function print_newvps() { global $xtpl; $xtpl->title(_("Create VPS")); $xtpl->form_create('?page=adminvps§ion=vps&action=new2&create=1', 'post'); $xtpl->form_add_input(_("Hostname") . ':', 'text', '30', 'vps_hostname', '', _("A-z, a-z"), 30); $xtpl->form_add_select(_("HW server") . ':', 'vps_server', list_servers(), '2', ''); $xtpl->form_add_select(_("Owner") . ':', 'm_id', members_list(), '', ''); $xtpl->form_add_select(_("Distribution") . ':', 'vps_template', list_templates(), '', ''); $xtpl->form_add_select(_("RAM") . ':', 'vps_privvmpages', list_limit_privvmpages(), '1', ''); $xtpl->form_add_select(_("Disk space") . ':', 'vps_diskspace', list_limit_diskspace(), '1', ''); $xtpl->form_add_checkbox(_("Boot on create") . ':', 'boot_after_create', '1', true, $hint = ''); $xtpl->form_add_textarea(_("Extra information about VPS") . ':', 28, 4, 'vps_info', '', ''); $xtpl->table_add_category(' '); $xtpl->table_add_category(' '); $xtpl->table_add_category(' '); $xtpl->form_out(_("Create")); }
function print_newvps() { global $xtpl, $cluster; $xtpl->title(_("Create VPS")); $xtpl->form_create('?page=adminvps§ion=vps&action=new2&create=1', 'post'); $xtpl->form_add_input(_("Hostname") . ':', 'text', '30', 'vps_hostname', '', _("A-z, a-z"), 255); if ($_SESSION["is_admin"]) { $xtpl->form_add_select(_("HW server") . ':', 'vps_server', list_servers(false, array("node")), '2', ''); $xtpl->form_add_select(_("Owner") . ':', 'm_id', members_list(), '', ''); } $xtpl->form_add_select(_("Distribution") . ':', 'vps_template', list_templates(false), '', ''); if ($_SESSION["is_admin"]) { //$xtpl->form_add_select(_("IPv4").':', 'ipv4', get_all_ip_list(4), '1', ''); $xtpl->form_add_checkbox(_("Boot on create") . ':', 'boot_after_create', '1', true, $hint = ''); $xtpl->form_add_textarea(_("Extra information about VPS") . ':', 28, 4, 'vps_info', '', ''); } $xtpl->table_add_category(' '); $xtpl->table_add_category(' '); $xtpl->table_add_category(' '); $xtpl->form_out(_("Create")); }
$xtpl->table_td($row["m_jabber"]); $xtpl->table_tr(); $xtpl->table_td(_("How") . ':'); $xtpl->table_td($row["m_how"]); $xtpl->table_tr(); $xtpl->table_td(_("Note") . ':'); $xtpl->table_td($row["m_note"]); $xtpl->table_tr(); $xtpl->table_td(_("Currency") . ':'); $xtpl->table_td($row["m_currency"]); $xtpl->table_tr(); $xtpl->form_add_checkbox(_("Create VPS") . ':', 'm_create_vps', '1', true); $xtpl->form_add_select(_("Distribution") . ':', 'm_distribution', list_templates(false), $row["m_distribution"]); $xtpl->form_add_select(_("Location") . ':', 'm_location', $cluster->list_locations(), $row["m_location"]); $empty = array("" => _("pick automatically")); $nodes = list_servers(false, array('node')); $xtpl->form_add_select(_("Node") . ':', 'm_node', $empty + $nodes); $xtpl->form_add_checkbox(_("Assign IP addresses") . ':', 'm_assign_ips', '1', true); $xtpl->form_add_select(_("IPv4") . ':', 'ipv4', array_merge($empty, get_free_ip_list(4, $row["m_location"])), '', _("listing IPs from application location only")); $xtpl->form_add_select(_("IPv6") . ':', 'ipv6', array_merge($empty, get_free_ip_list(6, $row["m_location"])), '', _("listing IPs from application location only")); $xtpl->form_add_input(_("Admin response") . ':', 'text', '30', 'm_admin_response', $row["m_admin_response"]); $xtpl->table_td(''); $xtpl->table_td($xtpl->html_submit(_("Approve"), "approve") . $xtpl->html_submit(_("Deny"), "deny") . $xtpl->html_submit(_("Invalidate"), "invalidate") . $xtpl->html_submit(_("Ignore"), "ignore")); $xtpl->table_tr(); $xtpl->form_out_raw(); break; case "change": $xtpl->table_add_category(_("Personal information")); $xtpl->table_add_category(_("From")); $xtpl->table_add_category(_("To")); $xtpl->form_create('?page=adminm§ion=members&action=request_process&id=' . $row["m_id"], 'post');
function change_server($target_id) { global $db; if ($this->exists) { $servers = list_servers(); if (isset($servers[$target_id])) { $sql = 'UPDATE vps SET vps_server = "' . $db->check($target_id) . '" WHERE vps_id = ' . $db->check($this->veid); $db->query($sql); $this->ve["vps_server"] = $target_id; } } }
function pick_free_node($location) { global $db; $servers = list_servers(false, array("node")); $sql = "SELECT server_id\n\t FROM servers s\n\t LEFT JOIN vps v ON v.vps_server = s.server_id\n\t LEFT JOIN vps_status st ON v.vps_id = st.vps_id\n\t WHERE\n\t (st.vps_up = 1 OR st.vps_up IS NULL)\n\t AND server_location = " . $db->check($location) . "\n\t AND max_vps > 0\n\t AND server_maintenance = 0\n\t GROUP BY server_id\n\t ORDER BY COUNT(st.vps_up) / max_vps ASC\n LIMIT 1\n\t "; $rs = $db->query($sql); if ($row = $db->fetch_array($rs)) { return $row["server_id"]; } else { return false; } }
$stmt->bindValue(':name', $obj->name); $stmt->bindValue(':haspassword', $obj->haspassword); $stmt->bindValue(':description', $obj->description); $stmt->bindValue(':version', $obj->version); $stmt->bindValue(':players', $obj->players); $stmt->bindValue(':maxplayers', $obj->maxplayers); $stmt->execute(); } } function remove_old_servers() { global $db; $result = $db->query("DELETE FROM servers WHERE time < DATETIME('now', '-70 seconds');"); } function list_servers() { global $db; $servers = array(); $result = $db->query("SELECT * FROM servers"); while ($row = $result->fetchArray()) { array_push($servers, array('address' => "{$row['address']}:{$row['port']}", 'name' => $row['name'], 'haspassword' => $row['haspassword'], 'description' => $row['description'], 'version' => $row['version'], 'players' => $row['players'], 'maxplayers' => $row['maxplayers'])); } echo json_encode($servers); } if ($port) { $data = request_gameinfo($address, $port); update_server($data); } else { remove_old_servers(); list_servers(); }
function save_config($id, $name, $label, $config, $reapply = false) { global $db; $params = array("name" => $name, "config" => $config); if ($id != NULL) { $sql = "UPDATE `config` SET name = '" . $db->check($name) . "',\n\t\t\t label = '" . $db->check($label) . "',\n\t\t\t `config` = '" . $db->check($config) . "'\n\t\t\t WHERE id = '" . $db->check($id) . "'"; $c = $db->findByColumnOnce("config", "id", $id); if ($c["name"] != $name) { $params["old_name"] = $c["name"]; } } else { $sql = "INSERT INTO `config` SET name = '" . $db->check($name) . "',\n\t\t\t label = '" . $db->check($label) . "',\n\t\t\t `config` = '" . $db->check($config) . "'"; } $db->query($sql); $servers = list_servers(false, array('node')); foreach ($servers as $sid => $name) { add_transaction($_SESSION["member"]["m_id"], $sid, 0, T_CLUSTER_CONFIG_CREATE, $params); $dep = $db->insertId(); if ($reapply) { $rs = $db->query("SELECT v.vps_id FROM vps v INNER JOIN vps_has_config c ON v.vps_id = c.vps_id WHERE c.config_id = " . $db->check($id) . " AND vps_server = " . $db->check($sid)); while ($row = $db->fetch_array($rs)) { $vps = vps_load($row["vps_id"]); $vps->applyconfigs($dep); } } } }
function mount_edit_form($target, $m, $default = false) { global $STORAGE_MOUNT_MODES_RO_RW, $STORAGE_MOUNT_TYPES, $xtpl; $e_list = get_nas_export_list($default); $nodes = list_servers(); $empty = array("" => "---"); $xtpl->table_title(_("Edit mount") . " " . $m["dst"]); $xtpl->form_create($target . '&id=' . $_GET["id"], 'post'); $xtpl->form_add_select(_("Export") . ':', 'export_id', $empty + $e_list, $_POST["export_id"] ? $_POST["export_id"] : (int) $m["storage_export_id"]); $xtpl->form_add_select(_("VPS") . ':', 'vps_id', get_user_vps_list(), $_POST["vps_id"] ? $_POST["vps_id"] : $m["vps_id"]); $xtpl->form_add_select(_("Access mode") . ':', 'access_mode', $STORAGE_MOUNT_MODES_RO_RW, $_POST["mode"] ? $_POST["mode"] : $m["mode"]); if ($_SESSION["is_admin"]) { $xtpl->form_add_select(_("Source node") . ':', 'source_node_id', $empty + $nodes, $_POST["source_node_id"] ? $_POST["source_node_id"] : $m["server_id"], _("Has no effect if export is selected.")); $xtpl->form_add_input(_("Source") . ':', 'text', '50', 'src', $_POST["src"] ? $_POST["src"] : $m["src"], _("Path is relative to source node root if specified, otherwise absolute. Has no effect if export is selected.")); } $xtpl->form_add_input(_("Destination") . ':', 'text', '50', 'dst', $_POST["dst"] ? $_POST["dst"] : $m["dst"], _("Path is relative to VPS root,<br>allowed chars: a-Z A-Z 0-9 _ - . /")); if ($_SESSION["is_admin"]) { $xtpl->form_add_input(_("Mount options") . ':', 'text', '50', 'm_opts', $_POST["m_opts"] ? $_POST["m_opts"] : $m["mount_opts"], ''); $xtpl->form_add_input(_("Umount options") . ':', 'text', '50', 'u_opts', $_POST["u_opts"] ? $_POST["u_opts"] : $m["umount_opts"], ''); $xtpl->form_add_select(_("Type") . ':', 'type', $STORAGE_MOUNT_TYPES, $_POST["type"] ? $_POST["type"] : $m["mount_type"]); } $xtpl->form_add_input(_("Pre-mount command") . ':', 'text', '50', 'cmd_premount', $_POST["cmd_premount"] ? $_POST["cmd_premount"] : $m["cmd_premount"], _("Command that is executed within VPS context <strong>before</strong> mount")); $xtpl->form_add_input(_("Post-mount command") . ':', 'text', '50', 'cmd_postmount', $_POST["cmd_postmount"] ? $_POST["cmd_postmount"] : $m["cmd_postmount"], _("Command that is executed within VPS context <strong>after</strong> mount")); $xtpl->form_add_input(_("Pre-umount command") . ':', 'text', '50', 'cmd_preumount', $_POST["cmd_preumount"] ? $_POST["cmd_preumount"] : $m["cmd_preumount"], _("Command that is executed within VPS context <strong>before</strong> umount")); $xtpl->form_add_input(_("Post-umount command") . ':', 'text', '50', 'cmd_postumount', $_POST["cmd_postumount"] ? $_POST["cmd_postumount"] : $m["cmd_postumount"], _("Command that is executed within VPS context <strong>after</strong> umount")); $xtpl->form_add_checkbox(_("Remount on save") . ':', 'remount_immediately', '1', $_POST["type"] ? $_POST["remount_immediately"] : true, "<strong>" . _("Recommended") . "</strong>"); $xtpl->form_out(_("Save")); }
function add_transaction_clusterwide($m_id, $vps_id, $t_type, $t_param = array(), $server_types = NULL) { global $db, $cluster, $NODE_TYPES; if ($server_types === NULL) { $server_types = $NODE_TYPES; } $sql = "INSERT INTO transaction_groups\n\t\t SET is_clusterwide=1"; $db->query_trans($sql, $err); $group_id = $db->insert_id(); $servers = list_servers(false, $server_types); foreach ($servers as $id => $name) { add_transaction($m_id, $id, $vps_id, $t_type, $t_param, $group_id); } }