Revision 97986aa6
Added by David Sorber over 7 years ago
| software/pwmgr/pwmgr.py | ||
|---|---|---|
|
ENC_TMP_FILE_PATH = '/home/dsorber/Documents/chicken_soup.enc.tmp'
|
||
|
KEY_FILE_PATH = '/mnt/pw_ramdisk/.f05d11ef-000c-45c2-ae14-56b56c23e1c5'
|
||
|
|
||
|
VERSION = '0.0.6'
|
||
|
VERSION = '0.0.7'
|
||
|
|
||
|
class SearchDialog(Gtk.Dialog):
|
||
|
|
||
| ... | ... | |
|
if (response == Gtk.ResponseType.OK) and (text != ''):
|
||
|
return text
|
||
|
else:
|
||
|
return None
|
||
|
return None
|
||
|
|
||
|
def yield_gtk():
|
||
|
while Gtk.events_pending():
|
||
|
Gtk.main_iteration()
|
||
|
|
||
|
class ProgressBarWindow(Gtk.Window):
|
||
|
|
||
| ... | ... | |
|
self.pwd_file_fd = None
|
||
|
self.original_hash = None
|
||
|
self.pbar_win = None
|
||
|
self.should_quit = False
|
||
|
|
||
|
# Open password prompt window at start
|
||
|
GLib.idle_add(self.open_pwd_file, self.grid)
|
||
|
|
||
|
|
||
|
def async_quit(self):
|
||
|
if self.should_quit:
|
||
|
if self.pbar_win is not None:
|
||
|
self.pbar_win.destroy()
|
||
|
Gtk.main_quit()
|
||
|
print('REAL QUIT')
|
||
|
return True
|
||
|
self.open_pwd_file(self.grid)
|
||
|
yield_gtk()
|
||
|
|
||
|
def _key_press_event(self, widget, event):
|
||
|
keyval = event.keyval
|
||
| ... | ... | |
|
"""
|
||
|
Clean up ramdisk by overwriting, then unmount
|
||
|
"""
|
||
|
GLib.idle_add(self.pbar_win.update_text, 'Starting ramdisk cleanup')
|
||
|
|
||
|
self.pbar_win.update_text('Starting ramdisk cleanup')
|
||
|
yield_gtk()
|
||
|
|
||
|
# Build shell commands to write random and zero data (respectively) to
|
||
|
# the file
|
||
|
rand_write_cmd = 'dd if=/dev/urandom of={:s} bs=16M count=1 status=none'
|
||
|
rand_write_cmd = rand_write_cmd.format(os.path.join(MOUNT_PATH, 'data'))
|
||
|
|
||
| ... | ... | |
|
for ctr in range(10):
|
||
|
print(ctr)
|
||
|
message = 'Overwrite {:d} of 10'.format(ctr + 1)
|
||
|
GLib.idle_add(self.pbar_win.update_text, message)
|
||
|
self.pbar_win.update_text(message)
|
||
|
yield_gtk()
|
||
|
|
||
|
# Do one pass, write random data then write zeros
|
||
|
subprocess.call(rand_write_cmd, shell=True, timeout=5)
|
||
|
self._remove_mount_files()
|
||
|
subprocess.call(zero_write_cmd, shell=True, timeout=5)
|
||
|
self._remove_mount_files()
|
||
|
|
||
|
GLib.idle_add(self.pbar_win.update_complete, (ctr + 1) / 10)
|
||
|
# Update progress bar
|
||
|
self.pbar_win.update_complete((ctr + 1) / 10)
|
||
|
yield_gtk()
|
||
|
|
||
|
self.pbar_win.update_text('Unmounting ramdisk')
|
||
|
yield_gtk()
|
||
|
|
||
|
GLib.idle_add(self.pbar_win.update_text, 'Unmounting ramdisk')
|
||
|
# Unmount the ramdisk
|
||
|
umount_cmd = 'umount {:s}'.format(MOUNT_PATH)
|
||
|
subprocess.call(umount_cmd, shell=True, timeout=5)
|
||
|
GLib.idle_add(self.pbar_win.update_text, 'Complete')
|
||
|
|
||
|
self.should_quit = True
|
||
|
print('SET should quit')
|
||
|
|
||
|
self.pbar_win.update_text('Complete')
|
||
|
yield_gtk()
|
||
|
|
||
|
def close_pwd_file(self, widget, other):
|
||
|
"""
|
||
| ... | ... | |
|
self.textview.set_cursor_visible(False)
|
||
|
|
||
|
if self.mounted:
|
||
|
# Start async polling of the quit flag
|
||
|
GLib.timeout_add(500, self.async_quit)
|
||
|
|
||
|
# Create the progress window
|
||
|
self.pbar_win = ProgressBarWindow(self, 'Closing...')
|
||
|
self.pbar_win.show_all()
|
||
|
yield_gtk()
|
||
|
|
||
|
# Start the work thread that does the cleanup
|
||
|
thread = threading.Thread(target=self.do_mount_cleanup)
|
||
|
thread.start()
|
||
|
else:
|
||
|
Gtk.main_quit()
|
||
|
|
||
|
self.do_mount_cleanup()
|
||
|
|
||
|
# Quit GTK app
|
||
|
Gtk.main_quit()
|
||
|
print('CLOSE')
|
||
|
|
||
|
def on_clear_clicked(self, widget):
|
||
Remove instances of Gtk.idle_add() in favor of a trick I discovered for
updating the UI inline.