Skip to content

Commit a4657cb

Browse files
author
Florian Schaal
committed
FS#2108 - Add option to set multiple ip addressses for a openvz container
FS#2006 - IPv6 Support for V-Server
1 parent eb1177f commit a4657cb

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

interface/lib/plugins/vm_openvz_plugin.inc.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ function openvz_vm_insert($event_name, $page_form) {
6060
// Set the IP address
6161
$app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
6262

63+
// Set additional IPs
64+
if (isset($this->dataRecord['additional_ip'])) {
65+
$app->db->query("UPDATE openvz_ip SET vm_id = 0, additional = 'n' WHERE vm_id = ? AND additional='y'", $this->id);
66+
foreach ($this->dataRecord['additional_ip'] as $idx => $rec) {
67+
$app->db->query("UPDATE openvz_ip SET vm_id = ?, additional = 'y' WHERE ip_address = ?", $this->id, $rec);
68+
}
69+
}
70+
6371
// Create the OpenVZ config file and store it in config field
6472
$this->makeOpenVZConfig();
6573

@@ -95,8 +103,16 @@ function openvz_vm_update($event_name, $page_form) {
95103

96104
// Set the IP address
97105
if(isset($this->dataRecord['ip_address'])) {
98-
$app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = ?", $this->id);
99-
$app->db->query("UPDATE openvz_ip SET vm_id = ? WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
106+
$app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = ? AND additional='n'", $this->id);
107+
$app->db->query("UPDATE openvz_ip SET vm_id = ?, additional = 'n' WHERE ip_address = ?", $this->id, $this->dataRecord['ip_address']);
108+
}
109+
110+
// Set additional IPs
111+
if (isset($this->dataRecord['additional_ip'])) {
112+
$app->db->query("UPDATE openvz_ip SET vm_id = 0, additional = 'n' WHERE (vm_id = ? AND additional='y')", $this->id);
113+
foreach ($this->dataRecord['additional_ip'] as $idx => $rec) {
114+
$app->db->query("UPDATE openvz_ip SET vm_id = ?, additional = 'y' WHERE ip_address = ?", $this->id, $rec);
115+
}
100116
}
101117

102118
// Create the OpenVZ config file and store it in config field
@@ -195,6 +211,17 @@ private function makeOpenVZConfig() {
195211
$hostname = str_replace('{VEID}', $vm['veid'], $vm['hostname']);
196212

197213
$tpl->setVar('hostname', $hostname);
214+
215+
$additional_ips = $app->db->queryAllRecords("SELECT * FROM openvz_ip WHERE vm_id = ?",$this->id);
216+
if (isset($additional_ips)) {
217+
$vm['ip_address']='';
218+
foreach ($additional_ips as $ip) {
219+
$vm['ip_address'] .= " ".$ip['ip_address'];
220+
}
221+
$vm['ip_address'] = substr($vm['ip_address'],1);
222+
}
223+
$tpl->setVar('ip_address', $vm['ip_address']);
224+
198225
$tpl->setVar('ip_address', $vm['ip_address']);
199226
$tpl->setVar('nameserver', $vm['nameserver']);
200227
$tpl->setVar('capability', $vm['capability']);

interface/web/vm/form/openvz_vm.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@
327327
//#################################
328328
)
329329
);
330+
331+
$form["tabs"]['additional_ip'] = array (
332+
'title' => "Additional IP",
333+
'width' => 100,
334+
'template' => "templates/openvz_vm_additional_ip_edit.htm",
335+
);
330336
}
331337

332338

interface/web/vm/openvz_vm_edit.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ function onShowEnd() {
178178
$app->tpl->setVar("ip_address", $ip_select);
179179
unset($tmp);
180180
unset($ips);
181+
182+
//* Additional IPs
183+
$sql="SELECT * FROM openvz_ip WHERE reserved = 'n' AND ((vm_id = ? AND additional='y') OR vm_id = 0) AND server_id = ?";
184+
$additional_ips = $app->db->queryAllRecords($sql, $this->id, $vm_server_id);
185+
foreach ($additional_ips as $idx => $rec) {
186+
$temp .= "<input type='hidden' id='id".$idx."' name='additional_ip[".$idx."]' name='additional_ip[".$idx."]' value='0'>";
187+
$used = @($rec['additional']=='y')?'CHECKED':'';
188+
$temp .= "<input type='checkbox' value='".$rec['ip_address']."' id='id".$idx."' name='additional_ip[".$idx."]' ".$used."> ".$rec['ip_address']."<br>";
189+
}
190+
$app->tpl->setVar("additional_ip", $temp);
191+
unset($used);
192+
unset($temp);
193+
unset($additional_ips);
181194

182195
if($this->id > 0) {
183196
//* we are editing a existing record
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class='page-header'></div>
2+
<p><tmpl_var name="list_desc_txt"></p>
3+
4+
<legend>Additional IPs</legend>
5+
6+
<div class="form-group">
7+
<div class="col-sm-3">
8+
{tmpl_var name='additional_ip'}
9+
</div>
10+
</div>
11+
12+
<input type="hidden" name="id" value="{tmpl_var name='id'}">
13+
14+
<div class="clear"><div class="right">
15+
<button class="btn btn-default formbutton-success" type="button" value="{tmpl_var name='btn_save_txt'}" data-submit-form="pageForm" data-form-action="vm/openvz_vm_edit.php">{tmpl_var name='btn_save_txt'}</button>
16+
<button class="btn btn-default formbutton-default" type="button" value="{tmpl_var name='btn_cancel_txt'}" data-load-content="vm/openvz_vm_list.php">{tmpl_var name='btn_cancel_txt'}</button>
17+
</div></div>
18+
19+

0 commit comments

Comments
 (0)