language namespace for plugins separated

plugin interface changed ("prepareForm" removed)
plugins do not raise exceptions anymore
first part of the partitioning plugin
device-specific stuff moved to CryptoBoxTools
This commit is contained in:
lars 2006-09-14 12:33:01 +00:00
parent f2a7ceb61c
commit de3280806f
26 changed files with 622 additions and 309 deletions

View file

@ -1,22 +1,22 @@
<?cs # $Id$ ?>
<h1><?cs var:html_escape(Lang.Title.Network) ?></h1>
<h1><?cs var:html_escape(Lang.Plugins.network.Title.Network) ?></h1>
<?cs call:print_form_header("module_network") ?>
<?cs call:print_form_header("plugins/network") ?>
<p><label for="ip"><?cs var:html_escape(Lang.Text.IP) ?>: </label><br/>
<p><label for="ip"><?cs var:html_escape(Lang.Plugins.network.Text.IP) ?>: </label><br/>
<input type="text" name="ip1" size="3" id="ip" value="<?cs
var:Data.Modules.network.ip.oc1 ?>" />.
var:Data.Plugins.network.ip.oc1 ?>" />.
<input type="text" name="ip2" size="3" value="<?cs
var:Data.Modules.network.ip.oc2 ?>" />.
var:Data.Plugins.network.ip.oc2 ?>" />.
<input type="text" name="ip3" size="3" value="<?cs
var:Data.Modules.network.ip.oc3 ?>" />.
var:Data.Plugins.network.ip.oc3 ?>" />.
<input type="text" name="ip4" size="3" value="<?cs
var:Data.Modules.network.ip.oc4 ?>" /></p>
var:Data.Plugins.network.ip.oc4 ?>" /></p>
<input type="hidden" name="store" value="yes" />
<button type="submit"><?cs var:html_escape(Lang.Button.Network) ?></button>
<button type="submit"><?cs var:html_escape(Lang.Plugins.network.Button.Network) ?></button>
</form>

View file

@ -1,20 +1,24 @@
Lang {
Name = Configure network
Link = Configure network
Rank = 30
Title.Network = Network settings
Title.Network = Network settings
Button.Network = Update settings
Button.Network = Update settings
Text.IP = Network address
Text.IP = Network address
Modules.network {
Name = Configure network
Link = Configure network
Rank = 30
}
WarningMessage.InvalidIP {
WarningMessage {
InvalidIP {
Title = Invalid value
Text = An invalid network address (IP) was supplied. Please try again.
}
}
SuccessMessage {
IPChanged {
Title = Network address changed
Text = The network address has been changed. In a few seconds you will get redirected to the new address.
}
}

View file

@ -1,19 +1,11 @@
from CryptoBoxExceptions import CBPluginActionError
import re
import subprocess
import imp
import os
def prepareForm(hdf, cbox):
(oc1, oc2, oc3, oc4) = __getCurrentIP(cbox)
hdf["Data.Modules.network.ip.oc1"] = oc1
hdf["Data.Modules.network.ip.oc2"] = oc2
hdf["Data.Modules.network.ip.oc3"] = oc3
hdf["Data.Modules.network.ip.oc4"] = oc4
def doAction(cbox, store=None, ip1="", ip2="", ip3="", ip4=""):
def doAction(hdf, cbox, store=None, ip1="", ip2="", ip3="", ip4=""):
__prepareFormData(hdf, cbox)
if store:
try:
for ip_in in (ip1, ip2, ip3, ip4):
@ -22,11 +14,16 @@ def doAction(cbox, store=None, ip1="", ip2="", ip3="", ip4=""):
raise ValueError
ip = "%d.%d.%d.%d" % (int(ip1), int(ip2), int(ip3), int(ip4))
except ValueError:
raise CBPluginActionError, "InvalidIP"
hdf["Data.Warning"] = "Plugins.network.InvalidIP"
return "form_system"
if __setIP(cbox, ip):
hdf["Data.Success"] = "Plugins.network.IPChanged"
hdf["Data.Redirect.URL"] = ""
hdf["Data.Redirect.Delay"] = 30
return "form_system"
else:
raise CBPluginActionError, "InvalidIP"
hdf["Data.Warning"] = "Plugins.network.InvalidIP"
return "form_network"
else:
return "form_network"
@ -35,14 +32,22 @@ def getStatus(cbox):
return "%d.%d.%d.%d" % __getCurrentIP(cbox)
def __prepareFormData(hdf, cbox):
(oc1, oc2, oc3, oc4) = __getCurrentIP(cbox)
hdf["Data.Plugins.network.ip.oc1"] = oc1
hdf["Data.Plugins.network.ip.oc2"] = oc2
hdf["Data.Plugins.network.ip.oc3"] = oc3
hdf["Data.Plugins.network.ip.oc4"] = oc4
def __getCurrentIP(cbox):
root_action_mod = imp.load_source("root_action", os.path.join(os.path.dirname(__file__), "root_action.py"))
root_action_plug = imp.load_source("root_action", os.path.join(os.path.dirname(__file__), "root_action.py"))
proc = subprocess.Popen(
shell = False,
stdout = subprocess.PIPE,
args = [
root_action_mod.IFCONFIG_BIN,
root_action_mod.IFACE])
root_action_plug.IFCONFIG_BIN,
root_action_plug.IFACE])
(output, error) = proc.communicate()
if proc.returncode != 0: return (0,0,0,0)
match = re.search(u'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s',output)