diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | cspell.yaml | 2 | ||||
-rw-r--r-- | template/docker-compose.yaml.template | 16 | ||||
-rw-r--r-- | template/nginx/root.conf.template | 17 | ||||
-rw-r--r-- | template/v2ray-client-config.json.template | 46 | ||||
-rw-r--r-- | template/v2ray-config.json.template | 29 | ||||
-rwxr-xr-x | tool/aio.py | 3 | ||||
-rw-r--r-- | tool/modules/config.py | 11 | ||||
-rwxr-xr-x | tool/modules/nginx.py | 15 | ||||
-rw-r--r-- | tool/modules/setup.py | 4 |
10 files changed, 135 insertions, 10 deletions
@@ -7,3 +7,5 @@ log tmp backup __pycache__ +v2ray-config.json +v2ray-client-config.json diff --git a/cspell.yaml b/cspell.yaml index b9a2fc9..da2eae4 100644 --- a/cspell.yaml +++ b/cspell.yaml @@ -17,4 +17,6 @@ words: - autoincrement - crupest - Fxxk + - outbounds - todos + - vmess diff --git a/template/docker-compose.yaml.template b/template/docker-compose.yaml.template index ad3b0ab..b2e3fe9 100644 --- a/template/docker-compose.yaml.template +++ b/template/docker-compose.yaml.template @@ -65,6 +65,7 @@ services: - code-server-network - auto-certbot-network - crupest-api-network + - v2ray-network crupest-api: pull_policy: build @@ -80,6 +81,19 @@ services: networks: - crupest-api-network + crupest-v2ray: + image: v2fly/v2fly-core:latest + pull_policy: always + command: [ "-c", "/etc/v2fly/config.json" ] + container_name: crupest-v2ray + restart: on-failure:3 + volumes: + - "./v2ray-config.json:/etc/v2fly/config.json:ro" + expose: + - "10000:10000" + networks: + - v2ray-network + auto-certbot: pull_policy: build depends_on: @@ -163,6 +177,8 @@ networks: code-server-network: auto-certbot-network: crupest-api-network: + v2ray-network: + volumes: blog-public: diff --git a/template/nginx/root.conf.template b/template/nginx/root.conf.template index dfedc81..f148db8 100644 --- a/template/nginx/root.conf.template +++ b/template/nginx/root.conf.template @@ -11,6 +11,22 @@ server { root /srv/www; } + location /_$CRUPEST_V2RAY_PATH { + if ($http_upgrade != "websocket") { + return 404; + } + + proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Real-IP $remote_addr; + proxy_pass http://crupest-v2ray:10000; + } + location /api { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; @@ -21,6 +37,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_pass http://crupest-api; } + } server { diff --git a/template/v2ray-client-config.json.template b/template/v2ray-client-config.json.template new file mode 100644 index 0000000..0c99c6d --- /dev/null +++ b/template/v2ray-client-config.json.template @@ -0,0 +1,46 @@ +{ + "inbounds": [ + { + "port": 1080, + "listen": "127.0.0.1", + "protocol": "socks", + "sniffing": { + "enabled": true, + "destOverride": [ + "http", + "tls" + ] + }, + "settings": { + "auth": "noauth", + "udp": false + } + } + ], + "outbounds": [ + { + "protocol": "vmess", + "settings": { + "vnext": [ + { + "address": "$CRUPEST_DOMAIN", + "port": 443, + "users": [ + { + "id": "$CRUPEST_V2RAY_TOKEN", + "alterId": 0 + } + ] + } + ] + }, + "streamSettings": { + "network": "ws", + "security": "tls", + "wsSettings": { + "path": "/_$CRUPEST_V2RAY_PATH" + } + } + } + ] +}
\ No newline at end of file diff --git a/template/v2ray-config.json.template b/template/v2ray-config.json.template new file mode 100644 index 0000000..33d3f16 --- /dev/null +++ b/template/v2ray-config.json.template @@ -0,0 +1,29 @@ +{ + "inbounds": [ + { + "port": 10000, + "listen": "0.0.0.0", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "$CRUPEST_V2RAY_TOKEN", + "alterId": 0 + } + ] + }, + "streamSettings": { + "network": "ws", + "wsSettings": { + "path": "/_$CRUPEST_V2RAY_PATH" + } + } + } + ], + "outbounds": [ + { + "protocol": "freedom", + "settings": {} + } + ] +}
\ No newline at end of file diff --git a/tool/aio.py b/tool/aio.py index 648e8b4..970c389 100755 --- a/tool/aio.py +++ b/tool/aio.py @@ -239,8 +239,7 @@ def run(): console.print(domain) case "nginx": - domain = check_domain_is_defined() - nginx(domain, console) + raise Exception("This command is deprecated.") case "certbot": domain = check_domain_is_defined() diff --git a/tool/modules/config.py b/tool/modules/config.py index 534ce30..40b20d1 100644 --- a/tool/modules/config.py +++ b/tool/modules/config.py @@ -1,10 +1,11 @@ -import pwd -import grp import os import typing +import uuid from rich.prompt import Prompt from .path import config_file_path +def generate_uuid(): + return str(uuid.uuid4()) class ConfigVar: def __init__(self, name: str, description: str, default_value_generator: typing.Callable[[], str] | str, /, default_value_for_ask=str | None): @@ -48,6 +49,12 @@ config_var_list: list = [ "github token for fetching todos", "Please input your github token for fetching todos"), ConfigVar("CRUPEST_GITHUB_TODO_COUNT", "github todo count", "Please input your github todo count", 10), + ConfigVar("CRUPEST_GITHUB_TODO_COUNT", + "github todo count", "Please input your github todo count", 10), + ConfigVar("CRUPEST_V2RAY_TOKEN", + "v2ray user id", generate_uuid), + ConfigVar("CRUPEST_V2RAY_PATH", + "v2ray path, which will be prefixed by _", generate_uuid), ] config_var_name_set = set([config_var.name for config_var in config_var_list]) diff --git a/tool/modules/nginx.py b/tool/modules/nginx.py index 4f77acd..db350a7 100755 --- a/tool/modules/nginx.py +++ b/tool/modules/nginx.py @@ -50,7 +50,7 @@ def list_domains(domain: str) -> list: return [domain, *list_subdomains(domain)] -def generate_nginx_config(domain: str, dest: str) -> None: +def generate_nginx_config(domain: str, original_config, dest: str) -> None: if not isdir(dest): raise ValueError('dest must be a directory') # copy ssl.conf and https-redirect.conf which need no variable substitution @@ -58,12 +58,19 @@ def generate_nginx_config(domain: str, dest: str) -> None: src = join(nginx_template_dir, filename) dst = join(dest, filename) shutil.copyfile(src, dst) - config = {"CRUPEST_DOMAIN": domain} + config = { + "CRUPEST_DOMAIN": domain, + "CRUPEST_V2RAY_TOKEN": original_config["CRUPEST_V2RAY_TOKEN"], + "CRUPEST_V2RAY_PATH": original_config["CRUPEST_V2RAY_PATH"] + } # generate ssl.conf with open(join(dest, 'ssl.conf'), 'w') as f: f.write(ssl_template.generate(config)) # generate root.conf with open(join(dest, f'{domain}.conf'), 'w') as f: + root_config = config.copy() + root_config["CRUPEST_V2RAY_TOKEN"] = config["CRUPEST_V2RAY_TOKEN"] + root_config["CRUPEST_V2RAY_PATH"] = config["CRUPEST_V2RAY_PATH"] f.write(root_template.generate(config)) # generate nginx config for each site sites: list = server["sites"] @@ -113,7 +120,7 @@ def restart_nginx(force=False) -> bool: return True -def nginx(domain: str, /, console) -> None: +def nginx(domain: str, config, /, console) -> None: bad_files = check_nginx_config_dir(nginx_config_dir, domain) if len(bad_files) > 0: console.print( @@ -133,7 +140,7 @@ def nginx(domain: str, /, console) -> None: os.mkdir(nginx_config_dir) console.print( f"Nginx config directory created at [magenta]{nginx_config_dir}[/]", style="green") - generate_nginx_config(domain, dest=nginx_config_dir) + generate_nginx_config(domain, config, dest=nginx_config_dir) console.print("Nginx config generated.", style="green") if restart_nginx(): console.print('Nginx restarted.', style="green") diff --git a/tool/modules/setup.py b/tool/modules/setup.py index 0e802c4..4e91302 100644 --- a/tool/modules/setup.py +++ b/tool/modules/setup.py @@ -143,7 +143,7 @@ def template_generate(console): "Great! Check the config file and see you next time!", style="green") to_gen = False - domain = config["CRUPEST_DOMAIN"] + domain = get_domain() if to_gen: console.print( @@ -186,7 +186,7 @@ def template_generate(console): to_gen_nginx_conf = Confirm.ask("[yellow]It seems you have already generated nginx config. Do you want to overwrite it?[/]", default=False, console=console) if to_gen_nginx_conf: - nginx(domain, console) + nginx(domain, config, console) data_dir_check(domain, console) |