Skip to content

Instantly share code, notes, and snippets.

@milisarge
Last active December 11, 2023 12:23
Show Gist options
  • Save milisarge/d169756e316e185572605699e73ed3ae to your computer and use it in GitHub Desktop.
Save milisarge/d169756e316e185572605699e73ed3ae to your computer and use it in GitHub Desktop.
Python Greetd Based Login Manager - CLI
#!/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
@milisarge
Copy link
Author

# /etc/greetd/config.toml
command = /usr/local/bin/greetd.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment