# HBNet Web Server
###############################################################################
# HBNet Web Server - Copyright (C) 2020 Eric Craw, KF7EEL 1: Log into your Pi-Star device. 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. DMR ID: ''' + str(i[0]) + ''': Error Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + str(gen_passphrase(int(i[0]))) + ''' Phonetically spelled: ''' + convert_nato(str(gen_passphrase(int(i[0])))) + ''' Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + str(gen_passphrase(int(i[0]))) + ''' Phonetically spelled: ''' + convert_nato(str(gen_passphrase(int(i[0])))) + ''' Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + legacy_passphrase + ''' Phonetically spelled: ''' + convert_nato(legacy_passphrase) + ''' Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + str(i[1]) + ''' Phonetically spelled: ''' + convert_nato(str(i[1])) + ''' Use this page to sync changes from RadioID.net with this system (such as a new DMR ID, name change, etc.). Updating your information from RadioID.net will overwrite any custom authentication passphrases, your city, and name in the database. Are you sure you want to continue? Sent email to: ' + u.email + ' Find user in "List Users", then click on the email link.' User ''' + str(user) + ''' has been enabled. User ''' + str(user) + ''' has been disabled. User ''' + str(user) + ''' changed to ''' + request.form.get('username') + '''. Changed email for user: ''' + str(user) + ''' to ''' + request.form.get('email') + ''' Changed notes for user: ''' + str(user) + '''. Changed password for user: ''' + str(user) + ''' Changed authentication settings for user: ''' + str(user) + ''' Deleted user: ''' + str(delete_user.username) + ''' User now Admin: ''' + str(request.args.get('callsign')) + ''' Admin now a user: ''' + str(request.args.get('callsign') ) + ''' User approved: ''' + str(request.args.get('callsign')) + ''' Email verified for: ''' + str(request.args.get('callsign')) + ''' Verify email - ''' + str(u.username) + ''' Give Admin role: ''' + str(u.username) + ''' Revert to User role: ''' + str(u.username) + ''' Email confirmed: ''' + str(u.email_confirmed_at) + ''' {DMR ID: Method, 2nd DMR ID: Method} Example: Flushed entire auth DB. Flushed auth DB for: ''' + request.args.get('portal_username') + ''' Flushed auth DB for: ''' + request.args.get('mmdvm_server') + ''' Flushed auth DB for: ''' + request.args.get('peer_ip') + ''' Flushed auth DB for: ''' + request.args.get('dmr_id') + ''' Flush auth log for: ''' + request.args.get('portal_username') + ''' Flush auth log for: ''' + request.args.get('dmr_id') + ''' Log for: ''' + g_arg + ''' Flush authentication log for server: ''' + request.args.get('mmdvm_server') + ''' Log for MMDVM server: ''' + request.args.get('mmdvm_server') + ''' Flush authentication log for IP: ''' + request.args.get('peer_ip') + ''' Log for IP address: ''' + request.args.get('peer_ip') + ''' Flush entire authentication log Un-registered authentication attempts Authentication log by DMR ID Currently active talkgroups. Updated every 2 minutes. DMR ID: ''' + str(i[0]) + ''' Redirecting in 3 seconds. Redirecting in 3 seconds. Redirecting in 3 seconds. Redirecting in 3 seconds.
Pi-Star Instructions
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:bash <(curl -s "''' + str(url) + '/get_script?dmr_id=' + str(i[0]) + '&number=' + str(link_num) + '''")
5: When asked for server ports, use the information above to populate the correct fields.
6: Reboot your Pi-Star device
Updated your information.
'
update_from_radioid(request.args.get('callsign'))
else:
content = '''
Yes, update my information.
'''
return render_template('flask_user_layout.html', markup_content = Markup(content))
@app.route('/email_user', methods=['POST', 'GET'])
@roles_required('Admin')
@login_required # User must be authenticated
def email_user():
if request.method == 'GET' and request.args.get('callsign'):
content = '''
Send email to user: ''' + request.args.get('callsign') + '''
List/edit users:
'''
for i in u:
u_list = u_list + '''
Callsign
Name
Enabled
DMR ID:Authentication
Notes
'''+ '\n'
content = u_list + '''
''' + str(i.username) + '''
''' + str(i.first_name) + ' ' + str(i.last_name) + '''
''' + str(i.active) + '''
''' + str(i.dmr_ids) + '''
''' + str(i.notes) + '''
Users waiting for approval:
'''
for i in u:
## print(i.username)
## print(i.initial_admin_approved)
if i.initial_admin_approved == False:
wait_list = wait_list+ '''
Callsign
Name
Enabled
DMR ID:Authentication
'''+ '\n'
content = wait_list + '''
''' + str(i.username) + '''
''' + str(i.first_name) + ' ' + str(i.last_name) + '''
''' + str(i.active) + '''
''' + str(i.dmr_ids) + '''
'
content = '''
'''
for i in id_dict.items():
print(i[1])
if isinstance(i[1], int) == True:
passphrase_list = passphrase_list + '''
DMR ID
Passphrase
\n'''
if i[1] == '':
passphrase_list = passphrase_list + '''''' + str(i[0]) + '''
''' + str(gen_passphrase(int(i[0]))) + '''
\n'''
if not isinstance(i[1], int) == True and i[1] != '':
passphrase_list = passphrase_list + '''''' + str(i[0]) + '''
''' + legacy_passphrase + '''
\n'''
passphrase_list = passphrase_list + '''' + str(i[0]) + '''
''' + str(i[1]) + '''
First Name
Last Name
''' + u.first_name + '''
''' + u.last_name + '''
City
''' + u.city + '''
Options for: ''' + u.username + '''
''' + confirm_link + '''
''' + role_link + '''
Passphrase Authentication Method Key
Calculated
Legacy (config)
Custom
0 - default,
1-999 - new calculation''
'passphrase'
{1234567: '', 134568: 0, 1234569: 'passphr8s3'}
'
elif request.args.get('mmdvm_server') and not request.args.get('flush_db_mmdvm'):
a = AuthLog.query.filter_by(server_name=request.args.get('mmdvm_server')).order_by(AuthLog.login_time.desc()).all()
content = '''
\n'''
for i in a:
if i.login_type == 'Attempt':
content = content + '''
DMR ID
Portal Username
Login IP
Passphrase
Server
Time (UTC)
Login Status
'''
if i.login_type == 'Confirmed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
if i.login_type == 'Failed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
content = content + ' ''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'
elif request.args.get('peer_ip') and not request.args.get('flush_db_ip'):
a = AuthLog.query.filter_by(peer_ip=request.args.get('peer_ip')).order_by(AuthLog.login_time.desc()).all()
content = '''
\n'''
for i in a:
if i.login_type == 'Attempt':
content = content + '''
DMR ID
Portal Username
Login IP
Passphrase
Server
Time (UTC)
Login Status
'''
if i.login_type == 'Confirmed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + i.server_name + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
if i.login_type == 'Failed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + i.server_name + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
content = content + ' ''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + i.server_name + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'
else:
#a = AuthLog.query.all()
## a = AuthLog.query.order_by(AuthLog.login_time.desc()).limit(300).all()
a = AuthLog.query.order_by(AuthLog.login_time.desc()).all()
recent_list = []
## r = AuthLog.query.order_by(AuthLog.login_dmr_id.desc()).all()
content = '''
\n'''
for i in a:
if i.login_type == 'Attempt':
content = content + '''
DMR ID
Portal Username
Login IP
Passphrase
Server
Time (UTC)
Login Status
'''
if i.login_type == 'Confirmed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + i.peer_ip + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
if i.login_type == 'Failed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + i.peer_ip + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
content = content + ' ''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + i.peer_ip + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'
return render_template('flask_user_layout.html', markup_content = Markup(content))
@app.route('/user_tg')
def tg_status():
cu = current_user
u = User.query.filter_by(username=cu.username).first()
sl = ServerList.query.all()
user_ids = ast.literal_eval(u.dmr_ids)
content = '
\n'''
for i in a:
if i.login_dmr_id not in recent_list:
recent_list.append(i.login_dmr_id)
if i.login_type == 'Attempt':
content = content + '''
DMR ID
Portal Username
Login IP
Passphrase
Server
Time (UTC)
Last Login Status
'''
if i.login_type == 'Confirmed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
if i.login_type == 'Failed':
content = content + '''
''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
content = content + ' ''' + str(i.login_dmr_id) + '''
''' + i.portal_username + '''
''' + str(i.peer_ip) + '''
''' + i.login_auth_method + '''
''' + str(i.server_name) + '''
''' + str(i.login_time) + '''
''' + str(i.login_type) + '''
'''
## except:
## pass
## #TS1
## for tg in active_tgs[s.name][i[0]][1]['2']:
## content = content + '''
Server: ''' + str(s.name) + '''
Timeslot 1
''' + str(active_tgs[s.name][ts[0]][0]['1'])[1:-1] + '''
Timeslot 2
''' + str(active_tgs[s.name][ts[0]][1]['2'])[1:-1] + '''
''' + str(tg) + '''
##'''
## print(active_tgs[s.name][i[0]])
## content = active_tgs[s.name][i[0]][1]['2']
## content = 'hji'
return render_template('flask_user_layout.html', markup_content = Markup(content))
@app.route('/test')
def test_peer():
#user = User(
# username='admin3',
# email_confirmed_at=datetime.datetime.utcnow(),
# password=user_manager.hash_password('admin'),
# )
#user.roles.append(Role(name='Admin'))
#user.roles.append(Role(name='User'))
#user.add_roles('Admin')
#db.session.add(user)
#db.session.commit()
u = User.query.filter_by(username='admin').first()
#u = Role.query.all()
## u = User.query.filter(User.dmr_ids.contains('3153591')).first()
#u = User.query.all()
## #tu = User.query().all()
#### print((tu.dmr_ids))
#### #print(tu.dmr_ids)
#### return str(tu.dmr_ids) #str(get_ids('kf7eel'))
## login_passphrase = ast.literal_eval(u.dmr_ids)
## print('|' + login_passphrase[3153591] + '|')
## #print(u.dmr_ids)
## #tu.dmr_ids = 'jkgfldj'
## #db.session.commit()
## return str(u.dmr_ids)
## u = User.query.filter(User.dmr_ids.contains('3153591')).first()
## #tu = User.query.all()
## #tu = User.query().all()
#### print((tu.dmr_ids))
#### #print(tu.dmr_ids)
#### return str(tu.dmr_ids) #str(get_ids('kf7eel'))
## print(u)
## login_passphrase = ast.literal_eval(u.dmr_ids)
##
## #tu.dmr_ids = 'jkgfldj'
## #db.session.commit()
## return str([u.is_active, login_passphrase[3153591]])
#edit_user = User.query.filter(User.username == 'bob').first()
#edit_user.active = False
#db.session.commit()
#print((current_user.has_roles('Admin')))
#u.roles.append(Role(name='Admin'))
#print((current_user.has_roles('Admin')))
#db.session.commit()
#db.session.add(u)
#db.session.commit()
## admin_role = UserRoles(
## user_id=3,
## role_id=1,
## )
## user_role = UserRoles(
## user_id=3,
## role_id=2,
## )
## db.session.add(user_role)
## db.session.add(admin_role)
## db.session.commit()
#print(role)
## for i in u:
## print(i.username)
#u = User.query.filter_by(username='kf7eel').first()
#print(u.id)
#u_role = UserRoles.query.filter_by(user_id=u.id).first()
#if u_role.role_id == 2:
# print('userhasjkdhfdsejksfdahjkdhjklhjkhjkl')
## print(u.has_roles('Admin'))
#u_role.role_id = 1
#print(u)
# for i in u:
##print(i.initial_admin_approved)
#if not i.initial_admin_approved:
#print(i.username)
# print(i)
#u_role = UserRoles.query.filter_by(id=2).first().role_id
#u_role = 1
# db.session.commit()
#u_role = UserRoles.query.filter_by(id=u.id).first().role_id
#print(u_role)
#return str(u)
## if not u.active:
## flash('We come in peace', 'success')
## content = 'hello'
#add
## burn_list = BurnList(
## dmr_id=3153595,
## version=1,
## )
## db.session.add(burn_list)
## db.session.commit()
##
#generate dict
## b = BurnList.query.all()
## print(b)
## burn_dict = {}
## for i in b:
## print(i.dmr_id)
## burn_dict[i.dmr_id] = i.version
## content = burn_dict
## # delete
#### delete_b = BurnList.query.filter_by(dmr_id=3153591).first()
#### db.session.delete(delete_b)
#### db.session.commit()
## a = AuthLog.query.all()
## print(a)
## authlog_flush()
## peer_delete('mmdvm', 1)
user_ids = ast.literal_eval(u.dmr_ids)
for i in user_ids.items():# active_tgs:
print(active_tgs['test'][i[0]])
content = active_tgs['test'][i[0]][1]['2']
## content = user_ids
return render_template('flask_user_layout.html', markup_content = Markup(content))
def get_peer_configs(_server_name):
mmdvm_pl = mmdvmPeer.query.filter_by(server=_server_name).filter_by(enabled=True).all()
xlx_pl = xlxPeer.query.filter_by(server=_server_name).filter_by(enabled=True).all()
## print(mmdvm_pl)
peer_config_list = {}
for i in mmdvm_pl:
## print(i.master_ip)
peer_config_list.update({i.name: {
'MODE': 'PEER',
'ENABLED': i.enabled,
'LOOSE': i.loose,
'SOCK_ADDR': (gethostbyname(i.ip), i.port),
'IP': i.ip,
'PORT': i.port,
'MASTER_SOCKADDR': (gethostbyname(i.master_ip), i.master_port),
'MASTER_IP': i.master_ip,
'MASTER_PORT': i.master_port,
'PASSPHRASE': i.passphrase,
'CALLSIGN': i.callsign,
'RADIO_ID': int(i.radio_id), #int(i.radio_id).to_bytes(4, 'big'),
'RX_FREQ': i.rx_freq,
'TX_FREQ': i.tx_freq,
'TX_POWER': i.tx_power,
'COLORCODE': i.color_code,
'LATITUDE': i.latitude,
'LONGITUDE': i.longitude,
'HEIGHT': i.height,
'LOCATION': i.location,
'DESCRIPTION': i.description,
'SLOTS': i.slots,
'URL': i.url,
'GROUP_HANGTIME': i.group_hangtime,
'OPTIONS': i.options,
'USE_ACL': i.use_acl,
'SUB_ACL': i.sub_acl,
'TG1_ACL': i.tg1_acl,
'TG2_ACL': i.tg2_acl
}})
for i in xlx_pl:
peer_config_list.update({i.name: {
'MODE': 'XLXPEER',
'ENABLED': i.enabled,
'LOOSE': i.loose,
'SOCK_ADDR': (gethostbyname(i.ip), i.port),
'IP': i.ip,
'PORT': i.port,
'MASTER_SOCKADDR': (gethostbyname(i.master_ip), i.master_port),
'MASTER_IP': i.master_ip,
'MASTER_PORT': i.master_port,
'PASSPHRASE': i.passphrase,
'CALLSIGN': i.callsign,
'RADIO_ID': int(i.radio_id), #int(i.radio_id).to_bytes(4, 'big'),
'RX_FREQ': i.rx_freq,
'TX_FREQ': i.tx_freq,
'TX_POWER': i.tx_power,
'COLORCODE': i.color_code,
'LATITUDE': i.latitude,
'LONGITUDE': i.longitude,
'HEIGHT': i.height,
'LOCATION': i.location,
'DESCRIPTION': i.description,
'SLOTS': i.slots,
'URL': i.url,
'OPTIONS': i.options,
'GROUP_HANGTIME': i.group_hangtime,
'XLXMODULE': i.xlxmodule,
'USE_ACL': i.use_acl,
'SUB_ACL': i.sub_acl,
'TG1_ACL': i.tg1_acl,
'TG2_ACL': i.tg2_acl
}})
#### print('peers')
## print('----------------')
return peer_config_list
def get_burnlist():
b = BurnList.query.all()
#print(b)
burn_dict = {}
for i in b:
#print(i.dmr_id)
burn_dict[i.dmr_id] = i.version
return burn_dict
def add_burnlist(_dmr_id, _version):
burn_list = BurnList(
dmr_id=_dmr_id,
version=_version,
)
db.session.add(burn_list)
db.session.commit()
def update_burnlist(_dmr_id, _version):
update_b = BurnList.query.filter_by(dmr_id=_dmr_id).first()
update_b.version=_version
db.session.commit()
def delete_burnlist(_dmr_id):
delete_b = BurnList.query.filter_by(dmr_id=_dmr_id).first()
db.session.delete(delete_b)
db.session.commit()
def authlog_add(_dmr_id, _peer_ip, _server_name, _portal_username, _auth_method, _login_type):
auth_log_add = AuthLog(
login_dmr_id=_dmr_id,
login_time=datetime.datetime.utcnow(),
portal_username = _portal_username,
peer_ip = _peer_ip,
server_name = _server_name,
login_auth_method=_auth_method,
login_type=_login_type
)
db.session.add(auth_log_add)
db.session.commit()
def authlog_flush():
AuthLog.query.delete()
db.session.commit()
def authlog_flush_user(_user):
flush_e = AuthLog.query.filter_by(portal_username=_user).all()
for i in flush_e:
db.session.delete(i)
db.session.commit()
def authlog_flush_dmr_id(_dmr_id):
flush_e = AuthLog.query.filter_by(login_dmr_id=_dmr_id).all()
for i in flush_e:
db.session.delete(i)
db.session.commit()
def authlog_flush_mmdvm_server(_mmdvm_serv):
flush_e = AuthLog.query.filter_by(server_name=_mmdvm_serv).all()
for i in flush_e:
db.session.delete(i)
db.session.commit()
def authlog_flush_ip(_ip):
flush_e = AuthLog.query.filter_by(peer_ip=_ip).all()
for i in flush_e:
db.session.delete(i)
db.session.commit()
## def peer_delete(_mode, _id):
## if _mode == 'xlx':
## p = xlxPeer.query.filter_by(id=_id).first()
## if _mode == 'mmdvm':
## p = mmdvmPeer.query.filter_by(id=_id).first()
## db.session.delete(p)
## db.session.commit()
def server_delete(_name):
s = ServerList.query.filter_by(name=_name).first()
m = MasterList.query.filter_by(server=_name).all()
p = ProxyList.query.filter_by(server=_name).all()
o = OBP.query.filter_by(server=_name).all()
dr = BridgeRules.query.filter_by(server=_name).all()
mp = mmdvmPeer.query.filter_by(server=_name).all()
xp = xlxPeer.query.filter_by(server=_name).all()
for d in m:
db.session.delete(d)
for d in p:
db.session.delete(d)
for d in o:
db.session.delete(d)
for d in dr:
db.session.delete(d)
for d in mp:
db.session.delete(d)
for d in xp:
db.session.delete(d)
db.session.delete(s)
db.session.commit()
def peer_delete(_mode, _server, _name):
if _mode == 'mmdvm':
p = mmdvmPeer.query.filter_by(server=_server).filter_by(name=_name).first()
if _mode == 'xlx':
p = xlxPeer.query.filter_by(server=_server).filter_by(name=_name).first()
dr = BridgeRules.query.filter_by(server=_server).filter_by(system_name=_name).all()
for d in dr:
db.session.delete(d)
db.session.delete(p)
db.session.commit()
def shared_secrets():
s = ServerList.query.all() #filter_by(name=_name).first()
r_list = []
for i in s:
r_list.append(str(i.secret))
return r_list
def bridge_add(_name, _desc, _public, _tg):
add_bridge = BridgeList(
bridge_name = _name,
description = _desc,
public_list = _public,
tg = _tg
)
db.session.add(add_bridge)
db.session.commit()
def update_bridge_list(_name, _desc, _public, _new_name, _tg):
bl = BridgeList.query.filter_by(bridge_name=_name).first()
bl.bridge_name = _new_name
bl.description = _desc
bl.public_list = _public
bl.tg = _tg
db.session.commit()
def bridge_delete(_name): #, _server):
bl = BridgeList.query.filter_by(bridge_name=_name).first()
db.session.delete(bl)
sl = ServerList.query.all()
for i in sl:
delete_system_bridge(_name, i.name)
db.session.commit()
def generate_rules(_name):
# generate UNIT list
## print('get rules')
## print(_name)
xlx_p = xlxPeer.query.filter_by(server=_name).all()
mmdvm_p = mmdvmPeer.query.filter_by(server=_name).all()
all_m = MasterList.query.filter_by(server=_name).all()
all_o = OBP.query.filter_by(server=_name).all()
all_p = ProxyList.query.filter_by(server=_name).all()
rules = BridgeRules.query.filter_by(server=_name).all()
UNIT = []
BRIDGES = {}
disabled = {}
for i in all_m:
if i.active == False:
disabled[i.name] = i.name
else:
if i.enable_unit == True:
UNIT.append(i.name)
for i in all_p:
if i.active == False:
disabled[i.name] = i.name
else:
if i.enable_unit == True:
n_systems = i.internal_stop_port - i.internal_start_port
n_count = 0
while n_count < n_systems:
UNIT.append(i.name + '-' + str(n_count))
n_count = n_count + 1
for i in all_o:
if i.enabled == False:
disabled[i.name] = i.name
else:
if i.enable_unit == True:
UNIT.append(i.name)
for i in xlx_p:
if i.enabled == False:
disabled[i.name] = i.name
else:
if i.enable_unit == True:
UNIT.append(i.name)
for i in mmdvm_p:
if i.enabled == False:
disabled[i.name] = i.name
else:
if i.enable_unit == True:
UNIT.append(i.name)
temp_dict = {}
# populate dict with needed bridges
for r in rules:
## print(r.bridge_name)
## b = BridgeRules.query.filter_by(server=_name).filter_by(server=_name).all()
## for d in temp_dict.items():
## if r.bridge_name == d[0]:
## print('update rule')
## if r.bridge_name != d[0]:
## print('add dict entry and rule')
temp_dict[r.bridge_name] = []
## print(temp_dict)
BRIDGES = temp_dict.copy()
for r in temp_dict.items():
b = BridgeRules.query.filter_by(bridge_name=r[0]).filter_by(server=_name).all()
for s in b:
try:
if s.system_name == disabled[s.system_name]:
pass
except:
if s.timeout == '':
timeout = 0
else:
timeout = int(s.timeout)
if s.proxy == True:
p = ProxyList.query.filter_by(server=_name).filter_by(name=s.system_name).first()
print(p.external_port)
n_systems = p.internal_stop_port - p.internal_start_port
n_count = 0
while n_count < n_systems:
BRIDGES[r[0]].append({'SYSTEM': s.system_name + '-' + str(n_count), 'TS': s.ts, 'TGID': s.tg, 'ACTIVE': s.active, 'TIMEOUT': timeout, 'TO_TYPE': s.to_type, 'ON': ast.literal_eval(str('[' + s.on + ']')), 'OFF': ast.literal_eval(str('[4000,' + s.off + ']')), 'RESET': ast.literal_eval(str('[' + s.reset + ']'))})
n_count = n_count + 1
else:
BRIDGES[r[0]].append({'SYSTEM': s.system_name, 'TS': s.ts, 'TGID': s.tg, 'ACTIVE': s.active, 'TIMEOUT': timeout, 'TO_TYPE': s.to_type, 'ON': ast.literal_eval(str('[' + s.on + ']')), 'OFF': ast.literal_eval(str('[' + s.off + ']')), 'RESET': ast.literal_eval(str('[' + s.reset + ']'))})
## for d in b:
## print(b.system_name)
## if r.bridge_name == d[0]:
## print('update rule')
## if r.bridge_name != d[0]:
## print('add dict entry and rule')
## print(r.tg)
## print(BRIDGES)
return [UNIT, BRIDGES]
def server_get(_name):
## print(_name)
#s = ServerList.query.filter_by(name=_name).first()
# print(s.name)
i = ServerList.query.filter_by(name=_name).first()
## print(i.name)
s_config = {}
s_config['GLOBAL'] = {}
s_config['REPORTS'] = {}
s_config['ALIASES'] = {}
s_config['USER_MANAGER'] = {}
s_config['GLOBAL'].update({
'PATH': i.global_path,
'PING_TIME': i.global_ping_time,
'MAX_MISSED': i.global_max_missed,
'USE_ACL': i.global_use_acl,
'REG_ACL': i.global_reg_acl,
'SUB_ACL': i.global_sub_acl,
'TG1_ACL': i.global_tg1_acl,
'TG2_ACL': i.global_tg2_acl
})
s_config['REPORTS'].update({
'REPORT': i.report_enable,
'REPORT_INTERVAL': i.report_interval,
'REPORT_PORT': i.report_port,
'REPORT_CLIENTS': i.report_clients.split(',')
})
s_config['ALIASES'].update({
'TRY_DOWNLOAD':i.ai_try_download,
'PATH': i.ai_path,
'PEER_FILE': i.ai_peer_file,
'SUBSCRIBER_FILE': i.ai_subscriber_file,
'TGID_FILE': i.ai_tgid_file,
'PEER_URL': i.ai_peer_url,
'SUBSCRIBER_URL': i.ai_subs_url,
'STALE_TIME': i.ai_stale * 86400,
})
s_config['USER_MANAGER'].update({
'SHORTEN_LENGTH': shorten_length,
'SHORTEN_SAMPLE': shorten_sample,
'EXTRA_1': extra_1,
'EXTRA_2': extra_2,
'EXTRA_INT_1': extra_int_1,
'EXTRA_INT_2': extra_int_2,
'APPEND_INT': append_int,
'SHORTEN_PASSPHRASE': i.um_shorten_passphrase,
'BURN_FILE': i.um_burn_file,
'BURN_INT': burn_int,
})
print(s_config['REPORTS'])
return s_config
def masters_get(_name):
## # print(_name)
#s = ServerList.query.filter_by(name=_name).first()
# print(s.name)
i = MasterList.query.filter_by(server=_name).filter_by(active=True).all()
o = OBP.query.filter_by(server=_name).filter_by(enabled=True).all()
p = ProxyList.query.filter_by(server=_name).filter_by(active=True).all()
# print('get masters')
master_config_list = {}
## master_config_list['SYSTEMS'] = {}
# print(i)
for m in i:
## print (m.name)
master_config_list.update({m.name: {
'MODE': 'MASTER',
'ENABLED': m.active,
'USE_USER_MAN': m.enable_um,
'STATIC_APRS_POSITION_ENABLED': m.static_positions,
'REPEAT': m.repeat,
'MAX_PEERS': m.max_peers,
'IP': m.ip,
'PORT': m.port,
'PASSPHRASE': m.passphrase, #bytes(m.passphrase, 'utf-8'),
'GROUP_HANGTIME': m.group_hang_time,
'USE_ACL': m.use_acl,
'REG_ACL': m.reg_acl,
'SUB_ACL': m.sub_acl,
'TG1_ACL': m.tg1_acl,
'TG2_ACL': m.tg2_acl
}})
master_config_list[m.name].update({'PEERS': {}})
for obp in o:
## print(type(obp.network_id))
master_config_list.update({obp.name: {
'MODE': 'OPENBRIDGE',
'ENABLED': obp.enabled,
'NETWORK_ID': obp.network_id, #int(obp.network_id).to_bytes(4, 'big'),
'IP': gethostbyname(obp.ip),
'PORT': obp.port,
'PASSPHRASE': obp.passphrase, #bytes(obp.passphrase.ljust(20,'\x00')[:20], 'utf-8'),
'TARGET_SOCK': (obp.target_ip, obp.target_port),
'TARGET_IP': gethostbyname(obp.target_ip),
'TARGET_PORT': obp.target_port,
'BOTH_SLOTS': obp.both_slots,
'USE_ACL': obp.use_acl,
'SUB_ACL': obp.sub_acl,
'TG1_ACL': obp.tg_acl,
'TG2_ACL': 'PERMIT:ALL'
}})
for pr in p:
master_config_list.update({pr.name: {
'MODE': 'PROXY',
'ENABLED': pr.active,
'EXTERNAL_PROXY_SCRIPT': pr.external_proxy,
'STATIC_APRS_POSITION_ENABLED': pr.static_positions,
'USE_USER_MAN': pr.enable_um,
'REPEAT': pr.repeat,
'PASSPHRASE': pr.passphrase, #bytes(pr.passphrase, 'utf-8'),
'EXTERNAL_PORT': pr.external_port,
'INTERNAL_PORT_START': pr.internal_start_port,
'INTERNAL_PORT_STOP': pr.internal_stop_port,
'GROUP_HANGTIME': pr.group_hang_time,
'USE_ACL': pr.use_acl,
'REG_ACL': pr.reg_acl,
'SUB_ACL': pr.sub_acl,
'TG1_ACL': pr.tg1_acl,
'TG2_ACL': pr.tg2_acl
}})
master_config_list[pr.name].update({'PEERS': {}})
# print(master_config_list)
return master_config_list
def add_system_rule(_bridge_name, _system_name, _ts, _tg, _active, _timeout, _to_type, _on, _off, _reset, _server, _public_list):
proxy = ProxyList.query.filter_by(server=_server).filter_by(name=_system_name).first()
is_proxy = False
try:
if _system_name == proxy.name:
is_proxy = True
except:
pass
add_system = BridgeRules(
bridge_name = _bridge_name,
system_name = _system_name,
ts = _ts,
tg = _tg,
active = _active,
timeout = _timeout,
to_type = _to_type,
on = _on,
off = _off,
reset = _reset,
server = _server,
public_list = _public_list,
proxy = is_proxy
)
db.session.add(add_system)
db.session.commit()
def edit_system_rule(_bridge_name, _system_name, _ts, _tg, _active, _timeout, _to_type, _on, _off, _reset, _server, _public_list):
proxy = ProxyList.query.filter_by(server=_server).filter_by(name=_system_name).first()
is_proxy = False
try:
if _system_name == proxy.name:
is_proxy = True
except:
pass
r = BridgeRules.query.filter_by(system_name=_system_name).filter_by(bridge_name=_bridge_name).first()
print('---')
print(_system_name)
print(_bridge_name)
print(r)
## for i in r:
## print(i.name)
## add_system = BridgeRules(
r.bridge_name = _bridge_name
r.system_name = _system_name
r.ts = _ts
r.tg = _tg
r.active = _active
r.timeout = _timeout
r.to_type = _to_type
r.on = _on
r.off = _off
r.reset = _reset
r.server = _server
r.public_list = _public_list
r.proxy = is_proxy
## db.session.add(add_system)
db.session.commit()
def delete_system_bridge(_name, _server):
dr = BridgeRules.query.filter_by(server=_server).filter_by(bridge_name=_name).all()
for i in dr:
db.session.delete(i)
db.session.commit()
def delete_system_rule(_name, _server, _system):
dr = BridgeRules.query.filter_by(server=_server).filter_by(bridge_name=_name).filter_by(system_name=_system).first()
db.session.delete(dr)
db.session.commit()
def server_edit(_name, _secret, _ip, _public_list, _port, _global_path, _global_ping_time, _global_max_missed, _global_use_acl, _global_reg_acl, _global_sub_acl, _global_tg1_acl, _global_tg2_acl, _ai_subscriber_file, _ai_try_download, _ai_path, _ai_peer_file, _ai_tgid_file, _ai_peer_url, _ai_subs_url, _ai_stale, _um_shorten_passphrase, _um_burn_file, _report_enable, _report_interval, _report_port, _report_clients, _unit_time, _notes):
s = ServerList.query.filter_by(name=_name).first()
# print(_name)
if _secret == '':
s.secret = s.secret
else:
s.secret = hashlib.sha256(_secret.encode()).hexdigest()
s.public_list = _public_list
s.ip = _ip
s.port = _port
s.global_path =_global_path
s.global_ping_time = _global_ping_time
s.global_max_missed = _global_max_missed
s.global_use_acl = _global_use_acl
s.global_reg_acl = _global_reg_acl
s.global_sub_acl = _global_sub_acl
s.global_tg1_acl = _global_tg1_acl
s.global_tg2_acl = _global_tg2_acl
s.ai_try_download = _ai_try_download
s.ai_path = _ai_path
s.ai_peer_file = _ai_peer_file
s.ai_subscriber_file = _ai_subscriber_file
s.ai_tgid_file = _ai_tgid_file
s.ai_peer_url = _ai_peer_url
s.ai_subs_url = _ai_subs_url
s.ai_stale = _ai_stale
# Pull from config file for now
## um_append_int = db.Column(db.Integer(), primary_key=False, server_default='2')
s.um_shorten_passphrase = _um_shorten_passphrase
s.um_burn_file = _um_burn_file
# Pull from config file for now
## um_burn_int = db.Column(db.Integer(), primary_key=False, server_default='6')
s.report_enable = _report_enable
s.report_interval = _report_interval
s.report_port = _report_port
s.report_clients = _report_clients
s.unit_time = int(_unit_time)
s.notes = _notes
db.session.commit()
def master_delete(_mode, _server, _name):
if _mode == 'MASTER':
m = MasterList.query.filter_by(server=_server).filter_by(name=_name).first()
if _mode == 'PROXY':
m = ProxyList.query.filter_by(server=_server).filter_by(name=_name).first()
if _mode == 'OBP':
m = OBP.query.filter_by(server=_server).filter_by(name=_name).first()
dr = BridgeRules.query.filter_by(server=_server).filter_by(system_name=_name).all()
for d in dr:
db.session.delete(d)
db.session.delete(m)
db.session.commit()
def edit_master(_mode, _name, _server, _static_positions, _repeat, _active, _max_peers, _ip, _port, _enable_um, _passphrase, _group_hang_time, _use_acl, _reg_acl, _sub_acl, _tg1_acl, _tg2_acl, _enable_unit, _notes, _external_proxy, _int_start_port, _int_stop_port, _network_id, _target_ip, _target_port, _both_slots, _public):
## print(_mode)
#### print(_server)
## print(_name)
if _mode == 'MASTER':
## print(_name)
m = MasterList.query.filter_by(server=_server).filter_by(name=_name).first()
## m.name = _name,
m.static_positions = _static_positions
m.repeat = _repeat
m.active = _active
m.max_peers = int(_max_peers)
m.ip = _ip
m.port = int(_port)
m.enable_um = _enable_um
m.passphrase = str(_passphrase)
m.group_hang_time = int(_group_hang_time)
m.use_acl = _use_acl
m.reg_acl = _reg_acl
m.sub_acl = _sub_acl
m.tg1_acl = _tg1_acl
m.tg2_acl = _tg2_acl
m.enable_unit = _enable_unit
## m.server = _server
m.notes = _notes
m.public_list = _public
db.session.commit()
if _mode == 'OBP':
# print(_enable_unit)
## print(enable_unit)
o = OBP.query.filter_by(server=_server).filter_by(name=_name).first()
o.enabled = _active
o.network_id = _network_id
o.ip = _ip
o.port = _port
o.passphrase = _passphrase
o.target_ip = _target_ip
o.target_port = _target_port
o.both_slots = _both_slots
o.use_acl = _use_acl
o.sub_acl = _sub_acl
o.tg1_acl = _tg1_acl
o.tg2_acl = _tg2_acl
o.enable_unit = _enable_unit
o.notes = _notes
db.session.commit()
if _mode == 'PROXY':
## print(_int_start_port)
## print(_int_stop_port)
p = ProxyList.query.filter_by(server=_server).filter_by(name=_name).first()
p.name = _name
p.static_positions = _static_positions
p.repeat = _repeat
p.active = _active
p.enable_um = _enable_um
p.passphrase = _passphrase
p.external_proxy = _external_proxy
external_port = int(_port)
p.group_hang_time = int(_group_hang_time)
p.internal_start_port = _int_start_port
p.internal_stop_port = _int_stop_port
p.use_acl = _use_acl
p.reg_acl = _reg_acl
p.sub_acl = _sub_acl
p.tg1_acl = _tg1_acl
p.tg2_acl = _tg2_acl
p.enable_unit = _enable_unit
p.server = _server
p.notes = _notes
p.public_list = _public
db.session.commit()
## add_proxy = ProxyList(
## name = _name,
## static_positions = _static_positions,
## repeat = _repeat,
## active = _active,
## enable_um = _enable_um,
## passphrase = _passphrase,
## external_proxy = _external_proxy,
## group_hang_time = int(_group_hang_time),
## internal_start_port = int(_int_start_port),
## internal_stop_port = int(_int_stop_port),
## use_acl = _use_acl,
## reg_acl = _reg_acl,
## sub_acl = _sub_acl,
## tg1_acl = _tg1_acl,
## tg2_acl = _tg2_acl,
## enable_unit = _enable_unit,
## server = _server,
## notes = _notes
## )
## db.session.add(add_master)
def add_master(_mode, _name, _server, _static_positions, _repeat, _active, _max_peers, _ip, _port, _enable_um, _passphrase, _group_hang_time, _use_acl, _reg_acl, _sub_acl, _tg1_acl, _tg2_acl, _enable_unit, _notes, _external_proxy, _int_start_port, _int_stop_port, _network_id, _target_ip, _target_port, _both_slots, _public):
# print(_mode)
if _mode == 'MASTER':
add_master = MasterList(
name = _name,
static_positions = _static_positions,
repeat = _repeat,
active = _active,
max_peers = int(_max_peers),
ip = _ip,
port = int(_port),
enable_um = _enable_um,
passphrase = _passphrase,
group_hang_time = int(_group_hang_time),
use_acl = _use_acl,
reg_acl = _reg_acl,
sub_acl = _sub_acl,
tg1_acl = _tg1_acl,
tg2_acl = _tg2_acl,
enable_unit = _enable_unit,
server = _server,
notes = _notes,
public_list = _public
)
db.session.add(add_master)
db.session.commit()
if _mode == 'PROXY':
add_proxy = ProxyList(
name = _name,
static_positions = _static_positions,
repeat = _repeat,
active = _active,
enable_um = _enable_um,
passphrase = _passphrase,
external_proxy = _external_proxy,
external_port = int(_port),
group_hang_time = int(_group_hang_time),
internal_start_port = int(_int_start_port),
internal_stop_port = int(_int_stop_port),
use_acl = _use_acl,
reg_acl = _reg_acl,
sub_acl = _sub_acl,
tg1_acl = _tg1_acl,
tg2_acl = _tg2_acl,
enable_unit = _enable_unit,
server = _server,
notes = _notes,
public_list = _public
)
db.session.add(add_proxy)
db.session.commit()
if _mode == 'OBP':
# print(_name)
# print(_network_id)
add_OBP = OBP(
name = _name,
enabled = _active,
network_id = _network_id, #
ip = _ip,
port = _port,
passphrase = _passphrase,
target_ip = _target_ip,#
target_port = _target_port,#
both_slots = _both_slots,#
use_acl = _use_acl,
sub_acl = _sub_acl,
tg_acl = _tg1_acl,
enable_unit = _enable_unit,
server = _server,
notes = _notes,
)
db.session.add(add_OBP)
db.session.commit()
def server_add(_name, _secret, _ip, _port, _global_path, _global_ping_time, _global_max_missed, _global_use_acl, _global_reg_acl, _global_sub_acl, _global_tg1_acl, _global_tg2_acl, _ai_subscriber_file, _ai_try_download, _ai_path, _ai_peer_file, _ai_tgid_file, _ai_peer_url, _ai_subs_url, _ai_stale, _um_shorten_passphrase, _um_burn_file, _report_enable, _report_interval, _report_port, _report_clients, _unit_time, _notes):
add_server = ServerList(
name = _name,
secret = hashlib.sha256(_secret.encode()).hexdigest(),
## public_list = _public_list,
ip = _ip,
port = _port,
global_path =_global_path,
global_ping_time = _global_ping_time,
global_max_missed = _global_max_missed,
global_use_acl = _global_use_acl,
global_reg_acl = _global_reg_acl,
global_sub_acl = _global_sub_acl,
global_tg1_acl = _global_tg1_acl,
global_tg2_acl = _global_tg2_acl,
ai_try_download = _ai_try_download,
ai_path = _ai_path,
ai_peer_file = _ai_peer_file,
ai_subscriber_file = _ai_subscriber_file,
ai_tgid_file = _ai_tgid_file,
ai_peer_url = _ai_peer_url,
ai_subs_url = _ai_subs_url,
ai_stale = _ai_stale,
# Pull from config file for now
## um_append_int = db.Column(db.Integer(), primary_key=False, server_default='2')
um_shorten_passphrase = _um_shorten_passphrase,
um_burn_file = _um_burn_file,
# Pull from config file for now
## um_burn_int = db.Column(db.Integer(), primary_key=False, server_default='6')
report_enable = _report_enable,
report_interval = _report_interval,
report_port = _report_port,
report_clients = _report_clients,
unit_time = int(_unit_time),
notes = _notes
)
db.session.add(add_server)
db.session.commit()
def peer_add(_mode, _name, _enabled, _loose, _ip, _port, _master_ip, _master_port, _passphrase, _callsign, _radio_id, _rx, _tx, _tx_power, _cc, _lat, _lon, _height, _loc, _desc, _slots, _url, _grp_hang, _xlx_mod, _opt, _use_acl, _sub_acl, _1_acl, _2_acl, _svr, _enable_unit, _notes):
if _mode == 'xlx':
xlx_peer_add = xlxPeer(
name = _name,
enabled = _enabled,
loose = _loose,
ip = _ip,
port = _port,
master_ip = _master_ip,
master_port = _master_port,
passphrase = _passphrase,
callsign = _callsign,
radio_id = _radio_id,
rx_freq = _rx,
tx_freq = _tx,
tx_power = _tx_power,
color_code = _cc,
latitude = _lat,
longitude = _lon,
height = _height,
location = _loc,
description = _desc,
slots = _slots,
xlxmodule = _xlx_mod,
url = _url,
enable_unit = _enable_unit,
group_hangtime = _grp_hang,
use_acl = _use_acl,
sub_acl = _sub_acl,
tg1_acl = _1_acl,
tg2_acl = _2_acl,
server = _svr,
notes = _notes
)
db.session.add(xlx_peer_add)
db.session.commit()
if _mode == 'mmdvm':
mmdvm_peer_add = mmdvmPeer(
name = _name,
enabled = _enabled,
loose = _loose,
ip = _ip,
port = _port,
master_ip = _master_ip,
master_port = _master_port,
passphrase = _passphrase,
callsign = _callsign,
radio_id = _radio_id,
rx_freq = _rx,
tx_freq = _tx,
tx_power = _tx_power,
color_code = _cc,
latitude = _lat,
longitude = _lon,
height = _height,
location = _loc,
description = _desc,
slots = _slots,
url = _url,
enable_unit = _enable_unit,
group_hangtime = _grp_hang,
use_acl = _use_acl,
sub_acl = _sub_acl,
tg1_acl = _1_acl,
tg2_acl = _2_acl,
server = _svr,
notes = _notes
)
db.session.add(mmdvm_peer_add)
db.session.commit()
def peer_edit(_mode, _server, _name, _enabled, _loose, _ip, _port, _master_ip, _master_port, _passphrase, _callsign, _radio_id, _rx, _tx, _tx_power, _cc, _lat, _lon, _height, _loc, _desc, _slots, _url, _grp_hang, _xlx_mod, _opt, _use_acl, _sub_acl, _1_acl, _2_acl, _enable_unit, _notes):
## print(_mode)
if _mode == 'mmdvm':
## print(_server)
## print(_name)
## print(_name)
## s = mmdvmPeer.query.filter_by(server=_server).filter_by(name=_name).first()
p = mmdvmPeer.query.filter_by(server=_server).filter_by(name=_name).first()
p.enabled = _enabled
p.loose = _loose
p.ip = _ip
p.port = _port
p.master_ip = _master_ip
p.master_port = _master_port
p.passphrase = _passphrase
p.callsign = _callsign
p.radio_id = _radio_id
p.rx_freq = _rx
p.tx_freq = _tx
p.tx_power = _tx_power
p.color_code = _cc
p.latitude = _lat
p.longitude = _lon
p.height = _height
p.location = _loc
p.description = _desc
p.slots = _slots
p.url = _url
p.enable_unit = _enable_unit
p.group_hangtime = _grp_hang
p.options = _opt
p.use_acl = _use_acl
p.sub_acl = _sub_acl
p.tg1_acl = _1_acl
p.tg2_acl = _2_acl
p.notes = _notes
if _mode == 'xlx':
## print(type(_server))
## print(type(_name))
## print(type(_enabled))
## print((_enable_unit))
## print(type(_use_acl))
#### print(_port)
## s = mmdvmPeer.query.filter_by(server=_server).filter_by(name=_name).first()
p = xlxPeer.query.filter_by(server=_server).filter_by(name=_name).first()
# print(type(p.enable_unit))
p.enabled = _enabled
p.loose = _loose
p.ip = _ip
p.port = _port
p.master_ip = _master_ip
p.master_port = _master_port
p.passphrase = _passphrase
p.callsign = _callsign
p.radio_id = _radio_id
p.rx_freq = _rx
p.tx_freq = _tx
p.tx_power = _tx_power
p.color_code = _cc
p.latitude = _lat
p.longitude = _lon
p.height = _height
p.location = _loc
p.description = _desc
p.slots = _slots
p.url = _url
p.options = _opt
p.enable_unit = _enable_unit
p.xlxmodule = _xlx_mod
p.group_hangtime = _grp_hang
p.use_acl = _use_acl
p.sub_acl = _sub_acl
p.tg1_acl = _1_acl
p.tg2_acl = _2_acl
p.notes = _notes
db.session.commit()
# Test server configs
@app.route('/manage_servers', methods=['POST', 'GET'])
@login_required
@roles_required('Admin')
def edit_server_db():
# Edit server
if request.args.get('save_mode'):# == 'new' and request.form.get('server_name'):
_port = int(request.form.get('server_port'))
_global_ping_time = int(request.form.get('ping_time'))
_global_max_missed = int(request.form.get('max_missed'))
_ai_stale = int(request.form.get('stale_days'))
_report_interval = int(request.form.get('report_interval'))
_report_port = int(request.form.get('report_port'))
if request.form.get('use_acl') == 'True':
_global_use_acl = True
if request.form.get('aliases_enabled') == 'True':
_ai_try_download = True
if request.form.get('um_shorten_passphrase') == 'True':
_um_shorten_passphrase = True
if request.form.get('report') == 'True':
_report_enabled = True
## if request.form.get('public_list') == 'True':
## public_list = True
else:
_global_use_acl = False
_ai_try_download = False
_um_shorten_passphrase = False
_report_enabled = False
## public_list = False
if request.args.get('save_mode') == 'new':
if request.form.get('server_name') == '':
content = '''Server can't have blank name.
Server saved.
Server changed.
Server deleted.
''' # Add new server elif request.args.get('add'): # == 'yes': content = '''
''' else: all_s = ServerList.query.all() p_list = '''
Add Server Config |
Name |
Notes |
'''
for s in all_s:
p_list = p_list + '''
''' + str(s.name) + ''' | ''' + s.notes + ''' |
Redirecting in 3 seconds.
''' else: if request.args.get('save_mode') == 'mmdvm_peer': peer_add('mmdvm', request.form.get('name_text'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), 'MMDVM', request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), request.form.get('server'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' if request.args.get('save_mode') == 'xlx_peer': peer_add('xlx', request.form.get('name_text'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), request.form.get('xlxmodule'), request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), request.form.get('server'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('add') == 'mmdvm' or request.args.get('add') == 'xlx': s = ServerList.query.all() if request.args.get('add') == 'mmdvm': mode = 'MMDVM' submit_link = 'manage_peers?save_mode=mmdvm_peer' xlx_module = '' if request.args.get('add') == 'xlx': xlx_module = '''
Redirecting in 3 seconds.
''' elif request.args.get('edit_mmdvm') == 'save' or request.args.get('edit_xlx') == 'save': peer_enabled = False use_acl = False peer_loose = True unit_enabled = False if request.form.get('enabled') == 'true': peer_enabled = True ## if request.form.get('loose') == 'true': ## peer_loose = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_unit') == 'True': unit_enabled = True ## else: ## peer_loose = False ## print((unit_enabled)) ## print(type(peer_enabled)) ## print(type(use_acl)) if request.args.get('edit_mmdvm') == 'save': peer_edit('mmdvm', request.args.get('server'), request.args.get('name'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), 'MMDVM', request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' if request.args.get('edit_xlx') == 'save': peer_edit('xlx', request.args.get('server'), request.args.get('name'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), request.form.get('xlxmodule'), request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('server') and request.args.get('peer_name') and request.args.get('mode'): # and request.args.get('edit_peer') and request.args.get('mode') == 'mmdvm': if request.args.get('mode') == 'mmdvm': p = mmdvmPeer.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('peer_name')).first() xlx_module = '' mode = "MMDVM" form_submit = '''''' else: all_s = ServerList.query.all() p_list = '' for s in all_s: # print(s.name) p_list = p_list + '''
Name | Mode | Notes |
''' + str(p.name) + ''' | MMDVM | ''' + p.notes + ''' |
''' + str(x.name) + ''' | XLX | ''' + x.notes + ''' |
Add MMDVM peer | Add XLX peer |
''' + p_list return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/manage_masters', methods=['POST', 'GET']) @login_required @roles_required('Admin') def manage_masters(): #PROXY if request.args.get('proxy_save'): active = False use_acl = False enable_unit = False repeat = True aprs_pos = False enable_um = True external_proxy = False public = False if request.form.get('enable_um') == 'False': enable_um = False if request.form.get('aprs_pos') == 'True': aprs_pos = True if request.form.get('enabled') == 'True': active = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_unit') == 'True': enable_unit = True if request.form.get('repeat') == 'False': repeat = False if request.form.get('external_proxy') == 'True': external_proxy = True if request.form.get('public_list') == 'True': public = True if request.args.get('proxy_save') == 'add': if request.form.get('name_text') == '': content = '''
Redirecting in 3 seconds.
''' else: add_master('PROXY', request.form.get('name_text'), request.form.get('server'), aprs_pos, repeat, active, 0, request.form.get('ip'), request.form.get('external_port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), external_proxy, request.form.get('int_port_start'), request.form.get('int_port_stop'), '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('proxy_save') == 'edit': ## print(request.args.get('name')) edit_master('PROXY', request.args.get('name'), request.args.get('server'), aprs_pos, repeat, active, 0, request.form.get('ip'), request.form.get('external_port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), external_proxy, request.form.get('int_port_start'), request.form.get('int_port_stop'), '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('proxy_save') == 'delete': master_delete('PROXY', request.args.get('server'), request.args.get('name')) content = '''Redirecting in 3 seconds.
''' # OBP elif request.args.get('OBP_save'): enabled = False use_acl = False enable_unit = False both_slots = True if request.form.get('enabled') == 'True': enabled = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_unit') == 'True': enable_unit = True if request.form.get('both_slots') == 'False': both_slots = False if request.args.get('OBP_save') == 'add': if request.form.get('name_text') == '': content = '''Redirecting in 3 seconds.
''' else: add_master('OBP', request.form.get('name_text'), request.form.get('server'), '', '', enabled, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), '', request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('tg_acl'), '', enable_unit, request.form.get('notes'), '', '', '', request.form.get('network_id'), request.form.get('target_ip'), request.form.get('target_port'), both_slots, '') content = '''Redirecting in 3 seconds.
''' elif request.args.get('OBP_save') == 'edit': edit_master('OBP', request.args.get('name'), request.args.get('server'), '', '', enabled, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), '', request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('tg_acl'), '', enable_unit, request.form.get('notes'), '', '', '', request.form.get('network_id'), request.form.get('target_ip'), request.form.get('target_port'), both_slots, '') content = '''Redirecting in 3 seconds.
''' elif request.args.get('OBP_save') == 'delete': master_delete('OBP', request.args.get('server'), request.args.get('name')) content = '''Redirecting in 3 seconds.
''' # MASTER elif request.args.get('master_save'): aprs_pos = False repeat = False active = False use_acl = False enable_um = False enable_unit = False public = False if request.form.get('aprs_pos') == 'True': aprs_pos = True if request.form.get('repeat') == 'True': repeat = True if request.form.get('enabled') == 'True': active = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_um') == 'True': enable_um = True if request.form.get('enable_unit') == 'True': enable_unit = True if request.form.get('public_list') == 'True': public = True if request.args.get('master_save') == 'add': if request.form.get('name_text') == '': content = '''Redirecting in 3 seconds.
''' else: add_master('MASTER', request.form.get('name_text'), request.form.get('server'), aprs_pos, repeat, active, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), '', '', '', '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('master_save') == 'edit': edit_master('MASTER', request.args.get('name'), request.args.get('server'), aprs_pos, repeat, active, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), '', '', '', '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('master_save') == 'delete': master_delete('MASTER', request.args.get('server'), request.args.get('name')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('add_OBP'): s = ServerList.query.all() server_options = '' for i in s: server_options = server_options + '''\n''' content = '''
''' elif request.args.get('edit_proxy'): # print(request.args.get('server')) # print(request.args.get('edit_proxy')) p = ProxyList.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('edit_proxy')).first() content = '''
''' elif request.args.get('add_proxy'): s = ServerList.query.all() server_options = '' for i in s: server_options = server_options + '''\n''' content = '''
''' elif request.args.get('add_master'): s = ServerList.query.all() server_options = '' for i in s: server_options = server_options + '''\n''' content = '''
''' elif request.args.get('edit_OBP'): ## print(request.args.get('server')) ## print(request.args.get('edit_OBP')) ## s = ServerList.query.all() o = OBP.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('edit_OBP')).first() ## print(o.notes) content = '''
''' elif request.args.get('edit_master'): ## s = ServerList.query.all() m = MasterList.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('edit_master')).first() content = '''
''' ## elif not request.args.get('edit_master') and not request.args.get('edit_OBP') and not request.args.get('add_OBP') and not request.args.get('add_master'): ## content = 'jglkdjklsd' else: #elif not request.args.get('add_proxy') or not request.args.get('add_OBP') or not request.args.get('add_master'): # or not request.args.get('proxy_save') or not request.args.get('master_save') or not request.args.get('OBP_save'): all_s = ServerList.query.all() m_list = '' for s in all_s: ## print(s.name) m_list = m_list + '''
Name | Mode | Notes |
''' + str(o.name) + ''' | OpenBridge | ''' + str(o.notes) + ''' |
''' + str(p.name) + ''' | PROXY | ''' + str(p.notes) + ''' |
''' + str(x.name) + ''' | MASTER | ''' + str(x.notes) + ''' |
Add MASTER | Add PROXY | Add OpenBridge |
''' + m_list return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/add_user', methods=['POST', 'GET']) @login_required @roles_required('Admin') def add_admin(): if request.method == 'GET': content = '''
''' elif request.method == 'POST' and request.form.get('username'): if not User.query.filter(User.username == request.form.get('username')).first(): radioid_data = ast.literal_eval(get_ids(request.form.get('username'))) user = User( username=request.form.get('username'), email=request.form.get('email'), email_confirmed_at=datetime.datetime.utcnow(), password=user_manager.hash_password(request.form.get('password')), dmr_ids = str(radioid_data[0]), initial_admin_approved = True, first_name = str(radioid_data[1]), last_name = str(radioid_data[2]), city = str(radioid_data[3]) ) db.session.add(user) u = User.query.filter_by(username=request.form.get('username')).first() user_role = UserRoles( user_id=u.id, role_id=2, ) db.session.add(user_role) db.session.commit() content = '''
Created user: ''' + str(request.form.get('username')) + '''
\n''' elif User.query.filter(User.username == request.form.get('username')).first(): content = 'Existing user: ' + str(request.form.get('username') + '. New user not created.') return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/manage_rules', methods=['POST', 'GET']) @login_required @roles_required('Admin') def manage_rules(): if request.args.get('save_bridge') == 'save': public = False if request.form.get('public_list') == 'True': public = True if request.form.get('bridge_name') == '': content = '''Redirecting in 3 seconds.
''' else: bridge_add(request.form.get('bridge_name'), request.form.get('description'), public, request.form.get('tg')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_bridge') == 'edit': public = False if request.form.get('public_list') == 'True': public = True update_bridge_list(request.args.get('bridge'), request.form.get('description'), public, request.form.get('bridge_name'), request.form.get('tg')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_bridge') == 'delete': bridge_delete(request.args.get('bridge')) content = '''Redirecting in 3 seconds.
''' #Rules elif request.args.get('save_rule'): public_list = False active = False if request.form.get('active_dropdown') == 'True': active = True if request.args.get('save_rule') == 'new': add_system_rule(request.form.get('bridge_dropdown'), request.form.get('system_text'), request.form.get('ts_dropdown'), request.form.get('tgid'), active, request.form.get('timer_time'), request.form.get('type_dropdown'), request.form.get('on'), request.form.get('off'), request.form.get('reset'), request.args.get('server'), public_list) content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_rule') == 'edit': content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_rule') == 'delete': # print(request.args.get('bridge')) # print(request.args.get('server')) if request.args.get('system'): delete_system_rule(request.args.get('bridge'), request.args.get('server'), request.args.get('system')) else: delete_system_bridge(request.args.get('bridge'), request.args.get('server')) ## delete_system_rule(request.args.get('bridge'), request.args.get('server'), request.args.get('system')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('add_rule'): ## svl = ServerList.query.all() bl = BridgeList.query.all() #filter(bridge_name== request.form.get('username')).all() all_o = OBP.query.filter_by(server=request.args.get('add_rule')).all() all_m = MasterList.query.filter_by(server=request.args.get('add_rule')).all() all_p = ProxyList.query.filter_by(server=request.args.get('add_rule')).all() m_l = mmdvmPeer.query.filter_by(server=request.args.get('add_rule')).all() x_l = xlxPeer.query.filter_by(server=request.args.get('add_rule')).all() ## print(sl) ## print(bl) ## svl_option = '' bl_option = '' sl_option = '' for i in all_o: sl_option = sl_option + '''''' for i in all_m: sl_option = sl_option + '''''' for i in all_p: sl_option = sl_option + '''''' for i in m_l: sl_option = sl_option + '''''' for i in x_l: sl_option = sl_option + '''''' for i in bl: bl_option = bl_option + '''''' content = '''''' elif request.args.get('edit_rule') and request.args.get('bridge'): br = BridgeRules.query.filter_by(server=request.args.get('edit_rule')).filter_by(bridge_name=request.args.get('bridge')).all() print(br) br_view = '''
Delete SYSTEM Rule |
|
''' content = br_view elif request.args.get('edit_rule') == 'save' and request.args.get('bridge_edit'): public_list = False active = False if request.form.get('active_dropdown') == 'True': active = True edit_system_rule(request.args.get('bridge_edit'), request.args.get('system'), request.form.get('ts_dropdown'), request.form.get('tgid'), active, request.form.get('timer_time'), request.form.get('type_dropdown'), request.form.get('on'), request.form.get('off'), request.form.get('reset'), request.args.get('server'), public_list) content = '''
Redirecting in 3 seconds.
''' elif request.args.get('add_bridge'): s = ServerList.query.all() ## server_options = '' ## for i in s: ## server_options = server_options + '''\n''' content = '''
''' else: all_b = BridgeList.query.all() s = ServerList.query.all() b_list = '''
Add Bridge |
Name | Public | Description | TGID |
''' + str(i.bridge_name) + ''' | ''' + str(i.public_list) + ''' | ''' + str(i.description) + ''' | ''' + str(i.tg) + ''' |
Add a rule to server: ''' + str(i.name) + ''' |
Bridge Name | - | - |
''' + str(x.bridge_name) + ''' | Edit Bridge Rules | Delete Bridge from this server |
''' content = b_list + r_list + '''''' return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/svr', methods=['POST']) def auth(): hblink_req = request.json # print((hblink_req)) if hblink_req['secret'] in shared_secrets(): 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) 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']}] response = jsonify( allow=True, mode='normal', ) elif authorized_peer(hblink_req['login_id'])[1] == '': authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], 'Config Passphrase: ' + legacy_passphrase, 'Attempt') ## active_tgs[hblink_req['login_server']][hblink_req['system']] = [{'1':[]}, {'2':[]}, {'SYSTEM': ''}, {'peer_id':hblink_req['login_id']}] response = jsonify( allow=True, mode='legacy', ) elif authorized_peer(hblink_req['login_id'])[1] != '' or isinstance(authorized_peer(hblink_req['login_id'])[1], int) == False: authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], authorized_peer(hblink_req['login_id'])[1], 'Attempt') ## active_tgs[hblink_req['login_server']][hblink_req['system']] = [{'1':[]}, {'2':[]}, {'SYSTEM': ''}, {'peer_id':hblink_req['login_id']}] # print(authorized_peer(hblink_req['login_id'])) response = jsonify( allow=True, mode='override', value=authorized_peer(hblink_req['login_id'])[1] ) try: active_tgs[hblink_req['login_server']][hblink_req['system']] = [{'1':[]}, {'2':[]}, {'SYSTEM': ''}, {'peer_id':hblink_req['login_id']}] ## print('Restart ' + hblink_req['login_server'] + ' please.') except: ## active_tgs[hblink_req['login_server']] = {} pass elif authorized_peer(hblink_req['login_id'])[0] == False: ## print('log fail') authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], 'Not Registered', '-', 'Failed') response = jsonify( allow=False) elif not type(hblink_req['login_id']) == int: user = hblink_req['login_id'] u = User.query.filter_by(username=user).first() if not u: msg = jsonify(auth=False, reason='User not found') response = make_response(msg, 401) if u: u_role = UserRoles.query.filter_by(user_id=u.id).first() password = user_manager.verify_password(hblink_req['password'], u.password) if u_role.role_id == 2: role = 'user' if u_role.role_id == 1: role = 'admin' if password: response = jsonify(auth=True, role=role) else: 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') response = jsonify( logged=True ) elif 'burn_list' in hblink_req: # ['burn_list']: # == 'burn_list': response = jsonify( burn_list=get_burnlist() ) elif 'get_config' in hblink_req: if hblink_req['get_config']: active_tgs[hblink_req['get_config']] = {} print(active_tgs) ## try: ## print(get_peer_configs(hblink_req['get_config'])) response = jsonify( config=server_get(hblink_req['get_config']), peers=get_peer_configs(hblink_req['get_config']), masters=masters_get(hblink_req['get_config']), ## OBP=get_OBP(hblink_req['get_config']) ) ## except: ## message = jsonify(message='Config error') ## response = make_response(message, 401) elif 'get_rules' in hblink_req: if hblink_req['get_rules']: # == 'burn_list': ## try: response = jsonify( rules=generate_rules(hblink_req['get_rules']), ## OBP=get_OBP(hblink_req['get_config']) ) ## 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']) ## 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) return response return app if __name__ == '__main__': app = create_app() app.run(debug = True, port=hws_port, host=hws_host)