From b25e07604670f9bab3f876248e9cdda2e42df4b3 Mon Sep 17 00:00:00 2001 From: punix Date: Thu, 16 Nov 2023 12:42:18 +0100 Subject: [PATCH] stop wieder in wire_g kleinere fixes --- installer1.0.5 | 2 +- uninstaller1.0.0 | 4 +-- wg_stop | 49 ----------------------------- wire_g | 80 +++++++++++++++++++++++++++++++++--------------- 4 files changed, 58 insertions(+), 77 deletions(-) delete mode 100755 wg_stop diff --git a/installer1.0.5 b/installer1.0.5 index c32f730..6da81bf 100755 --- a/installer1.0.5 +++ b/installer1.0.5 @@ -62,7 +62,7 @@ fi wait; sudo mkdir -p /usr/share/icons/Arch-Symbole ; sudo cp icons/wg-vpn.png /usr/share/icons/Arch-Symbole/ wait; -sudo cp wire_g wg_stop /sbin/ ; sudo chmod +x /sbin/wire_g ; sudo chmod +x /sbin/wg_stop +sudo cp wire_g /sbin/ ; sudo chmod +x /sbin/wire_g wait; sudo cp Wire-G.desktop /usr/share/applications/ echo case $LANG in diff --git a/uninstaller1.0.0 b/uninstaller1.0.0 index 39964f7..2fcef88 100755 --- a/uninstaller1.0.0 +++ b/uninstaller1.0.0 @@ -15,9 +15,7 @@ rm -f /home/"$USER"/.icons/wg-active.png wg-stop.png wg-vpn.png wg-import.png wg wait; rm -r /home/"$USER"/.config/wg_nmcli wait; -sudo rm /usr/share/icons/Arch-Symbole/wg-vpn.png -wait; -sudo rm /sbin/wire_g ; sudo rm /sbin/wg_stop +sudo rm /usr/share/icons/Arch-Symbole/wg-vpn.png ; sudo rm /sbin/wire_g wait; sudo rm /usr/share/applications/Wire-G.desktop ; sudo rm /usr/share/locale/de/LC_MESSAGES/wire-g.mo echo diff --git a/wg_stop b/wg_stop deleted file mode 100755 index e31329f..0000000 --- a/wg_stop +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -######################################################## -######################################################## -# Wire-G App for simple management a Wireguard Tunnel ## -# Author: Désiré Werner Menrath ## -# Email: polunga40@unity-mail.de ## -# Translate German to English with LibreTranslate ## -# Translatefiles edit with Poedit ## -# Use without warranty! ## -######################################################## -######################################################## - -Encoding=UTF-8 - -# i18n - Internationalization - Internationalisierung - -export TEXTDOMAIN=wire-g -export TEXTDOMAINDIR="/usr/share/locale" - -############################################################################################################ -############################################################################################################ - - WG_WDIR="/home/$USER/.config/wg_nmcli/" - WG_PIC="/home/$USER/.icons/" - #Dieser befehl ist notwendig da nach dem import (erster Start) gestartete Tunnel nicht in der .tunnel Datei stehen. - nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${WG_WDIR}.tunnel.txt - #Damit wird der inhalt von /home/$USER/.config/wg_nmcli/.tunnel.txt in ein Array gespeichert - IFS=$'\n' lines=( $(cat ${WG_WDIR}.tunnel.txt) ) - #echo ${lines[0]} #Damit wird der Inhalt ausgelesen. (Index angeben) - VALUE=$"*_*" - for VALUE in "${lines[@]}" - do - # hier wird die Ausgabe von nmcli für die auswertung in die .stop.txt gespeichert - nmcli connection down "$VALUE" &> ${WG_WDIR}.stop.txt - if disable=$(grep -i 'deaktiviert\|deactivated' ${WG_WDIR}.stop.txt) - then - yad --image-on-top --image=${WG_PIC}wg-info.png \ - --undecorated --borders=8 --skip-taskbar \ - --text-align=center --no-buttons \ - --timeout 2 --timeout-indicator=bottom \ - --text=$""$VALUE" Connection disconnected" - fi - done - IFS=$'\n' lines=( $(awk '{print $2}' ${WG_WDIR}Notify_PID.txt) ) # Dies zeigt auf die richtige pid - kill $lines - -################################# END ################################################################## -############################################################################################################ - diff --git a/wire_g b/wire_g index e85e288..1968d8f 100755 --- a/wire_g +++ b/wire_g @@ -31,9 +31,37 @@ nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${WG_WDIR 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/ .*//') - +# Dies zeigt auf die richtige pid + ############################################################################################################ ############################################################################################################ +wg_stop(){ + + #Dieser befehl ist notwendig da nach dem import (erster Start) gestartete Tunnel nicht in der .tunnel Datei stehen. + nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${WG_WDIR}.tunnel.txt + #Damit wird der inhalt von /home/$USER/.config/wg_nmcli/.tunnel.txt in ein Array gespeichert + IFS=$'\n' lines=( $(cat ${WG_WDIR}.tunnel.txt) ) + #echo ${lines[0]} #Damit wird der Inhalt ausgelesen. (Index angeben) + VALUE=$"*_*" + for VALUE in "${lines[@]}" + do + # hier wird die Ausgabe von nmcli für die auswertung in die .stop.txt gespeichert + nmcli connection down "$VALUE" &> ${WG_WDIR}.stop.txt + if disable=$(grep -i 'deaktiviert\|deactivated' ${WG_WDIR}.stop.txt) + then + yad --image-on-top --image=${WG_PIC}wg-info.png \ + --undecorated --borders=8 --skip-taskbar \ + --text-align=center --no-buttons \ + --timeout 2 --timeout-indicator=bottom \ + --text=$""$VALUE" Connection disconnected" + fi + done + IFS=$'\n' lines=( $(awk '{print $2}' ${WG_WDIR}Notify_PID.txt) ) + kill $lines +} + +################################# END ################################################################## +############################################################################################################ wg_notify(){ @@ -50,20 +78,21 @@ wg_notify(){ --undecorated --borders=8 --skip-taskbar \ --text-align=center --no-buttons --auto-close \ --timeout 2 --timeout-indicator=bottom \ - --text=$""$ACTIVE" powered" & + --text=$""$ACTIVE" powered" & # autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind nmcli con mod "$ACTIVE" connection.autoconnect no yad --notification \ - --image="${WG_PIC}wg-vpn.png" \ - --icon-size=32 --no-middle \ - --text=$"$ACTIVE activ" \ - --menu="Wire-G $OPEN!/sbin/wire_g - |$ACTIVE stop!/sbin/wg_stop" \ - --command="menu" & + --image="${WG_PIC}wg-vpn.png" \ + --icon-size=32 --no-middle \ + --text=$"$ACTIVE activ" \ + --menu="Wire-G $OPEN!/sbin/wire_g + |$ACTIVE stop!/sbin/wg_stop" \ + --command="menu" & # Schreib die pid von Notify in pid=$(ps aux | grep yad | grep -v grep | awk '{print $2}') echo $pid > ${WG_WDIR}Notify_PID.txt + IFS=$'\n' lines=( $(awk '{print $2}' ${WG_WDIR}Notify_PID.txt) ) } @@ -77,10 +106,10 @@ import_wg(){ WG_PIC="/home/$USER/.icons/" WG_WDIR="/home/$USER/.config/wg_nmcli/" if WG_CONF=$(yad --file --separator=" \n" \ - --button="OK" --button=$"Cancel" \ - --width=1200 --height=800 --no-klick \ - --window-icon=${WG_PIC}wg-import.png \ - --title=$"Wireguard .conf Select file") + --button="OK" --button=$"Cancel" \ + --width=1200 --height=800 --no-klick \ + --window-icon=${WG_PIC}wg-import.png \ + --title=$"Wireguard .conf Select file") then case "$WG_CONF" in @@ -94,7 +123,6 @@ import_wg(){ nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt wg_notify else - IFS=$'\n' lines=( $(awk '{print $2}' ${WG_WDIR}Notify_PID.txt) ) # Dies zeigt auf die richtige pid kill $lines nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt wg_notify @@ -109,7 +137,6 @@ import_wg(){ import_wg ;; esac fi } -export -f import_wg # function end ############################################################################################################ @@ -139,8 +166,7 @@ remove(){ if [ "$SELECTION" = "$ACTIVE" ] then - IFS=$'\n' lines=( $(awk '{print $2}' ${WG_WDIR}Notify_PID.txt) ) # Dies zeigt auf die richtige pid - kill $lines + kill $lines fi } # function end @@ -158,13 +184,11 @@ up_or_down(){ --text=$"There is no active Tunnel that you could stop." \ --text-align=center --no-buttons \ --borders=8 --undecorated \ - --timeout 4 --timeout-indicator=bottom --skip-taskbar + --timeout 3 --timeout-indicator=bottom --skip-taskbar else wg_stop - wire_g fi } -export -f up_or_down # funktion end ############################################################################################################ @@ -196,7 +220,6 @@ connect(){ if SUCCESS=$(grep -i 'erfolgreich aktiviert\|successfully activated' ${WG_WDIR}.tmp.txt) then - pkill yad nmcli con mod $SELECTION connection.autoconnect no wg_notify @@ -210,10 +233,9 @@ connect(){ SELECTION=$(yad --no-klick --list --center \ --height=300 --width=60 --title="Wire-G" \ --buttons-layout=center \ - --button=$"Start:0" --button=$"Stop":"bash -c up_or_down" \ - --button=$"Import":"bash -c import_wg" \ - --button=$"Remove:4" --separator="" \ - --button=$"About:5" \ + --button=$"Start:0" --button=$"Stop:2" \ + --button=$"Import:3" --button=$"Remove:4" \ + --button=$"About:5" --separator="" \ --window-icon=${WG_PIC}wg-vpn.png \ --borders=8 --image-on-top --image=${WG_PIC}wg-active.png \ --column=$"Selection" $TUNNEL \ @@ -225,6 +247,16 @@ RET=$? [[ $? -eq 1 ]] && exit 0 +if [[ $RET -eq 2 ]] + then + wg_stop +fi + +if [[ $RET -eq 3 ]] + then + import_wg +fi + if [[ $RET -eq 4 ]] then remove