webinterface: improve security features and defaults
[enigma2-plugins.git] / webinterface / src / WebIfConfig.py
1 Version = '$Header$';
2
3 from __init__ import _
4
5 from enigma import eListboxPythonMultiContent, gFont
6 from Screens.Screen import Screen
7 from Screens.MessageBox import MessageBox
8
9 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigInteger, ConfigYesNo, ConfigText, ConfigSelection
10 from Components.ConfigList import ConfigListScreen
11 from Components.Sources.StaticText import StaticText
12 from Components.MenuList import MenuList
13 from Components.MultiContent import MultiContentEntryText
14
15 from Components.ActionMap import ActionMap
16
17 class WebIfConfigScreen(ConfigListScreen, Screen):
18         skin = """
19                 <screen name="WebIfConfigScreen" position="center,center" size="560,400" title="Webinterface: Main Setup">
20                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
21                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
22                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
23                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
24                         <widget name="config" position="5,50" size="550,360" scrollbarMode="showOnDemand" zPosition="1"/>
25                 </screen>"""
26
27         def __init__(self, session, args=0):
28                 Screen.__init__(self, session)
29                 ConfigListScreen.__init__(self, [])
30                 self.createSetup()
31
32                 self["key_red"] = StaticText(_("Cancel"))
33                 self["key_green"] = StaticText(_("OK"))
34                 # SKIN Compat HACK!
35                 self["key_yellow"] = StaticText("")
36                 # EO SKIN Compat HACK!
37                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
38                 {
39                         "red": self.cancel,
40                         "green": self.save,
41                         "save": self.save,
42                         "cancel": self.cancel,
43                         "ok": self.save,
44                 }, -2)
45
46                 self.onLayoutFinish.append(self.layoutFinished)
47
48         def keyLeft(self):
49                 ConfigListScreen.keyLeft(self)
50                 self.createSetup()
51
52         def keyRight(self):
53                 ConfigListScreen.keyRight(self)
54                 self.createSetup()
55
56         def createSetup(self):
57                 list = [ getConfigListEntry(_("Start Webinterface"), config.plugins.Webinterface.enabled), ]
58
59                 if config.plugins.Webinterface.enabled.value:
60                         list.extend( [
61                                 getConfigListEntry(_("General")),
62                                 getConfigListEntry(_("Show Setup in Extensions menu"), config.plugins.Webinterface.show_in_extensionsmenu),
63                                 getConfigListEntry(_("Enable /media"), config.plugins.Webinterface.includemedia),
64                                 getConfigListEntry(_("Allow zapping via Webinterface"), config.plugins.Webinterface.allowzapping),
65                                 getConfigListEntry(_("Autowrite timer"), config.plugins.Webinterface.autowritetimer),
66                                 getConfigListEntry(_("Load movie-length"), config.plugins.Webinterface.loadmovielength),
67                                 getConfigListEntry(_("HTTP")),
68                                 getConfigListEntry(_("Enable HTTP Access"), config.plugins.Webinterface.http.enabled)
69                         ])
70
71                         if config.plugins.Webinterface.http.enabled.value == True:
72                                 list.extend([
73                                         getConfigListEntry(_("HTTP Port"), config.plugins.Webinterface.http.port),
74                                         getConfigListEntry(_("Enable HTTP Authentication"), config.plugins.Webinterface.http.auth)
75                                 ])
76
77                         list.extend([
78                                 getConfigListEntry(_("HTTPS")),
79                                 getConfigListEntry(_("Enable HTTPS Access"), config.plugins.Webinterface.https.enabled)
80                         ])
81                         if config.plugins.Webinterface.https.enabled.value == True:
82                                 list.extend([
83                                         getConfigListEntry(_("HTTPS Port"), config.plugins.Webinterface.https.port),
84                                         getConfigListEntry(_("Enable HTTPS Authentication"), config.plugins.Webinterface.https.auth)
85                                 ])
86
87                         list.extend([
88                                 getConfigListEntry(_("Additional Security")),
89                                 getConfigListEntry(_("Enable Streaming Authentication"), config.plugins.Webinterface.streamauth),
90                                 getConfigListEntry(_("Authentication for local clients"), config.plugins.Webinterface.localauth),
91                                 getConfigListEntry(_("Simple Anti-Hijack Measures (may break clients)"), config.plugins.Webinterface.anti_hijack),
92                                 getConfigListEntry(_("Token-based security (may break clients)"), config.plugins.Webinterface.extended_security),
93                         ])
94                 self["config"].list = list
95                 self["config"].l.setList(list)
96
97         def layoutFinished(self):
98                 self.setTitle(_("Webinterface: Main Setup"))
99
100         def save(self):
101                 print "[Webinterface] Saving Configuration"
102                 for x in self["config"].list:
103                         if len(x) > 1:
104                                 x[1].save()
105                 self.close(True, self.session)
106
107         def cancel(self):
108                 print "[Webinterface] Cancel setup changes"
109                 for x in self["config"].list:
110                         if len(x) > 1:
111                                 x[1].cancel()
112                 self.close(False, self.session)
113
114