2
2
3
3
from Screens .Screen import Screen
4
4
from Screens .MessageBox import MessageBox
5
- from Screens .VirtualKeyBoard import VirtualKeyBoard
5
+ from Screens .ChoiceBox import ChoiceBox
6
+ from Screens .InputBox import InputBox
7
+ from Tools .Log import Log
6
8
7
- from Screens .Setup import SetupSummary
8
- from Components .ConfigList import ConfigList
9
- from Components .config import config , getConfigListEntry , ConfigSelection , ConfigSubsection , ConfigText
10
-
11
- from Components .ActionMap import ActionMap
12
- from Components .Label import Label
13
- from Components .Pixmap import Pixmap
14
- from Components .Sources .StaticText import StaticText
15
- from Components .Sources .List import List
16
9
from Plugins .Plugin import PluginDescriptor
17
- from enigma import getDesktop
18
10
19
11
import string
20
- import sys
21
- import time
22
12
from random import Random
23
13
24
- setpasswd_title = _ ("Change Root Password" )
25
-
26
- sz_w = getDesktop (0 ).size ().width ()
27
-
28
- class ChangePasswdScreen (Screen ):
29
- if sz_w == 1920 :
30
- skin = """
31
- <screen name="ChangePasswdScreen" position="center,center" size="1200,150" title="Change Root Password">
32
- <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="295,70" />
33
- <ePixmap pixmap="skin_default/buttons/green.png" position="305,5" size="295,70" />
34
- <ePixmap pixmap="skin_default/buttons/yellow.png" position="600,5" size="295,70" />
35
- <ePixmap pixmap="skin_default/buttons/blue.png" position="895,5" size="295,70" />
36
- <widget backgroundColor="#9f1313" font="Regular;30" halign="center" position="10,5" render="Label" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="295,70" source="key_red" transparent="1" valign="center" zPosition="1" />
37
- <widget backgroundColor="#1f771f" font="Regular;30" halign="center" position="305,5" render="Label" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="295,70" source="key_green" transparent="1" valign="center" zPosition="1" />
38
- <widget backgroundColor="#a08500" font="Regular;30" halign="center" position="600,5" render="Label" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="295,70" source="key_yellow" transparent="1" valign="center" zPosition="1" />
39
- <widget backgroundColor="#18188b" font="Regular;30" halign="center" position="895,5" render="Label" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="295,70" source="key_blue" transparent="1" valign="center" zPosition="1" />
40
- <eLabel backgroundColor="grey" position="10,80" size="1180,1" />
41
- <widget name="passwd" position="10,90" size="1180,45" />
42
- </screen>"""
43
- else :
44
- skin = """
45
- <screen name="ChangePasswdScreen" position="center,center" size="820,100" title="Change Root Password" >
46
- <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40" alphatest="on" />
47
- <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40" alphatest="on" />
48
- <ePixmap pixmap="skin_default/buttons/yellow.png" position="410,5" size="200,40" alphatest="on" />
49
- <ePixmap pixmap="skin_default/buttons/blue.png" position="610,5" size="200,40" alphatest="on" />
50
- <widget source="key_red" render="Label" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
51
- <widget source="key_green" render="Label" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
52
- <widget source="key_yellow" render="Label" position="410,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
53
- <widget source="key_blue" render="Label" position="610,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
54
- <eLabel position="10,50" size="800,1" backgroundColor="grey" />
55
- <widget name="passwd" position="10,60" size="800,45" scrollbarMode="showOnDemand" />
56
- </screen>"""
57
-
58
- def __init__ (self , session , args = 0 ):
59
- Screen .__init__ (self , session )
60
- self .skin = ChangePasswdScreen .skin
61
-
62
- self .user = "root"
63
- self .output_line = ""
64
- self .list = []
65
14
66
- self .onShown .append (self .setWindowTitle )
67
-
68
- self ["passwd" ] = ConfigList (self .list )
69
- self ["key_red" ] = StaticText (_ ("Password" )+ " " + _ ("delete" ).lower ())
70
- self ["key_green" ] = StaticText (_ ("Set Password" ))
71
- self ["key_yellow" ] = StaticText (_ ("new Random" ))
72
- self ["key_blue" ] = StaticText (_ ("virt. Keyboard" ))
73
-
74
- self ["actions" ] = ActionMap (["OkCancelActions" , "ColorActions" ],
75
- {
76
- "exit" : self .close ,
77
- "red" : self .emptyPasswd ,
78
- "green" : self .SetPasswd ,
79
- "yellow" : self .newRandom ,
80
- "blue" : self .bluePressed ,
81
- "cancel" : self .close
82
- }, - 1 )
83
-
84
- self .buildList (self .GeneratePassword ())
85
-
86
- def setWindowTitle (self ):
87
- if config .usage .setup_level .value != "expert" :
88
- p = open ("/etc/shadow" ,"r" )
89
- rp = p .readline ()
90
- p .close ()
91
- if not rp .startswith ("root::" ): # root password already set but not expert ...
92
- message = _ ("Unable to change/reset password for %s user" ) % self .user
93
- type = MessageBox .TYPE_ERROR
94
- self .session .open (MessageBox , message , type )
95
- self .close ()
15
+ class ChangePasswordScreen (ChoiceBox ):
16
+ WINDOW_TITLE = _ ("Change Password" )
17
+ KEY_SET = "set"
18
+ KEY_RANDOM = "random"
19
+ KEY_LOCK = "lock"
20
+ KEY_REMOVE = "remove"
21
+
22
+ def __init__ (self , session , user = "root" ):
23
+ options = [
24
+ (_ ("Enter a new password" ), self .KEY_SET ),
25
+ (_ ("Generate a random password" ), self .KEY_RANDOM ),
26
+ (_ ("Disable password-based login" ), self .KEY_LOCK ),
27
+ (_ ("Remove password protection (DANGEROUS!)" ), self .KEY_REMOVE ),
28
+ ]
29
+ ChoiceBox .__init__ (self , session , title = _ ("If you want to login to your Dreambox using SSH, FTP or a remote web browser, you need to configure a password first.\n The username will be '%s'." ) % (user ), list = options , windowTitle = ChangePasswordScreen .WINDOW_TITLE )
30
+ self ._user = user
31
+ self ._password = ""
32
+ self ._wasLocked = False
33
+ self ._container = eConsoleAppContainer ()
34
+ self .__appClosed_conn = self ._container .appClosed .connect (self ._commandFinished )
35
+
36
+ def go (self ):
37
+ selected = self ["list" ].l .getCurrentSelection ()
38
+ Log .w (selected )
39
+ selected = selected and selected [0 ]
40
+ if not selected :
41
+ return
42
+ selected = selected [1 ]
43
+ if selected == self .KEY_SET :
44
+ self .session .openWithCallback (self ._onPasswordInputFinished , InputBox , title = _ ("Please enter a new password for %s" ) % (self ._user ), windowTitle = _ ("New Password" ), text = self ._getRandom ())
45
+ return
46
+ elif selected == self .KEY_RANDOM :
47
+ self ._apply (self ._getRandom ())
48
+ elif selected == self .KEY_LOCK :
49
+ self ._lock ()
50
+ elif selected == self .KEY_REMOVE :
51
+ self ._apply ("" )
52
+
53
+ def _apply (self , password ):
54
+ Log .w ("Changing password for %s" % (self ._user ,))
55
+ self ._password = password
56
+ if password :
57
+ self ._container .execute ("echo \" %s:%s\" | chpasswd" % (self ._user , password ))
96
58
else :
97
- self .setTitle ( setpasswd_title )
59
+ self ._container . execute ( "passwd -d %s" % self . _user )
98
60
99
- def newRandom (self ):
100
- self .buildList (self .GeneratePassword ())
101
-
102
- def buildList (self , password ):
103
- self .password = password
104
- self .list = []
105
- self .list .append (getConfigListEntry (_ ('Enter new Password' ), ConfigText (default = self .password , fixed_size = False )))
106
- self ["passwd" ].setList (self .list )
107
-
108
- def GeneratePassword (self ):
61
+ def _getRandom (self ):
109
62
passwdChars = string .letters + string .digits
110
- passwdLength = 8
63
+ passwdLength = 10
111
64
return '' .join (Random ().sample (passwdChars , passwdLength ))
112
65
113
- def SetPasswd (self ):
114
- print "Changing password for %s to %s " % (self .user , self . password )
115
- self .container = eConsoleAppContainer ()
116
- self .appClosed_conn = self . container . appClosed . connect ( self . runFinished )
117
- self .container .execute ("echo \" %s:%s \" | chpasswd" % ( self .user , self . password ) )
66
+ def _lock (self ):
67
+ Log . w ( "Removing password for %s" % (self ._user ))
68
+ self ._password = ""
69
+ self ._wasLocked = True
70
+ self ._container .execute ("passwd -l %s" % self ._user )
118
71
119
- def emptyPasswd (self ):
120
- print "Emptying password for %s" % (self .user )
121
- self .password = _ ("empty" )
122
- self .container = eConsoleAppContainer ()
123
- self .appClosed_conn = self .container .appClosed .connect (self .runFinished )
124
- self .container .execute ("passwd -d %s" % self .user )
125
-
126
- def runFinished (self ,retval ):
72
+ def _commandFinished (self ,retval ):
127
73
if retval == 0 :
128
- message = _ ("Sucessfully changed password for %s user to: %s" ) % (self .user , self .password )
129
74
type = MessageBox .TYPE_INFO
75
+ windowTitle = _ ("Password changed" )
76
+ if self ._password :
77
+ message = _ ("The password for '%s' was successfully changed to:\n \n %s" ) % (self ._user , self ._password )
78
+ else :
79
+ type = MessageBox .TYPE_WARNING
80
+ if self ._wasLocked :
81
+ windowTitle = _ ("Password locked" )
82
+ message = _ ("The password for '%s' is now disabled!" ) % (self ._user ,)
83
+ else :
84
+ windowTitle = _ ("Password removed" )
85
+ message = _ ("The password protection for '%s' was removed!" ) % (self ._user ,)
130
86
else :
131
- message = _ ("Unable to change/reset password for %s user" ) % self .user
87
+ windowTitle = _ ("Password change failed!" )
88
+ message = _ ("Unable to set new password for '%s'" ) % self ._user
132
89
type = MessageBox .TYPE_ERROR
133
- self .session .open (MessageBox , message , type )
134
- del self .container
90
+ self .session .open (MessageBox , message , type , windowTitle = windowTitle )
135
91
self .close ()
136
-
137
- def bluePressed (self ):
138
- self .session .openWithCallback (self .VirtualKeyBoardTextEntry , VirtualKeyBoard , title = (_ ("Enter your password here:" )), text = self .password )
139
-
140
- def VirtualKeyBoardTextEntry (self , callback = None ):
141
- if callback is not None and len (callback ):
142
- self .buildList (callback )
92
+
93
+ def _onPasswordInputFinished (self , password ):
94
+ if password :
95
+ self ._apply (password )
143
96
144
97
def startChange (menuid ):
145
98
if menuid != "system" :
146
99
return [ ]
147
- return [(setpasswd_title , main , "change_root_passwd" , 50 )]
100
+ return [(_ ( "Password" ) , main , "change_root_passwd" , 50 )]
148
101
149
102
def main (session , ** kwargs ):
150
- session .open (ChangePasswdScreen )
103
+ session .open (ChangePasswordScreen )
151
104
152
105
def Plugins (** kwargs ):
153
106
return PluginDescriptor (
154
- name = setpasswd_title ,
107
+ name = ChangePasswordScreen . WINDOW_TITLE ,
155
108
description = _ ("Change or reset the root password of your dreambox" ),
156
109
where = [PluginDescriptor .WHERE_MENU ], fnc = startChange )
157
-
0 commit comments