5 from Components.ActionMap import ActionMap
6 from Components.config import config, ConfigText, ConfigSubsection, getConfigListEntry
7 from Components.ConfigList import ConfigListScreen
8 from Components.ScrollLabel import ScrollLabel
9 from Plugins.Plugin import PluginDescriptor
10 from Screens.MessageBox import MessageBox
11 from Screens.Screen import Screen
12 from telnetlib import Telnet
14 ############################################
16 config.plugins.PasswordChanger = ConfigSubsection()
17 config.plugins.PasswordChanger.old_password = ConfigText(default="", fixed_size=False)
18 config.plugins.PasswordChanger.new_password = ConfigText(default="", fixed_size=False)
20 ############################################
22 class PasswordChanger(ConfigListScreen, Screen):
24 <screen position="150,265" size="420,70" title="Password Changer" >
25 <widget name="config" position="0,0" size="420,70" scrollbarMode="showOnDemand" />
28 def __init__(self, session, args=None):
29 Screen.__init__(self, session)
30 self.session = session
32 ConfigListScreen.__init__(self, [
33 getConfigListEntry(_("Old password:"), config.plugins.PasswordChanger.old_password),
34 getConfigListEntry(_("New password:"), config.plugins.PasswordChanger.new_password)])
36 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.changePassword, "cancel": self.exit}, -2)
38 def changePassword(self):
39 old_pass = config.plugins.PasswordChanger.old_password.value
40 new_pass = config.plugins.PasswordChanger.new_password.value
42 if len(new_pass) > 4 and len(new_pass) < 9:
43 self.session.open(PasswordChangerConsole, old_pass, new_pass)
45 self.session.open(MessageBox, _("Incorrect new password!\nMinimum length: 5\nMaximum length: 8"), MessageBox.TYPE_ERROR)
48 for x in self["config"].list:
53 ############################################
55 class PasswordChangerConsole(Screen):
57 <screen position="100,100" size="520,400" title="Password Changer" >
58 <widget name="label" position="0,0" size="520,400" font="Regular;20" />
61 def __init__(self, session, old_pass, new_pass):
62 Screen.__init__(self, session)
65 self.old_pass = old_pass
66 self.new_pass = new_pass
70 self["label"] = ScrollLabel("")
72 self["actions"] = ActionMap(["WizardActions"],
76 "up": self["label"].pageUp,
77 "down": self["label"].pageDown,
78 "left": self["label"].pageUp,
79 "right": self["label"].pageDown
82 self.onLayoutFinish.append(self.run)
86 self.sendMessage("exit")
89 def sendMessage(self, message):
90 if self.t is not None:
91 self.t.write(message + "\n")
92 r = self.t.read_until("UNKNOWN", self.timeout)
102 self.t = Telnet("localhost")
104 self.log = self.t.read_until("login:", self.timeout)
105 if self.log.__contains__("login:"):
106 r = self.sendMessage("root")
107 if r.__contains__("~#"):
110 elif r.__contains__("Password:"):
111 r = self.sendMessage(self.old_pass)
112 if r.__contains__("~#"):
118 self.changePassword()
120 self.log += _("Could not log in!")
121 self["label"].setText(self.log)
124 def changePassword(self):
126 r = self.sendMessage("passwd")
127 if r.__contains__("Enter new password:"):
128 r = self.sendMessage(self.new_pass)
130 if r.__contains__("Re-enter new password:"):
131 r = self.sendMessage(self.new_pass)
133 self.log += _("Error while setting new password!")
135 self["label"].setText(self.log)
138 ############################################
140 def main(session, **kwargs):
141 session.open(PasswordChanger)
143 ############################################
145 def Plugins(**kwargs):
146 return PluginDescriptor(name=_("Password Changer..."), description="Change your ftp and telnet password", where=PluginDescriptor.WHERE_PLUGINMENU, fnc=main)