add SMS log
This commit is contained in:
parent
d53743e171
commit
857c397693
|
@ -130,7 +130,7 @@ def ping(CONFIG):
|
|||
def send_dash_loc(CONFIG, call, lat, lon, time, comment, dmr_id):
|
||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
ping_data = {
|
||||
loc_data = {
|
||||
'dashboard': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||
'secret':shared_secret,
|
||||
'call': call,
|
||||
|
@ -139,7 +139,29 @@ def send_dash_loc(CONFIG, call, lat, lon, time, comment, dmr_id):
|
|||
'comment' : comment,
|
||||
'dmr_id' : dmr_id
|
||||
}
|
||||
json_object = json.dumps(ping_data, indent = 4)
|
||||
json_object = json.dumps(loc_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 send_sms_log(CONFIG, snd_call, rcv_call, msg, rcv_id, snd_id):
|
||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
sms_data = {
|
||||
'log_sms': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||
'secret':shared_secret,
|
||||
'snd_call': snd_call,
|
||||
'rcv_call': rcv_call,
|
||||
'message' : msg,
|
||||
'snd_id' : snd_id,
|
||||
'rcv_id' : rcv_id
|
||||
}
|
||||
json_object = json.dumps(sms_data, indent = 4)
|
||||
|
||||
try:
|
||||
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
|
||||
|
@ -151,6 +173,8 @@ def send_dash_loc(CONFIG, call, lat, lon, time, comment, dmr_id):
|
|||
## return config.build_config(cli_file)
|
||||
|
||||
|
||||
|
||||
|
||||
##################################################################################################
|
||||
|
||||
# Headers for GPS by model of radio:
|
||||
|
@ -246,15 +270,18 @@ def dashboard_bb_write(call, dmr_id, time, bulletin):
|
|||
#logger.info(dash_bb)
|
||||
|
||||
def dashboard_sms_write(snd_call, rcv_call, rcv_dmr_id, snd_dmr_id, sms, time):
|
||||
#try:
|
||||
dash_sms = ast.literal_eval(os.popen('cat ' + sms_file).read())
|
||||
# except:
|
||||
# dash_entries = []
|
||||
dash_sms.insert(0, {'snd_call': snd_call, 'rcv_call':rcv_call, 'snd_dmr_id': snd_dmr_id, 'rcv_dmr_id':rcv_dmr_id, 'time': time, 'sms':sms})
|
||||
with open(sms_file, 'w') as user_sms_file:
|
||||
user_sms_file.write(str(dash_sms[:25]))
|
||||
user_sms_file.close()
|
||||
logger.info('User SMS entry saved.')
|
||||
if CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED'] == True:
|
||||
send_sms_log(CONFIG, snd_call, rcv_call, sms, rcv_dmr_id, snd_dmr_id)
|
||||
else:
|
||||
#try:
|
||||
dash_sms = ast.literal_eval(os.popen('cat ' + sms_file).read())
|
||||
# except:
|
||||
# dash_entries = []
|
||||
dash_sms.insert(0, {'snd_call': snd_call, 'rcv_call':rcv_call, 'snd_dmr_id': snd_dmr_id, 'rcv_dmr_id':rcv_dmr_id, 'time': time, 'sms':sms})
|
||||
with open(sms_file, 'w') as user_sms_file:
|
||||
user_sms_file.write(str(dash_sms[:25]))
|
||||
user_sms_file.close()
|
||||
logger.info('User SMS entry saved.')
|
||||
|
||||
|
||||
def mailbox_write(call, dmr_id, time, message, recipient):
|
||||
|
@ -1201,6 +1228,7 @@ def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _fr
|
|||
logger.info('\n\n' + 'Received SMS from ' + str(get_alias(int_id(_rf_src), subscriber_ids)) + ', DMR ID: ' + str(int_id(_rf_src)) + ': ' + str(msg_found) + '\n')
|
||||
if int_id(_dst_id) == data_id:
|
||||
process_sms(_rf_src, msg_found, _call_type)
|
||||
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())
|
||||
#packet_assembly = ''
|
||||
pass
|
||||
#logger.info(bitarray(re.sub("\)|\(|bitarray|'", '', str(bptc_decode(_data)).tobytes().decode('utf-8', 'ignore'))))
|
||||
|
|
44
web/app.py
44
web/app.py
|
@ -2340,6 +2340,19 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||
</tr>'''
|
||||
|
||||
return render_template('tg_all.html', markup_content = Markup(content))
|
||||
|
||||
@app.route('/sms')
|
||||
def all_sms():
|
||||
smsl = SMSLog.query.order_by(SMSLog.time.desc()).all()
|
||||
content = ''' '''
|
||||
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>''' + i.message + '''</td>
|
||||
</tr>'''
|
||||
return render_template('sms.html', markup_content = Markup(content))
|
||||
|
||||
@app.route('/talkgroups/<server>') #, methods=['POST', 'GET'])
|
||||
@login_required
|
||||
|
@ -2575,7 +2588,30 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||
)
|
||||
db.session.add(add_loc)
|
||||
db.session.commit()
|
||||
|
||||
def sms_log_add(_snd_call, _rcv_call, _msg, _snd_id, _rcv_id, _server, _system_name):
|
||||
add_sms = SMSLog(
|
||||
snd_callsign = _snd_call,
|
||||
rcv_callsign = _rcv_call,
|
||||
message = _msg,
|
||||
time = datetime.datetime.utcnow(),
|
||||
snd_id = _snd_id,
|
||||
rcv_id = _rcv_id,
|
||||
server = _server,
|
||||
system_name = ''
|
||||
)
|
||||
db.session.add(add_sms)
|
||||
db.session.commit()
|
||||
|
||||
def trim_sms_log():
|
||||
trim_sms = SMSLog.query.all()
|
||||
|
||||
for i in trim_sms:
|
||||
elap_time = int(datetime.datetime.utcnow().strftime('%s')) - int(i.time.strftime('%s'))
|
||||
# Remove entries more than 1 month old
|
||||
if elap_time > 2678400:
|
||||
db.session.delete(i)
|
||||
|
||||
def trim_dash_loc():
|
||||
trim_dash = GPS_LocLog.query.all()
|
||||
## db.session.delete(delete_b)
|
||||
|
@ -5937,7 +5973,7 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||
def data_dash():
|
||||
|
||||
## dev_loc = GPS_LocLog.query.order_by(time).limit(3).all()
|
||||
dev_loc = GPS_LocLog.query.order_by(GPS_LocLog.time.desc()).limit(20).all()
|
||||
dev_loc = GPS_LocLog.query.order_by(GPS_LocLog.time.desc()).limit(50).all()
|
||||
content = ''
|
||||
dev_lst = []
|
||||
for i in dev_loc:
|
||||
|
@ -5959,7 +5995,6 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||
def svr_endpoint():
|
||||
hblink_req = request.json
|
||||
print((hblink_req))
|
||||
print(peer_locations)
|
||||
if hblink_req['secret'] in shared_secrets():
|
||||
try:
|
||||
if hblink_req['ping']:
|
||||
|
@ -6059,7 +6094,10 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||
dash_loc_add(hblink_req['call'], hblink_req['lat'], hblink_req['lon'], hblink_req['comment'], hblink_req['dmr_id'], hblink_req['dashboard'])
|
||||
trim_dash_loc()
|
||||
response = 'yes'
|
||||
|
||||
elif 'log_sms' in hblink_req:
|
||||
sms_log_add(hblink_req['snd_call'], hblink_req['rcv_call'], hblink_req['message'], hblink_req['snd_id'], hblink_req['rcv_id'], '', '')
|
||||
trim_sms_log()
|
||||
response = 'rcvd'
|
||||
|
||||
|
||||
elif 'get_config' in hblink_req:
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
{% block content %}
|
||||
|
||||
<p> </p>
|
||||
<div class="row container-fluid" >
|
||||
<div class="col-sm-12">
|
||||
<h1 style="text-align: center;">Last Known Location</h1>
|
||||
|
||||
<div class="row container-fluid" >
|
||||
<div class="col-sm-12">
|
||||
<table data-toggle="table" data-pagination="true" data-search="true" >
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="aprs_menu">
|
||||
<li><a class="dropdown-item" href="{{url}}/aprs">APRS Dashboard</a></li>
|
||||
<li><a class="dropdown-item" href="{{url}}/sms">SMS Log</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
{% extends 'flask_user/_public_base.html' %}
|
||||
{% block content %}
|
||||
|
||||
<h1 style="text-align: center;">SMS Log</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<table data-toggle="table" data-pagination="true" data-search="true" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Senderl</th>
|
||||
<th>Receiver</th>
|
||||
<th>Message</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{markup_content}}
|
||||
|
||||
</tbody></table>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue