rewrite of configuration of the interfaces the webif will bind to
[enigma2-plugins.git] / webinterface / src / __init__.py
1 import Plugins.Plugin
2 from Components.config import config
3 from Components.config import ConfigSubsection
4 from Components.config import ConfigSelection
5 from Components.config import ConfigInteger
6 from Components.config import ConfigSubList
7 from Components.config import ConfigSubDict
8 from Components.config import ConfigText
9 from Components.config import configfile
10 from Components.config import ConfigYesNo
11 from Components.Network import Network
12
13 __version__ = "0.99"
14
15 config.plugins.Webinterface = ConfigSubsection()
16 config.plugins.Webinterface.enable = ConfigYesNo(default = True)
17 config.plugins.Webinterface.includehdd = ConfigYesNo(default = False)
18 config.plugins.Webinterface.autowritetimer = ConfigYesNo(default = False)
19 config.plugins.Webinterface.loadmovielength = ConfigYesNo(default = False)
20 config.plugins.Webinterface.version = ConfigText(__version__) # used to make the versioninfo accessible enigma2-wide, not confgurable in GUI. 
21 config.plugins.Webinterface.interfacecount = ConfigInteger(0)
22 config.plugins.Webinterface.interfaces = ConfigSubList()
23
24
25 def addInterfaceConfig():
26     choices = getCofiguredAndSpecialNetworkinterfaces()
27     i = len(config.plugins.Webinterface.interfaces)
28     config.plugins.Webinterface.interfaces.append(ConfigSubsection())
29     config.plugins.Webinterface.interfaces[i].disabled = ConfigYesNo(default = False)
30     config.plugins.Webinterface.interfaces[i].adress = ConfigSelection(choices,default=choices[0])
31     config.plugins.Webinterface.interfaces[i].port = ConfigInteger(80, (0,65535))
32     config.plugins.Webinterface.interfaces[i].useauth = ConfigYesNo(default = False)
33     config.plugins.Webinterface.interfacecount.value = i+1
34     return i
35
36 def getCofiguredAndSpecialNetworkinterfaces():
37     nw = Network()
38     choices = []
39     choices.append('0.0.0.0')
40     choices.append('127.0.0.1')
41     for adaptername in nw.ifaces:
42         extip = nw.ifaces[adaptername]['ip']
43         if nw.ifaces[adaptername]['up'] is True:
44             extip = "%i.%i.%i.%i"%(extip[0],extip[1],extip[2],extip[3])
45             choices.append(extip)
46     return choices
47
48 if config.plugins.Webinterface.interfacecount.value == 0:
49     # setting default interface
50     # 0.0.0.0:80 auth=False
51     config.plugins.Webinterface.interfaces.append(ConfigSubsection())
52     config.plugins.Webinterface.interfaces[0].disabled = ConfigYesNo(default = False)
53     config.plugins.Webinterface.interfaces[0].adress = ConfigSelection(getCofiguredAndSpecialNetworkinterfaces(),default='0.0.0.0')
54     config.plugins.Webinterface.interfaces[0].port = ConfigInteger(80, (0,65535))
55     config.plugins.Webinterface.interfaces[0].useauth = ConfigYesNo(default = False)
56     config.plugins.Webinterface.interfacecount.value = 1
57     config.plugins.Webinterface.interfacecount.save()
58     config.plugins.Webinterface.interfaces[0].save()
59 else:    
60     for i in range(0, config.plugins.Webinterface.interfacecount.value):
61         addInterfaceConfig()
62