diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index 8071429b7c3965cebc9d153be2d35f8d3b017f64..21029929d566e505a2ca59017c9a6588c1c9eb02 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -52,7 +52,7 @@ class functions { unset($path_parts); } - $header = "From: $from\nReply-To: $from\n"; + $header = "Return-Path: $form\nFrom: $from\nReply-To: $from\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: multipart/mixed; boundary=$uid\n"; diff --git a/interface/lib/plugins/vm_openvz_plugin.inc.php b/interface/lib/plugins/vm_openvz_plugin.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..1112e081c719fda1f38fffb09da8a8f66a4173f2 --- /dev/null +++ b/interface/lib/plugins/vm_openvz_plugin.inc.php @@ -0,0 +1,233 @@ +plugin->registerEvent('vm:openvz_vm:on_after_insert','vm_openvz_plugin','openvz_vm_insert'); + $app->plugin->registerEvent('vm:openvz_vm:on_after_update','vm_openvz_plugin','openvz_vm_update'); + } + + /* + Function that gets called after a new vm was inserted + */ + function openvz_vm_insert($event_name, $page_form) { + global $app, $conf; + + $this->id = $page_form->id; + $this->dataRecord = $page_form->dataRecord; + $this->oldDataRecord = $page_form->oldDataRecord; + + // make sure that the record belongs to the clinet group and not the admin group when admin inserts it + // also make sure that the user can not delete domain created by a admin + if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { + $client_group_id = intval($this->dataRecord["client_group_id"]); + $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); + } + if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { + $client_group_id = intval($this->dataRecord["client_group_id"]); + $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); + } + + // Set the VEID + $tmp = $app->db->queryOneRecord('SELECT MAX(veid) + 1 as newveid FROM openvz_vm'); + $veid = ($tmp['newveid'] > 100)?$tmp['newveid']:101; + $app->db->query("UPDATE openvz_vm SET veid = ".$veid." WHERE vm_id = ".$this->id); + unset($tmp); + + // Apply template values to the advanced tab settings + $this->applyTemplate(); + + // Set the IP address + $app->db->query("UPDATE openvz_ip SET vm_id = ".$this->id." WHERE ip_address = '".$this->dataRecord['ip_address']."'"); + + // Create the OpenVZ config file and store it in config field + $this->makeOpenVZConfig(); + + // Create the DNS record + $this->createDNS(); + + } + + /* + Function that gets called after a vm was updated + */ + function openvz_vm_update($event_name, $page_form) { + global $app, $conf; + + $this->id = $page_form->id; + $this->dataRecord = $page_form->dataRecord; + $this->oldDataRecord = $page_form->oldDataRecord; + + // make sure that the record belongs to the clinet group and not the admin group when a admin inserts it + // also make sure that the user can not delete domain created by a admin + if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { + $client_group_id = intval($this->dataRecord["client_group_id"]); + $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); + } + if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { + $client_group_id = intval($this->dataRecord["client_group_id"]); + $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); + } + + if(isset($this->dataRecord["ostemplate_id"]) && $this->oldDataRecord["ostemplate_id"] != $this->dataRecord["ostemplate_id"]) { + $this->applyTemplate(); + } + + // Set the IP address + if(isset($this->dataRecord['ip_address'])) $app->db->query("UPDATE openvz_ip SET vm_id = ".$this->id." WHERE ip_address = '".$this->dataRecord['ip_address']."'"); + + // Create the OpenVZ config file and store it in config field + $this->makeOpenVZConfig(); + + // Create the DNS record + if((isset($this->dataRecord['hostname']) && $this->dataRecord['hostname'] != $this->oldDataRecord['hostname']) + or (isset($this->dataRecord['create_dns']) && $this->dataRecord['create_dns'] != $this->oldDataRecord['create_dns'])) { + $this->createDNS(); + } + + } + + private function applyTemplate() { + global $app, $conf; + + $tpl = $app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = ".$this->dataRecord["template_id"]); + + $sql = "UPDATE openvz_vm SET "; + $sql .= "diskspace = '".$tpl['diskspace']."', "; + $sql .= "ram = '".$tpl['ram']."', "; + $sql .= "ram_burst = '".$tpl['ram_burst']."', "; + $sql .= "cpu_units = '".$tpl['cpu_units']."', "; + $sql .= "cpu_num = '".$tpl['cpu_num']."', "; + $sql .= "cpu_limit = '".$tpl['cpu_limit']."', "; + $sql .= "io_priority = '".$tpl['io_priority']."', "; + $sql .= "nameserver = '".$tpl['nameserver']."', "; + $sql .= "create_dns = '".$tpl['create_dns']."', "; + $sql .= "capability = '".$tpl['capability']."' "; + $sql .= "WHERE vm_id = ".$this->id; + $app->db->query($sql); + + } + + private function makeOpenVZConfig() { + global $app, $conf; + + $vm = $app->tform->getDataRecord($this->id); + $vm_template = $app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = ".$vm['template_id']); + $burst_ram = $vm['ram_burst']*256; + $guar_ram = $vm['ram']*256; + + $tpl = new tpl(); + $tpl->newTemplate('templates/openvz.conf.tpl'); + + $onboot = ($vm['start_boot'] == 'y')?'yes':'no'; + $tpl->setVar('onboot',$onboot); + + $tpl->setVar('kmemsize',$vm_template['kmemsize']); + $tpl->setVar('lockedpages',$vm_template['lockedpages']); + $tpl->setVar('privvmpages',$burst_ram.':'.$burst_ram); + $tpl->setVar('shmpages',$guar_ram.':'.$guar_ram); + $tpl->setVar('numproc',$vm_template['numproc']); + $tpl->setVar('physpages',$vm_template['physpages']); + $tpl->setVar('vmguarpages',$guar_ram.':'.$guar_ram); + $tpl->setVar('oomguarpages',$guar_ram.':'.$guar_ram); + $tpl->setVar('numtcpsock',$vm_template['numtcpsock']); + $tpl->setVar('numflock',$vm_template['numflock']); + $tpl->setVar('numpty',$vm_template['numpty']); + $tpl->setVar('numsiginfo',$vm_template['numsiginfo']); + $tpl->setVar('tcpsndbuf',$vm_template['tcpsndbuf']); + $tpl->setVar('tcprcvbuf',$vm_template['tcprcvbuf']); + $tpl->setVar('othersockbuf',$vm_template['othersockbuf']); + $tpl->setVar('dgramrcvbuf',$vm_template['dgramrcvbuf']); + $tpl->setVar('numothersock',$vm_template['numothersock']); + $tpl->setVar('dcachesize',$vm_template['dcachesize']); + $tpl->setVar('numfile',$vm_template['numfile']); + $tpl->setVar('avnumproc',$vm_template['avnumproc']); + $tpl->setVar('numiptent',$vm_template['numiptent']); + + $diskspace = $vm['diskspace']*1048576; + $diskinodes = $vm['diskspace']*524288; + + $tpl->setVar('diskspace',$diskspace.":".$diskspace); + $tpl->setVar('diskinodes',$diskinodes.":".$diskinodes); + $tpl->setVar('io_priority',$vm['io_priority']); + + $tpl->setVar('cpu_num',$vm['cpu_num']); + $tpl->setVar('cpu_units',$vm['cpu_units']); + $tpl->setVar('cpu_limit',$vm['cpu_limit']); + + $hostname = str_replace('{VEID}',$vm['veid'],$vm['hostname']); + + $tpl->setVar('hostname',$hostname); + $tpl->setVar('ip_address',$vm['ip_address']); + $tpl->setVar('nameserver',$vm['nameserver']); + $tpl->setVar('capability',$vm['capability']); + + $tmp = $app->db->queryOneRecord("SELECT template_file FROM openvz_ostemplate WHERE ostemplate_id = ".$vm['ostemplate_id']); + $tpl->setVar('ostemplate',$tmp['template_file']); + unset($tmp); + + $openvz_config = $app->db->quote($tpl->grab()); + $app->db->query("UPDATE openvz_vm SET config = '".$openvz_config."' WHERE vm_id = ".$this->id); + + unset($tpl); + + } + + private function createDNS() { + global $app, $conf; + + $vm = $app->tform->getDataRecord($this->id); + + if($vm['create_dns'] != 'y') return; + + $full_hostname = str_replace('{VEID}',$vm['veid'],$vm['hostname']); + $hostname_parts = explode('.',$full_hostname); + $hostname = $hostname_parts[0]; + unset($hostname_parts[0]); + $zone = implode('.',$hostname_parts); + unset($hostname_parts); + + // Find the dns zone + $zone_rec = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE origin = '$zone.'"); + $rr_rec = $app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = '".$zone_rec['id']."' AND name = '$hostname'"); + + if($zone_rec['id'] > 0) { + $ip_address = $vm['ip_address']; + $sys_userid = $zone_rec['sys_userid']; + $sys_groupid = $zone_rec['sys_groupid']; + $server_id = $zone_rec['server_id']; + $dns_soa_id = $zone_rec['id']; + + if($rr_rec['id'] > 0) { + $app->uses('validate_dns'); + $app->db->datalogUpdate('dns_rr', "data = '$ip_address'", 'id', $rr_rec['id']); + $serial = $app->validate_dns->increase_serial($zone_rec['serial']); + $app->db->datalogUpdate('dns_soa', "serial = '$serial'", 'id', $zone_rec['id']); + } else { + $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `zone`, `name`, `type`, `data`, `aux`, `ttl`, `active`) VALUES + ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$hostname', 'A', '$ip_address', '0', '3600', 'Y')"; + $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); + } + + } + } + +} \ No newline at end of file diff --git a/interface/web/tools/templates/user_settings.htm b/interface/web/tools/templates/user_settings.htm index 415aafc1544cb8b1d9958c9dd6311128f12227be..49c2a55844c4147131a9cbcfdd97106225a8ed11 100644 --- a/interface/web/tools/templates/user_settings.htm +++ b/interface/web/tools/templates/user_settings.htm @@ -24,14 +24,6 @@ {tmpl_var name='language'} -
- - -
-
- - -
diff --git a/interface/web/vm/lib/lang/en_openvz_action.lng b/interface/web/vm/lib/lang/en_openvz_action.lng new file mode 100644 index 0000000000000000000000000000000000000000..9c5138decfec3fa21b0861f3aac4c219d87a8c9b --- /dev/null +++ b/interface/web/vm/lib/lang/en_openvz_action.lng @@ -0,0 +1,17 @@ + diff --git a/interface/web/vm/openvz_action.php b/interface/web/vm/openvz_action.php new file mode 100644 index 0000000000000000000000000000000000000000..e1707da72c5e662dcafc1a70b5b95d6381db0ee6 --- /dev/null +++ b/interface/web/vm/openvz_action.php @@ -0,0 +1,149 @@ +auth->check_module_permissions('vm'); + +$action = (isset($_POST['action']) && $_POST['action'] != '')?$_POST['action']:'show'; +$vm_id = intval($_REQUEST['id']); +$error_msg = ''; +$notify_msg = ''; + +if($vm_id == 0) die('Invalid VM ID'); + +$vm = $app->db->queryOneRecord("SELECT server_id, veid FROM openvz_vm WHERE vm_id = $vm_id"); +$veid = $vm['veid']; +$server_id = $vm['server_id']; + +//* Loading classes +$app->uses('tpl'); + +$app->tpl->newTemplate('form.tpl.htm'); +$app->tpl->setInclude('content_tpl', 'templates/openvz_action.htm'); + +//* load language file +$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_openvz_action.lng'; +include_once($lng_file); +$app->tpl->setVar($wb); + +$app->tpl->setVar('id',$vm_id); +$app->tpl->setVar('veid',$veid); + +$options = array('start_option_enabled'=>'','stop_option_enabled'=>'','restart_option_enabled'=>'','ostemplate_option_enabled'=>''); + + +//* Show the action select page +if($action == 'show') { + +$options['start_option_enabled'] = 'checked="checked"'; + +} elseif ($action == 'start') { + + //* Start the virtual machine + $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . + "VALUES (". + (int)$server_id . ", ". + time() . ", ". + "'openvz_start_vm', ". + $veid.", ". + "'pending', ". + "''". + ")"; + $app->db->query($sql); + + $app->tpl->setVar('msg',$wb['start_exec_txt']); + $options['start_option_enabled'] = 'checked="checked"'; + +} elseif ($action == 'stop') { + + //* Stop the virtual machine + $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . + "VALUES (". + (int)$server_id . ", ". + time() . ", ". + "'openvz_stop_vm', ". + $veid.", ". + "'pending', ". + "''". + ")"; + $app->db->query($sql); + + $app->tpl->setVar('msg',$wb['stop_exec_txt']); + $options['stop_option_enabled'] = 'checked="checked"'; + +} elseif ($action == 'restart') { + + //* Restart the virtual machine + $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . + "VALUES (". + (int)$server_id . ", ". + time() . ", ". + "'openvz_restart_vm', ". + $veid.", ". + "'pending', ". + "''". + ")"; + $app->db->query($sql); + + $app->tpl->setVar('msg',$wb['restart_exec_txt']); + $options['restart_option_enabled'] = 'checked="checked"'; + +} elseif ($action == 'ostemplate') { + + $ostemplate_name = $_POST['ostemplate_name']; + + if(!preg_match("/^[a-zA-Z0-9\.\-\_]{1,50}$/i", $ostemplate_name)) { + $error_msg .= $wb['ostemplate_name_error'].'
'; + $app->tpl->setVar('ostemplate_name',$ostemplate_name); + } + + //* Quote name + $ostemplate_name = $app->db->quote($ostemplate_name); + + //* Check for duplicates + $tmp = $app->db->queryOneRecord("SELECT count(ostemplate_id) as number FROM openvz_ostemplate WHERE template_file = '$ostemplate_name'"); + if($tmp['number'] > 0) $error_msg .= $wb['ostemplate_name_unique_error'].'
'; + unset($tmp); + + if($error_msg == '') { + //* Create ostemplate action + $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . + "VALUES (". + (int)$server_id . ", ". + time() . ", ". + "'openvz_create_ostpl', ". + "'".$veid.":".$ostemplate_name."', ". + "'pending', ". + "''". + ")"; + $app->db->query($sql); + + //* Create a record in the openvz_ostemplate table + $sql = "INSERT INTO `openvz_ostemplate` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `template_name`, `template_file`, `server_id`, `allservers`, `active`, `description`) + VALUES(1, 1, 'riud', 'riud', '', '$ostemplate_name', '$ostemplate_name', $server_id, 'n', 'y', '')"; + $app->db->query($sql); + + $app->tpl->setVar('msg',$wb['ostemplate_exec_txt']); + $options['ostemplate_option_enabled'] = 'checked="checked"'; + } + +} else { + $error_msg = $app->lng('Unknown action'); + $app->error($error_msg); +} + +$app->tpl->setVar($options); +$app->tpl->setVar('error',$error_msg); + +$app->tpl_defaults(); +$app->tpl->pparse(); + + + +?> \ No newline at end of file diff --git a/interface/web/vm/openvz_vm_edit.php b/interface/web/vm/openvz_vm_edit.php index bc0324907bf647c20049fa767f2297df4533cef2..65fbda3155ee621da09c3c91b18bca666835543d 100644 --- a/interface/web/vm/openvz_vm_edit.php +++ b/interface/web/vm/openvz_vm_edit.php @@ -59,12 +59,12 @@ class page_action extends tform_actions { //* Reseller: If the logged in user is not admin and has sub clients (is a rseller) } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { - // Get the limits of the client + //* Get the limits of the client $client_group_id = $_SESSION["s"]["user"]["default_group"]; $client = $app->db->queryOneRecord("SELECT client.client_id, client.contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); - // Fill the client select field + //* Fill the client select field $sql = "SELECT groupid, name FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$client['client_id']." ORDER BY name"; $records = $app->db->queryAllRecords($sql); $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$client['client_id']); @@ -81,7 +81,7 @@ class page_action extends tform_actions { //* Admin: If the logged in user is admin } else { - // Fill the client select field + //* Fill the client select field $sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0 ORDER BY name"; $clients = $app->db->queryAllRecords($sql); $client_select = ""; @@ -111,207 +111,12 @@ class page_action extends tform_actions { function onSubmit() { global $app, $conf; - // Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller + //* Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]); parent::onSubmit(); } - function onAfterInsert() { - global $app, $conf; - - // make sure that the record belongs to the clinet group and not the admin group when admin inserts it - // also make sure that the user can not delete domain created by a admin - if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { - $client_group_id = intval($this->dataRecord["client_group_id"]); - $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); - } - if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { - $client_group_id = intval($this->dataRecord["client_group_id"]); - $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); - } - - // Set the VEID - $tmp = $app->db->queryOneRecord('SELECT MAX(veid) + 1 as newveid FROM openvz_vm'); - $veid = ($tmp['newveid'] > 100)?$tmp['newveid']:101; - $app->db->query("UPDATE openvz_vm SET veid = ".$veid." WHERE vm_id = ".$this->id); - unset($tmp); - - // Apply template values to the advanced tab settings - $this->applyTemplate(); - - // Set the IP address - $app->db->query("UPDATE openvz_ip SET vm_id = ".$this->id." WHERE ip_address = '".$this->dataRecord['ip_address']."'"); - - // Create the OpenVZ config file and store it in config field - $this->makeOpenVZConfig(); - - // Create the DNS record - $this->createDNS(); - - } - - function onAfterUpdate() { - global $app, $conf; - - // make sure that the record belongs to the clinet group and not the admin group when a admin inserts it - // also make sure that the user can not delete domain created by a admin - if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { - $client_group_id = intval($this->dataRecord["client_group_id"]); - $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); - } - if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { - $client_group_id = intval($this->dataRecord["client_group_id"]); - $app->db->query("UPDATE openvz_vm SET sys_groupid = $client_group_id WHERE vm_id = ".$this->id); - } - - if(isset($this->dataRecord["ostemplate_id"]) && $this->oldDataRecord["ostemplate_id"] != $this->dataRecord["ostemplate_id"]) { - $this->applyTemplate(); - } - - // Set the IP address - if(isset($this->dataRecord['ip_address'])) $app->db->query("UPDATE openvz_ip SET vm_id = ".$this->id." WHERE ip_address = '".$this->dataRecord['ip_address']."'"); - - // Create the OpenVZ config file and store it in config field - $this->makeOpenVZConfig(); - - // Create the DNS record - if((isset($this->dataRecord['hostname']) && $this->dataRecord['hostname'] != $this->oldDataRecord['hostname']) - or (isset($this->dataRecord['create_dns']) && $this->dataRecord['create_dns'] != $this->oldDataRecord['create_dns'])) { - $this->createDNS(); - } - - } - - function applyTemplate() { - global $app, $conf; - - $tpl = $app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = ".$this->dataRecord["template_id"]); - - $sql = "UPDATE openvz_vm SET "; - $sql .= "diskspace = '".$tpl['diskspace']."', "; - $sql .= "ram = '".$tpl['ram']."', "; - $sql .= "ram_burst = '".$tpl['ram_burst']."', "; - $sql .= "cpu_units = '".$tpl['cpu_units']."', "; - $sql .= "cpu_num = '".$tpl['cpu_num']."', "; - $sql .= "cpu_limit = '".$tpl['cpu_limit']."', "; - $sql .= "io_priority = '".$tpl['io_priority']."', "; - $sql .= "nameserver = '".$tpl['nameserver']."', "; - $sql .= "create_dns = '".$tpl['create_dns']."', "; - $sql .= "capability = '".$tpl['capability']."' "; - $sql .= "WHERE vm_id = ".$this->id; - $app->db->query($sql); - - } - - function makeOpenVZConfig() { - global $app, $conf; - - $vm = $app->tform->getDataRecord($this->id); - $vm_template = $app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = ".$vm['template_id']); - $burst_ram = $vm['ram_burst']*256; - $guar_ram = $vm['ram']*256; - - $tpl = new tpl(); - $tpl->newTemplate('templates/openvz.conf.tpl'); - - $onboot = ($vm['start_boot'] == 'y')?'yes':'no'; - $tpl->setVar('onboot',$onboot); - - $tpl->setVar('kmemsize',$vm_template['kmemsize']); - $tpl->setVar('lockedpages',$vm_template['lockedpages']); - $tpl->setVar('privvmpages',$burst_ram.':'.$burst_ram); - $tpl->setVar('shmpages',$guar_ram.':'.$guar_ram); - $tpl->setVar('numproc',$vm_template['numproc']); - $tpl->setVar('physpages',$vm_template['physpages']); - $tpl->setVar('vmguarpages',$guar_ram.':'.$guar_ram); - $tpl->setVar('oomguarpages',$guar_ram.':'.$guar_ram); - $tpl->setVar('numtcpsock',$vm_template['numtcpsock']); - $tpl->setVar('numflock',$vm_template['numflock']); - $tpl->setVar('numpty',$vm_template['numpty']); - $tpl->setVar('numsiginfo',$vm_template['numsiginfo']); - $tpl->setVar('tcpsndbuf',$vm_template['tcpsndbuf']); - $tpl->setVar('tcprcvbuf',$vm_template['tcprcvbuf']); - $tpl->setVar('othersockbuf',$vm_template['othersockbuf']); - $tpl->setVar('dgramrcvbuf',$vm_template['dgramrcvbuf']); - $tpl->setVar('numothersock',$vm_template['numothersock']); - $tpl->setVar('dcachesize',$vm_template['dcachesize']); - $tpl->setVar('numfile',$vm_template['numfile']); - $tpl->setVar('avnumproc',$vm_template['avnumproc']); - $tpl->setVar('numiptent',$vm_template['numiptent']); - - $diskspace = $vm['diskspace']*1048576; - $diskinodes = $vm['diskspace']*524288; - - $tpl->setVar('diskspace',$diskspace.":".$diskspace); - $tpl->setVar('diskinodes',$diskinodes.":".$diskinodes); - $tpl->setVar('io_priority',$vm['io_priority']); - - $tpl->setVar('cpu_num',$vm['cpu_num']); - $tpl->setVar('cpu_units',$vm['cpu_units']); - $tpl->setVar('cpu_limit',$vm['cpu_limit']); - - $hostname = str_replace('{VEID}',$vm['veid'],$vm['hostname']); - - $tpl->setVar('hostname',$hostname); - $tpl->setVar('ip_address',$vm['ip_address']); - $tpl->setVar('nameserver',$vm['nameserver']); - $tpl->setVar('capability',$vm['capability']); - - $tmp = $app->db->queryOneRecord("SELECT template_file FROM openvz_ostemplate WHERE ostemplate_id = ".$vm['ostemplate_id']); - $tpl->setVar('ostemplate',$tmp['template_file']); - unset($tmp); - - $openvz_config = $app->db->quote($tpl->grab()); - $app->db->query("UPDATE openvz_vm SET config = '".$openvz_config."' WHERE vm_id = ".$this->id); - - unset($tpl); - - } - - function createDNS() { - global $app, $conf; - - $vm = $app->tform->getDataRecord($this->id); - - if($vm['create_dns'] != 'y') return; - - $full_hostname = str_replace('{VEID}',$vm['veid'],$vm['hostname']); - $hostname_parts = explode('.',$full_hostname); - $hostname = $hostname_parts[0]; - unset($hostname_parts[0]); - $zone = implode('.',$hostname_parts); - unset($hostname_parts); - - // Find the dns zone - $zone_rec = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE origin = '$zone.'"); - $rr_rec = $app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = '".$zone_rec['id']."' AND name = '$hostname'"); - - if($zone_rec['id'] > 0) { - $ip_address = $vm['ip_address']; - $sys_userid = $zone_rec['sys_userid']; - $sys_groupid = $zone_rec['sys_groupid']; - $server_id = $zone_rec['server_id']; - $dns_soa_id = $zone_rec['id']; - - if($rr_rec['id'] > 0) { - $app->uses('validate_dns'); - $app->db->datalogUpdate('dns_rr', "data = '$ip_address'", 'id', $rr_rec['id']); - $serial = $app->validate_dns->increase_serial($zone_rec['serial']); - $app->db->datalogUpdate('dns_soa', "serial = '$serial'", 'id', $zone_rec['id']); - } else { - $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `zone`, `name`, `type`, `data`, `aux`, `ttl`, `active`) VALUES - ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$hostname', 'A', '$ip_address', '0', '3600', 'Y')"; - $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id'); - } - - } - - - - - } - } $page = new page_action; diff --git a/interface/web/vm/templates/openvz_action.htm b/interface/web/vm/templates/openvz_action.htm new file mode 100644 index 0000000000000000000000000000000000000000..042bca838b0abd22187d9f495b029b99554a1003 --- /dev/null +++ b/interface/web/vm/templates/openvz_action.htm @@ -0,0 +1,54 @@ +

