setup.py 2.4 KB

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