This is the complete minimum viable dash. (#4)

It includes the Unlink and Link options.
pull/14/head
spynappels 8 years ago committed by Tom Early
parent 7afa5fef99
commit 73d523a883

@ -1,6 +1,6 @@
##### DASH #####
The first iteration of the dash is very rudimentary, but it provides the
This is the minimum viable dashboard to be useful. It provides the
following information, refreshed every 30s:
* Node Callsign
@ -8,6 +8,12 @@ following information, refreshed every 30s:
* 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).

@ -166,10 +166,9 @@ installmmdvm :
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
/bin/sh /usr/bin/python3 $(BINDIR)/qng-info.py &
uninstallmmdvm :
systemctl stop mmdvm.service
@ -278,6 +277,6 @@ uninstalldtmf :
/bin/rm -f $(BINDIR)/qndtmf
uninstalldash :
/bin/rm -f $(SYSDIR)/qng-*
/bin/rm -f $(SYSDIR)/qng-info.py
/bin/rm -f $(CRONDIR)/qngdash
/usr/bin/pkill python3

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

@ -1,49 +1,39 @@
#!/usr/bin/env python
from http.server import BaseHTTPRequestHandler, HTTPServer
import datetime
import socket
import datetime
import csv
import configparser
import libconf
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" >
<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> {0}<br>
<strong>Frequency:</strong> {1}MHz<br>
<strong>IP Address:</strong> {2}<br>
<strong>Reflector:</strong> {3}</p>
<p><strong>Callsign:</strong> {1}<br>
<strong>Frequency:</strong> {2}MHz<br>
<strong>IP Address:</strong> {3}<br>
<strong>External IP Address:</strong> {4}<br>
<strong>Reflector:</strong> {5}</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 = []
# 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:
@ -65,17 +55,10 @@ def get_data():
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(intip)
data.append(extip)
data.append(reflector)
return data
@ -86,14 +69,39 @@ def get_MMDVM():
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()
intip = get_ip()
extip = requests.get('https://ipapi.co/json/').json()['ip']
with open('/usr/local/etc/qn.cfg') as f:
config = libconf.load(f)
cs = config.ircddb.login
for key in config.module:
module = key
if config['module'][key]['type'] == 'mmdvm':
freq = get_MMDVM()
else:
freq = config['module'][key]['frequency']
#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)
run()
data = get_data()
response = html.format(data[2], data[0], data[1], data[2], data[3], data[4])
conn.send(bytes(response, "UTF-8"))
conn.close()

@ -3,4 +3,4 @@
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot root /usr/local/bin/qng-dash.sh
@reboot root /bin/sleep 30 && /usr/bin/python3 /usr/local/bin/qng-info.py

Loading…
Cancel
Save

Powered by TurnKey Linux.