From c58c5622968f7b8fee4936de00eb65becf7b66cc Mon Sep 17 00:00:00 2001 From: Stephan van Heest Date: Fri, 30 Aug 2019 10:15:48 +0200 Subject: [PATCH 01/18] Update dietpi-nordvpn Changed up to route-up and down to route-pre-down. This will ensure that the scripts will only run after the VPN succesfully connected. --- dietpi/misc/dietpi-nordvpn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index bf0b485def..a366e90804 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -104,8 +104,8 @@ _EOF_ local fp_ovpn="/etc/openvpn/ovpn_$PROTOCOL/$NORDVPN_SERVER" G_CONFIG_INJECT 'auth-user-pass([[:blank:]]|$)' "auth-user-pass $FP_SETTINGS_OVPN" $fp_ovpn [[ -f $FP_SETTINGS_UP || -f $FP_SETTINGS_DOWN ]] && G_CONFIG_INJECT 'script-security[[:blank:]]' 'script-security 2' $fp_ovpn 'auth[[:blank:]]' || sed -i '/^[[:blank:]]*script-security[[:blank:]]/d' $fp_ovpn - [[ -f $FP_SETTINGS_UP ]] && G_CONFIG_INJECT 'up[[:blank:]]' "up $FP_SETTINGS_UP" $fp_ovpn 'auth[[:blank:]]' || sed -i '/^[[:blank:]]*up[[:blank:]]/d' $fp_ovpn - [[ -f $FP_SETTINGS_DOWN ]] && G_CONFIG_INJECT 'down[[:blank:]]' "down $FP_SETTINGS_DOWN" $fp_ovpn 'auth[[:blank:]]' || sed -i '/^[[:blank:]]*down[[:blank:]]/d' $fp_ovpn + [[ -f $FP_SETTINGS_UP ]] && G_CONFIG_INJECT 'route-up[[:blank:]]' "route-up $FP_SETTINGS_UP" $fp_ovpn 'auth[[:blank:]]' || sed -i '/^[[:blank:]]*up[[:blank:]]/d' $fp_ovpn + [[ -f $FP_SETTINGS_DOWN ]] && G_CONFIG_INJECT 'route-pre-down[[:blank:]]' "route-pre-down $FP_SETTINGS_DOWN" $fp_ovpn 'auth[[:blank:]]' || sed -i '/^[[:blank:]]*down[[:blank:]]/d' $fp_ovpn chmod 600 $FP_SETTINGS_OVPN $FP_SETTINGS_DIETPI $fp_ovpn chown root:root $FP_SETTINGS_OVPN $FP_SETTINGS_DIETPI $fp_ovpn From 71e0d1dd16b88958b5b4b1fadcf8977d987f04a4 Mon Sep 17 00:00:00 2001 From: Stephan van Heest Date: Fri, 30 Aug 2019 10:47:12 +0200 Subject: [PATCH 02/18] Update dietpi-banner First commit. Add DietPi-NordVPN status to banner. --- dietpi/func/dietpi-banner | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index c557151494..6eaa448595 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -35,6 +35,7 @@ 'NIS domainname' 'LAN IP' 'WAN IP' + 'NordVPN status' 'Freespace (RootFS)' 'Freespace (userdata)' 'Weather (wttr.in)' @@ -44,7 +45,7 @@ ) # Set defaults - aENABLED=(1 0 1 0 0 1 0 0 0 0 0 1 1) + aENABLED=(1 0 1 0 0 1 0 0 0 0 0 0 1 1) COLOUR_RESET='\e[0m' aCOLOUR=( From 1b2522ae9cae11656980fb8f070b9882452d89d7 Mon Sep 17 00:00:00 2001 From: Stephan van Heest Date: Fri, 30 Aug 2019 11:04:50 +0200 Subject: [PATCH 03/18] Update dietpi-banner Placeholder added in DietPi-Banner for NordVPN --- dietpi/func/dietpi-banner | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index 6eaa448595..50bcbade13 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -198,10 +198,11 @@ $GREEN_LINE" (( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)" # 4: Domain name Print_Local_Ip (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1)" # 6: WAN IP # Move this to /DietPi/dietpi/.network? - (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 7: Freespace (RootFS) - (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (DietPi userdata) - (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 9: Weather - (( ${aENABLED[10]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 10: Custom + (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(echo "NordVPN Status Here")" # 7: DietPi-NordVPN status + (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (RootFS) + (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 9: Freespace (DietPi userdata) + (( ${aENABLED[10]} == 1 )) && echo -else "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 10: Weather + (( ${aENABLED[11]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[11]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 11: Custom if (( ${aENABLED[12]} == 1 )); then local fp_motd='/tmp/.dietpi_motd' From ac2f4a49d8abb747183999691b86f712f0b53ed7 Mon Sep 17 00:00:00 2001 From: Stephan van Heest Date: Fri, 30 Aug 2019 18:02:13 +0200 Subject: [PATCH 04/18] First work on dietpi-nordvpn Started work on a function in DietPi-NordVPN to get status from commandline. The retun now includes: [ OK ] DietPi-NordVPN | Root access verified. [ OK ] DietPi-NordVPN | RootFS R/W access verified. Need advise to solve this. Also set NORDVPN_SERVICE=1 manually because it does not sets the global var from the Init('status') function properly. Banner item NordVPN calls DietPi-NordVPN to get status. --- dietpi/func/dietpi-banner | 26 ++++++------- dietpi/misc/dietpi-nordvpn | 75 +++++++++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 18 deletions(-) diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index 50bcbade13..8cba5be859 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -191,18 +191,18 @@ $GREEN_LINE" printf '\ec' # clear current terminal screen Print_Header - (( ${aENABLED[0]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $(mawk 'NR==2 {print}' /DietPi/dietpi/.hw_model 2>&1)" # 0: Device model - (( ${aENABLED[1]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[1]} $GREEN_SEPARATOR $(uptime -p 2>&1)" # 1: Uptime - (( ${aENABLED[2]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[2]} $GREEN_SEPARATOR $(print_full_info=1 G_OBTAIN_CPU_TEMP 2>&1)" # 2: CPU temp - (( ${aENABLED[3]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[3]} $GREEN_SEPARATOR $(hostname -f 2>&1)" # 3: Hostname - (( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)" # 4: Domain name - Print_Local_Ip - (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1)" # 6: WAN IP # Move this to /DietPi/dietpi/.network? - (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(echo "NordVPN Status Here")" # 7: DietPi-NordVPN status - (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (RootFS) + (( ${aENABLED[0]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $(mawk 'NR==2 {print}' /DietPi/dietpi/.hw_model 2>&1)" # 0: Device model + (( ${aENABLED[1]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[1]} $GREEN_SEPARATOR $(uptime -p 2>&1)" # 1: Uptime + (( ${aENABLED[2]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[2]} $GREEN_SEPARATOR $(print_full_info=1 G_OBTAIN_CPU_TEMP 2>&1)" # 2: CPU temp + (( ${aENABLED[3]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[3]} $GREEN_SEPARATOR $(hostname -f 2>&1)" # 3: Hostname + (( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)" # 4: Domain name + Print_Local_Ip # 5: LAN IP + (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1)" # 6: WAN IP # Move this to /DietPi/dietpi/.network? + (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(bash /DietPi/dietpi/misc/dietpi-nordvpn status 2>&1)" # 7: DietPi-NordVPN Connection status + (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (RootFS) (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 9: Freespace (DietPi userdata) - (( ${aENABLED[10]} == 1 )) && echo -else "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 10: Weather - (( ${aENABLED[11]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[11]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 11: Custom + (( ${aENABLED[10]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 10: Weather + (( ${aENABLED[11]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[11]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 11: Custom if (( ${aENABLED[12]} == 1 )); then local fp_motd='/tmp/.dietpi_motd' @@ -211,7 +211,7 @@ $GREEN_LINE" if . $fp_motd &> /dev/null && [[ $motd ]]; then - echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[12]} $GREEN_SEPARATOR $motd" # 12: MOTD + echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[12]} $GREEN_SEPARATOR $motd" # 12: MOTD else @@ -260,7 +260,7 @@ $GREEN_LINE" aENABLED[$i]=1 # Custom entry - if (( $i == 10 )); then + if (( $i == 11 )); then [[ -f $FP_CUSTOM ]] && G_WHIP_DEFAULT_ITEM=$(<$FP_CUSTOM) || G_WHIP_DEFAULT_ITEM="echo 'Hello World!'" if G_WHIP_INPUTBOX 'You have chosen to show a custom entry in the banner. diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index a366e90804..cdc7819dc6 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -13,8 +13,12 @@ # - Automatically starts service during boot # Usage: # - /DietPi/dietpi/misc/dietpi-nordvpn + # - /DietPi/dietpi/misc/dietpi-nordvpn status #//////////////////////////////////// + # Grab Inputs + INPUT_CMD=$1 + # Import DietPi-Globals -------------------------------------------------------------- . /DietPi/dietpi/func/dietpi-globals G_PROGRAM_NAME='DietPi-NordVPN' @@ -41,6 +45,22 @@ Update_Wan_Ip(){ WAN_IP=$(curl -sLm 2 https://dietpi.com/myip.php 2>&1); } Init(){ + if [[ $1 == 'status' ]]; then + + # Check installed + until grep -q 'aSOFTWARE_INSTALL_STATE\[171\]=2' /DietPi/dietpi/.installed + do + + echo "$G_PROGRAM_NAME is not installed!" + break + + done + + # Check service exists + [[ -f '/lib/systemd/system/dietpi-nordvpn.service' ]] && NORDVPN_SERVICE=1 + + return + fi # Check installed until grep -q 'aSOFTWARE_INSTALL_STATE\[171\]=2' /DietPi/dietpi/.installed @@ -297,14 +317,59 @@ _EOF_ # Main Loop #///////////////////////////////////////////////////////////////////////////////////// #----------------------------------------------------------------------------------- - Init + #----------------------------------------------------------------------------------- - while (( $TARGETMENUID >= 0 )) - do + if [[ $INPUT_CMD || $INPUT_CMD == 'status' ]]; then + + initStatus=$(Init 'status') + if [[ $initStatus ]]; then + + # Not installed + G_DIETPI-NOTIFY 1 "$initStatus"; exit 1; + + else + # Installed; get status + NORDVPN_SERVICE=1 + if (( $NORDVPN_SERVICE )) && Check_Connected; then + + text_status="Connected" + + net_rx_byte=0 + net_tx_byte=0 + net_rx_mb='N/A' + net_tx_mb='N/A' + + if [[ -f /sys/class/net/$NET_DEV/statistics/rx_bytes && -f /sys/class/net/$NET_DEV/statistics/tx_bytes ]]; then + + net_rx_byte=$(= 0 )) + do + + Menu_Main + + done + fi #----------------------------------------------------------------------------------- exit #----------------------------------------------------------------------------------- From a9a6f771ef3e8f3dac4f935c3ea207930447d62f Mon Sep 17 00:00:00 2001 From: Stephan van Heest Date: Sun, 1 Sep 2019 12:10:38 +0200 Subject: [PATCH 05/18] Update dietpi-banner Update to maintain compatibility. --- dietpi/func/dietpi-banner | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index 8cba5be859..d36ecf62af 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -35,17 +35,17 @@ 'NIS domainname' 'LAN IP' 'WAN IP' - 'NordVPN status' 'Freespace (RootFS)' 'Freespace (userdata)' 'Weather (wttr.in)' 'Custom banner entry' 'Display DietPi useful commands?' 'MOTD' - + 'NordVPN status' + ) # Set defaults - aENABLED=(1 0 1 0 0 1 0 0 0 0 0 0 1 1) + aENABLED=(1 0 1 0 0 1 0 0 0 0 0 1 1 0) COLOUR_RESET='\e[0m' aCOLOUR=( @@ -198,11 +198,11 @@ $GREEN_LINE" (( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)" # 4: Domain name Print_Local_Ip # 5: LAN IP (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1)" # 6: WAN IP # Move this to /DietPi/dietpi/.network? - (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(bash /DietPi/dietpi/misc/dietpi-nordvpn status 2>&1)" # 7: DietPi-NordVPN Connection status - (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (RootFS) - (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 9: Freespace (DietPi userdata) - (( ${aENABLED[10]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 10: Weather - (( ${aENABLED[11]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[11]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 11: Custom + (( ${aENABLED[13]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[13]} $GREEN_SEPARATOR $(bash /DietPi/dietpi/misc/dietpi-nordvpn status 2>&1)" # 7: DietPi-NordVPN Connection status + (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (RootFS) + (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 9: Freespace (DietPi userdata) + (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 10: Weather + (( ${aENABLED[10]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 11: Custom if (( ${aENABLED[12]} == 1 )); then local fp_motd='/tmp/.dietpi_motd' @@ -260,7 +260,7 @@ $GREEN_LINE" aENABLED[$i]=1 # Custom entry - if (( $i == 11 )); then + if (( $i == 10 )); then [[ -f $FP_CUSTOM ]] && G_WHIP_DEFAULT_ITEM=$(<$FP_CUSTOM) || G_WHIP_DEFAULT_ITEM="echo 'Hello World!'" if G_WHIP_INPUTBOX 'You have chosen to show a custom entry in the banner. From 022877534d843ec086e4d7e9bd6957eac51f684d Mon Sep 17 00:00:00 2001 From: Stephan van Heest Date: Sun, 1 Sep 2019 13:07:03 +0200 Subject: [PATCH 06/18] Update dietpi-nordvpn Added service usage info that gets returned when wrong command has been passed as input. --- dietpi/misc/dietpi-nordvpn | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index cdc7819dc6..182cbdcbbd 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -15,6 +15,12 @@ # - /DietPi/dietpi/misc/dietpi-nordvpn # - /DietPi/dietpi/misc/dietpi-nordvpn status #//////////////////////////////////// + USAGE=' +Usage: dietpi-norddvpn [] +Available commands: + Interactive menu to apply service modes and settings + status Print connection status info +' #//////////////////////////////////// # Grab Inputs INPUT_CMD=$1 @@ -319,7 +325,7 @@ _EOF_ #----------------------------------------------------------------------------------- #----------------------------------------------------------------------------------- - if [[ $INPUT_CMD || $INPUT_CMD == 'status' ]]; then + if [[ $INPUT_CMD == 'status' ]]; then initStatus=$(Init 'status') if [[ $initStatus ]]; then @@ -359,6 +365,12 @@ _EOF_ echo "$text_status" fi + elif [[ $INPUT_CMD ]]; then + + # Unknown input + G_DIETPI-NOTIFY 1 "Invalid input command ($command). Aborting...\n$USAGE" + exit 1 + else Init From 2b3bcf02dd67b190418f12b9e3468bf5121bfd3a Mon Sep 17 00:00:00 2001 From: Stephan van Heest Date: Sun, 1 Sep 2019 13:08:59 +0200 Subject: [PATCH 07/18] Update dietpi-nordvpn Typo in usage info --- dietpi/misc/dietpi-nordvpn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index 182cbdcbbd..51409fe6a3 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -18,8 +18,8 @@ USAGE=' Usage: dietpi-norddvpn [] Available commands: - Interactive menu to apply service modes and settings - status Print connection status info + Interactive menu to edit, connect and apply NordVPN settings + status Print NordVPN connection status info ' #//////////////////////////////////// # Grab Inputs From cb6f82955020e04db94d1d2b6f37a9c2415576a7 Mon Sep 17 00:00:00 2001 From: svh1985 Date: Mon, 2 Sep 2019 21:45:28 +0200 Subject: [PATCH 08/18] Update dietpi-nordvpn Changed some status text and added colors to the status. --- dietpi/misc/dietpi-nordvpn | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index 51409fe6a3..c26d9f6fa2 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -22,6 +22,8 @@ Available commands: status Print NordVPN connection status info ' #//////////////////////////////////// + COLOUR_RESET='\e[0m' + # Grab Inputs INPUT_CMD=$1 @@ -338,7 +340,7 @@ _EOF_ NORDVPN_SERVICE=1 if (( $NORDVPN_SERVICE )) && Check_Connected; then - text_status="Connected" + text_status="\e[1;32mConnected$COLOUR_RESET" net_rx_byte=0 net_tx_byte=0 @@ -359,10 +361,10 @@ _EOF_ else - (( $NORDVPN_SERVICE )) && text_status+=' - Disconnected' || text_status+=' - Not configured' + (( $NORDVPN_SERVICE )) && text_status+="\e[1;31mDisconnected$COLOUR_RESET" || text_status+="Not configured" fi - echo "$text_status" + echo -e "$text_status" fi elif [[ $INPUT_CMD ]]; then From 6725b3f7a6f7efc3d72aeb809fd3148772439819 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 19:02:08 +0200 Subject: [PATCH 09/18] v6.26 + DietPi-NordVPN | Minor alignment + DietPi-NordVPN | DietPi scripts don't need to be executed with bash command, since they all contain a bash shebang. --- dietpi/func/dietpi-banner | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index d36ecf62af..1fcee6aa12 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -42,7 +42,7 @@ 'Display DietPi useful commands?' 'MOTD' 'NordVPN status' - + ) # Set defaults aENABLED=(1 0 1 0 0 1 0 0 0 0 0 1 1 0) @@ -185,24 +185,24 @@ $GREEN_LINE" Print_Banner(){ - # - Source DietPi-Globals if not yet sourced from main menu and CPU temp chosen + # Source DietPi-Globals if not yet sourced from main menu and CPU temp chosen [[ ${aENABLED[2]} != 1 && ${aENABLED[12]} != 1 || $G_PROGRAM_NAME ]] || . /DietPi/dietpi/func/dietpi-globals printf '\ec' # clear current terminal screen Print_Header - (( ${aENABLED[0]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $(mawk 'NR==2 {print}' /DietPi/dietpi/.hw_model 2>&1)" # 0: Device model - (( ${aENABLED[1]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[1]} $GREEN_SEPARATOR $(uptime -p 2>&1)" # 1: Uptime - (( ${aENABLED[2]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[2]} $GREEN_SEPARATOR $(print_full_info=1 G_OBTAIN_CPU_TEMP 2>&1)" # 2: CPU temp - (( ${aENABLED[3]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[3]} $GREEN_SEPARATOR $(hostname -f 2>&1)" # 3: Hostname - (( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)" # 4: Domain name - Print_Local_Ip # 5: LAN IP - (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1)" # 6: WAN IP # Move this to /DietPi/dietpi/.network? - (( ${aENABLED[13]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[13]} $GREEN_SEPARATOR $(bash /DietPi/dietpi/misc/dietpi-nordvpn status 2>&1)" # 7: DietPi-NordVPN Connection status - (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (RootFS) - (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 9: Freespace (DietPi userdata) - (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 10: Weather - (( ${aENABLED[10]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 11: Custom + (( ${aENABLED[0]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[0]} $GREEN_SEPARATOR $(mawk 'NR==2 {print}' /DietPi/dietpi/.hw_model 2>&1)" # 0: Device model + (( ${aENABLED[1]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[1]} $GREEN_SEPARATOR $(uptime -p 2>&1)" # 1: Uptime + (( ${aENABLED[2]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[2]} $GREEN_SEPARATOR $(print_full_info=1 G_OBTAIN_CPU_TEMP 2>&1)" # 2: CPU temp + (( ${aENABLED[3]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[3]} $GREEN_SEPARATOR $(hostname -f 2>&1)" # 3: Hostname + (( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)" # 4: Domain name + Print_Local_Ip # 5: LAN IP + (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1)" # 6: WAN IP # Move this to /DietPi/dietpi/.network? + (( ${aENABLED[13]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[13]} $GREEN_SEPARATOR $(/DietPi/dietpi/misc/dietpi-nordvpn status 2>&1)" # 13: DietPi-NordVPN connection status + (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 6: Freespace (RootFS) + (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (DietPi userdata) + (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 9: Weather + (( ${aENABLED[10]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 10: Custom if (( ${aENABLED[12]} == 1 )); then local fp_motd='/tmp/.dietpi_motd' @@ -211,7 +211,7 @@ $GREEN_LINE" if . $fp_motd &> /dev/null && [[ $motd ]]; then - echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[12]} $GREEN_SEPARATOR $motd" # 12: MOTD + echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[12]} $GREEN_SEPARATOR $motd" # 12: MOTD else @@ -225,7 +225,7 @@ $GREEN_LINE" echo -e "$GREEN_LINE\n" Print_Credits - (( ${aENABLED[11]} == 1 )) && Print_Useful_Commands + (( ${aENABLED[11]} == 1 )) && Print_Useful_Commands # 11: Useful commands } From 5d4fac3758818ea149724c640d5fd4895f4176a0 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 19:03:43 +0200 Subject: [PATCH 10/18] v6.26 + DietPi-Banner | Fix output entry indices --- dietpi/func/dietpi-banner | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index 1fcee6aa12..d5ee64e89b 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -199,7 +199,7 @@ $GREEN_LINE" Print_Local_Ip # 5: LAN IP (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1)" # 6: WAN IP # Move this to /DietPi/dietpi/.network? (( ${aENABLED[13]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[13]} $GREEN_SEPARATOR $(/DietPi/dietpi/misc/dietpi-nordvpn status 2>&1)" # 13: DietPi-NordVPN connection status - (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 6: Freespace (RootFS) + (( ${aENABLED[7]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[7]} $GREEN_SEPARATOR $(df -h --output=avail / | mawk 'NR==2 {print $1}' 2>&1)" # 7: Freespace (RootFS) (( ${aENABLED[8]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[8]} $GREEN_SEPARATOR $(df -h --output=avail /mnt/dietpi_userdata | mawk 'NR==2 {print $1}' 2>&1)" # 8: Freespace (DietPi userdata) (( ${aENABLED[9]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[9]} $GREEN_SEPARATOR $(curl -sSfLm 2 https://wttr.in/?format=4 2>&1)" # 9: Weather (( ${aENABLED[10]} == 1 )) && [[ -x $FP_CUSTOM ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[10]} $GREEN_SEPARATOR $(bash $FP_CUSTOM 2>&1)" # 10: Custom From 5642be20f5a0b34efbfe7cc08b84213744b126fb Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 20:56:03 +0200 Subject: [PATCH 11/18] v6.26 + DietPi-NordVPN | Do root user and rootfs R/W check only when menu is to be loaded, otherwise printing status would prompt error messages even that both is not required. This allows to load DietPi-Globals as well just for menu, which speeds up status print. + DietPi-NordVPN | Force non-interactive mode on status print, to skip any whiptail prompt + DietPi-NordVPN | Update WAN IP only on before first menu load, on connect, disconnect and refresh, to speed up all other navigation steps, which do not affect the connection state. This is due the WAN IP check can take up to two seconds, which adds a significant delay. + DietPi-NordVPN | Move RX/TX obtaining into an own function and remove DietPi-Globals dependency from it. This allows to share very most code between menu mode and status print. + DietPi-NordVPN | Further coding and wording enhancements --- dietpi/misc/dietpi-nordvpn | 189 ++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 108 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index c26d9f6fa2..caf062e980 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -10,31 +10,25 @@ # # Info: # - GUI to setup a NordVPN connection - # - Automatically starts service during boot - # Usage: - # - /DietPi/dietpi/misc/dietpi-nordvpn - # - /DietPi/dietpi/misc/dietpi-nordvpn status - #//////////////////////////////////// + # - Allows to automatically connect on boot + # - Allows to add post-up and pre-down scripts USAGE=' -Usage: dietpi-norddvpn [] +Usage: dietpi-nordvpn [] Available commands: Interactive menu to edit, connect and apply NordVPN settings status Print NordVPN connection status info ' #//////////////////////////////////// - COLOUR_RESET='\e[0m' - - # Grab Inputs - INPUT_CMD=$1 - # Import DietPi-Globals -------------------------------------------------------------- - . /DietPi/dietpi/func/dietpi-globals + # - Only loaded for interactive menu G_PROGRAM_NAME='DietPi-NordVPN' - G_CHECK_ROOT_USER - G_CHECK_ROOTFS_RW - G_INIT # Import DietPi-Globals -------------------------------------------------------------- + # Grab Inputs + INPUT=$1 + # - Force non-interactive mode on status print, to skip any whiptail prompt + [[ $INPUT == 'status' ]] && G_INTERACTIVE=0 + FP_SETTINGS_DIETPI='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_dietpi.conf' FP_SETTINGS_OVPN='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_ovpn.conf' FP_SETTINGS_UP='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/up.sh' @@ -45,30 +39,17 @@ Available commands: PROTOCOL='udp' NET_DEV='tun0' + MAX_WAIT_FOR_CONNECTION=5 + NORDVPN_INSTALLED=0 NORDVPN_SERVICE=0 NORDVPN_CONNECTED=0 - MAX_WAIT_FOR_CONNECTION=5 WAN_IP='' + RX='N/A' + TX='N/A' - Update_Wan_Ip(){ WAN_IP=$(curl -sLm 2 https://dietpi.com/myip.php 2>&1); } + Update_Wan_Ip(){ WAN_IP=$(curl -sSfLm 2 https://dietpi.com/myip.php 2>&1); } Init(){ - if [[ $1 == 'status' ]]; then - - # Check installed - until grep -q 'aSOFTWARE_INSTALL_STATE\[171\]=2' /DietPi/dietpi/.installed - do - - echo "$G_PROGRAM_NAME is not installed!" - break - - done - - # Check service exists - [[ -f '/lib/systemd/system/dietpi-nordvpn.service' ]] && NORDVPN_SERVICE=1 - - return - fi # Check installed until grep -q 'aSOFTWARE_INSTALL_STATE\[171\]=2' /DietPi/dietpi/.installed @@ -80,35 +61,51 @@ Available commands: else - TARGETMENUID=-1 #Exit path without save. - break + TARGETMENUID=-1 # Skip menu + return fi done + NORDVPN_INSTALLED=1 # Check service exists [[ -f '/lib/systemd/system/dietpi-nordvpn.service' ]] && NORDVPN_SERVICE=1 - Read_Settings - } Check_Connected(){ - NORDVPN_CONNECTED=0 #systemctl status dietpi-nordvpn | grep -qi 'initialization sequence completed' - ip r s dev $NET_DEV &>/dev/null && NORDVPN_CONNECTED=1 - + ip r s dev $NET_DEV &> /dev/null && NORDVPN_CONNECTED=1 || NORDVPN_CONNECTED=0 return $(( ! $NORDVPN_CONNECTED )) } + Get_Connection_Info(){ + + RX='N/A' + if [[ -f /sys/class/net/$NET_DEV/statistics/rx_bytes ]]; then + + local rx=$( /lib/systemd/system/dietpi-nordvpn.service [Unit] Description=NordVPN (DietPi) @@ -157,13 +154,12 @@ _EOF_ do Check_Connected && break - - G_DIETPI-NOTIFY 2 "Waiting for connection ($i/$MAX_WAIT_FOR_CONNECTION)" + G_DIETPI-NOTIFY -2 "Waiting for connection ($i/$MAX_WAIT_FOR_CONNECTION)" sleep 1 done - (( $NORDVPN_CONNECTED )) || G_WHIP_MSG "Connection failed/time out: $NORDVPN_SERVER\n\nPlease verify account details are correct.\n\nIf problems persist, please check the status of 'systemctl status dietpi-nordvpn -l'" + (( $NORDVPN_CONNECTED )) || G_WHIP_MSG "Connection failed/timeout: $NORDVPN_SERVER\n\nPlease verify account details are correct.\n\nIf problems persist, please check the status of \"systemctl -l status dietpi-nordvpn\"" } @@ -183,34 +179,19 @@ _EOF_ # TARGETMENUID=0 Menu_Main(){ - Update_Wan_Ip - local text_status="Status:\n - WAN IP: $WAN_IP\n" - if (( $NORDVPN_SERVICE )) && Check_Connected; then - - text_status+=" - Connected : $NORDVPN_SERVER\n" - - local net_rx_byte=0 - local net_tx_byte=0 - local net_rx_mb='N/A' - local net_tx_mb='N/A' + if (( ! $NORDVPN_SERVICE )); then - if [[ -f /sys/class/net/$NET_DEV/statistics/rx_bytes && -f /sys/class/net/$NET_DEV/statistics/tx_bytes ]]; then + text_status+=' - Not configured\n - NordVPN subscription: https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' - net_rx_byte=$(= 0 )) do @@ -383,6 +355,7 @@ _EOF_ Menu_Main done + fi #----------------------------------------------------------------------------------- exit From 7cc29c6f530cb9b2c498e66f54ce98679ef50f9f Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 21:10:56 +0200 Subject: [PATCH 12/18] v6.26 + DietPi-NordVPN | Print connection test result to console as well, to stops prior process animation --- dietpi/misc/dietpi-nordvpn | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index caf062e980..5fbc6eacd6 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -159,7 +159,16 @@ _EOF_ done - (( $NORDVPN_CONNECTED )) || G_WHIP_MSG "Connection failed/timeout: $NORDVPN_SERVER\n\nPlease verify account details are correct.\n\nIf problems persist, please check the status of \"systemctl -l status dietpi-nordvpn\"" + if (( $NORDVPN_CONNECTED )); then + + G_DIETPI-NOTIFY 0 "Connection established: $NORDVPN_SERVER" + + else + + G_DIETPI-NOTIFY 1 "Connection failed/timeout: $NORDVPN_SERVER" + G_WHIP_MSG "Connection failed/timeout: $NORDVPN_SERVER\n\nPlease verify account details are correct.\n\nIf problems persist, please check the status of \"systemctl -l status dietpi-nordvpn\"" + + fi } From 00086fd167d544c03a1548ca9055edc91e6372b9 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 21:15:23 +0200 Subject: [PATCH 13/18] v6.26 + DietPi-NordVPN | Print correct status text if service is not configured --- dietpi/misc/dietpi-nordvpn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index 5fbc6eacd6..a04dd2f147 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -329,7 +329,7 @@ _EOF_ elif (( ! $NORDVPN_SERVICE )); then - echo -e "\e[33m$G_PROGRAM_NAME is not installed! Please run: \"dietpi-nordvpn\"\e[0m" + echo -e "\e[33m$G_PROGRAM_NAME is not configured! Please run: \"dietpi-nordvpn\"\e[0m" elif ! Check_Connected; then From 2a2691f3c33c7ee74b845716a738c5ae303fb928 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 21:28:14 +0200 Subject: [PATCH 14/18] v6.26 + DietPi-NordVPN | Now that globals are only loaded on menu mode, G_INTERACTIVE has no effect and G_WHIP_YESNO from Init() must only be called on menu mode. --- dietpi/misc/dietpi-nordvpn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index a04dd2f147..db35407e6a 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -26,8 +26,6 @@ Available commands: # Grab Inputs INPUT=$1 - # - Force non-interactive mode on status print, to skip any whiptail prompt - [[ $INPUT == 'status' ]] && G_INTERACTIVE=0 FP_SETTINGS_DIETPI='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_dietpi.conf' FP_SETTINGS_OVPN='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_ovpn.conf' @@ -55,7 +53,7 @@ Available commands: until grep -q 'aSOFTWARE_INSTALL_STATE\[171\]=2' /DietPi/dietpi/.installed do - if G_WHIP_YESNO "$G_PROGRAM_NAME is not installed, would you like to install it now?"; then + if [[ ! $INPUT ]] && G_WHIP_YESNO "$G_PROGRAM_NAME is not installed, would you like to install it now?"; then /DietPi/dietpi/dietpi-software install 171 From 6d7ad247ce9c0c8a98b18b2ca12e095325284b9f Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 21:29:41 +0200 Subject: [PATCH 15/18] v6.26 + DietPi-NordVPN | Tiny --- dietpi/misc/dietpi-nordvpn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index db35407e6a..1b1c91c994 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -198,7 +198,7 @@ _EOF_ else Get_Connection_Info - text_status+=" - Usage : Sent = $TX | Received = $RX" + text_status+=" - Usage : Sent = $TX | Received = $RX" fi From 592a1487dd3b15381397926e0cb49a338081e2f8 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 5 Sep 2019 21:55:34 +0200 Subject: [PATCH 16/18] v6.26 + DietPi-NordVPN | Resolve G_WHIP_YESNO being called before globals are loaded --- dietpi/misc/dietpi-nordvpn | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index 1b1c91c994..2e42feb250 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -19,14 +19,26 @@ Available commands: status Print NordVPN connection status info ' #//////////////////////////////////// - # Import DietPi-Globals -------------------------------------------------------------- - # - Only loaded for interactive menu - G_PROGRAM_NAME='DietPi-NordVPN' - # Import DietPi-Globals -------------------------------------------------------------- - # Grab Inputs INPUT=$1 + # Import DietPi-Globals -------------------------------------------------------------- + # - Only load for interactive menu + if [[ $INPUT ]]; then + + G_PROGRAM_NAME='DietPi-NordVPN' + + else + + . /DietPi/dietpi/func/dietpi-globals + G_PROGRAM_NAME='DietPi-NordVPN' + G_CHECK_ROOT_USER + G_CHECK_ROOTFS_RW + G_INIT + + fi + # Import DietPi-Globals -------------------------------------------------------------- + FP_SETTINGS_DIETPI='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_dietpi.conf' FP_SETTINGS_OVPN='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/settings_ovpn.conf' FP_SETTINGS_UP='/var/lib/dietpi/dietpi-software/installed/dietpi-nordvpn/up.sh' @@ -275,7 +287,7 @@ _EOF_ elif [[ $G_WHIP_RETURNED_VALUE == 'Server' ]]; then - # - Select protocol + # Select protocol G_WHIP_MENU_ARRAY=( 'UDP' ': Recommended' @@ -286,7 +298,7 @@ _EOF_ G_WHIP_DEFAULT_ITEM=$PROTOCOL G_WHIP_MENU 'Please select the connection protocol type:' && PROTOCOL=${G_WHIP_RETURNED_VALUE,,} - # - Select server + # Select server G_DIETPI-NOTIFY 2 'Populating NordVPN server list, please wait...' G_WHIP_MENU_ARRAY=() for i in /etc/openvpn/ovpn_$PROTOCOL/*.ovpn @@ -348,11 +360,6 @@ _EOF_ else - . /DietPi/dietpi/func/dietpi-globals - G_PROGRAM_NAME='DietPi-NordVPN' - G_CHECK_ROOT_USER - G_CHECK_ROOTFS_RW - G_INIT Read_Settings Update_Wan_Ip From 091badf91c7cf7f60eaa4a8d39124e525a7ec136 Mon Sep 17 00:00:00 2001 From: svh1985 Date: Fri, 6 Sep 2019 10:42:43 +0200 Subject: [PATCH 17/18] Update dietpi-nordvpn Misallignment in menu, changed usage to traffic and added the connected state again. --- dietpi/misc/dietpi-nordvpn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index 2e42feb250..ebaa933a65 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -198,19 +198,19 @@ _EOF_ # TARGETMENUID=0 Menu_Main(){ - local text_status="Status:\n - WAN IP: $WAN_IP\n" + local text_status="Status:\n - WAN IP : $WAN_IP\n" if (( ! $NORDVPN_SERVICE )); then text_status+=' - Not configured\n - NordVPN subscription: https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' elif ! Check_Connected; then - text_status+=' - Disconnected\n - NordVPN subscription: https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' + text_status+=' - State : Disconnected\n - NordVPN subscription: https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' else Get_Connection_Info - text_status+=" - Usage : Sent = $TX | Received = $RX" + text_status+=" - State : Connected\n - Traffic : Sent = $TX | Received = $RX" fi From 45e2bbfca2044e319608488f15c275386c4db382 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 8 Sep 2019 12:46:32 +0200 Subject: [PATCH 18/18] v6.26 + DietPi-NordVPN | + DietPi-NordVPN | --- dietpi/misc/dietpi-nordvpn | 53 ++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/dietpi/misc/dietpi-nordvpn b/dietpi/misc/dietpi-nordvpn index ebaa933a65..7233112628 100644 --- a/dietpi/misc/dietpi-nordvpn +++ b/dietpi/misc/dietpi-nordvpn @@ -48,8 +48,8 @@ Available commands: NORDVPN_SERVER='' PROTOCOL='udp' - NET_DEV='tun0' - MAX_WAIT_FOR_CONNECTION=5 + IFACE='tun0' + MAX_WAIT_FOR_CONNECTION=5 # seconds NORDVPN_INSTALLED=0 NORDVPN_SERVICE=0 NORDVPN_CONNECTED=0 @@ -65,6 +65,7 @@ Available commands: until grep -q 'aSOFTWARE_INSTALL_STATE\[171\]=2' /DietPi/dietpi/.installed do + # Offer install only for interactive menu if [[ ! $INPUT ]] && G_WHIP_YESNO "$G_PROGRAM_NAME is not installed, would you like to install it now?"; then /DietPi/dietpi/dietpi-software install 171 @@ -80,14 +81,14 @@ Available commands: NORDVPN_INSTALLED=1 # Check service exists - [[ -f '/lib/systemd/system/dietpi-nordvpn.service' ]] && NORDVPN_SERVICE=1 + [[ -f '/etc/systemd/system/dietpi-nordvpn.service' ]] && NORDVPN_SERVICE=1 } Check_Connected(){ #systemctl status dietpi-nordvpn | grep -qi 'initialization sequence completed' - ip r s dev $NET_DEV &> /dev/null && NORDVPN_CONNECTED=1 || NORDVPN_CONNECTED=0 + ip r s dev $IFACE &> /dev/null && NORDVPN_CONNECTED=1 || NORDVPN_CONNECTED=0 return $(( ! $NORDVPN_CONNECTED )) } @@ -95,16 +96,16 @@ Available commands: Get_Connection_Info(){ RX='N/A' - if [[ -f /sys/class/net/$NET_DEV/statistics/rx_bytes ]]; then + if [[ -f /sys/class/net/$IFACE/statistics/rx_bytes ]]; then - local rx=$( /lib/systemd/system/dietpi-nordvpn.service + cat << _EOF_ > /etc/systemd/system/dietpi-nordvpn.service [Unit] Description=NordVPN (DietPi) After=network.target dietpi-boot.service @@ -160,11 +161,11 @@ _EOF_ NORDVPN_SERVICE=1 G_RUN_CMD systemctl restart dietpi-nordvpn - for (( i=1; i<=$MAX_WAIT_FOR_CONNECTION; i++ )) + local i=1 + until Check_Connected || (( $i > $MAX_WAIT_FOR_CONNECTION )) do - Check_Connected && break - G_DIETPI-NOTIFY -2 "Waiting for connection ($i/$MAX_WAIT_FOR_CONNECTION)" + G_DIETPI-NOTIFY -2 "Waiting for connection ($((i++))/$MAX_WAIT_FOR_CONNECTION)" sleep 1 done @@ -176,7 +177,7 @@ _EOF_ else G_DIETPI-NOTIFY 1 "Connection failed/timeout: $NORDVPN_SERVER" - G_WHIP_MSG "Connection failed/timeout: $NORDVPN_SERVER\n\nPlease verify account details are correct.\n\nIf problems persist, please check the status of \"systemctl -l status dietpi-nordvpn\"" + G_WHIP_MSG "Connection failed/timeout: $NORDVPN_SERVER\n\nPlease verify account details are correct.\n\nIf problems persist, please check the service status: \"systemctl -l status dietpi-nordvpn\"" fi @@ -198,19 +199,19 @@ _EOF_ # TARGETMENUID=0 Menu_Main(){ - local text_status="Status:\n - WAN IP : $WAN_IP\n" + local text_status="WAN IP : $WAN_IP\nState : " if (( ! $NORDVPN_SERVICE )); then - text_status+=' - Not configured\n - NordVPN subscription: https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' + text_status+='Not configured\nSubscription : https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' elif ! Check_Connected; then - text_status+=' - State : Disconnected\n - NordVPN subscription: https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' + text_status+='Disconnected\nSubscription : https://go.nordvpn.net/aff_c?offer_id=15&aff_id=5305&url_id=902' else Get_Connection_Info - text_status+=" - State : Connected\n - Traffic : Sent = $TX | Received = $RX" + text_status+="Connected\nTraffic : Sent = $TX | Received = $RX" fi @@ -230,7 +231,7 @@ _EOF_ fi G_WHIP_MENU_ARRAY+=('' '●─ Connection Up and Down Scripts ') G_WHIP_MENU_ARRAY+=('Edit Up' ': This script gets executed right after the VPN is connected') - G_WHIP_MENU_ARRAY+=('Edit Down' ': This script gets executed right after the VPN is disconnected') + G_WHIP_MENU_ARRAY+=('Edit Down' ': This script gets executed right before the VPN is disconnected') G_WHIP_MENU_ARRAY+=('' '●─ Save Settings ') G_WHIP_MENU_ARRAY+=('Apply' ': Save settings and restart VPN connection') @@ -245,17 +246,13 @@ _EOF_ Save_Settings Update_Wan_Ip - elif [[ $G_WHIP_RETURNED_VALUE == 'Edit Up' ]]; then + elif [[ $G_WHIP_RETURNED_VALUE == 'Edit'* ]]; then - [[ -f $FP_SETTINGS_UP ]] || echo -e '#!/bin/bash\n# Clear this file completely, including line breaks, to have it removed.' > $FP_SETTINGS_UP - nano $FP_SETTINGS_UP - (( $(stat -c %s $FP_SETTINGS_UP) )) && chmod 700 $FP_SETTINGS_UP || rm $FP_SETTINGS_UP - - elif [[ $G_WHIP_RETURNED_VALUE == 'Edit Down' ]]; then - - [[ -f $FP_SETTINGS_DOWN ]] || echo -e '#!/bin/bash\n# Clear this file completely, including line breaks, to have it removed.' > $FP_SETTINGS_DOWN - nano $FP_SETTINGS_DOWN - (( $(stat -c %s $FP_SETTINGS_DOWN) )) && chmod 700 $FP_SETTINGS_DOWN || rm $FP_SETTINGS_DOWN + local fp=$FP_SETTINGS_UP + [[ $G_WHIP_RETURNED_VALUE == *'Down' ]] && fp=$FP_SETTINGS_DOWN + [[ -f $fp ]] || echo -e '#!/bin/bash\n# Clear this file completely, including line breaks, to have it removed.' > $fp + nano $fp + (( $(stat -c %s $fp) )) && chmod 700 $fp || rm $fp elif [[ $G_WHIP_RETURNED_VALUE == 'Auto start' ]]; then