Permalink
Browse files

First attempt of Dashboard...

  • Loading branch information...
dg9vh committed Jun 12, 2016
1 parent 2e35938 commit b4d02247a0cbd0fde6a64d6b397c192825eb42c7
Showing with 577 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +32 −0 README.md
  3. +123 −0 include/functions.php
  4. +22 −0 include/gateways.php
  5. +28 −0 include/lh.php
  6. +134 −0 include/sysinfo.php
  7. +74 −0 include/tools.php
  8. +54 −0 index.php
  9. +109 −0 setup.php
View
@@ -0,0 +1 @@
config/config.php
View
@@ -1,2 +1,34 @@
# YSFReflector-Dashboard
Dashboard for YSFReflector (by G4KLX)
=====================================
About
=====
YSFReflector-Dashboard is a web-dashboard for visualization of different data like
system temperatur, cpu-load ... and it shows a last-heard-list.
It relies on YSFReflector by G4KLX (see https://github.com/g4klx/YSFClients). At
this place a big thank you to Jonathan for his great work he did with this
software.
Required are
============
* Webserver like
* lighttpd
* php5
* entry in /etc/sudoers:
www-data ALL=(ALL) NOPASSWD: ALL
Installation
============
* Please ensure to not put loglevels at 0 in YSFReflector.ini.
* Copy all files into your webroot and enjoy working with it.
* Create a config/config.php by calling setup.php and giving suitable values
* If Dashboard is working, remove setup.php from your webroot
For detailled installation see `linux-step-by-step.md` within this repository.
Contact
=======
Feel free to contact the author via email: dg9vh@darc.de
View
@@ -0,0 +1,123 @@
<?php
function getYSFReflectorVersion() {
// returns creation-time of YSFReflector as version-number
$filename = YSFREFLECTORPATH."/YSFReflector";
exec($filename." -v 2>&1", $output);
if (!startsWith(substr($output[0],21,8),"20")) {
return getYSFReflectorFileVersion();
} else {
return substr($output[0],21,8)." (compiled ".getYSFReflectorFileVersion().")";
}
}
function getYSFReflectorFileVersion() {
// returns creation-time of YSFReflector as version-number
$filename = YSFREFLECTORPATH."/YSFReflector";
if (file_exists($filename)) {
return date("d M y", filectime($filename));
}
}
function getYSFReflectorConfig() {
// loads YSFReflector.ini into array for further use
$conf = array();
if ($configs = fopen(YSFREFLECTORINIPATH."/".YSFREFLECTORINIFILENAME, 'r')) {
while ($config = fgets($configs)) {
array_push($conf, trim ( $config, " \t\n\r\0\x0B"));
}
fclose($configs);
}
return $conf;
}
function getConfigItem($section, $key, $configs) {
// retrieves the corresponding config-entry within a [section]
$sectionpos = array_search("[" . $section . "]", $configs) + 1;
$len = count($configs);
while(startsWith($configs[$sectionpos],$key."=") === false && $sectionpos <= ($len) ) {
if (startsWith($configs[$sectionpos],"[")) {
return null;
}
$sectionpos++;
}
return substr($configs[$sectionpos], strlen($key) + 1);
}
function getYSFReflectorLog() {
// Open Logfile and copy loglines into LogLines-Array()
$logLines = array();
if ($log = fopen(YSFREFLECTORLOGPATH."/".YSFREFLECTORLOGPREFIX."-".date("Y-m-d").".log", 'r')) {
while ($logLine = fgets($log)) {
array_push($logLines, $logLine);
}
fclose($log);
}
return $logLines;
}
function getConnectedGateways($logLines) {
$gateways = Array();
foreach ($logLines as $logLine) {
if(strpos($logLine,"YSFReflector")){
$gateways = Array();
}
if(strpos($logLine,"Adding")) {
$lineParts = explode(" ", $logLine);
if (!array_search($gateways, $lineParts[4])) {
array_push($gateways, Array('callsign'=>$lineParts[4],'timestamp'=>$lineParts[1]." ".substr($lineParts[2],0,8)));
}
}
if(strpos($logLine,"Removing")) {
$lineParts = explode(" ", $logLine);
$pos = array_search($lineParts[4],array_column($gateways, 'callsign'));
array_splice($gateways, $pos, 1);
}
}
return $gateways;
}
function getHeardList($logLines) {
$heardList = array();
foreach ($logLines as $logLine) {
$timestamp = substr($logLine, 3, 19);
$callsign2 = substr($logLine, strpos($logLine,"from") + 5, strpos($logLine,"to") - strpos($logLine,"from") - 6);
$callsign = trim($callsign2);
$target = substr($logLine, strpos($logLine, "to") + 3, strpos($logLine,"at") - strpos($logLine,"to") - 6);
$gateway = substr($logLine, strpos($logLine,"at") + 3);
// Callsign or ID should be less than 11 chars long, otherwise it could be errorneous
if ( strlen($callsign) < 11 ) {
array_push($heardList, array($timestamp, $callsign, $target, $gateway));
}
}
return $heardList;
}
function getLastHeard($logLines) {
//returns last heard list from log
$lastHeard = array();
$heardCalls = array();
$heardList = getHeardList($logLines);
$counter = 0;
foreach ($heardList as $listElem) {
if(!(array_search($listElem[1], $heardCalls) > -1)) {
array_push($heardCalls, $listElem[1]);
array_push($lastHeard, $listElem);
$counter++;
}
if ($counter == LHLINES) {
return $lastHeard;
}
}
return $lastHeard;
}
//Some basic inits
$configs = getYSFReflectorConfig();
$logLines = getYSFReflectorLog();
$reverseLogLines = $logLines;
array_multisort($reverseLogLines,SORT_DESC);
$lastHeard = getLastHeard($reverseLogLines);
?>
View
@@ -0,0 +1,22 @@
<?php
?>
<div class="panel panel-default">
<!-- Standard-Panel-Inhalt -->
<div class="panel-heading">Connected YSFGateways</div>
<!-- Tabelle -->
<table class="table">
<tr>
<th>Time (UTC)</th>
<th>Callsign</th>
</tr>
<?php
$gateways = getConnectedGateways($logLines);
foreach ($gateways as $gateway) {
echo "<tr>";
echo "<td>$gateway[timestamp]</td><td>$gateway[callsign]</td>";
echo "</tr>";
}
?>
</table>
</div>
View
@@ -0,0 +1,28 @@
<?php
?>
<div class="panel panel-default">
<!-- Standard-Panel-Inhalt -->
<div class="panel-heading">Last Heard List of today's <?php echo LHLINES; ?> callsigns.</div>
<!-- Tabelle -->
<table class="table">
<tr>
<th>Time (UTC)</th>
<th>Callsign</th>
<th>Target</th>
<th>Gateway</th>
</tr>
<?php
for ($i = 0; ($i < LHLINES) AND ($i < count($lastHeard)); $i++) {
$listElem = $lastHeard[$i];
echo"<tr>";
echo"<td>$listElem[0]</td>";
echo"<td>$listElem[1]</td>";
echo"<td>$listElem[2]</td>";
echo"<td>$listElem[3]</td>";
echo"<td>$listElem[4]</td>";
echo"</tr>\n";
}
?>
</table>
</div>
View
@@ -0,0 +1,134 @@
<?php
exec("cat /sys/class/thermal/thermal_zone0/temp", $cputemp);
exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", $cpufreq);
$cputemp = $cputemp[0] / 1000;
if (defined("TEMPERATUREALERT") && $cputemp > TEMPERATUREHIGHLEVEL) {
?>
<script>
function deleteLayer(id) {
if (document.getElementById && document.getElementById(id)) {
var theNode = document.getElementById(id);
theNode.parentNode.removeChild(theNode);
}
else if (document.all && document.all[id]) {
document.all[id].innerHTML='';
document.all[id].outerHTML='';
}
// OBSOLETE CODE FOR NETSCAPE 4
else if (document.layers && document.layers[id]) {
document.layers[id].visibility='hide';
delete document.layers[id];
}
}
function makeLayer(id,L,T,W,H,bgColor,visible,zIndex) {
if (document.getElementById) {
if (document.getElementById(id)) {
alert ('Layer with this ID already exists!');
return;
}
var ST = 'position:absolute; text-align:center;padding-top:20px;'
+'; left:'+L+'px'
+'; top:'+T+'px'
+'; width:'+W+'px'
+'; height:'+H+'px'
+'; clip:rect(0,'+W+','+H+',0)'
+'; visibility:'
+(null==visible || 1==visible ? 'visible':'hidden')
+(null==zIndex ? '' : '; z-index:'+zIndex)
+(null==bgColor ? '' : '; background-color:'+bgColor);
var LR = '<DIV id='+id+' style="'+ST+'">CPU-Temperature is very high!<br><input type="button" value="Close" onclick="deleteLayer(\'LYR1\')"></DIV>';
if (document.body) {
if (document.body.insertAdjacentHTML)
document.body.insertAdjacentHTML("BeforeEnd",LR);
else if (document.createElement && document.body.appendChild) {
var newNode = document.createElement('div');
newNode.setAttribute('id',id);
newNode.setAttribute('style',ST);
document.body.appendChild(newNode);
}
}
}
}
var audio = new Audio('sounds/alert.mp3');
audio.play();
var x = window.innerWidth/2-100;
var y = window.innerHeight/2-50;
makeLayer('LYR1',x,y,200,100,'red',1,1);
</script>
<?php
}
$cpufreq = $cpufreq[0] / 1000;
$output = shell_exec('cat /proc/loadavg');
$sysload = substr($output,0,strpos($output," "))*100;
$stat1 = file('/proc/stat');
sleep(1);
$stat2 = file('/proc/stat');
$info1 = explode(" ", preg_replace("!cpu +!", "", $stat1[0]));
$info2 = explode(" ", preg_replace("!cpu +!", "", $stat2[0]));
$dif = array();
$dif['user'] = $info2[0] - $info1[0];
$dif['nice'] = $info2[1] - $info1[1];
$dif['sys'] = $info2[2] - $info1[2];
$dif['idle'] = $info2[3] - $info1[3];
$total = array_sum($dif);
$cpu = array();
foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 1);
$cpuusage = round($cpu['user'] + $cpu['sys'], 2);
$output = shell_exec('grep -c processor /proc/cpuinfo');
$cpucores = $output;
$output = shell_exec('cat /proc/uptime');
$uptime = format_time(substr($output,0,strpos($output," ")));
$idletime = format_time((substr($output,strpos($output," ")))/$cpucores);
?>
<div class="panel panel-default">
<!-- Standard-Panel-Inhalt -->
<div class="panel-heading">System Info</div>
<!-- Tabelle -->
<table class="table">
<tbody>
<tr>
<th>CPU-Temperature</th>
<th>CPU-Frequency</th>
<th>System-Load</th>
<th>CPU-Usage</th>
<th>Uptime</th>
<th>Idle</th>
</tr>
<tr class="gatewayinfo">
<td><?php echo $cputemp; ?> &deg;C</td>
<td><?php echo $cpufreq; ?> MHz</td>
<td><?php echo $sysload; ?> %</td>
<td>
<?php
if (defined("SHOWPROGRESSBARS")) {
?>
<div class="progress"><div class="progress-bar <?php
if ($cpuusage < 30)
echo "progress-bar-success";
if ($cpuusage >= 30 and $cpuusage < 60)
echo "progress-bar-warning";
if ($cpuusage >= 60)
echo "progress-bar-danger";
?>" role="progressbar" aria-valuenow="<?php echo $cpuusage; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $cpuusage; ?>%;"><?php echo $cpuusage; ?>%</div></div>
<?php
} else {
echo $cpuusage." %";
}
?>
</td>
<td><?php echo $uptime; ?></td>
<td><?php echo $idletime; ?></td>
</tr>
</tbody>
</table>
</div>
Oops, something went wrong.

0 comments on commit b4d0224

Please sign in to comment.