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 #!/usr/bin/python -S
import os, sys 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): ...@@ -79,7 +79,7 @@ def startNewConnection(n):
log_message('Establishing a connection with id %s (%s:%s)' % (id,ip,port), 2) log_message('Establishing a connection with id %s (%s:%s)' % (id,ip,port), 2)
iface = free_interface_set.pop() iface = free_interface_set.pop()
connection_dict[id] = ( openvpn.client( ip, '--dev', iface, '--proto', proto, '--rport', str(port), 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) log_message('Updating peers database', 5)
peer_db.execute("UPDATE peers SET used = 1 WHERE id = ?", (id,)) peer_db.execute("UPDATE peers SET used = 1 WHERE id = ?", (id,))
except KeyError: except KeyError:
...@@ -115,6 +115,15 @@ def refreshConnections(): ...@@ -115,6 +115,15 @@ def refreshConnections():
# Establish new connections # Establish new connections
startNewConnection(config.client_count - len(connection_dict)) 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(): def main():
# Get arguments # Get arguments
getConfig() getConfig()
...@@ -142,16 +151,19 @@ def main(): ...@@ -142,16 +151,19 @@ def main():
# Establish connections # Establish connections
log_message('Starting openvpn server', 3) log_message('Starting openvpn server', 3)
serverProcess = openvpn.server(config.ip, write_pipe, 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) startNewConnection(config.client_count)
next_refresh = time.time() + config.refresh_time
# main loop # main loop
try: try:
while True: 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: if ready:
log_message(read_pipe.readline(), 0) handle_message(read_pipe.readline())
refreshConnections() if time.time() >= next_refresh:
refreshConnections()
next_refresh = time.time() + config.refresh_time
except KeyboardInterrupt: except KeyboardInterrupt:
return 0 return 0
......
...@@ -9,7 +9,7 @@ def openvpn(*args, **kw): ...@@ -9,7 +9,7 @@ def openvpn(*args, **kw):
'--script-security', '2', '--script-security', '2',
'--user', 'nobody', '--user', 'nobody',
'--group', 'nogroup', '--group', 'nogroup',
#'--verb', str(config.verbose), '--verb', str(config.verbose),
] + list(args) + config.openvpn_args ] + list(args) + config.openvpn_args
if config.verbose >= 5: if config.verbose >= 5:
print repr(args) print repr(args)
...@@ -26,6 +26,7 @@ def server(ip, pipe_fd, *args, **kw): ...@@ -26,6 +26,7 @@ def server(ip, pipe_fd, *args, **kw):
'--duplicate-cn', # XXX : to be removed '--duplicate-cn', # XXX : to be removed
'--up', 'up-server ' + ip, '--up', 'up-server ' + ip,
'--client-connect', 'client-connect ' + str(pipe_fd), '--client-connect', 'client-connect ' + str(pipe_fd),
'--client-disconnect', 'client-disconnect ' + str(pipe_fd),
'--dh', config.dh, '--dh', config.dh,
*args, **kw) *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