1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
|
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004 Ian Berry |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| cacti: a php-based graphing solution |
+-------------------------------------------------------------------------+
| Most of this code has been designed, written and is maintained by |
| Ian Berry. See about.php for specific developer credit. Any questions |
| or comments regarding this code should be directed to: |
| - iberry@raxnet.net |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/ |
+-------------------------------------------------------------------------+
*/
include("./include/auth.php");
include_once("./lib/utility.php");
load_current_session_value("page_referrer", "page_referrer", "");
/* set default action */
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
if (isset($_REQUEST["sort_direction"])) {
if ($_REQUEST['page_referrer'] == "view_snmp_cache") {
$_REQUEST["action"] = "view_snmp_cache";
}else if ($_REQUEST['page_referrer'] == "view_poller_cache") {
$_REQUEST["action"] = "view_poller_cache";
}else{
$_REQUEST["action"] = "view_user_log";
}
}
if ((isset($_REQUEST["clear_x"])) || (isset($_REQUEST["go_x"]))) {
if ($_REQUEST['page_referrer'] == "view_snmp_cache") {
$_REQUEST["action"] = "view_snmp_cache";
}else if ($_REQUEST['page_referrer'] == "view_poller_cache") {
$_REQUEST["action"] = "view_poller_cache";
}else if ($_REQUEST['page_referrer'] == "view_user_log") {
$_REQUEST["action"] = "view_user_log";
}else{
$_REQUEST["action"] = "view_logfile";
}
}
if (isset($_REQUEST["purge_x"])) {
if ($_REQUEST['page_referrer'] == "view_user_log") {
$_REQUEST["action"] = "clear_user_log";
}else{
$_REQUEST["action"] = "clear_logfile";
}
}
switch ($_REQUEST["action"]) {
case 'clear_poller_cache':
include_once("./include/top_header.php");
/* obtain timeout settings */
$max_execution = ini_get("max_execution_time");
$max_memory = ini_get("memory_limit");
ini_set("max_execution_time", "0");
ini_set("memory_limit", "32M");
repopulate_poller_cache();
ini_set("max_execution_time", $max_execution);
ini_set("memory_limit", $max_memory);
utilities_view_poller_cache();
include_once("./include/bottom_footer.php");
break;
case 'view_snmp_cache':
include_once("./include/top_header.php");
utilities_view_snmp_cache();
include_once("./include/bottom_footer.php");
break;
case 'view_poller_cache':
include_once("./include/top_header.php");
utilities_view_poller_cache();
include_once("./include/bottom_footer.php");
break;
case 'view_logfile':
utilities_view_logfile();
break;
case 'clear_logfile':
utilities_clear_logfile();
utilities_view_logfile();
include_once("./include/bottom_footer.php");
break;
case 'view_user_log':
include_once("./include/top_header.php");
utilities_view_user_log();
include_once("./include/bottom_footer.php");
break;
case 'clear_user_log':
include_once("./include/top_header.php");
utilities_clear_user_log();
utilities_view_user_log();
include_once("./include/bottom_footer.php");
break;
default:
include_once("./include/top_header.php");
utilities();
include_once("./include/bottom_footer.php");
break;
}
/* -----------------------
Utilities Functions
----------------------- */
function utilities_view_user_log() {
global $colors, $poller_actions;
define("MAX_DISPLAY_PAGES", 21);
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request("result"));
input_validate_input_number(get_request_var_request("page"));
/* ==================================================== */
/* clean up username */
if (isset($_REQUEST["username"])) {
$_REQUEST["username"] = sanitize_search_string(get_request_var("username"));
}
/* clean up search filter */
if (isset($_REQUEST["filter"])) {
$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
}
/* clean up sort_column */
if (isset($_REQUEST["sort_column"])) {
$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
}
/* clean up sort direction */
if (isset($_REQUEST["sort_direction"])) {
$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
}
/* if the user pushed the 'clear' button */
if (isset($_REQUEST["clear_x"])) {
kill_session_var("sess_userlog_current_page");
kill_session_var("sess_userlog_username");
kill_session_var("sess_userlog_result");
kill_session_var("sess_userlog_filter");
kill_session_var("sess_userlog_sort_column");
kill_session_var("sess_userlog_sort_direction");
unset($_REQUEST["page"]);
unset($_REQUEST["result"]);
unset($_REQUEST["filter"]);
unset($_REQUEST["username"]);
unset($_REQUEST["sort_column"]);
unset($_REQUEST["sort_direction"]);
}
/* remember these search fields in session vars so we don't have to keep passing them around */
load_current_session_value("page", "sess_userlog_current_page", "1");
load_current_session_value("username", "sess_userlog_username", "-1");
load_current_session_value("result", "sess_userlog_result", "-1");
load_current_session_value("filter", "sess_userlog_filter", "");
load_current_session_value("sort_column", "sess_userlog_sort_column", "time");
load_current_session_value("sort_direction", "sess_userlog_sort_direction", "DESC");
$_REQUEST['page_referrer'] = 'view_user_log';
load_current_session_value('page_referrer', 'page_referrer', 'view_user_log');
html_start_box("<strong>User Login History</strong>", "98%", $colors["header"], "3", "center", "");
include("./include/html/inc_user_log_filter_table.php");
html_end_box();
$sql_where = "";
/* filter by host */
if ($_REQUEST["username"] == "-1") {
/* Show all items */
}elseif ($_REQUEST["username"] == "-2") {
$sql_where = "WHERE user_log.username NOT IN (SELECT DISTINCT username from user_auth)";
}elseif (!empty($_REQUEST["username"])) {
$sql_where = "WHERE user_log.username='" . $_REQUEST["username"] . "'";
}
/* filter by result */
if ($_REQUEST["result"] == "-1") {
/* Show all items */
}else{
if (strlen($sql_where)) {
$sql_where .= " AND user_log.result=" . $_REQUEST["result"];
}else{
$sql_where = "WHERE user_log.result=" . $_REQUEST["result"];
}
}
/* filter by search string */
if ($_REQUEST["filter"] <> "") {
if (strlen($sql_where)) {
$sql_where .= " AND (user_log.username LIKE '%%" . $_REQUEST["filter"] . "%%'
OR user_log.time LIKE '%%" . $_REQUEST["filter"] . "%%'
OR user_log.ip LIKE '%%" . $_REQUEST["filter"] . "%%')";
}else{
$sql_where = "WHERE (user_log.username LIKE '%%" . $_REQUEST["filter"] . "%%'
OR user_log.time LIKE '%%" . $_REQUEST["filter"] . "%%'
OR user_log.ip LIKE '%%" . $_REQUEST["filter"] . "%%')";
}
}
html_start_box("", "98%", $colors["header"], "3", "center", "");
$total_rows = db_fetch_cell("SELECT
COUNT(*)
FROM user_auth
RIGHT JOIN user_log
ON user_auth.username = user_log.username
$sql_where");
$user_log_sql = "SELECT
user_log.username,
user_auth.full_name,
user_log.time,
user_log.result,
user_log.ip
FROM user_auth
RIGHT JOIN user_log
ON user_auth.username = user_log.username
$sql_where
ORDER BY " . $_REQUEST["sort_column"] . " " . $_REQUEST["sort_direction"] . "
LIMIT " . (read_config_option("num_rows_data_source")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_data_source");
// print $user_log_sql;
$user_log = db_fetch_assoc($user_log_sql);
/* generate page list */
$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "utilities.php?action=view_user_log&username=" . $_REQUEST["username"] . "&filter=" . $_REQUEST["filter"]);
$nav = "<tr bgcolor='#" . $colors["header"] . "'>
<td colspan='7'>
<table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td align='left' class='textHeaderDark'>
<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='utilities.php?action=view_user_log&username=" . $_REQUEST["username"] . "&filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
</td>\n
<td align='center' class='textHeaderDark'>
Showing Rows " . ((read_config_option("num_rows_data_source")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_data_source")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
</td>\n
<td align='right' class='textHeaderDark'>
<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "<a class='linkOverDark' href='utilities.php?action=view_user_log&username=" . $_REQUEST["username"] . "&filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>
</td>\n
</tr>
</table>
</td>
</tr>\n";
print $nav;
$display_text = array(
"username" => array("Username", "ASC"),
"full_name" => array("Full Name", "ASC"),
"time" => array("Date", "ASC"),
"result" => array("Result", "DESC"),
"ip" => array("IP Address", "DESC"));
html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
$i = 0;
if (sizeof($user_log) > 0) {
foreach ($user_log as $item) {
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
?>
<td width='35%'>
<?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["username"]);?>
</td>
<td width='20%'>
<?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["full_name"]);?>
</td>
<td width='20%'>
<?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["time"]);?>
</td>
<td width='10%'>
<?php print $item["result"] == 0 ? "Failed" : "Success";?>
</td>
<td width='15%'>
<?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["ip"]);?>
</td>
</tr>
<?php
$i++;
}
}
html_end_box();
}
function utilities_clear_user_log() {
$users = db_fetch_assoc("SELECT DISTINCT username FROM user_auth");
if (sizeof($users)) {
/* remove active users */
foreach ($users as $user) {
$total_rows = db_fetch_cell("SELECT COUNT(username) FROM user_log WHERE username = '" . $user['username'] . "'");
if ($total_rows > 1)
db_execute("DELETE FROM user_log WHERE username = '" . $user['username'] . "' ORDER BY time LIMIT " . ($total_rows - 1));
}
/* delete inactive users */
db_execute("DELETE FROM user_log WHERE username NOT IN (SELECT username FROM user_auth)");
}
}
function utilities_view_logfile() {
global $colors, $log_tail_lines, $page_refresh_interval;
$logfile = read_config_option("path_cactilog");
if ($logfile == "") {
$logfile = "./log/rrd.log";
}
/* helps determine output color */
$linecolor = True;
input_validate_input_number(get_request_var_request("tail_files"));
input_validate_input_number(get_request_var_request("message_type"));
input_validate_input_number(get_request_var_request("refresh"));
input_validate_input_number(get_request_var_request("reverse"));
/* clean up search filter */
if (isset($_REQUEST["filter"])) {
$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
}
/* if the user pushed the 'clear' button */
if (isset($_REQUEST["clear_x"])) {
kill_session_var("sess_logfile_tail_lines");
kill_session_var("sess_logfile_message_type");
kill_session_var("sess_logfile_filter");
kill_session_var("sess_logfile_refresh");
kill_session_var("sess_logfile_reverse");
unset($_REQUEST["tail_lines"]);
unset($_REQUEST["message_type"]);
unset($_REQUEST["filter"]);
unset($_REQUEST["refresh"]);
unset($_REQUEST["reverse"]);
}
load_current_session_value("tail_lines", "sess_logfile_tail_lines", read_config_option("num_rows_log"));
load_current_session_value("message_type", "sess_logfile_message_type", "-1");
load_current_session_value("filter", "sess_logfile_filter", "");
load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
load_current_session_value("reverse", "sess_logfile_reverse", 1);
$_REQUEST['page_referrer'] = 'view_logfile';
load_current_session_value('page_referrer', 'page_referrer', 'view_logfile');
$refresh["seconds"] = $_REQUEST["refresh"];
$refresh["page"] = "utilities.php?action=view_logfile";
include_once("./include/top_header.php");
html_start_box("<strong>Log File Filters</strong>", "98%", $colors["header"], "3", "center", "");
include("./include/html/inc_view_logfile_table.php");
html_end_box();
/* read logfile into an array and display */
$logcontents = tail_file($logfile, $_REQUEST["tail_lines"]);
if ($_REQUEST["reverse"] == 1) {
$logcontents = array_reverse($logcontents);
}
if ($_REQUEST["message_type"] > 0) {
$start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - Non-Matching Items Hidden]";
}else{
$start_string = "<strong>Log File</strong> [Total Lines: " . sizeof($logcontents) . " - All Items Shown]";
}
html_start_box($start_string, "98%", $colors["header"], "3", "center", "");
$i = 0;
$linecolor = false;
foreach ($logcontents as $item) {
$host_start = strpos($item, "Host[");
$ds_start = strpos($item, "DS[");
$new_item = "";
if ((!$host_start) && (!$ds_start)) {
$new_item = $item;
}else{
if ($host_start) {
$host_end = strpos($item, "]", $host_start);
$host_id = substr($item, $host_start+5, $host_end-($host_start+5));
$new_item = $new_item . substr($item, 0, $host_start + 5) . "<a href='host.php?action=edit&id=" . $host_id . "'>" . substr($item, $host_start + 5, $host_end-($host_start + 5)) . "</a>";
$item = substr($item, $host_end);
}
$ds_start = strpos($item, "DS[");
if ($ds_start) {
$ds_end = strpos($item, "]", $ds_start);
$ds_id = substr($item, $ds_start+3, $ds_end-($ds_start+3));
$new_item = $new_item . substr($item, 0, $ds_start + 3) . "<a href='data_sources.php?action=ds_edit&id=" . $ds_id . "'>" . substr($item, $ds_start + 3, $ds_end-($ds_start + 3)) . "</a>";
$item = substr($item, $ds_end);
$new_item = $new_item . $item;
}else{
$new_item = $new_item . $item;
}
}
/* determine if we are to display the line */
switch ($_REQUEST["message_type"]) {
case -1: /* all */
$display = true;
break;
case 5: /* sql calls */
if (substr_count($new_item, " SQL ")) {
$display=true;
}else{
$display=false;
}
break;
case 1: /* stats */
if (substr_count($new_item, "STATS")) {
$display=true;
}else{
$display=false;
}
break;
case 2: /* warnings */
if (substr_count($new_item, "WARN")) {
$display=true;
}else{
$display=false;
}
break;
case 3: /* errors */
if (substr_count($new_item, "ERROR")) {
$display=true;
}else{
$display=false;
}
break;
case 4: /* debug */
if (substr_count($new_item, "DEBUG")) {
$display=true;
}else{
$display=false;
}
if (substr_count($new_item, " SQL ")) {
$display=false;
}
break;
default: /* all other lines */
$display=true;
break;
}
/* get the background color */
if ((substr_count($new_item, "ERROR")) || (substr_count($new_item, "FATAL"))) {
$bgcolor = "FF3932";
}elseif (substr_count($new_item, "WARN")) {
$bgcolor = "EACC00";
}elseif (substr_count($new_item, " SQL ")) {
$bgcolor = "6DC8FE";
}elseif (substr_count($new_item, "DEBUG")) {
$bgcolor = "C4FD3D";
}elseif (substr_count($new_item, "STATS")) {
$bgcolor = "96E78A";
}else{
if ($linecolor) {
$bgcolor = "CCCCCC";
}else{
$bgcolor = "FFFFFF";
}
$linecolor = !$linecolor;
}
if ($display) {
?>
<tr bgcolor='#<?php print $bgcolor;?>'>
<td>
<?php print $new_item;?>
</td>
</tr>
<?php
}
$i++;
}
html_end_box();
include_once("./include/bottom_footer.php");
}
function utilities_clear_logfile() {
global $colors;
load_current_session_value("refresh", "sess_logfile_refresh", read_config_option("log_refresh_interval"));
$refresh["seconds"] = $_REQUEST["refresh"];
$refresh["page"] = "utilities.php?action=view_logfile";
include_once("./include/top_header.php");
$logfile = read_config_option("path_cactilog");
if ($logfile == "") {
$logfile = "./log/cacti.log";
}
html_start_box("<strong>Clear Cacti Log File</strong>", "98%", $colors["header"], "1", "center", "");
if (file_exists($logfile)) {
if (is_writable($logfile)) {
$timestamp = date("m/d/Y h:i:s A");
$log_fh = fopen($logfile, "w");
fwrite($log_fh, $timestamp . " - WEBUI: Cacti Log Cleared from Web Management Interface\n");
fclose($log_fh);
print "<tr><td>Cacti Log File Cleared</td></tr>";
}else{
print "<tr><td><font color='red'><b>Error: Unable to clear log, no write permissions.<b></font></td></tr>";
}
}else{
print "<tr><td><font color='red'><b>Error: Unable to clear log, file does not exist.</b></font></td></tr>";
}
html_end_box();
}
function utilities_view_snmp_cache() {
global $colors, $poller_actions;
define("MAX_DISPLAY_PAGES", 21);
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request("host_id"));
input_validate_input_number(get_request_var_request("snmp_query_id"));
input_validate_input_number(get_request_var_request("page"));
input_validate_input_number(get_request_var_request("poller_action"));
/* ==================================================== */
/* clean up search filter */
if (isset($_REQUEST["filter"])) {
$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
}
/* if the user pushed the 'clear' button */
if (isset($_REQUEST["clear_x"])) {
kill_session_var("sess_snmp_current_page");
kill_session_var("sess_snmp_host_id");
kill_session_var("sess_snmp_snmp_query_id");
kill_session_var("sess_snmp_filter");
unset($_REQUEST["page"]);
unset($_REQUEST["filter"]);
unset($_REQUEST["host_id"]);
unset($_REQUEST["snmp_query_id"]);
}
/* remember these search fields in session vars so we don't have to keep passing them around */
load_current_session_value("page", "sess_snmp_current_page", "1");
load_current_session_value("host_id", "sess_snmp_host_id", "-1");
load_current_session_value("snmp_query_id", "sess_snmp_snmp_query_id", "-1");
load_current_session_value("filter", "sess_snmp_filter", "");
$_REQUEST['page_referrer'] = 'view_snmp_cache';
load_current_session_value('page_referrer', 'page_referrer', 'view_snmp_cache');
html_start_box("<strong>SNMP Cache Items</strong>", "98%", $colors["header"], "3", "center", "");
include("./include/html/inc_snmp_cache_filter_table.php");
html_end_box();
$sql_where = "";
/* filter by host */
if ($_REQUEST["host_id"] == "-1") {
/* Show all items */
}elseif ($_REQUEST["host_id"] == "0") {
$sql_where .= " AND host.id=0";
}elseif (!empty($_REQUEST["host_id"])) {
$sql_where .= " AND host.id=" . $_REQUEST["host_id"];
}
/* filter by query name */
if ($_REQUEST["snmp_query_id"] == "-1") {
/* Show all items */
}elseif (!empty($_REQUEST["snmp_query_id"])) {
$sql_where .= " AND host_snmp_cache.snmp_query_id=" . $_REQUEST["snmp_query_id"];
}
/* filter by search string */
if ($_REQUEST["filter"] <> "") {
$sql_where .= " AND (host.description LIKE '%%" . $_REQUEST["filter"] . "%%'
OR snmp_query.name LIKE '%%" . $_REQUEST["filter"] . "%%'
OR host_snmp_cache.field_name LIKE '%%" . $_REQUEST["filter"] . "%%'
OR host_snmp_cache.field_value LIKE '%%" . $_REQUEST["filter"] . "%%'
OR host_snmp_cache.oid LIKE '%%" . $_REQUEST["filter"] . "%%')";
}
html_start_box("", "98%", $colors["header"], "3", "center", "");
$total_rows = db_fetch_cell("SELECT
COUNT(*)
FROM (host_snmp_cache,snmp_query,host)
WHERE host_snmp_cache.host_id=host.id
AND host_snmp_cache.snmp_query_id=snmp_query.id
$sql_where");
$snmp_cache_sql = "SELECT
host_snmp_cache.*,
host.description,
snmp_query.name
FROM (host_snmp_cache,snmp_query,host)
WHERE host_snmp_cache.host_id=host.id
AND host_snmp_cache.snmp_query_id=snmp_query.id
$sql_where
LIMIT " . (read_config_option("num_rows_data_source")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_data_source");
// print $snmp_cache_sql;
$snmp_cache = db_fetch_assoc($snmp_cache_sql);
/* generate page list */
$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "utilities.php?action=view_snmp_cache&host_id=" . $_REQUEST["host_id"] . "&filter=" . $_REQUEST["filter"]);
$nav = "<tr bgcolor='#" . $colors["header"] . "'>
<td colspan='7'>
<table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td align='left' class='textHeaderDark'>
<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='utilities.php?action=view_snmp_cache&host_id=" . $_REQUEST["host_id"] . "&filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
</td>\n
<td align='center' class='textHeaderDark'>
Showing Rows " . ((read_config_option("num_rows_data_source")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_data_source")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
</td>\n
<td align='right' class='textHeaderDark'>
<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "<a class='linkOverDark' href='utilities.php?action=view_snmp_cache&host_id=" . $_REQUEST["host_id"] . "&filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>
</td>\n
</tr>
</table>
</td>
</tr>\n";
print $nav;
html_header(array("Details"));
$i = 0;
if (sizeof($snmp_cache) > 0) {
foreach ($snmp_cache as $item) {
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
?>
<td>
Host: <?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["description"]);?>
, SNMP Query: <?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["name"]);?>
</td>
</tr>
<?php
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
?>
<td>
Index: <?php print $item["snmp_index"];?>
, Field Name: <?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["field_name"]);?>
, Field Value: <?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["field_value"]);?>
</td>
</tr>
<?php
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
?>
<td>
OID: <?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["oid"]);?>
</td>
</tr>
<?php
}
}
html_end_box();
}
function utilities_view_poller_cache() {
global $colors, $poller_actions;
define("MAX_DISPLAY_PAGES", 21);
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request("host_id"));
input_validate_input_number(get_request_var_request("page"));
input_validate_input_number(get_request_var_request("poller_action"));
/* ==================================================== */
/* clean up search filter */
if (isset($_REQUEST["filter"])) {
$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
}
/* clean up sort_column */
if (isset($_REQUEST["sort_column"])) {
$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
}
/* clean up sort direction */
if (isset($_REQUEST["sort_direction"])) {
$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
}
/* if the user pushed the 'clear' button */
if (isset($_REQUEST["clear_x"])) {
kill_session_var("sess_poller_current_page");
kill_session_var("sess_poller_host_id");
kill_session_var("sess_poller_poller_action");
kill_session_var("sess_poller_filter");
unset($_REQUEST["page"]);
unset($_REQUEST["filter"]);
unset($_REQUEST["host_id"]);
unset($_REQUEST["poller_action"]);
}
if ((!empty($_SESSION["sess_poller_action"])) && (!empty($_REQUEST["poller_action"]))) {
if ($_SESSION["sess_poller_poller_action"] != $_REQUEST["poller_action"]) {
$_REQUEST["page"] = 1;
}
}
/* remember these search fields in session vars so we don't have to keep passing them around */
load_current_session_value("page", "sess_poller_current_page", "1");
load_current_session_value("host_id", "sess_poller_host_id", "-1");
load_current_session_value("poller_action", "sess_poller_poller_action", "-1");
load_current_session_value("filter", "sess_poller_filter", "");
load_current_session_value("sort_column", "sess_poller_sort_column", "data_template_data.name_cache");
load_current_session_value("sort_direction", "sess_poller_sort_direction", "ASC");
$_REQUEST['page_referrer'] = 'view_poller_cache';
load_current_session_value('page_referrer', 'page_referrer', 'view_poller_cache');
html_start_box("<strong>Poller Cache Items</strong>", "98%", $colors["header"], "3", "center", "");
include("./include/html/inc_poller_item_filter_table.php");
html_end_box();
/* form the 'where' clause for our main sql query */
$sql_where = "WHERE poller_item.local_data_id=data_template_data.local_data_id";
if ($_REQUEST["poller_action"] == "-1") {
/* Show all items */
}else {
$sql_where .= " AND poller_item.action='" . $_REQUEST["poller_action"] . "'";
}
if ($_REQUEST["host_id"] == "-1") {
/* Show all items */
}elseif ($_REQUEST["host_id"] == "0") {
$sql_where .= " AND poller_item.host_id=0";
}elseif (!empty($_REQUEST["host_id"])) {
$sql_where .= " AND poller_item.host_id=" . $_REQUEST["host_id"];
}
if (strlen($_REQUEST["filter"])) {
$sql_where .= " AND (data_template_data.name_cache LIKE '%%" . $_REQUEST["filter"] . "%%'
OR host.description LIKE '%%" . $_REQUEST["filter"] . "%%'
OR poller_item.arg1 LIKE '%%" . $_REQUEST["filter"] . "%%'
OR poller_item.hostname LIKE '%%" . $_REQUEST["filter"] . "%%'
OR poller_item.rrd_path LIKE '%%" . $_REQUEST["filter"] . "%%')";
}
html_start_box("", "98%", $colors["header"], "3", "center", "");
$total_rows = db_fetch_cell("SELECT
COUNT(*)
FROM data_template_data
INNER JOIN (poller_item
INNER JOIN host
ON poller_item.host_id = host.id)
ON data_template_data.local_data_id = poller_item.local_data_id
$sql_where");
$poller_sql = "SELECT
poller_item.*,
data_template_data.name_cache,
host.description
FROM data_template_data
INNER JOIN (poller_item
INNER JOIN host
ON poller_item.host_id = host.id)
ON data_template_data.local_data_id = poller_item.local_data_id
$sql_where
ORDER BY " . $_REQUEST["sort_column"] . " " . $_REQUEST["sort_direction"] . ", action ASC
LIMIT " . (read_config_option("num_rows_data_source")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_data_source");
// print $poller_sql;
$poller_cache = db_fetch_assoc($poller_sql);
/* generate page list */
$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "utilities.php?action=view_poller_cache&host_id=" . $_REQUEST["host_id"] . "&poller_action=" . $_REQUEST["poller_action"]);
$nav = "<tr bgcolor='#" . $colors["header"] . "'>
<td colspan='7'>
<table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td align='left' class='textHeaderDark'>
<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='utilities.php?action=view_poller_cache&host_id=" . $_REQUEST["host_id"] . "&poller_action=" . $_REQUEST["poller_action"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
</td>\n
<td align='center' class='textHeaderDark'>
Showing Rows " . ((read_config_option("num_rows_data_source")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_data_source")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
</td>\n
<td align='right' class='textHeaderDark'>
<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "<a class='linkOverDark' href='utilities.php?action=view_poller_cache&host_id=" . $_REQUEST["host_id"] . "&poller_action=" . $_REQUEST["poller_action"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>
</td>\n
</tr>
</table>
</td>
</tr>\n";
print $nav;
$display_text = array(
"data_template_data.name_cache" => array("Data Source Name", "ASC"),
"" => array("Details", "ASC"));
html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
$i = 0;
if (sizeof($poller_cache) > 0) {
foreach ($poller_cache as $item) {
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
?>
<td width="375">
<a class="linkEditMain" href="data_sources.php?action=ds_edit&id=<?php print $item["local_data_id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["name_cache"]);?></a>
</td>
<td>
<?php
if ($item["action"] == 0) {
if ($item["snmp_version"] != 3) {
$details =
"SNMP Version: " . $item["snmp_version"] . ", " .
"Community: " . $item["snmp_community"] . ", " .
"OID: " . eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]);
}else{
$details =
"SNMP Version: " . $item["snmp_version"] . ", " .
"User: " . $item["snmp_username"] . ", OID: " . $item["arg1"];
}
}elseif ($item["action"] == 1) {
$details = "Script: " . eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]);
}else{
$details = "Script Server: " . eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]);
}
print $details;
?>
</td>
</tr>
<?php
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
?>
<td>
</td>
<td>
RRD: <?php print $item["rrd_path"];?>
</td>
</tr>
<?php
$i++;
}
}
html_end_box();
}
function utilities() {
global $colors;
html_start_box("<strong>Cacti System Utilities</strong>", "98%", $colors["header"], "3", "center", "");
?>
<colgroup span="3">
<col valign="top" width="20"></col>
<col valign="top" width="10"></col>
</colgroup>
<?php html_header(array("System Log Administration"), 2);?>
<tr bgcolor="#<?php print $colors["form_alternate1"];?>">
<td class="textArea">
<p><a href='utilities.php?action=view_logfile'>View Cacti Log File</a></p>
</td>
<td class="textArea">
<p>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.</p>
</td>
</tr>
<?php html_header(array("User Log Administration"), 2);?>
<tr bgcolor="#<?php print $colors["form_alternate1"];?>">
<td class="textArea">
<p><a href='utilities.php?action=view_user_log'>View User Log</a></p>
</td>
<td class="textArea">
<p>Allows Administrators to browse the user log. Administrators can filter and export the log as well.</p>
</td>
</tr>
<?php html_header(array("Poller Cache Administration"), 2); ?>
<tr bgcolor="#<?php print $colors["form_alternate1"];?>">
<td class="textArea">
<p><a href='utilities.php?action=view_poller_cache'>View Poller Cache</a></p>
</td>
<td class="textArea">
<p>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.</p>
</td>
</tr>
<tr bgcolor="#<?php print $colors["form_alternate2"];?>">
<td class="textArea">
<p><a href='utilities.php?action=view_snmp_cache'>View SNMP Cache</a></p>
</td>
<td class="textArea">
<p>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.</p>
</td>
</tr>
<tr bgcolor="#<?php print $colors["form_alternate1"];?>">
<td class="textArea">
<p><a href='utilities.php?action=clear_poller_cache'>Rebuild Poller Cache</a></p>
</td>
<td class="textArea">
<p>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.</p>
</td>
</tr>
<?php
html_end_box();
}
?>
|