|
|
|
@ -24,6 +24,8 @@ home_dir = os.path.expanduser("~")
@@ -24,6 +24,8 @@ home_dir = os.path.expanduser("~")
|
|
|
|
|
config = ConfigParser() |
|
|
|
|
config.read([f"{script_dir}/config.ini", f"{home_dir}/.yubilock"]) |
|
|
|
|
|
|
|
|
|
screensaver = config.get("HOSTCONFIG", "screensaver", fallback="xscreensaver")) |
|
|
|
|
|
|
|
|
|
yubikey_serials = config["USERCONFIG"]["yubikey_serial"].split(',') |
|
|
|
|
# Convert stringlist to intlist |
|
|
|
|
for i, serial in enumerate(yubikey_serials): |
|
|
|
@ -50,9 +52,14 @@ def execute(command: str, shell_on: bool = False, background: bool = False):
@@ -50,9 +52,14 @@ def execute(command: str, shell_on: bool = False, background: bool = False):
|
|
|
|
|
return '' if out == b'' else out.decode('utf-8') |
|
|
|
|
|
|
|
|
|
def screensaver_running(): |
|
|
|
|
if screensaver == 'xscreensaver': |
|
|
|
|
graphic_program_instances = execute(f"{script_dir}/kill_screensaver_graphic_program.sh -d | grep graphic_processes | wc -l", shell_on=True) |
|
|
|
|
if int(graphic_program_instances) > 0: return True |
|
|
|
|
if execute(f"DISPLAY=:0 xscreensaver-command -time | grep 'screen locked' >/dev/null 2>&1", shell_on=True): return True |
|
|
|
|
elif screensaver == 'gnome-screensaver': |
|
|
|
|
screensaver_state = execute("gnome-screensaver-command -q | tr -d '\n'", shell_on=True) |
|
|
|
|
if screensaver_state == 'The screensaver is active': return True |
|
|
|
|
if screensaver_state == 'The screensaver is inactive': return False |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def lock_screen(): |
|
|
|
@ -60,13 +67,18 @@ def lock_screen():
@@ -60,13 +67,18 @@ def lock_screen():
|
|
|
|
|
return |
|
|
|
|
if config.getboolean('USERCONFIG', 'remove_sudo_timestamp_when_locking', fallback=True): |
|
|
|
|
execute('sudo -K', shell_on=True) |
|
|
|
|
|
|
|
|
|
if screensaver == 'xscreensaver': |
|
|
|
|
execute('DISPLAY=:0 xscreensaver-command -lock', shell_on=True) |
|
|
|
|
elif screensaver == 'gnome-screensaver': |
|
|
|
|
execute('gnome-screensaver-command -l', shell_on=True) |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
def unlock_screen(): |
|
|
|
|
if args.dummy : |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if screensaver == 'xscreensaver': |
|
|
|
|
logger.info('xscreen process to be killed:') |
|
|
|
|
xscreensaver_pid = execute(r'ps -A | grep -oPm 1 "\d{2,}(?=\s.+xscreensaver)" || echo null', |
|
|
|
|
shell_on=True) |
|
|
|
@ -77,6 +89,8 @@ def unlock_screen():
@@ -77,6 +89,8 @@ def unlock_screen():
|
|
|
|
|
|
|
|
|
|
# restart xscreensaver process |
|
|
|
|
execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True) |
|
|
|
|
elif screensaver == 'gnome-screensaver': |
|
|
|
|
execute(f"{script_dir}/loginctl-unlock.sh", shell_on=True, background = True) |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
def get_yubikey_serials() -> int: |
|
|
|
@ -170,6 +184,8 @@ if __name__ == "__main__":
@@ -170,6 +184,8 @@ if __name__ == "__main__":
|
|
|
|
|
setup_logger(config.get("HOSTCONFIG", "logfile", |
|
|
|
|
fallback="log.log")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if screensaver == 'xscreensaver': |
|
|
|
|
# start xscreensaver process |
|
|
|
|
execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True) |
|
|
|
|
|
|
|
|
@ -178,8 +194,10 @@ if __name__ == "__main__":
@@ -178,8 +194,10 @@ if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
daemon(get_hid_event_monitor()) |
|
|
|
|
|
|
|
|
|
if screensaver == 'xscreensaver': |
|
|
|
|
# restart xscreensaver process before leaving |
|
|
|
|
execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True) |
|
|
|
|
|
|
|
|
|
sleep(0.2) |
|
|
|
|
|
|
|
|
|
sys.exit(0) |
|
|
|
|