First commit
This commit is contained in:
commit
872a281894
12
License.txt
Normal file
12
License.txt
Normal file
@ -0,0 +1,12 @@
|
||||
Copyright (c) 2016, Mr. Gecko's Media (James Coleman)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
||||
I needed a tool like this for my pfSense router, so I decided to go ahead and write my own. I loved getting these graphs from [vnStat](http://humdi.net/vnstat/), and wanted it on my new router. Easy to share and nice to look at. Make sure you edit the config.php file to your liking.
|
46
config.php
Normal file
46
config.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
//
|
||||
// config.php
|
||||
// vnStatGraphP
|
||||
//
|
||||
// Created by Mr. Gecko on 3/28/16.
|
||||
// Copyright (c) 2016 Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/
|
||||
//
|
||||
|
||||
//List of interfaces configured for vnStat.
|
||||
$ifaceList = array("igb0");
|
||||
//Optional readable title for interfaces.
|
||||
$ifaceTitles = array("igb0" => "External");
|
||||
|
||||
//Graphs to be shown on load of the index.
|
||||
$defaultGraphs = array(
|
||||
"vnstati.php?i=igb0&g=vs",
|
||||
"vnstati.php?i=igb0&g=d"
|
||||
);
|
||||
|
||||
//Location for the binary of vnStatI.
|
||||
$vnStatIBin = "/usr/local/bin/vnstati";
|
||||
|
||||
//Get configuration from parameters.
|
||||
$iface = isset($_REQUEST['i']) ? $_REQUEST['i'] : "";
|
||||
if (!in_array($iface, $ifaceList)) {
|
||||
$iface = $ifaceList[0];
|
||||
}
|
||||
$graph = isset($_REQUEST['g']) ? $_REQUEST['g'] : "vs";
|
||||
switch($graph) {
|
||||
case "h":
|
||||
case "d":
|
||||
case "m":
|
||||
case "t":
|
||||
case "s":
|
||||
case "hs":
|
||||
case "vs":
|
||||
break;
|
||||
default:
|
||||
$graph = "vs";
|
||||
}
|
||||
$noHeader = isset($_REQUEST['nh']) ? (is_string($_REQUEST['nh']) ? empty($_REQUEST['nh']) || preg_match("/^(y|t|on).*/i", $_REQUEST['nh']) : boolval($_REQUEST['nh'])) : false;
|
||||
$noEdge = isset($_REQUEST['ne']) ? (is_string($_REQUEST['ne']) ? empty($_REQUEST['ne']) || preg_match("/^(y|t|on).*/i", $_REQUEST['ne']) : boolval($_REQUEST['ne'])) : false;
|
||||
$noLegend = isset($_REQUEST['nl']) ? (is_string($_REQUEST['nl']) ? empty($_REQUEST['nl']) || preg_match("/^(y|t|on).*/i", $_REQUEST['nl']) : boolval($_REQUEST['nl'])) : false;
|
||||
$rateUnit = isset($_REQUEST['ru']) ? (is_string($_REQUEST['ru']) ? empty($_REQUEST['ru']) || preg_match("/^(y|t|on).*/i", $_REQUEST['ru']) : boolval($_REQUEST['ru'])) : false;
|
||||
?>
|
114
index.php
Normal file
114
index.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
//
|
||||
// index.php
|
||||
// vnStatGraphP
|
||||
//
|
||||
// Created by Mr. Gecko on 3/28/16.
|
||||
// Copyright (c) 2016 Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/
|
||||
//
|
||||
|
||||
require("config.php");
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="Copyright" content="Copyright (c) 2016 Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/" />
|
||||
<meta name="Author" content="James Coleman" />
|
||||
<title>vnStat GraphP</title>
|
||||
<style type="text/css">
|
||||
#optionsBox {
|
||||
border-style: solid;
|
||||
border-color: #afafaf;
|
||||
border-width: 1pt;
|
||||
|
||||
padding: 3pt;
|
||||
width: 490px;
|
||||
}
|
||||
#optionsTitle {
|
||||
background-color: #5f5f5f;
|
||||
color: #ffffff;
|
||||
margin: -1pt;
|
||||
padding: 2pt;
|
||||
padding-left: 5pt;
|
||||
}
|
||||
#optionsBox hr {
|
||||
color: #afafaf;
|
||||
}
|
||||
label.optionName {
|
||||
width: 50pt;
|
||||
}
|
||||
span.optionContainer {
|
||||
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?
|
||||
if (!isset($_REQUEST['i']) && count($defaultGraphs)>=1) {
|
||||
foreach ($defaultGraphs as $thisGraph) {
|
||||
?><img src="<?=$thisGraph?>" /><br /><?
|
||||
}
|
||||
?><br /><br /><?
|
||||
}
|
||||
?>
|
||||
<form action=""><div id="optionsBox">
|
||||
<div id="optionsTitle">vnStatGraphP Options</div><br />
|
||||
<label class="optionName" for="iface">Interface:</label>
|
||||
<span class="optionContainer"><select name="i" id="iface"><?
|
||||
foreach ($ifaceList as $interface) {
|
||||
$name = $interface;
|
||||
if (!empty($ifaceTitles[$interface])) {
|
||||
$name = $interface." - ".$ifaceTitles[$interface];
|
||||
}
|
||||
?><option value="<?=$interface?>"<?=($iface==$interface ? " selected" : "")?>><?=$name?></option><?
|
||||
}
|
||||
?></select></span><br />
|
||||
|
||||
<label class="optionName" for="graph">Graph:</label>
|
||||
<span class="optionContainer"><select name="g" id="graph">
|
||||
<option value="vs"<?=($graph=="vs" ? " selected" : "")?>>Vertical summary with hours</option>
|
||||
<option value="hs"<?=($graph=="hs" ? " selected" : "")?>>Horizontal summary with hours</option>
|
||||
<option value="s"<?=($graph=="s" ? " selected" : "")?>>Summary</option>
|
||||
<option value="t"<?=($graph=="t" ? " selected" : "")?>>Top 10</option>
|
||||
<option value="m"<?=($graph=="m" ? " selected" : "")?>>Months</option>
|
||||
<option value="d"<?=($graph=="d" ? " selected" : "")?>>Days</option>
|
||||
<option value="h"<?=($graph=="h" ? " selected" : "")?>>Hours</option>
|
||||
</select></span><br />
|
||||
|
||||
<label class="optionName" for="noHeader">No Header:</label>
|
||||
<span class="optionContainer"><input type="checkbox" name="nh" id="noHeader"<?=($noHeader ? " checked" : "")?> /></span><br />
|
||||
|
||||
<label class="optionName" for="noEdge">No Edge:</label>
|
||||
<span class="optionContainer"><input type="checkbox" name="ne" id="noEdge"<?=($noEdge ? " checked" : "")?> /></span><br />
|
||||
|
||||
<label class="optionName" for="noLegend">No Legend:</label>
|
||||
<span class="optionContainer"><input type="checkbox" name="nl" id="noLegend"<?=($noLegend ? " checked" : "")?> /></span><br />
|
||||
|
||||
<label class="optionName" for="rateUnit">Rate Unit:</label>
|
||||
<span class="optionContainer"><input type="checkbox" name="ru" id="rateUnit"<?=($rateUnit ? " checked" : "")?> /></span> - Swap configured rate unit<br />
|
||||
<hr />
|
||||
<input type="submit" value="Generate Graph" />
|
||||
</div></form><br />
|
||||
<?
|
||||
if (isset($_REQUEST['i']) || count($defaultGraphs)==0) {
|
||||
$data = "i=".urlencode($iface);
|
||||
$data .= "&g=".$graph;
|
||||
if ($noHeader) {
|
||||
$data .= "&nh";
|
||||
}
|
||||
if ($noEdge) {
|
||||
$data .= "&ne";
|
||||
}
|
||||
if ($noLegend) {
|
||||
$data .= "&nl";
|
||||
}
|
||||
if ($rateUnit) {
|
||||
$data .= "&ru";
|
||||
}
|
||||
?>
|
||||
<span id="vnStatResult"><img src="vnstati.php?<?=$data?>" /></span>
|
||||
<?}?>
|
||||
</body>
|
||||
</html>
|
33
vnstati.php
Normal file
33
vnstati.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
//
|
||||
// vnstati.php
|
||||
// vnStatGraphP
|
||||
//
|
||||
// Created by Mr. Gecko on 3/28/16.
|
||||
// Copyright (c) 2016 Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/
|
||||
//
|
||||
|
||||
require("config.php");
|
||||
|
||||
//No caching as this is always changing.
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-type: image/png");
|
||||
|
||||
//Prepare extra arguments for executing the command.
|
||||
$arguments = "";
|
||||
if ($noHeader) {
|
||||
$arguments .= " -nh";
|
||||
}
|
||||
if ($noEdge) {
|
||||
$arguments .= " -ne";
|
||||
}
|
||||
if ($noLegend) {
|
||||
$arguments .= " -nl";
|
||||
}
|
||||
if ($rateUnit) {
|
||||
$arguments .= " -ru";
|
||||
}
|
||||
|
||||
passthru($vnStatIBin." -i ".escapeshellarg($iface)." -".$graph.$arguments." -o -");
|
||||
?>
|
Loading…
Reference in New Issue
Block a user