updated dash for qn.cfg format

pull/14/head
Tom Early 6 years ago
parent 3f71c3e683
commit c2ee9973e0

@ -170,7 +170,6 @@ installdtmf : qndtmf
installdash : installdash :
/usr/bin/apt-get -y install python3-pip /usr/bin/apt-get -y install python3-pip
/usr/bin/pip3 install libconf
/bin/cp -f dash/qng-info.py $(BINDIR) /bin/cp -f dash/qng-info.py $(BINDIR)
/bin/cp -f dash/qngdash $(CRONDIR) /bin/cp -f dash/qngdash $(CRONDIR)
/bin/sh /usr/bin/python3 $(BINDIR)/qng-info.py & /bin/sh /usr/bin/python3 $(BINDIR)/qng-info.py &

@ -3,7 +3,6 @@ import socket
import datetime import datetime
import csv import csv
import configparser import configparser
import libconf
import json import json
import requests import requests
import subprocess import subprocess
@ -20,10 +19,11 @@ html = """<!DOCTYPE html>
<p>This status page shows the Callsign, Frequency, IP address and Connected Reflector for the QnetGateway D-Star Hotspot.</p> <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> <p><strong>Callsign:</strong> {1}<br>
<strong>Frequency:</strong> {2}MHz<br> <strong>Modem:</strong> {2}<br>
<strong>IP Address:</strong> {3}<br> <strong>Frequency:</strong> {3}MHz<br>
<strong>External IP Address:</strong> {4}<br> <strong>IP Address:</strong> {4}<br>
<strong>Reflector:</strong> {5}</p> <strong>External IP Address:</strong> {5}<br>
<strong>Reflector:</strong> {6}</p>
<form> <form>
<strong>Note:</strong> Please enter a valid 7 character reflector code.</br> <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> <strong>Link Reflector: </strong> <input type="text" name="LINK"> <input type="submit" value="Link Reflector"></br>
@ -35,73 +35,87 @@ html = """<!DOCTYPE html>
""" """
data = [] data = []
def get_ip(): def get_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try: try:
# doesn't even have to be reachable # doesn't even have to be reachable
s.connect(('10.255.255.255', 1)) s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0] IP = s.getsockname()[0]
except: except:
IP = '127.0.0.1' IP = '127.0.0.1'
finally: finally:
s.close() s.close()
return IP return IP
def get_data(): def get_data():
global data global data
data = [] data = []
reflector = "Unlinked" reflector = "Unlinked"
with open('/usr/local/etc/RPTR_STATUS.txt') as csvfile: with open('/usr/local/etc/rptr_status') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',') readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV: for row in readCSV:
reflector = row[1] + row[2] reflector = row[1] + row[2]
data.append(cs) data.append(cs)
data.append(freq) data.append(modem)
data.append(intip) data.append(freq)
data.append(extip) data.append(intip)
data.append(reflector) data.append(extip)
return data data.append(reflector)
return data
def get_MMDVM(): def get_MMDVM():
MMDVM_config = configparser.ConfigParser() MMDVM_config = configparser.ConfigParser()
MMDVM_config.read('/usr/local/etc/MMDVM.qn') MMDVM_config.read('/usr/local/etc/MMDVM.qn')
rawfreq = MMDVM_config['Info']['txfrequency'] rawfreq = MMDVM_config['Info']['txfrequency']
freq = float(rawfreq)/1000000 freq = float(rawfreq)/1000000
return freq return freq
intip = get_ip() intip = get_ip()
extip = requests.get('https://ipapi.co/json/').json()['ip'] extip = requests.get('https://ipapi.co/json/').json()['ip']
with open('/usr/local/etc/qn.cfg') as f:
config = libconf.load(f) cfg = dict()
cs = config.ircddb.login with open('/usr/local/etc/qn.cfg', 'r') as f:
for key in config.module: for line in f:
module = key if line.strip()[0] == "#":
if config['module'][key]['type'] == 'mmdvm': continue
freq = get_MMDVM() kv = line.strip().split("=")
else: cfg[kv[0]] = kv[1].strip("'")
freq = config['module'][key]['frequency']
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 #Setup Socket WebServer
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80)) s.bind(('', 80))
s.listen(5) s.listen(5)
while True: while True:
conn, addr = s.accept() conn, addr = s.accept()
request = conn.recv(1024) request = conn.recv(1024)
request = str(request) request = str(request)
UNLINK = request.find('/?UNLINK=UL') UNLINK = request.find('/?UNLINK=UL')
if UNLINK == 6: if UNLINK == 6:
unlink = "/usr/local/bin/qnremote " + module + " " + cs + " U" unlink = "/usr/local/bin/qnremote " + module + " " + cs + " U"
subprocess.Popen(unlink.split()) subprocess.Popen(unlink.split())
sleep(8) sleep(8)
LINK = request.find('/?LINK=') LINK = request.find('/?LINK=')
if LINK == 6: if LINK == 6:
refl = request[13:20].upper() refl = request[13:20].upper()
link = "/usr/local/bin/qnremote " + module + " " + cs + " " + refl + "L" link = "/usr/local/bin/qnremote " + module + " " + cs + " " + refl + "L"
subprocess.Popen(link.split()) subprocess.Popen(link.split())
sleep(8) sleep(8)
data = get_data() data = get_data()
response = html.format(data[2], data[0], data[1], data[2], data[3], data[4]) response = html.format(data[3], data[0], data[1], data[2], data[3], data[4], data[5])
conn.send(bytes(response, "UTF-8")) conn.send(bytes(response, "UTF-8"))
conn.close() conn.close()

Loading…
Cancel
Save

Powered by TurnKey Linux.