diff --git a/common_tools.py b/common_tools.py index 4655ef4..8f29f89 100755 --- a/common_tools.py +++ b/common_tools.py @@ -591,6 +591,36 @@ class ConfigManager: config = cls.load() return config.get(key, default) + @property + def username(self) -> str: + """ + Returns the username of the logged-in user, + even if the script is running with root privileges. + + Returns: + str: The username of the logged-in user + """ + import os + from pathlib import Path + + # Versuche zuerst SUDO_USER zu bekommen + sudo_user = os.environ.get("SUDO_USER") + if sudo_user: + return sudo_user + + # Extrahiere aus Path.home() + home_path = str(Path.home()) + if "/home/" in home_path: + return home_path.split("/home/")[1].split("/")[0] + + # Fallbacks + try: + return os.getlogin() + except: + import getpass + + return getpass.getuser() + class ThemeManager: @staticmethod diff --git a/ssl_decrypt.py b/ssl_decrypt.py index 0587e7f..5c0d45c 100755 --- a/ssl_decrypt.py +++ b/ssl_decrypt.py @@ -6,11 +6,9 @@ import shutil from pathlib import Path from subprocess import check_call from wp_app_config import AppConfig +from common_tools import ConfigManager -uname: Path = Path("/tmp/.log_user") - -log_name = Path(uname).read_text(encoding="utf-8") - +log_name: str = ConfigManager.username() keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem") # PKEYFILE: Path = "/usr/local/etc/ssl/pwgk.pem" diff --git a/ssl_encrypt.py b/ssl_encrypt.py index f924b26..9110d54 100755 --- a/ssl_encrypt.py +++ b/ssl_encrypt.py @@ -7,11 +7,11 @@ from pathlib import Path from subprocess import check_call from common_tools import LxTools from wp_app_config import AppConfig +from common_tools import ConfigManager +log_name = ConfigManager.username() -keyfile: Path = Path( - f"/home/{AppConfig.USER_FILE.read_text(encoding="utf-8")}/.config/wire_py/pbwgk.pem" -) +keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem") if not keyfile.is_file(): diff --git a/wirepy.py b/wirepy.py index 0231db8..0189206 100755 --- a/wirepy.py +++ b/wirepy.py @@ -23,7 +23,7 @@ from common_tools import ( ) from wp_app_config import AppConfig, Msg -LxTools.uos() + Create.dir_and_files() Create.make_dir() Create.decrypt()