* prepared gateway setting

* style changes
This commit is contained in:
age 2007-01-20 15:41:18 +00:00
parent db927f7e55
commit e7bacbf5ba
5 changed files with 88 additions and 30 deletions

View file

@ -6,9 +6,11 @@
<?cs call:show_help(Lang.Plugins.network.Help.Network) ?> <?cs call:show_help(Lang.Plugins.network.Help.Network) ?>
<?cs call:print_form_header("set_ip", "network") ?>
<p><label for="ip"><?cs var:html_escape(Lang.Plugins.network.Text.IP) ?>: </label><br/> <fieldset>
<legend><?cs var:html_escape(Lang.Plugins.network.Text.IP) ?></legend>
<?cs call:print_form_header("change_ip", "network") ?>
<p>
<input class="ipnum" type="text" tabindex="1" name="ip1" size="3" id="ip" <input class="ipnum" type="text" tabindex="1" name="ip1" size="3" id="ip"
value="<?cs var:Data.Plugins.network.ip.oc1 value="<?cs var:Data.Plugins.network.ip.oc1
?>" />.<input class="ipnum" type="text" tabindex="2" name="ip2" size="3" ?>" />.<input class="ipnum" type="text" tabindex="2" name="ip2" size="3"
@ -16,10 +18,28 @@
?>" />.<input class="ipnum" type="text" tabindex="3" name="ip3" size="3" ?>" />.<input class="ipnum" type="text" tabindex="3" name="ip3" size="3"
value="<?cs var:Data.Plugins.network.ip.oc3 value="<?cs var:Data.Plugins.network.ip.oc3
?>" />.<input class="ipnum" type="text" tabindex="4" name="ip4" size="3" ?>" />.<input class="ipnum" type="text" tabindex="4" name="ip4" size="3"
value="<?cs var:Data.Plugins.network.ip.oc4 ?>" /></p> value="<?cs var:Data.Plugins.network.ip.oc4 ?>" />
<p><input type="hidden" tabindex="5" name="store" value="yes" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.network.Button.Network) ?></button></p>
<input type="hidden" tabindex="5" name="store" value="set_ip" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.network.Button.NetworkIP) ?></button>
</p>
</fieldset>
<fieldset>
<legend><?cs var:html_escape(Lang.Plugins.network.Text.GW) ?></legend>
<?cs call:print_form_header("change_gw", "network") ?>
<p>
<input class="ipnum" type="text" tabindex="1" name="gw1" size="3" id="gw"
value="<?cs var:Data.Plugins.network.gw.oc1
?>" />.<input class="ipnum" type="text" tabindex="2" name="gw2" size="3"
value="<?cs var:Data.Plugins.network.gw.oc2
?>" />.<input class="ipnum" type="text" tabindex="3" name="gw3" size="3"
value="<?cs var:Data.Plugins.network.gw.oc3
?>" />.<input class="ipnum" type="text" tabindex="4" name="gw4" size="3"
value="<?cs var:Data.Plugins.network.gw.oc4 ?>" />
<input type="hidden" tabindex="5" name="store" value="set_gw" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.network.Button.NetworkGW) ?></button>
</p>
</form> </form>

View file

@ -1,13 +1,18 @@
Name = Configure network Name = Configure network
Link = Configure network Link = Network
Title.Network = Network settings 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 { WarningMessage {
InvalidIP { InvalidIP {

View file

@ -1,2 +1,8 @@
input.ipnum { text-align: center } input.ipnum {
text-align: center;
}
#words p {
text-align: left;
}

View file

@ -41,7 +41,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
request_auth = True request_auth = True
rank = 30 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. """Show a form containing the current IP - change it if requested.
""" """
## if we were redirected, then we should display the default page ## 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") self.cbox.log.debug("network plugin: redirected")
return "form_network" return "form_network"
## request for IP change? ## request for IP change?
if store:
elif store == "set_ip":
self.cbox.log.debug("network plugin: changing IP") self.cbox.log.debug("network plugin: changing IP")
try: try:
for ip_in in (ip1, ip2, ip3, ip4): for ip_in in (ip1, ip2, ip3, ip4):
if (int(ip_in) < 0) or (int(ip_in) > 255): 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))) str((ip1, ip2, ip3, ip4)))
raise ValueError raise ValueError
new_ip = "%d.%d.%d.%d" % (int(ip1), int(ip2), int(ip3), int(ip4)) 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.hdf["Data.Warning"] = "Plugins.network.InvalidIP"
self.__prepare_form_data() self.__prepare_form_data()
return "form_network" return "form_network"
elif store == "set_gw":
## TODO
pass
else: else:
self.cbox.log.debug("network plugin: show form") self.cbox.log.debug("network plugin: show form")
## just show the form ## just show the form
@ -169,7 +173,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.cbox.prefs["Programs"]["CryptoBoxRootActions"], self.cbox.prefs["Programs"]["CryptoBoxRootActions"],
"plugin", "plugin",
os.path.join(self.plugin_dir, "root_action.py"), os.path.join(self.plugin_dir, "root_action.py"),
new_ip]) new_ip,
"change_ip"])
proc.wait() proc.wait()
if proc.returncode != 0: if proc.returncode != 0:
self.cbox.log.warn("failed to change IP address: %s" % new_ip) self.cbox.log.warn("failed to change IP address: %s" % new_ip)

View file

@ -28,28 +28,16 @@ __revision__ = "$Id"
PLUGIN_TYPE = "cryptobox" PLUGIN_TYPE = "cryptobox"
IFCONFIG_BIN = "/sbin/ifconfig" IFCONFIG_BIN = "/sbin/ifconfig"
GWCONFIG_BIN = "/sbin/route"
#TODO: put IFACE in config #TODO: put IFACE in config
IFACE = "eth0" IFACE = "eth1"
import subprocess import subprocess
import re import re
import sys import sys
import os import os
def __changeIP(address):
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(r'^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', args[0]) 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? ## 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]: if not match or [e for e in match.groups() if int(e) > 255]:
@ -62,3 +50,37 @@ if __name__ == "__main__":
proc.wait() proc.wait()
sys.exit(proc.returncode) 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)