04-06-2025_large_update #35
							
								
								
									
										110
									
								
								common_tools.py
									
									
									
									
									
								
							
							
						
						
									
										110
									
								
								common_tools.py
									
									
									
									
									
								
							@@ -99,6 +99,7 @@ class Create:
 | 
				
			|||||||
        if file_in_path:
 | 
					        if file_in_path:
 | 
				
			||||||
            if process.returncode == 0:
 | 
					            if process.returncode == 0:
 | 
				
			||||||
                print("File successfully decrypted...")
 | 
					                print("File successfully decrypted...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                print(f"Error with the following code... {process.returncode}")
 | 
					                print(f"Error with the following code... {process.returncode}")
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
@@ -244,16 +245,26 @@ class LxTools(tk.Tk):
 | 
				
			|||||||
        return lists_file
 | 
					        return lists_file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def uos() -> None:
 | 
					    def get_username() -> str:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        uos = LOGIN USERNAME
 | 
					        Returns the username of the logged-in user,
 | 
				
			||||||
 | 
					        even if the script is running with root privileges.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            result = subprocess.run(
 | 
				
			||||||
 | 
					                ["logname"],
 | 
				
			||||||
 | 
					                stdout=subprocess.PIPE,
 | 
				
			||||||
 | 
					                text=True,
 | 
				
			||||||
 | 
					                check=True,
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            if result.returncode != 0:
 | 
				
			||||||
 | 
					                exit(1)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                print(result.stdout.strip())
 | 
				
			||||||
 | 
					                return result.stdout.strip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        This method displays the username of the logged-in user,
 | 
					        except subprocess.CalledProcessError:
 | 
				
			||||||
        even if you are rooted in a shell
 | 
					            pass
 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        log_name: str = f"{Path.home()}"[6:]
 | 
					 | 
				
			||||||
        file: Path = Path.home() / "/tmp/.log_user"
 | 
					 | 
				
			||||||
        Path(file).write_text(log_name, encoding="utf-8")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def clean_files(TEMP_DIR: Path = None, file: Path = None) -> None:
 | 
					    def clean_files(TEMP_DIR: Path = None, file: Path = None) -> None:
 | 
				
			||||||
@@ -265,9 +276,13 @@ class LxTools(tk.Tk):
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        if AppConfig.TEMP_DIR is not None:
 | 
					        if AppConfig.TEMP_DIR is not None:
 | 
				
			||||||
            shutil.rmtree(AppConfig.TEMP_DIR)
 | 
					            shutil.rmtree(AppConfig.TEMP_DIR)
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            if file is not None:
 | 
					            if file is not None:
 | 
				
			||||||
                Path.unlink(file)
 | 
					                Path.unlink(file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        except FileNotFoundError:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def msg_window(
 | 
					    def msg_window(
 | 
				
			||||||
        image_path: Path,
 | 
					        image_path: Path,
 | 
				
			||||||
@@ -389,6 +404,55 @@ class Tunnel:
 | 
				
			|||||||
    Class of Methods for Wire-Py
 | 
					    Class of Methods for Wire-Py
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @staticmethod
 | 
				
			||||||
 | 
					    def parse_files_to_dictionary() -> Dict[str, List[str]]:
 | 
				
			||||||
 | 
					        data = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if not AppConfig.TEMP_DIR.exists() or not AppConfig.TEMP_DIR.is_dir():
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Get a list of all files in the directorys
 | 
				
			||||||
 | 
					        files = [file for file in AppConfig.TEMP_DIR.iterdir() if file.is_file()]
 | 
				
			||||||
 | 
					        if not files:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Search for the string in the files
 | 
				
			||||||
 | 
					        for file in files:
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
 | 
					                with open(file, "r") as f:
 | 
				
			||||||
 | 
					                    content = f.read()
 | 
				
			||||||
 | 
					                    # Hier parsen wir die relevanten Zeilen aus dem Inhalt
 | 
				
			||||||
 | 
					                    address_line = next(
 | 
				
			||||||
 | 
					                        line
 | 
				
			||||||
 | 
					                        for line in content.splitlines()
 | 
				
			||||||
 | 
					                        if line.startswith("Address")
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					                    dns_line = next(
 | 
				
			||||||
 | 
					                        line for line in content.splitlines() if line.startswith("DNS")
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					                    endpoint_line = next(
 | 
				
			||||||
 | 
					                        line
 | 
				
			||||||
 | 
					                        for line in content.splitlines()
 | 
				
			||||||
 | 
					                        if line.startswith("Endpoint")
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    # Extrahiere die Werte
 | 
				
			||||||
 | 
					                    address = address_line.split("=")[1].strip()
 | 
				
			||||||
 | 
					                    dns = dns_line.split("=")[1].strip()
 | 
				
			||||||
 | 
					                    endpoint = endpoint_line.split("=")[1].strip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    # Speichere im Dictionary
 | 
				
			||||||
 | 
					                    data[file.stem] = {
 | 
				
			||||||
 | 
					                        "Address": address,
 | 
				
			||||||
 | 
					                        "DNS": dns,
 | 
				
			||||||
 | 
					                        "Endpoint": endpoint,
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					            except Exception:
 | 
				
			||||||
 | 
					                # Ignore errors and continue to the next file
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def con_to_dict(cls, file: TextIO) -> Tuple[str, str, str, Optional[str]]:
 | 
					    def con_to_dict(cls, file: TextIO) -> Tuple[str, str, str, Optional[str]]:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
@@ -591,36 +655,6 @@ class ConfigManager:
 | 
				
			|||||||
        config = cls.load()
 | 
					        config = cls.load()
 | 
				
			||||||
        return config.get(key, default)
 | 
					        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:
 | 
					class ThemeManager:
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,13 +6,18 @@ import shutil
 | 
				
			|||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
from subprocess import check_call
 | 
					from subprocess import check_call
 | 
				
			||||||
from wp_app_config import AppConfig
 | 
					from wp_app_config import AppConfig
 | 
				
			||||||
from common_tools import ConfigManager
 | 
					import getpass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					log_name: str = getpass.getuser()
 | 
				
			||||||
 | 
					if log_name == "root":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    from common_tools import LxTools
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log_name: str = LxTools.get_username()
 | 
				
			||||||
 | 
					    print("replacement method applied")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
log_name: str = ConfigManager.username()
 | 
					 | 
				
			||||||
keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
 | 
					keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# PKEYFILE: Path = "/usr/local/etc/ssl/pwgk.pem"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if not keyfile.is_file():
 | 
					if not keyfile.is_file():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    check_call(
 | 
					    check_call(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,13 +5,10 @@ import os
 | 
				
			|||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
from subprocess import check_call
 | 
					from subprocess import check_call
 | 
				
			||||||
from common_tools import LxTools
 | 
					 | 
				
			||||||
from wp_app_config import AppConfig
 | 
					from wp_app_config import AppConfig
 | 
				
			||||||
from common_tools import ConfigManager
 | 
					from common_tools import LxTools
 | 
				
			||||||
 | 
					
 | 
				
			||||||
log_name = ConfigManager.username()
 | 
					keyfile: Path = AppConfig.PUBLICKEY
 | 
				
			||||||
 | 
					 | 
				
			||||||
keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
if not keyfile.is_file():
 | 
					if not keyfile.is_file():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,6 @@ from common_tools import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
from wp_app_config import AppConfig, Msg
 | 
					from wp_app_config import AppConfig, Msg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
Create.dir_and_files()
 | 
					Create.dir_and_files()
 | 
				
			||||||
Create.make_dir()
 | 
					Create.make_dir()
 | 
				
			||||||
Create.decrypt()
 | 
					Create.decrypt()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ class AppConfig:
 | 
				
			|||||||
    CONFIG_DIR: Path = BASE_DIR / ".config/wire_py"
 | 
					    CONFIG_DIR: Path = BASE_DIR / ".config/wire_py"
 | 
				
			||||||
    TEMP_DIR: Path = Path("/tmp/tlecdcwg")
 | 
					    TEMP_DIR: Path = Path("/tmp/tlecdcwg")
 | 
				
			||||||
    USER_FILE: Path = Path("/tmp/.log_user")
 | 
					    USER_FILE: Path = Path("/tmp/.log_user")
 | 
				
			||||||
 | 
					    PUBLICKEY: Path = CONFIG_DIR / "pbwgk.pem"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Configuration files
 | 
					    # Configuration files
 | 
				
			||||||
    SETTINGS_FILE: Path = CONFIG_DIR / "settings"
 | 
					    SETTINGS_FILE: Path = CONFIG_DIR / "settings"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user