You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
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')
|