Commit b9857d17 authored by Julien Muchembled's avatar Julien Muchembled

Merge openvpn scripts in 2: 1 for server and 1 for client

parent 550be227
#!/bin/sh -e
ip link set $dev up
#!/bin/sh -e
ip link set $dev up
ip addr add $1 dev $dev
#!/usr/bin/python -S
import os, time, sys
import os, sys
if os.environ['script_type'] == 'route-up':
os.execlp('ip', 'ip', 'link', 'set', os.environ['dev'], 'up')
# Write into pipe external ip address received
os.write(int(sys.argv[1]), '%(script_type)s %(OPENVPN_external_ip)s\n' % os.environ)
#!/usr/bin/python -S
import os, time, sys
# example of os.environ
{'X509_0_C': 'FR',
......@@ -37,10 +36,18 @@ import os, time, sys
'untrusted_port': '59345',
'verb': '3'}
# Send to client his external ip address
if os.environ['script_type'] == 'client-connect':
script_type = os.environ['script_type']
if script_type == 'up':
from subprocess import call
dev = os.environ['dev']
sys.exit(call(('ip', 'link', 'set', dev, 'up'))
or call(('ip', 'addr', 'add', sys.argv[1], 'dev', dev)))
if script_type == 'client-connect':
# Send client its external ip address
with open(sys.argv[2], 'w') as f:
f.write('push "setenv-safe external_ip %s"\n' % os.environ['trusted_ip'])
f.write('push "setenv-safe external_ip %s"\n'
% os.environ['trusted_ip'])
# Write into pipe connect/disconnect events
os.write(int(sys.argv[1]), '%(script_type)s %(common_name)s\n' % os.environ)
......@@ -31,9 +31,9 @@ def server(ip, pipe_fd, *args, **kw):
return openvpn(
'--tls-server',
'--mode', 'server',
'--up', 'openvpn-up-server %s/%u' % (ip, len(utils.config.vifibnet)),
'--client-connect', 'openvpn-server-events ' + str(pipe_fd),
'--client-disconnect', 'openvpn-server-events ' + str(pipe_fd),
'--up', 'ovpn-server %s/%u' % (ip, len(utils.config.vifibnet)),
'--client-connect', 'ovpn-server ' + str(pipe_fd),
'--client-disconnect', 'ovpn-server ' + str(pipe_fd),
'--dh', utils.config.dh,
'--max-clients', str(utils.config.max_clients),
*args, **kw)
......@@ -44,8 +44,8 @@ def client(serverIp, pipe_fd, *args, **kw):
'--nobind',
'--client',
'--remote', serverIp,
'--up', 'openvpn-up-client',
'--route-up', 'openvpn-route-up ' + str(pipe_fd),
'--up', 'ovpn-client',
'--route-up', 'ovpn-client ' + str(pipe_fd),
*args, **kw)
def babel(**kw):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment