use latest websockify, allow user to change port

This commit is contained in:
ading2210 2024-01-08 01:38:41 -05:00
parent 953b6cb191
commit 7472c899db
4 changed files with 18 additions and 10 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
/client/build /client/build
/client/out /client/out
/server/.venv /server/.venv
/server/websockify

View file

@ -51,6 +51,8 @@ cd libcurl.js/server
./run.sh ./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: ## Copyright:
This project is licensed under the GNU AGPL v3. This project is licensed under the GNU AGPL v3.

View file

@ -1,5 +1,4 @@
import logging import logging
import threading
import os import os
from asyncio_socks_server.app import SocksServer from asyncio_socks_server.app import SocksServer
@ -16,28 +15,31 @@ def setup_logging(prefix):
root.addHandler(stderr_handler) root.addHandler(stderr_handler)
root.setLevel(logging.INFO) root.setLevel(logging.INFO)
def start_websockify(): def start_websockify(listen_port, proxy_port):
options = { options = {
"listen_host": "127.0.0.1", "listen_host": "127.0.0.1",
"listen_port": 6001, "listen_port": int(listen_port),
"target_host": "127.0.0.1", "target_host": "127.0.0.1",
"target_port": 1080 "target_port": int(proxy_port)
} }
server = WebSocketProxy(**options) server = WebSocketProxy(**options)
server.start_server() server.start_server()
def start_socks(): def start_socks(proxy_port):
socks_app = SocksServer( socks_app = SocksServer(
LISTEN_HOST="127.0.0.1", LISTEN_HOST="127.0.0.1",
LISTEN_PORT=1080 LISTEN_PORT=int(proxy_port)
) )
socks_app.run() socks_app.run()
if __name__ == "__main__": if __name__ == "__main__":
listen_port = os.environ.get("PORT") or 6001
proxy_port = os.environ.get("SOCKS5_PORT") or 6002
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
setup_logging("[websockify] ") setup_logging("[websockify] ")
start_websockify() start_websockify(listen_port, proxy_port)
else: else:
start_socks() start_socks(proxy_port)

View file

@ -10,7 +10,10 @@ fi
source .venv/bin/activate source .venv/bin/activate
if ! python3 -c "import asyncio_socks_server, websockify" 2> /dev/null; then 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 fi
python3 main.py python3 main.py