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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
re6stnet
Commits
51bf0f51
Commit
51bf0f51
authored
Jul 03, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
3aa12fca
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
98 deletions
+43
-98
config.py
config.py
+0
-16
configuration.py
configuration.py
+0
-30
main.py
main.py
+43
-6
openvpn.py
openvpn.py
+0
-46
No files found.
config.py
deleted
100644 → 0
View file @
3aa12fca
import
socket
hostname
=
socket
.
gethostname
()
CaPath
=
'/root/overnet/keys/ca.crt'
CertPath
=
'/root/overnet/keys/server.crt'
KeyPath
=
'/root/overnet/keys/server.key'
DhPath
=
'/root/overnet/keys/dh1024.pem'
if
hostname
==
'm5'
:
IPv6
=
'2000:0:0:1::1/64'
MandatoryConnections
=
[(
'10.1.4.3'
,
1194
)]
elif
hostname
==
'm6'
:
IPv6
=
'2000:0:0:2::1/64'
Debug
=
True
configuration.py
deleted
100644 → 0
View file @
3aa12fca
def
CheckVarExists
(
varName
):
return
varName
in
config
.
__dict__
def
FailIfNotExists
(
varName
):
if
not
CheckVarExists
(
varName
):
print
'Entry '
+
varName
+
' not found in config.py'
sys
.
exit
(
-
1
)
def
SetIfNotExists
(
varName
,
value
):
if
not
CheckVarExists
(
varName
):
config
.
__dict__
[
varName
]
=
value
# Check that the file config.py exist and is valid
try
:
import
config
except
ImportError
:
print
'Unable to read the config file config.py'
sys
.
exit
(
-
1
)
# Check vars existence
FailIfNotExists
(
'CaPath'
)
FailIfNotExists
(
'CertPath'
)
FailIfNotExists
(
'KeyPath'
)
FailIfNotExists
(
'DhPath'
)
FailIfNotExists
(
'IPv6'
)
SetIfNotExists
(
'Debug'
,
False
)
SetIfNotExists
(
'MandatoryConnections'
,
[])
SetIfNotExists
(
'LocalPort'
,
1194
)
main.py
View file @
51bf0f51
#!/usr/bin/env python
import
argparse
,
errno
,
os
,
subprocess
,
sys
,
time
import
upnpigd
import
openvpn
from
configuration
import
*
(
ip
,
port
)
=
upnpigd
.
GetExternalInfo
(
config
.
LocalPort
)
openvpn
.
LaunchServer
()
def
openvpn
(
*
args
,
**
kw
):
args
=
[
'openvpn'
,
'--dev'
,
'tap'
,
'--ca'
,
ca_path
,
'--cert'
,
cert_path
,
'--key'
,
key_path
,
'--nobind'
,
'--persist-tun'
,
'--persist-key'
,
'--user'
'nobody'
,
'--group'
,
'nogroup'
,
]
+
list
(
args
)
#stdin = kw.pop('stdin', None)
#stdout = kw.pop('stdout', None)
#stderr = kw.pop('stderr', None)
for
i
in
kw
.
iteritems
():
args
.
append
(
'--%s=%s'
%
i
)
return
subprocess
.
Popen
(
args
,
#stdin=stdin, stdout=stdout, stderr=stderr,
)
# TODO : set iface up when creating a server/client
# ! check working directory before launching up script ?
def
server
(
*
args
,
**
kw
):
return
openvpn
(
'--tls-server'
,
'--client-to-client'
,
#'--keepalive', '10', '60',
mode
=
'server'
,
dh
=
dh_path
,
*
args
,
**
kw
)
def
client
(
ip
,
*
args
,
**
kw
):
return
openvpn
(
remote
=
ip
,
*
args
,
**
kw
)
def
main
():
server
=
openvpn
.
server
(
dev
=
"server"
,
verb
=
3
)
pass
if
__name__
==
"__main__"
:
main
()
for
(
address
,
port
)
in
config
.
MandatoryConnections
:
openvpn
.
LaunchClient
(
address
,
port
)
openvpn.py
deleted
100644 → 0
View file @
3aa12fca
from
subprocess
import
call
from
configuration
import
*
def
LaunchClient
(
serverAddress
,
serverPort
):
if
config
.
Debug
:
print
'Connecting to :'
+
serverAddress
call
([
'openvpn'
,
'--client'
,
'--dev'
,
'tap'
,
'--proto'
,
'udp'
,
'--remote'
,
serverAddress
,
str
(
serverPort
),
'--nobind'
,
'--script-security'
,
'2'
,
'--up'
,
'./up-client'
,
'--persist-key'
,
'--persist-tun'
,
'--tls-client'
,
'--ca'
,
config
.
CaPath
,
'--cert'
,
config
.
CertPath
,
'--key'
,
config
.
KeyPath
,
'--user'
,
'nobody'
,
'--verb'
,
'3'
,
'--daemon'
,
'openVpnClient('
+
serverAddress
+
')'
])
def
LaunchServer
():
call
([
'openvpn'
,
'--dev'
,
'tap'
,
'--mode'
,
'server'
,
'--proto'
,
'udp'
,
'--tls-server'
,
'--ca'
,
config
.
CaPath
,
'--cert'
,
config
.
CertPath
,
'--key'
,
config
.
KeyPath
,
'--dh'
,
config
.
DhPath
,
'--user'
,
'nobody'
,
'--port'
,
str
(
config
.
LocalPort
),
'--up'
,
'./up-server '
+
config
.
IPv6
,
'--script-security'
,
'2'
,
'--persist-tun'
,
'--persist-key'
,
'--daemon'
,
'openvpnServer'
,
'--verb'
,
'3'
])
# TODO : should we use comp-lzo option ?
# TODO : group nobody
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