Basic dash (#3)

* First version of the basic dash.

* Dashboard doc v0.1

* Updated to support DVAP and DVRPTR too by parsing qn.cfg as appropriate.

* Corrected typo in get_MMDVM() function

* Updated doc to include info on pip3 and libconf module installation.
pull/4/head
spynappels 8 years ago committed by Tom Early
parent 524af5b5c5
commit 7afa5fef99

@ -0,0 +1,27 @@
##### DASH #####
The first iteration of the dash is very rudimentary, but it provides the
following information, refreshed every 30s:
* Node Callsign
* Node TX Frequency
* Node IP Address
* Currently Linked Reflector
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

@ -22,6 +22,7 @@ CFGDIR=/usr/local/etc
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)\"
@ -162,6 +163,14 @@ installmmdvm :
systemctl daemon-reload systemctl daemon-reload
systemctl start mmdvm.service systemctl start mmdvm.service
installdash :
/usr/bin/apt-get -y install python3-pip
/usr/bin/pip3 install libconf
/bin/cp -f dash/qng-dash.sh $(BINDIR)
/bin/cp -f dash/qng-info.py $(BINDIR)
/bin/cp -f dash/qngdash $(CRONDIR)
/bin/sh $(BINDIR)/qng-dash.sh
uninstallmmdvm : uninstallmmdvm :
systemctl stop mmdvm.service systemctl stop mmdvm.service
systemctl disable mmdvm.timer systemctl disable mmdvm.timer
@ -267,3 +276,8 @@ uninstalldtmf :
/bin/rm -f $(SYSDIR)/qndtmf.service /bin/rm -f $(SYSDIR)/qndtmf.service
systemctl daemon-reload systemctl daemon-reload
/bin/rm -f $(BINDIR)/qndtmf /bin/rm -f $(BINDIR)/qndtmf
uninstalldash :
/bin/rm -f $(SYSDIR)/qng-*
/bin/rm -f $(CRONDIR)/qngdash
/usr/bin/pkill python3

@ -0,0 +1,3 @@
#!/bin/sh
script='/usr/local/bin/qng-info.py'
nohup /usr/bin/python3 $script &

@ -0,0 +1,99 @@
#!/usr/bin/env python
from http.server import BaseHTTPRequestHandler, HTTPServer
import datetime
import socket
import csv
import configparser
import libconf
# HTML to send to browser
html = """<!DOCTYPE html>
<html>
<head>
<title>QnetGateway D-Star Hotspot</title>
<meta http-equiv="refresh" content="30" >
</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> {0}<br>
<strong>Frequency:</strong> {1}MHz<br>
<strong>IP Address:</strong> {2}<br>
<strong>Reflector:</strong> {3}</p>
</html>
"""
data = []
# HTTPRequestHandler class
class HS_HTTPServer_RequestHandler(BaseHTTPRequestHandler):
# GET
def do_GET(self):
# Send response status code
self.send_response(200)
# Send headers
self.send_header('Content-type','text/html')
self.end_headers()
# Send message back to client
data = get_data()
message = html.format(data[0], data[1], data[2], data[3])
# Write content as utf-8 data
self.wfile.write(bytes(message, "utf8"))
return
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.txt') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
reflector = row[1] + row[2]
with open('/usr/local/etc/qn.cfg') as f:
config = libconf.load(f)
cs = config.ircddb.login
for key in config.module:
if config['module'][key]['type'] == 'mmdvm':
freq = get_MMDVM()
else:
freq = config['module'][key]['frequency']
data.append(cs)
data.append(freq)
data.append(str(get_ip()))
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
def run():
print('starting server...')
# Server settings
server_address = ('', 80)
httpd = HTTPServer(server_address, HS_HTTPServer_RequestHandler)
print('running server...')
httpd.serve_forever()
run()

@ -0,0 +1,6 @@
# Cronjob to kick off dash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot root /usr/local/bin/qng-dash.sh
Loading…
Cancel
Save

Powered by TurnKey Linux.