modify template, finalize GPS location logging, initial commit of APRS dashboard, combine peer locations and APRS into single map

This commit is contained in:
KF7EEL 2021-09-20 09:33:21 -07:00
parent 2f8350ecc0
commit 4e98ed8513
7 changed files with 121 additions and 14 deletions

View File

@ -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()

View File

@ -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':

View File

@ -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)

View File

@ -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]

View File

@ -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>
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;">Last Location:</td>
</tr>
<tr>
<td style="text-align: center;"><strong>"""+ str(i.callsign) +"""</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>"""+ str(i.time) +"""</em></td>
""" + i.comment + """
</tr>
</tbody>
</table>
</i>
""", icon=folium.Icon(color="blue", icon="record"), tooltip='<strong>' + i.callsign + '</strong>').add_to(f_map)
for l in peer_locations.items():
## folium.Marker([float(l[1][1]), float(l[1][2])], popup='''
##<div class="panel panel-default">
@ -2420,18 +2461,18 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
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 #: <strong> ''' + str(tg_d.tg) + '''</strong>
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 + '''
<tr>
<td style="text-align: center;"><a href="https://hbnet.xyz"target="_blank"><strong>''' + i.callsign + '''</strong></a></td>
<td style="text-align: center;"><strong>&nbsp;''' + i.lat + '''&nbsp;</strong></td>
<td style="text-align: center;"><strong>&nbsp;''' + i.lon + '''&nbsp;</strong></td>
<td style="text-align: center;">&nbsp;''' + str(i.time) + '''&nbsp;</td>
</tr>
'''
## 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 #: <strong> ''' + str(tg_d.tg) + '''</strong>
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'

View File

@ -0,0 +1,31 @@
{% extends 'flask_user/_public_base.html' %}
{% block content %}
<p>&nbsp;</p>
<div class="row container-fluid" >
<div class="col-sm-12">
<h1 style="text-align: center;">Last Known Location</h1>
<table style="border-color: black; margin-left: auto; margin-right: auto;" border="2" cellspacing="6" cellpadding="2"><tbody>
<tr>
<td style="text-align: center;">
<h2><strong>&nbsp;Callsign&nbsp;</strong></h2>
</td>
<td style="text-align: center;">
<h2>&nbsp;<strong>Latitude</strong>&nbsp; </h2>
</td>
<td style="text-align: center;">
<h2>&nbsp;<strong>Longitude</strong>&nbsp;</h2>
</td>
<td style="text-align: center;">
<h2>&nbsp;<strong>Time</strong>&nbsp;</h2>
</td>
</tr>
{{markup_content}}
</tbody>
</table>
</div>
</div>
<p>&nbsp;</p>
{% endblock %}

View File

@ -39,6 +39,7 @@
<ul class="nav navbar-nav">
<li><a href="/"><span class="glyphicon glyphicon-home"></span> Home</a></li>
<li><a href="{{url}}/talkgroups"><span class="glyphicon glyphicon-list"></span> Talkgroups</a></li>
<li><a href="{{url}}/aprs"><span class="glyphicon glyphicon-list"></span> APRS</a></li>
<li><a href="{{url}}/news"><span class="glyphicon glyphicon-list-alt"></span> News</a></li>
<li><a href="{{url}}/help"><span class="glyphicon glyphicon-question-sign"></span> Help</a></li>
</ul>
@ -130,7 +131,7 @@
<br/>
<hr class="no-margins"/>
<div id="footer-div" class="clearfix with-margins">
<p style="text-align: center;"><strong>{{ user_manager.USER_APP_NAME }}<br /></strong><a href="https://hbnet.xyz">HBNet Project</a><br />Created by KF7EEL<br />Contributors:&nbsp; W7NCX</p>
<p style="text-align: center;"><strong>{{ user_manager.USER_APP_NAME }}<br /></strong><a href="https://hbnet.xyz">HBNet Project</a><br /></p>
</div>
{% endblock %}