Browse Source

added files

main
david 8 years ago
parent
commit
6c1f94e5dc
  1. 14
      app.py
  2. 41
      openvpnstatus.py
  3. 25
      templates/status.html

14
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')

41
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

25
templates/status.html

@ -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">