diff --git a/config.php.default b/config.php.default index 66215a186..f85aa1fdb 100755 --- a/config.php.default +++ b/config.php.default @@ -10,11 +10,9 @@ $config['db_name'] = "observer"; $config['install_dir'] = "/opt/observer/"; $config['html_dir'] = $config['install_dir'] . "html"; $config['rrd_dir'] = $config['install_dir'] . "rrd"; -$rrd_dir = $config['rrd_dir']; ### Default community $config['community'] = "observer"; -$community = $config['community']; $config['base_url'] = "http://observer"; @@ -39,16 +37,15 @@ $config['rrdgraph_defaults'] = array("-c", "BACK#FFFFFF", "-c", "SHADEA#E5E5E5", $config['overlib_defaults'] = ",FGCOLOR,'#e5e5e5', BGCOLOR, '#e5e5e5'"; -### List of networks to allow scanning-based discovery. +## List of networks to allow scanning-based discovery. $config['nets'] = array ("10.0.0.0/8", "172.22.0.0/16"); -### Your company domain name and specifics +## Your company domain name and specifics $config['mydomain'] = "observernms.net"; $config['page_title'] = "Project Observer"; $config['title_image'] = "images/observer-logo.jpg"; $config['stylesheet'] = "css/styles.css"; $config['mono_font'] = $config['install_dir'] . "/fonts/DejaVuSansMono.ttf"; -$mono_font = $config['mono_font']; $config['favicon'] = "favicon.ico"; $config['header_color'] = "#1F334E"; @@ -78,6 +75,8 @@ $config['enable_inventory'] = 1; # Enable Inventory ## Uncomment this to enable display of rancid-collected configs #$config['rancid_configs'] = '/var/lib/rancid/network/configs/'; +$config['cdp_autocreate'] = false; # Should we autocreate hosts we see via CDP? +$config['snmp_autodiscovery'] = false; ## If a syslog entry contails these strings it is deleted from the database $config['syslog_filter'] = array("last message repeated", "Connection from UDP: [127.0.0.1]:"); diff --git a/discover-cdp.php b/discover-cdp.php index fc86c4802..0a6f48d17 100755 --- a/discover-cdp.php +++ b/discover-cdp.php @@ -34,7 +34,7 @@ while ($device = mysql_fetch_array($device_query)) { $cdp_links = trim($cdp_links); - echo("\n$cdp_links\n\n"); +# echo("\n$cdp_links\n\n"); foreach ( explode("\n" ,$cdp_links) as $link ) { if ($link == "") { break; } @@ -49,8 +49,10 @@ while ($device = mysql_fetch_array($device_query)) { $ip = gethostbyname($dst_host); if ( match_network($config['nets'], $ip) ) { if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `sysName` = '$dst_host'"), 0) == '0' ) { - echo("++ Creating: $dst_host \n"); - #createHost ($dst_host, $community, "v2c"); + if($config['cdp_autocreate']) { + echo("++ Creating: $dst_host \n"); + createHost ($dst_host, $community, "v2c"); + } } else { echo(".. Already got host $dst_host\n"); } @@ -96,9 +98,9 @@ while($entry = mysql_fetch_array($query)) { } if (!$alive) { mysql_query("DELETE FROM `links` WHERE `src_if` = '$entry[src_if]' AND `dst_if` = '$entry[dst_if]'"); - echo("$src_if_id -> $dst_if_id REMOVED \n"); +# echo("$src_if_id -> $dst_if_id REMOVED \n"); } else { - echo("$src_if_id -> $dst_if_id VALID \n"); +# echo("$src_if_id -> $dst_if_id VALID \n"); } } diff --git a/html/includes/print-interface.inc b/html/includes/print-interface.inc index ca238ff25..b26726340 100644 --- a/html/includes/print-interface.inc +++ b/html/includes/print-interface.inc @@ -208,7 +208,7 @@ echo(""); echo(""); // If we're showing graphs, generate the graph and print the img tags - if($dographs && is_file($rrd_dir . "/" . $hostname . "/". $ifIndex . ".rrd")) { + if($dographs && is_file($config['rrd_dir'] . "/" . $hostname . "/". $ifIndex . ".rrd")) { $type = $_GET['type']; diff --git a/html/pages/adduser.php b/html/pages/adduser.php index 76579e409..e3fbccfdd 100644 --- a/html/pages/adduser.php +++ b/html/pages/adduser.php @@ -7,22 +7,31 @@ if($_SESSION['userlevel'] != '10') { echo("You do not have the echo("

Add User

"); if($_POST['action'] == "add") { - - mysql_query("INSERT INTO `users` (`username`, `realname`, `password`, `level`) VALUES ('" . mres($_POST['new_username']) . "', '" . mres($_POST['new_realname']) . "', MD5('" . mres($_POST['new_password']) . "'), '" . mres($_POST['new_level']) . "')"); - - if(mysql_affected_rows()) { echo("User " . $_GET['username'] . " added!"); } - + if($_POST['new_username'] && $_POST['new_password'] && !mysql_result(mysql_query("SELECT * FROM users WHERE username = '".$_POST['new_username']."'"),0) ) { + mysql_query("INSERT INTO `users` (`username`, `realname`, `password`, `level`) VALUES ('" . mres($_POST['new_username']) . "', '" . mres($_POST['new_realname']) . "', MD5('" . mres($_POST['new_password']) . "'), '" . mres($_POST['new_level']) . "')"); + if(mysql_affected_rows()) { echo("User " . $_POST['username'] . " added!"); } + } } echo("
"); - echo("Username
"); - echo("Password
"); - - echo("Realname

"); - - echo("
"); + if($_POST['action'] == "add" && !$_POST['new_username']) { + echo("
Please enter a username!
"); + } elseif( mysql_result(mysql_query("SELECT * FROM users WHERE username = '".$_POST['new_username']."'"),0)) { + echo("User with this name already exists!
"); + } + ?> + Password
+ Please enter a password!
"); + } + echo("Realname
"); + ?> + diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index 019790973..5f7c65608 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -1,10 +1,21 @@ = "5" && is_file($config['rancid_configs'] . $device['hostname'])) { $file = $config['rancid_configs'] . $device['hostname']; + # $file = "/testconfig.txt"; $fh = fopen($file, 'r') or die("Can't open file"); $text = fread($fh, filesize($file)); - echo(highlight_string($text)); + $language = "ios"; + $geshi = new GeSHi($text, $language); + $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); + $geshi->set_overall_style('color: black;'); +# $geshi->set_line_style('color: #999999'); + +# echo("
"); + echo $geshi->parse_code(); +# echo("
"); fclose($fh); } else { print_error("Error : Insufficient access."); diff --git a/html/pages/iftype.php b/html/pages/iftype.php index 542f8d1c6..3db137b54 100644 --- a/html/pages/iftype.php +++ b/html/pages/iftype.php @@ -24,7 +24,7 @@ if($_GET['type']) { echo(""); -if(file_exists($rrd_dir . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd")) { +if(file_exists($config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd")) { $graph_type = "bits"; include("includes/print-interface-graphs.php"); diff --git a/includes/functions.php b/includes/functions.php index 29ab3b0c8..d67dadcf8 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -216,8 +216,8 @@ function truncate($substring, $max = 50, $rep = '...') function interface_rates ($interface) { - global $config, $rrd_dir; - $rrdfile = $rrd_dir . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd"; + global $config; + $rrdfile = $config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd"; $cmd = $config['rrdtool']." fetch -s -600s -e now ".$rrdfile." AVERAGE | grep : | cut -d\" \" -f 2,3 | grep e"; $data = trim(`$cmd`); foreach( explode("\n", $data) as $entry) { @@ -231,8 +231,8 @@ function interface_rates ($interface) function interface_errors ($interface) { - global $config, $rrd_dir; - $rrdfile = $rrd_dir . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd"; + global $config; + $rrdfile = $config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd"; $cmd = $config['rrdtool']." fetch -s -1d -e -300s $rrdfile AVERAGE | grep : | cut -d\" \" -f 4,5"; $data = trim(`$cmd`); foreach( explode("\n", $data) as $entry) { @@ -356,9 +356,8 @@ function delHost($id) mysql_query("DELETE FROM `interfaces` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `services` WHERE `service_host` = '$id'"); mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); - $rrd_dir = $config['rrd_dir']; - `rm -f $rrd_dir/$host-*.rrd`; - `rm -rf $rrd_dir/$host`; + shell_exec("rm -f ".$config['rrd_dir'] . "/$host-*.rrd"); + shell_exec("rm -rf ".$config['rrd_dir']."/$host"); echo("Removed device $host
"); } diff --git a/includes/polling/bgpPeer.inc.php b/includes/polling/bgpPeer.inc.php index 6d0777eb6..15ebdc4e5 100755 --- a/includes/polling/bgpPeer.inc.php +++ b/includes/polling/bgpPeer.inc.php @@ -20,7 +20,7 @@ while($peer = mysql_fetch_array($peers)) { list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); - $peerrrd = $rrd_dir . "/" . $device['hostname'] . "/bgp-" . $peer['bgpPeerIdentifier'] . ".rrd"; + $peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/bgp-" . $peer['bgpPeerIdentifier'] . ".rrd"; if(!is_file($peerrrd)) { $woo = `rrdtool create $peerrrd \ diff --git a/includes/polling/device-fortigate.inc.php b/includes/polling/device-fortigate.inc.php index 0646b2b20..aa63c765f 100755 --- a/includes/polling/device-fortigate.inc.php +++ b/includes/polling/device-fortigate.inc.php @@ -8,9 +8,9 @@ $serial = shell_exec($config['snmpget']." -".$device['snmpver']." -Ovq -c $version = preg_replace("/(.+)\ (.+),(.+),(.+)/", "Fortinet \\1||\\2||\\3||\\4", $fnSysVersion); list($hardware,$version,$features) = explode("||", $version); -$cpurrd = $rrd_dir . "/" . $device['hostname'] . "/fortigate-cpu.rrd"; -$memrrd = $rrd_dir . "/" . $device['hostname'] . "/fortigate-memory.rrd"; -$sessrrd = $rrd_dir . "/" . $device['hostname'] . "/fortigate-sessions.rrd"; +$cpurrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/fortigate-cpu.rrd"; +$memrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/fortigate-memory.rrd"; +$sessrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/fortigate-sessions.rrd"; $cmd = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; $cmd .= " fnSysCpuUsage.0 fnSysMemUsage.0 fnSysSesCount.0 fnSysMemCapacity.0"; diff --git a/includes/polling/device-ios.inc.php b/includes/polling/device-ios.inc.php index 87761603a..bbcbca15b 100755 --- a/includes/polling/device-ios.inc.php +++ b/includes/polling/device-ios.inc.php @@ -5,17 +5,9 @@ $hostname = $device['hostname']; $port = $device['port']; - $Otemprrd = "rrd/" . $hostname . "-temp.rrd"; - $Ocpurrd = "rrd/" . $hostname . "-cpu.rrd"; - $Omemrrd = "rrd/" . $hostname . "-mem.rrd"; - - $temprrd = $rrd_dir . "/" . $hostname . "/temp.rrd"; - $cpurrd = $rrd_dir . "/" . $hostname . "/cpu.rrd"; - $memrrd = $rrd_dir . "/" . $hostname . "/mem.rrd"; - - if(is_file($Otemprrd) && !is_file($temprrd)) { rename($Otemprrd, $temprrd); echo("Moving $Otemprrd to $temprrd"); } - if(is_file($Ocpurrd) && !is_file($cpurrd)) { rename($Ocpurrd, $cpurrd); echo("Moving $Ocpurrd to $cpurrd"); } - if(is_file($Omemrrd) && !is_file($memrrd)) { rename($Omemrrd, $memrrd); echo("Moving $Omemrrd to $memrrd"); } + $temprrd = $config['rrd_dir'] . "/" . $hostname . "/temp.rrd"; + $cpurrd = $config['rrd_dir'] . "/" . $hostname . "/cpu.rrd"; + $memrrd = $config['rrd_dir'] . "/" . $hostname . "/mem.rrd"; $version = str_replace("Cisco IOS Software,", "", $sysDescr); $version = str_replace("IOS (tm) ", "", $version); diff --git a/includes/polling/device-junos.inc.php b/includes/polling/device-junos.inc.php index b23200cde..e0621103a 100644 --- a/includes/polling/device-junos.inc.php +++ b/includes/polling/device-junos.inc.php @@ -11,7 +11,7 @@ $features = preg_replace("/.+\ \((.+)\)$/", "\\1", $jun_ver); echo("$hardware - $version - $features - $serial\n"); -$cpurrd = $rrd_dir . "/" . $device['hostname'] . "/junos-cpu.rrd"; +$cpurrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/junos-cpu.rrd"; $cpu_cmd = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname']; $cpu_cmd .= " .1.3.6.1.4.1.2636.3.1.13.1.8.9.1.0.0"; diff --git a/includes/polling/device-netstats.inc.php b/includes/polling/device-netstats.inc.php index 95d416653..a60d8ba19 100755 --- a/includes/polling/device-netstats.inc.php +++ b/includes/polling/device-netstats.inc.php @@ -12,10 +12,7 @@ if($device[os] != "Snom") { 'tcpEstabResets','tcpInSegs','tcpOutSegs','tcpRetransSegs','udpInDatagrams','udpOutDatagrams','udpInErrors', 'udpNoPorts'); - $rrdfile = $rrd_dir . "/" . $device['hostname'] . "/netinfo.rrd"; - - $Orrdfile = "rrd/" . $device['hostname'] . "-netinfo.rrd"; - if(is_file($Orrdfile) && !is_file($rrdfile)) { rename($Orrdfile, $rrdfile); echo("Moving $Orrdfile to $rrdfile"); } + $rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/netinfo.rrd"; $rrd_create = "rrdtool create $rrdfile "; $rrd_create .= "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ diff --git a/includes/polling/device-procurve.inc.php b/includes/polling/device-procurve.inc.php index 16623f5c4..effc3b462 100755 --- a/includes/polling/device-procurve.inc.php +++ b/includes/polling/device-procurve.inc.php @@ -1,14 +1,7 @@