Dateien nach "/" hochladen
This commit is contained in:
159
wire_g
Normal file
159
wire_g
Normal file
@ -0,0 +1,159 @@
|
||||
#!/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"
|
||||
rm $PIPE
|
||||
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 \
|
||||
--title="Wire-G Trash" \
|
||||
--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
|
||||
erfolg=$(grep -i "Verbindung erfolgreich gelöscht" ${wg_wdir}.tmp.txt)
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
yad --window-icon=${wg_pic}wg-trash.png \
|
||||
--image-on-top --image=${wg_pic}wg-info.png \
|
||||
--text="Oh etwas ging schief.\nBitte Tunnel im Networkmanager löschen." \
|
||||
--text-align=center --button="OK" --title "Wire-G Trash" \
|
||||
--fixed --center --buttons-layout=center --borders=8 --center
|
||||
else
|
||||
yad --window-icon=${wg_pic}wg-trash.png \
|
||||
--image-on-top --image=${wg_pic}wg-info.png \
|
||||
--text="Ihr Tunnel $selection wurde erfolgreich gelöscht.\n" \
|
||||
--text-align=center --button="OK" --title "Wire-G Trash" \
|
||||
--fixed --center --buttons-layout=center --borders=8 --center
|
||||
fi
|
||||
if [ $selection = $active ]
|
||||
then
|
||||
pkill wire_g
|
||||
pkill yad
|
||||
fi
|
||||
fi }
|
||||
export -f remove
|
||||
|
||||
# function end
|
||||
############################################################################################################
|
||||
############################################################################################################
|
||||
# funktion wireguard enable select Tunnel
|
||||
|
||||
connect(){
|
||||
|
||||
erfolg=$(grep -i "Verbindung wurde erfolgreich aktiviert" ${wg_wdir}.tmp.txt)
|
||||
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 \
|
||||
--close-on-unfocus --tab=Löschen \
|
||||
--height=300 --width=60 --title="Wire-G" \
|
||||
--fixed --buttons-layout=center \
|
||||
--button="OK" --button="Abbrechen" \
|
||||
--button=Importieren:"bash -c import_wg" \
|
||||
--button=Entfernen:"bash -c remove" --separator="" \
|
||||
--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
|
||||
wg_stop
|
||||
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
|
||||
connect
|
||||
fi
|
||||
|
||||
############################################ ENDE #########################################################
|
||||
|
Reference in New Issue
Block a user