diff --git a/data_gateway.py b/data_gateway.py index 138104c..0f1156e 100644 --- a/data_gateway.py +++ b/data_gateway.py @@ -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')))) diff --git a/web/app.py b/web/app.py index e9728e2..9de9120 100644 --- a/web/app.py +++ b/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(): """+ str(i.time.strftime(time_format)) +""" - """ + i.comment + """ @@ -2348,8 +2348,8 @@ TG #: ''' + str(tg_d.tg) + ''' for i in smsl: content = content + ''' - ''' + i.snd_callsign + ''' \n ''' + str(i.snd_id) + ''' - ''' + i.rcv_callsign + ''' \n ''' + str(i.rcv_id) + ''' +

''' + i.snd_callsign + '''

\n +

''' + i.rcv_callsign + '''

\n ''' + i.message + ''' ''' + i.server + ' - ' + i.system_name + ''' @@ -2363,7 +2363,7 @@ TG #: ''' + str(tg_d.tg) + ''' for i in bbl: content = content + ''' - ''' + i.callsign + ''' \n ''' + str(i.dmr_id) + ''' +

''' + i.callsign + '''

\n ''' + i.bulletin + ''' ''' + str(i.time.strftime(time_format)) + ''' ''' + i.server + ' - ' + i.system_name + ''' @@ -2371,6 +2371,34 @@ TG #: ''' + str(tg_d.tg) + ''' ''' return render_template('bb.html', markup_content = Markup(content)) + @app.route('/ss/') + 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 = ''' +
+
+

''' + ssd.callsign + ' - ' + str(ssd.dmr_id) + '''

\n

''' + str(ssd.time.strftime(time_format)) + '''

+


+

''' + ssd.message + '''

+
+
+ + ''' + for i in ss_all: + post_content = post_content + ''' + + ''' + i.message + ''' + ''' + str(i.time.strftime(time_format)) + ''' + ''' + except: + content = '

Not posts by user.

' + all_post = '' + return render_template('ss.html', markup_content = Markup(content), all_post = Markup(post_content)) + @app.route('/talkgroups/') #, methods=['POST', 'GET']) @login_required def tg_list_server(server): @@ -2617,6 +2645,32 @@ TG #: ''' + str(tg_d.tg) + ''' ) 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 #: ''' + str(tg_d.tg) + ''' 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: diff --git a/web/templates/flask_user_layout.html b/web/templates/flask_user_layout.html index a551dfc..31553a6 100644 --- a/web/templates/flask_user_layout.html +++ b/web/templates/flask_user_layout.html @@ -54,7 +54,7 @@