From b084ea0e2891574d7b41dece9f2edb1d0cb527a4 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 25 Apr 2018 21:09:38 +0100 Subject: [PATCH] First version of the basic dash. --- Makefile | 12 +++++++ dash/qng-dash.sh | 3 ++ dash/qng-info.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ dash/qngdash | 6 ++++ 4 files changed, 109 insertions(+) create mode 100755 dash/qng-dash.sh create mode 100755 dash/qng-info.py create mode 100755 dash/qngdash diff --git a/Makefile b/Makefile index 8f2b2d0..2489773 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ CFGDIR=/usr/local/etc 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)\" @@ -162,6 +163,12 @@ installmmdvm : systemctl daemon-reload systemctl start mmdvm.service +installdash : + /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 : systemctl stop mmdvm.service systemctl disable mmdvm.timer @@ -264,3 +271,8 @@ uninstalldtmf : /bin/rm -f $(SYSDIR)/qndtmf.service systemctl daemon-reload /bin/rm -f $(BINDIR)/qndtmf + +uninstalldash : + /bin/rm -f $(SYSDIR)/qng-* + /bin/rm -f $(CRONDIR)/qngdash + /usr/bin/pkill python3 diff --git a/dash/qng-dash.sh b/dash/qng-dash.sh new file mode 100755 index 0000000..c631b69 --- /dev/null +++ b/dash/qng-dash.sh @@ -0,0 +1,3 @@ +#!/bin/sh +script='/usr/local/bin/qng-info.py' +nohup /usr/bin/python3 $script & diff --git a/dash/qng-info.py b/dash/qng-info.py new file mode 100755 index 0000000..b8e24bf --- /dev/null +++ b/dash/qng-info.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python + +from http.server import BaseHTTPRequestHandler, HTTPServer +import datetime +import socket +import csv +import configparser + +# 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: {0}
+Frequency: {1}MHz
+IP Address: {2}
+Reflector: {3}

+ +""" + +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] + config = configparser.ConfigParser() + config.read('/usr/local/etc/MMDVM.qn') + cs = config['General']['callsign'] + rawfreq = config['Info']['txfrequency'] + freq = float(rawfreq)/1000000 + data.append(cs) + data.append(freq) + data.append(str(get_ip())) + data.append(reflector) + return data + +def run(): + print('starting server...') + + # Server settings + server_address = ('', 80) + httpd = HTTPServer(server_address, HS_HTTPServer_RequestHandler) + print('running server...') + httpd.serve_forever() + + +run() diff --git a/dash/qngdash b/dash/qngdash new file mode 100755 index 0000000..cf6cb09 --- /dev/null +++ b/dash/qngdash @@ -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