Wire-G/wire_g

250 lines
11 KiB
Plaintext
Raw Normal View History

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 ##
2023-11-01 18:05:46 +01:00
# 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
2023-11-01 18:05:46 +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
############################################################################################################
############################################################################################################
VERSION=3.1.5
2023-10-28 21:38:26 +02:00
# wg_workdir Arbeitsverzeichnis wg
WG_WDIR="/home/$USER/.config/wg_nmcli/"
2023-10-28 21:38:26 +02:00
# Pfad wg Icons
WG_PIC="/home/$USER/.icons/"
# Wireguard TUNNEL auslesen mit grep nur Wireguard zeigen
# 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
# 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-10-28 21:38:26 +02:00
############################################################################################################
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
ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
WG_PIC="/home/$USER/.icons/"
2023-11-08 19:49:09 +01:00
case $LANG in
de_DE.UTF-8) OPEN=öffnen ;;
2023-11-08 19:49:09 +01:00
*) OPEN=open ;;
2023-11-08 19:49:09 +01:00
esac
2023-11-15 12:38:16 +01:00
yad --image-on-top --image=${WG_PIC}wg-vpn-info.png \
--undecorated --borders=8 --skip-taskbar \
--text-align=center --no-buttons --auto-close \
2023-11-15 12:38:16 +01:00
--timeout 4 --timeout-indicator=bottom \
--text=$"<span color='#0fad0a'><b>"$ACTIVE" powered</b></span>" &
2023-10-28 21:38:26 +02:00
# autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind
nmcli con mod "$ACTIVE" connection.autoconnect no
2023-11-10 22:50:33 +01:00
yad --notification \
--image="${WG_PIC}wg-vpn.png" \
2023-11-10 22:50:33 +01:00
--icon-size=32 --no-middle \
--text=$"$ACTIVE activ" \
--menu="Wire-G $OPEN!/sbin/wire_g
|$ACTIVE stop!/sbin/wg_stop" \
2023-11-10 22:50:33 +01:00
--command="menu"
2023-11-11 19:05:06 +01:00
2023-10-28 21:38:26 +02:00
}
export -f wg_notify
# function end
############################################################################################################
############################################################################################################
# funktion wireguard import
import_wg(){
WG_PIC="/home/$USER/.icons/"
WG_WDIR="/home/$USER/.config/wg_nmcli/"
if WG_CONF=$(yad --file --separator=" \n" \
2023-11-02 21:22:08 +01:00
--button="OK" --button=$"Cancel" \
2023-11-09 20:23:46 +01:00
--width=1200 --height=800 --no-klick \
--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 "$WG_CONF" in
2023-11-08 17:05:12 +01:00
*_*.conf) if grep -i 'PEER\|PublicKey' $WG_CONF > /dev/null && grep -i 'Interface\|PrivateKey' $WG_CONF > /dev/null
2023-11-09 17:14:02 +01:00
then
ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [[ -n $ACTIVE ]]
2023-11-08 17:53:22 +01:00
then
wg_stop
nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt
2023-11-14 18:18:43 +01:00
wg_notify
2023-11-09 16:53:37 +01:00
else
2023-11-11 21:02:41 +01:00
pkill yad
nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt
2023-11-14 18:18:43 +01:00
wg_notify
2023-11-14 18:09:15 +01:00
fi
2023-11-08 17:53:22 +01:00
fi ;;
2023-11-14 21:09:08 +01:00
*) yad --image-on-top --image=${WG_PIC}wg-info.png --height=150 --width=240 \
--text-align=center --undecorated --skip-taskbar \
2023-11-15 12:38:16 +01:00
--borders=12 --button="OK" --buttons-layout=center --center \
2023-11-14 21:09:08 +01:00
--text $"<b>Oh, something went wrong. No valid Wireguard file. </b> \n
<b>Here is an example:</b><span color='#0fad0a'><b> my_wireguard.conf</b></span>"
2023-11-08 17:53:22 +01:00
import_wg ;;
2023-11-10 20:48:17 +01:00
esac
fi }
2023-10-28 21:38:26 +02:00
export -f import_wg
# function end
############################################################################################################
############################################################################################################
# funktion wireguard remove
remove(){
2023-11-14 12:44:31 +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-14 20:03:48 +01:00
nmcli connection delete $SELECTION &> ${WG_WDIR}.tmp.txt
if SUCCESS=$(grep -i 'erfolgreich gelöscht\|successfully deleted' ${WG_WDIR}.tmp.txt)
then
2023-11-15 12:38:16 +01:00
yad --window-icon=${WG_PIC}wg-trash.png --undecorated \
2023-11-14 20:03:48 +01:00
--image-on-top --image=${WG_PIC}wg-info.png \
--text=$"Your Tunnel $SELECTION was successfully deleted." \
2023-11-15 12:38:16 +01:00
--text-align=center --button=$"OK" \
2023-11-14 20:03:48 +01:00
--center --buttons-layout=center --borders=8
else
2023-11-15 12:38:16 +01:00
yad --window-icon=${WG_PIC}wg-trash.png --undecorated \
2023-11-14 20:03:48 +01:00
--image-on-top --image=${WG_PIC}wg-info.png \
--text=$"Oh something went wrong.\nPlease delete Tunnel in the network manager." \
2023-11-15 12:38:16 +01:00
--text-align=center --button=$"OK" --height=60 --width=350 \
--buttons-layout=center --borders=8 --fixed
2023-11-14 20:03:48 +01:00
fi
2023-11-14 12:31:52 +01:00
2023-11-14 20:03:48 +01:00
if [ "$SELECTION" = "$ACTIVE" ]
then
pkill yad
fi }
2023-11-10 22:20:33 +01:00
2023-10-28 21:38:26 +02:00
# function end
############################################################################################################
############################################################################################################
#funktion for active TUNNEL a stop
2023-11-07 20:37:53 +01:00
up_or_down(){
WG_PIC="/home/$USER/.icons/"
ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [[ -z $ACTIVE ]]
then
yad --image-on-top --image=${WG_PIC}wg-info.png \
2023-11-15 12:38:16 +01:00
--text=$"There is no active Tunnel that you could stop." \
2023-11-14 21:09:08 +01:00
--text-align=center --no-buttons \
--borders=8 --undecorated \
--timeout 4 --timeout-indicator=bottom --skip-taskbar
else
wg_stop
wire_g
fi }
2023-11-01 10:11:42 +01:00
export -f up_or_down
# funktion end
############################################################################################################
############################################################################################################
# function button "more"
about(){
2023-11-14 21:30:13 +01:00
yad --width=240 \
--borders=8 --buttons-layout=center --text-align=center \
--button=$"OK" --undecorated \
2023-11-14 21:22:29 +01:00
--image-on-top --image=${WG_PIC}wg-vpn-info.png \
--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
<span color='#626ff1'><b>At all Tunnels, the auto start is disabled.</b></span> \n
<span color='#626ff1'><b>Version: $VERSION </b></span> \n
<span color='#626ff1'><b>Use without warranty.</b></span> \n
2023-11-14 21:30:13 +01:00
<a href='https://git.lunix.dedyn.io/punix/Wire-G'>Download Wire-G </a>"
}
2023-11-01 07:57:13 +01:00
# function end
############################################################################################################
############################################################################################################
2023-10-28 21:38:26 +02:00
# funktion wireguard enable select Tunnel
connect(){
if SUCCESS=$(grep -i 'erfolgreich aktiviert\|successfully activated' ${WG_WDIR}.tmp.txt)
2023-10-28 21:38:26 +02:00
then
2023-11-11 21:02:41 +01:00
pkill yad
nmcli con mod $SELECTION connection.autoconnect no
2023-11-14 18:18:43 +01:00
wg_notify
2023-11-14 18:09:15 +01:00
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.
# Farbe für Variable $ACTIVE festgelegt mit fetter Schrift. (bei --text zwischen " ")
2023-10-28 21:38:26 +02:00
SELECTION=$(yad --no-klick --list --center \
2023-11-10 21:05:43 +01:00
--height=300 --width=60 --title="Wire-G" \
--buttons-layout=center \
2023-11-10 22:20:33 +01:00
--button=$"Start:0" --button=$"Stop":"bash -c up_or_down" \
2023-11-10 21:05:43 +01:00
--button=$"Import":"bash -c import_wg" \
2023-11-14 12:31:52 +01:00
--button=$"Remove:4" --separator="" \
2023-11-14 20:03:48 +01:00
--button=$"About:5" \
--window-icon=${WG_PIC}wg-vpn.png \
--borders=8 --image-on-top --image=${WG_PIC}wg-active.png \
--column=$"Selection" $TUNNEL \
--text=$"<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$ACTIVE</b></span>
2023-11-15 17:21:31 +01:00
<b>------------------------------------------------------------------------------------------------</b>
<b>If no Tunnels are listed,</b>
<b>so they have to import their Tunnel beforehand.</b>")
2023-11-14 20:03:48 +01:00
RET=$?
2023-11-14 12:42:40 +01:00
[[ $? -eq 1 ]] && exit 0
2023-11-11 21:02:41 +01:00
2023-11-14 20:03:48 +01:00
if [[ $RET -eq 4 ]]
then
remove
fi
if [[ $RET -eq 5 ]]
then
2023-11-14 21:14:09 +01:00
about
2023-11-14 12:42:40 +01:00
fi
2023-11-14 20:03:48 +01:00
if [[ $RET -eq 0 ]]
2023-11-14 12:42:40 +01:00
then
if [[ -n $ACTIVE ]]
then
wg_stop
nmcli connection up $SELECTION &> ${WG_WDIR}.tmp.txt
2023-11-14 18:14:36 +01:00
connect
else
nmcli connection up $SELECTION &> ${WG_WDIR}.tmp.txt
connect
fi
2023-11-14 12:31:52 +01:00
fi
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