Create main.py

This commit is contained in:
Arash Hatami 2022-09-25 12:09:33 +03:30
parent fd6127269f
commit 8301538a9a
No known key found for this signature in database
GPG Key ID: D3D9E8CB2E49731F
1 changed files with 41 additions and 0 deletions

41
main.py Normal file
View File

@ -0,0 +1,41 @@
import environ
import json
env = environ.Env()
environ.Env.read_env()
# Load all IP addresses from the given file
finalIps = []
with open('ip-list.json', 'r') as file:
lists = json.load(file)
for list in lists:
for ip in lists[list]:
finalIps.append(ip)
finalIps = ", ".join(map(str, finalIps))
# Load other config options from .env file
PrivateKey = env('PRIVATE_KEY')
PublicKey = env('PUBLIC_KEY')
Address = env('ADDRESS')
MTU = env('MTU')
PersistentKeepalive = env('PERSISTENT_KEEPALIVE')
# Generate the config file for each endpoint
with open('endpoints.json', 'r') as file:
endpoints = json.load(file)
for endpoint in endpoints:
with open(endpoint['name']+'.conf', 'w') as file:
file.write('[Interface]\n')
file.write('PrivateKey = ' + PrivateKey + '\n')
file.write('Address = ' + Address + '\n')
file.write('MTU = ' + MTU + '\n\n')
file.write('[Peer]\n')
file.write('PublicKey = ' + PublicKey + '\n')
file.write('AllowedIPs = ' + finalIps + '\n')
file.write('Endpoint = ' + endpoint['address'] + '\n')
file.write('PersistentKeepalive = ' + PersistentKeepalive + '\n')