From 0268843c29fca51c73343a40ad70401c0ac72238 Mon Sep 17 00:00:00 2001 From: FengbinShi Date: Thu, 11 Jan 2024 16:57:47 +0800 Subject: [PATCH 1/3] feat: TokenFileName --- websockify/token_plugins.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index d42414e2..24c3943b 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -65,6 +65,19 @@ def lookup(self, token): return super().lookup(token) +class TokenFileName(BasePlugin): + def __init__(self, src): + super().__init__(src) + if not os.path.isdir(src): + raise Exception("TokenFileName plugin requires a directory") + + def lookup(self, 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 From 51acdccf269b421e73df4436376aaddf2433db50 Mon Sep 17 00:00:00 2001 From: FengbinShi Date: Thu, 11 Jan 2024 17:03:52 +0800 Subject: [PATCH 2/3] doc --- websockify/token_plugins.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index 24c3943b..a97c277c 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -66,6 +66,9 @@ 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): From 5bba48abd083d5980efd44a7b4974ce316a2defc Mon Sep 17 00:00:00 2001 From: shifengbin Date: Mon, 15 Jan 2024 17:52:16 +0800 Subject: [PATCH 3/3] limit tokenfile in source --- websockify/token_plugins.py | 1 + 1 file changed, 1 insertion(+) diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index a97c277c..36a1dbca 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -75,6 +75,7 @@ def __init__(self, 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(':')