mirror of
https://github.com/ShaYmez/xlxd.git
synced 2024-09-27 07:16:49 -04:00
v2.3.8
add support for network traffic statistics via vnstat.
This commit is contained in:
parent
8ea9385d56
commit
f696a5f7fd
@ -13,35 +13,33 @@ ShowLast3ByteOfIP
|
||||
$Service = array();
|
||||
$CallingHome = array();
|
||||
$PageOptions = array();
|
||||
$VNStat = array();
|
||||
|
||||
$PageOptions['ContactEmail'] = 'your_email'; // Support E-Mail address
|
||||
$PageOptions['ContactEmail'] = 'your_mail'; // Support E-Mail address
|
||||
|
||||
$PageOptions['DashboardVersion'] = '2.3.7'; // Dashboard Version
|
||||
|
||||
$PageOptions['PageRefreshActive'] = true; // Activate automatic refresh
|
||||
$PageOptions['PageRefreshDelay'] = '10000'; // Page refresh time in miliseconds
|
||||
$PageOptions['DashboardVersion'] = '2.3.8'; // Dashboard Version
|
||||
|
||||
$PageOptions['PageRefreshActive'] = true; // Activate automatic refresh
|
||||
$PageOptions['PageRefreshDelay'] = '10000'; // Page refresh time in miliseconds
|
||||
|
||||
$PageOptions['RepeatersPage'] = array();
|
||||
$PageOptions['RepeatersPage']['LimitTo'] = 99; // Number of Repeaters to show
|
||||
$PageOptions['RepeatersPage']['IPModus'] = 'ShowFullIP'; // See possible options above
|
||||
$PageOptions['RepeatersPage']['MasqueradeCharacter'] = '*'; // Character used for masquerade
|
||||
|
||||
$PageOptions['RepeatersPage']['LimitTo'] = 99; // Number of Repeaters to show
|
||||
$PageOptions['RepeatersPage']['IPModus'] = 'ShowFullIP'; // See possible options above
|
||||
$PageOptions['RepeatersPage']['MasqueradeCharacter'] = '*'; // Character used for masquerade
|
||||
|
||||
$PageOptions['PeerPage'] = array();
|
||||
$PageOptions['PeerPage']['LimitTo'] = 99; // Number of peers to show
|
||||
$PageOptions['PeerPage']['IPModus'] = 'ShowFullIP'; // See possible options above
|
||||
$PageOptions['PeerPage']['MasqueradeCharacter'] = '*'; // Character used for masquerade
|
||||
$PageOptions['PeerPage']['LimitTo'] = 99; // Number of peers to show
|
||||
$PageOptions['PeerPage']['IPModus'] = 'ShowFullIP'; // See possible options above
|
||||
$PageOptions['PeerPage']['MasqueradeCharacter'] = '*'; // Character used for masquerade
|
||||
|
||||
$PageOptions['LastHeardPage']['LimitTo'] = 39; // Number of stations to show
|
||||
|
||||
$PageOptions['ModuleNames'] = array(); // Module nomination
|
||||
$PageOptions['ModuleNames'] = array(); // Module nomination
|
||||
$PageOptions['ModuleNames']['A'] = 'Int.';
|
||||
$PageOptions['ModuleNames']['B'] = 'Regional';
|
||||
$PageOptions['ModuleNames']['C'] = 'National';
|
||||
$PageOptions['ModuleNames']['D'] = '';
|
||||
|
||||
|
||||
$PageOptions['MetaDescription'] = 'XLX is a D-Star Reflector System for Ham Radio Operators.'; // Meta Tag Values, usefull for Search Engine
|
||||
$PageOptions['MetaKeywords'] = 'Ham Radio, D-Star, XReflector, XLX, XRF, DCS, REF, '; // Meta Tag Values, usefull forSearch Engine
|
||||
$PageOptions['MetaAuthor'] = 'LX1IQ'; // Meta Tag Values, usefull for Search Engine
|
||||
@ -50,27 +48,24 @@ $PageOptions['MetaRobots'] = 'index,follow';
|
||||
|
||||
$PageOptions['UserPage']['ShowFilter'] = true; // Show Filter on Users page
|
||||
|
||||
$PageOptions['Traffic']['Show'] = false; // Enable vnstat traffic statistics
|
||||
|
||||
$Service['PIDFile'] = '/var/log/xlxd.pid';
|
||||
$Service['XMLFile'] = '/var/log/xlxd.xml';
|
||||
|
||||
$CallingHome['Active'] = false; // xlx phone home, true or false
|
||||
$CallingHome['MyDashBoardURL'] = 'http://your_dashboard'; // dashboard url
|
||||
$CallingHome['Active'] = false; // xlx phone home, true or false
|
||||
$CallingHome['MyDashBoardURL'] = 'http://your_dashboard'; // dashboard url
|
||||
$CallingHome['ServerURL'] = 'http://xlxapi.rlx.lu/api.php'; // database server, do not change !!!!
|
||||
$CallingHome['PushDelay'] = 600; // push delay in seconds
|
||||
$CallingHome['Country'] = "your_country"; // Country
|
||||
$CallingHome['Comment'] = "your_comment"; // Comment. Max 100 character
|
||||
$CallingHome['Comment'] = "your_comment"; // Comment. Max 100 character
|
||||
$CallingHome['HashFile'] = "/tmp/callinghome.php"; // Make sure the apache user has read and write permissions in this folder.
|
||||
$CallingHome['OverrideIPAddress'] = ""; // Insert your IP address here. Leave blank for autodetection. No need to enter a fake address.
|
||||
$CallingHome['InterlinkFile'] = "/xlxd/xlxd.interlink"; // Path to interlink file
|
||||
|
||||
|
||||
/*
|
||||
include an extra config file for people who dont like to mess with shipped config.ing.php
|
||||
this makes updating dashboard from git a little bit easier
|
||||
*/
|
||||
|
||||
if (file_exists("../config.inc.php")) {
|
||||
include ("../config.inc.php");
|
||||
}
|
||||
$VNStat['Interfaces'] = array();
|
||||
$VNStat['Interfaces'][0]['Name'] = 'eth0';
|
||||
$VNStat['Interfaces'][0]['Address'] = 'eth0';
|
||||
$VNStat['Binary'] = '/usr/bin/vnstat';
|
||||
|
||||
?>
|
||||
|
@ -60,4 +60,133 @@ function CreateCode ($laenge) {
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
function UpdateHashFile($HashFile, $newLastSync, $newHash) {
|
||||
if (version_compare(phpversion(), "5.6", ">=")) {
|
||||
$Ressource = @fopen($HashFile, "c");
|
||||
if ($Ressource) {
|
||||
if (flock($Ressource, LOCK_EX)) {
|
||||
@fwrite($Ressource, "<?php\n");
|
||||
@fwrite($Ressource, "\n".'$LastSync = '.$newLastSync.';');
|
||||
@fwrite($Ressource, "\n".'$Hash = "'.$newHash.'";');
|
||||
@fwrite($Ressource, "\n\n".'?>');
|
||||
|
||||
@fflush($Ressource);
|
||||
@ftruncate($Ressource, ftell($Ressource));
|
||||
@flock($Ressource, LOCK_UN);
|
||||
}
|
||||
@fclose($Ressource);
|
||||
@chmod($HashFile, 0777);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$Ressource = @fopen($HashFile, "w");
|
||||
if ($Ressource) {
|
||||
@fwrite($Ressource, "<?php\n");
|
||||
@fwrite($Ressource, "\n".'$LastSync = 0;');
|
||||
@fwrite($Ressource, "\n".'$Hash = "'.$newHash.'";');
|
||||
@fwrite($Ressource, "\n\n".'?>');
|
||||
@fclose($Ressource);
|
||||
@exec("chmod 777 ".$CallingHome['HashFile']);
|
||||
$CallHomeNow = true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function VNStatLocalize($str) {
|
||||
global $L;
|
||||
if (isset($L[$str])) {
|
||||
return $L[$str];
|
||||
}
|
||||
else {
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
function VNStatGetData($iface, $vnstat_bin) {
|
||||
$vnstat_data = array();
|
||||
|
||||
$fd = @popen("$vnstat_bin --dumpdb -i $iface", "r");
|
||||
if (is_resource($fd)) {
|
||||
$buffer = '';
|
||||
while (!feof($fd)) {
|
||||
$buffer .= fgets($fd);
|
||||
}
|
||||
$vnstat_data = explode("\n", $buffer);
|
||||
pclose($fd);
|
||||
}
|
||||
|
||||
$day = array();
|
||||
$hour = array();
|
||||
$month = array();
|
||||
$top = array();
|
||||
|
||||
if (isset($vnstat_data[0]) && strpos($vnstat_data[0], 'Error') !== false) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($vnstat_data as $line) {
|
||||
$d = explode(';', trim($line));
|
||||
if ($d[0] == 'd') {
|
||||
$day[$d[1]]['time'] = $d[2];
|
||||
$day[$d[1]]['rx'] = $d[3] * 1024 + $d[5];
|
||||
$day[$d[1]]['tx'] = $d[4] * 1024 + $d[6];
|
||||
$day[$d[1]]['act'] = $d[7];
|
||||
$day[$d[1]]['rx2'] = $d[5];
|
||||
$day[$d[1]]['tx2'] = $d[6];
|
||||
}
|
||||
else if ($d[0] == 'm') {
|
||||
$month[$d[1]]['time'] = $d[2];
|
||||
$month[$d[1]]['rx'] = $d[3] * 1024 + $d[5];
|
||||
$month[$d[1]]['tx'] = $d[4] * 1024 + $d[6];
|
||||
$month[$d[1]]['act'] = $d[7];
|
||||
$month[$d[1]]['rx2'] = $d[5];
|
||||
$month[$d[1]]['tx2'] = $d[6];
|
||||
}
|
||||
else if ($d[0] == 'h') {
|
||||
$hour[$d[1]]['time'] = $d[2];
|
||||
$hour[$d[1]]['rx'] = $d[3];
|
||||
$hour[$d[1]]['tx'] = $d[4];
|
||||
$hour[$d[1]]['act'] = 1;
|
||||
}
|
||||
else if ($d[0] == 't') {
|
||||
$top[$d[1]]['time'] = $d[2];
|
||||
$top[$d[1]]['rx'] = $d[3] * 1024 + $d[5];
|
||||
$top[$d[1]]['tx'] = $d[4] * 1024 + $d[6];
|
||||
$top[$d[1]]['act'] = $d[7];
|
||||
}
|
||||
else {
|
||||
$summary[$d[0]] = isset($d[1]) ? $d[1] : '';
|
||||
}
|
||||
}
|
||||
|
||||
rsort($day);
|
||||
rsort($month);
|
||||
rsort($hour);
|
||||
|
||||
return array($day, $month, $hour, $day, $month, $top, $summary);
|
||||
}
|
||||
|
||||
|
||||
function kbytes_to_string($kb) {
|
||||
$byte_notation = null;
|
||||
$units = array('TB','GB','MB','KB');
|
||||
$scale = 1024*1024*1024;
|
||||
$ui = 0;
|
||||
$custom_size = isset($byte_notation) && in_array($byte_notation, $units);
|
||||
|
||||
while ((($kb < $scale) && ($scale > 1)) || $custom_size) {
|
||||
$ui++;
|
||||
$scale = $scale / 1024;
|
||||
if ($custom_size && $units[$ui] == $byte_notation) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sprintf("%0.2f %s", ($kb/$scale),$units[$ui]);
|
||||
}
|
||||
|
||||
|
||||
?>
|
102
dashboard/pgs/traffic.php
Normal file
102
dashboard/pgs/traffic.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_GET['iface'])) {
|
||||
if (isset($VNStat['Interfaces'][0]['Address'])) {
|
||||
$_GET['iface'] = $VNStat['Interfaces'][0]['Address'];
|
||||
}
|
||||
else {
|
||||
$_GET['iface'] = "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$f = false;
|
||||
$i = 0;
|
||||
while ($i < count($VNStat['Interfaces']) && (!$f)) {
|
||||
if ($_GET['iface'] == $VNStat['Interfaces'][$i]['Address']) {
|
||||
$f = true;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if (!$f) {
|
||||
$_GET['iface'] = "";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<table class="listingtable">
|
||||
<tr>
|
||||
<th>Network interfaces</th>
|
||||
<th>Statistics</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#F1FAFA" align="left" valign="top" style="padding-left:5px;"><?php
|
||||
|
||||
for ($i=0;$i<count($VNStat['Interfaces']);$i++) {
|
||||
echo '<a href="./index.php?show=traffic&iface='.$VNStat['Interfaces'][$i]['Address'].'" class="listinglink">'.$VNStat['Interfaces'][$i]['Name'].'</a>';
|
||||
if ($i < count($VNStat['Interfaces'])) {
|
||||
echo '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
?></td>
|
||||
<td bgcolor="#FFFFFF"><?php
|
||||
|
||||
$Data = VNStatGetData($_GET['iface'], $VNStat['Binary']);
|
||||
|
||||
echo '
|
||||
<table style="margin:10px;">
|
||||
<tr>
|
||||
<td>Day</td>
|
||||
<td>RX</td>
|
||||
<td>TX</td>
|
||||
<td>Avg Rx</td>
|
||||
<td>Avg TX</td>
|
||||
</tr>';
|
||||
|
||||
for ($i=0;$i<count($Data[0]);$i++) {
|
||||
if ($Data[0][$i]['time'] > 0) {
|
||||
echo '
|
||||
<tr>
|
||||
<td width="100">'.date("d.m.Y", $Data[0][$i]['time']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[0][$i]['rx']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[0][$i]['tx']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[0][$i]['rx2']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[0][$i]['tx2']).'</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '<table>';
|
||||
|
||||
|
||||
|
||||
|
||||
echo '
|
||||
<table style="margin:10px;">
|
||||
<tr>
|
||||
<td>Month</td>
|
||||
<td>RX</td>
|
||||
<td>TX</td>
|
||||
<td>Avg Rx</td>
|
||||
<td>Avg TX</td>
|
||||
</tr>';
|
||||
|
||||
for ($i=0;$i<count($Data[1]);$i++) {
|
||||
if ($Data[1][$i]['time'] > 0) {
|
||||
echo '
|
||||
<tr>
|
||||
<td width="100">'.date("F", $Data[1][$i]['time']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[1][$i]['rx']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[1][$i]['tx']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[1][$i]['rx2']).'</td>
|
||||
<td width="100">'.kbytes_to_string($Data[1][$i]['tx2']).'</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '<table>';
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
Loading…
Reference in New Issue
Block a user