change active_tg structure, improve passphrase security
This commit is contained in:
parent
b382ffa21f
commit
7db02fcb4b
21
bridge.py
21
bridge.py
|
@ -380,11 +380,15 @@ def rule_timer_loop():
|
|||
_system['ACTIVE'] = True
|
||||
logger.info('(ROUTER) Conference Bridge TIMEOUT: ACTIVATE System: %s, Bridge: %s, TS: %s, TGID: %s', _system['SYSTEM'], _bridge, _system['TS'], int_id(_system['TGID']))
|
||||
# POST ON
|
||||
## update_tg(CONFIG, 'on', 0, [{'SYSTEM':_system['SYSTEM']}, {'ts':_system['TS']}, {'tg': int_id(_system['TGID'])}])
|
||||
else:
|
||||
timeout_in = _system['TIMER'] - _now
|
||||
logger.info('(ROUTER) Conference Bridge INACTIVE (OFF timer running): System: %s Bridge: %s, TS: %s, TGID: %s, Timeout in: %.2fs,', _system['SYSTEM'], _bridge, _system['TS'], int_id(_system['TGID']), timeout_in)
|
||||
elif _system['ACTIVE'] == True:
|
||||
logger.debug('(ROUTER) Conference Bridge ACTIVE (no change): System: %s Bridge: %s, TS: %s, TGID: %s', _system['SYSTEM'], _bridge, _system['TS'], int_id(_system['TGID']))
|
||||
# POST on
|
||||
## print(_system)
|
||||
## update_tg(CONFIG, 'on', 0, [{'SYSTEM':_system['SYSTEM']}, {'ts':_system['TS']}, {'tg': int_id(_system['TGID'])}])
|
||||
else:
|
||||
logger.debug('(ROUTER) Conference Bridge NO ACTION: System: %s, Bridge: %s, TS: %s, TGID: %s', _system['SYSTEM'], _bridge, _system['TS'], int_id(_system['TGID']))
|
||||
|
||||
|
@ -1095,15 +1099,9 @@ class routerHBP(HBSYSTEM):
|
|||
|
||||
# TGID matches an ACTIVATION trigger
|
||||
if (_dst_id in _system['ON'] or _dst_id in _system['RESET']) and _slot == _system['TS']:
|
||||
# Insert POST for TG timer update?
|
||||
print(self.STATUS[2])
|
||||
print()
|
||||
print(_system['SYSTEM'])
|
||||
print()
|
||||
print(datetime.fromtimestamp(_system['TIMER']).strftime('%H:%M:%S - %m/%d/%y'))
|
||||
|
||||
## update_tg(CONFIG, 'on', int(str(int_id(self.STATUS[2]['RX_PEER']))[:7]), [{'SYSTEM':_system['SYSTEM']}, {'ts1':int_id(self.STATUS[i]['RX_TGID'])}, {'ts1':int_id(self.STATUS[2]['RX_TGID'])}])
|
||||
# POST update TG for self care
|
||||
update_tg(CONFIG, 'on', int(str(int_id(self.STATUS[2]['RX_PEER']))[:7]), [{'SYSTEM':_system['SYSTEM']}, {'ts1':int_id(self.STATUS[1]['RX_TGID'])}, {'ts2':int_id(self.STATUS[2]['RX_TGID'])}])
|
||||
## print(datetime.fromtimestamp(_system['TIMER']).strftime('%H:%M:%S - %m/%d/%y'))
|
||||
|
||||
## update_tg(CONFIG, mode, dmr_id, data)
|
||||
# Set the matching rule as ACTIVE
|
||||
|
@ -1111,12 +1109,7 @@ class routerHBP(HBSYSTEM):
|
|||
if _system['ACTIVE'] == False:
|
||||
_system['ACTIVE'] = True
|
||||
_system['TIMER'] = pkt_time + _system['TIMEOUT']
|
||||
|
||||
|
||||
## print()
|
||||
## print(int_id(self.STATUS[2]['RX_PEER']))
|
||||
## print()
|
||||
|
||||
logger.info('(%s) Bridge: %s, connection changed to state: %s', self._system, _bridge, _system['ACTIVE'])
|
||||
# Cancel the timer if we've enabled an "OFF" type timeout
|
||||
if _system['TO_TYPE'] == 'OFF':
|
||||
|
@ -1136,7 +1129,7 @@ class routerHBP(HBSYSTEM):
|
|||
logger.info('(%s) Bridge: %s, connection changed to state: %s', self._system, _bridge, _system['ACTIVE'])
|
||||
# POST off
|
||||
update_tg(CONFIG, 'off', 0, [{'SYSTEM':_system['SYSTEM']}, {'ts':_system['TS']}, {'tg': int_id(_system['TGID'])}])
|
||||
update_tg(CONFIG, 'on', int(str(int_id(self.STATUS[2]['RX_PEER']))[:7]), [{'SYSTEM':_system['SYSTEM']}, {'ts1':int_id(self.STATUS[1]['RX_TGID'])}, {'ts2':int_id(self.STATUS[2]['RX_TGID'])}])
|
||||
## update_tg(CONFIG, 'on', int(str(int_id(self.STATUS[2]['RX_PEER']))[:7]), [{'SYSTEM':_system['SYSTEM']}, {'ts1':int_id(self.STATUS[1]['RX_TGID'])}, {'ts2':int_id(self.STATUS[2]['RX_TGID'])}])
|
||||
# Cancel the timer if we've enabled an "ON" type timeout
|
||||
if _system['TO_TYPE'] == 'ON':
|
||||
_system['TIMER'] = pkt_time
|
||||
|
|
|
@ -160,8 +160,14 @@ def build_config(_config_file):
|
|||
'URL': config.get(section, 'URL'),
|
||||
'REMOTE_CONFIG_ENABLED': config.getboolean(section, 'REMOTE_CONFIG_ENABLED'),
|
||||
'APPEND_INT': config.getint(section, 'APPEND_INT'),
|
||||
'EXTRA_INT_1': config.getint(section, 'EXTRA_INT_1'),
|
||||
'EXTRA_INT_2': config.getint(section, 'EXTRA_INT_2'),
|
||||
'EXTRA_1': config.get(section, 'EXTRA_1'),
|
||||
'EXTRA_2': config.get(section, 'EXTRA_2'),
|
||||
'SHARED_SECRET': config.get(section, 'SHARED_SECRET'),
|
||||
'SHORTEN_PASSPHRASE': config.getboolean(section, 'SHORTEN_PASSPHRASE'),
|
||||
'SHORTEN_SAMPLE': config.get(section, 'SHORTEN_SAMPLE'),
|
||||
'SHORTEN_LENGTH': config.get(section, 'SHORTEN_LENGTH'),
|
||||
'BURN_FILE': config.get(section, 'BURN_FILE'),
|
||||
'BURN_INT': config.getint(section, 'BURN_INT'),
|
||||
|
||||
|
|
27
hblink.py
27
hblink.py
|
@ -254,7 +254,7 @@ class HBSYSTEM(DatagramProtocol):
|
|||
self.datagramReceived = self.peer_datagramReceived
|
||||
self.dereg = self.peer_dereg
|
||||
|
||||
def check_user_man(self, _id, server_name, peer_ip):
|
||||
def check_user_man(self, _id, server_name, peer_ip, _system):
|
||||
#Change this to a config value
|
||||
user_man_url = self._CONFIG['USER_MANAGER']['URL']
|
||||
shared_secret = str(sha256(self._CONFIG['USER_MANAGER']['SHARED_SECRET'].encode()).hexdigest())
|
||||
|
@ -263,7 +263,8 @@ class HBSYSTEM(DatagramProtocol):
|
|||
'secret':shared_secret,
|
||||
'login_id':int(str(int_id(_id))[:7]),
|
||||
'login_ip': peer_ip,
|
||||
'login_server': server_name
|
||||
'login_server': server_name,
|
||||
'system': _system
|
||||
}
|
||||
json_object = json.dumps(auth_check, indent = 4)
|
||||
try:
|
||||
|
@ -299,7 +300,7 @@ class HBSYSTEM(DatagramProtocol):
|
|||
burn_id = ast.literal_eval(os.popen('cat ' + self._CONFIG['USER_MANAGER']['BURN_FILE']).read())
|
||||
peer_id_trimmed = int(str(int_id(peer_id))[:7])
|
||||
try:
|
||||
print(self.ums_response)
|
||||
## print(self.ums_response)
|
||||
if self.ums_response['mode'] == 'legacy':
|
||||
_calc_hash = bhex(sha256(_salt_str+self._config['PASSPHRASE']).hexdigest())
|
||||
calc_passphrase = self._config['PASSPHRASE']
|
||||
|
@ -311,11 +312,14 @@ class HBSYSTEM(DatagramProtocol):
|
|||
try:
|
||||
if burn_id[peer_id_trimmed]:
|
||||
logger.info('User ID has been burned. Requiring passphrase version: ' + str(burn_id[peer_id_trimmed]))
|
||||
calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))
|
||||
calc_passphrase = sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_1']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_1']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))+ sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_2']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_2']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14]
|
||||
except:
|
||||
calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))
|
||||
# + base64.b64encode(str.encode(str(_new_peer_id) + self._CONFIG['USER_MANAGER']['EXTRA_3'] + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_1'] - self._CONFIG['USER_MANAGER']['APPEND_INT']) + str(_new_peer_id) + self._CONFIG['USER_MANAGER']['EXTRA_2']))
|
||||
calc_passphrase = sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_1']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_1']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) + sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_2']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_2']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14]
|
||||
## print(base64.b64encode(calc_passphrase))
|
||||
if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == True:
|
||||
calc_passphrase = calc_passphrase[-8:]
|
||||
## print(calc_passphrase)
|
||||
calc_passphrase = calc_passphrase[::int(self._CONFIG['USER_MANAGER']['SHORTEN_SAMPLE'])][-int(self._CONFIG['USER_MANAGER']['SHORTEN_LENGTH']):]
|
||||
if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False:
|
||||
pass
|
||||
_calc_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest())
|
||||
|
@ -325,17 +329,17 @@ class HBSYSTEM(DatagramProtocol):
|
|||
_new_peer_id = bytes_4(int(str(int_id(peer_id))[:7]))
|
||||
if peer_id_trimmed in burn_id:
|
||||
logger.info('User ID has been burned. Requiring passphrase version: ' + str(burn_id[peer_id_trimmed]))
|
||||
calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))
|
||||
calc_passphrase = sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_1']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_1']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) + sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_2']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_2']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14]
|
||||
else:
|
||||
calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))
|
||||
calc_passphrase = sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_1']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_1']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) + sha256(str(self._CONFIG['USER_MANAGER']['EXTRA_2']).encode() + str(self._CONFIG['USER_MANAGER']['EXTRA_INT_2']).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14]
|
||||
|
||||
#calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))
|
||||
if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == True:
|
||||
calc_passphrase = calc_passphrase[-8:]
|
||||
calc_passphrase = calc_passphrase[::int(self._CONFIG['USER_MANAGER']['SHORTEN_SAMPLE'])][-int(self._CONFIG['USER_MANAGER']['SHORTEN_LENGTH']):]
|
||||
if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False:
|
||||
pass
|
||||
_calc_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest())
|
||||
print(calc_passphrase)
|
||||
## print(calc_passphrase)
|
||||
# print(_calc_hash)
|
||||
return _calc_hash
|
||||
|
||||
|
@ -520,7 +524,7 @@ class HBSYSTEM(DatagramProtocol):
|
|||
#print(self.check_user_man(_peer_id))
|
||||
if self._config['USE_USER_MAN'] == True:
|
||||
## print(str(_peer_id) + ' - hblink.py')
|
||||
self.ums_response = self.check_user_man(_peer_id, self._CONFIG['USER_MANAGER']['THIS_SERVER_NAME'], _sockaddr[0])
|
||||
self.ums_response = self.check_user_man(_peer_id, self._CONFIG['USER_MANAGER']['THIS_SERVER_NAME'], _sockaddr[0], self._system)
|
||||
## print(self.ums_response)
|
||||
#Will allow anyone to attempt authentication, used for a transition period
|
||||
## if acl_check(_peer_id, self._CONFIG['GLOBAL']['REG_ACL']) and self.ums_response['allow'] or acl_check(_peer_id, self._CONFIG['GLOBAL']['REG_ACL']) and acl_check(_peer_id, self._config['REG_ACL']):
|
||||
|
@ -528,7 +532,6 @@ class HBSYSTEM(DatagramProtocol):
|
|||
user_auth = self.ums_response['allow']
|
||||
else:
|
||||
user_auth = False
|
||||
## print(user_auth)
|
||||
if self._config['USE_USER_MAN'] == False:
|
||||
# print('False')
|
||||
if acl_check(_peer_id, self._CONFIG['GLOBAL']['REG_ACL']) and acl_check(_peer_id, self._config['REG_ACL']):
|
||||
|
|
|
@ -473,12 +473,14 @@ def create_app():
|
|||
#print(b_list)
|
||||
if ui[0] == trimmed_id:
|
||||
if ui[0] != 0:
|
||||
calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))
|
||||
calc_passphrase = hashlib.sha256(str(extra_1).encode() + str(extra_int_1).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big'))))[2:].zfill(8))) + hashlib.sha256(str(extra_2).encode() + str(extra_int_2).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14]
|
||||
burned = True
|
||||
if burned == False:
|
||||
calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))
|
||||
calc_passphrase = hashlib.sha256(str(extra_1).encode() + str(extra_int_1).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + append_int.to_bytes(2, 'big'))))[2:].zfill(8))) + hashlib.sha256(str(extra_2).encode() + str(extra_int_2).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14]
|
||||
if use_short_passphrase == True:
|
||||
return str(calc_passphrase)[-9:-1]
|
||||
trim_pass = str(calc_passphrase)[2:-1]
|
||||
new_pass = trim_pass[::int(shorten_sample)][-int(shorten_length):]
|
||||
return str(new_pass)
|
||||
elif use_short_passphrase ==False:
|
||||
return str(calc_passphrase)[2:-1]
|
||||
|
||||
|
@ -569,63 +571,63 @@ def create_app():
|
|||
@login_required
|
||||
def gen():
|
||||
#print(str(gen_passphrase(3153591))) #(int(i[0])))
|
||||
try:
|
||||
## try:
|
||||
#content = Markup('<strong>The HTML String</strong>')
|
||||
#user_id = request.args.get('user_id')
|
||||
u = current_user
|
||||
## print(u.username)
|
||||
id_dict = ast.literal_eval(u.dmr_ids)
|
||||
#u = User.query.filter_by(username=user).first()
|
||||
## print(user_id)
|
||||
## print(request.args.get('mode'))
|
||||
## if request.args.get('mode') == 'generated':
|
||||
#print(id_dict)
|
||||
content = '\n'
|
||||
for i in id_dict.items():
|
||||
if isinstance(i[1], int) == True and i[1] != 0:
|
||||
link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8)
|
||||
script_links[i[0]] = link_num
|
||||
#print(script_links)
|
||||
content = content + '''\n
|
||||
u = current_user
|
||||
## print(u.username)
|
||||
id_dict = ast.literal_eval(u.dmr_ids)
|
||||
#u = User.query.filter_by(username=user).first()
|
||||
## print(user_id)
|
||||
## print(request.args.get('mode'))
|
||||
## if request.args.get('mode') == 'generated':
|
||||
#print(id_dict)
|
||||
content = '\n'
|
||||
for i in id_dict.items():
|
||||
if isinstance(i[1], int) == True and i[1] != 0:
|
||||
link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8)
|
||||
script_links[i[0]] = link_num
|
||||
#print(script_links)
|
||||
content = content + '''\n
|
||||
<table style="width: 300px;" border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p style="text-align: center;">Your passphrase for <strong>''' + str(i[0]) + '''</strong>:</p>
|
||||
<p style="text-align: center;">Copy and paste: <strong>''' + str(gen_passphrase(int(i[0]))) + '''</strong></p>
|
||||
<p style="text-align: center;">Your passphrase for <strong>''' + str(i[0]) + '''</strong>:</p>
|
||||
<p style="text-align: center;">Copy and paste: <strong>''' + str(gen_passphrase(int(i[0]))) + '''</strong></p>
|
||||
<hr />
|
||||
|
||||
<p style="text-align: center;">Phonetically spelled: <span style="text-decoration: underline;"><em>''' + convert_nato(str(gen_passphrase(int(i[0])))) + '''</em></span></p>
|
||||
<p style="text-align: center;">Phonetically spelled: <span style="text-decoration: underline;"><em>''' + convert_nato(str(gen_passphrase(int(i[0])))) + '''</em></span></p>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p> </p>
|
||||
'''
|
||||
elif i[1] == 0:
|
||||
link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8)
|
||||
script_links[i[0]] = link_num
|
||||
#print(script_links)
|
||||
content = content + '''\n
|
||||
<p> </p>
|
||||
'''
|
||||
elif i[1] == 0:
|
||||
link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8)
|
||||
script_links[i[0]] = link_num
|
||||
#print(script_links)
|
||||
content = content + '''\n
|
||||
<table style="width: 300px;" border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p style="text-align: center;">Your passphrase for <strong>''' + str(i[0]) + '''</strong>:</p>
|
||||
<p style="text-align: center;">Copy and paste: <strong>''' + str(gen_passphrase(int(i[0]))) + '''</strong></p>
|
||||
<p style="text-align: center;">Your passphrase for <strong>''' + str(i[0]) + '''</strong>:</p>
|
||||
<p style="text-align: center;">Copy and paste: <strong>''' + str(gen_passphrase(int(i[0]))) + '''</strong></p>
|
||||
<hr />
|
||||
|
||||
<p style="text-align: center;">Phonetically spelled: <span style="text-decoration: underline;"><em>''' + convert_nato(str(gen_passphrase(int(i[0])))) + '''</em></span></p>
|
||||
<p style="text-align: center;">Phonetically spelled: <span style="text-decoration: underline;"><em>''' + convert_nato(str(gen_passphrase(int(i[0])))) + '''</em></span></p>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p> </p>
|
||||
'''
|
||||
elif i[1] == '':
|
||||
content = content + '''
|
||||
<p> </p>
|
||||
'''
|
||||
elif i[1] == '':
|
||||
content = content + '''
|
||||
<table style="width: 300px;" border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
@ -638,9 +640,9 @@ def create_app():
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p> </p>'''
|
||||
else:
|
||||
content = content + '''
|
||||
<p> </p>'''
|
||||
else:
|
||||
content = content + '''
|
||||
<table style="width: 300px;" border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
@ -653,11 +655,11 @@ def create_app():
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
'''
|
||||
#content = content + '\n\n' + str(script_links[i[0]])
|
||||
except:
|
||||
content = Markup('<strong>No DMR IDs found or other error.</strong>')
|
||||
## except:
|
||||
## content = Markup('<strong>No DMR IDs found or other error.</strong>')
|
||||
|
||||
|
||||
#return str(content)
|
||||
|
@ -1464,8 +1466,20 @@ def create_app():
|
|||
content = '<p style="text-align: center;">Currently active talkgroups. Updated every 2 minutes.</p>'
|
||||
for s in sl:
|
||||
for i in user_ids.items():
|
||||
for ts in active_tgs.items():
|
||||
for x in ts[1]:
|
||||
print(x)
|
||||
print(s.name)
|
||||
## print(active_tgs[s.name])
|
||||
## print(str(active_tgs[ts[1]]))
|
||||
# Remove 0 from TG list
|
||||
try:
|
||||
active_tgs[s.name][x][0]['1'].remove(0)
|
||||
active_tgs[s.name][x][1]['2'].remove(0)
|
||||
except:
|
||||
pass
|
||||
## try:
|
||||
content = content + ''' <table style="width: 500px; margin-left: auto; margin-right: auto;" border="1">
|
||||
content = content + ''' <table style="width: 500px; margin-left: auto; margin-right: auto;" border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align: center;">
|
||||
|
@ -1479,11 +1493,11 @@ def create_app():
|
|||
<tbody>
|
||||
<tr>
|
||||
<td style="width: 85.7px;"><strong>Timeslot 1</strong></td>
|
||||
<td style="width: 377.3px;"> ''' + str(active_tgs[s.name][i[0]][0]['1'])[1:-1] + '''</td>
|
||||
<td style="width: 377.3px;"> ''' + str(active_tgs[s.name][x][0]['1'])[1:-1] + '''</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 85.7px;"><strong>Timeslot 2</strong></td>
|
||||
<td style="width: 377.3px;"> ''' + str(active_tgs[s.name][i[0]][1]['2'])[1:-1] + '''</td>
|
||||
<td style="width: 377.3px;"> ''' + str(active_tgs[s.name][x][1]['2'])[1:-1] + '''</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -4778,7 +4792,8 @@ def create_app():
|
|||
mode='override',
|
||||
value=authorized_peer(hblink_req['login_id'])[1]
|
||||
)
|
||||
active_tgs[hblink_req['login_server']][hblink_req['login_id']] = [{'1':[]}, {'2':[]}, {'SYSTEM': ''}]
|
||||
active_tgs[hblink_req['login_server']][hblink_req['system']] = [{'1':[]}, {'2':[]}, {'SYSTEM': ''}, {'peer_id':hblink_req['login_id']}]
|
||||
print(active_tgs)
|
||||
elif authorized_peer(hblink_req['login_id'])[0] == False:
|
||||
## print('log fail')
|
||||
authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], 'Not Registered', '-', 'Failed')
|
||||
|
@ -4849,36 +4864,87 @@ def create_app():
|
|||
elif 'update_tg' in hblink_req:
|
||||
if hblink_req['update_tg']:
|
||||
print(hblink_req)
|
||||
## print(hblink_req['data'][0]['SYSTEM'])
|
||||
if 'on' == hblink_req['mode']:
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM']
|
||||
## active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']].update({hblink_req['data'][0]['SYSTEM']: [{1:[hblink_req['data'][1]['ts1']]}, {2:[hblink_req['data'][2]['ts2']]}]}) #.update({[hblink_req['dmr_id']]:hblink_req['data']})
|
||||
if hblink_req['data'][1]['ts1'] not in active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']][0]['1']:
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']][0]['1'].append(hblink_req['data'][1]['ts1'])
|
||||
if hblink_req['data'][2]['ts2'] not in active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']][1]['2']:
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']][1]['2'].append(hblink_req['data'][2]['ts2'])
|
||||
## try:
|
||||
if hblink_req['dmr_id'] == 0:
|
||||
print('id 0')
|
||||
## print(active_tgs)
|
||||
for system in active_tgs[hblink_req['update_tg']].items():
|
||||
## print(system)
|
||||
## print('sys')
|
||||
if system[0] == hblink_req['data'][0]['SYSTEM']:
|
||||
print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'])
|
||||
## print(hblink_req['data'][2]['tg'])
|
||||
print('---------')
|
||||
print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'])
|
||||
## print(hblink_req['data'][1]['ts'])
|
||||
if hblink_req['data'][1]['ts'] == 1:
|
||||
#### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1'])
|
||||
|
||||
if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'] == hblink_req['data'][2]['tg']:
|
||||
pass
|
||||
else:
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][2]['tg'])
|
||||
#### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0)
|
||||
if hblink_req['data'][1]['ts'] == 2:
|
||||
if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'] == hblink_req['data'][2]['tg']:
|
||||
pass
|
||||
#### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2'])
|
||||
else:
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['tg'])
|
||||
else:
|
||||
print('---------on------------')
|
||||
print(hblink_req['data'])
|
||||
print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'])
|
||||
print(hblink_req['data'][2]['ts2'])
|
||||
print('-----------------------')
|
||||
## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM']
|
||||
#### active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']].update({hblink_req['data'][0]['SYSTEM']: [{1:[hblink_req['data'][1]['ts1']]}, {2:[hblink_req['data'][2]['ts2']]}]}) #.update({[hblink_req['dmr_id']]:hblink_req['data']})
|
||||
if hblink_req['data'][1]['ts1'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1']:
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][1]['ts1'])
|
||||
if hblink_req['data'][2]['ts2'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']:
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['ts2'])
|
||||
## print('append')
|
||||
#### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0)
|
||||
## print(hblink_req['data'][0]['SYSTEM'])
|
||||
|
||||
## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']])
|
||||
## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['2'])
|
||||
## print(hblink_req['data'][1]['ts2'])
|
||||
## print(active_tgs[hblink_req['update_tg']])
|
||||
|
||||
## except:
|
||||
## pass
|
||||
|
||||
|
||||
elif 'off' == hblink_req['mode']:
|
||||
print('off')
|
||||
for system in active_tgs[hblink_req['update_tg']].items():
|
||||
if system[1][2]['SYSTEM'] == hblink_req['data'][0]['SYSTEM']:
|
||||
## print(system[0])
|
||||
## print(active_tgs[hblink_req['update_tg']][system[0]])
|
||||
new_ts = str(hblink_req['data'][1]['ts'])
|
||||
print(system)
|
||||
if system[0] == hblink_req['data'][0]['SYSTEM']:
|
||||
print('yes it is')
|
||||
#### print(system[0])
|
||||
#### print(active_tgs[hblink_req['update_tg']][system[0]])
|
||||
if hblink_req['data'][1]['ts'] == 1:
|
||||
## print(active_tgs[hblink_req['update_tg']][system[0]][0]['1'])
|
||||
active_tgs[hblink_req['update_tg']][system[0]][0]['1'].remove(hblink_req['data'][2]['tg'])
|
||||
## active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0)
|
||||
#### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1'])
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].remove(hblink_req['data'][2]['tg'])
|
||||
#### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0)
|
||||
if hblink_req['data'][1]['ts'] == 2:
|
||||
## print(active_tgs[hblink_req['update_tg']][system[0]][1]['2'])
|
||||
active_tgs[hblink_req['update_tg']][system[0]][1]['2'].remove(hblink_req['data'][2]['tg'])
|
||||
## active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0)
|
||||
#### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2'])
|
||||
active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].remove(hblink_req['data'][2]['tg'])
|
||||
#### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0)
|
||||
|
||||
|
||||
|
||||
## print()
|
||||
## print(system)
|
||||
## print(system[1][2]['SYSTEM'])
|
||||
print('off')
|
||||
## print('off')
|
||||
## print(hblink_req['data'][1]['ts'])
|
||||
## print(hblink_req['data'][2]['tg'])
|
||||
print(active_tgs)
|
||||
response = 'got it'
|
||||
print(active_tgs)
|
||||
response = 'got it'
|
||||
else:
|
||||
message = jsonify(message='Authentication error')
|
||||
response = make_response(message, 401)
|
||||
|
|
Loading…
Reference in New Issue