From 9dd67114f8cc2540ebe9555916b9e6315bcf2aa7 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Wed, 21 Oct 2020 22:35:29 +0100 Subject: [PATCH 01/11] disable and enable wireguard clients --- auto_install/install.sh | 4 +- scripts/wireguard/bash-completion | 4 +- scripts/wireguard/disableCONF.sh | 120 ++++++++++++++++++++++++++++++ scripts/wireguard/enableCONF.sh | 116 +++++++++++++++++++++++++++++ scripts/wireguard/listCONF.sh | 7 +- scripts/wireguard/pivpn.sh | 36 ++++++--- 6 files changed, 272 insertions(+), 15 deletions(-) create mode 100755 scripts/wireguard/disableCONF.sh create mode 100755 scripts/wireguard/enableCONF.sh diff --git a/auto_install/install.sh b/auto_install/install.sh index e37ef3e..4472cf0 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -13,8 +13,8 @@ # timestamp 2020/5/24 15:53BST ######## VARIABLES ######### -pivpnGitUrl="https://github.com/pivpn/pivpn.git" -#pivpnGitUrl="/home/pi/repos/pivpn" +#pivpnGitUrl="https://github.com/pivpn/pivpn.git" +pivpnGitUrl="/home/pi/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf" diff --git a/scripts/wireguard/bash-completion b/scripts/wireguard/bash-completion index a971696..3af6c28 100644 --- a/scripts/wireguard/bash-completion +++ b/scripts/wireguard/bash-completion @@ -4,8 +4,8 @@ _pivpn() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -qr -r -h -u -up -bk" - opts="add clients debug list qrcode remove help uninstall update backup" + dashopts="-a -c -d -l -qr -r -h -u -up -bk -dis -ena" + opts="add clients debug list qrcode remove help uninstall update backup disable enable" if [ "${#COMP_WORDS[@]}" -eq 2 ] then if [[ ${cur} == -* ]] ; then diff --git a/scripts/wireguard/disableCONF.sh b/scripts/wireguard/disableCONF.sh new file mode 100755 index 0000000..e8a8b5b --- /dev/null +++ b/scripts/wireguard/disableCONF.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +setupVars="/etc/pivpn/wireguard/setupVars.conf" + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +helpFunc(){ + echo "::: Disable client conf profiles" + echo ":::" + echo "::: Usage: pivpn <-dis|disable> [-h|--help] [-v] [ ... [] ...] " + echo ":::" + echo "::: Commands:" + echo "::: [none] Interactive mode" + echo "::: Client" + echo "::: -y,--yes Disable client(s) without confirmation" + echo "::: -v Show disabled clients only" + echo "::: -h,--help Show this help dialog" +} + +# Parse input arguments +while test $# -gt 0 +do + _key="$1" + case "$_key" in + -h|--help) + helpFunc + exit 0 + ;; + -y|--yes) + CONFIRM=true + ;; + -v) + DISPLAY_DISABLED=true + ;; + *) + CLIENTS_TO_CHANGE+=("$1") + ;; + esac + shift +done + +cd /etc/wireguard +if [ ! -s configs/clients.txt ]; then + echo "::: There are no clients to remove" + exit 1 +fi + + +if [ "$DISPLAY_DISABLED" ]; then + grep 'disabled### begin client' wg0.conf | sed 's/#//g; s/begin//' + exit 1 +fi + + +LIST=($(awk '{print $1}' configs/clients.txt)) +if [ "${#CLIENTS_TO_CHANGE[@]}" -eq 0 ]; then + echo -e "::\e[4m Client list \e[0m::" + len=${#LIST[@]} + COUNTER=1 + while [ $COUNTER -le ${len} ]; do + printf "%0${#len}s) %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} + ((COUNTER++)) + done + + read -r -p "Please enter the Index/Name of the Client to be removed from the list above: " CLIENTS_TO_CHANGE + + if [ -z "${CLIENTS_TO_CHANGE}" ]; then + echo "::: You can not leave this blank!" + exit 1 + fi +fi + +CHANGED_COUNT=0 + +for CLIENT_NAME in "${CLIENTS_TO_CHANGE[@]}"; do + + re='^[0-9]+$' + if [[ ${CLIENT_NAME} =~ $re ]] ; then + CLIENT_NAME=${LIST[$(($CLIENT_NAME -1))]} + fi + + if ! grep -q "^${CLIENT_NAME} " configs/clients.txt; then + echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" + elif grep -q "#disabled### begin ${CLIENT_NAME}" wg0.conf; then + echo -e "::: \e[1m${CLIENT_NAME}\e[0m is already disabled" + else + if [ -n "$CONFIRM" ]; then + REPLY="y" + else + read -r -p "Confirm you want to disable $CLIENT_NAME? [Y/n] " + fi + + if [[ $REPLY =~ ^[Yy]$ ]]; then + + # Disable the peer section from the server config + echo "${CLIENT_NAME}" + sed -e "/### begin ${CLIENT_NAME}/,/end ${CLIENT_NAME}/ s/^/#disabled/" -i wg0.conf + echo "::: Updated server config" + + ((CHANGED_COUNT++)) + echo "::: Successfully disabled ${CLIENT_NAME}" + + fi + fi + +done + +# Restart WireGuard only if some clients were actually deleted +if [ "${CHANGED_COUNT}" -gt 0 ]; then + if systemctl reload wg-quick@wg0; then + echo "::: WireGuard reloaded" + else + echo "::: Failed to reload WireGuard" + fi +fi diff --git a/scripts/wireguard/enableCONF.sh b/scripts/wireguard/enableCONF.sh new file mode 100755 index 0000000..0f20069 --- /dev/null +++ b/scripts/wireguard/enableCONF.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +setupVars="/etc/pivpn/wireguard/setupVars.conf" + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +helpFunc(){ + echo "::: Enables client conf profiles" + echo ":::" + echo "::: Usage: pivpn <-ena|enable> [-h|--help] [-v] [ ... [] ...] " + echo ":::" + echo "::: Commands:" + echo "::: [none] Interactive mode" + echo "::: Client" + echo "::: -y,--yes Remove client(s) without confirmation" + echo "::: -v Show disabled clients only" + echo "::: -h,--help Show this help dialog" +} + +# Parse input arguments +while test $# -gt 0 +do + _key="$1" + case "$_key" in + -h|--help) + helpFunc + exit 0 + ;; + -y|--yes) + CONFIRM=true + ;; + -v) + DISPLAY_DISABLED=true + ;; + *) + CLIENTS_TO_CHANGE+=("$1") + ;; + esac + shift +done + +cd /etc/wireguard +if [ ! -s configs/clients.txt ]; then + echo "::: There are no clients to change" + exit 1 +fi + +if [ "$DISPLAY_DISABLED" ]; then + grep 'disabled### begin client' wg0.conf | sed 's/#//g; s/begin//' + exit 1 +fi + +LIST=($(awk '{print $1}' configs/clients.txt)) +if [ "${#CLIENTS_TO_CHANGE[@]}" -eq 0 ]; then + echo -e "::\e[4m Client list \e[0m::" + len=${#LIST[@]} + COUNTER=1 + while [ $COUNTER -le ${len} ]; do + printf "%0${#len}s) %s\r\n" ${COUNTER} ${LIST[(($COUNTER-1))]} + ((COUNTER++)) + done + + read -r -p "Please enter the Index/Name of the Client to be enabled from the list above: " CLIENTS_TO_CHANGE + + if [ -z "${CLIENTS_TO_CHANGE}" ]; then + echo "::: You can not leave this blank!" + exit 1 + fi +fi + +CHANGED_COUNT=0 + +for CLIENT_NAME in "${CLIENTS_TO_CHANGE[@]}"; do + + re='^[0-9]+$' + if [[ ${CLIENT_NAME} =~ $re ]] ; then + CLIENT_NAME=${LIST[$(($CLIENT_NAME -1))]} + fi + + if ! grep -q "^${CLIENT_NAME} " configs/clients.txt; then + echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" + else + if [ -n "$CONFIRM" ]; then + REPLY="y" + else + read -r -p "Confirm you want to enable $CLIENT_NAME? [Y/n] " + fi + + if [[ $REPLY =~ ^[Yy]$ ]]; then + + # Enable the peer section from the server config + echo "${CLIENT_NAME}" + sed -e "/begin ${CLIENT_NAME}/,/end ${CLIENT_NAME}/ s/#disabled//" -i wg0.conf + echo "::: Updated server config" + + ((CHANGED_COUNT++)) + echo "::: Successfully enabled ${CLIENT_NAME}" + + fi + fi + +done + +# Restart WireGuard only if some clients were actually deleted +if [ "${CHANGED_COUNT}" -gt 0 ]; then + if systemctl reload wg-quick@wg0; then + echo "::: WireGuard reloaded" + else + echo "::: Failed to reload WireGuard" + fi +fi diff --git a/scripts/wireguard/listCONF.sh b/scripts/wireguard/listCONF.sh index 6f8e198..d4ab8dd 100755 --- a/scripts/wireguard/listCONF.sh +++ b/scripts/wireguard/listCONF.sh @@ -25,4 +25,9 @@ while read -r LINE; do echo -e "$CLIENT_NAME \t $PUBLIC_KEY \t $CD_FORMAT" done < clients.txt -} | column -t -s $'\t' \ No newline at end of file +} | column -t -s $'\t' + + +cd /etc/wireguard || return +echo "::: Disabled clients :::" +grep 'disabled### begin client' wg0.conf | sed 's/#//g; s/begin//' diff --git a/scripts/wireguard/pivpn.sh b/scripts/wireguard/pivpn.sh index 61db6d9..963a8aa 100755 --- a/scripts/wireguard/pivpn.sh +++ b/scripts/wireguard/pivpn.sh @@ -47,6 +47,18 @@ removeClient(){ exit 0 } +disableClient(){ + shift + $SUDO ${scriptdir}/${vpn}/disableCONF.sh "$@" + exit 0 +} + +enableClient(){ + shift + $SUDO ${scriptdir}/${vpn}/enableCONF.sh "$@" + exit 0 +} + uninstallServer(){ $SUDO ${scriptdir}/uninstall.sh "${vpn}" exit 0 @@ -75,6 +87,8 @@ showHelp(){ echo "::: -l, list List all clients" echo "::: -qr, qrcode Show the qrcode of a client for use with the mobile app" echo "::: -r, remove Remove a client" + echo "::: -dis, disable Disable a user" + echo "::: -ena, enable Enable a user" echo "::: -h, help Show this help dialog" echo "::: -u, uninstall Uninstall pivpn from your system!" echo "::: -up, update Updates PiVPN Scripts" @@ -88,15 +102,17 @@ fi # Handle redirecting to specific functions based on arguments case "$1" in -"-a" | "add" ) makeConf "$@";; -"-c" | "clients" ) listConnected "$@";; -"-d" | "debug" ) debug;; -"-l" | "list" ) listClients;; -"-qr" | "qrcode" ) showQrcode "$@";; -"-r" | "remove" ) removeClient "$@";; -"-h" | "help" ) showHelp;; -"-u" | "uninstall" ) uninstallServer;; -"-up" | "update" ) updateScripts "$@" ;; -"-bk" | "backup" ) backup ;; +"-a" | "add" ) makeConf "$@";; +"-c" | "clients" ) listConnected "$@";; +"-d" | "debug" ) debug;; +"-l" | "list" ) listClients;; +"-qr" | "qrcode" ) showQrcode "$@";; +"-r" | "remove" ) removeClient "$@";; +"-dis" | "disable" ) disableClient "$@";; +"-ena" | "enable" ) enableClient "$@";; +"-h" | "help" ) showHelp;; +"-u" | "uninstall" ) uninstallServer;; +"-up" | "update" ) updateScripts "$@" ;; +"-bk" | "backup" ) backup ;; * ) showHelp;; esac From a0660979d4cca0a1a5e8731a5fc38b9bac16f1bd Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Wed, 21 Oct 2020 23:23:58 +0100 Subject: [PATCH 02/11] corrent enable help --- scripts/wireguard/enableCONF.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/wireguard/enableCONF.sh b/scripts/wireguard/enableCONF.sh index 0f20069..606adae 100755 --- a/scripts/wireguard/enableCONF.sh +++ b/scripts/wireguard/enableCONF.sh @@ -17,7 +17,7 @@ helpFunc(){ echo "::: Commands:" echo "::: [none] Interactive mode" echo "::: Client" - echo "::: -y,--yes Remove client(s) without confirmation" + echo "::: -y,--yes Enable client(s) without confirmation" echo "::: -v Show disabled clients only" echo "::: -h,--help Show this help dialog" } From 468ea296c06bf529f86f9a1ebbb8795ff66dc722 Mon Sep 17 00:00:00 2001 From: shelleycat485 <63857845+shelleycat485@users.noreply.github.com> Date: Thu, 22 Oct 2020 19:23:33 +0100 Subject: [PATCH 04/11] back to pivpn github repository --- auto_install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 4472cf0..e37ef3e 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -13,8 +13,8 @@ # timestamp 2020/5/24 15:53BST ######## VARIABLES ######### -#pivpnGitUrl="https://github.com/pivpn/pivpn.git" -pivpnGitUrl="/home/pi/repos/pivpn" +pivpnGitUrl="https://github.com/pivpn/pivpn.git" +#pivpnGitUrl="/home/pi/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf" From 13d40399f3f2288444c198684a4ec2533801fe5d Mon Sep 17 00:00:00 2001 From: Roger Haxby <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 27 Oct 2020 21:25:27 +0000 Subject: [PATCH 05/11] fix listing disabled clients --- scripts/wireguard/disableCONF.sh | 2 +- scripts/wireguard/enableCONF.sh | 2 +- scripts/wireguard/listCONF.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/wireguard/disableCONF.sh b/scripts/wireguard/disableCONF.sh index e8a8b5b..16dcfe7 100755 --- a/scripts/wireguard/disableCONF.sh +++ b/scripts/wireguard/disableCONF.sh @@ -52,7 +52,7 @@ fi if [ "$DISPLAY_DISABLED" ]; then - grep 'disabled### begin client' wg0.conf | sed 's/#//g; s/begin//' + grep 'disabled### begin' wg0.conf | sed 's/#//g; s/begin//' exit 1 fi diff --git a/scripts/wireguard/enableCONF.sh b/scripts/wireguard/enableCONF.sh index 606adae..dad65b6 100755 --- a/scripts/wireguard/enableCONF.sh +++ b/scripts/wireguard/enableCONF.sh @@ -51,7 +51,7 @@ if [ ! -s configs/clients.txt ]; then fi if [ "$DISPLAY_DISABLED" ]; then - grep 'disabled### begin client' wg0.conf | sed 's/#//g; s/begin//' + grep 'disabled### begin' wg0.conf | sed 's/#//g; s/begin//' exit 1 fi diff --git a/scripts/wireguard/listCONF.sh b/scripts/wireguard/listCONF.sh index d4ab8dd..a8f5e57 100755 --- a/scripts/wireguard/listCONF.sh +++ b/scripts/wireguard/listCONF.sh @@ -30,4 +30,4 @@ done < clients.txt cd /etc/wireguard || return echo "::: Disabled clients :::" -grep 'disabled### begin client' wg0.conf | sed 's/#//g; s/begin//' +grep 'disabled### begin' wg0.conf | sed 's/#//g; s/begin//' From 49a9314325e9da9e543b6025998e65d48031f4fd Mon Sep 17 00:00:00 2001 From: Roger Haxby <63857845+shelleycat485@users.noreply.github.com> Date: Thu, 26 Nov 2020 15:36:00 +0000 Subject: [PATCH 06/11] change to on/off for temp enable/disable --- auto_install/install.sh | 1 - scripts/wireguard/pivpn.sh | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index ed54931..421daeb 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -10,7 +10,6 @@ # curl -L https://install.pivpn.io | bash # Make sure you have `curl` installed -# timestamp 2020/5/24 15:53BST ######## VARIABLES ######### pivpnGitUrl="https://github.com/pivpn/pivpn.git" diff --git a/scripts/wireguard/pivpn.sh b/scripts/wireguard/pivpn.sh index fba567e..b157431 100755 --- a/scripts/wireguard/pivpn.sh +++ b/scripts/wireguard/pivpn.sh @@ -92,8 +92,8 @@ showHelp(){ echo "::: -l, list List all clients" echo "::: -qr, qrcode Show the qrcode of a client for use with the mobile app" echo "::: -r, remove Remove a client" - echo "::: -dis, disable Disable a user" - echo "::: -ena, enable Enable a user" + echo "::: -off, off Disable a user" + echo "::: -on , on Enable a user" echo "::: -h, help Show this help dialog" echo "::: -u, uninstall Uninstall pivpn from your system!" echo "::: -up, update Updates PiVPN Scripts" @@ -113,11 +113,11 @@ case "$1" in "-l" | "list" ) listClients;; "-qr" | "qrcode" ) showQrcode "$@";; "-r" | "remove" ) removeClient "$@";; -"-dis" | "disable" ) disableClient "$@";; -"-ena" | "enable" ) enableClient "$@";; +"-off" | "off" ) disableClient "$@";; +"-on" | "on" ) enableClient "$@";; "-h" | "help" ) showHelp;; "-u" | "uninstall" ) uninstallServer;; "-up" | "update" ) updateScripts "$@" ;; "-bk" | "backup" ) backup ;; -* ) showHelp;; +* ) showHelp;; esac From 6009e52e746df74c2474fb42e8d29f8eb1c45ec5 Mon Sep 17 00:00:00 2001 From: Roger Haxby <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 8 Dec 2020 23:44:51 +0000 Subject: [PATCH 07/11] disabled in square brackets --- scripts/wireguard/bash-completion | 4 ++-- scripts/wireguard/disableCONF.sh | 8 ++++---- scripts/wireguard/pivpn.sh | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scripts/wireguard/bash-completion b/scripts/wireguard/bash-completion index 3af6c28..ae57b41 100644 --- a/scripts/wireguard/bash-completion +++ b/scripts/wireguard/bash-completion @@ -4,8 +4,8 @@ _pivpn() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -qr -r -h -u -up -bk -dis -ena" - opts="add clients debug list qrcode remove help uninstall update backup disable enable" + dashopts="-a -c -d -l -qr -r -h -u -up -bk -off -on" + opts="add clients debug list qrcode remove help uninstall update backup (temp) off (temp) on" if [ "${#COMP_WORDS[@]}" -eq 2 ] then if [[ ${cur} == -* ]] ; then diff --git a/scripts/wireguard/disableCONF.sh b/scripts/wireguard/disableCONF.sh index 16dcfe7..61ea52e 100755 --- a/scripts/wireguard/disableCONF.sh +++ b/scripts/wireguard/disableCONF.sh @@ -46,13 +46,13 @@ done cd /etc/wireguard if [ ! -s configs/clients.txt ]; then - echo "::: There are no clients to remove" + echo "::: There are no clients to change" exit 1 fi if [ "$DISPLAY_DISABLED" ]; then - grep 'disabled### begin' wg0.conf | sed 's/#//g; s/begin//' + grep '\[disabled\] ### begin' wg0.conf | sed 's/#//g; s/begin//' exit 1 fi @@ -86,7 +86,7 @@ for CLIENT_NAME in "${CLIENTS_TO_CHANGE[@]}"; do if ! grep -q "^${CLIENT_NAME} " configs/clients.txt; then echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" - elif grep -q "#disabled### begin ${CLIENT_NAME}" wg0.conf; then + elif grep -q "#\[disabled\] ### begin ${CLIENT_NAME}" wg0.conf; then echo -e "::: \e[1m${CLIENT_NAME}\e[0m is already disabled" else if [ -n "$CONFIRM" ]; then @@ -99,7 +99,7 @@ for CLIENT_NAME in "${CLIENTS_TO_CHANGE[@]}"; do # Disable the peer section from the server config echo "${CLIENT_NAME}" - sed -e "/### begin ${CLIENT_NAME}/,/end ${CLIENT_NAME}/ s/^/#disabled/" -i wg0.conf + sed -e "/### begin ${CLIENT_NAME}/,/end ${CLIENT_NAME}/ s/^/#\[disabled\] /" -i wg0.conf echo "::: Updated server config" ((CHANGED_COUNT++)) diff --git a/scripts/wireguard/pivpn.sh b/scripts/wireguard/pivpn.sh index b157431..4679e13 100755 --- a/scripts/wireguard/pivpn.sh +++ b/scripts/wireguard/pivpn.sh @@ -86,18 +86,18 @@ showHelp(){ echo "::: Usage: pivpn [option]" echo ":::" echo "::: Commands:" - echo "::: -a, add Create a client conf profile" - echo "::: -c, clients List any connected clients to the server" - echo "::: -d, debug Start a debugging session if having trouble" - echo "::: -l, list List all clients" - echo "::: -qr, qrcode Show the qrcode of a client for use with the mobile app" - echo "::: -r, remove Remove a client" - echo "::: -off, off Disable a user" - echo "::: -on , on Enable a user" - echo "::: -h, help Show this help dialog" - echo "::: -u, uninstall Uninstall pivpn from your system!" - echo "::: -up, update Updates PiVPN Scripts" - echo "::: -bk, backup Backup VPN configs and user profiles" + echo "::: -a, add Create a client conf profile" + echo "::: -c, clients List any connected clients to the server" + echo "::: -d, debug Start a debugging session if having trouble" + echo "::: -l, list List all clients" + echo "::: -qr, qrcode Show the qrcode of a client for use with the mobile app" + echo "::: -r, remove Remove a client" + echo "::: -off, off Disable a user" + echo "::: -on, on Enable a user" + echo "::: -h, help Show this help dialog" + echo "::: -u, uninstall Uninstall pivpn from your system!" + echo "::: -up, update Updates PiVPN Scripts" + echo "::: -bk, backup Backup VPN configs and user profiles" exit 0 } From a3b7af869c7c06083bc875644010ce1e05546630 Mon Sep 17 00:00:00 2001 From: Roger Haxby <63857845+shelleycat485@users.noreply.github.com> Date: Wed, 9 Dec 2020 23:07:28 +0000 Subject: [PATCH 08/11] more disabled in brackets --- auto_install/install.sh | 4 ++-- scripts/wireguard/enableCONF.sh | 4 ++-- scripts/wireguard/listCONF.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 421daeb..2691d48 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -12,8 +12,8 @@ ######## VARIABLES ######### -pivpnGitUrl="https://github.com/pivpn/pivpn.git" -#pivpnGitUrl="/home/pi/repos/pivpn" +#pivpnGitUrl="https://github.com/pivpn/pivpn.git" +pivpnGitUrl="/home/pi/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf" diff --git a/scripts/wireguard/enableCONF.sh b/scripts/wireguard/enableCONF.sh index dad65b6..b45395f 100755 --- a/scripts/wireguard/enableCONF.sh +++ b/scripts/wireguard/enableCONF.sh @@ -51,7 +51,7 @@ if [ ! -s configs/clients.txt ]; then fi if [ "$DISPLAY_DISABLED" ]; then - grep 'disabled### begin' wg0.conf | sed 's/#//g; s/begin//' + grep '\[disabled\] ### begin' wg0.conf | sed 's/#//g; s/begin//' exit 1 fi @@ -95,7 +95,7 @@ for CLIENT_NAME in "${CLIENTS_TO_CHANGE[@]}"; do # Enable the peer section from the server config echo "${CLIENT_NAME}" - sed -e "/begin ${CLIENT_NAME}/,/end ${CLIENT_NAME}/ s/#disabled//" -i wg0.conf + sed -e "/begin ${CLIENT_NAME}/,/end ${CLIENT_NAME}/ s/#\[disabled\] //" -i wg0.conf echo "::: Updated server config" ((CHANGED_COUNT++)) diff --git a/scripts/wireguard/listCONF.sh b/scripts/wireguard/listCONF.sh index a8f5e57..150eb5a 100755 --- a/scripts/wireguard/listCONF.sh +++ b/scripts/wireguard/listCONF.sh @@ -30,4 +30,4 @@ done < clients.txt cd /etc/wireguard || return echo "::: Disabled clients :::" -grep 'disabled### begin' wg0.conf | sed 's/#//g; s/begin//' +grep '\[disabled\] ### begin' wg0.conf | sed 's/#//g; s/begin//' From 8bff0b6cb669c3c510e5b98ad5eead05a47d5d0a Mon Sep 17 00:00:00 2001 From: Roger Haxby <63857845+shelleycat485@users.noreply.github.com> Date: Thu, 10 Dec 2020 12:34:49 +0000 Subject: [PATCH 09/11] clientSTAT shows disabled clients at end --- scripts/wireguard/clientSTAT.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/wireguard/clientSTAT.sh b/scripts/wireguard/clientSTAT.sh index 166085f..ae07a72 100755 --- a/scripts/wireguard/clientSTAT.sh +++ b/scripts/wireguard/clientSTAT.sh @@ -2,6 +2,7 @@ # PiVPN: client status script CLIENTS_FILE="/etc/wireguard/configs/clients.txt" +CONF_FILE="/etc/wireguard/wg0.conf" if [ ! -s "$CLIENTS_FILE" ]; then echo "::: There are no clients to list" @@ -44,7 +45,6 @@ listClients(){ BYTES_SENT="$(awk '{ print $7 }' <<< "$LINE")" LAST_SEEN="$(awk '{ print $5 }' <<< "$LINE")" CLIENT_NAME="$(grep "$PUBLIC_KEY" "$CLIENTS_FILE" | awk '{ print $1 }')" - if [ "$HR" = 1 ]; then if [ "$LAST_SEEN" -ne 0 ]; then printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "$(date -d @"$LAST_SEEN" '+%b %d %Y - %T')" @@ -63,6 +63,11 @@ listClients(){ printf "\n" } | column -t -s $'\t' + + cd /etc/wireguard || return + echo "::: Disabled clients :::" + grep '\[disabled\] ### begin' wg0.conf | sed 's/#//g; s/begin//' + } if [[ $# -eq 0 ]]; then From 86de3eaa8ce16f1171117cab5b82dfa1d755f637 Mon Sep 17 00:00:00 2001 From: Roger Haxby <63857845+shelleycat485@users.noreply.github.com> Date: Thu, 10 Dec 2020 23:59:54 +0000 Subject: [PATCH 10/11] corect help on disable and enable --- auto_install/install.sh | 4 ++-- scripts/wireguard/disableCONF.sh | 2 +- scripts/wireguard/enableCONF.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 2691d48..421daeb 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -12,8 +12,8 @@ ######## VARIABLES ######### -#pivpnGitUrl="https://github.com/pivpn/pivpn.git" -pivpnGitUrl="/home/pi/repos/pivpn" +pivpnGitUrl="https://github.com/pivpn/pivpn.git" +#pivpnGitUrl="/home/pi/repos/pivpn" setupVarsFile="setupVars.conf" setupConfigDir="/etc/pivpn" tempsetupVarsFile="/tmp/setupVars.conf" diff --git a/scripts/wireguard/disableCONF.sh b/scripts/wireguard/disableCONF.sh index 61ea52e..7d3d682 100755 --- a/scripts/wireguard/disableCONF.sh +++ b/scripts/wireguard/disableCONF.sh @@ -12,7 +12,7 @@ source "${setupVars}" helpFunc(){ echo "::: Disable client conf profiles" echo ":::" - echo "::: Usage: pivpn <-dis|disable> [-h|--help] [-v] [ ... [] ...] " + echo "::: Usage: pivpn <-off|off> [-h|--help] [-v] [ ... [] ...] " echo ":::" echo "::: Commands:" echo "::: [none] Interactive mode" diff --git a/scripts/wireguard/enableCONF.sh b/scripts/wireguard/enableCONF.sh index b45395f..4ce0cf7 100755 --- a/scripts/wireguard/enableCONF.sh +++ b/scripts/wireguard/enableCONF.sh @@ -12,7 +12,7 @@ source "${setupVars}" helpFunc(){ echo "::: Enables client conf profiles" echo ":::" - echo "::: Usage: pivpn <-ena|enable> [-h|--help] [-v] [ ... [] ...] " + echo "::: Usage: pivpn <-on|on> [-h|--help] [-v] [ ... [] ...] " echo ":::" echo "::: Commands:" echo "::: [none] Interactive mode" From ec32851e0c7682bbcd6f5e78710e53f119db0958 Mon Sep 17 00:00:00 2001 From: Roger Haxby <63857845+shelleycat485@users.noreply.github.com> Date: Tue, 15 Dec 2020 14:17:05 +0000 Subject: [PATCH 11/11] fix clientSTAT.sh error if all clients are disabled --- scripts/wireguard/clientSTAT.sh | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/wireguard/clientSTAT.sh b/scripts/wireguard/clientSTAT.sh index ae07a72..0df3664 100755 --- a/scripts/wireguard/clientSTAT.sh +++ b/scripts/wireguard/clientSTAT.sh @@ -37,28 +37,28 @@ listClients(){ printf "\e[4mName\e[0m \t \e[4mRemote IP\e[0m \t \e[4mVirtual IP\e[0m \t \e[4mBytes Received\e[0m \t \e[4mBytes Sent\e[0m \t \e[4mLast Seen\e[0m\n" while IFS= read -r LINE; do - - PUBLIC_KEY="$(awk '{ print $1 }' <<< "$LINE")" - REMOTE_IP="$(awk '{ print $3 }' <<< "$LINE")" - VIRTUAL_IP="$(awk '{ print $4 }' <<< "$LINE")" - BYTES_RECEIVED="$(awk '{ print $6 }' <<< "$LINE")" - BYTES_SENT="$(awk '{ print $7 }' <<< "$LINE")" - LAST_SEEN="$(awk '{ print $5 }' <<< "$LINE")" - CLIENT_NAME="$(grep "$PUBLIC_KEY" "$CLIENTS_FILE" | awk '{ print $1 }')" - if [ "$HR" = 1 ]; then - if [ "$LAST_SEEN" -ne 0 ]; then - printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "$(date -d @"$LAST_SEEN" '+%b %d %Y - %T')" + if [ -n "${LINE}" ]; then + PUBLIC_KEY="$(awk '{ print $1 }' <<< "$LINE")" + REMOTE_IP="$(awk '{ print $3 }' <<< "$LINE")" + VIRTUAL_IP="$(awk '{ print $4 }' <<< "$LINE")" + BYTES_RECEIVED="$(awk '{ print $6 }' <<< "$LINE")" + BYTES_SENT="$(awk '{ print $7 }' <<< "$LINE")" + LAST_SEEN="$(awk '{ print $5 }' <<< "$LINE")" + CLIENT_NAME="$(grep "$PUBLIC_KEY" "$CLIENTS_FILE" | awk '{ print $1 }')" + if [ "$HR" = 1 ]; then + if [ "$LAST_SEEN" -ne 0 ]; then + printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "$(date -d @"$LAST_SEEN" '+%b %d %Y - %T')" + else + printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "(not yet)" + fi else - printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "(not yet)" - fi - else - if [ "$LAST_SEEN" -ne 0 ]; then - printf "%s \t %s \t %s \t %'d \t %'d \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$BYTES_RECEIVED" "$BYTES_SENT" "$(date -d @"$LAST_SEEN" '+%b %d %Y - %T')" - else - printf "%s \t %s \t %s \t %'d \t %'d \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$BYTES_RECEIVED" "$BYTES_SENT" "(not yet)" + if [ "$LAST_SEEN" -ne 0 ]; then + printf "%s \t %s \t %s \t %'d \t %'d \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$BYTES_RECEIVED" "$BYTES_SENT" "$(date -d @"$LAST_SEEN" '+%b %d %Y - %T')" + else + printf "%s \t %s \t %s \t %'d \t %'d \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$BYTES_RECEIVED" "$BYTES_SENT" "(not yet)" + fi fi fi - done <<< "$DUMP" printf "\n"