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-02 22:36:14 +01:00
|
|
|
version=3.0.8
|
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/ .*//')
|
|
|
|
|
|
|
|
############################################################################################################
|
|
|
|
############################################################################################################
|
|
|
|
# funktion wg_notify
|
|
|
|
|
|
|
|
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-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-01 13:10:57 +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-03 21:16:03 +01:00
|
|
|
echo "tooltip:$active activ" >&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-01 16:16:38 +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-10-30 19:44:47 +01:00
|
|
|
then
|
|
|
|
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
|
2023-11-01 13:10:57 +01:00
|
|
|
if [[ -n $active ]]
|
2023-11-01 09:05:51 +01:00
|
|
|
then
|
2023-11-01 09:54:42 +01:00
|
|
|
wg_stop
|
2023-11-01 13:10:57 +01:00
|
|
|
nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt
|
2023-10-30 19:44:47 +01:00
|
|
|
wg_notify
|
|
|
|
else
|
2023-11-01 13:10:57 +01:00
|
|
|
nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt
|
2023-10-30 19:44:47 +01:00
|
|
|
wg_notify
|
|
|
|
fi
|
|
|
|
fi }
|
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-01 16:16:38 +01:00
|
|
|
if selection=$(yad --no-click --list --height=300 --width=60 \
|
2023-10-28 22:45:53 +02:00
|
|
|
--title="Wire-G Trash" --center \
|
2023-10-28 21:38:26 +02:00
|
|
|
--fixed --buttons-layout=center \
|
2023-11-01 17:41:32 +01:00
|
|
|
--button=$"OK" --button=$"Cancel" \
|
2023-11-01 13:10:57 +01:00
|
|
|
--separator="" --window-icon=${wg_pic}wg-trash.png \
|
2023-11-02 11:01:37 +01:00
|
|
|
--borders=8 --column=$"Delete" $tunnel)
|
2023-10-30 19:44:47 +01:00
|
|
|
then
|
2023-11-01 13:10:57 +01:00
|
|
|
nmcli connection delete $selection &> ${wg_wdir}.tmp.txt
|
2023-11-01 14:27:39 +01:00
|
|
|
success=$(grep -i 'erfolgreich gelöscht\|successfully deleted' ${wg_wdir}.tmp.txt)
|
2023-10-30 19:44:47 +01:00
|
|
|
if [ "$?" = "0" ]
|
|
|
|
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-02 20:58:08 +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-10-30 19:44:47 +01:00
|
|
|
--fixed --center --buttons-layout=center --borders=8 --center
|
|
|
|
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-10-30 19:44:47 +01:00
|
|
|
--fixed --center --buttons-layout=center --borders=8 --center
|
|
|
|
fi
|
2023-11-01 13:10:57 +01:00
|
|
|
if [ $selection = $active ]
|
2023-10-30 19:44:47 +01:00
|
|
|
then
|
|
|
|
pkill wire_g
|
|
|
|
pkill yad
|
|
|
|
fi
|
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
|
|
|
|
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-02 22:53:50 +01:00
|
|
|
version=3.0.8
|
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-10-29 18:44:48 +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-03 14:05:31 +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-03 14:05:31 +01:00
|
|
|
<a href='https://git.lunix.dedyn.io/punix/Wire-G'>Download Wire-G </a> \n")
|
|
|
|
|
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-01 13:10:57 +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-03 14:05:31 +01:00
|
|
|
--column=$"Selection" $tunnel \
|
|
|
|
--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-01 13:10:57 +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-01 13:10:57 +01:00
|
|
|
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
|
2023-10-30 19:44:47 +01:00
|
|
|
connect
|
|
|
|
else
|
2023-11-01 13:10:57 +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
|
|
|
|