Wire-G/wire_g

189 lines
8.2 KiB
Plaintext
Raw Normal View History

2023-10-28 21:38:26 +02:00
#!/bin/bash
############################################################################################################
############################################################################################################
# Angemeldeten Benutzer ermitteln
a_user=$(whoami)
# wg_workdir Arbeitsverzeichnis wg
wg_wdir="/home/$a_user/.config/wg_nmcli/"
# Pfad wg Icons
wg_pic="/home/$a_user/.icons/"
# Wireguard tunnel auslesen mit grep nur Wireguard zeigen
# mit sed alles nach dem ersten Leerzeichen bis Zeilenende weggeschneiden und .tunnel.txt schreiben
nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${wg_wdir}.tunnel.txt
# Variable der verfügbaren Tunnelanzeige für Yad
tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
# Variable der aktiven Tunnelanzeige für Yad
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
############################################################################################################
############################################################################################################
# funktion wg_notify
wg_notify(){
a_user=$(whoami)
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
wg_pic="/home/$a_user/.icons/"
notify-send --icon=${wg_pic}wg-vpn.png "$active eingeschaltet"
# autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind
nmcli con mod $active connection.autoconnect no
# ab hier beginnt yad notify
#Pipe erstellen
PIPE="$HOME/.pipe.tmp"
2023-10-29 14:21:01 +01:00
rm $PIPE > /dev/null 2>&1
2023-10-28 21:38:26 +02:00
mkfifo $PIPE
exec 3<> $PIPE
#Yad Dialog erstellen
yad --notification --listen --command=wire_g --icon-size=32 --no-middle <&3 &
#Menüeinträge definieren
echo "menu:\
$active stop!/sbin/wg_stop| " >&3
#Icon des Menübuttons definieren
echo "icon:${wg_pic}wg-vpn.png" >&3
#Name des Menüs definieren
echo "tooltip:$active aktiv" >&3
}
export -f wg_notify
# function end
############################################################################################################
############################################################################################################
# funktion wireguard import
import_wg(){
a_user=$(whoami)
wg_pic="/home/$a_user/.icons/"
wg_wdir="/home/$a_user/.config/wg_nmcli/"
wgconf=$(yad --file --separator=" \n" \
--button="OK" --button="Abbrechen" \
--width=1200 --height=800 \
--window-icon=${wg_pic}wg-import.png \
--title="Wireguard .conf Datei auswählen")
if [ "$?" = "0" ]
then
wg_stop
nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt
wg_notify
fi }
export -f import_wg
# function end
############################################################################################################
############################################################################################################
# funktion wireguard remove
remove(){
a_user=$(whoami)
wg_pic="/home/$a_user/.icons/"
wg_wdir="/home/$a_user/.config/wg_nmcli/"
tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> ${wg_wdir}.wg_noactive.txt
active=$(cat ${wg_wdir}.wg_noactive.txt)
selection=$(yad --no-click --list --height=300 --width=60 \
2023-10-28 22:45:53 +02:00
--title="Wire-G Trash" --center \
2023-10-28 21:38:26 +02:00
--fixed --buttons-layout=center \
--button="OK" --button="Abbrechen" \
--separator="" --window-icon=${wg_pic}wg-trash.png \
--borders=8 --column 'Löschen' $tunnel)
if [ "$?" = "0" ]
then
nmcli connection delete $selection &> ${wg_wdir}.tmp.txt
2023-10-28 22:45:53 +02:00
success=$(grep -i "erfolgreich gelöscht" ${wg_wdir}.tmp.txt)
2023-10-28 21:38:26 +02:00
if [ "$?" = "0" ]
then
yad --window-icon=${wg_pic}wg-trash.png \
--image-on-top --image=${wg_pic}wg-info.png \
2023-10-28 23:22:34 +02:00
--text="Ihr Tunnel $selection wurde erfolgreich gelöscht.\n" \
2023-10-28 21:38:26 +02:00
--text-align=center --button="OK" --title "Wire-G Trash" \
2023-10-28 23:22:34 +02:00
--fixed --center --buttons-layout=center --borders=8 --center
2023-10-28 21:38:26 +02:00
else
yad --window-icon=${wg_pic}wg-trash.png \
--image-on-top --image=${wg_pic}wg-info.png \
2023-10-28 23:22:34 +02:00
--text="Oh etwas ging schief.\nBitte Tunnel im Networkmanager löschen." \
2023-10-28 21:38:26 +02:00
--text-align=center --button="OK" --title "Wire-G Trash" \
2023-10-28 23:22:34 +02:00
--fixed --center --buttons-layout=center --borders=8 --center
2023-10-28 21:38:26 +02:00
fi
if [ $selection = $active ]
then
pkill wire_g
pkill yad
fi
fi }
export -f remove
# function end
############################################################################################################
############################################################################################################
# function button "more"
more(){
a_user=$(whoami)
wg_pic="/home/$a_user/.icons/"
selection=$(yad --text "<span color='#626ff1'><b>Wire-G Author: Désiré Werner Menrath</b></span>
<span color='#626ff1'><b>E-Mail: polunga40@unity-mail.de</b></span>
<span color='#626ff1'><b>Bei allen Tunnel wird der Autostart deaktiviert"!"</b></span>
<span color='#626ff1'><b>Benutzung ohne Gewähr"!"</b></span>
" \
--height=100 --width=80 \
--title="Wire-G" --center \
--fixed --borders=8 --close-on-unfocus \
--buttons-layout=center \
--button=Importieren:"bash -c import_wg" \
2023-10-29 19:03:58 +01:00
--button="Wire-G Stop":"bash -c wg_stop" \
--button="Abbrechen":1 \
--separator="" --window-icon=${wg_pic}wg-vpn.png )
}
export -f more
# function end
############################################################################################################
############################################################################################################
2023-10-28 21:38:26 +02:00
# funktion wireguard enable select Tunnel
connect(){
2023-10-28 22:45:53 +02:00
success=$(grep -i "erfolgreich aktiviert" ${wg_wdir}.tmp.txt)
2023-10-28 21:38:26 +02:00
if [ "$?" = "0" ]
then
nmcli con mod $selection connection.autoconnect no
wg_notify
fi }
# function end
############################################################################################################
############################################################################################################ # --text "<b>Aktiver Tunnel:</b> <span color='#0fad0a'><b>$active</b></span> # mit <b>gewünschtes wort</b> wird fett geschrieben.
# hiermit wird die Farbe für Variable $active festgelegt mit fetter Schrift.
selection=$(yad --no-click --list \
2023-10-28 22:45:53 +02:00
--close-on-unfocus --center \
2023-10-28 21:38:26 +02:00
--height=300 --width=60 --title="Wire-G" \
--fixed --buttons-layout=center \
--button="OK" --button="Abbrechen" \
--button=Mehr:"bash -c more" --button=Entfernen:"bash -c remove" --separator="" \
2023-10-28 21:38:26 +02:00
--window-icon=${wg_pic}wg-vpn.png \
--borders=8 --image-on-top --image=${wg_pic}wg-active.png \
--text "<b>Aktiver Tunnel: </b> <span color='#0fad0a'><b>$active</b></span>
<b>----------------------------------------------------------------------------------</b>
<b>Sollten keine Tunnel aufgelistet sein,</b>
<b>so müssen sie ihren Tunnel zuvor importieren.</b>" \
--column 'Auswahl' $tunnel)
if [ "$?" = "0" ]
then
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [ -n $active ]
then
2023-10-28 21:38:26 +02:00
wg_stop
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
connect
else
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
connect
2023-10-28 21:38:26 +02:00
fi
############################################ ENDE #########################################################