add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again
now works
This commit is contained in:
parent
f90b10f948
commit
7e461db7a9
@ -4,7 +4,7 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add rename Label rename works">
|
||||
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/wg_main.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_main.py" afterDir="false" />
|
||||
@ -486,7 +486,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1726915238475</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="45" />
|
||||
<task id="LOCAL-00045" summary="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again">
|
||||
<option name="closed" value="true" />
|
||||
<created>1726959423800</created>
|
||||
<option name="number" value="00045" />
|
||||
<option name="presentableId" value="LOCAL-00045" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1726959423800</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="46" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="UnknownFeatures">
|
||||
@ -527,7 +535,6 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||
<MESSAGE value="add export Tunnel as zip" />
|
||||
<MESSAGE value="columnconfigure on all widgets set" />
|
||||
<MESSAGE value="little fixes a " " to ' '" />
|
||||
<MESSAGE value="add class FileHandle, add Label to show autoconnect Tunnel disable checkbox when Listbox is empty or no select Tunnel" />
|
||||
@ -552,6 +559,7 @@
|
||||
<MESSAGE value="Create your own message boxes for export" />
|
||||
<MESSAGE value="chown Export File to 1000:1000" />
|
||||
<MESSAGE value="add rename Label rename works" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add rename Label rename works" />
|
||||
<MESSAGE value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again" />
|
||||
</component>
|
||||
</project>
|
107
wg_func.py
107
wg_func.py
@ -14,78 +14,34 @@ path_to_file = Path('/etc/wire_py/wg_py')
|
||||
_u = Path.read_text(Path('/tmp/_u'))
|
||||
|
||||
|
||||
def msg_window():
|
||||
def msg_window(img_w, img_i, w_title, w_txt):
|
||||
"""
|
||||
img_w = Image for Tk Window
|
||||
img_i = Image for Icon
|
||||
w_title = Windows Title
|
||||
w_txt = Text for Tk Window
|
||||
"""
|
||||
msg = tk.Toplevel()
|
||||
msg.resizable(width=False, height=False)
|
||||
msg.x_width = 340
|
||||
msg.y_height = 140
|
||||
msg.title('Import error!')
|
||||
msg.title(w_title)
|
||||
msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
|
||||
msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
|
||||
msg.geometry('%dx%d+%d+%d' % (msg.x_width, msg.y_height, msg.monitor_center_x, msg.monitor_center_y))
|
||||
msg.columnconfigure(0, weight=1)
|
||||
msg.configure(pady=20)
|
||||
msg.warning = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/error.png')
|
||||
msg.i_warning = tk.Label(msg, image=msg.warning)
|
||||
msg.i_warning.grid(column=0, row=0)
|
||||
label = tk.Label(msg, text='Oh... no valid Wireguard File!\nPlease select a valid Wireguard File')
|
||||
msg.img = tk.PhotoImage(file=img_w)
|
||||
msg.i_window = tk.Label(msg, image=msg.img)
|
||||
msg.i_window.grid(column=0, row=0)
|
||||
label = tk.Label(msg, text=w_txt)
|
||||
label.config(font=('Ubuntu', 11), padx=15, pady=15)
|
||||
label.grid(column=1, row=0)
|
||||
button = tk.Button(msg, text='OK', command=msg.destroy)
|
||||
button.config(padx=15, pady=5)
|
||||
button.grid(column=0, columnspan=2, row=1)
|
||||
wg_icon_2 = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_msg.png')
|
||||
msg.iconphoto(True, wg_icon_2)
|
||||
msg.winfo_toplevel()
|
||||
|
||||
|
||||
def msg_exp_successful_window():
|
||||
msg = tk.Toplevel()
|
||||
msg.resizable(width=False, height=False)
|
||||
msg.x_width = 340
|
||||
msg.y_height = 140
|
||||
msg.title('Import error!')
|
||||
msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
|
||||
msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
|
||||
msg.geometry('%dx%d+%d+%d' % (msg.x_width, msg.y_height, msg.monitor_center_x, msg.monitor_center_y))
|
||||
msg.columnconfigure(0, weight=1)
|
||||
msg.configure(pady=20)
|
||||
msg.warning = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/info.png')
|
||||
msg.i_warning = tk.Label(msg, image=msg.warning)
|
||||
msg.i_warning.grid(column=0, row=0)
|
||||
label = tk.Label(msg, text='Your zip file is in home directory')
|
||||
label.config(font=('Ubuntu', 11), padx=15, pady=15)
|
||||
label.grid(column=1, row=0)
|
||||
button = tk.Button(msg, text='OK', command=msg.destroy)
|
||||
button.config(padx=15, pady=5)
|
||||
button.grid(column=0, columnspan=2, row=1)
|
||||
wg_icon_2 = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_vpn.png')
|
||||
msg.iconphoto(True, wg_icon_2)
|
||||
msg.winfo_toplevel()
|
||||
|
||||
|
||||
def msg_exp_fail_window():
|
||||
msg = tk.Toplevel()
|
||||
msg.resizable(width=False, height=False)
|
||||
msg.x_width = 340
|
||||
msg.y_height = 140
|
||||
msg.title('Export error!')
|
||||
msg.monitor_center_x = msg.winfo_screenwidth() / 2 - (msg.x_width / 2)
|
||||
msg.monitor_center_y = msg.winfo_screenheight() / 2 - (msg.y_height / 2)
|
||||
msg.geometry('%dx%d+%d+%d' % (msg.x_width, msg.y_height, msg.monitor_center_x, msg.monitor_center_y))
|
||||
msg.columnconfigure(0, weight=1)
|
||||
msg.configure(pady=20)
|
||||
msg.warning = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/64/error.png')
|
||||
msg.i_warning = tk.Label(msg, image=msg.warning)
|
||||
msg.i_warning.grid(column=0, row=0)
|
||||
label = tk.Label(msg, text='Export failed! Please try again')
|
||||
label.config(font=('Ubuntu', 11), padx=15, pady=15)
|
||||
label.grid(column=1, row=0)
|
||||
button = tk.Button(msg, text='OK', command=msg.destroy)
|
||||
button.config(padx=15, pady=5)
|
||||
button.grid(column=0, columnspan=2, row=1)
|
||||
wg_icon_2 = tk.PhotoImage(file=r'/usr/share/icons/wp-icons/48/wg_msg.png')
|
||||
msg.iconphoto(True, wg_icon_2)
|
||||
img_i = tk.PhotoImage(file=img_i)
|
||||
msg.iconphoto(True, img_i)
|
||||
msg.winfo_toplevel()
|
||||
|
||||
|
||||
@ -250,14 +206,20 @@ class ImportTunnel:
|
||||
with open(filepath, 'r') as file:
|
||||
key = ConToDict.covert_to_dict(file)
|
||||
pre_key = key[3]
|
||||
print(type(pre_key))
|
||||
if len(pre_key) != 0:
|
||||
with open('/etc/wire_py/.keys', 'r') as readfile:
|
||||
if pre_key in readfile:
|
||||
print('Tunnel already available! Please use another file for import')
|
||||
p_key = readfile.readlines()
|
||||
print(p_key)
|
||||
if pre_key in p_key or pre_key + '\n' in p_key:
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/error.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Import Error'
|
||||
msg_t = 'Tunnel already available!\nPlease use another file for import'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
else:
|
||||
with open('/etc/wire_py/.keys', 'a') as keyfile:
|
||||
keyfile.write('\r\n' + pre_key)
|
||||
keyfile.write(pre_key + '\r')
|
||||
if len(path_split1) > 17:
|
||||
p1 = shutil.copy(filepath, Path('/etc/wire_py/'))
|
||||
path_split = path_split1[len(path_split1) - 17:]
|
||||
@ -297,7 +259,12 @@ class ImportTunnel:
|
||||
os.chmod(str(wg_read), 0o600)
|
||||
|
||||
if 'PrivateKey = ' not in read:
|
||||
msg_window()
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/error.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Import Error'
|
||||
msg_t = 'Oh... no valid Wireguard File!\nPlease select a valid Wireguard File'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
except EOFError:
|
||||
pass
|
||||
except TypeError:
|
||||
@ -379,9 +346,19 @@ class ExportTunnels:
|
||||
os.chown(wg_tar + '.zip', 1000, 1000)
|
||||
with zipfile.ZipFile((wg_tar + '.zip'), 'r') as zf:
|
||||
if len(zf.namelist()) != 0:
|
||||
msg_exp_successful_window()
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/info.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_vpn.png'
|
||||
wt = 'Import Error'
|
||||
msg_t = 'Your zip file is in home directory'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
else:
|
||||
msg_exp_fail_window()
|
||||
"""img_w, img_i, w_title, w_txt hand over"""
|
||||
iw = r'/usr/share/icons/wp-icons/64/error.png'
|
||||
ii = r'/usr/share/icons/wp-icons/48/wg_msg.png'
|
||||
wt = 'Export error'
|
||||
msg_t = 'Export failed! Please try again'
|
||||
msg_window(iw, ii, wt, msg_t)
|
||||
|
||||
except TypeError:
|
||||
pass
|
||||
|
@ -160,7 +160,6 @@ class FrameWidgets(ttk.Frame):
|
||||
with open('/etc/wire_py/' + select_tl + '.conf', 'r+') as file2:
|
||||
key = ConToDict.covert_to_dict(file2)
|
||||
pre_key = key[3]
|
||||
print(pre_key)
|
||||
check_call(['nmcli', 'connection', 'delete', select_tl])
|
||||
self.l_box.delete(self.select_tunnel[0])
|
||||
if Path.is_file(Path('/etc/wire_py/wg_py')):
|
||||
|
Loading…
Reference in New Issue
Block a user