small fixes (this is still not in any productive use!)
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / Network.py
1 from Components.Sources.Source import Source
2 from Components.Network import iNetwork
3
4 class Interface:
5         def __init__(self, name):
6                 self.name = name
7                 self.mac = None
8                 self.dhcp = None
9                 self.ip = None
10                 self.netmask = None
11                 self.gateway = None
12
13 class Network(Source):
14         LAN = 0
15         WLAN = 1
16         
17         def __init__(self, device = LAN):
18                 Source.__init__(self)
19                 if device is self.LAN:
20                         self.iface = "eth0"
21                 elif device is self.WLAN:
22                         self.iface = "ath0"
23                         
24
25         def ConvertIP(self, list):
26                 if(len(list) == 4):
27                         retstr = "%s.%s.%s.%s" %(list[0], list[1], list[2], list[3])
28                 else:
29                         retstr = "0.0.0.0"
30                 return retstr
31
32                 
33         def getInterface(self):
34                 iface = Interface(self.iface)
35                 iface.mac =  iNetwork.getAdapterAttribute(self.iface, "mac")
36                 iface.dhcp = iNetwork.getAdapterAttribute(self.iface, "dhcp")
37                 iface.ip = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "ip"))
38                 iface.netmask = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "netmask"))
39                 iface.gateway = self.ConvertIP(iNetwork.getAdapterAttribute(self.iface, "gateway"))
40                 
41                 return iface
42         
43         interface = property(getInterface)
44         
45         def getList(self):
46                 ifaces = []
47                 for ifname in iNetwork.getConfiguredAdapters():
48                         iface = [
49                                         ifname,
50                                         iNetwork.getAdapterAttribute(ifname, "mac"),
51                                         iNetwork.getAdapterAttribute(ifname, "dhcp"),
52                                         self.ConvertIP(iNetwork.getAdapterAttribute(ifname, "ip")),
53                                         self.ConvertIP(iNetwork.getAdapterAttribute(ifname, "netmask")),
54                                         self.ConvertIP(iNetwork.getAdapterAttribute(ifname, "gateway"))
55                                 ]                       
56                         ifaces.append(iface)
57                 
58                 return ifaces
59
60                 
61         list = property(getList)
62         
63         lut = { 
64                         "Name": 0,
65                         "Mac" : 1,
66                         "Dhcp" : 2,
67                         "Ip" : 3,
68                         "Gateway" : 4,
69                         "Netmask" : 5,
70                    }
71         
72         
73         def destroy(self):
74                 Source.destroy(self)