small fixes (this is still not in any productive use!)
authorStephan Reichholf <sreichholf@users.schwerkraft.elitedvb.net>
Fri, 27 Feb 2009 16:48:17 +0000 (16:48 +0000)
committerStephan Reichholf <sreichholf@users.schwerkraft.elitedvb.net>
Fri, 27 Feb 2009 16:48:17 +0000 (16:48 +0000)
webinterface/src/WebComponents/Converter/NetworkInfo.py
webinterface/src/WebComponents/Sources/Network.py

index 6396312..82245fd 100644 (file)
@@ -2,27 +2,32 @@ from Components.Converter.Converter import Converter
 from Components.Element import cached
 
 class NetworkInfo(Converter, object):
-       MAC = 0
-       DHCP = 1
-       IP = 2
-       GATEWAY = 3
-       NETMASK = 4
-
+       NAME = 0
+       MAC = 1
+       DHCP = 2
+       IP = 3
+       GATEWAY = 4
+       NETMASK = 5
+       
+       
        def __init__(self, type):
                Converter.__init__(self, type)
                self.type = {
+                                        "Name" : self.NAME,                             
                                         "Mac" : self.MAC,
                                         "Dhcp" : self.DHCP,
                                         "Ip" : self.IP,
                                         "Gateway" : self.GATEWAY,
-                                        "Netmask" : self.NETMASK,
+                                        "Netmask" : self.NETMASK,                                       
                                         }[type]
-
+       
        @cached
        def getText(self):
                iface = self.source.interface
-
-               if self.type is self.MAC:
+               
+               if self.type is self.NAME:
+                       return iface.name               
+               elif self.type is self.MAC:
                        return iface.mac
                elif self.type is self.DHCP:
                        return iface.dhcp
@@ -34,6 +39,6 @@ class NetworkInfo(Converter, object):
                        return iface.netmask
                else:
                        return _("N/A")
-
+       
        text = property(getText)
-
+       
\ No newline at end of file
index 08fbbea..2abb356 100644 (file)
@@ -1,36 +1,74 @@
 from Components.Sources.Source import Source
 from Components.Network import iNetwork
-#from Components.Element import cached
+
+class Interface:
+       def __init__(self, name):
+               self.name = name
+               self.mac = None
+               self.dhcp = None
+               self.ip = None
+               self.netmask = None
+               self.gateway = None
 
 class Network(Source):
        LAN = 0
        WLAN = 1
-
+       
        def __init__(self, device = LAN):
                Source.__init__(self)
                if device is self.LAN:
                        self.iface = "eth0"
                elif device is self.WLAN:
                        self.iface = "ath0"
+                       
 
-                       #Get Network Info
        def ConvertIP(self, list):
                if(len(list) == 4):
                        retstr = "%s.%s.%s.%s" %(list[0], list[1], list[2], list[3])
                else:
                        retstr = "0.0.0.0"
                return retstr
-#      @cached
-       def getInterface(self):
-               self.mac = iNetwork.getAdapterAttribute(self.iface, "mac")
-               self.dhcp = iNetwork.getAdapterAttribute(self.iface, "dhcp")
-               self.ip = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "ip"))
-               self.netmask = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "netmask"))
-               self.gateway = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "gateway"))
-
-               return self
 
+               
+       def getInterface(self):
+               iface = Interface(self.iface)
+               iface.mac =  iNetwork.getAdapterAttribute(self.iface, "mac")
+               iface.dhcp = iNetwork.getAdapterAttribute(self.iface, "dhcp")
+               iface.ip = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "ip"))
+               iface.netmask = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "netmask"))
+               iface.gateway = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "gateway"))
+               
+               return iface
+       
        interface = property(getInterface)
+       
+       def getList(self):
+               ifaces = []
+               for ifname in iNetwork.getConfiguredAdapters():
+                       iface = [
+                                       ifname,
+                                       iNetwork.getAdapterAttribute(ifname, "mac"),
+                                       iNetwork.getAdapterAttribute(ifname, "dhcp"),
+                                       self.ConvertIP(iNetwork.getAdapterAttribute(ifname, "ip")),
+                                       self.ConvertIP(iNetwork.getAdapterAttribute(ifname, "netmask")),
+                                       self.ConvertIP(iNetwork.getAdapterAttribute(ifname, "gateway"))
+                               ]                       
+                       ifaces.append(iface)
+               
+               return ifaces
 
+               
+       list = property(getList)
+       
+       lut = { 
+                       "Name": 0,
+                       "Mac" : 1,
+                       "Dhcp" : 2,
+                       "Ip" : 3,
+                       "Gateway" : 4,
+                       "Netmask" : 5,
+                  }
+       
+       
        def destroy(self):
-               Source.destroy(self)
+               Source.destroy(self)
\ No newline at end of file