diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 58d9c5d..5f091cf 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,7 @@
-
+
@@ -268,7 +268,15 @@
1725391658456
-
+
+
+ 1725434328731
+
+
+
+ 1725434328731
+
+
@@ -317,6 +325,7 @@
-
+
+
\ No newline at end of file
diff --git a/main.py b/main.py
index a7dbdf5..bf43e69 100755
--- a/main.py
+++ b/main.py
@@ -4,7 +4,7 @@ import tkinter as tk
from tkinter import ttk
from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLabel, StartStopBTN, ShowAddress,
- FileHandle, ExportTunnels)
+ FileHandle, ExportTunnels, OnOff)
font_color = '#4011a7'
replacement = ''
@@ -20,7 +20,7 @@ class MainWindow(tk.Tk):
self.y_height = 360
self.monitor_center_x = self.winfo_screenwidth() / 2 - (self.x_width / 2)
self.monitor_center_y = 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.configure()
self.geometry('%dx%d+%d+%d' % (self.x_width, self.y_height, self.monitor_center_x, self.monitor_center_y))
@@ -136,21 +136,26 @@ class FrameWidgets(ttk.Frame):
os.system('nmcli connection delete ' + str(select_tl))
self.l_box.delete(self.select_tunnel[0])
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
- try:
- with open('wg_py.xml', 'r') as fr:
- lines = fr.readlines()
- with open('wg_py.xml_2', 'w') as fw:
- for line in lines:
+ del_tl_read = open('wg_py.xml', 'r')
+ if 'false ' in del_tl_read:
+ first_word = 'false '
+ else:
+ first_word = 'true '
- # strip() is used to remove '\n'
- # present at the end of each line
- if line.strip('\n') != select_tl:
- fw.write(line)
- print("Deleted")
- except:
- print("Oops! someting error")
+ word_replace = ''
+ # using the for loop
+ for line in del_tl_read:
+ line = line.strip()
+ changes = line.replace(first_word + select_tl, '')
+ word_replace = word_replace + changes + "\n"
+ del_tl_read.close()
+ del_tl = open('wg_py.xml', 'w')
+ del_tl.write(word_replace)
+ del_tl.close()
+ if len(self.tl) == 0:
+ self.wg_autostart.configure(state='disabled')
if self.a != '' and self.a == select_tl:
self.StrVar.set(value='')
StartStopBTN.button_start(self)
@@ -182,23 +187,7 @@ class FrameWidgets(ttk.Frame):
command=lambda: FileHandle.box_set(self))
self.wg_autostart.grid(column=1, row=4, sticky='nw')
- on_or_off = open('wg_py.xml', 'r')
- res = on_or_off.read()
- if 'true' in res:
- self.selected_option.set(1)
- self.auto_con = res
- self.auto_con = self.auto_con[5:]
- print(self.auto_con)
- else:
- self.wg_autostart.configure(state='disabled')
- self.auto_con = 'no Autoconnect'
- on_or_off.close()
-
- self.autoconnect_var = tk.StringVar()
- self.autoconnect_var.set(self.auto_con)
- self.autoconnect = tk.Label(self, textvariable=self.autoconnect_var, bd=2, fg='blue', padx=5)
- self.autoconnect.config(font=('Ubuntu', 11))
- self.autoconnect.grid(column=1, row=4, sticky='we')
+ OnOff.on_off(self)
#self.wg_update = tk.Checkbutton(self, tex='Search automatically for\nWire-Py updates')
#self.wg_update.grid(column=1, rowspan=3, row=5)
diff --git a/wg_func.py b/wg_func.py
index a5dfd41..dab7940 100755
--- a/wg_func.py
+++ b/wg_func.py
@@ -217,7 +217,7 @@ class ImportTunnel:
file.close()
os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no')
new_tl = open('wg_py.xml', 'a')
- new_tl.write('false ' + str(self.a))
+ new_tl.write('false ' + str(self.a) + '\n')
new_tl.close()
if 'PrivateKey = ' not in read:
Message()
@@ -243,45 +243,51 @@ class FileHandle:
self.select_tunnel = None
def box_set(self):
-
- global replacement
+ word_replace = ''
try:
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
if self.selected_option.get() == 0:
set_on = open('wg_py.xml', 'r')
- replacement = ""
# using the for loop
for line in set_on:
line = line.strip()
changes = line.replace('true ' + select_tl, 'false ' + select_tl)
- for tl in self.tl:
- os.system('nmcli con mod ' + str(tl) + ' connection.autoconnect no')
- replacement = replacement + changes + "\n"
+ os.system('nmcli con mod ' + str(self.auto_con) + ' connection.autoconnect no')
+ word_replace = word_replace + changes + "\n"
set_on.close()
- if self.selected_option.get() == 1:
+ if self.selected_option.get() >= 1:
set_on = open('wg_py.xml', 'r')
- replacement = ""
# using the for loop
for line in set_on:
line = line.strip()
changes = line.replace('false ' + select_tl, 'true ' + select_tl)
os.system('nmcli con mod ' + str(select_tl) + ' connection.autoconnect yes')
- replacement = replacement + changes + "\n"
+ word_replace = word_replace + changes + "\n"
set_on.close()
set_off = open('wg_py.xml', 'w')
- set_off.write(replacement)
+ set_off.write(word_replace)
set_off.close()
except IndexError:
self.selected_option.set(1)
+ OnOff.on_off(self)
+
+
+class OnOff(tk.Tk, FileHandle):
+ def __init__(self, container, **kwargs):
+ super().__init__(container, **kwargs)
+
+ def on_off(self):
+ a_connect = {}
on_or_off = open('wg_py.xml', 'r')
- res = on_or_off.read()
- if 'true' in res:
+ for line in on_or_off.readlines():
+ line_splitted = line.split()
+ a_connect[line_splitted[0]] = line_splitted[1]
+ if 'true' in a_connect:
self.selected_option.set(1)
- self.auto_con = res
- self.auto_con = self.auto_con[5:]
- print(self.auto_con)
+ self.auto_con = a_connect['true']
+
else:
self.wg_autostart.configure(state='disabled')
self.auto_con = 'no Autoconnect'
diff --git a/wg_py.xml b/wg_py.xml
index 1162854..e69de29 100644
--- a/wg_py.xml
+++ b/wg_py.xml
@@ -1 +0,0 @@
-false iphone-wg