Commit b714bddd authored by Jake Howard's avatar Jake Howard
Browse files

Add handle
parent bf639797
......@@ -14,3 +14,10 @@ def store_key(ident):
with open(os.path.join(BASE_DIR, "data/keys.json"), 'w') as file:
json.dump(existing_data, file)
def has_ident(ident):
with open(os.path.join(BASE_DIR, "data/keys.json")) as file:
existing_data = json.load(file)
return ident in existing_data
import click
import click, subprocess, os
from yubi_lock.api.yubikey import get_all_yubikeys, generate_ident
from yubi_lock.api.user import has_ident, get_username
@click.command('handle', short_help='Handler for inserting and removing drives')
@click.argument('type', type=click.Choice(["enable", "disable"]))
def cli(type):
@click.argument('action', type=click.Choice(["enable", "disable"]))
def cli(action):
ident = generate_ident(get_all_yubikeys(False)[0])
if not has_ident(ident):
return 1
session_id = subprocess.check_output(
"/bin/loginctl list-sessions | grep USER | awk '{print $1}'".replace('USER', get_username()),
).decode().replace('\n', '')
if action == 'enable':
os.system("/bin/loginctl lock-session {}".format(session_id))
elif action == 'disable':
os.system("/bin/loginctl unlock-session {}".format(session_id))
return 1
......@@ -5,8 +5,9 @@ from yubi_lock.api import BASE_DIR
@click.command('install', short_help='Install required files for insertion detection')
def cli():
exit_code = os.system("sudo cp {} {}".format(BASE_DIR + "../data/85-yubikey-screen-lock.rules", "/etc/udev/rules.d/85-yubikey-screen-lock.rules"))
exit_code = os.system("sudo cp {} {}".format(BASE_DIR + "/data/85-yubikey-screen-lock.rules", "/etc/udev/rules.d/85-yubikey-screen-lock.rules"))
if exit_code == 0:
print('Export complete!')
print('Export complete! Refreshing...')
os.system("sudo udevadm control --reload-rules")
print('Something went wrong!')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment