zurück zu translate

This commit is contained in:
Désiré Werner Menrath 2023-11-01 13:10:57 +01:00
parent b23149cf15
commit cddec9ff5f
2 changed files with 41 additions and 40 deletions

View File

@ -7,17 +7,17 @@
wg_wdir="/home/$a_user/.config/wg_nmcli/" wg_wdir="/home/$a_user/.config/wg_nmcli/"
wg_pic="/home/$a_user/.icons/" wg_pic="/home/$a_user/.icons/"
#Damit wird der inhalt von /home/$a_user/.config/wg_nmcli/.tunnel.txt in ein Array gespeichert #Damit wird der inhalt von /home/$a_user/.config/wg_nmcli/.tunnel.txt in ein Array gespeichert
IFS=$'\n' lines=( "$(cat "${wg_wdir}.tunnel.txt")" ) IFS=$'\n' lines=( "$(cat ${wg_wdir}.tunnel.txt)" )
#echo ${lines[0]} #Damit wird der Inhalt ausgelesen. (Index angeben) #echo ${lines[0]} #Damit wird der Inhalt ausgelesen. (Index angeben)
wert=$"*_*" wert=$"*_*"
for wert in "${lines[@]}" for wert in "${lines[@]}"
do do
# rm /home/$a_user/.config/wg_nmcli/.tunnel.txt # falls Wireguard nicht richtig funktioniert hier die # wegnehmen # rm /home/$a_user/.config/wg_nmcli/.tunnel.txt # falls Wireguard nicht richtig funktioniert hier die # wegnehmen
# hier wird die Ausgabe von nmcli für die auswertung in die .stop.txt gespeichert # hier wird die Ausgabe von nmcli für die auswertung in die .stop.txt gespeichert
nmcli connection down "$wert" &> "${wg_wdir}.stop.txt" nmcli connection down $wert &> ${wg_wdir}.stop.txt
if disable=$(grep -i '"deaktiviert"\|"disabled"' "${wg_wdir}.stop.txt") if disable=$(grep -i 'deaktiviert\|disabled' ${wg_wdir}.stop.txt)
then then
notify-send --icon="${wg_pic}wg-stop.png" "$wert Connection disconnected." notify-send --icon=${wg_pic}wg-stop.png "$wert Connection disconnected."
pkill yad pkill yad
fi fi

67
wire_g
View File

@ -11,7 +11,7 @@ wg_wdir="/home/$a_user/.config/wg_nmcli/"
wg_pic="/home/$a_user/.icons/" wg_pic="/home/$a_user/.icons/"
# Wireguard tunnel auslesen mit grep nur Wireguard zeigen # Wireguard tunnel auslesen mit grep nur Wireguard zeigen
# mit sed alles nach dem ersten Leerzeichen bis Zeilenende weggeschneiden und .tunnel.txt schreiben # 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" nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${wg_wdir}.tunnel.txt
# Variable der verfügbaren Tunnelanzeige für Yad # Variable der verfügbaren Tunnelanzeige für Yad
tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
# Variable der aktiven Tunnelanzeige für Yad # Variable der aktiven Tunnelanzeige für Yad
@ -26,15 +26,15 @@ wg_notify(){
a_user=$(whoami) a_user=$(whoami)
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
wg_pic="/home/$a_user/.icons/" wg_pic="/home/$a_user/.icons/"
notify-send --icon="${wg_pic}wg-vpn.png" "$active powered" notify-send --icon=${wg_pic}wg-vpn.png "$active powered"
# autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind # autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind
nmcli con mod "$active" connection.autoconnect no nmcli con mod $active connection.autoconnect no
# ab hier beginnt yad notify # ab hier beginnt yad notify
#Pipe erstellen #Pipe erstellen
PIPE="$HOME/.pipe.tmp" PIPE="$HOME/.pipe.tmp"
rm "$PIPE" > /dev/null 2>&1 rm $PIPE > /dev/null 2>&1
mkfifo "$PIPE" mkfifo $PIPE
exec 3<> "$PIPE" exec 3<> $PIPE
#Yad Dialog erstellen #Yad Dialog erstellen
yad --notification --listen --command=wire_g --icon-size=32 --no-middle <&3 & yad --notification --listen --command=wire_g --icon-size=32 --no-middle <&3 &
#Menüeinträge definieren #Menüeinträge definieren
@ -60,18 +60,18 @@ import_wg(){
wgconf=$(yad --file --separator=" \n" \ wgconf=$(yad --file --separator=" \n" \
--button="OK" --button="Cancel" \ --button="OK" --button="Cancel" \
--width=1200 --height=800 \ --width=1200 --height=800 \
--window-icon="${wg_pic}wg-import.png" \ --window-icon=${wg_pic}wg-import.png \
--title="Wireguard .conf Select file") --title="Wireguard .conf Select file")
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [ -n "$active" ] if [[ -n $active ]]
then then
wg_stop wg_stop
nmcli connection import type wireguard file "$wgconf" > "${wg_wdir}.tmp.txt" nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt
wg_notify wg_notify
else else
nmcli connection import type wireguard file "$wgconf" > "${wg_wdir}.tmp.txt" nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt
wg_notify wg_notify
fi fi
fi } fi }
@ -87,34 +87,34 @@ remove(){
wg_pic="/home/$a_user/.icons/" wg_pic="/home/$a_user/.icons/"
wg_wdir="/home/$a_user/.config/wg_nmcli/" wg_wdir="/home/$a_user/.config/wg_nmcli/"
tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> "${wg_wdir}.wg_noactive.txt" nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> ${wg_wdir}.wg_noactive.txt
active=$(cat "${wg_wdir}.wg_noactive.txt") active=$(cat ${wg_wdir}.wg_noactive.txt)
selection=$(yad --no-click --list --height=300 --width=60 \ selection=$(yad --no-click --list --height=300 --width=60 \
--title="Wire-G Trash" --center \ --title="Wire-G Trash" --center \
--fixed --buttons-layout=center \ --fixed --buttons-layout=center \
--button="OK" --button="Cancel" \ --button="OK" --button="Cancel" \
--separator="" --window-icon="${wg_pic}wg-trash.png" \ --separator="" --window-icon=${wg_pic}wg-trash.png \
--borders=8 --column 'Delete' "$tunnel") --borders=8 --column 'Delete' $tunnel)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
nmcli connection delete "$selection" &> "${wg_wdir}.tmp.txt" nmcli connection delete $selection &> ${wg_wdir}.tmp.txt
success=$(grep -i '"erfolgreich gelöscht"\|"successfully deleted"' "${wg_wdir}.tmp.txt") success=$(grep -i '"erfolgreich gelöscht"\|"successfully deleted"' ${wg_wdir}.tmp.txt)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
yad --window-icon="${wg_pic}wg-trash.png" \ yad --window-icon=${wg_pic}wg-trash.png \
--image-on-top --image="${wg_pic}wg-info.png" \ --image-on-top --image=${wg_pic}wg-info.png \
--text="Your tunnel $selection was successfully deleted.\n" \ --text="Your tunnel $selection was successfully deleted.\n" \
--text-align=center --button="OK" --title "Wire-G Trash" \ --text-align=center --button="OK" --title "Wire-G Trash" \
--fixed --center --buttons-layout=center --borders=8 --center --fixed --center --buttons-layout=center --borders=8 --center
else else
yad --window-icon="${wg_pic}wg-trash.png" \ yad --window-icon=${wg_pic}wg-trash.png \
--image-on-top --image="${wg_pic}wg-info.png" \ --image-on-top --image=${wg_pic}wg-info.png \
--text="Oh something went wrong.\nPlease delete tunnel in the network manager." \ --text="Oh something went wrong.\nPlease delete tunnel in the network manager." \
--text-align=center --button="OK" --title "Wire-G Trash" \ --text-align=center --button="OK" --title "Wire-G Trash" \
--fixed --center --buttons-layout=center --borders=8 --center --fixed --center --buttons-layout=center --borders=8 --center
fi fi
if [ "$selection" = "$active" ] if [ $selection = $active ]
then then
pkill wire_g pkill wire_g
pkill yad pkill yad
@ -128,9 +128,9 @@ export -f remove
#funktion for active tunnel a stop #funktion for active tunnel a stop
up_or_down(){ up_or_down(){
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [ -z "$active" ] if [[ -z $active ]]
then then
yad --image-on-top --image="${wg_pic}wg-info.png" \ yad --image-on-top --image=${wg_pic}wg-info.png \
--text="There is no active tunnel that you could stop.\n" \ --text="There is no active tunnel that you could stop.\n" \
--text-align=center --button="OK" --title "Wire-G" \ --text-align=center --button="OK" --title "Wire-G" \
--fixed --center --buttons-layout=center --borders=8 --center --fixed --center --buttons-layout=center --borders=8 --center
@ -159,9 +159,9 @@ more(){
--fixed --borders=8 --close-on-unfocus \ --fixed --borders=8 --close-on-unfocus \
--buttons-layout=center \ --buttons-layout=center \
--button=Import:"bash -c import_wg" \ --button=Import:"bash -c import_wg" \
--button="Wire-G Stop":up_or_down \ --button="Wire-G Stop":"bash -c up_or_down" \
--button="Cancel":1 \ --button="Cancel":1 \
--separator="" --window-icon="${wg_pic}wg-vpn.png") --separator="" --window-icon=${wg_pic}wg-vpn.png)
} }
export -f more export -f more
@ -172,10 +172,10 @@ export -f more
connect(){ connect(){
success=$(grep -i '"erfolgreich aktiviert"\|"successfully activated"' "${wg_wdir}.tmp.txt") success=$(grep -i '"erfolgreich aktiviert"\|"successfully activated"' ${wg_wdir}.tmp.txt)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
nmcli con mod "$selection" connection.autoconnect no nmcli con mod $selection connection.autoconnect no
wg_notify wg_notify
fi } fi }
@ -190,26 +190,27 @@ selection=$(yad --no-click --list \
--fixed --buttons-layout=center \ --fixed --buttons-layout=center \
--button="OK" --button="Cancel" \ --button="OK" --button="Cancel" \
--button=More:"bash -c more" --button=Remove:"bash -c remove" --separator="" \ --button=More:"bash -c more" --button=Remove:"bash -c remove" --separator="" \
--window-icon="${wg_pic}wg-vpn.png" \ --window-icon=${wg_pic}wg-vpn.png \
--borders=8 --image-on-top --image="${wg_pic}wg-active.png" \ --borders=8 --image-on-top --image=${wg_pic}wg-active.png \
--text "<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$active</b></span> --text "<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$active</b></span>
<b>----------------------------------------------------------------------------------</b> <b>----------------------------------------------------------------------------------</b>
<b>If no tunnels are listed,</b> <b>If no tunnels are listed,</b>
<b>so they have to import their tunnel beforehand.</b>" \ <b>so they have to import their tunnel beforehand.</b>" \
--column 'Selection' "$tunnel") --column 'Selection' $tunnel)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
if [ -n "$active" ] if [[ -n $active ]]
then then
wg_stop wg_stop
nmcli connection up "$selection" &> "${wg_wdir}.tmp.txt" nmcli connection up $selection &> ${wg_wdir}.tmp.txt
connect connect
else else
nmcli connection up "$selection" &> "${wg_wdir}.tmp.txt" nmcli connection up $selection &> ${wg_wdir}.tmp.txt
connect connect
fi fi
fi fi
############################################ END ########################################################## ############################################ END ##########################################################