Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Yohann D'Anello
re6stnet
Commits
550be227
Commit
550be227
authored
Jul 17, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned some log messages in main
parent
abe109ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
17 deletions
+14
-17
plib.py
plib.py
+4
-2
tunnelmanager.py
tunnelmanager.py
+4
-7
vifibnet.py
vifibnet.py
+6
-8
No files found.
plib.py
View file @
550be227
...
@@ -27,6 +27,7 @@ def openvpn(*args, **kw):
...
@@ -27,6 +27,7 @@ def openvpn(*args, **kw):
# ! check working directory before launching up script ?
# ! check working directory before launching up script ?
def
server
(
ip
,
pipe_fd
,
*
args
,
**
kw
):
def
server
(
ip
,
pipe_fd
,
*
args
,
**
kw
):
utils
.
log
(
'Starting server'
,
3
)
return
openvpn
(
return
openvpn
(
'--tls-server'
,
'--tls-server'
,
'--mode'
,
'server'
,
'--mode'
,
'server'
,
...
@@ -38,6 +39,7 @@ def server(ip, pipe_fd, *args, **kw):
...
@@ -38,6 +39,7 @@ def server(ip, pipe_fd, *args, **kw):
*
args
,
**
kw
)
*
args
,
**
kw
)
def
client
(
serverIp
,
pipe_fd
,
*
args
,
**
kw
):
def
client
(
serverIp
,
pipe_fd
,
*
args
,
**
kw
):
utils
.
log
(
'Starting client'
,
5
)
return
openvpn
(
return
openvpn
(
'--nobind'
,
'--nobind'
,
'--client'
,
'--client'
,
...
@@ -47,6 +49,7 @@ def client(serverIp, pipe_fd, *args, **kw):
...
@@ -47,6 +49,7 @@ def client(serverIp, pipe_fd, *args, **kw):
*
args
,
**
kw
)
*
args
,
**
kw
)
def
babel
(
**
kw
):
def
babel
(
**
kw
):
utils
.
log
(
'Starting babel'
,
3
)
args
=
[
'babeld'
,
args
=
[
'babeld'
,
'-C'
,
'redistribute local ip %s'
%
(
utils
.
config
.
internal_ip
),
'-C'
,
'redistribute local ip %s'
%
(
utils
.
config
.
internal_ip
),
'-C'
,
'redistribute local deny'
,
'-C'
,
'redistribute local deny'
,
...
@@ -64,7 +67,6 @@ def babel(**kw):
...
@@ -64,7 +67,6 @@ def babel(**kw):
if
utils
.
config
.
babel_state
:
if
utils
.
config
.
babel_state
:
args
+=
'-S'
,
utils
.
config
.
babel_state
args
+=
'-S'
,
utils
.
config
.
babel_state
args
=
args
+
[
'vifibnet'
]
+
list
(
tunnelmanager
.
free_interface_set
)
args
=
args
+
[
'vifibnet'
]
+
list
(
tunnelmanager
.
free_interface_set
)
if
utils
.
config
.
verbose
>=
5
:
utils
.
log
(
str
(
args
),
5
)
print
args
return
subprocess
.
Popen
(
args
,
**
kw
)
return
subprocess
.
Popen
(
args
,
**
kw
)
tunnelmanager.py
View file @
550be227
import
os
,
random
,
traceback
import
os
,
random
,
traceback
import
openvpn
import
plib
,
utils
,
db
import
utils
import
db
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
'client6'
,
'client7'
,
'client8'
,
'client9'
,
'client10'
))
'client6'
,
'client7'
,
'client8'
,
'client9'
,
'client10'
))
...
@@ -44,10 +42,9 @@ class TunnelManager:
...
@@ -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
):
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
)
utils
.
log
(
'Establishing a connection with id %s (%s:%s)'
%
(
peer_id
,
ip
,
port
),
2
)
iface
=
free_interface_set
.
pop
()
iface
=
free_interface_set
.
pop
()
self
.
connection_dict
[
peer_id
]
=
(
openvpn
.
client
(
ip
,
write_pipe
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
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
,)),
stdout
=
os
.
open
(
os
.
path
.
join
(
utils
.
config
.
log
,
'vifibnet.client.%s.log'
%
(
peer_id
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
iface
)
iface
)
self
.
peers_db
.
usePeer
(
peer_id
)
self
.
peers_db
.
usePeer
(
peer_id
)
except
KeyError
:
except
KeyError
:
utils
.
log
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
utils
.
log
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
...
...
vifibnet.py
View file @
550be227
#!/usr/bin/env python
#!/usr/bin/env python
import
argparse
,
errno
,
math
,
os
,
select
,
subprocess
,
sys
,
time
,
traceback
import
argparse
,
errno
,
math
,
os
,
select
,
subprocess
,
sys
,
time
,
traceback
from
OpenSSL
import
crypto
from
OpenSSL
import
crypto
import
db
,
openvpn
,
upnpigd
,
utils
,
tunnelmanager
import
db
,
plib
,
upnpigd
,
utils
,
tunnelmanager
def
handle_message
(
msg
):
def
handle_message
(
msg
):
script_type
,
arg
=
msg
.
split
()
script_type
,
arg
=
msg
.
split
()
...
@@ -19,24 +19,22 @@ def handle_message(msg):
...
@@ -19,24 +19,22 @@ def handle_message(msg):
def
main
():
def
main
():
# Get arguments
# Get arguments
utils
.
getConfig
()
utils
.
getConfig
()
# Launch babel on all interfaces. WARNING : you have to be root to start babeld
# Launch babel on all interfaces. WARNING : you have to be root to start babeld
utils
.
log
(
'Starting babel'
,
3
)
babel
=
plib
.
babel
(
stdout
=
os
.
open
(
os
.
path
.
join
(
utils
.
config
.
log
,
'vifibnet.babeld.log'
),
babel
=
startBabel
(
stdout
=
os
.
open
(
os
.
path
.
join
(
utils
.
config
.
log
,
'vifibnet.babeld.log'
),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
),
stderr
=
subprocess
.
STDOUT
)
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
# 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
()
r_pipe
,
write_pipe
=
os
.
pipe
()
read_pipe
=
os
.
fdopen
(
r_pipe
)
read_pipe
=
os
.
fdopen
(
r_pipe
)
#
setup the tunnel manager
#
Setup the tunnel manager
peers_db
=
db
.
PeersDB
(
utils
.
config
.
db
)
peers_db
=
db
.
PeersDB
(
utils
.
config
.
db
)
tunnelManager
=
tunnelmanager
.
TunnelManager
(
write_pipe
,
peers_db
)
tunnelManager
=
tunnelmanager
.
TunnelManager
(
write_pipe
,
peers_db
)
# Establish connections
# Establish connections
utils
.
log
(
'Starting openvpn server'
,
3
)
serverProcess
=
plib
.
server
(
utils
.
config
.
internal_ip
,
write_pipe
,
'--dev'
,
'vifibnet'
,
serverProcess
=
openvpn
.
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
))
stdout
=
os
.
open
(
os
.
path
.
join
(
utils
.
config
.
log
,
'vifibnet.server.log'
),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
))
tunnelManager
.
refresh
()
tunnelManager
.
refresh
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment