Imported Upstream version 0.8.7g
[debian/cacti] / utilities.php
1 <?php
2 /*
3  +-------------------------------------------------------------------------+
4  | Copyright (C) 2004-2010 The Cacti Group                                 |
5  |                                                                         |
6  | This program is free software; you can redistribute it and/or           |
7  | modify it under the terms of the GNU General Public License             |
8  | as published by the Free Software Foundation; either version 2          |
9  | of the License, or (at your option) any later version.                  |
10  |                                                                         |
11  | This program is distributed in the hope that it will be useful,         |
12  | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14  | GNU General Public License for more details.                            |
15  +-------------------------------------------------------------------------+
16  | Cacti: The Complete RRDTool-based Graphing Solution                     |
17  +-------------------------------------------------------------------------+
18  | This code is designed, written, and maintained by the Cacti Group. See  |
19  | about.php and/or the AUTHORS file for specific developer information.   |
20  +-------------------------------------------------------------------------+
21  | http://www.cacti.net/                                                   |
22  +-------------------------------------------------------------------------+
23 */
24
25 include("./include/auth.php");
26 include_once("./lib/utility.php");
27
28 load_current_session_value("page_referrer", "page_referrer", "");
29
30 /* set default action */
31 if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
32
33 if (isset($_REQUEST["sort_direction"])) {
34         if ($_REQUEST['page_referrer'] == "view_snmp_cache") {
35                 $_REQUEST["action"] = "view_snmp_cache";
36         }else if ($_REQUEST['page_referrer'] == "view_poller_cache") {
37                 $_REQUEST["action"] = "view_poller_cache";
38         }else{
39                 $_REQUEST["action"] = "view_user_log";
40         }
41 }
42
43 if ((isset($_REQUEST["clear_x"])) || (isset($_REQUEST["go_x"]))) {
44         if ($_REQUEST['page_referrer'] == "view_snmp_cache") {
45                 $_REQUEST["action"] = "view_snmp_cache";
46         }else if ($_REQUEST['page_referrer'] == "view_poller_cache") {
47                 $_REQUEST["action"] = "view_poller_cache";
48         }else if ($_REQUEST['page_referrer'] == "view_user_log") {
49                 $_REQUEST["action"] = "view_user_log";
50         }else{
51                 $_REQUEST["action"] = "view_logfile";
52         }
53 }
54
55 if (isset($_REQUEST["purge_x"])) {
56         if ($_REQUEST['page_referrer'] == "view_user_log") {
57                 $_REQUEST["action"] = "clear_user_log";
58         }else{
59                 $_REQUEST["action"] = "clear_logfile";
60         }
61 }
62
63 switch ($_REQUEST["action"]) {
64         case 'clear_poller_cache':
65                 include_once("./include/top_header.php");
66
67                 /* obtain timeout settings */
68                 $max_execution = ini_get("max_execution_time");
69                 ini_set("max_execution_time", "0");
70                 repopulate_poller_cache();
71                 ini_set("max_execution_time", $max_execution);
72
73                 utilities_view_poller_cache();
74
75                 include_once("./include/bottom_footer.php");
76                 break;
77         case 'view_snmp_cache':
78                 include_once("./include/top_header.php");
79
80                 utilities_view_snmp_cache();
81
82                 include_once("./include/bottom_footer.php");
83                 break;
84         case 'view_poller_cache':
85                 include_once("./include/top_header.php");
86
87                 utilities_view_poller_cache();
88
89                 include_once("./include/bottom_footer.php");
90                 break;
91         case 'view_logfile':
92                 utilities_view_logfile();
93
94                 break;
95         case 'clear_logfile':
96                 utilities_clear_logfile();
97                 utilities_view_logfile();
98
99                 include_once("./include/bottom_footer.php");
100                 break;
101         case 'view_user_log':
102                 include_once("./include/top_header.php");
103
104                 utilities_view_user_log();
105
106                 include_once("./include/bottom_footer.php");
107                 break;
108         case 'clear_user_log':
109                 include_once("./include/top_header.php");
110
111                 utilities_clear_user_log();
112                 utilities_view_user_log();
113
114                 include_once("./include/bottom_footer.php");
115                 break;
116         case 'view_tech':
117                 $php_info = utilities_php_modules();
118
119                 include_once("./include/top_header.php");
120
121                 utilities_view_tech($php_info);
122
123                 include_once("./include/bottom_footer.php");
124                 break;
125         default:
126                 include_once("./include/top_header.php");
127
128                 utilities();
129
130                 include_once("./include/bottom_footer.php");
131                 break;
132 }
133
134 /* -----------------------
135     Utilities Functions
136    ----------------------- */
137
138 function utilities_php_modules() {
139
140         /*
141            Gather phpinfo into a string variable - This has to be done before
142            any headers are sent to the browser, as we are going to do some
143            output buffering fun
144         */
145
146         ob_start();
147         phpinfo(INFO_MODULES);
148         $php_info = ob_get_contents();
149         ob_end_clean();
150
151         /* Remove nasty style sheets, links and other junk */
152         $php_info = str_replace("\n", "", $php_info);
153         $php_info = preg_replace('/^.*\<body\>/', '', $php_info);
154         $php_info = preg_replace('/\<\/body\>.*$/', '', $php_info);
155         $php_info = preg_replace('/\<a.*\>/U', '', $php_info);
156         $php_info = preg_replace('/\<\/a\>/', '<hr>', $php_info);
157         $php_info = preg_replace('/\<img.*\>/U', '', $php_info);
158         $php_info = preg_replace('/\<\/?address\>/', '', $php_info);
159
160         return $php_info;
161 }
162
163
164 function memory_bytes($val) {
165     $val = trim($val);
166     $last = strtolower($val{strlen($val)-1});
167     switch($last) {
168         // The 'G' modifier is available since PHP 5.1.0
169         case 'g':
170             $val *= 1024;
171         case 'm':
172             $val *= 1024;
173         case 'k':
174             $val *= 1024;
175     }
176
177     return $val;
178 }
179
180
181 function memory_readable($val) {
182
183         if ($val < 1024) {
184                 $val_label = "bytes";
185         }elseif ($val < 1048576) {
186                 $val_label = "K";
187                 $val /= 1024;
188         }elseif ($val < 1073741824) {
189                 $val_label = "M";
190                 $val /= 1048576;
191         }else{
192                 $val_label = "G";
193                 $val /= 1073741824;
194         }
195
196     return $val . $val_label;
197 }
198
199
200 function utilities_view_tech($php_info = "") {
201         global $database_default, $colors, $config, $rrdtool_versions, $poller_options, $input_types;
202
203         /* Get table status */
204         $tables = db_fetch_assoc("SHOW TABLES");
205         $skip_tables  = array();
206         $table_status = array();
207
208         if (sizeof($tables)) {
209         foreach($tables as $table) {
210                 $create_syntax = db_fetch_row("SHOW CREATE TABLE " . $table["Tables_in_" . $database_default]);
211
212                 if (sizeof($create_syntax)) {
213                         if (substr_count(strtoupper($create_syntax["Create Table"]), "INNODB")) {
214                                 $skip_tables[] = $table["Tables_in_" . $database_default];
215                         }else{
216                                 $include_tables[] = $table["Tables_in_" . $database_default];
217                         }
218                 }
219         }
220         }
221
222         if (sizeof($include_tables)) {
223         foreach($include_tables as $table) {
224                 $status = db_fetch_row("SHOW TABLE STATUS LIKE '$table'");
225
226                 array_push($table_status, $status);
227         }
228         }
229
230         /* Get poller stats */
231         $poller_item = db_fetch_assoc("SELECT action, count(action) as total FROM poller_item GROUP BY action");
232
233         /* Get system stats */
234         $host_count = db_fetch_cell("SELECT COUNT(*) FROM host");
235         $graph_count = db_fetch_cell("SELECT COUNT(*) FROM graph_local");
236         $data_count = db_fetch_assoc("SELECT i.type_id, COUNT(i.type_id) AS total FROM data_template_data AS d, data_input AS i WHERE d.data_input_id = i.id AND local_data_id <> 0 GROUP BY i.type_id");
237
238         /* Get RRDtool version */
239         $rrdtool_version = "Unknown";
240         if ((file_exists(read_config_option("path_rrdtool"))) && ((function_exists('is_executable')) && (is_executable(read_config_option("path_rrdtool"))))) {
241
242                 $out_array = array();
243                 exec(cacti_escapeshellcmd(read_config_option("path_rrdtool")), $out_array);
244
245                 if (sizeof($out_array) > 0) {
246                         if (ereg("^RRDtool 1\.4", $out_array[0])) {
247                                 $rrdtool_version = "rrd-1.4.x";
248                         }else if (ereg("^RRDtool 1\.3\.", $out_array[0])) {
249                                 $rrdtool_version = "rrd-1.3.x";
250                         }else if (ereg("^RRDtool 1\.2\.", $out_array[0])) {
251                                 $rrdtool_version = "rrd-1.2.x";
252                         }else if (ereg("^RRDtool 1\.0\.", $out_array[0])) {
253                                 $rrdtool_version = "rrd-1.0.x";
254                         }
255                 }
256         }
257
258         /* Get SNMP cli version */
259         $snmp_version = read_config_option("snmp_version");
260         if ((file_exists(read_config_option("path_snmpget"))) && ((function_exists('is_executable')) && (is_executable(read_config_option("path_snmpget"))))) {
261                 $snmp_version = shell_exec(cacti_escapeshellcmd(read_config_option("path_snmpget")) . " -V 2>&1");
262         }
263
264         /* Check RRDTool issues */
265         $rrdtool_error = "";
266         if ($rrdtool_version != read_config_option("rrdtool_version")) {
267                 $rrdtool_error .= "<br><font color='red'>ERROR: Installed RRDTool version does not match configured version.<br>Please visit the <a href='" . htmlspecialchars("settings.php?tab=general") . "'>Configuration Settings</a> and select the correct RRDTool Utility Version.</font><br>";
268         }
269         $graph_gif_count = db_fetch_cell("SELECT COUNT(*) FROM graph_templates_graph WHERE image_format_id = 2");
270         if (($graph_gif_count > 0) && (read_config_option("rrdtool_version") != "rrd-1.0.x")) {
271                 $rrdtool_error .= "<br><font color='red'>ERROR: RRDTool 1.2.x does not support the GIF images format, but " . $graph_gif_count . " graph(s) and/or templates have GIF set as the image format.</font><br>";
272         }
273
274         /* Display tech information */
275         html_start_box("<strong>Technical Support</strong>", "100%", $colors["header"], "3", "center", "");
276         html_header(array("General Information"), 2);
277         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
278         print "         <td class='textArea'>Date</td>\n";
279         print "         <td class='textArea'>" . date("r") . "</td>\n";
280         print "</tr>\n";
281         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
282         print "         <td class='textArea'>Cacti Version</td>\n";
283         print "         <td class='textArea'>" . $config["cacti_version"] . "</td>\n";
284         print "</tr>\n";
285         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
286         print "         <td class='textArea'>Cacti OS</td>\n";
287         print "         <td class='textArea'>" . $config["cacti_server_os"] . "</td>\n";
288         print "</tr>\n";
289         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
290         print "         <td class='textArea'>SNMP Version</td>\n";
291         print "         <td class='textArea'>" . $snmp_version . "</td>\n";
292         print "</tr>\n";
293
294         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
295         print "         <td class='textArea'>RRDTool Version</td>\n";
296         print "         <td class='textArea'>" . $rrdtool_versions[$rrdtool_version] . " " . $rrdtool_error . "</td>\n";
297         print "</tr>\n";
298         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
299         print "         <td class='textArea'>Hosts</td>\n";
300         print "         <td class='textArea'>" . $host_count . "</td>\n";
301         print "</tr>\n";
302         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
303         print "         <td class='textArea'>Graphs</td>\n";
304         print "         <td class='textArea'>" . $graph_count . "</td>\n";
305         print "</tr>\n";
306         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
307         print "         <td class='textArea'>Data Sources</td>\n";
308         print "         <td class='textArea'>";
309         $data_total = 0;
310         if (sizeof($data_count)) {
311                 foreach ($data_count as $item) {
312                         print $input_types[$item["type_id"]] . ": " . $item["total"] . "<br>";
313                         $data_total += $item["total"];
314                 }
315                 print "Total: " . $data_total;
316         }else{
317                 print "<font color='red'>0</font>";
318         }
319         print "</td>\n";
320         print "</tr>\n";
321
322         html_header(array("Poller Information"), 2);
323         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
324         print "         <td class='textArea'>Interval</td>\n";
325         print "         <td class='textArea'>" . read_config_option("poller_interval") . "</td>\n";
326         print "</tr>\n";
327         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
328         print "         <td class='textArea'>Type</td>\n";
329         print "         <td class='textArea'>" . $poller_options[read_config_option("poller_type")] . "</td>\n";
330         print "</tr>\n";
331         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
332         print "         <td class='textArea'>Items</td>\n";
333         print "         <td class='textArea'>";
334         $total = 0;
335         if (sizeof($poller_item)) {
336                 foreach ($poller_item as $item) {
337                         print "Action[" . $item["action"] . "]: " . $item["total"] . "<br>";
338                         $total += $item["total"];
339                 }
340                 print "Total: " . $total;
341         }else{
342                 print "<font color='red'>No items to poll</font>";
343         }
344         print "</td>\n";
345         print "</tr>\n";
346
347         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
348         print "         <td class='textArea'>Concurrent Processes</td>\n";
349         print "         <td class='textArea'>" . read_config_option("concurrent_processes") . "</td>\n";
350         print "</tr>\n";
351
352         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
353         print "         <td class='textArea'>Max Threads</td>\n";
354         print "         <td class='textArea'>" . read_config_option("max_threads") . "</td>\n";
355         print "</tr>\n";
356
357         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
358         print "         <td class='textArea'>PHP Servers</td>\n";
359         print "         <td class='textArea'>" . read_config_option("php_servers") . "</td>\n";
360         print "</tr>\n";
361
362         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
363         print "         <td class='textArea'>Script Timeout</td>\n";
364         print "         <td class='textArea'>" . read_config_option("script_timeout") . "</td>\n";
365         print "</tr>\n";
366
367         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
368         print "         <td class='textArea'>Max OID</td>\n";
369         print "         <td class='textArea'>" . read_config_option("max_get_size") . "</td>\n";
370         print "</tr>\n";
371
372
373         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
374         print "         <td class='textArea'>Last Run Statistics</td>\n";
375         print "         <td class='textArea'>" . read_config_option("stats_poller") . "</td>\n";
376         print "</tr>\n";
377
378
379         html_header(array("PHP Information"), 2);
380         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
381         print "         <td class='textArea'>PHP Version</td>\n";
382         print "         <td class='textArea'>" . phpversion() . "</td>\n";
383         print "</tr>\n";
384         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
385         print "         <td class='textArea'>PHP OS</td>\n";
386         print "         <td class='textArea'>" . PHP_OS . "</td>\n";
387         print "</tr>\n";
388         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
389         print "         <td class='textArea'>PHP uname</td>\n";
390         print "         <td class='textArea'>";
391         if (function_exists("php_uname")) {
392                 print php_uname();
393         }else{
394                 print "N/A";
395         }
396         print "</td>\n";
397         print "</tr>\n";
398         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
399         print "         <td class='textArea'>PHP SNMP</td>\n";
400         print "         <td class='textArea'>";
401         if (function_exists("snmpget")) {
402                 print "Installed";
403         } else {
404                 print "Not Installed";
405         }
406         print "</td>\n";
407         print "</tr>\n";
408         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
409         print "         <td class='textArea'>max_execution_time</td>\n";
410         print "         <td class='textArea'>" . ini_get("max_execution_time") . "</td>\n";
411         print "</tr>\n";
412         print "<tr bgcolor='#" . $colors["form_alternate2"] . "'>\n";
413         print "         <td class='textArea'>memory_limit</td>\n";
414         print "         <td class='textArea'>" . ini_get("memory_limit");
415
416         /* Calculate memory suggestion based off of data source count */
417         $memory_suggestion = $data_total * 32768;
418         /* Set minimum - 16M */
419         if ($memory_suggestion < 16777216) {
420                 $memory_suggestion = 16777216;
421         }
422         /* Set maximum - 512M */
423         if ($memory_suggestion > 536870912) {
424                 $memory_suggestion = 536870912;
425         }
426         /* Suggest values in 8M increments */
427         $memory_suggestion = round($memory_suggestion / 8388608) * 8388608;
428         if (memory_bytes(ini_get('memory_limit')) < $memory_suggestion) {
429                 print "<br><font color='red'>";
430                 if ((ini_get('memory_limit') == -1)) {
431                         print "You've set memory limit to 'unlimited'.<br/>";
432                 }
433                 print "It is highly suggested that you alter you php.ini memory_limit to " . memory_readable($memory_suggestion) . " or higher. <br/>
434                         This suggested memory value is calculated based on the number of data source present and is only to be used as a suggestion, actual values may vary system to system based on requirements.";
435                 print "</font><br>";
436         }
437         print "</td>\n";
438         print "</tr>\n";
439
440         html_header(array("MySQL Table Information"), 2);
441         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
442         print "         <td class='textArea' colspan='2' align='center'>";
443         if (sizeof($table_status) > 0) {
444                 print "<table border='1' cellpadding='2' cellspacing='0'>\n";
445                 print "<tr>\n";
446                 print "  <th>Name</th>\n";
447                 print "  <th>Rows</th>\n";
448                 print "  <th>Engine</th>\n";
449                 print "  <th>Collation</th>\n";
450                 print "  <th>Check Status</th>\n";
451                 print "</tr>\n";
452                 foreach ($table_status as $item) {
453                         print "<tr>\n";
454                         print "  <td>" . $item["Name"] . "</td>\n";
455                         print "  <td>" . $item["Rows"] . "</td>\n";
456                         if (isset($item["Engine"])) {
457                                 print "  <td>" . $item["Engine"] . "</td>\n";
458                         }else{
459                                 print "  <td>Unknown</td>\n";
460                         }
461                         if (isset($item["Collation"])) {
462                                 print "  <td>" . $item["Collation"] . "</td>\n";
463                         } else {
464                                 print "  <td>Unknown</td>\n";
465                         }
466                         print "  <td>" . db_fetch_cell("CHECK TABLE " . $item["Name"], "Msg_text") . "</td>\n";
467                         print "</tr>\n";
468                 }
469
470                 if (sizeof($skip_tables)) {
471                         print "<tr><td colspan='20' align='center'><strong>The Following Tables were Skipped Due to being INNODB</strong></td></tr>";
472
473                         foreach($skip_tables as $table) {
474                                 print "<tr><td colspan='20' align='center'>" . $table . "</td></tr>";
475                         }
476                 }
477
478                 print "</table>\n";
479         }else{
480                 print "Unable to retrieve table status";
481         }
482
483         print "</td>\n";
484         print "</tr>\n";
485
486         html_header(array("PHP Module Information"), 2);
487         print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
488         print "         <td class='textArea' colspan='2'>" . $php_info . "</td>\n";
489         print "</tr>\n";
490
491         html_end_box();
492
493 }
494
495
496 function utilities_view_user_log() {
497         global $colors, $auth_realms;
498
499         define("MAX_DISPLAY_PAGES", 21);
500
501         /* ================= input validation ================= */
502         input_validate_input_number(get_request_var_request("result"));
503         input_validate_input_number(get_request_var_request("page"));
504         /* ==================================================== */
505
506         /* clean up username */
507         if (isset($_REQUEST["username"])) {
508                 $_REQUEST["username"] = sanitize_search_string(get_request_var("username"));
509         }
510
511         /* clean up search filter */
512         if (isset($_REQUEST["filter"])) {
513                 $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
514         }
515
516         /* clean up sort_column */
517         if (isset($_REQUEST["sort_column"])) {
518                 $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
519         }
520
521         /* clean up sort direction */
522         if (isset($_REQUEST["sort_direction"])) {
523                 $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
524         }
525
526         /* if the user pushed the 'clear' button */
527         if (isset($_REQUEST["clear_x"])) {
528                 kill_session_var("sess_userlog_current_page");
529                 kill_session_var("sess_userlog_username");
530                 kill_session_var("sess_userlog_result");
531                 kill_session_var("sess_userlog_filter");
532                 kill_session_var("sess_userlog_sort_column");
533                 kill_session_var("sess_userlog_sort_direction");
534
535                 unset($_REQUEST["page"]);
536                 unset($_REQUEST["result"]);
537                 unset($_REQUEST["filter"]);
538                 unset($_REQUEST["username"]);
539                 unset($_REQUEST["sort_column"]);
540                 unset($_REQUEST["sort_direction"]);
541         }
542
543         /* remember these search fields in session vars so we don't have to keep passing them around */
544         load_current_session_value("page", "sess_userlog_current_page", "1");
545         load_current_session_value("username", "sess_userlog_username", "-1");
546         load_current_session_value("result", "sess_userlog_result", "-1");
547         load_current_session_value("filter", "sess_userlog_filter", "");
548         load_current_session_value("sort_column", "sess_userlog_sort_column", "time");
549         load_current_session_value("sort_direction", "sess_userlog_sort_direction", "DESC");
550
551         $_REQUEST['page_referrer'] = 'view_user_log';
552         load_current_session_value('page_referrer', 'page_referrer', 'view_user_log');
553
554         ?>
555         <script type="text/javascript">
556         <!--
557
558         function applyViewLogFilterChange(objForm) {
559                 strURL = '?username=' + objForm.username.value;
560                 strURL = strURL + '&result=' + objForm.result.value;
561                 strURL = strURL + '&action=view_user_log';
562                 document.location = strURL;
563         }
564
565         -->
566         </script>
567         <?php
568
569         html_start_box("<strong>User Login History</strong>", "100%", $colors["header"], "3", "center", "");
570
571         ?>
572         <tr bgcolor="#<?php print $colors["panel"];?>">
573                 <td>
574                 <form name="form_userlog" action="utilities.php">
575                         <table cellpadding="0" cellspacing="0">
576                                 <tr>
577                                         <td nowrap style='white-space: nowrap;' width="50">
578                                                 Username:&nbsp;
579                                         </td>
580                                         <td width="1">
581                                                 <select name="username" onChange="applyViewLogFilterChange(document.form_userlog)">
582                                                         <option value="-1"<?php if (get_request_var_request("username") == "-1") {?> selected<?php }?>>All</option>
583                                                         <option value="-2"<?php if (get_request_var_request("username") == "-2") {?> selected<?php }?>>Deleted/Invalid</option>
584                                                         <?php
585                                                         $users = db_fetch_assoc("SELECT DISTINCT username FROM user_auth ORDER BY username");
586
587                                                         if (sizeof($users) > 0) {
588                                                         foreach ($users as $user) {
589                                                                 print "<option value='" . $user["username"] . "'"; if (get_request_var_request("username") == $user["username"]) { print " selected"; } print ">" . $user["username"] . "</option>\n";
590                                                         }
591                                                         }
592                                                         ?>
593                                                 </select>
594                                         </td>
595                                         <td nowrap style='white-space: nowrap;' width="50">
596                                                 &nbsp;Result:&nbsp;
597                                         </td>
598                                         <td width="1">
599                                                 <select name="result" onChange="applyViewLogFilterChange(document.form_userlog)">
600                                                         <option value="-1"<?php if (get_request_var_request("result") == '-1') {?> selected<?php }?>>Any</option>
601                                                         <option value="1"<?php if (get_request_var_request("result") == '1') {?> selected<?php }?>>Success</option>
602                                                         <option value="0"<?php if (get_request_var_request("result") == '0') {?> selected<?php }?>>Failed</option>
603                                                 </select>
604                                         </td>
605                                         <td nowrap style='white-space: nowrap;' width="50">
606                                                 &nbsp;Search:&nbsp;
607                                         </td>
608                                         <td width="1">
609                                                 <input type="text" name="filter" size="20" value="<?php print htmlspecialchars(get_request_var_request("filter"));?>">
610                                         </td>
611                                         <td nowrap style='white-space: nowrap;'>
612                                                 &nbsp;<input type="submit" name="go" value="Go" title="Set/Refresh Filters">
613                                                 <input type="submit" name="clear_x" value="Clear" title="Clear Filters">
614                                                 <input type="submit" name="purge_x" value="Purge" title="Purge User Log">
615                                         </td>
616                                 </tr>
617                         </table>
618                         <input type='hidden' name='page' value='1'>
619                         <input type='hidden' name='action' value='view_user_log'>
620                 </form>
621                 </td>
622         </tr>
623         <?php
624
625         html_end_box();
626
627         $sql_where = "";
628
629         /* filter by username */
630         if (get_request_var_request("username") == "-2") {
631                 $sql_where = "WHERE user_log.username NOT IN (SELECT DISTINCT username from user_auth)";
632         }elseif (get_request_var_request("username") != "-1") {
633                 $sql_where = "WHERE user_log.username='" . get_request_var_request("username") . "'";
634         }
635
636         /* filter by result */
637         if (get_request_var_request("result") != "-1") {
638                 if (strlen($sql_where)) {
639                         $sql_where .= " AND user_log.result=" . get_request_var_request("result");
640                 }else{
641                         $sql_where = "WHERE user_log.result=" . get_request_var_request("result");
642                 }
643         }
644
645         /* filter by search string */
646         if (get_request_var_request("filter") <> "") {
647                 if (strlen($sql_where)) {
648                         $sql_where .= " AND (user_log.username LIKE '%%" . get_request_var_request("filter") . "%%'
649                                 OR user_log.time LIKE '%%" . get_request_var_request("filter") . "%%'
650                                 OR user_log.ip LIKE '%%" . get_request_var_request("filter") . "%%')";
651                 }else{
652                         $sql_where = "WHERE (user_log.username LIKE '%%" . get_request_var_request("filter") . "%%'
653                                 OR user_log.time LIKE '%%" . get_request_var_request("filter") . "%%'
654                                 OR user_log.ip LIKE '%%" . get_request_var_request("filter") . "%%')";
655                 }
656         }
657
658         html_start_box("", "100%", $colors["header"], "3", "center", "");
659
660         $total_rows = db_fetch_cell("SELECT
661                 COUNT(*)
662                 FROM user_auth
663                 RIGHT JOIN user_log
664                 ON user_auth.username = user_log.username
665                 $sql_where");
666
667         $user_log_sql = "SELECT
668                 user_log.username,
669                 user_auth.full_name,
670                 user_auth.realm,
671                 user_log.time,
672                 user_log.result,
673                 user_log.ip
674                 FROM user_auth
675                 RIGHT JOIN user_log
676                 ON user_auth.username = user_log.username
677                 $sql_where
678                 ORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . "
679                 LIMIT " . (read_config_option("num_rows_data_source")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_data_source");
680
681 //      print $user_log_sql;
682
683         $user_log = db_fetch_assoc($user_log_sql);
684
685         /* generate page list */
686         $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "utilities.php?action=view_user_log&username=" . get_request_var_request("username") . "&filter=" . get_request_var_request("filter"));
687
688         $nav = "<tr bgcolor='#" . $colors["header"] . "'>
689                         <td colspan='7'>
690                                 <table width='100%' cellspacing='0' cellpadding='0' border='0'>
691                                         <tr>
692                                                 <td align='left' class='textHeaderDark'>
693                                                         <strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("utilities.php?action=view_user_log&username=" . get_request_var_request("username") . "&filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")-1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
694                                                 </td>\n
695                                                 <td align='center' class='textHeaderDark'>
696                                                         Showing Rows " . ((read_config_option("num_rows_data_source")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_data_source")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
697                                                 </td>\n
698                                                 <td align='right' class='textHeaderDark'>
699                                                         <strong>"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("utilities.php?action=view_user_log&username=" . get_request_var_request("username") . "&filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")+1)) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
700                                                 </td>\n
701                                         </tr>
702                                 </table>
703                         </td>
704                 </tr>\n";
705
706         print $nav;
707
708         $display_text = array(
709                 "username" => array("Username", "ASC"),
710                 "full_name" => array("Full Name", "ASC"),
711                 "realm" => array("Authentication Realm", "ASC"),
712                 "time" => array("Date", "ASC"),
713                 "result" => array("Result", "DESC"),
714                 "ip" => array("IP Address", "DESC"));
715
716         html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));
717
718         $i = 0;
719         if (sizeof($user_log) > 0) {
720                 foreach ($user_log as $item) {
721                         if (isset($item["full_name"])) {
722                                 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
723                         }else{
724                                 form_alternate_row_color("FF9D9D","FFAFAF",$i);
725                         }
726                         ?>
727                         <td style='white-space:nowrap;'>
728                                 <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["username"])) : $item["username"]);?>
729                         </td>
730                         <td style='white-space:nowrap;'>
731                                 <?php if (isset($item["full_name"])) {
732                                                 print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["full_name"])) : $item["full_name"]);
733                                         }else{
734                                                 print "(User Removed)";
735                                         }
736                                 ?>
737                         </td>
738                         <td style='white-space:nowrap;'>
739                                 <?php if (isset($auth_realms[$item["realm"]])) {
740                                                 print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $auth_realms[$item["realm"]])) : $auth_realms[$item["realm"]]);
741                                         }else{
742                                                 print "N/A";
743                                         }
744                                 ?>
745                         </td>
746                         <td style='white-space:nowrap;'>
747                                 <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["time"])) : $item["time"]);?>
748                         </td>
749                         <td style='white-space:nowrap;'>
750                                 <?php print $item["result"] == 0 ? "Failed" : "Success";?>
751                         </td>
752                         <td style='white-space:nowrap;'>
753                                 <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["ip"])) : $item["ip"]);?>
754                         </td>
755                         </tr>
756                         <?php
757                         $i++;
758                 }
759         }
760
761         html_end_box();
762 }
763
764 function utilities_clear_user_log() {
765         $users = db_fetch_assoc("SELECT DISTINCT username FROM user_auth");
766
767         if (sizeof($users)) {
768                 /* remove active users */
769                 foreach ($users as $user) {
770                         $total_rows = db_fetch_cell("SELECT COUNT(username) FROM user_log WHERE username = '" . $user['username'] . "' AND result = 1");
771                         if ($total_rows > 1) {
772                                 db_execute("DELETE FROM user_log WHERE username = '" . $user['username'] . "' AND result = 1 ORDER BY time LIMIT " . ($total_rows - 1));
773                         }
774                         db_execute("DELETE FROM user_log WHERE username = '" . $user['username'] . "' AND result = 0");
775                 }
776
777                 /* delete inactive users */
778                 db_execute("DELETE FROM user_log WHERE user_id NOT IN (SELECT id FROM user_auth) OR username NOT IN (SELECT username FROM user_auth)");
779
780         }
781 }
782
783 function utilities_view_logfile() {
784         global $colors, $log_tail_lines, $page_refresh_interval;
785
786         $logfile = read_config_option("path_cactilog");
787
788         if ($logfile == "") {
789                 $logfile = "./log/rrd.log";
790         }
791
792         /* helps determine output color */
793         $linecolor = True;
794
795         input_validate_input_number(get_request_var_request("tail_files"));
796         input_validate_input_number(get_request_var_request("message_type"));
797         input_validate_input_number(get_request_var_request("refresh"));
798         input_validate_input_number(get_request_var_request("reverse"));
799
800         /* if the user pushed the 'clear' button */
801         if (isset($_REQUEST["clear_x"])) {
802                 kill_session_var("sess_logfile_tail_lines");
803                 kill_session_var("sess_logfile_message_type");
804                 kill_session_var("sess_logfile_filter");
805                 kill_session_var("sess_logfile_refresh");
806                 kill_session_var("sess_logfile_reverse");
807
808                 unset($_REQUEST["tail_lines"]);
809                 unset($_REQUEST["message_type"]);
810                 unset($_REQUEST["filter"]);
811                 unset($_REQUEST["refresh"]);
812                 unset($_REQUEST["reverse"]);
813         }
814
815         load_current_session_value("tail_lines", "sess_logfile_tail_lines", read_config_option("num_rows_log"));
816         load_current_session_value("message_type", "sess_logfile_message_type", "-1");
817         load_current_session_value("filter", "sess_logfile_filter", "");
818         load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
819         load_current_session_value("reverse", "sess_logfile_reverse", 1);
820
821         $_REQUEST['page_referrer'] = 'view_logfile';
822         load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
823
824         $refresh["seconds"] = get_request_var_request("refresh");
825         $refresh["page"] = "utilities.php?action=view_logfile";
826
827         include_once("./include/top_header.php");
828
829         ?>
830         <script type="text/javascript">
831         <!--
832
833         function applyViewLogFilterChange(objForm) {
834                 strURL = '?tail_lines=' + objForm.tail_lines.value;
835                 strURL = strURL + '&message_type=' + objForm.message_type.value;
836                 strURL = strURL + '&refresh=' + objForm.refresh.value;
837                 strURL = strURL + '&reverse=' + objForm.reverse.value;
838                 strURL = strURL + '&filter=' + objForm.filter.value;
839                 strURL = strURL + '&action=view_logfile';
840                 document.location = strURL;
841         }
842
843         -->
844         </script>
845         <?php
846
847         html_start_box("<strong>Log File Filters</strong>", "100%", $colors["header"], "3", "center", "");
848
849         ?>
850         <tr bgcolor="#<?php print $colors["panel"];?>">
851                 <td>
852                 <form name="form_logfile" action="utilities.php">
853                         <table cellpadding="1" cellspacing="0">
854                                 <tr>
855                                         <td nowrap style='white-space: nowrap;' width="80">
856                                                 Tail Lines:&nbsp;
857                                         </td>
858                                         <td width="1">
859                                                 <select name="tail_lines" onChange="applyViewLogFilterChange(document.form_logfile)">
860                                                         <?php
861                                                         foreach($log_tail_lines AS $tail_lines => $display_text) {
862                                                                 print "<option value='" . $tail_lines . "'"; if (get_request_var_request("tail_lines") == $tail_lines) { print " selected"; } print ">" . $display_text . "</option>\n";
863                                                         }
864                                                         ?>
865                                                 </select>
866                                         </td>
867                                         <td nowrap style='white-space: nowrap;' width="100">
868                                                 &nbsp;Message Type:&nbsp;
869                                         </td>
870                                         <td width="1">
871                                                 <select name="message_type" onChange="applyViewLogFilterChange(document.form_logfile)">
872                                                         <option value="-1"<?php if (get_request_var_request("message_type") == '-1') {?> selected<?php }?>>All</option>
873                                                         <option value="1"<?php if (get_request_var_request("message_type") == '1') {?> selected<?php }?>>Stats</option>
874                                                         <option value="2"<?php if (get_request_var_request("message_type") == '2') {?> selected<?php }?>>Warnings</option>
875                                                         <option value="3"<?php if (get_request_var_request("message_type") == '3') {?> selected<?php }?>>Errors</option>
876                                                         <option value="4"<?php if (get_request_var_request("message_type") == '4') {?> selected<?php }?>>Debug</option>
877                                                         <option value="5"<?php if (get_request_var_request("message_type") == '5') {?> selected<?php }?>>SQL Calls</option>
878                                                 </select>
879                                         </td>
880                                         <td nowrap style='white-space: nowrap;'>
881                                                 &nbsp;<input type="submit" name="go" value="Go" title="Set/Refresh Filters">
882                                                 <input type="submit" name="clear_x" value="Clear" title="Clear Filters">
883                                                 <input type="submit" name="purge_x" value="Purge" title="Purge Log File">
884                                         </td>
885                                 </tr>
886                                 <tr>
887                                         <td nowrap style='white-space: nowrap;' width="80">
888                                                 Refresh:&nbsp;
889                                         </td>
890                                         <td width="1">
891                                                 <select name="refresh" onChange="applyViewLogFilterChange(document.form_logfile)">
892                                                         <?php
893                                                         foreach($page_refresh_interval AS $seconds => $display_text) {
894                                                                 print "<option value='" . $seconds . "'"; if (get_request_var_request("refresh") == $seconds) { print " selected"; } print ">" . $display_text . "</option>\n";
895                                                         }
896                                                         ?>
897                                                 </select>
898                                         </td>
899                                         <td nowrap style='white-space: nowrap;' width="100">
900                                                 &nbsp;Display Order:&nbsp;
901                                         </td>
902                                         <td width="1">
903                                                 <select name="reverse" onChange="applyViewLogFilterChange(document.form_logfile)">
904                                                         <option value="1"<?php if (get_request_var_request("reverse") == '1') {?> selected<?php }?>>Newest First</option>
905                                                         <option value="2"<?php if (get_request_var_request("reverse") == '2') {?> selected<?php }?>>Oldest First</option>
906                                                 </select>
907                                         </td>
908                                 </tr>
909                         </table>
910                         <table cellpadding="1" cellspacing="0">
911                                 <tr>
912                                         <td nowrap style='white-space: nowrap;' width="80">
913                                                 Search:&nbsp;
914                                         </td>
915                                         <td width="1">
916                                                 <input type="text" name="filter" size="75" value="<?php print htmlspecialchars(get_request_var_request("filter"));?>">
917                                         </td>
918                                 </tr>
919                         </table>
920                         <input type='hidden' name='page' value='1'>
921                         <input type='hidden' name='action' value='view_logfile'>
922                 </form>
923                 </td>
924         </tr>
925         <?php
926
927         html_end_box();
928
929         /* read logfile into an array and display */
930         $logcontents = tail_file($logfile, get_request_var_request("tail_lines"), get_request_var_request("message_type"), get_request_var_request("filter"));
931
932         if (get_request_var_request("reverse") == 1) {
933                 $logcontents = array_reverse($logcontents);
934         }
935
936         if (get_request_var_request("message_type") > 0) {
937                 $start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - Non-Matching Items Hidden]";
938         }else{
939                 $start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - All Items Shown]";
940         }
941
942         html_start_box($start_string, "100%", $colors["header"], "3", "center", "");
943
944         $i = 0;
945         $j = 0;
946         $linecolor = false;
947         foreach ($logcontents as $item) {
948                 $host_start = strpos($item, "Host[");
949                 $ds_start   = strpos($item, "DS[");
950
951                 $new_item = "";
952
953                 if ((!$host_start) && (!$ds_start)) {
954                         $new_item = $item;
955                 }else{
956                         while ($host_start) {
957                                 $host_end   = strpos($item, "]", $host_start);
958                                 $host_id    = substr($item, $host_start+5, $host_end-($host_start+5));
959                                 $new_item   = $new_item . substr($item, 0, $host_start + 5) . "<a href='" . htmlspecialchars("host.php?action=edit&id=" . $host_id) . "'>" . substr($item, $host_start + 5, $host_end-($host_start + 5)) . "</a>";
960                                 $item       = substr($item, $host_end);
961                                 $host_start = strpos($item, "Host[");
962                         }
963
964                         $ds_start = strpos($item, "DS[");
965                         while ($ds_start) {
966                                 $ds_end   = strpos($item, "]", $ds_start);
967                                 $ds_id    = substr($item, $ds_start+3, $ds_end-($ds_start+3));
968                                 $new_item = $new_item . substr($item, 0, $ds_start + 3) . "<a href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $ds_id) . "'>" . substr($item, $ds_start + 3, $ds_end-($ds_start + 3)) . "</a>";
969                                 $item     = substr($item, $ds_end);
970                                 $ds_start = strpos($item, "DS[");
971                         }
972
973                         $new_item = $new_item . $item;
974                 }
975
976                 /* get the background color */
977                 if ((substr_count($new_item, "ERROR")) || (substr_count($new_item, "FATAL"))) {
978                         $bgcolor = "FF3932";
979                 }elseif (substr_count($new_item, "WARN")) {
980                         $bgcolor = "EACC00";
981                 }elseif (substr_count($new_item, " SQL ")) {
982                         $bgcolor = "6DC8FE";
983                 }elseif (substr_count($new_item, "DEBUG")) {
984                         $bgcolor = "C4FD3D";
985                 }elseif (substr_count($new_item, "STATS")) {
986                         $bgcolor = "96E78A";
987                 }else{
988                         if ($linecolor) {
989                                 $bgcolor = "CCCCCC";
990                         }else{
991                                 $bgcolor = "FFFFFF";
992                         }
993                         $linecolor = !$linecolor;
994                 }
995
996                 ?>
997                 <tr bgcolor='#<?php print $bgcolor;?>'>
998                         <td>
999                                 <?php print $new_item;?>
1000                         </td>
1001                 </tr>
1002                 <?php
1003                 $j++;
1004                 $i++;
1005
1006                 if ($j > 1000) {
1007                         ?>
1008                         <tr bgcolor='#EACC00'>
1009                                 <td>
1010                                         <?php print ">>>>  LINE LIMIT OF 1000 LINES REACHED!!  <<<<";?>
1011                                 </td>
1012                         </tr>
1013                         <?php
1014
1015                         break;
1016                 }
1017         }
1018
1019         html_end_box();
1020
1021         include_once("./include/bottom_footer.php");
1022 }
1023
1024 function utilities_clear_logfile() {
1025         global $colors;
1026
1027         load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
1028
1029         $refresh["seconds"] = get_request_var_request("refresh");
1030         $refresh["page"] = "utilities.php?action=view_logfile";
1031
1032         include_once("./include/top_header.php");
1033
1034         $logfile = read_config_option("path_cactilog");
1035
1036         if ($logfile == "") {
1037                 $logfile = "./log/cacti.log";
1038         }
1039
1040         html_start_box("<strong>Clear Cacti Log File</strong>", "100%", $colors["header"], "1", "center", "");
1041         if (file_exists($logfile)) {
1042                 if (is_writable($logfile)) {
1043                         $timestamp = date("m/d/Y h:i:s A");
1044                         $log_fh = fopen($logfile, "w");
1045                         fwrite($log_fh, $timestamp . " - WEBUI: Cacti Log Cleared from Web Management Interface\n");
1046                         fclose($log_fh);
1047                         print "<tr><td>Cacti Log File Cleared</td></tr>";
1048                 }else{
1049                         print "<tr><td><font color='red'><b>Error: Unable to clear log, no write permissions.<b></font></td></tr>";
1050                 }
1051         }else{
1052                 print "<tr><td><font color='red'><b>Error: Unable to clear log, file does not exist.</b></font></td></tr>";
1053         }
1054         html_end_box();
1055 }
1056
1057 function utilities_view_snmp_cache() {
1058         global $colors, $poller_actions;
1059
1060         define("MAX_DISPLAY_PAGES", 21);
1061
1062         /* ================= input validation ================= */
1063         input_validate_input_number(get_request_var_request("host_id"));
1064         input_validate_input_number(get_request_var_request("snmp_query_id"));
1065         input_validate_input_number(get_request_var_request("page"));
1066         input_validate_input_number(get_request_var_request("poller_action"));
1067         /* ==================================================== */
1068
1069         /* clean up search filter */
1070         if (isset($_REQUEST["filter"])) {
1071                 $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
1072         }
1073
1074         /* if the user pushed the 'clear' button */
1075         if (isset($_REQUEST["clear_x"])) {
1076                 kill_session_var("sess_snmp_current_page");
1077                 kill_session_var("sess_snmp_host_id");
1078                 kill_session_var("sess_snmp_snmp_query_id");
1079                 kill_session_var("sess_snmp_filter");
1080
1081                 unset($_REQUEST["page"]);
1082                 unset($_REQUEST["filter"]);
1083                 unset($_REQUEST["host_id"]);
1084                 unset($_REQUEST["snmp_query_id"]);
1085         }
1086
1087         /* remember these search fields in session vars so we don't have to keep passing them around */
1088         load_current_session_value("page", "sess_snmp_current_page", "1");
1089         load_current_session_value("host_id", "sess_snmp_host_id", "-1");
1090         load_current_session_value("snmp_query_id", "sess_snmp_snmp_query_id", "-1");
1091         load_current_session_value("filter", "sess_snmp_filter", "");
1092
1093         $_REQUEST['page_referrer'] = 'view_snmp_cache';
1094         load_current_session_value('page_referrer', 'page_referrer', 'view_snmp_cache');
1095
1096         ?>
1097         <script type="text/javascript">
1098         <!--
1099
1100         function applyViewSNMPFilterChange(objForm) {
1101                 strURL = '?host_id=' + objForm.host_id.value;
1102                 strURL = strURL + '&snmp_query_id=' + objForm.snmp_query_id.value;
1103                 strURL = strURL + '&filter=' + objForm.filter.value;
1104                 strURL = strURL + '&action=view_snmp_cache';
1105                 document.location = strURL;
1106         }
1107
1108         -->
1109         </script>
1110         <?php
1111
1112         html_start_box("<strong>SNMP Cache Items</strong>", "100%", $colors["header"], "3", "center", "");
1113
1114         ?>
1115         <tr bgcolor="#<?php print $colors["panel"];?>">
1116                 <td>
1117                 <form name="form_snmpcache" action="utilities.php">
1118                         <table cellpadding="0" cellspacing="0">
1119                                 <tr>
1120                                         <td nowrap style='white-space: nowrap;' width="50">
1121                                                 Host:&nbsp;
1122                                         </td>
1123                                         <td width="1">
1124                                                 <select name="host_id" onChange="applyViewSNMPFilterChange(document.form_snmpcache)">
1125                                                         <option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option>
1126                                                         <option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option>
1127                                                         <?php
1128                                                         if (get_request_var_request("snmp_query_id") == -1) {
1129                                                                 $hosts = db_fetch_assoc("SELECT DISTINCT
1130                                                                                         host.id,
1131                                                                                         host.description,
1132                                                                                         host.hostname
1133                                                                                         FROM (host_snmp_cache,snmp_query,host)
1134                                                                                         WHERE host_snmp_cache.host_id=host.id
1135                                                                                         AND host_snmp_cache.snmp_query_id=snmp_query.id
1136                                                                                         ORDER by host.description");
1137                                                         }else{
1138                                                                 $hosts = db_fetch_assoc("SELECT DISTINCT
1139                                                                                         host.id,
1140                                                                                         host.description,
1141                                                                                         host.hostname
1142                                                                                         FROM (host_snmp_cache,snmp_query,host)
1143                                                                                         WHERE host_snmp_cache.host_id=host.id
1144                                                                                         AND host_snmp_cache.snmp_query_id=snmp_query.id
1145                                                                                         AND host_snmp_cache.snmp_query_id='" . get_request_var_request("snmp_query_id") . "'
1146                                                                                         ORDER by host.description");
1147                                                         }
1148                                                         if (sizeof($hosts) > 0) {
1149                                                         foreach ($hosts as $host) {
1150                                                                 print "<option value='" . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . $host["description"] . "</option>\n";
1151                                                         }
1152                                                         }
1153                                                         ?>
1154                                                 </select>
1155                                         </td>
1156                                         <td nowrap style='white-space: nowrap;' width="90">
1157                                                 &nbsp;Query Name:&nbsp;
1158                                         </td>
1159                                         <td width="1">
1160                                                 <select name="snmp_query_id" onChange="applyViewSNMPFilterChange(document.form_snmpcache)">
1161                                                         <option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option>
1162                                                         <?php
1163                                                         if (get_request_var_request("host_id") == -1) {
1164                                                                 $snmp_queries = db_fetch_assoc("SELECT DISTINCT
1165                                                                                         snmp_query.id,
1166                                                                                         snmp_query.name
1167                                                                                         FROM (host_snmp_cache,snmp_query,host)
1168                                                                                         WHERE host_snmp_cache.host_id=host.id
1169                                                                                         AND host_snmp_cache.snmp_query_id=snmp_query.id
1170                                                                                         ORDER by snmp_query.name");
1171                                                         }else{
1172                                                                 $snmp_queries = db_fetch_assoc("SELECT DISTINCT
1173                                                                                         snmp_query.id,
1174                                                                                         snmp_query.name
1175                                                                                         FROM (host_snmp_cache,snmp_query,host)
1176                                                                                         WHERE host_snmp_cache.host_id=host.id
1177                                                                                         AND host_snmp_cache.host_id='" . get_request_var_request("host_id") . "'
1178                                                                                         AND host_snmp_cache.snmp_query_id=snmp_query.id
1179                                                                                         ORDER by snmp_query.name");
1180                                                         }
1181                                                         if (sizeof($snmp_queries) > 0) {
1182                                                         foreach ($snmp_queries as $snmp_query) {
1183                                                                 print "<option value='" . $snmp_query["id"] . "'"; if (get_request_var_request("snmp_query_id") == $snmp_query["id"]) { print " selected"; } print ">" . $snmp_query["name"] . "</option>\n";
1184                                                         }
1185                                                         }
1186                                                         ?>
1187                                                 </select>
1188                                         </td>
1189                                         <td nowrap style='white-space: nowrap;' width="50">
1190                                                 &nbsp;Search:&nbsp;
1191                                         </td>
1192                                         <td width="1">
1193                                                 <input type="text" name="filter" size="20" value="<?php print htmlspecialchars(get_request_var_request("filter"));?>">
1194                                         </td>
1195                                         <td nowrap style='white-space: nowrap;'>
1196                                                 &nbsp;<input type="submit" name="go" value="Go" title="Set/Refresh Filters">
1197                                                 <input type="submit" name="clear_x" value="Clear" title="Clear Fitlers">
1198                                         </td>
1199                                 </tr>
1200                         </table>
1201                         <input type='hidden' name='page' value='1'>
1202                         <input type='hidden' name='action' value='view_snmp_cache'>
1203                 </form>
1204                 </td>
1205         </tr>
1206         <?php
1207
1208         html_end_box();
1209
1210         $sql_where = "";
1211
1212         /* filter by host */
1213         if (get_request_var_request("host_id") == "-1") {
1214                 /* Show all items */
1215         }elseif (get_request_var_request("host_id") == "0") {
1216                 $sql_where .= " AND host.id=0";
1217         }elseif (!empty($_REQUEST["host_id"])) {
1218                 $sql_where .= " AND host.id=" . get_request_var_request("host_id");
1219         }
1220
1221         /* filter by query name */
1222         if (get_request_var_request("snmp_query_id") == "-1") {
1223                 /* Show all items */
1224         }elseif (!empty($_REQUEST["snmp_query_id"])) {
1225                 $sql_where .= " AND host_snmp_cache.snmp_query_id=" . get_request_var_request("snmp_query_id");
1226         }
1227
1228         /* filter by search string */
1229         if (get_request_var_request("filter") != "") {
1230                 $sql_where .= " AND (host.description LIKE '%%" . get_request_var_request("filter") . "%%'
1231                         OR snmp_query.name LIKE '%%" . get_request_var_request("filter") . "%%'
1232                         OR host_snmp_cache.field_name LIKE '%%" . get_request_var_request("filter") . "%%'
1233                         OR host_snmp_cache.field_value LIKE '%%" . get_request_var_request("filter") . "%%'
1234                         OR host_snmp_cache.oid LIKE '%%" . get_request_var_request("filter") . "%%')";
1235         }
1236
1237         html_start_box("", "100%", $colors["header"], "3", "center", "");
1238
1239         $total_rows = db_fetch_cell("SELECT
1240                 COUNT(*)
1241                 FROM (host_snmp_cache,snmp_query,host)
1242                 WHERE host_snmp_cache.host_id=host.id
1243                 AND host_snmp_cache.snmp_query_id=snmp_query.id
1244                 $sql_where");
1245
1246         $snmp_cache_sql = "SELECT
1247                 host_snmp_cache.*,
1248                 host.description,
1249                 snmp_query.name
1250                 FROM (host_snmp_cache,snmp_query,host)
1251                 WHERE host_snmp_cache.host_id=host.id
1252                 AND host_snmp_cache.snmp_query_id=snmp_query.id
1253                 $sql_where
1254                 LIMIT " . (read_config_option("num_rows_data_source")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_data_source");
1255
1256 //      print $snmp_cache_sql;
1257
1258         $snmp_cache = db_fetch_assoc($snmp_cache_sql);
1259
1260         /* generate page list */
1261         $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "utilities.php?action=view_snmp_cache&host_id=" . get_request_var_request("host_id") . "&filter=" . get_request_var_request("filter"));
1262
1263         $nav = "<tr bgcolor='#" . $colors["header"] . "'>
1264                         <td colspan='7'>
1265                                 <table width='100%' cellspacing='0' cellpadding='0' border='0'>
1266                                         <tr>
1267                                                 <td align='left' class='textHeaderDark'>
1268                                                         <strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("utilities.php?action=view_snmp_cache&host_id=" . get_request_var_request("host_id") . "&filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")-1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
1269                                                 </td>\n
1270                                                 <td align='center' class='textHeaderDark'>
1271                                                         Showing Rows " . ((read_config_option("num_rows_data_source")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_data_source")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
1272                                                 </td>\n
1273                                                 <td align='right' class='textHeaderDark'>
1274                                                         <strong>"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("utilities.php?action=view_snmp_cache&host_id=" . get_request_var_request("host_id") . "&filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")+1)) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
1275                                                 </td>\n
1276                                         </tr>
1277                                 </table>
1278                         </td>
1279                 </tr>\n";
1280
1281         print $nav;
1282
1283         html_header(array("Details"));
1284
1285         $i = 0;
1286         if (sizeof($snmp_cache) > 0) {
1287         foreach ($snmp_cache as $item) {
1288                 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
1289                 ?>
1290                 <td>
1291                         Host: <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["description"])) : $item["description"]);?>
1292                         , SNMP Query: <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["name"])) : $item["name"]);?>
1293                 </td>
1294                 </tr>
1295                 <?php
1296                 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
1297                 ?>
1298                 <td>
1299                         Index: <?php print $item["snmp_index"];?>
1300                         , Field Name: <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["field_name"])) : $item["field_name"]);?>
1301                         , Field Value: <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["field_value"])) : $item["field_value"]);?>
1302                 </td>
1303                 </tr>
1304                 <?php
1305                 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
1306                 ?>
1307                 <td>
1308                         OID: <?php print (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["oid"])) : $item["oid"]);?>
1309                 </td>
1310                 </tr>
1311                 <?php
1312         }
1313         }
1314
1315         html_end_box();
1316 }
1317
1318 function utilities_view_poller_cache() {
1319         global $colors, $poller_actions;
1320
1321         define("MAX_DISPLAY_PAGES", 21);
1322
1323         /* ================= input validation ================= */
1324         input_validate_input_number(get_request_var_request("host_id"));
1325         input_validate_input_number(get_request_var_request("page"));
1326         input_validate_input_number(get_request_var_request("poller_action"));
1327         /* ==================================================== */
1328
1329         /* clean up search filter */
1330         if (isset($_REQUEST["filter"])) {
1331                 $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
1332         }
1333
1334         /* clean up sort_column */
1335         if (isset($_REQUEST["sort_column"])) {
1336                 $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
1337         }
1338
1339         /* clean up sort direction */
1340         if (isset($_REQUEST["sort_direction"])) {
1341                 $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
1342         }
1343
1344         /* if the user pushed the 'clear' button */
1345         if (isset($_REQUEST["clear_x"])) {
1346                 kill_session_var("sess_poller_current_page");
1347                 kill_session_var("sess_poller_host_id");
1348                 kill_session_var("sess_poller_poller_action");
1349                 kill_session_var("sess_poller_filter");
1350
1351                 unset($_REQUEST["page"]);
1352                 unset($_REQUEST["filter"]);
1353                 unset($_REQUEST["host_id"]);
1354                 unset($_REQUEST["poller_action"]);
1355         }
1356
1357         if ((!empty($_SESSION["sess_poller_action"])) && (!empty($_REQUEST["poller_action"]))) {
1358                 if ($_SESSION["sess_poller_poller_action"] != $_REQUEST["poller_action"]) {
1359                         $_REQUEST["page"] = 1;
1360                 }
1361         }
1362
1363         /* remember these search fields in session vars so we don't have to keep passing them around */
1364         load_current_session_value("page", "sess_poller_current_page", "1");
1365         load_current_session_value("host_id", "sess_poller_host_id", "-1");
1366         load_current_session_value("poller_action", "sess_poller_poller_action", "-1");
1367         load_current_session_value("filter", "sess_poller_filter", "");
1368         load_current_session_value("sort_column", "sess_poller_sort_column", "data_template_data.name_cache");
1369         load_current_session_value("sort_direction", "sess_poller_sort_direction", "ASC");
1370
1371         $_REQUEST['page_referrer'] = 'view_poller_cache';
1372         load_current_session_value('page_referrer', 'page_referrer', 'view_poller_cache');
1373
1374         ?>
1375         <script type="text/javascript">
1376         <!--
1377
1378         function applyPItemFilterChange(objForm) {
1379                 strURL = '?poller_action=' + objForm.poller_action.value;
1380                 strURL = strURL + '&host_id=' + objForm.host_id.value;
1381                 strURL = strURL + '&filter=' + objForm.filter.value;
1382                 strURL = strURL + '&action=view_poller_cache';
1383                 document.location = strURL;
1384         }
1385
1386         -->
1387         </script>
1388         <?php
1389
1390         html_start_box("<strong>Poller Cache Items</strong>", "100%", $colors["header"], "3", "center", "");
1391
1392         ?>
1393         <tr bgcolor="#<?php print $colors["panel"];?>">
1394                 <td>
1395                 <form name="form_pollercache" action="utilities.php">
1396                         <table cellpadding="0" cellspacing="0">
1397                                 <tr>
1398                                         <td nowrap style='white-space: nowrap;' width="50">
1399                                                 Host:&nbsp;
1400                                         </td>
1401                                         <td width="1">
1402                                                 <select name="host_id" onChange="applyPItemFilterChange(document.form_pollercache)">
1403                                                         <option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option>
1404                                                         <option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option>
1405                                                         <?php
1406                                                         $hosts = db_fetch_assoc("select id,description,hostname from host order by description");
1407
1408                                                         if (sizeof($hosts) > 0) {
1409                                                         foreach ($hosts as $host) {
1410                                                                 print "<option value='" . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . $host["description"] . "</option>\n";
1411                                                         }
1412                                                         }
1413                                                         ?>
1414                                                 </select>
1415                                         </td>
1416                                         <td nowrap style='white-space: nowrap;' width="50">
1417                                                 &nbsp;Action:&nbsp;
1418                                         </td>
1419                                         <td width="1">
1420                                                 <select name="poller_action" onChange="applyPItemFilterChange(document.form_pollercache)">
1421                                                         <option value="-1"<?php if (get_request_var_request("poller_action") == '-1') {?> selected<?php }?>>Any</option>
1422                                                         <option value="0"<?php if (get_request_var_request("poller_action") == '0') {?> selected<?php }?>>SNMP</option>
1423                                                         <option value="1"<?php if (get_request_var_request("poller_action") == '1') {?> selected<?php }?>>Script</option>
1424                                                         <option value="2"<?php if (get_request_var_request("poller_action") == '2') {?> selected<?php }?>>Script Server</option>
1425                                                 </select>
1426                                         </td>
1427                                         <td nowrap style='white-space: nowrap;' width="50">
1428                                                 &nbsp;Search:&nbsp;
1429                                         </td>
1430                                         <td width="1">
1431                                                 <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter"));?>">
1432                                         </td>
1433                                         <td nowrap style='white-space: nowrap;'>
1434                                                 &nbsp;<input type="submit" name="go" value="Go" title="Set/Refresh Filters">
1435                                                 <input type="submit" name="clear_x" value="Clear" title="Clear Filters">
1436                                         </td>
1437                                 </tr>
1438                         </table>
1439                         <input type='hidden' name='page' value='1'>
1440                         <input type='hidden' name='action' value='view_poller_cache'>
1441                 </form>
1442                 </td>
1443         </tr>
1444         <?php
1445
1446         html_end_box();
1447
1448         /* form the 'where' clause for our main sql query */
1449         $sql_where = "WHERE poller_item.local_data_id=data_template_data.local_data_id";
1450
1451         if (get_request_var_request("poller_action") != "-1") {
1452                 $sql_where .= " AND poller_item.action='" . get_request_var_request("poller_action") . "'";
1453         }
1454
1455         if (get_request_var_request("host_id") == "-1") {
1456                 /* Show all items */
1457         }elseif (get_request_var_request("host_id") == "0") {
1458                 $sql_where .= " AND poller_item.host_id=0";
1459         }elseif (!empty($_REQUEST["host_id"])) {
1460                 $sql_where .= " AND poller_item.host_id=" . get_request_var_request("host_id");
1461         }
1462
1463         if (strlen(get_request_var_request("filter"))) {
1464                 $sql_where .= " AND (data_template_data.name_cache LIKE '%%" . get_request_var_request("filter") . "%%'
1465                         OR host.description LIKE '%%" . get_request_var_request("filter") . "%%'
1466                         OR poller_item.arg1 LIKE '%%" . get_request_var_request("filter") . "%%'
1467                         OR poller_item.hostname LIKE '%%" . get_request_var_request("filter") . "%%'
1468                         OR poller_item.rrd_path  LIKE '%%" . get_request_var_request("filter") . "%%')";
1469         }
1470
1471         html_start_box("", "100%", $colors["header"], "3", "center", "");
1472
1473         $total_rows = db_fetch_cell("SELECT
1474                 COUNT(*)
1475                 FROM data_template_data
1476                 RIGHT JOIN (poller_item
1477                 LEFT JOIN host
1478                 ON poller_item.host_id=host.id)
1479                 ON data_template_data.local_data_id=poller_item.local_data_id
1480                 $sql_where");
1481
1482         $poller_sql = "SELECT
1483                 poller_item.*,
1484                 data_template_data.name_cache,
1485                 host.description
1486                 FROM data_template_data
1487                 RIGHT JOIN (poller_item
1488                 LEFT JOIN host
1489                 ON poller_item.host_id=host.id)
1490                 ON data_template_data.local_data_id=poller_item.local_data_id
1491                 $sql_where
1492                 ORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . ", action ASC
1493                 LIMIT " . (read_config_option("num_rows_data_source")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_data_source");
1494
1495 //      print $poller_sql;
1496
1497         $poller_cache = db_fetch_assoc($poller_sql);
1498
1499         /* generate page list */
1500         $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "utilities.php?action=view_poller_cache&host_id=" . get_request_var_request("host_id") . "&poller_action=" . get_request_var_request("poller_action"));
1501
1502         $nav = "<tr bgcolor='#" . $colors["header"] . "'>
1503                         <td colspan='7'>
1504                                 <table width='100%' cellspacing='0' cellpadding='0' border='0'>
1505                                         <tr>
1506                                                 <td align='left' class='textHeaderDark'>
1507                                                         <strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("utilities.php?action=view_poller_cache&host_id=" . get_request_var_request("host_id") . "&poller_action=" . get_request_var_request("poller_action") . "&page=" . (get_request_var_request("page")-1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
1508                                                 </td>\n
1509                                                 <td align='center' class='textHeaderDark'>
1510                                                         Showing Rows " . ((read_config_option("num_rows_data_source")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_data_source")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
1511                                                 </td>\n
1512                                                 <td align='right' class='textHeaderDark'>
1513                                                         <strong>"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("utilities.php?action=view_poller_cache&host_id=" . get_request_var_request("host_id") . "&poller_action=" . get_request_var_request("poller_action") . "&page=" . (get_request_var_request("page")+1)) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
1514                                                 </td>\n
1515                                         </tr>
1516                                 </table>
1517                         </td>
1518                 </tr>\n";
1519
1520         print $nav;
1521
1522         $display_text = array(
1523                 "data_template_data.name_cache" => array("Data Source Name", "ASC"),
1524                 "nosort" => array("Details", "ASC"));
1525
1526         html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));
1527
1528         $i = 0;
1529         if (sizeof($poller_cache) > 0) {
1530         foreach ($poller_cache as $item) {
1531                 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
1532                         ?>
1533                         <td width="375">
1534                                 <a class="linkEditMain" href="<?php print htmlspecialchars("data_sources.php?action=ds_edit&id=" . $item["local_data_id"]);?>"><?php print (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["name_cache"]):$item["name_cache"]);?></a>
1535                         </td>
1536
1537                         <td>
1538                         <?php
1539                         if ($item["action"] == 0) {
1540                                 if ($item["snmp_version"] != 3) {
1541                                         $details =
1542                                                 "SNMP Version: " . $item["snmp_version"] . ", " .
1543                                                 "Community: " . $item["snmp_community"] . ", " .
1544                                                 "OID: " . (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"])) : $item["arg1"]);
1545                                 }else{
1546                                         $details =
1547                                                 "SNMP Version: " . $item["snmp_version"] . ", " .
1548                                                 "User: " . $item["snmp_username"] . ", OID: " . $item["arg1"];
1549                                 }
1550                         }elseif ($item["action"] == 1) {
1551                                         $details = "Script: " . (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"])) : $item["arg1"]);
1552                         }else{
1553                                         $details = "Script Server: " . (strlen(get_request_var_request("filter")) ? (eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"])) : $item["arg1"]);
1554                         }
1555
1556                         print $details;
1557                         ?>
1558                         </td>
1559                 </tr>
1560                 <?php
1561
1562                 form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
1563                 ?>
1564                         <td>
1565                         </td>
1566                         <td>
1567                                 RRD: <?php print $item["rrd_path"];?>
1568                         </td>
1569                 </tr>
1570                 <?php
1571                 $i++;
1572         }
1573         }
1574
1575         html_end_box();
1576 }
1577
1578 function utilities() {
1579         global $colors;
1580
1581         html_start_box("<strong>Cacti System Utilities</strong>", "100%", $colors["header"], "3", "center", "");
1582
1583         ?>
1584         <colgroup span="3">
1585                 <col valign="top" width="20%"></col>
1586                 <col valign="top" width="80%"></col>
1587         </colgroup>
1588
1589         <?php html_header(array("Technical Support"), 2); ?>
1590         <tr bgcolor="#<?php print $colors["form_alternate1"];?>">
1591                 <td class="textArea">
1592                         <a href='<?php print htmlspecialchars("utilities.php?action=view_tech");?>'>Technical Support</a>
1593                 </td>
1594                 <td class="textArea">
1595                         Cacti technical support page.  Used by developers and technical support persons to assist with issues in Cacti.  Includes checks for common configuration issues.
1596                 </td>
1597         </tr>
1598
1599         <?php html_header(array("Log Administration"), 2);?>
1600
1601         <tr bgcolor="#<?php print $colors["form_alternate1"];?>">
1602                 <td class="textArea">
1603                         <a href='<?php print htmlspecialchars("utilities.php?action=view_logfile");?>'>View Cacti Log File</a>
1604                 </td>
1605                 <td class="textArea">
1606                         The Cacti Log File stores statistic, error and other message depending on system settings.  This information can be used to identify problems with the poller and application.
1607                 </td>
1608         </tr>
1609         <tr bgcolor="#<?php print $colors["form_alternate1"];?>">
1610                 <td class="textArea">
1611                         <a href='<?php print htmlspecialchars("utilities.php?action=view_user_log");?>'>View User Log</a>
1612                 </td>
1613                 <td class="textArea">
1614                         Allows Administrators to browse the user log.  Administrators can filter and export the log as well.
1615                 </td>
1616         </tr>
1617
1618         <?php html_header(array("Poller Cache Administration"), 2); ?>
1619
1620         <tr bgcolor="#<?php print $colors["form_alternate1"];?>">
1621                 <td class="textArea">
1622                         <a href='<?php print htmlspecialchars("utilities.php?action=view_poller_cache");?>'>View Poller Cache</a>
1623                 </td>
1624                 <td class="textArea">
1625                         This is the data that is being passed to the poller each time it runs. This data is then in turn executed/interpreted and the results are fed into the rrd files for graphing or the database for display.
1626                 </td>
1627         </tr>
1628         <tr bgcolor="#<?php print $colors["form_alternate2"];?>">
1629                 <td class="textArea">
1630                         <a href='<?php print htmlspecialchars("utilities.php?action=view_snmp_cache");?>'>View SNMP Cache</a>
1631                 </td>
1632                 <td class="textArea">
1633                         The SNMP cache stores information gathered from SNMP queries. It is used by cacti to determine the OID to use when gathering information from an SNMP-enabled host.
1634                 </td>
1635         </tr>
1636         <tr bgcolor="#<?php print $colors["form_alternate1"];?>">
1637                 <td class="textArea">
1638                         <a href='<?php print htmlspecialchars("utilities.php?action=clear_poller_cache");?>'>Rebuild Poller Cache</a>
1639                 </td>
1640                 <td class="textArea">
1641                         The poller cache will be cleared and re-generated if you select this option. Sometimes host/data source data can get out of sync with the cache in which case it makes sense to clear the cache and start over.
1642                 </td>
1643         </tr>
1644
1645         <?php
1646
1647         html_end_box();
1648 }
1649
1650 ?>
1651
1652