From b71626e5f8c611778495bd3e83a0dc73b775e473 Mon Sep 17 00:00:00 2001 From: quackerd Date: Mon, 4 May 2020 05:16:02 -0400 Subject: [PATCH] initial commit --- client.conf | 43 ++++++++++++ docker-compose.yml | 41 ++++++++++++ nginx/nginx/site-confs/default | 34 ++++++++++ setup.py | 116 +++++++++++++++++++++++++++++++++ v2ray/config.json | 29 +++++++++ 5 files changed, 263 insertions(+) create mode 100644 client.conf create mode 100644 docker-compose.yml create mode 100644 nginx/nginx/site-confs/default create mode 100644 setup.py create mode 100644 v2ray/config.json diff --git a/client.conf b/client.conf new file mode 100644 index 0000000..88a5f97 --- /dev/null +++ b/client.conf @@ -0,0 +1,43 @@ +{ + "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": "nocturne.quacker.net", + "port": 443, + "users": [ + { + "id": "{{ uuid }}", + "alterId": 64 + } + ] + } + ] + }, + "streamSettings": { + "network": "ws", + "security": "tls", + "wsSettings": { + "path": "/{{ path }}" + } + } + } + ] +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e3d6554 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +version: '3.4' + +networks: + br0: + external: false + +services: + nginx: + container_name: nginx + image: linuxserver/letsencrypt + restart: always + cap_add: + - NET_ADMIN + networks: + - br0 + environment: + - PUID={{ uid }} + - PGID={{ gid }} + - TZ=US/Eastern + - URL={{ domain }} + - SUBDOMAINS={{ subdomain }} + - VALIDATION=http + - EMAIL={{ email }} + - DHLEVEL=2048 + - ONLY_SUBDOMAINS={{ only_sub }} + - STAGING=false + ports: + - 80:80 + - 443:443 + volumes: + - ./nginx:/config + + v2ray: + container_name: v2ray + image: v2ray/official + restart: always + networks: + - br0 + command: ["v2ray","-config=/etc/v2ray/config.json"] + volumes: + - ./v2ray:/etc/v2ray diff --git a/nginx/nginx/site-confs/default b/nginx/nginx/site-confs/default new file mode 100644 index 0000000..9b0851f --- /dev/null +++ b/nginx/nginx/site-confs/default @@ -0,0 +1,34 @@ +# redirect all traffic to https +server { + listen 80 default_server; + listen [::]:80 default_server; + server_name _; + return 301 https://$host$request_uri; +} + +# main server block +server { + listen 443 ssl http2 default_server; + listen [::]:443 ssl http2 default_server; + + root /config/www; + index index.html index.htm index.php; + + # all ssl related config moved to ssl.conf + include /config/nginx/ssl.conf; + + server_name {{server_name}}; + location /{{ path }} { + proxy_redirect off; + proxy_pass http://v2ray:8080; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $http_host; + + # Show realip in v2ray access.log + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3724111 --- /dev/null +++ b/setup.py @@ -0,0 +1,116 @@ +import getopt +import sys +import uuid +import pwd +import jinja2 +import random +import os +import string + +def randomString(stringLength=16): + letters = string.ascii_lowercase + return ''.join(random.choice(letters) for i in range(stringLength)) + +def usage(): + print("Usage: python setup.py [options]\n\ + Options:\n\ + -h : show usage\n\ + -d domain : your domain - mydomain.tld\n\ + [-s subdomain] : your subdomain. Optional.\n\ + [-e email] : your email. Optional.\n") + +def main(): + email = None + subdomain = None + domain = None + uid = os.getuid() + gid = os.getgid() + v_uuid = uuid.uuid4() + v_path = randomString() + + try: + opts , args = getopt.getopt(sys.argv[1:], "hd:s:e:") + except getopt.GetoptError as err: + print(str(err)) + usage() + sys.exit(1) + + for o, a in opts: + if o == "-h": + usage() + sys.exit(0) + elif o == "-d": + if domain != None: + print("Can specify maximum ONE domain.") + sys.exit(1) + else: + domain = a + elif o == "-s": + if subdomain != None: + print("Can specify maximum ONE subdomain.") + sys.exit(1) + else: + subdomain = a + elif o == "-e": + if email != None: + print("Can specify maximum ONE email.") + else: + email = a + + if domain == None: + print("Must specify a domain.") + sys.exit(1) + + server_name = None + if subdomain == None: + server_name = domain + else: + server_name = subdomain + "." + domain + + # process docker-compose + with open("docker-compose.yml", "r") as file: + template = jinja2.Template(file.read()) + + output = template.render(uid = uid, gid = gid, domain = domain, \ + subdomain = (subdomain if subdomain != None else ""), \ + only_sub = ("true" if subdomain != None else "false"), \ + email = ("dummy@dummy.com" if email == None else email)) + + with open("docker-compose.yml", "w") as file: + file.write(output) + + # process v2ray/config + with open("v2ray/config.json", "r") as file: + template = jinja2.Template(file.read()) + + output = template.render(uuid = v_uuid, path = v_path) + + with open("v2ray/config.json", "w") as file: + file.write(output) + + # process nginx/nginx/site-confs/default + with open("nginx/nginx/site-confs/default", "r") as file: + template = jinja2.Template(file.read()) + + output = template.render(server_name = server_name, path = v_path) + + with open("nginx/nginx/site-confs/default", "w") as file: + file.write(output) + + # process client.conf + with open("client.conf", "r") as file: + template = jinja2.Template(file.read()) + + output = template.render(uuid = v_uuid, path = v_path) + + with open("client.conf", "w") as file: + file.write(output) + + print("Processed all files. The detailed client config is written to client.conf.\n\ + Summary:\n\ + Server Address: " + server_name + "\n\ + Path: " + v_path + "\n\ + UUID: " + v_uuid + "\n\n\ + Please run docker-compose up -d to start the service.") + +main() diff --git a/v2ray/config.json b/v2ray/config.json new file mode 100644 index 0000000..cc7ce2c --- /dev/null +++ b/v2ray/config.json @@ -0,0 +1,29 @@ +{ + "inbounds": [ + { + "port": 8080, + "listen":"0.0.0.0", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "{{ uuid }}", + "alterId": 64 + } + ] + }, + "streamSettings": { + "network": "ws", + "wsSettings": { + "path": "/{{ path }}" + } + } + } + ], + "outbounds": [ + { + "protocol": "freedom", + "settings": {} + } + ] +}