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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#!/usr/bin/env python3
# (c) LEAP Encryption Access Project 2020
# License: GPL
import string
import subprocess
import sys
import os
VENDOR_PATH = None
PROVIDER=None
SCRIPT_NAME = sys.argv[0]
CA_README = "CERT.Readme"
ASSETS_README = "assets/FILES.Readme"
VENDOR_QRC = "vendor.qrc"
def initVendor():
global VENDOR_PATH
if not VENDOR_PATH:
bail("ERROR: Please set VENDOR_PATH environment variable.")
VENDOR_PATH = os.path.abspath(VENDOR_PATH)
if os.path.isdir(VENDOR_PATH):
bail("ERROR: VENDOR_PATH folder already exists {path}".format(path=VENDOR_PATH))
for d in ["assets"]:
os.makedirs(os.path.join(VENDOR_PATH, d))
initVendorConfig()
initGitRepo()
displayRepoInfo()
def displayRepoInfo():
print()
print("[+] Initialized repo in", VENDOR_PATH)
print()
print(f"- Please add all the needed assets. See {VENDOR_PATH}/{ASSETS_README}.")
print(f"- Add your provider's CA certificate, see see {VENDOR_PATH}/{PROVIDER}/{CA_README}.")
print("- Remember to commit your changes.")
print()
print("[+] After doing that, you can run 'make vendor_check' to validate the configuration for your provider.")
def bail(msg=None):
if not msg:
print("ERROR: no arguments supported!")
print('Usage: {scriptname}'.format(
scriptname=SCRIPT_NAME))
else:
print(msg)
sys.exit(1)
def getVendorPath():
return os.environ.get('VENDOR_PATH')
def sanitize(word):
result = ""
for letter in word:
if letter in string.ascii_letters:
result = result + letter.lower()
return result
def getProvider():
provider = os.environ.get('PROVIDER')
if not provider:
provider = input('> provider name? ')
provider = sanitize(provider)
print("[+] provider name:", provider)
return provider
def getProviderURL():
url = os.environ.get('PROVIDER_URL')
if not url :
url = input('> provider url?: https://')
return url.replace('https://', '').replace('/', '')
def getAppName(provider):
return provider[0].capitalize() + provider[1:] + "VPN"
def initVendorConfig():
with open(os.path.join(VENDOR_PATH, "vendor.conf"), "w") as f:
f.write(getConf())
caDir = os.path.join(VENDOR_PATH, PROVIDER)
print("CADIR??", caDir)
os.makedirs(caDir, exist_ok=True)
with open(os.path.join(caDir, CA_README), "w") as f:
f.write(getCAInfo())
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "ASSETS_REQUIRED")) as f:
allAssets = f.read()
with open(os.path.join(VENDOR_PATH, ASSETS_README), "w") as f:
f.write(ASSETS_INFO)
f.write(allAssets)
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../templates/vendor/vendor.qrc")) as f:
qrc = f.read()
with open(os.path.join(VENDOR_PATH, VENDOR_QRC), "w") as f:
f.write(qrc)
def initGitRepo():
out = subprocess.run(['git', 'init'], cwd=VENDOR_PATH)
if out.returncode != 0:
print(f'ERROR: cannot initialize git repo in {VENDOR_PATH}')
CONF_TEMPLATE = """[default]
provider = {provider}
[{provider}]
name = {provider}
applicationName = {appName}
binaryName = {provider}-vpn
providerURL = https://{providerURL}
auth = anon
apiURL = https://api.{providerURL}/
caURL = https://{providerURL}/ca.crt
infoURL = https://{providerURL}/vpn
tosURL = https://{providerURL}/tos
helpURL = https://{providerURL}/support
geolocationAPI = https://{providerURL}:9001/json
askForDonations = false
donateURL = https://{providerURL}/vpn/donate
"""
def getConf():
return CONF_TEMPLATE.format(
provider=PROVIDER,
appName=getAppName(PROVIDER),
providerURL=PROVIDER_URL)
CA_INFO = """Place in this folder your provider's CA certificate, with the name:
{provider}-ca.crt
"""
def getCAInfo():
return CA_INFO.format(provider=PROVIDER)
ASSETS_INFO = """This is the list of assets that you MUST place in this folder for your provider:
"""
if __name__ == "__main__":
if len(sys.argv) != 1:
bail()
VENDOR_PATH = getVendorPath()
PROVIDER = getProvider()
PROVIDER_URL = getProviderURL()
initVendor()
|