Last active
December 11, 2023 12:23
-
-
Save milisarge/d169756e316e185572605699e73ed3ae to your computer and use it in GitHub Desktop.
Python Greetd Based Login Manager - CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import socket, os | |
import json | |
soket = os.getenv("GREETD_SOCK") | |
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
client.connect(soket) | |
def g_send(json_req): | |
req = json.dumps(jreq) | |
client.send( len(req).to_bytes(4,"little") + req.encode()) | |
return client.recv(128) | |
start = 1 | |
while True: | |
try: | |
if start == 1: | |
username = input("user:") | |
jreq = {"type": "create_session", "username": username } | |
g_send(jreq) | |
start = 2 | |
if start == 2: | |
password = input("password:") | |
jreq = {"type": "post_auth_message_response", "response": password} | |
resp = g_send(jreq) | |
resp = json.loads(resp.decode("utf-8")) | |
#print("resp",resp) | |
start = 3 | |
if start == 3: | |
cmd = input("cmd:") | |
jreq = {"type": "start_session", "cmd": cmd.split() } | |
resp_raw = g_send(jreq) | |
resp_len = int.from_bytes(resp_raw[0:4],"little") | |
respt = resp_raw[4:resp_len+4].decode() | |
resp = json.loads(respt) | |
#print("resp",resp) | |
if "error_type" in resp and resp["error_type"] == "auth_error": | |
start = 1 | |
print("auth error - try again") | |
elif "type" in resp and resp["type"] == "success": | |
print(resp) | |
sys.exit() | |
except KeyboardInterrupt as k: | |
print("kapat") | |
client.close() | |
break |
Author
milisarge
commented
Dec 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment