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
Xiaowu Zhang
re6stnet
Commits
3b161a08
Commit
3b161a08
authored
Jul 05, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added fifo to get connect openvpn events
parent
08ce480b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
8 deletions
+18
-8
client-connect
client-connect
+3
-0
main.py
main.py
+13
-7
openvpn.py
openvpn.py
+2
-1
No files found.
client-connect
0 → 100755
View file @
3b161a08
#!/usr/bin/python -S
import
os
,
sys
os
.
write
(
int
(
sys
.
argv
[
1
]),
'hello !
\
n
'
)
main.py
View file @
3b161a08
#!/usr/bin/env python
import
argparse
,
errno
,
os
,
sqlite3
,
subprocess
,
sys
,
time
import
argparse
,
errno
,
os
,
s
elect
,
s
qlite3
,
subprocess
,
sys
,
time
import
traceback
import
upnpigd
import
openvpn
...
...
@@ -80,7 +80,7 @@ def startNewConnection(n):
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
)
log_message
(
'Updating peers database'
,
3
)
log_message
(
'Updating peers database'
,
5
)
peer_db
.
execute
(
"UPDATE peers SET used = 1 WHERE id = ?"
,
(
id
,))
except
KeyError
:
log_message
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
...
...
@@ -94,7 +94,7 @@ def killConnection(id):
p
,
iface
=
connection_dict
.
pop
(
id
)
p
.
kill
()
free_interface_set
.
add
(
iface
)
log_message
(
'Updating peers database'
,
3
)
log_message
(
'Updating peers database'
,
5
)
peer_db
.
execute
(
"UPDATE peers SET used = 0 WHERE id = ?"
,
(
id
,))
except
KeyError
:
log_message
(
"Can't kill connection to "
+
peer
+
": no existing connection"
,
1
)
...
...
@@ -134,17 +134,23 @@ def main():
peer_db
.
execute
(
"CREATE INDEX IF NOT EXISTS _peers_used ON peers(used)"
)
peer_db
.
execute
(
"UPDATE peers SET used = 0"
)
# Create and open read_only pipe to get connect/disconnect events from openvpn
log_message
(
'Creating pipe for openvpn events'
,
3
)
r_pipe
,
write_pipe
=
os
.
pipe
()
read_pipe
=
os
.
fdopen
(
r_pipe
)
# Establish connections
log_message
(
'Starting openvpn server'
,
3
)
serverProcess
=
openvpn
.
server
(
config
.
ip
,
serverProcess
=
openvpn
.
server
(
config
.
ip
,
write_pipe
,
'--dev'
,
'vifibnet'
,
stdout
=
os
.
open
(
config
.
server_log
,
os
.
O_RDONLY
|
os
.
O_CREAT
))
startNewConnection
(
config
.
client_count
)
# main loop
try
:
while
True
:
# TODO : use select to get openvpn events from pipes
time
.
sleep
(
float
(
config
.
refresh_time
))
ready
,
tmp1
,
tmp2
=
select
.
select
([
read_pipe
],
[],
[],
float
(
config
.
refresh_time
))
if
ready
:
log_message
(
read_pipe
.
readline
(),
0
)
refreshConnections
()
except
KeyboardInterrupt
:
return
0
...
...
openvpn.py
View file @
3b161a08
...
...
@@ -18,13 +18,14 @@ def openvpn(*args, **kw):
# TODO : set iface up when creating a server/client
# ! check working directory before launching up script ?
def
server
(
ip
,
*
args
,
**
kw
):
def
server
(
ip
,
pipe_fd
,
*
args
,
**
kw
):
return
openvpn
(
'--tls-server'
,
'--keepalive'
,
'10'
,
'60'
,
'--mode'
,
'server'
,
'--duplicate-cn'
,
# XXX : to be removed
'--up'
,
'up-server '
+
ip
,
'--client-connect'
,
'client-connect '
+
str
(
pipe_fd
),
'--dh'
,
config
.
dh
,
*
args
,
**
kw
)
...
...
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