Skip to content

Commit

Permalink
Dashboard order
Browse files Browse the repository at this point in the history
  • Loading branch information
n7tae committed Mar 26, 2020
1 parent 9a4e645 commit c49692f
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 147 deletions.
2 changes: 1 addition & 1 deletion DASHBOARD.README
@@ -1,7 +1,7 @@
##### DASHBOARD.README #####

A web-based dashboard can be enabled. The dashboard has several sections
that you can disable if you want. You can also control the refresh rate and
that you can display in any order. You can also control the refresh rate and
how many rows you want in the Last Heard section. You can configure these
features with the ./qnconfig menu. Don't set the refresh time faster than about
10 seconds. If you do, it will become difficult to use the Send URCall button.
Expand Down
7 changes: 4 additions & 3 deletions QnetGateway.cpp
Expand Up @@ -345,7 +345,8 @@ bool CQnetGateway::ReadConfig(char *cfgFile)

// dashboard
path.assign("dash_");
cfg.GetValue(path+"show_lh", estr, DASH_SHOW_LH);
cfg.GetValue(path+"show_order", estr, DASH_SHOW_ORDER, 2, 17);
showLastHeard = (std::string::npos == DASH_SHOW_ORDER.find("LH"));
cfg.GetValue(path+"sql_filename", estr, DASH_SQL_NAME, 1, 32);

return false;
Expand Down Expand Up @@ -993,7 +994,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const i
}

