part one more optimization with app_config file
This commit is contained in:
95
wirepy.py
95
wirepy.py
@ -15,7 +15,7 @@ from subprocess import check_call
|
||||
from tkinter import TclError, filedialog, ttk
|
||||
|
||||
from cls_mth_fc import (Create, GiteaUpdate, Tooltip, Tunnel, LxTools)
|
||||
from wp_app_config import AppConfig
|
||||
from wp_app_config import AppConfig, Msg
|
||||
|
||||
LxTools.uos()
|
||||
Create.dir_and_files()
|
||||
@ -24,28 +24,18 @@ Create.decrypt()
|
||||
|
||||
tips = LxTools.if_tip(AppConfig.SETTINGS_FILE)
|
||||
|
||||
|
||||
# 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year
|
||||
VERSION: str = "v. 2.04.1725"
|
||||
|
||||
res = GiteaUpdate.api_down("https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases", VERSION, AppConfig.SETTINGS_FILE)
|
||||
|
||||
# Translate
|
||||
AppConfig.APP_NAME
|
||||
locale.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
|
||||
gettext.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
|
||||
gettext.textdomain(AppConfig.APP_NAME)
|
||||
_ = gettext.gettext
|
||||
_ = AppConfig.setup_translations()
|
||||
|
||||
img_w: str = r"/usr/share/icons/lx-icons/64/info.png"
|
||||
img_i: str = r"/usr/share/icons/lx-icons/48/wg_vpn.png"
|
||||
img_w2: str = r"/usr/share/icons/lx-icons/64/error.png"
|
||||
img_i2: str = r"/usr/share/icons/lx-icons/48/wg_msg.png"
|
||||
sl: str = _("Select tunnel")
|
||||
rnp: str = _("Renaming not possible")
|
||||
ie:str = _("Import Error")
|
||||
pfit: str = _("Please first import tunnel")
|
||||
pstl: str = _("Please select a tunnel from the list")
|
||||
|
||||
LxTools.sigi(AppConfig.TEMP_DIR, AppConfig.USER_FILE)
|
||||
|
||||
@ -71,7 +61,7 @@ class Wirepy(tk.Tk):
|
||||
LxTools.theme_change(self)
|
||||
|
||||
# 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=AppConfig.IMAGE_PATHS["icon_vpn"])
|
||||
|
||||
# Set it as the window icon
|
||||
self.iconphoto(True, self.wg_icon)
|
||||
@ -92,12 +82,12 @@ class FrameWidgets(ttk.Frame):
|
||||
self.dns = None
|
||||
self.address = None
|
||||
self.auto_con = None
|
||||
self.wg_vpn_start = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn-start.png")
|
||||
self.wg_vpn_stop = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn-stop.png")
|
||||
self.imp_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_import.png")
|
||||
self.tr_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_trash.png")
|
||||
self.exp_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_export.png")
|
||||
self.warning_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/64/error.png")
|
||||
self.wg_vpn_start = tk.PhotoImage(file=AppConfig.IMAGE_PATHS["icon_start"])
|
||||
self.wg_vpn_stop = tk.PhotoImage(file=AppConfig.IMAGE_PATHS["icon_stop"])
|
||||
self.imp_pic = tk.PhotoImage(file=AppConfig.IMAGE_PATHS["icon_import"])
|
||||
self.tr_pic = tk.PhotoImage(file=AppConfig.IMAGE_PATHS["icon_trash"])
|
||||
self.exp_pic = tk.PhotoImage(file=AppConfig.IMAGE_PATHS["icon_export"])
|
||||
self.warning_pic = tk.PhotoImage(file=AppConfig.IMAGE_PATHS["icon_error"])
|
||||
|
||||
# Frame for Menu
|
||||
self.menu_frame = ttk.Frame(self)
|
||||
@ -271,7 +261,8 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
# Button Export
|
||||
self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic,
|
||||
command=lambda: Tunnel.export(img_w, img_i, img_w2, img_i2, sl, pfit), padding=0)
|
||||
command=lambda: Tunnel.export(img_w, img_i, img_w2, img_i2,
|
||||
Msg.STR["sel_tl"], Msg.STR["tl_first"]), padding=0)
|
||||
self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
|
||||
|
||||
if self.l_box.size() == 0:
|
||||
@ -309,14 +300,14 @@ class FrameWidgets(ttk.Frame):
|
||||
self.wg_autostart.grid(column=0, row=0, pady=15, padx=15, sticky="nw")
|
||||
|
||||
if self.l_box.size() >= 1 and len(self.l_box.curselection()) >= 1:
|
||||
Tooltip(self.wg_autostart, _("To use the autostart, enable this Checkbox"), tips)
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart"], tips)
|
||||
|
||||
if self.l_box.size() == 0:
|
||||
Tooltip(self.wg_autostart, _("You must have at least one\ntunnel in the list,to use the autostart"), tips)
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart_info"], tips)
|
||||
|
||||
else:
|
||||
|
||||
Tooltip(self.wg_autostart, _("To use the autostart, a tunnel must be selected from the list"), tips)
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart"], tips)
|
||||
|
||||
self.on_off()
|
||||
|
||||
@ -459,30 +450,34 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
if self.l_box.size() != 0:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, sl, pstl)
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["sel_tl"], Msg.STR["sel_list"])
|
||||
|
||||
else:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, sl, pfit)
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["sel_tl"], Msg.STR["tl_first"])
|
||||
|
||||
def tl_rename(self) -> None:
|
||||
"""
|
||||
method to rename a tunnel
|
||||
"""
|
||||
name_of_file = LxTools.get_file_name(AppConfig.TEMP_DIR)
|
||||
special_characters = ["\\", "/", "{", "}", " "]
|
||||
|
||||
if len(self.lb_rename.get()) > 12:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, rnp, _("The new name may contain only 12 characters"))
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["ren_err"], Msg.STR["sign_len"])
|
||||
|
||||
elif len(self.lb_rename.get()) == 0:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, rnp, _("At least one character must be entered"))
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["ren_err"], Msg.STR["zero_signs"])
|
||||
|
||||
elif any(ch in special_characters for ch in self.lb_rename.get()):
|
||||
|
||||
msg_t = _("No valid sign. These must not be used.\nBlank, Slash, Backslash and { }\n")
|
||||
LxTools.msg_window(img_w, img_i2, rnp, msg_t)
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["ren_err"], Msg.STR["false_signs"])
|
||||
|
||||
elif self.lb_rename.get() in name_of_file:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["ren_err"], Msg.STR["is_in_use"])
|
||||
|
||||
else:
|
||||
|
||||
@ -491,7 +486,7 @@ class FrameWidgets(ttk.Frame):
|
||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||
|
||||
# nmcli connection modify old connection.id iphone
|
||||
check_call(["nmcli", "connection", "modify", select_tl, "connection.id", self.lb_rename.get()])
|
||||
subprocess.check_output(["nmcli", "connection", "modify", select_tl, "connection.id", self.lb_rename.get()], text=True)
|
||||
source = Path(f"/tmp/tlecdcwg/{select_tl}.conf")
|
||||
destination = source.with_name(f"{self.lb_rename.get()}.conf")
|
||||
source.replace(destination)
|
||||
@ -515,11 +510,14 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
except IndexError:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, rnp, pstl)
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["ren_err"], Msg.STR["sel_list"])
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
except EOFError as e:
|
||||
print(e)
|
||||
|
||||
def import_sl(self) -> None:
|
||||
"""
|
||||
validity check of wireguard config files
|
||||
@ -543,18 +541,17 @@ class FrameWidgets(ttk.Frame):
|
||||
p_key = AppConfig.KEYS_FILE.read_text(encoding="utf-8")
|
||||
if pre_key in p_key or f"{pre_key}\n" in p_key:
|
||||
|
||||
msg_t = _("Tunnel already available!\nPlease use another file for import")
|
||||
LxTools.msg_window(img_w2, img_i2, ie, msg_t)
|
||||
LxTools.msg_window(img_w2, img_i2, Msg.STR["imp_err"], Msg.STR["tl_exist"])
|
||||
|
||||
else:
|
||||
|
||||
with open(AppConfig.KEYS_FILE, "a", encoding="utf-8") as keyfile:
|
||||
keyfile.write(f"{pre_key}\r")
|
||||
if len(path_split1) > 17:
|
||||
p1 = shutil.copy(filepath, "/tmp/tlecdcwg/")
|
||||
p1 = shutil.copy(filepath, AppConfig.TEMP_DIR)
|
||||
path_split = path_split1[len(path_split1) - 17:]
|
||||
os.rename(p1, f"/tmp/tlecdcwg/{path_split}")
|
||||
new_conf = f"/tmp/tlecdcwg/{path_split}"
|
||||
os.rename(p1, f"{AppConfig.TEMP_DIR}/{path_split}")
|
||||
new_conf = f"{AppConfig.TEMP_DIR}/{path_split}"
|
||||
if self.a != "":
|
||||
check_call(["nmcli", "connection", "down", self.a])
|
||||
self.reset_fields()
|
||||
@ -565,7 +562,7 @@ class FrameWidgets(ttk.Frame):
|
||||
Create.encrypt()
|
||||
|
||||
else:
|
||||
shutil.copy(filepath, "/tmp/tlecdcwg/")
|
||||
shutil.copy(filepath, f"{AppConfig.TEMP_DIR}/")
|
||||
if self.a != "":
|
||||
check_call(["nmcli", "connection", "down", self.a])
|
||||
self.reset_fields()
|
||||
@ -583,16 +580,13 @@ class FrameWidgets(ttk.Frame):
|
||||
self.l_box.update()
|
||||
self.l_box.selection_set(0)
|
||||
|
||||
Tooltip(self.wg_autostart, _("To use the autostart, enable this Checkbox"), tips)
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart"], tips)
|
||||
|
||||
Tooltip(self.btn_tr, _("Click to delete a Wireguard Tunnel\nSelect from the list!")
|
||||
, tips,)
|
||||
Tooltip(self.btn_tr, Msg.TTIP["trash_tl"], tips)
|
||||
|
||||
Tooltip(self.btn_exp, _(" Click to export all\nWireguard Tunnel to Zipfile")
|
||||
, tips)
|
||||
Tooltip(self.btn_exp, Msg.TTIP["export_tl"], tips)
|
||||
|
||||
Tooltip(self.btn_rename, _("To rename a tunnel, you need to\nselect a tunnel from"
|
||||
" the list"), tips)
|
||||
Tooltip(self.btn_rename, Msg.TTIP["rename_tl"], tips)
|
||||
|
||||
self.lb_rename.insert(0, "Max. 12 characters!")
|
||||
self.str_var = tk.StringVar()
|
||||
@ -606,8 +600,7 @@ class FrameWidgets(ttk.Frame):
|
||||
pass
|
||||
else:
|
||||
|
||||
msg_t = _("Oh... no valid Wireguard File!\nPlease select a valid Wireguard File")
|
||||
LxTools.msg_window(img_w2, img_i2, ie, msg_t)
|
||||
LxTools.msg_window(img_w2, img_i2, Msg.STR["imp_err"], Msg.STR["no_valid_file"])
|
||||
|
||||
except EOFError as e:
|
||||
print(e)
|
||||
@ -738,7 +731,7 @@ class FrameWidgets(ttk.Frame):
|
||||
command=lambda: self.wg_switch("stop"), padding=0)
|
||||
self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
|
||||
|
||||
Tooltip(self.btn_stst, _("Click to stop selected Wireguard Tunnel"), tips)
|
||||
Tooltip(self.btn_stst, Msg.TTIP["stop_tl"], tips)
|
||||
|
||||
def start(self) -> None:
|
||||
"""
|
||||
@ -750,9 +743,9 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
tl = Tunnel.list()
|
||||
if len(tl) == 0:
|
||||
Tooltip(self.btn_stst, _("No tunnels to start in the list"), tips)
|
||||
Tooltip(self.btn_stst, Msg.TTIP["empty_list"], tips)
|
||||
else:
|
||||
Tooltip(self.btn_stst, _("Click to start selected Wireguard Tunnel"), tips)
|
||||
Tooltip(self.btn_stst, Msg.TTIP["start_tl"], tips)
|
||||
|
||||
def color_label(self) -> None:
|
||||
"""
|
||||
@ -789,11 +782,11 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
if self.l_box.size() != 0:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, sl, pstl)
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["sel_tl"], Msg.STR["sel_list"])
|
||||
|
||||
else:
|
||||
|
||||
LxTools.msg_window(img_w, img_i2, sl, pfit)
|
||||
LxTools.msg_window(img_w, img_i2, Msg.STR["sel_tl"], Msg.STR["tl_first"])
|
||||
|
||||
def handle_connection_state(self, action: str, tunnel_name: str = None) -> None:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user