|
|
|
@ -4,6 +4,7 @@ import re
|
|
|
|
|
import Plugins
|
|
|
|
|
from CryptoBoxExceptions import *
|
|
|
|
|
import cherrypy
|
|
|
|
|
import types
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WebInterfacePlugins:
|
|
|
|
@ -40,9 +41,11 @@ class PluginIconHandler:
|
|
|
|
|
|
|
|
|
|
class WebInterfaceSites:
|
|
|
|
|
'''
|
|
|
|
|
url2func = {'index':'show_status','doc':'show_doc','logs':'show_log'}
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
## this template is used under strange circumstances
|
|
|
|
|
defaultTemplate = "empty"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
import logging
|
|
|
|
@ -60,23 +63,11 @@ class WebInterfaceSites:
|
|
|
|
|
"""
|
|
|
|
|
self.pluginList = Plugins.PluginManager(self.cbox, self.prefs["Locations"]["PluginDir"])
|
|
|
|
|
self.plugins = WebInterfacePlugins(self.log, self.pluginList, self.return_plugin_action)
|
|
|
|
|
## publish the url "/system" as an alias for "/plugins"
|
|
|
|
|
self.plugins.index = self.system
|
|
|
|
|
self.dataset = WebInterfaceDataset.WebInterfaceDataset(self.cbox, self.prefs, self.pluginList.getPlugins())
|
|
|
|
|
## publish plugin icons
|
|
|
|
|
self.icons = IconHandler(self.pluginList)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __check_config(self):
|
|
|
|
|
#TODO: from now on a cryptobox is always configured
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __check_init_running(self):
|
|
|
|
|
#TODO: implement this check (is mkfs still running?)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## this is a function decorator to check authentication
|
|
|
|
|
## it has to be defined before any page definition requiring authentification
|
|
|
|
|
def __requestAuth(self=None):
|
|
|
|
@ -119,77 +110,14 @@ class WebInterfaceSites:
|
|
|
|
|
## put real sites down here and don't forget to expose them at the end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
|
def status(self, weblang=""):
|
|
|
|
|
'''shows the current status of the box
|
|
|
|
|
'''
|
|
|
|
|
self.__resetDataset()
|
|
|
|
|
self.__setWebLang(weblang)
|
|
|
|
|
if not self.__check_config():
|
|
|
|
|
self.dataset["Data.Warning"] = "NotInitialized"
|
|
|
|
|
return self.__render("form_init")
|
|
|
|
|
elif self.__check_init_running():
|
|
|
|
|
self.dataset["Data.Warning"] = "InitNotFinished"
|
|
|
|
|
self.dataset["Data.Redirect.Action"] = "form_config"
|
|
|
|
|
self.dataset["Data.Redirect.Delay"] = "30"
|
|
|
|
|
return self.__render("empty")
|
|
|
|
|
else:
|
|
|
|
|
self.dataset["Data.Redirect.Delay"] = "60"
|
|
|
|
|
return self.__render("show_status")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
|
def doc(self,page="",weblang=""):
|
|
|
|
|
'''prints the offline wikipage
|
|
|
|
|
'''
|
|
|
|
|
import re
|
|
|
|
|
self.__resetDataset()
|
|
|
|
|
self.__setWebLang(weblang)
|
|
|
|
|
|
|
|
|
|
## check for invalid characters
|
|
|
|
|
if page and not re.search(u'\W', page):
|
|
|
|
|
self.dataset["Data.Doc.Page"] = page
|
|
|
|
|
else:
|
|
|
|
|
## display this page as default help page
|
|
|
|
|
self.dataset["Data.Doc.Page"] ="CryptoBoxUser"
|
|
|
|
|
|
|
|
|
|
return self.__render("show_doc")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
|
def system(self, weblang=""):
|
|
|
|
|
self.__resetDataset()
|
|
|
|
|
self.__setWebLang(weblang)
|
|
|
|
|
return self.__render("form_system")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
|
def index(self, weblang=""):
|
|
|
|
|
self.__resetDataset()
|
|
|
|
|
self.__setWebLang(weblang)
|
|
|
|
|
return self.__render("show_status")
|
|
|
|
|
## render "disks" plugin by default
|
|
|
|
|
return self.return_plugin_action(self.pluginList.getPlugin("disks"))()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
|
def show_volume(self, device="", weblang=""):
|
|
|
|
|
self.__resetDataset()
|
|
|
|
|
self.__setWebLang(weblang)
|
|
|
|
|
if self.__setDevice(device):
|
|
|
|
|
return self.__render("show_volume")
|
|
|
|
|
else:
|
|
|
|
|
if self.cbox.getContainerList():
|
|
|
|
|
return self.__render("show_volumes")
|
|
|
|
|
else:
|
|
|
|
|
return self.__render("show_status")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cherrypy.expose
|
|
|
|
|
def show_volumes(self, weblang=""):
|
|
|
|
|
self.__resetDataset()
|
|
|
|
|
self.__setWebLang(weblang)
|
|
|
|
|
return self.__render("show_volumes")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def return_plugin_action(self, plugin):
|
|
|
|
|
def handler(self, **args):
|
|
|
|
|
self.__resetDataset()
|
|
|
|
@ -206,9 +134,9 @@ class WebInterfaceSites:
|
|
|
|
|
plugin.device = args["device"]
|
|
|
|
|
self.dataset.setCurrentDiskState(plugin.device)
|
|
|
|
|
else:
|
|
|
|
|
return self.__render("show_status")
|
|
|
|
|
return self.__render(self.defaultTemplate)
|
|
|
|
|
except KeyError:
|
|
|
|
|
return self.__render("show_status")
|
|
|
|
|
return self.__render(self.defaultTemplate)
|
|
|
|
|
else:
|
|
|
|
|
## the parameter 'device' exists - we have to remove it
|
|
|
|
|
del args["device"]
|
|
|
|
@ -218,10 +146,18 @@ class WebInterfaceSites:
|
|
|
|
|
## additionally: set the default template for plugins
|
|
|
|
|
if "volume" in plugin.pluginCapabilities:
|
|
|
|
|
self.dataset.setCurrentDiskState(plugin.device)
|
|
|
|
|
if not nextTemplate: nextTemplate = "show_volume"
|
|
|
|
|
if not nextTemplate: nextTemplate = { "plugin":"volume_mount", "values":{"device":plugin.device}}
|
|
|
|
|
else:
|
|
|
|
|
self.dataset.setPluginData()
|
|
|
|
|
if not nextTemplate: nextTemplate = "form_system"
|
|
|
|
|
if not nextTemplate: nextTemplate = { "plugin":"disks", "values":{} }
|
|
|
|
|
## if another plugins was choosen for 'nextTemplate', then do it!
|
|
|
|
|
if isinstance(nextTemplate, types.DictType) \
|
|
|
|
|
and "plugin" in nextTemplate.keys() \
|
|
|
|
|
and "values" in nextTemplate.keys() \
|
|
|
|
|
and self.pluginList.getPlugin(nextTemplate["plugin"]):
|
|
|
|
|
valueDict = nextTemplate["values"]
|
|
|
|
|
new_plugin = self.pluginList.getPlugin(nextTemplate["plugin"])
|
|
|
|
|
return self.return_plugin_action(new_plugin)(**valueDict)
|
|
|
|
|
## save the currently active plugin name
|
|
|
|
|
self.dataset["Data.ActivePlugin"] = plugin.getName()
|
|
|
|
|
return self.__render(nextTemplate, plugin)
|
|
|
|
|