2006-09-07 13:21:56 +02:00
|
|
|
import os
|
|
|
|
import CryptoBoxContainer
|
|
|
|
|
2006-09-12 10:55:20 +02:00
|
|
|
## useful constant for some functions
|
2006-09-07 13:21:56 +02:00
|
|
|
CONT_TYPES = CryptoBoxContainer.CryptoBoxContainer.Types
|
|
|
|
|
|
|
|
class WebInterfaceDataset(dict):
|
|
|
|
"""this class contains all data that should be available for the clearsilver
|
|
|
|
templates
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, cbox, prefs):
|
|
|
|
self.prefs = prefs
|
|
|
|
self.cbox = cbox
|
|
|
|
self.__setConfigValues()
|
|
|
|
self.__setCryptoBoxState()
|
2006-09-18 12:16:05 +02:00
|
|
|
|
2006-09-07 13:21:56 +02:00
|
|
|
|
|
|
|
|
2006-09-12 10:55:20 +02:00
|
|
|
def setPluginState(self, plugins):
|
|
|
|
for pl in plugins.allPlugins():
|
2006-09-14 14:33:01 +02:00
|
|
|
self["Data.Status.Plugins." + pl] = plugins.getPlugin(pl).getStatus(self.cbox)
|
2006-09-12 10:55:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
def setCurrentDiskState(self, device):
|
|
|
|
for container in self.cbox.getContainerList():
|
|
|
|
if container.getDevice() == device:
|
|
|
|
isEncrypted = (container.getType() == CONT_TYPES["luks"]) and 1 or 0
|
|
|
|
isPlain = (container.getType() == CONT_TYPES["plain"]) and 1 or 0
|
|
|
|
isMounted = container.isMounted() and 1 or 0
|
|
|
|
self["Data.CurrentDisk.device"] = container.getDevice()
|
|
|
|
self["Data.CurrentDisk.name"] = container.getName()
|
|
|
|
self["Data.CurrentDisk.encryption"] = isEncrypted
|
|
|
|
self["Data.CurrentDisk.plaintext"] = isPlain
|
|
|
|
self["Data.CurrentDisk.active"] = isMounted
|
|
|
|
if isMounted:
|
|
|
|
(size, avail, used) = container.getCapacity()
|
|
|
|
percent = used / size
|
|
|
|
self["Data.CurrentDisk.capacity.used"] = used
|
|
|
|
self["Data.CurrentDisk.capacity.free"] = avail
|
|
|
|
self["Data.CurrentDisk.capacity.size"] = size
|
|
|
|
self["Data.CurrentDisk.capacity.percent"] = percent
|
|
|
|
|
|
|
|
|
2006-09-18 12:16:05 +02:00
|
|
|
def setContainersState(self):
|
2006-09-07 13:21:56 +02:00
|
|
|
avail_counter = 0
|
|
|
|
active_counter = 0
|
|
|
|
for container in self.cbox.getContainerList():
|
|
|
|
isEncrypted = (container.getType() == CONT_TYPES["luks"]) and 1 or 0
|
|
|
|
isPlain = (container.getType() == CONT_TYPES["plain"]) and 1 or 0
|
|
|
|
isMounted = container.isMounted() and 1 or 0
|
|
|
|
self["Data.Disks.%d.device" % avail_counter] = container.getDevice()
|
|
|
|
self["Data.Disks.%d.name" % avail_counter] = container.getName()
|
|
|
|
self["Data.Disks.%d.encryption" % avail_counter] = isEncrypted
|
|
|
|
self["Data.Disks.%d.plaintext" % avail_counter] = isPlain
|
|
|
|
self["Data.Disks.%d.active" % avail_counter] = isMounted
|
|
|
|
if isMounted: active_counter += 1
|
|
|
|
avail_counter += 1
|
|
|
|
self["Data.activeDisksCount"] = active_counter
|
2006-09-18 12:16:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def __setConfigValues(self):
|
|
|
|
self["Settings.TemplateDir"] = os.path.abspath(self.prefs["Locations"]["TemplateDir"])
|
|
|
|
self["Settings.LanguageDir"] = os.path.abspath(self.prefs["Locations"]["LangDir"])
|
|
|
|
self["Settings.DocDir"] = os.path.abspath(self.prefs["Locations"]["DocDir"])
|
|
|
|
self["Settings.Stylesheet"] = self.prefs["WebSettings"]["Stylesheet"]
|
|
|
|
self["Settings.Language"] = self.prefs["WebSettings"]["Language"]
|
|
|
|
self["Settings.DocLang"] = self.prefs["WebSettings"]["DocLanguage"]
|
|
|
|
self["Settings.PluginDir"] = self.prefs["Locations"]["PluginDir"]
|
|
|
|
|
|
|
|
|
|
|
|
def __setCryptoBoxState(self):
|
|
|
|
self["Data.Version"] = self.cbox.VERSION
|
2006-09-07 13:21:56 +02:00
|
|
|
for lang in self.cbox.getAvailableLanguages():
|
|
|
|
self["Data.Languages." + lang] = self.__getLanguageName(lang)
|
|
|
|
## TODO: open issues: Data.Config.AdminPasswordIsSet
|
|
|
|
|
|
|
|
|
|
|
|
def __getLanguageName(self, lang):
|
|
|
|
import neo_cgi, neo_util, neo_cs
|
|
|
|
hdf_path = os.path.join(self.prefs["Locations"]["LangDir"], lang + ".hdf")
|
|
|
|
hdf = neo_util.HDF()
|
|
|
|
hdf.readFile(hdf_path)
|
|
|
|
return hdf.getValue("Lang.Name",lang)
|
|
|
|
|