def finish_initializing(self, builder): # pylint: disable=E1002 """Set up the main window""" super(MugshotWindow, self).finish_initializing(builder) self.set_wmclass("Mugshot", "Mugshot") # User Image widgets self.image_button = builder.get_object('image_button') self.user_image = builder.get_object('user_image') self.image_menu = builder.get_object('image_menu') self.image_from_camera = builder.get_object('image_from_camera') self.image_from_stock = builder.get_object('image_from_stock') self.image_from_stock.set_visible( os.path.exists(faces_dir) and len(os.listdir(faces_dir)) > 0) self.menuitem1 = builder.get_object('menuitem1') self.image_remove = builder.get_object('image_remove') if get_has_camera_support(): self.CameraDialog = CameraMugshotDialog self.image_from_camera.set_visible(True) else: self.image_from_camera.set_visible(False) # Entry widgets (chfn) self.first_name_entry = builder.get_object('first_name') self.last_name_entry = builder.get_object('last_name') self.initials_entry = builder.get_object('initials') self.office_phone_entry = builder.get_object('office_phone') self.home_phone_entry = builder.get_object('home_phone') self.email_entry = builder.get_object('email') self.fax_entry = builder.get_object('fax') # Stock photo browser self.stock_browser = builder.get_object('stock_browser') self.iconview = builder.get_object('stock_iconview') # File Chooser Dialog self.chooser = builder.get_object('filechooserdialog') self.crop_center = builder.get_object('crop_center') self.crop_left = builder.get_object('crop_left') self.crop_right = builder.get_object('crop_right') self.file_chooser_preview = builder.get_object('file_chooser_preview') # Add a filter for only image files. image_filter = Gtk.FileFilter() image_filter.set_name('Images') image_filter.add_mime_type('image/*') self.chooser.add_filter(image_filter) self.tmpfile = None self.accounts_service = \ AccountsServiceAdapter.MugshotAccountsServiceAdapter(username) # Users without sudo rights cannot change their name. if not self.accounts_service.available(): self.set_name_editable(SudoDialog.check_dependencies(['chfn'])) self.set_phone_editable(SudoDialog.check_dependencies(['chfn'])) # Populate all of the widgets. self.init_user_details()
def process_terminal_password(self, command, password): """Handle password prompts from the interactive chfn commands.""" # Force the C language for guaranteed english strings in the script. logger.debug('Executing: %s' % command) child = SudoDialog.env_spawn(command, [], 5) child.write_to_stdout = True try: child.expect([".*ssword.*", pexpect.EOF]) child.sendline(password) child.expect([pexpect.EOF]) except pexpect.TIMEOUT: logger.warning('Timeout reached, password was likely incorrect.') child.close(True) return child.exitstatus == 0
def save_chfn_details(self): """Commit changes to chfn-related details. For full name, changes must be performed as root. Other changes are done with the user password. Return TRUE if successful.""" success = True # Get the password for sudo sudo_dialog = SudoDialog.SudoDialog(icon=None, name=_("Mugshot"), retries=3) sudo_dialog.format_primary_text( _("Enter your password to change user " "details.")) sudo_dialog.format_secondary_text( _("This is a security measure to " "prevent unwanted updates\n" "to your personal information.")) response = sudo_dialog.run() sudo_dialog.hide() password = sudo_dialog.get_password() sudo_dialog.destroy() if not password: return (False, response) sudo = which('sudo') chfn = which('chfn') # Get each of the updated values. first_name = get_entry_value(self.first_name_entry) last_name = get_entry_value(self.last_name_entry) full_name = "%s %s" % (first_name, last_name) full_name = full_name.strip() office_phone = get_entry_value(self.office_phone_entry) if office_phone == '': office_phone = 'none' home_phone = get_entry_value(self.home_phone_entry) if home_phone == '': home_phone = 'none' # Full name can only be modified by root. Try using sudo to modify. if not self.accounts_service.available(): if SudoDialog.check_dependencies(['chfn']): logger.debug('Updating Full Name...') command = "%s %s -f \"%s\" %s" % (sudo, chfn, full_name, username) if self.process_terminal_password(command, password): self.first_name = first_name self.last_name = last_name else: success = False logger.debug('Updating Home Phone...') command = "%s -h \"%s\" %s" % (chfn, home_phone, username) if self.process_terminal_password(command, password): self.home_phone = home_phone else: success = False logger.debug('Updating Office Phone...') # chfn 2.29 uses "-p" as parameter for changing the office-phone (LP: #1699285) p_command = "%s -p \"%s\" %s" % (chfn, office_phone, username) # other (newer, older?) use "-w" w_command = "%s -w \"%s\" %s" % (chfn, office_phone, username) if self.process_terminal_password(p_command, password) or \ self.process_terminal_password(w_command, password): self.office_phone = office_phone else: success = False return (success, response)