diff --git a/html/csv.php b/html/csv.php new file mode 100644 index 0000000000..1f9dee0ca8 --- /dev/null +++ b/html/csv.php @@ -0,0 +1,52 @@ + + * + * 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 (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"; + +$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"; +} +?> diff --git a/html/includes/reports/alert-log.inc.php b/html/includes/reports/alert-log.pdf.inc.php similarity index 100% rename from html/includes/reports/alert-log.inc.php rename to html/includes/reports/alert-log.pdf.inc.php diff --git a/html/includes/reports/example.inc.php b/html/includes/reports/example.pdf.inc.php similarity index 100% rename from html/includes/reports/example.inc.php rename to html/includes/reports/example.pdf.inc.php diff --git a/html/includes/reports/ports.csv.inc.php b/html/includes/reports/ports.csv.inc.php new file mode 100644 index 0000000000..5013afd414 --- /dev/null +++ b/html/includes/reports/ports.csv.inc.php @@ -0,0 +1,137 @@ + $value) +{ + if ($value != "") + { + switch ($var) + { + case 'hostname': + $where .= " AND D.hostname LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'location': + $where .= " AND D.location LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'device_id': + $where .= " AND D.device_id = ?"; + $param[] = $value; + break; + case 'deleted': + case 'ignore': + if ($value == 1) + { + $where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0"; + } + break; + case 'disable': + case 'ifSpeed': + if (is_numeric($value)) + { + $where .= " AND I.$var = ?"; + $param[] = $value; + } + break; + case 'ifType': + $where .= " AND I.$var = ?"; + $param[] = $value; + break; + case 'ifAlias': + case 'port_descr_type': + $where .= " AND I.$var LIKE ?"; + $param[] = "%".$value."%"; + break; + case 'errors': + if ($value == 1) + { + $where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"; + } + break; + case 'state': + if ($value == "down") + { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?"; + $param[] = "up"; + $param[] = "down"; + } elseif($value == "up") { + $where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'"; + $param[] = "up"; + $param[] = "up"; + } elseif($value == "admindown") { + $where .= "AND I.ifAdminStatus = ? AND D.ignore = 0"; + $param[] = "down"; + } + break; + } + } +} + +$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ".$where." ".$query_sort; + +$row = 1; + +list($format, $subformat) = explode("_", $vars['format']); + +$ports = dbFetchRows($query, $param); + +switch ($vars['sort']) +{ + case 'traffic': + $ports = array_sort($ports, 'ifOctets_rate', SORT_DESC); + break; + case 'traffic_in': + $ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC); + break; + case 'traffic_out': + $ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC); + break; + case 'packets': + $ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC); + break; + case 'packets_in': + $ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC); + break; + case 'packets_out': + $ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC); + break; + case 'errors': + $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); + break; + case 'speed': + $ports = array_sort($ports, 'ifSpeed', SORT_DESC); + break; + case 'port': + $ports = array_sort($ports, 'ifDescr', SORT_ASC); + break; + case 'media': + $ports = array_sort($ports, 'ifType', SORT_ASC); + break; + case 'descr': + $ports = array_sort($ports, 'ifAlias', SORT_ASC); + break; + case 'device': + default: + $ports = array_sort($ports, 'hostname', SORT_ASC); +} + +$csv[] = array('Device','Port','Speed','Down','Up','Media','Description'); +foreach( $ports as $port ) { + if( port_permitted($port['port_id'], $port['device_id']) ) { + $speed = humanspeed($port['ifSpeed']); + $type = humanmedia($port['ifType']); + $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); + $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); + $port = ifLabel($port, $device); + $csv[] = array($port['hostname'],fixIfName($port['label']),$speed,$port['in_rate'],$port['out_rate'],$type,$port['ifAlias']); + } +} +?> diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php new file mode 100644 index 0000000000..788915f694 --- /dev/null +++ b/html/includes/vars.inc.php @@ -0,0 +1,40 @@ +$get_var) +{ + if (strstr($key, "opt")) + { + list($name, $value) = explode("|", $get_var); + if (!isset($value)) { $value = "yes"; } + $vars[$name] = $value; + } +} + +$segments = explode('/', trim($_SERVER['REQUEST_URI'], '/')); + +foreach ($segments as $pos => $segment) +{ + $segment = urldecode($segment); + if ($pos == "0") + { + $vars['page'] = $segment; + } else { + list($name, $value) = explode("=", $segment); + if ($value == "" || !isset($value)) + { + $vars[$name] = yes; + } else { + $vars[$name] = $value; + } + } +} + +foreach ($_GET as $name => $value) +{ + $vars[$name] = $value; +} + +foreach ($_POST as $name => $value) +{ + $vars[$name] = $value; +} diff --git a/html/index.php b/html/index.php index a7baf36ae9..62618323c7 100755 --- a/html/index.php +++ b/html/index.php @@ -52,6 +52,7 @@ include("../config.php"); include_once("../includes/definitions.inc.php"); include("../includes/functions.php"); include("includes/functions.inc.php"); +include("includes/vars.inc.php"); include('includes/plugins.inc.php'); Plugins::start(); @@ -70,45 +71,6 @@ ob_start(); ini_set('allow_url_fopen', 0); ini_set('display_errors', 0); -foreach ($_GET as $key=>$get_var) -{ - if (strstr($key, "opt")) - { - list($name, $value) = explode("|", $get_var); - if (!isset($value)) { $value = "yes"; } - $vars[$name] = $value; - } -} - -$segments = explode('/', trim($_SERVER['REQUEST_URI'], '/')); - -foreach ($segments as $pos => $segment) -{ - $segment = urldecode($segment); - if ($pos == "0") - { - $vars['page'] = $segment; - } else { - list($name, $value) = explode("=", $segment); - if ($value == "" || !isset($value)) - { - $vars[$name] = yes; - } else { - $vars[$name] = $value; - } - } -} - -foreach ($_GET as $name => $value) -{ - $vars[$name] = $value; -} - -foreach ($_POST as $name => $value) -{ - $vars[$name] = $value; -} - include("includes/authenticate.inc.php"); if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { $_SESSION['widescreen'] = 1; } diff --git a/html/pages/ports.inc.php b/html/pages/ports.inc.php index 23977e5e75..386100262a 100644 --- a/html/pages/ports.inc.php +++ b/html/pages/ports.inc.php @@ -60,6 +60,7 @@ foreach ($menu_options as $option => $text) echo('