From a4657cb063ce020550e8ff523ead765c05ad4782 Mon Sep 17 00:00:00 2001 From: Florian Schaal Date: Wed, 26 Aug 2015 22:13:45 +0200 Subject: [PATCH] FS#2108 - Add option to set multiple ip addressses for a openvz container FS#2006 - IPv6 Support for V-Server --- .../lib/plugins/vm_openvz_plugin.inc.php | 31 +++++++++++++++++-- interface/web/vm/form/openvz_vm.tform.php | 6 ++++ interface/web/vm/openvz_vm_edit.php | 13 ++++++++ .../openvz_vm_additional_ip_edit.htm | 19 ++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 interface/web/vm/templates/openvz_vm_additional_ip_edit.htm diff --git a/interface/lib/plugins/vm_openvz_plugin.inc.php b/interface/lib/plugins/vm_openvz_plugin.inc.php index 7cbf843d3..305118d33 100644 --- a/interface/lib/plugins/vm_openvz_plugin.inc.php +++ b/interface/lib/plugins/vm_openvz_plugin.inc.php @@ -60,6 +60,14 @@ class vm_openvz_plugin { // 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(); @@ -95,8 +103,16 @@ class vm_openvz_plugin { // Set the IP address if(isset($this->dataRecord['ip_address'])) { - $app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = ?", $this->id); - $app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $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 @@ -195,6 +211,17 @@ class vm_openvz_plugin { $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']); diff --git a/interface/web/vm/form/openvz_vm.tform.php b/interface/web/vm/form/openvz_vm.tform.php index 666d06cf3..d6911ccfd 100644 --- a/interface/web/vm/form/openvz_vm.tform.php +++ b/interface/web/vm/form/openvz_vm.tform.php @@ -327,6 +327,12 @@ if($_SESSION["s"]["user"]["typ"] == 'admin') { //################################# ) ); + + $form["tabs"]['additional_ip'] = array ( + 'title' => "Additional IP", + 'width' => 100, + 'template' => "templates/openvz_vm_additional_ip_edit.htm", + ); } diff --git a/interface/web/vm/openvz_vm_edit.php b/interface/web/vm/openvz_vm_edit.php index 07f6aaa53..0db2053a3 100644 --- a/interface/web/vm/openvz_vm_edit.php +++ b/interface/web/vm/openvz_vm_edit.php @@ -178,6 +178,19 @@ class page_action extends tform_actions { $app->tpl->setVar("ip_address", $ip_select); unset($tmp); unset($ips); + + //* Additional IPs + $sql="SELECT * FROM openvz_ip WHERE reserved = 'n' AND ((vm_id = ? AND additional='y') OR vm_id = 0) AND server_id = ?"; + $additional_ips = $app->db->queryAllRecords($sql, $this->id, $vm_server_id); + foreach ($additional_ips as $idx => $rec) { + $temp .= ""; + $used = @($rec['additional']=='y')?'CHECKED':''; + $temp .= " ".$rec['ip_address']."
"; + } + $app->tpl->setVar("additional_ip", $temp); + unset($used); + unset($temp); + unset($additional_ips); if($this->id > 0) { //* we are editing a existing record diff --git a/interface/web/vm/templates/openvz_vm_additional_ip_edit.htm b/interface/web/vm/templates/openvz_vm_additional_ip_edit.htm new file mode 100644 index 000000000..f19eb6ca9 --- /dev/null +++ b/interface/web/vm/templates/openvz_vm_additional_ip_edit.htm @@ -0,0 +1,19 @@ + +

+ +Additional IPs + +
+
+ {tmpl_var name='additional_ip'} +
+
+ + + +
+ + +
+ + -- GitLab