From 4e98ed851396a9eaf994bab0df6a413f2258178d Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Mon, 20 Sep 2021 09:33:21 -0700 Subject: [PATCH] modify template, finalize GPS location logging, initial commit of APRS dashboard, combine peer locations and APRS into single map --- bridge.py | 6 ++- config.py | 3 ++ data_gateway.py | 14 ++++-- hblink.py | 3 +- web/app.py | 75 +++++++++++++++++++++++++--- web/templates/aprs_page.html | 31 ++++++++++++ web/templates/flask_user_layout.html | 3 +- 7 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 web/templates/aprs_page.html diff --git a/bridge.py b/bridge.py index 40a5ada..421c0bd 100755 --- a/bridge.py +++ b/bridge.py @@ -1584,8 +1584,10 @@ if __name__ == '__main__': stream_trimmer.addErrback(loopingErrHandle) logger.info('Unit calls will be bridged to: ' + str(UNIT)) + # Download burn list - with open(CONFIG['WEB_SERVICE']['BURN_FILE'], 'w') as f: - f.write(str(download_burnlist(CONFIG))) + if LOCAL_CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED']: + with open(CONFIG['WEB_SERVICE']['BURN_FILE'], 'w') as f: + f.write(str(download_burnlist(CONFIG))) print(CONFIG['SYSTEMS']) reactor.run() diff --git a/config.py b/config.py index 9a0f665..040821f 100755 --- a/config.py +++ b/config.py @@ -68,6 +68,9 @@ def acl_build(_acl, _max): return(True, set((const.ID_MIN, _max))) acl = [] #set() + print(type(_acl)) + if type(_acl) == tuple: + _acl = ''.join(_acl) sections = _acl.split(':') if sections[0] == 'PERMIT': diff --git a/data_gateway.py b/data_gateway.py index 94c13e3..91a787c 100644 --- a/data_gateway.py +++ b/data_gateway.py @@ -65,6 +65,11 @@ import codecs #Needed for working with NMEA import pynmea2 +# Used with HTTP POST +from hashlib import sha256 +import json, requests + + # Modules for executing commands/scripts import os ##from gps_functions import cmd_list @@ -200,7 +205,7 @@ def aprs_send(packet): AIS.sendall(packet) logger.info('Packet sent to APRS-IS.') -def dashboard_loc_write(call, lat, lon, time, comment): +def dashboard_loc_write(call, lat, lon, time, comment, dmr_id): if CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED'] == True: send_dash_loc(CONFIG, call, lat, lon, time, comment, dmr_id) else: @@ -543,7 +548,7 @@ def process_sms(_rf_src, sms, call_type): try: aprslib.parse(aprs_loc_packet) aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time(), comment) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time(), comment, int_id(_rf_src)) #logger.info('Sent manual position to APRS') except Exception as error_exception: logger.info('Exception. Not uploaded') @@ -1054,7 +1059,7 @@ def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _fr float(lon_deg) < 121 if int_id(_dst_id) == data_id: aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time(), comment) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time(), comment, int_id(_rf_src)) #logger.info('Sent APRS packet') except Exception as error_exception: logger.info('Error. Failed to send packet. Packet may be malformed.') @@ -1157,7 +1162,7 @@ def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _fr float(loc.lon) if int_id(_dst_id) == data_id: aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time(), comment) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time(), comment, int_id(_rf_src)) except Exception as error_exception: logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.') logger.info(error_exception) @@ -1268,6 +1273,7 @@ class OBP(OPENBRIDGE): def svrd_received(self, _mode, _data): print('SVRD RCV') + print(_mode) if _mode == b'UNIT': UNIT_MAP[_data] = (self._system, time()) print(UNIT_MAP) diff --git a/hblink.py b/hblink.py index 47d4a0b..55a3ba3 100755 --- a/hblink.py +++ b/hblink.py @@ -159,7 +159,7 @@ class OPENBRIDGE(DatagramProtocol): logger.info('(%s) is mode OPENBRIDGE. No De-Registration required, continuing shutdown', self._system) def send_system(self, _packet): - if _packet[:4] == DMRD or _packet[:4] == EOBP or _packet[:4] == b'NOCK': + if _packet[:4] == DMRD or _packet[:4] == EOBP: #_packet = _packet[:11] + self._config['NETWORK_ID'] + _packet[15:] _packet = b''.join([_packet[:11], self._config['NETWORK_ID'], _packet[15:]]) #_packet += hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest() @@ -200,6 +200,7 @@ class OPENBRIDGE(DatagramProtocol): _data = _packet[:53] _hash = _packet[53:] _ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() + if compare_digest(_hash, _ckhs) and _sockaddr == self._config['TARGET_SOCK']: _peer_id = _data[11:15] diff --git a/web/app.py b/web/app.py index 91ef244..48e84e4 100644 --- a/web/app.py +++ b/web/app.py @@ -103,6 +103,12 @@ def convert_nato(string): ns = ns + c + ' ' return ns +# Convert APRS to map coordinates +def aprs_to_latlon(x): + degrees = int(x) // 100 + minutes = x - 100*degrees + return degrees + minutes/60 + # Class-based application configuration class ConfigClass(object): from config import MAIL_SERVER, MAIL_PORT, MAIL_USE_SSL, MAIL_USE_TLS, MAIL_USERNAME, MAIL_PASSWORD, MAIL_DEFAULT_SENDER, USER_ENABLE_EMAIL, USER_ENABLE_USERNAME, USER_REQUIRE_RETYPE_PASSWORD, USER_ENABLE_CHANGE_USERNAME, USER_ENABLE_MULTIPLE_EMAILS, USER_ENABLE_CONFIRM_EMAIL, USER_ENABLE_REGISTER, USER_AUTO_LOGIN_AFTER_CONFIRM, USER_SHOW_USERNAME_DOES_NOT_EXIST @@ -712,8 +718,43 @@ def create_app(): @app.route('/map') @login_required def map_page(): - print(peer_locations) + dev_loc = GPS_LocLog.query.order_by(GPS_LocLog.time.desc()).limit(300).all() + dev_list = [] f_map = folium.Map(location=center_map, zoom_start=map_zoom) + for i in dev_loc: + if i.callsign in dev_list: + pass + elif i.callsign not in dev_list: + dev_list.append(i.callsign) + lat = i.lat + lon = i.lon + if 'S' in i.lat: + lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', i.lat))) + lat = -lat + if 'S' not in i.lat: + lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', i.lat))) + if 'W' in i.lon: + lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', i.lon))) + lon = -lon + if 'W' not in i.lon: + lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', i.lon))) + folium.Marker([lat, lon], popup=""" + + + + + + + + + + + """ + i.comment + """ + + +
Last Location:
"""+ str(i.callsign) +"""
"""+ str(i.time) +"""
+
+ """, icon=folium.Icon(color="blue", icon="record"), tooltip='' + i.callsign + '').add_to(f_map) for l in peer_locations.items(): ## folium.Marker([float(l[1][1]), float(l[1][2])], popup=''' ##
@@ -2420,18 +2461,18 @@ TG #: ''' + str(tg_d.tg) + ''' db.session.add(burn_list) db.session.commit() - def dash_loc_add(_call, _lat, _lon, _time, _comment, _dmr_id, _server): + def dash_loc_add(_call, _lat, _lon, _comment, _dmr_id, _server): add_loc = GPS_LocLog( - callsign = _callsign, + callsign = _call, lat = _lat, lon = _lon, - time = _time, + time = datetime.datetime.utcnow(), comment = _comment, dmr_id = _dmr_id, server = _server, system_name = '' ) - db.session.add(add_bridge) + db.session.add(add_loc) db.session.commit() def update_burnlist(_dmr_id, _version): @@ -5774,6 +5815,27 @@ TG #: ''' + str(tg_d.tg) + ''' return render_template('flask_user_layout.html', markup_content = Markup(content)) + + @app.route('/aprs') + def data_dash(): + +## dev_loc = GPS_LocLog.query.order_by(time).limit(3).all() + dev_loc = GPS_LocLog.query.order_by(GPS_LocLog.time.desc()).limit(3).all() + content = '' + for i in dev_loc: + print(i.callsign) + content = content + ''' + + ''' + i.callsign + ''' +  ''' + i.lat + '''  +  ''' + i.lon + '''  +  ''' + str(i.time) + '''  + +''' +## content = dev_loc + + return render_template('aprs_page.html', markup_content = Markup(content)) + @app.route('/svr', methods=['POST']) def auth(): hblink_req = request.json @@ -5866,7 +5928,8 @@ TG #: ''' + str(tg_d.tg) + ''' elif 'dashboard' in hblink_req: if 'lat' in hblink_req: # Assuming this is a GPS loc - dash_loc_add(hblink_req['call'], hblink_req['lat'], hblink_req['lon'], time(), hblink_req['comment'], hblink_req['dmr_id'], hblink_req['dashboard']) + dash_loc_add(hblink_req['call'], hblink_req['lat'], hblink_req['lon'], hblink_req['comment'], hblink_req['dmr_id'], hblink_req['dashboard']) + response = 'yes' diff --git a/web/templates/aprs_page.html b/web/templates/aprs_page.html new file mode 100644 index 0000000..2d2ba10 --- /dev/null +++ b/web/templates/aprs_page.html @@ -0,0 +1,31 @@ +{% extends 'flask_user/_public_base.html' %} +{% block content %} + +

 

+
+
+

Last Known Location

+ + + + + + + + + {{markup_content}} + +
+

 Callsign 

+
+

 Latitude 

+
+

 Longitude 

+
+

 Time 

+
+
+
+ +

 

+{% endblock %} diff --git a/web/templates/flask_user_layout.html b/web/templates/flask_user_layout.html index d41410b..db91d37 100644 --- a/web/templates/flask_user_layout.html +++ b/web/templates/flask_user_layout.html @@ -39,6 +39,7 @@ @@ -130,7 +131,7 @@

{% endblock %}