Browse Source

* network plugin supports dhcp

master
age 15 years ago
parent
commit
cbfddddeb2
  1. 21
      plugins/network/form_network.cs
  2. 58
      plugins/network/intl/pl/cryptobox-server-feature-network.po
  3. 32
      plugins/network/language.hdf
  4. 52
      plugins/network/network.py
  5. 12
      plugins/network/root_action.py

21
plugins/network/form_network.cs

@ -80,13 +80,26 @@
var:html_escape(Lang.Plugins.network.Button.Gateway) ?></button>
</p>
</form>
</fieldset>
<!-- DHCP comes later
<fieldset>
<legend>
<?cs call:show_plugin_icon() ?>
<?cs var:html_escape(Lang.Plugins.network.Title.DHCP) ?>
</legend>
<?cs call:print_form_header("network_address", "network") ?>
<?cs call:show_help(Lang.Plugins.network.Help.DHCP) ?>
<p>
<input type="checkbox" name="dhcp" value="1" id="dhcp" /><label for="dhcp"><?cs var:html_escape(Lang.Plugins.network.Text.DHCP) ?></label>
<input type="checkbox" name="confirm_dhcp" value="1" id="confirm_dhcp"
<?cs if:Data.Plugins.network.dhcp == "use" ?>checked<?cs /if ?>
/>
<label for="confirm_dhcp"><?cs var:html_escape(Lang.Plugins.network.Text.DHCP) ?></label>
</p>
-->
<p>
<input type="hidden" name="store" value="use_dhcp" />
<button type="submit" tabindex="9"><?cs
var:html_escape(Lang.Plugins.network.Button.DHCP) ?></button>
</p>
</form>
</fieldset>

58
plugins/network/intl/pl/cryptobox-server-feature-network.po

@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: CryptoBox-Server 0.3\n"
"Report-Msgid-Bugs-To: translate@cryptobox.org\n"
"POT-Creation-Date: 2007-02-07 09:21+0100\n"
"POT-Creation-Date: 2007-08-11 23:48+0200\n"
"PO-Revision-Date: 2007-03-29 10:17+0200\n"
"Last-Translator: Andrzej S. Kaznowski <andrzej@kaznowski.com>\n"
"Language-Team: POLSKI <LL@li.org>\n"
@ -12,114 +12,114 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"X-Generator: Pootle 0.10.1\n"
#: :
#: Name
msgid "Configure network"
msgstr "Konfiguruj sieć"
#: :
#: Link
msgid "Network"
msgstr "Sieć"
#: :
#: Title
msgid "Network settings"
msgstr "Ustawienia sieci"
#: :
#: Title.IP
msgid "CryptoBox server IP"
msgstr "Numer IP serwera CryptoBox"
#: :
#: Title.GW
msgid "Gateway address"
msgstr "Adres bramki"
#: :
#: Text.IP
msgid "Address"
msgstr "Adres"
#: :
#: Text.NM
msgid "Netmask"
msgstr "Maska sieciowa"
#: :
#: Text.GW
msgid "Gateway"
msgstr "Bramka"
#: :
#: Text.DHCP
msgid "Automatic configuration (Caution!)"
msgstr "Konfiguruj automatycznie (Uwaga!)"
#: :
#: Button.Network
msgid "Change server address"
msgstr "Zmień adres serwera"
#: :
#: Button.Gateway
msgid "Change default gateway"
msgstr "Zmień domyślną bramkę"
#: :
#: Help.Network
msgid "Insert the network address of the CryptoBox server, the network mask and the default gateway. Be aware that you may lose your connection to the server under some circumstances. The actual values are visible in the form fields."
msgstr "Wpisz adres sieci serwera CryptoBox, maski sieciowej i domyślnej bramki. Weź pod uwagę, że możesz stracić połączenie z serwerem. Aktualne parametry są domyślnie wyświetlone w polach."
#: :
#: Help.Gateway
msgid "If you have a gateway in your LAN and want to make use of it, type it's address in here. It will be added as default route. A quadruple of zeros means, there is no gateway set."
msgstr "Jeśli masz bramkę w twojej lokalnej sieci i chcesz jej użyć, wpisz jej adres tutaj. Będzie dodany jako domyślna bramka. Cztery zera oznaczają, że nie wpisano żadnej bramki."
#: :
#: Help.DHCP
msgid "If you enable automatic network configuration make sure you have a well configured DHCP server running. All values will be overridden by the settings from the DHCP server. If you don't know what DHCP means leave this box unchecked."
msgstr "Jeśli włączasz automatyczną konfigurację sieci, upewnij się, że twój serwer DHCP działa poprawnie. Wszystkie dane zostaną zastąpione danymi z serwera DHCP. Jeśli nie wiesz, co oznacza DHCP, pozostaw to pole niezaznaczone."
#: :
#: WarningMessage.AddressChangeFailed.Title
msgid "Failure"
msgstr "Błąd"
#: :
#: WarningMessage.AddressChangeFailed.Text
msgid "The address of the CryptoBox server could not be changed."
msgstr "Nie można zmienić adresu serwera CryptoBox."
#: :
#: WarningMessage.GatewayChangeFailed.Text
msgid "The gateway of the CryptoBox server could not be set. Maybe the address you entered is unreachable?"
msgstr "Nie można ustlić bramki serwera CryptoBox. Może wpisany przez ciebie adres jest niedostępny."
#: :
#: WarningMessage.InvalidServerIP.Title
msgid "Invalid value"
msgstr "Nieprawidłowe dane"
#: :
#: WarningMessage.InvalidServerIP.Text
msgid "The server address is not valid."
msgstr "Nieprawidłowy adres serwera."
#: :
#: WarningMessage.InvalidNetmask.Text
msgid "The netmask is not valid."
msgstr "Nieprawidłowa maska sieciowa."
#: :
#: WarningMessage.InvalidGatewayIP.Text
msgid "The gateway address is not valid."
msgstr "Nieprawidłowy adres bramki."
#: :
#: SuccessMessage.IPChanged.Title
msgid "Network address changed"
msgstr "Zmieniono adres sieciowy"
#: :
#: SuccessMessage.IPChanged.Text
msgid "The network address has been changed. In a few seconds you will get redirected to the new address."
msgstr "Zmieniono adres sieciowy. Za chwilę zostaniesz przekierowany na nowy adres."
#: :
#: SuccessMessage.GWChanged.Title
msgid "Gateway address changed"
msgstr "Zmieniono adres bramki"
#: :
#: SuccessMessage.GWChanged.Text
msgid "The gateway was added to your default route."
msgstr "Dodano bramkę do domyślnej trasy."
#: :
#: EnvironmentWarning.MissingProgramIfconfig.Title
msgid "Missing program"
msgstr "Brak programu"
#: :
#: EnvironmentWarning.MissingProgramIfconfig.Text
msgid "The 'ifconfig' program is not installed. Please ask the administrator of the CryptoBox server to configure it properly."
msgstr "Program 'ifconfig' nie jest instalowany. Proszę zwrócić się do administratora serwera CryptoBox, aby prawidłowo skonfigurał go."
#: :
#: EnvironmentWarning.MissingProgramRoute.Text
msgid "The 'route' program is not installed. Please ask the administrator of the CryptoBox server to configure it properly."
msgstr "Program 'route' nie jest instalowany. Proszę zwrócić się do administratora serwera CryptoBox, aby prawidłowo skonfigurał go."

