output of log action fixed

added some RFCs
added some unittests for CryptoBox config handling
This commit is contained in:
lars 2006-08-25 07:37:52 +00:00
parent 3b97f675bf
commit 3fd2064439
5 changed files with 139 additions and 86 deletions

View file

@ -3,6 +3,8 @@ import CryptoBoxWebserverSettings
import CryptoBoxWebserverRender
website = CryptoBoxWebserverRender.CryptoBoxWebserverRender()
# is it necessary to inherit these both classes?
# for clarity they should be just instanciated - or not?
class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettings.CryptoBoxWebserverSettings):
'''
url2func = {'index':'show_status','doc':'show_doc','logs':'show_log'}
@ -14,9 +16,11 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
The default site to render is 'show_status'.
Self.settings is filled by the following methodcall
thus every rendered site will get actual values from the configfile.
After that the concrete site-method (e.g. doc) may set individual values.
After that the corresponding site-method (e.g. doc) may set individual values.
'''
# RFC: the following line somehow implicitly calls 'setSettings(self, self)'
# should it be that way? [l]
self.setSettings(self)
#self.settings
self.settings["Data.Action"] = action
@ -29,7 +33,9 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
Every single site method has to call this before even looking
at url-given parameters.
This has to be called manually, since I don't see any other way of
sanitizing input automatically for all sites.'''
sanitizing input automatically for all sites.
# RFC: why shouldn't it be called in __init__? [l]
'''
#TODO: generate languages from existing hdf files
niceparams = { 'weblang': ('', 'de', 'en'),
'loglevel': ('','info', 'warn', 'debug', 'error'),
@ -38,7 +44,7 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
for evilkey in evilparams.keys():
## if the param isn't in the niceparams list, ignore it
if not niceparams.get(evilkey):
self.log.warn("irgnoring \"%s\"" % evilkey)
self.log.warn("ignoring \"%s\"" % evilkey)
return False
#TODO: until now only a warning message is printed
## if the param has no such value, set it to a default (the first in the list)
@ -47,28 +53,33 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
#TODO: set it to: niceparams.get(evilkey)[0]))
return
def __check_config(self):
#TODO
pass
def __check_init_running(self):
#TODO
pass
######################################################################
## put real sites down here and don't forget to expose the mat the end
## put real sites down here and don't forget to expose them at the end
def logs(self, loglevel=""):
'''displays a HTML version of the logfile
The loglevel has to be set and nothing else, as we just log in
english.
Be awar not to name this method just "log" as it seems to be a
reserved word.'''
The loglevel has to be set and nothing else, as we just log in english.
RFC: what does this mean? We still have to save the current language - or not?
Be aware not to name this method just "log" as it seems to be a
reserved word.
# RFC: maybe it conflicts with CryptoBoxProps.log - which we inherited?
'''
self.__sanitize_input({"loglevel":loglevel})
self.__prepare("show_log")
import filehandling
self.settings["Data.Log"] = filehandling.read_file(self.settings["Log.Details"])
self.settings["Data.Log"] = "<br/>".join(self.getLogData(lines=30, maxSize=2000))
#TODO: give the logs a nice format for displaying as html
# sed s/$/<\/br>/
return website.render(self)
@ -90,46 +101,52 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
self.settings["Data.Action"] = "show_status"
self.settings["Data.Redirect.Delay"] = "60"
return website.render(self)
def config(self,weblang=""):
pass
def doc(self,action="",page="",weblang=""):
'''prints the offline wikipage
TODO: action is unnessessary, remove here and from all html
files in doc/html/[de|en]/*
'''
# RFC: sanitize?
self.__prepare("show_doc")
if page:
self.settings["Data.Doc.Page"] = page
if page == "":
self.settings["Data.Doc.Page"] ="CryptoBoxUser"
if not weblang == "":
# TODO: check if there is a 'weblang' translation available for the docs
self.settings["Settings.DocLang"] = weblang
return website.render(self)
def system(self,type=""):
def system(self,typeOfShutdown=""):
self.__prepare("form_system")
if type == "reboot":
if typeOfShutdown == "reboot":
self.settings["Data.Success"] = "ReBoot"
self.settings["Data.Redirect.Action"] = "show_status"
self.settings["Data.Redirect.Delay"] = "180"
self.log.info("TODO: call function for system reboot")
elif type == "poweroff":
elif typeOfShutdown == "poweroff":
self.settings["Data.Success"] = "PowerOff"
self.log.info("TODO: call function for system shutdown")
else:
self.log.warn("someone tried to shutdown the system")
self.log.warn("someone tried to shutdown the system in a broken way (%s)" % typeOfShutdown)
return website.render(self)
def index(self):
self.__prepare("show_status")
return website.render(self)
'''
## DONE: this functions are pythonized
## DONE: these functions are pythonized
#################### show_log #######################
##################### doc ############################
##################### poweroff ######################
@ -182,6 +199,7 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
#at cryptobox.pl line 568
'''
############################################################################
## to make the sites visible through the webserver they must be exposed here
index.exposed = True