root/trunk/gui/admin/manage_reseller_users.php

Revision 1327, 13.5 kB (checked in by rats, 4 months ago)

* Fixed: --scan-knownbad-files and --check-deleted are no longer supported by rkhunter
* Fixed #1471: chkrootkit should be in lenny / hardy
* Updated Chinese (simplified)
* Updated German
* Fixed #1475: typo on installation (ispcp-setup)
* Fixed: default user for rkhunter.log

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 $tpl->define_dynamic('page', Config::get('ADMIN_TEMPLATE_PATH') . '/manage_reseller_users.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('hosting_plans', 'page');
29 $tpl->define_dynamic('reseller_list', 'page');
30 $tpl->define_dynamic('reseller_item', 'reseller_list');
31 $tpl->define_dynamic('src_reseller', 'page');
32 $tpl->define_dynamic('src_reseller_option', 'src_reseller');
33 $tpl->define_dynamic('dst_reseller', 'page');
34 $tpl->define_dynamic('dst_reseller_option', 'dst_reseller');
35
36 $theme_color = Config::get('USER_INITIAL_THEME');
37
38 function gen_user_table(&$tpl, &$sql) {
39     $query = <<<SQL_QUERY
40         SELECT
41             admin_id, admin_name
42         FROM
43             admin
44         WHERE
45             admin_type = 'reseller'
46         ORDER BY
47             admin_name
48 SQL_QUERY;
49
50     $rs = exec_query($sql, $query, array());
51
52     if ($rs->RecordCount() == 0) {
53         set_page_message(tr('Reseller or user list is empty!'));
54         header('Location: manage_users.php');
55         die();
56     }
57
58     $reseller_id = $rs->fields['admin_id'];
59
60     while (!$rs->EOF) {
61         $selected = '';
62
63         if (isset($_POST['uaction']) && $_POST['uaction'] === 'change_src') {
64             if (isset($_POST['src_reseller']) && $_POST['src_reseller'] == $rs->fields['admin_id']) {
65                 $selected = 'selected';
66
67                 $reseller_id = $_POST['src_reseller'];
68             }
69         } else if (isset($_POST['uaction']) && $_POST['uaction'] === 'move_user') {
70             if (isset($_POST['dst_reseller']) && $_POST['dst_reseller'] == $rs->fields['admin_id']) {
71                 $selected = 'selected';
72
73                 $reseller_id = $_POST['dst_reseller'];
74             }
75         }
76         $tpl->assign(
77             array(
78                 'SRC_RSL_OPTION' => $rs->fields['admin_name'],
79                 'SRC_RSL_VALUE' => $rs->fields['admin_id'],
80                 'SRC_RSL_SELECTED' => $selected,
81                 )
82             );
83
84         $tpl->assign(
85             array('DST_RSL_OPTION' => $rs->fields['admin_name'],
86                 'DST_RSL_VALUE' => $rs->fields['admin_id'],
87                 )
88             );
89
90         $tpl->parse('SRC_RESELLER_OPTION', '.src_reseller_option');
91         $tpl->parse('DST_RESELLER_OPTION', '.dst_reseller_option');
92         $rs->MoveNext();
93     }
94
95     $query = <<<SQL_QUERY
96         SELECT
97             admin_id, admin_name
98         FROM
99             admin
100         WHERE
101             admin_type = 'user'
102           AND
103             created_by = ?
104         ORDER BY
105             admin_name
106 SQL_QUERY;
107
108     $rs = exec_query($sql, $query, array($reseller_id));
109
110     $i = 0;
111
112     if ($rs->RecordCount() == 0) {
113         set_page_message(tr('User list is empty!'));
114
115         $tpl->assign('RESELLER_LIST', '');
116     } else {
117         while (!$rs->EOF) {
118             if ($i % 2 == 0) {
119                 $tpl->assign(
120                     array('RSL_CLASS' => 'content',
121                         )
122                     );
123             } else {
124                 $tpl->assign(
125                     array('RSL_CLASS' => 'content2',
126                         )
127                     );
128             }
129
130             $admin_id = $rs->fields['admin_id'];
131
132             $admin_id_var_name = "admin_id_$admin_id";
133
134             $show_admin_name = decode_idna($rs->fields['admin_name']);
135
136             $tpl->assign(
137                 array(
138                     'NUMBER' => $i + 1,
139                     'USER_NAME' => $show_admin_name,
140                     'CKB_NAME' => $admin_id_var_name,
141                     )
142                 );
143
144             $tpl->parse('RESELLER_ITEM', '.reseller_item');
145             $rs->MoveNext();
146
147             $i++;
148         }
149         $tpl->parse('RESELLER_LIST', 'reseller_list');
150     }
151 }
152
153 function update_reseller_user($sql) {
154     if (isset($_POST['uaction']) && $_POST['uaction'] === 'move_user') {
155         if (check_user_data()) {
156             set_page_message(tr('User was moved'));
157         }
158     }
159 }
160
161 function check_user_data() {
162     $sql = Database::getInstance();
163
164     $query = <<<SQL_QUERY
165         SELECT
166             admin_id
167         FROM
168             admin
169         WHERE
170             admin_type = 'user'
171         ORDER BY
172             admin_name
173 SQL_QUERY;
174
175     $rs = exec_query($sql, $query, array());
176
177     $selected_users = '';
178
179     while (!$rs->EOF) {
180         $admin_id = $rs->fields['admin_id'];
181
182         $admin_id_var_name = "admin_id_$admin_id";
183
184         if (isset($_POST[$admin_id_var_name]) && $_POST[$admin_id_var_name] === 'on') {
185             $selected_users .= $rs->fields['admin_id'] . ';';
186         }
187
188         $rs->Movenext();
189     }
190
191     if ($selected_users == '') {
192         set_page_message(tr('Please select some user(s)!'));
193
194         return false;
195     } else if ($_POST['src_reseller'] == $_POST['dst_reseller']) {
196         set_page_message(tr('Source and destination reseller are the same!'));
197
198         return false;
199     }
200
201     $dst_reseller = $_POST['dst_reseller'];
202
203     $query = <<<SQL_QUERY
204         select
205             reseller_ips
206         from
207             reseller_props
208         where
209             reseller_id = ?
210 SQL_QUERY;
211
212     $rs = exec_query($sql, $query, array($dst_reseller));
213
214     $mru_error = '_off_';
215
216     $dest_reseller_ips = $rs->fields['reseller_ips'];
217
218     check_ip_sets($dest_reseller_ips, $selected_users, $mru_error);
219
220     if ($mru_error == '_off_') {
221         manage_reseller_limits($_POST['dst_reseller'], $_POST['src_reseller'], $selected_users, $mru_error);
222     }
223
224     if ($mru_error != '_off_') {
225         set_page_message($mru_error);
226
227         return false;
228     }
229
230     return true;
231 }
232
233 function manage_reseller_limits ($dest_reseller, $src_reseller, $users, &$err) {
234     $sql = Database::getInstance();
235
236     list ($dest_dmn_current, $dest_dmn_max,
237         $dest_sub_current, $dest_sub_max,
238         $dest_als_current, $dest_als_max,
239         $dest_mail_current, $dest_mail_max,
240         $dest_ftp_current, $dest_ftp_max,
241         $dest_sql_db_current, $dest_sql_db_max,
242         $dest_sql_user_current, $dest_sql_user_max,
243         $dest_traff_current, $dest_traff_max,
244         $dest_disk_current, $dest_disk_max
245         ) = generate_reseller_props($dest_reseller);
246
247     list ($src_dmn_current, $src_dmn_max,
248         $src_sub_current, $src_sub_max,
249         $src_als_current, $src_als_max,
250         $src_mail_current, $src_mail_max,
251         $src_ftp_current, $src_ftp_max,
252         $src_sql_db_current, $src_sql_db_max,
253         $src_sql_user_current, $src_sql_user_max,
254         $src_traff_current, $src_traff_max,
255         $src_disk_current, $src_disk_max
256         ) = generate_reseller_props($src_reseller);
257
258     $users_array = explode(";", $users);
259
260     for ($i = 0; $i < count($users_array) - 1; $i++) {
261         $query = <<<SQL_QUERY
262             select
263                 domain_id, domain_name
264             from
265                 domain
266             where
267                 domain_admin_id = ?
268 SQL_QUERY;
269
270         $rs = exec_query($sql, $query, array($users_array[$i]));
271
272         $domain_name = $rs->fields['domain_name'];
273
274         $domain_id = $rs->fields['domain_id'];
275
276         list ($sub_current, $sub_max,
277             $als_current, $als_max,
278             $mail_current, $mail_max,
279             $ftp_current, $ftp_max,
280             $sql_db_current, $sql_db_max,
281             $sql_user_current, $sql_user_max,
282             $traff_max, $disk_max
283             ) = generate_user_props($domain_id);
284
285         calculate_reseller_dvals($dest_dmn_current, $dest_dmn_max, $src_dmn_current, $src_dmn_max, 1, $err, 'Domain', $domain_name);
286
287         if ($err == '_off_') {
288             calculate_reseller_dvals($dest_sub_current, $dest_sub_max, $src_sub_current, $src_sub_max, $sub_max, $err, 'Subdomain', $domain_name);
289             calculate_reseller_dvals($dest_als_current, $dest_als_max, $src_als_current, $src_als_max, $als_max, $err, 'Alias', $domain_name);
290             calculate_reseller_dvals($dest_mail_current, $dest_mail_max, $src_mail_current, $src_mail_max, $mail_max, $err, 'Mail', $domain_name);
291             calculate_reseller_dvals($dest_ftp_current, $dest_ftp_max, $src_ftp_current, $src_ftp_max, $ftp_max, $err, 'FTP', $domain_name);
292             calculate_reseller_dvals($dest_sql_db_current, $dest_sql_db_max, $src_sql_db_current, $src_sql_db_max, $sql_db_max, $err, 'SQL Database', $domain_name);
293             calculate_reseller_dvals($dest_sql_user_current, $dest_sql_user_max, $src_sql_user_current, $src_sql_user_max, $sql_user_max, $err, 'SQL User', $domain_name);
294             calculate_reseller_dvals($dest_traff_current, $dest_traff_max, $src_traff_current, $src_traff_max, $traff_max, $err, 'Traffic', $domain_name);
295             calculate_reseller_dvals($dest_disk_current, $dest_disk_max, $src_disk_current, $src_disk_max, $disk_max, $err, 'Disk', $domain_name);
296         }
297
298         if ($err != '_off_') {
299             return false;
300         }
301     }
302
303     // Let's Make Necessary Updates;
304
305     $src_reseller_props = "$src_dmn_current;$src_dmn_max;";
306     $src_reseller_props .= "$src_sub_current;$src_sub_max;";
307     $src_reseller_props .= "$src_als_current;$src_als_max;";
308     $src_reseller_props .= "$src_mail_current;$src_mail_max;";
309     $src_reseller_props .= "$src_ftp_current;$src_ftp_max;";
310     $src_reseller_props .= "$src_sql_db_current;$src_sql_db_max;";
311     $src_reseller_props .= "$src_sql_user_current;$src_sql_user_max;";
312     $src_reseller_props .= "$src_traff_current;$src_traff_max;";
313     $src_reseller_props .= "$src_disk_current;$src_disk_max;";
314
315     update_reseller_props($src_reseller, $src_reseller_props);
316
317     $dest_reseller_props = "$dest_dmn_current;$dest_dmn_max;";
318     $dest_reseller_props .= "$dest_sub_current;$dest_sub_max;";
319     $dest_reseller_props .= "$dest_als_current;$dest_als_max;";
320     $dest_reseller_props .= "$dest_mail_current;$dest_mail_max;";
321     $dest_reseller_props .= "$dest_ftp_current;$dest_ftp_max;";
322     $dest_reseller_props .= "$dest_sql_db_current;$dest_sql_db_max;";
323     $dest_reseller_props .= "$dest_sql_user_current;$dest_sql_user_max;";
324     $dest_reseller_props .= "$dest_traff_current;$dest_traff_max;";
325     $dest_reseller_props .= "$dest_disk_current;$dest_disk_max;";
326
327     update_reseller_props($dest_reseller, $dest_reseller_props);
328
329     for ($i = 0; $i < count($users_array) - 1; $i++) {
330         $query = "update admin set created_by = ? where admin_id = ?";
331         exec_query($sql, $query, array($dest_reseller, $users_array[$i]));
332
333         $query = "update domain set domain_created_id = ? where domain_admin_id = ?";
334         exec_query($sql, $query, array($dest_reseller, $users_array[$i]));
335     }
336
337     return true;
338 }
339
340 function calculate_reseller_dvals(&$dest, $dest_max, &$src, $src_max, $umax, &$err, $obj, $uname) {
341     if ($dest_max == 0 && $src_max == 0 && $umax == -1) {
342         return;
343     } else if ($dest_max == 0 && $src_max == 0 && $umax == 0) {
344         return;
345     } else if ($dest_max == 0 && $src_max == 0 && $umax > 0) {
346         $src -= $umax;
347
348         $dest += $umax;
349
350         return;
351     } else if ($dest_max == 0 && $src_max > 0 && $umax == -1) {
352         return;
353     } else if ($dest_max == 0 && $src_max > 0 && $umax == 0) {
354         // Impossible condition;
355         return;
356     } else if ($dest_max == 0 && $src_max > 0 && $umax > 0) {
357         $src -= $umax;
358
359         $dest += $umax;
360
361         return;
362     } else if ($dest_max > 0 && $src_max == 0 && $umax == -1) {
363         return;
364     } else if ($dest_max > 0 && $src_max == 0 && $umax == 0) {
365         if ($err == '_off_') {
366             $err = '';
367         }
368         $err .= tr('<b>%1$s</b> has unlimited rights for a <b>%2$s</b> Service !<br>', $uname, $obj);
369
370         $err .= tr('You cannot move <b>%1$s</b> in a destination reseller,<br>which has limits for the <b>%2$s</b> service!', $uname, $obj);
371
372         return;
373     } else if ($dest_max > 0 && $src_max == 0 && $umax > 0) {
374         if ($dest + $umax > $dest_max) {
375             if ($err == '_off_') {
376                 $err = '';
377             }
378             $err .= tr('<b>%1$s</b> is exceeding limits for a <b>%2$s</b><br>service in destination reseller!<br>', $uname, $obj);
379
380             $err .= tr('Moving aborted!');
381         } else {
382             $src -= $umax;
383
384             $dest += $umax;
385         }
386
387         return;
388     } else if ($dest_max > 0 && $src_max > 0 && $umax == -1) {
389         return;
390     } else if ($dest_max > 0 && $src_max > 0 && $umax == 0) {
391         // Impossible condition;
392         return;
393     } else if ($dest_max > 0 && $src_max > 0 && $umax > 0) {
394         if ($dest + $umax > $dest_max) {
395             if ($err == '_off_') {
396                 $err = '';
397             }
398             $err .= tr('<b>%1$s</b> is exceeding limits for a <b>%2$s</b><br>service in destination reseller!<br>', $uname, $obj);
399
400             $err .= tr('Moving aborted!');
401         } else {
402             $src -= $umax;
403
404             $dest += $umax;
405         }
406
407         return;
408     }
409 }
410
411 function check_ip_sets($dest, $users, &$err) {
412     $sql = Database::getInstance();
413
414     $users_array = explode(";", $users);
415
416     for ($i = 0; $i < count($users_array); $i++) {
417         $query = <<<SQL_QUERY
418             select
419                 domain_name, domain_ip_id
420             from
421                 domain
422             where
423                 domain_admin_id = ?
424 SQL_QUERY;
425
426         $rs = exec_query($sql, $query, array($users_array[$i]));
427
428         $domain_ip_id = $rs->fields['domain_ip_id'];
429
430         $domain_name = $rs->fields['domain_name'];
431
432         if (!preg_match("/$domain_ip_id;/", $dest)) {
433             if ($err == '_off_') {
434                 $err = '';
435             }
436             $err .= tr('<b>%s</b> has IP address that cannot be managed from the destination reseller !<br>This user cannot be moved!', $domain_name);
437
438             return false;
439         }
440     }
441
442     return true;
443 }
444
445 /*
446  *
447  * static page messages.
448  *
449  */
450
451 $tpl->assign(
452     array(
453         'TR_ADMIN_MANAGE_RESELLER_USERS_PAGE_TITLE' => tr('ispCP - Admin/Manage users/User assignment'),
454         'THEME_COLOR_PATH' => "../themes/$theme_color",
455         'THEME_CHARSET' => tr('encoding'),
456         'ISP_LOGO' => get_logo($_SESSION['user_id'])
457         )
458     );
459
460 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_users_manage.tpl');
461 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_users_manage.tpl');
462
463 update_reseller_user($sql);
464
465 gen_user_table($tpl, $sql);
466
467 $tpl->assign(
468     array(
469         'TR_USER_ASSIGNMENT' => tr('User assignment'),
470         'TR_RESELLER_USERS' => tr('Users'),
471         'TR_NUMBER' => tr('No.'),
472         'TR_MARK' => tr('Mark'),
473         'TR_USER_NAME' => tr('User name'),
474         'TR_FROM_RESELLER' => tr('From reseller'),
475         'TR_TO_RESELLER' => tr('To reseller'),
476         'TR_MOVE' => tr('Move'),
477         )
478     );
479
480 gen_page_message($tpl);
481
482 $tpl->parse('PAGE', 'page');
483 $tpl->prnt();
484
485 if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug();
486
487 unset_messages();
488
489 ?>
Note: See TracBrowser for help on using the browser.