Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
b74ef5 1 <?php
T 2 /*
3 Copyright (c) 2005 - 2010, Till Brehm, projektfarm Gmbh
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/openvz_vm.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
7fe908 41 require_once '../../lib/config.inc.php';
MC 42 require_once '../../lib/app.inc.php';
b74ef5 43
T 44 //* Check permissions for module
45 $app->auth->check_module_permissions('vm');
46
47 // Loading classes
48 $app->uses('tpl,tform');
49 $app->load('tform_actions');
50
51 class page_action extends tform_actions {
52
f414ab 53     function onShowNew() {
T 54         global $app, $conf;
7fe908 55
f414ab 56         // we will check only users, not admins
T 57         if($_SESSION["s"]["user"]["typ"] == 'user') {
58             if(!$app->tform->checkClientLimit('limit_openvz_vm')) {
59                 $app->error($app->tform->wordbook["limit_openvz_vm_txt"]);
60             }
61             if(!$app->tform->checkResellerLimit('limit_openvz_vm')) {
62                 $app->error('Reseller: '.$app->tform->wordbook["limit_openvz_vm_txt"]);
63             }
64         }
7fe908 65
f414ab 66         parent::onShowNew();
T 67     }
7fe908 68
b74ef5 69     function onShowEnd() {
T 70         global $app, $conf;
71
72         //* Client: If the logged in user is not admin and has no sub clients (no rseller)
73         if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
7fe908 74
f414ab 75             //* Get the limits of the client
dce3bb 76             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
cc7a82 77             $client = $app->db->queryOneRecord("SELECT client.client_id, client.contact_name, client.limit_openvz_vm_template_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
7fe908 78
f414ab 79             //* Fill the template_id field
T 80             if($client['limit_openvz_vm_template_id'] == 0) {
81                 $sql = 'SELECT template_id,template_name FROM openvz_template WHERE 1 ORDER BY template_name';
82             } else {
2af58c 83                 $sql = 'SELECT template_id,template_name FROM openvz_template WHERE template_id = ? ORDER BY template_name';
f414ab 84             }
2af58c 85             $records = $app->db->queryAllRecords($sql, $client['limit_openvz_vm_template_id']);
f414ab 86             if(is_array($records)) {
T 87                 foreach( $records as $rec) {
88                     $selected = @($rec["template_id"] == $this->dataRecord["template_id"])?'SELECTED':'';
89                     $template_id_select .= "<option value='$rec[template_id]' $selected>$rec[template_name]</option>\r\n";
90                 }
91             }
7fe908 92             $app->tpl->setVar("template_id_select", $template_id_select);
MC 93
b74ef5 94             //* Reseller: If the logged in user is not admin and has sub clients (is a rseller)
T 95         } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
7fe908 96
46598e 97             //* Get the limits of the client
b74ef5 98             $client_group_id = $_SESSION["s"]["user"]["default_group"];
cc7a82 99             $client = $app->db->queryOneRecord("SELECT client.client_id, client.contact_name, client.limit_openvz_vm_template_id, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname, sys_group.name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
7fe908 100
MC 101
46598e 102             //* Fill the client select field
2af58c 103             $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ? ORDER BY client.company_name, client.contact_name, sys_group.name";
MC 104             $records = $app->db->queryAllRecords($sql, $client['client_id']);
105             $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']);
615a0a 106             $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
8ab3cd 107             //$tmp_data_record = $app->tform->getDataRecord($this->id);
b74ef5 108             if(is_array($records)) {
T 109                 foreach( $records as $rec) {
8ab3cd 110                     $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
615a0a 111                     $client_select .= "<option value='$rec[groupid]' $selected>$rec[contactname]</option>\r\n";
b74ef5 112                 }
T 113             }
7fe908 114             $app->tpl->setVar("client_group_id", $client_select);
MC 115
f414ab 116             //* Fill the template_id field
T 117             if($client['limit_openvz_vm_template_id'] == 0) {
118                 $sql = 'SELECT template_id,template_name FROM openvz_template WHERE 1 ORDER BY template_name';
119             } else {
2af58c 120                 $sql = 'SELECT template_id,template_name FROM openvz_template WHERE template_id = ? ORDER BY template_name';
f414ab 121             }
2af58c 122             $records = $app->db->queryAllRecords($sql, $client['limit_openvz_vm_template_id']);
f414ab 123             if(is_array($records)) {
T 124                 foreach( $records as $rec) {
125                     $selected = @($rec["template_id"] == $this->dataRecord["template_id"])?'SELECTED':'';
126                     $template_id_select .= "<option value='$rec[template_id]' $selected>$rec[template_name]</option>\r\n";
127                 }
128             }
7fe908 129             $app->tpl->setVar("template_id_select", $template_id_select);
b74ef5 130
T 131             //* Admin: If the logged in user is admin
132         } else {
133
46598e 134             //* Fill the client select field
ca4b71 135             $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
b74ef5 136             $clients = $app->db->queryAllRecords($sql);
T 137             $client_select = "<option value='0'></option>";
8ab3cd 138             //$tmp_data_record = $app->tform->getDataRecord($this->id);
b74ef5 139             if(is_array($clients)) {
T 140                 foreach( $clients as $client) {
8ab3cd 141                     $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
615a0a 142                     $client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
b74ef5 143                 }
T 144             }
7fe908 145             $app->tpl->setVar("client_group_id", $client_select);
MC 146
f414ab 147             //* Fill the template_id field
T 148             $sql = 'SELECT template_id,template_name FROM openvz_template WHERE 1 ORDER BY template_name';
149             $records = $app->db->queryAllRecords($sql);
150             if(is_array($records)) {
a8b07f 151                 $template_id_select='';
f414ab 152                 foreach( $records as $rec) {
T 153                     $selected = @($rec["template_id"] == $this->dataRecord["template_id"])?'SELECTED':'';
154                     $template_id_select .= "<option value='$rec[template_id]' $selected>$rec[template_name]</option>\r\n";
155                 }
156             }
7fe908 157             $app->tpl->setVar("template_id_select", $template_id_select);
b74ef5 158
T 159         }
7fe908 160
26c0fc 161         //* Fill the IPv4 select field with the IP addresses that are allowed for this client
T 162         //$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'].")";
163         if(isset($this->dataRecord["server_id"])) {
782f4a 164 //            $vm_server_id = $app->functions->intval($this->dataRecord["server_id"]);
FS 165             $vm_server_id = $app->functions->intval($this->dataRecord["vm_id"]);
26c0fc 166         } else {
T 167             $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');
dce3bb 168             $vm_server_id = $app->functions->intval($tmp['server_id']);
26c0fc 169         }
2af58c 170         $sql = "SELECT ip_address FROM openvz_ip WHERE reserved = 'n' AND (vm_id = 0 or vm_id = ?) AND server_id = ? ORDER BY ip_address";
MC 171         $ips = $app->db->queryAllRecords($sql, $this->id, $vm_server_id);
26c0fc 172         $ip_select = "";
T 173         if(is_array($ips)) {
174             foreach( $ips as $ip) {
175                 $selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
176                 $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
177             }
178         }
7fe908 179         $app->tpl->setVar("ip_address", $ip_select);
26c0fc 180         unset($tmp);
T 181         unset($ips);
a4657c 182         
FS 183         //* Additional IPs
184         $sql="SELECT * FROM openvz_ip WHERE reserved = 'n' AND ((vm_id = ? AND additional='y') OR vm_id = 0) AND server_id = ?";
185         $additional_ips = $app->db->queryAllRecords($sql, $this->id, $vm_server_id);
186         foreach ($additional_ips as $idx => $rec) {
187             $temp .= "<input type='hidden' id='id".$idx."' name='additional_ip[".$idx."]' name='additional_ip[".$idx."]'  value='0'>";
188             $used = @($rec['additional']=='y')?'CHECKED':'';
189             $temp .= "<input type='checkbox' value='".$rec['ip_address']."' id='id".$idx."' name='additional_ip[".$idx."]' ".$used.">   ".$rec['ip_address']."<br>";
190         }
191         $app->tpl->setVar("additional_ip", $temp);
192         unset($used);
193         unset($temp);
194         unset($additional_ips);
7fe908 195
b74ef5 196         if($this->id > 0) {
T 197             //* we are editing a existing record
198             $app->tpl->setVar("edit_disabled", 1);
199             $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
200             $app->tpl->setVar("ostemplate_id_value", $this->dataRecord["ostemplate_id"]);
201         } else {
202             $app->tpl->setVar("edit_disabled", 0);
203         }
204
b2673a 205         // Datepicker
F 206         $date_format = $app->lng('conf_format_dateshort');
207         $trans = array("d" => "dd", "m" => "mm", "Y" => "yy");
208         $date_format = strtr($date_format, $trans);
7fe908 209         $app->tpl->setVar("date_format", $date_format);
43e5b6 210         $app->tpl->setVar("conf_format_datetime_js", strtr($app->lng('conf_format_dateshort'), array('d' => 'dd', 'm' => 'mm', 'Y' => 'yyyy', 'y' => 'yy', 'H' => 'hh', 'h' => 'HH', 'i' => 'ii')));
7fe908 211
2fb920 212         $app->tpl->setVar("daynamesmin_su", $app->lng('daynamesmin_su'));
F 213         $app->tpl->setVar("daynamesmin_mo", $app->lng('daynamesmin_mo'));
214         $app->tpl->setVar("daynamesmin_tu", $app->lng('daynamesmin_tu'));
215         $app->tpl->setVar("daynamesmin_we", $app->lng('daynamesmin_we'));
216         $app->tpl->setVar("daynamesmin_th", $app->lng('daynamesmin_th'));
217         $app->tpl->setVar("daynamesmin_fr", $app->lng('daynamesmin_fr'));
218         $app->tpl->setVar("daynamesmin_sa", $app->lng('daynamesmin_sa'));
7fe908 219
2fb920 220         $app->tpl->setVar("daynames_sunday", $app->lng('daynames_sunday'));
F 221         $app->tpl->setVar("daynames_monday", $app->lng('daynames_monday'));
222         $app->tpl->setVar("daynames_tuesday", $app->lng('daynames_tuesday'));
223         $app->tpl->setVar("daynames_wednesday", $app->lng('daynames_wednesday'));
224         $app->tpl->setVar("daynames_thursday", $app->lng('daynames_thursday'));
225         $app->tpl->setVar("daynames_friday", $app->lng('daynames_friday'));
226         $app->tpl->setVar("daynames_saturday", $app->lng('daynames_saturday'));
7fe908 227
2fb920 228         $app->tpl->setVar("monthnamesshort_jan", $app->lng('monthnamesshort_jan'));
F 229         $app->tpl->setVar("monthnamesshort_feb", $app->lng('monthnamesshort_feb'));
230         $app->tpl->setVar("monthnamesshort_mar", $app->lng('monthnamesshort_mar'));
231         $app->tpl->setVar("monthnamesshort_apr", $app->lng('monthnamesshort_apr'));
232         $app->tpl->setVar("monthnamesshort_may", $app->lng('monthnamesshort_may'));
233         $app->tpl->setVar("monthnamesshort_jun", $app->lng('monthnamesshort_jun'));
234         $app->tpl->setVar("monthnamesshort_jul", $app->lng('monthnamesshort_jul'));
235         $app->tpl->setVar("monthnamesshort_aug", $app->lng('monthnamesshort_aug'));
236         $app->tpl->setVar("monthnamesshort_sep", $app->lng('monthnamesshort_sep'));
237         $app->tpl->setVar("monthnamesshort_oct", $app->lng('monthnamesshort_oct'));
238         $app->tpl->setVar("monthnamesshort_nov", $app->lng('monthnamesshort_nov'));
7fe908 239         $app->tpl->setVar("monthnamesshort_dec", $app->lng('monthnamesshort_dec'));
MC 240
b2673a 241         $app->tpl->setVar("datepicker_nextText", $app->lng('datepicker_nextText'));
F 242         $app->tpl->setVar("datepicker_prevText", $app->lng('datepicker_prevText'));
7fe908 243
b74ef5 244         parent::onShowEnd();
T 245     }
246
247     function onSubmit() {
248         global $app, $conf;
249
46598e 250         //* Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller
b74ef5 251         if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
T 252
253         parent::onSubmit();
254     }
255
256 }
257
258 $page = new page_action;
259 $page->onLoad();
260
7fe908 261 ?>