134 lines
5.0 KiB
Python
134 lines
5.0 KiB
Python
|
#!/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()
|