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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
re6stnet
Commits
209ce7c6
Commit
209ce7c6
authored
Jul 06, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.erp5.org/repos/vifibnet
parents
54873e82
aa7588d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
main.py
main.py
+11
-9
No files found.
main.py
View file @
209ce7c6
...
@@ -46,7 +46,7 @@ class PeersDB:
...
@@ -46,7 +46,7 @@ class PeersDB:
def
babel
(
network_ip
,
network_mask
,
verbose_level
):
def
babel
(
network_ip
,
network_mask
):
args
=
[
'babeld'
,
args
=
[
'babeld'
,
'-C'
,
'redistribute local ip %s/%s'
%
(
network_ip
,
network_mask
),
'-C'
,
'redistribute local ip %s/%s'
%
(
network_ip
,
network_mask
),
'-C'
,
'redistribute local deny'
,
'-C'
,
'redistribute local deny'
,
...
@@ -58,7 +58,7 @@ def babel(network_ip, network_mask, verbose_level):
...
@@ -58,7 +58,7 @@ def babel(network_ip, network_mask, verbose_level):
#'-C', 'in ip ::/0 le %s' % network_mask,
#'-C', 'in ip ::/0 le %s' % network_mask,
# Don't route other addresses
# Don't route other addresses
'-C'
,
'in ip deny'
,
'-C'
,
'in ip deny'
,
'-d'
,
str
(
verbose_level
),
'-d'
,
str
(
config
.
verbose
),
'-s'
,
'-s'
,
]
]
if
config
.
babel_state
:
if
config
.
babel_state
:
...
@@ -73,7 +73,7 @@ def getConfig():
...
@@ -73,7 +73,7 @@ def getConfig():
_
=
parser
.
add_argument
_
=
parser
.
add_argument
_
(
'--server-log'
,
default
=
'/var/log/vifibnet.server.log'
,
_
(
'--server-log'
,
default
=
'/var/log/vifibnet.server.log'
,
help
=
'Path to openvpn server log file'
)
help
=
'Path to openvpn server log file'
)
_
(
'--client-log'
,
default
=
'/var/log
/
'
,
_
(
'--client-log'
,
default
=
'/var/log'
,
help
=
'Path to openvpn client log directory'
)
help
=
'Path to openvpn client log directory'
)
_
(
'--client-count'
,
default
=
2
,
type
=
int
,
_
(
'--client-count'
,
default
=
2
,
type
=
int
,
help
=
'the number servers the peers try to connect to'
)
help
=
'the number servers the peers try to connect to'
)
...
@@ -107,7 +107,8 @@ def startNewConnection(n):
...
@@ -107,7 +107,8 @@ 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_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
,
iface
)
stdout
=
os
.
open
(
'%s/vifibnet.client.%s.log'
%
(
config
.
client_log
,
id
),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
iface
)
peers_db
.
usePeer
(
id
)
peers_db
.
usePeer
(
id
)
except
KeyError
:
except
KeyError
:
log_message
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
log_message
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
...
@@ -121,7 +122,7 @@ def killConnection(id):
...
@@ -121,7 +122,7 @@ def killConnection(id):
p
,
iface
=
connection_dict
.
pop
(
id
)
p
,
iface
=
connection_dict
.
pop
(
id
)
p
.
kill
()
p
.
kill
()
free_interface_set
.
add
(
iface
)
free_interface_set
.
add
(
iface
)
peers_db
.
unuse
d
Peer
(
id
)
peers_db
.
unusePeer
(
id
)
except
KeyError
:
except
KeyError
:
log_message
(
"Can't kill connection to "
+
peer
+
": no existing connection"
,
1
)
log_message
(
"Can't kill connection to "
+
peer
+
": no existing connection"
,
1
)
pass
pass
...
@@ -130,11 +131,10 @@ def killConnection(id):
...
@@ -130,11 +131,10 @@ def killConnection(id):
pass
pass
def
checkConnections
():
def
checkConnections
():
toDel
=
set
([])
for
id
in
connection_dict
.
keys
():
for
id
in
connection_dict
.
keys
():
p
,
iface
=
connection_dict
[
id
]
p
,
iface
=
connection_dict
[
id
]
if
p
.
poll
()
!=
None
:
if
p
.
poll
()
!=
None
:
log_message
(
'Connection with
'
+
str
(
id
)
+
' has failed with return code '
+
str
(
p
.
returncode
)
,
3
)
log_message
(
'Connection with
%s has failed with return code %s'
%
(
id
,
p
.
returncode
)
,
3
)
free_interface_set
.
add
(
iface
)
free_interface_set
.
add
(
iface
)
peers_db
.
unusePeer
(
id
)
peers_db
.
unusePeer
(
id
)
del
connection_dict
[
id
]
del
connection_dict
[
id
]
...
@@ -180,11 +180,13 @@ def main():
...
@@ -180,11 +180,13 @@ 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'
,
'--dev'
,
'vifibnet'
,
stdout
=
os
.
open
(
config
.
server_log
,
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
))
stdout
=
os
.
open
(
config
.
server_log
,
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
))
startNewConnection
(
config
.
client_count
)
startNewConnection
(
config
.
client_count
)
# Timed refresh initializing
next_refresh
=
time
.
time
()
+
config
.
refresh_time
next_refresh
=
time
.
time
()
+
config
.
refresh_time
# main loop
# main loop
try
:
try
:
while
True
:
while
True
:
...
...
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