Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
6c424f 1 <?php
FS 2 /*
3 Copyright (c) 2015, Florian Schaal, schaal @it
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 $tform_def_file = "form/server_ip_map.tform.php";
31
32 require_once '../../lib/config.inc.php';
33 require_once '../../lib/app.inc.php';
34
35 //* Check permissions for module
36 $app->auth->check_module_permissions('admin');
37 $app->auth->check_security_permissions('admin_allow_server_ip');
38
39 // Loading classes
40 $app->uses('tpl,tform,tform_actions');
41 $app->load('tform_actions');
42
43 class page_action extends tform_actions {
44
45     function onShowEnd() {
46         global $app;
47
48         // server-list
49         $sql = "SELECT server_id, server_name FROM server WHERE mirror_server_id > 0 ORDER BY server_name";
50         $servers =  $app->db->queryAllRecords($sql);
51         $server_select = "<option value=''></option>";
52         if(is_array($servers)) {
53             foreach($servers as $server) {
54                 $selected = ($server['server_id'] == $this->dataRecord['server_id'])?'SELECTED':'';
55                 $server_select .= "<option value='$server[server_id]' $selected>$server[server_name]</option>\r\n";
56             }
57         }
58         unset($servers);
59         $app->tpl->setVar('server_id', $server_select);
60
61         // ip-list
bb2930 62         $sql = "SELECT server_ip.server_ip_id, server_ip.ip_address AS ip_address, server.server_name, CONCAT(server_ip.ip_address,' :: [', server.server_name, ']') AS source FROM server_ip, server WHERE (server_ip.server_id = server.server_id AND server.web_server =1 AND mirror_server_id = 0 AND virtualhost = 'y' AND IP_TYPE = 'IPv4')";
6c424f 63         $ips = $app->db->queryAllRecords($sql);
FS 64         $ip_select = "<option value=''></option>";
65         if(is_array($ips)) {
66             foreach( $ips as $ip) {
67                 $selected = ($ip['ip_address'] == $this->dataRecord['source_ip'])?'SELECTED':'';
68                 $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[source]</option>\r\n";
69             }
70         }
71         unset($ips);
72         $app->tpl->setVar('source_ip', $ip_select);
73
74         parent::onShowEnd();
75     }
76
77     function onBeforeInsert() {
78         global $app;
79
bb2930 80         if($this->dataRecord['server_id']=='') $app->tform->errorMessage .= $app->tform->wordbook['server_empty_error'];
FS 81
6c424f 82         $sql = "SELECT * FROM server_ip WHERE server_id = ? and ip_address = ?";
FS 83         $ip_check=$app->db->queryOneRecord($sql, $this->dataRecord['server_id'], $this->dataRecord['source_ip']);
bb2930 84         if (is_array($ip_check)) $app->tform->errorMessage .= $app->tform->wordbook['ip_mapping_error'];
6c424f 85
FS 86         $sql = 'SELECT count(*) as no FROM server_ip_map WHERE server_id = ? AND source_ip = ? AND destination_ip = ?';
87         $check = $app->db->queryOneRecord($sql, $this->dataRecord['server_id'], $this->dataRecord['source_ip'], $this->dataRecord['destination_ip']);
88         if ($check['no'] > 0) $app->tform->errorMessage .= $app->tform->wordbook['duplicate_mapping_error'];    
89     }
90
91     function onBeforeUpdate() {
92         global $app;
bb2930 93
FS 94         if($this->dataRecord['server_id']=='') $app->tform->errorMessage .= $app->tform->wordbook['server_empty_error'];
95
6c424f 96         $sql = "SELECT * FROM server_ip WHERE server_id = ? and ip_address = ?";
FS 97         $ip_check=$app->db->queryOneRecord($sql, $this->dataRecord['server_id'], $this->dataRecord['source_ip']);
bb2930 98         if (is_array($ip_check)) $app->tform->errorMessage .= $app->tform->wordbook['ip_mapping_error'];
6c424f 99
FS 100         $this->oldDataRecord = $app->tform->getDataRecord($this->id);
101         if ($this->dataRecord['source_ip'] != $this->oldDataRecord['source_ip'] || $this->dataRecord['destination_ip'] != $this->oldDataRecord['destination_ip']) {
102             $sql = 'SELECT count(*) as no FROM server_ip_map WHERE server_id = ? AND source_ip = ? AND destination_ip = ?';
103             $check = $app->db->queryOneRecord($sql, $this->dataRecord['server_id'], $this->dataRecord['source_ip'], $this->dataRecord['destination_ip']);
104             if ($check['no'] > 0) $app->tform->errorMessage .= $app->tform->wordbook['duplicate_mapping_error'];    
105         }
106     }
107
108 }
109
110 $page = new page_action;
111 $page->onLoad();
112
113 ?>