diff --git a/QnetDB.cpp b/QnetDB.cpp index bc16880..a0d3251 100644 --- a/QnetDB.cpp +++ b/QnetDB.cpp @@ -19,11 +19,8 @@ #include #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)) return true; diff --git a/QnetDB.h b/QnetDB.h index b24ba92..76ebe11 100644 --- a/QnetDB.h +++ b/QnetDB.h @@ -24,7 +24,7 @@ class CQnetDB { public: CQnetDB() : db(NULL) {} ~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); private: diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 95237a8..820b68f 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -351,9 +351,8 @@ bool CQnetGateway::ReadConfig(char *cfgFile) // dashboard path.assign("dashboard_"); - cfg.GetValue(path+"enable_lastheard", estr, DASHBOARD_ENABLE_LASTHEARD); - cfg.GetValue(path+"sql_filename", estr, DASHBOARD_SQL_NAME, 1, 32); - cfg.GetValue(path+"refresh", estr, DASHBOARD_REFRESH, 10, 60); + cfg.GetValue(path+"enable_lastheard", estr, DASH_SHOW_LH); + cfg.GetValue(path+"sql_filename", estr, DASH_SQL_NAME, 1, 32); 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()); } - 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 sfx((const char *)g2buf.hdr.sfx, 4); std::string urcall((const char *)g2buf.hdr.urcall, 8); @@ -2463,7 +2462,7 @@ bool CQnetGateway::Init(char *cfgfile) } // 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; playNotInCache = false; diff --git a/QnetGateway.h b/QnetGateway.h index b1f227c..8154ae9 100644 --- a/QnetGateway.h +++ b/QnetGateway.h @@ -102,12 +102,13 @@ private: 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 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 }; diff --git a/defaults b/defaults index 0cdb6ff..b211686 100644 --- a/defaults +++ b/defaults @@ -216,7 +216,11 @@ timing_play_delay_d=19 # milliseconds between frames playback, if echo so # # 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 -dashboard_sql_filename_d='/usr/local/etc/qn.db' # name for the sqlite database -dashboard_refresh_d=20 # seconds for the webpage to reload -dashboard_lastheard_count_d=20 # maximum number of last heard entries to display +dash_sql_filename_d='/usr/local/etc/qn.db' # name for the sqlite database +dash_refresh_d=20 # seconds for the webpage to reload +dash_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 diff --git a/example.php b/example.php index 1bf88fe..6d53b0f 100644 --- a/example.php +++ b/example.php @@ -6,122 +6,134 @@ = 86400) - return sprintf("%0.2f days", $sec/86400); - $hrs = intdiv($sec, 3600); - $sec %= 3600; - $min = intdiv($sec, 60); - $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); + return explode(',', ',,,,,'); +} + +function SecToString(int $sec) { + if ($sec >= 86400) + return sprintf("%0.2f days", $sec/86400); + $hrs = intdiv($sec, 3600); + $sec %= 3600; + $min = intdiv($sec, 60); + $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 ''.$rptr.''; + } + return $rptr; +} - function LastHeardPage() - { - echo 'Last Heard:
', "\n"; - $rstr = 'MyCall/Sfx URCall Module Gateway Last Time
'; - echo str_replace(' ', ' ', $rstr), "\n"; - echo '

', "\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])).'
'; - echo str_replace(' ', ' ', $rstr), "\n"; - } - $result->finalize(); - } - $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 = ''.$my.''; + while ($len < 13) { + $my .= ' '; + $len += 1; } - $db->Close(); - echo '
', "\n"; } + return $my; +} - ParseKVFile($cfgdir.'/qn.cfg', $cfg); - ParseKVFile($cfgdir.'/defaults', $defaults); +ParseKVFile($cfgdir.'/qn.cfg', $cfg); +ParseKVFile($cfgdir.'/defaults', $defaults); ?> +

QnetGateway Dashboard

+ 2) { +if ('true' == GetCFGValue('dash_show_ps') && `ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) { echo 'Processes:
', "\n"; echo str_replace(' ', ' ', 'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
'), "\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`); @@ -131,40 +143,63 @@ if (`ps -aux | grep -e qn -e MMDVMHost | wc -l` > 2) { echo '
', "\n"; } -if ('true' == GetCFGValue('dashboard_enable_lastheard')) - LastHeardPage(); -?> -IP Addresses:
- - - -
InternalIPV4IPV6

-Modules:
- - -',"\n"; +if ('true' == GetCFGValue('dash_show_lh')) { + echo 'Last Heard:
', "\n"; + $rstr = 'MyCall/Sfx URCall Module Gateway Last Time
'; + echo str_replace(' ', ' ', $rstr), "\n"; + echo '

', "\n"; + $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('dash_lastheard_count').' '; + if ($stmnt = $db->prepare($ss)) { + if ($result = $stmnt->execute()) { + while ($row = $result->FetchArray(SQLITE3_NUM)) { + $rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$row[2].' '.RptrToAprs($row[3]).' '.$row[4].' '.SecToString(intval($row[5])).'
'; + echo str_replace(str_replace(' ', ' ', $rstr), '*', ' '), "\n"; + } + $result->finalize(); + } + $stmnt->close(); } + $db->Close(); + echo '
', "\n"; } -?> -
ModuleModemFrequencyRepeaterRepeater IP
',strtoupper($mod),'',$cfg[$module],'',$freq,'',$linkstatus,'',$stat[3],'

-Send URCall:
-
-', "\n"; + echo '', "\n"; + echo '', "\n"; + echo '', "\n"; + echo '
InternalIPV4IPV6
', GetIP('internal'), '', GetIP('ipv4'), '', GetIP('ipv6'), '

', "\n"; +} + +if ('true' == GetCFGValue('dash_show_mo')) { + echo 'Modules:
', "\n"; + echo "\n"; + echo '', "\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 '',"\n"; + } + } + echo '
ModuleModemFrequencyRepeaterRepeater IP
',strtoupper($mod),'',$cfg[$module],'',$freq,'',$linkstatus,'',$stat[3],'

', "\n"; +} + +if ('true' == GetCFGValue('dash_show_ur')) { + echo 'Send URCall:
', "\n"; + echo '', "\n"; if (count($configured) > 1) { echo 'Module: ', "\n"; foreach ($configured as $mod) { @@ -172,12 +207,9 @@ Send URCall:
} } else $fmodule = $configured[0]; -?> -URCall: -
-
- -', "\n"; + echo '
', "\n"; + echo '', "\n"; if (isset($_POST['sendurcall'])) { $furcall = $_POST['furcall']; @@ -188,14 +220,17 @@ URCall: } else { $fmodule = $_POST['fmodule']; } - } - $furcall = str_replace(' ', '_', trim(preg_replace('/[^0-9a-z ]/', '', strtolower($furcall)))); - - if (strlen($furcall)>0 && strlen($fmodule)>0) { - $command = 'qnremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall; - echo $command, "
\n"; - $unused = `$command`; - } + } + $furcall = str_replace(' ', '_', trim(preg_replace('/[^0-9a-z ]/', '', strtolower($furcall)))); + + if (strlen($furcall)>0 && strlen($fmodule)>0) { + $command = 'qnremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall; + echo $command, "
\n"; + $unused = `$command`; + } +} ?> +
+

QnetGateway Dashboard Version 2.0 Copyright (©) by Thomas A. Early, N7TAE.