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,13 +6,13 @@
</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);
@ -27,10 +27,10 @@
$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];
@ -46,10 +46,10 @@
return $defaults[$key.'_d']; return $defaults[$key.'_d'];
} }
return ''; 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) {
@ -62,10 +62,10 @@
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'];
@ -79,8 +79,9 @@
} }
} }
return explode(',', ',,,,,'); return explode(',', ',,,,,');
} }
function SecToString(int $sec) {
function SecToString(int $sec) {
if ($sec >= 86400) if ($sec >= 86400)
return sprintf("%0.2f days", $sec/86400); return sprintf("%0.2f days", $sec/86400);
$hrs = intdiv($sec, 3600); $hrs = intdiv($sec, 3600);
@ -90,23 +91,71 @@
if ($hrs) return sprintf("%2d hr %2d min %2d sec", $hrs, $min, $sec); if ($hrs) return sprintf("%2d hr %2d min %2d sec", $hrs, $min, $sec);
if ($min) return sprintf("%2d min %2d sec", $min, $sec); if ($min) return sprintf("%2d min %2d sec", $min, $sec);
return sprintf("%2d sec", $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(' ', '&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`);
foreach ($lines as $line) {
echo str_replace(' ', '&nbsp;', $line), "<br>\n";
} }
echo '</code>', "\n";
}
function LastHeardPage() if ('true' == GetCFGValue('dash_show_lh')) {
{
echo 'Last Heard:<br><code>', "\n"; echo 'Last Heard:<br><code>', "\n";
$rstr = 'MyCall/Sfx URCall Module Gateway Last Time<br>'; $rstr = 'MyCall/Sfx URCall Module Gateway Last Time<br>';
echo str_replace(' ', '&nbsp;', $rstr), "\n"; echo str_replace(' ', '&nbsp;', $rstr), "\n";
echo '</code><br>', "\n"; echo '</code><br>', "\n";
$dbname = GetCFGValue('dashboard_sql_filename'); $dbname = GetCFGValue('dash_sql_filename');
$db = new SQLite3($dbname, SQLITE3_OPEN_READONLY); $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 ($stmnt = $db->prepare($ss)) {
if ($result = $stmnt->execute()) { if ($result = $stmnt->execute()) {
while ($row = $result->FetchArray(SQLITE3_NUM)) { while ($row = $result->FetchArray(SQLITE3_NUM)) {
$cs = str_pad(trim($row[0]).'/'.trim($row[1]), 13); $rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$row[2].' '.RptrToAprs($row[3]).' '.$row[4].' '.SecToString(intval($row[5])).'<br>';
$rstr = $cs.' '.$row[2].' '.$row[3].' '.$row[4].' '.SecToString(intval($row[5])).'<br>'; echo str_replace(str_replace(' ', '&nbsp;', $rstr), '*', ' '), "\n";
echo str_replace(' ', '&nbsp;', $rstr), "\n";
} }
$result->finalize(); $result->finalize();
} }
@ -114,36 +163,21 @@
} }
$db->Close(); $db->Close();
echo '</code><br>', "\n"; echo '</code><br>', "\n";
} }
ParseKVFile($cfgdir.'/qn.cfg', $cfg); if ('true' == GetCFGValue('dash_show_ip')) {
ParseKVFile($cfgdir.'/defaults', $defaults); echo 'IP Addresses:<br>', "\n";
?> echo '<table cellpadding="1" border="1" style="font-family: monospace">', "\n";
<h2>QnetGateway <?php echo GetCFGValue('ircddb_login'); ?> Dashboard</h2> 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";
<?php echo '<tr><td>', GetIP('internal'), '</td><td>', GetIP('ipv4'), '</td><td>', GetIP('ipv6'), '</td></tr>', "\n";
if (`ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) { echo '</table><br>', "\n";
echo 'Processes:<br><code>', "\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`);
foreach ($lines as $line) {
echo str_replace(' ', '&nbsp;', $line), "<br>\n";
}
echo '</code>', "\n";
} }
if ('true' == GetCFGValue('dashboard_enable_lastheard')) if ('true' == GetCFGValue('dash_show_mo')) {
LastHeardPage(); echo 'Modules:<br>', "\n";
?> echo "<table cellpadding='1' border='1' style='font-family: monospace'>\n";
IP Addresses:<br> 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";
<table cellpadding='1' border='1' style='font-family: monospace'> foreach (array('a', 'b', 'c') as $mod) {
<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) {
$module = 'module_'.$mod; $module = 'module_'.$mod;
if (array_key_exists($module, $cfg)) { if (array_key_exists($module, $cfg)) {
$configured[] = strtoupper($mod); $configured[] = strtoupper($mod);
@ -159,12 +193,13 @@ foreach (array('a', 'b', 'c') as $mod) {
$linkstatus = 'Unlinked'; $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 '<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> if ('true' == GetCFGValue('dash_show_ur')) {
Send URCall:<br> echo 'Send URCall:<br>', "\n";
<form method="post"> echo '<form method="post">', "\n";
<?php
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'];
@ -196,6 +228,9 @@ URCall: <input type="text" name='furcall' value="<?php echo $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.