now checks url params

adapted templates
renderer checks for sources
This commit is contained in:
age 2006-08-24 14:41:11 +00:00
parent 414a6c6e60
commit 3b97f675bf
8 changed files with 94 additions and 50 deletions

View file

@ -60,14 +60,14 @@ class CryptoBox:
self.log.info("loggingsystem is up'n running") self.log.info("loggingsystem is up'n running")
## from now on everything can be logged via self.log... ## from now on everything can be logged via self.log...
except: except:
sys.errorExit("SystemError","Something with the loggingsystem went wrong. I give up.") sys.errorExit("SystemError","Couldn't initialise the loggingsystem. I give up.")
def __initPreferences(self, config_file): def __initPreferences(self, config_file):
try: try:
import configobj ## needed for reading and writing of the config file import configobj ## needed for reading and writing of the config file
except: except:
self.errorExit("SystemError", "Could't import 'configobj'! Try 'apt-get install python-configobj'.") self.errorExit("SystemError", "Couldn't import 'configobj'! Try 'apt-get install python-configobj'.")
# search for the configuration file # search for the configuration file
if config_file is None: if config_file is None:
# no config file was specified - we will look for it in the ususal locations # no config file was specified - we will look for it in the ususal locations

View file

@ -1,26 +1,36 @@
import os
try: try:
import neo_cgi, neo_util, neo_cs import neo_cgi, neo_util, neo_cs
except: except:
print "could not import clearsilver modules! Try apt-get install python-clearsilver." print "could not import clearsilver modules! Try apt-get install python-clearsilver."
class CryptoBoxWebserverRender: class CryptoBoxWebserverRender:
'''renders the site with clearsilver template and languagefile
'''
def render(self, website): def render(self, website):
''' '''renders from clearsilver templates and returns the resulting html
render a clearsilver template and return the result.
gets: Gets a dictionary with all settings, nessessary for rendering.
- path to clearsilver template In fact the dictionary is a copy of the CryptoBoxWerbserverSite
- dictionary with settings (optional) object, that calls this render method. This might be bloat but
- path to hdf dataset (optional) this way the render method has always a complete, actual set of values.
''' '''
## overload to the max website.log.info("rendering site: "+website.settings["Data.Action"])
website.log.info("rendering site: "+website.settings["Data.Action"]+" "+str(website.settings))
cs_path = website.cbxPrefs["Settings"]["TemplateDir"]+"/main.cs" cs_path = website.cbxPrefs["Settings"]["TemplateDir"]+"/main.cs"
if not os.access(cs_path, os.R_OK):
website.log.error("Couldn't read cs file: %s" % cs_path)
return "Couldn't read cs file: %s" % cs_path
hdf_path = website.cbxPrefs["Settings"]["LangDir"]+"/"+website.cbxPrefs["Settings"]["Language"]+".hdf" hdf_path = website.cbxPrefs["Settings"]["LangDir"]+"/"+website.cbxPrefs["Settings"]["Language"]+".hdf"
if not os.access(hdf_path, os.R_OK):
website.log.error("Couldn't read hdf file: %s" % hdf_path)
return "Couldn't read hdf file: %s" % hdf_path
hdf = neo_util.HDF() hdf = neo_util.HDF()
if hdf_path != "": hdf.readFile(hdf_path)
hdf.readFile(hdf_path)
for key in website.settings.keys(): for key in website.settings.keys():
hdf.setValue(key,str(website.settings[key])) hdf.setValue(key,str(website.settings[key]))
cs = neo_cs.CS(hdf) cs = neo_cs.CS(hdf)

View file

@ -4,16 +4,17 @@ class CryptoBoxWebserverSettings:
put the stuff in here, that every site will need access to''' put the stuff in here, that every site will need access to'''
def setSettings(self, website): def setSettings(self, website):
'''a dictionary gets filled here, with values from the configfile '''fills a dictionary with values from the configfile
there can also be set some useful standards here''' There may also be set some useful standards here.'''
website.settings={} website.settings={}
## put all found Settings values in the dictionary ## put all found Settings values in the dictionary
for key in self.cbxPrefs["Settings"].keys(): for key in self.cbxPrefs["Settings"].keys():
website.settings["Settings."+key] = self.cbxPrefs["Settings"][key] website.settings["Settings."+key] = self.cbxPrefs["Settings"][key]
## also all Log values
for key in self.cbxPrefs["Log"].keys():
website.settings["Log."+key] = self.cbxPrefs["Log"][key]
## for reading the logbook, we have to propagate it's # filename
website.settings["Settings.Details"] = self.cbxPrefs["Log"]["Details"]
#self.log.info(self.settings) #self.log.info(self.settings)

