settings.cgi.in 1.94 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

config_file = "{{ config_cfg }}"

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

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

26 27 28 29
if not parser.has_section('public'):
  print "<p>Your software does not use 0-knowledge settings.</p></body></html>"
  exit(0)

30
for name in form:
31 32
  if parser.has_option('public', name):
    parser.set('public', name, form[name].value)
33 34 35
with open(config_file, 'w') as file:
  parser.write(file)

36
if len(form) > 0:
37 38 39 40
  try:
    os.remove("{{ timestamp }}")
  except OSError:
    pass
41

42
print "<h1>Values that can be defined :</h1>"
43
print "<form action=\"/index.cgi\" method=\"post\" class=\"pure-form-aligned\">"
44 45
print "<input type=\"hidden\" name=\"posting-script\" value=\"{{ pwd }}/{{ this_file }}\">"
for option in parser.options("public"):
46
  print "<div class=\"pure-control-group\">"
47
  print "<label for=\"%s\">%s</label>"%(option, option)
48
  print "<input type=\"text\" name=\"%s\" value=\"%s\">"%(option, parser.get('public', option))
49 50 51 52 53 54
  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\">"
55 56 57
for section in parser.sections():
  if section != 'public':
    for option in parser.options(section):
58
      print "<div class=\"pure-control-group\">"
59
      print "<label for=\"%s\">%s</label>"%(option, option)
60
      print "<input type=\"text\" name=\"%s\" value=\"%s\" readonly>"%(option, parser.get(section, option))
61 62
      print "</div>"
print "</form>"
63 64

print "</body></html>"