moved plugin specific settings storing from volume_db to plugin_conf

store configured IP and restore during reboot
This commit is contained in:
lars 2007-01-19 01:51:35 +00:00
parent 297cdca0af
commit 9c1f5c3fc2
4 changed files with 60 additions and 34 deletions

View file

@ -68,6 +68,11 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf["Data.Success"] = "Plugins.network.IPChanged"
self.hdf["Data.Redirect.URL"] = self.__get_redirect_destination(new_ip)
self.hdf["Data.Redirect.Delay"] = REDIRECT_DELAY
self.prefs["_address"] = new_ip
try:
self.cbox.prefs.plugin_conf.write()
except IOError:
self.cbox.log.warn("Could not write plugin configuration")
return "form_network"
else:
self.cbox.log.warn("failed to change IP address to: %s" % new_ip)
@ -87,6 +92,16 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
return "%d.%d.%d.%d" % self.__get_current_ip()
def handle_event(self, event, event_info=None):
"""Override bootup behaviour
Apply the configured network settings
"""
if event == "bootup":
if "_address" in self.prefs:
self.__set_ip(self.prefs["_address"])
def __get_redirect_destination(self, ip):
"""Put the new URL together.
"""
@ -126,7 +141,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
root_action_plug.IFACE])
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
return (0,0,0,0)
return (0, 0, 0, 0)
## this regex matches the four numbers of the IP
match = re.search(r'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', stdout)
if match:

View file

@ -8,7 +8,7 @@ The following directory structure is required:
Python code interface:
- create a class with the same name as the plugin - it must inherit CryptoBoxPlugin
- function "do_action":
- method "do_action":
- this function will get called whenever this plugins is involved in a request
- all arguments should be optional (e.g. for displaying a form without previous input values)
- the argument "store" should be used to process a form submission (just a recommendation)
@ -28,14 +28,17 @@ Python code interface:
* values: a dictionary of variables that should be defined for this plugin
- an empty (e.g. None) return value can be used to go to the default page ("disks"
or "volume_mount" (for volume plugins))
- function "get_status":
- access the plugin's state as self.prefs
- store user supplied values in the dictionary self.prefs with indices starting with "_" (e.g.: self.prefs["_automount_uuids"])
- method "get_status":
- returns a string, that describes a state connected to this plugin (e.g. the current date and
time (for the "date" plugin))
- function "handle_event(event, event_info)":
- method "handle_event(event, event_info)":
- may be overridden to specify event handling (e.g. "bootup", "shutdown")
- see src/cryptobox/plugins/base.py for details
- the class variable "plugin_capabilities" must be an array of strings (supported: "system" and
"volume")
- method "is_useful(self, device)": defaults to "True" - overwrite it, if there could be circumstances, which could make the plugin useless - e.g. "automount" is not useful for encrypted containers
- the class variable "plugin_visibility" may contain one or more of the following items:
menu/preferences/volume. This should fit to the 'plugin_capabilities' variable.
An empty list is interpreted as an invisible plugin.

View file

