add_wp_app_config.py for central configuration

This commit is contained in:
Désiré Werner Menrath 2025-04-30 09:49:57 +02:00
parent 2e94a324a6
commit 08bef8fe6e
9 changed files with 92 additions and 91 deletions

View File

@ -41,7 +41,7 @@ My standard System: Linux Mint 22 Cinnamon
- Fix ipv6 in Config File on import - Fix ipv6 in Config File on import
- Wirepy run now as user - Wirepy run now as user
- settings, keys and Config Files now in ~/.config/wire_py - settings, AppConfig.KEYS_FILE and Config Files now in ~/.config/wire_py
- For new users, the required files are created and autostart service is started. - For new users, the required files are created and autostart service is started.
- Tunnels are now read from the directory to view them in the list. - Tunnels are now read from the directory to view them in the list.
To display only own tunnels, and read errors are minimized. To display only own tunnels, and read errors are minimized.

Binary file not shown.

View File

@ -14,14 +14,14 @@ from datetime import datetime
from pathlib import Path from pathlib import Path
from subprocess import check_call, CompletedProcess from subprocess import check_call, CompletedProcess
from tkinter import ttk, Toplevel from tkinter import ttk, Toplevel
from wp_app_config import AppConfig
import requests import requests
APP = "wirepy" # Translate
LOCALE_DIR = "/usr/share/locale/" AppConfig.APP_NAME
locale.bindtextdomain(APP, LOCALE_DIR) locale.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
gettext.bindtextdomain(APP, LOCALE_DIR) gettext.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
gettext.textdomain(APP) gettext.textdomain(AppConfig.APP_NAME)
_ = gettext.gettext _ = gettext.gettext
@ -41,7 +41,7 @@ class Create:
pth: Path = Path.home() / ".config/wire_py" pth: Path = Path.home() / ".config/wire_py"
pth.mkdir(parents=True, exist_ok=True) pth.mkdir(parents=True, exist_ok=True)
sett: Path = Path.home() / ".config/wire_py/settings" sett: Path = Path.home() / ".config/wire_py/settings"
ks: Path = Path.home() / ".config/wire_py/keys" AppConfig.KEYS_FILE
if sett.exists(): if sett.exists():
pass pass
@ -50,11 +50,11 @@ class Create:
sett.touch() sett.touch()
sett.write_text("[UPDATES]\non\n[THEME]\nlight\n[TOOLTIP]\nTrue\n[AUTOSTART ON]\noff\n") sett.write_text("[UPDATES]\non\n[THEME]\nlight\n[TOOLTIP]\nTrue\n[AUTOSTART ON]\noff\n")
if ks.exists(): if AppConfig.KEYS_FILE.exists():
pass pass
else: else:
ks.touch() AppConfig.KEYS_FILE.touch()
@staticmethod @staticmethod
def files_for_autostart() -> None: def files_for_autostart() -> None:
@ -80,11 +80,11 @@ class Create:
def make_dir() -> None: def make_dir() -> None:
"""Folder Name "tlecdewg" = Tunnel Encrypt Decrypt Wireguard""" """Folder Name "tlecdewg" = Tunnel Encrypt Decrypt Wireguard"""
folder_path: Path = Path("/tmp/tlecdcwg/") AppConfig.TEMP_DIR: Path = Path("/tmp/tlecdcwg/")
if folder_path.exists(): if AppConfig.TEMP_DIR.exists():
pass pass
else: else:
folder_path.mkdir() AppConfig.TEMP_DIR.mkdir()
@staticmethod @staticmethod
def decrypt() -> None: def decrypt() -> None:
@ -138,15 +138,15 @@ class LxTools(tk.Tk):
Path(file).write_text(log_name, encoding="utf-8") Path(file).write_text(log_name, encoding="utf-8")
@staticmethod @staticmethod
def clean_files(folder_path: Path = None, file: Path = None) -> None: def clean_files(TEMP_DIR: Path = None, file: Path = None) -> None:
""" """
method that can be added after need to delete a folder and a file when quitting. method that can be added after need to delete a folder and a file when quitting.
Args: Args:
:param file: default None :param file: default None
:param folder_path: default None :param AppConfig.TEMP_DIR: default None
""" """
if folder_path is not None: if AppConfig.TEMP_DIR is not None:
shutil.rmtree(folder_path) shutil.rmtree(AppConfig.TEMP_DIR)
if file is not None: if file is not None:
Path.unlink(file) Path.unlink(file)
@ -162,6 +162,15 @@ class LxTools(tk.Tk):
tip = True tip = True
return tip return tip
def theme_change(self) -> None:
lines = AppConfig.SETTINGS_FILE.read_text()
if "light\n" in lines:
self.tk.call("set_theme", "light")
else:
self.tk.call("set_theme", "dark")
@staticmethod @staticmethod
def msg_window(img_w: str, img_i: str, w_title: str, w_txt: str, txt2: Optional[str] = None, def msg_window(img_w: str, img_i: str, w_title: str, w_txt: str, txt2: Optional[str] = None,
com: Optional[str] = None) -> None: com: Optional[str] = None) -> None:
@ -392,8 +401,8 @@ class Tunnel:
""" """
Returns a list of Wireguard tunnel names Returns a list of Wireguard tunnel names
""" """
folder_path: Path = Path("/tmp/tlecdcwg/") AppConfig.TEMP_DIR: Path = Path("/tmp/tlecdcwg/")
wg_s: List[str] = os.listdir(folder_path) wg_s: List[str] = os.listdir(AppConfig.TEMP_DIR)
return wg_s return wg_s