32
plugins/network/language.hdf

@ -5,16 +5,18 @@ Title = Network settings
Title {
IP = CryptoBox server IP
GW = Gateway address
DHCP = DHCP network configuration
}
Text {
IP = Address
NM = Netmask
GW = Gateway
DHCP = Automatic configuration (Caution!)
DHCP = Configure the network interface automatically (Caution, please read help!)
}
Button {
DHCP = Recieve network settings
Network = Change server address
Gateway = Change default gateway
}
@ -22,7 +24,7 @@ Button {
Help {
Network = Insert the network address of the CryptoBox server, the network mask and the default gateway. Be aware that you may lose your connection to the server under some circumstances. The actual values are visible in the form fields.
Gateway = If you have a gateway in your LAN and want to make use of it, type it's address in here. It will be added as default route. A quadruple of zeros means, there is no gateway set.
DHCP = If you enable automatic network configuration make sure you have a well configured DHCP server running. All values will be overridden by the settings from the DHCP server. If you don't know what DHCP means leave this box unchecked.
DHCP = If you enable automatic network configuration make sure you have a well configured DHCP server running. All former network settings will be overridden by the settings from the DHCP server. Remember you need to know which network address the CryptoBox will recieve, otherwise you won't know where to connect to. If you don't know what DHCP means leave this box unchecked.
}
WarningMessage {
@ -50,6 +52,19 @@ WarningMessage {
Title = Invalid value
Text = The gateway address is not valid.
}
DHCPNotConfirmed {
Title = Confirmation missing
Text = If you really want to use DHCP, please confirm by activating the checkbox.
}
DHCPNotRunning {
Title = DHCP Failure
Text = The network settings couldn't be recieved.
}
DHCPNotFound {
Title = DHCP program missing
Text = The 'dhclient' program is not installed. Please ask the administrator of the CryptoBox server to install it.
}
}
SuccessMessage {
@ -61,6 +76,10 @@ SuccessMessage {
Title = Gateway address changed
Text = The gateway was added to your default route.
}
DHCPRunning {
Title = Recieving network settings
Text = In a few seconds you can connect to the address provided by dhcp.
}
}
EnvironmentWarning {
@ -68,16 +87,9 @@ EnvironmentWarning {
Title = Missing program
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.
Text = The 'route' program is not installed. Please ask the administrator of the CryptoBox server to install it.
}
}

52
plugins/network/network.py

@ -48,7 +48,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
rank = 30
def do_action(self, store=None, redirected="", ip1="", ip2="", ip3="", ip4="",
nm1="", nm2="", nm3="", nm4=""):
nm1="", nm2="", nm3="", nm4="", confirm_dhcp=""):
"""Show a form containing the current IP - change it if requested.
"""
## if we were redirected, then we should display the default page
@ -85,6 +85,9 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf["Data.Redirect.Delay"] = REDIRECT_DELAY
self.prefs["_address"] = new_ip
self.prefs["_netmask"] = new_nm
## if an ip is set manually, don't use dhcp any longer
if self.prefs.has_key("_dhcp"):
del self.prefs["_dhcp"]
try:
self.cbox.prefs.plugin_conf.write()
except IOError:
@ -113,6 +116,9 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
+ new_gw_str)
self.hdf["Data.Success"] = "Plugins.network.GWChanged"
self.prefs["_gateway"] = new_gw_str
## if an gw is set manually, don't use dhcp any longer
if self.prefs.has_key("_dhcp"):
del self.prefs["_dhcp"]
try:
self.cbox.prefs.plugin_conf.write()
except IOError:
@ -123,6 +129,28 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf["Data.Warning"] = "Plugins.network.GatewayChangeFailed"
self.__prepare_form_data()
return "form_network"
## request for dhcp usage
elif store == "use_dhcp":
if confirm_dhcp != "1":
## do nothing as the action was not confirmed with the checkbox
self.hdf["Data.Warning"] = "Plugins.network.DHCPNotConfirmed"
self.__prepare_form_data()
return "form_network"
else:
self.cbox.log.info( "[network] recieve network settings via DHCP")
if not os.path.isfile(self.root_action.DHCLIENT_BIN):
self.hdf["Data.Warning"] = "Plugins.network.DHCPNotFound"
elif self.__use_dhcp():
self.hdf["Data.Success"] = "Plugins.network.DHCPRunning"
self.prefs["_dhcp"] = "use"
try:
self.cbox.prefs.plugin_conf.write()
except IOError:
self.cbox.log.warn("Could not write plugin configuration")
else:
self.hdf["Data.Warning"] = "Plugins.network.DHCPNotRunning"
self.__prepare_form_data()
return "form_network"
else:
## invalid action was requested -> show default form
self.cbox.log.debug("network plugin: invalid request (%s)" % str(store))
@ -176,6 +204,7 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
dest = "%s://%s" % (base_parts[0], ip)
if len(base_parts) == 3:
dest += ":%s" % base_parts[2]
dest += "/network"
return dest
@ -198,6 +227,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf[self.hdf_prefix + "gw.oc2"] = oc2
self.hdf[self.hdf_prefix + "gw.oc3"] = oc3
self.hdf[self.hdf_prefix + "gw.oc4"] = oc4
if self.prefs.has_key("_dhcp"):
self.hdf[self.hdf_prefix + "dhcp"] = str(self.prefs["_dhcp"])
def __get_current_ip(self, address_type="ip"):
@ -357,3 +388,22 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
return False
return True
def __use_dhcp(self):
"""Try to recieve network settings via dhcp
"""
proc = subprocess.Popen(
shell = False,
stderr = subprocess.PIPE,
args = [
self.cbox.prefs["Programs"]["super"],
self.cbox.prefs["Programs"]["CryptoBoxRootActions"],
"plugin",
os.path.join(self.plugin_dir, "root_action.py"),
"use_dhcp",
self.__get_interface() ])
proc.wait()
if proc.returncode != 0:
self.cbox.log.warn("failed to recieve IP address via DHCP")
self.cbox.log.warn("error output: %s" % str(proc.stderr.read()))
return True

12
plugins/network/root_action.py

@ -27,6 +27,7 @@ PLUGIN_TYPE = "cryptobox"
IFCONFIG_BIN = "/sbin/ifconfig"
ROUTE_BIN = "/sbin/route"
DHCLIENT_BIN = "/sbin/dhclient"
import subprocess
import re
@ -77,6 +78,14 @@ def __check_address(address):
sys.exit(1)
return
def __use_DHCP(interface):
"""Recieve network settings via dhcp
"""
proc = subprocess.Popen(
shell = False,
args = [DHCLIENT_BIN, interface])
proc.wait()
if __name__ == "__main__":
args = sys.argv[1:]
@ -94,6 +103,9 @@ if __name__ == "__main__":
elif args[0] == "change_gw":
if len(args) != 3: raise "InvalidArgNum"
result = __changeGW(args[1], args[2])
elif args[0] == "use_dhcp":
if len(args) != 2: raise "InvalidArgNum"
result = __use_DHCP(args[1])
else:
sys.stderr.write("%s: invalid action (%s)\n" % (self_bin, args[0]))
sys.exit(1)

Loading…
Cancel
Save