+

+ +
+ +
+
{tmpl_var name="head_txt"} {tmpl_var name='veid'} + + +

+
+ +

ERROR

+
+ +
+

{tmpl_var name='start_txt'}

+
+ +
+
+ +
+

{tmpl_var name='stop_txt'}

+
+ +
+
+ +
+

{tmpl_var name='restart_txt'}

+
+ +
+
+ +
+

{tmpl_var name='ostemplate_txt'}

+
+ +  {tmpl_var name='ostemplate_desc_txt'} +
+
+ + + +
+ + +
+
+
+ +
diff --git a/interface/web/vm/templates/openvz_vm_list.htm b/interface/web/vm/templates/openvz_vm_list.htm index 6eba7cfadf1720b05e6d664298ac57a656f81d4d..08bfab4af253cb3013074863a5eaaaedfe847693 100644 --- a/interface/web/vm/templates/openvz_vm_list.htm +++ b/interface/web/vm/templates/openvz_vm_list.htm @@ -49,7 +49,8 @@ {tmpl_var name="ip_address"}
- {tmpl_var name='delete_txt'} +   + {tmpl_var name='delete_txt'}
diff --git a/server/mods-available/remoteaction_core_module.inc.php b/server/mods-available/remoteaction_core_module.inc.php index 6bf3ad39879f8ae5e6b1679f71035e87562e127b..678b4befa11fd988b9685b72e0e593c6705310a9 100644 --- a/server/mods-available/remoteaction_core_module.inc.php +++ b/server/mods-available/remoteaction_core_module.inc.php @@ -126,6 +126,41 @@ class remoteaction_core_module { * we stop executing the actions not to waste more time */ return; } + if ($action['action_type'] == 'openvz_start_vm') { + $veid = intval($action['action_param']); + if($veid > 0) { + exec("vzctl start $veid"); + } + } + if ($action['action_type'] == 'openvz_stop_vm') { + $veid = intval($action['action_param']); + if($veid > 0) { + exec("vzctl stop $veid"); + } + } + if ($action['action_type'] == 'openvz_restart_vm') { + $veid = intval($action['action_param']); + if($veid > 0) { + exec("vzctl restart $veid"); + } + } + if ($action['action_type'] == 'openvz_create_ostpl') { + $parts = explode(':',$action['action_param']); + $veid = intval($parts[0]); + $template_cache_dir = '/vz/template/cache/'; + $template_name = escapeshellcmd($parts[1]); + if($veid > 0 && $template_name != '' && is_dir($template_cache_dir)) { + $command = "vzdump --suspend --compress --stdexcludes --dumpdir $template_cache_dir $veid"; + exec($command); + exec("mv ".$template_cache_dir."vzdump-openvz-".$veid."*.tgz ".$template_cache_dir.$template_name.".tar.gz"); + exec("rm -f ".$template_cache_dir."vzdump-openvz-".$veid."*.log"); + } + /* this action takes so much time, + * we stop executing the actions not to waste more time */ + return; + } + + } } }