Esempio n. 1
0
 public static function AddDomain($uDomain)
 {
     global $sUser;
     global $sDefaultIP;
     global $user_ssh;
     global $user_sftp;
     global $database;
     // Filter Domain
     $uDomain = preg_replace("/[^a-z0-9_ .-]/i", "", $uDomain);
     $uDomain = str_replace("www.", "", $uDomain);
     $sDomain = str_replace("http://", "", $uDomain);
     $result = $database->CachedQuery("SELECT * FROM domains WHERE `domain_name` = :Domain", array(':Domain' => $sDomain), 5);
     if (empty($result)) {
         // Validate path information
         $sUser->sRootDir = '/home/' . $sUser->sUsername . '/';
         $sValidate = new PathValidator($sUser->sRootDir . $sDomain);
         if ($sValidate->ValidatePath($sUser->sRootDir)) {
             // Connect to server
             if (!$user_ssh->login($sUser->sUsername, $_SESSION['password'])) {
                 exit('User Connection To Server Failed!');
             }
             if (!$user_sftp->login($sUser->sUsername, $_SESSION['password'])) {
                 exit('User Connection To Server Failed!');
             }
             // Create folders for domain & logs
             $sPublic = $sUser->sRootDir . $sDomain . "/public_html/";
             $sLogs = $sUser->sRootDir . "/logs/";
             $sCreateFolder = $user_ssh->exec("mkdir " . escapeshellarg($sUser->sRootDir . $sDomain) . ";mkdir " . escapeshellarg($sPublic) . ";mkdir " . escapeshellarg($sLogs) . ";");
             // Generate configs
             $sReplace = array("domain_name" => $sDomain, "username" => $sUser->sUsername);
             $sConfig = file_get_contents('./includes/configs/nginx.default.conf');
             foreach ($sReplace as $key => $value) {
                 $sConfig = str_replace($key, $value, $sConfig);
             }
             $sFileContent = $user_sftp->put('/etc/nginx/sites-enabled/' . $sDomain . '.conf', $sConfig);
             $sTestConfig = $user_ssh->exec("nginx -t -c /etc/nginx/nginx.conf");
             if (strpos($sTestConfig, 'failed') !== false) {
                 $sDeleteConfig = $user_ssh->exec("rm -rf /etc/nginx/sites-enabled/" . $sDomain . ".conf");
                 die("Seems to be a problem setting up the config.");
             }
             $sReload = $user_ssh->exec("/etc/init.d/nginx reload");
             $sReload = $user_ssh->exec("/etc/init.d/pdns reload");
             // Insert Domain Into Database
             $sCreateDomain = new Domain(0);
             $sCreateDomain->uName = $uDomain;
             $sCreateDomain->uOwner = $sUser->sId;
             $sCreateDomain->uActive = 1;
             $sCreateDomain->InsertIntoDatabase();
             // Add DNS Records
             $sResultOne = $database->CachedQuery("INSERT INTO dns.domains (name, type) VALUES(:Domain, 'NATIVE')", array(':Domain' => $sDomain));
             $sDomainId = $database->lastInsertId();
             $sResultTwo = $database->CachedQuery("INSERT INTO dns.records (domain_id, name, content, type, ttl, prio) VALUES(:Id, :Domain, :IPAddress, 'A', '120', 'NULL')", array(':Id' => $sDomainId, ':Domain' => $sDomain, ':IPAddress' => $sDefaultIP->sValue));
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Esempio n. 2
0
             } elseif ($sAction == move_folder || $sAction == move_file) {
                 $sMove = $user_ssh->exec('mv ' . escapeshellarg($sFrom) . ' ' . escapeshellarg($sTo));
             } elseif ($sAction == copy_file) {
                 $sCopy = $user_ssh->exec('cp -r ' . escapeshellarg($sFrom) . ' ' . escapeshellarg($sTo));
             }
         } else {
             die("There seems to be a problem with your request. Please go back and try again.");
         }
     } else {
         die("There seems to be a problem with your request. Please go back and try again.");
     }
 }
 if ($sAction == permissions) {
     $uName = preg_replace("/[^a-z0-9\\/;_ \\.-]/i", "", $_GET['name']);
     if (is_numeric($_GET['value'])) {
         $sNameValidate = new PathValidator($sRequest . $uName);
         if ($sNameValidate->ValidatePath($sUser->sRootDir)) {
             $sName = $uName;
             $sPerms = $user_ssh->exec('chmod ' . $_GET["value"] . ' ' . escapeshellarg($sRequest . $sName));
         } else {
             die("Invalud File Path");
         }
     } else {
         die("Permissions error!");
     }
 }
 // Begin pulling folder & file data to display to the user.
 $sPullDirectories = $user_ssh->exec('ls -l ' . escapeshellarg($sRequest) . ' |grep ^d');
 $sParsedDirectories = preg_split('/\\r\\n|\\r|\\n/', $sPullDirectories);
 $sDirectories = array();
 foreach ($sParsedDirectories as $sValue) {