mirror of
https://github.com/hatamiarash7/WireGuard-Config-Generator.git
synced 2025-06-14 13:47:11 +02:00
lint file
This commit is contained in:
parent
ff99d45c4b
commit
364064e27d
24
main.py
24
main.py
@ -1,20 +1,24 @@
|
|||||||
import environ
|
"""
|
||||||
|
Generate WireGuard tunnel configuration files from your data
|
||||||
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import environ
|
||||||
|
|
||||||
env = environ.Env()
|
env = environ.Env()
|
||||||
environ.Env.read_env()
|
environ.Env.read_env()
|
||||||
|
|
||||||
# Load all IP addresses from the given file
|
# Load all IP addresses from the given file
|
||||||
|
|
||||||
finalIps = []
|
IPS = []
|
||||||
|
|
||||||
with open('ip-list.json', 'r') as file:
|
with open(file='ip-list.json', mode='r', encoding='UTF-8') as file:
|
||||||
lists = json.load(file)
|
lists = json.load(file)
|
||||||
for list in lists:
|
for group in lists:
|
||||||
for ip in lists[list]:
|
for ip in lists[group]:
|
||||||
finalIps.append(ip)
|
IPS.append(ip)
|
||||||
|
|
||||||
finalIps = ", ".join(map(str, finalIps))
|
IPS = ", ".join(map(str, IPS))
|
||||||
|
|
||||||
# Load other config options from .env file
|
# Load other config options from .env file
|
||||||
|
|
||||||
@ -26,16 +30,16 @@ PersistentKeepalive = env('PERSISTENT_KEEPALIVE')
|
|||||||
|
|
||||||
# Generate the config file for each endpoint
|
# Generate the config file for each endpoint
|
||||||
|
|
||||||
with open('endpoints.json', 'r') as file:
|
with open(file='endpoints.json', mode='r', encoding='UTF-8') as file:
|
||||||
endpoints = json.load(file)
|
endpoints = json.load(file)
|
||||||
for endpoint in endpoints:
|
for endpoint in endpoints:
|
||||||
with open(endpoint['name']+'.conf', 'w') as file:
|
with open(file=endpoint['name']+'.conf', mode='w', encoding='UTF-8') as file:
|
||||||
file.write('[Interface]\n')
|
file.write('[Interface]\n')
|
||||||
file.write('PrivateKey = ' + PrivateKey + '\n')
|
file.write('PrivateKey = ' + PrivateKey + '\n')
|
||||||
file.write('Address = ' + Address + '\n')
|
file.write('Address = ' + Address + '\n')
|
||||||
file.write('MTU = ' + MTU + '\n\n')
|
file.write('MTU = ' + MTU + '\n\n')
|
||||||
file.write('[Peer]\n')
|
file.write('[Peer]\n')
|
||||||
file.write('PublicKey = ' + PublicKey + '\n')
|
file.write('PublicKey = ' + PublicKey + '\n')
|
||||||
file.write('AllowedIPs = ' + finalIps + '\n')
|
file.write('AllowedIPs = ' + IPS + '\n')
|
||||||
file.write('Endpoint = ' + endpoint['address'] + '\n')
|
file.write('Endpoint = ' + endpoint['address'] + '\n')
|
||||||
file.write('PersistentKeepalive = ' + PersistentKeepalive + '\n')
|
file.write('PersistentKeepalive = ' + PersistentKeepalive + '\n')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user