@ -41,21 +41,13 @@ class volume_automount(cryptobox.plugins.base.CryptoBoxPlugin):
if action is None:
pass
elif action == "enable":
container.attributes["automount"] = self.true_string
self.__set_auto_mount(container, True)
self.hdf["Data.Success"] = "Plugins.volume_automount.AutoMountEnabled"
self.cbox.log.info("volume_automount: enabled for device '%s'" % self.device)
try:
self.cbox.prefs.volumes_db.write()
except IOError:
self.cbox.log.warn("Failed to store volume database")
elif action == "disable":
container.attributes["automount"] = self.false_string
self.__set_auto_mount(container, False)
self.hdf["Data.Success"] = "Plugins.volume_automount.AutoMountDisabled"
self.cbox.log.info("volume_automount: disabled for device '%s'" % self.device)
try:
self.cbox.prefs.volumes_db.write()
except IOError:
self.cbox.log.warn("Failed to store volume database")
else:
self.cbox.log.info("volume_automount: invalid action (%s)" % str(action))
self.__prepare_hdf()
@ -77,11 +69,10 @@ class volume_automount(cryptobox.plugins.base.CryptoBoxPlugin):
def is_useful(self, device):
"""Automount does not work for encrypted volumes.
"""
from cryptobox.core.container import CONTAINERTYPES as cont_types
cont = self.cbox.get_container(device)
if not cont:
return False
if cont.get_type() != cont_types["luks"]:
if cont.get_type() != cryptobox.core.container.CONTAINERTYPES["luks"]:
return True
return False
@ -103,8 +94,27 @@ class volume_automount(cryptobox.plugins.base.CryptoBoxPlugin):
## only valid for plain volumes
if container.get_type() != cryptobox.core.container.CONTAINERTYPES["plain"]:
return False
if container.attributes.has_key("automount"):
return container.attributes["automount"] == self.true_string
if "_automount_names" in self.prefs:
if container.get_name() in self.prefs["_automount_names"]:
return True
else:
return False
else:
return False
def __set_auto_mount(self, container, state):
if state == self.__is_auto_mount(container):
return
name = container.get_name()
if not "_automount_names" in self.prefs:
self.prefs["_automount_names"] = []
if state:
self.prefs["_automount_names"].append(name)
else:
self.prefs["_automount_names"].remove(name)
try:
self.cbox.prefs.plugin_conf.write()
except IOError:
self.cbox.log.warn("Failed to store plugin configuration")

View file

@ -60,6 +60,10 @@ class CryptoBoxPlugin:
self.plugin_dir = plugin_dir
self.hdf_prefix = "Data.Plugins.%s." % self.get_name()
self.site = site_class
if not self.get_name() in self.cbox.prefs.plugin_conf:
## initialize plugin configuration
self.cbox.prefs.plugin_conf[self.get_name()] = {}
self.prefs = self.cbox.prefs.plugin_conf[self.get_name()]
@ -167,9 +171,9 @@ class CryptoBoxPlugin:
second step: check default value of plugin
"""
try:
if self.cbox.prefs.plugin_conf[self.get_name()]["requestAuth"] is None:
if self.prefs["requestAuth"] is None:
return self.request_auth
if self.cbox.prefs.plugin_conf[self.get_name()]["requestAuth"]:
if self.prefs["requestAuth"]:
return True
else:
return False
@ -184,9 +188,9 @@ class CryptoBoxPlugin:
"""
fallback = bool(self.plugin_visibility)
try:
if self.cbox.prefs.plugin_conf[self.get_name()]["visibility"] is None:
if self.prefs["visibility"] is None:
return fallback
return bool(self.cbox.prefs.plugin_conf[self.get_name()]["visibility"])
return bool(self.prefs["visibility"])
except KeyError:
return fallback
@ -197,9 +201,9 @@ class CryptoBoxPlugin:
second step: check default value of plugin
"""
try:
if self.cbox.prefs.plugin_conf[self.get_name()]["rank"] is None:
if self.prefs["rank"] is None:
return int(self.rank)
return int(self.cbox.prefs.plugin_conf[self.get_name()]["rank"])
return int(self.prefs["rank"])
except (KeyError, TypeError):
return int(self.rank)
@ -208,22 +212,16 @@ class CryptoBoxPlugin:
"""change the current rank of the plugin in plugin_conf
'rank' should be an integer
"""
pl_conf = self.cbox.prefs.plugin_conf
pl_name = self.get_name()
if pl_conf.has_key(pl_name):
pl_conf[pl_name]["rank"] = rank
else:
pl_conf[pl_name] = {}
pl_conf[pl_name]["rank"] = rank
self.prefs["rank"] = rank
def get_visibility(self):
"""Check which visibility flags of the feature are set.
"""Check which visibility flags of the plugin are set.
"""
try:
if self.cbox.prefs.plugin_conf[self.get_name()]["visibility"] is None:
if self.prefs["visibility"] is None:
return self.plugin_visibility[:]
return self.cbox.prefs.plugin_conf[self.get_name()]["visibility"]
return self.prefs["visibility"]
except KeyError:
return self.plugin_visibility