mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
CSV Exports
This commit is contained in:
52
html/csv.php
Normal file
52
html/csv.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
*
|
||||
* 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";
|
||||
}
|
||||
?>
|
137
html/includes/reports/ports.csv.inc.php
Normal file
137
html/includes/reports/ports.csv.inc.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
$param = array();
|
||||
|
||||
if(!isset($vars['ignore'])) { $vars['ignore'] = "0"; }
|
||||
if(!isset($vars['disabled'])) { $vars['disabled'] = "0"; }
|
||||
if(!isset($vars['deleted'])) { $vars['deleted'] = "0"; }
|
||||
|
||||
$where = '';
|
||||
|
||||
foreach ($vars as $var => $value)
|
||||
{
|
||||
if ($value != "")
|
||||
{
|
||||
switch ($var)
|
||||
{
|
||||
case 'hostname':
|
||||
$where .= " AND D.hostname LIKE ?";
|
||||
$param[] = "%".$value."%";
|
||||
break;
|
||||
case 'location':
|
||||
$where .= " AND D.location LIKE ?";
|
||||
$param[] = "%".$value."%";
|
||||
break;
|
||||
case 'device_id':
|
||||
$where .= " AND D.device_id = ?";
|
||||
$param[] = $value;
|
||||
break;
|
||||
case 'deleted':
|
||||
case 'ignore':
|
||||
if ($value == 1)
|
||||
{
|
||||
$where .= " AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0";
|
||||
}
|
||||
break;
|
||||
case 'disable':
|
||||
case 'ifSpeed':
|
||||
if (is_numeric($value))
|
||||
{
|
||||
$where .= " AND I.$var = ?";
|
||||
$param[] = $value;
|
||||
}
|
||||
break;
|
||||
case 'ifType':
|
||||
$where .= " AND I.$var = ?";
|
||||
$param[] = $value;
|
||||
break;
|
||||
case 'ifAlias':
|
||||
case 'port_descr_type':
|
||||
$where .= " AND I.$var LIKE ?";
|
||||
$param[] = "%".$value."%";
|
||||
break;
|
||||
case 'errors':
|
||||
if ($value == 1)
|
||||
{
|
||||
$where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')";
|
||||
}
|
||||
break;
|
||||
case 'state':
|
||||
if ($value == "down")
|
||||
{
|
||||
$where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ?";
|
||||
$param[] = "up";
|
||||
$param[] = "down";
|
||||
} elseif($value == "up") {
|
||||
$where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'";
|
||||
$param[] = "up";
|
||||
$param[] = "up";
|
||||
} elseif($value == "admindown") {
|
||||
$where .= "AND I.ifAdminStatus = ? AND D.ignore = 0";
|
||||
$param[] = "down";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
?>
|
40
html/includes/vars.inc.php
Normal file
40
html/includes/vars.inc.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
}
|
@@ -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; }
|
||||
|
@@ -60,6 +60,7 @@ foreach ($menu_options as $option => $text)
|
||||
echo('<div style="float: right;">');
|
||||
?>
|
||||
|
||||
<a href="/csv.php/report=<?php echo generate_url($vars,array('format'=>'')); ?>" title="Export as CSV" target="_blank">Export CSV</a> |
|
||||
<a href="<?php echo(generate_url($vars)); ?>" title="Update the browser URL to reflect the search criteria." >Update URL</a> |
|
||||
|
||||
<?php
|
||||
|
@@ -55,7 +55,7 @@ $pdf->setTextShadow(array('enabled'=>false, 'depth_w'=>0.2, 'depth_h'=>0.2, 'col
|
||||
if (isset($_GET['report']) && !empty($_GET['report'])) {
|
||||
$report = mres($_GET['report']);
|
||||
$pdf->SetHeaderData('../../' . $config['title_image'], 40, ucfirst($report), $config['project_name'], array(0,0,0), array(0,64,128));
|
||||
include_once "includes/reports/$report.inc.php";
|
||||
include_once "includes/reports/$report.pdf.inc.php";
|
||||
} else {
|
||||
$report = 'report';
|
||||
}
|
||||
|
Reference in New Issue
Block a user