Last active
July 19, 2016 19:17
-
-
Save RealOrangeOne/050da86871fb952ba7bfe97eece8555c to your computer and use it in GitHub Desktop.
Revisions
-
RealOrangeOne revised this gist
Jul 19, 2016 . 1 changed file with 5 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,17 +2,10 @@ from glob import glob def write_file(data, out_file_name, new_dir): with open(os.path.join(new_dir, out_file_name), 'w') as f: f.write(''.join(data)) for ovpn_file in glob('*.ovpn'): new_dir = os.path.join(ovpn_file.replace('.ovpn', '')) @@ -27,7 +20,8 @@ def write_file(data, end_tag_line, new_dir): for line in file_data: if line.startswith('<') and line.strip().endswith('>'): # if this is a tag line if in_block: # we're in a block, write data file_ext = line.strip().replace('</', '').replace('>', '') + ".pem" write_file(data, ovpn_file.split('/')[-1] + '-' + file_ext, new_dir) data = [] in_block = False else: @@ -36,4 +30,4 @@ def write_file(data, end_tag_line, new_dir): data.append(line) os.remove(ovpn_file) print("Exported {}".format(ovpn_file.split('/')[-1])) -
RealOrangeOne created this gist
Jul 18, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import os, shutil from glob import glob def write_file(data, end_tag_line, new_dir): with open(os.path.join(new_dir, file_names[end_tag_line]), 'w') as f: f.write(''.join(data)) file_names = { '</ca>': 'user.crt', '</cert>': 'ca.crt', '</key>': 'private.key', '</tls-auth>': 'tls.key' } for ovpn_file in glob('*.ovpn'): new_dir = os.path.join(ovpn_file.replace('.ovpn', '')) os.makedirs(new_dir, exist_ok=True) shutil.copy2(ovpn_file, os.path.join(new_dir, ovpn_file.split('/')[-1])) with open(ovpn_file) as f: file_data = f.readlines() in_block = False data = [] for line in file_data: if line.startswith('<') and line.strip().endswith('>'): # if this is a tag line if in_block: # we're in a block, write data write_file(data, line.strip(), new_dir) data = [] in_block = False else: in_block = True elif in_block: data.append(line) os.remove(ovpn_file) print("Exported {}".format(ovpn_file.split('/')[-1]))