6
6
# This program is free software: you can redistribute it and/or modify it
7
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
8
# the Free Software Foundation, either version 3 of the License, or
9
9
# (at your option) any later version.
11
11
# This program is distributed in the hope that it will be useful, but
217
215
# Populate all of the widgets.
218
216
self.init_user_details()
218
def set_name_editable(self, editable):
219
"""Set name fields editable."""
220
self.first_name_entry.set_sensitive(editable)
221
self.last_name_entry.set_sensitive(editable)
222
self.initials_entry.set_sensitive(editable)
220
224
def init_user_details(self):
221
225
"""Initialize the user details entries and variables."""
222
226
# Check for .face and set profile image.
248
252
self.updated_image = None
249
253
self.set_user_image(None)
251
# Search /etc/passwd for the current user's details.
252
logger.debug('Getting user details from /etc/passwd')
253
for line in open('/etc/passwd', 'r'):
254
if line.startswith(username + ':'):
255
logger.debug('Found details: %s' % line.strip())
256
details = line.split(':')[4].split(',', 3)
258
while len(details) < 4:
261
# Extract the user details
262
name, office, office_phone, home_phone = details
265
# Expand the user's fullname into first and last.
267
first_name, last_name = name.split(' ', 1)
272
# If the variables are defined as 'none', use blank for cleanliness.
273
if home_phone == 'none':
275
if office_phone == 'none':
279
logger.debug('Getting initials, email, and fax from dconf')
280
initials = self.settings['initials']
281
email = self.settings['email']
282
fax = self.settings['fax']
255
user_details = self.get_user_details()
284
257
# Set the class variables
285
self.first_name = first_name
286
self.last_name = last_name
287
self.initials = initials
288
self.home_phone = home_phone
289
self.office_phone = office_phone
258
self.first_name = user_details['first_name']
259
self.last_name = user_details['last_name']
260
self.initials = user_details['initials']
261
self.home_phone = user_details['home_phone']
262
self.office_phone = user_details['office_phone']
263
email = user_details['email']
264
fax = user_details['fax']
291
266
# Populate the GtkEntries.
292
267
logger.debug('Populating entries')
337
312
logger.debug('Applying changes...')
338
313
if self.get_chfn_details_updated():
339
if not self.save_chfn_details():
314
success, response = self.save_chfn_details()
340
316
# Password was incorrect, complain.
341
primary = _("Authentication Failed")
317
if response in [Gtk.ResponseType.NONE,
318
Gtk.ResponseType.CANCEL,
319
Gtk.ResponseType.DELETE_EVENT]:
320
msg_type = Gtk.MessageType.WARNING
321
primary = _("Authentication cancelled.")
322
elif response == Gtk.ResponseType.REJECT:
323
msg_type = Gtk.MessageType.WARNING
324
primary = _("Authentication failed.")
326
msg_type = Gtk.MessageType.ERROR
327
primary = _("An error occurred when saving changes.")
342
329
secondary = _("User details were not updated.")
343
330
dialog = Gtk.MessageDialog(transient_for=self, flags=0,
345
Gtk.MessageType.WARNING,
331
message_type=msg_type,
346
332
buttons=Gtk.ButtonsType.OK,
348
334
dialog.format_secondary_text(secondary)
458
444
(path,) = result.unpack()
460
446
variant = GLib.Variant('(s)',
461
('org.freedesktop.Accounts.User',)
447
('org.freedesktop.Accounts.User',))
463
448
result = bus.call_sync('org.freedesktop.Accounts',
465
450
'org.freedesktop.DBus.Properties',
580
565
"""Handle password prompts from the interactive chfn commands."""
581
566
# Force the C language for guaranteed english strings in the script.
582
567
logger.debug('Executing: %s' % command)
583
child = pexpect.spawn(command, env={"LANG": "C"})
568
child = SudoDialog.env_spawn(command, 5)
585
569
child.write_to_stdout = True
587
571
child.expect([".*ssword.*", pexpect.EOF])
631
615
home_phone = 'none'
633
617
# Full name can only be modified by root. Try using sudo to modify.
634
if SudoDialog.check_sudo():
618
if SudoDialog.check_dependencies(['chfn']):
635
619
logger.debug('Updating Full Name...')
636
620
command = "%s %s -f \"%s\" %s" % (sudo, chfn, full_name, username)
637
621
if self.process_terminal_password(command, password):
683
667
logger.debug('LibreOffice details do not need to be updated.')
670
def get_user_details(self):
671
"""Use the various methods to get the most up-to-date version of the
673
# Start with LibreOffice, as users may have configured that first.
674
data = self.get_libreoffice_data()
676
# Next is passwd, where we override name values with system values.
677
pwd_data = self.get_passwd_data()
678
data['first_name'] = pwd_data['first_name']
679
data['last_name'] = pwd_data['last_name']
680
data['initials'] = pwd_data['initials']
681
if len(data['home_phone']) == 0:
682
data['home_phone'] = pwd_data['home_phone']
683
if len(data['office_phone']) == 0:
684
data['office_phone'] = pwd_data['office_phone']
686
# Then get data from dconf
687
initials = self.settings['initials']
688
if len(initials) > 0:
689
data['initials'] = initials
690
email = self.settings['email']
691
if len(data['email']) == 0:
692
data['email'] = email
693
if len(data['fax']) == 0:
694
data['fax'] = self.settings['fax']
696
# Return all of the finalized information.
699
def get_passwd_data(self):
700
"""Get user details from passwd"""
701
# Use getent for current user's details.
703
line = subprocess.check_output(['getent', 'passwd', username])
704
if isinstance(line, bytes):
705
line = line.decode('utf-8')
707
logger.debug('Found details: %s' % line.strip())
708
details = line.split(':')[4].split(',', 3)
710
while len(details) < 4:
713
# Extract the user details
714
name, office, office_phone, home_phone = details
715
except subprocess.CalledProcessError:
716
logger.warning("User %s not found in /etc/passwd. "
717
"Mugshot may not function correctly." % username)
722
# Use GLib to get the actual name.
723
name = GLib.get_real_name()
725
# Expand the user's fullname into first, last, and initials.
728
first_name, last_name = name.split(' ', 1)
729
initials += last_name[0]
734
# If the variables are defined as 'none', use blank for cleanliness.
735
if home_phone == 'none':
737
if office_phone == 'none':
741
data = {'first_name': first_name, 'last_name': last_name,
742
'home_phone': home_phone, 'office_phone': office_phone,
743
'initials': initials, 'email': '', 'fax': ''}
686
747
def get_libreoffice_data(self):
687
748
"""Get each of the preferences from the LibreOffice
688
749
registymodifications preferences file.