Lars' poland path #2
This commit is contained in:
parent
175cb831ad
commit
f450e116a7
8 changed files with 173 additions and 220 deletions
|
@ -36,20 +36,21 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
|
|||
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'),
|
||||
niceparams = { 'weblang': tuple(self.__getAvailableLanguages()),
|
||||
'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("ignoring \"%s\"" % evilkey)
|
||||
self.log.warn('ignoring "%s"' % evilkey)
|
||||
# RFC: why "return False"? - just ignoring is sufficient
|
||||
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)))
|
||||
self.log.warn('"%s" not in weblang %s' % (evilkey, niceparams.get(evilkey)))
|
||||
# RFC: why "weblang"?
|
||||
#TODO: set it to: niceparams.get(evilkey)[0]))
|
||||
return
|
||||
|
||||
|
@ -63,6 +64,44 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
|
|||
#TODO
|
||||
pass
|
||||
|
||||
|
||||
def __getAvailableLanguages(self):
|
||||
import re, os
|
||||
regpat = re.compile(r"^\w+\.hdf$")
|
||||
try:
|
||||
lang_dir = self.cbxPrefs["Locations"]["LangDir"]
|
||||
except KeyError:
|
||||
self.log.error("Could not find a configuration setting: [Locations]->LangDir - please check the config file")
|
||||
return []
|
||||
if not os.path.exists(lang_dir):
|
||||
self.log.error("The configured language directory (%s) does not exist" % (lang_dir, ))
|
||||
return []
|
||||
try:
|
||||
return [ e[:-4] for e in os.listdir(lang_dir) if regpat.search(e)]
|
||||
except OSError:
|
||||
self.log.error("Could not access the language directory (%s)" % (lang_dir,))
|
||||
return []
|
||||
|
||||
|
||||
def __getAvailableDocLanguages(self):
|
||||
import re, os
|
||||
regpat = re.compile(r"^\w+$")
|
||||
try:
|
||||
doc_dir = self.cbxPrefs["Locations"]["DocDir"]
|
||||
except KeyError:
|
||||
self.log.error("Could not find a configuration setting: [Locations]->DocDir - please check the config file")
|
||||
return []
|
||||
if not os.path.exists(doc_dir):
|
||||
self.log.error("The configured documentation directory (%s) does not exist" % (doc_dir, ))
|
||||
return []
|
||||
try:
|
||||
return [ e for e in os.listdir(doc_dir)
|
||||
if regpat.search(e) and os.path.isdir(os.path.join(doc_dir, e))]
|
||||
except OSError:
|
||||
self.log.error("Could not access the documentations directory (%s)" % (doc_dir,))
|
||||
return []
|
||||
|
||||
|
||||
######################################################################
|
||||
## put real sites down here and don't forget to expose them at the end
|
||||
|
||||
|
@ -78,10 +117,7 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
|
|||
'''
|
||||
self.__sanitize_input({"loglevel":loglevel})
|
||||
self.__prepare("show_log")
|
||||
import filehandling
|
||||
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)
|
||||
|
||||
def status(self, weblang=""):
|
||||
|
@ -117,11 +153,13 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
|
|||
self.__prepare("show_doc")
|
||||
if page:
|
||||
self.settings["Data.Doc.Page"] = page
|
||||
if page == "":
|
||||
else:
|
||||
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
|
||||
if weblang:
|
||||
if weblang in self.__getAvailableDocLanguages():
|
||||
self.settings["Settings.DocLang"] = weblang
|
||||
else:
|
||||
self.log.warn("invalid documentation language selected: %s", % (weblang, ))
|
||||
return website.render(self)
|
||||
|
||||
|
||||
|
@ -163,8 +201,8 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
|
|||
#-------------------------------------------------------#
|
||||
################ umount_do #######################
|
||||
elif action == "unmount_do":
|
||||
if device == "":
|
||||
#TODO: debug message: "invalid device: "+ device
|
||||
if not device:
|
||||
self.log.debug("invalid device chosen: %s" device
|
||||
settings["Data.Warning"] = "InvalidDevice"
|
||||
settings["Data.Action"] = "empty"
|
||||
elif not True: #TODO: replace True with check_config()
|
||||
|
@ -187,10 +225,10 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
|
|||
settings["Data.Action"] = "show_volume"
|
||||
################ mount_do ########################
|
||||
elif action == "mount_do":
|
||||
if device != "":
|
||||
if device:
|
||||
pass #TODO: is_encrypted = check_device_encryption(device)
|
||||
if device == "":
|
||||
#TODO: debug_msg(DEBUG_INFO, "invalid device: " + device)
|
||||
else:
|
||||
self.log.debug("invalid device chosen: %s" device
|
||||
settings["Data.Warning"] = "InvalidDevice"
|
||||
settings["Data.Action"] = "empty"
|
||||
elif not True: #TODO: replace True with check_config()
|
||||
|
@ -208,3 +246,4 @@ class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettin
|
|||
system.exposed = True
|
||||
status.exposed = True
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue