root/trunk/gui/admin/admin_log.php

Revision 1327, 7.2 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') . '/admin_log.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('log_row', 'page');
29 $tpl->define_dynamic('scroll_prev_gray', 'page');
30 $tpl->define_dynamic('scroll_prev', 'page');
31 $tpl->define_dynamic('scroll_next_gray', 'page');
32 $tpl->define_dynamic('scroll_next', 'page');
33 $tpl->define_dynamic('clear_log', 'page');
34
35 $theme_color = Config::get('USER_INITIAL_THEME');
36
37 $tpl->assign(
38         array(
39             'TR_ADMIN_ADMIN_LOG_PAGE_TITLE' => tr('ispCP - Admin/Admin Log'),
40             'THEME_COLOR_PATH' => "../themes/$theme_color",
41             'THEME_CHARSET' => tr('encoding'),
42             'ISP_LOGO' => get_logo($_SESSION['user_id'])
43         )
44     );
45
46 function generate_page (&$tpl) {
47     $sql = Database::getInstance();
48
49     $start_index = 0;
50     $rows_per_page = 15;
51
52     if (isset($_GET['psi']) && is_numeric($_GET['psi']))
53         $start_index = intval($_GET['psi']);
54
55     $count_query = <<<SQL_QUERY
56         SELECT
57             COUNT(log_id) AS cnt
58         FROM
59             log
60 SQL_QUERY;
61
62     $query = <<<SQL_QUERY
63         SELECT
64             DATE_FORMAT(log_time,'%Y-%m-%d %H:%i') AS dat, log_message
65         FROM
66             log
67         ORDER BY
68             log_time DESC
69         LIMIT
70            $start_index, $rows_per_page
71 SQL_QUERY;
72
73     $rs = exec_query($sql, $count_query);
74
75     $records_count = $rs->fields['cnt'];
76
77     $rs = exec_query($sql, $query);
78
79     if ($rs->RowCount() == 0) {
80         // set_page_message(tr('Log is empty!'));
81         $tpl->assign(
82                 array(
83                     'LOG_ROW' => '',
84                     'PAG_MESSAGE' => tr('Log is empty!'),
85                     'USERS_LIST' => '',
86                     'SCROLL_PREV' => '',
87                     'SCROLL_NEXT' => '',
88                     'CLEAR_LOG' => ''
89                 )
90             );
91     } else {
92         $prev_si = $start_index - $rows_per_page;
93
94         if ($start_index == 0) {
95             $tpl->assign('SCROLL_PREV', '');
96         } else {
97             $tpl->assign(
98                     array(
99                         'SCROLL_PREV_GRAY' => '',
100                         'PREV_PSI' => $prev_si
101                     )
102                 );
103         }
104
105         $next_si = $start_index + $rows_per_page;
106
107         if ($next_si + 1 > $records_count) {
108             $tpl->assign('SCROLL_NEXT', '');
109         } else {
110             $tpl->assign(
111                     array(
112                         'SCROLL_NEXT_GRAY' => '',
113                         'NEXT_PSI' => $next_si
114                     )
115                 );
116         }
117
118         $tpl->assign(
119                 array(
120                     'PAGE_MESSAGE' => ''
121                 )
122             );
123
124         $row = 1;
125
126         while (!$rs->EOF) {
127             if ($row++ % 2 == 0) {
128                 $tpl->assign(
129                         array(
130                             'ROW_CLASS' => 'content',
131                         )
132                     );
133             } else {
134                 $tpl->assign(
135                         array(
136                             'ROW_CLASS' => 'content2',
137                         )
138                     );
139             }
140             $log_message = $rs->fields['log_message'];
141             $replaces = array(
142                 '/[^a-zA-Z](delete)[^a-zA-Z]/i' => ' <strong style="color:#FF0000">\\1</strong> ',
143                 '/[^a-zA-Z](add)[^a-zA-Z]/i' => ' <strong style="color:#33CC66">\\1</strong> ',
144                 '/[^a-zA-Z](change)[^a-zA-Z]/i' => ' <strong style="color:#3300FF">\\1</strong> ',
145                 '/[^a-zA-Z](edit)[^a-zA-Z]/i' => ' <strong style="color:#33CC66">\\1</strong> ',
146                 '/[^a-zA-Z](unknown)[^a-zA-Z]/i' => ' <strong style="color:#CC00FF">\\1</strong> ',
147                 '/[^a-zA-Z](logged)[^a-zA-Z]/i' => ' <strong style="color:#336600">\\1</strong> ',
148                 '/(bad password login data)/i' => ' <strong style="color:#FF0000">\\1</strong> '
149                 );
150
151             foreach ($replaces as $pattern => $replacement) {
152                 $log_message = preg_replace($pattern, $replacement, $log_message);
153             }
154
155             $date_formt = Config::get('DATE_FORMAT') . ' H:i';
156             $tpl->assign(
157                     array(
158                         'MESSAGE' => $log_message,
159                         'DATE' => date($date_formt, strtotime($rs->fields['dat'])),
160                     )
161                 );
162
163             $tpl->parse('LOG_ROW', '.log_row');
164
165             $rs->MoveNext();
166         } //while
167     }
168 }
169
170 function clear_log() {
171     $sql = Database::getInstance();
172
173     if (isset($_POST['uaction']) && $_POST['uaction'] === 'clear_log') {
174         $query = null;
175         $msg = '';
176
177         switch ($_POST['uaction_clear']) {
178             case 0:
179                 $query = <<<SQL_QUERY
180             delete
181                 from
182             log
183 SQL_QUERY;
184                 $msg = tr('%s deleted the full admin log!', $_SESSION['user_logged']);
185                 break;
186
187             case 2:
188                 // 2 Weeks
189                 $query = <<<SQL_QUERY
190             delete
191                 from
192             log
193                 where
194             DATE_SUB(CURDATE(), INTERVAL 14 DAY)
195                    >= log_time
196
197 SQL_QUERY;
198                 $msg = tr('%s deleted the admin log older than two weeks!', $_SESSION['user_logged']);
199
200                 break;
201
202             case 4:
203                 $query = <<<SQL_QUERY
204             delete
205                 from
206             log
207                 where
208             DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
209                    >= log_time
210 SQL_QUERY;
211                 $msg = tr('%s deleted the admin log older than one month!', $_SESSION['user_logged']);
212
213                 break;
214
215             case 12:
216                 $query = <<<SQL_QUERY
217             delete
218                 from
219             log
220                 where
221             DATE_SUB(CURDATE(), INTERVAL 3 MONTH)
222                    >= log_time
223 SQL_QUERY;
224                 $msg = tr('%s deleted the admin log older than three months!', $_SESSION['user_logged']);
225                 break;
226
227             case 26:
228                 $query = <<<SQL_QUERY
229             delete
230                 from
231             log
232                 where
233             DATE_SUB(CURDATE(), INTERVAL 6 MONTH)
234                    >= log_time
235 SQL_QUERY;
236                 $msg = tr('%s deleted the admin log older than six months!', $_SESSION['user_logged']);
237                 break;
238
239             case 52;
240                 $query = <<<SQL_QUERY
241             delete
242                 from
243             log
244                 where
245             DATE_SUB(CURDATE(), INTERVAL 1 YEAR)
246                    >= log_time
247 SQL_QUERY;
248                 $msg = tr('%s deleted the admin log older than one year!', $_SESSION['user_logged']);
249
250                 break;
251             default:
252                 system_message(tr('Invalid time period!'));
253                 break;
254         }
255
256         $rs = execute_query($sql, $query);
257         write_log($msg);
258     }
259 }
260
261 /*
262  *
263  * static page messages.
264  *
265  */
266 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_general_information.tpl');
267 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_general_information.tpl');
268
269 clear_log();
270
271 generate_page ($tpl);
272
273 $tpl->assign(
274         array(
275             'TR_ADMIN_LOG' => tr('Admin Log'),
276             'TR_CLEAR_LOG' => tr('Clear log'),
277             'TR_DATE' => tr('Date'),
278             'TR_MESSAGE' => tr('Message'),
279             'TR_CLEAR_LOG_MESSAGE' => tr('Delete from log:'),
280             'TR_CLEAR_LOG_EVERYTHING' => tr('everything'),
281             'TR_CLEAR_LOG_LAST2' => tr('older than 2 weeks'),
282             'TR_CLEAR_LOG_LAST4' => tr('older than 1 month'),
283             'TR_CLEAR_LOG_LAST12' => tr('older than 3 months'),
284             'TR_CLEAR_LOG_LAST26' => tr('older than 6 months'),
285             'TR_CLEAR_LOG_LAST52' => tr('older than 12 months'),
286         )
287     );
288 // gen_page_message($tpl);
289
290 $tpl->parse('PAGE', 'page');
291 $tpl->prnt();
292
293 if (Config::get('DUMP_GUI_DEBUG'))
294     dump_gui_debug();
295
296 unset_messages();
297
298 ?>
Note: See TracBrowser for help on using the browser.