10
install
View File

@ -17,7 +17,7 @@ install_file_with(){
exit 0 exit 0
else else
sudo apt install python3-tk && \ sudo apt install python3-tk && \
sudo cp -fv wirepy.py start_wg.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \ sudo cp -fv wirepy.py start_wg.py wp_app_config.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \
sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \ sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \ sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \ sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \
@ -43,7 +43,7 @@ install_arch_d(){
exit 0 exit 0
else else
sudo pacman -S --noconfirm tk python3 python-requests && \ sudo pacman -S --noconfirm tk python3 python-requests && \
sudo cp -fv wirepy.py start_wg.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \ sudo cp -fv wirepy.py start_wg.py wp_app_config.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \
sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \ sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \ sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \ sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \
@ -120,7 +120,7 @@ install(){
exit 0 exit 0
else else
sudo dnf install python3-tkinter -y sudo dnf install python3-tkinter -y
sudo cp -fv wirepy.py start_wg.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \ sudo cp -fv wirepy.py start_wg.py wp_app_config.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \
sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \ sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \ sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \ sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \
@ -145,7 +145,7 @@ install(){
rm -r ~/.config/wire_py && rm -r ~/.config/systemd rm -r ~/.config/wire_py && rm -r ~/.config/systemd
exit 0 exit 0
else else
sudo cp -fv wirepy.py start_wg.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \ sudo cp -fv wirepy.py start_wg.py wp_app_config.py cls_mth_fc.py ssl_encrypt.py ssl_decrypt.py /usr/local/bin/ && \
sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \ sudo cp -uR lx-icons /usr/share/icons/ && sudo cp -uR TK-Themes /usr/share/ && \
sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \ sudo cp -u languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ && \
sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \ sudo cp -fv Wire-Py.desktop /usr/share/applications/ && \
@ -181,7 +181,7 @@ install(){
remove(){ remove(){
sudo rm -f /usr/local/bin/wirepy /usr/local/bin/wirepy.py /usr/local/bin/start_wg.py \ sudo rm -f /usr/local/bin/wirepy /usr/local/bin/wirepy.py /usr/local/bin/start_wg.py \
/usr/local/bin/cls_mth_fc.py /usr/local/bin/ssl_encrypt.py /usr/local/bin/ssl_decrypt.py /usr/local/bin/wp_app_config.py cls_mth_fc.py /usr/local/bin/ssl_encrypt.py /usr/local/bin/ssl_decrypt.py
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
exit 0 exit 0

View File

@ -5,13 +5,12 @@ 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 wp_app_config import AppConfig
uname: Path = Path("/tmp/.log_user") uname: Path = Path("/tmp/.log_user")
log_name = Path(uname).read_text(encoding="utf-8") log_name = Path(uname).read_text(encoding="utf-8")
# Folder Name "tlecdewg" = Tunnel Encrypt Decrypt Wireguard
folder_path: Path = Path("/tmp/tlecdcwg/")
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" PKEYFILE: Path = "/usr/local/etc/ssl/pwgk.pem"
@ -20,16 +19,16 @@ if not keyfile.is_file():
check_call(["openssl", "rsa", "-in", PKEYFILE, "-out", keyfile, "-outform", "PEM", "-pubout"]) check_call(["openssl", "rsa", "-in", PKEYFILE, "-out", keyfile, "-outform", "PEM", "-pubout"])
shutil.chown(keyfile, 1000, 1000) shutil.chown(keyfile, 1000, 1000)
folder_path2 = f"/home/{log_name}/.config/wire_py/" AppConfig.TEMP_DIR2 = f"/home/{log_name}/.config/wire_py/"
detl: list[str] = os.listdir(folder_path2) detl: list[str] = os.listdir(AppConfig.TEMP_DIR2)
os.chdir(folder_path2) os.chdir(AppConfig.TEMP_DIR2)
detl.remove("keys") detl.remove("keys")
detl.remove("settings") detl.remove("settings")
if os.path.exists(f"{folder_path2}pbwgk.pem"): if os.path.exists(f"{AppConfig.TEMP_DIR2}pbwgk.pem"):
detl.remove("pbwgk.pem") detl.remove("pbwgk.pem")
for detunnels in detl: for detunnels in detl:
tlname2 = f"{detunnels[:-4]}.conf" tlname2 = f"{detunnels[:-4]}.conf"
extpath = f"{folder_path}/{tlname2}" extpath = f"{AppConfig.TEMP_DIR}/{tlname2}"
check_call(["openssl", "pkeyutl", "-decrypt", "-inkey", PKEYFILE, "-in", detunnels, check_call(["openssl", "pkeyutl", "-decrypt", "-inkey", PKEYFILE, "-in", detunnels,
"-out", extpath]) "-out", extpath])
shutil.chown(extpath, 1000, 1000) shutil.chown(extpath, 1000, 1000)

View File

@ -6,12 +6,13 @@ 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
uname: Path = Path("/tmp/.log_user") uname: Path = Path("/tmp/.log_user")
log_name = Path(uname).read_text(encoding="utf-8") log_name = Path(uname).read_text(encoding="utf-8")
keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem") keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
folder_path: Path = Path("/tmp/tlecdcwg/")
PKEYFILE = "/usr/local/etc/ssl/pwgk.pem" PKEYFILE = "/usr/local/etc/ssl/pwgk.pem"
if not keyfile.is_file(): if not keyfile.is_file():
@ -19,28 +20,28 @@ if not keyfile.is_file():
check_call(["openssl", "rsa", "-in", PKEYFILE, "-out", keyfile, "-outform", "PEM", "-pubout"]) check_call(["openssl", "rsa", "-in", PKEYFILE, "-out", keyfile, "-outform", "PEM", "-pubout"])
shutil.chown(keyfile, 1000, 1000) shutil.chown(keyfile, 1000, 1000)
if folder_path.exists(): if AppConfig.TEMP_DIR.exists():
tl = os.listdir(f"{folder_path}") tl = os.listdir(f"{AppConfig.TEMP_DIR}")
CPTH: str = f"{keyfile}" CPTH: str = f"{keyfile}"
CRYPTFILES: str = CPTH[:-9] CRYPTFILES: str = CPTH[:-9]
if keyfile.exists() and len(tl) != 0: if keyfile.exists() and len(tl) != 0:
for tunnels in tl: for tunnels in tl:
sourcetl: str = f"{folder_path}/{tunnels}" sourcetl: str = f"{AppConfig.TEMP_DIR}/{tunnels}"
tlname: str = f"{CRYPTFILES}{tunnels[:-5]}.dat" tlname: str = f"{CRYPTFILES}{tunnels[:-5]}.dat"
check_call(["openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out", check_call(["openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out",
tlname,]) tlname,])
else: else:
if folder_path.exists(): if AppConfig.TEMP_DIR.exists():
tl: list[str] = os.listdir(f"{folder_path}") tl: list[str] = os.listdir(f"{AppConfig.TEMP_DIR}")
CPTH: str = f"{keyfile}" CPTH: str = f"{keyfile}"
CRYPTFILES: str = CPTH[:-9] CRYPTFILES: str = CPTH[:-9]
if keyfile.exists() and len(tl) != 0: if keyfile.exists() and len(tl) != 0:
for tunnels in tl: for tunnels in tl:
sourcetl: str = f"{folder_path}/{tunnels}" sourcetl: str = f"{AppConfig.TEMP_DIR}/{tunnels}"
tlname: str = f"{CRYPTFILES}{tunnels[:-5]}.dat" tlname: str = f"{CRYPTFILES}{tunnels[:-5]}.dat"
check_call(["openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out", check_call(["openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out",
tlname]) tlname])

View File

@ -15,31 +15,26 @@ from subprocess import check_call
from tkinter import TclError, filedialog, ttk from tkinter import TclError, filedialog, ttk
from cls_mth_fc import (Create, GiteaUpdate, Tooltip, Tunnel, LxTools) from cls_mth_fc import (Create, GiteaUpdate, Tooltip, Tunnel, LxTools)
from wp_app_config import AppConfig
LxTools.uos() LxTools.uos()
Create.dir_and_files() Create.dir_and_files()
Create.make_dir() Create.make_dir()
Create.decrypt() Create.decrypt()
tcl_path: Path = Path("/usr/share/TK-Themes")
set_file: Path = Path(Path.home() / ".config/wire_py/settings")
keys: Path = Path(Path.home() / ".config/wire_py/keys")
tips = LxTools.if_tip(set_file) tips = LxTools.if_tip(AppConfig.SETTINGS_FILE)
folder_path: Path = Path("/tmp/tlecdcwg/")
user_file = Path("/tmp/.log_user")
# 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year # 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year
VERSION: str = "v. 2.04.1725" VERSION: str = "v. 2.04.1725"
res = GiteaUpdate.api_down("https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases", VERSION, set_file) res = GiteaUpdate.api_down("https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases", VERSION, AppConfig.SETTINGS_FILE)
# Translate # Translate
APP = "wirepy" AppConfig.APP_NAME
LOCALE_DIR = "/usr/share/locale/" locale.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
locale.bindtextdomain(APP, LOCALE_DIR) gettext.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
gettext.bindtextdomain(APP, LOCALE_DIR) gettext.textdomain(AppConfig.APP_NAME)
gettext.textdomain(APP)
_ = gettext.gettext _ = gettext.gettext
img_w: str = r"/usr/share/icons/lx-icons/64/info.png" img_w: str = r"/usr/share/icons/lx-icons/64/info.png"
@ -52,7 +47,7 @@ ie:str = _("Import Error")
pfit: str = _("Please first import tunnel") pfit: str = _("Please first import tunnel")
pstl: str = _("Please select a tunnel from the list") pstl: str = _("Please select a tunnel from the list")
LxTools.sigi(folder_path, user_file) LxTools.sigi(AppConfig.TEMP_DIR, AppConfig.USER_FILE)
class Wirepy(tk.Tk): class Wirepy(tk.Tk):
""" """
@ -62,24 +57,18 @@ class Wirepy(tk.Tk):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.my_tool_tip = None self.my_tool_tip = None
self.x_width = 600 self.x_width = AppConfig.UI_CONFIG["window_size"][0]
self.y_height = 383 self.y_height = AppConfig.UI_CONFIG["window_size"][1]
self.monitor_center_x = int(self.winfo_screenwidth() / 2 - (self.x_width / 2)) self.monitor_center_x = int(self.winfo_screenwidth() / 2 - (self.x_width / 2))
self.monitor_center_y = int(self.winfo_screenheight() / 2 - (self.y_height / 2)) self.monitor_center_y = int(self.winfo_screenheight() / 2 - (self.y_height / 2))
self.resizable(width=False, height=False) self.resizable(AppConfig.UI_CONFIG["resizable_window"][0], AppConfig.UI_CONFIG["resizable_window"][1])
self.title("Wire-Py") self.title(AppConfig.UI_CONFIG["window_title"])
self.geometry(f"{self.x_width}x{self.y_height}+{self.monitor_center_x}+{self.monitor_center_y}") self.geometry(f"{self.x_width}x{self.y_height}+{self.monitor_center_x}+{self.monitor_center_y}")
self.columnconfigure(0, weight=1) self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1) self.rowconfigure(0, weight=1)
self.style = ttk.Style(self) self.style = ttk.Style(self)
self.tk.call("source", f"{tcl_path}/water.tcl") self.tk.call("source", f"{AppConfig.SYSTEM_PATHS["tcl_path"]}/water.tcl")
LxTools.theme_change(self)
lines = set_file.read_text()
if "light\n" in lines:
self.tk.call("set_theme", "light")
else:
self.tk.call("set_theme", "dark")
# Load the image file from the disk # Load the image file from the disk
self.wg_icon = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn.png") self.wg_icon = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn.png")
@ -352,9 +341,9 @@ class FrameWidgets(ttk.Frame):
""" """
if self.tk.call("ttk::style", "theme", "use") == "water-dark": if self.tk.call("ttk::style", "theme", "use") == "water-dark":
self.tk.call("set_theme", "light") self.tk.call("set_theme", "light")
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) # (keepends=True) = not changed lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True) # (keepends=True) = not changed
lines[3] = 'light\n' lines[3] = 'light\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
self.color_label() self.color_label()
def theme_change_dark(self) -> None: def theme_change_dark(self) -> None:
@ -363,9 +352,9 @@ class FrameWidgets(ttk.Frame):
""" """
if not self.tk.call("ttk::style", "theme", "use") == "water-dark": if not self.tk.call("ttk::style", "theme", "use") == "water-dark":
self.tk.call("set_theme", "dark") self.tk.call("set_theme", "dark")
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
lines[3] = 'dark\n' lines[3] = 'dark\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
self.color_label() self.color_label()
@staticmethod @staticmethod
@ -376,14 +365,14 @@ class FrameWidgets(ttk.Frame):
update_res (int): argument that is passed contains 0 or 1 update_res (int): argument that is passed contains 0 or 1
""" """
if update_res == 1: if update_res == 1:
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
lines[1] = 'off\n' lines[1] = 'off\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
else: else:
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
lines[1] = 'on\n' lines[1] = 'on\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
@staticmethod @staticmethod
def tooltip(tip) -> None: def tooltip(tip) -> None:
@ -393,14 +382,14 @@ class FrameWidgets(ttk.Frame):
tip (bool): argument that is passed contains True or False tip (bool): argument that is passed contains True or False
""" """
if tip: if tip:
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
lines[5] = 'False\n' lines[5] = 'False\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
else: else:
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
lines[5] = 'True\n' lines[5] = 'True\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
def enable_check_box(self, _) -> None: def enable_check_box(self, _) -> None:
""" """
@ -425,12 +414,12 @@ class FrameWidgets(ttk.Frame):
pre_key = key[3] pre_key = key[3]
check_call(["nmcli", "connection", "delete", select_tl]) check_call(["nmcli", "connection", "delete", select_tl])
self.l_box.delete(self.select_tunnel[0]) self.l_box.delete(self.select_tunnel[0])
with open(set_file, "r", encoding="utf-8") as set_f6: with open(AppConfig.SETTINGS_FILE, "r", encoding="utf-8") as set_f6:
lines6 = set_f6.readlines() lines6 = set_f6.readlines()
if (select_tl == lines6[7].strip() if (select_tl == lines6[7].strip()
and "off\n" not in lines6[7].strip()): and "off\n" not in lines6[7].strip()):
lines6[7] = "off\n" lines6[7] = "off\n"
with open(set_file, "w", encoding="utf-8") as set_f7: with open(AppConfig.SETTINGS_FILE, "w", encoding="utf-8") as set_f7:
set_f7.writelines(lines6) set_f7.writelines(lines6)
self.selected_option.set(0) self.selected_option.set(0)
self.autoconnect_var.set(_("no Autoconnect")) self.autoconnect_var.set(_("no Autoconnect"))
@ -516,11 +505,11 @@ class FrameWidgets(ttk.Frame):
if self.a != "" and self.a == select_tl: if self.a != "" and self.a == select_tl:
self.a = Tunnel.active() self.a = Tunnel.active()
self.str_var.set(value=self.a) self.str_var.set(value=self.a)
with open(set_file, "r", encoding="utf-8") as set_f5: with open(AppConfig.SETTINGS_FILE, "r", encoding="utf-8") as set_f5:
lines5 = set_f5.readlines() lines5 = set_f5.readlines()
if select_tl == lines5[7].strip() and "off\n" not in lines5[7].strip(): if select_tl == lines5[7].strip() and "off\n" not in lines5[7].strip():
lines5[7] = new_a_connect lines5[7] = new_a_connect
with open(set_file, "w", encoding="utf-8") as theme_set5: with open(AppConfig.SETTINGS_FILE, "w", encoding="utf-8") as theme_set5:
theme_set5.writelines(lines5) theme_set5.writelines(lines5)
self.autoconnect_var.set(value=new_a_connect) self.autoconnect_var.set(value=new_a_connect)
@ -658,9 +647,9 @@ class FrameWidgets(ttk.Frame):
select_tl = self.l_box.get(select_tunnel[0]) select_tl = self.l_box.get(select_tunnel[0])
if self.selected_option.get() == 0: if self.selected_option.get() == 0:
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
lines[7] = 'off\n' lines[7] = 'off\n'
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
tl = Tunnel.list() tl = Tunnel.list()
@ -668,9 +657,9 @@ class FrameWidgets(ttk.Frame):
self.wg_autostart.configure(state="disabled") self.wg_autostart.configure(state="disabled")
if self.selected_option.get() >= 1: if self.selected_option.get() >= 1:
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
lines[7] = select_tl lines[7] = select_tl
Path(set_file).write_text(''.join(lines), encoding="utf-8") Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
except IndexError: except IndexError:
self.selected_option.set(1) self.selected_option.set(1)
@ -683,7 +672,7 @@ class FrameWidgets(ttk.Frame):
Set (on), the selected tunnel is displayed in the label. Set (on), the selected tunnel is displayed in the label.
At (off) the label is first emptied then filled with No Autoconnect At (off) the label is first emptied then filled with No Autoconnect
""" """
lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
if lines[7] != "off\n": if lines[7] != "off\n":
print(f"{lines[7]} starts automatically when the system starts.") print(f"{lines[7]} starts automatically when the system starts.")
@ -771,7 +760,7 @@ class FrameWidgets(ttk.Frame):
""" """
View activ Tunnel in the color green or yellow View activ Tunnel in the color green or yellow
""" """
lines = set_file.read_text() lines = AppConfig.SETTINGS_FILE.read_text()
if "light\n" in lines: if "light\n" in lines:
self.lb_tunnel = ttk.Label(self, textvariable=self.str_var, foreground="green") self.lb_tunnel = ttk.Label(self, textvariable=self.str_var, foreground="green")
@ -865,5 +854,5 @@ if __name__ == "__main__":
window.tk.call("set", "::tk::dialog::file::showHiddenVar", "0") window.tk.call("set", "::tk::dialog::file::showHiddenVar", "0")
window.mainloop() window.mainloop()
LxTools.clean_files(folder_path, user_file) LxTools.clean_files(AppConfig.TEMP_DIR, AppConfig.USER_FILE)
sys.exit(0) sys.exit(0)

View File

@ -8,7 +8,8 @@ class AppConfig:
BASE_DIR = Path.home() BASE_DIR = Path.home()
CONFIG_DIR = BASE_DIR / ".config/wire_py" CONFIG_DIR = BASE_DIR / ".config/wire_py"
TEMP_DIR = Path("/tmp/tlecdcwg") TEMP_DIR = Path("/tmp/tlecdcwg")
USER_FILE = Path("/tmp/.log_user")
# Configuration files # Configuration files
SETTINGS_FILE = CONFIG_DIR / "settings" SETTINGS_FILE = CONFIG_DIR / "settings"
KEYS_FILE = CONFIG_DIR / "keys" KEYS_FILE = CONFIG_DIR / "keys"
@ -29,15 +30,17 @@ class AppConfig:
# UI configuration # UI configuration
UI_CONFIG = { UI_CONFIG = {
"window_title": "Wire-Py", "window_title": "Wire-Py",
"window_size": (800, 600), "window_size": (600, 383),
"font_family": "Ubuntu", "font_family": "Ubuntu",
"font_size": 11 "font_size": 11,
"resizable_window": (False, False)
} }
# System-dependent paths # System-dependent paths
SYSTEM_PATHS = { SYSTEM_PATHS = {
"ssl_decrypt": "/usr/local/bin/ssl_decrypt.py", "ssl_decrypt": "/usr/local/bin/ssl_decrypt.py",
"ssl_encrypt": "/usr/local/bin/ssl_encrypt.py" "ssl_encrypt": "/usr/local/bin/ssl_encrypt.py",
"tcl_path": "/usr/share/TK-Themes"
} }
@classmethod @classmethod