From d03323d167435f14e65b20475ce4d6e257c7ce43 Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Wed, 06 Jun 2012 08:08:47 -0400 Subject: [PATCH] Fixed: FS#2118 - IP addresses dont get loaded into list of openvz container when the server is changed --- interface/web/vm/templates/openvz_vm_edit.htm | 2 interface/web/vm/ajax_get_ip.php | 55 +++++++++++++++++++++++++++ interface/web/vm/openvz_vm_edit.php | 21 ++++++++++ interface/web/vm/form/openvz_vm.tform.php | 2 + 4 files changed, 79 insertions(+), 1 deletions(-) diff --git a/interface/web/vm/ajax_get_ip.php b/interface/web/vm/ajax_get_ip.php new file mode 100644 index 0000000..b6963ad --- /dev/null +++ b/interface/web/vm/ajax_get_ip.php @@ -0,0 +1,55 @@ +<?php + +/* +Copyright (c) 2012, Till Brehm, ISPConfig UG +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of ISPConfig nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once('../../lib/config.inc.php'); +require_once('../../lib/app.inc.php'); + +//* Check permissions for module +$app->auth->check_module_permissions('vm'); + +$server_id = intval($_GET["server_id"]); + +if($_SESSION["s"]["user"]["typ"] == 'admin' or $app->auth->has_clients($_SESSION['s']['user']['userid'])) { + + $sql = "SELECT ip_address FROM openvz_ip WHERE reserved = 'n' AND server_id = $server_id"; + $ips = $app->db->queryAllRecords($sql); + $ip_select = ""; + if(is_array($ips)) { + foreach( $ips as $ip) { + //$selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':''; + $ip_select .= "$ip[ip_address]#"; + } + } + unset($tmp); + unset($ips); +} +$ip_select = substr($ip_select,0,-1); +echo $ip_select; +?> \ No newline at end of file diff --git a/interface/web/vm/form/openvz_vm.tform.php b/interface/web/vm/form/openvz_vm.tform.php index 3d75e84..280473a 100644 --- a/interface/web/vm/form/openvz_vm.tform.php +++ b/interface/web/vm/form/openvz_vm.tform.php @@ -100,11 +100,13 @@ 'errmsg'=> 'ip_address_error_empty'), ), 'default' => '', + /* 'datasource' => array ( 'type' => 'SQL', 'querystring' => "SELECT ip_address FROM openvz_ip WHERE reserved = 'n' AND (vm_id = 0 or vm_id = '{RECORDID}') ORDER BY ip_address", 'keyfield'=> 'ip_address', 'valuefield'=> 'ip_address' ), + */ 'value' => '' ), 'hostname' => array ( diff --git a/interface/web/vm/openvz_vm_edit.php b/interface/web/vm/openvz_vm_edit.php index eefe4f0..e5bd211 100644 --- a/interface/web/vm/openvz_vm_edit.php +++ b/interface/web/vm/openvz_vm_edit.php @@ -157,6 +157,27 @@ } + //* Fill the IPv4 select field with the IP addresses that are allowed for this client + //$sql = "SELECT ip_address FROM server_ip WHERE server_id = ".$client['default_webserver']." AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"; + if(isset($this->dataRecord["server_id"])) { + $vm_server_id = intval($this->dataRecord["server_id"]); + } else { + $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE vserver_server = 1 AND mirror_server_id = 0 ORDER BY server_name LIMIT 0,1'); + $vm_server_id = $tmp['server_id']; + } + $sql = "SELECT ip_address FROM openvz_ip WHERE reserved = 'n' AND (vm_id = 0 or vm_id = '".$this->id."') AND server_id = ".$vm_server_id." ORDER BY ip_address"; + $ips = $app->db->queryAllRecords($sql); + $ip_select = ""; + if(is_array($ips)) { + foreach( $ips as $ip) { + $selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':''; + $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n"; + } + } + $app->tpl->setVar("ip_address",$ip_select); + unset($tmp); + unset($ips); + if($this->id > 0) { //* we are editing a existing record $app->tpl->setVar("edit_disabled", 1); diff --git a/interface/web/vm/templates/openvz_vm_edit.htm b/interface/web/vm/templates/openvz_vm_edit.htm index c661570..9ffea3e 100644 --- a/interface/web/vm/templates/openvz_vm_edit.htm +++ b/interface/web/vm/templates/openvz_vm_edit.htm @@ -15,7 +15,7 @@ <input type="hidden" name="server_id" value="{tmpl_var name='server_id_value'}" /> <tmpl_else> <label for="server_id">{tmpl_var name='server_id_txt'}</label> - <select name="server_id" id="server_id" class="selectInput" onChange="loadOptionInto('ip_address','sites/ajax_get_ip.php?server_id='+document.getElementById('server_id').value)"> + <select name="server_id" id="server_id" class="selectInput" onChange="loadOptionInto('ip_address','vm/ajax_get_ip.php?server_id='+document.getElementById('server_id').value)"> {tmpl_var name='server_id'} </select> </tmpl_if> -- Gitblit v1.9.1