std::string mycall((const char *)g2buf.hdr.mycall, 8);
if (DASH_SHOW_LH && memcmp(g2buf.hdr.sfx, "RPTR", 4) && std::regex_match(mycall.c_str(), preg)) {
if (showLastHeard && memcmp(g2buf.hdr.sfx, "RPTR", 4) && std::regex_match(mycall.c_str(), preg)) {
std::string sfx((const char *)g2buf.hdr.sfx, 4);
std::string urcall((const char *)g2buf.hdr.urcall, 8);
rtrim(mycall);
Expand Down Expand Up @@ -2268,7 +2269,7 @@ bool CQnetGateway::Init(char *cfgfile)
}

// open database
if (DASH_SHOW_LH) {
if (showLastHeard) {
std::string dbname(CFG_DIR);
dbname.append("/");
dbname.append(DASH_SQL_NAME);
Expand Down
5 changes: 2 additions & 3 deletions QnetGateway.h
Expand Up @@ -103,11 +103,10 @@ class CQnetGateway {

std::string gate2link, link2gate, gate2modem[3], modem2gate;

std::string OWNER, owner, FILE_STATUS, FILE_DTMF, FILE_ECHOTEST, IRCDDB_PASSWORD[2], FILE_QNVOICE_FILE, DASH_SQL_NAME;
std::string OWNER, owner, FILE_STATUS, FILE_DTMF, FILE_ECHOTEST, IRCDDB_PASSWORD[2], FILE_QNVOICE_FILE, DASH_SQL_NAME, DASH_SHOW_ORDER;

bool GATEWAY_SEND_QRGS_MAP, GATEWAY_HEADER_REGEN, APRS_ENABLE, playNotInCache;
bool GATEWAY_SEND_QRGS_MAP, GATEWAY_HEADER_REGEN, APRS_ENABLE, playNotInCache, showLastHeard;
bool LOG_DEBUG, LOG_IRC, LOG_DTMF, LOG_QSO;
bool DASH_SHOW_LH;

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;

Expand Down
7 changes: 1 addition & 6 deletions defaults
Expand Up @@ -219,9 +219,4 @@ timing_play_delay_d=19 # milliseconds between frames playback, if echo so
dash_sql_filename_d='qn.db' # name for the sqlite database in the $CFGDIR directory
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_sy_d=true # set to false if for no System Info section
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
dash_show_order_d='LH,MO,SY,IP,PS,UR' # Show sections in this order
226 changes: 116 additions & 110 deletions index.php
Expand Up @@ -123,120 +123,126 @@ function MyAndSfxToQrz(string $my, string $sfx)
<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";
}

if ('true' == GetCFGValue('dash_show_sy')) {
echo 'System Info:<br>', "\n";
$hn = trim(`uname -n`);
$kn = trim(`uname -rmo`);
$oslist = explode(':', `lsb_release -d`);
$os = trim($oslist[1]);
$cu = trim(`cat /proc/cpuinfo | grep Model`);
if (0 == strlen($cu))
$cu = trim(`cat /proc/cpuinfo | grep "model name"`);
$culist = explode("\n", $cu);
$mnlist = explode(':', $culist[0]);
$cu = trim($mnlist[1]);
if (count($culist) > 1)
$cu .= ' ' . count($culist) . ' Threads';
if (file_exists('/opt/vc/bin/vcgencmd'))
$cu .= ' ' . str_replace("'", '&deg;', trim(`/opt/vc/bin/vcgencmd measure_temp`));
echo '<table cellpadding="1" border="1" style="font-family: monospace">', "\n";
echo '<tr><td style="text-align:center">Hostname</td><td style="text-align:center">Kernel</td><td style="text-align:center">OS</td><td style="text-align:center">CPU</td></tr>', "\n";
echo '<tr><td style="text-align:center">', $hn, '</td><td style="text-align:center">', $kn, '</td><td style="text-align:center">', $os, '</td><td style="text-align:center">', $cu, '</td></tr></table><br>', "\n";
}

if ('true' == GetCFGValue('dash_show_lh')) {
echo 'Last Heard:<br><code>', "\n";
$rstr = 'MyCall/Sfx Source Last Time<br>';
echo str_replace(' ', '&nbsp;', $rstr), "\n";
$dbname = $cfgdir.'/'.GetCFGValue('dash_sql_filename');
$db = new SQLite3($dbname, SQLITE3_OPEN_READONLY);
$ss = 'SELECT mycall,sfx,urcall,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 4 LIMIT '.GetCFGValue('dash_lastheard_count').' ';
if ($stmnt = $db->prepare($ss)) {
if ($result = $stmnt->execute()) {
while ($row = $result->FetchArray(SQLITE3_NUM)) {
$source = ("CQCQCQ " == $row[2]) ? "Linking" : "Routing";
$rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$source.' '.SecToString(intval($row[3])).'<br>';
echo str_replace('*', ' ', str_replace(' ', '&nbsp;', $rstr)), "\n";
$showorder = GetCFGValue('dash_show_order');
$showlist = explode(',', trim($showorder));
foreach($showlist as $section) {
switch ($section) {
case 'PS':
if (`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";
}
$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) {
$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) {
echo 'Module: ', "\n";
foreach ($configured as $mod) {
echo '<input type="radio" name="fmodule"', (isset($fmodule) && $fmodule==$mod) ? '"checked"' : '', ' value="$mod">', $mod, '<br>', "\n";
}
} else
$fmodule = $configured[0];
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'];
if (empty($_POST['fmodule'])) {
if (1==count($configured)) {
break;
case 'SY':
echo 'System Info:<br>', "\n";
$hn = trim(`uname -n`);
$kn = trim(`uname -rmo`);
$oslist = explode(':', `lsb_release -d`);
$os = trim($oslist[1]);
$cu = trim(`cat /proc/cpuinfo | grep Model`);
if (0 == strlen($cu))
$cu = trim(`cat /proc/cpuinfo | grep "model name"`);
$culist = explode("\n", $cu);
$mnlist = explode(':', $culist[0]);
$cu = trim($mnlist[1]);
if (count($culist) > 1)
$cu .= ' ' . count($culist) . ' Threads';
if (file_exists('/opt/vc/bin/vcgencmd'))
$cu .= ' ' . str_replace("'", '&deg;', trim(`/opt/vc/bin/vcgencmd measure_temp`));
echo '<table cellpadding="1" border="1" style="font-family: monospace">', "\n";
echo '<tr><td style="text-align:center">Hostname</td><td style="text-align:center">Kernel</td><td style="text-align:center">OS</td><td style="text-align:center">CPU</td></tr>', "\n";
echo '<tr><td style="text-align:center">', $hn, '</td><td style="text-align:center">', $kn, '</td><td style="text-align:center">', $os, '</td><td style="text-align:center">', $cu, '</td></tr></table><br>', "\n";
break;
case 'LH':
echo 'Last Heard:<br><code>', "\n";
$rstr = 'MyCall/Sfx Source Last Time<br>';
echo str_replace(' ', '&nbsp;', $rstr), "\n";
$dbname = $cfgdir.'/'.GetCFGValue('dash_sql_filename');
$db = new SQLite3($dbname, SQLITE3_OPEN_READONLY);
$ss = 'SELECT mycall,sfx,urcall,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 4 LIMIT '.GetCFGValue('dash_lastheard_count').' ';
if ($stmnt = $db->prepare($ss)) {
if ($result = $stmnt->execute()) {
while ($row = $result->FetchArray(SQLITE3_NUM)) {
$source = ("CQCQCQ " == $row[2]) ? "Linking" : "Routing";
$rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$source.' '.SecToString(intval($row[3])).'<br>';
echo str_replace('*', ' ', str_replace(' ', '&nbsp;', $rstr)), "\n";
}
$result->finalize();
}
$stmnt->close();
}
$db->Close();
echo '</code><br>', "\n";
break;
case '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";
break;
case '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">Link</td><td style="text-align:center">Link 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";
break;
case 'UR':
echo 'Send URCall:<br>', "\n";
echo '<form method="post">', "\n";
if (count($configured) > 1) {
echo 'Module: ', "\n";
foreach ($configured as $mod) {
echo '<input type="radio" name="fmodule"', (isset($fmodule) && $fmodule==$mod) ? '"checked"' : '', ' value="$mod">', $mod, '<br>', "\n";
}
} else
$fmodule = $configured[0];
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'];
if (empty($_POST['fmodule'])) {
if (1==count($configured)) {
$fmodule = $configured[0];
}
} else {
$fmodule = $_POST['fmodule'];
}
}
} else {
$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) {
$command = 'qnremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall;
echo $command, "<br>\n";
$unused = `$command`;
if (strlen($furcall)>0 && strlen($fmodule)>0) {
$command = 'qnremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall;
echo $command, "<br>\n";
$unused = `$command`;
}
break;
default:
echo 'Section "', $section, '" was not found!<br>', "\n";
break;
}
}
?>
Expand Down
39 changes: 15 additions & 24 deletions qnconfig
Expand Up @@ -146,33 +146,29 @@ DashboardMenu () {
fi
echo -n "r : Refresh time (sec) for page = "; EvaluateVar dash_refresh{,_d}
echo -n "c : Max number of last heard entries = "; EvaluateVar dash_lastheard_count{,_d}
echo -n "p : Show the Processes = "; EvaluateVar dash_show_ps{,_d}
echo -n "y : Show the System = "; EvaluateVar dash_show_sy{,_d}
echo -n "l : Show the Last Heard = "; EvaluateVar dash_show_lh{,_d}
echo -n "i : Show the IP Addresses = "; EvaluateVar dash_show_ip{,_d}
echo -n "m : Show the Modules(s) = "; EvaluateVar dash_show_mo{,_d}
echo -n "s : Show the Send URCall = "; EvaluateVar dash_show_ur{,_d}
echo -n "o : Show Section Order = "; EvaluateVar dash_show_order{,_d}
echo
echo " The 'Show Section' is a comma separated value, e.g. 'lh,mo,sy,ip,ps,ur'"
echo " The following sections can be shown in any order. It's okay to leave out sections."
echo " Don't use spaces, just use commas. Lowercase will be set to uppercase."
echo
echo " LH is the Last Heard Section"
echo " MO is the Modules Section"
echo " SY is the System Section"
echo " IP is the IP Address Section"
echo " PS is the Processes Section"
echo " UR is the Send URCall Section"
EndMenu

if [[ "$key" == n* ]]; then dash_sql_filename="$value"
elif [[ "$key" == r* ]]; then dash_refresh="$value"
elif [[ "$key" == c* ]]; then dash_lastheard_count="$value"
elif [[ "$key" == p* ]]; then SetBooleanValue dash_show_ps "$value"
elif [[ "$key" == y* ]]; then SetBooleanValue dash_show_sy "$value"
elif [[ "$key" == l* ]]; then SetBooleanValue dash_show_lh "$value"
elif [[ "$key" == i* ]]; then SetBooleanValue dash_show_ip "$value"
elif [[ "$key" == m* ]]; then SetBooleanValue dash_show_mo "$value"
elif [[ "$key" == s* ]]; then SetBooleanValue dash_show_ur "$value"
elif [[ "$key" == o* ]]; then dash_show_order="${value^^}"
elif [[ "$key" == u* ]]; then
if [[ "$value" == n* ]]; then unset dash_sql_filename
elif [[ "$value" == r* ]]; then unset dash_refresh
elif [[ "$value" == c* ]]; then unset dash_lastheard_count
elif [[ "$value" == p* ]]; then unset dash_show_ps
elif [[ "$value" == y* ]]; then unset dash_show_sy
elif [[ "$value" == l* ]]; then unset dash_show_lh
elif [[ "$value" == i* ]]; then unset dash_show_ip
elif [[ "$value" == m* ]]; then unset dash_show_mo
elif [[ "$value" == s* ]]; then unset dash_show_ur
elif [[ "$value" == o* ]]; then unset dash_show_order
fi
fi
done
Expand Down Expand Up @@ -700,12 +696,7 @@ WriteCFGFile () {
[ -z "${dash_sql_filename+x}" ] || echo "dash_sql_filename='${dash_sql_filename}'" >> $outFile
[ -z "${dash_refresh+x}" ] || echo "dash_refresh=${dash_refresh}" >> $outFile
[ -z "${dash_lastheard_count+x}" ] || echo "dash_lastheard_count=${dash_lastheard_count}" >> $outFile
[ -z "${dash_show_ip+x}" ] || echo "dash_show_ip=${dash_show_ip}" >> $outFile
[ -z "${dash_show_lh+x}" ] || echo "dash_show_lh=${dash_show_lh}" >> $outFile
[ -z "${dash_show_ps+x}" ] || echo "dash_show_ps=${dash_show_ps}" >> $outFile
[ -z "${dash_show_sy+x}" ] || echo "dash_show_sy=${dash_show_sy}" >> $outFile
[ -z "${dash_show_mo+x}" ] || echo "dash_show_mo=${dash_show_mo}" >> $outFile
[ -z "${dash_show_ur+x}" ] || echo "dash_show_ur=${dash_show_ur}" >> $outFile
[ -z "${dash_show_order+x}" ] || echo "dash_show_order='${dash_show_order}'" >> $outFile
clear
cat $outFile
echo
Expand Down

0 comments on commit c49692f

Please sign in to comment.