remove USER_FILE usage in ssl_decrypt.py and ssl_encrypt.py; switch to argparse for command-line arguments
This commit is contained in:
@ -1,19 +1,30 @@
|
||||
#!/usr/bin/python3
|
||||
""" This Script decrypt Wireguard files for Wirepy users """
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import pwd
|
||||
import shutil
|
||||
from subprocess import CompletedProcess
|
||||
import subprocess
|
||||
from subprocess import CompletedProcess, run
|
||||
from wp_app_config import AppConfig
|
||||
|
||||
log_name = AppConfig.USER_FILE.read_text().strip()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--user", required=True, help="Username of the target file system")
|
||||
args = parser.parse_args()
|
||||
|
||||
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")
|
||||
try:
|
||||
# Retrieve UID and GID
|
||||
user_info = pwd.getpwnam(args.user)
|
||||
uid = user_info.pw_uid # User ID (e.g., 1000)
|
||||
gid = user_info.pw_gid # Group ID (e.g., 1000)
|
||||
except KeyError:
|
||||
print(f"User '{args.user}' not found.")
|
||||
exit(1)
|
||||
|
||||
keyfile: Path = Path(f"/home/{args.user}/.config/wire_py/pbwgk.pem")
|
||||
path_of_crypted_tunnel: Path = Path(f"/home/{args.user}/.config/wire_py")
|
||||
|
||||
if not keyfile.is_file():
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
[
|
||||
"openssl",
|
||||
"rsa",
|
||||
@ -34,9 +45,9 @@ if not keyfile.is_file():
|
||||
print("Public key generated successfully.")
|
||||
else:
|
||||
print(f"Error with the following code... {process.returncode}")
|
||||
shutil.chown(keyfile, 1000, 1000)
|
||||
shutil.chown(keyfile, uid, gid)
|
||||
|
||||
if AppConfig.PUBLICKEY.exists:
|
||||
if AppConfig.PUBLICKEY.exists():
|
||||
|
||||
crypted__tunnel = [str(file) for file in path_of_crypted_tunnel.glob("*.dat")]
|
||||
|
||||
@ -44,7 +55,7 @@ if AppConfig.PUBLICKEY.exists:
|
||||
|
||||
base_name = Path(tunnel_path).stem
|
||||
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
[
|
||||
"openssl",
|
||||
"pkeyutl",
|
||||
@ -60,7 +71,7 @@ if AppConfig.PUBLICKEY.exists:
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
shutil.chown(f"{AppConfig.TEMP_DIR}/{base_name}.conf", 1000, 1000)
|
||||
shutil.chown(f"{AppConfig.TEMP_DIR}/{base_name}.conf", uid, gid)
|
||||
print(f"Processing of the file: {tunnel_path}")
|
||||
|
||||
if process.stdout:
|
||||
|
Reference in New Issue
Block a user