enablel/disable zapping via config
[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.allowzapping = ConfigYesNo(default = True)
18 config.plugins.Webinterface.includehdd = ConfigYesNo(default = False)
19 config.plugins.Webinterface.autowritetimer = ConfigYesNo(default = False)
20 config.plugins.Webinterface.loadmovielength = ConfigYesNo(default = False)
21 config.plugins.Webinterface.version = ConfigText(__version__) # used to make the versioninfo accessible enigma2-wide, not confgurable in GUI. 
22 config.plugins.Webinterface.interfacecount = ConfigInteger(0)
23 config.plugins.Webinterface.interfaces = ConfigSubList()
24
25
26 def addInterfaceConfig():
27     choices = getCofiguredAndSpecialNetworkinterfaces()
28     i = len(config.plugins.Webinterface.interfaces)
29     config.plugins.Webinterface.interfaces.append(ConfigSubsection())
30     config.plugins.Webinterface.interfaces[i].disabled = ConfigYesNo(default = False)
31     config.plugins.Webinterface.interfaces[i].adress = ConfigSelection(choices,default=choices[0])
32     config.plugins.Webinterface.interfaces[i].port = ConfigInteger(80, (0,65535))
33     config.plugins.Webinterface.interfaces[i].useauth = ConfigYesNo(default = False)
34     config.plugins.Webinterface.interfacecount.value = i+1
35     return i
36
37 def getCofiguredAndSpecialNetworkinterfaces():
38     nw = Network()
39     choices = []
40     choices.append('0.0.0.0')
41     choices.append('127.0.0.1')
42     for adaptername in nw.ifaces:
43         extip = nw.ifaces[adaptername]['ip']
44         if nw.ifaces[adaptername]['up'] is True:
45             extip = "%i.%i.%i.%i"%(extip[0],extip[1],extip[2],extip[3])
46             choices.append(extip)
47     return choices
48
49 if config.plugins.Webinterface.interfacecount.value == 0:
50     # setting default interface
51     # 0.0.0.0:80 auth=False
52     config.plugins.Webinterface.interfaces.append(ConfigSubsection())
53     config.plugins.Webinterface.interfaces[0].disabled = ConfigYesNo(default = False)
54     config.plugins.Webinterface.interfaces[0].adress = ConfigSelection(getCofiguredAndSpecialNetworkinterfaces(),default='0.0.0.0')
55     config.plugins.Webinterface.interfaces[0].port = ConfigInteger(80, (0,65535))
56     config.plugins.Webinterface.interfaces[0].useauth = ConfigYesNo(default = False)
57     config.plugins.Webinterface.interfacecount.value = 1
58     config.plugins.Webinterface.interfacecount.save()
59     config.plugins.Webinterface.interfaces[0].save()
60 else:    
61     for i in range(0, config.plugins.Webinterface.interfacecount.value):
62         addInterfaceConfig()
63