From bdc4deb4355c5a81f7bbd6fe2e35e02fe72978f8 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 1 Jun 2015 23:27:41 +0100 Subject: [PATCH 01/20] Updated to use mac address data --- html/includes/print-map.inc.php | 66 ++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index c8fcf1249b..6902db4b19 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -36,13 +36,66 @@ foreach (dbFetchRows("SELECT DISTINCT least(`devices`.`device_id`, `remote_devic array_push($tmp_ids,$link_devices['remote_device_id']); } -$tmp_ids = implode(',',$tmp_ids); - -$nodes = json_encode($tmp_devices); +$tmp_exp_ids = implode(',',$tmp_ids); + +$port_ids = array(); +foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL", array()) as $macs) { + if (!in_array($macs['local_port_id'], $port_ids) && port_permitted($macs['local_port_id'])) { + $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($macs['local_port_id'])); + $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['local_port_id'])); + if (!in_array($port_dev['device_id'],$tmp_ids)) { + $mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box'); + array_push($port_ids, $port_dev['device_id']); + $port_data = $port_det; + $from = $port_dev['device_id']; + $port = shorten_interface_type($port_det['ifName']); + $speed = $port_det['ifSpeed']/1000/1000; + if ($speed == 100) { + $width = 3; + } elseif ($speed == 1000) { + $width = 5; + } elseif ($speed == 10000) { + $width = 10; + } elseif ($speed == 40000) { + $width = 15; + } elseif ($speed == 100000) { + $width = 20; + } else { + $width = 1; + } + $link_in_used = ($port_det['ifInOctets_rate'] * 8) / $port_det['ifSpeed'] * 100; + $link_out_used = ($port_det['ifOutOctets_rate'] * 8) / $port_det['ifSpeed'] * 100; + if ($link_in_used > $link_out_used) { + $link_used = $link_in_used; + } else { + $link_used = $link_out_used; + } + $link_used = round($link_used, -1); + if ($link_used > 100) { + $link_used = 100; + } + $link_color = $config['map_legend'][$link_used]; + } + } + if (!in_array($macs['remote_port_id'], $port_ids) && port_permitted($macs['remote_port_id'])) { + $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($macs['remote_port_id'])); + $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['remote_port_id'])); + if (!in_array($port_dev['device_id'],$tmp_ids)) { + $mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box'); + array_push($port_ids, $port_dev['device_id']); + $to = $port_dev['device_id']; + $port .= ' > ' . shorten_interface_type($port_det['ifName']); + } + } + $tmp_links[] = array('from'=>$from,'to'=>$to,'label'=>$port,'title'=>generate_port_link($port_data, "",'',0,1),'width'=>$width,'color'=>$link_color); +} + +$node_devices = array_merge($tmp_devices,$mac_devices); +$nodes = json_encode($node_devices); if (is_array($tmp_devices[0])) { $tmp_links = array(); - foreach (dbFetchRows("SELECT local_device_id, remote_device_id, `remote_hostname`,`ports`.*, `remote_port` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` WHERE (`local_device_id` IN ($tmp_ids) AND `remote_device_id` IN ($tmp_ids))") as $link_devices) { + foreach (dbFetchRows("SELECT local_device_id, remote_device_id, `remote_hostname`,`ports`.*, `remote_port` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` WHERE (`local_device_id` IN ($tmp_exp_ids) AND `remote_device_id` IN ($tmp_exp_ids))") as $link_devices) { foreach ($tmp_devices as $k=>$v) { if ($v['id'] == $link_devices['local_device_id']) { $from = $v['id']; @@ -85,6 +138,8 @@ if (is_array($tmp_devices[0])) { } $edges = json_encode($tmp_links); +} + ?> @@ -147,7 +202,6 @@ network.redraw(); From 988cb3b2407ed533d8f30f890aafb256e6da1994 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Tue, 2 Jun 2015 00:03:06 +0100 Subject: [PATCH 02/20] Last update to get map working for mac addresses --- html/includes/print-map.inc.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index 6902db4b19..fb1d16f700 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -16,6 +16,8 @@ $tmp_devices = array(); if (!empty($device['hostname'])) { $sql = ' WHERE `devices`.`hostname`=?'; $sql_array = array($device['hostname']); + $mac_sql = ' AND `D`.`hostname` = ?'; + $mac_array = array($device['hostname']); } else { $sql = ' WHERE 1'; } @@ -39,13 +41,15 @@ foreach (dbFetchRows("SELECT DISTINCT least(`devices`.`device_id`, `remote_devic $tmp_exp_ids = implode(',',$tmp_ids); $port_ids = array(); -foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL", array()) as $macs) { +$port_devices = array(); +foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` LEFT JOIN `devices` AS `D` ON `P`.`device_id`=`D`.`device_id` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL $mac_sql", $mac_array) as $macs) { if (!in_array($macs['local_port_id'], $port_ids) && port_permitted($macs['local_port_id'])) { - $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($macs['local_port_id'])); $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['local_port_id'])); - if (!in_array($port_dev['device_id'],$tmp_ids)) { + $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($port_det['device_id'])); + if (!in_array($port_dev['device_id'],$tmp_ids) && !in_array($port_dev['device_id'],$port_devices)) { $mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box'); - array_push($port_ids, $port_dev['device_id']); + array_push($port_ids, $port_det['port_id']); + array_push($port_devices, $port_dev['device_id']); $port_data = $port_det; $from = $port_dev['device_id']; $port = shorten_interface_type($port_det['ifName']); @@ -78,11 +82,12 @@ foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `re } } if (!in_array($macs['remote_port_id'], $port_ids) && port_permitted($macs['remote_port_id'])) { - $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($macs['remote_port_id'])); $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['remote_port_id'])); - if (!in_array($port_dev['device_id'],$tmp_ids)) { + $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($port_det['device_id'])); + if (!in_array($port_dev['device_id'],$tmp_ids) && !in_array($port_dev['device_id'],$port_devices)) { $mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box'); - array_push($port_ids, $port_dev['device_id']); + array_push($port_ids, $port_det['port_id']); + array_push($port_devices, $port_dev['device_id']); $to = $port_dev['device_id']; $port .= ' > ' . shorten_interface_type($port_det['ifName']); } @@ -94,7 +99,6 @@ $node_devices = array_merge($tmp_devices,$mac_devices); $nodes = json_encode($node_devices); if (is_array($tmp_devices[0])) { - $tmp_links = array(); foreach (dbFetchRows("SELECT local_device_id, remote_device_id, `remote_hostname`,`ports`.*, `remote_port` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` WHERE (`local_device_id` IN ($tmp_exp_ids) AND `remote_device_id` IN ($tmp_exp_ids))") as $link_devices) { foreach ($tmp_devices as $k=>$v) { if ($v['id'] == $link_devices['local_device_id']) { @@ -136,10 +140,9 @@ if (is_array($tmp_devices[0])) { $tmp_links[] = array('from'=>$from,'to'=>$to,'label'=>$port,'title'=>generate_port_link($port_data, "",'',0,1),'width'=>$width,'color'=>$link_color); } - - $edges = json_encode($tmp_links); } +$edges = json_encode($tmp_links); ?> From f0395e453eb4cfcabc431a9a4005d2e47a0cb9cc Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 2 Jun 2015 00:37:34 +0100 Subject: [PATCH 03/20] Final final updates to get better map support --- html/includes/print-map.inc.php | 10 +++++++++- html/includes/print-menubar.php | 8 -------- html/pages/device.inc.php | 4 ---- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index fb1d16f700..bfadc788d2 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -42,7 +42,7 @@ $tmp_exp_ids = implode(',',$tmp_ids); $port_ids = array(); $port_devices = array(); -foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` LEFT JOIN `devices` AS `D` ON `P`.`device_id`=`D`.`device_id` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL $mac_sql", $mac_array) as $macs) { +foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` LEFT JOIN `devices` AS `D` ON `P`.`device_id`=`D`.`device_id` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL AND `M`.`port_id` != 0 AND `P`.`port_id` != 0 $mac_sql", $mac_array) as $macs) { if (!in_array($macs['local_port_id'], $port_ids) && port_permitted($macs['local_port_id'])) { $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['local_port_id'])); $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($port_det['device_id'])); @@ -143,6 +143,8 @@ if (is_array($tmp_devices[0])) { } $edges = json_encode($tmp_links); + +if (count($node_devices) > 1 && count($tmp_links) > 0) { ?> @@ -205,6 +207,12 @@ network.redraw(); diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index ca30ad6c32..ab43b2a9eb 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -147,17 +147,9 @@ if ($config['show_locations'])
  • Delete Device
  • '); } -if ($links['count'] > 0) { - ?>
  • Network Map Network Map
  • - - diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index c72daf9bfe..245c29dd3a 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -256,15 +256,11 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) '); } - if ($_SESSION['userlevel'] >= "5" && dbFetchCell("SELECT COUNT(*) FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.port_id = L.local_port_id")) - { - $discovery_links = TRUE; echo('
  • Map
  • '); - } if (@dbFetchCell("SELECT COUNT(*) FROM `packages` WHERE device_id = '".$device['device_id']."'") > '0') { From 841cb803b3fc8f9e244e46973e9c142ff8f47e50 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 2 Jun 2015 00:50:09 +0100 Subject: [PATCH 04/20] Some tidying up of variables/array --- html/includes/print-map.inc.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index bfadc788d2..1e4311351c 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -42,6 +42,7 @@ $tmp_exp_ids = implode(',',$tmp_ids); $port_ids = array(); $port_devices = array(); +$tmp_links = array(); foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` LEFT JOIN `devices` AS `D` ON `P`.`device_id`=`D`.`device_id` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL AND `M`.`port_id` != 0 AND `P`.`port_id` != 0 $mac_sql", $mac_array) as $macs) { if (!in_array($macs['local_port_id'], $port_ids) && port_permitted($macs['local_port_id'])) { $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['local_port_id'])); @@ -93,6 +94,7 @@ foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `re } } $tmp_links[] = array('from'=>$from,'to'=>$to,'label'=>$port,'title'=>generate_port_link($port_data, "",'',0,1),'width'=>$width,'color'=>$link_color); + unset($port); } $node_devices = array_merge($tmp_devices,$mac_devices); From 116a64deb95d6a71c322f4fa1d5da6395165a728 Mon Sep 17 00:00:00 2001 From: laf Date: Sat, 27 Jun 2015 22:52:01 +0100 Subject: [PATCH 05/20] Added basic detection for Mellanox devices --- html/images/os/mellanox.png | Bin 0 -> 1323 bytes includes/definitions.inc.php | 10 ++++++++++ includes/discovery/os/mellanox.inc.php | 7 +++++++ includes/polling/os/mellanox.inc.php | 8 ++++++++ 4 files changed, 25 insertions(+) create mode 100644 html/images/os/mellanox.png create mode 100644 includes/discovery/os/mellanox.inc.php create mode 100644 includes/polling/os/mellanox.inc.php diff --git a/html/images/os/mellanox.png b/html/images/os/mellanox.png new file mode 100644 index 0000000000000000000000000000000000000000..a1b9b4b0eb2c6da64d5f4a738eee97ac947863c3 GIT binary patch literal 1323 zcmc(e|2xwO0LMS14xLbXqA2B(WY1N0aea|x3U!XnMCHtvk(2K`C2BKLhI=;G^+g>C z8z)+&xoxT0WH$LWh7t2^n^|m{jhS)ouekT~yx*_q{qy^I=Lh(oGc(<33IKqauMZTq zPW%6CykR||mH5_m*r2^b(D0-f^!12T6aa}%ibUD_CPc)dV5o@bj1(^FBmfv-11S0u zCsVGe$y{P9=UVW;qcF6c z(bOxEDsXv}uI@3FYDuHflB!!*SM>^oy7W0qEK#(!a&$U9Hn)CqYF0ERzn)nmomTet zO-{?^Kd}0hN(EpWz0EP`BXsuRDa5&<%Y4x2!BZ9NfO|aG@ z*|zzjXT!J7&#KEd^R^NW5KdhkzjauU`m<-zZd_RT3pkEsx?pl&nKfqf&j$NW_Io3j z6zg6;jNHIuQ|OGzm@0snP0qnmJS{9?X$>Yw*Kq2o>}0#bYwUjCy6IHOscXfIrixxr zCTxpPzuWz-qe*8+yfH>48v$dKEk+-LS)8^+krOok41IlAAnJYm~21#_1?nh(n=R3!@WoE_2 z_6Q*Xi?Ph8(Od#fd{2m{THg)10W*KH%V`(9Bzii?w!&y_rF&B>-m=+&=qGg@rk*Z= zdT~fD#(Q}cNc%u-6f2N02A+YMIwpIl@^M>SeBAcEnu)L{xA}$@A_}P0lAVU|qPk%V zq`hmcLBb9J=w-&^$e@Gb2{6gy<#PM({~t Date: Mon, 29 Jun 2015 16:28:58 +0100 Subject: [PATCH 06/20] Updated NX-OS to avoid conflicts elsewhere --- includes/discovery/os/nxos.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/discovery/os/nxos.inc.php b/includes/discovery/os/nxos.inc.php index 989021c932..5e374396a7 100644 --- a/includes/discovery/os/nxos.inc.php +++ b/includes/discovery/os/nxos.inc.php @@ -2,7 +2,7 @@ if (!$os) { - if (strstr($sysDescr, "NX-OS")) { $os = "nxos"; } + if (strstr($sysDescr, "NX-OS(tm)")) { $os = "nxos"; } } -?> \ No newline at end of file +?> From e8d830498ca21e9782826394d6fbdd51d518e5b0 Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 12 Jul 2015 19:12:04 +0100 Subject: [PATCH 07/20] Updated Mellanox detection to use sysObjectID --- includes/discovery/os/mellanox.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/os/mellanox.inc.php b/includes/discovery/os/mellanox.inc.php index 7400f910be..1b2516e68a 100644 --- a/includes/discovery/os/mellanox.inc.php +++ b/includes/discovery/os/mellanox.inc.php @@ -1,7 +1,7 @@ Date: Mon, 13 Jul 2015 21:45:40 +0100 Subject: [PATCH 08/20] Default to only two days performance data but data picker available --- html/pages/device/performance.inc.php | 39 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/html/pages/device/performance.inc.php b/html/pages/device/performance.inc.php index 1c642daf49..8686bf8034 100644 --- a/html/pages/device/performance.inc.php +++ b/html/pages/device/performance.inc.php @@ -23,12 +23,43 @@ if(!isset($vars['section'])) { $vars['section'] = "performance"; } +if (empty($vars['dtpickerfrom'])) { + $vars['dtpickerfrom'] = date($config['dateformat']['byminute'], time() - 3600 * 24 * 2); +} +if (empty($vars['dtpickerto'])) { + $vars['dtpickerto'] = date($config['dateformat']['byminute']); +} + +?> + +
    +
    +
    + + +
    +
    + + +
    + +
    +
    + + + += ? AND `timestamp` <= ?"; + $param = array($device['device_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); } else { - $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf`,`devices_perms` WHERE `device_id` = ? AND alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id']; - $param = array($device['device_id']); + $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf`,`devices_perms` WHERE `device_id` = ? AND alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = ? AND `timestamp` >= ? AND `timestamp` <= ?"; + $param = array($device['device_id'], $_SESSION['user_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); } ?> From bec3c5ffde14073ebde39afa4160a23e29516673 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 13 Jul 2015 23:04:10 +0100 Subject: [PATCH 09/20] broader mellanox detection --- includes/discovery/os/mellanox.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/os/mellanox.inc.php b/includes/discovery/os/mellanox.inc.php index 1b2516e68a..7453ead3cd 100644 --- a/includes/discovery/os/mellanox.inc.php +++ b/includes/discovery/os/mellanox.inc.php @@ -1,7 +1,7 @@ Date: Tue, 14 Jul 2015 12:13:17 +0100 Subject: [PATCH 10/20] Added restriction for device_id --- html/includes/print-map.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index a973f27e7d..c9fc541d1c 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -61,7 +61,7 @@ foreach (dbFetchRows("SELECT LEFT JOIN `ports` AS `P2` ON `P2`.`port_id`=`links`.`remote_port_id` WHERE `active`=1 - AND `remote_device_id`!=0 + $sql ",$sql_array) as $items) { $local_device = array('device_id'=>$items['local_device_id'], 'os'=>$items['local_os'], 'hostname'=>$items['local_hostname']); $remote_device = array('device_id'=>$items['remote_device_id'], 'os'=>$items['remote_os'], 'hostname'=>$items['remote_hostname']); From dfcf5c912a8a0f68d53358c06926dcf4bd024897 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 14 Jul 2015 12:15:05 +0100 Subject: [PATCH 11/20] Updated where queries --- html/includes/print-map.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index c9fc541d1c..6fc83465b1 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -17,12 +17,12 @@ $row_colour="#ffffff"; $sql_array= array(); if (!empty($device['hostname'])) { - $sql = ' WHERE `devices`.`hostname`=?'; + $sql = ' `devices`.`hostname`=?'; $sql_array = array($device['hostname']); $mac_sql = ' AND `D`.`hostname` = ?'; $mac_array = array($device['hostname']); } else { - $sql = ' WHERE 1'; + $sql = ' '; } $sql .= ' AND `local_device_id` != 0 AND `remote_device_id` != 0 '; From 746f918a8a395ee3ff23a4a6fffe29f78a1f65a2 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 14 Jul 2015 13:11:54 +0100 Subject: [PATCH 12/20] More map updates --- html/includes/print-map.inc.php | 84 ++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index 6fc83465b1..45a814e253 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -17,21 +17,62 @@ $row_colour="#ffffff"; $sql_array= array(); if (!empty($device['hostname'])) { - $sql = ' `devices`.`hostname`=?'; - $sql_array = array($device['hostname']); + $sql = ' AND (`D1`.`hostname`=? OR `D2`.`hostname`=?)'; + $sql_array = array($device['hostname'], $device['hostname']); $mac_sql = ' AND `D`.`hostname` = ?'; $mac_array = array($device['hostname']); } else { $sql = ' '; } -$sql .= ' AND `local_device_id` != 0 AND `remote_device_id` != 0 '; -$sql .= ' AND `local_device_id` IS NOT NULL AND `remote_device_id` IS NOT NULL '; +if (is_admin() === false && is_read() === false) { + $join_sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D1`.`device_id` = `DP`.`device_id`'; + $sql .= ' AND `DP`.`user_id`=?'; + $sql_array[] = $_SESSION['user_id']; +} $tmp_devices = array(); $tmp_ids = array(); $tmp_links = array(); -foreach (dbFetchRows("SELECT + + +$ports = dbFetchRows("SELECT + `D1`.`device_id` AS `local_device_id`, + `D1`.`os` AS `local_os`, + `D1`.`hostname` AS `local_hostname`, + `D2`.`device_id` AS `remote_device_id`, + `D2`.`os` AS `remote_os`, + `D2`.`hostname` AS `remote_hostname`, + `P1`.`port_id` AS `local_port_id`, + `P1`.`device_id` AS `local_port_device_id`, + `P1`.`ifName` AS `local_ifname`, + `P1`.`ifSpeed` AS `local_ifspeed`, + `P1`.`ifOperStatus` AS `local_ifoperstatus`, + `P1`.`ifAdminStatus` AS `local_ifadminstatus`, + `P1`.`ifInOctets_rate` AS `local_ifinoctets_rate`, + `P1`.`ifOutOctets_rate` AS `local_ifoutoctets_rate`, + `P2`.`port_id` AS `remote_port_id`, + `P2`.`device_id` AS `remote_port_device_id`, + `P2`.`ifName` AS `remote_ifname`, + `P2`.`ifSpeed` AS `remote_ifspeed`, + `P2`.`ifOperStatus` AS `remote_ifoperstatus`, + `P2`.`ifAdminStatus` AS `remote_ifadminstatus`, + `P2`.`ifInOctets_rate` AS `remote_ifinoctets_rate`, + `P2`.`ifOutOctets_rate` AS `remote_ifoutoctets_rate` + FROM `ipv4_mac` AS `M` + LEFT JOIN `ports` AS `P1` ON `P1`.`port_id`=`M`.`port_id` + LEFT JOIN `ports` AS `P2` ON `P2`.`ifPhysAddress`=`M`.`mac_address` + LEFT JOIN `devices` AS `D1` ON `P1`.`device_id`=`D1`.`device_id` + LEFT JOIN `devices` AS `D2` ON `P2`.`device_id`=`D2`.`device_id` + $join_sql + WHERE + `P1`.`port_id` IS NOT NULL AND + `P2`.`port_id` IS NOT NULL AND + `D1`.`device_id` != `D2`.`device_id` + $sql + ", $sql_array); + +$devices = dbFetchRows("SELECT `D1`.`device_id` AS `local_device_id`, `D1`.`os` AS `local_os`, `D1`.`hostname` AS `local_hostname`, @@ -59,10 +100,19 @@ foreach (dbFetchRows("SELECT LEFT JOIN `devices` AS `D2` ON `D2`.`device_id`=`links`.`remote_device_id` LEFT JOIN `ports` AS `P1` ON `P1`.`port_id`=`links`.`local_port_id` LEFT JOIN `ports` AS `P2` ON `P2`.`port_id`=`links`.`remote_port_id` + $join_sql WHERE - `active`=1 + `active`=1 AND + `local_device_id` != 0 AND + `remote_device_id` != 0 AND + `local_device_id` IS NOT NULL AND + `remote_device_id` IS NOT NULL $sql - ",$sql_array) as $items) { + ", $sql_array); + +$list = array_merge($ports,$devices); + +foreach ($list as $items) { $local_device = array('device_id'=>$items['local_device_id'], 'os'=>$items['local_os'], 'hostname'=>$items['local_hostname']); $remote_device = array('device_id'=>$items['remote_device_id'], 'os'=>$items['remote_os'], 'hostname'=>$items['remote_hostname']); @@ -77,7 +127,7 @@ foreach (dbFetchRows("SELECT } array_push($tmp_ids,$items['local_device_id']); array_push($tmp_ids,$items['remote_device_id']); - $speed = $items['ifSpeed']/1000/1000; + $speed = $items['local_ifspeed']/1000/1000; if ($speed == 100) { $width = 3; } elseif ($speed == 1000) { @@ -117,7 +167,8 @@ if (count($node_devices) > 1 && count($tmp_links) > 0) {
    - Date: Tue, 14 Jul 2015 13:15:37 +0100 Subject: [PATCH 13/20] set width 100% for network map --- html/css/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/css/styles.css b/html/css/styles.css index 94697ff523..69ae991a8f 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -1588,7 +1588,7 @@ tr.search:nth-child(odd) { } #visualization { - width: 90%; + width: 100%; min-height: 600px; } From 361653aa81fcd685e5f07dca9b3ffbd48eaa6857 Mon Sep 17 00:00:00 2001 From: Job Snijders Date: Mon, 13 Jul 2015 20:10:26 +0200 Subject: [PATCH 14/20] Fix coding style part 2 --- addhost.php | 328 +- adduser.php | 63 +- alerts.php | 824 +++-- billing-calculate.php | 253 +- build-base.php | 51 +- callback.php | 110 +- config_to_json.php | 3 +- contrib/generate-iplist.php | 52 +- daily.php | 73 +- delhost.php | 38 +- discovery.php | 182 +- dist-pollers.php | 66 +- html/ajax_form.php | 62 +- html/ajax_listports.php | 53 +- html/ajax_rulesuggest.php | 204 +- html/ajax_search.php | 418 +-- html/ajax_table.php | 40 +- html/api_v0.php | 158 +- html/bandwidth-graph.php | 375 +- html/billing-graph.php | 349 +- html/csv.php | 67 +- html/data.php | 50 +- html/form_new_config.php | 121 +- html/forms/ack-alert.inc.php | 38 +- html/forms/alert-templates.inc.php | 28 +- html/forms/attach-alert-template.inc.php | 30 +- html/forms/callback-statistics.inc.php | 6 +- html/forms/config-item-disable.inc.php | 52 +- html/forms/config-item-update.inc.php | 34 +- html/forms/config-item.inc.php | 188 +- html/forms/create-alert-item.inc.php | 89 +- html/forms/create-device-group.inc.php | 55 +- html/forms/create-map-item.inc.php | 94 +- html/forms/delete-alert-map.inc.php | 48 +- html/forms/delete-alert-rule.inc.php | 35 +- html/forms/delete-alert-template.inc.php | 41 +- html/forms/delete-device-group.inc.php | 34 +- html/forms/discovery-module-update.inc.php | 49 +- html/forms/health-update.inc.php | 32 +- html/forms/parse-alert-map.inc.php | 21 +- html/forms/parse-alert-rule.inc.php | 17 +- html/forms/parse-alert-template.inc.php | 11 +- html/forms/parse-device-group.inc.php | 22 +- html/forms/parse-poller-groups.inc.php | 11 +- html/forms/parse-template-rules.inc.php | 9 +- html/forms/poller-group-remove.inc.php | 29 +- html/forms/poller-groups.inc.php | 44 +- html/forms/poller-module-update.inc.php | 49 +- html/forms/rediscover-device.inc.php | 49 +- html/forms/schedule-maintenance.inc.php | 103 +- html/forms/sensor-alert-reset.inc.php | 25 +- html/forms/sensor-alert-update.inc.php | 60 +- html/forms/token-item-create.inc.php | 68 +- html/forms/token-item-disable.inc.php | 70 +- html/forms/token-item-remove.inc.php | 53 +- html/forms/update-alert-rule.inc.php | 53 +- html/forms/update-config-item.inc.php | 64 +- html/graph-realtime.php | 85 +- html/graph.php | 77 +- html/includes/api_functions.inc.php | 1134 +++--- html/includes/authenticate.inc.php | 173 +- .../includes/authentication/http-auth.inc.php | 127 +- html/includes/authentication/ldap.inc.php | 395 ++- html/includes/authentication/mysql.inc.php | 270 +- .../includes/authentication/twofactor.lib.php | 47 +- html/includes/collectd/functions.php | 1455 +++++--- html/includes/dev-overview-data.inc.php | 108 +- html/includes/device-header.inc.php | 95 +- html/includes/device-summary-horiz.inc.php | 2 +- html/includes/device-summary-vert.inc.php | 2 +- html/includes/error-no-perm.inc.php | 2 - html/includes/front/boxes.inc.php | 38 +- html/includes/front/top_device_bits.inc.php | 41 +- html/includes/front/top_ports.inc.php | 39 +- html/includes/functions.inc.php | 1626 +++++---- html/includes/geshi/geshi/ios.php | 326 +- .../graphs/accesspoints/channel.inc.php | 24 +- .../graphs/application/apache_bits.inc.php | 25 +- .../graphs/application/apache_cpu.inc.php | 23 +- .../graphs/application/apache_hits.inc.php | 23 +- .../application/apache_scoreboard.inc.php | 86 +- .../graphs/application/bind_queries.inc.php | 55 +- .../graphs/application/drbd_disk_bits.inc.php | 21 +- .../application/drbd_network_bits.inc.php | 19 +- .../graphs/application/drbd_unsynced.inc.php | 25 +- .../graphs/application/memcached_bits.inc.php | 12 +- .../mysql_command_counters.inc.php | 77 +- .../application/ntpdserver_packets.inc.php | 18 +- .../application/shoutcast_multi_bits.inc.php | 3 +- .../application/shoutcast_multi_stats.inc.php | 3 +- .../graphs/application/tinydns_dnssec.inc.php | 51 +- .../graphs/application/tinydns_errors.inc.php | 49 +- .../graphs/application/tinydns_other.inc.php | 49 +- .../application/tinydns_queries.inc.php | 58 +- html/includes/graphs/common.inc.php | 121 +- html/includes/graphs/customer/auth.inc.php | 12 +- html/includes/graphs/customer/bits.inc.php | 44 +- html/includes/graphs/device/asa_conns.inc.php | 37 +- html/includes/graphs/device/auth.inc.php | 9 +- html/includes/graphs/device/bits.inc.php | 105 +- html/includes/graphs/device/charge.inc.php | 10 +- .../graphs/device/cipsec_flow_stats.inc.php | 87 +- html/includes/graphs/device/collectd.inc.php | 352 +- .../graphs/device/diskio_bits.inc.php | 18 +- .../includes/graphs/device/diskio_ops.inc.php | 16 +- html/includes/graphs/device/fdb_count.inc.php | 12 +- html/includes/graphs/device/load.inc.php | 10 +- html/includes/graphs/device/mib.inc.php | 27 +- .../graphs/device/netstat_ip_forward.inc.php | 26 +- html/includes/graphs/device/ping_perf.inc.php | 32 +- .../graphs/device/poller_perf.inc.php | 32 +- html/includes/graphs/device/sensor.inc.php | 99 +- .../graphs/device/siklu_rfAverageCinr.inc.php | 13 +- .../graphs/device/siklu_rfAverageRssi.inc.php | 13 +- .../siklu_rfOperationalFrequency.inc.php | 13 +- .../device/siklu_rfinterfaceOctets.inc.php | 25 +- .../siklu_rfinterfaceOtherOctets.inc.php | 39 +- .../device/siklu_rfinterfaceOtherPkts.inc.php | 29 +- .../device/siklu_rfinterfacePkts.inc.php | 21 +- html/includes/graphs/device/sla.inc.php | 46 +- html/includes/graphs/device/state.inc.php | 10 +- html/includes/graphs/device/toner.inc.php | 3 +- .../device/ubnt_airfiber_Capacity.inc.php | 36 +- .../device/ubnt_airfiber_LinkDist.inc.php | 22 +- .../ubnt_airfiber_RFTotOctetsRx.inc.php | 23 +- .../ubnt_airfiber_RFTotOctetsTx.inc.php | 23 +- .../device/ubnt_airfiber_RFTotPktsRx.inc.php | 23 +- .../device/ubnt_airfiber_RFTotPktsTx.inc.php | 23 +- .../device/ubnt_airfiber_RadioFreqs.inc.php | 33 +- .../device/ubnt_airfiber_RadioTemp.inc.php | 33 +- .../device/ubnt_airfiber_TxPower.inc.php | 22 +- .../device/ubnt_airmax_AirMaxCapacity.inc.php | 23 +- .../device/ubnt_airmax_AirMaxQuality.inc.php | 23 +- .../device/ubnt_airmax_RadioDistance.inc.php | 23 +- .../device/ubnt_airmax_RadioFreq.inc.php | 22 +- .../device/ubnt_airmax_RadioRssi_0.inc.php | 23 +- .../device/ubnt_airmax_RadioRssi_1.inc.php | 23 +- .../device/ubnt_airmax_RadioTxPower.inc.php | 22 +- .../device/ubnt_airmax_WlStatCcq.inc.php | 22 +- .../ubnt_airmax_WlStatNoiseFloor.inc.php | 23 +- .../device/ubnt_airmax_WlStatRssi.inc.php | 23 +- .../device/ubnt_airmax_WlStatRxRate.inc.php | 25 +- .../device/ubnt_airmax_WlStatSignal.inc.php | 18 +- .../device/ubnt_airmax_WlStatStaCount.inc.php | 22 +- .../device/ubnt_airmax_WlStatTxRate.inc.php | 25 +- .../graphs/device/ucd_contexts.inc.php | 16 +- html/includes/graphs/device/ucd_cpu.inc.php | 24 +- .../graphs/device/ucd_interrupts.inc.php | 18 +- html/includes/graphs/generic_data.inc.php | 202 +- .../generic_multi_bits_separated.inc.php | 227 +- .../graphs/generic_multi_seperated.inc.php | 302 +- html/includes/graphs/global/bits.inc.php | 6 +- html/includes/graphs/graph.inc.php | 299 +- html/includes/graphs/location/bits.inc.php | 9 +- html/includes/graphs/mempool/auth.inc.php | 22 +- html/includes/graphs/munin/auth.inc.php | 30 +- html/includes/graphs/munin/graph.inc.php | 2 +- html/includes/graphs/port/auth.inc.php | 25 +- html/includes/graphs/port/nupkts.inc.php | 2 +- html/includes/graphs/processor/auth.inc.php | 17 +- html/includes/graphs/processor/usage.inc.php | 18 +- html/includes/graphs/rserver/auth.inc.php | 2 +- html/includes/graphs/rserver/curr.inc.php | 21 +- html/includes/graphs/rserver/failed.inc.php | 6 +- html/includes/graphs/rserver/total.inc.php | 16 +- html/includes/graphs/sensor/charge.inc.php | 38 +- html/includes/graphs/sensor/current.inc.php | 2 +- html/includes/graphs/sensor/dbm.inc.php | 2 +- html/includes/graphs/sensor/load.inc.php | 25 +- html/includes/graphs/sensor/state.inc.php | 22 +- .../graphs/service/availability.inc.php | 29 +- html/includes/graphs/storage/auth.inc.php | 22 +- html/includes/graphs/toner/auth.inc.php | 22 +- html/includes/graphs/toner/usage.inc.php | 26 +- html/includes/graphs/vserver/auth.inc.php | 2 +- html/includes/graphs/vserver/conns.inc.php | 16 +- html/includes/hostbox-menu.inc.php | 56 +- html/includes/hostbox-public.inc.php | 100 +- .../javascript-interfacepicker.inc.php | 1 - .../jpgraph/src/contour_dev/findpolygon.php | 12 +- .../jpgraph/src/contour_dev/tri-quad.php | 32 +- html/includes/modal/alert_schedule.inc.php | 2 - html/includes/modal/new_alert_rule.inc.php | 2 - html/includes/modal/new_device_group.inc.php | 2 - html/includes/modal/poller_groups.inc.php | 5 +- .../modal/remove_alert_schedule.inc.php | 2 - html/includes/object-cache.inc.php | 45 +- html/includes/plugins.inc.php | 117 +- html/includes/print-accesspoint.inc.php | 2 +- html/includes/print-alert-rules.php | 402 ++- html/includes/print-alert-templates.php | 67 +- html/includes/print-alerts.inc.php | 60 +- html/includes/print-debug.php | 25 +- html/includes/print-event-short.inc.php | 30 +- html/includes/print-event.inc.php | 38 +- html/includes/print-graph-alerts.inc.php | 25 +- html/includes/print-graphrow.inc.php | 76 +- html/includes/print-interface.inc.php | 509 +-- html/includes/print-map.inc.php | 26 +- html/includes/print-menubar.php | 383 +- html/includes/print-service-add.inc.php | 4 +- html/includes/print-service-edit.inc.php | 20 +- html/includes/print-syslog.inc.php | 31 +- html/includes/reports/alert-log.pdf.inc.php | 126 +- html/includes/reports/ports.csv.inc.php | 234 +- html/includes/service-add.inc.php | 6 +- html/includes/table/address-search.inc.php | 97 +- html/includes/table/alert-schedule.inc.php | 32 +- html/includes/table/alertlog.inc.php | 74 +- html/includes/table/alerts.inc.php | 130 +- html/includes/table/arp-search.inc.php | 103 +- html/includes/table/devices.inc.php | 300 +- html/includes/table/eventlog.inc.php | 57 +- html/includes/table/inventory.inc.php | 50 +- html/includes/table/mempool.inc.php | 114 +- html/includes/table/poll-log.inc.php | 32 +- html/includes/table/processor.inc.php | 104 +- html/includes/table/storage.inc.php | 105 +- html/includes/table/syslog.inc.php | 80 +- html/includes/vars.inc.php | 54 +- html/index.php | 261 +- html/install.php | 299 +- html/netcmd.php | 96 +- html/pages/about.inc.php | 87 +- html/pages/addhost.inc.php | 156 +- html/pages/addsrv.inc.php | 76 +- html/pages/adduser.inc.php | 117 +- html/pages/alert-log.inc.php | 25 +- html/pages/alert-map.inc.php | 40 +- html/pages/alert-rules.inc.php | 22 +- html/pages/alert-schedule.inc.php | 18 +- html/pages/alert-stats.inc.php | 21 +- html/pages/alerts.inc.php | 22 +- html/pages/api-access.inc.php | 69 +- html/pages/api-docs.inc.php | 3 +- html/pages/apps.inc.php | 111 +- html/pages/apps/default.inc.php | 64 +- html/pages/authlog.inc.php | 60 +- html/pages/bill.inc.php | 536 +-- html/pages/bill/actions.inc.php | 3 +- html/pages/bill/edit.inc.php | 231 +- html/pages/bill/history.inc.php | 225 +- html/pages/bill/pdf_history.inc.php | 633 ++-- html/pages/bill/transfer.inc.php | 290 +- html/pages/bills.inc.php | 376 +- html/pages/bills/pmonth.inc.php | 126 +- html/pages/bills/search.inc.php | 21 +- html/pages/customers.inc.php | 93 +- html/pages/deleted-ports.inc.php | 3 +- html/pages/delhost.inc.php | 56 +- html/pages/delsrv.inc.php | 41 +- html/pages/deluser.inc.php | 127 +- html/pages/device-groups.inc.php | 28 +- html/pages/device.inc.php | 714 ++-- html/pages/device/accesspoints.inc.php | 20 +- html/pages/device/alert-stats.inc.php | 21 +- html/pages/device/alerts.inc.php | 22 +- html/pages/device/apps/bind.inc.php | 33 +- html/pages/device/apps/shoutcast.inc.php | 6 +- html/pages/device/apps/tinydns.inc.php | 41 +- html/pages/device/collectd.inc.php | 3 +- html/pages/device/edit.inc.php | 252 +- html/pages/device/edit/alert-rules.inc.php | 22 +- html/pages/device/edit/alerts.inc.php | 95 +- html/pages/device/edit/apps.inc.php | 173 +- html/pages/device/edit/device.inc.php | 117 +- html/pages/device/edit/health.inc.php | 218 +- html/pages/device/edit/ipmi.inc.php | 66 +- html/pages/device/edit/modules.inc.php | 162 +- html/pages/device/edit/ports.inc.php | 99 +- html/pages/device/edit/services.inc.php | 78 +- html/pages/device/edit/snmp.inc.php | 341 +- html/pages/device/entphysical.inc.php | 9 +- html/pages/device/graphs.inc.php | 90 +- .../device/graphs/netstats_ip_forward.inc.php | 11 +- html/pages/device/health.inc.php | 176 +- html/pages/device/health/charge.inc.php | 10 +- html/pages/device/health/current.inc.php | 4 +- html/pages/device/health/humidity.inc.php | 4 +- html/pages/device/health/load.inc.php | 10 +- html/pages/device/health/mempool.inc.php | 94 +- html/pages/device/health/processor.inc.php | 51 +- html/pages/device/health/state.inc.php | 8 +- html/pages/device/health/storage.inc.php | 66 +- html/pages/device/hrdevice.inc.php | 113 +- .../device/loadbalancer/ace_rservers.inc.php | 13 +- .../device/loadbalancer/ace_vservers.inc.php | 133 +- .../loadbalancer/netscaler_vsvr.inc.php | 2 +- html/pages/device/logs.inc.php | 52 +- html/pages/device/logs/eventlog.inc.php | 42 +- html/pages/device/logs/syslog.inc.php | 53 +- html/pages/device/map.inc.php | 6 +- html/pages/device/munin.inc.php | 103 +- html/pages/device/overview.inc.php | 60 +- html/pages/device/overview/c6kxbar.inc.php | 153 +- html/pages/device/overview/eventlog.inc.php | 31 +- .../device/overview/generic/sensor.inc.php | 118 +- html/pages/device/overview/mempools.inc.php | 117 +- html/pages/device/overview/ports.inc.php | 98 +- html/pages/device/overview/processors.inc.php | 89 +- .../device/overview/sensors/charge.inc.php | 12 +- .../device/overview/sensors/load.inc.php | 10 +- .../device/overview/sensors/state.inc.php | 10 +- html/pages/device/overview/services.inc.php | 61 +- html/pages/device/overview/storage.inc.php | 127 +- html/pages/device/overview/syslog.inc.php | 39 +- html/pages/device/overview/toner.inc.php | 94 +- html/pages/device/performance.inc.php | 10 +- html/pages/device/port.inc.php | 299 +- html/pages/device/port/events.inc.php | 13 +- html/pages/device/port/pagp.inc.php | 56 +- html/pages/device/ports.inc.php | 226 +- html/pages/device/ports/neighbours.inc.php | 3 +- html/pages/device/processes.inc.php | 154 +- html/pages/device/pseudowires.inc.php | 3 +- html/pages/device/routing/bgp.inc.php | 366 +- html/pages/device/routing/ospf.inc.php | 3 +- html/pages/device/showconfig.inc.php | 217 +- html/pages/device/slas.inc.php | 2 +- html/pages/devices.inc.php | 431 +-- html/pages/editsrv.inc.php | 46 +- html/pages/edituser.inc.php | 537 +-- html/pages/eventlog.inc.php | 33 +- html/pages/front/default.php | 340 +- html/pages/front/demo.php | 237 +- html/pages/front/example2.php | 222 +- html/pages/front/globe.php | 242 +- html/pages/front/jt.php | 337 +- html/pages/front/traffic.php | 288 +- html/pages/graphs.inc.php | 325 +- html/pages/health.inc.php | 66 +- html/pages/health/charge.inc.php | 4 +- html/pages/health/load.inc.php | 10 +- html/pages/health/sensors.inc.php | 148 +- html/pages/iftype.inc.php | 158 +- html/pages/inventory.inc.php | 33 +- html/pages/locations.inc.php | 144 +- html/pages/logon.inc.php | 9 +- html/pages/map.inc.php | 5 +- html/pages/packages.inc.php | 9 +- html/pages/plugin.inc.php | 30 +- html/pages/plugin/admin.inc.php | 104 +- html/pages/poll-log.inc.php | 2 +- html/pages/pollers.inc.php | 29 +- html/pages/pollers/groups.inc.php | 11 +- html/pages/pollers/pollers.inc.php | 16 +- html/pages/ports.inc.php | 541 ++- html/pages/ports/list.inc.php | 113 +- html/pages/preferences.inc.php | 261 +- html/pages/pseudowires.inc.php | 3 +- html/pages/public.inc.php | 30 +- html/pages/routing/bgp.inc.php | 577 +-- html/pages/routing/overview.inc.php | 2 +- html/pages/search.inc.php | 55 +- html/pages/search/arp.inc.php | 29 +- html/pages/search/ipv4.inc.php | 29 +- html/pages/search/ipv6.inc.php | 29 +- html/pages/search/mac.inc.php | 30 +- html/pages/search/packages.inc.php | 194 +- html/pages/services.inc.php | 165 +- html/pages/settings.inc.php | 57 +- html/pages/settings/alerting.inc.php | 147 +- html/pages/syslog.inc.php | 43 +- html/pages/templates.inc.php | 22 +- html/pdf.php | 55 +- html/plugins/Test/Test.inc.php | 4 +- html/plugins/Test/Test.php | 25 +- includes/alerts.inc.php | 515 +-- includes/alerts/transport.api.php | 50 +- includes/alerts/transport.dummy.php | 4 +- includes/alerts/transport.hipchat.php | 60 +- includes/alerts/transport.irc.php | 4 +- includes/alerts/transport.mail.php | 4 +- includes/alerts/transport.nagios.php | 4 +- includes/alerts/transport.pagerduty.php | 32 +- includes/alerts/transport.pushover.php | 64 +- includes/alerts/transport.slack.php | 56 +- includes/billing.php | 336 +- includes/caches/devices.inc.php | 77 +- includes/caches/ports.inc.php | 83 +- includes/caches/services.inc.php | 61 +- includes/cisco-entities.php | 42 +- includes/common.php | 942 +++-- includes/console_colour.php | 280 +- includes/console_table.php | 503 +-- includes/db/status_count.inc.php | 24 +- includes/dbFacile.php | 697 ++-- includes/defaults.inc.php | 1074 +++--- includes/definitions.inc.php | 3101 +++++++++-------- includes/device-groups.inc.php | 121 +- includes/discovery/arp-table.inc.php | 130 +- includes/discovery/bgp-peers.inc.php | 444 +-- includes/discovery/charge.inc.php | 15 +- includes/discovery/charge/apc.inc.php | 71 +- includes/discovery/charge/dsm.inc.php | 29 +- includes/discovery/charge/rfc1628.inc.php | 45 +- includes/discovery/cisco-cef.inc.php | 77 +- .../discovery/cisco-entity-sensor.inc.php | 5 +- .../discovery/cisco-mac-accounting.inc.php | 90 +- includes/discovery/cisco-pw.inc.php | 108 +- includes/discovery/cisco-sla.inc.php | 6 +- includes/discovery/cisco-vrf.inc.php | 263 +- includes/discovery/current/apc.inc.php | 409 ++- .../discovery/current/gamatronicups.inc.php | 6 +- includes/discovery/current/ipoman.inc.php | 6 +- includes/discovery/current/netvision.inc.php | 6 +- includes/discovery/current/raritan.inc.php | 123 +- includes/discovery/current/rfc1628.inc.php | 144 +- includes/discovery/current/sentry3.inc.php | 3 +- includes/discovery/current/xups.inc.php | 3 +- includes/discovery/discovery-arp.inc.php | 93 +- .../discovery/discovery-protocols.inc.php | 256 +- includes/discovery/entity-physical.inc.php | 202 +- includes/discovery/entity-sensor.inc.php | 173 +- includes/discovery/fanspeeds/dell.inc.php | 35 +- includes/discovery/fanspeeds/drac.inc.php | 36 +- .../discovery/fanspeeds/equallogic.inc.php | 58 +- includes/discovery/fanspeeds/mikrotik.inc.php | 51 +- includes/discovery/frequencies/ipoman.inc.php | 3 +- .../discovery/frequencies/raritan.inc.php | 45 +- .../discovery/frequencies/rfc1628.inc.php | 81 +- includes/discovery/functions.inc.php | 1251 +++---- includes/discovery/hr-device.inc.php | 104 +- includes/discovery/humidity.inc.php | 15 +- includes/discovery/humidity/apc.inc.php | 5 +- includes/discovery/humidity/mgeups.inc.php | 3 +- includes/discovery/humidity/netbotz.inc.php | 3 +- includes/discovery/ipmi.inc.php | 77 +- includes/discovery/ipv4-addresses.inc.php | 95 +- includes/discovery/ipv6-addresses.inc.php | 143 +- includes/discovery/junose-atm-vp.inc.php | 94 +- includes/discovery/libvirt-vminfo.inc.php | 234 +- includes/discovery/load.inc.php | 15 +- includes/discovery/load/apc.inc.php | 54 +- includes/discovery/load/dsm.inc.php | 41 +- includes/discovery/load/rfc1628.inc.php | 29 +- includes/discovery/mempools.inc.php | 39 +- .../discovery/mempools/aos-device.inc.php | 21 +- includes/discovery/mempools/cemp.inc.php | 36 +- includes/discovery/mempools/cmp.inc.php | 24 +- includes/discovery/mempools/fiberhome.inc.php | 29 +- .../discovery/mempools/hp-procurve.inc.php | 61 +- includes/discovery/mempools/hrstorage.inc.php | 88 +- .../discovery/mempools/ironware-dyn.inc.php | 15 +- includes/discovery/mempools/junos.inc.php | 96 +- .../mempools/powerconnect-cpu.inc.php | 15 +- includes/discovery/mempools/screenos.inc.php | 21 +- includes/discovery/mempools/vrp.inc.php | 3 +- includes/discovery/os.inc.php | 16 +- includes/discovery/os/3com.inc.php | 17 +- includes/discovery/os/adva.inc.php | 8 - includes/discovery/os/alcatel-lucent.inc.php | 55 +- includes/discovery/os/allied.inc.php | 14 +- includes/discovery/os/areca.inc.php | 9 +- includes/discovery/os/arista-eos.inc.php | 9 +- includes/discovery/os/asa.inc.php | 9 +- includes/discovery/os/avaya-ers.inc.php | 13 +- includes/discovery/os/barracuda.inc.php | 23 +- includes/discovery/os/canopy.inc.php | 2 +- includes/discovery/os/cat1900.inc.php | 9 +- includes/discovery/os/catos.inc.php | 9 +- includes/discovery/os/ciscosb.inc.php | 10 +- includes/discovery/os/ciscowlc.inc.php | 25 +- includes/discovery/os/comware.inc.php | 13 +- includes/discovery/os/datacom.inc.php | 8 +- includes/discovery/os/drac.inc.php | 9 +- includes/discovery/os/edgeos.inc.php | 6 +- includes/discovery/os/edgeswitch.inc.php | 6 +- includes/discovery/os/engenius.inc.php | 27 +- includes/discovery/os/enterasys.inc.php | 6 +- includes/discovery/os/equallogic.inc.php | 5 +- includes/discovery/os/extremeware.inc.php | 14 +- includes/discovery/os/f5.inc.php | 9 +- includes/discovery/os/fabos.inc.php | 14 +- includes/discovery/os/fireware.inc.php | 5 +- includes/discovery/os/fortigate.inc.php | 14 +- includes/discovery/os/freebsd.inc.php | 21 +- includes/discovery/os/ftos.inc.php | 9 +- includes/discovery/os/hikvision.inc.php | 8 +- includes/discovery/os/huaweiups.inc.php | 13 +- includes/discovery/os/ibmnos.inc.php | 23 +- includes/discovery/os/ios.inc.php | 36 +- includes/discovery/os/ironware.inc.php | 9 +- includes/discovery/os/junos.inc.php | 9 +- includes/discovery/os/junose.inc.php | 9 +- includes/discovery/os/jwos.inc.php | 9 +- includes/discovery/os/linux.inc.php | 101 +- includes/discovery/os/merakimr.inc.php | 6 +- includes/discovery/os/merakims.inc.php | 6 +- includes/discovery/os/merakimx.inc.php | 6 +- includes/discovery/os/multimatic.inc.php | 8 +- includes/discovery/os/netapp.inc.php | 4 +- includes/discovery/os/netbsd.inc.php | 9 +- includes/discovery/os/netgear.inc.php | 4 +- includes/discovery/os/netmanplus.inc.php | 14 +- includes/discovery/os/netscaler.inc.php | 9 +- includes/discovery/os/nos.inc.php | 4 +- includes/discovery/os/nxos.inc.php | 9 +- includes/discovery/os/openbsd.inc.php | 13 +- includes/discovery/os/papouch-tme.inc.php | 13 +- includes/discovery/os/pbn.inc.php | 7 +- includes/discovery/os/pix.inc.php | 9 +- includes/discovery/os/powercode.inc.php | 8 +- includes/discovery/os/powerconnect.inc.php | 20 +- includes/discovery/os/procurve.inc.php | 11 +- includes/discovery/os/proxim.inc.php | 9 +- includes/discovery/os/radlan.inc.php | 14 +- includes/discovery/os/raritan.inc.php | 26 +- includes/discovery/os/ruckuswireless.inc.php | 23 +- includes/discovery/os/sanos.inc.php | 9 +- includes/discovery/os/screenos.inc.php | 14 +- includes/discovery/os/sentry3.inc.php | 9 +- includes/discovery/os/siklu.inc.php | 3 +- includes/discovery/os/solaris.inc.php | 29 +- includes/discovery/os/speedtouch.inc.php | 17 +- includes/discovery/os/vmware.inc.php | 9 +- includes/discovery/os/vyatta.inc.php | 9 +- includes/discovery/os/vyos.inc.php | 8 +- includes/discovery/os/watchguard.inc.php | 6 +- includes/discovery/os/webpower.inc.php | 5 +- includes/discovery/ports-stack.inc.php | 76 +- includes/discovery/ports.inc.php | 107 +- includes/discovery/power/dsm.inc.php | 29 +- includes/discovery/power/ipoman.inc.php | 3 +- includes/discovery/power/raritan.inc.php | 45 +- includes/discovery/power/rfc1628.inc.php | 89 +- includes/discovery/processors-ucd-old.inc.php | 24 +- includes/discovery/processors.inc.php | 46 +- .../discovery/processors/aos-device.inc.php | 45 +- includes/discovery/processors/ciscosb.inc.php | 32 +- includes/discovery/processors/datacom.inc.php | 11 +- .../discovery/processors/fiberhome.inc.php | 25 +- .../discovery/processors/fortigate.inc.php | 2 +- .../discovery/processors/hrdevice.inc.php | 145 +- includes/discovery/processors/ios.inc.php | 107 +- .../discovery/processors/ironware.inc.php | 76 +- includes/discovery/processors/junos.inc.php | 96 +- includes/discovery/processors/junose.inc.php | 44 +- .../discovery/processors/powerconnect.inc.php | 34 +- .../discovery/processors/procurve.inc.php | 29 +- includes/discovery/processors/radlan.inc.php | 2 +- .../discovery/processors/screenos.inc.php | 21 +- includes/discovery/processors/vrp.inc.php | 5 +- .../discovery/processors/watchguard.inc.php | 2 +- includes/discovery/sensors.inc.php | 34 +- includes/discovery/states.inc.php | 6 +- includes/discovery/states/dell.inc.php | 17 +- includes/discovery/states/dsm.inc.php | 91 +- includes/discovery/states/equallogic.inc.php | 55 +- includes/discovery/states/rfc1628.inc.php | 82 +- includes/discovery/storage.inc.php | 39 +- includes/discovery/storage/hrstorage.inc.php | 132 +- .../discovery/storage/netapp-storage.inc.php | 51 +- includes/discovery/temperatures.inc.php | 15 +- includes/discovery/temperatures/adva.inc.php | 14 +- includes/discovery/temperatures/apc.inc.php | 248 +- .../temperatures/cisco-envmon.inc.php | 59 +- .../discovery/temperatures/ciscowlc.inc.php | 30 +- .../temperatures/cometsystem-p85xx.inc.php | 5 +- includes/discovery/temperatures/dell.inc.php | 4 +- includes/discovery/temperatures/drac.inc.php | 44 +- includes/discovery/temperatures/dsm.inc.php | 45 +- .../discovery/temperatures/equallogic.inc.php | 72 +- .../discovery/temperatures/fiberhome.inc.php | 10 +- .../temperatures/ftos-c-series.inc.php | 3 +- .../temperatures/ftos-e-series.inc.php | 3 +- .../temperatures/ftos-s-series.inc.php | 3 +- includes/discovery/temperatures/hpilo.inc.php | 39 +- .../discovery/temperatures/ibmnos.inc.php | 50 +- .../discovery/temperatures/junose.inc.php | 5 +- .../discovery/temperatures/mgeups.inc.php | 3 +- .../discovery/temperatures/mikrotik.inc.php | 48 +- .../discovery/temperatures/netbotz.inc.php | 3 +- .../temperatures/papouch-tme.inc.php | 2 +- .../temperatures/powerconnect.inc.php | 63 +- includes/discovery/temperatures/siklu.inc.php | 29 +- .../discovery/temperatures/zyxel-ies.inc.php | 3 +- includes/discovery/toner.inc.php | 111 +- includes/discovery/ucd-diskio.inc.php | 76 +- includes/discovery/vlans.inc.php | 124 +- includes/discovery/vlans/cisco-vtp.inc.php | 52 +- includes/discovery/vmware-vminfo.inc.php | 222 +- includes/discovery/voltages.inc.php | 15 +- includes/discovery/voltages/dsm.inc.php | 73 +- .../discovery/voltages/gamatronicups.inc.php | 3 +- includes/discovery/voltages/ipoman.inc.php | 3 +- includes/discovery/voltages/mikrotik.inc.php | 45 +- includes/discovery/voltages/netvision.inc.php | 6 +- includes/discovery/voltages/rfc1628.inc.php | 3 +- includes/discovery/voltages/siklu.inc.php | 28 +- includes/discovery/voltages/xups.inc.php | 3 +- includes/functions.php | 1799 +++++----- includes/load_db_graph_types.inc.php | 3 +- includes/mergecnf.inc.php | 54 +- includes/object-cache.inc.php | 191 +- includes/polling/altiga-ssl.inc.php | 74 +- includes/polling/applications.inc.php | 3 +- includes/polling/applications/bind.inc.php | 131 +- includes/polling/applications/tinydns.inc.php | 35 +- includes/polling/aruba-controller.inc.php | 247 +- includes/polling/bgp-peers.inc.php | 606 ++-- includes/polling/cipsec-tunnels.inc.php | 159 +- .../polling/cisco-ace-loadbalancer.inc.php | 3 +- .../polling/cisco-ace-serverfarms.inc.php | 3 +- includes/polling/cisco-asa-firewall.inc.php | 89 +- includes/polling/cisco-cef.inc.php | 192 +- .../polling/cisco-ipsec-flow-monitor.inc.php | 211 +- includes/polling/cisco-mac-accounting.inc.php | 180 +- .../cisco-remote-access-monitor.inc.php | 126 +- includes/polling/cisco-vpdn.inc.php | 51 +- includes/polling/entity-physical.inc.php | 6 +- includes/polling/functions.inc.php | 669 ++-- includes/polling/hr-mib.inc.php | 59 +- includes/polling/ipSystemStats.inc.php | 196 +- includes/polling/ipmi.inc.php | 83 +- includes/polling/junose-atm-vp.inc.php | 92 +- includes/polling/mempools.inc.php | 94 +- includes/polling/mempools/aos-device.inc.php | 25 +- includes/polling/mempools/cemp.inc.php | 10 +- includes/polling/mempools/cmp.inc.php | 10 +- includes/polling/mempools/fiberhome.inc.php | 24 +- includes/polling/mempools/hpGlobal.inc.php | 35 +- includes/polling/mempools/hrstorage.inc.php | 25 +- .../polling/mempools/ironware-dyn.inc.php | 9 +- includes/polling/mempools/junos.inc.php | 39 +- .../polling/mempools/powerconnect-cpu.inc.php | 14 +- includes/polling/mempools/screenos.inc.php | 9 +- includes/polling/mib.inc.php | 2 +- includes/polling/mib/siklu-mib.inc.php | 123 +- .../polling/mib/ubnt-airfiber-mib.inc.php | 237 +- includes/polling/mib/ubnt-airmax-mib.inc.php | 187 +- includes/polling/netstats-icmp.inc.php | 108 +- includes/polling/netstats-ip.inc.php | 94 +- includes/polling/netstats-ip_forward.inc.php | 71 +- includes/polling/netstats-snmp.inc.php | 104 +- includes/polling/netstats-tcp.inc.php | 98 +- includes/polling/netstats-udp.inc.php | 80 +- includes/polling/netstats.inc.php | 18 +- includes/polling/os/3com.inc.php | 6 +- includes/polling/os/airos-af.inc.php | 6 +- includes/polling/os/airos.inc.php | 6 +- includes/polling/os/aos.inc.php | 4 +- includes/polling/os/apc.inc.php | 151 +- includes/polling/os/arista_eos.inc.php | 6 +- includes/polling/os/asa.inc.php | 18 +- includes/polling/os/canopy.inc.php | 10 +- includes/polling/os/cat1900.inc.php | 6 +- includes/polling/os/catos.inc.php | 35 +- includes/polling/os/cisco.inc.php | 65 +- includes/polling/os/ciscosb.inc.php | 27 +- includes/polling/os/ciscowlc.inc.php | 24 +- includes/polling/os/comware.inc.php | 17 +- includes/polling/os/datacom.inc.php | 9 +- includes/polling/os/dlink.inc.php | 10 +- includes/polling/os/edgeos.inc.php | 8 +- includes/polling/os/engenius.inc.php | 66 +- includes/polling/os/enterasys.inc.php | 8 +- includes/polling/os/f5.inc.php | 3 +- includes/polling/os/fiberhome.inc.php | 7 +- includes/polling/os/fortigate.inc.php | 57 +- includes/polling/os/hikvision.inc.php | 4 +- includes/polling/os/ibmnos.inc.php | 56 +- includes/polling/os/ios.inc.php | 81 +- includes/polling/os/iosxr.inc.php | 17 +- includes/polling/os/merakimr.inc.php | 4 +- includes/polling/os/merakims.inc.php | 4 +- includes/polling/os/merakimx.inc.php | 4 +- includes/polling/os/multimatic.inc.php | 4 +- includes/polling/os/netapp.inc.php | 8 +- includes/polling/os/netgear.inc.php | 6 +- includes/polling/os/nos.inc.php | 4 +- includes/polling/os/nxos.inc.php | 10 +- includes/polling/os/pbn.inc.php | 21 +- includes/polling/os/powercode.inc.php | 4 +- includes/polling/os/procera.inc.php | 6 +- includes/polling/os/procurve.inc.php | 70 +- includes/polling/os/routeros.inc.php | 9 +- includes/polling/os/ruckuswireless.inc.php | 62 +- includes/polling/os/screenos.inc.php | 28 +- includes/polling/os/siklu.inc.php | 2 +- includes/polling/os/snom.inc.php | 53 +- includes/polling/os/unifi.inc.php | 17 +- includes/polling/os/unix.inc.php | 207 +- includes/polling/os/vmware.inc.php | 120 +- includes/polling/os/vyos.inc.php | 12 +- includes/polling/os/webpower.inc.php | 26 +- includes/polling/os/windows.inc.php | 218 +- includes/polling/port-adsl.inc.php | 256 +- includes/polling/port-etherlike.inc.php | 57 +- includes/polling/port-poe.inc.php | 79 +- includes/polling/ports.inc.php | 1012 +++--- includes/polling/processors.inc.php | 53 +- includes/polling/processors/datacom.inc.php | 4 +- .../polling/processors/powerconnect.inc.php | 19 +- includes/polling/sensors.inc.php | 36 +- includes/polling/storage.inc.php | 76 +- includes/polling/storage/hrstorage.inc.php | 20 +- .../polling/storage/netapp-storage.inc.php | 16 +- includes/polling/system.inc.php | 136 +- includes/polling/temperatures/netapp.inc.php | 6 +- includes/polling/test.inc.php | 6 +- includes/polling/toner.inc.php | 66 +- includes/polling/ucd-diskio.inc.php | 3 +- includes/polling/ucd-mib.inc.php | 245 +- includes/polling/unix-agent.inc.php | 317 +- includes/polling/unix-agent/hddtemp.inc.php | 5 +- .../polling/unix-agent/munin-plugins.inc.php | 235 +- includes/polling/unix-agent/packages.inc.php | 258 +- includes/polling/wifi.inc.php | 201 +- includes/rewrites.php | 1997 +++++------ includes/rrdtool.inc.php | 361 +- includes/services.inc.php | 5 +- includes/snmp.inc.php | 918 +++-- includes/snmptrap/linkDown.inc.php | 32 +- includes/snmptrap/linkUp.inc.php | 10 +- includes/snom-graphing.php | 3 +- includes/sql-schema/update.php | 233 +- includes/syslog.php | 298 +- includes/versioncheck.inc.php | 73 +- irc.php | 1235 ++++--- poll-billing.php | 192 +- poller.php | 193 +- scripts/console-ui.php | 234 +- scripts/ntp-client.php | 143 +- scripts/ntpd-server.php | 154 +- scripts/powerdns.php | 138 +- scripts/update-sql.php | 35 +- syslog.php | 30 +- upgrade-scripts/fix-billing-2758.inc.php | 73 +- upgrade-scripts/fix-events.php | 23 +- validate.php | 165 +- 731 files changed, 37550 insertions(+), 34012 deletions(-) delete mode 100644 includes/discovery/os/adva.inc.php diff --git a/addhost.php b/addhost.php index d1e26a3991..f0719cc5e3 100755 --- a/addhost.php +++ b/addhost.php @@ -10,17 +10,16 @@ * @subpackage cli * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ chdir(dirname($argv[0])); -include("includes/defaults.inc.php"); -include("config.php"); -include("includes/definitions.inc.php"); -include("includes/functions.php"); +require 'includes/defaults.inc.php'; +require 'config.php'; +require 'includes/definitions.inc.php'; +require 'includes/functions.php'; -$options = getopt("g:f::"); +$options = getopt('g:f::'); if (isset($options['g']) && $options['g'] >= 0) { $cmd = array_shift($argv); @@ -28,7 +27,8 @@ if (isset($options['g']) && $options['g'] >= 0) { array_shift($argv); array_unshift($argv, $cmd); $poller_group = $options['g']; -} elseif ($config['distributed_poller'] === TRUE) { +} +else if ($config['distributed_poller'] === true) { $poller_group = $config['distributed_poller_group']; } @@ -39,195 +39,169 @@ if (isset($options['f']) && $options['f'] == 0) { $force_add = 1; } -if (!empty($argv[1])) -{ - $host = strtolower($argv[1]); - $community = $argv[2]; - $snmpver = strtolower($argv[3]); +if (!empty($argv[1])) { + $host = strtolower($argv[1]); + $community = $argv[2]; + $snmpver = strtolower($argv[3]); - $port = 161; - $transport = 'udp'; + $port = 161; + $transport = 'udp'; - if ($snmpver === "v3") - { - $seclevel = $community; + if ($snmpver === 'v3') { + $seclevel = $community; - // These values are the same as in defaults.inc.php - $v3 = array( - 'authlevel' => "noAuthNoPriv", - 'authname' => "root", - 'authpass' => "", - 'authalgo' => "MD5", - 'cryptopass' => "", - 'cryptoalgo' => "AES" - ); + // These values are the same as in defaults.inc.php + $v3 = array( + 'authlevel' => 'noAuthNoPriv', + 'authname' => 'root', + 'authpass' => '', + 'authalgo' => 'MD5', + 'cryptopass' => '', + 'cryptoalgo' => 'AES', + ); - if ($seclevel === "nanp" or $seclevel === "any" or $seclevel === "noAuthNoPriv") - { - $v3['authlevel'] = "noAuthNoPriv"; - $v3args = array_slice($argv, 4); + if ($seclevel === 'nanp' or $seclevel === 'any' or $seclevel === 'noAuthNoPriv') { + $v3['authlevel'] = 'noAuthNoPriv'; + $v3args = array_slice($argv, 4); - while ($arg = array_shift($v3args)) - { - // parse all remaining args - if (is_numeric($arg)) - { - $port = $arg; + while ($arg = array_shift($v3args)) { + // parse all remaining args + if (is_numeric($arg)) { + $port = $arg; + } + else if (preg_match('/^('.implode('|', $config['snmp']['transports']).')$/', $arg)) { + $transport = $arg; + } + else { + // should add a sanity check of chars allowed in user + $user = $arg; + } + } + + if ($seclevel === 'nanp') { + array_push($config['snmp']['v3'], $v3); + } + + $device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add); } - elseif (preg_match ('/^(' . implode("|",$config['snmp']['transports']) . ')$/', $arg)) - { - $transport = $arg; + else if ($seclevel === 'anp' or $seclevel === 'authNoPriv') { + $v3['authlevel'] = 'authNoPriv'; + $v3args = array_slice($argv, 4); + $v3['authname'] = array_shift($v3args); + $v3['authpass'] = array_shift($v3args); + + while ($arg = array_shift($v3args)) { + // parse all remaining args + if (is_numeric($arg)) { + $port = $arg; + } + else if (preg_match('/^('.implode('|', $config['snmp']['transports']).')$/i', $arg)) { + $transport = $arg; + } + else if (preg_match('/^(sha|md5)$/i', $arg)) { + $v3['authalgo'] = $arg; + } + else { + echo 'Invalid argument: '.$arg."\n"; + return; + } + } + + array_push($config['snmp']['v3'], $v3); + $device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add); } - else - { - // should add a sanity check of chars allowed in user - $user = $arg; + else if ($seclevel === 'ap' or $seclevel === 'authPriv') { + $v3['authlevel'] = 'authPriv'; + $v3args = array_slice($argv, 4); + $v3['authname'] = array_shift($v3args); + $v3['authpass'] = array_shift($v3args); + $v3['cryptopass'] = array_shift($v3args); + + while ($arg = array_shift($v3args)) { + // parse all remaining args + if (is_numeric($arg)) { + $port = $arg; + } + else if (preg_match('/^('.implode('|', $config['snmp']['transports']).')$/i', $arg)) { + $transport = $arg; + } + else if (preg_match('/^(sha|md5)$/i', $arg)) { + $v3['authalgo'] = $arg; + } + else if (preg_match('/^(aes|des)$/i', $arg)) { + $v3['cryptoalgo'] = $arg; + } + else { + echo 'Invalid argument: '.$arg."\n"; + return; + } + }//end while + + array_push($config['snmp']['v3'], $v3); + $device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add); } - - } - - if ($seclevel === "nanp") - { array_push($config['snmp']['v3'], $v3); } - - $device_id = addHost($host, $snmpver, $port, $transport,0,$poller_group,$force_add); - + else { + // Error or do nothing ? + }//end if } - elseif ($seclevel === "anp" or $seclevel === "authNoPriv") - { + else { + $v2args = array_slice($argv, 2); - $v3['authlevel'] = "authNoPriv"; - $v3args = array_slice($argv, 4); - $v3['authname'] = array_shift($v3args); - $v3['authpass'] = array_shift($v3args); - - while ($arg = array_shift($v3args)) - { - // parse all remaining args - if (is_numeric($arg)) - { - $port = $arg; + while ($arg = array_shift($v2args)) { + // parse all remaining args + if (is_numeric($arg)) { + $port = $arg; + } + else if (preg_match('/('.implode('|', $config['snmp']['transports']).')/i', $arg)) { + $transport = $arg; + } + else if (preg_match('/^(v1|v2c)$/i', $arg)) { + $snmpver = $arg; + } } - elseif (preg_match ('/^(' . implode("|",$config['snmp']['transports']) . ')$/i', $arg)) - { - $transport = $arg; - } - elseif (preg_match ('/^(sha|md5)$/i', $arg)) - { - $v3['authalgo'] = $arg; - } else { - echo "Invalid argument: " . $arg . "\n" ; - return ; - } - } - array_push($config['snmp']['v3'], $v3); - $device_id = addHost($host, $snmpver, $port, $transport,0,$poller_group,$force_add); + if ($community) { + $config['snmp']['community'] = array($community); + } + $device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add); + }//end if + + if ($snmpver) { + $snmpversions[] = $snmpver; } - elseif ($seclevel === "ap" or $seclevel === "authPriv") - { - $v3['authlevel'] = "authPriv"; - $v3args = array_slice($argv, 4); - $v3['authname'] = array_shift($v3args); - $v3['authpass'] = array_shift($v3args); - $v3['cryptopass'] = array_shift($v3args); - - while ($arg = array_shift($v3args)) - { - // parse all remaining args - if (is_numeric($arg)) - { - $port = $arg; - } - elseif (preg_match ('/^(' . implode("|",$config['snmp']['transports']) . ')$/i', $arg)) - { - $transport = $arg; - } - elseif (preg_match ('/^(sha|md5)$/i', $arg)) - { - $v3['authalgo'] = $arg; - } - elseif (preg_match ('/^(aes|des)$/i', $arg)) - { - $v3['cryptoalgo'] = $arg; - } else { - echo "Invalid argument: " . $arg . "\n" ; - return ; - } - } - - array_push($config['snmp']['v3'], $v3); - $device_id = addHost($host, $snmpver, $port, $transport,0,$poller_group,$force_add); - - } - else - { - // Error or do nothing ? - } - } - else // v1 or v2c - { - $v2args = array_slice($argv, 2); - - while ($arg = array_shift($v2args)) - { - // parse all remaining args - if (is_numeric($arg)) - { - $port = $arg; - } - elseif (preg_match ('/(' . implode("|",$config['snmp']['transports']) . ')/i', $arg)) - { - $transport = $arg; - } - elseif (preg_match ('/^(v1|v2c)$/i', $arg)) - { - $snmpver = $arg; - } + else { + $snmpversions = array( + 'v2c', + 'v3', + 'v1', + ); } - if ($community) - { - $config['snmp']['community'] = array($community); + while (!$device_id && count($snmpversions)) { + $snmpver = array_shift($snmpversions); + $device_id = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add); } - $device_id = addHost($host, $snmpver, $port, $transport,0,$poller_group,$force_add); - } + if ($device_id) { + $device = device_by_id_cache($device_id); + echo 'Added device '.$device['hostname'].' ('.$device_id.")\n"; + exit; + } +}//end if - if ($snmpver) - { - $snmpversions[] = $snmpver; - } - else - { - $snmpversions = array('v2c', 'v3', 'v1'); - } +print $console_color->convert( + "\n".$config['project_name_version'].' Add Host Tool - while (!$device_id && count($snmpversions)) - { - $snmpver = array_shift($snmpversions); - $device_id = addHost($host, $snmpver, $port, $transport,0,$poller_group,$force_add); - } + Usage (SNMPv1/2c): ./addhost.php [-g ] [-f] <%Whostname%n> [community] [v1|v2c] [port] ['.implode('|', $config['snmp']['transports']).'] + Usage (SNMPv3) : Config Defaults : ./addhost.php [-g ] [-f]<%Whostname%n> any v3 [user] [port] ['.implode('|', $config['snmp']['transports']).'] + No Auth, No Priv : ./addhost.php [-g ] [-f]<%Whostname%n> nanp v3 [user] [port] ['.implode('|', $config['snmp']['transports']).'] + Auth, No Priv : ./addhost.php [-g ] [-f]<%Whostname%n> anp v3 [md5|sha] [port] ['.implode('|', $config['snmp']['transports']).'] + Auth, Priv : ./addhost.php [-g ] [-f]<%Whostname%n> ap v3 [md5|sha] [aes|dsa] [port] ['.implode('|', $config['snmp']['transports']).'] - if ($device_id) - { - $device = device_by_id_cache($device_id); - echo("Added device ".$device['hostname']." (".$device_id.")\n"); - exit; - } -} + -g allows you to add a device to be pinned to a specific poller when using distributed polling. X can be any number associated with a poller group + -f forces the device to be added by skipping the icmp and snmp check against the host. -print $console_color->convert("\n" . $config['project_name_version']." Add Host Tool - -Usage (SNMPv1/2c): ./addhost.php [-g ] [-f] <%Whostname%n> [community] [v1|v2c] [port] [" . implode("|",$config['snmp']['transports']) . "] -Usage (SNMPv3) : Config Defaults : ./addhost.php [-g ] [-f]<%Whostname%n> any v3 [user] [port] [" . implode("|",$config['snmp']['transports']) . "] - No Auth, No Priv : ./addhost.php [-g ] [-f]<%Whostname%n> nanp v3 [user] [port] [" . implode("|",$config['snmp']['transports']) . "] - Auth, No Priv : ./addhost.php [-g ] [-f]<%Whostname%n> anp v3 [md5|sha] [port] [" . implode("|",$config['snmp']['transports']) . "] - Auth, Priv : ./addhost.php [-g ] [-f]<%Whostname%n> ap v3 [md5|sha] [aes|dsa] [port] [" . implode("|",$config['snmp']['transports']) . "] --g allows you to add a device to be pinned to a specific poller when using distributed polling. X can be any number associated with a poller group --f forces the device to be added by skipping the icmp and snmp check against the host. -%rRemember to run discovery for the host afterwards.%n - -"); - -?> + %rRemember to run discovery for the host afterwards.%n + ' +); diff --git a/adduser.php b/adduser.php index 4de2208be9..f1e591415c 100755 --- a/adduser.php +++ b/adduser.php @@ -1,7 +1,7 @@ #!/usr/bin/env php [email]\n"; } - } - else - { - echo("Add User Tool\nUsage: ./adduser.php [email]\n"); - } } -else -{ - echo("Auth module does not allow adding users!\n"); -} - -?> +else { + echo "Auth module does not allow adding users!\n"; +}//end if diff --git a/alerts.php b/alerts.php index c419ebaeb2..8fd4e53611 100755 --- a/alerts.php +++ b/alerts.php @@ -1,18 +1,20 @@ #!/usr/bin/env php +/* + * Copyright (C) 2014 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ /** * Alerts Cronjob @@ -23,59 +25,65 @@ * @subpackage Alerts */ -include_once("includes/defaults.inc.php"); -include_once("config.php"); +require_once 'includes/defaults.inc.php'; +require_once 'config.php'; $lock = false; -if( file_exists($config['install_dir']."/.alerts.lock") ) { - $pids = explode("\n", trim(`ps -e | grep php | awk '{print $1}'`)); - $lpid = trim(file_get_contents($config['install_dir']."/.alerts.lock")); - if( in_array($lpid,$pids) ) { - $lock = true; - } +if (file_exists($config['install_dir'].'/.alerts.lock')) { + $pids = explode("\n", trim(`ps -e | grep php | awk '{print $1}'`)); + $lpid = trim(file_get_contents($config['install_dir'].'/.alerts.lock')); + if (in_array($lpid, $pids)) { + $lock = true; + } } -if( $lock === true ) { - exit(1); -} else { - file_put_contents($config['install_dir']."/.alerts.lock", getmypid()); +if ($lock === true) { + exit(1); +} +else { + file_put_contents($config['install_dir'].'/.alerts.lock', getmypid()); } -include_once($config['install_dir']."/includes/definitions.inc.php"); -include_once($config['install_dir']."/includes/functions.php"); -include_once($config['install_dir']."/includes/alerts.inc.php"); +require_once $config['install_dir'].'/includes/definitions.inc.php'; +require_once $config['install_dir'].'/includes/functions.php'; +require_once $config['install_dir'].'/includes/alerts.inc.php'; -if( !defined("TEST") ) { - echo "Start: ".date('r')."\r\n"; - echo "RunFollowUp():\r\n"; - RunFollowUp(); - echo "RunAlerts():\r\n"; - RunAlerts(); - echo "RunAcks():\r\n"; - RunAcks(); - echo "End : ".date('r')."\r\n"; +if (!defined('TEST')) { + echo 'Start: '.date('r')."\r\n"; + echo "RunFollowUp():\r\n"; + RunFollowUp(); + echo "RunAlerts():\r\n"; + RunAlerts(); + echo "RunAcks():\r\n"; + RunAcks(); + echo 'End : '.date('r')."\r\n"; } -unlink($config['install_dir']."/.alerts.lock"); +unlink($config['install_dir'].'/.alerts.lock'); + /** * Re-Validate Rule-Mappings - * @param int $device Device-ID - * @param int $rule Rule-ID + * @param integer $device Device-ID + * @param integer $rule Rule-ID * @return boolean */ -function IsRuleValid($device,$rule) { - global $rulescache; - if( empty($rulescache[$device]) || !isset($rulescache[$device]) ) { - foreach( GetRules($device) as $chk ) { - $rulescache[$device][$chk['id']] = true; - } - } - if( $rulescache[$device][$rule] === true ) { - return true; - } - return false; -} +function IsRuleValid($device, $rule) { + global $rulescache; + if (empty($rulescache[$device]) || !isset($rulescache[$device])) { + foreach (GetRules($device) as $chk) { + $rulescache[$device][$chk['id']] = true; + } + } + + if ($rulescache[$device][$rule] === true) { + return true; + } + + return false; + +}//end IsRuleValid() + /** * Issue Alert-Object @@ -83,185 +91,228 @@ function IsRuleValid($device,$rule) { * @return boolean */ function IssueAlert($alert) { - global $config; - if( dbFetchCell('SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = ?',array($alert['device_id'])) == "1" ) { - return true; - } - $default_tpl = "%title\r\nSeverity: %severity\r\n{if %state == 0}Time elapsed: %elapsed\r\n{/if}Timestamp: %timestamp\r\nUnique-ID: %uid\r\nRule: {if %name}%name{else}%rule{/if}\r\n{if %faults}Faults:\r\n{foreach %faults} #%key: %value.string\r\n{/foreach}{/if}Alert sent to: {foreach %contacts}%value <%key> {/foreach}"; //FIXME: Put somewhere else? - if( $config['alert']['fixed-contacts'] == false ) { - $alert['details']['contacts'] = GetContacts($alert['details']['rule']); - } - $obj = DescribeAlert($alert); - if( is_array($obj) ) { - $tpl = dbFetchRow("SELECT `template` FROM `alert_templates` JOIN `alert_template_map` ON `alert_template_map`.`alert_templates_id`=`alert_templates`.`id` WHERE `alert_template_map`.`alert_rule_id`=?", array($alert['rule_id'])); - if( isset($tpl['template']) ) { - $tpl = $tpl['template']; - } else { - $tpl = $default_tpl; - } - echo "Issuing Alert-UID #".$alert['id']."/".$alert['state'].": "; - $msg = FormatAlertTpl($tpl,$obj); - $obj['msg'] = $msg; - if( !empty($config['alert']['transports']) ) { - ExtTransports($obj); - } - echo "\r\n"; - } - return true; -} + global $config; + if (dbFetchCell('SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = ?', array($alert['device_id'])) == '1') { + return true; + } + + $default_tpl = "%title\r\nSeverity: %severity\r\n{if %state == 0}Time elapsed: %elapsed\r\n{/if}Timestamp: %timestamp\r\nUnique-ID: %uid\r\nRule: {if %name}%name{else}%rule{/if}\r\n{if %faults}Faults:\r\n{foreach %faults} #%key: %value.string\r\n{/foreach}{/if}Alert sent to: {foreach %contacts}%value <%key> {/foreach}"; + // FIXME: Put somewhere else? + if ($config['alert']['fixed-contacts'] == false) { + $alert['details']['contacts'] = GetContacts($alert['details']['rule']); + } + + $obj = DescribeAlert($alert); + if (is_array($obj)) { + $tpl = dbFetchRow('SELECT `template` FROM `alert_templates` JOIN `alert_template_map` ON `alert_template_map`.`alert_templates_id`=`alert_templates`.`id` WHERE `alert_template_map`.`alert_rule_id`=?', array($alert['rule_id'])); + if (isset($tpl['template'])) { + $tpl = $tpl['template']; + } + else { + $tpl = $default_tpl; + } + + echo 'Issuing Alert-UID #'.$alert['id'].'/'.$alert['state'].': '; + $msg = FormatAlertTpl($tpl, $obj); + $obj['msg'] = $msg; + if (!empty($config['alert']['transports'])) { + ExtTransports($obj); + } + + echo "\r\n"; + } + + return true; + +}//end IssueAlert() + /** * Issue ACK notification * @return void */ function RunAcks() { - foreach( dbFetchRows("SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state = 2 && alerts.open = 1") as $alert ) { - $tmp = array($alert['rule_id'],$alert['device_id']); - $alert = dbFetchRow("SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1",array($alert['device_id'],$alert['rule_id'])); - if( empty($alert['rule']) || !IsRuleValid($tmp[1],$tmp[0]) ) { - // Alert-Rule does not exist anymore, let's remove the alert-state. - echo "Stale-Rule: #".$tmp[0]."/".$tmp[1]."\r\n"; - dbDelete('alerts','rule_id = ? && device_id = ?',array($tmp[0],$tmp[1])); - continue; - } - $alert['details'] = json_decode(gzuncompress($alert['details']),true); - $alert['state'] = 2; - IssueAlert($alert); - dbUpdate(array('open' => 0),'alerts','rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); - } -} + foreach (dbFetchRows('SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state = 2 && alerts.open = 1') as $alert) { + $tmp = array( + $alert['rule_id'], + $alert['device_id'], + ); + $alert = dbFetchRow('SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1', array($alert['device_id'], $alert['rule_id'])); + if (empty($alert['rule']) || !IsRuleValid($tmp[1], $tmp[0])) { + // Alert-Rule does not exist anymore, let's remove the alert-state. + echo 'Stale-Rule: #'.$tmp[0].'/'.$tmp[1]."\r\n"; + dbDelete('alerts', 'rule_id = ? && device_id = ?', array($tmp[0], $tmp[1])); + continue; + } + + $alert['details'] = json_decode(gzuncompress($alert['details']), true); + $alert['state'] = 2; + IssueAlert($alert); + dbUpdate(array('open' => 0), 'alerts', 'rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); + } + +}//end RunAcks() + /** * Run Follow-Up alerts * @return void */ function RunFollowUp() { - global $config; - foreach( dbFetchRows("SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state != 2 && alerts.state > 0 && alerts.open = 0") as $alert ) { - $tmp = array($alert['rule_id'],$alert['device_id']); - $alert = dbFetchRow("SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1",array($alert['device_id'],$alert['rule_id'])); - if( empty($alert['rule']) || !IsRuleValid($tmp[1],$tmp[0]) ) { - // Alert-Rule does not exist anymore, let's remove the alert-state. - echo "Stale-Rule: #".$tmp[0]."/".$tmp[1]."\r\n"; - dbDelete('alerts','rule_id = ? && device_id = ?',array($tmp[0],$tmp[1])); - continue; - } - $alert['details'] = json_decode(gzuncompress($alert['details']),true); - $rextra = json_decode($alert['extra'],true); - if( $rextra['invert'] ) { - continue; - } - $chk = dbFetchRows(GenSQL($alert['rule']),array($alert['device_id'])); - $o = sizeof($alert['details']['rule']); - $n = sizeof($chk); - $ret = "Alert #".$alert['id']; - $state = 0; - if( $n > $o ) { - $ret .= " Worsens"; - $state = 3; - } elseif( $n < $o ) { - $ret .= " Betters"; - $state = 4; - } - if( $state > 0 ) { - $alert['details']['rule'] = $chk; - if( dbInsert(array('state' => $state, 'device_id' => $alert['device_id'], 'rule_id' => $alert['rule_id'], 'details' => gzcompress(json_encode($alert['details']),9)), 'alert_log') ) { - dbUpdate(array('state' => $state, 'open' => 1, 'alerted' => 1),'alerts','rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); - } - echo $ret." (".$o."/".$n.")\r\n"; - } - } -} + global $config; + foreach (dbFetchRows('SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state != 2 && alerts.state > 0 && alerts.open = 0') as $alert) { + $tmp = array( + $alert['rule_id'], + $alert['device_id'], + ); + $alert = dbFetchRow('SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1', array($alert['device_id'], $alert['rule_id'])); + if (empty($alert['rule']) || !IsRuleValid($tmp[1], $tmp[0])) { + // Alert-Rule does not exist anymore, let's remove the alert-state. + echo 'Stale-Rule: #'.$tmp[0].'/'.$tmp[1]."\r\n"; + dbDelete('alerts', 'rule_id = ? && device_id = ?', array($tmp[0], $tmp[1])); + continue; + } + + $alert['details'] = json_decode(gzuncompress($alert['details']), true); + $rextra = json_decode($alert['extra'], true); + if ($rextra['invert']) { + continue; + } + + $chk = dbFetchRows(GenSQL($alert['rule']), array($alert['device_id'])); + $o = sizeof($alert['details']['rule']); + $n = sizeof($chk); + $ret = 'Alert #'.$alert['id']; + $state = 0; + if ($n > $o) { + $ret .= ' Worsens'; + $state = 3; + } + else if ($n < $o) { + $ret .= ' Betters'; + $state = 4; + } + + if ($state > 0) { + $alert['details']['rule'] = $chk; + if (dbInsert(array('state' => $state, 'device_id' => $alert['device_id'], 'rule_id' => $alert['rule_id'], 'details' => gzcompress(json_encode($alert['details']), 9)), 'alert_log')) { + dbUpdate(array('state' => $state, 'open' => 1, 'alerted' => 1), 'alerts', 'rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); + } + + echo $ret.' ('.$o.'/'.$n.")\r\n"; + } + }//end foreach + +}//end RunFollowUp() + /** * Run all alerts * @return void */ function RunAlerts() { - global $config; - foreach( dbFetchRows("SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state != 2 && alerts.open = 1") as $alert ) { - $tmp = array($alert['rule_id'],$alert['device_id']); - $alert = dbFetchRow("SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1",array($alert['device_id'],$alert['rule_id'])); - if( empty($alert['rule_id']) || !IsRuleValid($tmp[1],$tmp[0]) ) { - echo "Stale-Rule: #".$tmp[0]."/".$tmp[1]."\r\n"; - // Alert-Rule does not exist anymore, let's remove the alert-state. - dbDelete('alerts','rule_id = ? && device_id = ?',array($tmp[0],$tmp[1])); - continue; - } - $alert['details'] = json_decode(gzuncompress($alert['details']),true); - $noiss = false; - $noacc = false; - $updet = false; - $rextra = json_decode($alert['extra'],true); - $chk = dbFetchRow('SELECT alerts.alerted,devices.ignore,devices.disabled FROM alerts,devices WHERE alerts.device_id = ? && devices.device_id = alerts.device_id && alerts.rule_id = ?',array($alert['device_id'],$alert['rule_id'])); - if( $chk['alerted'] == $alert['state'] ) { - $noiss = true; - } - if( !empty($rextra['count']) && empty($rextra['interval']) ) { - // This check below is for compat-reasons - if( !empty($rextra['delay']) ) { - if( (time()-strtotime($alert['time_logged'])+$config['alert']['tolerance-window']) < $rextra['delay'] || (!empty($alert['details']['delay']) && (time()-$alert['details']['delay']+$config['alert']['tolerance-window']) < $rextra['delay']) ) { - continue; - } else { - $alert['details']['delay'] = time(); - $updet = true; - } - } - if( $alert['state'] == 1 && !empty($rextra['count']) && ($rextra['count'] == -1 || $alert['details']['count']++ < $rextra['count']) ) { - if( $alert['details']['count'] < $rextra['count'] ) { - $noacc = true; - } - $updet = true; - $noiss = false; - } + global $config; + foreach (dbFetchRows('SELECT alerts.device_id, alerts.rule_id, alerts.state FROM alerts WHERE alerts.state != 2 && alerts.open = 1') as $alert) { + $tmp = array( + $alert['rule_id'], + $alert['device_id'], + ); + $alert = dbFetchRow('SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1', array($alert['device_id'], $alert['rule_id'])); + if (empty($alert['rule_id']) || !IsRuleValid($tmp[1], $tmp[0])) { + echo 'Stale-Rule: #'.$tmp[0].'/'.$tmp[1]."\r\n"; + // Alert-Rule does not exist anymore, let's remove the alert-state. + dbDelete('alerts', 'rule_id = ? && device_id = ?', array($tmp[0], $tmp[1])); + continue; + } - } else { - // This is the new way - if( !empty($rextra['delay']) && (time()-strtotime($alert['time_logged'])+$config['alert']['tolerance-window']) < $rextra['delay'] ) { - continue; - } - if( !empty($rextra['interval']) ) { - if( !empty($alert['details']['interval']) && (time()-$alert['details']['interval']+$config['alert']['tolerance-window']) < $rextra['interval'] ) { - continue; - } else { - $alert['details']['interval'] = time(); - $updet = true; - } - } - if( $alert['state'] == 1 && !empty($rextra['count']) && ($rextra['count'] == -1 || $alert['details']['count']++ < $rextra['count']) ) { - if( $alert['details']['count'] < $rextra['count'] ) { - $noacc = true; - } - $updet = true; - $noiss = false; - } + $alert['details'] = json_decode(gzuncompress($alert['details']), true); + $noiss = false; + $noacc = false; + $updet = false; + $rextra = json_decode($alert['extra'], true); + $chk = dbFetchRow('SELECT alerts.alerted,devices.ignore,devices.disabled FROM alerts,devices WHERE alerts.device_id = ? && devices.device_id = alerts.device_id && alerts.rule_id = ?', array($alert['device_id'], $alert['rule_id'])); + if ($chk['alerted'] == $alert['state']) { + $noiss = true; + } + + if (!empty($rextra['count']) && empty($rextra['interval'])) { + // This check below is for compat-reasons + if (!empty($rextra['delay'])) { + if ((time() - strtotime($alert['time_logged']) + $config['alert']['tolerance-window']) < $rextra['delay'] || (!empty($alert['details']['delay']) && (time() - $alert['details']['delay'] + $config['alert']['tolerance-window']) < $rextra['delay'])) { + continue; + } + else { + $alert['details']['delay'] = time(); + $updet = true; + } + } + + if ($alert['state'] == 1 && !empty($rextra['count']) && ($rextra['count'] == -1 || $alert['details']['count']++ < $rextra['count'])) { + if ($alert['details']['count'] < $rextra['count']) { + $noacc = true; + } + + $updet = true; + $noiss = false; + } + } + else { + // This is the new way + if (!empty($rextra['delay']) && (time() - strtotime($alert['time_logged']) + $config['alert']['tolerance-window']) < $rextra['delay']) { + continue; + } + + if (!empty($rextra['interval'])) { + if (!empty($alert['details']['interval']) && (time() - $alert['details']['interval'] + $config['alert']['tolerance-window']) < $rextra['interval']) { + continue; + } + else { + $alert['details']['interval'] = time(); + $updet = true; + } + } + + if ($alert['state'] == 1 && !empty($rextra['count']) && ($rextra['count'] == -1 || $alert['details']['count']++ < $rextra['count'])) { + if ($alert['details']['count'] < $rextra['count']) { + $noacc = true; + } + + $updet = true; + $noiss = false; + } + }//end if + if ($chk['ignore'] == 1 || $chk['disabled'] == 1) { + $noiss = true; + $updet = false; + $noacc = false; + } + + if (IsMaintenance($alert['device_id']) > 0) { + $noiss = true; + $noacc = true; + } + + if ($updet) { + dbUpdate(array('details' => gzcompress(json_encode($alert['details']), 9)), 'alert_log', 'id = ?', array($alert['id'])); + } + + if (!empty($rextra['mute'])) { + echo 'Muted Alert-UID #'.$alert['id']."\r\n"; + $noiss = true; + } + + if (!$noiss) { + IssueAlert($alert); + dbUpdate(array('alerted' => $alert['state']), 'alerts', 'rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); + } + + if (!$noacc) { + dbUpdate(array('open' => 0), 'alerts', 'rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); + } + }//end foreach + +}//end RunAlerts() - } - if( $chk['ignore'] == 1 || $chk['disabled'] == 1 ) { - $noiss = true; - $updet = false; - $noacc = false; - } - if( IsMaintenance($alert['device_id']) > 0 ) { - $noiss = true; - $noacc = true; - } - if( $updet ) { - dbUpdate(array('details' => gzcompress(json_encode($alert['details']),9)),'alert_log','id = ?',array($alert['id'])); - } - if( !empty($rextra['mute']) ) { - echo "Muted Alert-UID #".$alert['id']."\r\n"; - $noiss = true; - } - if( !$noiss ) { - IssueAlert($alert); - dbUpdate(array('alerted' => $alert['state']),'alerts','rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); - } - if( !$noacc ) { - dbUpdate(array('open' => 0),'alerts','rule_id = ? && device_id = ?', array($alert['rule_id'], $alert['device_id'])); - } - } -} /** * Run external transports @@ -269,24 +320,29 @@ function RunAlerts() { * @return void */ function ExtTransports($obj) { - global $config; - $tmp = false; //To keep scrutinizer from naging because it doesnt understand eval - foreach( $config['alert']['transports'] as $transport=>$opts ) { - if( ($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir']."/includes/alerts/transport.".$transport.".php") ) { - echo $transport." => "; - eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir']."/includes/alerts/transport.".$transport.".php").' };'); - $tmp = $tmp($obj,$opts); - if( $tmp ) { - echo "OK"; - log_event("Issued ".$obj['severity']." alert for rule '".$obj['name']."' to transport '".$transport."'",$obj['device_id']); - } else { - echo "ERROR"; - log_event("Could not issue ".$obj['severity']." alert for rule '".$obj['name']."' to transport '".$transport."'",$obj['device_id']); - } - } - echo "; "; - } -} + global $config; + $tmp = false; + // To keep scrutinizer from naging because it doesnt understand eval + foreach ($config['alert']['transports'] as $transport => $opts) { + if (($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php')) { + echo $transport.' => '; + eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' };'); + $tmp = $tmp($obj,$opts); + if ($tmp) { + echo 'OK'; + log_event('Issued '.$obj['severity']." alert for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']); + } + else { + echo 'ERROR'; + log_event('Could not issue '.$obj['severity']." alert for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']); + } + } + + echo '; '; + } + +}//end ExtTransports() + /** * Format Alert @@ -294,52 +350,69 @@ function ExtTransports($obj) { * @param array $obj Alert-Array * @return string */ -function FormatAlertTpl($tpl,$obj) { - $msg = '$ret .= "'.str_replace(array("{else}","{/if}","{/foreach}"),array('"; } else { $ret .= "','"; } $ret .= "','"; } $ret .= "'),addslashes($tpl)).'";'; - $parsed = $msg; - $s = strlen($msg); - $x = $pos = -1; - $buff = ""; - $if = $for = false; - while( ++$x < $s ) { - if( $msg[$x] == "{" && $buff == "" ) { - $buff .= $msg[$x]; - } elseif( $buff == "{ " ) { - $buff = ""; - } elseif( $buff != "" ) { - $buff .= $msg[$x]; - } - if( $buff == "{if" ) { - $pos = $x; - $if = true; - } elseif( $buff == "{foreach" ) { - $pos = $x; - $for = true; - } - if( $pos != -1 && $msg[$x] == "}" ) { - $orig = $buff; - $buff = ""; - $pos = -1; - if( $if ) { - $if = false; - $o = 3; - $native = array('"; if( ',' ) { $ret .= "'); - } elseif( $for ) { - $for = false; - $o = 8; - $native = array('"; foreach( ',' as $key=>$value) { $ret .= "'); - } else { - continue; - } - $cond = trim(populate(substr($orig,$o,-1),false)); - $native = $native[0].$cond.$native[1]; - $parsed = str_replace($orig,$native,$parsed); - unset($cond, $o, $orig, $native); - } - } - $parsed = populate($parsed); - return RunJail($parsed,$obj); -} +function FormatAlertTpl($tpl, $obj) { + $msg = '$ret .= "'.str_replace(array('{else}', '{/if}', '{/foreach}'), array('"; } else { $ret .= "', '"; } $ret .= "', '"; } $ret .= "'), addslashes($tpl)).'";'; + $parsed = $msg; + $s = strlen($msg); + $x = $pos = -1; + $buff = ''; + $if = $for = false; + while (++$x < $s) { + if ($msg[$x] == '{' && $buff == '') { + $buff .= $msg[$x]; + } + else if ($buff == '{ ') { + $buff = ''; + } + else if ($buff != '') { + $buff .= $msg[$x]; + } + + if ($buff == '{if') { + $pos = $x; + $if = true; + } + else if ($buff == '{foreach') { + $pos = $x; + $for = true; + } + + if ($pos != -1 && $msg[$x] == '}') { + $orig = $buff; + $buff = ''; + $pos = -1; + if ($if) { + $if = false; + $o = 3; + $native = array( + '"; if( ', + ' ) { $ret .= "', + ); + } + else if ($for) { + $for = false; + $o = 8; + $native = array( + '"; foreach( ', + ' as $key=>$value) { $ret .= "', + ); + } + else { + continue; + } + + $cond = trim(populate(substr($orig, $o, -1), false)); + $native = $native[0].$cond.$native[1]; + $parsed = str_replace($orig, $native, $parsed); + unset($cond, $o, $orig, $native); + }//end if + }//end while + + $parsed = populate($parsed); + return RunJail($parsed, $obj); + +}//end FormatAlertTpl() + /** * Describe Alert @@ -347,119 +420,138 @@ function FormatAlertTpl($tpl,$obj) { * @return array */ function DescribeAlert($alert) { - $obj = array(); - $i = 0; - $device = dbFetchRow("SELECT hostname FROM devices WHERE device_id = ?",array($alert['device_id'])); - $obj['hostname'] = $device['hostname']; - $obj['device_id'] = $alert['device_id']; - $extra = $alert['details']; - if( $alert['state'] >= 1 ) { - $obj['title'] = 'Alert for device '.$device['hostname'].' - '.($alert['name'] ? $alert['name'] : $alert['rule']); - if( $alert['state'] == 2 ) { - $obj['title'] .= " got acknowledged"; - } elseif( $alert['state'] == 3 ) { - $obj['title'] .= " got worse"; - } elseif( $alert['state'] == 4 ) { - $obj['title'] .= " got better"; - } - foreach( $extra['rule'] as $incident ) { - $i++; - $obj['faults'][$i] = $incident; - foreach( $incident as $k=>$v ) { - if( !empty($v) && $k != 'device_id' && (stristr($k,'id') || stristr($k,'desc') || stristr($k,'msg')) && substr_count($k,'_') <= 1 ) { - $obj['faults'][$i]['string'] .= $k.' => '.$v."; "; - } - } - } - } elseif( $alert['state'] == 0 ) { - $id = dbFetchRow("SELECT alert_log.id,alert_log.time_logged,alert_log.details FROM alert_log WHERE alert_log.state != 2 && alert_log.state != 0 && alert_log.rule_id = ? && alert_log.device_id = ? && alert_log.id < ? ORDER BY id DESC LIMIT 1", array($alert['rule_id'],$alert['device_id'],$alert['id'])); - if( empty($id['id']) ) { - return false; - } - $extra = json_decode(gzuncompress($id['details']),true); - $obj['title'] = 'Device '.$device['hostname'].' recovered from '.($alert['name'] ? $alert['name'] : $alert['rule']); - $obj['elapsed'] = TimeFormat(strtotime($alert['time_logged'])-strtotime($id['time_logged'])); - $obj['id'] = $id['id']; - $obj['faults'] = false; - } else { - return "Unknown State"; - } - $obj['uid'] = $alert['id']; - $obj['severity'] = $alert['severity']; - $obj['rule'] = $alert['rule']; - $obj['name'] = $alert['name']; - $obj['timestamp'] = $alert['time_logged']; - $obj['contacts'] = $extra['contacts']; - $obj['state'] = $alert['state']; - return $obj; -} + $obj = array(); + $i = 0; + $device = dbFetchRow('SELECT hostname FROM devices WHERE device_id = ?', array($alert['device_id'])); + $obj['hostname'] = $device['hostname']; + $obj['device_id'] = $alert['device_id']; + $extra = $alert['details']; + if ($alert['state'] >= 1) { + $obj['title'] = 'Alert for device '.$device['hostname'].' - '.($alert['name'] ? $alert['name'] : $alert['rule']); + if ($alert['state'] == 2) { + $obj['title'] .= ' got acknowledged'; + } + else if ($alert['state'] == 3) { + $obj['title'] .= ' got worse'; + } + else if ($alert['state'] == 4) { + $obj['title'] .= ' got better'; + } + + foreach ($extra['rule'] as $incident) { + $i++; + $obj['faults'][$i] = $incident; + foreach ($incident as $k => $v) { + if (!empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1) { + $obj['faults'][$i]['string'] .= $k.' => '.$v.'; '; + } + } + } + } + else if ($alert['state'] == 0) { + $id = dbFetchRow('SELECT alert_log.id,alert_log.time_logged,alert_log.details FROM alert_log WHERE alert_log.state != 2 && alert_log.state != 0 && alert_log.rule_id = ? && alert_log.device_id = ? && alert_log.id < ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id'], $alert['id'])); + if (empty($id['id'])) { + return false; + } + + $extra = json_decode(gzuncompress($id['details']), true); + $obj['title'] = 'Device '.$device['hostname'].' recovered from '.($alert['name'] ? $alert['name'] : $alert['rule']); + $obj['elapsed'] = TimeFormat(strtotime($alert['time_logged']) - strtotime($id['time_logged'])); + $obj['id'] = $id['id']; + $obj['faults'] = false; + } + else { + return 'Unknown State'; + }//end if + $obj['uid'] = $alert['id']; + $obj['severity'] = $alert['severity']; + $obj['rule'] = $alert['rule']; + $obj['name'] = $alert['name']; + $obj['timestamp'] = $alert['time_logged']; + $obj['contacts'] = $extra['contacts']; + $obj['state'] = $alert['state']; + return $obj; + +}//end DescribeAlert() + /** * Format Elapsed Time - * @param int $secs Seconds elapsed + * @param integer $secs Seconds elapsed * @return string */ -function TimeFormat($secs){ - $bit = array( - 'y' => $secs / 31556926 % 12, - 'w' => $secs / 604800 % 52, - 'd' => $secs / 86400 % 7, - 'h' => $secs / 3600 % 24, - 'm' => $secs / 60 % 60, - 's' => $secs % 60 - ); - $ret = array(); - foreach($bit as $k => $v){ - if($v > 0) { - $ret[] = $v . $k; - } - } - if( empty($ret) ) { - return "none"; - } - return join(' ', $ret); -} +function TimeFormat($secs) { + $bit = array( + 'y' => $secs / 31556926 % 12, + 'w' => $secs / 604800 % 52, + 'd' => $secs / 86400 % 7, + 'h' => $secs / 3600 % 24, + 'm' => $secs / 60 % 60, + 's' => $secs % 60, + ); + $ret = array(); + foreach ($bit as $k => $v) { + if ($v > 0) { + $ret[] = $v.$k; + } + } + + if (empty($ret)) { + return 'none'; + } + + return join(' ', $ret); + +}//end TimeFormat() + /** * "Safely" run eval * @param string $code Code to run - * @param array $obj Object with variables + * @param array $obj Object with variables * @return string|mixed */ -function RunJail($code,$obj) { - $ret = ""; - eval($code); - return $ret; -} +function RunJail($code, $obj) { + $ret = ''; + eval($code); + return $ret; + +}//end RunJail() + /** * Populate variables - * @param string $txt Text with variables - * @param bool $wrap Wrap variable for text-usage (default: true) + * @param string $txt Text with variables + * @param boolean $wrap Wrap variable for text-usage (default: true) * @return string */ -function populate($txt,$wrap=true) { - preg_match_all('/%([\w\.]+)/', $txt, $m); - foreach( $m[1] as $tmp ) { - $orig = $tmp; - $rep = false; - if( $tmp == "key" || $tmp == "value" ) { - $rep = '$'.$tmp; - } else { - if( strstr($tmp,'.') ) { - $tmp = explode('.',$tmp,2); - $pre = '$'.$tmp[0]; - $tmp = $tmp[1]; - } else { - $pre = '$obj'; - } - $rep = $pre."['".str_replace('.',"']['",$tmp)."']"; - if( $wrap ) { - $rep = "{".$rep."}"; - } - } - $txt = str_replace("%".$orig,$rep,$txt); - } - return $txt; -} -?> +function populate($txt, $wrap=true) { + preg_match_all('/%([\w\.]+)/', $txt, $m); + foreach ($m[1] as $tmp) { + $orig = $tmp; + $rep = false; + if ($tmp == 'key' || $tmp == 'value') { + $rep = '$'.$tmp; + } + else { + if (strstr($tmp, '.')) { + $tmp = explode('.', $tmp, 2); + $pre = '$'.$tmp[0]; + $tmp = $tmp[1]; + } + else { + $pre = '$obj'; + } + + $rep = $pre."['".str_replace('.', "']['", $tmp)."']"; + if ($wrap) { + $rep = '{'.$rep.'}'; + } + } + + $txt = str_replace('%'.$orig, $rep, $txt); + }//end foreach + + return $txt; + +}//end populate() diff --git a/billing-calculate.php b/billing-calculate.php index 6895083fb4..e89e65675a 100755 --- a/billing-calculate.php +++ b/billing-calculate.php @@ -10,136 +10,139 @@ * @subpackage billing * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ chdir(dirname($argv[0])); -include("includes/defaults.inc.php"); -include("config.php"); -include("includes/definitions.inc.php"); -include("includes/functions.php"); +require 'includes/defaults.inc.php'; +require 'config.php'; +require 'includes/definitions.inc.php'; +require 'includes/functions.php'; -$options = getopt("r"); +$options = getopt('r'); -if (isset($options['r'])) { echo("Clearing history table.\n"); dbQuery("TRUNCATE TABLE `bill_history`"); } - -foreach (dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_id`") as $bill) -{ - echo(str_pad($bill['bill_id']." ".$bill['bill_name'], 30)." \n"); - - $i=0; - while ($i <= 24) - { - unset($class); - unset($rate_data); - $day_data = getDates($bill['bill_day'], $i); - - $datefrom = $day_data['0']; - $dateto = $day_data['1']; - - $check = dbFetchRow("SELECT * FROM `bill_history` WHERE bill_id = ? AND bill_datefrom = ? AND bill_dateto = ? LIMIT 1", array($bill['bill_id'], $datefrom, $dateto)); - - $period = getPeriod($bill['bill_id'],$datefrom,$dateto); - - $date_updated = str_replace("-", "", str_replace(":", "", str_replace(" ", "", $check['updated']))); - - if ($period > 0 && $dateto > $date_updated) - { - $rate_data = getRates($bill['bill_id'],$datefrom,$dateto); - $rate_95th = $rate_data['rate_95th']; - $dir_95th = $rate_data['dir_95th']; - $total_data = $rate_data['total_data']; - $rate_average = $rate_data['rate_average']; - - if ($bill['bill_type'] == "cdr") - { - $type = "CDR"; - $allowed = $bill['bill_cdr']; - $used = $rate_data['rate_95th']; - $allowed_text = format_si($allowed)."bps"; - $used_text = format_si($used)."bps"; - $overuse = $used - $allowed; - $overuse = (($overuse <= 0) ? "0" : $overuse); - $percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100,2); - } elseif ($bill['bill_type'] == "quota") { - $type = "Quota"; - $allowed = $bill['bill_quota']; - $used = $rate_data['total_data']; - $allowed_text = format_bytes_billing($allowed); - $used_text = format_bytes_billing($used); - $overuse = $used - $allowed; - $overuse = (($overuse <= 0) ? "0" : $overuse); - $percent = round(($rate_data['total_data'] / $bill['bill_quota']) * 100,2); - } - - echo(strftime("%x @ %X", strtotime($datefrom))." to ".strftime("%x @ %X", strtotime($dateto))." ".str_pad($type,8)." ".str_pad($allowed_text,10)." ".str_pad($used_text,10)." ".$percent."%"); - - if ($i == '0') - { - $update = array('rate_95th' => $rate_data['rate_95th'], - 'rate_95th_in' => $rate_data['rate_95th_in'], - 'rate_95th_out' => $rate_data['rate_95th_out'], - 'dir_95th' => $rate_data['dir_95th'], - 'total_data' => $rate_data['total_data'], - 'total_data_in' => $rate_data['total_data_in'], - 'total_data_out' => $rate_data['total_data_out'], - 'rate_average' => $rate_data['rate_average'], - 'rate_average_in' => $rate_data['rate_average_in'], - 'rate_average_out' => $rate_data['rate_average_out'], - 'bill_last_calc' => array('NOW()') ); - - dbUpdate($update, 'bills', '`bill_id` = ?', array($bill['bill_id'])); - echo(" Updated! "); - } - - if ($check['bill_id'] == $bill['bill_id']) - { - $update = array('rate_95th' => $rate_data['rate_95th'], - 'rate_95th_in' => $rate_data['rate_95th_in'], - 'rate_95th_out' => $rate_data['rate_95th_out'], - 'dir_95th' => $rate_data['dir_95th'], - 'rate_average' => $rate_data['rate_average'], - 'rate_average_in' => $rate_data['rate_average_in'], - 'rate_average_out' => $rate_data['rate_average_out'], - 'traf_total' => $rate_data['total_data'], - 'traf_in' => $rate_data['total_data_in'], - 'traf_out' => $rate_data['total_data_out'], - 'bill_used' => $used, - 'bill_overuse' => $overuse, - 'bill_percent' => $percent, - 'updated' => array('NOW()')); - - dbUpdate($update, 'bill_history', '`bill_hist_id` = ?', array($check['bill_hist_id'])); - echo(" Updated history! "); - } else { - $update = array('rate_95th' => $rate_data['rate_95th'], - 'rate_95th_in' => $rate_data['rate_95th_in'], - 'rate_95th_out' => $rate_data['rate_95th_out'], - 'dir_95th' => $rate_data['dir_95th'], - 'rate_average' => $rate_data['rate_average'], - 'rate_average_in' => $rate_data['rate_average_in'], - 'rate_average_out' => $rate_data['rate_average_out'], - 'traf_total' => $rate_data['total_data'], - 'traf_in' => $rate_data['total_data_in'], - 'traf_out' => $rate_data['total_data_out'], - 'bill_datefrom' => $datefrom, - 'bill_dateto' => $dateto, - 'bill_type' => $type, - 'bill_allowed' => $allowed, - 'bill_used' => $used, - 'bill_overuse' => $overuse, - 'bill_percent' => $percent, - 'bill_datefrom' => $datefrom, - 'bill_dateto' => $dateto, - 'bill_id' => $bill['bill_id'] ); - dbInsert($update, 'bill_history'); - echo(" Generated history! "); - } - echo("\n\n"); - } - $i++; - } +if (isset($options['r'])) { + echo "Clearing history table.\n"; + dbQuery('TRUNCATE TABLE `bill_history`'); } -?> +foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) { + echo str_pad($bill['bill_id'].' '.$bill['bill_name'], 30)." \n"; + + $i = 0; + while ($i <= 24) { + unset($class); + unset($rate_data); + $day_data = getDates($bill['bill_day'], $i); + + $datefrom = $day_data['0']; + $dateto = $day_data['1']; + + $check = dbFetchRow('SELECT * FROM `bill_history` WHERE bill_id = ? AND bill_datefrom = ? AND bill_dateto = ? LIMIT 1', array($bill['bill_id'], $datefrom, $dateto)); + + $period = getPeriod($bill['bill_id'], $datefrom, $dateto); + + $date_updated = str_replace('-', '', str_replace(':', '', str_replace(' ', '', $check['updated']))); + + if ($period > 0 && $dateto > $date_updated) { + $rate_data = getRates($bill['bill_id'], $datefrom, $dateto); + $rate_95th = $rate_data['rate_95th']; + $dir_95th = $rate_data['dir_95th']; + $total_data = $rate_data['total_data']; + $rate_average = $rate_data['rate_average']; + + if ($bill['bill_type'] == 'cdr') { + $type = 'CDR'; + $allowed = $bill['bill_cdr']; + $used = $rate_data['rate_95th']; + $allowed_text = format_si($allowed).'bps'; + $used_text = format_si($used).'bps'; + $overuse = ($used - $allowed); + $overuse = (($overuse <= 0) ? '0' : $overuse); + $percent = round((($rate_data['rate_95th'] / $bill['bill_cdr']) * 100), 2); + } + else if ($bill['bill_type'] == 'quota') { + $type = 'Quota'; + $allowed = $bill['bill_quota']; + $used = $rate_data['total_data']; + $allowed_text = format_bytes_billing($allowed); + $used_text = format_bytes_billing($used); + $overuse = ($used - $allowed); + $overuse = (($overuse <= 0) ? '0' : $overuse); + $percent = round((($rate_data['total_data'] / $bill['bill_quota']) * 100), 2); + } + + echo strftime('%x @ %X', strtotime($datefrom)).' to '.strftime('%x @ %X', strtotime($dateto)).' '.str_pad($type, 8).' '.str_pad($allowed_text, 10).' '.str_pad($used_text, 10).' '.$percent.'%'; + + if ($i == '0') { + $update = array( + 'rate_95th' => $rate_data['rate_95th'], + 'rate_95th_in' => $rate_data['rate_95th_in'], + 'rate_95th_out' => $rate_data['rate_95th_out'], + 'dir_95th' => $rate_data['dir_95th'], + 'total_data' => $rate_data['total_data'], + 'total_data_in' => $rate_data['total_data_in'], + 'total_data_out' => $rate_data['total_data_out'], + 'rate_average' => $rate_data['rate_average'], + 'rate_average_in' => $rate_data['rate_average_in'], + 'rate_average_out' => $rate_data['rate_average_out'], + 'bill_last_calc' => array('NOW()'), + ); + + dbUpdate($update, 'bills', '`bill_id` = ?', array($bill['bill_id'])); + echo ' Updated! '; + } + + if ($check['bill_id'] == $bill['bill_id']) { + $update = array( + 'rate_95th' => $rate_data['rate_95th'], + 'rate_95th_in' => $rate_data['rate_95th_in'], + 'rate_95th_out' => $rate_data['rate_95th_out'], + 'dir_95th' => $rate_data['dir_95th'], + 'rate_average' => $rate_data['rate_average'], + 'rate_average_in' => $rate_data['rate_average_in'], + 'rate_average_out' => $rate_data['rate_average_out'], + 'traf_total' => $rate_data['total_data'], + 'traf_in' => $rate_data['total_data_in'], + 'traf_out' => $rate_data['total_data_out'], + 'bill_used' => $used, + 'bill_overuse' => $overuse, + 'bill_percent' => $percent, + 'updated' => array('NOW()'), + ); + + dbUpdate($update, 'bill_history', '`bill_hist_id` = ?', array($check['bill_hist_id'])); + echo ' Updated history! '; + } + else { + $update = array( + 'rate_95th' => $rate_data['rate_95th'], + 'rate_95th_in' => $rate_data['rate_95th_in'], + 'rate_95th_out' => $rate_data['rate_95th_out'], + 'dir_95th' => $rate_data['dir_95th'], + 'rate_average' => $rate_data['rate_average'], + 'rate_average_in' => $rate_data['rate_average_in'], + 'rate_average_out' => $rate_data['rate_average_out'], + 'traf_total' => $rate_data['total_data'], + 'traf_in' => $rate_data['total_data_in'], + 'traf_out' => $rate_data['total_data_out'], + 'bill_datefrom' => $datefrom, + 'bill_dateto' => $dateto, + 'bill_type' => $type, + 'bill_allowed' => $allowed, + 'bill_used' => $used, + 'bill_overuse' => $overuse, + 'bill_percent' => $percent, + 'bill_datefrom' => $datefrom, + 'bill_dateto' => $dateto, + 'bill_id' => $bill['bill_id'], + ); + dbInsert($update, 'bill_history'); + echo ' Generated history! '; + }//end if + echo "\n\n"; + }//end if + + $i++; + }//end while +}//end foreach diff --git a/build-base.php b/build-base.php index f3b04f67c2..8f631c365a 100644 --- a/build-base.php +++ b/build-base.php @@ -2,43 +2,40 @@ // MYSQL Check - FIXME // 1 UNKNOWN - -include( "config.php" ); +require 'config.php'; if (!isset($sql_file)) { - $sql_file = 'build.sql'; -} -$sql_fh = fopen( $sql_file, 'r' ); -if ($sql_fh === FALSE) { - echo( "ERROR: Cannot open SQL build script " . $sql_file . "\n" ); - exit(1); + $sql_file = 'build.sql'; } -$connection = mysql_connect( $config['db_host'], $config['db_user'], $config['db_pass'] ); -if ($connection === FALSE) { - echo( "ERROR: Cannot connect to database: " . mysql_error() . "\n" ); - exit(1); +$sql_fh = fopen($sql_file, 'r'); +if ($sql_fh === false) { + echo 'ERROR: Cannot open SQL build script '.$sql_file."\n"; + exit(1); } -$select = mysql_select_db( $config['db_name'] ); -if ($select === FALSE) { - echo( "ERROR: Cannot select database: " . mysql_error() . "\n" ); - exit(1); +$connection = mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']); +if ($connection === false) { + echo 'ERROR: Cannot connect to database: '.mysql_error()."\n"; + exit(1); } -while( !feof( $sql_fh ) ) { - $line = fgetss( $sql_fh ); - if(!empty($line)) - { - $creation = mysql_query( $line ); - if( !$creation ) { - echo( "WARNING: Cannot execute query (" . $line . "): " . mysql_error() . "\n" ); +$select = mysql_select_db($config['db_name']); +if ($select === false) { + echo 'ERROR: Cannot select database: '.mysql_error()."\n"; + exit(1); +} + +while (!feof($sql_fh)) { + $line = fgetss($sql_fh); + if (!empty($line)) { + $creation = mysql_query($line); + if (!$creation) { + echo 'WARNING: Cannot execute query ('.$line.'): '.mysql_error()."\n"; + } } - } } fclose($sql_fh); -include("includes/sql-schema/update.php"); - -?> +require 'includes/sql-schema/update.php'; diff --git a/callback.php b/callback.php index 1b0e138fb4..bc4517f410 100644 --- a/callback.php +++ b/callback.php @@ -14,68 +14,74 @@ $enabled = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'"); if ($enabled == 1) { - if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") == '') { - dbInsert(array('name'=>'uuid','value'=>guidv4(openssl_random_pseudo_bytes(16))), 'callback'); + dbInsert(array('name' => 'uuid', 'value' => guidv4(openssl_random_pseudo_bytes(16))), 'callback'); } + $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'"); $queries = array( - 'alert_rules'=>'SELECT COUNT(`severity`) AS `total`,`severity` FROM `alert_rules` WHERE `disabled`=0 GROUP BY `severity`', - 'alert_templates'=>'SELECT COUNT(`id`) AS `total` FROM `alert_templates`', - 'api_tokens'=>'SELECT COUNT(`id`) AS `total` FROM `api_tokens` WHERE `disabled`=0', - 'applications'=>'SELECT COUNT(`app_type`) AS `total`,`app_type` FROM `applications` GROUP BY `app_type`', - 'bgppeer_state'=>'SELECT COUNT(`bgpPeerState`) AS `total`,`bgpPeerState` FROM `bgpPeers` GROUP BY `bgpPeerState`', - 'bgppeer_status'=>'SELECT COUNT(`bgpPeerAdminStatus`) AS `total`,`bgpPeerAdminStatus` FROM `bgpPeers` GROUP BY `bgpPeerAdminStatus`', - 'bills'=>'SELECT COUNT(`bill_type`) AS `total`,`bill_type` FROM `bills` GROUP BY `bill_type`', - 'cef'=>'SELECT COUNT(`device_id`) AS `total` FROM `cef_switching`', - 'cisco_asa'=>'SELECT COUNT(`oid`) AS `total`,`oid` FROM `ciscoASA` WHERE `disabled` = 0 GROUP BY `oid`', - 'mempool'=>'SELECT COUNT(`cmpName`) AS `total`,`cmpName` FROM `cmpMemPool` GROUP BY `cmpName`', - 'current'=>'SELECT COUNT(`current_type`) AS `total`,`current_type` FROM `current` GROUP BY `current_type`', - 'dbschema'=>'SELECT COUNT(`version`) AS `total`, `version` FROM `dbSchema`', - 'snmp_version'=>'SELECT COUNT(`snmpver`) AS `total`,`snmpver` FROM `devices` GROUP BY `snmpver`', - 'os'=>'SELECT COUNT(`os`) AS `total`,`os` FROM `devices` GROUP BY `os`', - 'type'=>'SELECT COUNT(`type`) AS `total`,`type` FROM `devices` GROUP BY `type`', - 'hardware'=>'SELECT COUNT(`device_id`) AS `total`, `hardware` FROM `devices` GROUP BY `hardware`', - 'ipsec'=>'SELECT COUNT(`device_id`) AS `total` FROM `ipsec_tunnels`', - 'ipv4_addresses'=>'SELECT COUNT(`ipv4_address_id`) AS `total` FROM `ipv4_addresses`', - 'ipv4_macaddress'=>'SELECT COUNT(`port_id`) AS `total` FROM ipv4_mac', - 'ipv4_networks'=>'SELECT COUNT(`ipv4_network_id`) AS `total` FROM ipv4_networks', - 'ipv6_addresses'=>'SELECT COUNT(`ipv6_address_id`) AS `total` FROM `ipv6_addresses`', - 'ipv6_networks'=>'SELECT COUNT(`ipv6_network_id`) AS `total` FROM `ipv6_networks`', - 'xdp'=>'SELECT COUNT(`id`) AS `total`,`protocol` FROM `links` GROUP BY `protocol`', - 'ospf'=>'SELECT COUNT(`device_id`) AS `total`,`ospfVersionNumber` FROM `ospf_instances` GROUP BY `ospfVersionNumber`', - 'ospf_links'=>'SELECT COUNT(`device_id`) AS `total`,`ospfIfType` FROM `ospf_ports` GROUP BY `ospfIfType`', - 'arch'=>'SELECT COUNT(`pkg_id`) AS `total`,`arch` FROM `packages` GROUP BY `arch`', - 'pollers'=>'SELECT COUNT(`id`) AS `total` FROM `pollers`', - 'port_type'=>'SELECT COUNT(`port_id`) AS `total`,`ifType` FROM `ports` GROUP BY `ifType`', - 'port_ifspeed'=>'SELECT COUNT(`ifSpeed`) AS `total`,ROUND(`ifSpeed`/1000/1000) FROM `ports` GROUP BY `ifSpeed`', - 'port_vlans'=>'SELECT COUNT(`device_id`) AS `total`,`state` FROM `ports_vlans` GROUP BY `state`', - 'processes'=>'SELECT COUNT(`device_id`) AS `total` FROM `processes`', - 'processors'=>'SELECT COUNT(`processor_id`) AS `total`,`processor_type` FROM `processors` GROUP BY `processor_type`', - 'pseudowires'=>'SELECT COUNT(`pseudowire_id`) AS `total` FROM `pseudowires`', - 'sensors'=>'SELECT COUNT(`sensor_id`) AS `total`,`sensor_class` FROM `sensors` GROUP BY `sensor_class`', - 'storage'=>'SELECT COUNT(`storage_id`) AS `total`,`storage_type` FROM `storage` GROUP BY `storage_type`', - 'toner'=>'SELECT COUNT(`toner_id`) AS `total`,`toner_type` FROM `toner` GROUP BY `toner_type`', - 'vlans'=>'SELECT COUNT(`vlan_id`) AS `total`,`vlan_type` FROM `vlans` GROUP BY `vlan_type`', - 'vminfo'=>'SELECT COUNT(`id`) AS `total`,`vm_type` FROM `vminfo` GROUP BY `vm_type`', - 'vmware'=>'SELECT COUNT(`id`) AS `total` FROM `vmware_vminfo`', - 'vrfs'=>'SELECT COUNT(`vrf_id`) AS `total` FROM `vrfs`', - 'mysql_version'=>'SELECT 1 AS `total`, @@version AS `version`',); + 'alert_rules' => 'SELECT COUNT(`severity`) AS `total`,`severity` FROM `alert_rules` WHERE `disabled`=0 GROUP BY `severity`', + 'alert_templates' => 'SELECT COUNT(`id`) AS `total` FROM `alert_templates`', + 'api_tokens' => 'SELECT COUNT(`id`) AS `total` FROM `api_tokens` WHERE `disabled`=0', + 'applications' => 'SELECT COUNT(`app_type`) AS `total`,`app_type` FROM `applications` GROUP BY `app_type`', + 'bgppeer_state' => 'SELECT COUNT(`bgpPeerState`) AS `total`,`bgpPeerState` FROM `bgpPeers` GROUP BY `bgpPeerState`', + 'bgppeer_status' => 'SELECT COUNT(`bgpPeerAdminStatus`) AS `total`,`bgpPeerAdminStatus` FROM `bgpPeers` GROUP BY `bgpPeerAdminStatus`', + 'bills' => 'SELECT COUNT(`bill_type`) AS `total`,`bill_type` FROM `bills` GROUP BY `bill_type`', + 'cef' => 'SELECT COUNT(`device_id`) AS `total` FROM `cef_switching`', + 'cisco_asa' => 'SELECT COUNT(`oid`) AS `total`,`oid` FROM `ciscoASA` WHERE `disabled` = 0 GROUP BY `oid`', + 'mempool' => 'SELECT COUNT(`cmpName`) AS `total`,`cmpName` FROM `cmpMemPool` GROUP BY `cmpName`', + 'current' => 'SELECT COUNT(`current_type`) AS `total`,`current_type` FROM `current` GROUP BY `current_type`', + 'dbschema' => 'SELECT COUNT(`version`) AS `total`, `version` FROM `dbSchema`', + 'snmp_version' => 'SELECT COUNT(`snmpver`) AS `total`,`snmpver` FROM `devices` GROUP BY `snmpver`', + 'os' => 'SELECT COUNT(`os`) AS `total`,`os` FROM `devices` GROUP BY `os`', + 'type' => 'SELECT COUNT(`type`) AS `total`,`type` FROM `devices` GROUP BY `type`', + 'hardware' => 'SELECT COUNT(`device_id`) AS `total`, `hardware` FROM `devices` GROUP BY `hardware`', + 'ipsec' => 'SELECT COUNT(`device_id`) AS `total` FROM `ipsec_tunnels`', + 'ipv4_addresses' => 'SELECT COUNT(`ipv4_address_id`) AS `total` FROM `ipv4_addresses`', + 'ipv4_macaddress' => 'SELECT COUNT(`port_id`) AS `total` FROM ipv4_mac', + 'ipv4_networks' => 'SELECT COUNT(`ipv4_network_id`) AS `total` FROM ipv4_networks', + 'ipv6_addresses' => 'SELECT COUNT(`ipv6_address_id`) AS `total` FROM `ipv6_addresses`', + 'ipv6_networks' => 'SELECT COUNT(`ipv6_network_id`) AS `total` FROM `ipv6_networks`', + 'xdp' => 'SELECT COUNT(`id`) AS `total`,`protocol` FROM `links` GROUP BY `protocol`', + 'ospf' => 'SELECT COUNT(`device_id`) AS `total`,`ospfVersionNumber` FROM `ospf_instances` GROUP BY `ospfVersionNumber`', + 'ospf_links' => 'SELECT COUNT(`device_id`) AS `total`,`ospfIfType` FROM `ospf_ports` GROUP BY `ospfIfType`', + 'arch' => 'SELECT COUNT(`pkg_id`) AS `total`,`arch` FROM `packages` GROUP BY `arch`', + 'pollers' => 'SELECT COUNT(`id`) AS `total` FROM `pollers`', + 'port_type' => 'SELECT COUNT(`port_id`) AS `total`,`ifType` FROM `ports` GROUP BY `ifType`', + 'port_ifspeed' => 'SELECT COUNT(`ifSpeed`) AS `total`,ROUND(`ifSpeed`/1000/1000) FROM `ports` GROUP BY `ifSpeed`', + 'port_vlans' => 'SELECT COUNT(`device_id`) AS `total`,`state` FROM `ports_vlans` GROUP BY `state`', + 'processes' => 'SELECT COUNT(`device_id`) AS `total` FROM `processes`', + 'processors' => 'SELECT COUNT(`processor_id`) AS `total`,`processor_type` FROM `processors` GROUP BY `processor_type`', + 'pseudowires' => 'SELECT COUNT(`pseudowire_id`) AS `total` FROM `pseudowires`', + 'sensors' => 'SELECT COUNT(`sensor_id`) AS `total`,`sensor_class` FROM `sensors` GROUP BY `sensor_class`', + 'storage' => 'SELECT COUNT(`storage_id`) AS `total`,`storage_type` FROM `storage` GROUP BY `storage_type`', + 'toner' => 'SELECT COUNT(`toner_id`) AS `total`,`toner_type` FROM `toner` GROUP BY `toner_type`', + 'vlans' => 'SELECT COUNT(`vlan_id`) AS `total`,`vlan_type` FROM `vlans` GROUP BY `vlan_type`', + 'vminfo' => 'SELECT COUNT(`id`) AS `total`,`vm_type` FROM `vminfo` GROUP BY `vm_type`', + 'vmware' => 'SELECT COUNT(`id`) AS `total` FROM `vmware_vminfo`', + 'vrfs' => 'SELECT COUNT(`vrf_id`) AS `total` FROM `vrfs`', + 'mysql_version' => 'SELECT 1 AS `total`, @@version AS `version`', + ); foreach ($queries as $name => $query) { - $data = dbFetchRows($query); + $data = dbFetchRows($query); $response[$name] = $data; } - $output = array('uuid'=>$uuid,'data'=>$response); - $data = json_encode($output); - $submit = array('data'=>$data); + + $output = array( + 'uuid' => $uuid, + 'data' => $response, + ); + $data = json_encode($output); + $submit = array('data' => $data); $fields = ''; foreach ($submit as $key => $value) { - $fields .= $key . '=' . $value . '&'; + $fields .= $key.'='.$value.'&'; } + rtrim($fields, '&'); $post = curl_init(); @@ -85,9 +91,9 @@ if ($enabled == 1) { curl_setopt($post, CURLOPT_POSTFIELDS, $fields); curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($post); -} elseif ($enabled == 2) { - - $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'"); +} +else if ($enabled == 2) { + $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'"); $fields = "uuid=$uuid"; $clear = curl_init(); @@ -100,5 +106,3 @@ if ($enabled == 1) { dbDelete('callback', '`name`="uuid"', array()); dbUpdate(array('value' => '0'), 'callback', '`name` = "enabled"', array()); } - -?> diff --git a/config_to_json.php b/config_to_json.php index e1012a7887..45e3394bcc 100644 --- a/config_to_json.php +++ b/config_to_json.php @@ -12,8 +12,7 @@ $config_file = 'config.php'; // move to install dir chdir(dirname($argv[0])); -function iscli() -{ +function iscli() { if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { return true; } diff --git a/contrib/generate-iplist.php b/contrib/generate-iplist.php index fd5e10048a..cfb5bd62b9 100644 --- a/contrib/generate-iplist.php +++ b/contrib/generate-iplist.php @@ -1,7 +1,7 @@ #!/usr/bin/env php * @copyright (C) 2006 - 2012 Adam Armstrong - * */ -include("includes/defaults.inc.php"); -include("config.php"); -include("includes/definitions.inc.php"); -include("includes/functions.php"); +require 'includes/defaults.inc.php'; +require 'config.php'; +require 'includes/definitions.inc.php'; +require 'includes/functions.php'; -$handle = fopen("ips.txt", "w"); +$handle = fopen('ips.txt', 'w'); -foreach (dbFetchRows("SELECT * FROM `ipv4_networks`") as $data) -{ - $cidr = $data['ipv4_network']; - list ($network, $bits) = explode("/", $cidr); - if ($bits != '32' && $bits != '32' && $bits > '22') - { - $addr = Net_IPv4::parseAddress($cidr); - $broadcast = $addr->broadcast; - $ip = ip2long($network) + '1'; - $end = ip2long($broadcast); - while ($ip < $end) - { - $ipdotted = long2ip($ip); - if (dbFetchCell("SELECT COUNT(ipv4_address_id) FROM `ipv4_addresses` WHERE `ipv4_address` = ?", array($ipdotted)) == '0' && match_network($config['nets'], $ipdotted)) - { - fputs($handle, $ipdotted . "\n"); - } - $ip++; +foreach (dbFetchRows('SELECT * FROM `ipv4_networks`') as $data) { + $cidr = $data['ipv4_network']; + list ($network, $bits) = explode('/', $cidr); + if ($bits != '32' && $bits != '32' && $bits > '22') { + $addr = Net_IPv4::parseAddress($cidr); + $broadcast = $addr->broadcast; + $ip = ip2long($network) + '1'; + $end = ip2long($broadcast); + while ($ip < $end) { + $ipdotted = long2ip($ip); + if (dbFetchCell('SELECT COUNT(ipv4_address_id) FROM `ipv4_addresses` WHERE `ipv4_address` = ?', array($ipdotted)) == '0' && match_network($config['nets'], $ipdotted)) { + fputs($handle, $ipdotted."\n"); + } + + $ip++; + } } - } } fclose($handle); -shell_exec("fping -t 100 -f ips.txt > ips-scanned.txt"); - -?> +shell_exec('fping -t 100 -f ips.txt > ips-scanned.txt'); diff --git a/daily.php b/daily.php index abb525a0b2..0b20ebf5ff 100644 --- a/daily.php +++ b/daily.php @@ -5,66 +5,71 @@ * (c) 2013 LibreNMS Contributors */ -include('includes/defaults.inc.php'); -include('config.php'); -include_once("includes/definitions.inc.php"); -include("includes/functions.php"); +require 'includes/defaults.inc.php'; +require 'config.php'; +require_once 'includes/definitions.inc.php'; +require 'includes/functions.php'; -$options = getopt("f:"); +$options = getopt('f:'); if ($options['f'] === 'update') { echo $config['update']; } if ($options['f'] === 'syslog') { - if (is_numeric($config['syslog_purge'])) { - $rows = dbFetchRow("SELECT MIN(seq) FROM syslog"); - while(TRUE) { - $limit = dbFetchRow("SELECT seq FROM syslog WHERE seq >= ? ORDER BY seq LIMIT 1000,1", array($rows)); - if(empty($limit)) { - break; - } - if (dbDelete('syslog', "seq >= ? AND seq < ? AND timestamp < DATE_SUB(NOW(), INTERVAL ? DAY)", array($rows,$limit,$config['syslog_purge'])) > 0) { - $rows = $limit; - echo 'Syslog cleared for entries over ' . $config['syslog_purge'] . " days 1000 limit\n"; - } else { - break; - } + if (is_numeric($config['syslog_purge'])) { + $rows = dbFetchRow('SELECT MIN(seq) FROM syslog'); + while (true) { + $limit = dbFetchRow('SELECT seq FROM syslog WHERE seq >= ? ORDER BY seq LIMIT 1000,1', array($rows)); + if (empty($limit)) { + break; + } + + if (dbDelete('syslog', 'seq >= ? AND seq < ? AND timestamp < DATE_SUB(NOW(), INTERVAL ? DAY)', array($rows, $limit, $config['syslog_purge'])) > 0) { + $rows = $limit; + echo 'Syslog cleared for entries over '.$config['syslog_purge']." days 1000 limit\n"; + } + else { + break; + } + } + + dbDelete('syslog', 'seq >= ? AND timestamp < DATE_SUB(NOW(), INTERVAL ? DAY)', array($rows, $config['syslog_purge'])); } - dbDelete('syslog', "seq >= ? AND timestamp < DATE_SUB(NOW(), INTERVAL ? DAY)", array($rows,$config['syslog_purge'])); - } } + if ($options['f'] === 'eventlog') { - if (is_numeric($config['eventlog_purge'])) { - if (dbDelete('eventlog', "datetime < DATE_SUB(NOW(), INTERVAL ? DAY)", array($config['eventlog_purge'])) ) { - echo 'Eventlog cleared for entries over ' . $config['eventlog_purge'] . " days\n"; + if (is_numeric($config['eventlog_purge'])) { + if (dbDelete('eventlog', 'datetime < DATE_SUB(NOW(), INTERVAL ? DAY)', array($config['eventlog_purge']))) { + echo 'Eventlog cleared for entries over '.$config['eventlog_purge']." days\n"; + } } - } } + if ($options['f'] === 'authlog') { if (is_numeric($config['authlog_purge'])) { - if (dbDelete('authlog', "datetime < DATE_SUB(NOW(), INTERVAL ? DAY)", array($config['authlog_purge'])) ) { - echo 'Authlog cleared for entries over ' . $config['authlog_purge'] . " days\n"; + if (dbDelete('authlog', 'datetime < DATE_SUB(NOW(), INTERVAL ? DAY)', array($config['authlog_purge']))) { + echo 'Authlog cleared for entries over '.$config['authlog_purge']." days\n"; } } } + if ($options['f'] === 'perf_times') { if (is_numeric($config['perf_times_purge'])) { - if (dbDelete('perf_times', "start < UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL ? DAY))", array($config['perf_times_purge'])) ) { - echo 'Performance poller times cleared for entries over ' . $config['perf_times_purge'] . " days\n"; + if (dbDelete('perf_times', 'start < UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL ? DAY))', array($config['perf_times_purge']))) { + echo 'Performance poller times cleared for entries over '.$config['perf_times_purge']." days\n"; } } } + if ($options['f'] === 'callback') { - require_once "callback.php"; + include_once 'callback.php'; } + if ($options['f'] === 'device_perf') { if (is_numeric($config['device_perf_purge'])) { - if (dbDelete('device_perf', "timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL ? DAY))", array($config['device_perf_purge'])) ) { - echo 'Device performance times cleared for entries over ' . $config['device_perf_purge'] . " days\n"; + if (dbDelete('device_perf', 'timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL ? DAY))', array($config['device_perf_purge']))) { + echo 'Device performance times cleared for entries over '.$config['device_perf_purge']." days\n"; } } } - - -?> diff --git a/delhost.php b/delhost.php index 189881778a..38ea772ad4 100755 --- a/delhost.php +++ b/delhost.php @@ -10,30 +10,26 @@ * @subpackage cli * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ chdir(dirname($argv[0])); -include("includes/defaults.inc.php"); -include("config.php"); -include("includes/definitions.inc.php"); -include("includes/functions.php"); +require 'includes/defaults.inc.php'; +require 'config.php'; +require 'includes/definitions.inc.php'; +require 'includes/functions.php'; -# Remove a host and all related data from the system - -if ($argv[1]) -{ - $host = strtolower($argv[1]); - $id = getidbyname($host); - if ($id) - { - echo(delete_device($id)."\n"); - } else { - echo("Host doesn't exist!\n"); - } -} else { - echo("Host Removal Tool\nUsage: ./delhost.php \n"); +// Remove a host and all related data from the system +if ($argv[1]) { + $host = strtolower($argv[1]); + $id = getidbyname($host); + if ($id) { + echo delete_device($id)."\n"; + } + else { + echo "Host doesn't exist!\n"; + } +} +else { + echo "Host Removal Tool\nUsage: ./delhost.php \n"; } - -?> diff --git a/discovery.php b/discovery.php index 7d8cfbd7f8..336f91ad08 100755 --- a/discovery.php +++ b/discovery.php @@ -10,129 +10,125 @@ * @subpackage discovery * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ chdir(dirname($argv[0])); -include("includes/defaults.inc.php"); -include("config.php"); -include("includes/definitions.inc.php"); -include("includes/functions.php"); -include("includes/discovery/functions.inc.php"); +require 'includes/defaults.inc.php'; +require 'config.php'; +require 'includes/definitions.inc.php'; +require 'includes/functions.php'; +require 'includes/discovery/functions.inc.php'; -$start = utime(); +$start = utime(); $runtime_stats = array(); // Observium Device Discovery +$options = getopt('h:m:i:n:d::a::q'); -$options = getopt("h:m:i:n:d::a::q"); - -if (!isset($options['q'])) -{ - echo($config['project_name_version']." Discovery\n\n"); +if (!isset($options['q'])) { + echo $config['project_name_version']." Discovery\n\n"; } -if (isset($options['h'])) -{ - if ($options['h'] == "odd") { $options['n'] = "1"; $options['i'] = "2"; } - elseif ($options['h'] == "even") { $options['n'] = "0"; $options['i'] = "2"; } - elseif ($options['h'] == "all") { $where = " "; $doing = "all"; } - elseif ($options['h'] == "new") { $where = "AND `last_discovered` IS NULL"; $doing = "new"; } - elseif ($options['h']) - { - if (is_numeric($options['h'])) - { - $where = "AND `device_id` = '".$options['h']."'"; - $doing = $options['h']; +if (isset($options['h'])) { + if ($options['h'] == 'odd') { + $options['n'] = '1'; + $options['i'] = '2'; } - else - { - $where = "AND `hostname` LIKE '".str_replace('*','%',mres($options['h']))."'"; - $doing = $options['h']; + else if ($options['h'] == 'even') { + $options['n'] = '0'; + $options['i'] = '2'; } - } + else if ($options['h'] == 'all') { + $where = ' '; + $doing = 'all'; + } + else if ($options['h'] == 'new') { + $where = 'AND `last_discovered` IS NULL'; + $doing = 'new'; + } + else if ($options['h']) { + if (is_numeric($options['h'])) { + $where = "AND `device_id` = '".$options['h']."'"; + $doing = $options['h']; + } + else { + $where = "AND `hostname` LIKE '".str_replace('*', '%', mres($options['h']))."'"; + $doing = $options['h']; + } + }//end if +}//end if + +if (isset($options['i']) && $options['i'] && isset($options['n'])) { + $where = 'AND MOD(device_id,'.$options['i'].") = '".$options['n']."'"; + $doing = $options['n'].'/'.$options['i']; } -if (isset($options['i']) && $options['i'] && isset($options['n'])) -{ - $where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'"; - $doing = $options['n'] ."/".$options['i']; +if (isset($options['d'])) { + echo "DEBUG!\n"; + $debug = true; + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', 1); +} +else { + $debug = false; + // ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + // ini_set('error_reporting', 0); } -if (isset($options['d'])) -{ - echo("DEBUG!\n"); - $debug = TRUE; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', 1); -} else { - $debug = FALSE; - # ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - # ini_set('error_reporting', 0); +if (!$where) { + echo "-h | Poll single device\n"; + echo "-h odd Poll odd numbered devices (same as -i 2 -n 0)\n"; + echo "-h even Poll even numbered devices (same as -i 2 -n 1)\n"; + echo "-h all Poll all devices\n"; + echo "-h new Poll all devices that have not had a discovery run before\n\n"; + echo "-i -n Poll as instance of \n"; + echo " Instances start at 0. 0-3 for -n 4\n\n"; + echo "\n"; + echo "Debugging and testing options:\n"; + echo "-d Enable debugging output\n"; + echo "-m Specify single module to be run\n"; + echo "\n"; + echo "Invalid arguments!\n"; + exit; } -if (!$where) -{ - echo("-h | Poll single device\n"); - echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n"); - echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n"); - echo("-h all Poll all devices\n"); - echo("-h new Poll all devices that have not had a discovery run before\n\n"); - echo("-i -n Poll as instance of \n"); - echo(" Instances start at 0. 0-3 for -n 4\n\n"); - echo("\n"); - echo("Debugging and testing options:\n"); - echo("-d Enable debugging output\n"); - echo("-m Specify single module to be run\n"); - echo("\n"); - echo("Invalid arguments!\n"); - exit; -} - -include("includes/sql-schema/update.php"); +require 'includes/sql-schema/update.php'; $discovered_devices = 0; -if ($config['distributed_poller'] === TRUE) { - $where .= " AND poller_group IN(".$config['distributed_poller_group'].")"; -} -foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC") as $device) -{ - discover_device($device, $options); +if ($config['distributed_poller'] === true) { + $where .= ' AND poller_group IN('.$config['distributed_poller_group'].')'; } -$end = utime(); $run = $end - $start; +foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC") as $device) { + discover_device($device, $options); +} + +$end = utime(); +$run = ($end - $start); $proctime = substr($run, 0, 5); -if ($discovered_devices) -{ - dbInsert(array('type' => 'discover', 'doing' => $doing, 'start' => $start, 'duration' => $proctime, 'devices' => $discovered_devices), 'perf_times'); +if ($discovered_devices) { + dbInsert(array('type' => 'discover', 'doing' => $doing, 'start' => $start, 'duration' => $proctime, 'devices' => $discovered_devices), 'perf_times'); } -$string = $argv[0] . " $doing " . date($config['dateformat']['compact']) . " - $discovered_devices devices discovered in $proctime secs"; -if ($debug) echo("$string\n"); - -if($options['h'] != "new" && $config['version_check']) { - include("includes/versioncheck.inc.php"); +$string = $argv[0]." $doing ".date($config['dateformat']['compact'])." - $discovered_devices devices discovered in $proctime secs"; +if ($debug) { + echo "$string\n"; } -if (!isset($options['q'])) -{ - echo('MySQL: Cell['.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,2).'s]'. - ' Row['.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,2).'s]'. - ' Rows['.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,2).'s]'. - ' Column['.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,2).'s]'. - ' Update['.($db_stats['update']+0).'/'.round($db_stats['update_sec']+0,2).'s]'. - ' Insert['.($db_stats['insert']+0). '/'.round($db_stats['insert_sec']+0,2).'s]'. - ' Delete['.($db_stats['delete']+0). '/'.round($db_stats['delete_sec']+0,2).'s]'); - echo("\n"); +if ($options['h'] != 'new' && $config['version_check']) { + include 'includes/versioncheck.inc.php'; +} + +if (!isset($options['q'])) { + echo ('MySQL: Cell['.($db_stats['fetchcell'] + 0).'/'.round(($db_stats['fetchcell_sec'] + 0), 2).'s]'.' Row['.($db_stats['fetchrow'] + 0).'/'.round(($db_stats['fetchrow_sec'] + 0), 2).'s]'.' Rows['.($db_stats['fetchrows'] + 0).'/'.round(($db_stats['fetchrows_sec'] + 0), 2).'s]'.' Column['.($db_stats['fetchcol'] + 0).'/'.round(($db_stats['fetchcol_sec'] + 0), 2).'s]'.' Update['.($db_stats['update'] + 0).'/'.round(($db_stats['update_sec'] + 0), 2).'s]'.' Insert['.($db_stats['insert'] + 0).'/'.round(($db_stats['insert_sec'] + 0), 2).'s]'.' Delete['.($db_stats['delete'] + 0).'/'.round(($db_stats['delete_sec'] + 0), 2).'s]'); + echo "\n"; } logfile($string); - -?> diff --git a/dist-pollers.php b/dist-pollers.php index 81e7116941..e3f016af4d 100755 --- a/dist-pollers.php +++ b/dist-pollers.php @@ -15,49 +15,55 @@ chdir(dirname($argv[0])); -include("includes/defaults.inc.php"); -include("config.php"); -include("includes/definitions.inc.php"); -include("includes/functions.php"); -include("includes/polling/functions.inc.php"); -include("includes/alerts.inc.php"); -include('includes/console_table.php'); +require 'includes/defaults.inc.php'; +require 'config.php'; +require 'includes/definitions.inc.php'; +require 'includes/functions.php'; +require 'includes/polling/functions.inc.php'; +require 'includes/alerts.inc.php'; +require 'includes/console_table.php'; -$options = getopt("l:u:r::"); +$options = getopt('l:u:r::'); if (isset($options['l'])) { if ($options['l'] == 'pollers') { $tbl = new Console_Table(); - $tbl->setHeaders(array('ID','Poller Name','Last Polled','# Devices','Poll Time')); - foreach (dbFetchRows("SELECT * FROM `pollers`") as $poller) { - $tbl->addRow(array($poller['id'],$poller['poller_name'],$poller['last_polled'],$poller['devices'],$poller['time_taken'])); - } - echo $tbl->getTable(); - } elseif ($options['l'] == 'groups') { - $tbl = new Console_Table(); - $tbl->setHeaders(array('ID','Group Name','Description')); - foreach (dbFetchRows("SELECT * FROM `poller_groups`") as $groups) { - $tbl->addRow(array($groups['id'],$groups['group_name'],$groups['descr'])); + $tbl->setHeaders(array('ID', 'Poller Name', 'Last Polled', '# Devices', 'Poll Time')); + foreach (dbFetchRows('SELECT * FROM `pollers`') as $poller) { + $tbl->addRow(array($poller['id'], $poller['poller_name'], $poller['last_polled'], $poller['devices'], $poller['time_taken'])); } + echo $tbl->getTable(); } -} elseif (isset($options['u']) && !empty($options['u'])) { + else if ($options['l'] == 'groups') { + $tbl = new Console_Table(); + $tbl->setHeaders(array('ID', 'Group Name', 'Description')); + foreach (dbFetchRows('SELECT * FROM `poller_groups`') as $groups) { + $tbl->addRow(array($groups['id'], $groups['group_name'], $groups['descr'])); + } + + echo $tbl->getTable(); + } +} +else if (isset($options['u']) && !empty($options['u'])) { if (is_numeric($options['u'])) { - $db_column = 'id'; - } else { + $db_column = 'id'; + } + else { $db_column = 'poller_name'; } - if (dbDelete('pollers',"`$db_column` = ?", array($options['u'])) >= 0) { - echo "Poller " . $options['u'] . " has been removed\n"; + + if (dbDelete('pollers', "`$db_column` = ?", array($options['u'])) >= 0) { + echo 'Poller '.$options['u']." has been removed\n"; } -} elseif (isset($options['r'])) { - if(dbInsert(array('poller_name' => $config['distributed_poller_name'], 'last_polled' => '0000-00-00 00:00:00', 'devices' => 0, 'time_taken' => 0), 'pollers') >= 0) { - echo "Poller " . $config['distributed_poller_name'] . " has been registered\n"; +} +else if (isset($options['r'])) { + if (dbInsert(array('poller_name' => $config['distributed_poller_name'], 'last_polled' => '0000-00-00 00:00:00', 'devices' => 0, 'time_taken' => 0), 'pollers') >= 0) { + echo 'Poller '.$config['distributed_poller_name']." has been registered\n"; } -} else { +} +else { echo "-l pollers | groups List registered pollers or poller groups\n"; echo "-u | Unregister a poller\n"; echo "-r Register this install as a poller\n"; -} - -?> +}//end if diff --git a/html/ajax_form.php b/html/ajax_form.php index b269a19357..a017b4c3d4 100644 --- a/html/ajax_form.php +++ b/html/ajax_form.php @@ -1,44 +1,40 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ // FUA - -if (isset($_REQUEST['debug'])) -{ - ini_set('display_errors', 1); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('allow_url_fopen', 0); - ini_set('error_reporting', E_ALL); +if (isset($_REQUEST['debug'])) { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('allow_url_fopen', 0); + ini_set('error_reporting', E_ALL); } -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); -include_once("includes/functions.inc.php"); -include_once("../includes/functions.php"); -include_once("includes/authenticate.inc.php"); - -if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } - -if(preg_match("/^[a-zA-Z0-9\-]+$/", $_POST['type']) == 1) { - - if(file_exists('forms/'.$_POST['type'].'.inc.php')) - { - include_once('forms/'.$_POST['type'].'.inc.php'); - } +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once 'includes/functions.inc.php'; +require_once '../includes/functions.php'; +require_once 'includes/authenticate.inc.php'; +if (!$_SESSION['authenticated']) { + echo 'unauthenticated'; + exit; } -?> +if (preg_match('/^[a-zA-Z0-9\-]+$/', $_POST['type']) == 1) { + if (file_exists('forms/'.$_POST['type'].'.inc.php')) { + include_once 'forms/'.$_POST['type'].'.inc.php'; + } +} diff --git a/html/ajax_listports.php b/html/ajax_listports.php index 0f7b4469c7..0ebab67b17 100644 --- a/html/ajax_listports.php +++ b/html/ajax_listports.php @@ -9,39 +9,36 @@ * @subpackage ajax * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ -if (isset($_GET['debug'])) -{ - ini_set('display_errors', 1); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('allow_url_fopen', 0); - ini_set('error_reporting', E_ALL); +if (isset($_GET['debug'])) { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('allow_url_fopen', 0); + ini_set('error_reporting', E_ALL); } -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); -include_once("includes/functions.inc.php"); -include_once("../includes/dbFacile.php"); -include_once("../includes/common.php"); +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once 'includes/functions.inc.php'; +require_once '../includes/dbFacile.php'; +require_once '../includes/common.php'; -include_once("../includes/rewrites.php"); -include_once("includes/authenticate.inc.php"); +require_once '../includes/rewrites.php'; +require_once 'includes/authenticate.inc.php'; -if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } - -if (is_numeric($_GET['device_id'])) -{ - foreach (dbFetch("SELECT * FROM ports WHERE device_id = ?", array($_GET['device_id'])) as $interface) - { - $interface = ifNameDescr($interface); - $string = mres($interface['label']." - ".$interface['ifAlias']); - echo("obj.options[obj.options.length] = new Option('".$string."','".$interface['port_id']."');\n"); - #echo("obj.options[obj.options.length] = new Option('".$interface['ifDescr']." - ".$interface['ifAlias']."','".$interface['port_id']."');\n"); - } +if (!$_SESSION['authenticated']) { + echo 'unauthenticated'; + exit; } -?> +if (is_numeric($_GET['device_id'])) { + foreach (dbFetch('SELECT * FROM ports WHERE device_id = ?', array($_GET['device_id'])) as $interface) { + $interface = ifNameDescr($interface); + $string = mres($interface['label'].' - '.$interface['ifAlias']); + echo "obj.options[obj.options.length] = new Option('".$string."','".$interface['port_id']."');\n"; + // echo("obj.options[obj.options.length] = new Option('".$interface['ifDescr']." - ".$interface['ifAlias']."','".$interface['port_id']."');\n"); + } +} diff --git a/html/ajax_rulesuggest.php b/html/ajax_rulesuggest.php index 7312e73930..159d4630c6 100644 --- a/html/ajax_rulesuggest.php +++ b/html/ajax_rulesuggest.php @@ -1,19 +1,21 @@ +/* + * Copyright (C) 2014 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * Rule Suggestion-AJAX * @author Daniel Preussker * @copyright 2014 f0o, LibreNMS @@ -22,103 +24,123 @@ */ session_start(); -if( !isset($_SESSION['authenticated']) ) { - die("Unauthorized."); +if (!isset($_SESSION['authenticated'])) { + die('Unauthorized.'); } -require_once("../includes/defaults.inc.php"); -require_once("../config.php"); -require_once("../includes/definitions.inc.php"); -require_once("../includes/functions.php"); +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once '../includes/functions.php'; + /** * Levenshtein Sort * @param string $base Comparisson basis - * @param array $obj Object to sort + * @param array $obj Object to sort * @return array */ function levsort($base, $obj) { - $ret = array(); - foreach( $obj as $elem ) { - $lev = levenshtein($base, $elem, 1, 10, 10); - if( $lev == 0 ) { - return array(array('name'=>$elem)); - } else { - while( isset($ret["$lev"]) ) { - $lev += 0.1; - } - $ret["$lev"] = array('name'=>$elem); - } - } - ksort($ret); - return $ret; + $ret = array(); + foreach ($obj as $elem) { + $lev = levenshtein($base, $elem, 1, 10, 10); + if ($lev == 0) { + return array(array('name' => $elem)); + } + else { + while (isset($ret["$lev"])) { + $lev += 0.1; + } + + $ret["$lev"] = array('name' => $elem); + } + } + + ksort($ret); + return $ret; + } -$obj = array(array('name'=>'Error: No suggestions found.')); -$term = array(); + +$obj = array(array('name' => 'Error: No suggestions found.')); +$term = array(); $current = false; -if( isset($_GET['term'],$_GET['device_id']) ) { - $chk = array(); - $_GET['term'] = mres($_GET['term']); - $_GET['device_id'] = mres($_GET['device_id']); - if( strstr($_GET['term'],".") ) { - $term = explode(".",$_GET['term']); - if( $config['memcached']['enable'] ) { - $chk = $memcache->get('rule-suggest_'.$term[0]); - } - if( !(sizeof($chk) > 0) || $chk === false ) { - if( $term[0] == "macros" ) { - foreach( $config['alert']['macros']['rule'] as $macro=>$v ) { - $chk[] = "macros.".$macro; - } - } else { - $tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]); - foreach( $tmp as $tst ) { - if( isset($tst['Field']) ) { - $chk[] = $term[0].'.'.$tst['Field']; - } - } - } - } - $current = true; - } else { - if( $config['memcached']['enable'] ) { - $chk = $memcache->get('rule-suggest-toplvl'); - } - if( !(sizeof($chk) > 0) || $chk === false ) { - $tmp = dbFetchRows("SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'device_id'"); - foreach( $tmp as $tst ) { - $chk[] = $tst['TABLE_NAME'].'.'; - } - $chk[] = 'macros.'; - $chk[] = 'bills.'; - } - } - if( sizeof($chk) > 0 ) { - if( $config['memcached']['enable'] ) { - $memcache->set('rule-suggest-'.$oterm,$chk,86400); //Cache for 24h - } - $obj = levsort($_GET['term'],$chk); - $obj = array_chunk($obj,20,true); - $obj = $obj[0]; - $flds = array(); - if( $current == true ) { - foreach( $obj as $fld ) { - $flds[] = $fld['name']; - } - $qry = dbFetchRows("SELECT ".implode(", ",$flds)." FROM ".$term[0]." WHERE device_id = ?", array($_GET['device_id'])); - $ret = array(); - foreach( $obj as $lev=>$fld ) { - list($tbl, $chk) = explode(".",$fld['name']); - $val = array(); - foreach( $qry as $row ) { - $val[] = $row[$chk]; - } - $ret[$lev] = array('name'=>$fld['name'],'current'=>$val); - } - $obj = $ret; - } - } +if (isset($_GET['term'],$_GET['device_id'])) { + $chk = array(); + $_GET['term'] = mres($_GET['term']); + $_GET['device_id'] = mres($_GET['device_id']); + if (strstr($_GET['term'], '.')) { + $term = explode('.', $_GET['term']); + if ($config['memcached']['enable']) { + $chk = $memcache->get('rule-suggest_'.$term[0]); + } + + if (!(sizeof($chk) > 0) || $chk === false) { + if ($term[0] == 'macros') { + foreach ($config['alert']['macros']['rule'] as $macro => $v) { + $chk[] = 'macros.'.$macro; + } + } + else { + $tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]); + foreach ($tmp as $tst) { + if (isset($tst['Field'])) { + $chk[] = $term[0].'.'.$tst['Field']; + } + } + } + } + + $current = true; + } + else { + if ($config['memcached']['enable']) { + $chk = $memcache->get('rule-suggest-toplvl'); + } + + if (!(sizeof($chk) > 0) || $chk === false) { + $tmp = dbFetchRows("SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'device_id'"); + foreach ($tmp as $tst) { + $chk[] = $tst['TABLE_NAME'].'.'; + } + + $chk[] = 'macros.'; + $chk[] = 'bills.'; + } + } + if (sizeof($chk) > 0) { + if ($config['memcached']['enable']) { + $memcache->set('rule-suggest-'.$oterm, $chk, 86400); + // Cache for 24h + } + + $obj = levsort($_GET['term'], $chk); + $obj = array_chunk($obj, 20, true); + $obj = $obj[0]; + $flds = array(); + if ($current == true) { + foreach ($obj as $fld) { + $flds[] = $fld['name']; + } + + $qry = dbFetchRows('SELECT '.implode(', ', $flds).' FROM '.$term[0].' WHERE device_id = ?', array($_GET['device_id'])); + $ret = array(); + foreach ($obj as $lev => $fld) { + list($tbl, $chk) = explode('.', $fld['name']); + $val = array(); + foreach ($qry as $row) { + $val[] = $row[$chk]; + } + + $ret[$lev] = array( + 'name' => $fld['name'], + 'current' => $val, + ); + } + + $obj = $ret; + } + } } + die(json_encode($obj)); -?> diff --git a/html/ajax_search.php b/html/ajax_search.php index 410aac1111..d9c9610540 100644 --- a/html/ajax_search.php +++ b/html/ajax_search.php @@ -1,212 +1,218 @@ 0) - { - $found = 0; - - if( $_REQUEST['type'] == 'group' ) { - include_once('../includes/device-groups.inc.php'); - foreach( dbFetchRows("SELECT id,name FROM device_groups WHERE name LIKE '%".$search."%'") as $group ) { - if( $_REQUEST['map'] ) { - $results[] = array('name'=>'g:'.$group['name'],'group_id'=>$group['id']); - } else { - $results[] = array('name'=>$group['name']); - } - } - die(json_encode($results)); - } elseif( $_REQUEST['type'] == 'alert-rules' ) { - foreach( dbFetchRows("SELECT name FROM alert_rules WHERE name LIKE '%".$search."%'") as $rules ) { - $results[] = array('name'=>$rules['name']); - } - die(json_encode($results)); - } elseif($_REQUEST['type'] == 'device') { - - // Device search - if (is_admin() === TRUE || is_read() === TRUE) { - $results = dbFetchRows("SELECT * FROM `devices` WHERE `hostname` LIKE '%" . $search . "%' OR `location` LIKE '%" . $search . "%' ORDER BY hostname LIMIT 8"); - } else { - $results = dbFetchRows("SELECT * FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND (`hostname` LIKE '%" . $search . "%' OR `location` LIKE '%" . $search . "%') ORDER BY hostname LIMIT 8", array($_SESSION['user_id'])); - } - if (count($results)) - { - $found = 1; - $devices = count($results); - - foreach ($results as $result) - { - $name = $result['hostname']; - if($result['disabled'] == 1) - { - $highlight_colour = '#808080'; - } - elseif($result['ignored'] == 1 && $result['disabled'] == 0) - { - $highlight_colour = '#000000'; - } - elseif($result['status'] == 0 && $result['ignore'] == 0 && $result['disabled'] == 0) - { - $highlight_colour = '#ff0000'; - } - elseif($result['status'] == 1 && $result['ignore'] == 0 && $result['disabled'] == 0) - { - $highlight_colour = '#008000'; - } - if (is_admin() === TRUE || is_read() === TRUE) { - $num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ?", array($result['device_id'])); - } else { - $num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `I`.`device_id` = `D`.`device_id` AND device_id = ?", array($_SESSION['user_id'],$result['device_id'])); - } - $device[]=array('name'=>$name, - 'device_id'=>$result['device_id'], - 'url'=> generate_device_url($result), - 'colours'=>$highlight_colour, - 'device_ports'=>$num_ports, - 'device_image'=>getImageSrc($result), - 'device_hardware'=>$result['hardware'], - 'device_os'=>$config['os'][$result['os']]['text'], - 'version'=>$result['version'], - 'location'=>$result['location']); - } - } - $json = json_encode($device); - print_r($json); - exit; - - } elseif($_REQUEST['type'] == 'ports') { - // Search ports - if (is_admin() === TRUE || is_read() === TRUE) { - $results = dbFetchRows("SELECT `ports`.*,`devices`.* FROM `ports` LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id` WHERE `ifAlias` LIKE '%" . $search . "%' OR `ifDescr` LIKE '%" . $search . "%' ORDER BY ifDescr LIMIT 8"); - } else { - $results = dbFetchRows("SELECT DISTINCT(`I`.`port_id`), `I`.*, `D`.`hostname` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifAlias` LIKE '%" . $search . "%' OR `ifDescr` LIKE '%" . $search . "%') ORDER BY ifDescr LIMIT 8", array($_SESSION['user_id'],$_SESSION['user_id'])); - } - - if (count($results)) - { - $found = 1; - - foreach ($results as $result) - { - $name = $result['ifDescr']; - $description = $result['ifAlias']; - - if($result['deleted'] == 0 && ($result['ignore'] == 0 || $result['ignore'] == 0) && ($result['ifInErrors_delta'] > 0 || $result['ifOutErrors_delta'] > 0)) - { - // Errored ports - $port_colour = '#ffa500'; - } - elseif($result['deleted'] == 0 && ($result['ignore'] == 1 || $result['ignore'] == 1)) - { - // Ignored ports - $port_colour = '#000000'; - - } - elseif($result['deleted'] == 0 && $result['ifAdminStatus'] == 'down' && $result['ignore'] == 0 && $result['ignore'] == 0) - { - // Shutdown ports - $port_colour = '#808080'; - } - elseif($result['deleted'] == 0 && $result['ifOperStatus'] == 'down' && $result['ifAdminStatus'] == 'up' && $result['ignore'] == 0 && $result['ignore'] == 0) - { - // Down ports - $port_colour = '#ff0000'; - } - elseif($result['deleted'] == 0 && $result['ifOperStatus'] == 'up' && $result['ignore'] == 0 && $result['ignore'] == 0) - { - // Up ports - $port_colour = '#008000'; - } - - $ports[]=array('count'=>count($results), - 'url'=>generate_port_url($result), - 'name'=>$name, - 'description'=>$description, - 'colours'=>$highlight_colour, - 'hostname'=>$result['hostname']); - - } - } - $json = json_encode($ports); - print_r($json); - exit; - - } elseif($_REQUEST['type'] == 'bgp') { - // Search bgp peers - if (is_admin() === TRUE || is_read() === TRUE) { - $results = dbFetchRows("SELECT `bgpPeers`.*,`devices`.* FROM `bgpPeers` LEFT JOIN `devices` ON `bgpPeers`.`device_id` = `devices`.`device_id` WHERE `astext` LIKE '%" . $search . "%' OR `bgpPeerIdentifier` LIKE '%" . $search . "%' OR `bgpPeerRemoteAs` LIKE '%" . $search . "%' ORDER BY `astext` LIMIT 8"); - } else { - $results = dbFetchRows("SELECT `bgpPeers`.*,`D`.* FROM `bgpPeers`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `bgpPeers`.`device_id`=`D`.`device_id` AND (`astext` LIKE '%" . $search . "%' OR `bgpPeerIdentifier` LIKE '%" . $search . "%' OR `bgpPeerRemoteAs` LIKE '%" . $search . "%') ORDER BY `astext` LIMIT 8", array($_SESSION['user_id'])); - } - if (count($results)) - { - $found = 1; - - foreach ($results as $result) - { - $name = $result['bgpPeerIdentifier']; - $description = $result['astext']; - $remoteas = $result['bgpPeerRemoteAs']; - $localas = $result['bgpLocalAs']; - - if($result['bgpPeerAdminStatus'] == 'start' && $result['bgpPeerState'] != 'established') - { - // Session active but errored - $port_colour = '#ffa500'; - } - elseif($result['bgpPeerAdminStatus'] != 'start') - { - // Session inactive - $port_colour = '#000000'; - - } - elseif($result['bgpPeerAdminStatus'] == 'start' && $result['bgpPeerState'] == 'established') - { - // Session Up - $port_colour = '#008000'; - } - - if ($result['bgpPeerRemoteAs'] == $result['bgpLocalAs']) { $bgp_image = "images/16/brick_link.png"; } else { $bgp_image = "images/16/world_link.png"; } - - $bgp[]=array('count'=>count($results), - 'url'=>generate_peer_url($result), - 'name'=>$name, - 'description'=>$description, - 'localas'=>$localas, - 'bgp_image'=>$bgp_image, - 'remoteas'=>$remoteas, - 'colours'=>$port_colour, - 'hostname'=>$result['hostname']); - - } - } - $json = json_encode($bgp); - print_r($json); - exit; - } - } +if (!$_SESSION['authenticated']) { + echo 'unauthenticated'; + exit; } -?> + +$device = array(); +$ports = array(); + +if (isset($_REQUEST['search'])) { + $search = mres($_REQUEST['search']); + + if (strlen($search) > 0) { + $found = 0; + + if ($_REQUEST['type'] == 'group') { + include_once '../includes/device-groups.inc.php'; + foreach (dbFetchRows("SELECT id,name FROM device_groups WHERE name LIKE '%".$search."%'") as $group) { + if ($_REQUEST['map']) { + $results[] = array( + 'name' => 'g:'.$group['name'], + 'group_id' => $group['id'], + ); + } + else { + $results[] = array('name' => $group['name']); + } + } + + die(json_encode($results)); + } + else if ($_REQUEST['type'] == 'alert-rules') { + foreach (dbFetchRows("SELECT name FROM alert_rules WHERE name LIKE '%".$search."%'") as $rules) { + $results[] = array('name' => $rules['name']); + } + + die(json_encode($results)); + } + else if ($_REQUEST['type'] == 'device') { + // Device search + if (is_admin() === true || is_read() === true) { + $results = dbFetchRows("SELECT * FROM `devices` WHERE `hostname` LIKE '%".$search."%' OR `location` LIKE '%".$search."%' ORDER BY hostname LIMIT 8"); + } + else { + $results = dbFetchRows("SELECT * FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND (`hostname` LIKE '%".$search."%' OR `location` LIKE '%".$search."%') ORDER BY hostname LIMIT 8", array($_SESSION['user_id'])); + } + + if (count($results)) { + $found = 1; + $devices = count($results); + + foreach ($results as $result) { + $name = $result['hostname']; + if ($result['disabled'] == 1) { + $highlight_colour = '#808080'; + } + else if ($result['ignored'] == 1 && $result['disabled'] == 0) { + $highlight_colour = '#000000'; + } + else if ($result['status'] == 0 && $result['ignore'] == 0 && $result['disabled'] == 0) { + $highlight_colour = '#ff0000'; + } + else if ($result['status'] == 1 && $result['ignore'] == 0 && $result['disabled'] == 0) { + $highlight_colour = '#008000'; + } + + if (is_admin() === true || is_read() === true) { + $num_ports = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ?', array($result['device_id'])); + } + else { + $num_ports = dbFetchCell('SELECT COUNT(*) FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `I`.`device_id` = `D`.`device_id` AND device_id = ?', array($_SESSION['user_id'], $result['device_id'])); + } + + $device[] = array( + 'name' => $name, + 'device_id' => $result['device_id'], + 'url' => generate_device_url($result), + 'colours' => $highlight_colour, + 'device_ports' => $num_ports, + 'device_image' => getImageSrc($result), + 'device_hardware' => $result['hardware'], + 'device_os' => $config['os'][$result['os']]['text'], + 'version' => $result['version'], + 'location' => $result['location'], + ); + }//end foreach + }//end if + + $json = json_encode($device); + print_r($json); + exit; + } + else if ($_REQUEST['type'] == 'ports') { + // Search ports + if (is_admin() === true || is_read() === true) { + $results = dbFetchRows("SELECT `ports`.*,`devices`.* FROM `ports` LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id` WHERE `ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%' ORDER BY ifDescr LIMIT 8"); + } + else { + $results = dbFetchRows("SELECT DISTINCT(`I`.`port_id`), `I`.*, `D`.`hostname` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifAlias` LIKE '%".$search."%' OR `ifDescr` LIKE '%".$search."%') ORDER BY ifDescr LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id'])); + } + + if (count($results)) { + $found = 1; + + foreach ($results as $result) { + $name = $result['ifDescr']; + $description = $result['ifAlias']; + + if ($result['deleted'] == 0 && ($result['ignore'] == 0 || $result['ignore'] == 0) && ($result['ifInErrors_delta'] > 0 || $result['ifOutErrors_delta'] > 0)) { + // Errored ports + $port_colour = '#ffa500'; + } + else if ($result['deleted'] == 0 && ($result['ignore'] == 1 || $result['ignore'] == 1)) { + // Ignored ports + $port_colour = '#000000'; + } + else if ($result['deleted'] == 0 && $result['ifAdminStatus'] == 'down' && $result['ignore'] == 0 && $result['ignore'] == 0) { + // Shutdown ports + $port_colour = '#808080'; + } + else if ($result['deleted'] == 0 && $result['ifOperStatus'] == 'down' && $result['ifAdminStatus'] == 'up' && $result['ignore'] == 0 && $result['ignore'] == 0) { + // Down ports + $port_colour = '#ff0000'; + } + else if ($result['deleted'] == 0 && $result['ifOperStatus'] == 'up' && $result['ignore'] == 0 && $result['ignore'] == 0) { + // Up ports + $port_colour = '#008000'; + }//end if + + $ports[] = array( + 'count' => count($results), + 'url' => generate_port_url($result), + 'name' => $name, + 'description' => $description, + 'colours' => $highlight_colour, + 'hostname' => $result['hostname'], + ); + }//end foreach + }//end if + + $json = json_encode($ports); + print_r($json); + exit; + } + else if ($_REQUEST['type'] == 'bgp') { + // Search bgp peers + if (is_admin() === true || is_read() === true) { + $results = dbFetchRows("SELECT `bgpPeers`.*,`devices`.* FROM `bgpPeers` LEFT JOIN `devices` ON `bgpPeers`.`device_id` = `devices`.`device_id` WHERE `astext` LIKE '%".$search."%' OR `bgpPeerIdentifier` LIKE '%".$search."%' OR `bgpPeerRemoteAs` LIKE '%".$search."%' ORDER BY `astext` LIMIT 8"); + } + else { + $results = dbFetchRows("SELECT `bgpPeers`.*,`D`.* FROM `bgpPeers`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `bgpPeers`.`device_id`=`D`.`device_id` AND (`astext` LIKE '%".$search."%' OR `bgpPeerIdentifier` LIKE '%".$search."%' OR `bgpPeerRemoteAs` LIKE '%".$search."%') ORDER BY `astext` LIMIT 8", array($_SESSION['user_id'])); + } + + if (count($results)) { + $found = 1; + + foreach ($results as $result) { + $name = $result['bgpPeerIdentifier']; + $description = $result['astext']; + $remoteas = $result['bgpPeerRemoteAs']; + $localas = $result['bgpLocalAs']; + + if ($result['bgpPeerAdminStatus'] == 'start' && $result['bgpPeerState'] != 'established') { + // Session active but errored + $port_colour = '#ffa500'; + } + else if ($result['bgpPeerAdminStatus'] != 'start') { + // Session inactive + $port_colour = '#000000'; + } + else if ($result['bgpPeerAdminStatus'] == 'start' && $result['bgpPeerState'] == 'established') { + // Session Up + $port_colour = '#008000'; + } + + if ($result['bgpPeerRemoteAs'] == $result['bgpLocalAs']) { + $bgp_image = 'images/16/brick_link.png'; + } + else { + $bgp_image = 'images/16/world_link.png'; + } + + $bgp[] = array( + 'count' => count($results), + 'url' => generate_peer_url($result), + 'name' => $name, + 'description' => $description, + 'localas' => $localas, + 'bgp_image' => $bgp_image, + 'remoteas' => $remoteas, + 'colours' => $port_colour, + 'hostname' => $result['hostname'], + ); + }//end foreach + }//end if + + $json = json_encode($bgp); + print_r($json); + exit; + }//end if + }//end if +}//end if diff --git a/html/ajax_table.php b/html/ajax_table.php index dc5af2c6e6..3684681a45 100644 --- a/html/ajax_table.php +++ b/html/ajax_table.php @@ -12,39 +12,37 @@ * the source code distribution for details. */ -if (isset($_REQUEST['debug'])) -{ - ini_set('display_errors', 1); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('allow_url_fopen', 0); - ini_set('error_reporting', E_ALL); +if (isset($_REQUEST['debug'])) { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('allow_url_fopen', 0); + ini_set('error_reporting', E_ALL); } -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); -include_once("includes/functions.inc.php"); -include_once("../includes/functions.php"); -include_once("includes/authenticate.inc.php"); +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once 'includes/functions.inc.php'; +require_once '../includes/functions.php'; +require_once 'includes/authenticate.inc.php'; $current = $_POST['current']; -settype($current,"integer"); +settype($current, 'integer'); $rowCount = $_POST['rowCount']; -settype($rowCount,"integer"); +settype($rowCount, 'integer'); if (isset($_POST['sort']) && is_array($_POST['sort'])) { - foreach ($_POST['sort'] as $k=>$v) { + foreach ($_POST['sort'] as $k => $v) { $sort .= " $k $v"; } } + $searchPhrase = mres($_POST['searchPhrase']); -$id = mres($_POST['id']); -$response = array(); +$id = mres($_POST['id']); +$response = array(); if (isset($id)) { if (file_exists("includes/table/$id.inc.php")) { - require_once "includes/table/$id.inc.php"; + include_once "includes/table/$id.inc.php"; } } - -?> diff --git a/html/api_v0.php b/html/api_v0.php index 81b81f11a5..412680e43f 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -12,67 +12,111 @@ * the source code distribution for details. */ -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); -include_once("../includes/common.php"); -include_once("../includes/dbFacile.php"); -include_once("../includes/rewrites.php"); -include_once("includes/functions.inc.php"); -include_once("../includes/rrdtool.inc.php"); +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once '../includes/common.php'; +require_once '../includes/dbFacile.php'; +require_once '../includes/rewrites.php'; +require_once 'includes/functions.inc.php'; +require_once '../includes/rrdtool.inc.php'; require 'includes/Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); -require_once("includes/api_functions.inc.php"); +require_once 'includes/api_functions.inc.php'; $app->setName('api'); -$app->group('/api', function() use ($app) { - $app->group('/v0', function() use ($app) { - $app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');//api/v0/bgp - $app->get('/oxidized', 'authToken', 'list_oxidized')->name('list_oxidized'); - $app->group('/devices', function() use ($app) { - $app->delete('/:hostname', 'authToken', 'del_device')->name('del_device');//api/v0/devices/$hostname - $app->get('/:hostname', 'authToken', 'get_device')->name('get_device');//api/v0/devices/$hostname - $app->get('/:hostname/vlans', 'authToken', 'get_vlans')->name('get_vlans');//api/v0/devices/$hostname/vlans - $app->get('/:hostname/graphs', 'authToken', 'get_graphs')->name('get_graphs');//api/v0/devices/$hostname/graphs - $app->get('/:hostname/ports', 'authToken', 'get_port_graphs')->name('get_port_graphs');//api/v0/devices/$hostname/ports - $app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname');//api/v0/devices/$hostname/$type - $app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname')->name('get_port_stats_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName - $app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname')->name('get_graph_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName/$type - }); - $app->get('/devices', 'authToken', 'list_devices')->name('list_devices');//api/v0/devices - $app->post('/devices', 'authToken', 'add_device')->name('add_device');//api/v0/devices (json data needs to be passed) - $app->group('/portgroups', function() use ($app) { - $app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup');//api/v0/portgroups/$group - }); - $app->group('/bills', function() use ($app) { - $app->get('/:bill_id', 'authToken', 'list_bills')->name('get_bill');//api/v0/bills/$bill_id - }); - $app->get('/bills', 'authToken', 'list_bills')->name('list_bills');//api/v0/bills - - // /api/v0/alerts - $app->group('/alerts', function() use ($app) { - $app->get('/:id', 'authToken', 'list_alerts')->name('get_alert');//api/v0/alerts - $app->put('/:id', 'authToken', 'ack_alert')->name('ack_alert');//api/v0/alerts/$id (PUT) - }); - $app->get('/alerts', 'authToken', 'list_alerts')->name('list_alerts');//api/v0/alerts - - // /api/v0/rules - $app->group('/rules', function() use ($app) { - $app->get('/:id', 'authToken', 'list_alert_rules')->name('get_alert_rule');//api/v0/rules/$id - $app->delete('/:id', 'authToken', 'delete_rule')->name('delete_rule');//api/v0/rules/$id (DELETE) - }); - $app->get('/rules', 'authToken', 'list_alert_rules')->name('list_alert_rules');//api/v0/rules - $app->post('/rules', 'authToken', 'add_edit_rule')->name('add_rule');//api/v0/rules (json data needs to be passed) - $app->put('/rules', 'authToken', 'add_edit_rule')->name('edit_rule');//api/v0/rules (json data needs to be passed) - // Inventory section - $app->group('/inventory', function() use ($app) { - $app->get('/:hostname', 'authToken', 'get_inventory')->name('get_inventory'); - });// End Inventory - }); - $app->get('/v0', 'authToken', 'show_endpoints');//api/v0 -}); +$app->group( + '/api', + function () use ($app) { + $app->group( + '/v0', + function () use ($app) { + $app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp'); + // api/v0/bgp + $app->get('/oxidized', 'authToken', 'list_oxidized')->name('list_oxidized'); + $app->group( + '/devices', + function () use ($app) { + $app->delete('/:hostname', 'authToken', 'del_device')->name('del_device'); + // api/v0/devices/$hostname + $app->get('/:hostname', 'authToken', 'get_device')->name('get_device'); + // api/v0/devices/$hostname + $app->get('/:hostname/vlans', 'authToken', 'get_vlans')->name('get_vlans'); + // api/v0/devices/$hostname/vlans + $app->get('/:hostname/graphs', 'authToken', 'get_graphs')->name('get_graphs'); + // api/v0/devices/$hostname/graphs + $app->get('/:hostname/ports', 'authToken', 'get_port_graphs')->name('get_port_graphs'); + // api/v0/devices/$hostname/ports + $app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname'); + // api/v0/devices/$hostname/$type + $app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname')->name('get_port_stats_by_port_hostname'); + // api/v0/devices/$hostname/ports/$ifName + $app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname')->name('get_graph_by_port_hostname'); + // api/v0/devices/$hostname/ports/$ifName/$type + } + ); + $app->get('/devices', 'authToken', 'list_devices')->name('list_devices'); + // api/v0/devices + $app->post('/devices', 'authToken', 'add_device')->name('add_device'); + // api/v0/devices (json data needs to be passed) + $app->group( + '/portgroups', + function () use ($app) { + $app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup'); + // api/v0/portgroups/$group + } + ); + $app->group( + '/bills', + function () use ($app) { + $app->get('/:bill_id', 'authToken', 'list_bills')->name('get_bill'); + // api/v0/bills/$bill_id + } + ); + $app->get('/bills', 'authToken', 'list_bills')->name('list_bills'); + // api/v0/bills + // /api/v0/alerts + $app->group( + '/alerts', + function () use ($app) { + $app->get('/:id', 'authToken', 'list_alerts')->name('get_alert'); + // api/v0/alerts + $app->put('/:id', 'authToken', 'ack_alert')->name('ack_alert'); + // api/v0/alerts/$id (PUT) + } + ); + $app->get('/alerts', 'authToken', 'list_alerts')->name('list_alerts'); + // api/v0/alerts + // /api/v0/rules + $app->group( + '/rules', + function () use ($app) { + $app->get('/:id', 'authToken', 'list_alert_rules')->name('get_alert_rule'); + // api/v0/rules/$id + $app->delete('/:id', 'authToken', 'delete_rule')->name('delete_rule'); + // api/v0/rules/$id (DELETE) + } + ); + $app->get('/rules', 'authToken', 'list_alert_rules')->name('list_alert_rules'); + // api/v0/rules + $app->post('/rules', 'authToken', 'add_edit_rule')->name('add_rule'); + // api/v0/rules (json data needs to be passed) + $app->put('/rules', 'authToken', 'add_edit_rule')->name('edit_rule'); + // api/v0/rules (json data needs to be passed) + // Inventory section + $app->group( + '/inventory', + function () use ($app) { + $app->get('/:hostname', 'authToken', 'get_inventory')->name('get_inventory'); + } + ); + // End Inventory + } + ); + $app->get('/v0', 'authToken', 'show_endpoints'); + // api/v0 + } +); $app->run(); - -?> diff --git a/html/bandwidth-graph.php b/html/bandwidth-graph.php index 031a03fd51..9f5d9df3ed 100644 --- a/html/bandwidth-graph.php +++ b/html/bandwidth-graph.php @@ -9,72 +9,77 @@ * @subpackage webinterface * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ ini_set('allow_url_fopen', 0); ini_set('display_errors', 0); -if (strpos($_SERVER['REQUEST_URI'], "debug")) -{ - $debug = "1"; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); -} else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); +if (strpos($_SERVER['REQUEST_URI'], 'debug')) { + $debug = '1'; + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); +} +else { + $debug = false; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } -include("../includes/defaults.inc.php"); -include("../config.php"); -include("../includes/definitions.inc.php"); -include("../includes/functions.php"); -include("includes/functions.inc.php"); -include("includes/authenticate.inc.php"); +require '../includes/defaults.inc.php'; +require '../config.php'; +require '../includes/definitions.inc.php'; +require '../includes/functions.php'; +require 'includes/functions.inc.php'; +require 'includes/authenticate.inc.php'; -if (get_client_ip() != $_SERVER['SERVER_ADDR']) { if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } } -require_once("includes/jpgraph/src/jpgraph.php"); -require_once("includes/jpgraph/src/jpgraph_line.php"); -require_once("includes/jpgraph/src/jpgraph_bar.php"); -require_once("includes/jpgraph/src/jpgraph_utils.inc.php"); -require_once("includes/jpgraph/src/jpgraph_date.php"); - -if (is_numeric($_GET['bill_id'])) -{ - if (get_client_ip() != $_SERVER['SERVER_ADDR']) - { - if (bill_permitted($_GET['bill_id'])) - { - $bill_id = $_GET['bill_id']; - } else { - echo("Unauthorised Access Prohibited."); - exit; +if (get_client_ip() != $_SERVER['SERVER_ADDR']) { + if (!$_SESSION['authenticated']) { + echo 'unauthenticated'; + exit; } - } else { - $bill_id = $_GET['bill_id']; - } -} else { - echo("Unauthorised Access Prohibited."); - exit; } -$start = $_GET['from']; -$end = $_GET['to']; -$xsize = (is_numeric($_GET['x']) ? $_GET['x'] : "800" ); -$ysize = (is_numeric($_GET['y']) ? $_GET['y'] : "250" ); -//$count = (is_numeric($_GET['count']) ? $_GET['count'] : "0" ); -//$type = (isset($_GET['type']) ? $_GET['type'] : "date" ); -//$dur = $end - $start; -//$datefrom = date('Ymthis', $start); -//$dateto = date('Ymthis', $end); -$imgtype = (isset($_GET['type']) ? $_GET['type'] : "historical" ); -$imgbill = (isset($_GET['imgbill']) ? $_GET['imgbill'] : false); -$yaxistitle = "Bytes"; +require_once 'includes/jpgraph/src/jpgraph.php'; +require_once 'includes/jpgraph/src/jpgraph_line.php'; +require_once 'includes/jpgraph/src/jpgraph_bar.php'; +require_once 'includes/jpgraph/src/jpgraph_utils.inc.php'; +require_once 'includes/jpgraph/src/jpgraph_date.php'; + +if (is_numeric($_GET['bill_id'])) { + if (get_client_ip() != $_SERVER['SERVER_ADDR']) { + if (bill_permitted($_GET['bill_id'])) { + $bill_id = $_GET['bill_id']; + } + else { + echo 'Unauthorised Access Prohibited.'; + exit; + } + } + else { + $bill_id = $_GET['bill_id']; + } +} +else { + echo 'Unauthorised Access Prohibited.'; + exit; +} + +$start = $_GET['from']; +$end = $_GET['to']; +$xsize = (is_numeric($_GET['x']) ? $_GET['x'] : '800' ); +$ysize = (is_numeric($_GET['y']) ? $_GET['y'] : '250' ); +// $count = (is_numeric($_GET['count']) ? $_GET['count'] : "0" ); +// $type = (isset($_GET['type']) ? $_GET['type'] : "date" ); +// $dur = $end - $start; +// $datefrom = date('Ymthis', $start); +// $dateto = date('Ymthis', $end); +$imgtype = (isset($_GET['type']) ? $_GET['type'] : 'historical' ); +$imgbill = (isset($_GET['imgbill']) ? $_GET['imgbill'] : false); +$yaxistitle = 'Bytes'; $in_data = array(); $out_data = array(); @@ -84,187 +89,179 @@ $ave_data = array(); $overuse_data = array(); $ticklabels = array(); -if ($imgtype == "historical") -{ - $i = "0"; +if ($imgtype == 'historical') { + $i = '0'; - foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12", array($bill_id)) as $data) - { - $datefrom = strftime("%e %b %Y", strtotime($data['bill_datefrom'])); - $dateto = strftime("%e %b %Y", strtotime($data['bill_dateto'])); - $datelabel = $datefrom."\n".$dateto; - $traf['in'] = $data['traf_in']; - $traf['out'] = $data['traf_out']; - $traf['total'] = $data['traf_total']; + foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12', array($bill_id)) as $data) { + $datefrom = strftime('%e %b %Y', strtotime($data['bill_datefrom'])); + $dateto = strftime('%e %b %Y', strtotime($data['bill_dateto'])); + $datelabel = $datefrom."\n".$dateto; + $traf['in'] = $data['traf_in']; + $traf['out'] = $data['traf_out']; + $traf['total'] = $data['traf_total']; - if ($data['bill_type'] == "Quota") - { - $traf['allowed'] = $data['bill_allowed']; - $traf['overuse'] = $data['bill_overuse']; - } else { - $traf['allowed'] = "0"; - $traf['overuse'] = "0"; + if ($data['bill_type'] == 'Quota') { + $traf['allowed'] = $data['bill_allowed']; + $traf['overuse'] = $data['bill_overuse']; + } + else { + $traf['allowed'] = '0'; + $traf['overuse'] = '0'; + } + + array_push($ticklabels, $datelabel); + array_push($in_data, $traf['in']); + array_push($out_data, $traf['out']); + array_push($tot_data, $traf['total']); + array_push($allow_data, $traf['allowed']); + array_push($overuse_data, $traf['overuse']); + $i++; + // print_r($data); + }//end foreach + + if ($i < 12) { + $y = (12 - $i); + for ($x = 0; $x < $y; $x++) { + $allowed = (($x == '0') ? $traf['allowed'] : '0' ); + array_push($in_data, '0'); + array_push($out_data, '0'); + array_push($tot_data, '0'); + array_push($allow_data, $allowed); + array_push($overuse_data, '0'); + array_push($ticklabels, ''); + } } - array_push($ticklabels, $datelabel); - array_push($in_data, $traf['in']); - array_push($out_data, $traf['out']); - array_push($tot_data, $traf['total']); - array_push($allow_data, $traf['allowed']); - array_push($overuse_data, $traf['overuse']); - $i++; - //print_r($data); - } - - if ($i < 12) - { - $y = 12 - $i; - for ($x=0;$x<$y;$x++) - { - $allowed = (($x == "0") ? $traf['allowed'] : "0" ); - array_push($in_data, "0"); - array_push($out_data, "0"); - array_push($tot_data, "0"); - array_push($allow_data, $allowed); - array_push($overuse_data, "0"); - array_push($ticklabels, ""); - } - } - $yaxistitle = "Gigabytes"; - $graph_name = "Historical bandwidth over the last 12 billing periods"; -} else { - $data = array(); - $average = 0; - if ($imgtype == "day") - { - foreach (dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data) - { - $traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0); - $traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0); - $traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0); - $datelabel = strftime("%e\n%b", $data['timestamp']); - array_push($ticklabels, $datelabel); - array_push($in_data, $traf['in']); - array_push($out_data, $traf['out']); - array_push($tot_data, $traf['total']); - $average += $data['traf_total']; - } - $ave_count = count($tot_data); - if ($imgbill != false) - { - $days = strftime("%e", date($end - $start)) - $ave_count - 1; - for ($x=0;$x<$days;$x++) - { - array_push($ticklabels, ""); - array_push($in_data, 0); - array_push($out_data, 0); - array_push($tot_data, 0); - } - } - } elseif ($imgtype == "hour") - { - foreach (dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data) - { - $traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0); - $traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0); - $traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0); - $datelabel = strftime("%H:%M", $data['timestamp']); - array_push($ticklabels, $datelabel); - array_push($in_data, $traf['in']); - array_push($out_data, $traf['out']); - array_push($tot_data, $traf['total']); - $average += $data['traf_total']; - } - $ave_count = count($tot_data); - } - - $decimal = 0; - $average = $average / $ave_count; - for ($x=0;$x<=count($tot_data);$x++) - { - array_push($ave_data, $average); - } - $graph_name = date('M j g:ia', $start)." - ".date('M j g:ia', $end); + $yaxistitle = 'Gigabytes'; + $graph_name = 'Historical bandwidth over the last 12 billing periods'; } +else { + $data = array(); + $average = 0; + if ($imgtype == 'day') { + foreach (dbFetch('SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC', array($bill_id, $start, $end)) as $data) { + $traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0); + $traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0); + $traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0); + $datelabel = strftime("%e\n%b", $data['timestamp']); + array_push($ticklabels, $datelabel); + array_push($in_data, $traf['in']); + array_push($out_data, $traf['out']); + array_push($tot_data, $traf['total']); + $average += $data['traf_total']; + } + + $ave_count = count($tot_data); + if ($imgbill != false) { + $days = (strftime('%e', date($end - $start)) - $ave_count - 1); + for ($x = 0; $x < $days; $x++) { + array_push($ticklabels, ''); + array_push($in_data, 0); + array_push($out_data, 0); + array_push($tot_data, 0); + } + } + } + else if ($imgtype == 'hour') { + foreach (dbFetch('SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY timestamp ASC', array($bill_id, $start, $end)) as $data) { + $traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0); + $traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0); + $traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0); + $datelabel = strftime('%H:%M', $data['timestamp']); + array_push($ticklabels, $datelabel); + array_push($in_data, $traf['in']); + array_push($out_data, $traf['out']); + array_push($tot_data, $traf['total']); + $average += $data['traf_total']; + } + + $ave_count = count($tot_data); + }//end if + + $decimal = 0; + $average = ($average / $ave_count); + for ($x = 0; $x <= count($tot_data); $x++) { + array_push($ave_data, $average); + } + + $graph_name = date('M j g:ia', $start).' - '.date('M j g:ia', $end); +}//end if // Create the graph. These two calls are always required $graph = new Graph($xsize, $ysize, $graph_name); -$graph->img->SetImgFormat("png"); +$graph->img->SetImgFormat('png'); -#$graph->SetScale("textlin",0,0,$start,$end); - -$graph->SetScale("textlin"); -#$graph->title->Set("$graph_name"); +// $graph->SetScale("textlin",0,0,$start,$end); +$graph->SetScale('textlin'); +// $graph->title->Set("$graph_name"); $graph->title->SetFont(FF_FONT2, FS_BOLD, 10); -$graph->SetMarginColor("white"); +$graph->SetMarginColor('white'); $graph->SetFrame(false); -$graph->SetMargin("75", "30", "30", "65"); +$graph->SetMargin('75', '30', '30', '65'); $graph->legend->SetFont(FF_FONT1, FS_NORMAL); $graph->legend->SetLayout(LEGEND_HOR); -$graph->legend->Pos("0.52", "0.91", "center"); +$graph->legend->Pos('0.52', '0.91', 'center'); $graph->xaxis->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetPos('min'); $graph->xaxis->SetTitleMargin(30); $graph->xaxis->SetTickLabels($ticklabels); -$graph->xgrid->Show(true,true); -$graph->xgrid->SetColor('#e0e0e0','#efefef'); +$graph->xgrid->Show(true, true); +$graph->xgrid->SetColor('#e0e0e0', '#efefef'); $graph->yaxis->SetFont(FF_FONT1); $graph->yaxis->SetTitleMargin(50); $graph->yaxis->title->SetFont(FF_FONT1, FS_NORMAL, 10); -$graph->yaxis->title->Set("Bytes Transferred"); +$graph->yaxis->title->Set('Bytes Transferred'); $graph->yaxis->SetLabelFormatCallback('format_bytes_billing'); -$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#FFFFFF@0.5'); +$graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#FFFFFF@0.5'); // Create the bar plots $barplot_tot = new BarPlot($tot_data); -$barplot_tot->SetLegend("Traffic total"); +$barplot_tot->SetLegend('Traffic total'); $barplot_tot->SetColor('darkgray'); $barplot_tot->SetFillColor('lightgray@0.4'); $barplot_tot->value->Show(); $barplot_tot->value->SetFormatCallback('format_bytes_billing_short'); $barplot_in = new BarPlot($in_data); -$barplot_in->SetLegend("Traffic In"); +$barplot_in->SetLegend('Traffic In'); $barplot_in->SetColor('darkgreen'); $barplot_in->SetFillColor('lightgreen@0.4'); $barplot_in->SetWeight(1); $barplot_out = new BarPlot($out_data); -$barplot_out->SetLegend("Traffic Out"); +$barplot_out->SetLegend('Traffic Out'); $barplot_out->SetColor('darkblue'); $barplot_out->SetFillColor('lightblue@0.4'); $barplot_out->SetWeight(1); -if ($imgtype == "historical") -{ - $barplot_over = new BarPlot($overuse_data); - $barplot_over->SetLegend("Traffic Overusage"); - $barplot_over->SetColor('darkred'); - $barplot_over->SetFillColor('lightred@0.4'); - $barplot_over->SetWeight(1); +if ($imgtype == 'historical') { + $barplot_over = new BarPlot($overuse_data); + $barplot_over->SetLegend('Traffic Overusage'); + $barplot_over->SetColor('darkred'); + $barplot_over->SetFillColor('lightred@0.4'); + $barplot_over->SetWeight(1); - $lineplot_allow = new LinePlot($allow_data); - $lineplot_allow->SetLegend("Traffic Allowed"); - $lineplot_allow->SetColor('black'); - $lineplot_allow->SetWeight(1); + $lineplot_allow = new LinePlot($allow_data); + $lineplot_allow->SetLegend('Traffic Allowed'); + $lineplot_allow->SetColor('black'); + $lineplot_allow->SetWeight(1); - $gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out, $barplot_over)); -} else { - $lineplot_allow = new LinePlot($ave_data); - //$lineplot_allow->SetLegend("Average per ".$imgtype); - $lineplot_allow->SetLegend("Average"); - $lineplot_allow->SetColor('black'); - $lineplot_allow->SetWeight(1); - - $gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out)); + $gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out, $barplot_over)); } +else { + $lineplot_allow = new LinePlot($ave_data); + // $lineplot_allow->SetLegend("Average per ".$imgtype); + $lineplot_allow->SetLegend('Average'); + $lineplot_allow->SetColor('black'); + $lineplot_allow->SetWeight(1); + + $gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out)); +}//end if $graph->Add($gbplot); $graph->Add($lineplot_allow); // Display the graph $graph->Stroke(); - -?> diff --git a/html/billing-graph.php b/html/billing-graph.php index 7bc995dafc..b7d9c6200c 100644 --- a/html/billing-graph.php +++ b/html/billing-graph.php @@ -1,6 +1,6 @@ * @copyright (C) 2006 - 2012 Adam Armstrong - * */ ini_set('allow_url_fopen', 0); ini_set('display_errors', 0); -if (strpos($_SERVER['REQUEST_URI'], "debug")) -{ - $debug = "1"; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); -} else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); +if (strpos($_SERVER['REQUEST_URI'], 'debug')) { + $debug = '1'; + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); +} +else { + $debug = false; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } -include("../includes/defaults.inc.php"); -include("../config.php"); -include("../includes/definitions.inc.php"); -include("../includes/functions.php"); -include("includes/functions.inc.php"); -include("includes/authenticate.inc.php"); +require '../includes/defaults.inc.php'; +require '../config.php'; +require '../includes/definitions.inc.php'; +require '../includes/functions.php'; +require 'includes/functions.inc.php'; +require 'includes/authenticate.inc.php'; -if (get_client_ip() != $_SERVER['SERVER_ADDR']) { if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } } -require("includes/jpgraph/src/jpgraph.php"); -include("includes/jpgraph/src/jpgraph_line.php"); -include("includes/jpgraph/src/jpgraph_utils.inc.php"); -include("includes/jpgraph/src/jpgraph_date.php"); - -if (is_numeric($_GET['bill_id'])) -{ - if (get_client_ip() != $_SERVER['SERVER_ADDR']) - { - if (bill_permitted($_GET['bill_id'])) - { - $bill_id = $_GET['bill_id']; - } else { - echo("Unauthorised Access Prohibited."); - exit; +if (get_client_ip() != $_SERVER['SERVER_ADDR']) { + if (!$_SESSION['authenticated']) { + echo 'unauthenticated'; + exit; } - } else { - $bill_id = $_GET['bill_id']; - } -} else { - echo("Unauthorised Access Prohibited."); - exit; +} + +require 'includes/jpgraph/src/jpgraph.php'; +require 'includes/jpgraph/src/jpgraph_line.php'; +require 'includes/jpgraph/src/jpgraph_utils.inc.php'; +require 'includes/jpgraph/src/jpgraph_date.php'; + +if (is_numeric($_GET['bill_id'])) { + if (get_client_ip() != $_SERVER['SERVER_ADDR']) { + if (bill_permitted($_GET['bill_id'])) { + $bill_id = $_GET['bill_id']; + } + else { + echo 'Unauthorised Access Prohibited.'; + exit; + } + } + else { + $bill_id = $_GET['bill_id']; + } +} +else { + echo 'Unauthorised Access Prohibited.'; + exit; } $start = $_GET[from]; -$end = $_GET[to]; +$end = $_GET[to]; $xsize = $_GET[x]; $ysize = $_GET[y]; $count = $_GET[count]; -$count = $count + 0; -$iter = 1; +$count = ($count + 0); +$iter = 1; -if ($_GET[type]) { $type = $_GET[type]; } else { $type = "date"; } - -$dur = $end - $start; - -$datefrom = date('Ymthis', $start); -$dateto = date('Ymthis', $end); - -#$rate_data = getRates($bill_id,$datefrom,$dateto); -$rate_data = dbFetchRow("SELECT * from `bills` WHERE `bill_id`= ? LIMIT 1", array($bill_id)); -$rate_95th = $rate_data['rate_95th']; -$rate_average = $rate_data['rate_average']; - -#$bi_a = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)); -#$bill_name = $bi_a['bill_name']; -$bill_name = $rate_data['bill_name']; - -$dur = $end - $start; - -$counttot = dbFetchCell("SELECT count(`delta`) FROM `bill_data` WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? )", array($bill_id, $start, $end)); - -$count = round($dur / 300 / (($ysize - 100) * 3), 0); -if ($count <= 1) { $count = 2; } - -#$count = round($counttot / 260, 0); -#if ($count <= 1) { $count = 2; } - -#$max = dbFetchCell("SELECT delta FROM bill_data WHERE bill_id = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? ) ORDER BY delta DESC LIMIT 0,1", array($bill_id, $start, $end)); -#if ($max > 1000000) { $div = "1000000"; $yaxis = "Mbit/sec"; } else { $div = "1000"; $yaxis = "Kbit/sec"; } - -$i = '0'; - -foreach (dbFetch("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? ) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $row) -{ - @$timestamp = $row['formatted_date']; - if (!$first) { $first = $timestamp; } - $delta = $row['delta']; - $period = $row['period']; - $in_delta = $row['in_delta']; - $out_delta = $row['out_delta']; - $in_value = round($in_delta * 8 / $period, 2); - $out_value = round($out_delta * 8 / $period, 2); - - $last = $timestamp; - - $iter_in += $in_delta; - $iter_out += $out_delta; - $iter_period += $period; - - if ($iter == $count) - { - $out_data[$i] = round($iter_out * 8 / $iter_period, 2); - $out_data_inv[$i] = $out_data[$i] * -1; - $in_data[$i] = round($iter_in * 8 / $iter_period, 2); - $tot_data[$i] = $out_data[$i] + $in_data[$i]; - $tot_data_inv[$i] = $tot_data[$i] * -1; - - if ($tot_data[$i] > $max_value) { $max_value = $tot_data[$i]; } - - $ticks[$i] = $timestamp; - $per_data[$i] = $rate_95th; - $ave_data[$i] = $rate_average; - $iter = "1"; - $i++; - unset($iter_out, $iter_in, $iter_period); - } - - $iter++; +if ($_GET[type]) { + $type = $_GET[type]; +} +else { + $type = 'date'; } -$graph_name = date('M j g:ia', $start) . " - " . date('M j g:ia', $last); +$dur = ($end - $start); -$n = count($ticks); +$datefrom = date('Ymthis', $start); +$dateto = date('Ymthis', $end); + +// $rate_data = getRates($bill_id,$datefrom,$dateto); +$rate_data = dbFetchRow('SELECT * from `bills` WHERE `bill_id`= ? LIMIT 1', array($bill_id)); +$rate_95th = $rate_data['rate_95th']; +$rate_average = $rate_data['rate_average']; + +// $bi_a = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)); +// $bill_name = $bi_a['bill_name']; +$bill_name = $rate_data['bill_name']; + +$dur = ($end - $start); + +$counttot = dbFetchCell('SELECT count(`delta`) FROM `bill_data` WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? )', array($bill_id, $start, $end)); + +$count = round(($dur / 300 / (($ysize - 100) * 3)), 0); +if ($count <= 1) { + $count = 2; +} + +// $count = round($counttot / 260, 0); +// if ($count <= 1) { $count = 2; } +// $max = dbFetchCell("SELECT delta FROM bill_data WHERE bill_id = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? ) ORDER BY delta DESC LIMIT 0,1", array($bill_id, $start, $end)); +// if ($max > 1000000) { $div = "1000000"; $yaxis = "Mbit/sec"; } else { $div = "1000"; $yaxis = "Kbit/sec"; } +$i = '0'; + +foreach (dbFetch('SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? ) ORDER BY timestamp ASC', array($bill_id, $start, $end)) as $row) { + @$timestamp = $row['formatted_date']; + if (!$first) { + $first = $timestamp; + } + + $delta = $row['delta']; + $period = $row['period']; + $in_delta = $row['in_delta']; + $out_delta = $row['out_delta']; + $in_value = round(($in_delta * 8 / $period), 2); + $out_value = round(($out_delta * 8 / $period), 2); + + $last = $timestamp; + + $iter_in += $in_delta; + $iter_out += $out_delta; + $iter_period += $period; + + if ($iter == $count) { + $out_data[$i] = round(($iter_out * 8 / $iter_period), 2); + $out_data_inv[$i] = ($out_data[$i] * -1); + $in_data[$i] = round(($iter_in * 8 / $iter_period), 2); + $tot_data[$i] = ($out_data[$i] + $in_data[$i]); + $tot_data_inv[$i] = ($tot_data[$i] * -1); + + if ($tot_data[$i] > $max_value) { + $max_value = $tot_data[$i]; + } + + $ticks[$i] = $timestamp; + $per_data[$i] = $rate_95th; + $ave_data[$i] = $rate_average; + $iter = '1'; + $i++; + unset($iter_out, $iter_in, $iter_period); + } + + $iter++; +}//end foreach + +$graph_name = date('M j g:ia', $start).' - '.date('M j g:ia', $last); + +$n = count($ticks); $xmin = $ticks[0]; -$xmax = $ticks[$n-1]; +$xmax = $ticks[($n - 1)]; -$graph_name = date('M j g:ia', $xmin) . " - " . date('M j g:ia', $xmax); +$graph_name = date('M j g:ia', $xmin).' - '.date('M j g:ia', $xmax); $graph = new Graph($xsize, $ysize, $graph_name); -$graph->img->SetImgFormat("png"); +$graph->img->SetImgFormat('png'); -$graph->SetScale('datlin',0,0,$start,$end); +$graph->SetScale('datlin', 0, 0, $start, $end); -#$graph->title->Set("$graph_name"); -$graph->title->SetFont(FF_FONT2,FS_BOLD,10); -$graph->xaxis->SetFont(FF_FONT1,FS_BOLD); +// $graph->title->Set("$graph_name"); +$graph->title->SetFont(FF_FONT2, FS_BOLD, 10); +$graph->xaxis->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetTextLabelInterval(2); $graph->xaxis->SetPos('min'); -#$graph->xaxis->SetLabelAngle(15); +// $graph->xaxis->SetLabelAngle(15); $graph->yaxis->HideZeroLabel(1); $graph->yaxis->SetFont(FF_FONT1); $graph->yaxis->SetLabelAngle(0); -$graph->xaxis->title->SetFont(FF_FONT1,FS_NORMAL,10); -$graph->yaxis->title->SetFont(FF_FONT1,FS_NORMAL,10); +$graph->xaxis->title->SetFont(FF_FONT1, FS_NORMAL, 10); +$graph->yaxis->title->SetFont(FF_FONT1, FS_NORMAL, 10); $graph->yaxis->SetTitleMargin(50); $graph->xaxis->SetTitleMargin(30); -#$graph->xaxis->HideLastTickLabel(); -#$graph->xaxis->HideFirstTickLabel(); -#$graph->yaxis->scale->SetAutoMin(1); +// $graph->xaxis->HideLastTickLabel(); +// $graph->xaxis->HideFirstTickLabel(); +// $graph->yaxis->scale->SetAutoMin(1); $graph->xaxis->title->Set($type); -$graph->yaxis->title->Set("Bits per second"); -$graph->yaxis->SetLabelFormatCallback("format_si"); +$graph->yaxis->title->Set('Bits per second'); +$graph->yaxis->SetLabelFormatCallback('format_si'); + function TimeCallback($aVal) { global $dur; - if ($dur < 172800) - { - return Date('H:i',$aVal); - } elseif ($dur < 604800) { - return Date('D',$aVal); - } else { - return Date('j M',$aVal); + if ($dur < 172800) { + return date('H:i', $aVal); } -} + else if ($dur < 604800) { + return date('D', $aVal); + } + else { + return date('j M', $aVal); + } + +}//end TimeCallback() + $graph->xaxis->SetLabelFormatCallback('TimeCallBack'); -$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#FFFFFF@0.5'); -$graph->xgrid->Show(true,true); -$graph->xgrid->SetColor('#e0e0e0','#efefef'); +$graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#FFFFFF@0.5'); +$graph->xgrid->Show(true, true); +$graph->xgrid->SetColor('#e0e0e0', '#efefef'); $graph->SetMarginColor('white'); $graph->SetFrame(false); -$graph->SetMargin(75,30,30,45); -$graph->legend->SetFont(FF_FONT1,FS_NORMAL); +$graph->SetMargin(75, 30, 30, 45); +$graph->legend->SetFont(FF_FONT1, FS_NORMAL); $lineplot = new LinePlot($tot_data, $ticks); -$lineplot->SetLegend("Traffic total"); -$lineplot->SetColor("#d5d5d5"); -$lineplot->SetFillColor("#d5d5d5@0.5"); - -#$lineplot2 = new LinePlot($tot_data_inv, $ticks); -#$lineplot2->SetColor("#d5d5d5"); -#$lineplot2->SetFillColor("#d5d5d5@0.5"); +$lineplot->SetLegend('Traffic total'); +$lineplot->SetColor('#d5d5d5'); +$lineplot->SetFillColor('#d5d5d5@0.5'); +// $lineplot2 = new LinePlot($tot_data_inv, $ticks); +// $lineplot2->SetColor("#d5d5d5"); +// $lineplot2->SetFillColor("#d5d5d5@0.5"); $lineplot_in = new LinePlot($in_data, $ticks); -$lineplot_in->SetLegend("Traffic In"); +$lineplot_in->SetLegend('Traffic In'); $lineplot_in->SetColor('darkgreen'); $lineplot_in->SetFillColor('lightgreen@0.4'); $lineplot_in->SetWeight(1); $lineplot_out = new LinePlot($out_data_inv, $ticks); -$lineplot_out->SetLegend("Traffic Out"); +$lineplot_out->SetLegend('Traffic Out'); $lineplot_out->SetColor('darkblue'); $lineplot_out->SetFillColor('lightblue@0.4'); $lineplot_out->SetWeight(1); -if ($_GET['95th']) -{ - $lineplot_95th = new LinePlot($per_data, $ticks); - $lineplot_95th ->SetColor("red"); +if ($_GET['95th']) { + $lineplot_95th = new LinePlot($per_data, $ticks); + $lineplot_95th->SetColor('red'); } -if ($_GET['ave']) -{ - $lineplot_ave = new LinePlot($ave_data, $ticks); - $lineplot_ave ->SetColor("red"); +if ($_GET['ave']) { + $lineplot_ave = new LinePlot($ave_data, $ticks); + $lineplot_ave->SetColor('red'); } $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->Pos(0.52, 0.90, 'center'); $graph->Add($lineplot); -#$graph->Add($lineplot2); - +// $graph->Add($lineplot2); $graph->Add($lineplot_in); $graph->Add($lineplot_out); -if ($_GET['95th']) -{ - $graph->Add($lineplot_95th); +if ($_GET['95th']) { + $graph->Add($lineplot_95th); } -if ($_GET['ave']) -{ - $graph->Add($lineplot_ave); +if ($_GET['ave']) { + $graph->Add($lineplot_ave); } $graph->stroke(); - -?> diff --git a/html/csv.php b/html/csv.php index 1f9dee0ca8..19203237de 100644 --- a/html/csv.php +++ b/html/csv.php @@ -12,41 +12,42 @@ * the source code distribution for details. */ -if (strpos($_SERVER['PATH_INFO'], "debug")) -{ - $debug = "1"; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); -} else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); +if (strpos($_SERVER['PATH_INFO'], 'debug')) { + $debug = '1'; + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); +} +else { + $debug = false; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } -include "../includes/defaults.inc.php"; -include "../config.php"; -include_once "../includes/definitions.inc.php"; -include "../includes/functions.php"; -include "includes/functions.inc.php"; -include "includes/vars.inc.php"; -include "includes/authenticate.inc.php"; +require '../includes/defaults.inc.php'; +require '../config.php'; +require_once '../includes/definitions.inc.php'; +require '../includes/functions.php'; +require 'includes/functions.inc.php'; +require 'includes/vars.inc.php'; +require 'includes/authenticate.inc.php'; $report = mres($vars['report']); -if( !empty($report) && file_exists("includes/reports/$report.csv.inc.php")) { - if( $debug == false ) { - header("Content-Type: text/csv"); - header('Content-Disposition: attachment; filename="'.$report.'-'.date('Ymd').'.csv"'); - } - $csv = array(); - include_once "includes/reports/$report.csv.inc.php"; - foreach( $csv as $line ) { - echo implode(',',$line)."\n"; - } -} else { - echo "Report not found.\n"; +if (!empty($report) && file_exists("includes/reports/$report.csv.inc.php")) { + if ($debug == false) { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="'.$report.'-'.date('Ymd').'.csv"'); + } + + $csv = array(); + include_once "includes/reports/$report.csv.inc.php"; + foreach ($csv as $line) { + echo implode(',', $line)."\n"; + } +} +else { + echo "Report not found.\n"; } -?> diff --git a/html/data.php b/html/data.php index ce08fd6775..b55d09c32b 100644 --- a/html/data.php +++ b/html/data.php @@ -9,44 +9,38 @@ * @subpackage webinterface * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ // FIXME - fewer includes! +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once '../includes/common.php'; +require_once '../includes/dbFacile.php'; +require_once '../includes/rewrites.php'; +require_once 'includes/functions.inc.php'; +require_once 'includes/authenticate.inc.php'; -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); -include_once("../includes/common.php"); -include_once("../includes/dbFacile.php"); -include_once("../includes/rewrites.php"); -include_once("includes/functions.inc.php"); -include_once("includes/authenticate.inc.php"); +require_once '../includes/snmp.inc.php'; -include_once("../includes/snmp.inc.php"); - -if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) -{ - $port = get_port_by_id($_GET['id']); - $device = device_by_id_cache($port['device_id']); - $title = generate_device_link($device); - $title .= " :: Port ".generate_port_link($port); - $auth = TRUE; +if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) { + $port = get_port_by_id($_GET['id']); + $device = device_by_id_cache($port['device_id']); + $title = generate_device_link($device); + $title .= ' :: Port '.generate_port_link($port); + $auth = true; } -$in = snmp_get($device, "ifInOctets.".$port['ifIndex'], "-OUqnv", "IF-MIB"); -$out = snmp_get($device, "ifOutOctets.".$port['ifIndex'], "-OUqnv", "IF-MIB"); -if(empty($in)) -{ - $in = snmp_get($device, "ifHCInOctets.".$port['ifIndex'], "-OUqnv", "IF-MIB"); +$in = snmp_get($device, 'ifInOctets.'.$port['ifIndex'], '-OUqnv', 'IF-MIB'); +$out = snmp_get($device, 'ifOutOctets.'.$port['ifIndex'], '-OUqnv', 'IF-MIB'); +if (empty($in)) { + $in = snmp_get($device, 'ifHCInOctets.'.$port['ifIndex'], '-OUqnv', 'IF-MIB'); } -if(empty($out)) -{ - $out = snmp_get($device, "ifHCOutOctets.".$port['ifIndex'], "-OUqnv", "IF-MIB"); + +if (empty($out)) { + $out = snmp_get($device, 'ifHCOutOctets.'.$port['ifIndex'], '-OUqnv', 'IF-MIB'); } $time = time(); printf("%lf|%s|%s\n", time(), $in, $out); - -?> diff --git a/html/form_new_config.php b/html/form_new_config.php index 6f45a3d6c4..a993066e53 100644 --- a/html/form_new_config.php +++ b/html/form_new_config.php @@ -14,86 +14,75 @@ enable_debug(); -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); -include_once("includes/functions.inc.php"); -include_once("../includes/functions.php"); -include_once("includes/authenticate.inc.php"); +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once 'includes/functions.inc.php'; +require_once '../includes/functions.php'; +require_once 'includes/authenticate.inc.php'; -if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } +if (!$_SESSION['authenticated']) { + echo 'unauthenticated'; + exit; +} $new_conf_type = $_POST['new_conf_type']; $new_conf_name = $_POST['new_conf_name']; $new_conf_desc = $_POST['new_conf_desc']; -if(empty($new_conf_name)) -{ - echo("You haven't specified a config name"); - exit; +if (empty($new_conf_name)) { + echo "You haven't specified a config name"; + exit; } -elseif(empty($new_conf_desc)) -{ - echo("You haven't specified a config description"); - exit; +else if (empty($new_conf_desc)) { + echo "You haven't specified a config description"; + exit; } -elseif(empty($_POST['new_conf_single_value']) && empty($_POST['new_conf_multi_value'])) -{ - echo("You haven't specified a config value"); - exit; +else if (empty($_POST['new_conf_single_value']) && empty($_POST['new_conf_multi_value'])) { + echo "You haven't specified a config value"; + exit; } $db_inserted = '0'; -if($new_conf_type == 'Single') -{ - $new_conf_type = 'single'; - $new_conf_value = $_POST['new_conf_single_value']; - $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); +if ($new_conf_type == 'Single') { + $new_conf_type = 'single'; + $new_conf_value = $_POST['new_conf_single_value']; + $db_inserted = add_config_item($new_conf_name, $new_conf_value, $new_conf_type, $new_conf_desc); } -elseif($new_conf_type == 'Single Array') -{ - $new_conf_type = 'single-array'; - $new_conf_value = $_POST['new_conf_single_value']; - $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); -} -elseif($new_conf_type == 'Standard Array' || $new_conf_type == 'Multi Array') -{ - if($new_conf_type == 'Standard Array') - { - $new_conf_type = 'array'; - } - elseif($new_conf_type == 'Multi Array') - { - $new_conf_type = 'multi-array'; - } - else - { - # $new_conf_type is invalid so clear values so we don't create any config - $new_conf_value = ''; - } - $new_conf_value = nl2br($_POST['new_conf_multi_value']); - $values = explode('
    ',$new_conf_value); - foreach ($values as $item) - { - $new_conf_value = trim($item); - $db_inserted = add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc); - } -} -else -{ - echo('Bad config type!'); - $db_inserted = 0; - exit; +else if ($new_conf_type == 'Single Array') { + $new_conf_type = 'single-array'; + $new_conf_value = $_POST['new_conf_single_value']; + $db_inserted = add_config_item($new_conf_name, $new_conf_value, $new_conf_type, $new_conf_desc); } +else if ($new_conf_type == 'Standard Array' || $new_conf_type == 'Multi Array') { + if ($new_conf_type == 'Standard Array') { + $new_conf_type = 'array'; + } + else if ($new_conf_type == 'Multi Array') { + $new_conf_type = 'multi-array'; + } + else { + // $new_conf_type is invalid so clear values so we don't create any config + $new_conf_value = ''; + } -if($db_inserted == 1) -{ - echo('Your new config item has been added'); -} -else -{ - echo('An error occurred adding your config item to the database'); + $new_conf_value = nl2br($_POST['new_conf_multi_value']); + $values = explode('
    ', $new_conf_value); + foreach ($values as $item) { + $new_conf_value = trim($item); + $db_inserted = add_config_item($new_conf_name, $new_conf_value, $new_conf_type, $new_conf_desc); + } } +else { + echo 'Bad config type!'; + $db_inserted = 0; + exit; +}//end if -?> +if ($db_inserted == 1) { + echo 'Your new config item has been added'; +} +else { + echo 'An error occurred adding your config item to the database'; +} diff --git a/html/forms/ack-alert.inc.php b/html/forms/ack-alert.inc.php index 873aabc128..351825fb7d 100644 --- a/html/forms/ack-alert.inc.php +++ b/html/forms/ack-alert.inc.php @@ -13,25 +13,29 @@ */ $alert_id = mres($_POST['alert_id']); -$state = mres($_POST['state']); -if(!is_numeric($alert_id)) { - echo('ERROR: No alert selected'); +$state = mres($_POST['state']); +if (!is_numeric($alert_id)) { + echo 'ERROR: No alert selected'; exit; -} elseif(!is_numeric($state)) { - echo('ERROR: No state passed'); +} +else if (!is_numeric($state)) { + echo 'ERROR: No state passed'; exit; -} else { - if($state == 2) { - $state = dbFetchCell('SELECT alerted FROM alerts WHERE id = ?',array($alert_id)); - } elseif($state >= 1) { +} +else { + if ($state == 2) { + $state = dbFetchCell('SELECT alerted FROM alerts WHERE id = ?', array($alert_id)); + } + else if ($state >= 1) { $state = 2; } - if(dbUpdate(array('state' => $state), 'alerts', 'id=?',array($alert_id)) >= 0) { - echo('Alert acknowledged status changed.'); - exit; - } else { - echo('ERROR: Alert has not been acknowledged.'); - exit; - } -} + if (dbUpdate(array('state' => $state), 'alerts', 'id=?', array($alert_id)) >= 0) { + echo 'Alert acknowledged status changed.'; + exit; + } + else { + echo 'ERROR: Alert has not been acknowledged.'; + exit; + } +}//end if diff --git a/html/forms/alert-templates.inc.php b/html/forms/alert-templates.inc.php index 5838e9ae3f..0dc3ff58cd 100644 --- a/html/forms/alert-templates.inc.php +++ b/html/forms/alert-templates.inc.php @@ -4,12 +4,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 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. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -44,35 +44,43 @@ if(!empty($name)) { } if(dbUpdate(array('rule_id' => mres($_REQUEST['rule_id']), 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) { $ok = "Updated template and rule id mapping"; - } else { + } + else { $error ="Failed to update the template and rule id mapping"; } - } elseif( $_REQUEST['template'] && is_numeric($_REQUEST['template_id']) ) { + } + elseif( $_REQUEST['template'] && is_numeric($_REQUEST['template_id']) ) { //Update template-text if($ret = dbUpdate(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) { $ok = "Updated template"; - } else { + } + else { $error = "Failed to update the template"; } - } elseif( $_REQUEST['template'] ) { + } + elseif( $_REQUEST['template'] ) { //Create new template if(dbInsert(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates")) { $ok = "Alert template has been created."; - } else { + } + else { $error = "Could not create alert template"; } - } else { + } + else { $error = "We could not work out what you wanted to do!"; } -} else { +} +else { $error = "You haven't given your template a name, it feels sad :( - $name"; } if(!empty( $ok )) { die("$ok"); -} else { +} +else { die("ERROR: $error"); } ?> diff --git a/html/forms/attach-alert-template.inc.php b/html/forms/attach-alert-template.inc.php index 5278fcf524..efa97f01eb 100644 --- a/html/forms/attach-alert-template.inc.php +++ b/html/forms/attach-alert-template.inc.php @@ -12,30 +12,32 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -if(!is_numeric($_POST['template_id'])) { - echo('ERROR: No template selected'); +if (!is_numeric($_POST['template_id'])) { + echo 'ERROR: No template selected'; exit; -} else { - $rules = preg_split("/,/",mres($_POST['rule_id'])); - $success = FALSE; +} +else { + $rules = preg_split('/,/', mres($_POST['rule_id'])); + $success = false; foreach ($rules as $rule_id) { $db_id = dbInsert(array('alert_rule_id' => $rule_id, 'alert_templates_id' => mres($_POST['template_id'])), 'alert_template_map'); if ($db_id > 0) { - $success = TRUE; - $ids[] = $db_id; - } else { - echo('ERROR: Alert rules have not been attached to this template.'); + $success = true; + $ids[] = $db_id; + } + else { + echo 'ERROR: Alert rules have not been attached to this template.'; exit; } } - if ($success === TRUE) { - dbDelete('alert_template_map',"id NOT IN (".implode(',',$ids).")"); + + if ($success === true) { + dbDelete('alert_template_map', 'id NOT IN ('.implode(',', $ids).')'); echo "Alert rules have been attached to this template. $template_map_ids"; exit; } -} - +}//end if diff --git a/html/forms/callback-statistics.inc.php b/html/forms/callback-statistics.inc.php index 22f65e71d1..7e934b22db 100644 --- a/html/forms/callback-statistics.inc.php +++ b/html/forms/callback-statistics.inc.php @@ -14,9 +14,11 @@ if ($_POST['state'] == 'true') { $state = 1; -} elseif ($_POST['state'] == 'false') { +} +elseif ($_POST['state'] == 'false') { $state = 0; -} else { +} +else { $state = 0; } diff --git a/html/forms/config-item-disable.inc.php b/html/forms/config-item-disable.inc.php index e44f6afdc0..73ebfa5a2f 100644 --- a/html/forms/config-item-disable.inc.php +++ b/html/forms/config-item-disable.inc.php @@ -13,36 +13,28 @@ */ // FUA - -if(!is_numeric($_POST['config_id'])) -{ - echo('error with data'); - exit; -} -else -{ - if($_POST['state'] == 'true') - { - $state = 1; - } - elseif($_POST['state'] == 'false') - { - $state = 0; - } - else - { - $state = 0; - } - $update = dbUpdate(array('config_disabled' => $state), 'config', '`config_id` = ?', array($_POST['config_id'])); - if(!empty($update) || $update == '0') - { - echo('success'); +if (!is_numeric($_POST['config_id'])) { + echo 'error with data'; exit; - } - else - { - echo('error'); - exit; - } } +else { + if ($_POST['state'] == 'true') { + $state = 1; + } + else if ($_POST['state'] == 'false') { + $state = 0; + } + else { + $state = 0; + } + $update = dbUpdate(array('config_disabled' => $state), 'config', '`config_id` = ?', array($_POST['config_id'])); + if (!empty($update) || $update == '0') { + echo 'success'; + exit; + } + else { + echo 'error'; + exit; + } +}//end if diff --git a/html/forms/config-item-update.inc.php b/html/forms/config-item-update.inc.php index 9ba7957861..bb8c12559c 100644 --- a/html/forms/config-item-update.inc.php +++ b/html/forms/config-item-update.inc.php @@ -13,25 +13,19 @@ */ // FUA - -if(!is_numeric($_POST['config_id']) || empty($_POST['data'])) -{ - echo('error with data'); - exit; -} -else -{ - $data = mres($_POST['data']); - $update = dbUpdate(array('config_value' => "$data"), 'config', '`config_id` = ?', array($_POST['config_id'])); - if(!empty($update) || $update == '0') - { - echo('success'); +if (!is_numeric($_POST['config_id']) || empty($_POST['data'])) { + echo 'error with data'; exit; - } - else - { - echo('error'); - exit; - } } - +else { + $data = mres($_POST['data']); + $update = dbUpdate(array('config_value' => "$data"), 'config', '`config_id` = ?', array($_POST['config_id'])); + if (!empty($update) || $update == '0') { + echo 'success'; + exit; + } + else { + echo 'error'; + exit; + } +} diff --git a/html/forms/config-item.inc.php b/html/forms/config-item.inc.php index 46def6626a..8e35c10ccd 100644 --- a/html/forms/config-item.inc.php +++ b/html/forms/config-item.inc.php @@ -12,121 +12,145 @@ * the source code distribution for details. */ -if(is_admin() === false) { - $response = array('status'=>'error','message'=>'Need to be admin'); +if (is_admin() === false) { + $response = array( + 'status' => 'error', + 'message' => 'Need to be admin', + ); echo _json_encode($response); exit; } -$action = mres($_POST['action']); -$config_group = mres($_POST['config_group']); +$action = mres($_POST['action']); +$config_group = mres($_POST['config_group']); $config_sub_group = mres($_POST['config_sub_group']); -$config_name = mres($_POST['config_name']); -$config_value = mres($_POST['config_value']); -$config_extra = mres($_POST['config_extra']); -$config_room_id = mres($_POST['config_room_id']); -$config_from = mres($_POST['config_from']); -$config_userkey = mres($_POST['config_userkey']); -$status = 'error'; -$message = 'Error with config'; +$config_name = mres($_POST['config_name']); +$config_value = mres($_POST['config_value']); +$config_extra = mres($_POST['config_extra']); +$config_room_id = mres($_POST['config_room_id']); +$config_from = mres($_POST['config_from']); +$config_userkey = mres($_POST['config_userkey']); +$status = 'error'; +$message = 'Error with config'; if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover') { $config_id = mres($_POST['config_id']); if (empty($config_id)) { $message = 'No config id passed'; - } else { + } + else { if (dbDelete('config', '`config_id`=?', array($config_id))) { if ($action == 'remove-slack') { dbDelete('config', "`config_name` LIKE 'alert.transports.slack.$config_id.%'"); - } elseif ($action == 'remove-hipchat') { + } + else if ($action == 'remove-hipchat') { dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.$config_id.%'"); - } elseif ($action == 'remove-pushover') { + } + else if ($action == 'remove-pushover') { dbDelete('config', "`config_name` LIKE 'alert.transports.pushover.$config_id.%'"); } - $status = 'ok'; + + $status = 'ok'; $message = 'Config item removed'; - } else { + } + else { $message = 'General error, could not remove config'; } } -} elseif ($action == 'add-slack') { +} +else if ($action == 'add-slack') { if (empty($config_value)) { $message = 'No Slack url provided'; - } else { - $config_id = dbInsert(array('config_name' => 'alert.transports.slack.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Slack Transport'), 'config'); + } + else { + $config_id = dbInsert(array('config_name' => 'alert.transports.slack.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Slack Transport'), 'config'); if ($config_id > 0) { dbUpdate(array('config_name' => 'alert.transports.slack.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); - $status = 'ok'; + $status = 'ok'; $message = 'Config item created'; - $extras = explode('\n',$config_extra); + $extras = explode('\n', $config_extra); foreach ($extras as $option) { - list($k,$v) = explode("=", $option,2); + list($k,$v) = explode('=', $option, 2); if (!empty($k) || !empty($v)) { - dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Slack Transport'), 'config'); + dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Slack Transport'), 'config'); } } - } else { - $message = 'Could not create config item'; } - } -} elseif ($action == 'add-hipchat') { - if (empty($config_value) || empty($config_room_id) || empty($config_from)) { - $message = 'No hipchat url, room id or from provided'; - } else { - $config_id = dbInsert(array('config_name' => 'alert.transports.hipchat.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Hipchat Transport'), 'config'); - if ($config_id > 0) { - dbUpdate(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); - $additional_id['room_id'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.room_id', 'config_value' => $config_room_id, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_room_id, 'config_descr'=>'Hipchat URL'), 'config'); - $additional_id['from'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.from', 'config_value' => $config_from, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_from, 'config_descr'=>'Hipchat From'), 'config'); - $status = 'ok'; - $message = 'Config item created'; - $extras = explode('\n',$config_extra); - foreach ($extras as $option) { - list($k,$v) = explode("=", $option,2); - if (!empty($k) || !empty($v)) { - dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Hipchat '.$v), 'config'); - } - } - } else { - $message = 'Could not create config item'; - } - } -} elseif ($action == 'add-pushover') { - if (empty($config_value) || empty($config_userkey)) { - $message = 'No pushover appkey or userkey provided'; - } else { - $config_id = dbInsert(array('config_name' => 'alert.transports.pushover.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'Pushover Transport'), 'config'); - if ($config_id > 0) { - dbUpdate(array('config_name' => 'alert.transports.pushover.'.$config_id.'.appkey'), 'config', 'config_id=?', array($config_id)); - $additional_id['userkey'] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.userkey', 'config_value' => $config_userkey, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_userkey, 'config_descr'=>'Pushver Userkey'), 'config'); - $status = 'ok'; - $message = 'Config item created'; - $extras = explode('\n',$config_extra); - foreach ($extras as $option) { - list($k,$v) = explode("=", $option,2); - if (!empty($k) || !empty($v)) { - dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$v, 'config_descr'=>'Pushover '.$v), 'config'); - } - } - } else { - $message = 'Could not create config item'; - } - } -} else { - - if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) { - $message = 'Missing config name or value'; - } else { - $config_id = dbInsert(array('config_name' => $config_name, 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default'=>$config_value, 'config_descr'=>'API Transport'), 'config'); - if ($config_id > 0) { - dbUpdate(array('config_name'=>$config_name.$config_id),'config','config_id=?',array($config_id)); - $status = 'ok'; - $message = 'Config item created'; - } else { + else { $message = 'Could not create config item'; } } } +else if ($action == 'add-hipchat') { + if (empty($config_value) || empty($config_room_id) || empty($config_from)) { + $message = 'No hipchat url, room id or from provided'; + } + else { + $config_id = dbInsert(array('config_name' => 'alert.transports.hipchat.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Hipchat Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); + $additional_id['room_id'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.room_id', 'config_value' => $config_room_id, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_room_id, 'config_descr' => 'Hipchat URL'), 'config'); + $additional_id['from'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.from', 'config_value' => $config_from, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_from, 'config_descr' => 'Hipchat From'), 'config'); + $status = 'ok'; + $message = 'Config item created'; + $extras = explode('\n', $config_extra); + foreach ($extras as $option) { + list($k,$v) = explode('=', $option, 2); + if (!empty($k) || !empty($v)) { + dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Hipchat '.$v), 'config'); + } + } + } + else { + $message = 'Could not create config item'; + } + }//end if +} +else if ($action == 'add-pushover') { + if (empty($config_value) || empty($config_userkey)) { + $message = 'No pushover appkey or userkey provided'; + } + else { + $config_id = dbInsert(array('config_name' => 'alert.transports.pushover.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Pushover Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name' => 'alert.transports.pushover.'.$config_id.'.appkey'), 'config', 'config_id=?', array($config_id)); + $additional_id['userkey'] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.userkey', 'config_value' => $config_userkey, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_userkey, 'config_descr' => 'Pushver Userkey'), 'config'); + $status = 'ok'; + $message = 'Config item created'; + $extras = explode('\n', $config_extra); + foreach ($extras as $option) { + list($k,$v) = explode('=', $option, 2); + if (!empty($k) || !empty($v)) { + dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Pushover '.$v), 'config'); + } + } + } + else { + $message = 'Could not create config item'; + } + } +} +else { + if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) { + $message = 'Missing config name or value'; + } + else { + $config_id = dbInsert(array('config_name' => $config_name, 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'API Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name' => $config_name.$config_id), 'config', 'config_id=?', array($config_id)); + $status = 'ok'; + $message = 'Config item created'; + } + else { + $message = 'Could not create config item'; + } + } +}//end if -$response = array('status'=>$status,'message'=>$message, 'config_id'=>$config_id, 'additional_id'=>$additional_id); +$response = array( + 'status' => $status, + 'message' => $message, + 'config_id' => $config_id, + 'additional_id' => $additional_id, +); echo _json_encode($response); diff --git a/html/forms/create-alert-item.inc.php b/html/forms/create-alert-item.inc.php index a3f021bfde..1d3ae7e77b 100644 --- a/html/forms/create-alert-item.inc.php +++ b/html/forms/create-alert-item.inc.php @@ -12,68 +12,85 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -$rule = implode(" ", $_POST['rules']); -$rule = rtrim($rule,'&&'); -$rule = rtrim($rule,'||'); +$rule = implode(' ', $_POST['rules']); +$rule = rtrim($rule, '&&'); +$rule = rtrim($rule, '||'); $alert_id = $_POST['alert_id']; -$count = mres($_POST['count']); -$delay = mres($_POST['delay']); +$count = mres($_POST['count']); +$delay = mres($_POST['delay']); $interval = mres($_POST['interval']); -$mute = mres($_POST['mute']); -$invert = mres($_POST['invert']); -$name = mres($_POST['name']); +$mute = mres($_POST['mute']); +$invert = mres($_POST['invert']); +$name = mres($_POST['name']); -if(empty($rule)) { - $update_message = "ERROR: No rule was generated - did you forget to click and / or?"; -} elseif(validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' || $_POST['device_id'][0] == ':') { +if (empty($rule)) { + $update_message = 'ERROR: No rule was generated - did you forget to click and / or?'; +} +else if (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' || $_POST['device_id'][0] == ':') { $device_id = $_POST['device_id']; - if(!is_numeric($count)) { - $count='-1'; + if (!is_numeric($count)) { + $count = '-1'; } - $delay_sec = convert_delay($delay); + + $delay_sec = convert_delay($delay); $interval_sec = convert_delay($interval); - if($mute == 'on') { + if ($mute == 'on') { $mute = true; - } else { + } + else { $mute = false; } - if($invert == 'on') { + + if ($invert == 'on') { $invert = true; - } else { + } + else { $invert = false; } - $extra = array('mute'=>$mute,'count'=>$count,'delay'=>$delay_sec,'invert'=>$invert,'interval'=>$interval_sec); + + $extra = array( + 'mute' => $mute, + 'count' => $count, + 'delay' => $delay_sec, + 'invert' => $invert, + 'interval' => $interval_sec, + ); $extra_json = json_encode($extra); - if(is_numeric($alert_id) && $alert_id > 0) { - if(dbUpdate(array('rule' => $rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json,'name'=>$name), 'alert_rules', 'id=?',array($alert_id)) >= 0) { + if (is_numeric($alert_id) && $alert_id > 0) { + if (dbUpdate(array('rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name), 'alert_rules', 'id=?', array($alert_id)) >= 0) { $update_message = "Edited Rule: $name: $rule"; - } else { - $update_message = "ERROR: Failed to edit Rule: ".$rule.""; } - } else { - if( is_array($_POST['maps']) ) { + else { + $update_message = 'ERROR: Failed to edit Rule: '.$rule.''; + } + } + else { + if (is_array($_POST['maps'])) { $device_id = ':'.$device_id; } - if( dbInsert(array('device_id'=>$device_id,'rule'=>$rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json,'name'=>$name),'alert_rules') ) { + + if (dbInsert(array('device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name), 'alert_rules')) { $update_message = "Added Rule: $name: $rule"; - if( is_array($_POST['maps']) ) { - foreach( $_POST['maps'] as $target ) { - $_POST['rule'] = $name; + if (is_array($_POST['maps'])) { + foreach ($_POST['maps'] as $target) { + $_POST['rule'] = $name; $_POST['target'] = $target; $_POST['map_id'] = ''; - include('forms/create-map-item.inc.php'); + include 'forms/create-map-item.inc.php'; unset($ret,$target,$raw,$rule,$msg,$map_id); } } - } else { - $update_message = "ERROR: Failed to add Rule: ".$rule.""; } - } -} else { - $update_message = "ERROR: invalid device ID or not a global alert"; + else { + $update_message = 'ERROR: Failed to add Rule: '.$rule.''; + } + }//end if } +else { + $update_message = 'ERROR: invalid device ID or not a global alert'; +}//end if echo $update_message; diff --git a/html/forms/create-device-group.inc.php b/html/forms/create-device-group.inc.php index 0992f73a12..ef82a16394 100644 --- a/html/forms/create-device-group.inc.php +++ b/html/forms/create-device-group.inc.php @@ -12,39 +12,46 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -$pattern = $_POST['patterns']; +$pattern = $_POST['patterns']; $group_id = $_POST['group_id']; -$name = mres($_POST['name']); -$desc = mres($_POST['desc']); +$name = mres($_POST['name']); +$desc = mres($_POST['desc']); -if( is_array($pattern) ) { - $pattern = implode(" ", $pattern); -} elseif( !empty($_POST['pattern']) && !empty($_POST['condition']) && !empty($_POST['value']) ) { - $pattern = '%'.$_POST['pattern'].' '.$_POST['condition'].' '; - if( is_numeric($_POST['value']) ) { - $pattern .= $_POST['value']; - } else { - $pattern .= '"'.$_POST['value'].'"'; - } +if (is_array($pattern)) { + $pattern = implode(' ', $pattern); +} +else if (!empty($_POST['pattern']) && !empty($_POST['condition']) && !empty($_POST['value'])) { + $pattern = '%'.$_POST['pattern'].' '.$_POST['condition'].' '; + if (is_numeric($_POST['value'])) { + $pattern .= $_POST['value']; + } + else { + $pattern .= '"'.$_POST['value'].'"'; + } } -if(empty($pattern)) { - $update_message = "ERROR: No group was generated"; -} elseif(is_numeric($group_id) && $group_id > 0) { - if(dbUpdate(array('pattern' => $pattern,'name'=>$name,'desc'=>$desc), 'device_groups', 'id=?',array($group_id)) >= 0) { - $update_message = "Edited Group: $name: $pattern"; - } else { - $update_message = "ERROR: Failed to edit Group: ".$pattern.""; +if (empty($pattern)) { + $update_message = 'ERROR: No group was generated'; +} +else if (is_numeric($group_id) && $group_id > 0) { + if (dbUpdate(array('pattern' => $pattern, 'name' => $name, 'desc' => $desc), 'device_groups', 'id=?', array($group_id)) >= 0) { + $update_message = "Edited Group: $name: $pattern"; } -} else { - if( dbInsert(array('pattern'=>$pattern,'name'=>$name,'desc'=>$desc),'device_groups') ) { + else { + $update_message = 'ERROR: Failed to edit Group: '.$pattern.''; + } +} +else { + if (dbInsert(array('pattern' => $pattern, 'name' => $name, 'desc' => $desc), 'device_groups')) { $update_message = "Added Group: $name: $pattern"; - } else { - $update_message = "ERROR: Failed to add Group: ".$pattern.""; + } + else { + $update_message = 'ERROR: Failed to add Group: '.$pattern.''; } } + echo $update_message; diff --git a/html/forms/create-map-item.inc.php b/html/forms/create-map-item.inc.php index 52670ac8a4..28062d02fb 100644 --- a/html/forms/create-map-item.inc.php +++ b/html/forms/create-map-item.inc.php @@ -12,7 +12,7 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } @@ -21,46 +21,56 @@ $target = mres($_POST['target']); $map_id = mres($_POST['map_id']); $ret = array(); -if( empty($rule) || empty($target) ) { - $ret[] = "ERROR: No map was generated"; -} else { - $raw = $rule; - $rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?',array($rule)); - if( !is_numeric($rule) ) { - array_unshift($ret, "ERROR: Could not find rule for '".$raw."'"); - } else { - $raw = $target; - if( $target[0].$target[1] == "g:" ) { - $target = "g".dbFetchCell('SELECT id FROM device_groups WHERE name = ?',array(substr($target,2))); - } else { - $target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?',array($target)); - } - if( !is_numeric(str_replace('g','',$target)) ) { - array_unshift($ret, "ERROR: Could not find entry for '".$raw."'"); - } else { - if(is_numeric($map_id) && $map_id > 0) { - if(dbUpdate(array('rule' => $rule,'target'=>$target), 'alert_map', 'id=?',array($map_id)) >= 0) { - $ret[] = "Edited Map: ".$map_id.": ".$rule." = ".$target.""; - } else { - array_unshift($ret,"ERROR: Failed to edit Map: ".$map_id.": ".$rule." = ".$target.""); - } - } else { - if( dbInsert(array('rule'=>$rule,'target'=>$target),'alert_map') ) { - $ret[] = "Added Map: ".$rule." = ".$target.""; - } else { - array_unshift($ret,"ERROR: Failed to add Map: ".$rule." = ".$target.""); - } - } - if( ($tmp=dbFetchCell('SELECT device_id FROM alert_rules WHERE id = ?',array($rule))) && $tmp[0] != ":" ) { - if(dbUpdate(array('device_id' => ':'.$tmp), 'alert_rules', 'id=?',array($rule)) >= 0) { - $ret[] = "Edited Rule: ".$rule." device_id = ':".$tmp."'"; - } else { - array_unshift($ret,"ERROR: Failed to edit Rule: ".$rule.": device_id = ':".$tmp."'"); - } - } - } - } +if (empty($rule) || empty($target)) { + $ret[] = 'ERROR: No map was generated'; } -foreach( $ret as $msg ) { - echo $msg."
    "; +else { + $raw = $rule; + $rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?', array($rule)); + if (!is_numeric($rule)) { + array_unshift($ret, "ERROR: Could not find rule for '".$raw."'"); + } + else { + $raw = $target; + if ($target[0].$target[1] == 'g:') { + $target = 'g'.dbFetchCell('SELECT id FROM device_groups WHERE name = ?', array(substr($target, 2))); + } + else { + $target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?', array($target)); + } + + if (!is_numeric(str_replace('g', '', $target))) { + array_unshift($ret, "ERROR: Could not find entry for '".$raw."'"); + } + else { + if (is_numeric($map_id) && $map_id > 0) { + if (dbUpdate(array('rule' => $rule, 'target' => $target), 'alert_map', 'id=?', array($map_id)) >= 0) { + $ret[] = 'Edited Map: '.$map_id.': '.$rule.' = '.$target.''; + } + else { + array_unshift($ret, 'ERROR: Failed to edit Map: '.$map_id.': '.$rule.' = '.$target.''); + } + } + else { + if (dbInsert(array('rule' => $rule, 'target' => $target), 'alert_map')) { + $ret[] = 'Added Map: '.$rule.' = '.$target.''; + } + else { + array_unshift($ret, 'ERROR: Failed to add Map: '.$rule.' = '.$target.''); + } + } + + if (($tmp = dbFetchCell('SELECT device_id FROM alert_rules WHERE id = ?', array($rule))) && $tmp[0] != ':') { + if (dbUpdate(array('device_id' => ':'.$tmp), 'alert_rules', 'id=?', array($rule)) >= 0) { + $ret[] = 'Edited Rule: '.$rule." device_id = ':".$tmp."'"; + } + else { + array_unshift($ret, 'ERROR: Failed to edit Rule: '.$rule.": device_id = ':".$tmp."'"); + } + } + }//end if + }//end if +}//end if +foreach ($ret as $msg) { + echo $msg.'
    '; } diff --git a/html/forms/delete-alert-map.inc.php b/html/forms/delete-alert-map.inc.php index 1275ea6a79..1719939c3e 100644 --- a/html/forms/delete-alert-map.inc.php +++ b/html/forms/delete-alert-map.inc.php @@ -12,30 +12,36 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } + $ret = array(); $brk = false; -if( !is_numeric($_POST['map_id']) ) { - array_unshift($ret,'ERROR: No map selected'); -} else { - if( dbFetchCell('SELECT COUNT(B.id) FROM alert_map,alert_map AS B WHERE alert_map.rule=B.rule && alert_map.id = ?',array($_POST['map_id'])) <= 1 ) { - $rule = dbFetchRow('SELECT alert_rules.id,alert_rules.device_id FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?',array($_POST['map_id'])); - $rule['device_id'] = str_replace(":",'',$rule['device_id']); - if( dbUpdate(array('device_id'=>$rule['device_id']),'alert_rules','id = ?',array($rule['id'])) >= 0 ) { - $ret[] = "Restored Rule: ".$rule['id'].": device_id = '".$rule['device_id']."'"; - } else { - array_unshift($ret, 'ERROR: Rule '.$rule['id'].' has not been restored.'); - $brk = true; - } - } - if( $brk === false && dbDelete('alert_map', "`id` = ?", array($_POST['map_id'])) ) { - $ret[] = 'Map has been deleted.'; - } else { - array_unshift($ret, 'ERROR: Map has not been deleted.'); - } +if (!is_numeric($_POST['map_id'])) { + array_unshift($ret, 'ERROR: No map selected'); } -foreach( $ret as $msg ) { - echo $msg."
    "; +else { + if (dbFetchCell('SELECT COUNT(B.id) FROM alert_map,alert_map AS B WHERE alert_map.rule=B.rule && alert_map.id = ?', array($_POST['map_id'])) <= 1) { + $rule = dbFetchRow('SELECT alert_rules.id,alert_rules.device_id FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?', array($_POST['map_id'])); + $rule['device_id'] = str_replace(':', '', $rule['device_id']); + if (dbUpdate(array('device_id' => $rule['device_id']), 'alert_rules', 'id = ?', array($rule['id'])) >= 0) { + $ret[] = 'Restored Rule: '.$rule['id'].": device_id = '".$rule['device_id']."'"; + } + else { + array_unshift($ret, 'ERROR: Rule '.$rule['id'].' has not been restored.'); + $brk = true; + } + } + + if ($brk === false && dbDelete('alert_map', '`id` = ?', array($_POST['map_id']))) { + $ret[] = 'Map has been deleted.'; + } + else { + array_unshift($ret, 'ERROR: Map has not been deleted.'); + } +} + +foreach ($ret as $msg) { + echo $msg.'
    '; } diff --git a/html/forms/delete-alert-rule.inc.php b/html/forms/delete-alert-rule.inc.php index f77c5dc2b1..5c3e157440 100644 --- a/html/forms/delete-alert-rule.inc.php +++ b/html/forms/delete-alert-rule.inc.php @@ -12,25 +12,28 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -if(!is_numeric($_POST['alert_id'])) { - echo('ERROR: No alert selected'); +if (!is_numeric($_POST['alert_id'])) { + echo 'ERROR: No alert selected'; exit; -} else { - if(dbDelete('alert_rules', "`id` = ?", array($_POST['alert_id']))) { - if(dbDelete('alert_map', "rule = ?", array($_POST['alert_id'])) || dbFetchCell('COUNT(id) FROM alert_map WHERE rule = ?',array($_POST['alert_id'])) == 0) { - echo('Maps has been deleted.'); - } else { - echo('WARNING: Maps could not be deleted.'); - } - echo('Alert rule has been deleted.'); - exit; - } else { - echo('ERROR: Alert rule has not been deleted.'); - exit; +} +else { + if (dbDelete('alert_rules', '`id` = ?', array($_POST['alert_id']))) { + if (dbDelete('alert_map', 'rule = ?', array($_POST['alert_id'])) || dbFetchCell('COUNT(id) FROM alert_map WHERE rule = ?', array($_POST['alert_id'])) == 0) { + echo 'Maps has been deleted.'; + } + else { + echo 'WARNING: Maps could not be deleted.'; + } + + echo 'Alert rule has been deleted.'; + exit; + } + else { + echo 'ERROR: Alert rule has not been deleted.'; + exit; } } - diff --git a/html/forms/delete-alert-template.inc.php b/html/forms/delete-alert-template.inc.php index 14ebd6c5b8..4328a1329a 100644 --- a/html/forms/delete-alert-template.inc.php +++ b/html/forms/delete-alert-template.inc.php @@ -1,31 +1,32 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -if(!is_numeric($_POST['template_id'])) { - echo('ERROR: No template selected'); +if (!is_numeric($_POST['template_id'])) { + echo 'ERROR: No template selected'; exit; -} else { - if(dbDelete('alert_templates', "`id` = ?", array($_POST['template_id']))) { - echo('Alert template has been deleted.'); - exit; - } else { - echo('ERROR: Alert template has not been deleted.'); - exit; +} +else { + if (dbDelete('alert_templates', '`id` = ?', array($_POST['template_id']))) { + echo 'Alert template has been deleted.'; + exit; + } + else { + echo 'ERROR: Alert template has not been deleted.'; + exit; } } - diff --git a/html/forms/delete-device-group.inc.php b/html/forms/delete-device-group.inc.php index 05e7ce7879..d22874750b 100644 --- a/html/forms/delete-device-group.inc.php +++ b/html/forms/delete-device-group.inc.php @@ -12,26 +12,28 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -if(!is_numeric($_POST['group_id'])) { - echo('ERROR: No group selected'); +if (!is_numeric($_POST['group_id'])) { + echo 'ERROR: No group selected'; exit; -} else { - if(dbDelete('device_groups', "`id` = ?", array($_POST['group_id']))) { - if( dbFetchCell('SELECT COUNT(id) FROM alert_map WHERE target = ?',array('g'.$_POST['group_id'])) >= 1 ) { - foreach( dbFetchRows('SELECT id FROM alert_map WHERE target = ?',array('g'.$_POST['group_id'])) as $map ) { - $_POST['map_id'] = $map['id']; - include('forms/delete-alert-map.inc.php'); +} +else { + if (dbDelete('device_groups', '`id` = ?', array($_POST['group_id']))) { + if (dbFetchCell('SELECT COUNT(id) FROM alert_map WHERE target = ?', array('g'.$_POST['group_id'])) >= 1) { + foreach (dbFetchRows('SELECT id FROM alert_map WHERE target = ?', array('g'.$_POST['group_id'])) as $map) { + $_POST['map_id'] = $map['id']; + include 'forms/delete-alert-map.inc.php'; + } } - } - echo('Group has been deleted.'); - exit; - } else { - echo('ERROR: Group has not been deleted.'); - exit; + + echo 'Group has been deleted.'; + exit; + } + else { + echo 'ERROR: Group has not been deleted.'; + exit; } } - diff --git a/html/forms/discovery-module-update.inc.php b/html/forms/discovery-module-update.inc.php index df5a60dabb..61a0a28b68 100644 --- a/html/forms/discovery-module-update.inc.php +++ b/html/forms/discovery-module-update.inc.php @@ -1,37 +1,28 @@ $_POST['data'], 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'],$_POST['device_id'])); - if(!empty($update) || $update == '0') - { - echo('success'); +if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || (empty($_POST['data']) || !isset($_POST['data']))) { + echo 'error with data'; exit; - } - else - { - echo('error'); - exit; - } } - +else { + $update = dbUpdate(array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'], $_POST['device_id'])); + if (!empty($update) || $update == '0') { + echo 'success'; + exit; + } + else { + echo 'error'; + exit; + } +} diff --git a/html/forms/parse-alert-map.inc.php b/html/forms/parse-alert-map.inc.php index 393b1dc68b..075de355b6 100644 --- a/html/forms/parse-alert-map.inc.php +++ b/html/forms/parse-alert-map.inc.php @@ -12,19 +12,24 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } $map_id = $_POST['map_id']; -if(is_numeric($map_id) && $map_id > 0) { - $map = dbFetchRow("SELECT alert_rules.name,alert_map.target FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?",array($map_id)); - if( $map['target'][0] == "g" ) { - $map['target'] = 'g:'.dbFetchCell("SELECT name FROM device_groups WHERE id = ?",array(substr($map['target'],1))); - } else { - $map['target'] = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?",array($map['target'])); +if (is_numeric($map_id) && $map_id > 0) { + $map = dbFetchRow('SELECT alert_rules.name,alert_map.target FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?', array($map_id)); + if ($map['target'][0] == 'g') { + $map['target'] = 'g:'.dbFetchCell('SELECT name FROM device_groups WHERE id = ?', array(substr($map['target'], 1))); } - $output = array('rule'=>$map['name'],'target'=>$map['target']); + else { + $map['target'] = dbFetchCell('SELECT hostname FROM devices WHERE device_id = ?', array($map['target'])); + } + + $output = array( + 'rule' => $map['name'], + 'target' => $map['target'], + ); echo _json_encode($output); } diff --git a/html/forms/parse-alert-rule.inc.php b/html/forms/parse-alert-rule.inc.php index 191535b4b2..aa3120424c 100644 --- a/html/forms/parse-alert-rule.inc.php +++ b/html/forms/parse-alert-rule.inc.php @@ -12,17 +12,22 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } $alert_id = $_POST['alert_id']; -if(is_numeric($alert_id) && $alert_id > 0) { - $rule = dbFetchRow("SELECT * FROM `alert_rules` WHERE `id` = ? LIMIT 1",array($alert_id)); - $rule_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@]+[&&\|\|]+)/',$rule['rule'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - $count = count($rule_split) - 1; +if (is_numeric($alert_id) && $alert_id > 0) { + $rule = dbFetchRow('SELECT * FROM `alert_rules` WHERE `id` = ? LIMIT 1', array($alert_id)); + $rule_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@]+[&&\|\|]+)/', $rule['rule'], -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); + $count = (count($rule_split) - 1); $rule_split[$count] = $rule_split[$count].' &&'; - $output = array('severity'=>$rule['severity'],'extra'=>$rule['extra'],'name'=>$rule['name'],'rules'=>$rule_split); + $output = array( + 'severity' => $rule['severity'], + 'extra' => $rule['extra'], + 'name' => $rule['name'], + 'rules' => $rule_split, + ); echo _json_encode($output); } diff --git a/html/forms/parse-alert-template.inc.php b/html/forms/parse-alert-template.inc.php index a04104a8f2..31dc3c7140 100644 --- a/html/forms/parse-alert-template.inc.php +++ b/html/forms/parse-alert-template.inc.php @@ -12,14 +12,17 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } $template_id = ($_POST['template_id']); -if(is_numeric($template_id) && $template_id > 0) { - $template = dbFetchRow("SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1",array($template_id)); - $output = array('template'=>$template['template'],'name'=>$template['name']); +if (is_numeric($template_id) && $template_id > 0) { + $template = dbFetchRow('SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1', array($template_id)); + $output = array( + 'template' => $template['template'], + 'name' => $template['name'], + ); echo _json_encode($output); } diff --git a/html/forms/parse-device-group.inc.php b/html/forms/parse-device-group.inc.php index 2293b198da..146b8fde1f 100644 --- a/html/forms/parse-device-group.inc.php +++ b/html/forms/parse-device-group.inc.php @@ -12,21 +12,27 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } $group_id = $_POST['group_id']; -if(is_numeric($group_id) && $group_id > 0) { - $group = dbFetchRow("SELECT * FROM `device_groups` WHERE `id` = ? LIMIT 1",array($group_id)); - $group_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@\[\]]+[&&\|\|]+)/',$group['pattern'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - $count = count($group_split) - 1; - if (preg_match("/\&\&$/",$group_split[$count]) == 1 || preg_match("/\|\|$/", $group_split[$count]) == 1) { +if (is_numeric($group_id) && $group_id > 0) { + $group = dbFetchRow('SELECT * FROM `device_groups` WHERE `id` = ? LIMIT 1', array($group_id)); + $group_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@\[\]]+[&&\|\|]+)/', $group['pattern'], -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); + $count = (count($group_split) - 1); + if (preg_match('/\&\&$/', $group_split[$count]) == 1 || preg_match('/\|\|$/', $group_split[$count]) == 1) { $group_split[$count] = $group_split[$count]; - } else { + } + else { $group_split[$count] = $group_split[$count].' &&'; } - $output = array('name'=>$group['name'],'desc'=>$group['desc'],'pattern'=>$group_split); + + $output = array( + 'name' => $group['name'], + 'desc' => $group['desc'], + 'pattern' => $group_split, + ); echo _json_encode($output); } diff --git a/html/forms/parse-poller-groups.inc.php b/html/forms/parse-poller-groups.inc.php index 72fd86eb72..f9cac5ba1d 100644 --- a/html/forms/parse-poller-groups.inc.php +++ b/html/forms/parse-poller-groups.inc.php @@ -12,14 +12,17 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } $group_id = ($_POST['group_id']); -if(is_numeric($group_id) && $group_id > 0) { - $group = dbFetchRow("SELECT * FROM `poller_groups` WHERE `id` = ? LIMIT 1",array($group_id)); - $output = array('group_name'=>$group['group_name'],'descr'=>$group['descr']); +if (is_numeric($group_id) && $group_id > 0) { + $group = dbFetchRow('SELECT * FROM `poller_groups` WHERE `id` = ? LIMIT 1', array($group_id)); + $output = array( + 'group_name' => $group['group_name'], + 'descr' => $group['descr'], + ); echo _json_encode($output); } diff --git a/html/forms/parse-template-rules.inc.php b/html/forms/parse-template-rules.inc.php index c30eec3f53..b5800b50f0 100644 --- a/html/forms/parse-template-rules.inc.php +++ b/html/forms/parse-template-rules.inc.php @@ -12,16 +12,17 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } $template_id = ($_POST['template_id']); -if(is_numeric($template_id) && $template_id > 0) { - foreach (dbFetchRows("SELECT `alert_rule_id` FROM `alert_template_map` WHERE `alert_templates_id` = ?",array($template_id)) as $rule) { +if (is_numeric($template_id) && $template_id > 0) { + foreach (dbFetchRows('SELECT `alert_rule_id` FROM `alert_template_map` WHERE `alert_templates_id` = ?', array($template_id)) as $rule) { $rules[] = $rule['alert_rule_id']; } - $output = array('rule_id'=>$rules); + + $output = array('rule_id' => $rules); echo _json_encode($output); } diff --git a/html/forms/poller-group-remove.inc.php b/html/forms/poller-group-remove.inc.php index b07f2c4422..ad65e10697 100644 --- a/html/forms/poller-group-remove.inc.php +++ b/html/forms/poller-group-remove.inc.php @@ -13,18 +13,19 @@ */ if (!is_numeric($_POST['group_id'])) { - echo('error with data'); - exit; -} else { - if($_POST['confirm'] == 'yes') - { - $delete = dbDelete('poller_groups', '`id` = ?', array($_POST['group_id'])); - if ($delete > '0') { - echo('Poller group has been removed'); - exit; - } else { - echo('An error occurred removing the Poller group'); - exit; - } - } + echo 'error with data'; + exit; +} +else { + if ($_POST['confirm'] == 'yes') { + $delete = dbDelete('poller_groups', '`id` = ?', array($_POST['group_id'])); + if ($delete > '0') { + echo 'Poller group has been removed'; + exit; + } + else { + echo 'An error occurred removing the Poller group'; + exit; + } + } } diff --git a/html/forms/poller-groups.inc.php b/html/forms/poller-groups.inc.php index a9856729b9..d7c14af04f 100644 --- a/html/forms/poller-groups.inc.php +++ b/html/forms/poller-groups.inc.php @@ -12,36 +12,40 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -$ok = ''; -$error = ''; -$group_id = $_POST['group_id']; +$ok = ''; +$error = ''; +$group_id = $_POST['group_id']; $group_name = mres($_POST['group_name']); -$descr = mres($_POST['descr']); -if(!empty($group_name)) { - if( is_numeric($group_id)) { - if (dbUpdate(array('group_name' => $group_name, 'descr' => $descr), "poller_groups", "id = ?", array($group_id))) { - $ok = "Updated poller group"; - } else { - $error = "Failed to update the poller group"; +$descr = mres($_POST['descr']); +if (!empty($group_name)) { + if (is_numeric($group_id)) { + if (dbUpdate(array('group_name' => $group_name, 'descr' => $descr), 'poller_groups', 'id = ?', array($group_id))) { + $ok = 'Updated poller group'; } - } else { - if (dbInsert(array('group_name' => $group_name, 'descr' => $descr), 'poller_groups') >= 0) { - $ok = "Added new poller group"; - } else { - $error = "Failed to create new poller group"; + else { + $error = 'Failed to update the poller group'; } } -} else { + else { + if (dbInsert(array('group_name' => $group_name, 'descr' => $descr), 'poller_groups') >= 0) { + $ok = 'Added new poller group'; + } + else { + $error = 'Failed to create new poller group'; + } + } +} +else { $error = "You haven't given your poller group a name, it feels sad :( - $group_name"; } -if(!empty( $ok )) { +if (!empty($ok)) { die("$ok"); -} else { +} +else { die("ERROR: $error"); } -?> diff --git a/html/forms/poller-module-update.inc.php b/html/forms/poller-module-update.inc.php index 8b686e610b..4c24950603 100644 --- a/html/forms/poller-module-update.inc.php +++ b/html/forms/poller-module-update.inc.php @@ -1,37 +1,28 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ // FIXME: Make this part of the API instead of a standalone function - -if(!is_numeric($_POST['device_id'])) { - $status = "error"; - $message = "Invalid device id"; -} else { +if (!is_numeric($_POST['device_id'])) { + $status = 'error'; + $message = 'Invalid device id'; +} +else { $update = dbUpdate(array('last_discovered' => array('NULL')), 'devices', '`device_id` = ?', array($_POST['device_id'])); - if(!empty($update) || $update == '0') { - $status = "ok"; - $message = "Device will be rediscovered"; - } else { - $status = "error"; - $message = "Error rediscovering device"; + if (!empty($update) || $update == '0') { + $status = 'ok'; + $message = 'Device will be rediscovered'; + } + else { + $status = 'error'; + $message = 'Error rediscovering device'; } } -$output = array("status" => $status, "message" => $message); -header("Content-type: application/json"); + +$output = array( + 'status' => $status, + 'message' => $message, + ); +header('Content-type: application/json'); echo _json_encode($output); diff --git a/html/forms/schedule-maintenance.inc.php b/html/forms/schedule-maintenance.inc.php index 4699653c6e..d601116ee1 100644 --- a/html/forms/schedule-maintenance.inc.php +++ b/html/forms/schedule-maintenance.inc.php @@ -12,14 +12,13 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } $sub_type = $_POST['sub_type']; if ($sub_type == 'new-maintenance') { - // Defaults $status = 'error'; $update = 0; @@ -28,6 +27,7 @@ if ($sub_type == 'new-maintenance') { if ($schedule_id > 0) { $update = 1; } + $title = mres($_POST['title']); $notes = mres($_POST['notes']); $start = mres($_POST['start']); @@ -35,75 +35,98 @@ if ($sub_type == 'new-maintenance') { $maps = mres($_POST['maps']); if (empty($title)) { - $message = "Missing title
    "; + $message = 'Missing title
    '; } + if (empty($start)) { - $message .= "Missing start date
    "; + $message .= 'Missing start date
    '; } + if (empty($end)) { - $message .= "Missing end date
    "; + $message .= 'Missing end date
    '; } - if( !is_array($_POST['maps']) ) { - $message .= "Not mapped to any groups or devices
    "; + + if (!is_array($_POST['maps'])) { + $message .= 'Not mapped to any groups or devices
    '; } if (empty($message)) { if (empty($schedule_id)) { - $schedule_id = dbInsert(array('start'=>$start,'end'=>$end,'title'=>$title,'notes'=>$notes),'alert_schedule'); - } else { - dbUpdate(array('start'=>$start,'end'=>$end,'title'=>$title,'notes'=>$notes),'alert_schedule','`schedule_id`=?',array($schedule_id)); + $schedule_id = dbInsert(array('start' => $start, 'end' => $end, 'title' => $title, 'notes' => $notes), 'alert_schedule'); } + else { + dbUpdate(array('start' => $start, 'end' => $end, 'title' => $title, 'notes' => $notes), 'alert_schedule', '`schedule_id`=?', array($schedule_id)); + } + if ($schedule_id > 0) { $items = array(); - $fail = 0; - + $fail = 0; + if ($update == 1) { dbDelete('alert_schedule_items', '`schedule_id`=?', array($schedule_id)); } - foreach( $_POST['maps'] as $target ) { + foreach ($_POST['maps'] as $target) { $target = target_to_id($target); - $item = dbInsert(array('schedule_id'=>$schedule_id,'target'=>$target),'alert_schedule_items'); + $item = dbInsert(array('schedule_id' => $schedule_id, 'target' => $target), 'alert_schedule_items'); if ($item > 0) { - array_push($items,$item); - } else { + array_push($items, $item); + } + else { $fail = 1; } } + if ($fail == 1 && $update == 0) { foreach ($items as $item) { dbDelete('alert_schedule_items', '`item_id`=?', array($item)); } + dbDelete('alert_schedule', '`schedule_id`=?', array($schedule_id)); $message = 'Issue scheduling maintenance'; - } else { - $status = 'ok'; + } + else { + $status = 'ok'; $message = 'Scheduling maintenance ok'; } - } else { - $message = "Issue scheduling maintenance"; } - } + else { + $message = 'Issue scheduling maintenance'; + }//end if + }//end if - $response = array('status'=>$status,'message'=>$message); - -} elseif ($sub_type == 'parse-maintenance') { - - $schedule_id = mres($_POST['schedule_id']); - $schedule = dbFetchRow("SELECT * FROM `alert_schedule` WHERE `schedule_id`=?",array($schedule_id)); - $items = array(); - foreach (dbFetchRows("SELECT `target` FROM `alert_schedule_items` WHERE `schedule_id`=?",array($schedule_id)) as $targets) { - $targets = id_to_target($targets['target']); - array_push($items,$targets); - } - $response = array('start'=>$schedule['start'],'end'=>$schedule['end'],'title'=>$schedule['title'],'notes'=>$schedule['notes'],'targets'=>$items); -} elseif ($sub_type == 'del-maintenance') { - $schedule_id = mres($_POST['del_schedule_id']); - dbDelete('alert_schedule_items','`schedule_id`=?',array($schedule_id)); - dbDelete('alert_schedule','`schedule_id`=?', array($schedule_id)); - $status = 'ok'; - $message = 'Maintenance schedule has been removed'; - $response = array('status'=>$status,'message'=>$message); + $response = array( + 'status' => $status, + 'message' => $message, + ); } +else if ($sub_type == 'parse-maintenance') { + $schedule_id = mres($_POST['schedule_id']); + $schedule = dbFetchRow('SELECT * FROM `alert_schedule` WHERE `schedule_id`=?', array($schedule_id)); + $items = array(); + foreach (dbFetchRows('SELECT `target` FROM `alert_schedule_items` WHERE `schedule_id`=?', array($schedule_id)) as $targets) { + $targets = id_to_target($targets['target']); + array_push($items, $targets); + } + + $response = array( + 'start' => $schedule['start'], + 'end' => $schedule['end'], + 'title' => $schedule['title'], + 'notes' => $schedule['notes'], + 'targets' => $items, + ); +} +else if ($sub_type == 'del-maintenance') { + $schedule_id = mres($_POST['del_schedule_id']); + dbDelete('alert_schedule_items', '`schedule_id`=?', array($schedule_id)); + dbDelete('alert_schedule', '`schedule_id`=?', array($schedule_id)); + $status = 'ok'; + $message = 'Maintenance schedule has been removed'; + $response = array( + 'status' => $status, + 'message' => $message, + ); +}//end if echo _json_encode($response); diff --git a/html/forms/sensor-alert-reset.inc.php b/html/forms/sensor-alert-reset.inc.php index 15415f1185..f2b8c911fc 100644 --- a/html/forms/sensor-alert-reset.inc.php +++ b/html/forms/sensor-alert-reset.inc.php @@ -1,21 +1,18 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ // FUA - -for($x=0;$x $_POST['sensor_limit'][$x], 'sensor_limit_low' => $_POST['sensor_limit_low'][$x], 'sensor_alert' => $_POST['sensor_alert'][$x]), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'][$x])); +for ($x = 0; $x < count($_POST['sensor_id']); $x++) { + dbUpdate(array('sensor_limit' => $_POST['sensor_limit'][$x], 'sensor_limit_low' => $_POST['sensor_limit_low'][$x], 'sensor_alert' => $_POST['sensor_alert'][$x]), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'][$x])); } - diff --git a/html/forms/sensor-alert-update.inc.php b/html/forms/sensor-alert-update.inc.php index 91a5b9aecc..b0596db895 100644 --- a/html/forms/sensor-alert-update.inc.php +++ b/html/forms/sensor-alert-update.inc.php @@ -13,41 +13,33 @@ */ // FUA - if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) { dbUpdate(array('sensor_custom' => 'No'), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'])); -} else { +} +else { + if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) { + echo 'error with data'; + exit; + } + else { + if ($_POST['state'] == 'true') { + $state = 1; + } + else if ($_POST['state'] == 'false') { + $state = 0; + } + else { + $state = 0; + } -if(!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) -{ - echo('error with data'); - exit; + $update = dbUpdate(array('sensor_alert' => $state), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'], $_POST['device_id'])); + if (!empty($update) || $update == '0') { + echo 'success'; + exit; + } + else { + echo 'error'; + exit; + } + } } -else -{ - if($_POST['state'] == 'true') - { - $state = 1; - } - elseif($_POST['state'] == 'false') - { - $state = 0; - } - else - { - $state = 0; - } - $update = dbUpdate(array('sensor_alert' => $state), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'],$_POST['device_id'])); - if(!empty($update) || $update == '0') - { - echo('success'); - exit; - } - else - { - echo('error'); - exit; - } -} -} - diff --git a/html/forms/token-item-create.inc.php b/html/forms/token-item-create.inc.php index dc6da67c38..0eb06a9955 100644 --- a/html/forms/token-item-create.inc.php +++ b/html/forms/token-item-create.inc.php @@ -1,44 +1,38 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ -if(!is_numeric($_POST['user_id']) || !isset($_POST['token'])) -{ - echo('ERROR: error with data, please ensure a valid user and token have been specified.'); - exit; -} -elseif(strlen($_POST['token']) > 32) -{ - echo('ERROR: The token is more than 32 characters'); - exit; -} -elseif(strlen($_POST['token']) < 16) -{ - echo('ERROR: The token is less than 16 characters'); - exit; -} -else -{ - $create = dbInsert(array('user_id' => $_POST['user_id'], 'token_hash' => $_POST['token'], 'description' => $_POST['description']), 'api_tokens'); - if($create > '0') - { - echo('API token has been created'); - $_SESSION['api_token'] = TRUE; +if (!is_numeric($_POST['user_id']) || !isset($_POST['token'])) { + echo 'ERROR: error with data, please ensure a valid user and token have been specified.'; exit; - } - else - { - echo('ERROR: An error occurred creating the API token'); - exit; - } } +else if (strlen($_POST['token']) > 32) { + echo 'ERROR: The token is more than 32 characters'; + exit; +} +else if (strlen($_POST['token']) < 16) { + echo 'ERROR: The token is less than 16 characters'; + exit; +} +else { + $create = dbInsert(array('user_id' => $_POST['user_id'], 'token_hash' => $_POST['token'], 'description' => $_POST['description']), 'api_tokens'); + if ($create > '0') { + echo 'API token has been created'; + $_SESSION['api_token'] = true; + exit; + } + else { + echo 'ERROR: An error occurred creating the API token'; + exit; + } +}//end if diff --git a/html/forms/token-item-disable.inc.php b/html/forms/token-item-disable.inc.php index e336d911ea..2f8c635b8a 100644 --- a/html/forms/token-item-disable.inc.php +++ b/html/forms/token-item-disable.inc.php @@ -1,45 +1,39 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ -if(!is_numeric($_POST['token_id'])) -{ - echo('error with data'); - exit; -} -else -{ - if($_POST['state'] == 'true') - { - $state = 1; - } - elseif($_POST['state'] == 'false') - { - $state = 0; - } - else - { - $state = 0; - } - $update = dbUpdate(array('disabled' => $state), 'api_tokens', '`id` = ?', array($_POST['token_id'])); - if(!empty($update) || $update == '0') - { - echo('success'); +if (!is_numeric($_POST['token_id'])) { + echo 'error with data'; exit; - } - else - { - echo('error'); - exit; - } } +else { + if ($_POST['state'] == 'true') { + $state = 1; + } + else if ($_POST['state'] == 'false') { + $state = 0; + } + else { + $state = 0; + } + + $update = dbUpdate(array('disabled' => $state), 'api_tokens', '`id` = ?', array($_POST['token_id'])); + if (!empty($update) || $update == '0') { + echo 'success'; + exit; + } + else { + echo 'error'; + exit; + } +}//end if diff --git a/html/forms/token-item-remove.inc.php b/html/forms/token-item-remove.inc.php index 1b4522f39d..5057d047c9 100644 --- a/html/forms/token-item-remove.inc.php +++ b/html/forms/token-item-remove.inc.php @@ -1,36 +1,31 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ -if(!is_numeric($_POST['token_id'])) -{ - echo('error with data'); - exit; +if (!is_numeric($_POST['token_id'])) { + echo 'error with data'; + exit; } -else -{ - if($_POST['confirm'] == 'yes') - { - $delete = dbDelete('api_tokens', '`id` = ?', array($_POST['token_id'])); - if($delete > '0') - { - echo('API token has been removed'); - exit; +else { + if ($_POST['confirm'] == 'yes') { + $delete = dbDelete('api_tokens', '`id` = ?', array($_POST['token_id'])); + if ($delete > '0') { + echo 'API token has been removed'; + exit; + } + else { + echo 'An error occurred removing the API token'; + exit; + } } - else - { - echo('An error occurred removing the API token'); - exit; - } - } -} +}//end if diff --git a/html/forms/update-alert-rule.inc.php b/html/forms/update-alert-rule.inc.php index 9c8de3cbc9..261e300625 100644 --- a/html/forms/update-alert-rule.inc.php +++ b/html/forms/update-alert-rule.inc.php @@ -12,39 +12,32 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -if(!is_numeric($_POST['alert_id'])) -{ - echo('ERROR: No alert selected'); - exit; -} -else -{ - if($_POST['state'] == 'true') - { - $state = 0; - } - elseif($_POST['state'] == 'false') - { - $state = 1; - } - else - { - $state = 1; - } - $update = dbUpdate(array('disabled' => $state), 'alert_rules', '`id`=?', array($_POST['alert_id'])); - if(!empty($update) || $update == '0') - { - echo('Alert rule has been updated.'); +if (!is_numeric($_POST['alert_id'])) { + echo 'ERROR: No alert selected'; exit; - } - else - { - echo('ERROR: Alert rule has not been updated.'); - exit; - } } +else { + if ($_POST['state'] == 'true') { + $state = 0; + } + else if ($_POST['state'] == 'false') { + $state = 1; + } + else { + $state = 1; + } + $update = dbUpdate(array('disabled' => $state), 'alert_rules', '`id`=?', array($_POST['alert_id'])); + if (!empty($update) || $update == '0') { + echo 'Alert rule has been updated.'; + exit; + } + else { + echo 'ERROR: Alert rule has not been updated.'; + exit; + } +} diff --git a/html/forms/update-config-item.inc.php b/html/forms/update-config-item.inc.php index 85919d1b70..edcaf8cb00 100644 --- a/html/forms/update-config-item.inc.php +++ b/html/forms/update-config-item.inc.php @@ -12,58 +12,70 @@ * the source code distribution for details. */ -if(is_admin() === false) { +if (is_admin() === false) { die('ERROR: You need to be admin'); } -$config_id = mres($_POST['config_id']); -$action = mres($_POST['action']); +$config_id = mres($_POST['config_id']); +$action = mres($_POST['action']); $config_type = mres($_POST['config_type']); $status = 'error'; if (!is_numeric($config_id)) { $message = 'ERROR: No alert selected'; -} elseif ($action == 'update-textarea') { - $extras = explode(PHP_EOL,$_POST['config_value']); +} +else if ($action == 'update-textarea') { + $extras = explode(PHP_EOL, $_POST['config_value']); foreach ($extras as $option) { - list($k,$v) = explode("=", $option,2); + list($k,$v) = explode('=', $option, 2); if (!empty($k) || !empty($v)) { if ($config_type == 'slack') { - $db_id[] = dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Slack Transport'), 'config'); - } elseif ($config_type == 'hipchat') { - $db_id[] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Hipchat Transport'), 'config'); - } elseif ($config_type == 'pushover') { - $db_id[] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default'=>$v, 'config_descr'=>'Pushover Transport'), 'config'); + $db_id[] = dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Slack Transport'), 'config'); + } + else if ($config_type == 'hipchat') { + $db_id[] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Hipchat Transport'), 'config'); + } + else if ($config_type == 'pushover') { + $db_id[] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Pushover Transport'), 'config'); } } } - $db_inserts = implode(",",$db_id); + + $db_inserts = implode(',', $db_id); if (!empty($db_inserts) || empty($_POST['config_value'])) { if (empty($_POST['config_value'])) { $db_inserts = 0; } + if ($config_type == 'slack') { - dbDelete('config',"(`config_name` LIKE 'alert.transports.slack.$config_id.%' AND `config_name` != 'alert.transports.slack.$config_id.url' AND `config_id` NOT IN ($db_inserts))"); - } elseif ($config_type == 'hipchat') { - dbDelete('config',"(`config_name` LIKE 'alert.transports.hipchat.$config_id.%' AND (`config_name` != 'alert.transports.hipchat.$config_id.url' AND `config_name` != 'alert.transports.hipchat.$config_id.room_id' AND `config_name` != 'alert.transports.hipchat.$config_id.from') AND `config_id` NOT IN ($db_inserts))"); - } elseif ($config_type == 'pushover') { - dbDelete('config',"(`config_name` LIKE 'alert.transports.pushover.$config_id.%' AND (`config_name` != 'alert.transports.pushover.$config_id.appkey' AND `config_name` != 'alert.transports.pushover.$config_id.userkey') AND `config_id` NOT IN ($db_inserts))"); + dbDelete('config', "(`config_name` LIKE 'alert.transports.slack.$config_id.%' AND `config_name` != 'alert.transports.slack.$config_id.url' AND `config_id` NOT IN ($db_inserts))"); + } + else if ($config_type == 'hipchat') { + dbDelete('config', "(`config_name` LIKE 'alert.transports.hipchat.$config_id.%' AND (`config_name` != 'alert.transports.hipchat.$config_id.url' AND `config_name` != 'alert.transports.hipchat.$config_id.room_id' AND `config_name` != 'alert.transports.hipchat.$config_id.from') AND `config_id` NOT IN ($db_inserts))"); + } + else if ($config_type == 'pushover') { + dbDelete('config', "(`config_name` LIKE 'alert.transports.pushover.$config_id.%' AND (`config_name` != 'alert.transports.pushover.$config_id.appkey' AND `config_name` != 'alert.transports.pushover.$config_id.userkey') AND `config_id` NOT IN ($db_inserts))"); } } + $message = 'Config item has been updated:'; - $status = 'ok'; -} else { - $state = mres($_POST['config_value']); + $status = 'ok'; +} +else { + $state = mres($_POST['config_value']); $update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($config_id)); - if(!empty($update) || $update == '0') - { + if (!empty($update) || $update == '0') { $message = 'Alert rule has been updated.'; - $status = 'ok'; - } else { + $status = 'ok'; + } + else { $message = 'ERROR: Alert rule has not been updated.'; } -} +}//end if -$response = array('status'=>$status,'message'=>$message); +$response = array( + 'status' => $status, + 'message' => $message, +); echo _json_encode($response); diff --git a/html/graph-realtime.php b/html/graph-realtime.php index 73e60edca2..8b7e8fac32 100644 --- a/html/graph-realtime.php +++ b/html/graph-realtime.php @@ -13,30 +13,28 @@ * */ -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; -include_once("../includes/common.php"); -include_once("../includes/dbFacile.php"); -include_once("../includes/rewrites.php"); -include_once("includes/functions.inc.php"); -include_once("includes/authenticate.inc.php"); +require_once '../includes/common.php'; +require_once '../includes/dbFacile.php'; +require_once '../includes/rewrites.php'; +require_once 'includes/functions.inc.php'; +require_once 'includes/authenticate.inc.php'; -include_once("../includes/snmp.inc.php"); - -if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) -{ - $port = get_port_by_id($_GET['id']); - $device = device_by_id_cache($port['device_id']); - $title = generate_device_link($device); - $title .= " :: Port ".generate_port_link($port); - $auth = TRUE; -} else { - - echo("Unauthenticad"); - die; +require_once '../includes/snmp.inc.php'; +if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) { + $port = get_port_by_id($_GET['id']); + $device = device_by_id_cache($port['device_id']); + $title = generate_device_link($device); + $title .= " :: Port ".generate_port_link($port); + $auth = TRUE; +} +else { + echo("Unauthenticad"); + die; } header("Content-type: image/svg+xml"); @@ -47,16 +45,19 @@ $ifname=ifLabel($port); $ifname=$ifname['label']; //Interface name that will be showed on top right of graph $hostname=shorthost($device['hostname']); -if($_GET['title']) { $ifname = $_GET['title']; } +if($_GET['title']) { + $ifname = $_GET['title']; +} /********* Other conf *******/ $scale_type="follow"; //Autoscale default setup : "up" = only increase scale; "follow" = increase and decrease scale according to current graphed datas $nb_plot=240; //NB plot in graph if(is_numeric($_GET['interval'])) { - $time_interval=$_GET['interval']; -} else { - $time_interval=1; //Refresh time Interval + $time_interval=$_GET['interval']; +} +else { + $time_interval=1; //Refresh time Interval } $fetch_link = "data.php?id=".$_GET[id]; @@ -225,24 +226,24 @@ function plot_data(obj) { last_ifout = ifout; switch (plot_in.length) { - case 0: - SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'visible'); - plot_in[0] = diff_ifin / diff_ugmt; - plot_out[0] = diff_ifout / diff_ugmt; - setTimeout('fetch_data()',); - return; - case 1: - SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'hidden'); - break; + case 0: + SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'visible'); + plot_in[0] = diff_ifin / diff_ugmt; + plot_out[0] = diff_ifout / diff_ugmt; + setTimeout('fetch_data()',); + return; + case 1: + SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'hidden'); + break; case max_num_points: - // shift plot to left if the maximum number of plot points has been reached - var i = 0; - while (i < max_num_points) { - plot_in[i] = plot_in[i+1]; - plot_out[i] = plot_out[++i]; - } - plot_in.length--; - plot_out.length--; + // shift plot to left if the maximum number of plot points has been reached + var i = 0; + while (i < max_num_points) { + plot_in[i] = plot_in[i+1]; + plot_out[i] = plot_out[++i]; + } + plot_in.length--; + plot_out.length--; } plot_in[plot_in.length] = diff_ifin / diff_ugmt; diff --git a/html/graph.php b/html/graph.php index 95cf00b214..f3cf51fd98 100644 --- a/html/graph.php +++ b/html/graph.php @@ -9,62 +9,57 @@ * @subpackage graphing * @author Adam Armstrong * @copyright (C) 2006 - 2012 Adam Armstrong - * */ -function utime() -{ - $time = explode(" ", microtime()); - $usec = (double)$time[0]; - $sec = (double)$time[1]; - return $sec + $usec; + +function utime() { + $time = explode(' ', microtime()); + $usec = (double) $time[0]; + $sec = (double) $time[1]; + return ($sec + $usec); + } $start = utime(); -include_once("Net/IPv4.php"); +require_once 'Net/IPv4.php'; -if (isset($_GET['debug'])) -{ - $debug = TRUE; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', E_ALL); +if (isset($_GET['debug'])) { + $debug = true; + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', E_ALL); } -else -{ - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); +else { + $debug = false; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); -include_once("../includes/common.php"); -include_once("../includes/console_colour.php"); -include_once("../includes/dbFacile.php"); -include_once("../includes/rewrites.php"); -include_once("includes/functions.inc.php"); -include_once("../includes/rrdtool.inc.php"); -include_once("includes/authenticate.inc.php"); +require_once '../includes/defaults.inc.php'; +require_once '../config.php'; +require_once '../includes/definitions.inc.php'; +require_once '../includes/common.php'; +require_once '../includes/console_colour.php'; +require_once '../includes/dbFacile.php'; +require_once '../includes/rewrites.php'; +require_once 'includes/functions.inc.php'; +require_once '../includes/rrdtool.inc.php'; +require_once 'includes/authenticate.inc.php'; -include("includes/graphs/graph.inc.php"); +require 'includes/graphs/graph.inc.php'; $console_color = new Console_Color2(); -$end = utime(); $run = $end - $start;; +$end = utime(); +$run = ($end - $start); -if($debug) { echo("
    Runtime ".$run." secs"); -echo('
    MySQL: Cell '.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,3).'s'. - ' Row '.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,3).'s'. - ' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'. - ' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s'); +if ($debug) { + echo '
    Runtime '.$run.' secs'; + echo ('
    MySQL: Cell '.($db_stats['fetchcell'] + 0).'/'.round(($db_stats['fetchcell_sec'] + 0), 3).'s'.' Row '.($db_stats['fetchrow'] + 0).'/'.round(($db_stats['fetchrow_sec'] + 0), 3).'s'.' Rows '.($db_stats['fetchrows'] + 0).'/'.round(($db_stats['fetchrows_sec'] + 0), 3).'s'.' Column '.($db_stats['fetchcol'] + 0).'/'.round(($db_stats['fetchcol_sec'] + 0), 3).'s'); } - -?> diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index a3593e684e..4f20c9b8b3 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -12,713 +12,877 @@ * the source code distribution for details. */ -require_once("../includes/functions.php"); - -function authToken(\Slim\Route $route) -{ - $app = \Slim\Slim::getInstance(); - $token = $app->request->headers->get('X-Auth-Token'); - if(isset($token) && !empty($token)) - { - $username = dbFetchCell("SELECT `U`.`username` FROM `api_tokens` AS AT JOIN `users` AS U ON `AT`.`user_id`=`U`.`user_id` WHERE `AT`.`token_hash`=?", array($token)); - if(!empty($username)) - { - $authenticated = true; - } - else - { - $authenticated = false; - } - } - else - { - $authenticated = false; - } - - if($authenticated === false) - { - $app->response->setStatus(401); - $output = array("status" => "error", "message" => "API Token is missing or invalid; please supply a valid token"); - echo _json_encode($output); - $app->stop(); - } -} - -function get_graph_by_port_hostname() -{ - // This will return a graph for a given port by the ifName - global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); - $hostname = $router['hostname']; - $vars = array(); - $vars['port'] = urldecode($router['ifname']); - $vars['type'] = $router['type'] ?: 'port_bits'; - if(!empty($_GET['from'])) - { - $vars['from'] = $_GET['from']; - } - if(!empty($_GET['to'])) - { - $vars['to'] = $_GET['to']; - } - $vars['width'] = $_GET['width'] ?: 1075; - $vars['height'] = $_GET['height'] ?: 300; - $auth = "1"; - $vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`ifName`=?", array($hostname,$vars['port'])); - $app->response->headers->set('Content-Type', 'image/png'); - require("includes/graphs/graph.inc.php"); -} - -function get_port_stats_by_port_hostname() -{ - // This will return port stats based on a devices hostname and ifName - global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); - $hostname = $router['hostname']; - $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - $ifName = urldecode($router['ifname']); - $stats = dbFetchRow("SELECT * FROM `ports` WHERE `device_id`=? AND `ifName`=?", array($device_id,$ifName)); - $output = array("status" => "ok", "port" => $stats); - $app->response->headers->set('Content-Type', 'application/json'); - echo _json_encode($output); -} - -function get_graph_generic_by_hostname() -{ - // This will return a graph type given a device id. - global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); - $hostname = $router['hostname']; - $vars = array(); - $vars['type'] = $router['type'] ?: 'device_uptime'; - if(!empty($_GET['from'])) - { - $vars['from'] = $_GET['from']; - } - if(!empty($_GET['to'])) - { - $vars['to'] = $_GET['to']; - } - $vars['width'] = $_GET['width'] ?: 1075; - $vars['height'] = $_GET['height'] ?: 300; - $auth = "1"; - $vars['device'] = dbFetchCell("SELECT `D`.`device_id` FROM `devices` AS `D` WHERE `D`.`hostname`=?", array($hostname)); - $app->response->headers->set('Content-Type', 'image/png'); - require("includes/graphs/graph.inc.php"); -} - -function get_device() -{ - // return details of a single device - $app = \Slim\Slim::getInstance(); - $app->response->headers->set('Content-Type', 'application/json'); - $router = $app->router()->getCurrentRoute()->getParams(); - $hostname = $router['hostname']; - - // use hostname as device_id if it's all digits - $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - - // find device matching the id - $device = device_by_id_cache($device_id); - if (!$device) { - $app->response->setStatus(404); - $output = array("status" => "error", "message" => "Device $hostname does not exist"); - echo _json_encode($output); - $app->stop(); - } - else { - $output = array("status" => "ok", "devices" => array($device)); - echo _json_encode($output); - } -} - -function list_devices() -{ - // This will return a list of devices - global $config; - $app = \Slim\Slim::getInstance(); - $order = $_GET['order']; - $type = $_GET['type']; - if(empty($order)) - { - $order = "hostname"; - } - if(stristr($order,' desc') === FALSE && stristr($order, ' asc') === FALSE) - { - $order .= ' ASC'; - } - if($type == 'all' || empty($type)) - { - $sql = "1"; - } - elseif($type == 'ignored') - { - $sql = "ignore='1' AND disabled='0'"; - } - elseif($type == 'up') - { - $sql = "status='1' AND ignore='0' AND disabled='0'"; - } - elseif($type == 'down') - { - $sql = "status='0' AND ignore='0' AND disabled='0'"; - } - elseif($type == 'disabled') - { - $sql = "disabled='1'"; - } - else - { - $sql = "1"; - } - $devices = array(); - foreach (dbFetchRows("SELECT * FROM `devices` WHERE $sql ORDER by $order") as $device) - { - $devices[] = $device; - } - $output = array("status" => "ok", "devices" => $devices); - $app->response->headers->set('Content-Type', 'application/json'); - echo _json_encode($output); -} - -function add_device() -{ - // This will add a device using the data passed encoded with json - // FIXME: Execution flow through this function could be improved - global $config; - $app = \Slim\Slim::getInstance(); - $data = json_decode(file_get_contents('php://input'), true); - // Default status & code to error and change it if we need to. - $status = "error"; - $code = 500; - // keep scrutinizer from complaining about snmpver not being set for all execution paths - $snmpver = "v2c"; - if(empty($data)) - { - $message = "No information has been provided to add this new device"; - } - elseif(empty($data["hostname"])) - { - $message = "Missing the device hostname"; - } - $hostname = $data['hostname']; - $port = $data['port'] ? mres($data['port']) : $config['snmp']['port']; - $transport = $data['transport'] ? mres($data['transport']) : "udp"; - $poller_group = $data['poller_group'] ? mres($data['poller_group']) : 0; - $force_add = $data['force_add'] ? mres($data['force_add']) : 0; - if($data['version'] == "v1" || $data['version'] == "v2c") - { - if ($data['community']) - { - $config['snmp']['community'] = array($data['community']); - } - $snmpver = mres($data['version']); - } - elseif($data['version'] == 'v3') - { - $v3 = array ( - 'authlevel' => mres($data['authlevel']), - 'authname' => mres($data['authname']), - 'authpass' => mres($data['authpass']), - 'authalgo' => mres($data['authalgo']), - 'cryptopass' => mres($data['cryptopass']), - 'cryptoalgo' => mres($data['cryptoalgo']), - ); - - array_push($config['snmp']['v3'], $v3); - $snmpver = "v3"; - } - else - { - $code = 400; - $status = "error"; - $message = "You haven't specified an SNMP version to use"; - } - if(empty($message)) - { - $result = addHost($hostname, $snmpver, $port, $transport, 1, $poller_group,$force_add); - if($result) - { - $code = 201; - $status = "ok"; - $message = "Device $hostname has been added successfully"; - } - else - { - $message = "Failed adding $hostname"; - } - } - - $app->response->setStatus($code); - $output = array("status" => $status, "message" => $message); - $app->response->headers->set('Content-Type', 'application/json'); - echo _json_encode($output); -} +require_once '../includes/functions.php'; -function del_device() -{ - // This will add a device using the data passed encoded with json - global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); - $hostname = $router['hostname']; - // Default status to error and change it if we need to. - $status = "error"; - $code = 500; - if(empty($hostname) || $config['api_demo'] == 1) - { - $message = "No hostname has been provided to delete"; - if ($config['api_demo'] == 1) { - $message = "This feature isn\'t available in the demo"; - } - $output = array("status" => $status, "message" => $message); - } - else - { - - // allow deleting by device_id or hostname - $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - $device = null; - if ($device_id) { - // save the current details for returning to the client on successful delete - $device = device_by_id_cache($device_id); - } - if ($device) { - $response = delete_device($device_id); - if(empty($response)) { - // FIXME: Need to provide better diagnostics out of delete_device - $output = array("status" => $status, "message" => "Device deletion failed"); - } - else { - // deletion succeeded - include old device details in response - $code = 200; - $status = "ok"; - $output = array("status" => $status, "message" => $response, "devices" => array($device)); - } +function authToken(\Slim\Route $route) { + $app = \Slim\Slim::getInstance(); + $token = $app->request->headers->get('X-Auth-Token'); + if (isset($token) && !empty($token)) { + $username = dbFetchCell('SELECT `U`.`username` FROM `api_tokens` AS AT JOIN `users` AS U ON `AT`.`user_id`=`U`.`user_id` WHERE `AT`.`token_hash`=?', array($token)); + if (!empty($username)) { + $authenticated = true; + } + else { + $authenticated = false; + } } else { - // no device matching the name - $code = 404; - $output = array("status" => $status, "message" => "Device $hostname not found"); + $authenticated = false; + } + + if ($authenticated === false) { + $app->response->setStatus(401); + $output = array( + 'status' => 'error', + 'message' => 'API Token is missing or invalid; please supply a valid token', + ); + echo _json_encode($output); + $app->stop(); } - } - $app->response->setStatus($code); - $app->response->headers->set('Content-Type', 'application/json'); - echo _json_encode($output); } -function get_vlans() { - // This will list all vlans for a given device + + +function get_graph_by_port_hostname() { + // This will return a graph for a given port by the ifName global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $hostname = $router['hostname']; + $vars = array(); + $vars['port'] = urldecode($router['ifname']); + $vars['type'] = $router['type'] ?: 'port_bits'; + if (!empty($_GET['from'])) { + $vars['from'] = $_GET['from']; + } + + if (!empty($_GET['to'])) { + $vars['to'] = $_GET['to']; + } + + $vars['width'] = $_GET['width'] ?: 1075; + $vars['height'] = $_GET['height'] ?: 300; + $auth = '1'; + $vars['id'] = dbFetchCell('SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`ifName`=?', array($hostname, $vars['port'])); + $app->response->headers->set('Content-Type', 'image/png'); + include 'includes/graphs/graph.inc.php'; + +} + + +function get_port_stats_by_port_hostname() { + // This will return port stats based on a devices hostname and ifName + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $hostname = $router['hostname']; + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + $ifName = urldecode($router['ifname']); + $stats = dbFetchRow('SELECT * FROM `ports` WHERE `device_id`=? AND `ifName`=?', array($device_id, $ifName)); + $output = array( + 'status' => 'ok', + 'port' => $stats, + ); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); + +} + + +function get_graph_generic_by_hostname() { + // This will return a graph type given a device id. + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $hostname = $router['hostname']; + $vars = array(); + $vars['type'] = $router['type'] ?: 'device_uptime'; + if (!empty($_GET['from'])) { + $vars['from'] = $_GET['from']; + } + + if (!empty($_GET['to'])) { + $vars['to'] = $_GET['to']; + } + + $vars['width'] = $_GET['width'] ?: 1075; + $vars['height'] = $_GET['height'] ?: 300; + $auth = '1'; + $vars['device'] = dbFetchCell('SELECT `D`.`device_id` FROM `devices` AS `D` WHERE `D`.`hostname`=?', array($hostname)); + $app->response->headers->set('Content-Type', 'image/png'); + include 'includes/graphs/graph.inc.php'; + +} + + +function get_device() { + // return details of a single device $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); + $app->response->headers->set('Content-Type', 'application/json'); + $router = $app->router()->getCurrentRoute()->getParams(); $hostname = $router['hostname']; - $code = 500; - if(empty($hostname)) { - $output = $output = array("status" => "error", "message" => "No hostname has been provided"); - } else { - require_once("../includes/functions.php"); + + // use hostname as device_id if it's all digits + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + + // find device matching the id + $device = device_by_id_cache($device_id); + if (!$device) { + $app->response->setStatus(404); + $output = array( + 'status' => 'error', + 'message' => "Device $hostname does not exist", + ); + echo _json_encode($output); + $app->stop(); + } + else { + $output = array( + 'status' => 'ok', + 'devices' => array($device), + ); + echo _json_encode($output); + } + +} + + +function list_devices() { + // This will return a list of devices + global $config; + $app = \Slim\Slim::getInstance(); + $order = $_GET['order']; + $type = $_GET['type']; + if (empty($order)) { + $order = 'hostname'; + } + + if (stristr($order, ' desc') === false && stristr($order, ' asc') === false) { + $order .= ' ASC'; + } + + if ($type == 'all' || empty($type)) { + $sql = '1'; + } + else if ($type == 'ignored') { + $sql = "ignore='1' AND disabled='0'"; + } + else if ($type == 'up') { + $sql = "status='1' AND ignore='0' AND disabled='0'"; + } + else if ($type == 'down') { + $sql = "status='0' AND ignore='0' AND disabled='0'"; + } + else if ($type == 'disabled') { + $sql = "disabled='1'"; + } + else { + $sql = '1'; + } + $devices = array(); + foreach (dbFetchRows("SELECT * FROM `devices` WHERE $sql ORDER by $order") as $device) { + $devices[] = $device; + } + + $output = array( + 'status' => 'ok', + 'devices' => $devices, + ); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); + +} + + +function add_device() { + // This will add a device using the data passed encoded with json + // FIXME: Execution flow through this function could be improved + global $config; + $app = \Slim\Slim::getInstance(); + $data = json_decode(file_get_contents('php://input'), true); + // Default status & code to error and change it if we need to. + $status = 'error'; + $code = 500; + // keep scrutinizer from complaining about snmpver not being set for all execution paths + $snmpver = 'v2c'; + if (empty($data)) { + $message = 'No information has been provided to add this new device'; + } + + else if (empty($data['hostname'])) { + $message = 'Missing the device hostname'; + } + + $hostname = $data['hostname']; + $port = $data['port'] ? mres($data['port']) : $config['snmp']['port']; + $transport = $data['transport'] ? mres($data['transport']) : 'udp'; + $poller_group = $data['poller_group'] ? mres($data['poller_group']) : 0; + $force_add = $data['force_add'] ? mres($data['force_add']) : 0; + if ($data['version'] == 'v1' || $data['version'] == 'v2c') { + if ($data['community']) { + $config['snmp']['community'] = array($data['community']); + } + + $snmpver = mres($data['version']); + } + else if ($data['version'] == 'v3') { + $v3 = array( + 'authlevel' => mres($data['authlevel']), + 'authname' => mres($data['authname']), + 'authpass' => mres($data['authpass']), + 'authalgo' => mres($data['authalgo']), + 'cryptopass' => mres($data['cryptopass']), + 'cryptoalgo' => mres($data['cryptoalgo']), + ); + + array_push($config['snmp']['v3'], $v3); + $snmpver = 'v3'; + } + else { + $code = 400; + $status = 'error'; + $message = "You haven't specified an SNMP version to use"; + } + if (empty($message)) { + $result = addHost($hostname, $snmpver, $port, $transport, 1, $poller_group, $force_add); + if ($result) { + $code = 201; + $status = 'ok'; + $message = "Device $hostname has been added successfully"; + } + else { + $message = "Failed adding $hostname"; + } + } + + $app->response->setStatus($code); + $output = array( + 'status' => $status, + 'message' => $message, + ); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); + +} + + +function del_device() { + // This will add a device using the data passed encoded with json + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $hostname = $router['hostname']; + // Default status to error and change it if we need to. + $status = 'error'; + $code = 500; + if (empty($hostname) || $config['api_demo'] == 1) { + $message = 'No hostname has been provided to delete'; + if ($config['api_demo'] == 1) { + $message = "This feature isn\'t available in the demo"; + } + + $output = array( + 'status' => $status, + 'message' => $message, + ); + } + + else { + // allow deleting by device_id or hostname $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - $device = null; + $device = null; if ($device_id) { // save the current details for returning to the client on successful delete $device = device_by_id_cache($device_id); } + if ($device) { - $vlans = dbFetchRows("SELECT vlan_vlan,vlan_domain,vlan_name,vlan_type,vlan_mtu FROM vlans WHERE `device_id` = ?", array($device_id)); - $total_vlans = count($vlans); - $code = 200; - $output = array("status" => "ok", "count" => $total_vlans, "vlans" => $vlans); - } else { - $code = 404; - $output = array("status" => "error", "Device $hostname not found"); + $response = delete_device($device_id); + if (empty($response)) { + // FIXME: Need to provide better diagnostics out of delete_device + $output = array( + 'status' => $status, + 'message' => 'Device deletion failed', + ); + } + else { + // deletion succeeded - include old device details in response + $code = 200; + $status = 'ok'; + $output = array( + 'status' => $status, + 'message' => $response, + 'devices' => array($device), + ); + } + } + else { + // no device matching the name + $code = 404; + $output = array( + 'status' => $status, + 'message' => "Device $hostname not found", + ); } } + $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + +function get_vlans() { + // This will list all vlans for a given device + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $hostname = $router['hostname']; + $code = 500; + if (empty($hostname)) { + $output = $output = array( + 'status' => 'error', + 'message' => 'No hostname has been provided', + ); + } + else { + include_once '../includes/functions.php'; + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + $device = null; + if ($device_id) { + // save the current details for returning to the client on successful delete + $device = device_by_id_cache($device_id); + } + + if ($device) { + $vlans = dbFetchRows('SELECT vlan_vlan,vlan_domain,vlan_name,vlan_type,vlan_mtu FROM vlans WHERE `device_id` = ?', array($device_id)); + $total_vlans = count($vlans); + $code = 200; + $output = array( + 'status' => 'ok', + 'count' => $total_vlans, + 'vlans' => $vlans, + ); + } + + else { + $code = 404; + $output = array( + 'status' => 'error', "Device $hostname not found" + ); + } + } + + $app->response->setStatus($code); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); + +} + + function show_endpoints() { global $config; - $app = \Slim\Slim::getInstance(); - $routes = $app->router()->getNamedRoutes(); + $app = \Slim\Slim::getInstance(); + $routes = $app->router()->getNamedRoutes(); $output = array(); - foreach($routes as $route) { - $output[$route->getName()] = $config['base_url'].$route->getPattern(); + foreach ($routes as $route) { + $output[$route->getName()] = $config['base_url'].$route->getPattern(); } + $app->response->setStatus('200'); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function list_bgp() { global $config; - $app = \Slim\Slim::getInstance(); - $code = 500; - $status = 'error'; - $message = 'Error retrieving bgpPeers'; - $sql = ''; + $app = \Slim\Slim::getInstance(); + $code = 500; + $status = 'error'; + $message = 'Error retrieving bgpPeers'; + $sql = ''; $sql_params = array(); - $hostname = $_GET['hostname']; - $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - if(is_numeric($device_id)) { - $sql = " AND `device_id`=?"; + $hostname = $_GET['hostname']; + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + if (is_numeric($device_id)) { + $sql = ' AND `device_id`=?'; $sql_params = array($device_id); } - $bgp_sessions = dbFetchRows("SELECT * FROM bgpPeers WHERE `bgpPeerState` IS NOT NULL AND `bgpPeerState` != '' $sql", $sql_params); + + $bgp_sessions = dbFetchRows("SELECT * FROM bgpPeers WHERE `bgpPeerState` IS NOT NULL AND `bgpPeerState` != '' $sql", $sql_params); $total_bgp_sessions = count($bgp_sessions); - if(is_numeric($total_bgp_sessions)) { - $code = 200; - $status = 'ok'; + if (is_numeric($total_bgp_sessions)) { + $code = 200; + $status = 'ok'; $message = ''; } - $output = array("status" => "$status", "err-msg" => $message, "count" => $total_bgp_sessions, "bgp_sessions" => $bgp_sessions); + + $output = array( + 'status' => "$status", + 'err-msg' => $message, + 'count' => $total_bgp_sessions, + 'bgp_sessions' => $bgp_sessions, + ); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function get_graph_by_portgroup() { - global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); - $group = $router['group']; - $vars = array(); - if(!empty($_GET['from'])) - { - $vars['from'] = $_GET['from']; - } - if(!empty($_GET['to'])) - { - $vars['to'] = $_GET['to']; - } - $vars['width'] = $_GET['width'] ?: 1075; - $vars['height'] = $_GET['height'] ?: 300; - $auth = "1"; - $type_where = " ("; - $or = ''; - $type_param = array(); - foreach (explode(",", $group) as $type) - { - $type_where .= " $or `port_descr_type` = ?"; - $or = "OR"; - $type_param[] = $type; - } + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $group = $router['group']; + $vars = array(); + if (!empty($_GET['from'])) { + $vars['from'] = $_GET['from']; + } + + if (!empty($_GET['to'])) { + $vars['to'] = $_GET['to']; + } + + $vars['width'] = $_GET['width'] ?: 1075; + $vars['height'] = $_GET['height'] ?: 300; + $auth = '1'; + $type_where = ' ('; + $or = ''; + $type_param = array(); + foreach (explode(',', $group) as $type) { + $type_where .= " $or `port_descr_type` = ?"; + $or = 'OR'; + $type_param[] = $type; + } + + $type_where .= ') '; + $if_list = ''; + $seperator = ''; + $ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias", $type_param); + foreach ($ports as $port) { + $if_list .= $seperator.$port['port_id']; + $seperator = ','; + } + + unset($seperator); + $vars['type'] = 'multiport_bits_separate'; + $vars['id'] = $if_list; + $app->response->headers->set('Content-Type', 'image/png'); + include 'includes/graphs/graph.inc.php'; - $type_where .= ") "; - $if_list = ''; - $seperator = ''; - $ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias", $type_param); - foreach ($ports as $port) - { - $if_list .= $seperator . $port['port_id']; - $seperator = ","; - } - unset($seperator); - $vars['type'] = "multiport_bits_separate"; - $vars['id'] = $if_list; - $app->response->headers->set('Content-Type', 'image/png'); - require("includes/graphs/graph.inc.php"); } + function get_graphs() { global $config; - $code = 200; - $status = 'ok'; - $message = ''; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); + $code = 200; + $status = 'ok'; + $message = ''; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); $hostname = $router['hostname']; // FIXME: this has some overlap with html/pages/device/graphs.inc.php // use hostname as device_id if it's all digits $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - $graphs = array(); - $graphs[] = array('desc' => 'Poller Time', 'name' => 'device_poller_perf'); - $graphs[] = array('desc' => 'Ping Response', 'name' => 'device_ping_perf'); - foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph", array($device_id)) as $graph) { - $desc = $config['graph_types']['device'][$graph['graph']]['descr']; - $graphs[] = array('desc' => $desc, 'name' => 'device_'.$graph['graph']); + $graphs = array(); + $graphs[] = array( + 'desc' => 'Poller Time', + 'name' => 'device_poller_perf', + ); + $graphs[] = array( + 'desc' => 'Ping Response', + 'name' => 'device_ping_perf', + ); + foreach (dbFetchRows('SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph', array($device_id)) as $graph) { + $desc = $config['graph_types']['device'][$graph['graph']]['descr']; + $graphs[] = array( + 'desc' => $desc, + 'name' => 'device_'.$graph['graph'], + ); } + $total_graphs = count($graphs); - $output = array("status" => "$status", "err-msg" => $message, "count" => $total_graphs, "graphs" => $graphs); + $output = array( + 'status' => "$status", + 'err-msg' => $message, + 'count' => $total_graphs, + 'graphs' => $graphs, + ); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function get_port_graphs() { global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); $hostname = $router['hostname']; - if(isset($_GET['columns'])) { + if (isset($_GET['columns'])) { $columns = $_GET['columns']; - } else { + } + else { $columns = 'ifName'; } // use hostname as device_id if it's all digits - $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - $ports = dbFetchRows("SELECT $columns FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device_id)); + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + $ports = dbFetchRows("SELECT $columns FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device_id)); $total_ports = count($ports); - $output = array("status" => "ok", "err-msg" => '', "count" => $total_ports, "ports" => $ports); + $output = array( + 'status' => 'ok', + 'err-msg' => '', + 'count' => $total_ports, + 'ports' => $ports, + ); $app->response->setStatus('200'); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function list_bills() { global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); $bill_id = $router['bill_id']; - if(isset($_GET['custid'])) { - $sql = "`bill_custid` = ?"; + if (isset($_GET['custid'])) { + $sql = '`bill_custid` = ?'; $param = array($_GET['custid']); - } elseif(isset($_GET['ref'])) { - $sql = "`bill_ref` = ?"; + } + else if (isset($_GET['ref'])) { + $sql = '`bill_ref` = ?'; $param = array($_GET['ref']); - } elseif(is_numeric($bill_id)) { - $sql = "`bill_id` = ?"; + } + else if (is_numeric($bill_id)) { + $sql = '`bill_id` = ?'; $param = array($bill_id); - } else { - $sql = ""; + } + + else { + $sql = ''; $param = array(); } - if(count($param) >= 1) { + + if (count($param) >= 1) { $sql = "WHERE $sql"; } - $bills = dbFetchRows("SELECT * FROM `bills` $sql",$param); + + $bills = dbFetchRows("SELECT * FROM `bills` $sql", $param); $total_bills = count($bills); - $output = array("status" => "ok", "err-msg" => '', "count" => $total_bills, "bills" => $bills); + $output = array( + 'status' => 'ok', + 'err-msg' => '', + 'count' => $total_bills, + 'bills' => $bills, + ); $app->response->setStatus('200'); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function list_alert_rules() { global $config; - $app = \Slim\Slim::getInstance(); + $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); - $sql = ''; - $param = array(); - if(isset($router['id']) && $router['id'] > 0) { + $sql = ''; + $param = array(); + if (isset($router['id']) && $router['id'] > 0) { $rule_id = mres($router['id']); - $sql = "WHERE id=?"; - $param = array($rule_id); + $sql = 'WHERE id=?'; + $param = array($rule_id); } - $rules = dbFetchRows("SELECT * FROM `alert_rules` $sql",$param); + + $rules = dbFetchRows("SELECT * FROM `alert_rules` $sql", $param); $total_rules = count($rules); - $output = array("status" => "ok", "err-msg" => '', "count" => $total_rules, "rules" => $rules); + $output = array( + 'status' => 'ok', + 'err-msg' => '', + 'count' => $total_rules, + 'rules' => $rules, + ); $app->response->setStatus('200'); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function list_alerts() { global $config; - $app = \Slim\Slim::getInstance(); + $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); - if(isset($_POST['state'])) { + if (isset($_POST['state'])) { $param = array(mres($_POST['state'])); - } else { + } + else { $param = array('1'); } + $sql = ''; - if(isset($router['id']) && $router['id'] > 0) { + if (isset($router['id']) && $router['id'] > 0) { $alert_id = mres($router['id']); - $sql = "AND id=?"; - array_push($param,$alert_id); + $sql = 'AND id=?'; + array_push($param, $alert_id); } - $alerts = dbFetchRows("SELECT `D`.`hostname`, `A`.* FROM `alerts` AS `A`, `devices` AS `D` WHERE `D`.`device_id` = `A`.`device_id` AND `A`.`state` IN (?) $sql",$param); + + $alerts = dbFetchRows("SELECT `D`.`hostname`, `A`.* FROM `alerts` AS `A`, `devices` AS `D` WHERE `D`.`device_id` = `A`.`device_id` AND `A`.`state` IN (?) $sql", $param); $total_alerts = count($alerts); - $output = array("status" => "ok", "err-msg" => '', "count" => $total_alerts, "alerts" => $alerts); + $output = array( + 'status' => 'ok', + 'err-msg' => '', + 'count' => $total_alerts, + 'alerts' => $alerts, + ); $app->response->setStatus('200'); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function add_edit_rule() { global $config; - $app = \Slim\Slim::getInstance(); + $app = \Slim\Slim::getInstance(); $data = json_decode(file_get_contents('php://input'), true); - $status = 'error'; + $status = 'error'; $message = ''; - $code = 500; + $code = 500; $rule_id = mres($data['rule_id']); $device_id = mres($data['device_id']); - if(empty($device_id) && !isset($rule_id)) { + if (empty($device_id) && !isset($rule_id)) { $message = 'Missing the device id or global device id (-1)'; - } elseif($device_id == 0) { + } + else if ($device_id == 0) { $device_id = '-1'; } $rule = $data['rule']; - if(empty($rule)) { + if (empty($rule)) { $message = 'Missing the alert rule'; } + $name = mres($data['name']); if (empty($name)) { $message = 'Missing the alert rule name'; } + $severity = mres($data['severity']); - $sevs = array("ok","warning","critical"); - if(!in_array($severity, $sevs)) { + $sevs = array( + 'ok', + 'warning', + 'critical', + ); + if (!in_array($severity, $sevs)) { $message = 'Missing the severity'; } + $disabled = mres($data['disabled']); - if($disabled != '0' && $disabled != '1') { + if ($disabled != '0' && $disabled != '1') { $disabled = 0; } - $count = mres($data['count']); - $mute = mres($data['mute']); - $delay = mres($data['delay']); + $count = mres($data['count']); + $mute = mres($data['mute']); + $delay = mres($data['delay']); $delay_sec = convert_delay($delay); - if($mute == 1) { + if ($mute == 1) { $mute = true; - } else { + } + else { $mute = false; } - $extra = array('mute'=>$mute,'count'=>$count,'delay'=>$delay_sec); + $extra = array( + 'mute' => $mute, + 'count' => $count, + 'delay' => $delay_sec, + ); $extra_json = json_encode($extra); - if (dbFetchCell("SELECT `name` FROM `alert_rules` WHERE `name`=?",array($name)) == $name) { + if (dbFetchCell('SELECT `name` FROM `alert_rules` WHERE `name`=?', array($name)) == $name) { $message = 'Name has already been used'; } - if(empty($message)) { - if(is_numeric($rule_id)) { - if( dbUpdate(array('name' => $name, 'rule' => $rule,'severity'=>$severity,'disabled'=>$disabled,'extra'=>$extra_json), 'alert_rules', 'id=?',array($rule_id)) >= 0) { + if (empty($message)) { + if (is_numeric($rule_id)) { + if (dbUpdate(array('name' => $name, 'rule' => $rule, 'severity' => $severity, 'disabled' => $disabled, 'extra' => $extra_json), 'alert_rules', 'id=?', array($rule_id)) >= 0) { $status = 'ok'; - $code = 200; - } else { + $code = 200; + } + + else { $message = 'Failed to update existing alert rule'; } - } elseif( dbInsert(array('name' => $name, 'device_id'=>$device_id,'rule'=>$rule,'severity'=>$severity,'disabled'=>$disabled,'extra'=>$extra_json),'alert_rules') ) { + } + else if (dbInsert(array('name' => $name, 'device_id' => $device_id, 'rule' => $rule, 'severity' => $severity, 'disabled' => $disabled, 'extra' => $extra_json), 'alert_rules')) { $status = 'ok'; - $code = 200; - } else { + $code = 200; + } + else { $message = 'Failed to create new alert rule'; } } - $output = array("status" => $status, "err-msg" => $message); + + $output = array( + 'status' => $status, + 'err-msg' => $message, + ); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function delete_rule() { global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); $rule_id = mres($router['id']); - $status = 'error'; + $status = 'error'; $err_msg = ''; $message = ''; - $code = 500; - if(is_numeric($rule_id)) { + $code = 500; + if (is_numeric($rule_id)) { $status = 'ok'; - $code = 200; - if(dbDelete('alert_rules', "`id` = ? LIMIT 1", array($rule_id))) { + $code = 200; + if (dbDelete('alert_rules', '`id` = ? LIMIT 1', array($rule_id))) { $message = 'Alert rule has been removed'; - } else { + } + else { $message = 'No alert rule by that ID'; } - } else { + } + + else { $err_msg = 'Invalid rule id has been provided'; } - $output = array("status" => $status, "err-msg" => $err_msg, "message" => $message); + + $output = array( + 'status' => $status, + 'err-msg' => $err_msg, + 'message' => $message, + ); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function ack_alert() { global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); $alert_id = mres($router['id']); - $status = 'error'; - $err_msg = ''; - $message = ''; - $code = 500; - if(is_numeric($alert_id)) { + $status = 'error'; + $err_msg = ''; + $message = ''; + $code = 500; + if (is_numeric($alert_id)) { $status = 'ok'; - $code = 200; - if(dbUpdate(array("state" => 2), 'alerts', '`id` = ? LIMIT 1', array($alert_id))) { + $code = 200; + if (dbUpdate(array('state' => 2), 'alerts', '`id` = ? LIMIT 1', array($alert_id))) { $message = 'Alert has been ackgnowledged'; - } else { + } + else { $message = 'No alert by that ID'; } - } else { + } + else { $err_msg = 'Invalid alert has been provided'; } - $output = array("status" => $status, "err-msg" => $err_msg, "message" => $message); + + $output = array( + 'status' => $status, + 'err-msg' => $err_msg, + 'message' => $message, + ); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function get_inventory() { global $config; - $app = \Slim\Slim::getInstance(); - $router = $app->router()->getCurrentRoute()->getParams(); - $status = 'error'; - $err_msg = ''; - $code = 500; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $status = 'error'; + $err_msg = ''; + $code = 500; $hostname = $router['hostname']; // use hostname as device_id if it's all digits $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - $sql = ''; - $params = array(); + $sql = ''; + $params = array(); if (isset($_GET['entPhysicalClass']) && !empty($_GET['entPhysicalClass'])) { - $sql .= ' AND entPhysicalClass=?'; + $sql .= ' AND entPhysicalClass=?'; $params[] = mres($_GET['entPhysicalClass']); } + if (isset($_GET['entPhysicalContainedIn']) && !empty($_GET['entPhysicalContainedIn'])) { - $sql .= ' AND entPhysicalContainedIn=?'; + $sql .= ' AND entPhysicalContainedIn=?'; $params[] = mres($_GET['entPhysicalContainedIn']); - } else { + } + else { $sql .= ' AND entPhysicalContainedIn="0"'; } + if (!is_numeric($device_id)) { - $err_msg = 'Invalid device provided'; + $err_msg = 'Invalid device provided'; $total_inv = 0; $inventory = array(); - } else { - $inventory = dbFetchRows("SELECT * FROM `entPhysical` WHERE 1 $sql",$params); - $code = 200; - $status = 'ok'; + } + + else { + $inventory = dbFetchRows("SELECT * FROM `entPhysical` WHERE 1 $sql", $params); + $code = 200; + $status = 'ok'; $total_inv = count($inventory); } - $output = array("status" => $status, "err-msg" => $err_msg, "count" => $total_inv, "inventory" => $inventory); + + $output = array( + 'status' => $status, + 'err-msg' => $err_msg, + 'count' => $total_inv, + 'inventory' => $inventory, + ); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); + } + function list_oxidized() { - // return details of a single device - $app = \Slim\Slim::getInstance(); - $app->response->headers->set('Content-Type', 'application/json'); + // return details of a single device + $app = \Slim\Slim::getInstance(); + $app->response->headers->set('Content-Type', 'application/json'); - $devices = array(); - foreach (dbFetchRows("SELECT hostname,os FROM `devices` WHERE `status`='1'") as $device) { - $devices[] = $device; - } - $app->response->headers->set('Content-Type', 'application/json'); - echo _json_encode($devices); + $devices = array(); + foreach (dbFetchRows("SELECT hostname,os FROM `devices` WHERE `status`='1'") as $device) { + $devices[] = $device; + } + + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($devices); } diff --git a/html/includes/authenticate.inc.php b/html/includes/authenticate.inc.php index e64465a35e..316fcde5c5 100644 --- a/html/includes/authenticate.inc.php +++ b/html/includes/authenticate.inc.php @@ -1,123 +1,114 @@ RRD Log Directory is missing ({$config['rrd_dir']}). Graphing may fail."); +if (!is_dir($config['rrd_dir'])) { + echo "
    RRD Log Directory is missing ({$config['rrd_dir']}). Graphing may fail.
    "; } -if (!is_dir($config['temp_dir'])) -{ - echo("
    Temp Directory is missing ({$config['temp_dir']}). Graphing may fail.
    "); +if (!is_dir($config['temp_dir'])) { + echo "
    Temp Directory is missing ({$config['temp_dir']}). Graphing may fail.
    "; } -if (!is_writable($config['temp_dir'])) -{ - echo("
    Temp Directory is not writable ({$config['tmp_dir']}). Graphing may fail.
    "); +if (!is_writable($config['temp_dir'])) { + echo "
    Temp Directory is not writable ({$config['tmp_dir']}). Graphing may fail.
    "; } // Clear up any old sessions -dbDelete('session', "`session_expiry` < ?", array(time())); +dbDelete('session', '`session_expiry` < ?', array(time())); -if ($vars['page'] == "logout" && $_SESSION['authenticated']) -{ - dbInsert(array('user' => $_SESSION['username'], 'address' => get_client_ip(), 'result' => 'Logged Out'), 'authlog'); - dbDelete('session', "`session_username` = ? AND session_value = ?", array($_SESSION['username'],$_COOKIE['sess_id'])); - unset($_SESSION); - unset($_COOKIE); - setcookie ("sess_id", "", time() - 60*60*24*$config['auth_remember'], "/"); - setcookie ("token", "", time() - 60*60*24*$config['auth_remember'], "/"); - setcookie ("auth", "", time() - 60*60*24*$config['auth_remember'], "/"); - session_destroy(); - $auth_message = "Logged Out"; - header('Location: /'); - exit; +if ($vars['page'] == 'logout' && $_SESSION['authenticated']) { + dbInsert(array('user' => $_SESSION['username'], 'address' => get_client_ip(), 'result' => 'Logged Out'), 'authlog'); + dbDelete('session', '`session_username` = ? AND session_value = ?', array($_SESSION['username'], $_COOKIE['sess_id'])); + unset($_SESSION); + unset($_COOKIE); + setcookie('sess_id', '', (time() - 60 * 60 * 24 * $config['auth_remember']), '/'); + setcookie('token', '', (time() - 60 * 60 * 24 * $config['auth_remember']), '/'); + setcookie('auth', '', (time() - 60 * 60 * 24 * $config['auth_remember']), '/'); + session_destroy(); + $auth_message = 'Logged Out'; + header('Location: /'); + exit; } // We are only interested in login details passed via POST. if (isset($_POST['username']) && isset($_POST['password'])) { - $_SESSION['username'] = mres($_POST['username']); - $_SESSION['password'] = $_POST['password']; -} elseif(isset($_GET['username']) && isset($_GET['password'])) { - $_SESSION['username'] = mres($_GET['username']); - $_SESSION['password'] = $_GET['password']; + $_SESSION['username'] = mres($_POST['username']); + $_SESSION['password'] = $_POST['password']; +} +else if (isset($_GET['username']) && isset($_GET['password'])) { + $_SESSION['username'] = mres($_GET['username']); + $_SESSION['password'] = $_GET['password']; } -if (!isset($config['auth_mechanism'])) -{ - $config['auth_mechanism'] = "mysql"; +if (!isset($config['auth_mechanism'])) { + $config['auth_mechanism'] = 'mysql'; } -if (file_exists('includes/authentication/' . $config['auth_mechanism'] . '.inc.php')) -{ - include_once('includes/authentication/' . $config['auth_mechanism'] . '.inc.php'); +if (file_exists('includes/authentication/'.$config['auth_mechanism'].'.inc.php')) { + include_once 'includes/authentication/'.$config['auth_mechanism'].'.inc.php'; } -else -{ - print_error('ERROR: no valid auth_mechanism defined!'); - exit(); +else { + print_error('ERROR: no valid auth_mechanism defined!'); + exit(); } $auth_success = 0; -if ((isset($_SESSION['username'])) || (isset($_COOKIE['sess_id'],$_COOKIE['token']))) -{ - if ((authenticate($_SESSION['username'],$_SESSION['password'])) || (reauthenticate($_COOKIE['sess_id'],$_COOKIE['token']))) - { - $_SESSION['userlevel'] = get_userlevel($_SESSION['username']); - $_SESSION['user_id'] = get_userid($_SESSION['username']); - if (!$_SESSION['authenticated']) - { - if( $config['twofactor'] === true && !isset($_SESSION['twofactor']) ) { - require_once($config['install_dir'].'/html/includes/authentication/twofactor.lib.php'); - twofactor_auth(); - } - if( !$config['twofactor'] || $_SESSION['twofactor'] ) { - $_SESSION['authenticated'] = true; - dbInsert(array('user' => $_SESSION['username'], 'address' => get_client_ip(), 'result' => 'Logged In'), 'authlog'); - } +if ((isset($_SESSION['username'])) || (isset($_COOKIE['sess_id'],$_COOKIE['token']))) { + if ((authenticate($_SESSION['username'], $_SESSION['password'])) || (reauthenticate($_COOKIE['sess_id'], $_COOKIE['token']))) { + $_SESSION['userlevel'] = get_userlevel($_SESSION['username']); + $_SESSION['user_id'] = get_userid($_SESSION['username']); + if (!$_SESSION['authenticated']) { + if ($config['twofactor'] === true && !isset($_SESSION['twofactor'])) { + include_once $config['install_dir'].'/html/includes/authentication/twofactor.lib.php'; + twofactor_auth(); + } + + if (!$config['twofactor'] || $_SESSION['twofactor']) { + $_SESSION['authenticated'] = true; + dbInsert(array('user' => $_SESSION['username'], 'address' => get_client_ip(), 'result' => 'Logged In'), 'authlog'); + } + } + + if (isset($_POST['remember'])) { + $sess_id = session_id(); + $hasher = new PasswordHash(8, false); + $token = strgen(); + $auth = strgen(); + $hasher = new PasswordHash(8, false); + $token_id = $_SESSION['username'].'|'.$hasher->HashPassword($_SESSION['username'].$token); + // If we have been asked to remember the user then set the relevant cookies and create a session in the DB. + setcookie('sess_id', $sess_id, (time() + 60 * 60 * 24 * $config['auth_remember']), '/', null, false, true); + setcookie('token', $token_id, (time() + 60 * 60 * 24 * $config['auth_remember']), '/', null, false, true); + setcookie('auth', $auth, (time() + 60 * 60 * 24 * $config['auth_remember']), '/', null, false, true); + dbInsert(array('session_username' => $_SESSION['username'], 'session_value' => $sess_id, 'session_token' => $token, 'session_auth' => $auth, 'session_expiry' => time() + 60 * 60 * 24 * $config['auth_remember']), 'session'); + } + + if (isset($_COOKIE['sess_id'],$_COOKIE['token'],$_COOKIE['auth'])) { + // If we have the remember me cookies set then update session expiry times to keep us logged in. + $sess_id = session_id(); + dbUpdate(array('session_value' => $sess_id, 'session_expiry' => time() + 60 * 60 * 24 * $config['auth_remember']), 'session', 'session_auth=?', array($_COOKIE['auth'])); + setcookie('sess_id', $sess_id, (time() + 60 * 60 * 24 * $config['auth_remember']), '/', null, false, true); + setcookie('token', $_COOKIE['token'], (time() + 60 * 60 * 24 * $config['auth_remember']), '/', null, false, true); + setcookie('auth', $_COOKIE['auth'], (time() + 60 * 60 * 24 * $config['auth_remember']), '/', null, false, true); + } + + $permissions = permissions_cache($_SESSION['user_id']); + if (isset($_POST['username'])) { + header('Location: '.$_SERVER['REQUEST_URI'], true, 303); + exit; + } } - if (isset($_POST['remember'])) - { - $sess_id = session_id(); - $hasher = new PasswordHash(8, FALSE); - $token = strgen(); - $auth = strgen(); - $hasher = new PasswordHash(8, FALSE); - $token_id = $_SESSION['username'].'|'.$hasher->HashPassword($_SESSION['username'].$token); - // If we have been asked to remember the user then set the relevant cookies and create a session in the DB. - setcookie("sess_id", $sess_id, time()+60*60*24*$config['auth_remember'], "/", null, false, true); - setcookie("token", $token_id, time()+60*60*24*$config['auth_remember'], "/", null, false, true); - setcookie("auth", $auth, time()+60*60*24*$config['auth_remember'], "/", null, false, true); - dbInsert(array('session_username' => $_SESSION['username'], 'session_value' => $sess_id, 'session_token' => $token, 'session_auth' => $auth, 'session_expiry' => time()+60*60*24*$config['auth_remember']), 'session'); + else if (isset($_SESSION['username'])) { + $auth_message = 'Authentication Failed'; + unset($_SESSION['authenticated']); + dbInsert(array('user' => $_SESSION['username'], 'address' => get_client_ip(), 'result' => 'Authentication Failure'), 'authlog'); } - if (isset($_COOKIE['sess_id'],$_COOKIE['token'],$_COOKIE['auth'])) - { - // If we have the remember me cookies set then update session expiry times to keep us logged in. - $sess_id = session_id(); - dbUpdate(array('session_value' => $sess_id, 'session_expiry' => time()+60*60*24*$config['auth_remember']), 'session', 'session_auth=?', array($_COOKIE['auth'])); - setcookie("sess_id", $sess_id, time()+60*60*24*$config['auth_remember'], "/", null, false, true); - setcookie("token", $_COOKIE['token'], time()+60*60*24*$config['auth_remember'], "/", null, false, true); - setcookie("auth", $_COOKIE['auth'], time()+60*60*24*$config['auth_remember'], "/", null, false, true); - } - $permissions = permissions_cache($_SESSION['user_id']); - if (isset($_POST['username'])) { - header('Location: '.$_SERVER['REQUEST_URI'],TRUE,303); - exit; - } - } - elseif (isset($_SESSION['username'])) - { - $auth_message = "Authentication Failed"; - unset ($_SESSION['authenticated']); - dbInsert(array('user' => $_SESSION['username'], 'address' => get_client_ip(), 'result' => 'Authentication Failure'), 'authlog'); - } } -?> diff --git a/html/includes/authentication/http-auth.inc.php b/html/includes/authentication/http-auth.inc.php index 883cd2d08d..221de3adca 100644 --- a/html/includes/authentication/http-auth.inc.php +++ b/html/includes/authentication/http-auth.inc.php @@ -1,104 +1,99 @@ HashPassword($password); return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname), 'users'); - } else { - return FALSE; + } + else { + return false; } } -function user_exists($username) -{ - // FIXME this doesn't seem right? (adama) - return dbFetchCell("SELECT * FROM `users` WHERE `username` = ?", array($username)); + +function user_exists($username) { + // FIXME this doesn't seem right? (adama) + return dbFetchCell('SELECT * FROM `users` WHERE `username` = ?', array($username)); } -function get_userlevel($username) -{ - return dbFetchCell("SELECT `level` FROM `users` WHERE `username`= ?", array($username)); + +function get_userlevel($username) { + return dbFetchCell('SELECT `level` FROM `users` WHERE `username`= ?', array($username)); } -function get_userid($username) -{ - return dbFetchCell("SELECT `user_id` FROM `users` WHERE `username`= ?", array($username)); + +function get_userid($username) { + return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username`= ?', array($username)); } -function deluser($username) -{ - # Not supported - return 0; + +function deluser($username) { + // Not supported + return 0; } -function get_userlist() -{ - return dbFetchRows("SELECT * FROM `users`"); + +function get_userlist() { + return dbFetchRows('SELECT * FROM `users`'); } -function can_update_users() -{ - # supported so return 1 - return 1; + +function can_update_users() { + // supported so return 1 + return 1; } -function get_user($user_id) -{ - return dbFetchRow("SELECT * FROM `users` WHERE `user_id` = ?", array($user_id)); + +function get_user($user_id) { + return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id)); } -function update_user($user_id,$realname,$level,$can_modify_passwd,$email) -{ - dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id)); -} -?> +function update_user($user_id, $realname, $level, $can_modify_passwd, $email) { + dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id)); +} diff --git a/html/includes/authentication/ldap.inc.php b/html/includes/authentication/ldap.inc.php index c0416ab0f0..c55b54009b 100644 --- a/html/includes/authentication/ldap.inc.php +++ b/html/includes/authentication/ldap.inc.php @@ -1,228 +1,237 @@ Fatal error: LDAP TLS required but not successfully negotiated:" . ldap_error($ds) . ""); - exit; - } +if ($config['auth_ldap_starttls'] && ($config['auth_ldap_starttls'] == 'optional' || $config['auth_ldap_starttls'] == 'require')) { + $tls = ldap_start_tls($ds); + if ($config['auth_ldap_starttls'] == 'require' && $tls == false) { + echo '

    Fatal error: LDAP TLS required but not successfully negotiated:'.ldap_error($ds).'

    '; + exit; + } } -function authenticate($username,$password) -{ - global $config, $ds; - - if ($username && $ds) - { - if ($config['auth_ldap_version']) - { - ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']); + +function authenticate($username, $password) { + global $config, $ds; + + if ($username && $ds) { + if ($config['auth_ldap_version']) { + ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']); + } + + if (ldap_bind($ds, $config['auth_ldap_prefix'].$username.$config['auth_ldap_suffix'], $password)) { + if (!$config['auth_ldap_group']) { + return 1; + } + else { + $ldap_groups = get_group_list(); + foreach ($ldap_groups as $ldap_group) { + $ldap_comparison = ldap_compare( + $ds, + $ldap_group, + $config['auth_ldap_groupmemberattr'], + get_membername($username) + ); + if ($ldap_comparison === true) { + return 1; + } + } + } + } + else { + echo ldap_error($ds); + } } - if (ldap_bind($ds, $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix'], $password)) - { - if (!$config['auth_ldap_group']) - { + else { + // FIXME return a warning that LDAP couldn't connect? + } + + return 0; + +} + + +function reauthenticate($sess_id, $token) { + return 0; + +} + + +function passwordscanchange($username='') { + return 0; + +} + + +function changepassword($username, $newpassword) { + // Not supported (for now) + +} + + +function auth_usermanagement() { + return 0; + +} + + +function adduser($username, $password, $level, $email='', $realname='', $can_modify_passwd='1') { + // Not supported + return 0; + +} + + +function user_exists($username) { + global $config, $ds; + + $filter = '('.$config['auth_ldap_prefix'].$username.')'; + $search = ldap_search($ds, trim($config['auth_ldap_suffix'], ','), $filter); + $entries = ldap_get_entries($ds, $search); + if ($entries['count']) { return 1; - } - else - { - $ldap_groups = get_group_list(); - foreach($ldap_groups as $ldap_group) { - $ldap_comparison = ldap_compare($ds, - $ldap_group, - $config['auth_ldap_groupmemberattr'], - get_membername($username)); - if($ldap_comparison === true) { - return 1; - } + } + + return 0; + +} + + +function get_userlevel($username) { + global $config, $ds; + + $userlevel = 0; + + // Find all defined groups $username is in + $filter = '(&(|(cn='.join(')(cn=', array_keys($config['auth_ldap_groups'])).'))('.$config['auth_ldap_groupmemberattr'].'='.get_membername($username).'))'; + $search = ldap_search($ds, $config['auth_ldap_groupbase'], $filter); + $entries = ldap_get_entries($ds, $search); + + // Loop the list and find the highest level + foreach ($entries as $entry) { + $groupname = $entry['cn'][0]; + if ($config['auth_ldap_groups'][$groupname]['level'] > $userlevel) { + $userlevel = $config['auth_ldap_groups'][$groupname]['level']; } - } } - else - { - echo(ldap_error($ds)); + + return $userlevel; + +} + + +function get_userid($username) { + global $config, $ds; + + $filter = '('.$config['auth_ldap_prefix'].$username.')'; + $search = ldap_search($ds, trim($config['auth_ldap_suffix'], ','), $filter); + $entries = ldap_get_entries($ds, $search); + + if ($entries['count']) { + return $entries[0]['uidnumber'][0]; } - } - else - { - // FIXME return a warning that LDAP couldn't connect? - } - return 0; + return -1; + } -function reauthenticate($sess_id,$token) -{ - return 0; + +function deluser($username) { + // Not supported + return 0; + } -function passwordscanchange($username = "") -{ - return 0; -} -function changepassword($username,$newpassword) -{ - # Not supported (for now) -} +function get_userlist() { + global $config, $ds; + $userlist = array(); -function auth_usermanagement() -{ - return 0; -} + $filter = '('.$config['auth_ldap_prefix'].'*)'; -function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd = '1') -{ - # Not supported - return 0; -} + $search = ldap_search($ds, trim($config['auth_ldap_suffix'], ','), $filter); + $entries = ldap_get_entries($ds, $search); -function user_exists($username) -{ - global $config, $ds; - - $filter = "(" . $config['auth_ldap_prefix'] . $username . ")"; - $search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter); - $entries = ldap_get_entries($ds, $search); - if ($entries['count']) - { - return 1; - } - - return 0; -} - -function get_userlevel($username) -{ - global $config, $ds; - - $userlevel = 0; - - # Find all defined groups $username is in - $filter = "(&(|(cn=" . join(")(cn=", array_keys($config['auth_ldap_groups'])) . "))(". $config['auth_ldap_groupmemberattr']. "=" . get_membername($username) . "))"; - $search = ldap_search($ds, $config['auth_ldap_groupbase'], $filter); - $entries = ldap_get_entries($ds, $search); - - # Loop the list and find the highest level - foreach ($entries as $entry) - { - $groupname = $entry['cn'][0]; - if ($config['auth_ldap_groups'][$groupname]['level'] > $userlevel) - { - $userlevel = $config['auth_ldap_groups'][$groupname]['level']; - } - } - - return $userlevel; -} - -function get_userid($username) -{ - global $config, $ds; - - $filter = "(" . $config['auth_ldap_prefix'] . $username . ")"; - $search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter); - $entries = ldap_get_entries($ds, $search); - - if ($entries['count']) - { - return $entries[0]['uidnumber'][0]; - } - - return -1; -} - -function deluser($username) -{ - # Not supported - return 0; -} - -function get_userlist() -{ - global $config, $ds; - $userlist = array(); - - $filter = '(' . $config['auth_ldap_prefix'] . '*)'; - - $search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter); - $entries = ldap_get_entries($ds, $search); - - if ($entries['count']) - { - foreach ($entries as $entry) - { - $username = $entry['uid'][0]; - $realname = $entry['cn'][0]; - $user_id = $entry['uidnumber'][0]; - $email = $entry[$config['auth_ldap_emailattr']][0]; - $ldap_groups = get_group_list(); - foreach($ldap_groups as $ldap_group) { - $ldap_comparison = ldap_compare($ds, - $ldap_group, - $config['auth_ldap_groupmemberattr'], - get_membername($username)); - if (!isset($config['auth_ldap_group']) || $ldap_comparison === true) { - $userlist[] = array('username' => $username, 'realname' => $realname, 'user_id' => $user_id, 'email' => $email); + if ($entries['count']) { + foreach ($entries as $entry) { + $username = $entry['uid'][0]; + $realname = $entry['cn'][0]; + $user_id = $entry['uidnumber'][0]; + $email = $entry[$config['auth_ldap_emailattr']][0]; + $ldap_groups = get_group_list(); + foreach ($ldap_groups as $ldap_group) { + $ldap_comparison = ldap_compare( + $ds, + $ldap_group, + $config['auth_ldap_groupmemberattr'], + get_membername($username) + ); + if (!isset($config['auth_ldap_group']) || $ldap_comparison === true) { + $userlist[] = array( + 'username' => $username, + 'realname' => $realname, + 'user_id' => $user_id, + 'email' => $email, + ); + } + } } - } } - } - - return $userlist; + return $userlist; } -function can_update_users() -{ - # not supported so return 0 - return 0; + +function can_update_users() { + // not supported so return 0 + return 0; + } -function get_user($user_id) -{ - # not supported - return 0; + +function get_user($user_id) { + // not supported + return 0; + } -function update_user($user_id,$realname,$level,$can_modify_passwd,$email) -{ - # not supported - return 0; + +function update_user($user_id, $realname, $level, $can_modify_passwd, $email) { + // not supported + return 0; + } -function get_membername ($username) -{ - global $config; - if ($config['auth_ldap_groupmembertype'] == "fulldn") - { - $membername = $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix']; - } - else - { - $membername = $username; - } - return $membername; + +function get_membername($username) { + global $config; + if ($config['auth_ldap_groupmembertype'] == 'fulldn') { + $membername = $config['auth_ldap_prefix'].$username.$config['auth_ldap_suffix']; + } + else { + $membername = $username; + } + + return $membername; + } + function get_group_list() { - global $config; + global $config; - $ldap_groups = array(); - $default_group = 'cn=groupname,ou=groups,dc=example,dc=com'; - if(isset($config['auth_ldap_group'])) { - if($config['auth_ldap_group'] !== $default_group) { - $ldap_groups[] = $config['auth_ldap_group']; + $ldap_groups = array(); + $default_group = 'cn=groupname,ou=groups,dc=example,dc=com'; + if (isset($config['auth_ldap_group'])) { + if ($config['auth_ldap_group'] !== $default_group) { + $ldap_groups[] = $config['auth_ldap_group']; + } } - } - foreach($config['auth_ldap_groups'] as $key => $value) { - $dn = "cn=$key," . $config['auth_ldap_groupbase']; - $ldap_groups[] = $dn; - } - return $ldap_groups; -} -?> + foreach ($config['auth_ldap_groups'] as $key => $value) { + $dn = "cn=$key,".$config['auth_ldap_groupbase']; + $ldap_groups[] = $dn; + } + + return $ldap_groups; + +} diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php index cf91f27c2d..84e119ceac 100644 --- a/html/includes/authentication/mysql.inc.php +++ b/html/includes/authentication/mysql.inc.php @@ -1,71 +1,69 @@ CheckPassword($password, $row['password'])) - { - return 1; - } - } - return 0; -} -function reauthenticate($sess_id,$token) -{ - list($uname,$hash) = explode("|",$token); - $session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'"); - $hasher = new PasswordHash(8, FALSE); - if($hasher->CheckPassword($uname.$session['session_token'],$hash)) - { - $_SESSION['username'] = $uname; - return 1; - } - else - { + $hasher = new PasswordHash(8, false); + if ($hasher->CheckPassword($password, $row['password'])) { + return 1; + } + }//end if + return 0; - } -} -function passwordscanchange($username = "") -{ - /* - * By default allow the password to be modified, unless the existing - * user is explicitly prohibited to do so. - */ +}//end authenticate() + + +function reauthenticate($sess_id, $token) { + list($uname,$hash) = explode('|', $token); + $session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'"); + $hasher = new PasswordHash(8, false); + if ($hasher->CheckPassword($uname.$session['session_token'], $hash)) { + $_SESSION['username'] = $uname; + return 1; + } + else { + return 0; + } + +}//end reauthenticate() + + +function passwordscanchange($username='') { + /* + * By default allow the password to be modified, unless the existing + * user is explicitly prohibited to do so. + */ + + if (empty($username) || !user_exists($username)) { + return 1; + } + else { + return dbFetchCell('SELECT can_modify_passwd FROM users WHERE username = ?', array($username)); + } + +}//end passwordscanchange() - if (empty($username) || !user_exists($username)) - { - return 1; - } else { - return dbFetchCell("SELECT can_modify_passwd FROM users WHERE username = ?", array($username)); - } -} /** * From: http://code.activestate.com/recipes/576894-generate-a-salt/ @@ -74,92 +72,98 @@ function passwordscanchange($username = "") * @param $max integer The number of characters in the string * @author AfroSoft */ -function generateSalt($max = 15) -{ - $characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - $i = 0; - $salt = ""; - do - { - $salt .= $characterList{mt_rand(0,strlen($characterList))}; - $i++; - } while ($i <= $max); +function generateSalt($max=15) { + $characterList = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + $i = 0; + $salt = ''; + do { + $salt .= $characterList{mt_rand(0, strlen($characterList))}; + $i++; + } while ($i <= $max); - return $salt; -} + return $salt; -function changepassword($username,$password) -{ - $hasher = new PasswordHash(8, FALSE); - $encrypted = $hasher->HashPassword($password); - return dbUpdate(array('password' => $encrypted), 'users', '`username` = ?', array($username)); -} +}//end generateSalt() -function auth_usermanagement() -{ - return 1; -} -function adduser($username, $password, $level, $email = "", $realname = "", $can_modify_passwd=1, $description ="", $twofactor=0) -{ - if (!user_exists($username)) - { - $hasher = new PasswordHash(8, FALSE); +function changepassword($username, $password) { + $hasher = new PasswordHash(8, false); $encrypted = $hasher->HashPassword($password); - return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); - } else { - return FALSE; - } -} + return dbUpdate(array('password' => $encrypted), 'users', '`username` = ?', array($username)); -function user_exists($username) -{ - $return = @dbFetchCell("SELECT COUNT(*) FROM users WHERE username = ?", array($username)); - return $return; -} +}//end changepassword() -function get_userlevel($username) -{ - return dbFetchCell("SELECT `level` FROM `users` WHERE `username` = ?", array($username)); -} -function get_userid($username) -{ - return dbFetchCell("SELECT `user_id` FROM `users` WHERE `username` = ?", array($username)); -} +function auth_usermanagement() { + return 1; -function deluser($username) -{ +}//end auth_usermanagement() - dbDelete('bill_perms', "`user_name` = ?", array($username)); - dbDelete('devices_perms', "`user_name` = ?", array($username)); - dbDelete('ports_perms', "`user_name` = ?", array($username)); - dbDelete('users_prefs', "`user_name` = ?", array($username)); - dbDelete('users', "`user_name` = ?", array($username)); - return dbDelete('users', "`username` = ?", array($username)); +function adduser($username, $password, $level, $email='', $realname='', $can_modify_passwd=1, $description='', $twofactor=0) { + if (!user_exists($username)) { + $hasher = new PasswordHash(8, false); + $encrypted = $hasher->HashPassword($password); + return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); + } + else { + return false; + } -} +}//end adduser() -function get_userlist() -{ - return dbFetchRows("SELECT * FROM `users`"); -} -function can_update_users() -{ - # supported so return 1 - return 1; -} +function user_exists($username) { + $return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username)); + return $return; -function get_user($user_id) -{ - return dbFetchRow("SELECT * FROM `users` WHERE `user_id` = ?", array($user_id)); -} +}//end user_exists() -function update_user($user_id,$realname,$level,$can_modify_passwd,$email) -{ - dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id)); -} -?> +function get_userlevel($username) { + return dbFetchCell('SELECT `level` FROM `users` WHERE `username` = ?', array($username)); + +}//end get_userlevel() + + +function get_userid($username) { + return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username` = ?', array($username)); + +}//end get_userid() + + +function deluser($username) { + dbDelete('bill_perms', '`user_name` = ?', array($username)); + dbDelete('devices_perms', '`user_name` = ?', array($username)); + dbDelete('ports_perms', '`user_name` = ?', array($username)); + dbDelete('users_prefs', '`user_name` = ?', array($username)); + dbDelete('users', '`user_name` = ?', array($username)); + + return dbDelete('users', '`username` = ?', array($username)); + +}//end deluser() + + +function get_userlist() { + return dbFetchRows('SELECT * FROM `users`'); + +}//end get_userlist() + + +function can_update_users() { + // supported so return 1 + return 1; + +}//end can_update_users() + + +function get_user($user_id) { + return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id)); + +}//end get_user() + + +function update_user($user_id, $realname, $level, $can_modify_passwd, $email) { + dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id)); + +}//end update_user() diff --git a/html/includes/authentication/twofactor.lib.php b/html/includes/authentication/twofactor.lib.php index 0d54628c9f..92f2aea2f8 100644 --- a/html/includes/authentication/twofactor.lib.php +++ b/html/includes/authentication/twofactor.lib.php @@ -4,14 +4,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ /** * Two-Factor Authentication Library @@ -44,14 +45,14 @@ const otpWindow = 4; * Base32 Decoding dictionary */ $base32 = array( - "A" => 0, "B" => 1, "C" => 2, "D" => 3, - "E" => 4, "F" => 5, "G" => 6, "H" => 7, - "I" => 8, "J" => 9, "K" => 10, "L" => 11, - "M" => 12, "N" => 13, "O" => 14, "P" => 15, - "Q" => 16, "R" => 17, "S" => 18, "T" => 19, - "U" => 20, "V" => 21, "W" => 22, "X" => 23, - "Y" => 24, "Z" => 25, "2" => 26, "3" => 27, - "4" => 28, "5" => 29, "6" => 30, "7" => 31 + "A" => 0, "B" => 1, "C" => 2, "D" => 3, + "E" => 4, "F" => 5, "G" => 6, "H" => 7, + "I" => 8, "J" => 9, "K" => 10, "L" => 11, + "M" => 12, "N" => 13, "O" => 14, "P" => 15, + "Q" => 16, "R" => 17, "S" => 18, "T" => 19, + "U" => 20, "V" => 21, "W" => 22, "X" => 23, + "Y" => 24, "Z" => 25, "2" => 26, "3" => 27, + "4" => 28, "5" => 29, "6" => 30, "7" => 31 ); /** @@ -128,14 +129,16 @@ function oath_hotp($key, $counter=false) { function verify_hotp($key,$otp,$counter=false) { if( oath_hotp($key,$counter) == $otp ) { return true; - } else { + } + else { if( $counter === false ) { //TimeBased HOTP requires lookbehind and lookahead. $counter = floor(microtime(true)/keyInterval); $initcount = $counter-((otpWindow+1)*keyInterval); $endcount = $counter+(otpWindow*keyInterval); $totp = true; - } else { + } + else { //Counter based HOTP only has lookahead, not lookbehind. $initcount = $counter-1; $endcount = $counter+otpWindow; @@ -145,7 +148,8 @@ function verify_hotp($key,$otp,$counter=false) { if( oath_hotp($key,$initcount) == $otp ) { if( !$totp ) { return $initcount; - } else { + } + else { return true; } } @@ -200,23 +204,28 @@ function twofactor_auth() { $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); if( empty($twofactor['twofactor']) ) { $_SESSION['twofactor'] = true; - } else { + } + else { $twofactor = json_decode($twofactor['twofactor'],true); if( $twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time()-$twofactor['last']) < $config['twofactor_lock']) ) { $auth_message = "Too many failures, please ".($config['twofactor_lock'] ? "wait ".$config['twofactor_lock']." seconds" : "contact administrator")."."; - } else { + } + else { if( !$_POST['twofactor'] ) { $twofactorform = true; - } else { + } + else { if( ($server_c = verify_hotp($twofactor['key'],$_POST['twofactor'],$twofactor['counter'])) === false ) { $twofactor['fails']++; $twofactor['last'] = time(); $auth_message = "Wrong Two-Factor Token."; - } else { + } + else { if( $twofactor['counter'] !== false ) { if( $server_c !== true && $server_c !== $twofactor['counter'] ) { $twofactor['counter'] = $server_c+1; - } else { + } + else { $twofactor['counter']++; } } diff --git a/html/includes/collectd/functions.php b/html/includes/collectd/functions.php index d7b44a969e..b004f832df 100644 --- a/html/includes/collectd/functions.php +++ b/html/includes/collectd/functions.php @@ -1,4 +1,5 @@ - * @@ -19,7 +20,7 @@ define('REGEXP_HOST', '/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/'); define('REGEXP_PLUGIN', '/^[a-zA-Z0-9_.-]+$/'); -/** +/* * Read input variable from GET, POST or COOKIE taking * care of magic quotes * @name Name of value to return @@ -28,84 +29,114 @@ define('REGEXP_PLUGIN', '/^[a-zA-Z0-9_.-]+$/'); * @return $default if name in unknown in $array, otherwise * input value with magic quotes stripped off */ -function read_var($name, &$array, $default = null) { - if (isset($array[$name])) { - if (is_array($array[$name])) { - if (get_magic_quotes_gpc()) { - $ret = array(); - while (list($k, $v) = each($array[$name])) - $ret[stripslashes($k)] = stripslashes($v); - return $ret; - } else - return $array[$name]; - } else if (is_string($array[$name]) && get_magic_quotes_gpc()) { - return stripslashes($array[$name]); - } else - return $array[$name]; - } else - return $default; -} +function read_var($name, &$array, $default=null) { + if (isset($array[$name])) { + if (is_array($array[$name])) { + if (get_magic_quotes_gpc()) { + $ret = array(); + while (list($k, $v) = each($array[$name])) { + $ret[stripslashes($k)] = stripslashes($v); + } -/** + return $ret; + } + else { + return $array[$name]; + } + } + else if (is_string($array[$name]) && get_magic_quotes_gpc()) { + return stripslashes($array[$name]); + } + else { + return $array[$name]; + } + } + else { + return $default; + } + +}//end read_var() + + +/* * Alphabetically compare host names, comparing label * from tld to node name */ function collectd_compare_host($a, $b) { - $ea = explode('.', $a); - $eb = explode('.', $b); - $i = count($ea) - 1; - $j = count($eb) - 1; - while ($i >= 0 && $j >= 0) - if (($r = strcmp($ea[$i--], $eb[$j--])) != 0) - return $r; - return 0; -} + $ea = explode('.', $a); + $eb = explode('.', $b); + $i = (count($ea) - 1); + $j = (count($eb) - 1); + while ($i >= 0 && $j >= 0) { + if (($r = strcmp($ea[$i--], $eb[$j--])) != 0) { + return $r; + } + } + + return 0; + +}//end collectd_compare_host() + /** * Fetch list of hosts found in collectd's datadirs. * @return Sorted list of hosts (sorted by label from rigth to left) */ function collectd_list_hosts() { - global $config; + global $config; - $hosts = array(); - foreach($config['datadirs'] as $datadir) - if ($d = @opendir($datadir)) { - while (($dent = readdir($d)) !== false) - if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$dent) && preg_match(REGEXP_HOST, $dent)) - $hosts[] = $dent; - closedir($d); - } else - error_log('Failed to open datadir: '.$datadir); - $hosts = array_unique($hosts); - usort($hosts, 'collectd_compare_host'); - return $hosts; + $hosts = array(); + foreach($config['datadirs'] as $datadir) { + if ($d = @opendir($datadir)) { + while (($dent = readdir($d)) !== false) { + if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$dent) && preg_match(REGEXP_HOST, $dent)) { + $hosts[] = $dent; + } + } + closedir($d); + } + else { + error_log('Failed to open datadir: '.$datadir); + } + } + $hosts = array_unique($hosts); + usort($hosts, 'collectd_compare_host'); + return $hosts; } + /** * Fetch list of plugins found in collectd's datadirs for given host. * @arg_host Name of host for which to return plugins * @return Sorted list of plugins (sorted alphabetically) */ function collectd_list_plugins($arg_host) { - global $config; + global $config; + + $plugins = array(); + foreach ($config['datadirs'] as $datadir) { + if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host))) { + while (($dent = readdir($d)) !== false) { + if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$arg_host.'/'.$dent)) { + if ($i = strpos($dent, '-')) { + $plugins[] = substr($dent, 0, $i); + } + else { + $plugins[] = $dent; + } + } + } + + closedir($d); + } + } + + $plugins = array_unique($plugins); + sort($plugins); + return $plugins; + +}//end collectd_list_plugins() - $plugins = array(); - foreach ($config['datadirs'] as $datadir) - if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host))) { - while (($dent = readdir($d)) !== false) - if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$arg_host.'/'.$dent)) { - if ($i = strpos($dent, '-')) - $plugins[] = substr($dent, 0, $i); - else - $plugins[] = $dent; - } - closedir($d); - } - $plugins = array_unique($plugins); - sort($plugins); - return $plugins; -} /** * Fetch list of plugin instances found in collectd's datadirs for given host+plugin @@ -114,29 +145,38 @@ function collectd_list_plugins($arg_host) { * @return Sorted list of plugin instances (sorted alphabetically) */ function collectd_list_pinsts($arg_host, $arg_plugin) { - global $config; + global $config; + + $pinsts = array(); + foreach ($config['datadirs'] as $datadir) { + if (preg_match(REGEXP_HOST, $arg_host) && ($d = opendir($datadir.'/'.$arg_host))) { + while (($dent = readdir($d)) !== false) { + if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$arg_host.'/'.$dent)) { + if ($i = strpos($dent, '-')) { + $plugin = substr($dent, 0, $i); + $pinst = substr($dent, ($i + 1)); + } + else { + $plugin = $dent; + $pinst = ''; + } + + if ($plugin == $arg_plugin) { + $pinsts[] = $pinst; + } + } + } + + closedir($d); + } + }//end foreach + + $pinsts = array_unique($pinsts); + sort($pinsts); + return $pinsts; + +}//end collectd_list_pinsts() - $pinsts = array(); - foreach ($config['datadirs'] as $datadir) - if (preg_match(REGEXP_HOST, $arg_host) && ($d = opendir($datadir.'/'.$arg_host))) { - while (($dent = readdir($d)) !== false) - if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$arg_host.'/'.$dent)) { - if ($i = strpos($dent, '-')) { - $plugin = substr($dent, 0, $i); - $pinst = substr($dent, $i+1); - } else { - $plugin = $dent; - $pinst = ''; - } - if ($plugin == $arg_plugin) - $pinsts[] = $pinst; - } - closedir($d); - } - $pinsts = array_unique($pinsts); - sort($pinsts); - return $pinsts; -} /** * Fetch list of types found in collectd's datadirs for given host+plugin+instance @@ -146,28 +186,38 @@ function collectd_list_pinsts($arg_host, $arg_plugin) { * @return Sorted list of types (sorted alphabetically) */ function collectd_list_types($arg_host, $arg_plugin, $arg_pinst) { - global $config; + global $config; + + $types = array(); + $my_plugin = $arg_plugin.(strlen($arg_pinst) ? '-'.$arg_pinst : ''); + if (!preg_match(REGEXP_PLUGIN, $my_plugin)) { + return $types; + } + + foreach ($config['datadirs'] as $datadir) { + if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host.'/'.$my_plugin))) { + while (($dent = readdir($d)) !== false) { + if ($dent != '.' && $dent != '..' && is_file($datadir.'/'.$arg_host.'/'.$my_plugin.'/'.$dent) && substr($dent, (strlen($dent) - 4)) == '.rrd') { + $dent = substr($dent, 0, (strlen($dent) - 4)); + if ($i = strpos($dent, '-')) { + $types[] = substr($dent, 0, $i); + } + else { + $types[] = $dent; + } + } + } + + closedir($d); + } + } + + $types = array_unique($types); + sort($types); + return $types; + +}//end collectd_list_types() - $types = array(); - $my_plugin = $arg_plugin . (strlen($arg_pinst) ? '-'.$arg_pinst : ''); - if (!preg_match(REGEXP_PLUGIN, $my_plugin)) - return $types; - foreach ($config['datadirs'] as $datadir) - if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host.'/'.$my_plugin))) { - while (($dent = readdir($d)) !== false) - if ($dent != '.' && $dent != '..' && is_file($datadir.'/'.$arg_host.'/'.$my_plugin.'/'.$dent) && substr($dent, strlen($dent)-4) == '.rrd') { - $dent = substr($dent, 0, strlen($dent)-4); - if ($i = strpos($dent, '-')) - $types[] = substr($dent, 0, $i); - else - $types[] = $dent; - } - closedir($d); - } - $types = array_unique($types); - sort($types); - return $types; -} /** * Fetch list of type instances found in collectd's datadirs for given host+plugin+instance+type @@ -178,33 +228,44 @@ function collectd_list_types($arg_host, $arg_plugin, $arg_pinst) { * @return Sorted list of type instances (sorted alphabetically) */ function collectd_list_tinsts($arg_host, $arg_plugin, $arg_pinst, $arg_type) { - global $config; + global $config; + + $tinsts = array(); + $my_plugin = $arg_plugin.(strlen($arg_pinst) ? '-'.$arg_pinst : ''); + if (!preg_match(REGEXP_PLUGIN, $my_plugin)) { + return $types; + } + + foreach ($config['datadirs'] as $datadir) { + if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host.'/'.$my_plugin))) { + while (($dent = readdir($d)) !== false) { + if ($dent != '.' && $dent != '..' && is_file($datadir.'/'.$arg_host.'/'.$my_plugin.'/'.$dent) && substr($dent, (strlen($dent) - 4)) == '.rrd') { + $dent = substr($dent, 0, (strlen($dent) - 4)); + if ($i = strpos($dent, '-')) { + $type = substr($dent, 0, $i); + $tinst = substr($dent, ($i + 1)); + } + else { + $type = $dent; + $tinst = ''; + } + + if ($type == $arg_type) { + $tinsts[] = $tinst; + } + } + } + + closedir($d); + } + }//end foreach + + $tinsts = array_unique($tinsts); + sort($tinsts); + return $tinsts; + +}//end collectd_list_tinsts() - $tinsts = array(); - $my_plugin = $arg_plugin . (strlen($arg_pinst) ? '-'.$arg_pinst : ''); - if (!preg_match(REGEXP_PLUGIN, $my_plugin)) - return $types; - foreach ($config['datadirs'] as $datadir) - if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host.'/'.$my_plugin))) { - while (($dent = readdir($d)) !== false) - if ($dent != '.' && $dent != '..' && is_file($datadir.'/'.$arg_host.'/'.$my_plugin.'/'.$dent) && substr($dent, strlen($dent)-4) == '.rrd') { - $dent = substr($dent, 0, strlen($dent)-4); - if ($i = strpos($dent, '-')) { - $type = substr($dent, 0, $i); - $tinst = substr($dent, $i+1); - } else { - $type = $dent; - $tinst = ''; - } - if ($type == $arg_type) - $tinsts[] = $tinst; - } - closedir($d); - } - $tinsts = array_unique($tinsts); - sort($tinsts); - return $tinsts; -} /** * Parse symlinks in order to get an identifier that collectd understands @@ -219,29 +280,35 @@ function collectd_list_tinsts($arg_host, $arg_plugin, $arg_pinst, $arg_type) { * @return Identifier that collectd's FLUSH command understands */ function collectd_identifier($host, $plugin, $pinst, $type, $tinst) { - global $config; - $rrd_realpath = null; - $orig_identifier = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, strlen($pinst) ? '-' : '', $pinst, $type, strlen($tinst) ? '-' : '', $tinst); - $identifier = null; - foreach ($config['datadirs'] as $datadir) - if (is_file($datadir.'/'.$orig_identifier.'.rrd')) { - $rrd_realpath = realpath($datadir.'/'.$orig_identifier.'.rrd'); - break; - } - if ($rrd_realpath) { - $identifier = basename($rrd_realpath); - $identifier = substr($identifier, 0, strlen($identifier)-4); - $rrd_realpath = dirname($rrd_realpath); - $identifier = basename($rrd_realpath).'/'.$identifier; - $rrd_realpath = dirname($rrd_realpath); - $identifier = basename($rrd_realpath).'/'.$identifier; - } + global $config; + $rrd_realpath = null; + $orig_identifier = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, strlen($pinst) ? '-' : '', $pinst, $type, strlen($tinst) ? '-' : '', $tinst); + $identifier = null; + foreach ($config['datadirs'] as $datadir) { + if (is_file($datadir.'/'.$orig_identifier.'.rrd')) { + $rrd_realpath = realpath($datadir.'/'.$orig_identifier.'.rrd'); + break; + } + } + + if ($rrd_realpath) { + $identifier = basename($rrd_realpath); + $identifier = substr($identifier, 0, (strlen($identifier) - 4)); + $rrd_realpath = dirname($rrd_realpath); + $identifier = basename($rrd_realpath).'/'.$identifier; + $rrd_realpath = dirname($rrd_realpath); + $identifier = basename($rrd_realpath).'/'.$identifier; + } + + if (is_null($identifier)) { + return $orig_identifier; + } + else { + return $identifier; + } + +}//end collectd_identifier() - if (is_null($identifier)) - return $orig_identifier; - else - return $identifier; -} /** * Tell collectd that it should FLUSH all data it has regarding the @@ -253,124 +320,178 @@ function collectd_identifier($host, $plugin, $pinst, $type, $tinst) { * @tinst Type instance */ function collectd_flush($identifier) { - global $config; + global $config; - if (!$config['collectd_sock']) - return false; - if (is_null($identifier) || (is_array($identifier) && count($identifier) == 0) || !(is_string($identifier) || is_array($identifier))) - return false; + if (!$config['collectd_sock']) { + return false; + } - if (is_null($host) || !is_string($host) || strlen($host) == 0) - return false; - if (is_null($plugin) || !is_string($plugin) || strlen($plugin) == 0) - return false; - if (is_null($pinst) || !is_string($pinst)) - return false; - if (is_null($type) || !is_string($type) || strlen($type) == 0) - return false; - if (is_null($tinst) || (is_array($tinst) && count($tinst) == 0) || !(is_string($tinst) || is_array($tinst))) - return false; + if (is_null($identifier) || (is_array($identifier) && count($identifier) == 0) || !(is_string($identifier) || is_array($identifier))) { + return false; + } - $u_errno = 0; - $u_errmsg = ''; - if ($socket = @fsockopen($config['collectd_sock'], 0, $u_errno, $u_errmsg)) { - $cmd = 'FLUSH plugin=rrdtool'; - if (is_array($identifier)) { - foreach ($identifier as $val) - $cmd .= sprintf(' identifier="%s"', $val); - } else - $cmd .= sprintf(' identifier="%s"', $identifier); - $cmd .= "\n"; + if (is_null($host) || !is_string($host) || strlen($host) == 0) { + return false; + } - $r = fwrite($socket, $cmd, strlen($cmd)); - if ($r === false || $r != strlen($cmd)) - error_log(sprintf("graph.php: Failed to write whole command to unix-socket: %d out of %d written", $r === false ? -1 : $r, strlen($cmd))); + if (is_null($plugin) || !is_string($plugin) || strlen($plugin) == 0) { + return false; + } - $resp = fgets($socket); - if ($resp === false) - error_log(sprintf("graph.php: Failed to read response from collectd for command: %s", trim($cmd))); + if (is_null($pinst) || !is_string($pinst)) { + return false; + } - $n = (int)$resp; - while ($n-- > 0) - fgets($socket); + if (is_null($type) || !is_string($type) || strlen($type) == 0) { + return false; + } + + if (is_null($tinst) || (is_array($tinst) && count($tinst) == 0) || !(is_string($tinst) || is_array($tinst))) { + return false; + } + + $u_errno = 0; + $u_errmsg = ''; + if ($socket = @fsockopen($config['collectd_sock'], 0, $u_errno, $u_errmsg)) { + $cmd = 'FLUSH plugin=rrdtool'; + if (is_array($identifier)) { + foreach ($identifier as $val) { + $cmd .= sprintf(' identifier="%s"', $val); + } + } + else { + $cmd .= sprintf(' identifier="%s"', $identifier); + } + + $cmd .= "\n"; + + $r = fwrite($socket, $cmd, strlen($cmd)); + if ($r === false || $r != strlen($cmd)) { + error_log(sprintf('graph.php: Failed to write whole command to unix-socket: %d out of %d written', $r === false ? (-1) : $r, strlen($cmd))); + } + + $resp = fgets($socket); + if ($resp === false) { + error_log(sprintf('graph.php: Failed to read response from collectd for command: %s', trim($cmd))); + } + + $n = (int) $resp; + while ($n-- > 0) { + fgets($socket); + } + + fclose($socket); + } //end if + else { + error_log(sprintf('graph.php: Failed to open unix-socket to collectd: %d: %s', $u_errno, $u_errmsg)); + } + +}//end collectd_flush() - fclose($socket); - } else - error_log(sprintf("graph.php: Failed to open unix-socket to collectd: %d: %s", $u_errno, $u_errmsg)); -} class CollectdColor { - private $r = 0; - private $g = 0; - private $b = 0; - function __construct($value = null) { - if (is_null($value)) { - } else if (is_array($value)) { - if (isset($value['r'])) - $this->r = $value['r'] > 0 ? ($value['r'] > 1 ? 1 : $value['r']) : 0; - if (isset($value['g'])) - $this->g = $value['g'] > 0 ? ($value['g'] > 1 ? 1 : $value['g']) : 0; - if (isset($value['b'])) - $this->b = $value['b'] > 0 ? ($value['b'] > 1 ? 1 : $value['b']) : 0; - } else if (is_string($value)) { - $matches = array(); - if ($value == 'random') { - $this->randomize(); - } else if (preg_match('/([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/', $value, $matches)) { - $this->r = ('0x'.$matches[1]) / 255.0; - $this->g = ('0x'.$matches[2]) / 255.0; - $this->b = ('0x'.$matches[3]) / 255.0; - } - } else if (is_a($value, 'CollectdColor')) { - $this->r = $value->r; - $this->g = $value->g; - $this->b = $value->b; - } - } + private $r = 0; - function randomize() { - $this->r = rand(0, 255) / 255.0; - $this->g = rand(0, 255) / 255.0; - $this->b = 0.0; - $min = 0.0; - $max = 1.0; + private $g = 0; - if (($this->r + $this->g) < 1.0) { - $min = 1.0 - ($this->r + $this->g); - } else { - $max = 2.0 - ($this->r + $this->g); - } - $this->b = $min + ((rand(0, 255)/255.0) * ($max - $min)); - } + private $b = 0; - function fade($bkgnd = null, $alpha = 0.25) { - if (is_null($bkgnd) || !is_a($bkgnd, 'CollectdColor')) { - $bg_r = 1.0; - $bg_g = 1.0; - $bg_b = 1.0; - } else { - $bg_r = $bkgnd->r; - $bg_g = $bkgnd->g; - $bg_b = $bkgnd->b; - } - $this->r = $alpha * $this->r + ((1.0 - $alpha) * $bg_r); - $this->g = $alpha * $this->g + ((1.0 - $alpha) * $bg_g); - $this->b = $alpha * $this->b + ((1.0 - $alpha) * $bg_b); - } + function __construct($value=null) { + if (is_null($value)) { + } + else if (is_array($value)) { + if (isset($value['r'])) { + $this->r = $value['r'] > 0 ? ($value['r'] > 1 ? 1 : $value['r']) : 0; + } - function as_array() { - return array('r'=>$this->r, 'g'=>$this->g, 'b'=>$this->b); - } + if (isset($value['g'])) { + $this->g = $value['g'] > 0 ? ($value['g'] > 1 ? 1 : $value['g']) : 0; + } - function as_string() { - $r = (int)($this->r*255); - $g = (int)($this->g*255); - $b = (int)($this->b*255); - return sprintf('%02x%02x%02x', $r > 255 ? 255 : $r, $g > 255 ? 255 : $g, $b > 255 ? 255 : $b); - } -} + if (isset($value['b'])) { + $this->b = $value['b'] > 0 ? ($value['b'] > 1 ? 1 : $value['b']) : 0; + } + } + else if (is_string($value)) { + $matches = array(); + if ($value == 'random') { + $this->randomize(); + } + else if (preg_match('/([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/', $value, $matches)) { + $this->r = (('0x'.$matches[1]) / 255.0); + $this->g = (('0x'.$matches[2]) / 255.0); + $this->b = (('0x'.$matches[3]) / 255.0); + } + } + else if (is_a($value, 'CollectdColor')) { + $this->r = $value->r; + $this->g = $value->g; + $this->b = $value->b; + }//end if + + }//end __construct() + + + function randomize() { + $this->r = (rand(0, 255) / 255.0); + $this->g = (rand(0, 255) / 255.0); + $this->b = 0.0; + $min = 0.0; + $max = 1.0; + + if (($this->r + $this->g) < 1.0) { + $min = (1.0 - ($this->r + $this->g)); + } + else { + $max = (2.0 - ($this->r + $this->g)); + } + + $this->b = ($min + ((rand(0, 255) / 255.0) * ($max - $min))); + + }//end randomize() + + + function fade($bkgnd=null, $alpha=0.25) { + if (is_null($bkgnd) || !is_a($bkgnd, 'CollectdColor')) { + $bg_r = 1.0; + $bg_g = 1.0; + $bg_b = 1.0; + } + else { + $bg_r = $bkgnd->r; + $bg_g = $bkgnd->g; + $bg_b = $bkgnd->b; + } + + $this->r = ($alpha * $this->r + ((1.0 - $alpha) * $bg_r)); + $this->g = ($alpha * $this->g + ((1.0 - $alpha) * $bg_g)); + $this->b = ($alpha * $this->b + ((1.0 - $alpha) * $bg_b)); + + }//end fade() + + + function as_array() { + return array( + 'r' => $this->r, + 'g' => $this->g, + 'b' => $this->b, + ); + + }//end as_array() + + + function as_string() { + $r = (int) ($this->r * 255); + $g = (int) ($this->g * 255); + $b = (int) ($this->b * 255); + return sprintf('%02x%02x%02x', $r > 255 ? 255 : $r, $g > 255 ? 255 : $g, $b > 255 ? 255 : $b); + + }//end as_string() + + +}//end class /** @@ -379,11 +500,15 @@ class CollectdColor { * @return String with one surrounding pair of quotes stripped */ function rrd_strip_quotes($str) { - if ($str[0] == '"' && $str[strlen($str)-1] == '"') - return substr($str, 1, strlen($str)-2); - else - return $str; -} + if ($str[0] == '"' && $str[(strlen($str) - 1)] == '"') { + return substr($str, 1, (strlen($str) - 2)); + } + else { + return $str; + } + +}//end rrd_strip_quotes() + /** * Determine useful information about RRD file @@ -391,66 +516,86 @@ function rrd_strip_quotes($str) { * @return Array describing the RRD file */ function rrd_info($file) { - $info = array('filename'=>$file); + $info = array('filename' => $file); - $rrd = popen(RRDTOOL.' info '.escapeshellarg($file), 'r'); - if ($rrd) { - while (($s = fgets($rrd)) !== false) { - $p = strpos($s, '='); - if ($p === false) - continue; - $key = trim(substr($s, 0, $p)); - $value = trim(substr($s, $p+1)); - if (strncmp($key,'ds[', 3) == 0) { - /* DS definition */ - $p = strpos($key, ']'); - $ds = substr($key, 3, $p-3); - if (!isset($info['DS'])) - $info['DS'] = array(); - $ds_key = substr($key, $p+2); + $rrd = popen(RRDTOOL.' info '.escapeshellarg($file), 'r'); + if ($rrd) { + while (($s = fgets($rrd)) !== false) { + $p = strpos($s, '='); + if ($p === false) { + continue; + } - if (strpos($ds_key, '[') === false) { - if (!isset($info['DS']["$ds"])) - $info['DS']["$ds"] = array(); - $info['DS']["$ds"]["$ds_key"] = rrd_strip_quotes($value); - } - } else if (strncmp($key, 'rra[', 4) == 0) { - /* RRD definition */ - $p = strpos($key, ']'); - $rra = substr($key, 4, $p-4); - if (!isset($info['RRA'])) - $info['RRA'] = array(); - $rra_key = substr($key, $p+2); + $key = trim(substr($s, 0, $p)); + $value = trim(substr($s, ($p + 1))); + if (strncmp($key, 'ds[', 3) == 0) { + // DS definition + $p = strpos($key, ']'); + $ds = substr($key, 3, ($p - 3)); + if (!isset($info['DS'])) { + $info['DS'] = array(); + } - if (strpos($rra_key, '[') === false) { - if (!isset($info['RRA']["$rra"])) - $info['RRA']["$rra"] = array(); - $info['RRA']["$rra"]["$rra_key"] = rrd_strip_quotes($value); - } - } else if (strpos($key, '[') === false) { - $info[$key] = rrd_strip_quotes($value); - } - } - pclose($rrd); - } - return $info; -} + $ds_key = substr($key, ($p + 2)); + + if (strpos($ds_key, '[') === false) { + if (!isset($info['DS']["$ds"])) { + $info['DS']["$ds"] = array(); + } + + $info['DS']["$ds"]["$ds_key"] = rrd_strip_quotes($value); + } + } + else if (strncmp($key, 'rra[', 4) == 0) { + // RRD definition + $p = strpos($key, ']'); + $rra = substr($key, 4, ($p - 4)); + if (!isset($info['RRA'])) { + $info['RRA'] = array(); + } + + $rra_key = substr($key, ($p + 2)); + + if (strpos($rra_key, '[') === false) { + if (!isset($info['RRA']["$rra"])) { + $info['RRA']["$rra"] = array(); + } + + $info['RRA']["$rra"]["$rra_key"] = rrd_strip_quotes($value); + } + } + else if (strpos($key, '[') === false) { + $info[$key] = rrd_strip_quotes($value); + }//end if + }//end while + + pclose($rrd); + }//end if + + return $info; + +}//end rrd_info() + + +function rrd_get_color($code, $line=true) { + global $config; + $name = ($line ? 'f_' : 'h_').$code; + if (!isset($config['rrd_colors'][$name])) { + $c_f = new CollectdColor('random'); + $c_h = new CollectdColor($c_f); + $c_h->fade(); + $config['rrd_colors']['f_'.$code] = $c_f->as_string(); + $config['rrd_colors']['h_'.$code] = $c_h->as_string(); + } + + return $config['rrd_colors'][$name]; + +}//end rrd_get_color() -function rrd_get_color($code, $line = true) { - global $config; - $name = ($line ? 'f_' : 'h_').$code; - if (!isset($config['rrd_colors'][$name])) { - $c_f = new CollectdColor('random'); - $c_h = new CollectdColor($c_f); - $c_h->fade(); - $config['rrd_colors']['f_'.$code] = $c_f->as_string(); - $config['rrd_colors']['h_'.$code] = $c_h->as_string(); - } - return $config['rrd_colors'][$name]; -} /** * Draw RRD file based on it's structure + * * @host * @plugin * @pinst @@ -459,116 +604,176 @@ function rrd_get_color($code, $line = true) { * @opts * @return Commandline to call RRDGraph in order to generate the final graph */ -function collectd_draw_rrd($host, $plugin, $pinst = null, $type, $tinst = null, $opts = array()) { - global $config; - $timespan_def = null; - if (!isset($opts['timespan'])) - $timespan_def = reset($config['timespan']); - else foreach ($config['timespan'] as &$ts) - if ($ts['name'] == $opts['timespan']) - $timespan_def = $ts; +function collectd_draw_rrd($host, $plugin, $pinst=null, $type, $tinst=null, $opts=array()) { + global $config; + $timespan_def = null; + if (!isset($opts['timespan'])) { + $timespan_def = reset($config['timespan']); + } + else { + foreach ($config['timespan'] as &$ts) { + if ($ts['name'] == $opts['timespan']) { + $timespan_def = $ts; + } + } + } - if (!isset($opts['rrd_opts'])) - $opts['rrd_opts'] = array(); - if (isset($opts['logarithmic']) && $opts['logarithmic']) - array_unshift($opts['rrd_opts'], '-o'); + if (!isset($opts['rrd_opts'])) { + $opts['rrd_opts'] = array(); + } - $rrdinfo = null; - $rrdfile = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, is_null($pinst) ? '' : '-', $pinst, $type, is_null($tinst) ? '' : '-', $tinst); - foreach ($config['datadirs'] as $datadir) - if (is_file($datadir.'/'.$rrdfile.'.rrd')) { - $rrdinfo = rrd_info($datadir.'/'.$rrdfile.'.rrd'); - if (isset($rrdinfo['RRA']) && is_array($rrdinfo['RRA'])) - break; - else - $rrdinfo = null; - } + if (isset($opts['logarithmic']) && $opts['logarithmic']) { + array_unshift($opts['rrd_opts'], '-o'); + } - if (is_null($rrdinfo)) - return false; + $rrdinfo = null; + $rrdfile = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, is_null($pinst) ? '' : '-', $pinst, $type, is_null($tinst) ? '' : '-', $tinst); + foreach ($config['datadirs'] as $datadir) { + if (is_file($datadir.'/'.$rrdfile.'.rrd')) { + $rrdinfo = rrd_info($datadir.'/'.$rrdfile.'.rrd'); + if (isset($rrdinfo['RRA']) && is_array($rrdinfo['RRA'])) { + break; + } + else { + $rrdinfo = null; + } + } + } - $graph = array(); - $has_avg = false; - $has_max = false; - $has_min = false; - reset($rrdinfo['RRA']); - $l_max = 0; - while (list($k, $v) = each($rrdinfo['RRA'])) { - if ($v['cf'] == 'MAX') - $has_max = true; - else if ($v['cf'] == 'AVERAGE') - $has_avg = true; - else if ($v['cf'] == 'MIN') - $has_min = true; - } + if (is_null($rrdinfo)) { + return false; + } - // Build legend. This may not work for all RRDs, i don't know :) - if ($has_avg) - $graph[] = "COMMENT: Last"; - if ($has_min) - $graph[] = "COMMENT: Min"; - if ($has_max) - $graph[] = "COMMENT: Max"; - if ($has_avg) - $graph[] = "COMMENT: Avg\\n"; + $graph = array(); + $has_avg = false; + $has_max = false; + $has_min = false; + reset($rrdinfo['RRA']); + $l_max = 0; + while (list($k, $v) = each($rrdinfo['RRA'])) { + if ($v['cf'] == 'MAX') { + $has_max = true; + } + else if ($v['cf'] == 'AVERAGE') { + $has_avg = true; + } + else if ($v['cf'] == 'MIN') { + $has_min = true; + } + } + // Build legend. This may not work for all RRDs, i don't know :) + if ($has_avg) { + $graph[] = 'COMMENT: Last'; + } - reset($rrdinfo['DS']); - while (list($k, $v) = each($rrdinfo['DS'])) { - if (strlen($k) > $l_max) - $l_max = strlen($k); - if ($has_min) - $graph[] = sprintf('DEF:%s_min=%s:%s:MIN', $k, $rrdinfo['filename'], $k); - if ($has_avg) - $graph[] = sprintf('DEF:%s_avg=%s:%s:AVERAGE', $k, $rrdinfo['filename'], $k); - if ($has_max) - $graph[] = sprintf('DEF:%s_max=%s:%s:MAX', $k, $rrdinfo['filename'], $k); - } - if ($has_min && $has_max || $has_min && $has_avg || $has_avg && $has_max) { - $n = 1; - reset($rrdinfo['DS']); - while (list($k, $v) = each($rrdinfo['DS'])) { - $graph[] = sprintf('LINE:%s_%s', $k, $has_min ? 'min' : 'avg'); - $graph[] = sprintf('CDEF:%s_var=%s_%s,%s_%s,-', $k, $k, $has_max ? 'max' : 'avg', $k, $has_min ? 'min' : 'avg'); - $graph[] = sprintf('AREA:%s_var#%s::STACK', $k, rrd_get_color($n++, false)); - } - } + if ($has_min) { + $graph[] = 'COMMENT: Min'; + } - reset($rrdinfo['DS']); - $n = 1; - while (list($k, $v) = each($rrdinfo['DS'])) { - $graph[] = sprintf('LINE1:%s_avg#%s:%s ', $k, rrd_get_color($n++, true), $k.substr(' ', 0, $l_max-strlen($k))); - if (isset($opts['tinylegend']) && $opts['tinylegend']) - continue; - if ($has_avg) - $graph[] = sprintf('GPRINT:%s_avg:AVERAGE:%%5.1lf%%s', $k, $has_max || $has_min || $has_avg ? ',' : "\\l"); - if ($has_min) - $graph[] = sprintf('GPRINT:%s_min:MIN:%%5.1lf%%s', $k, $has_max || $has_avg ? ',' : "\\l"); - if ($has_max) - $graph[] = sprintf('GPRINT:%s_max:MAX:%%5.1lf%%s', $k, $has_avg ? ',' : "\\l"); - if ($has_avg) - $graph[] = sprintf('GPRINT:%s_avg:LAST:%%5.1lf%%s\\l', $k); - } + if ($has_max) { + $graph[] = 'COMMENT: Max'; + } - #$rrd_cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-t', $rrdfile); - $rrd_cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height']); - if($config['rrd_width'] <= "300") { - $small_opts = array ('--font', "LEGEND:7:mono", '--font', "AXIS:6:mono", "--font-render-mode", "normal"); - $rrd_cmd = array_merge($rrd_cmd, $small_opts); + if ($has_avg) { + $graph[] = "COMMENT: Avg\\n"; + } + + reset($rrdinfo['DS']); + while (list($k, $v) = each($rrdinfo['DS'])) { + if (strlen($k) > $l_max) { + $l_max = strlen($k); } - $rrd_cmd = array_merge($rrd_cmd, $config['rrd_opts_array'], $opts['rrd_opts'], $graph); + if ($has_min) { + $graph[] = sprintf('DEF:%s_min=%s:%s:MIN', $k, $rrdinfo['filename'], $k); + } - $cmd = RRDTOOL; - $count_rrd_cmd = count($rrd_cmd); - for ($i = 1; $i < $count_rrd_cmd; $i++) - $cmd .= ' '.escapeshellarg($rrd_cmd[$i]); + if ($has_avg) { + $graph[] = sprintf('DEF:%s_avg=%s:%s:AVERAGE', $k, $rrdinfo['filename'], $k); + } + + if ($has_max) { + $graph[] = sprintf('DEF:%s_max=%s:%s:MAX', $k, $rrdinfo['filename'], $k); + } + } + + if ($has_min && $has_max || $has_min && $has_avg || $has_avg && $has_max) { + $n = 1; + reset($rrdinfo['DS']); + while (list($k, $v) = each($rrdinfo['DS'])) { + $graph[] = sprintf('LINE:%s_%s', $k, $has_min ? 'min' : 'avg'); + $graph[] = sprintf('CDEF:%s_var=%s_%s,%s_%s,-', $k, $k, $has_max ? 'max' : 'avg', $k, $has_min ? 'min' : 'avg'); + $graph[] = sprintf('AREA:%s_var#%s::STACK', $k, rrd_get_color($n++, false)); + } + } + + reset($rrdinfo['DS']); + $n = 1; + while (list($k, $v) = each($rrdinfo['DS'])) { + $graph[] = sprintf('LINE1:%s_avg#%s:%s ', $k, rrd_get_color($n++, true), $k.substr(' ', 0, ($l_max - strlen($k)))); + if (isset($opts['tinylegend']) && $opts['tinylegend']) { + continue; + } + + if ($has_avg) { + $graph[] = sprintf('GPRINT:%s_avg:AVERAGE:%%5.1lf%%s', $k, $has_max || $has_min || $has_avg ? ',' : '\\l'); + } + + if ($has_min) { + $graph[] = sprintf('GPRINT:%s_min:MIN:%%5.1lf%%s', $k, $has_max || $has_avg ? ',' : '\\l'); + } + + if ($has_max) { + $graph[] = sprintf('GPRINT:%s_max:MAX:%%5.1lf%%s', $k, $has_avg ? ',' : '\\l'); + } + + if ($has_avg) { + $graph[] = sprintf('GPRINT:%s_avg:LAST:%%5.1lf%%s\\l', $k); + } + }//end while + + // $rrd_cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-t', $rrdfile); + $rrd_cmd = array( + RRDTOOL, + 'graph', + '-', + '-E', + '-a', + 'PNG', + '-w', + $config['rrd_width'], + '-h', + $config['rrd_height'], + ); + if ($config['rrd_width'] <= '300') { + $small_opts = array( + '--font', + 'LEGEND:7:mono', + '--font', + 'AXIS:6:mono', + '--font-render-mode', + 'normal', + ); + $rrd_cmd = array_merge($rrd_cmd, $small_opts); + } + + $rrd_cmd = array_merge($rrd_cmd, $config['rrd_opts_array'], $opts['rrd_opts'], $graph); + + $cmd = RRDTOOL; + $count_rrd_cmd = count($rrd_cmd); + for ($i = 1; $i < $count_rrd_cmd; $i++) { + $cmd .= ' '.escapeshellarg($rrd_cmd[$i]); + } + + return $cmd; + +}//end collectd_draw_rrd() - return $cmd; -} /** * Draw RRD file based on it's structure + * * @timespan * @host * @plugin @@ -576,50 +781,78 @@ function collectd_draw_rrd($host, $plugin, $pinst = null, $type, $tinst = null, * @type * @tinst * @opts - * @return Commandline to call RRDGraph in order to generate the final graph + * @return Commandline to call RRDGraph in order to generate the final graph */ -function collectd_draw_generic($timespan, $host, $plugin, $pinst = null, $type, $tinst = null) { - global $config, $GraphDefs; - $timespan_def = NULL; - foreach ($config['timespan'] as &$ts) - if ($ts['name'] == $timespan) - $timespan_def = $ts; - if (is_null($timespan_def)) - $timespan_def = reset($config['timespan']); +function collectd_draw_generic($timespan, $host, $plugin, $pinst=null, $type, $tinst=null) { + global $config, $GraphDefs; + $timespan_def = null; + foreach ($config['timespan'] as &$ts) { + if ($ts['name'] == $timespan) { + $timespan_def = $ts; + } + } - if (!isset($GraphDefs[$type])) - return false; + if (is_null($timespan_def)) { + $timespan_def = reset($config['timespan']); + } - $rrd_file = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, is_null($pinst) ? '' : '-', $pinst, $type, is_null($tinst) ? '' : '-', $tinst); - #$rrd_cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-t', $rrd_file); - $rrd_cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height']); + if (!isset($GraphDefs[$type])) { + return false; + } - if($config['rrd_width'] <= "300") { - $small_opts = array ('--font', 'LEGEND:7:mono', '--font', 'AXIS:6:mono', '--font-render-mode', 'normal'); - $rrd_cmd = array_merge($rrd_cmd, $small_opts); + $rrd_file = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, is_null($pinst) ? '' : '-', $pinst, $type, is_null($tinst) ? '' : '-', $tinst); + // $rrd_cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-t', $rrd_file); + $rrd_cmd = array( + RRDTOOL, + 'graph', + '-', + '-E', + '-a', + 'PNG', + '-w', + $config['rrd_width'], + '-h', + $config['rrd_height'], + ); + + if ($config['rrd_width'] <= '300') { + $small_opts = array( + '--font', + 'LEGEND:7:mono', + '--font', + 'AXIS:6:mono', + '--font-render-mode', + 'normal', + ); + $rrd_cmd = array_merge($rrd_cmd, $small_opts); + } + + $rrd_cmd = array_merge($rrd_cmd, $config['rrd_opts_array']); + $rrd_args = $GraphDefs[$type]; + + foreach ($config['datadirs'] as $datadir) { + $file = $datadir.'/'.$rrd_file.'.rrd'; + if (!is_file($file)) { + continue; } - $rrd_cmd = array_merge($rrd_cmd, $config['rrd_opts_array']); - $rrd_args = $GraphDefs[$type]; + $file = str_replace(':', '\\:', $file); + $rrd_args = str_replace('{file}', $file, $rrd_args); - foreach ($config['datadirs'] as $datadir) { - $file = $datadir.'/'.$rrd_file.'.rrd'; - if (!is_file($file)) - continue; + $rrdgraph = array_merge($rrd_cmd, $rrd_args); + $cmd = RRDTOOL; + $count_rrdgraph = count($rrdgraph); + for ($i = 1; $i < $count_rrdgraph; $i++) { + $cmd .= ' '.escapeshellarg($rrdgraph[$i]); + } - $file = str_replace(":", "\\:", $file); - $rrd_args = str_replace('{file}', $file, $rrd_args); + return $cmd; + } - $rrdgraph = array_merge($rrd_cmd, $rrd_args); - $cmd = RRDTOOL; - $count_rrdgraph = count($rrdgraph); - for ($i = 1; $i < $count_rrdgraph; $i++) - $cmd .= ' '.escapeshellarg($rrdgraph[$i]); + return false; + +}//end collectd_draw_generic() - return $cmd; - } - return false; -} /** * Draw stack-graph for set of RRD files @@ -628,97 +861,137 @@ function collectd_draw_generic($timespan, $host, $plugin, $pinst = null, $type, * @return Commandline to call RRDGraph in order to generate the final graph */ function collectd_draw_meta_stack(&$opts, &$sources) { - global $config; - $timespan_def = null; - if (!isset($opts['timespan'])) - $timespan_def = reset($config['timespan']); - else foreach ($config['timespan'] as &$ts) - if ($ts['name'] == $opts['timespan']) - $timespan_def = $ts; + global $config; + $timespan_def = null; + if (!isset($opts['timespan'])) { + $timespan_def = reset($config['timespan']); + } + else { + foreach ($config['timespan'] as &$ts) { + if ($ts['name'] == $opts['timespan']) { + $timespan_def = $ts; + } + } + } - if (!isset($opts['title'])) - $opts['title'] = 'Unknown title'; - if (!isset($opts['rrd_opts'])) - $opts['rrd_opts'] = array(); - if (!isset($opts['colors'])) - $opts['colors'] = array(); - if (isset($opts['logarithmic']) && $opts['logarithmic']) - array_unshift($opts['rrd_opts'], '-o'); + if (!isset($opts['title'])) { + $opts['title'] = 'Unknown title'; + } -# $cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], -# '-t', $opts['title']); + if (!isset($opts['rrd_opts'])) { + $opts['rrd_opts'] = array(); + } - $cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height']); + if (!isset($opts['colors'])) { + $opts['colors'] = array(); + } - if($config['rrd_width'] <= "300") { - $small_opts = array ('--font', 'LEGEND:7:mono', '--font', 'AXIS:6:mono', '--font-render-mode', 'normal'); - $cmd = array_merge($cmd, $small_opts); + if (isset($opts['logarithmic']) && $opts['logarithmic']) { + array_unshift($opts['rrd_opts'], '-o'); + } + + // $cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], + // '-t', $opts['title']); + $cmd = array( + RRDTOOL, + 'graph', + '-', + '-E', + '-a', + 'PNG', + '-w', + $config['rrd_width'], + '-h', + $config['rrd_height'], + ); + + if ($config['rrd_width'] <= '300') { + $small_opts = array( + '--font', + 'LEGEND:7:mono', + '--font', + 'AXIS:6:mono', + '--font-render-mode', + 'normal', + ); + $cmd = array_merge($cmd, $small_opts); + } + + $cmd = array_merge($cmd, $config['rrd_opts_array'], $opts['rrd_opts']); + $max_inst_name = 0; + + foreach ($sources as &$inst_data) { + $inst_name = $inst_data['name']; + $file = $inst_data['file']; + $ds = isset($inst_data['ds']) ? $inst_data['ds'] : 'value'; + + if (strlen($inst_name) > $max_inst_name) { + $max_inst_name = strlen($inst_name); } + if (!is_file($file)) { + continue; + } - $cmd = array_merge($cmd, $config['rrd_opts_array'], $opts['rrd_opts']); - $max_inst_name = 0; + $cmd[] = 'DEF:'.$inst_name.'_min='.$file.':'.$ds.':MIN'; + $cmd[] = 'DEF:'.$inst_name.'_avg='.$file.':'.$ds.':AVERAGE'; + $cmd[] = 'DEF:'.$inst_name.'_max='.$file.':'.$ds.':MAX'; + $cmd[] = 'CDEF:'.$inst_name.'_nnl='.$inst_name.'_avg,UN,0,'.$inst_name.'_avg,IF'; + } - foreach($sources as &$inst_data) { - $inst_name = $inst_data['name']; - $file = $inst_data['file']; - $ds = isset($inst_data['ds']) ? $inst_data['ds'] : 'value'; + $inst_data = end($sources); + $inst_name = $inst_data['name']; + $cmd[] = 'CDEF:'.$inst_name.'_stk='.$inst_name.'_nnl'; - if (strlen($inst_name) > $max_inst_name) - $max_inst_name = strlen($inst_name); + $inst_data1 = end($sources); + while (($inst_data0 = prev($sources)) !== false) { + $inst_name0 = $inst_data0['name']; + $inst_name1 = $inst_data1['name']; - if (!is_file($file)) - continue; + $cmd[] = 'CDEF:'.$inst_name0.'_stk='.$inst_name0.'_nnl,'.$inst_name1.'_stk,+'; + $inst_data1 = $inst_data0; + } - $cmd[] = 'DEF:'.$inst_name.'_min='.$file.':'.$ds.':MIN'; - $cmd[] = 'DEF:'.$inst_name.'_avg='.$file.':'.$ds.':AVERAGE'; - $cmd[] = 'DEF:'.$inst_name.'_max='.$file.':'.$ds.':MAX'; - $cmd[] = 'CDEF:'.$inst_name.'_nnl='.$inst_name.'_avg,UN,0,'.$inst_name.'_avg,IF'; - } - $inst_data = end($sources); - $inst_name = $inst_data['name']; - $cmd[] = 'CDEF:'.$inst_name.'_stk='.$inst_name.'_nnl'; + foreach ($sources as &$inst_data) { + $inst_name = $inst_data['name']; + // $legend = sprintf('%s', $inst_name); + $legend = $inst_name; + while (strlen($legend) < $max_inst_name) { + $legend .= ' '; + } - $inst_data1 = end($sources); - while (($inst_data0 = prev($sources)) !== false) { - $inst_name0 = $inst_data0['name']; - $inst_name1 = $inst_data1['name']; + $number_format = isset($opts['number_format']) ? $opts['number_format'] : '%6.1lf'; - $cmd[] = 'CDEF:'.$inst_name0.'_stk='.$inst_name0.'_nnl,'.$inst_name1.'_stk,+'; - $inst_data1 = $inst_data0; - } + if (isset($opts['colors'][$inst_name])) { + $line_color = new CollectdColor($opts['colors'][$inst_name]); + } + else { + $line_color = new CollectdColor('random'); + } - foreach($sources as &$inst_data) { - $inst_name = $inst_data['name']; -# $legend = sprintf('%s', $inst_name); - $legend = $inst_name; - while (strlen($legend) < $max_inst_name) - $legend .= ' '; - $number_format = isset($opts['number_format']) ? $opts['number_format'] : '%6.1lf'; + $area_color = new CollectdColor($line_color); + $area_color->fade(); - if (isset($opts['colors'][$inst_name])) - $line_color = new CollectdColor($opts['colors'][$inst_name]); - else - $line_color = new CollectdColor('random'); - $area_color = new CollectdColor($line_color); - $area_color->fade(); + $cmd[] = 'AREA:'.$inst_name.'_stk#'.$area_color->as_string(); + $cmd[] = 'LINE1:'.$inst_name.'_stk#'.$line_color->as_string().':'.$legend; + if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) { + $cmd[] = 'GPRINT:'.$inst_name.'_avg:LAST:'.$number_format.''; + $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.''; + $cmd[] = 'GPRINT:'.$inst_name.'_min:MIN:'.$number_format.''; + $cmd[] = 'GPRINT:'.$inst_name.'_max:MAX:'.$number_format.'\\l'; + } + }//end foreach - $cmd[] = 'AREA:'.$inst_name.'_stk#'.$area_color->as_string(); - $cmd[] = 'LINE1:'.$inst_name.'_stk#'.$line_color->as_string().':'.$legend; - if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) { - $cmd[] = 'GPRINT:'.$inst_name.'_avg:LAST:'.$number_format.''; - $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.''; - $cmd[] = 'GPRINT:'.$inst_name.'_min:MIN:'.$number_format.''; - $cmd[] = 'GPRINT:'.$inst_name.'_max:MAX:'.$number_format.'\\l'; - } - } + $rrdcmd = RRDTOOL; + $count_cmd = count($cmd); + for ($i = 1; $i < $count_cmd; $i++) { + $rrdcmd .= ' '.escapeshellarg($cmd[$i]); + } + + return $rrdcmd; + +}//end collectd_draw_meta_stack() - $rrdcmd = RRDTOOL; - $count_cmd = count($cmd); - for ($i = 1; $i < $count_cmd; $i++) - $rrdcmd .= ' '.escapeshellarg($cmd[$i]); - return $rrdcmd; -} /** * Draw stack-graph for set of RRD files @@ -727,79 +1000,113 @@ function collectd_draw_meta_stack(&$opts, &$sources) { * @return Commandline to call RRDGraph in order to generate the final graph */ function collectd_draw_meta_line(&$opts, &$sources) { - global $config; - $timespan_def = null; - if (!isset($opts['timespan'])) - $timespan_def = reset($config['timespan']); - else foreach ($config['timespan'] as &$ts) - if ($ts['name'] == $opts['timespan']) - $timespan_def = $ts; + global $config; + $timespan_def = null; + if (!isset($opts['timespan'])) { + $timespan_def = reset($config['timespan']); + } + else { + foreach ($config['timespan'] as &$ts) { + if ($ts['name'] == $opts['timespan']) { + $timespan_def = $ts; + } + } + } - if (!isset($opts['title'])) - $opts['title'] = 'Unknown title'; - if (!isset($opts['rrd_opts'])) - $opts['rrd_opts'] = array(); - if (!isset($opts['colors'])) - $opts['colors'] = array(); - if (isset($opts['logarithmic']) && $opts['logarithmic']) - array_unshift($opts['rrd_opts'], '-o'); + if (!isset($opts['title'])) { + $opts['title'] = 'Unknown title'; + } -# $cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-t', $opts['title']); -# $cmd = array_merge($cmd, $config['rrd_opts_array'], $opts['rrd_opts']); + if (!isset($opts['rrd_opts'])) { + $opts['rrd_opts'] = array(); + } - $cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height']); + if (!isset($opts['colors'])) { + $opts['colors'] = array(); + } - if($config['rrd_width'] <= "300") { - $small_opts = array ('--font', 'LEGEND:7:mono', '--font', 'AXIS:6:mono', '--font-render-mode', 'normal'); - $cmd = array_merge($cmd, $small_opts); + if (isset($opts['logarithmic']) && $opts['logarithmic']) { + array_unshift($opts['rrd_opts'], '-o'); + } + + // $cmd = array(RRDTOOL, 'graph', '-', '-E', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-t', $opts['title']); + // $cmd = array_merge($cmd, $config['rrd_opts_array'], $opts['rrd_opts']); + $cmd = array( + RRDTOOL, + 'graph', + '-', + '-E', + '-a', + 'PNG', + '-w', + $config['rrd_width'], + '-h', + $config['rrd_height'], + ); + + if ($config['rrd_width'] <= '300') { + $small_opts = array( + '--font', + 'LEGEND:7:mono', + '--font', + 'AXIS:6:mono', + '--font-render-mode', + 'normal', + ); + $cmd = array_merge($cmd, $small_opts); + } + + $max_inst_name = 0; + + foreach ($sources as &$inst_data) { + $inst_name = $inst_data['name']; + $file = $inst_data['file']; + $ds = isset($inst_data['ds']) ? $inst_data['ds'] : 'value'; + + if (strlen($inst_name) > $max_inst_name) { + $max_inst_name = strlen($inst_name); } + if (!is_file($file)) { + continue; + } + $cmd[] = 'DEF:'.$inst_name.'_min='.$file.':'.$ds.':MIN'; + $cmd[] = 'DEF:'.$inst_name.'_avg='.$file.':'.$ds.':AVERAGE'; + $cmd[] = 'DEF:'.$inst_name.'_max='.$file.':'.$ds.':MAX'; + } - $max_inst_name = 0; + foreach ($sources as &$inst_data) { + $inst_name = $inst_data['name']; + $legend = sprintf('%s', $inst_name); + while (strlen($legend) < $max_inst_name) { + $legend .= ' '; + } - foreach ($sources as &$inst_data) { - $inst_name = $inst_data['name']; - $file = $inst_data['file']; - $ds = isset($inst_data['ds']) ? $inst_data['ds'] : 'value'; + $number_format = isset($opts['number_format']) ? $opts['number_format'] : '%6.1lf'; - if (strlen($inst_name) > $max_inst_name) - $max_inst_name = strlen($inst_name); + if (isset($opts['colors'][$inst_name])) { + $line_color = new CollectdColor($opts['colors'][$inst_name]); + } + else { + $line_color = new CollectdColor('random'); + } - if (!is_file($file)) - continue; + $cmd[] = 'LINE1:'.$inst_name.'_avg#'.$line_color->as_string().':'.$legend; + if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) { + $cmd[] = 'GPRINT:'.$inst_name.'_min:MIN:'.$number_format.''; + $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.''; + $cmd[] = 'GPRINT:'.$inst_name.'_max:MAX:'.$number_format.''; + $cmd[] = 'GPRINT:'.$inst_name.'_avg:LAST:'.$number_format.'\\l'; + } + }//end foreach - $cmd[] = 'DEF:'.$inst_name.'_min='.$file.':'.$ds.':MIN'; - $cmd[] = 'DEF:'.$inst_name.'_avg='.$file.':'.$ds.':AVERAGE'; - $cmd[] = 'DEF:'.$inst_name.'_max='.$file.':'.$ds.':MAX'; - } + $rrdcmd = RRDTOOL; + $count_cmd = count($cmd); + for ($i = 1; $i < $count_cmd; $i++) { + $rrdcmd .= ' '.escapeshellarg($cmd[$i]); + } - foreach ($sources as &$inst_data) { - $inst_name = $inst_data['name']; - $legend = sprintf('%s', $inst_name); - while (strlen($legend) < $max_inst_name) - $legend .= ' '; - $number_format = isset($opts['number_format']) ? $opts['number_format'] : '%6.1lf'; + return $rrdcmd; - if (isset($opts['colors'][$inst_name])) - $line_color = new CollectdColor($opts['colors'][$inst_name]); - else - $line_color = new CollectdColor('random'); - - $cmd[] = 'LINE1:'.$inst_name.'_avg#'.$line_color->as_string().':'.$legend; - if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) { - $cmd[] = 'GPRINT:'.$inst_name.'_min:MIN:'.$number_format.''; - $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.''; - $cmd[] = 'GPRINT:'.$inst_name.'_max:MAX:'.$number_format.''; - $cmd[] = 'GPRINT:'.$inst_name.'_avg:LAST:'.$number_format.'\\l'; - } - } - - $rrdcmd = RRDTOOL; - $count_cmd = count($cmd); - for ($i = 1; $i < $count_cmd; $i++) - $rrdcmd .= ' '.escapeshellarg($cmd[$i]); - return $rrdcmd; -} - -?> +}//end collectd_draw_meta_line() diff --git a/html/includes/dev-overview-data.inc.php b/html/includes/dev-overview-data.inc.php index 3d5882594f..889613c833 100644 --- a/html/includes/dev-overview-data.inc.php +++ b/html/includes/dev-overview-data.inc.php @@ -1,89 +1,87 @@ '); -echo("
    +echo '
    '; +echo "
    -
    "); +
    "; -if ($config['overview_show_sysDescr']) -{ - echo('' . $device['sysDescr'] . ""); +if ($config['overview_show_sysDescr']) { + echo ''.$device['sysDescr'].''; } -echo('
    - '); +echo ' +
    '; $uptime = $device['uptime']; -if ($device['os'] == "ios") { formatCiscoHardware($device); } -if ($device['features']) { $device['features'] = "(".$device['features'].")"; } +if ($device['os'] == 'ios') { + formatCiscoHardware($device); +} + +if ($device['features']) { + $device['features'] = '('.$device['features'].')'; +} + $device['os_text'] = $config['os'][$device['os']]['text']; -if ($device['hardware']) -{ - echo(' +if ($device['hardware']) { + echo ' - - '); + + '; } -echo(' +echo ' - - '); + + '; -if ($device['serial']) -{ - echo(' +if ($device['serial']) { + echo ' - - '); + + '; } -if ($device['sysContact']) -{ - echo(' - '); - if (get_dev_attrib($device,'override_sysContact_bool')) - { - echo(' - +if ($device['sysContact']) { + echo ' + '; + if (get_dev_attrib($device, 'override_sysContact_bool')) { + echo ' + - '); - } - echo(' - - '); + '; + } + + echo ' + + '; } -if ($device['location']) -{ - echo(' +if ($device['location']) { + echo ' - - '); - if (get_dev_attrib($device,'override_sysLocation_bool') && !empty($device['real_location'])) - { - echo(' + + '; + if (get_dev_attrib($device, 'override_sysLocation_bool') && !empty($device['real_location'])) { + echo ' - - '); - } + + '; + } } -if ($uptime) -{ - echo(' +if ($uptime) { + echo ' - - '); + + '; } -echo('
    Hardware' . $device['hardware']. '
    '.$device['hardware'].'
    Operating System' . $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'] . '
    '.$device['os_text'].' '.$device['version'].' '.$device['features'].'
    Serial' . $device['serial']. '
    '.$device['serial'].'
    Contact' . htmlspecialchars(get_dev_attrib($device,'override_sysContact_string')) . '
    Contact'.htmlspecialchars(get_dev_attrib($device, 'override_sysContact_string')).'
    SNMP Contact' . htmlspecialchars($device['sysContact']). '
    SNMP Contact'.htmlspecialchars($device['sysContact']).'
    Location' . $device['location']. '
    '.$device['location'].'
    SNMP Location' . $device['real_location']. '
    '.$device['real_location'].'
    Uptime' . formatUptime($uptime) . '
    '.formatUptime($uptime).'
    +echo '
    -
    '); -?> +
    '; diff --git a/html/includes/device-header.inc.php b/html/includes/device-header.inc.php index fc885958b0..8c6775930c 100644 --- a/html/includes/device-header.inc.php +++ b/html/includes/device-header.inc.php @@ -1,73 +1,70 @@ '.$image.' - ' . generate_device_link($device) . ' -
    ' . $device['location'] . ' - '); + '.generate_device_link($device).' +
    '.$device['location'].' + '; - if (isset($config['os'][$device['os']]['over'])) -{ - $graphs = $config['os'][$device['os']]['over']; +if (isset($config['os'][$device['os']]['over'])) { + $graphs = $config['os'][$device['os']]['over']; } -elseif (isset($device['os_group']) && isset($config['os'][$device['os_group']]['over'])) -{ - $graphs = $config['os'][$device['os_group']]['over']; +else if (isset($device['os_group']) && isset($config['os'][$device['os_group']]['over'])) { + $graphs = $config['os'][$device['os_group']]['over']; } -else -{ - $graphs = $config['os']['default']['over']; +else { + $graphs = $config['os']['default']['over']; } -$graph_array = array(); -$graph_array['height'] = "100"; -$graph_array['width'] = "310"; -$graph_array['to'] = $config['time']['now']; -$graph_array['device'] = $device['device_id']; -$graph_array['type'] = "device_bits"; -$graph_array['from'] = $config['time']['day']; -$graph_array['legend'] = "no"; +$graph_array = array(); +$graph_array['height'] = '100'; +$graph_array['width'] = '310'; +$graph_array['to'] = $config['time']['now']; +$graph_array['device'] = $device['device_id']; +$graph_array['type'] = 'device_bits'; +$graph_array['from'] = $config['time']['day']; +$graph_array['legend'] = 'no'; $graph_array['popup_title'] = $descr; -$graph_array['height'] = "45"; -$graph_array['width'] = "150"; -$graph_array['bg'] = "FFFFFF00"; +$graph_array['height'] = '45'; +$graph_array['width'] = '150'; +$graph_array['bg'] = 'FFFFFF00'; -foreach ($graphs as $entry) -{ - if ($entry['graph']) - { - $graph_array['type'] = $entry['graph']; +foreach ($graphs as $entry) { + if ($entry['graph']) { + $graph_array['type'] = $entry['graph']; - echo("
    "); - print_graph_popup($graph_array); - echo("
    ".$entry['text']."
    "); - echo("
    "); - } + echo "
    "; + print_graph_popup($graph_array); + echo "
    ".$entry['text'].'
    '; + echo '
    '; + } } unset($graph_array); -echo(' - '); - -?> +echo ' + '; diff --git a/html/includes/device-summary-horiz.inc.php b/html/includes/device-summary-horiz.inc.php index ae5d576c02..6f27b50af2 100644 --- a/html/includes/device-summary-horiz.inc.php +++ b/html/includes/device-summary-horiz.inc.php @@ -1,5 +1,5 @@
    diff --git a/html/includes/device-summary-vert.inc.php b/html/includes/device-summary-vert.inc.php index 8e0a1ff328..ee4e63d073 100644 --- a/html/includes/device-summary-vert.inc.php +++ b/html/includes/device-summary-vert.inc.php @@ -1,5 +1,5 @@
    diff --git a/html/includes/error-no-perm.inc.php b/html/includes/error-no-perm.inc.php index 09717037b6..37a1c9c7ea 100644 --- a/html/includes/error-no-perm.inc.php +++ b/html/includes/error-no-perm.inc.php @@ -16,5 +16,3 @@ echo("
    "); print_optionbar_end(); echo("
    "); - -?> diff --git a/html/includes/front/boxes.inc.php b/html/includes/front/boxes.inc.php index 665c1d738c..e767aa6989 100644 --- a/html/includes/front/boxes.inc.php +++ b/html/includes/front/boxes.inc.php @@ -11,31 +11,23 @@ * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ -?> - div" - style="clear: both"> -'); +data-cycle-fx="fade" +data-cycle-timeout="10000" +data-cycle-slides="> div" +style="clear: both"> +'; -foreach (get_matching_files($config['html_dir']."/includes/front/", "/^top_.*\.php$/") as $file) -{ - if(($file == 'top_ports.inc.php' && $config['top_ports'] == 0) || ($file == 'top_device_bits.inc.php' && $config['top_devices'] == 0)) - { - } - else - { - echo("
    \n"); - include_once($file); - echo("
    \n"); - } +foreach (get_matching_files($config['html_dir'].'/includes/front/', '/^top_.*\.php$/') as $file) { + if (($file == 'top_ports.inc.php' && $config['top_ports'] == 0) || ($file == 'top_device_bits.inc.php' && $config['top_devices'] == 0)) { + } + else { + echo "
    \n"; + include_once $file; + echo "
    \n"; + } } -echo("
    \n"); - -?> - +echo "\n"; diff --git a/html/includes/front/top_device_bits.inc.php b/html/includes/front/top_device_bits.inc.php index 4b48bfd4a7..9c0e873620 100644 --- a/html/includes/front/top_device_bits.inc.php +++ b/html/includes/front/top_device_bits.inc.php @@ -14,9 +14,9 @@ */ $minutes = 15; -$seconds = $minutes * 60; -$top = $config['front_page_settings']['top']['devices']; -if (is_admin() === TRUE || is_read() === TRUE) { +$seconds = ($minutes * 60); +$top = $config['front_page_settings']['top']['devices']; +if (is_admin() === true || is_read() === true) { $query = " SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total FROM ports as p, devices as d @@ -27,9 +27,10 @@ if (is_admin() === TRUE || is_read() === TRUE) { GROUP BY d.device_id ORDER BY total desc LIMIT $top - "; -} else { - $query = " + "; +} +else { + $query = " SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total FROM ports as p, devices as d, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id` AND @@ -40,19 +41,21 @@ if (is_admin() === TRUE || is_read() === TRUE) { GROUP BY d.device_id ORDER BY total desc LIMIT $top - "; + "; $param[] = array($_SESSION['user_id']); +}//end if + +echo "Top $top devices (last $minutes minutes)\n"; +echo "\n"; +foreach (dbFetchRows($query, $param) as $result) { + echo ''.''.''."\n"; } -echo("Top $top devices (last $minutes minutes)\n"); -echo("
    '.generate_device_link($result, shorthost($result['hostname'])).''.generate_device_link( + $result, + generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], 'device_bits', 'no', 150, 21, '&', 'top10'), + array(), + 0, + 0, + 0 + ).'
    \n"); -foreach (dbFetchRows($query,$param) as $result) { - echo("". - "". - "". - "\n"); -} -echo("
    ".generate_device_link($result, shorthost($result['hostname']))."".generate_device_link($result, - generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], "device_bits", "no", 150, 21, '&', "top10"), array(), 0, 0, 0)."
    \n"); - -?> +echo "\n"; diff --git a/html/includes/front/top_ports.inc.php b/html/includes/front/top_ports.inc.php index 0085252079..c3bf3bc304 100644 --- a/html/includes/front/top_ports.inc.php +++ b/html/includes/front/top_ports.inc.php @@ -14,9 +14,9 @@ */ $minutes = 15; -$seconds = $minutes * 60; -$top = $config['front_page_settings']['top']['ports']; -if (is_admin() === TRUE || is_read() === TRUE) { +$seconds = ($minutes * 60); +$top = $config['front_page_settings']['top']['ports']; +if (is_admin() === true || is_read() === true) { $query = " SELECT *, p.ifInOctets_rate + p.ifOutOctets_rate as total FROM ports as p, devices as d @@ -26,9 +26,10 @@ if (is_admin() === TRUE || is_read() === TRUE) { OR p.ifOutOctets_rate > 0 ) ORDER BY total desc LIMIT $top - "; -} else { - $query = " + "; +} +else { + $query = " SELECT *, I.ifInOctets_rate + I.ifOutOctets_rate as total FROM ports as I, devices as d, `devices_perms` AS `P`, `ports_perms` AS `PP` @@ -39,19 +40,17 @@ if (is_admin() === TRUE || is_read() === TRUE) { OR I.ifOutOctets_rate > 0 ) ORDER BY total desc LIMIT $top - "; - $param[] = array($_SESSION['user_id'],$_SESSION['user_id']); + "; + $param[] = array( + $_SESSION['user_id'], + $_SESSION['user_id'], + ); +}//end if + +echo "Top $top ports (last $minutes minutes)\n"; +echo "\n"; +foreach (dbFetchRows($query, $param) as $result) { + echo ''.''.''.''."\n"; } -echo("Top $top ports (last $minutes minutes)\n"); -echo("
    '.generate_device_link($result, shorthost($result['hostname'])).''.generate_port_link($result).''.generate_port_link($result, generate_port_thumbnail($result)).'
    \n"); -foreach (dbFetchRows($query,$param) as $result) { - echo("". - "". - "". - "". - "\n"); -} -echo("
    ".generate_device_link($result, shorthost($result['hostname']))."".generate_port_link($result)."".generate_port_link($result, generate_port_thumbnail($result))."
    \n"); - -?> +echo "\n"; diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index fc7c52a09b..6aed9fa6f3 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -10,351 +10,437 @@ * @author LibreNMS Contributors * @copyright (C) 2006 - 2012 Adam Armstrong (as Observium) * @copyright (C) 2013 LibreNMS Group - * */ -function data_uri($file, $mime) -{ - $contents = file_get_contents($file); - $base64 = base64_encode($contents); - return ('data:' . $mime . ';base64,' . $base64); -} -function nicecase($item) -{ - switch ($item) - { - case "dbm": - return "dBm"; - case "mysql": - return" MySQL"; - case "powerdns": - return "PowerDNS"; - case "bind": - return "BIND"; +function data_uri($file, $mime) { + $contents = file_get_contents($file); + $base64 = base64_encode($contents); + return ('data:'.$mime.';base64,'.$base64); + +}//end data_uri() + + +function nicecase($item) { + switch ($item) { + case 'dbm': + return 'dBm'; + + case 'mysql': + return ' MySQL'; + + case 'powerdns': + return 'PowerDNS'; + + case 'bind': + return 'BIND'; + default: - return ucfirst($item); - } -} - -function toner2colour($descr, $percent) -{ - $colour = get_percentage_colours(100-$percent); - - if (substr($descr,-1) == 'C' || stripos($descr,"cyan" ) !== false) { $colour['left'] = "55D6D3"; $colour['right'] = "33B4B1"; } - if (substr($descr,-1) == 'M' || stripos($descr,"magenta") !== false) { $colour['left'] = "F24AC8"; $colour['right'] = "D028A6"; } - if (substr($descr,-1) == 'Y' || stripos($descr,"yellow" ) !== false - || stripos($descr,"giallo" ) !== false - || stripos($descr,"gul" ) !== false) { $colour['left'] = "FFF200"; $colour['right'] = "DDD000"; } - if (substr($descr,-1) == 'K' || stripos($descr,"black" ) !== false - || stripos($descr,"nero" ) !== false) { $colour['left'] = "000000"; $colour['right'] = "222222"; } - - return $colour; -} - -function generate_link($text, $vars, $new_vars = array()) -{ - return ''.$text.''; -} - -function generate_url($vars, $new_vars = array()) -{ - - $vars = array_merge($vars, $new_vars); - - $url = $vars['page']."/"; - unset($vars['page']); - - foreach ($vars as $var => $value) - { - if ($value == "0" || $value != "" && strstr($var, "opt") === FALSE && is_numeric($var) === FALSE) - { - $url .= $var ."=".urlencode($value)."/"; + return ucfirst($item); } - } - return($url); +}//end nicecase() -} -function escape_quotes($text) -{ - return str_replace('"', "\'", str_replace("'", "\'", $text)); -} +function toner2colour($descr, $percent) { + $colour = get_percentage_colours(100 - $percent); -function generate_overlib_content($graph_array, $text) -{ + if (substr($descr, -1) == 'C' || stripos($descr, 'cyan') !== false) { + $colour['left'] = '55D6D3'; + $colour['right'] = '33B4B1'; + } + + if (substr($descr, -1) == 'M' || stripos($descr, 'magenta') !== false) { + $colour['left'] = 'F24AC8'; + $colour['right'] = 'D028A6'; + } + + if (substr($descr, -1) == 'Y' || stripos($descr, 'yellow') !== false + || stripos($descr, 'giallo') !== false + || stripos($descr, 'gul') !== false + ) { + $colour['left'] = 'FFF200'; + $colour['right'] = 'DDD000'; + } + + if (substr($descr, -1) == 'K' || stripos($descr, 'black') !== false + || stripos($descr, 'nero') !== false + ) { + $colour['left'] = '000000'; + $colour['right'] = '222222'; + } + + return $colour; + +}//end toner2colour() + + +function generate_link($text, $vars, $new_vars=array()) { + return ''.$text.''; + +}//end generate_link() + + +function generate_url($vars, $new_vars=array()) { + $vars = array_merge($vars, $new_vars); + + $url = $vars['page'].'/'; + unset($vars['page']); + + foreach ($vars as $var => $value) { + if ($value == '0' || $value != '' && strstr($var, 'opt') === false && is_numeric($var) === false) { + $url .= $var.'='.urlencode($value).'/'; + } + } + + return ($url); + +}//end generate_url() + + +function escape_quotes($text) { + return str_replace('"', "\'", str_replace("'", "\'", $text)); + +}//end escape_quotes() + + +function generate_overlib_content($graph_array, $text) { global $config; $overlib_content = '
    '.$text.'
    '; - foreach (array('day','week','month','year') as $period) - { - $graph_array['from'] = $config['time'][$period]; - $overlib_content .= escape_quotes(generate_graph_tag($graph_array)); + foreach (array('day', 'week', 'month', 'year') as $period) { + $graph_array['from'] = $config['time'][$period]; + $overlib_content .= escape_quotes(generate_graph_tag($graph_array)); } + $overlib_content .= '
    '; return $overlib_content; -} +}//end generate_overlib_content() -function get_percentage_colours($percentage) -{ - $background = array(); - if ($percentage > '90') { $background['left']='c4323f'; $background['right']='C96A73'; } - elseif ($percentage > '75') { $background['left']='bf5d5b'; $background['right']='d39392'; } - elseif ($percentage > '50') { $background['left']='bf875b'; $background['right']='d3ae92'; } - elseif ($percentage > '25') { $background['left']='5b93bf'; $background['right']='92b7d3'; } - else { $background['left']='9abf5b'; $background['right']='bbd392'; } - return($background); - -} - -function generate_minigraph_image($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100, $sep = '&', $class = "minigraph-image") -{ - return ''; -} - -function generate_device_url($device, $vars=array()) -{ - return generate_url(array('page' => 'device', 'device' => $device['device_id']), $vars); -} - -function generate_device_link($device, $text=NULL, $vars=array(), $start=0, $end=0, $escape_text=1, $overlib=1) -{ - global $config; - - if (!$start) { $start = $config['time']['day']; } - if (!$end) { $end = $config['time']['now']; } - - $class = devclass($device); - if (!$text) { $text = $device['hostname']; } - - if (isset($config['os'][$device['os']]['over'])) - { - $graphs = $config['os'][$device['os']]['over']; - } - elseif (isset($device['os_group']) && isset($config['os'][$device['os_group']]['over'])) - { - $graphs = $config['os'][$device['os_group']]['over']; - } - else - { - $graphs = $config['os']['default']['over']; - } - - $url = generate_device_url($device, $vars); - - // beginning of overlib box contains large hostname followed by hardware & OS details - $contents = "
    ".$device['hostname'].""; - if ($device['hardware']) { $contents .= " - ".$device['hardware']; } - if ($device['os']) { $contents .= " - ".mres($config['os'][$device['os']]['text']); } - if ($device['version']) { $contents .= " ".mres($device['version']); } - if ($device['features']) { $contents .= " (".mres($device['features']).")"; } - if (isset($device['location'])) { $contents .= " - " . htmlentities($device['location']); } - $contents .= "
    "; - - foreach ($graphs as $entry) - { - $graph = $entry['graph']; - $graphhead = $entry['text']; - $contents .= '
    '; - $contents .= ''.$graphhead.'
    '; - $contents .= generate_minigraph_image($device, $start, $end, $graph); - $contents .= generate_minigraph_image($device, $config['time']['week'], $end, $graph); - $contents .= '
    '; - } - - if ($escape_text) { $text = htmlentities($text); } - if ($overlib == 0) { - $link = $contents; - } else { - $link = overlib_link($url, $text, escape_quotes($contents), $class); - } - - if (device_permitted($device['device_id'])) - { - return $link; - } else { - return $device['hostname']; - } -} - -function overlib_link($url, $text, $contents, $class) -{ - global $config; - - $contents = str_replace("\"", "\'", $contents); - $output = '"; - } - $output .= $text.""; - - return $output; -} - -function generate_graph_popup($graph_array) -{ - global $config; - - // Take $graph_array and print day,week,month,year graps in overlib, hovered over graph - - $original_from = $graph_array['from']; - - $graph = generate_graph_tag($graph_array); - $content = "
    ".$graph_array['popup_title']."
    "; - $content .= "
    "; - $graph_array['legend'] = "yes"; - $graph_array['height'] = "100"; - $graph_array['width'] = "340"; - $graph_array['from'] = $config['time']['day']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['week']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['month']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['year']; - $content .= generate_graph_tag($graph_array); - $content .= "
    "; - - $graph_array['from'] = $original_from; - - $graph_array['link'] = generate_url($graph_array, array('page' => 'graphs', 'height' => NULL, 'width' => NULL, 'bg' => NULL)); - -# $graph_array['link'] = "graphs/type=" . $graph_array['type'] . "/id=" . $graph_array['id']; - - return overlib_link($graph_array['link'], $graph, $content, NULL); -} - -function print_graph_popup($graph_array) -{ - echo(generate_graph_popup($graph_array)); -} - -function permissions_cache($user_id) -{ - $permissions = array(); - foreach (dbFetchRows("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'") as $device) - { - $permissions['device'][$device['device_id']] = 1; - } - foreach (dbFetchRows("SELECT * FROM ports_perms WHERE user_id = '".$user_id."'") as $port) - { - $permissions['port'][$port['port_id']] = 1; - } - foreach (dbFetchRows("SELECT * FROM bill_perms WHERE user_id = '".$user_id."'") as $bill) - { - $permissions['bill'][$bill['bill_id']] = 1; - } - - return $permissions; -} - -function bill_permitted($bill_id) -{ - global $permissions; - - if ($_SESSION['userlevel'] >= "5") { - $allowed = TRUE; - } elseif ($permissions['bill'][$bill_id]) { - $allowed = TRUE; - } else { - $allowed = FALSE; - } - - return $allowed; -} - -function port_permitted($port_id, $device_id = NULL) -{ - global $permissions; - - if (!is_numeric($device_id)) { $device_id = get_device_id_by_port_id($port_id); } - - if ($_SESSION['userlevel'] >= "5") - { - $allowed = TRUE; - } elseif (device_permitted($device_id)) { - $allowed = TRUE; - } elseif ($permissions['port'][$port_id]) { - $allowed = TRUE; - } else { - $allowed = FALSE; - } - - return $allowed; -} - -function application_permitted($app_id, $device_id = NULL) -{ - global $permissions; - - if (is_numeric($app_id)) - { - if (!$device_id) { $device_id = get_device_id_by_app_id ($app_id); } - if ($_SESSION['userlevel'] >= "5") { - $allowed = TRUE; - } elseif (device_permitted($device_id)) { - $allowed = TRUE; - } elseif ($permissions['application'][$app_id]) { - $allowed = TRUE; - } else { - $allowed = FALSE; +function get_percentage_colours($percentage) { + $background = array(); + if ($percentage > '90') { + $background['left'] = 'c4323f'; + $background['right'] = 'C96A73'; } - } else { - $allowed = FALSE; - } - return $allowed; -} + else if ($percentage > '75') { + $background['left'] = 'bf5d5b'; + $background['right'] = 'd39392'; + } -function device_permitted($device_id) -{ - global $permissions; + else if ($percentage > '50') { + $background['left'] = 'bf875b'; + $background['right'] = 'd3ae92'; + } - if ($_SESSION['userlevel'] >= "5") - { - $allowed = true; - } elseif ($permissions['device'][$device_id]) { - $allowed = true; - } else { - $allowed = false; - } + else if ($percentage > '25') { + $background['left'] = '5b93bf'; + $background['right'] = '92b7d3'; + } - return $allowed; -} + else { + $background['left'] = '9abf5b'; + $background['right'] = 'bbd392'; + } -function print_graph_tag($args) -{ - echo(generate_graph_tag($args)); -} + return ($background); -function generate_graph_tag($args) -{ - $urlargs = array(); - foreach ($args as $key => $arg) - { - $urlargs[] = $key."=".urlencode($arg); - } +}//end get_percentage_colours() + + +function generate_minigraph_image($device, $start, $end, $type, $legend='no', $width=275, $height=100, $sep='&', $class='minigraph-image') { + return ''; + +}//end generate_minigraph_image() + + +function generate_device_url($device, $vars=array()) { + return generate_url(array('page' => 'device', 'device' => $device['device_id']), $vars); + +}//end generate_device_url() + + +function generate_device_link($device, $text=null, $vars=array(), $start=0, $end=0, $escape_text=1, $overlib=1) { + global $config; + + if (!$start) { + $start = $config['time']['day']; + } + + if (!$end) { + $end = $config['time']['now']; + } + + $class = devclass($device); + if (!$text) { + $text = $device['hostname']; + } + + if (isset($config['os'][$device['os']]['over'])) { + $graphs = $config['os'][$device['os']]['over']; + } + else if (isset($device['os_group']) && isset($config['os'][$device['os_group']]['over'])) { + $graphs = $config['os'][$device['os_group']]['over']; + } + else { + $graphs = $config['os']['default']['over']; + } + + $url = generate_device_url($device, $vars); + + // beginning of overlib box contains large hostname followed by hardware & OS details + $contents = '
    '.$device['hostname'].''; + if ($device['hardware']) { + $contents .= ' - '.$device['hardware']; + } + + if ($device['os']) { + $contents .= ' - '.mres($config['os'][$device['os']]['text']); + } + + if ($device['version']) { + $contents .= ' '.mres($device['version']); + } + + if ($device['features']) { + $contents .= ' ('.mres($device['features']).')'; + } + + if (isset($device['location'])) { + $contents .= ' - '.htmlentities($device['location']); + } + + $contents .= '
    '; + + foreach ($graphs as $entry) { + $graph = $entry['graph']; + $graphhead = $entry['text']; + $contents .= '
    '; + $contents .= ''.$graphhead.'
    '; + $contents .= generate_minigraph_image($device, $start, $end, $graph); + $contents .= generate_minigraph_image($device, $config['time']['week'], $end, $graph); + $contents .= '
    '; + } + + if ($escape_text) { + $text = htmlentities($text); + } + + if ($overlib == 0) { + $link = $contents; + } + else { + $link = overlib_link($url, $text, escape_quotes($contents), $class); + } + + if (device_permitted($device['device_id'])) { + return $link; + } + else { + return $device['hostname']; + } + +}//end generate_device_link() + + +function overlib_link($url, $text, $contents, $class) { + global $config; + + $contents = str_replace('"', "\'", $contents); + $output = ''; + } + + $output .= $text.''; + + return $output; + +}//end overlib_link() + + +function generate_graph_popup($graph_array) { + global $config; + + // Take $graph_array and print day,week,month,year graps in overlib, hovered over graph + $original_from = $graph_array['from']; + + $graph = generate_graph_tag($graph_array); + $content = '
    '.$graph_array['popup_title'].'
    '; + $content .= "
    "; + $graph_array['legend'] = 'yes'; + $graph_array['height'] = '100'; + $graph_array['width'] = '340'; + $graph_array['from'] = $config['time']['day']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['week']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['month']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['year']; + $content .= generate_graph_tag($graph_array); + $content .= '
    '; + + $graph_array['from'] = $original_from; + + $graph_array['link'] = generate_url($graph_array, array('page' => 'graphs', 'height' => null, 'width' => null, 'bg' => null)); + + // $graph_array['link'] = "graphs/type=" . $graph_array['type'] . "/id=" . $graph_array['id']; + return overlib_link($graph_array['link'], $graph, $content, null); + +}//end generate_graph_popup() + + +function print_graph_popup($graph_array) { + echo generate_graph_popup($graph_array); + +}//end print_graph_popup() + + +function permissions_cache($user_id) { + $permissions = array(); + foreach (dbFetchRows("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'") as $device) { + $permissions['device'][$device['device_id']] = 1; + } + + foreach (dbFetchRows("SELECT * FROM ports_perms WHERE user_id = '".$user_id."'") as $port) { + $permissions['port'][$port['port_id']] = 1; + } + + foreach (dbFetchRows("SELECT * FROM bill_perms WHERE user_id = '".$user_id."'") as $bill) { + $permissions['bill'][$bill['bill_id']] = 1; + } + + return $permissions; + +}//end permissions_cache() + + +function bill_permitted($bill_id) { + global $permissions; + + if ($_SESSION['userlevel'] >= '5') { + $allowed = true; + } + else if ($permissions['bill'][$bill_id]) { + $allowed = true; + } + else { + $allowed = false; + } + + return $allowed; + +}//end bill_permitted() + + +function port_permitted($port_id, $device_id=null) { + global $permissions; + + if (!is_numeric($device_id)) { + $device_id = get_device_id_by_port_id($port_id); + } + + if ($_SESSION['userlevel'] >= '5') { + $allowed = true; + } + else if (device_permitted($device_id)) { + $allowed = true; + } + else if ($permissions['port'][$port_id]) { + $allowed = true; + } + else { + $allowed = false; + } + + return $allowed; + +}//end port_permitted() + + +function application_permitted($app_id, $device_id=null) { + global $permissions; + + if (is_numeric($app_id)) { + if (!$device_id) { + $device_id = get_device_id_by_app_id($app_id); + } + + if ($_SESSION['userlevel'] >= '5') { + $allowed = true; + } + else if (device_permitted($device_id)) { + $allowed = true; + } + else if ($permissions['application'][$app_id]) { + $allowed = true; + } + else { + $allowed = false; + } + } + else { + $allowed = false; + } + + return $allowed; + +}//end application_permitted() + + +function device_permitted($device_id) { + global $permissions; + + if ($_SESSION['userlevel'] >= '5') { + $allowed = true; + } + else if ($permissions['device'][$device_id]) { + $allowed = true; + } + else { + $allowed = false; + } + + return $allowed; + +}//end device_permitted() + + +function print_graph_tag($args) { + echo generate_graph_tag($args); + +}//end print_graph_tag() + + +function generate_graph_tag($args) { + $urlargs = array(); + foreach ($args as $key => $arg) { + $urlargs[] = $key.'='.urlencode($arg); + } + + return ''; + +}//end generate_graph_tag() - return ''; -} function generate_graph_js_state($args) { - // we are going to assume we know roughly what the graph url looks like here. - // TODO: Add sensible defaults - $from = (is_numeric($args['from']) ? $args['from'] : 0); - $to = (is_numeric($args['to']) ? $args['to'] : 0); - $width = (is_numeric($args['width']) ? $args['width'] : 0); - $height = (is_numeric($args['height']) ? $args['height'] : 0); - $legend = str_replace("'", "", $args['legend']); + // we are going to assume we know roughly what the graph url looks like here. + // TODO: Add sensible defaults + $from = (is_numeric($args['from']) ? $args['from'] : 0); + $to = (is_numeric($args['to']) ? $args['to'] : 0); + $width = (is_numeric($args['width']) ? $args['width'] : 0); + $height = (is_numeric($args['height']) ? $args['height'] : 0); + $legend = str_replace("'", '', $args['legend']); - $state = << document.graphFrom = $from; document.graphTo = $to; @@ -364,504 +450,662 @@ document.graphLegend = '$legend'; STATE; - return $state; -} + return $state; -function print_percentage_bar($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background) -{ +}//end generate_graph_js_state() - if ($percent > "100") { $size_percent = "100"; } else { $size_percent = $percent; } - $output = ' -
    -
    -
    -
    -
    - '.$left_text.' - '.$right_text.' -
    -'; +function print_percentage_bar($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background) { + if ($percent > '100') { + $size_percent = '100'; + } + else { + $size_percent = $percent; + } - return $output; -} + $output = ' +
    +
    +
    +
    +
    + '.$left_text.' + '.$right_text.' +
    + '; -function generate_entity_link($type, $entity, $text = NULL, $graph_type=NULL) -{ - global $config, $entity_cache; + return $output; - if (is_numeric($entity)) - { - $entity = get_entity_by_id_cache($type, $entity); - } +}//end print_percentage_bar() + + +function generate_entity_link($type, $entity, $text=null, $graph_type=null) { + global $config, $entity_cache; + + if (is_numeric($entity)) { + $entity = get_entity_by_id_cache($type, $entity); + } + + switch ($type) { + case 'port': + $link = generate_port_link($entity, $text, $graph_type); + break; + + case 'storage': + if (empty($text)) { + $text = $entity['storage_descr']; + } + + $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'storage')); + break; - switch($type) - { - case "port": - $link = generate_port_link($entity, $text, $graph_type); - break; - case "storage": - if (empty($text)) { $text = $entity['storage_descr']; } - $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'storage')); - break; default: - $link = $entity[$type.'_id']; - } + $link = $entity[$type.'_id']; + } - return($link); + return ($link); -} +}//end generate_entity_link() -function generate_port_link($port, $text = NULL, $type = NULL, $overlib = 1, $single_graph = 0) -{ - global $config; - $graph_array = array(); - $port = ifNameDescr($port); - if (!$text) { $text = fixIfName($port['label']); } - if ($type) { $port['graph_type'] = $type; } - if (!isset($port['graph_type'])) { $port['graph_type'] = 'port_bits'; } +function generate_port_link($port, $text=null, $type=null, $overlib=1, $single_graph=0) { + global $config; - $class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); + $graph_array = array(); + $port = ifNameDescr($port); + if (!$text) { + $text = fixIfName($port['label']); + } - if (!isset($port['hostname'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } + if ($type) { + $port['graph_type'] = $type; + } - $content = "
    ".$port['hostname']." - " . fixifName($port['label']) . "
    "; - if ($port['ifAlias']) { $content .= $port['ifAlias']."
    "; } - $content .= "
    "; - $graph_array['type'] = $port['graph_type']; - $graph_array['legend'] = "yes"; - $graph_array['height'] = "100"; - $graph_array['width'] = "340"; - $graph_array['to'] = $config['time']['now']; - $graph_array['from'] = $config['time']['day']; - $graph_array['id'] = $port['port_id']; - $content .= generate_graph_tag($graph_array); - if ($single_graph == 0) { - $graph_array['from'] = $config['time']['week']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['month']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['year']; - $content .= generate_graph_tag($graph_array); - } - $content .= "
    "; + if (!isset($port['graph_type'])) { + $port['graph_type'] = 'port_bits'; + } - $url = generate_port_url($port); + $class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); - if ($overlib == 0) { - return $content; - } elseif (port_permitted($port['port_id'], $port['device_id'])) { - return overlib_link($url, $text, $content, $class); - } else { - return fixifName($text); - } -} + if (!isset($port['hostname'])) { + $port = array_merge($port, device_by_id_cache($port['device_id'])); + } -function generate_port_url($port, $vars=array()) -{ - return generate_url(array('page' => 'device', 'device' => $port['device_id'], 'tab' => 'port', 'port' => $port['port_id']), $vars); -} + $content = '
    '.$port['hostname'].' - '.fixifName($port['label']).'
    '; + if ($port['ifAlias']) { + $content .= $port['ifAlias'].'
    '; + } + + $content .= "
    "; + $graph_array['type'] = $port['graph_type']; + $graph_array['legend'] = 'yes'; + $graph_array['height'] = '100'; + $graph_array['width'] = '340'; + $graph_array['to'] = $config['time']['now']; + $graph_array['from'] = $config['time']['day']; + $graph_array['id'] = $port['port_id']; + $content .= generate_graph_tag($graph_array); + if ($single_graph == 0) { + $graph_array['from'] = $config['time']['week']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['month']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['year']; + $content .= generate_graph_tag($graph_array); + } + + $content .= '
    '; + + $url = generate_port_url($port); + + if ($overlib == 0) { + return $content; + } + else if (port_permitted($port['port_id'], $port['device_id'])) { + return overlib_link($url, $text, $content, $class); + } + else { + return fixifName($text); + } + +}//end generate_port_link() + + +function generate_port_url($port, $vars=array()) { + return generate_url(array('page' => 'device', 'device' => $port['device_id'], 'tab' => 'port', 'port' => $port['port_id']), $vars); + +}//end generate_port_url() + + +function generate_peer_url($peer, $vars=array()) { + return generate_url(array('page' => 'device', 'device' => $peer['device_id'], 'tab' => 'routing', 'proto' => 'bgp'), $vars); + +}//end generate_peer_url() -function generate_peer_url($peer, $vars=array()) -{ - return generate_url(array('page' => 'device', 'device' => $peer['device_id'], 'tab' => 'routing', 'proto' => 'bgp'), $vars); -} function generate_bill_url($bill, $vars=array()) { - return generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id']), $vars); -} + return generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id']), $vars); -function generate_port_image($args) -{ - if (!$args['bg']) { $args['bg'] = "FFFFFF"; } - return ""; -} +}//end generate_bill_url() -function generate_port_thumbnail($port) -{ - global $config; - $port['graph_type'] = 'port_bits'; - $port['from'] = $config['time']['day']; - $port['to'] = $config['time']['now']; - $port['width'] = 150; - $port['height'] = 21; - return generate_port_image($port); -} -function print_port_thumbnail($args) -{ - echo(generate_port_link($args, generate_port_image($args))); -} +function generate_port_image($args) { + if (!$args['bg']) { + $args['bg'] = 'FFFFFF'; + } -function print_optionbar_start ($height = 0, $width = 0, $marginbottom = 5) -{ - echo(' + return ""; + +}//end generate_port_image() + + +function generate_port_thumbnail($port) { + global $config; + $port['graph_type'] = 'port_bits'; + $port['from'] = $config['time']['day']; + $port['to'] = $config['time']['now']; + $port['width'] = 150; + $port['height'] = 21; + return generate_port_image($port); + +}//end generate_port_thumbnail() + + +function print_port_thumbnail($args) { + echo generate_port_link($args, generate_port_image($args)); + +}//end print_port_thumbnail() + + +function print_optionbar_start($height=0, $width=0, $marginbottom=5) { + echo '
    -'); -} + '; -function print_optionbar_end() -{ - echo('
    '); -} +}//end print_optionbar_start() -function geteventicon($message) -{ - if ($message == "Device status changed to Down") { $icon = "server_connect.png"; } - if ($message == "Device status changed to Up") { $icon = "server_go.png"; } - if ($message == "Interface went down" || $message == "Interface changed state to Down") { $icon = "if-disconnect.png"; } - if ($message == "Interface went up" || $message == "Interface changed state to Up") { $icon = "if-connect.png"; } - if ($message == "Interface disabled") { $icon = "if-disable.png"; } - if ($message == "Interface enabled") { $icon = "if-enable.png"; } - if (isset($icon)) { return $icon; } else { return false; } -} -function overlibprint($text) -{ - return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\""; -} +function print_optionbar_end() { + echo ' '; -function humanmedia($media) -{ - array_preg_replace($rewrite_iftype, $media); - return $media; -} +}//end print_optionbar_end() -function humanspeed($speed) -{ - $speed = formatRates($speed); - if ($speed == "") { $speed = "-"; } - return $speed; -} -function devclass($device) -{ - if (isset($device['status']) && $device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; } - if (isset($device['ignore']) && $device['ignore'] == '1') - { - $class = "list-device-ignored"; - if (isset($device['status']) && $device['status'] == '1') { $class = "list-device-ignored-up"; } - } - if (isset($device['disabled']) && $device['disabled'] == '1') { $class = "list-device-disabled"; } - - return $class; -} - -function getlocations() -{ - $ignore_dev_location = array(); - $locations = array(); - # Fetch override locations, not through get_dev_attrib, this would be a huge number of queries - $rows = dbFetchRows("SELECT attrib_type,attrib_value,device_id FROM devices_attribs WHERE attrib_type LIKE 'override_sysLocation%' ORDER BY attrib_type"); - foreach ($rows as $row) - { - if ($row['attrib_type'] == 'override_sysLocation_bool' && $row['attrib_value'] == 1) - { - $ignore_dev_location[$row['device_id']] = 1; +function geteventicon($message) { + if ($message == 'Device status changed to Down') { + $icon = 'server_connect.png'; } - # We can do this because of the ORDER BY, "bool" will be handled before "string" - elseif ($row['attrib_type'] == 'override_sysLocation_string' && (isset($ignore_dev_location[$row['device_id']]) && $ignore_dev_location[$row['device_id']] == 1)) - { - if (!in_array($row['attrib_value'],$locations)) { $locations[] = $row['attrib_value']; } + + if ($message == 'Device status changed to Up') { + $icon = 'server_go.png'; } - } - # Fetch regular locations - if ($_SESSION['userlevel'] >= '5') - { - $rows = dbFetchRows("SELECT D.device_id,location FROM devices AS D GROUP BY location ORDER BY location"); - } else { - $rows = dbFetchRows("SELECT D.device_id,location FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? GROUP BY location ORDER BY location", array($_SESSION['user_id'])); - } - - foreach ($rows as $row) - { - # Only add it as a location if it wasn't overridden (and not already there) - if ($row['location'] != '' && !isset($ignore_dev_location[$row['device_id']])) - { - if (!in_array($row['location'],$locations)) { $locations[] = $row['location']; } + if ($message == 'Interface went down' || $message == 'Interface changed state to Down') { + $icon = 'if-disconnect.png'; } - } - sort($locations); - return $locations; -} - -function foldersize($path) -{ - $total_size = 0; - $files = scandir($path); - $total_files = 0; - - foreach ($files as $t) - { - if (is_dir(rtrim($path, '/') . '/' . $t)) - { - if ($t<>"." && $t<>"..") - { - $size = foldersize(rtrim($path, '/') . '/' . $t); - $total_size += $size; - } - } else { - $size = filesize(rtrim($path, '/') . '/' . $t); - $total_size += $size; - $total_files++; + if ($message == 'Interface went up' || $message == 'Interface changed state to Up') { + $icon = 'if-connect.png'; } - } - return array($total_size, $total_files); -} - -function generate_ap_link($args, $text = NULL, $type = NULL) -{ - global $config; - - $args = ifNameDescr($args); - if (!$text) { $text = fixIfName($args['label']); } - if ($type) { $args['graph_type'] = $type; } - if (!isset($args['graph_type'])) { $args['graph_type'] = 'port_bits'; } - - if (!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); } - - $content = "
    ".$args['text']." - " . fixifName($args['label']) . "
    "; - if ($args['ifAlias']) { $content .= $args['ifAlias']."
    "; } - $content .= "
    "; - $graph_array = array(); - $graph_array['type'] = $args['graph_type']; - $graph_array['legend'] = "yes"; - $graph_array['height'] = "100"; - $graph_array['width'] = "340"; - $graph_array['to'] = $config['time']['now']; - $graph_array['from'] = $config['time']['day']; - $graph_array['id'] = $args['accesspoint_id']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['week']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['month']; - $content .= generate_graph_tag($graph_array); - $graph_array['from'] = $config['time']['year']; - $content .= generate_graph_tag($graph_array); - $content .= "
    "; - - - $url = generate_ap_url($args); - if (port_permitted($args['interface_id'], $args['device_id'])) { - return overlib_link($url, $text, $content, $class); - } else { - return fixifName($text); - } -} - -function generate_ap_url($ap, $vars=array()) -{ - return generate_url(array('page' => 'device', 'device' => $ap['device_id'], 'tab' => 'accesspoint', 'ap' => $ap['accesspoint_id']), $vars); -} - -function report_this($message) -{ - global $config; - return '

    '.$message.' Please report this to the '.$config['project_name'].' developers.

    '; -} - -function report_this_text($message) -{ - global $config; - return $message.'\nPlease report this to the '.$config['project_name'].' developers at '.$config['project_issues'].'\n'; -} - -# Find all the files in the given directory that match the pattern -function get_matching_files($dir, $match = "/\.php$/") -{ - global $config; - - $list = array(); - if ($handle = opendir($dir)) - { - while (false !== ($file = readdir($handle))) - { - if ($file != "." && $file != ".." && preg_match($match, $file) === 1) - { - $list[] = $file; - } + if ($message == 'Interface disabled') { + $icon = 'if-disable.png'; } - closedir($handle); - } - return $list; -} -# Include all the files in the given directory that match the pattern -function include_matching_files($dir, $match = "/\.php$/") -{ - foreach (get_matching_files($dir, $match) as $file) { - include_once($file); - } -} + if ($message == 'Interface enabled') { + $icon = 'if-enable.png'; + } -function generate_pagination($count,$limit,$page,$links = 2) { - $end_page = ceil($count / $limit); - $start = (($page - $links) > 0) ? $page - $links : 1; - $end = (($page + $links) < $end_page) ? $page + $links : $end_page; - $return = '
      '; - $link_class = ($page == 1) ? "disabled" : ""; - $return .= "
    • «
    • "; - $return .= ""; + if (isset($icon)) { + return $icon; + } + else { + return false; + } - if($start > 1) { +}//end geteventicon() + + +function overlibprint($text) { + return "onmouseover=\"return overlib('".$text."');\" onmouseout=\"return nd();\""; + +}//end overlibprint() + + +function humanmedia($media) { + array_preg_replace($rewrite_iftype, $media); + return $media; + +}//end humanmedia() + + +function humanspeed($speed) { + $speed = formatRates($speed); + if ($speed == '') { + $speed = '-'; + } + + return $speed; + +}//end humanspeed() + + +function devclass($device) { + if (isset($device['status']) && $device['status'] == '0') { + $class = 'list-device-down'; + } + else { + $class = 'list-device'; + } + + if (isset($device['ignore']) && $device['ignore'] == '1') { + $class = 'list-device-ignored'; + if (isset($device['status']) && $device['status'] == '1') { + $class = 'list-device-ignored-up'; + } + } + + if (isset($device['disabled']) && $device['disabled'] == '1') { + $class = 'list-device-disabled'; + } + + return $class; + +}//end devclass() + + +function getlocations() { + $ignore_dev_location = array(); + $locations = array(); + // Fetch override locations, not through get_dev_attrib, this would be a huge number of queries + $rows = dbFetchRows("SELECT attrib_type,attrib_value,device_id FROM devices_attribs WHERE attrib_type LIKE 'override_sysLocation%' ORDER BY attrib_type"); + foreach ($rows as $row) { + if ($row['attrib_type'] == 'override_sysLocation_bool' && $row['attrib_value'] == 1) { + $ignore_dev_location[$row['device_id']] = 1; + } //end if + else if ($row['attrib_type'] == 'override_sysLocation_string' && (isset($ignore_dev_location[$row['device_id']]) && $ignore_dev_location[$row['device_id']] == 1)) { + if (!in_array($row['attrib_value'], $locations)) { + $locations[] = $row['attrib_value']; + } + } + } + + // Fetch regular locations + if ($_SESSION['userlevel'] >= '5') { + $rows = dbFetchRows('SELECT D.device_id,location FROM devices AS D GROUP BY location ORDER BY location'); + } + else { + $rows = dbFetchRows('SELECT D.device_id,location FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? GROUP BY location ORDER BY location', array($_SESSION['user_id'])); + } + + foreach ($rows as $row) { + // Only add it as a location if it wasn't overridden (and not already there) + if ($row['location'] != '' && !isset($ignore_dev_location[$row['device_id']])) { + if (!in_array($row['location'], $locations)) { + $locations[] = $row['location']; + } + } + } + + sort($locations); + return $locations; + +}//end getlocations() + + +function foldersize($path) { + $total_size = 0; + $files = scandir($path); + $total_files = 0; + + foreach ($files as $t) { + if (is_dir(rtrim($path, '/').'/'.$t)) { + if ($t <> '.' && $t <> '..') { + $size = foldersize(rtrim($path, '/').'/'.$t); + $total_size += $size; + } + } + else { + $size = filesize(rtrim($path, '/').'/'.$t); + $total_size += $size; + $total_files++; + } + } + + return array( + $total_size, + $total_files, + ); + +}//end foldersize() + + +function generate_ap_link($args, $text=null, $type=null) { + global $config; + + $args = ifNameDescr($args); + if (!$text) { + $text = fixIfName($args['label']); + } + + if ($type) { + $args['graph_type'] = $type; + } + + if (!isset($args['graph_type'])) { + $args['graph_type'] = 'port_bits'; + } + + if (!isset($args['hostname'])) { + $args = array_merge($args, device_by_id_cache($args['device_id'])); + } + + $content = '
      '.$args['text'].' - '.fixifName($args['label']).'
      '; + if ($args['ifAlias']) { + $content .= $args['ifAlias'].'
      '; + } + + $content .= "
      "; + $graph_array = array(); + $graph_array['type'] = $args['graph_type']; + $graph_array['legend'] = 'yes'; + $graph_array['height'] = '100'; + $graph_array['width'] = '340'; + $graph_array['to'] = $config['time']['now']; + $graph_array['from'] = $config['time']['day']; + $graph_array['id'] = $args['accesspoint_id']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['week']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['month']; + $content .= generate_graph_tag($graph_array); + $graph_array['from'] = $config['time']['year']; + $content .= generate_graph_tag($graph_array); + $content .= '
      '; + + $url = generate_ap_url($args); + if (port_permitted($args['interface_id'], $args['device_id'])) { + return overlib_link($url, $text, $content, $class); + } + else { + return fixifName($text); + } + +}//end generate_ap_link() + + +function generate_ap_url($ap, $vars=array()) { + return generate_url(array('page' => 'device', 'device' => $ap['device_id'], 'tab' => 'accesspoint', 'ap' => $ap['accesspoint_id']), $vars); + +}//end generate_ap_url() + + +function report_this($message) { + global $config; + return '

      '.$message.' Please report this to the '.$config['project_name'].' developers.

      '; + +}//end report_this() + + +function report_this_text($message) { + global $config; + return $message.'\nPlease report this to the '.$config['project_name'].' developers at '.$config['project_issues'].'\n'; + +}//end report_this_text() + + +// Find all the files in the given directory that match the pattern + + +function get_matching_files($dir, $match='/\.php$/') { + global $config; + + $list = array(); + if ($handle = opendir($dir)) { + while (false !== ($file = readdir($handle))) { + if ($file != '.' && $file != '..' && preg_match($match, $file) === 1) { + $list[] = $file; + } + } + + closedir($handle); + } + + return $list; + +}//end get_matching_files() + + +// Include all the files in the given directory that match the pattern + + +function include_matching_files($dir, $match='/\.php$/') { + foreach (get_matching_files($dir, $match) as $file) { + include_once $file; + } + +}//end include_matching_files() + + +function generate_pagination($count, $limit, $page, $links=2) { + $end_page = ceil($count / $limit); + $start = (($page - $links) > 0) ? ($page - $links) : 1; + $end = (($page + $links) < $end_page) ? ($page + $links) : $end_page; + $return = '
        '; + $link_class = ($page == 1) ? 'disabled' : ''; + $return .= "
      • «
      • "; + $return .= ""; + + if ($start > 1) { $return .= "
      • 1
      • "; $return .= "
      • ...
      • "; } - for($x=$start;$x<=$end;$x++) { - $link_class = ($page == $x) ? "active" : ""; - $return .= ""; + for ($x = $start; $x <= $end; $x++) { + $link_class = ($page == $x) ? 'active' : ''; + $return .= ""; } - if($end < $end_page) { + if ($end < $end_page) { $return .= "
      • ...
      • "; $return .= "
      • $end_page
      • "; } - $link_class = ($page == $end_page) ? "disabled" : ""; - $return .= ""; - $return .= ""; - $return .= '
      '; - return($return); -} + $link_class = ($page == $end_page) ? 'disabled' : ''; + $return .= ""; + $return .= ""; + $return .= '
    '; + return ($return); + +}//end generate_pagination() + function is_admin() { if ($_SESSION['userlevel'] >= '10') { $allowed = true; - } else { + } + else { $allowed = false; } + return $allowed; -} + +}//end is_admin() + function is_read() { if ($_SESSION['userlevel'] == '5') { $allowed = true; - } else { + } + else { $allowed = false; } + return $allowed; -} + +}//end is_read() + function demo_account() { print_error("You are logged in as a demo account, this page isn't accessible to you"); -} + +}//end demo_account() + function get_client_ip() { - if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $client_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } else { + } + else { $client_ip = $_SERVER['REMOTE_ADDR']; } + return $client_ip; -} + +}//end get_client_ip() + function shorten_interface_type($string) { - return str_ireplace( - array('FastEthernet','TenGigabitEthernet','GigabitEthernet','Port-Channel','Ethernet'), - array('Fa','Te','Gi','Po','Eth'), - $string - ); -} + array( + 'FastEthernet', + 'TenGigabitEthernet', + 'GigabitEthernet', + 'Port-Channel', + 'Ethernet', + ), + array( + 'Fa', + 'Te', + 'Gi', + 'Po', + 'Eth', + ), + $string + ); + +}//end shorten_interface_type() + function clean_bootgrid($string) { - - $output = str_replace(array("\r","\n"), "", $string); + $output = str_replace(array("\r", "\n"), '', $string); $output = addslashes($output); return $output; -} -//Insert new config items -function add_config_item($new_conf_name,$new_conf_value,$new_conf_type,$new_conf_desc) { +}//end clean_bootgrid() + + +// Insert new config items +function add_config_item($new_conf_name, $new_conf_value, $new_conf_type, $new_conf_desc) { if (dbInsert(array('config_name' => $new_conf_name, 'config_value' => $new_conf_value, 'config_default' => $new_conf_value, 'config_type' => $new_conf_type, 'config_desc' => $new_conf_desc, 'config_group' => '500_Custom Settings', 'config_sub_group' => '01_Custom settings', 'config_hidden' => '0', 'config_disabled' => '0'), 'config')) { $db_inserted = 1; - } else { + } + else { $db_inserted = 0; } - return($db_inserted); -} + + return ($db_inserted); + +}//end add_config_item() + function get_config_by_group($group) { $group = array($group); $items = array(); foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_group` = '?'", array($group)) as $config_item) { $val = $config_item['config_value']; - if (filter_var($val,FILTER_VALIDATE_INT)) { + if (filter_var($val, FILTER_VALIDATE_INT)) { $val = (int) $val; - } elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) { + } + else if (filter_var($val, FILTER_VALIDATE_FLOAT)) { $val = (float) $val; - } elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) { - $val =(boolean) $val; } - if ($val === TRUE) { - $config_item += array('config_checked'=>'checked'); + else if (filter_var($val, FILTER_VALIDATE_BOOLEAN)) { + $val = (boolean) $val; } + + if ($val === true) { + $config_item += array('config_checked' => 'checked'); + } + $items[$config_item['config_name']] = $config_item; } + return $items; -} + +}//end get_config_by_group() + function get_config_like_name($name) { - $name = array($name); + $name = array($name); $items = array(); foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_name` LIKE '%?%'", array($name)) as $config_item) { $items[$config_item['config_name']] = $config_item; } + return $items; -} + +}//end get_config_like_name() + function get_config_by_name($name) { - $config_item = dbFetchRow("SELECT * FROM `config` WHERE `config_name` = ?", array($name)); - return $config_item; -} + $config_item = dbFetchRow('SELECT * FROM `config` WHERE `config_name` = ?', array($name)); + return $config_item; -function set_config_name($name,$config_value) { +}//end get_config_by_name() + + +function set_config_name($name, $config_value) { return dbUpdate(array('config_value' => $config_value), 'config', '`config_name`=?', array($name)); -} + +}//end set_config_name() + function get_url() { // http://stackoverflow.com/questions/2820723/how-to-get-base-url-with-php // http://stackoverflow.com/users/184600/ma%C4%8Dek return sprintf( - "%s://%s%s", + '%s://%s%s', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI'] ); -} + +}//end get_url() + function alert_details($details) { - if( !is_array($details) ) { - $details = json_decode(gzuncompress($details),true); + if (!is_array($details)) { + $details = json_decode(gzuncompress($details), true); } - $fault_detail = ''; - foreach( $details['rule'] as $o=>$tmp_alerts ) { - $fallback = true; - $fault_detail .= "#".($o+1).": "; - if( $tmp_alerts['bill_id'] ) { - $fault_detail .= ''.$tmp_alerts['bill_name'].'; '; - $fallback = false; - } - if( $tmp_alerts['port_id'] ) { - $fault_detail .= generate_port_link($tmp_alerts).'; '; - $fallback = false; - } - if( $fallback === true ) { - foreach( $tmp_alerts as $k=>$v ) { - if (!empty($v) && $k != 'device_id' && (stristr($k,'id') || stristr($k,'desc') || stristr($k,'msg')) && substr_count($k,'_') <= 1) { - $fault_detail .= "$k => '$v', "; - } - } - $fault_detail = rtrim($fault_detail,", "); - } - $fault_detail .= "
    "; - } - return $fault_detail; -} -?> + $fault_detail = ''; + foreach ($details['rule'] as $o => $tmp_alerts) { + $fallback = true; + $fault_detail .= '#'.($o + 1).': '; + if ($tmp_alerts['bill_id']) { + $fault_detail .= ''.$tmp_alerts['bill_name'].'; '; + $fallback = false; + } + + if ($tmp_alerts['port_id']) { + $fault_detail .= generate_port_link($tmp_alerts).'; '; + $fallback = false; + } + + if ($fallback === true) { + foreach ($tmp_alerts as $k => $v) { + if (!empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1) { + $fault_detail .= "$k => '$v', "; + } + } + + $fault_detail = rtrim($fault_detail, ', '); + } + + $fault_detail .= '
    '; + }//end foreach + + return $fault_detail; + +}//end alert_details() diff --git a/html/includes/geshi/geshi/ios.php b/html/includes/geshi/geshi/ios.php index dc6ccc5083..ab343e2d58 100644 --- a/html/includes/geshi/geshi/ios.php +++ b/html/includes/geshi/geshi/ios.php @@ -1,172 +1,170 @@ 'IOS', -'COMMENT_SINGLE' => array(1 => '!'), -'CASE_KEYWORDS' => GESHI_CAPS_LOWER, -'OOLANG' => false, -'NUMBERS' => GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX, -'KEYWORDS' => array( - 1 => array( - 'no', 'shutdown' - ), -# 2 => array( -# 'router', 'interface', 'service', 'config-register', 'upgrade', 'version', 'hostname', 'boot-start-marker', 'boot', 'boot-end-marker', 'enable', 'aaa', 'clock', 'ip', -# 'logging', 'access-list', 'route-map', 'snmp-server', 'mpls', 'speed', 'media-type', 'negotiation', 'timestamps', 'prefix-list', 'network', 'mask', 'unsuppress-map', -# 'neighbor', 'remote-as', 'ebgp-multihop', 'update-source', 'description', 'peer-group', 'policy-map', 'class-map', 'class', 'match', 'access-group', 'bandwidth', 'username', -# 'password', 'send-community', 'next-hop-self', 'route-reflector-client', 'ldp', 'discovery', 'advertise-labels', 'label', 'protocol', 'login', 'debug', 'log', 'duplex', 'router-id', -# 'authentication', 'mode', 'maximum-paths', 'address-family', 'set', 'local-preference', 'community', 'trap-source', 'location', 'host', 'tacacs-server', 'session-id', -# 'flow-export', 'destination', 'source', 'in', 'out', 'permit', 'deny', 'control-plane', 'line', 'con' ,'aux', 'vty', 'access-class', 'ntp', 'server', 'end', 'source-interface', -# 'key', 'chain', 'key-string', 'redundancy', 'match-any', 'queue-limit', 'encapsulation', 'pvc', 'vbr-nrt', 'address', 'bundle-enable', 'atm', 'sonet', 'clns', 'route-cache', -# 'default-information', 'redistribute', 'log-adjacency-changes', 'metric', 'spf-interval', 'prc-interval', 'lsp-refresh-interval', 'max-lsp-lifetime', 'set-overload-bit', -# 'on-startup', 'wait-for-bgp', 'system', 'flash', 'timezone', 'subnet-zero', 'cef', 'flow-cache', 'timeout', 'active', 'domain', 'lookup', 'dhcp', 'use', 'vrf', 'hello', 'interval', -# 'priority', 'ilmi-keepalive', 'buffered', 'debugging', 'fpd', 'secret', 'accounting', 'exec', 'group', 'local', 'recurring', 'source-route', 'call', 'rsvp-sync', 'scripting', -# 'mtu', 'passive-interface', 'area' , 'distribute-list', 'metric-style', 'is-type', 'originate', 'activate', 'both', 'auto-summary', 'synchronization', 'aggregate-address', 'le', 'ge', -# 'bgp-community', 'route', 'exit-address-family', 'standard', 'file', 'verify', 'domain-name', 'domain-lookup', 'route-target', 'export', 'import', 'map', 'rd', 'mfib', 'vtp', 'mls', -# 'hardware-switching', 'replication-mode', 'ingress', 'flow', 'error', 'action', 'slb', 'purge', 'share-global', 'routing', 'traffic-eng', 'tunnels', 'propagate-ttl', 'switchport', 'vlan', -# 'portfast', 'counters', 'max', 'age', 'ethernet', 'evc', 'uni', 'count', 'oam', 'lmi', 'gmt', 'netflow', 'pseudowire-class', 'spanning-tree', 'name', 'circuit-type' -# ), -# 3 => array( -# 'isis', 'ospf', 'eigrp', 'rip', 'igrp', 'bgp', 'ipv4', 'unicast', 'multicast', 'ipv6', 'connected', 'static', 'subnets', 'tcl' -# ), -# 4 => array( -# 'point-to-point', 'aal5snap', 'rj45', 'auto', 'full', 'half', 'precedence', 'percent', 'datetime', 'msec', 'locatime', 'summer-time', 'md5', 'wait-for-bgp', 'wide', -# 'level-1', 'level-2', 'log-neighbor-changes', 'directed-request', 'password-encryption', 'common', 'origin-as', 'bgp-nexthop', 'random-detect', 'localtime', 'sso', 'stm-1', -# 'dot1q', 'isl', 'new-model', 'always', 'summary-only', 'freeze', 'global', 'forwarded', 'access', 'trunk', 'edge', 'transparent' -# ), -), - -'REGEXPS' => array ( - 1 => array( - GESHI_SEARCH => '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', - GESHI_REPLACE => '\\1', - GESHI_BEFORE => '', - ), - 2 => array( - GESHI_SEARCH => '(255\.\d{1,3}\.\d{1,3}\.\d{1,3})', - GESHI_REPLACE => '\\1', - GESHI_BEFORE => '', - ), - 3 => array( - GESHI_SEARCH => '(source|interface|update-source|router-id) ([A-Za-z0-9\/\:\-\.]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 4 => array( - GESHI_SEARCH => '(neighbor) ([\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}]+|[a-zA-Z0-9\-\_]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 5 => array( - GESHI_SEARCH => '(distribute-map|access-group|policy-map|class-map\ match-any|ip\ access-list\ extended|match\ community|community-list\ standard|community-list\ expanded|ip\ access-list\ standard|router\ bgp|remote-as|key\ chain|service-policy\ input|service-policy\ output|class|login\ authentication|authentication\ key-chain|username|import\ map|export\ map|domain-name|hostname|route-map|access-class|ip\ vrf\ forwarding|ip\ vrf|vtp\ domain|name|pseudowire-class|pw-class|prefix-list|vrf) ([A-Za-z0-9\-\_\.]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 6 => array( - GESHI_SEARCH => '(password|key-string|key) ([0-9]) (.+)', - GESHI_REPLACE => '\\2 \\3', - GESHI_BEFORE => '\\1 ', - ), - 7 => array( - GESHI_SEARCH => '(enable) ([a-z]+) ([0-9]) (.+)', - GESHI_REPLACE => '\\3 \\4', - GESHI_BEFORE => '\\1 \\2 ', - ), - 8 => array( - GESHI_SEARCH => '(description|location|contact|remark) (.+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 9 => array( - GESHI_SEARCH => '([0-9\.\_\*]+\:[0-9\.\_\*]+)', - GESHI_REPLACE => '\\1', - ), - 10 => array( - GESHI_SEARCH => '(boot) ([a-z]+) (.+)', - GESHI_REPLACE => '\\3', - GESHI_BEFORE => '\\1 \\2 ' - ), - 11 => array( - GESHI_SEARCH => '(net) ([0-9a-z\.]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' - ), - 12 => array( - GESHI_SEARCH => '(access-list|RO|RW) ([0-9]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' - ), - 13 => array( - GESHI_SEARCH => '(vlan) ([0-9]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' - ), - 14 => array( - GESHI_SEARCH => '(encapsulation|speed|duplex|mtu|metric|media-type|negotiation|transport\ input|bgp-community|set\ as-path\ prepend|maximum-prefix|version|local-preference|continue|redistribute|cluster-id|vtp\ mode|label\ protocol|spanning-tree\ mode) (.+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' +$language_data = array( + 'LANG_NAME' => 'IOS', + 'COMMENT_SINGLE' => array(1 => '!'), + 'CASE_KEYWORDS' => GESHI_CAPS_LOWER, + 'OOLANG' => false, + 'NUMBERS' => GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX, + 'KEYWORDS' => array( + 1 => array( + 'no', + 'shutdown', + ), + // 2 => array( + // 'router', 'interface', 'service', 'config-register', 'upgrade', 'version', 'hostname', 'boot-start-marker', 'boot', 'boot-end-marker', 'enable', 'aaa', 'clock', 'ip', + // 'logging', 'access-list', 'route-map', 'snmp-server', 'mpls', 'speed', 'media-type', 'negotiation', 'timestamps', 'prefix-list', 'network', 'mask', 'unsuppress-map', + // 'neighbor', 'remote-as', 'ebgp-multihop', 'update-source', 'description', 'peer-group', 'policy-map', 'class-map', 'class', 'match', 'access-group', 'bandwidth', 'username', + // 'password', 'send-community', 'next-hop-self', 'route-reflector-client', 'ldp', 'discovery', 'advertise-labels', 'label', 'protocol', 'login', 'debug', 'log', 'duplex', 'router-id', + // 'authentication', 'mode', 'maximum-paths', 'address-family', 'set', 'local-preference', 'community', 'trap-source', 'location', 'host', 'tacacs-server', 'session-id', + // 'flow-export', 'destination', 'source', 'in', 'out', 'permit', 'deny', 'control-plane', 'line', 'con' ,'aux', 'vty', 'access-class', 'ntp', 'server', 'end', 'source-interface', + // 'key', 'chain', 'key-string', 'redundancy', 'match-any', 'queue-limit', 'encapsulation', 'pvc', 'vbr-nrt', 'address', 'bundle-enable', 'atm', 'sonet', 'clns', 'route-cache', + // 'default-information', 'redistribute', 'log-adjacency-changes', 'metric', 'spf-interval', 'prc-interval', 'lsp-refresh-interval', 'max-lsp-lifetime', 'set-overload-bit', + // 'on-startup', 'wait-for-bgp', 'system', 'flash', 'timezone', 'subnet-zero', 'cef', 'flow-cache', 'timeout', 'active', 'domain', 'lookup', 'dhcp', 'use', 'vrf', 'hello', 'interval', + // 'priority', 'ilmi-keepalive', 'buffered', 'debugging', 'fpd', 'secret', 'accounting', 'exec', 'group', 'local', 'recurring', 'source-route', 'call', 'rsvp-sync', 'scripting', + // 'mtu', 'passive-interface', 'area' , 'distribute-list', 'metric-style', 'is-type', 'originate', 'activate', 'both', 'auto-summary', 'synchronization', 'aggregate-address', 'le', 'ge', + // 'bgp-community', 'route', 'exit-address-family', 'standard', 'file', 'verify', 'domain-name', 'domain-lookup', 'route-target', 'export', 'import', 'map', 'rd', 'mfib', 'vtp', 'mls', + // 'hardware-switching', 'replication-mode', 'ingress', 'flow', 'error', 'action', 'slb', 'purge', 'share-global', 'routing', 'traffic-eng', 'tunnels', 'propagate-ttl', 'switchport', 'vlan', + // 'portfast', 'counters', 'max', 'age', 'ethernet', 'evc', 'uni', 'count', 'oam', 'lmi', 'gmt', 'netflow', 'pseudowire-class', 'spanning-tree', 'name', 'circuit-type' + // ), + // 3 => array( + // 'isis', 'ospf', 'eigrp', 'rip', 'igrp', 'bgp', 'ipv4', 'unicast', 'multicast', 'ipv6', 'connected', 'static', 'subnets', 'tcl' + // ), + // 4 => array( + // 'point-to-point', 'aal5snap', 'rj45', 'auto', 'full', 'half', 'precedence', 'percent', 'datetime', 'msec', 'locatime', 'summer-time', 'md5', 'wait-for-bgp', 'wide', + // 'level-1', 'level-2', 'log-neighbor-changes', 'directed-request', 'password-encryption', 'common', 'origin-as', 'bgp-nexthop', 'random-detect', 'localtime', 'sso', 'stm-1', + // 'dot1q', 'isl', 'new-model', 'always', 'summary-only', 'freeze', 'global', 'forwarded', 'access', 'trunk', 'edge', 'transparent' + // ), ), -), - -'STYLES' => array( - 'REGEXPS' => array( - 0 => 'color: #ff0000;', - 1 => 'color: #0000cc;', # x.x.x.x - 2 => 'color: #000099; font-style: italic', # 255.x.x.x - 3 => 'color: #000000; font-weight: bold; font-style: italic;', # interface xxx - 4 => 'color: #ff0000;', # neighbor x.x.x.x - 5 => 'color: #000099;', # variable names - 6 => 'color: #cc0000;', - 7 => 'color: #cc0000;', # passwords - 8 => 'color: #555555;', # description - 9 => 'color: #990099;', # communities - 10 => 'color: #cc0000; font-style: italic;', # no/shut - 11 => 'color: #000099;', # net numbers - 12 => 'color: #000099;', # acls - 13 => 'color: #000099;', # acls - 14 => 'color: #990099;', # warnings - ), - 'KEYWORDS' => array( - 1 => 'color: #cc0000; font-weight: bold;', # no/shut - 2 => 'color: #000000;', # commands - 3 => 'color: #000000; font-weight: bold;', # proto/service - 4 => 'color: #000000;', # options - 5 => 'color: #ff0000;' - ), - 'COMMENTS' => array( - 1 => 'color: #808080; font-style: italic;' - ), - 'ESCAPE_CHAR' => array( - 0 => 'color: #000099; font-weight: bold;' - ), - 'BRACKETS' => array( - 0 => 'color: #66cc66;' - ), - 'STRINGS' => array( - 0 => 'color: #ff0000;' - ), - 'NUMBERS' => array( - 0 => 'color: #cc0000;' - ), - 'METHODS' => array( - 0 => 'color: #006600;' - ), - 'SYMBOLS' => array( - 0 => 'color: #66cc66;' - ), - 'SCRIPT' => array( - 0 => '', - 1 => '', - 2 => '', - 3 => '' - ) - -) + 'REGEXPS' => array( + 1 => array( + GESHI_SEARCH => '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', + GESHI_REPLACE => '\\1', + GESHI_BEFORE => '', + ), + 2 => array( + GESHI_SEARCH => '(255\.\d{1,3}\.\d{1,3}\.\d{1,3})', + GESHI_REPLACE => '\\1', + GESHI_BEFORE => '', + ), + 3 => array( + GESHI_SEARCH => '(source|interface|update-source|router-id) ([A-Za-z0-9\/\:\-\.]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 4 => array( + GESHI_SEARCH => '(neighbor) ([\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}]+|[a-zA-Z0-9\-\_]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 5 => array( + GESHI_SEARCH => '(distribute-map|access-group|policy-map|class-map\ match-any|ip\ access-list\ extended|match\ community|community-list\ standard|community-list\ expanded|ip\ access-list\ standard|router\ bgp|remote-as|key\ chain|service-policy\ input|service-policy\ output|class|login\ authentication|authentication\ key-chain|username|import\ map|export\ map|domain-name|hostname|route-map|access-class|ip\ vrf\ forwarding|ip\ vrf|vtp\ domain|name|pseudowire-class|pw-class|prefix-list|vrf) ([A-Za-z0-9\-\_\.]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 6 => array( + GESHI_SEARCH => '(password|key-string|key) ([0-9]) (.+)', + GESHI_REPLACE => '\\2 \\3', + GESHI_BEFORE => '\\1 ', + ), + 7 => array( + GESHI_SEARCH => '(enable) ([a-z]+) ([0-9]) (.+)', + GESHI_REPLACE => '\\3 \\4', + GESHI_BEFORE => '\\1 \\2 ', + ), + 8 => array( + GESHI_SEARCH => '(description|location|contact|remark) (.+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 9 => array( + GESHI_SEARCH => '([0-9\.\_\*]+\:[0-9\.\_\*]+)', + GESHI_REPLACE => '\\1', + ), + 10 => array( + GESHI_SEARCH => '(boot) ([a-z]+) (.+)', + GESHI_REPLACE => '\\3', + GESHI_BEFORE => '\\1 \\2 ', + ), + 11 => array( + GESHI_SEARCH => '(net) ([0-9a-z\.]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 12 => array( + GESHI_SEARCH => '(access-list|RO|RW) ([0-9]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 13 => array( + GESHI_SEARCH => '(vlan) ([0-9]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 14 => array( + GESHI_SEARCH => '(encapsulation|speed|duplex|mtu|metric|media-type|negotiation|transport\ input|bgp-community|set\ as-path\ prepend|maximum-prefix|version|local-preference|continue|redistribute|cluster-id|vtp\ mode|label\ protocol|spanning-tree\ mode) (.+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + ), + 'STYLES' => array( + 'REGEXPS' => array( + 0 => 'color: #ff0000;', + 1 => 'color: #0000cc;', + // x.x.x.x + 2 => 'color: #000099; font-style: italic', + // 255.x.x.x + 3 => 'color: #000000; font-weight: bold; font-style: italic;', + // interface xxx + 4 => 'color: #ff0000;', + // neighbor x.x.x.x + 5 => 'color: #000099;', + // variable names + 6 => 'color: #cc0000;', + 7 => 'color: #cc0000;', + // passwords + 8 => 'color: #555555;', + // description + 9 => 'color: #990099;', + // communities + 10 => 'color: #cc0000; font-style: italic;', + // no/shut + 11 => 'color: #000099;', + // net numbers + 12 => 'color: #000099;', + // acls + 13 => 'color: #000099;', + // acls + 14 => 'color: #990099;', + // warnings + ), + 'KEYWORDS' => array( + 1 => 'color: #cc0000; font-weight: bold;', + // no/shut + 2 => 'color: #000000;', + // commands + 3 => 'color: #000000; font-weight: bold;', + // proto/service + 4 => 'color: #000000;', + // options + 5 => 'color: #ff0000;', + ), + 'COMMENTS' => array(1 => 'color: #808080; font-style: italic;'), + 'ESCAPE_CHAR' => array(0 => 'color: #000099; font-weight: bold;'), + 'BRACKETS' => array(0 => 'color: #66cc66;'), + 'STRINGS' => array(0 => 'color: #ff0000;'), + 'NUMBERS' => array(0 => 'color: #cc0000;'), + 'METHODS' => array(0 => 'color: #006600;'), + 'SYMBOLS' => array(0 => 'color: #66cc66;'), + 'SCRIPT' => array( + 0 => '', + 1 => '', + 2 => '', + 3 => '', + ), + ), ); - -?> diff --git a/html/includes/graphs/accesspoints/channel.inc.php b/html/includes/graphs/accesspoints/channel.inc.php index 03b0dd24c0..d68824fa16 100644 --- a/html/includes/graphs/accesspoints/channel.inc.php +++ b/html/includes/graphs/accesspoints/channel.inc.php @@ -1,25 +1,21 @@ diff --git a/html/includes/graphs/application/apache_bits.inc.php b/html/includes/graphs/application/apache_bits.inc.php index fabf9453b4..b6767533e1 100644 --- a/html/includes/graphs/application/apache_bits.inc.php +++ b/html/includes/graphs/application/apache_bits.inc.php @@ -2,27 +2,24 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$apache_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-apache-".$app['app_id'].".rrd"; +$apache_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/app-apache-'.$app['app_id'].'.rrd'; -if (is_file($apache_rrd)) -{ - $rrd_filename = $apache_rrd; +if (is_file($apache_rrd)) { + $rrd_filename = $apache_rrd; } -$ds = "kbyte"; +$ds = 'kbyte'; -$colour_area = "CDEB8B"; -$colour_line = "006600"; +$colour_area = 'CDEB8B'; +$colour_line = '006600'; -$colour_area_max = "FFEE99"; +$colour_area_max = 'FFEE99'; -$graph_max = 1; +$graph_max = 1; $multiplier = 8; -$unit_text = "Kbps"; +$unit_text = 'Kbps'; -include("includes/graphs/generic_simplex.inc.php"); - -?> +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/apache_cpu.inc.php b/html/includes/graphs/application/apache_cpu.inc.php index bb49d3f639..e136a6ed15 100644 --- a/html/includes/graphs/application/apache_cpu.inc.php +++ b/html/includes/graphs/application/apache_cpu.inc.php @@ -2,26 +2,23 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$apache_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-apache-".$app['app_id'].".rrd"; +$apache_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/app-apache-'.$app['app_id'].'.rrd'; -if (is_file($apache_rrd)) -{ - $rrd_filename = $apache_rrd; +if (is_file($apache_rrd)) { + $rrd_filename = $apache_rrd; } -$ds = "cpu"; +$ds = 'cpu'; -$colour_area = "F0E68C"; -$colour_line = "FF4500"; +$colour_area = 'F0E68C'; +$colour_line = 'FF4500'; -$colour_area_max = "FFEE99"; +$colour_area_max = 'FFEE99'; $graph_max = 1; -$unit_text = "% Used"; +$unit_text = '% Used'; -include("includes/graphs/generic_simplex.inc.php"); - -?> +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/apache_hits.inc.php b/html/includes/graphs/application/apache_hits.inc.php index 0f0d4832cc..5e1a74cea9 100644 --- a/html/includes/graphs/application/apache_hits.inc.php +++ b/html/includes/graphs/application/apache_hits.inc.php @@ -2,26 +2,23 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$apache_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-apache-".$app['app_id'].".rrd"; +$apache_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/app-apache-'.$app['app_id'].'.rrd'; -if (is_file($apache_rrd)) -{ - $rrd_filename = $apache_rrd; +if (is_file($apache_rrd)) { + $rrd_filename = $apache_rrd; } -$ds = "access"; +$ds = 'access'; -$colour_area = "B0C4DE"; -$colour_line = "191970"; +$colour_area = 'B0C4DE'; +$colour_line = '191970'; -$colour_area_max = "FFEE99"; +$colour_area_max = 'FFEE99'; $graph_max = 1; -$unit_text = "Hits/sec"; +$unit_text = 'Hits/sec'; -include("includes/graphs/generic_simplex.inc.php"); - -?> +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/apache_scoreboard.inc.php b/html/includes/graphs/application/apache_scoreboard.inc.php index bf9237f4a0..fe216efe72 100644 --- a/html/includes/graphs/application/apache_scoreboard.inc.php +++ b/html/includes/graphs/application/apache_scoreboard.inc.php @@ -2,39 +2,69 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-apache-".$app['app_id'].".rrd"; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-apache-'.$app['app_id'].'.rrd'; -$array = array('sb_reading' => array('descr' => 'Reading', 'colour' => '750F7DFF'), - 'sb_writing' => array('descr' => 'Writing', 'colour' => '00FF00FF'), - 'sb_wait' => array('descr' => 'Waiting', 'colour' => '4444FFFF'), - 'sb_start' => array('descr' => 'Starting', 'colour' => '157419FF'), - 'sb_keepalive' => array('descr' => 'Keepalive', 'colour' => 'FF0000FF'), - 'sb_dns' => array('descr' => 'DNS', 'colour' => '6DC8FEFF'), - 'sb_closing' => array('descr' => 'Closing', 'colour' => 'FFAB00FF'), - 'sb_logging' => array('descr' => 'Logging', 'colour' => 'FFFF00FF'), - 'sb_graceful' => array('descr' => 'Graceful', 'colour' => 'FF5576FF'), - 'sb_idle' => array('descr' => 'Idle', 'colour' => 'FF4105FF'), +$array = array( + 'sb_reading' => array( + 'descr' => 'Reading', + 'colour' => '750F7DFF', + ), + 'sb_writing' => array( + 'descr' => 'Writing', + 'colour' => '00FF00FF', + ), + 'sb_wait' => array( + 'descr' => 'Waiting', + 'colour' => '4444FFFF', + ), + 'sb_start' => array( + 'descr' => 'Starting', + 'colour' => '157419FF', + ), + 'sb_keepalive' => array( + 'descr' => 'Keepalive', + 'colour' => 'FF0000FF', + ), + 'sb_dns' => array( + 'descr' => 'DNS', + 'colour' => '6DC8FEFF', + ), + 'sb_closing' => array( + 'descr' => 'Closing', + 'colour' => 'FFAB00FF', + ), + 'sb_logging' => array( + 'descr' => 'Logging', + 'colour' => 'FFFF00FF', + ), + 'sb_graceful' => array( + 'descr' => 'Graceful', + 'colour' => 'FF5576FF', + ), + 'sb_idle' => array( + 'descr' => 'Idle', + 'colour' => 'FF4105FF', + ), ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = $vars['descr']; - $rrd_list[$i]['ds'] = $ds; - $rrd_list[$i]['colour'] = $vars['colour']; - $i++; - } -} else { echo("file missing: $file"); } +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $vars['descr']; + $rrd_list[$i]['ds'] = $ds; + $rrd_list[$i]['colour'] = $vars['colour']; + $i++; + } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "Workers"; +$unit_text = 'Workers'; -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); - -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/bind_queries.inc.php b/html/includes/graphs/application/bind_queries.inc.php index 985e720e75..3df1abf45a 100644 --- a/html/includes/graphs/application/bind_queries.inc.php +++ b/html/includes/graphs/application/bind_queries.inc.php @@ -1,19 +1,21 @@ +/* + * Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * Bind9 Query Graph * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -22,29 +24,40 @@ * @subpackage Graphs */ -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; $i = 0; $scale_min = 0; $nototal = 1; -$unit_text = "Query/sec"; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-bind-".$app['app_id'].".rrd"; -$array = array( 'any', 'a', 'aaaa', 'cname', 'mx', 'ns', 'ptr', 'soa', 'srv', 'spf' ); -$colours = "merged"; +$unit_text = 'Query/sec'; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-bind-'.$app['app_id'].'.rrd'; +$array = array( + 'any', + 'a', + 'aaaa', + 'cname', + 'mx', + 'ns', + 'ptr', + 'soa', + 'srv', + 'spf', +); +$colours = 'merged'; $rrd_list = array(); $config['graph_colours']['merged'] = array_merge($config['graph_colours']['greens'], $config['graph_colours']['blues']); -if( is_file($rrd_filename) ) { - foreach( $array as $ds ) { - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = strtoupper($ds); - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { - echo "file missing: $file"; +if (is_file($rrd_filename)) { + foreach ($array as $ds) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = strtoupper($ds); + $rrd_list[$i]['ds'] = $ds; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/drbd_disk_bits.inc.php b/html/includes/graphs/application/drbd_disk_bits.inc.php index 767246ce8b..d3458c72a6 100644 --- a/html/includes/graphs/application/drbd_disk_bits.inc.php +++ b/html/includes/graphs/application/drbd_disk_bits.inc.php @@ -2,21 +2,18 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$drbd_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$app['app_instance'].".rrd"; +$drbd_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/app-drbd-'.$app['app_instance'].'.rrd'; -if (is_file($drbd_rrd)) -{ - $rrd_filename = $drbd_rrd; +if (is_file($drbd_rrd)) { + $rrd_filename = $drbd_rrd; } -$ds_in = "dr"; -$ds_out = "dw"; +$ds_in = 'dr'; +$ds_out = 'dw'; -$multiplier = "8"; -$format = "bytes"; +$multiplier = '8'; +$format = 'bytes'; -include("includes/graphs/generic_data.inc.php"); - -?> +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/application/drbd_network_bits.inc.php b/html/includes/graphs/application/drbd_network_bits.inc.php index 37c1d9db04..d20c1b3043 100644 --- a/html/includes/graphs/application/drbd_network_bits.inc.php +++ b/html/includes/graphs/application/drbd_network_bits.inc.php @@ -2,20 +2,17 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$drbd_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$app['app_instance'].".rrd"; +$drbd_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/app-drbd-'.$app['app_instance'].'.rrd'; -if (is_file($drbd_rrd)) -{ - $rrd_filename = $drbd_rrd; +if (is_file($drbd_rrd)) { + $rrd_filename = $drbd_rrd; } -$ds_in = "nr"; -$ds_out = "ns"; +$ds_in = 'nr'; +$ds_out = 'ns'; -$multiplier = "8"; +$multiplier = '8'; -include("includes/graphs/generic_data.inc.php"); - -?> +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/application/drbd_unsynced.inc.php b/html/includes/graphs/application/drbd_unsynced.inc.php index 03293e1363..f2a551ba8c 100644 --- a/html/includes/graphs/application/drbd_unsynced.inc.php +++ b/html/includes/graphs/application/drbd_unsynced.inc.php @@ -2,27 +2,24 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$drbd_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$app['app_instance'].".rrd"; +$drbd_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/app-drbd-'.$app['app_instance'].'.rrd'; -if (is_file($drbd_rrd)) -{ - $rrd_filename = $drbd_rrd; +if (is_file($drbd_rrd)) { + $rrd_filename = $drbd_rrd; } -$ds = "oos"; +$ds = 'oos'; -$colour_area = "CDEB8B"; -$colour_line = "006600"; +$colour_area = 'CDEB8B'; +$colour_line = '006600'; -$colour_area_max = "FFEE99"; +$colour_area_max = 'FFEE99'; -$graph_max = 1; +$graph_max = 1; $multiplier = 8; -$unit_text = "Bytes"; +$unit_text = 'Bytes'; -include("includes/graphs/generic_simplex.inc.php"); - -?> +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/memcached_bits.inc.php b/html/includes/graphs/application/memcached_bits.inc.php index 2fadf3e16e..c377e301b4 100644 --- a/html/includes/graphs/application/memcached_bits.inc.php +++ b/html/includes/graphs/application/memcached_bits.inc.php @@ -1,13 +1,11 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/application/mysql_command_counters.inc.php b/html/includes/graphs/application/mysql_command_counters.inc.php index 5ca5d7d685..19182d0a6d 100644 --- a/html/includes/graphs/application/mysql_command_counters.inc.php +++ b/html/includes/graphs/application/mysql_command_counters.inc.php @@ -5,43 +5,43 @@ require 'includes/graphs/common.inc.php'; $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-mysql-'.$app['app_id'].'.rrd'; $array = array( - 'CDe' => array( - 'descr' => 'Delete', - 'colour' => '22FF22', - ), - 'CIt' => array( - 'descr' => 'Insert', - 'colour' => '0022FF', - ), - 'CISt' => array( - 'descr' => 'Insert Select', - 'colour' => 'FF0000', - ), - 'CLd' => array( - 'descr' => 'Load Data', - 'colour' => '00AAAA', - ), - 'CRe' => array( - 'descr' => 'Replace', - 'colour' => 'FF00FF', - ), - 'CRSt' => array( - 'descr' => 'Replace Select', - 'colour' => 'FFA500', - ), - 'CSt' => array( - 'descr' => 'Select', - 'colour' => 'CC0000', - ), - 'CUe' => array( - 'descr' => 'Update', - 'colour' => '0000CC', - ), - 'CUMi' => array( - 'descr' => 'Update Multiple', - 'colour' => '0080C0', - ), - ); + 'CDe' => array( + 'descr' => 'Delete', + 'colour' => '22FF22', + ), + 'CIt' => array( + 'descr' => 'Insert', + 'colour' => '0022FF', + ), + 'CISt' => array( + 'descr' => 'Insert Select', + 'colour' => 'FF0000', + ), + 'CLd' => array( + 'descr' => 'Load Data', + 'colour' => '00AAAA', + ), + 'CRe' => array( + 'descr' => 'Replace', + 'colour' => 'FF00FF', + ), + 'CRSt' => array( + 'descr' => 'Replace Select', + 'colour' => 'FFA500', + ), + 'CSt' => array( + 'descr' => 'Select', + 'colour' => 'CC0000', + ), + 'CUe' => array( + 'descr' => 'Update', + 'colour' => '0000CC', + ), + 'CUMi' => array( + 'descr' => 'Update Multiple', + 'colour' => '0080C0', + ), +); $i = 0; if (is_file($rrd_filename)) { @@ -52,7 +52,8 @@ if (is_file($rrd_filename)) { // $rrd_list[$i]['colour'] = $vars['colour']; $i++; } -} else { +} +else { echo "file missing: $file"; } diff --git a/html/includes/graphs/application/ntpdserver_packets.inc.php b/html/includes/graphs/application/ntpdserver_packets.inc.php index 6eee73cabc..b3d906aa3c 100644 --- a/html/includes/graphs/application/ntpdserver_packets.inc.php +++ b/html/includes/graphs/application/ntpdserver_packets.inc.php @@ -7,15 +7,15 @@ $nototal = (($width < 224) ? 1 : 0); $unit_text = 'Packets'; $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-ntpdserver-'.$app['app_id'].'.rrd'; $array = array( - 'packets_drop' => array( - 'descr' => 'Dropped', - 'colour' => '880000FF', - ), - 'packets_ignore' => array( - 'descr' => 'Ignored', - 'colour' => 'FF8800FF', - ), - ); + 'packets_drop' => array( + 'descr' => 'Dropped', + 'colour' => '880000FF', + ), + 'packets_ignore' => array( + 'descr' => 'Ignored', + 'colour' => 'FF8800FF', + ), +); $i = 0; diff --git a/html/includes/graphs/application/shoutcast_multi_bits.inc.php b/html/includes/graphs/application/shoutcast_multi_bits.inc.php index 69b7b482b1..d526863aea 100644 --- a/html/includes/graphs/application/shoutcast_multi_bits.inc.php +++ b/html/includes/graphs/application/shoutcast_multi_bits.inc.php @@ -25,8 +25,7 @@ $files = array(); $i = 0; if ($handle = opendir($rrddir)) { - while (false !== ($file = readdir($handle))) - { + while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { if (eregi('app-shoutcast-'.$app['app_id'], $file)) { array_push($files, $file); diff --git a/html/includes/graphs/application/shoutcast_multi_stats.inc.php b/html/includes/graphs/application/shoutcast_multi_stats.inc.php index 3d901e14b4..ea01630bf1 100644 --- a/html/includes/graphs/application/shoutcast_multi_stats.inc.php +++ b/html/includes/graphs/application/shoutcast_multi_stats.inc.php @@ -13,8 +13,7 @@ $i = 0; $x = 0; if ($handle = opendir($rrddir)) { - while (false !== ($file = readdir($handle))) - { + while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { if (eregi('app-shoutcast-'.$app['app_id'], $file)) { array_push($files, $file); diff --git a/html/includes/graphs/application/tinydns_dnssec.inc.php b/html/includes/graphs/application/tinydns_dnssec.inc.php index 14b4c8136d..a3a0bf110d 100644 --- a/html/includes/graphs/application/tinydns_dnssec.inc.php +++ b/html/includes/graphs/application/tinydns_dnssec.inc.php @@ -1,19 +1,21 @@ +/* + * Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * TinyDNS DNSSec Graph * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -22,28 +24,31 @@ * @subpackage Graphs */ -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; $i = 0; $scale_min = 0; $nototal = 1; -$unit_text = "Query/sec"; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-tinydns-".$app['app_id'].".rrd"; -//$array = explode(":","hinfo:rp:sig:key:axfr:total"); -$array = array( "key", "sig" ); -$colours = "mixed"; -$rrd_list = array(); +$unit_text = 'Query/sec'; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-tinydns-'.$app['app_id'].'.rrd'; +// $array = explode(":","hinfo:rp:sig:key:axfr:total"); +$array = array( + 'key', + 'sig', +); +$colours = 'mixed'; +$rrd_list = array(); -if( is_file($rrd_filename) ) { - foreach( $array as $ds ) { - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = strtoupper($ds); - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { - echo "file missing: $file"; +if (is_file($rrd_filename)) { + foreach ($array as $ds) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = strtoupper($ds); + $rrd_list[$i]['ds'] = $ds; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/tinydns_errors.inc.php b/html/includes/graphs/application/tinydns_errors.inc.php index 6cec421c91..5673c635e1 100644 --- a/html/includes/graphs/application/tinydns_errors.inc.php +++ b/html/includes/graphs/application/tinydns_errors.inc.php @@ -1,19 +1,21 @@ +/* + Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * TinyDNS Error Graph * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -22,27 +24,32 @@ * @subpackage Graphs */ -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; $i = 0; $scale_min = 0; $nototal = 1; -$unit_text = "Query/sec"; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-tinydns-".$app['app_id'].".rrd"; -$array = array( "notauth", "notimpl", "badclass", "noquery" ); -$colours = "oranges"; +$unit_text = 'Query/sec'; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-tinydns-'.$app['app_id'].'.rrd'; +$array = array( + 'notauth', + 'notimpl', + 'badclass', + 'noquery', +); +$colours = 'oranges'; $rrd_list = array(); -if( is_file($rrd_filename) ) { - foreach( $array as $ds ) { - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = strtoupper($ds); - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { - echo "file missing: $file"; +if (is_file($rrd_filename)) { + foreach ($array as $ds) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = strtoupper($ds); + $rrd_list[$i]['ds'] = $ds; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/tinydns_other.inc.php b/html/includes/graphs/application/tinydns_other.inc.php index b7c08f88e3..3d4178994a 100644 --- a/html/includes/graphs/application/tinydns_other.inc.php +++ b/html/includes/graphs/application/tinydns_other.inc.php @@ -1,19 +1,21 @@ +/* + Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * TinyDNS Other Graph * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -22,27 +24,32 @@ * @subpackage Graphs */ -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; $i = 0; $scale_min = 0; $nototal = 1; -$unit_text = "Query/sec"; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-tinydns-".$app['app_id'].".rrd"; -$array = array( "other", "hinfo", "rp", "axfr" ); -$colours = "mixed"; +$unit_text = 'Query/sec'; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-tinydns-'.$app['app_id'].'.rrd'; +$array = array( + 'other', + 'hinfo', + 'rp', + 'axfr', +); +$colours = 'mixed'; $rrd_list = array(); -if( is_file($rrd_filename) ) { - foreach( $array as $ds ) { - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = strtoupper($ds); - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { - echo "file missing: $file"; +if (is_file($rrd_filename)) { + foreach ($array as $ds) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = strtoupper($ds); + $rrd_list[$i]['ds'] = $ds; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/tinydns_queries.inc.php b/html/includes/graphs/application/tinydns_queries.inc.php index 2d2b03ebee..b35a32bc06 100644 --- a/html/includes/graphs/application/tinydns_queries.inc.php +++ b/html/includes/graphs/application/tinydns_queries.inc.php @@ -1,19 +1,21 @@ +/* + * Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * TinyDNS Query Graph * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -22,30 +24,40 @@ * @subpackage Graphs */ -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; $i = 0; $scale_min = 0; $nototal = 1; -$unit_text = "Query/sec"; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-tinydns-".$app['app_id'].".rrd"; -//$array = explode(":","hinfo:rp:sig:key:axfr:total"); -$array = array( "any", "a", "aaaa", "cname", "mx", "ns", "ptr", "soa", "txt" ); -$colours = "merged"; -$rrd_list = array(); +$unit_text = 'Query/sec'; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-tinydns-'.$app['app_id'].'.rrd'; +// $array = explode(":","hinfo:rp:sig:key:axfr:total"); +$array = array( + 'any', + 'a', + 'aaaa', + 'cname', + 'mx', + 'ns', + 'ptr', + 'soa', + 'txt', +); +$colours = 'merged'; +$rrd_list = array(); $config['graph_colours']['merged'] = array_merge($config['graph_colours']['greens'], $config['graph_colours']['blues']); -if( is_file($rrd_filename) ) { - foreach( $array as $ds ) { - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = strtoupper($ds); - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { - echo "file missing: $file"; +if (is_file($rrd_filename)) { + foreach ($array as $ds) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = strtoupper($ds); + $rrd_list[$i]['ds'] = $ds; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/common.inc.php b/html/includes/graphs/common.inc.php index a46b353841..9dbc97b805 100644 --- a/html/includes/graphs/common.inc.php +++ b/html/includes/graphs/common.inc.php @@ -1,34 +1,105 @@ = "5" || $auth) -{ - $id = mres($vars['id']); - $title = generate_device_link($device); - $auth = TRUE; +if ($_SESSION['userlevel'] >= '5' || $auth) { + $id = mres($vars['id']); + $title = generate_device_link($device); + $auth = true; } - -?> diff --git a/html/includes/graphs/customer/bits.inc.php b/html/includes/graphs/customer/bits.inc.php index e279c8691a..f66f91df05 100644 --- a/html/includes/graphs/customer/bits.inc.php +++ b/html/includes/graphs/customer/bits.inc.php @@ -1,39 +1,35 @@ +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/device/asa_conns.inc.php b/html/includes/graphs/device/asa_conns.inc.php index 5ac548631b..2965987009 100644 --- a/html/includes/graphs/device/asa_conns.inc.php +++ b/html/includes/graphs/device/asa_conns.inc.php @@ -1,32 +1,29 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ -$scale_min = "0"; +$scale_min = '0'; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/asa_conns.rrd"; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/asa_conns.rrd'; $rrd_options .= " DEF:connections=$rrd_filename:connections:AVERAGE"; $rrd_options .= " DEF:connections_max=$rrd_filename:connections:MAX"; $rrd_options .= " DEF:connections_min=$rrd_filename:connections:MIN"; -$rrd_options .= " AREA:connections_min"; +$rrd_options .= ' AREA:connections_min'; -$rrd_options .= " LINE1.5:connections#cc0000:'" . rrdtool_escape('Current connections')."'"; -$rrd_options .= " GPRINT:connections_min:MIN:%4.0lf"; -$rrd_options .= " GPRINT:connections:LAST:%4.0lf"; -$rrd_options .= " GPRINT:connections_max:MAX:%4.0lf\\\\l"; - - -?> +$rrd_options .= " LINE1.5:connections#cc0000:'".rrdtool_escape('Current connections')."'"; +$rrd_options .= ' GPRINT:connections_min:MIN:%4.0lf'; +$rrd_options .= ' GPRINT:connections:LAST:%4.0lf'; +$rrd_options .= ' GPRINT:connections_max:MAX:%4.0lf\\\\l'; diff --git a/html/includes/graphs/device/auth.inc.php b/html/includes/graphs/device/auth.inc.php index 79027e7bf4..1ed6b7b335 100644 --- a/html/includes/graphs/device/auth.inc.php +++ b/html/includes/graphs/device/auth.inc.php @@ -1,10 +1,7 @@ diff --git a/html/includes/graphs/device/bits.inc.php b/html/includes/graphs/device/bits.inc.php index 64d4c0398a..eaeed92f48 100644 --- a/html/includes/graphs/device/bits.inc.php +++ b/html/includes/graphs/device/bits.inc.php @@ -1,73 +1,62 @@ +// include("includes/graphs/generic_multi_bits_separated.inc.php"); +// include("includes/graphs/generic_multi_data_separated.inc.php"); diff --git a/html/includes/graphs/device/charge.inc.php b/html/includes/graphs/device/charge.inc.php index 237803fa82..66c6ed5ae4 100644 --- a/html/includes/graphs/device/charge.inc.php +++ b/html/includes/graphs/device/charge.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/cipsec_flow_stats.inc.php b/html/includes/graphs/device/cipsec_flow_stats.inc.php index 2e69d2a792..e721b722f9 100644 --- a/html/includes/graphs/device/cipsec_flow_stats.inc.php +++ b/html/includes/graphs/device/cipsec_flow_stats.inc.php @@ -1,85 +1,82 @@ \ No newline at end of file +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/collectd.inc.php b/html/includes/graphs/device/collectd.inc.php index 05ce8b3cbe..7de6424332 100644 --- a/html/includes/graphs/device/collectd.inc.php +++ b/html/includes/graphs/device/collectd.inc.php @@ -1,4 +1,5 @@ - * @@ -16,27 +17,32 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -require('includes/collectd/config.php'); -require('includes/collectd/functions.php'); -require('includes/collectd/definitions.php'); +require 'includes/collectd/config.php'; +require 'includes/collectd/functions.php'; +require 'includes/collectd/definitions.php'; + function makeTextBlock($text, $fontfile, $fontsize, $width) { - // TODO: handle explicit line-break! - $words = explode(' ', $text); - $lines = array($words[0]); - $currentLine = 0; - foreach ($words as $word) { - $lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word); - if ($lineSize[2] - $lineSize[0] < $width) { - $lines[$currentLine] .= ' ' . $word; - } else { - $currentLine++; - $lines[$currentLine] = $word; + // TODO: handle explicit line-break! + $words = explode(' ', $text); + $lines = array($words[0]); + $currentLine = 0; + foreach ($words as $word) { + $lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine].' '.$word); + if (($lineSize[2] - $lineSize[0]) < $width) { + $lines[$currentLine] .= ' '.$word; + } + else { + $currentLine++; + $lines[$currentLine] = $word; + } } - } - error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines))); - return implode("\n", $lines); -} + + error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines))); + return implode("\n", $lines); + +}//end makeTextBlock() + /** * No RRD files found that could match request @@ -46,124 +52,150 @@ function makeTextBlock($text, $fontfile, $fontsize, $width) { * @msg Complete error message to display in place of graph content */ function error($code, $code_msg, $title, $msg) { - global $config; + global $config; - header(sprintf("HTTP/1.0 %d %s", $code, $code_msg)); - header("Pragma: no-cache"); - header("Expires: Mon, 01 Jan 2008 00:00:00 CET"); - header("Content-Type: image/png"); - $w = $config['rrd_width']+81; - $h = $config['rrd_height']+79; + header(sprintf('HTTP/1.0 %d %s', $code, $code_msg)); + header('Pragma: no-cache'); + header('Expires: Mon, 01 Jan 2008 00:00:00 CET'); + header('Content-Type: image/png'); + $w = ($config['rrd_width'] + 81); + $h = ($config['rrd_height'] + 79); - $png = imagecreate($w, $h); - $c_bkgnd = imagecolorallocate($png, 240, 240, 240); - $c_fgnd = imagecolorallocate($png, 255, 255, 255); - $c_blt = imagecolorallocate($png, 208, 208, 208); - $c_brb = imagecolorallocate($png, 160, 160, 160); - $c_grln = imagecolorallocate($png, 114, 114, 114); - $c_grarr = imagecolorallocate($png, 128, 32, 32); - $c_txt = imagecolorallocate($png, 0, 0, 0); - $c_etxt = imagecolorallocate($png, 64, 0, 0); + $png = imagecreate($w, $h); + $c_bkgnd = imagecolorallocate($png, 240, 240, 240); + $c_fgnd = imagecolorallocate($png, 255, 255, 255); + $c_blt = imagecolorallocate($png, 208, 208, 208); + $c_brb = imagecolorallocate($png, 160, 160, 160); + $c_grln = imagecolorallocate($png, 114, 114, 114); + $c_grarr = imagecolorallocate($png, 128, 32, 32); + $c_txt = imagecolorallocate($png, 0, 0, 0); + $c_etxt = imagecolorallocate($png, 64, 0, 0); - if (function_exists('imageantialias')) - imageantialias($png, true); - imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd); - imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd); - imageline($png, 51, 30, 51, $h-43, $c_grln); - imageline($png, 48, $h-46, $w-28, $h-46, $c_grln); - imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr); - imagefilledpolygon($png, array($w-28, $h-48, $w-24, $h-46, $w-28, $h-44), 3, $c_grarr); - imageline($png, 0, 0, $w, 0, $c_blt); - imageline($png, 0, 1, $w, 1, $c_blt); - imageline($png, 0, 0, 0, $h, $c_blt); - imageline($png, 1, 0, 1, $h, $c_blt); - imageline($png, $w-1, 0, $w-1, $h, $c_brb); - imageline($png, $w-2, 1, $w-2, $h, $c_brb); - imageline($png, 1, $h-2, $w, $h-2, $c_brb); - imageline($png, 0, $h-1, $w, $h-1, $c_brb); + if (function_exists('imageantialias')) { + imageantialias($png, true); + } - imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt); - imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt); - if (function_exists('imagettfbbox') && is_file($config['error_font'])) { - // Detailled error message - $fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86); - $fmtbox = imagettfbbox(12, 0, $errorfont, $fmt_msg); - imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg); - } else { - imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt); - } + imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd); + imagefilledrectangle($png, 51, 33, ($w - 31), ($h - 47), $c_fgnd); + imageline($png, 51, 30, 51, ($h - 43), $c_grln); + imageline($png, 48, ($h - 46), ($w - 28), ($h - 46), $c_grln); + imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr); + imagefilledpolygon($png, array($w - 28, $h - 48, $w - 24, $h - 46, $w - 28, $h - 44), 3, $c_grarr); + imageline($png, 0, 0, $w, 0, $c_blt); + imageline($png, 0, 1, $w, 1, $c_blt); + imageline($png, 0, 0, 0, $h, $c_blt); + imageline($png, 1, 0, 1, $h, $c_blt); + imageline($png, ($w - 1), 0, ($w - 1), $h, $c_brb); + imageline($png, ($w - 2), 1, ($w - 2), $h, $c_brb); + imageline($png, 1, ($h - 2), $w, ($h - 2), $c_brb); + imageline($png, 0, ($h - 1), $w, ($h - 1), $c_brb); + + imagestring($png, 4, ceil(($w - strlen($title) * imagefontwidth(4)) / 2), 10, $title, $c_txt); + imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt); + if (function_exists('imagettfbbox') && is_file($config['error_font'])) { + // Detailled error message + $fmt_msg = makeTextBlock($msg, $errorfont, 10, ($w - 86)); + $fmtbox = imagettfbbox(12, 0, $errorfont, $fmt_msg); + imagettftext($png, 10, 0, 55, (35 + 3 + imagefontwidth(5) - $fmtbox[7] + $fmtbox[1]), $c_txt, $errorfont, $fmt_msg); + } + else { + imagestring($png, 4, 53, (35 + 6 + imagefontwidth(5)), $msg, $c_txt); + } + + imagepng($png); + imagedestroy($png); + +}//end error() - imagepng($png); - imagedestroy($png); -} /** * No RRD files found that could match request */ function error404($title, $msg) { - return error(404, "Not found", $title, $msg); -} + return error(404, 'Not found', $title, $msg); + +}//end error404() + function error500($title, $msg) { - return error(500, "Not found", $title, $msg); -} + return error(500, 'Not found', $title, $msg); + +}//end error500() + /** * Incomplete / invalid request */ function error400($title, $msg) { - return error(400, "Bad request", $title, $msg); -} + return error(400, 'Bad request', $title, $msg); + +}//end error400() + // Process input arguments -#$host = read_var('host', $_GET, null); -$host = $device['hostname']; -if (is_null($host)) - return error400("?/?-?/?", "Missing host name"); -else if (!is_string($host)) - return error400("?/?-?/?", "Expecting exactly 1 host name"); -else if (strlen($host) == 0) - return error400("?/?-?/?", "Host name may not be blank"); +// $host = read_var('host', $_GET, null); +$host = $device['hostname']; +if (is_null($host)) { + return error400('?/?-?/?', 'Missing host name'); +} +else if (!is_string($host)) { + return error400('?/?-?/?', 'Expecting exactly 1 host name'); +} +else if (strlen($host) == 0) { + return error400('?/?-?/?', 'Host name may not be blank'); +} -$plugin = read_var('c_plugin', $_GET, null); -if (is_null($plugin)) - return error400($host.'/?-?/?', "Missing plugin name"); -else if (!is_string($plugin)) - return error400($host.'/?-?/?', "Plugin name must be a string"); -else if (strlen($plugin) == 0) - return error400($host.'/?-?/?', "Plugin name may not be blank"); +$plugin = read_var('c_plugin', $_GET, null); +if (is_null($plugin)) { + return error400($host.'/?-?/?', 'Missing plugin name'); +} +else if (!is_string($plugin)) { + return error400($host.'/?-?/?', 'Plugin name must be a string'); +} +else if (strlen($plugin) == 0) { + return error400($host.'/?-?/?', 'Plugin name may not be blank'); +} -$pinst = read_var('c_plugin_instance', $_GET, ''); -if (!is_string($pinst)) - return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string"); +$pinst = read_var('c_plugin_instance', $_GET, ''); +if (!is_string($pinst)) { + return error400($host.'/'.$plugin.'-?/?', 'Plugin instance name must be a string'); +} -$type = read_var('c_type', $_GET, ''); -if (is_null($type)) - return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name"); -else if (!is_string($type)) - return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string"); -else if (strlen($type) == 0) - return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank"); +$type = read_var('c_type', $_GET, ''); +if (is_null($type)) { + return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', 'Missing type name'); +} +else if (!is_string($type)) { + return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', 'Type name must be a string'); +} +else if (strlen($type) == 0) { + return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', 'Type name may not be blank'); +} -$tinst = read_var('c_type_instance', $_GET, ''); +$tinst = read_var('c_type_instance', $_GET, ''); $graph_identifier = $host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/'.$type.(strlen($tinst) ? '-'.$tinst : '-*'); -$timespan = read_var('timespan', $_GET, $config['timespan'][0]['name']); +$timespan = read_var('timespan', $_GET, $config['timespan'][0]['name']); $timespan_ok = false; -foreach ($config['timespan'] as &$ts) - if ($ts['name'] == $timespan) - $timespan_ok = true; -if (!$timespan_ok) - return error400($graph_identifier, "Unknown timespan requested"); +foreach ($config['timespan'] as &$ts) { + if ($ts['name'] == $timespan) { + $timespan_ok = true; + } +} -$logscale = (boolean)read_var('logarithmic', $_GET, false); -$tinylegend = (boolean)read_var('tinylegend', $_GET, false); +if (!$timespan_ok) { + return error400($graph_identifier, 'Unknown timespan requested'); +} + +$logscale = (boolean) read_var('logarithmic', $_GET, false); +$tinylegend = (boolean) read_var('tinylegend', $_GET, false); // Check that at least 1 RRD exists for the specified request $all_tinst = collectd_list_tinsts($host, $plugin, $pinst, $type); -if (count($all_tinst) == 0) - return error404($graph_identifier, "No rrd file found for graphing"); +if (count($all_tinst) == 0) { + return error404($graph_identifier, 'No rrd file found for graphing'); +} // Now that we are read, do the bulk work load_graph_definitions($logscale, $tinylegend); @@ -171,57 +203,83 @@ load_graph_definitions($logscale, $tinylegend); $pinst = strlen($pinst) == 0 ? null : $pinst; $tinst = strlen($tinst) == 0 ? null : $tinst; -$opts = array(); +$opts = array(); $opts['timespan'] = $timespan; -if ($logscale) - $opts['logarithmic'] = 1; -if ($tinylegend) - $opts['tinylegend'] = 1; +if ($logscale) { + $opts['logarithmic'] = 1; +} + +if ($tinylegend) { + $opts['tinylegend'] = 1; +} $rrd_cmd = false; if (isset($MetaGraphDefs[$type])) { - $identifiers = array(); - foreach ($all_tinst as &$atinst) - $identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst); - collectd_flush($identifiers); - $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts); -} else { - if (!in_array(is_null($tinst) ? '' : $tinst, $all_tinst)) - return error404($host.'/'.$plugin.(!is_null($pinst) ? '-'.$pinst : '').'/'.$type.(!is_null($tinst) ? '-'.$tinst : ''), "No rrd file found for graphing"); - collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst)); - if (isset($GraphDefs[$type])) - $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst); - else - $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst); + $identifiers = array(); + foreach ($all_tinst as &$atinst) { + $identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst); + } + + collectd_flush($identifiers); + $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts); +} +else { + if (!in_array(is_null($tinst) ? '' : $tinst, $all_tinst)) { + return error404($host.'/'.$plugin.(!is_null($pinst) ? '-'.$pinst : '').'/'.$type.(!is_null($tinst) ? '-'.$tinst : ''), 'No rrd file found for graphing'); + } + + collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst)); + if (isset($GraphDefs[$type])) { + $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst); + } + else { + $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst); + } } -if(isset($rrd_cmd)) -{ - if ($_GET['from']) { $from = mres($_GET['from']); } - if ($_GET['to']) { $to = mres($_GET['to']); } - $rrd_cmd .= " -s " . $from . " -e " . $to; +if (isset($rrd_cmd)) { + if ($_GET['from']) { + $from = mres($_GET['from']); + } + + if ($_GET['to']) { + $to = mres($_GET['to']); + } + + $rrd_cmd .= ' -s '.$from.' -e '.$to; } -if ($_GET['legend'] == "no") { $rrd_cmd .= " -g "; } +if ($_GET['legend'] == 'no') { + $rrd_cmd .= ' -g '; +} -if ($height < "99") { $rrd_cmd .= " --only-graph "; } -if ($width <= "300") { $rrd_cmd .= " --font LEGEND:7:" . $config['mono_font'] . " --font AXIS:6:" . $config['mono_font'] . " "; } -else { $rrd_cmd .= " --font LEGEND:8:" . $config['mono_font'] . " --font AXIS:7:" . $config['mono_font'] . " "; } +if ($height < '99') { + $rrd_cmd .= ' --only-graph '; +} + +if ($width <= '300') { + $rrd_cmd .= ' --font LEGEND:7:'.$config['mono_font'].' --font AXIS:6:'.$config['mono_font'].' '; +} +else { + $rrd_cmd .= ' --font LEGEND:8:'.$config['mono_font'].' --font AXIS:7:'.$config['mono_font'].' '; +} if (isset($_GET['debug'])) { - header('Content-Type: text/plain; charset=utf-8'); - printf("Would have executed:\n%s\n", $rrd_cmd); - return 0; -} else if ($rrd_cmd) { - header('Content-Type: image/png'); - header('Cache-Control: max-age=60'); - $rt = 0; - passthru($rrd_cmd, $rt); - if ($rt != 0) - return error500($graph_identifier, "RRD failed to generate the graph: ".$rt); - return $rt; -} else { - return error500($graph_identifier, "Failed to tell RRD how to generate the graph"); + header('Content-Type: text/plain; charset=utf-8'); + printf("Would have executed:\n%s\n", $rrd_cmd); + return 0; } +else if ($rrd_cmd) { + header('Content-Type: image/png'); + header('Cache-Control: max-age=60'); + $rt = 0; + passthru($rrd_cmd, $rt); + if ($rt != 0) { + return error500($graph_identifier, 'RRD failed to generate the graph: '.$rt); + } -?> + return $rt; +} +else { + return error500($graph_identifier, 'Failed to tell RRD how to generate the graph'); +} diff --git a/html/includes/graphs/device/diskio_bits.inc.php b/html/includes/graphs/device/diskio_bits.inc.php index 32f61ffe4e..efe305efdf 100644 --- a/html/includes/graphs/device/diskio_bits.inc.php +++ b/html/includes/graphs/device/diskio_bits.inc.php @@ -1,17 +1,15 @@ +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/device/diskio_ops.inc.php b/html/includes/graphs/device/diskio_ops.inc.php index 5b1593258d..3c788f69fc 100644 --- a/html/includes/graphs/device/diskio_ops.inc.php +++ b/html/includes/graphs/device/diskio_ops.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_multi_seperated.inc.php'; diff --git a/html/includes/graphs/device/fdb_count.inc.php b/html/includes/graphs/device/fdb_count.inc.php index 484ac9b892..83dd721867 100644 --- a/html/includes/graphs/device/fdb_count.inc.php +++ b/html/includes/graphs/device/fdb_count.inc.php @@ -1,19 +1,17 @@ diff --git a/html/includes/graphs/device/load.inc.php b/html/includes/graphs/device/load.inc.php index a8b27356ca..31a2e9c120 100644 --- a/html/includes/graphs/device/load.inc.php +++ b/html/includes/graphs/device/load.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/mib.inc.php b/html/includes/graphs/device/mib.inc.php index 7f76f3bbee..08241e9226 100644 --- a/html/includes/graphs/device/mib.inc.php +++ b/html/includes/graphs/device/mib.inc.php @@ -13,24 +13,25 @@ */ $rrd_list = array(); -$prefix = rrd_name($device['hostname'], array($subtype, ""), ""); -foreach (glob($prefix."*.rrd") as $filename) { +$prefix = rrd_name($device['hostname'], array($subtype, ''), ''); +foreach (glob($prefix.'*.rrd') as $filename) { // find out what * expanded to - $globpart = str_replace($prefix, '', $filename); // take off the prefix - $instance = substr($globpart, 0, -4); // take off ".rrd" - - $ds = array(); - $mibparts = explode("-", $subtype); - $mibvar = end($mibparts); - $ds['ds'] = name_shorten($mibvar); - $ds['descr'] = "$mibvar-$instance"; + $globpart = str_replace($prefix, '', $filename); + // take off the prefix + $instance = substr($globpart, 0, -4); + // take off ".rrd" + $ds = array(); + $mibparts = explode('-', $subtype); + $mibvar = end($mibparts); + $ds['ds'] = name_shorten($mibvar); + $ds['descr'] = "$mibvar-$instance"; $ds['filename'] = $filename; - $rrd_list[] = $ds; + $rrd_list[] = $ds; } $colours = 'mixed'; -$scale_min = "0"; +$scale_min = '0'; $nototal = 0; $simple_rrd = true; -include("includes/graphs/generic_multi_line.inc.php"); +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/netstat_ip_forward.inc.php b/html/includes/graphs/device/netstat_ip_forward.inc.php index 30402f5c9c..e4f5b04d4d 100644 --- a/html/includes/graphs/device/netstat_ip_forward.inc.php +++ b/html/includes/graphs/device/netstat_ip_forward.inc.php @@ -1,23 +1,21 @@ array()); -$i=0; -foreach ($stats as $stat => $array) -{ - $i++; - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = str_replace("ip", "", $stat); - $rrd_list[$i]['ds'] = $stat; +$i = 0; +foreach ($stats as $stat => $array) { + $i++; + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = str_replace('ip', '', $stat); + $rrd_list[$i]['ds'] = $stat; } -$colours='mixed'; +$colours = 'mixed'; -$scale_min = "0"; -$nototal = 1; -$simple_rrd = TRUE; - -include("includes/graphs/generic_multi_line.inc.php"); +$scale_min = '0'; +$nototal = 1; +$simple_rrd = true; +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/ping_perf.inc.php b/html/includes/graphs/device/ping_perf.inc.php index cbbb48d622..2e1e49b606 100644 --- a/html/includes/graphs/device/ping_perf.inc.php +++ b/html/includes/graphs/device/ping_perf.inc.php @@ -1,27 +1,25 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ -$scale_min = "0"; +$scale_min = '0'; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/ping-perf.rrd"; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/ping-perf.rrd'; -$rrd_options .= " DEF:ping=".$rrd_filename.":ping:AVERAGE"; +$rrd_options .= ' DEF:ping='.$rrd_filename.':ping:AVERAGE'; $rrd_options .= " 'COMMENT:Seconds Current Minimum Maximum Average\\n'"; -$rrd_options .= " LINE1.25:ping#36393D:Ping"; -$rrd_options .= " GPRINT:ping:LAST:%6.2lf GPRINT:ping:AVERAGE:%6.2lf"; +$rrd_options .= ' LINE1.25:ping#36393D:Ping'; +$rrd_options .= ' GPRINT:ping:LAST:%6.2lf GPRINT:ping:AVERAGE:%6.2lf'; $rrd_options .= " GPRINT:ping:MAX:%6.2lf 'GPRINT:ping:AVERAGE:%6.2lf\\n'"; - -?> diff --git a/html/includes/graphs/device/poller_perf.inc.php b/html/includes/graphs/device/poller_perf.inc.php index 1ce7689d68..b8dae8037b 100644 --- a/html/includes/graphs/device/poller_perf.inc.php +++ b/html/includes/graphs/device/poller_perf.inc.php @@ -1,27 +1,25 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ -$scale_min = "0"; +$scale_min = '0'; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/poller-perf.rrd"; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/poller-perf.rrd'; -$rrd_options .= " DEF:poller=".$rrd_filename.":poller:AVERAGE"; +$rrd_options .= ' DEF:poller='.$rrd_filename.':poller:AVERAGE'; $rrd_options .= " 'COMMENT:Seconds Current Minimum Maximum Average\\n'"; -$rrd_options .= " LINE1.25:poller#36393D:Poller"; -$rrd_options .= " GPRINT:poller:LAST:%6.2lf GPRINT:poller:AVERAGE:%6.2lf"; +$rrd_options .= ' LINE1.25:poller#36393D:Poller'; +$rrd_options .= ' GPRINT:poller:LAST:%6.2lf GPRINT:poller:AVERAGE:%6.2lf'; $rrd_options .= " GPRINT:poller:MAX:%6.2lf 'GPRINT:poller:AVERAGE:%6.2lf\\n'"; - -?> diff --git a/html/includes/graphs/device/sensor.inc.php b/html/includes/graphs/device/sensor.inc.php index bf75c82877..38b91b211f 100644 --- a/html/includes/graphs/device/sensor.inc.php +++ b/html/includes/graphs/device/sensor.inc.php @@ -1,51 +1,58 @@ "300") { $descr_len = "40"; } else { $descr_len = "22"; } - -$rrd_options .= " -E "; -$iter = "1"; -$rrd_options .= " COMMENT:'".str_pad($unit_long,$descr_len)." Cur Min Max\\n'"; - -foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? ORDER BY `sensor_index`", array($class, $device['device_id'])) as $sensor) -{ - // FIXME generic colour function - switch ($iter) - { - case "1": - $colour= "CC0000"; - break; - case "2": - $colour= "008C00"; - break; - case "3": - $colour= "4096EE"; - break; - case "4": - $colour= "73880A"; - break; - case "5": - $colour= "D01F3C"; - break; - case "6": - $colour= "36393D"; - break; - case "7": - default: - $colour= "FF0084"; - unset($iter); - break; - } - - $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], $descr_len),0,$descr_len); - $rrd_file = get_sensor_rrd($device, $sensor); - $rrd_options .= " DEF:sensor" . $sensor['sensor_id'] . "=$rrd_file:sensor:AVERAGE "; - $rrd_options .= " LINE1:sensor" . $sensor['sensor_id'] . "#" . $colour . ":'" . str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed'])) . "'"; - $rrd_options .= " GPRINT:sensor" . $sensor['sensor_id'] . ":LAST:%4.1lf".$unit." "; - $rrd_options .= " GPRINT:sensor" . $sensor['sensor_id'] . ":MIN:%4.1lf".$unit." "; - $rrd_options .= " GPRINT:sensor" . $sensor['sensor_id'] . ":MAX:%4.1lf".$unit."\\\l "; - $iter++; +if ($_GET['width'] > '300') { + $descr_len = '40'; +} +else { + $descr_len = '22'; } -?> +$rrd_options .= ' -E '; +$iter = '1'; +$rrd_options .= " COMMENT:'".str_pad($unit_long, $descr_len)." Cur Min Max\\n'"; + +foreach (dbFetchRows('SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? ORDER BY `sensor_index`', array($class, $device['device_id'])) as $sensor) { + // FIXME generic colour function + switch ($iter) { + case '1': + $colour = 'CC0000'; + break; + + case '2': + $colour = '008C00'; + break; + + case '3': + $colour = '4096EE'; + break; + + case '4': + $colour = '73880A'; + break; + + case '5': + $colour = 'D01F3C'; + break; + + case '6': + $colour = '36393D'; + break; + + case '7': + default: + $colour = 'FF0084'; + unset($iter); + break; + }//end switch + + $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], $descr_len), 0, $descr_len); + $rrd_file = get_sensor_rrd($device, $sensor); + $rrd_options .= ' DEF:sensor'.$sensor['sensor_id']."=$rrd_file:sensor:AVERAGE "; + $rrd_options .= ' LINE1:sensor'.$sensor['sensor_id'].'#'.$colour.":'".str_replace(':', '\:', str_replace('\*', '*', $sensor['sensor_descr_fixed']))."'"; + $rrd_options .= ' GPRINT:sensor'.$sensor['sensor_id'].':LAST:%4.1lf'.$unit.' '; + $rrd_options .= ' GPRINT:sensor'.$sensor['sensor_id'].':MIN:%4.1lf'.$unit.' '; + $rrd_options .= ' GPRINT:sensor'.$sensor['sensor_id'].':MAX:%4.1lf'.$unit.'\\\l '; + $iter++; +}//end foreach diff --git a/html/includes/graphs/device/siklu_rfAverageCinr.inc.php b/html/includes/graphs/device/siklu_rfAverageCinr.inc.php index a34a1b6b43..17a5b5ee08 100644 --- a/html/includes/graphs/device/siklu_rfAverageCinr.inc.php +++ b/html/includes/graphs/device/siklu_rfAverageCinr.inc.php @@ -1,15 +1,14 @@ = "450") { $descr_len = "48"; } else { $descr_len = "21"; } -$descr_len = intval($_GET['width'] / 8) * 0.8; +// if ($_GET['width'] >= "450") { $descr_len = "48"; } else { $descr_len = "21"; } +$descr_len = (intval(($_GET['width'] / 8)) * 0.8); $unit_long = 'milliseconds'; -$unit = 'ms'; +$unit = 'ms'; -$rrd_options .= " -l 0 -E "; -$rrd_options .= " COMMENT:'".str_pad($unit_long,$descr_len)." Cur Min Max\\n'"; +$rrd_options .= ' -l 0 -E '; +$rrd_options .= " COMMENT:'".str_pad($unit_long, $descr_len)." Cur Min Max\\n'"; -$name = ""; -if ($sla['tag']) - $name .= $sla['tag']; -if ($sla['owner']) - $name .= " (Owner: ". $sla['owner'] .")"; +$name = ''; +if ($sla['tag']) { + $name .= $sla['tag']; +} -$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("sla-" . $sla['sla_nr'] . ".rrd"); +if ($sla['owner']) { + $name .= ' (Owner: '.$sla['owner'].')'; +} + +$rrd_file = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('sla-'.$sla['sla_nr'].'.rrd'); $rrd_options .= " DEF:rtt=$rrd_file:rtt:AVERAGE "; -$rrd_options .= " VDEF:avg=rtt,AVERAGE "; -$rrd_options .= " LINE1:avg#CCCCFF:'".str_pad('Average',$descr_len-3)."':dashes"; -$rrd_options .= " GPRINT:rtt:AVERAGE:%4.1lf".$unit."\\\l "; -$rrd_options .= " LINE1:rtt#CC0000:'" . rrdtool_escape($descr,$descr_len-3) . "'"; -$rrd_options .= " GPRINT:rtt:LAST:%4.1lf".$unit." "; -$rrd_options .= " GPRINT:rtt:MIN:%4.1lf".$unit." "; -$rrd_options .= " GPRINT:rtt:MAX:%4.1lf".$unit."\\\l "; - -?> +$rrd_options .= ' VDEF:avg=rtt,AVERAGE '; +$rrd_options .= " LINE1:avg#CCCCFF:'".str_pad('Average', ($descr_len - 3))."':dashes"; +$rrd_options .= ' GPRINT:rtt:AVERAGE:%4.1lf'.$unit.'\\\l '; +$rrd_options .= " LINE1:rtt#CC0000:'".rrdtool_escape($descr, ($descr_len - 3))."'"; +$rrd_options .= ' GPRINT:rtt:LAST:%4.1lf'.$unit.' '; +$rrd_options .= ' GPRINT:rtt:MIN:%4.1lf'.$unit.' '; +$rrd_options .= ' GPRINT:rtt:MAX:%4.1lf'.$unit.'\\\l '; diff --git a/html/includes/graphs/device/state.inc.php b/html/includes/graphs/device/state.inc.php index 56b059e012..a8ae9041c8 100644 --- a/html/includes/graphs/device/state.inc.php +++ b/html/includes/graphs/device/state.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/toner.inc.php b/html/includes/graphs/device/toner.inc.php index 6a974b64a7..9ba469cc04 100644 --- a/html/includes/graphs/device/toner.inc.php +++ b/html/includes/graphs/device/toner.inc.php @@ -11,8 +11,7 @@ foreach (dbFetchRows('SELECT * FROM toner where device_id = ?', array($device['d if ($colour['left'] == null) { // FIXME generic colour function - switch ($iter) - { + switch ($iter) { case '1': $colour['left'] = '000000'; break; diff --git a/html/includes/graphs/device/ubnt_airfiber_Capacity.inc.php b/html/includes/graphs/device/ubnt_airfiber_Capacity.inc.php index 6174a0e18f..63a8083e88 100644 --- a/html/includes/graphs/device/ubnt_airfiber_Capacity.inc.php +++ b/html/includes/graphs/device/ubnt_airfiber_Capacity.inc.php @@ -1,24 +1,22 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/ucd_cpu.inc.php b/html/includes/graphs/device/ucd_cpu.inc.php index 3068bba695..af7fc5e9f5 100644 --- a/html/includes/graphs/device/ucd_cpu.inc.php +++ b/html/includes/graphs/device/ucd_cpu.inc.php @@ -1,33 +1,31 @@ diff --git a/html/includes/graphs/device/ucd_interrupts.inc.php b/html/includes/graphs/device/ucd_interrupts.inc.php index 92665285dc..1054df1d22 100644 --- a/html/includes/graphs/device/ucd_interrupts.inc.php +++ b/html/includes/graphs/device/ucd_interrupts.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/generic_data.inc.php b/html/includes/graphs/generic_data.inc.php index a85a6c760b..e13fce80c4 100644 --- a/html/includes/graphs/generic_data.inc.php +++ b/html/includes/graphs/generic_data.inc.php @@ -2,130 +2,134 @@ // Draw generic bits graph // args: ds_in, ds_out, rrd_filename, bg, legend, from, to, width, height, inverse, previous +require 'includes/graphs/common.inc.php'; -include("includes/graphs/common.inc.php"); - -if ($rrd_filename) { $rrd_filename_out = $rrd_filename; $rrd_filename_in = $rrd_filename; } -if ($inverse) { $in = 'out'; $out = 'in'; } else { $in = 'in'; $out = 'out'; } - -if ($multiplier) -{ - $rrd_options .= " DEF:p".$out."octets=".$rrd_filename_out.":".$ds_out.":AVERAGE"; - $rrd_options .= " DEF:p".$in."octets=".$rrd_filename_in.":".$ds_in.":AVERAGE"; - $rrd_options .= " DEF:p".$out."octets_max=".$rrd_filename_out.":".$ds_out.":MAX"; - $rrd_options .= " DEF:p".$in."octets_max=".$rrd_filename_in.":".$ds_in.":MAX"; - $rrd_options .= " CDEF:inoctets=pinoctets,$multiplier,*"; - $rrd_options .= " CDEF:outoctets=poutoctets,$multiplier,*"; - $rrd_options .= " CDEF:inoctets_max=pinoctets_max,$multiplier,*"; - $rrd_options .= " CDEF:outoctets_max=poutoctets_max,$multiplier,*"; -} else { - $rrd_options .= " DEF:".$out."octets=".$rrd_filename_out.":".$ds_out.":AVERAGE"; - $rrd_options .= " DEF:".$in."octets=".$rrd_filename_in.":".$ds_in.":AVERAGE"; - $rrd_options .= " DEF:".$out."octets_max=".$rrd_filename_out.":".$ds_out.":MAX"; - $rrd_options .= " DEF:".$in."octets_max=".$rrd_filename_in.":".$ds_in.":MAX"; +if ($rrd_filename) { + $rrd_filename_out = $rrd_filename; + $rrd_filename_in = $rrd_filename; } -if($_GET['previous'] == "yes") -{ - if ($multiplier) - { - $rrd_options .= " DEF:p".$out."octetsX=".$rrd_filename_out.":".$ds_out.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " DEF:p".$in."octetsX=".$rrd_filename_in.":".$ds_in.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:p".$out."octetsX:$period"; - $rrd_options .= " SHIFT:p".$in."octetsX:$period"; - $rrd_options .= " CDEF:inoctetsX=pinoctetsX,$multiplier,*"; - $rrd_options .= " CDEF:outoctetsX=poutoctetsX,$multiplier,*"; - } else { - $rrd_options .= " DEF:".$out."octetsX=".$rrd_filename_out.":".$ds_out.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " DEF:".$in."octetsX=".$rrd_filename_in.":".$ds_in.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:".$out."octetsX:$period"; - $rrd_options .= " SHIFT:".$in."octetsX:$period"; - } - - $rrd_options .= " CDEF:octetsX=inoctetsX,outoctetsX,+"; - $rrd_options .= " CDEF:doutoctetsX=outoctetsX,-1,*"; - $rrd_options .= " CDEF:outbitsX=outoctetsX,8,*"; - #$rrd_options .= " CDEF:outbits_maxX=outoctets_maxX,8,*"; - #$rrd_options .= " CDEF:doutoctets_maxX=outoctets_maxX,-1,*"; - $rrd_options .= " CDEF:doutbitsX=doutoctetsX,8,*"; - #$rrd_options .= " CDEF:doutbits_maxX=doutoctets_maxX,8,*"; - - $rrd_options .= " CDEF:inbitsX=inoctetsX,8,*"; - #$rrd_options .= " CDEF:inbits_maxX=inoctets_maxX,8,*"; - $rrd_options .= " VDEF:totinX=inoctetsX,TOTAL"; - $rrd_options .= " VDEF:totoutX=outoctetsX,TOTAL"; - $rrd_options .= " VDEF:totX=octetsX,TOTAL"; - +if ($inverse) { + $in = 'out'; + $out = 'in'; +} +else { + $in = 'in'; + $out = 'out'; } -$rrd_options .= " CDEF:octets=inoctets,outoctets,+"; -$rrd_options .= " CDEF:doutoctets=outoctets,-1,*"; -$rrd_options .= " CDEF:outbits=outoctets,8,*"; -$rrd_options .= " CDEF:outbits_max=outoctets_max,8,*"; -$rrd_options .= " CDEF:doutoctets_max=outoctets_max,-1,*"; -$rrd_options .= " CDEF:doutbits=doutoctets,8,*"; -$rrd_options .= " CDEF:doutbits_max=doutoctets_max,8,*"; +if ($multiplier) { + $rrd_options .= ' DEF:p'.$out.'octets='.$rrd_filename_out.':'.$ds_out.':AVERAGE'; + $rrd_options .= ' DEF:p'.$in.'octets='.$rrd_filename_in.':'.$ds_in.':AVERAGE'; + $rrd_options .= ' DEF:p'.$out.'octets_max='.$rrd_filename_out.':'.$ds_out.':MAX'; + $rrd_options .= ' DEF:p'.$in.'octets_max='.$rrd_filename_in.':'.$ds_in.':MAX'; + $rrd_options .= " CDEF:inoctets=pinoctets,$multiplier,*"; + $rrd_options .= " CDEF:outoctets=poutoctets,$multiplier,*"; + $rrd_options .= " CDEF:inoctets_max=pinoctets_max,$multiplier,*"; + $rrd_options .= " CDEF:outoctets_max=poutoctets_max,$multiplier,*"; +} +else { + $rrd_options .= ' DEF:'.$out.'octets='.$rrd_filename_out.':'.$ds_out.':AVERAGE'; + $rrd_options .= ' DEF:'.$in.'octets='.$rrd_filename_in.':'.$ds_in.':AVERAGE'; + $rrd_options .= ' DEF:'.$out.'octets_max='.$rrd_filename_out.':'.$ds_out.':MAX'; + $rrd_options .= ' DEF:'.$in.'octets_max='.$rrd_filename_in.':'.$ds_in.':MAX'; +} -$rrd_options .= " CDEF:inbits=inoctets,8,*"; -$rrd_options .= " CDEF:inbits_max=inoctets_max,8,*"; +if ($_GET['previous'] == 'yes') { + if ($multiplier) { + $rrd_options .= ' DEF:p'.$out.'octetsX='.$rrd_filename_out.':'.$ds_out.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' DEF:p'.$in.'octetsX='.$rrd_filename_in.':'.$ds_in.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:p'.$out."octetsX:$period"; + $rrd_options .= ' SHIFT:p'.$in."octetsX:$period"; + $rrd_options .= " CDEF:inoctetsX=pinoctetsX,$multiplier,*"; + $rrd_options .= " CDEF:outoctetsX=poutoctetsX,$multiplier,*"; + } + else { + $rrd_options .= ' DEF:'.$out.'octetsX='.$rrd_filename_out.':'.$ds_out.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' DEF:'.$in.'octetsX='.$rrd_filename_in.':'.$ds_in.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:'.$out."octetsX:$period"; + $rrd_options .= ' SHIFT:'.$in."octetsX:$period"; + } + + $rrd_options .= ' CDEF:octetsX=inoctetsX,outoctetsX,+'; + $rrd_options .= ' CDEF:doutoctetsX=outoctetsX,-1,*'; + $rrd_options .= ' CDEF:outbitsX=outoctetsX,8,*'; + // $rrd_options .= " CDEF:outbits_maxX=outoctets_maxX,8,*"; + // $rrd_options .= " CDEF:doutoctets_maxX=outoctets_maxX,-1,*"; + $rrd_options .= ' CDEF:doutbitsX=doutoctetsX,8,*'; + // $rrd_options .= " CDEF:doutbits_maxX=doutoctets_maxX,8,*"; + $rrd_options .= ' CDEF:inbitsX=inoctetsX,8,*'; + // $rrd_options .= " CDEF:inbits_maxX=inoctets_maxX,8,*"; + $rrd_options .= ' VDEF:totinX=inoctetsX,TOTAL'; + $rrd_options .= ' VDEF:totoutX=outoctetsX,TOTAL'; + $rrd_options .= ' VDEF:totX=octetsX,TOTAL'; +}//end if + +$rrd_options .= ' CDEF:octets=inoctets,outoctets,+'; +$rrd_options .= ' CDEF:doutoctets=outoctets,-1,*'; +$rrd_options .= ' CDEF:outbits=outoctets,8,*'; +$rrd_options .= ' CDEF:outbits_max=outoctets_max,8,*'; +$rrd_options .= ' CDEF:doutoctets_max=outoctets_max,-1,*'; +$rrd_options .= ' CDEF:doutbits=doutoctets,8,*'; +$rrd_options .= ' CDEF:doutbits_max=doutoctets_max,8,*'; + +$rrd_options .= ' CDEF:inbits=inoctets,8,*'; +$rrd_options .= ' CDEF:inbits_max=inoctets_max,8,*'; if ($config['rrdgraph_real_95th']) { - $rrd_options .= " CDEF:highbits=inoctets,outoctets,MAX,8,*"; - $rrd_options .= " VDEF:95thhigh=highbits,95,PERCENT"; + $rrd_options .= ' CDEF:highbits=inoctets,outoctets,MAX,8,*'; + $rrd_options .= ' VDEF:95thhigh=highbits,95,PERCENT'; } -$rrd_options .= " VDEF:totin=inoctets,TOTAL"; -$rrd_options .= " VDEF:totout=outoctets,TOTAL"; -$rrd_options .= " VDEF:tot=octets,TOTAL"; +$rrd_options .= ' VDEF:totin=inoctets,TOTAL'; +$rrd_options .= ' VDEF:totout=outoctets,TOTAL'; +$rrd_options .= ' VDEF:tot=octets,TOTAL'; -$rrd_options .= " VDEF:95thin=inbits,95,PERCENT"; -$rrd_options .= " VDEF:95thout=outbits,95,PERCENT"; -$rrd_options .= " VDEF:d95thout=doutbits,5,PERCENT"; +$rrd_options .= ' VDEF:95thin=inbits,95,PERCENT'; +$rrd_options .= ' VDEF:95thout=outbits,95,PERCENT'; +$rrd_options .= ' VDEF:d95thout=doutbits,5,PERCENT'; -if($format == "octets" || $format == "bytes") -{ - $units = "Bps"; - $format = "octets"; -} else { - $units = "bps"; - $format = "bits"; +if ($format == 'octets' || $format == 'bytes') { + $units = 'Bps'; + $format = 'octets'; +} +else { + $units = 'bps'; + $format = 'bits'; } $rrd_options .= " COMMENT:'bps Now Ave Max 95th %\\n'"; -$rrd_options .= " AREA:in".$format."_max#D7FFC7:"; -$rrd_options .= " AREA:in".$format."#90B040:"; -$rrd_options .= " LINE:in".$format."#608720:'In '"; -#$rrd_options .= " LINE1.25:in".$format."#006600:'In '"; -$rrd_options .= " GPRINT:in".$format.":LAST:%6.2lf%s"; -$rrd_options .= " GPRINT:in".$format.":AVERAGE:%6.2lf%s"; -$rrd_options .= " GPRINT:in".$format."_max:MAX:%6.2lf%s"; +$rrd_options .= ' AREA:in'.$format.'_max#D7FFC7:'; +$rrd_options .= ' AREA:in'.$format.'#90B040:'; +$rrd_options .= ' LINE:in'.$format."#608720:'In '"; +// $rrd_options .= " LINE1.25:in".$format."#006600:'In '"; +$rrd_options .= ' GPRINT:in'.$format.':LAST:%6.2lf%s'; +$rrd_options .= ' GPRINT:in'.$format.':AVERAGE:%6.2lf%s'; +$rrd_options .= ' GPRINT:in'.$format.'_max:MAX:%6.2lf%s'; $rrd_options .= " GPRINT:95thin:%6.2lf%s\\\\n"; -$rrd_options .= " AREA:dout".$format."_max#E0E0FF:"; -$rrd_options .= " AREA:dout".$format."#8080C0:"; -$rrd_options .= " LINE:dout".$format."#606090:'Out'"; -#$rrd_options .= " LINE1.25:dout".$format."#000099:Out"; -$rrd_options .= " GPRINT:out".$format.":LAST:%6.2lf%s"; -$rrd_options .= " GPRINT:out".$format.":AVERAGE:%6.2lf%s"; -$rrd_options .= " GPRINT:out".$format."_max:MAX:%6.2lf%s"; +$rrd_options .= ' AREA:dout'.$format.'_max#E0E0FF:'; +$rrd_options .= ' AREA:dout'.$format.'#8080C0:'; +$rrd_options .= ' LINE:dout'.$format."#606090:'Out'"; +// $rrd_options .= " LINE1.25:dout".$format."#000099:Out"; +$rrd_options .= ' GPRINT:out'.$format.':LAST:%6.2lf%s'; +$rrd_options .= ' GPRINT:out'.$format.':AVERAGE:%6.2lf%s'; +$rrd_options .= ' GPRINT:out'.$format.'_max:MAX:%6.2lf%s'; $rrd_options .= " GPRINT:95thout:%6.2lf%s\\\\n"; if ($config['rrdgraph_real_95th']) { - $rrd_options .= " HRULE:95thhigh#FF0000:\"Highest\""; - $rrd_options .= " GPRINT:95thhigh:\"%30.2lf%s\\n\""; + $rrd_options .= ' HRULE:95thhigh#FF0000:"Highest"'; + $rrd_options .= " GPRINT:95thhigh:\"%30.2lf%s\\n\""; } $rrd_options .= " GPRINT:tot:'Total %6.2lf%s'"; $rrd_options .= " GPRINT:totin:'(In %6.2lf%s'"; $rrd_options .= " GPRINT:totout:'Out %6.2lf%s)\\\\l'"; -$rrd_options .= " LINE1:95thin#aa0000"; -$rrd_options .= " LINE1:d95thout#aa0000"; +$rrd_options .= ' LINE1:95thin#aa0000'; +$rrd_options .= ' LINE1:d95thout#aa0000'; -if($_GET['previous'] == "yes") -{ - $rrd_options .= " LINE1.25:in".$format."X#009900:'Prev In \\\\n'"; - $rrd_options .= " LINE1.25:dout".$format."X#000099:'Prev Out'"; +if ($_GET['previous'] == 'yes') { + $rrd_options .= ' LINE1.25:in'.$format."X#009900:'Prev In \\\\n'"; + $rrd_options .= ' LINE1.25:dout'.$format."X#000099:'Prev Out'"; } - -?> diff --git a/html/includes/graphs/generic_multi_bits_separated.inc.php b/html/includes/graphs/generic_multi_bits_separated.inc.php index 5eaa709086..181f0ae4d7 100644 --- a/html/includes/graphs/generic_multi_bits_separated.inc.php +++ b/html/includes/graphs/generic_multi_bits_separated.inc.php @@ -1,133 +1,152 @@ "500") -{ - $descr_len=18; -} else { - $descr_len=8; - $descr_len += round(($width - 260) / 9.5); +if ($width > '500') { + $descr_len = 18; +} +else { + $descr_len = 8; + $descr_len += round(($width - 260) / 9.5); } -$unit_text = "Bits/sec"; +$unit_text = 'Bits/sec'; if (!$noagg || !$nodetails) { - if($width > "500") { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." Current Average Maximum '"; - if (!$nototal) { $rrd_options .= " COMMENT:'Total '"; } - $rrd_options .= " COMMENT:'\l'"; - } else { - $nototal=TRUE; - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." Now Ave Max\l'"; - } + if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." Current Average Maximum '"; + if (!$nototal) { + $rrd_options .= " COMMENT:'Total '"; + } + + $rrd_options .= " COMMENT:'\l'"; + } + else { + $nototal = true; + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." Now Ave Max\l'"; + } } -if(!isset($multiplier)) { $multiplier = "8"; } +if (!isset($multiplier)) { + $multiplier = '8'; +} -foreach ($rrd_list as $rrd) -{ - if (!$config['graph_colours'][$colours_in][$iter] || !$config['graph_colours'][$colours_out][$iter]) { $iter = 0; } - - $colour_in=$config['graph_colours'][$colours_in][$iter]; - $colour_out=$config['graph_colours'][$colours_out][$iter]; - - if (!$nodetails) { - if (isset($rrd['descr_in'])) { - $descr = rrdtool_escape($rrd['descr_in'], $descr_len) . " In"; - } else { - $descr = rrdtool_escape($rrd['descr'], $descr_len) . " In"; +foreach ($rrd_list as $rrd) { + if (!$config['graph_colours'][$colours_in][$iter] || !$config['graph_colours'][$colours_out][$iter]) { + $iter = 0; } - $descr_out = rrdtool_escape($rrd['descr_out'], $descr_len) . " Out"; - $descr = str_replace("'", "", $descr); // FIXME does this mean ' should be filtered in rrdtool_escape? probably... - $descr_out = str_replace("'", "", $descr_out); - } - $rrd_options .= " DEF:".$in.$i."=".$rrd['filename'].":".$ds_in.":AVERAGE "; - $rrd_options .= " DEF:".$out.$i."=".$rrd['filename'].":".$ds_out.":AVERAGE "; - $rrd_options .= " CDEF:inB".$i."=in".$i.",$multiplier,* "; - $rrd_options .= " CDEF:outB".$i."=out".$i.",$multiplier,*"; - $rrd_options .= " CDEF:outB".$i."_neg=outB".$i.",-1,*"; - $rrd_options .= " CDEF:octets".$i."=inB".$i.",outB".$i.",+"; + $colour_in = $config['graph_colours'][$colours_in][$iter]; + $colour_out = $config['graph_colours'][$colours_out][$iter]; - if (!$nototal) { - $rrd_options .= " VDEF:totin".$i."=inB".$i.",TOTAL"; - $rrd_options .= " VDEF:totout".$i."=outB".$i.",TOTAL"; - $rrd_options .= " VDEF:tot".$i."=octets".$i.",TOTAL"; - } + if (!$nodetails) { + if (isset($rrd['descr_in'])) { + $descr = rrdtool_escape($rrd['descr_in'], $descr_len).' In'; + } + else { + $descr = rrdtool_escape($rrd['descr'], $descr_len).' In'; + } - if ($i) { $stack="STACK"; } + $descr_out = rrdtool_escape($rrd['descr_out'], $descr_len).' Out'; + $descr = str_replace("'", '', $descr); + // FIXME does this mean ' should be filtered in rrdtool_escape? probably... + $descr_out = str_replace("'", '', $descr_out); + } + + $rrd_options .= ' DEF:'.$in.$i.'='.$rrd['filename'].':'.$ds_in.':AVERAGE '; + $rrd_options .= ' DEF:'.$out.$i.'='.$rrd['filename'].':'.$ds_out.':AVERAGE '; + $rrd_options .= ' CDEF:inB'.$i.'=in'.$i.",$multiplier,* "; + $rrd_options .= ' CDEF:outB'.$i.'=out'.$i.",$multiplier,*"; + $rrd_options .= ' CDEF:outB'.$i.'_neg=outB'.$i.',-1,*'; + $rrd_options .= ' CDEF:octets'.$i.'=inB'.$i.',outB'.$i.',+'; - $rrd_options .= " AREA:inB".$i."#" . $colour_in . ":'" . $descr . "':$stack"; - if (!$nodetails) { - $rrd_options .= " GPRINT:inB".$i.":LAST:%6.2lf%s$units"; - $rrd_options .= " GPRINT:inB".$i.":AVERAGE:%6.2lf%s$units"; - $rrd_options .= " GPRINT:inB".$i.":MAX:%6.2lf%s$units"; if (!$nototal) { - $rrd_options .= " GPRINT:totin".$i.":%6.2lf%s$total_units"; + $rrd_options .= ' VDEF:totin'.$i.'=inB'.$i.',TOTAL'; + $rrd_options .= ' VDEF:totout'.$i.'=outB'.$i.',TOTAL'; + $rrd_options .= ' VDEF:tot'.$i.'=octets'.$i.',TOTAL'; } - $rrd_options .= "\l"; - } - $rrd_options .= " 'HRULE:0#" . $colour_out.":".$descr_out."'"; - $rrd_optionsb .= " 'AREA:outB".$i."_neg#" . $colour_out . "::$stack'"; - - if (!$nodetails) { - $rrd_options .= " GPRINT:outB".$i.":LAST:%6.2lf%s$units"; - $rrd_options .= " GPRINT:outB".$i.":AVERAGE:%6.2lf%s$units"; - $rrd_options .= " GPRINT:outB".$i.":MAX:%6.2lf%s$units"; - if (!$nototal) { - $rrd_options .= " GPRINT:totout".$i.":%6.2lf%s$total_unit"; + if ($i) { + $stack = 'STACK'; } - $rrd_options .= "\l"; - } - $rrd_options .= " 'COMMENT:\l'"; + $rrd_options .= ' AREA:inB'.$i.'#'.$colour_in.":'".$descr."':$stack"; + if (!$nodetails) { + $rrd_options .= ' GPRINT:inB'.$i.":LAST:%6.2lf%s$units"; + $rrd_options .= ' GPRINT:inB'.$i.":AVERAGE:%6.2lf%s$units"; + $rrd_options .= ' GPRINT:inB'.$i.":MAX:%6.2lf%s$units"; + if (!$nototal) { + $rrd_options .= ' GPRINT:totin'.$i.":%6.2lf%s$total_units"; + } - if ($i >= 1) { - $aggr_in .= ","; - $aggr_out .= ","; - } - if ($i > 1) { - $aggr_in .= "ADDNAN,"; - $aggr_out .= "ADDNAN,"; - } - $aggr_in .= $in.$i ; - $aggr_out .= $out.$i ; + $rrd_options .= '\l'; + } - $i++; $iter++; + $rrd_options .= " 'HRULE:0#".$colour_out.':'.$descr_out."'"; + $rrd_optionsb .= " 'AREA:outB".$i.'_neg#'.$colour_out."::$stack'"; + + if (!$nodetails) { + $rrd_options .= ' GPRINT:outB'.$i.":LAST:%6.2lf%s$units"; + $rrd_options .= ' GPRINT:outB'.$i.":AVERAGE:%6.2lf%s$units"; + $rrd_options .= ' GPRINT:outB'.$i.":MAX:%6.2lf%s$units"; + if (!$nototal) { + $rrd_options .= ' GPRINT:totout'.$i.":%6.2lf%s$total_unit"; + } + + $rrd_options .= '\l'; + } + + $rrd_options .= " 'COMMENT:\l'"; + + if ($i >= 1) { + $aggr_in .= ','; + $aggr_out .= ','; + } + + if ($i > 1) { + $aggr_in .= 'ADDNAN,'; + $aggr_out .= 'ADDNAN,'; + } + + $aggr_in .= $in.$i; + $aggr_out .= $out.$i; + + $i++; + $iter++; } -if (!$noagg){ - $rrd_options .= " CDEF:aggr".$in."bytes=" . $aggr_in.",ADDNAN"; - $rrd_options .= " CDEF:aggr".$out."bytes=" . $aggr_out.",ADDNAN"; - $rrd_options .= " CDEF:aggrinbits=aggrinbytes,".$multiplier.",*"; - $rrd_options .= " CDEF:aggroutbits=aggroutbytes,".$multiplier.",*"; - $rrd_options .= " VDEF:totalin=aggrinbytes,TOTAL"; - $rrd_options .= " VDEF:totalout=aggroutbytes,TOTAL"; - $rrd_options .= " COMMENT:' \\\\n'"; - $rrd_options .= " COMMENT:'".substr(str_pad("Aggregate In", $descr_len+5),0,$descr_len+5)."'"; - $rrd_options .= " GPRINT:aggrinbits:LAST:%6.2lf%s$units"; - $rrd_options .= " GPRINT:aggrinbits:AVERAGE:%6.2lf%s$units"; - $rrd_options .= " GPRINT:aggrinbits:MAX:%6.2lf%s$units"; - if (!$nototal) { - $rrd_options .= " GPRINT:totalin:%6.2lf%s$total_units"; - } - $rrd_options .= "\\\\n"; - $rrd_options .= " COMMENT:'".substr(str_pad("Aggregate Out", $descr_len+5),0,$descr_len+5)."'"; - $rrd_options .= " GPRINT:aggroutbits:LAST:%6.2lf%s$units"; - $rrd_options .= " GPRINT:aggroutbits:AVERAGE:%6.2lf%s$units"; - $rrd_options .= " GPRINT:aggroutbits:MAX:%6.2lf%s$units"; - if (!$nototal) { - $rrd_options .= " GPRINT:totalout:%6.2lf%s$total_units"; - } - $rrd_options .= "\\\\n"; +if (!$noagg) { + $rrd_options .= ' CDEF:aggr'.$in.'bytes='.$aggr_in.',ADDNAN'; + $rrd_options .= ' CDEF:aggr'.$out.'bytes='.$aggr_out.',ADDNAN'; + $rrd_options .= ' CDEF:aggrinbits=aggrinbytes,'.$multiplier.',*'; + $rrd_options .= ' CDEF:aggroutbits=aggroutbytes,'.$multiplier.',*'; + $rrd_options .= ' VDEF:totalin=aggrinbytes,TOTAL'; + $rrd_options .= ' VDEF:totalout=aggroutbytes,TOTAL'; + $rrd_options .= " COMMENT:' \\\\n'"; + $rrd_options .= " COMMENT:'".substr(str_pad('Aggregate In', ($descr_len + 5)), 0, ($descr_len + 5))."'"; + $rrd_options .= " GPRINT:aggrinbits:LAST:%6.2lf%s$units"; + $rrd_options .= " GPRINT:aggrinbits:AVERAGE:%6.2lf%s$units"; + $rrd_options .= " GPRINT:aggrinbits:MAX:%6.2lf%s$units"; + if (!$nototal) { + $rrd_options .= " GPRINT:totalin:%6.2lf%s$total_units"; + } + + $rrd_options .= "\\\\n"; + $rrd_options .= " COMMENT:'".substr(str_pad('Aggregate Out', ($descr_len + 5)), 0, ($descr_len + 5))."'"; + $rrd_options .= " GPRINT:aggroutbits:LAST:%6.2lf%s$units"; + $rrd_options .= " GPRINT:aggroutbits:AVERAGE:%6.2lf%s$units"; + $rrd_options .= " GPRINT:aggroutbits:MAX:%6.2lf%s$units"; + if (!$nototal) { + $rrd_options .= " GPRINT:totalout:%6.2lf%s$total_units"; + } + + $rrd_options .= "\\\\n"; } -if ($custom_graph) { $rrd_options .= $custom_graph; } +if ($custom_graph) { + $rrd_options .= $custom_graph; +} $rrd_options .= $rrd_optionsb; -$rrd_options .= " HRULE:0#999999"; - -?> +$rrd_options .= ' HRULE:0#999999'; diff --git a/html/includes/graphs/generic_multi_seperated.inc.php b/html/includes/graphs/generic_multi_seperated.inc.php index d6cf17271f..e672b143b9 100644 --- a/html/includes/graphs/generic_multi_seperated.inc.php +++ b/html/includes/graphs/generic_multi_seperated.inc.php @@ -1,185 +1,195 @@ +$rrd_options .= ' HRULE:0#999999'; diff --git a/html/includes/graphs/global/bits.inc.php b/html/includes/graphs/global/bits.inc.php index 674229ecfb..763a9d1032 100644 --- a/html/includes/graphs/global/bits.inc.php +++ b/html/includes/graphs/global/bits.inc.php @@ -6,8 +6,7 @@ $i = 0; foreach (dbFetchRows('SELECT * FROM `ports` AS P, `devices` AS D WHERE D.device_id = P.device_id ORDER BY P.ifInOctets_rate DESC') as $port) { $ignore = 0; if (is_array($config['device_traffic_iftype'])) { - foreach ($config['device_traffic_iftype'] as $iftype) - { + foreach ($config['device_traffic_iftype'] as $iftype) { if (preg_match($iftype.'i', $port['ifType'])) { $ignore = 1; } @@ -15,8 +14,7 @@ foreach (dbFetchRows('SELECT * FROM `ports` AS P, `devices` AS D WHERE D.device_ } if (is_array($config['device_traffic_descr'])) { - foreach ($config['device_traffic_descr'] as $ifdescr) - { + foreach ($config['device_traffic_descr'] as $ifdescr) { if (preg_match($ifdescr.'i', $port['ifDescr']) || preg_match($ifdescr.'i', $port['ifName']) || preg_match($ifdescr.'i', $port['portName'])) { $ignore = 1; } diff --git a/html/includes/graphs/graph.inc.php b/html/includes/graphs/graph.inc.php index 6ba9de57a8..19e99c9b69 100644 --- a/html/includes/graphs/graph.inc.php +++ b/html/includes/graphs/graph.inc.php @@ -1,188 +1,199 @@ $value) -{ - $vars[$name] = $value; +foreach ($_GET as $name => $value) { + $vars[$name] = $value; } preg_match('/^(?P[A-Za-z0-9]+)_(?P.+)/', $vars['type'], $graphtype); -if(is_numeric($vars['device'])) -{ - $device = device_by_id_cache($vars['device']); -} elseif(!empty($vars['device'])) { - $device = device_by_name($vars['device']); +if (is_numeric($vars['device'])) { + $device = device_by_id_cache($vars['device']); +} +else if (!empty($vars['device'])) { + $device = device_by_name($vars['device']); } // FIXME -- remove these - $width = $vars['width']; $height = $vars['height']; $title = $vars['title']; $vertical = $vars['vertical']; $legend = $vars['legend']; -$from = (isset($vars['from']) ? $vars['from'] : time() - 60*60*24); -$to = (isset($vars['to']) ? $vars['to'] : time()); +$from = (isset($vars['from']) ? $vars['from'] : time() - 60 * 60 * 24); +$to = (isset($vars['to']) ? $vars['to'] : time()); -if ($from < 0) { $from = $to + $from; } +if ($from < 0) { + $from = ($to + $from); +} -$period = $to - $from; +$period = ($to - $from); -$prev_from = $from - $period; +$prev_from = ($from - $period); -$graphfile = $config['temp_dir'] . "/" . strgen() . ".png"; +$graphfile = $config['temp_dir'].'/'.strgen().'.png'; -$type = $graphtype['type']; +$type = $graphtype['type']; $subtype = $graphtype['subtype']; if ($auth !== true && $auth != 1) { $auth = is_client_authorized($_SERVER['REMOTE_ADDR']); } -include($config['install_dir'] . "/html/includes/graphs/$type/auth.inc.php"); -if ($auth === true && is_file($config['install_dir'] . "/html/includes/graphs/$type/$subtype.inc.php")) { - include($config['install_dir'] . "/html/includes/graphs/$type/$subtype.inc.php"); +require $config['install_dir']."/html/includes/graphs/$type/auth.inc.php"; + +if ($auth === true && is_file($config['install_dir']."/html/includes/graphs/$type/$subtype.inc.php")) { + include $config['install_dir']."/html/includes/graphs/$type/$subtype.inc.php"; } -elseif ($auth === true && is_mib_graph($type, $subtype)) { - include($config['install_dir'] . "/html/includes/graphs/$type/mib.inc.php"); +else if ($auth === true && is_mib_graph($type, $subtype)) { + include $config['install_dir']."/html/includes/graphs/$type/mib.inc.php"; } else { - graph_error("$type*$subtype ");//Graph Template Missing"); + graph_error("$type*$subtype "); + // Graph Template Missing"); } -function graph_error($string) -{ - global $vars, $config, $debug, $graphfile; - $vars['bg'] = "FFBBBB"; +function graph_error($string) { + global $vars, $config, $debug, $graphfile; - include("includes/graphs/common.inc.php"); + $vars['bg'] = 'FFBBBB'; - $rrd_options .= " HRULE:0#555555"; - $rrd_options .= " --title='".$string."'"; + include 'includes/graphs/common.inc.php'; - rrdtool_graph($graphfile, $rrd_options); + $rrd_options .= ' HRULE:0#555555'; + $rrd_options .= " --title='".$string."'"; - if ($height > "99") { - shell_exec($rrd_cmd); - if ($debug) { echo("
    ".$rrd_cmd."
    "); } - if (is_file($graphfile) && !$debug) - { - header('Content-type: image/png'); - $fd = fopen($graphfile,'r'); fpassthru($fd); fclose($fd); - unlink($graphfile); - exit(); + rrdtool_graph($graphfile, $rrd_options); + + if ($height > '99') { + shell_exec($rrd_cmd); + if ($debug) { + echo '
    '.$rrd_cmd.'
    '; + } + + if (is_file($graphfile) && !$debug) { + header('Content-type: image/png'); + $fd = fopen($graphfile, 'r'); + fpassthru($fd); + fclose($fd); + unlink($graphfile); + exit(); + } } - } else { - if (!$debug) { header('Content-type: image/png'); } - $im = imagecreate($width, $height); - $px = (imagesx($im) - 7.5 * strlen($string)) / 2; - imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0)); - imagepng($im); - imagedestroy($im); - exit(); - } + else { + if (!$debug) { + header('Content-type: image/png'); + } + + $im = imagecreate($width, $height); + $px = ((imagesx($im) - 7.5 * strlen($string)) / 2); + imagestring($im, 3, $px, ($height / 2 - 8), $string, imagecolorallocate($im, 128, 0, 0)); + imagepng($im); + imagedestroy($im); + exit(); + } + } if ($error_msg) { - // We have an error :( - - graph_error($graph_error); - -} elseif ($auth === null) { - // We are unauthenticated :( - - if ($width < 200) - { - graph_error("No Auth"); - } else { - graph_error("No Authorisation"); - } -} else { - #$rrd_options .= " HRULE:0#999999"; - if ($no_file) - { - if ($width < 200) - { - graph_error("No RRD"); - } else { - graph_error("Missing RRD Datafile"); - } - } elseif($command_only) { - echo("
    "); - echo("

    RRDTool Command

    "); - echo("rrdtool graph $graphfile $rrd_options"); - echo(""); - $return = rrdtool_graph($graphfile, $rrd_options); - echo("

    "); - echo("

    RRDTool Output

    $return"); - unlink($graphfile); - echo("
    "); - } else { - - if ($rrd_options) - { - rrdtool_graph($graphfile, $rrd_options); - if ($debug) { echo($rrd_cmd); } - if (is_file($graphfile)) - { - if (!$debug) - { - header('Content-type: image/png'); - if ($config['trim_tobias']) - { - list($w, $h, $type, $attr) = getimagesize($graphfile); - $src_im = imagecreatefrompng($graphfile); - $src_x = '0'; // begin x - $src_y = '0'; // begin y - $src_w = $w-12; // width - $src_h = $h; // height - $dst_x = '0'; // destination x - $dst_y = '0'; // destination y - $dst_im = imagecreatetruecolor($src_w, $src_h); - imagesavealpha($dst_im, true); - $white = imagecolorallocate($dst_im, 255, 255, 255); - $trans_colour = imagecolorallocatealpha($dst_im, 0, 0, 0, 127); - imagefill($dst_im, 0, 0, $trans_colour); - imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); - imagepng($dst_im); - imagedestroy($dst_im); - } else { - $fd = fopen($graphfile,'r');fpassthru($fd);fclose($fd); - } - - } else { - echo(`ls -l $graphfile`); - echo('graph'); - } - unlink($graphfile); - } - else - { - if ($width < 200) - { - graph_error("Draw Error"); - } - else - { - graph_error("Error Drawing Graph"); - } - } - } - else - { - if ($width < 200) - { - graph_error("Def Error"); - } else { - graph_error("Graph Definition Error"); - } - } - } + // We have an error :( + graph_error($graph_error); } +else if ($auth === null) { + // We are unauthenticated :( + if ($width < 200) { + graph_error('No Auth'); + } + else { + graph_error('No Authorisation'); + } +} +else { + // $rrd_options .= " HRULE:0#999999"; + if ($no_file) { + if ($width < 200) { + graph_error('No RRD'); + } + else { + graph_error('Missing RRD Datafile'); + } + } + else if ($command_only) { + echo "
    "; + echo "

    RRDTool Command

    "; + echo "rrdtool graph $graphfile $rrd_options"; + echo ''; + $return = rrdtool_graph($graphfile, $rrd_options); + echo '

    '; + echo "

    RRDTool Output

    $return"; + unlink($graphfile); + echo '
    '; + } + else { + if ($rrd_options) { + rrdtool_graph($graphfile, $rrd_options); + if ($debug) { + echo $rrd_cmd; + } -?> + if (is_file($graphfile)) { + if (!$debug) { + header('Content-type: image/png'); + if ($config['trim_tobias']) { + list($w, $h, $type, $attr) = getimagesize($graphfile); + $src_im = imagecreatefrompng($graphfile); + $src_x = '0'; + // begin x + $src_y = '0'; + // begin y + $src_w = ($w - 12); + // width + $src_h = $h; + // height + $dst_x = '0'; + // destination x + $dst_y = '0'; + // destination y + $dst_im = imagecreatetruecolor($src_w, $src_h); + imagesavealpha($dst_im, true); + $white = imagecolorallocate($dst_im, 255, 255, 255); + $trans_colour = imagecolorallocatealpha($dst_im, 0, 0, 0, 127); + imagefill($dst_im, 0, 0, $trans_colour); + imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); + imagepng($dst_im); + imagedestroy($dst_im); + } + else { + $fd = fopen($graphfile, 'r'); + fpassthru($fd); + fclose($fd); + } + } + else { + echo `ls -l $graphfile`; + echo 'graph'; + } + unlink($graphfile); + } + else { + if ($width < 200) { + graph_error('Draw Error'); + } + else { + graph_error('Error Drawing Graph'); + } + } + } + else { + if ($width < 200) { + graph_error('Def Error'); + } + else { + graph_error('Graph Definition Error'); + } + } + } +} diff --git a/html/includes/graphs/location/bits.inc.php b/html/includes/graphs/location/bits.inc.php index 501b39c743..53b0a656e2 100644 --- a/html/includes/graphs/location/bits.inc.php +++ b/html/includes/graphs/location/bits.inc.php @@ -6,12 +6,10 @@ $ds_out = 'OUTOCTETS'; $i = 1; foreach ($devices as $device) { - foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($device['device_id'])) as $int) - { + foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($device['device_id'])) as $int) { $ignore = 0; if (is_array($config['device_traffic_iftype'])) { - foreach ($config['device_traffic_iftype'] as $iftype) - { + foreach ($config['device_traffic_iftype'] as $iftype) { if (preg_match($iftype.'i', $int['ifType'])) { $ignore = 1; } @@ -19,8 +17,7 @@ foreach ($devices as $device) { } if (is_array($config['device_traffic_descr'])) { - foreach ($config['device_traffic_descr'] as $ifdescr) - { + foreach ($config['device_traffic_descr'] as $ifdescr) { if (preg_match($ifdescr.'i', $int['ifDescr']) || preg_match($ifdescr.'i', $int['ifName']) || preg_match($ifdescr.'i', $int['portName'])) { $ignore = 1; } diff --git a/html/includes/graphs/mempool/auth.inc.php b/html/includes/graphs/mempool/auth.inc.php index 142952551e..bd507b89cc 100644 --- a/html/includes/graphs/mempool/auth.inc.php +++ b/html/includes/graphs/mempool/auth.inc.php @@ -1,17 +1,13 @@ diff --git a/html/includes/graphs/munin/auth.inc.php b/html/includes/graphs/munin/auth.inc.php index cf894de654..df77b06e76 100644 --- a/html/includes/graphs/munin/auth.inc.php +++ b/html/includes/graphs/munin/auth.inc.php @@ -1,20 +1,16 @@ +if (is_numeric($mplug['device_id']) && ($auth || device_permitted($mplug['device_id']))) { + $device = &$mplug; + $title = generate_device_link($device); + $plugfile = $config['rrd_dir'].'/'.$device['hostname'].'/munin/'.$mplug['mplug_type']; + $title .= ' :: Plugin :: '.$mplug['mplug_type'].' - '.$mplug['mplug_title']; + $auth = true; +} diff --git a/html/includes/graphs/munin/graph.inc.php b/html/includes/graphs/munin/graph.inc.php index 21521c60a5..9b634813ba 100644 --- a/html/includes/graphs/munin/graph.inc.php +++ b/html/includes/graphs/munin/graph.inc.php @@ -43,7 +43,7 @@ foreach ($dbq as $ds) { $colour = $config['graph_colours']['mixed'][$c_i]; $c_i++; - } + } else { $colour = $ds['colour']; } diff --git a/html/includes/graphs/port/auth.inc.php b/html/includes/graphs/port/auth.inc.php index a11959eb34..68114f8c4a 100644 --- a/html/includes/graphs/port/auth.inc.php +++ b/html/includes/graphs/port/auth.inc.php @@ -1,20 +1,17 @@ diff --git a/html/includes/graphs/port/nupkts.inc.php b/html/includes/graphs/port/nupkts.inc.php index e26f5e449a..6b8d11b2d8 100644 --- a/html/includes/graphs/port/nupkts.inc.php +++ b/html/includes/graphs/port/nupkts.inc.php @@ -1,7 +1,7 @@ diff --git a/html/includes/graphs/processor/usage.inc.php b/html/includes/graphs/processor/usage.inc.php index 3812a1432d..5954685d77 100644 --- a/html/includes/graphs/processor/usage.inc.php +++ b/html/includes/graphs/processor/usage.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/rserver/auth.inc.php b/html/includes/graphs/rserver/auth.inc.php index d179370bce..d166efd19d 100644 --- a/html/includes/graphs/rserver/auth.inc.php +++ b/html/includes/graphs/rserver/auth.inc.php @@ -1,6 +1,6 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/rserver/failed.inc.php b/html/includes/graphs/rserver/failed.inc.php index 291cdd3963..60f544bbaf 100644 --- a/html/includes/graphs/rserver/failed.inc.php +++ b/html/includes/graphs/rserver/failed.inc.php @@ -2,7 +2,7 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; $graph_max = 1; @@ -16,6 +16,4 @@ $colour_area_max = "FFEE99"; $nototal = 1; $unit_text = "Conns"; -include("includes/graphs/generic_simplex.inc.php"); - -?> +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/rserver/total.inc.php b/html/includes/graphs/rserver/total.inc.php index e4efdc81f5..9d39f6bce3 100644 --- a/html/includes/graphs/rserver/total.inc.php +++ b/html/includes/graphs/rserver/total.inc.php @@ -2,20 +2,18 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; $graph_max = 1; -$ds = "RserverTotalConns"; +$ds = 'RserverTotalConns'; -$colour_area = "B0C4DE"; -$colour_line = "191970"; +$colour_area = 'B0C4DE'; +$colour_line = '191970'; -$colour_area_max = "FFEE99"; +$colour_area_max = 'FFEE99'; $nototal = 1; -$unit_text = "Conns"; +$unit_text = 'Conns'; -include("includes/graphs/generic_simplex.inc.php"); - -?> +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/sensor/charge.inc.php b/html/includes/graphs/sensor/charge.inc.php index 331d4ff1a4..e400153ae1 100644 --- a/html/includes/graphs/sensor/charge.inc.php +++ b/html/includes/graphs/sensor/charge.inc.php @@ -1,9 +1,9 @@ +if (is_numeric($sensor['sensor_limit'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit'].'#999999::dashes'; +} + +if (is_numeric($sensor['sensor_limit_low'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; +} diff --git a/html/includes/graphs/sensor/current.inc.php b/html/includes/graphs/sensor/current.inc.php index b496c002ab..f1ca4abdd6 100644 --- a/html/includes/graphs/sensor/current.inc.php +++ b/html/includes/graphs/sensor/current.inc.php @@ -19,5 +19,5 @@ if (is_numeric($sensor['sensor_limit'])) { } if (is_numeric($sensor['sensor_limit_low'])) { - $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; } diff --git a/html/includes/graphs/sensor/dbm.inc.php b/html/includes/graphs/sensor/dbm.inc.php index 5880ddafc3..32d6a57fc0 100644 --- a/html/includes/graphs/sensor/dbm.inc.php +++ b/html/includes/graphs/sensor/dbm.inc.php @@ -19,5 +19,5 @@ if (is_numeric($sensor['sensor_limit'])) { } if (is_numeric($sensor['sensor_limit_low'])) { - $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; } diff --git a/html/includes/graphs/sensor/load.inc.php b/html/includes/graphs/sensor/load.inc.php index 095f0eb2e7..050f58a0bd 100644 --- a/html/includes/graphs/sensor/load.inc.php +++ b/html/includes/graphs/sensor/load.inc.php @@ -1,22 +1,25 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; +} diff --git a/html/includes/graphs/sensor/state.inc.php b/html/includes/graphs/sensor/state.inc.php index 281b1932fc..e04e7dc294 100644 --- a/html/includes/graphs/sensor/state.inc.php +++ b/html/includes/graphs/sensor/state.inc.php @@ -1,17 +1,21 @@ \ No newline at end of file +$rrd_options .= ' CDEF:percent=status,100,*'; +$rrd_options .= ' CDEF:down=status,1,LT,status,UNKN,IF'; +$rrd_options .= ' CDEF:percentdown=down,100,*'; +$rrd_options .= ' AREA:percent#CCFFCC'; +$rrd_options .= ' AREA:percentdown#FFCCCC'; +$rrd_options .= " LINE1.5:percent#009900:'".$service_text."'"; +// Ugly hack :( +$rrd_options .= ' LINE1.5:percentdown#cc0000'; +$rrd_options .= ' GPRINT:status:LAST:%3.0lf'; +$rrd_options .= ' GPRINT:percent:AVERAGE:%3.5lf%%\\\\l'; diff --git a/html/includes/graphs/storage/auth.inc.php b/html/includes/graphs/storage/auth.inc.php index 0e26713042..47f8189aa6 100644 --- a/html/includes/graphs/storage/auth.inc.php +++ b/html/includes/graphs/storage/auth.inc.php @@ -1,18 +1,14 @@ diff --git a/html/includes/graphs/toner/auth.inc.php b/html/includes/graphs/toner/auth.inc.php index 928b7af38a..72222f18f4 100644 --- a/html/includes/graphs/toner/auth.inc.php +++ b/html/includes/graphs/toner/auth.inc.php @@ -1,18 +1,14 @@ diff --git a/html/includes/graphs/toner/usage.inc.php b/html/includes/graphs/toner/usage.inc.php index 3849b279c2..2b617eb8ba 100644 --- a/html/includes/graphs/toner/usage.inc.php +++ b/html/includes/graphs/toner/usage.inc.php @@ -1,24 +1,24 @@ +$rrd_options .= ' AREA:toner'.$toner['toner_id'].'#'.$background['right'].':'; +$rrd_options .= ' GPRINT:toner'.$toner['toner_id'].":LAST:'%5.0lf%%'"; +$rrd_options .= ' GPRINT:toner'.$toner['toner_id'].':MAX:%5.0lf%%\\\\l'; diff --git a/html/includes/graphs/vserver/auth.inc.php b/html/includes/graphs/vserver/auth.inc.php index 2d16279db5..4cb444871e 100644 --- a/html/includes/graphs/vserver/auth.inc.php +++ b/html/includes/graphs/vserver/auth.inc.php @@ -1,6 +1,6 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/hostbox-menu.inc.php b/html/includes/hostbox-menu.inc.php index 702941a310..03a9bb2775 100644 --- a/html/includes/hostbox-menu.inc.php +++ b/html/includes/hostbox-menu.inc.php @@ -12,33 +12,33 @@ * the source code distribution for details. */ -echo(''); - if (device_permitted($device['device_id'])) { - echo ('
    -
    '); - echo ' View device '; - echo ('
    -
    '); - echo ' View alerts '; - echo '
    '; - if ($_SESSION['userlevel'] >= "7") { - echo ('
    - Edit device -
    '); - } - echo ('
    -
    -
    - telnet -
    -
    - ssh -
    -
    - https -
    -
    '); +echo ''; +if (device_permitted($device['device_id'])) { + echo '
    +
    '; + echo ' View device '; + echo '
    +
    '; + echo ' View alerts '; + echo '
    '; + if ($_SESSION['userlevel'] >= '7') { + echo '
    + Edit device +
    '; } -echo(''); -?> + echo '
    +
    +
    + telnet +
    +
    + ssh +
    +
    + https +
    +
    '; +}//end if + +echo ''; diff --git a/html/includes/hostbox-public.inc.php b/html/includes/hostbox-public.inc.php index 47b4d23cc3..ac30376885 100644 --- a/html/includes/hostbox-public.inc.php +++ b/html/includes/hostbox-public.inc.php @@ -1,61 +1,73 @@ -* -* 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 3 of the License, or (at your -* option) any later version. Please see LICENSE.txt at the top level of -* the source code distribution for details. + * This file is part of LibreNMS + * + * Copyright (c) 2014 Bohdan Sanders + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ ?> - - ' . $image . ' - ' . generate_device_link($device) . '' - ); +echo ' + + '.$image.' + '.generate_device_link($device).''; -echo(''); -if ($port_count) { echo(' '.$port_count); } -echo('
    '); -if ($sensor_count) { echo(' '.$sensor_count); } -echo(''); -echo(' ' . $device['hardware'] . ' ' . $device['features'] . ''); -echo(' ' . formatUptime($device['uptime'], 'short') . '
    '); +echo ''; +if ($port_count) { + echo ' '.$port_count; +} -if (get_dev_attrib($device,'override_sysLocation_bool')) { $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); } -echo(' ' . truncate($device['location'],32, '') . ''); +echo '
    '; +if ($sensor_count) { + echo ' '.$sensor_count; +} -echo(' '); +echo ''; +echo ' '.$device['hardware'].' '.$device['features'].''; +echo ' '.formatUptime($device['uptime'], 'short').'
    '; -?> +if (get_dev_attrib($device, 'override_sysLocation_bool')) { + $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); +} + +echo ' '.truncate($device['location'], 32, '').''; + +echo ' '; diff --git a/html/includes/javascript-interfacepicker.inc.php b/html/includes/javascript-interfacepicker.inc.php index 7fcdf11a9f..c5a8c932f4 100644 --- a/html/includes/javascript-interfacepicker.inc.php +++ b/html/includes/javascript-interfacepicker.inc.php @@ -24,4 +24,3 @@ function createInterfaces(index) } - diff --git a/html/includes/jpgraph/src/contour_dev/findpolygon.php b/html/includes/jpgraph/src/contour_dev/findpolygon.php index 4d105280ff..675c74c2e1 100644 --- a/html/includes/jpgraph/src/contour_dev/findpolygon.php +++ b/html/includes/jpgraph/src/contour_dev/findpolygon.php @@ -98,16 +98,20 @@ class Findpolygon { array_pop($b); } - $n1 = count($a); $n2 = count($b); - if( $n1 != $n2 ) + $n1 = count($a); + $n2 = count($b); + if( $n1 != $n2 ) { return false; + } $i=0; - while( ($i < $n2) && ($a[0] != $b[$i]) ) + while( ($i < $n2) && ($a[0] != $b[$i]) ) { ++$i; + } - if( $i >= $n2 ) + if( $i >= $n2 ) { return false; + } $j=0; if( $forward ) { diff --git a/html/includes/jpgraph/src/contour_dev/tri-quad.php b/html/includes/jpgraph/src/contour_dev/tri-quad.php index 7281f8e369..826d1bf013 100644 --- a/html/includes/jpgraph/src/contour_dev/tri-quad.php +++ b/html/includes/jpgraph/src/contour_dev/tri-quad.php @@ -59,11 +59,14 @@ class ContCanvas { function DrawLinePolygons($p,$color='red') { $this->shape->SetColor($color); for ($i = 0 ; $i < count($p) ; $i++) { - $x1 = $p[$i][0][0]; $y1 = $p[$i][0][1]; + $x1 = $p[$i][0][0]; + $y1 = $p[$i][0][1]; for ($j = 1 ; $j < count($p[$i]) ; $j++) { - $x2=$p[$i][$j][0]; $y2 = $p[$i][$j][1]; + $x2=$p[$i][$j][0]; + $y2 = $p[$i][$j][1]; $this->shape->Line($x1, $y1, $x2, $y2); - $x1=$x2; $y1=$y2; + $x1=$x2; + $y1=$y2; } } } @@ -138,7 +141,7 @@ class SingleTestTriangle { //$this->g->InitFrame(); self::$t = new Text(); - self::$t->SetColor('black'); + self::$t->SetColor('black'); self::$t->SetFont(FF_ARIAL,FS_BOLD,9); self::$t->SetAlign('center','center'); } @@ -487,7 +490,8 @@ class SingleTestTriangle { $pl1 = array($x1p,$y1p,$x4p,$y4p); $colorl2 = $this->GetColor($v2p); $pl2 = array($x2p,$y2p,$x3p,$y3p); - $vl1 = $v1p; $vl2 = $v2p; + $vl1 = $v1p; + $vl2 = $v2p; } else { @@ -505,7 +509,8 @@ class SingleTestTriangle { $pl1 = array($x1p,$y1p,$x2p,$y2p); $colorl2 = $this->GetColor($v4p); $pl2 = array($x4p,$y4p,$x3p,$y3p); - $vl1 = $v1p; $vl2 = $v4p; + $vl1 = $v1p; + $vl2 = $v4p; } } else { @@ -526,7 +531,8 @@ class SingleTestTriangle { $pl1 = array($x1p,$y1p,$x2p,$y2p); $colorl2 = $this->GetColor($v4p); $pl2 = array($x4p,$y4p,$x3p,$y3p); - $vl1 = $v1p; $vl2 = $v4p; + $vl1 = $v1p; + $vl2 = $v4p; } else { //( $v1p == $v4p ) // "\" @@ -543,7 +549,8 @@ class SingleTestTriangle { $pl1 = array($x1p,$y1p,$x4p,$y4p); $colorl2 = $this->GetColor($v2p); $pl2 = array($x2p,$y2p,$x3p,$y3p); - $vl1 = $v1p; $vl2 = $v2p; + $vl1 = $v1p; + $vl2 = $v2p; } } $this->FillPolygon($color1,$p1); @@ -730,9 +737,12 @@ class SingleTestTriangle { } function Fill($v1,$v2,$v3,$maxdepth) { - $x1=0; $y1=1; - $x2=1; $y2=0; - $x3=1; $y3=1; + $x1=0; + $y1=1; + $x2=1; + $y2=0; + $x3=1; + $y3=1; self::$maxdepth = $maxdepth; $this->TriFill($v1, $v2, $v3, $x1, $y1, $x2, $y2, $x3, $y3, 0); } diff --git a/html/includes/modal/alert_schedule.inc.php b/html/includes/modal/alert_schedule.inc.php index 7c6b7b628e..b726a219f6 100644 --- a/html/includes/modal/alert_schedule.inc.php +++ b/html/includes/modal/alert_schedule.inc.php @@ -223,5 +223,3 @@ $(function () { diff --git a/html/includes/modal/new_alert_rule.inc.php b/html/includes/modal/new_alert_rule.inc.php index cce990eb4d..5d4ff60765 100644 --- a/html/includes/modal/new_alert_rule.inc.php +++ b/html/includes/modal/new_alert_rule.inc.php @@ -391,5 +391,3 @@ $( "#suggest, #value" ).blur(function() { diff --git a/html/includes/modal/new_device_group.inc.php b/html/includes/modal/new_device_group.inc.php index aa5717b28a..d1dc5d6f4d 100644 --- a/html/includes/modal/new_device_group.inc.php +++ b/html/includes/modal/new_device_group.inc.php @@ -246,5 +246,3 @@ $( "#name, #suggest, #value" ).blur(function() { diff --git a/html/includes/modal/poller_groups.inc.php b/html/includes/modal/poller_groups.inc.php index c966da6ac2..ccbfe22458 100644 --- a/html/includes/modal/poller_groups.inc.php +++ b/html/includes/modal/poller_groups.inc.php @@ -13,7 +13,9 @@ if(is_admin() === false) { echo ('ERROR: You need to be admin'); -} else { +} +else { + ?> '-1', 'rule' => '%macros.device_down = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Devices up/down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%devices.uptime < "300" && %macros.device = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Device rebooted'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerState != "established" && %macros.device_up = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session establised'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%macros.port_down = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Port status up/down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%macros.port_usage_perc >= "80"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Port utilisation over threshold'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor over limit'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor under limit'); - foreach( $default_rules as $add_rule ) { - dbInsert($add_rule,'alert_rules'); +if (isset($_POST['create-default'])) { + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%macros.device_down = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Devices up/down', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%devices.uptime < "300" && %macros.device = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Device rebooted', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%bgpPeers.bgpPeerState != "established" && %macros.device_up = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'BGP Session down', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'BGP Session establised', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%macros.port_down = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Port status up/down', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%macros.port_usage_perc >= "80"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Port utilisation over threshold', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Sensor over limit', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Sensor under limit', + ); + foreach ($default_rules as $add_rule) { + dbInsert($add_rule, 'alert_rules'); } -} - -require_once('includes/modal/new_alert_rule.inc.php'); -require_once('includes/modal/delete_alert_rule.inc.php'); +}//end if +require_once 'includes/modal/new_alert_rule.inc.php'; +require_once 'includes/modal/delete_alert_rule.inc.php'; ?>
    0) { +if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) { $results = $_POST['results']; -} else { +} +else { $results = 50; } echo '
    - - +
    + @@ -49,126 +103,150 @@ echo '
    - '; + '; -echo (' - + '); -$rulei=1; -$count_query = "SELECT COUNT(id)"; -$full_query = "SELECT *"; -$sql = ''; -$param = array(); -if(isset($device['device_id']) && $device['device_id'] > 0) { - $sql = 'WHERE (device_id=? OR device_id="-1")'; +echo ''; + +$rulei = 1; +$count_query = 'SELECT COUNT(id)'; +$full_query = 'SELECT *'; +$sql = ''; +$param = array(); +if (isset($device['device_id']) && $device['device_id'] > 0) { + $sql = 'WHERE (device_id=? OR device_id="-1")'; $param = array($device['device_id']); } -$query = " FROM alert_rules $sql ORDER BY device_id,id"; -$count_query = $count_query . $query; -$count = dbFetchCell($count_query,$param); -if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { + +$query = " FROM alert_rules $sql ORDER BY device_id,id"; +$count_query = $count_query.$query; +$count = dbFetchCell($count_query, $param); +if (!isset($_POST['page_number']) && $_POST['page_number'] < 1) { $page_number = 1; -} else { +} +else { $page_number = $_POST['page_number']; } -$start = ($page_number - 1) * $results; -$full_query = $full_query . $query . " LIMIT $start,$results"; -foreach( dbFetchRows($full_query, $param) as $rule ) { - $sub = dbFetchRows("SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'])); - $ico = "ok"; - $col = "success"; - $extra = ""; - if( sizeof($sub) == 1 ) { - $sub = $sub[0]; - if( (int) $sub['state'] === 0 ) { - $ico = "ok"; - $col = "success"; - } elseif( (int) $sub['state'] === 1 ) { - $ico = "remove"; - $col = "danger"; - $extra = "danger"; - } elseif( (int) $sub['state'] === 2 ) { - $ico = "time"; - $col = "default"; - $extra = "warning"; - } - } - $alert_checked = ''; - $orig_ico = $ico; - $orig_col = $col; - $orig_class = $extra; - if( $rule['disabled'] ) { - $ico = "pause"; - $col = ""; - $extra = "active"; - } else { - $alert_checked = 'checked'; +$start = (($page_number - 1) * $results); +$full_query = $full_query.$query." LIMIT $start,$results"; + +foreach (dbFetchRows($full_query, $param) as $rule) { + $sub = dbFetchRows('SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1', array($rule['id'])); + $ico = 'ok'; + $col = 'success'; + $extra = ''; + if (sizeof($sub) == 1) { + $sub = $sub[0]; + if ((int) $sub['state'] === 0) { + $ico = 'ok'; + $col = 'success'; } - $rule_extra = json_decode($rule['extra'],TRUE); - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + else if ((int) $sub['state'] === 2) { + $ico = 'time'; + $col = 'default'; + $extra = 'warning'; } - echo ""; - echo ""; - echo ""; - echo "\r\n"; + } + + $alert_checked = ''; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; + if ($rule['disabled']) { + $ico = 'pause'; + $col = ''; + $extra = 'active'; + } + else { + $alert_checked = 'checked'; + } + + $rule_extra = json_decode($rule['extra'], true); + echo ""; + echo ''; + echo ''; + echo "'; + echo ''; + echo ""; + } + + echo ''; + echo ''; + echo ''; + echo "\r\n"; +}//end foreach + +if (($count % $results) > 0) { + echo ' + + '; } -if($count % $results > 0) { - echo(' - - '); -} echo '
    # Name RuleExtra Enabled Action
    '); +echo ''; if ($_SESSION['userlevel'] >= '10') { - echo(''); + echo ''; } -echo ('
    #".((int) $rulei++)."".$rule['name'].""; - if($rule_extra['invert'] === true) { - echo "Inverted "; + else if ((int) $sub['state'] === 1) { + $ico = 'remove'; + $col = 'danger'; + $extra = 'danger'; } - echo "".htmlentities($rule['rule'])."".$rule['severity']." "; - if($rule_extra['mute'] === true) { - echo "Max: ".$rule_extra['count']."
    Delay: ".$rule_extra['delay']."
    Interval: ".$rule_extra['interval']."
    "; - if ($_SESSION['userlevel'] >= '10') { - echo ""; - } - echo ""; - if ($_SESSION['userlevel'] >= '10') { - echo " "; - echo ""; - } - echo "
    #'.((int) $rulei++).''.$rule['name'].'"; + if ($rule_extra['invert'] === true) { + echo 'Inverted '; + } + + echo ''.htmlentities($rule['rule']).''.$rule['severity'].' "; + if ($rule_extra['mute'] === true) { + echo "Max: '.$rule_extra['count'].'
    Delay: '.$rule_extra['delay'].'
    Interval: '.$rule_extra['interval'].'
    '; + if ($_SESSION['userlevel'] >= '10') { + echo ""; + } + + echo ''; + if ($_SESSION['userlevel'] >= '10') { + echo " "; + echo ""; + } + + echo '
    '.generate_pagination($count, $results, $page_number).'
    '. generate_pagination($count,$results,$page_number) .'
    - - - -
    '; + + + + '; -if($count < 1) { +if ($count < 1) { if ($_SESSION['userlevel'] >= '10') { echo '
    -
    -
    -

    - -

    -
    -
    -
    '; +
    +
    +

    + +

    +
    +
    + '; } } @@ -180,19 +258,19 @@ $('#ack-alert').click('', function(e) { var alert_id = $(this).data("alert_id"); $.ajax({ type: "POST", - url: "/ajax_form.php", - data: { type: "ack-alert", alert_id: alert_id }, - success: function(msg){ - $("#message").html('
    '+msg+'
    '); - if(msg.indexOf("ERROR:") <= -1) { - setTimeout(function() { - location.reload(1); - }, 1000); - } - }, - error: function(){ - $("#message").html('
    An error occurred acking this alert.
    '); - } + url: "/ajax_form.php", + data: { type: "ack-alert", alert_id: alert_id }, + success: function(msg){ + $("#message").html('
    '+msg+'
    '); + if(msg.indexOf("ERROR:") <= -1) { + setTimeout(function() { + location.reload(1); + }, 1000); + } + }, + error: function(){ + $("#message").html('
    An error occurred acking this alert.
    '); + } }); }); @@ -206,42 +284,42 @@ $('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event var orig_class = $(this).data("orig_class"); $.ajax({ type: 'POST', - url: '/ajax_form.php', - data: { type: "update-alert-rule", alert_id: alert_id, state: state }, - dataType: "html", - success: function(msg) { - if(msg.indexOf("ERROR:") <= -1) { - if(state) { - $('#alert-rule-'+alert_id).removeClass('glyphicon-pause'); - $('#alert-rule-'+alert_id).addClass('glyphicon-'+orig_state); - $('#alert-rule-'+alert_id).removeClass('text-default'); - $('#alert-rule-'+alert_id).addClass('text-'+orig_colour); - $('#row_'+alert_id).removeClass('active'); - $('#row_'+alert_id).addClass(orig_class); + url: '/ajax_form.php', + data: { type: "update-alert-rule", alert_id: alert_id, state: state }, + dataType: "html", + success: function(msg) { + if(msg.indexOf("ERROR:") <= -1) { + if(state) { + $('#alert-rule-'+alert_id).removeClass('glyphicon-pause'); + $('#alert-rule-'+alert_id).addClass('glyphicon-'+orig_state); + $('#alert-rule-'+alert_id).removeClass('text-default'); + $('#alert-rule-'+alert_id).addClass('text-'+orig_colour); + $('#row_'+alert_id).removeClass('active'); + $('#row_'+alert_id).addClass(orig_class); + } else { + $('#alert-rule-'+alert_id).removeClass('glyphicon-'+orig_state); + $('#alert-rule-'+alert_id).addClass('glyphicon-pause'); + $('#alert-rule-'+alert_id).removeClass('text-'+orig_colour); + $('#alert-rule-'+alert_id).addClass('text-default'); + $('#row_'+alert_id).removeClass('warning'); + $('#row_'+alert_id).addClass('active'); + } } else { - $('#alert-rule-'+alert_id).removeClass('glyphicon-'+orig_state); - $('#alert-rule-'+alert_id).addClass('glyphicon-pause'); - $('#alert-rule-'+alert_id).removeClass('text-'+orig_colour); - $('#alert-rule-'+alert_id).addClass('text-default'); - $('#row_'+alert_id).removeClass('warning'); - $('#row_'+alert_id).addClass('active'); + $("#message").html('
    '+msg+'
    '); + $('#'+alert_id).bootstrapSwitch('toggleState',true ); + } + }, + error: function() { + $("#message").html('
    This alert could not be updated.
    '); + $('#'+alert_id).bootstrapSwitch('toggleState',true ); } - } else { - $("#message").html('
    '+msg+'
    '); - $('#'+alert_id).bootstrapSwitch('toggleState',true ); - } - }, - error: function() { - $("#message").html('
    This alert could not be updated.
    '); - $('#'+alert_id).bootstrapSwitch('toggleState',true ); - } }); }); function updateResults(results) { - $('#results_amount').val(results.value); - $('#page_number').val(1); - $('#result_form').submit(); + $('#results_amount').val(results.value); + $('#page_number').val(1); + $('#result_form').submit(); } function changePage(page,e) { diff --git a/html/includes/print-alert-templates.php b/html/includes/print-alert-templates.php index 16a3afdd08..8ad6e8265d 100644 --- a/html/includes/print-alert-templates.php +++ b/html/includes/print-alert-templates.php @@ -1,6 +1,6 @@ @@ -10,17 +10,17 @@ $no_refresh = TRUE;
    0) { +if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) { $results = $_POST['results']; -} else { +} +else { $results = 50; } @@ -34,37 +34,49 @@ echo '
    '; if ($_SESSION['userlevel'] >= '10') { - echo(''); + echo ''; } echo ' '); -$count_query = "SELECT COUNT(id)"; -$full_query = "SELECT *"; +echo ''; -$query = " FROM `alert_templates`"; +$count_query = 'SELECT COUNT(id)'; +$full_query = 'SELECT *'; -$count_query = $count_query . $query; -$count = dbFetchCell($count_query,$param); -if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { +$query = ' FROM `alert_templates`'; + +$count_query = $count_query.$query; +$count = dbFetchCell($count_query, $param); +if (!isset($_POST['page_number']) && $_POST['page_number'] < 1) { $page_number = 1; -} else { +} +else { $page_number = $_POST['page_number']; } -$start = ($page_number - 1) * $results; -$full_query = $full_query . $query . " LIMIT $start,$results"; -foreach( dbFetchRows($full_query, $param) as $template ) { +$start = (($page_number - 1) * $results); +$full_query = $full_query.$query." LIMIT $start,$results"; + +foreach (dbFetchRows($full_query, $param) as $template) { echo ' '.$template['name'].' '; @@ -73,14 +85,15 @@ foreach( dbFetchRows($full_query, $param) as $template ) { echo " "; echo ""; } + echo ' '; } -if($count % $results > 0) { - echo(' - '. generate_pagination($count,$results,$page_number) .' - '); +if (($count % $results) > 0) { + echo ' + '.generate_pagination($count, $results, $page_number).' + '; } echo ' diff --git a/html/includes/print-alerts.inc.php b/html/includes/print-alerts.inc.php index dcbab4b3d9..d9758a0f38 100644 --- a/html/includes/print-alerts.inc.php +++ b/html/includes/print-alerts.inc.php @@ -1,49 +1,49 @@ - - ' . $alert_entry['time_logged'] . ' - '); +echo ' + + '.$alert_entry['time_logged'].' + '; if (!isset($alert_entry['device'])) { - $dev = device_by_id_cache($alert_entry['device_id']); - echo(" - " . generate_device_link($dev, shorthost($dev['hostname'])) . " - "); + $dev = device_by_id_cache($alert_entry['device_id']); + echo ' + '.generate_device_link($dev, shorthost($dev['hostname'])).' + '; } -echo("".htmlspecialchars($alert_entry['name']) . ""); +echo ''.htmlspecialchars($alert_entry['name']).''; -if ($alert_state!='') { - if ($alert_state=='0') { - $glyph_icon = 'ok'; +if ($alert_state != '') { + if ($alert_state == '0') { + $glyph_icon = 'ok'; $glyph_color = 'green'; - $text = 'Ok'; + $text = 'Ok'; } - elseif ($alert_state=='1') { - $glyph_icon = 'remove'; + else if ($alert_state == '1') { + $glyph_icon = 'remove'; $glyph_color = 'red'; - $text = 'Alert'; + $text = 'Alert'; } - elseif ($alert_state=='2') { - $glyph_icon = 'info-sign'; + else if ($alert_state == '2') { + $glyph_icon = 'info-sign'; $glyph_color = 'lightgrey'; - $text = 'Ack'; + $text = 'Ack'; } - elseif ($alert_state=='3') { - $glyph_icon = 'arrow-down'; + else if ($alert_state == '3') { + $glyph_icon = 'arrow-down'; $glyph_color = 'orange'; - $text = 'Worse'; + $text = 'Worse'; } - elseif ($alert_state=='4') { - $glyph_icon = 'arrow-up'; + else if ($alert_state == '4') { + $glyph_icon = 'arrow-up'; $glyph_color = 'khaki'; - $text = 'Better'; - } - echo(" $text"); -} + $text = 'Better'; + }//end if + echo " $text"; +}//end if -echo(""); +echo ''; diff --git a/html/includes/print-debug.php b/html/includes/print-debug.php index f35cd05bfe..7fdbbcc6d9 100644 --- a/html/includes/print-debug.php +++ b/html/includes/print-debug.php @@ -1,6 +1,6 @@ @@ -14,25 +14,23 @@ @@ -52,26 +50,25 @@ foreach ($sql_debug as $sql_error) { @@ -97,10 +95,12 @@ if ($_SESSION['userlevel'] >= '10') { if (is_admin() === TRUE || is_read() === TRUE) { $sql = "SELECT `type`,COUNT(`type`) AS total_type FROM `devices` AS D WHERE 1 GROUP BY `type` ORDER BY `type`"; -} else { +} +else { $sql = "SELECT `type`,COUNT(`type`) AS total_type FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `type` ORDER BY `type`"; $param[] = $_SESSION['user_id']; } + foreach (dbFetchRows($sql,$param) as $devtype) { if (empty($devtype['type'])) { $devtype['type'] = 'generic'; @@ -108,9 +108,10 @@ foreach (dbFetchRows($sql,$param) as $devtype) { echo('
  • ' . ucfirst($devtype['type']) . '
  • '); } -require_once('../includes/device-groups.inc.php'); +require_once '../includes/device-groups.inc.php'; + foreach( GetDeviceGroups() as $group ) { - echo '
  • '.ucfirst($group['name']).'
  • '; + echo '
  • '.ucfirst($group['name']).'
  • '; } unset($group); @@ -118,29 +119,24 @@ unset($group); '); if ($_SESSION['userlevel'] >= '10') { -if ($config['show_locations']) -{ - - echo(' + if ($config['show_locations']) { + echo(' - '); -} - echo(' + '); + } + echo('
  • Manage Groups
  • Add Device
  • @@ -155,8 +151,7 @@ if ($config['show_locations'])
  • Alerts ('.$service_alerts.')
  • '); } -if ($_SESSION['userlevel'] >= '10') -{ - echo(' +if ($_SESSION['userlevel'] >= '10') { + echo('
  • Add Service
  • Edit Service
  • @@ -197,36 +190,53 @@ if ($_SESSION['userlevel'] >= '10') 0) -{ - echo('
  • Errored ('.$ports['errored'].')
  • '); +if ($ports['errored'] > 0) { + echo('
  • Errored ('.$ports['errored'].')
  • '); } -if ($ports['ignored'] > 0) -{ - echo('
  • Ignored ('.$ports['ignored'].')
  • '); +if ($ports['ignored'] > 0) { + echo('
  • Ignored ('.$ports['ignored'].')
  • '); } if ($config['enable_billing']) { - echo('
  • Traffic Bills
  • '); $ifbreak = 1; + echo('
  • Traffic Bills
  • '); + $ifbreak = 1; } if ($config['enable_pseudowires']) { - echo('
  • Pseudowires
  • '); $ifbreak = 1; + echo('
  • Pseudowires
  • '); + $ifbreak = 1; } ?> = '5') -{ - echo(' '); - if ($config['int_customers']) { echo('
  • Customers
  • '); $ifbreak = 1; } - if ($config['int_l2tp']) { echo('
  • L2TP
  • '); $ifbreak = 1; } - if ($config['int_transit']) { echo('
  • Transit
  • '); $ifbreak = 1; } - if ($config['int_peering']) { echo('
  • Peering
  • '); $ifbreak = 1; } - if ($config['int_peering'] && $config['int_transit']) { echo('
  • Peering + Transit
  • '); $ifbreak = 1; } - if ($config['int_core']) { echo('
  • Core
  • '); $ifbreak = 1; } +if ($_SESSION['userlevel'] >= '5') { + echo(' '); + if ($config['int_customers']) { + echo('
  • Customers
  • '); + $ifbreak = 1; + } + if ($config['int_l2tp']) { + echo('
  • L2TP
  • '); + $ifbreak = 1; + } + if ($config['int_transit']) { + echo('
  • Transit
  • '); + $ifbreak = 1; + } + if ($config['int_peering']) { + echo('
  • Peering
  • '); + $ifbreak = 1; + } + if ($config['int_peering'] && $config['int_transit']) { + echo('
  • Peering + Transit
  • '); + $ifbreak = 1; + } + if ($config['int_core']) { + echo('
  • Core
  • '); + $ifbreak = 1; + } if (is_array($config['custom_descr']) === FALSE) { $config['custom_descr'] = array($config['custom_descr']); } @@ -239,21 +249,18 @@ if ($_SESSION['userlevel'] >= '5') } if ($ifbreak) { - echo(' '); + echo(' '); } -if (isset($interface_alerts)) -{ - echo('
  • Alerts ('.$interface_alerts.')
  • '); +if (isset($interface_alerts)) { + echo('
  • Alerts ('.$interface_alerts.')
  • '); } $deleted_ports = 0; -foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) -{ - if (port_permitted($interface['port_id'], $interface['device_id'])) - { - $deleted_ports++; - } +foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) { + if (port_permitted($interface['port_id'], $interface['device_id'])) { + $deleted_ports++; + } } ?> @@ -261,7 +268,9 @@ foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`delete
  • Disabled
  • Deleted ('.$deleted_ports.')'); } +if ($deleted_ports) { + echo('
  • Deleted ('.$deleted_ports.')
  • '); +} ?> @@ -270,9 +279,8 @@ if ($deleted_ports) { echo('
  • Processor
  • Storage
  • '); +if ($menu_sensors) { + $sep = 0; + echo(' '); } $icons = array('fanspeed'=>'tachometer','humidity'=>'tint','temperature'=>'fire','current'=>'bolt','frequency'=>'line-chart','power'=>'power-off','voltage'=>'bolt','charge'=>'plus-square','dbm'=>'sun-o', 'load'=>'spinner','state'=>'bullseye'); -foreach (array('fanspeed','humidity','temperature') as $item) -{ - if (isset($menu_sensors[$item])) - { +foreach (array('fanspeed','humidity','temperature') as $item) { + if (isset($menu_sensors[$item])) { + echo('
  • '.nicecase($item).'
  • '); + unset($menu_sensors[$item]);$sep++; + } +} + +if ($sep && array_keys($menu_sensors)) { + echo(' '); + $sep = 0; +} + +foreach (array('current','frequency','power','voltage') as $item) { + if (isset($menu_sensors[$item])) { + echo('
  • '.nicecase($item).'
  • '); + unset($menu_sensors[$item]);$sep++; + } +} + +if ($sep && array_keys($menu_sensors)) { + echo(' '); + $sep = 0; +} + +foreach (array_keys($menu_sensors) as $item) { echo('
  • '.nicecase($item).'
  • '); unset($menu_sensors[$item]);$sep++; - } -} - -if ($sep && array_keys($menu_sensors)) -{ - echo(' '); - $sep = 0; -} - -foreach (array('current','frequency','power','voltage') as $item) -{ - if (isset($menu_sensors[$item])) - { - echo('
  • '.nicecase($item).'
  • '); - unset($menu_sensors[$item]);$sep++; - } -} - -if ($sep && array_keys($menu_sensors)) -{ - echo(' '); - $sep = 0; -} - -foreach (array_keys($menu_sensors) as $item) -{ - echo('
  • '.nicecase($item).'
  • '); - unset($menu_sensors[$item]);$sep++; } ?> @@ -337,27 +337,24 @@ foreach (array_keys($menu_sensors) as $item) $app_count = dbFetchCell("SELECT COUNT(`app_id`) FROM `applications`"); -if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") -{ +if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") { ?> + = '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") -{ +if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") { ?> @@ -440,16 +427,11 @@ if ( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) { = '10') -{ - if (dbFetchCell("SELECT COUNT(*) from `plugins` WHERE plugin_active = '1'") > 0) { - echo(' - - '); - } - echo(' -
  • Plugin Admin
  • - '); +if ($_SESSION['userlevel'] >= '10') { + if (dbFetchCell("SELECT COUNT(*) from `plugins` WHERE plugin_active = '1'") > 0) { + echo(''); + } + echo('
  • Plugin Admin
  • '); } ?> @@ -457,9 +439,8 @@ if ($_SESSION['userlevel'] >= '10') @@ -476,50 +457,42 @@ if(is_file("includes/print-menubar-custom.inc.php"))
    -"); \ No newline at end of file +"; diff --git a/html/includes/print-service-edit.inc.php b/html/includes/print-service-edit.inc.php index 0954649d6d..d0ad23a569 100644 --- a/html/includes/print-service-edit.inc.php +++ b/html/includes/print-service-edit.inc.php @@ -1,35 +1,33 @@ Edit Service
    - - + +
    - +
    - +
    - +
    -
    "); - -} \ No newline at end of file +"; +}//end if diff --git a/html/includes/print-syslog.inc.php b/html/includes/print-syslog.inc.php index 09467dd7c4..1a7564920d 100644 --- a/html/includes/print-syslog.inc.php +++ b/html/includes/print-syslog.inc.php @@ -1,23 +1,18 @@ "); +if (device_permitted($entry['device_id'])) { + echo ''; - // Stop shortening hostname. Issue #61 - //$entry['hostname'] = shorthost($entry['hostname'], 20); - - if ($vars['page'] != "device") - { - echo("" . $entry['date'] . ""); - echo("".generate_device_link($entry).""); - echo("" . $entry['program'] . " : " . htmlspecialchars($entry['msg']) . ""); - } else { - echo("" . $entry['date'] . "   " . $entry['program'] . "   " . htmlspecialchars($entry['msg']) . ""); - } - - echo(""); + // Stop shortening hostname. Issue #61 + // $entry['hostname'] = shorthost($entry['hostname'], 20); + if ($vars['page'] != 'device') { + echo ''.$entry['date'].''; + echo ''.generate_device_link($entry).''; + echo ''.$entry['program'].' : '.htmlspecialchars($entry['msg']).''; + } + else { + echo ''.$entry['date'].'   '.$entry['program'].'   '.htmlspecialchars($entry['msg']).''; + } + echo ''; } - -?> diff --git a/html/includes/reports/alert-log.pdf.inc.php b/html/includes/reports/alert-log.pdf.inc.php index 5ee0e91ea1..d293b474b9 100644 --- a/html/includes/reports/alert-log.pdf.inc.php +++ b/html/includes/reports/alert-log.pdf.inc.php @@ -1,65 +1,83 @@ AddPage('L'); +$where = '1'; +if (is_numeric($_GET['device_id'])) { + $where .= ' AND E.device_id = ?'; + $param[] = $_GET['device_id']; +} - $where = "1"; - if (is_numeric($_GET['device_id'])) { - $where .= ' AND E.device_id = ?'; - $param[] = $_GET['device_id']; - } - if ($_GET['string']) { - $where .= " AND R.rule LIKE ?"; - $param[] = "%".$_GET['string']."%"; - } +if ($_GET['string']) { + $where .= ' AND R.rule LIKE ?'; + $param[] = '%'.$_GET['string'].'%'; +} - if ($_SESSION['userlevel'] >= '5') { - $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where ORDER BY `humandate` DESC"; - } else { - $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? ORDER BY `humandate` DESC"; - $param[] = $_SESSION['user_id']; - } +if ($_SESSION['userlevel'] >= '5') { + $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where ORDER BY `humandate` DESC"; +} +else { + $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? ORDER BY `humandate` DESC"; + $param[] = $_SESSION['user_id']; +} - if (isset($_GET['start']) && is_numeric($_GET['start'])) { - $start = mres($_GET['start']); - } else { - $start = 0; - } +if (isset($_GET['start']) && is_numeric($_GET['start'])) { + $start = mres($_GET['start']); +} +else { + $start = 0; +} - if (isset($_GET['results']) && is_numeric($_GET['results'])) { - $numresults = mres($_GET['results']); - } else { - $numresults = 250; - } +if (isset($_GET['results']) && is_numeric($_GET['results'])) { + $numresults = mres($_GET['results']); +} +else { + $numresults = 250; +} - $full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults"; +$full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults"; - foreach (dbFetchRows($full_query, $param) as $alert_entry) { - $hostname = gethostbyid(mres($alert_entry['device_id'])); - $alert_state = $alert_entry['state']; +foreach (dbFetchRows($full_query, $param) as $alert_entry) { + $hostname = gethostbyid(mres($alert_entry['device_id'])); + $alert_state = $alert_entry['state']; - if ($alert_state!='') { - if ($alert_state=='0') { - $glyph_color = 'green'; - $text = 'Ok'; - } elseif ($alert_state=='1') { - $glyph_color = 'red'; - $text = 'Alert'; - } elseif ($alert_state=='2') { - $glyph_color = 'lightgrey'; - $text = 'Ack'; - } elseif ($alert_state=='3') { - $glyph_color = 'orange'; - $text = 'Worse'; - } elseif ($alert_state=='4') { - $glyph_color = 'khaki'; - $text = 'Better'; - } - $data[] = array($alert_entry['time_logged'],$hostname,htmlspecialchars($alert_entry['name']),$text); + if ($alert_state != '') { + if ($alert_state == '0') { + $glyph_color = 'green'; + $text = 'Ok'; + } + else if ($alert_state == '1') { + $glyph_color = 'red'; + $text = 'Alert'; + } + else if ($alert_state == '2') { + $glyph_color = 'lightgrey'; + $text = 'Ack'; + } + else if ($alert_state == '3') { + $glyph_color = 'orange'; + $text = 'Worse'; + } + else if ($alert_state == '4') { + $glyph_color = 'khaki'; + $text = 'Better'; } - } -$header = array('Datetime', 'Device', 'Log', 'Status'); + $data[] = array( + $alert_entry['time_logged'], + $hostname, + htmlspecialchars($alert_entry['name']), + $text, + ); + }//end if +}//end foreach + +$header = array( + 'Datetime', + 'Device', + 'Log', + 'Status', +); $table = << @@ -74,17 +92,19 @@ EOD; foreach ($data as $log) { if ($log[3] == 'Alert') { $tr_col = '#d39392'; - } else { + } + else { $tr_col = '#bbd392'; } + $table .= ' - + '.$log[0].' '.$log[1].' '.$log[2].' '.$log[3].' - - '; + + '; } $table .= << $value) -{ - if ($value != "") - { - switch ($var) - { - case 'hostname': - $where .= " AND D.hostname LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'location': - $where .= " AND D.location LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'device_id': - $where .= " AND D.device_id = ?"; - $param[] = $value; - break; - case 'deleted': - case 'ignore': - if ($value == 1) - { - $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; - } - break; - case 'disable': - case 'ifSpeed': - if (is_numeric($value)) - { - $where .= " AND I.$var = ?"; - $param[] = $value; - } - break; - case 'ifType': - $where .= " AND I.$var = ?"; - $param[] = $value; - break; - case 'ifAlias': - case 'port_descr_type': - $where .= " AND I.$var LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'errors': - if ($value == 1) - { - $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; - } - break; - case 'state': - if ($value == "down") - { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; - $param[] = "up"; - $param[] = "down"; - } elseif($value == "up") { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; - $param[] = "up"; - $param[] = "up"; - } elseif($value == "admindown") { - $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; - $param[] = "down"; - } - break; - } - } -} +foreach ($vars as $var => $value) { + if ($value != '') { + switch ($var) { + case 'hostname': + $where .= ' AND D.hostname LIKE ?'; + $param[] = '%'.$value.'%'; + break; -$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ".$where." ".$query_sort; + case 'location': + $where .= ' AND D.location LIKE ?'; + $param[] = '%'.$value.'%'; + break; + + case 'device_id': + $where .= ' AND D.device_id = ?'; + $param[] = $value; + break; + + case 'deleted': + case 'ignore': + if ($value == 1) { + $where .= ' AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0'; + } + break; + + case 'disable': + case 'ifSpeed': + if (is_numeric($value)) { + $where .= " AND I.$var = ?"; + $param[] = $value; + } + break; + + case 'ifType': + $where .= " AND I.$var = ?"; + $param[] = $value; + break; + + case 'ifAlias': + case 'port_descr_type': + $where .= " AND I.$var LIKE ?"; + $param[] = '%'.$value.'%'; + break; + + case 'errors': + if ($value == 1) { + $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; + } + break; + + case 'state': + if ($value == 'down') { + $where .= 'AND I.ifAdminStatus = ? AND I.ifOperStatus = ?'; + $param[] = 'up'; + $param[] = 'down'; + } + else if ($value == 'up') { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; + $param[] = 'up'; + $param[] = 'up'; + } + else if ($value == 'admindown') { + $where .= 'AND I.ifAdminStatus = ? AND D.ignore = 0'; + $param[] = 'down'; + } + break; + }//end switch + }//end if +}//end foreach + +$query = 'SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id '.$where.' '.$query_sort; $row = 1; -list($format, $subformat) = explode("_", $vars['format']); +list($format, $subformat) = explode('_', $vars['format']); $ports = dbFetchRows($query, $param); -switch ($vars['sort']) -{ - case 'traffic': +switch ($vars['sort']) { +case 'traffic': $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); break; - case 'traffic_in': + +case 'traffic_in': $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); break; - case 'traffic_out': + +case 'traffic_out': $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); break; - case 'packets': + +case 'packets': $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); break; - case 'packets_in': + +case 'packets_in': $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); break; - case 'packets_out': + +case 'packets_out': $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); break; - case 'errors': + +case 'errors': $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); break; - case 'speed': + +case 'speed': $ports = array_sort($ports, 'ifSpeed', SORT_DESC); break; - case 'port': + +case 'port': $ports = array_sort($ports, 'ifDescr', SORT_ASC); break; - case 'media': + +case 'media': $ports = array_sort($ports, 'ifType', SORT_ASC); break; - case 'descr': + +case 'descr': $ports = array_sort($ports, 'ifAlias', SORT_ASC); break; - case 'device': - default: - $ports = array_sort($ports, 'hostname', SORT_ASC); -} -$csv[] = array('Device','Port','Speed','Down','Up','Media','Description'); -foreach( $ports as $port ) { - if( port_permitted($port['port_id'], $port['device_id']) ) { - $speed = humanspeed($port['ifSpeed']); - $type = humanmedia($port['ifType']); - $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); - $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); - $port = ifLabel($port, $device); - $csv[] = array($port['hostname'],fixIfName($port['label']),$speed,$port['in_rate'],$port['out_rate'],$type,$port['ifAlias']); - } +case 'device': +default: + $ports = array_sort($ports, 'hostname', SORT_ASC); +}//end switch + +$csv[] = array( + 'Device', + 'Port', + 'Speed', + 'Down', + 'Up', + 'Media', + 'Description', +); +foreach ($ports as $port) { + if (port_permitted($port['port_id'], $port['device_id'])) { + $speed = humanspeed($port['ifSpeed']); + $type = humanmedia($port['ifType']); + $port['in_rate'] = formatRates(($port['ifInOctets_rate'] * 8)); + $port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8)); + $port = ifLabel($port, $device); + $csv[] = array( + $port['hostname'], + fixIfName($port['label']), + $speed, + $port['in_rate'], + $port['out_rate'], + $type, + $port['ifAlias'], + ); + } } -?> diff --git a/html/includes/service-add.inc.php b/html/includes/service-add.inc.php index 3bc9eca630..cf1433b274 100644 --- a/html/includes/service-add.inc.php +++ b/html/includes/service-add.inc.php @@ -5,6 +5,6 @@ $updated = '1'; $service_id = add_service(mres($_POST['device']), mres($_POST['type']), mres($_POST['descr']), mres($_POST['ip']), mres($_POST['params'])); if ($service_id) { - $message .= $message_break . "Service added (".$service_id.")!"; - $message_break .= "
    "; -} \ No newline at end of file + $message .= $message_break.'Service added ('.$service_id.')!'; + $message_break .= '
    '; +} diff --git a/html/includes/table/address-search.inc.php b/html/includes/table/address-search.inc.php index a50d06afc7..25eb75360e 100644 --- a/html/includes/table/address-search.inc.php +++ b/html/includes/table/address-search.inc.php @@ -2,56 +2,64 @@ $param = array(); -if (is_admin() === FALSE && is_read() === FALSE) { - $perms_sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; - $param[] = array($_SESSION['user_id']); +if (is_admin() === false && is_read() === false) { + $perms_sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; + $param[] = array($_SESSION['user_id']); } -list($address,$prefix) = explode("/", $_POST['address']); +list($address,$prefix) = explode('/', $_POST['address']); if ($_POST['search_type'] == 'ipv4') { - $sql = " FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D"; + $sql = ' FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D'; $sql .= $perms_sql; $sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id $where "; if (!empty($address)) { $sql .= " AND ipv4_address LIKE '%".$address."%'"; } + if (!empty($prefix)) { - $sql .= " AND ipv4_prefixlen='?'"; + $sql .= " AND ipv4_prefixlen='?'"; $param[] = array($prefix); } -} elseif ($_POST['search_type'] == 'ipv6') { - $sql = " FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D"; +} +else if ($_POST['search_type'] == 'ipv6') { + $sql = ' FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D'; $sql .= $perms_sql; $sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id $where "; if (!empty($address)) { $sql .= " AND (ipv6_address LIKE '%".$address."%' OR ipv6_compressed LIKE '%".$address."%')"; } + if (!empty($prefix)) { $sql .= " AND ipv6_prefixlen = '$prefix'"; } -} elseif ($_POST['search_type'] == 'mac') { - $sql = " FROM `ports` AS I, `devices` AS D"; - $sql .= $perms_sql; - $sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%' $where "; } +else if ($_POST['search_type'] == 'mac') { + $sql = ' FROM `ports` AS I, `devices` AS D'; + $sql .= $perms_sql; + $sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address']))."%' $where "; +}//end if if (is_numeric($_POST['device_id'])) { - $sql .= " AND I.device_id = ?"; + $sql .= ' AND I.device_id = ?'; $param[] = array($_POST['device_id']); } + if ($_POST['interface']) { - $sql .= " AND I.ifDescr LIKE '?'"; + $sql .= " AND I.ifDescr LIKE '?'"; $param[] = array($_POST['interface']); } if ($_POST['search_type'] == 'ipv4') { $count_sql = "SELECT COUNT(`ipv4_address_id`) $sql"; -} elseif ($_POST['search_type'] == 'ipv6') { - $count_sql = "SELECT COUNT(`ipv6_address_id`) $sql"; -} elseif ($_POST['search_type'] == 'mac') { - $count_sql = "SELECT COUNT(`port_id`) $sql"; } -$total = dbFetchCell($count_sql,$param); +else if ($_POST['search_type'] == 'ipv6') { + $count_sql = "SELECT COUNT(`ipv6_address_id`) $sql"; +} +else if ($_POST['search_type'] == 'mac') { + $count_sql = "SELECT COUNT(`port_id`) $sql"; +} + +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -63,7 +71,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -75,31 +83,42 @@ $sql = "SELECT *,`I`.`ifDescr` AS `interface` $sql"; foreach (dbFetchRows($sql, $param) as $interface) { $speed = humanspeed($interface['ifSpeed']); - $type = humanmedia($interface['ifType']); + $type = humanmedia($interface['ifType']); if ($_POST['search_type'] == 'ipv6') { - list($prefix, $length) = explode("/", $interface['ipv6_network']); - $address = Net_IPv6::compress($interface['ipv6_address']) . '/'.$length; - } elseif ($_POST['search_type'] == 'mac') { + list($prefix, $length) = explode('/', $interface['ipv6_network']); + $address = Net_IPv6::compress($interface['ipv6_address']).'/'.$length; + } + else if ($_POST['search_type'] == 'mac') { $address = formatMac($interface['ifPhysAddress']); - } else { - list($prefix, $length) = explode("/", $interface['ipv4_network']); - $address = $interface['ipv4_address'] . '/' .$length; + } + else { + list($prefix, $length) = explode('/', $interface['ipv4_network']); + $address = $interface['ipv4_address'].'/'.$length; } if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { - $error_img = generate_port_link($interface,"Interface Errors",errors); - } else { - $error_img = ""; + $error_img = generate_port_link($interface, "Interface Errors", errors); } - if (port_permitted($interface['port_id'])) { - $interface = ifLabel ($interface, $interface); - $response[] = array('hostname'=>generate_device_link($interface), - 'interface'=>generate_port_link($interface) . ' ' . $error_img, - 'address'=>$address, - 'description'=>$interface['ifAlias']); + else { + $error_img = ''; } -} -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); + if (port_permitted($interface['port_id'])) { + $interface = ifLabel($interface, $interface); + $response[] = array( + 'hostname' => generate_device_link($interface), + 'interface' => generate_port_link($interface).' '.$error_img, + 'address' => $address, + 'description' => $interface['ifAlias'], + ); + } +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/alert-schedule.inc.php b/html/includes/table/alert-schedule.inc.php index 635e67be92..5d2bfa9b89 100644 --- a/html/includes/table/alert-schedule.inc.php +++ b/html/includes/table/alert-schedule.inc.php @@ -16,8 +16,9 @@ $where = 1; if ($_SESSION['userlevel'] >= '5') { $sql = " FROM `alert_schedule` AS S WHERE $where"; -} else { - $sql = " FROM `alert_schedule` AS S WHERE $where"; +} +else { + $sql = " FROM `alert_schedule` AS S WHERE $where"; $param[] = $_SESSION['user_id']; } @@ -26,7 +27,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(`id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -38,7 +39,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -48,20 +49,29 @@ if ($rowCount != -1) { $sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '".$config['dateformat']['mysql']['compact']."') AS `start`, DATE_FORMAT(`S`.`end`, '".$config['dateformat']['mysql']['compact']."') AS `end`, `S`.`title` $sql"; -foreach (dbFetchRows($sql,$param) as $schedule) { +foreach (dbFetchRows($sql, $param) as $schedule) { $status = 0; if ($schedule['end'] < date('dS M Y H:i::s')) { $status = 1; } + if (date('dS M Y H:i::s') >= $schedule['start'] && date('dS M Y H:i::s') < $schedule['end']) { $status = 2; } - $response[] = array('title'=>$schedule['title'], - 'start'=>$schedule['start'], - 'end'=>$schedule['end'], - 'id'=>$schedule['schedule_id'], - 'status'=>$status); + + $response[] = array( + 'title' => $schedule['title'], + 'start' => $schedule['start'], + 'end' => $schedule['end'], + 'id' => $schedule['schedule_id'], + 'status' => $status, + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/alertlog.inc.php b/html/includes/table/alertlog.inc.php index 0c8e515e62..8b4d94d3e2 100644 --- a/html/includes/table/alertlog.inc.php +++ b/html/includes/table/alertlog.inc.php @@ -3,14 +3,15 @@ $where = 1; if (is_numeric($_POST['device_id'])) { - $where .= ' AND E.device_id = ?'; + $where .= ' AND E.device_id = ?'; $param[] = $_POST['device_id']; } if ($_SESSION['userlevel'] >= '5') { $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where"; -} else { - $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?"; +} +else { + $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?"; $param[] = array($_SESSION['user_id']); } @@ -19,7 +20,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(`E`.`id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -31,7 +32,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -42,42 +43,49 @@ if ($rowCount != -1) { $sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql"; $rulei = 0; -foreach (dbFetchRows($sql,$param) as $alertlog) { - $dev = device_by_id_cache($alertlog['device_id']); +foreach (dbFetchRows($sql, $param) as $alertlog) { + $dev = device_by_id_cache($alertlog['device_id']); $fault_detail = alert_details($alertlog['details']); - $alert_state = $alertlog['state']; - if ($alert_state=='0') { - $glyph_icon = 'ok'; + $alert_state = $alertlog['state']; + if ($alert_state == '0') { + $glyph_icon = 'ok'; $glyph_color = 'green'; - $text = 'Ok'; + $text = 'Ok'; } - elseif ($alert_state=='1') { - $glyph_icon = 'remove'; + else if ($alert_state == '1') { + $glyph_icon = 'remove'; $glyph_color = 'red'; - $text = 'Alert'; + $text = 'Alert'; } - elseif ($alert_state=='2') { - $glyph_icon = 'info-sign'; + else if ($alert_state == '2') { + $glyph_icon = 'info-sign'; $glyph_color = 'lightgrey'; - $text = 'Ack'; + $text = 'Ack'; } - elseif ($alert_state=='3') { - $glyph_icon = 'arrow-down'; + else if ($alert_state == '3') { + $glyph_icon = 'arrow-down'; $glyph_color = 'orange'; - $text = 'Worse'; + $text = 'Worse'; } - elseif ($alert_state=='4') { - $glyph_icon = 'arrow-up'; + else if ($alert_state == '4') { + $glyph_icon = 'arrow-up'; $glyph_color = 'khaki'; - $text = 'Better'; - } - $response[] = array('id'=>$rulei++, - 'time_logged'=>$alertlog['humandate'], - 'details'=>'', - 'hostname'=>'
    '.generate_device_link($dev, shorthost($dev['hostname'])).'
    '.$fault_detail.'
    ', - 'alert'=>htmlspecialchars($alertlog['alert']), - 'status'=>" $text"); -} + $text = 'Better'; + }//end if + $response[] = array( + 'id' => $rulei++, + 'time_logged' => $alertlog['humandate'], + 'details' => '', + 'hostname' => '
    '.generate_device_link($dev, shorthost($dev['hostname'])).'
    '.$fault_detail.'
    ', + 'alert' => htmlspecialchars($alertlog['alert']), + 'status' => " $text", + ); +}//end foreach -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); -echo _json_encode($output); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); +echo _json_encode($output); diff --git a/html/includes/table/alerts.inc.php b/html/includes/table/alerts.inc.php index 799404b1a4..2efab5d1f1 100644 --- a/html/includes/table/alerts.inc.php +++ b/html/includes/table/alerts.inc.php @@ -10,18 +10,18 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { $sql_search .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')"; } -$sql = " FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`"; +$sql = ' FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`'; -if (is_admin() === FALSE && is_read() === FALSE) { - $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; +if (is_admin() === false && is_read() === false) { + $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; $param[] = $_SESSION['user_id']; } $sql .= " RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE $where AND `state` IN (1,2,3,4) $sql_search"; $count_sql = "SELECT COUNT(`alerts`.`id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -33,7 +33,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -43,76 +43,86 @@ if ($rowCount != -1) { $sql = "SELECT `alerts`.*, `devices`.`hostname` AS `hostname`,`alert_rules`.`rule` AS `rule`, `alert_rules`.`name` AS `name`, `alert_rules`.`severity` AS `severity` $sql"; -$rulei = 0; +$rulei = 0; $format = $_POST['format']; -foreach (dbFetchRows($sql,$param) as $alert) { - $log = dbFetchCell("SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1", array($alert['rule_id'],$alert['device_id'])); +foreach (dbFetchRows($sql, $param) as $alert) { + $log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id'])); $fault_detail = alert_details($log); - $ico = "ok"; - $col = "green"; - $extra = ""; - $msg = ""; - if ( (int) $alert['state'] === 0 ) { - $ico = "ok"; - $col = "green"; - $extra = "success"; - $msg = "ok"; - } elseif ( (int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) { - $ico = "volume-up"; - $col = "red"; - $extra = "danger"; - $msg = "alert"; - if ( (int) $alert['state'] === 3) { - $msg = "worse"; - } elseif ( (int) $alert['state'] === 4) { - $msg = "better"; - } - } elseif ( (int) $alert['state'] === 2) { - $ico = "volume-off"; - $col = "#800080"; - $extra = "warning"; - $msg = "muted"; + $ico = 'ok'; + $col = 'green'; + $extra = ''; + $msg = ''; + if ((int) $alert['state'] === 0) { + $ico = 'ok'; + $col = 'green'; + $extra = 'success'; + $msg = 'ok'; } + else if ((int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) { + $ico = 'volume-up'; + $col = 'red'; + $extra = 'danger'; + $msg = 'alert'; + if ((int) $alert['state'] === 3) { + $msg = 'worse'; + } + else if ((int) $alert['state'] === 4) { + $msg = 'better'; + } + } + else if ((int) $alert['state'] === 2) { + $ico = 'volume-off'; + $col = '#800080'; + $extra = 'warning'; + $msg = 'muted'; + }//end if $alert_checked = ''; - $orig_ico = $ico; - $orig_col = $col; - $orig_class = $extra; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; $severity = $alert['severity']; if ($alert['state'] == 3) { - $severity .= " +"; - } elseif ($alert['state'] == 4) { - $severity .= " -"; + $severity .= ' +'; + } + else if ($alert['state'] == 4) { + $severity .= ' -'; } $ack_ico = 'volume-up'; $ack_col = 'success'; - if($alert['state'] == 2) { + if ($alert['state'] == 2) { $ack_ico = 'volume-off'; $ack_col = 'danger'; - } + } $hostname = ' -
    - '.generate_device_link($alert).' -
    '.$fault_detail.'
    -
    '; +
    + '.generate_device_link($alert).' +
    '.$fault_detail.'
    +
    '; - $response[] = array('id'=>$rulei++, - 'rule'=>"".htmlentities($alert['name'])."", - 'details'=>'', - 'hostname'=>$hostname, - 'timestamp'=>($alert['timestamp'] ? $alert['timestamp'] : "N/A"), - 'severity'=>$severity, - 'ack_col'=>$ack_col, - 'state'=>$alert['state'], - 'alert_id'=>$alert['id'], - 'ack_ico'=>$ack_ico, - 'extra'=>$extra, - 'msg'=>$msg); + $response[] = array( + 'id' => $rulei++, + 'rule' => ''.htmlentities($alert['name']).'', + 'details' => '', + 'hostname' => $hostname, + 'timestamp' => ($alert['timestamp'] ? $alert['timestamp'] : 'N/A'), + 'severity' => $severity, + 'ack_col' => $ack_col, + 'state' => $alert['state'], + 'alert_id' => $alert['id'], + 'ack_ico' => $ack_ico, + 'extra' => $extra, + 'msg' => $msg, + ); +}//end foreach -} - -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/arp-search.inc.php b/html/includes/table/arp-search.inc.php index dd5c6225ea..090476048f 100644 --- a/html/includes/table/arp-search.inc.php +++ b/html/includes/table/arp-search.inc.php @@ -2,32 +2,33 @@ $param = array(); -$sql .= " FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D "; +$sql .= ' FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D '; -if (is_admin() === FALSE && is_read() === FALSE) { - $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; +if (is_admin() === false && is_read() === false) { + $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; $param[] = $_SESSION['user_id']; } $sql .= " WHERE M.port_id = P.port_id AND P.device_id = D.device_id $where "; -if (isset($_POST['searchby']) && $_POST['searchby'] == "ip") { - $sql .= " AND `ipv4_address` LIKE ?"; - $param[] = "%".trim($_POST['address'])."%"; -} elseif (isset($_POST['searchby']) && $_POST['searchby'] == "mac") { - $sql .= " AND `mac_address` LIKE ?"; - $param[] = "%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%"; +if (isset($_POST['searchby']) && $_POST['searchby'] == 'ip') { + $sql .= ' AND `ipv4_address` LIKE ?'; + $param[] = '%'.trim($_POST['address']).'%'; +} +else if (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') { + $sql .= ' AND `mac_address` LIKE ?'; + $param[] = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address'])).'%'; } if (is_numeric($_POST['device_id'])) { - $sql .= " AND P.device_id = ?"; + $sql .= ' AND P.device_id = ?'; $param[] = $_POST['device_id']; } $count_sql = "SELECT COUNT(`M`.`port_id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -39,7 +40,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -51,39 +52,53 @@ $sql = "SELECT *,`P`.`ifDescr` AS `interface` $sql"; foreach (dbFetchRows($sql, $param) as $entry) { if (!$ignore) { - if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) { - $error_img = generate_port_link($entry,"Interface Errors",port_errors); - } else { - $error_img = ""; + $error_img = generate_port_link($entry, "Interface Errors", port_errors); + } + else { + $error_img = ''; } - $arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address'])); - if ($arp_host) { - $arp_name = generate_device_link($arp_host); - } else { - unset($arp_name); - } - if ($arp_host) { - $arp_if = generate_port_link($arp_host); - } else { - unset($arp_if); - } - if ($arp_host['device_id'] == $entry['device_id']) { - $arp_name = "Localhost"; - } - if ($arp_host['port_id'] == $entry['port_id']) { - $arp_if = "Local port"; - } - $response[] = array('mac_address'=>formatMac($entry['mac_address']), - 'ipv4_address'=>$entry['ipv4_address'], - 'hostname'=>generate_device_link($entry), - 'interface'=>generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))) . ' ' . $error_img, - 'remote_device'=>$arp_name, - 'remote_interface'=>$arp_if); - } - unset($ignore); -} + $arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($entry['ipv4_address'])); + if ($arp_host) { + $arp_name = generate_device_link($arp_host); + } + else { + unset($arp_name); + } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); + if ($arp_host) { + $arp_if = generate_port_link($arp_host); + } + else { + unset($arp_if); + } + + if ($arp_host['device_id'] == $entry['device_id']) { + $arp_name = 'Localhost'; + } + + if ($arp_host['port_id'] == $entry['port_id']) { + $arp_if = 'Local port'; + } + + $response[] = array( + 'mac_address' => formatMac($entry['mac_address']), + 'ipv4_address' => $entry['ipv4_address'], + 'hostname' => generate_device_link($entry), + 'interface' => generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))).' '.$error_img, + 'remote_device' => $arp_name, + 'remote_interface' => $arp_if, + ); + }//end if + + unset($ignore); +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/devices.inc.php b/html/includes/table/devices.inc.php index 25cf21bd51..129e198f21 100644 --- a/html/includes/table/devices.inc.php +++ b/html/includes/table/devices.inc.php @@ -3,11 +3,11 @@ $where = 1; $param = array(); -$sql = " FROM `devices`"; +$sql = ' FROM `devices`'; -if (is_admin() === FALSE && is_read() === FALSE) { - $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; +if (is_admin() === false && is_read() === false) { + $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; $param[] = $_SESSION['user_id']; } @@ -17,48 +17,87 @@ if (!empty($_POST['location'])) { $sql .= " WHERE $where "; -if (!empty($_POST['hostname'])) { $sql .= " AND hostname LIKE ?"; $param[] = "%".$_POST['hostname']."%"; } -if (!empty($_POST['os'])) { $sql .= " AND os = ?"; $param[] = $_POST['os']; } -if (!empty($_POST['version'])) { $sql .= " AND version = ?"; $param[] = $_POST['version']; } -if (!empty($_POST['hardware'])) { $sql .= " AND hardware = ?"; $param[] = $_POST['hardware']; } -if (!empty($_POST['features'])) { $sql .= " AND features = ?"; $param[] = $_POST['features']; } -if (!empty($_POST['type'])) { - if ($_POST['type'] == 'generic') { - $sql .= " AND ( type = ? OR type = '')"; $param[] = $_POST['type']; - } else { - $sql .= " AND type = ?"; $param[] = $_POST['type']; - } +if (!empty($_POST['hostname'])) { + $sql .= ' AND hostname LIKE ?'; + $param[] = '%'.$_POST['hostname'].'%'; } -if (!empty($_POST['state'])) { - $sql .= " AND status= ?"; - if( is_numeric($_POST['state']) ) { - $param[] = $_POST['state']; - } else { - $param[] = str_replace(array('up','down'),array(1,0),$_POST['state']); + +if (!empty($_POST['os'])) { + $sql .= ' AND os = ?'; + $param[] = $_POST['os']; +} + +if (!empty($_POST['version'])) { + $sql .= ' AND version = ?'; + $param[] = $_POST['version']; +} + +if (!empty($_POST['hardware'])) { + $sql .= ' AND hardware = ?'; + $param[] = $_POST['hardware']; +} + +if (!empty($_POST['features'])) { + $sql .= ' AND features = ?'; + $param[] = $_POST['features']; +} + +if (!empty($_POST['type'])) { + if ($_POST['type'] == 'generic') { + $sql .= " AND ( type = ? OR type = '')"; + $param[] = $_POST['type']; + } + else { + $sql .= ' AND type = ?'; + $param[] = $_POST['type']; } } -if (!empty($_POST['disabled'])) { $sql .= " AND disabled= ?"; $param[] = $_POST['disabled']; } -if (!empty($_POST['ignore'])) { $sql .= " AND `ignore`= ?"; $param[] = $_POST['ignore']; } -if (!empty($_POST['location']) && $_POST['location'] == "Unset") { $location_filter = ''; } + +if (!empty($_POST['state'])) { + $sql .= ' AND status= ?'; + if (is_numeric($_POST['state'])) { + $param[] = $_POST['state']; + } + else { + $param[] = str_replace(array('up', 'down'), array(1, 0), $_POST['state']); + } +} + +if (!empty($_POST['disabled'])) { + $sql .= ' AND disabled= ?'; + $param[] = $_POST['disabled']; +} + +if (!empty($_POST['ignore'])) { + $sql .= ' AND `ignore`= ?'; + $param[] = $_POST['ignore']; +} + +if (!empty($_POST['location']) && $_POST['location'] == 'Unset') { + $location_filter = ''; +} + if (!empty($_POST['location'])) { - $sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)"; + $sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)"; $param[] = mres($_POST['location']); $param[] = mres($_POST['location']); } -if( !empty($_POST['group']) ) { - require_once('../includes/device-groups.inc.php'); - $sql .= " AND ( "; - foreach( GetDevicesFromGroup($_POST['group']) as $dev ) { - $sql .= "`devices`.`device_id` = ? OR "; + +if (!empty($_POST['group'])) { + include_once '../includes/device-groups.inc.php'; + $sql .= ' AND ( '; + foreach (GetDevicesFromGroup($_POST['group']) as $dev) { + $sql .= '`devices`.`device_id` = ? OR '; $param[] = $dev['device_id']; } - $sql = substr($sql, 0, strlen($sql)-3); - $sql .= " )"; + + $sql = substr($sql, 0, (strlen($sql) - 3)); + $sql .= ' )'; } $count_sql = "SELECT COUNT(`devices`.`device_id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -70,7 +109,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -81,99 +120,124 @@ if ($rowCount != -1) { $sql = "SELECT DISTINCT(`devices`.`device_id`),`devices`.* $sql"; if (!isset($_POST['format'])) { - $_POST['format'] = "list_detail"; + $_POST['format'] = 'list_detail'; } -list($format, $subformat) = explode("_", $_POST['format']); + +list($format, $subformat) = explode('_', $_POST['format']); foreach (dbFetchRows($sql, $param) as $device) { - if (isset($bg) && $bg == $list_colour_b) { - $bg = $list_colour_a; - } else { - $bg = $list_colour_b; - } + if (isset($bg) && $bg == $list_colour_b) { + $bg = $list_colour_a; + } + else { + $bg = $list_colour_b; + } - if ($device['status'] == '0') { - $extra = "danger"; - $msg = $device['status_reason']; - } else { - $extra = "success"; - $msg = "up"; - } - if ($device['ignore'] == '1') { - $extra = "default"; - $msg = "ignored"; - if ($device['status'] == '1') { - $extra = "warning"; - $msg = "ignored"; - } - } - if ($device['disabled'] == '1') { - $extra = "default"; - $msg = "disabled"; - } + if ($device['status'] == '0') { + $extra = 'danger'; + $msg = $device['status_reason']; + } + else { + $extra = 'success'; + $msg = 'up'; + } - $type = strtolower($device['os']); - $image = getImage($device); - - if ($device['os'] == "ios") { - formatCiscoHardware($device, true); - } + if ($device['ignore'] == '1') { + $extra = 'default'; + $msg = 'ignored'; + if ($device['status'] == '1') { + $extra = 'warning'; + $msg = 'ignored'; + } + } - $device['os_text'] = $config['os'][$device['os']]['text']; - $port_count = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?", array($device['device_id'])); - $sensor_count = dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?", array($device['device_id'])); + if ($device['disabled'] == '1') { + $extra = 'default'; + $msg = 'disabled'; + } - if (get_dev_attrib($device,'override_sysLocation_bool')) { - $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); - } + $type = strtolower($device['os']); + $image = getImage($device); - $actions = ('
    -
    '); - $actions .= ' View device '; - $actions .= ('
    -
    '); - $actions .= ' View alerts '; - $actions .= '
    '; - if ($_SESSION['userlevel'] >= "7") { - $actions .= ('
    - Edit device -
    '); - } - $actions .= ('
    -
    -
    - telnet -
    -
    - ssh -
    -
    - https -
    -
    '); + if ($device['os'] == 'ios') { + formatCiscoHardware($device, true); + } - $hostname = generate_device_link($device); - $platform = $device['hardware'] . '
    ' . $device['features']; - $os = $device['os_text'] . '
    ' . $device['version']; - if (extension_loaded('mbstring')) { - $location = mb_substr($device['location'], 0, 32, 'utf8'); - } else { - $location = truncate($device['location'], 32, ''); - } - $uptime = formatUptime($device['uptime'], 'short') . '
    ' . $location; - if ($subformat == "detail") { - $hostname .= '
    ' . $device['sysName']; - if ($port_count) { - $col_port = ' '.$port_count . '
    '; - } - if ($sensor_count) { - $col_port .= ' '.$sensor_count; - } - } else { + $device['os_text'] = $config['os'][$device['os']]['text']; + $port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); + $sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id'])); - } - $response[] = array('extra'=>$extra,'msg'=>$msg,'icon'=>$image,'hostname'=>$hostname,'ports'=>$col_port,'hardware'=>$platform,'os'=>$os,'uptime'=>$uptime,'actions'=>$actions); -} + if (get_dev_attrib($device, 'override_sysLocation_bool')) { + $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); + } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); + $actions = ('
    +
    '); + $actions .= ' View device '; + $actions .= ('
    +
    '); + $actions .= ' View alerts '; + $actions .= '
    '; + if ($_SESSION['userlevel'] >= '7') { + $actions .= ('
    + Edit device +
    '); + } + + $actions .= ('
    +
    +
    + telnet +
    +
    + ssh +
    +
    + https +
    +
    '); + + $hostname = generate_device_link($device); + $platform = $device['hardware'].'
    '.$device['features']; + $os = $device['os_text'].'
    '.$device['version']; + if (extension_loaded('mbstring')) { + $location = mb_substr($device['location'], 0, 32, 'utf8'); + } + else { + $location = truncate($device['location'], 32, ''); + } + + $uptime = formatUptime($device['uptime'], 'short').'
    '.$location; + if ($subformat == 'detail') { + $hostname .= '
    '.$device['sysName']; + if ($port_count) { + $col_port = ' '.$port_count.'
    '; + } + + if ($sensor_count) { + $col_port .= ' '.$sensor_count; + } + } + else { + } + + $response[] = array( + 'extra' => $extra, + 'msg' => $msg, + 'icon' => $image, + 'hostname' => $hostname, + 'ports' => $col_port, + 'hardware' => $platform, + 'os' => $os, + 'uptime' => $uptime, + 'actions' => $actions, + ); +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php index d5e5e7d60e..9cae422965 100644 --- a/html/includes/table/eventlog.inc.php +++ b/html/includes/table/eventlog.inc.php @@ -1,23 +1,22 @@ = '5') { $sql = " FROM `eventlog` AS E LEFT JOIN `devices` AS `D` ON `E`.`host`=`D`.`device_id` WHERE $where"; -} else { - $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?"; +} +else { + $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?"; $param[] = $_SESSION['user_id']; } @@ -26,7 +25,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(datetime) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -38,7 +37,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -48,22 +47,28 @@ if ($rowCount != -1) { $sql = "SELECT `E`.*,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate $sql"; -foreach (dbFetchRows($sql,$param) as $eventlog) { +foreach (dbFetchRows($sql, $param) as $eventlog) { $dev = device_by_id_cache($eventlog['host']); - if ($eventlog['type'] == "interface") { + if ($eventlog['type'] == 'interface') { $this_if = ifLabel(getifbyid($eventlog['reference'])); - $type = "".generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).""; - } else { - $type = "System"; + $type = ''.generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).''; } - - $response[] = array('datetime'=>$eventlog['humandate'], - 'hostname'=>generate_device_link($dev, shorthost($dev['hostname'])), - 'type'=>$type, - 'message'=>htmlspecialchars($eventlog['message'])); + else { + $type = 'System'; + } + + $response[] = array( + 'datetime' => $eventlog['humandate'], + 'hostname' => generate_device_link($dev, shorthost($dev['hostname'])), + 'type' => $type, + 'message' => htmlspecialchars($eventlog['message']), + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); - -?> diff --git a/html/includes/table/inventory.inc.php b/html/includes/table/inventory.inc.php index 6c5b92823f..2e4c0b9281 100644 --- a/html/includes/table/inventory.inc.php +++ b/html/includes/table/inventory.inc.php @@ -1,14 +1,15 @@ = '5') { $sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id"; -} else { - $sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?"; +} +else { + $sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?"; $param[] = $_SESSION['user_id']; } @@ -17,32 +18,32 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } if (isset($_POST['string']) && strlen($_POST['string'])) { - $sql .= " AND E.entPhysicalDescr LIKE ?"; - $param[] = "%".$_POST['string']."%"; + $sql .= ' AND E.entPhysicalDescr LIKE ?'; + $param[] = '%'.$_POST['string'].'%'; } if (isset($_POST['device_string']) && strlen($_POST['device_string'])) { - $sql .= " AND D.hostname LIKE ?"; - $param[] = "%".$_POST['device_string']."%"; + $sql .= ' AND D.hostname LIKE ?'; + $param[] = '%'.$_POST['device_string'].'%'; } if (isset($_POST['part']) && strlen($_POST['part'])) { - $sql .= " AND E.entPhysicalModelName = ?"; - $param[] = $_POST['part']; + $sql .= ' AND E.entPhysicalModelName = ?'; + $param[] = $_POST['part']; } if (isset($_POST['serial']) && strlen($_POST['serial'])) { - $sql .= " AND E.entPhysicalSerialNum LIKE ?"; - $param[] = "%".$_POST['serial']."%"; + $sql .= ' AND E.entPhysicalSerialNum LIKE ?'; + $param[] = '%'.$_POST['serial'].'%'; } if (isset($_POST['device']) && is_numeric($_POST['device'])) { - $sql .= " AND D.device_id = ?"; - $param[] = $_POST['device']; + $sql .= ' AND D.device_id = ?'; + $param[] = $_POST['device']; } $count_sql = "SELECT COUNT(`entPhysical_id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -54,7 +55,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -65,12 +66,19 @@ if ($rowCount != -1) { $sql = "SELECT `D`.`device_id` AS `device_id`, `D`.`hostname` AS `hostname`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql"; foreach (dbFetchRows($sql, $param) as $invent) { - $response[] = array('hostname'=>generate_device_link($invent, shortHost($invent['hostname'])), - 'description'=>$invent['description'], - 'name'=>$invent['name'], - 'model'=>$invent['model'], - 'serial'=>$invent['serial']); + $response[] = array( + 'hostname' => generate_device_link($invent, shortHost($invent['hostname'])), + 'description' => $invent['description'], + 'name' => $invent['name'], + 'model' => $invent['model'], + 'serial' => $invent['serial'], + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, + ); echo _json_encode($output); diff --git a/html/includes/table/mempool.inc.php b/html/includes/table/mempool.inc.php index d3968a5317..2afb80edc0 100644 --- a/html/includes/table/mempool.inc.php +++ b/html/includes/table/mempool.inc.php @@ -1,72 +1,88 @@ generate_device_link($mempool), - 'mempool_descr' => $mempool['mempool_descr'], - 'graph' => $mini_graph, - 'mempool_used' => $bar_link, - 'mempool_perc' => $perc . "%"); - if ($_POST['view'] == "graphs") { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; - $return_data = true; - include("includes/print-graphrow.inc.php"); - unset($return_data); - $response[] = array('hostname' => $graph_data[0], - 'mempool_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'mempool_used' => $graph_data[3], - 'mempool_perc' => ''); - } # endif graphs -} -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count); +$sql = "SELECT * $sql"; +foreach (dbFetchRows($sql, $param) as $mempool) { + $perc = round($mempool['mempool_perc'], 0); + $total = formatStorage($mempool['mempool_total']); + $free = formatStorage($mempool['mempool_free']); + $used = formatStorage($mempool['mempool_used']); + $graph_array['type'] = $graph_type; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['from'] = $config['time']['day']; + $graph_array['to'] = $config['time']['now']; + $graph_array['height'] = '20'; + $graph_array['width'] = '80'; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; + $link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/'; + $mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + $background = get_percentage_colours($perc); + $bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $free, 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null); + + $response[] = array( + 'hostname' => generate_device_link($mempool), + 'mempool_descr' => $mempool['mempool_descr'], + 'graph' => $mini_graph, + 'mempool_used' => $bar_link, + 'mempool_perc' => $perc.'%', + ); + if ($_POST['view'] == 'graphs') { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; + $return_data = true; + include 'includes/print-graphrow.inc.php'; + unset($return_data); + $response[] = array( + 'hostname' => $graph_data[0], + 'mempool_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'mempool_used' => $graph_data[3], + 'mempool_perc' => '', + ); + } //end if +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $count, +); echo _json_encode($output); diff --git a/html/includes/table/poll-log.inc.php b/html/includes/table/poll-log.inc.php index 3a0ca3213e..3579759b6c 100644 --- a/html/includes/table/poll-log.inc.php +++ b/html/includes/table/poll-log.inc.php @@ -1,11 +1,12 @@ " 'graphs', 'group' => 'poller')). "'>" .$device['hostname']. "", - 'last_polled' => $device['last_polled'], - 'last_polled_timetaken' => $device['last_polled_timetaken']); + $response[] = array( + 'hostname' => " 'graphs', 'group' => 'poller'))."'>".$device['hostname'].'', + 'last_polled' => $device['last_polled'], + 'last_polled_timetaken' => $device['last_polled_timetaken'], + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); - -?> diff --git a/html/includes/table/processor.inc.php b/html/includes/table/processor.inc.php index a7b3d97457..bcedd6196f 100644 --- a/html/includes/table/processor.inc.php +++ b/html/includes/table/processor.inc.php @@ -1,67 +1,83 @@ generate_device_link($processor), - 'processor_descr' => $processor['processor_descr'], - 'graph' => $mini_graph, - 'processor_usage' => $bar_link); - if ($_POST['view'] == "graphs") { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $processor['processor_id']; - $graph_array['type'] = $graph_type; - $return_data = true; - include("includes/print-graphrow.inc.php"); - unset($return_data); - $response[] = array('hostname' => $graph_data[0], - 'processor_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'processor_usage' => $graph_data[3]); - } # endif graphs -} -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$sql = "SELECT * $sql"; +foreach (dbFetchRows($sql, $param) as $processor) { + $perc = round($processor['processor_usage'], 0); + $graph_array['type'] = $graph_type; + $graph_array['id'] = $processor['processor_id']; + $graph_array['from'] = $config['time']['day']; + $graph_array['to'] = $config['time']['now']; + $graph_array['height'] = '20'; + $graph_array['width'] = '80'; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; + $link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/'; + $mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + $background = get_percentage_colours($perc); + $bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, $perc.'%', 'ffffff', $background['left'], (100 - $perc).'%', 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null); + + $response[] = array( + 'hostname' => generate_device_link($processor), + 'processor_descr' => $processor['processor_descr'], + 'graph' => $mini_graph, + 'processor_usage' => $bar_link, + ); + if ($_POST['view'] == 'graphs') { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $processor['processor_id']; + $graph_array['type'] = $graph_type; + $return_data = true; + include 'includes/print-graphrow.inc.php'; + unset($return_data); + $response[] = array( + 'hostname' => $graph_data[0], + 'processor_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'processor_usage' => $graph_data[3], + ); + } //end if +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/storage.inc.php b/html/includes/table/storage.inc.php index a912ba1d2e..3d301456f0 100644 --- a/html/includes/table/storage.inc.php +++ b/html/includes/table/storage.inc.php @@ -1,14 +1,14 @@ generate_device_link($drive), + 'storage_descr' => $drive['storage_descr'], + 'graph' => $mini_graph, + 'storage_used' => $bar_link, + 'storage_perc' => $perc.'%', + ); + if ($_POST['view'] == 'graphs') { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; - $response[] = array('hostname' => generate_device_link($drive), - 'storage_descr' => $drive['storage_descr'], - 'graph' => $mini_graph, - 'storage_used' => $bar_link, - 'storage_perc' => $perc . "%"); - if ($_POST['view'] == "graphs") { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; + $return_data = true; + include 'includes/print-graphrow.inc.php'; + unset($return_data); + $response[] = array( + 'hostname' => $graph_data[0], + 'storage_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'storage_used' => $graph_data[3], + 'storage_perc' => '', + ); + } //end if +}//end foreach - $return_data = true; - include("includes/print-graphrow.inc.php"); - unset($return_data); - $response[] = array('hostname' => $graph_data[0], - 'storage_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'storage_used' => $graph_data[3], - 'storage_perc' => ''); - - } # endif graphs -} - -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $count, +); echo _json_encode($output); diff --git a/html/includes/table/syslog.inc.php b/html/includes/table/syslog.inc.php index 81df05d289..987aac65a1 100644 --- a/html/includes/table/syslog.inc.php +++ b/html/includes/table/syslog.inc.php @@ -1,46 +1,44 @@ = ?"; - $param[] = $_POST['from']; -} -if( !empty($_POST['to']) ) { - $where .= " AND timestamp <= ?"; - $param[] = $_POST['to']; +if (!empty($_POST['from'])) { + $where .= ' AND timestamp >= ?'; + $param[] = $_POST['from']; } -if ($_SESSION['userlevel'] >= '5') -{ - $sql = "FROM syslog AS S"; - $sql .= " WHERE ".$where; -} else { - $sql = "FROM syslog AS S, devices_perms AS P"; - $sql .= "WHERE S.device_id = P.device_id AND P.user_id = ?"; - $sql .= $where; - $param = array_merge(array($_SESSION['user_id']), $param); +if (!empty($_POST['to'])) { + $where .= ' AND timestamp <= ?'; + $param[] = $_POST['to']; +} + +if ($_SESSION['userlevel'] >= '5') { + $sql = 'FROM syslog AS S'; + $sql .= ' WHERE '.$where; +} +else { + $sql = 'FROM syslog AS S, devices_perms AS P'; + $sql .= 'WHERE S.device_id = P.device_id AND P.user_id = ?'; + $sql .= $where; + $param = array_merge(array($_SESSION['user_id']), $param); } $count_sql = "SELECT COUNT(timestamp) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -52,7 +50,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -62,14 +60,20 @@ if ($rowCount != -1) { $sql = "SELECT S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql"; -foreach (dbFetchRows($sql,$param) as $syslog) { - $dev = device_by_id_cache($syslog['device_id']); - $response[] = array('timestamp'=>$syslog['date'], - 'device_id'=>generate_device_link($dev, shorthost($dev['hostname'])), - 'program'=>$syslog['program'], - 'msg'=>htmlspecialchars($syslog['msg'])); +foreach (dbFetchRows($sql, $param) as $syslog) { + $dev = device_by_id_cache($syslog['device_id']); + $response[] = array( + 'timestamp' => $syslog['date'], + 'device_id' => generate_device_link($dev, shorthost($dev['hostname'])), + 'program' => $syslog['program'], + 'msg' => htmlspecialchars($syslog['msg']), + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); -?> diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 788915f694..477f056b46 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -1,40 +1,38 @@ $get_var) -{ - if (strstr($key, "opt")) - { - list($name, $value) = explode("|", $get_var); - if (!isset($value)) { $value = "yes"; } - $vars[$name] = $value; - } +foreach ($_GET as $key => $get_var) { + if (strstr($key, 'opt')) { + list($name, $value) = explode('|', $get_var); + if (!isset($value)) { + $value = 'yes'; + } + + $vars[$name] = $value; + } } $segments = explode('/', trim($_SERVER['REQUEST_URI'], '/')); -foreach ($segments as $pos => $segment) -{ - $segment = urldecode($segment); - if ($pos == "0") - { - $vars['page'] = $segment; - } else { - list($name, $value) = explode("=", $segment); - if ($value == "" || !isset($value)) - { - $vars[$name] = yes; - } else { - $vars[$name] = $value; +foreach ($segments as $pos => $segment) { + $segment = urldecode($segment); + if ($pos == '0') { + $vars['page'] = $segment; + } + else { + list($name, $value) = explode('=', $segment); + if ($value == '' || !isset($value)) { + $vars[$name] = yes; + } + else { + $vars[$name] = $value; + } } - } } -foreach ($_GET as $name => $value) -{ - $vars[$name] = $value; +foreach ($_GET as $name => $value) { + $vars[$name] = $value; } -foreach ($_POST as $name => $value) -{ - $vars[$name] = $value; +foreach ($_POST as $name => $value) { + $vars[$name] = $value; } diff --git a/html/index.php b/html/index.php index 57fff1b57a..a3de9ba0c5 100644 --- a/html/index.php +++ b/html/index.php @@ -14,7 +14,8 @@ if( strstr($_SERVER['SERVER_SOFTWARE'],"nginx") ) { $_SERVER['PATH_INFO'] = str_replace($_SERVER['PATH_TRANSLATED'].$_SERVER['PHP_SELF'],"",$_SERVER['ORIG_SCRIPT_FILENAME']); -} else { +} +else { $_SERVER['PATH_INFO'] = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : ''); } @@ -31,40 +32,40 @@ function catchFatal() { } } -if (strpos($_SERVER['PATH_INFO'], "debug")) -{ - $debug = "1"; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); - set_error_handler('logErrors'); - register_shutdown_function('catchFatal'); -} else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); +if (strpos($_SERVER['PATH_INFO'], "debug")) { + $debug = "1"; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); + set_error_handler('logErrors'); + register_shutdown_function('catchFatal'); +} +else { + $debug = FALSE; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } // Set variables $msg_box = array(); // Check for install.inc.php -if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') -{ - // no config.php does so let's redirect to the install - header('Location: /install.php'); - exit; +if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') { + // no config.php does so let's redirect to the install + header('Location: /install.php'); + exit; } -include("../includes/defaults.inc.php"); -include("../config.php"); -include_once("../includes/definitions.inc.php"); -include("../includes/functions.php"); -include("includes/functions.inc.php"); -include("includes/vars.inc.php"); -include('includes/plugins.inc.php'); +require '../includes/defaults.inc.php'; +require '../config.php'; +require_once '../includes/definitions.inc.php'; +require '../includes/functions.php'; +require 'includes/functions.inc.php'; +require 'includes/vars.inc.php'; +require 'includes/plugins.inc.php'; + Plugins::start(); $runtime_start = utime(); @@ -74,30 +75,33 @@ ob_start(); ini_set('allow_url_fopen', 0); ini_set('display_errors', 0); -include("includes/authenticate.inc.php"); +require 'includes/authenticate.inc.php'; -if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { $_SESSION['widescreen'] = 1; } -if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) { unset($_SESSION['widescreen']); } +if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { + $_SESSION['widescreen'] = 1; +} +if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) { + unset($_SESSION['widescreen']); +} # Load the settings for Multi-Tenancy. -if (isset($config['branding']) && is_array($config['branding'])) -{ - if ($config['branding'][$_SERVER['SERVER_NAME']]) - { - foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) - { - eval("\$config['" . $confitem . "'] = \$confval;"); +if (isset($config['branding']) && is_array($config['branding'])) { + if ($config['branding'][$_SERVER['SERVER_NAME']]) { + foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) { + eval("\$config['" . $confitem . "'] = \$confval;"); + } } - } else { - foreach ($config['branding']['default'] as $confitem => $confval) - { - eval("\$config['" . $confitem . "'] = \$confval;"); + else { + foreach ($config['branding']['default'] as $confitem => $confval) { + eval("\$config['" . $confitem . "'] = \$confval;"); + } } - } } # page_title_prefix is displayed, unless page_title is set -if (isset($config['page_title'])) { $config['page_title_prefix'] = $config['page_title']; } +if (isset($config['page_title'])) { + $config['page_title_prefix'] = $config['page_title']; +} ?> @@ -119,7 +123,8 @@ if (empty($config['favicon'])) { ' . "\n"); } ?> @@ -169,14 +174,13 @@ if (empty($config['favicon'])) { body { padding-top: 0px !important; - padding-bottom: 0px !important; }"; + padding-bottom: 0px !important; }"; } @@ -188,50 +192,47 @@ if ((isset($vars['bare']) && $vars['bare'] != "yes") || !isset($vars['bare'])) { "); - print_r($_GET); - print_r($vars); - echo(""); +if (isset($devel) || isset($vars['devel'])) { + echo("
    ");
    +    print_r($_GET);
    +    print_r($vars);
    +    echo("
    "); } -if ($_SESSION['authenticated']) -{ - // Authenticated. Print a page. - if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) - { - include("pages/" . $vars['page'] . ".inc.php"); - } else { - if (isset($config['front_page']) && is_file($config['front_page'])) - { - include($config['front_page']); - } else { - include("pages/front/default.php"); +if ($_SESSION['authenticated']) { + // Authenticated. Print a page. + if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) { + require "pages/" . $vars['page'] . ".inc.php"; + } + else { + if (isset($config['front_page']) && is_file($config['front_page'])) { + require $config['front_page']; + } + else { + require 'pages/front/default.php'; + } } - } -} else { - // Not Authenticated. Show status page if enabled - if ( $config['public_status'] === true ) - { - if (isset($vars['page']) && strstr("login", $vars['page'])) - { - include("pages/logon.inc.php"); - } else { - echo '
    '; - include("pages/public.inc.php"); - echo '
    '; - echo ''; +} +else { + // Not Authenticated. Show status page if enabled + if ( $config['public_status'] === true ) { + if (isset($vars['page']) && strstr("login", $vars['page'])) { + require 'pages/logon.inc.php'; + } + else { + echo '
    '; + require 'pages/public.inc.php'; + echo '
    '; + echo ''; + } + } + else { + require 'pages/logon.inc.php'; } - } - else - { - include("pages/logon.inc.php"); - } } ?> @@ -239,37 +240,42 @@ if ($_SESSION['authenticated']) MySQL: Cell '.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,3).'s'. - ' Row '.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,3).'s'. - ' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'. - ' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s'); +if ($config['page_gen']) { + echo('
    MySQL: Cell '.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,3).'s'. + ' Row '.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,3).'s'. + ' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'. + ' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s'); - $fullsize = memory_get_usage(); - unset($cache); - $cachesize = $fullsize - memory_get_usage(); - if ($cachesize < 0) { $cachesize = 0; } // Silly PHP! + $fullsize = memory_get_usage(); + unset($cache); + $cachesize = $fullsize - memory_get_usage(); + if ($cachesize < 0) { + $cachesize = 0; + } // Silly PHP! - echo('
    Cached data in memory is '.formatStorage($cachesize).'. Page memory usage is '.formatStorage($fullsize).', peaked at '. formatStorage(memory_get_peak_usage()) .'.'); - echo('
    Generated in ' . $gentime . ' seconds.'); + echo('
    Cached data in memory is '.formatStorage($cachesize).'. Page memory usage is '.formatStorage($fullsize).', peaked at '. formatStorage(memory_get_peak_usage()) .'.'); + echo('
    Generated in ' . $gentime . ' seconds.'); } -if (isset($pagetitle) && is_array($pagetitle)) -{ - # if prefix is set, put it in front - if ($config['page_title_prefix']) { array_unshift($pagetitle,$config['page_title_prefix']); } +if (isset($pagetitle) && is_array($pagetitle)) { + # if prefix is set, put it in front + if ($config['page_title_prefix']) { + array_unshift($pagetitle,$config['page_title_prefix']); + } - # if suffix is set, put it in the back - if ($config['page_title_suffix']) { $pagetitle[] = $config['page_title_suffix']; } + # if suffix is set, put it in the back + if ($config['page_title_suffix']) { + $pagetitle[] = $config['page_title_suffix']; + } - # create and set the title - $title = join(" - ",$pagetitle); - echo(""); + # create and set the title + $title = join(" - ",$pagetitle); + echo(""); } ?> @@ -295,23 +301,21 @@ if(dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` <= } if(is_array($msg_box)) { - echo(""); + echo(""); } if (is_array($sql_debug) && is_array($php_debug) && $_SESSION['authenticated'] === TRUE) { - - include_once "includes/print-debug.php"; - + require_once "includes/print-debug.php"; } if ($no_refresh !== TRUE && $config['page_refresh'] != 0) { @@ -367,7 +371,8 @@ if ($no_refresh !== TRUE && $config['page_refresh'] != 0) { }); '); -} else { +} +else { echo(' +}//end if diff --git a/html/pages/alert-stats.inc.php b/html/pages/alert-stats.inc.php index d392f1dd20..ab9a0c57fd 100644 --- a/html/pages/alert-stats.inc.php +++ b/html/pages/alert-stats.inc.php @@ -1,12 +1,13 @@ -* 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 3 of the License, or (at your -* option) any later version. Please see LICENSE.txt at the top level of -* the source code distribution for details. -*/ -require_once('includes/print-graph-alerts.inc.php'); + * LibreNMS + * + * Copyright (c) 2015 Søren Friis Rosiak + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +require_once 'includes/print-graph-alerts.inc.php'; diff --git a/html/pages/alerts.inc.php b/html/pages/alerts.inc.php index bcc97a32a0..91526b69ff 100644 --- a/html/pages/alerts.inc.php +++ b/html/pages/alerts.inc.php @@ -1,19 +1,17 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ $device['device_id'] = '-1'; -require_once('includes/print-alerts.php'); +require_once 'includes/print-alerts.php'; unset($device['device_id']); - -?> diff --git a/html/pages/api-access.inc.php b/html/pages/api-access.inc.php index a1b6e5a528..6b8a885a7a 100644 --- a/html/pages/api-access.inc.php +++ b/html/pages/api-access.inc.php @@ -12,22 +12,22 @@ * the source code distribution for details. */ -if ($_SESSION['userlevel'] >= '10') -{ -if(empty($_POST['token'])) { +if ($_SESSION['userlevel'] >= '10') { +if (empty($_POST['token'])) { $_POST['token'] = bin2hex(openssl_random_pseudo_bytes(16)); } + ?> -'); - if($_SESSION['api_token'] === TRUE) - { - echo(" - "); + "; unset($_SESSION['api_token']); - } -echo(' +} + +echo '
    @@ -127,19 +125,17 @@ echo(' Disabled Remove -'); +'; - foreach (dbFetchRows("SELECT `AT`.*,`U`.`username` FROM `api_tokens` AS AT JOIN users AS U ON AT.user_id=U.user_id ORDER BY AT.user_id") as $api) - { - if($api['disabled'] == '1') - { - $api_disabled = 'checked'; +foreach (dbFetchRows('SELECT `AT`.*,`U`.`username` FROM `api_tokens` AS AT JOIN users AS U ON AT.user_id=U.user_id ORDER BY AT.user_id') as $api) { + if ($api['disabled'] == '1') { + $api_disabled = 'checked'; } - else - { - $api_disabled = ''; + else { + $api_disabled = ''; } - echo(' + + echo ' '.$api['username'].' '.$api['token_hash'].' @@ -147,14 +143,14 @@ echo(' -'); - } +'; +} - echo(' + echo '
    -'); +'; ?> +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index c260b73cec..d3bd68b840 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -17,8 +17,7 @@
    here.'); +print_error('Documentation for the API has now been moved to GitHub, you can go straight to the API Wiki from here.'); ?>
    - diff --git a/html/pages/apps.inc.php b/html/pages/apps.inc.php index 1a20acc41f..cfd2378dde 100644 --- a/html/pages/apps.inc.php +++ b/html/pages/apps.inc.php @@ -1,54 +1,91 @@ Apps » "); +echo "Apps » "; unset($sep); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'apps'); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'apps', +); -foreach ($app_list as $app) -{ - echo($sep); +foreach ($app_list as $app) { + echo $sep; -# if (!$vars['app']) { $vars['app'] = $app['app_type']; } + // if (!$vars['app']) { $vars['app'] = $app['app_type']; } + if ($vars['app'] == $app['app_type']) { + echo ""; + // echo(''); + } + else { + // echo(''); + } - if ($vars['app'] == $app['app_type']) - { - echo(""); - #echo(''); - } else { - #echo(''); - } - echo(generate_link(nicecase($app['app_type']),array('page'=>'apps','app'=>$app['app_type']))); - if ($vars['app'] == $app['app_type']) { echo(""); } - $sep = " | "; + echo generate_link(nicecase($app['app_type']), array('page' => 'apps', 'app' => $app['app_type'])); + if ($vars['app'] == $app['app_type']) { + echo ''; + } + + $sep = ' | '; } print_optionbar_end(); -if($vars['app']) -{ - if (is_file("pages/apps/".mres($vars['app']).".inc.php")) - { - include("pages/apps/".mres($vars['app']).".inc.php"); - } else { - include("pages/apps/default.inc.php"); - } -} else { - include("pages/apps/overview.inc.php"); +if ($vars['app']) { + if (is_file('pages/apps/'.mres($vars['app']).'.inc.php')) { + include 'pages/apps/'.mres($vars['app']).'.inc.php'; + } + else { + include 'pages/apps/default.inc.php'; + } +} +else { + include 'pages/apps/overview.inc.php'; } -$pagetitle[] = "Apps"; -?> +$pagetitle[] = 'Apps'; diff --git a/html/pages/apps/default.inc.php b/html/pages/apps/default.inc.php index e333674057..bf752de29c 100644 --- a/html/pages/apps/default.inc.php +++ b/html/pages/apps/default.inc.php @@ -1,45 +1,41 @@ '.nicecase($vars['app']).''); -echo(''); -$app_devices = dbFetchRows("SELECT * FROM `devices` AS D, `applications` AS A WHERE D.device_id = A.device_id AND A.app_type = ?", array($vars['app'])); +echo '

    '.nicecase($vars['app']).'

    '; +echo '
    '; +$app_devices = dbFetchRows('SELECT * FROM `devices` AS D, `applications` AS A WHERE D.device_id = A.device_id AND A.app_type = ?', array($vars['app'])); -foreach ($app_devices as $app_device) -{ - echo(''); - echo(''); - echo(''); - echo(''); - echo(''); - echo(''); - echo(''); - echo(''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''); - echo(''); -} + echo ''; + echo ''; +}//end foreach -echo('
    '.generate_device_link($app_device, shorthost($app_device['hostname']), array('tab'=>'apps','app'=>$vars['app'])).''.$app_device['app_instance'].''.$app_device['app_status'].'
    '); +foreach ($app_devices as $app_device) { + echo '
    '.generate_device_link($app_device, shorthost($app_device['hostname']), array('tab' => 'apps', 'app' => $vars['app'])).''.$app_device['app_instance'].''.$app_device['app_status'].'
    '; - foreach ($graphs[$vars['app']] as $graph_type) - { - $graph_array['type'] = "application_".$vars['app']."_".$graph_type; - $graph_array['id'] = $app_device['app_id']; - $graph_array_zoom['type'] = "application_".$vars['app']."_".$graph_type; - $graph_array_zoom['id'] = $app_device['app_id']; + foreach ($graphs[$vars['app']] as $graph_type) { + $graph_array['type'] = 'application_'.$vars['app'].'_'.$graph_type; + $graph_array['id'] = $app_device['app_id']; + $graph_array_zoom['type'] = 'application_'.$vars['app'].'_'.$graph_type; + $graph_array_zoom['id'] = $app_device['app_id']; - $link = generate_url(array('page' => 'device', 'device' => $app_device['device_id'],'tab'=>'apps','app'=>$vars['app'])); + $link = generate_url(array('page' => 'device', 'device' => $app_device['device_id'], 'tab' => 'apps', 'app' => $vars['app'])); - echo(overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL)); - } + echo overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + } - echo('
    '); - -?> +echo ''; diff --git a/html/pages/authlog.inc.php b/html/pages/authlog.inc.php index 64b4080ad2..3cffbbea9e 100644 --- a/html/pages/authlog.inc.php +++ b/html/pages/authlog.inc.php @@ -1,37 +1,37 @@ = '10') -{ - echo(""); +if ($_SESSION['userlevel'] >= '10') { + echo '
    '; - foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) - { - if ($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } + foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) { + if ($bg == $list_colour_a) { + $bg = $list_colour_b; + } + else { + $bg = $list_colour_a; + } - echo(" - - - - - - "); - } + echo " + + + + + + '; + }//end foreach - $pagetitle[] = "Authlog"; + $pagetitle[] = 'Authlog'; - echo("
    - " . $entry['datetime'] . " - - ".$entry['user']." - - ".$entry['address']." - - ".$entry['result']." -
    + ".$entry['datetime'].' + + '.$entry['user'].' + + '.$entry['address'].' + + '.$entry['result'].' +
    "); + echo ''; } -else -{ - include("includes/error-no-perm.inc.php"); -} - -?> +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php index 13b640057b..03faf35c17 100644 --- a/html/pages/bill.inc.php +++ b/html/pages/bill.inc.php @@ -2,255 +2,274 @@ $bill_id = mres($vars['bill_id']); -if ($_SESSION['userlevel'] >= "10") -{ - include("pages/bill/actions.inc.php"); +if ($_SESSION['userlevel'] >= '10') { + include 'pages/bill/actions.inc.php'; } -if (bill_permitted($bill_id)) -{ - $bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)); +if (bill_permitted($bill_id)) { + $bill_data = dbFetchRow('SELECT * FROM bills WHERE bill_id = ?', array($bill_id)); - $bill_name = $bill_data['bill_name']; + $bill_name = $bill_data['bill_name']; - $today = str_replace("-", "", dbFetchCell("SELECT CURDATE()")); - $yesterday = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)")); - $tomorrow = str_replace("-", "", dbFetchCell("SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)")); - $last_month = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")); + $today = str_replace('-', '', dbFetchCell('SELECT CURDATE()')); + $yesterday = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)')); + $tomorrow = str_replace('-', '', dbFetchCell('SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)')); + $last_month = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)')); - $rightnow = $today . date(His); - $before = $yesterday . date(His); - $lastmonth = $last_month . date(His); + $rightnow = $today.date(His); + $before = $yesterday.date(His); + $lastmonth = $last_month.date(His); - $bill_name = $bill_data['bill_name']; - $dayofmonth = $bill_data['bill_day']; + $bill_name = $bill_data['bill_name']; + $dayofmonth = $bill_data['bill_day']; - $day_data = getDates($dayofmonth); + $day_data = getDates($dayofmonth); - $datefrom = $day_data['0']; - $dateto = $day_data['1']; - $lastfrom = $day_data['2']; - $lastto = $day_data['3']; + $datefrom = $day_data['0']; + $dateto = $day_data['1']; + $lastfrom = $day_data['2']; + $lastto = $day_data['3']; - $rate_95th = $bill_data['rate_95th']; - $dir_95th = $bill_data['dir_95th']; - $total_data = $bill_data['total_data']; - $rate_average = $bill_data['rate_average']; + $rate_95th = $bill_data['rate_95th']; + $dir_95th = $bill_data['dir_95th']; + $total_data = $bill_data['total_data']; + $rate_average = $bill_data['rate_average']; - if ($rate_95th > $paid_kb) - { - $over = $rate_95th - $paid_kb; - $bill_text = $over . "Kbit excess."; - $bill_color = "#cc0000"; - } - else - { - $under = $paid_kb - $rate_95th; - $bill_text = $under . "Kbit headroom."; - $bill_color = "#0000cc"; - } - - $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); - $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); - $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); - $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); - - $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); - $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); - # Speeds up loading for other included pages by setting it before progessing of mysql data! - - $ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D - WHERE B.bill_id = ? AND P.port_id = B.port_id - AND D.device_id = P.device_id", array($bill_id)); - - echo("

    - Bill : " . $bill_data['bill_name'] . "

    "); - - print_optionbar_start(); - - echo("Bill » "); - - if (!$vars['view']) { $vars['view'] = "quick"; } - - if ($vars['view'] == "quick") { echo(""); } - echo('Quick Graphs'); - if ($vars['view'] == "quick") { echo(""); } - - echo(" | "); - - if ($vars['view'] == "accurate") { echo(""); } - echo('Accurate Graphs'); - if ($vars['view'] == "accurate") { echo(""); } - - echo(" | "); - - if ($vars['view'] == "transfer") { echo(""); } - echo('Transfer Graphs'); - if ($vars['view'] == "transfer") { echo(""); } - - echo(" | "); - - if ($vars['view'] == "history") { echo(""); } - echo('Historical Usage'); - if ($vars['view'] == "history") { echo(""); } - - if ($_SESSION['userlevel'] >= "10") - { - echo(" | "); - if ($vars['view'] == "edit") { echo(""); } - echo('Edit'); - if ($vars['view'] == "edit") { echo(""); } - - echo(" | "); - if ($vars['view'] == "delete") { echo(""); } - echo('Delete'); - if ($vars['view'] == "delete") { echo(""); } - - echo(" | "); - if ($vars['view'] == "reset") { echo(""); } - echo('Reset'); - if ($vars['view'] == "reset") { echo(""); } - } - - echo(''); - - print_optionbar_end(); - - if ($vars['view'] == "edit" && $_SESSION['userlevel'] >= "10") - { - include("pages/bill/edit.inc.php"); - } - elseif ($vars['view'] == "delete" && $_SESSION['userlevel'] >= "10") - { - include("pages/bill/delete.inc.php"); - } - elseif ($vars['view'] == "reset" && $_SESSION['userlevel'] >= "10") - { - include("pages/bill/reset.inc.php"); - } - elseif ($vars['view'] == "history") - { - include("pages/bill/history.inc.php"); - } - elseif ($vars['view'] == "transfer") - { - include("pages/bill/transfer.inc.php"); - } - elseif ($vars['view'] == "quick" || $vars['view'] == "accurate") { - - echo("

    Billed Ports

    "); - - // Collected Earlier - foreach ($ports as $port) - { - echo(generate_port_link($port) . " on " . generate_device_link($port) . "
    "); + if ($rate_95th > $paid_kb) { + $over = ($rate_95th - $paid_kb); + $bill_text = $over.'Kbit excess.'; + $bill_color = '#cc0000'; + } + else { + $under = ($paid_kb - $rate_95th); + $bill_text = $under.'Kbit headroom.'; + $bill_color = '#0000cc'; } - echo("

    Bill Summary

    "); + $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); + $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); + $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); + $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); - if ($bill_data['bill_type'] == "quota") - { - // The Customer is billed based on a pre-paid quota with overage in xB + $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); + $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); + // Speeds up loading for other included pages by setting it before progessing of mysql data! + $ports = dbFetchRows( + 'SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D + WHERE B.bill_id = ? AND P.port_id = B.port_id + AND D.device_id = P.device_id', + array($bill_id) + ); - echo("

    Quota Bill

    "); + echo '

    + Bill : '.$bill_data['bill_name'].'

    '; - $percent = round(($total_data) / $bill_data['bill_quota'] * 100, 2); - $unit = "MB"; - $total_data = round($total_data, 2); - echo("Billing Period from " . $fromtext . " to " . $totext); - echo("
    Transferred ".format_bytes_billing($total_data)." of ".format_bytes_billing($bill_data['bill_quota'])." (".$percent."%)"); - echo("
    Average rate " . formatRates($rate_average)); + print_optionbar_start(); - $background = get_percentage_colours($percent); + echo "Bill » "; - echo("

    ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

    "); - - $type="&ave=yes"; - } - elseif ($bill_data['bill_type'] == "cdr") - { - // The customer is billed based on a CDR with 95th%ile overage - - echo("

    CDR / 95th Bill

    "); - - $unit = "kbps"; - $cdr = $bill_data['bill_cdr']; - $rate_95th = round($rate_95th, 2); - - $percent = round(($rate_95th) / $cdr * 100, 2); - - $type="&95th=yes"; - - echo("" . $fromtext . " to " . $totext . " -
    Measured ".format_si($rate_95th)."bps of ".format_si($cdr)."bps (".$percent."%) @ 95th %ile"); - - $background = get_percentage_colours($percent); - - echo("

    ".print_percentage_bar (350, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

    "); - - # echo("

    Billing Period : " . $fromtext . " to " . $totext . "
    - # " . $paidrate_text . "
    - # " . $total_data . "MB transfered in the current billing cycle.
    - # " . $rate_average . "Kbps Average during the current billing cycle.

    - # " . $rate_95th . "Kbps @ 95th Percentile. (" . $dir_95th . ") (" . $bill_text . ") - # - #
    "); + if (!$vars['view']) { + $vars['view'] = 'quick'; } - $lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"); - $yesterday = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))"); - $rightnow = date(U); - - if ($vars['view'] == "accurate") { - - $bi = ""; - - $li = ""; - - $di = ""; - - $mi = ""; - + if ($vars['view'] == 'quick') { + echo ""; } - if ($null) - { - echo(" - @@ -268,39 +287,32 @@ if (bill_permitted($bill_id)) - "); + "; + }//end if - } - - if ($_GET['all']) - { - $ai = ""; - echo("

    Entire Data View

    $ai"); - } - elseif ($_GET['custom']) - { - $cg = ""; - echo("

    Custom Graph

    $cg"); - } - else - { - echo("

    Billing View

    $bi"); -# echo("

    Previous Bill View

    $li"); - echo("

    24 Hour View

    $di"); - echo("

    Monthly View

    $mi"); -# echo("
    Graph All Data (SLOW)"); - } - } # End if details + if ($_GET['all']) { + $ai = ''; + echo "

    Entire Data View

    $ai"; + } + else if ($_GET['custom']) { + $cg = ''; + echo "

    Custom Graph

    $cg"; + } + else { + echo "

    Billing View

    $bi"; + // echo("

    Previous Bill View

    $li"); + echo "

    24 Hour View

    $di"; + echo "

    Monthly View

    $mi"; + // echo("
    Graph All Data (SLOW)"); + }//end if + } //end if } -else -{ - include("includes/error-no-perm.inc.php"); -} - -?> +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/bill/actions.inc.php b/html/pages/bill/actions.inc.php index d55c2944cc..29afb6d3b4 100644 --- a/html/pages/bill/actions.inc.php +++ b/html/pages/bill/actions.inc.php @@ -1,8 +1,7 @@ = 1) { + $quota = array( + 'type' => 'tb', + 'select_tb' => ' selected', + 'data' => $tmp['tb'], + ); + } + else if (($tmp['gb'] >= 1) and ($tmp['gb'] < $base)) { + $quota = array( + 'type' => 'gb', + 'select_gb' => ' selected', + 'data' => $tmp['gb'], + ); + } + else if (($tmp['mb'] >= 1) and ($tmp['mb'] < $base)) { + $quota = array( + 'type' => 'mb', + 'select_mb' => ' selected', + 'data' => $tmp['mb'], + ); + } +}//end if -if ($bill_data['bill_type'] == "quota") { - $data = $bill_data['bill_quota']; - $tmp['mb'] = $data / $base / $base; - $tmp['gb'] = $data / $base / $base / $base; - $tmp['tb'] = $data / $base / $base / $base / $base; - if ($tmp['tb']>=1) { $quota = array("type" => "tb", "select_tb" => " selected", "data" => $tmp['tb']); } - elseif (($tmp['gb']>=1) and ($tmp['gb']<$base)) { $quota = array("type" => "gb", "select_gb" => " selected", "data" => $tmp['gb']); } - elseif (($tmp['mb']>=1) and ($tmp['mb']<$base)) { $quota = array("type" => "mb", "select_mb" => " selected", "data" => $tmp['mb']); } -} -if ($bill_data['bill_type'] == "cdr") { - $data = $bill_data['bill_cdr']; - $tmp['kbps'] = $data / $base; - $tmp['mbps'] = $data / $base / $base; - $tmp['gbps'] = $data / $base / $base / $base; - if ($tmp['gbps']>=1) { $cdr = array("type" => "gbps", "select_gbps" => " selected", "data" => $tmp['gbps']); } - elseif (($tmp['mbps']>=1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_mbps" => " selected", "data" => $tmp['mbps']); } - elseif (($tmp['kbps']>=1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_kbps" => " selected", "data" => $tmp['kbps']); } -} +if ($bill_data['bill_type'] == 'cdr') { + $data = $bill_data['bill_cdr']; + $tmp['kbps'] = ($data / $base); + $tmp['mbps'] = ($data / $base / $base); + $tmp['gbps'] = ($data / $base / $base / $base); + if ($tmp['gbps'] >= 1) { + $cdr = array( + 'type' => 'gbps', + 'select_gbps' => ' selected', + 'data' => $tmp['gbps'], + ); + } + else if (($tmp['mbps'] >= 1) and ($tmp['mbps'] < $base)) { + $cdr = array( + 'type' => 'mbps', + 'select_mbps' => ' selected', + 'data' => $tmp['mbps'], + ); + } + else if (($tmp['kbps'] >= 1) and ($tmp['kbps'] < $base)) { + $cdr = array( + 'type' => 'kbps', + 'select_kbps' => ' selected', + 'data' => $tmp['kbps'], + ); + } +}//end if ?>
    - +

    Bill Properties

    - " /> +
    @@ -51,17 +86,35 @@ if ($bill_data['bill_type'] == "cdr") {
    - -
    - /> + />
    - /> + />
    diff --git a/html/pages/device/edit/health.inc.php b/html/pages/device/edit/health.inc.php index 3d7d213527..922bb36c77 100644 --- a/html/pages/device/edit/health.inc.php +++ b/html/pages/device/edit/health.inc.php @@ -30,156 +30,158 @@ $sensor['sensor_id'], 'sensor_limit' => $sensor['sensor_limit'], 'sensor_limit_low' => $sensor['sensor_limit_low'], 'sensor_alert' => $sensor['sensor_alert']); - if($sensor['sensor_alert'] == 1) - { - $alert_status = 'checked'; - } - else - { - $alert_status = ''; - } - if ($sensor['sensor_custom'] == 'No') { - $custom = 'disabled'; - } else { - $custom = ''; - } - echo(' - - '.$sensor['sensor_class'].' - '.$sensor['sensor_type'].' - '.$sensor['sensor_descr'].' - '.$sensor['sensor_current'].' - -
    +foreach (dbFetchRows("SELECT * FROM sensors WHERE device_id = ? AND sensor_deleted='0'", array($device['device_id'])) as $sensor) { + $rollback[] = array( + 'sensor_id' => $sensor['sensor_id'], + 'sensor_limit' => $sensor['sensor_limit'], + 'sensor_limit_low' => $sensor['sensor_limit_low'], + 'sensor_alert' => $sensor['sensor_alert'], + ); + if ($sensor['sensor_alert'] == 1) { + $alert_status = 'checked'; + } + else { + $alert_status = ''; + } + + if ($sensor['sensor_custom'] == 'No') { + $custom = 'disabled'; + } + else { + $custom = ''; + } + + echo ' + + '.$sensor['sensor_class'].' + '.$sensor['sensor_type'].' + '.$sensor['sensor_descr'].' + '.$sensor['sensor_current'].' + +
    -
    - - -
    +
    + + +
    -
    - - - - - +
    + + + + + Clear custom - - -'); + + + '; } - ?>
    - - - - '); +foreach ($rollback as $reset_data) { + echo ' + + + + + '; } ?>
    - diff --git a/html/pages/device/edit/ipmi.inc.php b/html/pages/device/edit/ipmi.inc.php index f3971ca413..0aff50bdd7 100644 --- a/html/pages/device/edit/ipmi.inc.php +++ b/html/pages/device/edit/ipmi.inc.php @@ -1,31 +1,45 @@ "7") - { - $ipmi_hostname = mres($_POST['ipmi_hostname']); - $ipmi_username = mres($_POST['ipmi_username']); - $ipmi_password = mres($_POST['ipmi_password']); +if ($_POST['editing']) { + if ($_SESSION['userlevel'] > '7') { + $ipmi_hostname = mres($_POST['ipmi_hostname']); + $ipmi_username = mres($_POST['ipmi_username']); + $ipmi_password = mres($_POST['ipmi_password']); - if ($ipmi_hostname != '') { set_dev_attrib($device, 'ipmi_hostname', $ipmi_hostname); } else { del_dev_attrib($device, 'ipmi_hostname'); } - if ($ipmi_username != '') { set_dev_attrib($device, 'ipmi_username', $ipmi_username); } else { del_dev_attrib($device, 'ipmi_username'); } - if ($ipmi_password != '') { set_dev_attrib($device, 'ipmi_password', $ipmi_password); } else { del_dev_attrib($device, 'ipmi_password'); } + if ($ipmi_hostname != '') { + set_dev_attrib($device, 'ipmi_hostname', $ipmi_hostname); + } + else { + del_dev_attrib($device, 'ipmi_hostname'); + } - $update_message = "Device IPMI data updated."; - $updated = 1; - } - else - { - include("includes/error-no-perm.inc.php"); - } + if ($ipmi_username != '') { + set_dev_attrib($device, 'ipmi_username', $ipmi_username); + } + else { + del_dev_attrib($device, 'ipmi_username'); + } + + if ($ipmi_password != '') { + set_dev_attrib($device, 'ipmi_password', $ipmi_password); + } + else { + del_dev_attrib($device, 'ipmi_password'); + } + + $update_message = 'Device IPMI data updated.'; + $updated = 1; + } + else { + include 'includes/error-no-perm.inc.php'; + }//end if +}//end if + +if ($updated && $update_message) { + print_message($update_message); } - -if ($updated && $update_message) -{ - print_message($update_message); -} elseif ($update_message) { - print_error($update_message); +else if ($update_message) { + print_error($update_message); } ?> @@ -37,19 +51,19 @@ if ($updated && $update_message)
    - +
    - +
    - +
    diff --git a/html/pages/device/edit/modules.inc.php b/html/pages/device/edit/modules.inc.php index 36a53b3f10..3196171626 100644 --- a/html/pages/device/edit/modules.inc.php +++ b/html/pages/device/edit/modules.inc.php @@ -17,68 +17,57 @@ $module_status) -{ - echo(' +foreach ($config['poller_modules'] as $module => $module_status) { + echo(' '.$module.' -'); + '); - if($module_status == 1) - { - echo('Enabled'); - } - else - { - echo('Disabled'); - } + if($module_status == 1) { + echo('Enabled'); + } + else { + echo('Disabled'); + } - echo(' + echo(' -'); + '); - if (isset($attribs['poll_'.$module])) - { - if ($attribs['poll_'.$module]) - { - echo('Enabled'); - $module_checked = 'checked'; + if (isset($attribs['poll_'.$module])) { + if ($attribs['poll_'.$module]) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - else - { - echo('Disabled'); - $module_checked = ''; + else { + if($module_status == 1) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - } - else - { - if($module_status == 1) - { - echo('Enabled'); - $module_checked = 'checked'; - } - else - { - echo('Disabled'); - $module_checked = ''; - } - } - echo(' + echo(' -'); + '); - echo(' - -'); + echo(''); - echo(' + echo(' -'); + '); } ?> @@ -96,71 +85,56 @@ foreach ($config['poller_modules'] as $module => $module_status) $module_status) -{ - - echo(' +foreach ($config['discovery_modules'] as $module => $module_status) { + echo(' '.$module.' -'); + '); - if($module_status == 1) - { - echo('Enabled'); - } - else - { - echo('Disabled'); - } + if($module_status == 1) { + echo('Enabled'); + } + else { + echo('Disabled'); + } - echo(' + echo(' - -'); + '); - if (isset($attribs['discover_'.$module])) - { - if($attribs['discover_'.$module]) - { - echo('Enabled'); - $module_checked = 'checked'; + if (isset($attribs['discover_'.$module])) { + if($attribs['discover_'.$module]) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - else - { - echo('Disabled'); - $module_checked = ''; + else { + if($module_status == 1) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - } - else - { - if($module_status == 1) - { - echo('Enabled'); - $module_checked = 'checked'; - } - else - { - echo('Disabled'); - $module_checked = ''; - } - } - echo(' + echo(' - -'); + '); - echo(' - -'); + echo(''); - echo(' + echo(' - -'); + '); } echo(' diff --git a/html/pages/device/edit/ports.inc.php b/html/pages/device/edit/ports.inc.php index b382cf05a8..d8dc562e43 100644 --- a/html/pages/device/edit/ports.inc.php +++ b/html/pages/device/edit/ports.inc.php @@ -1,28 +1,26 @@ '); +echo '
    '; -if ($_POST['ignoreport']) -{ - if ($_SESSION['userlevel'] == '10') - { - include("includes/port-edit.inc.php"); - } +if ($_POST['ignoreport']) { + if ($_SESSION['userlevel'] == '10') { + include 'includes/port-edit.inc.php'; + } } -if ($updated && $update_message) -{ - print_message($update_message); -} elseif ($update_message) { - print_error($update_message); +if ($updated && $update_message) { + print_message($update_message); +} +else if ($update_message) { + print_error($update_message); } -echo("
    +echo "
    - "); + "; -echo(" +echo "
    @@ -41,14 +39,14 @@ echo("
    Index Name
    -"); +"; ?> '; + echo ''; + echo ''; + echo ''; - echo(""); - echo(""); - echo(""); - echo(""); + // Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled + // - as to draw the attention to a possible problem. + $isportbad = ($port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] != 'down') ? 1 : 0; + $dowecare = ($port['ignore'] == 0 && $port['disabled'] == 0) ? $isportbad : !$isportbad; + $outofsync = $dowecare ? " class='red'" : ''; - # Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled - # - as to draw the attention to a possible problem. - $isportbad = ($port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] != 'down') ? 1 : 0; - $dowecare = ($port['ignore'] == 0 && $port['disabled'] == 0) ? $isportbad : !$isportbad; - $outofsync = $dowecare ? " class='red'" : ""; + echo "'; - echo(""); + echo '"); + echo '"); - echo(""); + echo "\n"; - echo("\n"); + $row++; +}//end foreach - $row++; -} - -echo('
    '.$port['ifIndex'].''.$port['label'].''.$port['ifAdminStatus'].'
    ". $port['ifIndex']."".$port['label'] . "". $port['ifAdminStatus']."'.$port['ifOperStatus'].'". $port['ifOperStatus']."'; + echo "'; + echo ""); - echo(""); - echo(""); - echo("'; + echo "'; + echo ""); - echo(""); - echo(""); - echo("".$port['ifAlias'] . "
    '); -echo('
    '); -echo('
    '); - -?> +echo ''; +echo ''; +echo '
    '; diff --git a/html/pages/device/edit/services.inc.php b/html/pages/device/edit/services.inc.php index e6969a9fe9..1f2bc1d30e 100644 --- a/html/pages/device/edit/services.inc.php +++ b/html/pages/device/edit/services.inc.php @@ -1,29 +1,28 @@ = '10') { - include("includes/service-add.inc.php"); + include 'includes/service-add.inc.php'; } } if ($_POST['delsrv']) { if ($_SESSION['userlevel'] >= '10') { - include("includes/service-delete.inc.php"); + include 'includes/service-delete.inc.php'; } } if ($_POST['confirm-editsrv']) { - echo "yeah"; + echo 'yeah'; if ($_SESSION['userlevel'] >= '10') { - include("includes/service-edit.inc.php"); + include 'includes/service-edit.inc.php'; } } - if ($handle = opendir($config['install_dir'] . "/includes/services/")) { + if ($handle = opendir($config['install_dir'].'/includes/services/')) { while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != ".." && !strstr($file, ".")) { + if ($file != '.' && $file != '..' && !strstr($file, '.')) { $servicesform .= ""; } } @@ -31,17 +30,17 @@ if (is_admin() === TRUE || is_read() === TRUE) { closedir($handle); } - $dev = device_by_id_cache($device['device_id']); - $devicesform = ""; + $dev = device_by_id_cache($device['device_id']); + $devicesform = "'; if ($updated) { - print_message("Device Settings Saved"); + print_message('Device Settings Saved'); } - if (dbFetchCell("SELECT COUNT(*) from `services` WHERE `device_id` = ?", array($device['device_id'])) > '0') { - $i = "1"; - foreach (dbFetchRows("select * from services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $service) { - $existform .= ""; + if (dbFetchCell('SELECT COUNT(*) from `services` WHERE `device_id` = ?', array($device['device_id'])) > '0') { + $i = '1'; + foreach (dbFetchRows('select * from services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $service) { + $existform .= "'; } } @@ -49,28 +48,29 @@ if (is_admin() === TRUE || is_read() === TRUE) { if ($existform) { echo '
    '; - if ($_POST['editsrv'] == "yes") { - include_once "includes/print-service-edit.inc.php"; - } else { + if ($_POST['editsrv'] == 'yes') { + include_once 'includes/print-service-edit.inc.php'; + } + else { echo " -

    Edit / Delete Service

    -
    +

    Edit / Delete Service

    +
    -
    - -
    - -
    -
    -
    -
    - -
    -
    +
    + +
    +
    - "; +
    +
    +
    + +
    +
    +
    + "; } echo '
    '; @@ -78,8 +78,8 @@ if (is_admin() === TRUE || is_read() === TRUE) { echo '
    '; - require_once "includes/print-service-add.inc.php"; - -} else { - include("includes/error-no-perm.inc.php"); -} \ No newline at end of file + include_once 'includes/print-service-add.inc.php'; +} +else { + include 'includes/error-no-perm.inc.php'; +} diff --git a/html/pages/device/edit/snmp.inc.php b/html/pages/device/edit/snmp.inc.php index 9e8a5b7b04..59c6bf4cd3 100644 --- a/html/pages/device/edit/snmp.inc.php +++ b/html/pages/device/edit/snmp.inc.php @@ -1,225 +1,240 @@ "7") - { - $community = mres($_POST['community']); - $snmpver = mres($_POST['snmpver']); - $transport = $_POST['transport'] ? mres($_POST['transport']) : $transport = "udp"; - $port = $_POST['port'] ? mres($_POST['port']) : $config['snmp']['port']; - $timeout = mres($_POST['timeout']); - $retries = mres($_POST['retries']); - $poller_group = mres($_POST['poller_group']); - $v3 = array ( - 'authlevel' => mres($_POST['authlevel']), - 'authname' => mres($_POST['authname']), - 'authpass' => mres($_POST['authpass']), - 'authalgo' => mres($_POST['authalgo']), - 'cryptopass' => mres($_POST['cryptopass']), - 'cryptoalgo' => mres($_POST['cryptoalgo']) - ); +if ($_POST['editing']) { + if ($_SESSION['userlevel'] > '7') { + $community = mres($_POST['community']); + $snmpver = mres($_POST['snmpver']); + $transport = $_POST['transport'] ? mres($_POST['transport']) : $transport = 'udp'; + $port = $_POST['port'] ? mres($_POST['port']) : $config['snmp']['port']; + $timeout = mres($_POST['timeout']); + $retries = mres($_POST['retries']); + $poller_group = mres($_POST['poller_group']); + $v3 = array( + 'authlevel' => mres($_POST['authlevel']), + 'authname' => mres($_POST['authname']), + 'authpass' => mres($_POST['authpass']), + 'authalgo' => mres($_POST['authalgo']), + 'cryptopass' => mres($_POST['cryptopass']), + 'cryptoalgo' => mres($_POST['cryptoalgo']), + ); - #FIXME needs better feedback - $update = array( - 'community' => $community, - 'snmpver' => $snmpver, - 'port' => $port, - 'transport' => $transport, - 'poller_group' => $poller_group - ); + // FIXME needs better feedback + $update = array( + 'community' => $community, + 'snmpver' => $snmpver, + 'port' => $port, + 'transport' => $transport, + 'poller_group' => $poller_group, + ); - if ($_POST['timeout']) { $update['timeout'] = $timeout; } - else { $update['timeout'] = array('NULL'); } - if ($_POST['retries']) { $update['retries'] = $retries; } - else { $update['retries'] = array('NULL'); } - - $update = array_merge($update, $v3); - - $device_tmp = deviceArray($device['hostname'], $community, $snmpver, $port, $transport, $v3); - if (isSNMPable($device_tmp)) { - $rows_updated = dbUpdate($update, 'devices', '`device_id` = ?',array($device['device_id'])); - - if ($rows_updated > 0) { - $update_message = $rows_updated . " Device record updated."; - $updated = 1; - } elseif ($rows_updated = '-1') { - $update_message = "Device record unchanged. No update necessary."; - $updated = -1; - } else { - $update_message = "Device record update error."; - $updated = 0; + if ($_POST['timeout']) { + $update['timeout'] = $timeout; + } + else { + $update['timeout'] = array('NULL'); } - } else { - $update_message = "Could not connect to device with new SNMP details"; - $updated = 0; - } - } -} -$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id'])); + if ($_POST['retries']) { + $update['retries'] = $retries; + } + else { + $update['retries'] = array('NULL'); + } + + $update = array_merge($update, $v3); + + $device_tmp = deviceArray($device['hostname'], $community, $snmpver, $port, $transport, $v3); + if (isSNMPable($device_tmp)) { + $rows_updated = dbUpdate($update, 'devices', '`device_id` = ?', array($device['device_id'])); + + if ($rows_updated > 0) { + $update_message = $rows_updated.' Device record updated.'; + $updated = 1; + } + else if ($rows_updated = '-1') { + $update_message = 'Device record unchanged. No update necessary.'; + $updated = -1; + } + else { + $update_message = 'Device record update error.'; + $updated = 0; + } + } + else { + $update_message = 'Could not connect to device with new SNMP details'; + $updated = 0; + } + }//end if +}//end if + +$device = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($device['device_id'])); $descr = $device['purpose']; -echo('
    -
    '); -if ($updated && $update_message) -{ - print_message($update_message); -} elseif ($update_message) { - print_error($update_message); +echo '
    +
    '; +if ($updated && $update_message) { + print_message($update_message); +} +else if ($update_message) { + print_error($update_message); } -echo('
    -
    '); -echo(" -
    - -
    +echo '
    +
    '; + +echo " + + +
    - +
    - +
    - "; foreach ($config['snmp']['transports'] as $transport) { - echo(""); + + echo '>'.$transport.''; } -echo(" + +echo "
    -
    -
    +
    +
    - +
    - +
    -
    -
    +
    +
    - +
    - -
    - -
    + +
    +
    -
    -
    +
    +
    +
    - +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    +
    -
    "); +
    +
    '; -if ($config['distributed_poller'] === TRUE) { - echo(' -
    - -
    - + + '; - foreach (dbFetchRows("SELECT `id`,`group_name` FROM `poller_groups`") as $group) { - echo ''; + + echo '>'.$group['group_name'].''; } - echo(' - -
    -
    - '); -} + echo ' + +
    +
    + '; +}//end if -echo(' - - -'); +echo ' + + + '; ?> diff --git a/html/pages/device/entphysical.inc.php b/html/pages/device/entphysical.inc.php index af167b4ddc..7b5d956faa 100644 --- a/html/pages/device/entphysical.inc.php +++ b/html/pages/device/entphysical.inc.php @@ -1,13 +1,11 @@ "; @@ -33,7 +31,8 @@ function printEntPhysical($ent, $level, $class) if (count($sensor)) { $link = " href='device/device=".$device['device_id'].'/tab=health/metric='.$sensor['sensor_class']."/' onmouseover=\"return overlib('', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\""; } - } else { + } + else { unset($link); } diff --git a/html/pages/device/graphs.inc.php b/html/pages/device/graphs.inc.php index a275e71e31..e4bd13d84c 100644 --- a/html/pages/device/graphs.inc.php +++ b/html/pages/device/graphs.inc.php @@ -1,70 +1,68 @@ 'device', + 'device' => $device['device_id'], + 'tab' => 'graphs', +); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'graphs'); +$bg = '#ffffff'; -$bg="#ffffff"; - -echo('
    '); +echo '
    '; print_optionbar_start(); -echo("Graphs » "); +echo "Graphs » "; -foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph", array($device['device_id'])) as $graph) -{ - $section = $config['graph_types']['device'][$graph['graph']]['section']; - if ($section != "") { - $graph_enable[$section][$graph['graph']] = $graph['graph']; - } +foreach (dbFetchRows('SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph', array($device['device_id'])) as $graph) { + $section = $config['graph_types']['device'][$graph['graph']]['section']; + if ($section != '') { + $graph_enable[$section][$graph['graph']] = $graph['graph']; + } } // These are standard graphs we should have for all systems $graph_enable['poller']['poller_perf'] = 'device_poller_perf'; -$graph_enable['poller']['ping_perf'] = 'device_ping_perf'; +$graph_enable['poller']['ping_perf'] = 'device_ping_perf'; -$sep = ""; -foreach ($graph_enable as $section => $nothing) -{ - if (isset($graph_enable) && is_array($graph_enable[$section])) - { - $type = strtolower($section); - if (!$vars['group']) { $vars['group'] = $type; } - echo($sep); - if ($vars['group'] == $type) - { - echo(''); +$sep = ''; +foreach ($graph_enable as $section => $nothing) { + if (isset($graph_enable) && is_array($graph_enable[$section])) { + $type = strtolower($section); + if (!$vars['group']) { + $vars['group'] = $type; + } + + echo $sep; + if ($vars['group'] == $type) { + echo ''; + } + + echo generate_link(ucwords($type), $link_array, array('group' => $type)); + if ($vars['group'] == $type) { + echo ''; + } + + $sep = ' | '; } - echo(generate_link(ucwords($type),$link_array,array('group'=>$type))); - if ($vars['group'] == $type) - { - echo(""); - } - $sep = " | "; - } } -unset ($sep); + +unset($sep); print_optionbar_end(); $graph_enable = $graph_enable[$vars['group']]; -#foreach ($config['graph_types']['device'] as $graph => $entry) -foreach ($graph_enable as $graph => $entry) -{ - $graph_array = array(); - if ($graph_enable[$graph]) - { - $graph_title = $config['graph_types']['device'][$graph]['descr']; - $graph_array['type'] = "device_" . $graph; +// foreach ($config['graph_types']['device'] as $graph => $entry) +foreach ($graph_enable as $graph => $entry) { + $graph_array = array(); + if ($graph_enable[$graph]) { + $graph_title = $config['graph_types']['device'][$graph]['descr']; + $graph_array['type'] = 'device_'.$graph; - include("includes/print-device-graph.php"); - } + include 'includes/print-device-graph.php'; + } } -$pagetitle[] = "Graphs"; - -?> +$pagetitle[] = 'Graphs'; diff --git a/html/pages/device/graphs/netstats_ip_forward.inc.php b/html/pages/device/graphs/netstats_ip_forward.inc.php index cc728ac77c..eda137a788 100644 --- a/html/pages/device/graphs/netstats_ip_forward.inc.php +++ b/html/pages/device/graphs/netstats_ip_forward.inc.php @@ -1,11 +1,8 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'health'); +if ($storage) { + $datas[] = 'storage'; +} + +if ($diskio) { + $datas[] = 'diskio'; +} + +if ($charge) { + $datas[] = 'charge'; +} + +if ($temperatures) { + $datas[] = 'temperature'; +} + +if ($humidity) { + $datas[] = 'humidity'; +} + +if ($fans) { + $datas[] = 'fanspeed'; +} + +if ($volts) { + $datas[] = 'voltage'; +} + +if ($freqs) { + $datas[] = 'frequency'; +} + +if ($current) { + $datas[] = 'current'; +} + +if ($power) { + $datas[] = 'power'; +} + +if ($dBm) { + $datas[] = 'dbm'; +} + +if ($states) { + $datas[] = 'state'; +} + +if ($load) { + $datas[] = 'load'; +} + +$type_text['overview'] = 'Overview'; +$type_text['charge'] = 'Battery Charge'; +$type_text['temperature'] = 'Temperature'; +$type_text['humidity'] = 'Humidity'; +$type_text['mempool'] = 'Memory'; +$type_text['storage'] = 'Disk Usage'; +$type_text['diskio'] = 'Disk I/O'; +$type_text['processor'] = 'Processor'; +$type_text['voltage'] = 'Voltage'; +$type_text['fanspeed'] = 'Fanspeed'; +$type_text['frequency'] = 'Frequency'; +$type_text['current'] = 'Current'; +$type_text['power'] = 'Power'; +$type_text['dbm'] = 'dBm'; +$type_text['state'] = 'State'; +$type_text['load'] = 'Load'; + +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'health', +); print_optionbar_start(); -echo("Health » "); +echo "Health » "; -if (!$vars['metric']) { $vars['metric'] = "overview"; } +if (!$vars['metric']) { + $vars['metric'] = 'overview'; +} unset($sep); -foreach ($datas as $type) -{ - echo($sep); +foreach ($datas as $type) { + echo $sep; - if ($vars['metric'] == $type) - { echo(''); } - echo(generate_link($type_text[$type],$link_array,array('metric'=>$type))); - if ($vars['metric'] == $type) { echo(""); } - $sep = " | "; + if ($vars['metric'] == $type) { + echo ''; + } + + echo generate_link($type_text[$type], $link_array, array('metric' => $type)); + if ($vars['metric'] == $type) { + echo ''; + } + + $sep = ' | '; } print_optionbar_end(); -if (is_file("pages/device/health/".mres($vars['metric']).".inc.php")) -{ - include("pages/device/health/".mres($vars['metric']).".inc.php"); -} else { +if (is_file('pages/device/health/'.mres($vars['metric']).'.inc.php')) { + include 'pages/device/health/'.mres($vars['metric']).'.inc.php'; +} +else { + foreach ($datas as $type) { + if ($type != 'overview') { + $graph_title = $type_text[$type]; + $graph_array['type'] = 'device_'.$type; - foreach ($datas as $type) - { - if ($type != "overview") - { - - $graph_title = $type_text[$type]; - $graph_array['type'] = "device_".$type; - - include("includes/print-device-graph.php"); + include 'includes/print-device-graph.php'; + } } - } } -$pagetitle[] = "Health"; - -?> +$pagetitle[] = 'Health'; diff --git a/html/pages/device/health/charge.inc.php b/html/pages/device/health/charge.inc.php index 7282247bff..0750ae5935 100644 --- a/html/pages/device/health/charge.inc.php +++ b/html/pages/device/health/charge.inc.php @@ -1,9 +1,7 @@ +require 'sensors.inc.php'; diff --git a/html/pages/device/health/current.inc.php b/html/pages/device/health/current.inc.php index 0fa318a9b3..70bd4dc425 100644 --- a/html/pages/device/health/current.inc.php +++ b/html/pages/device/health/current.inc.php @@ -4,6 +4,4 @@ $class = "current"; $unit = "A"; $graph_type = "sensor_current"; -include("sensors.inc.php"); - -?> +require 'sensors.inc.php'; diff --git a/html/pages/device/health/humidity.inc.php b/html/pages/device/health/humidity.inc.php index 93b4772a3f..ffef7afa6a 100644 --- a/html/pages/device/health/humidity.inc.php +++ b/html/pages/device/health/humidity.inc.php @@ -4,6 +4,4 @@ $class = "humidity"; $unit = "%"; $graph_type = "sensor_humidity"; -include("sensors.inc.php"); - -?> +require 'sensors.inc.php'; diff --git a/html/pages/device/health/load.inc.php b/html/pages/device/health/load.inc.php index 399237aaef..18f5b5f5cd 100644 --- a/html/pages/device/health/load.inc.php +++ b/html/pages/device/health/load.inc.php @@ -1,9 +1,7 @@ +require 'sensors.inc.php'; diff --git a/html/pages/device/health/mempool.inc.php b/html/pages/device/health/mempool.inc.php index 6630c31476..613aa1250b 100644 --- a/html/pages/device/health/mempool.inc.php +++ b/html/pages/device/health/mempool.inc.php @@ -1,66 +1,72 @@ "); -echo(""); +echo "
    "; +echo '
    '; $i = '1'; -#FIXME css alternating colours +// FIXME css alternating colours +foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($device['device_id'])) as $mempool) { + if (!is_integer($i / 2)) { + $row_colour = $list_colour_a; + } + else { + $row_colour = $list_colour_b; + } -foreach (dbFetchRows("SELECT * FROM `mempools` WHERE device_id = ?", array($device['device_id'])) as $mempool) -{ - if (!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + if ($config['memcached']['enable'] === true) { + $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); + if ($debug) { + print_r($state); + } - if ($config['memcached']['enable'] === TRUE) - { - $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $mempool = array_merge($mempool, $state); } - unset($state); - } + if (is_array($state)) { + $mempool = array_merge($mempool, $state); + } - $text_descr = rewrite_entity_descr($mempool['mempool_descr']); + unset($state); + } - $mempool_url = "graphs/id=".$mempool['mempool_id']."/type=mempool_usage/"; - $mini_url = "graph.php?id=".$mempool['mempool_id']."&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=80&height=20&bg=f4f4f4"; + $text_descr = rewrite_entity_descr($mempool['mempool_descr']); - $mempool_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$text_descr; - $mempool_popup .= "
    "; - $mempool_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; + $mempool_url = 'graphs/id='.$mempool['mempool_id'].'/type=mempool_usage/'; + $mini_url = 'graph.php?id='.$mempool['mempool_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; - $total = formatStorage($mempool['mempool_total']); - $used = formatStorage($mempool['mempool_used']); - $free = formatStorage($mempool['mempool_free']); + $mempool_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; + $mempool_popup .= "
    "; + $mempool_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; - $perc = round($mempool['mempool_used'] / $mempool['mempool_total'] * 100); + $total = formatStorage($mempool['mempool_total']); + $used = formatStorage($mempool['mempool_used']); + $free = formatStorage($mempool['mempool_free']); - $background = get_percentage_colours($percent); - $right_background = $background['right']; - $left_background = $background['left']; + $perc = round(($mempool['mempool_used'] / $mempool['mempool_total'] * 100)); - echo(" - - - - "); + $background = get_percentage_colours($percent); + $right_background = $background['right']; + $left_background = $background['left']; - echo(" + + + + '; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; + echo ""); + include 'includes/print-graphrow.inc.php'; - $i++; -} + echo ''; -echo("
    " . $text_descr . " - ".print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $left_background, $free , "ffffff", $right_background)." - ".$perc."%
    "); + echo "
    ".$text_descr." + ".print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $left_background, $free, 'ffffff', $right_background).' + '.$perc.'%
    "; - include("includes/print-graphrow.inc.php"); + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; - echo("
    "); -echo("
    "); + $i++; +}//end foreach -?> +echo ''; +echo '
    '; diff --git a/html/pages/device/health/processor.inc.php b/html/pages/device/health/processor.inc.php index bde4a3b3f1..725e37c21f 100644 --- a/html/pages/device/health/processor.inc.php +++ b/html/pages/device/health/processor.inc.php @@ -1,46 +1,43 @@ "); -echo(""); +echo "
    "; +echo '
    '; $i = '1'; -foreach (dbFetchRows("SELECT * FROM `processors` WHERE device_id = ?", array($device['device_id'])) as $proc) -{ - $proc_url = "graphs/id=".$proc['processor_id']."/type=processor_usage/"; +foreach (dbFetchRows('SELECT * FROM `processors` WHERE device_id = ?', array($device['device_id'])) as $proc) { + $proc_url = 'graphs/id='.$proc['processor_id'].'/type=processor_usage/'; - $mini_url = "graph.php?id=".$proc['processor_id']."&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=80&height=20&bg=f4f4f4"; + $mini_url = 'graph.php?id='.$proc['processor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; - $text_descr = $proc['processor_descr']; + $text_descr = $proc['processor_descr']; - $text_descr = rewrite_entity_descr($text_descr); + $text_descr = rewrite_entity_descr($text_descr); - $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$text_descr; - $proc_popup .= "
    "; - $proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; + $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; + $proc_popup .= "
    "; + $proc_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; - $percent = round($proc['processor_usage']); + $percent = round($proc['processor_usage']); - $background = get_percentage_colours($percent); + $background = get_percentage_colours($percent); - echo(" - + echo (" + - "); + '); - echo("
    " . $text_descr . "
    ".$text_descr." - ".print_percentage_bar (400, 20, $percent, $percent."%", "ffffff", $background['left'], (100 - $percent)."%" , "ffffff", $background['right'])." + ".print_percentage_bar(400, 20, $percent, $percent.'%', 'ffffff', $background['left'], (100 - $percent).'%', 'ffffff', $background['right']).'
    "); + echo "
    "; - $graph_array['id'] = $proc['processor_id']; - $graph_array['type'] = $graph_type; + $graph_array['id'] = $proc['processor_id']; + $graph_array['type'] = $graph_type; - include("includes/print-graphrow.inc.php"); -} + include 'includes/print-graphrow.inc.php'; +}//end foreach -echo("
    "); -echo(""); - -?> +echo ''; +echo ''; diff --git a/html/pages/device/health/state.inc.php b/html/pages/device/health/state.inc.php index 5463962196..9781248bea 100644 --- a/html/pages/device/health/state.inc.php +++ b/html/pages/device/health/state.inc.php @@ -1,7 +1,7 @@ "); +echo ''; -echo(" +echo ' - "); + '; $row = 1; -foreach (dbFetchRows("SELECT * FROM `storage` WHERE device_id = ? ORDER BY storage_descr", array($device['device_id'])) as $drive) -{ - if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } +foreach (dbFetchRows('SELECT * FROM `storage` WHERE device_id = ? ORDER BY storage_descr', array($device['device_id'])) as $drive) { + if (is_integer($row / 2)) { + $row_colour = $list_colour_a; + } + else { + $row_colour = $list_colour_b; + } - $total = $drive['storage_size']; - $used = $drive['storage_used']; - $free = $drive['storage_free']; - $perc = round($drive['storage_perc'], 0); - $used = formatStorage($used); - $total = formatStorage($total); - $free = formatStorage($free); + $total = $drive['storage_size']; + $used = $drive['storage_used']; + $free = $drive['storage_free']; + $perc = round($drive['storage_perc'], 0); + $used = formatStorage($used); + $total = formatStorage($total); + $free = formatStorage($free); - $fs_url = "graphs/id=".$drive['storage_id']."/type=storage_usage/"; + $fs_url = 'graphs/id='.$drive['storage_id'].'/type=storage_usage/'; - $fs_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$drive['storage_descr']; - $fs_popup .= "
    "; - $fs_popup .= "', RIGHT, FGCOLOR, '#e5e5e5');\" onmouseout=\"return nd();\""; + $fs_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$drive['storage_descr']; + $fs_popup .= "
    "; + $fs_popup .= "', RIGHT, FGCOLOR, '#e5e5e5');\" onmouseout=\"return nd();\""; - $background = get_percentage_colours($percent); + $background = get_percentage_colours($percent); - echo(""); + echo "'; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; - echo(""); + echo ''; - $row++; -} + $row++; +}//end foreach -echo("
    Drive Usage Free
    " . $drive['storage_descr'] . " - ".print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $perc . "%", "ffffff", $background['right'])." - " . $free . "
    ".$drive['storage_descr']." + ".print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $perc.'%', 'ffffff', $background['right']).' + '.$free.'
    "); + echo "
    "; - include("includes/print-graphrow.inc.php"); + include 'includes/print-graphrow.inc.php'; - echo("
    "); - -?> +echo ''; diff --git a/html/pages/device/hrdevice.inc.php b/html/pages/device/hrdevice.inc.php index 68928187b3..d16a0ba839 100644 --- a/html/pages/device/hrdevice.inc.php +++ b/html/pages/device/hrdevice.inc.php @@ -1,70 +1,69 @@ '); +echo ''; // FIXME missing heading +foreach (dbFetchRows('SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`', array($device['device_id'])) as $hrdevice) { + echo "'; -foreach (dbFetchRows("SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`", array($device['device_id'])) as $hrdevice) -{ - echo(""); + if ($hrdevice['hrDeviceType'] == 'hrDeviceProcessor') { + $proc_id = dbFetchCell("SELECT processor_id FROM processors WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrdevice['hrDeviceIndex']."'"); + $proc_url = 'device/device='.$device['device_id'].'/tab=health/metric=processor/'; + $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$hrdevice['hrDeviceDescr']; + $proc_popup .= "
    "; + $proc_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; + echo "'; - if ($hrdevice['hrDeviceType'] == "hrDeviceProcessor") - { - $proc_id = dbFetchCell("SELECT processor_id FROM processors WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrdevice['hrDeviceIndex']."'"); - $proc_url = "device/device=".$device['device_id']."/tab=health/metric=processor/"; - $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$hrdevice['hrDeviceDescr']; - $proc_popup .= "
    "; - $proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; - echo(""); + $graph_array['height'] = '20'; + $graph_array['width'] = '100'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $proc_id; + $graph_array['type'] = 'processor_usage'; + $graph_array['from'] = $config['time']['day']; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; - $graph_array['height'] = "20"; - $graph_array['width'] = "100"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $proc_id; - $graph_array['type'] = 'processor_usage'; - $graph_array['from'] = $config['time']['day']; - $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; + $mini_graph = overlib_link($proc_url, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); - $mini_graph = overlib_link($proc_url, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); - - echo(''); - } - elseif ($hrdevice['hrDeviceType'] == "hrDeviceNetwork") - { - $int = str_replace("network interface ", "", $hrdevice['hrDeviceDescr']); - $interface = dbFetchRow("SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?", array($device['device_id'], $int)); - if ($interface['ifIndex']) - { - echo(""); - - $graph_array['height'] = "20"; - $graph_array['width'] = "100"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $interface['port_id']; - $graph_array['type'] = 'port_bits'; - $graph_array['from'] = $config['time']['day']; - $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; - - // FIXME click on graph should also link to port, but can't use generate_port_link here... - $mini_graph = overlib_link(generate_port_url($interface), generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); - - echo(""); - } else { - echo(""); - echo(""); + echo ''; } - } else { - echo(""); - echo(""); - } + else if ($hrdevice['hrDeviceType'] == 'hrDeviceNetwork') { + $int = str_replace('network interface ', '', $hrdevice['hrDeviceDescr']); + $interface = dbFetchRow('SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?', array($device['device_id'], $int)); + if ($interface['ifIndex']) { + echo ''; - echo(""); - echo(""); - echo(""); -} + $graph_array['height'] = '20'; + $graph_array['width'] = '100'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $interface['port_id']; + $graph_array['type'] = 'port_bits'; + $graph_array['from'] = $config['time']['day']; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; -echo('
    ".$hrdevice['hrDeviceIndex'].'
    ".$hrdevice['hrDeviceIndex']."".$hrdevice['hrDeviceDescr'].'".$hrdevice['hrDeviceDescr']."'.$mini_graph.'".generate_port_link($interface)."$mini_graph".stripslashes($hrdevice['hrDeviceDescr'])."'.$mini_graph.'".stripslashes($hrdevice['hrDeviceDescr'])."'.generate_port_link($interface).'".$hrdevice['hrDeviceType'].''.$hrdevice['hrDeviceStatus']."".$hrdevice['hrDeviceErrors'].''.$hrdevice['hrProcessorLoad']."
    '); + // FIXME click on graph should also link to port, but can't use generate_port_link here... + $mini_graph = overlib_link(generate_port_url($interface), generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); -$pagetitle[] = "Inventory"; + echo "$mini_graph"; + } + else { + echo ''.stripslashes($hrdevice['hrDeviceDescr']).''; + echo ''; + } + } + else { + echo ''.stripslashes($hrdevice['hrDeviceDescr']).''; + echo ''; + }//end if -?> + echo ''.$hrdevice['hrDeviceType'].''.$hrdevice['hrDeviceStatus'].''; + echo ''.$hrdevice['hrDeviceErrors'].''.$hrdevice['hrProcessorLoad'].''; + echo ''; +}//end foreach + +echo ''; + +$pagetitle[] = 'Inventory'; diff --git a/html/pages/device/loadbalancer/ace_rservers.inc.php b/html/pages/device/loadbalancer/ace_rservers.inc.php index 52f1773c7e..c8b4b2acdc 100644 --- a/html/pages/device/loadbalancer/ace_rservers.inc.php +++ b/html/pages/device/loadbalancer/ace_rservers.inc.php @@ -33,10 +33,10 @@ echo ' Graphs: '; // "pkts" => "Packets", // "errors" => "Errors"); $graph_types = array( - 'curr' => 'CurrentConns', - 'failed' => 'FailedConns', - 'total' => 'TotalConns', - ); + 'curr' => 'CurrentConns', + 'failed' => 'FailedConns', + 'total' => 'TotalConns', +); foreach ($graph_types as $type => $descr) { echo "$type_sep"; @@ -66,7 +66,8 @@ foreach (dbFetchRows('SELECT * FROM `loadbalancer_rservers` WHERE `device_id` = if ($rserver['StateDescr'] == 'Server is now operational') { $rserver_class = 'green'; - } else { + } + else { $rserver_class = 'red'; } @@ -87,7 +88,7 @@ foreach (dbFetchRows('SELECT * FROM `loadbalancer_rservers` WHERE `device_id` = $graph_array['id'] = $rserver['rserver_id']; $graph_array['type'] = $graph_type; - include 'includes/print-graphrow.inc.php'; + require 'includes/print-graphrow.inc.php'; // include("includes/print-interface-graphs.inc.php"); echo ' diff --git a/html/pages/device/loadbalancer/ace_vservers.inc.php b/html/pages/device/loadbalancer/ace_vservers.inc.php index 65032709c8..68ebd1d3f5 100644 --- a/html/pages/device/loadbalancer/ace_vservers.inc.php +++ b/html/pages/device/loadbalancer/ace_vservers.inc.php @@ -2,84 +2,101 @@ print_optionbar_start(); -echo("Serverfarms » "); +echo "Serverfarms » "; -#$auth = TRUE; +// $auth = TRUE; +$menu_options = array('basic' => 'Basic'); -$menu_options = array('basic' => 'Basic', - ); +if (!$_GET['opta']) { + $_GET['opta'] = 'basic'; +} -if (!$_GET['opta']) { $_GET['opta'] = "basic"; } +$sep = ''; +foreach ($menu_options as $option => $text) { + if ($_GET['type'] == $option) { + echo ""; + } -$sep = ""; -foreach ($menu_options as $option => $text) -{ - if ($_GET['type'] == $option) { echo(""); } - echo(''.$text.''); - if ($_GET['type'] == $option) { echo(""); } - echo(" | "); + echo ''.$text.''; + if ($_GET['type'] == $option) { + echo ''; + } + + echo ' | '; } unset($sep); -echo(' Graphs: '); +echo ' Graphs: '; -$graph_types = array("bits" => "Bits", - "pkts" => "Packets", - "conns" => "Connections"); +$graph_types = array( + 'bits' => 'Bits', + 'pkts' => 'Packets', + 'conns' => 'Connections', +); -foreach ($graph_types as $type => $descr) -{ - echo("$type_sep"); - if ($_GET['opte'] == $type) { echo(""); } - echo(''.$descr.''); - echo(''.$text.''); - if ($_GET['opte'] == $type) { echo(""); } +foreach ($graph_types as $type => $descr) { + echo "$type_sep"; + if ($_GET['opte'] == $type) { + echo ""; + } - $type_sep = " | "; + echo ''.$descr.''; + echo ''.$text.''; + if ($_GET['opte'] == $type) { + echo ''; + } + + $type_sep = ' | '; } print_optionbar_end(); -echo("
    "); -$i = "0"; -foreach (dbFetchRows("SELECT * FROM `loadbalancer_vservers` WHERE `device_id` = ? ORDER BY `classmap`", array($device['device_id'])) as $vserver) -{ -if (is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } +echo "
    "; +$i = '0'; +foreach (dbFetchRows('SELECT * FROM `loadbalancer_vservers` WHERE `device_id` = ? ORDER BY `classmap`', array($device['device_id'])) as $vserver) { + if (is_integer($i / 2)) { + $bg_colour = $list_colour_a; + } + else { + $bg_colour = $list_colour_b; + } -if($vserver['serverstate'] == "inService") { $vserver_class="green"; } else { $vserver_class="red"; } + if ($vserver['serverstate'] == 'inService') { + $vserver_class = 'green'; + } + else { + $vserver_class = 'red'; + } -echo(""); -#echo(""); -echo(""); -#echo(""); -echo(""); -echo(""); - if ($_GET['type'] == "graphs") - { - echo(''); - echo(""; + // echo(""); + echo ''; + // echo(""); + echo "'; + echo ''; + if ($_GET['type'] == 'graphs') { + echo ''; + echo ' - "); - } + echo ' + + '; + } -echo(""); -echo(""); + echo ''; + echo ''; - $i++; -} + $i++; +}//end foreach -echo("
    " . $tunnel['local_addr'] . " » " . $tunnel['peer_addr'] . "" . $vserver['classmap'] . "" . $rserver['farm_id'] . "" . $vserver['serverstate'] . "
    "); - $graph_type = "vserver_" . $_GET['opte']; + echo "
    " . $tunnel['local_addr'] . " » " . $tunnel['peer_addr'] . "'.$vserver['classmap'].'" . $rserver['farm_id'] . "".$vserver['serverstate'].'
    '; + $graph_type = 'vserver_'.$_GET['opte']; -$graph_array['height'] = "100"; -$graph_array['width'] = "215"; -$graph_array['to'] = $config['time']['now']; -$graph_array['id'] = $vserver['classmap_id']; -$graph_array['type'] = $graph_type; + $graph_array['height'] = '100'; + $graph_array['width'] = '215'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $vserver['classmap_id']; + $graph_array['type'] = $graph_type; -include("includes/print-graphrow.inc.php"); + include 'includes/print-graphrow.inc.php'; - echo(" -
    "); - -?> +echo ''; diff --git a/html/pages/device/loadbalancer/netscaler_vsvr.inc.php b/html/pages/device/loadbalancer/netscaler_vsvr.inc.php index a67d755b9a..91abc8204f 100644 --- a/html/pages/device/loadbalancer/netscaler_vsvr.inc.php +++ b/html/pages/device/loadbalancer/netscaler_vsvr.inc.php @@ -1,6 +1,6 @@ VServer
    » "); // echo('All'); diff --git a/html/pages/device/logs.inc.php b/html/pages/device/logs.inc.php index 0b8481a68f..11fd6914ba 100644 --- a/html/pages/device/logs.inc.php +++ b/html/pages/device/logs.inc.php @@ -1,41 +1,43 @@ Logging » "); +echo 'Logging » '; -if ($vars['section'] == "eventlog") { - echo(''); +if ($vars['section'] == 'eventlog') { + echo ''; } -echo(generate_link("Event Log" , $vars, array('section'=>'eventlog'))); -if ($vars['section'] == "eventlog") { - echo(""); + +echo generate_link('Event Log', $vars, array('section' => 'eventlog')); +if ($vars['section'] == 'eventlog') { + echo ''; } if (isset($config['enable_syslog']) && $config['enable_syslog'] == 1) { - echo(" | "); + echo ' | '; - if ($vars['section'] == "syslog") { - echo(''); + if ($vars['section'] == 'syslog') { + echo ''; } - echo(generate_link("Syslog" , $vars, array('section'=>'syslog'))); - if ($vars['section'] == "syslog") { - echo(""); + + echo generate_link('Syslog', $vars, array('section' => 'syslog')); + if ($vars['section'] == 'syslog') { + echo ''; } } -switch ($vars['section']) -{ - case 'syslog': - case 'eventlog': - include('pages/device/logs/'.$vars['section'].'.inc.php'); - break; - default: - print_optionbar_end(); - echo(report_this('Unknown section '.$vars['section'])); - break; -} +switch ($vars['section']) { + case 'syslog': + case 'eventlog': + include 'pages/device/logs/'.$vars['section'].'.inc.php'; + break; -?> + default: + print_optionbar_end(); + echo report_this('Unknown section '.$vars['section']); + break; +} diff --git a/html/pages/device/logs/eventlog.inc.php b/html/pages/device/logs/eventlog.inc.php index aec8bdd98c..7d5204f1cd 100644 --- a/html/pages/device/logs/eventlog.inc.php +++ b/html/pages/device/logs/eventlog.inc.php @@ -2,51 +2,49 @@
    +echo '
    Eventlog entries
    - '); +
    '; -foreach ($entries as $entry) -{ - include("includes/print-event.inc.php"); +foreach ($entries as $entry) { + include 'includes/print-event.inc.php'; } -echo('
    -
    '); +echo ' + '; -$pagetitle[] = "Events"; - -?> +$pagetitle[] = 'Events'; diff --git a/html/pages/device/logs/syslog.inc.php b/html/pages/device/logs/syslog.inc.php index 7aae3b8e0c..1284ad157f 100644 --- a/html/pages/device/logs/syslog.inc.php +++ b/html/pages/device/logs/syslog.inc.php @@ -3,53 +3,54 @@
    +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? $where"; +$sql .= ' ORDER BY timestamp DESC LIMIT 1000'; +echo '
    Syslog entries
    - '); -foreach (dbFetchRows($sql, $param) as $entry) { include("includes/print-syslog.inc.php"); } -echo('
    -
    '); -$pagetitle[] = "Syslog"; + '; +foreach (dbFetchRows($sql, $param) as $entry) { + include 'includes/print-syslog.inc.php'; +} -?> +echo '
    + '; +$pagetitle[] = 'Syslog'; diff --git a/html/pages/device/map.inc.php b/html/pages/device/map.inc.php index 522de36a51..918f62e7fc 100644 --- a/html/pages/device/map.inc.php +++ b/html/pages/device/map.inc.php @@ -12,8 +12,6 @@ * the source code distribution for details. */ -$pagetitle[] = "Map"; +$pagetitle[] = 'Map'; -require_once "includes/print-map.inc.php"; - -?> +require_once 'includes/print-map.inc.php'; diff --git a/html/pages/device/munin.inc.php b/html/pages/device/munin.inc.php index 67fd22d6e0..e12279687e 100644 --- a/html/pages/device/munin.inc.php +++ b/html/pages/device/munin.inc.php @@ -1,75 +1,72 @@ 'device', + 'device' => $device['device_id'], + 'tab' => 'munin', +); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'munin'); +$bg = '#ffffff'; -$bg="#ffffff"; - -echo('
    '); +echo '
    '; print_optionbar_start(); -echo("Munin » "); +echo "Munin » "; -$sep = ""; +$sep = ''; -foreach (dbFetchRows("SELECT * FROM munin_plugins WHERE device_id = ? ORDER BY mplug_category, mplug_type", array($device['device_id'])) as $mplug) -{ -# if (strlen($mplug['mplug_category']) == 0) { $mplug['mplug_category'] = "general"; } else { } - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['id'] = $mplug['mplug_id']; - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['title'] = $mplug['mplug_title']; - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['plugin'] = $mplug['mplug_type']; +foreach (dbFetchRows('SELECT * FROM munin_plugins WHERE device_id = ? ORDER BY mplug_category, mplug_type', array($device['device_id'])) as $mplug) { + // if (strlen($mplug['mplug_category']) == 0) { $mplug['mplug_category'] = "general"; } else { } + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['id'] = $mplug['mplug_id']; + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['title'] = $mplug['mplug_title']; + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['plugin'] = $mplug['mplug_type']; } -foreach ($graph_enable as $section => $nothing) -{ - if (isset($graph_enable) && is_array($graph_enable[$section])) - { - $type = strtolower($section); - if (!$vars['group']) { $vars['group'] = $type; } - echo($sep); - if ($vars['group'] == $type) - { - echo(''); +foreach ($graph_enable as $section => $nothing) { + if (isset($graph_enable) && is_array($graph_enable[$section])) { + $type = strtolower($section); + if (!$vars['group']) { + $vars['group'] = $type; + } + + echo $sep; + if ($vars['group'] == $type) { + echo ''; + } + + echo generate_link(ucwords($type), $link_array, array('group' => $type)); + if ($vars['group'] == $type) { + echo ''; + } + + $sep = ' | '; } - echo(generate_link(ucwords($type),$link_array,array('group'=>$type))); - if ($vars['group'] == $type) - { - echo(""); - } - $sep = " | "; - } } -unset ($sep); +unset($sep); print_optionbar_end(); $graph_enable = $graph_enable[$vars['group']]; -#foreach ($config['graph_types']['device'] as $graph => $entry) -foreach ($graph_enable as $graph => $entry) -{ - $graph_array = array(); - if ($graph_enable[$graph]) - { - if (!empty($entry['plugin'])) - { - $graph_title = $entry['title']; - $graph_array['type'] = "munin_graph"; - $graph_array['device'] = $device['device_id']; - $graph_array['plugin'] = $entry['plugin']; - } else { - $graph_title = $config['graph_types']['device'][$graph]['descr']; - $graph_array['type'] = "device_" . $graph; - } +// foreach ($config['graph_types']['device'] as $graph => $entry) +foreach ($graph_enable as $graph => $entry) { + $graph_array = array(); + if ($graph_enable[$graph]) { + if (!empty($entry['plugin'])) { + $graph_title = $entry['title']; + $graph_array['type'] = 'munin_graph'; + $graph_array['device'] = $device['device_id']; + $graph_array['plugin'] = $entry['plugin']; + } + else { + $graph_title = $config['graph_types']['device'][$graph]['descr']; + $graph_array['type'] = 'device_'.$graph; + } - include("includes/print-device-graph.php"); - } + include 'includes/print-device-graph.php'; + } } -$pagetitle[] = "Graphs"; - -?> +$pagetitle[] = 'Graphs'; diff --git a/html/pages/device/overview.inc.php b/html/pages/device/overview.inc.php index aac3b2ca23..13227e0136 100644 --- a/html/pages/device/overview.inc.php +++ b/html/pages/device/overview.inc.php @@ -12,8 +12,18 @@ $services['up'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WH $services['down'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_status` = '0' AND `service_ignore` = '0'", array($device['device_id'])); $services['disabled'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_ignore` = '1'", array($device['device_id'])); -if ($services['down']) { $services_colour = $warn_colour_a; } else { $services_colour = $list_colour_a; } -if ($ports['down']) { $ports_colour = $warn_colour_a; } else { $ports_colour = $list_colour_a; } +if ($services['down']) { + $services_colour = $warn_colour_a; +} +else { + $services_colour = $list_colour_a; +} +if ($ports['down']) { + $ports_colour = $warn_colour_a; +} +else { + $ports_colour = $list_colour_a; +} echo('
    @@ -25,39 +35,41 @@ echo('
    '); -include("includes/dev-overview-data.inc.php"); +require 'includes/dev-overview-data.inc.php'; Plugins::call('device_overview_container',array($device)); -include("overview/ports.inc.php"); +require 'overview/ports.inc.php'; echo('
    '); // Right Pane -include("overview/processors.inc.php"); -include("overview/mempools.inc.php"); -include("overview/storage.inc.php"); +require 'overview/processors.inc.php'; +require 'overview/mempools.inc.php'; +require 'overview/storage.inc.php'; -if(is_array($entity_state['group']['c6kxbar'])) { include("overview/c6kxbar.inc.php"); } +if(is_array($entity_state['group']['c6kxbar'])) { + require 'overview/c6kxbar.inc.php'; +} -include("overview/toner.inc.php"); -include("overview/sensors/charge.inc.php"); -include("overview/sensors/temperatures.inc.php"); -include("overview/sensors/humidity.inc.php"); -include("overview/sensors/fanspeeds.inc.php"); -include("overview/sensors/dbm.inc.php"); -include("overview/sensors/voltages.inc.php"); -include("overview/sensors/current.inc.php"); -include("overview/sensors/power.inc.php"); -include("overview/sensors/frequencies.inc.php"); -include("overview/sensors/load.inc.php"); -include("overview/sensors/state.inc.php"); -include("overview/eventlog.inc.php"); -include("overview/services.inc.php"); -include("overview/syslog.inc.php"); +require 'overview/toner.inc.php'; +require 'overview/sensors/charge.inc.php'; +require 'overview/sensors/temperatures.inc.php'; +require 'overview/sensors/humidity.inc.php'; +require 'overview/sensors/fanspeeds.inc.php'; +require 'overview/sensors/dbm.inc.php'; +require 'overview/sensors/voltages.inc.php'; +require 'overview/sensors/current.inc.php'; +require 'overview/sensors/power.inc.php'; +require 'overview/sensors/frequencies.inc.php'; +require 'overview/sensors/load.inc.php'; +require 'overview/sensors/state.inc.php'; +require 'overview/eventlog.inc.php'; +require 'overview/services.inc.php'; +require 'overview/syslog.inc.php'; echo('
    '); -#include("overview/current.inc.php"); +#require 'overview/current.inc.php"); ?> diff --git a/html/pages/device/overview/c6kxbar.inc.php b/html/pages/device/overview/c6kxbar.inc.php index 14f5d54e48..eb04e0a7db 100644 --- a/html/pages/device/overview/c6kxbar.inc.php +++ b/html/pages/device/overview/c6kxbar.inc.php @@ -1,102 +1,99 @@ -
    -
    -
    -
    '); -echo(''); -echo(" Catalyst 6k Crossbar"); -echo('
    - '); +echo '
    +
    +
    +
    +
    '; +echo ''; +echo " Catalyst 6k Crossbar"; +echo '
    +
    '; -foreach ($entity_state['group']['c6kxbar'] as $index => $entry) -{ - // FIXME i'm not sure if this is the correct way to decide what entphysical index it is. slotnum+1? :> - $entity = dbFetchRow("SELECT * FROM entPhysical WHERE device_id = ? AND entPhysicalIndex = ?", array($device['device_id'], $index+1)); +foreach ($entity_state['group']['c6kxbar'] as $index => $entry) { + // FIXME i'm not sure if this is the correct way to decide what entphysical index it is. slotnum+1? :> + $entity = dbFetchRow('SELECT * FROM entPhysical WHERE device_id = ? AND entPhysicalIndex = ?', array($device['device_id'], $index + 1)); - echo(" + echo " - - "); + echo ' + '; - foreach ($entity_state['group']['c6kxbar'][$index] as $subindex => $fabric) - { - if (is_numeric($subindex)) - { - if ($fabric['cc6kxbarModuleChannelFabStatus'] == "ok") - { - $fabric['mode_class'] = "green"; - } else { - $fabric['mode_class'] = "red"; - } + foreach ($entity_state['group']['c6kxbar'][$index] as $subindex => $fabric) { + if (is_numeric($subindex)) { + if ($fabric['cc6kxbarModuleChannelFabStatus'] == 'ok') { + $fabric['mode_class'] = 'green'; + } + else { + $fabric['mode_class'] = 'red'; + } - $percent_in = $fabric['cc6kxbarStatisticsInUtil']; - $background_in = get_percentage_colours($percent_in); + $percent_in = $fabric['cc6kxbarStatisticsInUtil']; + $background_in = get_percentage_colours($percent_in); - $percent_out = $fabric['cc6kxbarStatisticsOutUtil']; - $background_out = get_percentage_colours($percent_out); + $percent_out = $fabric['cc6kxbarStatisticsOutUtil']; + $background_out = get_percentage_colours($percent_out); - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device['device_id']; - $graph_array['mod'] = $index; - $graph_array['chan'] = $subindex; - $graph_array['type'] = "c6kxbar_util"; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device['device_id']; + $graph_array['mod'] = $index; + $graph_array['chan'] = $subindex; + $graph_array['type'] = 'c6kxbar_util'; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $text_descr = $entity['entPhysicalName'] . " - Fabric " . $subindex; + $text_descr = $entity['entPhysicalName'].' - Fabric '.$subindex; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - $minigraph = generate_graph_tag($graph_array); + echo (' + + + - - - - - - - "); - } - } -} - -echo("
    ".$entity['entPhysicalName'].""); + "; - switch ($entry['']['cc6kxbarModuleModeSwitchingMode']) - { - case "busmode": - # echo 'Bus'; + switch ($entry['']['cc6kxbarModuleModeSwitchingMode']) { + case 'busmode': + // echo 'Bus'; break; - case "crossbarmode": + + case 'crossbarmode': echo 'Crossbar'; break; - case "dcefmode": + + case 'dcefmode': echo 'DCEF'; break; - default: + + default: echo $entry['']['cc6kxbarModuleModeSwitchingMode']; } - echo("
    Fabric '.$subindex." - Fabric ".$subindex."". - - $fabric['cc6kxbarModuleChannelFabStatus']."".formatRates($fabric['cc6kxbarModuleChannelSpeed']*1000000)."".overlib_link($link, $minigraph, $overlib_content)."".print_percentage_bar (125, 20, $percent_in, "Ingress", "ffffff", $background['left'], $percent_in . "%", "ffffff", $background['right'])."".print_percentage_bar (125, 20, $percent_out, "Egress", "ffffff", $background['left'], $percent_out . "%", "ffffff", $background['right'])."
    "); -echo("
    "); -echo("
    "); -echo("
    "); -echo("
    "); - -?> +echo ' '; +echo '
    '; +echo ' '; +echo ' '; +echo ''; diff --git a/html/pages/device/overview/eventlog.inc.php b/html/pages/device/overview/eventlog.inc.php index ff235aa4a8..d555118136 100644 --- a/html/pages/device/overview/eventlog.inc.php +++ b/html/pages/device/overview/eventlog.inc.php @@ -1,25 +1,22 @@ '); - echo('
    +echo '
    '; +echo '
    -
    '); -echo(''); -echo(" Recent Events"); -echo('
    - '); +
    '; +echo ''; +echo " Recent Events"; +echo '
    +
    '; $eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` WHERE `host` = ? ORDER BY `datetime` DESC LIMIT 0,10", array($device['device_id'])); -foreach ($eventlog as $entry) -{ - include("includes/print-event-short.inc.php"); +foreach ($eventlog as $entry) { + include 'includes/print-event-short.inc.php'; } -echo("
    "); -echo('
    '); -echo('
    '); -echo('
    '); -echo('
    '); - -?> +echo ''; +echo '
    '; +echo ''; +echo ''; +echo ''; diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index 6194c37c00..36bc05cd5d 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -1,75 +1,71 @@ +if (count($sensors)) { + echo '
    -
    -
    -
    '); - echo(' ' . $sensor_type . ''); - echo('
    - '); - foreach ($sensors as $sensor) - { - if ($config['memcached']['enable'] === TRUE) - { - $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); - } +
    +
    +
    '; + echo ' '.$sensor_type.''; + echo '
    +
    '; + foreach ($sensors as $sensor) { + if ($config['memcached']['enable'] === true) { + $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); + } - if (empty($sensor['sensor_current'])) - { - $sensor['sensor_current'] = "NaN"; - } + if (empty($sensor['sensor_current'])) { + $sensor['sensor_current'] = 'NaN'; + } - // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. - // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? - // FIXME - DUPLICATED IN health/sensors + // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. + // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? + // FIXME - DUPLICATED IN health/sensors + $graph_colour = str_replace('#', '', $row_colour); - $graph_colour = str_replace("#", "", $row_colour); + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $sensor['sensor_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $sensor['sensor_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $overlib_content = '

    '.$device['hostname'].' - '.$sensor['sensor_descr'].'

    '; + foreach (array('day', 'week', 'month', 'year') as $period) { + $graph_array['from'] = $config['time'][$period]; + $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); + } - $overlib_content = '

    '.$device['hostname']." - ".$sensor['sensor_descr']."

    "; - foreach (array('day','week','month','year') as $period) - { - $graph_array['from'] = $config['time'][$period]; - $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); - } - $overlib_content .= "
    "; + $overlib_content .= '
    '; - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. - $graph_array['from'] = $config['time']['day']; - $sensor_minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $graph_array['from'] = $config['time']['day']; + $sensor_minigraph = generate_graph_tag($graph_array); - $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); + $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); - echo(" - - - - "); - } + echo ' + + + + '; + }//end foreach - echo("
    ".overlib_link($link, $sensor['sensor_descr'], $overlib_content)."".overlib_link($link, $sensor_minigraph, $overlib_content)."".overlib_link($link, " $sensor['sensor_limit'] ? "style='color: red'" : '') . '>' . $sensor['sensor_current'] . $sensor_unit . "", $overlib_content)."
    '.overlib_link($link, $sensor['sensor_descr'], $overlib_content).''.overlib_link($link, $sensor_minigraph, $overlib_content).''.overlib_link($link, ' $sensor['sensor_limit'] ? "style='color: red'" : '').'>'.$sensor['sensor_current'].$sensor_unit.'', $overlib_content).'
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); -} - -?> + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +}//end if diff --git a/html/pages/device/overview/mempools.inc.php b/html/pages/device/overview/mempools.inc.php index 3d35a8d554..0699872416 100644 --- a/html/pages/device/overview/mempools.inc.php +++ b/html/pages/device/overview/mempools.inc.php @@ -1,76 +1,77 @@ +if (count($mempools)) { + echo '
    -
    -
    -
    -'); - echo(''); - echo(" Memory Pools"); - echo(' -
    - -'); +
    +
    +
    + '; + echo ''; + echo " Memory Pools"; + echo ' +
    +
    + '; - foreach ($mempools as $mempool) - { + foreach ($mempools as $mempool) { + if ($config['memcached']['enable'] === true) { + $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); + if ($debug) { + print_r($state); + } - if ($config['memcached']['enable'] === TRUE) - { - $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $mempool = array_merge($mempool, $state); } - unset($state); - } + if (is_array($state)) { + $mempool = array_merge($mempool, $state); + } - $percent= round($mempool['mempool_perc'],0); - $text_descr = rewrite_entity_descr($mempool['mempool_descr']); - $total = formatStorage($mempool['mempool_total']); - $used = formatStorage($mempool['mempool_used']); - $free = formatStorage($mempool['mempool_free']); - $background = get_percentage_colours($percent); + unset($state); + } - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $percent = round($mempool['mempool_perc'], 0); + $text_descr = rewrite_entity_descr($mempool['mempool_descr']); + $total = formatStorage($mempool['mempool_total']); + $used = formatStorage($mempool['mempool_used']); + $free = formatStorage($mempool['mempool_free']); + $background = get_percentage_colours($percent); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); - $minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - echo(" - - - - "); - } + echo ' + + + + '; + }//end foreach - echo('
    ".overlib_link($link, $text_descr, $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." -
    '.overlib_link($link, $text_descr, $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).' +
    + echo '
    -
    '); - -} - -?> + '; +}//end if diff --git a/html/pages/device/overview/ports.inc.php b/html/pages/device/overview/ports.inc.php index 807f8ee4fb..75cf3ca29f 100644 --- a/html/pages/device/overview/ports.inc.php +++ b/html/pages/device/overview/ports.inc.php @@ -1,68 +1,64 @@ '); - echo('
    +if ($ports['total']) { + echo '
    '; + echo '
    Overall Traffic
    - '); +
    '; - $graph_array['height'] = "100"; - $graph_array['width'] = "485"; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device['device_id']; - $graph_array['type'] = "device_bits"; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; - $graph = generate_graph_tag($graph_array); + $graph_array['height'] = '100'; + $graph_array['width'] = '485'; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device['device_id']; + $graph_array['type'] = 'device_bits'; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; + $graph = generate_graph_tag($graph_array); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width']); + $link = generate_url($link_array); - $graph_array['width'] = "210"; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - Device Traffic"); + $graph_array['width'] = '210'; + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - Device Traffic'); - echo(' - - '); + echo ' + + '; - echo(' + echo ' - - - - - '); + + + + + '; - echo(' - + "); - echo(""); - echo("
    '); - echo(overlib_link($link, $graph, $overlib_content, NULL)); - echo('
    '; + echo overlib_link($link, $graph, $overlib_content, null); + echo '
    ' . $ports['total'] . ' ' . $ports['up'] . ' ' . $ports['down'] . ' ' . $ports['disabled'] . '
    '.$ports['total'].' '.$ports['up'].' '.$ports['down'].' '.$ports['disabled'].'
    '); + echo '
    '; - $ifsep = ""; + $ifsep = ''; - foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) - { - $data = ifNameDescr($data); - $data = array_merge($data, $device); - echo("$ifsep" . generate_port_link($data, makeshortif(strtolower($data['label'])))); - $ifsep = ", "; - } + foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) { + $data = ifNameDescr($data); + $data = array_merge($data, $device); + echo "$ifsep".generate_port_link($data, makeshortif(strtolower($data['label']))); + $ifsep = ', '; + } - unset($ifsep); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); -} - -?> + unset($ifsep); + echo ' '; + echo ''; + echo ''; + echo '
    '; + echo ''; + echo ''; + echo ''; +}//end if diff --git a/html/pages/device/overview/processors.inc.php b/html/pages/device/overview/processors.inc.php index 3394e263ca..8b4d3f2912 100644 --- a/html/pages/device/overview/processors.inc.php +++ b/html/pages/device/overview/processors.inc.php @@ -1,66 +1,63 @@ +if (count($processors)) { + echo '
    -'); - echo(''); - echo(" Processors"); - echo('
    - '); +'; + echo ''; + echo " Processors"; + echo ' +
    '; - foreach ($processors as $proc) - { - $text_descr = rewrite_entity_descr($proc['processor_descr']); + foreach ($processors as $proc) { + $text_descr = rewrite_entity_descr($proc['processor_descr']); - # disable short hrDeviceDescr. need to make this prettier. - #$text_descr = short_hrDeviceDescr($proc['processor_descr']); - $percent = $proc['processor_usage']; - $background = get_percentage_colours($percent); - $graph_colour = str_replace("#", "", $row_colour); + // disable short hrDeviceDescr. need to make this prettier. + // $text_descr = short_hrDeviceDescr($proc['processor_descr']); + $percent = $proc['processor_usage']; + $background = get_percentage_colours($percent); + $graph_colour = str_replace('#', '', $row_colour); - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $proc['processor_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $proc['processor_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - $minigraph = generate_graph_tag($graph_array); - - echo(" - - - + + + - "); - } + '; + }//end foreach - echo('
    ".overlib_link($link, $text_descr, $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." + echo '
    '.overlib_link($link, $text_descr, $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).'
    + echo '
    -
    '); - -} - -?> + '; +}//end if diff --git a/html/pages/device/overview/sensors/charge.inc.php b/html/pages/device/overview/sensors/charge.inc.php index bf40977499..b0df00968a 100644 --- a/html/pages/device/overview/sensors/charge.inc.php +++ b/html/pages/device/overview/sensors/charge.inc.php @@ -1,10 +1,8 @@ +require 'pages/device/overview/generic/sensor.inc.php'; diff --git a/html/pages/device/overview/sensors/load.inc.php b/html/pages/device/overview/sensors/load.inc.php index 989a305b9b..089f93dffb 100644 --- a/html/pages/device/overview/sensors/load.inc.php +++ b/html/pages/device/overview/sensors/load.inc.php @@ -1,8 +1,8 @@ '); - echo('
    +if ($services['total']) { +echo '
    '; + echo '
    -
    '); - echo(" Services"); - echo('
    - '); +
    '; + echo " Services"; + echo '
    +
    '; - echo(" + echo " @@ -19,22 +18,32 @@ echo('
    ');
    -
    $services[total] $services[up] $services[disabled]
    "); +"; - foreach (dbFetchRows("SELECT * FROM services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $data) - { - if ($data['service_status'] == "0" && $data['service_ignore'] == "1") { $status = "grey"; } - if ($data['service_status'] == "1" && $data['service_ignore'] == "1") { $status = "green"; } - if ($data['service_status'] == "0" && $data['service_ignore'] == "0") { $status = "red"; } - if ($data['service_status'] == "1" && $data['service_ignore'] == "0") { $status = "blue"; } - echo("$break" . strtolower($data['service_type']) . ""); - $break = ", "; - } - echo('
    '); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); -} + foreach (dbFetchRows('SELECT * FROM services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $data) { + if ($data['service_status'] == '0' && $data['service_ignore'] == '1') { + $status = 'grey'; + } -?> + if ($data['service_status'] == '1' && $data['service_ignore'] == '1') { + $status = 'green'; + } + + if ($data['service_status'] == '0' && $data['service_ignore'] == '0') { + $status = 'red'; + } + + if ($data['service_status'] == '1' && $data['service_ignore'] == '0') { + $status = 'blue'; + } + + echo "$break".strtolower($data['service_type']).''; + $break = ', '; + } + + echo ''; + echo '
    '; + echo ''; + echo ''; + echo ''; +}//end if diff --git a/html/pages/device/overview/storage.inc.php b/html/pages/device/overview/storage.inc.php index 01c02edb4e..e81b1b5b5d 100644 --- a/html/pages/device/overview/storage.inc.php +++ b/html/pages/device/overview/storage.inc.php @@ -1,91 +1,86 @@ +if (count($drives)) { + echo '
    -
    '); - echo(''); - echo(" Storage"); - echo('
    - '); +
    '; + echo ''; + echo " Storage"; + echo '
    +
    '; - foreach ($drives as $drive) - { - $skipdrive = 0; + foreach ($drives as $drive) { + $skipdrive = 0; - if ($device["os"] == "junos") - { - foreach ($config['ignore_junos_os_drives'] as $jdrive) - { - if (preg_match($jdrive, $drive["storage_descr"])) - { - $skipdrive = 1; + if ($device['os'] == 'junos') { + foreach ($config['ignore_junos_os_drives'] as $jdrive) { + if (preg_match($jdrive, $drive['storage_descr'])) { + $skipdrive = 1; + } + } + + $drive['storage_descr'] = preg_replace('/.*mounted on: (.*)/', '\\1', $drive['storage_descr']); } - } - $drive["storage_descr"] = preg_replace("/.*mounted on: (.*)/", "\\1", $drive["storage_descr"]); - } - if ($device['os'] == "freebsd") - { - foreach ($config['ignore_bsd_os_drives'] as $jdrive) - { - if (preg_match($jdrive, $drive["storage_descr"])) - { - $skipdrive = 1; + if ($device['os'] == 'freebsd') { + foreach ($config['ignore_bsd_os_drives'] as $jdrive) { + if (preg_match($jdrive, $drive['storage_descr'])) { + $skipdrive = 1; + } + } } - } - } - if ($skipdrive) { continue; } - $percent = round($drive['storage_perc'], 0); - $total = formatStorage($drive['storage_size']); - $free = formatStorage($drive['storage_free']); - $used = formatStorage($drive['storage_used']); - $background = get_percentage_colours($percent); + if ($skipdrive) { + continue; + } - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $percent = round($drive['storage_perc'], 0); + $total = formatStorage($drive['storage_size']); + $free = formatStorage($drive['storage_free']); + $used = formatStorage($drive['storage_used']); + $background = get_percentage_colours($percent); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $drive['storage_descr']); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$drive['storage_descr']); - $minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - echo(" - - - + + + - "); - } + '; + }//end foreach - echo('
    ".overlib_link($link, $drive['storage_descr'], $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." + echo '
    '.overlib_link($link, $drive['storage_descr'], $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).'
    + echo '
    -
    '); + '; +}//end if -} - -unset ($drive_rows); - -?> +unset($drive_rows); diff --git a/html/pages/device/overview/syslog.inc.php b/html/pages/device/overview/syslog.inc.php index 1d26fbb2a7..bcfb6d2c52 100644 --- a/html/pages/device/overview/syslog.inc.php +++ b/html/pages/device/overview/syslog.inc.php @@ -1,25 +1,24 @@ '); - echo('
    +if ($config['enable_syslog']) { + $syslog = dbFetchRows("SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? ORDER BY timestamp DESC LIMIT 20", array($device['device_id'])); + if (count($syslog)) { + echo '
    '; + echo '
    -
    '); - echo(' Recent Syslog'); -echo('
    - '); - foreach ($syslog as $entry) { include("includes/print-syslog.inc.php"); } - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - } -} +
    '; + echo ' Recent Syslog'; + echo '
    + '; + foreach ($syslog as $entry) { + include 'includes/print-syslog.inc.php'; + } -?> + echo '
    '; + echo '
    '; + echo ''; + echo ''; + echo ''; + } +} diff --git a/html/pages/device/overview/toner.inc.php b/html/pages/device/overview/toner.inc.php index 347a636195..7c789573c5 100644 --- a/html/pages/device/overview/toner.inc.php +++ b/html/pages/device/overview/toner.inc.php @@ -1,64 +1,62 @@ +if (count($toners)) { + echo '
    -
    '); - echo(''); - echo(" Toner"); - echo('
    - '); +
    '; + echo ''; + echo " Toner"; + echo '
    +
    '; - foreach ($toners as $toner) - { - $percent = round($toner['toner_current'], 0); - $total = formatStorage($toner['toner_size']); - $free = formatStorage($toner['toner_free']); - $used = formatStorage($toner['toner_used']); + foreach ($toners as $toner) { + $percent = round($toner['toner_current'], 0); + $total = formatStorage($toner['toner_size']); + $free = formatStorage($toner['toner_free']); + $used = formatStorage($toner['toner_used']); - $background = toner2colour($toner['toner_descr'], $percent); + $background = toner2colour($toner['toner_descr'], $percent); - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $toner['toner_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $toner['toner_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $toner['toner_descr']); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$toner['toner_descr']); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - $minigraph = generate_graph_tag($graph_array); - - echo(" - - - + + + - "); - } + '; + }//end foreach - echo("
    ".overlib_link($link, $toner['toner_descr'], $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." + echo '
    '.overlib_link($link, $toner['toner_descr'], $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).'
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo(""); -} + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +}//end if -unset ($toner_rows); - -?> +unset($toner_rows); diff --git a/html/pages/device/performance.inc.php b/html/pages/device/performance.inc.php index 8686bf8034..da2056c54b 100644 --- a/html/pages/device/performance.inc.php +++ b/html/pages/device/performance.inc.php @@ -21,7 +21,9 @@ */ -if(!isset($vars['section'])) { $vars['section'] = "performance"; } +if(!isset($vars['section'])) { + $vars['section'] = "performance"; +} if (empty($vars['dtpickerfrom'])) { $vars['dtpickerfrom'] = date($config['dateformat']['byminute'], time() - 3600 * 24 * 2); @@ -57,7 +59,8 @@ if (empty($vars['dtpickerto'])) { if (is_admin() === true || is_read() === true) { $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf` WHERE `device_id` = ? AND `timestamp` >= ? AND `timestamp` <= ?"; $param = array($device['device_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); -} else { +} +else { $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf`,`devices_perms` WHERE `device_id` = ? AND alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = ? AND `timestamp` >= ? AND `timestamp` <= ?"; $param = array($device['device_id'], $_SESSION['user_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); } @@ -81,7 +84,7 @@ foreach(dbFetchRows($query, $param) as $return_value) { $avg = $return_value['avg']; if ($max > $max_val) { - $max_val = $max; + $max_val = $max; } $data[] = array('x' => $date,'y' => $loss,'group' => 0); @@ -186,4 +189,3 @@ echo $milisec_diff; var graph2d = new vis.Graph2d(container, items, groups, options); - diff --git a/html/pages/device/port.inc.php b/html/pages/device/port.inc.php index ecb25cfd28..a70d40a763 100644 --- a/html/pages/device/port.inc.php +++ b/html/pages/device/port.inc.php @@ -1,15 +1,22 @@ get('port-'.$port['port_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $port = array_merge($port, $state); } - unset($state); +if ($config['memcached']['enable'] === true) { + $state = $memcache->get('port-'.$port['port_id'].'-state'); + if ($debug) { + print_r($state); + } + + if (is_array($state)) { + $port = array_merge($port, $state); + } + + unset($state); } $port_details = 1; @@ -17,148 +24,218 @@ $port_details = 1; $hostname = $device['hostname']; $hostid = $device['port_id']; $ifname = $port['ifDescr']; -$ifIndex = $port['ifIndex']; -$speed = humanspeed($port['ifSpeed']); +$ifIndex = $port['ifIndex']; +$speed = humanspeed($port['ifSpeed']); $ifalias = $port['name']; -if ($port['ifPhysAddress']) { $mac = "$port[ifPhysAddress]"; } +if ($port['ifPhysAddress']) { + $mac = "$port[ifPhysAddress]"; +} -$color = "black"; -if ($port['ifAdminStatus'] == "down") { $status = "Disabled"; } -if ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "down") { $status = "Enabled / Disconnected"; } -if ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "up") { $status = "Enabled / Connected"; } +$color = 'black'; +if ($port['ifAdminStatus'] == 'down') { + $status = "Disabled"; +} -$i = 1; +if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'down') { + $status = "Enabled / Disconnected"; +} + +if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') { + $status = "Enabled / Connected"; +} + +$i = 1; $inf = fixifName($ifname); -$bg="#ffffff"; +$bg = '#ffffff'; $show_all = 1; -echo("
    "); +echo "
    "; -include("includes/print-interface.inc.php"); +require 'includes/print-interface.inc.php'; -echo("
    "); +echo ''; -$pos = strpos(strtolower($ifname), "vlan"); -if ($pos !== false ) -{ - $broke = yes; +$pos = strpos(strtolower($ifname), 'vlan'); +if ($pos !== false) { + $broke = yes; } -$pos = strpos(strtolower($ifname), "loopback"); +$pos = strpos(strtolower($ifname), 'loopback'); -if ($pos !== false ) -{ - $broke = yes; +if ($pos !== false) { + $broke = yes; } -echo("
    "); +echo "
    "; print_optionbar_start(); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'port', - 'port' => $port['port_id']); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'port', + 'port' => $port['port_id'], +); $menu_options['graphs'] = 'Graphs'; -$menu_options['realtime'] = 'Real time'; // FIXME CONDITIONAL -$menu_options['arp'] = 'ARP Table'; -$menu_options['events'] = 'Eventlog'; +$menu_options['realtime'] = 'Real time'; +// FIXME CONDITIONAL +$menu_options['arp'] = 'ARP Table'; +$menu_options['events'] = 'Eventlog'; -if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '".$port['port_id']."'") ) -{ $menu_options['adsl'] = 'ADSL'; } - -if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '".$port['ifIndex']."' and `device_id` = '".$device['device_id']."'") ) -{ $menu_options['pagp'] = 'PAgP'; } - -if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'") ) -{ $menu_options['vlans'] = 'VLANs'; } - -$sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['view'] == $option) { echo(""); } - echo(generate_link($text,$link_array,array('view'=>$option))); - if ($vars['view'] == $option) { echo(""); } - $sep = " | "; +if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '".$port['port_id']."'")) { + $menu_options['adsl'] = 'ADSL'; } + +if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '".$port['ifIndex']."' and `device_id` = '".$device['device_id']."'")) { + $menu_options['pagp'] = 'PAgP'; +} + +if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'")) { + $menu_options['vlans'] = 'VLANs'; +} + +$sep = ''; +foreach ($menu_options as $option => $text) { + echo $sep; + if ($vars['view'] == $option) { + echo ""; + } + + echo generate_link($text, $link_array, array('view' => $option)); + if ($vars['view'] == $option) { + echo ''; + } + + $sep = ' | '; +} + unset($sep); -if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '".$port['port_id']."'") > "0" ) -{ +if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '".$port['port_id']."'") > '0') { + echo generate_link($descr, $link_array, array('view' => 'macaccounting', 'graph' => $type)); - echo(generate_link($descr,$link_array,array('view'=>'macaccounting','graph'=>$type))); + echo ' | Mac Accounting : '; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') { + echo ""; + } - echo(" | Mac Accounting : "); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "graphs") { echo(""); } - echo(generate_link("Bits",$link_array,array('view' => 'macaccounting', 'subview' => 'graphs', 'graph'=>'bits'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "graphs") { echo(""); } + echo generate_link('Bits', $link_array, array('view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'bits')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') { + echo ''; + } - echo("("); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "minigraphs") { echo(""); } - echo(generate_link("Mini",$link_array,array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph'=>'bits'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "minigraphs") { echo(""); } - echo('|'); + echo '('; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') { + echo ""; + } - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "top10") { echo(""); } - echo(generate_link("Top10",$link_array,array('view' => 'macaccounting', 'subview' => 'top10', 'graph'=>'bits'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "top10") { echo(""); } - echo(") | "); + echo generate_link('Mini', $link_array, array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'bits')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') { + echo ''; + } - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "graphs") { echo(""); } - echo(generate_link("Packets",$link_array,array('view' => 'macaccounting', 'subview' => 'graphs', 'graph'=>'pkts'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "graphs") { echo(""); } - echo("("); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "minigraphs") { echo(""); } - echo(generate_link("Mini",$link_array,array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph'=>'pkts'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "minigraphs") { echo(""); } - echo('|'); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "top10") { echo(""); } - echo(generate_link("Top10",$link_array,array('view' => 'macaccounting', 'subview' => 'top10', 'graph'=>'pkts'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "top10") { echo(""); } - echo(")"); -} + echo '|'; -if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '".$port['port_id']."'") > "0" ) -{ + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') { + echo ""; + } - // FIXME ATM VPs - // FIXME URLs BROKEN + echo generate_link('Top10', $link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'bits')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') { + echo ''; + } - echo(" | ATM VPs : "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo("Bits"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo(" | "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "packets") { echo(""); } - echo("Packets"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo(" | "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "cells") { echo(""); } - echo("Cells"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo(" | "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "errors") { echo(""); } - echo("Errors"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } -} + echo ') | '; -if ($_SESSION['userlevel'] >= '10') -{ - echo(" Create Bill"); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') { + echo ""; + } + + echo generate_link('Packets', $link_array, array('view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'pkts')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') { + echo ''; + } + + echo '('; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') { + echo ""; + } + + echo generate_link('Mini', $link_array, array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'pkts')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') { + echo ''; + } + + echo '|'; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') { + echo ""; + } + + echo generate_link('Top10', $link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'pkts')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') { + echo ''; + } + + echo ')'; +}//end if + +if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '".$port['port_id']."'") > '0') { + // FIXME ATM VPs + // FIXME URLs BROKEN + echo ' | ATM VPs : '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ""; + } + + echo "Bits"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } + + echo ' | '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'packets') { + echo ""; + } + + echo "Packets"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } + + echo ' | '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'cells') { + echo ""; + } + + echo "Cells"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } + + echo ' | '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'errors') { + echo ""; + } + + echo "Errors"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } +}//end if + +if ($_SESSION['userlevel'] >= '10') { + echo " Create Bill"; } print_optionbar_end(); -echo("
    "); +echo "
    "; -include("pages/device/port/".mres($vars['view']).".inc.php"); +require 'pages/device/port/'.mres($vars['view']).'.inc.php'; -echo("
    "); - -?> +echo '
    '; diff --git a/html/pages/device/port/events.inc.php b/html/pages/device/port/events.inc.php index 6de49ef262..5a113fafe6 100644 --- a/html/pages/device/port/events.inc.php +++ b/html/pages/device/port/events.inc.php @@ -1,15 +1,12 @@ '); +echo ''; -foreach ($entries as $entry) -{ - include("includes/print-event.inc.php"); +foreach ($entries as $entry) { + include 'includes/print-event.inc.php'; } -echo('
    '); +echo ''; -$pagetitle[] = "Events"; - -?> +$pagetitle[] = 'Events'; diff --git a/html/pages/device/port/pagp.inc.php b/html/pages/device/port/pagp.inc.php index e64437e2c2..7a8e41ff50 100644 --- a/html/pages/device/port/pagp.inc.php +++ b/html/pages/device/port/pagp.inc.php @@ -3,34 +3,32 @@ global $config; // FIXME functions! - -if (!$graph_type) { $graph_type = "pagp_bits"; } - -$daily_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['day']."&to=".$config['time']['now']."&width=215&height=100"; -$daily_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; - -$weekly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['week']."&to=".$config['time']['now']."&width=215&height=100"; -$weekly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['week']."&to=".$config['time']['now']."&width=500&height=150"; - -$monthly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['month']."&to=".$config['time']['now']."&width=215&height=100"; -$monthly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['month']."&to=".$config['time']['now']."&width=500&height=150"; - -$yearly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['year']."&to=".$config['time']['now']."&width=215&height=100"; -$yearly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['year']."&to=".$config['time']['now']."&width=500&height=150"; - -echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "); -echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "); -echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "); -echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "); - -foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member) -{ - echo("$br " . generate_port_link($member) . " (PAgP)"); - $br = "
    "; +if (!$graph_type) { + $graph_type = 'pagp_bits'; } -?> +$daily_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['day'].'&to='.$config['time']['now'].'&width=215&height=100'; +$daily_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; + +$weekly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['week'].'&to='.$config['time']['now'].'&width=215&height=100'; +$weekly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['week'].'&to='.$config['time']['now'].'&width=500&height=150'; + +$monthly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['month'].'&to='.$config['time']['now'].'&width=215&height=100'; +$monthly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['month'].'&to='.$config['time']['now'].'&width=500&height=150'; + +$yearly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['year'].'&to='.$config['time']['now'].'&width=215&height=100'; +$yearly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['year'].'&to='.$config['time']['now'].'&width=500&height=150'; + +echo "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "; +echo "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "; +echo "', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "; +echo "', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "; + +foreach (dbFetchRows('SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $member) { + echo "$br ".generate_port_link($member).' (PAgP)'; + $br = '
    '; +} diff --git a/html/pages/device/ports.inc.php b/html/pages/device/ports.inc.php index b254b376da..dc941e246f 100644 --- a/html/pages/device/ports.inc.php +++ b/html/pages/device/ports.inc.php @@ -1,15 +1,23 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'ports'); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'ports', +); print_optionbar_start(); @@ -17,110 +25,136 @@ $menu_options['basic'] = 'Basic'; $menu_options['details'] = 'Details'; $menu_options['arp'] = 'ARP Table'; -if(dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.port_id = L.local_port_id")) -{ - $menu_options['neighbours'] = 'Neighbours'; -} -if(dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) -{ - $menu_options['adsl'] = 'ADSL'; +if (dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.port_id = L.local_port_id")) { + $menu_options['neighbours'] = 'Neighbours'; } -$sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['view'] == $option) { echo(""); } - echo(generate_link($text,$link_array,array('view'=>$option))); - if ($vars['view'] == $option) { echo(""); } - $sep = " | "; +if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) { + $menu_options['adsl'] = 'ADSL'; +} + +$sep = ''; +foreach ($menu_options as $option => $text) { + echo $sep; + if ($vars['view'] == $option) { + echo ""; + } + + echo generate_link($text, $link_array, array('view' => $option)); + if ($vars['view'] == $option) { + echo ''; + } + + $sep = ' | '; } unset($sep); -echo(' | Graphs: '); +echo ' | Graphs: '; -$graph_types = array("bits" => "Bits", - "upkts" => "Unicast Packets", - "nupkts" => "Non-Unicast Packets", - "errors" => "Errors", - "etherlike" => "Etherlike"); +$graph_types = array( + 'bits' => 'Bits', + 'upkts' => 'Unicast Packets', + 'nupkts' => 'Non-Unicast Packets', + 'errors' => 'Errors', + 'etherlike' => 'Etherlike', +); -foreach ($graph_types as $type => $descr) -{ - echo("$type_sep"); - if ($vars['graph'] == $type && $vars['view'] == "graphs") { echo(""); } - echo(generate_link($descr,$link_array,array('view'=>'graphs','graph'=>$type))); - if ($vars['graph'] == $type && $vars['view'] == "graphs") { echo(""); } +foreach ($graph_types as $type => $descr) { + echo "$type_sep"; + if ($vars['graph'] == $type && $vars['view'] == 'graphs') { + echo ""; + } - echo(' ('); - if ($vars['graph'] == $type && $vars['view'] == "minigraphs") { echo(""); } - echo(generate_link('Mini',$link_array,array('view'=>'minigraphs','graph'=>$type))); - if ($vars['graph'] == $type && $vars['view'] == "minigraphs") { echo(""); } - echo(')'); - $type_sep = " | "; -} + echo generate_link($descr, $link_array, array('view' => 'graphs', 'graph' => $type)); + if ($vars['graph'] == $type && $vars['view'] == 'graphs') { + echo ''; + } + + echo ' ('; + if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { + echo ""; + } + + echo generate_link('Mini', $link_array, array('view' => 'minigraphs', 'graph' => $type)); + if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { + echo ''; + } + + echo ')'; + $type_sep = ' | '; +}//end foreach print_optionbar_end(); -if ($vars['view'] == 'minigraphs') -{ - $timeperiods = array('-1day','-1week','-1month','-1year'); - $from = '-1day'; - echo("
    "); - unset ($seperator); +if ($vars['view'] == 'minigraphs') { + $timeperiods = array( + '-1day', + '-1week', + '-1month', + '-1year', + ); + $from = '-1day'; + echo "
    "; + unset($seperator); - // FIXME - FIX THIS. UGLY. - foreach (dbFetchRows("select * from ports WHERE device_id = ? ORDER BY ifIndex", array($device['device_id'])) as $port) - { - echo("
    -
    ".makeshortif($port['ifDescr'])."
    - ".$device['hostname']." - ".$port['ifDescr']."
    \ - ".$port['ifAlias']." \ - \ - ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >". - " - -
    ".truncate(short_port_descr($port['ifAlias']), 32, '')."
    -
    "); - } - echo("
    "); -} elseif ($vars['view'] == "arp" || $vars['view'] == "adsl" || $vars['view'] == "neighbours") { - include("ports/".$vars['view'].".inc.php"); -} else { - if ($vars['view'] == "details") { $port_details = 1; } - echo("
    "); - $i = "1"; - - global $port_cache, $port_index_cache; - - $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device['device_id'])); - // As we've dragged the whole database, lets pre-populate our caches :) - // FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries. - foreach ($ports as $port) - { - $port_cache[$port['port_id']] = $port; - $port_index_cache[$port['device_id']][$port['ifIndex']] = $port; - } - - foreach ($ports as $port) - { - if ($config['memcached']['enable'] === TRUE) - { - $state = $memcache->get('port-'.$port['port_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $port = array_merge($port, $state); } - unset($state); + // FIXME - FIX THIS. UGLY. + foreach (dbFetchRows('select * from ports WHERE device_id = ? ORDER BY ifIndex', array($device['device_id'])) as $port) { + echo "
    +
    ".makeshortif($port['ifDescr']).'
    + ".$device['hostname'].' - '.$port['ifDescr'].'
    \ + '.$port['ifAlias']." \ + \ + ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >"." + +
    ".truncate(short_port_descr($port['ifAlias']), 32, '').'
    + '; } - include("includes/print-interface.inc.php"); - - $i++; - } - echo("
    "); + echo '
    '; } +else if ($vars['view'] == 'arp' || $vars['view'] == 'adsl' || $vars['view'] == 'neighbours') { + include 'ports/'.$vars['view'].'.inc.php'; +} +else { + if ($vars['view'] == 'details') { + $port_details = 1; + } -$pagetitle[] = "Ports"; + echo "
    "; + $i = '1'; -?> + global $port_cache, $port_index_cache; + + $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device['device_id'])); + // As we've dragged the whole database, lets pre-populate our caches :) + // FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries. + foreach ($ports as $port) { + $port_cache[$port['port_id']] = $port; + $port_index_cache[$port['device_id']][$port['ifIndex']] = $port; + } + + foreach ($ports as $port) { + if ($config['memcached']['enable'] === true) { + $state = $memcache->get('port-'.$port['port_id'].'-state'); + if ($debug) { + print_r($state); + } + + if (is_array($state)) { + $port = array_merge($port, $state); + } + + unset($state); + } + + include 'includes/print-interface.inc.php'; + + $i++; + } + + echo '
    '; +}//end if + +$pagetitle[] = 'Ports'; diff --git a/html/pages/device/ports/neighbours.inc.php b/html/pages/device/ports/neighbours.inc.php index 5e417eb996..b56136881e 100644 --- a/html/pages/device/ports/neighbours.inc.php +++ b/html/pages/device/ports/neighbours.inc.php @@ -10,8 +10,7 @@ echo 'Local Port Protocol '; -foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id', array($device['device_id'])) as $neighbour) -{ +foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id', array($device['device_id'])) as $neighbour) { if ($bg_colour == $list_colour_b) { $bg_colour = $list_colour_a; } diff --git a/html/pages/device/processes.inc.php b/html/pages/device/processes.inc.php index 41fda92887..0ce8e4c70f 100644 --- a/html/pages/device/processes.inc.php +++ b/html/pages/device/processes.inc.php @@ -1,19 +1,21 @@ +/* + * Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * Process Listing * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -22,77 +24,89 @@ * @subpackage Pages */ -switch( $vars['order'] ) { - case "vsz": - $order = "`vsz`"; - break; - case "rss": - $order = "`rss`"; - break; - case "cputime": - $order = "`cputime`"; - break; - case "user": - $order = "`user`"; - break; - case "command": - $order = "`command`"; - break; - default: - $order = "`pid`"; - break; +switch ($vars['order']) { + case 'vsz': + $order = '`vsz`'; + break; + + case 'rss': + $order = '`rss`'; + break; + + case 'cputime': + $order = '`cputime`'; + break; + + case 'user': + $order = '`user`'; + break; + + case 'command': + $order = '`command`'; + break; + + default: + $order = '`pid`'; + break; +}//end switch + +if ($vars['by'] == 'desc') { + $by = 'desc'; } -if( $vars['by'] == "desc" ) { - $by = "desc"; -} else { - $by = "asc"; +else { + $by = 'asc'; } $heads = array( - 'PID' => '', - 'VSZ' => 'Virtual Memory', - 'RSS' => 'Resident Memory', - 'cputime' => '', - 'user' => '', - 'command' => '' + 'PID' => '', + 'VSZ' => 'Virtual Memory', + 'RSS' => 'Resident Memory', + 'cputime' => '', + 'user' => '', + 'command' => '', ); echo "
    "; -foreach( $heads as $head=>$extra ) { - unset($lhead, $bhead); - $lhead = strtolower($head); - $bhead = 'asc'; - $icon = ""; - if( '`'.$lhead.'`' == $order ) { - $icon = " class='glyphicon glyphicon-chevron-"; - if( $by == 'asc' ) { - $bhead = 'desc'; - $icon .= 'up'; - } else { - $icon .= 'down'; - } - $icon .= "'"; - } - echo ''; -} -echo ""; +foreach ($heads as $head => $extra) { + unset($lhead, $bhead); + $lhead = strtolower($head); + $bhead = 'asc'; + $icon = ''; + if ('`'.$lhead.'`' == $order) { + $icon = " class='glyphicon glyphicon-chevron-"; + if ($by == 'asc') { + $bhead = 'desc'; + $icon .= 'up'; + } + else { + $icon .= 'down'; + } -foreach (dbFetchRows("SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY ".$order." ".$by, array($device['device_id'])) as $entry) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -} -echo"
     '; - if( !empty($extra) ) { - echo "$head"; - } else { - echo $head; - } - echo '
    '.$entry['pid'].''.format_si($entry['vsz']*1024).''.format_si($entry['rss']*1024).''.$entry['cputime'].''.$entry['user'].''.$entry['command'].'
    "; + $icon .= "'"; + } -?> + echo ' '; + if (!empty($extra)) { + echo "$head"; + } + else { + echo $head; + } + + echo ''; +}//end foreach + +echo ''; + +foreach (dbFetchRows('SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY '.$order.' '.$by, array($device['device_id'])) as $entry) { + echo ''; + echo ''.$entry['pid'].''; + echo ''.format_si(($entry['vsz'] * 1024)).''; + echo ''.format_si(($entry['rss'] * 1024)).''; + echo ''.$entry['cputime'].''; + echo ''.$entry['user'].''; + echo ''.$entry['command'].''; + echo ''; +} + +echo '
    '; diff --git a/html/pages/device/pseudowires.inc.php b/html/pages/device/pseudowires.inc.php index c134c8b661..c48bca5738 100644 --- a/html/pages/device/pseudowires.inc.php +++ b/html/pages/device/pseudowires.inc.php @@ -89,8 +89,7 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I WHERE P.port_id 'upkts', 'errors', ); - foreach ($types as $graph_type) - { + foreach ($types as $graph_type) { $pw_a['graph_type'] = 'port_'.$graph_type; print_port_thumbnail($pw_a); } diff --git a/html/pages/device/routing/bgp.inc.php b/html/pages/device/routing/bgp.inc.php index 5b327aca30..17f0629a02 100644 --- a/html/pages/device/routing/bgp.inc.php +++ b/html/pages/device/routing/bgp.inc.php @@ -1,203 +1,275 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'routing', - 'proto' => 'bgp'); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'routing', + 'proto' => 'bgp', +); -if(!isset($vars['view'])) { $vars['view'] = "basic"; } +if (!isset($vars['view'])) { + $vars['view'] = 'basic'; +} print_optionbar_start(); -echo "Local AS : " .$device['bgpLocalAs']." "; +echo 'Local AS : '.$device['bgpLocalAs'].' '; -echo("BGP » "); +echo "BGP » "; -if ($vars['view'] == "basic") { echo(""); } -echo(generate_link("Basic", $link_array,array('view'=>'basic'))); -if ($vars['view'] == "basic") { echo(""); } +if ($vars['view'] == 'basic') { + echo ""; +} -echo(" | "); +echo generate_link('Basic', $link_array, array('view' => 'basic')); +if ($vars['view'] == 'basic') { + echo ''; +} -if ($vars['view'] == "updates") { echo(""); } -echo(generate_link("Updates", $link_array,array('view'=>'updates'))); -if ($vars['view'] == "updates") { echo(""); } +echo ' | '; -echo(" | Prefixes: "); +if ($vars['view'] == 'updates') { + echo ""; +} -if ($vars['view'] == "prefixes_ipv4unicast") { echo(""); } -echo(generate_link("IPv4", $link_array,array('view'=>'prefixes_ipv4unicast'))); -if ($vars['view'] == "prefixes_ipv4unicast") { echo(""); } +echo generate_link('Updates', $link_array, array('view' => 'updates')); +if ($vars['view'] == 'updates') { + echo ''; +} -echo(" | "); +echo ' | Prefixes: '; -if ($vars['view'] == "prefixes_vpnv4unicast") { echo(""); } -echo(generate_link("VPNv4", $link_array,array('view'=>'prefixes_vpnv4unicast'))); -if ($vars['view'] == "prefixes_vpnv4unicast") { echo(""); } +if ($vars['view'] == 'prefixes_ipv4unicast') { + echo ""; +} -echo(" | "); +echo generate_link('IPv4', $link_array, array('view' => 'prefixes_ipv4unicast')); +if ($vars['view'] == 'prefixes_ipv4unicast') { + echo ''; +} -if ($vars['view'] == "prefixes_ipv6unicast") { echo(""); } -echo(generate_link("IPv6", $link_array,array('view'=>'prefixes_ipv6unicast'))); -if ($vars['view'] == "prefixes_ipv6unicast") { echo(""); } +echo ' | '; -echo(" | Traffic: "); +if ($vars['view'] == 'prefixes_vpnv4unicast') { + echo ""; +} -if ($vars['view'] == "macaccounting_bits") { echo(""); } -echo(generate_link("Bits", $link_array,array('view'=>'macaccounting_bits'))); -if ($vars['view'] == "macaccounting_bits") { echo(""); } -echo(" | "); -if ($vars['view'] == "macaccounting_pkts") { echo(""); } -echo(generate_link("Packets", $link_array,array('view'=>'macaccounting_pkts'))); -if ($vars['view'] == "macaccounting_pkts") { echo(""); } +echo generate_link('VPNv4', $link_array, array('view' => 'prefixes_vpnv4unicast')); +if ($vars['view'] == 'prefixes_vpnv4unicast') { + echo ''; +} + +echo ' | '; + +if ($vars['view'] == 'prefixes_ipv6unicast') { + echo ""; +} + +echo generate_link('IPv6', $link_array, array('view' => 'prefixes_ipv6unicast')); +if ($vars['view'] == 'prefixes_ipv6unicast') { + echo ''; +} + +echo ' | Traffic: '; + +if ($vars['view'] == 'macaccounting_bits') { + echo ""; +} + +echo generate_link('Bits', $link_array, array('view' => 'macaccounting_bits')); +if ($vars['view'] == 'macaccounting_bits') { + echo ''; +} + +echo ' | '; +if ($vars['view'] == 'macaccounting_pkts') { + echo ""; +} + +echo generate_link('Packets', $link_array, array('view' => 'macaccounting_pkts')); +if ($vars['view'] == 'macaccounting_pkts') { + echo ''; +} print_optionbar_end(); -echo(''); -echo(''); +echo '
    Peer addressTypeRemote ASStateUptime
    '; +echo ''; -$i = "1"; +$i = '1'; -foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? ORDER BY `bgpPEerRemoteAs`, `bgpPeerIdentifier`", array($device['device_id'])) as $peer) -{ - $has_macaccounting = dbFetchCell("SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address", array($peer['bgpPeerIdentifier'])); - unset($bg_image); - if (!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } - unset ($alert, $bg_image); - unset ($peerhost, $peername); +foreach (dbFetchRows('SELECT * FROM `bgpPeers` WHERE `device_id` = ? ORDER BY `bgpPEerRemoteAs`, `bgpPeerIdentifier`', array($device['device_id'])) as $peer) { + $has_macaccounting = dbFetchCell('SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address', array($peer['bgpPeerIdentifier'])); + unset($bg_image); + if (!is_integer($i / 2)) { + $bg_colour = $list_colour_a; + } + else { + $bg_colour = $list_colour_b; + } - if (!is_integer($i/2)) { $bg_colour = $list_colour_b; } else { $bg_colour = $list_colour_a; } - if ($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $peer['alert']=1; } - if ($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "gray"; } - if ($peer['bgpPeerAdminStatus'] == "stop") { $peer['alert']=0; $peer['disabled']=1; } + unset($alert, $bg_image); + unset($peerhost, $peername); - if ($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; } + if (!is_integer($i / 2)) { + $bg_colour = $list_colour_b; + } + else { + $bg_colour = $list_colour_a; + } - $query = "SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE "; - $query .= "(A.ipv4_address = ? AND I.port_id = A.port_id)"; - $query .= " AND D.device_id = I.device_id"; - $ipv4_host = dbFetchRow($query,array($peer['bgpPeerIdentifier'])); + if ($peer['bgpPeerState'] == 'established') { + $col = 'green'; + } + else { + $col = 'red'; + $peer['alert'] = 1; + } - $query = "SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE "; - $query .= "(A.ipv6_address = ? AND I.port_id = A.port_id)"; - $query .= " AND D.device_id = I.device_id"; - $ipv6_host = dbFetchRow($query,array($peer['bgpPeerIdentifier'])); + if ($peer['bgpPeerAdminStatus'] == 'start' || $peer['bgpPeerAdminStatus'] == 'running') { + $admin_col = 'green'; + } + else { + $admin_col = 'gray'; + } - if ($ipv4_host) - { - $peerhost = $ipv4_host; - } elseif ($ipv6_host) { - $peerhost = $ipv6_host; - } else { - unset($peerhost); - } + if ($peer['bgpPeerAdminStatus'] == 'stop') { + $peer['alert'] = 0; + $peer['disabled'] = 1; + } - if (is_array($peerhost)) - { - #$peername = generate_device_link($peerhost); - $peername = generate_device_link($peerhost) ." ". generate_port_link($peerhost); - $peer_url = "device/device=" . $peer['device_id'] . "/tab=routing/proto=bgp/view=updates/"; - } - else - { - #$peername = gethostbyaddr($peer['bgpPeerIdentifier']); // FFffuuu DNS // Cache this in discovery? -# if ($peername == $peer['bgpPeerIdentifier']) -# { -# unset($peername); -# } else { -# $peername = "".$peername.""; -# } - } + if ($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { + $peer_type = "iBGP"; + } + else { + $peer_type = "eBGP"; + } - unset($peer_af); - unset($sep); + $query = 'SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE '; + $query .= '(A.ipv4_address = ? AND I.port_id = A.port_id)'; + $query .= ' AND D.device_id = I.device_id'; + $ipv4_host = dbFetchRow($query, array($peer['bgpPeerIdentifier'])); - foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($device['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) - { - $afi = $afisafi['afi']; - $safi = $afisafi['safi']; - $this_afisafi = $afi.$safi; - $peer['afi'] .= $sep . $afi .".".$safi; - $sep = "
    "; - $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer - } + $query = 'SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE '; + $query .= '(A.ipv6_address = ? AND I.port_id = A.port_id)'; + $query .= ' AND D.device_id = I.device_id'; + $ipv6_host = dbFetchRow($query, array($peer['bgpPeerIdentifier'])); - unset($sep); + if ($ipv4_host) { + $peerhost = $ipv4_host; + } + else if ($ipv6_host) { + $peerhost = $ipv6_host; + } + else { + unset($peerhost); + } - if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { - $peer['bgpPeerIdentifier'] = Net_IPv6::compress($peer['bgpPeerIdentifier']); - } + if (is_array($peerhost)) { + // $peername = generate_device_link($peerhost); + $peername = generate_device_link($peerhost).' '.generate_port_link($peerhost); + $peer_url = 'device/device='.$peer['device_id'].'/tab=routing/proto=bgp/view=updates/'; + } + else { + // FIXME + // $peername = gethostbyaddr($peer['bgpPeerIdentifier']); // FFffuuu DNS // Cache this in discovery? + // if ($peername == $peer['bgpPeerIdentifier']) + // { + // unset($peername); + // } else { + // $peername = "".$peername.""; + // } + } + + unset($peer_af); + unset($sep); + + foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { + $afi = $afisafi['afi']; + $safi = $afisafi['safi']; + $this_afisafi = $afi.$safi; + $peer['afi'] .= $sep.$afi.'.'.$safi; + $sep = '
    '; + $peer['afisafi'][$this_afisafi] = 1; + // Build a list of valid AFI/SAFI for this peer + } + + unset($sep); + + if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { + $peer['bgpPeerIdentifier'] = Net_IPv6::compress($peer['bgpPeerIdentifier']); + } - $graph_type = "bgp_updates"; - $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; - $peeraddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer['bgpPeerIdentifier'] . ""; + $graph_type = 'bgp_updates'; + $peer_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; + $peeraddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer['bgpPeerIdentifier'].''; - echo('
    - "); + echo ' + '; - echo(" - - - - - - - - "); + echo ' + + + + + + + + '; - unset($invalid); + unset($invalid); - switch ($vars['view']) - { + switch ($vars['view']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': - list(,$afisafi) = explode("_", $vars['view']); - if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } - // FIXME no break?? - case 'updates': - $graph_array['type'] = "bgp_" . $vars['view']; - $graph_array['id'] = $peer['bgpPeer_id']; - } + list(,$afisafi) = explode('_', $vars['view']); + if (isset($peer['afisafi'][$afisafi])) { + $peer['graph'] = 1; + } - switch ($vars['view']) - { + // FIXME no break?? + case 'updates': + $graph_array['type'] = 'bgp_'.$vars['view']; + $graph_array['id'] = $peer['bgpPeer_id']; + } + + switch ($vars['view']) { case 'macaccounting_bits': case 'macaccounting_pkts': - $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier'])); - $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; - if (is_array($acc) && is_file($database)) - { - $peer['graph'] = 1; - $graph_array['id'] = $acc['ma_id']; - $graph_array['type'] = $vars['view']; - } - } + $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', array($peer['bgpPeerIdentifier'])); + $database = $config['rrd_dir'].'/'.$device['hostname'].'/cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'; + if (is_array($acc) && is_file($database)) { + $peer['graph'] = 1; + $graph_array['id'] = $acc['ma_id']; + $graph_array['type'] = $vars['view']; + } + } - if ($vars['view'] == 'updates') { $peer['graph'] = 1; } + if ($vars['view'] == 'updates') { + $peer['graph'] = 1; + } - if ($peer['graph']) - { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - echo('"); - } + echo ''; + } - $i++; + $i++; - unset($valid_afi_safi); -} + unset($valid_afi_safi); +}//end foreach ?>
    Peer addressTypeRemote ASStateUptime
    ".$i."" . $peeraddresslink . "
    ".$peername."
    $peer_type" . (isset($peer['afi']) ? $peer['afi'] : '') . "AS" . $peer['bgpPeerRemoteAs'] . "
    " . $peer['astext'] . "
    " . $peer['bgpPeerAdminStatus'] . "
    " . $peer['bgpPeerState'] . "
    " .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
    - Updates " . $peer['bgpPeerInUpdates'] . " - " . $peer['bgpPeerOutUpdates'] . "
    '.$i.''.$peeraddresslink.'
    '.$peername."
    $peer_type".(isset($peer['afi']) ? $peer['afi'] : '').'AS'.$peer['bgpPeerRemoteAs'].'
    '.$peer['astext']."
    ".$peer['bgpPeerAdminStatus']."
    ".$peer['bgpPeerState'].'
    '.formatUptime($peer['bgpPeerFsmEstablishedTime'])."
    + Updates ".$peer['bgpPeerInUpdates']." + ".$peer['bgpPeerOutUpdates'].'
    '); + if ($peer['graph']) { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + echo '
    '; - include("includes/print-graphrow.inc.php"); + include 'includes/print-graphrow.inc.php'; - echo("
    diff --git a/html/pages/device/routing/ospf.inc.php b/html/pages/device/routing/ospf.inc.php index ed126a7fe3..7bf6798b7b 100644 --- a/html/pages/device/routing/ospf.inc.php +++ b/html/pages/device/routing/ospf.inc.php @@ -88,8 +88,7 @@ foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', arr // # Loop Ports $i_p = ($i_a + 1); $p_sql = "SELECT * FROM `ospf_ports` AS O, `ports` AS P WHERE O.`ospfIfAdminStat` = 'enabled' AND O.`device_id` = ? AND O.`ospfIfAreaId` = ? AND P.port_id = O.port_id"; - foreach (dbFetchRows($p_sql, array($device['device_id'], $area['ospfAreaId'])) as $ospfport) - { + foreach (dbFetchRows($p_sql, array($device['device_id'], $area['ospfAreaId'])) as $ospfport) { if (!is_integer($i_a / 2)) { if (!is_integer($i_p / 2)) { $port_bg = $list_colour_b_b; diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index aed9398dd2..9efc95d63a 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -1,134 +1,135 @@ = '7') { + if (!is_array($config['rancid_configs'])) { + $config['rancid_configs'] = array($config['rancid_configs']); + } -if ($_SESSION['userlevel'] >= "7") -{ + if (isset($config['rancid_configs'][0])) { + foreach ($config['rancid_configs'] as $configs) { + if ($configs[(strlen($configs) - 1)] != '/') { + $configs .= '/'; + } - if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); } + if (is_file($configs.$device['hostname'])) { + $file = $configs.$device['hostname']; + } + } - if (isset($config['rancid_configs'][0])) { + echo '
    '; - foreach ($config['rancid_configs'] as $configs) { - if ($configs[strlen($configs) - 1] != '/') { - $configs .= '/'; - } - if (is_file($configs . $device['hostname'])) { - $file = $configs . $device['hostname']; - } - } + print_optionbar_start('', ''); - echo('
    '); + echo "Config » "; - print_optionbar_start('', ''); + if (!$vars['rev']) { + echo ''; + echo generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig')); + echo ''; + } + else { + echo generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig')); + } - echo("Config » "); + if (function_exists('svn_log')) { + $sep = ' | '; + $svnlogs = svn_log($file, SVN_REVISION_HEAD, null, 8); + $revlist = array(); - if (!$vars['rev']) { - echo(''); - echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); - echo(""); - } else { - echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); - } + foreach ($svnlogs as $svnlog) { + echo $sep; + $revlist[] = $svnlog['rev']; - if (function_exists('svn_log')) { + if ($vars['rev'] == $svnlog['rev']) { + echo ''; + } - $sep = " | "; - $svnlogs = svn_log($file, SVN_REVISION_HEAD, NULL, 8); - $revlist = array(); + $linktext = 'r'.$svnlog['rev'].' '.date($config['dateformat']['byminute'], strtotime($svnlog['date'])).''; + echo generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog['rev'])); - foreach ($svnlogs as $svnlog) { + if ($vars['rev'] == $svnlog['rev']) { + echo ''; + } - echo($sep); - $revlist[] = $svnlog["rev"]; + $sep = ' | '; + } + }//end if - if ($vars['rev'] == $svnlog["rev"]) { - echo(''); - } - $linktext = "r" . $svnlog["rev"] . " " . date($config['dateformat']['byminute'], strtotime($svnlog["date"])) . ""; - echo(generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog["rev"]))); + print_optionbar_end(); - if ($vars['rev'] == $svnlog["rev"]) { - echo(""); - } + if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { + list($diff, $errors) = svn_diff($file, ($vars['rev'] - 1), $file, $vars['rev']); + if (!$diff) { + $text = 'No Difference'; + } + else { + $text = ''; + while (!feof($diff)) { + $text .= fread($diff, 8192); + } - $sep = " | "; - } - } + fclose($diff); + fclose($errors); + } + } + else { + $fh = fopen($file, 'r') or die("Can't open file"); + $text = fread($fh, filesize($file)); + fclose($fh); + } - print_optionbar_end(); + if ($config['rancid_ignorecomments']) { + $lines = explode("\n", $text); + for ($i = 0; $i < count($lines); $i++) { + if ($lines[$i][0] == '#') { + unset($lines[$i]); + } + } - if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { - list($diff, $errors) = svn_diff($file, $vars['rev'] - 1, $file, $vars['rev']); - if (!$diff) { - $text = "No Difference"; - } else { - $text = ""; - while (!feof($diff)) { - $text .= fread($diff, 8192); - } - fclose($diff); - fclose($errors); - } + $text = join("\n", $lines); + } + } + else if ($config['oxidized']['enabled'] === true && isset($config['oxidized']['url'])) { + $node_info = json_decode(file_get_contents($config['oxidized']['url'].'/node/show/'.$device['hostname'].'?format=json'), true); + $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.$device['hostname']); + if ($text == 'node not found') { + $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.$device['os'].'/'.$device['hostname']); + } - } else { - $fh = fopen($file, 'r') or die("Can't open file"); - $text = fread($fh, filesize($file)); - fclose($fh); - } - - if ($config['rancid_ignorecomments']) { - $lines = explode("\n", $text); - for ($i = 0; $i < count($lines); $i++) { - if ($lines[$i][0] == "#") { - unset($lines[$i]); - } - } - $text = join("\n", $lines); - } - } elseif ($config['oxidized']['enabled'] === TRUE && isset($config['oxidized']['url'])) { - $node_info = json_decode(file_get_contents($config['oxidized']['url']."/node/show/".$device['hostname']."?format=json"),TRUE); - $text = file_get_contents($config['oxidized']['url']."/node/fetch/".$device['hostname']); - if ($text == "node not found") { - $text = file_get_contents($config['oxidized']['url']."/node/fetch/".$device['os']."/".$device['hostname']); - } - - if (is_array($node_info)) { - echo('
    -
    + if (is_array($node_info)) { + echo '
    +
    -
    -
    Sync status: '.$node_info['last']['status'].'
    -
      -
    • Node: '. $node_info['name'].'
    • -
    • IP: '. $node_info['ip'].'
    • -
    • Model: '. $node_info['model'].'
    • -
    • Last Sync: '. $node_info['last']['end'].'
    • -
    -
    +
    +
    Sync status: '.$node_info['last']['status'].'
    +
      +
    • Node: '.$node_info['name'].'
    • +
    • IP: '.$node_info['ip'].'
    • +
    • Model: '.$node_info['model'].'
    • +
    • Last Sync: '.$node_info['last']['end'].'
    • +
    -
    '); - } else { - echo "
    "; - print_error("We couldn't retrieve the device information from Oxidized"); - $text = ''; - } +
    +
    '; + } + else { + echo '
    '; + print_error("We couldn't retrieve the device information from Oxidized"); + $text = ''; + } + }//end if - } + if (!empty($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 $geshi->parse_code(); + } +}//end if - if (!empty($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($geshi->parse_code()); - } -} - -$pagetitle[] = "Config"; - -?> +$pagetitle[] = 'Config'; diff --git a/html/pages/device/slas.inc.php b/html/pages/device/slas.inc.php index 3cc6cbf119..587c7d7438 100644 --- a/html/pages/device/slas.inc.php +++ b/html/pages/device/slas.inc.php @@ -12,7 +12,7 @@ foreach ($slas as $sla) { $sla_type = $sla['rtt_type']; if (!in_array($sla_type, $sla_types)) { - if (isset($config['sla_type_labels'][$sla_type])) { + if (isset($config['sla_type_labels'][$sla_type])) { $text = $config['sla_type_labels'][$sla_type]; } } diff --git a/html/pages/devices.inc.php b/html/pages/devices.inc.php index 67a8c39edd..0367b8a1c3 100644 --- a/html/pages/devices.inc.php +++ b/html/pages/devices.inc.php @@ -2,7 +2,9 @@ // Set Defaults here -if(!isset($vars['format'])) { $vars['format'] = "list_detail"; } +if(!isset($vars['format'])) { + $vars['format'] = "list_detail"; +} $pagetitle[] = "Devices"; @@ -10,23 +12,19 @@ print_optionbar_start(); echo('Lists » '); -$menu_options = array('basic' => 'Basic', - 'detail' => 'Detail'); +$menu_options = array('basic' => 'Basic', 'detail' => 'Detail'); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == "list_".$option) { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == "list_".$option) { + echo(""); + } + $sep = " | "; } ?> @@ -38,29 +36,26 @@ foreach ($menu_options as $option => $text) 'Bits', - 'processor' => 'CPU', - 'ucd_load' => 'Load', - 'mempool' => 'Memory', - 'uptime' => 'Uptime', - 'storage' => 'Storage', - 'diskio' => 'Disk I/O', - 'poller_perf' => 'Poller', - 'ping_perf' => 'Ping' - ); + 'processor' => 'CPU', + 'ucd_load' => 'Load', + 'mempool' => 'Memory', + 'uptime' => 'Uptime', + 'storage' => 'Storage', + 'diskio' => 'Disk I/O', + 'poller_perf' => 'Poller', + 'ping_perf' => 'Ping' +); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == 'graph_'.$option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == 'graph_'.$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == 'graph_'.$option) { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == 'graph_'.$option) { + echo(""); + } + $sep = " | "; } ?> @@ -69,21 +64,21 @@ foreach ($menu_options as $option => $text) '')).'">Restore Search'); - } else { +} +else { echo('Remove Search'); - } +} - echo(" | "); +echo(" | "); - if (isset($vars['bare']) && $vars['bare'] == "yes") - { +if (isset($vars['bare']) && $vars['bare'] == "yes") { echo('Restore Header'); - } else { +} +else { echo('Remove Header'); - } +} print_optionbar_end(); ?> @@ -94,76 +89,110 @@ print_optionbar_end(); list($format, $subformat) = explode("_", $vars['format'], 2); -if($format == "graph") -{ -$sql_param = array(); +if($format == "graph") { + $sql_param = array(); -if(isset($vars['state'])) -{ - if($vars['state'] == 'up') - { - $state = '1'; - } - elseif($vars['state'] == 'down') - { - $state = '0'; - } -} + if(isset($vars['state'])) { + if($vars['state'] == 'up') { + $state = '1'; + } + elseif($vars['state'] == 'down') { + $state = '0'; + } + } -if (!empty($vars['hostname'])) { $where .= " AND hostname LIKE ?"; $sql_param[] = "%".$vars['hostname']."%"; } -if (!empty($vars['os'])) { $where .= " AND os = ?"; $sql_param[] = $vars['os']; } -if (!empty($vars['version'])) { $where .= " AND version = ?"; $sql_param[] = $vars['version']; } -if (!empty($vars['hardware'])) { $where .= " AND hardware = ?"; $sql_param[] = $vars['hardware']; } -if (!empty($vars['features'])) { $where .= " AND features = ?"; $sql_param[] = $vars['features']; } -if (!empty($vars['type'])) { - if ($vars['type'] == 'generic') { - $where .= " AND ( type = ? OR type = '')"; $sql_param[] = $vars['type']; - } else { - $where .= " AND type = ?"; $sql_param[] = $vars['type']; - } -} -if (!empty($vars['state'])) { - $where .= " AND status= ?"; $sql_param[] = $state; - $where .= " AND disabled='0' AND `ignore`='0'"; $sql_param[] = ''; -} -if (!empty($vars['disabled'])) { $where .= " AND disabled= ?"; $sql_param[] = $vars['disabled']; } -if (!empty($vars['ignore'])) { $where .= " AND `ignore`= ?"; $sql_param[] = $vars['ignore']; } -if (!empty($vars['location']) && $vars['location'] == "Unset") { $location_filter = ''; } -if (!empty($vars['location'])) { $location_filter = $vars['location']; } -if( !empty($vars['group']) ) { - require_once('../includes/device-groups.inc.php'); - $where .= " AND ( "; - foreach( GetDevicesFromGroup($vars['group']) as $dev ) { - $where .= "device_id = ? OR "; - $sql_param[] = $dev['device_id']; - } - $where = substr($where, 0, strlen($where)-3); - $where .= " )"; -} + if (!empty($vars['hostname'])) { + $where .= " AND hostname LIKE ?"; + $sql_param[] = "%".$vars['hostname']."%"; + } + if (!empty($vars['os'])) { + $where .= " AND os = ?"; + $sql_param[] = $vars['os']; + } + if (!empty($vars['version'])) { + $where .= " AND version = ?"; + $sql_param[] = $vars['version']; + } + if (!empty($vars['hardware'])) { + $where .= " AND hardware = ?"; + $sql_param[] = $vars['hardware']; + } + if (!empty($vars['features'])) { + $where .= " AND features = ?"; + $sql_param[] = $vars['features']; + } -$query = "SELECT * FROM `devices` WHERE 1 "; + if (!empty($vars['type'])) { + if ($vars['type'] == 'generic') { + $where .= " AND ( type = ? OR type = '')"; + $sql_param[] = $vars['type']; + } + else { + $where .= " AND type = ?"; + $sql_param[] = $vars['type']; + } + } + if (!empty($vars['state'])) { + $where .= " AND status= ?"; + $sql_param[] = $state; + $where .= " AND disabled='0' AND `ignore`='0'"; + $sql_param[] = ''; + } + if (!empty($vars['disabled'])) { + $where .= " AND disabled= ?"; + $sql_param[] = $vars['disabled']; + } + if (!empty($vars['ignore'])) { + $where .= " AND `ignore`= ?"; + $sql_param[] = $vars['ignore']; + } + if (!empty($vars['location']) && $vars['location'] == "Unset") { + $location_filter = ''; + } + if (!empty($vars['location'])) { + $location_filter = $vars['location']; + } + if( !empty($vars['group']) ) { + require_once('../includes/device-groups.inc.php'); + $where .= " AND ( "; + foreach( GetDevicesFromGroup($vars['group']) as $dev ) { + $where .= "device_id = ? OR "; + $sql_param[] = $dev['device_id']; + } + $where = substr($where, 0, strlen($where)-3); + $where .= " )"; + } -if (isset($where)) { - $query .= $where; -} + $query = "SELECT * FROM `devices` WHERE 1 "; -$query .= " ORDER BY hostname"; + if (isset($where)) { + $query .= $where; + } - $row = 1; - foreach (dbFetchRows($query, $sql_param) as $device) - { - if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + $query .= " ORDER BY hostname"; - if (device_permitted($device['device_id'])) - { - if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter) - || $device['location'] == $location_filter)) - { - $graph_type = "device_".$subformat; + $row = 1; + foreach (dbFetchRows($query, $sql_param) as $device) { + if (is_integer($row/2)) { + $row_colour = $list_colour_a; + } + else { + $row_colour = $list_colour_b; + } - if ($_SESSION['widescreen']) { $width=270; } else { $width=315; } + if (device_permitted($device['device_id'])) { + if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter) + || $device['location'] == $location_filter)) { + $graph_type = "device_".$subformat; - echo("
    + if ($_SESSION['widescreen']) { + $width=270; + } + else { + $width=315; + } + + echo("\ \ @@ -171,11 +200,11 @@ $query .= " ORDER BY hostname"; "
    "); - } + } + } } - } - -} else { +} +else { ?> @@ -209,22 +238,23 @@ $query .= " ORDER BY hostname"; ""+ '.$config['os'][$tmp_os]['text'].'"+'); + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `os` FROM `devices` AS D WHERE 1 GROUP BY `os` ORDER BY `os`"; + } + else { + $sql = "SELECT `os` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `os` ORDER BY `os`"; + $param[] = $_SESSION['user_id']; + } + foreach (dbFetch($sql,$param) as $data) { + if ($data['os']) { + $tmp_os = clean_bootgrid($data['os']); + echo('""+'); + } } -} ?> ""+ "
    "+ @@ -233,22 +263,23 @@ foreach (dbFetch($sql,$param) as $data) { ""+ '.$tmp_version.'"+'); } - echo('">'.$tmp_version.'"+'); - } -} + } ?> ""+ "
    "+ @@ -257,22 +288,23 @@ foreach (dbFetch($sql,$param) as $data) { ""+ '.$tmp_hardware.'"+'); + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `hardware` FROM `devices` AS D WHERE 1 GROUP BY `hardware` ORDER BY `hardware`"; + } + else { + $sql = "SELECT `hardware` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hardware` ORDER BY `hardware`"; + $param[] = $_SESSION['user_id']; + } + foreach (dbFetch($sql,$param) as $data) { + if ($data['hardware']) { + $tmp_hardware = clean_bootgrid($data['hardware']); + echo('""+'); + } } -} ?> ""+ @@ -282,24 +314,24 @@ foreach (dbFetch($sql,$param) as $data) { ""+ '.$tmp_features.'"+'); + else { + $sql = "SELECT `features` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `features` ORDER BY `features`"; + $param[] = $_SESSION['user_id']; + } + + foreach (dbFetch($sql,$param) as $data) { + if ($data['features']) { + $tmp_features = clean_bootgrid($data['features']); + echo('""+'); + } } -} ?> ""+ @@ -311,16 +343,16 @@ foreach (dbFetch($sql,$param) as $data) '.$location.'"+'); } - echo('">'.$location.'"+'); } -} ?> ""+ ""+ @@ -329,21 +361,22 @@ foreach (getlocations() as $location) { ""+ '.ucfirst($data['type']).'"+'); + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `type` FROM `devices` AS D WHERE 1 GROUP BY `type` ORDER BY `type`"; + } + else { + $sql = "SELECT `type` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `type` ORDER BY `type`"; + $param[] = $_SESSION['user_id']; + } + foreach (dbFetch($sql,$param) as $data) { + if ($data['type']) { + echo('""+'); + } } -} ?> ""+ @@ -357,9 +390,9 @@ foreach (dbFetch($sql,$param) as $data) { "

    " var grid = $("#devices").bootgrid({ @@ -400,5 +433,3 @@ var grid = $("#devices").bootgrid({ diff --git a/html/pages/editsrv.inc.php b/html/pages/editsrv.inc.php index 9c56b96d1e..1c04e4510f 100644 --- a/html/pages/editsrv.inc.php +++ b/html/pages/editsrv.inc.php @@ -1,35 +1,30 @@ "5") - { - include("includes/service-edit.inc.php"); + if ($_POST['confirm-editsrv']) { + if ($_SESSION['userlevel'] > '5') { + include 'includes/service-edit.inc.php'; } } - foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname") as $device) - { - $servicesform .= ""; + foreach (dbFetchRows('SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname') as $device) { + $servicesform .= "'; } - if ($updated) { print_message("Service updated!"); } + if ($updated) { + print_message('Service updated!'); + } if ($_POST['editsrv'] == 'yes') { - - require_once "includes/print-service-edit.inc.php"; - - } else { - - echo(" + include_once 'includes/print-service-edit.inc.php'; + } + else { + echo "

    Delete Service

    @@ -46,7 +41,6 @@ if (is_admin() === FALSE && is_read() === FALSE) { -
    "); - } - -} + "; + }//end if +}//end if diff --git a/html/pages/edituser.inc.php b/html/pages/edituser.inc.php index 6a9a7d2830..ec2a3f1c9e 100644 --- a/html/pages/edituser.inc.php +++ b/html/pages/edituser.inc.php @@ -1,167 +1,170 @@ "); +echo "
    "; -$pagetitle[] = "Edit user"; +$pagetitle[] = 'Edit user'; -if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php"); } else -{ - if ($vars['user_id'] && !$vars['edit']) - { - $user_data = dbFetchRow("SELECT * FROM users WHERE user_id = ?", array($vars['user_id'])); - echo("

    " . $user_data['realname'] . "

    Change...

    "); - // Perform actions if requested +if ($_SESSION['userlevel'] != '10') { + include 'includes/error-no-perm.inc.php'; +} +else { + if ($vars['user_id'] && !$vars['edit']) { + $user_data = dbFetchRow('SELECT * FROM users WHERE user_id = ?', array($vars['user_id'])); + echo '

    '.$user_data['realname']."

    Change...

    "; + // Perform actions if requested + if ($vars['action'] == 'deldevperm') { + if (dbFetchCell('SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id']))) { + dbDelete('devices_perms', '`device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id'])); + } + } - if ($vars['action'] == "deldevperm") - { - if (dbFetchCell("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?", array($vars['device_id'] ,$vars['user_id']))) - { - dbDelete('devices_perms', "`device_id` = ? AND `user_id` = ?", array($vars['device_id'], $vars['user_id'])); - } - } - if ($vars['action'] == "adddevperm") - { - if (!dbFetchCell("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?", array($vars['device_id'] ,$vars['user_id']))) - { - dbInsert(array('device_id' => $vars['device_id'], 'user_id' => $vars['user_id']), 'devices_perms'); - } - } - if ($vars['action'] == "delifperm") - { - if (dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) - { - dbDelete('ports_perms', "`port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id'])); - } - } - if ($vars['action'] == "addifperm") - { - if (!dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) - { - dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms'); - } - } - if ($vars['action'] == "delbillperm") - { - if (dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) - { - dbDelete('bill_perms', "`bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id'])); - } - } - if ($vars['action'] == "addbillperm") - { - if (!dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) - { - dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms'); - } - } + if ($vars['action'] == 'adddevperm') { + if (!dbFetchCell('SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id']))) { + dbInsert(array('device_id' => $vars['device_id'], 'user_id' => $vars['user_id']), 'devices_perms'); + } + } - echo('
    -
    '); + if ($vars['action'] == 'delifperm') { + if (dbFetchCell('SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id']))) { + dbDelete('ports_perms', '`port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id'])); + } + } - // Display devices this users has access to - echo("

    Device Access

    "); + if ($vars['action'] == 'addifperm') { + if (!dbFetchCell('SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id']))) { + dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms'); + } + } - echo("
    + if ($vars['action'] == 'delbillperm') { + if (dbFetchCell('SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id']))) { + dbDelete('bill_perms', '`bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id'])); + } + } + + if ($vars['action'] == 'addbillperm') { + if (!dbFetchCell('SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id']))) { + dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms'); + } + } + + echo '
    +
    '; + + // Display devices this users has access to + echo '

    Device Access

    '; + + echo "
    - "); + "; - $device_perms = dbFetchRows("SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id", array($vars['user_id'])); - foreach ($device_perms as $device_perm) - { - echo(""); - $access_list[] = $device_perm['device_id']; - $permdone = "yes"; - } + $device_perms = dbFetchRows('SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id', array($vars['user_id'])); + foreach ($device_perms as $device_perm) { + echo '"; + $access_list[] = $device_perm['device_id']; + $permdone = 'yes'; + } - echo("
    Device Action
    " . $device_perm['hostname'] . "
    '.$device_perm['hostname']."
    -
    "); + echo ' +
    '; - if (!$permdone) { echo("None Configured"); } + if (!$permdone) { + echo 'None Configured'; + } - // Display devices this user doesn't have access to - echo("

    Grant access to new device

    "); - echo("
    - + // Display devices this user doesn't have access to + echo '

    Grant access to new device

    '; + echo " +
    - "; - $devices = dbFetchRows("SELECT * FROM `devices` ORDER BY hostname"); - foreach ($devices as $device) - { - unset($done); - foreach ($access_list as $ac) { if ($ac == $device['device_id']) { $done = 1; } } - if (!$done) - { - echo(""); - } - } + $devices = dbFetchRows('SELECT * FROM `devices` ORDER BY hostname'); + foreach ($devices as $device) { + unset($done); + foreach ($access_list as $ac) { + if ($ac == $device['device_id']) { + $done = 1; + } + } - echo(" + if (!$done) { + echo "'; + } + } + + echo "
    -
    "); + "; - echo("
    -
    "); - echo("

    Interface Access

    "); + echo "
    +
    "; + echo '

    Interface Access

    '; - $interface_perms = dbFetchRows("SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($vars['user_id'])); + $interface_perms = dbFetchRows('SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id', array($vars['user_id'])); - echo("
    + echo "
    - "); - foreach ($interface_perms as $interface_perm) - { - echo(" + "; + foreach ($interface_perms as $interface_perm) { + echo ' - "); - $ipermdone = "yes"; - } - echo("
    Interface name Action
    - ".$interface_perm['hostname']." - ".$interface_perm['ifDescr']."". - "" . $interface_perm['ifAlias'] . " + '.$interface_perm['hostname'].' - '.$interface_perm['ifDescr'].''.''.$interface_perm['ifAlias']." -    +   
    -
    "); + "; + $ipermdone = 'yes'; + } - if (!$ipermdone) { echo("None Configured"); } + echo ' +
    '; - // Display devices this user doesn't have access to - echo("

    Grant access to new interface

    "); + if (!$ipermdone) { + echo 'None Configured'; + } - echo("
    - + // Display devices this user doesn't have access to + echo '

    Grant access to new interface

    '; + + echo " +
    + if (!$done) { + echo "'; + } + } + + echo "
    @@ -176,133 +179,135 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    - "); + "; - echo("
    -
    "); - echo("

    Bill Access

    "); + echo "
    +
    "; + echo '

    Bill Access

    '; - $bill_perms = dbFetchRows("SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id", array($vars['user_id'])); + $bill_perms = dbFetchRows('SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id', array($vars['user_id'])); - echo("
    + echo "
    - "); + "; - foreach ($bill_perms as $bill_perm) - { - echo(" + foreach ($bill_perms as $bill_perm) { + echo ' - "); - $bill_access_list[] = $bill_perm['bill_id']; + "; + $bill_access_list[] = $bill_perm['bill_id']; - $bpermdone = "yes"; - } + $bpermdone = 'yes'; + } - echo("
    Bill name Action
    - ".$bill_perm['bill_name']."   + '.$bill_perm['bill_name']."  
    -
    "); + echo ' +
    '; - if (!$bpermdone) { echo("None Configured"); } + if (!$bpermdone) { + echo 'None Configured'; + } - // Display devices this user doesn't have access to - echo("

    Grant access to new bill

    "); - echo("
    - + // Display devices this user doesn't have access to + echo '

    Grant access to new bill

    '; + echo " +
    - "; - $bills = dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_name`"); - foreach ($bills as $bill) - { - unset($done); - foreach ($bill_access_list as $ac) { if ($ac == $bill['bill_id']) { $done = 1; } } - if (!$done) - { - echo(""); - } - } + $bills = dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_name`'); + foreach ($bills as $bill) { + unset($done); + foreach ($bill_access_list as $ac) { + if ($ac == $bill['bill_id']) { + $done = 1; + } + } - echo(" + if (!$done) { + echo "'; + } + } + + echo "
    -
    "); - - } elseif ($vars['user_id'] && $vars['edit']) { - - if($_SESSION['userlevel'] == 11) { - demo_account(); - } else { - - if(!empty($vars['new_level'])) - { - if($vars['can_modify_passwd'] == 'on') { - $vars['can_modify_passwd'] = '1'; - } - update_user($vars['user_id'],$vars['new_realname'],$vars['new_level'],$vars['can_modify_passwd'],$vars['new_email']); - print_message("User has been updated"); +
    "; } - - if(can_update_users() == '1') { - - $users_details = get_user($vars['user_id']); - if(!empty($users_details)) - { - - if(empty($vars['new_realname'])) - { - $vars['new_realname'] = $users_details['realname']; - } - if(empty($vars['new_level'])) - { - $vars['new_level'] = $users_details['level']; - } - if(empty($vars['can_modify_passwd'])) - { - $vars['can_modify_passwd'] = $users_details['can_modify_passwd']; - } elseif($vars['can_modify_passwd'] == 'on') { - $vars['can_modify_passwd'] = '1'; - } - if(empty($vars['new_email'])) - { - $vars['new_email'] = $users_details['email']; + else if ($vars['user_id'] && $vars['edit']) { + if ($_SESSION['userlevel'] == 11) { + demo_account(); } + else { + if (!empty($vars['new_level'])) { + if ($vars['can_modify_passwd'] == 'on') { + $vars['can_modify_passwd'] = '1'; + } - if( $config['twofactor'] ) { - if( $vars['twofactorremove'] ) { - if( dbUpdate(array('twofactor'=>''),users,'user_id = ?',array($vars['user_id'])) ) { - echo "
    TwoFactor credentials removed.
    "; - } else { - echo "
    Couldnt remove user's TwoFactor credentials.
    "; + update_user($vars['user_id'], $vars['new_realname'], $vars['new_level'], $vars['can_modify_passwd'], $vars['new_email']); + print_message('User has been updated'); } - } - if( $vars['twofactorunlock'] ) { - $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE user_id = ?",array($vars['user_id'])); - $twofactor = json_decode($twofactor['twofactor'],true); - $twofactor['fails'] = 0; - if( dbUpdate(array('twofactor'=>json_encode($twofactor)),users,'user_id = ?',array($vars['user_id'])) ) { - echo "
    User unlocked.
    "; - } else { - echo "
    Couldnt reset user's TwoFactor failures.
    "; - } - } - } - echo("
    - + if (can_update_users() == '1') { + $users_details = get_user($vars['user_id']); + if (!empty($users_details)) { + if (empty($vars['new_realname'])) { + $vars['new_realname'] = $users_details['realname']; + } + + if (empty($vars['new_level'])) { + $vars['new_level'] = $users_details['level']; + } + + if (empty($vars['can_modify_passwd'])) { + $vars['can_modify_passwd'] = $users_details['can_modify_passwd']; + } + else if ($vars['can_modify_passwd'] == 'on') { + $vars['can_modify_passwd'] = '1'; + } + + if (empty($vars['new_email'])) { + $vars['new_email'] = $users_details['email']; + } + + if ($config['twofactor']) { + if ($vars['twofactorremove']) { + if (dbUpdate(array('twofactor' => ''), users, 'user_id = ?', array($vars['user_id']))) { + echo "
    TwoFactor credentials removed.
    "; + } + else { + echo "
    Couldnt remove user's TwoFactor credentials.
    "; + } + } + + if ($vars['twofactorunlock']) { + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE user_id = ?', array($vars['user_id'])); + $twofactor = json_decode($twofactor['twofactor'], true); + $twofactor['fails'] = 0; + if (dbUpdate(array('twofactor' => json_encode($twofactor)), users, 'user_id = ?', array($vars['user_id']))) { + echo "
    User unlocked.
    "; + } + else { + echo "
    Couldnt reset user's TwoFactor failures.
    "; + } + } + } + + echo " +
    - +
    @@ -310,7 +315,7 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    - +
    @@ -319,10 +324,22 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    @@ -332,7 +349,10 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    @@ -340,14 +360,14 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    - "); - if( $config['twofactor'] ) { - echo "

    Two-Factor Authentication

    "; - $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE user_id = ?",array($vars['user_id'])); - $twofactor = json_decode($twofactor['twofactor'],true); - if( $twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time()-$twofactor['last']) < $config['twofactor_lock']) ) { - echo "
    - +
    "; + if ($config['twofactor']) { + echo "

    Two-Factor Authentication

    "; + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE user_id = ?', array($vars['user_id'])); + $twofactor = json_decode($twofactor['twofactor'], true); + if ($twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time() - $twofactor['last']) < $config['twofactor_lock'])) { + echo "
    +
    @@ -355,43 +375,47 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    "; - } - if( $twofactor['key'] ) { - echo "
    - + } + + if ($twofactor['key']) { + echo " +
    "; - } else { - echo "

    No TwoFactor key generated for this user, Nothing to do.

    "; - } - } - } else { - echo print_error("Error getting user details"); - } - } else { - echo print_error("Authentication method doesn't support updating users"); + } + else { + echo '

    No TwoFactor key generated for this user, Nothing to do.

    '; + } + }//end if + } + else { + echo print_error('Error getting user details'); + }//end if + } + else { + echo print_error("Authentication method doesn't support updating users"); + }//end if + }//end if } - } - } else { + else { + $user_list = get_userlist(); - $user_list = get_userlist(); + echo '

    Select a user to edit

    '; - echo("

    Select a user to edit

    "); - - echo("
    + echo "
    - +
    @@ -399,11 +423,8 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php"); /
    - "); - } + "; + }//end if +}//end if -} - -echo("
    "); - -?> +echo '
    '; diff --git a/html/pages/eventlog.inc.php b/html/pages/eventlog.inc.php index 4e1cad13d2..2ac41ec91b 100644 --- a/html/pages/eventlog.inc.php +++ b/html/pages/eventlog.inc.php @@ -1,16 +1,15 @@ = '10') -{ - dbQuery("TRUNCATE TABLE `eventlog`"); - print_message("Event log truncated"); +if ($vars['action'] == 'expunge' && $_SESSION['userlevel'] >= '10') { + dbQuery('TRUNCATE TABLE `eventlog`'); + print_message('Event log truncated'); } -$pagetitle[] = "Eventlog"; +$pagetitle[] = 'Eventlog'; print_optionbar_start(); @@ -24,15 +23,17 @@ print_optionbar_start();
    @@ -40,9 +41,7 @@ print_optionbar_start(); diff --git a/html/pages/front/default.php b/html/pages/front/default.php index 7b17f08a45..b69f7f97b1 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -1,174 +1,180 @@ + +function generate_front_box($frontbox_class, $content) { + echo "
    $content -
    "); + "; + +}//end generate_front_box() + + +echo ' +
    +'; +if ($config['vertical_summary']) { + echo '
    '; +} +else { + echo '
    '; } -echo(' -
    -'); -if ($config['vertical_summary']) { - echo('
    '); -} -else -{ - echo('
    '); -} -echo(' +echo '
    -'); +'; -echo('
    '); +echo '
    '; -echo('
    '); +echo '
    '; $count_boxes = 0; // Device down boxes -if ($_SESSION['userlevel'] >= '10') -{ - $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT ".$config['front_page_down_box_limit']; -} else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0' LIMIT".$config['front_page_down_box_limit']; +if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT ".$config['front_page_down_box_limit']; } -foreach (dbFetchRows($sql) as $device) -{ - generate_front_box("device-down", generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 20).""); - ++$count_boxes; +else { + $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '0' AND D.ignore = '0' LIMIT".$config['front_page_down_box_limit']; } -if ($_SESSION['userlevel'] >= '10') -{ - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; -} else { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; +foreach (dbFetchRows($sql) as $device) { + generate_front_box( + 'device-down', + generate_device_link($device, shorthost($device['hostname'])).'
    + Device Down
    + '.truncate($device['location'], 20).'' + ); + ++$count_boxes; +} + +if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; +} +else { + $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; } // These things need to become more generic, and more manageable across different frontpages... rewrite inc :> - // Port down boxes -if ($config['warn']['ifdown']) -{ - foreach (dbFetchRows($sql) as $interface) - { - if (!$interface['deleted']) - { - $interface = ifNameDescr($interface); - generate_front_box("port-down", generate_device_link($interface, shorthost($interface['hostname']))."
    +if ($config['warn']['ifdown']) { + foreach (dbFetchRows($sql) as $interface) { + if (!$interface['deleted']) { + $interface = ifNameDescr($interface); + generate_front_box( + 'port-down', + generate_device_link($interface, shorthost($interface['hostname']))."
    Port Down
    - - ".generate_port_link($interface, truncate(makeshortif($interface['label']),13,''))."
    - " . ($interface['ifAlias'] ? ''.truncate($interface['ifAlias'], 20, '').'' : '')); - ++$count_boxes; + + ".generate_port_link($interface, truncate(makeshortif($interface['label']), 13, '')).'
    + '.($interface['ifAlias'] ? ''.truncate($interface['ifAlias'], 20, '').'' : '') + ); + ++$count_boxes; + } } - } } -/* FIXME service permissions? seem nonexisting now.. */ +/* + FIXME service permissions? seem nonexisting now.. */ // Service down boxes -if ($_SESSION['userlevel'] >= '10') -{ - $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - $param[] = ''; +if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + $param[] = ''; } -else -{ - $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - $param[] = $_SESSION['user_id']; +else { + $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + $param[] = $_SESSION['user_id']; } -foreach (dbFetchRows($sql,$param) as $service) -{ - generate_front_box("service-down", generate_device_link($service, shorthost($service['hostname']))."
    + +foreach (dbFetchRows($sql, $param) as $service) { + generate_front_box( + 'service-down', + generate_device_link($service, shorthost($service['hostname'])).'
    Service Down - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 20).""); - ++$count_boxes; + '.$service['service_type'].'
    + '.truncate($interface['ifAlias'], 20).'' + ); + ++$count_boxes; } // BGP neighbour down boxes -if (isset($config['enable_bgp']) && $config['enable_bgp']) -{ - if ($_SESSION['userlevel'] >= '10') - { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - } else { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - } - foreach (dbFetchRows($sql) as $peer) - { - generate_front_box("bgp-down", generate_device_link($peer, shorthost($peer['hostname']))."
    +if (isset($config['enable_bgp']) && $config['enable_bgp']) { + if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + } + else { + $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + } + + foreach (dbFetchRows($sql) as $peer) { + generate_front_box( + 'bgp-down', + generate_device_link($peer, shorthost($peer['hostname']))."
    BGP Down - ".$peer['bgpPeerIdentifier']."
    - AS".truncate($peer['bgpPeerRemoteAs']." ".$peer['astext'], 14, "").""); - ++$count_boxes; - } + ".$peer['bgpPeerIdentifier'].'
    + AS'.truncate($peer['bgpPeerRemoteAs'].' '.$peer['astext'], 14, '').'' + ); + ++$count_boxes; + } } // Device rebooted boxes -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - if ($_SESSION['userlevel'] >= '10') - { - $sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; - } else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" . - $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; + } + else { + $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; + } - foreach (dbFetchRows($sql) as $device) - { - generate_front_box("device-rebooted", generate_device_link($device, shorthost($device['hostname']))."
    + foreach (dbFetchRows($sql) as $device) { + generate_front_box( + 'device-rebooted', + generate_device_link($device, shorthost($device['hostname'])).'
    Device Rebooted
    - ".formatUptime($device['uptime'], 'short').""); - ++$count_boxes; - } + '.formatUptime($device['uptime'], 'short').'' + ); + ++$count_boxes; + } } + if ($count_boxes == 0) { - echo("
    Nothing here yet

    This is where status notifications about devices and services would normally go. You might have none - because you run such a great network, or perhaps you've just started using ".$config['project_name'].". If you're new to ".$config['project_name'].", you might - want to start by adding one or more devices in the Devices menu.

    "); -} -echo('
    '); -echo('
    '); -echo('
    '); -echo(' -
    -
    -'); - -if ($config['vertical_summary']) -{ - echo('
    '); - include_once("includes/device-summary-vert.inc.php"); -} -else -{ - echo('
    '); - include_once("includes/device-summary-horiz.inc.php"); + echo "
    Nothing here yet

    This is where status notifications about devices and services would normally go. You might have none + because you run such a great network, or perhaps you've just started using ".$config['project_name'].". If you're new to ".$config['project_name'].', you might + want to start by adding one or more devices in the Devices menu.

    '; } -echo(' +echo '
    '; +echo '
    '; +echo '
    '; +echo ' +
    +
    +'; + +if ($config['vertical_summary']) { + echo '
    '; + include_once 'includes/device-summary-vert.inc.php'; +} +else { + echo '
    '; + include_once 'includes/device-summary-horiz.inc.php'; +} + +echo '
    -'); +'; -if ($config['enable_syslog']) -{ +if ($config['enable_syslog']) { + $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; + $query = mysql_query($sql); - $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; - $query = mysql_query($sql); - - echo('
    + echo '
      @@ -180,35 +186,34 @@ if ($config['enable_syslog'])
    Syslog entries
    -
    '); +
    '; - foreach (dbFetchRows($sql) as $entry) - { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); + foreach (dbFetchRows($sql) as $entry) { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include("includes/print-syslog.inc.php"); - } - echo("
    "); - echo(""); - echo(""); - echo(""); - echo(""); + include 'includes/print-syslog.inc.php'; + } -} else { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +} +else { + if ($_SESSION['userlevel'] >= '10') { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15'; + } + else { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = ".$_SESSION['user_id'].' ORDER BY `datetime` DESC LIMIT 0,15'; + $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = '.$_SESSION['user_id'].' ORDER BY `time_logged` DESC LIMIT 0,15'; + } - if ($_SESSION['userlevel'] >= '10') - { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15"; - } else { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id'] . " ORDER BY `time_logged` DESC LIMIT 0,15"; - } + $data = mysql_query($query); + $alertdata = mysql_query($alertquery); - $data = mysql_query($query); - $alertdata = mysql_query($alertquery); - - echo('
    + echo '
      @@ -220,13 +225,13 @@ if ($config['enable_syslog'])
    Alertlog entries
    - '); +
    '; - foreach (dbFetchRows($alertquery) as $alert_entry) - { - include("includes/print-alerts.inc.php"); - } - echo('
    + foreach (dbFetchRows($alertquery) as $alert_entry) { + include 'includes/print-alerts.inc.php'; + } + + echo '
    @@ -234,24 +239,21 @@ if ($config['enable_syslog'])
    Eventlog entries
    - '); +
    '; - foreach (dbFetchRows($query) as $entry) - { - include("includes/print-event.inc.php"); - } + foreach (dbFetchRows($query) as $entry) { + include 'includes/print-event.inc.php'; + } - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo(""); -} + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +}//end if -echo(""); +echo ''; -echo(' +echo ' -'); - -?> +'; diff --git a/html/pages/front/demo.php b/html/pages/front/demo.php index 1000fbca24..6478a566b8 100644 --- a/html/pages/front/demo.php +++ b/html/pages/front/demo.php @@ -4,56 +4,55 @@ "); +echo ''; -$dev_list = array('6' => 'Central Fileserver', - '7' => 'NE61 Fileserver', - '34' => 'DE56 Fileserver'); +$dev_list = array( + '6' => 'Central Fileserver', + '7' => 'NE61 Fileserver', + '34' => 'DE56 Fileserver', +); -foreach ($dev_list as $device_id => $descr) -{ +foreach ($dev_list as $device_id => $descr) { + echo ''; +}//end foreach - echo(""); - -} - -echo("
    '; + echo "
    ".$descr.'
    '; + $graph_array['height'] = '100'; + $graph_array['width'] = '310'; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device_id; + $graph_array['type'] = 'device_bits'; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; + $graph_array['popup_title'] = $descr; + // $graph_array['link'] = generate_device_link($device_id); + print_graph_popup($graph_array); - echo("
    "); - echo("
    ".$descr."
    "); - $graph_array['height'] = "100"; - $graph_array['width'] = "310"; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device_id; - $graph_array['type'] = "device_bits"; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; - $graph_array['popup_title'] = $descr; -# $graph_array['link'] = generate_device_link($device_id); - print_graph_popup($graph_array); + $graph_array['height'] = '50'; + $graph_array['width'] = '180'; - $graph_array['height'] = "50"; - $graph_array['width'] = "180"; + echo "
    "; + $graph_array['type'] = 'device_ucd_memory'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_ucd_memory"; - print_graph_popup($graph_array); - echo("
    "); + echo "
    "; + $graph_array['type'] = 'device_processor'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_processor"; - print_graph_popup($graph_array); - echo("
    "); + echo "
    "; + $graph_array['type'] = 'device_storage'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_storage"; - print_graph_popup($graph_array); - echo("
    "); + echo "
    "; + $graph_array['type'] = 'device_diskio'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_diskio"; - print_graph_popup($graph_array); - echo("
    "); + echo '
    "); +echo ''; ?> @@ -62,115 +61,105 @@ echo(""); '0' AND A.attrib_value < '86400'"; -foreach (dbFetchRows($sql) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = "yes"; +foreach (dbFetchRows($sql) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) -{ - if (device_permitted($device['device_id'])) { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35)." -
    "); - } +foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id'])) { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35).' +
    '; + } } -if ($config['warn']['ifdown']) -{ - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; - foreach (dbFetchRows($sql) as $interface) - { - if (port_permitted($interface['port_id'])) - { - echo("
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 15)." -
    "); +if ($config['warn']['ifdown']) { + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; + foreach (dbFetchRows($sql) as $interface) { + if (port_permitted($interface['port_id'])) { + echo "
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } - } } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) -{ - if (device_permitted($service['device_id'])) - { - echo("
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } +foreach (dbFetchRows($sql) as $service) { + if (device_permitted($service['device_id'])) { + echo "
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) -{ - if (device_permitted($peer['device_id'])) - { - echo("
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - } -} - -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE - A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) - { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") - { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); +foreach (dbFetchRows($sql) as $peer) { + if (device_permitted($peer['device_id'])) { + echo "
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; } - } } -echo(" -
    $errorboxes
    +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE + A.attrib_value < '".$config['uptime_warning']."' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; + foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } + } +} -

    Recent Syslog Messages

    -"); +echo " +
    $errorboxes
    + +

    Recent Syslog Messages

    + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from `syslog` ORDER BY seq DESC LIMIT 20"; -echo(""); -foreach (dbFetchRows($sql) as $entry) -{ - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include("includes/print-syslog.inc.php"); + include 'includes/print-syslog.inc.php'; } -echo("
    "); +echo ''; ?> diff --git a/html/pages/front/example2.php b/html/pages/front/example2.php index 717ee75184..e5898ac073 100644 --- a/html/pages/front/example2.php +++ b/html/pages/front/example2.php @@ -4,173 +4,141 @@
    Devices with Alerts
    Host
    Int
    Srv
    +// ?> '0' AND A.attrib_value < '86400'"; -foreach (dbFetchRows($sql) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) - { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) - { - $already = "yes"; +foreach (dbFetchRows($sql) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) -{ - echo("
    -
    ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down - ".truncate($device['location'], 20)." -
    "); - +foreach (dbFetchRows($sql) as $device) { + echo "
    +
    ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down + ".truncate($device['location'], 20).' +
    '; } $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; -foreach (dbFetchRows($sql) as $interface) -{ - echo("
    -
    ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 20)." -
    "); - +foreach (dbFetchRows($sql) as $interface) { + echo "
    +
    ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 20).' +
    '; } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) -{ - echo("
    -
    ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 20)." -
    "); - +foreach (dbFetchRows($sql) as $service) { + echo "
    +
    ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 20).' +
    '; } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) -{ - echo("
    -
    ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - +foreach (dbFetchRows($sql) as $peer) { + echo "
    +
    ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '" . $config['uptime_warning'] . "'"; - foreach (dbFetchRows($sql) as $device) - { - echo("
    -
    ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '".$config['uptime_warning']."'"; + foreach (dbFetchRows($sql) as $device) { + echo "
    +
    ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } } -echo(" +echo " -
    $errorboxes
    +
    $errorboxes
    -

    Recent Syslog Messages

    +

    Recent Syslog Messages

    -"); + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; -echo("
    Devices with Alerts
    Host
    Int
    Srv
    "); -foreach (dbFetchRows($sql) as $entry) -{ - include("includes/print-syslog.inc.php"); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + include 'includes/print-syslog.inc.php'; } -echo("
    "); -echo("
    +echo ''; - - "); +echo '
    + + + '; // this stuff can be customised to show whatever you want.... +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['l2tp'] .= $seperator.$interface['port_id']; + $seperator = ','; + } -if ($_SESSION['userlevel'] >= '5') -{ - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['l2tp'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['transit'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['transit'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['voip'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['voip'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + if ($ports['transit']) { + echo "', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    Internet Transit
    "."
    "; + } - if ($ports['transit']) - { - echo("', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". - "
    Internet Transit
    ". - "
    "); - } + if ($ports['l2tp']) { + echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    L2TP ADSL
    "."
    "; + } - if ($ports['l2tp']) - { - echo("', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". - "
    L2TP ADSL
    ". - "
    "); - } - - if ($ports['voip']) - { - echo("', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". - "
    VoIP to PSTN
    ". - "
    "); - } - -} + if ($ports['voip']) { + echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    VoIP to PSTN
    "."
    "; + } +}//end if // END VOSTRON - ?> diff --git a/html/pages/front/globe.php b/html/pages/front/globe.php index 75a5917c70..9884b402fa 100644 --- a/html/pages/front/globe.php +++ b/html/pages/front/globe.php @@ -4,16 +4,17 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * Custom Frontpage * @author f0o * @copyright 2014 f0o, LibreNMS @@ -25,107 +26,111 @@ ?> -
    -
    -
    -
    -
    -
    -
    -
    '; - include_once("includes/device-summary-vert.inc.php"); -echo '
    -
    -
    -
    '; - include_once("includes/front/boxes.inc.php"); -echo '
    -
    -
    -
    -
    -
    -
    '; - $device['device_id'] = '-1'; - require_once('includes/print-alerts.php'); - unset($device['device_id']); -echo '
    -
    +
    +
    +
    +
    +
    +
    +
    +
    '; + include_once("includes/device-summary-vert.inc.php"); +echo '
    +
    +
    +
    '; + include_once("includes/front/boxes.inc.php"); +echo '
    +
    +
    +
    +
    +
    +
    '; + $device['device_id'] = '-1'; + require_once('includes/print-alerts.php'); + unset($device['device_id']); +echo '
    +
    '; //From default.php - This code is not part of above license. if ($config['enable_syslog']) { -$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; -$query = mysql_query($sql); -echo('
    + $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; + $query = mysql_query($sql); + echo('
      @@ -139,29 +144,28 @@ echo('
    '); - foreach (dbFetchRows($sql) as $entry) - { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); + foreach (dbFetchRows($sql) as $entry) { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include("includes/print-syslog.inc.php"); - } - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); + include 'includes/print-syslog.inc.php'; + } + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); +} +else { -} else { + if ($_SESSION['userlevel'] == '10') { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + } + else { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = + P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; + } - if ($_SESSION['userlevel'] == '10') - { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - } else { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = - P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; - } - - $data = mysql_query($query); + $data = mysql_query($query); echo('
    @@ -177,15 +181,13 @@ echo('
    '); - foreach (dbFetchRows($query) as $entry) - { - include("includes/print-event.inc.php"); - } + foreach (dbFetchRows($query) as $entry) { + include 'includes/print-event.inc.php'; + } - echo("
    "); - echo("
    "); - echo("
    "); - echo(""); - echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); } -?> diff --git a/html/pages/front/jt.php b/html/pages/front/jt.php index 2256cf0856..cda0b49bb7 100644 --- a/html/pages/front/jt.php +++ b/html/pages/front/jt.php @@ -5,238 +5,209 @@ $nodes = array(); -$uptimesql = ""; -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $uptimesql = " AND A.attrib_value < '" . $config['uptime_warning'] . "'"; +$uptimesql = ''; +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $uptimesql = " AND A.attrib_value < '".$config['uptime_warning']."'"; } -$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql; +$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql; -foreach (dbFetchRows($sql) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = "yes"; +foreach (dbFetchRows($sql) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) -{ - if (device_permitted($device['device_id'])) { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35)." -
    "); - } +foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id'])) { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35).' +
    '; + } } if ($config['warn']['ifdown']) { - -$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; -foreach (dbFetchRows($sql) as $interface) -{ - if (port_permitted($interface['port_id'])) { - echo("
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } -} - + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; + foreach (dbFetchRows($sql) as $interface) { + if (port_permitted($interface['port_id'])) { + echo "
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } + } } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) -{ - if (device_permitted($service['device_id'])) { - echo("
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } +foreach (dbFetchRows($sql) as $service) { + if (device_permitted($service['device_id'])) { + echo "
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) -{ - if (device_permitted($peer['device_id'])) { - echo("
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - } +foreach (dbFetchRows($sql) as $peer) { + if (device_permitted($peer['device_id'])) { + echo "
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; + } } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); - } - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '".$config['uptime_warning']."' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; + foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } + } } -echo(" +echo " -
    $errorboxes
    +
    $errorboxes
    -

    Recent Syslog Messages

    +

    Recent Syslog Messages

    -"); + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo(""); -foreach (dbFetchRows($sql) as $entry) -{ - include("includes/print-syslog.inc.php"); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + include 'includes/print-syslog.inc.php'; } -echo("
    "); -echo("
    +echo ''; - - "); +echo '
    + + + '; // this stuff can be customised to show whatever you want.... +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['transit'] .= $seperator.$interface['port_id']; + $seperator = ','; + } -if ($_SESSION['userlevel'] >= '5') -{ + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['peering'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['transit'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $ports['broadband'] = '3294,3295,688,3534'; + $ports['wave_broadband'] = '827'; - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['peering'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $ports['new_broadband'] = '3659,4149,4121,4108,3676,4135'; - $ports['broadband'] = "3294,3295,688,3534"; - $ports['wave_broadband'] = "827"; + echo "
    "; - $ports['new_broadband'] = "3659,4149,4121,4108,3676,4135"; + if ($ports['peering'] && $ports['transit']) { + echo ""; + } - echo("
    "); + echo '
    '; - if ($ports['peering'] && $ports['transit']) { - echo(""); - } + echo "
    "; - echo("
    "); + if ($ports['transit']) { + echo ""; + } - echo("'; - if ($ports['peering']) { - echo(""); - } + echo "
    "; - echo("
    "); + if ($ports['broadband'] && $ports['wave_broadband'] && $ports['new_broadband']) { + echo ""; + } - echo("
    "); + echo "
    "; - if ($ports['broadband'] && $ports['wave_broadband'] && $ports['new_broadband']) { - echo(""); - } + if ($ports['broadband']) { + echo ""; + } - echo("
    "); + echo "
    "; - if ($ports['broadband']) { - echo(""); - } + if ($ports['new_broadband']) { + echo ""; + } - echo("
    "); + echo '
    '; - if ($ports['new_broadband']) { - echo(""); - } + if ($ports['wave_broadband']) { + echo ""; + } - echo("
    "); - - if ($ports['wave_broadband']) { - echo(""); - } - - echo("
    "); - -} + echo '
    '; +}//end if ?> diff --git a/html/pages/front/traffic.php b/html/pages/front/traffic.php index 5f9a8acced..6b501cf9c1 100644 --- a/html/pages/front/traffic.php +++ b/html/pages/front/traffic.php @@ -3,200 +3,172 @@ 0) -{ - $uptimesql = " AND A.attrib_value < ?"; - $param = array($config['uptime_warning']); +$nodes = array(); +$param = array(); +$uptimesql = ''; +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $uptimesql = ' AND A.attrib_value < ?'; + $param = array($config['uptime_warning']); } -foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql, $param) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = "yes"; +foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql, $param) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } -foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) -{ - if (device_permitted($device['device_id'])) { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35)." -
    "); - } +foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) { + if (device_permitted($device['device_id'])) { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35).' +
    '; + } } if ($config['warn']['ifdown']) { - -foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) -{ - if (port_permitted($interface['port_id'])) { - echo("
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } + foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) { + if (port_permitted($interface['port_id'])) { + echo "
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } + } } +foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) { + if (device_permitted($service['device_id'])) { + echo "
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } -foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) -{ - if (device_permitted($service['device_id'])) { - echo("
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } +foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) { + if (device_permitted($peer['device_id'])) { + echo "
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; + } } -foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) -{ - if (device_permitted($peer['device_id'])) { - echo("
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", array($config['uptime_warning'])) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } + } } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", array($config['uptime_warning'])) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); - } - } -} +echo " -echo(" +
    $errorboxes
    -
    $errorboxes
    +

    Recent Syslog Messages

    -

    Recent Syslog Messages

    - -"); + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo(""); -foreach (dbFetchRows($sql) as $entry) -{ - include("includes/print-syslog.inc.php"); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + include 'includes/print-syslog.inc.php'; } -echo("
    "); -echo("
    +echo ''; - - "); +echo '
    + + + '; // this stuff can be customised to show whatever you want.... +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['transit'] .= $seperator.$interface['port_id']; + $seperator = ','; + } -if ($_SESSION['userlevel'] >= '5') -{ + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['peering'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['transit'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['core'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['peering'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + echo "
    "; - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['core'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + if ($ports['peering'] && $ports['transit']) { + echo ""; + } - echo("
    "); + echo '
    '; - if ($ports['peering'] && $ports['transit']) - { - echo(""); - } + echo "
    "; - echo("
    "); + if ($ports['transit']) { + echo ""; + } - echo("
    "); + if ($ports['peering']) { + echo ""; + } - if ($ports['transit']) - { - echo(""); - } + if ($ports['core']) { + echo ""; + } - if ($ports['peering']) - { - echo(""); - } - - if ($ports['core']) - { - echo(""); - } - - echo("
    "); - -} + echo '
    '; +}//end if ?> diff --git a/html/pages/graphs.inc.php b/html/pages/graphs.inc.php index 0cc268fceb..78c6a73e09 100644 --- a/html/pages/graphs.inc.php +++ b/html/pages/graphs.inc.php @@ -4,17 +4,21 @@ unset($vars['page']); // Setup here -if($_SESSION['widescreen']) -{ - $graph_width=1700; - $thumb_width=180; -} else { - $graph_width=1075; - $thumb_width=113; +if($_SESSION['widescreen']) { + $graph_width=1700; + $thumb_width=180; +} +else { + $graph_width=1075; + $thumb_width=113; } -if (!is_numeric($vars['from'])) { $vars['from'] = $config['time']['day']; } -if (!is_numeric($vars['to'])) { $vars['to'] = $config['time']['now']; } +if (!is_numeric($vars['from'])) { + $vars['from'] = $config['time']['day']; +} +if (!is_numeric($vars['to'])) { + $vars['to'] = $config['time']['now']; +} preg_match('/^(?P[A-Za-z0-9]+)_(?P.+)/', $vars['type'], $graphtype); @@ -22,208 +26,201 @@ $type = $graphtype['type']; $subtype = $graphtype['subtype']; $id = $vars['id']; -if(is_numeric($vars['device'])) -{ - $device = device_by_id_cache($vars['device']); -} elseif(!empty($vars['device'])) { - $device = device_by_name($vars['device']); +if(is_numeric($vars['device'])) { + $device = device_by_id_cache($vars['device']); +} +elseif(!empty($vars['device'])) { + $device = device_by_name($vars['device']); } -if (is_file("includes/graphs/".$type."/auth.inc.php")) -{ - include("includes/graphs/".$type."/auth.inc.php"); +if (is_file("includes/graphs/".$type."/auth.inc.php")) { + require "includes/graphs/".$type."/auth.inc.php"; } -if (!$auth) -{ - include("includes/error-no-perm.inc.php"); -} else { - if (isset($config['graph_types'][$type][$subtype]['descr'])) - { - $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; - } else { - $title .= " :: ".ucfirst($subtype); - } +if (!$auth) { + require 'includes/error-no-perm.inc.php'; +} +else { + if (isset($config['graph_types'][$type][$subtype]['descr'])) { + $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; + } + else { + $title .= " :: ".ucfirst($subtype); + } - $graph_array = $vars; - $graph_array['height'] = "60"; - $graph_array['width'] = $thumb_width; - $graph_array['legend'] = "no"; - $graph_array['to'] = $config['time']['now']; + $graph_array = $vars; + $graph_array['height'] = "60"; + $graph_array['width'] = $thumb_width; + $graph_array['legend'] = "no"; + $graph_array['to'] = $config['time']['now']; - print_optionbar_start(); - echo($title); + print_optionbar_start(); + echo($title); - echo('
    '); - ?> + echo('
    '); +?>
    - '); +'); - print_optionbar_end(); + print_optionbar_end(); - print_optionbar_start(); + print_optionbar_start(); - $thumb_array = array('sixhour' => '6 Hours', 'day' => '24 Hours', 'twoday' => '48 Hours', 'week' => 'One Week', 'twoweek' => 'Two Weeks', - 'month' => 'One Month', 'twomonth' => 'Two Months','year' => 'One Year', 'twoyear' => 'Two Years'); + $thumb_array = array('sixhour' => '6 Hours', 'day' => '24 Hours', 'twoday' => '48 Hours', 'week' => 'One Week', 'twoweek' => 'Two Weeks', + 'month' => 'One Month', 'twomonth' => 'Two Months','year' => 'One Year', 'twoyear' => 'Two Years'); - echo(''); + echo('
    '); - foreach ($thumb_array as $period => $text) - { - $graph_array['from'] = $config['time'][$period]; + foreach ($thumb_array as $period => $text) { + $graph_array['from'] = $config['time'][$period]; - $link_array = $vars; - $link_array['from'] = $graph_array['from']; - $link_array['to'] = $graph_array['to']; - $link_array['page'] = "graphs"; - $link = generate_url($link_array); + $link_array = $vars; + $link_array['from'] = $graph_array['from']; + $link_array['to'] = $graph_array['to']; + $link_array['page'] = "graphs"; + $link = generate_url($link_array); - echo(''); + echo(''); - } + } - echo('
    '); - echo(''.$text.'
    '); - echo(''); - echo(generate_graph_tag($graph_array)); - echo(''); - echo('
    '); + echo(''.$text.'
    '); + echo(''); + echo(generate_graph_tag($graph_array)); + echo(''); + echo('
    '); + echo(''); - $graph_array = $vars; - $graph_array['height'] = "300"; - $graph_array['width'] = $graph_width; + $graph_array = $vars; + $graph_array['height'] = "300"; + $graph_array['width'] = $graph_width; - echo("
    "); + echo("
    "); - // datetime range picker + // datetime range picker ?> - "); - echo(' + echo(" +
    + "); + echo('
    - - + +
    - - + +
    -
    - '); - echo("
    "); + echo("
    "); - if ($vars['legend'] == "no") - { - echo(generate_link("Show Legend",$vars, array('page' => "graphs", 'legend' => NULL))); - } else { - echo(generate_link("Hide Legend",$vars, array('page' => "graphs", 'legend' => "no"))); - } - - // FIXME : do this properly -# if ($type == "port" && $subtype == "bits") -# { - echo(' | '); - if ($vars['previous'] == "yes") - { - echo(generate_link("Hide Previous",$vars, array('page' => "graphs", 'previous' => NULL))); - } else { - echo(generate_link("Show Previous",$vars, array('page' => "graphs", 'previous' => "yes"))); + if ($vars['legend'] == "no") { + echo(generate_link("Show Legend",$vars, array('page' => "graphs", 'legend' => NULL))); + } + else { + echo(generate_link("Hide Legend",$vars, array('page' => "graphs", 'legend' => "no"))); } -# } - echo('
    '); + // FIXME : do this properly + # if ($type == "port" && $subtype == "bits") + # { + echo(' | '); + if ($vars['previous'] == "yes") { + echo(generate_link("Hide Previous",$vars, array('page' => "graphs", 'previous' => NULL))); + } + else { + echo(generate_link("Show Previous",$vars, array('page' => "graphs", 'previous' => "yes"))); + } + # } - if ($vars['showcommand'] == "yes") - { - echo(generate_link("Hide RRD Command",$vars, array('page' => "graphs", 'showcommand' => NULL))); - } else { - echo(generate_link("Show RRD Command",$vars, array('page' => "graphs", 'showcommand' => "yes"))); - } + echo('
    '); - echo('
    '); + if ($vars['showcommand'] == "yes") { + echo(generate_link("Hide RRD Command",$vars, array('page' => "graphs", 'showcommand' => NULL))); + } + else { + echo(generate_link("Show RRD Command",$vars, array('page' => "graphs", 'showcommand' => "yes"))); + } - print_optionbar_end(); + echo('
    '); - echo generate_graph_js_state($graph_array); - - echo('
    '); - echo(generate_graph_tag($graph_array)); - echo("
    "); - - if (isset($config['graph_descr'][$vars['type']])) - { - - print_optionbar_start(); - echo('
    -
    - -
    -
    '); - echo($config['graph_descr'][$vars['type']]); print_optionbar_end(); - } - if ($vars['showcommand']) - { - $_GET = $graph_array; - $command_only = 1; + echo generate_graph_js_state($graph_array); - include("includes/graphs/graph.inc.php"); - } + echo('
    '); + echo(generate_graph_tag($graph_array)); + echo("
    "); + + if (isset($config['graph_descr'][$vars['type']])) { + + print_optionbar_start(); + echo('
    +
    + +
    +
    '); + echo($config['graph_descr'][$vars['type']]); + print_optionbar_end(); + } + + if ($vars['showcommand']) { + $_GET = $graph_array; + $command_only = 1; + + require 'includes/graphs/graph.inc.php'; + } } - -?> diff --git a/html/pages/health.inc.php b/html/pages/health.inc.php index 3b06d4db6b..eb13def9b7 100644 --- a/html/pages/health.inc.php +++ b/html/pages/health.inc.php @@ -30,8 +30,12 @@ $type_text['toner'] = "Toner"; $type_text['dbm'] = "dBm"; $type_text['load'] = "Load"; -if (!$vars['metric']) { $vars['metric'] = "processor"; } -if (!$vars['view']) { $vars['view'] = "detail"; } +if (!$vars['metric']) { + $vars['metric'] = "processor"; +} +if (!$vars['view']) { + $vars['view'] = "detail"; +} $link_array = array('page' => 'health'); @@ -42,48 +46,44 @@ print_optionbar_start('', ''); echo('Health » '); $sep = ""; -foreach ($datas as $texttype) -{ - $metric = strtolower($texttype); - echo($sep); - if ($vars['metric'] == $metric) - { - echo(""); - } +foreach ($datas as $texttype) { + $metric = strtolower($texttype); + echo($sep); + if ($vars['metric'] == $metric) { + echo(""); + } - echo(generate_link($type_text[$metric],$link_array,array('metric'=> $metric, 'view' => $vars['view']))); + echo(generate_link($type_text[$metric],$link_array,array('metric'=> $metric, 'view' => $vars['view']))); - if ($vars['metric'] == $metric) { echo(""); } + if ($vars['metric'] == $metric) { + echo(""); + } - $sep = ' | '; + $sep = ' | '; } unset ($sep); echo('
    '); -if ($vars['view'] == "graphs") -{ - echo(''); +if ($vars['view'] == "graphs") { + echo(''); } echo(generate_link("Graphs",$link_array,array('metric'=> $vars['metric'], 'view' => "graphs"))); -if ($vars['view'] == "graphs") -{ - echo(''); +if ($vars['view'] == "graphs") { + echo(''); } echo(' | '); -if ($vars['view'] != "graphs") -{ - echo(''); +if ($vars['view'] != "graphs") { + echo(''); } echo(generate_link("No Graphs",$link_array,array('metric'=> $vars['metric'], 'view' => "detail"))); -if ($vars['view'] != "graphs") -{ - echo(''); +if ($vars['view'] != "graphs") { + echo(''); } echo('
    '); @@ -91,16 +91,14 @@ echo('
    '); print_optionbar_end(); if (in_array($vars['metric'],array_keys($used_sensors)) - || $vars['metric'] == 'processor' - || $vars['metric'] == 'storage' - || $vars['metric'] == 'toner' - || $vars['metric'] == 'mempool') -{ - include('pages/health/'.$vars['metric'].'.inc.php'); + || $vars['metric'] == 'processor' + || $vars['metric'] == 'storage' + || $vars['metric'] == 'toner' + || $vars['metric'] == 'mempool') { + include('pages/health/'.$vars['metric'].'.inc.php'); } -else -{ - echo("No sensors of type " . $vars['metric'] . " found."); +else { + echo("No sensors of type " . $vars['metric'] . " found."); } ?> diff --git a/html/pages/health/charge.inc.php b/html/pages/health/charge.inc.php index 867b50f9e8..3838d0e790 100644 --- a/html/pages/health/charge.inc.php +++ b/html/pages/health/charge.inc.php @@ -4,6 +4,4 @@ $graph_type = "sensor_charge"; $unit = "%"; $class = "charge"; -include("pages/health/sensors.inc.php"); - -?> +require 'pages/health/sensors.inc.php'; diff --git a/html/pages/health/load.inc.php b/html/pages/health/load.inc.php index d9257519d3..f506e3ca1d 100644 --- a/html/pages/health/load.inc.php +++ b/html/pages/health/load.inc.php @@ -1,9 +1,7 @@ +require 'pages/health/sensors.inc.php'; diff --git a/html/pages/health/sensors.inc.php b/html/pages/health/sensors.inc.php index 02224d485c..52828b9c19 100644 --- a/html/pages/health/sensors.inc.php +++ b/html/pages/health/sensors.inc.php @@ -1,19 +1,18 @@ = '5') -{ - $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr"; - $param = array(); -} else { - $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = ? ORDER BY D.hostname, S.sensor_descr"; - $param = array($_SESSION['user_id']); +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr"; + $param = array(); +} +else { + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = ? ORDER BY D.hostname, S.sensor_descr"; + $param = array($_SESSION['user_id']); } -echo(''); +echo '
    '; -echo(' +echo ' @@ -21,99 +20,102 @@ echo(' - '); + '; -foreach (dbFetchRows($sql, $param) as $sensor) -{ +foreach (dbFetchRows($sql, $param) as $sensor) { + if ($config['memcached']['enable'] === true) { + $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); + if ($debug) { + echo 'Memcached['.'sensor-'.$sensor['sensor_id'].'-value'.'='.$sensor['sensor_current'].']'; + } + } - if ($config['memcached']['enable'] === TRUE) - { - $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); - if($debug) { echo("Memcached[".'sensor-'.$sensor['sensor_id'].'-value'."=".$sensor['sensor_current']."]"); } - } - - if (empty($sensor['sensor_current'])) - { - $sensor['sensor_current'] = "NaN"; - } else { - if ($sensor['sensor_current'] >= $sensor['sensor_limit']) { $alert = 'alert'; } else { $alert = ""; } - } + if (empty($sensor['sensor_current'])) { + $sensor['sensor_current'] = 'NaN'; + } + else { + if ($sensor['sensor_current'] >= $sensor['sensor_limit']) { + $alert = 'alert'; + } + else { + $alert = ''; + } + } // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? // FIXME - DUPLICATED IN device/overview/sensors - - $graph_colour = str_replace("#", "", $row_colour); + $graph_colour = str_replace('#', '', $row_colour); $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = $graph_type; $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; + $link_array = $graph_array; + $link_array['page'] = 'graphs'; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link_graph = generate_url($link_array); - $link = generate_url(array("page" => "device", "device" => $sensor['device_id'], "tab" => "health", "metric" => $sensor['sensor_class'])); + $link = generate_url(array('page' => 'device', 'device' => $sensor['device_id'], 'tab' => 'health', 'metric' => $sensor['sensor_class'])); - $overlib_content = '

    '.$device['hostname']." - ".$sensor['sensor_descr']."

    "; - foreach (array('day','week','month','year') as $period) - { - $graph_array['from'] = $config['time'][$period]; - $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); + $overlib_content = '

    '.$device['hostname'].' - '.$sensor['sensor_descr'].'

    '; + foreach (array('day', 'week', 'month', 'year') as $period) { + $graph_array['from'] = $config['time'][$period]; + $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); } - $overlib_content .= "
    "; - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $overlib_content .= '
    '; + + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. $graph_array['from'] = $config['time']['day']; - $sensor_minigraph = generate_graph_tag($graph_array); + $sensor_minigraph = generate_graph_tag($graph_array); $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); - echo(' - - + echo ' + + - - - + + + - '); + '; - if ($vars['view'] == "graphs") - { - echo(""); - } # endif graphs -} + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo ''; + } //end if +}//end foreach -echo("
    Device Sensor
    Current Range limit Notes
    ' . generate_device_link($sensor) . ''.overlib_link($link, $sensor['sensor_descr'],$overlib_content).'
    '.generate_device_link($sensor).''.overlib_link($link, $sensor['sensor_descr'], $overlib_content).' '.overlib_link($link_graph, $sensor_minigraph, $overlib_content).' '.$alert.'' . $sensor['sensor_current'] . $unit . '' . round($sensor['sensor_limit_low'],2) . $unit . ' - ' . round($sensor['sensor_limit'],2) . $unit . '' . (isset($sensor['sensor_notes']) ? $sensor['sensor_notes'] : '') . ''.$sensor['sensor_current'].$unit.''.round($sensor['sensor_limit_low'], 2).$unit.' - '.round($sensor['sensor_limit'], 2).$unit.''.(isset($sensor['sensor_notes']) ? $sensor['sensor_notes'] : '').'
    "); + if ($vars['view'] == 'graphs') { + echo "
    "; - $daily_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=211&height=100"; - $daily_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=400&height=150"; + $daily_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=211&height=100'; + $daily_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=400&height=150'; - $weekly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['week']."&to=".$config['time']['now']."&width=211&height=100"; - $weekly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['week']."&to=".$config['time']['now']."&width=400&height=150"; + $weekly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=211&height=100'; + $weekly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=400&height=150'; - $monthly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['month']."&to=".$config['time']['now']."&width=211&height=100"; - $monthly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['month']."&to=".$config['time']['now']."&width=400&height=150"; + $monthly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=211&height=100'; + $monthly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=400&height=150'; - $yearly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['year']."&to=".$config['time']['now']."&width=211&height=100"; - $yearly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['year']."&to=".$config['time']['now']."&width=400&height=150"; + $yearly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=211&height=100'; + $yearly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=400&height=150'; - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("
    "); - -?> +echo ''; diff --git a/html/pages/iftype.inc.php b/html/pages/iftype.inc.php index f4349111cd..8a6d20201b 100644 --- a/html/pages/iftype.inc.php +++ b/html/pages/iftype.inc.php @@ -9,92 +9,102 @@ - Total Graph for ports of type : ".$types."
    "); - -if ($if_list) -{ - $graph_type = "multiport_bits_separate"; - $port['port_id'] = $if_list; - - include("includes/print-interface-graphs.inc.php"); - - echo(""); - - foreach ($ports as $port) - { - $done = "yes"; - unset($class); - $port['ifAlias'] = str_ireplace($type . ": ", "", $port['ifAlias']); - $port['ifAlias'] = str_ireplace("[PNI]", "Private", $port['ifAlias']); - $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); - if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg = "#ffffff"; } - echo(" - " . generate_port_link($port,$port['port_descr_descr']) . "
    - ".generate_device_link($port)." ".generate_port_link($port)." - ".generate_port_link($port, makeshortif($port['ifDescr']))." - ".$port['port_descr_speed']." - ".$port['port_descr_circuit']." - ".$port['port_descr_notes']." - - - MAC Accounting"); - } - - echo('
    '); - - if (file_exists($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . $port['ifIndex'] . ".rrd")) - { - $graph_type = "port_bits"; - - include("includes/print-interface-graphs.inc.php"); - } - - echo(""); - } - +$types_array = explode(',', $vars['type']); +for ($i = 0; $i < count($types_array); +$i++) { + $types_array[$i] = ucfirst($types_array[$i]); } -else -{ - echo("None found."); + +$types = implode(' + ', $types_array); + +echo " + Total Graph for ports of type : ".$types.'
    '; + +if ($if_list) { + $graph_type = 'multiport_bits_separate'; + $port['port_id'] = $if_list; + + include 'includes/print-interface-graphs.inc.php'; + + echo ''; + + foreach ($ports as $port) { + $done = 'yes'; + unset($class); + $port['ifAlias'] = str_ireplace($type.': ', '', $port['ifAlias']); + $port['ifAlias'] = str_ireplace('[PNI]', 'Private', $port['ifAlias']); + $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); + if ($bg == '#ffffff') { + $bg = '#e5e5e5'; + } + else { + $bg = '#ffffff'; + } + + echo " + ".generate_port_link($port, $port['port_descr_descr'])."
    + ".generate_device_link($port).' '.generate_port_link($port).' + '.generate_port_link($port, makeshortif($port['ifDescr'])).' + '.$port['port_descr_speed'].' + '.$port['port_descr_circuit'].' + '.$port['port_descr_notes']." + + + MAC Accounting"; + } + + echo '
    '; + + if (file_exists($config['rrd_dir'].'/'.$port['hostname'].'/port-'.$port['ifIndex'].'.rrd')) { + $graph_type = 'port_bits'; + + include 'includes/print-interface-graphs.inc.php'; + } + + echo ''; + } +} +else { + echo 'None found.'; } ?> diff --git a/html/pages/inventory.inc.php b/html/pages/inventory.inc.php index e53daab965..7fc461e4aa 100644 --- a/html/pages/inventory.inc.php +++ b/html/pages/inventory.inc.php @@ -1,6 +1,6 @@ @@ -29,46 +29,53 @@ var grid = $("#inventory").bootgrid({ header: "
    "+ "
    "+ "
    "+ - "\" placeholder=\"Description\" class=\"form-control input-sm\" />"+ + "\" placeholder=\"Description\" class=\"form-control input-sm\" />"+ "
    "+ "
    "+ " Part No "+ ""+ "
    "+ "
    "+ - "\" placeholder=\"Serial\" class=\"form-control input-sm\"/>"+ + "\" placeholder=\"Serial\" class=\"form-control input-sm\"/>"+ "
    "+ "
    "+ " Device "+ ""+ "
    "+ "
    "+ - "\" placeholder=\"Description\" class=\"form-control input-sm\"/>"+ + " +\" placeholder=\"Description\" class=\"form-control input-sm\"/>"+ "
    "+ ""+ "
    "+ diff --git a/html/pages/locations.inc.php b/html/pages/locations.inc.php index 93dffa0e36..bbe6adcf99 100644 --- a/html/pages/locations.inc.php +++ b/html/pages/locations.inc.php @@ -1,88 +1,92 @@ Locations » '); +echo 'Locations » '; -$menu_options = array('basic' => 'Basic', - 'traffic' => 'Traffic'); +$menu_options = array( + 'basic' => 'Basic', + 'traffic' => 'Traffic', +); -if (!$vars['view']) { $vars['view'] = "basic"; } +if (!$vars['view']) { + $vars['view'] = 'basic'; +} -$sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['view'] == $option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['view'] == $option) - { - echo(""); - } - $sep = " | "; +$sep = ''; +foreach ($menu_options as $option => $text) { + echo $sep; + if ($vars['view'] == $option) { + echo ""; + } + + echo ''.$text.''; + if ($vars['view'] == $option) { + echo ''; + } + + $sep = ' | '; } unset($sep); print_optionbar_end(); -echo(''); +echo '
    '; -foreach (getlocations() as $location) -{ - if ($_SESSION['userlevel'] >= '10') - { - $num = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ?", array($location)); - $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'network'", array($location)); - $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'server'", array($location)); - $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'firewall'", array($location)); - $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND status = '0'", array($location)); - } else { - $num = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ?", array($_SESSION['user_id'], $location)); - $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND D.type = 'network'", array($_SESSION['user_id'], $location)); - $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'server'", array($_SESSION['user_id'], $location)); - $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'firewall'", array($_SESSION['user_id'], $location)); - $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND status = '0'", array($_SESSION['user_id'], $location)); - } - - if ($hostalerts) { $alert = 'alert'; } else { $alert = ""; } - - if ($location != "") - { - echo(' - - - - - - - - '); - - if ($vars['view'] == "traffic") - { - echo('"); +foreach (getlocations() as $location) { + if ($_SESSION['userlevel'] >= '10') { + $num = dbFetchCell('SELECT COUNT(device_id) FROM devices WHERE location = ?', array($location)); + $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'network'", array($location)); + $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'server'", array($location)); + $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'firewall'", array($location)); + $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND status = '0'", array($location)); + } + else { + $num = dbFetchCell('SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ?', array($_SESSION['user_id'], $location)); + $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND D.type = 'network'", array($_SESSION['user_id'], $location)); + $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'server'", array($_SESSION['user_id'], $location)); + $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'firewall'", array($_SESSION['user_id'], $location)); + $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND status = '0'", array($_SESSION['user_id'], $location)); } - $done = "yes"; - } -} -echo("
    ' . $location . '' . $alert . '' . $num . ' devices' . $net . ' network' . $srv . ' servers' . $fwl . ' firewalls
    '); - - $graph_array['type'] = "location_bits"; - $graph_array['height'] = "100"; - $graph_array['width'] = "220"; - $graph_array['to'] = $config['time']['now']; - $graph_array['legend'] = "no"; - $graph_array['id'] = $location; - - include("includes/print-graphrow.inc.php"); - - echo("
    "); + if ($hostalerts) { + $alert = 'alert'; + } + else { + $alert = ''; + } -?> + if ($location != '') { + echo ' + '.$location.' + '.$alert.' + '.$num.' devices + '.$net.' network + '.$srv.' servers + '.$fwl.' firewalls + + '; + + if ($vars['view'] == 'traffic') { + echo ''; + + $graph_array['type'] = 'location_bits'; + $graph_array['height'] = '100'; + $graph_array['width'] = '220'; + $graph_array['to'] = $config['time']['now']; + $graph_array['legend'] = 'no'; + $graph_array['id'] = $location; + + include 'includes/print-graphrow.inc.php'; + + echo ''; + } + + $done = 'yes'; + }//end if +}//end foreach + +echo ''; diff --git a/html/pages/logon.inc.php b/html/pages/logon.inc.php index e9819b1b01..a8a156574d 100644 --- a/html/pages/logon.inc.php +++ b/html/pages/logon.inc.php @@ -1,7 +1,8 @@
    @@ -32,14 +33,12 @@ if( $config['twofactor'] && isset($twofactorform) ) {
    'error','message'=>$auth_message,'title'=>'Login error'); } ?>
    diff --git a/html/pages/map.inc.php b/html/pages/map.inc.php index 0fa1cbb5f7..115c0600c3 100644 --- a/html/pages/map.inc.php +++ b/html/pages/map.inc.php @@ -10,6 +10,5 @@ * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ -$pagetitle[] = "Map"; -require_once "includes/print-map.inc.php"; -?> +$pagetitle[] = 'Map'; +require_once 'includes/print-map.inc.php'; diff --git a/html/pages/packages.inc.php b/html/pages/packages.inc.php index c3e79c8cf6..ab26fd00a9 100644 --- a/html/pages/packages.inc.php +++ b/html/pages/packages.inc.php @@ -2,8 +2,7 @@ foreach ($vars as $var => $value) { if ($value != '') { - switch ($var) - { + switch ($var) { case 'name': $where .= " AND `$var` = ?"; $param[] = $value; @@ -26,8 +25,7 @@ foreach (dbFetchRows("SELECT * FROM `packages` WHERE 1 $where GROUP BY `name`", foreach ($entry['blah'] as $version => $bleu) { $content = '
    '; - foreach ($bleu as $build => $bloo) - { + foreach ($bleu as $build => $bloo) { if ($build) { $dbuild = '-'.$build; } @@ -36,8 +34,7 @@ foreach (dbFetchRows("SELECT * FROM `packages` WHERE 1 $where GROUP BY `name`", } $content .= '
    '.$version.$dbuild.''; - foreach ($bloo as $device_id => $no) - { + foreach ($bloo as $device_id => $no) { $this_device = device_by_id_cache($device_id); $content .= ''.$this_device['hostname'].' '; } diff --git a/html/pages/plugin.inc.php b/html/pages/plugin.inc.php index daec96f46b..1f718acff2 100644 --- a/html/pages/plugin.inc.php +++ b/html/pages/plugin.inc.php @@ -1,24 +1,18 @@ 'plugin'); +$link_array = array('page' => 'plugin'); -$pagetitle[] = "Plugin"; +$pagetitle[] = 'Plugin'; -if ($vars['view'] == "admin") -{ - include_once('pages/plugin/admin.inc.php'); +if ($vars['view'] == 'admin') { + include_once 'pages/plugin/admin.inc.php'; } -else -{ - $plugin = dbFetchRow("SELECT `plugin_name` FROM `plugins` WHERE `plugin_name` = '".$vars['p']."' AND `plugin_active`='1'"); - if(!empty($plugin)) - { - require('plugins/'.$plugin['plugin_name'].'/'.$plugin['plugin_name'].'.inc.php'); - } - else - { - print_error( "This plugin is either disabled or not available." ); - } +else { + $plugin = dbFetchRow("SELECT `plugin_name` FROM `plugins` WHERE `plugin_name` = '".$vars['p']."' AND `plugin_active`='1'"); + if (!empty($plugin)) { + include 'plugins/'.$plugin['plugin_name'].'/'.$plugin['plugin_name'].'.inc.php'; + } + else { + print_error('This plugin is either disabled or not available.'); + } } - -?> diff --git a/html/pages/plugin/admin.inc.php b/html/pages/plugin/admin.inc.php index 1773d641d8..e20bec1b64 100644 --- a/html/pages/plugin/admin.inc.php +++ b/html/pages/plugin/admin.inc.php @@ -1,33 +1,26 @@ = '10') -{ - - // Scan for new plugins and add to the database - $new_plugins = scan_new_plugins(); +if ($_SESSION['userlevel'] >= '10') { + // Scan for new plugins and add to the database + $new_plugins = scan_new_plugins(); - // Check if we have to toggle enabled / disable a particular module - $plugin_id = $_POST['plugin_id']; - $plugin_active = $_POST['plugin_active']; - if(is_numeric($plugin_id) && is_numeric($plugin_active)) - { - if( $plugin_active == '0') - { - $plugin_active = 1; - } - elseif( $plugin_active == '1') - { - $plugin_active = 0; - } - else - { - $plugin_active = 0; - } + // Check if we have to toggle enabled / disable a particular module + $plugin_id = $_POST['plugin_id']; + $plugin_active = $_POST['plugin_active']; + if (is_numeric($plugin_id) && is_numeric($plugin_active)) { + if ($plugin_active == '0') { + $plugin_active = 1; + } + else if ($plugin_active == '1') { + $plugin_active = 0; + } + else { + $plugin_active = 0; + } - if(dbUpdate(array('plugin_active' => $plugin_active), 'plugins', '`plugin_id` = ?', array($plugin_id))) - { - echo(' + if (dbUpdate(array('plugin_active' => $plugin_active), 'plugins', '`plugin_id` = ?', array($plugin_id))) { + echo ' -'); - } - - } +'; + } + }//end if ?> @@ -49,14 +41,13 @@ $.ajax({ System plugins
    0) - { - echo('
    +if ($new_plugins > 0) { + echo '
    - We have found ' . $new_plugins . ' new plugins that need to be configured and enabled + We have found '.$new_plugins.' new plugins that need to be configured and enabled
    -
    '); - } +
    '; +} ?> @@ -65,24 +56,21 @@ $.ajax({ + echo ' - '); - } - + '; +}//end foreach ?>
    - '. $plugins['plugin_name'] . ' + '.$plugins['plugin_name'].' @@ -91,18 +79,14 @@ $.ajax({
    +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/poll-log.inc.php b/html/pages/poll-log.inc.php index 3abdf05a8e..91ef8132e2 100644 --- a/html/pages/poll-log.inc.php +++ b/html/pages/poll-log.inc.php @@ -1,5 +1,5 @@ diff --git a/html/pages/pollers.inc.php b/html/pages/pollers.inc.php index de85c2344c..3fef3d931c 100644 --- a/html/pages/pollers.inc.php +++ b/html/pages/pollers.inc.php @@ -12,25 +12,32 @@ * the source code distribution for details. */ -$no_refresh = TRUE; +$no_refresh = true; -echo(''; if (isset($vars['tab'])) { - require_once "pages/pollers/".mres($vars['tab']).".inc.php"; + include_once 'pages/pollers/'.mres($vars['tab']).'.inc.php'; } diff --git a/html/pages/pollers/groups.inc.php b/html/pages/pollers/groups.inc.php index 50019dfc26..a914650ae2 100644 --- a/html/pages/pollers/groups.inc.php +++ b/html/pages/pollers/groups.inc.php @@ -12,7 +12,7 @@ * the source code distribution for details. */ -require_once "includes/modal/poller_groups.inc.php"; +require_once 'includes/modal/poller_groups.inc.php'; ?>
    @@ -28,18 +28,17 @@ require_once "includes/modal/poller_groups.inc.php"; + echo ' + -'); +'; } ?> diff --git a/html/pages/pollers/pollers.inc.php b/html/pages/pollers/pollers.inc.php index c5e0eb2799..f948d3a8b1 100644 --- a/html/pages/pollers/pollers.inc.php +++ b/html/pages/pollers/pollers.inc.php @@ -24,26 +24,28 @@ = 300) { $row_class = 'danger'; - } elseif ($old >= 280 && $old < 300) { + } + else if ($old >= 280 && $old < 300) { $row_class = 'warning'; - } else { + } + else { $row_class = 'success'; } - echo(' + + echo ' -'); +'; } ?> diff --git a/html/pages/ports.inc.php b/html/pages/ports.inc.php index 8ff1f7d344..edeea9fbef 100644 --- a/html/pages/ports.inc.php +++ b/html/pages/ports.inc.php @@ -4,29 +4,27 @@ $pagetitle[] = "Ports"; // Set Defaults here -if(!isset($vars['format'])) { $vars['format'] = "list_basic"; } +if(!isset($vars['format'])) { + $vars['format'] = "list_basic"; +} print_optionbar_start(); echo('Lists » '); -$menu_options = array('basic' => 'Basic', - 'detail' => 'Detail'); +$menu_options = array('basic' => 'Basic', 'detail' => 'Detail'); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == "list_".$option) { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == "list_".$option) { + echo(""); + } + $sep = " | "; } ?> @@ -37,24 +35,21 @@ foreach ($menu_options as $option => $text) 'Bits', - 'upkts' => 'Unicast Packets', - 'nupkts' => 'Non-Unicast Packets', - 'errors' => 'Errors'); + 'upkts' => 'Unicast Packets', + 'nupkts' => 'Non-Unicast Packets', + 'errors' => 'Errors'); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == 'graph_'.$option) - { - echo(''); - } - echo('' . $text . ''); - if ($vars['format'] == 'graph_'.$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == 'graph_'.$option) { + echo(''); + } + echo('' . $text . ''); + if ($vars['format'] == 'graph_'.$option) { + echo(""); + } + $sep = " | "; } echo('
    '); @@ -64,29 +59,28 @@ echo('
    '); Update URL | '')).'">Search'); - } else { +} +else { echo('Search'); - } +} - echo(" | "); +echo(" | "); - if (isset($vars['bare']) && $vars['bare'] == "yes") - { +if (isset($vars['bare']) && $vars['bare'] == "yes") { echo('Header'); - } else { +} +else { echo('Header'); - } +} echo('
    '); print_optionbar_end(); print_optionbar_start(); -if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['searchbar'])) -{ +if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['searchbar'])) { ?>
    @@ -95,67 +89,66 @@ if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars[' = 5) -{ - $results = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`"); -} -else -{ - $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); -} -foreach ($results as $data) -{ - echo(' "); -} + if($_SESSION['userlevel'] >= 5) { + $results = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`"); + } + else { + $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); + } + foreach ($results as $data) { + echo(' "); + } -if($_SESSION['userlevel'] < 5) -{ - $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); -} -else -{ - $results = array(); -} -foreach ($results as $data) -{ - echo(' "); -} + if($_SESSION['userlevel'] < 5) { + $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); + } + else { + $results = array(); + } + foreach ($results as $data) { + echo(' "); + } ?> - placeholder="Hostname" /> + placeholder="Hostname" />
    @@ -164,97 +157,100 @@ foreach (dbFetchRows($sql,$param) as $data) ".$data['ifType'].""); - } -} + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `ifType` FROM `ports` GROUP BY `ifType` ORDER BY `ifType`"; + } + else { + $sql = "SELECT `ifType` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` GROUP BY `ifType` ORDER BY `ifType`"; + $param[] = array($_SESSION['user_id'],$_SESSION['user_id']); + } + foreach (dbFetchRows($sql,$param) as $data) { + if ($data['ifType']) { + echo(' "); + } + } ?>
    - placeholder="Port Description"/> + placeholder="Port Description"/>
    - > + > - > + > - > + >
    @@ -266,95 +262,98 @@ foreach ($sorts as $sort => $sort_text)
    '.$group['id'].' '.$group['group_name'].' '.$group['descr'].'
    '.$poller['poller_name'].' '.$poller['devices'].' '.$poller['time_taken'].' Seconds '.$poller['last_polled'].'
    - $value) -{ - if ($value != "") - { - switch ($var) - { - case 'hostname': - $where .= " AND D.hostname LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'location': - $where .= " AND D.location LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'device_id': - $where .= " AND D.device_id = ?"; - $param[] = $value; - break; - case 'deleted': - if ($value == 1) { - $where .= " AND `I`.`deleted` = 1"; - $ignore_filter = 1; +foreach ($vars as $var => $value) { + if ($value != "") { + switch ($var) { + case 'hostname': + $where .= " AND D.hostname LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'location': + $where .= " AND D.location LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'device_id': + $where .= " AND D.device_id = ?"; + $param[] = $value; + break; + case 'deleted': + if ($value == 1) { + $where .= " AND `I`.`deleted` = 1"; + $ignore_filter = 1; + } + break; + case 'ignore': + if ($value == 1) { + $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; + $ignore_filter = 1; + } + break; + case 'disabled': + if ($value == 1) { + $where .= " AND `I`.`disabled` = 1 AND `I`.`deleted` = 0"; + $disabled_filter = 1; + } + break; + case 'ifSpeed': + if (is_numeric($value)) { + $where .= " AND I.$var = ?"; + $param[] = $value; + } + break; + case 'ifType': + $where .= " AND I.$var = ?"; + $param[] = $value; + break; + case 'ifAlias': + case 'port_descr_type': + $where .= " AND I.$var LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'errors': + if ($value == 1) { + $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; + } + break; + case 'state': + if ($value == "down") { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; + $param[] = "up"; + $param[] = "down"; + } + elseif($value == "up") { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; + $param[] = "up"; + $param[] = "up"; + } + elseif($value == "admindown") { + $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; + $param[] = "down"; + } + break; } - break; - case 'ignore': - if ($value == 1) { - $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; - $ignore_filter = 1; - } - break; - case 'disabled': - if ($value == 1) { - $where .= " AND `I`.`disabled` = 1 AND `I`.`deleted` = 0"; - $disabled_filter = 1; - } - break; - case 'ifSpeed': - if (is_numeric($value)) - { - $where .= " AND I.$var = ?"; - $param[] = $value; - } - break; - case 'ifType': - $where .= " AND I.$var = ?"; - $param[] = $value; - break; - case 'ifAlias': - case 'port_descr_type': - $where .= " AND I.$var LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'errors': - if ($value == 1) - { - $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; - } - break; - case 'state': - if ($value == "down") - { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; - $param[] = "up"; - $param[] = "down"; - } elseif($value == "up") { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; - $param[] = "up"; - $param[] = "up"; - } elseif($value == "admindown") { - $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; - $param[] = "down"; - } - break; } - } } if ($ignore_filter == 0 && $disabled_filter == 0) { @@ -369,49 +368,47 @@ list($format, $subformat) = explode("_", $vars['format']); $ports = dbFetchRows($query, $param); -switch ($vars['sort']) -{ - case 'traffic': - $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); - break; - case 'traffic_in': - $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); - break; - case 'traffic_out': - $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); - break; - case 'packets': - $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); - break; - case 'packets_in': - $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); - break; - case 'packets_out': - $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); - break; - case 'errors': - $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); - break; - case 'speed': - $ports = array_sort($ports, 'ifSpeed', SORT_DESC); - break; - case 'port': - $ports = array_sort($ports, 'ifDescr', SORT_ASC); - break; - case 'media': - $ports = array_sort($ports, 'ifType', SORT_ASC); - break; - case 'descr': - $ports = array_sort($ports, 'ifAlias', SORT_ASC); - break; - case 'device': - default: - $ports = array_sort($ports, 'hostname', SORT_ASC); +switch ($vars['sort']) { + case 'traffic': + $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); + break; + case 'traffic_in': + $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); + break; + case 'traffic_out': + $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); + break; + case 'packets': + $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); + break; + case 'packets_in': + $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); + break; + case 'packets_out': + $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); + break; + case 'errors': + $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); + break; + case 'speed': + $ports = array_sort($ports, 'ifSpeed', SORT_DESC); + break; + case 'port': + $ports = array_sort($ports, 'ifDescr', SORT_ASC); + break; + case 'media': + $ports = array_sort($ports, 'ifType', SORT_ASC); + break; + case 'descr': + $ports = array_sort($ports, 'ifAlias', SORT_ASC); + break; + case 'device': + default: + $ports = array_sort($ports, 'hostname', SORT_ASC); } -if(file_exists('pages/ports/'.$format.'.inc.php')) -{ - include('pages/ports/'.$format.'.inc.php'); +if(file_exists('pages/ports/'.$format.'.inc.php')) { + require 'pages/ports/'.$format.'.inc.php'; } ?> diff --git a/html/pages/ports/list.inc.php b/html/pages/ports/list.inc.php index 8ae9c9df36..71f52e6180 100644 --- a/html/pages/ports/list.inc.php +++ b/html/pages/ports/list.inc.php @@ -3,68 +3,75 @@ '); +echo ''; -$cols = array('device' => 'Device', - 'port' => 'Port', - 'speed' => 'Speed', - 'traffic_in' => 'Down', - 'traffic_out' => 'Up', - 'media' => 'Media', - 'descr' => 'Description' ); +$cols = array( + 'device' => 'Device', + 'port' => 'Port', + 'speed' => 'Speed', + 'traffic_in' => 'Down', + 'traffic_out' => 'Up', + 'media' => 'Media', + 'descr' => 'Description', +); -foreach ($cols as $sort => $col) -{ - if (isset($vars['sort']) && $vars['sort'] == $sort) - { - echo(''.$col.' *'); - } else { - echo(''.$col.''); - } +foreach ($cols as $sort => $col) { + if (isset($vars['sort']) && $vars['sort'] == $sort) { + echo ''.$col.' *'; + } + else { + echo ''.$col.''; + } } -echo(" "); +echo ' '; -$ports_disabled = 0; $ports_down = 0; $ports_up = 0; $ports_total = 0; +$ports_disabled = 0; +$ports_down = 0; +$ports_up = 0; +$ports_total = 0; -foreach ($ports as $port) -{ +foreach ($ports as $port) { + if (port_permitted($port['port_id'], $port['device_id'])) { + if ($port['ifAdminStatus'] == 'down') { + $ports_disabled++; + } + else if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'down') { + $ports_down++; + } + else if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') { + $ports_up++; + } - if (port_permitted($port['port_id'], $port['device_id'])) - { + $ports_total++; - if ($port['ifAdminStatus'] == "down") { $ports_disabled++; - } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus']== "down") { $ports_down++; - } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus']== "up") { $ports_up++; } - $ports_total++; + $speed = humanspeed($port['ifSpeed']); + $type = humanmedia($port['ifType']); + $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); - $speed = humanspeed($port['ifSpeed']); - $type = humanmedia($port['ifType']); - $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); + if ((isset($port['in_errors']) && $port['in_errors'] > 0) || (isset($ports['out_errors']) && $port['out_errors'] > 0)) { + $error_img = generate_port_link($port, "Interface Errors", errors); + } + else { + $error_img = ''; + } - if ((isset($port['in_errors']) && $port['in_errors'] > 0) || (isset($ports['out_errors']) && $port['out_errors'] > 0)) - { - $error_img = generate_port_link($port,"Interface Errors",errors); - } else { $error_img = ""; } + $port['in_rate'] = formatRates(($port['ifInOctets_rate'] * 8)); + $port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8)); - $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); - $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); + $port = ifLabel($port, $device); + echo " + ".generate_device_link($port, shorthost($port['hostname'], '20'))." + ".fixIfName($port['label'])." $error_img + $speed + ".$port['in_rate'].' + '.$port['out_rate']." + $type + ".$port['ifAlias']." + \n"; + }//end if +}//end foreach - $port = ifLabel($port, $device); - echo(" - ".generate_device_link($port, shorthost($port['hostname'], "20"))." - ".fixIfName($port['label'])." $error_img - $speed - ".$port['in_rate']." - ".$port['out_rate']." - $type - " . $port['ifAlias'] . " - \n"); - } -} - -echo(''); -echo("Matched Ports: $ports_total ( Up $ports_up | Down $ports_down | Disabled $ports_disabled )"); -echo(''); - -?> +echo ''; +echo "Matched Ports: $ports_total ( Up $ports_up | Down $ports_down | Disabled $ports_disabled )"; +echo ''; diff --git a/html/pages/preferences.inc.php b/html/pages/preferences.inc.php index f4815df24e..ca2f798352 100644 --- a/html/pages/preferences.inc.php +++ b/html/pages/preferences.inc.php @@ -1,48 +1,41 @@ User Preferences"); +echo '

    User Preferences

    '; if ($_SESSION['userlevel'] == 11) { - demo_account(); - -} else { - -if ($_POST['action'] == "changepass") -{ - if (authenticate($_SESSION['username'],$_POST['old_pass'])) - { - if ($_POST['new_pass'] == "" || $_POST['new_pass2'] == "") - { - $changepass_message = "Password must not be blank."; - } - elseif ($_POST['new_pass'] == $_POST['new_pass2']) - { - changepassword($_SESSION['username'],$_POST['new_pass']); - $changepass_message = "Password Changed."; - } - else - { - $changepass_message = "Passwords don't match."; - } - } else { - $changepass_message = "Incorrect password"; - } } +else { + if ($_POST['action'] == 'changepass') { + if (authenticate($_SESSION['username'], $_POST['old_pass'])) { + if ($_POST['new_pass'] == '' || $_POST['new_pass2'] == '') { + $changepass_message = 'Password must not be blank.'; + } + else if ($_POST['new_pass'] == $_POST['new_pass2']) { + changepassword($_SESSION['username'], $_POST['new_pass']); + $changepass_message = 'Password Changed.'; + } + else { + $changepass_message = "Passwords don't match."; + } + } + else { + $changepass_message = 'Incorrect password'; + } + } -include("includes/update-preferences-password.inc.php"); + include 'includes/update-preferences-password.inc.php'; -echo("
    "); + echo "
    "; -if (passwordscanchange($_SESSION['username'])) -{ - echo("

    Change Password

    "); - echo($changepass_message); - echo(" + if (passwordscanchange($_SESSION['username'])) { + echo '

    Change Password

    '; + echo $changepass_message; + echo "
    @@ -69,93 +62,107 @@ if (passwordscanchange($_SESSION['username']))
    -"); - echo("
    "); -} +"; + echo '
    '; + }//end if -if( $config['twofactor'] === true ) { - if( $_POST['twofactorremove'] == 1 ) { - require_once($config['install_dir']."/html/includes/authentication/twofactor.lib.php"); - if( !isset($_POST['twofactor']) ) { - echo '
    '; - echo ''; - echo twofactor_form(false); - echo '
    '; - } else{ - $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); - if( empty($twofactor['twofactor']) ) { - echo '
    Error: How did you even get here?!
    '; - } else { - $twofactor = json_decode($twofactor['twofactor'],true); - } - if( verify_hotp($twofactor['key'],$_POST['twofactor'],$twofactor['counter']) ) { - if( !dbUpdate(array('twofactor' => ''),'users','username = ?',array($_SESSION['username'])) ) { - echo '
    Error while disabling TwoFactor.
    '; - } else { - echo '
    TwoFactor Disabled.
    '; + if ($config['twofactor'] === true) { + if ($_POST['twofactorremove'] == 1) { + include_once $config['install_dir'].'/html/includes/authentication/twofactor.lib.php'; + if (!isset($_POST['twofactor'])) { + echo '
    '; + echo ''; + echo twofactor_form(false); + echo '
    '; + } + else { + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); + if (empty($twofactor['twofactor'])) { + echo '
    Error: How did you even get here?!
    '; + } + else { + $twofactor = json_decode($twofactor['twofactor'], true); + } + + if (verify_hotp($twofactor['key'], $_POST['twofactor'], $twofactor['counter'])) { + if (!dbUpdate(array('twofactor' => ''), 'users', 'username = ?', array($_SESSION['username']))) { + echo '
    Error while disabling TwoFactor.
    '; + } + else { + echo '
    TwoFactor Disabled.
    '; + } + } + else { + session_destroy(); + echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; + } + }//end if } - } else { - session_destroy(); - echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; - } - } - } else { - $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE username = ?", array($_SESSION['username'])); - echo ''; - echo '

    Two-Factor Authentication

    '; - if( !empty($twofactor['twofactor']) ) { - $twofactor = json_decode($twofactor['twofactor'],true); - $twofactor['text'] = "
    + else { + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); + echo ''; + echo '

    Two-Factor Authentication

    '; + if (!empty($twofactor['twofactor'])) { + $twofactor = json_decode($twofactor['twofactor'], true); + $twofactor['text'] = "
    "; - if( $twofactor['counter'] !== false ) { - $twofactor['uri'] = "otpauth://hotp/".$_SESSION['username']."?issuer=LibreNMS&counter=".$twofactor['counter']."&secret=".$twofactor['key']; - $twofactor['text'] .= "
    + if ($twofactor['counter'] !== false) { + $twofactor['uri'] = 'otpauth://hotp/'.$_SESSION['username'].'?issuer=LibreNMS&counter='.$twofactor['counter'].'&secret='.$twofactor['key']; + $twofactor['text'] .= "
    "; - } else { - $twofactor['uri'] = "otpauth://totp/".$_SESSION['username']."?issuer=LibreNMS&secret=".$twofactor['key']; - } - echo '
    + } + else { + $twofactor['uri'] = 'otpauth://totp/'.$_SESSION['username'].'?issuer=LibreNMS&secret='.$twofactor['key']; + } + + echo '
    '; - echo '
    + echo '
    '.$twofactor['text'].'
    '; - echo ''; - echo '
    + echo ''; + echo '
    '; - } else { - if( isset($_POST['gentwofactorkey']) && isset($_POST['twofactortype']) ) { - require_once($config['install_dir']."/html/includes/authentication/twofactor.lib.php"); - $chk = dbFetchRow("SELECT twofactor FROM users WHERE username = ?", array($_SESSION['username'])); - if( empty($chk['twofactor']) ) { - $twofactor = array('key' => twofactor_genkey()); - if( $_POST['twofactortype'] == "counter" ) { - $twofactor['counter'] = 1; - } else { - $twofactor['counter'] = false; - } - if( !dbUpdate(array('twofactor' => json_encode($twofactor)),'users','username = ?',array($_SESSION['username'])) ) { - echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; - } else { - echo '
    Added TwoFactor credentials. Please reload page.
    '; - } - } else { - echo '
    TwoFactor credentials already exists.
    '; - } - } else { - echo '
    + } + else { + if (isset($_POST['gentwofactorkey']) && isset($_POST['twofactortype'])) { + include_once $config['install_dir'].'/html/includes/authentication/twofactor.lib.php'; + $chk = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); + if (empty($chk['twofactor'])) { + $twofactor = array('key' => twofactor_genkey()); + if ($_POST['twofactortype'] == 'counter') { + $twofactor['counter'] = 1; + } + else { + $twofactor['counter'] = false; + } + + if (!dbUpdate(array('twofactor' => json_encode($twofactor)), 'users', 'username = ?', array($_SESSION['username']))) { + echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; + } + else { + echo '
    Added TwoFactor credentials. Please reload page.
    '; + } + } + else { + echo '
    TwoFactor credentials already exists.
    '; + } + } + else { + echo '
    @@ -169,32 +176,34 @@ if( $config['twofactor'] === true ) {
    '; - } + }//end if + }//end if + echo '
    '; + }//end if + }//end if +}//end if + +echo "
    '; - } } -} - -echo("
    "); -echo("
    Device Permissions
    "); - -if ($_SESSION['userlevel'] == '10') { echo("Global Administrative Access"); } -if ($_SESSION['userlevel'] == '5') { echo("Global Viewing Access"); } -if ($_SESSION['userlevel'] == '1') -{ - - foreach (dbFetchRows("SELECT * FROM `devices_perms` AS P, `devices` AS D WHERE `user_id` = ? AND P.device_id = D.device_id", array($_SESSION['user_id'])) as $perm) - { - #FIXME generatedevicelink? - echo("" . $perm['hostname'] . "
    "); - $dev_access = 1; - } - - if (!$dev_access) { echo("No access!"); } -} - -echo("
    "); - -?> +echo '
    '; diff --git a/html/pages/pseudowires.inc.php b/html/pages/pseudowires.inc.php index 5dd77f468c..3408973fd4 100644 --- a/html/pages/pseudowires.inc.php +++ b/html/pages/pseudowires.inc.php @@ -90,8 +90,7 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I, devices AS D W $pw_a['to'] = $config['time']['now']; $pw_a['bg'] = $bg; $types = array('bits', 'upkts', 'errors'); - foreach ($types as $graph_type) - { + foreach ($types as $graph_type) { $pw_a['graph_type'] = 'port_'.$graph_type; print_port_thumbnail($pw_a); } diff --git a/html/pages/public.inc.php b/html/pages/public.inc.php index ad89593bcf..bb25838841 100644 --- a/html/pages/public.inc.php +++ b/html/pages/public.inc.php @@ -1,14 +1,14 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * This file is part of LibreNMS + * + * Copyright (c) 2014 Bohdan Sanders + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ ?> @@ -28,14 +28,11 @@ $(document).ready(function() {

    System Status

    @@ -50,9 +47,8 @@ $query = "SELECT * FROM `devices` WHERE 1 AND disabled='0' AND `ignore`='0' ORDE Uptime/Location diff --git a/html/pages/routing/bgp.inc.php b/html/pages/routing/bgp.inc.php index 5e04945626..3268715ec5 100644 --- a/html/pages/routing/bgp.inc.php +++ b/html/pages/routing/bgp.inc.php @@ -1,260 +1,355 @@ 'routing', 'protocol' => 'bgp'); +else { + $link_array = array( + 'page' => 'routing', + 'protocol' => 'bgp', + ); - print_optionbar_start('', ''); + print_optionbar_start('', ''); - echo('BGP » '); + echo 'BGP » '; - if (!$vars['type']) { $vars['type'] = "all"; } - - if ($vars['type'] == "all") { echo(""); } - echo(generate_link("All",$vars, array('type' => 'all'))); - if ($vars['type'] == "all") { echo(""); } - - echo(" | "); - - if ($vars['type'] == "internal") { echo(""); } - echo(generate_link("iBGP",$vars, array('type' => 'internal'))); - if ($vars['type'] == "internal") { echo(""); } - - echo(" | "); - - if ($vars['type'] == "external") { echo(""); } - echo(generate_link("eBGP",$vars, array('type' => 'external'))); - if ($vars['type'] == "external") { echo(""); } - - echo(" | "); - - if ($vars['adminstatus'] == "stop") - { - echo(""); - echo(generate_link("Shutdown",$vars, array('adminstatus' => NULL))); - echo(""); - } else { - echo(generate_link("Shutdown",$vars, array('adminstatus' => 'stop'))); - } - - echo(" | "); - - if ($vars['adminstatus'] == "start") - { - echo(""); - echo(generate_link("Enabled",$vars, array('adminstatus' => NULL))); - echo(""); - } else { - echo(generate_link("Enabled",$vars, array('adminstatus' => 'start'))); - } - - echo(" | "); - - if ($vars['state'] == "down") - { - echo(""); - echo(generate_link("Down",$vars, array('state' => NULL))); - echo(""); - } else { - echo(generate_link("Down",$vars, array('state' => 'down'))); - } - - // End BGP Menu - - if (!isset($vars['view'])) { $vars['view'] = 'details'; } - - echo('
    '); - - if ($vars['view'] == "details") { echo(""); } - echo(generate_link("No Graphs",$vars, array('view' => 'details', 'graph' => 'NULL'))); - if ($vars['view'] == "details") { echo(""); } - - echo(" | "); - - if ($vars['graph'] == "updates") { echo(""); } - echo(generate_link("Updates",$vars, array('view' => 'graphs', 'graph' => 'updates'))); - if ($vars['graph'] == "updates") { echo(""); } - - echo(" | Prefixes: Unicast ("); - if ($vars['graph'] == "prefixes_ipv4unicast") { echo(""); } - echo(generate_link("IPv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast'))); - if ($vars['graph'] == "prefixes_ipv4unicast") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "prefixes_ipv6unicast") { echo(""); } - echo(generate_link("IPv6",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast'))); - if ($vars['graph'] == "prefixes_ipv6unicast") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "prefixes_ipv4vpn") { echo(""); } - echo(generate_link("VPNv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4vpn'))); - if ($vars['graph'] == "prefixes_ipv4vpn") { echo(""); } - echo(")"); - - echo(" | Multicast ("); - if ($vars['graph'] == "prefixes_ipv4multicast") { echo(""); } - echo(generate_link("IPv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4multicast'))); - if ($vars['graph'] == "prefixes_ipv4multicast") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "prefixes_ipv6multicast") { echo(""); } - echo(generate_link("IPv6",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6multicast'))); - if ($vars['graph'] == "prefixes_ipv6multicast") { echo(""); } - echo(")"); - - echo(" | MAC ("); - if ($vars['graph'] == "macaccounting_bits") { echo(""); } - echo(generate_link("Bits",$vars, array('view' => 'graphs', 'graph' => 'macaccounting_bits'))); - if ($vars['graph'] == "macaccounting_bits") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "macaccounting_pkts") { echo(""); } - echo(generate_link("Packets",$vars, array('view' => 'graphs', 'graph' => 'macaccounting_pkts'))); - if ($vars['graph'] == "macaccounting_pkts") { echo(""); } - echo(")"); - - echo('
    '); - - print_optionbar_end(); - - echo(""); - echo(''); - - if ($vars['type'] == "external") - { - $where = "AND D.bgpLocalAs != B.bgpPeerRemoteAs"; - } elseif ($vars['type'] == "internal") { - $where = "AND D.bgpLocalAs = B.bgpPeerRemoteAs"; - } - - if ($vars['adminstatus'] == "stop") - { - $where .= " AND (B.bgpPeerAdminStatus = 'stop')"; - } elseif ($vars['adminstatus'] == "start") - { - $where .= " AND (B.bgpPeerAdminStatus = 'start' || B.bgpPeerAdminStatus = 'running')"; - } - - if ($vars['state'] == "down") - { - $where .= " AND (B.bgpPeerState != 'established')"; - } - - $peer_query = "select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id ".$where." ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier"; - foreach (dbFetchRows($peer_query) as $peer) - { - unset ($alert, $bg_image); - - if ($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $peer['alert']=1; } - if ($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "gray"; } - if ($peer['bgpPeerAdminStatus'] == "stop") { $peer['alert']=0; $peer['disabled']=1; } - if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; - if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { $peer_type = "Priv eBGP"; } + if (!$vars['type']) { + $vars['type'] = 'all'; } - $peerhost = dbFetchRow("SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($peer['bgpPeerIdentifier'])); - - if ($peerhost) { $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); } else { unset($peername); } - - // display overlib graphs - - $graph_type = "bgp_updates"; - $local_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150&&afi=ipv4&safi=unicast"; - if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { - $peer_ip = Net_IPv6::compress($peer['bgpLocalAddr']); - } else { - $peer_ip = $peer['bgpLocalAddr']; - } - $localaddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer_ip . ""; - - $graph_type = "bgp_updates"; - $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; - if (filter_var($peer['bgpPeerIdentifier'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { - $peer_ident = Net_IPv6::compress($peer['bgpPeerIdentifier']); - } else { - $peer_ident = $peer['bgpPeerIdentifier']; + if ($vars['type'] == 'all') { + echo ""; } - $peeraddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer_ident . ""; - - echo('"); - - unset($sep); - foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) - { - $afi = $afisafi['afi']; - $safi = $afisafi['safi']; - $this_afisafi = $afi.$safi; - $peer['afi'] .= $sep . $afi .".".$safi; - $sep = "
    "; - $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer - } - unset($sep); - - echo(" - - - - - - - - "); - - unset($invalid); - switch ($vars['graph']) - { - case 'prefixes_ipv4unicast': - case 'prefixes_ipv4multicast': - case 'prefixes_ipv4vpn': - case 'prefixes_ipv6unicast': - case 'prefixes_ipv6multicast': - list(,$afisafi) = explode("_", $vars['graph']); - if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } - case 'updates': - $graph_array['type'] = "bgp_" . $vars['graph']; - $graph_array['id'] = $peer['bgpPeer_id']; + echo generate_link('All', $vars, array('type' => 'all')); + if ($vars['type'] == 'all') { + echo ''; } - switch ($vars['graph']) - { - case 'macaccounting_bits': - case 'macaccounting_pkts': - $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier'])); - $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; - if (is_array($acc) && is_file($database)) - { - $peer['graph'] = 1; - $graph_array['id'] = $acc['ma_id']; - $graph_array['type'] = $vars['graph']; + echo ' | '; + + if ($vars['type'] == 'internal') { + echo ""; + } + + echo generate_link('iBGP', $vars, array('type' => 'internal')); + if ($vars['type'] == 'internal') { + echo ''; + } + + echo ' | '; + + if ($vars['type'] == 'external') { + echo ""; + } + + echo generate_link('eBGP', $vars, array('type' => 'external')); + if ($vars['type'] == 'external') { + echo ''; + } + + echo ' | '; + + if ($vars['adminstatus'] == 'stop') { + echo ""; + echo generate_link('Shutdown', $vars, array('adminstatus' => null)); + echo ''; + } + else { + echo generate_link('Shutdown', $vars, array('adminstatus' => 'stop')); + } + + echo ' | '; + + if ($vars['adminstatus'] == 'start') { + echo ""; + echo generate_link('Enabled', $vars, array('adminstatus' => null)); + echo ''; + } + else { + echo generate_link('Enabled', $vars, array('adminstatus' => 'start')); + } + + echo ' | '; + + if ($vars['state'] == 'down') { + echo ""; + echo generate_link('Down', $vars, array('state' => null)); + echo ''; + } + else { + echo generate_link('Down', $vars, array('state' => 'down')); + } + + // End BGP Menu + if (!isset($vars['view'])) { + $vars['view'] = 'details'; + } + + echo '
    '; + + if ($vars['view'] == 'details') { + echo ""; + } + + echo generate_link('No Graphs', $vars, array('view' => 'details', 'graph' => 'NULL')); + if ($vars['view'] == 'details') { + echo ''; + } + + echo ' | '; + + if ($vars['graph'] == 'updates') { + echo ""; + } + + echo generate_link('Updates', $vars, array('view' => 'graphs', 'graph' => 'updates')); + if ($vars['graph'] == 'updates') { + echo ''; + } + + echo ' | Prefixes: Unicast ('; + if ($vars['graph'] == 'prefixes_ipv4unicast') { + echo ""; + } + + echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast')); + if ($vars['graph'] == 'prefixes_ipv4unicast') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'prefixes_ipv6unicast') { + echo ""; + } + + echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast')); + if ($vars['graph'] == 'prefixes_ipv6unicast') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'prefixes_ipv4vpn') { + echo ""; + } + + echo generate_link('VPNv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4vpn')); + if ($vars['graph'] == 'prefixes_ipv4vpn') { + echo ''; + } + + echo ')'; + + echo ' | Multicast ('; + if ($vars['graph'] == 'prefixes_ipv4multicast') { + echo ""; + } + + echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4multicast')); + if ($vars['graph'] == 'prefixes_ipv4multicast') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'prefixes_ipv6multicast') { + echo ""; + } + + echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6multicast')); + if ($vars['graph'] == 'prefixes_ipv6multicast') { + echo ''; + } + + echo ')'; + + echo ' | MAC ('; + if ($vars['graph'] == 'macaccounting_bits') { + echo ""; + } + + echo generate_link('Bits', $vars, array('view' => 'graphs', 'graph' => 'macaccounting_bits')); + if ($vars['graph'] == 'macaccounting_bits') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'macaccounting_pkts') { + echo ""; + } + + echo generate_link('Packets', $vars, array('view' => 'graphs', 'graph' => 'macaccounting_pkts')); + if ($vars['graph'] == 'macaccounting_pkts') { + echo ''; + } + + echo ')'; + + echo '
    '; + + print_optionbar_end(); + + echo "
    Local addressPeer addressTypeFamilyRemote ASStateUptime / Updates
    " . $localaddresslink . "
    ".generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp'))."
    »" . $peeraddresslink . "$peer_type".$peer['afi']."AS" . $peer['bgpPeerRemoteAs'] . "
    " . $peer['astext'] . "
    " . $peer['bgpPeerAdminStatus'] . "
    " . $peer['bgpPeerState'] . "
    " .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
    - Updates " . format_si($peer['bgpPeerInUpdates']) . " - " . format_si($peer['bgpPeerOutUpdates']) . "
    "; + echo ''; + + if ($vars['type'] == 'external') { + $where = 'AND D.bgpLocalAs != B.bgpPeerRemoteAs'; + } + else if ($vars['type'] == 'internal') { + $where = 'AND D.bgpLocalAs = B.bgpPeerRemoteAs'; + } + + if ($vars['adminstatus'] == 'stop') { + $where .= " AND (B.bgpPeerAdminStatus = 'stop')"; + } + else if ($vars['adminstatus'] == 'start') { + $where .= " AND (B.bgpPeerAdminStatus = 'start' || B.bgpPeerAdminStatus = 'running')"; + } + + if ($vars['state'] == 'down') { + $where .= " AND (B.bgpPeerState != 'established')"; + } + + $peer_query = 'select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id '.$where.' ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier'; + foreach (dbFetchRows($peer_query) as $peer) { + unset($alert, $bg_image); + + if ($peer['bgpPeerState'] == 'established') { + $col = 'green'; + } + else { + $col = 'red'; + $peer['alert'] = 1; } - } - if ($vars['graph'] == 'updates') { $peer['graph'] = 1; } + if ($peer['bgpPeerAdminStatus'] == 'start' || $peer['bgpPeerAdminStatus'] == 'running') { + $admin_col = 'green'; + } + else { + $admin_col = 'gray'; + } - if ($peer['graph']) - { - $graph_array['height'] = "100"; - $graph_array['width'] = "218"; - $graph_array['to'] = $config['time']['now']; - echo('"); - } - } + $peerhost = dbFetchRow('SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($peer['bgpPeerIdentifier'])); - echo("
    Local addressPeer addressTypeFamilyRemote ASStateUptime / Updates
    '); + if ($peer['bgpPeerAdminStatus'] == 'stop') { + $peer['alert'] = 0; + $peer['disabled'] = 1; + } - include("includes/print-graphrow.inc.php"); + if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { + $peer_type = "iBGP"; + } + else { + $peer_type = "eBGP"; + if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { + $peer_type = "Priv eBGP"; + } + } - echo("
    "); -} + if ($peerhost) { + $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); + } + else { + unset($peername); + } + // display overlib graphs + $graph_type = 'bgp_updates'; + $local_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150&&afi=ipv4&safi=unicast'; + if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { + $peer_ip = Net_IPv6::compress($peer['bgpLocalAddr']); + } + else { + $peer_ip = $peer['bgpLocalAddr']; + } + + $localaddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer_ip.''; + + $graph_type = 'bgp_updates'; + $peer_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; + if (filter_var($peer['bgpPeerIdentifier'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { + $peer_ident = Net_IPv6::compress($peer['bgpPeerIdentifier']); + } + else { + $peer_ident = $peer['bgpPeerIdentifier']; + } + + $peeraddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer_ident.''; + + echo ''; + + unset($sep); + foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { + $afi = $afisafi['afi']; + $safi = $afisafi['safi']; + $this_afisafi = $afi.$safi; + $peer['afi'] .= $sep.$afi.'.'.$safi; + $sep = '
    '; + $peer['afisafi'][$this_afisafi] = 1; + // Build a list of valid AFI/SAFI for this peer + } + + unset($sep); + + echo ' + '.$localaddresslink.'
    '.generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')).' + » + '.$peeraddresslink." + $peer_type + ".$peer['afi'].' + AS'.$peer['bgpPeerRemoteAs'].'
    '.$peer['astext']." + ".$peer['bgpPeerAdminStatus']."
    ".$peer['bgpPeerState'].'
    + '.formatUptime($peer['bgpPeerFsmEstablishedTime'])."
    + Updates ".format_si($peer['bgpPeerInUpdates'])." + ".format_si($peer['bgpPeerOutUpdates']).''; + + unset($invalid); + switch ($vars['graph']) { + case 'prefixes_ipv4unicast': + case 'prefixes_ipv4multicast': + case 'prefixes_ipv4vpn': + case 'prefixes_ipv6unicast': + case 'prefixes_ipv6multicast': + list(,$afisafi) = explode('_', $vars['graph']); + if (isset($peer['afisafi'][$afisafi])) { + $peer['graph'] = 1; + } + + case 'updates': + $graph_array['type'] = 'bgp_'.$vars['graph']; + $graph_array['id'] = $peer['bgpPeer_id']; + } + + switch ($vars['graph']) { + case 'macaccounting_bits': + case 'macaccounting_pkts': + $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', array($peer['bgpPeerIdentifier'])); + $database = $config['rrd_dir'].'/'.$device['hostname'].'/cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'; + if (is_array($acc) && is_file($database)) { + $peer['graph'] = 1; + $graph_array['id'] = $acc['ma_id']; + $graph_array['type'] = $vars['graph']; + } + } + + if ($vars['graph'] == 'updates') { + $peer['graph'] = 1; + } + + if ($peer['graph']) { + $graph_array['height'] = '100'; + $graph_array['width'] = '218'; + $graph_array['to'] = $config['time']['now']; + echo ''; + + include 'includes/print-graphrow.inc.php'; + + echo ''; + } + }//end foreach + + echo ''; +}//end if diff --git a/html/pages/routing/overview.inc.php b/html/pages/routing/overview.inc.php index bd9a9e63e1..c16262143a 100644 --- a/html/pages/routing/overview.inc.php +++ b/html/pages/routing/overview.inc.php @@ -1,7 +1,7 @@ 'IPv4 Address', 'ipv6' => 'IPv6 Address', 'mac' => 'MAC Address', 'arp' => 'ARP Table'); +$sections = array( + 'ipv4' => 'IPv4 Address', + 'ipv6' => 'IPv6 Address', + 'mac' => 'MAC Address', + 'arp' => 'ARP Table', +); -if( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) { - $sections['packages'] = 'Packages'; +if (dbFetchCell('SELECT 1 from `packages` LIMIT 1')) { + $sections['packages'] = 'Packages'; } -if (!isset($vars['search'])) { $vars['search'] = "ipv4"; } +if (!isset($vars['search'])) { + $vars['search'] = 'ipv4'; +} print_optionbar_start('', ''); - echo('Search » '); +echo 'Search » '; unset($sep); -foreach ($sections as $type => $texttype) -{ - echo($sep); - if ($vars['search'] == $type) - { - echo(""); - } +foreach ($sections as $type => $texttype) { + echo $sep; + if ($vars['search'] == $type) { + echo ""; + } -# echo('' . $texttype .''); - echo(generate_link($texttype, array('page'=>'search','search'=>$type))); + // echo('' . $texttype .''); + echo generate_link($texttype, array('page' => 'search', 'search' => $type)); - if ($vars['search'] == $type) { echo(""); } + if ($vars['search'] == $type) { + echo ''; + } - $sep = ' | '; + $sep = ' | '; } -unset ($sep); + +unset($sep); print_optionbar_end('', ''); -if( file_exists('pages/search/'.$vars['search'].'.inc.php') ) { - include('pages/search/'.$vars['search'].'.inc.php'); -} else { - echo(report_this('Unknown search type '.$vars['search'])); +if (file_exists('pages/search/'.$vars['search'].'.inc.php')) { + include 'pages/search/'.$vars['search'].'.inc.php'; +} +else { + echo report_this('Unknown search type '.$vars['search']); } - -?> diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index a4dcbd1136..45cd6888a9 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -30,21 +30,22 @@ var grid = $("#arp-search").bootgrid({ '.$data['hostname'].'"+'); + + echo '">'.$data['hostname'].'"+'; } ?> ""+ @@ -53,18 +54,16 @@ foreach (dbFetchRows($sql,$param) as $data) { " "\" class=\"form-control input-sm\" placeholder=\"Address\" />"+ diff --git a/html/pages/search/ipv4.inc.php b/html/pages/search/ipv4.inc.php index e2ea785c07..843acbd1bc 100644 --- a/html/pages/search/ipv4.inc.php +++ b/html/pages/search/ipv4.inc.php @@ -27,22 +27,23 @@ var grid = $("#ipv4-search").bootgrid({ ""+ '.$data['hostname'].'"+'); + + echo '">'.$data['hostname'].'"+'; } ?> ""+ @@ -52,18 +53,16 @@ foreach (dbFetchRows($sql,$param) as $data) { ""+ ""+ "
     "+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ "
     "+ ""+ "
    "+ diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php index 8ab58d9fff..2b9115013d 100644 --- a/html/pages/search/ipv6.inc.php +++ b/html/pages/search/ipv6.inc.php @@ -26,22 +26,23 @@ var grid = $("#ipv6-search").bootgrid({ ""+ '.$data['hostname'].'"+'); + + echo '">'.$data['hostname'].'"+'; } ?> ""+ @@ -51,9 +52,8 @@ foreach (dbFetchRows($sql,$param) as $data) { ""+ ""+ "
    "+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ "
    "+ ""+ "
    "+ diff --git a/html/pages/search/mac.inc.php b/html/pages/search/mac.inc.php index c040a1e16a..f606e4436a 100644 --- a/html/pages/search/mac.inc.php +++ b/html/pages/search/mac.inc.php @@ -26,21 +26,22 @@ var grid = $("#mac-search").bootgrid({ ""+ @@ -50,17 +51,15 @@ foreach (dbFetchRows($sql,$param) as $data) { ""+ ""+ "
    '-1', - 'rule' => '%macros.device_down = "1"', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"-1","delay":"300"}', - 'disabled' => 0, - 'name' => 'Devices up/down', - ); - $default_rules[] = array( - 'device_id' => '-1', - 'rule' => '%devices.uptime < "300" && %macros.device = "1"', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"1","delay":"300"}', - 'disabled' => 0, - 'name' => 'Device rebooted', - ); - $default_rules[] = array( - 'device_id' => '-1', - 'rule' => '%bgpPeers.bgpPeerState != "established" && %macros.device_up = "1"', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"1","delay":"300"}', - 'disabled' => 0, - 'name' => 'BGP Session down', - ); - $default_rules[] = array( - 'device_id' => '-1', - 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"1","delay":"300"}', - 'disabled' => 0, - 'name' => 'BGP Session establised', - ); - $default_rules[] = array( - 'device_id' => '-1', - 'rule' => '%macros.port_down = "1"', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"1","delay":"300"}', - 'disabled' => 0, - 'name' => 'Port status up/down', - ); - $default_rules[] = array( - 'device_id' => '-1', - 'rule' => '%macros.port_usage_perc >= "80"', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"-1","delay":"300"}', - 'disabled' => 0, - 'name' => 'Port utilisation over threshold', - ); - $default_rules[] = array( - 'device_id' => '-1', - 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"-1","delay":"300"}', - 'disabled' => 0, - 'name' => 'Sensor over limit', - ); - $default_rules[] = array( - 'device_id' => '-1', - 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', - 'severity' => 'critical', - 'extra' => '{"mute":false,"count":"-1","delay":"300"}', - 'disabled' => 0, - 'name' => 'Sensor under limit', - ); - foreach ($default_rules as $add_rule) { - dbInsert($add_rule, 'alert_rules'); - } -}//end if -require_once 'includes/modal/new_alert_rule.inc.php'; -require_once 'includes/modal/delete_alert_rule.inc.php'; +if(isset($_POST['create-default'])) { + $default_rules[] = array('device_id' => '-1', 'rule' => '%macros.device_down = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Devices up/down'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%devices.uptime < "300" && %macros.device = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Device rebooted'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerState != "established" && %macros.device_up = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session down'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session establised'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%macros.port_down = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Port status up/down'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%macros.port_usage_perc >= "80"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Port utilisation over threshold'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor over limit'); + $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor under limit'); + foreach( $default_rules as $add_rule ) { + dbInsert($add_rule,'alert_rules'); + } +} + +require_once('includes/modal/new_alert_rule.inc.php'); +require_once('includes/modal/delete_alert_rule.inc.php'); + ?>
    0) { + +if(isset($_POST['results_amount']) && $_POST['results_amount'] > 0) { $results = $_POST['results']; -} -else { +} else { $results = 50; } echo '
    - - +
    + @@ -103,150 +49,126 @@ echo '
    - '; + '; -echo ' - +'); -echo ''; - -$rulei = 1; -$count_query = 'SELECT COUNT(id)'; -$full_query = 'SELECT *'; -$sql = ''; -$param = array(); -if (isset($device['device_id']) && $device['device_id'] > 0) { - $sql = 'WHERE (device_id=? OR device_id="-1")'; +$rulei=1; +$count_query = "SELECT COUNT(id)"; +$full_query = "SELECT *"; +$sql = ''; +$param = array(); +if(isset($device['device_id']) && $device['device_id'] > 0) { + $sql = 'WHERE (device_id=? OR device_id="-1")'; $param = array($device['device_id']); } - -$query = " FROM alert_rules $sql ORDER BY device_id,id"; -$count_query = $count_query.$query; -$count = dbFetchCell($count_query, $param); -if (!isset($_POST['page_number']) && $_POST['page_number'] < 1) { +$query = " FROM alert_rules $sql ORDER BY device_id,id"; +$count_query = $count_query . $query; +$count = dbFetchCell($count_query,$param); +if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { $page_number = 1; -} -else { +} else { $page_number = $_POST['page_number']; } +$start = ($page_number - 1) * $results; +$full_query = $full_query . $query . " LIMIT $start,$results"; -$start = (($page_number - 1) * $results); -$full_query = $full_query.$query." LIMIT $start,$results"; - -foreach (dbFetchRows($full_query, $param) as $rule) { - $sub = dbFetchRows('SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1', array($rule['id'])); - $ico = 'ok'; - $col = 'success'; - $extra = ''; - if (sizeof($sub) == 1) { - $sub = $sub[0]; - if ((int) $sub['state'] === 0) { - $ico = 'ok'; - $col = 'success'; +foreach( dbFetchRows($full_query, $param) as $rule ) { + $sub = dbFetchRows("SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'])); + $ico = "ok"; + $col = "success"; + $extra = ""; + if( sizeof($sub) == 1 ) { + $sub = $sub[0]; + if( (int) $sub['state'] === 0 ) { + $ico = "ok"; + $col = "success"; + } elseif( (int) $sub['state'] === 1 ) { + $ico = "remove"; + $col = "danger"; + $extra = "danger"; + } elseif( (int) $sub['state'] === 2 ) { + $ico = "time"; + $col = "default"; + $extra = "warning"; + } + } + $alert_checked = ''; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; + if( $rule['disabled'] ) { + $ico = "pause"; + $col = ""; + $extra = "active"; + } else { + $alert_checked = 'checked'; } - else if ((int) $sub['state'] === 1) { - $ico = 'remove'; - $col = 'danger'; - $extra = 'danger'; + $rule_extra = json_decode($rule['extra'],TRUE); + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; } - } - - $alert_checked = ''; - $orig_ico = $ico; - $orig_col = $col; - $orig_class = $extra; - if ($rule['disabled']) { - $ico = 'pause'; - $col = ''; - $extra = 'active'; - } - else { - $alert_checked = 'checked'; - } - - $rule_extra = json_decode($rule['extra'], true); - echo ""; - echo ''; - echo ''; - echo "'; - echo ''; - echo ""; - } - - echo ''; - echo ''; - echo ''; - echo "\r\n"; -}//end foreach - -if (($count % $results) > 0) { - echo ' - - '; + echo ""; + echo ""; + echo ""; + echo "\r\n"; } +if($count % $results > 0) { + echo(' + + '); +} echo '
    # Name RuleExtra Enabled Action
    '; +echo (''); if ($_SESSION['userlevel'] >= '10') { - echo ''; + echo(''); } - -echo '
    #".((int) $rulei++)."".$rule['name'].""; + if($rule_extra['invert'] === true) { + echo "Inverted "; } - else if ((int) $sub['state'] === 2) { - $ico = 'time'; - $col = 'default'; - $extra = 'warning'; + echo "".htmlentities($rule['rule'])."".$rule['severity']." "; + if($rule_extra['mute'] === true) { + echo "
    #'.((int) $rulei++).''.$rule['name'].'"; - if ($rule_extra['invert'] === true) { - echo 'Inverted '; - } - - echo ''.htmlentities($rule['rule']).''.$rule['severity'].' "; - if ($rule_extra['mute'] === true) { - echo "Max: '.$rule_extra['count'].'
    Delay: '.$rule_extra['delay'].'
    Interval: '.$rule_extra['interval'].'
    '; - if ($_SESSION['userlevel'] >= '10') { - echo ""; - } - - echo ''; - if ($_SESSION['userlevel'] >= '10') { - echo " "; - echo ""; - } - - echo '
    '.generate_pagination($count, $results, $page_number).'
    Max: ".$rule_extra['count']."
    Delay: ".$rule_extra['delay']."
    Interval: ".$rule_extra['interval']."
    "; + if ($_SESSION['userlevel'] >= '10') { + echo ""; + } + echo ""; + if ($_SESSION['userlevel'] >= '10') { + echo " "; + echo ""; + } + echo "
    '. generate_pagination($count,$results,$page_number) .'
    - - - -
    '; + + + +
    '; -if ($count < 1) { +if($count < 1) { if ($_SESSION['userlevel'] >= '10') { echo '
    -
    -
    -

    - -

    -
    -
    -
    '; +
    +
    +

    + +

    +
    +
    +
    '; } } @@ -258,19 +180,19 @@ $('#ack-alert').click('', function(e) { var alert_id = $(this).data("alert_id"); $.ajax({ type: "POST", - url: "/ajax_form.php", - data: { type: "ack-alert", alert_id: alert_id }, - success: function(msg){ - $("#message").html('
    '+msg+'
    '); - if(msg.indexOf("ERROR:") <= -1) { - setTimeout(function() { - location.reload(1); - }, 1000); - } - }, - error: function(){ - $("#message").html('
    An error occurred acking this alert.
    '); - } + url: "/ajax_form.php", + data: { type: "ack-alert", alert_id: alert_id }, + success: function(msg){ + $("#message").html('
    '+msg+'
    '); + if(msg.indexOf("ERROR:") <= -1) { + setTimeout(function() { + location.reload(1); + }, 1000); + } + }, + error: function(){ + $("#message").html('
    An error occurred acking this alert.
    '); + } }); }); @@ -284,42 +206,42 @@ $('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event var orig_class = $(this).data("orig_class"); $.ajax({ type: 'POST', - url: '/ajax_form.php', - data: { type: "update-alert-rule", alert_id: alert_id, state: state }, - dataType: "html", - success: function(msg) { - if(msg.indexOf("ERROR:") <= -1) { - if(state) { - $('#alert-rule-'+alert_id).removeClass('glyphicon-pause'); - $('#alert-rule-'+alert_id).addClass('glyphicon-'+orig_state); - $('#alert-rule-'+alert_id).removeClass('text-default'); - $('#alert-rule-'+alert_id).addClass('text-'+orig_colour); - $('#row_'+alert_id).removeClass('active'); - $('#row_'+alert_id).addClass(orig_class); - } else { - $('#alert-rule-'+alert_id).removeClass('glyphicon-'+orig_state); - $('#alert-rule-'+alert_id).addClass('glyphicon-pause'); - $('#alert-rule-'+alert_id).removeClass('text-'+orig_colour); - $('#alert-rule-'+alert_id).addClass('text-default'); - $('#row_'+alert_id).removeClass('warning'); - $('#row_'+alert_id).addClass('active'); - } + url: '/ajax_form.php', + data: { type: "update-alert-rule", alert_id: alert_id, state: state }, + dataType: "html", + success: function(msg) { + if(msg.indexOf("ERROR:") <= -1) { + if(state) { + $('#alert-rule-'+alert_id).removeClass('glyphicon-pause'); + $('#alert-rule-'+alert_id).addClass('glyphicon-'+orig_state); + $('#alert-rule-'+alert_id).removeClass('text-default'); + $('#alert-rule-'+alert_id).addClass('text-'+orig_colour); + $('#row_'+alert_id).removeClass('active'); + $('#row_'+alert_id).addClass(orig_class); } else { - $("#message").html('
    '+msg+'
    '); - $('#'+alert_id).bootstrapSwitch('toggleState',true ); - } - }, - error: function() { - $("#message").html('
    This alert could not be updated.
    '); - $('#'+alert_id).bootstrapSwitch('toggleState',true ); + $('#alert-rule-'+alert_id).removeClass('glyphicon-'+orig_state); + $('#alert-rule-'+alert_id).addClass('glyphicon-pause'); + $('#alert-rule-'+alert_id).removeClass('text-'+orig_colour); + $('#alert-rule-'+alert_id).addClass('text-default'); + $('#row_'+alert_id).removeClass('warning'); + $('#row_'+alert_id).addClass('active'); } + } else { + $("#message").html('
    '+msg+'
    '); + $('#'+alert_id).bootstrapSwitch('toggleState',true ); + } + }, + error: function() { + $("#message").html('
    This alert could not be updated.
    '); + $('#'+alert_id).bootstrapSwitch('toggleState',true ); + } }); }); function updateResults(results) { - $('#results_amount').val(results.value); - $('#page_number').val(1); - $('#result_form').submit(); + $('#results_amount').val(results.value); + $('#page_number').val(1); + $('#result_form').submit(); } function changePage(page,e) { diff --git a/html/includes/print-alert-templates.php b/html/includes/print-alert-templates.php index 8ad6e8265d..16a3afdd08 100644 --- a/html/includes/print-alert-templates.php +++ b/html/includes/print-alert-templates.php @@ -1,6 +1,6 @@ @@ -10,17 +10,17 @@ $no_refresh = true;
    0) { +if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) { $results = $_POST['results']; -} else { +} +else { $results = 50; } @@ -34,37 +34,49 @@ echo '
    '; if ($_SESSION['userlevel'] >= '10') { - echo(''); + echo ''; } echo ' '); -$count_query = "SELECT COUNT(id)"; -$full_query = "SELECT *"; +echo ''; -$query = " FROM `alert_templates`"; +$count_query = 'SELECT COUNT(id)'; +$full_query = 'SELECT *'; -$count_query = $count_query . $query; -$count = dbFetchCell($count_query,$param); -if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { +$query = ' FROM `alert_templates`'; + +$count_query = $count_query.$query; +$count = dbFetchCell($count_query, $param); +if (!isset($_POST['page_number']) && $_POST['page_number'] < 1) { $page_number = 1; -} else { +} +else { $page_number = $_POST['page_number']; } -$start = ($page_number - 1) * $results; -$full_query = $full_query . $query . " LIMIT $start,$results"; -foreach( dbFetchRows($full_query, $param) as $template ) { +$start = (($page_number - 1) * $results); +$full_query = $full_query.$query." LIMIT $start,$results"; + +foreach (dbFetchRows($full_query, $param) as $template) { echo ' '.$template['name'].' '; @@ -73,14 +85,15 @@ foreach( dbFetchRows($full_query, $param) as $template ) { echo " "; echo ""; } + echo ' '; } -if($count % $results > 0) { - echo(' - '. generate_pagination($count,$results,$page_number) .' - '); +if (($count % $results) > 0) { + echo ' + '.generate_pagination($count, $results, $page_number).' + '; } echo ' diff --git a/html/includes/print-alerts.inc.php b/html/includes/print-alerts.inc.php index dcbab4b3d9..d9758a0f38 100644 --- a/html/includes/print-alerts.inc.php +++ b/html/includes/print-alerts.inc.php @@ -1,49 +1,49 @@ - - ' . $alert_entry['time_logged'] . ' - '); +echo ' + + '.$alert_entry['time_logged'].' + '; if (!isset($alert_entry['device'])) { - $dev = device_by_id_cache($alert_entry['device_id']); - echo(" - " . generate_device_link($dev, shorthost($dev['hostname'])) . " - "); + $dev = device_by_id_cache($alert_entry['device_id']); + echo ' + '.generate_device_link($dev, shorthost($dev['hostname'])).' + '; } -echo("".htmlspecialchars($alert_entry['name']) . ""); +echo ''.htmlspecialchars($alert_entry['name']).''; -if ($alert_state!='') { - if ($alert_state=='0') { - $glyph_icon = 'ok'; +if ($alert_state != '') { + if ($alert_state == '0') { + $glyph_icon = 'ok'; $glyph_color = 'green'; - $text = 'Ok'; + $text = 'Ok'; } - elseif ($alert_state=='1') { - $glyph_icon = 'remove'; + else if ($alert_state == '1') { + $glyph_icon = 'remove'; $glyph_color = 'red'; - $text = 'Alert'; + $text = 'Alert'; } - elseif ($alert_state=='2') { - $glyph_icon = 'info-sign'; + else if ($alert_state == '2') { + $glyph_icon = 'info-sign'; $glyph_color = 'lightgrey'; - $text = 'Ack'; + $text = 'Ack'; } - elseif ($alert_state=='3') { - $glyph_icon = 'arrow-down'; + else if ($alert_state == '3') { + $glyph_icon = 'arrow-down'; $glyph_color = 'orange'; - $text = 'Worse'; + $text = 'Worse'; } - elseif ($alert_state=='4') { - $glyph_icon = 'arrow-up'; + else if ($alert_state == '4') { + $glyph_icon = 'arrow-up'; $glyph_color = 'khaki'; - $text = 'Better'; - } - echo(" $text"); -} + $text = 'Better'; + }//end if + echo " $text"; +}//end if -echo(""); +echo ''; diff --git a/html/includes/print-debug.php b/html/includes/print-debug.php index f35cd05bfe..7fdbbcc6d9 100644 --- a/html/includes/print-debug.php +++ b/html/includes/print-debug.php @@ -1,6 +1,6 @@ @@ -14,25 +14,23 @@ @@ -52,26 +50,25 @@ foreach ($sql_debug as $sql_error) { @@ -97,10 +95,12 @@ if ($_SESSION['userlevel'] >= '10') { if (is_admin() === TRUE || is_read() === TRUE) { $sql = "SELECT `type`,COUNT(`type`) AS total_type FROM `devices` AS D WHERE 1 GROUP BY `type` ORDER BY `type`"; -} else { +} +else { $sql = "SELECT `type`,COUNT(`type`) AS total_type FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `type` ORDER BY `type`"; $param[] = $_SESSION['user_id']; } + foreach (dbFetchRows($sql,$param) as $devtype) { if (empty($devtype['type'])) { $devtype['type'] = 'generic'; @@ -108,9 +108,10 @@ foreach (dbFetchRows($sql,$param) as $devtype) { echo('
  • ' . ucfirst($devtype['type']) . '
  • '); } -require_once('../includes/device-groups.inc.php'); +require_once '../includes/device-groups.inc.php'; + foreach( GetDeviceGroups() as $group ) { - echo '
  • '.ucfirst($group['name']).'
  • '; + echo '
  • '.ucfirst($group['name']).'
  • '; } unset($group); @@ -118,29 +119,24 @@ unset($group); '); if ($_SESSION['userlevel'] >= '10') { -if ($config['show_locations']) -{ - - echo(' + if ($config['show_locations']) { + echo(' - '); -} - echo(' + '); + } + echo('
  • Manage Groups
  • Add Device
  • @@ -155,8 +151,7 @@ if ($config['show_locations'])
  • Alerts ('.$service_alerts.')
  • '); } -if ($_SESSION['userlevel'] >= '10') -{ - echo(' +if ($_SESSION['userlevel'] >= '10') { + echo('
  • Add Service
  • Edit Service
  • @@ -197,36 +190,53 @@ if ($_SESSION['userlevel'] >= '10') 0) -{ - echo('
  • Errored ('.$ports['errored'].')
  • '); +if ($ports['errored'] > 0) { + echo('
  • Errored ('.$ports['errored'].')
  • '); } -if ($ports['ignored'] > 0) -{ - echo('
  • Ignored ('.$ports['ignored'].')
  • '); +if ($ports['ignored'] > 0) { + echo('
  • Ignored ('.$ports['ignored'].')
  • '); } if ($config['enable_billing']) { - echo('
  • Traffic Bills
  • '); $ifbreak = 1; + echo('
  • Traffic Bills
  • '); + $ifbreak = 1; } if ($config['enable_pseudowires']) { - echo('
  • Pseudowires
  • '); $ifbreak = 1; + echo('
  • Pseudowires
  • '); + $ifbreak = 1; } ?> = '5') -{ - echo(' '); - if ($config['int_customers']) { echo('
  • Customers
  • '); $ifbreak = 1; } - if ($config['int_l2tp']) { echo('
  • L2TP
  • '); $ifbreak = 1; } - if ($config['int_transit']) { echo('
  • Transit
  • '); $ifbreak = 1; } - if ($config['int_peering']) { echo('
  • Peering
  • '); $ifbreak = 1; } - if ($config['int_peering'] && $config['int_transit']) { echo('
  • Peering + Transit
  • '); $ifbreak = 1; } - if ($config['int_core']) { echo('
  • Core
  • '); $ifbreak = 1; } +if ($_SESSION['userlevel'] >= '5') { + echo(' '); + if ($config['int_customers']) { + echo('
  • Customers
  • '); + $ifbreak = 1; + } + if ($config['int_l2tp']) { + echo('
  • L2TP
  • '); + $ifbreak = 1; + } + if ($config['int_transit']) { + echo('
  • Transit
  • '); + $ifbreak = 1; + } + if ($config['int_peering']) { + echo('
  • Peering
  • '); + $ifbreak = 1; + } + if ($config['int_peering'] && $config['int_transit']) { + echo('
  • Peering + Transit
  • '); + $ifbreak = 1; + } + if ($config['int_core']) { + echo('
  • Core
  • '); + $ifbreak = 1; + } if (is_array($config['custom_descr']) === FALSE) { $config['custom_descr'] = array($config['custom_descr']); } @@ -239,21 +249,18 @@ if ($_SESSION['userlevel'] >= '5') } if ($ifbreak) { - echo(' '); + echo(' '); } -if (isset($interface_alerts)) -{ - echo('
  • Alerts ('.$interface_alerts.')
  • '); +if (isset($interface_alerts)) { + echo('
  • Alerts ('.$interface_alerts.')
  • '); } $deleted_ports = 0; -foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) -{ - if (port_permitted($interface['port_id'], $interface['device_id'])) - { - $deleted_ports++; - } +foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) { + if (port_permitted($interface['port_id'], $interface['device_id'])) { + $deleted_ports++; + } } ?> @@ -261,7 +268,9 @@ foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`delete
  • Disabled
  • Deleted ('.$deleted_ports.')'); } +if ($deleted_ports) { + echo('
  • Deleted ('.$deleted_ports.')
  • '); +} ?> @@ -270,9 +279,8 @@ if ($deleted_ports) { echo('
  • Processor
  • Storage
  • '); +if ($menu_sensors) { + $sep = 0; + echo(' '); } $icons = array('fanspeed'=>'tachometer','humidity'=>'tint','temperature'=>'fire','current'=>'bolt','frequency'=>'line-chart','power'=>'power-off','voltage'=>'bolt','charge'=>'plus-square','dbm'=>'sun-o', 'load'=>'spinner','state'=>'bullseye'); -foreach (array('fanspeed','humidity','temperature') as $item) -{ - if (isset($menu_sensors[$item])) - { +foreach (array('fanspeed','humidity','temperature') as $item) { + if (isset($menu_sensors[$item])) { + echo('
  • '.nicecase($item).'
  • '); + unset($menu_sensors[$item]);$sep++; + } +} + +if ($sep && array_keys($menu_sensors)) { + echo(' '); + $sep = 0; +} + +foreach (array('current','frequency','power','voltage') as $item) { + if (isset($menu_sensors[$item])) { + echo('
  • '.nicecase($item).'
  • '); + unset($menu_sensors[$item]);$sep++; + } +} + +if ($sep && array_keys($menu_sensors)) { + echo(' '); + $sep = 0; +} + +foreach (array_keys($menu_sensors) as $item) { echo('
  • '.nicecase($item).'
  • '); unset($menu_sensors[$item]);$sep++; - } -} - -if ($sep && array_keys($menu_sensors)) -{ - echo(' '); - $sep = 0; -} - -foreach (array('current','frequency','power','voltage') as $item) -{ - if (isset($menu_sensors[$item])) - { - echo('
  • '.nicecase($item).'
  • '); - unset($menu_sensors[$item]);$sep++; - } -} - -if ($sep && array_keys($menu_sensors)) -{ - echo(' '); - $sep = 0; -} - -foreach (array_keys($menu_sensors) as $item) -{ - echo('
  • '.nicecase($item).'
  • '); - unset($menu_sensors[$item]);$sep++; } ?> @@ -337,27 +337,24 @@ foreach (array_keys($menu_sensors) as $item) $app_count = dbFetchCell("SELECT COUNT(`app_id`) FROM `applications`"); -if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") -{ +if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") { ?> + = '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") -{ +if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") { ?> @@ -440,16 +427,11 @@ if ( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) { = '10') -{ - if (dbFetchCell("SELECT COUNT(*) from `plugins` WHERE plugin_active = '1'") > 0) { - echo(' - - '); - } - echo(' -
  • Plugin Admin
  • - '); +if ($_SESSION['userlevel'] >= '10') { + if (dbFetchCell("SELECT COUNT(*) from `plugins` WHERE plugin_active = '1'") > 0) { + echo(''); + } + echo('
  • Plugin Admin
  • '); } ?> @@ -457,9 +439,8 @@ if ($_SESSION['userlevel'] >= '10') @@ -476,50 +457,42 @@ if(is_file("includes/print-menubar-custom.inc.php"))
    -"); \ No newline at end of file +"; diff --git a/html/includes/print-service-edit.inc.php b/html/includes/print-service-edit.inc.php index 0954649d6d..d0ad23a569 100644 --- a/html/includes/print-service-edit.inc.php +++ b/html/includes/print-service-edit.inc.php @@ -1,35 +1,33 @@ Edit Service
    - - + +
    - +
    - +
    - +
    -
    "); - -} \ No newline at end of file +"; +}//end if diff --git a/html/includes/print-syslog.inc.php b/html/includes/print-syslog.inc.php index 09467dd7c4..1a7564920d 100644 --- a/html/includes/print-syslog.inc.php +++ b/html/includes/print-syslog.inc.php @@ -1,23 +1,18 @@ "); +if (device_permitted($entry['device_id'])) { + echo ''; - // Stop shortening hostname. Issue #61 - //$entry['hostname'] = shorthost($entry['hostname'], 20); - - if ($vars['page'] != "device") - { - echo("" . $entry['date'] . ""); - echo("".generate_device_link($entry).""); - echo("" . $entry['program'] . " : " . htmlspecialchars($entry['msg']) . ""); - } else { - echo("" . $entry['date'] . "   " . $entry['program'] . "   " . htmlspecialchars($entry['msg']) . ""); - } - - echo(""); + // Stop shortening hostname. Issue #61 + // $entry['hostname'] = shorthost($entry['hostname'], 20); + if ($vars['page'] != 'device') { + echo ''.$entry['date'].''; + echo ''.generate_device_link($entry).''; + echo ''.$entry['program'].' : '.htmlspecialchars($entry['msg']).''; + } + else { + echo ''.$entry['date'].'   '.$entry['program'].'   '.htmlspecialchars($entry['msg']).''; + } + echo ''; } - -?> diff --git a/html/includes/reports/alert-log.pdf.inc.php b/html/includes/reports/alert-log.pdf.inc.php index 5ee0e91ea1..d293b474b9 100644 --- a/html/includes/reports/alert-log.pdf.inc.php +++ b/html/includes/reports/alert-log.pdf.inc.php @@ -1,65 +1,83 @@ AddPage('L'); +$where = '1'; +if (is_numeric($_GET['device_id'])) { + $where .= ' AND E.device_id = ?'; + $param[] = $_GET['device_id']; +} - $where = "1"; - if (is_numeric($_GET['device_id'])) { - $where .= ' AND E.device_id = ?'; - $param[] = $_GET['device_id']; - } - if ($_GET['string']) { - $where .= " AND R.rule LIKE ?"; - $param[] = "%".$_GET['string']."%"; - } +if ($_GET['string']) { + $where .= ' AND R.rule LIKE ?'; + $param[] = '%'.$_GET['string'].'%'; +} - if ($_SESSION['userlevel'] >= '5') { - $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where ORDER BY `humandate` DESC"; - } else { - $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? ORDER BY `humandate` DESC"; - $param[] = $_SESSION['user_id']; - } +if ($_SESSION['userlevel'] >= '5') { + $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where ORDER BY `humandate` DESC"; +} +else { + $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? ORDER BY `humandate` DESC"; + $param[] = $_SESSION['user_id']; +} - if (isset($_GET['start']) && is_numeric($_GET['start'])) { - $start = mres($_GET['start']); - } else { - $start = 0; - } +if (isset($_GET['start']) && is_numeric($_GET['start'])) { + $start = mres($_GET['start']); +} +else { + $start = 0; +} - if (isset($_GET['results']) && is_numeric($_GET['results'])) { - $numresults = mres($_GET['results']); - } else { - $numresults = 250; - } +if (isset($_GET['results']) && is_numeric($_GET['results'])) { + $numresults = mres($_GET['results']); +} +else { + $numresults = 250; +} - $full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults"; +$full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults"; - foreach (dbFetchRows($full_query, $param) as $alert_entry) { - $hostname = gethostbyid(mres($alert_entry['device_id'])); - $alert_state = $alert_entry['state']; +foreach (dbFetchRows($full_query, $param) as $alert_entry) { + $hostname = gethostbyid(mres($alert_entry['device_id'])); + $alert_state = $alert_entry['state']; - if ($alert_state!='') { - if ($alert_state=='0') { - $glyph_color = 'green'; - $text = 'Ok'; - } elseif ($alert_state=='1') { - $glyph_color = 'red'; - $text = 'Alert'; - } elseif ($alert_state=='2') { - $glyph_color = 'lightgrey'; - $text = 'Ack'; - } elseif ($alert_state=='3') { - $glyph_color = 'orange'; - $text = 'Worse'; - } elseif ($alert_state=='4') { - $glyph_color = 'khaki'; - $text = 'Better'; - } - $data[] = array($alert_entry['time_logged'],$hostname,htmlspecialchars($alert_entry['name']),$text); + if ($alert_state != '') { + if ($alert_state == '0') { + $glyph_color = 'green'; + $text = 'Ok'; + } + else if ($alert_state == '1') { + $glyph_color = 'red'; + $text = 'Alert'; + } + else if ($alert_state == '2') { + $glyph_color = 'lightgrey'; + $text = 'Ack'; + } + else if ($alert_state == '3') { + $glyph_color = 'orange'; + $text = 'Worse'; + } + else if ($alert_state == '4') { + $glyph_color = 'khaki'; + $text = 'Better'; } - } -$header = array('Datetime', 'Device', 'Log', 'Status'); + $data[] = array( + $alert_entry['time_logged'], + $hostname, + htmlspecialchars($alert_entry['name']), + $text, + ); + }//end if +}//end foreach + +$header = array( + 'Datetime', + 'Device', + 'Log', + 'Status', +); $table = << @@ -74,17 +92,19 @@ EOD; foreach ($data as $log) { if ($log[3] == 'Alert') { $tr_col = '#d39392'; - } else { + } + else { $tr_col = '#bbd392'; } + $table .= ' - + '.$log[0].' '.$log[1].' '.$log[2].' '.$log[3].' - - '; + + '; } $table .= << $value) -{ - if ($value != "") - { - switch ($var) - { - case 'hostname': - $where .= " AND D.hostname LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'location': - $where .= " AND D.location LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'device_id': - $where .= " AND D.device_id = ?"; - $param[] = $value; - break; - case 'deleted': - case 'ignore': - if ($value == 1) - { - $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; - } - break; - case 'disable': - case 'ifSpeed': - if (is_numeric($value)) - { - $where .= " AND I.$var = ?"; - $param[] = $value; - } - break; - case 'ifType': - $where .= " AND I.$var = ?"; - $param[] = $value; - break; - case 'ifAlias': - case 'port_descr_type': - $where .= " AND I.$var LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'errors': - if ($value == 1) - { - $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; - } - break; - case 'state': - if ($value == "down") - { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; - $param[] = "up"; - $param[] = "down"; - } elseif($value == "up") { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; - $param[] = "up"; - $param[] = "up"; - } elseif($value == "admindown") { - $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; - $param[] = "down"; - } - break; - } - } -} +foreach ($vars as $var => $value) { + if ($value != '') { + switch ($var) { + case 'hostname': + $where .= ' AND D.hostname LIKE ?'; + $param[] = '%'.$value.'%'; + break; -$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ".$where." ".$query_sort; + case 'location': + $where .= ' AND D.location LIKE ?'; + $param[] = '%'.$value.'%'; + break; + + case 'device_id': + $where .= ' AND D.device_id = ?'; + $param[] = $value; + break; + + case 'deleted': + case 'ignore': + if ($value == 1) { + $where .= ' AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0'; + } + break; + + case 'disable': + case 'ifSpeed': + if (is_numeric($value)) { + $where .= " AND I.$var = ?"; + $param[] = $value; + } + break; + + case 'ifType': + $where .= " AND I.$var = ?"; + $param[] = $value; + break; + + case 'ifAlias': + case 'port_descr_type': + $where .= " AND I.$var LIKE ?"; + $param[] = '%'.$value.'%'; + break; + + case 'errors': + if ($value == 1) { + $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; + } + break; + + case 'state': + if ($value == 'down') { + $where .= 'AND I.ifAdminStatus = ? AND I.ifOperStatus = ?'; + $param[] = 'up'; + $param[] = 'down'; + } + else if ($value == 'up') { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; + $param[] = 'up'; + $param[] = 'up'; + } + else if ($value == 'admindown') { + $where .= 'AND I.ifAdminStatus = ? AND D.ignore = 0'; + $param[] = 'down'; + } + break; + }//end switch + }//end if +}//end foreach + +$query = 'SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id '.$where.' '.$query_sort; $row = 1; -list($format, $subformat) = explode("_", $vars['format']); +list($format, $subformat) = explode('_', $vars['format']); $ports = dbFetchRows($query, $param); -switch ($vars['sort']) -{ - case 'traffic': +switch ($vars['sort']) { +case 'traffic': $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); break; - case 'traffic_in': + +case 'traffic_in': $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); break; - case 'traffic_out': + +case 'traffic_out': $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); break; - case 'packets': + +case 'packets': $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); break; - case 'packets_in': + +case 'packets_in': $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); break; - case 'packets_out': + +case 'packets_out': $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); break; - case 'errors': + +case 'errors': $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); break; - case 'speed': + +case 'speed': $ports = array_sort($ports, 'ifSpeed', SORT_DESC); break; - case 'port': + +case 'port': $ports = array_sort($ports, 'ifDescr', SORT_ASC); break; - case 'media': + +case 'media': $ports = array_sort($ports, 'ifType', SORT_ASC); break; - case 'descr': + +case 'descr': $ports = array_sort($ports, 'ifAlias', SORT_ASC); break; - case 'device': - default: - $ports = array_sort($ports, 'hostname', SORT_ASC); -} -$csv[] = array('Device','Port','Speed','Down','Up','Media','Description'); -foreach( $ports as $port ) { - if( port_permitted($port['port_id'], $port['device_id']) ) { - $speed = humanspeed($port['ifSpeed']); - $type = humanmedia($port['ifType']); - $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); - $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); - $port = ifLabel($port, $device); - $csv[] = array($port['hostname'],fixIfName($port['label']),$speed,$port['in_rate'],$port['out_rate'],$type,$port['ifAlias']); - } +case 'device': +default: + $ports = array_sort($ports, 'hostname', SORT_ASC); +}//end switch + +$csv[] = array( + 'Device', + 'Port', + 'Speed', + 'Down', + 'Up', + 'Media', + 'Description', +); +foreach ($ports as $port) { + if (port_permitted($port['port_id'], $port['device_id'])) { + $speed = humanspeed($port['ifSpeed']); + $type = humanmedia($port['ifType']); + $port['in_rate'] = formatRates(($port['ifInOctets_rate'] * 8)); + $port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8)); + $port = ifLabel($port, $device); + $csv[] = array( + $port['hostname'], + fixIfName($port['label']), + $speed, + $port['in_rate'], + $port['out_rate'], + $type, + $port['ifAlias'], + ); + } } -?> diff --git a/html/includes/service-add.inc.php b/html/includes/service-add.inc.php index 3bc9eca630..cf1433b274 100644 --- a/html/includes/service-add.inc.php +++ b/html/includes/service-add.inc.php @@ -5,6 +5,6 @@ $updated = '1'; $service_id = add_service(mres($_POST['device']), mres($_POST['type']), mres($_POST['descr']), mres($_POST['ip']), mres($_POST['params'])); if ($service_id) { - $message .= $message_break . "Service added (".$service_id.")!"; - $message_break .= "
    "; -} \ No newline at end of file + $message .= $message_break.'Service added ('.$service_id.')!'; + $message_break .= '
    '; +} diff --git a/html/includes/table/address-search.inc.php b/html/includes/table/address-search.inc.php index a50d06afc7..25eb75360e 100644 --- a/html/includes/table/address-search.inc.php +++ b/html/includes/table/address-search.inc.php @@ -2,56 +2,64 @@ $param = array(); -if (is_admin() === FALSE && is_read() === FALSE) { - $perms_sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; - $param[] = array($_SESSION['user_id']); +if (is_admin() === false && is_read() === false) { + $perms_sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; + $param[] = array($_SESSION['user_id']); } -list($address,$prefix) = explode("/", $_POST['address']); +list($address,$prefix) = explode('/', $_POST['address']); if ($_POST['search_type'] == 'ipv4') { - $sql = " FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D"; + $sql = ' FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D'; $sql .= $perms_sql; $sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id $where "; if (!empty($address)) { $sql .= " AND ipv4_address LIKE '%".$address."%'"; } + if (!empty($prefix)) { - $sql .= " AND ipv4_prefixlen='?'"; + $sql .= " AND ipv4_prefixlen='?'"; $param[] = array($prefix); } -} elseif ($_POST['search_type'] == 'ipv6') { - $sql = " FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D"; +} +else if ($_POST['search_type'] == 'ipv6') { + $sql = ' FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D'; $sql .= $perms_sql; $sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id $where "; if (!empty($address)) { $sql .= " AND (ipv6_address LIKE '%".$address."%' OR ipv6_compressed LIKE '%".$address."%')"; } + if (!empty($prefix)) { $sql .= " AND ipv6_prefixlen = '$prefix'"; } -} elseif ($_POST['search_type'] == 'mac') { - $sql = " FROM `ports` AS I, `devices` AS D"; - $sql .= $perms_sql; - $sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%' $where "; } +else if ($_POST['search_type'] == 'mac') { + $sql = ' FROM `ports` AS I, `devices` AS D'; + $sql .= $perms_sql; + $sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address']))."%' $where "; +}//end if if (is_numeric($_POST['device_id'])) { - $sql .= " AND I.device_id = ?"; + $sql .= ' AND I.device_id = ?'; $param[] = array($_POST['device_id']); } + if ($_POST['interface']) { - $sql .= " AND I.ifDescr LIKE '?'"; + $sql .= " AND I.ifDescr LIKE '?'"; $param[] = array($_POST['interface']); } if ($_POST['search_type'] == 'ipv4') { $count_sql = "SELECT COUNT(`ipv4_address_id`) $sql"; -} elseif ($_POST['search_type'] == 'ipv6') { - $count_sql = "SELECT COUNT(`ipv6_address_id`) $sql"; -} elseif ($_POST['search_type'] == 'mac') { - $count_sql = "SELECT COUNT(`port_id`) $sql"; } -$total = dbFetchCell($count_sql,$param); +else if ($_POST['search_type'] == 'ipv6') { + $count_sql = "SELECT COUNT(`ipv6_address_id`) $sql"; +} +else if ($_POST['search_type'] == 'mac') { + $count_sql = "SELECT COUNT(`port_id`) $sql"; +} + +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -63,7 +71,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -75,31 +83,42 @@ $sql = "SELECT *,`I`.`ifDescr` AS `interface` $sql"; foreach (dbFetchRows($sql, $param) as $interface) { $speed = humanspeed($interface['ifSpeed']); - $type = humanmedia($interface['ifType']); + $type = humanmedia($interface['ifType']); if ($_POST['search_type'] == 'ipv6') { - list($prefix, $length) = explode("/", $interface['ipv6_network']); - $address = Net_IPv6::compress($interface['ipv6_address']) . '/'.$length; - } elseif ($_POST['search_type'] == 'mac') { + list($prefix, $length) = explode('/', $interface['ipv6_network']); + $address = Net_IPv6::compress($interface['ipv6_address']).'/'.$length; + } + else if ($_POST['search_type'] == 'mac') { $address = formatMac($interface['ifPhysAddress']); - } else { - list($prefix, $length) = explode("/", $interface['ipv4_network']); - $address = $interface['ipv4_address'] . '/' .$length; + } + else { + list($prefix, $length) = explode('/', $interface['ipv4_network']); + $address = $interface['ipv4_address'].'/'.$length; } if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { - $error_img = generate_port_link($interface,"Interface Errors",errors); - } else { - $error_img = ""; + $error_img = generate_port_link($interface, "Interface Errors", errors); } - if (port_permitted($interface['port_id'])) { - $interface = ifLabel ($interface, $interface); - $response[] = array('hostname'=>generate_device_link($interface), - 'interface'=>generate_port_link($interface) . ' ' . $error_img, - 'address'=>$address, - 'description'=>$interface['ifAlias']); + else { + $error_img = ''; } -} -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); + if (port_permitted($interface['port_id'])) { + $interface = ifLabel($interface, $interface); + $response[] = array( + 'hostname' => generate_device_link($interface), + 'interface' => generate_port_link($interface).' '.$error_img, + 'address' => $address, + 'description' => $interface['ifAlias'], + ); + } +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/alert-schedule.inc.php b/html/includes/table/alert-schedule.inc.php index 635e67be92..5d2bfa9b89 100644 --- a/html/includes/table/alert-schedule.inc.php +++ b/html/includes/table/alert-schedule.inc.php @@ -16,8 +16,9 @@ $where = 1; if ($_SESSION['userlevel'] >= '5') { $sql = " FROM `alert_schedule` AS S WHERE $where"; -} else { - $sql = " FROM `alert_schedule` AS S WHERE $where"; +} +else { + $sql = " FROM `alert_schedule` AS S WHERE $where"; $param[] = $_SESSION['user_id']; } @@ -26,7 +27,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(`id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -38,7 +39,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -48,20 +49,29 @@ if ($rowCount != -1) { $sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '".$config['dateformat']['mysql']['compact']."') AS `start`, DATE_FORMAT(`S`.`end`, '".$config['dateformat']['mysql']['compact']."') AS `end`, `S`.`title` $sql"; -foreach (dbFetchRows($sql,$param) as $schedule) { +foreach (dbFetchRows($sql, $param) as $schedule) { $status = 0; if ($schedule['end'] < date('dS M Y H:i::s')) { $status = 1; } + if (date('dS M Y H:i::s') >= $schedule['start'] && date('dS M Y H:i::s') < $schedule['end']) { $status = 2; } - $response[] = array('title'=>$schedule['title'], - 'start'=>$schedule['start'], - 'end'=>$schedule['end'], - 'id'=>$schedule['schedule_id'], - 'status'=>$status); + + $response[] = array( + 'title' => $schedule['title'], + 'start' => $schedule['start'], + 'end' => $schedule['end'], + 'id' => $schedule['schedule_id'], + 'status' => $status, + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/alertlog.inc.php b/html/includes/table/alertlog.inc.php index 0c8e515e62..8b4d94d3e2 100644 --- a/html/includes/table/alertlog.inc.php +++ b/html/includes/table/alertlog.inc.php @@ -3,14 +3,15 @@ $where = 1; if (is_numeric($_POST['device_id'])) { - $where .= ' AND E.device_id = ?'; + $where .= ' AND E.device_id = ?'; $param[] = $_POST['device_id']; } if ($_SESSION['userlevel'] >= '5') { $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where"; -} else { - $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?"; +} +else { + $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?"; $param[] = array($_SESSION['user_id']); } @@ -19,7 +20,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(`E`.`id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -31,7 +32,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -42,42 +43,49 @@ if ($rowCount != -1) { $sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql"; $rulei = 0; -foreach (dbFetchRows($sql,$param) as $alertlog) { - $dev = device_by_id_cache($alertlog['device_id']); +foreach (dbFetchRows($sql, $param) as $alertlog) { + $dev = device_by_id_cache($alertlog['device_id']); $fault_detail = alert_details($alertlog['details']); - $alert_state = $alertlog['state']; - if ($alert_state=='0') { - $glyph_icon = 'ok'; + $alert_state = $alertlog['state']; + if ($alert_state == '0') { + $glyph_icon = 'ok'; $glyph_color = 'green'; - $text = 'Ok'; + $text = 'Ok'; } - elseif ($alert_state=='1') { - $glyph_icon = 'remove'; + else if ($alert_state == '1') { + $glyph_icon = 'remove'; $glyph_color = 'red'; - $text = 'Alert'; + $text = 'Alert'; } - elseif ($alert_state=='2') { - $glyph_icon = 'info-sign'; + else if ($alert_state == '2') { + $glyph_icon = 'info-sign'; $glyph_color = 'lightgrey'; - $text = 'Ack'; + $text = 'Ack'; } - elseif ($alert_state=='3') { - $glyph_icon = 'arrow-down'; + else if ($alert_state == '3') { + $glyph_icon = 'arrow-down'; $glyph_color = 'orange'; - $text = 'Worse'; + $text = 'Worse'; } - elseif ($alert_state=='4') { - $glyph_icon = 'arrow-up'; + else if ($alert_state == '4') { + $glyph_icon = 'arrow-up'; $glyph_color = 'khaki'; - $text = 'Better'; - } - $response[] = array('id'=>$rulei++, - 'time_logged'=>$alertlog['humandate'], - 'details'=>'', - 'hostname'=>'
    '.generate_device_link($dev, shorthost($dev['hostname'])).'
    '.$fault_detail.'
    ', - 'alert'=>htmlspecialchars($alertlog['alert']), - 'status'=>" $text"); -} + $text = 'Better'; + }//end if + $response[] = array( + 'id' => $rulei++, + 'time_logged' => $alertlog['humandate'], + 'details' => '', + 'hostname' => '
    '.generate_device_link($dev, shorthost($dev['hostname'])).'
    '.$fault_detail.'
    ', + 'alert' => htmlspecialchars($alertlog['alert']), + 'status' => " $text", + ); +}//end foreach -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); -echo _json_encode($output); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); +echo _json_encode($output); diff --git a/html/includes/table/alerts.inc.php b/html/includes/table/alerts.inc.php index 799404b1a4..2efab5d1f1 100644 --- a/html/includes/table/alerts.inc.php +++ b/html/includes/table/alerts.inc.php @@ -10,18 +10,18 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { $sql_search .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')"; } -$sql = " FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`"; +$sql = ' FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`'; -if (is_admin() === FALSE && is_read() === FALSE) { - $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; +if (is_admin() === false && is_read() === false) { + $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; $param[] = $_SESSION['user_id']; } $sql .= " RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE $where AND `state` IN (1,2,3,4) $sql_search"; $count_sql = "SELECT COUNT(`alerts`.`id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -33,7 +33,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -43,76 +43,86 @@ if ($rowCount != -1) { $sql = "SELECT `alerts`.*, `devices`.`hostname` AS `hostname`,`alert_rules`.`rule` AS `rule`, `alert_rules`.`name` AS `name`, `alert_rules`.`severity` AS `severity` $sql"; -$rulei = 0; +$rulei = 0; $format = $_POST['format']; -foreach (dbFetchRows($sql,$param) as $alert) { - $log = dbFetchCell("SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1", array($alert['rule_id'],$alert['device_id'])); +foreach (dbFetchRows($sql, $param) as $alert) { + $log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id'])); $fault_detail = alert_details($log); - $ico = "ok"; - $col = "green"; - $extra = ""; - $msg = ""; - if ( (int) $alert['state'] === 0 ) { - $ico = "ok"; - $col = "green"; - $extra = "success"; - $msg = "ok"; - } elseif ( (int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) { - $ico = "volume-up"; - $col = "red"; - $extra = "danger"; - $msg = "alert"; - if ( (int) $alert['state'] === 3) { - $msg = "worse"; - } elseif ( (int) $alert['state'] === 4) { - $msg = "better"; - } - } elseif ( (int) $alert['state'] === 2) { - $ico = "volume-off"; - $col = "#800080"; - $extra = "warning"; - $msg = "muted"; + $ico = 'ok'; + $col = 'green'; + $extra = ''; + $msg = ''; + if ((int) $alert['state'] === 0) { + $ico = 'ok'; + $col = 'green'; + $extra = 'success'; + $msg = 'ok'; } + else if ((int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) { + $ico = 'volume-up'; + $col = 'red'; + $extra = 'danger'; + $msg = 'alert'; + if ((int) $alert['state'] === 3) { + $msg = 'worse'; + } + else if ((int) $alert['state'] === 4) { + $msg = 'better'; + } + } + else if ((int) $alert['state'] === 2) { + $ico = 'volume-off'; + $col = '#800080'; + $extra = 'warning'; + $msg = 'muted'; + }//end if $alert_checked = ''; - $orig_ico = $ico; - $orig_col = $col; - $orig_class = $extra; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; $severity = $alert['severity']; if ($alert['state'] == 3) { - $severity .= " +"; - } elseif ($alert['state'] == 4) { - $severity .= " -"; + $severity .= ' +'; + } + else if ($alert['state'] == 4) { + $severity .= ' -'; } $ack_ico = 'volume-up'; $ack_col = 'success'; - if($alert['state'] == 2) { + if ($alert['state'] == 2) { $ack_ico = 'volume-off'; $ack_col = 'danger'; - } + } $hostname = ' -
    - '.generate_device_link($alert).' -
    '.$fault_detail.'
    -
    '; +
    + '.generate_device_link($alert).' +
    '.$fault_detail.'
    +
    '; - $response[] = array('id'=>$rulei++, - 'rule'=>"".htmlentities($alert['name'])."", - 'details'=>'', - 'hostname'=>$hostname, - 'timestamp'=>($alert['timestamp'] ? $alert['timestamp'] : "N/A"), - 'severity'=>$severity, - 'ack_col'=>$ack_col, - 'state'=>$alert['state'], - 'alert_id'=>$alert['id'], - 'ack_ico'=>$ack_ico, - 'extra'=>$extra, - 'msg'=>$msg); + $response[] = array( + 'id' => $rulei++, + 'rule' => ''.htmlentities($alert['name']).'', + 'details' => '', + 'hostname' => $hostname, + 'timestamp' => ($alert['timestamp'] ? $alert['timestamp'] : 'N/A'), + 'severity' => $severity, + 'ack_col' => $ack_col, + 'state' => $alert['state'], + 'alert_id' => $alert['id'], + 'ack_ico' => $ack_ico, + 'extra' => $extra, + 'msg' => $msg, + ); +}//end foreach -} - -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/arp-search.inc.php b/html/includes/table/arp-search.inc.php index dd5c6225ea..090476048f 100644 --- a/html/includes/table/arp-search.inc.php +++ b/html/includes/table/arp-search.inc.php @@ -2,32 +2,33 @@ $param = array(); -$sql .= " FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D "; +$sql .= ' FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D '; -if (is_admin() === FALSE && is_read() === FALSE) { - $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; +if (is_admin() === false && is_read() === false) { + $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; $param[] = $_SESSION['user_id']; } $sql .= " WHERE M.port_id = P.port_id AND P.device_id = D.device_id $where "; -if (isset($_POST['searchby']) && $_POST['searchby'] == "ip") { - $sql .= " AND `ipv4_address` LIKE ?"; - $param[] = "%".trim($_POST['address'])."%"; -} elseif (isset($_POST['searchby']) && $_POST['searchby'] == "mac") { - $sql .= " AND `mac_address` LIKE ?"; - $param[] = "%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%"; +if (isset($_POST['searchby']) && $_POST['searchby'] == 'ip') { + $sql .= ' AND `ipv4_address` LIKE ?'; + $param[] = '%'.trim($_POST['address']).'%'; +} +else if (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') { + $sql .= ' AND `mac_address` LIKE ?'; + $param[] = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address'])).'%'; } if (is_numeric($_POST['device_id'])) { - $sql .= " AND P.device_id = ?"; + $sql .= ' AND P.device_id = ?'; $param[] = $_POST['device_id']; } $count_sql = "SELECT COUNT(`M`.`port_id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -39,7 +40,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -51,39 +52,53 @@ $sql = "SELECT *,`P`.`ifDescr` AS `interface` $sql"; foreach (dbFetchRows($sql, $param) as $entry) { if (!$ignore) { - if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) { - $error_img = generate_port_link($entry,"Interface Errors",port_errors); - } else { - $error_img = ""; + $error_img = generate_port_link($entry, "Interface Errors", port_errors); + } + else { + $error_img = ''; } - $arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address'])); - if ($arp_host) { - $arp_name = generate_device_link($arp_host); - } else { - unset($arp_name); - } - if ($arp_host) { - $arp_if = generate_port_link($arp_host); - } else { - unset($arp_if); - } - if ($arp_host['device_id'] == $entry['device_id']) { - $arp_name = "Localhost"; - } - if ($arp_host['port_id'] == $entry['port_id']) { - $arp_if = "Local port"; - } - $response[] = array('mac_address'=>formatMac($entry['mac_address']), - 'ipv4_address'=>$entry['ipv4_address'], - 'hostname'=>generate_device_link($entry), - 'interface'=>generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))) . ' ' . $error_img, - 'remote_device'=>$arp_name, - 'remote_interface'=>$arp_if); - } - unset($ignore); -} + $arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($entry['ipv4_address'])); + if ($arp_host) { + $arp_name = generate_device_link($arp_host); + } + else { + unset($arp_name); + } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); + if ($arp_host) { + $arp_if = generate_port_link($arp_host); + } + else { + unset($arp_if); + } + + if ($arp_host['device_id'] == $entry['device_id']) { + $arp_name = 'Localhost'; + } + + if ($arp_host['port_id'] == $entry['port_id']) { + $arp_if = 'Local port'; + } + + $response[] = array( + 'mac_address' => formatMac($entry['mac_address']), + 'ipv4_address' => $entry['ipv4_address'], + 'hostname' => generate_device_link($entry), + 'interface' => generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))).' '.$error_img, + 'remote_device' => $arp_name, + 'remote_interface' => $arp_if, + ); + }//end if + + unset($ignore); +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/devices.inc.php b/html/includes/table/devices.inc.php index 25cf21bd51..129e198f21 100644 --- a/html/includes/table/devices.inc.php +++ b/html/includes/table/devices.inc.php @@ -3,11 +3,11 @@ $where = 1; $param = array(); -$sql = " FROM `devices`"; +$sql = ' FROM `devices`'; -if (is_admin() === FALSE && is_read() === FALSE) { - $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`"; - $where .= " AND `DP`.`user_id`=?"; +if (is_admin() === false && is_read() === false) { + $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`'; + $where .= ' AND `DP`.`user_id`=?'; $param[] = $_SESSION['user_id']; } @@ -17,48 +17,87 @@ if (!empty($_POST['location'])) { $sql .= " WHERE $where "; -if (!empty($_POST['hostname'])) { $sql .= " AND hostname LIKE ?"; $param[] = "%".$_POST['hostname']."%"; } -if (!empty($_POST['os'])) { $sql .= " AND os = ?"; $param[] = $_POST['os']; } -if (!empty($_POST['version'])) { $sql .= " AND version = ?"; $param[] = $_POST['version']; } -if (!empty($_POST['hardware'])) { $sql .= " AND hardware = ?"; $param[] = $_POST['hardware']; } -if (!empty($_POST['features'])) { $sql .= " AND features = ?"; $param[] = $_POST['features']; } -if (!empty($_POST['type'])) { - if ($_POST['type'] == 'generic') { - $sql .= " AND ( type = ? OR type = '')"; $param[] = $_POST['type']; - } else { - $sql .= " AND type = ?"; $param[] = $_POST['type']; - } +if (!empty($_POST['hostname'])) { + $sql .= ' AND hostname LIKE ?'; + $param[] = '%'.$_POST['hostname'].'%'; } -if (!empty($_POST['state'])) { - $sql .= " AND status= ?"; - if( is_numeric($_POST['state']) ) { - $param[] = $_POST['state']; - } else { - $param[] = str_replace(array('up','down'),array(1,0),$_POST['state']); + +if (!empty($_POST['os'])) { + $sql .= ' AND os = ?'; + $param[] = $_POST['os']; +} + +if (!empty($_POST['version'])) { + $sql .= ' AND version = ?'; + $param[] = $_POST['version']; +} + +if (!empty($_POST['hardware'])) { + $sql .= ' AND hardware = ?'; + $param[] = $_POST['hardware']; +} + +if (!empty($_POST['features'])) { + $sql .= ' AND features = ?'; + $param[] = $_POST['features']; +} + +if (!empty($_POST['type'])) { + if ($_POST['type'] == 'generic') { + $sql .= " AND ( type = ? OR type = '')"; + $param[] = $_POST['type']; + } + else { + $sql .= ' AND type = ?'; + $param[] = $_POST['type']; } } -if (!empty($_POST['disabled'])) { $sql .= " AND disabled= ?"; $param[] = $_POST['disabled']; } -if (!empty($_POST['ignore'])) { $sql .= " AND `ignore`= ?"; $param[] = $_POST['ignore']; } -if (!empty($_POST['location']) && $_POST['location'] == "Unset") { $location_filter = ''; } + +if (!empty($_POST['state'])) { + $sql .= ' AND status= ?'; + if (is_numeric($_POST['state'])) { + $param[] = $_POST['state']; + } + else { + $param[] = str_replace(array('up', 'down'), array(1, 0), $_POST['state']); + } +} + +if (!empty($_POST['disabled'])) { + $sql .= ' AND disabled= ?'; + $param[] = $_POST['disabled']; +} + +if (!empty($_POST['ignore'])) { + $sql .= ' AND `ignore`= ?'; + $param[] = $_POST['ignore']; +} + +if (!empty($_POST['location']) && $_POST['location'] == 'Unset') { + $location_filter = ''; +} + if (!empty($_POST['location'])) { - $sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)"; + $sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)"; $param[] = mres($_POST['location']); $param[] = mres($_POST['location']); } -if( !empty($_POST['group']) ) { - require_once('../includes/device-groups.inc.php'); - $sql .= " AND ( "; - foreach( GetDevicesFromGroup($_POST['group']) as $dev ) { - $sql .= "`devices`.`device_id` = ? OR "; + +if (!empty($_POST['group'])) { + include_once '../includes/device-groups.inc.php'; + $sql .= ' AND ( '; + foreach (GetDevicesFromGroup($_POST['group']) as $dev) { + $sql .= '`devices`.`device_id` = ? OR '; $param[] = $dev['device_id']; } - $sql = substr($sql, 0, strlen($sql)-3); - $sql .= " )"; + + $sql = substr($sql, 0, (strlen($sql) - 3)); + $sql .= ' )'; } $count_sql = "SELECT COUNT(`devices`.`device_id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -70,7 +109,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -81,99 +120,124 @@ if ($rowCount != -1) { $sql = "SELECT DISTINCT(`devices`.`device_id`),`devices`.* $sql"; if (!isset($_POST['format'])) { - $_POST['format'] = "list_detail"; + $_POST['format'] = 'list_detail'; } -list($format, $subformat) = explode("_", $_POST['format']); + +list($format, $subformat) = explode('_', $_POST['format']); foreach (dbFetchRows($sql, $param) as $device) { - if (isset($bg) && $bg == $list_colour_b) { - $bg = $list_colour_a; - } else { - $bg = $list_colour_b; - } + if (isset($bg) && $bg == $list_colour_b) { + $bg = $list_colour_a; + } + else { + $bg = $list_colour_b; + } - if ($device['status'] == '0') { - $extra = "danger"; - $msg = $device['status_reason']; - } else { - $extra = "success"; - $msg = "up"; - } - if ($device['ignore'] == '1') { - $extra = "default"; - $msg = "ignored"; - if ($device['status'] == '1') { - $extra = "warning"; - $msg = "ignored"; - } - } - if ($device['disabled'] == '1') { - $extra = "default"; - $msg = "disabled"; - } + if ($device['status'] == '0') { + $extra = 'danger'; + $msg = $device['status_reason']; + } + else { + $extra = 'success'; + $msg = 'up'; + } - $type = strtolower($device['os']); - $image = getImage($device); - - if ($device['os'] == "ios") { - formatCiscoHardware($device, true); - } + if ($device['ignore'] == '1') { + $extra = 'default'; + $msg = 'ignored'; + if ($device['status'] == '1') { + $extra = 'warning'; + $msg = 'ignored'; + } + } - $device['os_text'] = $config['os'][$device['os']]['text']; - $port_count = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?", array($device['device_id'])); - $sensor_count = dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?", array($device['device_id'])); + if ($device['disabled'] == '1') { + $extra = 'default'; + $msg = 'disabled'; + } - if (get_dev_attrib($device,'override_sysLocation_bool')) { - $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); - } + $type = strtolower($device['os']); + $image = getImage($device); - $actions = ('
    -
    '); - $actions .= ' View device '; - $actions .= ('
    -
    '); - $actions .= ' View alerts '; - $actions .= '
    '; - if ($_SESSION['userlevel'] >= "7") { - $actions .= ('
    - Edit device -
    '); - } - $actions .= ('
    -
    -
    - telnet -
    -
    - ssh -
    -
    - https -
    -
    '); + if ($device['os'] == 'ios') { + formatCiscoHardware($device, true); + } - $hostname = generate_device_link($device); - $platform = $device['hardware'] . '
    ' . $device['features']; - $os = $device['os_text'] . '
    ' . $device['version']; - if (extension_loaded('mbstring')) { - $location = mb_substr($device['location'], 0, 32, 'utf8'); - } else { - $location = truncate($device['location'], 32, ''); - } - $uptime = formatUptime($device['uptime'], 'short') . '
    ' . $location; - if ($subformat == "detail") { - $hostname .= '
    ' . $device['sysName']; - if ($port_count) { - $col_port = ' '.$port_count . '
    '; - } - if ($sensor_count) { - $col_port .= ' '.$sensor_count; - } - } else { + $device['os_text'] = $config['os'][$device['os']]['text']; + $port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); + $sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id'])); - } - $response[] = array('extra'=>$extra,'msg'=>$msg,'icon'=>$image,'hostname'=>$hostname,'ports'=>$col_port,'hardware'=>$platform,'os'=>$os,'uptime'=>$uptime,'actions'=>$actions); -} + if (get_dev_attrib($device, 'override_sysLocation_bool')) { + $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); + } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); + $actions = ('
    +
    '); + $actions .= ' View device '; + $actions .= ('
    +
    '); + $actions .= ' View alerts '; + $actions .= '
    '; + if ($_SESSION['userlevel'] >= '7') { + $actions .= ('
    + Edit device +
    '); + } + + $actions .= ('
    +
    +
    + telnet +
    +
    + ssh +
    +
    + https +
    +
    '); + + $hostname = generate_device_link($device); + $platform = $device['hardware'].'
    '.$device['features']; + $os = $device['os_text'].'
    '.$device['version']; + if (extension_loaded('mbstring')) { + $location = mb_substr($device['location'], 0, 32, 'utf8'); + } + else { + $location = truncate($device['location'], 32, ''); + } + + $uptime = formatUptime($device['uptime'], 'short').'
    '.$location; + if ($subformat == 'detail') { + $hostname .= '
    '.$device['sysName']; + if ($port_count) { + $col_port = ' '.$port_count.'
    '; + } + + if ($sensor_count) { + $col_port .= ' '.$sensor_count; + } + } + else { + } + + $response[] = array( + 'extra' => $extra, + 'msg' => $msg, + 'icon' => $image, + 'hostname' => $hostname, + 'ports' => $col_port, + 'hardware' => $platform, + 'os' => $os, + 'uptime' => $uptime, + 'actions' => $actions, + ); +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php index d5e5e7d60e..9cae422965 100644 --- a/html/includes/table/eventlog.inc.php +++ b/html/includes/table/eventlog.inc.php @@ -1,23 +1,22 @@ = '5') { $sql = " FROM `eventlog` AS E LEFT JOIN `devices` AS `D` ON `E`.`host`=`D`.`device_id` WHERE $where"; -} else { - $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?"; +} +else { + $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?"; $param[] = $_SESSION['user_id']; } @@ -26,7 +25,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(datetime) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -38,7 +37,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -48,22 +47,28 @@ if ($rowCount != -1) { $sql = "SELECT `E`.*,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate $sql"; -foreach (dbFetchRows($sql,$param) as $eventlog) { +foreach (dbFetchRows($sql, $param) as $eventlog) { $dev = device_by_id_cache($eventlog['host']); - if ($eventlog['type'] == "interface") { + if ($eventlog['type'] == 'interface') { $this_if = ifLabel(getifbyid($eventlog['reference'])); - $type = "".generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).""; - } else { - $type = "System"; + $type = ''.generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).''; } - - $response[] = array('datetime'=>$eventlog['humandate'], - 'hostname'=>generate_device_link($dev, shorthost($dev['hostname'])), - 'type'=>$type, - 'message'=>htmlspecialchars($eventlog['message'])); + else { + $type = 'System'; + } + + $response[] = array( + 'datetime' => $eventlog['humandate'], + 'hostname' => generate_device_link($dev, shorthost($dev['hostname'])), + 'type' => $type, + 'message' => htmlspecialchars($eventlog['message']), + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); - -?> diff --git a/html/includes/table/inventory.inc.php b/html/includes/table/inventory.inc.php index 6c5b92823f..2e4c0b9281 100644 --- a/html/includes/table/inventory.inc.php +++ b/html/includes/table/inventory.inc.php @@ -1,14 +1,15 @@ = '5') { $sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id"; -} else { - $sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?"; +} +else { + $sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?"; $param[] = $_SESSION['user_id']; } @@ -17,32 +18,32 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } if (isset($_POST['string']) && strlen($_POST['string'])) { - $sql .= " AND E.entPhysicalDescr LIKE ?"; - $param[] = "%".$_POST['string']."%"; + $sql .= ' AND E.entPhysicalDescr LIKE ?'; + $param[] = '%'.$_POST['string'].'%'; } if (isset($_POST['device_string']) && strlen($_POST['device_string'])) { - $sql .= " AND D.hostname LIKE ?"; - $param[] = "%".$_POST['device_string']."%"; + $sql .= ' AND D.hostname LIKE ?'; + $param[] = '%'.$_POST['device_string'].'%'; } if (isset($_POST['part']) && strlen($_POST['part'])) { - $sql .= " AND E.entPhysicalModelName = ?"; - $param[] = $_POST['part']; + $sql .= ' AND E.entPhysicalModelName = ?'; + $param[] = $_POST['part']; } if (isset($_POST['serial']) && strlen($_POST['serial'])) { - $sql .= " AND E.entPhysicalSerialNum LIKE ?"; - $param[] = "%".$_POST['serial']."%"; + $sql .= ' AND E.entPhysicalSerialNum LIKE ?'; + $param[] = '%'.$_POST['serial'].'%'; } if (isset($_POST['device']) && is_numeric($_POST['device'])) { - $sql .= " AND D.device_id = ?"; - $param[] = $_POST['device']; + $sql .= ' AND D.device_id = ?'; + $param[] = $_POST['device']; } $count_sql = "SELECT COUNT(`entPhysical_id`) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -54,7 +55,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -65,12 +66,19 @@ if ($rowCount != -1) { $sql = "SELECT `D`.`device_id` AS `device_id`, `D`.`hostname` AS `hostname`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql"; foreach (dbFetchRows($sql, $param) as $invent) { - $response[] = array('hostname'=>generate_device_link($invent, shortHost($invent['hostname'])), - 'description'=>$invent['description'], - 'name'=>$invent['name'], - 'model'=>$invent['model'], - 'serial'=>$invent['serial']); + $response[] = array( + 'hostname' => generate_device_link($invent, shortHost($invent['hostname'])), + 'description' => $invent['description'], + 'name' => $invent['name'], + 'model' => $invent['model'], + 'serial' => $invent['serial'], + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, + ); echo _json_encode($output); diff --git a/html/includes/table/mempool.inc.php b/html/includes/table/mempool.inc.php index d3968a5317..2afb80edc0 100644 --- a/html/includes/table/mempool.inc.php +++ b/html/includes/table/mempool.inc.php @@ -1,72 +1,88 @@ generate_device_link($mempool), - 'mempool_descr' => $mempool['mempool_descr'], - 'graph' => $mini_graph, - 'mempool_used' => $bar_link, - 'mempool_perc' => $perc . "%"); - if ($_POST['view'] == "graphs") { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; - $return_data = true; - include("includes/print-graphrow.inc.php"); - unset($return_data); - $response[] = array('hostname' => $graph_data[0], - 'mempool_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'mempool_used' => $graph_data[3], - 'mempool_perc' => ''); - } # endif graphs -} -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count); +$sql = "SELECT * $sql"; +foreach (dbFetchRows($sql, $param) as $mempool) { + $perc = round($mempool['mempool_perc'], 0); + $total = formatStorage($mempool['mempool_total']); + $free = formatStorage($mempool['mempool_free']); + $used = formatStorage($mempool['mempool_used']); + $graph_array['type'] = $graph_type; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['from'] = $config['time']['day']; + $graph_array['to'] = $config['time']['now']; + $graph_array['height'] = '20'; + $graph_array['width'] = '80'; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; + $link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/'; + $mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + $background = get_percentage_colours($perc); + $bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $free, 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null); + + $response[] = array( + 'hostname' => generate_device_link($mempool), + 'mempool_descr' => $mempool['mempool_descr'], + 'graph' => $mini_graph, + 'mempool_used' => $bar_link, + 'mempool_perc' => $perc.'%', + ); + if ($_POST['view'] == 'graphs') { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; + $return_data = true; + include 'includes/print-graphrow.inc.php'; + unset($return_data); + $response[] = array( + 'hostname' => $graph_data[0], + 'mempool_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'mempool_used' => $graph_data[3], + 'mempool_perc' => '', + ); + } //end if +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $count, +); echo _json_encode($output); diff --git a/html/includes/table/poll-log.inc.php b/html/includes/table/poll-log.inc.php index 3a0ca3213e..3579759b6c 100644 --- a/html/includes/table/poll-log.inc.php +++ b/html/includes/table/poll-log.inc.php @@ -1,11 +1,12 @@ " 'graphs', 'group' => 'poller')). "'>" .$device['hostname']. "", - 'last_polled' => $device['last_polled'], - 'last_polled_timetaken' => $device['last_polled_timetaken']); + $response[] = array( + 'hostname' => " 'graphs', 'group' => 'poller'))."'>".$device['hostname'].'', + 'last_polled' => $device['last_polled'], + 'last_polled_timetaken' => $device['last_polled_timetaken'], + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); - -?> diff --git a/html/includes/table/processor.inc.php b/html/includes/table/processor.inc.php index a7b3d97457..bcedd6196f 100644 --- a/html/includes/table/processor.inc.php +++ b/html/includes/table/processor.inc.php @@ -1,67 +1,83 @@ generate_device_link($processor), - 'processor_descr' => $processor['processor_descr'], - 'graph' => $mini_graph, - 'processor_usage' => $bar_link); - if ($_POST['view'] == "graphs") { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $processor['processor_id']; - $graph_array['type'] = $graph_type; - $return_data = true; - include("includes/print-graphrow.inc.php"); - unset($return_data); - $response[] = array('hostname' => $graph_data[0], - 'processor_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'processor_usage' => $graph_data[3]); - } # endif graphs -} -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$sql = "SELECT * $sql"; +foreach (dbFetchRows($sql, $param) as $processor) { + $perc = round($processor['processor_usage'], 0); + $graph_array['type'] = $graph_type; + $graph_array['id'] = $processor['processor_id']; + $graph_array['from'] = $config['time']['day']; + $graph_array['to'] = $config['time']['now']; + $graph_array['height'] = '20'; + $graph_array['width'] = '80'; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; + $link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/'; + $mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + $background = get_percentage_colours($perc); + $bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, $perc.'%', 'ffffff', $background['left'], (100 - $perc).'%', 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null); + + $response[] = array( + 'hostname' => generate_device_link($processor), + 'processor_descr' => $processor['processor_descr'], + 'graph' => $mini_graph, + 'processor_usage' => $bar_link, + ); + if ($_POST['view'] == 'graphs') { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $processor['processor_id']; + $graph_array['type'] = $graph_type; + $return_data = true; + include 'includes/print-graphrow.inc.php'; + unset($return_data); + $response[] = array( + 'hostname' => $graph_data[0], + 'processor_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'processor_usage' => $graph_data[3], + ); + } //end if +}//end foreach + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); diff --git a/html/includes/table/storage.inc.php b/html/includes/table/storage.inc.php index a912ba1d2e..3d301456f0 100644 --- a/html/includes/table/storage.inc.php +++ b/html/includes/table/storage.inc.php @@ -1,14 +1,14 @@ generate_device_link($drive), + 'storage_descr' => $drive['storage_descr'], + 'graph' => $mini_graph, + 'storage_used' => $bar_link, + 'storage_perc' => $perc.'%', + ); + if ($_POST['view'] == 'graphs') { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; - $response[] = array('hostname' => generate_device_link($drive), - 'storage_descr' => $drive['storage_descr'], - 'graph' => $mini_graph, - 'storage_used' => $bar_link, - 'storage_perc' => $perc . "%"); - if ($_POST['view'] == "graphs") { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; + $return_data = true; + include 'includes/print-graphrow.inc.php'; + unset($return_data); + $response[] = array( + 'hostname' => $graph_data[0], + 'storage_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'storage_used' => $graph_data[3], + 'storage_perc' => '', + ); + } //end if +}//end foreach - $return_data = true; - include("includes/print-graphrow.inc.php"); - unset($return_data); - $response[] = array('hostname' => $graph_data[0], - 'storage_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'storage_used' => $graph_data[3], - 'storage_perc' => ''); - - } # endif graphs -} - -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $count, +); echo _json_encode($output); diff --git a/html/includes/table/syslog.inc.php b/html/includes/table/syslog.inc.php index 81df05d289..987aac65a1 100644 --- a/html/includes/table/syslog.inc.php +++ b/html/includes/table/syslog.inc.php @@ -1,46 +1,44 @@ = ?"; - $param[] = $_POST['from']; -} -if( !empty($_POST['to']) ) { - $where .= " AND timestamp <= ?"; - $param[] = $_POST['to']; +if (!empty($_POST['from'])) { + $where .= ' AND timestamp >= ?'; + $param[] = $_POST['from']; } -if ($_SESSION['userlevel'] >= '5') -{ - $sql = "FROM syslog AS S"; - $sql .= " WHERE ".$where; -} else { - $sql = "FROM syslog AS S, devices_perms AS P"; - $sql .= "WHERE S.device_id = P.device_id AND P.user_id = ?"; - $sql .= $where; - $param = array_merge(array($_SESSION['user_id']), $param); +if (!empty($_POST['to'])) { + $where .= ' AND timestamp <= ?'; + $param[] = $_POST['to']; +} + +if ($_SESSION['userlevel'] >= '5') { + $sql = 'FROM syslog AS S'; + $sql .= ' WHERE '.$where; +} +else { + $sql = 'FROM syslog AS S, devices_perms AS P'; + $sql .= 'WHERE S.device_id = P.device_id AND P.user_id = ?'; + $sql .= $where; + $param = array_merge(array($_SESSION['user_id']), $param); } $count_sql = "SELECT COUNT(timestamp) $sql"; -$total = dbFetchCell($count_sql,$param); +$total = dbFetchCell($count_sql, $param); if (empty($total)) { $total = 0; } @@ -52,7 +50,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = ($current * $rowCount) - ($rowCount); + $limit_low = (($current * $rowCount) - ($rowCount)); $limit_high = $rowCount; } @@ -62,14 +60,20 @@ if ($rowCount != -1) { $sql = "SELECT S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql"; -foreach (dbFetchRows($sql,$param) as $syslog) { - $dev = device_by_id_cache($syslog['device_id']); - $response[] = array('timestamp'=>$syslog['date'], - 'device_id'=>generate_device_link($dev, shorthost($dev['hostname'])), - 'program'=>$syslog['program'], - 'msg'=>htmlspecialchars($syslog['msg'])); +foreach (dbFetchRows($sql, $param) as $syslog) { + $dev = device_by_id_cache($syslog['device_id']); + $response[] = array( + 'timestamp' => $syslog['date'], + 'device_id' => generate_device_link($dev, shorthost($dev['hostname'])), + 'program' => $syslog['program'], + 'msg' => htmlspecialchars($syslog['msg']), + ); } -$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); echo _json_encode($output); -?> diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 788915f694..477f056b46 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -1,40 +1,38 @@ $get_var) -{ - if (strstr($key, "opt")) - { - list($name, $value) = explode("|", $get_var); - if (!isset($value)) { $value = "yes"; } - $vars[$name] = $value; - } +foreach ($_GET as $key => $get_var) { + if (strstr($key, 'opt')) { + list($name, $value) = explode('|', $get_var); + if (!isset($value)) { + $value = 'yes'; + } + + $vars[$name] = $value; + } } $segments = explode('/', trim($_SERVER['REQUEST_URI'], '/')); -foreach ($segments as $pos => $segment) -{ - $segment = urldecode($segment); - if ($pos == "0") - { - $vars['page'] = $segment; - } else { - list($name, $value) = explode("=", $segment); - if ($value == "" || !isset($value)) - { - $vars[$name] = yes; - } else { - $vars[$name] = $value; +foreach ($segments as $pos => $segment) { + $segment = urldecode($segment); + if ($pos == '0') { + $vars['page'] = $segment; + } + else { + list($name, $value) = explode('=', $segment); + if ($value == '' || !isset($value)) { + $vars[$name] = yes; + } + else { + $vars[$name] = $value; + } } - } } -foreach ($_GET as $name => $value) -{ - $vars[$name] = $value; +foreach ($_GET as $name => $value) { + $vars[$name] = $value; } -foreach ($_POST as $name => $value) -{ - $vars[$name] = $value; +foreach ($_POST as $name => $value) { + $vars[$name] = $value; } diff --git a/html/index.php b/html/index.php index 57fff1b57a..a3de9ba0c5 100644 --- a/html/index.php +++ b/html/index.php @@ -14,7 +14,8 @@ if( strstr($_SERVER['SERVER_SOFTWARE'],"nginx") ) { $_SERVER['PATH_INFO'] = str_replace($_SERVER['PATH_TRANSLATED'].$_SERVER['PHP_SELF'],"",$_SERVER['ORIG_SCRIPT_FILENAME']); -} else { +} +else { $_SERVER['PATH_INFO'] = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : ''); } @@ -31,40 +32,40 @@ function catchFatal() { } } -if (strpos($_SERVER['PATH_INFO'], "debug")) -{ - $debug = "1"; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); - set_error_handler('logErrors'); - register_shutdown_function('catchFatal'); -} else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); +if (strpos($_SERVER['PATH_INFO'], "debug")) { + $debug = "1"; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); + set_error_handler('logErrors'); + register_shutdown_function('catchFatal'); +} +else { + $debug = FALSE; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } // Set variables $msg_box = array(); // Check for install.inc.php -if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') -{ - // no config.php does so let's redirect to the install - header('Location: /install.php'); - exit; +if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') { + // no config.php does so let's redirect to the install + header('Location: /install.php'); + exit; } -include("../includes/defaults.inc.php"); -include("../config.php"); -include_once("../includes/definitions.inc.php"); -include("../includes/functions.php"); -include("includes/functions.inc.php"); -include("includes/vars.inc.php"); -include('includes/plugins.inc.php'); +require '../includes/defaults.inc.php'; +require '../config.php'; +require_once '../includes/definitions.inc.php'; +require '../includes/functions.php'; +require 'includes/functions.inc.php'; +require 'includes/vars.inc.php'; +require 'includes/plugins.inc.php'; + Plugins::start(); $runtime_start = utime(); @@ -74,30 +75,33 @@ ob_start(); ini_set('allow_url_fopen', 0); ini_set('display_errors', 0); -include("includes/authenticate.inc.php"); +require 'includes/authenticate.inc.php'; -if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { $_SESSION['widescreen'] = 1; } -if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) { unset($_SESSION['widescreen']); } +if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { + $_SESSION['widescreen'] = 1; +} +if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) { + unset($_SESSION['widescreen']); +} # Load the settings for Multi-Tenancy. -if (isset($config['branding']) && is_array($config['branding'])) -{ - if ($config['branding'][$_SERVER['SERVER_NAME']]) - { - foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) - { - eval("\$config['" . $confitem . "'] = \$confval;"); +if (isset($config['branding']) && is_array($config['branding'])) { + if ($config['branding'][$_SERVER['SERVER_NAME']]) { + foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) { + eval("\$config['" . $confitem . "'] = \$confval;"); + } } - } else { - foreach ($config['branding']['default'] as $confitem => $confval) - { - eval("\$config['" . $confitem . "'] = \$confval;"); + else { + foreach ($config['branding']['default'] as $confitem => $confval) { + eval("\$config['" . $confitem . "'] = \$confval;"); + } } - } } # page_title_prefix is displayed, unless page_title is set -if (isset($config['page_title'])) { $config['page_title_prefix'] = $config['page_title']; } +if (isset($config['page_title'])) { + $config['page_title_prefix'] = $config['page_title']; +} ?> @@ -119,7 +123,8 @@ if (empty($config['favicon'])) { ' . "\n"); } ?> @@ -169,14 +174,13 @@ if (empty($config['favicon'])) { body { padding-top: 0px !important; - padding-bottom: 0px !important; }"; + padding-bottom: 0px !important; }"; } @@ -188,50 +192,47 @@ if ((isset($vars['bare']) && $vars['bare'] != "yes") || !isset($vars['bare'])) { "); - print_r($_GET); - print_r($vars); - echo(""); +if (isset($devel) || isset($vars['devel'])) { + echo("
    ");
    +    print_r($_GET);
    +    print_r($vars);
    +    echo("
    "); } -if ($_SESSION['authenticated']) -{ - // Authenticated. Print a page. - if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) - { - include("pages/" . $vars['page'] . ".inc.php"); - } else { - if (isset($config['front_page']) && is_file($config['front_page'])) - { - include($config['front_page']); - } else { - include("pages/front/default.php"); +if ($_SESSION['authenticated']) { + // Authenticated. Print a page. + if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) { + require "pages/" . $vars['page'] . ".inc.php"; + } + else { + if (isset($config['front_page']) && is_file($config['front_page'])) { + require $config['front_page']; + } + else { + require 'pages/front/default.php'; + } } - } -} else { - // Not Authenticated. Show status page if enabled - if ( $config['public_status'] === true ) - { - if (isset($vars['page']) && strstr("login", $vars['page'])) - { - include("pages/logon.inc.php"); - } else { - echo '
    '; - include("pages/public.inc.php"); - echo '
    '; - echo ''; +} +else { + // Not Authenticated. Show status page if enabled + if ( $config['public_status'] === true ) { + if (isset($vars['page']) && strstr("login", $vars['page'])) { + require 'pages/logon.inc.php'; + } + else { + echo '
    '; + require 'pages/public.inc.php'; + echo '
    '; + echo ''; + } + } + else { + require 'pages/logon.inc.php'; } - } - else - { - include("pages/logon.inc.php"); - } } ?> @@ -239,37 +240,42 @@ if ($_SESSION['authenticated']) MySQL: Cell '.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,3).'s'. - ' Row '.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,3).'s'. - ' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'. - ' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s'); +if ($config['page_gen']) { + echo('
    MySQL: Cell '.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,3).'s'. + ' Row '.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,3).'s'. + ' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'. + ' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s'); - $fullsize = memory_get_usage(); - unset($cache); - $cachesize = $fullsize - memory_get_usage(); - if ($cachesize < 0) { $cachesize = 0; } // Silly PHP! + $fullsize = memory_get_usage(); + unset($cache); + $cachesize = $fullsize - memory_get_usage(); + if ($cachesize < 0) { + $cachesize = 0; + } // Silly PHP! - echo('
    Cached data in memory is '.formatStorage($cachesize).'. Page memory usage is '.formatStorage($fullsize).', peaked at '. formatStorage(memory_get_peak_usage()) .'.'); - echo('
    Generated in ' . $gentime . ' seconds.'); + echo('
    Cached data in memory is '.formatStorage($cachesize).'. Page memory usage is '.formatStorage($fullsize).', peaked at '. formatStorage(memory_get_peak_usage()) .'.'); + echo('
    Generated in ' . $gentime . ' seconds.'); } -if (isset($pagetitle) && is_array($pagetitle)) -{ - # if prefix is set, put it in front - if ($config['page_title_prefix']) { array_unshift($pagetitle,$config['page_title_prefix']); } +if (isset($pagetitle) && is_array($pagetitle)) { + # if prefix is set, put it in front + if ($config['page_title_prefix']) { + array_unshift($pagetitle,$config['page_title_prefix']); + } - # if suffix is set, put it in the back - if ($config['page_title_suffix']) { $pagetitle[] = $config['page_title_suffix']; } + # if suffix is set, put it in the back + if ($config['page_title_suffix']) { + $pagetitle[] = $config['page_title_suffix']; + } - # create and set the title - $title = join(" - ",$pagetitle); - echo(""); + # create and set the title + $title = join(" - ",$pagetitle); + echo(""); } ?> @@ -295,23 +301,21 @@ if(dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` <= } if(is_array($msg_box)) { - echo(""); + echo(""); } if (is_array($sql_debug) && is_array($php_debug) && $_SESSION['authenticated'] === TRUE) { - - include_once "includes/print-debug.php"; - + require_once "includes/print-debug.php"; } if ($no_refresh !== TRUE && $config['page_refresh'] != 0) { @@ -367,7 +371,8 @@ if ($no_refresh !== TRUE && $config['page_refresh'] != 0) { }); '); -} else { +} +else { echo(' +}//end if diff --git a/html/pages/alert-stats.inc.php b/html/pages/alert-stats.inc.php index d392f1dd20..ab9a0c57fd 100644 --- a/html/pages/alert-stats.inc.php +++ b/html/pages/alert-stats.inc.php @@ -1,12 +1,13 @@ -* 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 3 of the License, or (at your -* option) any later version. Please see LICENSE.txt at the top level of -* the source code distribution for details. -*/ -require_once('includes/print-graph-alerts.inc.php'); + * LibreNMS + * + * Copyright (c) 2015 Søren Friis Rosiak + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +require_once 'includes/print-graph-alerts.inc.php'; diff --git a/html/pages/alerts.inc.php b/html/pages/alerts.inc.php index bcc97a32a0..fae3fba5e5 100644 --- a/html/pages/alerts.inc.php +++ b/html/pages/alerts.inc.php @@ -13,7 +13,5 @@ */ $device['device_id'] = '-1'; -require_once('includes/print-alerts.php'); +require_once 'includes/print-alerts.php'; unset($device['device_id']); - -?> diff --git a/html/pages/api-access.inc.php b/html/pages/api-access.inc.php index a1b6e5a528..6b8a885a7a 100644 --- a/html/pages/api-access.inc.php +++ b/html/pages/api-access.inc.php @@ -12,22 +12,22 @@ * the source code distribution for details. */ -if ($_SESSION['userlevel'] >= '10') -{ -if(empty($_POST['token'])) { +if ($_SESSION['userlevel'] >= '10') { +if (empty($_POST['token'])) { $_POST['token'] = bin2hex(openssl_random_pseudo_bytes(16)); } + ?> -'); - if($_SESSION['api_token'] === TRUE) - { - echo(" - "); + "; unset($_SESSION['api_token']); - } -echo(' +} + +echo '
    @@ -127,19 +125,17 @@ echo(' Disabled Remove -'); +'; - foreach (dbFetchRows("SELECT `AT`.*,`U`.`username` FROM `api_tokens` AS AT JOIN users AS U ON AT.user_id=U.user_id ORDER BY AT.user_id") as $api) - { - if($api['disabled'] == '1') - { - $api_disabled = 'checked'; +foreach (dbFetchRows('SELECT `AT`.*,`U`.`username` FROM `api_tokens` AS AT JOIN users AS U ON AT.user_id=U.user_id ORDER BY AT.user_id') as $api) { + if ($api['disabled'] == '1') { + $api_disabled = 'checked'; } - else - { - $api_disabled = ''; + else { + $api_disabled = ''; } - echo(' + + echo ' '.$api['username'].' '.$api['token_hash'].' @@ -147,14 +143,14 @@ echo(' -'); - } +'; +} - echo(' + echo '
    -'); +'; ?> +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index c260b73cec..d3bd68b840 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -17,8 +17,7 @@
    here.'); +print_error('Documentation for the API has now been moved to GitHub, you can go straight to the API Wiki from here.'); ?>
    - diff --git a/html/pages/apps.inc.php b/html/pages/apps.inc.php index 1a20acc41f..cfd2378dde 100644 --- a/html/pages/apps.inc.php +++ b/html/pages/apps.inc.php @@ -1,54 +1,91 @@ Apps » "); +echo "Apps » "; unset($sep); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'apps'); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'apps', +); -foreach ($app_list as $app) -{ - echo($sep); +foreach ($app_list as $app) { + echo $sep; -# if (!$vars['app']) { $vars['app'] = $app['app_type']; } + // if (!$vars['app']) { $vars['app'] = $app['app_type']; } + if ($vars['app'] == $app['app_type']) { + echo ""; + // echo(''); + } + else { + // echo(''); + } - if ($vars['app'] == $app['app_type']) - { - echo(""); - #echo(''); - } else { - #echo(''); - } - echo(generate_link(nicecase($app['app_type']),array('page'=>'apps','app'=>$app['app_type']))); - if ($vars['app'] == $app['app_type']) { echo(""); } - $sep = " | "; + echo generate_link(nicecase($app['app_type']), array('page' => 'apps', 'app' => $app['app_type'])); + if ($vars['app'] == $app['app_type']) { + echo ''; + } + + $sep = ' | '; } print_optionbar_end(); -if($vars['app']) -{ - if (is_file("pages/apps/".mres($vars['app']).".inc.php")) - { - include("pages/apps/".mres($vars['app']).".inc.php"); - } else { - include("pages/apps/default.inc.php"); - } -} else { - include("pages/apps/overview.inc.php"); +if ($vars['app']) { + if (is_file('pages/apps/'.mres($vars['app']).'.inc.php')) { + include 'pages/apps/'.mres($vars['app']).'.inc.php'; + } + else { + include 'pages/apps/default.inc.php'; + } +} +else { + include 'pages/apps/overview.inc.php'; } -$pagetitle[] = "Apps"; -?> +$pagetitle[] = 'Apps'; diff --git a/html/pages/apps/default.inc.php b/html/pages/apps/default.inc.php index e333674057..bf752de29c 100644 --- a/html/pages/apps/default.inc.php +++ b/html/pages/apps/default.inc.php @@ -1,45 +1,41 @@ '.nicecase($vars['app']).''); -echo(''); -$app_devices = dbFetchRows("SELECT * FROM `devices` AS D, `applications` AS A WHERE D.device_id = A.device_id AND A.app_type = ?", array($vars['app'])); +echo '

    '.nicecase($vars['app']).'

    '; +echo '
    '; +$app_devices = dbFetchRows('SELECT * FROM `devices` AS D, `applications` AS A WHERE D.device_id = A.device_id AND A.app_type = ?', array($vars['app'])); -foreach ($app_devices as $app_device) -{ - echo(''); - echo(''); - echo(''); - echo(''); - echo(''); - echo(''); - echo(''); - echo(''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''); - echo(''); -} + echo ''; + echo ''; +}//end foreach -echo('
    '.generate_device_link($app_device, shorthost($app_device['hostname']), array('tab'=>'apps','app'=>$vars['app'])).''.$app_device['app_instance'].''.$app_device['app_status'].'
    '); +foreach ($app_devices as $app_device) { + echo '
    '.generate_device_link($app_device, shorthost($app_device['hostname']), array('tab' => 'apps', 'app' => $vars['app'])).''.$app_device['app_instance'].''.$app_device['app_status'].'
    '; - foreach ($graphs[$vars['app']] as $graph_type) - { - $graph_array['type'] = "application_".$vars['app']."_".$graph_type; - $graph_array['id'] = $app_device['app_id']; - $graph_array_zoom['type'] = "application_".$vars['app']."_".$graph_type; - $graph_array_zoom['id'] = $app_device['app_id']; + foreach ($graphs[$vars['app']] as $graph_type) { + $graph_array['type'] = 'application_'.$vars['app'].'_'.$graph_type; + $graph_array['id'] = $app_device['app_id']; + $graph_array_zoom['type'] = 'application_'.$vars['app'].'_'.$graph_type; + $graph_array_zoom['id'] = $app_device['app_id']; - $link = generate_url(array('page' => 'device', 'device' => $app_device['device_id'],'tab'=>'apps','app'=>$vars['app'])); + $link = generate_url(array('page' => 'device', 'device' => $app_device['device_id'], 'tab' => 'apps', 'app' => $vars['app'])); - echo(overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL)); - } + echo overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + } - echo('
    '); - -?> +echo ''; diff --git a/html/pages/authlog.inc.php b/html/pages/authlog.inc.php index 64b4080ad2..3cffbbea9e 100644 --- a/html/pages/authlog.inc.php +++ b/html/pages/authlog.inc.php @@ -1,37 +1,37 @@ = '10') -{ - echo(""); +if ($_SESSION['userlevel'] >= '10') { + echo '
    '; - foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) - { - if ($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } + foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) { + if ($bg == $list_colour_a) { + $bg = $list_colour_b; + } + else { + $bg = $list_colour_a; + } - echo(" - - - - - - "); - } + echo " + + + + + + '; + }//end foreach - $pagetitle[] = "Authlog"; + $pagetitle[] = 'Authlog'; - echo("
    - " . $entry['datetime'] . " - - ".$entry['user']." - - ".$entry['address']." - - ".$entry['result']." -
    + ".$entry['datetime'].' + + '.$entry['user'].' + + '.$entry['address'].' + + '.$entry['result'].' +
    "); + echo ''; } -else -{ - include("includes/error-no-perm.inc.php"); -} - -?> +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php index 13b640057b..03faf35c17 100644 --- a/html/pages/bill.inc.php +++ b/html/pages/bill.inc.php @@ -2,255 +2,274 @@ $bill_id = mres($vars['bill_id']); -if ($_SESSION['userlevel'] >= "10") -{ - include("pages/bill/actions.inc.php"); +if ($_SESSION['userlevel'] >= '10') { + include 'pages/bill/actions.inc.php'; } -if (bill_permitted($bill_id)) -{ - $bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)); +if (bill_permitted($bill_id)) { + $bill_data = dbFetchRow('SELECT * FROM bills WHERE bill_id = ?', array($bill_id)); - $bill_name = $bill_data['bill_name']; + $bill_name = $bill_data['bill_name']; - $today = str_replace("-", "", dbFetchCell("SELECT CURDATE()")); - $yesterday = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)")); - $tomorrow = str_replace("-", "", dbFetchCell("SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)")); - $last_month = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")); + $today = str_replace('-', '', dbFetchCell('SELECT CURDATE()')); + $yesterday = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)')); + $tomorrow = str_replace('-', '', dbFetchCell('SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)')); + $last_month = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)')); - $rightnow = $today . date(His); - $before = $yesterday . date(His); - $lastmonth = $last_month . date(His); + $rightnow = $today.date(His); + $before = $yesterday.date(His); + $lastmonth = $last_month.date(His); - $bill_name = $bill_data['bill_name']; - $dayofmonth = $bill_data['bill_day']; + $bill_name = $bill_data['bill_name']; + $dayofmonth = $bill_data['bill_day']; - $day_data = getDates($dayofmonth); + $day_data = getDates($dayofmonth); - $datefrom = $day_data['0']; - $dateto = $day_data['1']; - $lastfrom = $day_data['2']; - $lastto = $day_data['3']; + $datefrom = $day_data['0']; + $dateto = $day_data['1']; + $lastfrom = $day_data['2']; + $lastto = $day_data['3']; - $rate_95th = $bill_data['rate_95th']; - $dir_95th = $bill_data['dir_95th']; - $total_data = $bill_data['total_data']; - $rate_average = $bill_data['rate_average']; + $rate_95th = $bill_data['rate_95th']; + $dir_95th = $bill_data['dir_95th']; + $total_data = $bill_data['total_data']; + $rate_average = $bill_data['rate_average']; - if ($rate_95th > $paid_kb) - { - $over = $rate_95th - $paid_kb; - $bill_text = $over . "Kbit excess."; - $bill_color = "#cc0000"; - } - else - { - $under = $paid_kb - $rate_95th; - $bill_text = $under . "Kbit headroom."; - $bill_color = "#0000cc"; - } - - $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); - $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); - $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); - $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); - - $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); - $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); - # Speeds up loading for other included pages by setting it before progessing of mysql data! - - $ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D - WHERE B.bill_id = ? AND P.port_id = B.port_id - AND D.device_id = P.device_id", array($bill_id)); - - echo("

    - Bill : " . $bill_data['bill_name'] . "

    "); - - print_optionbar_start(); - - echo("Bill » "); - - if (!$vars['view']) { $vars['view'] = "quick"; } - - if ($vars['view'] == "quick") { echo(""); } - echo('Quick Graphs'); - if ($vars['view'] == "quick") { echo(""); } - - echo(" | "); - - if ($vars['view'] == "accurate") { echo(""); } - echo('Accurate Graphs'); - if ($vars['view'] == "accurate") { echo(""); } - - echo(" | "); - - if ($vars['view'] == "transfer") { echo(""); } - echo('Transfer Graphs'); - if ($vars['view'] == "transfer") { echo(""); } - - echo(" | "); - - if ($vars['view'] == "history") { echo(""); } - echo('Historical Usage'); - if ($vars['view'] == "history") { echo(""); } - - if ($_SESSION['userlevel'] >= "10") - { - echo(" | "); - if ($vars['view'] == "edit") { echo(""); } - echo('Edit'); - if ($vars['view'] == "edit") { echo(""); } - - echo(" | "); - if ($vars['view'] == "delete") { echo(""); } - echo('Delete'); - if ($vars['view'] == "delete") { echo(""); } - - echo(" | "); - if ($vars['view'] == "reset") { echo(""); } - echo('Reset'); - if ($vars['view'] == "reset") { echo(""); } - } - - echo(''); - - print_optionbar_end(); - - if ($vars['view'] == "edit" && $_SESSION['userlevel'] >= "10") - { - include("pages/bill/edit.inc.php"); - } - elseif ($vars['view'] == "delete" && $_SESSION['userlevel'] >= "10") - { - include("pages/bill/delete.inc.php"); - } - elseif ($vars['view'] == "reset" && $_SESSION['userlevel'] >= "10") - { - include("pages/bill/reset.inc.php"); - } - elseif ($vars['view'] == "history") - { - include("pages/bill/history.inc.php"); - } - elseif ($vars['view'] == "transfer") - { - include("pages/bill/transfer.inc.php"); - } - elseif ($vars['view'] == "quick" || $vars['view'] == "accurate") { - - echo("

    Billed Ports

    "); - - // Collected Earlier - foreach ($ports as $port) - { - echo(generate_port_link($port) . " on " . generate_device_link($port) . "
    "); + if ($rate_95th > $paid_kb) { + $over = ($rate_95th - $paid_kb); + $bill_text = $over.'Kbit excess.'; + $bill_color = '#cc0000'; + } + else { + $under = ($paid_kb - $rate_95th); + $bill_text = $under.'Kbit headroom.'; + $bill_color = '#0000cc'; } - echo("

    Bill Summary

    "); + $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); + $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); + $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); + $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); - if ($bill_data['bill_type'] == "quota") - { - // The Customer is billed based on a pre-paid quota with overage in xB + $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); + $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); + // Speeds up loading for other included pages by setting it before progessing of mysql data! + $ports = dbFetchRows( + 'SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D + WHERE B.bill_id = ? AND P.port_id = B.port_id + AND D.device_id = P.device_id', + array($bill_id) + ); - echo("

    Quota Bill

    "); + echo '

    + Bill : '.$bill_data['bill_name'].'

    '; - $percent = round(($total_data) / $bill_data['bill_quota'] * 100, 2); - $unit = "MB"; - $total_data = round($total_data, 2); - echo("Billing Period from " . $fromtext . " to " . $totext); - echo("
    Transferred ".format_bytes_billing($total_data)." of ".format_bytes_billing($bill_data['bill_quota'])." (".$percent."%)"); - echo("
    Average rate " . formatRates($rate_average)); + print_optionbar_start(); - $background = get_percentage_colours($percent); + echo "Bill » "; - echo("

    ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

    "); - - $type="&ave=yes"; - } - elseif ($bill_data['bill_type'] == "cdr") - { - // The customer is billed based on a CDR with 95th%ile overage - - echo("

    CDR / 95th Bill

    "); - - $unit = "kbps"; - $cdr = $bill_data['bill_cdr']; - $rate_95th = round($rate_95th, 2); - - $percent = round(($rate_95th) / $cdr * 100, 2); - - $type="&95th=yes"; - - echo("" . $fromtext . " to " . $totext . " -
    Measured ".format_si($rate_95th)."bps of ".format_si($cdr)."bps (".$percent."%) @ 95th %ile"); - - $background = get_percentage_colours($percent); - - echo("

    ".print_percentage_bar (350, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

    "); - - # echo("

    Billing Period : " . $fromtext . " to " . $totext . "
    - # " . $paidrate_text . "
    - # " . $total_data . "MB transfered in the current billing cycle.
    - # " . $rate_average . "Kbps Average during the current billing cycle.

    - # " . $rate_95th . "Kbps @ 95th Percentile. (" . $dir_95th . ") (" . $bill_text . ") - # - #
    "); + if (!$vars['view']) { + $vars['view'] = 'quick'; } - $lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"); - $yesterday = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))"); - $rightnow = date(U); - - if ($vars['view'] == "accurate") { - - $bi = ""; - - $li = ""; - - $di = ""; - - $mi = ""; - + if ($vars['view'] == 'quick') { + echo ""; } - if ($null) - { - echo(" - @@ -268,39 +287,32 @@ if (bill_permitted($bill_id)) - "); + "; + }//end if - } - - if ($_GET['all']) - { - $ai = ""; - echo("

    Entire Data View

    $ai"); - } - elseif ($_GET['custom']) - { - $cg = ""; - echo("

    Custom Graph

    $cg"); - } - else - { - echo("

    Billing View

    $bi"); -# echo("

    Previous Bill View

    $li"); - echo("

    24 Hour View

    $di"); - echo("

    Monthly View

    $mi"); -# echo("
    Graph All Data (SLOW)"); - } - } # End if details + if ($_GET['all']) { + $ai = ''; + echo "

    Entire Data View

    $ai"; + } + else if ($_GET['custom']) { + $cg = ''; + echo "

    Custom Graph

    $cg"; + } + else { + echo "

    Billing View

    $bi"; + // echo("

    Previous Bill View

    $li"); + echo "

    24 Hour View

    $di"; + echo "

    Monthly View

    $mi"; + // echo("
    Graph All Data (SLOW)"); + }//end if + } //end if } -else -{ - include("includes/error-no-perm.inc.php"); -} - -?> +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/bill/actions.inc.php b/html/pages/bill/actions.inc.php index d55c2944cc..29afb6d3b4 100644 --- a/html/pages/bill/actions.inc.php +++ b/html/pages/bill/actions.inc.php @@ -1,8 +1,7 @@ = 1) { + $quota = array( + 'type' => 'tb', + 'select_tb' => ' selected', + 'data' => $tmp['tb'], + ); + } + else if (($tmp['gb'] >= 1) and ($tmp['gb'] < $base)) { + $quota = array( + 'type' => 'gb', + 'select_gb' => ' selected', + 'data' => $tmp['gb'], + ); + } + else if (($tmp['mb'] >= 1) and ($tmp['mb'] < $base)) { + $quota = array( + 'type' => 'mb', + 'select_mb' => ' selected', + 'data' => $tmp['mb'], + ); + } +}//end if -if ($bill_data['bill_type'] == "quota") { - $data = $bill_data['bill_quota']; - $tmp['mb'] = $data / $base / $base; - $tmp['gb'] = $data / $base / $base / $base; - $tmp['tb'] = $data / $base / $base / $base / $base; - if ($tmp['tb']>=1) { $quota = array("type" => "tb", "select_tb" => " selected", "data" => $tmp['tb']); } - elseif (($tmp['gb']>=1) and ($tmp['gb']<$base)) { $quota = array("type" => "gb", "select_gb" => " selected", "data" => $tmp['gb']); } - elseif (($tmp['mb']>=1) and ($tmp['mb']<$base)) { $quota = array("type" => "mb", "select_mb" => " selected", "data" => $tmp['mb']); } -} -if ($bill_data['bill_type'] == "cdr") { - $data = $bill_data['bill_cdr']; - $tmp['kbps'] = $data / $base; - $tmp['mbps'] = $data / $base / $base; - $tmp['gbps'] = $data / $base / $base / $base; - if ($tmp['gbps']>=1) { $cdr = array("type" => "gbps", "select_gbps" => " selected", "data" => $tmp['gbps']); } - elseif (($tmp['mbps']>=1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_mbps" => " selected", "data" => $tmp['mbps']); } - elseif (($tmp['kbps']>=1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_kbps" => " selected", "data" => $tmp['kbps']); } -} +if ($bill_data['bill_type'] == 'cdr') { + $data = $bill_data['bill_cdr']; + $tmp['kbps'] = ($data / $base); + $tmp['mbps'] = ($data / $base / $base); + $tmp['gbps'] = ($data / $base / $base / $base); + if ($tmp['gbps'] >= 1) { + $cdr = array( + 'type' => 'gbps', + 'select_gbps' => ' selected', + 'data' => $tmp['gbps'], + ); + } + else if (($tmp['mbps'] >= 1) and ($tmp['mbps'] < $base)) { + $cdr = array( + 'type' => 'mbps', + 'select_mbps' => ' selected', + 'data' => $tmp['mbps'], + ); + } + else if (($tmp['kbps'] >= 1) and ($tmp['kbps'] < $base)) { + $cdr = array( + 'type' => 'kbps', + 'select_kbps' => ' selected', + 'data' => $tmp['kbps'], + ); + } +}//end if ?>
    - +

    Bill Properties

    - " /> +
    @@ -51,17 +86,35 @@ if ($bill_data['bill_type'] == "cdr") {
    - -
    @@ -121,19 +124,19 @@ foreach ($config['device_types'] as $type)
    - value="" /> + value="" />
    - /> + />
    - /> + />
    diff --git a/html/pages/device/edit/health.inc.php b/html/pages/device/edit/health.inc.php index 3d7d213527..922bb36c77 100644 --- a/html/pages/device/edit/health.inc.php +++ b/html/pages/device/edit/health.inc.php @@ -30,156 +30,158 @@ $sensor['sensor_id'], 'sensor_limit' => $sensor['sensor_limit'], 'sensor_limit_low' => $sensor['sensor_limit_low'], 'sensor_alert' => $sensor['sensor_alert']); - if($sensor['sensor_alert'] == 1) - { - $alert_status = 'checked'; - } - else - { - $alert_status = ''; - } - if ($sensor['sensor_custom'] == 'No') { - $custom = 'disabled'; - } else { - $custom = ''; - } - echo(' - - '.$sensor['sensor_class'].' - '.$sensor['sensor_type'].' - '.$sensor['sensor_descr'].' - '.$sensor['sensor_current'].' - -
    +foreach (dbFetchRows("SELECT * FROM sensors WHERE device_id = ? AND sensor_deleted='0'", array($device['device_id'])) as $sensor) { + $rollback[] = array( + 'sensor_id' => $sensor['sensor_id'], + 'sensor_limit' => $sensor['sensor_limit'], + 'sensor_limit_low' => $sensor['sensor_limit_low'], + 'sensor_alert' => $sensor['sensor_alert'], + ); + if ($sensor['sensor_alert'] == 1) { + $alert_status = 'checked'; + } + else { + $alert_status = ''; + } + + if ($sensor['sensor_custom'] == 'No') { + $custom = 'disabled'; + } + else { + $custom = ''; + } + + echo ' + + '.$sensor['sensor_class'].' + '.$sensor['sensor_type'].' + '.$sensor['sensor_descr'].' + '.$sensor['sensor_current'].' + +
    -
    - - -
    +
    + + +
    -
    - - - - - +
    + + + + + Clear custom - - -'); + + + '; } - ?>
    - - - - '); +foreach ($rollback as $reset_data) { + echo ' + + + + + '; } ?>
    - diff --git a/html/pages/device/edit/ipmi.inc.php b/html/pages/device/edit/ipmi.inc.php index f3971ca413..0aff50bdd7 100644 --- a/html/pages/device/edit/ipmi.inc.php +++ b/html/pages/device/edit/ipmi.inc.php @@ -1,31 +1,45 @@ "7") - { - $ipmi_hostname = mres($_POST['ipmi_hostname']); - $ipmi_username = mres($_POST['ipmi_username']); - $ipmi_password = mres($_POST['ipmi_password']); +if ($_POST['editing']) { + if ($_SESSION['userlevel'] > '7') { + $ipmi_hostname = mres($_POST['ipmi_hostname']); + $ipmi_username = mres($_POST['ipmi_username']); + $ipmi_password = mres($_POST['ipmi_password']); - if ($ipmi_hostname != '') { set_dev_attrib($device, 'ipmi_hostname', $ipmi_hostname); } else { del_dev_attrib($device, 'ipmi_hostname'); } - if ($ipmi_username != '') { set_dev_attrib($device, 'ipmi_username', $ipmi_username); } else { del_dev_attrib($device, 'ipmi_username'); } - if ($ipmi_password != '') { set_dev_attrib($device, 'ipmi_password', $ipmi_password); } else { del_dev_attrib($device, 'ipmi_password'); } + if ($ipmi_hostname != '') { + set_dev_attrib($device, 'ipmi_hostname', $ipmi_hostname); + } + else { + del_dev_attrib($device, 'ipmi_hostname'); + } - $update_message = "Device IPMI data updated."; - $updated = 1; - } - else - { - include("includes/error-no-perm.inc.php"); - } + if ($ipmi_username != '') { + set_dev_attrib($device, 'ipmi_username', $ipmi_username); + } + else { + del_dev_attrib($device, 'ipmi_username'); + } + + if ($ipmi_password != '') { + set_dev_attrib($device, 'ipmi_password', $ipmi_password); + } + else { + del_dev_attrib($device, 'ipmi_password'); + } + + $update_message = 'Device IPMI data updated.'; + $updated = 1; + } + else { + include 'includes/error-no-perm.inc.php'; + }//end if +}//end if + +if ($updated && $update_message) { + print_message($update_message); } - -if ($updated && $update_message) -{ - print_message($update_message); -} elseif ($update_message) { - print_error($update_message); +else if ($update_message) { + print_error($update_message); } ?> @@ -37,19 +51,19 @@ if ($updated && $update_message)
    - +
    - +
    - +
    diff --git a/html/pages/device/edit/modules.inc.php b/html/pages/device/edit/modules.inc.php index 36a53b3f10..3196171626 100644 --- a/html/pages/device/edit/modules.inc.php +++ b/html/pages/device/edit/modules.inc.php @@ -17,68 +17,57 @@ $module_status) -{ - echo(' +foreach ($config['poller_modules'] as $module => $module_status) { + echo(' '.$module.' -'); + '); - if($module_status == 1) - { - echo('Enabled'); - } - else - { - echo('Disabled'); - } + if($module_status == 1) { + echo('Enabled'); + } + else { + echo('Disabled'); + } - echo(' + echo(' -'); + '); - if (isset($attribs['poll_'.$module])) - { - if ($attribs['poll_'.$module]) - { - echo('Enabled'); - $module_checked = 'checked'; + if (isset($attribs['poll_'.$module])) { + if ($attribs['poll_'.$module]) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - else - { - echo('Disabled'); - $module_checked = ''; + else { + if($module_status == 1) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - } - else - { - if($module_status == 1) - { - echo('Enabled'); - $module_checked = 'checked'; - } - else - { - echo('Disabled'); - $module_checked = ''; - } - } - echo(' + echo(' -'); + '); - echo(' - -'); + echo(''); - echo(' + echo(' -'); + '); } ?> @@ -96,71 +85,56 @@ foreach ($config['poller_modules'] as $module => $module_status) $module_status) -{ - - echo(' +foreach ($config['discovery_modules'] as $module => $module_status) { + echo(' '.$module.' -'); + '); - if($module_status == 1) - { - echo('Enabled'); - } - else - { - echo('Disabled'); - } + if($module_status == 1) { + echo('Enabled'); + } + else { + echo('Disabled'); + } - echo(' + echo(' - -'); + '); - if (isset($attribs['discover_'.$module])) - { - if($attribs['discover_'.$module]) - { - echo('Enabled'); - $module_checked = 'checked'; + if (isset($attribs['discover_'.$module])) { + if($attribs['discover_'.$module]) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - else - { - echo('Disabled'); - $module_checked = ''; + else { + if($module_status == 1) { + echo('Enabled'); + $module_checked = 'checked'; + } + else { + echo('Disabled'); + $module_checked = ''; + } } - } - else - { - if($module_status == 1) - { - echo('Enabled'); - $module_checked = 'checked'; - } - else - { - echo('Disabled'); - $module_checked = ''; - } - } - echo(' + echo(' - -'); + '); - echo(' - -'); + echo(''); - echo(' + echo(' - -'); + '); } echo(' diff --git a/html/pages/device/edit/ports.inc.php b/html/pages/device/edit/ports.inc.php index b382cf05a8..d8dc562e43 100644 --- a/html/pages/device/edit/ports.inc.php +++ b/html/pages/device/edit/ports.inc.php @@ -1,28 +1,26 @@ '); +echo '
    '; -if ($_POST['ignoreport']) -{ - if ($_SESSION['userlevel'] == '10') - { - include("includes/port-edit.inc.php"); - } +if ($_POST['ignoreport']) { + if ($_SESSION['userlevel'] == '10') { + include 'includes/port-edit.inc.php'; + } } -if ($updated && $update_message) -{ - print_message($update_message); -} elseif ($update_message) { - print_error($update_message); +if ($updated && $update_message) { + print_message($update_message); +} +else if ($update_message) { + print_error($update_message); } -echo("
    +echo "
    - "); + "; -echo(" +echo "
    @@ -41,14 +39,14 @@ echo("
    Index Name
    -"); +"; ?> '; + echo ''; + echo ''; + echo ''; - echo(""); - echo(""); - echo(""); - echo(""); + // Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled + // - as to draw the attention to a possible problem. + $isportbad = ($port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] != 'down') ? 1 : 0; + $dowecare = ($port['ignore'] == 0 && $port['disabled'] == 0) ? $isportbad : !$isportbad; + $outofsync = $dowecare ? " class='red'" : ''; - # Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled - # - as to draw the attention to a possible problem. - $isportbad = ($port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] != 'down') ? 1 : 0; - $dowecare = ($port['ignore'] == 0 && $port['disabled'] == 0) ? $isportbad : !$isportbad; - $outofsync = $dowecare ? " class='red'" : ""; + echo "'; - echo(""); + echo '"); + echo '"); - echo(""); + echo "\n"; - echo("\n"); + $row++; +}//end foreach - $row++; -} - -echo('
    '.$port['ifIndex'].''.$port['label'].''.$port['ifAdminStatus'].'
    ". $port['ifIndex']."".$port['label'] . "". $port['ifAdminStatus']."'.$port['ifOperStatus'].'". $port['ifOperStatus']."'; + echo "'; + echo ""); - echo(""); - echo(""); - echo("'; + echo "'; + echo ""); - echo(""); - echo(""); - echo("".$port['ifAlias'] . "
    '); -echo('
    '); -echo('
    '); - -?> +echo ''; +echo ''; +echo '
    '; diff --git a/html/pages/device/edit/services.inc.php b/html/pages/device/edit/services.inc.php index e6969a9fe9..1f2bc1d30e 100644 --- a/html/pages/device/edit/services.inc.php +++ b/html/pages/device/edit/services.inc.php @@ -1,29 +1,28 @@ = '10') { - include("includes/service-add.inc.php"); + include 'includes/service-add.inc.php'; } } if ($_POST['delsrv']) { if ($_SESSION['userlevel'] >= '10') { - include("includes/service-delete.inc.php"); + include 'includes/service-delete.inc.php'; } } if ($_POST['confirm-editsrv']) { - echo "yeah"; + echo 'yeah'; if ($_SESSION['userlevel'] >= '10') { - include("includes/service-edit.inc.php"); + include 'includes/service-edit.inc.php'; } } - if ($handle = opendir($config['install_dir'] . "/includes/services/")) { + if ($handle = opendir($config['install_dir'].'/includes/services/')) { while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != ".." && !strstr($file, ".")) { + if ($file != '.' && $file != '..' && !strstr($file, '.')) { $servicesform .= ""; } } @@ -31,17 +30,17 @@ if (is_admin() === TRUE || is_read() === TRUE) { closedir($handle); } - $dev = device_by_id_cache($device['device_id']); - $devicesform = ""; + $dev = device_by_id_cache($device['device_id']); + $devicesform = "'; if ($updated) { - print_message("Device Settings Saved"); + print_message('Device Settings Saved'); } - if (dbFetchCell("SELECT COUNT(*) from `services` WHERE `device_id` = ?", array($device['device_id'])) > '0') { - $i = "1"; - foreach (dbFetchRows("select * from services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $service) { - $existform .= ""; + if (dbFetchCell('SELECT COUNT(*) from `services` WHERE `device_id` = ?', array($device['device_id'])) > '0') { + $i = '1'; + foreach (dbFetchRows('select * from services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $service) { + $existform .= "'; } } @@ -49,28 +48,29 @@ if (is_admin() === TRUE || is_read() === TRUE) { if ($existform) { echo '
    '; - if ($_POST['editsrv'] == "yes") { - include_once "includes/print-service-edit.inc.php"; - } else { + if ($_POST['editsrv'] == 'yes') { + include_once 'includes/print-service-edit.inc.php'; + } + else { echo " -

    Edit / Delete Service

    -
    +

    Edit / Delete Service

    +
    -
    - -
    - -
    -
    -
    -
    - -
    -
    +
    + +
    +
    - "; +
    +
    +
    + +
    +
    +
    + "; } echo '
    '; @@ -78,8 +78,8 @@ if (is_admin() === TRUE || is_read() === TRUE) { echo '
    '; - require_once "includes/print-service-add.inc.php"; - -} else { - include("includes/error-no-perm.inc.php"); -} \ No newline at end of file + include_once 'includes/print-service-add.inc.php'; +} +else { + include 'includes/error-no-perm.inc.php'; +} diff --git a/html/pages/device/edit/snmp.inc.php b/html/pages/device/edit/snmp.inc.php index 9e8a5b7b04..59c6bf4cd3 100644 --- a/html/pages/device/edit/snmp.inc.php +++ b/html/pages/device/edit/snmp.inc.php @@ -1,225 +1,240 @@ "7") - { - $community = mres($_POST['community']); - $snmpver = mres($_POST['snmpver']); - $transport = $_POST['transport'] ? mres($_POST['transport']) : $transport = "udp"; - $port = $_POST['port'] ? mres($_POST['port']) : $config['snmp']['port']; - $timeout = mres($_POST['timeout']); - $retries = mres($_POST['retries']); - $poller_group = mres($_POST['poller_group']); - $v3 = array ( - 'authlevel' => mres($_POST['authlevel']), - 'authname' => mres($_POST['authname']), - 'authpass' => mres($_POST['authpass']), - 'authalgo' => mres($_POST['authalgo']), - 'cryptopass' => mres($_POST['cryptopass']), - 'cryptoalgo' => mres($_POST['cryptoalgo']) - ); +if ($_POST['editing']) { + if ($_SESSION['userlevel'] > '7') { + $community = mres($_POST['community']); + $snmpver = mres($_POST['snmpver']); + $transport = $_POST['transport'] ? mres($_POST['transport']) : $transport = 'udp'; + $port = $_POST['port'] ? mres($_POST['port']) : $config['snmp']['port']; + $timeout = mres($_POST['timeout']); + $retries = mres($_POST['retries']); + $poller_group = mres($_POST['poller_group']); + $v3 = array( + 'authlevel' => mres($_POST['authlevel']), + 'authname' => mres($_POST['authname']), + 'authpass' => mres($_POST['authpass']), + 'authalgo' => mres($_POST['authalgo']), + 'cryptopass' => mres($_POST['cryptopass']), + 'cryptoalgo' => mres($_POST['cryptoalgo']), + ); - #FIXME needs better feedback - $update = array( - 'community' => $community, - 'snmpver' => $snmpver, - 'port' => $port, - 'transport' => $transport, - 'poller_group' => $poller_group - ); + // FIXME needs better feedback + $update = array( + 'community' => $community, + 'snmpver' => $snmpver, + 'port' => $port, + 'transport' => $transport, + 'poller_group' => $poller_group, + ); - if ($_POST['timeout']) { $update['timeout'] = $timeout; } - else { $update['timeout'] = array('NULL'); } - if ($_POST['retries']) { $update['retries'] = $retries; } - else { $update['retries'] = array('NULL'); } - - $update = array_merge($update, $v3); - - $device_tmp = deviceArray($device['hostname'], $community, $snmpver, $port, $transport, $v3); - if (isSNMPable($device_tmp)) { - $rows_updated = dbUpdate($update, 'devices', '`device_id` = ?',array($device['device_id'])); - - if ($rows_updated > 0) { - $update_message = $rows_updated . " Device record updated."; - $updated = 1; - } elseif ($rows_updated = '-1') { - $update_message = "Device record unchanged. No update necessary."; - $updated = -1; - } else { - $update_message = "Device record update error."; - $updated = 0; + if ($_POST['timeout']) { + $update['timeout'] = $timeout; + } + else { + $update['timeout'] = array('NULL'); } - } else { - $update_message = "Could not connect to device with new SNMP details"; - $updated = 0; - } - } -} -$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id'])); + if ($_POST['retries']) { + $update['retries'] = $retries; + } + else { + $update['retries'] = array('NULL'); + } + + $update = array_merge($update, $v3); + + $device_tmp = deviceArray($device['hostname'], $community, $snmpver, $port, $transport, $v3); + if (isSNMPable($device_tmp)) { + $rows_updated = dbUpdate($update, 'devices', '`device_id` = ?', array($device['device_id'])); + + if ($rows_updated > 0) { + $update_message = $rows_updated.' Device record updated.'; + $updated = 1; + } + else if ($rows_updated = '-1') { + $update_message = 'Device record unchanged. No update necessary.'; + $updated = -1; + } + else { + $update_message = 'Device record update error.'; + $updated = 0; + } + } + else { + $update_message = 'Could not connect to device with new SNMP details'; + $updated = 0; + } + }//end if +}//end if + +$device = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($device['device_id'])); $descr = $device['purpose']; -echo('
    -
    '); -if ($updated && $update_message) -{ - print_message($update_message); -} elseif ($update_message) { - print_error($update_message); +echo '
    +
    '; +if ($updated && $update_message) { + print_message($update_message); +} +else if ($update_message) { + print_error($update_message); } -echo('
    -
    '); -echo(" -
    - -
    +echo '
    +
    '; + +echo " + + +
    - +
    - +
    - "; foreach ($config['snmp']['transports'] as $transport) { - echo(""); + + echo '>'.$transport.''; } -echo(" + +echo "
    -
    -
    +
    +
    - +
    - +
    -
    -
    +
    +
    - +
    - -
    - -
    + +
    +
    -
    -
    +
    +
    +
    - +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    +
    -
    "); +
    +
    '; -if ($config['distributed_poller'] === TRUE) { - echo(' -
    - -
    - + + '; - foreach (dbFetchRows("SELECT `id`,`group_name` FROM `poller_groups`") as $group) { - echo ''; + + echo '>'.$group['group_name'].''; } - echo(' - -
    -
    - '); -} + echo ' + +
    +
    + '; +}//end if -echo(' - - -'); +echo ' + + + '; ?> diff --git a/html/pages/device/entphysical.inc.php b/html/pages/device/entphysical.inc.php index af167b4ddc..7b5d956faa 100644 --- a/html/pages/device/entphysical.inc.php +++ b/html/pages/device/entphysical.inc.php @@ -1,13 +1,11 @@ "; @@ -33,7 +31,8 @@ function printEntPhysical($ent, $level, $class) if (count($sensor)) { $link = " href='device/device=".$device['device_id'].'/tab=health/metric='.$sensor['sensor_class']."/' onmouseover=\"return overlib('', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\""; } - } else { + } + else { unset($link); } diff --git a/html/pages/device/graphs.inc.php b/html/pages/device/graphs.inc.php index a275e71e31..e4bd13d84c 100644 --- a/html/pages/device/graphs.inc.php +++ b/html/pages/device/graphs.inc.php @@ -1,70 +1,68 @@ 'device', + 'device' => $device['device_id'], + 'tab' => 'graphs', +); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'graphs'); +$bg = '#ffffff'; -$bg="#ffffff"; - -echo('
    '); +echo '
    '; print_optionbar_start(); -echo("Graphs » "); +echo "Graphs » "; -foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph", array($device['device_id'])) as $graph) -{ - $section = $config['graph_types']['device'][$graph['graph']]['section']; - if ($section != "") { - $graph_enable[$section][$graph['graph']] = $graph['graph']; - } +foreach (dbFetchRows('SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph', array($device['device_id'])) as $graph) { + $section = $config['graph_types']['device'][$graph['graph']]['section']; + if ($section != '') { + $graph_enable[$section][$graph['graph']] = $graph['graph']; + } } // These are standard graphs we should have for all systems $graph_enable['poller']['poller_perf'] = 'device_poller_perf'; -$graph_enable['poller']['ping_perf'] = 'device_ping_perf'; +$graph_enable['poller']['ping_perf'] = 'device_ping_perf'; -$sep = ""; -foreach ($graph_enable as $section => $nothing) -{ - if (isset($graph_enable) && is_array($graph_enable[$section])) - { - $type = strtolower($section); - if (!$vars['group']) { $vars['group'] = $type; } - echo($sep); - if ($vars['group'] == $type) - { - echo(''); +$sep = ''; +foreach ($graph_enable as $section => $nothing) { + if (isset($graph_enable) && is_array($graph_enable[$section])) { + $type = strtolower($section); + if (!$vars['group']) { + $vars['group'] = $type; + } + + echo $sep; + if ($vars['group'] == $type) { + echo ''; + } + + echo generate_link(ucwords($type), $link_array, array('group' => $type)); + if ($vars['group'] == $type) { + echo ''; + } + + $sep = ' | '; } - echo(generate_link(ucwords($type),$link_array,array('group'=>$type))); - if ($vars['group'] == $type) - { - echo(""); - } - $sep = " | "; - } } -unset ($sep); + +unset($sep); print_optionbar_end(); $graph_enable = $graph_enable[$vars['group']]; -#foreach ($config['graph_types']['device'] as $graph => $entry) -foreach ($graph_enable as $graph => $entry) -{ - $graph_array = array(); - if ($graph_enable[$graph]) - { - $graph_title = $config['graph_types']['device'][$graph]['descr']; - $graph_array['type'] = "device_" . $graph; +// foreach ($config['graph_types']['device'] as $graph => $entry) +foreach ($graph_enable as $graph => $entry) { + $graph_array = array(); + if ($graph_enable[$graph]) { + $graph_title = $config['graph_types']['device'][$graph]['descr']; + $graph_array['type'] = 'device_'.$graph; - include("includes/print-device-graph.php"); - } + include 'includes/print-device-graph.php'; + } } -$pagetitle[] = "Graphs"; - -?> +$pagetitle[] = 'Graphs'; diff --git a/html/pages/device/graphs/netstats_ip_forward.inc.php b/html/pages/device/graphs/netstats_ip_forward.inc.php index cc728ac77c..eda137a788 100644 --- a/html/pages/device/graphs/netstats_ip_forward.inc.php +++ b/html/pages/device/graphs/netstats_ip_forward.inc.php @@ -1,11 +1,8 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'health'); +if ($storage) { + $datas[] = 'storage'; +} + +if ($diskio) { + $datas[] = 'diskio'; +} + +if ($charge) { + $datas[] = 'charge'; +} + +if ($temperatures) { + $datas[] = 'temperature'; +} + +if ($humidity) { + $datas[] = 'humidity'; +} + +if ($fans) { + $datas[] = 'fanspeed'; +} + +if ($volts) { + $datas[] = 'voltage'; +} + +if ($freqs) { + $datas[] = 'frequency'; +} + +if ($current) { + $datas[] = 'current'; +} + +if ($power) { + $datas[] = 'power'; +} + +if ($dBm) { + $datas[] = 'dbm'; +} + +if ($states) { + $datas[] = 'state'; +} + +if ($load) { + $datas[] = 'load'; +} + +$type_text['overview'] = 'Overview'; +$type_text['charge'] = 'Battery Charge'; +$type_text['temperature'] = 'Temperature'; +$type_text['humidity'] = 'Humidity'; +$type_text['mempool'] = 'Memory'; +$type_text['storage'] = 'Disk Usage'; +$type_text['diskio'] = 'Disk I/O'; +$type_text['processor'] = 'Processor'; +$type_text['voltage'] = 'Voltage'; +$type_text['fanspeed'] = 'Fanspeed'; +$type_text['frequency'] = 'Frequency'; +$type_text['current'] = 'Current'; +$type_text['power'] = 'Power'; +$type_text['dbm'] = 'dBm'; +$type_text['state'] = 'State'; +$type_text['load'] = 'Load'; + +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'health', +); print_optionbar_start(); -echo("Health » "); +echo "Health » "; -if (!$vars['metric']) { $vars['metric'] = "overview"; } +if (!$vars['metric']) { + $vars['metric'] = 'overview'; +} unset($sep); -foreach ($datas as $type) -{ - echo($sep); +foreach ($datas as $type) { + echo $sep; - if ($vars['metric'] == $type) - { echo(''); } - echo(generate_link($type_text[$type],$link_array,array('metric'=>$type))); - if ($vars['metric'] == $type) { echo(""); } - $sep = " | "; + if ($vars['metric'] == $type) { + echo ''; + } + + echo generate_link($type_text[$type], $link_array, array('metric' => $type)); + if ($vars['metric'] == $type) { + echo ''; + } + + $sep = ' | '; } print_optionbar_end(); -if (is_file("pages/device/health/".mres($vars['metric']).".inc.php")) -{ - include("pages/device/health/".mres($vars['metric']).".inc.php"); -} else { +if (is_file('pages/device/health/'.mres($vars['metric']).'.inc.php')) { + include 'pages/device/health/'.mres($vars['metric']).'.inc.php'; +} +else { + foreach ($datas as $type) { + if ($type != 'overview') { + $graph_title = $type_text[$type]; + $graph_array['type'] = 'device_'.$type; - foreach ($datas as $type) - { - if ($type != "overview") - { - - $graph_title = $type_text[$type]; - $graph_array['type'] = "device_".$type; - - include("includes/print-device-graph.php"); + include 'includes/print-device-graph.php'; + } } - } } -$pagetitle[] = "Health"; - -?> +$pagetitle[] = 'Health'; diff --git a/html/pages/device/health/charge.inc.php b/html/pages/device/health/charge.inc.php index 7282247bff..0750ae5935 100644 --- a/html/pages/device/health/charge.inc.php +++ b/html/pages/device/health/charge.inc.php @@ -1,9 +1,7 @@ +require 'sensors.inc.php'; diff --git a/html/pages/device/health/current.inc.php b/html/pages/device/health/current.inc.php index 0fa318a9b3..70bd4dc425 100644 --- a/html/pages/device/health/current.inc.php +++ b/html/pages/device/health/current.inc.php @@ -4,6 +4,4 @@ $class = "current"; $unit = "A"; $graph_type = "sensor_current"; -include("sensors.inc.php"); - -?> +require 'sensors.inc.php'; diff --git a/html/pages/device/health/humidity.inc.php b/html/pages/device/health/humidity.inc.php index 93b4772a3f..ffef7afa6a 100644 --- a/html/pages/device/health/humidity.inc.php +++ b/html/pages/device/health/humidity.inc.php @@ -4,6 +4,4 @@ $class = "humidity"; $unit = "%"; $graph_type = "sensor_humidity"; -include("sensors.inc.php"); - -?> +require 'sensors.inc.php'; diff --git a/html/pages/device/health/load.inc.php b/html/pages/device/health/load.inc.php index 399237aaef..18f5b5f5cd 100644 --- a/html/pages/device/health/load.inc.php +++ b/html/pages/device/health/load.inc.php @@ -1,9 +1,7 @@ +require 'sensors.inc.php'; diff --git a/html/pages/device/health/mempool.inc.php b/html/pages/device/health/mempool.inc.php index 6630c31476..613aa1250b 100644 --- a/html/pages/device/health/mempool.inc.php +++ b/html/pages/device/health/mempool.inc.php @@ -1,66 +1,72 @@ "); -echo(""); +echo "
    "; +echo '
    '; $i = '1'; -#FIXME css alternating colours +// FIXME css alternating colours +foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($device['device_id'])) as $mempool) { + if (!is_integer($i / 2)) { + $row_colour = $list_colour_a; + } + else { + $row_colour = $list_colour_b; + } -foreach (dbFetchRows("SELECT * FROM `mempools` WHERE device_id = ?", array($device['device_id'])) as $mempool) -{ - if (!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + if ($config['memcached']['enable'] === true) { + $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); + if ($debug) { + print_r($state); + } - if ($config['memcached']['enable'] === TRUE) - { - $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $mempool = array_merge($mempool, $state); } - unset($state); - } + if (is_array($state)) { + $mempool = array_merge($mempool, $state); + } - $text_descr = rewrite_entity_descr($mempool['mempool_descr']); + unset($state); + } - $mempool_url = "graphs/id=".$mempool['mempool_id']."/type=mempool_usage/"; - $mini_url = "graph.php?id=".$mempool['mempool_id']."&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=80&height=20&bg=f4f4f4"; + $text_descr = rewrite_entity_descr($mempool['mempool_descr']); - $mempool_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$text_descr; - $mempool_popup .= "
    "; - $mempool_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; + $mempool_url = 'graphs/id='.$mempool['mempool_id'].'/type=mempool_usage/'; + $mini_url = 'graph.php?id='.$mempool['mempool_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; - $total = formatStorage($mempool['mempool_total']); - $used = formatStorage($mempool['mempool_used']); - $free = formatStorage($mempool['mempool_free']); + $mempool_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; + $mempool_popup .= "
    "; + $mempool_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; - $perc = round($mempool['mempool_used'] / $mempool['mempool_total'] * 100); + $total = formatStorage($mempool['mempool_total']); + $used = formatStorage($mempool['mempool_used']); + $free = formatStorage($mempool['mempool_free']); - $background = get_percentage_colours($percent); - $right_background = $background['right']; - $left_background = $background['left']; + $perc = round(($mempool['mempool_used'] / $mempool['mempool_total'] * 100)); - echo(" - - - - "); + $background = get_percentage_colours($percent); + $right_background = $background['right']; + $left_background = $background['left']; - echo(" + + + + '; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; + echo ""); + include 'includes/print-graphrow.inc.php'; - $i++; -} + echo ''; -echo("
    " . $text_descr . " - ".print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $left_background, $free , "ffffff", $right_background)." - ".$perc."%
    "); + echo "
    ".$text_descr." + ".print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $left_background, $free, 'ffffff', $right_background).' + '.$perc.'%
    "; - include("includes/print-graphrow.inc.php"); + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; - echo("
    "); -echo("
    "); + $i++; +}//end foreach -?> +echo ''; +echo '
    '; diff --git a/html/pages/device/health/processor.inc.php b/html/pages/device/health/processor.inc.php index bde4a3b3f1..725e37c21f 100644 --- a/html/pages/device/health/processor.inc.php +++ b/html/pages/device/health/processor.inc.php @@ -1,46 +1,43 @@ "); -echo(""); +echo "
    "; +echo '
    '; $i = '1'; -foreach (dbFetchRows("SELECT * FROM `processors` WHERE device_id = ?", array($device['device_id'])) as $proc) -{ - $proc_url = "graphs/id=".$proc['processor_id']."/type=processor_usage/"; +foreach (dbFetchRows('SELECT * FROM `processors` WHERE device_id = ?', array($device['device_id'])) as $proc) { + $proc_url = 'graphs/id='.$proc['processor_id'].'/type=processor_usage/'; - $mini_url = "graph.php?id=".$proc['processor_id']."&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=80&height=20&bg=f4f4f4"; + $mini_url = 'graph.php?id='.$proc['processor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; - $text_descr = $proc['processor_descr']; + $text_descr = $proc['processor_descr']; - $text_descr = rewrite_entity_descr($text_descr); + $text_descr = rewrite_entity_descr($text_descr); - $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$text_descr; - $proc_popup .= "
    "; - $proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; + $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; + $proc_popup .= "
    "; + $proc_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; - $percent = round($proc['processor_usage']); + $percent = round($proc['processor_usage']); - $background = get_percentage_colours($percent); + $background = get_percentage_colours($percent); - echo(" - + echo (" + - "); + '); - echo("
    " . $text_descr . "
    ".$text_descr." - ".print_percentage_bar (400, 20, $percent, $percent."%", "ffffff", $background['left'], (100 - $percent)."%" , "ffffff", $background['right'])." + ".print_percentage_bar(400, 20, $percent, $percent.'%', 'ffffff', $background['left'], (100 - $percent).'%', 'ffffff', $background['right']).'
    "); + echo "
    "; - $graph_array['id'] = $proc['processor_id']; - $graph_array['type'] = $graph_type; + $graph_array['id'] = $proc['processor_id']; + $graph_array['type'] = $graph_type; - include("includes/print-graphrow.inc.php"); -} + include 'includes/print-graphrow.inc.php'; +}//end foreach -echo("
    "); -echo(""); - -?> +echo ''; +echo ''; diff --git a/html/pages/device/health/state.inc.php b/html/pages/device/health/state.inc.php index 5463962196..9781248bea 100644 --- a/html/pages/device/health/state.inc.php +++ b/html/pages/device/health/state.inc.php @@ -1,7 +1,7 @@ "); +echo ''; -echo(" +echo ' - "); + '; $row = 1; -foreach (dbFetchRows("SELECT * FROM `storage` WHERE device_id = ? ORDER BY storage_descr", array($device['device_id'])) as $drive) -{ - if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } +foreach (dbFetchRows('SELECT * FROM `storage` WHERE device_id = ? ORDER BY storage_descr', array($device['device_id'])) as $drive) { + if (is_integer($row / 2)) { + $row_colour = $list_colour_a; + } + else { + $row_colour = $list_colour_b; + } - $total = $drive['storage_size']; - $used = $drive['storage_used']; - $free = $drive['storage_free']; - $perc = round($drive['storage_perc'], 0); - $used = formatStorage($used); - $total = formatStorage($total); - $free = formatStorage($free); + $total = $drive['storage_size']; + $used = $drive['storage_used']; + $free = $drive['storage_free']; + $perc = round($drive['storage_perc'], 0); + $used = formatStorage($used); + $total = formatStorage($total); + $free = formatStorage($free); - $fs_url = "graphs/id=".$drive['storage_id']."/type=storage_usage/"; + $fs_url = 'graphs/id='.$drive['storage_id'].'/type=storage_usage/'; - $fs_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$drive['storage_descr']; - $fs_popup .= "
    "; - $fs_popup .= "', RIGHT, FGCOLOR, '#e5e5e5');\" onmouseout=\"return nd();\""; + $fs_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$drive['storage_descr']; + $fs_popup .= "
    "; + $fs_popup .= "', RIGHT, FGCOLOR, '#e5e5e5');\" onmouseout=\"return nd();\""; - $background = get_percentage_colours($percent); + $background = get_percentage_colours($percent); - echo(""); + echo "'; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; - echo(""); + echo ''; - $row++; -} + $row++; +}//end foreach -echo("
    Drive Usage Free
    " . $drive['storage_descr'] . " - ".print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $perc . "%", "ffffff", $background['right'])." - " . $free . "
    ".$drive['storage_descr']." + ".print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $perc.'%', 'ffffff', $background['right']).' + '.$free.'
    "); + echo "
    "; - include("includes/print-graphrow.inc.php"); + include 'includes/print-graphrow.inc.php'; - echo("
    "); - -?> +echo ''; diff --git a/html/pages/device/hrdevice.inc.php b/html/pages/device/hrdevice.inc.php index 68928187b3..d16a0ba839 100644 --- a/html/pages/device/hrdevice.inc.php +++ b/html/pages/device/hrdevice.inc.php @@ -1,70 +1,69 @@ '); +echo ''; // FIXME missing heading +foreach (dbFetchRows('SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`', array($device['device_id'])) as $hrdevice) { + echo "'; -foreach (dbFetchRows("SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`", array($device['device_id'])) as $hrdevice) -{ - echo(""); + if ($hrdevice['hrDeviceType'] == 'hrDeviceProcessor') { + $proc_id = dbFetchCell("SELECT processor_id FROM processors WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrdevice['hrDeviceIndex']."'"); + $proc_url = 'device/device='.$device['device_id'].'/tab=health/metric=processor/'; + $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$hrdevice['hrDeviceDescr']; + $proc_popup .= "
    "; + $proc_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; + echo "'; - if ($hrdevice['hrDeviceType'] == "hrDeviceProcessor") - { - $proc_id = dbFetchCell("SELECT processor_id FROM processors WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrdevice['hrDeviceIndex']."'"); - $proc_url = "device/device=".$device['device_id']."/tab=health/metric=processor/"; - $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$hrdevice['hrDeviceDescr']; - $proc_popup .= "
    "; - $proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; - echo(""); + $graph_array['height'] = '20'; + $graph_array['width'] = '100'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $proc_id; + $graph_array['type'] = 'processor_usage'; + $graph_array['from'] = $config['time']['day']; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; - $graph_array['height'] = "20"; - $graph_array['width'] = "100"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $proc_id; - $graph_array['type'] = 'processor_usage'; - $graph_array['from'] = $config['time']['day']; - $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; + $mini_graph = overlib_link($proc_url, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); - $mini_graph = overlib_link($proc_url, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); - - echo(''); - } - elseif ($hrdevice['hrDeviceType'] == "hrDeviceNetwork") - { - $int = str_replace("network interface ", "", $hrdevice['hrDeviceDescr']); - $interface = dbFetchRow("SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?", array($device['device_id'], $int)); - if ($interface['ifIndex']) - { - echo(""); - - $graph_array['height'] = "20"; - $graph_array['width'] = "100"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $interface['port_id']; - $graph_array['type'] = 'port_bits'; - $graph_array['from'] = $config['time']['day']; - $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; - - // FIXME click on graph should also link to port, but can't use generate_port_link here... - $mini_graph = overlib_link(generate_port_url($interface), generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); - - echo(""); - } else { - echo(""); - echo(""); + echo ''; } - } else { - echo(""); - echo(""); - } + else if ($hrdevice['hrDeviceType'] == 'hrDeviceNetwork') { + $int = str_replace('network interface ', '', $hrdevice['hrDeviceDescr']); + $interface = dbFetchRow('SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?', array($device['device_id'], $int)); + if ($interface['ifIndex']) { + echo ''; - echo(""); - echo(""); - echo(""); -} + $graph_array['height'] = '20'; + $graph_array['width'] = '100'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $interface['port_id']; + $graph_array['type'] = 'port_bits'; + $graph_array['from'] = $config['time']['day']; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; -echo('
    ".$hrdevice['hrDeviceIndex'].'
    ".$hrdevice['hrDeviceIndex']."".$hrdevice['hrDeviceDescr'].'".$hrdevice['hrDeviceDescr']."'.$mini_graph.'".generate_port_link($interface)."$mini_graph".stripslashes($hrdevice['hrDeviceDescr'])."'.$mini_graph.'".stripslashes($hrdevice['hrDeviceDescr'])."'.generate_port_link($interface).'".$hrdevice['hrDeviceType'].''.$hrdevice['hrDeviceStatus']."".$hrdevice['hrDeviceErrors'].''.$hrdevice['hrProcessorLoad']."
    '); + // FIXME click on graph should also link to port, but can't use generate_port_link here... + $mini_graph = overlib_link(generate_port_url($interface), generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); -$pagetitle[] = "Inventory"; + echo "$mini_graph"; + } + else { + echo ''.stripslashes($hrdevice['hrDeviceDescr']).''; + echo ''; + } + } + else { + echo ''.stripslashes($hrdevice['hrDeviceDescr']).''; + echo ''; + }//end if -?> + echo ''.$hrdevice['hrDeviceType'].''.$hrdevice['hrDeviceStatus'].''; + echo ''.$hrdevice['hrDeviceErrors'].''.$hrdevice['hrProcessorLoad'].''; + echo ''; +}//end foreach + +echo ''; + +$pagetitle[] = 'Inventory'; diff --git a/html/pages/device/loadbalancer/ace_rservers.inc.php b/html/pages/device/loadbalancer/ace_rservers.inc.php index 52f1773c7e..c8b4b2acdc 100644 --- a/html/pages/device/loadbalancer/ace_rservers.inc.php +++ b/html/pages/device/loadbalancer/ace_rservers.inc.php @@ -33,10 +33,10 @@ echo ' Graphs: '; // "pkts" => "Packets", // "errors" => "Errors"); $graph_types = array( - 'curr' => 'CurrentConns', - 'failed' => 'FailedConns', - 'total' => 'TotalConns', - ); + 'curr' => 'CurrentConns', + 'failed' => 'FailedConns', + 'total' => 'TotalConns', +); foreach ($graph_types as $type => $descr) { echo "$type_sep"; @@ -66,7 +66,8 @@ foreach (dbFetchRows('SELECT * FROM `loadbalancer_rservers` WHERE `device_id` = if ($rserver['StateDescr'] == 'Server is now operational') { $rserver_class = 'green'; - } else { + } + else { $rserver_class = 'red'; } @@ -87,7 +88,7 @@ foreach (dbFetchRows('SELECT * FROM `loadbalancer_rservers` WHERE `device_id` = $graph_array['id'] = $rserver['rserver_id']; $graph_array['type'] = $graph_type; - include 'includes/print-graphrow.inc.php'; + require 'includes/print-graphrow.inc.php'; // include("includes/print-interface-graphs.inc.php"); echo ' diff --git a/html/pages/device/loadbalancer/ace_vservers.inc.php b/html/pages/device/loadbalancer/ace_vservers.inc.php index 65032709c8..68ebd1d3f5 100644 --- a/html/pages/device/loadbalancer/ace_vservers.inc.php +++ b/html/pages/device/loadbalancer/ace_vservers.inc.php @@ -2,84 +2,101 @@ print_optionbar_start(); -echo("Serverfarms » "); +echo "Serverfarms » "; -#$auth = TRUE; +// $auth = TRUE; +$menu_options = array('basic' => 'Basic'); -$menu_options = array('basic' => 'Basic', - ); +if (!$_GET['opta']) { + $_GET['opta'] = 'basic'; +} -if (!$_GET['opta']) { $_GET['opta'] = "basic"; } +$sep = ''; +foreach ($menu_options as $option => $text) { + if ($_GET['type'] == $option) { + echo ""; + } -$sep = ""; -foreach ($menu_options as $option => $text) -{ - if ($_GET['type'] == $option) { echo(""); } - echo(''.$text.''); - if ($_GET['type'] == $option) { echo(""); } - echo(" | "); + echo ''.$text.''; + if ($_GET['type'] == $option) { + echo ''; + } + + echo ' | '; } unset($sep); -echo(' Graphs: '); +echo ' Graphs: '; -$graph_types = array("bits" => "Bits", - "pkts" => "Packets", - "conns" => "Connections"); +$graph_types = array( + 'bits' => 'Bits', + 'pkts' => 'Packets', + 'conns' => 'Connections', +); -foreach ($graph_types as $type => $descr) -{ - echo("$type_sep"); - if ($_GET['opte'] == $type) { echo(""); } - echo(''.$descr.''); - echo(''.$text.''); - if ($_GET['opte'] == $type) { echo(""); } +foreach ($graph_types as $type => $descr) { + echo "$type_sep"; + if ($_GET['opte'] == $type) { + echo ""; + } - $type_sep = " | "; + echo ''.$descr.''; + echo ''.$text.''; + if ($_GET['opte'] == $type) { + echo ''; + } + + $type_sep = ' | '; } print_optionbar_end(); -echo("
    "); -$i = "0"; -foreach (dbFetchRows("SELECT * FROM `loadbalancer_vservers` WHERE `device_id` = ? ORDER BY `classmap`", array($device['device_id'])) as $vserver) -{ -if (is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } +echo "
    "; +$i = '0'; +foreach (dbFetchRows('SELECT * FROM `loadbalancer_vservers` WHERE `device_id` = ? ORDER BY `classmap`', array($device['device_id'])) as $vserver) { + if (is_integer($i / 2)) { + $bg_colour = $list_colour_a; + } + else { + $bg_colour = $list_colour_b; + } -if($vserver['serverstate'] == "inService") { $vserver_class="green"; } else { $vserver_class="red"; } + if ($vserver['serverstate'] == 'inService') { + $vserver_class = 'green'; + } + else { + $vserver_class = 'red'; + } -echo(""); -#echo(""); -echo(""); -#echo(""); -echo(""); -echo(""); - if ($_GET['type'] == "graphs") - { - echo(''); - echo(""; + // echo(""); + echo ''; + // echo(""); + echo "'; + echo ''; + if ($_GET['type'] == 'graphs') { + echo ''; + echo ' - "); - } + echo ' + + '; + } -echo(""); -echo(""); + echo ''; + echo ''; - $i++; -} + $i++; +}//end foreach -echo("
    " . $tunnel['local_addr'] . " » " . $tunnel['peer_addr'] . "" . $vserver['classmap'] . "" . $rserver['farm_id'] . "" . $vserver['serverstate'] . "
    "); - $graph_type = "vserver_" . $_GET['opte']; + echo "
    " . $tunnel['local_addr'] . " » " . $tunnel['peer_addr'] . "'.$vserver['classmap'].'" . $rserver['farm_id'] . "".$vserver['serverstate'].'
    '; + $graph_type = 'vserver_'.$_GET['opte']; -$graph_array['height'] = "100"; -$graph_array['width'] = "215"; -$graph_array['to'] = $config['time']['now']; -$graph_array['id'] = $vserver['classmap_id']; -$graph_array['type'] = $graph_type; + $graph_array['height'] = '100'; + $graph_array['width'] = '215'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $vserver['classmap_id']; + $graph_array['type'] = $graph_type; -include("includes/print-graphrow.inc.php"); + include 'includes/print-graphrow.inc.php'; - echo(" -
    "); - -?> +echo ''; diff --git a/html/pages/device/loadbalancer/netscaler_vsvr.inc.php b/html/pages/device/loadbalancer/netscaler_vsvr.inc.php index a67d755b9a..91abc8204f 100644 --- a/html/pages/device/loadbalancer/netscaler_vsvr.inc.php +++ b/html/pages/device/loadbalancer/netscaler_vsvr.inc.php @@ -1,6 +1,6 @@ VServer
    » "); // echo('All'); diff --git a/html/pages/device/logs.inc.php b/html/pages/device/logs.inc.php index 0b8481a68f..11fd6914ba 100644 --- a/html/pages/device/logs.inc.php +++ b/html/pages/device/logs.inc.php @@ -1,41 +1,43 @@ Logging » "); +echo 'Logging » '; -if ($vars['section'] == "eventlog") { - echo(''); +if ($vars['section'] == 'eventlog') { + echo ''; } -echo(generate_link("Event Log" , $vars, array('section'=>'eventlog'))); -if ($vars['section'] == "eventlog") { - echo(""); + +echo generate_link('Event Log', $vars, array('section' => 'eventlog')); +if ($vars['section'] == 'eventlog') { + echo ''; } if (isset($config['enable_syslog']) && $config['enable_syslog'] == 1) { - echo(" | "); + echo ' | '; - if ($vars['section'] == "syslog") { - echo(''); + if ($vars['section'] == 'syslog') { + echo ''; } - echo(generate_link("Syslog" , $vars, array('section'=>'syslog'))); - if ($vars['section'] == "syslog") { - echo(""); + + echo generate_link('Syslog', $vars, array('section' => 'syslog')); + if ($vars['section'] == 'syslog') { + echo ''; } } -switch ($vars['section']) -{ - case 'syslog': - case 'eventlog': - include('pages/device/logs/'.$vars['section'].'.inc.php'); - break; - default: - print_optionbar_end(); - echo(report_this('Unknown section '.$vars['section'])); - break; -} +switch ($vars['section']) { + case 'syslog': + case 'eventlog': + include 'pages/device/logs/'.$vars['section'].'.inc.php'; + break; -?> + default: + print_optionbar_end(); + echo report_this('Unknown section '.$vars['section']); + break; +} diff --git a/html/pages/device/logs/eventlog.inc.php b/html/pages/device/logs/eventlog.inc.php index aec8bdd98c..7d5204f1cd 100644 --- a/html/pages/device/logs/eventlog.inc.php +++ b/html/pages/device/logs/eventlog.inc.php @@ -2,51 +2,49 @@
    +echo '
    Eventlog entries
    - '); +
    '; -foreach ($entries as $entry) -{ - include("includes/print-event.inc.php"); +foreach ($entries as $entry) { + include 'includes/print-event.inc.php'; } -echo('
    -
    '); +echo ' + '; -$pagetitle[] = "Events"; - -?> +$pagetitle[] = 'Events'; diff --git a/html/pages/device/logs/syslog.inc.php b/html/pages/device/logs/syslog.inc.php index 7aae3b8e0c..1284ad157f 100644 --- a/html/pages/device/logs/syslog.inc.php +++ b/html/pages/device/logs/syslog.inc.php @@ -3,53 +3,54 @@
    +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? $where"; +$sql .= ' ORDER BY timestamp DESC LIMIT 1000'; +echo '
    Syslog entries
    - '); -foreach (dbFetchRows($sql, $param) as $entry) { include("includes/print-syslog.inc.php"); } -echo('
    -
    '); -$pagetitle[] = "Syslog"; + '; +foreach (dbFetchRows($sql, $param) as $entry) { + include 'includes/print-syslog.inc.php'; +} -?> +echo '
    + '; +$pagetitle[] = 'Syslog'; diff --git a/html/pages/device/map.inc.php b/html/pages/device/map.inc.php index 522de36a51..918f62e7fc 100644 --- a/html/pages/device/map.inc.php +++ b/html/pages/device/map.inc.php @@ -12,8 +12,6 @@ * the source code distribution for details. */ -$pagetitle[] = "Map"; +$pagetitle[] = 'Map'; -require_once "includes/print-map.inc.php"; - -?> +require_once 'includes/print-map.inc.php'; diff --git a/html/pages/device/munin.inc.php b/html/pages/device/munin.inc.php index 67fd22d6e0..e12279687e 100644 --- a/html/pages/device/munin.inc.php +++ b/html/pages/device/munin.inc.php @@ -1,75 +1,72 @@ 'device', + 'device' => $device['device_id'], + 'tab' => 'munin', +); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'munin'); +$bg = '#ffffff'; -$bg="#ffffff"; - -echo('
    '); +echo '
    '; print_optionbar_start(); -echo("Munin » "); +echo "Munin » "; -$sep = ""; +$sep = ''; -foreach (dbFetchRows("SELECT * FROM munin_plugins WHERE device_id = ? ORDER BY mplug_category, mplug_type", array($device['device_id'])) as $mplug) -{ -# if (strlen($mplug['mplug_category']) == 0) { $mplug['mplug_category'] = "general"; } else { } - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['id'] = $mplug['mplug_id']; - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['title'] = $mplug['mplug_title']; - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['plugin'] = $mplug['mplug_type']; +foreach (dbFetchRows('SELECT * FROM munin_plugins WHERE device_id = ? ORDER BY mplug_category, mplug_type', array($device['device_id'])) as $mplug) { + // if (strlen($mplug['mplug_category']) == 0) { $mplug['mplug_category'] = "general"; } else { } + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['id'] = $mplug['mplug_id']; + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['title'] = $mplug['mplug_title']; + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['plugin'] = $mplug['mplug_type']; } -foreach ($graph_enable as $section => $nothing) -{ - if (isset($graph_enable) && is_array($graph_enable[$section])) - { - $type = strtolower($section); - if (!$vars['group']) { $vars['group'] = $type; } - echo($sep); - if ($vars['group'] == $type) - { - echo(''); +foreach ($graph_enable as $section => $nothing) { + if (isset($graph_enable) && is_array($graph_enable[$section])) { + $type = strtolower($section); + if (!$vars['group']) { + $vars['group'] = $type; + } + + echo $sep; + if ($vars['group'] == $type) { + echo ''; + } + + echo generate_link(ucwords($type), $link_array, array('group' => $type)); + if ($vars['group'] == $type) { + echo ''; + } + + $sep = ' | '; } - echo(generate_link(ucwords($type),$link_array,array('group'=>$type))); - if ($vars['group'] == $type) - { - echo(""); - } - $sep = " | "; - } } -unset ($sep); +unset($sep); print_optionbar_end(); $graph_enable = $graph_enable[$vars['group']]; -#foreach ($config['graph_types']['device'] as $graph => $entry) -foreach ($graph_enable as $graph => $entry) -{ - $graph_array = array(); - if ($graph_enable[$graph]) - { - if (!empty($entry['plugin'])) - { - $graph_title = $entry['title']; - $graph_array['type'] = "munin_graph"; - $graph_array['device'] = $device['device_id']; - $graph_array['plugin'] = $entry['plugin']; - } else { - $graph_title = $config['graph_types']['device'][$graph]['descr']; - $graph_array['type'] = "device_" . $graph; - } +// foreach ($config['graph_types']['device'] as $graph => $entry) +foreach ($graph_enable as $graph => $entry) { + $graph_array = array(); + if ($graph_enable[$graph]) { + if (!empty($entry['plugin'])) { + $graph_title = $entry['title']; + $graph_array['type'] = 'munin_graph'; + $graph_array['device'] = $device['device_id']; + $graph_array['plugin'] = $entry['plugin']; + } + else { + $graph_title = $config['graph_types']['device'][$graph]['descr']; + $graph_array['type'] = 'device_'.$graph; + } - include("includes/print-device-graph.php"); - } + include 'includes/print-device-graph.php'; + } } -$pagetitle[] = "Graphs"; - -?> +$pagetitle[] = 'Graphs'; diff --git a/html/pages/device/overview.inc.php b/html/pages/device/overview.inc.php index aac3b2ca23..13227e0136 100644 --- a/html/pages/device/overview.inc.php +++ b/html/pages/device/overview.inc.php @@ -12,8 +12,18 @@ $services['up'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WH $services['down'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_status` = '0' AND `service_ignore` = '0'", array($device['device_id'])); $services['disabled'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_ignore` = '1'", array($device['device_id'])); -if ($services['down']) { $services_colour = $warn_colour_a; } else { $services_colour = $list_colour_a; } -if ($ports['down']) { $ports_colour = $warn_colour_a; } else { $ports_colour = $list_colour_a; } +if ($services['down']) { + $services_colour = $warn_colour_a; +} +else { + $services_colour = $list_colour_a; +} +if ($ports['down']) { + $ports_colour = $warn_colour_a; +} +else { + $ports_colour = $list_colour_a; +} echo('
    @@ -25,39 +35,41 @@ echo('
    '); -include("includes/dev-overview-data.inc.php"); +require 'includes/dev-overview-data.inc.php'; Plugins::call('device_overview_container',array($device)); -include("overview/ports.inc.php"); +require 'overview/ports.inc.php'; echo('
    '); // Right Pane -include("overview/processors.inc.php"); -include("overview/mempools.inc.php"); -include("overview/storage.inc.php"); +require 'overview/processors.inc.php'; +require 'overview/mempools.inc.php'; +require 'overview/storage.inc.php'; -if(is_array($entity_state['group']['c6kxbar'])) { include("overview/c6kxbar.inc.php"); } +if(is_array($entity_state['group']['c6kxbar'])) { + require 'overview/c6kxbar.inc.php'; +} -include("overview/toner.inc.php"); -include("overview/sensors/charge.inc.php"); -include("overview/sensors/temperatures.inc.php"); -include("overview/sensors/humidity.inc.php"); -include("overview/sensors/fanspeeds.inc.php"); -include("overview/sensors/dbm.inc.php"); -include("overview/sensors/voltages.inc.php"); -include("overview/sensors/current.inc.php"); -include("overview/sensors/power.inc.php"); -include("overview/sensors/frequencies.inc.php"); -include("overview/sensors/load.inc.php"); -include("overview/sensors/state.inc.php"); -include("overview/eventlog.inc.php"); -include("overview/services.inc.php"); -include("overview/syslog.inc.php"); +require 'overview/toner.inc.php'; +require 'overview/sensors/charge.inc.php'; +require 'overview/sensors/temperatures.inc.php'; +require 'overview/sensors/humidity.inc.php'; +require 'overview/sensors/fanspeeds.inc.php'; +require 'overview/sensors/dbm.inc.php'; +require 'overview/sensors/voltages.inc.php'; +require 'overview/sensors/current.inc.php'; +require 'overview/sensors/power.inc.php'; +require 'overview/sensors/frequencies.inc.php'; +require 'overview/sensors/load.inc.php'; +require 'overview/sensors/state.inc.php'; +require 'overview/eventlog.inc.php'; +require 'overview/services.inc.php'; +require 'overview/syslog.inc.php'; echo('
    '); -#include("overview/current.inc.php"); +#require 'overview/current.inc.php"); ?> diff --git a/html/pages/device/overview/c6kxbar.inc.php b/html/pages/device/overview/c6kxbar.inc.php index 14f5d54e48..eb04e0a7db 100644 --- a/html/pages/device/overview/c6kxbar.inc.php +++ b/html/pages/device/overview/c6kxbar.inc.php @@ -1,102 +1,99 @@ -
    -
    -
    -
    '); -echo(''); -echo(" Catalyst 6k Crossbar"); -echo('
    - '); +echo '
    +
    +
    +
    +
    '; +echo ''; +echo " Catalyst 6k Crossbar"; +echo '
    +
    '; -foreach ($entity_state['group']['c6kxbar'] as $index => $entry) -{ - // FIXME i'm not sure if this is the correct way to decide what entphysical index it is. slotnum+1? :> - $entity = dbFetchRow("SELECT * FROM entPhysical WHERE device_id = ? AND entPhysicalIndex = ?", array($device['device_id'], $index+1)); +foreach ($entity_state['group']['c6kxbar'] as $index => $entry) { + // FIXME i'm not sure if this is the correct way to decide what entphysical index it is. slotnum+1? :> + $entity = dbFetchRow('SELECT * FROM entPhysical WHERE device_id = ? AND entPhysicalIndex = ?', array($device['device_id'], $index + 1)); - echo(" + echo " - - "); + echo ' + '; - foreach ($entity_state['group']['c6kxbar'][$index] as $subindex => $fabric) - { - if (is_numeric($subindex)) - { - if ($fabric['cc6kxbarModuleChannelFabStatus'] == "ok") - { - $fabric['mode_class'] = "green"; - } else { - $fabric['mode_class'] = "red"; - } + foreach ($entity_state['group']['c6kxbar'][$index] as $subindex => $fabric) { + if (is_numeric($subindex)) { + if ($fabric['cc6kxbarModuleChannelFabStatus'] == 'ok') { + $fabric['mode_class'] = 'green'; + } + else { + $fabric['mode_class'] = 'red'; + } - $percent_in = $fabric['cc6kxbarStatisticsInUtil']; - $background_in = get_percentage_colours($percent_in); + $percent_in = $fabric['cc6kxbarStatisticsInUtil']; + $background_in = get_percentage_colours($percent_in); - $percent_out = $fabric['cc6kxbarStatisticsOutUtil']; - $background_out = get_percentage_colours($percent_out); + $percent_out = $fabric['cc6kxbarStatisticsOutUtil']; + $background_out = get_percentage_colours($percent_out); - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device['device_id']; - $graph_array['mod'] = $index; - $graph_array['chan'] = $subindex; - $graph_array['type'] = "c6kxbar_util"; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device['device_id']; + $graph_array['mod'] = $index; + $graph_array['chan'] = $subindex; + $graph_array['type'] = 'c6kxbar_util'; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $text_descr = $entity['entPhysicalName'] . " - Fabric " . $subindex; + $text_descr = $entity['entPhysicalName'].' - Fabric '.$subindex; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - $minigraph = generate_graph_tag($graph_array); + echo (' + + + - - - - - - - "); - } - } -} - -echo("
    ".$entity['entPhysicalName'].""); + "; - switch ($entry['']['cc6kxbarModuleModeSwitchingMode']) - { - case "busmode": - # echo 'Bus'; + switch ($entry['']['cc6kxbarModuleModeSwitchingMode']) { + case 'busmode': + // echo 'Bus'; break; - case "crossbarmode": + + case 'crossbarmode': echo 'Crossbar'; break; - case "dcefmode": + + case 'dcefmode': echo 'DCEF'; break; - default: + + default: echo $entry['']['cc6kxbarModuleModeSwitchingMode']; } - echo("
    Fabric '.$subindex." - Fabric ".$subindex."". - - $fabric['cc6kxbarModuleChannelFabStatus']."".formatRates($fabric['cc6kxbarModuleChannelSpeed']*1000000)."".overlib_link($link, $minigraph, $overlib_content)."".print_percentage_bar (125, 20, $percent_in, "Ingress", "ffffff", $background['left'], $percent_in . "%", "ffffff", $background['right'])."".print_percentage_bar (125, 20, $percent_out, "Egress", "ffffff", $background['left'], $percent_out . "%", "ffffff", $background['right'])."
    "); -echo("
    "); -echo("
    "); -echo("
    "); -echo("
    "); - -?> +echo ' '; +echo '
    '; +echo ' '; +echo ' '; +echo ''; diff --git a/html/pages/device/overview/eventlog.inc.php b/html/pages/device/overview/eventlog.inc.php index ff235aa4a8..d555118136 100644 --- a/html/pages/device/overview/eventlog.inc.php +++ b/html/pages/device/overview/eventlog.inc.php @@ -1,25 +1,22 @@ '); - echo('
    +echo '
    '; +echo '
    -
    '); -echo(''); -echo(" Recent Events"); -echo('
    - '); +
    '; +echo ''; +echo " Recent Events"; +echo '
    +
    '; $eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` WHERE `host` = ? ORDER BY `datetime` DESC LIMIT 0,10", array($device['device_id'])); -foreach ($eventlog as $entry) -{ - include("includes/print-event-short.inc.php"); +foreach ($eventlog as $entry) { + include 'includes/print-event-short.inc.php'; } -echo("
    "); -echo('
    '); -echo('
    '); -echo('
    '); -echo('
    '); - -?> +echo ''; +echo '
    '; +echo ''; +echo ''; +echo ''; diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index 6194c37c00..36bc05cd5d 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -1,75 +1,71 @@ +if (count($sensors)) { + echo '
    -
    -
    -
    '); - echo(' ' . $sensor_type . ''); - echo('
    - '); - foreach ($sensors as $sensor) - { - if ($config['memcached']['enable'] === TRUE) - { - $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); - } +
    +
    +
    '; + echo ' '.$sensor_type.''; + echo '
    +
    '; + foreach ($sensors as $sensor) { + if ($config['memcached']['enable'] === true) { + $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); + } - if (empty($sensor['sensor_current'])) - { - $sensor['sensor_current'] = "NaN"; - } + if (empty($sensor['sensor_current'])) { + $sensor['sensor_current'] = 'NaN'; + } - // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. - // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? - // FIXME - DUPLICATED IN health/sensors + // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. + // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? + // FIXME - DUPLICATED IN health/sensors + $graph_colour = str_replace('#', '', $row_colour); - $graph_colour = str_replace("#", "", $row_colour); + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $sensor['sensor_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $sensor['sensor_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $overlib_content = '

    '.$device['hostname'].' - '.$sensor['sensor_descr'].'

    '; + foreach (array('day', 'week', 'month', 'year') as $period) { + $graph_array['from'] = $config['time'][$period]; + $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); + } - $overlib_content = '

    '.$device['hostname']." - ".$sensor['sensor_descr']."

    "; - foreach (array('day','week','month','year') as $period) - { - $graph_array['from'] = $config['time'][$period]; - $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); - } - $overlib_content .= "
    "; + $overlib_content .= '
    '; - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. - $graph_array['from'] = $config['time']['day']; - $sensor_minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $graph_array['from'] = $config['time']['day']; + $sensor_minigraph = generate_graph_tag($graph_array); - $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); + $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); - echo(" - - - - "); - } + echo ' + + + + '; + }//end foreach - echo("
    ".overlib_link($link, $sensor['sensor_descr'], $overlib_content)."".overlib_link($link, $sensor_minigraph, $overlib_content)."".overlib_link($link, " $sensor['sensor_limit'] ? "style='color: red'" : '') . '>' . $sensor['sensor_current'] . $sensor_unit . "", $overlib_content)."
    '.overlib_link($link, $sensor['sensor_descr'], $overlib_content).''.overlib_link($link, $sensor_minigraph, $overlib_content).''.overlib_link($link, ' $sensor['sensor_limit'] ? "style='color: red'" : '').'>'.$sensor['sensor_current'].$sensor_unit.'', $overlib_content).'
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); -} - -?> + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +}//end if diff --git a/html/pages/device/overview/mempools.inc.php b/html/pages/device/overview/mempools.inc.php index 3d35a8d554..0699872416 100644 --- a/html/pages/device/overview/mempools.inc.php +++ b/html/pages/device/overview/mempools.inc.php @@ -1,76 +1,77 @@ +if (count($mempools)) { + echo '
    -
    -
    -
    -'); - echo(''); - echo(" Memory Pools"); - echo(' -
    - -'); +
    +
    +
    + '; + echo ''; + echo " Memory Pools"; + echo ' +
    +
    + '; - foreach ($mempools as $mempool) - { + foreach ($mempools as $mempool) { + if ($config['memcached']['enable'] === true) { + $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); + if ($debug) { + print_r($state); + } - if ($config['memcached']['enable'] === TRUE) - { - $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $mempool = array_merge($mempool, $state); } - unset($state); - } + if (is_array($state)) { + $mempool = array_merge($mempool, $state); + } - $percent= round($mempool['mempool_perc'],0); - $text_descr = rewrite_entity_descr($mempool['mempool_descr']); - $total = formatStorage($mempool['mempool_total']); - $used = formatStorage($mempool['mempool_used']); - $free = formatStorage($mempool['mempool_free']); - $background = get_percentage_colours($percent); + unset($state); + } - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $percent = round($mempool['mempool_perc'], 0); + $text_descr = rewrite_entity_descr($mempool['mempool_descr']); + $total = formatStorage($mempool['mempool_total']); + $used = formatStorage($mempool['mempool_used']); + $free = formatStorage($mempool['mempool_free']); + $background = get_percentage_colours($percent); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); - $minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - echo(" - - - - "); - } + echo ' + + + + '; + }//end foreach - echo('
    ".overlib_link($link, $text_descr, $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." -
    '.overlib_link($link, $text_descr, $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).' +
    + echo '
    -
    '); - -} - -?> + '; +}//end if diff --git a/html/pages/device/overview/ports.inc.php b/html/pages/device/overview/ports.inc.php index 807f8ee4fb..75cf3ca29f 100644 --- a/html/pages/device/overview/ports.inc.php +++ b/html/pages/device/overview/ports.inc.php @@ -1,68 +1,64 @@ '); - echo('
    +if ($ports['total']) { + echo '
    '; + echo '
    Overall Traffic
    - '); +
    '; - $graph_array['height'] = "100"; - $graph_array['width'] = "485"; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device['device_id']; - $graph_array['type'] = "device_bits"; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; - $graph = generate_graph_tag($graph_array); + $graph_array['height'] = '100'; + $graph_array['width'] = '485'; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device['device_id']; + $graph_array['type'] = 'device_bits'; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; + $graph = generate_graph_tag($graph_array); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width']); + $link = generate_url($link_array); - $graph_array['width'] = "210"; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - Device Traffic"); + $graph_array['width'] = '210'; + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - Device Traffic'); - echo(' - - '); + echo ' + + '; - echo(' + echo ' - - - - - '); + + + + + '; - echo(' - + "); - echo(""); - echo("
    '); - echo(overlib_link($link, $graph, $overlib_content, NULL)); - echo('
    '; + echo overlib_link($link, $graph, $overlib_content, null); + echo '
    ' . $ports['total'] . ' ' . $ports['up'] . ' ' . $ports['down'] . ' ' . $ports['disabled'] . '
    '.$ports['total'].' '.$ports['up'].' '.$ports['down'].' '.$ports['disabled'].'
    '); + echo '
    '; - $ifsep = ""; + $ifsep = ''; - foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) - { - $data = ifNameDescr($data); - $data = array_merge($data, $device); - echo("$ifsep" . generate_port_link($data, makeshortif(strtolower($data['label'])))); - $ifsep = ", "; - } + foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) { + $data = ifNameDescr($data); + $data = array_merge($data, $device); + echo "$ifsep".generate_port_link($data, makeshortif(strtolower($data['label']))); + $ifsep = ', '; + } - unset($ifsep); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); -} - -?> + unset($ifsep); + echo ' '; + echo ''; + echo ''; + echo '
    '; + echo ''; + echo ''; + echo ''; +}//end if diff --git a/html/pages/device/overview/processors.inc.php b/html/pages/device/overview/processors.inc.php index 3394e263ca..8b4d3f2912 100644 --- a/html/pages/device/overview/processors.inc.php +++ b/html/pages/device/overview/processors.inc.php @@ -1,66 +1,63 @@ +if (count($processors)) { + echo '
    -'); - echo(''); - echo(" Processors"); - echo('
    - '); +'; + echo ''; + echo " Processors"; + echo ' +
    '; - foreach ($processors as $proc) - { - $text_descr = rewrite_entity_descr($proc['processor_descr']); + foreach ($processors as $proc) { + $text_descr = rewrite_entity_descr($proc['processor_descr']); - # disable short hrDeviceDescr. need to make this prettier. - #$text_descr = short_hrDeviceDescr($proc['processor_descr']); - $percent = $proc['processor_usage']; - $background = get_percentage_colours($percent); - $graph_colour = str_replace("#", "", $row_colour); + // disable short hrDeviceDescr. need to make this prettier. + // $text_descr = short_hrDeviceDescr($proc['processor_descr']); + $percent = $proc['processor_usage']; + $background = get_percentage_colours($percent); + $graph_colour = str_replace('#', '', $row_colour); - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $proc['processor_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $proc['processor_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - $minigraph = generate_graph_tag($graph_array); - - echo(" - - - + + + - "); - } + '; + }//end foreach - echo('
    ".overlib_link($link, $text_descr, $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." + echo '
    '.overlib_link($link, $text_descr, $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).'
    + echo '
    -
    '); - -} - -?> + '; +}//end if diff --git a/html/pages/device/overview/sensors/charge.inc.php b/html/pages/device/overview/sensors/charge.inc.php index bf40977499..b0df00968a 100644 --- a/html/pages/device/overview/sensors/charge.inc.php +++ b/html/pages/device/overview/sensors/charge.inc.php @@ -1,10 +1,8 @@ +require 'pages/device/overview/generic/sensor.inc.php'; diff --git a/html/pages/device/overview/sensors/load.inc.php b/html/pages/device/overview/sensors/load.inc.php index 989a305b9b..089f93dffb 100644 --- a/html/pages/device/overview/sensors/load.inc.php +++ b/html/pages/device/overview/sensors/load.inc.php @@ -1,8 +1,8 @@ '); - echo('
    +if ($services['total']) { +echo '
    '; + echo '
    -
    '); - echo(" Services"); - echo('
    - '); +
    '; + echo " Services"; + echo '
    +
    '; - echo(" + echo " @@ -19,22 +18,32 @@ echo('
    ');
    -
    $services[total] $services[up] $services[disabled]
    "); +"; - foreach (dbFetchRows("SELECT * FROM services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $data) - { - if ($data['service_status'] == "0" && $data['service_ignore'] == "1") { $status = "grey"; } - if ($data['service_status'] == "1" && $data['service_ignore'] == "1") { $status = "green"; } - if ($data['service_status'] == "0" && $data['service_ignore'] == "0") { $status = "red"; } - if ($data['service_status'] == "1" && $data['service_ignore'] == "0") { $status = "blue"; } - echo("$break" . strtolower($data['service_type']) . ""); - $break = ", "; - } - echo('
    '); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); -} + foreach (dbFetchRows('SELECT * FROM services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $data) { + if ($data['service_status'] == '0' && $data['service_ignore'] == '1') { + $status = 'grey'; + } -?> + if ($data['service_status'] == '1' && $data['service_ignore'] == '1') { + $status = 'green'; + } + + if ($data['service_status'] == '0' && $data['service_ignore'] == '0') { + $status = 'red'; + } + + if ($data['service_status'] == '1' && $data['service_ignore'] == '0') { + $status = 'blue'; + } + + echo "$break".strtolower($data['service_type']).''; + $break = ', '; + } + + echo ''; + echo '
    '; + echo ''; + echo ''; + echo ''; +}//end if diff --git a/html/pages/device/overview/storage.inc.php b/html/pages/device/overview/storage.inc.php index 01c02edb4e..e81b1b5b5d 100644 --- a/html/pages/device/overview/storage.inc.php +++ b/html/pages/device/overview/storage.inc.php @@ -1,91 +1,86 @@ +if (count($drives)) { + echo '
    -
    '); - echo(''); - echo(" Storage"); - echo('
    - '); +
    '; + echo ''; + echo " Storage"; + echo '
    +
    '; - foreach ($drives as $drive) - { - $skipdrive = 0; + foreach ($drives as $drive) { + $skipdrive = 0; - if ($device["os"] == "junos") - { - foreach ($config['ignore_junos_os_drives'] as $jdrive) - { - if (preg_match($jdrive, $drive["storage_descr"])) - { - $skipdrive = 1; + if ($device['os'] == 'junos') { + foreach ($config['ignore_junos_os_drives'] as $jdrive) { + if (preg_match($jdrive, $drive['storage_descr'])) { + $skipdrive = 1; + } + } + + $drive['storage_descr'] = preg_replace('/.*mounted on: (.*)/', '\\1', $drive['storage_descr']); } - } - $drive["storage_descr"] = preg_replace("/.*mounted on: (.*)/", "\\1", $drive["storage_descr"]); - } - if ($device['os'] == "freebsd") - { - foreach ($config['ignore_bsd_os_drives'] as $jdrive) - { - if (preg_match($jdrive, $drive["storage_descr"])) - { - $skipdrive = 1; + if ($device['os'] == 'freebsd') { + foreach ($config['ignore_bsd_os_drives'] as $jdrive) { + if (preg_match($jdrive, $drive['storage_descr'])) { + $skipdrive = 1; + } + } } - } - } - if ($skipdrive) { continue; } - $percent = round($drive['storage_perc'], 0); - $total = formatStorage($drive['storage_size']); - $free = formatStorage($drive['storage_free']); - $used = formatStorage($drive['storage_used']); - $background = get_percentage_colours($percent); + if ($skipdrive) { + continue; + } - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $percent = round($drive['storage_perc'], 0); + $total = formatStorage($drive['storage_size']); + $free = formatStorage($drive['storage_free']); + $used = formatStorage($drive['storage_used']); + $background = get_percentage_colours($percent); - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $drive['storage_descr']); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$drive['storage_descr']); - $minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - echo(" - - - + + + - "); - } + '; + }//end foreach - echo('
    ".overlib_link($link, $drive['storage_descr'], $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." + echo '
    '.overlib_link($link, $drive['storage_descr'], $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).'
    + echo '
    -
    '); + '; +}//end if -} - -unset ($drive_rows); - -?> +unset($drive_rows); diff --git a/html/pages/device/overview/syslog.inc.php b/html/pages/device/overview/syslog.inc.php index 1d26fbb2a7..bcfb6d2c52 100644 --- a/html/pages/device/overview/syslog.inc.php +++ b/html/pages/device/overview/syslog.inc.php @@ -1,25 +1,24 @@ '); - echo('
    +if ($config['enable_syslog']) { + $syslog = dbFetchRows("SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? ORDER BY timestamp DESC LIMIT 20", array($device['device_id'])); + if (count($syslog)) { + echo '
    '; + echo '
    -
    '); - echo(' Recent Syslog'); -echo('
    - '); - foreach ($syslog as $entry) { include("includes/print-syslog.inc.php"); } - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - } -} +
    '; + echo ' Recent Syslog'; + echo '
    + '; + foreach ($syslog as $entry) { + include 'includes/print-syslog.inc.php'; + } -?> + echo '
    '; + echo '
    '; + echo ''; + echo ''; + echo ''; + } +} diff --git a/html/pages/device/overview/toner.inc.php b/html/pages/device/overview/toner.inc.php index 347a636195..7c789573c5 100644 --- a/html/pages/device/overview/toner.inc.php +++ b/html/pages/device/overview/toner.inc.php @@ -1,64 +1,62 @@ +if (count($toners)) { + echo '
    -
    '); - echo(''); - echo(" Toner"); - echo('
    - '); +
    '; + echo ''; + echo " Toner"; + echo '
    +
    '; - foreach ($toners as $toner) - { - $percent = round($toner['toner_current'], 0); - $total = formatStorage($toner['toner_size']); - $free = formatStorage($toner['toner_free']); - $used = formatStorage($toner['toner_used']); + foreach ($toners as $toner) { + $percent = round($toner['toner_current'], 0); + $total = formatStorage($toner['toner_size']); + $free = formatStorage($toner['toner_free']); + $used = formatStorage($toner['toner_used']); - $background = toner2colour($toner['toner_descr'], $percent); + $background = toner2colour($toner['toner_descr'], $percent); - $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $toner['toner_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array = array(); + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $toner['toner_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $toner['toner_descr']); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$toner['toner_descr']); - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_graph_tag($graph_array); - $minigraph = generate_graph_tag($graph_array); - - echo(" - - - + + + - "); - } + '; + }//end foreach - echo("
    ".overlib_link($link, $toner['toner_descr'], $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." + echo '
    '.overlib_link($link, $toner['toner_descr'], $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).'
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo(""); -} + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +}//end if -unset ($toner_rows); - -?> +unset($toner_rows); diff --git a/html/pages/device/performance.inc.php b/html/pages/device/performance.inc.php index 8686bf8034..da2056c54b 100644 --- a/html/pages/device/performance.inc.php +++ b/html/pages/device/performance.inc.php @@ -21,7 +21,9 @@ */ -if(!isset($vars['section'])) { $vars['section'] = "performance"; } +if(!isset($vars['section'])) { + $vars['section'] = "performance"; +} if (empty($vars['dtpickerfrom'])) { $vars['dtpickerfrom'] = date($config['dateformat']['byminute'], time() - 3600 * 24 * 2); @@ -57,7 +59,8 @@ if (empty($vars['dtpickerto'])) { if (is_admin() === true || is_read() === true) { $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf` WHERE `device_id` = ? AND `timestamp` >= ? AND `timestamp` <= ?"; $param = array($device['device_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); -} else { +} +else { $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf`,`devices_perms` WHERE `device_id` = ? AND alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = ? AND `timestamp` >= ? AND `timestamp` <= ?"; $param = array($device['device_id'], $_SESSION['user_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); } @@ -81,7 +84,7 @@ foreach(dbFetchRows($query, $param) as $return_value) { $avg = $return_value['avg']; if ($max > $max_val) { - $max_val = $max; + $max_val = $max; } $data[] = array('x' => $date,'y' => $loss,'group' => 0); @@ -186,4 +189,3 @@ echo $milisec_diff; var graph2d = new vis.Graph2d(container, items, groups, options); - diff --git a/html/pages/device/port.inc.php b/html/pages/device/port.inc.php index ecb25cfd28..a70d40a763 100644 --- a/html/pages/device/port.inc.php +++ b/html/pages/device/port.inc.php @@ -1,15 +1,22 @@ get('port-'.$port['port_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $port = array_merge($port, $state); } - unset($state); +if ($config['memcached']['enable'] === true) { + $state = $memcache->get('port-'.$port['port_id'].'-state'); + if ($debug) { + print_r($state); + } + + if (is_array($state)) { + $port = array_merge($port, $state); + } + + unset($state); } $port_details = 1; @@ -17,148 +24,218 @@ $port_details = 1; $hostname = $device['hostname']; $hostid = $device['port_id']; $ifname = $port['ifDescr']; -$ifIndex = $port['ifIndex']; -$speed = humanspeed($port['ifSpeed']); +$ifIndex = $port['ifIndex']; +$speed = humanspeed($port['ifSpeed']); $ifalias = $port['name']; -if ($port['ifPhysAddress']) { $mac = "$port[ifPhysAddress]"; } +if ($port['ifPhysAddress']) { + $mac = "$port[ifPhysAddress]"; +} -$color = "black"; -if ($port['ifAdminStatus'] == "down") { $status = "Disabled"; } -if ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "down") { $status = "Enabled / Disconnected"; } -if ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "up") { $status = "Enabled / Connected"; } +$color = 'black'; +if ($port['ifAdminStatus'] == 'down') { + $status = "Disabled"; +} -$i = 1; +if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'down') { + $status = "Enabled / Disconnected"; +} + +if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') { + $status = "Enabled / Connected"; +} + +$i = 1; $inf = fixifName($ifname); -$bg="#ffffff"; +$bg = '#ffffff'; $show_all = 1; -echo("
    "); +echo "
    "; -include("includes/print-interface.inc.php"); +require 'includes/print-interface.inc.php'; -echo("
    "); +echo ''; -$pos = strpos(strtolower($ifname), "vlan"); -if ($pos !== false ) -{ - $broke = yes; +$pos = strpos(strtolower($ifname), 'vlan'); +if ($pos !== false) { + $broke = yes; } -$pos = strpos(strtolower($ifname), "loopback"); +$pos = strpos(strtolower($ifname), 'loopback'); -if ($pos !== false ) -{ - $broke = yes; +if ($pos !== false) { + $broke = yes; } -echo("
    "); +echo "
    "; print_optionbar_start(); -$link_array = array('page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'port', - 'port' => $port['port_id']); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'port', + 'port' => $port['port_id'], +); $menu_options['graphs'] = 'Graphs'; -$menu_options['realtime'] = 'Real time'; // FIXME CONDITIONAL -$menu_options['arp'] = 'ARP Table'; -$menu_options['events'] = 'Eventlog'; +$menu_options['realtime'] = 'Real time'; +// FIXME CONDITIONAL +$menu_options['arp'] = 'ARP Table'; +$menu_options['events'] = 'Eventlog'; -if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '".$port['port_id']."'") ) -{ $menu_options['adsl'] = 'ADSL'; } - -if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '".$port['ifIndex']."' and `device_id` = '".$device['device_id']."'") ) -{ $menu_options['pagp'] = 'PAgP'; } - -if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'") ) -{ $menu_options['vlans'] = 'VLANs'; } - -$sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['view'] == $option) { echo(""); } - echo(generate_link($text,$link_array,array('view'=>$option))); - if ($vars['view'] == $option) { echo(""); } - $sep = " | "; +if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '".$port['port_id']."'")) { + $menu_options['adsl'] = 'ADSL'; } + +if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '".$port['ifIndex']."' and `device_id` = '".$device['device_id']."'")) { + $menu_options['pagp'] = 'PAgP'; +} + +if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'")) { + $menu_options['vlans'] = 'VLANs'; +} + +$sep = ''; +foreach ($menu_options as $option => $text) { + echo $sep; + if ($vars['view'] == $option) { + echo ""; + } + + echo generate_link($text, $link_array, array('view' => $option)); + if ($vars['view'] == $option) { + echo ''; + } + + $sep = ' | '; +} + unset($sep); -if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '".$port['port_id']."'") > "0" ) -{ +if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '".$port['port_id']."'") > '0') { + echo generate_link($descr, $link_array, array('view' => 'macaccounting', 'graph' => $type)); - echo(generate_link($descr,$link_array,array('view'=>'macaccounting','graph'=>$type))); + echo ' | Mac Accounting : '; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') { + echo ""; + } - echo(" | Mac Accounting : "); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "graphs") { echo(""); } - echo(generate_link("Bits",$link_array,array('view' => 'macaccounting', 'subview' => 'graphs', 'graph'=>'bits'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "graphs") { echo(""); } + echo generate_link('Bits', $link_array, array('view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'bits')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') { + echo ''; + } - echo("("); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "minigraphs") { echo(""); } - echo(generate_link("Mini",$link_array,array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph'=>'bits'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "minigraphs") { echo(""); } - echo('|'); + echo '('; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') { + echo ""; + } - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "top10") { echo(""); } - echo(generate_link("Top10",$link_array,array('view' => 'macaccounting', 'subview' => 'top10', 'graph'=>'bits'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "top10") { echo(""); } - echo(") | "); + echo generate_link('Mini', $link_array, array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'bits')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') { + echo ''; + } - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "graphs") { echo(""); } - echo(generate_link("Packets",$link_array,array('view' => 'macaccounting', 'subview' => 'graphs', 'graph'=>'pkts'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "graphs") { echo(""); } - echo("("); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "minigraphs") { echo(""); } - echo(generate_link("Mini",$link_array,array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph'=>'pkts'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "minigraphs") { echo(""); } - echo('|'); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "top10") { echo(""); } - echo(generate_link("Top10",$link_array,array('view' => 'macaccounting', 'subview' => 'top10', 'graph'=>'pkts'))); - if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "top10") { echo(""); } - echo(")"); -} + echo '|'; -if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '".$port['port_id']."'") > "0" ) -{ + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') { + echo ""; + } - // FIXME ATM VPs - // FIXME URLs BROKEN + echo generate_link('Top10', $link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'bits')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') { + echo ''; + } - echo(" | ATM VPs : "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo("Bits"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo(" | "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "packets") { echo(""); } - echo("Packets"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo(" | "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "cells") { echo(""); } - echo("Cells"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } - echo(" | "); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "errors") { echo(""); } - echo("Errors"); - if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } -} + echo ') | '; -if ($_SESSION['userlevel'] >= '10') -{ - echo(" Create Bill"); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') { + echo ""; + } + + echo generate_link('Packets', $link_array, array('view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'pkts')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') { + echo ''; + } + + echo '('; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') { + echo ""; + } + + echo generate_link('Mini', $link_array, array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'pkts')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') { + echo ''; + } + + echo '|'; + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') { + echo ""; + } + + echo generate_link('Top10', $link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'pkts')); + if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') { + echo ''; + } + + echo ')'; +}//end if + +if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '".$port['port_id']."'") > '0') { + // FIXME ATM VPs + // FIXME URLs BROKEN + echo ' | ATM VPs : '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ""; + } + + echo "Bits"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } + + echo ' | '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'packets') { + echo ""; + } + + echo "Packets"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } + + echo ' | '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'cells') { + echo ""; + } + + echo "Cells"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } + + echo ' | '; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'errors') { + echo ""; + } + + echo "Errors"; + if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { + echo ''; + } +}//end if + +if ($_SESSION['userlevel'] >= '10') { + echo " Create Bill"; } print_optionbar_end(); -echo("
    "); +echo "
    "; -include("pages/device/port/".mres($vars['view']).".inc.php"); +require 'pages/device/port/'.mres($vars['view']).'.inc.php'; -echo("
    "); - -?> +echo '
    '; diff --git a/html/pages/device/port/events.inc.php b/html/pages/device/port/events.inc.php index 6de49ef262..5a113fafe6 100644 --- a/html/pages/device/port/events.inc.php +++ b/html/pages/device/port/events.inc.php @@ -1,15 +1,12 @@ '); +echo ''; -foreach ($entries as $entry) -{ - include("includes/print-event.inc.php"); +foreach ($entries as $entry) { + include 'includes/print-event.inc.php'; } -echo('
    '); +echo ''; -$pagetitle[] = "Events"; - -?> +$pagetitle[] = 'Events'; diff --git a/html/pages/device/port/pagp.inc.php b/html/pages/device/port/pagp.inc.php index e64437e2c2..7a8e41ff50 100644 --- a/html/pages/device/port/pagp.inc.php +++ b/html/pages/device/port/pagp.inc.php @@ -3,34 +3,32 @@ global $config; // FIXME functions! - -if (!$graph_type) { $graph_type = "pagp_bits"; } - -$daily_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['day']."&to=".$config['time']['now']."&width=215&height=100"; -$daily_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; - -$weekly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['week']."&to=".$config['time']['now']."&width=215&height=100"; -$weekly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['week']."&to=".$config['time']['now']."&width=500&height=150"; - -$monthly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['month']."&to=".$config['time']['now']."&width=215&height=100"; -$monthly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['month']."&to=".$config['time']['now']."&width=500&height=150"; - -$yearly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['year']."&to=".$config['time']['now']."&width=215&height=100"; -$yearly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['year']."&to=".$config['time']['now']."&width=500&height=150"; - -echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "); -echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "); -echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "); -echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "); - -foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member) -{ - echo("$br " . generate_port_link($member) . " (PAgP)"); - $br = "
    "; +if (!$graph_type) { + $graph_type = 'pagp_bits'; } -?> +$daily_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['day'].'&to='.$config['time']['now'].'&width=215&height=100'; +$daily_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; + +$weekly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['week'].'&to='.$config['time']['now'].'&width=215&height=100'; +$weekly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['week'].'&to='.$config['time']['now'].'&width=500&height=150'; + +$monthly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['month'].'&to='.$config['time']['now'].'&width=215&height=100'; +$monthly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['month'].'&to='.$config['time']['now'].'&width=500&height=150'; + +$yearly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['year'].'&to='.$config['time']['now'].'&width=215&height=100'; +$yearly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['year'].'&to='.$config['time']['now'].'&width=500&height=150'; + +echo "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "; +echo "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "; +echo "', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "; +echo "', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "; + +foreach (dbFetchRows('SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $member) { + echo "$br ".generate_port_link($member).' (PAgP)'; + $br = '
    '; +} diff --git a/html/pages/device/ports.inc.php b/html/pages/device/ports.inc.php index b254b376da..dc941e246f 100644 --- a/html/pages/device/ports.inc.php +++ b/html/pages/device/ports.inc.php @@ -1,15 +1,23 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'ports'); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'ports', +); print_optionbar_start(); @@ -17,110 +25,136 @@ $menu_options['basic'] = 'Basic'; $menu_options['details'] = 'Details'; $menu_options['arp'] = 'ARP Table'; -if(dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.port_id = L.local_port_id")) -{ - $menu_options['neighbours'] = 'Neighbours'; -} -if(dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) -{ - $menu_options['adsl'] = 'ADSL'; +if (dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.port_id = L.local_port_id")) { + $menu_options['neighbours'] = 'Neighbours'; } -$sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['view'] == $option) { echo(""); } - echo(generate_link($text,$link_array,array('view'=>$option))); - if ($vars['view'] == $option) { echo(""); } - $sep = " | "; +if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) { + $menu_options['adsl'] = 'ADSL'; +} + +$sep = ''; +foreach ($menu_options as $option => $text) { + echo $sep; + if ($vars['view'] == $option) { + echo ""; + } + + echo generate_link($text, $link_array, array('view' => $option)); + if ($vars['view'] == $option) { + echo ''; + } + + $sep = ' | '; } unset($sep); -echo(' | Graphs: '); +echo ' | Graphs: '; -$graph_types = array("bits" => "Bits", - "upkts" => "Unicast Packets", - "nupkts" => "Non-Unicast Packets", - "errors" => "Errors", - "etherlike" => "Etherlike"); +$graph_types = array( + 'bits' => 'Bits', + 'upkts' => 'Unicast Packets', + 'nupkts' => 'Non-Unicast Packets', + 'errors' => 'Errors', + 'etherlike' => 'Etherlike', +); -foreach ($graph_types as $type => $descr) -{ - echo("$type_sep"); - if ($vars['graph'] == $type && $vars['view'] == "graphs") { echo(""); } - echo(generate_link($descr,$link_array,array('view'=>'graphs','graph'=>$type))); - if ($vars['graph'] == $type && $vars['view'] == "graphs") { echo(""); } +foreach ($graph_types as $type => $descr) { + echo "$type_sep"; + if ($vars['graph'] == $type && $vars['view'] == 'graphs') { + echo ""; + } - echo(' ('); - if ($vars['graph'] == $type && $vars['view'] == "minigraphs") { echo(""); } - echo(generate_link('Mini',$link_array,array('view'=>'minigraphs','graph'=>$type))); - if ($vars['graph'] == $type && $vars['view'] == "minigraphs") { echo(""); } - echo(')'); - $type_sep = " | "; -} + echo generate_link($descr, $link_array, array('view' => 'graphs', 'graph' => $type)); + if ($vars['graph'] == $type && $vars['view'] == 'graphs') { + echo ''; + } + + echo ' ('; + if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { + echo ""; + } + + echo generate_link('Mini', $link_array, array('view' => 'minigraphs', 'graph' => $type)); + if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { + echo ''; + } + + echo ')'; + $type_sep = ' | '; +}//end foreach print_optionbar_end(); -if ($vars['view'] == 'minigraphs') -{ - $timeperiods = array('-1day','-1week','-1month','-1year'); - $from = '-1day'; - echo("
    "); - unset ($seperator); +if ($vars['view'] == 'minigraphs') { + $timeperiods = array( + '-1day', + '-1week', + '-1month', + '-1year', + ); + $from = '-1day'; + echo "
    "; + unset($seperator); - // FIXME - FIX THIS. UGLY. - foreach (dbFetchRows("select * from ports WHERE device_id = ? ORDER BY ifIndex", array($device['device_id'])) as $port) - { - echo("
    -
    ".makeshortif($port['ifDescr'])."
    - ".$device['hostname']." - ".$port['ifDescr']."
    \ - ".$port['ifAlias']." \ - \ - ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >". - " - -
    ".truncate(short_port_descr($port['ifAlias']), 32, '')."
    -
    "); - } - echo("
    "); -} elseif ($vars['view'] == "arp" || $vars['view'] == "adsl" || $vars['view'] == "neighbours") { - include("ports/".$vars['view'].".inc.php"); -} else { - if ($vars['view'] == "details") { $port_details = 1; } - echo("
    "); - $i = "1"; - - global $port_cache, $port_index_cache; - - $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device['device_id'])); - // As we've dragged the whole database, lets pre-populate our caches :) - // FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries. - foreach ($ports as $port) - { - $port_cache[$port['port_id']] = $port; - $port_index_cache[$port['device_id']][$port['ifIndex']] = $port; - } - - foreach ($ports as $port) - { - if ($config['memcached']['enable'] === TRUE) - { - $state = $memcache->get('port-'.$port['port_id'].'-state'); - if($debug) { print_r($state); } - if(is_array($state)) { $port = array_merge($port, $state); } - unset($state); + // FIXME - FIX THIS. UGLY. + foreach (dbFetchRows('select * from ports WHERE device_id = ? ORDER BY ifIndex', array($device['device_id'])) as $port) { + echo "
    +
    ".makeshortif($port['ifDescr']).'
    + ".$device['hostname'].' - '.$port['ifDescr'].'
    \ + '.$port['ifAlias']." \ + \ + ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >"." + +
    ".truncate(short_port_descr($port['ifAlias']), 32, '').'
    + '; } - include("includes/print-interface.inc.php"); - - $i++; - } - echo("
    "); + echo '
    '; } +else if ($vars['view'] == 'arp' || $vars['view'] == 'adsl' || $vars['view'] == 'neighbours') { + include 'ports/'.$vars['view'].'.inc.php'; +} +else { + if ($vars['view'] == 'details') { + $port_details = 1; + } -$pagetitle[] = "Ports"; + echo "
    "; + $i = '1'; -?> + global $port_cache, $port_index_cache; + + $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device['device_id'])); + // As we've dragged the whole database, lets pre-populate our caches :) + // FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries. + foreach ($ports as $port) { + $port_cache[$port['port_id']] = $port; + $port_index_cache[$port['device_id']][$port['ifIndex']] = $port; + } + + foreach ($ports as $port) { + if ($config['memcached']['enable'] === true) { + $state = $memcache->get('port-'.$port['port_id'].'-state'); + if ($debug) { + print_r($state); + } + + if (is_array($state)) { + $port = array_merge($port, $state); + } + + unset($state); + } + + include 'includes/print-interface.inc.php'; + + $i++; + } + + echo '
    '; +}//end if + +$pagetitle[] = 'Ports'; diff --git a/html/pages/device/ports/neighbours.inc.php b/html/pages/device/ports/neighbours.inc.php index 5e417eb996..b56136881e 100644 --- a/html/pages/device/ports/neighbours.inc.php +++ b/html/pages/device/ports/neighbours.inc.php @@ -10,8 +10,7 @@ echo 'Local Port Protocol '; -foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id', array($device['device_id'])) as $neighbour) -{ +foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id', array($device['device_id'])) as $neighbour) { if ($bg_colour == $list_colour_b) { $bg_colour = $list_colour_a; } diff --git a/html/pages/device/processes.inc.php b/html/pages/device/processes.inc.php index 41fda92887..0ce8e4c70f 100644 --- a/html/pages/device/processes.inc.php +++ b/html/pages/device/processes.inc.php @@ -1,19 +1,21 @@ +/* + * Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * Process Listing * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -22,77 +24,89 @@ * @subpackage Pages */ -switch( $vars['order'] ) { - case "vsz": - $order = "`vsz`"; - break; - case "rss": - $order = "`rss`"; - break; - case "cputime": - $order = "`cputime`"; - break; - case "user": - $order = "`user`"; - break; - case "command": - $order = "`command`"; - break; - default: - $order = "`pid`"; - break; +switch ($vars['order']) { + case 'vsz': + $order = '`vsz`'; + break; + + case 'rss': + $order = '`rss`'; + break; + + case 'cputime': + $order = '`cputime`'; + break; + + case 'user': + $order = '`user`'; + break; + + case 'command': + $order = '`command`'; + break; + + default: + $order = '`pid`'; + break; +}//end switch + +if ($vars['by'] == 'desc') { + $by = 'desc'; } -if( $vars['by'] == "desc" ) { - $by = "desc"; -} else { - $by = "asc"; +else { + $by = 'asc'; } $heads = array( - 'PID' => '', - 'VSZ' => 'Virtual Memory', - 'RSS' => 'Resident Memory', - 'cputime' => '', - 'user' => '', - 'command' => '' + 'PID' => '', + 'VSZ' => 'Virtual Memory', + 'RSS' => 'Resident Memory', + 'cputime' => '', + 'user' => '', + 'command' => '', ); echo "
    "; -foreach( $heads as $head=>$extra ) { - unset($lhead, $bhead); - $lhead = strtolower($head); - $bhead = 'asc'; - $icon = ""; - if( '`'.$lhead.'`' == $order ) { - $icon = " class='glyphicon glyphicon-chevron-"; - if( $by == 'asc' ) { - $bhead = 'desc'; - $icon .= 'up'; - } else { - $icon .= 'down'; - } - $icon .= "'"; - } - echo ''; -} -echo ""; +foreach ($heads as $head => $extra) { + unset($lhead, $bhead); + $lhead = strtolower($head); + $bhead = 'asc'; + $icon = ''; + if ('`'.$lhead.'`' == $order) { + $icon = " class='glyphicon glyphicon-chevron-"; + if ($by == 'asc') { + $bhead = 'desc'; + $icon .= 'up'; + } + else { + $icon .= 'down'; + } -foreach (dbFetchRows("SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY ".$order." ".$by, array($device['device_id'])) as $entry) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -} -echo"
     '; - if( !empty($extra) ) { - echo "$head"; - } else { - echo $head; - } - echo '
    '.$entry['pid'].''.format_si($entry['vsz']*1024).''.format_si($entry['rss']*1024).''.$entry['cputime'].''.$entry['user'].''.$entry['command'].'
    "; + $icon .= "'"; + } -?> + echo ' '; + if (!empty($extra)) { + echo "$head"; + } + else { + echo $head; + } + + echo ''; +}//end foreach + +echo ''; + +foreach (dbFetchRows('SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY '.$order.' '.$by, array($device['device_id'])) as $entry) { + echo ''; + echo ''.$entry['pid'].''; + echo ''.format_si(($entry['vsz'] * 1024)).''; + echo ''.format_si(($entry['rss'] * 1024)).''; + echo ''.$entry['cputime'].''; + echo ''.$entry['user'].''; + echo ''.$entry['command'].''; + echo ''; +} + +echo '
    '; diff --git a/html/pages/device/pseudowires.inc.php b/html/pages/device/pseudowires.inc.php index c134c8b661..c48bca5738 100644 --- a/html/pages/device/pseudowires.inc.php +++ b/html/pages/device/pseudowires.inc.php @@ -89,8 +89,7 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I WHERE P.port_id 'upkts', 'errors', ); - foreach ($types as $graph_type) - { + foreach ($types as $graph_type) { $pw_a['graph_type'] = 'port_'.$graph_type; print_port_thumbnail($pw_a); } diff --git a/html/pages/device/routing/bgp.inc.php b/html/pages/device/routing/bgp.inc.php index 5b327aca30..17f0629a02 100644 --- a/html/pages/device/routing/bgp.inc.php +++ b/html/pages/device/routing/bgp.inc.php @@ -1,203 +1,275 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'routing', - 'proto' => 'bgp'); +$link_array = array( + 'page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'routing', + 'proto' => 'bgp', +); -if(!isset($vars['view'])) { $vars['view'] = "basic"; } +if (!isset($vars['view'])) { + $vars['view'] = 'basic'; +} print_optionbar_start(); -echo "Local AS : " .$device['bgpLocalAs']." "; +echo 'Local AS : '.$device['bgpLocalAs'].' '; -echo("BGP » "); +echo "BGP » "; -if ($vars['view'] == "basic") { echo(""); } -echo(generate_link("Basic", $link_array,array('view'=>'basic'))); -if ($vars['view'] == "basic") { echo(""); } +if ($vars['view'] == 'basic') { + echo ""; +} -echo(" | "); +echo generate_link('Basic', $link_array, array('view' => 'basic')); +if ($vars['view'] == 'basic') { + echo ''; +} -if ($vars['view'] == "updates") { echo(""); } -echo(generate_link("Updates", $link_array,array('view'=>'updates'))); -if ($vars['view'] == "updates") { echo(""); } +echo ' | '; -echo(" | Prefixes: "); +if ($vars['view'] == 'updates') { + echo ""; +} -if ($vars['view'] == "prefixes_ipv4unicast") { echo(""); } -echo(generate_link("IPv4", $link_array,array('view'=>'prefixes_ipv4unicast'))); -if ($vars['view'] == "prefixes_ipv4unicast") { echo(""); } +echo generate_link('Updates', $link_array, array('view' => 'updates')); +if ($vars['view'] == 'updates') { + echo ''; +} -echo(" | "); +echo ' | Prefixes: '; -if ($vars['view'] == "prefixes_vpnv4unicast") { echo(""); } -echo(generate_link("VPNv4", $link_array,array('view'=>'prefixes_vpnv4unicast'))); -if ($vars['view'] == "prefixes_vpnv4unicast") { echo(""); } +if ($vars['view'] == 'prefixes_ipv4unicast') { + echo ""; +} -echo(" | "); +echo generate_link('IPv4', $link_array, array('view' => 'prefixes_ipv4unicast')); +if ($vars['view'] == 'prefixes_ipv4unicast') { + echo ''; +} -if ($vars['view'] == "prefixes_ipv6unicast") { echo(""); } -echo(generate_link("IPv6", $link_array,array('view'=>'prefixes_ipv6unicast'))); -if ($vars['view'] == "prefixes_ipv6unicast") { echo(""); } +echo ' | '; -echo(" | Traffic: "); +if ($vars['view'] == 'prefixes_vpnv4unicast') { + echo ""; +} -if ($vars['view'] == "macaccounting_bits") { echo(""); } -echo(generate_link("Bits", $link_array,array('view'=>'macaccounting_bits'))); -if ($vars['view'] == "macaccounting_bits") { echo(""); } -echo(" | "); -if ($vars['view'] == "macaccounting_pkts") { echo(""); } -echo(generate_link("Packets", $link_array,array('view'=>'macaccounting_pkts'))); -if ($vars['view'] == "macaccounting_pkts") { echo(""); } +echo generate_link('VPNv4', $link_array, array('view' => 'prefixes_vpnv4unicast')); +if ($vars['view'] == 'prefixes_vpnv4unicast') { + echo ''; +} + +echo ' | '; + +if ($vars['view'] == 'prefixes_ipv6unicast') { + echo ""; +} + +echo generate_link('IPv6', $link_array, array('view' => 'prefixes_ipv6unicast')); +if ($vars['view'] == 'prefixes_ipv6unicast') { + echo ''; +} + +echo ' | Traffic: '; + +if ($vars['view'] == 'macaccounting_bits') { + echo ""; +} + +echo generate_link('Bits', $link_array, array('view' => 'macaccounting_bits')); +if ($vars['view'] == 'macaccounting_bits') { + echo ''; +} + +echo ' | '; +if ($vars['view'] == 'macaccounting_pkts') { + echo ""; +} + +echo generate_link('Packets', $link_array, array('view' => 'macaccounting_pkts')); +if ($vars['view'] == 'macaccounting_pkts') { + echo ''; +} print_optionbar_end(); -echo(''); -echo(''); +echo '
    Peer addressTypeRemote ASStateUptime
    '; +echo ''; -$i = "1"; +$i = '1'; -foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? ORDER BY `bgpPEerRemoteAs`, `bgpPeerIdentifier`", array($device['device_id'])) as $peer) -{ - $has_macaccounting = dbFetchCell("SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address", array($peer['bgpPeerIdentifier'])); - unset($bg_image); - if (!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } - unset ($alert, $bg_image); - unset ($peerhost, $peername); +foreach (dbFetchRows('SELECT * FROM `bgpPeers` WHERE `device_id` = ? ORDER BY `bgpPEerRemoteAs`, `bgpPeerIdentifier`', array($device['device_id'])) as $peer) { + $has_macaccounting = dbFetchCell('SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address', array($peer['bgpPeerIdentifier'])); + unset($bg_image); + if (!is_integer($i / 2)) { + $bg_colour = $list_colour_a; + } + else { + $bg_colour = $list_colour_b; + } - if (!is_integer($i/2)) { $bg_colour = $list_colour_b; } else { $bg_colour = $list_colour_a; } - if ($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $peer['alert']=1; } - if ($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "gray"; } - if ($peer['bgpPeerAdminStatus'] == "stop") { $peer['alert']=0; $peer['disabled']=1; } + unset($alert, $bg_image); + unset($peerhost, $peername); - if ($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; } + if (!is_integer($i / 2)) { + $bg_colour = $list_colour_b; + } + else { + $bg_colour = $list_colour_a; + } - $query = "SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE "; - $query .= "(A.ipv4_address = ? AND I.port_id = A.port_id)"; - $query .= " AND D.device_id = I.device_id"; - $ipv4_host = dbFetchRow($query,array($peer['bgpPeerIdentifier'])); + if ($peer['bgpPeerState'] == 'established') { + $col = 'green'; + } + else { + $col = 'red'; + $peer['alert'] = 1; + } - $query = "SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE "; - $query .= "(A.ipv6_address = ? AND I.port_id = A.port_id)"; - $query .= " AND D.device_id = I.device_id"; - $ipv6_host = dbFetchRow($query,array($peer['bgpPeerIdentifier'])); + if ($peer['bgpPeerAdminStatus'] == 'start' || $peer['bgpPeerAdminStatus'] == 'running') { + $admin_col = 'green'; + } + else { + $admin_col = 'gray'; + } - if ($ipv4_host) - { - $peerhost = $ipv4_host; - } elseif ($ipv6_host) { - $peerhost = $ipv6_host; - } else { - unset($peerhost); - } + if ($peer['bgpPeerAdminStatus'] == 'stop') { + $peer['alert'] = 0; + $peer['disabled'] = 1; + } - if (is_array($peerhost)) - { - #$peername = generate_device_link($peerhost); - $peername = generate_device_link($peerhost) ." ". generate_port_link($peerhost); - $peer_url = "device/device=" . $peer['device_id'] . "/tab=routing/proto=bgp/view=updates/"; - } - else - { - #$peername = gethostbyaddr($peer['bgpPeerIdentifier']); // FFffuuu DNS // Cache this in discovery? -# if ($peername == $peer['bgpPeerIdentifier']) -# { -# unset($peername); -# } else { -# $peername = "".$peername.""; -# } - } + if ($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { + $peer_type = "iBGP"; + } + else { + $peer_type = "eBGP"; + } - unset($peer_af); - unset($sep); + $query = 'SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE '; + $query .= '(A.ipv4_address = ? AND I.port_id = A.port_id)'; + $query .= ' AND D.device_id = I.device_id'; + $ipv4_host = dbFetchRow($query, array($peer['bgpPeerIdentifier'])); - foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($device['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) - { - $afi = $afisafi['afi']; - $safi = $afisafi['safi']; - $this_afisafi = $afi.$safi; - $peer['afi'] .= $sep . $afi .".".$safi; - $sep = "
    "; - $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer - } + $query = 'SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE '; + $query .= '(A.ipv6_address = ? AND I.port_id = A.port_id)'; + $query .= ' AND D.device_id = I.device_id'; + $ipv6_host = dbFetchRow($query, array($peer['bgpPeerIdentifier'])); - unset($sep); + if ($ipv4_host) { + $peerhost = $ipv4_host; + } + else if ($ipv6_host) { + $peerhost = $ipv6_host; + } + else { + unset($peerhost); + } - if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { - $peer['bgpPeerIdentifier'] = Net_IPv6::compress($peer['bgpPeerIdentifier']); - } + if (is_array($peerhost)) { + // $peername = generate_device_link($peerhost); + $peername = generate_device_link($peerhost).' '.generate_port_link($peerhost); + $peer_url = 'device/device='.$peer['device_id'].'/tab=routing/proto=bgp/view=updates/'; + } + else { + // FIXME + // $peername = gethostbyaddr($peer['bgpPeerIdentifier']); // FFffuuu DNS // Cache this in discovery? + // if ($peername == $peer['bgpPeerIdentifier']) + // { + // unset($peername); + // } else { + // $peername = "".$peername.""; + // } + } + + unset($peer_af); + unset($sep); + + foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { + $afi = $afisafi['afi']; + $safi = $afisafi['safi']; + $this_afisafi = $afi.$safi; + $peer['afi'] .= $sep.$afi.'.'.$safi; + $sep = '
    '; + $peer['afisafi'][$this_afisafi] = 1; + // Build a list of valid AFI/SAFI for this peer + } + + unset($sep); + + if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { + $peer['bgpPeerIdentifier'] = Net_IPv6::compress($peer['bgpPeerIdentifier']); + } - $graph_type = "bgp_updates"; - $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; - $peeraddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer['bgpPeerIdentifier'] . ""; + $graph_type = 'bgp_updates'; + $peer_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; + $peeraddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer['bgpPeerIdentifier'].''; - echo('
    - "); + echo ' + '; - echo(" - - - - - - - - "); + echo ' + + + + + + + + '; - unset($invalid); + unset($invalid); - switch ($vars['view']) - { + switch ($vars['view']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': - list(,$afisafi) = explode("_", $vars['view']); - if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } - // FIXME no break?? - case 'updates': - $graph_array['type'] = "bgp_" . $vars['view']; - $graph_array['id'] = $peer['bgpPeer_id']; - } + list(,$afisafi) = explode('_', $vars['view']); + if (isset($peer['afisafi'][$afisafi])) { + $peer['graph'] = 1; + } - switch ($vars['view']) - { + // FIXME no break?? + case 'updates': + $graph_array['type'] = 'bgp_'.$vars['view']; + $graph_array['id'] = $peer['bgpPeer_id']; + } + + switch ($vars['view']) { case 'macaccounting_bits': case 'macaccounting_pkts': - $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier'])); - $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; - if (is_array($acc) && is_file($database)) - { - $peer['graph'] = 1; - $graph_array['id'] = $acc['ma_id']; - $graph_array['type'] = $vars['view']; - } - } + $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', array($peer['bgpPeerIdentifier'])); + $database = $config['rrd_dir'].'/'.$device['hostname'].'/cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'; + if (is_array($acc) && is_file($database)) { + $peer['graph'] = 1; + $graph_array['id'] = $acc['ma_id']; + $graph_array['type'] = $vars['view']; + } + } - if ($vars['view'] == 'updates') { $peer['graph'] = 1; } + if ($vars['view'] == 'updates') { + $peer['graph'] = 1; + } - if ($peer['graph']) - { - $graph_array['height'] = "100"; - $graph_array['width'] = "216"; - $graph_array['to'] = $config['time']['now']; - echo('"); - } + echo ''; + } - $i++; + $i++; - unset($valid_afi_safi); -} + unset($valid_afi_safi); +}//end foreach ?>
    Peer addressTypeRemote ASStateUptime
    ".$i."" . $peeraddresslink . "
    ".$peername."
    $peer_type" . (isset($peer['afi']) ? $peer['afi'] : '') . "AS" . $peer['bgpPeerRemoteAs'] . "
    " . $peer['astext'] . "
    " . $peer['bgpPeerAdminStatus'] . "
    " . $peer['bgpPeerState'] . "
    " .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
    - Updates " . $peer['bgpPeerInUpdates'] . " - " . $peer['bgpPeerOutUpdates'] . "
    '.$i.''.$peeraddresslink.'
    '.$peername."
    $peer_type".(isset($peer['afi']) ? $peer['afi'] : '').'AS'.$peer['bgpPeerRemoteAs'].'
    '.$peer['astext']."
    ".$peer['bgpPeerAdminStatus']."
    ".$peer['bgpPeerState'].'
    '.formatUptime($peer['bgpPeerFsmEstablishedTime'])."
    + Updates ".$peer['bgpPeerInUpdates']." + ".$peer['bgpPeerOutUpdates'].'
    '); + if ($peer['graph']) { + $graph_array['height'] = '100'; + $graph_array['width'] = '216'; + $graph_array['to'] = $config['time']['now']; + echo '
    '; - include("includes/print-graphrow.inc.php"); + include 'includes/print-graphrow.inc.php'; - echo("
    diff --git a/html/pages/device/routing/ospf.inc.php b/html/pages/device/routing/ospf.inc.php index ed126a7fe3..7bf6798b7b 100644 --- a/html/pages/device/routing/ospf.inc.php +++ b/html/pages/device/routing/ospf.inc.php @@ -88,8 +88,7 @@ foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', arr // # Loop Ports $i_p = ($i_a + 1); $p_sql = "SELECT * FROM `ospf_ports` AS O, `ports` AS P WHERE O.`ospfIfAdminStat` = 'enabled' AND O.`device_id` = ? AND O.`ospfIfAreaId` = ? AND P.port_id = O.port_id"; - foreach (dbFetchRows($p_sql, array($device['device_id'], $area['ospfAreaId'])) as $ospfport) - { + foreach (dbFetchRows($p_sql, array($device['device_id'], $area['ospfAreaId'])) as $ospfport) { if (!is_integer($i_a / 2)) { if (!is_integer($i_p / 2)) { $port_bg = $list_colour_b_b; diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index aed9398dd2..9efc95d63a 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -1,134 +1,135 @@ = '7') { + if (!is_array($config['rancid_configs'])) { + $config['rancid_configs'] = array($config['rancid_configs']); + } -if ($_SESSION['userlevel'] >= "7") -{ + if (isset($config['rancid_configs'][0])) { + foreach ($config['rancid_configs'] as $configs) { + if ($configs[(strlen($configs) - 1)] != '/') { + $configs .= '/'; + } - if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); } + if (is_file($configs.$device['hostname'])) { + $file = $configs.$device['hostname']; + } + } - if (isset($config['rancid_configs'][0])) { + echo '
    '; - foreach ($config['rancid_configs'] as $configs) { - if ($configs[strlen($configs) - 1] != '/') { - $configs .= '/'; - } - if (is_file($configs . $device['hostname'])) { - $file = $configs . $device['hostname']; - } - } + print_optionbar_start('', ''); - echo('
    '); + echo "Config » "; - print_optionbar_start('', ''); + if (!$vars['rev']) { + echo ''; + echo generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig')); + echo ''; + } + else { + echo generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig')); + } - echo("Config » "); + if (function_exists('svn_log')) { + $sep = ' | '; + $svnlogs = svn_log($file, SVN_REVISION_HEAD, null, 8); + $revlist = array(); - if (!$vars['rev']) { - echo(''); - echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); - echo(""); - } else { - echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); - } + foreach ($svnlogs as $svnlog) { + echo $sep; + $revlist[] = $svnlog['rev']; - if (function_exists('svn_log')) { + if ($vars['rev'] == $svnlog['rev']) { + echo ''; + } - $sep = " | "; - $svnlogs = svn_log($file, SVN_REVISION_HEAD, NULL, 8); - $revlist = array(); + $linktext = 'r'.$svnlog['rev'].' '.date($config['dateformat']['byminute'], strtotime($svnlog['date'])).''; + echo generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog['rev'])); - foreach ($svnlogs as $svnlog) { + if ($vars['rev'] == $svnlog['rev']) { + echo ''; + } - echo($sep); - $revlist[] = $svnlog["rev"]; + $sep = ' | '; + } + }//end if - if ($vars['rev'] == $svnlog["rev"]) { - echo(''); - } - $linktext = "r" . $svnlog["rev"] . " " . date($config['dateformat']['byminute'], strtotime($svnlog["date"])) . ""; - echo(generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog["rev"]))); + print_optionbar_end(); - if ($vars['rev'] == $svnlog["rev"]) { - echo(""); - } + if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { + list($diff, $errors) = svn_diff($file, ($vars['rev'] - 1), $file, $vars['rev']); + if (!$diff) { + $text = 'No Difference'; + } + else { + $text = ''; + while (!feof($diff)) { + $text .= fread($diff, 8192); + } - $sep = " | "; - } - } + fclose($diff); + fclose($errors); + } + } + else { + $fh = fopen($file, 'r') or die("Can't open file"); + $text = fread($fh, filesize($file)); + fclose($fh); + } - print_optionbar_end(); + if ($config['rancid_ignorecomments']) { + $lines = explode("\n", $text); + for ($i = 0; $i < count($lines); $i++) { + if ($lines[$i][0] == '#') { + unset($lines[$i]); + } + } - if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { - list($diff, $errors) = svn_diff($file, $vars['rev'] - 1, $file, $vars['rev']); - if (!$diff) { - $text = "No Difference"; - } else { - $text = ""; - while (!feof($diff)) { - $text .= fread($diff, 8192); - } - fclose($diff); - fclose($errors); - } + $text = join("\n", $lines); + } + } + else if ($config['oxidized']['enabled'] === true && isset($config['oxidized']['url'])) { + $node_info = json_decode(file_get_contents($config['oxidized']['url'].'/node/show/'.$device['hostname'].'?format=json'), true); + $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.$device['hostname']); + if ($text == 'node not found') { + $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.$device['os'].'/'.$device['hostname']); + } - } else { - $fh = fopen($file, 'r') or die("Can't open file"); - $text = fread($fh, filesize($file)); - fclose($fh); - } - - if ($config['rancid_ignorecomments']) { - $lines = explode("\n", $text); - for ($i = 0; $i < count($lines); $i++) { - if ($lines[$i][0] == "#") { - unset($lines[$i]); - } - } - $text = join("\n", $lines); - } - } elseif ($config['oxidized']['enabled'] === TRUE && isset($config['oxidized']['url'])) { - $node_info = json_decode(file_get_contents($config['oxidized']['url']."/node/show/".$device['hostname']."?format=json"),TRUE); - $text = file_get_contents($config['oxidized']['url']."/node/fetch/".$device['hostname']); - if ($text == "node not found") { - $text = file_get_contents($config['oxidized']['url']."/node/fetch/".$device['os']."/".$device['hostname']); - } - - if (is_array($node_info)) { - echo('
    -
    + if (is_array($node_info)) { + echo '
    +
    -
    -
    Sync status: '.$node_info['last']['status'].'
    -
      -
    • Node: '. $node_info['name'].'
    • -
    • IP: '. $node_info['ip'].'
    • -
    • Model: '. $node_info['model'].'
    • -
    • Last Sync: '. $node_info['last']['end'].'
    • -
    -
    +
    +
    Sync status: '.$node_info['last']['status'].'
    +
      +
    • Node: '.$node_info['name'].'
    • +
    • IP: '.$node_info['ip'].'
    • +
    • Model: '.$node_info['model'].'
    • +
    • Last Sync: '.$node_info['last']['end'].'
    • +
    -
    '); - } else { - echo "
    "; - print_error("We couldn't retrieve the device information from Oxidized"); - $text = ''; - } +
    +
    '; + } + else { + echo '
    '; + print_error("We couldn't retrieve the device information from Oxidized"); + $text = ''; + } + }//end if - } + if (!empty($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 $geshi->parse_code(); + } +}//end if - if (!empty($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($geshi->parse_code()); - } -} - -$pagetitle[] = "Config"; - -?> +$pagetitle[] = 'Config'; diff --git a/html/pages/device/slas.inc.php b/html/pages/device/slas.inc.php index 3cc6cbf119..587c7d7438 100644 --- a/html/pages/device/slas.inc.php +++ b/html/pages/device/slas.inc.php @@ -12,7 +12,7 @@ foreach ($slas as $sla) { $sla_type = $sla['rtt_type']; if (!in_array($sla_type, $sla_types)) { - if (isset($config['sla_type_labels'][$sla_type])) { + if (isset($config['sla_type_labels'][$sla_type])) { $text = $config['sla_type_labels'][$sla_type]; } } diff --git a/html/pages/devices.inc.php b/html/pages/devices.inc.php index 67a8c39edd..0367b8a1c3 100644 --- a/html/pages/devices.inc.php +++ b/html/pages/devices.inc.php @@ -2,7 +2,9 @@ // Set Defaults here -if(!isset($vars['format'])) { $vars['format'] = "list_detail"; } +if(!isset($vars['format'])) { + $vars['format'] = "list_detail"; +} $pagetitle[] = "Devices"; @@ -10,23 +12,19 @@ print_optionbar_start(); echo('Lists » '); -$menu_options = array('basic' => 'Basic', - 'detail' => 'Detail'); +$menu_options = array('basic' => 'Basic', 'detail' => 'Detail'); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == "list_".$option) { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == "list_".$option) { + echo(""); + } + $sep = " | "; } ?> @@ -38,29 +36,26 @@ foreach ($menu_options as $option => $text) 'Bits', - 'processor' => 'CPU', - 'ucd_load' => 'Load', - 'mempool' => 'Memory', - 'uptime' => 'Uptime', - 'storage' => 'Storage', - 'diskio' => 'Disk I/O', - 'poller_perf' => 'Poller', - 'ping_perf' => 'Ping' - ); + 'processor' => 'CPU', + 'ucd_load' => 'Load', + 'mempool' => 'Memory', + 'uptime' => 'Uptime', + 'storage' => 'Storage', + 'diskio' => 'Disk I/O', + 'poller_perf' => 'Poller', + 'ping_perf' => 'Ping' +); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == 'graph_'.$option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == 'graph_'.$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == 'graph_'.$option) { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == 'graph_'.$option) { + echo(""); + } + $sep = " | "; } ?> @@ -69,21 +64,21 @@ foreach ($menu_options as $option => $text) '')).'">Restore Search'); - } else { +} +else { echo('Remove Search'); - } +} - echo(" | "); +echo(" | "); - if (isset($vars['bare']) && $vars['bare'] == "yes") - { +if (isset($vars['bare']) && $vars['bare'] == "yes") { echo('Restore Header'); - } else { +} +else { echo('Remove Header'); - } +} print_optionbar_end(); ?> @@ -94,76 +89,110 @@ print_optionbar_end(); list($format, $subformat) = explode("_", $vars['format'], 2); -if($format == "graph") -{ -$sql_param = array(); +if($format == "graph") { + $sql_param = array(); -if(isset($vars['state'])) -{ - if($vars['state'] == 'up') - { - $state = '1'; - } - elseif($vars['state'] == 'down') - { - $state = '0'; - } -} + if(isset($vars['state'])) { + if($vars['state'] == 'up') { + $state = '1'; + } + elseif($vars['state'] == 'down') { + $state = '0'; + } + } -if (!empty($vars['hostname'])) { $where .= " AND hostname LIKE ?"; $sql_param[] = "%".$vars['hostname']."%"; } -if (!empty($vars['os'])) { $where .= " AND os = ?"; $sql_param[] = $vars['os']; } -if (!empty($vars['version'])) { $where .= " AND version = ?"; $sql_param[] = $vars['version']; } -if (!empty($vars['hardware'])) { $where .= " AND hardware = ?"; $sql_param[] = $vars['hardware']; } -if (!empty($vars['features'])) { $where .= " AND features = ?"; $sql_param[] = $vars['features']; } -if (!empty($vars['type'])) { - if ($vars['type'] == 'generic') { - $where .= " AND ( type = ? OR type = '')"; $sql_param[] = $vars['type']; - } else { - $where .= " AND type = ?"; $sql_param[] = $vars['type']; - } -} -if (!empty($vars['state'])) { - $where .= " AND status= ?"; $sql_param[] = $state; - $where .= " AND disabled='0' AND `ignore`='0'"; $sql_param[] = ''; -} -if (!empty($vars['disabled'])) { $where .= " AND disabled= ?"; $sql_param[] = $vars['disabled']; } -if (!empty($vars['ignore'])) { $where .= " AND `ignore`= ?"; $sql_param[] = $vars['ignore']; } -if (!empty($vars['location']) && $vars['location'] == "Unset") { $location_filter = ''; } -if (!empty($vars['location'])) { $location_filter = $vars['location']; } -if( !empty($vars['group']) ) { - require_once('../includes/device-groups.inc.php'); - $where .= " AND ( "; - foreach( GetDevicesFromGroup($vars['group']) as $dev ) { - $where .= "device_id = ? OR "; - $sql_param[] = $dev['device_id']; - } - $where = substr($where, 0, strlen($where)-3); - $where .= " )"; -} + if (!empty($vars['hostname'])) { + $where .= " AND hostname LIKE ?"; + $sql_param[] = "%".$vars['hostname']."%"; + } + if (!empty($vars['os'])) { + $where .= " AND os = ?"; + $sql_param[] = $vars['os']; + } + if (!empty($vars['version'])) { + $where .= " AND version = ?"; + $sql_param[] = $vars['version']; + } + if (!empty($vars['hardware'])) { + $where .= " AND hardware = ?"; + $sql_param[] = $vars['hardware']; + } + if (!empty($vars['features'])) { + $where .= " AND features = ?"; + $sql_param[] = $vars['features']; + } -$query = "SELECT * FROM `devices` WHERE 1 "; + if (!empty($vars['type'])) { + if ($vars['type'] == 'generic') { + $where .= " AND ( type = ? OR type = '')"; + $sql_param[] = $vars['type']; + } + else { + $where .= " AND type = ?"; + $sql_param[] = $vars['type']; + } + } + if (!empty($vars['state'])) { + $where .= " AND status= ?"; + $sql_param[] = $state; + $where .= " AND disabled='0' AND `ignore`='0'"; + $sql_param[] = ''; + } + if (!empty($vars['disabled'])) { + $where .= " AND disabled= ?"; + $sql_param[] = $vars['disabled']; + } + if (!empty($vars['ignore'])) { + $where .= " AND `ignore`= ?"; + $sql_param[] = $vars['ignore']; + } + if (!empty($vars['location']) && $vars['location'] == "Unset") { + $location_filter = ''; + } + if (!empty($vars['location'])) { + $location_filter = $vars['location']; + } + if( !empty($vars['group']) ) { + require_once('../includes/device-groups.inc.php'); + $where .= " AND ( "; + foreach( GetDevicesFromGroup($vars['group']) as $dev ) { + $where .= "device_id = ? OR "; + $sql_param[] = $dev['device_id']; + } + $where = substr($where, 0, strlen($where)-3); + $where .= " )"; + } -if (isset($where)) { - $query .= $where; -} + $query = "SELECT * FROM `devices` WHERE 1 "; -$query .= " ORDER BY hostname"; + if (isset($where)) { + $query .= $where; + } - $row = 1; - foreach (dbFetchRows($query, $sql_param) as $device) - { - if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + $query .= " ORDER BY hostname"; - if (device_permitted($device['device_id'])) - { - if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter) - || $device['location'] == $location_filter)) - { - $graph_type = "device_".$subformat; + $row = 1; + foreach (dbFetchRows($query, $sql_param) as $device) { + if (is_integer($row/2)) { + $row_colour = $list_colour_a; + } + else { + $row_colour = $list_colour_b; + } - if ($_SESSION['widescreen']) { $width=270; } else { $width=315; } + if (device_permitted($device['device_id'])) { + if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter) + || $device['location'] == $location_filter)) { + $graph_type = "device_".$subformat; - echo("
    + if ($_SESSION['widescreen']) { + $width=270; + } + else { + $width=315; + } + + echo("\ \ @@ -171,11 +200,11 @@ $query .= " ORDER BY hostname"; "
    "); - } + } + } } - } - -} else { +} +else { ?> @@ -209,22 +238,23 @@ $query .= " ORDER BY hostname"; ""+ '.$config['os'][$tmp_os]['text'].'"+'); + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `os` FROM `devices` AS D WHERE 1 GROUP BY `os` ORDER BY `os`"; + } + else { + $sql = "SELECT `os` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `os` ORDER BY `os`"; + $param[] = $_SESSION['user_id']; + } + foreach (dbFetch($sql,$param) as $data) { + if ($data['os']) { + $tmp_os = clean_bootgrid($data['os']); + echo('""+'); + } } -} ?> ""+ "
    "+ @@ -233,22 +263,23 @@ foreach (dbFetch($sql,$param) as $data) { ""+ '.$tmp_version.'"+'); } - echo('">'.$tmp_version.'"+'); - } -} + } ?> ""+ "
    "+ @@ -257,22 +288,23 @@ foreach (dbFetch($sql,$param) as $data) { ""+ '.$tmp_hardware.'"+'); + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `hardware` FROM `devices` AS D WHERE 1 GROUP BY `hardware` ORDER BY `hardware`"; + } + else { + $sql = "SELECT `hardware` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hardware` ORDER BY `hardware`"; + $param[] = $_SESSION['user_id']; + } + foreach (dbFetch($sql,$param) as $data) { + if ($data['hardware']) { + $tmp_hardware = clean_bootgrid($data['hardware']); + echo('""+'); + } } -} ?> ""+ @@ -282,24 +314,24 @@ foreach (dbFetch($sql,$param) as $data) { ""+ '.$tmp_features.'"+'); + else { + $sql = "SELECT `features` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `features` ORDER BY `features`"; + $param[] = $_SESSION['user_id']; + } + + foreach (dbFetch($sql,$param) as $data) { + if ($data['features']) { + $tmp_features = clean_bootgrid($data['features']); + echo('""+'); + } } -} ?> ""+ @@ -311,16 +343,16 @@ foreach (dbFetch($sql,$param) as $data) '.$location.'"+'); } - echo('">'.$location.'"+'); } -} ?> ""+ ""+ @@ -329,21 +361,22 @@ foreach (getlocations() as $location) { ""+ '.ucfirst($data['type']).'"+'); + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `type` FROM `devices` AS D WHERE 1 GROUP BY `type` ORDER BY `type`"; + } + else { + $sql = "SELECT `type` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `type` ORDER BY `type`"; + $param[] = $_SESSION['user_id']; + } + foreach (dbFetch($sql,$param) as $data) { + if ($data['type']) { + echo('""+'); + } } -} ?> ""+ @@ -357,9 +390,9 @@ foreach (dbFetch($sql,$param) as $data) { "

    " var grid = $("#devices").bootgrid({ @@ -400,5 +433,3 @@ var grid = $("#devices").bootgrid({ diff --git a/html/pages/editsrv.inc.php b/html/pages/editsrv.inc.php index 9c56b96d1e..1c04e4510f 100644 --- a/html/pages/editsrv.inc.php +++ b/html/pages/editsrv.inc.php @@ -1,35 +1,30 @@ "5") - { - include("includes/service-edit.inc.php"); + if ($_POST['confirm-editsrv']) { + if ($_SESSION['userlevel'] > '5') { + include 'includes/service-edit.inc.php'; } } - foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname") as $device) - { - $servicesform .= ""; + foreach (dbFetchRows('SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname') as $device) { + $servicesform .= "'; } - if ($updated) { print_message("Service updated!"); } + if ($updated) { + print_message('Service updated!'); + } if ($_POST['editsrv'] == 'yes') { - - require_once "includes/print-service-edit.inc.php"; - - } else { - - echo(" + include_once 'includes/print-service-edit.inc.php'; + } + else { + echo "

    Delete Service

    @@ -46,7 +41,6 @@ if (is_admin() === FALSE && is_read() === FALSE) { -
    "); - } - -} + "; + }//end if +}//end if diff --git a/html/pages/edituser.inc.php b/html/pages/edituser.inc.php index 6a9a7d2830..ec2a3f1c9e 100644 --- a/html/pages/edituser.inc.php +++ b/html/pages/edituser.inc.php @@ -1,167 +1,170 @@ "); +echo "
    "; -$pagetitle[] = "Edit user"; +$pagetitle[] = 'Edit user'; -if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php"); } else -{ - if ($vars['user_id'] && !$vars['edit']) - { - $user_data = dbFetchRow("SELECT * FROM users WHERE user_id = ?", array($vars['user_id'])); - echo("

    " . $user_data['realname'] . "

    Change...

    "); - // Perform actions if requested +if ($_SESSION['userlevel'] != '10') { + include 'includes/error-no-perm.inc.php'; +} +else { + if ($vars['user_id'] && !$vars['edit']) { + $user_data = dbFetchRow('SELECT * FROM users WHERE user_id = ?', array($vars['user_id'])); + echo '

    '.$user_data['realname']."

    Change...

    "; + // Perform actions if requested + if ($vars['action'] == 'deldevperm') { + if (dbFetchCell('SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id']))) { + dbDelete('devices_perms', '`device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id'])); + } + } - if ($vars['action'] == "deldevperm") - { - if (dbFetchCell("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?", array($vars['device_id'] ,$vars['user_id']))) - { - dbDelete('devices_perms', "`device_id` = ? AND `user_id` = ?", array($vars['device_id'], $vars['user_id'])); - } - } - if ($vars['action'] == "adddevperm") - { - if (!dbFetchCell("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?", array($vars['device_id'] ,$vars['user_id']))) - { - dbInsert(array('device_id' => $vars['device_id'], 'user_id' => $vars['user_id']), 'devices_perms'); - } - } - if ($vars['action'] == "delifperm") - { - if (dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) - { - dbDelete('ports_perms', "`port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id'])); - } - } - if ($vars['action'] == "addifperm") - { - if (!dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) - { - dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms'); - } - } - if ($vars['action'] == "delbillperm") - { - if (dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) - { - dbDelete('bill_perms', "`bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id'])); - } - } - if ($vars['action'] == "addbillperm") - { - if (!dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) - { - dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms'); - } - } + if ($vars['action'] == 'adddevperm') { + if (!dbFetchCell('SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id']))) { + dbInsert(array('device_id' => $vars['device_id'], 'user_id' => $vars['user_id']), 'devices_perms'); + } + } - echo('
    -
    '); + if ($vars['action'] == 'delifperm') { + if (dbFetchCell('SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id']))) { + dbDelete('ports_perms', '`port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id'])); + } + } - // Display devices this users has access to - echo("

    Device Access

    "); + if ($vars['action'] == 'addifperm') { + if (!dbFetchCell('SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id']))) { + dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms'); + } + } - echo("
    + if ($vars['action'] == 'delbillperm') { + if (dbFetchCell('SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id']))) { + dbDelete('bill_perms', '`bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id'])); + } + } + + if ($vars['action'] == 'addbillperm') { + if (!dbFetchCell('SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id']))) { + dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms'); + } + } + + echo '
    +
    '; + + // Display devices this users has access to + echo '

    Device Access

    '; + + echo "
    - "); + "; - $device_perms = dbFetchRows("SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id", array($vars['user_id'])); - foreach ($device_perms as $device_perm) - { - echo(""); - $access_list[] = $device_perm['device_id']; - $permdone = "yes"; - } + $device_perms = dbFetchRows('SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id', array($vars['user_id'])); + foreach ($device_perms as $device_perm) { + echo '"; + $access_list[] = $device_perm['device_id']; + $permdone = 'yes'; + } - echo("
    Device Action
    " . $device_perm['hostname'] . "
    '.$device_perm['hostname']."
    -
    "); + echo ' +
    '; - if (!$permdone) { echo("None Configured"); } + if (!$permdone) { + echo 'None Configured'; + } - // Display devices this user doesn't have access to - echo("

    Grant access to new device

    "); - echo("
    - + // Display devices this user doesn't have access to + echo '

    Grant access to new device

    '; + echo " +
    - "; - $devices = dbFetchRows("SELECT * FROM `devices` ORDER BY hostname"); - foreach ($devices as $device) - { - unset($done); - foreach ($access_list as $ac) { if ($ac == $device['device_id']) { $done = 1; } } - if (!$done) - { - echo(""); - } - } + $devices = dbFetchRows('SELECT * FROM `devices` ORDER BY hostname'); + foreach ($devices as $device) { + unset($done); + foreach ($access_list as $ac) { + if ($ac == $device['device_id']) { + $done = 1; + } + } - echo(" + if (!$done) { + echo "'; + } + } + + echo "
    -
    "); + "; - echo("
    -
    "); - echo("

    Interface Access

    "); + echo "
    +
    "; + echo '

    Interface Access

    '; - $interface_perms = dbFetchRows("SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($vars['user_id'])); + $interface_perms = dbFetchRows('SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id', array($vars['user_id'])); - echo("
    + echo "
    - "); - foreach ($interface_perms as $interface_perm) - { - echo(" + "; + foreach ($interface_perms as $interface_perm) { + echo ' - "); - $ipermdone = "yes"; - } - echo("
    Interface name Action
    - ".$interface_perm['hostname']." - ".$interface_perm['ifDescr']."". - "" . $interface_perm['ifAlias'] . " + '.$interface_perm['hostname'].' - '.$interface_perm['ifDescr'].''.''.$interface_perm['ifAlias']." -    +   
    -
    "); + "; + $ipermdone = 'yes'; + } - if (!$ipermdone) { echo("None Configured"); } + echo ' +
    '; - // Display devices this user doesn't have access to - echo("

    Grant access to new interface

    "); + if (!$ipermdone) { + echo 'None Configured'; + } - echo("
    - + // Display devices this user doesn't have access to + echo '

    Grant access to new interface

    '; + + echo " +
    + if (!$done) { + echo "'; + } + } + + echo "
    @@ -176,133 +179,135 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    - "); + "; - echo("
    -
    "); - echo("

    Bill Access

    "); + echo "
    +
    "; + echo '

    Bill Access

    '; - $bill_perms = dbFetchRows("SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id", array($vars['user_id'])); + $bill_perms = dbFetchRows('SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id', array($vars['user_id'])); - echo("
    + echo "
    - "); + "; - foreach ($bill_perms as $bill_perm) - { - echo(" + foreach ($bill_perms as $bill_perm) { + echo ' - "); - $bill_access_list[] = $bill_perm['bill_id']; + "; + $bill_access_list[] = $bill_perm['bill_id']; - $bpermdone = "yes"; - } + $bpermdone = 'yes'; + } - echo("
    Bill name Action
    - ".$bill_perm['bill_name']."   + '.$bill_perm['bill_name']."  
    -
    "); + echo ' +
    '; - if (!$bpermdone) { echo("None Configured"); } + if (!$bpermdone) { + echo 'None Configured'; + } - // Display devices this user doesn't have access to - echo("

    Grant access to new bill

    "); - echo("
    - + // Display devices this user doesn't have access to + echo '

    Grant access to new bill

    '; + echo " +
    - "; - $bills = dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_name`"); - foreach ($bills as $bill) - { - unset($done); - foreach ($bill_access_list as $ac) { if ($ac == $bill['bill_id']) { $done = 1; } } - if (!$done) - { - echo(""); - } - } + $bills = dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_name`'); + foreach ($bills as $bill) { + unset($done); + foreach ($bill_access_list as $ac) { + if ($ac == $bill['bill_id']) { + $done = 1; + } + } - echo(" + if (!$done) { + echo "'; + } + } + + echo "
    -
    "); - - } elseif ($vars['user_id'] && $vars['edit']) { - - if($_SESSION['userlevel'] == 11) { - demo_account(); - } else { - - if(!empty($vars['new_level'])) - { - if($vars['can_modify_passwd'] == 'on') { - $vars['can_modify_passwd'] = '1'; - } - update_user($vars['user_id'],$vars['new_realname'],$vars['new_level'],$vars['can_modify_passwd'],$vars['new_email']); - print_message("User has been updated"); +
    "; } - - if(can_update_users() == '1') { - - $users_details = get_user($vars['user_id']); - if(!empty($users_details)) - { - - if(empty($vars['new_realname'])) - { - $vars['new_realname'] = $users_details['realname']; - } - if(empty($vars['new_level'])) - { - $vars['new_level'] = $users_details['level']; - } - if(empty($vars['can_modify_passwd'])) - { - $vars['can_modify_passwd'] = $users_details['can_modify_passwd']; - } elseif($vars['can_modify_passwd'] == 'on') { - $vars['can_modify_passwd'] = '1'; - } - if(empty($vars['new_email'])) - { - $vars['new_email'] = $users_details['email']; + else if ($vars['user_id'] && $vars['edit']) { + if ($_SESSION['userlevel'] == 11) { + demo_account(); } + else { + if (!empty($vars['new_level'])) { + if ($vars['can_modify_passwd'] == 'on') { + $vars['can_modify_passwd'] = '1'; + } - if( $config['twofactor'] ) { - if( $vars['twofactorremove'] ) { - if( dbUpdate(array('twofactor'=>''),users,'user_id = ?',array($vars['user_id'])) ) { - echo "
    TwoFactor credentials removed.
    "; - } else { - echo "
    Couldnt remove user's TwoFactor credentials.
    "; + update_user($vars['user_id'], $vars['new_realname'], $vars['new_level'], $vars['can_modify_passwd'], $vars['new_email']); + print_message('User has been updated'); } - } - if( $vars['twofactorunlock'] ) { - $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE user_id = ?",array($vars['user_id'])); - $twofactor = json_decode($twofactor['twofactor'],true); - $twofactor['fails'] = 0; - if( dbUpdate(array('twofactor'=>json_encode($twofactor)),users,'user_id = ?',array($vars['user_id'])) ) { - echo "
    User unlocked.
    "; - } else { - echo "
    Couldnt reset user's TwoFactor failures.
    "; - } - } - } - echo("
    - + if (can_update_users() == '1') { + $users_details = get_user($vars['user_id']); + if (!empty($users_details)) { + if (empty($vars['new_realname'])) { + $vars['new_realname'] = $users_details['realname']; + } + + if (empty($vars['new_level'])) { + $vars['new_level'] = $users_details['level']; + } + + if (empty($vars['can_modify_passwd'])) { + $vars['can_modify_passwd'] = $users_details['can_modify_passwd']; + } + else if ($vars['can_modify_passwd'] == 'on') { + $vars['can_modify_passwd'] = '1'; + } + + if (empty($vars['new_email'])) { + $vars['new_email'] = $users_details['email']; + } + + if ($config['twofactor']) { + if ($vars['twofactorremove']) { + if (dbUpdate(array('twofactor' => ''), users, 'user_id = ?', array($vars['user_id']))) { + echo "
    TwoFactor credentials removed.
    "; + } + else { + echo "
    Couldnt remove user's TwoFactor credentials.
    "; + } + } + + if ($vars['twofactorunlock']) { + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE user_id = ?', array($vars['user_id'])); + $twofactor = json_decode($twofactor['twofactor'], true); + $twofactor['fails'] = 0; + if (dbUpdate(array('twofactor' => json_encode($twofactor)), users, 'user_id = ?', array($vars['user_id']))) { + echo "
    User unlocked.
    "; + } + else { + echo "
    Couldnt reset user's TwoFactor failures.
    "; + } + } + } + + echo " +
    - +
    @@ -310,7 +315,7 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    - +
    @@ -319,10 +324,22 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    @@ -332,7 +349,10 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    @@ -340,14 +360,14 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    - "); - if( $config['twofactor'] ) { - echo "

    Two-Factor Authentication

    "; - $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE user_id = ?",array($vars['user_id'])); - $twofactor = json_decode($twofactor['twofactor'],true); - if( $twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time()-$twofactor['last']) < $config['twofactor_lock']) ) { - echo "
    - +
    "; + if ($config['twofactor']) { + echo "

    Two-Factor Authentication

    "; + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE user_id = ?', array($vars['user_id'])); + $twofactor = json_decode($twofactor['twofactor'], true); + if ($twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time() - $twofactor['last']) < $config['twofactor_lock'])) { + echo "
    +
    @@ -355,43 +375,47 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
    "; - } - if( $twofactor['key'] ) { - echo "
    - + } + + if ($twofactor['key']) { + echo " +
    "; - } else { - echo "

    No TwoFactor key generated for this user, Nothing to do.

    "; - } - } - } else { - echo print_error("Error getting user details"); - } - } else { - echo print_error("Authentication method doesn't support updating users"); + } + else { + echo '

    No TwoFactor key generated for this user, Nothing to do.

    '; + } + }//end if + } + else { + echo print_error('Error getting user details'); + }//end if + } + else { + echo print_error("Authentication method doesn't support updating users"); + }//end if + }//end if } - } - } else { + else { + $user_list = get_userlist(); - $user_list = get_userlist(); + echo '

    Select a user to edit

    '; - echo("

    Select a user to edit

    "); - - echo("
    + echo "
    - +
    @@ -399,11 +423,8 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php"); /
    - "); - } + "; + }//end if +}//end if -} - -echo("
    "); - -?> +echo '
    '; diff --git a/html/pages/eventlog.inc.php b/html/pages/eventlog.inc.php index 4e1cad13d2..2ac41ec91b 100644 --- a/html/pages/eventlog.inc.php +++ b/html/pages/eventlog.inc.php @@ -1,16 +1,15 @@ = '10') -{ - dbQuery("TRUNCATE TABLE `eventlog`"); - print_message("Event log truncated"); +if ($vars['action'] == 'expunge' && $_SESSION['userlevel'] >= '10') { + dbQuery('TRUNCATE TABLE `eventlog`'); + print_message('Event log truncated'); } -$pagetitle[] = "Eventlog"; +$pagetitle[] = 'Eventlog'; print_optionbar_start(); @@ -24,15 +23,17 @@ print_optionbar_start();
    @@ -40,9 +41,7 @@ print_optionbar_start(); diff --git a/html/pages/front/default.php b/html/pages/front/default.php index 7b17f08a45..b69f7f97b1 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -1,174 +1,180 @@ + +function generate_front_box($frontbox_class, $content) { + echo "
    $content -
    "); + "; + +}//end generate_front_box() + + +echo ' +
    +'; +if ($config['vertical_summary']) { + echo '
    '; +} +else { + echo '
    '; } -echo(' -
    -'); -if ($config['vertical_summary']) { - echo('
    '); -} -else -{ - echo('
    '); -} -echo(' +echo '
    -'); +'; -echo('
    '); +echo '
    '; -echo('
    '); +echo '
    '; $count_boxes = 0; // Device down boxes -if ($_SESSION['userlevel'] >= '10') -{ - $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT ".$config['front_page_down_box_limit']; -} else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0' LIMIT".$config['front_page_down_box_limit']; +if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT ".$config['front_page_down_box_limit']; } -foreach (dbFetchRows($sql) as $device) -{ - generate_front_box("device-down", generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 20).""); - ++$count_boxes; +else { + $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '0' AND D.ignore = '0' LIMIT".$config['front_page_down_box_limit']; } -if ($_SESSION['userlevel'] >= '10') -{ - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; -} else { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; +foreach (dbFetchRows($sql) as $device) { + generate_front_box( + 'device-down', + generate_device_link($device, shorthost($device['hostname'])).'
    + Device Down
    + '.truncate($device['location'], 20).'' + ); + ++$count_boxes; +} + +if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; +} +else { + $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; } // These things need to become more generic, and more manageable across different frontpages... rewrite inc :> - // Port down boxes -if ($config['warn']['ifdown']) -{ - foreach (dbFetchRows($sql) as $interface) - { - if (!$interface['deleted']) - { - $interface = ifNameDescr($interface); - generate_front_box("port-down", generate_device_link($interface, shorthost($interface['hostname']))."
    +if ($config['warn']['ifdown']) { + foreach (dbFetchRows($sql) as $interface) { + if (!$interface['deleted']) { + $interface = ifNameDescr($interface); + generate_front_box( + 'port-down', + generate_device_link($interface, shorthost($interface['hostname']))."
    Port Down
    - - ".generate_port_link($interface, truncate(makeshortif($interface['label']),13,''))."
    - " . ($interface['ifAlias'] ? ''.truncate($interface['ifAlias'], 20, '').'' : '')); - ++$count_boxes; + + ".generate_port_link($interface, truncate(makeshortif($interface['label']), 13, '')).'
    + '.($interface['ifAlias'] ? ''.truncate($interface['ifAlias'], 20, '').'' : '') + ); + ++$count_boxes; + } } - } } -/* FIXME service permissions? seem nonexisting now.. */ +/* + FIXME service permissions? seem nonexisting now.. */ // Service down boxes -if ($_SESSION['userlevel'] >= '10') -{ - $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - $param[] = ''; +if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + $param[] = ''; } -else -{ - $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - $param[] = $_SESSION['user_id']; +else { + $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + $param[] = $_SESSION['user_id']; } -foreach (dbFetchRows($sql,$param) as $service) -{ - generate_front_box("service-down", generate_device_link($service, shorthost($service['hostname']))."
    + +foreach (dbFetchRows($sql, $param) as $service) { + generate_front_box( + 'service-down', + generate_device_link($service, shorthost($service['hostname'])).'
    Service Down - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 20).""); - ++$count_boxes; + '.$service['service_type'].'
    + '.truncate($interface['ifAlias'], 20).'' + ); + ++$count_boxes; } // BGP neighbour down boxes -if (isset($config['enable_bgp']) && $config['enable_bgp']) -{ - if ($_SESSION['userlevel'] >= '10') - { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - } else { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - } - foreach (dbFetchRows($sql) as $peer) - { - generate_front_box("bgp-down", generate_device_link($peer, shorthost($peer['hostname']))."
    +if (isset($config['enable_bgp']) && $config['enable_bgp']) { + if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + } + else { + $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + } + + foreach (dbFetchRows($sql) as $peer) { + generate_front_box( + 'bgp-down', + generate_device_link($peer, shorthost($peer['hostname']))."
    BGP Down - ".$peer['bgpPeerIdentifier']."
    - AS".truncate($peer['bgpPeerRemoteAs']." ".$peer['astext'], 14, "").""); - ++$count_boxes; - } + ".$peer['bgpPeerIdentifier'].'
    + AS'.truncate($peer['bgpPeerRemoteAs'].' '.$peer['astext'], 14, '').'' + ); + ++$count_boxes; + } } // Device rebooted boxes -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - if ($_SESSION['userlevel'] >= '10') - { - $sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; - } else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" . - $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + if ($_SESSION['userlevel'] >= '10') { + $sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; + } + else { + $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; + } - foreach (dbFetchRows($sql) as $device) - { - generate_front_box("device-rebooted", generate_device_link($device, shorthost($device['hostname']))."
    + foreach (dbFetchRows($sql) as $device) { + generate_front_box( + 'device-rebooted', + generate_device_link($device, shorthost($device['hostname'])).'
    Device Rebooted
    - ".formatUptime($device['uptime'], 'short').""); - ++$count_boxes; - } + '.formatUptime($device['uptime'], 'short').'' + ); + ++$count_boxes; + } } + if ($count_boxes == 0) { - echo("
    Nothing here yet

    This is where status notifications about devices and services would normally go. You might have none - because you run such a great network, or perhaps you've just started using ".$config['project_name'].". If you're new to ".$config['project_name'].", you might - want to start by adding one or more devices in the Devices menu.

    "); -} -echo('
    '); -echo('
    '); -echo('
    '); -echo(' -
    -
    -'); - -if ($config['vertical_summary']) -{ - echo('
    '); - include_once("includes/device-summary-vert.inc.php"); -} -else -{ - echo('
    '); - include_once("includes/device-summary-horiz.inc.php"); + echo "
    Nothing here yet

    This is where status notifications about devices and services would normally go. You might have none + because you run such a great network, or perhaps you've just started using ".$config['project_name'].". If you're new to ".$config['project_name'].', you might + want to start by adding one or more devices in the Devices menu.

    '; } -echo(' +echo '
    '; +echo '
    '; +echo '
    '; +echo ' +
    +
    +'; + +if ($config['vertical_summary']) { + echo '
    '; + include_once 'includes/device-summary-vert.inc.php'; +} +else { + echo '
    '; + include_once 'includes/device-summary-horiz.inc.php'; +} + +echo '
    -'); +'; -if ($config['enable_syslog']) -{ +if ($config['enable_syslog']) { + $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; + $query = mysql_query($sql); - $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; - $query = mysql_query($sql); - - echo('
    + echo '
      @@ -180,35 +186,34 @@ if ($config['enable_syslog'])
    Syslog entries
    -
    '); +
    '; - foreach (dbFetchRows($sql) as $entry) - { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); + foreach (dbFetchRows($sql) as $entry) { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include("includes/print-syslog.inc.php"); - } - echo("
    "); - echo(""); - echo(""); - echo(""); - echo(""); + include 'includes/print-syslog.inc.php'; + } -} else { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +} +else { + if ($_SESSION['userlevel'] >= '10') { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15'; + } + else { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = ".$_SESSION['user_id'].' ORDER BY `datetime` DESC LIMIT 0,15'; + $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = '.$_SESSION['user_id'].' ORDER BY `time_logged` DESC LIMIT 0,15'; + } - if ($_SESSION['userlevel'] >= '10') - { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15"; - } else { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id'] . " ORDER BY `time_logged` DESC LIMIT 0,15"; - } + $data = mysql_query($query); + $alertdata = mysql_query($alertquery); - $data = mysql_query($query); - $alertdata = mysql_query($alertquery); - - echo('
    + echo '
      @@ -220,13 +225,13 @@ if ($config['enable_syslog'])
    Alertlog entries
    - '); +
    '; - foreach (dbFetchRows($alertquery) as $alert_entry) - { - include("includes/print-alerts.inc.php"); - } - echo('
    + foreach (dbFetchRows($alertquery) as $alert_entry) { + include 'includes/print-alerts.inc.php'; + } + + echo '
    @@ -234,24 +239,21 @@ if ($config['enable_syslog'])
    Eventlog entries
    - '); +
    '; - foreach (dbFetchRows($query) as $entry) - { - include("includes/print-event.inc.php"); - } + foreach (dbFetchRows($query) as $entry) { + include 'includes/print-event.inc.php'; + } - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo(""); -} + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +}//end if -echo(""); +echo ''; -echo(' +echo ' -'); - -?> +'; diff --git a/html/pages/front/demo.php b/html/pages/front/demo.php index 1000fbca24..6478a566b8 100644 --- a/html/pages/front/demo.php +++ b/html/pages/front/demo.php @@ -4,56 +4,55 @@ "); +echo ''; -$dev_list = array('6' => 'Central Fileserver', - '7' => 'NE61 Fileserver', - '34' => 'DE56 Fileserver'); +$dev_list = array( + '6' => 'Central Fileserver', + '7' => 'NE61 Fileserver', + '34' => 'DE56 Fileserver', +); -foreach ($dev_list as $device_id => $descr) -{ +foreach ($dev_list as $device_id => $descr) { + echo ''; +}//end foreach - echo(""); - -} - -echo("
    '; + echo "
    ".$descr.'
    '; + $graph_array['height'] = '100'; + $graph_array['width'] = '310'; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device_id; + $graph_array['type'] = 'device_bits'; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = 'no'; + $graph_array['popup_title'] = $descr; + // $graph_array['link'] = generate_device_link($device_id); + print_graph_popup($graph_array); - echo("
    "); - echo("
    ".$descr."
    "); - $graph_array['height'] = "100"; - $graph_array['width'] = "310"; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device_id; - $graph_array['type'] = "device_bits"; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; - $graph_array['popup_title'] = $descr; -# $graph_array['link'] = generate_device_link($device_id); - print_graph_popup($graph_array); + $graph_array['height'] = '50'; + $graph_array['width'] = '180'; - $graph_array['height'] = "50"; - $graph_array['width'] = "180"; + echo "
    "; + $graph_array['type'] = 'device_ucd_memory'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_ucd_memory"; - print_graph_popup($graph_array); - echo("
    "); + echo "
    "; + $graph_array['type'] = 'device_processor'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_processor"; - print_graph_popup($graph_array); - echo("
    "); + echo "
    "; + $graph_array['type'] = 'device_storage'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_storage"; - print_graph_popup($graph_array); - echo("
    "); + echo "
    "; + $graph_array['type'] = 'device_diskio'; + print_graph_popup($graph_array); + echo '
    '; - echo("
    "); - $graph_array['type'] = "device_diskio"; - print_graph_popup($graph_array); - echo("
    "); + echo '
    "); +echo ''; ?> @@ -62,115 +61,105 @@ echo(""); '0' AND A.attrib_value < '86400'"; -foreach (dbFetchRows($sql) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = "yes"; +foreach (dbFetchRows($sql) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) -{ - if (device_permitted($device['device_id'])) { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35)." -
    "); - } +foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id'])) { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35).' +
    '; + } } -if ($config['warn']['ifdown']) -{ - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; - foreach (dbFetchRows($sql) as $interface) - { - if (port_permitted($interface['port_id'])) - { - echo("
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 15)." -
    "); +if ($config['warn']['ifdown']) { + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; + foreach (dbFetchRows($sql) as $interface) { + if (port_permitted($interface['port_id'])) { + echo "
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } - } } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) -{ - if (device_permitted($service['device_id'])) - { - echo("
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } +foreach (dbFetchRows($sql) as $service) { + if (device_permitted($service['device_id'])) { + echo "
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) -{ - if (device_permitted($peer['device_id'])) - { - echo("
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - } -} - -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE - A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) - { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") - { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); +foreach (dbFetchRows($sql) as $peer) { + if (device_permitted($peer['device_id'])) { + echo "
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; } - } } -echo(" -
    $errorboxes
    +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE + A.attrib_value < '".$config['uptime_warning']."' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; + foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } + } +} -

    Recent Syslog Messages

    -"); +echo " +
    $errorboxes
    + +

    Recent Syslog Messages

    + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from `syslog` ORDER BY seq DESC LIMIT 20"; -echo(""); -foreach (dbFetchRows($sql) as $entry) -{ - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include("includes/print-syslog.inc.php"); + include 'includes/print-syslog.inc.php'; } -echo("
    "); +echo ''; ?> diff --git a/html/pages/front/example2.php b/html/pages/front/example2.php index 717ee75184..e5898ac073 100644 --- a/html/pages/front/example2.php +++ b/html/pages/front/example2.php @@ -4,173 +4,141 @@
    Devices with Alerts
    Host
    Int
    Srv
    +// ?> '0' AND A.attrib_value < '86400'"; -foreach (dbFetchRows($sql) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) - { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) - { - $already = "yes"; +foreach (dbFetchRows($sql) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) -{ - echo("
    -
    ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down - ".truncate($device['location'], 20)." -
    "); - +foreach (dbFetchRows($sql) as $device) { + echo "
    +
    ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down + ".truncate($device['location'], 20).' +
    '; } $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; -foreach (dbFetchRows($sql) as $interface) -{ - echo("
    -
    ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 20)." -
    "); - +foreach (dbFetchRows($sql) as $interface) { + echo "
    +
    ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 20).' +
    '; } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) -{ - echo("
    -
    ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 20)." -
    "); - +foreach (dbFetchRows($sql) as $service) { + echo "
    +
    ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 20).' +
    '; } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) -{ - echo("
    -
    ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - +foreach (dbFetchRows($sql) as $peer) { + echo "
    +
    ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '" . $config['uptime_warning'] . "'"; - foreach (dbFetchRows($sql) as $device) - { - echo("
    -
    ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '".$config['uptime_warning']."'"; + foreach (dbFetchRows($sql) as $device) { + echo "
    +
    ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } } -echo(" +echo " -
    $errorboxes
    +
    $errorboxes
    -

    Recent Syslog Messages

    +

    Recent Syslog Messages

    -"); + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; -echo("
    Devices with Alerts
    Host
    Int
    Srv
    "); -foreach (dbFetchRows($sql) as $entry) -{ - include("includes/print-syslog.inc.php"); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + include 'includes/print-syslog.inc.php'; } -echo("
    "); -echo("
    +echo ''; - - "); +echo '
    + + + '; // this stuff can be customised to show whatever you want.... +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['l2tp'] .= $seperator.$interface['port_id']; + $seperator = ','; + } -if ($_SESSION['userlevel'] >= '5') -{ - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['l2tp'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['transit'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['transit'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['voip'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['voip'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + if ($ports['transit']) { + echo "', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    Internet Transit
    "."
    "; + } - if ($ports['transit']) - { - echo("', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". - "
    Internet Transit
    ". - "
    "); - } + if ($ports['l2tp']) { + echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    L2TP ADSL
    "."
    "; + } - if ($ports['l2tp']) - { - echo("', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". - "
    L2TP ADSL
    ". - "
    "); - } - - if ($ports['voip']) - { - echo("', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". - "
    VoIP to PSTN
    ". - "
    "); - } - -} + if ($ports['voip']) { + echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    VoIP to PSTN
    "."
    "; + } +}//end if // END VOSTRON - ?> diff --git a/html/pages/front/globe.php b/html/pages/front/globe.php index 75a5917c70..9884b402fa 100644 --- a/html/pages/front/globe.php +++ b/html/pages/front/globe.php @@ -4,16 +4,17 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ + * along with this program. If not, see . + */ -/** +/* * Custom Frontpage * @author f0o * @copyright 2014 f0o, LibreNMS @@ -25,107 +26,111 @@ ?> -
    -
    -
    -
    -
    -
    -
    -
    '; - include_once("includes/device-summary-vert.inc.php"); -echo '
    -
    -
    -
    '; - include_once("includes/front/boxes.inc.php"); -echo '
    -
    -
    -
    -
    -
    -
    '; - $device['device_id'] = '-1'; - require_once('includes/print-alerts.php'); - unset($device['device_id']); -echo '
    -
    +
    +
    +
    +
    +
    +
    +
    +
    '; + include_once("includes/device-summary-vert.inc.php"); +echo '
    +
    +
    +
    '; + include_once("includes/front/boxes.inc.php"); +echo '
    +
    +
    +
    +
    +
    +
    '; + $device['device_id'] = '-1'; + require_once('includes/print-alerts.php'); + unset($device['device_id']); +echo '
    +
    '; //From default.php - This code is not part of above license. if ($config['enable_syslog']) { -$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; -$query = mysql_query($sql); -echo('
    + $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; + $query = mysql_query($sql); + echo('
      @@ -139,29 +144,28 @@ echo('
    '); - foreach (dbFetchRows($sql) as $entry) - { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); + foreach (dbFetchRows($sql) as $entry) { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include("includes/print-syslog.inc.php"); - } - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); + include 'includes/print-syslog.inc.php'; + } + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); +} +else { -} else { + if ($_SESSION['userlevel'] == '10') { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + } + else { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = + P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; + } - if ($_SESSION['userlevel'] == '10') - { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - } else { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = - P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; - } - - $data = mysql_query($query); + $data = mysql_query($query); echo('
    @@ -177,15 +181,13 @@ echo('
    '); - foreach (dbFetchRows($query) as $entry) - { - include("includes/print-event.inc.php"); - } + foreach (dbFetchRows($query) as $entry) { + include 'includes/print-event.inc.php'; + } - echo("
    "); - echo("
    "); - echo("
    "); - echo(""); - echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); } -?> diff --git a/html/pages/front/jt.php b/html/pages/front/jt.php index 2256cf0856..cda0b49bb7 100644 --- a/html/pages/front/jt.php +++ b/html/pages/front/jt.php @@ -5,238 +5,209 @@ $nodes = array(); -$uptimesql = ""; -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $uptimesql = " AND A.attrib_value < '" . $config['uptime_warning'] . "'"; +$uptimesql = ''; +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $uptimesql = " AND A.attrib_value < '".$config['uptime_warning']."'"; } -$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql; +$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql; -foreach (dbFetchRows($sql) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = "yes"; +foreach (dbFetchRows($sql) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) -{ - if (device_permitted($device['device_id'])) { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35)." -
    "); - } +foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id'])) { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35).' +
    '; + } } if ($config['warn']['ifdown']) { - -$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; -foreach (dbFetchRows($sql) as $interface) -{ - if (port_permitted($interface['port_id'])) { - echo("
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } -} - + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; + foreach (dbFetchRows($sql) as $interface) { + if (port_permitted($interface['port_id'])) { + echo "
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } + } } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) -{ - if (device_permitted($service['device_id'])) { - echo("
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } +foreach (dbFetchRows($sql) as $service) { + if (device_permitted($service['device_id'])) { + echo "
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) -{ - if (device_permitted($peer['device_id'])) { - echo("
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - } +foreach (dbFetchRows($sql) as $peer) { + if (device_permitted($peer['device_id'])) { + echo "
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; + } } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); - } - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '".$config['uptime_warning']."' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; + foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } + } } -echo(" +echo " -
    $errorboxes
    +
    $errorboxes
    -

    Recent Syslog Messages

    +

    Recent Syslog Messages

    -"); + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo(""); -foreach (dbFetchRows($sql) as $entry) -{ - include("includes/print-syslog.inc.php"); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + include 'includes/print-syslog.inc.php'; } -echo("
    "); -echo("
    +echo ''; - - "); +echo '
    + + + '; // this stuff can be customised to show whatever you want.... +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['transit'] .= $seperator.$interface['port_id']; + $seperator = ','; + } -if ($_SESSION['userlevel'] >= '5') -{ + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['peering'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['transit'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $ports['broadband'] = '3294,3295,688,3534'; + $ports['wave_broadband'] = '827'; - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['peering'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $ports['new_broadband'] = '3659,4149,4121,4108,3676,4135'; - $ports['broadband'] = "3294,3295,688,3534"; - $ports['wave_broadband'] = "827"; + echo "
    "; - $ports['new_broadband'] = "3659,4149,4121,4108,3676,4135"; + if ($ports['peering'] && $ports['transit']) { + echo ""; + } - echo("
    "); + echo '
    '; - if ($ports['peering'] && $ports['transit']) { - echo(""); - } + echo "
    "; - echo("
    "); + if ($ports['transit']) { + echo ""; + } - echo("'; - if ($ports['peering']) { - echo(""); - } + echo "
    "; - echo("
    "); + if ($ports['broadband'] && $ports['wave_broadband'] && $ports['new_broadband']) { + echo ""; + } - echo("
    "); + echo "
    "; - if ($ports['broadband'] && $ports['wave_broadband'] && $ports['new_broadband']) { - echo(""); - } + if ($ports['broadband']) { + echo ""; + } - echo("
    "); + echo "
    "; - if ($ports['broadband']) { - echo(""); - } + if ($ports['new_broadband']) { + echo ""; + } - echo("
    "); + echo '
    '; - if ($ports['new_broadband']) { - echo(""); - } + if ($ports['wave_broadband']) { + echo ""; + } - echo("
    "); - - if ($ports['wave_broadband']) { - echo(""); - } - - echo("
    "); - -} + echo '
    '; +}//end if ?> diff --git a/html/pages/front/traffic.php b/html/pages/front/traffic.php index 5f9a8acced..6b501cf9c1 100644 --- a/html/pages/front/traffic.php +++ b/html/pages/front/traffic.php @@ -3,200 +3,172 @@ 0) -{ - $uptimesql = " AND A.attrib_value < ?"; - $param = array($config['uptime_warning']); +$nodes = array(); +$param = array(); +$uptimesql = ''; +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + $uptimesql = ' AND A.attrib_value < ?'; + $param = array($config['uptime_warning']); } -foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql, $param) as $device) -{ - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = "yes"; +foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql, $param) as $device) { + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = 'yes'; + } + + $i++; + } + + if (!$already) { + $nodes[] = $device['device_id']; } - $i++; - } - if (!$already) { $nodes[] = $device['device_id']; } } -foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) -{ - if (device_permitted($device['device_id'])) { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35)." -
    "); - } +foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) { + if (device_permitted($device['device_id'])) { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35).' +
    '; + } } if ($config['warn']['ifdown']) { - -foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) -{ - if (port_permitted($interface['port_id'])) { - echo("
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } + foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) { + if (port_permitted($interface['port_id'])) { + echo "
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } + } } +foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) { + if (device_permitted($service['device_id'])) { + echo "
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type'].'
    + '.truncate($interface['ifAlias'], 15).' +
    '; + } } -foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) -{ - if (device_permitted($service['device_id'])) { - echo("
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type']."
    - ".truncate($interface['ifAlias'], 15)." -
    "); - } +foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) { + if (device_permitted($peer['device_id'])) { + echo "
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier'].'
    + AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' +
    '; + } } -foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) -{ - if (device_permitted($peer['device_id'])) { - echo("
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier']."
    - AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." -
    "); - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { + foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", array($config['uptime_warning'])) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { + echo "
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value']).' +
    '; + } + } } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) -{ - foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", array($config['uptime_warning'])) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") { - echo("
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value'])." -
    "); - } - } -} +echo " -echo(" +
    $errorboxes
    -
    $errorboxes
    +

    Recent Syslog Messages

    -

    Recent Syslog Messages

    - -"); + "; $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo(""); -foreach (dbFetchRows($sql) as $entry) -{ - include("includes/print-syslog.inc.php"); +echo '
    '; +foreach (dbFetchRows($sql) as $entry) { + include 'includes/print-syslog.inc.php'; } -echo("
    "); -echo("
    +echo ''; - - "); +echo '
    + + + '; // this stuff can be customised to show whatever you want.... +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['transit'] .= $seperator.$interface['port_id']; + $seperator = ','; + } -if ($_SESSION['userlevel'] >= '5') -{ + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['peering'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['transit'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset($seperator); + foreach (dbFetchRows($sql) as $interface) { + $ports['core'] .= $seperator.$interface['port_id']; + $seperator = ','; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['peering'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + echo "
    "; - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset ($seperator); - foreach (dbFetchRows($sql) as $interface) - { - $ports['core'] .= $seperator . $interface['port_id']; - $seperator = ","; - } + if ($ports['peering'] && $ports['transit']) { + echo ""; + } - echo("
    "); + echo '
    '; - if ($ports['peering'] && $ports['transit']) - { - echo(""); - } + echo "
    "; - echo("
    "); + if ($ports['transit']) { + echo ""; + } - echo("
    "); + if ($ports['peering']) { + echo ""; + } - if ($ports['transit']) - { - echo(""); - } + if ($ports['core']) { + echo ""; + } - if ($ports['peering']) - { - echo(""); - } - - if ($ports['core']) - { - echo(""); - } - - echo("
    "); - -} + echo '
    '; +}//end if ?> diff --git a/html/pages/graphs.inc.php b/html/pages/graphs.inc.php index 0cc268fceb..78c6a73e09 100644 --- a/html/pages/graphs.inc.php +++ b/html/pages/graphs.inc.php @@ -4,17 +4,21 @@ unset($vars['page']); // Setup here -if($_SESSION['widescreen']) -{ - $graph_width=1700; - $thumb_width=180; -} else { - $graph_width=1075; - $thumb_width=113; +if($_SESSION['widescreen']) { + $graph_width=1700; + $thumb_width=180; +} +else { + $graph_width=1075; + $thumb_width=113; } -if (!is_numeric($vars['from'])) { $vars['from'] = $config['time']['day']; } -if (!is_numeric($vars['to'])) { $vars['to'] = $config['time']['now']; } +if (!is_numeric($vars['from'])) { + $vars['from'] = $config['time']['day']; +} +if (!is_numeric($vars['to'])) { + $vars['to'] = $config['time']['now']; +} preg_match('/^(?P[A-Za-z0-9]+)_(?P.+)/', $vars['type'], $graphtype); @@ -22,208 +26,201 @@ $type = $graphtype['type']; $subtype = $graphtype['subtype']; $id = $vars['id']; -if(is_numeric($vars['device'])) -{ - $device = device_by_id_cache($vars['device']); -} elseif(!empty($vars['device'])) { - $device = device_by_name($vars['device']); +if(is_numeric($vars['device'])) { + $device = device_by_id_cache($vars['device']); +} +elseif(!empty($vars['device'])) { + $device = device_by_name($vars['device']); } -if (is_file("includes/graphs/".$type."/auth.inc.php")) -{ - include("includes/graphs/".$type."/auth.inc.php"); +if (is_file("includes/graphs/".$type."/auth.inc.php")) { + require "includes/graphs/".$type."/auth.inc.php"; } -if (!$auth) -{ - include("includes/error-no-perm.inc.php"); -} else { - if (isset($config['graph_types'][$type][$subtype]['descr'])) - { - $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; - } else { - $title .= " :: ".ucfirst($subtype); - } +if (!$auth) { + require 'includes/error-no-perm.inc.php'; +} +else { + if (isset($config['graph_types'][$type][$subtype]['descr'])) { + $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; + } + else { + $title .= " :: ".ucfirst($subtype); + } - $graph_array = $vars; - $graph_array['height'] = "60"; - $graph_array['width'] = $thumb_width; - $graph_array['legend'] = "no"; - $graph_array['to'] = $config['time']['now']; + $graph_array = $vars; + $graph_array['height'] = "60"; + $graph_array['width'] = $thumb_width; + $graph_array['legend'] = "no"; + $graph_array['to'] = $config['time']['now']; - print_optionbar_start(); - echo($title); + print_optionbar_start(); + echo($title); - echo('
    '); - ?> + echo('
    '); +?>
    - '); +'); - print_optionbar_end(); + print_optionbar_end(); - print_optionbar_start(); + print_optionbar_start(); - $thumb_array = array('sixhour' => '6 Hours', 'day' => '24 Hours', 'twoday' => '48 Hours', 'week' => 'One Week', 'twoweek' => 'Two Weeks', - 'month' => 'One Month', 'twomonth' => 'Two Months','year' => 'One Year', 'twoyear' => 'Two Years'); + $thumb_array = array('sixhour' => '6 Hours', 'day' => '24 Hours', 'twoday' => '48 Hours', 'week' => 'One Week', 'twoweek' => 'Two Weeks', + 'month' => 'One Month', 'twomonth' => 'Two Months','year' => 'One Year', 'twoyear' => 'Two Years'); - echo(''); + echo('
    '); - foreach ($thumb_array as $period => $text) - { - $graph_array['from'] = $config['time'][$period]; + foreach ($thumb_array as $period => $text) { + $graph_array['from'] = $config['time'][$period]; - $link_array = $vars; - $link_array['from'] = $graph_array['from']; - $link_array['to'] = $graph_array['to']; - $link_array['page'] = "graphs"; - $link = generate_url($link_array); + $link_array = $vars; + $link_array['from'] = $graph_array['from']; + $link_array['to'] = $graph_array['to']; + $link_array['page'] = "graphs"; + $link = generate_url($link_array); - echo(''); + echo(''); - } + } - echo('
    '); - echo(''.$text.'
    '); - echo(''); - echo(generate_graph_tag($graph_array)); - echo(''); - echo('
    '); + echo(''.$text.'
    '); + echo(''); + echo(generate_graph_tag($graph_array)); + echo(''); + echo('
    '); + echo(''); - $graph_array = $vars; - $graph_array['height'] = "300"; - $graph_array['width'] = $graph_width; + $graph_array = $vars; + $graph_array['height'] = "300"; + $graph_array['width'] = $graph_width; - echo("
    "); + echo("
    "); - // datetime range picker + // datetime range picker ?> - "); - echo(' + echo(" +
    + "); + echo('
    - - + +
    - - + +
    -
    - '); - echo("
    "); + echo("
    "); - if ($vars['legend'] == "no") - { - echo(generate_link("Show Legend",$vars, array('page' => "graphs", 'legend' => NULL))); - } else { - echo(generate_link("Hide Legend",$vars, array('page' => "graphs", 'legend' => "no"))); - } - - // FIXME : do this properly -# if ($type == "port" && $subtype == "bits") -# { - echo(' | '); - if ($vars['previous'] == "yes") - { - echo(generate_link("Hide Previous",$vars, array('page' => "graphs", 'previous' => NULL))); - } else { - echo(generate_link("Show Previous",$vars, array('page' => "graphs", 'previous' => "yes"))); + if ($vars['legend'] == "no") { + echo(generate_link("Show Legend",$vars, array('page' => "graphs", 'legend' => NULL))); + } + else { + echo(generate_link("Hide Legend",$vars, array('page' => "graphs", 'legend' => "no"))); } -# } - echo('
    '); + // FIXME : do this properly + # if ($type == "port" && $subtype == "bits") + # { + echo(' | '); + if ($vars['previous'] == "yes") { + echo(generate_link("Hide Previous",$vars, array('page' => "graphs", 'previous' => NULL))); + } + else { + echo(generate_link("Show Previous",$vars, array('page' => "graphs", 'previous' => "yes"))); + } + # } - if ($vars['showcommand'] == "yes") - { - echo(generate_link("Hide RRD Command",$vars, array('page' => "graphs", 'showcommand' => NULL))); - } else { - echo(generate_link("Show RRD Command",$vars, array('page' => "graphs", 'showcommand' => "yes"))); - } + echo('
    '); - echo('
    '); + if ($vars['showcommand'] == "yes") { + echo(generate_link("Hide RRD Command",$vars, array('page' => "graphs", 'showcommand' => NULL))); + } + else { + echo(generate_link("Show RRD Command",$vars, array('page' => "graphs", 'showcommand' => "yes"))); + } - print_optionbar_end(); + echo('
    '); - echo generate_graph_js_state($graph_array); - - echo('
    '); - echo(generate_graph_tag($graph_array)); - echo("
    "); - - if (isset($config['graph_descr'][$vars['type']])) - { - - print_optionbar_start(); - echo('
    -
    - -
    -
    '); - echo($config['graph_descr'][$vars['type']]); print_optionbar_end(); - } - if ($vars['showcommand']) - { - $_GET = $graph_array; - $command_only = 1; + echo generate_graph_js_state($graph_array); - include("includes/graphs/graph.inc.php"); - } + echo('
    '); + echo(generate_graph_tag($graph_array)); + echo("
    "); + + if (isset($config['graph_descr'][$vars['type']])) { + + print_optionbar_start(); + echo('
    +
    + +
    +
    '); + echo($config['graph_descr'][$vars['type']]); + print_optionbar_end(); + } + + if ($vars['showcommand']) { + $_GET = $graph_array; + $command_only = 1; + + require 'includes/graphs/graph.inc.php'; + } } - -?> diff --git a/html/pages/health.inc.php b/html/pages/health.inc.php index 3b06d4db6b..eb13def9b7 100644 --- a/html/pages/health.inc.php +++ b/html/pages/health.inc.php @@ -30,8 +30,12 @@ $type_text['toner'] = "Toner"; $type_text['dbm'] = "dBm"; $type_text['load'] = "Load"; -if (!$vars['metric']) { $vars['metric'] = "processor"; } -if (!$vars['view']) { $vars['view'] = "detail"; } +if (!$vars['metric']) { + $vars['metric'] = "processor"; +} +if (!$vars['view']) { + $vars['view'] = "detail"; +} $link_array = array('page' => 'health'); @@ -42,48 +46,44 @@ print_optionbar_start('', ''); echo('Health » '); $sep = ""; -foreach ($datas as $texttype) -{ - $metric = strtolower($texttype); - echo($sep); - if ($vars['metric'] == $metric) - { - echo(""); - } +foreach ($datas as $texttype) { + $metric = strtolower($texttype); + echo($sep); + if ($vars['metric'] == $metric) { + echo(""); + } - echo(generate_link($type_text[$metric],$link_array,array('metric'=> $metric, 'view' => $vars['view']))); + echo(generate_link($type_text[$metric],$link_array,array('metric'=> $metric, 'view' => $vars['view']))); - if ($vars['metric'] == $metric) { echo(""); } + if ($vars['metric'] == $metric) { + echo(""); + } - $sep = ' | '; + $sep = ' | '; } unset ($sep); echo('
    '); -if ($vars['view'] == "graphs") -{ - echo(''); +if ($vars['view'] == "graphs") { + echo(''); } echo(generate_link("Graphs",$link_array,array('metric'=> $vars['metric'], 'view' => "graphs"))); -if ($vars['view'] == "graphs") -{ - echo(''); +if ($vars['view'] == "graphs") { + echo(''); } echo(' | '); -if ($vars['view'] != "graphs") -{ - echo(''); +if ($vars['view'] != "graphs") { + echo(''); } echo(generate_link("No Graphs",$link_array,array('metric'=> $vars['metric'], 'view' => "detail"))); -if ($vars['view'] != "graphs") -{ - echo(''); +if ($vars['view'] != "graphs") { + echo(''); } echo('
    '); @@ -91,16 +91,14 @@ echo('
    '); print_optionbar_end(); if (in_array($vars['metric'],array_keys($used_sensors)) - || $vars['metric'] == 'processor' - || $vars['metric'] == 'storage' - || $vars['metric'] == 'toner' - || $vars['metric'] == 'mempool') -{ - include('pages/health/'.$vars['metric'].'.inc.php'); + || $vars['metric'] == 'processor' + || $vars['metric'] == 'storage' + || $vars['metric'] == 'toner' + || $vars['metric'] == 'mempool') { + include('pages/health/'.$vars['metric'].'.inc.php'); } -else -{ - echo("No sensors of type " . $vars['metric'] . " found."); +else { + echo("No sensors of type " . $vars['metric'] . " found."); } ?> diff --git a/html/pages/health/charge.inc.php b/html/pages/health/charge.inc.php index 867b50f9e8..3838d0e790 100644 --- a/html/pages/health/charge.inc.php +++ b/html/pages/health/charge.inc.php @@ -4,6 +4,4 @@ $graph_type = "sensor_charge"; $unit = "%"; $class = "charge"; -include("pages/health/sensors.inc.php"); - -?> +require 'pages/health/sensors.inc.php'; diff --git a/html/pages/health/load.inc.php b/html/pages/health/load.inc.php index d9257519d3..f506e3ca1d 100644 --- a/html/pages/health/load.inc.php +++ b/html/pages/health/load.inc.php @@ -1,9 +1,7 @@ +require 'pages/health/sensors.inc.php'; diff --git a/html/pages/health/sensors.inc.php b/html/pages/health/sensors.inc.php index 02224d485c..52828b9c19 100644 --- a/html/pages/health/sensors.inc.php +++ b/html/pages/health/sensors.inc.php @@ -1,19 +1,18 @@ = '5') -{ - $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr"; - $param = array(); -} else { - $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = ? ORDER BY D.hostname, S.sensor_descr"; - $param = array($_SESSION['user_id']); +if ($_SESSION['userlevel'] >= '5') { + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr"; + $param = array(); +} +else { + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = ? ORDER BY D.hostname, S.sensor_descr"; + $param = array($_SESSION['user_id']); } -echo(''); +echo '
    '; -echo(' +echo ' @@ -21,99 +20,102 @@ echo(' - '); + '; -foreach (dbFetchRows($sql, $param) as $sensor) -{ +foreach (dbFetchRows($sql, $param) as $sensor) { + if ($config['memcached']['enable'] === true) { + $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); + if ($debug) { + echo 'Memcached['.'sensor-'.$sensor['sensor_id'].'-value'.'='.$sensor['sensor_current'].']'; + } + } - if ($config['memcached']['enable'] === TRUE) - { - $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); - if($debug) { echo("Memcached[".'sensor-'.$sensor['sensor_id'].'-value'."=".$sensor['sensor_current']."]"); } - } - - if (empty($sensor['sensor_current'])) - { - $sensor['sensor_current'] = "NaN"; - } else { - if ($sensor['sensor_current'] >= $sensor['sensor_limit']) { $alert = 'alert'; } else { $alert = ""; } - } + if (empty($sensor['sensor_current'])) { + $sensor['sensor_current'] = 'NaN'; + } + else { + if ($sensor['sensor_current'] >= $sensor['sensor_limit']) { + $alert = 'alert'; + } + else { + $alert = ''; + } + } // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? // FIXME - DUPLICATED IN device/overview/sensors - - $graph_colour = str_replace("#", "", $row_colour); + $graph_colour = str_replace('#', '', $row_colour); $graph_array = array(); - $graph_array['height'] = "100"; - $graph_array['width'] = "210"; + $graph_array['height'] = '100'; + $graph_array['width'] = '210'; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = $graph_type; $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = "no"; + $graph_array['legend'] = 'no'; - $link_array = $graph_array; - $link_array['page'] = "graphs"; + $link_array = $graph_array; + $link_array['page'] = 'graphs'; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link_graph = generate_url($link_array); - $link = generate_url(array("page" => "device", "device" => $sensor['device_id'], "tab" => "health", "metric" => $sensor['sensor_class'])); + $link = generate_url(array('page' => 'device', 'device' => $sensor['device_id'], 'tab' => 'health', 'metric' => $sensor['sensor_class'])); - $overlib_content = '

    '.$device['hostname']." - ".$sensor['sensor_descr']."

    "; - foreach (array('day','week','month','year') as $period) - { - $graph_array['from'] = $config['time'][$period]; - $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); + $overlib_content = '

    '.$device['hostname'].' - '.$sensor['sensor_descr'].'

    '; + foreach (array('day', 'week', 'month', 'year') as $period) { + $graph_array['from'] = $config['time'][$period]; + $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); } - $overlib_content .= "
    "; - $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $overlib_content .= '
    '; + + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. $graph_array['from'] = $config['time']['day']; - $sensor_minigraph = generate_graph_tag($graph_array); + $sensor_minigraph = generate_graph_tag($graph_array); $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); - echo(' - - + echo ' + + - - - + + + - '); + '; - if ($vars['view'] == "graphs") - { - echo(""); - } # endif graphs -} + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo "', LEFT);\" onmouseout=\"return nd();\"> + "; + echo ''; + } //end if +}//end foreach -echo("
    Device Sensor
    Current Range limit Notes
    ' . generate_device_link($sensor) . ''.overlib_link($link, $sensor['sensor_descr'],$overlib_content).'
    '.generate_device_link($sensor).''.overlib_link($link, $sensor['sensor_descr'], $overlib_content).' '.overlib_link($link_graph, $sensor_minigraph, $overlib_content).' '.$alert.'' . $sensor['sensor_current'] . $unit . '' . round($sensor['sensor_limit_low'],2) . $unit . ' - ' . round($sensor['sensor_limit'],2) . $unit . '' . (isset($sensor['sensor_notes']) ? $sensor['sensor_notes'] : '') . ''.$sensor['sensor_current'].$unit.''.round($sensor['sensor_limit_low'], 2).$unit.' - '.round($sensor['sensor_limit'], 2).$unit.''.(isset($sensor['sensor_notes']) ? $sensor['sensor_notes'] : '').'
    "); + if ($vars['view'] == 'graphs') { + echo "
    "; - $daily_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=211&height=100"; - $daily_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=400&height=150"; + $daily_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=211&height=100'; + $daily_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=400&height=150'; - $weekly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['week']."&to=".$config['time']['now']."&width=211&height=100"; - $weekly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['week']."&to=".$config['time']['now']."&width=400&height=150"; + $weekly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=211&height=100'; + $weekly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=400&height=150'; - $monthly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['month']."&to=".$config['time']['now']."&width=211&height=100"; - $monthly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['month']."&to=".$config['time']['now']."&width=400&height=150"; + $monthly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=211&height=100'; + $monthly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=400&height=150'; - $yearly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['year']."&to=".$config['time']['now']."&width=211&height=100"; - $yearly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['year']."&to=".$config['time']['now']."&width=400&height=150"; + $yearly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=211&height=100'; + $yearly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=400&height=150'; - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("', LEFT);\" onmouseout=\"return nd();\"> - "); - echo("
    "); - -?> +echo ''; diff --git a/html/pages/iftype.inc.php b/html/pages/iftype.inc.php index f4349111cd..8a6d20201b 100644 --- a/html/pages/iftype.inc.php +++ b/html/pages/iftype.inc.php @@ -9,92 +9,102 @@ - Total Graph for ports of type : ".$types."
    "); - -if ($if_list) -{ - $graph_type = "multiport_bits_separate"; - $port['port_id'] = $if_list; - - include("includes/print-interface-graphs.inc.php"); - - echo(""); - - foreach ($ports as $port) - { - $done = "yes"; - unset($class); - $port['ifAlias'] = str_ireplace($type . ": ", "", $port['ifAlias']); - $port['ifAlias'] = str_ireplace("[PNI]", "Private", $port['ifAlias']); - $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); - if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg = "#ffffff"; } - echo(" - " . generate_port_link($port,$port['port_descr_descr']) . "
    - ".generate_device_link($port)." ".generate_port_link($port)." - ".generate_port_link($port, makeshortif($port['ifDescr']))." - ".$port['port_descr_speed']." - ".$port['port_descr_circuit']." - ".$port['port_descr_notes']." - - - MAC Accounting"); - } - - echo('
    '); - - if (file_exists($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . $port['ifIndex'] . ".rrd")) - { - $graph_type = "port_bits"; - - include("includes/print-interface-graphs.inc.php"); - } - - echo(""); - } - +$types_array = explode(',', $vars['type']); +for ($i = 0; $i < count($types_array); +$i++) { + $types_array[$i] = ucfirst($types_array[$i]); } -else -{ - echo("None found."); + +$types = implode(' + ', $types_array); + +echo " + Total Graph for ports of type : ".$types.'
    '; + +if ($if_list) { + $graph_type = 'multiport_bits_separate'; + $port['port_id'] = $if_list; + + include 'includes/print-interface-graphs.inc.php'; + + echo ''; + + foreach ($ports as $port) { + $done = 'yes'; + unset($class); + $port['ifAlias'] = str_ireplace($type.': ', '', $port['ifAlias']); + $port['ifAlias'] = str_ireplace('[PNI]', 'Private', $port['ifAlias']); + $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); + if ($bg == '#ffffff') { + $bg = '#e5e5e5'; + } + else { + $bg = '#ffffff'; + } + + echo " + ".generate_port_link($port, $port['port_descr_descr'])."
    + ".generate_device_link($port).' '.generate_port_link($port).' + '.generate_port_link($port, makeshortif($port['ifDescr'])).' + '.$port['port_descr_speed'].' + '.$port['port_descr_circuit'].' + '.$port['port_descr_notes']." + + + MAC Accounting"; + } + + echo '
    '; + + if (file_exists($config['rrd_dir'].'/'.$port['hostname'].'/port-'.$port['ifIndex'].'.rrd')) { + $graph_type = 'port_bits'; + + include 'includes/print-interface-graphs.inc.php'; + } + + echo ''; + } +} +else { + echo 'None found.'; } ?> diff --git a/html/pages/inventory.inc.php b/html/pages/inventory.inc.php index e53daab965..7fc461e4aa 100644 --- a/html/pages/inventory.inc.php +++ b/html/pages/inventory.inc.php @@ -1,6 +1,6 @@ @@ -29,46 +29,53 @@ var grid = $("#inventory").bootgrid({ header: "
    "+ "
    "+ "
    "+ - "\" placeholder=\"Description\" class=\"form-control input-sm\" />"+ + "\" placeholder=\"Description\" class=\"form-control input-sm\" />"+ "
    "+ "
    "+ " Part No "+ ""+ "
    "+ "
    "+ - "\" placeholder=\"Serial\" class=\"form-control input-sm\"/>"+ + "\" placeholder=\"Serial\" class=\"form-control input-sm\"/>"+ "
    "+ "
    "+ " Device "+ ""+ "
    "+ "
    "+ - "\" placeholder=\"Description\" class=\"form-control input-sm\"/>"+ + " +\" placeholder=\"Description\" class=\"form-control input-sm\"/>"+ "
    "+ ""+ "
    "+ diff --git a/html/pages/locations.inc.php b/html/pages/locations.inc.php index 93dffa0e36..bbe6adcf99 100644 --- a/html/pages/locations.inc.php +++ b/html/pages/locations.inc.php @@ -1,88 +1,92 @@ Locations » '); +echo 'Locations » '; -$menu_options = array('basic' => 'Basic', - 'traffic' => 'Traffic'); +$menu_options = array( + 'basic' => 'Basic', + 'traffic' => 'Traffic', +); -if (!$vars['view']) { $vars['view'] = "basic"; } +if (!$vars['view']) { + $vars['view'] = 'basic'; +} -$sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['view'] == $option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['view'] == $option) - { - echo(""); - } - $sep = " | "; +$sep = ''; +foreach ($menu_options as $option => $text) { + echo $sep; + if ($vars['view'] == $option) { + echo ""; + } + + echo ''.$text.''; + if ($vars['view'] == $option) { + echo ''; + } + + $sep = ' | '; } unset($sep); print_optionbar_end(); -echo(''); +echo '
    '; -foreach (getlocations() as $location) -{ - if ($_SESSION['userlevel'] >= '10') - { - $num = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ?", array($location)); - $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'network'", array($location)); - $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'server'", array($location)); - $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'firewall'", array($location)); - $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND status = '0'", array($location)); - } else { - $num = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ?", array($_SESSION['user_id'], $location)); - $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND D.type = 'network'", array($_SESSION['user_id'], $location)); - $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'server'", array($_SESSION['user_id'], $location)); - $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'firewall'", array($_SESSION['user_id'], $location)); - $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND status = '0'", array($_SESSION['user_id'], $location)); - } - - if ($hostalerts) { $alert = 'alert'; } else { $alert = ""; } - - if ($location != "") - { - echo(' - - - - - - - - '); - - if ($vars['view'] == "traffic") - { - echo('"); +foreach (getlocations() as $location) { + if ($_SESSION['userlevel'] >= '10') { + $num = dbFetchCell('SELECT COUNT(device_id) FROM devices WHERE location = ?', array($location)); + $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'network'", array($location)); + $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'server'", array($location)); + $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'firewall'", array($location)); + $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND status = '0'", array($location)); + } + else { + $num = dbFetchCell('SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ?', array($_SESSION['user_id'], $location)); + $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND D.type = 'network'", array($_SESSION['user_id'], $location)); + $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'server'", array($_SESSION['user_id'], $location)); + $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'firewall'", array($_SESSION['user_id'], $location)); + $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND status = '0'", array($_SESSION['user_id'], $location)); } - $done = "yes"; - } -} -echo("
    ' . $location . '' . $alert . '' . $num . ' devices' . $net . ' network' . $srv . ' servers' . $fwl . ' firewalls
    '); - - $graph_array['type'] = "location_bits"; - $graph_array['height'] = "100"; - $graph_array['width'] = "220"; - $graph_array['to'] = $config['time']['now']; - $graph_array['legend'] = "no"; - $graph_array['id'] = $location; - - include("includes/print-graphrow.inc.php"); - - echo("
    "); + if ($hostalerts) { + $alert = 'alert'; + } + else { + $alert = ''; + } -?> + if ($location != '') { + echo ' + '.$location.' + '.$alert.' + '.$num.' devices + '.$net.' network + '.$srv.' servers + '.$fwl.' firewalls + + '; + + if ($vars['view'] == 'traffic') { + echo ''; + + $graph_array['type'] = 'location_bits'; + $graph_array['height'] = '100'; + $graph_array['width'] = '220'; + $graph_array['to'] = $config['time']['now']; + $graph_array['legend'] = 'no'; + $graph_array['id'] = $location; + + include 'includes/print-graphrow.inc.php'; + + echo ''; + } + + $done = 'yes'; + }//end if +}//end foreach + +echo ''; diff --git a/html/pages/logon.inc.php b/html/pages/logon.inc.php index e9819b1b01..a8a156574d 100644 --- a/html/pages/logon.inc.php +++ b/html/pages/logon.inc.php @@ -1,7 +1,8 @@
    @@ -32,14 +33,12 @@ if( $config['twofactor'] && isset($twofactorform) ) {
    'error','message'=>$auth_message,'title'=>'Login error'); } ?>
    diff --git a/html/pages/map.inc.php b/html/pages/map.inc.php index 0fa1cbb5f7..115c0600c3 100644 --- a/html/pages/map.inc.php +++ b/html/pages/map.inc.php @@ -10,6 +10,5 @@ * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ -$pagetitle[] = "Map"; -require_once "includes/print-map.inc.php"; -?> +$pagetitle[] = 'Map'; +require_once 'includes/print-map.inc.php'; diff --git a/html/pages/packages.inc.php b/html/pages/packages.inc.php index c3e79c8cf6..ab26fd00a9 100644 --- a/html/pages/packages.inc.php +++ b/html/pages/packages.inc.php @@ -2,8 +2,7 @@ foreach ($vars as $var => $value) { if ($value != '') { - switch ($var) - { + switch ($var) { case 'name': $where .= " AND `$var` = ?"; $param[] = $value; @@ -26,8 +25,7 @@ foreach (dbFetchRows("SELECT * FROM `packages` WHERE 1 $where GROUP BY `name`", foreach ($entry['blah'] as $version => $bleu) { $content = '
    '; - foreach ($bleu as $build => $bloo) - { + foreach ($bleu as $build => $bloo) { if ($build) { $dbuild = '-'.$build; } @@ -36,8 +34,7 @@ foreach (dbFetchRows("SELECT * FROM `packages` WHERE 1 $where GROUP BY `name`", } $content .= '
    '.$version.$dbuild.''; - foreach ($bloo as $device_id => $no) - { + foreach ($bloo as $device_id => $no) { $this_device = device_by_id_cache($device_id); $content .= ''.$this_device['hostname'].' '; } diff --git a/html/pages/plugin.inc.php b/html/pages/plugin.inc.php index daec96f46b..1f718acff2 100644 --- a/html/pages/plugin.inc.php +++ b/html/pages/plugin.inc.php @@ -1,24 +1,18 @@ 'plugin'); +$link_array = array('page' => 'plugin'); -$pagetitle[] = "Plugin"; +$pagetitle[] = 'Plugin'; -if ($vars['view'] == "admin") -{ - include_once('pages/plugin/admin.inc.php'); +if ($vars['view'] == 'admin') { + include_once 'pages/plugin/admin.inc.php'; } -else -{ - $plugin = dbFetchRow("SELECT `plugin_name` FROM `plugins` WHERE `plugin_name` = '".$vars['p']."' AND `plugin_active`='1'"); - if(!empty($plugin)) - { - require('plugins/'.$plugin['plugin_name'].'/'.$plugin['plugin_name'].'.inc.php'); - } - else - { - print_error( "This plugin is either disabled or not available." ); - } +else { + $plugin = dbFetchRow("SELECT `plugin_name` FROM `plugins` WHERE `plugin_name` = '".$vars['p']."' AND `plugin_active`='1'"); + if (!empty($plugin)) { + include 'plugins/'.$plugin['plugin_name'].'/'.$plugin['plugin_name'].'.inc.php'; + } + else { + print_error('This plugin is either disabled or not available.'); + } } - -?> diff --git a/html/pages/plugin/admin.inc.php b/html/pages/plugin/admin.inc.php index 1773d641d8..e20bec1b64 100644 --- a/html/pages/plugin/admin.inc.php +++ b/html/pages/plugin/admin.inc.php @@ -1,33 +1,26 @@ = '10') -{ - - // Scan for new plugins and add to the database - $new_plugins = scan_new_plugins(); +if ($_SESSION['userlevel'] >= '10') { + // Scan for new plugins and add to the database + $new_plugins = scan_new_plugins(); - // Check if we have to toggle enabled / disable a particular module - $plugin_id = $_POST['plugin_id']; - $plugin_active = $_POST['plugin_active']; - if(is_numeric($plugin_id) && is_numeric($plugin_active)) - { - if( $plugin_active == '0') - { - $plugin_active = 1; - } - elseif( $plugin_active == '1') - { - $plugin_active = 0; - } - else - { - $plugin_active = 0; - } + // Check if we have to toggle enabled / disable a particular module + $plugin_id = $_POST['plugin_id']; + $plugin_active = $_POST['plugin_active']; + if (is_numeric($plugin_id) && is_numeric($plugin_active)) { + if ($plugin_active == '0') { + $plugin_active = 1; + } + else if ($plugin_active == '1') { + $plugin_active = 0; + } + else { + $plugin_active = 0; + } - if(dbUpdate(array('plugin_active' => $plugin_active), 'plugins', '`plugin_id` = ?', array($plugin_id))) - { - echo(' + if (dbUpdate(array('plugin_active' => $plugin_active), 'plugins', '`plugin_id` = ?', array($plugin_id))) { + echo ' -'); - } - - } +'; + } + }//end if ?> @@ -49,14 +41,13 @@ $.ajax({ System plugins
    0) - { - echo('
    +if ($new_plugins > 0) { + echo '
    - We have found ' . $new_plugins . ' new plugins that need to be configured and enabled + We have found '.$new_plugins.' new plugins that need to be configured and enabled
    -
    '); - } +
    '; +} ?> @@ -65,24 +56,21 @@ $.ajax({ + echo ' - '); - } - + '; +}//end foreach ?>
    - '. $plugins['plugin_name'] . ' + '.$plugins['plugin_name'].' @@ -91,18 +79,14 @@ $.ajax({
    +else { + include 'includes/error-no-perm.inc.php'; +}//end if diff --git a/html/pages/poll-log.inc.php b/html/pages/poll-log.inc.php index 3abdf05a8e..91ef8132e2 100644 --- a/html/pages/poll-log.inc.php +++ b/html/pages/poll-log.inc.php @@ -1,5 +1,5 @@ diff --git a/html/pages/pollers.inc.php b/html/pages/pollers.inc.php index de85c2344c..3fef3d931c 100644 --- a/html/pages/pollers.inc.php +++ b/html/pages/pollers.inc.php @@ -12,25 +12,32 @@ * the source code distribution for details. */ -$no_refresh = TRUE; +$no_refresh = true; -echo(''; if (isset($vars['tab'])) { - require_once "pages/pollers/".mres($vars['tab']).".inc.php"; + include_once 'pages/pollers/'.mres($vars['tab']).'.inc.php'; } diff --git a/html/pages/pollers/groups.inc.php b/html/pages/pollers/groups.inc.php index 50019dfc26..a914650ae2 100644 --- a/html/pages/pollers/groups.inc.php +++ b/html/pages/pollers/groups.inc.php @@ -12,7 +12,7 @@ * the source code distribution for details. */ -require_once "includes/modal/poller_groups.inc.php"; +require_once 'includes/modal/poller_groups.inc.php'; ?>
    @@ -28,18 +28,17 @@ require_once "includes/modal/poller_groups.inc.php"; + echo ' + -'); +'; } ?> diff --git a/html/pages/pollers/pollers.inc.php b/html/pages/pollers/pollers.inc.php index c5e0eb2799..f948d3a8b1 100644 --- a/html/pages/pollers/pollers.inc.php +++ b/html/pages/pollers/pollers.inc.php @@ -24,26 +24,28 @@ = 300) { $row_class = 'danger'; - } elseif ($old >= 280 && $old < 300) { + } + else if ($old >= 280 && $old < 300) { $row_class = 'warning'; - } else { + } + else { $row_class = 'success'; } - echo(' + + echo ' -'); +'; } ?> diff --git a/html/pages/ports.inc.php b/html/pages/ports.inc.php index 8ff1f7d344..edeea9fbef 100644 --- a/html/pages/ports.inc.php +++ b/html/pages/ports.inc.php @@ -4,29 +4,27 @@ $pagetitle[] = "Ports"; // Set Defaults here -if(!isset($vars['format'])) { $vars['format'] = "list_basic"; } +if(!isset($vars['format'])) { + $vars['format'] = "list_basic"; +} print_optionbar_start(); echo('Lists » '); -$menu_options = array('basic' => 'Basic', - 'detail' => 'Detail'); +$menu_options = array('basic' => 'Basic', 'detail' => 'Detail'); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == "list_".$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == "list_".$option) { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == "list_".$option) { + echo(""); + } + $sep = " | "; } ?> @@ -37,24 +35,21 @@ foreach ($menu_options as $option => $text) 'Bits', - 'upkts' => 'Unicast Packets', - 'nupkts' => 'Non-Unicast Packets', - 'errors' => 'Errors'); + 'upkts' => 'Unicast Packets', + 'nupkts' => 'Non-Unicast Packets', + 'errors' => 'Errors'); $sep = ""; -foreach ($menu_options as $option => $text) -{ - echo($sep); - if ($vars['format'] == 'graph_'.$option) - { - echo(''); - } - echo('' . $text . ''); - if ($vars['format'] == 'graph_'.$option) - { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) { + echo($sep); + if ($vars['format'] == 'graph_'.$option) { + echo(''); + } + echo('' . $text . ''); + if ($vars['format'] == 'graph_'.$option) { + echo(""); + } + $sep = " | "; } echo('
    '); @@ -64,29 +59,28 @@ echo('
    '); Update URL | '')).'">Search'); - } else { +} +else { echo('Search'); - } +} - echo(" | "); +echo(" | "); - if (isset($vars['bare']) && $vars['bare'] == "yes") - { +if (isset($vars['bare']) && $vars['bare'] == "yes") { echo('Header'); - } else { +} +else { echo('Header'); - } +} echo('
    '); print_optionbar_end(); print_optionbar_start(); -if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['searchbar'])) -{ +if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['searchbar'])) { ?>
    @@ -95,67 +89,66 @@ if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars[' = 5) -{ - $results = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`"); -} -else -{ - $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); -} -foreach ($results as $data) -{ - echo(' "); -} + if($_SESSION['userlevel'] >= 5) { + $results = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`"); + } + else { + $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); + } + foreach ($results as $data) { + echo(' "); + } -if($_SESSION['userlevel'] < 5) -{ - $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); -} -else -{ - $results = array(); -} -foreach ($results as $data) -{ - echo(' "); -} + if($_SESSION['userlevel'] < 5) { + $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); + } + else { + $results = array(); + } + foreach ($results as $data) { + echo(' "); + } ?> - placeholder="Hostname" /> + placeholder="Hostname" />
    @@ -164,97 +157,100 @@ foreach (dbFetchRows($sql,$param) as $data) ".$data['ifType'].""); - } -} + if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `ifType` FROM `ports` GROUP BY `ifType` ORDER BY `ifType`"; + } + else { + $sql = "SELECT `ifType` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` GROUP BY `ifType` ORDER BY `ifType`"; + $param[] = array($_SESSION['user_id'],$_SESSION['user_id']); + } + foreach (dbFetchRows($sql,$param) as $data) { + if ($data['ifType']) { + echo(' "); + } + } ?>
    - placeholder="Port Description"/> + placeholder="Port Description"/>
    - > + > - > + > - > + >
    @@ -266,95 +262,98 @@ foreach ($sorts as $sort => $sort_text)
    '.$group['id'].' '.$group['group_name'].' '.$group['descr'].'
    '.$poller['poller_name'].' '.$poller['devices'].' '.$poller['time_taken'].' Seconds '.$poller['last_polled'].'
    - $value) -{ - if ($value != "") - { - switch ($var) - { - case 'hostname': - $where .= " AND D.hostname LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'location': - $where .= " AND D.location LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'device_id': - $where .= " AND D.device_id = ?"; - $param[] = $value; - break; - case 'deleted': - if ($value == 1) { - $where .= " AND `I`.`deleted` = 1"; - $ignore_filter = 1; +foreach ($vars as $var => $value) { + if ($value != "") { + switch ($var) { + case 'hostname': + $where .= " AND D.hostname LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'location': + $where .= " AND D.location LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'device_id': + $where .= " AND D.device_id = ?"; + $param[] = $value; + break; + case 'deleted': + if ($value == 1) { + $where .= " AND `I`.`deleted` = 1"; + $ignore_filter = 1; + } + break; + case 'ignore': + if ($value == 1) { + $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; + $ignore_filter = 1; + } + break; + case 'disabled': + if ($value == 1) { + $where .= " AND `I`.`disabled` = 1 AND `I`.`deleted` = 0"; + $disabled_filter = 1; + } + break; + case 'ifSpeed': + if (is_numeric($value)) { + $where .= " AND I.$var = ?"; + $param[] = $value; + } + break; + case 'ifType': + $where .= " AND I.$var = ?"; + $param[] = $value; + break; + case 'ifAlias': + case 'port_descr_type': + $where .= " AND I.$var LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'errors': + if ($value == 1) { + $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; + } + break; + case 'state': + if ($value == "down") { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; + $param[] = "up"; + $param[] = "down"; + } + elseif($value == "up") { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; + $param[] = "up"; + $param[] = "up"; + } + elseif($value == "admindown") { + $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; + $param[] = "down"; + } + break; } - break; - case 'ignore': - if ($value == 1) { - $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; - $ignore_filter = 1; - } - break; - case 'disabled': - if ($value == 1) { - $where .= " AND `I`.`disabled` = 1 AND `I`.`deleted` = 0"; - $disabled_filter = 1; - } - break; - case 'ifSpeed': - if (is_numeric($value)) - { - $where .= " AND I.$var = ?"; - $param[] = $value; - } - break; - case 'ifType': - $where .= " AND I.$var = ?"; - $param[] = $value; - break; - case 'ifAlias': - case 'port_descr_type': - $where .= " AND I.$var LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'errors': - if ($value == 1) - { - $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; - } - break; - case 'state': - if ($value == "down") - { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; - $param[] = "up"; - $param[] = "down"; - } elseif($value == "up") { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; - $param[] = "up"; - $param[] = "up"; - } elseif($value == "admindown") { - $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; - $param[] = "down"; - } - break; } - } } if ($ignore_filter == 0 && $disabled_filter == 0) { @@ -369,49 +368,47 @@ list($format, $subformat) = explode("_", $vars['format']); $ports = dbFetchRows($query, $param); -switch ($vars['sort']) -{ - case 'traffic': - $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); - break; - case 'traffic_in': - $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); - break; - case 'traffic_out': - $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); - break; - case 'packets': - $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); - break; - case 'packets_in': - $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); - break; - case 'packets_out': - $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); - break; - case 'errors': - $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); - break; - case 'speed': - $ports = array_sort($ports, 'ifSpeed', SORT_DESC); - break; - case 'port': - $ports = array_sort($ports, 'ifDescr', SORT_ASC); - break; - case 'media': - $ports = array_sort($ports, 'ifType', SORT_ASC); - break; - case 'descr': - $ports = array_sort($ports, 'ifAlias', SORT_ASC); - break; - case 'device': - default: - $ports = array_sort($ports, 'hostname', SORT_ASC); +switch ($vars['sort']) { + case 'traffic': + $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); + break; + case 'traffic_in': + $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); + break; + case 'traffic_out': + $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); + break; + case 'packets': + $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); + break; + case 'packets_in': + $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); + break; + case 'packets_out': + $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); + break; + case 'errors': + $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); + break; + case 'speed': + $ports = array_sort($ports, 'ifSpeed', SORT_DESC); + break; + case 'port': + $ports = array_sort($ports, 'ifDescr', SORT_ASC); + break; + case 'media': + $ports = array_sort($ports, 'ifType', SORT_ASC); + break; + case 'descr': + $ports = array_sort($ports, 'ifAlias', SORT_ASC); + break; + case 'device': + default: + $ports = array_sort($ports, 'hostname', SORT_ASC); } -if(file_exists('pages/ports/'.$format.'.inc.php')) -{ - include('pages/ports/'.$format.'.inc.php'); +if(file_exists('pages/ports/'.$format.'.inc.php')) { + require 'pages/ports/'.$format.'.inc.php'; } ?> diff --git a/html/pages/ports/list.inc.php b/html/pages/ports/list.inc.php index 8ae9c9df36..71f52e6180 100644 --- a/html/pages/ports/list.inc.php +++ b/html/pages/ports/list.inc.php @@ -3,68 +3,75 @@ '); +echo ''; -$cols = array('device' => 'Device', - 'port' => 'Port', - 'speed' => 'Speed', - 'traffic_in' => 'Down', - 'traffic_out' => 'Up', - 'media' => 'Media', - 'descr' => 'Description' ); +$cols = array( + 'device' => 'Device', + 'port' => 'Port', + 'speed' => 'Speed', + 'traffic_in' => 'Down', + 'traffic_out' => 'Up', + 'media' => 'Media', + 'descr' => 'Description', +); -foreach ($cols as $sort => $col) -{ - if (isset($vars['sort']) && $vars['sort'] == $sort) - { - echo(''.$col.' *'); - } else { - echo(''.$col.''); - } +foreach ($cols as $sort => $col) { + if (isset($vars['sort']) && $vars['sort'] == $sort) { + echo ''.$col.' *'; + } + else { + echo ''.$col.''; + } } -echo(" "); +echo ' '; -$ports_disabled = 0; $ports_down = 0; $ports_up = 0; $ports_total = 0; +$ports_disabled = 0; +$ports_down = 0; +$ports_up = 0; +$ports_total = 0; -foreach ($ports as $port) -{ +foreach ($ports as $port) { + if (port_permitted($port['port_id'], $port['device_id'])) { + if ($port['ifAdminStatus'] == 'down') { + $ports_disabled++; + } + else if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'down') { + $ports_down++; + } + else if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') { + $ports_up++; + } - if (port_permitted($port['port_id'], $port['device_id'])) - { + $ports_total++; - if ($port['ifAdminStatus'] == "down") { $ports_disabled++; - } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus']== "down") { $ports_down++; - } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus']== "up") { $ports_up++; } - $ports_total++; + $speed = humanspeed($port['ifSpeed']); + $type = humanmedia($port['ifType']); + $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); - $speed = humanspeed($port['ifSpeed']); - $type = humanmedia($port['ifType']); - $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); + if ((isset($port['in_errors']) && $port['in_errors'] > 0) || (isset($ports['out_errors']) && $port['out_errors'] > 0)) { + $error_img = generate_port_link($port, "Interface Errors", errors); + } + else { + $error_img = ''; + } - if ((isset($port['in_errors']) && $port['in_errors'] > 0) || (isset($ports['out_errors']) && $port['out_errors'] > 0)) - { - $error_img = generate_port_link($port,"Interface Errors",errors); - } else { $error_img = ""; } + $port['in_rate'] = formatRates(($port['ifInOctets_rate'] * 8)); + $port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8)); - $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); - $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); + $port = ifLabel($port, $device); + echo " + ".generate_device_link($port, shorthost($port['hostname'], '20'))." + ".fixIfName($port['label'])." $error_img + $speed + ".$port['in_rate'].' + '.$port['out_rate']." + $type + ".$port['ifAlias']." + \n"; + }//end if +}//end foreach - $port = ifLabel($port, $device); - echo(" - ".generate_device_link($port, shorthost($port['hostname'], "20"))." - ".fixIfName($port['label'])." $error_img - $speed - ".$port['in_rate']." - ".$port['out_rate']." - $type - " . $port['ifAlias'] . " - \n"); - } -} - -echo(''); -echo("Matched Ports: $ports_total ( Up $ports_up | Down $ports_down | Disabled $ports_disabled )"); -echo(''); - -?> +echo ''; +echo "Matched Ports: $ports_total ( Up $ports_up | Down $ports_down | Disabled $ports_disabled )"; +echo ''; diff --git a/html/pages/preferences.inc.php b/html/pages/preferences.inc.php index f4815df24e..ca2f798352 100644 --- a/html/pages/preferences.inc.php +++ b/html/pages/preferences.inc.php @@ -1,48 +1,41 @@ User Preferences"); +echo '

    User Preferences

    '; if ($_SESSION['userlevel'] == 11) { - demo_account(); - -} else { - -if ($_POST['action'] == "changepass") -{ - if (authenticate($_SESSION['username'],$_POST['old_pass'])) - { - if ($_POST['new_pass'] == "" || $_POST['new_pass2'] == "") - { - $changepass_message = "Password must not be blank."; - } - elseif ($_POST['new_pass'] == $_POST['new_pass2']) - { - changepassword($_SESSION['username'],$_POST['new_pass']); - $changepass_message = "Password Changed."; - } - else - { - $changepass_message = "Passwords don't match."; - } - } else { - $changepass_message = "Incorrect password"; - } } +else { + if ($_POST['action'] == 'changepass') { + if (authenticate($_SESSION['username'], $_POST['old_pass'])) { + if ($_POST['new_pass'] == '' || $_POST['new_pass2'] == '') { + $changepass_message = 'Password must not be blank.'; + } + else if ($_POST['new_pass'] == $_POST['new_pass2']) { + changepassword($_SESSION['username'], $_POST['new_pass']); + $changepass_message = 'Password Changed.'; + } + else { + $changepass_message = "Passwords don't match."; + } + } + else { + $changepass_message = 'Incorrect password'; + } + } -include("includes/update-preferences-password.inc.php"); + include 'includes/update-preferences-password.inc.php'; -echo("
    "); + echo "
    "; -if (passwordscanchange($_SESSION['username'])) -{ - echo("

    Change Password

    "); - echo($changepass_message); - echo(" + if (passwordscanchange($_SESSION['username'])) { + echo '

    Change Password

    '; + echo $changepass_message; + echo "
    @@ -69,93 +62,107 @@ if (passwordscanchange($_SESSION['username']))
    -"); - echo("
    "); -} +"; + echo '
    '; + }//end if -if( $config['twofactor'] === true ) { - if( $_POST['twofactorremove'] == 1 ) { - require_once($config['install_dir']."/html/includes/authentication/twofactor.lib.php"); - if( !isset($_POST['twofactor']) ) { - echo '
    '; - echo ''; - echo twofactor_form(false); - echo '
    '; - } else{ - $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); - if( empty($twofactor['twofactor']) ) { - echo '
    Error: How did you even get here?!
    '; - } else { - $twofactor = json_decode($twofactor['twofactor'],true); - } - if( verify_hotp($twofactor['key'],$_POST['twofactor'],$twofactor['counter']) ) { - if( !dbUpdate(array('twofactor' => ''),'users','username = ?',array($_SESSION['username'])) ) { - echo '
    Error while disabling TwoFactor.
    '; - } else { - echo '
    TwoFactor Disabled.
    '; + if ($config['twofactor'] === true) { + if ($_POST['twofactorremove'] == 1) { + include_once $config['install_dir'].'/html/includes/authentication/twofactor.lib.php'; + if (!isset($_POST['twofactor'])) { + echo '
    '; + echo ''; + echo twofactor_form(false); + echo '
    '; + } + else { + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); + if (empty($twofactor['twofactor'])) { + echo '
    Error: How did you even get here?!
    '; + } + else { + $twofactor = json_decode($twofactor['twofactor'], true); + } + + if (verify_hotp($twofactor['key'], $_POST['twofactor'], $twofactor['counter'])) { + if (!dbUpdate(array('twofactor' => ''), 'users', 'username = ?', array($_SESSION['username']))) { + echo '
    Error while disabling TwoFactor.
    '; + } + else { + echo '
    TwoFactor Disabled.
    '; + } + } + else { + session_destroy(); + echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; + } + }//end if } - } else { - session_destroy(); - echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; - } - } - } else { - $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE username = ?", array($_SESSION['username'])); - echo ''; - echo '

    Two-Factor Authentication

    '; - if( !empty($twofactor['twofactor']) ) { - $twofactor = json_decode($twofactor['twofactor'],true); - $twofactor['text'] = "
    + else { + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); + echo ''; + echo '

    Two-Factor Authentication

    '; + if (!empty($twofactor['twofactor'])) { + $twofactor = json_decode($twofactor['twofactor'], true); + $twofactor['text'] = "
    "; - if( $twofactor['counter'] !== false ) { - $twofactor['uri'] = "otpauth://hotp/".$_SESSION['username']."?issuer=LibreNMS&counter=".$twofactor['counter']."&secret=".$twofactor['key']; - $twofactor['text'] .= "
    + if ($twofactor['counter'] !== false) { + $twofactor['uri'] = 'otpauth://hotp/'.$_SESSION['username'].'?issuer=LibreNMS&counter='.$twofactor['counter'].'&secret='.$twofactor['key']; + $twofactor['text'] .= "
    "; - } else { - $twofactor['uri'] = "otpauth://totp/".$_SESSION['username']."?issuer=LibreNMS&secret=".$twofactor['key']; - } - echo '
    + } + else { + $twofactor['uri'] = 'otpauth://totp/'.$_SESSION['username'].'?issuer=LibreNMS&secret='.$twofactor['key']; + } + + echo '
    '; - echo '
    + echo '
    '.$twofactor['text'].'
    '; - echo ''; - echo '
    + echo ''; + echo '
    '; - } else { - if( isset($_POST['gentwofactorkey']) && isset($_POST['twofactortype']) ) { - require_once($config['install_dir']."/html/includes/authentication/twofactor.lib.php"); - $chk = dbFetchRow("SELECT twofactor FROM users WHERE username = ?", array($_SESSION['username'])); - if( empty($chk['twofactor']) ) { - $twofactor = array('key' => twofactor_genkey()); - if( $_POST['twofactortype'] == "counter" ) { - $twofactor['counter'] = 1; - } else { - $twofactor['counter'] = false; - } - if( !dbUpdate(array('twofactor' => json_encode($twofactor)),'users','username = ?',array($_SESSION['username'])) ) { - echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; - } else { - echo '
    Added TwoFactor credentials. Please reload page.
    '; - } - } else { - echo '
    TwoFactor credentials already exists.
    '; - } - } else { - echo '
    + } + else { + if (isset($_POST['gentwofactorkey']) && isset($_POST['twofactortype'])) { + include_once $config['install_dir'].'/html/includes/authentication/twofactor.lib.php'; + $chk = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); + if (empty($chk['twofactor'])) { + $twofactor = array('key' => twofactor_genkey()); + if ($_POST['twofactortype'] == 'counter') { + $twofactor['counter'] = 1; + } + else { + $twofactor['counter'] = false; + } + + if (!dbUpdate(array('twofactor' => json_encode($twofactor)), 'users', 'username = ?', array($_SESSION['username']))) { + echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; + } + else { + echo '
    Added TwoFactor credentials. Please reload page.
    '; + } + } + else { + echo '
    TwoFactor credentials already exists.
    '; + } + } + else { + echo '
    @@ -169,32 +176,34 @@ if( $config['twofactor'] === true ) {
    '; - } + }//end if + }//end if + echo '
    '; + }//end if + }//end if +}//end if + +echo "
    '; - } } -} - -echo("
    "); -echo("
    Device Permissions
    "); - -if ($_SESSION['userlevel'] == '10') { echo("Global Administrative Access"); } -if ($_SESSION['userlevel'] == '5') { echo("Global Viewing Access"); } -if ($_SESSION['userlevel'] == '1') -{ - - foreach (dbFetchRows("SELECT * FROM `devices_perms` AS P, `devices` AS D WHERE `user_id` = ? AND P.device_id = D.device_id", array($_SESSION['user_id'])) as $perm) - { - #FIXME generatedevicelink? - echo("" . $perm['hostname'] . "
    "); - $dev_access = 1; - } - - if (!$dev_access) { echo("No access!"); } -} - -echo("
    "); - -?> +echo '
    '; diff --git a/html/pages/pseudowires.inc.php b/html/pages/pseudowires.inc.php index 5dd77f468c..3408973fd4 100644 --- a/html/pages/pseudowires.inc.php +++ b/html/pages/pseudowires.inc.php @@ -90,8 +90,7 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I, devices AS D W $pw_a['to'] = $config['time']['now']; $pw_a['bg'] = $bg; $types = array('bits', 'upkts', 'errors'); - foreach ($types as $graph_type) - { + foreach ($types as $graph_type) { $pw_a['graph_type'] = 'port_'.$graph_type; print_port_thumbnail($pw_a); } diff --git a/html/pages/public.inc.php b/html/pages/public.inc.php index ad89593bcf..71181a977e 100644 --- a/html/pages/public.inc.php +++ b/html/pages/public.inc.php @@ -1,4 +1,5 @@

    System Status

    @@ -50,9 +49,8 @@ $query = "SELECT * FROM `devices` WHERE 1 AND disabled='0' AND `ignore`='0' ORDE Uptime/Location diff --git a/html/pages/routing/bgp.inc.php b/html/pages/routing/bgp.inc.php index 5e04945626..3268715ec5 100644 --- a/html/pages/routing/bgp.inc.php +++ b/html/pages/routing/bgp.inc.php @@ -1,260 +1,355 @@ 'routing', 'protocol' => 'bgp'); +else { + $link_array = array( + 'page' => 'routing', + 'protocol' => 'bgp', + ); - print_optionbar_start('', ''); + print_optionbar_start('', ''); - echo('BGP » '); + echo 'BGP » '; - if (!$vars['type']) { $vars['type'] = "all"; } - - if ($vars['type'] == "all") { echo(""); } - echo(generate_link("All",$vars, array('type' => 'all'))); - if ($vars['type'] == "all") { echo(""); } - - echo(" | "); - - if ($vars['type'] == "internal") { echo(""); } - echo(generate_link("iBGP",$vars, array('type' => 'internal'))); - if ($vars['type'] == "internal") { echo(""); } - - echo(" | "); - - if ($vars['type'] == "external") { echo(""); } - echo(generate_link("eBGP",$vars, array('type' => 'external'))); - if ($vars['type'] == "external") { echo(""); } - - echo(" | "); - - if ($vars['adminstatus'] == "stop") - { - echo(""); - echo(generate_link("Shutdown",$vars, array('adminstatus' => NULL))); - echo(""); - } else { - echo(generate_link("Shutdown",$vars, array('adminstatus' => 'stop'))); - } - - echo(" | "); - - if ($vars['adminstatus'] == "start") - { - echo(""); - echo(generate_link("Enabled",$vars, array('adminstatus' => NULL))); - echo(""); - } else { - echo(generate_link("Enabled",$vars, array('adminstatus' => 'start'))); - } - - echo(" | "); - - if ($vars['state'] == "down") - { - echo(""); - echo(generate_link("Down",$vars, array('state' => NULL))); - echo(""); - } else { - echo(generate_link("Down",$vars, array('state' => 'down'))); - } - - // End BGP Menu - - if (!isset($vars['view'])) { $vars['view'] = 'details'; } - - echo('
    '); - - if ($vars['view'] == "details") { echo(""); } - echo(generate_link("No Graphs",$vars, array('view' => 'details', 'graph' => 'NULL'))); - if ($vars['view'] == "details") { echo(""); } - - echo(" | "); - - if ($vars['graph'] == "updates") { echo(""); } - echo(generate_link("Updates",$vars, array('view' => 'graphs', 'graph' => 'updates'))); - if ($vars['graph'] == "updates") { echo(""); } - - echo(" | Prefixes: Unicast ("); - if ($vars['graph'] == "prefixes_ipv4unicast") { echo(""); } - echo(generate_link("IPv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast'))); - if ($vars['graph'] == "prefixes_ipv4unicast") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "prefixes_ipv6unicast") { echo(""); } - echo(generate_link("IPv6",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast'))); - if ($vars['graph'] == "prefixes_ipv6unicast") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "prefixes_ipv4vpn") { echo(""); } - echo(generate_link("VPNv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4vpn'))); - if ($vars['graph'] == "prefixes_ipv4vpn") { echo(""); } - echo(")"); - - echo(" | Multicast ("); - if ($vars['graph'] == "prefixes_ipv4multicast") { echo(""); } - echo(generate_link("IPv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4multicast'))); - if ($vars['graph'] == "prefixes_ipv4multicast") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "prefixes_ipv6multicast") { echo(""); } - echo(generate_link("IPv6",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6multicast'))); - if ($vars['graph'] == "prefixes_ipv6multicast") { echo(""); } - echo(")"); - - echo(" | MAC ("); - if ($vars['graph'] == "macaccounting_bits") { echo(""); } - echo(generate_link("Bits",$vars, array('view' => 'graphs', 'graph' => 'macaccounting_bits'))); - if ($vars['graph'] == "macaccounting_bits") { echo(""); } - - echo("|"); - - if ($vars['graph'] == "macaccounting_pkts") { echo(""); } - echo(generate_link("Packets",$vars, array('view' => 'graphs', 'graph' => 'macaccounting_pkts'))); - if ($vars['graph'] == "macaccounting_pkts") { echo(""); } - echo(")"); - - echo('
    '); - - print_optionbar_end(); - - echo(""); - echo(''); - - if ($vars['type'] == "external") - { - $where = "AND D.bgpLocalAs != B.bgpPeerRemoteAs"; - } elseif ($vars['type'] == "internal") { - $where = "AND D.bgpLocalAs = B.bgpPeerRemoteAs"; - } - - if ($vars['adminstatus'] == "stop") - { - $where .= " AND (B.bgpPeerAdminStatus = 'stop')"; - } elseif ($vars['adminstatus'] == "start") - { - $where .= " AND (B.bgpPeerAdminStatus = 'start' || B.bgpPeerAdminStatus = 'running')"; - } - - if ($vars['state'] == "down") - { - $where .= " AND (B.bgpPeerState != 'established')"; - } - - $peer_query = "select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id ".$where." ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier"; - foreach (dbFetchRows($peer_query) as $peer) - { - unset ($alert, $bg_image); - - if ($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $peer['alert']=1; } - if ($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "gray"; } - if ($peer['bgpPeerAdminStatus'] == "stop") { $peer['alert']=0; $peer['disabled']=1; } - if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; - if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { $peer_type = "Priv eBGP"; } + if (!$vars['type']) { + $vars['type'] = 'all'; } - $peerhost = dbFetchRow("SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($peer['bgpPeerIdentifier'])); - - if ($peerhost) { $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); } else { unset($peername); } - - // display overlib graphs - - $graph_type = "bgp_updates"; - $local_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150&&afi=ipv4&safi=unicast"; - if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { - $peer_ip = Net_IPv6::compress($peer['bgpLocalAddr']); - } else { - $peer_ip = $peer['bgpLocalAddr']; - } - $localaddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer_ip . ""; - - $graph_type = "bgp_updates"; - $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; - if (filter_var($peer['bgpPeerIdentifier'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { - $peer_ident = Net_IPv6::compress($peer['bgpPeerIdentifier']); - } else { - $peer_ident = $peer['bgpPeerIdentifier']; + if ($vars['type'] == 'all') { + echo ""; } - $peeraddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer_ident . ""; - - echo('"); - - unset($sep); - foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) - { - $afi = $afisafi['afi']; - $safi = $afisafi['safi']; - $this_afisafi = $afi.$safi; - $peer['afi'] .= $sep . $afi .".".$safi; - $sep = "
    "; - $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer - } - unset($sep); - - echo(" - - - - - - - - "); - - unset($invalid); - switch ($vars['graph']) - { - case 'prefixes_ipv4unicast': - case 'prefixes_ipv4multicast': - case 'prefixes_ipv4vpn': - case 'prefixes_ipv6unicast': - case 'prefixes_ipv6multicast': - list(,$afisafi) = explode("_", $vars['graph']); - if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } - case 'updates': - $graph_array['type'] = "bgp_" . $vars['graph']; - $graph_array['id'] = $peer['bgpPeer_id']; + echo generate_link('All', $vars, array('type' => 'all')); + if ($vars['type'] == 'all') { + echo ''; } - switch ($vars['graph']) - { - case 'macaccounting_bits': - case 'macaccounting_pkts': - $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier'])); - $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; - if (is_array($acc) && is_file($database)) - { - $peer['graph'] = 1; - $graph_array['id'] = $acc['ma_id']; - $graph_array['type'] = $vars['graph']; + echo ' | '; + + if ($vars['type'] == 'internal') { + echo ""; + } + + echo generate_link('iBGP', $vars, array('type' => 'internal')); + if ($vars['type'] == 'internal') { + echo ''; + } + + echo ' | '; + + if ($vars['type'] == 'external') { + echo ""; + } + + echo generate_link('eBGP', $vars, array('type' => 'external')); + if ($vars['type'] == 'external') { + echo ''; + } + + echo ' | '; + + if ($vars['adminstatus'] == 'stop') { + echo ""; + echo generate_link('Shutdown', $vars, array('adminstatus' => null)); + echo ''; + } + else { + echo generate_link('Shutdown', $vars, array('adminstatus' => 'stop')); + } + + echo ' | '; + + if ($vars['adminstatus'] == 'start') { + echo ""; + echo generate_link('Enabled', $vars, array('adminstatus' => null)); + echo ''; + } + else { + echo generate_link('Enabled', $vars, array('adminstatus' => 'start')); + } + + echo ' | '; + + if ($vars['state'] == 'down') { + echo ""; + echo generate_link('Down', $vars, array('state' => null)); + echo ''; + } + else { + echo generate_link('Down', $vars, array('state' => 'down')); + } + + // End BGP Menu + if (!isset($vars['view'])) { + $vars['view'] = 'details'; + } + + echo '
    '; + + if ($vars['view'] == 'details') { + echo ""; + } + + echo generate_link('No Graphs', $vars, array('view' => 'details', 'graph' => 'NULL')); + if ($vars['view'] == 'details') { + echo ''; + } + + echo ' | '; + + if ($vars['graph'] == 'updates') { + echo ""; + } + + echo generate_link('Updates', $vars, array('view' => 'graphs', 'graph' => 'updates')); + if ($vars['graph'] == 'updates') { + echo ''; + } + + echo ' | Prefixes: Unicast ('; + if ($vars['graph'] == 'prefixes_ipv4unicast') { + echo ""; + } + + echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast')); + if ($vars['graph'] == 'prefixes_ipv4unicast') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'prefixes_ipv6unicast') { + echo ""; + } + + echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast')); + if ($vars['graph'] == 'prefixes_ipv6unicast') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'prefixes_ipv4vpn') { + echo ""; + } + + echo generate_link('VPNv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4vpn')); + if ($vars['graph'] == 'prefixes_ipv4vpn') { + echo ''; + } + + echo ')'; + + echo ' | Multicast ('; + if ($vars['graph'] == 'prefixes_ipv4multicast') { + echo ""; + } + + echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4multicast')); + if ($vars['graph'] == 'prefixes_ipv4multicast') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'prefixes_ipv6multicast') { + echo ""; + } + + echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6multicast')); + if ($vars['graph'] == 'prefixes_ipv6multicast') { + echo ''; + } + + echo ')'; + + echo ' | MAC ('; + if ($vars['graph'] == 'macaccounting_bits') { + echo ""; + } + + echo generate_link('Bits', $vars, array('view' => 'graphs', 'graph' => 'macaccounting_bits')); + if ($vars['graph'] == 'macaccounting_bits') { + echo ''; + } + + echo '|'; + + if ($vars['graph'] == 'macaccounting_pkts') { + echo ""; + } + + echo generate_link('Packets', $vars, array('view' => 'graphs', 'graph' => 'macaccounting_pkts')); + if ($vars['graph'] == 'macaccounting_pkts') { + echo ''; + } + + echo ')'; + + echo '
    '; + + print_optionbar_end(); + + echo "
    Local addressPeer addressTypeFamilyRemote ASStateUptime / Updates
    " . $localaddresslink . "
    ".generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp'))."
    »" . $peeraddresslink . "$peer_type".$peer['afi']."AS" . $peer['bgpPeerRemoteAs'] . "
    " . $peer['astext'] . "
    " . $peer['bgpPeerAdminStatus'] . "
    " . $peer['bgpPeerState'] . "
    " .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
    - Updates " . format_si($peer['bgpPeerInUpdates']) . " - " . format_si($peer['bgpPeerOutUpdates']) . "
    "; + echo ''; + + if ($vars['type'] == 'external') { + $where = 'AND D.bgpLocalAs != B.bgpPeerRemoteAs'; + } + else if ($vars['type'] == 'internal') { + $where = 'AND D.bgpLocalAs = B.bgpPeerRemoteAs'; + } + + if ($vars['adminstatus'] == 'stop') { + $where .= " AND (B.bgpPeerAdminStatus = 'stop')"; + } + else if ($vars['adminstatus'] == 'start') { + $where .= " AND (B.bgpPeerAdminStatus = 'start' || B.bgpPeerAdminStatus = 'running')"; + } + + if ($vars['state'] == 'down') { + $where .= " AND (B.bgpPeerState != 'established')"; + } + + $peer_query = 'select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id '.$where.' ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier'; + foreach (dbFetchRows($peer_query) as $peer) { + unset($alert, $bg_image); + + if ($peer['bgpPeerState'] == 'established') { + $col = 'green'; + } + else { + $col = 'red'; + $peer['alert'] = 1; } - } - if ($vars['graph'] == 'updates') { $peer['graph'] = 1; } + if ($peer['bgpPeerAdminStatus'] == 'start' || $peer['bgpPeerAdminStatus'] == 'running') { + $admin_col = 'green'; + } + else { + $admin_col = 'gray'; + } - if ($peer['graph']) - { - $graph_array['height'] = "100"; - $graph_array['width'] = "218"; - $graph_array['to'] = $config['time']['now']; - echo('"); - } - } + $peerhost = dbFetchRow('SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($peer['bgpPeerIdentifier'])); - echo("
    Local addressPeer addressTypeFamilyRemote ASStateUptime / Updates
    '); + if ($peer['bgpPeerAdminStatus'] == 'stop') { + $peer['alert'] = 0; + $peer['disabled'] = 1; + } - include("includes/print-graphrow.inc.php"); + if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { + $peer_type = "iBGP"; + } + else { + $peer_type = "eBGP"; + if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { + $peer_type = "Priv eBGP"; + } + } - echo("
    "); -} + if ($peerhost) { + $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); + } + else { + unset($peername); + } + // display overlib graphs + $graph_type = 'bgp_updates'; + $local_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150&&afi=ipv4&safi=unicast'; + if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { + $peer_ip = Net_IPv6::compress($peer['bgpLocalAddr']); + } + else { + $peer_ip = $peer['bgpLocalAddr']; + } + + $localaddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer_ip.''; + + $graph_type = 'bgp_updates'; + $peer_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; + if (filter_var($peer['bgpPeerIdentifier'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { + $peer_ident = Net_IPv6::compress($peer['bgpPeerIdentifier']); + } + else { + $peer_ident = $peer['bgpPeerIdentifier']; + } + + $peeraddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer_ident.''; + + echo ''; + + unset($sep); + foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { + $afi = $afisafi['afi']; + $safi = $afisafi['safi']; + $this_afisafi = $afi.$safi; + $peer['afi'] .= $sep.$afi.'.'.$safi; + $sep = '
    '; + $peer['afisafi'][$this_afisafi] = 1; + // Build a list of valid AFI/SAFI for this peer + } + + unset($sep); + + echo ' + '.$localaddresslink.'
    '.generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')).' + » + '.$peeraddresslink." + $peer_type + ".$peer['afi'].' + AS'.$peer['bgpPeerRemoteAs'].'
    '.$peer['astext']." + ".$peer['bgpPeerAdminStatus']."
    ".$peer['bgpPeerState'].'
    + '.formatUptime($peer['bgpPeerFsmEstablishedTime'])."
    + Updates ".format_si($peer['bgpPeerInUpdates'])." + ".format_si($peer['bgpPeerOutUpdates']).''; + + unset($invalid); + switch ($vars['graph']) { + case 'prefixes_ipv4unicast': + case 'prefixes_ipv4multicast': + case 'prefixes_ipv4vpn': + case 'prefixes_ipv6unicast': + case 'prefixes_ipv6multicast': + list(,$afisafi) = explode('_', $vars['graph']); + if (isset($peer['afisafi'][$afisafi])) { + $peer['graph'] = 1; + } + + case 'updates': + $graph_array['type'] = 'bgp_'.$vars['graph']; + $graph_array['id'] = $peer['bgpPeer_id']; + } + + switch ($vars['graph']) { + case 'macaccounting_bits': + case 'macaccounting_pkts': + $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', array($peer['bgpPeerIdentifier'])); + $database = $config['rrd_dir'].'/'.$device['hostname'].'/cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'; + if (is_array($acc) && is_file($database)) { + $peer['graph'] = 1; + $graph_array['id'] = $acc['ma_id']; + $graph_array['type'] = $vars['graph']; + } + } + + if ($vars['graph'] == 'updates') { + $peer['graph'] = 1; + } + + if ($peer['graph']) { + $graph_array['height'] = '100'; + $graph_array['width'] = '218'; + $graph_array['to'] = $config['time']['now']; + echo ''; + + include 'includes/print-graphrow.inc.php'; + + echo ''; + } + }//end foreach + + echo ''; +}//end if diff --git a/html/pages/routing/overview.inc.php b/html/pages/routing/overview.inc.php index bd9a9e63e1..c16262143a 100644 --- a/html/pages/routing/overview.inc.php +++ b/html/pages/routing/overview.inc.php @@ -1,7 +1,7 @@ 'IPv4 Address', 'ipv6' => 'IPv6 Address', 'mac' => 'MAC Address', 'arp' => 'ARP Table'); +$sections = array( + 'ipv4' => 'IPv4 Address', + 'ipv6' => 'IPv6 Address', + 'mac' => 'MAC Address', + 'arp' => 'ARP Table', +); -if( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) { - $sections['packages'] = 'Packages'; +if (dbFetchCell('SELECT 1 from `packages` LIMIT 1')) { + $sections['packages'] = 'Packages'; } -if (!isset($vars['search'])) { $vars['search'] = "ipv4"; } +if (!isset($vars['search'])) { + $vars['search'] = 'ipv4'; +} print_optionbar_start('', ''); - echo('Search » '); +echo 'Search » '; unset($sep); -foreach ($sections as $type => $texttype) -{ - echo($sep); - if ($vars['search'] == $type) - { - echo(""); - } +foreach ($sections as $type => $texttype) { + echo $sep; + if ($vars['search'] == $type) { + echo ""; + } -# echo('' . $texttype .''); - echo(generate_link($texttype, array('page'=>'search','search'=>$type))); + // echo('' . $texttype .''); + echo generate_link($texttype, array('page' => 'search', 'search' => $type)); - if ($vars['search'] == $type) { echo(""); } + if ($vars['search'] == $type) { + echo ''; + } - $sep = ' | '; + $sep = ' | '; } -unset ($sep); + +unset($sep); print_optionbar_end('', ''); -if( file_exists('pages/search/'.$vars['search'].'.inc.php') ) { - include('pages/search/'.$vars['search'].'.inc.php'); -} else { - echo(report_this('Unknown search type '.$vars['search'])); +if (file_exists('pages/search/'.$vars['search'].'.inc.php')) { + include 'pages/search/'.$vars['search'].'.inc.php'; +} +else { + echo report_this('Unknown search type '.$vars['search']); } - -?> diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index a4dcbd1136..45cd6888a9 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -30,21 +30,22 @@ var grid = $("#arp-search").bootgrid({ '.$data['hostname'].'"+'); + + echo '">'.$data['hostname'].'"+'; } ?> ""+ @@ -53,18 +54,16 @@ foreach (dbFetchRows($sql,$param) as $data) { " "\" class=\"form-control input-sm\" placeholder=\"Address\" />"+ diff --git a/html/pages/search/ipv4.inc.php b/html/pages/search/ipv4.inc.php index e2ea785c07..843acbd1bc 100644 --- a/html/pages/search/ipv4.inc.php +++ b/html/pages/search/ipv4.inc.php @@ -27,22 +27,23 @@ var grid = $("#ipv4-search").bootgrid({ ""+ '.$data['hostname'].'"+'); + + echo '">'.$data['hostname'].'"+'; } ?> ""+ @@ -52,18 +53,16 @@ foreach (dbFetchRows($sql,$param) as $data) { ""+ ""+ "
     "+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ "
     "+ ""+ "
    "+ diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php index 8ab58d9fff..2b9115013d 100644 --- a/html/pages/search/ipv6.inc.php +++ b/html/pages/search/ipv6.inc.php @@ -26,22 +26,23 @@ var grid = $("#ipv6-search").bootgrid({ ""+ '.$data['hostname'].'"+'); + + echo '">'.$data['hostname'].'"+'; } ?> ""+ @@ -51,9 +52,8 @@ foreach (dbFetchRows($sql,$param) as $data) { ""+ ""+ "
    "+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ "
    "+ ""+ "
    "+ diff --git a/html/pages/search/mac.inc.php b/html/pages/search/mac.inc.php index c040a1e16a..f606e4436a 100644 --- a/html/pages/search/mac.inc.php +++ b/html/pages/search/mac.inc.php @@ -26,21 +26,22 @@ var grid = $("#mac-search").bootgrid({ ""+ @@ -50,17 +51,15 @@ foreach (dbFetchRows($sql,$param) as $data) { ""+ ""+ "
    0) { + +if(isset($_POST['results_amount']) && $_POST['results_amount'] > 0) { $results = $_POST['results']; -} -else { +} else { $results = 50; } @@ -34,49 +34,37 @@ echo '
    '; if ($_SESSION['userlevel'] >= '10') { - echo ''; + echo(''); } echo ' '); -echo ''; +$count_query = "SELECT COUNT(id)"; +$full_query = "SELECT *"; -$count_query = 'SELECT COUNT(id)'; -$full_query = 'SELECT *'; +$query = " FROM `alert_templates`"; -$query = ' FROM `alert_templates`'; - -$count_query = $count_query.$query; -$count = dbFetchCell($count_query, $param); -if (!isset($_POST['page_number']) && $_POST['page_number'] < 1) { +$count_query = $count_query . $query; +$count = dbFetchCell($count_query,$param); +if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { $page_number = 1; -} -else { +} else { $page_number = $_POST['page_number']; } +$start = ($page_number - 1) * $results; +$full_query = $full_query . $query . " LIMIT $start,$results"; -$start = (($page_number - 1) * $results); -$full_query = $full_query.$query." LIMIT $start,$results"; - -foreach (dbFetchRows($full_query, $param) as $template) { +foreach( dbFetchRows($full_query, $param) as $template ) { echo ' '.$template['name'].' '; @@ -85,15 +73,14 @@ foreach (dbFetchRows($full_query, $param) as $template) { echo " "; echo ""; } - echo ' '; } -if (($count % $results) > 0) { - echo ' - '.generate_pagination($count, $results, $page_number).' - '; +if($count % $results > 0) { + echo(' + '. generate_pagination($count,$results,$page_number) .' + '); } echo ' diff --git a/html/includes/print-alerts.inc.php b/html/includes/print-alerts.inc.php index d9758a0f38..dcbab4b3d9 100644 --- a/html/includes/print-alerts.inc.php +++ b/html/includes/print-alerts.inc.php @@ -1,49 +1,49 @@ - - '.$alert_entry['time_logged'].' - '; +echo(' + + ' . $alert_entry['time_logged'] . ' + '); if (!isset($alert_entry['device'])) { - $dev = device_by_id_cache($alert_entry['device_id']); - echo ' - '.generate_device_link($dev, shorthost($dev['hostname'])).' - '; + $dev = device_by_id_cache($alert_entry['device_id']); + echo(" + " . generate_device_link($dev, shorthost($dev['hostname'])) . " + "); } -echo ''.htmlspecialchars($alert_entry['name']).''; +echo("".htmlspecialchars($alert_entry['name']) . ""); -if ($alert_state != '') { - if ($alert_state == '0') { - $glyph_icon = 'ok'; +if ($alert_state!='') { + if ($alert_state=='0') { + $glyph_icon = 'ok'; $glyph_color = 'green'; - $text = 'Ok'; + $text = 'Ok'; } - else if ($alert_state == '1') { - $glyph_icon = 'remove'; + elseif ($alert_state=='1') { + $glyph_icon = 'remove'; $glyph_color = 'red'; - $text = 'Alert'; + $text = 'Alert'; } - else if ($alert_state == '2') { - $glyph_icon = 'info-sign'; + elseif ($alert_state=='2') { + $glyph_icon = 'info-sign'; $glyph_color = 'lightgrey'; - $text = 'Ack'; + $text = 'Ack'; } - else if ($alert_state == '3') { - $glyph_icon = 'arrow-down'; + elseif ($alert_state=='3') { + $glyph_icon = 'arrow-down'; $glyph_color = 'orange'; - $text = 'Worse'; + $text = 'Worse'; } - else if ($alert_state == '4') { - $glyph_icon = 'arrow-up'; + elseif ($alert_state=='4') { + $glyph_icon = 'arrow-up'; $glyph_color = 'khaki'; - $text = 'Better'; - }//end if - echo " $text"; -}//end if + $text = 'Better'; + } + echo(" $text"); +} -echo ''; +echo(""); diff --git a/html/includes/print-debug.php b/html/includes/print-debug.php index 7fdbbcc6d9..f35cd05bfe 100644 --- a/html/includes/print-debug.php +++ b/html/includes/print-debug.php @@ -1,6 +1,6 @@ @@ -14,23 +14,25 @@ @@ -50,25 +52,26 @@ foreach ($sql_debug as $sql_error) { @@ -95,12 +97,10 @@ if ($_SESSION['userlevel'] >= '10') { if (is_admin() === TRUE || is_read() === TRUE) { $sql = "SELECT `type`,COUNT(`type`) AS total_type FROM `devices` AS D WHERE 1 GROUP BY `type` ORDER BY `type`"; -} -else { +} else { $sql = "SELECT `type`,COUNT(`type`) AS total_type FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `type` ORDER BY `type`"; $param[] = $_SESSION['user_id']; } - foreach (dbFetchRows($sql,$param) as $devtype) { if (empty($devtype['type'])) { $devtype['type'] = 'generic'; @@ -108,10 +108,9 @@ foreach (dbFetchRows($sql,$param) as $devtype) { echo('
  • ' . ucfirst($devtype['type']) . '
  • '); } -require_once '../includes/device-groups.inc.php'; - +require_once('../includes/device-groups.inc.php'); foreach( GetDeviceGroups() as $group ) { - echo '
  • '.ucfirst($group['name']).'
  • '; + echo '
  • '.ucfirst($group['name']).'
  • '; } unset($group); @@ -119,24 +118,29 @@ unset($group); '); if ($_SESSION['userlevel'] >= '10') { - if ($config['show_locations']) { - echo(' +if ($config['show_locations']) +{ + + echo(' - '); + Locations + + + '); +} + echo('
  • Manage Groups
  • Add Device
  • @@ -151,7 +155,8 @@ if ($_SESSION['userlevel'] >= '10') {
  • Alerts ('.$service_alerts.')
  • '); } -if ($_SESSION['userlevel'] >= '10') { - echo(' +if ($_SESSION['userlevel'] >= '10') +{ + echo('
  • Add Service
  • Edit Service
  • @@ -190,53 +197,36 @@ if ($_SESSION['userlevel'] >= '10') { 0) { - echo('
  • Errored ('.$ports['errored'].')
  • '); +if ($ports['errored'] > 0) +{ + echo('
  • Errored ('.$ports['errored'].')
  • '); } -if ($ports['ignored'] > 0) { - echo('
  • Ignored ('.$ports['ignored'].')
  • '); +if ($ports['ignored'] > 0) +{ + echo('
  • Ignored ('.$ports['ignored'].')
  • '); } if ($config['enable_billing']) { - echo('
  • Traffic Bills
  • '); - $ifbreak = 1; + echo('
  • Traffic Bills
  • '); $ifbreak = 1; } if ($config['enable_pseudowires']) { - echo('
  • Pseudowires
  • '); - $ifbreak = 1; + echo('
  • Pseudowires
  • '); $ifbreak = 1; } ?> = '5') { - echo(' '); - if ($config['int_customers']) { - echo('
  • Customers
  • '); - $ifbreak = 1; - } - if ($config['int_l2tp']) { - echo('
  • L2TP
  • '); - $ifbreak = 1; - } - if ($config['int_transit']) { - echo('
  • Transit
  • '); - $ifbreak = 1; - } - if ($config['int_peering']) { - echo('
  • Peering
  • '); - $ifbreak = 1; - } - if ($config['int_peering'] && $config['int_transit']) { - echo('
  • Peering + Transit
  • '); - $ifbreak = 1; - } - if ($config['int_core']) { - echo('
  • Core
  • '); - $ifbreak = 1; - } +if ($_SESSION['userlevel'] >= '5') +{ + echo(' '); + if ($config['int_customers']) { echo('
  • Customers
  • '); $ifbreak = 1; } + if ($config['int_l2tp']) { echo('
  • L2TP
  • '); $ifbreak = 1; } + if ($config['int_transit']) { echo('
  • Transit
  • '); $ifbreak = 1; } + if ($config['int_peering']) { echo('
  • Peering
  • '); $ifbreak = 1; } + if ($config['int_peering'] && $config['int_transit']) { echo('
  • Peering + Transit
  • '); $ifbreak = 1; } + if ($config['int_core']) { echo('
  • Core
  • '); $ifbreak = 1; } if (is_array($config['custom_descr']) === FALSE) { $config['custom_descr'] = array($config['custom_descr']); } @@ -249,18 +239,21 @@ if ($_SESSION['userlevel'] >= '5') { } if ($ifbreak) { - echo(' '); + echo(' '); } -if (isset($interface_alerts)) { - echo('
  • Alerts ('.$interface_alerts.')
  • '); +if (isset($interface_alerts)) +{ + echo('
  • Alerts ('.$interface_alerts.')
  • '); } $deleted_ports = 0; -foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) { - if (port_permitted($interface['port_id'], $interface['device_id'])) { - $deleted_ports++; - } +foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) +{ + if (port_permitted($interface['port_id'], $interface['device_id'])) + { + $deleted_ports++; + } } ?> @@ -268,9 +261,7 @@ foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`delete
  • Disabled
  • Deleted ('.$deleted_ports.')'); -} +if ($deleted_ports) { echo('
  • Deleted ('.$deleted_ports.')
  • '); } ?> @@ -279,8 +270,9 @@ if ($deleted_ports) { Processor
  • Storage
  • '); +if ($menu_sensors) +{ + $sep = 0; + echo(' '); } $icons = array('fanspeed'=>'tachometer','humidity'=>'tint','temperature'=>'fire','current'=>'bolt','frequency'=>'line-chart','power'=>'power-off','voltage'=>'bolt','charge'=>'plus-square','dbm'=>'sun-o', 'load'=>'spinner','state'=>'bullseye'); -foreach (array('fanspeed','humidity','temperature') as $item) { - if (isset($menu_sensors[$item])) { - echo('
  • '.nicecase($item).'
  • '); - unset($menu_sensors[$item]);$sep++; - } -} - -if ($sep && array_keys($menu_sensors)) { - echo(' '); - $sep = 0; -} - -foreach (array('current','frequency','power','voltage') as $item) { - if (isset($menu_sensors[$item])) { - echo('
  • '.nicecase($item).'
  • '); - unset($menu_sensors[$item]);$sep++; - } -} - -if ($sep && array_keys($menu_sensors)) { - echo(' '); - $sep = 0; -} - -foreach (array_keys($menu_sensors) as $item) { +foreach (array('fanspeed','humidity','temperature') as $item) +{ + if (isset($menu_sensors[$item])) + { echo('
  • '.nicecase($item).'
  • '); unset($menu_sensors[$item]);$sep++; + } +} + +if ($sep && array_keys($menu_sensors)) +{ + echo(' '); + $sep = 0; +} + +foreach (array('current','frequency','power','voltage') as $item) +{ + if (isset($menu_sensors[$item])) + { + echo('
  • '.nicecase($item).'
  • '); + unset($menu_sensors[$item]);$sep++; + } +} + +if ($sep && array_keys($menu_sensors)) +{ + echo(' '); + $sep = 0; +} + +foreach (array_keys($menu_sensors) as $item) +{ + echo('
  • '.nicecase($item).'
  • '); + unset($menu_sensors[$item]);$sep++; } ?> @@ -337,24 +337,27 @@ foreach (array_keys($menu_sensors) as $item) { $app_count = dbFetchCell("SELECT COUNT(`app_id`) FROM `applications`"); -if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") { +if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") +{ ?> + = '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") { +if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") +{ ?> @@ -427,11 +440,16 @@ if ( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) { = '10') { - if (dbFetchCell("SELECT COUNT(*) from `plugins` WHERE plugin_active = '1'") > 0) { - echo(''); - } - echo('
  • Plugin Admin
  • '); +if ($_SESSION['userlevel'] >= '10') +{ + if (dbFetchCell("SELECT COUNT(*) from `plugins` WHERE plugin_active = '1'") > 0) { + echo(' + + '); + } + echo(' +
  • Plugin Admin
  • + '); } ?> @@ -439,8 +457,9 @@ if ($_SESSION['userlevel'] >= '10') { @@ -457,42 +476,50 @@ if(is_file("includes/print-menubar-custom.inc.php")) {
    -"; +"); \ No newline at end of file diff --git a/html/includes/print-service-edit.inc.php b/html/includes/print-service-edit.inc.php index d0ad23a569..0954649d6d 100644 --- a/html/includes/print-service-edit.inc.php +++ b/html/includes/print-service-edit.inc.php @@ -1,33 +1,35 @@ Edit Service
    - - + +
    - +
    - +
    - +
    -
    "; -}//end if +"); + +} \ No newline at end of file diff --git a/html/includes/print-syslog.inc.php b/html/includes/print-syslog.inc.php index 1a7564920d..09467dd7c4 100644 --- a/html/includes/print-syslog.inc.php +++ b/html/includes/print-syslog.inc.php @@ -1,18 +1,23 @@ '; +if (device_permitted($entry['device_id'])) +{ + echo(""); - // Stop shortening hostname. Issue #61 - // $entry['hostname'] = shorthost($entry['hostname'], 20); - if ($vars['page'] != 'device') { - echo ''.$entry['date'].''; - echo ''.generate_device_link($entry).''; - echo ''.$entry['program'].' : '.htmlspecialchars($entry['msg']).''; - } - else { - echo ''.$entry['date'].'   '.$entry['program'].'   '.htmlspecialchars($entry['msg']).''; - } + // Stop shortening hostname. Issue #61 + //$entry['hostname'] = shorthost($entry['hostname'], 20); + + if ($vars['page'] != "device") + { + echo("" . $entry['date'] . ""); + echo("".generate_device_link($entry).""); + echo("" . $entry['program'] . " : " . htmlspecialchars($entry['msg']) . ""); + } else { + echo("" . $entry['date'] . "   " . $entry['program'] . "   " . htmlspecialchars($entry['msg']) . ""); + } + + echo(""); - echo ''; } + +?> diff --git a/html/includes/reports/alert-log.pdf.inc.php b/html/includes/reports/alert-log.pdf.inc.php index d293b474b9..5ee0e91ea1 100644 --- a/html/includes/reports/alert-log.pdf.inc.php +++ b/html/includes/reports/alert-log.pdf.inc.php @@ -1,83 +1,65 @@ AddPage('L'); -$where = '1'; -if (is_numeric($_GET['device_id'])) { - $where .= ' AND E.device_id = ?'; - $param[] = $_GET['device_id']; -} -if ($_GET['string']) { - $where .= ' AND R.rule LIKE ?'; - $param[] = '%'.$_GET['string'].'%'; -} + $where = "1"; + if (is_numeric($_GET['device_id'])) { + $where .= ' AND E.device_id = ?'; + $param[] = $_GET['device_id']; + } + if ($_GET['string']) { + $where .= " AND R.rule LIKE ?"; + $param[] = "%".$_GET['string']."%"; + } -if ($_SESSION['userlevel'] >= '5') { - $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where ORDER BY `humandate` DESC"; -} -else { - $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? ORDER BY `humandate` DESC"; - $param[] = $_SESSION['user_id']; -} + if ($_SESSION['userlevel'] >= '5') { + $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where ORDER BY `humandate` DESC"; + } else { + $query = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ? ORDER BY `humandate` DESC"; + $param[] = $_SESSION['user_id']; + } -if (isset($_GET['start']) && is_numeric($_GET['start'])) { - $start = mres($_GET['start']); -} -else { - $start = 0; -} + if (isset($_GET['start']) && is_numeric($_GET['start'])) { + $start = mres($_GET['start']); + } else { + $start = 0; + } -if (isset($_GET['results']) && is_numeric($_GET['results'])) { - $numresults = mres($_GET['results']); -} -else { - $numresults = 250; -} + if (isset($_GET['results']) && is_numeric($_GET['results'])) { + $numresults = mres($_GET['results']); + } else { + $numresults = 250; + } -$full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults"; + $full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults"; -foreach (dbFetchRows($full_query, $param) as $alert_entry) { - $hostname = gethostbyid(mres($alert_entry['device_id'])); - $alert_state = $alert_entry['state']; + foreach (dbFetchRows($full_query, $param) as $alert_entry) { + $hostname = gethostbyid(mres($alert_entry['device_id'])); + $alert_state = $alert_entry['state']; - if ($alert_state != '') { - if ($alert_state == '0') { - $glyph_color = 'green'; - $text = 'Ok'; - } - else if ($alert_state == '1') { - $glyph_color = 'red'; - $text = 'Alert'; - } - else if ($alert_state == '2') { - $glyph_color = 'lightgrey'; - $text = 'Ack'; - } - else if ($alert_state == '3') { - $glyph_color = 'orange'; - $text = 'Worse'; - } - else if ($alert_state == '4') { - $glyph_color = 'khaki'; - $text = 'Better'; + if ($alert_state!='') { + if ($alert_state=='0') { + $glyph_color = 'green'; + $text = 'Ok'; + } elseif ($alert_state=='1') { + $glyph_color = 'red'; + $text = 'Alert'; + } elseif ($alert_state=='2') { + $glyph_color = 'lightgrey'; + $text = 'Ack'; + } elseif ($alert_state=='3') { + $glyph_color = 'orange'; + $text = 'Worse'; + } elseif ($alert_state=='4') { + $glyph_color = 'khaki'; + $text = 'Better'; + } + $data[] = array($alert_entry['time_logged'],$hostname,htmlspecialchars($alert_entry['name']),$text); } + } - $data[] = array( - $alert_entry['time_logged'], - $hostname, - htmlspecialchars($alert_entry['name']), - $text, - ); - }//end if -}//end foreach - -$header = array( - 'Datetime', - 'Device', - 'Log', - 'Status', -); +$header = array('Datetime', 'Device', 'Log', 'Status'); $table = << @@ -92,19 +74,17 @@ EOD; foreach ($data as $log) { if ($log[3] == 'Alert') { $tr_col = '#d39392'; - } - else { + } else { $tr_col = '#bbd392'; } - $table .= ' - + '.$log[0].' '.$log[1].' '.$log[2].' '.$log[3].' - - '; + + '; } $table .= << $value) { - if ($value != '') { - switch ($var) { - case 'hostname': - $where .= ' AND D.hostname LIKE ?'; - $param[] = '%'.$value.'%'; - break; +foreach ($vars as $var => $value) +{ + if ($value != "") + { + switch ($var) + { + case 'hostname': + $where .= " AND D.hostname LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'location': + $where .= " AND D.location LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'device_id': + $where .= " AND D.device_id = ?"; + $param[] = $value; + break; + case 'deleted': + case 'ignore': + if ($value == 1) + { + $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; + } + break; + case 'disable': + case 'ifSpeed': + if (is_numeric($value)) + { + $where .= " AND I.$var = ?"; + $param[] = $value; + } + break; + case 'ifType': + $where .= " AND I.$var = ?"; + $param[] = $value; + break; + case 'ifAlias': + case 'port_descr_type': + $where .= " AND I.$var LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'errors': + if ($value == 1) + { + $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; + } + break; + case 'state': + if ($value == "down") + { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; + $param[] = "up"; + $param[] = "down"; + } elseif($value == "up") { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; + $param[] = "up"; + $param[] = "up"; + } elseif($value == "admindown") { + $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; + $param[] = "down"; + } + break; + } + } +} - case 'location': - $where .= ' AND D.location LIKE ?'; - $param[] = '%'.$value.'%'; - break; - - case 'device_id': - $where .= ' AND D.device_id = ?'; - $param[] = $value; - break; - - case 'deleted': - case 'ignore': - if ($value == 1) { - $where .= ' AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0'; - } - break; - - case 'disable': - case 'ifSpeed': - if (is_numeric($value)) { - $where .= " AND I.$var = ?"; - $param[] = $value; - } - break; - - case 'ifType': - $where .= " AND I.$var = ?"; - $param[] = $value; - break; - - case 'ifAlias': - case 'port_descr_type': - $where .= " AND I.$var LIKE ?"; - $param[] = '%'.$value.'%'; - break; - - case 'errors': - if ($value == 1) { - $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; - } - break; - - case 'state': - if ($value == 'down') { - $where .= 'AND I.ifAdminStatus = ? AND I.ifOperStatus = ?'; - $param[] = 'up'; - $param[] = 'down'; - } - else if ($value == 'up') { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; - $param[] = 'up'; - $param[] = 'up'; - } - else if ($value == 'admindown') { - $where .= 'AND I.ifAdminStatus = ? AND D.ignore = 0'; - $param[] = 'down'; - } - break; - }//end switch - }//end if -}//end foreach - -$query = 'SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id '.$where.' '.$query_sort; +$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ".$where." ".$query_sort; $row = 1; -list($format, $subformat) = explode('_', $vars['format']); +list($format, $subformat) = explode("_", $vars['format']); $ports = dbFetchRows($query, $param); -switch ($vars['sort']) { -case 'traffic': +switch ($vars['sort']) +{ + case 'traffic': $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); break; - -case 'traffic_in': + case 'traffic_in': $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); break; - -case 'traffic_out': + case 'traffic_out': $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); break; - -case 'packets': + case 'packets': $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); break; - -case 'packets_in': + case 'packets_in': $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); break; - -case 'packets_out': + case 'packets_out': $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); break; - -case 'errors': + case 'errors': $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); break; - -case 'speed': + case 'speed': $ports = array_sort($ports, 'ifSpeed', SORT_DESC); break; - -case 'port': + case 'port': $ports = array_sort($ports, 'ifDescr', SORT_ASC); break; - -case 'media': + case 'media': $ports = array_sort($ports, 'ifType', SORT_ASC); break; - -case 'descr': + case 'descr': $ports = array_sort($ports, 'ifAlias', SORT_ASC); break; - -case 'device': -default: + case 'device': + default: $ports = array_sort($ports, 'hostname', SORT_ASC); -}//end switch - -$csv[] = array( - 'Device', - 'Port', - 'Speed', - 'Down', - 'Up', - 'Media', - 'Description', -); -foreach ($ports as $port) { - if (port_permitted($port['port_id'], $port['device_id'])) { - $speed = humanspeed($port['ifSpeed']); - $type = humanmedia($port['ifType']); - $port['in_rate'] = formatRates(($port['ifInOctets_rate'] * 8)); - $port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8)); - $port = ifLabel($port, $device); - $csv[] = array( - $port['hostname'], - fixIfName($port['label']), - $speed, - $port['in_rate'], - $port['out_rate'], - $type, - $port['ifAlias'], - ); - } } + +$csv[] = array('Device','Port','Speed','Down','Up','Media','Description'); +foreach( $ports as $port ) { + if( port_permitted($port['port_id'], $port['device_id']) ) { + $speed = humanspeed($port['ifSpeed']); + $type = humanmedia($port['ifType']); + $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); + $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); + $port = ifLabel($port, $device); + $csv[] = array($port['hostname'],fixIfName($port['label']),$speed,$port['in_rate'],$port['out_rate'],$type,$port['ifAlias']); + } +} +?> diff --git a/html/includes/service-add.inc.php b/html/includes/service-add.inc.php index cf1433b274..3bc9eca630 100644 --- a/html/includes/service-add.inc.php +++ b/html/includes/service-add.inc.php @@ -5,6 +5,6 @@ $updated = '1'; $service_id = add_service(mres($_POST['device']), mres($_POST['type']), mres($_POST['descr']), mres($_POST['ip']), mres($_POST['params'])); if ($service_id) { - $message .= $message_break.'Service added ('.$service_id.')!'; - $message_break .= '
    '; -} + $message .= $message_break . "Service added (".$service_id.")!"; + $message_break .= "
    "; +} \ No newline at end of file diff --git a/html/includes/table/address-search.inc.php b/html/includes/table/address-search.inc.php index 25eb75360e..a50d06afc7 100644 --- a/html/includes/table/address-search.inc.php +++ b/html/includes/table/address-search.inc.php @@ -2,64 +2,56 @@ $param = array(); -if (is_admin() === false && is_read() === false) { - $perms_sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`'; - $where .= ' AND `DP`.`user_id`=?'; - $param[] = array($_SESSION['user_id']); +if (is_admin() === FALSE && is_read() === FALSE) { + $perms_sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`"; + $where .= " AND `DP`.`user_id`=?"; + $param[] = array($_SESSION['user_id']); } -list($address,$prefix) = explode('/', $_POST['address']); +list($address,$prefix) = explode("/", $_POST['address']); if ($_POST['search_type'] == 'ipv4') { - $sql = ' FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D'; + $sql = " FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D"; $sql .= $perms_sql; $sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id $where "; if (!empty($address)) { $sql .= " AND ipv4_address LIKE '%".$address."%'"; } - if (!empty($prefix)) { - $sql .= " AND ipv4_prefixlen='?'"; + $sql .= " AND ipv4_prefixlen='?'"; $param[] = array($prefix); } -} -else if ($_POST['search_type'] == 'ipv6') { - $sql = ' FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D'; +} elseif ($_POST['search_type'] == 'ipv6') { + $sql = " FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D"; $sql .= $perms_sql; $sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id $where "; if (!empty($address)) { $sql .= " AND (ipv6_address LIKE '%".$address."%' OR ipv6_compressed LIKE '%".$address."%')"; } - if (!empty($prefix)) { $sql .= " AND ipv6_prefixlen = '$prefix'"; } -} -else if ($_POST['search_type'] == 'mac') { - $sql = ' FROM `ports` AS I, `devices` AS D'; +} elseif ($_POST['search_type'] == 'mac') { + $sql = " FROM `ports` AS I, `devices` AS D"; $sql .= $perms_sql; - $sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address']))."%' $where "; -}//end if + $sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%' $where "; +} if (is_numeric($_POST['device_id'])) { - $sql .= ' AND I.device_id = ?'; + $sql .= " AND I.device_id = ?"; $param[] = array($_POST['device_id']); } - if ($_POST['interface']) { - $sql .= " AND I.ifDescr LIKE '?'"; + $sql .= " AND I.ifDescr LIKE '?'"; $param[] = array($_POST['interface']); } if ($_POST['search_type'] == 'ipv4') { $count_sql = "SELECT COUNT(`ipv4_address_id`) $sql"; -} -else if ($_POST['search_type'] == 'ipv6') { +} elseif ($_POST['search_type'] == 'ipv6') { $count_sql = "SELECT COUNT(`ipv6_address_id`) $sql"; +} elseif ($_POST['search_type'] == 'mac') { + $count_sql = "SELECT COUNT(`port_id`) $sql"; } -else if ($_POST['search_type'] == 'mac') { - $count_sql = "SELECT COUNT(`port_id`) $sql"; -} - -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -71,7 +63,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -83,42 +75,31 @@ $sql = "SELECT *,`I`.`ifDescr` AS `interface` $sql"; foreach (dbFetchRows($sql, $param) as $interface) { $speed = humanspeed($interface['ifSpeed']); - $type = humanmedia($interface['ifType']); + $type = humanmedia($interface['ifType']); if ($_POST['search_type'] == 'ipv6') { - list($prefix, $length) = explode('/', $interface['ipv6_network']); - $address = Net_IPv6::compress($interface['ipv6_address']).'/'.$length; - } - else if ($_POST['search_type'] == 'mac') { + list($prefix, $length) = explode("/", $interface['ipv6_network']); + $address = Net_IPv6::compress($interface['ipv6_address']) . '/'.$length; + } elseif ($_POST['search_type'] == 'mac') { $address = formatMac($interface['ifPhysAddress']); - } - else { - list($prefix, $length) = explode('/', $interface['ipv4_network']); - $address = $interface['ipv4_address'].'/'.$length; + } else { + list($prefix, $length) = explode("/", $interface['ipv4_network']); + $address = $interface['ipv4_address'] . '/' .$length; } if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { - $error_img = generate_port_link($interface, "Interface Errors", errors); + $error_img = generate_port_link($interface,"Interface Errors",errors); + } else { + $error_img = ""; } - else { - $error_img = ''; - } - if (port_permitted($interface['port_id'])) { - $interface = ifLabel($interface, $interface); - $response[] = array( - 'hostname' => generate_device_link($interface), - 'interface' => generate_port_link($interface).' '.$error_img, - 'address' => $address, - 'description' => $interface['ifAlias'], - ); + $interface = ifLabel ($interface, $interface); + $response[] = array('hostname'=>generate_device_link($interface), + 'interface'=>generate_port_link($interface) . ' ' . $error_img, + 'address'=>$address, + 'description'=>$interface['ifAlias']); } -}//end foreach +} -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); diff --git a/html/includes/table/alert-schedule.inc.php b/html/includes/table/alert-schedule.inc.php index 5d2bfa9b89..635e67be92 100644 --- a/html/includes/table/alert-schedule.inc.php +++ b/html/includes/table/alert-schedule.inc.php @@ -16,9 +16,8 @@ $where = 1; if ($_SESSION['userlevel'] >= '5') { $sql = " FROM `alert_schedule` AS S WHERE $where"; -} -else { - $sql = " FROM `alert_schedule` AS S WHERE $where"; +} else { + $sql = " FROM `alert_schedule` AS S WHERE $where"; $param[] = $_SESSION['user_id']; } @@ -27,7 +26,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(`id`) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -39,7 +38,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -49,29 +48,20 @@ if ($rowCount != -1) { $sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '".$config['dateformat']['mysql']['compact']."') AS `start`, DATE_FORMAT(`S`.`end`, '".$config['dateformat']['mysql']['compact']."') AS `end`, `S`.`title` $sql"; -foreach (dbFetchRows($sql, $param) as $schedule) { +foreach (dbFetchRows($sql,$param) as $schedule) { $status = 0; if ($schedule['end'] < date('dS M Y H:i::s')) { $status = 1; } - if (date('dS M Y H:i::s') >= $schedule['start'] && date('dS M Y H:i::s') < $schedule['end']) { $status = 2; } - - $response[] = array( - 'title' => $schedule['title'], - 'start' => $schedule['start'], - 'end' => $schedule['end'], - 'id' => $schedule['schedule_id'], - 'status' => $status, - ); + $response[] = array('title'=>$schedule['title'], + 'start'=>$schedule['start'], + 'end'=>$schedule['end'], + 'id'=>$schedule['schedule_id'], + 'status'=>$status); } -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); diff --git a/html/includes/table/alertlog.inc.php b/html/includes/table/alertlog.inc.php index 8b4d94d3e2..0c8e515e62 100644 --- a/html/includes/table/alertlog.inc.php +++ b/html/includes/table/alertlog.inc.php @@ -3,15 +3,14 @@ $where = 1; if (is_numeric($_POST['device_id'])) { - $where .= ' AND E.device_id = ?'; + $where .= ' AND E.device_id = ?'; $param[] = $_POST['device_id']; } if ($_SESSION['userlevel'] >= '5') { $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where"; -} -else { - $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?"; +} else { + $sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?"; $param[] = array($_SESSION['user_id']); } @@ -20,7 +19,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(`E`.`id`) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -32,7 +31,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -43,49 +42,42 @@ if ($rowCount != -1) { $sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql"; $rulei = 0; -foreach (dbFetchRows($sql, $param) as $alertlog) { - $dev = device_by_id_cache($alertlog['device_id']); +foreach (dbFetchRows($sql,$param) as $alertlog) { + $dev = device_by_id_cache($alertlog['device_id']); $fault_detail = alert_details($alertlog['details']); - $alert_state = $alertlog['state']; - if ($alert_state == '0') { - $glyph_icon = 'ok'; + $alert_state = $alertlog['state']; + if ($alert_state=='0') { + $glyph_icon = 'ok'; $glyph_color = 'green'; - $text = 'Ok'; + $text = 'Ok'; } - else if ($alert_state == '1') { - $glyph_icon = 'remove'; + elseif ($alert_state=='1') { + $glyph_icon = 'remove'; $glyph_color = 'red'; - $text = 'Alert'; + $text = 'Alert'; } - else if ($alert_state == '2') { - $glyph_icon = 'info-sign'; + elseif ($alert_state=='2') { + $glyph_icon = 'info-sign'; $glyph_color = 'lightgrey'; - $text = 'Ack'; + $text = 'Ack'; } - else if ($alert_state == '3') { - $glyph_icon = 'arrow-down'; + elseif ($alert_state=='3') { + $glyph_icon = 'arrow-down'; $glyph_color = 'orange'; - $text = 'Worse'; + $text = 'Worse'; } - else if ($alert_state == '4') { - $glyph_icon = 'arrow-up'; + elseif ($alert_state=='4') { + $glyph_icon = 'arrow-up'; $glyph_color = 'khaki'; - $text = 'Better'; - }//end if - $response[] = array( - 'id' => $rulei++, - 'time_logged' => $alertlog['humandate'], - 'details' => '', - 'hostname' => '
    '.generate_device_link($dev, shorthost($dev['hostname'])).'
    '.$fault_detail.'
    ', - 'alert' => htmlspecialchars($alertlog['alert']), - 'status' => " $text", - ); -}//end foreach + $text = 'Better'; + } + $response[] = array('id'=>$rulei++, + 'time_logged'=>$alertlog['humandate'], + 'details'=>'', + 'hostname'=>'
    '.generate_device_link($dev, shorthost($dev['hostname'])).'
    '.$fault_detail.'
    ', + 'alert'=>htmlspecialchars($alertlog['alert']), + 'status'=>" $text"); +} -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); -echo _json_encode($output); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +echo _json_encode($output); diff --git a/html/includes/table/alerts.inc.php b/html/includes/table/alerts.inc.php index 2efab5d1f1..799404b1a4 100644 --- a/html/includes/table/alerts.inc.php +++ b/html/includes/table/alerts.inc.php @@ -10,18 +10,18 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { $sql_search .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')"; } -$sql = ' FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`'; +$sql = " FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`"; -if (is_admin() === false && is_read() === false) { - $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`'; - $where .= ' AND `DP`.`user_id`=?'; +if (is_admin() === FALSE && is_read() === FALSE) { + $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`"; + $where .= " AND `DP`.`user_id`=?"; $param[] = $_SESSION['user_id']; } $sql .= " RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE $where AND `state` IN (1,2,3,4) $sql_search"; $count_sql = "SELECT COUNT(`alerts`.`id`) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -33,7 +33,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -43,86 +43,76 @@ if ($rowCount != -1) { $sql = "SELECT `alerts`.*, `devices`.`hostname` AS `hostname`,`alert_rules`.`rule` AS `rule`, `alert_rules`.`name` AS `name`, `alert_rules`.`severity` AS `severity` $sql"; -$rulei = 0; +$rulei = 0; $format = $_POST['format']; -foreach (dbFetchRows($sql, $param) as $alert) { - $log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id'])); +foreach (dbFetchRows($sql,$param) as $alert) { + $log = dbFetchCell("SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1", array($alert['rule_id'],$alert['device_id'])); $fault_detail = alert_details($log); - $ico = 'ok'; - $col = 'green'; - $extra = ''; - $msg = ''; - if ((int) $alert['state'] === 0) { - $ico = 'ok'; - $col = 'green'; - $extra = 'success'; - $msg = 'ok'; - } - else if ((int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) { - $ico = 'volume-up'; - $col = 'red'; - $extra = 'danger'; - $msg = 'alert'; - if ((int) $alert['state'] === 3) { - $msg = 'worse'; - } - else if ((int) $alert['state'] === 4) { - $msg = 'better'; + $ico = "ok"; + $col = "green"; + $extra = ""; + $msg = ""; + if ( (int) $alert['state'] === 0 ) { + $ico = "ok"; + $col = "green"; + $extra = "success"; + $msg = "ok"; + } elseif ( (int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) { + $ico = "volume-up"; + $col = "red"; + $extra = "danger"; + $msg = "alert"; + if ( (int) $alert['state'] === 3) { + $msg = "worse"; + } elseif ( (int) $alert['state'] === 4) { + $msg = "better"; } + } elseif ( (int) $alert['state'] === 2) { + $ico = "volume-off"; + $col = "#800080"; + $extra = "warning"; + $msg = "muted"; } - else if ((int) $alert['state'] === 2) { - $ico = 'volume-off'; - $col = '#800080'; - $extra = 'warning'; - $msg = 'muted'; - }//end if $alert_checked = ''; - $orig_ico = $ico; - $orig_col = $col; - $orig_class = $extra; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; $severity = $alert['severity']; if ($alert['state'] == 3) { - $severity .= ' +'; - } - else if ($alert['state'] == 4) { - $severity .= ' -'; + $severity .= " +"; + } elseif ($alert['state'] == 4) { + $severity .= " -"; } $ack_ico = 'volume-up'; $ack_col = 'success'; - if ($alert['state'] == 2) { + if($alert['state'] == 2) { $ack_ico = 'volume-off'; $ack_col = 'danger'; - } + } $hostname = ' -
    - '.generate_device_link($alert).' -
    '.$fault_detail.'
    -
    '; +
    + '.generate_device_link($alert).' +
    '.$fault_detail.'
    +
    '; - $response[] = array( - 'id' => $rulei++, - 'rule' => ''.htmlentities($alert['name']).'', - 'details' => '', - 'hostname' => $hostname, - 'timestamp' => ($alert['timestamp'] ? $alert['timestamp'] : 'N/A'), - 'severity' => $severity, - 'ack_col' => $ack_col, - 'state' => $alert['state'], - 'alert_id' => $alert['id'], - 'ack_ico' => $ack_ico, - 'extra' => $extra, - 'msg' => $msg, - ); -}//end foreach + $response[] = array('id'=>$rulei++, + 'rule'=>"".htmlentities($alert['name'])."", + 'details'=>'', + 'hostname'=>$hostname, + 'timestamp'=>($alert['timestamp'] ? $alert['timestamp'] : "N/A"), + 'severity'=>$severity, + 'ack_col'=>$ack_col, + 'state'=>$alert['state'], + 'alert_id'=>$alert['id'], + 'ack_ico'=>$ack_ico, + 'extra'=>$extra, + 'msg'=>$msg); -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +} + +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); diff --git a/html/includes/table/arp-search.inc.php b/html/includes/table/arp-search.inc.php index 090476048f..dd5c6225ea 100644 --- a/html/includes/table/arp-search.inc.php +++ b/html/includes/table/arp-search.inc.php @@ -2,33 +2,32 @@ $param = array(); -$sql .= ' FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D '; +$sql .= " FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D "; -if (is_admin() === false && is_read() === false) { - $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`'; - $where .= ' AND `DP`.`user_id`=?'; +if (is_admin() === FALSE && is_read() === FALSE) { + $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`"; + $where .= " AND `DP`.`user_id`=?"; $param[] = $_SESSION['user_id']; } $sql .= " WHERE M.port_id = P.port_id AND P.device_id = D.device_id $where "; -if (isset($_POST['searchby']) && $_POST['searchby'] == 'ip') { - $sql .= ' AND `ipv4_address` LIKE ?'; - $param[] = '%'.trim($_POST['address']).'%'; -} -else if (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') { - $sql .= ' AND `mac_address` LIKE ?'; - $param[] = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address'])).'%'; +if (isset($_POST['searchby']) && $_POST['searchby'] == "ip") { + $sql .= " AND `ipv4_address` LIKE ?"; + $param[] = "%".trim($_POST['address'])."%"; +} elseif (isset($_POST['searchby']) && $_POST['searchby'] == "mac") { + $sql .= " AND `mac_address` LIKE ?"; + $param[] = "%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%"; } if (is_numeric($_POST['device_id'])) { - $sql .= ' AND P.device_id = ?'; + $sql .= " AND P.device_id = ?"; $param[] = $_POST['device_id']; } $count_sql = "SELECT COUNT(`M`.`port_id`) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -40,7 +39,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -52,53 +51,39 @@ $sql = "SELECT *,`P`.`ifDescr` AS `interface` $sql"; foreach (dbFetchRows($sql, $param) as $entry) { if (!$ignore) { + if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) { - $error_img = generate_port_link($entry, "Interface Errors", port_errors); - } - else { - $error_img = ''; + $error_img = generate_port_link($entry,"Interface Errors",port_errors); + } else { + $error_img = ""; } - $arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($entry['ipv4_address'])); - if ($arp_host) { - $arp_name = generate_device_link($arp_host); - } - else { - unset($arp_name); - } - - if ($arp_host) { - $arp_if = generate_port_link($arp_host); - } - else { - unset($arp_if); - } - - if ($arp_host['device_id'] == $entry['device_id']) { - $arp_name = 'Localhost'; - } - - if ($arp_host['port_id'] == $entry['port_id']) { - $arp_if = 'Local port'; - } - - $response[] = array( - 'mac_address' => formatMac($entry['mac_address']), - 'ipv4_address' => $entry['ipv4_address'], - 'hostname' => generate_device_link($entry), - 'interface' => generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))).' '.$error_img, - 'remote_device' => $arp_name, - 'remote_interface' => $arp_if, - ); - }//end if - + $arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address'])); + if ($arp_host) { + $arp_name = generate_device_link($arp_host); + } else { + unset($arp_name); + } + if ($arp_host) { + $arp_if = generate_port_link($arp_host); + } else { + unset($arp_if); + } + if ($arp_host['device_id'] == $entry['device_id']) { + $arp_name = "Localhost"; + } + if ($arp_host['port_id'] == $entry['port_id']) { + $arp_if = "Local port"; + } + $response[] = array('mac_address'=>formatMac($entry['mac_address']), + 'ipv4_address'=>$entry['ipv4_address'], + 'hostname'=>generate_device_link($entry), + 'interface'=>generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))) . ' ' . $error_img, + 'remote_device'=>$arp_name, + 'remote_interface'=>$arp_if); + } unset($ignore); -}//end foreach +} -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); diff --git a/html/includes/table/devices.inc.php b/html/includes/table/devices.inc.php index 129e198f21..25cf21bd51 100644 --- a/html/includes/table/devices.inc.php +++ b/html/includes/table/devices.inc.php @@ -3,11 +3,11 @@ $where = 1; $param = array(); -$sql = ' FROM `devices`'; +$sql = " FROM `devices`"; -if (is_admin() === false && is_read() === false) { - $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`'; - $where .= ' AND `DP`.`user_id`=?'; +if (is_admin() === FALSE && is_read() === FALSE) { + $sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`"; + $where .= " AND `DP`.`user_id`=?"; $param[] = $_SESSION['user_id']; } @@ -17,87 +17,48 @@ if (!empty($_POST['location'])) { $sql .= " WHERE $where "; -if (!empty($_POST['hostname'])) { - $sql .= ' AND hostname LIKE ?'; - $param[] = '%'.$_POST['hostname'].'%'; +if (!empty($_POST['hostname'])) { $sql .= " AND hostname LIKE ?"; $param[] = "%".$_POST['hostname']."%"; } +if (!empty($_POST['os'])) { $sql .= " AND os = ?"; $param[] = $_POST['os']; } +if (!empty($_POST['version'])) { $sql .= " AND version = ?"; $param[] = $_POST['version']; } +if (!empty($_POST['hardware'])) { $sql .= " AND hardware = ?"; $param[] = $_POST['hardware']; } +if (!empty($_POST['features'])) { $sql .= " AND features = ?"; $param[] = $_POST['features']; } +if (!empty($_POST['type'])) { + if ($_POST['type'] == 'generic') { + $sql .= " AND ( type = ? OR type = '')"; $param[] = $_POST['type']; + } else { + $sql .= " AND type = ?"; $param[] = $_POST['type']; + } } - -if (!empty($_POST['os'])) { - $sql .= ' AND os = ?'; - $param[] = $_POST['os']; -} - -if (!empty($_POST['version'])) { - $sql .= ' AND version = ?'; - $param[] = $_POST['version']; -} - -if (!empty($_POST['hardware'])) { - $sql .= ' AND hardware = ?'; - $param[] = $_POST['hardware']; -} - -if (!empty($_POST['features'])) { - $sql .= ' AND features = ?'; - $param[] = $_POST['features']; -} - -if (!empty($_POST['type'])) { - if ($_POST['type'] == 'generic') { - $sql .= " AND ( type = ? OR type = '')"; - $param[] = $_POST['type']; - } - else { - $sql .= ' AND type = ?'; - $param[] = $_POST['type']; - } -} - if (!empty($_POST['state'])) { - $sql .= ' AND status= ?'; - if (is_numeric($_POST['state'])) { + $sql .= " AND status= ?"; + if( is_numeric($_POST['state']) ) { $param[] = $_POST['state']; - } - else { - $param[] = str_replace(array('up', 'down'), array(1, 0), $_POST['state']); + } else { + $param[] = str_replace(array('up','down'),array(1,0),$_POST['state']); } } - -if (!empty($_POST['disabled'])) { - $sql .= ' AND disabled= ?'; - $param[] = $_POST['disabled']; -} - -if (!empty($_POST['ignore'])) { - $sql .= ' AND `ignore`= ?'; - $param[] = $_POST['ignore']; -} - -if (!empty($_POST['location']) && $_POST['location'] == 'Unset') { - $location_filter = ''; -} - +if (!empty($_POST['disabled'])) { $sql .= " AND disabled= ?"; $param[] = $_POST['disabled']; } +if (!empty($_POST['ignore'])) { $sql .= " AND `ignore`= ?"; $param[] = $_POST['ignore']; } +if (!empty($_POST['location']) && $_POST['location'] == "Unset") { $location_filter = ''; } if (!empty($_POST['location'])) { - $sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)"; + $sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)"; $param[] = mres($_POST['location']); $param[] = mres($_POST['location']); } - -if (!empty($_POST['group'])) { - include_once '../includes/device-groups.inc.php'; - $sql .= ' AND ( '; - foreach (GetDevicesFromGroup($_POST['group']) as $dev) { - $sql .= '`devices`.`device_id` = ? OR '; +if( !empty($_POST['group']) ) { + require_once('../includes/device-groups.inc.php'); + $sql .= " AND ( "; + foreach( GetDevicesFromGroup($_POST['group']) as $dev ) { + $sql .= "`devices`.`device_id` = ? OR "; $param[] = $dev['device_id']; } - - $sql = substr($sql, 0, (strlen($sql) - 3)); - $sql .= ' )'; + $sql = substr($sql, 0, strlen($sql)-3); + $sql .= " )"; } $count_sql = "SELECT COUNT(`devices`.`device_id`) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -109,7 +70,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -120,124 +81,99 @@ if ($rowCount != -1) { $sql = "SELECT DISTINCT(`devices`.`device_id`),`devices`.* $sql"; if (!isset($_POST['format'])) { - $_POST['format'] = 'list_detail'; + $_POST['format'] = "list_detail"; } - -list($format, $subformat) = explode('_', $_POST['format']); +list($format, $subformat) = explode("_", $_POST['format']); foreach (dbFetchRows($sql, $param) as $device) { - if (isset($bg) && $bg == $list_colour_b) { - $bg = $list_colour_a; - } - else { - $bg = $list_colour_b; - } + if (isset($bg) && $bg == $list_colour_b) { + $bg = $list_colour_a; + } else { + $bg = $list_colour_b; + } - if ($device['status'] == '0') { - $extra = 'danger'; - $msg = $device['status_reason']; - } - else { - $extra = 'success'; - $msg = 'up'; - } + if ($device['status'] == '0') { + $extra = "danger"; + $msg = $device['status_reason']; + } else { + $extra = "success"; + $msg = "up"; + } + if ($device['ignore'] == '1') { + $extra = "default"; + $msg = "ignored"; + if ($device['status'] == '1') { + $extra = "warning"; + $msg = "ignored"; + } + } + if ($device['disabled'] == '1') { + $extra = "default"; + $msg = "disabled"; + } - if ($device['ignore'] == '1') { - $extra = 'default'; - $msg = 'ignored'; - if ($device['status'] == '1') { - $extra = 'warning'; - $msg = 'ignored'; - } - } + $type = strtolower($device['os']); + $image = getImage($device); + + if ($device['os'] == "ios") { + formatCiscoHardware($device, true); + } - if ($device['disabled'] == '1') { - $extra = 'default'; - $msg = 'disabled'; - } + $device['os_text'] = $config['os'][$device['os']]['text']; + $port_count = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?", array($device['device_id'])); + $sensor_count = dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?", array($device['device_id'])); - $type = strtolower($device['os']); - $image = getImage($device); + if (get_dev_attrib($device,'override_sysLocation_bool')) { + $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); + } - if ($device['os'] == 'ios') { - formatCiscoHardware($device, true); - } + $actions = ('
    +
    '); + $actions .= ' View device '; + $actions .= ('
    +
    '); + $actions .= ' View alerts '; + $actions .= '
    '; + if ($_SESSION['userlevel'] >= "7") { + $actions .= ('
    + Edit device +
    '); + } + $actions .= ('
    +
    +
    + telnet +
    +
    + ssh +
    +
    + https +
    +
    '); - $device['os_text'] = $config['os'][$device['os']]['text']; - $port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); - $sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id'])); + $hostname = generate_device_link($device); + $platform = $device['hardware'] . '
    ' . $device['features']; + $os = $device['os_text'] . '
    ' . $device['version']; + if (extension_loaded('mbstring')) { + $location = mb_substr($device['location'], 0, 32, 'utf8'); + } else { + $location = truncate($device['location'], 32, ''); + } + $uptime = formatUptime($device['uptime'], 'short') . '
    ' . $location; + if ($subformat == "detail") { + $hostname .= '
    ' . $device['sysName']; + if ($port_count) { + $col_port = ' '.$port_count . '
    '; + } + if ($sensor_count) { + $col_port .= ' '.$sensor_count; + } + } else { - if (get_dev_attrib($device, 'override_sysLocation_bool')) { - $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); - } + } + $response[] = array('extra'=>$extra,'msg'=>$msg,'icon'=>$image,'hostname'=>$hostname,'ports'=>$col_port,'hardware'=>$platform,'os'=>$os,'uptime'=>$uptime,'actions'=>$actions); +} - $actions = ('
    -
    '); - $actions .= ' View device '; - $actions .= ('
    -
    '); - $actions .= ' View alerts '; - $actions .= '
    '; - if ($_SESSION['userlevel'] >= '7') { - $actions .= ('
    - Edit device -
    '); - } - - $actions .= ('
    -
    -
    - telnet -
    -
    - ssh -
    -
    - https -
    -
    '); - - $hostname = generate_device_link($device); - $platform = $device['hardware'].'
    '.$device['features']; - $os = $device['os_text'].'
    '.$device['version']; - if (extension_loaded('mbstring')) { - $location = mb_substr($device['location'], 0, 32, 'utf8'); - } - else { - $location = truncate($device['location'], 32, ''); - } - - $uptime = formatUptime($device['uptime'], 'short').'
    '.$location; - if ($subformat == 'detail') { - $hostname .= '
    '.$device['sysName']; - if ($port_count) { - $col_port = ' '.$port_count.'
    '; - } - - if ($sensor_count) { - $col_port .= ' '.$sensor_count; - } - } - else { - } - - $response[] = array( - 'extra' => $extra, - 'msg' => $msg, - 'icon' => $image, - 'hostname' => $hostname, - 'ports' => $col_port, - 'hardware' => $platform, - 'os' => $os, - 'uptime' => $uptime, - 'actions' => $actions, - ); -}//end foreach - -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php index 9cae422965..d5e5e7d60e 100644 --- a/html/includes/table/eventlog.inc.php +++ b/html/includes/table/eventlog.inc.php @@ -1,22 +1,23 @@ = '5') { $sql = " FROM `eventlog` AS E LEFT JOIN `devices` AS `D` ON `E`.`host`=`D`.`device_id` WHERE $where"; -} -else { - $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?"; +} else { + $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?"; $param[] = $_SESSION['user_id']; } @@ -25,7 +26,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } $count_sql = "SELECT COUNT(datetime) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -37,7 +38,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -47,28 +48,22 @@ if ($rowCount != -1) { $sql = "SELECT `E`.*,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate $sql"; -foreach (dbFetchRows($sql, $param) as $eventlog) { +foreach (dbFetchRows($sql,$param) as $eventlog) { $dev = device_by_id_cache($eventlog['host']); - if ($eventlog['type'] == 'interface') { + if ($eventlog['type'] == "interface") { $this_if = ifLabel(getifbyid($eventlog['reference'])); - $type = ''.generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).''; + $type = "".generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).""; + } else { + $type = "System"; } - else { - $type = 'System'; - } - - $response[] = array( - 'datetime' => $eventlog['humandate'], - 'hostname' => generate_device_link($dev, shorthost($dev['hostname'])), - 'type' => $type, - 'message' => htmlspecialchars($eventlog['message']), - ); + + $response[] = array('datetime'=>$eventlog['humandate'], + 'hostname'=>generate_device_link($dev, shorthost($dev['hostname'])), + 'type'=>$type, + 'message'=>htmlspecialchars($eventlog['message'])); } -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); + +?> diff --git a/html/includes/table/inventory.inc.php b/html/includes/table/inventory.inc.php index 2e4c0b9281..6c5b92823f 100644 --- a/html/includes/table/inventory.inc.php +++ b/html/includes/table/inventory.inc.php @@ -1,15 +1,14 @@ = '5') { $sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id"; -} -else { - $sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?"; +} else { + $sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?"; $param[] = $_SESSION['user_id']; } @@ -18,32 +17,32 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } if (isset($_POST['string']) && strlen($_POST['string'])) { - $sql .= ' AND E.entPhysicalDescr LIKE ?'; - $param[] = '%'.$_POST['string'].'%'; + $sql .= " AND E.entPhysicalDescr LIKE ?"; + $param[] = "%".$_POST['string']."%"; } if (isset($_POST['device_string']) && strlen($_POST['device_string'])) { - $sql .= ' AND D.hostname LIKE ?'; - $param[] = '%'.$_POST['device_string'].'%'; + $sql .= " AND D.hostname LIKE ?"; + $param[] = "%".$_POST['device_string']."%"; } if (isset($_POST['part']) && strlen($_POST['part'])) { - $sql .= ' AND E.entPhysicalModelName = ?'; - $param[] = $_POST['part']; + $sql .= " AND E.entPhysicalModelName = ?"; + $param[] = $_POST['part']; } if (isset($_POST['serial']) && strlen($_POST['serial'])) { - $sql .= ' AND E.entPhysicalSerialNum LIKE ?'; - $param[] = '%'.$_POST['serial'].'%'; + $sql .= " AND E.entPhysicalSerialNum LIKE ?"; + $param[] = "%".$_POST['serial']."%"; } if (isset($_POST['device']) && is_numeric($_POST['device'])) { - $sql .= ' AND D.device_id = ?'; - $param[] = $_POST['device']; + $sql .= " AND D.device_id = ?"; + $param[] = $_POST['device']; } $count_sql = "SELECT COUNT(`entPhysical_id`) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -55,7 +54,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -66,19 +65,12 @@ if ($rowCount != -1) { $sql = "SELECT `D`.`device_id` AS `device_id`, `D`.`hostname` AS `hostname`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql"; foreach (dbFetchRows($sql, $param) as $invent) { - $response[] = array( - 'hostname' => generate_device_link($invent, shortHost($invent['hostname'])), - 'description' => $invent['description'], - 'name' => $invent['name'], - 'model' => $invent['model'], - 'serial' => $invent['serial'], - ); + $response[] = array('hostname'=>generate_device_link($invent, shortHost($invent['hostname'])), + 'description'=>$invent['description'], + 'name'=>$invent['name'], + 'model'=>$invent['model'], + 'serial'=>$invent['serial']); } -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, - ); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); diff --git a/html/includes/table/mempool.inc.php b/html/includes/table/mempool.inc.php index 2afb80edc0..d3968a5317 100644 --- a/html/includes/table/mempool.inc.php +++ b/html/includes/table/mempool.inc.php @@ -1,88 +1,72 @@ generate_device_link($mempool), - 'mempool_descr' => $mempool['mempool_descr'], - 'graph' => $mini_graph, - 'mempool_used' => $bar_link, - 'mempool_perc' => $perc.'%', - ); - if ($_POST['view'] == 'graphs') { - $graph_array['height'] = '100'; - $graph_array['width'] = '216'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; - $return_data = true; - include 'includes/print-graphrow.inc.php'; - unset($return_data); - $response[] = array( - 'hostname' => $graph_data[0], - 'mempool_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'mempool_used' => $graph_data[3], - 'mempool_perc' => '', - ); - } //end if -}//end foreach - -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $count, -); + $response[] = array('hostname' => generate_device_link($mempool), + 'mempool_descr' => $mempool['mempool_descr'], + 'graph' => $mini_graph, + 'mempool_used' => $bar_link, + 'mempool_perc' => $perc . "%"); + if ($_POST['view'] == "graphs") { + $graph_array['height'] = "100"; + $graph_array['width'] = "216"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; + $return_data = true; + include("includes/print-graphrow.inc.php"); + unset($return_data); + $response[] = array('hostname' => $graph_data[0], + 'mempool_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'mempool_used' => $graph_data[3], + 'mempool_perc' => ''); + } # endif graphs +} +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count); echo _json_encode($output); diff --git a/html/includes/table/poll-log.inc.php b/html/includes/table/poll-log.inc.php index 3579759b6c..3a0ca3213e 100644 --- a/html/includes/table/poll-log.inc.php +++ b/html/includes/table/poll-log.inc.php @@ -1,12 +1,11 @@ " 'graphs', 'group' => 'poller'))."'>".$device['hostname'].'', - 'last_polled' => $device['last_polled'], - 'last_polled_timetaken' => $device['last_polled_timetaken'], - ); + $response[] = array('hostname' => " 'graphs', 'group' => 'poller')). "'>" .$device['hostname']. "", + 'last_polled' => $device['last_polled'], + 'last_polled_timetaken' => $device['last_polled_timetaken']); } -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); + +?> diff --git a/html/includes/table/processor.inc.php b/html/includes/table/processor.inc.php index bcedd6196f..a7b3d97457 100644 --- a/html/includes/table/processor.inc.php +++ b/html/includes/table/processor.inc.php @@ -1,83 +1,67 @@ generate_device_link($processor), - 'processor_descr' => $processor['processor_descr'], - 'graph' => $mini_graph, - 'processor_usage' => $bar_link, - ); - if ($_POST['view'] == 'graphs') { - $graph_array['height'] = '100'; - $graph_array['width'] = '216'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $processor['processor_id']; - $graph_array['type'] = $graph_type; - $return_data = true; - include 'includes/print-graphrow.inc.php'; - unset($return_data); - $response[] = array( - 'hostname' => $graph_data[0], - 'processor_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'processor_usage' => $graph_data[3], - ); - } //end if -}//end foreach - -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); + $response[] = array('hostname' => generate_device_link($processor), + 'processor_descr' => $processor['processor_descr'], + 'graph' => $mini_graph, + 'processor_usage' => $bar_link); + if ($_POST['view'] == "graphs") { + $graph_array['height'] = "100"; + $graph_array['width'] = "216"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $processor['processor_id']; + $graph_array['type'] = $graph_type; + $return_data = true; + include("includes/print-graphrow.inc.php"); + unset($return_data); + $response[] = array('hostname' => $graph_data[0], + 'processor_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'processor_usage' => $graph_data[3]); + } # endif graphs +} +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); diff --git a/html/includes/table/storage.inc.php b/html/includes/table/storage.inc.php index 3d301456f0..a912ba1d2e 100644 --- a/html/includes/table/storage.inc.php +++ b/html/includes/table/storage.inc.php @@ -1,14 +1,14 @@ generate_device_link($drive), - 'storage_descr' => $drive['storage_descr'], - 'graph' => $mini_graph, - 'storage_used' => $bar_link, - 'storage_perc' => $perc.'%', - ); - if ($_POST['view'] == 'graphs') { - $graph_array['height'] = '100'; - $graph_array['width'] = '216'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; + $graph_array['type'] = $graph_type; + $graph_array['id'] = $drive['storage_id']; + $graph_array['from'] = $config['time']['day']; + $graph_array['to'] = $config['time']['now']; + $graph_array['height'] = "20"; + $graph_array['width'] = "80"; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = "150"; + $graph_array_zoom['width'] = "400"; + $link = "graphs/id=" . $graph_array['id'] . "/type=" . $graph_array['type'] . "/from=" . $graph_array['from'] . "/to=" . $graph_array['to'] . "/"; + $mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); + $background = get_percentage_colours($perc); + $bar_link = overlib_link($link, print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $free, "ffffff", $background['right']), generate_graph_tag($graph_array_zoom), NULL); - $return_data = true; - include 'includes/print-graphrow.inc.php'; - unset($return_data); - $response[] = array( - 'hostname' => $graph_data[0], - 'storage_descr' => $graph_data[1], - 'graph' => $graph_data[2], - 'storage_used' => $graph_data[3], - 'storage_perc' => '', - ); - } //end if -}//end foreach + $response[] = array('hostname' => generate_device_link($drive), + 'storage_descr' => $drive['storage_descr'], + 'graph' => $mini_graph, + 'storage_used' => $bar_link, + 'storage_perc' => $perc . "%"); + if ($_POST['view'] == "graphs") { + $graph_array['height'] = "100"; + $graph_array['width'] = "216"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $count, -); + $return_data = true; + include("includes/print-graphrow.inc.php"); + unset($return_data); + $response[] = array('hostname' => $graph_data[0], + 'storage_descr' => $graph_data[1], + 'graph' => $graph_data[2], + 'storage_used' => $graph_data[3], + 'storage_perc' => ''); + + } # endif graphs +} + +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count); echo _json_encode($output); diff --git a/html/includes/table/syslog.inc.php b/html/includes/table/syslog.inc.php index 987aac65a1..81df05d289 100644 --- a/html/includes/table/syslog.inc.php +++ b/html/includes/table/syslog.inc.php @@ -1,44 +1,46 @@ = ?'; - $param[] = $_POST['from']; +if( !empty($_POST['from']) ) { + $where .= " AND timestamp >= ?"; + $param[] = $_POST['from']; +} +if( !empty($_POST['to']) ) { + $where .= " AND timestamp <= ?"; + $param[] = $_POST['to']; } -if (!empty($_POST['to'])) { - $where .= ' AND timestamp <= ?'; - $param[] = $_POST['to']; -} - -if ($_SESSION['userlevel'] >= '5') { - $sql = 'FROM syslog AS S'; - $sql .= ' WHERE '.$where; -} -else { - $sql = 'FROM syslog AS S, devices_perms AS P'; - $sql .= 'WHERE S.device_id = P.device_id AND P.user_id = ?'; - $sql .= $where; - $param = array_merge(array($_SESSION['user_id']), $param); +if ($_SESSION['userlevel'] >= '5') +{ + $sql = "FROM syslog AS S"; + $sql .= " WHERE ".$where; +} else { + $sql = "FROM syslog AS S, devices_perms AS P"; + $sql .= "WHERE S.device_id = P.device_id AND P.user_id = ?"; + $sql .= $where; + $param = array_merge(array($_SESSION['user_id']), $param); } $count_sql = "SELECT COUNT(timestamp) $sql"; -$total = dbFetchCell($count_sql, $param); +$total = dbFetchCell($count_sql,$param); if (empty($total)) { $total = 0; } @@ -50,7 +52,7 @@ if (!isset($sort) || empty($sort)) { $sql .= " ORDER BY $sort"; if (isset($current)) { - $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_low = ($current * $rowCount) - ($rowCount); $limit_high = $rowCount; } @@ -60,20 +62,14 @@ if ($rowCount != -1) { $sql = "SELECT S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql"; -foreach (dbFetchRows($sql, $param) as $syslog) { - $dev = device_by_id_cache($syslog['device_id']); - $response[] = array( - 'timestamp' => $syslog['date'], - 'device_id' => generate_device_link($dev, shorthost($dev['hostname'])), - 'program' => $syslog['program'], - 'msg' => htmlspecialchars($syslog['msg']), - ); +foreach (dbFetchRows($sql,$param) as $syslog) { + $dev = device_by_id_cache($syslog['device_id']); + $response[] = array('timestamp'=>$syslog['date'], + 'device_id'=>generate_device_link($dev, shorthost($dev['hostname'])), + 'program'=>$syslog['program'], + 'msg'=>htmlspecialchars($syslog['msg'])); } -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); echo _json_encode($output); +?> diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 477f056b46..788915f694 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -1,38 +1,40 @@ $get_var) { - if (strstr($key, 'opt')) { - list($name, $value) = explode('|', $get_var); - if (!isset($value)) { - $value = 'yes'; - } - - $vars[$name] = $value; - } +foreach ($_GET as $key=>$get_var) +{ + if (strstr($key, "opt")) + { + list($name, $value) = explode("|", $get_var); + if (!isset($value)) { $value = "yes"; } + $vars[$name] = $value; + } } $segments = explode('/', trim($_SERVER['REQUEST_URI'], '/')); -foreach ($segments as $pos => $segment) { - $segment = urldecode($segment); - if ($pos == '0') { - $vars['page'] = $segment; - } - else { - list($name, $value) = explode('=', $segment); - if ($value == '' || !isset($value)) { - $vars[$name] = yes; - } - else { - $vars[$name] = $value; - } +foreach ($segments as $pos => $segment) +{ + $segment = urldecode($segment); + if ($pos == "0") + { + $vars['page'] = $segment; + } else { + list($name, $value) = explode("=", $segment); + if ($value == "" || !isset($value)) + { + $vars[$name] = yes; + } else { + $vars[$name] = $value; } + } } -foreach ($_GET as $name => $value) { - $vars[$name] = $value; +foreach ($_GET as $name => $value) +{ + $vars[$name] = $value; } -foreach ($_POST as $name => $value) { - $vars[$name] = $value; +foreach ($_POST as $name => $value) +{ + $vars[$name] = $value; } diff --git a/html/index.php b/html/index.php index a3de9ba0c5..57fff1b57a 100644 --- a/html/index.php +++ b/html/index.php @@ -14,8 +14,7 @@ if( strstr($_SERVER['SERVER_SOFTWARE'],"nginx") ) { $_SERVER['PATH_INFO'] = str_replace($_SERVER['PATH_TRANSLATED'].$_SERVER['PHP_SELF'],"",$_SERVER['ORIG_SCRIPT_FILENAME']); -} -else { +} else { $_SERVER['PATH_INFO'] = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : ''); } @@ -32,40 +31,40 @@ function catchFatal() { } } -if (strpos($_SERVER['PATH_INFO'], "debug")) { - $debug = "1"; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); - set_error_handler('logErrors'); - register_shutdown_function('catchFatal'); -} -else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); +if (strpos($_SERVER['PATH_INFO'], "debug")) +{ + $debug = "1"; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); + set_error_handler('logErrors'); + register_shutdown_function('catchFatal'); +} else { + $debug = FALSE; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } // Set variables $msg_box = array(); // Check for install.inc.php -if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') { - // no config.php does so let's redirect to the install - header('Location: /install.php'); - exit; +if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') +{ + // no config.php does so let's redirect to the install + header('Location: /install.php'); + exit; } -require '../includes/defaults.inc.php'; -require '../config.php'; -require_once '../includes/definitions.inc.php'; -require '../includes/functions.php'; -require 'includes/functions.inc.php'; -require 'includes/vars.inc.php'; -require 'includes/plugins.inc.php'; - +include("../includes/defaults.inc.php"); +include("../config.php"); +include_once("../includes/definitions.inc.php"); +include("../includes/functions.php"); +include("includes/functions.inc.php"); +include("includes/vars.inc.php"); +include('includes/plugins.inc.php'); Plugins::start(); $runtime_start = utime(); @@ -75,33 +74,30 @@ ob_start(); ini_set('allow_url_fopen', 0); ini_set('display_errors', 0); -require 'includes/authenticate.inc.php'; +include("includes/authenticate.inc.php"); -if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { - $_SESSION['widescreen'] = 1; -} -if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) { - unset($_SESSION['widescreen']); -} +if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { $_SESSION['widescreen'] = 1; } +if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) { unset($_SESSION['widescreen']); } # Load the settings for Multi-Tenancy. -if (isset($config['branding']) && is_array($config['branding'])) { - if ($config['branding'][$_SERVER['SERVER_NAME']]) { - foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) { - eval("\$config['" . $confitem . "'] = \$confval;"); - } +if (isset($config['branding']) && is_array($config['branding'])) +{ + if ($config['branding'][$_SERVER['SERVER_NAME']]) + { + foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) + { + eval("\$config['" . $confitem . "'] = \$confval;"); } - else { - foreach ($config['branding']['default'] as $confitem => $confval) { - eval("\$config['" . $confitem . "'] = \$confval;"); - } + } else { + foreach ($config['branding']['default'] as $confitem => $confval) + { + eval("\$config['" . $confitem . "'] = \$confval;"); } + } } # page_title_prefix is displayed, unless page_title is set -if (isset($config['page_title'])) { - $config['page_title_prefix'] = $config['page_title']; -} +if (isset($config['page_title'])) { $config['page_title_prefix'] = $config['page_title']; } ?> @@ -123,8 +119,7 @@ if (empty($config['favicon'])) { ' . "\n"); } ?> @@ -174,13 +169,14 @@ else { body { padding-top: 0px !important; - padding-bottom: 0px !important; }"; + padding-bottom: 0px !important; }"; } @@ -192,47 +188,50 @@ else { "); - print_r($_GET); - print_r($vars); - echo(""); +if (isset($devel) || isset($vars['devel'])) +{ + echo("
    ");
    +  print_r($_GET);
    +  print_r($vars);
    +  echo("
    "); } -if ($_SESSION['authenticated']) { - // Authenticated. Print a page. - if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) { - require "pages/" . $vars['page'] . ".inc.php"; - } - else { - if (isset($config['front_page']) && is_file($config['front_page'])) { - require $config['front_page']; - } - else { - require 'pages/front/default.php'; - } +if ($_SESSION['authenticated']) +{ + // Authenticated. Print a page. + if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) + { + include("pages/" . $vars['page'] . ".inc.php"); + } else { + if (isset($config['front_page']) && is_file($config['front_page'])) + { + include($config['front_page']); + } else { + include("pages/front/default.php"); } + } -} -else { - // Not Authenticated. Show status page if enabled - if ( $config['public_status'] === true ) { - if (isset($vars['page']) && strstr("login", $vars['page'])) { - require 'pages/logon.inc.php'; - } - else { - echo '
    '; - require 'pages/public.inc.php'; - echo '
    '; - echo ''; - } - } - else { - require 'pages/logon.inc.php'; +} else { + // Not Authenticated. Show status page if enabled + if ( $config['public_status'] === true ) + { + if (isset($vars['page']) && strstr("login", $vars['page'])) + { + include("pages/logon.inc.php"); + } else { + echo '
    '; + include("pages/public.inc.php"); + echo '
    '; + echo ''; } + } + else + { + include("pages/logon.inc.php"); + } } ?> @@ -240,42 +239,37 @@ else { MySQL: Cell '.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,3).'s'. - ' Row '.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,3).'s'. - ' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'. - ' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s'); +if ($config['page_gen']) +{ + echo('
    MySQL: Cell '.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,3).'s'. + ' Row '.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,3).'s'. + ' Rows '.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,3).'s'. + ' Column '.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,3).'s'); - $fullsize = memory_get_usage(); - unset($cache); - $cachesize = $fullsize - memory_get_usage(); - if ($cachesize < 0) { - $cachesize = 0; - } // Silly PHP! + $fullsize = memory_get_usage(); + unset($cache); + $cachesize = $fullsize - memory_get_usage(); + if ($cachesize < 0) { $cachesize = 0; } // Silly PHP! - echo('
    Cached data in memory is '.formatStorage($cachesize).'. Page memory usage is '.formatStorage($fullsize).', peaked at '. formatStorage(memory_get_peak_usage()) .'.'); - echo('
    Generated in ' . $gentime . ' seconds.'); + echo('
    Cached data in memory is '.formatStorage($cachesize).'. Page memory usage is '.formatStorage($fullsize).', peaked at '. formatStorage(memory_get_peak_usage()) .'.'); + echo('
    Generated in ' . $gentime . ' seconds.'); } -if (isset($pagetitle) && is_array($pagetitle)) { - # if prefix is set, put it in front - if ($config['page_title_prefix']) { - array_unshift($pagetitle,$config['page_title_prefix']); - } +if (isset($pagetitle) && is_array($pagetitle)) +{ + # if prefix is set, put it in front + if ($config['page_title_prefix']) { array_unshift($pagetitle,$config['page_title_prefix']); } - # if suffix is set, put it in the back - if ($config['page_title_suffix']) { - $pagetitle[] = $config['page_title_suffix']; - } + # if suffix is set, put it in the back + if ($config['page_title_suffix']) { $pagetitle[] = $config['page_title_suffix']; } - # create and set the title - $title = join(" - ",$pagetitle); - echo(""); + # create and set the title + $title = join(" - ",$pagetitle); + echo(""); } ?> @@ -301,21 +295,23 @@ if(dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` <= } if(is_array($msg_box)) { - echo(""); + echo(""); } if (is_array($sql_debug) && is_array($php_debug) && $_SESSION['authenticated'] === TRUE) { - require_once "includes/print-debug.php"; + + include_once "includes/print-debug.php"; + } if ($no_refresh !== TRUE && $config['page_refresh'] != 0) { @@ -371,8 +367,7 @@ if ($no_refresh !== TRUE && $config['page_refresh'] != 0) { }); '); -} -else { +} else { echo(' diff --git a/html/pages/alert-stats.inc.php b/html/pages/alert-stats.inc.php index ab9a0c57fd..d392f1dd20 100644 --- a/html/pages/alert-stats.inc.php +++ b/html/pages/alert-stats.inc.php @@ -1,13 +1,12 @@ - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. - */ - -require_once 'includes/print-graph-alerts.inc.php'; +* LibreNMS +* +* Copyright (c) 2015 Søren Friis Rosiak +* 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 3 of the License, or (at your +* option) any later version. Please see LICENSE.txt at the top level of +* the source code distribution for details. +*/ +require_once('includes/print-graph-alerts.inc.php'); diff --git a/html/pages/alerts.inc.php b/html/pages/alerts.inc.php index 91526b69ff..bcc97a32a0 100644 --- a/html/pages/alerts.inc.php +++ b/html/pages/alerts.inc.php @@ -1,17 +1,19 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * LibreNMS + * + * Copyright (c) 2014 Neil Lathwood + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ $device['device_id'] = '-1'; -require_once 'includes/print-alerts.php'; +require_once('includes/print-alerts.php'); unset($device['device_id']); + +?> diff --git a/html/pages/api-access.inc.php b/html/pages/api-access.inc.php index 6b8a885a7a..a1b6e5a528 100644 --- a/html/pages/api-access.inc.php +++ b/html/pages/api-access.inc.php @@ -12,22 +12,22 @@ * the source code distribution for details. */ -if ($_SESSION['userlevel'] >= '10') { -if (empty($_POST['token'])) { +if ($_SESSION['userlevel'] >= '10') +{ +if(empty($_POST['token'])) { $_POST['token'] = bin2hex(openssl_random_pseudo_bytes(16)); } - ?> -'; -if ($_SESSION['api_token'] === true) { - echo " - "; + "); unset($_SESSION['api_token']); -} - -echo ' + } +echo('
    @@ -125,17 +127,19 @@ echo ' Disabled Remove -'; +'); -foreach (dbFetchRows('SELECT `AT`.*,`U`.`username` FROM `api_tokens` AS AT JOIN users AS U ON AT.user_id=U.user_id ORDER BY AT.user_id') as $api) { - if ($api['disabled'] == '1') { - $api_disabled = 'checked'; + foreach (dbFetchRows("SELECT `AT`.*,`U`.`username` FROM `api_tokens` AS AT JOIN users AS U ON AT.user_id=U.user_id ORDER BY AT.user_id") as $api) + { + if($api['disabled'] == '1') + { + $api_disabled = 'checked'; } - else { - $api_disabled = ''; + else + { + $api_disabled = ''; } - - echo ' + echo(' '.$api['username'].' '.$api['token_hash'].' @@ -143,14 +147,14 @@ foreach (dbFetchRows('SELECT `AT`.*,`U`.`username` FROM `api_tokens` AS AT JOIN -'; -} +'); + } - echo ' + echo('
    -'; +'); ?> diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index d3bd68b840..c260b73cec 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -17,7 +17,8 @@
    here.'); + print_error('Documentation for the API has now been moved to GitHub, you can go straight to the API Wiki from here.'); ?>
    + diff --git a/html/pages/apps.inc.php b/html/pages/apps.inc.php index cfd2378dde..1a20acc41f 100644 --- a/html/pages/apps.inc.php +++ b/html/pages/apps.inc.php @@ -1,91 +1,54 @@ Apps » "; +echo("Apps » "); unset($sep); -$link_array = array( - 'page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'apps', -); +$link_array = array('page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'apps'); -foreach ($app_list as $app) { - echo $sep; +foreach ($app_list as $app) +{ + echo($sep); - // if (!$vars['app']) { $vars['app'] = $app['app_type']; } - if ($vars['app'] == $app['app_type']) { - echo ""; - // echo(''); - } - else { - // echo(''); - } +# if (!$vars['app']) { $vars['app'] = $app['app_type']; } - echo generate_link(nicecase($app['app_type']), array('page' => 'apps', 'app' => $app['app_type'])); - if ($vars['app'] == $app['app_type']) { - echo ''; - } - - $sep = ' | '; + if ($vars['app'] == $app['app_type']) + { + echo(""); + #echo(''); + } else { + #echo(''); + } + echo(generate_link(nicecase($app['app_type']),array('page'=>'apps','app'=>$app['app_type']))); + if ($vars['app'] == $app['app_type']) { echo(""); } + $sep = " | "; } print_optionbar_end(); -if ($vars['app']) { - if (is_file('pages/apps/'.mres($vars['app']).'.inc.php')) { - include 'pages/apps/'.mres($vars['app']).'.inc.php'; - } - else { - include 'pages/apps/default.inc.php'; - } -} -else { - include 'pages/apps/overview.inc.php'; +if($vars['app']) +{ + if (is_file("pages/apps/".mres($vars['app']).".inc.php")) + { + include("pages/apps/".mres($vars['app']).".inc.php"); + } else { + include("pages/apps/default.inc.php"); + } +} else { + include("pages/apps/overview.inc.php"); } -$pagetitle[] = 'Apps'; +$pagetitle[] = "Apps"; +?> diff --git a/html/pages/apps/default.inc.php b/html/pages/apps/default.inc.php index bf752de29c..e333674057 100644 --- a/html/pages/apps/default.inc.php +++ b/html/pages/apps/default.inc.php @@ -1,41 +1,45 @@ '.nicecase($vars['app']).''; -echo ''; -$app_devices = dbFetchRows('SELECT * FROM `devices` AS D, `applications` AS A WHERE D.device_id = A.device_id AND A.app_type = ?', array($vars['app'])); +echo('

    '.nicecase($vars['app']).'

    '); +echo('
    '); +$app_devices = dbFetchRows("SELECT * FROM `devices` AS D, `applications` AS A WHERE D.device_id = A.device_id AND A.app_type = ?", array($vars['app'])); -foreach ($app_devices as $app_device) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''); + echo(''); + echo(''); + echo(''); + echo(''); + echo(''); + echo(''); + echo(''; - echo ''; -}//end foreach + echo(''); + echo(''); +} -echo '
    '.generate_device_link($app_device, shorthost($app_device['hostname']), array('tab' => 'apps', 'app' => $vars['app'])).''.$app_device['app_instance'].''.$app_device['app_status'].'
    '; +foreach ($app_devices as $app_device) +{ + echo('
    '.generate_device_link($app_device, shorthost($app_device['hostname']), array('tab'=>'apps','app'=>$vars['app'])).''.$app_device['app_instance'].''.$app_device['app_status'].'
    '); - foreach ($graphs[$vars['app']] as $graph_type) { - $graph_array['type'] = 'application_'.$vars['app'].'_'.$graph_type; - $graph_array['id'] = $app_device['app_id']; - $graph_array_zoom['type'] = 'application_'.$vars['app'].'_'.$graph_type; - $graph_array_zoom['id'] = $app_device['app_id']; + foreach ($graphs[$vars['app']] as $graph_type) + { + $graph_array['type'] = "application_".$vars['app']."_".$graph_type; + $graph_array['id'] = $app_device['app_id']; + $graph_array_zoom['type'] = "application_".$vars['app']."_".$graph_type; + $graph_array_zoom['id'] = $app_device['app_id']; - $link = generate_url(array('page' => 'device', 'device' => $app_device['device_id'], 'tab' => 'apps', 'app' => $vars['app'])); + $link = generate_url(array('page' => 'device', 'device' => $app_device['device_id'],'tab'=>'apps','app'=>$vars['app'])); - echo overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); - } + echo(overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL)); + } - echo '
    '; +echo(''); + +?> diff --git a/html/pages/authlog.inc.php b/html/pages/authlog.inc.php index 3cffbbea9e..64b4080ad2 100644 --- a/html/pages/authlog.inc.php +++ b/html/pages/authlog.inc.php @@ -1,37 +1,37 @@ = '10') { - echo ''; +if ($_SESSION['userlevel'] >= '10') +{ + echo("
    "); - foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) { - if ($bg == $list_colour_a) { - $bg = $list_colour_b; - } - else { - $bg = $list_colour_a; - } + foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry) + { + if ($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } - echo " - - - - - - '; - }//end foreach + echo(" + + + + + + "); + } - $pagetitle[] = 'Authlog'; + $pagetitle[] = "Authlog"; - echo '
    - ".$entry['datetime'].' - - '.$entry['user'].' - - '.$entry['address'].' - - '.$entry['result'].' -
    + " . $entry['datetime'] . " + + ".$entry['user']." + + ".$entry['address']." + + ".$entry['result']." +
    '; + echo(""); } -else { - include 'includes/error-no-perm.inc.php'; -}//end if +else +{ + include("includes/error-no-perm.inc.php"); +} + +?> diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php index 03faf35c17..13b640057b 100644 --- a/html/pages/bill.inc.php +++ b/html/pages/bill.inc.php @@ -2,274 +2,255 @@ $bill_id = mres($vars['bill_id']); -if ($_SESSION['userlevel'] >= '10') { - include 'pages/bill/actions.inc.php'; +if ($_SESSION['userlevel'] >= "10") +{ + include("pages/bill/actions.inc.php"); } -if (bill_permitted($bill_id)) { - $bill_data = dbFetchRow('SELECT * FROM bills WHERE bill_id = ?', array($bill_id)); +if (bill_permitted($bill_id)) +{ + $bill_data = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)); - $bill_name = $bill_data['bill_name']; + $bill_name = $bill_data['bill_name']; - $today = str_replace('-', '', dbFetchCell('SELECT CURDATE()')); - $yesterday = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)')); - $tomorrow = str_replace('-', '', dbFetchCell('SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)')); - $last_month = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)')); + $today = str_replace("-", "", dbFetchCell("SELECT CURDATE()")); + $yesterday = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)")); + $tomorrow = str_replace("-", "", dbFetchCell("SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)")); + $last_month = str_replace("-", "", dbFetchCell("SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")); - $rightnow = $today.date(His); - $before = $yesterday.date(His); - $lastmonth = $last_month.date(His); + $rightnow = $today . date(His); + $before = $yesterday . date(His); + $lastmonth = $last_month . date(His); - $bill_name = $bill_data['bill_name']; - $dayofmonth = $bill_data['bill_day']; + $bill_name = $bill_data['bill_name']; + $dayofmonth = $bill_data['bill_day']; - $day_data = getDates($dayofmonth); + $day_data = getDates($dayofmonth); - $datefrom = $day_data['0']; - $dateto = $day_data['1']; - $lastfrom = $day_data['2']; - $lastto = $day_data['3']; + $datefrom = $day_data['0']; + $dateto = $day_data['1']; + $lastfrom = $day_data['2']; + $lastto = $day_data['3']; - $rate_95th = $bill_data['rate_95th']; - $dir_95th = $bill_data['dir_95th']; - $total_data = $bill_data['total_data']; - $rate_average = $bill_data['rate_average']; + $rate_95th = $bill_data['rate_95th']; + $dir_95th = $bill_data['dir_95th']; + $total_data = $bill_data['total_data']; + $rate_average = $bill_data['rate_average']; - if ($rate_95th > $paid_kb) { - $over = ($rate_95th - $paid_kb); - $bill_text = $over.'Kbit excess.'; - $bill_color = '#cc0000'; - } - else { - $under = ($paid_kb - $rate_95th); - $bill_text = $under.'Kbit headroom.'; - $bill_color = '#0000cc'; + if ($rate_95th > $paid_kb) + { + $over = $rate_95th - $paid_kb; + $bill_text = $over . "Kbit excess."; + $bill_color = "#cc0000"; + } + else + { + $under = $paid_kb - $rate_95th; + $bill_text = $under . "Kbit headroom."; + $bill_color = "#0000cc"; + } + + $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); + $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); + $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); + $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); + + $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); + $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); + # Speeds up loading for other included pages by setting it before progessing of mysql data! + + $ports = dbFetchRows("SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D + WHERE B.bill_id = ? AND P.port_id = B.port_id + AND D.device_id = P.device_id", array($bill_id)); + + echo("

    + Bill : " . $bill_data['bill_name'] . "

    "); + + print_optionbar_start(); + + echo("Bill » "); + + if (!$vars['view']) { $vars['view'] = "quick"; } + + if ($vars['view'] == "quick") { echo(""); } + echo('Quick Graphs'); + if ($vars['view'] == "quick") { echo(""); } + + echo(" | "); + + if ($vars['view'] == "accurate") { echo(""); } + echo('Accurate Graphs'); + if ($vars['view'] == "accurate") { echo(""); } + + echo(" | "); + + if ($vars['view'] == "transfer") { echo(""); } + echo('Transfer Graphs'); + if ($vars['view'] == "transfer") { echo(""); } + + echo(" | "); + + if ($vars['view'] == "history") { echo(""); } + echo('Historical Usage'); + if ($vars['view'] == "history") { echo(""); } + + if ($_SESSION['userlevel'] >= "10") + { + echo(" | "); + if ($vars['view'] == "edit") { echo(""); } + echo('Edit'); + if ($vars['view'] == "edit") { echo(""); } + + echo(" | "); + if ($vars['view'] == "delete") { echo(""); } + echo('Delete'); + if ($vars['view'] == "delete") { echo(""); } + + echo(" | "); + if ($vars['view'] == "reset") { echo(""); } + echo('Reset'); + if ($vars['view'] == "reset") { echo(""); } + } + + echo(''); + + print_optionbar_end(); + + if ($vars['view'] == "edit" && $_SESSION['userlevel'] >= "10") + { + include("pages/bill/edit.inc.php"); + } + elseif ($vars['view'] == "delete" && $_SESSION['userlevel'] >= "10") + { + include("pages/bill/delete.inc.php"); + } + elseif ($vars['view'] == "reset" && $_SESSION['userlevel'] >= "10") + { + include("pages/bill/reset.inc.php"); + } + elseif ($vars['view'] == "history") + { + include("pages/bill/history.inc.php"); + } + elseif ($vars['view'] == "transfer") + { + include("pages/bill/transfer.inc.php"); + } + elseif ($vars['view'] == "quick" || $vars['view'] == "accurate") { + + echo("

    Billed Ports

    "); + + // Collected Earlier + foreach ($ports as $port) + { + echo(generate_port_link($port) . " on " . generate_device_link($port) . "
    "); } - $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')"); - $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')"); - $unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')"); - $unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')"); + echo("

    Bill Summary

    "); - $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')"); - $unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')"); - // Speeds up loading for other included pages by setting it before progessing of mysql data! - $ports = dbFetchRows( - 'SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D - WHERE B.bill_id = ? AND P.port_id = B.port_id - AND D.device_id = P.device_id', - array($bill_id) - ); + if ($bill_data['bill_type'] == "quota") + { + // The Customer is billed based on a pre-paid quota with overage in xB - echo '

    - Bill : '.$bill_data['bill_name'].'

    '; + echo("

    Quota Bill

    "); - print_optionbar_start(); + $percent = round(($total_data) / $bill_data['bill_quota'] * 100, 2); + $unit = "MB"; + $total_data = round($total_data, 2); + echo("Billing Period from " . $fromtext . " to " . $totext); + echo("
    Transferred ".format_bytes_billing($total_data)." of ".format_bytes_billing($bill_data['bill_quota'])." (".$percent."%)"); + echo("
    Average rate " . formatRates($rate_average)); - echo "Bill » "; + $background = get_percentage_colours($percent); - if (!$vars['view']) { - $vars['view'] = 'quick'; + echo("

    ".print_percentage_bar (350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

    "); + + $type="&ave=yes"; + } + elseif ($bill_data['bill_type'] == "cdr") + { + // The customer is billed based on a CDR with 95th%ile overage + + echo("

    CDR / 95th Bill

    "); + + $unit = "kbps"; + $cdr = $bill_data['bill_cdr']; + $rate_95th = round($rate_95th, 2); + + $percent = round(($rate_95th) / $cdr * 100, 2); + + $type="&95th=yes"; + + echo("" . $fromtext . " to " . $totext . " +
    Measured ".format_si($rate_95th)."bps of ".format_si($cdr)."bps (".$percent."%) @ 95th %ile"); + + $background = get_percentage_colours($percent); + + echo("

    ".print_percentage_bar (350, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right'])."

    "); + + # echo("

    Billing Period : " . $fromtext . " to " . $totext . "
    + # " . $paidrate_text . "
    + # " . $total_data . "MB transfered in the current billing cycle.
    + # " . $rate_average . "Kbps Average during the current billing cycle.

    + # " . $rate_95th . "Kbps @ 95th Percentile. (" . $dir_95th . ") (" . $bill_text . ") + # + #
    "); } - if ($vars['view'] == 'quick') { - echo ""; + $lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"); + $yesterday = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))"); + $rightnow = date(U); + + if ($vars['view'] == "accurate") { + + $bi = ""; + + $li = ""; + + $di = ""; + + $mi = ""; + } - echo 'Quick Graphs'; - if ($vars['view'] == 'quick') { - echo ''; - } - - echo ' | '; - - if ($vars['view'] == 'accurate') { - echo ""; - } - - echo 'Accurate Graphs'; - if ($vars['view'] == 'accurate') { - echo ''; - } - - echo ' | '; - - if ($vars['view'] == 'transfer') { - echo ""; - } - - echo 'Transfer Graphs'; - if ($vars['view'] == 'transfer') { - echo ''; - } - - echo ' | '; - - if ($vars['view'] == 'history') { - echo ""; - } - - echo 'Historical Usage'; - if ($vars['view'] == 'history') { - echo ''; - } - - if ($_SESSION['userlevel'] >= '10') { - echo ' | '; - if ($vars['view'] == 'edit') { - echo ""; - } - - echo 'Edit'; - if ($vars['view'] == 'edit') { - echo ''; - } - - echo ' | '; - if ($vars['view'] == 'delete') { - echo ""; - } - - echo 'Delete'; - if ($vars['view'] == 'delete') { - echo ''; - } - - echo ' | '; - if ($vars['view'] == 'reset') { - echo ""; - } - - echo 'Reset'; - if ($vars['view'] == 'reset') { - echo ''; - } - }//end if - - echo ''; - - print_optionbar_end(); - - if ($vars['view'] == 'edit' && $_SESSION['userlevel'] >= '10') { - include 'pages/bill/edit.inc.php'; - } - else if ($vars['view'] == 'delete' && $_SESSION['userlevel'] >= '10') { - include 'pages/bill/delete.inc.php'; - } - else if ($vars['view'] == 'reset' && $_SESSION['userlevel'] >= '10') { - include 'pages/bill/reset.inc.php'; - } - else if ($vars['view'] == 'history') { - include 'pages/bill/history.inc.php'; - } - else if ($vars['view'] == 'transfer') { - include 'pages/bill/transfer.inc.php'; - } - else if ($vars['view'] == 'quick' || $vars['view'] == 'accurate') { - echo '

    Billed Ports

    '; - - // Collected Earlier - foreach ($ports as $port) { - echo generate_port_link($port).' on '.generate_device_link($port).'
    '; - } - - echo '

    Bill Summary

    '; - - if ($bill_data['bill_type'] == 'quota') { - // The Customer is billed based on a pre-paid quota with overage in xB - echo '

    Quota Bill

    '; - - $percent = round((($total_data) / $bill_data['bill_quota'] * 100), 2); - $unit = 'MB'; - $total_data = round($total_data, 2); - echo 'Billing Period from '.$fromtext.' to '.$totext; - echo '
    Transferred '.format_bytes_billing($total_data).' of '.format_bytes_billing($bill_data['bill_quota']).' ('.$percent.'%)'; - echo '
    Average rate '.formatRates($rate_average); - - $background = get_percentage_colours($percent); - - echo '

    '.print_percentage_bar(350, 20, $perc, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'

    '; - - $type = '&ave=yes'; - } - else if ($bill_data['bill_type'] == 'cdr') { - // The customer is billed based on a CDR with 95th%ile overage - echo '

    CDR / 95th Bill

    '; - - $unit = 'kbps'; - $cdr = $bill_data['bill_cdr']; - $rate_95th = round($rate_95th, 2); - - $percent = round((($rate_95th) / $cdr * 100), 2); - - $type = '&95th=yes'; - - echo ''.$fromtext.' to '.$totext.' -
    Measured '.format_si($rate_95th).'bps of '.format_si($cdr).'bps ('.$percent.'%) @ 95th %ile'; - - $background = get_percentage_colours($percent); - - echo '

    '.print_percentage_bar(350, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'

    '; - - // echo("

    Billing Period : " . $fromtext . " to " . $totext . "
    - // " . $paidrate_text . "
    - // " . $total_data . "MB transfered in the current billing cycle.
    - // " . $rate_average . "Kbps Average during the current billing cycle.

    - // " . $rate_95th . "Kbps @ 95th Percentile. (" . $dir_95th . ") (" . $bill_text . ") - // - //
    "); - }//end if - - $lastmonth = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))'); - $yesterday = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))'); - $rightnow = date(U); - - if ($vars['view'] == 'accurate') { - $bi = ""; - - $li = ""; - - $di = ""; - }//end if - - if ($null) { - echo " - @@ -287,32 +268,39 @@ if (bill_permitted($bill_id)) { - "; - }//end if + "); - if ($_GET['all']) { - $ai = ''; - echo "

    Entire Data View

    $ai"; - } - else if ($_GET['custom']) { - $cg = ''; - echo "

    Custom Graph

    $cg"; - } - else { - echo "

    Billing View

    $bi"; - // echo("

    Previous Bill View

    $li"); - echo "

    24 Hour View

    $di"; - echo "

    Monthly View

    $mi"; - // echo("
    Graph All Data (SLOW)"); - }//end if - } //end if + } + + if ($_GET['all']) + { + $ai = ""; + echo("

    Entire Data View

    $ai"); + } + elseif ($_GET['custom']) + { + $cg = ""; + echo("

    Custom Graph

    $cg"); + } + else + { + echo("

    Billing View

    $bi"); +# echo("

    Previous Bill View

    $li"); + echo("

    24 Hour View

    $di"); + echo("

    Monthly View

    $mi"); +# echo("
    Graph All Data (SLOW)"); + } + } # End if details } -else { - include 'includes/error-no-perm.inc.php'; -}//end if +else +{ + include("includes/error-no-perm.inc.php"); +} + +?> diff --git a/html/pages/bill/actions.inc.php b/html/pages/bill/actions.inc.php index 29afb6d3b4..d55c2944cc 100644 --- a/html/pages/bill/actions.inc.php +++ b/html/pages/bill/actions.inc.php @@ -1,7 +1,8 @@ = 1) { - $quota = array( - 'type' => 'tb', - 'select_tb' => ' selected', - 'data' => $tmp['tb'], - ); - } - else if (($tmp['gb'] >= 1) and ($tmp['gb'] < $base)) { - $quota = array( - 'type' => 'gb', - 'select_gb' => ' selected', - 'data' => $tmp['gb'], - ); - } - else if (($tmp['mb'] >= 1) and ($tmp['mb'] < $base)) { - $quota = array( - 'type' => 'mb', - 'select_mb' => ' selected', - 'data' => $tmp['mb'], - ); - } -}//end if +$base = $config["billing"]["base"]; -if ($bill_data['bill_type'] == 'cdr') { - $data = $bill_data['bill_cdr']; - $tmp['kbps'] = ($data / $base); - $tmp['mbps'] = ($data / $base / $base); - $tmp['gbps'] = ($data / $base / $base / $base); - if ($tmp['gbps'] >= 1) { - $cdr = array( - 'type' => 'gbps', - 'select_gbps' => ' selected', - 'data' => $tmp['gbps'], - ); - } - else if (($tmp['mbps'] >= 1) and ($tmp['mbps'] < $base)) { - $cdr = array( - 'type' => 'mbps', - 'select_mbps' => ' selected', - 'data' => $tmp['mbps'], - ); - } - else if (($tmp['kbps'] >= 1) and ($tmp['kbps'] < $base)) { - $cdr = array( - 'type' => 'kbps', - 'select_kbps' => ' selected', - 'data' => $tmp['kbps'], - ); - } -}//end if +if ($bill_data['bill_type'] == "quota") { + $data = $bill_data['bill_quota']; + $tmp['mb'] = $data / $base / $base; + $tmp['gb'] = $data / $base / $base / $base; + $tmp['tb'] = $data / $base / $base / $base / $base; + if ($tmp['tb']>=1) { $quota = array("type" => "tb", "select_tb" => " selected", "data" => $tmp['tb']); } + elseif (($tmp['gb']>=1) and ($tmp['gb']<$base)) { $quota = array("type" => "gb", "select_gb" => " selected", "data" => $tmp['gb']); } + elseif (($tmp['mb']>=1) and ($tmp['mb']<$base)) { $quota = array("type" => "mb", "select_mb" => " selected", "data" => $tmp['mb']); } +} +if ($bill_data['bill_type'] == "cdr") { + $data = $bill_data['bill_cdr']; + $tmp['kbps'] = $data / $base; + $tmp['mbps'] = $data / $base / $base; + $tmp['gbps'] = $data / $base / $base / $base; + if ($tmp['gbps']>=1) { $cdr = array("type" => "gbps", "select_gbps" => " selected", "data" => $tmp['gbps']); } + elseif (($tmp['mbps']>=1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_mbps" => " selected", "data" => $tmp['mbps']); } + elseif (($tmp['kbps']>=1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_kbps" => " selected", "data" => $tmp['kbps']); } +} ?>
    - +

    Bill Properties

    - + " />
    @@ -86,35 +51,17 @@ function billType() {
    - -
    @@ -124,19 +121,19 @@ if ($unknown) {
    - value="" /> + value="" />
    - /> + />
    - /> + />
    diff --git a/html/pages/device/edit/health.inc.php b/html/pages/device/edit/health.inc.php index 922bb36c77..3d7d213527 100644 --- a/html/pages/device/edit/health.inc.php +++ b/html/pages/device/edit/health.inc.php @@ -30,158 +30,156 @@ $sensor['sensor_id'], - 'sensor_limit' => $sensor['sensor_limit'], - 'sensor_limit_low' => $sensor['sensor_limit_low'], - 'sensor_alert' => $sensor['sensor_alert'], - ); - if ($sensor['sensor_alert'] == 1) { - $alert_status = 'checked'; - } - else { - $alert_status = ''; - } - - if ($sensor['sensor_custom'] == 'No') { - $custom = 'disabled'; - } - else { - $custom = ''; - } - - echo ' - - '.$sensor['sensor_class'].' - '.$sensor['sensor_type'].' - '.$sensor['sensor_descr'].' - '.$sensor['sensor_current'].' - -
    +foreach ( dbFetchRows("SELECT * FROM sensors WHERE device_id = ? AND sensor_deleted='0'", array($device['device_id'])) as $sensor) +{ + $rollback[] = array('sensor_id' => $sensor['sensor_id'], 'sensor_limit' => $sensor['sensor_limit'], 'sensor_limit_low' => $sensor['sensor_limit_low'], 'sensor_alert' => $sensor['sensor_alert']); + if($sensor['sensor_alert'] == 1) + { + $alert_status = 'checked'; + } + else + { + $alert_status = ''; + } + if ($sensor['sensor_custom'] == 'No') { + $custom = 'disabled'; + } else { + $custom = ''; + } + echo(' + + '.$sensor['sensor_class'].' + '.$sensor['sensor_type'].' + '.$sensor['sensor_descr'].' + '.$sensor['sensor_current'].' + +
    -
    - - -
    +
    + + +
    -
    - - - - - +
    + + + + + Clear custom - - - '; + + +'); } + ?>
    - - - - '; +foreach($rollback as $reset_data) +{ + echo (' + + + + + '); } ?>
    + diff --git a/html/pages/device/edit/ipmi.inc.php b/html/pages/device/edit/ipmi.inc.php index 0aff50bdd7..f3971ca413 100644 --- a/html/pages/device/edit/ipmi.inc.php +++ b/html/pages/device/edit/ipmi.inc.php @@ -1,45 +1,31 @@ '7') { - $ipmi_hostname = mres($_POST['ipmi_hostname']); - $ipmi_username = mres($_POST['ipmi_username']); - $ipmi_password = mres($_POST['ipmi_password']); +if ($_POST['editing']) +{ + if ($_SESSION['userlevel'] > "7") + { + $ipmi_hostname = mres($_POST['ipmi_hostname']); + $ipmi_username = mres($_POST['ipmi_username']); + $ipmi_password = mres($_POST['ipmi_password']); - if ($ipmi_hostname != '') { - set_dev_attrib($device, 'ipmi_hostname', $ipmi_hostname); - } - else { - del_dev_attrib($device, 'ipmi_hostname'); - } + if ($ipmi_hostname != '') { set_dev_attrib($device, 'ipmi_hostname', $ipmi_hostname); } else { del_dev_attrib($device, 'ipmi_hostname'); } + if ($ipmi_username != '') { set_dev_attrib($device, 'ipmi_username', $ipmi_username); } else { del_dev_attrib($device, 'ipmi_username'); } + if ($ipmi_password != '') { set_dev_attrib($device, 'ipmi_password', $ipmi_password); } else { del_dev_attrib($device, 'ipmi_password'); } - if ($ipmi_username != '') { - set_dev_attrib($device, 'ipmi_username', $ipmi_username); - } - else { - del_dev_attrib($device, 'ipmi_username'); - } - - if ($ipmi_password != '') { - set_dev_attrib($device, 'ipmi_password', $ipmi_password); - } - else { - del_dev_attrib($device, 'ipmi_password'); - } - - $update_message = 'Device IPMI data updated.'; - $updated = 1; - } - else { - include 'includes/error-no-perm.inc.php'; - }//end if -}//end if - -if ($updated && $update_message) { - print_message($update_message); + $update_message = "Device IPMI data updated."; + $updated = 1; + } + else + { + include("includes/error-no-perm.inc.php"); + } } -else if ($update_message) { - print_error($update_message); + +if ($updated && $update_message) +{ + print_message($update_message); +} elseif ($update_message) { + print_error($update_message); } ?> @@ -51,19 +37,19 @@ else if ($update_message) {
    - +
    - +
    - +
    diff --git a/html/pages/device/edit/modules.inc.php b/html/pages/device/edit/modules.inc.php index 3196171626..36a53b3f10 100644 --- a/html/pages/device/edit/modules.inc.php +++ b/html/pages/device/edit/modules.inc.php @@ -17,57 +17,68 @@ $module_status) { - echo(' +foreach ($config['poller_modules'] as $module => $module_status) +{ + echo(' '.$module.' - '); +'); - if($module_status == 1) { - echo('Enabled'); - } - else { - echo('Disabled'); - } + if($module_status == 1) + { + echo('Enabled'); + } + else + { + echo('Disabled'); + } - echo(' + echo(' - '); +'); - if (isset($attribs['poll_'.$module])) { - if ($attribs['poll_'.$module]) { - echo('Enabled'); - $module_checked = 'checked'; - } - else { - echo('Disabled'); - $module_checked = ''; - } + if (isset($attribs['poll_'.$module])) + { + if ($attribs['poll_'.$module]) + { + echo('Enabled'); + $module_checked = 'checked'; } - else { - if($module_status == 1) { - echo('Enabled'); - $module_checked = 'checked'; - } - else { - echo('Disabled'); - $module_checked = ''; - } + else + { + echo('Disabled'); + $module_checked = ''; } + } + else + { + if($module_status == 1) + { + echo('Enabled'); + $module_checked = 'checked'; + } + else + { + echo('Disabled'); + $module_checked = ''; + } + } - echo(' + echo(' - '); +'); - echo(''); + echo(' + +'); - echo(' + echo(' - '); +'); } ?> @@ -85,56 +96,71 @@ foreach ($config['poller_modules'] as $module => $module_status) { $module_status) { - echo(' +foreach ($config['discovery_modules'] as $module => $module_status) +{ + + echo(' '.$module.' - '); +'); - if($module_status == 1) { - echo('Enabled'); - } - else { - echo('Disabled'); - } + if($module_status == 1) + { + echo('Enabled'); + } + else + { + echo('Disabled'); + } - echo(' + echo(' - '); + +'); - if (isset($attribs['discover_'.$module])) { - if($attribs['discover_'.$module]) { - echo('Enabled'); - $module_checked = 'checked'; - } - else { - echo('Disabled'); - $module_checked = ''; - } + if (isset($attribs['discover_'.$module])) + { + if($attribs['discover_'.$module]) + { + echo('Enabled'); + $module_checked = 'checked'; } - else { - if($module_status == 1) { - echo('Enabled'); - $module_checked = 'checked'; - } - else { - echo('Disabled'); - $module_checked = ''; - } + else + { + echo('Disabled'); + $module_checked = ''; } + } + else + { + if($module_status == 1) + { + echo('Enabled'); + $module_checked = 'checked'; + } + else + { + echo('Disabled'); + $module_checked = ''; + } + } - echo(' + echo(' - '); + +'); - echo(''); + echo(' + +'); - echo(' + echo(' - '); + +'); } echo(' diff --git a/html/pages/device/edit/ports.inc.php b/html/pages/device/edit/ports.inc.php index d8dc562e43..b382cf05a8 100644 --- a/html/pages/device/edit/ports.inc.php +++ b/html/pages/device/edit/ports.inc.php @@ -1,26 +1,28 @@ '; +echo('
    '); -if ($_POST['ignoreport']) { - if ($_SESSION['userlevel'] == '10') { - include 'includes/port-edit.inc.php'; - } +if ($_POST['ignoreport']) +{ + if ($_SESSION['userlevel'] == '10') + { + include("includes/port-edit.inc.php"); + } } -if ($updated && $update_message) { - print_message($update_message); -} -else if ($update_message) { - print_error($update_message); +if ($updated && $update_message) +{ + print_message($update_message); +} elseif ($update_message) { + print_error($update_message); } -echo "
    +echo("
    - "; + "); -echo " +echo("
    @@ -39,14 +41,14 @@ echo "
    Index Name
    -"; +"); ?> '; - echo ''; - echo ''; - echo ''; + if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - // Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled - // - as to draw the attention to a possible problem. - $isportbad = ($port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] != 'down') ? 1 : 0; - $dowecare = ($port['ignore'] == 0 && $port['disabled'] == 0) ? $isportbad : !$isportbad; - $outofsync = $dowecare ? " class='red'" : ''; + echo(""); + echo(""); + echo(""); + echo(""); - echo "'; + # Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled + # - as to draw the attention to a possible problem. + $isportbad = ($port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] != 'down') ? 1 : 0; + $dowecare = ($port['ignore'] == 0 && $port['disabled'] == 0) ? $isportbad : !$isportbad; + $outofsync = $dowecare ? " class='red'" : ""; - echo '"); - echo '"); - echo "\n"; + echo(""); + echo(""); - $row++; -}//end foreach + echo("\n"); -echo '
    '.$port['ifIndex'].''.$port['label'].''.$port['ifAdminStatus'].'
    ". $port['ifIndex']."".$port['label'] . "". $port['ifAdminStatus']."'.$port['ifOperStatus'].''; - echo "'; - echo "". $port['ifOperStatus']."'; - echo "'; - echo ""); + echo(""); + echo(""); + echo("
    "); + echo(""); + echo(""); + echo("".$port['ifAlias'] . "
    '; -echo '
    '; -echo '
    '; + $row++; +} + +echo(''); +echo(''); +echo('
    '); + +?> diff --git a/html/pages/device/edit/services.inc.php b/html/pages/device/edit/services.inc.php index 1f2bc1d30e..e6969a9fe9 100644 --- a/html/pages/device/edit/services.inc.php +++ b/html/pages/device/edit/services.inc.php @@ -1,28 +1,29 @@ = '10') { - include 'includes/service-add.inc.php'; + include("includes/service-add.inc.php"); } } if ($_POST['delsrv']) { if ($_SESSION['userlevel'] >= '10') { - include 'includes/service-delete.inc.php'; + include("includes/service-delete.inc.php"); } } if ($_POST['confirm-editsrv']) { - echo 'yeah'; + echo "yeah"; if ($_SESSION['userlevel'] >= '10') { - include 'includes/service-edit.inc.php'; + include("includes/service-edit.inc.php"); } } - if ($handle = opendir($config['install_dir'].'/includes/services/')) { + if ($handle = opendir($config['install_dir'] . "/includes/services/")) { while (false !== ($file = readdir($handle))) { - if ($file != '.' && $file != '..' && !strstr($file, '.')) { + if ($file != "." && $file != ".." && !strstr($file, ".")) { $servicesform .= ""; } } @@ -30,17 +31,17 @@ if (is_admin() === true || is_read() === true) { closedir($handle); } - $dev = device_by_id_cache($device['device_id']); - $devicesform = "'; + $dev = device_by_id_cache($device['device_id']); + $devicesform = ""; if ($updated) { - print_message('Device Settings Saved'); + print_message("Device Settings Saved"); } - if (dbFetchCell('SELECT COUNT(*) from `services` WHERE `device_id` = ?', array($device['device_id'])) > '0') { - $i = '1'; - foreach (dbFetchRows('select * from services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $service) { - $existform .= "'; + if (dbFetchCell("SELECT COUNT(*) from `services` WHERE `device_id` = ?", array($device['device_id'])) > '0') { + $i = "1"; + foreach (dbFetchRows("select * from services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $service) { + $existform .= ""; } } @@ -48,29 +49,28 @@ if (is_admin() === true || is_read() === true) { if ($existform) { echo '
    '; - if ($_POST['editsrv'] == 'yes') { - include_once 'includes/print-service-edit.inc.php'; - } - else { + if ($_POST['editsrv'] == "yes") { + include_once "includes/print-service-edit.inc.php"; + } else { echo " -

    Edit / Delete Service

    -
    +

    Edit / Delete Service

    +
    -
    - -
    - +
    + +
    + +
    +
    +
    +
    + +
    +
    -
    -
    -
    - -
    -
    -
    -
    "; + "; } echo '
    '; @@ -78,8 +78,8 @@ if (is_admin() === true || is_read() === true) { echo '
    '; - include_once 'includes/print-service-add.inc.php'; -} -else { - include 'includes/error-no-perm.inc.php'; -} + require_once "includes/print-service-add.inc.php"; + +} else { + include("includes/error-no-perm.inc.php"); +} \ No newline at end of file diff --git a/html/pages/device/edit/snmp.inc.php b/html/pages/device/edit/snmp.inc.php index 59c6bf4cd3..9e8a5b7b04 100644 --- a/html/pages/device/edit/snmp.inc.php +++ b/html/pages/device/edit/snmp.inc.php @@ -1,240 +1,225 @@ '7') { - $community = mres($_POST['community']); - $snmpver = mres($_POST['snmpver']); - $transport = $_POST['transport'] ? mres($_POST['transport']) : $transport = 'udp'; - $port = $_POST['port'] ? mres($_POST['port']) : $config['snmp']['port']; - $timeout = mres($_POST['timeout']); - $retries = mres($_POST['retries']); - $poller_group = mres($_POST['poller_group']); - $v3 = array( - 'authlevel' => mres($_POST['authlevel']), - 'authname' => mres($_POST['authname']), - 'authpass' => mres($_POST['authpass']), - 'authalgo' => mres($_POST['authalgo']), - 'cryptopass' => mres($_POST['cryptopass']), - 'cryptoalgo' => mres($_POST['cryptoalgo']), - ); +if ($_POST['editing']) +{ + if ($_SESSION['userlevel'] > "7") + { + $community = mres($_POST['community']); + $snmpver = mres($_POST['snmpver']); + $transport = $_POST['transport'] ? mres($_POST['transport']) : $transport = "udp"; + $port = $_POST['port'] ? mres($_POST['port']) : $config['snmp']['port']; + $timeout = mres($_POST['timeout']); + $retries = mres($_POST['retries']); + $poller_group = mres($_POST['poller_group']); + $v3 = array ( + 'authlevel' => mres($_POST['authlevel']), + 'authname' => mres($_POST['authname']), + 'authpass' => mres($_POST['authpass']), + 'authalgo' => mres($_POST['authalgo']), + 'cryptopass' => mres($_POST['cryptopass']), + 'cryptoalgo' => mres($_POST['cryptoalgo']) + ); - // FIXME needs better feedback - $update = array( - 'community' => $community, - 'snmpver' => $snmpver, - 'port' => $port, - 'transport' => $transport, - 'poller_group' => $poller_group, - ); + #FIXME needs better feedback + $update = array( + 'community' => $community, + 'snmpver' => $snmpver, + 'port' => $port, + 'transport' => $transport, + 'poller_group' => $poller_group + ); - if ($_POST['timeout']) { - $update['timeout'] = $timeout; - } - else { - $update['timeout'] = array('NULL'); + if ($_POST['timeout']) { $update['timeout'] = $timeout; } + else { $update['timeout'] = array('NULL'); } + if ($_POST['retries']) { $update['retries'] = $retries; } + else { $update['retries'] = array('NULL'); } + + $update = array_merge($update, $v3); + + $device_tmp = deviceArray($device['hostname'], $community, $snmpver, $port, $transport, $v3); + if (isSNMPable($device_tmp)) { + $rows_updated = dbUpdate($update, 'devices', '`device_id` = ?',array($device['device_id'])); + + if ($rows_updated > 0) { + $update_message = $rows_updated . " Device record updated."; + $updated = 1; + } elseif ($rows_updated = '-1') { + $update_message = "Device record unchanged. No update necessary."; + $updated = -1; + } else { + $update_message = "Device record update error."; + $updated = 0; } + } else { + $update_message = "Could not connect to device with new SNMP details"; + $updated = 0; + } + } +} - if ($_POST['retries']) { - $update['retries'] = $retries; - } - else { - $update['retries'] = array('NULL'); - } - - $update = array_merge($update, $v3); - - $device_tmp = deviceArray($device['hostname'], $community, $snmpver, $port, $transport, $v3); - if (isSNMPable($device_tmp)) { - $rows_updated = dbUpdate($update, 'devices', '`device_id` = ?', array($device['device_id'])); - - if ($rows_updated > 0) { - $update_message = $rows_updated.' Device record updated.'; - $updated = 1; - } - else if ($rows_updated = '-1') { - $update_message = 'Device record unchanged. No update necessary.'; - $updated = -1; - } - else { - $update_message = 'Device record update error.'; - $updated = 0; - } - } - else { - $update_message = 'Could not connect to device with new SNMP details'; - $updated = 0; - } - }//end if -}//end if - -$device = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($device['device_id'])); +$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id'])); $descr = $device['purpose']; -echo '
    -
    '; -if ($updated && $update_message) { - print_message($update_message); -} -else if ($update_message) { - print_error($update_message); +echo('
    +
    '); +if ($updated && $update_message) +{ + print_message($update_message); +} elseif ($update_message) { + print_error($update_message); } +echo('
    +
    '); -echo '
    -
    '; - -echo " -
    - -
    +echo(" + + +
    - +
    - +
    - "); foreach ($config['snmp']['transports'] as $transport) { - echo "'; + echo(">".$transport.""); } - -echo " +echo("
    -
    -
    +
    +
    - +
    - +
    -
    -
    +
    +
    - +
    - -
    - + +
    + +
    -
    -
    -
    +
    +
    - +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - -
    + +
    + +
    - -
    - + +
    + +
    -
    -
    '; +
    "); -if ($config['distributed_poller'] === true) { - echo ' -
    - -
    - + + '); - foreach (dbFetchRows('SELECT `id`,`group_name` FROM `poller_groups`') as $group) { - echo ''; + echo '>' . $group['group_name'] . ''; } - echo ' - -
    -
    - '; -}//end if + echo(' + +
    +
    + '); +} -echo ' - - - '; +echo(' + + +'); ?> diff --git a/html/pages/device/entphysical.inc.php b/html/pages/device/entphysical.inc.php index 7b5d956faa..af167b4ddc 100644 --- a/html/pages/device/entphysical.inc.php +++ b/html/pages/device/entphysical.inc.php @@ -1,11 +1,13 @@ "; @@ -31,8 +33,7 @@ function printEntPhysical($ent, $level, $class) { if (count($sensor)) { $link = " href='device/device=".$device['device_id'].'/tab=health/metric='.$sensor['sensor_class']."/' onmouseover=\"return overlib('', LEFT,FGCOLOR,'#e5e5e5', BGCOLOR, '#c0c0c0', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#050505');\" onmouseout=\"return nd();\""; } - } - else { + } else { unset($link); } diff --git a/html/pages/device/graphs.inc.php b/html/pages/device/graphs.inc.php index e4bd13d84c..a275e71e31 100644 --- a/html/pages/device/graphs.inc.php +++ b/html/pages/device/graphs.inc.php @@ -1,68 +1,70 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'graphs', -); -$bg = '#ffffff'; +$link_array = array('page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'graphs'); -echo '
    '; +$bg="#ffffff"; + +echo('
    '); print_optionbar_start(); -echo "Graphs » "; +echo("Graphs » "); -foreach (dbFetchRows('SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph', array($device['device_id'])) as $graph) { - $section = $config['graph_types']['device'][$graph['graph']]['section']; - if ($section != '') { - $graph_enable[$section][$graph['graph']] = $graph['graph']; - } +foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph", array($device['device_id'])) as $graph) +{ + $section = $config['graph_types']['device'][$graph['graph']]['section']; + if ($section != "") { + $graph_enable[$section][$graph['graph']] = $graph['graph']; + } } // These are standard graphs we should have for all systems $graph_enable['poller']['poller_perf'] = 'device_poller_perf'; -$graph_enable['poller']['ping_perf'] = 'device_ping_perf'; +$graph_enable['poller']['ping_perf'] = 'device_ping_perf'; -$sep = ''; -foreach ($graph_enable as $section => $nothing) { - if (isset($graph_enable) && is_array($graph_enable[$section])) { - $type = strtolower($section); - if (!$vars['group']) { - $vars['group'] = $type; - } - - echo $sep; - if ($vars['group'] == $type) { - echo ''; - } - - echo generate_link(ucwords($type), $link_array, array('group' => $type)); - if ($vars['group'] == $type) { - echo ''; - } - - $sep = ' | '; +$sep = ""; +foreach ($graph_enable as $section => $nothing) +{ + if (isset($graph_enable) && is_array($graph_enable[$section])) + { + $type = strtolower($section); + if (!$vars['group']) { $vars['group'] = $type; } + echo($sep); + if ($vars['group'] == $type) + { + echo(''); } + echo(generate_link(ucwords($type),$link_array,array('group'=>$type))); + if ($vars['group'] == $type) + { + echo(""); + } + $sep = " | "; + } } - -unset($sep); +unset ($sep); print_optionbar_end(); $graph_enable = $graph_enable[$vars['group']]; -// foreach ($config['graph_types']['device'] as $graph => $entry) -foreach ($graph_enable as $graph => $entry) { - $graph_array = array(); - if ($graph_enable[$graph]) { - $graph_title = $config['graph_types']['device'][$graph]['descr']; - $graph_array['type'] = 'device_'.$graph; +#foreach ($config['graph_types']['device'] as $graph => $entry) +foreach ($graph_enable as $graph => $entry) +{ + $graph_array = array(); + if ($graph_enable[$graph]) + { + $graph_title = $config['graph_types']['device'][$graph]['descr']; + $graph_array['type'] = "device_" . $graph; - include 'includes/print-device-graph.php'; - } + include("includes/print-device-graph.php"); + } } -$pagetitle[] = 'Graphs'; +$pagetitle[] = "Graphs"; + +?> diff --git a/html/pages/device/graphs/netstats_ip_forward.inc.php b/html/pages/device/graphs/netstats_ip_forward.inc.php index eda137a788..cc728ac77c 100644 --- a/html/pages/device/graphs/netstats_ip_forward.inc.php +++ b/html/pages/device/graphs/netstats_ip_forward.inc.php @@ -1,8 +1,11 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'health', -); +$link_array = array('page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'health'); print_optionbar_start(); -echo "Health » "; +echo("Health » "); -if (!$vars['metric']) { - $vars['metric'] = 'overview'; -} +if (!$vars['metric']) { $vars['metric'] = "overview"; } unset($sep); -foreach ($datas as $type) { - echo $sep; +foreach ($datas as $type) +{ + echo($sep); - if ($vars['metric'] == $type) { - echo ''; - } - - echo generate_link($type_text[$type], $link_array, array('metric' => $type)); - if ($vars['metric'] == $type) { - echo ''; - } - - $sep = ' | '; + if ($vars['metric'] == $type) + { echo(''); } + echo(generate_link($type_text[$type],$link_array,array('metric'=>$type))); + if ($vars['metric'] == $type) { echo(""); } + $sep = " | "; } print_optionbar_end(); -if (is_file('pages/device/health/'.mres($vars['metric']).'.inc.php')) { - include 'pages/device/health/'.mres($vars['metric']).'.inc.php'; -} -else { - foreach ($datas as $type) { - if ($type != 'overview') { - $graph_title = $type_text[$type]; - $graph_array['type'] = 'device_'.$type; +if (is_file("pages/device/health/".mres($vars['metric']).".inc.php")) +{ + include("pages/device/health/".mres($vars['metric']).".inc.php"); +} else { - include 'includes/print-device-graph.php'; - } + foreach ($datas as $type) + { + if ($type != "overview") + { + + $graph_title = $type_text[$type]; + $graph_array['type'] = "device_".$type; + + include("includes/print-device-graph.php"); } + } } -$pagetitle[] = 'Health'; +$pagetitle[] = "Health"; + +?> diff --git a/html/pages/device/health/charge.inc.php b/html/pages/device/health/charge.inc.php index 0750ae5935..7282247bff 100644 --- a/html/pages/device/health/charge.inc.php +++ b/html/pages/device/health/charge.inc.php @@ -1,7 +1,9 @@ diff --git a/html/pages/device/health/current.inc.php b/html/pages/device/health/current.inc.php index 70bd4dc425..0fa318a9b3 100644 --- a/html/pages/device/health/current.inc.php +++ b/html/pages/device/health/current.inc.php @@ -4,4 +4,6 @@ $class = "current"; $unit = "A"; $graph_type = "sensor_current"; -require 'sensors.inc.php'; +include("sensors.inc.php"); + +?> diff --git a/html/pages/device/health/humidity.inc.php b/html/pages/device/health/humidity.inc.php index ffef7afa6a..93b4772a3f 100644 --- a/html/pages/device/health/humidity.inc.php +++ b/html/pages/device/health/humidity.inc.php @@ -4,4 +4,6 @@ $class = "humidity"; $unit = "%"; $graph_type = "sensor_humidity"; -require 'sensors.inc.php'; +include("sensors.inc.php"); + +?> diff --git a/html/pages/device/health/load.inc.php b/html/pages/device/health/load.inc.php index 18f5b5f5cd..399237aaef 100644 --- a/html/pages/device/health/load.inc.php +++ b/html/pages/device/health/load.inc.php @@ -1,7 +1,9 @@ diff --git a/html/pages/device/health/mempool.inc.php b/html/pages/device/health/mempool.inc.php index 613aa1250b..6630c31476 100644 --- a/html/pages/device/health/mempool.inc.php +++ b/html/pages/device/health/mempool.inc.php @@ -1,72 +1,66 @@ "; -echo ''; +echo("
    "); +echo("
    "); $i = '1'; -// FIXME css alternating colours -foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($device['device_id'])) as $mempool) { - if (!is_integer($i / 2)) { - $row_colour = $list_colour_a; - } - else { - $row_colour = $list_colour_b; - } +#FIXME css alternating colours - if ($config['memcached']['enable'] === true) { - $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); - if ($debug) { - print_r($state); - } +foreach (dbFetchRows("SELECT * FROM `mempools` WHERE device_id = ?", array($device['device_id'])) as $mempool) +{ + if (!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - if (is_array($state)) { - $mempool = array_merge($mempool, $state); - } + if ($config['memcached']['enable'] === TRUE) + { + $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); + if($debug) { print_r($state); } + if(is_array($state)) { $mempool = array_merge($mempool, $state); } + unset($state); + } - unset($state); - } + $text_descr = rewrite_entity_descr($mempool['mempool_descr']); - $text_descr = rewrite_entity_descr($mempool['mempool_descr']); + $mempool_url = "graphs/id=".$mempool['mempool_id']."/type=mempool_usage/"; + $mini_url = "graph.php?id=".$mempool['mempool_id']."&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=80&height=20&bg=f4f4f4"; - $mempool_url = 'graphs/id='.$mempool['mempool_id'].'/type=mempool_usage/'; - $mini_url = 'graph.php?id='.$mempool['mempool_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; + $mempool_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$text_descr; + $mempool_popup .= "
    "; + $mempool_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; - $mempool_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; - $mempool_popup .= "
    "; - $mempool_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; + $total = formatStorage($mempool['mempool_total']); + $used = formatStorage($mempool['mempool_used']); + $free = formatStorage($mempool['mempool_free']); - $total = formatStorage($mempool['mempool_total']); - $used = formatStorage($mempool['mempool_used']); - $free = formatStorage($mempool['mempool_free']); + $perc = round($mempool['mempool_used'] / $mempool['mempool_total'] * 100); - $perc = round(($mempool['mempool_used'] / $mempool['mempool_total'] * 100)); + $background = get_percentage_colours($percent); + $right_background = $background['right']; + $left_background = $background['left']; - $background = get_percentage_colours($percent); - $right_background = $background['right']; - $left_background = $background['left']; + echo(" + + + + "); - echo " - - - - '; + echo(""); - echo ''; + $i++; +} - $i++; -}//end foreach +echo("
    " . $text_descr . " + ".print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $left_background, $free , "ffffff", $right_background)." + ".$perc."%
    ".$text_descr." - ".print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $left_background, $free, 'ffffff', $right_background).' - '.$perc.'%
    "); - echo "
    "; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; + include("includes/print-graphrow.inc.php"); - include 'includes/print-graphrow.inc.php'; + echo("
    "); +echo("
    "); -echo ''; -echo '
    '; +?> diff --git a/html/pages/device/health/processor.inc.php b/html/pages/device/health/processor.inc.php index 725e37c21f..bde4a3b3f1 100644 --- a/html/pages/device/health/processor.inc.php +++ b/html/pages/device/health/processor.inc.php @@ -1,43 +1,46 @@ "; -echo ''; +echo("
    "); +echo("
    "); $i = '1'; -foreach (dbFetchRows('SELECT * FROM `processors` WHERE device_id = ?', array($device['device_id'])) as $proc) { - $proc_url = 'graphs/id='.$proc['processor_id'].'/type=processor_usage/'; +foreach (dbFetchRows("SELECT * FROM `processors` WHERE device_id = ?", array($device['device_id'])) as $proc) +{ + $proc_url = "graphs/id=".$proc['processor_id']."/type=processor_usage/"; - $mini_url = 'graph.php?id='.$proc['processor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; + $mini_url = "graph.php?id=".$proc['processor_id']."&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=80&height=20&bg=f4f4f4"; - $text_descr = $proc['processor_descr']; + $text_descr = $proc['processor_descr']; - $text_descr = rewrite_entity_descr($text_descr); + $text_descr = rewrite_entity_descr($text_descr); - $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; - $proc_popup .= "
    "; - $proc_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; + $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$text_descr; + $proc_popup .= "
    "; + $proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; - $percent = round($proc['processor_usage']); + $percent = round($proc['processor_usage']); - $background = get_percentage_colours($percent); + $background = get_percentage_colours($percent); - echo (" - + echo(" + - '); + "); - echo "
    ".$text_descr."
    " . $text_descr . " - ".print_percentage_bar(400, 20, $percent, $percent.'%', 'ffffff', $background['left'], (100 - $percent).'%', 'ffffff', $background['right']).' + ".print_percentage_bar (400, 20, $percent, $percent."%", "ffffff", $background['left'], (100 - $percent)."%" , "ffffff", $background['right'])."
    "; + echo("
    "); - $graph_array['id'] = $proc['processor_id']; - $graph_array['type'] = $graph_type; + $graph_array['id'] = $proc['processor_id']; + $graph_array['type'] = $graph_type; - include 'includes/print-graphrow.inc.php'; -}//end foreach + include("includes/print-graphrow.inc.php"); +} -echo '
    '; -echo ''; +echo(""); +echo(""); + +?> diff --git a/html/pages/device/health/state.inc.php b/html/pages/device/health/state.inc.php index 9781248bea..5463962196 100644 --- a/html/pages/device/health/state.inc.php +++ b/html/pages/device/health/state.inc.php @@ -1,7 +1,7 @@ '; +echo(""); -echo ' +echo(" - '; + "); $row = 1; -foreach (dbFetchRows('SELECT * FROM `storage` WHERE device_id = ? ORDER BY storage_descr', array($device['device_id'])) as $drive) { - if (is_integer($row / 2)) { - $row_colour = $list_colour_a; - } - else { - $row_colour = $list_colour_b; - } +foreach (dbFetchRows("SELECT * FROM `storage` WHERE device_id = ? ORDER BY storage_descr", array($device['device_id'])) as $drive) +{ + if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - $total = $drive['storage_size']; - $used = $drive['storage_used']; - $free = $drive['storage_free']; - $perc = round($drive['storage_perc'], 0); - $used = formatStorage($used); - $total = formatStorage($total); - $free = formatStorage($free); + $total = $drive['storage_size']; + $used = $drive['storage_used']; + $free = $drive['storage_free']; + $perc = round($drive['storage_perc'], 0); + $used = formatStorage($used); + $total = formatStorage($total); + $free = formatStorage($free); - $fs_url = 'graphs/id='.$drive['storage_id'].'/type=storage_usage/'; + $fs_url = "graphs/id=".$drive['storage_id']."/type=storage_usage/"; - $fs_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$drive['storage_descr']; - $fs_popup .= "
    "; - $fs_popup .= "', RIGHT, FGCOLOR, '#e5e5e5');\" onmouseout=\"return nd();\""; + $fs_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$drive['storage_descr']; + $fs_popup .= "
    "; + $fs_popup .= "', RIGHT, FGCOLOR, '#e5e5e5');\" onmouseout=\"return nd();\""; - $background = get_percentage_colours($percent); + $background = get_percentage_colours($percent); - echo "'; + echo(""); - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; - echo "'; + echo(""); - $row++; -}//end foreach + $row++; +} -echo '
    Drive Usage Free
    ".$drive['storage_descr']." - ".print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $perc.'%', 'ffffff', $background['right']).' - '.$free.'
    " . $drive['storage_descr'] . " + ".print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $perc . "%", "ffffff", $background['right'])." + " . $free . "
    "; + echo("
    "); - include 'includes/print-graphrow.inc.php'; + include("includes/print-graphrow.inc.php"); - echo '
    '; +echo(""); + +?> diff --git a/html/pages/device/hrdevice.inc.php b/html/pages/device/hrdevice.inc.php index d16a0ba839..68928187b3 100644 --- a/html/pages/device/hrdevice.inc.php +++ b/html/pages/device/hrdevice.inc.php @@ -1,69 +1,70 @@ '; +echo(''); // FIXME missing heading -foreach (dbFetchRows('SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`', array($device['device_id'])) as $hrdevice) { - echo "'; - if ($hrdevice['hrDeviceType'] == 'hrDeviceProcessor') { - $proc_id = dbFetchCell("SELECT processor_id FROM processors WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrdevice['hrDeviceIndex']."'"); - $proc_url = 'device/device='.$device['device_id'].'/tab=health/metric=processor/'; - $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$hrdevice['hrDeviceDescr']; - $proc_popup .= "
    "; - $proc_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; - echo "'; +foreach (dbFetchRows("SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`", array($device['device_id'])) as $hrdevice) +{ + echo(""); - $graph_array['height'] = '20'; - $graph_array['width'] = '100'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $proc_id; - $graph_array['type'] = 'processor_usage'; - $graph_array['from'] = $config['time']['day']; - $graph_array_zoom = $graph_array; - $graph_array_zoom['height'] = '150'; - $graph_array_zoom['width'] = '400'; + if ($hrdevice['hrDeviceType'] == "hrDeviceProcessor") + { + $proc_id = dbFetchCell("SELECT processor_id FROM processors WHERE device_id = '".$device['device_id']."' AND hrDeviceIndex = '".$hrdevice['hrDeviceIndex']."'"); + $proc_url = "device/device=".$device['device_id']."/tab=health/metric=processor/"; + $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname']." - ".$hrdevice['hrDeviceDescr']; + $proc_popup .= "
    "; + $proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\""; + echo(""); - $mini_graph = overlib_link($proc_url, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + $graph_array['height'] = "20"; + $graph_array['width'] = "100"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $proc_id; + $graph_array['type'] = 'processor_usage'; + $graph_array['from'] = $config['time']['day']; + $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; - echo ''; + $mini_graph = overlib_link($proc_url, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); + + echo(''); + } + elseif ($hrdevice['hrDeviceType'] == "hrDeviceNetwork") + { + $int = str_replace("network interface ", "", $hrdevice['hrDeviceDescr']); + $interface = dbFetchRow("SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?", array($device['device_id'], $int)); + if ($interface['ifIndex']) + { + echo(""); + + $graph_array['height'] = "20"; + $graph_array['width'] = "100"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $interface['port_id']; + $graph_array['type'] = 'port_bits'; + $graph_array['from'] = $config['time']['day']; + $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = "150"; $graph_array_zoom['width'] = "400"; + + // FIXME click on graph should also link to port, but can't use generate_port_link here... + $mini_graph = overlib_link(generate_port_url($interface), generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); + + echo(""); + } else { + echo(""); + echo(""); } - else if ($hrdevice['hrDeviceType'] == 'hrDeviceNetwork') { - $int = str_replace('network interface ', '', $hrdevice['hrDeviceDescr']); - $interface = dbFetchRow('SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?', array($device['device_id'], $int)); - if ($interface['ifIndex']) { - echo ''; + } else { + echo(""); + echo(""); + } - $graph_array['height'] = '20'; - $graph_array['width'] = '100'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $interface['port_id']; - $graph_array['type'] = 'port_bits'; - $graph_array['from'] = $config['time']['day']; - $graph_array_zoom = $graph_array; - $graph_array_zoom['height'] = '150'; - $graph_array_zoom['width'] = '400'; + echo(""); + echo(""); + echo(""); +} - // FIXME click on graph should also link to port, but can't use generate_port_link here... - $mini_graph = overlib_link(generate_port_url($interface), generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); +echo('
    ".$hrdevice['hrDeviceIndex'].'".$hrdevice['hrDeviceDescr'].'
    ".$hrdevice['hrDeviceIndex']."".$hrdevice['hrDeviceDescr']."'.$mini_graph.''.$mini_graph.'".generate_port_link($interface)."$mini_graph".stripslashes($hrdevice['hrDeviceDescr'])."'.generate_port_link($interface).'".stripslashes($hrdevice['hrDeviceDescr'])."".$hrdevice['hrDeviceType'].''.$hrdevice['hrDeviceStatus']."".$hrdevice['hrDeviceErrors'].''.$hrdevice['hrProcessorLoad']."
    '); - echo "$mini_graph"; - } - else { - echo ''.stripslashes($hrdevice['hrDeviceDescr']).''; - echo ''; - } - } - else { - echo ''.stripslashes($hrdevice['hrDeviceDescr']).''; - echo ''; - }//end if +$pagetitle[] = "Inventory"; - echo ''.$hrdevice['hrDeviceType'].''.$hrdevice['hrDeviceStatus'].''; - echo ''.$hrdevice['hrDeviceErrors'].''.$hrdevice['hrProcessorLoad'].''; - echo ''; -}//end foreach - -echo ''; - -$pagetitle[] = 'Inventory'; +?> diff --git a/html/pages/device/loadbalancer/ace_rservers.inc.php b/html/pages/device/loadbalancer/ace_rservers.inc.php index c8b4b2acdc..52f1773c7e 100644 --- a/html/pages/device/loadbalancer/ace_rservers.inc.php +++ b/html/pages/device/loadbalancer/ace_rservers.inc.php @@ -33,10 +33,10 @@ echo ' Graphs: '; // "pkts" => "Packets", // "errors" => "Errors"); $graph_types = array( - 'curr' => 'CurrentConns', - 'failed' => 'FailedConns', - 'total' => 'TotalConns', -); + 'curr' => 'CurrentConns', + 'failed' => 'FailedConns', + 'total' => 'TotalConns', + ); foreach ($graph_types as $type => $descr) { echo "$type_sep"; @@ -66,8 +66,7 @@ foreach (dbFetchRows('SELECT * FROM `loadbalancer_rservers` WHERE `device_id` = if ($rserver['StateDescr'] == 'Server is now operational') { $rserver_class = 'green'; - } - else { + } else { $rserver_class = 'red'; } @@ -88,7 +87,7 @@ foreach (dbFetchRows('SELECT * FROM `loadbalancer_rservers` WHERE `device_id` = $graph_array['id'] = $rserver['rserver_id']; $graph_array['type'] = $graph_type; - require 'includes/print-graphrow.inc.php'; + include 'includes/print-graphrow.inc.php'; // include("includes/print-interface-graphs.inc.php"); echo ' diff --git a/html/pages/device/loadbalancer/ace_vservers.inc.php b/html/pages/device/loadbalancer/ace_vservers.inc.php index 68ebd1d3f5..65032709c8 100644 --- a/html/pages/device/loadbalancer/ace_vservers.inc.php +++ b/html/pages/device/loadbalancer/ace_vservers.inc.php @@ -2,101 +2,84 @@ print_optionbar_start(); -echo "Serverfarms » "; +echo("Serverfarms » "); -// $auth = TRUE; -$menu_options = array('basic' => 'Basic'); +#$auth = TRUE; -if (!$_GET['opta']) { - $_GET['opta'] = 'basic'; -} +$menu_options = array('basic' => 'Basic', + ); -$sep = ''; -foreach ($menu_options as $option => $text) { - if ($_GET['type'] == $option) { - echo ""; - } +if (!$_GET['opta']) { $_GET['opta'] = "basic"; } - echo ''.$text.''; - if ($_GET['type'] == $option) { - echo ''; - } - - echo ' | '; +$sep = ""; +foreach ($menu_options as $option => $text) +{ + if ($_GET['type'] == $option) { echo(""); } + echo(''.$text.''); + if ($_GET['type'] == $option) { echo(""); } + echo(" | "); } unset($sep); -echo ' Graphs: '; +echo(' Graphs: '); -$graph_types = array( - 'bits' => 'Bits', - 'pkts' => 'Packets', - 'conns' => 'Connections', -); +$graph_types = array("bits" => "Bits", + "pkts" => "Packets", + "conns" => "Connections"); -foreach ($graph_types as $type => $descr) { - echo "$type_sep"; - if ($_GET['opte'] == $type) { - echo ""; - } +foreach ($graph_types as $type => $descr) +{ + echo("$type_sep"); + if ($_GET['opte'] == $type) { echo(""); } + echo(''.$descr.''); + echo(''.$text.''); + if ($_GET['opte'] == $type) { echo(""); } - echo ''.$descr.''; - echo ''.$text.''; - if ($_GET['opte'] == $type) { - echo ''; - } - - $type_sep = ' | '; + $type_sep = " | "; } print_optionbar_end(); -echo "
    "; -$i = '0'; -foreach (dbFetchRows('SELECT * FROM `loadbalancer_vservers` WHERE `device_id` = ? ORDER BY `classmap`', array($device['device_id'])) as $vserver) { - if (is_integer($i / 2)) { - $bg_colour = $list_colour_a; - } - else { - $bg_colour = $list_colour_b; - } +echo("
    "); +$i = "0"; +foreach (dbFetchRows("SELECT * FROM `loadbalancer_vservers` WHERE `device_id` = ? ORDER BY `classmap`", array($device['device_id'])) as $vserver) +{ +if (is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } - if ($vserver['serverstate'] == 'inService') { - $vserver_class = 'green'; - } - else { - $vserver_class = 'red'; - } +if($vserver['serverstate'] == "inService") { $vserver_class="green"; } else { $vserver_class="red"; } - echo ""; - // echo(""); - echo ''; - // echo(""); - echo "'; - echo ''; - if ($_GET['type'] == 'graphs') { - echo ''; - echo '"); +#echo(""); +echo(""); +#echo(""); +echo(""); +echo(""); + if ($_GET['type'] == "graphs") + { + echo(''); + echo(" - '; - } + echo(" + + "); + } - echo ''; - echo ''; +echo(""); +echo(""); - $i++; -}//end foreach + $i++; +} -echo '
    " . $tunnel['local_addr'] . " » " . $tunnel['peer_addr'] . "'.$vserver['classmap'].'" . $rserver['farm_id'] . "".$vserver['serverstate'].'
    '; - $graph_type = 'vserver_'.$_GET['opte']; +echo("
    " . $tunnel['local_addr'] . " » " . $tunnel['peer_addr'] . "" . $vserver['classmap'] . "" . $rserver['farm_id'] . "" . $vserver['serverstate'] . "
    "); + $graph_type = "vserver_" . $_GET['opte']; - $graph_array['height'] = '100'; - $graph_array['width'] = '215'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $vserver['classmap_id']; - $graph_array['type'] = $graph_type; +$graph_array['height'] = "100"; +$graph_array['width'] = "215"; +$graph_array['to'] = $config['time']['now']; +$graph_array['id'] = $vserver['classmap_id']; +$graph_array['type'] = $graph_type; - include 'includes/print-graphrow.inc.php'; +include("includes/print-graphrow.inc.php"); - echo ' -
    '; +echo(""); + +?> diff --git a/html/pages/device/loadbalancer/netscaler_vsvr.inc.php b/html/pages/device/loadbalancer/netscaler_vsvr.inc.php index 91abc8204f..a67d755b9a 100644 --- a/html/pages/device/loadbalancer/netscaler_vsvr.inc.php +++ b/html/pages/device/loadbalancer/netscaler_vsvr.inc.php @@ -1,6 +1,6 @@ VServer » "); // echo('All'); diff --git a/html/pages/device/logs.inc.php b/html/pages/device/logs.inc.php index 11fd6914ba..0b8481a68f 100644 --- a/html/pages/device/logs.inc.php +++ b/html/pages/device/logs.inc.php @@ -1,43 +1,41 @@ Logging » '; +echo("Logging » "); -if ($vars['section'] == 'eventlog') { - echo ''; +if ($vars['section'] == "eventlog") { + echo(''); } - -echo generate_link('Event Log', $vars, array('section' => 'eventlog')); -if ($vars['section'] == 'eventlog') { - echo ''; +echo(generate_link("Event Log" , $vars, array('section'=>'eventlog'))); +if ($vars['section'] == "eventlog") { + echo(""); } if (isset($config['enable_syslog']) && $config['enable_syslog'] == 1) { - echo ' | '; + echo(" | "); - if ($vars['section'] == 'syslog') { - echo ''; + if ($vars['section'] == "syslog") { + echo(''); } - - echo generate_link('Syslog', $vars, array('section' => 'syslog')); - if ($vars['section'] == 'syslog') { - echo ''; + echo(generate_link("Syslog" , $vars, array('section'=>'syslog'))); + if ($vars['section'] == "syslog") { + echo(""); } } -switch ($vars['section']) { - case 'syslog': - case 'eventlog': - include 'pages/device/logs/'.$vars['section'].'.inc.php'; - break; - - default: - print_optionbar_end(); - echo report_this('Unknown section '.$vars['section']); - break; +switch ($vars['section']) +{ + case 'syslog': + case 'eventlog': + include('pages/device/logs/'.$vars['section'].'.inc.php'); + break; + default: + print_optionbar_end(); + echo(report_this('Unknown section '.$vars['section'])); + break; } + +?> diff --git a/html/pages/device/logs/eventlog.inc.php b/html/pages/device/logs/eventlog.inc.php index 7d5204f1cd..aec8bdd98c 100644 --- a/html/pages/device/logs/eventlog.inc.php +++ b/html/pages/device/logs/eventlog.inc.php @@ -2,49 +2,51 @@
    +echo('
    Eventlog entries
    - '; +
    '); -foreach ($entries as $entry) { - include 'includes/print-event.inc.php'; +foreach ($entries as $entry) +{ + include("includes/print-event.inc.php"); } -echo '
    -
    '; +echo(' + '); -$pagetitle[] = 'Events'; +$pagetitle[] = "Events"; + +?> diff --git a/html/pages/device/logs/syslog.inc.php b/html/pages/device/logs/syslog.inc.php index 1284ad157f..7aae3b8e0c 100644 --- a/html/pages/device/logs/syslog.inc.php +++ b/html/pages/device/logs/syslog.inc.php @@ -3,54 +3,53 @@
    +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? $where"; +$sql .= " ORDER BY timestamp DESC LIMIT 1000"; +echo('
    Syslog entries
    - '; -foreach (dbFetchRows($sql, $param) as $entry) { - include 'includes/print-syslog.inc.php'; -} +
    '); +foreach (dbFetchRows($sql, $param) as $entry) { include("includes/print-syslog.inc.php"); } +echo('
    +
    '); +$pagetitle[] = "Syslog"; -echo ' - '; -$pagetitle[] = 'Syslog'; +?> diff --git a/html/pages/device/map.inc.php b/html/pages/device/map.inc.php index 918f62e7fc..522de36a51 100644 --- a/html/pages/device/map.inc.php +++ b/html/pages/device/map.inc.php @@ -12,6 +12,8 @@ * the source code distribution for details. */ -$pagetitle[] = 'Map'; +$pagetitle[] = "Map"; -require_once 'includes/print-map.inc.php'; +require_once "includes/print-map.inc.php"; + +?> diff --git a/html/pages/device/munin.inc.php b/html/pages/device/munin.inc.php index e12279687e..67fd22d6e0 100644 --- a/html/pages/device/munin.inc.php +++ b/html/pages/device/munin.inc.php @@ -1,72 +1,75 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'munin', -); -$bg = '#ffffff'; +$link_array = array('page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'munin'); -echo '
    '; +$bg="#ffffff"; + +echo('
    '); print_optionbar_start(); -echo "Munin » "; +echo("Munin » "); -$sep = ''; +$sep = ""; -foreach (dbFetchRows('SELECT * FROM munin_plugins WHERE device_id = ? ORDER BY mplug_category, mplug_type', array($device['device_id'])) as $mplug) { - // if (strlen($mplug['mplug_category']) == 0) { $mplug['mplug_category'] = "general"; } else { } - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['id'] = $mplug['mplug_id']; - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['title'] = $mplug['mplug_title']; - $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['plugin'] = $mplug['mplug_type']; +foreach (dbFetchRows("SELECT * FROM munin_plugins WHERE device_id = ? ORDER BY mplug_category, mplug_type", array($device['device_id'])) as $mplug) +{ +# if (strlen($mplug['mplug_category']) == 0) { $mplug['mplug_category'] = "general"; } else { } + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['id'] = $mplug['mplug_id']; + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['title'] = $mplug['mplug_title']; + $graph_enable[$mplug['mplug_category']][$mplug['mplug_type']]['plugin'] = $mplug['mplug_type']; } -foreach ($graph_enable as $section => $nothing) { - if (isset($graph_enable) && is_array($graph_enable[$section])) { - $type = strtolower($section); - if (!$vars['group']) { - $vars['group'] = $type; - } - - echo $sep; - if ($vars['group'] == $type) { - echo ''; - } - - echo generate_link(ucwords($type), $link_array, array('group' => $type)); - if ($vars['group'] == $type) { - echo ''; - } - - $sep = ' | '; +foreach ($graph_enable as $section => $nothing) +{ + if (isset($graph_enable) && is_array($graph_enable[$section])) + { + $type = strtolower($section); + if (!$vars['group']) { $vars['group'] = $type; } + echo($sep); + if ($vars['group'] == $type) + { + echo(''); } + echo(generate_link(ucwords($type),$link_array,array('group'=>$type))); + if ($vars['group'] == $type) + { + echo(""); + } + $sep = " | "; + } } -unset($sep); +unset ($sep); print_optionbar_end(); $graph_enable = $graph_enable[$vars['group']]; -// foreach ($config['graph_types']['device'] as $graph => $entry) -foreach ($graph_enable as $graph => $entry) { - $graph_array = array(); - if ($graph_enable[$graph]) { - if (!empty($entry['plugin'])) { - $graph_title = $entry['title']; - $graph_array['type'] = 'munin_graph'; - $graph_array['device'] = $device['device_id']; - $graph_array['plugin'] = $entry['plugin']; - } - else { - $graph_title = $config['graph_types']['device'][$graph]['descr']; - $graph_array['type'] = 'device_'.$graph; - } - - include 'includes/print-device-graph.php'; +#foreach ($config['graph_types']['device'] as $graph => $entry) +foreach ($graph_enable as $graph => $entry) +{ + $graph_array = array(); + if ($graph_enable[$graph]) + { + if (!empty($entry['plugin'])) + { + $graph_title = $entry['title']; + $graph_array['type'] = "munin_graph"; + $graph_array['device'] = $device['device_id']; + $graph_array['plugin'] = $entry['plugin']; + } else { + $graph_title = $config['graph_types']['device'][$graph]['descr']; + $graph_array['type'] = "device_" . $graph; } + + include("includes/print-device-graph.php"); + } } -$pagetitle[] = 'Graphs'; +$pagetitle[] = "Graphs"; + +?> diff --git a/html/pages/device/overview.inc.php b/html/pages/device/overview.inc.php index 13227e0136..aac3b2ca23 100644 --- a/html/pages/device/overview.inc.php +++ b/html/pages/device/overview.inc.php @@ -12,18 +12,8 @@ $services['up'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WH $services['down'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_status` = '0' AND `service_ignore` = '0'", array($device['device_id'])); $services['disabled'] = dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `device_id` = ? AND `service_ignore` = '1'", array($device['device_id'])); -if ($services['down']) { - $services_colour = $warn_colour_a; -} -else { - $services_colour = $list_colour_a; -} -if ($ports['down']) { - $ports_colour = $warn_colour_a; -} -else { - $ports_colour = $list_colour_a; -} +if ($services['down']) { $services_colour = $warn_colour_a; } else { $services_colour = $list_colour_a; } +if ($ports['down']) { $ports_colour = $warn_colour_a; } else { $ports_colour = $list_colour_a; } echo('
    @@ -35,41 +25,39 @@ echo('
    '); -require 'includes/dev-overview-data.inc.php'; +include("includes/dev-overview-data.inc.php"); Plugins::call('device_overview_container',array($device)); -require 'overview/ports.inc.php'; +include("overview/ports.inc.php"); echo('
    '); // Right Pane -require 'overview/processors.inc.php'; -require 'overview/mempools.inc.php'; -require 'overview/storage.inc.php'; +include("overview/processors.inc.php"); +include("overview/mempools.inc.php"); +include("overview/storage.inc.php"); -if(is_array($entity_state['group']['c6kxbar'])) { - require 'overview/c6kxbar.inc.php'; -} +if(is_array($entity_state['group']['c6kxbar'])) { include("overview/c6kxbar.inc.php"); } -require 'overview/toner.inc.php'; -require 'overview/sensors/charge.inc.php'; -require 'overview/sensors/temperatures.inc.php'; -require 'overview/sensors/humidity.inc.php'; -require 'overview/sensors/fanspeeds.inc.php'; -require 'overview/sensors/dbm.inc.php'; -require 'overview/sensors/voltages.inc.php'; -require 'overview/sensors/current.inc.php'; -require 'overview/sensors/power.inc.php'; -require 'overview/sensors/frequencies.inc.php'; -require 'overview/sensors/load.inc.php'; -require 'overview/sensors/state.inc.php'; -require 'overview/eventlog.inc.php'; -require 'overview/services.inc.php'; -require 'overview/syslog.inc.php'; +include("overview/toner.inc.php"); +include("overview/sensors/charge.inc.php"); +include("overview/sensors/temperatures.inc.php"); +include("overview/sensors/humidity.inc.php"); +include("overview/sensors/fanspeeds.inc.php"); +include("overview/sensors/dbm.inc.php"); +include("overview/sensors/voltages.inc.php"); +include("overview/sensors/current.inc.php"); +include("overview/sensors/power.inc.php"); +include("overview/sensors/frequencies.inc.php"); +include("overview/sensors/load.inc.php"); +include("overview/sensors/state.inc.php"); +include("overview/eventlog.inc.php"); +include("overview/services.inc.php"); +include("overview/syslog.inc.php"); echo('
    '); -#require 'overview/current.inc.php"); +#include("overview/current.inc.php"); ?> diff --git a/html/pages/device/overview/c6kxbar.inc.php b/html/pages/device/overview/c6kxbar.inc.php index eb04e0a7db..14f5d54e48 100644 --- a/html/pages/device/overview/c6kxbar.inc.php +++ b/html/pages/device/overview/c6kxbar.inc.php @@ -1,99 +1,102 @@ -
    -
    -
    -
    '; -echo ''; -echo " Catalyst 6k Crossbar"; -echo '
    - '; + echo('
    +
    +
    +
    +
    '); +echo(''); +echo(" Catalyst 6k Crossbar"); +echo('
    +
    '); -foreach ($entity_state['group']['c6kxbar'] as $index => $entry) { - // FIXME i'm not sure if this is the correct way to decide what entphysical index it is. slotnum+1? :> - $entity = dbFetchRow('SELECT * FROM entPhysical WHERE device_id = ? AND entPhysicalIndex = ?', array($device['device_id'], $index + 1)); +foreach ($entity_state['group']['c6kxbar'] as $index => $entry) +{ + // FIXME i'm not sure if this is the correct way to decide what entphysical index it is. slotnum+1? :> + $entity = dbFetchRow("SELECT * FROM entPhysical WHERE device_id = ? AND entPhysicalIndex = ?", array($device['device_id'], $index+1)); - echo " + echo(" - - '; + echo(" + "); - foreach ($entity_state['group']['c6kxbar'][$index] as $subindex => $fabric) { - if (is_numeric($subindex)) { - if ($fabric['cc6kxbarModuleChannelFabStatus'] == 'ok') { - $fabric['mode_class'] = 'green'; - } - else { - $fabric['mode_class'] = 'red'; - } + foreach ($entity_state['group']['c6kxbar'][$index] as $subindex => $fabric) + { + if (is_numeric($subindex)) + { + if ($fabric['cc6kxbarModuleChannelFabStatus'] == "ok") + { + $fabric['mode_class'] = "green"; + } else { + $fabric['mode_class'] = "red"; + } - $percent_in = $fabric['cc6kxbarStatisticsInUtil']; - $background_in = get_percentage_colours($percent_in); + $percent_in = $fabric['cc6kxbarStatisticsInUtil']; + $background_in = get_percentage_colours($percent_in); - $percent_out = $fabric['cc6kxbarStatisticsOutUtil']; - $background_out = get_percentage_colours($percent_out); + $percent_out = $fabric['cc6kxbarStatisticsOutUtil']; + $background_out = get_percentage_colours($percent_out); - $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device['device_id']; - $graph_array['mod'] = $index; - $graph_array['chan'] = $subindex; - $graph_array['type'] = 'c6kxbar_util'; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $graph_array = array(); + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device['device_id']; + $graph_array['mod'] = $index; + $graph_array['chan'] = $subindex; + $graph_array['type'] = "c6kxbar_util"; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $text_descr = $entity['entPhysicalName'].' - Fabric '.$subindex; + $text_descr = $entity['entPhysicalName'] . " - Fabric " . $subindex; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. - $minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. - echo (' - - - + + + + + + + "); + } + } +} + +echo("
    ".$entity['entPhysicalName'].""; + "); - switch ($entry['']['cc6kxbarModuleModeSwitchingMode']) { - case 'busmode': - // echo 'Bus'; + switch ($entry['']['cc6kxbarModuleModeSwitchingMode']) + { + case "busmode": + # echo 'Bus'; break; - - case 'crossbarmode': + case "crossbarmode": echo 'Crossbar'; break; - - case 'dcefmode': + case "dcefmode": echo 'DCEF'; break; - - default: + default: echo $entry['']['cc6kxbarModuleModeSwitchingMode']; } - echo '
    Fabric '.$subindex." + Fabric ".$subindex."". + + $fabric['cc6kxbarModuleChannelFabStatus']."".formatRates($fabric['cc6kxbarModuleChannelSpeed']*1000000)."".overlib_link($link, $minigraph, $overlib_content)."".print_percentage_bar (125, 20, $percent_in, "Ingress", "ffffff", $background['left'], $percent_in . "%", "ffffff", $background['right'])."".print_percentage_bar (125, 20, $percent_out, "Egress", "ffffff", $background['left'], $percent_out . "%", "ffffff", $background['right'])."
    "); +echo("
    "); +echo("
    "); +echo("
    "); +echo("
    "); + +?> diff --git a/html/pages/device/overview/eventlog.inc.php b/html/pages/device/overview/eventlog.inc.php index d555118136..ff235aa4a8 100644 --- a/html/pages/device/overview/eventlog.inc.php +++ b/html/pages/device/overview/eventlog.inc.php @@ -1,22 +1,25 @@ '; -echo '
    +echo('
    '); + echo('
    -
    '; -echo ''; -echo " Recent Events"; -echo '
    - '; +
    '); +echo(''); +echo(" Recent Events"); +echo('
    +
    '); $eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` WHERE `host` = ? ORDER BY `datetime` DESC LIMIT 0,10", array($device['device_id'])); -foreach ($eventlog as $entry) { - include 'includes/print-event-short.inc.php'; +foreach ($eventlog as $entry) +{ + include("includes/print-event-short.inc.php"); } -echo '
    '; -echo '
    '; -echo '
    '; -echo '
    '; -echo '
    '; +echo(""); +echo('
    '); +echo('
    '); +echo(''); +echo(''); + +?> diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index 36bc05cd5d..6194c37c00 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -1,71 +1,75 @@ +if (count($sensors)) +{ + echo('
    -
    -
    -
    '; - echo ' '.$sensor_type.''; - echo '
    - '; - foreach ($sensors as $sensor) { - if ($config['memcached']['enable'] === true) { - $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); - } +
    +
    +
    '); + echo(' ' . $sensor_type . ''); + echo('
    +
    '); + foreach ($sensors as $sensor) + { + if ($config['memcached']['enable'] === TRUE) + { + $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); + } - if (empty($sensor['sensor_current'])) { - $sensor['sensor_current'] = 'NaN'; - } + if (empty($sensor['sensor_current'])) + { + $sensor['sensor_current'] = "NaN"; + } - // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. - // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? - // FIXME - DUPLICATED IN health/sensors - $graph_colour = str_replace('#', '', $row_colour); + // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. + // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? + // FIXME - DUPLICATED IN health/sensors - $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $sensor['sensor_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $graph_colour = str_replace("#", "", $row_colour); - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $graph_array = array(); + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $sensor['sensor_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; - $overlib_content = '

    '.$device['hostname'].' - '.$sensor['sensor_descr'].'

    '; - foreach (array('day', 'week', 'month', 'year') as $period) { - $graph_array['from'] = $config['time'][$period]; - $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); - } + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content .= '
    '; + $overlib_content = '

    '.$device['hostname']." - ".$sensor['sensor_descr']."

    "; + foreach (array('day','week','month','year') as $period) + { + $graph_array['from'] = $config['time'][$period]; + $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); + } + $overlib_content .= "
    "; - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. - $graph_array['from'] = $config['time']['day']; - $sensor_minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. + $graph_array['from'] = $config['time']['day']; + $sensor_minigraph = generate_graph_tag($graph_array); - $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); + $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); - echo ' - - - - '; - }//end foreach + echo(" + + + + "); + } - echo '
    '.overlib_link($link, $sensor['sensor_descr'], $overlib_content).''.overlib_link($link, $sensor_minigraph, $overlib_content).''.overlib_link($link, ' $sensor['sensor_limit'] ? "style='color: red'" : '').'>'.$sensor['sensor_current'].$sensor_unit.'', $overlib_content).'
    ".overlib_link($link, $sensor['sensor_descr'], $overlib_content)."".overlib_link($link, $sensor_minigraph, $overlib_content)."".overlib_link($link, " $sensor['sensor_limit'] ? "style='color: red'" : '') . '>' . $sensor['sensor_current'] . $sensor_unit . "", $overlib_content)."
    '; - echo '
    '; - echo '
    '; - echo '
    '; - echo '
    '; -}//end if + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); +} + +?> diff --git a/html/pages/device/overview/mempools.inc.php b/html/pages/device/overview/mempools.inc.php index 0699872416..3d35a8d554 100644 --- a/html/pages/device/overview/mempools.inc.php +++ b/html/pages/device/overview/mempools.inc.php @@ -1,77 +1,76 @@ +if (count($mempools)) +{ + echo('
    -
    -
    -
    - '; - echo ''; - echo " Memory Pools"; - echo ' -
    - - '; +
    +
    +
    +'); + echo(''); + echo(" Memory Pools"); + echo(' +
    +
    +'); - foreach ($mempools as $mempool) { - if ($config['memcached']['enable'] === true) { - $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); - if ($debug) { - print_r($state); - } + foreach ($mempools as $mempool) + { - if (is_array($state)) { - $mempool = array_merge($mempool, $state); - } + if ($config['memcached']['enable'] === TRUE) + { + $state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state'); + if($debug) { print_r($state); } + if(is_array($state)) { $mempool = array_merge($mempool, $state); } + unset($state); + } - unset($state); - } + $percent= round($mempool['mempool_perc'],0); + $text_descr = rewrite_entity_descr($mempool['mempool_descr']); + $total = formatStorage($mempool['mempool_total']); + $used = formatStorage($mempool['mempool_used']); + $free = formatStorage($mempool['mempool_free']); + $background = get_percentage_colours($percent); - $percent = round($mempool['mempool_perc'], 0); - $text_descr = rewrite_entity_descr($mempool['mempool_descr']); - $total = formatStorage($mempool['mempool_total']); - $used = formatStorage($mempool['mempool_used']); - $free = formatStorage($mempool['mempool_free']); - $background = get_percentage_colours($percent); + $graph_array = array(); + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $mempool['mempool_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; - $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $mempool['mempool_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. - $minigraph = generate_graph_tag($graph_array); + $minigraph = generate_graph_tag($graph_array); - echo ' - - - - '; - }//end foreach + echo(" + + + + "); + } - echo '
    '.overlib_link($link, $text_descr, $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).' -
    ".overlib_link($link, $text_descr, $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." +
    + echo('
    -
    '; -}//end if + '); + +} + +?> diff --git a/html/pages/device/overview/ports.inc.php b/html/pages/device/overview/ports.inc.php index 75cf3ca29f..807f8ee4fb 100644 --- a/html/pages/device/overview/ports.inc.php +++ b/html/pages/device/overview/ports.inc.php @@ -1,64 +1,68 @@ '; - echo '
    +if ($ports['total']) +{ + echo('
    '); + echo('
    Overall Traffic
    - '; +
    '); - $graph_array['height'] = '100'; - $graph_array['width'] = '485'; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device['device_id']; - $graph_array['type'] = 'device_bits'; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; - $graph = generate_graph_tag($graph_array); + $graph_array['height'] = "100"; + $graph_array['width'] = "485"; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device['device_id']; + $graph_array['type'] = "device_bits"; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; + $graph = generate_graph_tag($graph_array); - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width']); + $link = generate_url($link_array); - $graph_array['width'] = '210'; - $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - Device Traffic'); + $graph_array['width'] = "210"; + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - Device Traffic"); - echo ' - - '; + echo(' + + '); - echo ' + echo(' - - - - - '; + + + + + '); - echo ' - + '; - echo ''; - echo '
    '; - echo overlib_link($link, $graph, $overlib_content, null); - echo '
    '); + echo(overlib_link($link, $graph, $overlib_content, NULL)); + echo('
    '.$ports['total'].' '.$ports['up'].' '.$ports['down'].' '.$ports['disabled'].'
    ' . $ports['total'] . ' ' . $ports['up'] . ' ' . $ports['down'] . ' ' . $ports['disabled'] . '
    '; + echo('
    '); - $ifsep = ''; + $ifsep = ""; - foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) { - $data = ifNameDescr($data); - $data = array_merge($data, $device); - echo "$ifsep".generate_port_link($data, makeshortif(strtolower($data['label']))); - $ifsep = ', '; - } + foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) + { + $data = ifNameDescr($data); + $data = array_merge($data, $device); + echo("$ifsep" . generate_port_link($data, makeshortif(strtolower($data['label'])))); + $ifsep = ", "; + } - unset($ifsep); - echo '
    '; - echo '
    '; - echo '
    '; - echo '
    '; - echo '
    '; -}//end if + unset($ifsep); + echo(" "); + echo(""); + echo(""); + echo("
    "); + echo(""); + echo(""); + echo(""); +} + +?> diff --git a/html/pages/device/overview/processors.inc.php b/html/pages/device/overview/processors.inc.php index 8b4d3f2912..3394e263ca 100644 --- a/html/pages/device/overview/processors.inc.php +++ b/html/pages/device/overview/processors.inc.php @@ -1,63 +1,66 @@ +if (count($processors)) +{ + echo('
    -'; - echo ''; - echo " Processors"; - echo '
    - '; +'); + echo(''); + echo(" Processors"); + echo(' +
    '); - foreach ($processors as $proc) { - $text_descr = rewrite_entity_descr($proc['processor_descr']); + foreach ($processors as $proc) + { + $text_descr = rewrite_entity_descr($proc['processor_descr']); - // disable short hrDeviceDescr. need to make this prettier. - // $text_descr = short_hrDeviceDescr($proc['processor_descr']); - $percent = $proc['processor_usage']; - $background = get_percentage_colours($percent); - $graph_colour = str_replace('#', '', $row_colour); + # disable short hrDeviceDescr. need to make this prettier. + #$text_descr = short_hrDeviceDescr($proc['processor_descr']); + $percent = $proc['processor_usage']; + $background = get_percentage_colours($percent); + $graph_colour = str_replace("#", "", $row_colour); - $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $proc['processor_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $graph_array = array(); + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $proc['processor_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$text_descr); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $text_descr); - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. - $minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. - echo ' - - - + + + - '; - }//end foreach + "); + } - echo '
    '.overlib_link($link, $text_descr, $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).' + $minigraph = generate_graph_tag($graph_array); + + echo("
    ".overlib_link($link, $text_descr, $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)."
    + echo('
    -
    '; -}//end if + '); + +} + +?> diff --git a/html/pages/device/overview/sensors/charge.inc.php b/html/pages/device/overview/sensors/charge.inc.php index b0df00968a..bf40977499 100644 --- a/html/pages/device/overview/sensors/charge.inc.php +++ b/html/pages/device/overview/sensors/charge.inc.php @@ -1,8 +1,10 @@ diff --git a/html/pages/device/overview/sensors/load.inc.php b/html/pages/device/overview/sensors/load.inc.php index 089f93dffb..989a305b9b 100644 --- a/html/pages/device/overview/sensors/load.inc.php +++ b/html/pages/device/overview/sensors/load.inc.php @@ -1,8 +1,8 @@ '; - echo '
    +if ($services['total']) +{ +echo('
    '); + echo('
    -
    '; - echo " Services"; - echo '
    - '; +
    '); + echo(" Services"); + echo('
    +
    '); - echo " + echo(" @@ -18,32 +19,22 @@ echo '
    ';
    -
    $services[total] $services[up] $services[disabled]
    "; +"); - foreach (dbFetchRows('SELECT * FROM services WHERE device_id = ? ORDER BY service_type', array($device['device_id'])) as $data) { - if ($data['service_status'] == '0' && $data['service_ignore'] == '1') { - $status = 'grey'; - } + foreach (dbFetchRows("SELECT * FROM services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $data) + { + if ($data['service_status'] == "0" && $data['service_ignore'] == "1") { $status = "grey"; } + if ($data['service_status'] == "1" && $data['service_ignore'] == "1") { $status = "green"; } + if ($data['service_status'] == "0" && $data['service_ignore'] == "0") { $status = "red"; } + if ($data['service_status'] == "1" && $data['service_ignore'] == "0") { $status = "blue"; } + echo("$break" . strtolower($data['service_type']) . ""); + $break = ", "; + } + echo('
    '); + echo("
    "); + echo("
    "); + echo("
    "); + echo("
    "); +} - if ($data['service_status'] == '1' && $data['service_ignore'] == '1') { - $status = 'green'; - } - - if ($data['service_status'] == '0' && $data['service_ignore'] == '0') { - $status = 'red'; - } - - if ($data['service_status'] == '1' && $data['service_ignore'] == '0') { - $status = 'blue'; - } - - echo "$break".strtolower($data['service_type']).''; - $break = ', '; - } - - echo ''; - echo '
    '; - echo ''; - echo ''; - echo ''; -}//end if +?> diff --git a/html/pages/device/overview/storage.inc.php b/html/pages/device/overview/storage.inc.php index e81b1b5b5d..01c02edb4e 100644 --- a/html/pages/device/overview/storage.inc.php +++ b/html/pages/device/overview/storage.inc.php @@ -1,86 +1,91 @@ +if (count($drives)) +{ + echo('
    -
    '; - echo ''; - echo " Storage"; - echo '
    - '; +
    '); + echo(''); + echo(" Storage"); + echo('
    +
    '); - foreach ($drives as $drive) { - $skipdrive = 0; + foreach ($drives as $drive) + { + $skipdrive = 0; - if ($device['os'] == 'junos') { - foreach ($config['ignore_junos_os_drives'] as $jdrive) { - if (preg_match($jdrive, $drive['storage_descr'])) { - $skipdrive = 1; - } - } - - $drive['storage_descr'] = preg_replace('/.*mounted on: (.*)/', '\\1', $drive['storage_descr']); + if ($device["os"] == "junos") + { + foreach ($config['ignore_junos_os_drives'] as $jdrive) + { + if (preg_match($jdrive, $drive["storage_descr"])) + { + $skipdrive = 1; } + } + $drive["storage_descr"] = preg_replace("/.*mounted on: (.*)/", "\\1", $drive["storage_descr"]); + } - if ($device['os'] == 'freebsd') { - foreach ($config['ignore_bsd_os_drives'] as $jdrive) { - if (preg_match($jdrive, $drive['storage_descr'])) { - $skipdrive = 1; - } - } + if ($device['os'] == "freebsd") + { + foreach ($config['ignore_bsd_os_drives'] as $jdrive) + { + if (preg_match($jdrive, $drive["storage_descr"])) + { + $skipdrive = 1; } + } + } - if ($skipdrive) { - continue; - } + if ($skipdrive) { continue; } + $percent = round($drive['storage_perc'], 0); + $total = formatStorage($drive['storage_size']); + $free = formatStorage($drive['storage_free']); + $used = formatStorage($drive['storage_used']); + $background = get_percentage_colours($percent); - $percent = round($drive['storage_perc'], 0); - $total = formatStorage($drive['storage_size']); - $free = formatStorage($drive['storage_free']); - $used = formatStorage($drive['storage_used']); - $background = get_percentage_colours($percent); + $graph_array = array(); + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $drive['storage_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; - $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $drive['storage_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $drive['storage_descr']); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$drive['storage_descr']); + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. - $minigraph = generate_graph_tag($graph_array); + $minigraph = generate_graph_tag($graph_array); - echo ' - - - + + + - '; - }//end foreach + "); + } - echo '
    '.overlib_link($link, $drive['storage_descr'], $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).' + echo("
    ".overlib_link($link, $drive['storage_descr'], $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)."
    + echo('
    -
    '; -}//end if + '); -unset($drive_rows); +} + +unset ($drive_rows); + +?> diff --git a/html/pages/device/overview/syslog.inc.php b/html/pages/device/overview/syslog.inc.php index bcfb6d2c52..1d26fbb2a7 100644 --- a/html/pages/device/overview/syslog.inc.php +++ b/html/pages/device/overview/syslog.inc.php @@ -1,24 +1,25 @@ '; - echo '
    +if ($config['enable_syslog']) +{ + $syslog = dbFetchRows("SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? ORDER BY timestamp DESC LIMIT 20", array($device['device_id'])); + if (count($syslog)) + { +echo('
    '); + echo('
    -
    '; - echo ' Recent Syslog'; - echo '
    - '; - foreach ($syslog as $entry) { - include 'includes/print-syslog.inc.php'; - } - - echo '
    '; - echo '
    '; - echo '
    '; - echo '
    '; - echo '
    '; - } +
    '); + echo(' Recent Syslog'); +echo('
    + '); + foreach ($syslog as $entry) { include("includes/print-syslog.inc.php"); } + echo("
    "); + echo("
    "); + echo(""); + echo(""); + echo(""); + } } + +?> diff --git a/html/pages/device/overview/toner.inc.php b/html/pages/device/overview/toner.inc.php index 7c789573c5..347a636195 100644 --- a/html/pages/device/overview/toner.inc.php +++ b/html/pages/device/overview/toner.inc.php @@ -1,62 +1,64 @@ +if (count($toners)) +{ + echo('
    -
    '; - echo ''; - echo " Toner"; - echo '
    - '; +
    '); + echo(''); + echo(" Toner"); + echo('
    +
    '); - foreach ($toners as $toner) { - $percent = round($toner['toner_current'], 0); - $total = formatStorage($toner['toner_size']); - $free = formatStorage($toner['toner_free']); - $used = formatStorage($toner['toner_used']); + foreach ($toners as $toner) + { + $percent = round($toner['toner_current'], 0); + $total = formatStorage($toner['toner_size']); + $free = formatStorage($toner['toner_free']); + $used = formatStorage($toner['toner_used']); - $background = toner2colour($toner['toner_descr'], $percent); + $background = toner2colour($toner['toner_descr'], $percent); - $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $toner['toner_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $graph_array = array(); + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $toner['toner_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$toner['toner_descr']); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $toner['toner_descr']); - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. - $minigraph = generate_graph_tag($graph_array); + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. - echo ' - - - + + + - '; - }//end foreach + "); + } - echo '
    '.overlib_link($link, $toner['toner_descr'], $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).' + $minigraph = generate_graph_tag($graph_array); + + echo("
    ".overlib_link($link, $toner['toner_descr'], $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)."
    '; - echo '
    '; - echo '
    '; - echo '
    '; - echo ''; -}//end if + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); +} -unset($toner_rows); +unset ($toner_rows); + +?> diff --git a/html/pages/device/performance.inc.php b/html/pages/device/performance.inc.php index da2056c54b..8686bf8034 100644 --- a/html/pages/device/performance.inc.php +++ b/html/pages/device/performance.inc.php @@ -21,9 +21,7 @@ */ -if(!isset($vars['section'])) { - $vars['section'] = "performance"; -} +if(!isset($vars['section'])) { $vars['section'] = "performance"; } if (empty($vars['dtpickerfrom'])) { $vars['dtpickerfrom'] = date($config['dateformat']['byminute'], time() - 3600 * 24 * 2); @@ -59,8 +57,7 @@ if (empty($vars['dtpickerto'])) { if (is_admin() === true || is_read() === true) { $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf` WHERE `device_id` = ? AND `timestamp` >= ? AND `timestamp` <= ?"; $param = array($device['device_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); -} -else { +} else { $query = "SELECT DATE_FORMAT(timestamp, '".$config['alert_graph_date_format']."') Date, xmt,rcv,loss,min,max,avg FROM `device_perf`,`devices_perms` WHERE `device_id` = ? AND alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = ? AND `timestamp` >= ? AND `timestamp` <= ?"; $param = array($device['device_id'], $_SESSION['user_id'], $vars['dtpickerfrom'], $vars['dtpickerto']); } @@ -84,7 +81,7 @@ foreach(dbFetchRows($query, $param) as $return_value) { $avg = $return_value['avg']; if ($max > $max_val) { - $max_val = $max; + $max_val = $max; } $data[] = array('x' => $date,'y' => $loss,'group' => 0); @@ -189,3 +186,4 @@ echo $milisec_diff; var graph2d = new vis.Graph2d(container, items, groups, options); + diff --git a/html/pages/device/port.inc.php b/html/pages/device/port.inc.php index a70d40a763..ecb25cfd28 100644 --- a/html/pages/device/port.inc.php +++ b/html/pages/device/port.inc.php @@ -1,22 +1,15 @@ get('port-'.$port['port_id'].'-state'); - if ($debug) { - print_r($state); - } - - if (is_array($state)) { - $port = array_merge($port, $state); - } - - unset($state); +if ($config['memcached']['enable'] === TRUE) +{ + $state = $memcache->get('port-'.$port['port_id'].'-state'); + if($debug) { print_r($state); } + if(is_array($state)) { $port = array_merge($port, $state); } + unset($state); } $port_details = 1; @@ -24,218 +17,148 @@ $port_details = 1; $hostname = $device['hostname']; $hostid = $device['port_id']; $ifname = $port['ifDescr']; -$ifIndex = $port['ifIndex']; -$speed = humanspeed($port['ifSpeed']); +$ifIndex = $port['ifIndex']; +$speed = humanspeed($port['ifSpeed']); $ifalias = $port['name']; -if ($port['ifPhysAddress']) { - $mac = "$port[ifPhysAddress]"; -} +if ($port['ifPhysAddress']) { $mac = "$port[ifPhysAddress]"; } -$color = 'black'; -if ($port['ifAdminStatus'] == 'down') { - $status = "Disabled"; -} +$color = "black"; +if ($port['ifAdminStatus'] == "down") { $status = "Disabled"; } +if ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "down") { $status = "Enabled / Disconnected"; } +if ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "up") { $status = "Enabled / Connected"; } -if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'down') { - $status = "Enabled / Disconnected"; -} - -if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') { - $status = "Enabled / Connected"; -} - -$i = 1; +$i = 1; $inf = fixifName($ifname); -$bg = '#ffffff'; +$bg="#ffffff"; $show_all = 1; -echo "
    "; +echo("
    "); -require 'includes/print-interface.inc.php'; +include("includes/print-interface.inc.php"); -echo '
    '; +echo(""); -$pos = strpos(strtolower($ifname), 'vlan'); -if ($pos !== false) { - $broke = yes; +$pos = strpos(strtolower($ifname), "vlan"); +if ($pos !== false ) +{ + $broke = yes; } -$pos = strpos(strtolower($ifname), 'loopback'); +$pos = strpos(strtolower($ifname), "loopback"); -if ($pos !== false) { - $broke = yes; +if ($pos !== false ) +{ + $broke = yes; } -echo "
    "; +echo("
    "); print_optionbar_start(); -$link_array = array( - 'page' => 'device', - 'device' => $device['device_id'], - 'tab' => 'port', - 'port' => $port['port_id'], -); +$link_array = array('page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'port', + 'port' => $port['port_id']); $menu_options['graphs'] = 'Graphs'; -$menu_options['realtime'] = 'Real time'; -// FIXME CONDITIONAL -$menu_options['arp'] = 'ARP Table'; -$menu_options['events'] = 'Eventlog'; +$menu_options['realtime'] = 'Real time'; // FIXME CONDITIONAL +$menu_options['arp'] = 'ARP Table'; +$menu_options['events'] = 'Eventlog'; -if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '".$port['port_id']."'")) { - $menu_options['adsl'] = 'ADSL'; +if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '".$port['port_id']."'") ) +{ $menu_options['adsl'] = 'ADSL'; } + +if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '".$port['ifIndex']."' and `device_id` = '".$device['device_id']."'") ) +{ $menu_options['pagp'] = 'PAgP'; } + +if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'") ) +{ $menu_options['vlans'] = 'VLANs'; } + +$sep = ""; +foreach ($menu_options as $option => $text) +{ + echo($sep); + if ($vars['view'] == $option) { echo(""); } + echo(generate_link($text,$link_array,array('view'=>$option))); + if ($vars['view'] == $option) { echo(""); } + $sep = " | "; } - -if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '".$port['ifIndex']."' and `device_id` = '".$device['device_id']."'")) { - $menu_options['pagp'] = 'PAgP'; -} - -if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['port_id']."' and `device_id` = '".$device['device_id']."'")) { - $menu_options['vlans'] = 'VLANs'; -} - -$sep = ''; -foreach ($menu_options as $option => $text) { - echo $sep; - if ($vars['view'] == $option) { - echo ""; - } - - echo generate_link($text, $link_array, array('view' => $option)); - if ($vars['view'] == $option) { - echo ''; - } - - $sep = ' | '; -} - unset($sep); -if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '".$port['port_id']."'") > '0') { - echo generate_link($descr, $link_array, array('view' => 'macaccounting', 'graph' => $type)); +if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '".$port['port_id']."'") > "0" ) +{ - echo ' | Mac Accounting : '; - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') { - echo ""; - } + echo(generate_link($descr,$link_array,array('view'=>'macaccounting','graph'=>$type))); - echo generate_link('Bits', $link_array, array('view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'bits')); - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') { - echo ''; - } + echo(" | Mac Accounting : "); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "graphs") { echo(""); } + echo(generate_link("Bits",$link_array,array('view' => 'macaccounting', 'subview' => 'graphs', 'graph'=>'bits'))); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "graphs") { echo(""); } - echo '('; - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') { - echo ""; - } + echo("("); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "minigraphs") { echo(""); } + echo(generate_link("Mini",$link_array,array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph'=>'bits'))); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "minigraphs") { echo(""); } + echo('|'); - echo generate_link('Mini', $link_array, array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'bits')); - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') { - echo ''; - } + if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "top10") { echo(""); } + echo(generate_link("Top10",$link_array,array('view' => 'macaccounting', 'subview' => 'top10', 'graph'=>'bits'))); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "bits" && $vars['subview'] == "top10") { echo(""); } + echo(") | "); - echo '|'; + if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "graphs") { echo(""); } + echo(generate_link("Packets",$link_array,array('view' => 'macaccounting', 'subview' => 'graphs', 'graph'=>'pkts'))); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "graphs") { echo(""); } + echo("("); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "minigraphs") { echo(""); } + echo(generate_link("Mini",$link_array,array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph'=>'pkts'))); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "minigraphs") { echo(""); } + echo('|'); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "top10") { echo(""); } + echo(generate_link("Top10",$link_array,array('view' => 'macaccounting', 'subview' => 'top10', 'graph'=>'pkts'))); + if ($vars['view'] == "macaccounting" && $vars['graph'] == "pkts" && $vars['subview'] == "top10") { echo(""); } + echo(")"); +} - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') { - echo ""; - } +if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '".$port['port_id']."'") > "0" ) +{ - echo generate_link('Top10', $link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'bits')); - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') { - echo ''; - } + // FIXME ATM VPs + // FIXME URLs BROKEN - echo ') | '; + echo(" | ATM VPs : "); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } + echo("Bits"); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } + echo(" | "); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "packets") { echo(""); } + echo("Packets"); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } + echo(" | "); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "cells") { echo(""); } + echo("Cells"); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } + echo(" | "); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "errors") { echo(""); } + echo("Errors"); + if ($vars['view'] == "junose-atm-vp" && $vars['graph'] == "bits") { echo(""); } +} - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') { - echo ""; - } - - echo generate_link('Packets', $link_array, array('view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'pkts')); - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') { - echo ''; - } - - echo '('; - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') { - echo ""; - } - - echo generate_link('Mini', $link_array, array('view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'pkts')); - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') { - echo ''; - } - - echo '|'; - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') { - echo ""; - } - - echo generate_link('Top10', $link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'pkts')); - if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') { - echo ''; - } - - echo ')'; -}//end if - -if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '".$port['port_id']."'") > '0') { - // FIXME ATM VPs - // FIXME URLs BROKEN - echo ' | ATM VPs : '; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { - echo ""; - } - - echo "Bits"; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { - echo ''; - } - - echo ' | '; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'packets') { - echo ""; - } - - echo "Packets"; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { - echo ''; - } - - echo ' | '; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'cells') { - echo ""; - } - - echo "Cells"; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { - echo ''; - } - - echo ' | '; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'errors') { - echo ""; - } - - echo "Errors"; - if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') { - echo ''; - } -}//end if - -if ($_SESSION['userlevel'] >= '10') { - echo " Create Bill"; +if ($_SESSION['userlevel'] >= '10') +{ + echo(" Create Bill"); } print_optionbar_end(); -echo "
    "; +echo("
    "); -require 'pages/device/port/'.mres($vars['view']).'.inc.php'; +include("pages/device/port/".mres($vars['view']).".inc.php"); -echo '
    '; +echo("
    "); + +?> diff --git a/html/pages/device/port/events.inc.php b/html/pages/device/port/events.inc.php index 5a113fafe6..6de49ef262 100644 --- a/html/pages/device/port/events.inc.php +++ b/html/pages/device/port/events.inc.php @@ -1,12 +1,15 @@ '; +echo(''); -foreach ($entries as $entry) { - include 'includes/print-event.inc.php'; +foreach ($entries as $entry) +{ + include("includes/print-event.inc.php"); } -echo '
    '; +echo(''); -$pagetitle[] = 'Events'; +$pagetitle[] = "Events"; + +?> diff --git a/html/pages/device/port/pagp.inc.php b/html/pages/device/port/pagp.inc.php index 7a8e41ff50..e64437e2c2 100644 --- a/html/pages/device/port/pagp.inc.php +++ b/html/pages/device/port/pagp.inc.php @@ -3,32 +3,34 @@ global $config; // FIXME functions! -if (!$graph_type) { - $graph_type = 'pagp_bits'; + +if (!$graph_type) { $graph_type = "pagp_bits"; } + +$daily_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['day']."&to=".$config['time']['now']."&width=215&height=100"; +$daily_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; + +$weekly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['week']."&to=".$config['time']['now']."&width=215&height=100"; +$weekly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['week']."&to=".$config['time']['now']."&width=500&height=150"; + +$monthly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['month']."&to=".$config['time']['now']."&width=215&height=100"; +$monthly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['month']."&to=".$config['time']['now']."&width=500&height=150"; + +$yearly_traffic = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['year']."&to=".$config['time']['now']."&width=215&height=100"; +$yearly_url = "graph.php?port=" . $port['port_id'] . "&type=$graph_type&from=".$config['time']['year']."&to=".$config['time']['now']."&width=500&height=150"; + +echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "); +echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "); +echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "); +echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "); + +foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member) +{ + echo("$br " . generate_port_link($member) . " (PAgP)"); + $br = "
    "; } -$daily_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['day'].'&to='.$config['time']['now'].'&width=215&height=100'; -$daily_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; - -$weekly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['week'].'&to='.$config['time']['now'].'&width=215&height=100'; -$weekly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['week'].'&to='.$config['time']['now'].'&width=500&height=150'; - -$monthly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['month'].'&to='.$config['time']['now'].'&width=215&height=100'; -$monthly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['month'].'&to='.$config['time']['now'].'&width=500&height=150'; - -$yearly_traffic = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['year'].'&to='.$config['time']['now'].'&width=215&height=100'; -$yearly_url = 'graph.php?port='.$port['port_id']."&type=$graph_type&from=".$config['time']['year'].'&to='.$config['time']['now'].'&width=500&height=150'; - -echo "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "; -echo "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> - "; -echo "', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "; -echo "', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> - "; - -foreach (dbFetchRows('SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $member) { - echo "$br ".generate_port_link($member).' (PAgP)'; - $br = '
    '; -} +?> diff --git a/html/pages/device/ports.inc.php b/html/pages/device/ports.inc.php index dc941e246f..b254b376da 100644 --- a/html/pages/device/ports.inc.php +++ b/html/pages/device/ports.inc.php @@ -1,23 +1,15 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'ports', -); +$link_array = array('page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'ports'); print_optionbar_start(); @@ -25,136 +17,110 @@ $menu_options['basic'] = 'Basic'; $menu_options['details'] = 'Details'; $menu_options['arp'] = 'ARP Table'; -if (dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.port_id = L.local_port_id")) { - $menu_options['neighbours'] = 'Neighbours'; +if(dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '".$device['device_id']."' AND I.port_id = L.local_port_id")) +{ + $menu_options['neighbours'] = 'Neighbours'; +} +if(dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) +{ + $menu_options['adsl'] = 'ADSL'; } -if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) { - $menu_options['adsl'] = 'ADSL'; -} - -$sep = ''; -foreach ($menu_options as $option => $text) { - echo $sep; - if ($vars['view'] == $option) { - echo ""; - } - - echo generate_link($text, $link_array, array('view' => $option)); - if ($vars['view'] == $option) { - echo ''; - } - - $sep = ' | '; +$sep = ""; +foreach ($menu_options as $option => $text) +{ + echo($sep); + if ($vars['view'] == $option) { echo(""); } + echo(generate_link($text,$link_array,array('view'=>$option))); + if ($vars['view'] == $option) { echo(""); } + $sep = " | "; } unset($sep); -echo ' | Graphs: '; +echo(' | Graphs: '); -$graph_types = array( - 'bits' => 'Bits', - 'upkts' => 'Unicast Packets', - 'nupkts' => 'Non-Unicast Packets', - 'errors' => 'Errors', - 'etherlike' => 'Etherlike', -); +$graph_types = array("bits" => "Bits", + "upkts" => "Unicast Packets", + "nupkts" => "Non-Unicast Packets", + "errors" => "Errors", + "etherlike" => "Etherlike"); -foreach ($graph_types as $type => $descr) { - echo "$type_sep"; - if ($vars['graph'] == $type && $vars['view'] == 'graphs') { - echo ""; - } +foreach ($graph_types as $type => $descr) +{ + echo("$type_sep"); + if ($vars['graph'] == $type && $vars['view'] == "graphs") { echo(""); } + echo(generate_link($descr,$link_array,array('view'=>'graphs','graph'=>$type))); + if ($vars['graph'] == $type && $vars['view'] == "graphs") { echo(""); } - echo generate_link($descr, $link_array, array('view' => 'graphs', 'graph' => $type)); - if ($vars['graph'] == $type && $vars['view'] == 'graphs') { - echo ''; - } - - echo ' ('; - if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { - echo ""; - } - - echo generate_link('Mini', $link_array, array('view' => 'minigraphs', 'graph' => $type)); - if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { - echo ''; - } - - echo ')'; - $type_sep = ' | '; -}//end foreach + echo(' ('); + if ($vars['graph'] == $type && $vars['view'] == "minigraphs") { echo(""); } + echo(generate_link('Mini',$link_array,array('view'=>'minigraphs','graph'=>$type))); + if ($vars['graph'] == $type && $vars['view'] == "minigraphs") { echo(""); } + echo(')'); + $type_sep = " | "; +} print_optionbar_end(); -if ($vars['view'] == 'minigraphs') { - $timeperiods = array( - '-1day', - '-1week', - '-1month', - '-1year', - ); - $from = '-1day'; - echo "
    "; - unset($seperator); +if ($vars['view'] == 'minigraphs') +{ + $timeperiods = array('-1day','-1week','-1month','-1year'); + $from = '-1day'; + echo("
    "); + unset ($seperator); - // FIXME - FIX THIS. UGLY. - foreach (dbFetchRows('select * from ports WHERE device_id = ? ORDER BY ifIndex', array($device['device_id'])) as $port) { - echo "
    -
    ".makeshortif($port['ifDescr']).'
    - ".$device['hostname'].' - '.$port['ifDescr'].'
    \ - '.$port['ifAlias']." \ - \ - ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >"." - -
    ".truncate(short_port_descr($port['ifAlias']), 32, '').'
    -
    '; + // FIXME - FIX THIS. UGLY. + foreach (dbFetchRows("select * from ports WHERE device_id = ? ORDER BY ifIndex", array($device['device_id'])) as $port) + { + echo("
    +
    ".makeshortif($port['ifDescr'])."
    + ".$device['hostname']." - ".$port['ifDescr']."
    \ + ".$port['ifAlias']." \ + \ + ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >". + " + +
    ".truncate(short_port_descr($port['ifAlias']), 32, '')."
    +
    "); + } + echo("
    "); +} elseif ($vars['view'] == "arp" || $vars['view'] == "adsl" || $vars['view'] == "neighbours") { + include("ports/".$vars['view'].".inc.php"); +} else { + if ($vars['view'] == "details") { $port_details = 1; } + echo("
    "); + $i = "1"; + + global $port_cache, $port_index_cache; + + $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device['device_id'])); + // As we've dragged the whole database, lets pre-populate our caches :) + // FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries. + foreach ($ports as $port) + { + $port_cache[$port['port_id']] = $port; + $port_index_cache[$port['device_id']][$port['ifIndex']] = $port; + } + + foreach ($ports as $port) + { + if ($config['memcached']['enable'] === TRUE) + { + $state = $memcache->get('port-'.$port['port_id'].'-state'); + if($debug) { print_r($state); } + if(is_array($state)) { $port = array_merge($port, $state); } + unset($state); } - echo ''; + include("includes/print-interface.inc.php"); + + $i++; + } + echo("
    "); } -else if ($vars['view'] == 'arp' || $vars['view'] == 'adsl' || $vars['view'] == 'neighbours') { - include 'ports/'.$vars['view'].'.inc.php'; -} -else { - if ($vars['view'] == 'details') { - $port_details = 1; - } - echo "
    "; - $i = '1'; +$pagetitle[] = "Ports"; - global $port_cache, $port_index_cache; - - $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device['device_id'])); - // As we've dragged the whole database, lets pre-populate our caches :) - // FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries. - foreach ($ports as $port) { - $port_cache[$port['port_id']] = $port; - $port_index_cache[$port['device_id']][$port['ifIndex']] = $port; - } - - foreach ($ports as $port) { - if ($config['memcached']['enable'] === true) { - $state = $memcache->get('port-'.$port['port_id'].'-state'); - if ($debug) { - print_r($state); - } - - if (is_array($state)) { - $port = array_merge($port, $state); - } - - unset($state); - } - - include 'includes/print-interface.inc.php'; - - $i++; - } - - echo '
    '; -}//end if - -$pagetitle[] = 'Ports'; +?> diff --git a/html/pages/device/ports/neighbours.inc.php b/html/pages/device/ports/neighbours.inc.php index b56136881e..5e417eb996 100644 --- a/html/pages/device/ports/neighbours.inc.php +++ b/html/pages/device/ports/neighbours.inc.php @@ -10,7 +10,8 @@ echo 'Local Port Protocol '; -foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id', array($device['device_id'])) as $neighbour) { +foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id', array($device['device_id'])) as $neighbour) +{ if ($bg_colour == $list_colour_b) { $bg_colour = $list_colour_a; } diff --git a/html/pages/device/processes.inc.php b/html/pages/device/processes.inc.php index 0ce8e4c70f..41fda92887 100644 --- a/html/pages/device/processes.inc.php +++ b/html/pages/device/processes.inc.php @@ -1,21 +1,19 @@ +/* Copyright (C) 2015 Daniel Preussker * 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 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ + * along with this program. If not, see . */ -/* +/** * Process Listing * @author Daniel Preussker * @copyright 2015 f0o, LibreNMS @@ -24,89 +22,77 @@ * @subpackage Pages */ -switch ($vars['order']) { - case 'vsz': - $order = '`vsz`'; - break; - - case 'rss': - $order = '`rss`'; - break; - - case 'cputime': - $order = '`cputime`'; - break; - - case 'user': - $order = '`user`'; - break; - - case 'command': - $order = '`command`'; - break; - - default: - $order = '`pid`'; - break; -}//end switch - -if ($vars['by'] == 'desc') { - $by = 'desc'; +switch( $vars['order'] ) { + case "vsz": + $order = "`vsz`"; + break; + case "rss": + $order = "`rss`"; + break; + case "cputime": + $order = "`cputime`"; + break; + case "user": + $order = "`user`"; + break; + case "command": + $order = "`command`"; + break; + default: + $order = "`pid`"; + break; } -else { - $by = 'asc'; +if( $vars['by'] == "desc" ) { + $by = "desc"; +} else { + $by = "asc"; } $heads = array( - 'PID' => '', - 'VSZ' => 'Virtual Memory', - 'RSS' => 'Resident Memory', - 'cputime' => '', - 'user' => '', - 'command' => '', + 'PID' => '', + 'VSZ' => 'Virtual Memory', + 'RSS' => 'Resident Memory', + 'cputime' => '', + 'user' => '', + 'command' => '' ); echo "
    "; -foreach ($heads as $head => $extra) { - unset($lhead, $bhead); - $lhead = strtolower($head); - $bhead = 'asc'; - $icon = ''; - if ('`'.$lhead.'`' == $order) { - $icon = " class='glyphicon glyphicon-chevron-"; - if ($by == 'asc') { - $bhead = 'desc'; - $icon .= 'up'; - } - else { - $icon .= 'down'; - } - - $icon .= "'"; - } - - echo ''; -}//end foreach - -echo ''; - -foreach (dbFetchRows('SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY '.$order.' '.$by, array($device['device_id'])) as $entry) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; +foreach( $heads as $head=>$extra ) { + unset($lhead, $bhead); + $lhead = strtolower($head); + $bhead = 'asc'; + $icon = ""; + if( '`'.$lhead.'`' == $order ) { + $icon = " class='glyphicon glyphicon-chevron-"; + if( $by == 'asc' ) { + $bhead = 'desc'; + $icon .= 'up'; + } else { + $icon .= 'down'; + } + $icon .= "'"; + } + echo ''; } +echo ""; -echo '
     '; - if (!empty($extra)) { - echo "$head"; - } - else { - echo $head; - } - - echo '
    '.$entry['pid'].''.format_si(($entry['vsz'] * 1024)).''.format_si(($entry['rss'] * 1024)).''.$entry['cputime'].''.$entry['user'].''.$entry['command'].'
     '; + if( !empty($extra) ) { + echo "$head"; + } else { + echo $head; + } + echo '
    '; +foreach (dbFetchRows("SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY ".$order." ".$by, array($device['device_id'])) as $entry) { + echo ''; + echo ''.$entry['pid'].''; + echo ''.format_si($entry['vsz']*1024).''; + echo ''.format_si($entry['rss']*1024).''; + echo ''.$entry['cputime'].''; + echo ''.$entry['user'].''; + echo ''.$entry['command'].''; + echo ''; +} +echo"
    "; + +?> diff --git a/html/pages/device/pseudowires.inc.php b/html/pages/device/pseudowires.inc.php index c48bca5738..c134c8b661 100644 --- a/html/pages/device/pseudowires.inc.php +++ b/html/pages/device/pseudowires.inc.php @@ -89,7 +89,8 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I WHERE P.port_id 'upkts', 'errors', ); - foreach ($types as $graph_type) { + foreach ($types as $graph_type) + { $pw_a['graph_type'] = 'port_'.$graph_type; print_port_thumbnail($pw_a); } diff --git a/html/pages/device/routing/bgp.inc.php b/html/pages/device/routing/bgp.inc.php index 17f0629a02..5b327aca30 100644 --- a/html/pages/device/routing/bgp.inc.php +++ b/html/pages/device/routing/bgp.inc.php @@ -1,275 +1,203 @@ 'device', - 'device' => $device['device_id'], - 'tab' => 'routing', - 'proto' => 'bgp', -); +$link_array = array('page' => 'device', + 'device' => $device['device_id'], + 'tab' => 'routing', + 'proto' => 'bgp'); -if (!isset($vars['view'])) { - $vars['view'] = 'basic'; -} +if(!isset($vars['view'])) { $vars['view'] = "basic"; } print_optionbar_start(); -echo 'Local AS : '.$device['bgpLocalAs'].' '; +echo "Local AS : " .$device['bgpLocalAs']." "; -echo "BGP » "; +echo("BGP » "); -if ($vars['view'] == 'basic') { - echo ""; -} +if ($vars['view'] == "basic") { echo(""); } +echo(generate_link("Basic", $link_array,array('view'=>'basic'))); +if ($vars['view'] == "basic") { echo(""); } -echo generate_link('Basic', $link_array, array('view' => 'basic')); -if ($vars['view'] == 'basic') { - echo ''; -} +echo(" | "); -echo ' | '; +if ($vars['view'] == "updates") { echo(""); } +echo(generate_link("Updates", $link_array,array('view'=>'updates'))); +if ($vars['view'] == "updates") { echo(""); } -if ($vars['view'] == 'updates') { - echo ""; -} +echo(" | Prefixes: "); -echo generate_link('Updates', $link_array, array('view' => 'updates')); -if ($vars['view'] == 'updates') { - echo ''; -} +if ($vars['view'] == "prefixes_ipv4unicast") { echo(""); } +echo(generate_link("IPv4", $link_array,array('view'=>'prefixes_ipv4unicast'))); +if ($vars['view'] == "prefixes_ipv4unicast") { echo(""); } -echo ' | Prefixes: '; +echo(" | "); -if ($vars['view'] == 'prefixes_ipv4unicast') { - echo ""; -} +if ($vars['view'] == "prefixes_vpnv4unicast") { echo(""); } +echo(generate_link("VPNv4", $link_array,array('view'=>'prefixes_vpnv4unicast'))); +if ($vars['view'] == "prefixes_vpnv4unicast") { echo(""); } -echo generate_link('IPv4', $link_array, array('view' => 'prefixes_ipv4unicast')); -if ($vars['view'] == 'prefixes_ipv4unicast') { - echo ''; -} +echo(" | "); -echo ' | '; +if ($vars['view'] == "prefixes_ipv6unicast") { echo(""); } +echo(generate_link("IPv6", $link_array,array('view'=>'prefixes_ipv6unicast'))); +if ($vars['view'] == "prefixes_ipv6unicast") { echo(""); } -if ($vars['view'] == 'prefixes_vpnv4unicast') { - echo ""; -} +echo(" | Traffic: "); -echo generate_link('VPNv4', $link_array, array('view' => 'prefixes_vpnv4unicast')); -if ($vars['view'] == 'prefixes_vpnv4unicast') { - echo ''; -} - -echo ' | '; - -if ($vars['view'] == 'prefixes_ipv6unicast') { - echo ""; -} - -echo generate_link('IPv6', $link_array, array('view' => 'prefixes_ipv6unicast')); -if ($vars['view'] == 'prefixes_ipv6unicast') { - echo ''; -} - -echo ' | Traffic: '; - -if ($vars['view'] == 'macaccounting_bits') { - echo ""; -} - -echo generate_link('Bits', $link_array, array('view' => 'macaccounting_bits')); -if ($vars['view'] == 'macaccounting_bits') { - echo ''; -} - -echo ' | '; -if ($vars['view'] == 'macaccounting_pkts') { - echo ""; -} - -echo generate_link('Packets', $link_array, array('view' => 'macaccounting_pkts')); -if ($vars['view'] == 'macaccounting_pkts') { - echo ''; -} +if ($vars['view'] == "macaccounting_bits") { echo(""); } +echo(generate_link("Bits", $link_array,array('view'=>'macaccounting_bits'))); +if ($vars['view'] == "macaccounting_bits") { echo(""); } +echo(" | "); +if ($vars['view'] == "macaccounting_pkts") { echo(""); } +echo(generate_link("Packets", $link_array,array('view'=>'macaccounting_pkts'))); +if ($vars['view'] == "macaccounting_pkts") { echo(""); } print_optionbar_end(); -echo ''; -echo ''; +echo('
    Peer addressTypeRemote ASStateUptime
    '); +echo(''); -$i = '1'; +$i = "1"; -foreach (dbFetchRows('SELECT * FROM `bgpPeers` WHERE `device_id` = ? ORDER BY `bgpPEerRemoteAs`, `bgpPeerIdentifier`', array($device['device_id'])) as $peer) { - $has_macaccounting = dbFetchCell('SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address', array($peer['bgpPeerIdentifier'])); - unset($bg_image); - if (!is_integer($i / 2)) { - $bg_colour = $list_colour_a; - } - else { - $bg_colour = $list_colour_b; - } +foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? ORDER BY `bgpPEerRemoteAs`, `bgpPeerIdentifier`", array($device['device_id'])) as $peer) +{ + $has_macaccounting = dbFetchCell("SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address", array($peer['bgpPeerIdentifier'])); + unset($bg_image); + if (!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } + unset ($alert, $bg_image); + unset ($peerhost, $peername); - unset($alert, $bg_image); - unset($peerhost, $peername); + if (!is_integer($i/2)) { $bg_colour = $list_colour_b; } else { $bg_colour = $list_colour_a; } + if ($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $peer['alert']=1; } + if ($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "gray"; } + if ($peer['bgpPeerAdminStatus'] == "stop") { $peer['alert']=0; $peer['disabled']=1; } - if (!is_integer($i / 2)) { - $bg_colour = $list_colour_b; - } - else { - $bg_colour = $list_colour_a; - } + if ($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; } - if ($peer['bgpPeerState'] == 'established') { - $col = 'green'; - } - else { - $col = 'red'; - $peer['alert'] = 1; - } + $query = "SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE "; + $query .= "(A.ipv4_address = ? AND I.port_id = A.port_id)"; + $query .= " AND D.device_id = I.device_id"; + $ipv4_host = dbFetchRow($query,array($peer['bgpPeerIdentifier'])); - if ($peer['bgpPeerAdminStatus'] == 'start' || $peer['bgpPeerAdminStatus'] == 'running') { - $admin_col = 'green'; - } - else { - $admin_col = 'gray'; - } + $query = "SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE "; + $query .= "(A.ipv6_address = ? AND I.port_id = A.port_id)"; + $query .= " AND D.device_id = I.device_id"; + $ipv6_host = dbFetchRow($query,array($peer['bgpPeerIdentifier'])); - if ($peer['bgpPeerAdminStatus'] == 'stop') { - $peer['alert'] = 0; - $peer['disabled'] = 1; - } + if ($ipv4_host) + { + $peerhost = $ipv4_host; + } elseif ($ipv6_host) { + $peerhost = $ipv6_host; + } else { + unset($peerhost); + } - if ($peer['bgpPeerRemoteAs'] == $device['bgpLocalAs']) { - $peer_type = "iBGP"; - } - else { - $peer_type = "eBGP"; - } + if (is_array($peerhost)) + { + #$peername = generate_device_link($peerhost); + $peername = generate_device_link($peerhost) ." ". generate_port_link($peerhost); + $peer_url = "device/device=" . $peer['device_id'] . "/tab=routing/proto=bgp/view=updates/"; + } + else + { + #$peername = gethostbyaddr($peer['bgpPeerIdentifier']); // FFffuuu DNS // Cache this in discovery? +# if ($peername == $peer['bgpPeerIdentifier']) +# { +# unset($peername); +# } else { +# $peername = "".$peername.""; +# } + } - $query = 'SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE '; - $query .= '(A.ipv4_address = ? AND I.port_id = A.port_id)'; - $query .= ' AND D.device_id = I.device_id'; - $ipv4_host = dbFetchRow($query, array($peer['bgpPeerIdentifier'])); + unset($peer_af); + unset($sep); - $query = 'SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE '; - $query .= '(A.ipv6_address = ? AND I.port_id = A.port_id)'; - $query .= ' AND D.device_id = I.device_id'; - $ipv6_host = dbFetchRow($query, array($peer['bgpPeerIdentifier'])); + foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($device['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) + { + $afi = $afisafi['afi']; + $safi = $afisafi['safi']; + $this_afisafi = $afi.$safi; + $peer['afi'] .= $sep . $afi .".".$safi; + $sep = "
    "; + $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer + } - if ($ipv4_host) { - $peerhost = $ipv4_host; - } - else if ($ipv6_host) { - $peerhost = $ipv6_host; - } - else { - unset($peerhost); - } + unset($sep); - if (is_array($peerhost)) { - // $peername = generate_device_link($peerhost); - $peername = generate_device_link($peerhost).' '.generate_port_link($peerhost); - $peer_url = 'device/device='.$peer['device_id'].'/tab=routing/proto=bgp/view=updates/'; - } - else { - // FIXME - // $peername = gethostbyaddr($peer['bgpPeerIdentifier']); // FFffuuu DNS // Cache this in discovery? - // if ($peername == $peer['bgpPeerIdentifier']) - // { - // unset($peername); - // } else { - // $peername = "".$peername.""; - // } - } - - unset($peer_af); - unset($sep); - - foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { - $afi = $afisafi['afi']; - $safi = $afisafi['safi']; - $this_afisafi = $afi.$safi; - $peer['afi'] .= $sep.$afi.'.'.$safi; - $sep = '
    '; - $peer['afisafi'][$this_afisafi] = 1; - // Build a list of valid AFI/SAFI for this peer - } - - unset($sep); - - if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { - $peer['bgpPeerIdentifier'] = Net_IPv6::compress($peer['bgpPeerIdentifier']); - } + if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { + $peer['bgpPeerIdentifier'] = Net_IPv6::compress($peer['bgpPeerIdentifier']); + } - $graph_type = 'bgp_updates'; - $peer_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; - $peeraddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer['bgpPeerIdentifier'].''; + $graph_type = "bgp_updates"; + $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; + $peeraddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer['bgpPeerIdentifier'] . ""; - echo '
    - '; + echo(' + "); - echo ' - - - - - - - - '; + echo(" + + + + + + + + "); - unset($invalid); + unset($invalid); - switch ($vars['view']) { + switch ($vars['view']) + { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': - list(,$afisafi) = explode('_', $vars['view']); - if (isset($peer['afisafi'][$afisafi])) { - $peer['graph'] = 1; - } - - // FIXME no break?? + list(,$afisafi) = explode("_", $vars['view']); + if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } + // FIXME no break?? case 'updates': - $graph_array['type'] = 'bgp_'.$vars['view']; - $graph_array['id'] = $peer['bgpPeer_id']; - } + $graph_array['type'] = "bgp_" . $vars['view']; + $graph_array['id'] = $peer['bgpPeer_id']; + } - switch ($vars['view']) { + switch ($vars['view']) + { case 'macaccounting_bits': case 'macaccounting_pkts': - $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', array($peer['bgpPeerIdentifier'])); - $database = $config['rrd_dir'].'/'.$device['hostname'].'/cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'; - if (is_array($acc) && is_file($database)) { - $peer['graph'] = 1; - $graph_array['id'] = $acc['ma_id']; - $graph_array['type'] = $vars['view']; - } - } + $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier'])); + $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; + if (is_array($acc) && is_file($database)) + { + $peer['graph'] = 1; + $graph_array['id'] = $acc['ma_id']; + $graph_array['type'] = $vars['view']; + } + } - if ($vars['view'] == 'updates') { - $peer['graph'] = 1; - } + if ($vars['view'] == 'updates') { $peer['graph'] = 1; } - if ($peer['graph']) { - $graph_array['height'] = '100'; - $graph_array['width'] = '216'; - $graph_array['to'] = $config['time']['now']; - echo ''; - } + echo(""); + } - $i++; + $i++; - unset($valid_afi_safi); -}//end foreach + unset($valid_afi_safi); +} ?>
    Peer addressTypeRemote ASStateUptime
    '.$i.''.$peeraddresslink.'
    '.$peername."
    $peer_type".(isset($peer['afi']) ? $peer['afi'] : '').'AS'.$peer['bgpPeerRemoteAs'].'
    '.$peer['astext']."
    ".$peer['bgpPeerAdminStatus']."
    ".$peer['bgpPeerState'].'
    '.formatUptime($peer['bgpPeerFsmEstablishedTime'])."
    - Updates ".$peer['bgpPeerInUpdates']." - ".$peer['bgpPeerOutUpdates'].'
    ".$i."" . $peeraddresslink . "
    ".$peername."
    $peer_type" . (isset($peer['afi']) ? $peer['afi'] : '') . "AS" . $peer['bgpPeerRemoteAs'] . "
    " . $peer['astext'] . "
    " . $peer['bgpPeerAdminStatus'] . "
    " . $peer['bgpPeerState'] . "
    " .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
    + Updates " . $peer['bgpPeerInUpdates'] . " + " . $peer['bgpPeerOutUpdates'] . "
    '; + if ($peer['graph']) + { + $graph_array['height'] = "100"; + $graph_array['width'] = "216"; + $graph_array['to'] = $config['time']['now']; + echo('
    '); - include 'includes/print-graphrow.inc.php'; + include("includes/print-graphrow.inc.php"); - echo '
    diff --git a/html/pages/device/routing/ospf.inc.php b/html/pages/device/routing/ospf.inc.php index 7bf6798b7b..ed126a7fe3 100644 --- a/html/pages/device/routing/ospf.inc.php +++ b/html/pages/device/routing/ospf.inc.php @@ -88,7 +88,8 @@ foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', arr // # Loop Ports $i_p = ($i_a + 1); $p_sql = "SELECT * FROM `ospf_ports` AS O, `ports` AS P WHERE O.`ospfIfAdminStat` = 'enabled' AND O.`device_id` = ? AND O.`ospfIfAreaId` = ? AND P.port_id = O.port_id"; - foreach (dbFetchRows($p_sql, array($device['device_id'], $area['ospfAreaId'])) as $ospfport) { + foreach (dbFetchRows($p_sql, array($device['device_id'], $area['ospfAreaId'])) as $ospfport) + { if (!is_integer($i_a / 2)) { if (!is_integer($i_p / 2)) { $port_bg = $list_colour_b_b; diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index 9efc95d63a..aed9398dd2 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -1,135 +1,134 @@ = '7') { - if (!is_array($config['rancid_configs'])) { - $config['rancid_configs'] = array($config['rancid_configs']); - } - if (isset($config['rancid_configs'][0])) { - foreach ($config['rancid_configs'] as $configs) { - if ($configs[(strlen($configs) - 1)] != '/') { - $configs .= '/'; - } +if ($_SESSION['userlevel'] >= "7") +{ - if (is_file($configs.$device['hostname'])) { - $file = $configs.$device['hostname']; - } - } + if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); } - echo '
    '; + if (isset($config['rancid_configs'][0])) { - print_optionbar_start('', ''); + foreach ($config['rancid_configs'] as $configs) { + if ($configs[strlen($configs) - 1] != '/') { + $configs .= '/'; + } + if (is_file($configs . $device['hostname'])) { + $file = $configs . $device['hostname']; + } + } - echo "Config » "; + echo('
    '); - if (!$vars['rev']) { - echo ''; - echo generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig')); - echo ''; - } - else { - echo generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig')); - } + print_optionbar_start('', ''); - if (function_exists('svn_log')) { - $sep = ' | '; - $svnlogs = svn_log($file, SVN_REVISION_HEAD, null, 8); - $revlist = array(); + echo("Config » "); - foreach ($svnlogs as $svnlog) { - echo $sep; - $revlist[] = $svnlog['rev']; + if (!$vars['rev']) { + echo(''); + echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); + echo(""); + } else { + echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); + } - if ($vars['rev'] == $svnlog['rev']) { - echo ''; - } + if (function_exists('svn_log')) { - $linktext = 'r'.$svnlog['rev'].' '.date($config['dateformat']['byminute'], strtotime($svnlog['date'])).''; - echo generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog['rev'])); + $sep = " | "; + $svnlogs = svn_log($file, SVN_REVISION_HEAD, NULL, 8); + $revlist = array(); - if ($vars['rev'] == $svnlog['rev']) { - echo ''; - } + foreach ($svnlogs as $svnlog) { - $sep = ' | '; - } - }//end if + echo($sep); + $revlist[] = $svnlog["rev"]; - print_optionbar_end(); + if ($vars['rev'] == $svnlog["rev"]) { + echo(''); + } + $linktext = "r" . $svnlog["rev"] . " " . date($config['dateformat']['byminute'], strtotime($svnlog["date"])) . ""; + echo(generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog["rev"]))); - if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { - list($diff, $errors) = svn_diff($file, ($vars['rev'] - 1), $file, $vars['rev']); - if (!$diff) { - $text = 'No Difference'; - } - else { - $text = ''; - while (!feof($diff)) { - $text .= fread($diff, 8192); - } + if ($vars['rev'] == $svnlog["rev"]) { + echo(""); + } - fclose($diff); - fclose($errors); - } - } - else { - $fh = fopen($file, 'r') or die("Can't open file"); - $text = fread($fh, filesize($file)); - fclose($fh); - } + $sep = " | "; + } + } - if ($config['rancid_ignorecomments']) { - $lines = explode("\n", $text); - for ($i = 0; $i < count($lines); $i++) { - if ($lines[$i][0] == '#') { - unset($lines[$i]); - } - } + print_optionbar_end(); - $text = join("\n", $lines); - } - } - else if ($config['oxidized']['enabled'] === true && isset($config['oxidized']['url'])) { - $node_info = json_decode(file_get_contents($config['oxidized']['url'].'/node/show/'.$device['hostname'].'?format=json'), true); - $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.$device['hostname']); - if ($text == 'node not found') { - $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.$device['os'].'/'.$device['hostname']); - } + if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { + list($diff, $errors) = svn_diff($file, $vars['rev'] - 1, $file, $vars['rev']); + if (!$diff) { + $text = "No Difference"; + } else { + $text = ""; + while (!feof($diff)) { + $text .= fread($diff, 8192); + } + fclose($diff); + fclose($errors); + } - if (is_array($node_info)) { - echo '
    -
    + } else { + $fh = fopen($file, 'r') or die("Can't open file"); + $text = fread($fh, filesize($file)); + fclose($fh); + } + + if ($config['rancid_ignorecomments']) { + $lines = explode("\n", $text); + for ($i = 0; $i < count($lines); $i++) { + if ($lines[$i][0] == "#") { + unset($lines[$i]); + } + } + $text = join("\n", $lines); + } + } elseif ($config['oxidized']['enabled'] === TRUE && isset($config['oxidized']['url'])) { + $node_info = json_decode(file_get_contents($config['oxidized']['url']."/node/show/".$device['hostname']."?format=json"),TRUE); + $text = file_get_contents($config['oxidized']['url']."/node/fetch/".$device['hostname']); + if ($text == "node not found") { + $text = file_get_contents($config['oxidized']['url']."/node/fetch/".$device['os']."/".$device['hostname']); + } + + if (is_array($node_info)) { + echo('
    +
    -
    -
    Sync status: '.$node_info['last']['status'].'
    -
      -
    • Node: '.$node_info['name'].'
    • -
    • IP: '.$node_info['ip'].'
    • -
    • Model: '.$node_info['model'].'
    • -
    • Last Sync: '.$node_info['last']['end'].'
    • -
    +
    +
    Sync status: '.$node_info['last']['status'].'
    +
      +
    • Node: '. $node_info['name'].'
    • +
    • IP: '. $node_info['ip'].'
    • +
    • Model: '. $node_info['model'].'
    • +
    • Last Sync: '. $node_info['last']['end'].'
    • +
    +
    -
    -
    '; - } - else { - echo '
    '; - print_error("We couldn't retrieve the device information from Oxidized"); - $text = ''; - } - }//end if +
    '); + } else { + echo "
    "; + print_error("We couldn't retrieve the device information from Oxidized"); + $text = ''; + } - if (!empty($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 $geshi->parse_code(); - } -}//end if + } -$pagetitle[] = 'Config'; + if (!empty($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($geshi->parse_code()); + } +} + +$pagetitle[] = "Config"; + +?> diff --git a/html/pages/device/slas.inc.php b/html/pages/device/slas.inc.php index 587c7d7438..3cc6cbf119 100644 --- a/html/pages/device/slas.inc.php +++ b/html/pages/device/slas.inc.php @@ -12,7 +12,7 @@ foreach ($slas as $sla) { $sla_type = $sla['rtt_type']; if (!in_array($sla_type, $sla_types)) { - if (isset($config['sla_type_labels'][$sla_type])) { + if (isset($config['sla_type_labels'][$sla_type])) { $text = $config['sla_type_labels'][$sla_type]; } } diff --git a/html/pages/devices.inc.php b/html/pages/devices.inc.php index 0367b8a1c3..67a8c39edd 100644 --- a/html/pages/devices.inc.php +++ b/html/pages/devices.inc.php @@ -2,9 +2,7 @@ // Set Defaults here -if(!isset($vars['format'])) { - $vars['format'] = "list_detail"; -} +if(!isset($vars['format'])) { $vars['format'] = "list_detail"; } $pagetitle[] = "Devices"; @@ -12,19 +10,23 @@ print_optionbar_start(); echo('Lists » '); -$menu_options = array('basic' => 'Basic', 'detail' => 'Detail'); +$menu_options = array('basic' => 'Basic', + 'detail' => 'Detail'); $sep = ""; -foreach ($menu_options as $option => $text) { - echo($sep); - if ($vars['format'] == "list_".$option) { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == "list_".$option) { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) +{ + echo($sep); + if ($vars['format'] == "list_".$option) + { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == "list_".$option) + { + echo(""); + } + $sep = " | "; } ?> @@ -36,26 +38,29 @@ foreach ($menu_options as $option => $text) { 'Bits', - 'processor' => 'CPU', - 'ucd_load' => 'Load', - 'mempool' => 'Memory', - 'uptime' => 'Uptime', - 'storage' => 'Storage', - 'diskio' => 'Disk I/O', - 'poller_perf' => 'Poller', - 'ping_perf' => 'Ping' -); + 'processor' => 'CPU', + 'ucd_load' => 'Load', + 'mempool' => 'Memory', + 'uptime' => 'Uptime', + 'storage' => 'Storage', + 'diskio' => 'Disk I/O', + 'poller_perf' => 'Poller', + 'ping_perf' => 'Ping' + ); $sep = ""; -foreach ($menu_options as $option => $text) { - echo($sep); - if ($vars['format'] == 'graph_'.$option) { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == 'graph_'.$option) { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) +{ + echo($sep); + if ($vars['format'] == 'graph_'.$option) + { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == 'graph_'.$option) + { + echo(""); + } + $sep = " | "; } ?> @@ -64,21 +69,21 @@ foreach ($menu_options as $option => $text) { '')).'">Restore Search'); -} -else { + } else { echo('Remove Search'); -} + } -echo(" | "); + echo(" | "); -if (isset($vars['bare']) && $vars['bare'] == "yes") { + if (isset($vars['bare']) && $vars['bare'] == "yes") + { echo('Restore Header'); -} -else { + } else { echo('Remove Header'); -} + } print_optionbar_end(); ?> @@ -89,110 +94,76 @@ print_optionbar_end(); list($format, $subformat) = explode("_", $vars['format'], 2); -if($format == "graph") { - $sql_param = array(); +if($format == "graph") +{ +$sql_param = array(); - if(isset($vars['state'])) { - if($vars['state'] == 'up') { - $state = '1'; - } - elseif($vars['state'] == 'down') { - $state = '0'; - } - } +if(isset($vars['state'])) +{ + if($vars['state'] == 'up') + { + $state = '1'; + } + elseif($vars['state'] == 'down') + { + $state = '0'; + } +} - if (!empty($vars['hostname'])) { - $where .= " AND hostname LIKE ?"; - $sql_param[] = "%".$vars['hostname']."%"; - } - if (!empty($vars['os'])) { - $where .= " AND os = ?"; - $sql_param[] = $vars['os']; - } - if (!empty($vars['version'])) { - $where .= " AND version = ?"; - $sql_param[] = $vars['version']; - } - if (!empty($vars['hardware'])) { - $where .= " AND hardware = ?"; - $sql_param[] = $vars['hardware']; - } - if (!empty($vars['features'])) { - $where .= " AND features = ?"; - $sql_param[] = $vars['features']; - } +if (!empty($vars['hostname'])) { $where .= " AND hostname LIKE ?"; $sql_param[] = "%".$vars['hostname']."%"; } +if (!empty($vars['os'])) { $where .= " AND os = ?"; $sql_param[] = $vars['os']; } +if (!empty($vars['version'])) { $where .= " AND version = ?"; $sql_param[] = $vars['version']; } +if (!empty($vars['hardware'])) { $where .= " AND hardware = ?"; $sql_param[] = $vars['hardware']; } +if (!empty($vars['features'])) { $where .= " AND features = ?"; $sql_param[] = $vars['features']; } +if (!empty($vars['type'])) { + if ($vars['type'] == 'generic') { + $where .= " AND ( type = ? OR type = '')"; $sql_param[] = $vars['type']; + } else { + $where .= " AND type = ?"; $sql_param[] = $vars['type']; + } +} +if (!empty($vars['state'])) { + $where .= " AND status= ?"; $sql_param[] = $state; + $where .= " AND disabled='0' AND `ignore`='0'"; $sql_param[] = ''; +} +if (!empty($vars['disabled'])) { $where .= " AND disabled= ?"; $sql_param[] = $vars['disabled']; } +if (!empty($vars['ignore'])) { $where .= " AND `ignore`= ?"; $sql_param[] = $vars['ignore']; } +if (!empty($vars['location']) && $vars['location'] == "Unset") { $location_filter = ''; } +if (!empty($vars['location'])) { $location_filter = $vars['location']; } +if( !empty($vars['group']) ) { + require_once('../includes/device-groups.inc.php'); + $where .= " AND ( "; + foreach( GetDevicesFromGroup($vars['group']) as $dev ) { + $where .= "device_id = ? OR "; + $sql_param[] = $dev['device_id']; + } + $where = substr($where, 0, strlen($where)-3); + $where .= " )"; +} - if (!empty($vars['type'])) { - if ($vars['type'] == 'generic') { - $where .= " AND ( type = ? OR type = '')"; - $sql_param[] = $vars['type']; - } - else { - $where .= " AND type = ?"; - $sql_param[] = $vars['type']; - } - } - if (!empty($vars['state'])) { - $where .= " AND status= ?"; - $sql_param[] = $state; - $where .= " AND disabled='0' AND `ignore`='0'"; - $sql_param[] = ''; - } - if (!empty($vars['disabled'])) { - $where .= " AND disabled= ?"; - $sql_param[] = $vars['disabled']; - } - if (!empty($vars['ignore'])) { - $where .= " AND `ignore`= ?"; - $sql_param[] = $vars['ignore']; - } - if (!empty($vars['location']) && $vars['location'] == "Unset") { - $location_filter = ''; - } - if (!empty($vars['location'])) { - $location_filter = $vars['location']; - } - if( !empty($vars['group']) ) { - require_once('../includes/device-groups.inc.php'); - $where .= " AND ( "; - foreach( GetDevicesFromGroup($vars['group']) as $dev ) { - $where .= "device_id = ? OR "; - $sql_param[] = $dev['device_id']; - } - $where = substr($where, 0, strlen($where)-3); - $where .= " )"; - } +$query = "SELECT * FROM `devices` WHERE 1 "; - $query = "SELECT * FROM `devices` WHERE 1 "; +if (isset($where)) { + $query .= $where; +} - if (isset($where)) { - $query .= $where; - } +$query .= " ORDER BY hostname"; - $query .= " ORDER BY hostname"; + $row = 1; + foreach (dbFetchRows($query, $sql_param) as $device) + { + if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - $row = 1; - foreach (dbFetchRows($query, $sql_param) as $device) { - if (is_integer($row/2)) { - $row_colour = $list_colour_a; - } - else { - $row_colour = $list_colour_b; - } + if (device_permitted($device['device_id'])) + { + if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter) + || $device['location'] == $location_filter)) + { + $graph_type = "device_".$subformat; - if (device_permitted($device['device_id'])) { - if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter) - || $device['location'] == $location_filter)) { - $graph_type = "device_".$subformat; + if ($_SESSION['widescreen']) { $width=270; } else { $width=315; } - if ($_SESSION['widescreen']) { - $width=270; - } - else { - $width=315; - } - - echo(""); - } - } + } } -} -else { + } + +} else { ?> @@ -238,23 +209,22 @@ else { ""+ '.$config['os'][$tmp_os]['text'].'"+'); +if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `os` FROM `devices` AS D WHERE 1 GROUP BY `os` ORDER BY `os`"; +} else { + $sql = "SELECT `os` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `os` ORDER BY `os`"; + $param[] = $_SESSION['user_id']; +} +foreach (dbFetch($sql,$param) as $data) { + if ($data['os']) { + $tmp_os = clean_bootgrid($data['os']); + echo('""+'); } +} ?> ""+ "
    "+ @@ -263,23 +233,22 @@ else { ""+ '.$tmp_version.'"+'); +if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `version` FROM `devices` AS D WHERE 1 GROUP BY `version` ORDER BY `version`"; +} else { + $sql = "SELECT `version` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `version` ORDER BY `version`"; + $param[] = $_SESSION['user_id']; +} +foreach (dbFetch($sql,$param) as $data) { + if ($data['version']) { + $tmp_version = clean_bootgrid($data['version']); + echo('""+'); + } +} ?> ""+ "
    "+ @@ -288,23 +257,22 @@ else { ""+ '.$tmp_hardware.'"+'); +if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `hardware` FROM `devices` AS D WHERE 1 GROUP BY `hardware` ORDER BY `hardware`"; +} else { + $sql = "SELECT `hardware` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hardware` ORDER BY `hardware`"; + $param[] = $_SESSION['user_id']; +} +foreach (dbFetch($sql,$param) as $data) { + if ($data['hardware']) { + $tmp_hardware = clean_bootgrid($data['hardware']); + echo('""+'); } +} ?> ""+ @@ -314,24 +282,24 @@ else { ""+ '.$tmp_features.'"+'); - } + echo('">'.$tmp_features.'"+'); } +} ?> ""+ @@ -343,16 +311,16 @@ else { '.$location.'"+'); +foreach (getlocations() as $location) { + if ($location) { + $location = clean_bootgrid($location); + echo('""+'); } +} ?> ""+ ""+ @@ -361,22 +329,21 @@ else { ""+ '.ucfirst($data['type']).'"+'); +if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `type` FROM `devices` AS D WHERE 1 GROUP BY `type` ORDER BY `type`"; +} else { + $sql = "SELECT `type` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `type` ORDER BY `type`"; + $param[] = $_SESSION['user_id']; +} +foreach (dbFetch($sql,$param) as $data) { + if ($data['type']) { + echo('""+'); } +} ?> ""+ @@ -390,9 +357,9 @@ else { "

    " var grid = $("#devices").bootgrid({ @@ -433,3 +400,5 @@ var grid = $("#devices").bootgrid({ diff --git a/html/pages/editsrv.inc.php b/html/pages/editsrv.inc.php index 1c04e4510f..9c56b96d1e 100644 --- a/html/pages/editsrv.inc.php +++ b/html/pages/editsrv.inc.php @@ -1,30 +1,35 @@ '5') { - include 'includes/service-edit.inc.php'; + include "includes/error-no-perm.inc.php"; + +} else { + + $pagetitle[] = "Edit service"; + + if ($_POST['confirm-editsrv']) + { + if ($_SESSION['userlevel'] > "5") + { + include("includes/service-edit.inc.php"); } } - foreach (dbFetchRows('SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname') as $device) { - $servicesform .= "'; + foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname") as $device) + { + $servicesform .= ""; } - if ($updated) { - print_message('Service updated!'); - } + if ($updated) { print_message("Service updated!"); } if ($_POST['editsrv'] == 'yes') { - include_once 'includes/print-service-edit.inc.php'; - } - else { - echo " + + require_once "includes/print-service-edit.inc.php"; + + } else { + + echo("

    Delete Service

    @@ -41,6 +46,7 @@ else { -
    "; - }//end if -}//end if + "); + } + +} diff --git a/html/pages/edituser.inc.php b/html/pages/edituser.inc.php index ec2a3f1c9e..6a9a7d2830 100644 --- a/html/pages/edituser.inc.php +++ b/html/pages/edituser.inc.php @@ -1,170 +1,167 @@ "; +echo("
    "); -$pagetitle[] = 'Edit user'; +$pagetitle[] = "Edit user"; -if ($_SESSION['userlevel'] != '10') { - include 'includes/error-no-perm.inc.php'; -} -else { - if ($vars['user_id'] && !$vars['edit']) { - $user_data = dbFetchRow('SELECT * FROM users WHERE user_id = ?', array($vars['user_id'])); - echo '

    '.$user_data['realname']."

    Change...

    "; - // Perform actions if requested - if ($vars['action'] == 'deldevperm') { - if (dbFetchCell('SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id']))) { - dbDelete('devices_perms', '`device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id'])); - } - } +if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php"); } else +{ + if ($vars['user_id'] && !$vars['edit']) + { + $user_data = dbFetchRow("SELECT * FROM users WHERE user_id = ?", array($vars['user_id'])); + echo("

    " . $user_data['realname'] . "

    Change...

    "); + // Perform actions if requested - if ($vars['action'] == 'adddevperm') { - if (!dbFetchCell('SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?', array($vars['device_id'], $vars['user_id']))) { - dbInsert(array('device_id' => $vars['device_id'], 'user_id' => $vars['user_id']), 'devices_perms'); - } - } + if ($vars['action'] == "deldevperm") + { + if (dbFetchCell("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?", array($vars['device_id'] ,$vars['user_id']))) + { + dbDelete('devices_perms', "`device_id` = ? AND `user_id` = ?", array($vars['device_id'], $vars['user_id'])); + } + } + if ($vars['action'] == "adddevperm") + { + if (!dbFetchCell("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?", array($vars['device_id'] ,$vars['user_id']))) + { + dbInsert(array('device_id' => $vars['device_id'], 'user_id' => $vars['user_id']), 'devices_perms'); + } + } + if ($vars['action'] == "delifperm") + { + if (dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) + { + dbDelete('ports_perms', "`port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id'])); + } + } + if ($vars['action'] == "addifperm") + { + if (!dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) + { + dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms'); + } + } + if ($vars['action'] == "delbillperm") + { + if (dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) + { + dbDelete('bill_perms', "`bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id'])); + } + } + if ($vars['action'] == "addbillperm") + { + if (!dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) + { + dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms'); + } + } - if ($vars['action'] == 'delifperm') { - if (dbFetchCell('SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id']))) { - dbDelete('ports_perms', '`port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id'])); - } - } + echo('
    +
    '); - if ($vars['action'] == 'addifperm') { - if (!dbFetchCell('SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?', array($vars['port_id'], $vars['user_id']))) { - dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms'); - } - } + // Display devices this users has access to + echo("

    Device Access

    "); - if ($vars['action'] == 'delbillperm') { - if (dbFetchCell('SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id']))) { - dbDelete('bill_perms', '`bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id'])); - } - } - - if ($vars['action'] == 'addbillperm') { - if (!dbFetchCell('SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?', array($vars['bill_id'], $vars['user_id']))) { - dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms'); - } - } - - echo '
    -
    '; - - // Display devices this users has access to - echo '

    Device Access

    '; - - echo "
    + echo("
    - "; + "); - $device_perms = dbFetchRows('SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id', array($vars['user_id'])); - foreach ($device_perms as $device_perm) { - echo '"; - $access_list[] = $device_perm['device_id']; - $permdone = 'yes'; - } + $device_perms = dbFetchRows("SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id", array($vars['user_id'])); + foreach ($device_perms as $device_perm) + { + echo(""); + $access_list[] = $device_perm['device_id']; + $permdone = "yes"; + } - echo '
    Device Action
    '.$device_perm['hostname']."
    " . $device_perm['hostname'] . "
    -
    '; + echo(" +
    "); - if (!$permdone) { - echo 'None Configured'; - } + if (!$permdone) { echo("None Configured"); } - // Display devices this user doesn't have access to - echo '

    Grant access to new device

    '; - echo "
    - + // Display devices this user doesn't have access to + echo("

    Grant access to new device

    "); + echo(" +
    - "); - $devices = dbFetchRows('SELECT * FROM `devices` ORDER BY hostname'); - foreach ($devices as $device) { - unset($done); - foreach ($access_list as $ac) { - if ($ac == $device['device_id']) { - $done = 1; - } - } + $devices = dbFetchRows("SELECT * FROM `devices` ORDER BY hostname"); + foreach ($devices as $device) + { + unset($done); + foreach ($access_list as $ac) { if ($ac == $device['device_id']) { $done = 1; } } + if (!$done) + { + echo(""); + } + } - if (!$done) { - echo "'; - } - } - - echo " + echo("
    -
    "; + "); - echo "
    -
    "; - echo '

    Interface Access

    '; + echo("
    +
    "); + echo("

    Interface Access

    "); - $interface_perms = dbFetchRows('SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id', array($vars['user_id'])); + $interface_perms = dbFetchRows("SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($vars['user_id'])); - echo "
    + echo("
    - "; - foreach ($interface_perms as $interface_perm) { - echo ' + "); + foreach ($interface_perms as $interface_perm) + { + echo(" - "; - $ipermdone = 'yes'; - } + "); + $ipermdone = "yes"; + } + echo("
    Interface name Action
    - '.$interface_perm['hostname'].' - '.$interface_perm['ifDescr'].''.''.$interface_perm['ifAlias']." + ".$interface_perm['hostname']." - ".$interface_perm['ifDescr']."". + "" . $interface_perm['ifAlias'] . " -    +   
    +
    "); - echo ' -
    '; + if (!$ipermdone) { echo("None Configured"); } - if (!$ipermdone) { - echo 'None Configured'; - } + // Display devices this user doesn't have access to + echo("

    Grant access to new interface

    "); - // Display devices this user doesn't have access to - echo '

    Grant access to new interface

    '; - - echo "
    - + echo(" +
    + echo("
    @@ -179,135 +176,133 @@ else {
    - "; + "); - echo "
    -
    "; - echo '

    Bill Access

    '; + echo("
    +
    "); + echo("

    Bill Access

    "); - $bill_perms = dbFetchRows('SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id', array($vars['user_id'])); + $bill_perms = dbFetchRows("SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id", array($vars['user_id'])); - echo "
    + echo("
    - "; + "); - foreach ($bill_perms as $bill_perm) { - echo ' + foreach ($bill_perms as $bill_perm) + { + echo(" - "; - $bill_access_list[] = $bill_perm['bill_id']; + "); + $bill_access_list[] = $bill_perm['bill_id']; - $bpermdone = 'yes'; - } + $bpermdone = "yes"; + } - echo '
    Bill name Action
    - '.$bill_perm['bill_name']."   + ".$bill_perm['bill_name']."  
    -
    '; + echo(" +
    "); - if (!$bpermdone) { - echo 'None Configured'; - } + if (!$bpermdone) { echo("None Configured"); } - // Display devices this user doesn't have access to - echo '

    Grant access to new bill

    '; - echo "
    - + // Display devices this user doesn't have access to + echo("

    Grant access to new bill

    "); + echo(" +
    - "); - $bills = dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_name`'); - foreach ($bills as $bill) { - unset($done); - foreach ($bill_access_list as $ac) { - if ($ac == $bill['bill_id']) { - $done = 1; - } - } + $bills = dbFetchRows("SELECT * FROM `bills` ORDER BY `bill_name`"); + foreach ($bills as $bill) + { + unset($done); + foreach ($bill_access_list as $ac) { if ($ac == $bill['bill_id']) { $done = 1; } } + if (!$done) + { + echo(""); + } + } - if (!$done) { - echo "'; - } - } - - echo " + echo("
    -
    "; +
    "); + + } elseif ($vars['user_id'] && $vars['edit']) { + + if($_SESSION['userlevel'] == 11) { + demo_account(); + } else { + + if(!empty($vars['new_level'])) + { + if($vars['can_modify_passwd'] == 'on') { + $vars['can_modify_passwd'] = '1'; + } + update_user($vars['user_id'],$vars['new_realname'],$vars['new_level'],$vars['can_modify_passwd'],$vars['new_email']); + print_message("User has been updated"); } - else if ($vars['user_id'] && $vars['edit']) { - if ($_SESSION['userlevel'] == 11) { - demo_account(); + + if(can_update_users() == '1') { + + $users_details = get_user($vars['user_id']); + if(!empty($users_details)) + { + + if(empty($vars['new_realname'])) + { + $vars['new_realname'] = $users_details['realname']; + } + if(empty($vars['new_level'])) + { + $vars['new_level'] = $users_details['level']; + } + if(empty($vars['can_modify_passwd'])) + { + $vars['can_modify_passwd'] = $users_details['can_modify_passwd']; + } elseif($vars['can_modify_passwd'] == 'on') { + $vars['can_modify_passwd'] = '1'; + } + if(empty($vars['new_email'])) + { + $vars['new_email'] = $users_details['email']; } - else { - if (!empty($vars['new_level'])) { - if ($vars['can_modify_passwd'] == 'on') { - $vars['can_modify_passwd'] = '1'; - } - update_user($vars['user_id'], $vars['new_realname'], $vars['new_level'], $vars['can_modify_passwd'], $vars['new_email']); - print_message('User has been updated'); + if( $config['twofactor'] ) { + if( $vars['twofactorremove'] ) { + if( dbUpdate(array('twofactor'=>''),users,'user_id = ?',array($vars['user_id'])) ) { + echo "
    TwoFactor credentials removed.
    "; + } else { + echo "
    Couldnt remove user's TwoFactor credentials.
    "; } + } + if( $vars['twofactorunlock'] ) { + $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE user_id = ?",array($vars['user_id'])); + $twofactor = json_decode($twofactor['twofactor'],true); + $twofactor['fails'] = 0; + if( dbUpdate(array('twofactor'=>json_encode($twofactor)),users,'user_id = ?',array($vars['user_id'])) ) { + echo "
    User unlocked.
    "; + } else { + echo "
    Couldnt reset user's TwoFactor failures.
    "; + } + } + } - if (can_update_users() == '1') { - $users_details = get_user($vars['user_id']); - if (!empty($users_details)) { - if (empty($vars['new_realname'])) { - $vars['new_realname'] = $users_details['realname']; - } - - if (empty($vars['new_level'])) { - $vars['new_level'] = $users_details['level']; - } - - if (empty($vars['can_modify_passwd'])) { - $vars['can_modify_passwd'] = $users_details['can_modify_passwd']; - } - else if ($vars['can_modify_passwd'] == 'on') { - $vars['can_modify_passwd'] = '1'; - } - - if (empty($vars['new_email'])) { - $vars['new_email'] = $users_details['email']; - } - - if ($config['twofactor']) { - if ($vars['twofactorremove']) { - if (dbUpdate(array('twofactor' => ''), users, 'user_id = ?', array($vars['user_id']))) { - echo "
    TwoFactor credentials removed.
    "; - } - else { - echo "
    Couldnt remove user's TwoFactor credentials.
    "; - } - } - - if ($vars['twofactorunlock']) { - $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE user_id = ?', array($vars['user_id'])); - $twofactor = json_decode($twofactor['twofactor'], true); - $twofactor['fails'] = 0; - if (dbUpdate(array('twofactor' => json_encode($twofactor)), users, 'user_id = ?', array($vars['user_id']))) { - echo "
    User unlocked.
    "; - } - else { - echo "
    Couldnt reset user's TwoFactor failures.
    "; - } - } - } - - echo "
    - + echo(" +
    - +
    @@ -315,7 +310,7 @@ else {
    - +
    @@ -324,22 +319,10 @@ else {
    @@ -349,10 +332,7 @@ else {
    @@ -360,14 +340,14 @@ else {
    - "; - if ($config['twofactor']) { - echo "

    Two-Factor Authentication

    "; - $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE user_id = ?', array($vars['user_id'])); - $twofactor = json_decode($twofactor['twofactor'], true); - if ($twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time() - $twofactor['last']) < $config['twofactor_lock'])) { - echo "
    - +
    "); + if( $config['twofactor'] ) { + echo "

    Two-Factor Authentication

    "; + $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE user_id = ?",array($vars['user_id'])); + $twofactor = json_decode($twofactor['twofactor'],true); + if( $twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || (time()-$twofactor['last']) < $config['twofactor_lock']) ) { + echo "
    +
    @@ -375,47 +355,43 @@ else {
    "; - } - - if ($twofactor['key']) { - echo "
    - + } + if( $twofactor['key'] ) { + echo " +
    "; - } - else { - echo '

    No TwoFactor key generated for this user, Nothing to do.

    '; - } - }//end if - } - else { - echo print_error('Error getting user details'); - }//end if - } - else { - echo print_error("Authentication method doesn't support updating users"); - }//end if - }//end if + } else { + echo "

    No TwoFactor key generated for this user, Nothing to do.

    "; + } + } + } else { + echo print_error("Error getting user details"); + } + } else { + echo print_error("Authentication method doesn't support updating users"); } - else { - $user_list = get_userlist(); + } + } else { - echo '

    Select a user to edit

    '; + $user_list = get_userlist(); - echo "
    + echo("

    Select a user to edit

    "); + + echo("
    - +
    @@ -423,8 +399,11 @@ else { /
    - "; - }//end if -}//end if + "); + } -echo '
    '; +} + +echo("
    "); + +?> diff --git a/html/pages/eventlog.inc.php b/html/pages/eventlog.inc.php index 2ac41ec91b..4e1cad13d2 100644 --- a/html/pages/eventlog.inc.php +++ b/html/pages/eventlog.inc.php @@ -1,15 +1,16 @@ = '10') { - dbQuery('TRUNCATE TABLE `eventlog`'); - print_message('Event log truncated'); +if ($vars['action'] == "expunge" && $_SESSION['userlevel'] >= '10') +{ + dbQuery("TRUNCATE TABLE `eventlog`"); + print_message("Event log truncated"); } -$pagetitle[] = 'Eventlog'; +$pagetitle[] = "Eventlog"; print_optionbar_start(); @@ -23,17 +24,15 @@ print_optionbar_start();
    @@ -41,7 +40,9 @@ print_optionbar_start(); diff --git a/html/pages/front/default.php b/html/pages/front/default.php index b69f7f97b1..7b17f08a45 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -1,180 +1,174 @@ +function generate_front_box ($frontbox_class, $content) +{ +echo("
    $content -
    "; + "); +} -}//end generate_front_box() - - -echo ' +echo('
    -'; +'); if ($config['vertical_summary']) { - echo '
    '; + echo('
    '); } -else { - echo '
    '; +else +{ + echo('
    '); } - -echo ' +echo('
    -'; +'); -echo '
    '; +echo('
    '); -echo '
    '; +echo('
    '); $count_boxes = 0; // Device down boxes -if ($_SESSION['userlevel'] >= '10') { - $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT ".$config['front_page_down_box_limit']; +if ($_SESSION['userlevel'] >= '10') +{ + $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT ".$config['front_page_down_box_limit']; +} else { + $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0' LIMIT".$config['front_page_down_box_limit']; } -else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '0' AND D.ignore = '0' LIMIT".$config['front_page_down_box_limit']; -} - -foreach (dbFetchRows($sql) as $device) { - generate_front_box( - 'device-down', - generate_device_link($device, shorthost($device['hostname'])).'
    +foreach (dbFetchRows($sql) as $device) +{ + generate_front_box("device-down", generate_device_link($device, shorthost($device['hostname']))."
    Device Down
    - '.truncate($device['location'], 20).'' - ); - ++$count_boxes; + ".truncate($device['location'], 20).""); + ++$count_boxes; } -if ($_SESSION['userlevel'] >= '10') { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; -} -else { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; +if ($_SESSION['userlevel'] >= '10') +{ + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; +} else { + $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; } // These things need to become more generic, and more manageable across different frontpages... rewrite inc :> + // Port down boxes -if ($config['warn']['ifdown']) { - foreach (dbFetchRows($sql) as $interface) { - if (!$interface['deleted']) { - $interface = ifNameDescr($interface); - generate_front_box( - 'port-down', - generate_device_link($interface, shorthost($interface['hostname']))."
    +if ($config['warn']['ifdown']) +{ + foreach (dbFetchRows($sql) as $interface) + { + if (!$interface['deleted']) + { + $interface = ifNameDescr($interface); + generate_front_box("port-down", generate_device_link($interface, shorthost($interface['hostname']))."
    Port Down
    - - ".generate_port_link($interface, truncate(makeshortif($interface['label']), 13, '')).'
    - '.($interface['ifAlias'] ? ''.truncate($interface['ifAlias'], 20, '').'' : '') - ); - ++$count_boxes; - } + + ".generate_port_link($interface, truncate(makeshortif($interface['label']),13,''))."
    + " . ($interface['ifAlias'] ? ''.truncate($interface['ifAlias'], 20, '').'' : '')); + ++$count_boxes; } + } } -/* - FIXME service permissions? seem nonexisting now.. */ +/* FIXME service permissions? seem nonexisting now.. */ // Service down boxes -if ($_SESSION['userlevel'] >= '10') { - $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - $param[] = ''; +if ($_SESSION['userlevel'] >= '10') +{ + $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + $param[] = ''; } -else { - $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - $param[] = $_SESSION['user_id']; +else +{ + $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0' AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + $param[] = $_SESSION['user_id']; } - -foreach (dbFetchRows($sql, $param) as $service) { - generate_front_box( - 'service-down', - generate_device_link($service, shorthost($service['hostname'])).'
    +foreach (dbFetchRows($sql,$param) as $service) +{ + generate_front_box("service-down", generate_device_link($service, shorthost($service['hostname']))."
    Service Down - '.$service['service_type'].'
    - '.truncate($interface['ifAlias'], 20).'' - ); - ++$count_boxes; + ".$service['service_type']."
    + ".truncate($interface['ifAlias'], 20).""); + ++$count_boxes; } // BGP neighbour down boxes -if (isset($config['enable_bgp']) && $config['enable_bgp']) { - if ($_SESSION['userlevel'] >= '10') { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - } - else { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; - } - - foreach (dbFetchRows($sql) as $peer) { - generate_front_box( - 'bgp-down', - generate_device_link($peer, shorthost($peer['hostname']))."
    +if (isset($config['enable_bgp']) && $config['enable_bgp']) +{ + if ($_SESSION['userlevel'] >= '10') + { + $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + } else { + $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT ".$config['front_page_down_box_limit']; + } + foreach (dbFetchRows($sql) as $peer) + { + generate_front_box("bgp-down", generate_device_link($peer, shorthost($peer['hostname']))."
    BGP Down - ".$peer['bgpPeerIdentifier'].'
    - AS'.truncate($peer['bgpPeerRemoteAs'].' '.$peer['astext'], 14, '').'' - ); - ++$count_boxes; - } + ".$peer['bgpPeerIdentifier']."
    + AS".truncate($peer['bgpPeerRemoteAs']." ".$peer['astext'], 14, "").""); + ++$count_boxes; + } } // Device rebooted boxes -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { - if ($_SESSION['userlevel'] >= '10') { - $sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; - } - else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '".$config['uptime_warning']."' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) +{ + if ($_SESSION['userlevel'] >= '10') + { + $sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; + } else { + $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" . + $config['uptime_warning'] . "' AND D.ignore = 0 LIMIT ".$config['front_page_down_box_limit']; + } - foreach (dbFetchRows($sql) as $device) { - generate_front_box( - 'device-rebooted', - generate_device_link($device, shorthost($device['hostname'])).'
    + foreach (dbFetchRows($sql) as $device) + { + generate_front_box("device-rebooted", generate_device_link($device, shorthost($device['hostname']))."
    Device Rebooted
    - '.formatUptime($device['uptime'], 'short').'' - ); - ++$count_boxes; - } + ".formatUptime($device['uptime'], 'short').""); + ++$count_boxes; + } } - if ($count_boxes == 0) { - echo "
    Nothing here yet

    This is where status notifications about devices and services would normally go. You might have none - because you run such a great network, or perhaps you've just started using ".$config['project_name'].". If you're new to ".$config['project_name'].', you might - want to start by adding one or more devices in the Devices menu.

    '; + echo("
    Nothing here yet

    This is where status notifications about devices and services would normally go. You might have none + because you run such a great network, or perhaps you've just started using ".$config['project_name'].". If you're new to ".$config['project_name'].", you might + want to start by adding one or more devices in the Devices menu.

    "); } - -echo '
    '; -echo '
    '; -echo '
    '; -echo ' +echo('
    '); +echo('
    '); +echo('
    '); +echo('
    -'; +'); -if ($config['vertical_summary']) { - echo '
    '; - include_once 'includes/device-summary-vert.inc.php'; +if ($config['vertical_summary']) +{ + echo('
    '); + include_once("includes/device-summary-vert.inc.php"); } -else { - echo '
    '; - include_once 'includes/device-summary-horiz.inc.php'; +else +{ + echo('
    '); + include_once("includes/device-summary-horiz.inc.php"); } -echo ' +echo('
    -'; +'); -if ($config['enable_syslog']) { - $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; - $query = mysql_query($sql); +if ($config['enable_syslog']) +{ - echo '
    + $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; + $query = mysql_query($sql); + + echo('
      @@ -186,34 +180,35 @@ if ($config['enable_syslog']) {
    Syslog entries
    -
    '; +
    '); - foreach (dbFetchRows($sql) as $entry) { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); + foreach (dbFetchRows($sql) as $entry) + { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include 'includes/print-syslog.inc.php'; - } + include("includes/print-syslog.inc.php"); + } + echo("
    "); + echo(""); + echo(""); + echo(""); + echo(""); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -} -else { - if ($_SESSION['userlevel'] >= '10') { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15'; - } - else { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = ".$_SESSION['user_id'].' ORDER BY `datetime` DESC LIMIT 0,15'; - $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = '.$_SESSION['user_id'].' ORDER BY `time_logged` DESC LIMIT 0,15'; - } +} else { - $data = mysql_query($query); - $alertdata = mysql_query($alertquery); + if ($_SESSION['userlevel'] >= '10') + { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15"; + } else { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; + $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id'] . " ORDER BY `time_logged` DESC LIMIT 0,15"; + } - echo '
    + $data = mysql_query($query); + $alertdata = mysql_query($alertquery); + + echo('
      @@ -225,13 +220,13 @@ else {
    Alertlog entries
    - '; +
    '); - foreach (dbFetchRows($alertquery) as $alert_entry) { - include 'includes/print-alerts.inc.php'; - } - - echo '
    + foreach (dbFetchRows($alertquery) as $alert_entry) + { + include("includes/print-alerts.inc.php"); + } + echo('
    @@ -239,21 +234,24 @@ else {
    Eventlog entries
    - '; +
    '); - foreach (dbFetchRows($query) as $entry) { - include 'includes/print-event.inc.php'; - } + foreach (dbFetchRows($query) as $entry) + { + include("includes/print-event.inc.php"); + } - echo '
    '; - echo '
    '; - echo '
    '; - echo '
    '; - echo ''; -}//end if + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); +} -echo ''; +echo(""); -echo ' +echo(' -'; +'); + +?> diff --git a/html/pages/front/demo.php b/html/pages/front/demo.php index 6478a566b8..1000fbca24 100644 --- a/html/pages/front/demo.php +++ b/html/pages/front/demo.php @@ -4,55 +4,56 @@ '; +echo(""); -$dev_list = array( - '6' => 'Central Fileserver', - '7' => 'NE61 Fileserver', - '34' => 'DE56 Fileserver', -); +$dev_list = array('6' => 'Central Fileserver', + '7' => 'NE61 Fileserver', + '34' => 'DE56 Fileserver'); -foreach ($dev_list as $device_id => $descr) { - echo ''; -}//end foreach + echo("
    "); + $graph_array['type'] = "device_diskio"; + print_graph_popup($graph_array); + echo("
    "); -echo '
    '; - echo "
    ".$descr.'
    '; - $graph_array['height'] = '100'; - $graph_array['width'] = '310'; - $graph_array['to'] = $config['time']['now']; - $graph_array['device'] = $device_id; - $graph_array['type'] = 'device_bits'; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; - $graph_array['popup_title'] = $descr; - // $graph_array['link'] = generate_device_link($device_id); - print_graph_popup($graph_array); +foreach ($dev_list as $device_id => $descr) +{ - $graph_array['height'] = '50'; - $graph_array['width'] = '180'; + echo("
    "); + echo("
    ".$descr."
    "); + $graph_array['height'] = "100"; + $graph_array['width'] = "310"; + $graph_array['to'] = $config['time']['now']; + $graph_array['device'] = $device_id; + $graph_array['type'] = "device_bits"; + $graph_array['from'] = $config['time']['day']; + $graph_array['legend'] = "no"; + $graph_array['popup_title'] = $descr; +# $graph_array['link'] = generate_device_link($device_id); + print_graph_popup($graph_array); - echo "
    "; - $graph_array['type'] = 'device_ucd_memory'; - print_graph_popup($graph_array); - echo '
    '; + $graph_array['height'] = "50"; + $graph_array['width'] = "180"; - echo "
    "; - $graph_array['type'] = 'device_processor'; - print_graph_popup($graph_array); - echo '
    '; + echo("
    "); + $graph_array['type'] = "device_ucd_memory"; + print_graph_popup($graph_array); + echo("
    "); - echo "
    "; - $graph_array['type'] = 'device_storage'; - print_graph_popup($graph_array); - echo '
    '; + echo("
    "); + $graph_array['type'] = "device_processor"; + print_graph_popup($graph_array); + echo("
    "); - echo "
    "; - $graph_array['type'] = 'device_diskio'; - print_graph_popup($graph_array); - echo '
    '; + echo("
    "); + $graph_array['type'] = "device_storage"; + print_graph_popup($graph_array); + echo("
    "); - echo '
    '; + echo(""); + +} + +echo(""); ?> @@ -61,105 +62,115 @@ echo ''; '0' AND A.attrib_value < '86400'"; -foreach (dbFetchRows($sql) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; +foreach (dbFetchRows($sql) as $device) +{ + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = "yes"; } + $i++; + } + if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id'])) { - echo "
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35).' -
    '; - } +foreach (dbFetchRows($sql) as $device) +{ + if (device_permitted($device['device_id'])) { + echo("
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35)." +
    "); + } } -if ($config['warn']['ifdown']) { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; - foreach (dbFetchRows($sql) as $interface) { - if (port_permitted($interface['port_id'])) { - echo "
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    - '.truncate($interface['ifAlias'], 15).' -
    '; - } +if ($config['warn']['ifdown']) +{ + $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; + foreach (dbFetchRows($sql) as $interface) + { + if (port_permitted($interface['port_id'])) + { + echo("
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    + ".truncate($interface['ifAlias'], 15)." +
    "); } + } } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) { - if (device_permitted($service['device_id'])) { - echo "
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type'].'
    - '.truncate($interface['ifAlias'], 15).' -
    '; - } +foreach (dbFetchRows($sql) as $service) +{ + if (device_permitted($service['device_id'])) + { + echo("
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type']."
    + ".truncate($interface['ifAlias'], 15)." +
    "); + } } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) { - if (device_permitted($peer['device_id'])) { - echo "
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier'].'
    - AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
    '; - } +foreach (dbFetchRows($sql) as $peer) +{ + if (device_permitted($peer['device_id'])) + { + echo("
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier']."
    + AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." +
    "); + } } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE - A.attrib_value < '".$config['uptime_warning']."' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { - echo "
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value']).' -
    '; - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) +{ + $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE + A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; + foreach (dbFetchRows($sql) as $device) + { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") + { + echo("
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value'])." +
    "); } + } } -echo " -
    $errorboxes
    +echo(" +
    $errorboxes
    -

    Recent Syslog Messages

    - "; +

    Recent Syslog Messages

    +"); $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from `syslog` ORDER BY seq DESC LIMIT 20"; -echo ''; -foreach (dbFetchRows($sql) as $entry) { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); +echo("
    "); +foreach (dbFetchRows($sql) as $entry) +{ + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include 'includes/print-syslog.inc.php'; + include("includes/print-syslog.inc.php"); } -echo '
    '; +echo(""); ?> diff --git a/html/pages/front/example2.php b/html/pages/front/example2.php index e5898ac073..717ee75184 100644 --- a/html/pages/front/example2.php +++ b/html/pages/front/example2.php @@ -4,141 +4,173 @@
    Devices with Alerts
    Host
    Int
    Srv
    +# ?> '0' AND A.attrib_value < '86400'"; -foreach (dbFetchRows($sql) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; +foreach (dbFetchRows($sql) as $device) +{ + unset($already); + $i = 0; + while ($i <= count($nodes)) + { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) + { + $already = "yes"; } + $i++; + } + if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) { - echo "
    -
    ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down - ".truncate($device['location'], 20).' -
    '; +foreach (dbFetchRows($sql) as $device) +{ + echo("
    +
    ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down + ".truncate($device['location'], 20)." +
    "); + } $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; -foreach (dbFetchRows($sql) as $interface) { - echo "
    -
    ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down - ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    - '.truncate($interface['ifAlias'], 20).' -
    '; +foreach (dbFetchRows($sql) as $interface) +{ + echo("
    +
    ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down + ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    + ".truncate($interface['ifAlias'], 20)." +
    "); + } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) { - echo "
    -
    ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down - ".$service['service_type'].'
    - '.truncate($interface['ifAlias'], 20).' -
    '; +foreach (dbFetchRows($sql) as $service) +{ + echo("
    +
    ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down + ".$service['service_type']."
    + ".truncate($interface['ifAlias'], 20)." +
    "); + } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) { - echo "
    -
    ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down - ".$peer['bgpPeerIdentifier'].'
    - AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
    '; +foreach (dbFetchRows($sql) as $peer) +{ + echo("
    +
    ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down + ".$peer['bgpPeerIdentifier']."
    + AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." +
    "); + } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { - $sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '".$config['uptime_warning']."'"; - foreach (dbFetchRows($sql) as $device) { - echo "
    -
    ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value']).' -
    '; - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) +{ + $sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '" . $config['uptime_warning'] . "'"; + foreach (dbFetchRows($sql) as $device) + { + echo("
    +
    ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value'])." +
    "); + } } -echo " +echo(" -
    $errorboxes
    +
    $errorboxes
    -

    Recent Syslog Messages

    +

    Recent Syslog Messages

    - "; +"); $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; -echo '
    Devices with Alerts
    Host
    Int
    Srv
    '; -foreach (dbFetchRows($sql) as $entry) { - include 'includes/print-syslog.inc.php'; +echo("
    "); +foreach (dbFetchRows($sql) as $entry) +{ + include("includes/print-syslog.inc.php"); } +echo("
    "); -echo ''; +echo("
    -echo '
    - - - '; + + "); // this stuff can be customised to show whatever you want.... -if ($_SESSION['userlevel'] >= '5') { - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['l2tp'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['transit'] .= $seperator.$interface['port_id']; - $seperator = ','; - } +if ($_SESSION['userlevel'] >= '5') +{ + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['l2tp'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= $config['mydomain']."' ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['voip'] .= $seperator.$interface['port_id']; - $seperator = ','; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['transit'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - if ($ports['transit']) { - echo "', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    Internet Transit
    "."
    "; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%"; + $sql .= $config['mydomain'] . "' ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['voip'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - if ($ports['l2tp']) { - echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    L2TP ADSL
    "."
    "; - } + if ($ports['transit']) + { + echo("', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". + "
    Internet Transit
    ". + "
    "); + } - if ($ports['voip']) { - echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >"."
    VoIP to PSTN
    "."
    "; - } -}//end if + if ($ports['l2tp']) + { + echo("', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". + "
    L2TP ADSL
    ". + "
    "); + } + + if ($ports['voip']) + { + echo("', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >". + "
    VoIP to PSTN
    ". + "
    "); + } + +} // END VOSTRON + ?> diff --git a/html/pages/front/globe.php b/html/pages/front/globe.php index 9884b402fa..75a5917c70 100644 --- a/html/pages/front/globe.php +++ b/html/pages/front/globe.php @@ -4,17 +4,16 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 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. - * + * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ + * along with this program. If not, see . */ -/* +/** * Custom Frontpage * @author f0o * @copyright 2014 f0o, LibreNMS @@ -26,111 +25,107 @@ ?> -
    -
    -
    -
    -
    -
    -
    -
    '; - include_once("includes/device-summary-vert.inc.php"); -echo '
    -
    -
    -
    '; - include_once("includes/front/boxes.inc.php"); -echo '
    -
    -
    -
    -
    -
    -
    '; - $device['device_id'] = '-1'; - require_once('includes/print-alerts.php'); - unset($device['device_id']); -echo '
    -
    +
    +
    +
    +
    +
    +
    +
    +
    '; + include_once("includes/device-summary-vert.inc.php"); +echo '
    +
    +
    +
    '; + include_once("includes/front/boxes.inc.php"); +echo '
    +
    +
    +
    +
    +
    +
    '; + $device['device_id'] = '-1'; + require_once('includes/print-alerts.php'); + unset($device['device_id']); +echo '
    +
    '; //From default.php - This code is not part of above license. if ($config['enable_syslog']) { - $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; - $query = mysql_query($sql); - echo('
    +$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; +$query = mysql_query($sql); +echo('
      @@ -144,28 +139,29 @@ if ($config['enable_syslog']) {
    '); - foreach (dbFetchRows($sql) as $entry) { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); + foreach (dbFetchRows($sql) as $entry) + { + $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - include 'includes/print-syslog.inc.php'; - } - echo("
    "); - echo("
    "); - echo("
    "); - echo("
    "); - echo(""); -} -else { + include("includes/print-syslog.inc.php"); + } + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); - if ($_SESSION['userlevel'] == '10') { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - } - else { - $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = - P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; - } +} else { - $data = mysql_query($query); + if ($_SESSION['userlevel'] == '10') + { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; + } else { + $query = "SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = + P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; + } + + $data = mysql_query($query); echo('
    @@ -181,13 +177,15 @@ else {
    '); - foreach (dbFetchRows($query) as $entry) { - include 'includes/print-event.inc.php'; - } + foreach (dbFetchRows($query) as $entry) + { + include("includes/print-event.inc.php"); + } - echo("
    "); - echo("
    "); - echo(""); - echo(""); - echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); } +?> diff --git a/html/pages/front/jt.php b/html/pages/front/jt.php index cda0b49bb7..2256cf0856 100644 --- a/html/pages/front/jt.php +++ b/html/pages/front/jt.php @@ -5,209 +5,238 @@ $nodes = array(); -$uptimesql = ''; -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { - $uptimesql = " AND A.attrib_value < '".$config['uptime_warning']."'"; +$uptimesql = ""; +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) +{ + $uptimesql = " AND A.attrib_value < '" . $config['uptime_warning'] . "'"; } -$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql; +$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql; -foreach (dbFetchRows($sql) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; +foreach (dbFetchRows($sql) as $device) +{ + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = "yes"; } + $i++; + } + if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id'])) { - echo "
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35).' -
    '; - } +foreach (dbFetchRows($sql) as $device) +{ + if (device_permitted($device['device_id'])) { + echo("
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35)." +
    "); + } } if ($config['warn']['ifdown']) { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; - foreach (dbFetchRows($sql) as $interface) { - if (port_permitted($interface['port_id'])) { - echo "
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    - '.truncate($interface['ifAlias'], 15).' -
    '; - } - } + +$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; +foreach (dbFetchRows($sql) as $interface) +{ + if (port_permitted($interface['port_id'])) { + echo("
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    + ".truncate($interface['ifAlias'], 15)." +
    "); + } +} + } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) { - if (device_permitted($service['device_id'])) { - echo "
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type'].'
    - '.truncate($interface['ifAlias'], 15).' -
    '; - } +foreach (dbFetchRows($sql) as $service) +{ + if (device_permitted($service['device_id'])) { + echo("
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type']."
    + ".truncate($interface['ifAlias'], 15)." +
    "); + } } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) { - if (device_permitted($peer['device_id'])) { - echo "
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier'].'
    - AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
    '; - } +foreach (dbFetchRows($sql) as $peer) +{ + if (device_permitted($peer['device_id'])) { + echo("
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier']."
    + AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." +
    "); + } } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '".$config['uptime_warning']."' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { - echo "
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value']).' -
    '; - } - } +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) +{ + $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . $config['uptime_warning'] . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; + foreach (dbFetchRows($sql) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") { + echo("
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value'])." +
    "); + } + } } -echo " +echo(" -
    $errorboxes
    +
    $errorboxes
    -

    Recent Syslog Messages

    +

    Recent Syslog Messages

    - "; +"); $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo ''; -foreach (dbFetchRows($sql) as $entry) { - include 'includes/print-syslog.inc.php'; +echo("
    "); +foreach (dbFetchRows($sql) as $entry) +{ + include("includes/print-syslog.inc.php"); } +echo("
    "); -echo ''; +echo("
    -echo '
    - - - '; + + "); // this stuff can be customised to show whatever you want.... -if ($_SESSION['userlevel'] >= '5') { - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['transit'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['peering'] .= $seperator.$interface['port_id']; - $seperator = ','; - } +if ($_SESSION['userlevel'] >= '5') +{ - $ports['broadband'] = '3294,3295,688,3534'; - $ports['wave_broadband'] = '827'; + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['transit'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - $ports['new_broadband'] = '3659,4149,4121,4108,3676,4135'; + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['peering'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - echo "
    "; + $ports['broadband'] = "3294,3295,688,3534"; + $ports['wave_broadband'] = "827"; - if ($ports['peering'] && $ports['transit']) { - echo ""; - } + $ports['new_broadband'] = "3659,4149,4121,4108,3676,4135"; - echo '
    '; + echo("
    "); - echo ""); - if ($ports['peering']) { - echo ""; - } + echo("
    "); - echo '
    '; + if ($ports['transit']) { + echo(""); + } - echo ""); - echo "
    "; + echo("
    "); - if ($ports['broadband']) { - echo ""; - } + if ($ports['broadband'] && $ports['wave_broadband'] && $ports['new_broadband']) { + echo(""); + } - echo "
    "; + echo("'; + echo("'; -}//end if + echo("
    "); + + if ($ports['wave_broadband']) { + echo(""); + } + + echo("
    "); + +} ?> diff --git a/html/pages/front/traffic.php b/html/pages/front/traffic.php index 6b501cf9c1..5f9a8acced 100644 --- a/html/pages/front/traffic.php +++ b/html/pages/front/traffic.php @@ -3,172 +3,200 @@ 0) { - $uptimesql = ' AND A.attrib_value < ?'; - $param = array($config['uptime_warning']); +$nodes = array(); +$param = array(); +$uptimesql = ""; +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) +{ + $uptimesql = " AND A.attrib_value < ?"; + $param = array($config['uptime_warning']); } -foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql, $param) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; +foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' " . $uptimesql, $param) as $device) +{ + unset($already); + $i = 0; + while ($i <= count($nodes)) { + $thisnode = $device['device_id']; + if ($nodes[$i] == $thisnode) { + $already = "yes"; } + $i++; + } + if (!$already) { $nodes[] = $device['device_id']; } } -foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) { - if (device_permitted($device['device_id'])) { - echo "
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device Down
    - ".truncate($device['location'], 35).' -
    '; - } +foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) +{ + if (device_permitted($device['device_id'])) { + echo("
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device Down
    + ".truncate($device['location'], 35)." +
    "); + } } if ($config['warn']['ifdown']) { - foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) { - if (port_permitted($interface['port_id'])) { - echo "
    - ".generate_device_link($interface, shorthost($interface['hostname']))."
    - Port Down
    - ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
    - '.truncate($interface['ifAlias'], 15).' -
    '; - } - } + +foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) +{ + if (port_permitted($interface['port_id'])) { + echo("
    + ".generate_device_link($interface, shorthost($interface['hostname']))."
    + Port Down
    + ".generate_port_link($interface, makeshortif($interface['ifDescr']))."
    + ".truncate($interface['ifAlias'], 15)." +
    "); + } } -foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) { - if (device_permitted($service['device_id'])) { - echo "
    - ".generate_device_link($service, shorthost($service['hostname']))."
    - Service Down
    - ".$service['service_type'].'
    - '.truncate($interface['ifAlias'], 15).' -
    '; - } } -foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) { - if (device_permitted($peer['device_id'])) { - echo "
    - ".generate_device_link($peer, shorthost($peer['hostname']))."
    - BGP Down
    - ".$peer['bgpPeerIdentifier'].'
    - AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
    '; - } +foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) +{ + if (device_permitted($service['device_id'])) { + echo("
    + ".generate_device_link($service, shorthost($service['hostname']))."
    + Service Down
    + ".$service['service_type']."
    + ".truncate($interface['ifAlias'], 15)." +
    "); + } } -if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== false && $config['uptime_warning'] > 0) { - foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", array($config['uptime_warning'])) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == 'uptime') { - echo "
    - ".generate_device_link($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    - ".formatUptime($device['attrib_value']).' -
    '; - } - } +foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) +{ + if (device_permitted($peer['device_id'])) { + echo("
    + ".generate_device_link($peer, shorthost($peer['hostname']))."
    + BGP Down
    + ".$peer['bgpPeerIdentifier']."
    + AS".$peer['bgpPeerRemoteAs']." ".truncate($peer['astext'], 10)." +
    "); + } } -echo " +if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) +{ + foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", array($config['uptime_warning'])) as $device) { + if (device_permitted($device['device_id']) && $device['attrib_value'] < $config['uptime_warning'] && $device['attrib_type'] == "uptime") { + echo("
    + ".generate_device_link($device, shorthost($device['hostname']))."
    + Device
    Rebooted

    + ".formatUptime($device['attrib_value'])." +
    "); + } + } +} -
    $errorboxes
    +echo(" -

    Recent Syslog Messages

    +
    $errorboxes
    - "; +

    Recent Syslog Messages

    + +"); $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo ''; -foreach (dbFetchRows($sql) as $entry) { - include 'includes/print-syslog.inc.php'; +echo("
    "); +foreach (dbFetchRows($sql) as $entry) +{ + include("includes/print-syslog.inc.php"); } +echo("
    "); -echo ''; +echo("
    -echo '
    - - - '; + + "); // this stuff can be customised to show whatever you want.... -if ($_SESSION['userlevel'] >= '5') { - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['transit'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['peering'] .= $seperator.$interface['port_id']; - $seperator = ','; - } +if ($_SESSION['userlevel'] >= '5') +{ - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['core'] .= $seperator.$interface['port_id']; - $seperator = ','; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['transit'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - echo "
    "; + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['peering'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - if ($ports['peering'] && $ports['transit']) { - echo ""; - } + $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; + unset ($seperator); + foreach (dbFetchRows($sql) as $interface) + { + $ports['core'] .= $seperator . $interface['port_id']; + $seperator = ","; + } - echo '
    '; + echo("
    "); - echo ""); - if ($ports['peering']) { - echo ""; - } + echo("'; -}//end if + if ($ports['peering']) + { + echo(""); + } + + if ($ports['core']) + { + echo(""); + } + + echo("
    "); + +} ?> diff --git a/html/pages/graphs.inc.php b/html/pages/graphs.inc.php index 78c6a73e09..0cc268fceb 100644 --- a/html/pages/graphs.inc.php +++ b/html/pages/graphs.inc.php @@ -4,21 +4,17 @@ unset($vars['page']); // Setup here -if($_SESSION['widescreen']) { - $graph_width=1700; - $thumb_width=180; -} -else { - $graph_width=1075; - $thumb_width=113; +if($_SESSION['widescreen']) +{ + $graph_width=1700; + $thumb_width=180; +} else { + $graph_width=1075; + $thumb_width=113; } -if (!is_numeric($vars['from'])) { - $vars['from'] = $config['time']['day']; -} -if (!is_numeric($vars['to'])) { - $vars['to'] = $config['time']['now']; -} +if (!is_numeric($vars['from'])) { $vars['from'] = $config['time']['day']; } +if (!is_numeric($vars['to'])) { $vars['to'] = $config['time']['now']; } preg_match('/^(?P[A-Za-z0-9]+)_(?P.+)/', $vars['type'], $graphtype); @@ -26,201 +22,208 @@ $type = $graphtype['type']; $subtype = $graphtype['subtype']; $id = $vars['id']; -if(is_numeric($vars['device'])) { - $device = device_by_id_cache($vars['device']); -} -elseif(!empty($vars['device'])) { - $device = device_by_name($vars['device']); +if(is_numeric($vars['device'])) +{ + $device = device_by_id_cache($vars['device']); +} elseif(!empty($vars['device'])) { + $device = device_by_name($vars['device']); } -if (is_file("includes/graphs/".$type."/auth.inc.php")) { - require "includes/graphs/".$type."/auth.inc.php"; +if (is_file("includes/graphs/".$type."/auth.inc.php")) +{ + include("includes/graphs/".$type."/auth.inc.php"); } -if (!$auth) { - require 'includes/error-no-perm.inc.php'; -} -else { - if (isset($config['graph_types'][$type][$subtype]['descr'])) { - $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; - } - else { - $title .= " :: ".ucfirst($subtype); - } +if (!$auth) +{ + include("includes/error-no-perm.inc.php"); +} else { + if (isset($config['graph_types'][$type][$subtype]['descr'])) + { + $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; + } else { + $title .= " :: ".ucfirst($subtype); + } - $graph_array = $vars; - $graph_array['height'] = "60"; - $graph_array['width'] = $thumb_width; - $graph_array['legend'] = "no"; - $graph_array['to'] = $config['time']['now']; + $graph_array = $vars; + $graph_array['height'] = "60"; + $graph_array['width'] = $thumb_width; + $graph_array['legend'] = "no"; + $graph_array['to'] = $config['time']['now']; - print_optionbar_start(); - echo($title); + print_optionbar_start(); + echo($title); - echo('
    '); -?> + echo('
    '); + ?>
    -'); + '); - print_optionbar_end(); + print_optionbar_end(); - print_optionbar_start(); + print_optionbar_start(); - $thumb_array = array('sixhour' => '6 Hours', 'day' => '24 Hours', 'twoday' => '48 Hours', 'week' => 'One Week', 'twoweek' => 'Two Weeks', - 'month' => 'One Month', 'twomonth' => 'Two Months','year' => 'One Year', 'twoyear' => 'Two Years'); + $thumb_array = array('sixhour' => '6 Hours', 'day' => '24 Hours', 'twoday' => '48 Hours', 'week' => 'One Week', 'twoweek' => 'Two Weeks', + 'month' => 'One Month', 'twomonth' => 'Two Months','year' => 'One Year', 'twoyear' => 'Two Years'); - echo(''); + echo('
    '); - foreach ($thumb_array as $period => $text) { - $graph_array['from'] = $config['time'][$period]; + foreach ($thumb_array as $period => $text) + { + $graph_array['from'] = $config['time'][$period]; - $link_array = $vars; - $link_array['from'] = $graph_array['from']; - $link_array['to'] = $graph_array['to']; - $link_array['page'] = "graphs"; - $link = generate_url($link_array); + $link_array = $vars; + $link_array['from'] = $graph_array['from']; + $link_array['to'] = $graph_array['to']; + $link_array['page'] = "graphs"; + $link = generate_url($link_array); - echo(''); + echo(''); - } + } - echo('
    '); - echo(''.$text.'
    '); - echo(''); - echo(generate_graph_tag($graph_array)); - echo(''); - echo('
    '); + echo(''.$text.'
    '); + echo(''); + echo(generate_graph_tag($graph_array)); + echo(''); + echo('
    '); + echo(''); - $graph_array = $vars; - $graph_array['height'] = "300"; - $graph_array['width'] = $graph_width; + $graph_array = $vars; + $graph_array['height'] = "300"; + $graph_array['width'] = $graph_width; - echo("
    "); + echo("
    "); - // datetime range picker + // datetime range picker ?> - "); - echo(' + echo(" +
    + "); + echo('
    - - + +
    - - + +
    -
    - '); - echo("
    "); + echo("
    "); - if ($vars['legend'] == "no") { - echo(generate_link("Show Legend",$vars, array('page' => "graphs", 'legend' => NULL))); - } - else { - echo(generate_link("Hide Legend",$vars, array('page' => "graphs", 'legend' => "no"))); - } + if ($vars['legend'] == "no") + { + echo(generate_link("Show Legend",$vars, array('page' => "graphs", 'legend' => NULL))); + } else { + echo(generate_link("Hide Legend",$vars, array('page' => "graphs", 'legend' => "no"))); + } - // FIXME : do this properly - # if ($type == "port" && $subtype == "bits") - # { + // FIXME : do this properly +# if ($type == "port" && $subtype == "bits") +# { echo(' | '); - if ($vars['previous'] == "yes") { - echo(generate_link("Hide Previous",$vars, array('page' => "graphs", 'previous' => NULL))); + if ($vars['previous'] == "yes") + { + echo(generate_link("Hide Previous",$vars, array('page' => "graphs", 'previous' => NULL))); + } else { + echo(generate_link("Show Previous",$vars, array('page' => "graphs", 'previous' => "yes"))); } - else { - echo(generate_link("Show Previous",$vars, array('page' => "graphs", 'previous' => "yes"))); - } - # } +# } - echo('
    '); + echo('
    '); - if ($vars['showcommand'] == "yes") { - echo(generate_link("Hide RRD Command",$vars, array('page' => "graphs", 'showcommand' => NULL))); - } - else { - echo(generate_link("Show RRD Command",$vars, array('page' => "graphs", 'showcommand' => "yes"))); - } + if ($vars['showcommand'] == "yes") + { + echo(generate_link("Hide RRD Command",$vars, array('page' => "graphs", 'showcommand' => NULL))); + } else { + echo(generate_link("Show RRD Command",$vars, array('page' => "graphs", 'showcommand' => "yes"))); + } - echo('
    '); + echo('
    '); - print_optionbar_end(); + print_optionbar_end(); - echo generate_graph_js_state($graph_array); + echo generate_graph_js_state($graph_array); - echo('
    '); - echo(generate_graph_tag($graph_array)); - echo("
    "); + echo('
    '); + echo(generate_graph_tag($graph_array)); + echo("
    "); - if (isset($config['graph_descr'][$vars['type']])) { + if (isset($config['graph_descr'][$vars['type']])) + { - print_optionbar_start(); - echo('
    -
    + print_optionbar_start(); + echo('
    +
    -
    -
    '); - echo($config['graph_descr'][$vars['type']]); - print_optionbar_end(); - } +
    +
    '); + echo($config['graph_descr'][$vars['type']]); + print_optionbar_end(); + } - if ($vars['showcommand']) { - $_GET = $graph_array; - $command_only = 1; + if ($vars['showcommand']) + { + $_GET = $graph_array; + $command_only = 1; - require 'includes/graphs/graph.inc.php'; - } + include("includes/graphs/graph.inc.php"); + } } + +?> diff --git a/html/pages/health.inc.php b/html/pages/health.inc.php index eb13def9b7..3b06d4db6b 100644 --- a/html/pages/health.inc.php +++ b/html/pages/health.inc.php @@ -30,12 +30,8 @@ $type_text['toner'] = "Toner"; $type_text['dbm'] = "dBm"; $type_text['load'] = "Load"; -if (!$vars['metric']) { - $vars['metric'] = "processor"; -} -if (!$vars['view']) { - $vars['view'] = "detail"; -} +if (!$vars['metric']) { $vars['metric'] = "processor"; } +if (!$vars['view']) { $vars['view'] = "detail"; } $link_array = array('page' => 'health'); @@ -46,44 +42,48 @@ print_optionbar_start('', ''); echo('Health » '); $sep = ""; -foreach ($datas as $texttype) { - $metric = strtolower($texttype); - echo($sep); - if ($vars['metric'] == $metric) { - echo(""); - } +foreach ($datas as $texttype) +{ + $metric = strtolower($texttype); + echo($sep); + if ($vars['metric'] == $metric) + { + echo(""); + } - echo(generate_link($type_text[$metric],$link_array,array('metric'=> $metric, 'view' => $vars['view']))); + echo(generate_link($type_text[$metric],$link_array,array('metric'=> $metric, 'view' => $vars['view']))); - if ($vars['metric'] == $metric) { - echo(""); - } + if ($vars['metric'] == $metric) { echo(""); } - $sep = ' | '; + $sep = ' | '; } unset ($sep); echo('
    '); -if ($vars['view'] == "graphs") { - echo(''); +if ($vars['view'] == "graphs") +{ + echo(''); } echo(generate_link("Graphs",$link_array,array('metric'=> $vars['metric'], 'view' => "graphs"))); -if ($vars['view'] == "graphs") { - echo(''); +if ($vars['view'] == "graphs") +{ + echo(''); } echo(' | '); -if ($vars['view'] != "graphs") { - echo(''); +if ($vars['view'] != "graphs") +{ + echo(''); } echo(generate_link("No Graphs",$link_array,array('metric'=> $vars['metric'], 'view' => "detail"))); -if ($vars['view'] != "graphs") { - echo(''); +if ($vars['view'] != "graphs") +{ + echo(''); } echo('
    '); @@ -91,14 +91,16 @@ echo('
    '); print_optionbar_end(); if (in_array($vars['metric'],array_keys($used_sensors)) - || $vars['metric'] == 'processor' - || $vars['metric'] == 'storage' - || $vars['metric'] == 'toner' - || $vars['metric'] == 'mempool') { - include('pages/health/'.$vars['metric'].'.inc.php'); + || $vars['metric'] == 'processor' + || $vars['metric'] == 'storage' + || $vars['metric'] == 'toner' + || $vars['metric'] == 'mempool') +{ + include('pages/health/'.$vars['metric'].'.inc.php'); } -else { - echo("No sensors of type " . $vars['metric'] . " found."); +else +{ + echo("No sensors of type " . $vars['metric'] . " found."); } ?> diff --git a/html/pages/health/charge.inc.php b/html/pages/health/charge.inc.php index 3838d0e790..867b50f9e8 100644 --- a/html/pages/health/charge.inc.php +++ b/html/pages/health/charge.inc.php @@ -4,4 +4,6 @@ $graph_type = "sensor_charge"; $unit = "%"; $class = "charge"; -require 'pages/health/sensors.inc.php'; +include("pages/health/sensors.inc.php"); + +?> diff --git a/html/pages/health/load.inc.php b/html/pages/health/load.inc.php index f506e3ca1d..d9257519d3 100644 --- a/html/pages/health/load.inc.php +++ b/html/pages/health/load.inc.php @@ -1,7 +1,9 @@ diff --git a/html/pages/health/sensors.inc.php b/html/pages/health/sensors.inc.php index 52828b9c19..02224d485c 100644 --- a/html/pages/health/sensors.inc.php +++ b/html/pages/health/sensors.inc.php @@ -1,18 +1,19 @@ = '5') { - $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr"; - $param = array(); -} -else { - $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = ? ORDER BY D.hostname, S.sensor_descr"; - $param = array($_SESSION['user_id']); + +if ($_SESSION['userlevel'] >= '5') +{ + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr"; + $param = array(); +} else { + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = ? ORDER BY D.hostname, S.sensor_descr"; + $param = array($_SESSION['user_id']); } -echo ''; +echo('
    '); -echo ' +echo(' @@ -20,102 +21,99 @@ echo ' - '; + '); -foreach (dbFetchRows($sql, $param) as $sensor) { - if ($config['memcached']['enable'] === true) { - $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); - if ($debug) { - echo 'Memcached['.'sensor-'.$sensor['sensor_id'].'-value'.'='.$sensor['sensor_current'].']'; - } - } +foreach (dbFetchRows($sql, $param) as $sensor) +{ - if (empty($sensor['sensor_current'])) { - $sensor['sensor_current'] = 'NaN'; - } - else { - if ($sensor['sensor_current'] >= $sensor['sensor_limit']) { - $alert = 'alert'; - } - else { - $alert = ''; - } - } + if ($config['memcached']['enable'] === TRUE) + { + $sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value'); + if($debug) { echo("Memcached[".'sensor-'.$sensor['sensor_id'].'-value'."=".$sensor['sensor_current']."]"); } + } + + if (empty($sensor['sensor_current'])) + { + $sensor['sensor_current'] = "NaN"; + } else { + if ($sensor['sensor_current'] >= $sensor['sensor_limit']) { $alert = 'alert'; } else { $alert = ""; } + } // FIXME - make this "four graphs in popup" a function/include and "small graph" a function. // FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"? // FIXME - DUPLICATED IN device/overview/sensors - $graph_colour = str_replace('#', '', $row_colour); + + $graph_colour = str_replace("#", "", $row_colour); $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = $graph_type; $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $graph_array['legend'] = "no"; - $link_array = $graph_array; - $link_array['page'] = 'graphs'; + $link_array = $graph_array; + $link_array['page'] = "graphs"; unset($link_array['height'], $link_array['width'], $link_array['legend']); $link_graph = generate_url($link_array); - $link = generate_url(array('page' => 'device', 'device' => $sensor['device_id'], 'tab' => 'health', 'metric' => $sensor['sensor_class'])); + $link = generate_url(array("page" => "device", "device" => $sensor['device_id'], "tab" => "health", "metric" => $sensor['sensor_class'])); - $overlib_content = '

    '.$device['hostname'].' - '.$sensor['sensor_descr'].'

    '; - foreach (array('day', 'week', 'month', 'year') as $period) { - $graph_array['from'] = $config['time'][$period]; - $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); + $overlib_content = '

    '.$device['hostname']." - ".$sensor['sensor_descr']."

    "; + foreach (array('day','week','month','year') as $period) + { + $graph_array['from'] = $config['time'][$period]; + $overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array)); } + $overlib_content .= "
    "; - $overlib_content .= '
    '; - - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00'; # the 00 at the end makes the area transparent. $graph_array['from'] = $config['time']['day']; - $sensor_minigraph = generate_graph_tag($graph_array); + $sensor_minigraph = generate_graph_tag($graph_array); $sensor['sensor_descr'] = truncate($sensor['sensor_descr'], 48, ''); - echo ' - - + echo(' + + - - - + + + - '; + '); - if ($vars['view'] == 'graphs') { - echo "'; - } //end if -}//end foreach + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo(""); + } # endif graphs +} -echo '
    Device Sensor
    Current Range limit Notes
    '.generate_device_link($sensor).''.overlib_link($link, $sensor['sensor_descr'], $overlib_content).'
    ' . generate_device_link($sensor) . ''.overlib_link($link, $sensor['sensor_descr'],$overlib_content).' '.overlib_link($link_graph, $sensor_minigraph, $overlib_content).' '.$alert.''.$sensor['sensor_current'].$unit.''.round($sensor['sensor_limit_low'], 2).$unit.' - '.round($sensor['sensor_limit'], 2).$unit.''.(isset($sensor['sensor_notes']) ? $sensor['sensor_notes'] : '').'' . $sensor['sensor_current'] . $unit . '' . round($sensor['sensor_limit_low'],2) . $unit . ' - ' . round($sensor['sensor_limit'],2) . $unit . '' . (isset($sensor['sensor_notes']) ? $sensor['sensor_notes'] : '') . '
    "; + if ($vars['view'] == "graphs") + { + echo("
    "); - $daily_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=211&height=100'; - $daily_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=400&height=150'; + $daily_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=211&height=100"; + $daily_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=400&height=150"; - $weekly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=211&height=100'; - $weekly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=400&height=150'; + $weekly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['week']."&to=".$config['time']['now']."&width=211&height=100"; + $weekly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['week']."&to=".$config['time']['now']."&width=400&height=150"; - $monthly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=211&height=100'; - $monthly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=400&height=150'; + $monthly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['month']."&to=".$config['time']['now']."&width=211&height=100"; + $monthly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['month']."&to=".$config['time']['now']."&width=400&height=150"; - $yearly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=211&height=100'; - $yearly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=400&height=150'; + $yearly_graph = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['year']."&to=".$config['time']['now']."&width=211&height=100"; + $yearly_url = "graph.php?id=" . $sensor['sensor_id'] . "&type=".$graph_type."&from=".$config['time']['year']."&to=".$config['time']['now']."&width=400&height=150"; - echo "', LEFT);\" onmouseout=\"return nd();\"> - "; - echo "', LEFT);\" onmouseout=\"return nd();\"> - "; - echo "', LEFT);\" onmouseout=\"return nd();\"> - "; - echo "', LEFT);\" onmouseout=\"return nd();\"> - "; - echo '
    '; +echo(""); + +?> diff --git a/html/pages/iftype.inc.php b/html/pages/iftype.inc.php index 8a6d20201b..f4349111cd 100644 --- a/html/pages/iftype.inc.php +++ b/html/pages/iftype.inc.php @@ -9,102 +9,92 @@ + Total Graph for ports of type : ".$types."
    "); -echo " - Total Graph for ports of type : ".$types.'
    '; +if ($if_list) +{ + $graph_type = "multiport_bits_separate"; + $port['port_id'] = $if_list; -if ($if_list) { - $graph_type = 'multiport_bits_separate'; - $port['port_id'] = $if_list; + include("includes/print-interface-graphs.inc.php"); - include 'includes/print-interface-graphs.inc.php'; + echo(""); - echo ''; + foreach ($ports as $port) + { + $done = "yes"; + unset($class); + $port['ifAlias'] = str_ireplace($type . ": ", "", $port['ifAlias']); + $port['ifAlias'] = str_ireplace("[PNI]", "Private", $port['ifAlias']); + $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); + if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg = "#ffffff"; } + echo(" + " . generate_port_link($port,$port['port_descr_descr']) . "
    + ".generate_device_link($port)." ".generate_port_link($port)." + ".generate_port_link($port, makeshortif($port['ifDescr']))." + ".$port['port_descr_speed']." + ".$port['port_descr_circuit']." + ".$port['port_descr_notes']." + + + - ".generate_port_link($port, $port['port_descr_descr'])."
    - ".generate_device_link($port).' '.generate_port_link($port).' - '.generate_port_link($port, makeshortif($port['ifDescr'])).' - '.$port['port_descr_speed'].' - '.$port['port_descr_circuit'].' - '.$port['port_descr_notes']." - - - MAC Accounting"; - } - - echo '
    '; - - if (file_exists($config['rrd_dir'].'/'.$port['hostname'].'/port-'.$port['ifIndex'].'.rrd')) { - $graph_type = 'port_bits'; - - include 'includes/print-interface-graphs.inc.php'; - } - - echo ''; + if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = ?", array($port['port_id']))) + { + echo(" MAC Accounting"); } + + echo('
    '); + + if (file_exists($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . $port['ifIndex'] . ".rrd")) + { + $graph_type = "port_bits"; + + include("includes/print-interface-graphs.inc.php"); + } + + echo(""); + } + } -else { - echo 'None found.'; +else +{ + echo("None found."); } ?> diff --git a/html/pages/inventory.inc.php b/html/pages/inventory.inc.php index 7fc461e4aa..e53daab965 100644 --- a/html/pages/inventory.inc.php +++ b/html/pages/inventory.inc.php @@ -1,6 +1,6 @@ @@ -29,53 +29,46 @@ var grid = $("#inventory").bootgrid({ header: "
    "+ "
    "+ "
    "+ - "\" placeholder=\"Description\" class=\"form-control input-sm\" />"+ + "\" placeholder=\"Description\" class=\"form-control input-sm\" />"+ "
    "+ "
    "+ " Part No "+ ""+ "
    "+ "
    "+ - "\" placeholder=\"Serial\" class=\"form-control input-sm\"/>"+ + "\" placeholder=\"Serial\" class=\"form-control input-sm\"/>"+ "
    "+ "
    "+ " Device "+ ""+ "
    "+ "
    "+ - " -\" placeholder=\"Description\" class=\"form-control input-sm\"/>"+ + "\" placeholder=\"Description\" class=\"form-control input-sm\"/>"+ "
    "+ ""+ "
    "+ diff --git a/html/pages/locations.inc.php b/html/pages/locations.inc.php index bbe6adcf99..93dffa0e36 100644 --- a/html/pages/locations.inc.php +++ b/html/pages/locations.inc.php @@ -1,92 +1,88 @@ Locations » '; +echo('Locations » '); -$menu_options = array( - 'basic' => 'Basic', - 'traffic' => 'Traffic', -); +$menu_options = array('basic' => 'Basic', + 'traffic' => 'Traffic'); -if (!$vars['view']) { - $vars['view'] = 'basic'; -} +if (!$vars['view']) { $vars['view'] = "basic"; } -$sep = ''; -foreach ($menu_options as $option => $text) { - echo $sep; - if ($vars['view'] == $option) { - echo ""; - } - - echo ''.$text.''; - if ($vars['view'] == $option) { - echo ''; - } - - $sep = ' | '; +$sep = ""; +foreach ($menu_options as $option => $text) +{ + echo($sep); + if ($vars['view'] == $option) + { + echo(""); + } + echo('' . $text . ''); + if ($vars['view'] == $option) + { + echo(""); + } + $sep = " | "; } unset($sep); print_optionbar_end(); -echo ''; +echo('
    '); -foreach (getlocations() as $location) { - if ($_SESSION['userlevel'] >= '10') { - $num = dbFetchCell('SELECT COUNT(device_id) FROM devices WHERE location = ?', array($location)); - $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'network'", array($location)); - $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'server'", array($location)); - $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'firewall'", array($location)); - $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND status = '0'", array($location)); - } - else { - $num = dbFetchCell('SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ?', array($_SESSION['user_id'], $location)); - $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND D.type = 'network'", array($_SESSION['user_id'], $location)); - $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'server'", array($_SESSION['user_id'], $location)); - $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'firewall'", array($_SESSION['user_id'], $location)); - $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND status = '0'", array($_SESSION['user_id'], $location)); +foreach (getlocations() as $location) +{ + if ($_SESSION['userlevel'] >= '10') + { + $num = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ?", array($location)); + $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'network'", array($location)); + $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'server'", array($location)); + $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'firewall'", array($location)); + $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND status = '0'", array($location)); + } else { + $num = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ?", array($_SESSION['user_id'], $location)); + $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND D.type = 'network'", array($_SESSION['user_id'], $location)); + $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'server'", array($_SESSION['user_id'], $location)); + $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'firewall'", array($_SESSION['user_id'], $location)); + $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND status = '0'", array($_SESSION['user_id'], $location)); + } + + if ($hostalerts) { $alert = 'alert'; } else { $alert = ""; } + + if ($location != "") + { + echo(' + + + + + + + + '); + + if ($vars['view'] == "traffic") + { + echo('"); } + $done = "yes"; + } +} - if ($hostalerts) { - $alert = 'alert'; - } - else { - $alert = ''; - } +echo("
    ' . $location . '' . $alert . '' . $num . ' devices' . $net . ' network' . $srv . ' servers' . $fwl . ' firewalls
    '); + + $graph_array['type'] = "location_bits"; + $graph_array['height'] = "100"; + $graph_array['width'] = "220"; + $graph_array['to'] = $config['time']['now']; + $graph_array['legend'] = "no"; + $graph_array['id'] = $location; + + include("includes/print-graphrow.inc.php"); + + echo("
    "); - if ($location != '') { - echo ' - '.$location.' - '.$alert.' - '.$num.' devices - '.$net.' network - '.$srv.' servers - '.$fwl.' firewalls - - '; - - if ($vars['view'] == 'traffic') { - echo ''; - - $graph_array['type'] = 'location_bits'; - $graph_array['height'] = '100'; - $graph_array['width'] = '220'; - $graph_array['to'] = $config['time']['now']; - $graph_array['legend'] = 'no'; - $graph_array['id'] = $location; - - include 'includes/print-graphrow.inc.php'; - - echo ''; - } - - $done = 'yes'; - }//end if -}//end foreach - -echo ''; +?> diff --git a/html/pages/logon.inc.php b/html/pages/logon.inc.php index a8a156574d..e9819b1b01 100644 --- a/html/pages/logon.inc.php +++ b/html/pages/logon.inc.php @@ -1,8 +1,7 @@
    @@ -33,12 +32,14 @@ else {
    'error','message'=>$auth_message,'title'=>'Login error'); } ?>
    diff --git a/html/pages/map.inc.php b/html/pages/map.inc.php index 115c0600c3..0fa1cbb5f7 100644 --- a/html/pages/map.inc.php +++ b/html/pages/map.inc.php @@ -10,5 +10,6 @@ * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ -$pagetitle[] = 'Map'; -require_once 'includes/print-map.inc.php'; +$pagetitle[] = "Map"; +require_once "includes/print-map.inc.php"; +?> diff --git a/html/pages/packages.inc.php b/html/pages/packages.inc.php index ab26fd00a9..c3e79c8cf6 100644 --- a/html/pages/packages.inc.php +++ b/html/pages/packages.inc.php @@ -2,7 +2,8 @@ foreach ($vars as $var => $value) { if ($value != '') { - switch ($var) { + switch ($var) + { case 'name': $where .= " AND `$var` = ?"; $param[] = $value; @@ -25,7 +26,8 @@ foreach (dbFetchRows("SELECT * FROM `packages` WHERE 1 $where GROUP BY `name`", foreach ($entry['blah'] as $version => $bleu) { $content = '
    '; - foreach ($bleu as $build => $bloo) { + foreach ($bleu as $build => $bloo) + { if ($build) { $dbuild = '-'.$build; } @@ -34,7 +36,8 @@ foreach (dbFetchRows("SELECT * FROM `packages` WHERE 1 $where GROUP BY `name`", } $content .= '
    '.$version.$dbuild.''; - foreach ($bloo as $device_id => $no) { + foreach ($bloo as $device_id => $no) + { $this_device = device_by_id_cache($device_id); $content .= ''.$this_device['hostname'].' '; } diff --git a/html/pages/plugin.inc.php b/html/pages/plugin.inc.php index 1f718acff2..daec96f46b 100644 --- a/html/pages/plugin.inc.php +++ b/html/pages/plugin.inc.php @@ -1,18 +1,24 @@ 'plugin'); +$link_array = array('page' => 'plugin'); -$pagetitle[] = 'Plugin'; +$pagetitle[] = "Plugin"; -if ($vars['view'] == 'admin') { - include_once 'pages/plugin/admin.inc.php'; +if ($vars['view'] == "admin") +{ + include_once('pages/plugin/admin.inc.php'); } -else { - $plugin = dbFetchRow("SELECT `plugin_name` FROM `plugins` WHERE `plugin_name` = '".$vars['p']."' AND `plugin_active`='1'"); - if (!empty($plugin)) { - include 'plugins/'.$plugin['plugin_name'].'/'.$plugin['plugin_name'].'.inc.php'; - } - else { - print_error('This plugin is either disabled or not available.'); - } +else +{ + $plugin = dbFetchRow("SELECT `plugin_name` FROM `plugins` WHERE `plugin_name` = '".$vars['p']."' AND `plugin_active`='1'"); + if(!empty($plugin)) + { + require('plugins/'.$plugin['plugin_name'].'/'.$plugin['plugin_name'].'.inc.php'); + } + else + { + print_error( "This plugin is either disabled or not available." ); + } } + +?> diff --git a/html/pages/plugin/admin.inc.php b/html/pages/plugin/admin.inc.php index e20bec1b64..1773d641d8 100644 --- a/html/pages/plugin/admin.inc.php +++ b/html/pages/plugin/admin.inc.php @@ -1,26 +1,33 @@ = '10') { - // Scan for new plugins and add to the database - $new_plugins = scan_new_plugins(); +if ($_SESSION['userlevel'] >= '10') +{ + + // Scan for new plugins and add to the database + $new_plugins = scan_new_plugins(); - // Check if we have to toggle enabled / disable a particular module - $plugin_id = $_POST['plugin_id']; - $plugin_active = $_POST['plugin_active']; - if (is_numeric($plugin_id) && is_numeric($plugin_active)) { - if ($plugin_active == '0') { - $plugin_active = 1; - } - else if ($plugin_active == '1') { - $plugin_active = 0; - } - else { - $plugin_active = 0; - } + // Check if we have to toggle enabled / disable a particular module + $plugin_id = $_POST['plugin_id']; + $plugin_active = $_POST['plugin_active']; + if(is_numeric($plugin_id) && is_numeric($plugin_active)) + { + if( $plugin_active == '0') + { + $plugin_active = 1; + } + elseif( $plugin_active == '1') + { + $plugin_active = 0; + } + else + { + $plugin_active = 0; + } - if (dbUpdate(array('plugin_active' => $plugin_active), 'plugins', '`plugin_id` = ?', array($plugin_id))) { - echo ' + if(dbUpdate(array('plugin_active' => $plugin_active), 'plugins', '`plugin_id` = ?', array($plugin_id))) + { + echo(' -'; - } - }//end if +'); + } + + } ?> @@ -41,13 +49,14 @@ $.ajax({ System plugins
    0) { - echo '
    + if($new_plugins > 0) + { + echo('
    - We have found '.$new_plugins.' new plugins that need to be configured and enabled + We have found ' . $new_plugins . ' new plugins that need to be configured and enabled
    -
    '; -} +
    '); + } ?> @@ -56,21 +65,24 @@ if ($new_plugins > 0) { + foreach (dbFetchRows("SELECT * FROM plugins") as $plugins) + { + if($plugins['plugin_active'] == 1) + { + $plugin_colour = 'bg-success'; + $plugin_button = 'danger'; + $plugin_label = 'Disable'; + } + else + { + $plugin_colour = 'bg-danger'; + $plugin_button = 'success'; + $plugin_label = 'Enable'; + } + echo(' - '; -}//end foreach + '); + } + ?>
    - '.$plugins['plugin_name'].' + '. $plugins['plugin_name'] . ' @@ -79,14 +91,18 @@ foreach (dbFetchRows('SELECT * FROM plugins') as $plugins) {
    diff --git a/html/pages/poll-log.inc.php b/html/pages/poll-log.inc.php index 91ef8132e2..3abdf05a8e 100644 --- a/html/pages/poll-log.inc.php +++ b/html/pages/poll-log.inc.php @@ -1,5 +1,5 @@ diff --git a/html/pages/pollers.inc.php b/html/pages/pollers.inc.php index 3fef3d931c..de85c2344c 100644 --- a/html/pages/pollers.inc.php +++ b/html/pages/pollers.inc.php @@ -12,32 +12,25 @@ * the source code distribution for details. */ -$no_refresh = true; +$no_refresh = TRUE; -echo ''); if (isset($vars['tab'])) { - include_once 'pages/pollers/'.mres($vars['tab']).'.inc.php'; + require_once "pages/pollers/".mres($vars['tab']).".inc.php"; } diff --git a/html/pages/pollers/groups.inc.php b/html/pages/pollers/groups.inc.php index a914650ae2..50019dfc26 100644 --- a/html/pages/pollers/groups.inc.php +++ b/html/pages/pollers/groups.inc.php @@ -12,7 +12,7 @@ * the source code distribution for details. */ -require_once 'includes/modal/poller_groups.inc.php'; +require_once "includes/modal/poller_groups.inc.php"; ?>
    @@ -28,17 +28,18 @@ require_once 'includes/modal/poller_groups.inc.php'; + echo(' + -'; +'); } ?> diff --git a/html/pages/pollers/pollers.inc.php b/html/pages/pollers/pollers.inc.php index f948d3a8b1..c5e0eb2799 100644 --- a/html/pages/pollers/pollers.inc.php +++ b/html/pages/pollers/pollers.inc.php @@ -24,28 +24,26 @@ = 300) { $row_class = 'danger'; - } - else if ($old >= 280 && $old < 300) { + } elseif ($old >= 280 && $old < 300) { $row_class = 'warning'; - } - else { + } else { $row_class = 'success'; } - - echo ' + echo(' -'; +'); } ?> diff --git a/html/pages/ports.inc.php b/html/pages/ports.inc.php index edeea9fbef..8ff1f7d344 100644 --- a/html/pages/ports.inc.php +++ b/html/pages/ports.inc.php @@ -4,27 +4,29 @@ $pagetitle[] = "Ports"; // Set Defaults here -if(!isset($vars['format'])) { - $vars['format'] = "list_basic"; -} +if(!isset($vars['format'])) { $vars['format'] = "list_basic"; } print_optionbar_start(); echo('Lists » '); -$menu_options = array('basic' => 'Basic', 'detail' => 'Detail'); +$menu_options = array('basic' => 'Basic', + 'detail' => 'Detail'); $sep = ""; -foreach ($menu_options as $option => $text) { - echo($sep); - if ($vars['format'] == "list_".$option) { - echo(""); - } - echo('' . $text . ''); - if ($vars['format'] == "list_".$option) { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) +{ + echo($sep); + if ($vars['format'] == "list_".$option) + { + echo(""); + } + echo('' . $text . ''); + if ($vars['format'] == "list_".$option) + { + echo(""); + } + $sep = " | "; } ?> @@ -35,21 +37,24 @@ foreach ($menu_options as $option => $text) { 'Bits', - 'upkts' => 'Unicast Packets', - 'nupkts' => 'Non-Unicast Packets', - 'errors' => 'Errors'); + 'upkts' => 'Unicast Packets', + 'nupkts' => 'Non-Unicast Packets', + 'errors' => 'Errors'); $sep = ""; -foreach ($menu_options as $option => $text) { - echo($sep); - if ($vars['format'] == 'graph_'.$option) { - echo(''); - } - echo('' . $text . ''); - if ($vars['format'] == 'graph_'.$option) { - echo(""); - } - $sep = " | "; +foreach ($menu_options as $option => $text) +{ + echo($sep); + if ($vars['format'] == 'graph_'.$option) + { + echo(''); + } + echo('' . $text . ''); + if ($vars['format'] == 'graph_'.$option) + { + echo(""); + } + $sep = " | "; } echo('
    '); @@ -59,28 +64,29 @@ echo('
    '); Update URL | '')).'">Search'); -} -else { + } else { echo('Search'); -} + } -echo(" | "); + echo(" | "); -if (isset($vars['bare']) && $vars['bare'] == "yes") { + if (isset($vars['bare']) && $vars['bare'] == "yes") + { echo('Header'); -} -else { + } else { echo('Header'); -} + } echo('
    '); print_optionbar_end(); print_optionbar_start(); -if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['searchbar'])) { +if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['searchbar'])) +{ ?>
    @@ -89,66 +95,67 @@ if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars[' = 5) { - $results = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`"); - } - else { - $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); - } - foreach ($results as $data) { - echo(' "); - } +if($_SESSION['userlevel'] >= 5) +{ + $results = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`"); +} +else +{ + $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); +} +foreach ($results as $data) +{ + echo(' "); +} - if($_SESSION['userlevel'] < 5) { - $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); - } - else { - $results = array(); - } - foreach ($results as $data) { - echo(' "); - } +if($_SESSION['userlevel'] < 5) +{ + $results = dbFetchRows("SELECT `D`.`device_id`,`D`.`hostname` FROM `ports` AS `I` JOIN `devices` AS `D` ON `D`.`device_id`=`I`.`device_id` JOIN `ports_perms` AS `PP` ON `PP`.`port_id`=`I`.`port_id` WHERE `PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` GROUP BY `hostname` ORDER BY `hostname`", array($_SESSION['user_id'])); +} +else +{ + $results = array(); +} +foreach ($results as $data) +{ + echo(' "); +} ?> - placeholder="Hostname" /> + placeholder="Hostname" />
    @@ -157,100 +164,97 @@ if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars[' ".$data['ifType'].""); - } - } +if (is_admin() === TRUE || is_read() === TRUE) { + $sql = "SELECT `ifType` FROM `ports` GROUP BY `ifType` ORDER BY `ifType`"; +} else { + $sql = "SELECT `ifType` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` GROUP BY `ifType` ORDER BY `ifType`"; + $param[] = array($_SESSION['user_id'],$_SESSION['user_id']); +} +foreach (dbFetchRows($sql,$param) as $data) +{ + if ($data['ifType']) + { + echo(' "); + } +} ?>
    - placeholder="Port Description"/> + placeholder="Port Description"/>
    - > + > - > + > - > + >
    @@ -262,98 +266,95 @@ if((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['
    '.$group['id'].' '.$group['group_name'].' '.$group['descr'].'
    '.$poller['poller_name'].' '.$poller['devices'].' '.$poller['time_taken'].' Seconds '.$poller['last_polled'].'
    - $value) { - if ($value != "") { - switch ($var) { - case 'hostname': - $where .= " AND D.hostname LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'location': - $where .= " AND D.location LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'device_id': - $where .= " AND D.device_id = ?"; - $param[] = $value; - break; - case 'deleted': - if ($value == 1) { - $where .= " AND `I`.`deleted` = 1"; - $ignore_filter = 1; - } - break; - case 'ignore': - if ($value == 1) { - $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; - $ignore_filter = 1; - } - break; - case 'disabled': - if ($value == 1) { - $where .= " AND `I`.`disabled` = 1 AND `I`.`deleted` = 0"; - $disabled_filter = 1; - } - break; - case 'ifSpeed': - if (is_numeric($value)) { - $where .= " AND I.$var = ?"; - $param[] = $value; - } - break; - case 'ifType': - $where .= " AND I.$var = ?"; - $param[] = $value; - break; - case 'ifAlias': - case 'port_descr_type': - $where .= " AND I.$var LIKE ?"; - $param[] = "%".$value."%"; - break; - case 'errors': - if ($value == 1) { - $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; - } - break; - case 'state': - if ($value == "down") { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; - $param[] = "up"; - $param[] = "down"; - } - elseif($value == "up") { - $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; - $param[] = "up"; - $param[] = "up"; - } - elseif($value == "admindown") { - $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; - $param[] = "down"; - } - break; +foreach ($vars as $var => $value) +{ + if ($value != "") + { + switch ($var) + { + case 'hostname': + $where .= " AND D.hostname LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'location': + $where .= " AND D.location LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'device_id': + $where .= " AND D.device_id = ?"; + $param[] = $value; + break; + case 'deleted': + if ($value == 1) { + $where .= " AND `I`.`deleted` = 1"; + $ignore_filter = 1; } + break; + case 'ignore': + if ($value == 1) { + $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; + $ignore_filter = 1; + } + break; + case 'disabled': + if ($value == 1) { + $where .= " AND `I`.`disabled` = 1 AND `I`.`deleted` = 0"; + $disabled_filter = 1; + } + break; + case 'ifSpeed': + if (is_numeric($value)) + { + $where .= " AND I.$var = ?"; + $param[] = $value; + } + break; + case 'ifType': + $where .= " AND I.$var = ?"; + $param[] = $value; + break; + case 'ifAlias': + case 'port_descr_type': + $where .= " AND I.$var LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'errors': + if ($value == 1) + { + $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; + } + break; + case 'state': + if ($value == "down") + { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; + $param[] = "up"; + $param[] = "down"; + } elseif($value == "up") { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; + $param[] = "up"; + $param[] = "up"; + } elseif($value == "admindown") { + $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; + $param[] = "down"; + } + break; } + } } if ($ignore_filter == 0 && $disabled_filter == 0) { @@ -368,47 +369,49 @@ list($format, $subformat) = explode("_", $vars['format']); $ports = dbFetchRows($query, $param); -switch ($vars['sort']) { - case 'traffic': - $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); - break; - case 'traffic_in': - $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); - break; - case 'traffic_out': - $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); - break; - case 'packets': - $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); - break; - case 'packets_in': - $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); - break; - case 'packets_out': - $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); - break; - case 'errors': - $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); - break; - case 'speed': - $ports = array_sort($ports, 'ifSpeed', SORT_DESC); - break; - case 'port': - $ports = array_sort($ports, 'ifDescr', SORT_ASC); - break; - case 'media': - $ports = array_sort($ports, 'ifType', SORT_ASC); - break; - case 'descr': - $ports = array_sort($ports, 'ifAlias', SORT_ASC); - break; - case 'device': - default: - $ports = array_sort($ports, 'hostname', SORT_ASC); +switch ($vars['sort']) +{ + case 'traffic': + $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); + break; + case 'traffic_in': + $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); + break; + case 'traffic_out': + $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); + break; + case 'packets': + $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); + break; + case 'packets_in': + $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); + break; + case 'packets_out': + $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); + break; + case 'errors': + $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); + break; + case 'speed': + $ports = array_sort($ports, 'ifSpeed', SORT_DESC); + break; + case 'port': + $ports = array_sort($ports, 'ifDescr', SORT_ASC); + break; + case 'media': + $ports = array_sort($ports, 'ifType', SORT_ASC); + break; + case 'descr': + $ports = array_sort($ports, 'ifAlias', SORT_ASC); + break; + case 'device': + default: + $ports = array_sort($ports, 'hostname', SORT_ASC); } -if(file_exists('pages/ports/'.$format.'.inc.php')) { - require 'pages/ports/'.$format.'.inc.php'; +if(file_exists('pages/ports/'.$format.'.inc.php')) +{ + include('pages/ports/'.$format.'.inc.php'); } ?> diff --git a/html/pages/ports/list.inc.php b/html/pages/ports/list.inc.php index 71f52e6180..8ae9c9df36 100644 --- a/html/pages/ports/list.inc.php +++ b/html/pages/ports/list.inc.php @@ -3,75 +3,68 @@ '; +echo(''); -$cols = array( - 'device' => 'Device', - 'port' => 'Port', - 'speed' => 'Speed', - 'traffic_in' => 'Down', - 'traffic_out' => 'Up', - 'media' => 'Media', - 'descr' => 'Description', -); +$cols = array('device' => 'Device', + 'port' => 'Port', + 'speed' => 'Speed', + 'traffic_in' => 'Down', + 'traffic_out' => 'Up', + 'media' => 'Media', + 'descr' => 'Description' ); -foreach ($cols as $sort => $col) { - if (isset($vars['sort']) && $vars['sort'] == $sort) { - echo ''.$col.' *'; - } - else { - echo ''.$col.''; - } +foreach ($cols as $sort => $col) +{ + if (isset($vars['sort']) && $vars['sort'] == $sort) + { + echo(''.$col.' *'); + } else { + echo(''.$col.''); + } } -echo ' '; +echo(" "); -$ports_disabled = 0; -$ports_down = 0; -$ports_up = 0; -$ports_total = 0; +$ports_disabled = 0; $ports_down = 0; $ports_up = 0; $ports_total = 0; -foreach ($ports as $port) { - if (port_permitted($port['port_id'], $port['device_id'])) { - if ($port['ifAdminStatus'] == 'down') { - $ports_disabled++; - } - else if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'down') { - $ports_down++; - } - else if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') { - $ports_up++; - } +foreach ($ports as $port) +{ - $ports_total++; + if (port_permitted($port['port_id'], $port['device_id'])) + { - $speed = humanspeed($port['ifSpeed']); - $type = humanmedia($port['ifType']); - $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); + if ($port['ifAdminStatus'] == "down") { $ports_disabled++; + } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus']== "down") { $ports_down++; + } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus']== "up") { $ports_up++; } + $ports_total++; - if ((isset($port['in_errors']) && $port['in_errors'] > 0) || (isset($ports['out_errors']) && $port['out_errors'] > 0)) { - $error_img = generate_port_link($port, "Interface Errors", errors); - } - else { - $error_img = ''; - } + $speed = humanspeed($port['ifSpeed']); + $type = humanmedia($port['ifType']); + $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); - $port['in_rate'] = formatRates(($port['ifInOctets_rate'] * 8)); - $port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8)); + if ((isset($port['in_errors']) && $port['in_errors'] > 0) || (isset($ports['out_errors']) && $port['out_errors'] > 0)) + { + $error_img = generate_port_link($port,"Interface Errors",errors); + } else { $error_img = ""; } - $port = ifLabel($port, $device); - echo " - ".generate_device_link($port, shorthost($port['hostname'], '20'))." - ".fixIfName($port['label'])." $error_img - $speed - ".$port['in_rate'].' - '.$port['out_rate']." - $type - ".$port['ifAlias']." - \n"; - }//end if -}//end foreach + $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); + $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); -echo ''; -echo "Matched Ports: $ports_total ( Up $ports_up | Down $ports_down | Disabled $ports_disabled )"; -echo ''; + $port = ifLabel($port, $device); + echo(" + ".generate_device_link($port, shorthost($port['hostname'], "20"))." + ".fixIfName($port['label'])." $error_img + $speed + ".$port['in_rate']." + ".$port['out_rate']." + $type + " . $port['ifAlias'] . " + \n"); + } +} + +echo(''); +echo("Matched Ports: $ports_total ( Up $ports_up | Down $ports_down | Disabled $ports_disabled )"); +echo(''); + +?> diff --git a/html/pages/preferences.inc.php b/html/pages/preferences.inc.php index ca2f798352..f4815df24e 100644 --- a/html/pages/preferences.inc.php +++ b/html/pages/preferences.inc.php @@ -1,41 +1,48 @@ User Preferences'; +echo("

    User Preferences

    "); if ($_SESSION['userlevel'] == 11) { + demo_account(); -} -else { - if ($_POST['action'] == 'changepass') { - if (authenticate($_SESSION['username'], $_POST['old_pass'])) { - if ($_POST['new_pass'] == '' || $_POST['new_pass2'] == '') { - $changepass_message = 'Password must not be blank.'; - } - else if ($_POST['new_pass'] == $_POST['new_pass2']) { - changepassword($_SESSION['username'], $_POST['new_pass']); - $changepass_message = 'Password Changed.'; - } - else { - $changepass_message = "Passwords don't match."; - } - } - else { - $changepass_message = 'Incorrect password'; - } + +} else { + +if ($_POST['action'] == "changepass") +{ + if (authenticate($_SESSION['username'],$_POST['old_pass'])) + { + if ($_POST['new_pass'] == "" || $_POST['new_pass2'] == "") + { + $changepass_message = "Password must not be blank."; } + elseif ($_POST['new_pass'] == $_POST['new_pass2']) + { + changepassword($_SESSION['username'],$_POST['new_pass']); + $changepass_message = "Password Changed."; + } + else + { + $changepass_message = "Passwords don't match."; + } + } else { + $changepass_message = "Incorrect password"; + } +} - include 'includes/update-preferences-password.inc.php'; +include("includes/update-preferences-password.inc.php"); - echo "
    "; +echo("
    "); - if (passwordscanchange($_SESSION['username'])) { - echo '

    Change Password

    '; - echo $changepass_message; - echo " +if (passwordscanchange($_SESSION['username'])) +{ + echo("

    Change Password

    "); + echo($changepass_message); + echo("
    @@ -62,107 +69,93 @@ else {
    -"; - echo '
    '; - }//end if +"); + echo("
    "); +} - if ($config['twofactor'] === true) { - if ($_POST['twofactorremove'] == 1) { - include_once $config['install_dir'].'/html/includes/authentication/twofactor.lib.php'; - if (!isset($_POST['twofactor'])) { - echo '
    '; - echo ''; - echo twofactor_form(false); - echo '
    '; - } - else { - $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); - if (empty($twofactor['twofactor'])) { - echo '
    Error: How did you even get here?!
    '; - } - else { - $twofactor = json_decode($twofactor['twofactor'], true); - } - - if (verify_hotp($twofactor['key'], $_POST['twofactor'], $twofactor['counter'])) { - if (!dbUpdate(array('twofactor' => ''), 'users', 'username = ?', array($_SESSION['username']))) { - echo '
    Error while disabling TwoFactor.
    '; - } - else { - echo '
    TwoFactor Disabled.
    '; - } - } - else { - session_destroy(); - echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; - } - }//end if +if( $config['twofactor'] === true ) { + if( $_POST['twofactorremove'] == 1 ) { + require_once($config['install_dir']."/html/includes/authentication/twofactor.lib.php"); + if( !isset($_POST['twofactor']) ) { + echo '
    '; + echo ''; + echo twofactor_form(false); + echo '
    '; + } else{ + $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); + if( empty($twofactor['twofactor']) ) { + echo '
    Error: How did you even get here?!
    '; + } else { + $twofactor = json_decode($twofactor['twofactor'],true); + } + if( verify_hotp($twofactor['key'],$_POST['twofactor'],$twofactor['counter']) ) { + if( !dbUpdate(array('twofactor' => ''),'users','username = ?',array($_SESSION['username'])) ) { + echo '
    Error while disabling TwoFactor.
    '; + } else { + echo '
    TwoFactor Disabled.
    '; } - else { - $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); - echo ''; - echo '

    Two-Factor Authentication

    '; - if (!empty($twofactor['twofactor'])) { - $twofactor = json_decode($twofactor['twofactor'], true); - $twofactor['text'] = "
    + } else { + session_destroy(); + echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; + } + } + } else { + $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE username = ?", array($_SESSION['username'])); + echo ''; + echo '

    Two-Factor Authentication

    '; + if( !empty($twofactor['twofactor']) ) { + $twofactor = json_decode($twofactor['twofactor'],true); + $twofactor['text'] = "
    "; - if ($twofactor['counter'] !== false) { - $twofactor['uri'] = 'otpauth://hotp/'.$_SESSION['username'].'?issuer=LibreNMS&counter='.$twofactor['counter'].'&secret='.$twofactor['key']; - $twofactor['text'] .= "
    + if( $twofactor['counter'] !== false ) { + $twofactor['uri'] = "otpauth://hotp/".$_SESSION['username']."?issuer=LibreNMS&counter=".$twofactor['counter']."&secret=".$twofactor['key']; + $twofactor['text'] .= "
    "; - } - else { - $twofactor['uri'] = 'otpauth://totp/'.$_SESSION['username'].'?issuer=LibreNMS&secret='.$twofactor['key']; - } - - echo '
    + } else { + $twofactor['uri'] = "otpauth://totp/".$_SESSION['username']."?issuer=LibreNMS&secret=".$twofactor['key']; + } + echo '
    '; - echo '
    + echo '
    '.$twofactor['text'].'
    '; - echo ''; - echo '
    + echo ''; + echo '
    '; - } - else { - if (isset($_POST['gentwofactorkey']) && isset($_POST['twofactortype'])) { - include_once $config['install_dir'].'/html/includes/authentication/twofactor.lib.php'; - $chk = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); - if (empty($chk['twofactor'])) { - $twofactor = array('key' => twofactor_genkey()); - if ($_POST['twofactortype'] == 'counter') { - $twofactor['counter'] = 1; - } - else { - $twofactor['counter'] = false; - } - - if (!dbUpdate(array('twofactor' => json_encode($twofactor)), 'users', 'username = ?', array($_SESSION['username']))) { - echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; - } - else { - echo '
    Added TwoFactor credentials. Please reload page.
    '; - } - } - else { - echo '
    TwoFactor credentials already exists.
    '; - } - } - else { - echo '
    + } else { + if( isset($_POST['gentwofactorkey']) && isset($_POST['twofactortype']) ) { + require_once($config['install_dir']."/html/includes/authentication/twofactor.lib.php"); + $chk = dbFetchRow("SELECT twofactor FROM users WHERE username = ?", array($_SESSION['username'])); + if( empty($chk['twofactor']) ) { + $twofactor = array('key' => twofactor_genkey()); + if( $_POST['twofactortype'] == "counter" ) { + $twofactor['counter'] = 1; + } else { + $twofactor['counter'] = false; + } + if( !dbUpdate(array('twofactor' => json_encode($twofactor)),'users','username = ?',array($_SESSION['username'])) ) { + echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; + } else { + echo '
    Added TwoFactor credentials. Please reload page.
    '; + } + } else { + echo '
    TwoFactor credentials already exists.
    '; + } + } else { + echo '
    @@ -176,34 +169,32 @@ else {
    '; - }//end if - }//end if - echo '
    '; - }//end if - }//end if -}//end if - -echo "
    '; + } } -echo '
    '; +} + +echo("
    "); +echo("
    Device Permissions
    "); + +if ($_SESSION['userlevel'] == '10') { echo("Global Administrative Access"); } +if ($_SESSION['userlevel'] == '5') { echo("Global Viewing Access"); } +if ($_SESSION['userlevel'] == '1') +{ + + foreach (dbFetchRows("SELECT * FROM `devices_perms` AS P, `devices` AS D WHERE `user_id` = ? AND P.device_id = D.device_id", array($_SESSION['user_id'])) as $perm) + { + #FIXME generatedevicelink? + echo("" . $perm['hostname'] . "
    "); + $dev_access = 1; + } + + if (!$dev_access) { echo("No access!"); } +} + +echo("
    "); + +?> diff --git a/html/pages/pseudowires.inc.php b/html/pages/pseudowires.inc.php index 3408973fd4..5dd77f468c 100644 --- a/html/pages/pseudowires.inc.php +++ b/html/pages/pseudowires.inc.php @@ -90,7 +90,8 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I, devices AS D W $pw_a['to'] = $config['time']['now']; $pw_a['bg'] = $bg; $types = array('bits', 'upkts', 'errors'); - foreach ($types as $graph_type) { + foreach ($types as $graph_type) + { $pw_a['graph_type'] = 'port_'.$graph_type; print_port_thumbnail($pw_a); } diff --git a/html/pages/public.inc.php b/html/pages/public.inc.php index bb25838841..ad89593bcf 100644 --- a/html/pages/public.inc.php +++ b/html/pages/public.inc.php @@ -1,14 +1,14 @@ - * - * 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 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. + * This file is part of LibreNMS + * + * Copyright (c) 2014 Bohdan Sanders + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. */ ?> @@ -28,11 +28,14 @@ $(document).ready(function() {

    System Status

    @@ -47,8 +50,9 @@ $query = "SELECT * FROM `devices` WHERE 1 AND disabled='0' AND `ignore`='0' ORDE Uptime/Location diff --git a/html/pages/routing/bgp.inc.php b/html/pages/routing/bgp.inc.php index 3268715ec5..5e04945626 100644 --- a/html/pages/routing/bgp.inc.php +++ b/html/pages/routing/bgp.inc.php @@ -1,355 +1,260 @@ 'routing', - 'protocol' => 'bgp', - ); +else +{ + $link_array = array('page' => 'routing', 'protocol' => 'bgp'); - print_optionbar_start('', ''); + print_optionbar_start('', ''); - echo 'BGP » '; + echo('BGP » '); - if (!$vars['type']) { - $vars['type'] = 'all'; + if (!$vars['type']) { $vars['type'] = "all"; } + + if ($vars['type'] == "all") { echo(""); } + echo(generate_link("All",$vars, array('type' => 'all'))); + if ($vars['type'] == "all") { echo(""); } + + echo(" | "); + + if ($vars['type'] == "internal") { echo(""); } + echo(generate_link("iBGP",$vars, array('type' => 'internal'))); + if ($vars['type'] == "internal") { echo(""); } + + echo(" | "); + + if ($vars['type'] == "external") { echo(""); } + echo(generate_link("eBGP",$vars, array('type' => 'external'))); + if ($vars['type'] == "external") { echo(""); } + + echo(" | "); + + if ($vars['adminstatus'] == "stop") + { + echo(""); + echo(generate_link("Shutdown",$vars, array('adminstatus' => NULL))); + echo(""); + } else { + echo(generate_link("Shutdown",$vars, array('adminstatus' => 'stop'))); + } + + echo(" | "); + + if ($vars['adminstatus'] == "start") + { + echo(""); + echo(generate_link("Enabled",$vars, array('adminstatus' => NULL))); + echo(""); + } else { + echo(generate_link("Enabled",$vars, array('adminstatus' => 'start'))); + } + + echo(" | "); + + if ($vars['state'] == "down") + { + echo(""); + echo(generate_link("Down",$vars, array('state' => NULL))); + echo(""); + } else { + echo(generate_link("Down",$vars, array('state' => 'down'))); + } + + // End BGP Menu + + if (!isset($vars['view'])) { $vars['view'] = 'details'; } + + echo('
    '); + + if ($vars['view'] == "details") { echo(""); } + echo(generate_link("No Graphs",$vars, array('view' => 'details', 'graph' => 'NULL'))); + if ($vars['view'] == "details") { echo(""); } + + echo(" | "); + + if ($vars['graph'] == "updates") { echo(""); } + echo(generate_link("Updates",$vars, array('view' => 'graphs', 'graph' => 'updates'))); + if ($vars['graph'] == "updates") { echo(""); } + + echo(" | Prefixes: Unicast ("); + if ($vars['graph'] == "prefixes_ipv4unicast") { echo(""); } + echo(generate_link("IPv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast'))); + if ($vars['graph'] == "prefixes_ipv4unicast") { echo(""); } + + echo("|"); + + if ($vars['graph'] == "prefixes_ipv6unicast") { echo(""); } + echo(generate_link("IPv6",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast'))); + if ($vars['graph'] == "prefixes_ipv6unicast") { echo(""); } + + echo("|"); + + if ($vars['graph'] == "prefixes_ipv4vpn") { echo(""); } + echo(generate_link("VPNv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4vpn'))); + if ($vars['graph'] == "prefixes_ipv4vpn") { echo(""); } + echo(")"); + + echo(" | Multicast ("); + if ($vars['graph'] == "prefixes_ipv4multicast") { echo(""); } + echo(generate_link("IPv4",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4multicast'))); + if ($vars['graph'] == "prefixes_ipv4multicast") { echo(""); } + + echo("|"); + + if ($vars['graph'] == "prefixes_ipv6multicast") { echo(""); } + echo(generate_link("IPv6",$vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6multicast'))); + if ($vars['graph'] == "prefixes_ipv6multicast") { echo(""); } + echo(")"); + + echo(" | MAC ("); + if ($vars['graph'] == "macaccounting_bits") { echo(""); } + echo(generate_link("Bits",$vars, array('view' => 'graphs', 'graph' => 'macaccounting_bits'))); + if ($vars['graph'] == "macaccounting_bits") { echo(""); } + + echo("|"); + + if ($vars['graph'] == "macaccounting_pkts") { echo(""); } + echo(generate_link("Packets",$vars, array('view' => 'graphs', 'graph' => 'macaccounting_pkts'))); + if ($vars['graph'] == "macaccounting_pkts") { echo(""); } + echo(")"); + + echo('
    '); + + print_optionbar_end(); + + echo(""); + echo(''); + + if ($vars['type'] == "external") + { + $where = "AND D.bgpLocalAs != B.bgpPeerRemoteAs"; + } elseif ($vars['type'] == "internal") { + $where = "AND D.bgpLocalAs = B.bgpPeerRemoteAs"; + } + + if ($vars['adminstatus'] == "stop") + { + $where .= " AND (B.bgpPeerAdminStatus = 'stop')"; + } elseif ($vars['adminstatus'] == "start") + { + $where .= " AND (B.bgpPeerAdminStatus = 'start' || B.bgpPeerAdminStatus = 'running')"; + } + + if ($vars['state'] == "down") + { + $where .= " AND (B.bgpPeerState != 'established')"; + } + + $peer_query = "select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id ".$where." ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier"; + foreach (dbFetchRows($peer_query) as $peer) + { + unset ($alert, $bg_image); + + if ($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $peer['alert']=1; } + if ($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "gray"; } + if ($peer['bgpPeerAdminStatus'] == "stop") { $peer['alert']=0; $peer['disabled']=1; } + if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; + if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { $peer_type = "Priv eBGP"; } } - if ($vars['type'] == 'all') { - echo ""; + $peerhost = dbFetchRow("SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($peer['bgpPeerIdentifier'])); + + if ($peerhost) { $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); } else { unset($peername); } + + // display overlib graphs + + $graph_type = "bgp_updates"; + $local_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150&&afi=ipv4&safi=unicast"; + if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { + $peer_ip = Net_IPv6::compress($peer['bgpLocalAddr']); + } else { + $peer_ip = $peer['bgpLocalAddr']; + } + $localaddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer_ip . ""; + + $graph_type = "bgp_updates"; + $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=".$config['time']['day']."&to=".$config['time']['now']."&width=500&height=150"; + if (filter_var($peer['bgpPeerIdentifier'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { + $peer_ident = Net_IPv6::compress($peer['bgpPeerIdentifier']); + } else { + $peer_ident = $peer['bgpPeerIdentifier']; } - echo generate_link('All', $vars, array('type' => 'all')); - if ($vars['type'] == 'all') { - echo ''; + $peeraddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer_ident . ""; + + echo('"); + + unset($sep); + foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) + { + $afi = $afisafi['afi']; + $safi = $afisafi['safi']; + $this_afisafi = $afi.$safi; + $peer['afi'] .= $sep . $afi .".".$safi; + $sep = "
    "; + $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer } + unset($sep); - echo ' | '; - - if ($vars['type'] == 'internal') { - echo ""; - } - - echo generate_link('iBGP', $vars, array('type' => 'internal')); - if ($vars['type'] == 'internal') { - echo ''; - } - - echo ' | '; - - if ($vars['type'] == 'external') { - echo ""; - } - - echo generate_link('eBGP', $vars, array('type' => 'external')); - if ($vars['type'] == 'external') { - echo ''; - } - - echo ' | '; - - if ($vars['adminstatus'] == 'stop') { - echo ""; - echo generate_link('Shutdown', $vars, array('adminstatus' => null)); - echo ''; - } - else { - echo generate_link('Shutdown', $vars, array('adminstatus' => 'stop')); - } - - echo ' | '; - - if ($vars['adminstatus'] == 'start') { - echo ""; - echo generate_link('Enabled', $vars, array('adminstatus' => null)); - echo ''; - } - else { - echo generate_link('Enabled', $vars, array('adminstatus' => 'start')); - } - - echo ' | '; - - if ($vars['state'] == 'down') { - echo ""; - echo generate_link('Down', $vars, array('state' => null)); - echo ''; - } - else { - echo generate_link('Down', $vars, array('state' => 'down')); - } - - // End BGP Menu - if (!isset($vars['view'])) { - $vars['view'] = 'details'; - } - - echo '
    '; - - if ($vars['view'] == 'details') { - echo ""; - } - - echo generate_link('No Graphs', $vars, array('view' => 'details', 'graph' => 'NULL')); - if ($vars['view'] == 'details') { - echo ''; - } - - echo ' | '; - - if ($vars['graph'] == 'updates') { - echo ""; - } - - echo generate_link('Updates', $vars, array('view' => 'graphs', 'graph' => 'updates')); - if ($vars['graph'] == 'updates') { - echo ''; - } - - echo ' | Prefixes: Unicast ('; - if ($vars['graph'] == 'prefixes_ipv4unicast') { - echo ""; - } - - echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast')); - if ($vars['graph'] == 'prefixes_ipv4unicast') { - echo ''; - } - - echo '|'; - - if ($vars['graph'] == 'prefixes_ipv6unicast') { - echo ""; - } - - echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast')); - if ($vars['graph'] == 'prefixes_ipv6unicast') { - echo ''; - } - - echo '|'; - - if ($vars['graph'] == 'prefixes_ipv4vpn') { - echo ""; - } - - echo generate_link('VPNv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4vpn')); - if ($vars['graph'] == 'prefixes_ipv4vpn') { - echo ''; - } - - echo ')'; - - echo ' | Multicast ('; - if ($vars['graph'] == 'prefixes_ipv4multicast') { - echo ""; - } - - echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4multicast')); - if ($vars['graph'] == 'prefixes_ipv4multicast') { - echo ''; - } - - echo '|'; - - if ($vars['graph'] == 'prefixes_ipv6multicast') { - echo ""; - } - - echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6multicast')); - if ($vars['graph'] == 'prefixes_ipv6multicast') { - echo ''; - } - - echo ')'; - - echo ' | MAC ('; - if ($vars['graph'] == 'macaccounting_bits') { - echo ""; - } - - echo generate_link('Bits', $vars, array('view' => 'graphs', 'graph' => 'macaccounting_bits')); - if ($vars['graph'] == 'macaccounting_bits') { - echo ''; - } - - echo '|'; - - if ($vars['graph'] == 'macaccounting_pkts') { - echo ""; - } - - echo generate_link('Packets', $vars, array('view' => 'graphs', 'graph' => 'macaccounting_pkts')); - if ($vars['graph'] == 'macaccounting_pkts') { - echo ''; - } - - echo ')'; - - echo '
    '; - - print_optionbar_end(); - - echo "
    Local addressPeer addressTypeFamilyRemote ASStateUptime / Updates
    "; - echo ''; - - if ($vars['type'] == 'external') { - $where = 'AND D.bgpLocalAs != B.bgpPeerRemoteAs'; - } - else if ($vars['type'] == 'internal') { - $where = 'AND D.bgpLocalAs = B.bgpPeerRemoteAs'; - } - - if ($vars['adminstatus'] == 'stop') { - $where .= " AND (B.bgpPeerAdminStatus = 'stop')"; - } - else if ($vars['adminstatus'] == 'start') { - $where .= " AND (B.bgpPeerAdminStatus = 'start' || B.bgpPeerAdminStatus = 'running')"; - } - - if ($vars['state'] == 'down') { - $where .= " AND (B.bgpPeerState != 'established')"; - } - - $peer_query = 'select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id '.$where.' ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier'; - foreach (dbFetchRows($peer_query) as $peer) { - unset($alert, $bg_image); - - if ($peer['bgpPeerState'] == 'established') { - $col = 'green'; - } - else { - $col = 'red'; - $peer['alert'] = 1; - } - - if ($peer['bgpPeerAdminStatus'] == 'start' || $peer['bgpPeerAdminStatus'] == 'running') { - $admin_col = 'green'; - } - else { - $admin_col = 'gray'; - } - - if ($peer['bgpPeerAdminStatus'] == 'stop') { - $peer['alert'] = 0; - $peer['disabled'] = 1; - } - - if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { - $peer_type = "iBGP"; - } - else { - $peer_type = "eBGP"; - if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { - $peer_type = "Priv eBGP"; - } - } - - $peerhost = dbFetchRow('SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($peer['bgpPeerIdentifier'])); - - if ($peerhost) { - $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); - } - else { - unset($peername); - } - - // display overlib graphs - $graph_type = 'bgp_updates'; - $local_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150&&afi=ipv4&safi=unicast'; - if (filter_var($peer['bgpLocalAddr'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { - $peer_ip = Net_IPv6::compress($peer['bgpLocalAddr']); - } - else { - $peer_ip = $peer['bgpLocalAddr']; - } - - $localaddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer_ip.''; - - $graph_type = 'bgp_updates'; - $peer_daily_url = 'graph.php?id='.$peer['bgpPeer_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=500&height=150'; - if (filter_var($peer['bgpPeerIdentifier'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { - $peer_ident = Net_IPv6::compress($peer['bgpPeerIdentifier']); - } - else { - $peer_ident = $peer['bgpPeerIdentifier']; - } - - $peeraddresslink = "', LEFT".$config['overlib_defaults'].');" onmouseout="return nd();">'.$peer_ident.''; - - echo ''; - - unset($sep); - foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { - $afi = $afisafi['afi']; - $safi = $afisafi['safi']; - $this_afisafi = $afi.$safi; - $peer['afi'] .= $sep.$afi.'.'.$safi; - $sep = '
    '; - $peer['afisafi'][$this_afisafi] = 1; - // Build a list of valid AFI/SAFI for this peer - } - - unset($sep); - - echo ' - + echo(" + - + - - - - '; + + + + "); - unset($invalid); - switch ($vars['graph']) { - case 'prefixes_ipv4unicast': - case 'prefixes_ipv4multicast': - case 'prefixes_ipv4vpn': - case 'prefixes_ipv6unicast': - case 'prefixes_ipv6multicast': - list(,$afisafi) = explode('_', $vars['graph']); - if (isset($peer['afisafi'][$afisafi])) { - $peer['graph'] = 1; - } + unset($invalid); + switch ($vars['graph']) + { + case 'prefixes_ipv4unicast': + case 'prefixes_ipv4multicast': + case 'prefixes_ipv4vpn': + case 'prefixes_ipv6unicast': + case 'prefixes_ipv6multicast': + list(,$afisafi) = explode("_", $vars['graph']); + if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } + case 'updates': + $graph_array['type'] = "bgp_" . $vars['graph']; + $graph_array['id'] = $peer['bgpPeer_id']; + } - case 'updates': - $graph_array['type'] = 'bgp_'.$vars['graph']; - $graph_array['id'] = $peer['bgpPeer_id']; + switch ($vars['graph']) + { + case 'macaccounting_bits': + case 'macaccounting_pkts': + $acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier'])); + $database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"; + if (is_array($acc) && is_file($database)) + { + $peer['graph'] = 1; + $graph_array['id'] = $acc['ma_id']; + $graph_array['type'] = $vars['graph']; } + } - switch ($vars['graph']) { - case 'macaccounting_bits': - case 'macaccounting_pkts': - $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', array($peer['bgpPeerIdentifier'])); - $database = $config['rrd_dir'].'/'.$device['hostname'].'/cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'; - if (is_array($acc) && is_file($database)) { - $peer['graph'] = 1; - $graph_array['id'] = $acc['ma_id']; - $graph_array['type'] = $vars['graph']; - } - } + if ($vars['graph'] == 'updates') { $peer['graph'] = 1; } - if ($vars['graph'] == 'updates') { - $peer['graph'] = 1; - } + if ($peer['graph']) + { + $graph_array['height'] = "100"; + $graph_array['width'] = "218"; + $graph_array['to'] = $config['time']['now']; + echo('"); + } + } - echo ''; - } - }//end foreach + echo("
    Local addressPeer addressTypeFamilyRemote ASStateUptime / Updates
    '.$localaddresslink.'
    '.generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')).'
    " . $localaddresslink . "
    ".generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp'))."
    »'.$peeraddresslink."" . $peeraddresslink . " $peer_type".$peer['afi'].'AS'.$peer['bgpPeerRemoteAs'].'
    '.$peer['astext']."
    ".$peer['bgpPeerAdminStatus']."
    ".$peer['bgpPeerState'].'
    '.formatUptime($peer['bgpPeerFsmEstablishedTime'])."
    - Updates ".format_si($peer['bgpPeerInUpdates'])." - ".format_si($peer['bgpPeerOutUpdates']).'
    ".$peer['afi']."AS" . $peer['bgpPeerRemoteAs'] . "
    " . $peer['astext'] . "
    " . $peer['bgpPeerAdminStatus'] . "
    " . $peer['bgpPeerState'] . "
    " .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
    + Updates " . format_si($peer['bgpPeerInUpdates']) . " + " . format_si($peer['bgpPeerOutUpdates']) . "
    '); - if ($peer['graph']) { - $graph_array['height'] = '100'; - $graph_array['width'] = '218'; - $graph_array['to'] = $config['time']['now']; - echo '
    '; + include("includes/print-graphrow.inc.php"); - include 'includes/print-graphrow.inc.php'; + echo("
    "); +} - echo ''; -}//end if diff --git a/html/pages/routing/overview.inc.php b/html/pages/routing/overview.inc.php index c16262143a..bd9a9e63e1 100644 --- a/html/pages/routing/overview.inc.php +++ b/html/pages/routing/overview.inc.php @@ -1,7 +1,7 @@ 'IPv4 Address', - 'ipv6' => 'IPv6 Address', - 'mac' => 'MAC Address', - 'arp' => 'ARP Table', -); +$sections = array('ipv4' => 'IPv4 Address', 'ipv6' => 'IPv6 Address', 'mac' => 'MAC Address', 'arp' => 'ARP Table'); -if (dbFetchCell('SELECT 1 from `packages` LIMIT 1')) { - $sections['packages'] = 'Packages'; +if( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) { + $sections['packages'] = 'Packages'; } -if (!isset($vars['search'])) { - $vars['search'] = 'ipv4'; -} +if (!isset($vars['search'])) { $vars['search'] = "ipv4"; } print_optionbar_start('', ''); -echo 'Search » '; + echo('Search » '); unset($sep); -foreach ($sections as $type => $texttype) { - echo $sep; - if ($vars['search'] == $type) { - echo ""; - } +foreach ($sections as $type => $texttype) +{ + echo($sep); + if ($vars['search'] == $type) + { + echo(""); + } - // echo('' . $texttype .''); - echo generate_link($texttype, array('page' => 'search', 'search' => $type)); +# echo('' . $texttype .''); + echo(generate_link($texttype, array('page'=>'search','search'=>$type))); - if ($vars['search'] == $type) { - echo ''; - } + if ($vars['search'] == $type) { echo(""); } - $sep = ' | '; + $sep = ' | '; } - -unset($sep); +unset ($sep); print_optionbar_end('', ''); -if (file_exists('pages/search/'.$vars['search'].'.inc.php')) { - include 'pages/search/'.$vars['search'].'.inc.php'; -} -else { - echo report_this('Unknown search type '.$vars['search']); +if( file_exists('pages/search/'.$vars['search'].'.inc.php') ) { + include('pages/search/'.$vars['search'].'.inc.php'); +} else { + echo(report_this('Unknown search type '.$vars['search'])); } + +?> diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index 45cd6888a9..a4dcbd1136 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -30,22 +30,21 @@ var grid = $("#arp-search").bootgrid({ '.$data['hostname'].'"+'; + echo('">'.$data['hostname'].'"+'); } ?> ""+ @@ -54,16 +53,18 @@ foreach (dbFetchRows($sql, $param) as $data) { " "\" class=\"form-control input-sm\" placeholder=\"Address\" />"+ diff --git a/html/pages/search/ipv4.inc.php b/html/pages/search/ipv4.inc.php index 843acbd1bc..e2ea785c07 100644 --- a/html/pages/search/ipv4.inc.php +++ b/html/pages/search/ipv4.inc.php @@ -27,23 +27,22 @@ var grid = $("#ipv4-search").bootgrid({ ""+ '.$data['hostname'].'"+'; + echo('">'.$data['hostname'].'"+'); } ?> ""+ @@ -53,16 +52,18 @@ foreach (dbFetchRows($sql, $param) as $data) { ""+ ""+ "
     "+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ "
     "+ ""+ "
    "+ diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php index 2b9115013d..8ab58d9fff 100644 --- a/html/pages/search/ipv6.inc.php +++ b/html/pages/search/ipv6.inc.php @@ -26,23 +26,22 @@ var grid = $("#ipv6-search").bootgrid({ ""+ '.$data['hostname'].'"+'; + echo('">'.$data['hostname'].'"+'); } ?> ""+ @@ -52,8 +51,9 @@ foreach (dbFetchRows($sql, $param) as $data) { ""+ ""+ "
    "+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ "
    "+ ""+ "
    "+ diff --git a/html/pages/search/mac.inc.php b/html/pages/search/mac.inc.php index f606e4436a..c040a1e16a 100644 --- a/html/pages/search/mac.inc.php +++ b/html/pages/search/mac.inc.php @@ -26,22 +26,21 @@ var grid = $("#mac-search").bootgrid({ ""+ @@ -51,15 +50,17 @@ foreach (dbFetchRows($sql, $param) as $data) { ""+ ""+ "
    '-1', 'rule' => '%macros.device_down = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Devices up/down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%devices.uptime < "300" && %macros.device = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Device rebooted'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerState != "established" && %macros.device_up = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'BGP Session establised'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%macros.port_down = "1"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"1","delay":"300"}', 'disabled' => 0, 'name' => 'Port status up/down'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%macros.port_usage_perc >= "80"', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Port utilisation over threshold'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor over limit'); - $default_rules[] = array('device_id' => '-1', 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', 'severity' => 'critical', 'extra' => '{"mute":false,"count":"-1","delay":"300"}', 'disabled' => 0, 'name' => 'Sensor under limit'); - foreach( $default_rules as $add_rule ) { - dbInsert($add_rule,'alert_rules'); +if (isset($_POST['create-default'])) { + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%macros.device_down = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Devices up/down', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%devices.uptime < "300" && %macros.device = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Device rebooted', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%bgpPeers.bgpPeerState != "established" && %macros.device_up = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'BGP Session down', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%bgpPeers.bgpPeerFsmEstablishedTime < "300" && %bgpPeers.bgpPeerState = "established"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'BGP Session establised', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%macros.port_down = "1"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Port status up/down', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%macros.port_usage_perc >= "80"', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Port utilisation over threshold', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%sensors.sensor_current > %sensors.sensor_limit', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Sensor over limit', + ); + $default_rules[] = array( + 'device_id' => '-1', + 'rule' => '%sensors.sensor_current < %sensors.sensor_limit_low', + 'severity' => 'critical', + 'extra' => '{"mute":false,"count":"-1","delay":"300"}', + 'disabled' => 0, + 'name' => 'Sensor under limit', + ); + foreach ($default_rules as $add_rule) { + dbInsert($add_rule, 'alert_rules'); } -} - -require_once('includes/modal/new_alert_rule.inc.php'); -require_once('includes/modal/delete_alert_rule.inc.php'); +}//end if +require_once 'includes/modal/new_alert_rule.inc.php'; +require_once 'includes/modal/delete_alert_rule.inc.php'; ?>
    0) { +if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) { $results = $_POST['results']; -} else { +} +else { $results = 50; } echo '
    - - +
    + @@ -49,126 +103,150 @@ echo '
    - '; + '; -echo (' - + '); -$rulei=1; -$count_query = "SELECT COUNT(id)"; -$full_query = "SELECT *"; -$sql = ''; -$param = array(); -if(isset($device['device_id']) && $device['device_id'] > 0) { - $sql = 'WHERE (device_id=? OR device_id="-1")'; +echo ''; + +$rulei = 1; +$count_query = 'SELECT COUNT(id)'; +$full_query = 'SELECT *'; +$sql = ''; +$param = array(); +if (isset($device['device_id']) && $device['device_id'] > 0) { + $sql = 'WHERE (device_id=? OR device_id="-1")'; $param = array($device['device_id']); } -$query = " FROM alert_rules $sql ORDER BY device_id,id"; -$count_query = $count_query . $query; -$count = dbFetchCell($count_query,$param); -if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { + +$query = " FROM alert_rules $sql ORDER BY device_id,id"; +$count_query = $count_query.$query; +$count = dbFetchCell($count_query, $param); +if (!isset($_POST['page_number']) && $_POST['page_number'] < 1) { $page_number = 1; -} else { +} +else { $page_number = $_POST['page_number']; } -$start = ($page_number - 1) * $results; -$full_query = $full_query . $query . " LIMIT $start,$results"; -foreach( dbFetchRows($full_query, $param) as $rule ) { - $sub = dbFetchRows("SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'])); - $ico = "ok"; - $col = "success"; - $extra = ""; - if( sizeof($sub) == 1 ) { - $sub = $sub[0]; - if( (int) $sub['state'] === 0 ) { - $ico = "ok"; - $col = "success"; - } elseif( (int) $sub['state'] === 1 ) { - $ico = "remove"; - $col = "danger"; - $extra = "danger"; - } elseif( (int) $sub['state'] === 2 ) { - $ico = "time"; - $col = "default"; - $extra = "warning"; - } - } - $alert_checked = ''; - $orig_ico = $ico; - $orig_col = $col; - $orig_class = $extra; - if( $rule['disabled'] ) { - $ico = "pause"; - $col = ""; - $extra = "active"; - } else { - $alert_checked = 'checked'; +$start = (($page_number - 1) * $results); +$full_query = $full_query.$query." LIMIT $start,$results"; + +foreach (dbFetchRows($full_query, $param) as $rule) { + $sub = dbFetchRows('SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1', array($rule['id'])); + $ico = 'ok'; + $col = 'success'; + $extra = ''; + if (sizeof($sub) == 1) { + $sub = $sub[0]; + if ((int) $sub['state'] === 0) { + $ico = 'ok'; + $col = 'success'; } - $rule_extra = json_decode($rule['extra'],TRUE); - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + else if ((int) $sub['state'] === 2) { + $ico = 'time'; + $col = 'default'; + $extra = 'warning'; } - echo ""; - echo ""; - echo ""; - echo "\r\n"; + } + + $alert_checked = ''; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; + if ($rule['disabled']) { + $ico = 'pause'; + $col = ''; + $extra = 'active'; + } + else { + $alert_checked = 'checked'; + } + + $rule_extra = json_decode($rule['extra'], true); + echo ""; + echo ''; + echo ''; + echo "'; + echo ''; + echo ""; + } + + echo ''; + echo ''; + echo ''; + echo "\r\n"; +}//end foreach + +if (($count % $results) > 0) { + echo ' + + '; } -if($count % $results > 0) { - echo(' - - '); -} echo '
    # Name RuleExtra Enabled Action
    '); +echo ''; if ($_SESSION['userlevel'] >= '10') { - echo(''); + echo ''; } -echo ('
    #".((int) $rulei++)."".$rule['name'].""; - if($rule_extra['invert'] === true) { - echo "Inverted "; + else if ((int) $sub['state'] === 1) { + $ico = 'remove'; + $col = 'danger'; + $extra = 'danger'; } - echo "".htmlentities($rule['rule'])."".$rule['severity']." "; - if($rule_extra['mute'] === true) { - echo "Max: ".$rule_extra['count']."
    Delay: ".$rule_extra['delay']."
    Interval: ".$rule_extra['interval']."
    "; - if ($_SESSION['userlevel'] >= '10') { - echo ""; - } - echo ""; - if ($_SESSION['userlevel'] >= '10') { - echo " "; - echo ""; - } - echo "
    #'.((int) $rulei++).''.$rule['name'].'"; + if ($rule_extra['invert'] === true) { + echo 'Inverted '; + } + + echo ''.htmlentities($rule['rule']).''.$rule['severity'].' "; + if ($rule_extra['mute'] === true) { + echo "Max: '.$rule_extra['count'].'
    Delay: '.$rule_extra['delay'].'
    Interval: '.$rule_extra['interval'].'
    '; + if ($_SESSION['userlevel'] >= '10') { + echo ""; + } + + echo ''; + if ($_SESSION['userlevel'] >= '10') { + echo " "; + echo ""; + } + + echo '
    '.generate_pagination($count, $results, $page_number).'
    '. generate_pagination($count,$results,$page_number) .'
    - - - -
    '; + + + +
    '; -if($count < 1) { +if ($count < 1) { if ($_SESSION['userlevel'] >= '10') { echo '
    -
    -
    -

    - -

    -
    -
    -
    '; +
    +
    +

    + +

    +
    +
    +
    '; } } @@ -180,19 +258,19 @@ $('#ack-alert').click('', function(e) { var alert_id = $(this).data("alert_id"); $.ajax({ type: "POST", - url: "/ajax_form.php", - data: { type: "ack-alert", alert_id: alert_id }, - success: function(msg){ - $("#message").html('
    '+msg+'
    '); - if(msg.indexOf("ERROR:") <= -1) { - setTimeout(function() { - location.reload(1); - }, 1000); - } - }, - error: function(){ - $("#message").html('
    An error occurred acking this alert.
    '); - } + url: "/ajax_form.php", + data: { type: "ack-alert", alert_id: alert_id }, + success: function(msg){ + $("#message").html('
    '+msg+'
    '); + if(msg.indexOf("ERROR:") <= -1) { + setTimeout(function() { + location.reload(1); + }, 1000); + } + }, + error: function(){ + $("#message").html('
    An error occurred acking this alert.
    '); + } }); }); @@ -206,42 +284,42 @@ $('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event var orig_class = $(this).data("orig_class"); $.ajax({ type: 'POST', - url: '/ajax_form.php', - data: { type: "update-alert-rule", alert_id: alert_id, state: state }, - dataType: "html", - success: function(msg) { - if(msg.indexOf("ERROR:") <= -1) { - if(state) { - $('#alert-rule-'+alert_id).removeClass('glyphicon-pause'); - $('#alert-rule-'+alert_id).addClass('glyphicon-'+orig_state); - $('#alert-rule-'+alert_id).removeClass('text-default'); - $('#alert-rule-'+alert_id).addClass('text-'+orig_colour); - $('#row_'+alert_id).removeClass('active'); - $('#row_'+alert_id).addClass(orig_class); + url: '/ajax_form.php', + data: { type: "update-alert-rule", alert_id: alert_id, state: state }, + dataType: "html", + success: function(msg) { + if(msg.indexOf("ERROR:") <= -1) { + if(state) { + $('#alert-rule-'+alert_id).removeClass('glyphicon-pause'); + $('#alert-rule-'+alert_id).addClass('glyphicon-'+orig_state); + $('#alert-rule-'+alert_id).removeClass('text-default'); + $('#alert-rule-'+alert_id).addClass('text-'+orig_colour); + $('#row_'+alert_id).removeClass('active'); + $('#row_'+alert_id).addClass(orig_class); + } else { + $('#alert-rule-'+alert_id).removeClass('glyphicon-'+orig_state); + $('#alert-rule-'+alert_id).addClass('glyphicon-pause'); + $('#alert-rule-'+alert_id).removeClass('text-'+orig_colour); + $('#alert-rule-'+alert_id).addClass('text-default'); + $('#row_'+alert_id).removeClass('warning'); + $('#row_'+alert_id).addClass('active'); + } } else { - $('#alert-rule-'+alert_id).removeClass('glyphicon-'+orig_state); - $('#alert-rule-'+alert_id).addClass('glyphicon-pause'); - $('#alert-rule-'+alert_id).removeClass('text-'+orig_colour); - $('#alert-rule-'+alert_id).addClass('text-default'); - $('#row_'+alert_id).removeClass('warning'); - $('#row_'+alert_id).addClass('active'); + $("#message").html('
    '+msg+'
    '); + $('#'+alert_id).bootstrapSwitch('toggleState',true ); + } + }, + error: function() { + $("#message").html('
    This alert could not be updated.
    '); + $('#'+alert_id).bootstrapSwitch('toggleState',true ); } - } else { - $("#message").html('
    '+msg+'
    '); - $('#'+alert_id).bootstrapSwitch('toggleState',true ); - } - }, - error: function() { - $("#message").html('
    This alert could not be updated.
    '); - $('#'+alert_id).bootstrapSwitch('toggleState',true ); - } }); }); function updateResults(results) { - $('#results_amount').val(results.value); - $('#page_number').val(1); - $('#result_form').submit(); + $('#results_amount').val(results.value); + $('#page_number').val(1); + $('#result_form').submit(); } function changePage(page,e) { diff --git a/html/includes/print-alert-templates.php b/html/includes/print-alert-templates.php index 16a3afdd08..8ad6e8265d 100644 --- a/html/includes/print-alert-templates.php +++ b/html/includes/print-alert-templates.php @@ -1,6 +1,6 @@ @@ -10,17 +10,17 @@ $no_refresh = TRUE;