-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
114 lines (88 loc) · 3.53 KB
/
main.py
File metadata and controls
114 lines (88 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import webview
import subprocess
import os
import pam
import sys
import time
import tkinter as tk # For Screen Resolution Detection
# import archinstall
# import pathlib
# import json
# Function to find a free TTY dynamically
def find_free_tty():
used_ttys = subprocess.getoutput("who").split("\n")
used_ttys = [line.split()[1] for line in used_ttys if line] # Extract active TTYs
for i in range(2, 10): # Check tty2 to tty9
if f"tty{i}" not in used_ttys:
return i
return 1 # Fallback to tty1
# Find a free Xorg display
display_num = 0 if not os.path.exists("/tmp/.X0-lock") else 1
free_tty = find_free_tty()
# Start Xorg dynamically
os.system(f"Xorg :{display_num} vt{free_tty} -nolisten tcp &")
time.sleep(2)
# Set DISPLAY environment variable
os.environ["DISPLAY"] = f":{display_num}"
xsessions = "/usr/share/xsessions"
waylandsessions = "/usr/share/wayland-sessions"
session_dirs = [xsessions, waylandsessions]
class Api:
def __init__(self):
self.selected_session = None # Initialize selected session
def test_func(self):
print("bruh")
def get_sessions(self):
sessions = {}
for directory in session_dirs:
if os.path.exists(directory):
for file in os.listdir(directory):
if file.endswith(".desktop"):
with open(os.path.join(directory, file), "r") as f:
name, cmd = None, None
for line in f:
if line.startswith("Name="):
name = line.strip().split("=", 1)[1]
elif line.startswith("Exec="):
cmd = line.strip().split("=", 1)[1]
if name and cmd:
break
if name and cmd:
sessions[name] = cmd
return sessions
def select_session(self, name):
self.selected_session = name # Store selected session
def auth_user(self, username, password):
return pam.authenticate(username, password)
def start_session(self, username):
if not self.selected_session:
print("No session selected")
return
sessions = self.get_sessions()
session_cmd = sessions.get(self.selected_session)
if not session_cmd:
print(f"Invalid session: {self.selected_session}")
return
print(f"Starting session: {self.selected_session} for {username}")
# xinit_file = open('~/.azuloginXINIT', 'x')
# xinit_file.write(f"exec {session_cmd}")
# xinit_file.close()
# os.system('chmod +x ~/.azuloginXINIT')
# os.system('startx ~/.azuloginXINIT')
os.system(f"sudo -u {username} setsid {session_cmd} &") # Use setsid to detach session
# os.system(f'sudo -u {username} {session_cmd}')
sys.exit()
root = tk.Tk()
displayWidth = root.winfo_screenwidth()
displayHeight = root.winfo_screenheight()
print("Starting AzuLogin")
# Instantiate Api class
api = Api()
webview.settings = {
"ALLOW_FILE_URLS": True,
"ALLOW_DOWNLOADS": True,
"OPEN_DEVTOOLS_IN_DEBUG": False,
}
webview.create_window('AzuLogin', url="assets/index.html", background_color='#000000', js_api=api, fullscreen=True, width=displayWidth, height=displayHeight)
# webview.create_window("AzuLogin", url="assets/index.html", background_color="#000000", js_api=api, width=1280, height=720)
webview.start(gui="qt", debug=True)