From 7472c899db96debf7ee3ad9e4f8d0d538b5eeeff Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 8 Jan 2024 01:38:41 -0500 Subject: [PATCH] use latest websockify, allow user to change port --- .gitignore | 3 ++- README.md | 2 ++ server/main.py | 18 ++++++++++-------- server/run.sh | 5 ++++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index d367d31..7b3cd3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /client/build /client/out -/server/.venv \ No newline at end of file +/server/.venv +/server/websockify \ No newline at end of file diff --git a/README.md b/README.md index 2431547..43b6bb8 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ cd libcurl.js/server ./run.sh ``` +You can use the `PORT` and `SOCKS5_PORT` environment variables to control which ports the websocket proxy and the SOCKS5 server run on. + ## Copyright: This project is licensed under the GNU AGPL v3. diff --git a/server/main.py b/server/main.py index 28e2ddb..60ea254 100644 --- a/server/main.py +++ b/server/main.py @@ -1,5 +1,4 @@ import logging -import threading import os from asyncio_socks_server.app import SocksServer @@ -16,28 +15,31 @@ def setup_logging(prefix): root.addHandler(stderr_handler) root.setLevel(logging.INFO) -def start_websockify(): +def start_websockify(listen_port, proxy_port): options = { "listen_host": "127.0.0.1", - "listen_port": 6001, + "listen_port": int(listen_port), "target_host": "127.0.0.1", - "target_port": 1080 + "target_port": int(proxy_port) } server = WebSocketProxy(**options) server.start_server() -def start_socks(): +def start_socks(proxy_port): socks_app = SocksServer( LISTEN_HOST="127.0.0.1", - LISTEN_PORT=1080 + LISTEN_PORT=int(proxy_port) ) socks_app.run() if __name__ == "__main__": + listen_port = os.environ.get("PORT") or 6001 + proxy_port = os.environ.get("SOCKS5_PORT") or 6002 + pid = os.fork() if pid == 0: setup_logging("[websockify] ") - start_websockify() + start_websockify(listen_port, proxy_port) else: - start_socks() \ No newline at end of file + start_socks(proxy_port) \ No newline at end of file diff --git a/server/run.sh b/server/run.sh index 09af827..011d553 100755 --- a/server/run.sh +++ b/server/run.sh @@ -10,7 +10,10 @@ fi source .venv/bin/activate if ! python3 -c "import asyncio_socks_server, websockify" 2> /dev/null; then - pip3 install -r requirements.txt + pip3 install asyncio-socks-server + git clone https://github.com/novnc/websockify -b master --depth=1 + pip3 install ./websockify + rm -rf websockify fi python3 main.py \ No newline at end of file