From c9677a3421efe7ee4b1c40c53c6932cff63ad570 Mon Sep 17 00:00:00 2001 From: punix Date: Wed, 27 Dec 2023 01:02:51 +0100 Subject: [PATCH] First Wire-Py --- .idea/misc.xml | 7 +++ .idea/vcs.xml | 6 ++ .idea/workspace.xml | 101 +++++++++++++++++++++++++++++++++ main.py | 133 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 247 insertions(+) create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 main.py diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9de2865 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..c0eb7a0 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + { + "associatedIndex": 4 +} + + + + + { + "keyToString": { + "Notification.DisplayName-DoNotAsk-CythonWarning": "Python debugger native extension available", + "Notification.DoNotAsk-CythonWarning": "true", + "Python.main.executor": "Run", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "master", + "last_opened_file_path": "/home/punix/PycharmProjects/ctk_test/pythonProject1/main.py" + } +} + + + + + + + + + + + + + + + + 1703099124640 + + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..28356f3 --- /dev/null +++ b/main.py @@ -0,0 +1,133 @@ +#!/usr/bin/python3 + +import os +import tkinter as tk + +# Dieser Befehl zeigt den aktiven Tunnel an +wg_s = os.popen('nmcli connection show | grep -iPo "(.*)(wireguard)"').read().strip().split() +tl = wg_s[::3] # tl = Tunnelliste # Hiermit wird jedes 4. Element der Liste gezeigt + +lbg_color = '#c9c9c9' +bg_color = '#2f2f2f' +a_bg_color = '#484848' # color on active Button +up = os.popen('whoami').read().strip() +p1 = '/home/' +p2 = '/.config/wg_nmcli/' +wg_on = True + + +# Funktion um den aktuell aktiven Tunnel anzuzeigen +def active(): + wg_a = os.popen('nmcli connection show --active | grep -iPo "(.*)(wireguard)"').read().strip().split() + if not wg_a: + wg_a = '' + return wg_a + + else: + for tunnel in wg_a: + return tunnel + + +a = active() + + +class WG(tk.Tk): + def __init__(self): + super().__init__() + self.title('Wire-Py') + self.geometry('430x290') + # Load the image file from disk. + wg_icon = tk.PhotoImage(file=r'icons/wg-vpn-48.png') + # Set it as the window icon. + self.iconphoto(True, wg_icon) + + self.wgi_on = tk.PhotoImage(file=r'icons/wire-switch-on-48.png') + self.wgi_off = tk.PhotoImage(file=r'icons/wire-switch-off-48.png') + self.imp_pic = tk.PhotoImage(file=r'icons/wg-import.png') + + self.btn_i = tk.Button(self, image=self.imp_pic, bd=0, bg=bg_color, activebackground=bg_color) + self.btn_i.config(width=52, height=52, highlightthickness=0) + self.btn_i.place(x=95, y=110) + # + self.lbi = tk.Label(self, text='Import', bg=bg_color, fg='yellow') + self.lbi.config(font=("Ubuntu", 9)) + self.lbi.pack(pady=5) + self.lbi.place(x=101, y=85) + + self.tr_pic = tk.PhotoImage(file=r'icons/wg-trash.png') + self.btn_tr = tk.Button(self, image=self.tr_pic, bd=0, bg=bg_color, activebackground=bg_color) + self.btn_tr.config(width=52, height=52, text='Trash', highlightthickness=0) + self.btn_tr.place(x=170, y=110) + + self.lb_tr = tk.Label(self, text='Remove', bg=bg_color, fg='red') + self.lb_tr.config(font=("Ubuntu", 9)) + self.lb_tr.pack(pady=5) + self.lb_tr.place(x=170, y=85) + + self.lb_stst = tk.Label(self, text='On/Off', bg=bg_color, fg='#1c77f8') + self.lb_stst.config(font=("Ubuntu", 9)) + self.lb_stst.pack(pady=5) + self.lb_stst.place(x=25, y=85) + + self.btn_stst = tk.Button(self, image=self.wgi_on, bg=bg_color, activebackground=bg_color, bd=0, + command=self.wg_switch) + self.btn_stst.config(image=self.wgi_on, width=50, height=75, highlightthickness=0) + self.config(bg=bg_color) + self.btn_stst.place(x=20, y=113) + + self.lb = tk.Label(self, text='Active: ', bg=bg_color, fg='white') + self.lb.config(font=("Ubuntu", 11, "bold")) + self.lb.pack(padx=10, pady=10) + self.lb.place(x=30, y=10) + + self.lb_tunnel = tk.Label(self, text=f'{a}', bg=bg_color, fg='yellow') + self.lb_tunnel.config(font=("Ubuntu", 11, "bold")) + self.lb_tunnel.pack(pady=5, side='bottom') + self.lb_tunnel.place(x=90, y=10) + + self.lb_2 = tk.Label(self, text='''If no tunnels are listed + you must first import your tunnel.''', bg=bg_color, fg='white') + self.lb_2.config(font=("Ubuntu", 9, "bold")) + self.lb_2.pack(pady=5, side='left') + self.lb_2.place(x=20, y=40) + + self.scrollbar = tk.Scrollbar(self) + self.l_box = tk.Listbox(self, height=110, bg=lbg_color, fg='#606060', selectmode='single') + self.l_box.config(highlightthickness=0, relief='flat') + self.scrollbar.config(command=self.l_box.yview) + self.l_box.config(font=("Ubuntu", 12, "bold")) + self.l_box.pack(side='right', pady=30) + + for tunnels in tl: + self.l_box.insert("end", tunnels) + + self.wg_autostart = tk.Checkbutton(self, text='Autoconnect on PC Start', bg=bg_color, + activebackground=bg_color, fg='white') + self.wg_autostart.config(height=2, bg=bg_color, highlightthickness=0) + self.wg_autostart.pack() + self.wg_autostart.place(x=20, y=190) + self.wg_update = tk.Checkbutton(self, text='\nSearch automatically for\nWire-Py updates', bg=bg_color, + activebackground=bg_color, fg='white') + self.wg_update.config(height=0, bg=bg_color, highlightthickness=0) + self.wg_update.pack() + self.wg_update.place(x=20, y=215) + + def wg_switch(self): + global wg_on + if wg_on: + self.btn_stst.config(image=self.wgi_off, width=50, height=75) + self.config(bg=bg_color) + self.btn_stst.place(x=20, y=113) + wg_on = False + else: + self.btn_stst.config(image=self.wgi_on, width=50, height=75) + self.config(bg=bg_color) + self.btn_stst.place(x=20, y=113) + wg_on = True + + +# scrollbar.pack(side='left', fill='y') + +if __name__ == '__main__': + window = WG() + window.mainloop()