Example #1
0
 public static function add_template($sLocalSSH, $uName, $uURL, $uType)
 {
     global $database;
     if (filter_var($uURL, FILTER_VALIDATE_URL) === FALSE) {
         return $sError = array("red" => "Invalid URL for the template to download");
     } else {
         if ($uType == 'openvz') {
             $sList = ".tar.gz";
         } elseif ($uType == 'kvm') {
             $sList = ".iso";
         }
         $sName = preg_replace("/[^a-z0-9._-\\s]+/i", "", $uName);
         $sPath = str_replace($sList, "", basename($uURL));
         if ($sExists = $database->CachedQuery("SELECT * FROM templates WHERE `path` LIKE :TemplatePath && `type` = :Type", array('TemplatePath' => "%" . $sPath . "%", 'Type' => $uType))) {
             $sPath .= random_string(6);
         }
         $sTemplate = new Template(0);
         $sTemplate->uName = $sName;
         $sTemplate->uPath = $sPath;
         $sTemplate->uType = $uType;
         $sTemplate->InsertIntoDatabase();
         $sDownload = $sLocalSSH->exec("cd /var/feathur/data/templates/;mkdir {$sTemplate->sType};cd {$sTemplate->sType};wget_output=\$(wget -O {$sTemplate->sPath}{$sList} \"{$uURL}\")");
         $sRandoCalrissian = random_string(12);
         $sCheckDownload = $sLocalSSH->exec("cd /var/feathur/data/templates/{$sTemplate->sType};if [ -f {$sTemplate->sPath}{$sList} ]; do echo \"{$sRandoCalrissian}\"; fi;if [ \$(ls -l {$sTemplate->sPath}{$sList} | awk '{print \$5}') == 0 ]; do echo {$sRandoCalrissian}; fi");
         if (strpos($sCheckDownload, $sRandoCalrissian) !== false) {
             return $sArray = array("json" => 1, "type" => "success", "result" => "Template added, should be syncing to the servers here shortly.", "reload" => "1");
         } else {
             $sClean = $database->CachedQuery("DELETE FROM templates WHERE `id` = :Id", array('Id' => $sTemplate->sId));
             $sData = $sLocalSSH->exec("cd /var/feathur/data/templates/{$sTemplate->sType};rm -rf {$sTemplate->sPath}{$sList};");
             return $sArray = array("json" => 1, "type" => "error", "result" => "There was an issue downloading the template/iso.");
         }
     }
 }
Example #2
0
}
if ($sAction == removetemplate) {
    if (!empty($_GET['id'])) {
        $sRemove = VPS::remove_template(VPS::localhost_connect(), $_GET['id']);
        if (is_array($sRemove)) {
            echo json_encode($sRemove);
            die;
        }
    }
    $sJson = 1;
}
if ($sAction == updatetemplate) {
    if (!empty($_GET['name']) && is_numeric($_GET['id'])) {
        $sUpdateTemplate = new Template($_GET['id']);
        $sUpdateTemplate->uName = $_GET['name'];
        $sUpdateTemplate->InsertIntoDatabase();
        echo json_encode(array("result" => "Template name updated.", "type" => "success", "json" => "1"));
        die;
    } else {
        echo json_encode(array("result" => "You must specify a name for the template.", "type" => "error", "json" => "1"));
        die;
    }
}
if (empty($sType)) {
    $sContent .= Templater::AdvancedParse($sAdminTemplate->sValue . '/templates', $locale->strings, array("Virtualization" => 0));
} else {
    if ($sTL = $database->CachedQuery("SELECT * FROM templates WHERE `type` = :Type", array('Type' => $sType))) {
        foreach ($sTL->data as $sData) {
            $sTemplateList[] = array("id" => $sData["id"], "name" => $sData["name"], "path" => $sData["path"]);
        }
    }