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):
|
def send_dash_loc(CONFIG, call, lat, lon, time, comment, dmr_id):
|
||||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||||
ping_data = {
|
loc_data = {
|
||||||
'dashboard': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
'dashboard': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||||
'secret':shared_secret,
|
'secret':shared_secret,
|
||||||
'call': call,
|
'call': call,
|
||||||
@ -139,7 +139,29 @@ def send_dash_loc(CONFIG, call, lat, lon, time, comment, dmr_id):
|
|||||||
'comment' : comment,
|
'comment' : comment,
|
||||||
'dmr_id' : dmr_id
|
'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:
|
try:
|
||||||
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
|
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)
|
## return config.build_config(cli_file)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
# Headers for GPS by model of radio:
|
# Headers for GPS by model of radio:
|
||||||
@ -246,6 +270,9 @@ def dashboard_bb_write(call, dmr_id, time, bulletin):
|
|||||||
#logger.info(dash_bb)
|
#logger.info(dash_bb)
|
||||||
|
|
||||||
def dashboard_sms_write(snd_call, rcv_call, rcv_dmr_id, snd_dmr_id, sms, time):
|
def dashboard_sms_write(snd_call, rcv_call, rcv_dmr_id, snd_dmr_id, sms, time):
|
||||||
|
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:
|
#try:
|
||||||
dash_sms = ast.literal_eval(os.popen('cat ' + sms_file).read())
|
dash_sms = ast.literal_eval(os.popen('cat ' + sms_file).read())
|
||||||
# except:
|
# except:
|
||||||
@ -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')
|
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:
|
if int_id(_dst_id) == data_id:
|
||||||
process_sms(_rf_src, msg_found, _call_type)
|
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 = ''
|
#packet_assembly = ''
|
||||||
pass
|
pass
|
||||||
#logger.info(bitarray(re.sub("\)|\(|bitarray|'", '', str(bptc_decode(_data)).tobytes().decode('utf-8', 'ignore'))))
|
#logger.info(bitarray(re.sub("\)|\(|bitarray|'", '', str(bptc_decode(_data)).tobytes().decode('utf-8', 'ignore'))))
|
||||||
|
44
web/app.py
44
web/app.py
@ -2341,6 +2341,19 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||||||
|
|
||||||
return render_template('tg_all.html', markup_content = Markup(content))
|
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'])
|
@app.route('/talkgroups/<server>') #, methods=['POST', 'GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def tg_list_server(server):
|
def tg_list_server(server):
|
||||||
@ -2576,6 +2589,29 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||||||
db.session.add(add_loc)
|
db.session.add(add_loc)
|
||||||
db.session.commit()
|
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():
|
def trim_dash_loc():
|
||||||
trim_dash = GPS_LocLog.query.all()
|
trim_dash = GPS_LocLog.query.all()
|
||||||
## db.session.delete(delete_b)
|
## db.session.delete(delete_b)
|
||||||
@ -5937,7 +5973,7 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||||||
def data_dash():
|
def data_dash():
|
||||||
|
|
||||||
## dev_loc = GPS_LocLog.query.order_by(time).limit(3).all()
|
## 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 = ''
|
content = ''
|
||||||
dev_lst = []
|
dev_lst = []
|
||||||
for i in dev_loc:
|
for i in dev_loc:
|
||||||
@ -5959,7 +5995,6 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
|
|||||||
def svr_endpoint():
|
def svr_endpoint():
|
||||||
hblink_req = request.json
|
hblink_req = request.json
|
||||||
print((hblink_req))
|
print((hblink_req))
|
||||||
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']:
|
||||||
@ -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'])
|
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()
|
trim_dash_loc()
|
||||||
response = 'yes'
|
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:
|
elif 'get_config' in hblink_req:
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<p> </p>
|
<p> </p>
|
||||||
<div class="row container-fluid" >
|
|
||||||
<div class="col-sm-12">
|
|
||||||
<h1 style="text-align: center;">Last Known Location</h1>
|
<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" >
|
<table data-toggle="table" data-pagination="true" data-search="true" >
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu" aria-labelledby="aprs_menu">
|
<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}}/aprs">APRS Dashboard</a></li>
|
||||||
|
<li><a class="dropdown-item" href="{{url}}/sms">SMS Log</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
28
web/templates/sms.html
Normal file
28
web/templates/sms.html
Normal file
@ -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…
x
Reference in New Issue
Block a user