#!/usr/bin/env python3 # (c) LEAP Encryption Access Project 2020 # License: GPL import subprocess import sys import os VENDOR_PATH = None SCRIPT_NAME = sys.argv[0] CA_README = "config/CERT.Readme" ASSETS_README = "assets/FILES.Readme" 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") for d in ["config", "assets", "pkg"]: os.makedirs(os.path.join(VENDOR_PATH, d)) initVendorConfig() initGitRepo() displayRepoInfo() def displayRepoInfo(): print("[+] Initialized repo in", VENDOR_PATH) print(f"[ ] - Add the assets in the assets/ folder, see {ASSETS_README}.") print(f"[ ] - Add the CA certificate in the config/ folder, see {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 initVendorConfig(): with open(os.path.join(VENDOR_PATH, "config", "vendor.conf"), "w") as f: f.write(CONF_TEMPLATE) with open(os.path.join(VENDOR_PATH, CA_README), "w") as f: f.write(CA_INFO) with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "ASSETS_LIST")) as f: allAssets = f.read() with open(os.path.join(VENDOR_PATH, ASSETS_README), "w") as f: f.write(ASSETS_INFO) f.write(allAssets) 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 = myprovider [myprovider] name = MyProvider applicationName = MyProviderVPN binaryName = myprovider-vpn providerURL = example.org auth = anon apiURL = https://api.myprovider.net/ caURL = https://myprovider.net/ca.crt infoURL = https://myprovider.net/vpn tosURL = https://myprovider.net/tos helpURL = https://myprovider.net/support geolocationAPI = https://myprovider.net:9001/json askForDonations = true donateURL = https://myprovider.net/vpn/donate """ CA_INFO = """Place in this folder your provider's CA certificate, with the name: -ca.crt """ 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() initVendor()