diff --git a/setup.py b/setup.py index b487172..c83303e 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ setup(name=name, packages=['websockify'], include_package_data=True, - install_requires=['numpy'], + install_requires=['numpy', 'hashids'], zip_safe=False, entry_points={ 'console_scripts': [ diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index 7a988a3..3ffea42 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -186,3 +186,21 @@ class UnixDomainSocketDirectory(BasePlugin): except Exception as e: print("Error finding unix domain socket: %s" % str(e), file=sys.stderr) return None + +class HashIdToken(BasePlugin): + + def __init__(self, salt_file): + file = open(salt_file, 'r') + self.salt = file.read().rstrip() + + def lookup(self, token): + try: + from hashids import Hashids + + hashids = Hashids(salt = self.salt,min_length=10) + out = hashids.decode(token) + + return ['localost', out[0]] + except Exception as e: + print("Error looking up Hashid token: %s" % str(e)) + return None \ No newline at end of file