Read only working
This commit is contained in:
parent
114e3b143b
commit
f801ef1915
1 changed files with 104 additions and 20 deletions
124
src/passui
124
src/passui
|
@ -2,8 +2,12 @@
|
||||||
"""
|
"""
|
||||||
A mobile first interface for the standard unix password manager written in python
|
A mobile first interface for the standard unix password manager written in python
|
||||||
"""
|
"""
|
||||||
import wx
|
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import wx
|
||||||
|
import wx.lib.scrolledpanel as scrolled
|
||||||
|
|
||||||
|
|
||||||
class PassUi(wx.Frame):
|
class PassUi(wx.Frame):
|
||||||
"""
|
"""
|
||||||
|
@ -11,41 +15,56 @@ class PassUi(wx.Frame):
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
super().__init__(*args, **kw)
|
super().__init__(*args, **kw)
|
||||||
|
# Find the top directory and set that to current dirtectory
|
||||||
# create a panel in the frame
|
|
||||||
#self.pnl = wx.Panel(self)
|
|
||||||
self.pnl = wx.ScrolledWindow(self, style = wx.VSCROLL)
|
|
||||||
self.topdir = os.environ.get('PASSWORD_STORE_DIR')
|
self.topdir = os.environ.get('PASSWORD_STORE_DIR')
|
||||||
if not self.topdir:
|
if not self.topdir:
|
||||||
self.topdir = os.environ.get('HOME') + '/.password-store'
|
self.topdir = os.environ.get('HOME') + '/.password-store'
|
||||||
self.curdir = self.topdir
|
self.curdir = self.topdir
|
||||||
|
# create a panel in the frame
|
||||||
|
self.pnl = scrolled.ScrolledPanel(self, -1, style=wx.VSCROLL)
|
||||||
|
self.pnl.SetupScrolling()
|
||||||
# and create a sizer to manage the layout of child widgets
|
# and create a sizer to manage the layout of child widgets
|
||||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
self.pnl.SetSizer(self.sizer)
|
self.pnl.SetSizer(self.sizer)
|
||||||
self.cur_paths = self.get_pass_paths()
|
self.cur_paths = self.get_pass_paths()
|
||||||
self.cur_passwords = self.get_pass_passwords()
|
self.cur_passwords = self.get_pass_passwords()
|
||||||
self.add_buttons()
|
self.add_buttons()
|
||||||
|
|
||||||
def add_buttons(self):
|
def add_buttons(self):
|
||||||
self.sizer.Clear(delete_windows=True)
|
self.sizer.Clear(delete_windows=True)
|
||||||
|
if self.curdir != self.topdir:
|
||||||
|
index = -1
|
||||||
|
cpath = os.path.abspath(os.path.join(self.curdir, os.pardir))
|
||||||
|
label = '../'
|
||||||
|
btn = wx.Button(self.pnl, id=index, label=label)
|
||||||
|
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
|
||||||
|
self.Bind(wx.EVT_BUTTON,
|
||||||
|
lambda event, path=cpath: self.path_button_clicked(
|
||||||
|
event, path),
|
||||||
|
btn)
|
||||||
index = 0
|
index = 0
|
||||||
for cpath in self.cur_paths:
|
for cpath in self.cur_paths:
|
||||||
|
if cpath != self.curdir:
|
||||||
if self.curdir != self.topdir:
|
|
||||||
label = '../'
|
|
||||||
else:
|
|
||||||
label = os.path.basename(os.path.normpath(cpath))
|
label = os.path.basename(os.path.normpath(cpath))
|
||||||
btn = wx.Button(self.pnl, id = index, label=label)
|
btn = wx.Button(self.pnl, id=index, label=label)
|
||||||
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
|
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
|
||||||
print(self.get_pass_path_from_index(index))
|
self.Bind(wx.EVT_BUTTON,
|
||||||
index = index + 1
|
lambda event, path=cpath: self.path_button_clicked(
|
||||||
|
event, path),
|
||||||
|
btn)
|
||||||
|
index = index + 1
|
||||||
for password in self.cur_passwords:
|
for password in self.cur_passwords:
|
||||||
label = os.path.splitext(os.path.basename(os.path.normpath(password)))[0]
|
label = os.path.splitext(
|
||||||
btn = wx.Button(self.pnl, id = index, label=label)
|
os.path.basename(os.path.normpath(password)))[0]
|
||||||
|
btn = wx.Button(self.pnl, id=index, label=label)
|
||||||
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
|
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
|
||||||
print(self.get_pass_path_from_index(index,'password'))
|
self.Bind(wx.EVT_BUTTON,
|
||||||
|
lambda event, index=index: self.password_button_clicked(
|
||||||
|
event, index),
|
||||||
|
btn)
|
||||||
index = index + 1
|
index = index + 1
|
||||||
|
|
||||||
self.sizer.Layout()
|
self.sizer.Layout()
|
||||||
|
|
||||||
def get_pass_path_from_index(self, index, pathtype="path"):
|
def get_pass_path_from_index(self, index, pathtype="path"):
|
||||||
result = ""
|
result = ""
|
||||||
if pathtype == "password":
|
if pathtype == "password":
|
||||||
|
@ -53,21 +72,86 @@ class PassUi(wx.Frame):
|
||||||
result = self.cur_passwords[index]
|
result = self.cur_passwords[index]
|
||||||
else:
|
else:
|
||||||
result = self.cur_paths[index]
|
result = self.cur_paths[index]
|
||||||
return result.replace(self.topdir,'').replace('.gpg','')
|
return result.replace(self.topdir, '').replace('.gpg', '')
|
||||||
|
|
||||||
def get_pass_passwords(self):
|
def get_pass_passwords(self):
|
||||||
passwords = []
|
passwords = []
|
||||||
for mfile in os.listdir(self.curdir):
|
for mfile in os.listdir(self.curdir):
|
||||||
if mfile.endswith(".gpg"): # and os.path.isfile(mfile):
|
if mfile.endswith(".gpg"): # and os.path.isfile(mfile):
|
||||||
passwords.append(os.path.join(self.curdir, mfile))
|
passwords.append(os.path.join(self.curdir, mfile))
|
||||||
return passwords
|
return passwords
|
||||||
|
|
||||||
def get_pass_paths(self):
|
def get_pass_paths(self):
|
||||||
dirs = []
|
dirs = []
|
||||||
if self.curdir != self.topdir:
|
if self.curdir != self.topdir:
|
||||||
dirs.append(self.curdir)
|
dirs.append(self.curdir)
|
||||||
for cdir in os.listdir(self.curdir):
|
for cdir in os.listdir(self.curdir):
|
||||||
if os.path.isdir(os.path.join(self.curdir,cdir)) and cdir != ".git":
|
if os.path.isdir(os.path.join(self.curdir,
|
||||||
|
cdir)) and cdir != ".git":
|
||||||
dirs.append(os.path.join(self.curdir, cdir))
|
dirs.append(os.path.join(self.curdir, cdir))
|
||||||
return dirs
|
return dirs
|
||||||
|
|
||||||
|
def password_button_clicked(self, event, index):
|
||||||
|
self.show_password(index)
|
||||||
|
|
||||||
|
def path_button_clicked(self, event, path):
|
||||||
|
self.curdir = path
|
||||||
|
self.cur_paths = self.get_pass_paths()
|
||||||
|
self.cur_passwords = self.get_pass_passwords()
|
||||||
|
self.add_buttons()
|
||||||
|
|
||||||
|
def show_password(self, index):
|
||||||
|
self.sizer.Clear(delete_windows=True)
|
||||||
|
|
||||||
|
cpath = os.path.abspath(os.path.join(self.curdir, os.pardir))
|
||||||
|
label = '../'
|
||||||
|
btn = wx.Button(self.pnl, id=index, label=label)
|
||||||
|
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
|
||||||
|
self.Bind(
|
||||||
|
wx.EVT_BUTTON,
|
||||||
|
lambda event, path=cpath: self.path_button_clicked(event, path),
|
||||||
|
btn)
|
||||||
|
|
||||||
|
passpath = self.get_pass_path_from_index(index, "password")
|
||||||
|
password = get_password_from_path(passpath)
|
||||||
|
btn = wx.Button(self.pnl, id=index + 1, label=password)
|
||||||
|
self.sizer.Add(btn, 0, wx.EXPAND) # pylint: disable=no-member
|
||||||
|
self.Bind(wx.EVT_BUTTON,
|
||||||
|
lambda event, text=password: copy_to_clipboard(event, text),
|
||||||
|
btn)
|
||||||
|
self.sizer.Layout()
|
||||||
|
|
||||||
|
|
||||||
|
def copy_to_clipboard(event, text):
|
||||||
|
command1 = '/bin/echo ' + text
|
||||||
|
command2 = '/usr/bin/wl-copy'
|
||||||
|
return run_command(command1, command2)
|
||||||
|
|
||||||
|
|
||||||
|
def get_password_from_path(passpath):
|
||||||
|
result = run_command("/usr/bin/pass show " + passpath)
|
||||||
|
temp = result[0].decode()
|
||||||
|
password = temp.split('\n')[0]
|
||||||
|
return password
|
||||||
|
|
||||||
|
|
||||||
|
def run_command(command1, command2=None):
|
||||||
|
"""Run a command on system and capture result"""
|
||||||
|
process1 = subprocess.Popen(command1.split(),
|
||||||
|
shell=False,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
|
# If there is a second command it is taken to be a pipline
|
||||||
|
if command2:
|
||||||
|
process2 = subprocess.Popen(command2.split(),
|
||||||
|
shell=False,
|
||||||
|
stdin=process1.stdout,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
|
process1.stdout.close()
|
||||||
|
return process1.communicate()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# When this module is run (not imported) then create the app, the
|
# When this module is run (not imported) then create the app, the
|
||||||
# frame, show it, and start the event loop.
|
# frame, show it, and start the event loop.
|
||||||
|
|
Loading…
Add table
Reference in a new issue