ssl_decrypt.py now with output and check_call replace with subprocess.run

This commit is contained in:
Désiré Werner Menrath 2025-05-11 18:24:57 +02:00
parent a903666a26
commit 6604650adf
6 changed files with 68 additions and 39 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
debug.log
.venv
.venv.bak
.idea
.vscode
__pycache__

View File

@ -90,20 +90,23 @@ class Create:
"""
process: CompletedProcess[str] = subprocess.run(
["pkexec", "/usr/local/bin/ssl_decrypt.py"],
stdout=subprocess.PIPE,
capture_output=True,
text=True,
check=True,
check=False,
)
path: Path = Path.home() / ".config/wire_py/"
file_in_path: list[Path] = list(path.rglob("*.dat"))
if file_in_path:
if process.returncode == 0:
print("File successfully decrypted...")
else:
print(f"Error with the following code... {process.returncode}")
# Output from Openssl
if process.stdout:
print(process.stdout)
# Output from Openssl Error
if process.stderr:
print(process.stderr)
if process.returncode == 0:
print("Datei entschlüsseln wurde erfolgreich entschlossen.")
else:
print(_("Ready for import"))
print(f"Fehler bei der Verarbeitung von Dateien: Code {process.returncode}")
@staticmethod
def encrypt() -> str:

View File

@ -1,19 +1,19 @@
#!/usr/bin/python3
""" This Script decrypt Wireguard files for Wirepy users """
import os
import shutil
from pathlib import Path
from subprocess import check_call
import shutil
from subprocess import CompletedProcess
import subprocess
from wp_app_config import AppConfig
log_name = AppConfig.USER_FILE.read_text()
keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
path_of_crypted_tunnel: Path = Path(f"/home/{log_name}/.config/wire_py")
if not keyfile.is_file():
check_call(
process: CompletedProcess[str] = subprocess.run(
[
"openssl",
"rsa",
@ -24,21 +24,27 @@ if not keyfile.is_file():
"-outform",
"PEM",
"-pubout",
]
],
capture_output=True,
text=True,
check=False,
)
print(process.stdout)
if process.returncode == 0:
print("Public key generated successfully.")
else:
print(f"Error with the following code... {process.returncode}")
shutil.chown(keyfile, 1000, 1000)
AppConfig.TEMP_DIR2 = f"/home/{log_name}/.config/wire_py/"
detl: list[str] = os.listdir(AppConfig.TEMP_DIR2)
os.chdir(AppConfig.TEMP_DIR2)
detl.remove("keys")
detl.remove("settings")
if os.path.exists(f"{AppConfig.TEMP_DIR2}pbwgk.pem"):
detl.remove("pbwgk.pem")
for detunnels in detl:
tlname2 = f"{detunnels[:-4]}.conf"
extpath = f"{AppConfig.TEMP_DIR}/{tlname2}"
check_call(
if AppConfig.PUBLICKEY.exists:
crypted__tunnel = [str(file) for file in path_of_crypted_tunnel.glob("*.dat")]
for tunnel_path in crypted__tunnel:
base_name = Path(tunnel_path).stem
process: CompletedProcess[str] = subprocess.run(
[
"openssl",
"pkeyutl",
@ -46,9 +52,25 @@ if os.path.exists(f"{AppConfig.TEMP_DIR2}pbwgk.pem"):
"-inkey",
AppConfig.SYSTEM_PATHS["pkey_path"],
"-in",
detunnels,
tunnel_path, # full path to the file
"-out",
extpath,
]
f"{AppConfig.TEMP_DIR}/{base_name}.conf",
],
capture_output=True,
text=True,
check=False,
)
shutil.chown(extpath, 1000, 1000)
print(f"Processing of the file: {tunnel_path}")
if process.stdout:
print(process.stdout)
# Output from Openssl Error
if process.stderr:
print("(Error):", process.stderr)
if process.returncode == 0:
print(f"File {base_name}.dat successfully decrypted.")
else:
print(f"Error by {tunnel_path}: Code: {process.returncode}")

View File

@ -2,8 +2,8 @@
""" This Script encrypt Wireguardfiles for Wirepy users for more Security """
import os
import shutil
from pathlib import Path
import shutil
from subprocess import check_call
from wp_app_config import AppConfig
from common_tools import LxTools

View File

@ -874,7 +874,7 @@ class FrameWidgets(ttk.Frame):
"""
checkbox for enable autostart Tunnel
"""
Create.files_for_autostart()
AppConfig.get_autostart_content()
if self.l_box.size() != 0:
self.wg_autostart.configure(state="normal")
self.lb_rename.config(state="normal")

View File

@ -122,18 +122,21 @@ class AppConfig:
if not cls.SYSTEMD_USER_FOLDER.exists():
cls.SYSTEMD_USER_FOLDER.mkdir(parents=True, exist_ok=True)
for line in SYSTEMD_FILE:
cls.AUTOSTART_SERVICE.write_text(line)
from subprocess import CompletedProcess
process = subprocess.run(
if not cls.AUTOSTART_SERVICE.is_file():
content = "\n".join([line for line in SYSTEMD_FILE])
cls.AUTOSTART_SERVICE.write_text(content)
process: CompletedProcess[str] = subprocess.run(
["systemctl", "--user", "enable", "wg_start.service"],
stdout=subprocess.PIPE,
capture_output=True,
text=True,
check=True,
check=False,
)
print(process.stdout)
if process.returncode == 0:
print("File for autostart created successfully")
print(process.stdout)
else:
print(f"Error with the following code... {process.returncode}")