removed two TODOs
This commit is contained in:
parent
636973af95
commit
d7c5b5ead5
|
@ -162,7 +162,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
"""The current IP is the status of this feature.
|
"""The current IP is the status of this feature.
|
||||||
"""
|
"""
|
||||||
return "%d.%d.%d.%d" % self.__get_current_ip()
|
return "%d.%d.%d.%d" % self.__get_current_ip()[1]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handle_event(self, event, event_info=None):
|
def handle_event(self, event, event_info=None):
|
||||||
|
@ -212,35 +213,34 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
|
||||||
def __prepare_form_data(self):
|
def __prepare_form_data(self):
|
||||||
"""Set some hdf values.
|
"""Set some hdf values.
|
||||||
"""
|
"""
|
||||||
#TODO: the following looks nicer in a loop
|
(ip1, ip2, ip3, ip4),(nm1, nm2, nm3, nm4) = self.__get_current_ip()
|
||||||
(oc1, oc2, oc3, oc4) = self.__get_current_ip("ip")
|
self.hdf[self.hdf_prefix + "ip.oc1"] = ip1
|
||||||
self.hdf[self.hdf_prefix + "ip.oc1"] = oc1
|
self.hdf[self.hdf_prefix + "ip.oc2"] = ip2
|
||||||
self.hdf[self.hdf_prefix + "ip.oc2"] = oc2
|
self.hdf[self.hdf_prefix + "ip.oc3"] = ip3
|
||||||
self.hdf[self.hdf_prefix + "ip.oc3"] = oc3
|
self.hdf[self.hdf_prefix + "ip.oc4"] = ip4
|
||||||
self.hdf[self.hdf_prefix + "ip.oc4"] = oc4
|
self.hdf[self.hdf_prefix + "nm.oc1"] = nm1
|
||||||
(oc1, oc2, oc3, oc4) = self.__get_current_ip("nm")
|
self.hdf[self.hdf_prefix + "nm.oc2"] = nm2
|
||||||
self.hdf[self.hdf_prefix + "nm.oc1"] = oc1
|
self.hdf[self.hdf_prefix + "nm.oc3"] = nm3
|
||||||
self.hdf[self.hdf_prefix + "nm.oc2"] = oc2
|
self.hdf[self.hdf_prefix + "nm.oc4"] = nm4
|
||||||
self.hdf[self.hdf_prefix + "nm.oc3"] = oc3
|
|
||||||
self.hdf[self.hdf_prefix + "nm.oc4"] = oc4
|
|
||||||
(oc1, oc2, oc3, oc4) = self.__get_current_gw()
|
(oc1, oc2, oc3, oc4) = self.__get_current_gw()
|
||||||
self.hdf[self.hdf_prefix + "gw.oc1"] = oc1
|
self.hdf[self.hdf_prefix + "gw.oc1"] = oc1
|
||||||
self.hdf[self.hdf_prefix + "gw.oc2"] = oc2
|
self.hdf[self.hdf_prefix + "gw.oc2"] = oc2
|
||||||
self.hdf[self.hdf_prefix + "gw.oc3"] = oc3
|
self.hdf[self.hdf_prefix + "gw.oc3"] = oc3
|
||||||
self.hdf[self.hdf_prefix + "gw.oc4"] = oc4
|
self.hdf[self.hdf_prefix + "gw.oc4"] = oc4
|
||||||
|
|
||||||
if self.prefs.has_key("_dhcp"):
|
if self.prefs.has_key("_dhcp"):
|
||||||
self.hdf[self.hdf_prefix + "dhcp"] = str(self.prefs["_dhcp"])
|
self.hdf[self.hdf_prefix + "dhcp"] = str(self.prefs["_dhcp"])
|
||||||
self.hdf[self.hdf_prefix + "interface"] = str(self.__get_interface())
|
self.hdf[self.hdf_prefix + "interface"] = str(self.__get_interface())
|
||||||
self.hdf[self.hdf_prefix + "mac"] = str(self.__get_interface_mac(self.__get_interface()))
|
self.hdf[self.hdf_prefix + "mac"] = str(self.__get_interface_mac(self.__get_interface()))
|
||||||
|
|
||||||
|
|
||||||
def __get_current_ip(self, address_type="ip"):
|
def __get_current_ip(self):
|
||||||
"""Retrieve the current IP.
|
"""Retrieve the current IP.
|
||||||
|
|
||||||
TODO: do not use "address_type" for ip and netmask, but return both in
|
|
||||||
two tuples
|
|
||||||
"""
|
"""
|
||||||
## get the current IP of the network interface
|
ip = (0,0,0,0)
|
||||||
|
nm = (0,0,0,0)
|
||||||
|
## get the current IP/netmask of the network interface
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
shell = False,
|
shell = False,
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
|
@ -249,25 +249,23 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
|
||||||
self.__get_interface()])
|
self.__get_interface()])
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
return (0, 0, 0, 0)
|
return ip, nm
|
||||||
if address_type == "ip":
|
|
||||||
## this regex matches the four numbers of the IP
|
## this regex matches the four numbers of the IP
|
||||||
match = re.search(r'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', stdout)
|
match = re.search(
|
||||||
if match:
|
r'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s',
|
||||||
## use the previously matched numbers
|
stdout)
|
||||||
return tuple([int(e) for e in match.groups()])
|
if match:
|
||||||
else:
|
ip = tuple([int(e) for e in match.groups()])
|
||||||
return (0, 0, 0, 0)
|
|
||||||
elif address_type == "nm":
|
## this greps the netmask
|
||||||
## this greps the netmask
|
match = re.search(
|
||||||
match = re.search(
|
r'inet [\w]+:.*Mask:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s',
|
||||||
r'inet [\w]+:.*Mask:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s',
|
stdout)
|
||||||
stdout)
|
if match:
|
||||||
if match:
|
nm = tuple([int(e) for e in match.groups()])
|
||||||
## use the previously matched numbers
|
|
||||||
return tuple([int(e) for e in match.groups()])
|
return ip, nm
|
||||||
else:
|
|
||||||
return (0, 0, 0, 0)
|
|
||||||
|
|
||||||
|
|
||||||
def __get_current_gw(self):
|
def __get_current_gw(self):
|
||||||
|
|
Loading…
Reference in a new issue