Commit 550be227 authored by Guillaume Bury's avatar Guillaume Bury

Cleaned some log messages in main

parent abe109ab
......@@ -27,6 +27,7 @@ def openvpn(*args, **kw):
# ! check working directory before launching up script ?
def server(ip, pipe_fd, *args, **kw):
utils.log('Starting server', 3)
return openvpn(
'--tls-server',
'--mode', 'server',
......@@ -38,6 +39,7 @@ def server(ip, pipe_fd, *args, **kw):
*args, **kw)
def client(serverIp, pipe_fd, *args, **kw):
utils.log('Starting client', 5)
return openvpn(
'--nobind',
'--client',
......@@ -47,6 +49,7 @@ def client(serverIp, pipe_fd, *args, **kw):
*args, **kw)
def babel(**kw):
utils.log('Starting babel', 3)
args = ['babeld',
'-C', 'redistribute local ip %s' % (utils.config.internal_ip),
'-C', 'redistribute local deny',
......@@ -64,7 +67,6 @@ def babel(**kw):
if utils.config.babel_state:
args += '-S', utils.config.babel_state
args = args + ['vifibnet'] + list(tunnelmanager.free_interface_set)
if utils.config.verbose >= 5:
print args
utils.log(str(args), 5)
return subprocess.Popen(args, **kw)
import os, random, traceback
import openvpn
import utils
import db
import plib, utils, db
free_interface_set = set(('client1', 'client2', 'client3', 'client4', 'client5',
'client6', 'client7', 'client8', 'client9', 'client10'))
......@@ -44,10 +42,9 @@ class TunnelManager:
for peer_id, ip, port, proto in self.peers_db.getUnusedPeers(utils.config.client_count - len(self.connection_dict), self.write_pipe):
utils.log('Establishing a connection with id %s (%s:%s)' % (peer_id, ip, port), 2)
iface = free_interface_set.pop()
self.connection_dict[peer_id] = ( openvpn.client( ip, write_pipe, '--dev', iface, '--proto', proto, '--rport', str(port),
stdout=os.open(os.path.join(utils.config.log, 'vifibnet.client.%s.log' % (peer_id,)),
os.O_WRONLY|os.O_CREAT|os.O_TRUNC) ),
iface)
self.connection_dict[peer_id] = ( plib.client( ip, write_pipe, '--dev', iface, '--proto', proto, '--rport', str(port),
stdout=os.open(os.path.join(utils.config.log, 'vifibnet.client.%s.log' % (peer_id,)),
os.O_WRONLY|os.O_CREAT|os.O_TRUNC) ), iface)
self.peers_db.usePeer(peer_id)
except KeyError:
utils.log("Can't establish connection with %s : no available interface" % ip, 2)
......
#!/usr/bin/env python
import argparse, errno, math, os, select, subprocess, sys, time, traceback
from OpenSSL import crypto
import db, openvpn, upnpigd, utils, tunnelmanager
import db, plib, upnpigd, utils, tunnelmanager
def handle_message(msg):
script_type, arg = msg.split()
......@@ -19,24 +19,22 @@ def handle_message(msg):
def main():
# Get arguments
utils.getConfig()
# Launch babel on all interfaces. WARNING : you have to be root to start babeld
utils.log('Starting babel', 3)
babel = startBabel(stdout=os.open(os.path.join(utils.config.log, 'vifibnet.babeld.log'),
babel = plib.babel(stdout=os.open(os.path.join(utils.config.log, 'vifibnet.babeld.log'),
os.O_WRONLY | os.O_CREAT | os.O_TRUNC), stderr=subprocess.STDOUT)
# Create and open read_only pipe to get connect/disconnect events from openvpn
utils.log('Creating pipe for openvpn events', 3)
utils.log('Creating pipe for server events', 3)
r_pipe, write_pipe = os.pipe()
read_pipe = os.fdopen(r_pipe)
# setup the tunnel manager
# Setup the tunnel manager
peers_db = db.PeersDB(utils.config.db)
tunnelManager = tunnelmanager.TunnelManager(write_pipe, peers_db)
# Establish connections
utils.log('Starting openvpn server', 3)
serverProcess = openvpn.server(utils.config.internal_ip, write_pipe, '--dev', 'vifibnet',
serverProcess = plib.server(utils.config.internal_ip, write_pipe, '--dev', 'vifibnet',
stdout=os.open(os.path.join(utils.config.log, 'vifibnet.server.log'), os.O_WRONLY | os.O_CREAT | os.O_TRUNC))
tunnelManager.refresh()
......
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