View file

@ -8,44 +8,75 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
url2func = {'index':'show_status','doc':'show_doc','logs':'show_log'} url2func = {'index':'show_status','doc':'show_doc','logs':'show_log'}
''' '''
def __prepare(self, csname="show_status"): def __prepare(self, action="show_status"):
'''this method handles stuff that all sites need as preparation '''handles stuff that all sites need as preparation
self.settings is filled be the following methodcall The default site to render is 'show_status'.
thus every rendered site will get actual values from the configfile Self.settings is filled by the following methodcall
after that the site-method may set individual values too thus every rendered site will get actual values from the configfile.
After that the concrete site-method (e.g. doc) may set individual values.
''' '''
self.setSettings(self) self.setSettings(self)
self.settings #self.settings
## default site to render is 'show_status' self.settings["Data.Action"] = action
self.settings["Data.Action"] = csname
#TODO: check ssl status #TODO: check ssl status
def __sanitize_input(self,data): def __sanitize_input(self, evilparams):
#TODO: don't let evil cracker fuck up your code '''mistrusts every given parameter and wipes crap out
return data
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.'''
#TODO: generate languages from existing hdf files
niceparams = { 'weblang': ('', 'de', 'en'),
'loglevel': ('','info', 'warn', 'debug', 'error'),
'type': ('reboot', 'poweroff')
}
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)
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)
if evilparams.get(evilkey) not in niceparams.get(evilkey):
self.log.warn("\"%s\" not in weblang %s"% (evilkey, niceparams.get(evilkey)))
#TODO: set it to: niceparams.get(evilkey)[0]))
return
def __check_config(self): def __check_config(self):
#TODO
pass pass
def __check_init_running(self): def __check_init_running(self):
#TODO
pass 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 the mat the end
def logs(self): def logs(self, loglevel=""):
'''be careful to name this method just "log" seems to be a '''displays a HTML version of the logfile
reserved word'''
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.'''
self.__sanitize_input({"loglevel":loglevel})
self.__prepare("show_log") self.__prepare("show_log")
import filehandling import filehandling
self.settings["Data.Log"] = filehandling.read_file(self.settings["Settings.Details"]) self.settings["Data.Log"] = filehandling.read_file(self.settings["Log.Details"])
#TODO: give the logs a nice format for displaying as html #TODO: give the logs a nice format for displaying as html
# sed s/$/<\/br>/ # sed s/$/<\/br>/
return website.render(self) return website.render(self)
def status(self): def status(self, weblang=""):
'''shows the current status of the box
'''
self.__sanitize_input({"weblang":weblang})
self.__prepare("show_status") self.__prepare("show_status")
if not self.__check_config(): if not self.__check_config():
self.settings["Data.Warning"] = "NotInitialized" self.settings["Data.Warning"] = "NotInitialized"
@ -59,18 +90,23 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
self.settings["Data.Action"] = "show_status" self.settings["Data.Action"] = "show_status"
self.settings["Data.Redirect.Delay"] = "60" self.settings["Data.Redirect.Delay"] = "60"
return website.render(self) return website.render(self)
def config(self,weblang=""):
pass
def doc(self,action="",page="",weblang=""): def doc(self,action="",page="",weblang=""):
#TODO: action is unnessessary, remove here and from all templates '''prints the offline wikipage
TODO: action is unnessessary, remove here and from all html
files in doc/html/[de|en]/*
'''
self.__prepare("show_doc") self.__prepare("show_doc")
if not page == "": if page:
self.settings["Data.Doc.Page"] = page self.settings["Data.Doc.Page"] = page
#self.log.info(page) if page == "":
#self.log.info(self.settings)
else:
self.settings["Data.Doc.Page"] ="CryptoBoxUser" self.settings["Data.Doc.Page"] ="CryptoBoxUser"
#self.log.info(page) if not weblang == "":
#self.log.info(self.settings) self.settings["Settings.DocLang"] = weblang
return website.render(self) return website.render(self)
def system(self,type=""): def system(self,type=""):

View file

@ -60,7 +60,7 @@ Language = de
#path to documentation files #path to documentation files
DocDir = ../doc/html DocDir = ../doc/html
#default language for documentation #default language for documentation
DocLang = en DocLang = de
[Programs] [Programs]
cryptsetup = /sbin/cryptsetup cryptsetup = /sbin/cryptsetup

View file

@ -5,11 +5,11 @@
<p><ul> <p><ul>
<?cs # poweroff ?> <?cs # poweroff ?>
<li><a href="<?cs call:link('reboot','','','','') ?>" title="<?cs var:html_escape(Lang.Button.PowerOff) ?>"> <li><a href="<?cs call:link('system','type','poweroff','','') ?>" title="<?cs var:html_escape(Lang.Button.PowerOff) ?>">
<?cs var:html_escape(Lang.Button.PowerOff) ?></a></li> <?cs var:html_escape(Lang.Button.PowerOff) ?></a></li>
<?cs # reboot ?> <?cs # reboot ?>
<li><a href="<?cs call:link('shutdown_do','type','reboot','','') ?>" title="<?cs <li><a href="<?cs call:link('system','type','reboot','','') ?>" title="<?cs
var:html_escape(Lang.Button.ReBoot) ?>"><?cs var:html_escape(Lang.Button.ReBoot) ?></a></li> var:html_escape(Lang.Button.ReBoot) ?>"><?cs var:html_escape(Lang.Button.ReBoot) ?></a></li>
<?cs # config ?> <?cs # config ?>
@ -21,7 +21,7 @@
var:html_escape(Lang.Button.DoInit) ?>"><?cs var:html_escape(Lang.Button.DoInit) ?></a></li> var:html_escape(Lang.Button.DoInit) ?>"><?cs var:html_escape(Lang.Button.DoInit) ?></a></li>
<?cs # show log files ?> <?cs # show log files ?>
<li><a href="/logs" title="<?cs var:html_escape(Lang.Button.Protocol) ?>"><?cs var:html_escape(Lang.Button.Protocol) ?></a></li> <li><a href="<?cs call:link('logs','','','','') ?>" title="<?cs var:html_escape(Lang.Button.Protocol) ?>"><?cs var:html_escape(Lang.Button.Protocol) ?></a></li>
</ul></p> </ul></p>

View file

@ -60,7 +60,7 @@ def:link(path, attr1, value1, attr2, value2)
?><?cs if:attr1 != "" ?><?cs set:Temp[attr1] = value1 ?><?cs /if ?><?cs if:attr1 != "" ?><?cs set:Temp[attr1] = value1 ?><?cs /if
?><?cs if:attr2 != "" ?><?cs set:Temp[attr2] = value2 ?><?cs /if ?><?cs if:attr2 != "" ?><?cs set:Temp[attr2] = value2 ?><?cs /if
?><?cs var:ScriptName ?><?cs var:ScriptName
?>/<?cs:var:path ?>/<?cs var:path
?><?cs set:first_each = 1 ?><?cs set:first_each = 1
?><?cs if:subcount(Temp) > 0 ?><?cs if:subcount(Temp) > 0
?><?cs each:attrs = Temp ?><?cs each:attrs = Temp

View file

@ -19,10 +19,7 @@
<?cs /if ?> <?cs /if ?>
<?cs # manual ?> <?cs # manual ?>
<!-- <a href="<?cs call:link('doc','','','','') ?>" title="<?cs var:html_escape(Lang.Button.Documentation) ?>"><?cs var:html_escape(Lang.Button.Documentation) ?></a>--> <a href="<?cs call:link('doc','','','','') ?>" title="<?cs var:html_escape(Lang.Button.Documentation) ?>"><?cs var:html_escape(Lang.Button.Documentation) ?></a>
<a href="<?cs call:link('status','','','','') ?>" title="<?cs var:html_escape(Lang.Button.Status) ?>"><?cs var:html_escape(Lang.Button.Status) ?></a>
<a href="/status" title="<?cs var:html_escape(Lang.Button.Status) ?>"><?cs var:html_escape(Lang.Button.Status) ?></a> <a href="<?cs call:link('system','','','','') ?>" title="<?cs var:html_escape(Lang.Button.System) ?>"><?cs var:html_escape(Lang.Button.System) ?></a>
<a href="/doc" title="<?cs var:html_escape(Lang.Button.Documentation) ?>"><?cs var:html_escape(Lang.Button.Documentation) ?></a>
<a href="/logs" title="<?cs var:html_escape(Lang.Button.Protocol) ?>"><?cs var:html_escape(Lang.Button.Protocol) ?></a>
<a href="/system" title="<?cs var:html_escape(Lang.Button.System) ?>"><?cs var:html_escape(Lang.Button.System) ?></a>