added hotlinks to last heard

pull/14/head
Tom Early 6 years ago
parent f7a76dcd27
commit 6f148956f9

@ -19,11 +19,8 @@
#include <string> #include <string>
#include "QnetDB.h" #include "QnetDB.h"
bool CQnetDB::Open(const char *name, const bool enable) bool CQnetDB::Open(const char *name)
{ {
if (! enable)
return false;
if (sqlite3_open(name, &db)) if (sqlite3_open(name, &db))
return true; return true;

@ -24,7 +24,7 @@ class CQnetDB {
public: public:
CQnetDB() : db(NULL) {} CQnetDB() : db(NULL) {}
~CQnetDB() { if (db) sqlite3_close(db); } ~CQnetDB() { if (db) sqlite3_close(db); }
bool Open(const char *name, const bool disable = false); bool Open(const char *name);
bool Update(const char *mycall, const char *sfx, const char *urcall, const char *module, const char *gateway); bool Update(const char *mycall, const char *sfx, const char *urcall, const char *module, const char *gateway);
private: private:

@ -351,9 +351,8 @@ bool CQnetGateway::ReadConfig(char *cfgFile)
// dashboard // dashboard
path.assign("dashboard_"); path.assign("dashboard_");
cfg.GetValue(path+"enable_lastheard", estr, DASHBOARD_ENABLE_LASTHEARD); cfg.GetValue(path+"enable_lastheard", estr, DASH_SHOW_LH);
cfg.GetValue(path+"sql_filename", estr, DASHBOARD_SQL_NAME, 1, 32); cfg.GetValue(path+"sql_filename", estr, DASH_SQL_NAME, 1, 32);
cfg.GetValue(path+"refresh", estr, DASHBOARD_REFRESH, 10, 60);
return false; return false;
} }
@ -1121,7 +1120,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const i
printf("UnixSock=%s\n", link2gate.c_str()); printf("UnixSock=%s\n", link2gate.c_str());
} }
if (DASHBOARD_ENABLE_LASTHEARD) { if (DASH_SHOW_LH && memcmp(g2buf.hdr.sfx, "RPTR", 4)) {
std::string mycall((const char *)g2buf.hdr.mycall, 8); std::string mycall((const char *)g2buf.hdr.mycall, 8);
std::string sfx((const char *)g2buf.hdr.sfx, 4); std::string sfx((const char *)g2buf.hdr.sfx, 4);
std::string urcall((const char *)g2buf.hdr.urcall, 8); std::string urcall((const char *)g2buf.hdr.urcall, 8);
@ -2463,7 +2462,7 @@ bool CQnetGateway::Init(char *cfgfile)
} }
// open database // open database
if (qnDB.Open(DASHBOARD_SQL_NAME.c_str(), DASHBOARD_ENABLE_LASTHEARD)) if (DASH_SHOW_LH && qnDB.Open(DASH_SQL_NAME.c_str()))
return true; return true;
playNotInCache = false; playNotInCache = false;

@ -102,12 +102,13 @@ private:
std::string gate2link, link2gate, gate2modem[3], modem2gate; std::string gate2link, link2gate, gate2modem[3], modem2gate;
std::string OWNER, owner, FILE_STATUS, FILE_DTMF, FILE_ECHOTEST, IRCDDB_PASSWORD[2], FILE_QNVOICE_FILE, DASHBOARD_SQL_NAME; std::string OWNER, owner, FILE_STATUS, FILE_DTMF, FILE_ECHOTEST, IRCDDB_PASSWORD[2], FILE_QNVOICE_FILE, DASH_SQL_NAME;
bool GATEWAY_SEND_QRGS_MAP, GATEWAY_HEADER_REGEN, APRS_ENABLE, playNotInCache; bool GATEWAY_SEND_QRGS_MAP, GATEWAY_HEADER_REGEN, APRS_ENABLE, playNotInCache;
bool LOG_DEBUG, LOG_IRC, LOG_DTMF, LOG_QSO, DASHBOARD_ENABLE_LASTHEARD; bool LOG_DEBUG, LOG_IRC, LOG_DTMF, LOG_QSO;
bool DASH_SHOW_LH;
int DASHBOARD_REFRESH, TIMING_PLAY_WAIT, TIMING_PLAY_DELAY, TIMING_TIMEOUT_ECHO, TIMING_TIMEOUT_VOICEMAIL, TIMING_TIMEOUT_REMOTE_G2, TIMING_TIMEOUT_LOCAL_RPTR, dtmf_digit; int DASH_REFRESH, TIMING_PLAY_WAIT, TIMING_PLAY_DELAY, TIMING_TIMEOUT_ECHO, TIMING_TIMEOUT_VOICEMAIL, TIMING_TIMEOUT_REMOTE_G2, TIMING_TIMEOUT_LOCAL_RPTR, dtmf_digit;
unsigned int vPacketCount[3] = { 0, 0, 0 }; unsigned int vPacketCount[3] = { 0, 0, 0 };

