root/trunk/gui/admin/ip_manage.php

Revision 1372, 6.1 kB (checked in by rats, 1 month ago)

* Added Mailsize function
* Fixed #1594: (CentOS) More perl dependencies on CentOS
* Fixed #1595: (CentOS) CentOS perl docs: Advice to autoconfigure first
* Fixed #1483: Misleading information in INSTALL-files
* Fixed #1512: Subdomains for domain-aliases
* Fixed #1509: New subdomain management system
* Fixed Order delete bug
* Fixed #1507: Some errors on around "Execute Query" option on a database
* Fixed #1511: e-mail aliases & autoreply
* Fixed #1151: Update Hosting Package should only visible for a customer if a hosting plan to update is available (thanks Feg)
* Fixed #1556: Special Characters like Umlauts (äüöÄÜÖ) and Ligatures (ß) in Javascript messages are encoded, wrongly.
* PHPmyAdmin 3.0.0

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22
23 check_login(__FILE__);
24
25 $tpl = new pTemplate();
26
27 $tpl->define_dynamic('page', Config::get('ADMIN_TEMPLATE_PATH') . '/ip_manage.tpl');
28 $tpl->define_dynamic('page_message', 'page');
29 $tpl->define_dynamic('hosting_plans', 'page');
30 $tpl->define_dynamic('ip_row', 'page');
31 $tpl->define_dynamic('ip_delete_show', 'ip_row');
32 $tpl->define_dynamic('ip_delete_link', 'ip_row');
33
34 $theme_color = Config::get('USER_INITIAL_THEME');
35
36 $tpl->assign(
37         array(
38             'TR_ADMIN_IP_MANAGE_PAGE_TITLE' => tr('ispCP - Admin/IP manage'),
39             'THEME_COLOR_PATH' => "../themes/$theme_color",
40             'THEME_CHARSET' => tr('encoding'),
41             'ISP_LOGO' => get_logo($_SESSION['user_id'])
42         )
43     );
44
45 function show_IPs(&$tpl, &$sql) {
46     $query = <<<SQL_QUERY
47         select
48             *
49         from
50             server_ips
51 SQL_QUERY;
52
53     $rs = exec_query($sql, $query, array());
54
55     $row = 1;
56     $single = false;
57
58     if ($rs->RecordCount() < 2) {
59         $single = true;
60     }
61
62     while (!$rs->EOF) {
63         if ($row++ % 2 == 0) {
64             $tpl->assign('IP_CLASS', 'content');
65         } else {
66             $tpl->assign('IP_CLASS', 'content2');
67         }
68
69         $tpl->assign(
70                 array(
71                     'IP' => $rs->fields['ip_number'],
72                     'DOMAIN' => $rs->fields['ip_domain'],
73                     'ALIAS' => $rs->fields['ip_alias']
74                 )
75             );
76
77         if ($single == true) {
78             $tpl->assign(
79                         array(
80                             'IP_DELETE_LINK' => '',
81                             'TR_UNINSTALL' => ''
82                             )
83                         );
84             $tpl->parse('IP_DELETE_SHOW', 'ip_delete_show');
85         }
86         else {
87             $tpl->assign(
88                         array(
89                             'IP_DELETE_SHOW' => '',
90                             'TR_UNINSTALL' => tr('Remove IP'),
91                             'DELETE_ID' => $rs->fields['ip_id']
92                             )
93                         );
94             $tpl->parse('IP_DELETE_LINK', 'ip_delete_link');
95         }
96
97         $tpl->parse('IP_ROW', '.ip_row');
98
99         $rs->MoveNext();
100     } //while
101 }
102
103 function add_ip(&$tpl, &$sql) {
104     global $ip_number_1, $ip_number_2, $ip_number_3, $ip_number_4;
105
106     global $domain, $alias;
107
108     if (isset($_POST['uaction']) && $_POST['uaction'] === 'add_ip') {
109         if (check_user_data()) {
110             // add ip
111             global $ip_number_1, $ip_number_2, $ip_number_3, $ip_number_4;
112
113             $ip_number = trim($ip_number_1) . '.' . trim($ip_number_2) . '.' . trim($ip_number_3) . '.' . trim($ip_number_4);
114
115             $query = <<<SQL_QUERY
116                 insert into server_ips
117                     (ip_number, ip_domain, ip_alias)
118                 values
119                     (?, ?, ?)
120 SQL_QUERY;
121             $rs = exec_query($sql, $query, array($ip_number, htmlspecialchars($domain, ENT_QUOTES, "UTF-8"),
122             htmlspecialchars($alias, ENT_QUOTES, "UTF-8")));
123
124             set_page_message(tr('New IP was added!'));
125
126             $user_logged = $_SESSION['user_logged'];
127
128             write_log("$user_logged: adds new IPv4 address: $ip_number!");
129
130             $sucess = true;
131         }
132     }
133
134     if (!isset($sucess) && isset($_POST['ip_number_1'])) {
135         $tpl->assign(
136             array(
137                 'VALUE_IP1' => $_POST['ip_number_1'],
138                 'VALUE_IP2' => $_POST['ip_number_2'],
139                 'VALUE_IP3' => $_POST['ip_number_3'],
140                 'VALUE_IP4' => $_POST['ip_number_4'],
141                 'VALUE_DOMAIN' => clean_input($_POST['domain']),
142                 'VALUE_ALIAS' => clean_input($_POST['alias']),
143             )
144         );
145     } else {
146         $tpl->assign(
147             array(
148                 'VALUE_IP1' => '',
149                 'VALUE_IP2' => '',
150                 'VALUE_IP3' => '',
151                 'VALUE_IP4' => '',
152                 'VALUE_DOMAIN' => '',
153                 'VALUE_ALIAS' => '',
154             )
155         );
156     }
157 }
158
159 function check_user_data () {
160     global $ip_number_1, $ip_number_2, $ip_number_3, $ip_number_4;
161
162     $ip_number_1 = $_POST['ip_number_1'];
163     $ip_number_2 = $_POST['ip_number_2'];
164     $ip_number_3 = $_POST['ip_number_3'];
165     $ip_number_4 = $_POST['ip_number_4'];
166
167     global $domain, $alias;
168
169     $domain = clean_input($_POST['domain']);
170     $alias = clean_input($_POST['alias']);
171
172     $err_msg = '_off_';
173
174     if ($ip_number_1 < 0 || $ip_number_1 > 255 || !is_numeric($ip_number_1) ||
175         $ip_number_2 < 0 || $ip_number_2 > 255 || !is_numeric($ip_number_2) ||
176         $ip_number_3 < 0 || $ip_number_3 > 255 || !is_numeric($ip_number_3) ||
177         $ip_number_4 < 0 || $ip_number_4 > 255 || !is_numeric($ip_number_4)) {
178         $err_msg = tr('Wrong IP number!');
179     } else if ($domain == '') {
180         $err_msg = tr('Please specify domain!');
181     } else if ($alias == '') {
182         $err_msg = tr('Please specify alias!');
183     } else if (IP_exists()) {
184         $err_msg = tr('This IP already exist!');
185     }
186
187     if ($err_msg == '_off_') {
188         return true;
189     } else {
190         set_page_message($err_msg);
191
192         return false;
193     }
194 }
195
196 function IP_exists() {
197     $sql = Database::getInstance();
198
199     global $ip_number_1, $ip_number_2, $ip_number_3, $ip_number_4;
200
201     $ip_number = trim($ip_number_1) . '.' . trim($ip_number_2) . '.' . trim($ip_number_3) . '.' . trim($ip_number_4);
202
203     $query = <<<SQL_QUERY
204         select
205             *
206         from
207             server_ips
208         where
209             ip_number = ?
210 SQL_QUERY;
211
212     $rs = exec_query($sql, $query, array($ip_number));
213
214     if ($rs->RowCount() == 0)
215
216         return false;
217
218     return true;
219 }
220
221 /*
222  *
223  * static page messages.
224  *
225  */
226 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_settings.tpl');
227 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_settings.tpl');
228
229 add_ip($tpl, $sql);
230
231 show_IPs($tpl, $sql);
232
233 $tpl->assign(
234         array(
235             'MANAGE_IPS' => tr('Manage IPs'),
236             'TR_AVAILABLE_IPS' => tr('Available IPs'),
237             'TR_IP' => tr('IP'),
238             'TR_DOMAIN' => tr('Domain'),
239             'TR_ALIAS' => tr('Alias'),
240             'TR_ACTION' => tr('Action'),
241             'TR_ADD' => tr('Add'),
242             'TR_ADD_NEW_IP' => tr('Add new IP'),
243             'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete this IP: %s?', true, '%s')
244             )
245     );
246
247 gen_page_message($tpl);
248
249 $tpl->parse('PAGE', 'page');
250 $tpl->prnt();
251
252 if (Config::get('DUMP_GUI_DEBUG'))
253     dump_gui_debug();
254
255 unset_messages();
256
257 ?>
258
Note: See TracBrowser for help on using the browser.