2 Commits

5 changed files with 84 additions and 20 deletions

View File

@ -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]]:
""" """

View File

@ -6,15 +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
import getpass
uname: Path = Path("/tmp/.log_user") log_name: str = getpass.getuser()
if log_name == "root":
log_name = Path(uname).read_text(encoding="utf-8") from common_tools import LxTools
log_name: str = LxTools.get_username()
print("replacement method applied")
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(

View File

@ -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 LxTools
keyfile: Path = AppConfig.PUBLICKEY
keyfile: Path = Path(
f"/home/{AppConfig.USER_FILE.read_text(encoding="utf-8")}/.config/wire_py/pbwgk.pem"
)
if not keyfile.is_file(): if not keyfile.is_file():

View File

@ -23,7 +23,6 @@ from common_tools import (
) )
from wp_app_config import AppConfig, Msg from wp_app_config import AppConfig, Msg
LxTools.uos()
Create.dir_and_files() Create.dir_and_files()
Create.make_dir() Create.make_dir()
Create.decrypt() Create.decrypt()

View File

@ -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"