diff --git a/hblink.py b/hblink.py index b1963cc..af96be6 100755 --- a/hblink.py +++ b/hblink.py @@ -61,6 +61,7 @@ import os, ast import requests, json import base64 import libscrc +import re # Does anybody read this stuff? There's a PEP somewhere that says I should do this. @@ -289,6 +290,7 @@ class HBSYSTEM(DatagramProtocol): 'login_confirmed': True, 'old_auth': old_auth } +## print(auth_conf) json_object = json.dumps(auth_conf, indent = 4) try: req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'}) @@ -296,6 +298,30 @@ class HBSYSTEM(DatagramProtocol): #return resp except Exception as e: logger.info(e) + + def send_peer_loc(self, _id, call, lat, lon, url, description, loc, soft): + #Change this to a config value + user_man_url = self._CONFIG['USER_MANAGER']['URL'] + shared_secret = str(sha256(self._CONFIG['USER_MANAGER']['SHARED_SECRET'].encode()).hexdigest()) + peer_loc_conf = { + 'secret':shared_secret, + 'loc_callsign':re.sub("b'|'|\s\s+", '', str(call)), + 'dmr_id' : int(str(int_id(_id))), + 'lat': re.sub("b'|'|\s\s\s+", '', str(lat)), + 'lon': re.sub("b'|'|\s\s\s+", '', str(lon)), + 'url': re.sub("b'|'|\s\s\s+", '', str(url)), + 'description': re.sub("b'|'|\s\s+", '', str(description)), + 'loc' : re.sub("b'|'|\s\s+", '', str(loc)), + 'software': re.sub("b'|'|\s\s+", '', str(soft)) + } + json_object = json.dumps(peer_loc_conf, indent = 4) + print(json_object) + try: + req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'}) + # resp = json.loads(req.text) + #return resp + except Exception as e: + logger.info(e) def calc_passphrase(self, peer_id, _salt_str): burn_id = ast.literal_eval(os.popen('cat ' + self._CONFIG['USER_MANAGER']['BURN_FILE']).read()) @@ -340,7 +366,7 @@ class HBSYSTEM(DatagramProtocol): if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False: pass _calc_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest()) - print(calc_passphrase) +## print(calc_passphrase) # print(_calc_hash) return _calc_hash @@ -652,6 +678,7 @@ class HBSYSTEM(DatagramProtocol): self.send_peer(_peer_id, b''.join([RPTACK, _peer_id])) logger.info('(%s) Peer %s (%s) has sent repeater configuration', self._system, _this_peer['CALLSIGN'], _this_peer['RADIO_ID']) + self.send_peer_loc(_peer_id, _this_peer['CALLSIGN'], _this_peer['LATITUDE'], _this_peer['LONGITUDE'], _this_peer['URL'], _this_peer['DESCRIPTION'], _this_peer['LOCATION'], _this_peer['SOFTWARE_ID']) else: self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) logger.warning('(%s) Peer info from Radio ID that has not logged in: %s', self._system, int_id(_peer_id)) diff --git a/web/app.py b/web/app.py index 912ee7e..8f72371 100644 --- a/web/app.py +++ b/web/app.py @@ -40,7 +40,7 @@ import random from flask_mail import Message, Mail from socket import gethostbyname import re - +import folium try: from gen_script_template import gen_script @@ -53,6 +53,7 @@ import os, ast script_links = {} active_tgs = {} ping_list = {} +peer_locations = {} # Query radioid.net for list of IDs def get_ids(callsign): @@ -697,6 +698,32 @@ def create_app(): content = tos_text.field_2 return render_template('flask_user_layout.html', markup_content = Markup(content)) + + @app.route('/map') + @login_required + def map_page(): + f_map = folium.Map(location=[45.372, -121.6972], zoom_start=7) +## folium.Marker([45.372, -121.6972], popup="hello", icon=folium.Icon(color="red", icon="record"), tooltip='hi').add_to(f_map) + for l in peer_locations.items(): + folium.Marker([float(l[1][1]), float(l[1][2])], popup=''' +
+

''' + l[1][0] + '''

+
+ ''' + l[1][5] + ''' +
+ ''' + l[1][1] + ''', ''' + l[1][2] + ''' +
+ ''' + l[1][3] + ''' +
+ ''' + l[1][4] + ''' +
+ ''' + l[1][6] + ''' +
+
+ ''', icon=folium.Icon(color="red", icon="record"), tooltip='' + l[1][0] + '').add_to(f_map) + content = f_map._repr_html_() + + return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/help') def help_page(): @@ -5555,13 +5582,14 @@ TG #: ''' + str(tg_d.tg) + ''' try: if hblink_req['ping']: ping_list[hblink_req['ping']] = time.time() + print(peer_locations) response = '' except: pass if 'login_id' in hblink_req and 'login_confirmed' not in hblink_req: if type(hblink_req['login_id']) == int: if authorized_peer(hblink_req['login_id'])[0]: - print(active_tgs) +## print(active_tgs) if isinstance(authorized_peer(hblink_req['login_id'])[1], int) == True: authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], gen_passphrase(hblink_req['login_id']), 'Attempt') ## active_tgs[hblink_req['login_server']][hblink_req['system']] = [{'1':[]}, {'2':[]}, {'SYSTEM': ''}, {'peer_id':hblink_req['login_id']}] @@ -5617,11 +5645,12 @@ TG #: ''' + str(tg_d.tg) + ''' msg = jsonify(auth=False, reason='Incorrect password') response = make_response(msg, 401) + elif 'login_id' in hblink_req and 'login_confirmed' in hblink_req: if hblink_req['old_auth'] == True: authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], 'CONFIG, NO UMS', 'Confirmed') - else: - authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], 'USER MANAGER', 'Confirmed') + #else: + # authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], 'USER MANAGER', 'Confirmed') response = jsonify( logged=True ) @@ -5629,6 +5658,9 @@ TG #: ''' + str(tg_d.tg) + ''' response = jsonify( burn_list=get_burnlist() ) + elif 'loc_callsign' in hblink_req: + peer_locations[hblink_req['dmr_id']] = [hblink_req['loc_callsign'], hblink_req['lat'], hblink_req['lon'], hblink_req['url'], hblink_req['description'], hblink_req['loc'], hblink_req['software']] + response = '' elif 'get_config' in hblink_req: if hblink_req['get_config']: diff --git a/web/templates/flask_user_layout.html b/web/templates/flask_user_layout.html index 93fda1e..2a07987 100644 --- a/web/templates/flask_user_layout.html +++ b/web/templates/flask_user_layout.html @@ -48,6 +48,7 @@
  • Register
  • {% endif %} {% if call_or_get(current_user.is_authenticated) %} +
  • Map
  • Passphrase(s)
  • Edit {{ current_user.username or current_user.email }}
  • Sign Out
  • @@ -77,7 +78,6 @@
  • Add User
  • Manage Users
  • Waiting Approval
  • -
  • Authorization Log