diff --git a/web/app.py b/web/app.py index 6a9fe2e..ce1c81f 100644 --- a/web/app.py +++ b/web/app.py @@ -42,10 +42,7 @@ from socket import gethostbyname import re import folium -try: - from gen_script_template import gen_script -except: - pass +from gen_script_template import gen_script import os, ast ##import hb_config @@ -702,7 +699,7 @@ def create_app(): @app.route('/map') @login_required def map_page(): - f_map = folium.Map(location=[45.372, -121.6972], zoom_start=7) + f_map = folium.Map(location=center_map, zoom_start=map_zoom) ## 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=''' @@ -723,7 +720,7 @@ def create_app(): ''', 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)) + return render_template('map.html', markup_content = Markup(content)) @app.route('/help') def help_page(): @@ -734,50 +731,30 @@ def create_app(): def gen_pi_star(): try: u = current_user - ## print(u.username) id_dict = ast.literal_eval(u.dmr_ids) #u = User.query.filter_by(username=user).first() - ## print(user_id) ## print(request.args.get('mode')) ## if request.args.get('mode') == 'generated': - content = ''' - - - - - - -
-

Pi-Star Instructions

-

 

-

1: Log into your Pi-Star device.
2: Change to Read-Write mode of the device by issuing the command:

-
rpi-rw
-


3a: Change to the root user by issuing the command:

-
sudo su -
-


3b: Now type pwd and verify you get a return indicating you are in the /root directory. If you are in the wrong directory, it is because you're not following the instructions and syntax above! This is a show stopper, and your attempt to load the files correctly, will fail !

4: Issue one of the commands below for the chosen DMR ID:

-

Note: Link can be used only once. To run the script again, simply reload the page and paste a new command into the command line.

- -''' + content = '' for i in id_dict.items(): #if i[1] == '': link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8) script_links[i[0]] = link_num - content = content + '''\n -

DMR ID: ''' + str(i[0]) + ''':

-

bash <(curl -s "''' + str(url) + '/get_script?dmr_id=' + str(i[0]) + '&number=' + str(link_num) + '''")

-

 

+ content = content + ''' +
+

ID: ''' + str(i[0]) + '''

+
rpi-rw; wget -O /root/auto_pistar.py "''' + str(url) + '/get_script?dmr_id=' + str(i[0]) + '&number=' + str(link_num) + '''"; chmod +x /root/auto_pistar.py; python3 /root/auto_pistar.py; pistar-update
+
''' #else: # content = content + '''\n

Error

''' - content = content + '''\n


5: When asked for server ports, use the information above to populate the correct fields.
6: Reboot your Pi-Star device

-
-

 

''' + except: content = Markup('No DMR IDs found or other error.') #return str(content) - return render_template('flask_user_layout.html', markup_content = Markup(content)) + return render_template('pi-star_gen.html', markup_content = Markup(content)) @@ -829,16 +806,11 @@ def create_app(): ''' try: - #content = Markup('The HTML String') #user_id = request.args.get('user_id') u = current_user - ## print(u.username) id_dict = ast.literal_eval(u.dmr_ids) #u = User.query.filter_by(username=user).first() - ## print(user_id) - ## print(request.args.get('mode')) ## if request.args.get('mode') == 'generated': - #print(id_dict) content = '\n' for i in id_dict.items(): @@ -1342,6 +1314,11 @@ def create_app(): number = float(request.args.get('number')) #print(type(script_links[dmr_id])) u = User.query.filter(User.dmr_ids.contains(request.args.get('dmr_id'))).first() + + pub_list = [] + + + #print(u.dmr_ids) if authorized_peer(dmr_id)[1] == 0: @@ -1350,13 +1327,29 @@ def create_app(): passphrase = gen_passphrase(dmr_id) elif authorized_peer(dmr_id)[1] == '': passphrase = legacy_passphrase - print(passphrase) elif authorized_peer(dmr_id)[1] != '' or authorized_peer(dmr_id)[1] != 0: passphrase = authorized_peer(dmr_id)[1] #try: if dmr_id in script_links and number == float(script_links[dmr_id]): script_links.pop(dmr_id) - return str(gen_script(dmr_id, passphrase)) + + ml = MasterList.query.filter_by(public_list=True).filter_by(active=True).all() + pl = ProxyList.query.filter_by(public_list=True).filter_by(active=True).all() +## print(ml) + for m in ml: +## print(m.name) +## print(m.server) +## print(m.port) +## print(m.enable_um) +## print(m.passphrase) + sl = ServerList.query.filter_by(name=m.server).first() +## print(sl.ip) + if m.enable_um == True: + passp = passphrase + pub_list.append([m.server + '_' + m.name, sl.ip, passphrase, m.port]) + + + return str(gen_script(dmr_id, pub_list)) #except: #else: #content = 'Link used or other error.' @@ -2196,8 +2189,8 @@ TG #: ''' + str(tg_d.tg) + '''  

