2023-10-28 21:38:26 +02:00
|
|
|
#!/bin/bash
|
2023-11-01 18:05:46 +01:00
|
|
|
########################################################
|
|
|
|
########################################################
|
|
|
|
# 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! ##
|
|
|
|
########################################################
|
|
|
|
########################################################
|
|
|
|
|
2023-11-01 17:44:23 +01:00
|
|
|
Encoding=UTF-8
|
2023-11-01 18:05:46 +01:00
|
|
|
|
2023-11-01 17:44:23 +01:00
|
|
|
# i18n - Internationalization - Internationalisierung
|
2023-11-01 18:05:46 +01:00
|
|
|
|
2023-11-01 21:46:24 +01:00
|
|
|
export TEXTDOMAIN=wire-g
|
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
2023-11-01 18:05:46 +01:00
|
|
|
|
2023-10-28 21:38:26 +02:00
|
|
|
############################################################################################################
|
|
|
|
############################################################################################################
|
2023-11-08 20:46:16 +01:00
|
|
|
version=3.1.1
|
2023-10-28 21:38:26 +02:00
|
|
|
# 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
|
2023-11-01 13:10:57 +01:00
|
|
|
nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${wg_wdir}.tunnel.txt
|
2023-10-28 21:38:26 +02:00
|
|
|
# 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/ .*//')
|
|
|
|
|
|
|
|
############################################################################################################
|
2023-11-08 09:03:02 +01:00
|
|
|
############################################################################################################
|
2023-10-28 21:38:26 +02:00
|
|
|
|
|
|
|
wg_notify(){
|
2023-11-01 07:57:13 +01:00
|
|
|
|
2023-10-28 21:38:26 +02:00
|
|
|
a_user=$(whoami)
|
|
|
|
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
|
|
|
|
wg_pic="/home/$a_user/.icons/"
|
2023-11-08 19:49:09 +01:00
|
|
|
case $LANG in
|
|
|
|
|
2023-11-08 19:56:26 +01:00
|
|
|
de_DE.UTF-8) show=aktiv ;;
|
2023-11-08 19:49:09 +01:00
|
|
|
|
|
|
|
|
2023-11-08 19:56:26 +01:00
|
|
|
*) show=activ ;;
|
2023-11-08 19:49:09 +01:00
|
|
|
esac
|
2023-11-02 20:58:08 +01:00
|
|
|
notify-send --icon=${wg_pic}wg-vpn.png $"$active powered"
|
2023-10-28 21:38:26 +02:00
|
|
|
# autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind
|
2023-11-07 19:55:03 +01:00
|
|
|
nmcli con mod $active connection.autoconnect no
|
2023-10-28 21:38:26 +02:00
|
|
|
# ab hier beginnt yad notify
|
|
|
|
#Pipe erstellen
|
|
|
|
PIPE="$HOME/.pipe.tmp"
|
2023-11-01 13:10:57 +01:00
|
|
|
rm $PIPE > /dev/null 2>&1
|
|
|
|
mkfifo $PIPE
|
|
|
|
exec 3<> $PIPE
|
2023-10-28 21:38:26 +02:00
|
|
|
#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
|
2023-11-08 19:56:26 +01:00
|
|
|
echo "tooltip:$active $show" >&3
|
2023-10-28 21:38:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
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/"
|
2023-11-08 17:53:22 +01:00
|
|
|
if wgconf=$(yad --file --separator=" \n" \
|
2023-11-02 21:22:08 +01:00
|
|
|
--button="OK" --button=$"Cancel" \
|
2023-10-28 21:38:26 +02:00
|
|
|
--width=1200 --height=800 \
|
2023-11-01 13:10:57 +01:00
|
|
|
--window-icon=${wg_pic}wg-import.png \
|
2023-11-01 17:41:32 +01:00
|
|
|
--title=$"Wireguard .conf Select file")
|
2023-11-09 16:53:37 +01:00
|
|
|
|
2023-11-08 17:53:22 +01:00
|
|
|
then
|
|
|
|
case "$wgconf" in
|
2023-11-08 17:05:12 +01:00
|
|
|
|
2023-11-08 17:53:22 +01:00
|
|
|
*_*.conf) if grep -i 'PEER\|PublicKey' $wgconf > /dev/null && grep -i 'Interface\|PrivateKey' $wgconf > /dev/null
|
2023-11-09 17:14:02 +01:00
|
|
|
then
|
2023-11-09 18:39:47 +01:00
|
|
|
for wgconf in $(cat ${wg_wdir}.tunnel.txt)
|
2023-11-09 17:28:22 +01:00
|
|
|
do
|
|
|
|
yad --window-icon=${wg_pic}wg-stop.png \
|
2023-11-09 17:14:02 +01:00
|
|
|
--image=${wg_pic}wg-info.png --button "OK" \
|
2023-11-09 19:05:26 +01:00
|
|
|
--title=$"Wire-G" --image-on-top --borders=8 \
|
|
|
|
--text-align=center --buttons-layout=center \
|
|
|
|
--text $"Tunnel name already exists."
|
|
|
|
exit 0
|
2023-11-09 17:14:02 +01:00
|
|
|
done
|
2023-11-08 17:53:22 +01:00
|
|
|
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
|
|
|
|
if [[ -n $active ]]
|
|
|
|
then
|
|
|
|
wg_stop
|
|
|
|
nmcli connection import type wireguard file $wgconf &> ${wg_wdir}.tmp.txt
|
|
|
|
wg_notify
|
|
|
|
|
2023-11-09 16:53:37 +01:00
|
|
|
else
|
2023-11-08 17:53:22 +01:00
|
|
|
nmcli connection import type wireguard file $wgconf &> ${wg_wdir}.tmp.txt
|
|
|
|
wg_notify
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi ;;
|
|
|
|
|
|
|
|
*) yad --text-align=center --button=$"OK" --title=$"Wireguard .conf Select file" \
|
2023-11-08 20:23:22 +01:00
|
|
|
--image-on-top --window-icon=${wg_pic}wg-stop.png --image=${wg_pic}wg-info.png \
|
|
|
|
--fixed --center --buttons-layout=center --borders=8 \
|
|
|
|
--text $"<b>Oh, something went wrong.</b> \n
|
2023-11-08 09:11:31 +01:00
|
|
|
<b>No valid Wireguard file.</b> \n
|
2023-11-08 17:53:22 +01:00
|
|
|
<b>Here is an example:</b><span color='#0fad0a'><b> my_wireguard.conf</b></span> \n"
|
|
|
|
import_wg ;;
|
|
|
|
esac
|
|
|
|
else
|
2023-11-08 19:27:38 +01:00
|
|
|
wire_g
|
2023-11-08 18:05:00 +01:00
|
|
|
fi
|
2023-11-08 19:27:38 +01:00
|
|
|
|
2023-11-08 18:05:00 +01:00
|
|
|
}
|
2023-10-28 21:38:26 +02:00
|
|
|
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/ .*//')
|
2023-11-01 13:10:57 +01:00
|
|
|
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> ${wg_wdir}.wg_noactive.txt
|
|
|
|
active=$(cat ${wg_wdir}.wg_noactive.txt)
|
2023-10-28 21:38:26 +02:00
|
|
|
|
2023-11-05 11:07:20 +01:00
|
|
|
if selection=$(yad --no-click --list --center \
|
|
|
|
--window-icon=${wg_pic}wg-trash.png \
|
|
|
|
--height=300 --width=60 --title="Wire-G Trash" \
|
|
|
|
--fixed --buttons-layout=center --separator="" \
|
|
|
|
--button=$"OK" --button=$"Cancel" \
|
|
|
|
--borders=8 --image-on-top --image=${wg_pic}wg-active.png \
|
2023-11-07 19:55:03 +01:00
|
|
|
--column=$"Delete" $tunnel \
|
2023-11-05 11:07:20 +01:00
|
|
|
--text=$"<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$active</b></span>
|
|
|
|
<b>----------------------------------------------------------------------------------</b>
|
|
|
|
<b>If no tunnels are listed,</b>
|
|
|
|
<b>so they have to import their tunnel beforehand.</b>")
|
|
|
|
|
2023-10-30 19:44:47 +01:00
|
|
|
then
|
2023-11-07 19:55:03 +01:00
|
|
|
nmcli connection delete $selection &> ${wg_wdir}.tmp.txt
|
2023-11-07 19:47:05 +01:00
|
|
|
if success=$(grep -i 'erfolgreich gelöscht\|successfully deleted' ${wg_wdir}.tmp.txt)
|
2023-10-30 19:44:47 +01:00
|
|
|
then
|
2023-11-01 13:10:57 +01:00
|
|
|
yad --window-icon=${wg_pic}wg-trash.png \
|
|
|
|
--image-on-top --image=${wg_pic}wg-info.png \
|
2023-11-07 19:55:03 +01:00
|
|
|
--text=$"Your tunnel $selection was successfully deleted." \
|
2023-11-01 17:41:32 +01:00
|
|
|
--text-align=center --button=$"OK" --title "Wire-G Trash" \
|
2023-11-09 19:05:26 +01:00
|
|
|
--fixed --center --buttons-layout=center --borders=8
|
2023-10-30 19:44:47 +01:00
|
|
|
else
|
2023-11-01 13:10:57 +01:00
|
|
|
yad --window-icon=${wg_pic}wg-trash.png \
|
|
|
|
--image-on-top --image=${wg_pic}wg-info.png \
|
2023-11-01 17:41:32 +01:00
|
|
|
--text=$"Oh something went wrong.\nPlease delete tunnel in the network manager." \
|
|
|
|
--text-align=center --button=$"OK" --title "Wire-G Trash" \
|
2023-11-09 19:05:26 +01:00
|
|
|
--fixed --center --buttons-layout=center --borders=8
|
2023-10-30 19:44:47 +01:00
|
|
|
fi
|
2023-11-07 19:47:05 +01:00
|
|
|
if [ "$selection" = "$active" ]
|
2023-10-30 19:44:47 +01:00
|
|
|
then
|
|
|
|
pkill wire_g
|
|
|
|
pkill yad
|
|
|
|
fi
|
2023-11-05 12:19:08 +01:00
|
|
|
wire_g
|
2023-10-28 21:38:26 +02:00
|
|
|
fi }
|
|
|
|
export -f remove
|
|
|
|
|
|
|
|
# function end
|
|
|
|
############################################################################################################
|
|
|
|
############################################################################################################
|
2023-11-01 09:54:42 +01:00
|
|
|
#funktion for active tunnel a stop
|
2023-11-07 20:37:53 +01:00
|
|
|
|
2023-11-01 09:54:42 +01:00
|
|
|
up_or_down(){
|
2023-11-01 13:21:30 +01:00
|
|
|
a_user=$(whoami)
|
|
|
|
wg_pic="/home/$a_user/.icons/"
|
2023-11-01 10:31:14 +01:00
|
|
|
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
|
2023-11-01 13:10:57 +01:00
|
|
|
if [[ -z $active ]]
|
2023-11-01 10:31:14 +01:00
|
|
|
then
|
2023-11-01 13:10:57 +01:00
|
|
|
yad --image-on-top --image=${wg_pic}wg-info.png \
|
2023-11-02 20:58:08 +01:00
|
|
|
--text=$"There is no active tunnel that you could stop." \
|
2023-11-01 17:41:32 +01:00
|
|
|
--text-align=center --button=$"OK" --title "Wire-G" \
|
2023-11-02 21:22:08 +01:00
|
|
|
--fixed --center --buttons-layout=center --borders=8
|
2023-11-01 10:31:14 +01:00
|
|
|
else
|
|
|
|
wg_stop
|
2023-11-01 09:54:42 +01:00
|
|
|
|
2023-11-01 10:31:14 +01:00
|
|
|
fi }
|
2023-11-01 10:11:42 +01:00
|
|
|
export -f up_or_down
|
2023-11-01 09:54:42 +01:00
|
|
|
|
|
|
|
# funktion end
|
|
|
|
############################################################################################################
|
|
|
|
############################################################################################################
|
2023-10-29 18:33:07 +01:00
|
|
|
# function button "more"
|
|
|
|
|
|
|
|
more(){
|
|
|
|
a_user=$(whoami)
|
|
|
|
wg_pic="/home/$a_user/.icons/"
|
2023-11-08 20:46:16 +01:00
|
|
|
version=3.1.1
|
2023-11-03 14:05:31 +01:00
|
|
|
selection=$(yad --height=100 --width=80 \
|
2023-10-29 18:33:07 +01:00
|
|
|
--title="Wire-G" --center \
|
2023-11-08 20:34:06 +01:00
|
|
|
--fixed --borders=8 --close-on-unfocus \
|
2023-11-02 22:36:14 +01:00
|
|
|
--buttons-layout=center --text-align=center \
|
2023-11-01 17:41:32 +01:00
|
|
|
--button=$"Import":"bash -c import_wg" \
|
|
|
|
--button=$"Wire-G Stop":"bash -c up_or_down" \
|
|
|
|
--button=$"Cancel":1 \
|
2023-11-03 14:05:31 +01:00
|
|
|
--separator="" --window-icon=${wg_pic}wg-vpn.png \
|
|
|
|
--text=$"<span color='#626ff1'><b>Wire-G Author: Désiré Werner Menrath</b></span> \n
|
|
|
|
<span color='#626ff1'><b>E-Mail: polunga40@unity-mail.de</b></span> \n
|
2023-11-03 18:30:57 +01:00
|
|
|
<span color='#626ff1'><b>At all tunnels, the auto start is disabled.</b></span> \n
|
2023-11-07 19:55:03 +01:00
|
|
|
<span color='#626ff1'><b>Version: $version </b></span> \n
|
2023-11-03 18:30:57 +01:00
|
|
|
<span color='#626ff1'><b>Use without warranty.</b></span> \n
|
2023-11-08 20:34:06 +01:00
|
|
|
<a href='https://git.lunix.dedyn.io/punix/Wire-G'>Download Wire-G </a> \n")
|
2023-11-03 14:05:31 +01:00
|
|
|
|
2023-10-29 18:33:07 +01:00
|
|
|
}
|
|
|
|
export -f more
|
2023-11-01 07:57:13 +01:00
|
|
|
|
2023-10-29 18:33:07 +01:00
|
|
|
# function end
|
|
|
|
############################################################################################################
|
|
|
|
############################################################################################################
|
2023-10-28 21:38:26 +02:00
|
|
|
# funktion wireguard enable select Tunnel
|
|
|
|
|
|
|
|
connect(){
|
|
|
|
|
2023-11-01 16:16:38 +01:00
|
|
|
if success=$(grep -i 'erfolgreich aktiviert\|successfully activated' ${wg_wdir}.tmp.txt)
|
2023-10-28 21:38:26 +02:00
|
|
|
then
|
2023-11-07 19:55:03 +01:00
|
|
|
nmcli con mod $selection connection.autoconnect no
|
2023-10-30 19:44:47 +01:00
|
|
|
wg_notify
|
|
|
|
fi }
|
2023-10-28 21:38:26 +02:00
|
|
|
|
|
|
|
# function end
|
|
|
|
############################################################################################################
|
|
|
|
############################################################################################################ # --text "<b>Aktiver Tunnel:</b> <span color='#0fad0a'><b>$active</b></span> # mit <b>gewünschtes wort</b> wird fett geschrieben.
|
2023-11-01 07:57:13 +01:00
|
|
|
# Farbe für Variable $active festgelegt mit fetter Schrift. (bei --text zwischen " ")
|
2023-10-28 21:38:26 +02:00
|
|
|
|
2023-11-01 16:16:38 +01:00
|
|
|
if 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 \
|
2023-11-01 17:41:32 +01:00
|
|
|
--button=$"OK" --button=$"Cancel" \
|
|
|
|
--button=$"More":"bash -c more" --button=$"Remove":"bash -c remove" --separator="" \
|
2023-11-01 13:10:57 +01:00
|
|
|
--window-icon=${wg_pic}wg-vpn.png \
|
|
|
|
--borders=8 --image-on-top --image=${wg_pic}wg-active.png \
|
2023-11-07 19:55:03 +01:00
|
|
|
--column=$"Selection" $tunnel \
|
2023-11-03 14:05:31 +01:00
|
|
|
--text=$"<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$active</b></span>
|
2023-10-28 21:38:26 +02:00
|
|
|
<b>----------------------------------------------------------------------------------</b>
|
2023-11-01 07:57:13 +01:00
|
|
|
<b>If no tunnels are listed,</b>
|
2023-11-03 14:05:31 +01:00
|
|
|
<b>so they have to import their tunnel beforehand.</b>")
|
|
|
|
|
2023-10-30 19:44:47 +01:00
|
|
|
then
|
2023-11-01 09:05:51 +01:00
|
|
|
|
2023-11-07 19:55:03 +01:00
|
|
|
if [[ -n $active ]]
|
2023-10-30 19:44:47 +01:00
|
|
|
then
|
2023-11-01 09:05:51 +01:00
|
|
|
wg_stop
|
2023-11-07 19:55:03 +01:00
|
|
|
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
|
2023-10-30 19:44:47 +01:00
|
|
|
connect
|
|
|
|
else
|
2023-11-07 19:55:03 +01:00
|
|
|
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
|
2023-10-30 19:44:47 +01:00
|
|
|
connect
|
|
|
|
fi
|
|
|
|
fi
|
2023-10-28 21:38:26 +02:00
|
|
|
|
2023-11-01 07:57:13 +01:00
|
|
|
############################################ END ##########################################################
|
2023-10-28 21:38:26 +02:00
|
|
|
|
2023-11-01 13:10:57 +01:00
|
|
|
|