fix templates, continue tiny pages, continue data gateway

This commit is contained in:
KF7EEL 2021-10-10 05:16:38 -07:00
parent bb8763bd45
commit 4633f4d518
6 changed files with 182 additions and 46 deletions

View File

@ -998,45 +998,74 @@ def send_sms(csbk, to_id, from_id, peer_id, call_type, msg):
def data_que_check(): def data_que_check():
l=task.LoopingCall(data_que_send) l=task.LoopingCall(data_que_send)
l.start(1) l.start(1)
def data_que_send(): ##def data_que_send():
#logger.info('Check SMS que') ## #logger.info('Check SMS que')
## try:
## #logger.info(UNIT_MAP)
## for packet_file in os.listdir('/tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/'):
## logger.info('Sending SMS')
## logger.info(os.listdir('/tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/'))
## snd_seq = ast.literal_eval(os.popen('cat /tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/' + packet_file).read())
## for data in snd_seq:
## # Get dest id
## dst_id = bytes.fromhex(str(data[10:16])[2:-1])
## call_type = hex2bits(data)[121:122]
## # Handle UNIT calls
## if call_type[0] == True:
## # If destination ID in map, route call only there
## if dst_id in UNIT_MAP:
## data_target = UNIT_MAP[dst_id][0]
## reactor.callFromThread(systems[data_target].send_system,bytes.fromhex(re.sub("b'|'", '', str(data))))
## logger.info('Sending data to ' + str(data[10:16])[2:-1] + ' on system ' + data_target)
## # Flood all systems
## elif dst_id not in UNIT_MAP:
## for i in UNIT:
## reactor.callFromThread(systems[i].send_system,bytes.fromhex(re.sub("b'|'", '', str(data))))
## logger.info('Sending data to ' + str(data[10:16])[2:-1] + ' on system ' + i)
## # Handle group calls
## elif call_type[0] == False:
## for i in BRIDGES.items():
## for d in i[1]:
## if dst_id == d['TGID']:
## data_target = d['SYSTEM']
## reactor.callFromThread(systems[data_target].send_system,bytes.fromhex(re.sub("b'|'", '', str(data))))
## logger.info('Sending data to ' + str(data[10:16])[2:-1] + ' on system ' + data_target)
##
## os.system('rm /tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/' + packet_file)
##
## #routerHBP.send_peer('MASTER-2', bytes.fromhex(re.sub("b'|'", '', str(data))))
## ## os.system('rm /tmp/.hblink_data_que/' + packet_file)
## except Exception as e:
## logger.info(e)
def aprs_process(packet):
try: try:
#logger.info(UNIT_MAP) if 'addresse' in aprslib.parse(packet):
for packet_file in os.listdir('/tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/'): #print(aprslib.parse(packet))
logger.info('Sending SMS') recipient = re.sub('-.*','', aprslib.parse(packet)['addresse'])
logger.info(os.listdir('/tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/')) recipient_ssid = re.sub('.*-','', aprslib.parse(packet)['addresse'])
snd_seq = ast.literal_eval(os.popen('cat /tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/' + packet_file).read()) if recipient == '':
for data in snd_seq: pass
# Get dest id else:
dst_id = bytes.fromhex(str(data[10:16])[2:-1]) user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read())
call_type = hex2bits(data)[121:122] for i in user_settings.items():
# Handle UNIT calls sms_id = i[0]
if call_type[0] == True: ssid = i[1][1]['ssid']
# If destination ID in map, route call only there if i[1][1]['ssid'] == '':
if dst_id in UNIT_MAP: ssid = user_ssid
data_target = UNIT_MAP[dst_id][0] if recipient in i[1][0]['call'] and i[1][5]['APRS'] == True and recipient_ssid in ssid:
reactor.callFromThread(systems[data_target].send_system,bytes.fromhex(re.sub("b'|'", '', str(data)))) mailbox_write(re.sub('-.*','', aprslib.parse(packet)['addresse']), aprslib.parse(packet)['from'], time(), aprslib.parse(packet)['message_text'], recipient)
logger.info('Sending data to ' + str(data[10:16])[2:-1] + ' on system ' + data_target) send_sms(False, sms_id, 0000, 0000, 'unit', str('APRS / ' + str(aprslib.parse(packet)['from']) + ': ' + aprslib.parse(packet)['message_text']))
# Flood all systems try:
elif dst_id not in UNIT_MAP: if 'msgNo' in aprslib.parse(packet):
for i in UNIT: #sleep(1)
reactor.callFromThread(systems[i].send_system,bytes.fromhex(re.sub("b'|'", '', str(data)))) logger.info(str(aprslib.parse(packet)['addresse']) + '>APHBL3,TCPIP*:' + ':' + str(aprslib.parse(packet)['from'].ljust(9)) +':ack' + str(aprslib.parse(packet)['msgNo']))
logger.info('Sending data to ' + str(data[10:16])[2:-1] + ' on system ' + i) aprs_send(str(aprslib.parse(packet)['addresse']) + '>APHBL3,TCPIP*:' + ':' + str(aprslib.parse(packet)['from'].ljust(9)) +':ack' + str(aprslib.parse(packet)['msgNo']))
# Handle group calls logger.info('Send ACK')
elif call_type[0] == False:
for i in BRIDGES.items():
for d in i[1]:
if dst_id == d['TGID']:
data_target = d['SYSTEM']
reactor.callFromThread(systems[data_target].send_system,bytes.fromhex(re.sub("b'|'", '', str(data))))
logger.info('Sending data to ' + str(data[10:16])[2:-1] + ' on system ' + data_target)
os.system('rm /tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/' + packet_file)
#routerHBP.send_peer('MASTER-2', bytes.fromhex(re.sub("b'|'", '', str(data))))
## os.system('rm /tmp/.hblink_data_que/' + packet_file)
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
except:
logger.info('aprs except')
# the APRS RX process # the APRS RX process
def aprs_rx(aprs_rx_login, aprs_passcode, aprs_server, aprs_port, aprs_filter, user_ssid): def aprs_rx(aprs_rx_login, aprs_passcode, aprs_server, aprs_port, aprs_filter, user_ssid):
@ -1062,6 +1091,11 @@ def aprs_rx(aprs_rx_login, aprs_passcode, aprs_server, aprs_port, aprs_filter, u
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
def aprs_beacon_send():
beacon_packet = CONFIG['GPS_DATA']['APRS_LOGIN_CALL'] + '>APHBL3,TCPIP*:!' + CONFIG['GPS_DATA']['IGATE_LATITUDE'] + str(CONFIG['GPS_DATA']['IGATE_BEACON_ICON'][0]) + CONFIG['GPS_DATA']['IGATE_LONGITUDE'] + str(CONFIG['GPS_DATA']['IGATE_BEACON_ICON'][1]) + '/' + CONFIG['GPS_DATA']['IGATE_BEACON_COMMENT']
aprs_send(beacon_packet)
logger.info(beacon_packet)
##### DMR data function #### ##### DMR data function ####
def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
# Capture data headers # Capture data headers

View File

@ -501,7 +501,7 @@ def hbnet_web_service():
id = db.Column(db.Integer(), primary_key=True) id = db.Column(db.Integer(), primary_key=True)
author = db.Column(db.String(100), nullable=False, server_default='') author = db.Column(db.String(100), nullable=False, server_default='')
content = db.Column(db.String(150), nullable=False, server_default='') content = db.Column(db.String(150), nullable=False, server_default='')
query = db.Column(db.String(100), nullable=False, server_default='') query_term = db.Column(db.String(100), nullable=False, server_default='', unique=False)
time = db.Column(db.DateTime()) time = db.Column(db.DateTime())
class Misc(db.Model): class Misc(db.Model):
@ -2453,6 +2453,45 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
</tr>''' </tr>'''
return render_template('bb.html', markup_content = Markup(content)) return render_template('bb.html', markup_content = Markup(content))
@app.route('/tp')
def all_tp():
tpl = TinyPage.query.order_by(TinyPage.time.desc()).all()
content = ''' '''
for i in tpl:
content = content + '''
<tr>
<td><strong>''' + i.query_term + '''</strong></td>
<td>''' + i.content + '''</td>
<td>''' + i.author + '''</td>
<td></td>
</tr>'''
return render_template('tp_all.html', markup_content = Markup(content))
@app.route('/add_tp', methods=['POST', 'GET'])
## @app.route('/add_tp')
def new_tp():
u = current_user
print(u.username)
if request.args.get('add_page'):
tp_add(u.username, request.form.get('query'), request.form.get('content'))
content = '''<h3 style="text-align: center;">Saved Tiny Page.</h3>
<p style="text-align: center;">Redirecting in 1 seconds.</p>
<meta http-equiv="refresh" content="1; URL=''' + url + '''/tp" /> '''
else:
content = ''
## tpl = TinyPage.query.order_by(TinyPage.time.desc()).all()
## content = ''' '''
## for i in tpl:
## content = content + '''
## <tr>
## <td><strong>''' + i.query_term + '''</strong></td>
## <td>''' + i.content + '''</td>
## <td>''' + i.author + '''</td>
##
## </tr>'''
return render_template('tp_add.html', markup_content = Markup(content), url = url)
@app.route('/ss') @app.route('/ss')
def get_all_ss(): def get_all_ss():
ss_all = Social.query.order_by(Social.time.desc()).all() ss_all = Social.query.order_by(Social.time.desc()).all()
@ -2854,11 +2893,12 @@ Name: <strong>''' + p.name + '''</strong>&nbsp; -&nbsp; Port: <strong>''' + str(
db.session.add(add_loc) db.session.add(add_loc)
db.session.commit() db.session.commit()
def tp_add(_callsign, _bulletin, _dmr_id, _server, _system_name): def tp_add(_author, _query_term, _content):
add_tp = BulletinBoard( add_tp = TinyPage(
author = _author, author = _author,
query = _query, query_term = _query_term,
content = _content content = _content,
time = datetime.datetime.utcnow(),
) )
db.session.add(add_tp) db.session.add(add_tp)
db.session.commit() db.session.commit()

View File

@ -17,7 +17,7 @@
{# Label on left, "New here? Register." on right #} {# Label on left, "New here? Register." on right #}
<div class="row"> <div class="row">
<div class="col-xs-6"> <div class="col-xs-6">
<label for="{{ field.id }}" class="control-label">{{ field.label.text }}</label> <label for="{{ field.id }}" class="control-label"><strong>{{ field.label.text }}</strong></label>
</div> </div>
<div class="col-xs-6 text-right"> <div class="col-xs-6 text-right">
{% if user_manager.USER_ENABLE_REGISTER and not user_manager.USER_REQUIRE_INVITATION %} {% if user_manager.USER_ENABLE_REGISTER and not user_manager.USER_REQUIRE_INVITATION %}
@ -43,7 +43,7 @@
{# Label on left, "Forgot your Password?" on right #} {# Label on left, "Forgot your Password?" on right #}
<div class="row"> <div class="row">
<div class="col-xs-6"> <div class="col-xs-6">
<label for="{{ field.id }}" class="control-label">{{ field.label.text }}</label> <label for="{{ field.id }}" class="control-label"><strong>{{ field.label.text }}</strong></label>
</div> </div>
<div class="col-xs-6 text-right"> <div class="col-xs-6 text-right">
{% if user_manager.USER_ENABLE_FORGOT_PASSWORD %} {% if user_manager.USER_ENABLE_FORGOT_PASSWORD %}

View File

@ -25,7 +25,7 @@ By registering, you acknowledge that you agree to the Terms of Use.
{# Label on left, "Already registered? Sign in." on right #} {# Label on left, "Already registered? Sign in." on right #}
<div class="row"> <div class="row">
<div class="col-xs-6"> <div class="col-xs-6">
<label for="{{ field.id }}" class="control-label">{{ field.label.text }}</label> <label for="{{ field.id }}" class="control-label"><strong>{{ field.label.text }}</strong></label>
</div> </div>
<div class="col-xs-6 text-right"> <div class="col-xs-6 text-right">
{% if user_manager.USER_ENABLE_REGISTER %} {% if user_manager.USER_ENABLE_REGISTER %}

30
web/templates/tp_add.html Normal file
View File

@ -0,0 +1,30 @@
{% extends 'flask_user/_public_base.html' %}
{% block content %}
<h1 style="text-align: center;">Tiny Pages</h1>
<div class="row">
<div class="col-lg-12">
<form action="?add_page=true" method="post">
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1"><strong>?</strong></span>
<input type="text" id="username" placeholder="Query" name="query" class="form-control" aria-label="Query" aria-describedby="basic-addon1">
</div>
<div class="input-group">
<span class="input-group-text">Content</span>
<textarea id="message" name="content" class="form-control" aria-label="Content"></textarea>
</div>
<br />
<p style="text-align: center;"><input class="btn btn-primary" type="submit" value="Add" /></form></p>
</div>
</div>
<p>&nbsp;</p>
{% endblock %}

32
web/templates/tp_all.html Normal file
View File

@ -0,0 +1,32 @@
{% extends 'flask_user/_public_base.html' %}
{% block content %}
<h1 style="text-align: center;">Tiny Pages</h1>
<div class="row">
<div class="col-lg-12">
{% if call_or_get(current_user.is_authenticated) %}
<button type="button" class="btn btn-primary">Add Tiny Page</button>
{% endif %}
<table data-toggle="table" data-pagination="true" data-search="true" >
<thead>
<tr>
<th>Query</th>
<th>Content</th>
<th>Author</th>
<th>Options</th>
</tr>
</thead>
<tbody>
{{markup_content}}
</tbody></table>
</div>
</div>
<p>&nbsp;</p>
{% endblock %}