From 6c1f94e5dc64a66f8a9fd06c587b010cbb945d0a Mon Sep 17 00:00:00 2001 From: david Date: Sat, 24 Aug 2013 17:47:25 +0200 Subject: [PATCH] added files --- app.py | 14 ++++++++++++++ openvpnstatus.py | 41 +++++++++++++++++++++++++++++++++++++++++ templates/status.html | 25 +++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 app.py create mode 100644 openvpnstatus.py create mode 100644 templates/status.html diff --git a/app.py b/app.py new file mode 100644 index 0000000..cde80ca --- /dev/null +++ b/app.py @@ -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') diff --git a/openvpnstatus.py b/openvpnstatus.py new file mode 100644 index 0000000..5d7690b --- /dev/null +++ b/openvpnstatus.py @@ -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 diff --git a/templates/status.html b/templates/status.html new file mode 100644 index 0000000..afcadaf --- /dev/null +++ b/templates/status.html @@ -0,0 +1,25 @@ + +OpenVPN Status +

OpenVPN Status

+

Connections:

+ +{% for connection in connections %} + + {% for field in connection %} + + {% endfor %} + +{% endfor %} +
{{ field }}
+
+

Routing Table:

+ +{% for route in routes %} + + {% for field in route %} + + {% endfor %} + +{% endfor %} +
{{ field }}
+