Commit ec50944f authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

A few bug solved :

    server and client log file are now opened in WRONLY mode instead of RDONLY
    connections are not refreshed evrytime that a message is transmited on the pipe
Open vpn now trigger client-disconnect
When a new client arrive, its IP is sent to the pipe
parent 3b161a08
#!/usr/bin/python -S
import os, sys
os.write(int(sys.argv[1]), 'hello !\n')
os.write(int(sys.argv[1]), 'CLIENT_CONNECTED ' + os.environ['trusted_ip'] + '\n')
......@@ -79,7 +79,7 @@ def startNewConnection(n):
log_message('Establishing a connection with id %s (%s:%s)' % (id,ip,port), 2)
iface = free_interface_set.pop()
connection_dict[id] = ( openvpn.client( ip, '--dev', iface, '--proto', proto, '--rport', str(port),
stdout=os.open(config.client_log + 'vifibnet.client.' + str(id) + '.log', os.O_RDONLY|os.O_CREAT) ) , iface)
stdout=os.open(config.client_log + 'vifibnet.client.' + str(id) + '.log', os.O_WRONLY|os.O_CREAT|os.O_TRUNC) ) , iface)
log_message('Updating peers database', 5)
peer_db.execute("UPDATE peers SET used = 1 WHERE id = ?", (id,))
except KeyError:
......@@ -115,6 +115,15 @@ def refreshConnections():
# Establish new connections
startNewConnection(config.client_count - len(connection_dict))
def handle_message(msg):
words = msg.split()
if words[0] == 'CLIENT_CONNECTED':
log_message('Incomming connection from ' + words[1], 3)
elif words[0] == 'CLIENT_DISCONNECTED':
log_message(words[1] + ' has disconnected', 3)
else:
log_message('Unknow message recieved : ' + msg, 1)
def main():
# Get arguments
getConfig()
......@@ -142,16 +151,19 @@ def main():
# Establish connections
log_message('Starting openvpn server', 3)
serverProcess = openvpn.server(config.ip, write_pipe,
'--dev', 'vifibnet', stdout=os.open(config.server_log, os.O_RDONLY|os.O_CREAT))
'--dev', 'vifibnet', stdout=os.open(config.server_log, os.O_WRONLY|os.O_CREAT|os.O_TRUNC))
startNewConnection(config.client_count)
next_refresh = time.time() + config.refresh_time
# main loop
try:
while True:
ready, tmp1, tmp2 = select.select([read_pipe], [], [], float(config.refresh_time))
ready, tmp1, tmp2 = select.select([read_pipe], [], [], max(0, next_refresh - time.time()))
if ready:
log_message(read_pipe.readline(), 0)
refreshConnections()
handle_message(read_pipe.readline())
if time.time() >= next_refresh:
refreshConnections()
next_refresh = time.time() + config.refresh_time
except KeyboardInterrupt:
return 0
......
......@@ -9,7 +9,7 @@ def openvpn(*args, **kw):
'--script-security', '2',
'--user', 'nobody',
'--group', 'nogroup',
#'--verb', str(config.verbose),
'--verb', str(config.verbose),
] + list(args) + config.openvpn_args
if config.verbose >= 5:
print repr(args)
......@@ -26,6 +26,7 @@ def server(ip, pipe_fd, *args, **kw):
'--duplicate-cn', # XXX : to be removed
'--up', 'up-server ' + ip,
'--client-connect', 'client-connect ' + str(pipe_fd),
'--client-disconnect', 'client-disconnect ' + str(pipe_fd),
'--dh', config.dh,
*args, **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