Jesse Norell
2015-07-14 411a6f5299c2894a27ba26e4c0531b36615216ee
interface/lib/plugins/vm_openvz_plugin.inc.php
@@ -60,6 +60,14 @@
      // Set the IP address
      $app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
      // Set additional IPs
      if (isset($this->dataRecord['additional_ip'])) {
         $app->db->query("UPDATE openvz_ip SET vm_id = 0, additional = 'n' WHERE vm_id = ? AND additional='y'", $this->id);
         foreach ($this->dataRecord['additional_ip'] as $idx => $rec) {
            $app->db->query("UPDATE openvz_ip SET vm_id = ?, additional = 'y' WHERE ip_address = ?", $this->id, $rec);
         }
      }
      // Create the OpenVZ config file and store it in config field
      $this->makeOpenVZConfig();
@@ -94,7 +102,18 @@
      }
      // Set the IP address
      if(isset($this->dataRecord['ip_address'])) $app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
      if(isset($this->dataRecord['ip_address'])) {
         $app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = ? AND additional='n'", $this->id);
         $app->db->query("UPDATE openvz_ip SET vm_id = ?, additional = 'n' WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
      }
      // Set additional IPs
      if (isset($this->dataRecord['additional_ip'])) {
         $app->db->query("UPDATE openvz_ip SET vm_id = 0, additional = 'n' WHERE (vm_id = ? AND additional='y')", $this->id);
         foreach ($this->dataRecord['additional_ip'] as $idx => $rec) {
            $app->db->query("UPDATE openvz_ip SET vm_id = ?, additional = 'y' WHERE ip_address = ?", $this->id, $rec);
         }
      }
      // Create the OpenVZ config file and store it in config field
      $this->makeOpenVZConfig();
@@ -111,10 +130,10 @@
      global $app, $conf;
      //* Free the IP address
      $tmp = $app->db->queryOneRecord("SELECT ip_address_id FROM openvz_ip WHERE vm_id = ?", $page_form->id);
      $app->db->datalogUpdate('openvz_ip', 'vm_id = 0', 'ip_address_id', $tmp['ip_address_id']);
      unset($tmp);
      $tmp_rec = $app->db->queryAllRecords("SELECT ip_address_id FROM openvz_ip WHERE vm_id = ?", $page_form->id);
      foreach ($tmp_rec as $tmp) {
         $app->db->datalogUpdate('openvz_ip', array('vm_id' => 0), 'ip_address_id', $tmp['ip_address_id']);
      }
   }
   private function applyTemplate() {
@@ -132,9 +151,12 @@
      $sql .= "io_priority = ?, ";
      $sql .= "nameserver = ?, ";
      $sql .= "create_dns = ?, ";
      $sql .= "capability = ? ";
      $sql .= "capability = ?, ";
      $sql .= "features = ?, ";
      $sql .= "iptables = ? ";
      $sql .= "custom = ? ";
      $sql .= "WHERE vm_id = ?";
      $app->db->query($sql, $tpl['diskspace'], $tpl['ram'], $tpl['ram_burst'], $tpl['cpu_units'], $tpl['cpu_num'], $tpl['cpu_limit'], $tpl['io_priority'], $tpl['nameserver'], $tpl['create_dns'], $tpl['capability'], $this->id);
      $app->db->query($sql, $tpl['diskspace'], $tpl['ram'], $tpl['ram_burst'], $tpl['cpu_units'], $tpl['cpu_num'], $tpl['cpu_limit'], $tpl['io_priority'], $tpl['nameserver'], $tpl['create_dns'], $tpl['capability'], $tpl['features'], $tpl['iptables'], $tpl['custom'], $this->id);
   }
@@ -153,13 +175,14 @@
      $onboot = ($vm['start_boot'] == 'y')?'yes':'no';
      $tpl->setVar('onboot', $onboot);
      $tpl->setVar('bootorder', $vm['bootorder']);
      $tpl->setVar('kmemsize', $vm_template['kmemsize']);
      $tpl->setVar('lockedpages', $vm_template['lockedpages']);
      $tpl->setVar('privvmpages', $burst_ram.':'.$burst_ram);
      $tpl->setVar('privvmpages', $burst_ram.':'.$burst_ram*1.0625);
      $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('vmguarpages', $guar_ram.':unlimited');
      $tpl->setVar('oomguarpages', $guar_ram.':'.$guar_ram);
      $tpl->setVar('numtcpsock', $vm_template['numtcpsock']);
      $tpl->setVar('numflock', $vm_template['numflock']);
@@ -190,9 +213,24 @@
      $hostname = str_replace('{VEID}', $vm['veid'], $vm['hostname']);
      $tpl->setVar('hostname', $hostname);
      $additional_ips = $app->db->queryAllRecords("SELECT * FROM openvz_ip WHERE vm_id = ?",$this->id);
      if (isset($additional_ips)) {
         $vm['ip_address']='';
         foreach ($additional_ips as $ip) {
            $vm['ip_address'] .= " ".$ip['ip_address'];
         }
         $vm['ip_address'] = substr($vm['ip_address'],1);
      }
      $tpl->setVar('ip_address', $vm['ip_address']);
      $tpl->setVar('ip_address', $vm['ip_address']);
      $tpl->setVar('nameserver', $vm['nameserver']);
      $tpl->setVar('capability', $vm['capability']);
      $tpl->setVar('features', $vm['features']);
      $tpl->setVar('iptables', $vm['iptables']);
      $tpl->setVar('custom', $vm['custom']);
      $tmp = $app->db->queryOneRecord("SELECT template_file FROM openvz_ostemplate WHERE ostemplate_id = ?", $app->functions->intval($vm['ostemplate_id']));
      $tpl->setVar('ostemplate', $tmp['template_file']);
@@ -214,9 +252,9 @@
      $full_hostname = str_replace('{VEID}', $vm['veid'], $vm['hostname']);
      $hostname_parts = explode('.', $full_hostname);
      $hostname = $app->db->quote($hostname_parts[0]);
      $hostname = $hostname_parts[0];
      unset($hostname_parts[0]);
      $zone = $app->db->quote((implode('.', $hostname_parts)));
      $zone = implode('.', $hostname_parts);
      unset($hostname_parts);
      // Find the dns zone
@@ -224,7 +262,7 @@
      $rr_rec = $app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = ? AND name = ?", $zone_rec['id'], $hostname);
      if($zone_rec['id'] > 0) {
         $ip_address = $app->db->quote($vm['ip_address']);
         $ip_address = $vm['ip_address'];
         $sys_userid = $app->functions->intval($zone_rec['sys_userid']);
         $sys_groupid = $app->functions->intval($zone_rec['sys_groupid']);
         $server_id = $app->functions->intval($zone_rec['server_id']);
@@ -232,12 +270,25 @@
         if($rr_rec['id'] > 0) {
            $app->uses('validate_dns');
            $app->db->datalogUpdate('dns_rr', "data = '$ip_address'", 'id', $app->functions->intval($rr_rec['id']));
            $app->db->datalogUpdate('dns_rr', array("data" => $ip_address), 'id', $app->functions->intval($rr_rec['id']));
            $serial = $app->validate_dns->increase_serial($zone_rec['serial']);
            $app->db->datalogUpdate('dns_soa', "serial = '$serial'", 'id', $app->functions->intval($zone_rec['id']));
            $app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $app->functions->intval($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')";
            $insert_data = array(
               "sys_userid" => $sys_userid,
               "sys_groupid" => $sys_groupid,
               "sys_perm_user" => 'riud',
               "sys_perm_group" => 'riud',
               "sys_perm_other" => '',
               "server_id" => $server_id,
               "zone" => $dns_soa_id,
               "name" => $hostname,
               "type" => @(preg_match("/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/", $ip_address))?'A':'AAAA',
               "data" => $ip_address,
               "aux" => '0',
               "ttl" => '3600',
               "active" => 'Y'
            );
            $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
         }