-
Notifications
You must be signed in to change notification settings - Fork 3
/
ovpn-gen.py
39 lines (34 loc) · 1.07 KB
/
ovpn-gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from jinja2 import Template
import sys
'''Generate an .ovpn file from a set of user keys
to be used with an ovpn client.
'''
try:
username = sys.argv[1]
except:
print 'Error: Supply a username!'
sys.exit()
try:
server = sys.argv[2]
except:
print 'Error: Need an ip and port "12.34.56.78 1194"'
sys.exit()
#'/etc/openvpn/easy-rsa'
ca = 'keys/ca.crt'
usercert = 'keys/' + username + '.crt'
userkey = 'keys/' + username + '.key'
userovpn = username + '.ovpn'
with open('templates/ovpn.template') as ovpntemplate, \
open(usercert) as certfile, \
open(userkey) as keyfile, \
open(ca) as cafile, \
open(userovpn, 'w') as outfile:
model = Template(ovpntemplate.read())
certvalue = certfile.read()
keyvalue = keyfile.read()
cavalue = cafile.read()
outfile.write(model.render(usercert=certvalue, userkey=keyvalue, cacert=cavalue, servername=server))
print model.render(usercert=certvalue, userkey=keyvalue, cacert=cavalue, servername=server)
print 'OVPN file generated:' + username + '.ovpn'