Exemplo n.º 1
0
     $m = new member_load($_SESSION["is_admin"] ? $_POST["member"] : $_SESSION["member"]["m_id"]);
     foreach (nas_root_list_where($_SESSION["is_admin"] ? '' : "user_export = 1") as $r_id => $r) {
         if ($r_id == $_POST["root_id"]) {
             $ok = true;
         }
     }
     if (($path = is_ds_valid($_POST["path"])) === false) {
         $xtpl->perex(_("Path contains forbidden characters"), '');
         export_add_form($export_add_target);
     } else {
         if ($_SESSION["is_admin"] && ($ds = is_ds_valid($_POST["dataset"])) === false) {
             $xtpl->perex(_("Dataset contains forbidden characters"), '');
             export_add_form($export_add_target);
         } else {
             if ($ok && $m->exists) {
                 nas_export_add($_SESSION["is_admin"] ? $_POST["member"] : $_SESSION["member"]["m_id"], $_POST["root_id"], $_SESSION["is_admin"] ? $ds : NULL, $path, $_POST["quota_val"] * (2 << $NAS_UNITS_TR[$_POST["quota_unit"]]), $_SESSION["is_admin"] ? $_POST["user_editable"] : -1, $_SESSION["is_admin"] ? $_POST["type"] : "data");
                 notify_user(_("Export created"), _("Export was created."));
                 redirect('?page=nas');
             }
         }
     }
     break;
 case "export_edit":
     $e = nas_get_export_by_id($_GET["id"]);
     if (nas_can_user_manage_export($e)) {
         export_edit_form('?page=nas&action=export_edit_save', $e);
     }
     $xtpl->sbar_add(_("Back"), '?page=nas');
     break;
 case "export_edit_save":
     if ($_GET["id"] && $_POST["quota_val"] && $_POST["quota_unit"]) {
Exemplo n.º 2
0
    function clone_vps($m_id, $server_id, $hostname, $configs, $features, $backuper)
    {
        global $db;
        $sql = 'INSERT INTO vps
			SET m_id = "' . $db->check($m_id) . '",
				vps_created = "' . $db->check(time()) . '",
				vps_template = "' . $db->check($this->ve["vps_template"]) . '",
				vps_info ="' . $db->check("Cloned from {$this->veid}") . '",
				vps_hostname ="' . $db->check($hostname) . '",
				dns_resolver_id ="' . $db->check($this->ve["dns_resolver_id"]) . '",
				vps_server ="' . $db->check($server_id) . '",
				vps_onboot ="' . $db->check($this->ve["vps_onboot"]) . '",
				vps_onstartall = ' . $db->check($this->ve["vps_onstartall"]) . ',
				vps_features_enabled = ' . $db->check($features ? $this->ve["vps_features_enabled"] : 0) . ',
				vps_backup_enabled = ' . $db->check($backuper ? $this->ve["vps_backup_enabled"] : 1) . ',
				vps_backup_exclude = "' . $db->check($backuper ? $this->ve["vps_backup_exclude"] : '') . '",
				vps_config = "' . $db->check($configs ? $this->ve["vps_config"] : '') . '"';
        $db->query($sql);
        $clone = vps_load($db->insert_id());
        $src_node = new cluster_node($this->ve["vps_server"]);
        $dst_node = new cluster_node($server_id);
        $params = array("src_veid" => $this->veid, "src_addr" => $this->ve["server_ip4"], "src_node_type" => $src_node->role["fstype"], "dst_node_type" => $dst_node->role["fstype"]);
        add_transaction($_SESSION["member"]["m_id"], $server_id, $clone->veid, $server_id == $this->ve["vps_server"] ? T_CLONE_VE_LOCAL : T_CLONE_VE_REMOTE, $params);
        switch ($configs) {
            case 0:
                $clone->add_default_configs("default_config_chain");
                break;
            case 1:
                $db->query("INSERT INTO vps_has_config (vps_id, config_id, `order`) SELECT '" . $db->check($clone->veid) . "' AS vps_id, config_id, `order` FROM vps_has_config WHERE vps_id = '" . $db->check($this->veid) . "'");
                if ($clone->ve["vps_config"]) {
                    $clone->update_custom_config($clone->ve["vps_config"]);
                } else {
                    $clone->applyconfigs();
                }
                break;
            case 2:
                $clone->add_default_configs("playground_default_config_chain");
                break;
        }
        // Clone mounts - exports are the same, except backup, that must be created
        $db->query("INSERT INTO vps_mount (vps_id, src, dst, mount_opts, umount_opts, type, server_id, storage_export_id, mode, cmd_premount, cmd_postmount, cmd_preumount, cmd_postumount)\n\t            SELECT " . $clone->veid . " AS vps_id, src, dst, mount_opts, umount_opts, type, server_id, storage_export_id, mode, cmd_premount, cmd_postmount, cmd_preumount, cmd_postumount\n\t            FROM vps_mount\n\t            WHERE vps_id = " . $db->check($this->veid));
        $def_exports = nas_list_default_exports("vps");
        $cloned_backup_export = 0;
        foreach ($def_exports as $e) {
            if ($e["export_type"] == "backup") {
                $cloned_backup_export = nas_export_add($clone->ve["m_id"], $e["root_id"], nas_resolve_vars($e["dataset"], $clone->ve), nas_resolve_vars($e["path"], $clone->ve), $e["export_quota"], $e["user_editable"], $e["export_type"]);
                break;
            }
        }
        if ($cloned_backup_export) {
            $db->query("UPDATE vps_mount SET storage_export_id = " . $db->check($cloned_backup_export) . "\n\t\t            WHERE vps_id = " . $db->check($clone->veid) . " AND storage_export_id = " . $db->check($this->ve["vps_backup_export"]));
            $clone->set_backuper(NULL, $cloned_backup_export, false, true);
        }
        $clone->mount_regen();
        $clone->set_hostname($hostname);
        if ($features && $this->ve["vps_features_enabled"]) {
            add_transaction($_SESSION["member"]["m_id"], $server_id, $clone->veid, T_ENABLE_FEATURES);
        }
        $this->info();
        if ($this->ve["vps_up"]) {
            $clone->start();
        }
        return $clone;
    }
Exemplo n.º 3
0
function nas_create_default_exports($type, $obj)
{
    $exports = nas_list_default_exports($type);
    $mapping = array();
    foreach ($exports as $e) {
        $new_id = nas_export_add($e["member_id"] ? $e["member_id"] : $obj["m_id"], $e["root_id"], nas_resolve_vars($e["dataset"], $obj), nas_resolve_vars($e["path"], $obj), $e["export_quota"], $e["user_editable"], $e["export_type"], "no", false);
        $mapping[$e["export_id"]] = $new_id;
        if ($type == "vps" && $e["export_type"] == "backup") {
            $vps = new vps_load($obj["vps_id"]);
            $vps->set_backuper(NULL, $new_id, false, true);
        }
    }
    return $mapping;
}
Exemplo n.º 4
0
     break;
 case "nas_def_export_add":
     $xtpl->table_title(_("Add default export for new") . ' ' . ($_GET["for"] == "member" ? _("member") : _("VPS")));
     export_add_form($export_add_target, true);
     $xtpl->sbar_add(_("Back"), '?page=cluster&action=nas_settings');
     break;
 case "nas_def_export_edit":
     $e = nas_get_export_by_id($_GET["id"]);
     export_edit_form('?page=cluster&action=nas_def_export_save', $e);
     break;
 case "nas_def_export_save":
     if (isset($_POST["root_id"]) || isset($_POST["quota_val"])) {
         if ($_GET["id"]) {
             nas_export_update($_GET["id"], $_POST["quota_val"] * (2 << $NAS_UNITS_TR[$_POST["quota_unit"]]), $_POST["user_editable"], $_POST["type"]);
         } else {
             nas_export_add($_POST["member"], $_POST["root_id"], $_POST["dataset"], $_POST["path"], $_POST["quota_val"] * (2 << $NAS_UNITS_TR[$_POST["quota_unit"]]), $_POST["user_editable"], $_POST["type"], $_GET["for"]);
         }
         notify_user(_("Default export saved"), '');
         redirect('?page=cluster&action=nas_settings');
     }
     break;
 case "nas_def_export_del":
     if ($_GET["id"] && ($e = nas_get_export_by_id($_GET["id"]))) {
         $mounts = nas_get_mounts_for_export($_GET["id"]);
         $msg = "";
         $children = nas_get_export_children($_GET["id"]);
         if (count($children) > 0) {
             $msg .= _("This export has following subdirectories and ALL OF THEM will be DELETED too:");
             $msg .= "<br><ul>";
             foreach ($children as $child) {
                 $mounts = array_merge($mounts, nas_get_mounts_for_export($child["id"]));