@ -6,13 +6,13 @@
< / head >
< body >
<?php
$cfg = array();
$defaults = array();
$fmodule = $furcall = '';
$cfgdir = '/usr/local/etc';
$cfg = array();
$defaults = array();
$fmodule = $furcall = '';
$cfgdir = '/usr/local/etc';
function ParseKVFile(string $filename, & $kvarray)
{
function ParseKVFile(string $filename, & $kvarray)
{
if ($lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) {
foreach ($lines as $line) {
$line = trim($line);
@ -27,10 +27,10 @@
$kvarray[$key] = $value;
}
}
}
}
function GetCFGValue(string $key)
{
function GetCFGValue(string $key)
{
global $cfg, $defaults;
if (array_key_exists($key, $cfg))
return $cfg[$key];
@ -46,10 +46,10 @@
return $defaults[$key.'_d'];
}
return '';
}
}
function GetIP(string $type)
{
function GetIP(string $type)
{
if ('internal' == $type) {
$iplist = explode(' ', `hostname -I`);
foreach ($iplist as $ip) {
@ -62,10 +62,10 @@
else
$ip = '';
return $ip;
}
}
function GetStatus(string $mod, array & $kv)
{
function GetStatus(string $mod, array & $kv)
{
$mod = strtoupper(substr($mod, 0, 1));
if (array_key_exists('file_status', $kv))
$file = $kv['file_status'];
@ -79,8 +79,9 @@
}
}
return explode(',', ',,,,,');
}
function SecToString(int $sec) {
}
function SecToString(int $sec) {
if ($sec >= 86400)
return sprintf("%0.2f days", $sec/86400);
$hrs = intdiv($sec, 3600);
@ -90,23 +91,71 @@
if ($hrs) return sprintf("%2d hr %2d min %2d sec", $hrs, $min, $sec);
if ($min) return sprintf("%2d min %2d sec", $min, $sec);
return sprintf("%2d sec", $sec);
}
function RptrToAprs(string $rptr)
{
if (8==strlen($rptr) & & 8==strlen(trim($rptr)) & & strpos($rptr, ' ')) {
$link = strstr($rptr, ' ', true).'-'.$rptr[7];
return '< a * href * target = "_blank" * href = "https://aprs.fi/'.$link.' > '.$rptr.'< / a > ';
}
return $rptr;
}
function MyAndSfxToQrz(string $my, string $sfx)
{
$my = trim($my);
$sfx = trim($sfx);
if (0 == strlen($my)) {
$my = 'Empty MYCall ';
} else {
if (strpos($my, ' '))
$link = strstr($my, ' ', true);
else
$link = $my;
if (strlen($sfx))
$my .= '/'.$sfx;
$len = strlen($my);
$my = '< a * href * target = "_blank" * href = "https://www.qrz.com/db/'.$link.' > '.$my.'< / a > ';
while ($len < 13 ) {
$my .= ' ';
$len += 1;
}
}
return $my;
}
ParseKVFile($cfgdir.'/qn.cfg', $cfg);
ParseKVFile($cfgdir.'/defaults', $defaults);
?>
< h2 > QnetGateway <?php echo GetCFGValue ( 'ircddb_login' ); ?> Dashboard</ h2 >
<?php
if ('true' == GetCFGValue('dash_show_ps') & & `ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) {
echo 'Processes:< br > < code > ', "\n";
echo str_replace(' ', ' ', 'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND< br > '), "\n";
$lines = explode("\n", `ps -aux | grep -e qngateway -e qnlink -e qndtmf -e qndvap -e qnitap -e qnrelay -e qndvrptr -e qnmodem -e MMDVMHost | grep -v grep`);
foreach ($lines as $line) {
echo str_replace(' ', ' ', $line), "< br > \n";
}
echo '< / code > ', "\n";
}
function LastHeardPage()
{
if ('true' == GetCFGValue('dash_show_lh')) {
echo 'Last Heard:< br > < code > ', "\n";
$rstr = 'MyCall/Sfx URCall Module Gateway Last Time< br > ';
echo str_replace(' ', ' ', $rstr), "\n";
echo '< / code > < br > ', "\n";
$dbname = GetCFGValue('dashboard_sql_filename');
$dbname = GetCFGValue('dash_sql_filename');
$db = new SQLite3($dbname, SQLITE3_OPEN_READONLY);
$ss = 'SELECT mycall,sfx,urcall,module,gateway,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 6 LIMIT '.GetCFGValue('dashboard_lastheard_count').' ';
$ss = 'SELECT mycall,sfx,urcall,module,gateway,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 6 LIMIT '.GetCFGValue('dash_lastheard_count').' ';
if ($stmnt = $db->prepare($ss)) {
if ($result = $stmnt->execute()) {
while ($row = $result->FetchArray(SQLITE3_NUM)) {
$cs = str_pad(trim($row[0]).'/'.trim($row[1]), 13);
$rstr = $cs.' '.$row[2].' '.$row[3].' '.$row[4].' '.SecToString(intval($row[5])).'< br > ';
echo str_replace(' ', ' ', $rstr), "\n";
$rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$row[2].' '.RptrToAprs($row[3]).' '.$row[4].' '.SecToString(intval($row[5])).'< br > ';
echo str_replace(str_replace(' ', ' ', $rstr), '*', ' '), "\n";
}
$result->finalize();
}
@ -114,36 +163,21 @@
}
$db->Close();
echo '< / code > < br > ', "\n";
}
}
ParseKVFile($cfgdir.'/qn.cfg', $cfg);
ParseKVFile($cfgdir.'/defaults', $defaults);
?>
< h2 > QnetGateway <?php echo GetCFGValue ( 'ircddb_login' ); ?> Dashboard</ h2 >
<?php
if (`ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) {
echo 'Processes:< br > < code > ', "\n";
echo str_replace(' ', ' ', 'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND< br > '), "\n";
$lines = explode("\n", `ps -aux | grep -e qngateway -e qnlink -e qndtmf -e qndvap -e qnitap -e qnrelay -e qndvrptr -e qnmodem -e MMDVMHost | grep -v grep`);
foreach ($lines as $line) {
echo str_replace(' ', ' ', $line), "< br > \n";
}
echo '< / code > ', "\n";
if ('true' == GetCFGValue('dash_show_ip')) {
echo 'IP Addresses:< br > ', "\n";
echo '< table cellpadding = "1" border = "1" style = "font-family: monospace" > ', "\n";
echo '< tr > < td style = "text-align:center" > Internal< / td > < td style = "text-align:center" > IPV4< / td > < td style = "text-align:center" > IPV6< / td > < / tr > ', "\n";
echo '< tr > < td > ', GetIP('internal'), '< / td > < td > ', GetIP('ipv4'), '< / td > < td > ', GetIP('ipv6'), '< / td > < / tr > ', "\n";
echo '< / table > < br > ', "\n";
}
if ('true' == GetCFGValue('dashboard_enable_lastheard'))
LastHeardPage();
?>
IP Addresses:< br >
< table cellpadding = '1' border = '1' style = 'font-family: monospace' >
< tr > < td style = "text-align:center" > Internal< / td > < td style = "text-align:center" > IPV4< / td > < td style = "text-align:center" > IPV6< / td > < / tr >
< tr >< td > <?php echo GetIP ( 'internal' ); ?> </ td >< td > <?php echo GetIP ( 'ipv4' ); ?> </ td >< td > <?php echo GetIP ( 'ipv6' ); ?> </ td ></ tr >
< / table > < br >
Modules:< br >
< table cellpadding = '1' border = '1' style = 'font-family: monospace' >
< tr > < td style = "text-align:center" > Module< / td > < td style = "text-align:center" > Modem< / td > < td style = "text-align:center" > Frequency< / td > < td style = "text-align:center" > Repeater< / td > < td style = "text-align:center" > Repeater IP< / td > < / tr >
<?php
foreach (array('a', 'b', 'c') as $mod) {
if ('true' == GetCFGValue('dash_show_mo')) {
echo 'Modules:< br > ', "\n";
echo "< table cellpadding = '1' border = '1' style = 'font-family: monospace' > \n";
echo '< tr > < td style = "text-align:center" > Module< / td > < td style = "text-align:center" > Modem< / td > < td style = "text-align:center" > Frequency< / td > < td style = "text-align:center" > Repeater< / td > < td style = "text-align:center" > Repeater IP< / td > < / tr > ', "\n";
foreach (array('a', 'b', 'c') as $mod) {
$module = 'module_'.$mod;
if (array_key_exists($module, $cfg)) {
$configured[] = strtoupper($mod);
@ -159,12 +193,13 @@ foreach (array('a', 'b', 'c') as $mod) {
$linkstatus = 'Unlinked';
echo '< tr > < td style = "text-align:center" > ',strtoupper($mod),'< / td > < td style = "text-align:center" > ',$cfg[$module],'< / td > < td style = "text-align:center" > ',$freq,'< / td > < td style = "text-align:center" > ',$linkstatus,'< / td > < td style = "text-align:center" > ',$stat[3],'< / td > < / tr > ',"\n";
}
}
echo '< / table > < br > ', "\n";
}
?>
< / table > < br >
Send URCall:< br >
< form method = "post" >
<?php
if ('true' == GetCFGValue('dash_show_ur')) {
echo 'Send URCall:< br > ', "\n";
echo '< form method = "post" > ', "\n";
if (count($configured) > 1) {
echo 'Module: ', "\n";
foreach ($configured as $mod) {
@ -172,12 +207,9 @@ Send URCall:<br>
}
} else
$fmodule = $configured[0];
?>
URCall: < input type = "text" name = 'furcall' value = " <?php echo $furcall ; ?> " >
< input type = "submit" name = "sendurcall" value = "Send URCall" > < br >
< / form >
<?php
echo 'URCall: < input type = "text" name = "furcall" value = "', $furcall, '" > ', "\n";
echo '< input type = "submit" name = "sendurcall" value = "Send URCall" > < br > ', "\n";
echo '< / form > ', "\n";
if (isset($_POST['sendurcall'])) {
$furcall = $_POST['furcall'];
@ -196,6 +228,9 @@ URCall: <input type="text" name='furcall' value="<?php echo $furcall;?>">
echo $command, "< br > \n";
$unused = `$command`;
}
}
?>
< br >
< p align = "right" > QnetGateway Dashboard Version 2.0 Copyright (© ) by Thomas A. Early, N7TAE.< / p >
< / body >
< / html >