@ -216,7 +216,11 @@ timing_play_delay_d=19 # milliseconds between frames playback, if echo so
# #
# Dashboard - for the php/sqlite webpage # Dashboard - for the php/sqlite webpage
# #
dashboard_enable_lastheard_d=true # set to false if you don't want a last heard section in the dashboard dash_sql_filename_d='/usr/local/etc/qn.db' # name for the sqlite database
dashboard_sql_filename_d='/usr/local/etc/qn.db' # name for the sqlite database dash_refresh_d=20 # seconds for the webpage to reload
dashboard_refresh_d=20 # seconds for the webpage to reload dash_lastheard_count_d=20 # maximum number of last heard entries to display
dashboard_lastheard_count_d=20 # maximum number of last heard entries to display dash_show_lh_d=true # set to false if for no Last Heard section
dash_show_ps_d=true # set to false if for no Processes section
dash_show_ip_d=true # set to false if for no IP Addresses section
dash_show_mo_d=true # set to false if for no Modules section
dash_show_ur_d=true # set to false if for Send URCall section

@ -6,122 +6,134 @@
</head> </head>
<body> <body>
<?php <?php
$cfg = array(); $cfg = array();
$defaults = array(); $defaults = array();
$fmodule = $furcall = ''; $fmodule = $furcall = '';
$cfgdir = '/usr/local/etc'; $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)) { if ($lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) {
foreach ($lines as $line) { foreach ($lines as $line) {
$line = trim($line); $line = trim($line);
if ($line[0] == '#') continue; if ($line[0] == '#') continue;
if (! strpos($line, '=')) continue; if (! strpos($line, '=')) continue;
list( $key, $value ) = explode('=', $line); list( $key, $value ) = explode('=', $line);
if ("'" == $value[0]) if ("'" == $value[0])
list ( $value ) = explode("'", substr($value, 1)); list ( $value ) = explode("'", substr($value, 1));
else else
list ( $value ) = explode(' ', $value); list ( $value ) = explode(' ', $value);
$value = trim($value); $value = trim($value);
$kvarray[$key] = $value; $kvarray[$key] = $value;
}
} }
} }
}
function GetCFGValue(string $key) function GetCFGValue(string $key)
{ {
global $cfg, $defaults; global $cfg, $defaults;
if (array_key_exists($key, $cfg)) if (array_key_exists($key, $cfg))
return $cfg[$key]; return $cfg[$key];
if ('module_' == substr($key, 0, 7)) { if ('module_' == substr($key, 0, 7)) {
$mod = substr($key, 0, 8); $mod = substr($key, 0, 8);
if (array_key_exists($mod, $cfg)) { if (array_key_exists($mod, $cfg)) {
$key = $cfg[$mod].substr($key, 8); $key = $cfg[$mod].substr($key, 8);
if (array_key_exists($key, $defaults)) if (array_key_exists($key, $defaults))
return $defaults[$key]; return $defaults[$key];
}
} else {
if (array_key_exists($key.'_d', $defaults))
return $defaults[$key.'_d'];
} }
return ''; } else {
if (array_key_exists($key.'_d', $defaults))
return $defaults[$key.'_d'];
} }
return '';
}
function GetIP(string $type) function GetIP(string $type)
{ {
if ('internal' == $type) { if ('internal' == $type) {
$iplist = explode(' ', `hostname -I`); $iplist = explode(' ', `hostname -I`);
foreach ($iplist as $ip) { foreach ($iplist as $ip) {
if (strpos($ip, '.')) break; if (strpos($ip, '.')) break;
} }
} else if ('ipv6' == $type) } else if ('ipv6' == $type)
$ip = trim(`curl --silent -6 icanhazip.com`); $ip = trim(`curl --silent -6 icanhazip.com`);
else if ('ipv4' == $type) else if ('ipv4' == $type)
$ip = trim(`curl --silent -4 icanhazip.com`); $ip = trim(`curl --silent -4 icanhazip.com`);
else else
$ip = ''; $ip = '';
return $ip; return $ip;
} }
function GetStatus(string $mod, array &$kv) function GetStatus(string $mod, array &$kv)
{ {
$mod = strtoupper(substr($mod, 0, 1)); $mod = strtoupper(substr($mod, 0, 1));
if (array_key_exists('file_status', $kv)) if (array_key_exists('file_status', $kv))
$file = $kv['file_status']; $file = $kv['file_status'];
else else
$file = '/usr/local/etc/rptr_status'; $file = '/usr/local/etc/rptr_status';
if ($lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) { if ($lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) {
foreach ($lines as $line) { foreach ($lines as $line) {
$words = explode(',', $line); $words = explode(',', $line);
if ($words[0] == $mod) if ($words[0] == $mod)
return $words; return $words;
}
} }
return explode(',', ',,,,,');
} }
function SecToString(int $sec) { return explode(',', ',,,,,');
if ($sec >= 86400) }
return sprintf("%0.2f days", $sec/86400);
$hrs = intdiv($sec, 3600); function SecToString(int $sec) {
$sec %= 3600; if ($sec >= 86400)
$min = intdiv($sec, 60); return sprintf("%0.2f days", $sec/86400);
$sec %= 60; $hrs = intdiv($sec, 3600);
if ($hrs) return sprintf("%2d hr %2d min %2d sec", $hrs, $min, $sec); $sec %= 3600;
if ($min) return sprintf("%2d min %2d sec", $min, $sec); $min = intdiv($sec, 60);
return sprintf("%2d sec", $sec); $sec %= 60;
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 LastHeardPage() function MyAndSfxToQrz(string $my, string $sfx)
{ {
echo 'Last Heard:<br><code>', "\n"; $my = trim($my);
$rstr = 'MyCall/Sfx URCall Module Gateway Last Time<br>'; $sfx = trim($sfx);
echo str_replace(' ', '&nbsp;', $rstr), "\n"; if (0 == strlen($my)) {
echo '</code><br>', "\n"; $my = 'Empty MYCall ';
$dbname = GetCFGValue('dashboard_sql_filename'); } else {
$db = new SQLite3($dbname, SQLITE3_OPEN_READONLY); if (strpos($my, ' '))
$ss = 'SELECT mycall,sfx,urcall,module,gateway,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 6 LIMIT '.GetCFGValue('dashboard_lastheard_count').' '; $link = strstr($my, ' ', true);
if ($stmnt = $db->prepare($ss)) { else
if ($result = $stmnt->execute()) { $link = $my;
while ($row = $result->FetchArray(SQLITE3_NUM)) { if (strlen($sfx))
$cs = str_pad(trim($row[0]).'/'.trim($row[1]), 13); $my .= '/'.$sfx;
$rstr = $cs.' '.$row[2].' '.$row[3].' '.$row[4].' '.SecToString(intval($row[5])).'<br>'; $len = strlen($my);
echo str_replace(' ', '&nbsp;', $rstr), "\n"; $my = '<a*href*target="_blank"*href="https://www.qrz.com/db/'.$link.'>'.$my.'</a>';
} while ($len < 13) {
$result->finalize(); $my .= ' ';
} $len += 1;
$stmnt->close();
} }
$db->Close();
echo '</code><br>', "\n";
} }
return $my;
}
ParseKVFile($cfgdir.'/qn.cfg', $cfg); ParseKVFile($cfgdir.'/qn.cfg', $cfg);
ParseKVFile($cfgdir.'/defaults', $defaults); ParseKVFile($cfgdir.'/defaults', $defaults);
?> ?>
<h2>QnetGateway <?php echo GetCFGValue('ircddb_login'); ?> Dashboard</h2> <h2>QnetGateway <?php echo GetCFGValue('ircddb_login'); ?> Dashboard</h2>
<?php <?php
if (`ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) { if ('true' == GetCFGValue('dash_show_ps') && `ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) {
echo 'Processes:<br><code>', "\n"; echo 'Processes:<br><code>', "\n";
echo str_replace(' ', '&nbsp;', 'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND<br>'), "\n"; echo str_replace(' ', '&nbsp;', '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`); $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`);
@ -131,40 +143,63 @@ if (`ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) {
echo '</code>', "\n"; echo '</code>', "\n";
} }
if ('true' == GetCFGValue('dashboard_enable_lastheard')) if ('true' == GetCFGValue('dash_show_lh')) {
LastHeardPage(); echo 'Last Heard:<br><code>', "\n";
?> $rstr = 'MyCall/Sfx URCall Module Gateway Last Time<br>';
IP Addresses:<br> echo str_replace(' ', '&nbsp;', $rstr), "\n";
<table cellpadding='1' border='1' style='font-family: monospace'> echo '</code><br>', "\n";
<tr><td style="text-align:center">Internal</td><td style="text-align:center">IPV4</td><td style="text-align:center">IPV6</td></tr> $dbname = GetCFGValue('dash_sql_filename');
<tr><td><?php echo GetIP('internal');?></td><td><?php echo GetIP('ipv4');?></td><td><?php echo GetIP('ipv6');?></td></tr> $db = new SQLite3($dbname, SQLITE3_OPEN_READONLY);
</table><br> $ss = 'SELECT mycall,sfx,urcall,module,gateway,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 6 LIMIT '.GetCFGValue('dash_lastheard_count').' ';
Modules:<br> if ($stmnt = $db->prepare($ss)) {
<table cellpadding='1' border='1' style='font-family: monospace'> if ($result = $stmnt->execute()) {
<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> while ($row = $result->FetchArray(SQLITE3_NUM)) {
<?php $rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$row[2].' '.RptrToAprs($row[3]).' '.$row[4].' '.SecToString(intval($row[5])).'<br>';
foreach (array('a', 'b', 'c') as $mod) { echo str_replace(str_replace(' ', '&nbsp;', $rstr), '*', ' '), "\n";
$module = 'module_'.$mod; }
if (array_key_exists($module, $cfg)) { $result->finalize();
$configured[] = strtoupper($mod); }
$freq = 0.0; $stmnt->close();
if (array_key_exists($module.'_tx_frequency', $cfg))
$freq = $cfg[$module.'_tx_frequency'];
else if (array_key_exists($module.'_frequency', $cfg))
$freq = $cfg[$module.'_frequency'];
$stat = GetStatus($mod, $cfg);
if (8==strlen($stat[1]) && 1==strlen($stat[2]))
$linkstatus = substr($stat[1], 0, 7).$stat[2];
else
$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";
} }
$db->Close();
echo '</code><br>', "\n";
} }
?>
</table><br> if ('true' == GetCFGValue('dash_show_ip')) {
Send URCall:<br> echo 'IP Addresses:<br>', "\n";
<form method="post"> echo '<table cellpadding="1" border="1" style="font-family: monospace">', "\n";
<?php 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('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);
$freq = 0.0;
if (array_key_exists($module.'_tx_frequency', $cfg))
$freq = $cfg[$module.'_tx_frequency'];
else if (array_key_exists($module.'_frequency', $cfg))
$freq = $cfg[$module.'_frequency'];
$stat = GetStatus($mod, $cfg);
if (8==strlen($stat[1]) && 1==strlen($stat[2]))
$linkstatus = substr($stat[1], 0, 7).$stat[2];
else
$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";
}
if ('true' == GetCFGValue('dash_show_ur')) {
echo 'Send URCall:<br>', "\n";
echo '<form method="post">', "\n";
if (count($configured) > 1) { if (count($configured) > 1) {
echo 'Module: ', "\n"; echo 'Module: ', "\n";
foreach ($configured as $mod) { foreach ($configured as $mod) {
@ -172,12 +207,9 @@ Send URCall:<br>
} }
} else } else
$fmodule = $configured[0]; $fmodule = $configured[0];
?> echo 'URCall: <input type="text" name="furcall" value="', $furcall, '">', "\n";
URCall: <input type="text" name='furcall' value="<?php echo $furcall;?>"> echo '<input type="submit" name="sendurcall" value="Send URCall"><br>', "\n";
<input type="submit" name="sendurcall" value="Send URCall"><br> echo '</form>', "\n";
</form>
<?php
if (isset($_POST['sendurcall'])) { if (isset($_POST['sendurcall'])) {
$furcall = $_POST['furcall']; $furcall = $_POST['furcall'];
@ -188,14 +220,17 @@ URCall: <input type="text" name='furcall' value="<?php echo $furcall;?>">
} else { } else {
$fmodule = $_POST['fmodule']; $fmodule = $_POST['fmodule'];
} }
} }
$furcall = str_replace(' ', '_', trim(preg_replace('/[^0-9a-z ]/', '', strtolower($furcall)))); $furcall = str_replace(' ', '_', trim(preg_replace('/[^0-9a-z ]/', '', strtolower($furcall))));
if (strlen($furcall)>0 && strlen($fmodule)>0) { if (strlen($furcall)>0 && strlen($fmodule)>0) {
$command = 'qnremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall; $command = 'qnremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall;
echo $command, "<br>\n"; echo $command, "<br>\n";
$unused = `$command`; $unused = `$command`;
} }
}
?> ?>
<br>
<p align="right">QnetGateway Dashboard Version 2.0 Copyright (&copy;) by Thomas A. Early, N7TAE.</p>
</body> </body>
</html> </html>

Loading…
Cancel
Save

Powered by TurnKey Linux.