From 27007045ab50a8a8b574a519145c0f661f8c652b Mon Sep 17 00:00:00 2001 From: eskemojoe007 Date: Thu, 11 Apr 2019 16:44:31 -0400 Subject: [PATCH] Update create_certs.py --- .../ghostpath/create-certs/create-certs.py | 28 ----------- .../ghostpath/create-certs/create_certs.py | 48 +++++++++++++++++++ 2 files changed, 48 insertions(+), 28 deletions(-) delete mode 100644 openvpn/ghostpath/create-certs/create-certs.py create mode 100644 openvpn/ghostpath/create-certs/create_certs.py diff --git a/openvpn/ghostpath/create-certs/create-certs.py b/openvpn/ghostpath/create-certs/create-certs.py deleted file mode 100644 index e7cb2d1e3..000000000 --- a/openvpn/ghostpath/create-certs/create-certs.py +++ /dev/null @@ -1,28 +0,0 @@ -import pandas as pd - -df = pd.read_csv('GhostPath_URLS.csv', header=None, - names=['country', 'city', 'url']) - -df['location'] = (df['country'].map(str) + '-' + df['city']).map( - lambda x: x.replace(' ', '-')) - -urls_by_location = df.groupby('location')['url'].apply(list).reset_index() - -tail = """ -auth-user-pass /config/openvpn-credentials.txt -client -redirect-gateway -remote-cert-tls server -cipher AES-256-CBC -proto udp -dev tun -nobind -ca /etc/openvpn/ghostpath/ca.crt -""" -def create_cert(row): - with open(f'{row["location"]}.ovpn', 'w') as f: - for url in row['url']: - f.write(f'remote {url} 443 udp\n') - f.write(tail) - -urls_by_location.apply(create_cert, axis=1) diff --git a/openvpn/ghostpath/create-certs/create_certs.py b/openvpn/ghostpath/create-certs/create_certs.py new file mode 100644 index 000000000..78c7a37e8 --- /dev/null +++ b/openvpn/ghostpath/create-certs/create_certs.py @@ -0,0 +1,48 @@ +'''This code reads in "GhostPath_URLS.csv" +(which was copied from https://ghostpath.com/servers) +in order to create basic ovpn files for all the different instances +It requires pandas and python 3.6 or greater. +''' +import pandas as pd + +TAIL = ''' +auth-user-pass /config/openvpn-credentials.txt +client +redirect-gateway +remote-cert-tls server +cipher AES-256-CBC +proto udp +dev tun +nobind +ca /etc/openvpn/ghostpath/ca.crt +''' + + +def main(): + + # Read in teh CSV + df = pd.read_csv('GhostPath_URLS.csv', header=None, + names=['country', 'city', 'url']) + + # Create a new column `locations` with the stringized file names + df['location'] = (df['country'].map(str) + '-' + df['city']).map( + lambda x: x.replace(' ', '-')) + + # Group by locations and create lists of all the urls for each location + urls_by_location = df.groupby('location')['url'].apply(list).reset_index() + + def create_cert(row): + ''' + Creates a file with the location name and the urls with the `TAIL` + ''' + with open(f'{row["location"]}.ovpn', 'w') as f: + for url in row['url']: + f.write(f'remote {url} 443 udp\n') + f.write(TAIL) + + # Save the files for each location + urls_by_location.apply(create_cert, axis=1) + + +if __name__ == '__main__': + main()