MMDVMHost-Dashboard/ajax.php

325 lines
12 KiB
PHP
Raw Permalink Normal View History

<?php
//session_start();
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
include "config/config.php";
2017-03-15 14:20:28 +01:00
if (!defined("LOCALE"))
define("LOCALE", "en_GB");
include "locale/".LOCALE."/settings.php";
$codeset = "UTF8";
putenv('LANG='.LANG_LOCALE.'.'.$codeset);
putenv('LANGUAGE='.LANG_LOCALE.'.'.$codeset);
bind_textdomain_codeset('messages', $codeset);
bindtextdomain('messages', dirname(__FILE__).'/locale/');
setlocale(LC_ALL, LANG_LOCALE.'.'.$codeset);
textdomain('messages');
include "include/tools.php";
include "include/functions.php";
$mmdvmconfigs = getMMDVMConfig();
2016-10-26 15:06:45 +02:00
if (!defined("MMDVMLOGPREFIX"))
2017-01-10 15:04:51 +01:00
define("MMDVMLOGPREFIX", getConfigItem("Log", "FileRoot", $mmdvmconfigs));
if (!defined("TIMEZONE"))
2017-01-10 15:04:51 +01:00
define("TIMEZONE", "UTC");
if (defined("RESOLVETGS")) {
$tgList = getTGList();
}
$logLinesMMDVM = getMMDVMLog();
$reverseLogLinesMMDVM = $logLinesMMDVM;
2017-03-22 22:29:28 +01:00
rsort($reverseLogLinesMMDVM);
if (defined("ENABLEDAPNETGATEWAY")) {
$logLinesDAPNETGateway = getDAPNETGatewayLog();
showLapTime("getDAPNETGatewayLog");
$reverseLogLinesDAPNETGateway = $logLinesDAPNETGateway;
rsort($reverseLogLinesDAPNETGateway);
showLapTime("array_multisort");
}
2016-10-09 22:34:09 +02:00
if ($_GET['section'] == "mode") {
2017-03-22 22:42:29 +01:00
$mode = getActualMode(getLastHeard($reverseLogLinesMMDVM, TRUE), $mmdvmconfigs);
2017-01-10 15:04:51 +01:00
echo $mode;
2016-10-09 22:34:09 +02:00
}
2017-05-07 14:21:21 +02:00
if ($_GET['section'] == "dstarlink") {
$link = getActualLink($reverseLogLinesMMDVM, "D-Star");
echo $link;
}
if ($_GET['section'] == "ysflink") {
$logLinesYSFGateway = getYSFGatewayLog();
$reverseLogLinesYSFGateway = $logLinesYSFGateway;
rsort($reverseLogLinesYSFGateway);
$activeYSFReflectors = getActiveYSFReflectors();
$link = getActualLink($reverseLogLinesYSFGateway, "YSF");
2017-05-07 14:21:21 +02:00
echo $link;
}
if ($_GET['section'] == "dmr1link") {
$link = getActualLink($reverseLogLinesMMDVM, "DMR Slot 1");
echo $link;
}
if ($_GET['section'] == "dmr2link") {
$link = getActualLink($reverseLogLinesMMDVM, "DMR Slot 2")."/". getActualReflector($reverseLogLinesMMDVM, "DMR Slot 2") ;
echo $link;
}
if ($_GET['section'] == "lastHeard") {
2017-02-13 21:48:20 +01:00
$lastHeardList = getLastHeard($reverseLogLinesMMDVM, FALSE);
$lastHeard = Array();
for ($i = 0; $i < count($lastHeardList); $i++) {
$listElem = $lastHeardList[$i];
// Generate a canonicalized call for QRZ and name lookups
$call_canon = preg_replace('/\s+\w$/', '', $listElem[2]);
if (defined("ENABLEXTDLOOKUP")) {
$listElem[11] ="";
array_push($lastHeard, $listElem);
} else {
$listElem[10] ="";
array_push($lastHeard, $listElem);
}
}
2017-01-10 15:04:51 +01:00
echo '{"data": '.json_encode($lastHeard)."}";
}
if ($_GET['section'] == "DAPNETTx") {
$DAPNETTxList = getDAPNETTxList($reverseLogLinesDAPNETGateway);
$DAPNETTx = Array();
for ($i = 0; $i < count($DAPNETTxList); $i++) {
$listElem = $DAPNETTxList[$i];
array_push($DAPNETTx, $listElem);
}
echo '{"data": '.json_encode($DAPNETTx)."}";
}
if ($_GET['section'] == "localTx") {
2017-01-10 15:04:51 +01:00
$localTXList = getHeardList($reverseLogLinesMMDVM, FALSE);
$lastHeard = Array();
for ($i = 0; $i < count($localTXList); $i++) {
$listElem = $localTXList[$i];
// Generate a canonicalized call for QRZ and name lookups
$call_canon = preg_replace('/\s+\w$/', '', $listElem[2]);
//remove suffix used sometimes in YSF (es: -FT2 , -991)
if (strpos($call_canon,"-")!=false) {
$call_canon = substr($call_canon, 0, strpos($call_canon, "-"));
}
2017-01-10 15:04:51 +01:00
if (defined("ENABLEXTDLOOKUP")) {
2024-04-07 20:08:05 +02:00
if (getEnabled("D-Star", $mmdvmconfigs) == 1 && $listElem[6] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25" || $listElem[1]=="NXDN") || getEnabled("D-Star", $mmdvmconfigs) == 0 && $listElem[5] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25" || $listElem[1]=="NXDN")) {
$listElem[3] = getName($call_canon);
2017-01-10 15:04:51 +01:00
if ($listElem[2] !== "??????????") {
if (!is_numeric($listElem[2])) {
2017-01-10 20:38:44 +01:00
if (defined("SHOWQRZ")) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$call_canon\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
2017-01-10 15:04:51 +01:00
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://ham-digital.org/dmr-userreg.php?callsign=$call_canon\">".$listElem[2]."</a>";
2017-01-10 15:04:51 +01:00
}
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://ham-digital.org/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</a>";
2017-01-10 15:04:51 +01:00
}
}
array_push($lastHeard, $listElem);
$oldListElem = $listElem;
2017-01-10 15:04:51 +01:00
}
} else {
//$listElem[10] ="";
2024-04-07 20:08:05 +02:00
if (getEnabled("D-Star", $mmdvmconfigs) == 1 && $listElem[5] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25" || $listElem[1]=="NXDN") || getEnabled("D-Star", $mmdvmconfigs) == 0 && $listElem[4] == "RF" && ($listElem[1]=="D-Star" || startsWith($listElem[1], "DMR") || $listElem[1]=="YSF" || $listElem[1]=="P25" || $listElem[1]=="NXDN")) {
2017-01-10 15:04:51 +01:00
if ($listElem[2] !== "??????????") {
if (!is_numeric($listElem[2])) {
2017-01-10 20:38:44 +01:00
if (defined("SHOWQRZ")) {
$listElem[2] = "<a target=\"_new\" href=\"https://qrz.com/db/$call_canon\">".str_replace("0","&Oslash;",$listElem[2])."</a>";
2017-01-10 15:04:51 +01:00
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://ham-digital.org/dmr-userreg.php?callsign=$call_canon\">".$listElem[2]."</a>";
2017-01-10 15:04:51 +01:00
}
} else {
$listElem[2] = "<a target=\"_new\" href=\"http://ham-digital.org/dmr-userreg.php?usrid=$listElem[2]\">".$listElem[2]."</a>";
2017-01-10 15:04:51 +01:00
}
}
array_push($lastHeard, $listElem);
}
}
}
echo '{"data": '.json_encode($lastHeard)."}";
}
2016-10-12 18:54:11 +02:00
if ($_GET['section'] == "sysinfo") {
2017-01-10 15:04:51 +01:00
$cputemp = NULL;
$cpufreq = NULL;
if (file_exists ("/sys/class/thermal/thermal_zone0/temp")) {
exec("cat /sys/class/thermal/thermal_zone0/temp", $cputemp);
$cputemp = $cputemp[0] / 1000;
}
showLapTime("cputemp");
if (file_exists ("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")) {
exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", $cpufreq);
$cpufreq = $cpufreq[0] / 1000;
}
showLapTime("cpufreq");
2016-10-26 09:46:15 +02:00
2017-01-10 15:04:51 +01:00
if (defined("TEMPERATUREALERT") && $cputemp > TEMPERATUREHIGHLEVEL && $cputemp !== NULL) {
2016-10-12 18:54:11 +02:00
?>
2017-01-10 15:04:51 +01:00
<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];
}
}
2016-10-12 18:54:11 +02:00
2017-01-10 15:04:51 +01:00
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);
2016-10-12 18:54:11 +02:00
2017-01-10 15:04:51 +01:00
var LR = '<DIV id='+id+' style="'+ST+'">CPU-Temperature is very high!<br><input type="button" value="Close" onclick="deleteLayer(\'LYR1\')"></DIV>';
2016-10-12 18:54:11 +02:00
2017-01-10 15:04:51 +01:00
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;
2016-10-12 18:54:11 +02:00
2017-01-10 15:04:51 +01:00
makeLayer('LYR1',x,y,200,100,'red',1,1);
</script>
2016-10-12 18:54:11 +02:00
<?php
2017-01-10 15:04:51 +01:00
}
2016-10-12 18:54:11 +02:00
2017-05-16 10:05:52 +02:00
$output = shell_exec('cat /proc/loadavg');
$loadavg = explode(" ", $output);
$sysload = $loadavg[0] . " / " . $loadavg[1] . " / " . $loadavg[2];
Showlaptime("sysload");
2017-05-16 10:05:52 +02:00
$stat1 = file('/proc/stat');
2017-01-10 15:04:51 +01:00
sleep(1);
2017-05-16 10:05:52 +02:00
$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();
2017-01-10 15:04:51 +01:00
foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 1);
2017-05-16 10:05:52 +02:00
$cpuusage = round($cpu['user'] + $cpu['sys'], 2);
2017-01-10 15:04:51 +01:00
showLapTime("cpuusage");
2016-10-26 09:46:15 +02:00
2017-05-16 10:05:52 +02:00
$output = shell_exec('grep -c processor /proc/cpuinfo');
2020-05-03 23:05:51 +02:00
$cpucores = intval($output);
2016-10-12 18:54:11 +02:00
2017-05-16 10:05:52 +02:00
$output = shell_exec('cat /proc/uptime');
$uptime = format_time(substr($output,0,strpos($output," ")));
2020-05-03 23:05:51 +02:00
$idletime = format_time(doubleval((substr($output,strpos($output," "))))/$cpucores);
2017-01-10 15:04:51 +01:00
showLapTime("idletime");
2016-10-26 09:46:15 +02:00
2017-01-10 15:04:51 +01:00
if (defined("SHOWPOWERSTATE")) {
$pinStatus = trim(shell_exec("gpio -g read ".POWERONLINEPIN)); // Pin 18
}
//returns 0 = low; 1 = high
2016-10-12 18:54:11 +02:00
?>
<tbody>
2017-01-10 15:04:51 +01:00
<tr>
<?php
if (defined("SHOWPOWERSTATE")) {
?>
<th><?php echo _("Power"); ?></th>
2017-01-10 15:04:51 +01:00
<?php
}
if ($cputemp !== NULL) {
?>
<th><?php echo _("CPU-Temperature"); ?></th>
2017-01-10 15:04:51 +01:00
<?php
}
if ($cpufreq !== NULL) {
?>
<th><?php echo _("CPU-Frequency");?></th>
2017-01-10 15:04:51 +01:00
<?php
}
?>
<th><?php echo _("System-Load"); ?></th>
<th><?php echo _("CPU-Usage"); ?></th>
<th><?php echo _("Uptime"); ?></th>
<th><?php echo _("Idle"); ?></th>
2017-01-10 15:04:51 +01:00
</tr>
<tr class="gatewayinfo">
<?php
if (defined("SHOWPOWERSTATE")) {
?>
<td><?php if ($pinStatus == POWERONLINESTATE ) {echo _("online");} else {echo _("on battery");} ?></td>
2017-01-10 15:04:51 +01:00
<?php
}
if ($cputemp !== NULL) {
?>
<td><?php echo $cputemp; ?> &deg;C</td>
<?php
}
if ($cpufreq !== NULL) {
?>
<td><?php echo $cpufreq; ?> MHz</td>
<?php
}
?>
<td><?php echo $sysload; ?></td>
2017-01-10 15:04:51 +01:00
<td>
2016-10-12 18:54:11 +02:00
<?php
2017-01-10 15:04:51 +01:00
if (defined("SHOWPROGRESSBARS")) {
2016-10-12 18:54:11 +02:00
?>
2017-01-10 15:04:51 +01:00
<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 intval($cpuusage); ?>%;"><?php echo $cpuusage; ?>%</div></div>
2016-10-12 18:54:11 +02:00
<?php
2017-01-10 15:04:51 +01:00
} else {
echo $cpuusage." %";
}
2016-10-12 18:54:11 +02:00
?>
2017-01-10 15:04:51 +01:00
</td>
<td><?php echo $uptime; ?></td>
<td><?php echo $idletime; ?></td>
</tr>
</tbody>
2016-10-12 18:54:11 +02:00
<?php
}
?>