settings.cgi.in 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!{{ python_executable }}

import cgi
import cgitb
import ConfigParser
import os

cgitb.enable()
form = cgi.FieldStorage()

11 12 13 14
print "<html><head>"
print "<link rel=\"stylesheet\" href=\"pure-min.css\">"
print "<link rel=\"stylesheet\" href=\"/style.css\">"
print "</head><body>"
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

config_file = "{{ config_cfg }}"

if not os.path.exists(config_file):
  print "Your software does <b>not</b> embed 0-knowledge. \
  This interface is useless in this case"
  exit(0)

parser = ConfigParser.ConfigParser()
parser.read(config_file)

for name in form:
  parser.set('public', name, form[name].value)
with open(config_file, 'w') as file:
  parser.write(file)

31
if len(form) > 0:
32 33 34 35
  try:
    os.remove("{{ timestamp }}")
  except OSError:
    pass
36

37
print "<h1>Values that can be defined :</h1>"
38
print "<form action=\"/index.cgi\" method=\"post\" class=\"pure-form-aligned\">"
39 40
print "<input type=\"hidden\" name=\"posting-script\" value=\"{{ pwd }}/{{ this_file }}\">"
for option in parser.options("public"):
41
  print "<div class=\"pure-control-group\">"
42
  print "<label for=\"%s\">%s</label>"%(option, option)
43
  print "<input type=\"text\" name=\"%s\" value=\"%s\">"%(option, parser.get('public', option))
44 45 46 47 48 49
  print "</div>"
print "<div class=\"pure-controls\"><button type=\"submit\" class=\"pure-button \
 pure-button-primary\">Save</button></div></form>"

print "<br><h1>Other values :</h1>"
print "<form class=\"pure-form-aligned\">"
50 51 52
for section in parser.sections():
  if section != 'public':
    for option in parser.options(section):
53
      print "<div class=\"pure-control-group\">"
54
      print "<label for=\"%s\">%s</label>"%(option, option)
55
      print "<input type=\"text\" name=\"%s\" value=\"%s\" readonly>"%(option, parser.get(section, option))
56 57
      print "</div>"
print "</form>"
58 59

print "</body></html>"