added regex for netmask

minor changes in language file
This commit is contained in:
lars 2007-01-30 09:12:54 +00:00
parent 14188be2ab
commit b789fec8ad
3 changed files with 39 additions and 24 deletions

View file

@ -5,14 +5,16 @@
<fieldset>
<legend><?cs var:html_escape(Lang.Plugins.network.Title.IP) ?></legend>
<?cs call:print_form_header("static", "network") ?>
<?cs call:print_form_header("network_address", "network") ?>
<?cs call:show_help(Lang.Plugins.network.Help.Network) ?>
<table>
<tr><td>
<?cs var:html_escape(Lang.Plugins.network.Text.IP) ?>:
</td><td>
<!-- maybe display the used network interface?
<!-- maybe display the used network interface?
but users will not really know what this is about
admins will know anyway, which interface it is (because of the IP)
<tr><td>
<?cs var:html_escape(Lang.Plugins.network.Interface) ?>:
</td><td>
@ -30,19 +32,20 @@
<tr><td>
<?cs var:html_escape(Lang.Plugins.network.Text.NM) ?>:
</td><td>
<input class="ipnum" type="text" tabindex="1" name="nm1" size="3" id="nm"
<input class="ipnum" type="text" tabindex="5" name="nm1" size="3" id="nm"
value="<?cs var:Data.Plugins.network.nm.oc1
?>" />.<input class="ipnum" type="text" tabindex="2" name="nm2" size="3"
?>" />.<input class="ipnum" type="text" tabindex="6" name="nm2" size="3"
value="<?cs var:Data.Plugins.network.nm.oc2
?>" />.<input class="ipnum" type="text" tabindex="3" name="nm3" size="3"
?>" />.<input class="ipnum" type="text" tabindex="7" name="nm3" size="3"
value="<?cs var:Data.Plugins.network.nm.oc3
?>" />.<input class="ipnum" type="text" tabindex="4" name="nm4" size="3"
?>" />.<input class="ipnum" type="text" tabindex="8" name="nm4" size="3"
value="<?cs var:Data.Plugins.network.nm.oc4 ?>" />
</td></tr><tr><td>
</table>
<p>
<input type="hidden" name="store" value="set_ip" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.network.Button.Network) ?></button>
<button type="submit" tabindex="9"><?cs
var:html_escape(Lang.Plugins.network.Button.Network) ?></button>
</p>
</form>
</fieldset>
@ -50,26 +53,27 @@
<fieldset>
<legend><?cs var:html_escape(Lang.Plugins.network.Title.GW) ?></legend>
<?cs call:print_form_header("static", "network") ?>
<?cs call:print_form_header("network_gateway", "network") ?>
<?cs call:show_help(Lang.Plugins.network.Help.Gateway) ?>
<table>
<tr><td>
<?cs var:html_escape(Lang.Plugins.network.Text.GW) ?>:
</td><td>
<input class="ipnum" type="text" tabindex="1" name="ip1" size="3" id="ip"
<input class="ipnum" type="text" tabindex="20" name="ip1" size="3" id="ip"
value="<?cs var:Data.Plugins.network.gw.oc1
?>" />.<input class="ipnum" type="text" tabindex="2" name="ip2" size="3"
?>" />.<input class="ipnum" type="text" tabindex="21" name="ip2" size="3"
value="<?cs var:Data.Plugins.network.gw.oc2
?>" />.<input class="ipnum" type="text" tabindex="3" name="ip3" size="3"
?>" />.<input class="ipnum" type="text" tabindex="22" name="ip3" size="3"
value="<?cs var:Data.Plugins.network.gw.oc3
?>" />.<input class="ipnum" type="text" tabindex="4" name="ip4" size="3"
?>" />.<input class="ipnum" type="text" tabindex="23" name="ip4" size="3"
value="<?cs var:Data.Plugins.network.gw.oc4 ?>" />
</td></tr>
</table>
<p>
<input type="hidden" name="store" value="set_gateway" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.network.Button.Gateway) ?></button>
<button type="submit" tabindex="24"><?cs
var:html_escape(Lang.Plugins.network.Button.Gateway) ?></button>
</p>
</form>

View file

@ -32,15 +32,15 @@ WarningMessage {
}
InvalidServerIP {
Title = Invalid value
Text = The server address is not a valid number.
Text = The server address is not valid.
}
InvalidNetmaskIP {
InvalidNetmask {
Title = Invalid value
Text = The netmask address is not a valid number.
Text = The netmask is not valid.
}
InvalidGatewayIP {
Title = Invalid value
Text = The gateway address is not a valid number.
Text = The gateway address is not valid.
}
}
@ -61,6 +61,12 @@ EnvironmentWarning {
Text = The 'ifconfig' program is not installed. Please ask the administrator of the CryptoBox server to install it.
}
MissingProgramIfconfig {
Title = Missing program
Text = The 'ifconfig' program is not installed. Please ask the administrator of the CryptoBox server to configure it properly.
}
MissingProgramRoute {
Title = Missing program
Text = The 'route' program is not installed. Please ask the administrator of the CryptoBox server to configure it properly.

View file

@ -74,7 +74,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
if self.__IP_is_valid(nm1, nm2, nm3, nm4):
new_nm = "%d.%d.%d.%d" % (int(nm1), int(nm2), int(nm3), int(nm4))
else:
self.hdf["Data.Warning"] = "Plugins.network.InvalidNetmaskIP"
self.hdf["Data.Warning"] = "Plugins.network.InvalidNetmask"
self.__prepare_form_data()
return "form_network"
if self.__set_ip(new_ip, new_nm):
@ -90,7 +90,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.__prepare_form_data()
return "empty"
else:
self.cbox.log.warn("failed to change IP address to: %s" % new_ip)
self.cbox.log.warn("Failed to change IP address to: %s" % new_ip)
self.hdf["Data.Warning"] = "Plugins.network.Failure"
self.__prepare_form_data()
return "form_network"
@ -107,7 +107,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf["Data.Success"] = "Plugins.network.GWChanged"
else:
self.cbox.log.warn("failed to change gateway address to: %s" % new_ip)
self.cbox.log.warn("Failed to change gateway address to: %s" % new_ip)
self.hdf["Data.Warning"] = "Plugins.network.Failure"
self.__prepare_form_data()
return "form_network"
@ -139,7 +139,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
"""
warnings = []
if not os.path.isfile(self.root_action.IFCONFIG_BIN):
warnings.append((55, "MissingProgramIfconfig"))
warnings.append((55, "Plugins.%s.MissingProgramIfconfig" % self.get_name()))
if not os.path.isfile(self.root_action.GWCONFIG_BIN):
warnings.append((52, "Plugins.%s.MissingProgramRoute" % self.get_name()))
return warnings
@ -171,6 +171,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf[self.hdf_prefix + "nm.oc3"] = oc3
self.hdf[self.hdf_prefix + "nm.oc4"] = oc4
def __get_current_ip(self, type="ip"):
"""Retrieve the current IP.
"""
@ -196,11 +197,15 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
elif type == "nm":
##TODO: Lars please leave a regex note for fetching the
## netmask with ifconfig
#match = re.search(r'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', stdout)
return ("L", "A", "3", "S")
match = re.search(r'inet [\w]+:.*Mask:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', stdout)
if match:
## use the previously matched numbers
return tuple([int(e) for e in match.groups()])
else:
return (0, 0, 0, 0)
def __set_ip(self, new_ip, new_nm="0"):
def __set_ip(self, new_ip, new_nm="255.255.255.0"):
"""Change the IP, additionally a netmask can be applied
"""
import threading