status.cgi.in 1.37 KB
Newer Older
1
#!{{ python_executable }}
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

import cgi
import cgitb
import json
import sys

cgitb.enable(display=0, logdir="/tmp/cgi.log")

json_file = "{{ json_file }}"
result = json.load(open(json_file))

# Headers
print "Content-Type: text/html"
print

# Body content
form = cgi.FieldStorage()
if "password" not in form:
  print """<html>
  <body>
  <h1>This is the monitoring interface</h1>
  <p>Please enter the monitor_password in the next field to access the data</p>
24
  <form action="/{{ this_filename }}" method="post">
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    Password : <input type="password" name="password">
    <input type="submit" value="Access">
  </form></body></html>"""

elif form['password'].value != '{{ password }}':
  print "<html><body><h1>Error</h1><p>Wrong password</p></body></html>"

else:
  print "<html><body>"
  print "<h1>Monitoring :</h1>"
  print "<p><em>Last time of monitoring process : %s</em></p>" % (result['datetime'])
  del result['datetime']
  print "<br/>"

  print "<h2>These scripts and promises have failed :</h2>"
  for r in result:
    if result[r] != '':
      print "<h3>%s</h3><p style=\"padding-left:30px;\">%s</p>" % (r, result[r])
  print "<br/>"

  print "<h2>These scripts and promises were successful :</h2>"
  for r in result:
    if result[r] == '':
      print "<h3>%s</h3><p>%s</p>" % (r, result[r])
49
  print "<br><br><p><a href=\"/control.cgi\">Control interface</a></p>"
50
  print "</body></html>"