405 Method Not Allowed"; exit(0); } if(!empty($_SERVER['QUERY_STRING'])){ parse_str($_SERVER['QUERY_STRING'], $_GET); foreach($_GET as $k => $v){ $_REQUEST[$k] = $v; } } if(!empty($_SERVER['POST'])){ parse_str($_SERVER['POST'], $_POST); foreach($_POST as $k => $v){ $_REQUEST[$k] = $v; } } echo "HTTP/1.1 200 OK\n"; echo "Content-Type: text/html\n"; if((@$_GET['act'] == 'backups' || @$_GET['act'] == 'templates') && !empty($_GET['download']) && substr_count($_GET['download'], './') == 0){ echo 'Content-Disposition: attachment; filename="'.$_GET['download'].'"'."\n"; } echo "\n"; define('SOFTACULOUS', 1); include_once(dirname(dirname(__FILE__)).'/enduser/universal.php'); if(file_exists($globals['path'].'/conf/universal.json') && is_readable($globals['path'].'/conf/universal.json') && (filesize($globals['path'].'/conf/universal.json') > 0)){ $secure_file = @file_get_contents($globals['path'].'/conf/universal.json'); if(empty($secure_file)){ die('Failed to load universal.json'); } $secure_val = json_decode($secure_file, true); if(is_array($secure_val)){ $globals = array_merge($globals, $secure_val); } } $orig_gid = (int) getenv('soft_egid'); $orig_uid = (int) getenv('soft_euid'); $env_userdata = posix_getpwnam($_SERVER['USERNAME']); if(empty($env_userdata) || $env_userdata['uid'] !== $orig_uid || $env_userdata['gid'] !== $orig_gid){ die('Unauthorised web access : Incorrect username'); } // These commands need to be executed as root $da_version = @shell_exec('/usr/local/directadmin/directadmin v'); // Sometimes the document root API fails so we are taking the domains list from CLI //$tmp_document_root = @shell_exec("/usr/local/directadmin/directadmin --DocumentRoot"); if(!empty($tmp_document_root)){ $tmp_document_root = json_decode($tmp_document_root, true); if(!empty($tmp_document_root['users'][$env_userdata['name']])){ $da_dom_data['users'][$env_userdata['name']] = $tmp_document_root['users'][$env_userdata['name']]; } // Not needed anymore unset($tmp_document_root); } // Create the Code-with-AI jail scratch dir while still root (before stepping // down). Parent root-owned 0711, per-user dir 0700 owned by the user. if(!empty($_REQUEST['act']) && $_REQUEST['act'] == 'ai'){ $ai_jail_pw = posix_getpwuid($orig_uid); if(!empty($ai_jail_pw['name'])){ $ai_jails_base = (!empty($globals['softscripts']) ? $globals['softscripts'] : '/var/softaculous').'/jails'; if(!is_dir($ai_jails_base)){ @mkdir($ai_jails_base, 0711, true); } @chmod($ai_jails_base, 0711); $ai_jail_user_dir = $ai_jails_base.'/'.$ai_jail_pw['name']; if(!is_dir($ai_jail_user_dir)){ @mkdir($ai_jail_user_dir, 0700); @chown($ai_jail_user_dir, $ai_jail_pw['name']); @chgrp($ai_jail_user_dir, $ai_jail_pw['name']); } @chmod($ai_jail_user_dir, 0700); } } // directadmin.conf is only readable as root so load the DA API endpoint details which are used later in softpanel.php function da_api_endpoint(){ global $globals; $hostname = (!empty($globals['cp_host']) ? $globals['cp_host'] : '127.0.0.1'); $endpoint = array('port' => '', 'ssl' => ''); $conf_file = '/usr/local/directadmin/conf/directadmin.conf'; if(is_readable($conf_file)){ $cdata = file_get_contents($conf_file); if(preg_match('/^\\s*port\\s*=\\s*(\\d+)\\s*$/im', $cdata, $m)){ $endpoint['port'] = $m[1]; } // DirectAdmin speaks HTTPS on its port when ssl=1 (unless told to ignore SSL for local calls) if(preg_match('/^\\s*ssl\\s*=\\s*1\\s*$/im', $cdata) && !preg_match('/^\\s*ssl_ignore_when_local\\s*=\\s*1\\s*$/im', $cdata)){ $endpoint['ssl'] = 's'; } } if(empty($endpoint['port']) && !empty($globals['cp_port'])){ $endpoint['port'] = $globals['cp_port']; } if(empty($endpoint['port'])){ $endpoint['port'] = 2222; } return $endpoint; } global $da_endpoint; $da_endpoint = da_api_endpoint(); posix_setgid($orig_gid); posix_setuid($orig_uid); putenv('soft_egid'); putenv('soft_euid'); // Still Root ? if(posix_getuid() == 0 || posix_geteuid() == 0){ echo 'ERROR IN SHIFTING TO USER LEVEL';exit(1); } include(dirname(dirname(__FILE__)).'/enduser/inc.php');