implement Social Status
This commit is contained in:
parent
9dc5693dd6
commit
e8e6e04f60
@ -193,6 +193,28 @@ def send_bb(CONFIG, callsign, dmr_id, bulletin, system_name):
|
||||
except requests.ConnectionError:
|
||||
logger.error('Config server unreachable')
|
||||
|
||||
|
||||
def send_ss(CONFIG, callsign, message, dmr_id):
|
||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
sms_data = {
|
||||
'ss_update': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||
'secret':shared_secret,
|
||||
'callsign': callsign,
|
||||
'message' : message,
|
||||
'dmr_id' : dmr_id,
|
||||
|
||||
}
|
||||
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')
|
||||
|
||||
|
||||
|
||||
|
||||
@ -495,7 +517,11 @@ def process_sms(_rf_src, sms, call_type, system_name):
|
||||
logger.info(call_type)
|
||||
parse_sms = sms.split(' ')
|
||||
logger.info(parse_sms)
|
||||
if parse_sms[0] == 'ID':
|
||||
if '@SS' in parse_sms[0]:
|
||||
s = ' '
|
||||
post = s.join(parse_sms[1:])
|
||||
send_ss(CONFIG, str(get_alias(int_id(_rf_src), subscriber_ids)), post, int_id(_rf_src))
|
||||
elif parse_sms[0] == 'ID':
|
||||
logger.info(str(get_alias(int_id(_rf_src), subscriber_ids)) + ' - ' + str(int_id(_rf_src)))
|
||||
if call_type == 'unit':
|
||||
send_sms(False, int_id(_rf_src), 0000, 0000, 'unit', 'Your DMR ID: ' + str(int_id(_rf_src)) + ' - ' + str(get_alias(int_id(_rf_src), subscriber_ids)))
|
||||
@ -1253,7 +1279,8 @@ def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _fr
|
||||
|
||||
if int_id(_dst_id) == data_id:
|
||||
process_sms(_rf_src, msg_found, _call_type, UNIT_MAP[_rf_src][0])
|
||||
dashboard_sms_write(str(get_alias(int_id(_rf_src), subscriber_ids)), str(get_alias(int_id(_dst_id), subscriber_ids)), int_id(_dst_id), int_id(_rf_src), msg_found, time(), UNIT_MAP[_rf_src][0])
|
||||
if int_id(_dst_id) != data_id:
|
||||
dashboard_sms_write(str(get_alias(int_id(_rf_src), subscriber_ids)), str(get_alias(int_id(_dst_id), subscriber_ids)), int_id(_dst_id), int_id(_rf_src), msg_found, time(), UNIT_MAP[_rf_src][0])
|
||||
#packet_assembly = ''
|
||||
pass
|
||||
#logger.info(bitarray(re.sub("\)|\(|bitarray|'", '', str(bptc_decode(_data)).tobytes().decode('utf-8', 'ignore'))))
|
||||
|
68
web/app.py
68
web/app.py
@ -494,6 +494,7 @@ def hbnet_web_service():
|
||||
callsign = db.Column(db.String(100), nullable=False, server_default='')
|
||||
message = db.Column(db.String(150), nullable=False, server_default='')
|
||||
time = db.Column(db.DateTime())
|
||||
dmr_id = db.Column(db.Integer(), primary_key=False)
|
||||
|
||||
class Misc(db.Model):
|
||||
__tablename__ = 'misc'
|
||||
@ -817,7 +818,6 @@ def hbnet_web_service():
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: center;"><em>"""+ str(i.time.strftime(time_format)) +"""</em></td>
|
||||
""" + i.comment + """
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -2348,8 +2348,8 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
for i in smsl:
|
||||
content = content + '''
|
||||
<tr>
|
||||
<td>''' + i.snd_callsign + ''' \n ''' + str(i.snd_id) + '''</td>
|
||||
<td>''' + i.rcv_callsign + ''' \n ''' + str(i.rcv_id) + '''</td>
|
||||
<td><p style="text-align: center;"><strong>''' + i.snd_callsign + '''</strong></p> \n <a href="/ss/''' + str(i.snd_id) + '''"><button type="button" class="btn btn-warning">''' + str(i.snd_id) + '''</button></a></td>
|
||||
<td><p style="text-align: center;"><strong>''' + i.rcv_callsign + '''</strong></p> \n <a href="/ss/''' + str(i.rcv_id) + '''"><button type="button" class="btn btn-warning">''' + str(i.rcv_id) + '''</button></a></td>
|
||||
<td>''' + i.message + '''</td>
|
||||
<td>''' + i.server + ' - ' + i.system_name + '''</td>
|
||||
|
||||
@ -2363,7 +2363,7 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
for i in bbl:
|
||||
content = content + '''
|
||||
<tr>
|
||||
<td>''' + i.callsign + ''' \n ''' + str(i.dmr_id) + '''</td>
|
||||
<td><p style="text-align: center;"><strong>''' + i.callsign + '''<strong></p> \n <a href="/ss/''' + str(i.dmr_id) + '''"><button type="button" class="btn btn-warning">''' + str(i.dmr_id) + '''</button></a></td>
|
||||
<td>''' + i.bulletin + '''</td>
|
||||
<td>''' + str(i.time.strftime(time_format)) + '''</td>
|
||||
<td>''' + i.server + ' - ' + i.system_name + '''</td>
|
||||
@ -2371,6 +2371,34 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
</tr>'''
|
||||
return render_template('bb.html', markup_content = Markup(content))
|
||||
|
||||
@app.route('/ss/<dmr_id>')
|
||||
def get_ss(dmr_id):
|
||||
try:
|
||||
ssd = Social.query.filter_by(dmr_id=dmr_id).order_by(Social.time.desc()).first()
|
||||
ss_all = Social.query.filter_by(dmr_id=dmr_id).order_by(Social.time.desc()).all()
|
||||
print(ss_all)
|
||||
post_content = ''
|
||||
content = '''
|
||||
<div class="card" style="width: 400px;">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title" style="text-align: center;">''' + ssd.callsign + ' - ' + str(ssd.dmr_id) + '''</h4>\n <p style="text-align: center;">''' + str(ssd.time.strftime(time_format)) + '''</p>
|
||||
<br /><hr /><br />
|
||||
<p class="card-text" style="text-align: center;">''' + ssd.message + '''</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
'''
|
||||
for i in ss_all:
|
||||
post_content = post_content + '''
|
||||
<tr>
|
||||
<td>''' + i.message + '''</td>
|
||||
<td>''' + str(i.time.strftime(time_format)) + '''</td>
|
||||
</tr>'''
|
||||
except:
|
||||
content = '<h4><p style="text-align: center;">Not posts by user.</p></h4>'
|
||||
all_post = ''
|
||||
return render_template('ss.html', markup_content = Markup(content), all_post = Markup(post_content))
|
||||
|
||||
@app.route('/talkgroups/<server>') #, methods=['POST', 'GET'])
|
||||
@login_required
|
||||
def tg_list_server(server):
|
||||
@ -2617,6 +2645,32 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
)
|
||||
db.session.add(add_bb)
|
||||
db.session.commit()
|
||||
|
||||
def del_ss(_dmr_id):
|
||||
try:
|
||||
## ss_post = Social.query.filter_by(dmr_id=_dmr_id).first()
|
||||
## db.session.delete(ss_post)
|
||||
## db.session.commit()
|
||||
ss_post = Social.query.filter_by(dmr_id=_dmr_id).all()
|
||||
for i in ss_post:
|
||||
elap_time = int(datetime.datetime.utcnow().strftime('%s')) - int(i.time.strftime('%s'))
|
||||
# Remove entries more than 1 year old
|
||||
if elap_time > 31536000:
|
||||
db.session.delete(i)
|
||||
|
||||
except:
|
||||
print('Social Status not in DB')
|
||||
pass
|
||||
|
||||
def ss_add(_callsign, _message, _dmr_id):
|
||||
add_ss = Social(
|
||||
callsign = _callsign,
|
||||
message = _message,
|
||||
time = datetime.datetime.utcnow(),
|
||||
dmr_id = _dmr_id
|
||||
)
|
||||
db.session.add(add_ss)
|
||||
db.session.commit()
|
||||
|
||||
def sms_log_add(_snd_call, _rcv_call, _msg, _snd_id, _rcv_id, _server, _system_name):
|
||||
add_sms = SMSLog(
|
||||
@ -6138,7 +6192,11 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
||||
response = 'rcvd'
|
||||
elif 'bb_send' in hblink_req:
|
||||
bb_add(hblink_req['callsign'], hblink_req['bulletin'], hblink_req['dmr_id'], hblink_req['bb_send'], hblink_req['system_name'])
|
||||
trim_sms_log()
|
||||
trim_bb()
|
||||
response = 'rcvd'
|
||||
elif 'ss_update' in hblink_req:
|
||||
del_ss(hblink_req['dmr_id'])
|
||||
ss_add(hblink_req['callsign'], str(hblink_req['message']), hblink_req['dmr_id'])
|
||||
response = 'rcvd'
|
||||
|
||||
elif 'get_config' in hblink_req:
|
||||
|
@ -54,7 +54,7 @@
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="aprs_menu" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-hash"></i> APRS/SMS
|
||||
<i class="bi bi-hash"></i> Data
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="aprs_menu">
|
||||
<li><a class="dropdown-item" href="{{url}}/aprs"><i class="bi bi-geo"></i> APRS Dashboard </a></li>
|
||||
|
31
web/templates/ss.html
Normal file
31
web/templates/ss.html
Normal file
@ -0,0 +1,31 @@
|
||||
{% extends 'flask_user/_public_base.html' %}
|
||||
{% block content %}
|
||||
|
||||
<h1 style="text-align: center;">Social Status</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
{{markup_content}}
|
||||
|
||||
</div>
|
||||
<div class="col-lg-12">
|
||||
<p> </p>
|
||||
|
||||
<table data-toggle="table" data-pagination="true" data-search="true" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Post</th>
|
||||
<th>Time</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{all_post}}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user