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

@ -80,6 +80,7 @@
} }
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);
@ -92,36 +93,47 @@
return sprintf("%2d sec", $sec); return sprintf("%2d sec", $sec);
} }
function LastHeardPage() function RptrToAprs(string $rptr)
{ {
echo 'Last Heard:<br><code>', "\n"; if (8==strlen($rptr) && 8==strlen(trim($rptr)) && strpos($rptr, ' ')) {
$rstr = 'MyCall/Sfx URCall Module Gateway Last Time<br>'; $link = strstr($rptr, ' ', true).'-'.$rptr[7];
echo str_replace(' ', '&nbsp;', $rstr), "\n"; return '<a*href*target="_blank"*href="https://aprs.fi/'.$link.'>'.$rptr.'</a>';
echo '</code><br>', "\n";
$dbname = GetCFGValue('dashboard_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').' ';
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(' ', '&nbsp;', $rstr), "\n";
} }
$result->finalize(); return $rptr;
} }
$stmnt->close();
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;
} }
$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,18 +143,40 @@ 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>';
echo str_replace(str_replace(' ', '&nbsp;', $rstr), '*', ' '), "\n";
}
$result->finalize();
}
$stmnt->close();
}
$db->Close();
echo '</code><br>', "\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('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) { 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)) {
@ -160,11 +194,12 @@ foreach (array('a', 'b', 'c') as $mod) {
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> }
Send URCall:<br>
<form method="post"> if ('true' == GetCFGValue('dash_show_ur')) {
<?php 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'];
@ -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.