1st release candidate

pull/14/head
Tom Early 6 years ago
parent e749704b77
commit d28bdf5780

@ -1,33 +0,0 @@
##### DASH #####
This is the minimum viable dashboard to be useful. It provides the
following information, refreshed every 30s:
* Node Callsign
* Node TX Frequency
* Node IP Address
* Currently Linked Reflector
It also has a button to disconnect the currently connected reflector, and a text
field and button to connect to another reflector. Only the first 7 characters
entered here will be used, the rest will be discarded. If the reflector entered
is not valid (or not included in the gwys.txt file) the command will still run
but have no effect.
To access the dashboard, simply point a browser at the Hotspot's IP address or
at http://<hostname>.local/ (on the same subnet).
To install, run the following command after the main installation:
sudo make installdash
Note that this will install the PIP package for Python3 if not installed, and
it will also install the libconf Python module. These are not uninstalled by the
uninstall script, but as these are idempotent commands, there is no issue running
the install if they are already present.
To uninstall, run the following:
sudo make uninstalldash

@ -0,0 +1,34 @@
##### DASHBOARD.README #####
A web-based dashboard can be enabled. You can supply your own index.php file,
or a functional dashboard can be provide. If no index.php file is in the
build directroy when try to install the dashboard, the installation will fail.
To get started, copy the "example.php" file to "index.php".
The example.php file is a good place to start, if you want to create your own
by adding features to your dashboard. This dashboard include a <form> with
a button to send any URCALL to your gateway.
To install, run the following command after you have created an index.php file:
sudo make installdash
Note that this will install a php web server and all necessary packaged needed
for the server. To uninstall, run the following:
sudo make uninstalldash
These installed packaged are not uninstalled by the uninstall script. It will
only shut down the php web server.
Likewise, the index.php file will not be erased in the build directory when you
uninstall the dashboard, so if you've done a "git pull" and have noticed that
there was a new example.php file downloaded, you may want to copy the newer
example.php file to index.php.
One the dashboard server is running, simply point a browser at the Hotspot's IP
address or at http://<hostname>.local/ (on the same subnet).
Please note that this is a very simple server and is not recommended for the
world wide web. If you want a robust dashboard accessible from the web, you
will want to use a robust server, like apache, and a different index.php file.

@ -16,13 +16,14 @@
# locations for the executibles and other files are set here # locations for the executibles and other files are set here
# NOTE: IF YOU CHANGE THESE, YOU WILL NEED TO UPDATE THE service.* FILES AND # NOTE: IF YOU CHANGE THESE, YOU WILL NEED TO UPDATE THE service.* FILES AND
# if you change these locations, make sure the sgs.service file is updated! # if you change these locations, make sure the sgs.service file is updated!
# you will also break hard coded paths in the dashboard file, index.php.
BINDIR=/usr/local/bin BINDIR=/usr/local/bin
CFGDIR=/usr/local/etc CFGDIR=/usr/local/etc
WWWDIR=/usr/local/www
MMPATH=../MMDVMHost MMPATH=../MMDVMHost
SYSDIR=/lib/systemd/system SYSDIR=/lib/systemd/system
IRC=ircddb IRC=ircddb
CRONDIR=/etc/cron.d
# use this if you want debugging help in the case of a crash # use this if you want debugging help in the case of a crash
#CPPFLAGS=-g -ggdb -W -Wall -std=c++11 -Iircddb -DCFG_DIR=\"$(CFGDIR)\" #CPPFLAGS=-g -ggdb -W -Wall -std=c++11 -Iircddb -DCFG_DIR=\"$(CFGDIR)\"
@ -168,11 +169,14 @@ installdtmf : qndtmf
systemctl daemon-reload systemctl daemon-reload
systemctl start qndtmf.service systemctl start qndtmf.service
installdash : installdash : index.php
/usr/bin/apt-get -y install python3-pip /usr/bin/apt -y php-cli
/bin/cp -f dash/qng-info.py $(BINDIR) mkdir -p $(WWWDIR)
/bin/cp -f dash/qngdash $(CRONDIR) /bin/cp -f index.php $(WWWDIR)
/usr/bin/python3 $(BINDIR)/qng-info.py & /bin/cp -f system/qndash.service $(SYSDIR)
systemctl enable qndash.service
systemctl daemon-reload
systemctl start qndash.servlce
uninstallbase : uninstallbase :
######### QnetGateway ######### ######### QnetGateway #########
@ -252,6 +256,8 @@ uninstalldtmf :
/bin/rm -f $(BINDIR)/qndtmf /bin/rm -f $(BINDIR)/qndtmf
uninstalldash : uninstalldash :
/bin/rm -f $(SYSDIR)/qng-info.py systemctl stop qndash.service
/bin/rm -f $(CRONDIR)/qngdash systemctl disable qndash.service
/usr/bin/pkill python3 /bin/rm -f $(SYSDIR)/qndash.service
systemctl daemon-reload
/bin/rm -f $(WWWDIR)/index.php

@ -1,121 +0,0 @@
#!/usr/bin/env python
import socket
import datetime
import csv
import configparser
import json
import requests
import subprocess
from time import sleep
# HTML to send to browser
html = """<!DOCTYPE html>
<html>
<head>
<title>QnetGateway D-Star Hotspot</title>
<meta http-equiv="refresh" content="30, url=http://{0}" >
</head>
<h2>QnetGateway D-Star Hotspot</h2>
<p>This status page shows the Callsign, Frequency, IP address and Connected Reflector for the QnetGateway D-Star Hotspot.</p>
<p><strong>Callsign:</strong> {1}<br>
<strong>Modem:</strong> {2}<br>
<strong>Frequency:</strong> {3}MHz<br>
<strong>IP Address:</strong> {4}<br>
<strong>External IP Address:</strong> {5}<br>
<strong>Reflector:</strong> {6}</p>
<form>
<strong>Note:</strong> Please enter a valid 7 character reflector code.</br>
<strong>Link Reflector: </strong> <input type="text" name="LINK"> <input type="submit" value="Link Reflector"></br>
</form>
<form>
<strong>Unlink Reflector: </strong> <button name="UNLINK" value="UL" type="submit">Unlink Reflector</button>
</form>
</html>
"""
data = []
def get_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0]
except:
IP = '127.0.0.1'
finally:
s.close()
return IP
def get_data():
global data
data = []
reflector = "Unlinked"
with open('/usr/local/etc/rptr_status') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
reflector = row[1] + row[2]
data.append(cs)
data.append(modem)
data.append(freq)
data.append(intip)
data.append(extip)
data.append(reflector)
return data
def get_MMDVM():
MMDVM_config = configparser.ConfigParser()
MMDVM_config.read('/usr/local/etc/MMDVM.qn')
rawfreq = MMDVM_config['Info']['txfrequency']
freq = float(rawfreq)/1000000
return freq
intip = get_ip()
extip = requests.get('https://ipapi.co/json/').json()['ip']
cfg = dict()
with open('/usr/local/etc/qn.cfg', 'r') as f:
for line in f:
if line.strip()[0] == "#":
continue
kv = line.strip().split("=")
cfg[kv[0]] = kv[1].strip("'")
cs = cfg['ircddb_login']
for module in ( 'a', 'b', 'c' ):
key = 'module_' + module
if key in cfg:
modem = cfg[key]
if modem == 'mmdvmhost':
freq = get_MMDVM()
elif key + "_tx_frequency" in cfg:
freq = cfg[key + "_tx_frequency"]
elif key + "_frequency" in cfg:
freq = cfg[key + "_frequency"]
else:
freq = 0.0
break
#Setup Socket WebServer
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
request = conn.recv(1024)
request = str(request)
UNLINK = request.find('/?UNLINK=UL')
if UNLINK == 6:
unlink = "/usr/local/bin/qnremote " + module + " " + cs + " U"
subprocess.Popen(unlink.split())
sleep(8)
LINK = request.find('/?LINK=')
if LINK == 6:
refl = request[13:20].upper()
link = "/usr/local/bin/qnremote " + module + " " + cs + " " + refl + "L"
subprocess.Popen(link.split())
sleep(8)
data = get_data()
response = html.format(data[3], data[0], data[1], data[2], data[3], data[4], data[5])
conn.send(bytes(response, "UTF-8"))
conn.close()

@ -1,6 +0,0 @@
# Cronjob to kick off dash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot root /bin/sleep 30 && /usr/bin/python3 /usr/local/bin/qng-info.py

@ -46,7 +46,7 @@
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 = '../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);
@ -57,9 +57,20 @@
return explode(',', ',,,,,'); return explode(',', ',,,,,');
} }
$cfg = parse("../qn.cfg"); $cfg = parse("/usr/local/etc/qn.cfg");
?> ?>
<h2>QnetGateway <?php echo $cfg['ircddb_login']; ?> Dashboard</h2> <h2>QnetGateway <?php echo $cfg['ircddb_login']; ?> Dashboard</h2>
<?php
if (`ps -aux -e qn -e MMDVMHost | wc -l` > 1) {
echo 'Process:<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";
}
?>
IP Addresses:<br> IP Addresses:<br>
<table cellpadding='1' border='1' style='font-family: monospace'> <table cellpadding='1' border='1' style='font-family: monospace'>
<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 style="text-align:center">Internal</td><td style="text-align:center">IPV4</td><td style="text-align:center">IPV6</td></tr>
@ -115,9 +126,12 @@ URCall: <input type="text" name='furcall' value="<?php echo $furcall;?>">
$fmodule = $_POST['fmodule']; $fmodule = $_POST['fmodule'];
} }
} }
$furcall = trim(preg_replace('/[^0-9a-z ]/', '', strtolower($furcall)));
if (strlen($furcall)>0 && strlen($fmodule)>0) { if (strlen($furcall)>0 && strlen($fmodule)>0) {
echo 'COMMAND: sgsremote ', $fmodule, ' ', $cfg['ircddb_login'], ' ', $furcall, '<br>', "\n"; $command = 'sgsremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall;
echo $command, "<br>\n";
//exec($command);
} }
?> ?>
</body> </body>

@ -0,0 +1,13 @@
[Unit]
Description=QnetGateway Dashboard
Requires=network.target
After=systemd-user-session.service network.target
[Service]
Type=simple
WorkingDirectory=/usr/local/etc/www
ExecStart=/usr/bin/php -S 0.0.0.0:80
Restart=always
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save

Powered by TurnKey Linux.