remove USER_FILE usage in ssl_decrypt.py and ssl_encrypt.py; switch to argparse for command-line arguments
This commit is contained in:
49
wirepy.py
49
wirepy.py
@ -10,7 +10,7 @@ import sys
|
||||
import tkinter as tk
|
||||
import webbrowser
|
||||
from pathlib import Path
|
||||
from subprocess import CompletedProcess
|
||||
from subprocess import CompletedProcess, run
|
||||
from tkinter import TclError, filedialog, ttk
|
||||
|
||||
from common_tools import (
|
||||
@ -24,10 +24,9 @@ from common_tools import (
|
||||
)
|
||||
from wp_app_config import AppConfig, Msg
|
||||
|
||||
AppConfig.USER_FILE.write_text(getpass.getuser())
|
||||
AppConfig.ensure_directories()
|
||||
AppConfig.create_default_settings()
|
||||
CryptoUtil.decrypt()
|
||||
CryptoUtil.decrypt(getpass.getuser())
|
||||
|
||||
|
||||
class Wirepy(tk.Tk):
|
||||
@ -538,7 +537,13 @@ class FrameWidgets(ttk.Frame):
|
||||
self.tooltip_label.set(_("Enable Tooltips"))
|
||||
|
||||
def tooltips_toggle(self):
|
||||
"""Toggles tooltips on/off and updates the menu label"""
|
||||
"""
|
||||
Toggles the visibility of tooltips (on/off) and updates
|
||||
the corresponding menu label. Inverts the current tooltip state
|
||||
(`self.tooltip_state`), saves the new value in the configuration,
|
||||
and applies the change immediately. Updates the menu entry's label to
|
||||
reflect the new tooltip status (e.g., "Tooltips: On" or "Tooltips: Off").
|
||||
"""
|
||||
# Toggle the boolean state
|
||||
new_bool_state = not self.tooltip_state.get()
|
||||
# Save the converted value in the configuration
|
||||
@ -674,7 +679,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.tl.update(data_import)
|
||||
|
||||
if self.a != "":
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
["nmcli", "connection", "down", self.a],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
@ -688,7 +693,7 @@ class FrameWidgets(ttk.Frame):
|
||||
print(f"Error process decrypt: Code {process.returncode}")
|
||||
self.reset_fields()
|
||||
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
[
|
||||
"nmcli",
|
||||
"connection",
|
||||
@ -711,7 +716,7 @@ class FrameWidgets(ttk.Frame):
|
||||
else:
|
||||
print(f"Error process decrypt: Code {process.returncode}")
|
||||
|
||||
CryptoUtil.encrypt()
|
||||
CryptoUtil.encrypt(getpass.getuser())
|
||||
LxTools.clean_files(AppConfig.TEMP_DIR, file=None)
|
||||
AppConfig.ensure_directories()
|
||||
self.str_var.set("")
|
||||
@ -740,7 +745,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.stop()
|
||||
self.handle_tunnel_data(self.a, self.tl)
|
||||
self.show_data()
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
["nmcli", "con", "mod", self.a, "connection.autoconnect", "no"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
@ -779,7 +784,7 @@ class FrameWidgets(ttk.Frame):
|
||||
self.select_tunnel = self.l_box.curselection()
|
||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
["nmcli", "connection", "delete", select_tl],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
@ -973,7 +978,7 @@ class FrameWidgets(ttk.Frame):
|
||||
select_tl = self.l_box.get(self.select_tunnel[0])
|
||||
|
||||
# nmcli connection modify old connection.id iphone
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
[
|
||||
"nmcli",
|
||||
"connection",
|
||||
@ -1036,7 +1041,13 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
def show_data(self) -> None:
|
||||
"""
|
||||
shows data in the label
|
||||
Displays network-related data (address, DNS, endpoint)
|
||||
in the UI using ttk.Label widgets.
|
||||
Creates three labels for address, DNS, and endpoint with
|
||||
specific styling (color, font), positioning them in a
|
||||
grid layout (`lb_frame` and `lb_frame2`).
|
||||
Each label is linked to a corresponding text variable
|
||||
(`self.add`, `self.DNS`, `self.enp`) for dynamic data updates.
|
||||
"""
|
||||
# Address Label
|
||||
self.address = ttk.Label(
|
||||
@ -1059,7 +1070,13 @@ class FrameWidgets(ttk.Frame):
|
||||
|
||||
def wg_switch(self, event=None) -> None:
|
||||
"""
|
||||
Deals with switching the VPN connection
|
||||
Manages switching between active and inactiveVPN connections.
|
||||
If no tunnel is selected (`self.a == ""`), it starts a new connection
|
||||
with the selected tunnel from the listbox (`l_box`).
|
||||
Otherwise, it stops the current connection and updates
|
||||
tunnel data using `handle_tunnel_data`.
|
||||
Handles errors like `IndexError` by displaying appropriate
|
||||
messages if no items are selected or the listbox is empty.
|
||||
"""
|
||||
try:
|
||||
if self.a == "":
|
||||
@ -1102,7 +1119,7 @@ class FrameWidgets(ttk.Frame):
|
||||
"""
|
||||
if action == "stop":
|
||||
if self.a:
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
["nmcli", "connection", "down", self.a],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
@ -1122,7 +1139,7 @@ class FrameWidgets(ttk.Frame):
|
||||
elif action == "start":
|
||||
if tunnel_name or self.a:
|
||||
target_tunnel = tunnel_name or self.a
|
||||
process: CompletedProcess[str] = subprocess.run(
|
||||
process: CompletedProcess[str] = run(
|
||||
["nmcli", "connection", "up", target_tunnel],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
@ -1164,7 +1181,7 @@ class FrameWidgets(ttk.Frame):
|
||||
if __name__ == "__main__":
|
||||
|
||||
_ = AppConfig.setup_translations()
|
||||
LxTools.sigi(AppConfig.TEMP_DIR, AppConfig.USER_FILE)
|
||||
LxTools.sigi(AppConfig.TEMP_DIR)
|
||||
window = Wirepy()
|
||||
"""
|
||||
the hidden files are hidden in Filedialog
|
||||
@ -1177,5 +1194,5 @@ if __name__ == "__main__":
|
||||
window.tk.call("set", "::tk::dialog::file::showHiddenVar", "0")
|
||||
window.mainloop()
|
||||
|
||||
LxTools.clean_files(AppConfig.TEMP_DIR, AppConfig.USER_FILE)
|
||||
LxTools.clean_files(AppConfig.TEMP_DIR)
|
||||
sys.exit(0)
|
||||
|
Reference in New Issue
Block a user