From 3b97f675bf4b1b49aa6f68ffa811957819373a2b Mon Sep 17 00:00:00 2001
From: age
Date: Thu, 24 Aug 2006 14:41:11 +0000
Subject: [PATCH] now checks url params adapted templates renderer checks for
sources
---
pythonrewrite/bin2/CryptoBox.py | 4 +-
.../bin2/CryptoBoxWebserverRender.py | 30 ++++---
.../bin2/CryptoBoxWebserverSettings.py | 9 +-
pythonrewrite/bin2/CryptoBoxWebserverSites.py | 82 +++++++++++++------
pythonrewrite/bin2/cryptobox.conf | 2 +-
pythonrewrite/templates/form_system.cs | 6 +-
pythonrewrite/templates/macros.cs | 2 +-
pythonrewrite/templates/nav.cs | 9 +-
8 files changed, 94 insertions(+), 50 deletions(-)
diff --git a/pythonrewrite/bin2/CryptoBox.py b/pythonrewrite/bin2/CryptoBox.py
index eeec39e..71837ba 100755
--- a/pythonrewrite/bin2/CryptoBox.py
+++ b/pythonrewrite/bin2/CryptoBox.py
@@ -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
diff --git a/pythonrewrite/bin2/CryptoBoxWebserverRender.py b/pythonrewrite/bin2/CryptoBoxWebserverRender.py
index 411d132..b7297e8 100644
--- a/pythonrewrite/bin2/CryptoBoxWebserverRender.py
+++ b/pythonrewrite/bin2/CryptoBoxWebserverRender.py
@@ -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)
diff --git a/pythonrewrite/bin2/CryptoBoxWebserverSettings.py b/pythonrewrite/bin2/CryptoBoxWebserverSettings.py
index 13c6b18..ad74160 100644
--- a/pythonrewrite/bin2/CryptoBoxWebserverSettings.py
+++ b/pythonrewrite/bin2/CryptoBoxWebserverSettings.py
@@ -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)
diff --git a/pythonrewrite/bin2/CryptoBoxWebserverSites.py b/pythonrewrite/bin2/CryptoBoxWebserverSites.py
index c22e861..8ad8c7c 100755
--- a/pythonrewrite/bin2/CryptoBoxWebserverSites.py
+++ b/pythonrewrite/bin2/CryptoBoxWebserverSites.py
@@ -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"
@@ -59,18 +90,23 @@ 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=""):
- #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=""):
diff --git a/pythonrewrite/bin2/cryptobox.conf b/pythonrewrite/bin2/cryptobox.conf
index 577c522..2fdde1e 100644
--- a/pythonrewrite/bin2/cryptobox.conf
+++ b/pythonrewrite/bin2/cryptobox.conf
@@ -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
diff --git a/pythonrewrite/templates/form_system.cs b/pythonrewrite/templates/form_system.cs
index 9e0f001..9582285 100644
--- a/pythonrewrite/templates/form_system.cs
+++ b/pythonrewrite/templates/form_system.cs
@@ -5,11 +5,11 @@
diff --git a/pythonrewrite/templates/macros.cs b/pythonrewrite/templates/macros.cs
index 7a180c7..83863d7 100644
--- a/pythonrewrite/templates/macros.cs
+++ b/pythonrewrite/templates/macros.cs
@@ -60,7 +60,7 @@ def:link(path, attr1, value1, attr2, value2)
?>// 0
?>
-
-
-
-
-
-
+
+
+