add script_links and ping_list to DB, works accross multiple instances/processes
This commit is contained in:
parent
85a16ffe08
commit
0e03ad4f03
49
web/app.py
49
web/app.py
|
@ -51,9 +51,9 @@ from cryptography.fernet import Fernet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
script_links = {}
|
##script_links = {}
|
||||||
active_tgs = {}
|
##active_tgs = {}
|
||||||
ping_list = {}
|
##ping_list = {}
|
||||||
peer_locations = {}
|
peer_locations = {}
|
||||||
|
|
||||||
# Query radioid.net for list of IDs
|
# Query radioid.net for list of IDs
|
||||||
|
@ -158,7 +158,7 @@ def hbnet_web_service():
|
||||||
username = db.Column(db.String(100,), nullable=False, unique=True)
|
username = db.Column(db.String(100,), nullable=False, unique=True)
|
||||||
password = db.Column(db.String(255), nullable=False, server_default='')
|
password = db.Column(db.String(255), nullable=False, server_default='')
|
||||||
email_confirmed_at = db.Column(db.DateTime())
|
email_confirmed_at = db.Column(db.DateTime())
|
||||||
email = db.Column(db.String(255), nullable=True, unique=True)
|
email = db.Column(db.String(255), nullable=True, unique=True, server_default='')
|
||||||
|
|
||||||
# User information
|
# User information
|
||||||
first_name = db.Column(db.String(100), nullable=False, server_default='')
|
first_name = db.Column(db.String(100), nullable=False, server_default='')
|
||||||
|
@ -620,6 +620,20 @@ def hbnet_web_service():
|
||||||
time = datetime.datetime.utcnow()
|
time = datetime.datetime.utcnow()
|
||||||
)
|
)
|
||||||
db.session.add(home_entry_add)
|
db.session.add(home_entry_add)
|
||||||
|
ping_list_initial = Misc(
|
||||||
|
field_1 = 'ping_list',
|
||||||
|
field_2 = '{}',
|
||||||
|
|
||||||
|
time = datetime.datetime.utcnow()
|
||||||
|
)
|
||||||
|
db.session.add(ping_list_initial)
|
||||||
|
script_links_initial = Misc(
|
||||||
|
field_1 = 'script_links',
|
||||||
|
field_2 = '{}',
|
||||||
|
|
||||||
|
time = datetime.datetime.utcnow()
|
||||||
|
)
|
||||||
|
db.session.add(script_links_initial)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Query radioid.net for list of DMR IDs, then add to DB
|
# Query radioid.net for list of DMR IDs, then add to DB
|
||||||
|
@ -827,6 +841,8 @@ def hbnet_web_service():
|
||||||
try:
|
try:
|
||||||
u = current_user
|
u = current_user
|
||||||
id_dict = ast.literal_eval(u.dmr_ids)
|
id_dict = ast.literal_eval(u.dmr_ids)
|
||||||
|
script_l = Misc.query.filter_by(field_1='script_links').first()
|
||||||
|
script_links = ast.literal_eval(script_l.field_2)
|
||||||
#u = User.query.filter_by(username=user).first()
|
#u = User.query.filter_by(username=user).first()
|
||||||
## print(request.args.get('mode'))
|
## print(request.args.get('mode'))
|
||||||
## if request.args.get('mode') == 'generated':
|
## if request.args.get('mode') == 'generated':
|
||||||
|
@ -835,6 +851,7 @@ def hbnet_web_service():
|
||||||
#if i[1] == '':
|
#if i[1] == '':
|
||||||
link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8)
|
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
|
script_links[i[0]] = link_num
|
||||||
|
misc_edit_field_1('script_links', str(script_links), '', '', 0, 0, 0, 0, False, False)
|
||||||
content = content + '''
|
content = content + '''
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading" style="text-align: center;"><h4>ID: ''' + str(i[0]) + '''</h4></div>
|
<div class="panel-heading" style="text-align: center;"><h4>ID: ''' + str(i[0]) + '''</h4></div>
|
||||||
|
@ -857,7 +874,11 @@ def hbnet_web_service():
|
||||||
@login_required
|
@login_required
|
||||||
def gen():
|
def gen():
|
||||||
#print(str(gen_passphrase(3153591))) #(int(i[0])))
|
#print(str(gen_passphrase(3153591))) #(int(i[0])))
|
||||||
|
pl = Misc.query.filter_by(field_1='ping_list').first()
|
||||||
|
ping_list = ast.literal_eval(pl.field_2)
|
||||||
sl = ServerList.query.all()
|
sl = ServerList.query.all()
|
||||||
|
script_l = Misc.query.filter_by(field_1='script_links').first()
|
||||||
|
script_links = ast.literal_eval(script_l.field_2)
|
||||||
svr_content = ''
|
svr_content = ''
|
||||||
for i in sl:
|
for i in sl:
|
||||||
try:
|
try:
|
||||||
|
@ -912,6 +933,7 @@ def hbnet_web_service():
|
||||||
if isinstance(i[1], int) == True and i[1] != 0:
|
if isinstance(i[1], int) == True and i[1] != 0:
|
||||||
link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8)
|
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
|
script_links[i[0]] = link_num
|
||||||
|
misc_edit_field_1('script_links', str(script_links), '', '', 0, 0, 0, 0, False, False)
|
||||||
#print(script_links)
|
#print(script_links)
|
||||||
content = content + '''\n
|
content = content + '''\n
|
||||||
<div class="panel panel-default" style="text-align: center;">
|
<div class="panel panel-default" style="text-align: center;">
|
||||||
|
@ -927,6 +949,7 @@ def hbnet_web_service():
|
||||||
elif i[1] == 0:
|
elif i[1] == 0:
|
||||||
link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8)
|
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
|
script_links[i[0]] = link_num
|
||||||
|
misc_edit_field_1('script_links', str(script_links), '', '', 0, 0, 0, 0, False, False)
|
||||||
#print(script_links)
|
#print(script_links)
|
||||||
content = content + '''\n
|
content = content + '''\n
|
||||||
<div class="panel panel-default" style="text-align: center;">
|
<div class="panel panel-default" style="text-align: center;">
|
||||||
|
@ -1414,6 +1437,8 @@ def hbnet_web_service():
|
||||||
dmr_id = int(request.args.get('dmr_id'))
|
dmr_id = int(request.args.get('dmr_id'))
|
||||||
number = float(request.args.get('number'))
|
number = float(request.args.get('number'))
|
||||||
#print(type(script_links[dmr_id]))
|
#print(type(script_links[dmr_id]))
|
||||||
|
script_l = Misc.query.filter_by(field_1='script_links').first()
|
||||||
|
script_links = ast.literal_eval(script_l.field_2)
|
||||||
u = User.query.filter(User.dmr_ids.contains(request.args.get('dmr_id'))).first()
|
u = User.query.filter(User.dmr_ids.contains(request.args.get('dmr_id'))).first()
|
||||||
|
|
||||||
pub_list = []
|
pub_list = []
|
||||||
|
@ -1433,6 +1458,7 @@ def hbnet_web_service():
|
||||||
#try:
|
#try:
|
||||||
if dmr_id in script_links and number == float(script_links[dmr_id]):
|
if dmr_id in script_links and number == float(script_links[dmr_id]):
|
||||||
script_links.pop(dmr_id)
|
script_links.pop(dmr_id)
|
||||||
|
misc_edit_field_1('script_links', str(script_links), '', '', 0, 0, 0, 0, False, False)
|
||||||
|
|
||||||
ml = MasterList.query.filter_by(public_list=True).filter_by(active=True).all()
|
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()
|
pl = ProxyList.query.filter_by(public_list=True).filter_by(active=True).all()
|
||||||
|
@ -3870,6 +3896,8 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||||
'''
|
'''
|
||||||
else:
|
else:
|
||||||
all_s = ServerList.query.all()
|
all_s = ServerList.query.all()
|
||||||
|
pl = Misc.query.filter_by(field_1='ping_list').first()
|
||||||
|
ping_list = ast.literal_eval(pl.field_2)
|
||||||
p_list = '''
|
p_list = '''
|
||||||
<h3 style="text-align: center;">View/Edit Servers</h3>
|
<h3 style="text-align: center;">View/Edit Servers</h3>
|
||||||
|
|
||||||
|
@ -5853,14 +5881,17 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||||
return render_template('aprs_page.html', markup_content = Markup(content))
|
return render_template('aprs_page.html', markup_content = Markup(content))
|
||||||
|
|
||||||
@app.route('/svr', methods=['POST'])
|
@app.route('/svr', methods=['POST'])
|
||||||
def auth():
|
def svr_endpoint():
|
||||||
hblink_req = request.json
|
hblink_req = request.json
|
||||||
print((hblink_req))
|
print((hblink_req))
|
||||||
print(peer_locations)
|
print(peer_locations)
|
||||||
if hblink_req['secret'] in shared_secrets():
|
if hblink_req['secret'] in shared_secrets():
|
||||||
try:
|
try:
|
||||||
if hblink_req['ping']:
|
if hblink_req['ping']:
|
||||||
|
pl = Misc.query.filter_by(field_1='ping_list').first()
|
||||||
|
ping_list = ast.literal_eval(pl.field_2)
|
||||||
ping_list[hblink_req['ping']] = time.time()
|
ping_list[hblink_req['ping']] = time.time()
|
||||||
|
misc_edit_field_1('ping_list', str(ping_list), '', '', 0, 0, 0, 0, True, True)
|
||||||
response = ''
|
response = ''
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -5953,8 +5984,14 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||||
|
|
||||||
elif 'get_config' in hblink_req:
|
elif 'get_config' in hblink_req:
|
||||||
if hblink_req['get_config']:
|
if hblink_req['get_config']:
|
||||||
active_tgs[hblink_req['get_config']] = {}
|
## active_tgs[hblink_req['get_config']] = {}
|
||||||
|
|
||||||
|
pl = Misc.query.filter_by(field_1='ping_list').first()
|
||||||
|
ping_list = ast.literal_eval(pl.field_2)
|
||||||
|
|
||||||
ping_list[hblink_req['get_config']] = time.time()
|
ping_list[hblink_req['get_config']] = time.time()
|
||||||
|
|
||||||
|
misc_edit_field_1('ping_list', str(ping_list), '', '', 0, 0, 0, 0, True, True)
|
||||||
## print(active_tgs)
|
## print(active_tgs)
|
||||||
## try:
|
## try:
|
||||||
## print(get_peer_configs(hblink_req['get_config']))
|
## print(get_peer_configs(hblink_req['get_config']))
|
||||||
|
|
Loading…
Reference in New Issue