Skip to content

Instantly share code, notes, and snippets.

@RealOrangeOne
Last active July 19, 2016 19:17
Show Gist options
  • Select an option

  • Save RealOrangeOne/050da86871fb952ba7bfe97eece8555c to your computer and use it in GitHub Desktop.

Select an option

Save RealOrangeOne/050da86871fb952ba7bfe97eece8555c to your computer and use it in GitHub Desktop.

Revisions

  1. RealOrangeOne revised this gist Jul 19, 2016. 1 changed file with 5 additions and 11 deletions.
    16 changes: 5 additions & 11 deletions astrill-extractor.py
    Original file line number Diff line number Diff line change
    @@ -2,17 +2,10 @@

    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:
    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))

    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', ''))

    @@ -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
    write_file(data, line.strip(), new_dir)
    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]))
    print("Exported {}".format(ovpn_file.split('/')[-1]))
  2. RealOrangeOne created this gist Jul 18, 2016.
    39 changes: 39 additions & 0 deletions astrill-extractor.py
    Original 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]))