diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index d42414e2..36a1dbca 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -65,6 +65,23 @@ def lookup(self, token): return super().lookup(token) +class TokenFileName(BasePlugin): + # source is a directory + # token is filename + # contents of file is host:port + def __init__(self, src): + super().__init__(src) + if not os.path.isdir(src): + raise Exception("TokenFileName plugin requires a directory") + + def lookup(self, token): + token = os.path.basename(token) + path = os.path.join(self.source, token) + if os.path.exists(path): + return open(path).read().strip().split(':') + else: + return None + class BaseTokenAPI(BasePlugin): # source is a url with a '%s' in it where the token