mirror of https://github.com/kf7eel/hbnet.git
misc clean up
This commit is contained in:
parent
e784c033e1
commit
d8b2d94cef
57
bridge.py
57
bridge.py
|
|
@ -89,30 +89,30 @@ __email__ = 'kf7eel@qsl.net'
|
|||
|
||||
##import os, ast
|
||||
|
||||
# Function to download rules
|
||||
def update_tg(CONFIG, mode, dmr_id, data):
|
||||
user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
update_srv = {
|
||||
'update_tg':CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||
'secret':shared_secret,
|
||||
'dmr_id': dmr_id,
|
||||
## 'ts1': data['ts1'],
|
||||
## 'ts2': data['ts2'],
|
||||
'mode': mode,
|
||||
'data': data
|
||||
}
|
||||
## print(rules_check)
|
||||
json_object = json.dumps(update_srv, 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, defaulting to local config')
|
||||
## return config.build_config(cli_file)
|
||||
### Function to download rules
|
||||
##def update_tg(CONFIG, mode, dmr_id, data):
|
||||
## user_man_url = CONFIG['WEB_SERVICE']['URL']
|
||||
## shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
|
||||
## update_srv = {
|
||||
## 'update_tg':CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
|
||||
## 'secret':shared_secret,
|
||||
## 'dmr_id': dmr_id,
|
||||
#### 'ts1': data['ts1'],
|
||||
#### 'ts2': data['ts2'],
|
||||
## 'mode': mode,
|
||||
## 'data': data
|
||||
## }
|
||||
#### print(rules_check)
|
||||
## json_object = json.dumps(update_srv, 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, defaulting to local config')
|
||||
#### return config.build_config(cli_file)
|
||||
|
||||
|
||||
def send_unit_table(CONFIG, _data):
|
||||
|
|
@ -377,7 +377,7 @@ def hotspot_proxy(listen_port, port_start, port_stop):
|
|||
reactor.listenUDP(ListenPort,Proxy(Master,ListenPort,CONNTRACK,BlackList,Timeout,Debug,ClientInfo,DestportStart,DestPortEnd),interface=ListenIP)
|
||||
|
||||
def loopingErrHandle(failure):
|
||||
print('(GLOBAL) STOPPING REACTOR TO AVOID MEMORY LEAK: Unhandled error innowtimed loop.\n {}'.format(failure))
|
||||
logger.info('(GLOBAL) STOPPING REACTOR TO AVOID MEMORY LEAK: Unhandled error innowtimed loop.\n {}'.format(failure))
|
||||
reactor.stop()
|
||||
|
||||
def stats():
|
||||
|
|
@ -390,7 +390,7 @@ def hotspot_proxy(listen_port, port_start, port_stop):
|
|||
totalPorts = DestPortEnd - DestportStart
|
||||
freePorts = totalPorts - count
|
||||
|
||||
print("{} ports out of {} in use ({} free)".format(count,totalPorts,freePorts))
|
||||
logger.info("{} ports out of {} in use ({} free)".format(count,totalPorts,freePorts))
|
||||
|
||||
|
||||
|
||||
|
|
@ -585,7 +585,6 @@ def rule_timer_loop(unit_flood_time):
|
|||
|
||||
# run this every 10 seconds to trim orphaned stream ids
|
||||
def stream_trimmer_loop():
|
||||
print(UNIT_MAP)
|
||||
ping(CONFIG)
|
||||
logger.debug('(ROUTER) Trimming inactive stream IDs from system lists')
|
||||
_now = time()
|
||||
|
|
@ -851,8 +850,8 @@ class routerOBP(OPENBRIDGE):
|
|||
dmrpkt = _data[20:53]
|
||||
_bits = _data[15]
|
||||
|
||||
print('Src: ' + str(int_id(_rf_src)))
|
||||
print('Dst: ' + str(int_id(_dst_id)))
|
||||
logger.debug('Src: ' + str(int_id(_rf_src)))
|
||||
logger.debug('Dst: ' + str(int_id(_dst_id)))
|
||||
|
||||
# Make/update this unit in the UNIT_MAP cache
|
||||
UNIT_MAP[_rf_src] = (self.name, pkt_time)
|
||||
|
|
|
|||
|
|
@ -991,9 +991,9 @@ def create_sms_seq(dst_id, src_id, peer_id, _slot, _call_type, dmr_string):
|
|||
mmdvm_send_seq.append(the_mmdvm_pkt)
|
||||
cap_in = cap_in + 1
|
||||
|
||||
if CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED'] == False:
|
||||
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))
|
||||
## if CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED'] == False:
|
||||
## 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))
|
||||
|
||||
return mmdvm_send_seq
|
||||
## return the_mmdvm_pkt
|
||||
|
|
@ -1539,8 +1539,8 @@ def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _fr
|
|||
float(loc.lon)
|
||||
## if int_id(_dst_id) == data_id:
|
||||
if int_id(_dst_id) in data_id:
|
||||
aprs_send(aprs_loc_packet)
|
||||
dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time(), comment, int_id(_rf_src))
|
||||
aprs_send(aprs_loc_packet)
|
||||
except Exception as error_exception:
|
||||
logger.error('Failed to parse packet. Packet may be deformed. Not uploaded.')
|
||||
logger.error(error_exception)
|
||||
|
|
@ -1665,46 +1665,46 @@ class OBP(OPENBRIDGE):
|
|||
logger.debug('SVRD RCV')
|
||||
if _mode == b'UNIT':
|
||||
UNIT_MAP[_data] = (self._system, time())
|
||||
## if _mode == b'DATA' or _mode == b'MDAT':
|
||||
#### print(ahex(_data))
|
||||
## # DMR Data packet, sent via SVRD
|
||||
## _peer_id = _data[11:15]
|
||||
## _seq = _data[4]
|
||||
## _rf_src = _data[5:8]
|
||||
## _dst_id = _data[8:11]
|
||||
## _bits = _data[15]
|
||||
## _slot = 2 if (_bits & 0x80) else 1
|
||||
## #_call_type = 'unit' if (_bits & 0x40) else 'group'
|
||||
## if _bits & 0x40:
|
||||
## _call_type = 'unit'
|
||||
## elif (_bits & 0x23) == 0x23:
|
||||
## _call_type = 'vcsbk'
|
||||
## else:
|
||||
## _call_type = 'group'
|
||||
## _frame_type = (_bits & 0x30) >> 4
|
||||
## _dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F
|
||||
## _stream_id = _data[16:20]
|
||||
##
|
||||
#### print(int_id(_peer_id))
|
||||
#### print(int_id(_rf_src))
|
||||
#### print(int_id(_dst_id))
|
||||
#### print((_dtype_vseq))
|
||||
#### print(ahex(bptc_decode(_data)))
|
||||
##
|
||||
## if _mode == b'MDAT' or _mode == b'DATA':
|
||||
## print('MDAT')
|
||||
## if _rf_src not in PACKET_MATCH:
|
||||
## PACKET_MATCH[_rf_src] = [_seq, time()]
|
||||
## if _seq == PACKET_MATCH[_rf_src][0] and time() - 1 < PACKET_MATCH[_rf_src][1]:
|
||||
## print('matched, dropping')
|
||||
## pass
|
||||
##
|
||||
## else:
|
||||
## print('no match')
|
||||
## if _mode == b'MDAT':
|
||||
## data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data, True)
|
||||
## if _mode == b'DATA':
|
||||
## data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
|
||||
if _mode == b'DATA' or _mode == b'MDAT':
|
||||
## print(ahex(_data))
|
||||
# DMR Data packet, sent via SVRD
|
||||
_peer_id = _data[11:15]
|
||||
_seq = _data[4]
|
||||
_rf_src = _data[5:8]
|
||||
_dst_id = _data[8:11]
|
||||
_bits = _data[15]
|
||||
_slot = 2 if (_bits & 0x80) else 1
|
||||
#_call_type = 'unit' if (_bits & 0x40) else 'group'
|
||||
if _bits & 0x40:
|
||||
_call_type = 'unit'
|
||||
elif (_bits & 0x23) == 0x23:
|
||||
_call_type = 'vcsbk'
|
||||
else:
|
||||
_call_type = 'group'
|
||||
_frame_type = (_bits & 0x30) >> 4
|
||||
_dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F
|
||||
_stream_id = _data[16:20]
|
||||
|
||||
## print(int_id(_peer_id))
|
||||
## print(int_id(_rf_src))
|
||||
## print(int_id(_dst_id))
|
||||
## print((_dtype_vseq))
|
||||
## print(ahex(bptc_decode(_data)))
|
||||
|
||||
if _mode == b'MDAT' or _mode == b'DATA':
|
||||
print('MDAT')
|
||||
if _rf_src not in PACKET_MATCH:
|
||||
PACKET_MATCH[_rf_src] = [_seq, time()]
|
||||
if _seq == PACKET_MATCH[_rf_src][0] and time() - 1 < PACKET_MATCH[_rf_src][1]:
|
||||
print('matched, dropping')
|
||||
pass
|
||||
|
||||
else:
|
||||
print('no match')
|
||||
if _mode == b'MDAT':
|
||||
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data, True)
|
||||
if _mode == b'DATA':
|
||||
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
|
||||
|
||||
|
||||
|
||||
|
|
@ -1791,7 +1791,6 @@ if __name__ == '__main__':
|
|||
#### use_api = CONFIG['DATA_CONFIG']['USE_API']
|
||||
|
||||
if CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED'] == True:
|
||||
#### if 'DUAL_DASH' in CONFIG['WEB_SERVICE']['']
|
||||
pass
|
||||
if CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED'] == False:
|
||||
# Check if user_settings (for APRS settings of users) exists. Creat it if not.
|
||||
|
|
@ -1858,7 +1857,7 @@ if __name__ == '__main__':
|
|||
ten_loop.addErrback(loopingErrHandle)
|
||||
|
||||
if 'N0CALL' in aprs_callsign:
|
||||
logger.info('APRS callsighn set to N0CALL, packet not sent.')
|
||||
logger.info('APRS callsign set to N0CALL, packet not sent.')
|
||||
pass
|
||||
else:
|
||||
aprs_thread = threading.Thread(target=aprs_rx, args=(aprs_callsign, aprs_passcode, aprs_server, aprs_port, aprs_filter, user_ssid,))
|
||||
|
|
|
|||
13
hblink.py
13
hblink.py
|
|
@ -325,7 +325,7 @@ class HBSYSTEM(DatagramProtocol):
|
|||
try:
|
||||
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
|
||||
resp = json.loads(req.text)
|
||||
print(resp)
|
||||
logger.debug(resp)
|
||||
return resp
|
||||
except requests.ConnectionError:
|
||||
return {'allow':True}
|
||||
|
|
@ -369,11 +369,9 @@ class HBSYSTEM(DatagramProtocol):
|
|||
'software': re.sub("b'|'|\s\s+", '', str(soft))
|
||||
}
|
||||
json_object = json.dumps(peer_loc_conf, indent = 4)
|
||||
print()
|
||||
print()
|
||||
print(json_object)
|
||||
print()
|
||||
print()
|
||||
|
||||
logger.debug(json_object)
|
||||
|
||||
try:
|
||||
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
|
||||
# resp = json.loads(req.text)
|
||||
|
|
@ -625,13 +623,12 @@ class HBSYSTEM(DatagramProtocol):
|
|||
else:
|
||||
user_auth = False
|
||||
elif self._config['USE_USER_MAN'] == False:
|
||||
print('False')
|
||||
logger.debug('False, not using user manager')
|
||||
b_acl = self._config['REG_ACL']
|
||||
if self._CONFIG['WEB_SERVICE']['REMOTE_CONFIG_ENABLED'] == True:
|
||||
# If UMS is False, and Rmote Confir True
|
||||
if acl_check(_peer_id, self._CONFIG['GLOBAL']['REG_ACL']) and acl_check(_peer_id, self._config['REG_ACL']):
|
||||
user_auth = True
|
||||
print(self._CONFIG['GLOBAL']['REG_ACL'])
|
||||
else:
|
||||
user_auth = False
|
||||
#If UMS and Remot Config False
|
||||
|
|
|
|||
|
|
@ -7007,7 +7007,7 @@ Name: <strong>''' + p.name + '''</strong> - Port: <strong>''' + str(
|
|||
'''
|
||||
b_list = b_list + '''</tbody></table>
|
||||
<h3 style="text-align: center;">View/Edit Rules (Bridges)</h3>
|
||||
/
|
||||
|
||||
'''
|
||||
r_list = ''
|
||||
for i in s:
|
||||
|
|
|
|||
Loading…
Reference in New Issue