add UNIT table view
This commit is contained in:
parent
4fcafa1927
commit
3b8dff4c03
20
bridge.py
20
bridge.py
@ -110,6 +110,25 @@ def update_tg(CONFIG, mode, dmr_id, data):
|
||||
## return config.build_config(cli_file)
|
||||
|
||||
|
||||
def send_unit_table(CONFIG, _data):
|
||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
sms_data = {
|
||||
'unit_table': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||
'secret':shared_secret,
|
||||
'data': str(_data),
|
||||
|
||||
}
|
||||
json_object = json.dumps(sms_data, indent = 4)
|
||||
|
||||
try:
|
||||
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
|
||||
## resp = json.loads(req.text)
|
||||
## print(resp)
|
||||
## return resp['rules']
|
||||
except requests.ConnectionError:
|
||||
logger.error('Config server unreachable')
|
||||
|
||||
def ping(CONFIG):
|
||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
@ -436,6 +455,7 @@ def rule_timer_loop(unit_flood_time):
|
||||
|
||||
for unit in remove_list:
|
||||
del UNIT_MAP[unit]
|
||||
send_unit_table(CONFIG, UNIT_MAP)
|
||||
|
||||
logger.debug('Removed unit(s) %s from UNIT_MAP', remove_list)
|
||||
|
||||
|
@ -215,6 +215,25 @@ def send_ss(CONFIG, callsign, message, dmr_id):
|
||||
except requests.ConnectionError:
|
||||
logger.error('Config server unreachable')
|
||||
|
||||
def send_unit_table(CONFIG, _data):
|
||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
sms_data = {
|
||||
'unit_table': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||
'secret':shared_secret,
|
||||
'data': str(_data),
|
||||
|
||||
}
|
||||
json_object = json.dumps(sms_data, indent = 4)
|
||||
|
||||
try:
|
||||
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
|
||||
## resp = json.loads(req.text)
|
||||
## print(resp)
|
||||
## return resp['rules']
|
||||
except requests.ConnectionError:
|
||||
logger.error('Config server unreachable')
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1324,6 +1343,7 @@ def rule_timer_loop():
|
||||
|
||||
logger.debug('Removed unit(s) %s from UNIT_MAP', remove_list)
|
||||
ping(CONFIG)
|
||||
send_unit_table(CONFIG, UNIT_MAP)
|
||||
|
||||
|
||||
class OBP(OPENBRIDGE):
|
||||
|
57
web/app.py
57
web/app.py
@ -2377,8 +2377,6 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
content = ''
|
||||
disp_list = []
|
||||
for i in ss_all:
|
||||
print(i.dmr_id)
|
||||
print(disp_list)
|
||||
if i.dmr_id not in disp_list:
|
||||
content = content + '''
|
||||
<tr>
|
||||
@ -2415,7 +2413,7 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
<td>''' + str(i.time.strftime(time_format)) + '''</td>
|
||||
</tr>'''
|
||||
except:
|
||||
content = '<h4><p style="text-align: center;">Not posts by user.</p></h4>'
|
||||
content = '<h4><p style="text-align: center;">No posts by user.</p></h4>'
|
||||
all_post = ''
|
||||
return render_template('ss.html', markup_content = Markup(content), all_post = Markup(post_content))
|
||||
|
||||
@ -2758,7 +2756,7 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
db.session.add(auth_log_add)
|
||||
db.session.commit()
|
||||
|
||||
def misc_add(_field_1, _field_2, _field_3, _field_4, int_1, _int_2, _int_3, _int_4, _boo_1, _boo_2):
|
||||
def misc_add(_field_1, _field_2, _field_3, _field_4, _int_1, _int_2, _int_3, _int_4, _boo_1, _boo_2):
|
||||
misc_entry_add = Misc(
|
||||
field_1 = _field_1,
|
||||
field_2 = _field_2,
|
||||
@ -6024,7 +6022,7 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
<table style="width: 500px; margin-left: auto; margin-right: auto;" border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align: center;"><strong>Add a rule to server: <a href="manage_rules?add_rule=''' + str(i.name) + '''">''' + str(i.name) + '''</a></strong></td>
|
||||
<td style="text-align: center;"><a href="manage_rules?add_rule=''' + str(i.name) + '''"><button type="button" class="btn btn-success">Add rule to <strong>''' + str(i.name) + '''</strong></button></a> - <a href="/unit/''' + i.name + '''"><button type="button" class="btn btn-primary">View UNIT Table</button></a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -6054,6 +6052,45 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
|
||||
return render_template('flask_user_layout.html', markup_content = Markup(content))
|
||||
|
||||
|
||||
@login_required
|
||||
@roles_required('Admin')
|
||||
@app.route('/unit/<server>')
|
||||
def get_unit_table(server):
|
||||
unit_table = Misc.query.filter_by(field_1='unit_table_' + server).first()
|
||||
table_dict = ast.literal_eval(unit_table.field_2)
|
||||
print(table_dict)
|
||||
content = '''
|
||||
<h3 style="text-align: center;">UNIT Call Routing Table for ''' + server + '''</h3>
|
||||
<p> </p>
|
||||
|
||||
<table data-toggle="table" data-pagination="true" data-search="true" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>System</th>
|
||||
<th>Expiration</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
'''
|
||||
try:
|
||||
for i in table_dict.items():
|
||||
content = content + '''
|
||||
<tr>
|
||||
<td>''' + str(int_id(i[0])) + '''</td>
|
||||
<td>''' + str((i[1][0])) + '''</td>
|
||||
<td>''' + str(i[1][1]) + '''</td>
|
||||
</tr>
|
||||
'''
|
||||
|
||||
content = content + '</tbody></table>'
|
||||
except:
|
||||
content = '<h4><p style="text-align: center;">No UNIT table.</p></h4>'
|
||||
return render_template('flask_user_layout.html', markup_content = Markup(content))
|
||||
|
||||
|
||||
@login_required
|
||||
@roles_required('Admin')
|
||||
@app.route('/OBP_key_gen')
|
||||
@ -6218,6 +6255,16 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
del_ss(hblink_req['dmr_id'])
|
||||
ss_add(hblink_req['callsign'], str(hblink_req['message']), hblink_req['dmr_id'])
|
||||
response = 'rcvd'
|
||||
elif 'unit_table' in hblink_req:
|
||||
## del_unit_table(hblink_req['unit_table'])
|
||||
try:
|
||||
delete_misc_field_1('unit_table_' + hblink_req['unit_table'])
|
||||
except:
|
||||
print('entry error')
|
||||
misc_add('unit_table_' + hblink_req['unit_table'], str(hblink_req['data']), '', '', 0, 0, 0, 0, False, False)
|
||||
## unit_table_add(hblink_req['data'])
|
||||
response = 'rcvd'
|
||||
|
||||
|
||||
elif 'get_config' in hblink_req:
|
||||
if hblink_req['get_config']:
|
||||
|
Loading…
Reference in New Issue
Block a user