initial commit of map

This commit is contained in:
KF7EEL 2021-08-07 16:15:32 -07:00
parent af345335b7
commit 5b290bf1b8
3 changed files with 66 additions and 6 deletions

View File

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

View File

@ -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='''
<div class="panel panel-default">
<div class="panel-heading" style="text-align: center;"><h4>''' + l[1][0] + '''</h4></div>
<div class="panel-body">
''' + l[1][5] + '''
<hr />
''' + l[1][1] + ''', ''' + l[1][2] + '''
<hr />
''' + l[1][3] + '''
<hr />
''' + l[1][4] + '''
<hr />
''' + l[1][6] + '''
</div>
</div>
''', icon=folium.Icon(color="red", icon="record"), tooltip='<strong>' + l[1][0] + '</strong>').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 #: <strong> ''' + str(tg_d.tg) + '''</strong>
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 #: <strong> ''' + str(tg_d.tg) + '''</strong>
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 #: <strong> ''' + str(tg_d.tg) + '''</strong>
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']:

View File

@ -48,6 +48,7 @@
<li><a href="{{ url_for('user.register') }}"><span class="glyphicon glyphicon-user"></span> Register</a></li>
{% endif %}
{% if call_or_get(current_user.is_authenticated) %}
<li><a href="{{url}}/map"><span class="glyphicon glyphicon-map-marker"></span> Map</a></li>
<li><a href="{{url}}/generate_passphrase"><span class="glyphicon glyphicon-lock"></span> Passphrase(s)</a></li>
<li><a href="{{ url_for('user.edit_user_profile') }}"><span class="glyphicon glyphicon-user"></span> Edit {{ current_user.username or current_user.email }}</a></li>
<li><a href="{{ url_for('user.logout') }}"><span class="glyphicon glyphicon-remove"></span> Sign Out</a></li>
@ -77,7 +78,6 @@
<li><a href="{{url}}/add_user">Add User</a></li>
<li><a href="{{url}}/list_users">Manage Users</a></li>
<li><a href="{{url}}/approve_users">Waiting Approval</a></li>
<li><a href="{{url}}/auth_log">Authorization Log</a></li>
</ul>
</li>
<li class="dropdown">
@ -86,6 +86,7 @@
<ul class="dropdown-menu">
<li><a href="{{url}}/manage_news">Manage News</a></li>
<li><a href="{{url}}/misc_settings">Misc Options</a></li>
<li><a href="{{url}}/auth_log">Authorization Log</a></li>
</ul>
</li>