From 7b26eae1b657e81aefe2a50e1c15518f0f6ee935 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Thu, 27 Aug 2015 02:45:37 -0400
Subject: [PATCH] Merge branch 'master' into 'master'

---
 interface/lib/plugins/vm_openvz_plugin.inc.php |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/interface/lib/plugins/vm_openvz_plugin.inc.php b/interface/lib/plugins/vm_openvz_plugin.inc.php
index 7cbf843..305118d 100644
--- a/interface/lib/plugins/vm_openvz_plugin.inc.php
+++ b/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();
 
@@ -95,8 +103,16 @@
 
 		// 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 @@
 		$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']);

--
Gitblit v1.9.1