-
Notifications
You must be signed in to change notification settings - Fork 51
/
generate-config.py
50 lines (44 loc) · 1.53 KB
/
generate-config.py
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
from piawg import piawg
from pick import pick
from getpass import getpass
from datetime import datetime
pia = piawg()
# Generate public and private key pair
pia.generate_keys()
# Select region
title = 'Please choose a region: '
options = sorted(list(pia.server_list.keys()))
option, index = pick(options, title)
pia.set_region(option)
print("Selected '{}'".format(option))
# Get token
while True:
username = input("\nEnter PIA username: ")
password = getpass()
if pia.get_token(username, password):
print("Login successful!")
break
else:
print("Error logging in, please try again...")
# Add key
status, response = pia.addkey()
if status:
print("Added key to server!")
else:
print("Error adding key to server")
print(response)
# Build config
timestamp = int(datetime.now().timestamp())
location = pia.region.replace(' ', '-')
config_file = 'PIA-{}-{}.conf'.format(location, timestamp)
print("Saving configuration file {}".format(config_file))
with open(config_file, 'w') as file:
file.write('[Interface]\n')
file.write('Address = {}\n'.format(pia.connection['peer_ip']))
file.write('PrivateKey = {}\n'.format(pia.privatekey))
file.write('DNS = {},{}\n\n'.format(pia.connection['dns_servers'][0], pia.connection['dns_servers'][1]))
file.write('[Peer]\n')
file.write('PublicKey = {}\n'.format(pia.connection['server_key']))
file.write('Endpoint = {}:1337\n'.format(pia.connection['server_ip']))
file.write('AllowedIPs = 0.0.0.0/0\n')
file.write('PersistentKeepalive = 25\n')