Skip to content

Commit 0a9e70b

Browse files
committed
Initial commit
1 parent 0521eaf commit 0a9e70b

File tree

6 files changed

+143
-2
lines changed

6 files changed

+143
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vpnwebctl
2-
=========
1+
vpncwebctl
2+
==========
33

44
Control your Cisco VPN client remotely

initctl_template.tpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
<title>VPNC Web Management</title>
4+
<link rel="stylesheet" href="static/style.css" type="text/css">
5+
</head>
6+
<body>
7+
<h1>{{action}} vpnc...</h1>
8+
<h2>Output:</h2>
9+
<pre>{{output}}</pre>
10+
<center>
11+
<p><a href="status">Return to status</a><p>
12+
</center>
13+
</body>
14+
</html>

server.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[vpncweb]
2+
username = admin
3+
password = secret
4+
port = 80
5+
6+
[vpnc]
7+
profile = /etc/vpnc/default.conf
8+
remote_ip = 1.2.3.4

server.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from bottle import static_file, template, post, request, route, run, auth_basic
2+
import ConfigParser
3+
import subprocess
4+
5+
def check_login(username, password):
6+
config = ConfigParser.ConfigParser()
7+
config.read('server.conf')
8+
u = config.get('vpncweb', 'username')
9+
p = config.get('vpncweb', 'password')
10+
if ( u == username and p == password ):
11+
return True
12+
else:
13+
return False
14+
15+
@route('/static/<filename>')
16+
def server_static(filename):
17+
return static_file(filename, root='/opt/vpncwebctl/static')
18+
19+
@route('/initctl', method='POST')
20+
@auth_basic(check_login)
21+
def initctl():
22+
username = request.forms.get('username')
23+
password = request.forms.get('password')
24+
action = request.forms.get('initctl')
25+
config = ConfigParser.ConfigParser()
26+
config.read('server.conf')
27+
profile = config.get('vpnc', 'profile')
28+
if (action == "start"):
29+
p = subprocess.Popen(["vpnc-connect", profile], stdout=subprocess.PIPE)
30+
p_output, p_err = p.communicate()
31+
return template('initctl_template', action=action, output=p_output)
32+
elif (action == "stop"):
33+
p = subprocess.Popen(["vpnc-disconnect"], stdout=subprocess.PIPE)
34+
p_output, p_err = p.communicate()
35+
return template('initctl_template', action=action, output=p_output)
36+
else:
37+
return "<p>Unknown Error</p>"
38+
39+
40+
@route('/')
41+
@route('/status')
42+
@auth_basic(check_login)
43+
def status():
44+
config = ConfigParser.ConfigParser()
45+
config.read('server.conf')
46+
remote_ip = config.get('vpnc', 'remote_ip')
47+
p1 = subprocess.Popen(["pgrep","vpnc"], stdout=subprocess.PIPE)
48+
p1_output, p1_err = p1.communicate()
49+
p2 = subprocess.Popen(["ip","addr","show","tun0"], stdout=subprocess.PIPE)
50+
p2_output, p2_err = p2.communicate()
51+
p3 = subprocess.Popen(["ping", "-q", "-c", "1", remote_ip], stdout=subprocess.PIPE)
52+
p3_output, p3_err = p3.communicate()
53+
if '1 received' in p3_output:
54+
status = "Connected"
55+
else:
56+
status = "Disconnected"
57+
58+
return template('status_template', status=status, pid=p1_output, tun=p2_output, ping=p3_output)
59+
60+
if __name__ == '__main__':
61+
config = ConfigParser.ConfigParser()
62+
config.read('server.conf')
63+
port = config.get('vpncweb', 'port')
64+
run(host='0.0.0.0',port=port)

static/style.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Positional Layout */
2+
3+
body {
4+
margin: 0;
5+
}
6+
7+
body {
8+
background-color: #E8EFEF;
9+
font-family: 'Veranda', sans-serif;
10+
font-size: 16px;
11+
}
12+
13+
h1 {
14+
background-color: #697983;
15+
color: #fff;
16+
margin: 3em -15px 1em -15px;
17+
padding: 7px 15px 5px 15px;
18+
font-size: 140%;
19+
letter-spacing:1px;
20+
}
21+
22+
h2 {
23+
background-color: #697983;
24+
color: #fff;
25+
margin: 3em -15px 1em -15px;
26+
padding: 7px 15px 5px 15px;
27+
font-size: 120%;
28+
letter-spacing:1px;
29+
}
30+
31+
pre {
32+
background-color: #E8EFEF;
33+
margin: 1em 2em;
34+
padding: 0.5em;
35+
border: 1px dotted #697983;
36+
border-width: 1px 0;
37+
}

status_template.tpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html>
2+
<head>
3+
<title>VPNC Web Management</title>
4+
<link rel="stylesheet" href="static/style.css" type="text/css">
5+
</head>
6+
<body>
7+
<h1>VPNC Status: {{status}}</h1>
8+
<h2>vpnc PID: {{pid}}</h2>
9+
<h2>tun0 IP</h2> <pre>{{tun}}</pre>
10+
<h2>Ping</h2><pre>{{ping}}</pre>
11+
<center>
12+
<form action="/initctl" method="post">
13+
<input name="initctl" value="start" type="submit" />
14+
<input name="initctl" value="stop" type="submit" />
15+
</form>
16+
</center>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)