WIP - rofi bitwarden
This commit is contained in:
parent
d8390bc5ec
commit
164fb35375
@ -10,7 +10,7 @@
|
||||
# Please see https://i3wm.org/docs/userguide.html for a complete reference!
|
||||
|
||||
set $menu "rofi -show drun"
|
||||
set $pwdManager "rofi -modi 'bitwarden:~/bin/rofi-bitwarden.py' -show bitwarden"
|
||||
set $pwdManager "~/bin/rofi-bitwarden.py &"
|
||||
set $term alacritty
|
||||
set $compositor "picom --daemon --inactive-opacity 1 --menu-opacity 1"
|
||||
|
||||
|
||||
69
templates/rofi/rofi-bitwarden.py
Executable file
69
templates/rofi/rofi-bitwarden.py
Executable file
@ -0,0 +1,69 @@
|
||||
{# symlink{~/bin/rofi-bitwarden.py} #}
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
BW_SESSION_FILE = os.path.join('/var/run/user', str(os.getuid()), 'bitwarden-session')
|
||||
|
||||
def does_bw_session_exist():
|
||||
return os.path.exists(BW_SESSION_FILE)
|
||||
|
||||
def show_rofi_pwd_prompt():
|
||||
return os.popen('rofi -dmenu -password -i -no-fixed-num-lines -p "Master Password" -theme ~/.config/rofi/themes/askpass.rasi').read().strip()
|
||||
|
||||
def get_bw_session():
|
||||
if not does_bw_session_exist():
|
||||
return None
|
||||
|
||||
with open(BW_SESSION_FILE, 'r') as file:
|
||||
return file.read()
|
||||
|
||||
def is_logged_in():
|
||||
return os.system('bw login --check > /dev/null') == 0
|
||||
|
||||
def login():
|
||||
os.spawnl(os.P_WAIT, '/usr/bin/alacritty', 'alacritty', '-e', 'sh', '-c', 'bw login')
|
||||
|
||||
def unlock():
|
||||
password = show_rofi_pwd_prompt()
|
||||
|
||||
if len(password) > 0:
|
||||
# TODO: pipe in the password
|
||||
os.system(f'bw unlock "{password}" --raw > {BW_SESSION_FILE}')
|
||||
|
||||
def lock():
|
||||
if not does_bw_session_exist():
|
||||
return False
|
||||
|
||||
return os.system(f'bw --session "{get_bw_session()}" --nointeraction lock > /dev/null') == 0
|
||||
|
||||
def is_vault_unlocked():
|
||||
if not does_bw_session_exist():
|
||||
return False
|
||||
|
||||
return os.system(f'bw --session "{get_bw_session()}" --nointeraction list items > /dev/null 2>&1') == 0
|
||||
|
||||
def debug(msg):
|
||||
os.spawnl(os.P_WAIT, '/usr/bin/alacritty', 'alacritty', '-e', 'sh', '-c', f'echo "{msg}" && cat -')
|
||||
|
||||
def main():
|
||||
if not is_logged_in():
|
||||
login()
|
||||
if not is_logged_in():
|
||||
print('You did nog log in', file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
if not is_vault_unlocked():
|
||||
unlock()
|
||||
if not is_vault_unlocked():
|
||||
print('You did not unlock the vault', file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
print("Signed in and unlocked, cool")
|
||||
debug("Done")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user