Skip to content

Instantly share code, notes, and snippets.

@cheungpat
Created October 9, 2014 01:51
Show Gist options
  • Save cheungpat/1b6222a6a62bb3b42a99 to your computer and use it in GitHub Desktop.
Save cheungpat/1b6222a6a62bb3b42a99 to your computer and use it in GitHub Desktop.
Embed certs in OpenVPN config
#!/usr/bin/python
import argparse
import sys
def should_embed(line):
return True in (line.startswith(k) for k in ['ca', 'key', 'cert', 'dh'])
def embed(filename, out):
for line in (l.strip() for l in open(filename, 'r').readlines()):
if should_embed(line):
option, certfile = line.split(' ')
out.write('<%(option)s>\n%(content)s</%(option)s>\n' % \
dict(option=option, content=open(certfile, 'r').read()))
else:
out.write(line + '\n')
def main():
parser = argparse.ArgumentParser(
description='Embed certs to openvpn config.')
parser.add_argument('filename', type=str,
help='openvpn config file')
parser.add_argument('-o', dest='output', type=str, default='-',
help='embeded openvpn config file')
args = parser.parse_args()
out = sys.stdout if args.output == '-' else open(args.output, 'w')
embed(args.filename, out)
out.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment