1 from enigma import eConsoleAppContainer
3 from Screens.Screen import Screen
4 from Screens.MessageBox import MessageBox
6 from Screens.Setup import SetupSummary
7 from Components.ConfigList import ConfigList
8 from Components.config import config, getConfigListEntry, ConfigSelection, ConfigSubsection, ConfigText
10 from Components.ActionMap import ActionMap
11 from Components.Label import Label
12 from Components.Pixmap import Pixmap
13 from Components.Sources.StaticText import StaticText
14 from Components.Sources.List import List
15 from Plugins.Plugin import PluginDescriptor
20 from random import Random
22 title=_("Change Root Password")
24 class ChangePasswdScreen(Screen):
26 <screen position="110,145" size="490,260" title="%s" >
27 <widget name="passwd" position="10,10" size="470,200" scrollbarMode="showOnDemand" />
28 <ePixmap pixmap="skin_default/div-h.png" position="10,205" size="470,2" transparent="1" alphatest="on" />
29 <ePixmap pixmap="skin_default/buttons/red.png" position="10,210" size="150,40" alphatest="on" />
30 <ePixmap pixmap="skin_default/buttons/green.png" position="170,210" size="150,40" alphatest="on" />
31 <ePixmap pixmap="skin_default/buttons/yellow.png" position="330,210" size="150,40" alphatest="on" />
32 <widget source="key_red" render="Label" position="10,210" zPosition="1" size="150,40" font="Regular;19" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
33 <widget source="key_green" render="Label" position="170,210" zPosition="1" size="150,40" font="Regular;19" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
34 <widget source="key_yellow" render="Label" position="330,210" zPosition="1" size="150,40" font="Regular;19" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
35 </screen>""" % _("Change Root Password")
37 def __init__(self, session, args = 0):
38 Screen.__init__(self, session)
39 self.skin = ChangePasswdScreen.skin
44 self.password=self.GeneratePassword()
46 self.list.append(getConfigListEntry(_('Enter new Password'), ConfigText(default = self.password, fixed_size = False)))
48 self["passwd"] = ConfigList(self.list)
49 self["key_red"] = StaticText(_("Cancel"))
50 self["key_green"] = StaticText(_("Set Password"))
51 self["key_yellow"] = StaticText(_("new Random"))
53 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
55 "green": self.SetPasswd,
57 "yellow": self.buildList,
62 self.password=self.GeneratePassword()
64 self.list.append(getConfigListEntry(_('Enter new Password'), ConfigText(default = self.password, fixed_size = False)))
65 self["passwd"].setList(self.list)
67 def GeneratePassword(self):
68 passwdChars = string.letters + string.digits
69 # passwdChars = string.letters + string.digits + '~!@#$%^&*-_=+?' # use for more security :)
71 return ''.join(Random().sample(passwdChars, passwdLength))
74 print "Changing password for %s to %s" % (self.user,self.password)
75 self.container = eConsoleAppContainer()
76 self.container.appClosed.append(self.runFinished)
77 self.container.dataAvail.append(self.dataAvail)
78 retval = self.container.execute("passwd %s" % self.user)
80 self.session.open(MessageBox, _("Sucessfully changed password for root user to:\n%s " % self.password), MessageBox.TYPE_INFO)
82 self.session.open(MessageBox, _("Unable to change/reset password for root user"), MessageBox.TYPE_ERROR)
84 def dataAvail(self,data):
85 self.output_line += data
87 i = self.output_line.find('\n')
90 self.processOutputLine(self.output_line[:i+1])
91 self.output_line = self.output_line[i+1:]
93 def processOutputLine(self,line):
94 if line.find('password: '):
95 self.container.write("%s\n"%self.password)
97 def runFinished(self,retval):
98 del self.container.dataAvail[:]
99 del self.container.appClosed[:]
103 def startChange(menuid):
104 if menuid != "system":
106 return [(title, main, "change_root_passwd", 50)]
108 def main(session, **kwargs):
109 session.open(ChangePasswdScreen)
111 def Plugins(**kwargs):
112 return PluginDescriptor(
114 description=_("Change or reset the root password of your dreambox"),
115 where = [PluginDescriptor.WHERE_MENU], fnc = startChange)