Skip to content

Instantly share code, notes, and snippets.

@neatville
Last active November 6, 2017 20:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neatville/80182741cb6db637f33b2db64054b1cf to your computer and use it in GitHub Desktop.
Save neatville/80182741cb6db637f33b2db64054b1cf to your computer and use it in GitHub Desktop.
After installing PiA client on ubuntu
# https://www.privateinternetaccess.com/pages/client-support/ubuntu-openvpn
# cd /etc/NetworkManager/system-connections
import fileinput, glob, os
def replace(file):
for line in fileinput.input(file, inplace=True):
print(line.rstrip().replace('password-flags=1', 'password-flags=0'))
your_pw = "YOUR PASSWORD"
def append(file):
with open(file, "a") as myfile:
myfile.write("\n[vpn-secrets]\npassword="+your_pw)
for file in glob.glob("PIA*"):
replace(file)
with open(file) as the_file:
if your_pw not in the_file.read():
append(file)
@neatville
Copy link
Author

neatville commented Oct 28, 2016

I was looking for a good way to bulk rename file extensions, and I recently found the most readable way to do it. They were .ovpn files, so I thought I'd add that here.

for f in glob.glob('*.ovpn'):
    f2 = f
    f2 = f2.replace('.ovpn', '.conf')
    os.rename(f, f2)
# https://pythonicprose.blogspot.com/2010/02/python-bulk-rename-directory-of-files.html 

To take spaces out of filenames, you could use this same function and know what to put inside of f2.replace.
https://www.reddit.com/r/raspberry_pi/comments/43tana/i_now_have_a_folder_full_of_ovpn_files_how_do_i/

@neatville
Copy link
Author

neatville commented Nov 19, 2016

In Windows 10 I recently installed OpenVPN. As I needed to update the config files so I didn't have to enter the username and password each time, I wanted to do it the same way I did it on Linux. I figured I would just need to run Bash for Windows as the administrator to make it happen, and that worked. From the default directory, go to /mnt/c and then you can just navigate Windows as you would on Linux. Note that the updating of config files I'm talking about here is different than what I'm doing at the start of this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment