stop wieder in wire_g kleinere fixes

This commit is contained in:
Désiré Werner Menrath 2023-11-16 12:42:18 +01:00
parent 35bccd9744
commit b25e076046
4 changed files with 58 additions and 77 deletions

View File

@ -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

View File

@ -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

49
wg_stop
View File

@ -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=$"<span color='#0fad0a'><b>"$VALUE" Connection</b></span><span> <b>disconnected</b></span>"
fi
done
IFS=$'\n' lines=( $(awk '{print $2}' ${WG_WDIR}Notify_PID.txt) ) # Dies zeigt auf die richtige pid
kill $lines
################################# END ##################################################################
############################################################################################################

78
wire_g
View File

@ -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=$"<span color='#0fad0a'><b>"$VALUE" Connection</b></span><span> <b>disconnected</b></span>"
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=$"<span color='#0fad0a'><b>"$ACTIVE"</b></span> <span><b>powered</b></span>" &
--text=$"<span color='#0fad0a'><b>"$ACTIVE"</b></span> <span><b>powered</b></span>" &
# 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