diff --git a/data_gateway.py b/data_gateway.py index 780673a..7f0ac8e 100644 --- a/data_gateway.py +++ b/data_gateway.py @@ -234,6 +234,23 @@ def send_unit_table(CONFIG, _data): except requests.ConnectionError: logger.error('Config server unreachable') +def send_sms_que_req(CONFIG): + user_man_url = CONFIG['WEB_SERVICE']['URL'] + shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest()) + sms_req_data = { + 'get_sms_que': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'], + 'secret':shared_secret, + } + json_object = json.dumps(sms_req_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['que'] + except requests.ConnectionError: + logger.error('Config server unreachable') + @@ -897,7 +914,11 @@ def create_sms_seq(dst_id, src_id, peer_id, _slot, _call_type, dmr_string): mmdvm_send_seq.append(ahex(the_mmdvm_pkt)) cap_in = cap_in + 1 print(ahex(the_mmdvm_pkt)) - systems[UNIT_MAP[bytes.fromhex(dst_id)][0]].send_system(the_mmdvm_pkt) + if bytes.fromhex(dst_id) in UNIT_MAP: + systems[UNIT_MAP[bytes.fromhex(dst_id)][0]].send_system(the_mmdvm_pkt) + else: + systems['MASTER-1'].send_system(the_mmdvm_pkt) + print('need to code, flood all systems , ' + str(bytes.fromhex(dst_id) )) with open('/tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/' + str(random.randint(1000, 9999)) + '.mmdvm_seq', "w") as packet_write_file: packet_write_file.write(str(mmdvm_send_seq)) @@ -973,18 +994,19 @@ def send_sms(csbk, to_id, from_id, peer_id, call_type, msg): peer_id = str(hex(peer_id))[2:].zfill(8) if call_type == 'unit': call_type = 1 - # Try to find slot from UNIT_MAP - try: - #Slot 2 - if UNIT_MAP[bytes.fromhex(to_id)][2] == 2: - slot = 1 - # Slot 1 - if UNIT_MAP[bytes.fromhex(to_id)][2] == 1: - slot = 0 - except Exception as e: - logger.info(e) - # Change to config value later - slot = 1 + slot = 1 +## # Try to find slot from UNIT_MAP +## try: +## #Slot 2 +## if UNIT_MAP[bytes.fromhex(to_id)][2] == 2: +## slot = 1 +## # Slot 1 +## if UNIT_MAP[bytes.fromhex(to_id)][2] == 1: +## slot = 0 +## except Exception as e: +## logger.info(e) +## # Change to config value later +## slot = 1 if call_type == 'group': call_type = 0 # Send all Group data to TS 2, need to fix later. @@ -1059,6 +1081,9 @@ def aprs_process(packet): try: if 'msgNo' in aprslib.parse(packet): #sleep(1) + + # Write function to check UNIT_MAP and see if X amount of time has passed, if time passed, no ACK. This will prevent multiple gateways from + # ACKing. time of 24hrs? logger.info(str(aprslib.parse(packet)['addresse']) + '>APHBL3,TCPIP*:' + ':' + str(aprslib.parse(packet)['from'].ljust(9)) +':ack' + str(aprslib.parse(packet)['msgNo'])) aprs_send(str(aprslib.parse(packet)['addresse']) + '>APHBL3,TCPIP*:' + ':' + str(aprslib.parse(packet)['from'].ljust(9)) +':ack' + str(aprslib.parse(packet)['msgNo'])) logger.info('Send ACK') @@ -1378,6 +1403,16 @@ def rule_timer_loop(): logger.debug('Removed unit(s) %s from UNIT_MAP', remove_list) ping(CONFIG) send_unit_table(CONFIG, UNIT_MAP) + send_que = send_sms_que_req(CONFIG) + print(type(send_sms_que_req(CONFIG))) + print(send_sms_que_req(CONFIG)) + for i in send_que: + try: + send_sms(False, i['rcv_id'], 0000, 0000, 'unit', i['msg']) + except Exception as e: + logger.info('Error sending SMS in que to ' + str(i['rcv_id']) + ' - ' + i['msg']) + logger.info(e) + class OBP(OPENBRIDGE): @@ -1446,7 +1481,9 @@ class HBP(HBSYSTEM): def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): UNIT_MAP[_rf_src] = (self._system, time()) + print(_dtype_vseq) print('MMDVM RCVD') + print(UNIT_MAP) if _rf_src not in PACKET_MATCH: PACKET_MATCH[_rf_src] = [_data, time()] elif _data == PACKET_MATCH[_rf_src][0] and time() - 1 < PACKET_MATCH[_rf_src][1]: @@ -1455,10 +1492,13 @@ class HBP(HBSYSTEM): pass else: PACKET_MATCH[_rf_src] = [_data, time()] - if _dtype_vseq in [3,6,7] and _call_type == 'unit' or _call_type == 'group' and _dytpe_vseq == 6 or _call_type == 'vcsbk': - data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data) - else: - pass + try: + if _dtype_vseq in [3,6,7] and _call_type == 'unit' or _call_type == 'group' and _dytpe_vseq == 6 or _call_type == 'vcsbk': + data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data) + else: + pass + except Exception as e: + logger.error('Error, possibly received voice group call.') ## pass @@ -1605,7 +1645,7 @@ if __name__ == '__main__': # Initialize the rule timer -- this if for user activated stuff rule_timer_task = task.LoopingCall(rule_timer_loop) - rule_timer = rule_timer_task.start(60) + rule_timer = rule_timer_task.start(20) rule_timer.addErrback(loopingErrHandle) if 'N0CALL' in aprs_callsign: diff --git a/web/app.py b/web/app.py index 622c252..2c26414 100644 --- a/web/app.py +++ b/web/app.py @@ -2792,6 +2792,14 @@ TG #: ''' + str(tg_d.tg) + ''' content = '''
Redirecting in 1 seconds.
''' + + elif request.args.get('send_sms'): + sms_que_add(current_user.username, '', 0, int(request.form.get('dmr_id')), 'motorola', 'unit', 'DATA', '', request.form.get('message')) + content = '''Redirecting in 1 seconds.
+ ''' + + else: show_mailbox = True @@ -2936,11 +2944,32 @@ Name: ''' + p.name + ''' - Port: ''' + str( que_list = [] for i in que_db: print(i) + que_list.append({'snd_call': i.snd_callsign, 'rcv_id': i.rcv_id, 'msg_type': i.msg_type, 'call_type': i.call_type, 'msg': i.message}) + return que_list - def sms_que_add(): - pass - def sms_que_purge(): - pass + def sms_que_add(_snd_call, _rcv_call, _snd_id, _rcv_id, _msg_type, _call_type, _server, _system_name, _msg): + sqa = SMS_Que( + snd_callsign = _snd_call, + rcv_callsign = _rcv_call, + message = _msg, + time = datetime.datetime.utcnow(), + server = _server, + system_name = _system_name, + snd_id = _snd_id, + rcv_id = _rcv_id, + msg_type = _msg_type, + call_type = _call_type + ) + db.session.add(sqa) + db.session.commit() + + + def sms_que_purge(_server): + sqd = SMS_Que.query.filter_by(server=_server).all() + + for i in sqd: + db.session.delete(i) + db.session.commit() def get_peer_configs(_server_name): mmdvm_pl = mmdvmPeer.query.filter_by(server=_server_name).filter_by(enabled=True).all() @@ -6783,16 +6812,19 @@ Name: ''' + p.name + ''' - Port: ''' + str( ## except: ## message = jsonify(message='Config error') ## response = make_response(message, 401) - . + elif 'get_sms_que' in hblink_req: - if hblink_req['get_sms_que']: + if hblink_req['get_sms_que']: + q = sms_que('DATA') + print(q) response = jsonify( - que=server_get(hblink_req['get_config']) + que=q ## OBP=get_OBP(hblink_req['get_config']) - ) + ) + sms_que_purge('DATA') elif 'get_rules' in hblink_req: if hblink_req['get_rules']: # == 'burn_list': diff --git a/web/templates/mail.html b/web/templates/mail.html index 52d71a2..e57cf80 100644 --- a/web/templates/mail.html +++ b/web/templates/mail.html @@ -29,12 +29,43 @@ + + + +