removed rfmod
[enigma2.git] / lib / python / Components / Network.py
1 from config import *
2
3 import os
4
5 class Network:
6         def __init__(self):
7                 pass
8                 
9         def setDHCP(self, useDHCP):
10                 if (useDHCP):
11                         print "Using DHCP"
12                         config.network.ip.enabled = False
13                         config.network.gateway.enabled = False
14                         config.network.dns.enabled = False
15                 else:
16                         print "NOT using DHCP"
17                         config.network.ip.enabled = True
18                         config.network.gateway.enabled = True
19                         config.network.dns.enabled = True
20                                         
21         def setIPAddress(self, ip):
22                 print ip
23                 os.system("echo ifconfig eth0 %d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3]))
24
25         def setIPGateway(self, ip):
26                 os.system("echo route add default gw %d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3]))
27
28         def setIPNameserver(self, ip):
29                 resolvconf = file('/etc/resolv.conf', 'w')
30                 resolvconf.write("nameserver %d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3]))
31                 resolvconf.close()
32                 
33         def setMACAddress(self, mac):
34                 os.system("echo ifconfig eth0 ether %02x:%02x:%02x:%02x:%02x:%02x" % (mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]))
35                 
36 def InitNetwork():
37         config.network = ConfigSubsection()
38         config.network.dhcp = configElement("config.network.dhcp", configBoolean, 0, ("no", "yes"))
39         config.network.ip = configElement("config.network.ip", configSequence, [192,168,1,45], (("."), 3))
40         config.network.gateway = configElement("config.network.gateway", configSequence, [192,168,1,3], (("."), 3))
41         config.network.dns = configElement("config.network.dns", configSequence, [192,168,1,3], (("."), 3))
42         config.network.mac = configElement("config.network.mac", configSequence, [00,11,22,33,44,55], ((":"), 2))
43
44         iNetwork = Network()
45
46         def setDHCP(configElement):
47                 iNetwork.setDHCP(configElement.value)
48
49         def setIPAddress(configElement):
50                 iNetwork.setIPAddress(configElement.value)
51
52         def setIPGateway(configElement):
53                 iNetwork.setIPGateway(configElement.value)
54                 
55         def setIPNameserver(configElement):
56                 iNetwork.setIPNameserver(configElement.value)
57
58         def setMACAddress(configElement):
59                 iNetwork.setMACAddress(configElement.value)
60
61         # this will call the "setup-val" initial
62         config.network.dhcp.addNotifier(setDHCP)
63         config.network.ip.addNotifier(setIPAddress)
64         config.network.gateway.addNotifier(setIPGateway)
65         config.network.dns.addNotifier(setIPNameserver)
66         config.network.mac.addNotifier(setMACAddress)