fix message window a path errors
This commit is contained in:
536
wirepy.py
536
wirepy.py
@ -2,8 +2,6 @@
|
||||
"""
|
||||
this script is a simple GUI for managing Wireguard Tunnels
|
||||
"""
|
||||
import gettext
|
||||
import locale
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@ -14,7 +12,15 @@ from pathlib import Path
|
||||
from subprocess import check_call
|
||||
from tkinter import TclError, filedialog, ttk
|
||||
|
||||
from common_tools import (ConfigManager, ThemeManager, Create, GiteaUpdate, Tunnel, Tooltip, LxTools)
|
||||
from common_tools import (
|
||||
ConfigManager,
|
||||
ThemeManager,
|
||||
Create,
|
||||
GiteaUpdate,
|
||||
Tunnel,
|
||||
Tooltip,
|
||||
LxTools,
|
||||
)
|
||||
from wp_app_config import AppConfig, Msg
|
||||
|
||||
LxTools.uos()
|
||||
@ -22,26 +28,30 @@ Create.dir_and_files()
|
||||
Create.make_dir()
|
||||
Create.decrypt()
|
||||
|
||||
|
||||
class Wirepy(tk.Tk):
|
||||
"""
|
||||
Class Wirepy this is the Main Window of wirepy
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Hide the window initially
|
||||
self.withdraw()
|
||||
|
||||
|
||||
self.my_tool_tip = None
|
||||
self.x_width = AppConfig.UI_CONFIG["window_size"][0]
|
||||
self.y_height = AppConfig.UI_CONFIG["window_size"][1]
|
||||
|
||||
|
||||
# Set the window size
|
||||
self.geometry(f"{self.x_width}x{self.y_height}")
|
||||
self.resizable(AppConfig.UI_CONFIG["resizable_window"][0],
|
||||
AppConfig.UI_CONFIG["resizable_window"][1])
|
||||
self.resizable(
|
||||
AppConfig.UI_CONFIG["resizable_window"][0],
|
||||
AppConfig.UI_CONFIG["resizable_window"][1],
|
||||
)
|
||||
self.title(AppConfig.UI_CONFIG["window_title"])
|
||||
|
||||
|
||||
self.columnconfigure(0, weight=1)
|
||||
self.rowconfigure(0, weight=1)
|
||||
self.tk.call("source", f"{AppConfig.SYSTEM_PATHS['tcl_path']}/water.tcl")
|
||||
@ -57,10 +67,10 @@ class Wirepy(tk.Tk):
|
||||
|
||||
# Add the widgets
|
||||
FrameWidgets(self).grid()
|
||||
|
||||
|
||||
# Center the window on the primary monitor
|
||||
LxTools.center_window_cross_platform(self, self.x_width, self.y_height)
|
||||
|
||||
|
||||
# Now show the window after it has been positioned
|
||||
self.after(10, self.deiconify)
|
||||
|
||||
@ -69,9 +79,10 @@ class FrameWidgets(ttk.Frame):
|
||||
"""
|
||||
ttk frame class for better structure
|
||||
"""
|
||||
|
||||
def __init__(self, container, **kwargs):
|
||||
super().__init__(container, **kwargs)
|
||||
|
||||
|
||||
self.lb_tunnel = None
|
||||
self.btn_stst = None
|
||||
self.endpoint = None
|
||||
@ -100,13 +111,16 @@ class FrameWidgets(ttk.Frame):
|
||||
else:
|
||||
# If it's a string or something else
|
||||
self.tooltip_state.set(str(state) == "True")
|
||||
|
||||
self.tooltip_label = tk.StringVar() # StringVar-Variable for tooltip label for view Disabled/Enabled
|
||||
self.tooltip_update_label()
|
||||
self.update_label = tk.StringVar() # StringVar-Variable for update label
|
||||
self.update_tooltip = tk.StringVar() # StringVar-Variable for update tooltip please not remove!
|
||||
self.update_foreground = tk.StringVar(value="red")
|
||||
|
||||
self.tooltip_label = (
|
||||
tk.StringVar()
|
||||
) # StringVar-Variable for tooltip label for view Disabled/Enabled
|
||||
self.tooltip_update_label()
|
||||
self.update_label = tk.StringVar() # StringVar-Variable for update label
|
||||
self.update_tooltip = (
|
||||
tk.StringVar()
|
||||
) # StringVar-Variable for update tooltip please not remove!
|
||||
self.update_foreground = tk.StringVar(value="red")
|
||||
|
||||
# Frame for Menu
|
||||
self.menu_frame = ttk.Frame(self)
|
||||
@ -118,7 +132,9 @@ class FrameWidgets(ttk.Frame):
|
||||
self.version_lb.config(font=("Ubuntu", 11), foreground="#00c4ff")
|
||||
self.version_lb.grid(column=0, row=0, rowspan=4, padx=10)
|
||||
|
||||
Tooltip(self.version_lb, f"Version: {AppConfig.VERSION[2:]}", self.tooltip_state)
|
||||
Tooltip(
|
||||
self.version_lb, f"Version: {AppConfig.VERSION[2:]}", self.tooltip_state
|
||||
)
|
||||
|
||||
self.options_btn = ttk.Menubutton(self.menu_frame, text=_("Options"))
|
||||
self.options_btn.grid(column=1, columnspan=1, row=0)
|
||||
@ -128,27 +144,37 @@ class FrameWidgets(ttk.Frame):
|
||||
self.set_update = tk.IntVar()
|
||||
self.settings = tk.Menu(self, relief="flat")
|
||||
self.options_btn.configure(menu=self.settings, style="Toolbutton")
|
||||
self.settings.add_checkbutton(label=_("Disable Updates"),
|
||||
command=lambda: self.update_setting(self.set_update.get()), variable=self.set_update)
|
||||
self.settings.add_checkbutton(
|
||||
label=_("Disable Updates"),
|
||||
command=lambda: self.update_setting(self.set_update.get()),
|
||||
variable=self.set_update,
|
||||
)
|
||||
|
||||
self.updates_lb = ttk.Label(self.menu_frame, textvariable=self.update_label)
|
||||
self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10)
|
||||
self.updates_lb.grid_remove()
|
||||
self.update_label.trace_add("write", self.update_label_display)
|
||||
self.update_foreground.trace_add("write", self.update_label_display)
|
||||
res = GiteaUpdate.api_down(AppConfig.UPDATE_URL, AppConfig.VERSION, ConfigManager.get("updates"))
|
||||
res = GiteaUpdate.api_down(
|
||||
AppConfig.UPDATE_URL, AppConfig.VERSION, ConfigManager.get("updates")
|
||||
)
|
||||
self.update_ui_for_update(res)
|
||||
|
||||
# Tooltip Menu
|
||||
self.settings.add_command(label=self.tooltip_label.get(), command=self.tooltips_toggle)
|
||||
# Label show dark or light
|
||||
self.settings.add_command(
|
||||
label=self.tooltip_label.get(), command=self.tooltips_toggle
|
||||
)
|
||||
# Label show dark or light
|
||||
self.theme_label = tk.StringVar()
|
||||
self.update_theme_label()
|
||||
self.settings.add_command(label=self.theme_label.get(), command=self.on_theme_toggle)
|
||||
self.update_theme_label()
|
||||
self.settings.add_command(
|
||||
label=self.theme_label.get(), command=self.on_theme_toggle
|
||||
)
|
||||
|
||||
# About BTN Menu / Label
|
||||
self.about_btn = ttk.Button(
|
||||
self.menu_frame, text=_("About"), style="Toolbutton", command=self.about)
|
||||
self.menu_frame, text=_("About"), style="Toolbutton", command=self.about
|
||||
)
|
||||
self.about_btn.grid(column=2, columnspan=2, row=0)
|
||||
self.readme = tk.Menu(self)
|
||||
|
||||
@ -172,7 +198,9 @@ class FrameWidgets(ttk.Frame):
|
||||
# Bottom Frame 4
|
||||
self.lb_frame3 = ttk.Frame(self)
|
||||
self.lb_frame3.configure(relief="flat")
|
||||
self.lb_frame3.grid(column=0, row=5, columnspan=4, sticky="snew", padx=2, pady=2)
|
||||
self.lb_frame3.grid(
|
||||
column=0, row=5, columnspan=4, sticky="snew", padx=2, pady=2
|
||||
)
|
||||
|
||||
# Bottom Frame 5
|
||||
self.lb_frame4 = ttk.Frame(self)
|
||||
@ -205,7 +233,9 @@ class FrameWidgets(ttk.Frame):
|
||||
self.l_box.grid(column=1, rowspan=4, row=0, sticky="ns")
|
||||
self.l_box.event_add("<<ClickEvent>>", "<Button-1>")
|
||||
self.l_box.bind("<<ClickEvent>>", self.enable_check_box)
|
||||
self.scrollbar = ttk.Scrollbar(self.lb_frame_btn_lbox, orient="vertical", command=self.l_box.yview)
|
||||
self.scrollbar = ttk.Scrollbar(
|
||||
self.lb_frame_btn_lbox, orient="vertical", command=self.l_box.yview
|
||||
)
|
||||
self.scrollbar.grid(column=1, rowspan=4, row=0, sticky="nse")
|
||||
self.l_box.configure(yscrollcommand=self.scrollbar.set)
|
||||
|
||||
@ -230,14 +260,24 @@ class FrameWidgets(ttk.Frame):
|
||||
self.show_data()
|
||||
|
||||
# Button Import
|
||||
self.btn_i = ttk.Button(self.lb_frame_btn_lbox, image=self.imp_pic, command=self.import_sl, padding=0)
|
||||
self.btn_i = ttk.Button(
|
||||
self.lb_frame_btn_lbox,
|
||||
image=self.imp_pic,
|
||||
command=self.import_sl,
|
||||
padding=0,
|
||||
)
|
||||
self.btn_i.grid(column=0, row=1, padx=15, pady=8)
|
||||
|
||||
Tooltip(self.btn_i, Msg.TTIP["import_tl"], self.tooltip_state)
|
||||
|
||||
# Button Trash
|
||||
self.btn_tr = ttk.Button(self.lb_frame_btn_lbox, image=self.tr_pic, command=self.delete, padding=0,
|
||||
style="CButton.TButton")
|
||||
self.btn_tr = ttk.Button(
|
||||
self.lb_frame_btn_lbox,
|
||||
image=self.tr_pic,
|
||||
command=self.delete,
|
||||
padding=0,
|
||||
style="CButton.TButton",
|
||||
)
|
||||
self.btn_tr.grid(column=0, row=2, padx=15, pady=8)
|
||||
|
||||
if self.l_box.size() == 0:
|
||||
@ -246,12 +286,20 @@ class FrameWidgets(ttk.Frame):
|
||||
Tooltip(self.btn_tr, Msg.TTIP["trash_tl"], self.tooltip_state)
|
||||
|
||||
# Button Export
|
||||
self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic,
|
||||
command=lambda: Tunnel.export(AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_vpn"], AppConfig.IMAGE_PATHS["icon_error"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["sel_tl"], Msg.STR["tl_first"]), padding=0)
|
||||
|
||||
self.btn_exp = ttk.Button(
|
||||
self.lb_frame_btn_lbox,
|
||||
image=self.exp_pic,
|
||||
command=lambda: Tunnel.export(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_vpn"],
|
||||
AppConfig.IMAGE_PATHS["icon_error"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
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:
|
||||
@ -266,13 +314,31 @@ class FrameWidgets(ttk.Frame):
|
||||
self.lb_rename.config(state="disable")
|
||||
|
||||
if self.l_box.size() != 0:
|
||||
Tooltip(self.lb_rename, Msg.TTIP["rename_tl"], self.tooltip_state, x_offset= -120, y_offset=-70)
|
||||
Tooltip(
|
||||
self.lb_rename,
|
||||
Msg.TTIP["rename_tl"],
|
||||
self.tooltip_state,
|
||||
x_offset=-120,
|
||||
y_offset=-70,
|
||||
)
|
||||
else:
|
||||
Tooltip(self.lb_rename, Msg.TTIP["rename_tl_info"], self.tooltip_state, x_offset=-180, y_offset=-50)
|
||||
Tooltip(
|
||||
self.lb_rename,
|
||||
Msg.TTIP["rename_tl_info"],
|
||||
self.tooltip_state,
|
||||
x_offset=-180,
|
||||
y_offset=-50,
|
||||
)
|
||||
|
||||
# Button Rename
|
||||
self.btn_rename = ttk.Button(self.lb_frame4, text=_("Rename"), state="disable", command=self.tl_rename,
|
||||
padding=4, style="RnButton.TButton")
|
||||
self.btn_rename = ttk.Button(
|
||||
self.lb_frame4,
|
||||
text=_("Rename"),
|
||||
state="disable",
|
||||
command=self.tl_rename,
|
||||
padding=4,
|
||||
style="RnButton.TButton",
|
||||
)
|
||||
self.btn_rename.grid(column=3, row=0, padx=5, pady=10, sticky="ne")
|
||||
|
||||
# Check Buttons
|
||||
@ -281,22 +347,46 @@ class FrameWidgets(ttk.Frame):
|
||||
self.autoconnect_var.set(f"{self.auto_con}")
|
||||
|
||||
# Frame for Labels, Entry and Button
|
||||
self.autoconnect = ttk.Label(self.lb_frame3, textvariable=self.autoconnect_var, width=15)
|
||||
self.autoconnect = ttk.Label(
|
||||
self.lb_frame3, textvariable=self.autoconnect_var, width=15
|
||||
)
|
||||
self.autoconnect.config(font=("Ubuntu", 11))
|
||||
self.autoconnect.grid(column=1, row=0, sticky="e", pady=19)
|
||||
self.wg_autostart = ttk.Checkbutton(self.lb_frame3, text=_("Autoconnect on:"), variable=self.selected_option,
|
||||
command=self.box_set)
|
||||
self.wg_autostart = ttk.Checkbutton(
|
||||
self.lb_frame3,
|
||||
text=_("Autoconnect on:"),
|
||||
variable=self.selected_option,
|
||||
command=self.box_set,
|
||||
)
|
||||
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, Msg.TTIP["autostart"], self.tooltip_state, x_offset=-10, y_offset=-40)
|
||||
Tooltip(
|
||||
self.wg_autostart,
|
||||
Msg.TTIP["autostart"],
|
||||
self.tooltip_state,
|
||||
x_offset=-10,
|
||||
y_offset=-40,
|
||||
)
|
||||
|
||||
if self.l_box.size() == 0:
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart_info"], self.tooltip_state, x_offset=30, y_offset=-50)
|
||||
Tooltip(
|
||||
self.wg_autostart,
|
||||
Msg.TTIP["autostart_info"],
|
||||
self.tooltip_state,
|
||||
x_offset=30,
|
||||
y_offset=-50,
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart"], self.tooltip_state, x_offset=-10, y_offset=-40)
|
||||
Tooltip(
|
||||
self.wg_autostart,
|
||||
Msg.TTIP["autostart"],
|
||||
self.tooltip_state,
|
||||
x_offset=-10,
|
||||
y_offset=-40,
|
||||
)
|
||||
|
||||
self.on_off()
|
||||
|
||||
@ -316,10 +406,10 @@ class FrameWidgets(ttk.Frame):
|
||||
def update_ui_for_update(self, res):
|
||||
"""Update UI elements based on update check result"""
|
||||
# First, remove the update button if it exists to avoid conflicts
|
||||
if hasattr(self, 'update_btn'):
|
||||
if hasattr(self, "update_btn"):
|
||||
self.update_btn.grid_forget()
|
||||
delattr(self, 'update_btn')
|
||||
|
||||
delattr(self, "update_btn")
|
||||
|
||||
if res == "False":
|
||||
self.set_update.set(value=1)
|
||||
self.update_label.set(_("Update search off"))
|
||||
@ -328,44 +418,50 @@ class FrameWidgets(ttk.Frame):
|
||||
self.update_foreground.set("")
|
||||
# Set tooltip for the label
|
||||
Tooltip(self.updates_lb, self.update_tooltip.get(), self.tooltip_state)
|
||||
|
||||
|
||||
elif res == "No Internet Connection!":
|
||||
self.update_label.set(_("No Server Connection!"))
|
||||
self.update_foreground.set("red")
|
||||
# Set tooltip for "No Server Connection"
|
||||
Tooltip(self.updates_lb, _("Could not connect to update server"), self.tooltip_state)
|
||||
|
||||
Tooltip(
|
||||
self.updates_lb,
|
||||
_("Could not connect to update server"),
|
||||
self.tooltip_state,
|
||||
)
|
||||
|
||||
elif res == "No Updates":
|
||||
self.update_label.set(_("No Updates"))
|
||||
self.update_tooltip.set(_("Congratulations! Wire-Py is up to date"))
|
||||
self.update_foreground.set("")
|
||||
# Set tooltip for the label
|
||||
Tooltip(self.updates_lb, self.update_tooltip.get(), self.tooltip_state)
|
||||
|
||||
|
||||
else:
|
||||
self.set_update.set(value=0)
|
||||
update_text = f"Update {res} {_('available!')}"
|
||||
|
||||
# Clear the label text since we'll show the button instead
|
||||
self.update_label.set("")
|
||||
|
||||
|
||||
# Create the update button
|
||||
self.update_btn = ttk.Menubutton(self.menu_frame, text=update_text)
|
||||
self.update_btn.grid(column=4, columnspan=3, row=0, padx=0)
|
||||
Tooltip(self.update_btn, _("Click to download new version"), self.tooltip_state)
|
||||
|
||||
Tooltip(
|
||||
self.update_btn, _("Click to download new version"), self.tooltip_state
|
||||
)
|
||||
|
||||
self.download = tk.Menu(self, relief="flat")
|
||||
self.update_btn.configure(menu=self.download, style="Toolbutton")
|
||||
self.download.add_command(
|
||||
label=_("Download"),
|
||||
command=lambda: GiteaUpdate.download(
|
||||
f"{AppConfig.DOWNLOAD_URL}/{res}.zip",
|
||||
res,
|
||||
res,
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_vpn"],
|
||||
AppConfig.IMAGE_PATHS["icon_error"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"]
|
||||
)
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@ -373,15 +469,26 @@ class FrameWidgets(ttk.Frame):
|
||||
"""
|
||||
a tk.Toplevel window
|
||||
"""
|
||||
|
||||
def link_btn() -> str | None:
|
||||
webbrowser.open("https://git.ilunix.de/punix/Wire-Py")
|
||||
|
||||
msg_t = _("Wire-Py a simple Wireguard Gui for Linux systems.\n\n"
|
||||
"Wire-Py is open source software written in Python.\n\n"
|
||||
"Email: polunga40@unity-mail.de also likes for donation.\n\n"
|
||||
"Use without warranty!\n")
|
||||
msg_t = _(
|
||||
"Wire-Py a simple Wireguard Gui for Linux systems.\n\n"
|
||||
"Wire-Py is open source software written in Python.\n\n"
|
||||
"Email: polunga40@unity-mail.de also likes for donation.\n\n"
|
||||
"Use without warranty!\n"
|
||||
)
|
||||
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_vpn"],
|
||||
AppConfig.IMAGE_PATHS["icon_vpn"],
|
||||
_("Info"),
|
||||
msg_t,
|
||||
_("Go to Wire-Py git"),
|
||||
link_btn,
|
||||
)
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_vpn"], AppConfig.IMAGE_PATHS["icon_vpn"], _("Info"), msg_t, _("Go to Wire-Py git"), link_btn)
|
||||
def update_setting(self, update_res) -> None:
|
||||
"""write off or on in file
|
||||
Args:
|
||||
@ -398,14 +505,16 @@ class FrameWidgets(ttk.Frame):
|
||||
# When enabling updates, we need to actually check for updates
|
||||
try:
|
||||
# Force a fresh check by passing "on" as the update setting
|
||||
res = GiteaUpdate.api_down(AppConfig.UPDATE_URL, AppConfig.VERSION, "on")
|
||||
|
||||
res = GiteaUpdate.api_down(
|
||||
AppConfig.UPDATE_URL, AppConfig.VERSION, "on"
|
||||
)
|
||||
|
||||
# Make sure UI is updated regardless of previous state
|
||||
if hasattr(self, 'update_btn'):
|
||||
if hasattr(self, "update_btn"):
|
||||
self.update_btn.grid_forget()
|
||||
if hasattr(self, 'updates_lb'):
|
||||
if hasattr(self, "updates_lb"):
|
||||
self.updates_lb.grid_forget()
|
||||
|
||||
|
||||
# Now update the UI with the fresh result
|
||||
self.update_ui_for_update(res)
|
||||
except Exception as e:
|
||||
@ -431,10 +540,10 @@ class FrameWidgets(ttk.Frame):
|
||||
ConfigManager.set("tooltips", str(new_bool_state))
|
||||
# Update the tooltip_state variable for immediate effect
|
||||
self.tooltip_state.set(new_bool_state)
|
||||
|
||||
|
||||
# Update the menu label
|
||||
self.tooltip_update_label()
|
||||
|
||||
|
||||
# Update the menu entry - find the correct index
|
||||
# This assumes it's the third item (index 2) in your menu
|
||||
self.settings.entryconfigure(1, label=self.tooltip_label.get())
|
||||
@ -461,8 +570,12 @@ class FrameWidgets(ttk.Frame):
|
||||
"""
|
||||
Start Button
|
||||
"""
|
||||
self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_start,
|
||||
command=lambda: self.wg_switch("start"), padding=0)
|
||||
self.btn_stst = ttk.Button(
|
||||
self.lb_frame_btn_lbox,
|
||||
image=self.wg_vpn_start,
|
||||
command=lambda: self.wg_switch("start"),
|
||||
padding=0,
|
||||
)
|
||||
self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
|
||||
|
||||
tl = LxTools.get_file_name(AppConfig.TEMP_DIR)
|
||||
@ -491,12 +604,16 @@ class FrameWidgets(ttk.Frame):
|
||||
"""
|
||||
View activ Tunnel in the color green or yellow
|
||||
"""
|
||||
if ConfigManager.get("theme") == "light":
|
||||
|
||||
self.lb_tunnel = ttk.Label(self, textvariable=self.str_var, foreground="green")
|
||||
if ConfigManager.get("theme") == "light":
|
||||
|
||||
self.lb_tunnel = ttk.Label(
|
||||
self, textvariable=self.str_var, foreground="green"
|
||||
)
|
||||
|
||||
else:
|
||||
self.lb_tunnel = ttk.Label(self, textvariable=self.str_var, foreground="yellow")
|
||||
self.lb_tunnel = ttk.Label(
|
||||
self, textvariable=self.str_var, foreground="yellow"
|
||||
)
|
||||
|
||||
self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
|
||||
self.lb_tunnel.grid(column=2, padx=10, row=1)
|
||||
@ -505,8 +622,12 @@ class FrameWidgets(ttk.Frame):
|
||||
"""
|
||||
Stop Button
|
||||
"""
|
||||
self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_stop,
|
||||
command=lambda: self.wg_switch("stop"), padding=0)
|
||||
self.btn_stst = ttk.Button(
|
||||
self.lb_frame_btn_lbox,
|
||||
image=self.wg_vpn_stop,
|
||||
command=lambda: self.wg_switch("stop"),
|
||||
padding=0,
|
||||
)
|
||||
self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
|
||||
|
||||
Tooltip(self.btn_stst, Msg.TTIP["stop_tl"], self.tooltip_state)
|
||||
@ -525,58 +646,91 @@ class FrameWidgets(ttk.Frame):
|
||||
Create.dir_and_files()
|
||||
try:
|
||||
filepath = filedialog.askopenfilename(
|
||||
initialdir=f"{Path.home()}",
|
||||
initialdir=f"{Path.home()}",
|
||||
title=_("Select Wireguard config File"),
|
||||
filetypes=[(_("WG config files"), "*.conf")]
|
||||
filetypes=[(_("WG config files"), "*.conf")],
|
||||
)
|
||||
|
||||
|
||||
# Überprüfe, ob der Benutzer den Dialog abgebrochen hat
|
||||
if not filepath:
|
||||
print("File import: abort by user...")
|
||||
return
|
||||
|
||||
|
||||
with open(filepath, "r", encoding="utf-8") as file:
|
||||
read = file.read()
|
||||
|
||||
|
||||
path_split = filepath.split("/")
|
||||
path_split1 = path_split[-1]
|
||||
|
||||
if "PrivateKey = " in read and "PublicKey = " in read and "Endpoint =" in read:
|
||||
|
||||
if (
|
||||
"PrivateKey = " in read
|
||||
and "PublicKey = " in read
|
||||
and "Endpoint =" in read
|
||||
):
|
||||
with open(filepath, "r", encoding="utf-8") as file:
|
||||
key = Tunnel.con_to_dict(file)
|
||||
pre_key = key[3]
|
||||
|
||||
|
||||
if len(pre_key) != 0:
|
||||
p_key = AppConfig.KEYS_FILE.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
if pre_key in p_key or f"{pre_key}\n" in p_key:
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_error"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["imp_err"], Msg.STR["tl_exist"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_error"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["imp_err"],
|
||||
Msg.STR["tl_exist"],
|
||||
)
|
||||
else:
|
||||
with open(AppConfig.KEYS_FILE, "a", encoding="utf-8") as keyfile:
|
||||
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, AppConfig.TEMP_DIR)
|
||||
path_split = path_split1[len(path_split1) - 17:]
|
||||
path_split = path_split1[len(path_split1) - 17 :]
|
||||
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()
|
||||
|
||||
subprocess.check_output(["nmcli", "connection", "import", "type", "wireguard", "file", new_conf], text=True)
|
||||
|
||||
subprocess.check_output(
|
||||
[
|
||||
"nmcli",
|
||||
"connection",
|
||||
"import",
|
||||
"type",
|
||||
"wireguard",
|
||||
"file",
|
||||
new_conf,
|
||||
],
|
||||
text=True,
|
||||
)
|
||||
Create.encrypt()
|
||||
else:
|
||||
shutil.copy(filepath, f"{AppConfig.TEMP_DIR}/")
|
||||
|
||||
|
||||
if self.a != "":
|
||||
check_call(["nmcli", "connection", "down", self.a])
|
||||
self.reset_fields()
|
||||
|
||||
subprocess.check_output(["nmcli", "connection", "import", "type", "wireguard", "file", filepath], text=True)
|
||||
|
||||
subprocess.check_output(
|
||||
[
|
||||
"nmcli",
|
||||
"connection",
|
||||
"import",
|
||||
"type",
|
||||
"wireguard",
|
||||
"file",
|
||||
filepath,
|
||||
],
|
||||
text=True,
|
||||
)
|
||||
Create.encrypt()
|
||||
|
||||
|
||||
self.str_var.set("")
|
||||
self.a = Tunnel.active()
|
||||
self.l_box.insert(0, self.a)
|
||||
@ -584,23 +738,45 @@ class FrameWidgets(ttk.Frame):
|
||||
self.l_box.selection_clear(0, tk.END)
|
||||
self.l_box.update()
|
||||
self.l_box.selection_set(0)
|
||||
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart"], self.tooltip_state, x_offset=-10, y_offset=-40)
|
||||
|
||||
Tooltip(
|
||||
self.wg_autostart,
|
||||
Msg.TTIP["autostart"],
|
||||
self.tooltip_state,
|
||||
x_offset=-10,
|
||||
y_offset=-40,
|
||||
)
|
||||
Tooltip(self.btn_tr, Msg.TTIP["trash_tl"], self.tooltip_state)
|
||||
Tooltip(self.btn_exp, Msg.TTIP["export_tl"], self.tooltip_state)
|
||||
Tooltip(self.btn_rename, Msg.TTIP["rename_tl"], self.tooltip_state)
|
||||
|
||||
Tooltip(
|
||||
self.btn_rename, Msg.TTIP["rename_tl"], self.tooltip_state
|
||||
)
|
||||
|
||||
self.lb_rename.insert(0, "Max. 12 characters!")
|
||||
self.str_var = tk.StringVar()
|
||||
self.str_var.set(self.a)
|
||||
self.color_label()
|
||||
self.stop()
|
||||
data = self.handle_tunnel_data(self.a)
|
||||
check_call(["nmcli", "con", "mod", self.a, "connection.autoconnect", "no"])
|
||||
check_call(
|
||||
[
|
||||
"nmcli",
|
||||
"con",
|
||||
"mod",
|
||||
self.a,
|
||||
"connection.autoconnect",
|
||||
"no",
|
||||
]
|
||||
)
|
||||
elif ("PrivateKey = " in read) and ("Endpoint = " in read):
|
||||
pass
|
||||
else:
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_error"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["imp_err"], Msg.STR["no_valid_file"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_error"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["imp_err"],
|
||||
Msg.STR["no_valid_file"],
|
||||
)
|
||||
|
||||
except EOFError as e:
|
||||
print(e)
|
||||
@ -618,15 +794,16 @@ class FrameWidgets(ttk.Frame):
|
||||
try:
|
||||
self.select_tunnel = self.l_box.curselection()
|
||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||
with open(f"/tmp/tlecdcwg/{select_tl}.conf", "r+", encoding="utf-8") as file2:
|
||||
with open(
|
||||
f"/tmp/tlecdcwg/{select_tl}.conf", "r+", encoding="utf-8"
|
||||
) as file2:
|
||||
key = Tunnel.con_to_dict(file2)
|
||||
pre_key = key[3]
|
||||
check_call(["nmcli", "connection", "delete", select_tl])
|
||||
self.l_box.delete(self.select_tunnel[0])
|
||||
with open(AppConfig.SETTINGS_FILE, "r", encoding="utf-8") as set_f6:
|
||||
lines6 = set_f6.readlines()
|
||||
if (select_tl == lines6[7].strip()
|
||||
and "off\n" not in lines6[7].strip()):
|
||||
if select_tl == lines6[7].strip() and "off\n" not in lines6[7].strip():
|
||||
lines6[7] = "off\n"
|
||||
with open(AppConfig.SETTINGS_FILE, "w", encoding="utf-8") as set_f7:
|
||||
set_f7.writelines(lines6)
|
||||
@ -637,7 +814,9 @@ class FrameWidgets(ttk.Frame):
|
||||
Path.unlink(f"{Path.home()}/.config/wire_py/{select_tl}.dat")
|
||||
Path.unlink(f"/tmp/tlecdcwg/{select_tl}.conf")
|
||||
with open(AppConfig.KEYS_FILE, "r", encoding="utf-8") as readfile:
|
||||
with open(f"{Path.home()}/.config/wire_py/keys2", "w", encoding="utf-8") as writefile:
|
||||
with open(
|
||||
f"{Path.home()}/.config/wire_py/keys2", "w", encoding="utf-8"
|
||||
) as writefile:
|
||||
for line in readfile:
|
||||
if pre_key not in line.strip("\n"):
|
||||
writefile.write(line)
|
||||
@ -650,8 +829,13 @@ class FrameWidgets(ttk.Frame):
|
||||
if self.l_box.size() == 0:
|
||||
self.wg_autostart.configure(state="disabled")
|
||||
self.lb_rename.configure(state="disabled")
|
||||
Tooltip(self.wg_autostart, Msg.TTIP["autostart_info"]
|
||||
, self.tooltip_state, x_offset=30, y_offset=-50)
|
||||
Tooltip(
|
||||
self.wg_autostart,
|
||||
Msg.TTIP["autostart_info"],
|
||||
self.tooltip_state,
|
||||
x_offset=30,
|
||||
y_offset=-50,
|
||||
)
|
||||
|
||||
Tooltip(self.btn_exp, Msg.TTIP["export_tl_info"], self.tooltip_state)
|
||||
Tooltip(self.btn_stst, Msg.TTIP["empty_list"], self.tooltip_state)
|
||||
@ -668,11 +852,21 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
if self.l_box.size() != 0:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["sel_tl"], Msg.STR["sel_list"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["sel_tl"],
|
||||
Msg.STR["sel_list"],
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["sel_tl"], Msg.STR["tl_first"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["sel_tl"],
|
||||
Msg.STR["tl_first"],
|
||||
)
|
||||
|
||||
def enable_check_box(self, _) -> None:
|
||||
"""
|
||||
@ -691,7 +885,11 @@ class FrameWidgets(ttk.Frame):
|
||||
Set (on), the selected tunnel is displayed in the label.
|
||||
At (off) the label is first emptied then filled with No Autoconnect
|
||||
"""
|
||||
lines = Path(AppConfig.SETTINGS_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":
|
||||
print(f"{lines[7]} starts automatically when the system starts.")
|
||||
@ -707,7 +905,12 @@ class FrameWidgets(ttk.Frame):
|
||||
self.autoconnect_var = tk.StringVar()
|
||||
self.autoconnect_var.set(self.auto_con)
|
||||
|
||||
self.autoconnect = ttk.Label(self.lb_frame3, textvariable=self.autoconnect_var, foreground="#0071ff", width=15)
|
||||
self.autoconnect = ttk.Label(
|
||||
self.lb_frame3,
|
||||
textvariable=self.autoconnect_var,
|
||||
foreground="#0071ff",
|
||||
width=15,
|
||||
)
|
||||
self.autoconnect.config(font=("Ubuntu", 11))
|
||||
self.autoconnect.grid(column=1, row=0, sticky="e", pady=19)
|
||||
|
||||
@ -727,9 +930,15 @@ class FrameWidgets(ttk.Frame):
|
||||
select_tl = self.l_box.get(select_tunnel[0])
|
||||
|
||||
if self.selected_option.get() == 0:
|
||||
lines = Path(AppConfig.SETTINGS_FILE).read_text(encoding="utf-8").splitlines(keepends=True)
|
||||
lines[7] = 'off\n'
|
||||
Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
|
||||
lines = (
|
||||
Path(AppConfig.SETTINGS_FILE)
|
||||
.read_text(encoding="utf-8")
|
||||
.splitlines(keepends=True)
|
||||
)
|
||||
lines[7] = "off\n"
|
||||
Path(AppConfig.SETTINGS_FILE).write_text(
|
||||
"".join(lines), encoding="utf-8"
|
||||
)
|
||||
|
||||
tl = LxTools.get_file_name(AppConfig.TEMP_DIR)
|
||||
|
||||
@ -737,9 +946,15 @@ class FrameWidgets(ttk.Frame):
|
||||
self.wg_autostart.configure(state="disabled")
|
||||
|
||||
if self.selected_option.get() >= 1:
|
||||
lines = Path(AppConfig.SETTINGS_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
|
||||
Path(AppConfig.SETTINGS_FILE).write_text(''.join(lines), encoding="utf-8")
|
||||
Path(AppConfig.SETTINGS_FILE).write_text(
|
||||
"".join(lines), encoding="utf-8"
|
||||
)
|
||||
|
||||
except IndexError:
|
||||
self.selected_option.set(1)
|
||||
@ -755,19 +970,39 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
if len(self.lb_rename.get()) > 12:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["ren_err"], Msg.STR["sign_len"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["ren_err"],
|
||||
Msg.STR["sign_len"],
|
||||
)
|
||||
|
||||
elif len(self.lb_rename.get()) == 0:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["ren_err"], Msg.STR["zero_signs"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["ren_err"],
|
||||
Msg.STR["zero_signs"],
|
||||
)
|
||||
|
||||
elif any(ch in special_characters for ch in self.lb_rename.get()):
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["ren_err"], Msg.STR["false_signs"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["ren_err"],
|
||||
Msg.STR["false_signs"],
|
||||
)
|
||||
|
||||
elif self.lb_rename.get() in name_of_file:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["ren_err"], Msg.STR["is_in_use"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["ren_err"],
|
||||
Msg.STR["is_in_use"],
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
@ -776,7 +1011,17 @@ class FrameWidgets(ttk.Frame):
|
||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||
|
||||
# nmcli connection modify old connection.id iphone
|
||||
subprocess.check_output(["nmcli", "connection", "modify", select_tl, "connection.id", self.lb_rename.get()], text=True)
|
||||
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)
|
||||
@ -787,12 +1032,14 @@ class FrameWidgets(ttk.Frame):
|
||||
self.l_box.update()
|
||||
new_a_connect = self.lb_rename.get()
|
||||
self.lb_rename.delete(0, tk.END)
|
||||
|
||||
|
||||
with open(AppConfig.SETTINGS_FILE, "r", encoding="utf-8") as set_f5:
|
||||
lines5 = set_f5.readlines()
|
||||
if select_tl == lines5[7].strip() and "off\n" not in lines5[7].strip():
|
||||
lines5[7] = new_a_connect
|
||||
with open(AppConfig.SETTINGS_FILE, "w", encoding="utf-8") as theme_set5:
|
||||
with open(
|
||||
AppConfig.SETTINGS_FILE, "w", encoding="utf-8"
|
||||
) as theme_set5:
|
||||
theme_set5.writelines(lines5)
|
||||
self.autoconnect_var.set(value=new_a_connect)
|
||||
self.update_connection_display()
|
||||
@ -800,14 +1047,19 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
except IndexError:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["ren_err"], Msg.STR["sel_list"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["ren_err"],
|
||||
Msg.STR["sel_list"],
|
||||
)
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
except EOFError as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def init_and_report(self, data=None) -> None:
|
||||
"""
|
||||
Displays the value address, DNS and peer in the labels
|
||||
@ -826,7 +1078,9 @@ class FrameWidgets(ttk.Frame):
|
||||
shows data in the label
|
||||
"""
|
||||
# Address Label
|
||||
self.address = ttk.Label(self.lb_frame, textvariable=self.add, foreground="#0071ff")
|
||||
self.address = ttk.Label(
|
||||
self.lb_frame, textvariable=self.add, foreground="#0071ff"
|
||||
)
|
||||
self.address.grid(column=0, row=5, sticky="w", padx=10, pady=6)
|
||||
self.address.config(font=("Ubuntu", 9))
|
||||
|
||||
@ -836,7 +1090,9 @@ class FrameWidgets(ttk.Frame):
|
||||
self.dns.config(font=("Ubuntu", 9))
|
||||
|
||||
# Endpoint Label
|
||||
self.endpoint = ttk.Label(self.lb_frame2, textvariable=self.enp, foreground="#0071ff")
|
||||
self.endpoint = ttk.Label(
|
||||
self.lb_frame2, textvariable=self.enp, foreground="#0071ff"
|
||||
)
|
||||
self.endpoint.grid(column=0, row=8, sticky="w", padx=10, pady=20)
|
||||
self.endpoint.config(font=("Ubuntu", 9))
|
||||
|
||||
@ -851,7 +1107,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.handle_connection_state("start", select_tl)
|
||||
|
||||
else:
|
||||
|
||||
|
||||
data = self.handle_tunnel_data(self.a)
|
||||
if data:
|
||||
|
||||
@ -861,11 +1117,21 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
if self.l_box.size() != 0:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["sel_tl"], Msg.STR["sel_list"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
Msg.STR["sel_tl"],
|
||||
Msg.STR["sel_list"],
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_info"], AppConfig.IMAGE_PATHS["icon_msg"], Msg.STR["sel_tl"], Msg.STR["tl_first"])
|
||||
LxTools.msg_window(
|
||||
AppConfig.IMAGE_PATHS["icon_info"],
|
||||
AppConfig.IMAGE_PATHS["icon_msg"],
|
||||
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