moved plugin-specific css definitions to the appropriate plugin
cleaned up the error handling of WebInterfaceSites
This commit is contained in:
parent
c95ba55f25
commit
3b0e787d2f
5 changed files with 88 additions and 182 deletions
|
@ -11,6 +11,7 @@ import subprocess
|
|||
import os
|
||||
import re
|
||||
import logging
|
||||
from CryptoBoxExceptions import *
|
||||
|
||||
"""exceptions:
|
||||
VolumeIsActive
|
||||
|
@ -55,15 +56,15 @@ class CryptoBoxContainer:
|
|||
def setName(self, new_name):
|
||||
if new_name == self.name: return
|
||||
if self.isMounted():
|
||||
raise "VolumeIsActive", "the container must be inactive during renaming"
|
||||
raise CBVolumeIsActive("the container must be inactive during renaming")
|
||||
if not re.search(r'^[a-zA-Z0-9_\.\- ]+$', new_name):
|
||||
raise "InvalidName", "the supplied new name contains illegal characters"
|
||||
raise CBInvalidName("the supplied new name contains illegal characters")
|
||||
"check for active partitions with the same name"
|
||||
prev_name_owner = self.cbox.getContainerList(filterName=new_name)
|
||||
if prev_name_owner:
|
||||
for a in prev_name_owner:
|
||||
if a.isMounted():
|
||||
raise "NameActivelyUsed", "the supplied new name is already in use for an active partition"
|
||||
raise CBNameActivelyUsed("the supplied new name is already in use for an active partition")
|
||||
self.cbox.setNameForUUID(self.uuid, new_name)
|
||||
self.name = new_name
|
||||
|
||||
|
@ -116,21 +117,20 @@ class CryptoBoxContainer:
|
|||
self.__createPlain()
|
||||
self.resetObject()
|
||||
return
|
||||
raise "InvalidType", "invalid container type (%d) supplied" % (type, )
|
||||
raise CBInvalidType("invalid container type (%d) supplied" % (type, ))
|
||||
|
||||
|
||||
def changePassword(self, oldpw, newpw):
|
||||
if self.type != self.Types["luks"]:
|
||||
raise "InvalidType", \
|
||||
"changing of password is possible only for luks containers"
|
||||
raise CBInvalidType("changing of password is possible only for luks containers")
|
||||
if not oldpw:
|
||||
raise "InvalidPassword", "no old password supplied for password change"
|
||||
raise CBInvalidPassword("no old password supplied for password change")
|
||||
if not newpw:
|
||||
raise "InvalidPassword", "no new password supplied for password change"
|
||||
raise CBInvalidPassword("no new password supplied for password change")
|
||||
"return if new and old passwords are the same"
|
||||
if oldpw == newpw: return
|
||||
if self.isMounted():
|
||||
raise "VolumeIsActive", "this container is currently active"
|
||||
raise CBVolumeIsActive("this container is currently active")
|
||||
devnull = None
|
||||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
|
@ -156,13 +156,13 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not add a new luks key: %s - %s" % (output.strip(), errout.strip(), )
|
||||
self.log.error(errorMsg)
|
||||
raise "ChangePasswordError", errorMsg
|
||||
raise CBChangePasswordError(errorMsg)
|
||||
## retrieve the key slot we used for unlocking
|
||||
keys_found = re.search(r'key slot (\d{1,3}) unlocked', output).groups()
|
||||
if keys_found:
|
||||
keyslot = int(keys_found[0])
|
||||
else:
|
||||
raise "ChangePasswordError", "could not get the old key slot"
|
||||
raise CBChangePasswordError("could not get the old key slot")
|
||||
"remove the old key"
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -179,7 +179,7 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not remove the old luks key: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.error(errorMsg)
|
||||
raise "ChangePasswordError", errorMsg
|
||||
raise CBChangePasswordError(errorMsg)
|
||||
|
||||
|
||||
|
||||
|
@ -300,8 +300,8 @@ class CryptoBoxContainer:
|
|||
def __mountLuks(self, password):
|
||||
"mount a luks partition"
|
||||
if not password:
|
||||
raise "InvalidPassword", "no password supplied for luksOpen"
|
||||
if self.isMounted(): raise "VolumeIsActive", "this container is already active"
|
||||
raise CBInvalidPassword("no password supplied for luksOpen")
|
||||
if self.isMounted(): raise CBVolumeIsActive("this container is already active")
|
||||
self.__umountLuks()
|
||||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
|
@ -313,7 +313,7 @@ class CryptoBoxContainer:
|
|||
if not os.path.exists(self.__getMountPoint()):
|
||||
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
||||
self.log.error(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
stdin = subprocess.PIPE,
|
||||
|
@ -332,7 +332,7 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not open the luks mapping: %s" % (errout.strip(), )
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
stdin = None,
|
||||
|
@ -348,7 +348,7 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not mount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
devnull.close()
|
||||
|
||||
|
||||
|
@ -374,7 +374,7 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not umount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
if os.path.exists(os.path.join(self.__dmDir, self.name)):
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -392,13 +392,13 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not remove the luks mapping: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
devnull.close()
|
||||
|
||||
|
||||
def __mountPlain(self):
|
||||
"mount a plaintext partition"
|
||||
if self.isMounted(): raise "VolumeIsActive", "this container is already active"
|
||||
if self.isMounted(): raise CBVolumeIsActive("this container is already active")
|
||||
devnull = None
|
||||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
|
@ -410,7 +410,7 @@ class CryptoBoxContainer:
|
|||
if not os.path.exists(self.__getMountPoint()):
|
||||
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
||||
self.log.error(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
stdin = None,
|
||||
|
@ -426,7 +426,7 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not mount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
devnull.close()
|
||||
|
||||
|
||||
|
@ -452,15 +452,14 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not umount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
raise CBMountError(errorMsg)
|
||||
devnull.close()
|
||||
|
||||
|
||||
def __createPlain(self):
|
||||
"make a plaintext partition"
|
||||
if self.isMounted():
|
||||
raise "VolumeIsActive", \
|
||||
"deactivate the partition before filesystem initialization"
|
||||
raise CBVolumeIsActive("deactivate the partition before filesystem initialization")
|
||||
devnull = None
|
||||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
|
@ -478,17 +477,16 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not create the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.error(errorMsg)
|
||||
raise "CreateError", errorMsg
|
||||
raise CBCreateError(errorMsg)
|
||||
devnull.close()
|
||||
|
||||
|
||||
def __createLuks(self, password):
|
||||
"make a luks partition"
|
||||
if not password:
|
||||
raise "InvalidPassword", "no password supplied for new luks mapping"
|
||||
raise CBInvalidPassword("no password supplied for new luks mapping")
|
||||
if self.isMounted():
|
||||
raise "VolumeIsActive", \
|
||||
"deactivate the partition before filesystem initialization"
|
||||
raise CBVolumeIsActive("deactivate the partition before filesystem initialization")
|
||||
devnull = None
|
||||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
|
@ -516,7 +514,7 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not create the luks header: %s" % (errout.strip(), )
|
||||
self.log.error(errorMsg)
|
||||
raise "CreateError", errorMsg
|
||||
raise CBCreateError(errorMsg)
|
||||
"open the luks container for mkfs"
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -536,7 +534,7 @@ class CryptoBoxContainer:
|
|||
if proc.returncode != 0:
|
||||
errorMsg = "Could not open the new luks mapping: %s" % (errout.strip(), )
|
||||
self.log.error(errorMsg)
|
||||
raise "CreateError", errorMsg
|
||||
raise CBCreateError(errorMsg)
|
||||
"make the filesystem"
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -553,7 +551,7 @@ class CryptoBoxContainer:
|
|||
errorMsg = "Could not create the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.log.error(errorMsg)
|
||||
"remove the luks mapping"
|
||||
raise "CreateError", errorMsg
|
||||
raise CBCreateError(errorMsg)
|
||||
devnull.close()
|
||||
|
||||
|
||||
|
|
|
@ -8,15 +8,6 @@ class CryptoBoxError(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class CBPluginError(CryptoBoxError):
|
||||
"""should be raised for plugin specific problems"""
|
||||
|
||||
|
||||
class CBPluginActionError(CBPluginError):
|
||||
"""should be raised when a plugin action failed"""
|
||||
pass
|
||||
|
||||
|
||||
class CBConfigError(CryptoBoxError):
|
||||
"""any kind of error related to the configuration of a cryptobox"""
|
||||
pass
|
||||
|
@ -78,3 +69,36 @@ class CBEnvironmentError(CryptoBoxError):
|
|||
return "misconfiguration detected: %s" % self.desc
|
||||
|
||||
|
||||
class CBContainerError(CryptoBoxError):
|
||||
"""any error raised while manipulating a cryptobox container"""
|
||||
|
||||
def __init__(self, desc):
|
||||
self.desc = desc
|
||||
|
||||
def __str__(self):
|
||||
return self.desc
|
||||
|
||||
class CBCreateError(CBContainerError):
|
||||
pass
|
||||
|
||||
class CBVolumeIsActive(CBContainerError):
|
||||
pass
|
||||
|
||||
class CBInvalidName(CBContainerError):
|
||||
pass
|
||||
|
||||
class CBNameActivelyUsed(CBContainerError):
|
||||
pass
|
||||
|
||||
class CBInvalidType(CBContainerError):
|
||||
pass
|
||||
|
||||
class CBInvalidPassword(CBContainerError):
|
||||
pass
|
||||
|
||||
class CBChangePasswordError(CBContainerError):
|
||||
pass
|
||||
|
||||
class CBMountError(CBContainerError):
|
||||
pass
|
||||
|
||||
|
|
|
@ -60,14 +60,6 @@ class WebInterfaceSites:
|
|||
######################################################################
|
||||
## put real sites down here and don't forget to expose them at the end
|
||||
|
||||
def logs(self, weblang=""):
|
||||
'''displays a HTML version of the logfile
|
||||
'''
|
||||
self.__resetDataset()
|
||||
self.__setWebLang(weblang)
|
||||
self.dataset["Data.Log"] = "<br/>".join(self.cbox.getLogData(lines=30, maxSize=2000))
|
||||
return self.__render("show_log")
|
||||
|
||||
|
||||
def status(self, weblang=""):
|
||||
'''shows the current status of the box
|
||||
|
@ -143,8 +135,7 @@ class WebInterfaceSites:
|
|||
container = self.cbox.getContainer(device)
|
||||
try:
|
||||
container.setName(volume_name)
|
||||
# TODO: specify the possible exceptions
|
||||
except Exception, errMsg:
|
||||
except CBContainerError, errMsg:
|
||||
self.log.warn("failed to rename the volume '%s' to '%s: %s'" % (device, volume_name, errMsg))
|
||||
self.dataset["Data.Warning"] = "SetVolumeNameFailed"
|
||||
else:
|
||||
|
@ -183,8 +174,7 @@ class WebInterfaceSites:
|
|||
container.mount()
|
||||
else:
|
||||
## mounting is not possible
|
||||
# TODO: wrong warning message - replace it
|
||||
self.dataset["Data.Warning"] = "MountFailed"
|
||||
self.dataset["Data.Warning"] = "InvalidType"
|
||||
self.log.warn("this type of container (%s) cannot be mounted - sorry!" % device)
|
||||
except (Exception, "MountError"):
|
||||
self.dataset["Data.Warning"] = "MountFailed"
|
||||
|
@ -222,7 +212,7 @@ class WebInterfaceSites:
|
|||
return self.__render("show_status")
|
||||
|
||||
|
||||
def init_do(self, device, confirm, crypto_password=None, crypto_password2=None, encryption=None, weblang=""):
|
||||
def init_do(self, device, confirm="", crypto_password=None, crypto_password2=None, encryption=None, weblang=""):
|
||||
self.__resetDataset()
|
||||
self.__setWebLang(weblang)
|
||||
if self.__setDevice(device):
|
||||
|
@ -237,8 +227,7 @@ class WebInterfaceSites:
|
|||
self.log.warn("initialization is not possible as long as the device (%s) is mounted" % device)
|
||||
return self.__render("form_init")
|
||||
else:
|
||||
# TODO: we have to compare 'confirm' with the value in the language file - IMPORTANT!
|
||||
if not confirm:
|
||||
if confirm != self.__getLanguageValue("Text.ConfirmInit"):
|
||||
self.dataset["Data.Warning"] = "InitNotConfirmed"
|
||||
self.log.warn("the confirmation sentence for initialization of the device '%s' was wrong" % device)
|
||||
return self.__render("form_init")
|
||||
|
@ -255,10 +244,8 @@ class WebInterfaceSites:
|
|||
container.create(container.Types["luks"], crypto_password)
|
||||
else:
|
||||
container.create(container.Types["plain"])
|
||||
# TODO: specify the exception
|
||||
except Exception, errMsg:
|
||||
# TODO: wrong error/warning message - change it
|
||||
self.dataset["Data.Error"] = "InitFailed"
|
||||
except CBContainerError, errMsg:
|
||||
self.dataset["Data.Warning"] = "CreateFailed"
|
||||
self.log.warn("initialization of device '%s' failed" % device)
|
||||
self.log.warn("reason: %s" % errMsg)
|
||||
return self.__render("form_init")
|
||||
|
@ -278,11 +265,7 @@ class WebInterfaceSites:
|
|||
import cherrypy
|
||||
self.__resetDataset()
|
||||
self.__setWebLang(weblang)
|
||||
for x in pref_langs:
|
||||
yield "Lang: %s<br/>" % x
|
||||
for (key,value) in headers.items():
|
||||
yield "%s: %s<br/>" % (key,value)
|
||||
#return "test passed"
|
||||
return "test passed"
|
||||
|
||||
|
||||
def umount_do(self, device, weblang=""):
|
||||
|
@ -302,9 +285,8 @@ class WebInterfaceSites:
|
|||
## plain container
|
||||
container.umount()
|
||||
else:
|
||||
## mounting is not possible
|
||||
# TODO: wrong warning message - replace it
|
||||
self.dataset["Data.Warning"] = "UmountFailed"
|
||||
## umounting is not possible
|
||||
self.dataset["Data.Warning"] = "InvalidType"
|
||||
self.log.warn("this type of container (%s) cannot be umounted - sorry!" % device)
|
||||
except (Exception, "UmountError"):
|
||||
self.dataset["Data.Warning"] = "UmountFailed"
|
||||
|
@ -336,61 +318,12 @@ class WebInterfaceSites:
|
|||
return handler
|
||||
|
||||
|
||||
'''
|
||||
## DONE: these functions are pythonized
|
||||
#################### show_log #######################
|
||||
##################### doc ############################
|
||||
##################### poweroff ######################
|
||||
##################### reboot ########################
|
||||
|
||||
## but there are even more TODO
|
||||
#-------------------------------------------------------#
|
||||
# here you may define all cases that require a harddisk #
|
||||
#-------------------------------------------------------#
|
||||
################ umount_do #######################
|
||||
elif action == "unmount_do":
|
||||
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()
|
||||
settings["Data.Warning"] = "NotInitialized"
|
||||
settings["Data.Action"] = "form_init"
|
||||
elif True: #TODO: replace True with check_init_running()
|
||||
settings["Data.Warning"] = "InitNotFinished"
|
||||
settings["Data.Action"] = "empty"
|
||||
settings["Data.Redirect.Action"] = "form_config"
|
||||
settings["Data.Redirect.Delay"] = "30"
|
||||
elif not True: #TODO: replace True with check_mounted(device)
|
||||
settings["Data.Warning"] = "NotMounted"
|
||||
settings["Data.Action"] = "show_volume"
|
||||
else: #unmount
|
||||
#TODO: replace this line with umount_vol(device)
|
||||
if True: #TODO: replace True with check_mounted(device)
|
||||
settings["Data.Warning"] = "UmountFailed"
|
||||
settings["Data.Action"] = "show_volume"
|
||||
else:
|
||||
settings["Data.Action"] = "show_volume"
|
||||
################ mount_do ########################
|
||||
elif action == "mount_do":
|
||||
if device:
|
||||
pass #TODO: is_encrypted = check_device_encryption(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()
|
||||
settings["Data.Warning"] = "NotInitialized"
|
||||
settings["Data.Action"] = "form_init"
|
||||
#at cryptobox.pl line 568
|
||||
'''
|
||||
|
||||
|
||||
##################### input checker ##########################
|
||||
def __setWebLang(self, value):
|
||||
## TODO: add some code to evaluate the language setting of the browser
|
||||
guess = value
|
||||
availLangs = self.cbox.getAvailableLanguages()
|
||||
## no language specified: check browser language
|
||||
if not guess:
|
||||
guess = self.__getPreferredBrowserLanguage(availLangs)
|
||||
if not guess or \
|
||||
|
@ -398,7 +331,6 @@ class WebInterfaceSites:
|
|||
re.search(u'\W', guess):
|
||||
self.cbox.log.info("invalid language choosen: %s" % guess)
|
||||
guess = self.prefs["WebSettings"]["Language"]
|
||||
## TODO: extract the current "browser-language" - this should be the first guess
|
||||
## maybe the language is still not valid
|
||||
if not guess in availLangs:
|
||||
self.log.warn("the configured language is invalid: %s" % guess)
|
||||
|
@ -459,6 +391,11 @@ class WebInterfaceSites:
|
|||
return False
|
||||
|
||||
|
||||
def __getLanguageValue(self, value):
|
||||
hdf = self.__getLanguageData(self.dataset["Settings.Language"])
|
||||
return hdf.getValue(value, "")
|
||||
|
||||
|
||||
def __getLanguageData(self, web_lang="en"):
|
||||
import neo_cgi, neo_util, os
|
||||
default_lang = "en"
|
||||
|
@ -572,7 +509,6 @@ class WebInterfaceSites:
|
|||
## to make the sites visible through the webserver they must be exposed here
|
||||
index.exposed = True
|
||||
doc.exposed = True
|
||||
logs.exposed = True
|
||||
system.exposed = True
|
||||
status.exposed = True
|
||||
show_volume.exposed = True
|
||||
|
|
|
@ -161,6 +161,16 @@ WarningMessage {
|
|||
Text = Could not change the name of the container. Take a look at the log files for details.
|
||||
}
|
||||
|
||||
CreateFailed {
|
||||
Title = Initialization failed
|
||||
Text = Initialization of the volume failed for some unknown reasons - sorry!
|
||||
}
|
||||
|
||||
InvalidType {
|
||||
Title = Unknown type
|
||||
Text = The type of this volume is unknown.
|
||||
}
|
||||
|
||||
VolumeMayNotBeMounted {
|
||||
Title = The container is mounted
|
||||
Text = This action is not available while the container is active. Please turn it off first.
|
||||
|
|
|
@ -375,65 +375,3 @@ button:hover {
|
|||
padding-top: 10px;
|
||||
}
|
||||
|
||||
/* ------------=-=-=- special things -=-=-=------------- */
|
||||
|
||||
#partition_info p, #log p.console {
|
||||
margin-left: 10%;
|
||||
margin-right: 10%;
|
||||
font-family: monospace;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* ---------=-=-=-=- onscreen help -=-=-=-=--------- */
|
||||
/* not active anymore */
|
||||
|
||||
#words a.popup {
|
||||
line-height: inherit;
|
||||
color: inherit;
|
||||
background-color: inherit;
|
||||
text-decoration: inherit;
|
||||
font-weight: inherit;
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
#words a.popup:hover {
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
#words a.popup span {
|
||||
display: none;
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 9%;
|
||||
width: 80%;
|
||||
background: #f0f0f0;
|
||||
padding: 10px;
|
||||
border-color: #e0e0e0;
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#words a.popup:hover span {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
#words a.popup span p {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#words a.popup span h3 {
|
||||
color: #909090;
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
|
||||
// TODO: move this to the plugin "partition" (inline include with cs)
|
||||
#words div.partition {
|
||||
text-align: center;
|
||||
align: center;
|
||||
}
|
||||
|
||||
table.partition tr td{
|
||||
text-align: center
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue