diff --git a/hblink.py b/hblink.py index ea1ca39..70d552e 100755 --- a/hblink.py +++ b/hblink.py @@ -495,6 +495,7 @@ class HBSYSTEM(DatagramProtocol): _salt_str = bytes_4(_this_peer['SALT']) #print(self.ums_response) if self._config['USE_USER_MAN'] == True: +## print(self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE']) try: if self.ums_response['mode'] == 'legacy': _calc_hash = bhex(sha256(_salt_str+self._config['PASSPHRASE']).hexdigest()) @@ -503,16 +504,24 @@ class HBSYSTEM(DatagramProtocol): if self.ums_response['mode'] == 'normal': _new_peer_id = bytes_4(int(str(int_id(_peer_id))[:7])) ## print(int_id(_new_peer_id)) - 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))) + #print(self._CONFIG['USER_MANAGER']['APPEND_INT']) + if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == True: + 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 = base64.b64encode((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big')) - print(calc_passphrase) + calc_passphrase = calc_passphrase[-8:] + if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False: + 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_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest()) ums_down = False except Exception as e: ## # If UMS down, default to base 64 auth ## logger.info(e) _new_peer_id = bytes_4(int(str(int_id(_peer_id))[:7])) - 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 = 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 = calc_passphrase[-8:] + if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False: + 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_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest()) ums_down = True if self._config['USE_USER_MAN'] == False: diff --git a/user_managment/app.py b/user_managment/app.py index 86eb94b..1c1d656 100644 --- a/user_managment/app.py +++ b/user_managment/app.py @@ -35,7 +35,7 @@ def gen_passphrase(dmr_id): return str(calc_passphrase)[-9:-1] elif use_short_passphrase ==False: return str(calc_passphrase)[2:-1] - +# Query radioid.net for list of IDs def get_ids(callsign): try: url = "https://www.radioid.net" @@ -49,6 +49,32 @@ def get_ids(callsign): except: return '' +# Return string in NATO phonetics +def convert_nato(string): + d_nato = { 'A': 'ALPHA', 'B': 'BRAVO', 'C': 'CHARLIE', 'D': 'DELTA', + 'E': 'ECHO', 'F': 'FOXTROT', 'G': 'GOLF', 'H': 'HOTEL', + 'I': 'INDIA', 'J': 'JULIETT','K': 'KILO', 'L': 'LIMA', + 'M': 'MIKE', 'N': 'NOVEMBER','O': 'OSCAR', 'P': 'PAPA', + 'Q': 'QUEBEC', 'R': 'ROMEO', 'S': 'SIERRA', 'T': 'TANGO', + 'U': 'UNIFORM', 'V': 'VICTOR', 'W': 'WHISKEY', 'X': 'X-RAY', + 'Y': 'YANKEE', 'Z': 'ZULU', '0': 'zero', '1': 'one', + '2': 'two', '3': 'three', '4': 'four', '5': 'five', + '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', + 'a': 'alpha', 'b': 'bravo', 'c': 'charlie', 'd': 'delta', + 'e': 'echo', 'f': 'foxtrot', 'g': 'golf', 'h': 'hotel', + 'i': 'india', 'j': 'juliett','k': 'kilo', 'l': 'lima', + 'm': 'mike', 'n': 'november','o': 'oscar', 'p': 'papa', + 'q': 'quebec', 'r': 'romeo', 's': 'sierra', 't': 'tango', + 'u': 'uniform', 'v': 'victor', 'w': 'whiskey', 'x': 'x-ray', + 'y': 'yankee', 'z': 'Zulu'} + ns = '' + for c in string: + try: + ns = ns + d_nato[c] + ' ' + except: + ns = ns + c + ' ' + return ns + # Class-based application configuration class ConfigClass(object): """ Flask application config """ @@ -249,24 +275,58 @@ def create_app(): ## print(request.args.get('mode')) ## if request.args.get('mode') == 'generated': print(id_dict) - content = '

Click here for automated Pi-Star script.

 

\n' + content = '\n' for i in id_dict.items(): if i[1] == '': 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 + + + + + + +

Your passphrase for ''' + str(i[0]) + ''':

-

''' + str(gen_passphrase(int(i[0]))) + '''

+

Copy and paste: ''' + str(gen_passphrase(int(i[0]))) + '''

+
+ +

Phonetically spelled: ''' + convert_nato(str(gen_passphrase(int(i[0])))) + '''

+ +

 

''' elif i[1] == 0: - content = content + '''\n

Your passphrase for ''' + str(i[0]) + ''':

-

''' + legacy_passphrase + '''

+ content = content + ''' + + + + + + +
+

Your passphrase for ''' + str(i[0]) + ''':

+

Copy and paste: ''' + legacy_passphrase + '''

+
+

Phonetically spelled: ''' + convert_nato(legacy_passphrase) + '''

+

 

''' else: - content = content + '''\n

Your passphrase for ''' + str(i[0]) + ''':

-

''' + str(i[1]) + '''

+ content = content + ''' + + + + + + +
+

Your passphrase for ''' + str(i[0]) + ''':

+

Copy and paste: ''' + str(i[1]) + '''

+
+

Phonetically spelled: ''' + convert_nato(str(i[1])) + '''

+

 

''' #content = content + '\n\n' + str(script_links[i[0]]) @@ -275,7 +335,7 @@ def create_app(): #return str(content) - return render_template('flask_user_layout.html', markup_content = Markup(content), logo = logo) + return render_template('view_passphrase.html', markup_content = Markup(content), logo = logo) # The Members page is only accessible to authenticated users via the @login_required decorator @app.route('/members') diff --git a/user_managment/templates/view_passphrase.html b/user_managment/templates/view_passphrase.html new file mode 100644 index 0000000..aaf231e --- /dev/null +++ b/user_managment/templates/view_passphrase.html @@ -0,0 +1,34 @@ +{% extends 'flask_user/_public_base.html' %} +{% block content %} +

 

Click here for automated Pi-Star script.

 

+ + + + + + + + +
+ + + + + + + + + + + + + + + + +
Name:My Server
Host/IP:127.0.0.1
Port:62030
+ +
{{markup_content}} +
+

 

+{% endblock %}