line formatted for better reading

This commit is contained in:
Désiré Werner Menrath 2025-04-25 17:37:04 +02:00
parent f9ecd54e0a
commit f6204c9071
7 changed files with 117 additions and 364 deletions

31
.idea/workspace.xml generated
View File

@ -7,6 +7,10 @@
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment=" - Update Translate Files"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment=" - Update Translate Files">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cls_mth_fc.py" beforeDir="false" afterPath="$PROJECT_DIR$/cls_mth_fc.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/cls_mth_fc.py" beforeDir="false" afterPath="$PROJECT_DIR$/cls_mth_fc.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ssl_decrypt.py" beforeDir="false" afterPath="$PROJECT_DIR$/ssl_decrypt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ssl_encrypt.py" beforeDir="false" afterPath="$PROJECT_DIR$/ssl_encrypt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/start_wg.py" beforeDir="false" afterPath="$PROJECT_DIR$/start_wg.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wirepy.py" beforeDir="false" afterPath="$PROJECT_DIR$/wirepy.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -48,6 +52,7 @@
"keyToString": { "keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true", "ASKED_ADD_EXTERNAL_FILES": "true",
"Python.INSTALL.executor": "Run", "Python.INSTALL.executor": "Run",
"Python.cls_mth_fc.executor": "Run",
"Python.install.executor": "Run", "Python.install.executor": "Run",
"Python.main.executor": "Run", "Python.main.executor": "Run",
"Python.messagebox.executor": "Run", "Python.messagebox.executor": "Run",
@ -55,6 +60,7 @@
"Python.testtheme.executor": "Run", "Python.testtheme.executor": "Run",
"Python.wg_func.executor": "Run", "Python.wg_func.executor": "Run",
"Python.wg_main.executor": "Run", "Python.wg_main.executor": "Run",
"Python.wirepy.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true", "RunOnceActivity.git.unshallow": "true",
"Shell Script.install.executor": "Run", "Shell Script.install.executor": "Run",
@ -76,7 +82,7 @@
<recent name="$PROJECT_DIR$/wire-py" /> <recent name="$PROJECT_DIR$/wire-py" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Python.wg_main"> <component name="RunManager" selected="Python.wirepy">
<configuration name="start_wg" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="start_wg" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="wire-py" /> <module name="wire-py" />
<option name="ENV_FILES" value="" /> <option name="ENV_FILES" value="" />
@ -121,8 +127,31 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="wirepy" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="wire-py" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/wirepy.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.wirepy" />
<item itemvalue="Python.start_wg" /> <item itemvalue="Python.start_wg" />
</list> </list>
</recent_temporary> </recent_temporary>

View File

@ -47,9 +47,7 @@ class Create:
else: else:
sett.touch() sett.touch()
sett.write_text( sett.write_text("[UPDATES]\non\n[THEME]\nlight\n[TOOLTIP]\nTrue\n[AUTOSTART ON]\noff\n")
"[UPDATES]\non\n[THEME]\nlight\n[TOOLTIP]\nTrue\n[AUTOSTART ON]\noff\n"
)
if ks.exists(): if ks.exists():
pass pass
@ -72,11 +70,9 @@ class Create:
else: else:
wg_ser.touch() wg_ser.touch()
wg_ser.write_text( wg_ser.write_text("[Unit]\nDescription=Automatic Tunnel Start\nAfter=network-online.target\n\n[Service]\n"
"[Unit]\nDescription=Automatic Tunnel Start\nAfter=network-online.target" "Type=oneshot\nExecStartPre=/bin/sleep 5\nExecStart=/usr/local/bin/start_wg.py\n[Install]"
"\n\n[Service]\nType=oneshot\nExecStartPre=/bin/sleep 5\nExecStart=/usr/" "\nWantedBy=default.target")
"local/bin/start_wg.py\n[Install]\nWantedBy=default.target"
)
check_call(["systemctl", "--user", "enable", "wg_start.service"]) check_call(["systemctl", "--user", "enable", "wg_start.service"])
@staticmethod @staticmethod
@ -94,12 +90,8 @@ class Create:
""" """
This start ssl_decrypt file This start ssl_decrypt file
""" """
process = subprocess.run( process = subprocess.run(["pkexec", "/usr/local/bin/ssl_decrypt.py"], stdout=subprocess.PIPE, text=True,
["pkexec", "/usr/local/bin/ssl_decrypt.py"], check=True)
stdout=subprocess.PIPE,
text=True,
check=True,
)
path = Path.home() / ".config/wire_py/" path = Path.home() / ".config/wire_py/"
file_in_path = list(path.rglob("*.dat")) file_in_path = list(path.rglob("*.dat"))
if file_in_path: if file_in_path:
@ -115,12 +107,8 @@ class Create:
""" """
this start ssl_encrypt file this start ssl_encrypt file
""" """
process = subprocess.run( process = subprocess.run(["pkexec", "/usr/local/bin/ssl_encrypt.py"], stdout=subprocess.PIPE, text=True,
["pkexec", "/usr/local/bin/ssl_encrypt.py"], check=True)
stdout=subprocess.PIPE,
text=True,
check=True,
)
print(process.stdout) print(process.stdout)
if process.returncode == 0: if process.returncode == 0:
print("All Files successfully encrypted...") print("All Files successfully encrypted...")
@ -241,9 +229,7 @@ class LxTools(tk.Tk):
# End program for certain signals, report to others only reception # End program for certain signals, report to others only reception
if signum in (signal.SIGINT, signal.SIGTERM): if signum in (signal.SIGINT, signal.SIGTERM):
exit_code = 1 exit_code = 1
print( print(f"\nSignal {signame} {(signum)} received. => Aborting with exit code {exit_code}.")
f"\nSignal {signame} {(signum)} received. => Aborting with exit code {exit_code}."
)
LxTools.clean_files(dirname, file) LxTools.clean_files(dirname, file)
print("Breakdown by user...") print("Breakdown by user...")
sys.exit(exit_code) sys.exit(exit_code)
@ -380,11 +366,7 @@ class Tunnel:
""" """
Shows the Active Tunnel Shows the Active Tunnel
""" """
active = ( active = (os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split())
os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"')
.read()
.split()
)
if not active: if not active:
active = "" active = ""
else: else:
@ -485,16 +467,8 @@ class Tooltip:
tw.wm_overrideredirect(True) tw.wm_overrideredirect(True)
tw.wm_geometry(f"+{x}+{y}") tw.wm_geometry(f"+{x}+{y}")
label = tk.Label( label = tk.Label(tw, text=self.text, background="lightgreen", foreground="black", relief="solid", borderwidth=1,
tw, padx=5, pady=5)
text=self.text,
background="lightgreen",
foreground="black",
relief="solid",
borderwidth=1,
padx=5,
pady=5,
)
label.grid() label.grid()
def hide_tooltip(self, event=None): def hide_tooltip(self, event=None):

View File

@ -18,19 +18,7 @@ PKEYFILE = "/usr/local/etc/ssl/pwgk.pem"
if not keyfile.is_file(): if not keyfile.is_file():
check_call( check_call(["openssl", "rsa", "-in", PKEYFILE, "-out", keyfile, "-outform", "PEM", "-pubout"])
[
"openssl",
"rsa",
"-in",
PKEYFILE,
"-out",
keyfile,
"-outform",
"PEM",
"-pubout",
]
)
shutil.chown(keyfile, 1000, 1000) shutil.chown(keyfile, 1000, 1000)
dirname2 = f"/home/{logname}/.config/wire_py/" dirname2 = f"/home/{logname}/.config/wire_py/"
@ -43,17 +31,5 @@ if os.path.exists(f"{dirname2}pbwgk.pem"):
for detunnels in detl: for detunnels in detl:
tlname2 = f"{detunnels[:-4]}.conf" tlname2 = f"{detunnels[:-4]}.conf"
extpath = f"{dirname}/{tlname2}" extpath = f"{dirname}/{tlname2}"
check_call( check_call(["openssl", "pkeyutl", "-decrypt", "-inkey", PKEYFILE, "-in", detunnels, "-out", extpath])
[
"openssl",
"pkeyutl",
"-decrypt",
"-inkey",
PKEYFILE,
"-in",
detunnels,
"-out",
extpath,
]
)
shutil.chown(extpath, 1000, 1000) shutil.chown(extpath, 1000, 1000)

View File

@ -17,19 +17,7 @@ PKEYFILE = "/usr/local/etc/ssl/pwgk.pem"
if not keyfile.is_file(): if not keyfile.is_file():
check_call( check_call(["openssl", "rsa", "-in", PKEYFILE, "-out", keyfile, "-outform", "PEM", "-pubout"])
[
"openssl",
"rsa",
"-in",
PKEYFILE,
"-out",
keyfile,
"-outform",
"PEM",
"-pubout",
]
)
shutil.chown(keyfile, 1000, 1000) shutil.chown(keyfile, 1000, 1000)
if dirname.exists(): if dirname.exists():
@ -41,20 +29,8 @@ if not keyfile.is_file():
for tunnels in tl: for tunnels in tl:
sourcetl = f"{dirname}/{tunnels}" sourcetl = f"{dirname}/{tunnels}"
tlname = f"{CRYPTFILES}{tunnels[:-5]}.dat" tlname = f"{CRYPTFILES}{tunnels[:-5]}.dat"
check_call( check_call(["openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out",
[ tlname,])
"openssl",
"pkeyutl",
"-encrypt",
"-inkey",
keyfile,
"-pubin",
"-in",
sourcetl,
"-out",
tlname,
]
)
else: else:
@ -68,16 +44,4 @@ else:
sourcetl = f"{dirname}/{tunnels}" sourcetl = f"{dirname}/{tunnels}"
tlname = f"{CRYPTFILES}{tunnels[:-5]}.dat" tlname = f"{CRYPTFILES}{tunnels[:-5]}.dat"
check_call( check_call(
[ ["openssl", "pkeyutl", "-encrypt", "-inkey", keyfile, "-pubin", "-in", sourcetl, "-out", tlname])
"openssl",
"pkeyutl",
"-encrypt",
"-inkey",
keyfile,
"-pubin",
"-in",
sourcetl,
"-out",
tlname,
]
)

View File

@ -9,7 +9,7 @@ path_to_file = Path(Path.home() / ".config/wire_py/settings")
with open(path_to_file, "r", encoding="utf-8") as a_con: with open(path_to_file, "r", encoding="utf-8") as a_con:
# This funtion is for the independent autostart of the previously selected tunnel # This function is for the independent autostarted of the previously selected tunnel
lines = a_con.readlines() lines = a_con.readlines()
a_con = lines[7].strip() a_con = lines[7].strip()
if a_con != "off": if a_con != "off":

320
wirepy.py
View File

@ -30,9 +30,7 @@ userfile = Path("/tmp/.loguser")
# 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 = "v. 2.04.1725" VERSION = "v. 2.04.1725"
res = GiteaUpdate.api_down( res = GiteaUpdate.api_down("https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases", VERSION, set_file)
"https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases", VERSION, set_file
)
# Translate # Translate
APP = "wirepy" APP = "wirepy"
@ -60,9 +58,7 @@ class Wirepy(tk.Tk):
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(width=False, height=False)
self.title("Wire-Py") self.title("Wire-Py")
self.geometry( self.geometry(f"{self.x_width}x{self.y_height}+{self.monitor_center_x}+{self.monitor_center_y}")
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)
@ -98,22 +94,14 @@ class FrameWidgets(ttk.Frame):
self.dns = None self.dns = None
self.address = None self.address = None
self.auto_con = None self.auto_con = None
self.wg_vpn_start = tk.PhotoImage( self.wg_vpn_start = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn-start.png")
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.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.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.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.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.warning_pic = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/64/error.png")
self.wg_vpn_start = tk.PhotoImage( self.wg_vpn_start = tk.PhotoImage(file=r"/usr/share/icons/lx-icons/48/wg_vpn-start.png")
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.wg_vpn_stop = tk.PhotoImage(
file=r"/usr/share/icons/lx-icons/48/wg_vpn-stop.png"
)
def update(): def update():
""" """
@ -185,12 +173,10 @@ class FrameWidgets(ttk.Frame):
iw = r"/usr/share/icons/lx-icons/48/wg_vpn.png" iw = r"/usr/share/icons/lx-icons/48/wg_vpn.png"
ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" ii = r"/usr/share/icons/lx-icons/48/wg_msg.png"
wt = _("Info") wt = _("Info")
msg_t = _( msg_t = _("Wire-Py a simple Wireguard Gui for Linux systems.\n\n"
"Wire-Py a simple Wireguard Gui for Linux systems.\n\n"
"Wire-Py is open source software written in Python.\n\n" "Wire-Py is open source software written in Python.\n\n"
"Email: polunga40@unity-mail.de also likes for donation.\n\n" "Email: polunga40@unity-mail.de also likes for donation.\n\n"
"Use without warranty!\n" "Use without warranty!\n")
)
txt2 = _("Go to Wire-Py git") txt2 = _("Go to Wire-Py git")
com = link_btn com = link_btn
@ -217,12 +203,8 @@ class FrameWidgets(ttk.Frame):
set_tip = tk.BooleanVar() set_tip = tk.BooleanVar()
self.settings = tk.Menu(self, relief="flat") self.settings = tk.Menu(self, relief="flat")
self.options_btn.configure(menu=self.settings, style="Toolbutton") self.options_btn.configure(menu=self.settings, style="Toolbutton")
self.settings.add_checkbutton( self.settings.add_checkbutton(label=_("Disable Updates"), command=update, variable=set_update)
label=_("Disable Updates"), command=update, variable=set_update self.settings.add_checkbutton(label=_("Disable Tooltips"), command=tooltip, variable=set_tip)
)
self.settings.add_checkbutton(
label=_("Disable Tooltips"), command=tooltip, variable=set_tip
)
self.settings.add_command(label=_("Light"), command=theme_change_light) self.settings.add_command(label=_("Light"), command=theme_change_light)
self.settings.add_command(label=_("Dark"), command=theme_change_dark) self.settings.add_command(label=_("Dark"), command=theme_change_dark)
@ -272,13 +254,9 @@ class FrameWidgets(ttk.Frame):
self.update_btn.configure(menu=self.download, style="Toolbutton") self.update_btn.configure(menu=self.download, style="Toolbutton")
self.download.add_command( self.download.add_command(
label=_("Download"), label=_("Download"),
command=lambda: GiteaUpdate.download( command=lambda: GiteaUpdate.download(f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip",
f"https://git.ilunix.de/punix/Wire-Py/archive/{res}.zip",
r"/usr/share/icons/lx-icons/48/wg_vpn.png", r"/usr/share/icons/lx-icons/48/wg_vpn.png",
r"/usr/share/icons/lx-icons/48/wg_msg.png", r"/usr/share/icons/lx-icons/48/wg_msg.png", res))
res,
),
)
# Show active Tunnel # Show active Tunnel
self.a = Tunnel.active() self.a = Tunnel.active()
@ -301,8 +279,7 @@ class FrameWidgets(ttk.Frame):
# Bottom Frame 4 # Bottom Frame 4
self.lb_frame3 = ttk.Frame(self) self.lb_frame3 = ttk.Frame(self)
self.lb_frame3.configure(relief="flat") self.lb_frame3.configure(relief="flat")
self.lb_frame3.grid(column=0, row=5, columnspan=4, sticky="snew", self.lb_frame3.grid(column=0, row=5, columnspan=4, sticky="snew", padx=2, pady=2)
padx=2, pady=2)
# Bottom Frame 5 # Bottom Frame 5
self.lb_frame4 = ttk.Frame(self) self.lb_frame4 = ttk.Frame(self)
@ -346,9 +323,7 @@ class FrameWidgets(ttk.Frame):
self.l_box.grid(column=1, rowspan=4, row=0, sticky="ns") self.l_box.grid(column=1, rowspan=4, row=0, sticky="ns")
self.l_box.event_add("<<ClickEvent>>", "<Button-1>") self.l_box.event_add("<<ClickEvent>>", "<Button-1>")
self.l_box.bind("<<ClickEvent>>", enable_check_box) self.l_box.bind("<<ClickEvent>>", enable_check_box)
self.scrollbar = ttk.Scrollbar( self.scrollbar = ttk.Scrollbar(self.lb_frame_btn_lbox, orient="vertical", command=self.l_box.yview)
self.lb_frame_btn_lbox, orient="vertical", command=self.l_box.yview
)
self.scrollbar.grid(column=1, rowspan=4, row=0, sticky="nse") self.scrollbar.grid(column=1, rowspan=4, row=0, sticky="nse")
self.l_box.configure(yscrollcommand=self.scrollbar.set) self.l_box.configure(yscrollcommand=self.scrollbar.set)
@ -379,8 +354,7 @@ class FrameWidgets(ttk.Frame):
self.show_data() self.show_data()
# Button Import # Button Import
self.btn_i = ttk.Button(self.lb_frame_btn_lbox, image=self.imp_pic, self.btn_i = ttk.Button(self.lb_frame_btn_lbox, image=self.imp_pic, command=self.import_sl, padding=0)
command=self.import_sl, padding=0)
self.btn_i.grid(column=0, row=1, padx=15, pady=8) self.btn_i.grid(column=0, row=1, padx=15, pady=8)
Tooltip(self.btn_i, _("Click to import a Wireguard Tunnel"), tips) Tooltip(self.btn_i, _("Click to import a Wireguard Tunnel"), tips)
@ -392,8 +366,7 @@ class FrameWidgets(ttk.Frame):
try: try:
self.select_tunnel = self.l_box.curselection() self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0]) select_tl = self.l_box.get(self.select_tunnel[0])
with open(f"/tmp/tlecdcwg/{select_tl}.conf", "r+", encoding="utf-8" with open(f"/tmp/tlecdcwg/{select_tl}.conf", "r+", encoding="utf-8") as file2:
) as file2:
key = Tunnel.con_to_dict(file2) key = Tunnel.con_to_dict(file2)
pre_key = key[3] pre_key = key[3]
check_call(["nmcli", "connection", "delete", select_tl]) check_call(["nmcli", "connection", "delete", select_tl])
@ -427,7 +400,8 @@ class FrameWidgets(ttk.Frame):
if self.l_box.size() == 0: if self.l_box.size() == 0:
self.wg_autostart.configure(state="disabled") self.wg_autostart.configure(state="disabled")
self.lb_rename.configure(state="disabled") self.lb_rename.configure(state="disabled")
Tooltip(self.wg_autostart, _("You must have at least one\ntunnel in the list,to use the autostart"), tips) Tooltip(self.wg_autostart, _("You must have at least one\ntunnel in the list,to use the autostart")
, tips)
Tooltip(self.btn_exp, _("No Tunnels in List for Export"), tips) Tooltip(self.btn_exp, _("No Tunnels in List for Export"), tips)
Tooltip(self.btn_stst, _("No tunnels to start in the list"), tips) Tooltip(self.btn_stst, _("No tunnels to start in the list"), tips)
@ -465,36 +439,23 @@ class FrameWidgets(ttk.Frame):
LxTools.msg_window(iw, ii, wt, msg_t) LxTools.msg_window(iw, ii, wt, msg_t)
# Button Trash # Button Trash
self.btn_tr = ttk.Button( self.btn_tr = ttk.Button(self.lb_frame_btn_lbox, image=self.tr_pic, command=delete, padding=0,
self.lb_frame_btn_lbox, style="CButton.TButton")
image=self.tr_pic,
command=delete,
padding=0,
style="CButton.TButton",
)
self.btn_tr.grid(column=0, row=2, padx=15, pady=8) self.btn_tr.grid(column=0, row=2, padx=15, pady=8)
if self.l_box.size() == 0: if self.l_box.size() == 0:
Tooltip(self.btn_tr, _("No tunnels to delete in the list"), tips) Tooltip(self.btn_tr, _("No tunnels to delete in the list"), tips)
else: else:
Tooltip(self.btn_tr, _("Click to delete a Wireguard Tunnel\nSelect from the list!"), Tooltip(self.btn_tr, _("Click to delete a Wireguard Tunnel\nSelect from the list!"), tips)
tips,
)
# Button Export # Button Export
self.btn_exp = ttk.Button( self.btn_exp = ttk.Button(self.lb_frame_btn_lbox, image=self.exp_pic, command=Tunnel.export, padding=0)
self.lb_frame_btn_lbox, image=self.exp_pic, command=Tunnel.export, padding=0
)
self.btn_exp.grid(column=0, row=3, padx=15, pady=8) self.btn_exp.grid(column=0, row=3, padx=15, pady=8)
if self.l_box.size() == 0: if self.l_box.size() == 0:
Tooltip(self.btn_exp, _("No Tunnels in List for Export"), tips) Tooltip(self.btn_exp, _("No Tunnels in List for Export"), tips)
else: else:
Tooltip( Tooltip(self.btn_exp, _("Click to export all\nWireguard Tunnel to Zipfile"), tips)
self.btn_exp,
_("Click to export all\nWireguard Tunnel to Zipfile"),
tips,
)
# Label Entry # Label Entry
self.lb_rename = ttk.Entry(self.lb_frame4, width=20) self.lb_rename = ttk.Entry(self.lb_frame4, width=20)
@ -503,17 +464,9 @@ class FrameWidgets(ttk.Frame):
self.lb_rename.config(state="disable") self.lb_rename.config(state="disable")
if self.l_box.size() != 0: if self.l_box.size() != 0:
Tooltip( Tooltip(self.lb_rename, _("To rename a tunnel, you need to\nselect a tunnel from the list"), tips)
self.lb_rename,
_("To rename a tunnel, you need to\nselect a tunnel from the list"),
tips,
)
else: else:
Tooltip( Tooltip(self.lb_rename, _("To rename a tunnel, at least one must be in the list"), tips)
self.lb_rename,
_("To rename a tunnel, at least one must be in the list"),
tips,
)
def tl_rename(): def tl_rename():
@ -543,9 +496,7 @@ class FrameWidgets(ttk.Frame):
iw = r"/usr/share/icons/lx-icons/64/info.png" iw = r"/usr/share/icons/lx-icons/64/info.png"
ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" ii = r"/usr/share/icons/lx-icons/48/wg_msg.png"
wt = _("Renaming not possible") wt = _("Renaming not possible")
msg_t = _( msg_t = _("No valid sign. These must not be used.\nBlank, Slash, Backslash and { }\n")
"No valid sign. These must not be used.\nBlank, Slash, Backslash and { }\n"
)
LxTools.msg_window(iw, ii, wt, msg_t) LxTools.msg_window(iw, ii, wt, msg_t)
else: else:
@ -555,16 +506,7 @@ class FrameWidgets(ttk.Frame):
select_tl = self.l_box.get(self.select_tunnel[0]) select_tl = self.l_box.get(self.select_tunnel[0])
# nmcli connection modify old connection.id iphone # nmcli connection modify old connection.id iphone
check_call( check_call(["nmcli", "connection", "modify", select_tl, "connection.id", self.lb_rename.get()])
[
"nmcli",
"connection",
"modify",
select_tl,
"connection.id",
self.lb_rename.get(),
]
)
source = Path(f"/tmp/tlecdcwg/{select_tl}.conf") source = Path(f"/tmp/tlecdcwg/{select_tl}.conf")
destination = source.with_name(f"{self.lb_rename.get()}.conf") destination = source.with_name(f"{self.lb_rename.get()}.conf")
source.replace(destination) source.replace(destination)
@ -580,10 +522,7 @@ class FrameWidgets(ttk.Frame):
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(set_file, "r", encoding="utf-8") as set_f5:
lines5 = set_f5.readlines() lines5 = set_f5.readlines()
if ( if select_tl == lines5[7].strip() and "off\n" not in lines5[7].strip():
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(set_file, "w", encoding="utf-8") as theme_set5:
theme_set5.writelines(lines5) theme_set5.writelines(lines5)
@ -601,14 +540,8 @@ class FrameWidgets(ttk.Frame):
LxTools.msg_window(iw, ii, wt, msg_t) LxTools.msg_window(iw, ii, wt, msg_t)
# Button Rename # Button Rename
self.btn_rename = ttk.Button( self.btn_rename = ttk.Button(self.lb_frame4, text=_("Rename"), state="disable", command=tl_rename, padding=4,
self.lb_frame4, style="RnButton.TButton")
text=_("Rename"),
state="disable",
command=tl_rename,
padding=4,
style="RnButton.TButton",
)
self.btn_rename.grid(column=3, row=0, padx=5, pady=10, sticky="ne") self.btn_rename.grid(column=3, row=0, padx=5, pady=10, sticky="ne")
# Check Buttons # Check Buttons
@ -617,40 +550,22 @@ class FrameWidgets(ttk.Frame):
self.autoconnect_var.set(self.auto_con) self.autoconnect_var.set(self.auto_con)
# Frame for Labels, Entry and Button # Frame for Labels, Entry and Button
self.autoconnect = ttk.Label( self.autoconnect = ttk.Label(self.lb_frame3, textvariable=self.autoconnect_var, width=15)
self.lb_frame3, textvariable=self.autoconnect_var, width=15
)
self.autoconnect.config(font=("Ubuntu", 11)) self.autoconnect.config(font=("Ubuntu", 11))
self.autoconnect.grid(column=1, row=0, sticky="e", pady=19) self.autoconnect.grid(column=1, row=0, sticky="e", pady=19)
self.wg_autostart = ttk.Checkbutton( self.wg_autostart = ttk.Checkbutton(self.lb_frame3, text=_("Autoconnect on:"), variable=self.selected_option,
self.lb_frame3, command=self.box_set)
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") 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: if self.l_box.size() >= 1 and len(self.l_box.curselection()) >= 1:
Tooltip( Tooltip(self.wg_autostart, _("To use the autostart, enable this Checkbox"), tips)
self.wg_autostart, _("To use the autostart, enable this Checkbox"), tips
)
if self.l_box.size() == 0: if self.l_box.size() == 0:
Tooltip( Tooltip(self.wg_autostart, _("You must have at least one\ntunnel in the list,to use the autostart"), tips)
self.wg_autostart,
_(
"You must have at least one\ntunnel in the list,to use the autostart"
),
tips,
)
else: else:
Tooltip( Tooltip(self.wg_autostart, _("To use the autostart, a tunnel must be selected from the list"), tips)
self.wg_autostart,
_("To use the autostart, a tunnel must be selected from the list"),
tips,
)
self.on_off() self.on_off()
@ -672,11 +587,8 @@ class FrameWidgets(ttk.Frame):
Create.dir_and_files() Create.dir_and_files()
try: try:
filepath = filedialog.askopenfilename( filepath = filedialog.askopenfilename(initialdir=f"{Path.home()}", title=_("Select Wireguard config File"),
initialdir=f"{Path.home()}", filetypes=[(_("WG config files"), "*.conf")])
title=_("Select Wireguard config File"),
filetypes=[(_("WG config files"), "*.conf")],
)
with open(filepath, "r", encoding="utf-8") as file: with open(filepath, "r", encoding="utf-8") as file:
read = file.read() read = file.read()
@ -684,11 +596,7 @@ class FrameWidgets(ttk.Frame):
path_split1 = path_split[-1] path_split1 = path_split[-1]
self.a = Tunnel.active() self.a = Tunnel.active()
if ( if "PrivateKey = " in read and "PublicKey = " in read and "Endpoint =" in read:
"PrivateKey = " in read
and "PublicKey = " in read
and "Endpoint =" in read
):
with open(filepath, "r", encoding="utf-8") as file: with open(filepath, "r", encoding="utf-8") as file:
key = Tunnel.con_to_dict(file) key = Tunnel.con_to_dict(file)
pre_key = key[3] pre_key = key[3]
@ -701,9 +609,7 @@ class FrameWidgets(ttk.Frame):
iw = r"/usr/share/icons/lx-icons/64/error.png" iw = r"/usr/share/icons/lx-icons/64/error.png"
ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" ii = r"/usr/share/icons/lx-icons/48/wg_msg.png"
wt = _("Import Error") wt = _("Import Error")
msg_t = _( msg_t = _("Tunnel already available!\nPlease use another file for import")
"Tunnel already available!\nPlease use another file for import"
)
LxTools.msg_window(iw, ii, wt, msg_t) LxTools.msg_window(iw, ii, wt, msg_t)
else: else:
@ -712,64 +618,26 @@ class FrameWidgets(ttk.Frame):
keyfile.write(f"{pre_key}\r") keyfile.write(f"{pre_key}\r")
if len(path_split1) > 17: if len(path_split1) > 17:
p1 = shutil.copy(filepath, "/tmp/tlecdcwg/") p1 = shutil.copy(filepath, "/tmp/tlecdcwg/")
path_split = path_split1[ path_split = path_split1[len(path_split1) - 17:]
len(path_split1) - 17: os.rename(p1, f"/tmp/tlecdcwg/{path_split}")
]
os.rename(
p1, f"/tmp/tlecdcwg/{path_split}"
)
new_conf = f"/tmp/tlecdcwg/{path_split}" new_conf = f"/tmp/tlecdcwg/{path_split}"
if self.a != "": if self.a != "":
check_call( check_call(["nmcli", "connection", "down", Tunnel.active()])
[
"nmcli",
"connection",
"down",
Tunnel.active(),
]
)
self.label_empty() self.label_empty()
subprocess.check_output( subprocess.check_output(["nmcli", "connection", "import", "type",
[ "wireguard", "file", new_conf], text=True)
"nmcli",
"connection",
"import",
"type",
"wireguard",
"file",
new_conf,
],
text=True,
)
Create.encrypt() Create.encrypt()
else: else:
shutil.copy(filepath, "/tmp/tlecdcwg/") shutil.copy(filepath, "/tmp/tlecdcwg/")
if self.a != "": if self.a != "":
check_call( check_call(["nmcli", "connection", "down", Tunnel.active()])
[
"nmcli",
"connection",
"down",
Tunnel.active(),
]
)
self.label_empty() self.label_empty()
subprocess.check_output( subprocess.check_output(["nmcli", "connection", "import", "type",
[ "wireguard", "file", filepath], text=True)
"nmcli",
"connection",
"import",
"type",
"wireguard",
"file",
filepath,
],
text=True,
)
Create.encrypt() Create.encrypt()
@ -781,40 +649,18 @@ class FrameWidgets(ttk.Frame):
self.l_box.update() self.l_box.update()
self.l_box.selection_set(0) self.l_box.selection_set(0)
Tooltip( Tooltip(self.wg_autostart, _("To use the autostart, enable this Checkbox"), tips)
self.wg_autostart,
_("To use the autostart, enable this Checkbox"),
tips,
)
# Tooltip(self.l_box, _("List of available tunnels")) # Tooltip(self.l_box, _("List of available tunnels"))
Tooltip( Tooltip(self.btn_tr, _("Click to delete a Wireguard Tunnel\nSelect from the list!")
self.btn_tr, , tips,)
_(
"Click to delete a Wireguard Tunnel\n"
"Select from the list!"
),
tips,
)
Tooltip( Tooltip(self.btn_exp, _(" Click to export all\nWireguard Tunnel to Zipfile")
self.btn_exp, , tips)
_(
" Click to export all\n"
"Wireguard Tunnel to Zipfile"
),
tips,
)
Tooltip( Tooltip(self.btn_rename, _("To rename a tunnel, you need to\nselect a tunnel from"
self.btn_rename, " the list"), tips)
_(
"To rename a tunnel, you need to\n"
"select a tunnel from the list"
),
tips,
)
self.lb_rename.insert(0, "Max. 12 characters!") self.lb_rename.insert(0, "Max. 12 characters!")
self.str_var = tk.StringVar() self.str_var = tk.StringVar()
@ -822,24 +668,13 @@ class FrameWidgets(ttk.Frame):
self.color_label() self.color_label()
self.stop() self.stop()
wg_read = f"/tmp/tlecdcwg/{self.a}.conf" wg_read = f"/tmp/tlecdcwg/{self.a}.conf"
with open( with open(wg_read, "r", encoding="utf-8") as file_for_key:
wg_read, "r", encoding="utf-8"
) as file_for_key:
data = Tunnel.con_to_dict(file_for_key) data = Tunnel.con_to_dict(file_for_key)
# Address Label # Address Label
self.init_and_report(data) self.init_and_report(data)
self.show_data() self.show_data()
check_call( check_call(["nmcli", "con", "mod", self.a, "connection.autoconnect", "no"])
[
"nmcli",
"con",
"mod",
self.a,
"connection.autoconnect",
"no",
]
)
Path.chmod(wg_read, 0o600) Path.chmod(wg_read, 0o600)
if ("PrivateKey = " in read) and ("Endpoint = " in read): if ("PrivateKey = " in read) and ("Endpoint = " in read):
@ -850,9 +685,7 @@ class FrameWidgets(ttk.Frame):
iw = r"/usr/share/icons/lx-icons/64/error.png" iw = r"/usr/share/icons/lx-icons/64/error.png"
ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" ii = r"/usr/share/icons/lx-icons/48/wg_msg.png"
wt = _("Import Error") wt = _("Import Error")
msg_t = _( msg_t = _("Oh... no valid Wireguard File!\nPlease select a valid Wireguard File")
"Oh... no valid Wireguard File!\nPlease select a valid Wireguard File"
)
LxTools.msg_window(iw, ii, wt, msg_t) LxTools.msg_window(iw, ii, wt, msg_t)
except EOFError as e: except EOFError as e:
@ -921,12 +754,7 @@ class FrameWidgets(ttk.Frame):
self.autoconnect_var = tk.StringVar() self.autoconnect_var = tk.StringVar()
self.autoconnect_var.set(self.auto_con) self.autoconnect_var.set(self.auto_con)
self.autoconnect = ttk.Label( self.autoconnect = ttk.Label(self.lb_frame3, textvariable=self.autoconnect_var, foreground="#0071ff", width=15)
self.lb_frame3,
textvariable=self.autoconnect_var,
foreground="#0071ff",
width=15,
)
self.autoconnect.config(font=("Ubuntu", 11)) self.autoconnect.config(font=("Ubuntu", 11))
self.autoconnect.grid(column=1, row=0, sticky="e", pady=19) self.autoconnect.grid(column=1, row=0, sticky="e", pady=19)
@ -958,9 +786,7 @@ class FrameWidgets(ttk.Frame):
""" """
# Address Label # Address Label
self.address = ttk.Label( self.address = ttk.Label(self.lb_frame, textvariable=self.add, foreground="#0071ff")
self.lb_frame, textvariable=self.add, foreground="#0071ff"
)
self.address.grid(column=0, row=5, sticky="w", padx=10, pady=6) self.address.grid(column=0, row=5, sticky="w", padx=10, pady=6)
self.address.config(font=("Ubuntu", 9)) self.address.config(font=("Ubuntu", 9))
@ -970,9 +796,7 @@ class FrameWidgets(ttk.Frame):
self.dns.config(font=("Ubuntu", 9)) self.dns.config(font=("Ubuntu", 9))
# Endpoint Label # Endpoint Label
self.endpoint = ttk.Label( self.endpoint = ttk.Label(self.lb_frame2, textvariable=self.enp, foreground="#0071ff")
self.lb_frame2, textvariable=self.enp, foreground="#0071ff"
)
self.endpoint.grid(column=0, row=8, sticky="w", padx=10, pady=20) self.endpoint.grid(column=0, row=8, sticky="w", padx=10, pady=20)
self.endpoint.config(font=("Ubuntu", 9)) self.endpoint.config(font=("Ubuntu", 9))
@ -980,12 +804,7 @@ class FrameWidgets(ttk.Frame):
""" """
Stop Button Stop Button
""" """
self.btn_stst = ttk.Button( self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_stop, command=self.wg_switch, padding=0)
self.lb_frame_btn_lbox,
image=self.wg_vpn_stop,
command=self.wg_switch,
padding=0,
)
self.btn_stst.grid(column=0, row=0, padx=5, pady=8) 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, _("Click to stop selected Wireguard Tunnel"), tips)
@ -994,12 +813,7 @@ class FrameWidgets(ttk.Frame):
""" """
Start Button Start Button
""" """
self.btn_stst = ttk.Button( self.btn_stst = ttk.Button(self.lb_frame_btn_lbox, image=self.wg_vpn_start, command=self.wg_switch, padding=0)
self.lb_frame_btn_lbox,
image=self.wg_vpn_start,
command=self.wg_switch,
padding=0,
)
self.btn_stst.grid(column=0, row=0, padx=5, pady=8) self.btn_stst.grid(column=0, row=0, padx=5, pady=8)
tl = Tunnel.list() tl = Tunnel.list()
@ -1016,14 +830,10 @@ class FrameWidgets(ttk.Frame):
with open(set_file, "r", encoding="utf-8") as read_file: with open(set_file, "r", encoding="utf-8") as read_file:
lines = read_file.readlines() lines = read_file.readlines()
if "light\n" in lines: if "light\n" in lines:
self.lb_tunnel = ttk.Label( self.lb_tunnel = ttk.Label(self, textvariable=self.str_var, foreground="green")
self, textvariable=self.str_var, foreground="green"
)
else: else:
self.lb_tunnel = ttk.Label( self.lb_tunnel = ttk.Label(self, textvariable=self.str_var, foreground="yellow")
self, textvariable=self.str_var, foreground="yellow"
)
self.lb_tunnel.config(font=("Ubuntu", 11, "bold")) self.lb_tunnel.config(font=("Ubuntu", 11, "bold"))
self.lb_tunnel.grid(column=2, padx=10, row=1) self.lb_tunnel.grid(column=2, padx=10, row=1)