Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import tty
- import termios
- import sys
- import subprocess
- out = subprocess.check_output('loginctl').decode('utf8')
- users = {}
- for line in out.splitlines():
- session = line[8:13].strip()
- user = line[22:30].strip()
- seat = line[39:].strip()
- if not user in users:
- users[user] = []
- users[user].append({'session':session, 'seat':seat})
- session = None
- for row in users['username']:
- if row['seat']: session = row['session']
- def getchar():
- #Returns a single character from standard input
- fd = sys.stdin.fileno()
- old_settings = termios.tcgetattr(fd)
- try:
- tty.setraw(sys.stdin.fileno())
- ch = sys.stdin.read(1)
- finally:
- termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
- return ch
- print("UNLOCK <=== SWIPE ===> LOCK")
- while 1:
- c = getchar()
- if c == "\x01":
- ctrla = True
- elif ctrla and c == "p":
- subprocess.check_call("loginctl unlock-session "+session, shell=True)
- ctrla = False
- elif ctrla and c == "n":
- print(session)
- subprocess.check_call("loginctl lock-session "+session, shell=True)
- ctrla = False
- elif ctrla and c == "q":
- sys.exit()
- else:
- ctrla = False
Add Comment
Please, Sign In to add comment