openvpn.py 952 Bytes
Newer Older
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
1 2
import subprocess

3
def openvpn(*args, **kw):
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
4
    args = ['openvpn',
5
        '--dev-type', 'tap',
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
6 7 8 9 10
        '--persist-tun',
        '--persist-key',
        '--script-security', '2',
        '--user', 'nobody',
        '--group', 'nogroup',
11
        #'--verb', str(config.verbose),
Guillaume Bury's avatar
Guillaume Bury committed
12
        ] + list(args) + config.openvpn_args
13 14
    if config.verbose >= 5:
        print repr(args)
15
    return subprocess.Popen(args, **kw)
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
16 17 18 19

# TODO : set iface up when creating a server/client
# ! check working directory before launching up script ?

20 21
def server(ip, *args):
    return openvpn(
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
22 23 24
        '--tls-server',
        '--keepalive', '10', '60',
        '--mode', 'server',
25
        '--duplicate-cn', # XXX : to be removed
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
26
        '--up', 'up-server ' + ip,
27 28
        '--dh', config.dh,
        *args)
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
29

30 31
def client(serverIp, *args):
    return openvpn(
Guillaume Bury's avatar
Guillaume Bury committed
32 33 34
        '--nobind',
        '--tls-client',
        '--remote', serverIp,
35 36
        '--up', 'up-client',
        *args)
Ulysse Beaugnon's avatar
Ulysse Beaugnon committed
37