diff --git a/AUTHORS.md b/AUTHORS.md index ce1ce2b57..5150a6d0d 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -38,6 +38,7 @@ Contributors to LibreNMS: - Tony Ditchfield (arnoldthebat) - Travis Hegner (travishegner) - Will Jones (willjones) +- Job Snijders (job) [1]: http://observium.org/ "Observium web site" diff --git a/addhost.php b/addhost.php index d1e26a399..f0719cc5e 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 4de2208be..f1e591415 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 c419ebaeb..8fd4e5361 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 6895083fb..e89e65675 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 f3b04f67c..8f631c365 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 1b0e138fb..bc4517f41 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/check-errors.php b/check-errors.php index 9290425ef..702004f91 100755 --- a/check-errors.php +++ b/check-errors.php @@ -10,51 +10,50 @@ * @subpackage alerts * @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("html/includes/functions.inc.php"); +require 'includes/defaults.inc.php'; +require 'config.php'; +require 'includes/definitions.inc.php'; +require 'includes/functions.php'; +require 'html/includes/functions.inc.php'; // Check all of our interface RRD files for errors +if ($argv[1]) { + $where = 'AND `port_id` = ?'; + $params = array($argv[1]); +} -if ($argv[1]) { $where = "AND `port_id` = ?"; $params = array($argv[1]); } - -$i = 0; +$i = 0; $errored = 0; -foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where", $params) as $interface) -{ - $errors = $interface['ifInErrors_delta'] + $interface['ifOutErrors_delta']; - if ($errors > '1') - { - $errored[] = generate_device_link($interface, $interface['hostname'] . " - " . $interface['ifDescr'] . " - " . $interface['ifAlias'] . " - " . $interface['ifInErrors_delta'] . " - " . $interface['ifOutErrors_delta']); - $errored++; - } - $i++; -} +foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where", $params) as $interface) { + $errors = ($interface['ifInErrors_delta'] + $interface['ifOutErrors_delta']); + if ($errors > '1') { + $errored[] = generate_device_link($interface, $interface['hostname'].' - '.$interface['ifDescr'].' - '.$interface['ifAlias'].' - '.$interface['ifInErrors_delta'].' - '.$interface['ifOutErrors_delta']); + $errored++; + } -echo("Checked $i interfaces\n"); - -if (is_array($errored)) -{ // If there are errored ports - $i = 0; - $msg = "Interfaces with errors : \n\n"; - - foreach ($errored as $int) - { - $msg .= "$int\n"; // Add a line to the report email warning about them $i++; - } - // Send the alert email - notify($device, $config['project_name'] . " detected errors on $i interface" . ($i != 1 ? 's' : ''), $msg); } -echo("$errored interfaces with errors over the past 5 minutes.\n"); +echo "Checked $i interfaces\n"; -?> +if (is_array($errored)) { + // If there are errored ports + $i = 0; + $msg = "Interfaces with errors : \n\n"; + + foreach ($errored as $int) { + $msg .= "$int\n"; + // Add a line to the report email warning about them + $i++; + } + + // Send the alert email + notify($device, $config['project_name']." detected errors on $i interface".($i != 1 ? 's' : ''), $msg); +} + +echo "$errored interfaces with errors over the past 5 minutes.\n"; diff --git a/check-services.php b/check-services.php index 2f6f33ab6..6cbba11ec 100755 --- a/check-services.php +++ b/check-services.php @@ -1,7 +1,7 @@ #!/usr/bin/env php * @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'; -foreach (dbFetchRows("SELECT * FROM `devices` AS D, `services` AS S WHERE S.device_id = D.device_id ORDER by D.device_id DESC") as $service) -{ - if ($service['status'] = "1") - { - unset($check, $service_status, $time, $status); - $service_status = $service['service_status']; - $service_type = strtolower($service['service_type']); - $service_param = $service['service_param']; - $checker_script = $config['install_dir'] . "/includes/services/" . $service_type . "/check.inc"; +foreach (dbFetchRows('SELECT * FROM `devices` AS D, `services` AS S WHERE S.device_id = D.device_id ORDER by D.device_id DESC') as $service) { + if ($service['status'] = '1') { + unset($check, $service_status, $time, $status); + $service_status = $service['service_status']; + $service_type = strtolower($service['service_type']); + $service_param = $service['service_param']; + $checker_script = $config['install_dir'].'/includes/services/'.$service_type.'/check.inc'; - if (is_file($checker_script)) - { - include($checker_script); + if (is_file($checker_script)) { + include $checker_script; + } + else { + $status = '2'; + $check = "Error : Script not found ($checker_script)"; + } + + $update = array(); + + if ($service_status != $status) { + $update['service_changed'] = time(); + + if ($service['sysContact']) { + $email = $service['sysContact']; + } + else { + $email = $config['email_default']; + } + + if ($status == '1') { + $msg = 'Service Up: '.$service['service_type'].' on '.$service['hostname']; + notify($device, 'Service Up: '.$service['service_type'].' on '.$service['hostname'], $msg); + } + else if ($status == '0') { + $msg = 'Service Down: '.$service['service_type'].' on '.$service['hostname']; + notify($device, 'Service Down: '.$service['service_type'].' on '.$service['hostname'], $msg); + } + } + else { + unset($updated); + } + + $update = array_merge(array('service_status' => $status, 'service_message' => $check, 'service_checked' => time()), $update); + dbUpdate($update, 'services', '`service_id` = ?', array($service['service_id'])); + unset($update); } - else - { - $status = "2"; - $check = "Error : Script not found ($checker_script)"; + else { + $status = '0'; + }//end if + + $rrd = $config['rrd_dir'].'/'.$service['hostname'].'/'.safename('service-'.$service['service_type'].'-'.$service['service_id'].'.rrd'); + + if (!is_file($rrd)) { + rrdtool_create($rrd, 'DS:status:GAUGE:600:0:1 '.$config['rrd_rra']); } - $update = array(); - - if ($service_status != $status) - { - $update['service_changed'] = time(); - - if ($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; } - if ($status == "1") - { - $msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname']; - notify($device, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg); - } - elseif ($status == "0") - { - $msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname']; - notify($device, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg); - } - } else { unset($updated); } - - $update = array_merge(array('service_status' => $status, 'service_message' => $check, 'service_checked' => time()), $update); - dbUpdate($update, 'services', '`service_id` = ?', array($service['service_id'])); - unset($update); - - } else { - $status = "0"; - } - - $rrd = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename("service-" . $service['service_type'] . "-" . $service['service_id'] . ".rrd"); - - if (!is_file($rrd)) - { - rrdtool_create ($rrd, "DS:status:GAUGE:600:0:1 ".$config['rrd_rra']); - } - if ($status == "1" || $status == "0") - { - rrdtool_update($rrd,"N:".$status); - } else { - rrdtool_update($rrd,"N:U"); - } - -} # while - -?> + if ($status == '1' || $status == '0') { + rrdtool_update($rrd, 'N:'.$status); + } + else { + rrdtool_update($rrd, 'N:U'); + } +} //end foreach diff --git a/config_to_json.php b/config_to_json.php index ae4a32d82..45e3394bc 100644 --- a/config_to_json.php +++ b/config_to_json.php @@ -1,33 +1,30 @@ - -*/ + * Configuration to JSON converter + * Written by Job Snijders + * + */ $defaults_file = 'includes/defaults.inc.php'; -$config_file = 'config.php'; +$config_file = 'config.php'; // move to install dir chdir(dirname($argv[0])); function iscli() { - - if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { - return true; - } else { - return false; - } + if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { + return true; + } + else { + return false; + } + } // check if we are running throw the CLI, otherwise abort - -if ( iscli() ) { - - require_once($defaults_file); - require_once($config_file); - print(json_encode($config)); +if (iscli()) { + include_once $defaults_file; + include_once $config_file; + print (json_encode($config)); } - -?> diff --git a/contrib/generate-iplist.php b/contrib/generate-iplist.php index fd5e10048..cfb5bd62b 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/cronic b/cronic new file mode 100755 index 000000000..8536f29a3 --- /dev/null +++ b/cronic @@ -0,0 +1,48 @@ +#!/bin/bash + +# Cronic v2 - cron job report wrapper +# Copyright 2007 Chuck Houpt. No rights reserved, whatsoever. +# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/ + +set -eu + +OUT=/tmp/cronic.out.$$ +ERR=/tmp/cronic.err.$$ +TRACE=/tmp/cronic.trace.$$ + +set +e +"$@" >$OUT 2>$TRACE +RESULT=$? +set -e + +PATTERN="^${PS4:0:1}\\+${PS4:1}" +if grep -aq "$PATTERN" $TRACE +then + ! grep -av "$PATTERN" $TRACE > $ERR +else + ERR=$TRACE +fi + +if [ $RESULT -ne 0 -o -s "$ERR" ] + then + echo "Cronic detected failure or error output for the command:" + echo "$@" + echo + echo "RESULT CODE: $RESULT" + echo + echo "ERROR OUTPUT:" + cat "$ERR" + echo + echo "STANDARD OUTPUT:" + cat "$OUT" + if [ $TRACE != $ERR ] + then + echo + echo "TRACE-ERROR OUTPUT:" + cat "$TRACE" + fi +fi + +rm -f "$OUT" +rm -f "$ERR" +rm -f "$TRACE" diff --git a/daily.php b/daily.php index abb525a0b..0b20ebf5f 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 189881778..38ea772ad 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 37f75db4a..336f91ad0 100755 --- a/discovery.php +++ b/discovery.php @@ -10,130 +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(?)"; - $params = array($config['distributed_poller_group']); -} -foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC",$params) 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 81e711694..e3f016af4 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/doc/Developing/Code-Guidelines.md b/doc/Developing/Code-Guidelines.md index 4d661662b..bb1837818 100644 --- a/doc/Developing/Code-Guidelines.md +++ b/doc/Developing/Code-Guidelines.md @@ -37,6 +37,21 @@ if ($foo == 5) { } ``` +Start else and elsif on new lines, e.g. +```php +if ($foo == 5) { + echo 'foo is 5'; +} +elsif ($foo == 4) { + echo 'foo is 4'; +} +else { + echo 'foo is something else'; +} +``` +This makes diffs much cleaner when moving around blocks of code. + + ### Including files Using parenthesis around file includes isn't required, instead just place the file in between '' ```php diff --git a/doc/General/MIB-based-polling.md b/doc/General/MIB-based-polling.md index e66461601..5b390387b 100644 --- a/doc/General/MIB-based-polling.md +++ b/doc/General/MIB-based-polling.md @@ -3,7 +3,7 @@ MIB-based polling is experimental. It might overload your LibreNMS server, destroy your data, set your routers on fire, and kick your cat. It has been tested against a very limited set of devices (namely Ruckus ZD1000 wireless -controllers, and Net-SNMP on Linux). It may fail badly on other hardware. +controllers, and `net-snmp` on Linux). It may fail badly on other hardware. The approach taken is fairly basic and I claim no special expertise in understanding MIBs. Most of my understanding of SNMP comes from reading @@ -18,7 +18,7 @@ Paul Gear MIB-based polling is disabled by default; you must set `$config['poller_modules']['mib'] = 1;` -in config.php to enable it. +in `config.php` to enable it. The components involved in of MIB-based support are: @@ -41,7 +41,7 @@ The components involved in of MIB-based support are: - updates/adds graph definitions in the previously-unused graph_types database table - Individual OSes (`includes/polling/os/*.inc.php`) can poll extra MIBs - for a given OS by calling poll_mib(). At the moment, this actually + for a given OS by calling `poll_mib()`. At the moment, this actually happens before the general MIB polling. - Devices may be excluded from MIB polling by changing the setting in the device edit screen (`/device/device=ID/tab=edit/section=modules/`) @@ -73,17 +73,16 @@ gather the data you want. 3. Check that `snmptranslate -Td -On -M mibs -m MODULE MODULE::mibName` produces a parsed description of the OID values. An example can be found in the comments for `snmp_mib_parse()` in `includes/snmp.inc.php`. - 4. Get the `sysObjectID` from a device, for example:``` -snmpget -v2c -c public -OUsb -m SNMPv2-MIB -M /opt/librenms/mibs -t 30 hostname sysObjectID.0 -``` + 4. Get the `sysObjectID` from a device, for example: + ```snmpget -v2c -c public -OUsb -m SNMPv2-MIB -M /opt/librenms/mibs -t 30 hostname sysObjectID.0``` 5. Ensure `snmptranslate -m all -M /opt/librenms/mibs OID 2>/dev/null` (where OID is the value returned for sysObjectID above) results in a valid name for the MIB. See the comments for `snmp_translate()` in `includes/snmp.inc.php` for an example. If this step fails, it means - there is something wrong with the MIB and net-snmp cannot parse it. + there is something wrong with the MIB and `net-snmp` cannot parse it. 6. Add any additional MIBs you wish to poll for specific device types to `includes/polling/os/OSNAME.inc.php` by calling `poll_mibs()` with the - MIB module and name. See includes/polling/os/ruckuswireless.inc.php for + MIB module and name. See `includes/polling/os/ruckuswireless.inc.php` for an example. 7. That should be all you need to see MIB graphs! @@ -99,4 +98,3 @@ snmpget -v2c -c public -OUsb -m SNMPv2-MIB -M /opt/librenms/mibs -t 30 hostname - Combine multiple MIB values into graphs automatically on a predefined or user-defined basis. - Include MIB types in stats submissions. - diff --git a/doc/Installation/Installation-(RHEL-CentOS).md b/doc/Installation/Installation-(RHEL-CentOS).md index 42f277f18..5968dacbb 100644 --- a/doc/Installation/Installation-(RHEL-CentOS).md +++ b/doc/Installation/Installation-(RHEL-CentOS).md @@ -7,8 +7,8 @@ NOTE: These instructions assume you are the root user. If you are not, prepend yum install net-snmp mysql-server service snmpd start service mysqld start - chkconfig --levels 235 mysqld on - chkconfig --levels 235 snmpd on + chkconfig mysqld on + chkconfig snmpd on mysql_secure_installation mysql -uroot -p @@ -46,7 +46,7 @@ Install necessary software. The packages listed below are an all-inclusive list Note if not using HTTPd (Apache): RHEL requires `httpd` to be installed regardless of of `nginx`'s (or any other web-server's) presence. - rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm + yum install epel-release yum install php php-cli php-gd php-mysql php-snmp php-pear php-curl httpd net-snmp graphviz graphviz-php mysql ImageMagick jwhois nmap mtr rrdtool MySQL-python net-snmp-utils vixie-cron php-mcrypt fping git pear install Net_IPv4-1.3.4 pear install Net_IPv6-1.2.2b2 @@ -87,8 +87,8 @@ If the file `/etc/httpd/conf.d/welcome.conf` exists, you might want to remove th Install necessary extra software and let it start on system boot. yum install nginx php-fpm - chkconfig --levels 235 nginx on - chkconfig --levels 235 php-fpm on + chkconfig nginx on + chkconfig php-fpm on Modify permissions and configuration for `php-fpm` to use nginx credentials. diff --git a/html/ajax_form.php b/html/ajax_form.php index b269a1935..a9547d352 100644 --- a/html/ajax_form.php +++ b/html/ajax_form.php @@ -13,32 +13,28 @@ */ // 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 0f7b4469c..0ebab67b1 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 7312e7393..159d4630c 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 410aac111..d9c961054 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 dc5af2c6e..3684681a4 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 81b81f11a..412680e43 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 031a03fd5..9f5d9df3e 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 7bc995daf..b7d9c6200 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/css/styles.css b/html/css/styles.css index 94697ff52..69ae991a8 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; } diff --git a/html/csv.php b/html/csv.php index 1f9dee0ca..19203237d 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 ce08fd677..b55d09c32 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 6f45a3d6c..a993066e5 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 873aabc12..351825fb7 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 5838e9ae3..0dc3ff58c 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 5278fcf52..efa97f01e 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 22f65e71d..7e934b22d 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 e44f6afdc..73ebfa5a2 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 9ba795786..bb8c12559 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 46def6626..8e35c10cc 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 a3f021bfd..1d3ae7e77 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 94c410c9e..ef82a1639 100644 --- a/html/forms/create-device-group.inc.php +++ b/html/forms/create-device-group.inc.php @@ -12,41 +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); - $pattern = rtrim($pattern,'&&'); - $pattern = rtrim($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 52670ac8a..28062d02f 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 1275ea6a7..1719939c3 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 f77c5dc2b..5c3e15744 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 14ebd6c5b..c700a351a 100644 --- a/html/forms/delete-alert-template.inc.php +++ b/html/forms/delete-alert-template.inc.php @@ -12,20 +12,21 @@ * 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 05e7ce787..d22874750 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 df5a60dab..61a0a28b6 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 393b1dc68..075de355b 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 191535b4b..aa3120424 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 a04104a8f..31dc3c714 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 9ecd4e52e..146b8fde1 100644 --- a/html/forms/parse-device-group.inc.php +++ b/html/forms/parse-device-group.inc.php @@ -12,17 +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; - $group_split[$count] = $group_split[$count].' &&'; - $output = array('name'=>$group['name'],'desc'=>$group['desc'],'pattern'=>$group_split); +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 { + $group_split[$count] = $group_split[$count].' &&'; + } + + $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 72fd86eb7..f9cac5ba1 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 c30eec3f5..b5800b50f 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 b07f2c442..ad65e1069 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 a9856729b..d7c14af04 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 8b686e610..4c2495060 100644 --- a/html/forms/poller-module-update.inc.php +++ b/html/forms/poller-module-update.inc.php @@ -1,37 +1,28 @@ 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 4699653c6..d601116ee 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 15415f118..eb6b2b967 100644 --- a/html/forms/sensor-alert-reset.inc.php +++ b/html/forms/sensor-alert-reset.inc.php @@ -13,9 +13,6 @@ */ // 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 91a5b9aec..b0596db89 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 dc6da67c3..b7c04944b 100644 --- a/html/forms/token-item-create.inc.php +++ b/html/forms/token-item-create.inc.php @@ -12,33 +12,27 @@ * 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 e336d911e..987464ef1 100644 --- a/html/forms/token-item-disable.inc.php +++ b/html/forms/token-item-disable.inc.php @@ -12,34 +12,28 @@ * 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 1b4522f39..e2f111efd 100644 --- a/html/forms/token-item-remove.inc.php +++ b/html/forms/token-item-remove.inc.php @@ -12,25 +12,20 @@ * 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 9c8de3cbc..261e30062 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 85919d1b7..edcaf8cb0 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 73e60edca..8b7e8fac3 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 95cf00b21..f3cf51fd9 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/images/os/mellanox.png b/html/images/os/mellanox.png new file mode 100644 index 000000000..a1b9b4b0e Binary files /dev/null and b/html/images/os/mellanox.png differ diff --git a/html/images/os/meraki.png b/html/images/os/meraki.png new file mode 100644 index 000000000..51b3564f6 Binary files /dev/null and b/html/images/os/meraki.png differ diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index a3593e684..4f20c9b8b 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 e64465a35..316fcde5c 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 883cd2d08..221de3adc 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 c0416ab0f..c55b54009 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 cf91f27c2..84e119cea 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 0d54628c9..92f2aea2f 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/config.php b/html/includes/collectd/config.php index f65db26e8..812c5857a 100644 --- a/html/includes/collectd/config.php +++ b/html/includes/collectd/config.php @@ -1,53 +1,91 @@ -'hour', 'label'=>'past hour', 'seconds'=>3600), - array('name'=>'day', 'label'=>'past day', 'seconds'=>86400), - array('name'=>'week', 'label'=>'past week', 'seconds'=>604800), - array('name'=>'month', 'label'=>'past month', 'seconds'=>2678400), - array('name'=>'year', 'label'=>'past year', 'seconds'=>31622400)); +$config['timespan'] = array( + array( + 'name' => 'hour', + 'label' => 'past hour', + 'seconds' => 3600, + ), + array( + 'name' => 'day', + 'label' => 'past day', + 'seconds' => 86400, + ), + array( + 'name' => 'week', + 'label' => 'past week', + 'seconds' => 604800, + ), + array( + 'name' => 'month', + 'label' => 'past month', + 'seconds' => 2678400, + ), + array( + 'name' => 'year', + 'label' => 'past year', + 'seconds' => 31622400, + ), +); // Interval at which values are collectd (currently ignored) -$config['rrd_interval'] = 10; +$config['rrd_interval'] = 10; // Average rows/rra (currently ignored) -$config['rrd_rows'] = 2400; +$config['rrd_rows'] = 2400; // Additional options to pass to rrdgraph -#$config['rrd_opts'] = (isset($config['rrdgraph_defaults']) ? $config['rrdgraph_defaults'] : ''); -#$config['rrd_opts'] = array('-E', "-c", "SHADEA#a5a5a5", "-c", "SHADEB#a5a5a5", "-c", "FONT#000000", "-c", "CANVAS#FFFFFF", "-c", "GRID#aaaaaa", -# "-c", "MGRID#FFAAAA", "-c", "FRAME#3e3e3e", "-c", "ARROW#5e5e5e", "-R", "normal"); +// $config['rrd_opts'] = (isset($config['rrdgraph_defaults']) ? $config['rrdgraph_defaults'] : ''); +// $config['rrd_opts'] = array('-E', "-c", "SHADEA#a5a5a5", "-c", "SHADEB#a5a5a5", "-c", "FONT#000000", "-c", "CANVAS#FFFFFF", "-c", "GRID#aaaaaa", +// "-c", "MGRID#FFAAAA", "-c", "FRAME#3e3e3e", "-c", "ARROW#5e5e5e", "-R", "normal"); // Predefined set of colors for use by collectd_draw_rrd() -$config['rrd_colors'] = array( - 'h_1'=>'F7B7B7', 'f_1'=>'FF0000', // Red - 'h_2'=>'B7EFB7', 'f_2'=>'00E000', // Green - 'h_3'=>'B7B7F7', 'f_3'=>'0000FF', // Blue - 'h_4'=>'F3DFB7', 'f_4'=>'F0A000', // Yellow - 'h_5'=>'B7DFF7', 'f_5'=>'00A0FF', // Cyan - 'h_6'=>'DFB7F7', 'f_6'=>'A000FF', // Magenta - 'h_7'=>'FFC782', 'f_7'=>'FF8C00', // Orange - 'h_8'=>'DCFF96', 'f_8'=>'AAFF00', // Lime - 'h_9'=>'83FFCD', 'f_9'=>'00FF99', - 'h_10'=>'81D9FF', 'f_10'=>'00B2FF', - 'h_11'=>'FF89F5', 'f_11'=>'FF00EA', - 'h_12'=>'FF89AE', 'f_12'=>'FF0051', - 'h_13'=>'BBBBBB', 'f_13'=>'555555', - ); +$config['rrd_colors'] = array( + 'h_1' => 'F7B7B7', + 'f_1' => 'FF0000', // Red + 'h_2' => 'B7EFB7', + 'f_2' => '00E000', // Green + 'h_3' => 'B7B7F7', + 'f_3' => '0000FF', // Blue + 'h_4' => 'F3DFB7', + 'f_4' => 'F0A000', // Yellow + 'h_5' => 'B7DFF7', + 'f_5' => '00A0FF', // Cyan + 'h_6' => 'DFB7F7', + 'f_6' => 'A000FF', // Magenta + 'h_7' => 'FFC782', + 'f_7' => 'FF8C00', // Orange + 'h_8' => 'DCFF96', + 'f_8' => 'AAFF00', // Lime + 'h_9' => '83FFCD', + 'f_9' => '00FF99', + 'h_10' => '81D9FF', + 'f_10' => '00B2FF', + 'h_11' => 'FF89F5', + 'f_11' => 'FF00EA', + 'h_12' => 'FF89AE', + 'f_12' => 'FF0051', + 'h_13' => 'BBBBBB', + 'f_13' => '555555', +); /* * URL to collectd's unix socket (unixsock plugin) * enabled: 'unix:///var/run/collectd/collectd-unixsock' @@ -58,11 +96,9 @@ $config['collectd_sock'] = null; * Path to TTF font file to use in error images * (fallback when file does not exist is GD fixed font) */ -$config['error_font'] = '/usr/share/fonts/corefonts/arial.ttf'; +$config['error_font'] = '/usr/share/fonts/corefonts/arial.ttf'; /* * Constant defining full path to rrdtool */ define('RRDTOOL', $config['rrdtool']); - -?> diff --git a/html/includes/collectd/functions.php b/html/includes/collectd/functions.php index d7b44a969..b004f832d 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 3d5882594..889613c83 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 fc885958b..8c6775930 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 ae5d576c0..6f27b50af 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 8e0a1ff32..ee4e63d07 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 09717037b..37a1c9c7e 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 665c1d738..e767aa698 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 4b48bfd4a..9c0e87362 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 008525207..c3bf3bc30 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 fc7c52a09..6aed9fa6f 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 dc6ccc508..ab343e2d5 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/XXX_device_memory_windows.inc.php b/html/includes/graphs/XXX_device_memory_windows.inc.php index cd964a856..7122762da 100644 --- a/html/includes/graphs/XXX_device_memory_windows.inc.php +++ b/html/includes/graphs/XXX_device_memory_windows.inc.php @@ -1,12 +1,12 @@ \ No newline at end of file +$rrd_options .= ' LINE1:totalreal#050505:total'; +$rrd_options .= ' GPRINT:totalreal:AVERAGE:\ \ %7.2lf%sB'; diff --git a/html/includes/graphs/accesspoints/auth.inc.php b/html/includes/graphs/accesspoints/auth.inc.php index 7f479a0f2..16f3c57ba 100644 --- a/html/includes/graphs/accesspoints/auth.inc.php +++ b/html/includes/graphs/accesspoints/auth.inc.php @@ -1,17 +1,13 @@ diff --git a/html/includes/graphs/accesspoints/channel.inc.php b/html/includes/graphs/accesspoints/channel.inc.php index 03b0dd24c..d68824fa1 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/accesspoints/interference.inc.php b/html/includes/graphs/accesspoints/interference.inc.php index 03128f2ad..07bb8e393 100644 --- a/html/includes/graphs/accesspoints/interference.inc.php +++ b/html/includes/graphs/accesspoints/interference.inc.php @@ -1,25 +1,21 @@ diff --git a/html/includes/graphs/accesspoints/numasoclients.inc.php b/html/includes/graphs/accesspoints/numasoclients.inc.php index e0ee8a15d..9f4bde6fe 100644 --- a/html/includes/graphs/accesspoints/numasoclients.inc.php +++ b/html/includes/graphs/accesspoints/numasoclients.inc.php @@ -1,25 +1,21 @@ diff --git a/html/includes/graphs/accesspoints/nummonbssid.inc.php b/html/includes/graphs/accesspoints/nummonbssid.inc.php index c3f5c4ac6..85b3b10b5 100644 --- a/html/includes/graphs/accesspoints/nummonbssid.inc.php +++ b/html/includes/graphs/accesspoints/nummonbssid.inc.php @@ -1,26 +1,21 @@ diff --git a/html/includes/graphs/accesspoints/nummonclients.inc.php b/html/includes/graphs/accesspoints/nummonclients.inc.php index 9033ac1d8..5539f5af6 100644 --- a/html/includes/graphs/accesspoints/nummonclients.inc.php +++ b/html/includes/graphs/accesspoints/nummonclients.inc.php @@ -1,25 +1,21 @@ diff --git a/html/includes/graphs/accesspoints/radioutil.inc.php b/html/includes/graphs/accesspoints/radioutil.inc.php index cde1ed17e..d012ed294 100644 --- a/html/includes/graphs/accesspoints/radioutil.inc.php +++ b/html/includes/graphs/accesspoints/radioutil.inc.php @@ -1,25 +1,21 @@ diff --git a/html/includes/graphs/accesspoints/txpow.inc.php b/html/includes/graphs/accesspoints/txpow.inc.php index 86ecf0729..1dab4340d 100644 --- a/html/includes/graphs/accesspoints/txpow.inc.php +++ b/html/includes/graphs/accesspoints/txpow.inc.php @@ -1,26 +1,21 @@ diff --git a/html/includes/graphs/altiga_ssl_sessions.inc.php b/html/includes/graphs/altiga_ssl_sessions.inc.php index e9e93c9f1..a69f68178 100644 --- a/html/includes/graphs/altiga_ssl_sessions.inc.php +++ b/html/includes/graphs/altiga_ssl_sessions.inc.php @@ -1,33 +1,31 @@ \ No newline at end of file diff --git a/html/includes/graphs/application/apache_bits.inc.php b/html/includes/graphs/application/apache_bits.inc.php index fabf9453b..b6767533e 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 bb49d3f63..e136a6ed1 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 0f0d4832c..5e1a74cea 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 bf9237f4a..fe216efe7 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/auth.inc.php b/html/includes/graphs/application/auth.inc.php index b1662bc85..15c8f01ca 100644 --- a/html/includes/graphs/application/auth.inc.php +++ b/html/includes/graphs/application/auth.inc.php @@ -1,12 +1,9 @@ diff --git a/html/includes/graphs/application/bind_queries.inc.php b/html/includes/graphs/application/bind_queries.inc.php index 985e720e7..3df1abf45 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 767246ce8..d3458c72a 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 37c1d9db0..d20c1b304 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_queue.inc.php b/html/includes/graphs/application/drbd_queue.inc.php index 08a90f8c3..a04a4080b 100644 --- a/html/includes/graphs/application/drbd_queue.inc.php +++ b/html/includes/graphs/application/drbd_queue.inc.php @@ -1,37 +1,37 @@ 'Local I/O', - 'pe' => 'Pending', - 'ua' => 'UnAcked', - 'ap' => 'App Pending', -); + 'lo' => 'Local I/O', + 'pe' => 'Pending', + 'ua' => 'UnAcked', + 'ap' => 'App Pending', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { - $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 0; -$unit_text = ""; +$unit_text = ''; -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_unsynced.inc.php b/html/includes/graphs/application/drbd_unsynced.inc.php index 03293e136..f2a551ba8 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/mailscanner_reject.inc.php b/html/includes/graphs/application/mailscanner_reject.inc.php index b45e72398..9298460db 100644 --- a/html/includes/graphs/application/mailscanner_reject.inc.php +++ b/html/includes/graphs/application/mailscanner_reject.inc.php @@ -1,36 +1,32 @@ array('descr' => 'Rejected'), - 'msg_relay' => array('descr' => 'Relayed'), - 'msg_waiting' => array('descr' => 'Waiting'), - ); + 'msg_rejected' => array('descr' => 'Rejected'), + 'msg_relay' => array('descr' => 'Relayed'), + 'msg_waiting' => array('descr' => 'Waiting'), + ); -$i = 0; -$x = 0; +$i = 0; +$x = 0; -if (is_file($rrd_filename)) -{ - $max_colours = count($config['graph_colours'][$colours]); - foreach ($array as $ds => $vars) - { - $x = (($x<=$max_colours) ? $x : 0); - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = $vars['descr']; - $rrd_list[$i]['ds'] = $ds; - $rrd_list[$i]['colour'] = $config['graph_colours'][$colours][$x]; - $i++; - $x++; - } +if (is_file($rrd_filename)) { + $max_colours = count($config['graph_colours'][$colours]); + foreach ($array as $ds => $vars) { + $x = (($x <= $max_colours) ? $x : 0); + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $vars['descr']; + $rrd_list[$i]['ds'] = $ds; + $rrd_list[$i]['colour'] = $config['graph_colours'][$colours][$x]; + $i++; + $x++; + } } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/mailscanner_sent.inc.php b/html/includes/graphs/application/mailscanner_sent.inc.php index c006f5c5a..f9cb4c4a6 100644 --- a/html/includes/graphs/application/mailscanner_sent.inc.php +++ b/html/includes/graphs/application/mailscanner_sent.inc.php @@ -1,27 +1,24 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/application/mailscanner_spam.inc.php b/html/includes/graphs/application/mailscanner_spam.inc.php index 2e913f65c..f68b5200b 100644 --- a/html/includes/graphs/application/mailscanner_spam.inc.php +++ b/html/includes/graphs/application/mailscanner_spam.inc.php @@ -1,30 +1,32 @@ array('descr' => 'Spam', 'colour' => 'FF8800'), - 'virus' => array('descr' => 'Virus', 'colour' => 'FF0000') - ); + 'spam' => array( + 'descr' => 'Spam', + 'colour' => 'FF8800', + ), + 'virus' => array( + 'descr' => 'Virus', + 'colour' => 'FF0000', + ), + ); -$i = 0; +$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++; - } +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++; + } } -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/memcached.inc.php b/html/includes/graphs/application/memcached.inc.php index 8afd6bd1c..6bd8d5882 100644 --- a/html/includes/graphs/application/memcached.inc.php +++ b/html/includes/graphs/application/memcached.inc.php @@ -1,7 +1,5 @@ diff --git a/html/includes/graphs/application/memcached_bits.inc.php b/html/includes/graphs/application/memcached_bits.inc.php index 2fadf3e16..c377e301b 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/memcached_commands.inc.php b/html/includes/graphs/application/memcached_commands.inc.php index e7f0788b3..d3665e98b 100644 --- a/html/includes/graphs/application/memcached_commands.inc.php +++ b/html/includes/graphs/application/memcached_commands.inc.php @@ -1,25 +1,23 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/application/memcached_data.inc.php b/html/includes/graphs/application/memcached_data.inc.php index 6aec349b6..9b2f43db7 100644 --- a/html/includes/graphs/application/memcached_data.inc.php +++ b/html/includes/graphs/application/memcached_data.inc.php @@ -1,34 +1,41 @@ array('descr' => 'Capacity', 'colour' => '555555'), - 'bytes' => array('descr' => 'Used', 'colour' => 'cc0000', 'areacolour' => 'ff999955'), - ); +$scale_min = 0; +$colours = 'mixed'; +$nototal = 0; +$unit_text = 'Packets/sec'; +$array = array( + 'limit_maxbytes' => array( + 'descr' => 'Capacity', + 'colour' => '555555', + ), + 'bytes' => array( + 'descr' => 'Used', + 'colour' => 'cc0000', + 'areacolour' => 'ff999955', + ), +); -$i = 0; +$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']; - if (!empty($vars['areacolour'])) { $rrd_list[$i]['areacolour'] = $vars['areacolour']; } - $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']; + if (!empty($vars['areacolour'])) { + $rrd_list[$i]['areacolour'] = $vars['areacolour']; + } + + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/memcached_items.inc.php b/html/includes/graphs/application/memcached_items.inc.php index 5d8b41d36..067c6496c 100644 --- a/html/includes/graphs/application/memcached_items.inc.php +++ b/html/includes/graphs/application/memcached_items.inc.php @@ -1,33 +1,36 @@ array('descr' => 'Items', 'colour' => '555555'), - ); +$scale_min = 0; +$colours = 'mixed'; +$nototal = 0; +$unit_text = 'Items'; +$array = array( + 'curr_items' => array( + 'descr' => 'Items', + 'colour' => '555555', + ), +); -$i = 0; +$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']; - if (!empty($vars['areacolour'])) { $rrd_list[$i]['areacolour'] = $vars['areacolour']; } - $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']; + if (!empty($vars['areacolour'])) { + $rrd_list[$i]['areacolour'] = $vars['areacolour']; + } + + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/memcached_threads.inc.php b/html/includes/graphs/application/memcached_threads.inc.php index 1802f44e7..0792bd971 100644 --- a/html/includes/graphs/application/memcached_threads.inc.php +++ b/html/includes/graphs/application/memcached_threads.inc.php @@ -1,20 +1,18 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/memcached_uptime.inc.php b/html/includes/graphs/application/memcached_uptime.inc.php index ed76dda95..3a18bad68 100644 --- a/html/includes/graphs/application/memcached_uptime.inc.php +++ b/html/includes/graphs/application/memcached_uptime.inc.php @@ -1,18 +1,16 @@ diff --git a/html/includes/graphs/application/mysql_command_counters.inc.php b/html/includes/graphs/application/mysql_command_counters.inc.php index a8e17557c..19182d0a6 100644 --- a/html/includes/graphs/application/mysql_command_counters.inc.php +++ b/html/includes/graphs/application/mysql_command_counters.inc.php @@ -1,37 +1,64 @@ 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'), +$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', + ), ); $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 = "Commands"; +$unit_text = 'Commands'; -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/mysql_connections.inc.php b/html/includes/graphs/application/mysql_connections.inc.php index 5feb7bf49..d8024a9ed 100644 --- a/html/includes/graphs/application/mysql_connections.inc.php +++ b/html/includes/graphs/application/mysql_connections.inc.php @@ -1,36 +1,54 @@ array('descr' => 'Max Connections', 'colour' => '22FF22'), - 'MUCs' => array('descr' => 'Max Used Connections', 'colour' => '0022FF'), - 'ACs' => array('descr' => 'Aborted Clients', 'colour' => 'FF0000'), - 'AdCs' => array('descr' => 'Aborted Connects', 'colour' => '0080C0'), - 'TCd' => array('descr' => 'Threads Connected', 'colour' => 'FF0000'), - 'Cs' => array('descr' => 'New Connections', 'colour' => '0080C0'), -); +$array = array( + 'MaCs' => array( + 'descr' => 'Max Connections', + 'colour' => '22FF22', + ), + 'MUCs' => array( + 'descr' => 'Max Used Connections', + 'colour' => '0022FF', + ), + 'ACs' => array( + 'descr' => 'Aborted Clients', + 'colour' => 'FF0000', + ), + 'AdCs' => array( + 'descr' => 'Aborted Connects', + 'colour' => '0080C0', + ), + 'TCd' => array( + 'descr' => 'Threads Connected', + 'colour' => 'FF0000', + ), + 'Cs' => array( + 'descr' => 'New Connections', + 'colour' => '0080C0', + ), + ); $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 = "Connections"; +$unit_text = 'Connections'; -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/mysql_files_tables.inc.php b/html/includes/graphs/application/mysql_files_tables.inc.php index 758ec51e6..f02593e60 100644 --- a/html/includes/graphs/application/mysql_files_tables.inc.php +++ b/html/includes/graphs/application/mysql_files_tables.inc.php @@ -1,32 +1,32 @@ array('descr' => 'Table Cache'), - 'OFs' => array('descr' => 'Open Files'), - 'OTs' => array('descr' => 'Open Tables'), - 'OdTs' => array('descr' => 'Opened Tables'), -); +$array = array( + 'TOC' => array('descr' => 'Table Cache'), + 'OFs' => array('descr' => 'Open Files'), + 'OTs' => array('descr' => 'Open Tables'), + 'OdTs' => array('descr' => 'Opened Tables'), + ); $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 = ""; +$unit_text = ''; -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/mysql_innodb_buffer_pool.inc.php b/html/includes/graphs/application/mysql_innodb_buffer_pool.inc.php index 84adc77ba..6f9255ffa 100644 --- a/html/includes/graphs/application/mysql_innodb_buffer_pool.inc.php +++ b/html/includes/graphs/application/mysql_innodb_buffer_pool.inc.php @@ -1,36 +1,37 @@ 'Buffer Pool Size', - 'IBPDBp' => 'Database Pages', - 'IBPFe' => 'Free Pages', - 'IBPMps' => 'Modified Pages', -); +$array = array( + 'IBPse' => 'Buffer Pool Size', + 'IBPDBp' => 'Database Pages', + 'IBPFe' => 'Free Pages', + 'IBPMps' => 'Modified Pages', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "Commands"; +$unit_text = 'Commands'; -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/mysql_innodb_buffer_pool_activity.inc.php b/html/includes/graphs/application/mysql_innodb_buffer_pool_activity.inc.php index 11f282488..e2e3f8441 100644 --- a/html/includes/graphs/application/mysql_innodb_buffer_pool_activity.inc.php +++ b/html/includes/graphs/application/mysql_innodb_buffer_pool_activity.inc.php @@ -1,35 +1,36 @@ 'Pages Read', - 'IBCd' => 'Pages Created', - 'IBWr' => 'Pages Written', -); +$array = array( + 'IBRd' => 'Pages Read', + 'IBCd' => 'Pages Created', + 'IBWr' => 'Pages Written', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "activity"; +$unit_text = 'activity'; -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/mysql_innodb_insert_buffer.inc.php b/html/includes/graphs/application/mysql_innodb_insert_buffer.inc.php index da09b08ce..9cbde97ff 100644 --- a/html/includes/graphs/application/mysql_innodb_insert_buffer.inc.php +++ b/html/includes/graphs/application/mysql_innodb_insert_buffer.inc.php @@ -1,35 +1,36 @@ 'Inserts', - 'IBIMRd' => 'Merged Records', - 'IBIMs' => 'Merges', -); +$array = array( + 'IBIIs' => 'Inserts', + 'IBIMRd' => 'Merged Records', + 'IBIMs' => 'Merges', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = ""; +$unit_text = ''; -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/mysql_innodb_io.inc.php b/html/includes/graphs/application/mysql_innodb_io.inc.php index 8af3ff1b6..014030370 100644 --- a/html/includes/graphs/application/mysql_innodb_io.inc.php +++ b/html/includes/graphs/application/mysql_innodb_io.inc.php @@ -1,12 +1,11 @@ diff --git a/html/includes/graphs/application/mysql_innodb_io_pending.inc.php b/html/includes/graphs/application/mysql_innodb_io_pending.inc.php index 7214675d7..7b578e052 100644 --- a/html/includes/graphs/application/mysql_innodb_io_pending.inc.php +++ b/html/includes/graphs/application/mysql_innodb_io_pending.inc.php @@ -1,39 +1,40 @@ 'AIO Log', - 'IBISc' => 'AIO Sync', - 'IBIFLg' => 'Buf Pool Flush', - 'IBFBl' => 'Log Flushes', - 'IBIIAo' => 'Insert Buf AIO Read', - 'IBIAd' => 'Normal AIO Read', - 'IBIAe' => 'Normal AIO Writes', -); +$array = array( + 'IBILog' => 'AIO Log', + 'IBISc' => 'AIO Sync', + 'IBIFLg' => 'Buf Pool Flush', + 'IBFBl' => 'Log Flushes', + 'IBIIAo' => 'Insert Buf AIO Read', + 'IBIAd' => 'Normal AIO Read', + 'IBIAe' => 'Normal AIO Writes', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = ""; +$unit_text = ''; -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/mysql_innodb_log.inc.php b/html/includes/graphs/application/mysql_innodb_log.inc.php index 89750845d..b68890b84 100644 --- a/html/includes/graphs/application/mysql_innodb_log.inc.php +++ b/html/includes/graphs/application/mysql_innodb_log.inc.php @@ -1,12 +1,11 @@ diff --git a/html/includes/graphs/application/mysql_innodb_row_operations.inc.php b/html/includes/graphs/application/mysql_innodb_row_operations.inc.php index f178387a7..f3b74a58b 100644 --- a/html/includes/graphs/application/mysql_innodb_row_operations.inc.php +++ b/html/includes/graphs/application/mysql_innodb_row_operations.inc.php @@ -1,36 +1,37 @@ 'Deletes', - 'IDBRId' => 'Inserts', - 'IDBRRd' => 'Reads', - 'IDBRUd' => 'Updates', -); +$array = array( + 'IDBRDd' => 'Deletes', + 'IDBRId' => 'Inserts', + 'IDBRRd' => 'Reads', + 'IDBRUd' => 'Updates', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 0; -$unit_text = "Rows"; +$unit_text = 'Rows'; -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/mysql_innodb_semaphores.inc.php b/html/includes/graphs/application/mysql_innodb_semaphores.inc.php index 27e33aa18..4b259ed7a 100644 --- a/html/includes/graphs/application/mysql_innodb_semaphores.inc.php +++ b/html/includes/graphs/application/mysql_innodb_semaphores.inc.php @@ -1,35 +1,36 @@ 'Spin Rounds', - 'IBSWs' => 'Spin Waits', - 'IBOWs' => 'OS Waits', -); +$array = array( + 'IBSRs' => 'Spin Rounds', + 'IBSWs' => 'Spin Waits', + 'IBOWs' => 'OS Waits', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "Semaphores"; +$unit_text = 'Semaphores'; -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/mysql_innodb_transactions.inc.php b/html/includes/graphs/application/mysql_innodb_transactions.inc.php index 2f53e561b..87e64f73e 100644 --- a/html/includes/graphs/application/mysql_innodb_transactions.inc.php +++ b/html/includes/graphs/application/mysql_innodb_transactions.inc.php @@ -1,33 +1,32 @@ 'Transactions created', -); +$array = array('IBTNx' => 'Transactions created'); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { - $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "transactions"; +$unit_text = 'transactions'; -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/mysql_myisam_indexes.inc.php b/html/includes/graphs/application/mysql_myisam_indexes.inc.php index 883b496b1..a4d8a36e3 100644 --- a/html/includes/graphs/application/mysql_myisam_indexes.inc.php +++ b/html/includes/graphs/application/mysql_myisam_indexes.inc.php @@ -1,36 +1,37 @@ 'read requests', - 'KRs' => 'reads', - 'KWR' => 'write requests', - 'KWs' => 'writes', -); +$array = array( + 'KRRs' => 'read requests', + 'KRs' => 'reads', + 'KWR' => 'write requests', + 'KWs' => 'writes', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "Keys"; +$unit_text = 'Keys'; -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/mysql_network_traffic.inc.php b/html/includes/graphs/application/mysql_network_traffic.inc.php index d606a1cdd..c37372eee 100644 --- a/html/includes/graphs/application/mysql_network_traffic.inc.php +++ b/html/includes/graphs/application/mysql_network_traffic.inc.php @@ -1,19 +1,16 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/application/mysql_query_cache.inc.php b/html/includes/graphs/application/mysql_query_cache.inc.php index 132e66dd0..1de063436 100644 --- a/html/includes/graphs/application/mysql_query_cache.inc.php +++ b/html/includes/graphs/application/mysql_query_cache.inc.php @@ -1,38 +1,52 @@ array('descr' => 'Queries in cache', 'colour' => '22FF22'), - 'QCHs' => array('descr' => 'Cache hits', 'colour' => '0022FF'), - 'QCIs' => array('descr' => 'Inserts', 'colour' => 'FF0000'), - 'QCNCd' => array('descr' => 'Not cached', 'colour' => '00AAAA'), - 'QCLMPs' => array('descr' => 'Low-memory prunes', 'colour' => 'FF00FF'), -); +$array = array( + 'QCQICe' => array( + 'descr' => 'Queries in cache', + 'colour' => '22FF22', + ), + 'QCHs' => array( + 'descr' => 'Cache hits', + 'colour' => '0022FF', + ), + 'QCIs' => array( + 'descr' => 'Inserts', + 'colour' => 'FF0000', + ), + 'QCNCd' => array( + 'descr' => 'Not cached', + 'colour' => '00AAAA', + ), + 'QCLMPs' => array( + 'descr' => 'Low-memory prunes', + 'colour' => 'FF00FF', + ), + ); $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 = "Commands"; +$unit_text = 'Commands'; -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/mysql_query_cache_memory.inc.php b/html/includes/graphs/application/mysql_query_cache_memory.inc.php index bc72499d5..f4dcf4737 100644 --- a/html/includes/graphs/application/mysql_query_cache_memory.inc.php +++ b/html/includes/graphs/application/mysql_query_cache_memory.inc.php @@ -1,34 +1,35 @@ 'Cache size', - 'QCeFy' => 'Free mem', -); +$array = array( + 'QCs' => 'Cache size', + 'QCeFy' => 'Free mem', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "Bytes"; +$unit_text = 'Bytes'; -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/mysql_select_types.inc.php b/html/includes/graphs/application/mysql_select_types.inc.php index 7d25324e4..77f15948f 100644 --- a/html/includes/graphs/application/mysql_select_types.inc.php +++ b/html/includes/graphs/application/mysql_select_types.inc.php @@ -1,37 +1,38 @@ 'Full Join', - 'SFRJn' => 'Full Range', - 'SRe' => 'Range', - 'SRCk' => 'Range Check', - 'SSn' => 'Scan', -); +$array = array( + 'SFJn' => 'Full Join', + 'SFRJn' => 'Full Range', + 'SRe' => 'Range', + 'SRCk' => 'Range Check', + 'SSn' => 'Scan', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 0; -$unit_text = "Queries"; +$unit_text = 'Queries'; -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/mysql_slow_queries.inc.php b/html/includes/graphs/application/mysql_slow_queries.inc.php index 6abffdd0c..c8304c678 100644 --- a/html/includes/graphs/application/mysql_slow_queries.inc.php +++ b/html/includes/graphs/application/mysql_slow_queries.inc.php @@ -1,34 +1,32 @@ 'Slow queries', -); +$array = array('SQs' => 'Slow queries'); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { - $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "Queries"; +$unit_text = 'Queries'; -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/mysql_sorts.inc.php b/html/includes/graphs/application/mysql_sorts.inc.php index d2f44720b..15396df98 100644 --- a/html/includes/graphs/application/mysql_sorts.inc.php +++ b/html/includes/graphs/application/mysql_sorts.inc.php @@ -1,37 +1,37 @@ 'Rows Sorted', - 'SRange' => 'Range', - 'SMPs' => 'Merge Passes', - 'SScan' => 'Scan', -); + 'SRows' => 'Rows Sorted', + 'SRange' => 'Range', + 'SMPs' => 'Merge Passes', + 'SScan' => 'Scan', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { - $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 0; -$unit_text = ""; +$unit_text = ''; -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/mysql_status.inc.php b/html/includes/graphs/application/mysql_status.inc.php index ffbb8c176..9e8b1fa06 100644 --- a/html/includes/graphs/application/mysql_status.inc.php +++ b/html/includes/graphs/application/mysql_status.inc.php @@ -1,51 +1,51 @@ 'd2', - 'State_copying_to_tmp_table' => 'd3', - 'State_end' => 'd4', - 'State_freeing_items' => 'd5', - 'State_init' => 'd6', - 'State_locked' => 'd7', - 'State_login' => 'd8', - 'State_preparing' => 'd9', - 'State_reading_from_net' => 'da', - 'State_sending_data' => 'db', - 'State_sorting_result' => 'dc', - 'State_statistics' => 'dd', - 'State_updating' => 'de', - 'State_writing_to_net' => 'df', - 'State_none' => 'dg', - 'State_other' => 'dh' + 'State_closing_tables' => 'd2', + 'State_copying_to_tmp_table' => 'd3', + 'State_end' => 'd4', + 'State_freeing_items' => 'd5', + 'State_init' => 'd6', + 'State_locked' => 'd7', + 'State_login' => 'd8', + 'State_preparing' => 'd9', + 'State_reading_from_net' => 'da', + 'State_sending_data' => 'db', + 'State_sorting_result' => 'dc', + 'State_statistics' => 'dd', + 'State_updating' => 'de', + 'State_writing_to_net' => 'df', + 'State_none' => 'dg', + 'State_other' => 'dh', ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $vars => $ds) - { - $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; +if (is_file($rrd_filename)) { + foreach ($array as $vars => $ds) { + $rrd_list[$i]['filename'] = $rrd_filename; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['descr'] = str_replace('_', ' ', $rrd_list[$i]['descr']); + $rrd_list[$i]['descr'] = str_replace('State ', '', $rrd_list[$i]['descr']); + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['descr'] = str_replace("_", " ", $rrd_list[$i]['descr']); - $rrd_list[$i]['descr'] = str_replace("State ", "", $rrd_list[$i]['descr']); - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 1; -$unit_text = "activity"; +$unit_text = 'activity'; -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/mysql_table_locks.inc.php b/html/includes/graphs/application/mysql_table_locks.inc.php index 08234d735..7a7b0ed0a 100644 --- a/html/includes/graphs/application/mysql_table_locks.inc.php +++ b/html/includes/graphs/application/mysql_table_locks.inc.php @@ -1,35 +1,35 @@ 'immed', - 'TLWd' => 'waited', -); + 'TLIe' => 'immed', + 'TLWd' => 'waited', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { - $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 0; -$unit_text = "Table locks"; +$unit_text = 'Table locks'; -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/mysql_temporary_objects.inc.php b/html/includes/graphs/application/mysql_temporary_objects.inc.php index ec22c6925..149ec713e 100644 --- a/html/includes/graphs/application/mysql_temporary_objects.inc.php +++ b/html/includes/graphs/application/mysql_temporary_objects.inc.php @@ -1,36 +1,36 @@ 'disk tables', - 'CTMPTs' => 'tables', - 'CTMPFs' => 'files', -); + 'CTMPDTs' => 'disk tables', + 'CTMPTs' => 'tables', + 'CTMPFs' => 'files', + ); $i = 0; -if (is_file($rrd_filename)) -{ - foreach ($array as $ds => $vars) - { - $rrd_list[$i]['filename'] = $rrd_filename; - if (is_array($vars)) - { - $rrd_list[$i]['descr'] = $vars['descr']; - } else { - $rrd_list[$i]['descr'] = $vars; +if (is_file($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + if (is_array($vars)) { + $rrd_list[$i]['descr'] = $vars['descr']; + } + else { + $rrd_list[$i]['descr'] = $vars; + } + + $rrd_list[$i]['ds'] = $ds; + $i++; } - $rrd_list[$i]['ds'] = $ds; - $i++; - } -} else { echo("file missing: $file"); } +} +else { + echo "file missing: $file"; +} -$colours = "mixed"; +$colours = 'mixed'; $nototal = 0; -$unit_text = "Temp"; +$unit_text = 'Temp'; -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/nginx_connections.inc.php b/html/includes/graphs/application/nginx_connections.inc.php index d2dc35915..44e2e3a5d 100644 --- a/html/includes/graphs/application/nginx_connections.inc.php +++ b/html/includes/graphs/application/nginx_connections.inc.php @@ -2,33 +2,45 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-nginx-".$app['app_id'].".rrd"; +$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-nginx-'.$app['app_id'].'.rrd'; -$array = array('Reading' => array('descr' => 'Reading', 'colour' => '750F7DFF'), - 'Writing' => array('descr' => 'Writing', 'colour' => '00FF00FF'), - 'Waiting' => array('descr' => 'Waiting', 'colour' => '4444FFFF'), - 'Active' => array('descr' => 'Starting', 'colour' => '157419FF'), -); +$array = array( + 'Reading' => array( + 'descr' => 'Reading', + 'colour' => '750F7DFF', + ), + 'Writing' => array( + 'descr' => 'Writing', + 'colour' => '00FF00FF', + ), + 'Waiting' => array( + 'descr' => 'Waiting', + 'colour' => '4444FFFF', + ), + 'Active' => array( + 'descr' => 'Starting', + 'colour' => '157419FF', + ), + ); $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/nginx_req.inc.php b/html/includes/graphs/application/nginx_req.inc.php index a512b9a94..97bff73ae 100644 --- a/html/includes/graphs/application/nginx_req.inc.php +++ b/html/includes/graphs/application/nginx_req.inc.php @@ -1,25 +1,22 @@ diff --git a/html/includes/graphs/application/ntpclient_freq.inc.php b/html/includes/graphs/application/ntpclient_freq.inc.php index 01288ad9f..36d580a50 100644 --- a/html/includes/graphs/application/ntpclient_freq.inc.php +++ b/html/includes/graphs/application/ntpclient_freq.inc.php @@ -1,21 +1,18 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/ntpclient_stats.inc.php b/html/includes/graphs/application/ntpclient_stats.inc.php index c83993ebd..b7c668054 100644 --- a/html/includes/graphs/application/ntpclient_stats.inc.php +++ b/html/includes/graphs/application/ntpclient_stats.inc.php @@ -1,34 +1,31 @@ array('descr' => 'Offset'), - 'jitter' => array('descr' => 'Jitter'), - 'noise' => array('descr' => 'Noise'), - 'stability' => array('descr' => 'Stability') - ); + 'offset' => array('descr' => 'Offset'), + 'jitter' => array('descr' => 'Jitter'), + 'noise' => array('descr' => 'Noise'), + 'stability' => array('descr' => 'Stability'), + ); -$i = 0; +$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'] = $config['graph_colours'][$colours][$i]; - $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'] = $config['graph_colours'][$colours][$i]; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/ntpdserver_bits.inc.php b/html/includes/graphs/application/ntpdserver_bits.inc.php index f3cbb7428..b96f3c5a5 100644 --- a/html/includes/graphs/application/ntpdserver_bits.inc.php +++ b/html/includes/graphs/application/ntpdserver_bits.inc.php @@ -1,35 +1,30 @@ +// include("includes/graphs/generic_bits.inc.php"); +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/application/ntpdserver_buffer.inc.php b/html/includes/graphs/application/ntpdserver_buffer.inc.php index 47c930f8e..3e47555f9 100644 --- a/html/includes/graphs/application/ntpdserver_buffer.inc.php +++ b/html/includes/graphs/application/ntpdserver_buffer.inc.php @@ -1,34 +1,31 @@ array('descr' => 'Received'), - 'buffer_used' => array('descr' => 'Used'), - 'buffer_free' => array('descr' => 'Free') - ); + 'buffer_recv' => array('descr' => 'Received'), + 'buffer_used' => array('descr' => 'Used'), + 'buffer_free' => array('descr' => 'Free'), + ); -$i = 0; +$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'] = $config['graph_colours'][$colours][$i]; - $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'] = $config['graph_colours'][$colours][$i]; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/ntpdserver_freq.inc.php b/html/includes/graphs/application/ntpdserver_freq.inc.php index f74fc0d09..13f64c295 100644 --- a/html/includes/graphs/application/ntpdserver_freq.inc.php +++ b/html/includes/graphs/application/ntpdserver_freq.inc.php @@ -1,21 +1,18 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/ntpdserver_packets.inc.php b/html/includes/graphs/application/ntpdserver_packets.inc.php index 780039700..b3d906aa3 100644 --- a/html/includes/graphs/application/ntpdserver_packets.inc.php +++ b/html/includes/graphs/application/ntpdserver_packets.inc.php @@ -1,34 +1,36 @@ 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; +$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"; } -// include("includes/graphs/generic_multi_line.inc.php"); - -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); - -?> +// include("includes/graphs/generic_multi_line.inc.php"); +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/ntpdserver_stats.inc.php b/html/includes/graphs/application/ntpdserver_stats.inc.php index 70e129557..e6d79d292 100644 --- a/html/includes/graphs/application/ntpdserver_stats.inc.php +++ b/html/includes/graphs/application/ntpdserver_stats.inc.php @@ -1,34 +1,31 @@ array('descr' => 'Offset'), - 'jitter' => array('descr' => 'Jitter'), - 'noise' => array('descr' => 'Noise'), - 'stability' => array('descr' => 'Stability') - ); + 'offset' => array('descr' => 'Offset'), + 'jitter' => array('descr' => 'Jitter'), + 'noise' => array('descr' => 'Noise'), + 'stability' => array('descr' => 'Stability'), + ); -$i = 0; +$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'] = $config['graph_colours'][$colours][$i]; - $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'] = $config['graph_colours'][$colours][$i]; + $i++; + } +} +else { + echo "file missing: $file"; } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/ntpdserver_stratum.inc.php b/html/includes/graphs/application/ntpdserver_stratum.inc.php index e0d59019c..debff062e 100644 --- a/html/includes/graphs/application/ntpdserver_stratum.inc.php +++ b/html/includes/graphs/application/ntpdserver_stratum.inc.php @@ -1,21 +1,18 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/ntpdserver_uptime.inc.php b/html/includes/graphs/application/ntpdserver_uptime.inc.php index 03c94ce8a..e1b007f3d 100644 --- a/html/includes/graphs/application/ntpdserver_uptime.inc.php +++ b/html/includes/graphs/application/ntpdserver_uptime.inc.php @@ -1,40 +1,37 @@ +$rrd_options .= ' AREA:cuptime#'.$colour_area.':'; +$rrd_options .= ' LINE1.25:cuptime#'.$colour_line.':Uptime'; +$rrd_options .= ' GPRINT:cuptime:LAST:%6.2lf'; +$rrd_options .= ' GPRINT:cuptime:AVERAGE:%6.2lf'; +$rrd_options .= ' GPRINT:cuptime:MAX:%6.2lf'; +$rrd_options .= " GPRINT:cuptime:AVERAGE:%6.2lf\\n"; diff --git a/html/includes/graphs/application/powerdns_fail.inc.php b/html/includes/graphs/application/powerdns_fail.inc.php index a5b92fb65..469b633ac 100644 --- a/html/includes/graphs/application/powerdns_fail.inc.php +++ b/html/includes/graphs/application/powerdns_fail.inc.php @@ -1,34 +1,40 @@ array('descr' => 'Corrupt', 'colour' => 'FF8800FF'), - 'servfailPackets' => array('descr' => 'Failed', 'colour' => 'FF0000FF'), - 'q_timedout' => array('descr' => 'Timedout', 'colour' => 'FFFF00FF'), - ); + 'corruptPackets' => array( + 'descr' => 'Corrupt', + 'colour' => 'FF8800FF', + ), + 'servfailPackets' => array( + 'descr' => 'Failed', + 'colour' => 'FF0000FF', + ), + 'q_timedout' => array( + 'descr' => 'Timedout', + 'colour' => 'FFFF00FF', + ), + ); -$i = 0; +$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"; } -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/powerdns_latency.inc.php b/html/includes/graphs/application/powerdns_latency.inc.php index fb8ceb5ff..5e716a8dc 100644 --- a/html/includes/graphs/application/powerdns_latency.inc.php +++ b/html/includes/graphs/application/powerdns_latency.inc.php @@ -1,21 +1,18 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/application/powerdns_packetcache.inc.php b/html/includes/graphs/application/powerdns_packetcache.inc.php index 13f574b4a..abd3297cc 100644 --- a/html/includes/graphs/application/powerdns_packetcache.inc.php +++ b/html/includes/graphs/application/powerdns_packetcache.inc.php @@ -1,34 +1,40 @@ array('descr' => 'Hits', 'colour' => '008800FF'), - 'pc_miss' => array('descr' => 'Misses', 'colour' => '880000FF'), - 'pc_size' => array('descr' => 'Size', 'colour' => '006699FF'), - ); + 'pc_hit' => array( + 'descr' => 'Hits', + 'colour' => '008800FF', + ), + 'pc_miss' => array( + 'descr' => 'Misses', + 'colour' => '880000FF', + ), + 'pc_size' => array( + 'descr' => 'Size', + 'colour' => '006699FF', + ), + ); -$i = 0; +$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"; } -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/powerdns_queries.inc.php b/html/includes/graphs/application/powerdns_queries.inc.php index 71b2a0be0..49f5b8d20 100644 --- a/html/includes/graphs/application/powerdns_queries.inc.php +++ b/html/includes/graphs/application/powerdns_queries.inc.php @@ -1,35 +1,44 @@ array('descr' => 'TCP Answers', 'colour' => '008800FF'), - 'q_tcpQueries' => array('descr' => 'TCP Queries', 'colour' => '00FF00FF'), - 'q_udpAnswers' => array('descr' => 'UDP Answers', 'colour' => '336699FF'), - 'q_udpQueries' => array('descr' => 'UDP Queries', 'colour' => '6699CCFF'), - ); + 'q_tcpAnswers' => array( + 'descr' => 'TCP Answers', + 'colour' => '008800FF', + ), + 'q_tcpQueries' => array( + 'descr' => 'TCP Queries', + 'colour' => '00FF00FF', + ), + 'q_udpAnswers' => array( + 'descr' => 'UDP Answers', + 'colour' => '336699FF', + ), + 'q_udpQueries' => array( + 'descr' => 'UDP Queries', + 'colour' => '6699CCFF', + ), + ); -$i = 0; +$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"; } -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/powerdns_queries_udp.inc.php b/html/includes/graphs/application/powerdns_queries_udp.inc.php index ef2b6afd7..e680f72da 100644 --- a/html/includes/graphs/application/powerdns_queries_udp.inc.php +++ b/html/includes/graphs/application/powerdns_queries_udp.inc.php @@ -1,35 +1,44 @@ array('descr' => 'UDP4 Answers', 'colour' => '00008888'), - 'q_udp4Queries' => array('descr' => 'UDP4 Queries', 'colour' => '000088FF'), - 'q_udp6Answers' => array('descr' => 'UDP6 Answers', 'colour' => '88000088'), - 'q_udp6Queries' => array('descr' => 'UDP6 Queries', 'colour' => '880000FF'), - ); + 'q_udp4Answers' => array( + 'descr' => 'UDP4 Answers', + 'colour' => '00008888', + ), + 'q_udp4Queries' => array( + 'descr' => 'UDP4 Queries', + 'colour' => '000088FF', + ), + 'q_udp6Answers' => array( + 'descr' => 'UDP6 Answers', + 'colour' => '88000088', + ), + 'q_udp6Queries' => array( + 'descr' => 'UDP6 Queries', + 'colour' => '880000FF', + ), + ); -$i = 0; +$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"; } -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/powerdns_querycache.inc.php b/html/includes/graphs/application/powerdns_querycache.inc.php index 1ad4f3821..694bb88f7 100644 --- a/html/includes/graphs/application/powerdns_querycache.inc.php +++ b/html/includes/graphs/application/powerdns_querycache.inc.php @@ -1,33 +1,36 @@ array('descr' => 'Misses', 'colour' => '750F7DFF'), - 'qc_hit' => array('descr' => 'Hits', 'colour' => '00FF00FF'), - ); + 'qc_miss' => array( + 'descr' => 'Misses', + 'colour' => '750F7DFF', + ), + 'qc_hit' => array( + 'descr' => 'Hits', + 'colour' => '00FF00FF', + ), + ); -$i = 0; +$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"; } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/powerdns_recursing.inc.php b/html/includes/graphs/application/powerdns_recursing.inc.php index 758b3ee23..32a94799a 100644 --- a/html/includes/graphs/application/powerdns_recursing.inc.php +++ b/html/includes/graphs/application/powerdns_recursing.inc.php @@ -1,33 +1,36 @@ array('descr' => 'Questions', 'colour' => '6699CCFF'), - 'rec_answers' => array('descr' => 'Answers', 'colour' => '336699FF'), - ); + 'rec_questions' => array( + 'descr' => 'Questions', + 'colour' => '6699CCFF', + ), + 'rec_answers' => array( + 'descr' => 'Answers', + 'colour' => '336699FF', + ), + ); -$i = 0; +$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"; } -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/application/shoutcast_bits.inc.php b/html/includes/graphs/application/shoutcast_bits.inc.php index e1ac058d8..020ce76b9 100644 --- a/html/includes/graphs/application/shoutcast_bits.inc.php +++ b/html/includes/graphs/application/shoutcast_bits.inc.php @@ -1,27 +1,25 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/application/shoutcast_multi_bits.inc.php b/html/includes/graphs/application/shoutcast_multi_bits.inc.php index 3d9ba7d70..d526863ae 100644 --- a/html/includes/graphs/application/shoutcast_multi_bits.inc.php +++ b/html/includes/graphs/application/shoutcast_multi_bits.inc.php @@ -2,55 +2,48 @@ $device = device_by_id_cache($vars['id']); -$units = "b"; -$total_units = "B"; -$colours_in = "greens"; -$multiplier = "8"; -$colours_out = "blues"; +$units = 'b'; +$total_units = 'B'; +$colours_in = 'greens'; +$multiplier = '8'; +$colours_out = 'blues'; -$nototal = 1; +$nototal = 1; -$ds_in = "traf_in"; -$ds_out = "traf_out"; +$ds_in = 'traf_in'; +$ds_out = 'traf_out'; -$graph_title = "Traffic Statistic"; +$graph_title = 'Traffic Statistic'; -$colour_line_in = "006600"; -$colour_line_out = "000099"; -$colour_area_in = "CDEB8B"; -$colour_area_out = "C3D9FF"; +$colour_line_in = '006600'; +$colour_line_out = '000099'; +$colour_area_in = 'CDEB8B'; +$colour_area_out = 'C3D9FF'; -$rrddir = $config['rrd_dir']."/".$device['hostname']; -$files = array(); -$i = 0; +$rrddir = $config['rrd_dir'].'/'.$device['hostname']; +$files = array(); +$i = 0; -if ($handle = opendir($rrddir)) -{ - while (false !== ($file = readdir($handle))) - { - if ($file != "." && $file != "..") - { - if (eregi("app-shoutcast-".$app['app_id'], $file)) - { - array_push($files, $file); - } +if ($handle = opendir($rrddir)) { + while (false !== ($file = readdir($handle))) { + if ($file != '.' && $file != '..') { + if (eregi('app-shoutcast-'.$app['app_id'], $file)) { + array_push($files, $file); + } + } } - } } -foreach ($files as $id => $file) -{ - $hostname = eregi_replace('app-shoutcast-'.$app['app_id'].'-', '', $file); - $hostname = eregi_replace('.rrd', '', $hostname); - list($host, $port) = split('_', $hostname, 2); - $rrd_filenames[] = $rrddir."/".$file; - $rrd_list[$i]['filename'] = $rrddir."/".$file; - $rrd_list[$i]['descr'] = $host.":".$port; - $rrd_list[$i]['ds_in'] = $ds_in; - $rrd_list[$i]['ds_out'] = $ds_out; - $i++; +foreach ($files as $id => $file) { + $hostname = eregi_replace('app-shoutcast-'.$app['app_id'].'-', '', $file); + $hostname = eregi_replace('.rrd', '', $hostname); + list($host, $port) = split('_', $hostname, 2); + $rrd_filenames[] = $rrddir.'/'.$file; + $rrd_list[$i]['filename'] = $rrddir.'/'.$file; + $rrd_list[$i]['descr'] = $host.':'.$port; + $rrd_list[$i]['ds_in'] = $ds_in; + $rrd_list[$i]['ds_out'] = $ds_out; + $i++; } -include("includes/graphs/generic_multi_bits_separated.inc.php"); - -?> +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/application/shoutcast_multi_stats.inc.php b/html/includes/graphs/application/shoutcast_multi_stats.inc.php index e0345a95b..ea01630bf 100644 --- a/html/includes/graphs/application/shoutcast_multi_stats.inc.php +++ b/html/includes/graphs/application/shoutcast_multi_stats.inc.php @@ -2,103 +2,105 @@ $device = device_by_id_cache($vars['id']); -//$colour = "random"; -$unit_text = "ShoutCast Server"; -$total_text = "Total of all ShoutCast Servers"; +// $colour = "random"; +$unit_text = 'ShoutCast Server'; +$total_text = 'Total of all ShoutCast Servers'; $nototal = 0; -$rrddir = $config['rrd_dir']."/".$device['hostname']; -$files = array(); -$i = 0; -$x = 0; +$rrddir = $config['rrd_dir'].'/'.$device['hostname']; +$files = array(); +$i = 0; +$x = 0; -if ($handle = opendir($rrddir)) -{ - while (false !== ($file = readdir($handle))) - { - if ($file != "." && $file != "..") - { - if (eregi("app-shoutcast-".$app['app_id'], $file)) - { - array_push($files, $file); - } +if ($handle = opendir($rrddir)) { + while (false !== ($file = readdir($handle))) { + if ($file != '.' && $file != '..') { + if (eregi('app-shoutcast-'.$app['app_id'], $file)) { + array_push($files, $file); + } + } } - } } -foreach ($files as $id => $file) -{ - $hostname = eregi_replace('app-shoutcast-'.$app['app_id'].'-', '', $file); - $hostname = eregi_replace('.rrd', '', $hostname); - list($host, $port) = split('_', $hostname, 2); - $rrd_filenames[] = $rrddir."/".$file; - $rrd_list[$i]['filename'] = $rrddir."/".$file; - $rrd_list[$i]['descr'] = $host.":".$port; - $rrd_list[$i]['colour'] = $colour; - $i++; +foreach ($files as $id => $file) { + $hostname = eregi_replace('app-shoutcast-'.$app['app_id'].'-', '', $file); + $hostname = eregi_replace('.rrd', '', $hostname); + list($host, $port) = split('_', $hostname, 2); + $rrd_filenames[] = $rrddir.'/'.$file; + $rrd_list[$i]['filename'] = $rrddir.'/'.$file; + $rrd_list[$i]['descr'] = $host.':'.$port; + $rrd_list[$i]['colour'] = $colour; + $i++; } -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -if ($width > "500") -{ - $descr_len = 38; -} else { - $descr_len = 8; - $descr_len += round(($width - 250) / 8); +if ($width > '500') { + $descr_len = 38; +} +else { + $descr_len = 8; + $descr_len += round(($width - 250) / 8); } -if ($width > "500") -{ - $rrd_options .= " COMMENT:\"".substr(str_pad($unit_text, $descr_len+2), 0, $descr_len+2)." Current Unique Average Peak\\n\""; -} else { - $rrd_options .= " COMMENT:\"".substr(str_pad($unit_text, $descr_len+5), 0, $descr_len+5)." Now Unique Average Peak\\n\""; +if ($width > '500') { + $rrd_options .= ' COMMENT:"'.substr(str_pad($unit_text, ($descr_len + 2)), 0, ($descr_len + 2))." Current Unique Average Peak\\n\""; +} +else { + $rrd_options .= ' COMMENT:"'.substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." Now Unique Average Peak\\n\""; } -foreach ($rrd_list as $rrd) -{ - $colours = (isset($rrd['colour']) ? $rrd['colour'] : "default"); - $strlen = ((strlen($rrd['descr'])<$descr_len) ? ($descr_len - strlen($rrd['descr'])) : "0"); - $descr = (isset($rrd['descr']) ? rrdtool_escape($rrd['descr'], $desc_len+$strlen) : "Unkown"); - for ($z=0; $z<$strlen; $z++) { $descr .= " "; } - if ($i) { $stack = "STACK"; } +foreach ($rrd_list as $rrd) { + $colours = (isset($rrd['colour']) ? $rrd['colour'] : 'default'); + $strlen = ((strlen($rrd['descr']) < $descr_len) ? ($descr_len - strlen($rrd['descr'])) : '0'); + $descr = (isset($rrd['descr']) ? rrdtool_escape($rrd['descr'], ($desc_len + $strlen)) : 'Unkown'); + for ($z = 0; $z < $strlen; + $z++) { + $descr .= ' '; + } + + if ($i) { + $stack = 'STACK'; + } + $colour = $config['graph_colours'][$colours][$x]; - $rrd_options .= " DEF:cur".$x."=".$rrd['filename'].":current:AVERAGE"; - $rrd_options .= " DEF:peak".$x."=".$rrd['filename'].":peak:MAX"; - $rrd_options .= " DEF:unique".$x."=".$rrd['filename'].":unique:AVERAGE"; - $rrd_options .= " VDEF:avg".$x."=cur".$x.",AVERAGE"; - $rrd_options .= " AREA:cur".$x."#".$colour.":\"".$descr."\":$stack"; - $rrd_options .= " GPRINT:cur".$x.":LAST:\"%6.2lf\""; - $rrd_options .= " GPRINT:unique".$x.":LAST:\"%6.2lf%s\""; - $rrd_options .= " GPRINT:avg".$x.":\"%6.2lf\""; - $rrd_options .= " GPRINT:peak".$x.":LAST:\"%6.2lf\""; + $rrd_options .= ' DEF:cur'.$x.'='.$rrd['filename'].':current:AVERAGE'; + $rrd_options .= ' DEF:peak'.$x.'='.$rrd['filename'].':peak:MAX'; + $rrd_options .= ' DEF:unique'.$x.'='.$rrd['filename'].':unique:AVERAGE'; + $rrd_options .= ' VDEF:avg'.$x.'=cur'.$x.',AVERAGE'; + $rrd_options .= ' AREA:cur'.$x.'#'.$colour.':"'.$descr."\":$stack"; + $rrd_options .= ' GPRINT:cur'.$x.':LAST:"%6.2lf"'; + $rrd_options .= ' GPRINT:unique'.$x.':LAST:"%6.2lf%s"'; + $rrd_options .= ' GPRINT:avg'.$x.':"%6.2lf"'; + $rrd_options .= ' GPRINT:peak'.$x.':LAST:"%6.2lf"'; $rrd_options .= " COMMENT:\"\\n\""; - if ($x) - { - $totcur .= ",cur".$x.",+"; - $totpeak .= ",peak".$x.",+"; - $totunique .= ",unique".$x.",+"; + if ($x) { + $totcur .= ',cur'.$x.',+'; + $totpeak .= ',peak'.$x.',+'; + $totunique .= ',unique'.$x.',+'; } - $x = (($x +if (!$nototal) { + $strlen = ((strlen($total_text) < $descr_len) ? ($descr_len - strlen($total_text)) : '0'); + $descr = (isset($total_text) ? rrdtool_escape($total_text, ($desc_len + $strlen)) : 'Total'); + $colour = $config['graph_colours'][$colours][$x]; + for ($z = 0; $z < $strlen; + $z++) { + $descr .= ' '; + } + + $rrd_options .= ' CDEF:totcur=cur0'.$totcur; + $rrd_options .= ' CDEF:totunique=unique0'.$totunique; + $rrd_options .= ' CDEF:totpeak=peak0'.$totpeak; + $rrd_options .= ' VDEF:totavg=totcur,AVERAGE'; + $rrd_options .= ' LINE2:totcur#'.$colour.':"'.$descr.'"'; + $rrd_options .= ' GPRINT:totcur:LAST:"%6.2lf"'; + $rrd_options .= ' GPRINT:totunique:LAST:"%6.2lf%s"'; + $rrd_options .= ' GPRINT:totavg:"%6.2lf"'; + $rrd_options .= ' GPRINT:totpeak:LAST:"%6.2lf"'; + $rrd_options .= " COMMENT:\"\\n\""; +} diff --git a/html/includes/graphs/application/shoutcast_stats.inc.php b/html/includes/graphs/application/shoutcast_stats.inc.php index c383fc5ca..15f1e654a 100644 --- a/html/includes/graphs/application/shoutcast_stats.inc.php +++ b/html/includes/graphs/application/shoutcast_stats.inc.php @@ -1,45 +1,43 @@ = 355) -{ - $rrd_options .= " GPRINT:cur:LAST:\"\:%8.2lf\""; - $rrd_options .= " GPRINT:max:LAST:\"from%8.2lf\""; - $rrd_options .= " GPRINT:bitrate:LAST:\"(bitrate\:%8.2lf%s\""; - $rrd_options .= " COMMENT:\")\\n\""; -} else { - $rrd_options .= " GPRINT:cur:LAST:\"\:%8.2lf\\n\""; +if ($width >= 355) { + $rrd_options .= ' GPRINT:cur:LAST:"\:%8.2lf"'; + $rrd_options .= ' GPRINT:max:LAST:"from%8.2lf"'; + $rrd_options .= ' GPRINT:bitrate:LAST:"(bitrate\:%8.2lf%s"'; + $rrd_options .= " COMMENT:\")\\n\""; +} +else { + $rrd_options .= " GPRINT:cur:LAST:\"\:%8.2lf\\n\""; } -$rrd_options .= " AREA:unique#AADEFEFF:\"Unique Listeners \""; +$rrd_options .= ' AREA:unique#AADEFEFF:"Unique Listeners "'; $rrd_options .= " GPRINT:unique:LAST:\"\:%8.2lf%s\\n\""; -$rrd_options .= " HRULE:avg#FF9000FF:\"Average Listeners\""; +$rrd_options .= ' HRULE:avg#FF9000FF:"Average Listeners"'; $rrd_options .= " GPRINT:avg:\"\:%8.2lf\\n\""; -$rrd_options .= " LINE1:peak#C000FFFF:\"Peak Listeners \""; +$rrd_options .= ' LINE1:peak#C000FFFF:"Peak Listeners "'; $rrd_options .= " GPRINT:peak:LAST:\"\:%8.2lf\\n\""; $rrd_options .= " TICK:stream_offline#B4FF00FF:1.0:\"Streaming client offline\\n\""; -$rrd_options .= " TICK:server_offline".$warn_colour_b."FF:1.0:\"Streaming server offline\""; - -?> +$rrd_options .= ' TICK:server_offline'.$warn_colour_b.'FF:1.0:"Streaming server offline"'; diff --git a/html/includes/graphs/application/tinydns_dnssec.inc.php b/html/includes/graphs/application/tinydns_dnssec.inc.php index 14b4c8136..a3a0bf110 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 6cec421c9..5673c635e 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 b7c08f88e..3d4178994 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 2d2b03ebe..b35a32bc0 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/atmvp/auth.inc.php b/html/includes/graphs/atmvp/auth.inc.php index b307266b6..caf963e38 100644 --- a/html/includes/graphs/atmvp/auth.inc.php +++ b/html/includes/graphs/atmvp/auth.inc.php @@ -1,18 +1,17 @@ +$vp = dbFetchRow('SELECT * FROM `juniAtmVp` as J, `ports` AS I, `devices` AS D WHERE J.juniAtmVp_id = ? AND I.port_id = J.port_id AND I.device_id = D.device_id', array($atm_vp_id)); + +if ($auth || port_permitted($vp['port_id'])) { + $port = $vp; + $device = device_by_id_cache($port['device_id']); + $title = generate_device_link($device); + $title .= ' :: Port '.generate_port_link($port); + $title .= ' :: VP '.$vp['vp_id']; + $auth = true; + $rrd_filename = $config['rrd_dir'].'/'.$vp['hostname'].'/'.safename('vp-'.$vp['ifIndex'].'-'.$vp['vp_id'].'.rrd'); +} diff --git a/html/includes/graphs/atmvp/bits.inc.php b/html/includes/graphs/atmvp/bits.inc.php index a571ec7ed..f158d9c7a 100644 --- a/html/includes/graphs/atmvp/bits.inc.php +++ b/html/includes/graphs/atmvp/bits.inc.php @@ -1,8 +1,6 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/atmvp/cells.inc.php b/html/includes/graphs/atmvp/cells.inc.php index dc4387f58..36d067b6c 100644 --- a/html/includes/graphs/atmvp/cells.inc.php +++ b/html/includes/graphs/atmvp/cells.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/atmvp/errors.inc.php b/html/includes/graphs/atmvp/errors.inc.php index 7035a5385..b36562f58 100644 --- a/html/includes/graphs/atmvp/errors.inc.php +++ b/html/includes/graphs/atmvp/errors.inc.php @@ -1,20 +1,18 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/atmvp/packets.inc.php b/html/includes/graphs/atmvp/packets.inc.php index 34c5b8c93..fbfc62797 100644 --- a/html/includes/graphs/atmvp/packets.inc.php +++ b/html/includes/graphs/atmvp/packets.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/bgp/auth.inc.php b/html/includes/graphs/bgp/auth.inc.php index 96d999555..79ab1be2c 100644 --- a/html/includes/graphs/bgp/auth.inc.php +++ b/html/includes/graphs/bgp/auth.inc.php @@ -1,18 +1,13 @@ diff --git a/html/includes/graphs/bgp/prefixes.inc.php b/html/includes/graphs/bgp/prefixes.inc.php index 7a6170b36..db9290fb2 100644 --- a/html/includes/graphs/bgp/prefixes.inc.php +++ b/html/includes/graphs/bgp/prefixes.inc.php @@ -1,18 +1,16 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/bgp/prefixes_ipv4multicast.inc.php b/html/includes/graphs/bgp/prefixes_ipv4multicast.inc.php index 77dede1ba..8f2cfe54d 100644 --- a/html/includes/graphs/bgp/prefixes_ipv4multicast.inc.php +++ b/html/includes/graphs/bgp/prefixes_ipv4multicast.inc.php @@ -1,7 +1,5 @@ +require 'includes/graphs/bgp/prefixes.inc.php'; diff --git a/html/includes/graphs/bgp/prefixes_ipv4unicast.inc.php b/html/includes/graphs/bgp/prefixes_ipv4unicast.inc.php index 4efdd65be..6fbfa01cc 100644 --- a/html/includes/graphs/bgp/prefixes_ipv4unicast.inc.php +++ b/html/includes/graphs/bgp/prefixes_ipv4unicast.inc.php @@ -1,7 +1,5 @@ +require 'includes/graphs/bgp/prefixes.inc.php'; diff --git a/html/includes/graphs/bgp/prefixes_ipv4vpn.inc.php b/html/includes/graphs/bgp/prefixes_ipv4vpn.inc.php index 810b3525e..9ff56248e 100644 --- a/html/includes/graphs/bgp/prefixes_ipv4vpn.inc.php +++ b/html/includes/graphs/bgp/prefixes_ipv4vpn.inc.php @@ -1,7 +1,5 @@ +require 'includes/graphs/bgp/prefixes.inc.php'; diff --git a/html/includes/graphs/bgp/prefixes_ipv6multicast.inc.php b/html/includes/graphs/bgp/prefixes_ipv6multicast.inc.php index d6dc8d14a..8ed9bc649 100644 --- a/html/includes/graphs/bgp/prefixes_ipv6multicast.inc.php +++ b/html/includes/graphs/bgp/prefixes_ipv6multicast.inc.php @@ -1,7 +1,5 @@ +require 'includes/graphs/bgp/prefixes.inc.php'; diff --git a/html/includes/graphs/bgp/prefixes_ipv6unicast.inc.php b/html/includes/graphs/bgp/prefixes_ipv6unicast.inc.php index f902af499..f1b6a49ad 100644 --- a/html/includes/graphs/bgp/prefixes_ipv6unicast.inc.php +++ b/html/includes/graphs/bgp/prefixes_ipv6unicast.inc.php @@ -1,7 +1,5 @@ +require 'includes/graphs/bgp/prefixes.inc.php'; diff --git a/html/includes/graphs/bgp/prefixes_ipv6vpn.inc.php b/html/includes/graphs/bgp/prefixes_ipv6vpn.inc.php index 633d06aaf..730f66d31 100644 --- a/html/includes/graphs/bgp/prefixes_ipv6vpn.inc.php +++ b/html/includes/graphs/bgp/prefixes_ipv6vpn.inc.php @@ -1,7 +1,5 @@ +require 'includes/graphs/bgp/prefixes.inc.php'; diff --git a/html/includes/graphs/bgp/updates.inc.php b/html/includes/graphs/bgp/updates.inc.php index 04d8f44b2..2458a453b 100644 --- a/html/includes/graphs/bgp/updates.inc.php +++ b/html/includes/graphs/bgp/updates.inc.php @@ -1,24 +1,22 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/bill/auth.inc.php b/html/includes/graphs/bill/auth.inc.php index af4363b57..524082501 100644 --- a/html/includes/graphs/bill/auth.inc.php +++ b/html/includes/graphs/bill/auth.inc.php @@ -1,21 +1,17 @@ diff --git a/html/includes/graphs/bill/bits.inc.php b/html/includes/graphs/bill/bits.inc.php index 55edf988f..2e80ef792 100644 --- a/html/includes/graphs/bill/bits.inc.php +++ b/html/includes/graphs/bill/bits.inc.php @@ -1,41 +1,36 @@ +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/c6kxbar/auth.inc.php b/html/includes/graphs/c6kxbar/auth.inc.php index 96076c92c..57212efb8 100644 --- a/html/includes/graphs/c6kxbar/auth.inc.php +++ b/html/includes/graphs/c6kxbar/auth.inc.php @@ -1,18 +1,14 @@ diff --git a/html/includes/graphs/c6kxbar/util.inc.php b/html/includes/graphs/c6kxbar/util.inc.php index c3b3145a6..dbf8eb8d7 100644 --- a/html/includes/graphs/c6kxbar/util.inc.php +++ b/html/includes/graphs/c6kxbar/util.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/cefswitching/auth.inc.php b/html/includes/graphs/cefswitching/auth.inc.php index d95498efa..3db047851 100644 --- a/html/includes/graphs/cefswitching/auth.inc.php +++ b/html/includes/graphs/cefswitching/auth.inc.php @@ -1,19 +1,15 @@ diff --git a/html/includes/graphs/cefswitching/graph.inc.php b/html/includes/graphs/cefswitching/graph.inc.php index 212dba9c8..5a1b31419 100644 --- a/html/includes/graphs/cefswitching/graph.inc.php +++ b/html/includes/graphs/cefswitching/graph.inc.php @@ -1,28 +1,26 @@ +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 a46b35384..9dbc97b80 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 e279c8691..f66f91df0 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/agent.inc.php b/html/includes/graphs/device/agent.inc.php index da8a233a8..f37f864f9 100644 --- a/html/includes/graphs/device/agent.inc.php +++ b/html/includes/graphs/device/agent.inc.php @@ -2,26 +2,25 @@ $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -$agent_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/agent.rrd"; +$agent_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/agent.rrd'; -if (is_file($agent_rrd)) -{ - $rrd_filename = $agent_rrd; +if (is_file($agent_rrd)) { + $rrd_filename = $agent_rrd; } -$ds = "time"; +$ds = 'time'; -$colour_area = "EEEEEE"; -$colour_line = "36393D"; +$colour_area = 'EEEEEE'; +$colour_line = '36393D'; -$colour_area_max = "FFEE99"; +$colour_area_max = 'FFEE99'; -$graph_max = 1; +$graph_max = 1; +$multiplier = 1000; +$multiplier_action = '/'; -$unit_text = "msec"; +$unit_text = 'Seconds'; -include("includes/graphs/generic_simplex.inc.php"); - -?> +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/arubacontroller_numaps.inc.php b/html/includes/graphs/device/arubacontroller_numaps.inc.php index ea071fc2a..1aa6b2c62 100644 --- a/html/includes/graphs/device/arubacontroller_numaps.inc.php +++ b/html/includes/graphs/device/arubacontroller_numaps.inc.php @@ -1,22 +1,20 @@ diff --git a/html/includes/graphs/device/arubacontroller_numclients.inc.php b/html/includes/graphs/device/arubacontroller_numclients.inc.php index 6b7669c18..e86b4d758 100644 --- a/html/includes/graphs/device/arubacontroller_numclients.inc.php +++ b/html/includes/graphs/device/arubacontroller_numclients.inc.php @@ -1,26 +1,21 @@ diff --git a/html/includes/graphs/device/asa_conns.inc.php b/html/includes/graphs/device/asa_conns.inc.php index 5ac548631..a30e216ed 100644 --- a/html/includes/graphs/device/asa_conns.inc.php +++ b/html/includes/graphs/device/asa_conns.inc.php @@ -10,23 +10,20 @@ * 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 79027e7bf..1ed6b7b33 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 64d4c0398..eaeed92f4 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 237803fa8..66c6ed5ae 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_bits.inc.php b/html/includes/graphs/device/cipsec_flow_bits.inc.php index 7d19dafbb..861c01252 100644 --- a/html/includes/graphs/device/cipsec_flow_bits.inc.php +++ b/html/includes/graphs/device/cipsec_flow_bits.inc.php @@ -1,10 +1,8 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/device/cipsec_flow_pkts.inc.php b/html/includes/graphs/device/cipsec_flow_pkts.inc.php index 639dcbef8..526b02011 100644 --- a/html/includes/graphs/device/cipsec_flow_pkts.inc.php +++ b/html/includes/graphs/device/cipsec_flow_pkts.inc.php @@ -1,21 +1,19 @@ \ No newline at end of file +require 'includes/graphs/generic_duplex.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 2e69d2a79..e721b722f 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/cipsec_flow_tunnels.inc.php b/html/includes/graphs/device/cipsec_flow_tunnels.inc.php index e1e77f7a1..f45a73736 100644 --- a/html/includes/graphs/device/cipsec_flow_tunnels.inc.php +++ b/html/includes/graphs/device/cipsec_flow_tunnels.inc.php @@ -1,15 +1,13 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/collectd.inc.php b/html/includes/graphs/device/collectd.inc.php index 05ce8b3cb..7de642433 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/cras_sessions.inc.php b/html/includes/graphs/device/cras_sessions.inc.php index 90ae4b539..9feeefa25 100644 --- a/html/includes/graphs/device/cras_sessions.inc.php +++ b/html/includes/graphs/device/cras_sessions.inc.php @@ -1,10 +1,10 @@ diff --git a/html/includes/graphs/device/current.inc.php b/html/includes/graphs/device/current.inc.php index 4fb096550..23f8ef43e 100644 --- a/html/includes/graphs/device/current.inc.php +++ b/html/includes/graphs/device/current.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/dbm.inc.php b/html/includes/graphs/device/dbm.inc.php index 6243f739b..3c2fda3dc 100644 --- a/html/includes/graphs/device/dbm.inc.php +++ b/html/includes/graphs/device/dbm.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/diskio.inc.php b/html/includes/graphs/device/diskio.inc.php index 6fb4fa419..58f751509 100644 --- a/html/includes/graphs/device/diskio.inc.php +++ b/html/includes/graphs/device/diskio.inc.php @@ -1,5 +1,3 @@ \ No newline at end of file +require 'diskio_ops.inc.php'; diff --git a/html/includes/graphs/device/diskio_bits.inc.php b/html/includes/graphs/device/diskio_bits.inc.php index 32f61ffe4..efe305efd 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_common.inc.php b/html/includes/graphs/device/diskio_common.inc.php index 36b0b56f2..2fbb00336 100644 --- a/html/includes/graphs/device/diskio_common.inc.php +++ b/html/includes/graphs/device/diskio_common.inc.php @@ -2,17 +2,13 @@ $i = 1; -foreach (dbFetchRows("SELECT * FROM `ucd_diskio` AS U, `devices` AS D WHERE D.device_id = ? AND U.device_id = D.device_id", array($device['device_id'])) as $disk) -{ - $rrd_filename = $config['rrd_dir'] . "/" . $disk['hostname'] . "/ucd_diskio-" . safename($disk['diskio_descr'] . ".rrd"); - if (is_file($rrd_filename)) - { - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = $disk['diskio_descr']; - $rrd_list[$i]['ds_in'] = $ds_in; - $rrd_list[$i]['ds_out'] = $ds_out; - $i++; - } +foreach (dbFetchRows('SELECT * FROM `ucd_diskio` AS U, `devices` AS D WHERE D.device_id = ? AND U.device_id = D.device_id', array($device['device_id'])) as $disk) { + $rrd_filename = $config['rrd_dir'].'/'.$disk['hostname'].'/ucd_diskio-'.safename($disk['diskio_descr'].'.rrd'); + if (is_file($rrd_filename)) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $disk['diskio_descr']; + $rrd_list[$i]['ds_in'] = $ds_in; + $rrd_list[$i]['ds_out'] = $ds_out; + $i++; + } } - -?> diff --git a/html/includes/graphs/device/diskio_ops.inc.php b/html/includes/graphs/device/diskio_ops.inc.php index 5b1593258..3c788f69f 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/fanspeed.inc.php b/html/includes/graphs/device/fanspeed.inc.php index 7680f3372..21692b1e3 100644 --- a/html/includes/graphs/device/fanspeed.inc.php +++ b/html/includes/graphs/device/fanspeed.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/fdb_count.inc.php b/html/includes/graphs/device/fdb_count.inc.php index 484ac9b89..83dd72186 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/fortigate_cpu.inc.php b/html/includes/graphs/device/fortigate_cpu.inc.php index 4733263f6..d4474641c 100644 --- a/html/includes/graphs/device/fortigate_cpu.inc.php +++ b/html/includes/graphs/device/fortigate_cpu.inc.php @@ -1,20 +1,18 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/fortigate_sessions.inc.php b/html/includes/graphs/device/fortigate_sessions.inc.php index c2bfcef00..18d8f902f 100644 --- a/html/includes/graphs/device/fortigate_sessions.inc.php +++ b/html/includes/graphs/device/fortigate_sessions.inc.php @@ -1,20 +1,18 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/frequency.inc.php b/html/includes/graphs/device/frequency.inc.php index 41cd6a772..d1fdbcb38 100644 --- a/html/includes/graphs/device/frequency.inc.php +++ b/html/includes/graphs/device/frequency.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/hr_processes.inc.php b/html/includes/graphs/device/hr_processes.inc.php index 290f40838..07f451bed 100644 --- a/html/includes/graphs/device/hr_processes.inc.php +++ b/html/includes/graphs/device/hr_processes.inc.php @@ -1,21 +1,19 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/hr_users.inc.php b/html/includes/graphs/device/hr_users.inc.php index a8469e174..6d54484a3 100644 --- a/html/includes/graphs/device/hr_users.inc.php +++ b/html/includes/graphs/device/hr_users.inc.php @@ -1,21 +1,19 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/humidity.inc.php b/html/includes/graphs/device/humidity.inc.php index 58cd7b5bb..078cbc382 100644 --- a/html/includes/graphs/device/humidity.inc.php +++ b/html/includes/graphs/device/humidity.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/ipSystemStats.inc.php b/html/includes/graphs/device/ipSystemStats.inc.php index 0a3048f54..afcbc6cb7 100644 --- a/html/includes/graphs/device/ipSystemStats.inc.php +++ b/html/includes/graphs/device/ipSystemStats.inc.php @@ -1,9 +1,9 @@ diff --git a/html/includes/graphs/device/ipsystemstats_ipv4.inc.php b/html/includes/graphs/device/ipsystemstats_ipv4.inc.php index edda01e76..8c280d376 100644 --- a/html/includes/graphs/device/ipsystemstats_ipv4.inc.php +++ b/html/includes/graphs/device/ipsystemstats_ipv4.inc.php @@ -1,8 +1,8 @@ +$rrd_options .= ' LINE1.25:InReceives#9DaB6B:'; +$rrd_options .= ' LINE1.25:OutRequests_n#93a6eF:'; diff --git a/html/includes/graphs/device/ipsystemstats_ipv4_frag.inc.php b/html/includes/graphs/device/ipsystemstats_ipv4_frag.inc.php index a4e5344cf..c59fd3780 100644 --- a/html/includes/graphs/device/ipsystemstats_ipv4_frag.inc.php +++ b/html/includes/graphs/device/ipsystemstats_ipv4_frag.inc.php @@ -1,8 +1,8 @@ diff --git a/html/includes/graphs/device/ipsystemstats_ipv6.inc.php b/html/includes/graphs/device/ipsystemstats_ipv6.inc.php index 57cedb29d..1542b14b5 100644 --- a/html/includes/graphs/device/ipsystemstats_ipv6.inc.php +++ b/html/includes/graphs/device/ipsystemstats_ipv6.inc.php @@ -1,8 +1,8 @@ +$rrd_options .= ' LINE1.25:InReceives#9DaB6B:'; +$rrd_options .= ' LINE1.25:OutRequests_n#93a6eF:'; diff --git a/html/includes/graphs/device/ipsystemstats_ipv6_frag.inc.php b/html/includes/graphs/device/ipsystemstats_ipv6_frag.inc.php index 2b9912df3..1cb81d47b 100644 --- a/html/includes/graphs/device/ipsystemstats_ipv6_frag.inc.php +++ b/html/includes/graphs/device/ipsystemstats_ipv6_frag.inc.php @@ -1,8 +1,8 @@ diff --git a/html/includes/graphs/device/load.inc.php b/html/includes/graphs/device/load.inc.php index a8b27356c..31a2e9c12 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/mempool.inc.php b/html/includes/graphs/device/mempool.inc.php index ded4c7531..8c8fba677 100644 --- a/html/includes/graphs/device/mempool.inc.php +++ b/html/includes/graphs/device/mempool.inc.php @@ -1,40 +1,57 @@ +$rrd_options .= ' HRULE:0#999999'; diff --git a/html/includes/graphs/device/mib.inc.php b/html/includes/graphs/device/mib.inc.php index 7f76f3bbe..08241e922 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/netscaler_tcp_bits.inc.php b/html/includes/graphs/device/netscaler_tcp_bits.inc.php index c2bfa177f..401e25f66 100644 --- a/html/includes/graphs/device/netscaler_tcp_bits.inc.php +++ b/html/includes/graphs/device/netscaler_tcp_bits.inc.php @@ -1,12 +1,10 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/device/netscaler_tcp_conn.inc.php b/html/includes/graphs/device/netscaler_tcp_conn.inc.php index 06edbde3d..2e18e777e 100644 --- a/html/includes/graphs/device/netscaler_tcp_conn.inc.php +++ b/html/includes/graphs/device/netscaler_tcp_conn.inc.php @@ -1,24 +1,22 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/device/netscaler_tcp_pkts.inc.php b/html/includes/graphs/device/netscaler_tcp_pkts.inc.php index e95b000f9..ae3015c24 100644 --- a/html/includes/graphs/device/netscaler_tcp_pkts.inc.php +++ b/html/includes/graphs/device/netscaler_tcp_pkts.inc.php @@ -1,21 +1,19 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/device/netstat_icmp.inc.php b/html/includes/graphs/device/netstat_icmp.inc.php index c84409fac..d44b2e320 100644 --- a/html/includes/graphs/device/netstat_icmp.inc.php +++ b/html/includes/graphs/device/netstat_icmp.inc.php @@ -1,36 +1,34 @@ '00cc00', - 'icmpOutMsgs' => '006600', - 'icmpInErrors' => 'cc0000', - 'icmpOutErrors' => '660000', - 'icmpInEchos' => '0066cc', - 'icmpOutEchos' => '003399', - 'icmpInEchoReps' => 'cc00cc', - 'icmpOutEchoReps' => '990099'); +$stats = array( + 'icmpInMsgs' => '00cc00', + 'icmpOutMsgs' => '006600', + 'icmpInErrors' => 'cc0000', + 'icmpOutErrors' => '660000', + 'icmpInEchos' => '0066cc', + 'icmpOutEchos' => '003399', + 'icmpInEchoReps' => 'cc00cc', + 'icmpOutEchoReps' => '990099', +); -$i=0; +$i = 0; -foreach ($stats as $stat => $colour) -{ - $i++; - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = str_replace("icmp", "", $stat); - $rrd_list[$i]['ds'] = $stat; - if (strpos($stat, "Out") !== FALSE) - { - $rrd_list[$i]['invert'] = TRUE; - } +foreach ($stats as $stat => $colour) { + $i++; + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = str_replace('icmp', '', $stat); + $rrd_list[$i]['ds'] = $stat; + if (strpos($stat, 'Out') !== false) { + $rrd_list[$i]['invert'] = true; + } } -$colours='mixed'; +$colours = 'mixed'; -$scale_min = "0"; -$nototal = 1; -$simple_rrd = TRUE; +$scale_min = '0'; +$nototal = 1; +$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_icmp_info.inc.php b/html/includes/graphs/device/netstat_icmp_info.inc.php index 9d029320a..38ab1e719 100644 --- a/html/includes/graphs/device/netstat_icmp_info.inc.php +++ b/html/includes/graphs/device/netstat_icmp_info.inc.php @@ -1,36 +1,34 @@ array(), - 'icmpOutSrcQuenchs' => array(), - 'icmpInRedirects' => array(), - 'icmpOutRedirects' => array(), - 'icmpInAddrMasks' => array(), - 'icmpOutAddrMasks' => array(), - 'icmpInAddrMaskReps' => array(), - 'icmpOutAddrMaskReps' => array()); +$stats = array( + 'icmpInSrcQuenchs' => array(), + 'icmpOutSrcQuenchs' => array(), + 'icmpInRedirects' => array(), + 'icmpOutRedirects' => array(), + 'icmpInAddrMasks' => array(), + 'icmpOutAddrMasks' => array(), + 'icmpInAddrMaskReps' => array(), + 'icmpOutAddrMaskReps' => array(), +); -$i=0; +$i = 0; -foreach ($stats as $stat => $array) -{ - $i++; - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = str_replace("icmp", "", $stat); - $rrd_list[$i]['ds'] = $stat; - if (strpos($stat, "Out") !== FALSE) - { - $rrd_list[$i]['invert'] = TRUE; - } +foreach ($stats as $stat => $array) { + $i++; + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = str_replace('icmp', '', $stat); + $rrd_list[$i]['ds'] = $stat; + if (strpos($stat, 'Out') !== false) { + $rrd_list[$i]['invert'] = true; + } } -$colours='mixed'; +$colours = 'mixed'; -$scale_min = "0"; -$nototal = 1; -$simple_rrd = TRUE; +$scale_min = '0'; +$nototal = 1; +$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.inc.php b/html/includes/graphs/device/netstat_ip.inc.php index 35fd810b0..4c0dfad3e 100644 --- a/html/includes/graphs/device/netstat_ip.inc.php +++ b/html/includes/graphs/device/netstat_ip.inc.php @@ -1,34 +1,32 @@ array(), - 'ipInDelivers' => array(), - 'ipInReceives' => array(), - 'ipOutRequests' => array(), - 'ipInDiscards' => array(), - 'ipOutDiscards' => array(), - 'ipOutNoRoutes' => array()); +$stats = array( + 'ipForwDatagrams' => array(), + 'ipInDelivers' => array(), + 'ipInReceives' => array(), + 'ipOutRequests' => array(), + 'ipInDiscards' => array(), + 'ipOutDiscards' => array(), + 'ipOutNoRoutes' => 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; - if (strpos($stat, "Out") !== FALSE) - { - $rrd_list[$i]['invert'] = TRUE; - } +$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; + if (strpos($stat, 'Out') !== false) { + $rrd_list[$i]['invert'] = true; + } } -$colours='mixed'; +$colours = 'mixed'; -$scale_min = "0"; -$nototal = 1; -$simple_rrd = TRUE; +$scale_min = '0'; +$nototal = 1; +$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 30402f5c9..e4f5b04d4 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/netstat_ip_frag.inc.php b/html/includes/graphs/device/netstat_ip_frag.inc.php index 3fc3ba3ca..da5ea0249 100644 --- a/html/includes/graphs/device/netstat_ip_frag.inc.php +++ b/html/includes/graphs/device/netstat_ip_frag.inc.php @@ -1,8 +1,8 @@ \ No newline at end of file diff --git a/html/includes/graphs/device/netstat_snmp.inc.php b/html/includes/graphs/device/netstat_snmp.inc.php index 0a0bd9704..513872d27 100644 --- a/html/includes/graphs/device/netstat_snmp.inc.php +++ b/html/includes/graphs/device/netstat_snmp.inc.php @@ -1,33 +1,31 @@ +require 'includes/graphs/generic_multi.inc.php'; diff --git a/html/includes/graphs/device/netstat_snmp_pkt.inc.php b/html/includes/graphs/device/netstat_snmp_pkt.inc.php index a87f8eb0f..40883d7be 100644 --- a/html/includes/graphs/device/netstat_snmp_pkt.inc.php +++ b/html/includes/graphs/device/netstat_snmp_pkt.inc.php @@ -1,21 +1,19 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/device/netstat_tcp.inc.php b/html/includes/graphs/device/netstat_tcp.inc.php index 37c76a6ef..7559f3bd7 100644 --- a/html/includes/graphs/device/netstat_tcp.inc.php +++ b/html/includes/graphs/device/netstat_tcp.inc.php @@ -1,27 +1,31 @@ +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/netstat_udp.inc.php b/html/includes/graphs/device/netstat_udp.inc.php index 3b8ca5388..e6ff11b1d 100644 --- a/html/includes/graphs/device/netstat_udp.inc.php +++ b/html/includes/graphs/device/netstat_udp.inc.php @@ -1,27 +1,28 @@ +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/nfsen_common.inc.php b/html/includes/graphs/device/nfsen_common.inc.php index fc36a36c6..774d47e3f 100644 --- a/html/includes/graphs/device/nfsen_common.inc.php +++ b/html/includes/graphs/device/nfsen_common.inc.php @@ -1,49 +1,55 @@ + // convert dots in filename to underscores + $nfsensuffix = ''; + if ($config['nfsen_suffix']) { + $nfsensuffix = $config['nfsen_suffix']; + } + + $basefilename_underscored = preg_replace('/\./', $config['nfsen_split_char'], $device['hostname']); + $nfsen_filename = (strstr($basefilename_underscored, $nfsensuffix, true)); + + if (is_file($nfsenrrds.$nfsen_filename.'.rrd')) { + $rrd_filename = $nfsenrrds.$nfsen_filename.'.rrd'; + + $flowtypes = array('tcp', 'udp', 'icmp', 'other'); + + $rrd_list = array(); + $nfsen_iter = 1; + foreach ($flowtypes as $flowtype) { + $rrd_list[$nfsen_iter]['filename'] = $rrd_filename; + $rrd_list[$nfsen_iter]['descr'] = $flowtype; + $rrd_list[$nfsen_iter]['ds'] = $dsprefix.$flowtype; + + // set a multiplier which in turn will create a CDEF if this var is set + if ($dsprefix == 'traffic_') { + $multiplier = '8'; + } + + $colours = 'blues'; + $nototal = 0; + $units = ''; + $unit_text = $dsdescr; + $scale_min = '0'; + + if ($_GET['debug']) { + print_r($rrd_list); + } + + $nfsen_iter++; + } + } +} + +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/device/nfsen_flows.inc.php b/html/includes/graphs/device/nfsen_flows.inc.php index e1579a988..42701705b 100644 --- a/html/includes/graphs/device/nfsen_flows.inc.php +++ b/html/includes/graphs/device/nfsen_flows.inc.php @@ -1,7 +1,5 @@ +require 'nfsen_common.inc.php'; diff --git a/html/includes/graphs/device/nfsen_packets.inc.php b/html/includes/graphs/device/nfsen_packets.inc.php index e10447e45..9e5ba07b2 100644 --- a/html/includes/graphs/device/nfsen_packets.inc.php +++ b/html/includes/graphs/device/nfsen_packets.inc.php @@ -1,8 +1,6 @@ +require 'nfsen_common.inc.php'; diff --git a/html/includes/graphs/device/nfsen_traffic.inc.php b/html/includes/graphs/device/nfsen_traffic.inc.php index 8210d2851..1f04c3b37 100644 --- a/html/includes/graphs/device/nfsen_traffic.inc.php +++ b/html/includes/graphs/device/nfsen_traffic.inc.php @@ -1,8 +1,6 @@ +require 'nfsen_common.inc.php'; diff --git a/html/includes/graphs/device/panos_sessions.inc.php b/html/includes/graphs/device/panos_sessions.inc.php index cbfe61587..b4d1311b7 100644 --- a/html/includes/graphs/device/panos_sessions.inc.php +++ b/html/includes/graphs/device/panos_sessions.inc.php @@ -1,18 +1,16 @@ +require 'includes/graphs/generic_simplex.inc.php'; diff --git a/html/includes/graphs/device/ping_perf.inc.php b/html/includes/graphs/device/ping_perf.inc.php index cbbb48d62..9bd96faa7 100644 --- a/html/includes/graphs/device/ping_perf.inc.php +++ b/html/includes/graphs/device/ping_perf.inc.php @@ -12,16 +12,14 @@ * 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 1ce7689d6..8e5ca90b1 100644 --- a/html/includes/graphs/device/poller_perf.inc.php +++ b/html/includes/graphs/device/poller_perf.inc.php @@ -12,16 +12,14 @@ * 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/power.inc.php b/html/includes/graphs/device/power.inc.php index 3c320dda4..2a19fe0e0 100644 --- a/html/includes/graphs/device/power.inc.php +++ b/html/includes/graphs/device/power.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/processor.inc.php b/html/includes/graphs/device/processor.inc.php index 015a0c187..bc378e671 100644 --- a/html/includes/graphs/device/processor.inc.php +++ b/html/includes/graphs/device/processor.inc.php @@ -1,12 +1,10 @@ diff --git a/html/includes/graphs/device/processor_separate.inc.php b/html/includes/graphs/device/processor_separate.inc.php index c5bcb892f..2b5980256 100644 --- a/html/includes/graphs/device/processor_separate.inc.php +++ b/html/includes/graphs/device/processor_separate.inc.php @@ -2,33 +2,29 @@ $i = 0; -foreach ($procs as $proc) -{ - $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd"); +foreach ($procs as $proc) { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('processor-'.$proc['processor_type'].'-'.$proc['processor_index'].'.rrd'); - if (is_file($rrd_filename)) - { - $descr = short_hrDeviceDescr($proc['processor_descr']); + if (is_file($rrd_filename)) { + $descr = short_hrDeviceDescr($proc['processor_descr']); - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = $descr; - $rrd_list[$i]['ds'] = "usage"; - $rrd_list[$i]['area'] = 1; - $i++; - } + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $descr; + $rrd_list[$i]['ds'] = 'usage'; + $rrd_list[$i]['area'] = 1; + $i++; + } } -$unit_text = "Load %"; +$unit_text = 'Load %'; -$units = '%'; +$units = '%'; $total_units = '%'; -$colours ='mixed'; +$colours = 'mixed'; -$scale_min = "0"; -$scale_max = "100"; +$scale_min = '0'; +$scale_max = '100'; $nototal = 1; -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/processor_stack.inc.php b/html/includes/graphs/device/processor_stack.inc.php index 7cdfa0780..dfbd4b355 100644 --- a/html/includes/graphs/device/processor_stack.inc.php +++ b/html/includes/graphs/device/processor_stack.inc.php @@ -2,34 +2,30 @@ $i = 0; -foreach ($procs as $proc) -{ - $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd"); +foreach ($procs as $proc) { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('processor-'.$proc['processor_type'].'-'.$proc['processor_index'].'.rrd'); - if (is_file($rrd_filename)) - { - $descr = short_hrDeviceDescr($proc['processor_descr']); + if (is_file($rrd_filename)) { + $descr = short_hrDeviceDescr($proc['processor_descr']); - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = $descr; - $rrd_list[$i]['ds'] = "usage"; - $i++; - } + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $descr; + $rrd_list[$i]['ds'] = 'usage'; + $i++; + } } -$unit_text = "Load %"; +$unit_text = 'Load %'; -$units = '%'; +$units = '%'; $total_units = '%'; -$colours ='oranges'; +$colours = 'oranges'; -$scale_min = "0"; -$scale_max = "100"; +$scale_min = '0'; +$scale_max = '100'; -$divider = $i; +$divider = $i; $text_orig = 1; -$nototal = 1; +$nototal = 1; -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); - -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/device/screenos_sessions.inc.php b/html/includes/graphs/device/screenos_sessions.inc.php index d15ce2aee..52ff2b3a3 100644 --- a/html/includes/graphs/device/screenos_sessions.inc.php +++ b/html/includes/graphs/device/screenos_sessions.inc.php @@ -1,26 +1,26 @@ +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/sensor.inc.php b/html/includes/graphs/device/sensor.inc.php index bf75c8287..38b91b211 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 a34a1b6b4..17a5b5ee0 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/smokeping_all_common.inc.php b/html/includes/graphs/device/smokeping_all_common.inc.php index 6f5a5aadc..a9e7b86b7 100644 --- a/html/includes/graphs/device/smokeping_all_common.inc.php +++ b/html/includes/graphs/device/smokeping_all_common.inc.php @@ -3,90 +3,82 @@ // Dear Tobias. You write in Perl, this makes me hate you forever. // This is my translation of Smokeping's graphing. // Thanks to Bill Fenner for Perl->Human translation:> +$scale_min = 0; +$scale_rigid = true; -$scale_min = 0; -$scale_rigid = TRUE; +require 'includes/graphs/common.inc.php'; +require 'smokeping_common.inc.php'; -include("includes/graphs/common.inc.php"); -include("smokeping_common.inc.php"); +$i = 0; +$pings = 20; +$iter = 0; +$colourset = 'mixed'; -$i = 0; -$pings = 20; -$iter = 0; -$colourset = "mixed"; - -if($width > "500") -{ - $descr_len = 18; -} else { - $descr_len = 12 + round(($width - 275) / 8); +if ($width > '500') { + $descr_len = 18; +} +else { + $descr_len = (12 + round(($width - 275) / 8)); } -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev\l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev\l'"; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev\l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev\l'"; } -foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filename) -{ +foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filename) { + if (!isset($config['graph_colours'][$colourset][$iter])) { + $iter = 0; + } - if (!isset($config['graph_colours'][$colourset][$iter])) { $iter = 0; } - $colour = $config['graph_colours'][$colourset][$iter]; - $iter++; + $colour = $config['graph_colours'][$colourset][$iter]; + $iter++; - $descr = rrdtool_escape($source, $descr_len); + $descr = rrdtool_escape($source, $descr_len); $filename = generate_smokeping_file($device,$filename); + $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE '; + $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE'; + $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; + $rrd_options .= " CDEF:dm$i=median$i"; + // $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; + // start emulate Smokeping::calc_stddev + foreach (range(1, $pings) as $p) { + $rrd_options .= ' DEF:pin'.$i.'p'.$p.'='.$filename.':ping'.$p.':AVERAGE'; + $rrd_options .= ' CDEF:p'.$i.'p'.$p.'=pin'.$i.'p'.$p.',UN,0,pin'.$i.'p'.$p.',IF'; + } - $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; - $rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE"; - $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; - $rrd_options .= " CDEF:dm$i=median$i"; -# $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; + unset($pings_options, $m_options, $sdev_options); - // start emulate Smokeping::calc_stddev - foreach (range(1, $pings) as $p) - { - $rrd_options .= " DEF:pin".$i."p".$p."=".$filename.":ping".$p.":AVERAGE"; - $rrd_options .= " CDEF:p".$i."p".$p."=pin".$i."p".$p.",UN,0,pin".$i."p".$p.",IF"; - } + foreach (range(2, $pings) as $p) { + $pings_options .= ',p'.$i.'p'.$p.',UN,+'; + $m_options .= ',p'.$i.'p'.$p.',+'; + $sdev_options .= ',p'.$i.'p'.$p.',m'.$i.',-,DUP,*,+'; + } - unset($pings_options, $m_options, $sdev_options); + $rrd_options .= ' CDEF:pings'.$i.'='.$pings.',p'.$i.'p1,UN'.$pings_options.',-'; + $rrd_options .= ' CDEF:m'.$i.'=p'.$i.'p1'.$m_options.',pings'.$i.',/'; + $rrd_options .= ' CDEF:sdev'.$i.'=p'.$i.'p1,m'.$i.',-,DUP,*'.$sdev_options.',pings'.$i.',/,SQRT'; + // end emulate Smokeping::calc_stddev + $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-"; + $rrd_options .= " CDEF:s2d$i=sdev$i"; + $rrd_options .= " AREA:dmlow$i"; + $rrd_options .= " AREA:s2d$i#".$colour.'30::STACK'; + $rrd_options .= " LINE1:dm$i#".$colour.":'$descr'"; - foreach (range(2, $pings) as $p) - { - $pings_options .= ",p".$i."p".$p.",UN,+"; - $m_options .= ",p".$i."p".$p.",+"; - $sdev_options .= ",p".$i."p".$p.",m".$i.",-,DUP,*,+"; - } + // $rrd_options .= " LINE1:sdev$i#000000:$descr"; + $rrd_options .= " VDEF:avmed$i=median$i,AVERAGE"; + $rrd_options .= " VDEF:avsd$i=sdev$i,AVERAGE"; + $rrd_options .= " CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/"; + $rrd_options .= " VDEF:avmsr$i=msr$i,AVERAGE"; - $rrd_options .= " CDEF:pings".$i."=".$pings .",p".$i."p1,UN". $pings_options . ",-"; - $rrd_options .= " CDEF:m".$i."=p".$i."p1".$m_options.",pings".$i.",/"; - $rrd_options .= " CDEF:sdev".$i."=p".$i."p1,m".$i.",-,DUP,*".$sdev_options.",pings".$i.",/,SQRT"; - // end emulate Smokeping::calc_stddev + $rrd_options .= " GPRINT:avmed$i:'%5.1lf%ss'"; + $rrd_options .= " GPRINT:ploss$i:AVERAGE:'%5.1lf%%'"; - $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-"; - $rrd_options .= " CDEF:s2d$i=sdev$i"; - $rrd_options .= " AREA:dmlow$i"; - $rrd_options .= " AREA:s2d$i#".$colour."30::STACK"; - $rrd_options .= " LINE1:dm$i#".$colour.":'$descr'"; + $rrd_options .= " GPRINT:avsd$i:'%5.1lf%Ss'"; + $rrd_options .= " GPRINT:avmsr$i:'%5.1lf%s\\l'"; -# $rrd_options .= " LINE1:sdev$i#000000:$descr"; - - $rrd_options .= " VDEF:avmed$i=median$i,AVERAGE"; - $rrd_options .= " VDEF:avsd$i=sdev$i,AVERAGE"; - $rrd_options .= " CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/"; - $rrd_options .= " VDEF:avmsr$i=msr$i,AVERAGE"; - - $rrd_options .= " GPRINT:avmed$i:'%5.1lf%ss'"; - $rrd_options .= " GPRINT:ploss$i:AVERAGE:'%5.1lf%%'"; - - $rrd_options .= " GPRINT:avsd$i:'%5.1lf%Ss'"; - $rrd_options .= " GPRINT:avmsr$i:'%5.1lf%s\\l'"; - - $i++; -} - -?> + $i++; +}//end foreach diff --git a/html/includes/graphs/device/smokeping_all_common_avg.inc.php b/html/includes/graphs/device/smokeping_all_common_avg.inc.php index 0f0248d03..97c5d40fb 100644 --- a/html/includes/graphs/device/smokeping_all_common_avg.inc.php +++ b/html/includes/graphs/device/smokeping_all_common_avg.inc.php @@ -3,103 +3,95 @@ // Dear Tobias. You write in Perl, this makes me hate you forever. // This is my translation of Smokeping's graphing. // Thanks to Bill Fenner for Perl->Human translation:> +$scale_min = 0; +$scale_rigid = true; -$scale_min = 0; -$scale_rigid = TRUE; +require 'includes/graphs/common.inc.php'; +require 'smokeping_common.inc.php'; -include("includes/graphs/common.inc.php"); -include("smokeping_common.inc.php"); +$i = 0; +$pings = 20; +$iter = 0; +$colourset = 'mixed'; -$i = 0; -$pings = 20; -$iter = 0; -$colourset = "mixed"; - -if($width > "500") -{ - $descr_len = 18; -} else { - $descr_len = 12 + round(($width - 275) / 8); +if ($width > '500') { + $descr_len = 18; +} +else { + $descr_len = (12 + round(($width - 275) / 8)); } // FIXME str_pad really needs a "limit to length" so we can rid of all the substrs all over the code to limit the length as below... -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev\l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev\l'"; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev\l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev\l'"; } -foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filename) -{ +foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filename) { + if (!isset($config['graph_colours'][$colourset][$iter])) { + $iter = 0; + } - if (!isset($config['graph_colours'][$colourset][$iter])) { $iter = 0; } - $colour = $config['graph_colours'][$colourset][$iter]; - $iter++; + $colour = $config['graph_colours'][$colourset][$iter]; + $iter++; - $descr = rrdtool_escape($source, $descr_len); + $descr = rrdtool_escape($source, $descr_len); $filename = generate_smokeping_file($device,$filename); + $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE '; + $rrd_options .= " CDEF:dm$i=median$i,UN,0,median$i,IF"; + $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE'; + $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; + // $rrd_options .= " CDEF:dm$i=median$i"; + // $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; + // start emulate Smokeping::calc_stddev + foreach (range(1, $pings) as $p) { + $rrd_options .= ' DEF:pin'.$i.'p'.$p.'='.$filename.':ping'.$p.':AVERAGE'; + $rrd_options .= ' CDEF:p'.$i.'p'.$p.'=pin'.$i.'p'.$p.',UN,0,pin'.$i.'p'.$p.',IF'; + } - $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; - $rrd_options .= " CDEF:dm$i=median$i,UN,0,median$i,IF"; - $rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE"; - $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; -# $rrd_options .= " CDEF:dm$i=median$i"; -# $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; + unset($pings_options, $m_options, $sdev_options); - // start emulate Smokeping::calc_stddev - foreach (range(1, $pings) as $p) - { - $rrd_options .= " DEF:pin".$i."p".$p."=".$filename.":ping".$p.":AVERAGE"; - $rrd_options .= " CDEF:p".$i."p".$p."=pin".$i."p".$p.",UN,0,pin".$i."p".$p.",IF"; - } + foreach (range(2, $pings) as $p) { + $pings_options .= ',p'.$i.'p'.$p.',UN,+'; + $m_options .= ',p'.$i.'p'.$p.',+'; + $sdev_options .= ',p'.$i.'p'.$p.',m'.$i.',-,DUP,*,+'; + } - unset($pings_options, $m_options, $sdev_options); + $rrd_options .= ' CDEF:pings'.$i.'='.$pings.',p'.$i.'p1,UN'.$pings_options.',-'; + $rrd_options .= ' CDEF:m'.$i.'=p'.$i.'p1'.$m_options.',pings'.$i.',/'; + $rrd_options .= ' CDEF:sdev'.$i.'=p'.$i.'p1,m'.$i.',-,DUP,*'.$sdev_options.',pings'.$i.',/,SQRT'; + // end emulate Smokeping::calc_stddev + $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-"; + $rrd_options .= " CDEF:s2d$i=sdev$i"; - foreach (range(2, $pings) as $p) - { - $pings_options .= ",p".$i."p".$p.",UN,+"; - $m_options .= ",p".$i."p".$p.",+"; - $sdev_options .= ",p".$i."p".$p.",m".$i.",-,DUP,*,+"; - } + $dm_list .= ",dm$i,+"; + $sd_list .= ",s2d$i,+"; + $ploss_list .= ",ploss$i,+"; - $rrd_options .= " CDEF:pings".$i."=".$pings .",p".$i."p1,UN". $pings_options . ",-"; - $rrd_options .= " CDEF:m".$i."=p".$i."p1".$m_options.",pings".$i.",/"; - $rrd_options .= " CDEF:sdev".$i."=p".$i."p1,m".$i.",-,DUP,*".$sdev_options.",pings".$i.",/,SQRT"; - // end emulate Smokeping::calc_stddev + $i++; +}//end foreach - $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-"; - $rrd_options .= " CDEF:s2d$i=sdev$i"; +$descr = rrdtool_escape('Average', $descr_len); - $dm_list .= ",dm$i,+"; - $sd_list .= ",s2d$i,+"; - $ploss_list .= ",ploss$i,+"; +$rrd_options .= ' CDEF:ploss_all=0'.$ploss_list.",$i,/"; +$rrd_options .= ' CDEF:dm_all=0'.$dm_list.",$i,/"; +// $rrd_options .= " CDEF:dm_all_clean=dm_all,UN,NaN,dm_all,IF"; +$rrd_options .= ' CDEF:sd_all=0'.$sd_list.",$i,/"; +$rrd_options .= ' CDEF:dmlow_all=dm_all,sd_all,2,/,-'; - $i++; - -} - -$descr = rrdtool_escape("Average", $descr_len); - -$rrd_options .= " CDEF:ploss_all=0".$ploss_list.",$i,/"; -$rrd_options .= " CDEF:dm_all=0".$dm_list.",$i,/"; -# $rrd_options .= " CDEF:dm_all_clean=dm_all,UN,NaN,dm_all,IF"; -$rrd_options .= " CDEF:sd_all=0".$sd_list.",$i,/"; -$rrd_options .= " CDEF:dmlow_all=dm_all,sd_all,2,/,-"; - -$rrd_options .= " AREA:dmlow_all"; -$rrd_options .= " AREA:sd_all#AAAAAA::STACK"; +$rrd_options .= ' AREA:dmlow_all'; +$rrd_options .= ' AREA:sd_all#AAAAAA::STACK'; $rrd_options .= " LINE1:dm_all#CC0000:'$descr'"; -$rrd_options .= " VDEF:avmed=dm_all,AVERAGE"; -$rrd_options .= " VDEF:avsd=sd_all,AVERAGE"; -$rrd_options .= " CDEF:msr=dm_all,POP,avmed,avsd,/"; -$rrd_options .= " VDEF:avmsr=msr,AVERAGE"; +$rrd_options .= ' VDEF:avmed=dm_all,AVERAGE'; +$rrd_options .= ' VDEF:avsd=sd_all,AVERAGE'; +$rrd_options .= ' CDEF:msr=dm_all,POP,avmed,avsd,/'; +$rrd_options .= ' VDEF:avmsr=msr,AVERAGE'; $rrd_options .= " GPRINT:avmed:'%5.1lf%ss'"; $rrd_options .= " GPRINT:ploss_all:AVERAGE:'%5.1lf%%'"; $rrd_options .= " GPRINT:avsd:'%5.1lf%Ss'"; $rrd_options .= " GPRINT:avmsr:'%5.1lf%s\\l'"; - -?> diff --git a/html/includes/graphs/device/smokeping_in_all.inc.php b/html/includes/graphs/device/smokeping_in_all.inc.php index aaee41706..e9c9ca4e5 100644 --- a/html/includes/graphs/device/smokeping_in_all.inc.php +++ b/html/includes/graphs/device/smokeping_in_all.inc.php @@ -1,7 +1,5 @@ +require 'smokeping_all_common.inc.php'; diff --git a/html/includes/graphs/device/smokeping_in_all_avg.inc.php b/html/includes/graphs/device/smokeping_in_all_avg.inc.php index 8344ba94c..fcc5539cf 100644 --- a/html/includes/graphs/device/smokeping_in_all_avg.inc.php +++ b/html/includes/graphs/device/smokeping_in_all_avg.inc.php @@ -1,7 +1,5 @@ +require 'smokeping_all_common_avg.inc.php'; diff --git a/html/includes/graphs/device/smokeping_out_all.inc.php b/html/includes/graphs/device/smokeping_out_all.inc.php index ef1d87f94..923c0bc74 100644 --- a/html/includes/graphs/device/smokeping_out_all.inc.php +++ b/html/includes/graphs/device/smokeping_out_all.inc.php @@ -1,7 +1,5 @@ +require 'smokeping_all_common.inc.php'; diff --git a/html/includes/graphs/device/smokeping_out_all_avg.inc.php b/html/includes/graphs/device/smokeping_out_all_avg.inc.php index 3d3c8645d..b36cb0eb5 100644 --- a/html/includes/graphs/device/smokeping_out_all_avg.inc.php +++ b/html/includes/graphs/device/smokeping_out_all_avg.inc.php @@ -1,7 +1,5 @@ +require 'smokeping_all_common_avg.inc.php'; diff --git a/html/includes/graphs/device/state.inc.php b/html/includes/graphs/device/state.inc.php index 56b059e01..a8ae9041c 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/storage.inc.php b/html/includes/graphs/device/storage.inc.php index 211c98cc0..769e9ce91 100644 --- a/html/includes/graphs/device/storage.inc.php +++ b/html/includes/graphs/device/storage.inc.php @@ -1,31 +1,47 @@ + $descr = rrdtool_escape($storage['storage_descr'], 12); + $rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('storage-'.$storage['storage_mib'].'-'.$storage['storage_descr'].'.rrd'); + $rrd_options .= " DEF:$storage[storage_id]used=$rrd:used:AVERAGE"; + $rrd_options .= " DEF:$storage[storage_id]free=$rrd:free:AVERAGE"; + $rrd_options .= " CDEF:$storage[storage_id]size=$storage[storage_id]used,$storage[storage_id]free,+"; + $rrd_options .= " CDEF:$storage[storage_id]perc=$storage[storage_id]used,$storage[storage_id]size,/,100,*"; + $rrd_options .= " LINE1.25:$storage[storage_id]perc#".$colour.":'$descr'"; + $rrd_options .= " GPRINT:$storage[storage_id]size:LAST:%6.2lf%sB"; + $rrd_options .= " GPRINT:$storage[storage_id]used:LAST:%6.2lf%sB"; + $rrd_options .= " GPRINT:$storage[storage_id]perc:LAST:%5.2lf%%\\\\l"; + $iter++; +}//end foreach diff --git a/html/includes/graphs/device/temperature.inc.php b/html/includes/graphs/device/temperature.inc.php index bcc967485..b3f35c695 100644 --- a/html/includes/graphs/device/temperature.inc.php +++ b/html/includes/graphs/device/temperature.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 06029c8b3..9ba469cc0 100644 --- a/html/includes/graphs/device/toner.inc.php +++ b/html/includes/graphs/device/toner.inc.php @@ -1,59 +1,60 @@ + case '6': + $colour['left'] = '36393D'; + break; + + case '7': + default: + $colour['left'] = 'FF0000'; + unset($iter); + break; + }//end switch + }//end if + + $hostname = gethostbyid($toner['device_id']); + + $descr = substr(str_pad($toner['toner_descr'], 16), 0, 16); + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('toner-'.$toner['toner_index'].'.rrd'); + $toner_id = $toner['toner_id']; + + $rrd_options .= " DEF:toner$toner_id=$rrd_filename:toner:AVERAGE"; + $rrd_options .= " LINE2:toner$toner_id#".$colour['left'].":'".$descr."'"; + $rrd_options .= " GPRINT:toner$toner_id:LAST:'%5.0lf%%'"; + $rrd_options .= " GPRINT:toner$toner_id:MIN:'%5.0lf%%'"; + $rrd_options .= " GPRINT:toner$toner_id:MAX:%5.0lf%%\\\\l"; + + $iter++; +}//end foreach diff --git a/html/includes/graphs/device/ubnt_airfiber_Capacity.inc.php b/html/includes/graphs/device/ubnt_airfiber_Capacity.inc.php index 6174a0e18..63a8083e8 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 3068bba69..af7fc5e9f 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 92665285d..1054df1d2 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/device/ucd_io.inc.php b/html/includes/graphs/device/ucd_io.inc.php index 0a733f5bb..8b9c64f8c 100644 --- a/html/includes/graphs/device/ucd_io.inc.php +++ b/html/includes/graphs/device/ucd_io.inc.php @@ -1,12 +1,10 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/device/ucd_load.inc.php b/html/includes/graphs/device/ucd_load.inc.php index 9a0c45cc8..ccdf61ee5 100644 --- a/html/includes/graphs/device/ucd_load.inc.php +++ b/html/includes/graphs/device/ucd_load.inc.php @@ -1,21 +1,21 @@ diff --git a/html/includes/graphs/device/ucd_memory.inc.php b/html/includes/graphs/device/ucd_memory.inc.php index 992714aba..606fed717 100644 --- a/html/includes/graphs/device/ucd_memory.inc.php +++ b/html/includes/graphs/device/ucd_memory.inc.php @@ -1,8 +1,8 @@ diff --git a/html/includes/graphs/device/ucd_swap_io.inc.php b/html/includes/graphs/device/ucd_swap_io.inc.php index 6697ac8ae..002814538 100644 --- a/html/includes/graphs/device/ucd_swap_io.inc.php +++ b/html/includes/graphs/device/ucd_swap_io.inc.php @@ -1,12 +1,10 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/device/uptime.inc.php b/html/includes/graphs/device/uptime.inc.php index 20235f654..6c9c4ff88 100644 --- a/html/includes/graphs/device/uptime.inc.php +++ b/html/includes/graphs/device/uptime.inc.php @@ -1,17 +1,15 @@ diff --git a/html/includes/graphs/device/voltage.inc.php b/html/includes/graphs/device/voltage.inc.php index 3a2423fc7..efdf3350e 100644 --- a/html/includes/graphs/device/voltage.inc.php +++ b/html/includes/graphs/device/voltage.inc.php @@ -1,9 +1,7 @@ +require 'includes/graphs/device/sensor.inc.php'; diff --git a/html/includes/graphs/device/vpdn_sessions_l2tp.inc.php b/html/includes/graphs/device/vpdn_sessions_l2tp.inc.php index dd203415a..7e4ecc8e8 100644 --- a/html/includes/graphs/device/vpdn_sessions_l2tp.inc.php +++ b/html/includes/graphs/device/vpdn_sessions_l2tp.inc.php @@ -1,24 +1,21 @@ +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/vpdn_tunnels_l2tp.inc.php b/html/includes/graphs/device/vpdn_tunnels_l2tp.inc.php index 36d6c0fb1..9c4a9c01b 100644 --- a/html/includes/graphs/device/vpdn_tunnels_l2tp.inc.php +++ b/html/includes/graphs/device/vpdn_tunnels_l2tp.inc.php @@ -1,24 +1,21 @@ +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/device/wifi_clients.inc.php b/html/includes/graphs/device/wifi_clients.inc.php index 0ff024df4..1c45b1363 100644 --- a/html/includes/graphs/device/wifi_clients.inc.php +++ b/html/includes/graphs/device/wifi_clients.inc.php @@ -1,28 +1,24 @@ \ No newline at end of file diff --git a/html/includes/graphs/diskio/auth.inc.php b/html/includes/graphs/diskio/auth.inc.php index e9388680a..30b6271d7 100644 --- a/html/includes/graphs/diskio/auth.inc.php +++ b/html/includes/graphs/diskio/auth.inc.php @@ -1,19 +1,15 @@ diff --git a/html/includes/graphs/diskio/bits.inc.php b/html/includes/graphs/diskio/bits.inc.php index c61bf6d89..507e94cf1 100644 --- a/html/includes/graphs/diskio/bits.inc.php +++ b/html/includes/graphs/diskio/bits.inc.php @@ -1,10 +1,8 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/diskio/ops.inc.php b/html/includes/graphs/diskio/ops.inc.php index 1b0626757..eac593212 100644 --- a/html/includes/graphs/diskio/ops.inc.php +++ b/html/includes/graphs/diskio/ops.inc.php @@ -1,20 +1,18 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/generic_data.inc.php b/html/includes/graphs/generic_data.inc.php index a85a6c760..e13fce80c 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_duplex.inc.php b/html/includes/graphs/generic_duplex.inc.php index 6a11166ef..bddfd09b0 100644 --- a/html/includes/graphs/generic_duplex.inc.php +++ b/html/includes/graphs/generic_duplex.inc.php @@ -2,131 +2,126 @@ // Draw generic bits graph // args: ds_in, ds_out, rrd_filename, bg, legend, from, to, width, height, inverse, $percentile +require 'includes/graphs/common.inc.php'; -include("includes/graphs/common.inc.php"); +$length = '10'; -$length = "10"; - -if (!isset($percentile)) { $length += "2"; } - -if (!isset($out_text)) { $out_text = "Out"; } -if (!isset($in_text)) { $in_text = "In"; } - -$unit_text = str_pad(truncate($unit_text,$length),$length); -$in_text = str_pad(truncate($in_text,$length),$length); -$out_text = str_pad(truncate($out_text,$length),$length); - -$rrd_options .= " DEF:".$out."=".$rrd_filename.":".$ds_out.":AVERAGE"; -$rrd_options .= " DEF:".$in."=".$rrd_filename.":".$ds_in.":AVERAGE"; -$rrd_options .= " DEF:".$out."_max=".$rrd_filename.":".$ds_out.":MAX"; -$rrd_options .= " DEF:".$in."_max=".$rrd_filename.":".$ds_in.":MAX"; -$rrd_options .= " CDEF:dout_max=out_max,-1,*"; -$rrd_options .= " CDEF:dout=out,-1,*"; -$rrd_options .= " CDEF:both=in,out,+"; -if ($print_total) -{ - $rrd_options .= " VDEF:totin=in,TOTAL"; - $rrd_options .= " VDEF:totout=out,TOTAL"; - $rrd_options .= " VDEF:tot=both,TOTAL"; -} -if ($percentile) -{ - $rrd_options .= " VDEF:percentile_in=in,".$percentile.",PERCENT"; - $rrd_options .= " VDEF:percentile_out=out,".$percentile.",PERCENT"; - $rrd_options .= " VDEF:dpercentile_out=dout,".$percentile.",PERCENT"; -} -if ($graph_max) -{ - $rrd_options .= " AREA:in_max#".$colour_area_in_max.":"; - $rrd_options .= " AREA:dout_max#".$colour_area_out_max.":"; +if (!isset($percentile)) { + $length += '2'; } -if($_GET['previous'] == "yes") -{ - $rrd_options .= " DEF:".$out."X=".$rrd_filename.":".$ds_out.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " DEF:".$in."X=".$rrd_filename.":".$ds_in.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " DEF:".$out."_maxX=".$rrd_filename.":".$ds_out.":MAX:start=".$prev_from.":end=".$from; - $rrd_options .= " DEF:".$in."_maxX=".$rrd_filename.":".$ds_in.":MAX:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:".$out."X:$period"; - $rrd_options .= " SHIFT:".$in."X:$period"; - $rrd_options .= " SHIFT:".$out."_maxX:$period"; - $rrd_options .= " SHIFT:".$in."_maxX:$period"; - $rrd_options .= " CDEF:dout_maxX=out_maxX,-1,*"; - $rrd_options .= " CDEF:doutX=outX,-1,*"; - $rrd_options .= " CDEF:bothX=inX,outX,+"; - if ($print_total) - { - $rrd_options .= " VDEF:totinX=inX,TOTAL"; - $rrd_options .= " VDEF:totoutX=outX,TOTAL"; - $rrd_options .= " VDEF:totX=bothX,TOTAL"; - } - if ($percentile) - { - $rrd_options .= " VDEF:percentile_inX=inX,".$percentile.",PERCENT"; - $rrd_options .= " VDEF:percentile_outX=outX,".$percentile.",PERCENT"; - $rrd_options .= " VDEF:dpercentile_outX=doutX,".$percentile.",PERCENT"; - } - if ($graph_max) - { - $rrd_options .= " AREA:in_max#".$colour_area_in_max.":"; - $rrd_options .= " AREA:dout_max#".$colour_area_out_max.":"; - } +if (!isset($out_text)) { + $out_text = 'Out'; } -$rrd_options .= " AREA:in#".$colour_area_in.":"; -$rrd_options .= " COMMENT:'".$unit_text." Now Ave Max"; +if (!isset($in_text)) { + $in_text = 'In'; +} -if ($percentile) -{ - $rrd_options .= " ".$percentile."th %"; +$unit_text = str_pad(truncate($unit_text, $length), $length); +$in_text = str_pad(truncate($in_text, $length), $length); +$out_text = str_pad(truncate($out_text, $length), $length); + +$rrd_options .= ' DEF:'.$out.'='.$rrd_filename.':'.$ds_out.':AVERAGE'; +$rrd_options .= ' DEF:'.$in.'='.$rrd_filename.':'.$ds_in.':AVERAGE'; +$rrd_options .= ' DEF:'.$out.'_max='.$rrd_filename.':'.$ds_out.':MAX'; +$rrd_options .= ' DEF:'.$in.'_max='.$rrd_filename.':'.$ds_in.':MAX'; +$rrd_options .= ' CDEF:dout_max=out_max,-1,*'; +$rrd_options .= ' CDEF:dout=out,-1,*'; +$rrd_options .= ' CDEF:both=in,out,+'; +if ($print_total) { + $rrd_options .= ' VDEF:totin=in,TOTAL'; + $rrd_options .= ' VDEF:totout=out,TOTAL'; + $rrd_options .= ' VDEF:tot=both,TOTAL'; +} + +if ($percentile) { + $rrd_options .= ' VDEF:percentile_in=in,'.$percentile.',PERCENT'; + $rrd_options .= ' VDEF:percentile_out=out,'.$percentile.',PERCENT'; + $rrd_options .= ' VDEF:dpercentile_out=dout,'.$percentile.',PERCENT'; +} + +if ($graph_max) { + $rrd_options .= ' AREA:in_max#'.$colour_area_in_max.':'; + $rrd_options .= ' AREA:dout_max#'.$colour_area_out_max.':'; +} + +if ($_GET['previous'] == 'yes') { + $rrd_options .= ' DEF:'.$out.'X='.$rrd_filename.':'.$ds_out.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' DEF:'.$in.'X='.$rrd_filename.':'.$ds_in.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' DEF:'.$out.'_maxX='.$rrd_filename.':'.$ds_out.':MAX:start='.$prev_from.':end='.$from; + $rrd_options .= ' DEF:'.$in.'_maxX='.$rrd_filename.':'.$ds_in.':MAX:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:'.$out."X:$period"; + $rrd_options .= ' SHIFT:'.$in."X:$period"; + $rrd_options .= ' SHIFT:'.$out."_maxX:$period"; + $rrd_options .= ' SHIFT:'.$in."_maxX:$period"; + $rrd_options .= ' CDEF:dout_maxX=out_maxX,-1,*'; + $rrd_options .= ' CDEF:doutX=outX,-1,*'; + $rrd_options .= ' CDEF:bothX=inX,outX,+'; + if ($print_total) { + $rrd_options .= ' VDEF:totinX=inX,TOTAL'; + $rrd_options .= ' VDEF:totoutX=outX,TOTAL'; + $rrd_options .= ' VDEF:totX=bothX,TOTAL'; + } + + if ($percentile) { + $rrd_options .= ' VDEF:percentile_inX=inX,'.$percentile.',PERCENT'; + $rrd_options .= ' VDEF:percentile_outX=outX,'.$percentile.',PERCENT'; + $rrd_options .= ' VDEF:dpercentile_outX=doutX,'.$percentile.',PERCENT'; + } + + if ($graph_max) { + $rrd_options .= ' AREA:in_max#'.$colour_area_in_max.':'; + $rrd_options .= ' AREA:dout_max#'.$colour_area_out_max.':'; + } +}//end if + +$rrd_options .= ' AREA:in#'.$colour_area_in.':'; +$rrd_options .= " COMMENT:'".$unit_text.' Now Ave Max'; + +if ($percentile) { + $rrd_options .= ' '.$percentile.'th %'; } $rrd_options .= "\\n'"; -$rrd_options .= " LINE1.25:in#".$colour_line_in.":'".$in_text."'"; -$rrd_options .= " GPRINT:in:LAST:%6.2lf%s"; -$rrd_options .= " GPRINT:in:AVERAGE:%6.2lf%s"; -$rrd_options .= " GPRINT:in_max:MAX:%6.2lf%s"; +$rrd_options .= ' LINE1.25:in#'.$colour_line_in.":'".$in_text."'"; +$rrd_options .= ' GPRINT:in:LAST:%6.2lf%s'; +$rrd_options .= ' GPRINT:in:AVERAGE:%6.2lf%s'; +$rrd_options .= ' GPRINT:in_max:MAX:%6.2lf%s'; -if ($percentile) -{ - $rrd_options .= " GPRINT:percentile_in:%6.2lf%s"; +if ($percentile) { + $rrd_options .= ' GPRINT:percentile_in:%6.2lf%s'; } $rrd_options .= " COMMENT:'\\n'"; -$rrd_options .= " AREA:dout#".$colour_area_out.":"; -$rrd_options .= " LINE1.25:dout#".$colour_line_out.":'".$out_text."'"; -$rrd_options .= " GPRINT:out:LAST:%6.2lf%s"; -$rrd_options .= " GPRINT:out:AVERAGE:%6.2lf%s"; -$rrd_options .= " GPRINT:out_max:MAX:%6.2lf%s"; +$rrd_options .= ' AREA:dout#'.$colour_area_out.':'; +$rrd_options .= ' LINE1.25:dout#'.$colour_line_out.":'".$out_text."'"; +$rrd_options .= ' GPRINT:out:LAST:%6.2lf%s'; +$rrd_options .= ' GPRINT:out:AVERAGE:%6.2lf%s'; +$rrd_options .= ' GPRINT:out_max:MAX:%6.2lf%s'; -if ($percentile) -{ - $rrd_options .= " GPRINT:percentile_out:%6.2lf%s"; +if ($percentile) { + $rrd_options .= ' GPRINT:percentile_out:%6.2lf%s'; } $rrd_options .= " COMMENT:\\\\n"; -if ($print_total) -{ - $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'"; +if ($print_total) { + $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'"; } -if ($percentile) -{ - $rrd_options .= " LINE1:percentile_in#aa0000"; - $rrd_options .= " LINE1:dpercentile_out#aa0000"; +if ($percentile) { + $rrd_options .= ' LINE1:percentile_in#aa0000'; + $rrd_options .= ' LINE1:dpercentile_out#aa0000'; } -if($_GET['previous'] == "yes") -{ - $rrd_options .= " LINE1.25:in".$format."X#666666:'Prev In \\\\n'"; - $rrd_options .= " AREA:in".$format."X#99999966:"; - $rrd_options .= " LINE1.25:dout".$format."X#666666:'Prev Out'"; - $rrd_options .= " AREA:dout".$format."X#99999966:"; +if ($_GET['previous'] == 'yes') { + $rrd_options .= ' LINE1.25:in'.$format."X#666666:'Prev In \\\\n'"; + $rrd_options .= ' AREA:in'.$format.'X#99999966:'; + $rrd_options .= ' LINE1.25:dout'.$format."X#666666:'Prev Out'"; + $rrd_options .= ' AREA:dout'.$format.'X#99999966:'; } -$rrd_options .= " HRULE:0#999999"; - -?> +$rrd_options .= ' HRULE:0#999999'; diff --git a/html/includes/graphs/generic_multi.inc.php b/html/includes/graphs/generic_multi.inc.php index c9c1053f8..d02e82ebb 100644 --- a/html/includes/graphs/generic_multi.inc.php +++ b/html/includes/graphs/generic_multi.inc.php @@ -1,74 +1,78 @@ "500") -{ - $descr_len=24; -} else { - $descr_len=12; - $descr_len += round(($width - 250) / 8); +if ($width > '500') { + $descr_len = 24; +} +else { + $descr_len = 12; + $descr_len += round(($width - 250) / 8); } -if ($nototal) { $descrlen += "2"; $unitlen += "2";} - -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Now Min Max Avg\l'"; - if (!$nototal) { $rrd_options .= " COMMENT:'Total '"; } - $rrd_options .= " COMMENT:'\l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Now Min Max Avg\l'"; - +if ($nototal) { + $descrlen += '2'; + $unitlen += '2'; } -$i = 0; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'"; + if (!$nototal) { + $rrd_options .= " COMMENT:'Total '"; + } + + $rrd_options .= " COMMENT:'\l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'"; +} + +$i = 0; $iter = 0; -foreach ($rrd_list as $rrd) -{ - if (!$config['graph_colours'][$colours][$iter]) { $iter = 0; } +foreach ($rrd_list as $rrd) { + if (!$config['graph_colours'][$colours][$iter]) { + $iter = 0; + } - $colour=$config['graph_colours'][$colours][$iter]; + $colour = $config['graph_colours'][$colours][$iter]; - $ds = $rrd['ds']; - $filename = $rrd['filename']; + $ds = $rrd['ds']; + $filename = $rrd['filename']; - $descr = rrdtool_escape($rrd['descr'], $descr_len); + $descr = rrdtool_escape($rrd['descr'], $descr_len); - $id = "ds".$i; + $id = 'ds'.$i; - $rrd_options .= " DEF:".$id."=$filename:$ds:AVERAGE"; + $rrd_options .= ' DEF:'.$id."=$filename:$ds:AVERAGE"; - if ($simple_rrd) - { - $rrd_options .= " CDEF:".$id."min=".$id." "; - $rrd_options .= " CDEF:".$id."max=".$id." "; - } else { - $rrd_options .= " DEF:".$id."min=$filename:$ds:MIN"; - $rrd_options .= " DEF:".$id."max=$filename:$ds:MAX"; - } + if ($simple_rrd) { + $rrd_options .= ' CDEF:'.$id.'min='.$id.' '; + $rrd_options .= ' CDEF:'.$id.'max='.$id.' '; + } + else { + $rrd_options .= ' DEF:'.$id."min=$filename:$ds:MIN"; + $rrd_options .= ' DEF:'.$id."max=$filename:$ds:MAX"; + } - if ($rrd['invert']) - { - $rrd_options .= " CDEF:".$id."i=".$id.",-1,*"; - $rrd_optionsc .= " AREA:".$id."i#".$colour.":'$descr':".$cstack; - $rrd_optionsc .= " GPRINT:".$id.":LAST:%5.1lf%s GPRINT:".$id."min:MIN:%5.1lf%s"; - $rrd_optionsc .= " GPRINT:".$id."max:MAX:%5.1lf%s GPRINT:".$id.":AVERAGE:'%5.1lf%s\\n'"; - $cstack = "STACK"; - } else { - $rrd_optionsb .= " AREA:".$id."#".$colour.":'$descr':".$bstack; - $rrd_optionsb .= " GPRINT:".$id.":LAST:%5.1lf%s GPRINT:".$id."min:MIN:%5.1lf%s"; - $rrd_optionsb .= " GPRINT:".$id."max:MAX:%5.1lf%s GPRINT:".$id.":AVERAGE:'%5.1lf%s\\n'"; - $bstack = "STACK"; - } + if ($rrd['invert']) { + $rrd_options .= ' CDEF:'.$id.'i='.$id.',-1,*'; + $rrd_optionsc .= ' AREA:'.$id.'i#'.$colour.":'$descr':".$cstack; + $rrd_optionsc .= ' GPRINT:'.$id.':LAST:%5.1lf%s GPRINT:'.$id.'min:MIN:%5.1lf%s'; + $rrd_optionsc .= ' GPRINT:'.$id.'max:MAX:%5.1lf%s GPRINT:'.$id.":AVERAGE:'%5.1lf%s\\n'"; + $cstack = 'STACK'; + } + else { + $rrd_optionsb .= ' AREA:'.$id.'#'.$colour.":'$descr':".$bstack; + $rrd_optionsb .= ' GPRINT:'.$id.':LAST:%5.1lf%s GPRINT:'.$id.'min:MIN:%5.1lf%s'; + $rrd_optionsb .= ' GPRINT:'.$id.'max:MAX:%5.1lf%s GPRINT:'.$id.":AVERAGE:'%5.1lf%s\\n'"; + $bstack = 'STACK'; + } - $i++; $iter++; - -} + $i++; + $iter++; +}//end foreach $rrd_options .= $rrd_optionsb; -$rrd_options .= " HRULE:0#555555"; +$rrd_options .= ' HRULE:0#555555'; $rrd_options .= $rrd_optionsc; - -?> diff --git a/html/includes/graphs/generic_multi_bits.inc.php b/html/includes/graphs/generic_multi_bits.inc.php index 5ea0dfaac..caa765e4d 100644 --- a/html/includes/graphs/generic_multi_bits.inc.php +++ b/html/includes/graphs/generic_multi_bits.inc.php @@ -2,97 +2,104 @@ // Draws aggregate bits graph from multiple RRDs // Variables : colour_[line|area]_[in|out], rrd_filenames +require 'includes/graphs/common.inc.php'; -include("includes/graphs/common.inc.php"); +$i = 0; -$i=0; +foreach ($rrd_filenames as $key => $rrd_filename) { + if ($rrd_inverted[$key]) { + $in = 'out'; + $out = 'in'; + } + else { + $in = 'in'; + $out = 'out'; + } -foreach ($rrd_filenames as $key => $rrd_filename) -{ - if ($rrd_inverted[$key]) { $in = 'out'; $out = 'in'; } else { $in = 'in'; $out = 'out'; } + $rrd_options .= ' DEF:'.$in.'octets'.$i.'='.$rrd_filename.':'.$ds_in.':AVERAGE'; + $rrd_options .= ' DEF:'.$out.'octets'.$i.'='.$rrd_filename.':'.$ds_out.':AVERAGE'; + $in_thing .= $seperator.'inoctets'.$i.',UN,0,'.'inoctets'.$i.',IF'; + $out_thing .= $seperator.'outoctets'.$i.',UN,0,'.'outoctets'.$i.',IF'; + $pluses .= $plus; + $seperator = ','; + $plus = ',+'; - $rrd_options .= " DEF:".$in."octets" . $i . "=".$rrd_filename.":".$ds_in.":AVERAGE"; - $rrd_options .= " DEF:".$out."octets" . $i . "=".$rrd_filename.":".$ds_out.":AVERAGE"; - $in_thing .= $seperator . "inoctets" . $i . ",UN,0," . "inoctets" . $i . ",IF"; - $out_thing .= $seperator . "outoctets" . $i . ",UN,0," . "outoctets" . $i . ",IF"; - $pluses .= $plus; - $seperator = ","; - $plus = ",+"; + if ($_GET['previous']) { + $rrd_options .= ' DEF:'.$in.'octets'.$i.'X='.$rrd_filename.':'.$ds_in.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' DEF:'.$out.'octets'.$i.'X='.$rrd_filename.':'.$ds_out.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:'.$in.'octets'.$i."X:$period"; + $rrd_options .= ' SHIFT:'.$out.'octets'.$i."X:$period"; + $in_thingX .= $seperatorX.'inoctets'.$i.'X,UN,0,'.'inoctets'.$i.'X,IF'; + $out_thingX .= $seperatorX.'outoctets'.$i.'X,UN,0,'.'outoctets'.$i.'X,IF'; + $plusesX .= $plusX; + $seperatorX = ','; + $plusX = ',+'; + } - if ($_GET['previous']) - { - $rrd_options .= " DEF:".$in."octets" . $i . "X=".$rrd_filename.":".$ds_in.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " DEF:".$out."octets" . $i . "X=".$rrd_filename.":".$ds_out.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:".$in."octets" . $i . "X:$period"; - $rrd_options .= " SHIFT:".$out."octets" . $i . "X:$period"; - $in_thingX .= $seperatorX . "inoctets" . $i . "X,UN,0," . "inoctets" . $i . "X,IF"; - $out_thingX .= $seperatorX . "outoctets" . $i . "X,UN,0," . "outoctets" . $i . "X,IF"; - $plusesX .= $plusX; - $seperatorX = ","; - $plusX = ",+"; - } - $i++; -} + $i++; +}//end foreach -if ($i) -{ - if ($inverse) { $in = 'out'; $out = 'in'; } else { $in = 'in'; $out = 'out'; } - $rrd_options .= " CDEF:".$in."octets=" . $in_thing . $pluses; - $rrd_options .= " CDEF:".$out."octets=" . $out_thing . $pluses; - $rrd_options .= " CDEF:doutoctets=outoctets,-1,*"; - $rrd_options .= " CDEF:inbits=inoctets,8,*"; - $rrd_options .= " CDEF:outbits=outoctets,8,*"; - $rrd_options .= " CDEF:doutbits=doutoctets,8,*"; - $rrd_options .= " VDEF:95thin=inbits,95,PERCENT"; - $rrd_options .= " VDEF:95thout=outbits,95,PERCENT"; - $rrd_options .= " VDEF:d95thout=doutbits,5,PERCENT"; +if ($i) { + if ($inverse) { + $in = 'out'; + $out = 'in'; + } + else { + $in = 'in'; + $out = 'out'; + } - if ($_GET['previous'] == "yes") - { - $rrd_options .= " CDEF:".$in."octetsX=" . $in_thingX . $pluses; - $rrd_options .= " CDEF:".$out."octetsX=" . $out_thingX . $pluses; - $rrd_options .= " CDEF:doutoctetsX=outoctetsX,-1,*"; - $rrd_options .= " CDEF:inbitsX=inoctetsX,8,*"; - $rrd_options .= " CDEF:outbitsX=outoctetsX,8,*"; - $rrd_options .= " CDEF:doutbitsX=doutoctetsX,8,*"; - $rrd_options .= " VDEF:95thinX=inbitsX,95,PERCENT"; - $rrd_options .= " VDEF:95thoutX=outbitsX,95,PERCENT"; - $rrd_options .= " VDEF:d95thoutX=doutbitsX,5,PERCENT"; - } + $rrd_options .= ' CDEF:'.$in.'octets='.$in_thing.$pluses; + $rrd_options .= ' CDEF:'.$out.'octets='.$out_thing.$pluses; + $rrd_options .= ' CDEF:doutoctets=outoctets,-1,*'; + $rrd_options .= ' CDEF:inbits=inoctets,8,*'; + $rrd_options .= ' CDEF:outbits=outoctets,8,*'; + $rrd_options .= ' CDEF:doutbits=doutoctets,8,*'; + $rrd_options .= ' VDEF:95thin=inbits,95,PERCENT'; + $rrd_options .= ' VDEF:95thout=outbits,95,PERCENT'; + $rrd_options .= ' VDEF:d95thout=doutbits,5,PERCENT'; - if ($legend == 'no' || $legend == '1') - { - $rrd_options .= " AREA:inbits#".$colour_area_in.":"; - $rrd_options .= " LINE1.25:inbits#".$colour_line_in.":"; - $rrd_options .= " AREA:doutbits#".$colour_area_out.":"; - $rrd_options .= " LINE1.25:doutbits#".$colour_line_out.":"; - } else { - $rrd_options .= " AREA:inbits#".$colour_area_in.":"; - $rrd_options .= " COMMENT:'bps Now Ave Max 95th %\\n'"; - $rrd_options .= " LINE1.25:inbits#".$colour_line_in.":In\ "; - $rrd_options .= " GPRINT:inbits:LAST:%6.2lf%s"; - $rrd_options .= " GPRINT:inbits:AVERAGE:%6.2lf%s"; - $rrd_options .= " GPRINT:inbits:MAX:%6.2lf%s"; - $rrd_options .= " GPRINT:95thin:%6.2lf%s\\\\n"; - $rrd_options .= " AREA:doutbits#".$colour_area_out.":"; - $rrd_options .= " LINE1.25:doutbits#".$colour_line_out.":Out"; - $rrd_options .= " GPRINT:outbits:LAST:%6.2lf%s"; - $rrd_options .= " GPRINT:outbits:AVERAGE:%6.2lf%s"; - $rrd_options .= " GPRINT:outbits:MAX:%6.2lf%s"; - $rrd_options .= " GPRINT:95thout:%6.2lf%s\\\\n"; - } + if ($_GET['previous'] == 'yes') { + $rrd_options .= ' CDEF:'.$in.'octetsX='.$in_thingX.$pluses; + $rrd_options .= ' CDEF:'.$out.'octetsX='.$out_thingX.$pluses; + $rrd_options .= ' CDEF:doutoctetsX=outoctetsX,-1,*'; + $rrd_options .= ' CDEF:inbitsX=inoctetsX,8,*'; + $rrd_options .= ' CDEF:outbitsX=outoctetsX,8,*'; + $rrd_options .= ' CDEF:doutbitsX=doutoctetsX,8,*'; + $rrd_options .= ' VDEF:95thinX=inbitsX,95,PERCENT'; + $rrd_options .= ' VDEF:95thoutX=outbitsX,95,PERCENT'; + $rrd_options .= ' VDEF:d95thoutX=doutbitsX,5,PERCENT'; + } - $rrd_options .= " LINE1:95thin#aa0000"; - $rrd_options .= " LINE1:d95thout#aa0000"; + if ($legend == 'no' || $legend == '1') { + $rrd_options .= ' AREA:inbits#'.$colour_area_in.':'; + $rrd_options .= ' LINE1.25:inbits#'.$colour_line_in.':'; + $rrd_options .= ' AREA:doutbits#'.$colour_area_out.':'; + $rrd_options .= ' LINE1.25:doutbits#'.$colour_line_out.':'; + } + else { + $rrd_options .= ' AREA:inbits#'.$colour_area_in.':'; + $rrd_options .= " COMMENT:'bps Now Ave Max 95th %\\n'"; + $rrd_options .= ' LINE1.25:inbits#'.$colour_line_in.':In\ '; + $rrd_options .= ' GPRINT:inbits:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits:MAX:%6.2lf%s'; + $rrd_options .= " GPRINT:95thin:%6.2lf%s\\\\n"; + $rrd_options .= ' AREA:doutbits#'.$colour_area_out.':'; + $rrd_options .= ' LINE1.25:doutbits#'.$colour_line_out.':Out'; + $rrd_options .= ' GPRINT:outbits:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits:MAX:%6.2lf%s'; + $rrd_options .= " GPRINT:95thout:%6.2lf%s\\\\n"; + } - if ($_GET['previous'] == "yes") - { - $rrd_options .= " AREA:inbitsX#9999966:"; - $rrd_options .= " AREA:doutbitsX#99999966:"; - } + $rrd_options .= ' LINE1:95thin#aa0000'; + $rrd_options .= ' LINE1:d95thout#aa0000'; -} + if ($_GET['previous'] == 'yes') { + $rrd_options .= ' AREA:inbitsX#9999966:'; + $rrd_options .= ' AREA:doutbitsX#99999966:'; + } +}//end if -#$rrd_options .= " HRULE:0#999999"; - -?> +// $rrd_options .= " HRULE:0#999999"; diff --git a/html/includes/graphs/generic_multi_bits_separated.inc.php b/html/includes/graphs/generic_multi_bits_separated.inc.php index 5eaa70908..181f0ae4d 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_data.inc.php b/html/includes/graphs/generic_multi_data.inc.php index 93ee5b7cf..90f5c908e 100644 --- a/html/includes/graphs/generic_multi_data.inc.php +++ b/html/includes/graphs/generic_multi_data.inc.php @@ -2,108 +2,115 @@ // Draws aggregate bits graph from multiple RRDs // Variables : colour_[line|area]_[in|out], rrd_filenames +require 'includes/graphs/common.inc.php'; -include("includes/graphs/common.inc.php"); - -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'; } -$i=0; +$i = 0; -foreach ($rrd_filenames as $key => $rrd_filename) -{ - if ($rrd_inverted[$key]) { $in = 'out'; $out = 'in'; } else { $in = 'in'; $out = 'out'; } +foreach ($rrd_filenames as $key => $rrd_filename) { + if ($rrd_inverted[$key]) { + $in = 'out'; + $out = 'in'; + } + else { + $in = 'in'; + $out = 'out'; + } - $rrd_options .= " DEF:".$in."octets" . $i . "=".$rrd_filename.":".$ds_in.":AVERAGE"; - $rrd_options .= " DEF:".$out."octets" . $i . "=".$rrd_filename.":".$ds_out.":AVERAGE"; - $in_thing .= $seperator . "inoctets" . $i . ",UN,0," . "inoctets" . $i . ",IF"; - $out_thing .= $seperator . "outoctets" . $i . ",UN,0," . "outoctets" . $i . ",IF"; - $pluses .= $plus; - $seperator = ","; - $plus = ",+"; + $rrd_options .= ' DEF:'.$in.'octets'.$i.'='.$rrd_filename.':'.$ds_in.':AVERAGE'; + $rrd_options .= ' DEF:'.$out.'octets'.$i.'='.$rrd_filename.':'.$ds_out.':AVERAGE'; + $in_thing .= $seperator.'inoctets'.$i.',UN,0,'.'inoctets'.$i.',IF'; + $out_thing .= $seperator.'outoctets'.$i.',UN,0,'.'outoctets'.$i.',IF'; + $pluses .= $plus; + $seperator = ','; + $plus = ',+'; - if ($_GET['previous']) - { - $rrd_options .= " DEF:".$in."octets" . $i . "X=".$rrd_filename.":".$ds_in.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " DEF:".$out."octets" . $i . "X=".$rrd_filename.":".$ds_out.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:".$in."octets" . $i . "X:$period"; - $rrd_options .= " SHIFT:".$out."octets" . $i . "X:$period"; - $in_thingX .= $seperatorX . "inoctets" . $i . "X,UN,0," . "inoctets" . $i . "X,IF"; - $out_thingX .= $seperatorX . "outoctets" . $i . "X,UN,0," . "outoctets" . $i . "X,IF"; - $plusesX .= $plusX; - $seperatorX = ","; - $plusX = ",+"; - } - $i++; -} + if ($_GET['previous']) { + $rrd_options .= ' DEF:'.$in.'octets'.$i.'X='.$rrd_filename.':'.$ds_in.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' DEF:'.$out.'octets'.$i.'X='.$rrd_filename.':'.$ds_out.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:'.$in.'octets'.$i."X:$period"; + $rrd_options .= ' SHIFT:'.$out.'octets'.$i."X:$period"; + $in_thingX .= $seperatorX.'inoctets'.$i.'X,UN,0,'.'inoctets'.$i.'X,IF'; + $out_thingX .= $seperatorX.'outoctets'.$i.'X,UN,0,'.'outoctets'.$i.'X,IF'; + $plusesX .= $plusX; + $seperatorX = ','; + $plusX = ',+'; + } -if ($i) -{ - if ($inverse) { $in = 'out'; $out = 'in'; } else { $in = 'in'; $out = 'out'; } - $rrd_options .= " CDEF:".$in."octets=" . $in_thing . $pluses; - $rrd_options .= " CDEF:".$out."octets=" . $out_thing . $pluses; - $rrd_options .= " CDEF:doutoctets=outoctets,-1,*"; - $rrd_options .= " CDEF:inbits=inoctets,8,*"; - $rrd_options .= " CDEF:outbits=outoctets,8,*"; - $rrd_options .= " CDEF:doutbits=doutoctets,8,*"; - $rrd_options .= " VDEF:95thin=inbits,95,PERCENT"; - $rrd_options .= " VDEF:95thout=outbits,95,PERCENT"; - $rrd_options .= " VDEF:d95thout=doutbits,5,PERCENT"; + $i++; +}//end foreach - if ($_GET['previous'] == "yes") - { - $rrd_options .= " CDEF:".$in."octetsX=" . $in_thingX . $pluses; - $rrd_options .= " CDEF:".$out."octetsX=" . $out_thingX . $pluses; - $rrd_options .= " CDEF:doutoctetsX=outoctetsX,-1,*"; - $rrd_options .= " CDEF:inbitsX=inoctetsX,8,*"; - $rrd_options .= " CDEF:outbitsX=outoctetsX,8,*"; - $rrd_options .= " CDEF:doutbitsX=doutoctetsX,8,*"; - $rrd_options .= " VDEF:95thinX=inbitsX,95,PERCENT"; - $rrd_options .= " VDEF:95thoutX=outbitsX,95,PERCENT"; - $rrd_options .= " VDEF:d95thoutX=doutbitsX,5,PERCENT"; - } +if ($i) { + if ($inverse) { + $in = 'out'; + $out = 'in'; + } + else { + $in = 'in'; + $out = 'out'; + } - if ($legend == 'no' || $legend == '1') - { - $rrd_options .= " AREA:in".$format."#".$colour_area_in.":"; -# $rrd_options .= " LINE1.25:in".$format."#".$colour_line_in.":"; - $rrd_options .= " AREA:dout".$format."#".$colour_area_out.":"; -# $rrd_options .= " LINE1.25:dout".$format."#".$colour_line_out.":"; - } else { - $rrd_options .= " AREA:in".$format."#".$colour_area_in.":"; - $rrd_options .= " COMMENT:'bps Now Ave Max 95th %\\n'"; -# $rrd_options .= " LINE1.25:in".$format."#".$colour_line_in.":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:%6.2lf%s"; - $rrd_options .= " GPRINT:95thin:%6.2lf%s\\\\n"; - $rrd_options .= " AREA:dout".$format."#".$colour_area_out.":"; -# $rrd_options .= " LINE1.25:dout".$format."#".$colour_line_out.":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:%6.2lf%s"; - $rrd_options .= " GPRINT:95thout:%6.2lf%s\\\\n"; - } + $rrd_options .= ' CDEF:'.$in.'octets='.$in_thing.$pluses; + $rrd_options .= ' CDEF:'.$out.'octets='.$out_thing.$pluses; + $rrd_options .= ' CDEF:doutoctets=outoctets,-1,*'; + $rrd_options .= ' CDEF:inbits=inoctets,8,*'; + $rrd_options .= ' CDEF:outbits=outoctets,8,*'; + $rrd_options .= ' CDEF:doutbits=doutoctets,8,*'; + $rrd_options .= ' VDEF:95thin=inbits,95,PERCENT'; + $rrd_options .= ' VDEF:95thout=outbits,95,PERCENT'; + $rrd_options .= ' VDEF:d95thout=doutbits,5,PERCENT'; - $rrd_options .= " LINE1:95thin#aa0000"; - $rrd_options .= " LINE1:d95thout#aa0000"; + if ($_GET['previous'] == 'yes') { + $rrd_options .= ' CDEF:'.$in.'octetsX='.$in_thingX.$pluses; + $rrd_options .= ' CDEF:'.$out.'octetsX='.$out_thingX.$pluses; + $rrd_options .= ' CDEF:doutoctetsX=outoctetsX,-1,*'; + $rrd_options .= ' CDEF:inbitsX=inoctetsX,8,*'; + $rrd_options .= ' CDEF:outbitsX=outoctetsX,8,*'; + $rrd_options .= ' CDEF:doutbitsX=doutoctetsX,8,*'; + $rrd_options .= ' VDEF:95thinX=inbitsX,95,PERCENT'; + $rrd_options .= ' VDEF:95thoutX=outbitsX,95,PERCENT'; + $rrd_options .= ' VDEF:d95thoutX=doutbitsX,5,PERCENT'; + } - if ($_GET['previous'] == "yes") - { - $rrd_options .= " AREA:in".$format."X#99999999:"; - $rrd_options .= " AREA:dout".$format."X#99999999:"; - $rrd_options .= " LINE1:in".$format."X#666666:"; - $rrd_options .= " LINE1:dout".$format."X#666666:"; - } + if ($legend == 'no' || $legend == '1') { + $rrd_options .= ' AREA:in'.$format.'#'.$colour_area_in.':'; + // $rrd_options .= " LINE1.25:in".$format."#".$colour_line_in.":"; + $rrd_options .= ' AREA:dout'.$format.'#'.$colour_area_out.':'; + // $rrd_options .= " LINE1.25:dout".$format."#".$colour_line_out.":"; + } + else { + $rrd_options .= ' AREA:in'.$format.'#'.$colour_area_in.':'; + $rrd_options .= " COMMENT:'bps Now Ave Max 95th %\\n'"; + // $rrd_options .= " LINE1.25:in".$format."#".$colour_line_in.":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:%6.2lf%s'; + $rrd_options .= " GPRINT:95thin:%6.2lf%s\\\\n"; + $rrd_options .= ' AREA:dout'.$format.'#'.$colour_area_out.':'; + // $rrd_options .= " LINE1.25:dout".$format."#".$colour_line_out.":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:%6.2lf%s'; + $rrd_options .= " GPRINT:95thout:%6.2lf%s\\\\n"; + } -} + $rrd_options .= ' LINE1:95thin#aa0000'; + $rrd_options .= ' LINE1:d95thout#aa0000'; -#$rrd_options .= " HRULE:0#999999"; + if ($_GET['previous'] == 'yes') { + $rrd_options .= ' AREA:in'.$format.'X#99999999:'; + $rrd_options .= ' AREA:dout'.$format.'X#99999999:'; + $rrd_options .= ' LINE1:in'.$format.'X#666666:'; + $rrd_options .= ' LINE1:dout'.$format.'X#666666:'; + } +}//end if -?> +// $rrd_options .= " HRULE:0#999999"; diff --git a/html/includes/graphs/generic_multi_data_separated.inc.php b/html/includes/graphs/generic_multi_data_separated.inc.php index 07d6ee6c0..7865d03de 100644 --- a/html/includes/graphs/generic_multi_data_separated.inc.php +++ b/html/includes/graphs/generic_multi_data_separated.inc.php @@ -1,117 +1,127 @@ "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($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 { - $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 { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." Now Ave Max\l'"; } -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 (isset($rrd['descr_in'])) - { - $descr = rrdtool_escape($rrd['descr_in'], $descr_len) . " In"; - } else { - $descr = rrdtool_escape($rrd['descr'], $descr_len) . " In"; - } - $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.",+"; - - if (!$args['nototal']) - { - - $in_thing .= $seperator . $in . $i . ",UN,0," . $in . $i . ",IF"; - $out_thing .= $seperator . $out . $i . ",UN,0," . $out . $i . ",IF"; - $pluses .= $plus; - $seperator = ","; - $plus = ",+"; - - $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 ($i) { $stack="STACK"; } - - $rrd_options .= " AREA:inB".$i."#" . $colour_in . ":'" . $descr . "':$stack"; - $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\l"; - - if (!$nototal) { $rrd_options .= " GPRINT:totin".$i.":%6.2lf%s$total_units"; } - - $rrd_options .= " 'HRULE:0#" . $colour_out.":".$descr_out."'"; - $rrd_optionsb .= " 'AREA:outB".$i."_neg#" . $colour_out . "::$stack'"; - $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\l"; - - if (!$nototal) { $rrd_options .= " GPRINT:totout".$i.":%6.2lf%s$total_units"; } - - $rrd_options .= " 'COMMENT:\l'"; - $i++; $iter++; +if (!isset($multiplier)) { + $multiplier = '8'; } -if ($custom_graph) { $rrd_options .= $custom_graph; } +foreach ($rrd_list as $rrd) { + if (!$config['graph_colours'][$colours_in][$iter] || !$config['graph_colours'][$colours_out][$iter]) { + $iter = 0; + } -if(!$nototal) -{ - $rrd_options .= " CDEF:".$in."octets=" . $in_thing . $pluses; - $rrd_options .= " CDEF:".$out."octets=" . $out_thing . $pluses; - $rrd_options .= " CDEF:octets=inoctets,outoctets,+"; - $rrd_options .= " CDEF:doutoctets=outoctets,-1,*"; - $rrd_options .= " CDEF:inbits=inoctets,8,*"; - $rrd_options .= " CDEF:outbits=outoctets,8,*"; - $rrd_options .= " CDEF:doutbits=doutoctets,8,*"; + $colour_in = $config['graph_colours'][$colours_in][$iter]; + $colour_out = $config['graph_colours'][$colours_out][$iter]; - $rrd_options .= " VDEF:95thin=inbits,95,PERCENT"; - $rrd_options .= " VDEF:95thout=outbits,95,PERCENT"; - $rrd_options .= " VDEF:d95thout=doutbits,5,PERCENT"; + if (isset($rrd['descr_in'])) { + $descr = rrdtool_escape($rrd['descr_in'], $descr_len).' In'; + } + else { + $descr = rrdtool_escape($rrd['descr'], $descr_len).' In'; + } - $rrd_options .= " VDEF:totin=inoctets,TOTAL"; - $rrd_options .= " VDEF:totout=outoctets,TOTAL"; - $rrd_options .= " VDEF:tot=octets,TOTAL"; + $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 .= " AREA:totin#" . $colour_in . ":'" . $descr . "':$stack"; -# $rrd_options .= " GPRINT:totin:LAST:%6.2lf%s$units"; -# $rrd_options .= " GPRINT:totin:AVERAGE:%6.2lf%s$units"; -# $rrd_options .= " GPRINT:totin:MAX:%6.2lf%s$units\l"; + $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.',+'; + if (!$args['nototal']) { + $in_thing .= $seperator.$in.$i.',UN,0,'.$in.$i.',IF'; + $out_thing .= $seperator.$out.$i.',UN,0,'.$out.$i.',IF'; + $pluses .= $plus; + $seperator = ','; + $plus = ',+'; + + $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 ($i) { + $stack = 'STACK'; + } + + $rrd_options .= ' AREA:inB'.$i.'#'.$colour_in.":'".$descr."':$stack"; + $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\l"; + + if (!$nototal) { + $rrd_options .= ' GPRINT:totin'.$i.":%6.2lf%s$total_units"; + } + + $rrd_options .= " 'HRULE:0#".$colour_out.':'.$descr_out."'"; + $rrd_optionsb .= " 'AREA:outB".$i.'_neg#'.$colour_out."::$stack'"; + $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\l"; + + if (!$nototal) { + $rrd_options .= ' GPRINT:totout'.$i.":%6.2lf%s$total_units"; + } + + $rrd_options .= " 'COMMENT:\l'"; + $i++; + $iter++; +}//end foreach + +if ($custom_graph) { + $rrd_options .= $custom_graph; } +if (!$nototal) { + $rrd_options .= ' CDEF:'.$in.'octets='.$in_thing.$pluses; + $rrd_options .= ' CDEF:'.$out.'octets='.$out_thing.$pluses; + $rrd_options .= ' CDEF:octets=inoctets,outoctets,+'; + $rrd_options .= ' CDEF:doutoctets=outoctets,-1,*'; + $rrd_options .= ' CDEF:inbits=inoctets,8,*'; + $rrd_options .= ' CDEF:outbits=outoctets,8,*'; + $rrd_options .= ' CDEF:doutbits=doutoctets,8,*'; + + $rrd_options .= ' VDEF:95thin=inbits,95,PERCENT'; + $rrd_options .= ' VDEF:95thout=outbits,95,PERCENT'; + $rrd_options .= ' VDEF:d95thout=doutbits,5,PERCENT'; + + $rrd_options .= ' VDEF:totin=inoctets,TOTAL'; + $rrd_options .= ' VDEF:totout=outoctets,TOTAL'; + $rrd_options .= ' VDEF:tot=octets,TOTAL'; + + // $rrd_options .= " AREA:totin#" . $colour_in . ":'" . $descr . "':$stack"; + // $rrd_options .= " GPRINT:totin:LAST:%6.2lf%s$units"; + // $rrd_options .= " GPRINT:totin:AVERAGE:%6.2lf%s$units"; + // $rrd_options .= " GPRINT:totin:MAX:%6.2lf%s$units\l"; +}//end if + $rrd_options .= $rrd_optionsb; -$rrd_options .= " HRULE:0#999999"; - -?> +$rrd_options .= ' HRULE:0#999999'; diff --git a/html/includes/graphs/generic_multi_line.inc.php b/html/includes/graphs/generic_multi_line.inc.php index 7117f79e1..c34d78e77 100644 --- a/html/includes/graphs/generic_multi_line.inc.php +++ b/html/includes/graphs/generic_multi_line.inc.php @@ -1,72 +1,80 @@ "500") -{ - $descr_len=24; -} else { - $descr_len=12; - $descr_len += round(($width - 250) / 8); +if ($width > '500') { + $descr_len = 24; +} +else { + $descr_len = 12; + $descr_len += round(($width - 250) / 8); } -if ($nototal) { $descrlen += "2"; $unitlen += "2";} - -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Now Min Max Avg\l'"; - if (!$nototal) { $rrd_options .= " COMMENT:'Total '"; } - $rrd_options .= " COMMENT:'\l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Now Min Max Avg\l'"; - +if ($nototal) { + $descrlen += '2'; + $unitlen += '2'; } -$i = 0; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'"; + if (!$nototal) { + $rrd_options .= " COMMENT:'Total '"; + } + + $rrd_options .= " COMMENT:'\l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'"; +} + +$i = 0; $iter = 0; -foreach ($rrd_list as $rrd) -{ - if (!$config['graph_colours'][$colours][$iter]) { $iter = 0; } +foreach ($rrd_list as $rrd) { + if (!$config['graph_colours'][$colours][$iter]) { + $iter = 0; + } - $colour=$config['graph_colours'][$colours][$iter]; + $colour = $config['graph_colours'][$colours][$iter]; - $ds = $rrd['ds']; - $filename = $rrd['filename']; + $ds = $rrd['ds']; + $filename = $rrd['filename']; - $descr = rrdtool_escape($rrd['descr'], $descr_len); + $descr = rrdtool_escape($rrd['descr'], $descr_len); - $id = "ds".$i; + $id = 'ds'.$i; - $rrd_options .= " DEF:".$id."=$filename:$ds:AVERAGE"; + $rrd_options .= ' DEF:'.$id."=$filename:$ds:AVERAGE"; - if ($simple_rrd) - { - $rrd_options .= " CDEF:".$id."min=".$id." "; - $rrd_options .= " CDEF:".$id."max=".$id." "; - } else { - $rrd_options .= " DEF:".$id."min=$filename:$ds:MIN"; - $rrd_options .= " DEF:".$id."max=$filename:$ds:MAX"; - } + if ($simple_rrd) { + $rrd_options .= ' CDEF:'.$id.'min='.$id.' '; + $rrd_options .= ' CDEF:'.$id.'max='.$id.' '; + } + else { + $rrd_options .= ' DEF:'.$id."min=$filename:$ds:MIN"; + $rrd_options .= ' DEF:'.$id."max=$filename:$ds:MAX"; + } - if ($rrd['invert']) - { - $rrd_options .= " CDEF:".$id."i=".$id.",-1,*"; - $rrd_optionsb .= " LINE1.25:".$id."i#".$colour.":'$descr'"; - if (!empty($rrd['areacolour'])) { $rrd_optionsb .= " AREA:".$id."i#" . $rrd['areacolour']; } - } else { - $rrd_optionsb .= " LINE1.25:".$id."#".$colour.":'$descr'"; - if (!empty($rrd['areacolour'])) { $rrd_optionsb .= " AREA:".$id."#" . $rrd['areacolour']; } - } + if ($rrd['invert']) { + $rrd_options .= ' CDEF:'.$id.'i='.$id.',-1,*'; + $rrd_optionsb .= ' LINE1.25:'.$id.'i#'.$colour.":'$descr'"; + if (!empty($rrd['areacolour'])) { + $rrd_optionsb .= ' AREA:'.$id.'i#'.$rrd['areacolour']; + } + } + else { + $rrd_optionsb .= ' LINE1.25:'.$id.'#'.$colour.":'$descr'"; + if (!empty($rrd['areacolour'])) { + $rrd_optionsb .= ' AREA:'.$id.'#'.$rrd['areacolour']; + } + } - $rrd_optionsb .= " GPRINT:".$id.":LAST:%5.2lf%s GPRINT:".$id."min:MIN:%5.2lf%s"; - $rrd_optionsb .= " GPRINT:".$id."max:MAX:%5.2lf%s GPRINT:".$id.":AVERAGE:'%5.2lf%s\\n'"; + $rrd_optionsb .= ' GPRINT:'.$id.':LAST:%5.2lf%s GPRINT:'.$id.'min:MIN:%5.2lf%s'; + $rrd_optionsb .= ' GPRINT:'.$id.'max:MAX:%5.2lf%s GPRINT:'.$id.":AVERAGE:'%5.2lf%s\\n'"; - $i++; $iter++; - -} + $i++; + $iter++; +}//end foreach $rrd_options .= $rrd_optionsb; -$rrd_options .= " HRULE:0#555555"; - -?> +$rrd_options .= ' HRULE:0#555555'; diff --git a/html/includes/graphs/generic_multi_seperated.inc.php b/html/includes/graphs/generic_multi_seperated.inc.php index d6cf17271..e672b143b 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/generic_multi_simplex_seperated.inc.php b/html/includes/graphs/generic_multi_simplex_seperated.inc.php index adc08d957..18df802ae 100644 --- a/html/includes/graphs/generic_multi_simplex_seperated.inc.php +++ b/html/includes/graphs/generic_multi_simplex_seperated.inc.php @@ -1,127 +1,137 @@ "500") -{ - $descr_len = 24; // FIXME may even be more imo? -} else { - $descr_len = 12; - $descr_len += round(($width - 250) / 8); +if ($width > '500') { + $descr_len = 24; + // FIXME may even be more imo? +} +else { + $descr_len = 12; + $descr_len += round(($width - 250) / 8); } -if ($nototal) { $descrlen += "2"; $unitlen += "2";} -$unit_text = str_pad(truncate($unit_text,$unitlen),$unitlen); - -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Now Min Max Avg\l'"; - if (!$nototal) { $rrd_options .= " COMMENT:'Total '"; } - $rrd_options .= " COMMENT:'\l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Now Min Max Avg\l'"; - +if ($nototal) { + $descrlen += '2'; + $unitlen += '2'; } -$unitlen = "10"; -if ($nototal) { $descrlen += "2"; $unitlen += "2";} -$unit_text = str_pad(truncate($unit_text,$unitlen),$unitlen); +$unit_text = str_pad(truncate($unit_text, $unitlen), $unitlen); -$colour_iter=0; -foreach ($rrd_list as $i => $rrd) -{ - if ($rrd['colour']) - { - $colour = $rrd['colour']; - } else { - if (!$config['graph_colours'][$colours][$colour_iter]) { $colour_iter = 0; } - $colour = $config['graph_colours'][$colours][$colour_iter]; - $colour_iter++; - } - - $descr = rrdtool_escape($rrd['descr'], $descr_len); - - $rrd_options .= " DEF:".$rrd['ds'].$i."=".$rrd['filename'].":".$rrd['ds'].":AVERAGE "; - - if ($simple_rrd) - { - $rrd_options .= " CDEF:".$rrd['ds'].$i."min=".$rrd['ds'].$i." "; - $rrd_options .= " CDEF:".$rrd['ds'].$i."max=".$rrd['ds'].$i." "; - } else { - $rrd_options .= " DEF:".$rrd['ds'].$i."min=".$rrd['filename'].":".$rrd['ds'].":MIN "; - $rrd_options .= " DEF:".$rrd['ds'].$i."max=".$rrd['filename'].":".$rrd['ds'].":MAX "; - } - - if ($_GET['previous']) - { - $rrd_options .= " DEF:".$i . "X=".$rrd['filename'].":".$rrd['ds'].":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:".$i . "X:$period"; - $thingX .= $seperatorX . $i . "X,UN,0," . $i . "X,IF"; - $plusesX .= $plusX; - $seperatorX = ","; - $plusX = ",+"; - } - - // Suppress totalling? - if (!$nototal) - { - $rrd_options .= " VDEF:tot".$rrd['ds'].$i."=".$rrd['ds'].$i.",TOTAL"; - } - - // This this not the first entry? - if ($i) { $stack="STACK"; } - # if we've been passed a multiplier we must make a CDEF based on it! - $g_defname = $rrd['ds']; - if (is_numeric($multiplier)) - { - $g_defname = $rrd['ds'] . "_cdef"; - $rrd_options .= " CDEF:" . $g_defname . $i . "=" . $rrd['ds'] . $i . "," . $multiplier . ",*"; - $rrd_options .= " CDEF:" . $g_defname . $i . "min=" . $rrd['ds'] . $i . "min," . $multiplier . ",*"; - $rrd_options .= " CDEF:" . $g_defname . $i . "max=" . $rrd['ds'] . $i . "max," . $multiplier . ",*"; - - // If we've been passed a divider (divisor!) we make a CDEF for it. - } elseif (is_numeric($divider)) - { - $g_defname = $rrd['ds'] . "_cdef"; - $rrd_options .= " CDEF:" . $g_defname . $i . "=" . $rrd['ds'] . $i . "," . $divider . ",/"; - $rrd_options .= " CDEF:" . $g_defname . $i . "min=" . $rrd['ds'] . $i . "min," . $divider . ",/"; - $rrd_options .= " CDEF:" . $g_defname . $i . "max=" . $rrd['ds'] . $i . "max," . $divider . ",/"; - } - - // Are our text values related to te multiplier/divisor or not? - if (isset($text_orig) && $text_orig) - { - $t_defname = $rrd['ds']; - } else { - $t_defname = $g_defname; - } - - $rrd_options .= " AREA:".$g_defname.$i."#".$colour.":'".$descr."':$stack"; - - $rrd_options .= " GPRINT:".$t_defname.$i.":LAST:%5.2lf%s GPRINT:".$t_defname.$i."min:MIN:%5.2lf%s"; - $rrd_options .= " GPRINT:".$t_defname.$i."max:MAX:%5.2lf%s GPRINT:".$t_defname.$i.":AVERAGE:'%5.2lf%s\\n'"; - - if (!$nototal) { $rrd_options .= " GPRINT:tot".$rrd['ds'].$i.":%6.2lf%s".rrdtool_escape($total_units).""; } - - $rrd_options .= " COMMENT:'\\n'"; -} - - if ($_GET['previous'] == "yes") - { - if (is_numeric($multiplier)) - { - $rrd_options .= " CDEF:X=" . $thingX . $plusesX.",".$multiplier. ",*"; - } elseif (is_numeric($divider)) - { - $rrd_options .= " CDEF:X=" . $thingX . $plusesX.",".$divider. ",/"; - } else - { - $rrd_options .= " CDEF:X=" . $thingX . $plusesX; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'"; + if (!$nototal) { + $rrd_options .= " COMMENT:'Total '"; } - $rrd_options .= " AREA:X#99999999:"; - $rrd_options .= " LINE1.25:X#666666:"; + $rrd_options .= " COMMENT:'\l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Now Min Max Avg\l'"; +} - } +$unitlen = '10'; +if ($nototal) { + $descrlen += '2'; + $unitlen += '2'; +} -?> +$unit_text = str_pad(truncate($unit_text, $unitlen), $unitlen); + +$colour_iter = 0; +foreach ($rrd_list as $i => $rrd) { + if ($rrd['colour']) { + $colour = $rrd['colour']; + } + else { + if (!$config['graph_colours'][$colours][$colour_iter]) { + $colour_iter = 0; + } + + $colour = $config['graph_colours'][$colours][$colour_iter]; + $colour_iter++; + } + + $descr = rrdtool_escape($rrd['descr'], $descr_len); + + $rrd_options .= ' DEF:'.$rrd['ds'].$i.'='.$rrd['filename'].':'.$rrd['ds'].':AVERAGE '; + + if ($simple_rrd) { + $rrd_options .= ' CDEF:'.$rrd['ds'].$i.'min='.$rrd['ds'].$i.' '; + $rrd_options .= ' CDEF:'.$rrd['ds'].$i.'max='.$rrd['ds'].$i.' '; + } + else { + $rrd_options .= ' DEF:'.$rrd['ds'].$i.'min='.$rrd['filename'].':'.$rrd['ds'].':MIN '; + $rrd_options .= ' DEF:'.$rrd['ds'].$i.'max='.$rrd['filename'].':'.$rrd['ds'].':MAX '; + } + + if ($_GET['previous']) { + $rrd_options .= ' DEF:'.$i.'X='.$rrd['filename'].':'.$rrd['ds'].':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:'.$i."X:$period"; + $thingX .= $seperatorX.$i.'X,UN,0,'.$i.'X,IF'; + $plusesX .= $plusX; + $seperatorX = ','; + $plusX = ',+'; + } + + // Suppress totalling? + if (!$nototal) { + $rrd_options .= ' VDEF:tot'.$rrd['ds'].$i.'='.$rrd['ds'].$i.',TOTAL'; + } + + // This this not the first entry? + if ($i) { + $stack = 'STACK'; + } + + // if we've been passed a multiplier we must make a CDEF based on it! + $g_defname = $rrd['ds']; + if (is_numeric($multiplier)) { + $g_defname = $rrd['ds'].'_cdef'; + $rrd_options .= ' CDEF:'.$g_defname.$i.'='.$rrd['ds'].$i.','.$multiplier.',*'; + $rrd_options .= ' CDEF:'.$g_defname.$i.'min='.$rrd['ds'].$i.'min,'.$multiplier.',*'; + $rrd_options .= ' CDEF:'.$g_defname.$i.'max='.$rrd['ds'].$i.'max,'.$multiplier.',*'; + + // If we've been passed a divider (divisor!) we make a CDEF for it. + } + else if (is_numeric($divider)) { + $g_defname = $rrd['ds'].'_cdef'; + $rrd_options .= ' CDEF:'.$g_defname.$i.'='.$rrd['ds'].$i.','.$divider.',/'; + $rrd_options .= ' CDEF:'.$g_defname.$i.'min='.$rrd['ds'].$i.'min,'.$divider.',/'; + $rrd_options .= ' CDEF:'.$g_defname.$i.'max='.$rrd['ds'].$i.'max,'.$divider.',/'; + } + + // Are our text values related to te multiplier/divisor or not? + if (isset($text_orig) && $text_orig) { + $t_defname = $rrd['ds']; + } + else { + $t_defname = $g_defname; + } + + $rrd_options .= ' AREA:'.$g_defname.$i.'#'.$colour.":'".$descr."':$stack"; + + $rrd_options .= ' GPRINT:'.$t_defname.$i.':LAST:%5.2lf%s GPRINT:'.$t_defname.$i.'min:MIN:%5.2lf%s'; + $rrd_options .= ' GPRINT:'.$t_defname.$i.'max:MAX:%5.2lf%s GPRINT:'.$t_defname.$i.":AVERAGE:'%5.2lf%s\\n'"; + + if (!$nototal) { + $rrd_options .= ' GPRINT:tot'.$rrd['ds'].$i.':%6.2lf%s'.rrdtool_escape($total_units).''; + } + + $rrd_options .= " COMMENT:'\\n'"; +}//end foreach + +if ($_GET['previous'] == 'yes') { + if (is_numeric($multiplier)) { + $rrd_options .= ' CDEF:X='.$thingX.$plusesX.','.$multiplier.',*'; + } + else if (is_numeric($divider)) { + $rrd_options .= ' CDEF:X='.$thingX.$plusesX.','.$divider.',/'; + } + else { + $rrd_options .= ' CDEF:X='.$thingX.$plusesX; + } + + $rrd_options .= ' AREA:X#99999999:'; + $rrd_options .= ' LINE1.25:X#666666:'; +} diff --git a/html/includes/graphs/generic_simplex.inc.php b/html/includes/graphs/generic_simplex.inc.php index ed2562faa..186cc80a0 100644 --- a/html/includes/graphs/generic_simplex.inc.php +++ b/html/includes/graphs/generic_simplex.inc.php @@ -1,122 +1,117 @@ + if ($percentile) { + $rrd_options .= ' '.$percentile.'th %'; + } + + $rrd_options .= "\\n'"; + $rrd_options .= ' LINE1.25:'.$ds.'#'.$colour_line.":'".$line_text."'"; + $rrd_options .= ' GPRINT:'.$ds.':LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:'.$ds.':AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:'.$ds.'_max:MAX:%6.2lf%s'; + + if ($percentile) { + $rrd_options .= ' GPRINT:'.$ds.'_percentile:%6.2lf%s'; + } + + $rrd_options .= "\\\\n"; + $rrd_options .= " COMMENT:\\\\n"; + + if ($print_total) { + $rrd_options .= ' GPRINT:'.$ds.'_tot:Total\ %6.2lf%s\)\\\\l'; + } + + if ($percentile) { + $rrd_options .= ' LINE1:'.$ds.'_percentile#aa0000'; + } + + if ($_GET['previous'] == 'yes') { + $rrd_options .= ' LINE1.25:'.$ds."X#666666:'Prev \\\\n'"; + $rrd_options .= ' AREA:'.$ds.'X#99999966:'; + } +}//end if diff --git a/html/includes/graphs/global/auth.inc.php b/html/includes/graphs/global/auth.inc.php index b0ad7e578..c364820b4 100644 --- a/html/includes/graphs/global/auth.inc.php +++ b/html/includes/graphs/global/auth.inc.php @@ -1,8 +1,5 @@ = "5") -{ - $auth = 1; +if ($_SESSION['userlevel'] >= '5') { + $auth = 1; } - -?> diff --git a/html/includes/graphs/global/bits.inc.php b/html/includes/graphs/global/bits.inc.php index 862b39e50..763a9d103 100644 --- a/html/includes/graphs/global/bits.inc.php +++ b/html/includes/graphs/global/bits.inc.php @@ -1,66 +1,56 @@ +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/global/processor_separate.inc.php b/html/includes/graphs/global/processor_separate.inc.php index 74b80b923..3afd67250 100644 --- a/html/includes/graphs/global/processor_separate.inc.php +++ b/html/includes/graphs/global/processor_separate.inc.php @@ -2,33 +2,29 @@ $i = 0; -foreach (dbFetchRows("SELECT * FROM `processors` AS P, devices AS D WHERE D.device_id = P.device_id") as $proc) -{ - $rrd_filename = $config['rrd_dir'] . "/".$proc['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd"); +foreach (dbFetchRows('SELECT * FROM `processors` AS P, devices AS D WHERE D.device_id = P.device_id') as $proc) { + $rrd_filename = $config['rrd_dir'].'/'.$proc['hostname'].'/'.safename('processor-'.$proc['processor_type'].'-'.$proc['processor_index'].'.rrd'); - if (is_file($rrd_filename)) - { - $descr = short_hrDeviceDescr($proc['processor_descr']); + if (is_file($rrd_filename)) { + $descr = short_hrDeviceDescr($proc['processor_descr']); - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = $descr; - $rrd_list[$i]['ds'] = "usage"; - $rrd_list[$i]['area'] = 1; - $i++; - } + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $descr; + $rrd_list[$i]['ds'] = 'usage'; + $rrd_list[$i]['area'] = 1; + $i++; + } } -$unit_text = "Load %"; +$unit_text = 'Load %'; -$units = '%'; +$units = '%'; $total_units = '%'; -$colours ='mixed'; +$colours = 'mixed'; -$scale_min = "0"; -$scale_max = "100"; +$scale_min = '0'; +$scale_max = '100'; $nototal = 1; -include("includes/graphs/generic_multi_line.inc.php"); - -?> +require 'includes/graphs/generic_multi_line.inc.php'; diff --git a/html/includes/graphs/global/processor_stack.inc.php b/html/includes/graphs/global/processor_stack.inc.php index ffe3d6225..9c205f144 100644 --- a/html/includes/graphs/global/processor_stack.inc.php +++ b/html/includes/graphs/global/processor_stack.inc.php @@ -2,34 +2,30 @@ $i = 0; -foreach (dbFetchRows("SELECT * FROM `processors` AS P, devices AS D WHERE D.device_id = P.device_id") as $proc) -{ - $rrd_filename = $config['rrd_dir'] . "/".$proc['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd"); +foreach (dbFetchRows('SELECT * FROM `processors` AS P, devices AS D WHERE D.device_id = P.device_id') as $proc) { + $rrd_filename = $config['rrd_dir'].'/'.$proc['hostname'].'/'.safename('processor-'.$proc['processor_type'].'-'.$proc['processor_index'].'.rrd'); - if (is_file($rrd_filename)) - { - $descr = short_hrDeviceDescr($proc['processor_descr']); + if (is_file($rrd_filename)) { + $descr = short_hrDeviceDescr($proc['processor_descr']); - $rrd_list[$i]['filename'] = $rrd_filename; - $rrd_list[$i]['descr'] = $descr; - $rrd_list[$i]['ds'] = "usage"; - $i++; - } + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $descr; + $rrd_list[$i]['ds'] = 'usage'; + $i++; + } } -$unit_text = "Load %"; +$unit_text = 'Load %'; -$units = '%'; +$units = '%'; $total_units = '%'; -$colours ='oranges'; +$colours = 'oranges'; -$scale_min = "0"; -$scale_max = "100"; +$scale_min = '0'; +$scale_max = '100'; -$divider = $i; +$divider = $i; $text_orig = 1; -$nototal = 1; +$nototal = 1; -include("includes/graphs/generic_multi_simplex_seperated.inc.php"); - -?> +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/graph.inc.php b/html/includes/graphs/graph.inc.php index 6ba9de57a..19e99c9b6 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/ipsectunnel/auth.inc.php b/html/includes/graphs/ipsectunnel/auth.inc.php index f780ac87a..f5aebe2d3 100644 --- a/html/includes/graphs/ipsectunnel/auth.inc.php +++ b/html/includes/graphs/ipsectunnel/auth.inc.php @@ -1,19 +1,15 @@ diff --git a/html/includes/graphs/ipsectunnel/bits.inc.php b/html/includes/graphs/ipsectunnel/bits.inc.php index cd0fa91fd..ce3e84d36 100644 --- a/html/includes/graphs/ipsectunnel/bits.inc.php +++ b/html/includes/graphs/ipsectunnel/bits.inc.php @@ -1,10 +1,8 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/ipsectunnel/pkts.inc.php b/html/includes/graphs/ipsectunnel/pkts.inc.php index d90d03482..48daf4788 100644 --- a/html/includes/graphs/ipsectunnel/pkts.inc.php +++ b/html/includes/graphs/ipsectunnel/pkts.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/location/auth.inc.php b/html/includes/graphs/location/auth.inc.php index 1cb224e28..d3229e413 100644 --- a/html/includes/graphs/location/auth.inc.php +++ b/html/includes/graphs/location/auth.inc.php @@ -1,13 +1,9 @@ diff --git a/html/includes/graphs/location/bits.inc.php b/html/includes/graphs/location/bits.inc.php index 99e51c14c..53b0a656e 100644 --- a/html/includes/graphs/location/bits.inc.php +++ b/html/includes/graphs/location/bits.inc.php @@ -1,67 +1,57 @@ +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/macaccounting/auth.inc.php b/html/includes/graphs/macaccounting/auth.inc.php index dc1a7e84b..971874116 100644 --- a/html/includes/graphs/macaccounting/auth.inc.php +++ b/html/includes/graphs/macaccounting/auth.inc.php @@ -1,43 +1,45 @@ "); - print_r($acc); - echo(""); - } - - if (is_array($acc)) - { - - if ($auth || port_permitted($acc['port_id'])) - { - if ($debug) { echo($config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd")); } - - if (is_file($config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"))) - { - if ($debug) { echo("exists"); } - $rrd_filename = $config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); - $port = get_port_by_id($acc['port_id']); - $device = device_by_id_cache($port['device_id']); - $title = generate_device_link($device); - $title .= " :: Port ".generate_port_link($port); - $title .= " :: " . formatMac($acc['mac']); - $auth = TRUE; - } else { - graph_error("file not found"); - } - } else { - graph_error("unauthenticated"); + if ($debug) { + echo '
';
+        print_r($acc);
+        echo '
'; + } + + if (is_array($acc)) { + if ($auth || port_permitted($acc['port_id'])) { + if ($debug) { + echo $config['rrd_dir'].'/'.$acc['hostname'].'/'.safename('cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'); + } + + if (is_file($config['rrd_dir'].'/'.$acc['hostname'].'/'.safename('cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'))) { + if ($debug) { + echo 'exists'; + } + + $rrd_filename = $config['rrd_dir'].'/'.$acc['hostname'].'/'.safename('cip-'.$acc['ifIndex'].'-'.$acc['mac'].'.rrd'); + $port = get_port_by_id($acc['port_id']); + $device = device_by_id_cache($port['device_id']); + $title = generate_device_link($device); + $title .= ' :: Port '.generate_port_link($port); + $title .= ' :: '.formatMac($acc['mac']); + $auth = true; + } + else { + graph_error('file not found'); + } + } + else { + graph_error('unauthenticated'); + } + } + else { + graph_error('entry not found'); } - } else { - graph_error("entry not found"); - } -} else { - graph_error("invalid id"); } -?> +else { + graph_error('invalid id'); +} diff --git a/html/includes/graphs/macaccounting/bits.inc.php b/html/includes/graphs/macaccounting/bits.inc.php index e0f0f5e0a..7b650081b 100644 --- a/html/includes/graphs/macaccounting/bits.inc.php +++ b/html/includes/graphs/macaccounting/bits.inc.php @@ -1,8 +1,6 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/macaccounting/pkts.inc.php b/html/includes/graphs/macaccounting/pkts.inc.php index 2a9457642..b0f0eb6c7 100644 --- a/html/includes/graphs/macaccounting/pkts.inc.php +++ b/html/includes/graphs/macaccounting/pkts.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/mempool/auth.inc.php b/html/includes/graphs/mempool/auth.inc.php index 142952551..bd507b89c 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/mempool/usage.inc.php b/html/includes/graphs/mempool/usage.inc.php index 6fec6aa98..e3bde5516 100644 --- a/html/includes/graphs/mempool/usage.inc.php +++ b/html/includes/graphs/mempool/usage.inc.php @@ -1,33 +1,33 @@ "500") -{ - $descr_len=13; -} else { - $descr_len=8; - $descr_len += round(($width - 250) / 8); +if ($width > '500') { + $descr_len = 13; +} +else { + $descr_len = 8; + $descr_len += round(($width - 250) / 8); } -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Total Used Free( Min Max Ave)'"; - $rrd_options .= " COMMENT:'\l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Total Used Free\l'"; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Total Used Free( Min Max Ave)'"; + $rrd_options .= " COMMENT:'\l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))."Total Used Free\l'"; } $descr = rrdtool_escape(short_hrDeviceDescr($mempool['mempool_descr']), $descr_len); -$perc = round($mempool['mempool_perc'], 0); +$perc = round($mempool['mempool_perc'], 0); $background = get_percentage_colours($perc); $rrd_options .= " DEF:$mempool[mempool_id]used=$rrd_filename:used:AVERAGE"; @@ -35,33 +35,31 @@ $rrd_options .= " DEF:$mempool[mempool_id]free=$rrd_filename:free:AVERAGE"; $rrd_options .= " CDEF:$mempool[mempool_id]size=$mempool[mempool_id]used,$mempool[mempool_id]free,+"; $rrd_options .= " CDEF:$mempool[mempool_id]perc=$mempool[mempool_id]used,$mempool[mempool_id]size,/,100,*"; $rrd_options .= " CDEF:$mempool[mempool_id]percx=100,$mempool[mempool_id]perc,-"; -$rrd_options .= " AREA:$mempool[mempool_id]perc#" . $background['right'] . ":"; +$rrd_options .= " AREA:$mempool[mempool_id]perc#".$background['right'].':'; -if($width > "500") -{ - $rrd_options .= " LINE1.25:$mempool[mempool_id]perc#" . $background['left'] . ":'$descr'"; - $rrd_options .= " GPRINT:$mempool[mempool_id]size:LAST:%6.2lf%sB"; - $rrd_options .= " GPRINT:$mempool[mempool_id]used:LAST:%6.2lf%sB"; - $rrd_options .= " GPRINT:$mempool[mempool_id]free:LAST:%6.2lf%sB"; - $rrd_options .= " GPRINT:$mempool[mempool_id]free:MIN:%5.2lf%sB"; - $rrd_options .= " GPRINT:$mempool[mempool_id]free:MAX:%5.2lf%sB"; - $rrd_options .= " GPRINT:$mempool[mempool_id]free:AVERAGE:%5.2lf%sB\\\\n"; - $rrd_options .= " COMMENT:'".substr(str_pad('', $descr_len+12),0,$descr_len+12)." '"; - $rrd_options .= " GPRINT:$mempool[mempool_id]perc:LAST:'%5.2lf%% '"; - $rrd_options .= " GPRINT:$mempool[mempool_id]percx:LAST:'%5.2lf%% '"; - $rrd_options .= " GPRINT:$mempool[mempool_id]perc:MIN:'%5.2lf%% '"; - $rrd_options .= " GPRINT:$mempool[mempool_id]perc:MAX:'%5.2lf%% '"; - $rrd_options .= " GPRINT:$mempool[mempool_id]perc:AVERAGE:%5.2lf%%\\\\n"; -} else { - $rrd_options .= " LINE1.25:$mempool[mempool_id]perc#" . $background['left'] . ":'$descr'"; - $rrd_options .= " GPRINT:$mempool[mempool_id]size:LAST:%6.2lf%sB"; - $rrd_options .= " GPRINT:$mempool[mempool_id]used:LAST:%6.2lf%sB"; - $rrd_options .= " GPRINT:$mempool[mempool_id]free:LAST:%6.2lf%sB"; - $rrd_options .= " COMMENT:'\l'"; - $rrd_options .= " COMMENT:'".substr(str_pad('', $descr_len+12),0,$descr_len+12)." '"; - $rrd_options .= " GPRINT:$mempool[mempool_id]perc:LAST:'%5.2lf%% '"; - $rrd_options .= " GPRINT:$mempool[mempool_id]percx:LAST:'%5.2lf%% '"; - $rrd_options .= " COMMENT:'\l'"; +if ($width > '500') { + $rrd_options .= " LINE1.25:$mempool[mempool_id]perc#".$background['left'].":'$descr'"; + $rrd_options .= " GPRINT:$mempool[mempool_id]size:LAST:%6.2lf%sB"; + $rrd_options .= " GPRINT:$mempool[mempool_id]used:LAST:%6.2lf%sB"; + $rrd_options .= " GPRINT:$mempool[mempool_id]free:LAST:%6.2lf%sB"; + $rrd_options .= " GPRINT:$mempool[mempool_id]free:MIN:%5.2lf%sB"; + $rrd_options .= " GPRINT:$mempool[mempool_id]free:MAX:%5.2lf%sB"; + $rrd_options .= " GPRINT:$mempool[mempool_id]free:AVERAGE:%5.2lf%sB\\\\n"; + $rrd_options .= " COMMENT:'".substr(str_pad('', ($descr_len + 12)), 0, ($descr_len + 12))." '"; + $rrd_options .= " GPRINT:$mempool[mempool_id]perc:LAST:'%5.2lf%% '"; + $rrd_options .= " GPRINT:$mempool[mempool_id]percx:LAST:'%5.2lf%% '"; + $rrd_options .= " GPRINT:$mempool[mempool_id]perc:MIN:'%5.2lf%% '"; + $rrd_options .= " GPRINT:$mempool[mempool_id]perc:MAX:'%5.2lf%% '"; + $rrd_options .= " GPRINT:$mempool[mempool_id]perc:AVERAGE:%5.2lf%%\\\\n"; } - -?> +else { + $rrd_options .= " LINE1.25:$mempool[mempool_id]perc#".$background['left'].":'$descr'"; + $rrd_options .= " GPRINT:$mempool[mempool_id]size:LAST:%6.2lf%sB"; + $rrd_options .= " GPRINT:$mempool[mempool_id]used:LAST:%6.2lf%sB"; + $rrd_options .= " GPRINT:$mempool[mempool_id]free:LAST:%6.2lf%sB"; + $rrd_options .= " COMMENT:'\l'"; + $rrd_options .= " COMMENT:'".substr(str_pad('', ($descr_len + 12)), 0, ($descr_len + 12))." '"; + $rrd_options .= " GPRINT:$mempool[mempool_id]perc:LAST:'%5.2lf%% '"; + $rrd_options .= " GPRINT:$mempool[mempool_id]percx:LAST:'%5.2lf%% '"; + $rrd_options .= " COMMENT:'\l'"; +}//end if diff --git a/html/includes/graphs/multiport/auth.inc.php b/html/includes/graphs/multiport/auth.inc.php index 3ffe44929..603c6a945 100644 --- a/html/includes/graphs/multiport/auth.inc.php +++ b/html/includes/graphs/multiport/auth.inc.php @@ -1,21 +1,11 @@ +$title = 'Multi Port :: '; diff --git a/html/includes/graphs/multiport/bits.inc.php b/html/includes/graphs/multiport/bits.inc.php index 907bd06ad..de3206c23 100644 --- a/html/includes/graphs/multiport/bits.inc.php +++ b/html/includes/graphs/multiport/bits.inc.php @@ -2,30 +2,25 @@ $i = 1; -foreach (explode(",", $vars['id']) as $ifid) -{ - if (strstr($ifid, "!")) - { - $rrd_inverted[$i] = TRUE; - $ifid = str_replace("!", "", $ifid); - } +foreach (explode(',', $vars['id']) as $ifid) { + if (strstr($ifid, '!')) { + $rrd_inverted[$i] = true; + $ifid = str_replace('!', '', $ifid); + } - $int = dbFetchRow("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id", array($ifid)); - if (is_file($config['rrd_dir'] . "/" . $int['hostname'] . "/port-" . safename($int['ifIndex'] . ".rrd"))) - { - $rrd_filenames[$i] = $config['rrd_dir'] . "/" . $int['hostname'] . "/port-" . safename($int['ifIndex'] . ".rrd"); - $i++; - } + $int = dbFetchRow('SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + if (is_file($config['rrd_dir'].'/'.$int['hostname'].'/port-'.safename($int['ifIndex'].'.rrd'))) { + $rrd_filenames[$i] = $config['rrd_dir'].'/'.$int['hostname'].'/port-'.safename($int['ifIndex'].'.rrd'); + $i++; + } } -$ds_in = "INOCTETS"; -$ds_out = "OUTOCTETS"; +$ds_in = 'INOCTETS'; +$ds_out = 'OUTOCTETS'; -$colour_line_in = "006600"; -$colour_line_out = "000099"; -$colour_area_in = "CDEB8B"; -$colour_area_out = "C3D9FF"; +$colour_line_in = '006600'; +$colour_line_out = '000099'; +$colour_area_in = 'CDEB8B'; +$colour_area_out = 'C3D9FF'; -include("includes/graphs/generic_multi_data.inc.php"); - -?> +require 'includes/graphs/generic_multi_data.inc.php'; diff --git a/html/includes/graphs/multiport/bits_duo.inc.php b/html/includes/graphs/multiport/bits_duo.inc.php index 8393ece82..205ca3834 100644 --- a/html/includes/graphs/multiport/bits_duo.inc.php +++ b/html/includes/graphs/multiport/bits_duo.inc.php @@ -1,122 +1,133 @@ +$rrd_options .= ' CDEF:'.$in.'octets='.$in_thing.$pluses; +$rrd_options .= ' CDEF:'.$out.'octets='.$out_thing.$pluses; +$rrd_options .= ' CDEF:'.$in.'octetsb='.$in_thingb.$plusesb; +$rrd_options .= ' CDEF:'.$out.'octetsb='.$out_thingb.$plusesb; +$rrd_options .= ' CDEF:doutoctets=outoctets,-1,*'; +$rrd_options .= ' CDEF:inbits=inoctets,8,*'; +$rrd_options .= ' CDEF:outbits=outoctets,8,*'; +$rrd_options .= ' CDEF:doutbits=doutoctets,8,*'; +$rrd_options .= ' CDEF:doutoctetsb=outoctetsb,-1,*'; +$rrd_options .= ' CDEF:inbitsb=inoctetsb,8,*'; +$rrd_options .= ' CDEF:outbitsb=outoctetsb,8,*'; +$rrd_options .= ' CDEF:doutbitsb=doutoctetsb,8,*'; +$rrd_options .= ' CDEF:inbits_tot=inbits,inbitsb,+'; +$rrd_options .= ' CDEF:outbits_tot=outbits,outbitsb,+'; +$rrd_options .= ' CDEF:doutbits_tot=outbits_tot,-1,*'; +$rrd_options .= ' CDEF:nothing=outbits_tot,outbits_tot,-'; + +if ($legend == 'no') { + $rrd_options .= ' AREA:inbits_tot#cdeb8b:'; + $rrd_options .= ' AREA:inbits#ffcc99:'; + $rrd_options .= ' AREA:doutbits_tot#C3D9FF:'; + $rrd_options .= ' AREA:doutbits#ffcc99:'; + $rrd_options .= ' LINE1:inbits#aa9966:'; + $rrd_options .= ' LINE1:doutbits#aa9966:'; + // $rrd_options .= " LINE1:inbitsb#006600:"; + // $rrd_options .= " LINE1:doutbitsb#000066:"; + $rrd_options .= ' LINE1.25:inbits_tot#006600:'; + $rrd_options .= ' LINE1.25:doutbits_tot#000099:'; + $rrd_options .= ' LINE0.5:nothing#555555:'; +} +else { + $rrd_options .= " COMMENT:bps\ \ \ \ \ \ \ \ \ \ \ \ Current\ \ \ Average\ \ \ \ \ \ Min\ \ \ \ \ \ Max\\\\n"; + $rrd_options .= ' AREA:inbits_tot#cdeb8b:Peering\ In\ '; + $rrd_options .= ' GPRINT:inbitsb:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbitsb:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbitsb:MIN:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbitsb:MAX:%6.2lf%s\\\\l'; + $rrd_options .= ' AREA:doutbits_tot#C3D9FF:'; + $rrd_options .= ' COMMENT:\ \ \ \ \ \ \ \ \ \ Out'; + $rrd_options .= ' GPRINT:outbitsb:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbitsb:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbitsb:MIN:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbitsb:MAX:%6.2lf%s\\\\l'; + + $rrd_options .= ' AREA:inbits#ffcc99:Transit\ In\ '; + $rrd_options .= ' GPRINT:inbits:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits:MIN:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits:MAX:%6.2lf%s\\\\l'; + $rrd_options .= ' AREA:doutbits#ffcc99:'; + $rrd_options .= ' COMMENT:\ \ \ \ \ \ \ \ \ \ Out'; + $rrd_options .= ' GPRINT:outbits:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits:MIN:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits:MAX:%6.2lf%s\\\\l'; + + $rrd_options .= ' COMMENT:Total\ \ \ \ \ In\ '; + $rrd_options .= ' GPRINT:inbits_tot:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits_tot:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits_tot:MIN:%6.2lf%s'; + $rrd_options .= ' GPRINT:inbits_tot:MAX:%6.2lf%s\\\\l'; + $rrd_options .= ' COMMENT:\ \ \ \ \ \ \ \ \ \ Out'; + $rrd_options .= ' GPRINT:outbits_tot:LAST:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits_tot:AVERAGE:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits_tot:MIN:%6.2lf%s'; + $rrd_options .= ' GPRINT:outbits_tot:MAX:%6.2lf%s\\\\l'; + + $rrd_options .= ' LINE1:inbits#aa9966:'; + $rrd_options .= ' LINE1:doutbits#aa9966:'; + // $rrd_options .= " LINE1.25:inbitsb#006600:"; + // $rrd_options .= " LINE1.25:doutbitsb#006600:"; + $rrd_options .= ' LINE1.25:inbits_tot#006600:'; + $rrd_options .= ' LINE1.25:doutbits_tot#000099:'; + $rrd_options .= ' LINE0.5:nothing#555555:'; +}//end if + +if ($width <= '300') { + $rrd_options .= ' --font LEGEND:7:'.$config['mono_font'].' --font AXIS:6:'.$config['mono_font'].' --font-render-mode normal'; +} diff --git a/html/includes/graphs/multiport/bits_separate.inc.php b/html/includes/graphs/multiport/bits_separate.inc.php index 3419078ad..d54259d02 100644 --- a/html/includes/graphs/multiport/bits_separate.inc.php +++ b/html/includes/graphs/multiport/bits_separate.inc.php @@ -2,30 +2,26 @@ $i = 0; -foreach (explode(",", $vars['id']) as $ifid) -{ - $port = dbFetchRow("SELECT * FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id", array($ifid)); - if (is_file($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"))) - { - $port = ifLabel($port); - $rrd_list[$i]['filename'] = $config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"); - $rrd_list[$i]['descr'] = $port['hostname'] . " " . $port['ifDescr']; - $rrd_list[$i]['descr_in'] = $port['hostname']; - $rrd_list[$i]['descr_out'] = makeshortif($port['label']); - $i++; - } +foreach (explode(',', $vars['id']) as $ifid) { + $port = dbFetchRow('SELECT * FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + if (is_file($config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'))) { + $port = ifLabel($port); + $rrd_list[$i]['filename'] = $config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'); + $rrd_list[$i]['descr'] = $port['hostname'].' '.$port['ifDescr']; + $rrd_list[$i]['descr_in'] = $port['hostname']; + $rrd_list[$i]['descr_out'] = makeshortif($port['label']); + $i++; + } } -$units = 'bps'; -$total_units='B'; -$colours_in='greens'; -$multiplier = "8"; +$units = 'bps'; +$total_units = 'B'; +$colours_in = 'greens'; +$multiplier = '8'; $colours_out = 'blues'; $nototal = 1; -$ds_in = "INOCTETS"; -$ds_out = "OUTOCTETS"; +$ds_in = 'INOCTETS'; +$ds_out = 'OUTOCTETS'; -include("includes/graphs/generic_multi_bits_separated.inc.php"); - -?> +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/multiport/bits_trio.inc.php b/html/includes/graphs/multiport/bits_trio.inc.php index 4506c67b2..a1112a677 100644 --- a/html/includes/graphs/multiport/bits_trio.inc.php +++ b/html/includes/graphs/multiport/bits_trio.inc.php @@ -1,172 +1,197 @@ diff --git a/html/includes/graphs/munin/auth.inc.php b/html/includes/graphs/munin/auth.inc.php index cf894de65..df77b06e7 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 1d6be7dc9..9b634813b 100644 --- a/html/includes/graphs/munin/graph.inc.php +++ b/html/includes/graphs/munin/graph.inc.php @@ -2,63 +2,59 @@ // Attempt to draw a graph out of DSes we've collected from Munin plugins. // Reverse engineering ftw! - $scale_min = 0; -include("includes/graphs/common.inc.php"); +require 'includes/graphs/common.inc.php'; -if($width > "500") -{ - $descr_len=24; -} else { - $descr_len=14; - $descr_len += round(($width - 230) / 8.2); +if ($width > '500') { + $descr_len = 24; +} +else { + $descr_len = 14; + $descr_len += round(($width - 230) / 8.2); } -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($mplug['mplug_vlabel'], $descr_len),0,$descr_len)." Current Average Maximum\l'"; - $rrd_options .= " COMMENT:'\l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($mplug['mplug_vlabel'], $descr_len),0,$descr_len)." Current Average Maximum\l'"; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($mplug['mplug_vlabel'], $descr_len), 0, $descr_len)." Current Average Maximum\l'"; + $rrd_options .= " COMMENT:'\l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($mplug['mplug_vlabel'], $descr_len), 0, $descr_len)." Current Average Maximum\l'"; } $c_i = 0; -$dbq = dbFetchRows("SELECT * FROM `munin_plugins_ds` WHERE `mplug_id` = ?", array($mplug['mplug_id'])); -foreach ($dbq as $ds) -{ - $ds_filename = $plugfile."_".$ds['ds_name'].".rrd"; - $ds_name = $ds['ds_name']; +$dbq = dbFetchRows('SELECT * FROM `munin_plugins_ds` WHERE `mplug_id` = ?', array($mplug['mplug_id'])); +foreach ($dbq as $ds) { + $ds_filename = $plugfile.'_'.$ds['ds_name'].'.rrd'; + $ds_name = $ds['ds_name']; - $cmd_def .= " DEF:".$ds['ds_name']."=".$ds_filename.":val:AVERAGE"; + $cmd_def .= ' DEF:'.$ds['ds_name'].'='.$ds_filename.':val:AVERAGE'; - if (!empty($ds['ds_cdef'])) - { - $cmd_cdef .= ""; - $ds_name = $ds['ds_name']."_cdef"; - } - - if ($ds['ds_graph'] == "yes") - { - if (empty($ds['colour'])) - { - if (!$config['graph_colours']['mixed'][$c_i]) { $c_i = 0; } - $colour=$config['graph_colours']['mixed'][$c_i]; $c_i++; - } else { - $colour = $ds['colour']; + if (!empty($ds['ds_cdef'])) { + $cmd_cdef .= ''; + $ds_name = $ds['ds_name'].'_cdef'; } - $descr = rrdtool_escape($ds['ds_label'], $descr_len); + if ($ds['ds_graph'] == 'yes') { + if (empty($ds['colour'])) { + if (!$config['graph_colours']['mixed'][$c_i]) { + $c_i = 0; + } - $cmd_graph .= ' '.$ds['ds_draw'].':'.$ds_name.'#'.$colour.':"'.$descr.'"'; - $cmd_graph .= ' GPRINT:'.$ds_name.':LAST:"%6.2lf%s"'; - $cmd_graph .= ' GPRINT:'.$ds_name.':AVERAGE:"%6.2lf%s"'; - $cmd_graph .= ' GPRINT:'.$ds_name.':MAX:"%6.2lf%s\\n"'; + $colour = $config['graph_colours']['mixed'][$c_i]; + $c_i++; + } + else { + $colour = $ds['colour']; + } - } + $descr = rrdtool_escape($ds['ds_label'], $descr_len); -} + $cmd_graph .= ' '.$ds['ds_draw'].':'.$ds_name.'#'.$colour.':"'.$descr.'"'; + $cmd_graph .= ' GPRINT:'.$ds_name.':LAST:"%6.2lf%s"'; + $cmd_graph .= ' GPRINT:'.$ds_name.':AVERAGE:"%6.2lf%s"'; + $cmd_graph .= ' GPRINT:'.$ds_name.':MAX:"%6.2lf%s\\n"'; + } +}//end foreach -$rrd_options .= $cmd_def . $cmd_cdef . $cmd_graph; - -?> +$rrd_options .= $cmd_def.$cmd_cdef.$cmd_graph; diff --git a/html/includes/graphs/netscalervsvr/auth.inc.php b/html/includes/graphs/netscalervsvr/auth.inc.php index 6b90b0632..dbeb11450 100644 --- a/html/includes/graphs/netscalervsvr/auth.inc.php +++ b/html/includes/graphs/netscalervsvr/auth.inc.php @@ -1,20 +1,15 @@ diff --git a/html/includes/graphs/netscalervsvr/bits.inc.php b/html/includes/graphs/netscalervsvr/bits.inc.php index 17707bbb3..58ef562b6 100644 --- a/html/includes/graphs/netscalervsvr/bits.inc.php +++ b/html/includes/graphs/netscalervsvr/bits.inc.php @@ -1,8 +1,6 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/netscalervsvr/conns.inc.php b/html/includes/graphs/netscalervsvr/conns.inc.php index 9f17d874a..38927dc18 100644 --- a/html/includes/graphs/netscalervsvr/conns.inc.php +++ b/html/includes/graphs/netscalervsvr/conns.inc.php @@ -1,22 +1,20 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/netscalervsvr/hitmiss.inc.php b/html/includes/graphs/netscalervsvr/hitmiss.inc.php index 31e557dcb..cc4e63395 100644 --- a/html/includes/graphs/netscalervsvr/hitmiss.inc.php +++ b/html/includes/graphs/netscalervsvr/hitmiss.inc.php @@ -1,23 +1,23 @@ +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/netscalervsvr/pkts.inc.php b/html/includes/graphs/netscalervsvr/pkts.inc.php index 988e0c2f0..dd5ccec32 100644 --- a/html/includes/graphs/netscalervsvr/pkts.inc.php +++ b/html/includes/graphs/netscalervsvr/pkts.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/netscalervsvr/reqs.inc.php b/html/includes/graphs/netscalervsvr/reqs.inc.php index d39c6f9cb..758536538 100644 --- a/html/includes/graphs/netscalervsvr/reqs.inc.php +++ b/html/includes/graphs/netscalervsvr/reqs.inc.php @@ -1,22 +1,20 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/old_generic_simplex.inc.php b/html/includes/graphs/old_generic_simplex.inc.php index be70e9a87..24a93147c 100644 --- a/html/includes/graphs/old_generic_simplex.inc.php +++ b/html/includes/graphs/old_generic_simplex.inc.php @@ -2,91 +2,90 @@ // Draw generic bits graph // args: ds_in, ds_out, rrd_filename, bg, legend, from, to, width, height, inverse, percentile +require 'includes/graphs/common.inc.php'; -include("includes/graphs/common.inc.php"); +$unit_text = str_pad(truncate($unit_text, 18, ''), 18); +$line_text = str_pad(truncate($line_text, 12, ''), 12); -$unit_text = str_pad(truncate($unit_text,18,''),18); -$line_text = str_pad(truncate($line_text,12,''),12); +if ($multiplier) { + if (empty($multiplier_action)) { + $multiplier_action = '*'; + } -if ($multiplier) -{ - $rrd_options .= " DEF:".$ds."_o=".$rrd_filename.":".$ds.":AVERAGE"; - $rrd_options .= " CDEF:".$ds."=".$ds."_o,$multiplier,*"; -} else { - $rrd_options .= " DEF:".$ds."=".$rrd_filename.":".$ds.":AVERAGE"; + $rrd_options .= ' DEF:'.$ds.'_o='.$rrd_filename.':'.$ds.':AVERAGE'; + $rrd_options .= ' CDEF:'.$ds.'='.$ds."_o,$multiplier,$multiplier_action"; } -if ($print_total) -{ - $rrd_options .= " VDEF:".$ds."_total=ds,TOTAL"; +else { + $rrd_options .= ' DEF:'.$ds.'='.$rrd_filename.':'.$ds.':AVERAGE'; } -if ($percentile) -{ - $rrd_options .= " VDEF:".$ds."_percentile=".$ds.",".$percentile.",PERCENT"; +if ($print_total) { + $rrd_options .= ' VDEF:'.$ds.'_total=ds,TOTAL'; } -if($_GET['previous'] == "yes") -{ - if ($multiplier) - { - $rrd_options .= " DEF:".$ds."_oX=".$rrd_filename.":".$ds.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:".$ds."_oX:$period"; - $rrd_options .= " CDEF:".$ds."X=".$ds."_oX,$multiplier,*"; - } else { - $rrd_options .= " DEF:".$ds."X=".$rrd_filename.":".$ds.":AVERAGE:start=".$prev_from.":end=".$from; - $rrd_options .= " SHIFT:".$ds."X:$period"; - } - if ($print_total) - { - $rrd_options .= " VDEF:".$ds."_totalX=ds,TOTAL"; - } - if ($percentile) - { - $rrd_options .= " VDEF:".$ds."_percentileX=".$ds.",".$percentile.",PERCENT"; - } -# if ($graph_max) -# { -# $rrd_options .= " AREA:".$ds."_max#".$colour_area_max.":"; -# } +if ($percentile) { + $rrd_options .= ' VDEF:'.$ds.'_percentile='.$ds.','.$percentile.',PERCENT'; } -$rrd_options .= " AREA:".$ds."#".$colour_area.":"; +if ($_GET['previous'] == 'yes') { + if ($multiplier) { + if (empty($multiplier_action)) { + $multiplier_action = '*'; + } -$rrd_options .= " COMMENT:'".$unit_text."Now Ave Max"; + $rrd_options .= ' DEF:'.$ds.'_oX='.$rrd_filename.':'.$ds.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:'.$ds."_oX:$period"; + $rrd_options .= ' CDEF:'.$ds.'X='.$ds."_oX,$multiplier,*"; + } + else { + $rrd_options .= ' DEF:'.$ds.'X='.$rrd_filename.':'.$ds.':AVERAGE:start='.$prev_from.':end='.$from; + $rrd_options .= ' SHIFT:'.$ds."X:$period"; + } -if ($percentile) -{ - $rrd_options .= " ".$percentile."th %"; + if ($print_total) { + $rrd_options .= ' VDEF:'.$ds.'_totalX=ds,TOTAL'; + } + + if ($percentile) { + $rrd_options .= ' VDEF:'.$ds.'_percentileX='.$ds.','.$percentile.',PERCENT'; + } + + // if ($graph_max) + // { + // $rrd_options .= " AREA:".$ds."_max#".$colour_area_max.":"; + // } +}//end if + +$rrd_options .= ' AREA:'.$ds.'#'.$colour_area.':'; + +$rrd_options .= " COMMENT:'".$unit_text.'Now Ave Max'; + +if ($percentile) { + $rrd_options .= ' '.$percentile.'th %'; } $rrd_options .= "\\n'"; -$rrd_options .= " LINE1.25:".$ds."#".$colour_line.":'".$line_text."'"; -$rrd_options .= " GPRINT:".$ds.":LAST:%6.2lf%s"; -$rrd_options .= " GPRINT:".$ds.":AVERAGE:%6.2lf%s"; -$rrd_options .= " GPRINT:".$ds.":MAX:%6.2lf%s"; +$rrd_options .= ' LINE1.25:'.$ds.'#'.$colour_line.":'".$line_text."'"; +$rrd_options .= ' GPRINT:'.$ds.':LAST:%6.2lf%s'; +$rrd_options .= ' GPRINT:'.$ds.':AVERAGE:%6.2lf%s'; +$rrd_options .= ' GPRINT:'.$ds.':MAX:%6.2lf%s'; -if ($percentile) -{ - $rrd_options .= " GPRINT:".$ds."_percentile:%6.2lf%s"; +if ($percentile) { + $rrd_options .= ' GPRINT:'.$ds.'_percentile:%6.2lf%s'; } $rrd_options .= "\\\\n"; $rrd_options .= " COMMENT:\\\\n"; -if ($print_total) -{ - $rrd_options .= " GPRINT:".$ds."_tot:Total\ %6.2lf%s\)\\\\l"; +if ($print_total) { + $rrd_options .= ' GPRINT:'.$ds.'_tot:Total\ %6.2lf%s\)\\\\l'; } -if ($percentile) -{ - $rrd_options .= " LINE1:".$ds."_percentile#aa0000"; +if ($percentile) { + $rrd_options .= ' LINE1:'.$ds.'_percentile#aa0000'; } -if($_GET['previous'] == "yes") -{ - $rrd_options .= " LINE1.25:".$ds."X#666666:'Prev \\\\n'"; - $rrd_options .= " AREA:".$ds."X#99999966:"; +if ($_GET['previous'] == 'yes') { + $rrd_options .= ' LINE1.25:'.$ds."X#666666:'Prev \\\\n'"; + $rrd_options .= ' AREA:'.$ds.'X#99999966:'; } - -?> diff --git a/html/includes/graphs/port/adsl_attainable.inc.php b/html/includes/graphs/port/adsl_attainable.inc.php index 8ca0186f2..ad84314a0 100644 --- a/html/includes/graphs/port/adsl_attainable.inc.php +++ b/html/includes/graphs/port/adsl_attainable.inc.php @@ -1,28 +1,25 @@ \ No newline at end of file diff --git a/html/includes/graphs/port/adsl_attenuation.inc.php b/html/includes/graphs/port/adsl_attenuation.inc.php index 1c30b4a48..74cb1e2d3 100644 --- a/html/includes/graphs/port/adsl_attenuation.inc.php +++ b/html/includes/graphs/port/adsl_attenuation.inc.php @@ -1,28 +1,25 @@ \ No newline at end of file diff --git a/html/includes/graphs/port/adsl_power.inc.php b/html/includes/graphs/port/adsl_power.inc.php index eb5fd36dc..5b7d8957a 100644 --- a/html/includes/graphs/port/adsl_power.inc.php +++ b/html/includes/graphs/port/adsl_power.inc.php @@ -1,28 +1,25 @@ \ No newline at end of file diff --git a/html/includes/graphs/port/adsl_snr.inc.php b/html/includes/graphs/port/adsl_snr.inc.php index adf8f325e..9c369cda6 100644 --- a/html/includes/graphs/port/adsl_snr.inc.php +++ b/html/includes/graphs/port/adsl_snr.inc.php @@ -1,28 +1,25 @@ diff --git a/html/includes/graphs/port/adsl_speed.inc.php b/html/includes/graphs/port/adsl_speed.inc.php index da0c4b20b..25a080980 100644 --- a/html/includes/graphs/port/adsl_speed.inc.php +++ b/html/includes/graphs/port/adsl_speed.inc.php @@ -1,28 +1,25 @@ \ No newline at end of file diff --git a/html/includes/graphs/port/auth.inc.php b/html/includes/graphs/port/auth.inc.php index a11959eb3..68114f8c4 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/bits.inc.php b/html/includes/graphs/port/bits.inc.php index 8101cb933..c24f376dd 100644 --- a/html/includes/graphs/port/bits.inc.php +++ b/html/includes/graphs/port/bits.inc.php @@ -1,8 +1,6 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/port/errors.inc.php b/html/includes/graphs/port/errors.inc.php index 8f26b14b4..bb9e8b0a2 100644 --- a/html/includes/graphs/port/errors.inc.php +++ b/html/includes/graphs/port/errors.inc.php @@ -1,30 +1,28 @@ \ No newline at end of file +require 'includes/graphs/generic_multi_seperated.inc.php'; diff --git a/html/includes/graphs/port/etherlike.inc.php b/html/includes/graphs/port/etherlike.inc.php index c021b1e73..b997b3050 100644 --- a/html/includes/graphs/port/etherlike.inc.php +++ b/html/includes/graphs/port/etherlike.inc.php @@ -1,34 +1,39 @@ +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/port/mac_acc_total.inc.php b/html/includes/graphs/port/mac_acc_total.inc.php index c00d5ade7..eb9f0622a 100644 --- a/html/includes/graphs/port/mac_acc_total.inc.php +++ b/html/includes/graphs/port/mac_acc_total.inc.php @@ -1,108 +1,134 @@ +$rrd_options .= ' HRULE:0#999999'; diff --git a/html/includes/graphs/port/nupkts.inc.php b/html/includes/graphs/port/nupkts.inc.php index 1614b5f5e..6b8d11b2d 100644 --- a/html/includes/graphs/port/nupkts.inc.php +++ b/html/includes/graphs/port/nupkts.inc.php @@ -1,63 +1,58 @@ + include 'includes/graphs/generic_duplex.inc.php'; +}//end if diff --git a/html/includes/graphs/port/pagp_bits.inc.php b/html/includes/graphs/port/pagp_bits.inc.php index 43e715ad6..6c5663b08 100644 --- a/html/includes/graphs/port/pagp_bits.inc.php +++ b/html/includes/graphs/port/pagp_bits.inc.php @@ -1,28 +1,23 @@ +require 'includes/graphs/generic_multi_bits_separated.inc.php'; diff --git a/html/includes/graphs/port/upkts.inc.php b/html/includes/graphs/port/upkts.inc.php index e8cf22bdc..b0578c323 100644 --- a/html/includes/graphs/port/upkts.inc.php +++ b/html/includes/graphs/port/upkts.inc.php @@ -1,19 +1,17 @@ \ No newline at end of file +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/graphs/processor/auth.inc.php b/html/includes/graphs/processor/auth.inc.php index e014f0ab1..d92544725 100644 --- a/html/includes/graphs/processor/auth.inc.php +++ b/html/includes/graphs/processor/auth.inc.php @@ -1,14 +1,11 @@ diff --git a/html/includes/graphs/processor/usage.inc.php b/html/includes/graphs/processor/usage.inc.php index 3812a1432..5954685d7 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 6f0a1e274..d166efd19 100644 --- a/html/includes/graphs/rserver/auth.inc.php +++ b/html/includes/graphs/rserver/auth.inc.php @@ -1,20 +1,16 @@ diff --git a/html/includes/graphs/rserver/curr.inc.php b/html/includes/graphs/rserver/curr.inc.php index f3cc6d9ad..685e3b7f8 100644 --- a/html/includes/graphs/rserver/curr.inc.php +++ b/html/includes/graphs/rserver/curr.inc.php @@ -1,24 +1,21 @@ +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 291cdd396..60f544bba 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 e4efdc81f..9d39f6bce 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/screenos_sessions.inc.php b/html/includes/graphs/screenos_sessions.inc.php index e33da7f34..24117d9d0 100644 --- a/html/includes/graphs/screenos_sessions.inc.php +++ b/html/includes/graphs/screenos_sessions.inc.php @@ -1,30 +1,29 @@ \ No newline at end of file +require 'generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/sensor/auth.inc.php b/html/includes/graphs/sensor/auth.inc.php index d24d1d229..c86920ecf 100644 --- a/html/includes/graphs/sensor/auth.inc.php +++ b/html/includes/graphs/sensor/auth.inc.php @@ -1,21 +1,17 @@ diff --git a/html/includes/graphs/sensor/charge.inc.php b/html/includes/graphs/sensor/charge.inc.php index 331d4ff1a..e400153ae 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 381d1e270..f1ca4abdd 100644 --- a/html/includes/graphs/sensor/current.inc.php +++ b/html/includes/graphs/sensor/current.inc.php @@ -1,20 +1,23 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $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 a4ea9191f..32d6a57fc 100644 --- a/html/includes/graphs/sensor/dbm.inc.php +++ b/html/includes/graphs/sensor/dbm.inc.php @@ -1,20 +1,23 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; +} diff --git a/html/includes/graphs/sensor/fanspeed.inc.php b/html/includes/graphs/sensor/fanspeed.inc.php index 82ec16cc9..c1fad583c 100644 --- a/html/includes/graphs/sensor/fanspeed.inc.php +++ b/html/includes/graphs/sensor/fanspeed.inc.php @@ -1,17 +1,20 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; +} diff --git a/html/includes/graphs/sensor/frequency.inc.php b/html/includes/graphs/sensor/frequency.inc.php index 27629e65c..16dfe8ac5 100644 --- a/html/includes/graphs/sensor/frequency.inc.php +++ b/html/includes/graphs/sensor/frequency.inc.php @@ -1,19 +1,22 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; +} diff --git a/html/includes/graphs/sensor/humidity.inc.php b/html/includes/graphs/sensor/humidity.inc.php index 153d435dd..37ee96d63 100644 --- a/html/includes/graphs/sensor/humidity.inc.php +++ b/html/includes/graphs/sensor/humidity.inc.php @@ -1,29 +1,32 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $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 095f0eb2e..050f58a0b 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/power.inc.php b/html/includes/graphs/sensor/power.inc.php index 1731a3d09..c279bb80a 100644 --- a/html/includes/graphs/sensor/power.inc.php +++ b/html/includes/graphs/sensor/power.inc.php @@ -1,25 +1,28 @@ +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 281b1932f..e04e7dc29 100644 --- a/html/includes/graphs/sensor/state.inc.php +++ b/html/includes/graphs/sensor/state.inc.php @@ -1,17 +1,21 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; +} diff --git a/html/includes/graphs/sensor/voltage.inc.php b/html/includes/graphs/sensor/voltage.inc.php index ca3ea023d..634c7a54e 100644 --- a/html/includes/graphs/sensor/voltage.inc.php +++ b/html/includes/graphs/sensor/voltage.inc.php @@ -1,25 +1,28 @@ +if (is_numeric($sensor['sensor_limit_low'])) { + $rrd_options .= ' HRULE:'.$sensor['sensor_limit_low'].'#999999::dashes'; +} diff --git a/html/includes/graphs/service/auth.inc.php b/html/includes/graphs/service/auth.inc.php index 0d66f6946..eb30d023a 100644 --- a/html/includes/graphs/service/auth.inc.php +++ b/html/includes/graphs/service/auth.inc.php @@ -1,20 +1,16 @@ diff --git a/html/includes/graphs/service/availability.inc.php b/html/includes/graphs/service/availability.inc.php index 5dd1e926d..f836158a1 100644 --- a/html/includes/graphs/service/availability.inc.php +++ b/html/includes/graphs/service/availability.inc.php @@ -1,22 +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/smokeping/auth.inc.php b/html/includes/graphs/smokeping/auth.inc.php index ff2d92795..d3b0b0f3c 100644 --- a/html/includes/graphs/smokeping/auth.inc.php +++ b/html/includes/graphs/smokeping/auth.inc.php @@ -1,11 +1,8 @@ diff --git a/html/includes/graphs/smokeping/in.inc.php b/html/includes/graphs/smokeping/in.inc.php index c50d8a704..382bd7928 100644 --- a/html/includes/graphs/smokeping/in.inc.php +++ b/html/includes/graphs/smokeping/in.inc.php @@ -1,95 +1,90 @@ Human translation:> +$scale_min = 0; +$scale_rigid = true; -$scale_min = 0; -$scale_rigid = TRUE; +require 'includes/graphs/common.inc.php'; +require 'smokeping_common.inc.php'; -include("includes/graphs/common.inc.php"); -include("smokeping_common.inc.php"); +$i = 0; +$pings = 20; +$iter = 0; +$colourset = 'mixed'; -$i = 0; -$pings = 20; -$iter = 0; -$colourset = "mixed"; - -if($width > "500") -{ - $descr_len = 18; -} else { - $descr_len = 12 + round(($width - 275) / 8); +if ($width > '500') { + $descr_len = 18; +} +else { + $descr_len = (12 + round(($width - 275) / 8)); } -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev \l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev \l'"; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev \l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev \l'"; } $filename_dir = generate_smokeping_file($device); -if($src['hostname'] == $config['own_hostname']) -{ +if ($src['hostname'] == $config['own_hostname']) { $filename = $filename_dir . $device['hostname'].'.rrd'; - if (!file_exists($filename_dir.$device['hostname'].'.rrd')) - { - // Try with dots in hostname replaced by underscores - $filename = $filename_dir . str_replace(".", "_", $device['hostname']).'.rrd'; - } -} else { - $filename = $filename_dir . $device['hostname'] .'~'.$src['hostname'].'.rrd'; - if (!file_exists($filename)) - { - // Try with dots in hostname replaced by underscores - $filename = $filename_dir . str_replace(".", "-", $device['hostname']) .'~'.$src['hostname'].'.rrd'; - } + if (!file_exists($filename_dir.$device['hostname'].'.rrd')) { + // Try with dots in hostname replaced by underscores + $filename = $filename_dir . str_replace(".", "_", $device['hostname']).'.rrd'; + } +} +else { + $filename = $filename_dir . $device['hostname'] .'~'.$src['hostname'].'.rrd'; + if (!file_exists($filename)) { + // Try with dots in hostname replaced by underscores + $filename = $filename_dir . str_replace(".", "-", $device['hostname']) .'~'.$src['hostname'].'.rrd'; + } +} + +if (!isset($config['graph_colours'][$colourset][$iter])) { + $iter = 0; } - if (!isset($config['graph_colours'][$colourset][$iter])) { $iter = 0; } $colour = $config['graph_colours'][$colourset][$iter]; $iter++; - $descr = rrdtool_escape($source,$descr_len); + $descr = rrdtool_escape($source, $descr_len); - $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; - $rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE"; + $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE '; + $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE'; $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; $rrd_options .= " CDEF:dm$i=median$i"; -# $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; - +// $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; // start emulate Smokeping::calc_stddev - foreach (range(1, $pings) as $p) - { - $rrd_options .= " DEF:pin".$i."p".$p."=".$filename.":ping".$p.":AVERAGE"; - $rrd_options .= " CDEF:p".$i."p".$p."=pin".$i."p".$p.",UN,0,pin".$i."p".$p.",IF"; - } +foreach (range(1, $pings) as $p) { + $rrd_options .= ' DEF:pin'.$i.'p'.$p.'='.$filename.':ping'.$p.':AVERAGE'; + $rrd_options .= ' CDEF:p'.$i.'p'.$p.'=pin'.$i.'p'.$p.',UN,0,pin'.$i.'p'.$p.',IF'; +} unset($pings_options, $m_options, $sdev_options); - foreach (range(2, $pings) as $p) - { - $pings_options .= ",p".$i."p".$p.",UN,+"; - $m_options .= ",p".$i."p".$p.",+"; - $sdev_options .= ",p".$i."p".$p.",m".$i.",-,DUP,*,+"; - } +foreach (range(2, $pings) as $p) { + $pings_options .= ',p'.$i.'p'.$p.',UN,+'; + $m_options .= ',p'.$i.'p'.$p.',+'; + $sdev_options .= ',p'.$i.'p'.$p.',m'.$i.',-,DUP,*,+'; +} - $rrd_options .= " CDEF:pings".$i."=".$pings .",p".$i."p1,UN". $pings_options . ",-"; - $rrd_options .= " CDEF:m".$i."=p".$i."p1".$m_options.",pings".$i.",/"; - $rrd_options .= " CDEF:sdev".$i."=p".$i."p1,m".$i.",-,DUP,*".$sdev_options.",pings".$i.",/,SQRT"; + $rrd_options .= ' CDEF:pings'.$i.'='.$pings.',p'.$i.'p1,UN'.$pings_options.',-'; + $rrd_options .= ' CDEF:m'.$i.'=p'.$i.'p1'.$m_options.',pings'.$i.',/'; + $rrd_options .= ' CDEF:sdev'.$i.'=p'.$i.'p1,m'.$i.',-,DUP,*'.$sdev_options.',pings'.$i.',/,SQRT'; // end emulate Smokeping::calc_stddev - $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-"; $rrd_options .= " CDEF:s2d$i=sdev$i"; $rrd_options .= " AREA:dmlow$i"; - $rrd_options .= " AREA:s2d$i#".$colour."30::STACK"; + $rrd_options .= " AREA:s2d$i#".$colour.'30::STACK'; $rrd_options .= " LINE1:dm$i#".$colour.":'$descr'"; -# $rrd_options .= " LINE1:sdev$i#000000:$descr"; - +// $rrd_options .= " LINE1:sdev$i#000000:$descr"; $rrd_options .= " VDEF:avmed$i=median$i,AVERAGE"; $rrd_options .= " VDEF:avsd$i=sdev$i,AVERAGE"; $rrd_options .= " CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/"; @@ -102,5 +97,3 @@ if($src['hostname'] == $config['own_hostname']) $rrd_options .= " GPRINT:avmsr$i:'%5.1lf%s\\l'"; $i++; - -?> diff --git a/html/includes/graphs/smokeping/out.inc.php b/html/includes/graphs/smokeping/out.inc.php index 6ebfdc9e0..714aa9064 100644 --- a/html/includes/graphs/smokeping/out.inc.php +++ b/html/includes/graphs/smokeping/out.inc.php @@ -1,94 +1,89 @@ Human translation:> +$scale_min = 0; +$scale_rigid = true; -$scale_min = 0; -$scale_rigid = TRUE; +require 'includes/graphs/common.inc.php'; +require 'smokeping_common.inc.php'; -include("includes/graphs/common.inc.php"); -include("smokeping_common.inc.php"); +$i = 0; +$pings = 20; +$iter = 0; +$colourset = 'mixed'; -$i = 0; -$pings = 20; -$iter = 0; -$colourset = "mixed"; - -if($width > "500") -{ - $descr_len = 18; -} else { - $descr_len = 12 + round(($width - 275) / 8); +if ($width > '500') { + $descr_len = 18; +} +else { + $descr_len = (12 + round(($width - 275) / 8)); } -if($width > "500") -{ - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev \l'"; -} else { - $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev \l'"; +if ($width > '500') { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev \l'"; +} +else { + $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev \l'"; } -if($device['hostname'] == $config['own_hostname']) -{ - $filename = $config['smokeping']['dir'] . $dest['hostname'].'.rrd'; - if (!file_exists($filename)) - { - // Try with dots in hostname replaced by underscores - $filename = $config['smokeping']['dir'] . str_replace(".", "_", $dest['hostname']).'.rrd'; - } -} else { - $filename = $config['smokeping']['dir'] . $dest['hostname'] .'~'.$device['hostname'].'.rrd'; - if (!file_exists($filename)) - { - // Try with dots in hostname replaced by underscores - $filename = $config['smokeping']['dir'] . str_replace(".", "_", $dest['hostname']) .'~'.$device['hostname'].'.rrd'; - } +if ($device['hostname'] == $config['own_hostname']) { + $filename = $config['smokeping']['dir'].$dest['hostname'].'.rrd'; + if (!file_exists($filename)) { + // Try with dots in hostname replaced by underscores + $filename = $config['smokeping']['dir'].str_replace('.', '_', $dest['hostname']).'.rrd'; + } +} +else { + $filename = $config['smokeping']['dir'].$dest['hostname'].'~'.$device['hostname'].'.rrd'; + if (!file_exists($filename)) { + // Try with dots in hostname replaced by underscores + $filename = $config['smokeping']['dir'].str_replace('.', '_', $dest['hostname']).'~'.$device['hostname'].'.rrd'; + } +} + +if (!isset($config['graph_colours'][$colourset][$iter])) { + $iter = 0; } - if (!isset($config['graph_colours'][$colourset][$iter])) { $iter = 0; } $colour = $config['graph_colours'][$colourset][$iter]; $iter++; - $descr = rrdtool_escape($source,$descr_len); + $descr = rrdtool_escape($source, $descr_len); - $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; - $rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE"; + $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE '; + $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE'; $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; $rrd_options .= " CDEF:dm$i=median$i"; -# $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; - +// $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT"; // start emulate Smokeping::calc_stddev - foreach (range(1, $pings) as $p) - { - $rrd_options .= " DEF:pin".$i."p".$p."=".$filename.":ping".$p.":AVERAGE"; - $rrd_options .= " CDEF:p".$i."p".$p."=pin".$i."p".$p.",UN,0,pin".$i."p".$p.",IF"; - } +foreach (range(1, $pings) as $p) { + $rrd_options .= ' DEF:pin'.$i.'p'.$p.'='.$filename.':ping'.$p.':AVERAGE'; + $rrd_options .= ' CDEF:p'.$i.'p'.$p.'=pin'.$i.'p'.$p.',UN,0,pin'.$i.'p'.$p.',IF'; +} unset($pings_options, $m_options, $sdev_options); - foreach (range(2, $pings) as $p) - { - $pings_options .= ",p".$i."p".$p.",UN,+"; - $m_options .= ",p".$i."p".$p.",+"; - $sdev_options .= ",p".$i."p".$p.",m".$i.",-,DUP,*,+"; - } +foreach (range(2, $pings) as $p) { + $pings_options .= ',p'.$i.'p'.$p.',UN,+'; + $m_options .= ',p'.$i.'p'.$p.',+'; + $sdev_options .= ',p'.$i.'p'.$p.',m'.$i.',-,DUP,*,+'; +} - $rrd_options .= " CDEF:pings".$i."=".$pings .",p".$i."p1,UN". $pings_options . ",-"; - $rrd_options .= " CDEF:m".$i."=p".$i."p1".$m_options.",pings".$i.",/"; - $rrd_options .= " CDEF:sdev".$i."=p".$i."p1,m".$i.",-,DUP,*".$sdev_options.",pings".$i.",/,SQRT"; + $rrd_options .= ' CDEF:pings'.$i.'='.$pings.',p'.$i.'p1,UN'.$pings_options.',-'; + $rrd_options .= ' CDEF:m'.$i.'=p'.$i.'p1'.$m_options.',pings'.$i.',/'; + $rrd_options .= ' CDEF:sdev'.$i.'=p'.$i.'p1,m'.$i.',-,DUP,*'.$sdev_options.',pings'.$i.',/,SQRT'; // end emulate Smokeping::calc_stddev - $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-"; $rrd_options .= " CDEF:s2d$i=sdev$i"; $rrd_options .= " AREA:dmlow$i"; - $rrd_options .= " AREA:s2d$i#".$colour."30::STACK"; + $rrd_options .= " AREA:s2d$i#".$colour.'30::STACK'; $rrd_options .= " LINE1:dm$i#".$colour.":'$descr'"; -# $rrd_options .= " LINE1:sdev$i#000000:$descr"; - +// $rrd_options .= " LINE1:sdev$i#000000:$descr"; $rrd_options .= " VDEF:avmed$i=median$i,AVERAGE"; $rrd_options .= " VDEF:avsd$i=sdev$i,AVERAGE"; $rrd_options .= " CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/"; @@ -101,5 +96,3 @@ if($device['hostname'] == $config['own_hostname']) $rrd_options .= " GPRINT:avmsr$i:'%5.1lf%s\\l'"; $i++; - -?> diff --git a/html/includes/graphs/storage/auth.inc.php b/html/includes/graphs/storage/auth.inc.php index 0e2671304..47f8189aa 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/storage/usage.inc.php b/html/includes/graphs/storage/usage.inc.php index c42d339e6..60b01e418 100644 --- a/html/includes/graphs/storage/usage.inc.php +++ b/html/includes/graphs/storage/usage.inc.php @@ -1,20 +1,20 @@ diff --git a/html/includes/graphs/toner/auth.inc.php b/html/includes/graphs/toner/auth.inc.php index 928b7af38..72222f18f 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 3849b279c..2b617eb8b 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 3f400c1fd..4cb444871 100644 --- a/html/includes/graphs/vserver/auth.inc.php +++ b/html/includes/graphs/vserver/auth.inc.php @@ -1,20 +1,16 @@ diff --git a/html/includes/graphs/vserver/bits.inc.php b/html/includes/graphs/vserver/bits.inc.php index 28d4ac4c9..edafe2186 100644 --- a/html/includes/graphs/vserver/bits.inc.php +++ b/html/includes/graphs/vserver/bits.inc.php @@ -1,8 +1,6 @@ +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/graphs/vserver/conns.inc.php b/html/includes/graphs/vserver/conns.inc.php index 6715c89a2..4993c12b0 100644 --- a/html/includes/graphs/vserver/conns.inc.php +++ b/html/includes/graphs/vserver/conns.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 = "NumberOfConnections"; +$ds = 'NumberOfConnections'; -$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/vserver/pkts.inc.php b/html/includes/graphs/vserver/pkts.inc.php index be538a926..8590633ac 100644 --- a/html/includes/graphs/vserver/pkts.inc.php +++ b/html/includes/graphs/vserver/pkts.inc.php @@ -1,19 +1,17 @@ +require 'includes/graphs/generic_duplex.inc.php'; diff --git a/html/includes/hostbox-menu.inc.php b/html/includes/hostbox-menu.inc.php index 702941a31..03a9bb277 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 47b4d23cc..161ad34f1 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 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 ($bg == $list_colour_b) { $bg = $list_colour_a; } else { $bg = $list_colour_b; } +if ($bg == $list_colour_b) { + $bg = $list_colour_a; +} +else { + $bg = $list_colour_b; +} -if ($device['status'] == '0') -{ - $class = "bg-danger"; -} else { - $class = "bg-primary"; +if ($device['status'] == '0') { + $class = 'bg-danger'; } -if ($device['ignore'] == '1') -{ - $class = "bg-warning"; - if ($device['status'] == '1') - { - $class = "bg-success"; - } +else { + $class = 'bg-primary'; } -if ($device['disabled'] == '1') -{ - $class = "bg-info"; + +if ($device['ignore'] == '1') { + $class = 'bg-warning'; + if ($device['status'] == '1') { + $class = 'bg-success'; + } +} + +if ($device['disabled'] == '1') { + $class = 'bg-info'; } $type = strtolower($device['os']); -if ($device['os'] == "ios") { formatCiscoHardware($device, true); } +if ($device['os'] == 'ios') { + formatCiscoHardware($device, true); +} + $device['os_text'] = $config['os'][$device['os']]['text']; -echo(' - - ' . $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 7fcdf11a9..c5a8c932f 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 4d105280f..675c74c2e 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 7281f8e36..826d1bf01 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 7c6b7b628..b726a219f 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 cce990eb4..5d4ff6076 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 aa5717b28..d1dc5d6f4 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 c966da6ac..ccbfe2245 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 16a3afdd0..8ad6e8265 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 2a6d71a47..d9758a0f3 100644 --- a/html/includes/print-alerts.inc.php +++ b/html/includes/print-alerts.inc.php @@ -1,51 +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 f35cd05bf..7fdbbcc6d 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) { '; $g_i++; - -?> - diff --git a/html/includes/print-event-short.inc.php b/html/includes/print-event-short.inc.php index f28befee7..42fc75768 100644 --- a/html/includes/print-event-short.inc.php +++ b/html/includes/print-event-short.inc.php @@ -1,26 +1,30 @@ "; } +if ($icon) { + $icon = ""; +} -echo(" +echo ' - ".$entry['humandate']." + '.$entry['humandate'].' - "); + '; - if ($entry['type'] == "interface") { - $entry['link'] = "".generate_port_link(getifbyid($entry['reference'])).""; - } +if ($entry['type'] == 'interface') { + $entry['link'] = ''.generate_port_link(getifbyid($entry['reference'])).''; +} - echo($entry['link'] ." ". htmlspecialchars($entry['message']) - . " + echo $entry['link'].' '.htmlspecialchars($entry['message']).' -"); - -?> +'; diff --git a/html/includes/print-event.inc.php b/html/includes/print-event.inc.php index 6f09184cd..d8afd6bfa 100644 --- a/html/includes/print-event.inc.php +++ b/html/includes/print-event.inc.php @@ -5,31 +5,31 @@ $hostname = gethostbyid($entry['host']); unset($icon); $icon = geteventicon($entry['message']); -if ($icon) { $icon = ''; } +if ($icon) { + $icon = ''; +} -echo(' +echo ' - ' . $entry['datetime'] . ' - '); + '.$entry['datetime'].' + '; if (!isset($vars['device'])) { - $dev = device_by_id_cache($entry['host']); - echo(" - " . generate_device_link($dev, shorthost($dev['hostname'])) . " - "); + $dev = device_by_id_cache($entry['host']); + echo ' + '.generate_device_link($dev, shorthost($dev['hostname'])).' + '; } -if ($entry['type'] == "interface") -{ - $this_if = ifLabel(getifbyid($entry['reference'])); - $entry['link'] = "".generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).""; -} else { - $entry['link'] = "System"; +if ($entry['type'] == 'interface') { + $this_if = ifLabel(getifbyid($entry['reference'])); + $entry['link'] = ''.generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).''; +} +else { + $entry['link'] = 'System'; } -echo("".$entry['link'].""); +echo ''.$entry['link'].''; -echo("".htmlspecialchars($entry['message']) . " -"); - -?> +echo ''.htmlspecialchars($entry['message']).' +'; diff --git a/html/includes/print-graph-alerts.inc.php b/html/includes/print-graph-alerts.inc.php index de6f31600..f6b936d27 100644 --- a/html/includes/print-graph-alerts.inc.php +++ b/html/includes/print-graph-alerts.inc.php @@ -1,14 +1,15 @@ -* 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) 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. + */ + $pagetitle[] = "Alert Stats"; $sql = ""; @@ -31,7 +32,7 @@ if ($_SESSION['userlevel'] < '5') {
diff --git a/html/includes/print-graphrow.inc.php b/html/includes/print-graphrow.inc.php index c55091044..db451315f 100644 --- a/html/includes/print-graphrow.inc.php +++ b/html/includes/print-graphrow.inc.php @@ -2,37 +2,59 @@ global $config; -if($_SESSION['widescreen']) -{ - if (!$graph_array['height']) { $graph_array['height'] = "110"; } - if (!$graph_array['width']) { $graph_array['width'] = "215"; } - $periods = array('sixhour', 'day', 'week', 'month', 'year', 'twoyear'); -} else { - if (!$graph_array['height']) { $graph_array['height'] = "100"; } - if (!$graph_array['width']) { $graph_array['width'] = "215"; } - $periods = array('day', 'week', 'month', 'year'); -} +if ($_SESSION['widescreen']) { + if (!$graph_array['height']) { + $graph_array['height'] = '110'; + } -$graph_array['to'] = $config['time']['now']; + if (!$graph_array['width']) { + $graph_array['width'] = '215'; + } + + $periods = array( + 'sixhour', + 'day', + 'week', + 'month', + 'year', + 'twoyear', + ); +} +else { + if (!$graph_array['height']) { + $graph_array['height'] = '100'; + } + + if (!$graph_array['width']) { + $graph_array['width'] = '215'; + } + + $periods = array( + 'day', + 'week', + 'month', + 'year', + ); +}//end if + +$graph_array['to'] = $config['time']['now']; $graph_data = array(); -foreach ($periods as $period) -{ - $graph_array['from'] = $config['time'][$period]; - $graph_array_zoom = $graph_array; - $graph_array_zoom['height'] = "150"; - $graph_array_zoom['width'] = "400"; +foreach ($periods as $period) { + $graph_array['from'] = $config['time'][$period]; + $graph_array_zoom = $graph_array; + $graph_array_zoom['height'] = '150'; + $graph_array_zoom['width'] = '400'; - $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); - if ($return_data === TRUE) { - $graph_data[] = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); - } else { - echo(overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL)); + if ($return_data === true) { + $graph_data[] = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); + } + else { + echo overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null); } } - -?> diff --git a/html/includes/print-interface-adsl.inc.php b/html/includes/print-interface-adsl.inc.php index a53d2fc1b..fa891bbbc 100644 --- a/html/includes/print-interface-adsl.inc.php +++ b/html/includes/print-interface-adsl.inc.php @@ -1,106 +1,115 @@ 0 || $port['ifOutErrors_delta'] > 0) -{ - $error_img = generate_port_link($port,"Interface Errors","port_errors"); -} else { - $error_img = ""; +if (!is_integer($i / 2)) { + $row_colour = $list_colour_a; +} +else { + $row_colour = $list_colour_b; } -echo(" - "); -echo(" - " . generate_port_link($port, $port['ifIndex'] . ". ".$port['label']) . " -
".$port['ifAlias'].""); - -if ($port['ifAlias']) { echo("
"); } - -unset ($break); -if ($port_details) -{ - foreach (dbFetchRows("SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip) - { - echo("$break ".$ip['ipv4_address']."/".$ip['ipv4_prefixlen'].""); - $break = ","; - } - foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip6); - { - echo("$break ".Net_IPv6::compress($ip6['ipv6_address'])."/".$ip6['ipv6_prefixlen'].""); - $break = ","; - } +if ($port['ifInErrors_delta'] > 0 || $port['ifOutErrors_delta'] > 0) { + $error_img = generate_port_link($port, "Interface Errors", 'port_errors'); +} +else { + $error_img = ''; } -echo(""); +echo " + "; +echo ' + '.generate_port_link($port, $port['ifIndex'].'. '.$port['label']).' +
'.$port['ifAlias'].''; -$width="120"; $height="40"; $from = $config['time']['day']; +if ($port['ifAlias']) { + echo '
'; +} -echo(""); -echo(formatRates($port['ifInOctets_rate'] * 8)." ".formatRates($port['ifOutOctets_rate'] * 8)); -echo("
"); -$port['graph_type'] = "port_bits"; -echo(generate_port_link($port, "", $port['graph_type'])); +unset($break); +if ($port_details) { + foreach (dbFetchRows('SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip) { + echo "$break ".$ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'].''; + $break = ','; + } -echo(""); -echo("".formatRates($port['adslAturChanCurrTxRate']) . "/". formatRates($port['adslAtucChanCurrTxRate'])); -echo("
"); -$port['graph_type'] = "port_adsl_speed"; -echo(generate_port_link($port, "", $port['graph_type'])); + foreach (dbFetchRows('SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip6) { ; + echo "$break ".Net_IPv6::compress($ip6['ipv6_address']).'/'.$ip6['ipv6_prefixlen'].''; + $break = ','; + } +} -echo(""); -echo("".formatRates($port['adslAturCurrAttainableRate']) . "/". formatRates($port['adslAtucCurrAttainableRate'])); -echo("
"); -$port['graph_type'] = "port_adsl_attainable"; -echo(generate_port_link($port, "", $port['graph_type'])); +echo ''; -echo(""); -echo("".$port['adslAturCurrAtn'] . "dB/". $port['adslAtucCurrAtn'] . "dB"); -echo("
"); -$port['graph_type'] = "port_adsl_attenuation"; -echo(generate_port_link($port, "", $port['graph_type'])); +$width = '120'; +$height = '40'; +$from = $config['time']['day']; -echo(""); -echo("".$port['adslAturCurrSnrMgn'] . "dB/". $port['adslAtucCurrSnrMgn'] . "dB"); -echo("
"); -$port['graph_type'] = "port_adsl_snr"; -echo(generate_port_link($port, "", $port['graph_type'])); +echo ''; +echo (formatRates(($port['ifInOctets_rate'] * 8))." ".formatRates(($port['ifOutOctets_rate'] * 8))); +echo '
'; +$port['graph_type'] = 'port_bits'; +echo generate_port_link( + $port, + "", + $port['graph_type'] +); -echo(""); -echo("".$port['adslAturCurrOutputPwr'] . "dBm/". $port['adslAtucCurrOutputPwr'] . "dBm"); -echo("
"); -$port['graph_type'] = "port_adsl_power"; -echo(generate_port_link($port, "", $port['graph_type'])); +echo ''; +echo ''.formatRates($port['adslAturChanCurrTxRate']).'/'.formatRates($port['adslAtucChanCurrTxRate']); +echo '
'; +$port['graph_type'] = 'port_adsl_speed'; +echo generate_port_link( + $port, + "", + $port['graph_type'] +); -# if ($port[ifDuplex] != unknown) { echo("Duplex " . $port['ifDuplex'] . ""); } else { echo("-"); } +echo ''; +echo ''.formatRates($port['adslAturCurrAttainableRate']).'/'.formatRates($port['adslAtucCurrAttainableRate']); +echo '
'; +$port['graph_type'] = 'port_adsl_attainable'; +echo generate_port_link( + $port, + "", + $port['graph_type'] +); -# echo(""); -# echo($port_adsl['adslLineCoding']."/".$port_adsl['adslLineType']); -# echo("
"); -# echo("Sync:".formatRates($port_adsl['adslAtucChanCurrTxRate']) . "/". formatRates($port_adsl['adslAturChanCurrTxRate'])); -# echo("
"); -# echo("Max:".formatRates($port_adsl['adslAtucCurrAttainableRate']) . "/". formatRates($port_adsl['adslAturCurrAttainableRate'])); -# echo(""); -# echo("Atten:".$port_adsl['adslAtucCurrAtn'] . "dB/". $port_adsl['adslAturCurrAtn'] . "dB"); -# echo("
"); -# echo("SNR:".$port_adsl['adslAtucCurrSnrMgn'] . "dB/". $port_adsl['adslAturCurrSnrMgn']. "dB"); +echo ''; +echo ''.$port['adslAturCurrAtn'].'dB/'.$port['adslAtucCurrAtn'].'dB'; +echo '
'; +$port['graph_type'] = 'port_adsl_attenuation'; +echo generate_port_link( + $port, + "", + $port['graph_type'] +); -echo(""); +echo ''; +echo ''.$port['adslAturCurrSnrMgn'].'dB/'.$port['adslAtucCurrSnrMgn'].'dB'; +echo '
'; +$port['graph_type'] = 'port_adsl_snr'; +echo generate_port_link( + $port, + "", + $port['graph_type'] +); -?> +echo ''; +echo ''.$port['adslAturCurrOutputPwr'].'dBm/'.$port['adslAtucCurrOutputPwr'].'dBm'; +echo '
'; +$port['graph_type'] = 'port_adsl_power'; +echo generate_port_link( + $port, + "", + $port['graph_type'] +); + +echo ''; diff --git a/html/includes/print-interface-graphs.inc.php b/html/includes/print-interface-graphs.inc.php index 1049c7d80..7971fccff 100644 --- a/html/includes/print-interface-graphs.inc.php +++ b/html/includes/print-interface-graphs.inc.php @@ -2,12 +2,10 @@ global $config; -$graph_array['height'] = "100"; -$graph_array['width'] = "215"; +$graph_array['height'] = '100'; +$graph_array['width'] = '215'; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $port['port_id']; $graph_array['type'] = $graph_type; -include("includes/print-graphrow.inc.php"); - -?> +require 'includes/print-graphrow.inc.php'; diff --git a/html/includes/print-interface.inc.php b/html/includes/print-interface.inc.php index 489c60606..26f33fb50 100644 --- a/html/includes/print-interface.inc.php +++ b/html/includes/print-interface.inc.php @@ -1,282 +1,325 @@ 0 || $port['ifOutErrors_delta'] > 0) -{ - $error_img = generate_port_link($port, "Interface Errors", "port_errors"); -} else { $error_img = ""; } - -if (dbFetchCell("SELECT COUNT(*) FROM `mac_accounting` WHERE `port_id` = ?", array($port['port_id']))) -{ - $mac = " 'macaccounting')) . "'>"; -} else { $mac = ""; } - -echo(" - "); -echo(" - " . generate_port_link($port, $port['ifIndex'] . ". ".$port['label']) . " $error_img $mac -
".$port['ifAlias'].""); - -if ($port['ifAlias']) { echo("
"); } - -unset ($break); - -if ($port_details) -{ - foreach (dbFetchRows("SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip) - { - echo("$break ".$ip['ipv4_address']."/".$ip['ipv4_prefixlen'].""); - $break = "
"; - } - foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip6) - { - echo("$break ".Net_IPv6::compress($ip6['ipv6_address'])."/".$ip6['ipv6_prefixlen'].""); - $break = "
"; - } +if ($port['ifInErrors_delta'] > 0 || $port['ifOutErrors_delta'] > 0) { + $error_img = generate_port_link($port, "Interface Errors", 'port_errors'); +} +else { + $error_img = ''; } -echo(""); - -echo(""); - -if ($port_details) -{ - $port['graph_type'] = "port_bits"; - echo(generate_port_link($port, "")); - $port['graph_type'] = "port_upkts"; - echo(generate_port_link($port, "")); - $port['graph_type'] = "port_errors"; - echo(generate_port_link($port, "")); +if (dbFetchCell('SELECT COUNT(*) FROM `mac_accounting` WHERE `port_id` = ?', array($port['port_id']))) { + $mac = " 'macaccounting'))."'>"; +} +else { + $mac = ''; } -echo(""); +echo " + "; +echo ' + '.generate_port_link($port, $port['ifIndex'].'. '.$port['label'])." $error_img $mac +
".$port['ifAlias'].''; -if ($port['ifOperStatus'] == "up") -{ - $port['in_rate'] = $port['ifInOctets_rate'] * 8; - $port['out_rate'] = $port['ifOutOctets_rate'] * 8; - $in_perc = @round($port['in_rate']/$port['ifSpeed']*100); - $out_perc = @round($port['in_rate']/$port['ifSpeed']*100); - echo(" ".formatRates($port['in_rate'])."
- ".formatRates($port['out_rate']) . "
+if ($port['ifAlias']) { + echo '
'; +} + +unset($break); + +if ($port_details) { + foreach (dbFetchRows('SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip) { + echo "$break ".$ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'].''; + $break = '
'; + } + + foreach (dbFetchRows('SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip6) { + echo "$break ".Net_IPv6::compress($ip6['ipv6_address']).'/'.$ip6['ipv6_prefixlen'].''; + $break = '
'; + } +} + +echo '
'; + +echo ''; + +if ($port_details) { + $port['graph_type'] = 'port_bits'; + echo generate_port_link($port, ""); + $port['graph_type'] = 'port_upkts'; + echo generate_port_link($port, ""); + $port['graph_type'] = 'port_errors'; + echo generate_port_link($port, ""); +} + +echo ''; + +if ($port['ifOperStatus'] == 'up') { + $port['in_rate'] = ($port['ifInOctets_rate'] * 8); + $port['out_rate'] = ($port['ifOutOctets_rate'] * 8); + $in_perc = @round(($port['in_rate'] / $port['ifSpeed'] * 100)); + $out_perc = @round(($port['in_rate'] / $port['ifSpeed'] * 100)); + echo " ".formatRates($port['in_rate'])."
+ ".formatRates($port['out_rate'])."
".format_bi($port['ifInUcastPkts_rate'])."pps

- ".format_bi($port['ifOutUcastPkts_rate'])."pps
"); + ".format_bi($port['ifOutUcastPkts_rate']).'pps
'; } -echo(""); -if ($port['ifSpeed']) { echo("".humanspeed($port['ifSpeed']).""); } -echo("
"); +echo ''; +if ($port['ifSpeed']) { + echo ''.humanspeed($port['ifSpeed']).''; +} -if ($port[ifDuplex] != "unknown") { echo("" . $port['ifDuplex'] . ""); } else { echo("-"); } +echo '
'; -if ($device['os'] == "ios" || $device['os'] == "iosxe") -{ - if ($port['ifTrunk']) { +if ($port[ifDuplex] != 'unknown') { + echo ''.$port['ifDuplex'].''; +} +else { + echo '-'; +} - echo('

".$vlan['vlan'] ." ".$vlan['vlan_descr']."
"); +if ($device['os'] == 'ios' || $device['os'] == 'iosxe') { + if ($port['ifTrunk']) { + echo '

'.$vlan['vlan'].' '.$vlan['vlan_descr'].'
'; + } + + echo '">'.$port['ifTrunk'].'

'; } - echo('">'.$port['ifTrunk'].'

'); - } elseif ($port['ifVlan']) { - echo("

VLAN " . $port['ifVlan'] . "

"); - } elseif ($port['ifVrf']) { - $vrf = dbFetchRow("SELECT * FROM vrfs WHERE vrf_id = ?", array($port['ifVrf'])); - echo("

" . $vrf['vrf_name'] . "

"); - } + else if ($port['ifVlan']) { + echo '

VLAN '.$port['ifVlan'].'

'; + } + else if ($port['ifVrf']) { + $vrf = dbFetchRow('SELECT * FROM vrfs WHERE vrf_id = ?', array($port['ifVrf'])); + echo "

".$vrf['vrf_name'].'

'; + }//end if +}//end if + +if ($port_adsl['adslLineCoding']) { + echo ''; + echo $port_adsl['adslLineCoding'].'/'.rewrite_adslLineType($port_adsl['adslLineType']); + echo '
'; + echo 'Sync:'.formatRates($port_adsl['adslAtucChanCurrTxRate']).'/'.formatRates($port_adsl['adslAturChanCurrTxRate']); + echo '
'; + echo 'Max:'.formatRates($port_adsl['adslAtucCurrAttainableRate']).'/'.formatRates($port_adsl['adslAturCurrAttainableRate']); + echo ''; + echo 'Atten:'.$port_adsl['adslAtucCurrAtn'].'dB/'.$port_adsl['adslAturCurrAtn'].'dB'; + echo '
'; + echo 'SNR:'.$port_adsl['adslAtucCurrSnrMgn'].'dB/'.$port_adsl['adslAturCurrSnrMgn'].'dB'; } - -if ($port_adsl['adslLineCoding']) -{ - echo(""); - echo($port_adsl['adslLineCoding']."/" . rewrite_adslLineType($port_adsl['adslLineType'])); - echo("
"); - echo("Sync:".formatRates($port_adsl['adslAtucChanCurrTxRate']) . "/". formatRates($port_adsl['adslAturChanCurrTxRate'])); - echo("
"); - echo("Max:".formatRates($port_adsl['adslAtucCurrAttainableRate']) . "/". formatRates($port_adsl['adslAturCurrAttainableRate'])); - echo(""); - echo("Atten:".$port_adsl['adslAtucCurrAtn'] . "dB/". $port_adsl['adslAturCurrAtn'] . "dB"); - echo("
"); - echo("SNR:".$port_adsl['adslAtucCurrSnrMgn'] . "dB/". $port_adsl['adslAturCurrSnrMgn']. "dB"); -} else { - echo(""); - if ($port['ifType'] && $port['ifType'] != "") { echo("" . fixiftype($port['ifType']) . ""); } else { echo("-"); } - echo("
"); - if ($ifHardType && $ifHardType != "") { echo("" . $ifHardType . ""); } else { echo("-"); } - echo(""); - if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") { echo("" . formatMac($port['ifPhysAddress']) . ""); } else { echo("-"); } - echo("
"); - if ($port['ifMtu'] && $port['ifMtu'] != "") { echo("MTU " . $port['ifMtu'] . ""); } else { echo("-"); } -} - -echo(""); -echo(""); -if (strpos($port['label'], "oopback") === false && !$graph_type) -{ - foreach (dbFetchRows("SELECT * FROM `links` AS L, `ports` AS I, `devices` AS D WHERE L.local_port_id = ? AND L.remote_port_id = I.port_id AND I.device_id = D.device_id", array($if_id)) as $link) - { -# echo("Directly Connected " . generate_port_link($link, makeshortif($link['label'])) . " on " . generate_device_link($link, shorthost($link['hostname'])) . "
"); -# $br = "
"; - $int_links[$link['port_id']] = $link['port_id']; - $int_links_phys[$link['port_id']] = 1; - } - - unset($br); - - if ($port_details && $config['enable_port_relationship'] === TRUE) - { // Show which other devices are on the same subnet as this interface - foreach (dbFetchRows("SELECT `ipv4_network_id` FROM `ipv4_addresses` WHERE `port_id` = ? AND `ipv4_address` NOT LIKE '127.%'", array($port['port_id'])) as $net) - { - $ipv4_network_id = $net['ipv4_network_id']; - $sql = "SELECT I.port_id FROM ipv4_addresses AS A, ports AS I, devices AS D - WHERE A.port_id = I.port_id - AND A.ipv4_network_id = ? AND D.device_id = I.device_id - AND D.device_id != ?"; - $array = array($net['ipv4_network_id'], $device['device_id']); - foreach (dbFetchRows($sql, $array) AS $new) - { - echo($new['ipv4_network_id']); - $this_ifid = $new['port_id']; - $this_hostid = $new['device_id']; - $this_hostname = $new['hostname']; - $this_ifname = fixifName($new['label']); - $int_links[$this_ifid] = $this_ifid; - $int_links_v4[$this_ifid] = 1; - } +else { + echo ''; + if ($port['ifType'] && $port['ifType'] != '') { + echo ''.fixiftype($port['ifType']).''; + } + else { + echo '-'; } - foreach (dbFetchRows("SELECT ipv6_network_id FROM ipv6_addresses WHERE port_id = ?", array($port['port_id'])) as $net) - { - $ipv6_network_id = $net['ipv6_network_id']; - $sql = "SELECT I.port_id FROM ipv6_addresses AS A, ports AS I, devices AS D - WHERE A.port_id = I.port_id - AND A.ipv6_network_id = ? AND D.device_id = I.device_id - AND D.device_id != ? AND A.ipv6_origin != 'linklayer' AND A.ipv6_origin != 'wellknown'"; - $array = array($net['ipv6_network_id'], $device['device_id']); - - foreach (dbFetchRows($sql, $array) AS $new) - { - echo($new['ipv6_network_id']); - $this_ifid = $new['port_id']; - $this_hostid = $new['device_id']; - $this_hostname = $new['hostname']; - $this_ifname = fixifName($new['label']); - $int_links[$this_ifid] = $this_ifid; - $int_links_v6[$this_ifid] = 1; - } + echo '
'; + if ($ifHardType && $ifHardType != '') { + echo ''.$ifHardType.''; + } + else { + echo '-'; } - } - if ($port_details && $config['enable_port_relationship'] === TRUE) - { - foreach ($int_links as $int_link) - { - $link_if = dbFetchRow("SELECT * from ports AS I, devices AS D WHERE I.device_id = D.device_id and I.port_id = ?", array($int_link)); + echo ''; + if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != '') { + echo ''.formatMac($port['ifPhysAddress']).''; + } + else { + echo '-'; + } - echo("$br"); + echo '
'; + if ($port['ifMtu'] && $port['ifMtu'] != '') { + echo 'MTU '.$port['ifMtu'].''; + } + else { + echo '-'; + } +}//end if - if ($int_links_phys[$int_link]) { echo(" "); } else { - echo(" "); } +echo ''; +echo ''; +if (strpos($port['label'], 'oopback') === false && !$graph_type) { + foreach (dbFetchRows('SELECT * FROM `links` AS L, `ports` AS I, `devices` AS D WHERE L.local_port_id = ? AND L.remote_port_id = I.port_id AND I.device_id = D.device_id', array($if_id)) as $link) { + // echo("Directly Connected " . generate_port_link($link, makeshortif($link['label'])) . " on " . generate_device_link($link, shorthost($link['hostname'])) . "
"); + // $br = "
"; + $int_links[$link['port_id']] = $link['port_id']; + $int_links_phys[$link['port_id']] = 1; + } - echo("" . generate_port_link($link_if, makeshortif($link_if['label'])) . " on " . generate_device_link($link_if, shorthost($link_if['hostname']))); + unset($br); - if ($int_links_v6[$int_link]) { echo(" v6"); } - if ($int_links_v4[$int_link]) { echo(" v4"); } - $br = "
"; - } - } -# unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br); -} + if ($port_details && $config['enable_port_relationship'] === true) { + // Show which other devices are on the same subnet as this interface + foreach (dbFetchRows("SELECT `ipv4_network_id` FROM `ipv4_addresses` WHERE `port_id` = ? AND `ipv4_address` NOT LIKE '127.%'", array($port['port_id'])) as $net) { + $ipv4_network_id = $net['ipv4_network_id']; + $sql = 'SELECT I.port_id FROM ipv4_addresses AS A, ports AS I, devices AS D + WHERE A.port_id = I.port_id + AND A.ipv4_network_id = ? AND D.device_id = I.device_id + AND D.device_id != ?'; + $array = array( + $net['ipv4_network_id'], + $device['device_id'], + ); + foreach (dbFetchRows($sql, $array) as $new) { + echo $new['ipv4_network_id']; + $this_ifid = $new['port_id']; + $this_hostid = $new['device_id']; + $this_hostname = $new['hostname']; + $this_ifname = fixifName($new['label']); + $int_links[$this_ifid] = $this_ifid; + $int_links_v4[$this_ifid] = 1; + } + }//end foreach -if ($port_details && $config['enable_port_relationship'] === TRUE) -{ - foreach (dbFetchRows("SELECT * FROM `pseudowires` WHERE `port_id` = ?", array($port['port_id'])) as $pseudowire) - { - #`port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid` - $pw_peer_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($pseudowire['peer_device_id'])); - $pw_peer_int = dbFetchRow("SELECT * FROM `ports` AS I, pseudowires AS P WHERE I.device_id = ? AND P.cpwVcID = ? AND P.port_id = I.port_id", array($pseudowire['peer_device_id'], $pseudowire['cpwVcID'])); + foreach (dbFetchRows('SELECT ipv6_network_id FROM ipv6_addresses WHERE port_id = ?', array($port['port_id'])) as $net) { + $ipv6_network_id = $net['ipv6_network_id']; + $sql = "SELECT I.port_id FROM ipv6_addresses AS A, ports AS I, devices AS D + WHERE A.port_id = I.port_id + AND A.ipv6_network_id = ? AND D.device_id = I.device_id + AND D.device_id != ? AND A.ipv6_origin != 'linklayer' AND A.ipv6_origin != 'wellknown'"; + $array = array( + $net['ipv6_network_id'], + $device['device_id'], + ); - $pw_peer_int = ifNameDescr($pw_peer_int); - echo("$br " . generate_port_link($pw_peer_int, makeshortif($pw_peer_int['label'])) ." on ". generate_device_link($pw_peer_dev, shorthost($pw_peer_dev['hostname'])) . ""); - $br = "
"; - } + foreach (dbFetchRows($sql, $array) as $new) { + echo $new['ipv6_network_id']; + $this_ifid = $new['port_id']; + $this_hostid = $new['device_id']; + $this_hostname = $new['hostname']; + $this_ifname = fixifName($new['label']); + $int_links[$this_ifid] = $this_ifid; + $int_links_v6[$this_ifid] = 1; + } + }//end foreach + }//end if - 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 ($port_details && $config['enable_port_relationship'] === true) { + foreach ($int_links as $int_link) { + $link_if = dbFetchRow('SELECT * from ports AS I, devices AS D WHERE I.device_id = D.device_id and I.port_id = ?', array($int_link)); - if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) - { - $parent = dbFetchRow("SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?", array($port['pagpGroupIfIndex'], $device['device_id'])); - echo("$br " . generate_port_link($parent) . " (PAgP)"); - $br = "
"; - } + echo "$br"; - foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $higher_if) - { - if ($higher_if['port_id_high']) - { - $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']); - echo("$br " . generate_port_link($this_port) . ""); - $br = "
"; - } - } + if ($int_links_phys[$int_link]) { + echo " "; + } + else { + echo " "; + } - foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_high` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $lower_if) - { - if ($lower_if['port_id_low']) - { - $this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low']); - echo("$br " . generate_port_link($this_port) . ""); - $br = "
"; - } - } -} + echo ''.generate_port_link($link_if, makeshortif($link_if['label'])).' on '.generate_device_link($link_if, shorthost($link_if['hostname'])); + + if ($int_links_v6[$int_link]) { + echo " v6"; + } + + if ($int_links_v4[$int_link]) { + echo " v4"; + } + + $br = '
'; + }//end foreach + }//end if + + // unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br); +}//end if + +if ($port_details && $config['enable_port_relationship'] === true) { + foreach (dbFetchRows('SELECT * FROM `pseudowires` WHERE `port_id` = ?', array($port['port_id'])) as $pseudowire) { + // `port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid` + $pw_peer_dev = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($pseudowire['peer_device_id'])); + $pw_peer_int = dbFetchRow('SELECT * FROM `ports` AS I, pseudowires AS P WHERE I.device_id = ? AND P.cpwVcID = ? AND P.port_id = I.port_id', array($pseudowire['peer_device_id'], $pseudowire['cpwVcID'])); + + $pw_peer_int = ifNameDescr($pw_peer_int); + echo "$br ".generate_port_link($pw_peer_int, makeshortif($pw_peer_int['label'])).' on '.generate_device_link($pw_peer_dev, shorthost($pw_peer_dev['hostname'])).''; + $br = '
'; + } + + 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 ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) { + $parent = dbFetchRow('SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?', array($port['pagpGroupIfIndex'], $device['device_id'])); + echo "$br ".generate_port_link($parent).' (PAgP)'; + $br = '
'; + } + + foreach (dbFetchRows('SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $higher_if) { + if ($higher_if['port_id_high']) { + $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']); + echo "$br ".generate_port_link($this_port).''; + $br = '
'; + } + } + + foreach (dbFetchRows('SELECT * FROM `ports_stack` WHERE `port_id_high` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $lower_if) { + if ($lower_if['port_id_low']) { + $this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low']); + echo "$br ".generate_port_link($this_port).''; + $br = '
'; + } + } +}//end if unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br); -echo(""); +echo ''; // If we're showing graphs, generate the graph and print the img tags - -if ($graph_type == "etherlike") -{ - $graph_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/port-". safename($port['ifIndex']) . "-dot3.rrd"; -} else { - $graph_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/port-". safename($port['ifIndex']) . ".rrd"; +if ($graph_type == 'etherlike') { + $graph_file = $config['rrd_dir'].'/'.$device['hostname'].'/port-'.safename($port['ifIndex']).'-dot3.rrd'; +} +else { + $graph_file = $config['rrd_dir'].'/'.$device['hostname'].'/port-'.safename($port['ifIndex']).'.rrd'; } -if ($graph_type && is_file($graph_file)) -{ - $type = $graph_type; +if ($graph_type && is_file($graph_file)) { + $type = $graph_type; - echo(""); + echo ""; - include("includes/print-interface-graphs.inc.php"); + include 'includes/print-interface-graphs.inc.php'; - echo(""); + echo ''; } - -?> diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index ad1bf8a55..f5a9f1e88 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -15,93 +15,167 @@ //Don't know where this should come from, but it is used later, so I just define it here. $row_colour="#ffffff"; -$tmp_devices = array(); $sql_array= array(); if (!empty($device['hostname'])) { - $sql = ' WHERE `devices`.`hostname`=?'; - $sql_array = array($device['hostname']); -} else { - $sql = ' WHERE 1'; + $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(); -foreach (dbFetchRows("SELECT DISTINCT least(`devices`.`device_id`, `remote_device_id`) AS `remote_device_id`, GREATEST(`remote_device_id`,`devices`.`device_id`) AS `local_device_id` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` $sql", $sql_array) as $link_devices) { - if (!in_array($link_devices['local_device_id'], $tmp_ids) && device_permitted($link_devices['local_device_id'])) { - $link_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?",array($link_devices['local_device_id'])); - if (!empty($link_dev)) { - $tmp_devices[] = array('id'=>$link_devices['local_device_id'],'label'=>$link_dev['hostname'],'title'=>generate_device_link($link_dev,'',array(),'','','',0),'group'=>$link_dev['location'],'shape'=>'box'); - } +$tmp_links = array(); + + +$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`, + `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 `links` + LEFT JOIN `devices` AS `D1` ON `D1`.`device_id`=`links`.`local_device_id` + 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 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); + +$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']); + + $local_port = array('port_id'=>$items['local_port_id'],'device_id'=>$items['local_port_device_id'],'ifName'=>$items['local_ifname'],'ifSpeed'=>$items['local_ifspeed'],'ifOperStatus'=>$items['local_ifoperstatus'],'ifAdminStatus'=>$items['local_adminstatus']); + $remote_port = array('port_id'=>$items['remote_port_id'],'device_id'=>$items['remote_port_device_id'],'ifName'=>$items['remote_ifname'],'ifSpeed'=>$items['remote_ifspeed'],'ifOperStatus'=>$items['remote_ifoperstatus'],'ifAdminStatus'=>$items['remote_adminstatus']); + + if (!in_array($items['local_device_id'],$tmp_ids)) { + $tmp_devices[] = array('id'=>$items['local_device_id'],'label'=>$items['local_hostname'],'title'=>generate_device_link($local_device,'',array(),'','','',0),'shape'=>'box'); } - if (!in_array($link_devices['remote_device_id'], $tmp_ids) && device_permitted($link_devices['remote_device_id'])) { - $link_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?",array($link_devices['remote_device_id'])); - if (!empty($link_dev)) { - $tmp_devices[] = array('id'=>$link_devices['remote_device_id'],'label'=>$link_dev['hostname'],'title'=>generate_device_link($link_dev,'',array(),'','','',0),'group'=>$link_dev['location'],'shape'=>'box'); - } + if (!in_array($items['remote_device_id'],$tmp_ids)) { + $tmp_devices[] = array('id'=>$items['remote_device_id'],'label'=>$items['remote_hostname'],'title'=>generate_device_link($remote_device,'',array(),'','','',0),'shape'=>'box'); } - array_push($tmp_ids,$link_devices['local_device_id']); - array_push($tmp_ids,$link_devices['remote_device_id']); + array_push($tmp_ids,$items['local_device_id']); + array_push($tmp_ids,$items['remote_device_id']); + $speed = $items['local_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 = ($items['local_ifinoctets_rate'] * 8) / $items['local_ifspeed'] * 100; + $link_out_used = ($items['local_ifoutoctets_rate'] * 8) / $items['local_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]; + $tmp_links[] = array('from'=>$items['local_device_id'],'to'=>$items['remote_device_id'],'label'=>shorten_interface_type($items['local_ifname']) . ' > ' . shorten_interface_type($items['remote_ifname']),'title'=>generate_port_link($local_port, "",'',0,1),'width'=>$width,'color'=>$link_color); } -$tmp_ids = implode(',',$tmp_ids); - -$nodes = json_encode($tmp_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) { - $port=''; - foreach ($tmp_devices as $k=>$v) { - if ($v['id'] == $link_devices['local_device_id']) { - $from = $v['id']; - $port = shorten_interface_type($link_devices['ifName']); - $port_data = $link_devices; - } - if ($v['id'] == $link_devices['remote_device_id']) { - $to = $v['id']; - $port .= ' > ' .shorten_interface_type($link_devices['remote_port']); - } - } - $speed = $link_devices['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 = ($link_devices['ifInOctets_rate'] * 8) / $link_devices['ifSpeed'] * 100; - $link_out_used = ($link_devices['ifOutOctets_rate'] * 8) / $link_devices['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]; +$node_devices = $tmp_devices; +$nodes = json_encode($node_devices); +$edges = json_encode($tmp_links); - $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); +if (count($node_devices) > 1 && count($tmp_links) > 0) { ?>
- diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index ffea2d92e..1a4748908 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -1,5 +1,5 @@ = 5) { $links['count'] = dbFetchCell("SELECT COUNT(*) FROM `links`"); -} else { - $links['count'] = dbFetchCell("SELECT COUNT(*) FROM `links` AS `L`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `L`.`local_device_id` = `D`.`device_id`", array($_SESSION['user_id'])); +} +else { + $links['count'] = dbFetchCell("SELECT COUNT(*) FROM `links` AS `L`, `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` AND `L`.`local_device_id` = `D`.`device_id`", array($_SESSION['user_id'])); } -if (isset($config['enable_bgp']) && $config['enable_bgp']) -{ - $bgp_alerts = dbFetchCell("SELECT COUNT(bgpPeer_id) FROM bgpPeers AS B where (bgpPeerAdminStatus = 'start' OR bgpPeerAdminStatus = 'running') AND bgpPeerState != 'established'"); +if (isset($config['enable_bgp']) && $config['enable_bgp']) { + $bgp_alerts = dbFetchCell("SELECT COUNT(bgpPeer_id) FROM bgpPeers AS B where (bgpPeerAdminStatus = 'start' OR bgpPeerAdminStatus = 'running') AND bgpPeerState != 'established'"); } if (isset($config['site_style']) && ($config['site_style'] == 'dark' || $config['site_style'] == 'mono')) { @@ -34,14 +34,12 @@ if (isset($config['site_style']) && ($config['site_style'] == 'dark' || $config[ '); - } - else - { +} +else { echo(''.$config['project_name'].''); - } +} ?>
@@ -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,53 +119,39 @@ unset($group); '); if ($_SESSION['userlevel'] >= '10') { -if ($config['show_locations']) -{ - - echo(' + if ($config['show_locations']) { + echo(' - '); -} - echo(' + '); + } + echo('
  • Manage Groups
  • Add Device
  • Delete Device
  • '); } -if ($links['count'] > 0) { - ?>
  • Network Map Network Map
  • - -
  • Alerts ('.$service_alerts.')
  • '); } -if ($_SESSION['userlevel'] >= '10') -{ - echo(' +if ($_SESSION['userlevel'] >= '10') { + echo('
  • Add Service
  • Edit Service
  • @@ -205,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']); } @@ -247,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++; + } } ?> @@ -269,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.')
  • '); +} ?> @@ -278,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++; } ?> @@ -345,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") { ?> @@ -448,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
  • '); } ?> @@ -465,9 +439,8 @@ if ($_SESSION['userlevel'] >= '10') @@ -484,50 +457,42 @@ if(is_file("includes/print-menubar-custom.inc.php"))