Server: ''' + svr.name + '''  -  IP/Host: ''' + str(svr.ip) + '''

''' - m_list = MasterList.query.filter_by(server=server).filter_by(public_list=True).all() - p_list = ProxyList.query.filter_by(server=server).filter_by(public_list=True).all() + m_list = MasterList.query.filter_by(server=server).filter_by(active=True).filter_by(public_list=True).all() + p_list = ProxyList.query.filter_by(server=server).filter_by(active=True).filter_by(public_list=True).all() tg_list = '' for m in m_list: br = BridgeRules.query.filter_by(server=server).filter_by(system_name=m.name).all() @@ -5691,98 +5684,100 @@ TG #: ''' + str(tg_d.tg) + ''' ## except: ## message = jsonify(message='Config error') ## response = make_response(message, 401) - elif 'update_tg' in hblink_req: - if hblink_req['update_tg']: - print(hblink_req) -## print(hblink_req['data'][0]['SYSTEM']) - if 'on' == hblink_req['mode']: -## try: - if hblink_req['dmr_id'] == 0: - print('id 0') -## print(active_tgs) - for system in active_tgs[hblink_req['update_tg']].items(): - ## print(system) - ## print('sys') - if system[0] == hblink_req['data'][0]['SYSTEM']: - print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1']) -## print(hblink_req['data'][2]['tg']) - print('---------') - print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']) - ## print(hblink_req['data'][1]['ts']) - if hblink_req['data'][1]['ts'] == 1: - #### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1']) - if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'] == hblink_req['data'][2]['tg']: - pass - else: - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][2]['tg']) - #### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0) - if hblink_req['data'][1]['ts'] == 2: - if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'] == hblink_req['data'][2]['tg']: - pass - #### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2']) - else: - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['tg']) - else: - try: - print('---------on------------') - print(hblink_req['data']) - print(active_tgs[hblink_req['update_tg']]) - print(hblink_req['data'][2]['ts2']) - print('-----------------------') - ## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM'] - #### active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']].update({hblink_req['data'][0]['SYSTEM']: [{1:[hblink_req['data'][1]['ts1']]}, {2:[hblink_req['data'][2]['ts2']]}]}) #.update({[hblink_req['dmr_id']]:hblink_req['data']}) - if hblink_req['data'][1]['ts1'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1']: - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][1]['ts1']) - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM'] - if hblink_req['data'][2]['ts2'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']: - print('---0---') - print(hblink_req['data'][0]['SYSTEM']) - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM'] - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['ts2']) -## print('append') - #### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0) - ## print(hblink_req['data'][0]['SYSTEM']) - - ## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']]) - ## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['2']) - ## print(hblink_req['data'][1]['ts2']) - ## print(active_tgs[hblink_req['update_tg']]) - except: -## active_tgs[hblink_req['update_tg']] = {} - pass - -## except: -## pass - - - elif 'off' == hblink_req['mode']: - print('off') - for system in active_tgs[hblink_req['update_tg']].items(): - print(system) - if system[0] == hblink_req['data'][0]['SYSTEM']: - print('yes it is') -#### print(system[0]) -#### print(active_tgs[hblink_req['update_tg']][system[0]]) - if hblink_req['data'][1]['ts'] == 1: -#### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1']) - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].remove(hblink_req['data'][2]['tg']) -#### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0) - if hblink_req['data'][1]['ts'] == 2: -#### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2']) - active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].remove(hblink_req['data'][2]['tg']) -#### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0) - - - -## print() -## print(system) -## print(system[1][2]['SYSTEM']) +#################### Work in progress ###########################33 +## elif 'update_tg' in hblink_req: +## if hblink_req['update_tg']: +## print(hblink_req) +#### print(hblink_req['data'][0]['SYSTEM']) +## if 'on' == hblink_req['mode']: +#### try: +## if hblink_req['dmr_id'] == 0: +## print('id 0') +#### print(active_tgs) +## for system in active_tgs[hblink_req['update_tg']].items(): +## ## print(system) +## ## print('sys') +## if system[0] == hblink_req['data'][0]['SYSTEM']: +## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1']) +#### print(hblink_req['data'][2]['tg']) +## print('---------') +## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']) +## ## print(hblink_req['data'][1]['ts']) +## if hblink_req['data'][1]['ts'] == 1: +## #### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1']) +## +## if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'] == hblink_req['data'][2]['tg']: +## pass +## else: +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][2]['tg']) +## #### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0) +## if hblink_req['data'][1]['ts'] == 2: +## if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'] == hblink_req['data'][2]['tg']: +## pass +## #### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2']) +## else: +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['tg']) +## else: +## try: +## print('---------on------------') +## print(hblink_req['data']) +## print(active_tgs[hblink_req['update_tg']]) +## print(hblink_req['data'][2]['ts2']) +## print('-----------------------') +## ## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM'] +## #### active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']].update({hblink_req['data'][0]['SYSTEM']: [{1:[hblink_req['data'][1]['ts1']]}, {2:[hblink_req['data'][2]['ts2']]}]}) #.update({[hblink_req['dmr_id']]:hblink_req['data']}) +## if hblink_req['data'][1]['ts1'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1']: +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][1]['ts1']) +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM'] +## if hblink_req['data'][2]['ts2'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']: +## print('---0---') +## print(hblink_req['data'][0]['SYSTEM']) +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM'] +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['ts2']) +#### print('append') +## #### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0) +## ## print(hblink_req['data'][0]['SYSTEM']) +## +## ## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']]) +## ## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['2']) +## ## print(hblink_req['data'][1]['ts2']) +## ## print(active_tgs[hblink_req['update_tg']]) +## except: +#### active_tgs[hblink_req['update_tg']] = {} +## pass +## +#### except: +#### pass +## +## +## elif 'off' == hblink_req['mode']: ## print('off') -## print(hblink_req['data'][1]['ts']) -## print(hblink_req['data'][2]['tg']) - print(active_tgs) - response = 'got it' +## for system in active_tgs[hblink_req['update_tg']].items(): +## print(system) +## if system[0] == hblink_req['data'][0]['SYSTEM']: +## print('yes it is') +###### print(system[0]) +###### print(active_tgs[hblink_req['update_tg']][system[0]]) +## if hblink_req['data'][1]['ts'] == 1: +###### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1']) +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].remove(hblink_req['data'][2]['tg']) +###### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0) +## if hblink_req['data'][1]['ts'] == 2: +###### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2']) +## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].remove(hblink_req['data'][2]['tg']) +###### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0) +## +## +## +#### print() +#### print(system) +#### print(system[1][2]['SYSTEM']) +#### print('off') +#### print(hblink_req['data'][1]['ts']) +#### print(hblink_req['data'][2]['tg']) +## print(active_tgs) +## response = 'got it' else: message = jsonify(message='Authentication error') response = make_response(message, 401) diff --git a/web/config-SAMPLE.py b/web/config-SAMPLE.py index 4813004..59e4807 100644 --- a/web/config-SAMPLE.py +++ b/web/config-SAMPLE.py @@ -29,8 +29,12 @@ secret_key = 'SUPER SECRET LONG KEY' default_account_state = True # Legacy passphrase used in hblink.cfg -#legacy_passphrase = 'passw0rd' +legacy_passphrase = 'passw0rd' +# Coordinates to center map over +center_map = [45.372, -121.6972] +# Default map zoom level +map_zoom = 5 # Passphrase calculation config. If REMOTE_CONFIG is not used in your DMR server config # (hblink.cfg), then the values in section [USER_MANAGER] MUST match the values below. diff --git a/web/gen_script_template.py b/web/gen_script_template.py new file mode 100644 index 0000000..ef96ad5 --- /dev/null +++ b/web/gen_script_template.py @@ -0,0 +1,43 @@ +# Function to generate a script for Pi-Star that adds MASTER instances and generated passphrases to DMR_Hosts.txt. + +def gen_script(dmr_id, svr_lst): + auth_contents = '' + header = ''' +## DMR_hosts.txt, generated by HBNet. + +######################################################################################################## +### Name DMR-ID IP/Hostname Password Port # +######################################################################################################## +\n''' + for i in svr_lst: +## print(i[1]) + auth_contents = auth_contents + str(i[0]) + '''\t\t\t\t''' + str(dmr_id) + '''\t''' + i[1] + '''\t\t\t\t''' + i[2] + '''\t\t''' + str(i[3]) + '\n' +## print(header) +## print(auth_contents) + + +## return header + auth_contents + + output = ''' +#!/usr/bin/python3 + +import os +from pathlib import Path + +os.chdir('/root') +if Path('/root/DMR_Hosts.txt').is_file(): + print('DMR_Hosts.txt exists, adding entries...') + with open('/root/DMR_Hosts.txt', 'a') as dmr_hosts: + dmr_hosts.write("""''' + auth_contents + '''""") + dmr_hosts.close() + +else: + Path('/root/DMR_Hosts.txt').touch() + print('DMR_Hosts.txt does not exist, creating...') + with open('/root/DMR_Hosts.txt', 'w') as dmr_hosts: + dmr_hosts.write("""''' + header + auth_contents + '""")' + ''' + dmr_hosts.close() +print('DMR Host file updates.')''' + print(output) + return output + diff --git a/web/templates/flask_user_layout.html b/web/templates/flask_user_layout.html index 2a07987..d41410b 100644 --- a/web/templates/flask_user_layout.html +++ b/web/templates/flask_user_layout.html @@ -37,10 +37,10 @@ {{ user_manager.USER_APP_NAME }}