-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
72 lines (55 loc) · 2.4 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
import uuid
import json
import yaml
from pathlib import Path
sslEnable = False
# LOAD CONFIG FILES
v2rayConfigPath = Path(__file__).parent.joinpath('v2ray/config/config.json')
dockerComposePath = Path(__file__).parent.joinpath('docker-compose.yml')
file = open(str(v2rayConfigPath), 'r', encoding='utf-8')
config = json.load(file)
with open(str(dockerComposePath), 'r') as f:
dockerComposeObject = yaml.safe_load(f)
# INPUT: UPSTREAM UUID
defaultUUID = config['inbounds'][0]['settings']['clients'][0]['id']
if defaultUUID == '<UPSTREAM-UUID>':
message = "Upstream UUID: (Leave empty to generate a random one)\n"
else:
message = f"Upstream UUID: (Leave empty to use `{defaultUUID}`)\n"
upstreamUUID = input(message)
if upstreamUUID == '':
if defaultUUID == '<UPSTREAM-UUID>':
upstreamUUID = str(uuid.uuid4())
else:
upstreamUUID = defaultUUID
# INPUT: Nginx configs
message = "Enter your domain without http or https: (for example: test.com)\n"
domain = input(message)
message = "Enable SSL for this domain? type 'yes' or 'no'. Default is no. if you are using CDN, ignore this.\n"
isSSLEnable = input(message)
if isSSLEnable == 'yes':
sslEnable = True
message = "Enter your email for letsencrypt:\n"
email = input(message)
# SAVE CONFIG FILES
config['inbounds'][0]['settings']['clients'][0]['id'] = upstreamUUID
dockerComposeObject["services"]["v2ray"]["environment"][1] = f'VIRTUAL_HOST={domain}'
dockerComposeObject["services"]["v2ray"]["environment"][2] = f'LETSENCRYPT_HOST='
dockerComposeObject["services"]["nginx-proxy-acme"]["environment"][0] = f'DEFAULT_EMAIL='
if isSSLEnable == 'yes':
dockerComposeObject["services"]["v2ray"]["environment"][2] = f'LETSENCRYPT_HOST={domain}'
dockerComposeObject["services"]["nginx-proxy-acme"]["environment"][0] = f'DEFAULT_EMAIL={email}'
content = json.dumps(config, indent=2)
open(str(v2rayConfigPath), 'w', encoding='utf-8').write(content)
open(str(dockerComposePath), 'w', encoding='utf-8').write(yaml.dump(dockerComposeObject, default_flow_style=False))
# PRINT OUT RESULT
print(f'\n---------\nUpstream UUID: {upstreamUUID}')
print(f'Domain: {domain}')
if isSSLEnable == 'yes':
print('SSL: enabled')
print(f'Email: {email}')
print('---------\n')
print('\nDone!')
print('- Run docker-compose up -d for bringing up services')
print('- Run ./vmess.py to get your vmess links to share and import in clients\n')