You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.3 KiB
Python

# this is a web interface for simple edits to configuration or editing data
# for particular bureaus
import configparser
import os
from bottle import Bottle, request
import mako
class IhrApp(Bottle):
def __init__(self):
super(IhrApp, self).__init__()
self.name = "IHR App"
self.route("/", callback=self.index)
self.route("/config/<bureau>", callback=self.bureau_config)
self.route("/config/<bureau>", callback=self.bureau_config, method="POST")
self.bureaus = []
def index(self):
# return a list of active bureaus with links
# TODO: allow (de)activation of non-essential bureaus
templfile = "web_index.html"
out = """
<h3>The Screenless Office</h3>
<h4><em>Config Manager</em></h4>
<ul>
"""
for bureau in self.bureaus:
out += '<li><a href="/config/{0}">{0}</a></li>\n'.format(bureau)
out += '<li><a href="/config/printers">Printers</a></li>\n'
out += '<li><a href="/config/mgmt">Management</a></li>\n'
out += "</ul>"
return out
def bureau_config(self, bureau):
# parse the config and make it into a form
templfile = "web_config.html"
template = mako.template.Template(filename=templfile)
basedir = os.path.expanduser("~/.screenless")
if bureau == "mgmt":
cfgfile = "mgmt.ini"
mode = "ini"
elif bureau == "printers":
cfgfile = "printers.cfg"
mode = "ini"
else:
cfgfile = bureau + ".yml"
mode = "yaml"
cfgfile = os.path.join(basedir, cfgfile)
if request.method == "POST":
#save all the request.forms stuff to the config
# tell the bureau to restart / reload
# set our message to be "updated config"
print("NOT saving updated ", cfgfile)
pass
#parse and show the config as a form
with open(cfgfile) as cfg:
cfgdata += cfg.read()
return template.render_unicode(bureau=bureau, cfgfile=cfgfile, mode=mode, cfgdata=cfgdata)
def register_bureau(self, bureau):
self.bureaus.append(bureau)
def register_crud(self, data):
# adds callbacks for crud operations on a database
pass