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")
## from now on everything can be logged via self.log...
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):
try:
import configobj ## needed for reading and writing of the config file
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
if config_file is None:
# no config file was specified - we will look for it in the ususal locations

View file

@ -1,26 +1,36 @@
import os
try:
import neo_cgi, neo_util, neo_cs
except:
print "could not import clearsilver modules! Try apt-get install python-clearsilver."
class CryptoBoxWebserverRender:
'''renders the site with clearsilver template and languagefile
'''
def render(self, website):
'''
render a clearsilver template and return the result.
'''renders from clearsilver templates and returns the resulting html
gets:
- path to clearsilver template
- dictionary with settings (optional)
- path to hdf dataset (optional)
Gets a dictionary with all settings, nessessary for rendering.
In fact the dictionary is a copy of the CryptoBoxWerbserverSite
object, that calls this render method. This might be bloat but
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"]+" "+str(website.settings))
website.log.info("rendering site: "+website.settings["Data.Action"])
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"
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()
if hdf_path != "":
hdf.readFile(hdf_path)
hdf.readFile(hdf_path)
for key in website.settings.keys():
hdf.setValue(key,str(website.settings[key]))
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'''
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={}
## put all found Settings values in the dictionary
for key in self.cbxPrefs["Settings"].keys():
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)

View file

@ -8,44 +8,75 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
url2func = {'index':'show_status','doc':'show_doc','logs':'show_log'}
'''
def __prepare(self, csname="show_status"):
'''this method handles stuff that all sites need as preparation
def __prepare(self, action="show_status"):
'''handles stuff that all sites need as preparation
self.settings is filled be the following methodcall
thus every rendered site will get actual values from the configfile
after that the site-method may set individual values too
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.
'''
self.setSettings(self)
self.settings
## default site to render is 'show_status'
self.settings["Data.Action"] = csname
#self.settings
self.settings["Data.Action"] = action
#TODO: check ssl status
def __sanitize_input(self,data):
#TODO: don't let evil cracker fuck up your code
return data
def __sanitize_input(self, evilparams):
'''mistrusts every given parameter and wipes crap out
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):
#TODO
pass
def __check_init_running(self):
#TODO
pass
######################################################################
## put real sites down here and don't forget to expose the mat the end
def logs(self):
'''be careful to name this method just "log" seems to be a
reserved word'''
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.'''
self.__sanitize_input({"loglevel":loglevel})
self.__prepare("show_log")
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
# sed s/$/<\/br>/
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")
if not self.__check_config():
self.settings["Data.Warning"] = "NotInitialized"
@ -60,17 +91,22 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
self.settings["Data.Redirect.Delay"] = "60"
return website.render(self)
def config(self,weblang=""):
pass
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")
if not page == "":
if page:
self.settings["Data.Doc.Page"] = page
#self.log.info(page)
#self.log.info(self.settings)
else:
if page == "":
self.settings["Data.Doc.Page"] ="CryptoBoxUser"
#self.log.info(page)
#self.log.info(self.settings)
if not weblang == "":
self.settings["Settings.DocLang"] = weblang
return website.render(self)
def system(self,type=""):

View file

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

View file

@ -5,11 +5,11 @@
<p><ul>
<?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 # 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>
<?cs # config ?>
@ -21,7 +21,7 @@
var:html_escape(Lang.Button.DoInit) ?>"><?cs var:html_escape(Lang.Button.DoInit) ?></a></li>
<?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>

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:attr2 != "" ?><?cs set:Temp[attr2] = value2 ?><?cs /if
?><?cs var:ScriptName
?>/<?cs:var:path
?>/<?cs var:path
?><?cs set:first_each = 1
?><?cs if:subcount(Temp) > 0
?><?cs each:attrs = Temp

View file

@ -19,10 +19,7 @@
<?cs /if ?>
<?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="/status" title="<?cs var:html_escape(Lang.Button.Status) ?>"><?cs var:html_escape(Lang.Button.Status) ?></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>
<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="<?cs call:link('system','','','','') ?>" title="<?cs var:html_escape(Lang.Button.System) ?>"><?cs var:html_escape(Lang.Button.System) ?></a>