04-06-2025_large_update #35
@@ -84,7 +84,7 @@ class Create:
 | 
			
		||||
            AppConfig.TEMP_DIR.mkdir()
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def decrypt() -> None:
 | 
			
		||||
    def decrypt() -> str:
 | 
			
		||||
        """
 | 
			
		||||
        Starts SSL dencrypt
 | 
			
		||||
        """
 | 
			
		||||
@@ -106,7 +106,7 @@ class Create:
 | 
			
		||||
            print(_("Ready for import"))
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def encrypt() -> None:
 | 
			
		||||
    def encrypt() -> str:
 | 
			
		||||
        """
 | 
			
		||||
        Starts SSL encryption
 | 
			
		||||
        """
 | 
			
		||||
@@ -258,10 +258,9 @@ class LxTools(tk.Tk):
 | 
			
		||||
                check=True,
 | 
			
		||||
            )
 | 
			
		||||
            if result.returncode != 0:
 | 
			
		||||
                exit(1)
 | 
			
		||||
            else:
 | 
			
		||||
                print(result.stdout.strip())
 | 
			
		||||
                return result.stdout.strip()
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
            return result.stdout.strip()
 | 
			
		||||
 | 
			
		||||
        except subprocess.CalledProcessError:
 | 
			
		||||
            pass
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								settings
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								settings
									
									
									
									
									
								
							@@ -1,8 +1,9 @@
 | 
			
		||||
[UPDATES]
 | 
			
		||||
# Configuration
 | 
			
		||||
on
 | 
			
		||||
[THEME]
 | 
			
		||||
light
 | 
			
		||||
[TOOLTIP]
 | 
			
		||||
# Theme
 | 
			
		||||
dark
 | 
			
		||||
# Tooltips
 | 
			
		||||
True
 | 
			
		||||
[AUTOSTART ON]
 | 
			
		||||
# Autostart
 | 
			
		||||
off
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,15 +6,8 @@ import shutil
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from subprocess import check_call
 | 
			
		||||
from wp_app_config import AppConfig
 | 
			
		||||
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 = AppConfig.USER_FILE.read_text()
 | 
			
		||||
 | 
			
		||||
keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,8 @@
 | 
			
		||||
"""
 | 
			
		||||
this script is a simple GUI for managing Wireguard Tunnels
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import getpass
 | 
			
		||||
import os
 | 
			
		||||
import shutil
 | 
			
		||||
import subprocess
 | 
			
		||||
@@ -23,8 +25,9 @@ from common_tools import (
 | 
			
		||||
)
 | 
			
		||||
from wp_app_config import AppConfig, Msg
 | 
			
		||||
 | 
			
		||||
Create.dir_and_files()
 | 
			
		||||
Create.make_dir()
 | 
			
		||||
AppConfig.USER_FILE.write_text(getpass.getuser())
 | 
			
		||||
AppConfig.ensure_directories()
 | 
			
		||||
AppConfig.create_default_settings()
 | 
			
		||||
Create.decrypt()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
import gettext
 | 
			
		||||
import locale
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
import subprocess
 | 
			
		||||
from typing import Dict, Any
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -24,7 +25,14 @@ class AppConfig:
 | 
			
		||||
    # Configuration files
 | 
			
		||||
    SETTINGS_FILE: Path = CONFIG_DIR / "settings"
 | 
			
		||||
    KEYS_FILE: Path = CONFIG_DIR / "keys"
 | 
			
		||||
    SYSTEMD_USER_FOLDER: Path = Path.home() / ".config/systemd/user"
 | 
			
		||||
    AUTOSTART_SERVICE: Path = Path.home() / ".config/systemd/user/wg_start.service"
 | 
			
		||||
    DEFAULT_SETTINGS: Dict[str, str] = {
 | 
			
		||||
        "# Configuration": "on",
 | 
			
		||||
        "# Theme": "dark",
 | 
			
		||||
        "# Tooltips": True,
 | 
			
		||||
        "# Autostart": "off",
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # Updates
 | 
			
		||||
    # 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year
 | 
			
		||||
@@ -79,7 +87,8 @@ class AppConfig:
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def ensure_directories(cls) -> None:
 | 
			
		||||
        """Ensures that all required directories exist"""
 | 
			
		||||
        cls.CONFIG_DIR.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
        if not cls.CONFIG_DIR.exists():
 | 
			
		||||
            cls.CONFIG_DIR.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
        cls.TEMP_DIR.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
@@ -91,29 +100,40 @@ class AppConfig:
 | 
			
		||||
            )
 | 
			
		||||
            cls.SETTINGS_FILE.write_text(content)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def get_image_paths(cls) -> Dict[str, Path]:
 | 
			
		||||
        """Returns paths to UI images"""
 | 
			
		||||
        return {
 | 
			
		||||
            "main_icon": cls.SYSTEM_PATHS["image_path"] / "48/wg_vpn.png",
 | 
			
		||||
            "warning": cls.CONFIG_DIR / "images/warning.png",
 | 
			
		||||
            "success": cls.CONFIG_DIR / "images/success.png",
 | 
			
		||||
            "error": cls.CONFIG_DIR / "images/error.png",
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def get_autostart_content(cls) -> str:
 | 
			
		||||
        """Returns the content for the autostart service file"""
 | 
			
		||||
        SYSTEMD_FILE: list[str] = [
 | 
			
		||||
            "[Unit]",
 | 
			
		||||
            "Description=Automatic Tunnel Start",
 | 
			
		||||
            "After=network-online.target",
 | 
			
		||||
            "",
 | 
			
		||||
            "[Service]",
 | 
			
		||||
            "Type=oneshot",
 | 
			
		||||
            "ExecStartPre=/bin/sleep 5",
 | 
			
		||||
            "ExecStart=/usr/local/bin/start_wg.py",
 | 
			
		||||
            "",
 | 
			
		||||
            "[Install]",
 | 
			
		||||
            "WantedBy=default.target",
 | 
			
		||||
        ]
 | 
			
		||||
        if not cls.SYSTEMD_USER_FOLDER.exists():
 | 
			
		||||
            cls.SYSTEMD_USER_FOLDER.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
 | 
			
		||||
        return """[Unit]Description=Automatic Tunnel Start
 | 
			
		||||
After=network-online.target
 | 
			
		||||
        for line in SYSTEMD_FILE:
 | 
			
		||||
            cls.AUTOSTART_SERVICE.write_text(line)
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
Type=oneshot
 | 
			
		||||
ExecStartPre=/bin/sleep 5
 | 
			
		||||
ExecStart=/usr/local/bin/start_wg.py
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=default.target"""
 | 
			
		||||
        process = subprocess.run(
 | 
			
		||||
            ["systemctl", "--user", "enable", "wg_start.service"],
 | 
			
		||||
            stdout=subprocess.PIPE,
 | 
			
		||||
            text=True,
 | 
			
		||||
            check=True,
 | 
			
		||||
        )
 | 
			
		||||
        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}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# here is inizialize the class for translate strrings
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user