david/openvpnstatus
david
/
openvpnstatus
Archived
1
0
Fork 0

added files

This commit is contained in:
david 2013-08-24 17:47:25 +02:00
parent 0e1996e472
commit 6c1f94e5dc
3 changed files with 80 additions and 0 deletions

14
app.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env python
from flask import Flask, render_template
import openvpnstatus
app = Flask(__name__)
@app.route('/')
def status():
o = openvpnstatus.openvpnstatus()
return render_template('status.html', connections = o.connections, routes = o.routes)
if __name__ == '__main__':
app.run(host='0.0.0.0')

41
openvpnstatus.py Normal file
View File

@ -0,0 +1,41 @@
class openvpnstatus(object):
"""read the openvpn-status.log file"""
def __init__(self):
self.update()
def update(self):
"""read file"""
import os
self.connections = []
self.routes = []
f = open("openvpn-status.log", "r")
state = 0
for line in f:
if "Updated" in line:
state = 1
continue
elif "ROUTING" in line:
state = 2
continue
elif "GLOBAL" in line:
state = 0
break
if state == 1:
fields = line.split(",")
self.connections.append(fields)
elif state == 2:
fields = line.split(",")
self.routes.append(fields)
f.close()
#end of file

25
templates/status.html Normal file
View File

@ -0,0 +1,25 @@
<!doctype html>
<title>OpenVPN Status</title>
<h1>OpenVPN Status</h1>
<h3>Connections:</h3>
<table border="0" width="80%">
{% for connection in connections %}
<tr>
{% for field in connection %}
<td>{{ field }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
<hr width="80%" align="left">
<h3>Routing Table:</h3>
<table border="0" width="80%">
{% for route in routes %}
<tr>
{% for field in route %}
<td>{{ field }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
<hr width="80%" align="left">