diff --git a/plugins/network/form_network.cs b/plugins/network/form_network.cs index 99c9ee1..79b3ba4 100644 --- a/plugins/network/form_network.cs +++ b/plugins/network/form_network.cs @@ -6,9 +6,11 @@ - -


+

+ + +

." />..

- -

-

+ value="" /> + + +

+
+ +
+ + +

+ ... + + + +

diff --git a/plugins/network/language.hdf b/plugins/network/language.hdf index 1e2c41b..aa0bb94 100644 --- a/plugins/network/language.hdf +++ b/plugins/network/language.hdf @@ -1,13 +1,18 @@ Name = Configure network -Link = Configure network +Link = Network Title.Network = Network settings -Button.Network = Update network settings +Text.IP = CryptoBox server address -Text.IP = Network address +Button.NetworkIP = Change server address -Help.Network = Change the network address of the CryptoBox server. Be aware that you may lose your connection to the server under some circumstances. +Text.GW = Default gateway address + +Button.NetworkGW = Change default gateway + + +Help.Network = Change the network address of the CryptoBox server and the default gateway. Be aware that you may lose your connection to the server under some circumstances. WarningMessage { InvalidIP { diff --git a/plugins/network/network.css b/plugins/network/network.css index 44986c1..cc7ca11 100644 --- a/plugins/network/network.css +++ b/plugins/network/network.css @@ -1,2 +1,8 @@ -input.ipnum { text-align: center } +input.ipnum { + text-align: center; +} + +#words p { + text-align: left; +} diff --git a/plugins/network/network.py b/plugins/network/network.py index 4256309..3c16be7 100644 --- a/plugins/network/network.py +++ b/plugins/network/network.py @@ -41,7 +41,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): request_auth = True rank = 30 - def do_action(self, store=None, redirected="", ip1="", ip2="", ip3="", ip4=""): + def do_action(self, store=None, redirected="", ip1="", ip2="", ip3="", ip4="", gw1="", gw2="", gw3="", gw4=""): """Show a form containing the current IP - change it if requested. """ ## if we were redirected, then we should display the default page @@ -50,12 +50,13 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): self.cbox.log.debug("network plugin: redirected") return "form_network" ## request for IP change? - if store: + + elif store == "set_ip": self.cbox.log.debug("network plugin: changing IP") try: for ip_in in (ip1, ip2, ip3, ip4): if (int(ip_in) < 0) or (int(ip_in) > 255): - self.cbox.log.info("invalid IP supplied: %s" % \ + self.cbox.log.info("invalid CryptoBox IP supplied: %s" % \ str((ip1, ip2, ip3, ip4))) raise ValueError new_ip = "%d.%d.%d.%d" % (int(ip1), int(ip2), int(ip3), int(ip4)) @@ -79,6 +80,9 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): self.hdf["Data.Warning"] = "Plugins.network.InvalidIP" self.__prepare_form_data() return "form_network" + elif store == "set_gw": + ## TODO + pass else: self.cbox.log.debug("network plugin: show form") ## just show the form @@ -169,7 +173,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): self.cbox.prefs["Programs"]["CryptoBoxRootActions"], "plugin", os.path.join(self.plugin_dir, "root_action.py"), - new_ip]) + new_ip, + "change_ip"]) proc.wait() if proc.returncode != 0: self.cbox.log.warn("failed to change IP address: %s" % new_ip) diff --git a/plugins/network/root_action.py b/plugins/network/root_action.py index 998a754..c6d6d1e 100755 --- a/plugins/network/root_action.py +++ b/plugins/network/root_action.py @@ -28,28 +28,16 @@ __revision__ = "$Id" PLUGIN_TYPE = "cryptobox" IFCONFIG_BIN = "/sbin/ifconfig" +GWCONFIG_BIN = "/sbin/route" #TODO: put IFACE in config -IFACE = "eth0" +IFACE = "eth1" 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) - +def __changeIP(address): match = re.search(r'^(\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]: @@ -62,3 +50,37 @@ if __name__ == "__main__": proc.wait() sys.exit(proc.returncode) + +def __changeGW(address): + sys.exit(23) + + +if __name__ == "__main__": + args = sys.argv[1:] + + self_bin = sys.argv[0] + + if len(args) == 0: + sys.stderr.write("%s: no argument supplied\n" % self_bin) + sys.exit(1) + + try: + if args[0] == "change_ip": + if len(args) != 2: raise "InvalidArgNum" + result = __changeIP(args[1]) + elif args[0] == "change_gw": + if len(args) != 2: raise "InvalidArgNum" + result = __changeGW(args[1]) + else: + sys.stderr.write("%s: invalid action (%s)\n" % (self_bin, args[0])) + sys.exit(1) + if result: + sys.exit(0) + else: + sys.exit(1) + except "InvalidArgNum": + sys.stderr.write("%s: invalid number of arguments (%s)\n" % (self_bin, args)) + sys.exit(1) + + +