implemented root actions for plugins

finished network and date plugins
renamed old 'bin' direcory
This commit is contained in:
lars 2006-09-13 10:38:05 +00:00
parent 2b4180a83b
commit e80b8874ff
13 changed files with 211 additions and 23 deletions

View file

@ -12,7 +12,7 @@ Lang {
Rank = 30
}
Warning.InvalidIP {
WarningMessage.InvalidIP {
Title = Invalid value
Text = An invalid network address (IP) was supplied. Please try again.
}

View file

@ -1,8 +1,12 @@
from CryptoBoxExceptions import CBPluginActionError
import re
import subprocess
import imp
import os
def prepareForm(hdf, cbox):
(oc1, oc2, oc3, oc4) = __getCurrentIP()
(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
@ -12,22 +16,51 @@ def prepareForm(hdf, cbox):
def doAction(cbox, store=None, ip1="", ip2="", ip3="", ip4=""):
if store:
try:
# TODO: check the IP here
pass
for ip_in in (ip1, ip2, ip3, ip4):
if (int(ip_in) < 0) or (int(ip_in) > 255):
cbox.log.debug("invalid IP supplied: %s" % str((ip1,ip2,ip3,ip4)))
raise ValueError
ip = "%d.%d.%d.%d" % (int(ip1), int(ip2), int(ip3), int(ip4))
except ValueError:
raise CBPluginActionError, "InvalidIP"
# TODO: how to set the new IP? (and how to become root?)
## we will continue with the system menue
return "form_system"
if __setIP(cbox, ip):
return "form_system"
else:
raise CBPluginActionError, "InvalidIP"
else:
return "form_network"
def getStatus(cbox):
return "%d.%d.%d.%d" % __getCurrentIP()
return "%d.%d.%d.%d" % __getCurrentIP(cbox)
def __getCurrentIP():
# TODO: for now we only provide a dummy
return (192,168,0,23)
def __getCurrentIP(cbox):
root_action_mod = 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])
(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)
if match:
return tuple([int(e) for e in match.groups()])
else:
return (0,0,0,0)
def __setIP(cbox, ip):
proc = subprocess.Popen(
shell = False,
args = [
cbox.prefs["Programs"]["super"],
cbox.prefs["Programs"]["CryptoBoxRootActions"],
"plugin",
os.path.join(os.path.dirname(__file__), "root_action.py"),
ip])
proc.communicate()
return proc.returncode == 0

View file

@ -0,0 +1,41 @@
#!/usr/bin/env python2.4
#TODO: add netmask and gateway
## necessary: otherwise CryptoBoxRootActions.py will refuse to execute this script
PLUGIN_TYPE = "cryptobox"
IFCONFIG_BIN = "/sbin/ifconfig"
IFACE = "eth0"
import subprocess
import re
import sys
import os
if __name__ == "__main__":
args = sys.argv[1:]
self_bin =sys.argv[0]
if len(args) > 1:
sys.stderr.write("%s: too many arguments (%s)\n" % (self_bin, args))
sys.exit(1)
if len(args) == 0:
sys.stderr.write("%s: no argument supplied\n" % self_bin)
sys.exit(1)
match = re.search(u'^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', args[0])
## did we match? If yes, then: are there wrong values inside?
if not match or [e for e in match.groups() if int(e) > 255]:
sys.stderr.write("%s: illegal argument (%s)\n" % (self_bin, args[0]))
sys.exit(1)
proc = subprocess.Popen(
shell = False,
args = [IFCONFIG_BIN, IFACE, args[0]])
proc.communicate()
sys.exit(proc.returncode)