From d28bdf578005ba166b541f549ebdbe5f25e16caa Mon Sep 17 00:00:00 2001 From: Tom Early Date: Mon, 2 Mar 2020 11:45:55 -0700 Subject: [PATCH] 1st release candidate --- DASH.README | 33 ---------- DASHBOARD.README | 34 ++++++++++ Makefile | 24 ++++--- dash/qng-info.py | 121 ---------------------------------- dash/qngdash | 6 -- dash/index.php => example.php | 20 +++++- system/qndash.service | 13 ++++ 7 files changed, 79 insertions(+), 172 deletions(-) delete mode 100644 DASH.README create mode 100644 DASHBOARD.README delete mode 100755 dash/qng-info.py delete mode 100755 dash/qngdash rename dash/index.php => example.php (82%) create mode 100644 system/qndash.service diff --git a/DASH.README b/DASH.README deleted file mode 100644 index 7a7d482..0000000 --- a/DASH.README +++ /dev/null @@ -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://.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 diff --git a/DASHBOARD.README b/DASHBOARD.README new file mode 100644 index 0000000..b97e523 --- /dev/null +++ b/DASHBOARD.README @@ -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
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://.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. diff --git a/Makefile b/Makefile index f1f59a1..3e5cf9c 100644 --- a/Makefile +++ b/Makefile @@ -16,13 +16,14 @@ # locations for the executibles and other files are set here # 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! +# you will also break hard coded paths in the dashboard file, index.php. BINDIR=/usr/local/bin CFGDIR=/usr/local/etc +WWWDIR=/usr/local/www MMPATH=../MMDVMHost SYSDIR=/lib/systemd/system IRC=ircddb -CRONDIR=/etc/cron.d # 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)\" @@ -168,11 +169,14 @@ installdtmf : qndtmf systemctl daemon-reload systemctl start qndtmf.service -installdash : - /usr/bin/apt-get -y install python3-pip - /bin/cp -f dash/qng-info.py $(BINDIR) - /bin/cp -f dash/qngdash $(CRONDIR) - /usr/bin/python3 $(BINDIR)/qng-info.py & +installdash : index.php + /usr/bin/apt -y php-cli + mkdir -p $(WWWDIR) + /bin/cp -f index.php $(WWWDIR) + /bin/cp -f system/qndash.service $(SYSDIR) + systemctl enable qndash.service + systemctl daemon-reload + systemctl start qndash.servlce uninstallbase : ######### QnetGateway ######### @@ -252,6 +256,8 @@ uninstalldtmf : /bin/rm -f $(BINDIR)/qndtmf uninstalldash : - /bin/rm -f $(SYSDIR)/qng-info.py - /bin/rm -f $(CRONDIR)/qngdash - /usr/bin/pkill python3 + systemctl stop qndash.service + systemctl disable qndash.service + /bin/rm -f $(SYSDIR)/qndash.service + systemctl daemon-reload + /bin/rm -f $(WWWDIR)/index.php diff --git a/dash/qng-info.py b/dash/qng-info.py deleted file mode 100755 index f0a13d3..0000000 --- a/dash/qng-info.py +++ /dev/null @@ -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 = """ - - -QnetGateway D-Star Hotspot - - -

QnetGateway D-Star Hotspot

- -

This status page shows the Callsign, Frequency, IP address and Connected Reflector for the QnetGateway D-Star Hotspot.

-

Callsign: {1}
-Modem: {2}
-Frequency: {3}MHz
-IP Address: {4}
-External IP Address: {5}
-Reflector: {6}

- -Note: Please enter a valid 7 character reflector code.
-Link Reflector:
- -
-Unlink Reflector: -
- -""" -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() diff --git a/dash/qngdash b/dash/qngdash deleted file mode 100755 index 8dbda53..0000000 --- a/dash/qngdash +++ /dev/null @@ -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 diff --git a/dash/index.php b/example.php similarity index 82% rename from dash/index.php rename to example.php index 1b61f83..9f4273d 100644 --- a/dash/index.php +++ b/example.php @@ -46,7 +46,7 @@ if (array_key_exists('file_status', $kv)) $file = $kv['file_status']; else - $file = '../rptr_status'; + $file = '/usr/local/etc/rptr_status'; if ($lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) { foreach ($lines as $line) { $words = explode(',', $line); @@ -57,9 +57,20 @@ return explode(',', ',,,,,'); } - $cfg = parse("../qn.cfg"); + $cfg = parse("/usr/local/etc/qn.cfg"); ?>

QnetGateway Dashboard

+ 1) { + echo 'Process:
', "\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`); + foreach ($lines as $line) { + echo str_replace(' ', ' ', $line), "
\n"; + } + echo '
', "\n"; +} +?> IP Addresses:
@@ -115,9 +126,12 @@ URCall: $fmodule = $_POST['fmodule']; } } + $furcall = trim(preg_replace('/[^0-9a-z ]/', '', strtolower($furcall))); if (strlen($furcall)>0 && strlen($fmodule)>0) { - echo 'COMMAND: sgsremote ', $fmodule, ' ', $cfg['ircddb_login'], ' ', $furcall, '
', "\n"; + $command = 'sgsremote '.strtolower($fmodule).' '.strtolower($cfg['ircddb_login']).' '.$furcall; + echo $command, "
\n"; + //exec($command); } ?> diff --git a/system/qndash.service b/system/qndash.service new file mode 100644 index 0000000..d41c292 --- /dev/null +++ b/system/qndash.service @@ -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
InternalIPV4IPV6