diff --git a/.codacy.yml b/.codacy.yml index 707459b..01da791 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -1,3 +1,4 @@ exclude_paths: - '**.js' - '**.asp' + - '**.css' diff --git a/README.md b/README.md index b268a1a..b06ee0d 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,13 @@ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/f73bdf3124904744b1844b4099f77bfe)](https://www.codacy.com/gh/jackyaz/vpnmgr/dashboard?utm_source=github.com&utm_medium=referral&utm_content=jackyaz/vpnmgr&utm_campaign=Badge_Grade) ![Shellcheck](https://github.com/jackyaz/vpnmgr/actions/workflows/shellcheck.yml/badge.svg) -## v2.2.0 -### Updated on 2021-02-07 +## v2.3.0 +### Updated on 2021-08-03 ## About -The concept for this script was originally developed by [@h0me5k1n](https://github.com/h0me5k1n/asusmerlin-nvpnmgr) +vpnmgr enables easy management of your VPN Client connections for various VPN providers on AsusWRT-Merlin. The following VPN Providers are currently supported: NordVPN, Private Internet Access (PIA) and WeVPN. +NordVPN clients can be configured to automatically refresh on a scheduled basis with the recommended server as provided by the NordVPN API. -Easy management of your VPN Client connections for various VPN providers on AsusWRT-Merlin. +The concept for this script was originally developed by [@h0me5k1n](https://github.com/h0me5k1n/asusmerlin-nvpnmgr) ### Supporting development Love the script and want to support future development? Any and all donations gratefully received! @@ -46,4 +47,4 @@ If this does not work, you will need to use the full path: ![CLI UI](https://puu.sh/HevPC/4f5ddfc3d6.png) ## Help -Please post about any issues and problems here: [Asuswrt-Merlin AddOns on SNBForums](https://www.snbforums.com/forums/asuswrt-merlin-addons.60/) +Please post about any issues and problems here: [Asuswrt-Merlin AddOns on SNBForums](https://www.snbforums.com/forums/asuswrt-merlin-addons.60/?prefix_id=11) diff --git a/vpnmgr.sh b/vpnmgr.sh index 9a0146f..fd34a81 100644 --- a/vpnmgr.sh +++ b/vpnmgr.sh @@ -1,31 +1,32 @@ #!/bin/sh -################################################### -## ## -## __ __ _ __ _ __ _ __ ___ __ _ _ __ ## -## \ \ / /| '_ \ | '_ \ | '_ ` _ \ / _` || '__| ## -## \ V / | |_) || | | || | | | | || (_| || | ## -## \_/ | .__/ |_| |_||_| |_| |_| \__, ||_| ## -## | | __/ | ## -## |_| |___/ ## -## ## -## https://github.com/jackyaz/vpnmgr ## -## forked from h0me5k1n ## -################################################### - -######## Shellcheck directives ######## +####################################################### +## ## +## __ __ _ __ _ __ _ __ ___ __ _ _ __ ## +## \ \ / /| '_ \ | '_ \ | '_ ` _ \ / _` || '__| ## +## \ V / | |_) || | | || | | | | || (_| || | ## +## \_/ | .__/ |_| |_||_| |_| |_| \__, ||_| ## +## | | __/ | ## +## |_| |___/ ## +## ## +## https://github.com/jackyaz/vpnmgr ## +## forked from h0me5k1n ## +####################################################### + +########## Shellcheck directives ########## # shellcheck disable=SC2016 # shellcheck disable=SC2018 # shellcheck disable=SC2019 # shellcheck disable=SC2039 +# shellcheck disable=SC2059 # shellcheck disable=SC2140 # shellcheck disable=SC2155 # shellcheck disable=SC3003 -################################################### +####################################################### ### Start of script variables ### readonly SCRIPT_NAME="vpnmgr" -readonly SCRIPT_VERSION="v2.2.0" +readonly SCRIPT_VERSION="v2.3.0" SCRIPT_BRANCH="master" SCRIPT_REPO="https://raw.githubusercontent.com/jackyaz/$SCRIPT_NAME/$SCRIPT_BRANCH" readonly SCRIPT_DIR="/jffs/addons/$SCRIPT_NAME.d" @@ -55,16 +56,17 @@ readonly CRIT="\\e[41m" readonly ERR="\\e[31m" readonly WARN="\\e[33m" readonly PASS="\\e[32m" +readonly BOLD="\\e[1m" +readonly SETTING="${BOLD}\\e[36m" +readonly CLEARFORMAT="\\e[0m" ### End of output format variables ### # $1 = print to syslog, $2 = message to print, $3 = log level Print_Output(){ if [ "$1" = "true" ]; then logger -t "$SCRIPT_NAME" "$2" - printf "\\e[1m$3%s: $2\\e[0m\\n\\n" "$SCRIPT_NAME" - else - printf "\\e[1m$3%s: $2\\e[0m\\n\\n" "$SCRIPT_NAME" fi + printf "${BOLD}${3}%s${CLEARFORMAT}\\n\\n" "$2" } Firmware_Version_Check(){ @@ -120,14 +122,14 @@ Set_Version_Custom_Settings(){ local) if [ -f "$SETTINGSFILE" ]; then if [ "$(grep -c "vpnmgr_version_local" $SETTINGSFILE)" -gt 0 ]; then - if [ "$SCRIPT_VERSION" != "$(grep "vpnmgr_version_local" /jffs/addons/custom_settings.txt | cut -f2 -d' ')" ]; then - sed -i "s/vpnmgr_version_local.*/vpnmgr_version_local $SCRIPT_VERSION/" "$SETTINGSFILE" + if [ "$2" != "$(grep "vpnmgr_version_local" /jffs/addons/custom_settings.txt | cut -f2 -d' ')" ]; then + sed -i "s/vpnmgr_version_local.*/vpnmgr_version_local $2/" "$SETTINGSFILE" fi else - echo "vpnmgr_version_local $SCRIPT_VERSION" >> "$SETTINGSFILE" + echo "vpnmgr_version_local $2" >> "$SETTINGSFILE" fi else - echo "vpnmgr_version_local $SCRIPT_VERSION" >> "$SETTINGSFILE" + echo "vpnmgr_version_local $2" >> "$SETTINGSFILE" fi ;; server) @@ -149,7 +151,7 @@ Set_Version_Custom_Settings(){ Update_Check(){ echo 'var updatestatus = "InProgress";' > "$SCRIPT_WEB_DIR/detect_update.js" doupdate="false" - localver=$(grep "SCRIPT_VERSION=" /jffs/scripts/"$SCRIPT_NAME" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})') + localver=$(grep "SCRIPT_VERSION=" "/jffs/scripts/$SCRIPT_NAME" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})') /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" | grep -qF "jackyaz" || { Print_Output true "404 error detected - stopping update" "$ERR"; return 1; } serverver=$(/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" | grep "SCRIPT_VERSION=" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})') if [ "$localver" != "$serverver" ]; then @@ -172,33 +174,44 @@ Update_Check(){ } Update_Version(){ - if [ -z "$1" ] || [ "$1" = "unattended" ]; then + if [ -z "$1" ]; then updatecheckresult="$(Update_Check)" isupdate="$(echo "$updatecheckresult" | cut -f1 -d',')" localver="$(echo "$updatecheckresult" | cut -f2 -d',')" serverver="$(echo "$updatecheckresult" | cut -f3 -d',')" if [ "$isupdate" = "version" ]; then - Print_Output true "New version of $SCRIPT_NAME available - updating to $serverver" "$PASS" + Print_Output true "New version of $SCRIPT_NAME available - $serverver" "$PASS" elif [ "$isupdate" = "md5" ]; then - Print_Output true "MD5 hash of $SCRIPT_NAME does not match - downloading updated $serverver" "$PASS" + Print_Output true "MD5 hash of $SCRIPT_NAME does not match - hotfix available $serverver" "$PASS" fi - Update_File shared-jy.tar.gz - if [ "$isupdate" != "false" ]; then - Update_File vpnmgr_www.asp - /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" -o "/jffs/scripts/$SCRIPT_NAME" && Print_Output true "$SCRIPT_NAME successfully updated" - chmod 0755 /jffs/scripts/"$SCRIPT_NAME" - Clear_Lock - if [ -z "$1" ]; then - exec "$0" setversion - elif [ "$1" = "unattended" ]; then - exec "$0" setversion unattended - fi + printf "\\n${BOLD}Do you want to continue with the update? (y/n)${CLEARFORMAT} " + read -r confirm + case "$confirm" in + y|Y) + Update_File shared-jy.tar.gz + Update_File vpnmgr_www.asp + printf "\\n" + /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" -o "/jffs/scripts/$SCRIPT_NAME" && Print_Output true "$SCRIPT_NAME successfully updated" + chmod 0755 "/jffs/scripts/$SCRIPT_NAME" + Set_Version_Custom_Settings local "$serverver" + Set_Version_Custom_Settings server "$serverver" + Clear_Lock + PressEnter + exec "$0" + exit 0 + ;; + *) + printf "\\n" + Clear_Lock + return 1 + ;; + esac exit 0 else - Print_Output true "No new version - latest is $localver" "$WARN" + Print_Output true "No updates available - latest is $localver" "$WARN" Clear_Lock fi fi @@ -209,12 +222,15 @@ Update_Version(){ Update_File shared-jy.tar.gz Update_File vpnmgr_www.asp /usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" -o "/jffs/scripts/$SCRIPT_NAME" && Print_Output true "$SCRIPT_NAME successfully updated" - chmod 0755 /jffs/scripts/"$SCRIPT_NAME" + chmod 0755 "/jffs/scripts/$SCRIPT_NAME_LOWER" + Set_Version_Custom_Settings local "$serverver" + Set_Version_Custom_Settings server "$serverver" Clear_Lock if [ -z "$2" ]; then - exec "$0" setversion + PressEnter + exec "$0" elif [ "$2" = "unattended" ]; then - exec "$0" setversion unattended + exec "$0" postupdate fi exit 0 fi @@ -291,7 +307,7 @@ Auto_Startup(){ STARTUPLINECOUNT=$(grep -c '# '"${SCRIPT_NAME}_startup" /jffs/scripts/services-start) if [ "$STARTUPLINECOUNT" -gt 0 ]; then - sed -i -e '/# '"$SCRIPT_NAME""_startup"'/d' /jffs/scripts/services-start + sed -i -e '/# '"${SCRIPT_NAME}_startup"'/d' /jffs/scripts/services-start fi fi if [ -f /jffs/scripts/post-mount ]; then @@ -377,8 +393,41 @@ Get_WebUI_Page(){ done } +### function based on @dave14305's FlexQoS webconfigpage function ### +Get_WebUI_URL(){ + urlpage="" + urlproto="" + urldomain="" + urlport="" + + urlpage="$(sed -nE "/$SCRIPT_NAME/ s/.*url\: \"(user[0-9]+\.asp)\".*/\1/p" /tmp/menuTree.js)" + if [ "$(nvram get http_enable)" -eq 1 ]; then + urlproto="https" + else + urlproto="http" + fi + if [ -n "$(nvram get lan_domain)" ]; then + urldomain="$(nvram get lan_hostname).$(nvram get lan_domain)" + else + urldomain="$(nvram get lan_ipaddr)" + fi + if [ "$(nvram get ${urlproto}_lanport)" -eq 80 ] || [ "$(nvram get ${urlproto}_lanport)" -eq 443 ]; then + urlport="" + else + urlport=":$(nvram get ${urlproto}_lanport)" + fi + + if echo "$urlpage" | grep -qE "user[0-9]+\.asp"; then + echo "${urlproto}://${urldomain}${urlport}/${urlpage}" | tr "A-Z" "a-z" + else + echo "WebUI page not found" + fi +} +### ### + ### locking mechanism code credit to Martineau (@MartineauUK) ### Mount_WebUI(){ + Print_Output true "Mounting WebUI tab for $SCRIPT_NAME" "$PASS" LOCKFILE=/tmp/addonwebui.lock FD=386 eval exec "$FD>$LOCKFILE" @@ -390,7 +439,7 @@ Mount_WebUI(){ return 1 fi cp -f "$SCRIPT_DIR/vpnmgr_www.asp" "$SCRIPT_WEBPAGE_DIR/$MyPage" - echo "vpnmgr" > "$SCRIPT_WEBPAGE_DIR/$(echo $MyPage | cut -f1 -d'.').title" + echo "$SCRIPT_NAME" > "$SCRIPT_WEBPAGE_DIR/$(echo $MyPage | cut -f1 -d'.').title" if [ "$(uname -o)" = "ASUSWRT-Merlin" ]; then if [ ! -f "/tmp/menuTree.js" ]; then @@ -398,7 +447,7 @@ Mount_WebUI(){ fi sed -i "\\~$MyPage~d" /tmp/menuTree.js - sed -i "/url: \"Advanced_OpenVPNClient_Content.asp\", tabName:/a {url: \"$MyPage\", tabName: \"vpnmgr\"}," /tmp/menuTree.js + sed -i "/url: \"Advanced_OpenVPNClient_Content.asp\", tabName:/a {url: \"$MyPage\", tabName: \"$SCRIPT_NAME\"}," /tmp/menuTree.js umount /www/require/modules/menuTree.js 2>/dev/null mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js @@ -408,13 +457,9 @@ Mount_WebUI(){ } Validate_Number(){ - if [ "$2" -eq "$2" ] 2>/dev/null; then + if [ "$1" -eq "$1" ] 2>/dev/null; then return 0 else - formatted="$(echo "$1" | sed -e 's/|/ /g')" - if [ -z "$3" ]; then - Print_Output false "$formatted - $2 is not a number" "$ERR" - fi return 1 fi } @@ -497,17 +542,9 @@ Conf_Exists(){ dos2unix "$SCRIPT_CONF" chmod 0644 "$SCRIPT_CONF" sed -i -e 's/"//g' "$SCRIPT_CONF" - if [ "$(wc -l < "$SCRIPT_CONF")" -eq 45 ]; then - for i in 1 2 3 4 5; do - sed -i '/^vpn'"$i"'_schmins=.*/a vpn'"$i"'_cityid=0' "$SCRIPT_CONF" - sed -i '/^vpn'"$i"'_schmins=.*/a vpn'"$i"'_countryid=0' "$SCRIPT_CONF" - sed -i '/^vpn'"$i"'_schmins=.*/a vpn'"$i"'_cityname=' "$SCRIPT_CONF" - sed -i '/^vpn'"$i"'_schmins=.*/a vpn'"$i"'_countryname=' "$SCRIPT_CONF" - done - fi - if [ "$(wc -l < "$SCRIPT_CONF")" -eq 65 ]; then + if ! grep -q "_customsettings" "$SCRIPT_CONF"; then for i in 1 2 3 4 5; do - sed -i '/^vpn'"$i"'_managed=.*/a vpn'"$i"'_provider=NordVPN' "$SCRIPT_CONF" + sed -i '/^vpn'"$i"'_type=.*/a vpn'"$i"'_customsettings=true' "$SCRIPT_CONF" done fi return 0 @@ -519,6 +556,7 @@ Conf_Exists(){ echo "vpn${i}_provider=NordVPN" echo "vpn${i}_protocol=UDP" echo "vpn${i}_type=Standard" + echo "vpn${i}_customsettings=true" echo "vpn${i}_schenabled=false" echo "vpn${i}_schdays=*" echo "vpn${i}_schhours=0" @@ -537,7 +575,7 @@ Conf_Exists(){ # use to create content of vJSON variable; $1 VPN type, $2 VPN protocol, $3 country id getRecommendedServers(){ curlstring="https://api.nordvpn.com/v1/servers/recommendations?filters\[servers_groups\]\[identifier\]=${1}&filters\[servers_technologies\]\[identifier\]=${2}" - if [ "$3" != "0" ]; then + if [ "$3" -ne 0 ]; then curlstring="${curlstring}&filters\[country_id\]=$3" fi curlstring="${curlstring}&limit=1" @@ -703,7 +741,7 @@ getOVPNArchives(){ piachanged="$(CompareArchiveContents "/tmp/pia_udp_standard.zip /tmp/pia_tcp_standard.zip /tmp/pia_udp_strong.zip /tmp/pia_tcp_strong.zip")" if [ "$piachanged" = "true" ]; then - /opt/bin/7z -ba l "$OVPN_ARCHIVE_DIR/pia_udp_standard.zip" -- *.ovpn | awk '{ for (i = 6; i <= NF; i++) { printf "%s ",$i } printf "\n"}' | sed 's/\.ovpn//' | sort | awk '{$1=$1;print}' > "$SCRIPT_DIR/pia_countrydata" + /opt/bin/7za -ba l "$OVPN_ARCHIVE_DIR/pia_udp_standard.zip" -- *.ovpn | awk '{ for (i = 6; i <= NF; i++) { printf "%s ",$i } printf "\n"}' | sed 's/\.ovpn//' | sort | awk '{$1=$1;print}' > "$SCRIPT_DIR/pia_countrydata" Print_Output true "Changes detected in PIA OpenVPN file archives, local copies updated" "$PASS" else Print_Output true "No changes in PIA OpenVPN file archives" "$WARN" @@ -719,7 +757,7 @@ getOVPNArchives(){ wevpnchanged="$(CompareArchiveContents "/tmp/wevpn_udp_standard.zip /tmp/wevpn_tcp_standard.zip")" if [ "$wevpnchanged" = "true" ]; then - /opt/bin/7z -ba l "$OVPN_ARCHIVE_DIR/wevpn_tcp_standard.zip" -- *.ovpn | awk '{ for (i = 6; i <= NF; i++) { printf "%s ",$i } printf "\n"}' | sed 's/\.ovpn//;s/-UDP//;s/-TCP//;s/_/ /;' | sort | awk '{$1=$1;print}' > "$SCRIPT_DIR/wevpn_countrydata" + /opt/bin/7za -ba l "$OVPN_ARCHIVE_DIR/wevpn_tcp_standard.zip" -- *.ovpn | awk '{ for (i = 6; i <= NF; i++) { printf "%s ",$i } printf "\n"}' | sed 's/\.ovpn//;s/-UDP//;s/-TCP//;s/_/ /;' | sort | awk '{$1=$1;print}' > "$SCRIPT_DIR/wevpn_countrydata" Print_Output true "Changes detected in WeVPN OpenVPN file archives, local copies updated" "$PASS" else Print_Output true "No changes in WeVPN OpenVPN file archives" "$WARN" @@ -751,6 +789,7 @@ CompareArchiveContents(){ ListVPNClients(){ showload="$1" + showunmanaged="$2" if [ "$showload" = "true" ]; then printf "Checking server loads using NordVPN API...\\n\\n" @@ -767,20 +806,29 @@ ListVPNClients(){ MANAGEDSTATE="" CONNECTSTATE="" SCHEDULESTATE="" + CUSTOMSETTINGSTATE="" if [ "$(grep "vpn${i}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "true" ]; then - MANAGEDSTATE="Managed" + MANAGEDSTATE="${BOLD}${PASS}Managed${CLEARFORMAT}" elif [ "$(grep "vpn${i}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then - MANAGEDSTATE="Unmanaged" + if [ "$showunmanaged" = "hide" ]; then + continue + fi + MANAGEDSTATE="${BOLD}${ERR}Unmanaged${CLEARFORMAT}" fi if [ "$(getConnectState "$i")" = "2" ]; then - CONNECTSTATE="Active" + CONNECTSTATE="${BOLD}${PASS}Connected${CLEARFORMAT}" else - CONNECTSTATE="Inactive" + CONNECTSTATE="${BOLD}${ERR}Disconnected${CLEARFORMAT}" + fi + if [ "$(grep "vpn${i}_customsettings" "$SCRIPT_CONF" | cut -f2 -d"=")" = "true" ]; then + CUSTOMSETTINGSTATE="${SETTING}Customised${CLEARFORMAT}" + elif [ "$(grep "vpn${i}_customsettings" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + CUSTOMSETTINGSTATE="${BOLD}Uncustomised${CLEARFORMAT}" fi if [ "$(grep "vpn${i}_schenabled" "$SCRIPT_CONF" | cut -f2 -d"=")" = "true" ]; then - SCHEDULESTATE="Scheduled" + SCHEDULESTATE="${SETTING}Scheduled${CLEARFORMAT}" elif [ "$(grep "vpn${i}_schenabled" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then - SCHEDULESTATE="Unscheduled" + SCHEDULESTATE="${BOLD}Unscheduled${CLEARFORMAT}" fi COUNTRYNAME="$(grep "vpn${i}_countryname" "$SCRIPT_CONF" | cut -f2 -d"=")" [ -z "$COUNTRYNAME" ] && COUNTRYNAME="None" @@ -791,7 +839,11 @@ ListVPNClients(){ SERVERLOAD="$(getServerLoad "$VPN_CLIENTDESC")" fi - printf "%s. %s (%s, %s and %s)\\n" "$i" "$VPN_CLIENTDESC" "$MANAGEDSTATE" "$CONNECTSTATE" "$SCHEDULESTATE" + if [ "$(grep "vpn${i}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "true" ]; then + printf "%s. $VPN_CLIENTDESC ($MANAGEDSTATE, $SCHEDULESTATE, $CUSTOMSETTINGSTATE, $CONNECTSTATE)\\n" "$i" + else + printf "%s. $VPN_CLIENTDESC ($MANAGEDSTATE, $CONNECTSTATE)\\n" "$i" + fi if [ "$showload" = "true" ]; then printf " Current server load: %s%%\\n" "$SERVERLOAD" fi @@ -809,13 +861,13 @@ UpdateVPNConfig(){ VPN_NO="$1" VPN_PROVIDER="$(grep "vpn${VPN_NO}_provider" "$SCRIPT_CONF" | cut -f2 -d"=")" VPN_PROT_SHORT="$(grep "vpn${VPN_NO}_protocol" "$SCRIPT_CONF" | cut -f2 -d"=")" - VPN_PROT="openvpn_""$(echo "$VPN_PROT_SHORT" | tr "A-Z" "a-z")" + VPN_PROT="openvpn_$(echo "$VPN_PROT_SHORT" | tr "A-Z" "a-z")" VPN_TYPE_SHORT="$(grep "vpn${VPN_NO}_type" "$SCRIPT_CONF" | cut -f2 -d"=")" VPN_TYPE="" if [ "$VPN_TYPE_SHORT" = "Double" ]; then - VPN_TYPE="legacy_""$(echo "$VPN_TYPE_SHORT" | tr "A-Z" "a-z")""_vpn" + VPN_TYPE="legacy_$(echo "$VPN_TYPE_SHORT" | tr "A-Z" "a-z")""_vpn" else - VPN_TYPE="legacy_""$(echo "$VPN_TYPE_SHORT" | tr "A-Z" "a-z")" + VPN_TYPE="legacy_$(echo "$VPN_TYPE_SHORT" | tr "A-Z" "a-z")" fi VPN_COUNTRYID="$(grep "vpn${VPN_NO}_countryid" "$SCRIPT_CONF" | cut -f2 -d"=")" VPN_COUNTRYNAME="$(grep "vpn${VPN_NO}_countryname" "$SCRIPT_CONF" | cut -f2 -d"=")" @@ -827,11 +879,11 @@ UpdateVPNConfig(){ if [ "$VPN_PROVIDER" = "NordVPN" ]; then Print_Output true "Retrieving recommended VPN server using NordVPN API with below parameters" "$PASS" - if [ "$VPN_COUNTRYID" = "0" ]; then + if [ "$VPN_COUNTRYID" -eq 0 ]; then Print_Output true "Protocol: $VPN_PROT_SHORT - Type: $VPN_TYPE_SHORT" "$PASS" vJSON="$(getRecommendedServers "$VPN_TYPE" "$VPN_PROT" "$VPN_COUNTRYID")" else - if [ "$VPN_CITYID" = "0" ]; then + if [ "$VPN_CITYID" -eq 0 ]; then Print_Output true "Protocol: $VPN_PROT_SHORT - Type: $VPN_TYPE_SHORT - Country: $VPN_COUNTRYNAME" "$PASS" vJSON="$(getRecommendedServers "$VPN_TYPE" "$VPN_PROT" "$VPN_COUNTRYID")" else @@ -842,7 +894,7 @@ UpdateVPNConfig(){ vJSON="$(getRecommendedServers "$VPN_TYPE" "$VPN_PROT" "$VPN_COUNTRYID")" if [ -z "$vJSON" ]; then Print_Output true "No VPN servers found for $VPN_COUNTRYNAME, removing filter for country" "$WARN" - vJSON="$(getRecommendedServers "$VPN_TYPE" "$VPN_PROT" "0")" + vJSON="$(getRecommendedServers "$VPN_TYPE" "$VPN_PROT" 0)" fi fi fi @@ -860,13 +912,13 @@ UpdateVPNConfig(){ OVPN_FILENAME="${OVPN_FILENAME}_${VPN_CITYNAME}" fi OVPN_FILENAME="$(echo "$OVPN_FILENAME" | tr "A-Z" "a-z" | sed 's/ /_/g;')" - /opt/bin/7z e -bsp0 -bso0 "$OVPNARCHIVE" -o/tmp "$OVPN_FILENAME.ovpn" + /opt/bin/7za e -bsp0 -bso0 "$OVPNARCHIVE" -o/tmp "$OVPN_FILENAME.ovpn" OVPN_DETAIL="$(cat "/tmp/$OVPN_FILENAME.ovpn")" rm -f "/tmp/$OVPN_FILENAME.ovpn" elif [ "$VPN_PROVIDER" = "WeVPN" ]; then OVPNARCHIVE="$OVPN_ARCHIVE_DIR/wevpn_$(echo "$VPN_PROT" | cut -f2 -d"_")_$(echo "$VPN_TYPE" | cut -f2 -d"_").zip" OVPN_FILENAME="$(echo "$VPN_COUNTRYNAME" | sedReverseCountryCodesWeVPN)"'_'"$(echo "$VPN_CITYNAME" | tr "A-Z" "a-z")-$VPN_PROT_SHORT" - /opt/bin/7z e -bsp0 -bso0 "$OVPNARCHIVE" -o/tmp "$OVPN_FILENAME.ovpn" + /opt/bin/7za e -bsp0 -bso0 "$OVPNARCHIVE" -o/tmp "$OVPN_FILENAME.ovpn" OVPN_DETAIL="$(cat "/tmp/$OVPN_FILENAME.ovpn")" rm -f "/tmp/$OVPN_FILENAME.ovpn" fi @@ -938,8 +990,8 @@ UpdateVPNConfig(){ Print_Output true "Updating VPN client $VPN_NO to $VPN_PROVIDER server" "$PASS" if [ -z "$(nvram get vpn_client"$VPN_NO"_addr)" ]; then - nvram set vpn_client"$VPN_NO"_adns="3" - nvram set vpn_client"$VPN_NO"_enforce="1" + nvram set vpn_client"$VPN_NO"_adns=3 + nvram set vpn_client"$VPN_NO"_enforce=1 if [ "$(Firmware_Number_Check "$(nvram get buildno)")" -lt "$(Firmware_Number_Check 384.18)" ]; then nvram set vpn_client"$VPN_NO"_clientlist="172.16.14.1>0.0.0.0>VPN" else @@ -962,15 +1014,15 @@ UpdateVPNConfig(){ nvram set vpn_client"$VPN_NO"_cipher="$OVPN_CIPHER" nvram set vpn_client"$VPN_NO"_crypt="tls" nvram set vpn_client"$VPN_NO"_digest="$OVPN_AUTHDIGEST" - nvram set vpn_client"$VPN_NO"_fw="1" + nvram set vpn_client"$VPN_NO"_fw=1 nvram set vpn_client"$VPN_NO"_if="tun" - nvram set vpn_client"$VPN_NO"_nat="1" + nvram set vpn_client"$VPN_NO"_nat=1 nvram set vpn_client"$VPN_NO"_ncp_ciphers="AES-256-GCM:AES-128-GCM:AES-256-CBC:AES-128-CBC" - nvram set vpn_client"$VPN_NO"_ncp_enable="1" - nvram set vpn_client"$VPN_NO"_reneg="0" - nvram set vpn_client"$VPN_NO"_tlsremote="0" - nvram set vpn_client"$VPN_NO"_userauth="1" - nvram set vpn_client"$VPN_NO"_useronly="0" + nvram set vpn_client"$VPN_NO"_ncp_enable=1 + nvram set vpn_client"$VPN_NO"_reneg=0 + nvram set vpn_client"$VPN_NO"_tlsremote=0 + nvram set vpn_client"$VPN_NO"_userauth=1 + nvram set vpn_client"$VPN_NO"_useronly=0 if [ "$VPN_PROVIDER" = "NordVPN" ] || [ "$VPN_PROVIDER" = "WeVPN" ]; then nvram set vpn_client"$VPN_NO"_comp="-1" @@ -979,60 +1031,19 @@ UpdateVPNConfig(){ fi if [ "$VPN_PROVIDER" = "NordVPN" ] || [ "$VPN_PROVIDER" = "PIA" ]; then - nvram set vpn_client"$VPN_NO"_hmac="1" + nvram set vpn_client"$VPN_NO"_hmac=1 elif [ "$VPN_PROVIDER" = "WeVPN" ]; then - nvram set vpn_client"$VPN_NO"_hmac="3" + nvram set vpn_client"$VPN_NO"_hmac=3 fi if [ "$(Firmware_Number_Check "$(nvram get buildno)")" -lt "$(Firmware_Number_Check 384.19)" ]; then nvram set vpn_client"$VPN_NO"_connretry="-1" else - nvram set vpn_client"$VPN_NO"_connretry="0" + nvram set vpn_client"$VPN_NO"_connretry=0 fi - vpncustomoptions='remote-random -resolv-retry infinite -remote-cert-tls server -ping 15 -ping-restart 0 -ping-timer-rem -persist-key -persist-tun -reneg-sec 0 -fast-io -disable-occ -mute-replay-warnings -auth-nocache -sndbuf 524288 -rcvbuf 524288 -push "sndbuf 524288" -push "rcvbuf 524288" -pull-filter ignore "auth-token" -pull-filter ignore "ifconfig-ipv6" -pull-filter ignore "route-ipv6"' - - if [ "$VPN_PROT_SHORT" = "UDP" ]; then - vpncustomoptions="$vpncustomoptions -explicit-exit-notify 3" - fi - - if [ "$VPN_PROVIDER" = "NordVPN" ]; then - vpncustomoptions="$vpncustomoptions -tun-mtu 1500 -tun-mtu-extra 32 -mssfix 1450" - fi - - vpncustomoptionsbase64="$(echo "$vpncustomoptions" | head -c -1 | openssl base64 -A)" - - if [ "$(/bin/uname -m)" = "aarch64" ]; then - nvram set vpn_client"$VPN_NO"_cust2="$(echo "$vpncustomoptionsbase64" | cut -c0-255)" - nvram set vpn_client"$VPN_NO"_cust21="$(echo "$vpncustomoptionsbase64" | cut -c256-510)" - nvram set vpn_client"$VPN_NO"_cust22="$(echo "$vpncustomoptionsbase64" | cut -c511-765)" - elif [ "$(uname -o)" = "ASUSWRT-Merlin" ]; then - nvram set vpn_client"$VPN_NO"_cust2="$vpncustomoptionsbase64" - else - nvram set vpn_client"$VPN_NO"_custom="$vpncustomoptions" + if [ "$(grep "vpn${VPN_NO}_customsettings" "$SCRIPT_CONF" | cut -f2 -d"=")" = "true" ]; then + SetVPNCustomSettings "$VPN_NO" fi if [ "$ISUNATTENDED" = "true" ]; then @@ -1046,15 +1057,15 @@ mssfix 1450" else if [ -n "$(nvram get vpn_client"$VPN_NO"_username)" ] && [ -n "$(nvram get vpn_client"$VPN_NO"_password)" ]; then while true; do - printf "\\n\\e[1mDo you want to update the username and password for the VPN client? (y/n)\\e[0m\\n" + printf "\\n${BOLD}Do you want to update the username and password for the VPN client? (y/n)${CLEARFORMAT} " read -r confirm case "$confirm" in y|Y) - printf "Please enter username: " + printf "Please enter username: " read -r vpnusn nvram set vpn_client"$VPN_NO"_username="$vpnusn" printf "\\n" - printf "Please enter password: " + printf "Please enter password: " read -r vpnpwd nvram set vpn_client"$VPN_NO"_password="$vpnpwd" printf "\\n" @@ -1064,23 +1075,23 @@ mssfix 1450" break ;; *) - printf "\\n\\e[1mPlease enter a valid choice (y/n)\\e[0m\\n" + printf "\\n${BOLD}Please enter a valid choice (y/n)${CLEARFORMAT}\\n" ;; esac done fi if [ -z "$(nvram get vpn_client"$VPN_NO"_username)" ]; then - printf "\\n\\e[1mNo username set for VPN client %s\\e[0m\\n" "$VPN_NO" - printf "Please enter username: " + printf "\\n${BOLD}No username set for VPN client %s${CLEARFORMAT}\\n" "$VPN_NO" + printf "Please enter username: " read -r vpnusn nvram set vpn_client"$VPN_NO"_username="$vpnusn" printf "\\n" fi if [ -z "$(nvram get vpn_client"$VPN_NO"_password)" ]; then - printf "\\n\\e[1mNo password set for VPN client %s\\e[0m\\n" "$VPN_NO" - printf "Please enter password: " + printf "\\n${BOLD}No password set for VPN client %s${CLEARFORMAT}\\n" "$VPN_NO" + printf "Please enter password: " read -r vpnpwd nvram set vpn_client"$VPN_NO"_password="$vpnpwd" printf "\\n" @@ -1123,28 +1134,18 @@ ManageVPN(){ return 1 fi - if [ "$(grep "vpn${VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "true" ]; then - printf "\\n" - Print_Output false "VPN client $VPN_NO is already managed by $SCRIPT_NAME" "$WARN" - elif [ "$(grep "vpn${VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then - Print_Output true "Enabling management of VPN client $VPN_NO" "$PASS" - sed -i 's/^vpn'"$VPN_NO"'_managed.*$/vpn'"$VPN_NO"'_managed=true/' "$SCRIPT_CONF" - Print_Output true "Management of VPN client $VPN_NO successfully enabled" "$PASS" - fi + Print_Output true "Enabling management of VPN client $VPN_NO" "$PASS" + sed -i 's/^vpn'"$VPN_NO"'_managed.*$/vpn'"$VPN_NO"'_managed=true/' "$SCRIPT_CONF" + Print_Output true "Management of VPN client $VPN_NO successfully enabled" "$PASS" } UnmanageVPN(){ VPN_NO="$1" - if [ "$(grep "vpn${VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "true" ]; then - Print_Output true "Removing management of VPN client $VPN_NO" "$PASS" - sed -i 's/^vpn'"$VPN_NO"'_managed.*$/vpn'"$VPN_NO"'_managed=false/' "$SCRIPT_CONF" - CancelScheduleVPN "$VPN_NO" - Print_Output true "Management of VPN client $VPN_NO successfully removed" "$PASS" - elif [ "$(grep "vpn${VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then - printf "\\n" - Print_Output false "VPN client $VPN_NO is not managed by $SCRIPT_NAME" "$WARN" - fi + Print_Output true "Removing management of VPN client $VPN_NO" "$PASS" + sed -i 's/^vpn'"$VPN_NO"'_managed.*$/vpn'"$VPN_NO"'_managed=false/' "$SCRIPT_CONF" + CancelScheduleVPN "$VPN_NO" + Print_Output true "Management of VPN client $VPN_NO successfully removed" "$PASS" } ScheduleVPN(){ @@ -1155,7 +1156,7 @@ ScheduleVPN(){ Print_Output true "Configuring scheduled update for VPN client $VPN_NO" "$PASS" - if cru l | grep -q "$SCRIPT_NAME$VPN_NO"; then + if cru l | grep -q "${SCRIPT_NAME}${VPN_NO}"; then cru d "${SCRIPT_NAME}_VPN${VPN_NO}" fi @@ -1165,24 +1166,18 @@ ScheduleVPN(){ sed -i "/${SCRIPT_NAME}_VPN${VPN_NO}/d" /jffs/scripts/services-start echo "cru a ${SCRIPT_NAME}_VPN${VPN_NO} \"$CRU_MINUTES $CRU_HOURS * * $CRU_DAYNUMBERS /jffs/scripts/$SCRIPT_NAME updatevpn $VPN_NO\" # $SCRIPT_NAME" >> /jffs/scripts/services-start else - echo "#!/bin/sh" >> /jffs/scripts/services-start + echo "#!/bin/sh" > /jffs/scripts/services-start echo "cru a ${SCRIPT_NAME}_VPN${VPN_NO} \"$CRU_MINUTES $CRU_HOURS * * $CRU_DAYNUMBERS /jffs/scripts/$SCRIPT_NAME updatevpn $VPN_NO\" # $SCRIPT_NAME" >> /jffs/scripts/services-start chmod 755 /jffs/scripts/services-start fi + sed -i 's/^vpn'"$VPN_NO"'_schenabled.*$/vpn'"$VPN_NO"'_schenabled=true/' "$SCRIPT_CONF" + Print_Output true "Scheduled update created for VPN client $VPN_NO" "$PASS" } CancelScheduleVPN(){ VPN_NO="$1" - SCHEDULESTATE="" - if ! cru l | grep -q "#${SCRIPT_NAME}_VPN${VPN_NO}#"; then - SCHEDULESTATE="Unscheduled" - else - SCHEDULESTATE="Scheduled" - fi - - sed -i 's/^vpn'"$VPN_NO"'_schenabled.*$/vpn'"$VPN_NO"'_schenabled=false/' "$SCRIPT_CONF" Print_Output true "Removing scheduled update for VPN client $VPN_NO" "$PASS" @@ -1190,8 +1185,10 @@ CancelScheduleVPN(){ cru d "${SCRIPT_NAME}_VPN${VPN_NO}" fi + sed -i 's/^vpn'"$VPN_NO"'_schenabled.*$/vpn'"$VPN_NO"'_schenabled=false/' "$SCRIPT_CONF" + if grep -q "${SCRIPT_NAME}_VPN${VPN_NO}" /jffs/scripts/services-start; then - sed -i "/$SCRIPT_NAME""_VPN""$VPN_NO/d" /jffs/scripts/services-start + sed -i "/${SCRIPT_NAME}_VPN${VPN_NO}/d" /jffs/scripts/services-start fi Print_Output true "Scheduled update cancelled for VPN client $VPN_NO" "$PASS" @@ -1201,13 +1198,13 @@ Shortcut_Script(){ case $1 in create) if [ -d /opt/bin ] && [ ! -f "/opt/bin/$SCRIPT_NAME" ] && [ -f "/jffs/scripts/$SCRIPT_NAME" ]; then - ln -s /jffs/scripts/"$SCRIPT_NAME" /opt/bin - chmod 0755 /opt/bin/"$SCRIPT_NAME" + ln -s "/jffs/scripts/$SCRIPT_NAME" /opt/bin + chmod 0755 "/opt/bin/$SCRIPT_NAME" fi ;; delete) if [ -f "/opt/bin/$SCRIPT_NAME" ]; then - rm -f /opt/bin/"$SCRIPT_NAME" + rm -f "/opt/bin/$SCRIPT_NAME" fi ;; esac @@ -1215,27 +1212,27 @@ Shortcut_Script(){ SetVPNClient(){ ScriptHeader - ListVPNClients "false" + ListVPNClients false "$1" printf "Choose options as follows:\\n" - printf " - VPN client [1-5]\\n" + printf " - VPN client (pick from list)\\n" printf "\\n" - printf "\\e[1m#########################################################\\e[0m\\n" + printf "${BOLD}#########################################################${CLEARFORMAT}\\n" exitmenu="" vpnnum="" while true; do - printf "\\n\\e[1mPlease enter the VPN client number (1-5):\\e[0m " + printf "\\n${BOLD}Please enter the VPN client number (pick from list):${CLEARFORMAT} " read -r vpn_choice if [ "$vpn_choice" = "e" ]; then exitmenu="exit" break - elif ! Validate_Number "" "$vpn_choice" silent; then - printf "\\n\\e[31mPlease enter a valid number (1-5)\\e[0m\\n" + elif ! Validate_Number "$vpn_choice"; then + printf "\\n\\e[31mPlease enter a valid number (pick from list)${CLEARFORMAT}\\n" else if [ "$vpn_choice" -lt 1 ] || [ "$vpn_choice" -gt 5 ]; then - printf "\\n\\e[31mPlease enter a number between 1 and 5\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 1 and 5${CLEARFORMAT}\\n" else vpnnum="$vpn_choice" printf "\\n" @@ -1249,7 +1246,6 @@ SetVPNClient(){ return 0 else printf "\\n" - Print_Output false "VPN client selection cancelled" "$WARN" return 1 fi } @@ -1264,22 +1260,22 @@ SetVPNParameters(){ choosecountry="" choosecity="" countryname="" - countryid="0" + countryid=0 cityname="" - cityid="0" + cityid=0 while true; do - printf "\\n\\e[1mPlease enter the VPN client number (1-5):\\e[0m " + printf "\\n${BOLD}Please enter the VPN client number (pick from list):${CLEARFORMAT} " read -r vpn_choice if [ "$vpn_choice" = "e" ]; then exitmenu="exit" break - elif ! Validate_Number "" "$vpn_choice" silent; then - printf "\\n\\e[31mPlease enter a valid number (1-5)\\e[0m\\n" + elif ! Validate_Number "$vpn_choice"; then + printf "\\n\\e[31mPlease enter a valid number (pick from list)${CLEARFORMAT}\\n" else if [ "$vpn_choice" -lt 1 ] || [ "$vpn_choice" -gt 5 ]; then - printf "\\n\\e[31mPlease enter a number between 1 and 5\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 1 and 5${CLEARFORMAT}\\n" else vpnnum="$vpn_choice" printf "\\n" @@ -1289,12 +1285,16 @@ SetVPNParameters(){ done if [ "$exitmenu" != "exit" ]; then + if [ "$(grep "vpn${vpnnum}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + Print_Output false "VPN client $vpnnum is not managed" "$ERR" + return 1 + fi while true; do - printf "\\n\\e[1mPlease select a VPN provider:\\e[0m\\n" + printf "\\n${BOLD}Please select a VPN provider:${CLEARFORMAT}\\n" printf " 1. NordVPN\\n" printf " 2. Private Internet Access (PIA)\\n" printf " 3. WeVPN\\n\\n" - printf "Choose an option: " + printf "Choose an option: " read -r provmenu case "$provmenu" in @@ -1318,7 +1318,7 @@ SetVPNParameters(){ break ;; *) - printf "\\n\\e[31mPlease enter a valid choice (1-2)\\e[0m\\n" + printf "\\n\\e[31mPlease enter a valid choice (1-2)${CLEARFORMAT}\\n" ;; esac done @@ -1327,11 +1327,11 @@ SetVPNParameters(){ if [ "$exitmenu" != "exit" ]; then if [ "$vpnprovider" = "NordVPN" ]; then while true; do - printf "\\n\\e[1mPlease select a VPN Type:\\e[0m\\n" + printf "\\n${BOLD}Please select a VPN Type:${CLEARFORMAT}\\n" printf " 1. Standard\\n" printf " 2. Double\\n" printf " 3. P2P\\n\\n" - printf "Choose an option: " + printf "Choose an option: " read -r typemenu case "$typemenu" in @@ -1355,16 +1355,16 @@ SetVPNParameters(){ break ;; *) - printf "\\n\\e[31mPlease enter a valid choice (1-3)\\e[0m\\n" + printf "\\n\\e[31mPlease enter a valid choice (1-3)${CLEARFORMAT}\\n" ;; esac done elif [ "$vpnprovider" = "PIA" ]; then while true; do - printf "\\n\\e[1mPlease select a VPN Type:\\e[0m\\n" + printf "\\n${BOLD}Please select a VPN Type:${CLEARFORMAT}\\n" printf " 1. Standard\\n" printf " 2. Strong\\n\\n" - printf "Choose an option: " + printf "Choose an option: " read -r typemenu case "$typemenu" in @@ -1383,7 +1383,7 @@ SetVPNParameters(){ break ;; *) - printf "\\n\\e[31mPlease enter a valid choice (1-3)\\e[0m\\n" + printf "\\n\\e[31mPlease enter a valid choice (1-3)${CLEARFORMAT}\\n" ;; esac done @@ -1394,10 +1394,10 @@ SetVPNParameters(){ if [ "$exitmenu" != "exit" ]; then while true; do - printf "\\n\\e[1mPlease select a VPN protocol:\\e[0m\\n" + printf "\\n${BOLD}Please select a VPN protocol:${CLEARFORMAT}\\n" printf " 1. UDP\\n" printf " 2. TCP\\n\\n" - printf "Choose an option: " + printf "Choose an option: " read -r protmenu case "$protmenu" in @@ -1416,7 +1416,7 @@ SetVPNParameters(){ break ;; *) - printf "\\n\\e[31mPlease enter a valid choice (1-2)\\e[0m\\n" + printf "\\n\\e[31mPlease enter a valid choice (1-2)${CLEARFORMAT}\\n" ;; esac done @@ -1425,7 +1425,7 @@ SetVPNParameters(){ if [ "$exitmenu" != "exit" ]; then if [ "$vpnprovider" = "NordVPN" ]; then while true; do - printf "\\n\\e[1mWould you like to select a country (y/n)?\\e[0m " + printf "\\n${BOLD}Would you like to select a country (y/n)?${CLEARFORMAT} " read -r country_select if [ "$country_select" = "e" ]; then @@ -1438,7 +1438,7 @@ SetVPNParameters(){ choosecountry="true" break else - printf "\\n\\e[31mPlease enter y or n\\e[0m\\n" + printf "\\n\\e[31mPlease enter y or n${CLEARFORMAT}\\n" fi done elif [ "$vpnprovider" = "PIA" ] || [ "$vpnprovider" = "WeVPN" ]; then @@ -1463,8 +1463,8 @@ SetVPNParameters(){ fi COUNTCOUNTRIES="$(echo "$LISTCOUNTRIES" | wc -l)" while true; do - printf "\\n\\e[1mPlease select a country:\\e[0m\\n" - COUNTER="1" + printf "\\n${BOLD}Please select a country:${CLEARFORMAT}\\n" + COUNTER=1 IFS=$'\n' for COUNTRY in $LISTCOUNTRIES; do printf " %s. %s\\n" "$COUNTER" "$COUNTRY" >> /tmp/vpnmgr_countrylist @@ -1474,17 +1474,17 @@ SetVPNParameters(){ rm -f /tmp/vpnmgr_countrylist unset IFS - printf "\\nChoose an option: " + printf "\\nChoose an option: " read -r country_choice if [ "$country_choice" = "e" ]; then exitmenu="exit" break - elif ! Validate_Number "" "$country_choice" silent; then - printf "\\n\\e[31mPlease enter a valid number (1-%s)\\e[0m\\n" "$COUNTCOUNTRIES" + elif ! Validate_Number "$country_choice"; then + printf "\\n\\e[31mPlease enter a valid number (1-%s)${CLEARFORMAT}\\n" "$COUNTCOUNTRIES" else if [ "$country_choice" -lt 1 ] || [ "$country_choice" -gt "$COUNTCOUNTRIES" ]; then - printf "\\n\\e[31mPlease enter a number between 1 and %s\\e[0m\\n" "$COUNTCOUNTRIES" + printf "\\n\\e[31mPlease enter a number between 1 and %s${CLEARFORMAT}\\n" "$COUNTCOUNTRIES" else countryname="$(echo "$LISTCOUNTRIES" | sed -n "$country_choice"p)" if [ "$vpnprovider" = "NordVPN" ]; then @@ -1522,7 +1522,7 @@ SetVPNParameters(){ elif [ "$citycount" -gt 1 ]; then if [ "$vpnprovider" = "NordVPN" ]; then while true; do - printf "\\n\\e[1mWould you like to select a city (y/n)?\\e[0m " + printf "\\n${BOLD}Would you like to select a city (y/n)?${CLEARFORMAT} " read -r city_select if [ "$city_select" = "e" ]; then @@ -1535,7 +1535,7 @@ SetVPNParameters(){ choosecity="true" break else - printf "\\n\\e[31mPlease enter y or n\\e[0m\\n" + printf "\\n\\e[31mPlease enter y or n${CLEARFORMAT}\\n" fi done elif [ "$vpnprovider" = "PIA" ] || [ "$vpnprovider" = "WeVPN" ]; then @@ -1559,8 +1559,8 @@ SetVPNParameters(){ COUNTCITIES="$(echo "$LISTCITIES" | wc -l)" while true; do - printf "\\n\\e[1mPlease select a city:\\e[0m\\n" - COUNTER="1" + printf "\\n${BOLD}Please select a city:${CLEARFORMAT}\\n" + COUNTER=1 IFS=$'\n' for CITY in $LISTCITIES; do printf " %s. %s\\n" "$COUNTER" "$CITY" @@ -1568,17 +1568,17 @@ SetVPNParameters(){ done unset IFS - printf "\\nChoose an option: " + printf "\\nChoose an option: " read -r city_choice if [ "$city_choice" = "e" ]; then exitmenu="exit" break - elif ! Validate_Number "" "$city_choice" silent; then - printf "\\n\\e[31mPlease enter a valid number (1-%s)\\e[0m\\n" "$COUNTCITIES" + elif ! Validate_Number "$city_choice"; then + printf "\\n\\e[31mPlease enter a valid number (1-%s)${CLEARFORMAT}\\n" "$COUNTCITIES" else if [ "$city_choice" -lt 1 ] || [ "$city_choice" -gt "$COUNTCITIES" ]; then - printf "\\n\\e[31mPlease enter a number between 1 and %s\\e[0m\\n" "$COUNTCITIES" + printf "\\n\\e[31mPlease enter a number between 1 and %s${CLEARFORMAT}\\n" "$COUNTCITIES" else cityname="$(echo "$LISTCITIES" | sed -n "$city_choice"p)" if [ "$vpnprovider" = "NordVPN" ]; then @@ -1612,21 +1612,22 @@ SetScheduleParameters(){ vpnnum="" formattype="" crudays="" + crudaysvalidated="" cruhours="" crumins="" while true; do - printf "\\n\\e[1mPlease enter the VPN client number (1-5):\\e[0m " + printf "\\n${BOLD}Please enter the VPN client number (pick from list):${CLEARFORMAT} " read -r vpn_choice if [ "$vpn_choice" = "e" ]; then exitmenu="exit" break - elif ! Validate_Number "" "$vpn_choice" silent; then - printf "\\n\\e[31mPlease enter a valid number (1-5)\\e[0m\\n" + elif ! Validate_Number "$vpn_choice"; then + printf "\\n\\e[31mPlease enter a valid number (pick from list)${CLEARFORMAT}\\n" else if [ "$vpn_choice" -lt 1 ] || [ "$vpn_choice" -gt 5 ]; then - printf "\\n\\e[31mPlease enter a number between 1 and 5\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 1 and 5${CLEARFORMAT}\\n" else vpnnum="$vpn_choice" printf "\\n" @@ -1641,7 +1642,7 @@ SetScheduleParameters(){ return 1 fi while true; do - printf "\\n\\e[1mPlease choose which day(s) to update VPN configuration (0-6, * for every day, or comma separated days):\\e[0m " + printf "\\n${BOLD}Please choose which day(s) to update VPN configuration (0-6, * for every day, or comma separated days):${CLEARFORMAT} " read -r day_choice if [ "$day_choice" = "e" ]; then @@ -1652,18 +1653,18 @@ SetScheduleParameters(){ printf "\\n" break elif [ -z "$day_choice" ]; then - printf "\\n\\e[31mPlease enter a valid number (0-6) or comma separated values\\e[0m\\n" + printf "\\n\\e[31mPlease enter a valid number (0-6) or comma separated values${CLEARFORMAT}\\n" else crudaystmp="$(echo "$day_choice" | sed "s/,/ /g")" crudaysvalidated="true" for i in $crudaystmp; do - if ! Validate_Number "" "$i" silent; then - printf "\\n\\e[31mPlease enter a valid number (0-6) or comma separated values\\e[0m\\n" + if ! Validate_Number "$i"; then + printf "\\n\\e[31mPlease enter a valid number (0-6) or comma separated values${CLEARFORMAT}\\n" crudaysvalidated="false" break else if [ "$i" -lt 0 ] || [ "$i" -gt 6 ]; then - printf "\\n\\e[31mPlease enter a number between 0 and 6 or comma separated values\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 0 and 6 or comma separated values${CLEARFORMAT}\\n" crudaysvalidated="false" break fi @@ -1680,10 +1681,10 @@ SetScheduleParameters(){ if [ "$exitmenu" != "exit" ]; then while true; do - printf "\\n\\e[1mPlease choose the format to specify the hour/minute(s) to update VPN configuration:\\e[0m\\n" + printf "\\n${BOLD}Please choose the format to specify the hour/minute(s) to update VPN configuration:${CLEARFORMAT}\\n" printf " 1. Every X hours/minutes\\n" printf " 2. Custom\\n\\n" - printf "Choose an option: " + printf "Choose an option: " read -r formatmenu case "$formatmenu" in @@ -1702,7 +1703,7 @@ SetScheduleParameters(){ break ;; *) - printf "\\n\\e[31mPlease enter a valid choice (1-2)\\e[0m\\n" + printf "\\n\\e[31mPlease enter a valid choice (1-2)${CLEARFORMAT}\\n" ;; esac done @@ -1711,10 +1712,10 @@ SetScheduleParameters(){ if [ "$exitmenu" != "exit" ]; then if [ "$formattype" = "everyx" ]; then while true; do - printf "\\n\\e[1mPlease choose whether to specify every X hours or every X minutes to update VPN configuration:\\e[0m\\n" + printf "\\n${BOLD}Please choose whether to specify every X hours or every X minutes to update VPN configuration:${CLEARFORMAT}\\n" printf " 1. Hours\\n" printf " 2. Minutes\\n\\n" - printf "Choose an option: " + printf "Choose an option: " read -r formatmenu case "$formatmenu" in @@ -1733,7 +1734,7 @@ SetScheduleParameters(){ break ;; *) - printf "\\n\\e[31mPlease enter a valid choice (1-2)\\e[0m\\n" + printf "\\n\\e[31mPlease enter a valid choice (1-2)${CLEARFORMAT}\\n" ;; esac done @@ -1743,25 +1744,25 @@ SetScheduleParameters(){ if [ "$exitmenu" != "exit" ]; then if [ "$formattype" = "hours" ]; then while true; do - printf "\\n\\e[1mPlease choose how often to update VPN configuration (every X hours, where X is 1-24):\\e[0m " + printf "\\n${BOLD}Please choose how often to update VPN configuration (every X hours, where X is 1-24):${CLEARFORMAT} " read -r hour_choice if [ "$hour_choice" = "e" ]; then exitmenu="exit" break - elif ! Validate_Number "" "$hour_choice" silent; then - printf "\\n\\e[31mPlease enter a valid number (1-24)\\e[0m\\n" + elif ! Validate_Number "$hour_choice"; then + printf "\\n\\e[31mPlease enter a valid number (1-24)${CLEARFORMAT}\\n" elif [ "$hour_choice" -lt 1 ] || [ "$hour_choice" -gt 24 ]; then - printf "\\n\\e[31mPlease enter a number between 1 and 24\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 1 and 24${CLEARFORMAT}\\n" else if [ "$hour_choice" -eq 24 ]; then - cruhours="0" - crumins="0" + cruhours=0 + crumins=0 printf "\\n" break else cruhours="*/$hour_choice" - crumins="0" + crumins=0 printf "\\n" break fi @@ -1769,16 +1770,16 @@ SetScheduleParameters(){ done elif [ "$formattype" = "mins" ]; then while true; do - printf "\\n\\e[1mPlease choose how often to update VPN configuration (every X minutes, where X is 1-30):\\e[0m " + printf "\\n${BOLD}Please choose how often to update VPN configuration (every X minutes, where X is 1-30):${CLEARFORMAT} " read -r min_choice if [ "$min_choice" = "e" ]; then exitmenu="exit" break - elif ! Validate_Number "" "$min_choice" silent; then - printf "\\n\\e[31mPlease enter a valid number (1-30)\\e[0m\\n" + elif ! Validate_Number "$min_choice"; then + printf "\\n\\e[31mPlease enter a valid number (1-30)${CLEARFORMAT}\\n" elif [ "$min_choice" -lt 1 ] || [ "$min_choice" -gt 30 ]; then - printf "\\n\\e[31mPlease enter a number between 1 and 30\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 1 and 30${CLEARFORMAT}\\n" else crumins="*/$min_choice" cruhours="*" @@ -1792,7 +1793,7 @@ SetScheduleParameters(){ if [ "$exitmenu" != "exit" ]; then if [ "$formattype" = "custom" ]; then while true; do - printf "\\n\\e[1mPlease choose which hour(s) to update VPN configuration (0-23, * for every hour, or comma separated hours):\\e[0m " + printf "\\n${BOLD}Please choose which hour(s) to update VPN configuration (0-23, * for every hour, or comma separated hours):${CLEARFORMAT} " read -r hour_choice if [ "$hour_choice" = "e" ]; then @@ -1806,13 +1807,13 @@ SetScheduleParameters(){ cruhourstmp="$(echo "$hour_choice" | sed "s/,/ /g")" cruhoursvalidated="true" for i in $cruhourstmp; do - if ! Validate_Number "" "$i" silent; then - printf "\\n\\e[31mPlease enter a valid number (0-23) or comma separated values\\e[0m\\n" + if ! Validate_Number "$i"; then + printf "\\n\\e[31mPlease enter a valid number (0-23) or comma separated values${CLEARFORMAT}\\n" cruhoursvalidated="false" break else if [ "$i" -lt 0 ] || [ "$i" -gt 23 ]; then - printf "\\n\\e[31mPlease enter a number between 0 and 23 or comma separated values\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 0 and 23 or comma separated values${CLEARFORMAT}\\n" cruhoursvalidated="false" break fi @@ -1831,7 +1832,7 @@ SetScheduleParameters(){ if [ "$exitmenu" != "exit" ]; then if [ "$formattype" = "custom" ]; then while true; do - printf "\\n\\e[1mPlease choose which minutes(s) to update VPN configuration (0-59, * for every minute, or comma separated minutes):\\e[0m " + printf "\\n${BOLD}Please choose which minutes(s) to update VPN configuration (0-59, * for every minute, or comma separated minutes):${CLEARFORMAT} " read -r min_choice if [ "$min_choice" = "e" ]; then @@ -1845,13 +1846,13 @@ SetScheduleParameters(){ cruminstmp="$(echo "$min_choice" | sed "s/,/ /g")" cruminsvalidated="true" for i in $cruminstmp; do - if ! Validate_Number "" "$i" silent; then - printf "\\n\\e[31mPlease enter a valid number (0-59) or comma separated values\\e[0m\\n" + if ! Validate_Number "$i"; then + printf "\\n\\e[31mPlease enter a valid number (0-59) or comma separated values${CLEARFORMAT}\\n" cruminsvalidated="false" break else if [ "$i" -lt 0 ] || [ "$i" -gt 59 ]; then - printf "\\n\\e[31mPlease enter a number between 0 and 59 or comma separated values\\e[0m\\n" + printf "\\n\\e[31mPlease enter a number between 0 and 59 or comma separated values${CLEARFORMAT}\\n" cruminsvalidated="false" break fi @@ -1878,6 +1879,59 @@ SetScheduleParameters(){ fi } +SetVPNCustomSettings(){ + VPN_NO="$1" + vpncustomoptions='remote-random +resolv-retry infinite +remote-cert-tls server +ping 15 +ping-restart 0 +ping-timer-rem +persist-key +persist-tun +reneg-sec 0 +fast-io +disable-occ +mute-replay-warnings +auth-nocache +sndbuf 524288 +rcvbuf 524288 +push "sndbuf 524288" +push "rcvbuf 524288" +pull-filter ignore "auth-token" +pull-filter ignore "ifconfig-ipv6" +pull-filter ignore "route-ipv6"' + + if [ "$VPN_PROT_SHORT" = "UDP" ]; then + vpncustomoptions="$vpncustomoptions +explicit-exit-notify 3" + fi + + if [ "$VPN_PROVIDER" = "NordVPN" ]; then + vpncustomoptions="$vpncustomoptions +tun-mtu 1500 +tun-mtu-extra 32 +mssfix 1450" + fi + + if [ "$(Firmware_Number_Check "$(nvram get buildno)")" -lt "$(Firmware_Number_Check 386.3)" ]; then + vpncustomoptionsbase64="$(echo "$vpncustomoptions" | head -c -1 | openssl base64 -A)" + + if [ "$(/bin/uname -m)" = "aarch64" ]; then + nvram set vpn_client"$VPN_NO"_cust2="$(echo "$vpncustomoptionsbase64" | cut -c0-255)" + nvram set vpn_client"$VPN_NO"_cust21="$(echo "$vpncustomoptionsbase64" | cut -c256-510)" + nvram set vpn_client"$VPN_NO"_cust22="$(echo "$vpncustomoptionsbase64" | cut -c511-765)" + elif [ "$(uname -o)" = "ASUSWRT-Merlin" ]; then + nvram set vpn_client"$VPN_NO"_cust2="$vpncustomoptionsbase64" + else + nvram set vpn_client"$VPN_NO"_custom="$vpncustomoptions" + fi + nvram commit + else + printf "%s" "$vpncustomoptions" > /jffs/openvpn/vpn_client"$VPN_NO"_custom3 + fi +} + PressEnter(){ while true; do printf "Press enter to continue..." @@ -1894,61 +1948,63 @@ PressEnter(){ ScriptHeader(){ clear printf "\\n" - printf "\\e[1m###################################################\\e[0m\\n" - printf "\\e[1m## ##\\e[0m\\n" - printf "\\e[1m## __ __ _ __ _ __ _ __ ___ __ _ _ __ ##\\e[0m\\n" - printf "\\e[1m## \ \ / /| '_ \ | '_ \ | '_ _ \ / _ || '__| ##\\e[0m\\n" - printf "\\e[1m## \ V / | |_) || | | || | | | | || (_| || | ##\\e[0m\\n" - printf "\\e[1m## \_/ | .__/ |_| |_||_| |_| |_| \__, ||_| ##\\e[0m\\n" - printf "\\e[1m## | | __/ | ##\\e[0m\\n" - printf "\\e[1m## |_| |___/ ##\\e[0m\\n" - printf "\\e[1m## ##\\e[0m\\n" - printf "\\e[1m## %s on %-9s ##\\e[0m\\n" "$SCRIPT_VERSION" "$ROUTER_MODEL" - printf "\\e[1m## ##\\e[0m\\n" - printf "\\e[1m## https://github.com/jackyaz/vpnmgr ##\\e[0m\\n" - printf "\\e[1m## ##\\e[0m\\n" - printf "\\e[1m###################################################\\e[0m\\n" + printf "${BOLD}#######################################################${CLEARFORMAT}\\n" + printf "${BOLD}## ##${CLEARFORMAT}\\n" + printf "${BOLD}## __ __ _ __ _ __ _ __ ___ __ _ _ __ ##${CLEARFORMAT}\\n" + printf "${BOLD}## \ \ / /| '_ \ | '_ \ | '_ _ \ / _ || '__| ##${CLEARFORMAT}\\n" + printf "${BOLD}## \ V / | |_) || | | || | | | | || (_| || | ##${CLEARFORMAT}\\n" + printf "${BOLD}## \_/ | .__/ |_| |_||_| |_| |_| \__, ||_| ##${CLEARFORMAT}\\n" + printf "${BOLD}## | | __/ | ##${CLEARFORMAT}\\n" + printf "${BOLD}## |_| |___/ ##${CLEARFORMAT}\\n" + printf "${BOLD}## ##${CLEARFORMAT}\\n" + printf "${BOLD}## %s on %-11s ##${CLEARFORMAT}\\n" "$SCRIPT_VERSION" "$ROUTER_MODEL" + printf "${BOLD}## ##${CLEARFORMAT}\\n" + printf "${BOLD}## https://github.com/jackyaz/vpnmgr ##${CLEARFORMAT}\\n" + printf "${BOLD}## ##${CLEARFORMAT}\\n" + printf "${BOLD}#######################################################${CLEARFORMAT}\\n" printf "\\n" } MainMenu(){ + printf "WebUI for %s is available at:\\n${SETTING}%s${CLEARFORMAT}\\n\\n" "$SCRIPT_NAME" "$(Get_WebUI_URL)" printf "1. List VPN client configurations\\n" printf "1l. List NordVPN clients with server load percentages\\n\\n" printf "2. Update configuration for a managed VPN client\\n\\n" - printf "3. Enable management for a VPN client\\n" - printf "4. Disable management for a VPN client\\n\\n" - printf "5. Search for new recommended server/reload server\\n" - printf "6. Update schedule for a VPN client\\n" - printf "7. Enable a scheduled VPN client update/reload\\n" - printf "8. Delete a scheduled VPN client update/reload\\n\\n" + printf "3. Toggle management for a VPN client\\n\\n" + printf "4. Search for new recommended server/reload server\\n\\n" + printf "5. Toggle scheduled VPN client update/reload\\n" + printf "6. Update schedule for a VPN client\\n\\n" + printf "7. Toggle %s custom settings for a VPN client\\n\\n" "$SCRIPT_NAME" printf "r. Refresh cached data from VPN providers\\n\\n" printf "u. Check for updates\\n" printf "uf. Update %s with latest version (force)\\n\\n" "$SCRIPT_NAME" printf "e. Exit %s\\n\\n" "$SCRIPT_NAME" printf "z. Uninstall %s\\n" "$SCRIPT_NAME" printf "\\n" - printf "\\e[1m###################################################\\e[0m\\n" + printf "${BOLD}###################################################${CLEARFORMAT}\\n" printf "\\n" while true; do - printf "Choose an option: " + printf "Choose an option: " read -r menu case "$menu" in 1) printf "\\n" - Menu_ListVPN + ScriptHeader + ListVPNClients false show PressEnter break ;; 1l) printf "\\n" - Menu_ListVPN_WithLoad + ScriptHeader + ListVPNClients true show PressEnter break ;; 2) printf "\\n" - if Check_Lock "menu"; then + if Check_Lock menu; then Menu_UpdateVPN fi PressEnter @@ -1956,20 +2012,43 @@ MainMenu(){ ;; 3) printf "\\n" - Menu_ManageVPN + if SetVPNClient show; then + if [ "$(grep "vpn${GLOBAL_VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + ManageVPN "$GLOBAL_VPN_NO" + else + UnmanageVPN "$GLOBAL_VPN_NO" + fi + fi PressEnter break ;; 4) printf "\\n" - Menu_UnmanageVPN + if Check_Lock menu; then + if SetVPNClient hide; then + if [ "$(grep "vpn${GLOBAL_VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + Print_Output false "VPN client $GLOBAL_VPN_NO is not managed, cannot search for new server" "$ERR" + break + fi + UpdateVPNConfig unattended "$GLOBAL_VPN_NO" + fi + Clear_Lock + fi PressEnter break ;; 5) printf "\\n" - if Check_Lock "menu"; then - Menu_SearchVPN + if SetVPNClient hide; then + if [ "$(grep "vpn${GLOBAL_VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + Print_Output false "VPN client $GLOBAL_VPN_NO is not managed, cannot enable schedule" "$ERR" + break + fi + if [ "$(grep "vpn${GLOBAL_VPN_NO}_schenabled" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + ScheduleVPN "$GLOBAL_VPN_NO" + else + CancelScheduleVPN "$GLOBAL_VPN_NO" + fi fi PressEnter break @@ -1982,13 +2061,18 @@ MainMenu(){ ;; 7) printf "\\n" - Menu_EnableScheduleVPN - PressEnter - break - ;; - 8) - printf "\\n" - Menu_CancelScheduleVPN + if SetVPNClient hide; then + if [ "$(grep "vpn${GLOBAL_VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + Print_Output false "VPN client $GLOBAL_VPN_NO is not managed, cannot apply custom settings" "$ERR" + break + fi + if [ "$(grep "vpn${GLOBAL_VPN_NO}_customsettings" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then + sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_customsettings.*$/vpn'"$GLOBAL_VPN_NO"'_customsettings=true/' "$SCRIPT_CONF" + SetVPNCustomSettings "$GLOBAL_VPN_NO" + else + sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_customsettings.*$/vpn'"$GLOBAL_VPN_NO"'_customsettings=false/' "$SCRIPT_CONF" + fi + fi PressEnter break ;; @@ -2001,28 +2085,30 @@ MainMenu(){ ;; u) printf "\\n" - if Check_Lock "menu"; then - Menu_Update + if Check_Lock menu; then + Update_Version + Clear_Lock fi PressEnter break ;; uf) printf "\\n" - if Check_Lock "menu"; then - Menu_ForceUpdate + if Check_Lock menu; then + Update_Version force + Clear_Lock fi PressEnter break ;; e) ScriptHeader - printf "\\n\\e[1mThanks for using %s!\\e[0m\\n\\n\\n" "$SCRIPT_NAME" + printf "\\n${BOLD}Thanks for using %s!${CLEARFORMAT}\\n\\n\\n" "$SCRIPT_NAME" exit 0 ;; z) while true; do - printf "\\n\\e[1mAre you sure you want to uninstall %s? (y/n)\\e[0m\\n" "$SCRIPT_NAME" + printf "\\n${BOLD}Are you sure you want to uninstall %s? (y/n)${CLEARFORMAT} " "$SCRIPT_NAME" read -r confirm case "$confirm" in y|Y) @@ -2045,27 +2131,17 @@ MainMenu(){ MainMenu } -Menu_ListVPN(){ - ScriptHeader - ListVPNClients "false" -} - -Menu_ListVPN_WithLoad(){ - ScriptHeader - ListVPNClients "true" -} - Menu_UpdateVPN(){ ScriptHeader - ListVPNClients "false" + ListVPNClients false hide printf "Choose options as follows:\\n" - printf " - VPN client [1-5]\\n" + printf " - VPN client (pick from list)\\n" printf " - VPN provider (pick from list)\\n" printf " - type of VPN (pick from list)\\n" printf " - protocol (pick from list)\\n" printf " - country/city of VPN Server (pick from list)\\n" printf "\\n" - printf "\\e[1m#########################################################\\e[0m\\n" + printf "${BOLD}#########################################################${CLEARFORMAT}\\n" if SetVPNParameters; then VPN_PROT_SHORT="$(echo "$GLOBAL_VPN_PROT" | cut -f2 -d'_' | tr "a-z" "A-Z")" @@ -2076,7 +2152,6 @@ Menu_UpdateVPN(){ VPN_TYPE_SHORT="$(echo "$VPN_TYPE_SHORT" | awk '{print toupper(substr($0,0,1))tolower(substr($0,2))}')" fi - sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_managed.*$/vpn'"$GLOBAL_VPN_NO"'_managed=true/' "$SCRIPT_CONF" sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_provider.*$/vpn'"$GLOBAL_VPN_NO"'_provider='"$GLOBAL_VPN_PROVIDER"'/' "$SCRIPT_CONF" sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_type.*$/vpn'"$GLOBAL_VPN_NO"'_type='"$VPN_TYPE_SHORT"'/' "$SCRIPT_CONF" sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_protocol.*$/vpn'"$GLOBAL_VPN_NO"'_protocol='"$VPN_PROT_SHORT"'/' "$SCRIPT_CONF" @@ -2085,94 +2160,27 @@ Menu_UpdateVPN(){ sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_cityname.*$/vpn'"$GLOBAL_VPN_NO"'_cityname='"$GLOBAL_CITY_NAME"'/' "$SCRIPT_CONF" sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_cityid.*$/vpn'"$GLOBAL_VPN_NO"'_cityid='"$GLOBAL_CTIY_ID"'/' "$SCRIPT_CONF" UpdateVPNConfig "$GLOBAL_VPN_NO" - else - printf "\\n" - Print_Output false "VPN client update cancelled" "$WARN" - fi - Clear_Lock -} - -Menu_SearchVPN(){ - if SetVPNClient; then - if [ "$(grep "vpn${GLOBAL_VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then - Print_Output false "VPN client $GLOBAL_VPN_NO is not managed, cannot search for new server" "$ERR" - return 1 - fi - UpdateVPNConfig unattended "$GLOBAL_VPN_NO" - else - printf "\\n" - Print_Output false "VPN server search cancelled" "$WARN" fi Clear_Lock } -Menu_ManageVPN(){ - if SetVPNClient; then - ManageVPN "$GLOBAL_VPN_NO" - else - printf "\\n" - Print_Output false "VPN client management enabling cancelled" "$WARN" - fi -} - -Menu_UnmanageVPN(){ - if SetVPNClient; then - UnmanageVPN "$GLOBAL_VPN_NO" - else - printf "\\n" - Print_Output false "VPN client management removal cancelled" "$WARN" - fi -} - Menu_ScheduleVPN(){ ScriptHeader - ListVPNClients "false" + ListVPNClients false hide printf "Choose options as follows:\\n" - printf " - VPN client [1-5]\\n" + printf " - VPN client (pick from list)\\n" printf " - day(s) to update [0-6]\\n" printf " - hour(s) to update [0-23]\\n" printf " - minute(s) to update [0-59]\\n" printf "\\n" - printf "\\e[1m#########################################################\\e[0m\\n" + printf "${BOLD}#########################################################${CLEARFORMAT}\\n" if SetScheduleParameters; then - sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_managed.*$/vpn'"$GLOBAL_VPN_NO"'_managed=true/' "$SCRIPT_CONF" sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_schenabled.*$/vpn'"$GLOBAL_VPN_NO"'_schenabled=true/' "$SCRIPT_CONF" sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_schdays.*$/vpn'"$GLOBAL_VPN_NO"'_schdays='"$(echo "$GLOBAL_CRU_DAYNUMBERS" | sed 's/0/Sun/;s/1/Mon/;s/2/Tues/;s/3/Wed/;s/4/Thurs/;s/5/Fri/;s/6/Sat/;')"'/' "$SCRIPT_CONF" sed -i 's~^vpn'"$GLOBAL_VPN_NO"'_schhours.*$~vpn'"$GLOBAL_VPN_NO"'_schhours='"$GLOBAL_CRU_HOURS"'~' "$SCRIPT_CONF" sed -i 's~^vpn'"$GLOBAL_VPN_NO"'_schmins.*$~vpn'"$GLOBAL_VPN_NO"'_schmins='"$GLOBAL_CRU_MINS"'~' "$SCRIPT_CONF" ScheduleVPN "$GLOBAL_VPN_NO" - else - printf "\\n" - Print_Output false "VPN client update scheduling cancelled" "$WARN" - fi -} - -Menu_EnableScheduleVPN(){ - if SetVPNClient; then - if [ "$(grep "vpn${GLOBAL_VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then - Print_Output false "VPN client $GLOBAL_VPN_NO is not managed, cannot enable schedule" "$ERR" - return 1 - fi - sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_managed.*$/vpn'"$GLOBAL_VPN_NO"'_managed=true/' "$SCRIPT_CONF" - sed -i 's/^vpn'"$GLOBAL_VPN_NO"'_schenabled.*$/vpn'"$GLOBAL_VPN_NO"'_schenabled=true/' "$SCRIPT_CONF" - ScheduleVPN "$GLOBAL_VPN_NO" - else - printf "\\n" - Print_Output false "VPN client schedule enabling cancelled" "$WARN" - fi -} - -Menu_CancelScheduleVPN(){ - if SetVPNClient; then - if [ "$(grep "vpn${GLOBAL_VPN_NO}_managed" "$SCRIPT_CONF" | cut -f2 -d"=")" = "false" ]; then - Print_Output false "VPN client $GLOBAL_VPN_NO is not managed, cannot cancel schedule" "$ERR" - return 1 - fi - CancelScheduleVPN "$GLOBAL_VPN_NO" - else - printf "\\n" - Print_Output false "VPN client schedule cancellation cancelled" "$WARN" fi } @@ -2186,18 +2194,18 @@ Check_Requirements(){ fi if [ ! -f /opt/bin/opkg ]; then - Print_Output true "Entware not detected!" "$ERR" + Print_Output false "Entware not detected!" "$ERR" CHECKSFAILED="true" fi if ! Firmware_Version_Check ; then - Print_Output true "Unsupported firmware version detected" "$ERR" - Print_Output true "$SCRIPT_NAME requires Merlin 384.15/384.13_4 or Fork 43E5 (or later)" "$ERR" + Print_Output false "Unsupported firmware version detected" "$ERR" + Print_Output false "$SCRIPT_NAME requires Merlin 384.15/384.13_4 or Fork 43E5 (or later)" "$ERR" CHECKSFAILED="true" fi if [ "$CHECKSFAILED" = "false" ]; then - Print_Output true "Installing required packages from Entware" "$PASS" + Print_Output false "Installing required packages from Entware" "$PASS" opkg update opkg install jq opkg install p7zip @@ -2209,13 +2217,14 @@ Check_Requirements(){ } Menu_Install(){ + ScriptHeader Print_Output true "Welcome to $SCRIPT_NAME $SCRIPT_VERSION, a script by h0me5k1n and JackYaz" sleep 1 - Print_Output true "Checking your router meets the requirements for $SCRIPT_NAME" + Print_Output false "Checking your router meets the requirements for $SCRIPT_NAME" if ! Check_Requirements; then - Print_Output true "Requirements for $SCRIPT_NAME not met, please see above for the reason(s)" "$CRIT" + Print_Output false "Requirements for $SCRIPT_NAME not met, please see above for the reason(s)" "$CRIT" PressEnter Clear_Lock rm -f "/jffs/scripts/$SCRIPT_NAME" 2>/dev/null @@ -2237,6 +2246,9 @@ Menu_Install(){ Shortcut_Script create Clear_Lock + + ScriptHeader + MainMenu } Menu_Startup(){ @@ -2262,7 +2274,8 @@ Menu_Startup(){ Create_Dirs Conf_Exists - Set_Version_Custom_Settings local + Set_Version_Custom_Settings local "$SCRIPT_VERSION" + Set_Version_Custom_Settings server "$SCRIPT_VERSION" Create_Symlinks Auto_Cron create 2>/dev/null Auto_Startup create 2>/dev/null @@ -2272,16 +2285,6 @@ Menu_Startup(){ Clear_Lock } -Menu_Update(){ - Update_Version - Clear_Lock -} - -Menu_ForceUpdate(){ - Update_Version force - Clear_Lock -} - Menu_Uninstall(){ Print_Output true "Removing $SCRIPT_NAME..." "$PASS" @@ -2289,6 +2292,25 @@ Menu_Uninstall(){ Auto_Startup delete 2>/dev/null Auto_ServiceEvent delete 2>/dev/null + LOCKFILE=/tmp/addonwebui.lock + FD=386 + eval exec "$FD>$LOCKFILE" + flock -x "$FD" + Get_WebUI_Page "$SCRIPT_DIR/vpnmgr_www.asp" + if [ -n "$MyPage" ] && [ "$MyPage" != "none" ] && [ -f /tmp/menuTree.js ]; then + sed -i "\\~$MyPage~d" /tmp/menuTree.js + umount /www/require/modules/menuTree.js + mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js + rm -f "$SCRIPT_WEBPAGE_DIR/$MyPage" + rm -f "$SCRIPT_WEBPAGE_DIR/$(echo $MyPage | cut -f1 -d'.').title" + fi + flock -u "$FD" + rm -f "$SCRIPT_DIR/vpnmgr_www.asp" 2>/dev/null + + SETTINGSFILE="/jffs/addons/custom_settings.txt" + sed -i '/vpnmgr_version_local/d' "$SETTINGSFILE" + sed -i '/vpnmgr_version_server/d' "$SETTINGSFILE" + rm -rf "$SCRIPT_WEB_DIR" 2>/dev/null rm -rf "$SCRIPT_DIR" 2>/dev/null @@ -2301,17 +2323,14 @@ Menu_Uninstall(){ NTP_Ready(){ if [ "$(nvram get ntp_ready)" -eq 0 ]; then - ntpwaitcount="0" - Check_Lock - while [ "$(nvram get ntp_ready)" -eq 0 ] && [ "$ntpwaitcount" -lt 300 ]; do - ntpwaitcount="$((ntpwaitcount + 1))" - if [ "$ntpwaitcount" -eq 60 ]; then - Print_Output true "Waiting for NTP to sync..." "$WARN" - fi - sleep 1 + ntpwaitcount=0 + while [ "$(nvram get ntp_ready)" -eq 0 ] && [ "$ntpwaitcount" -lt 600 ]; do + ntpwaitcount="$((ntpwaitcount + 30))" + Print_Output true "Waiting for NTP to sync..." "$WARN" + sleep 30 done - if [ "$ntpwaitcount" -ge 300 ]; then - Print_Output true "NTP failed to sync after 5 minutes. Please resolve!" "$CRIT" + if [ "$ntpwaitcount" -ge 600 ]; then + Print_Output true "NTP failed to sync after 10 minutes. Please resolve!" "$CRIT" Clear_Lock exit 1 else @@ -2343,17 +2362,56 @@ Entware_Ready(){ } ### ### +Show_About(){ + cat </dev/null Auto_Startup create 2>/dev/null Auto_ServiceEvent create 2>/dev/null @@ -2412,7 +2470,9 @@ case "$1" in done exit 0 elif [ "$2" = "start" ] && [ "$3" = "${SCRIPT_NAME}refreshcacheddata" ]; then + rm -f /tmp/detect_vpnmgr.js Check_Lock webui + sleep 3 echo 'var refreshcacheddatastatus = "InProgress";' > /tmp/detect_vpnmgr.js sleep 1 getCountryData @@ -2436,29 +2496,73 @@ case "$1" in Update_Check exit 0 elif [ "$2" = "start" ] && [ "$3" = "${SCRIPT_NAME}doupdate" ]; then - Update_Version force unattended + Update_Version force exit 0 fi exit 0 ;; - checkupdate) - Update_Check - exit 0 - ;; update) - Update_Version unattended + Update_Version exit 0 ;; forceupdate) - Update_Version force unattended + Update_Version force exit 0 ;; setversion) - Set_Version_Custom_Settings local + Set_Version_Custom_Settings local "$SCRIPT_VERSION" Set_Version_Custom_Settings server "$SCRIPT_VERSION" - if [ -z "$2" ]; then - exec "$0" + if [ ! -f /opt/bin/7za ]; then + opkg update + opkg install p7zip + opkg install column + fi + Create_Dirs + Conf_Exists + Auto_Cron create 2>/dev/null + Auto_Startup create 2>/dev/null + Auto_ServiceEvent create 2>/dev/null + Shortcut_Script create + if [ ! -f "$SCRIPT_DIR/nordvpn_countrydata" ]; then + getCountryData + fi + if [ "$(/usr/bin/find "$OVPN_ARCHIVE_DIR" -name "*.zip" | wc -l)" -lt 4 ]; then + getOVPNArchives fi + + Create_Symlinks + exit 0 + ;; + postupdate) + if [ ! -f /opt/bin/7za ]; then + opkg update + opkg install p7zip + opkg install column + fi + Create_Dirs + Conf_Exists + Auto_Cron create 2>/dev/null + Auto_Startup create 2>/dev/null + Auto_ServiceEvent create 2>/dev/null + Shortcut_Script create + if [ ! -f "$SCRIPT_DIR/nordvpn_countrydata" ]; then + getCountryData + fi + if [ "$(/usr/bin/find "$OVPN_ARCHIVE_DIR" -name "*.zip" | wc -l)" -lt 4 ]; then + getOVPNArchives + fi + + Create_Symlinks + exit 0 + ;; + about) + ScriptHeader + Show_About + exit 0 + ;; + help) + ScriptHeader + Show_Help exit 0 ;; develop) @@ -2478,7 +2582,9 @@ case "$1" in exit 0 ;; *) - echo "Command not recognised, please try again" + ScriptHeader + Print_Output false "Command not recognised." "$ERR" + Print_Output false "For a list of available commands run: $SCRIPT_NAME help" exit 1 ;; esac diff --git a/vpnmgr_www.asp b/vpnmgr_www.asp index d6dcc3e..be2cb13 100644 --- a/vpnmgr_www.asp +++ b/vpnmgr_www.asp @@ -11,92 +11,7 @@ @@ -121,7 +36,7 @@ function LoadCustomSettings(){ } } } -var refreshcacheddatainterval,getserverloadinterval,$j=jQuery.noConflict(),daysofweek=["Mon","Tues","Wed","Thurs","Fri","Sat","Sun"],nordvpncountries=[],piacountries=[],wevpncountries=[];function SettingHint(a){for(var b=document.getElementsByTagName("a"),c=0;cvpnno;vpnno++){if("all"!=vpnclient&&vpnno!=vpnclient)continue;let dropdown=$j("#vpnmgr_vpn"+vpnno+"_countryname");dropdown.empty();var countryarray=[];"NordVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?(dropdown.append(""),dropdown.prop("selectedIndex",0),countryarray=nordvpncountries):"PIA"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?countryarray=piacountries:"WeVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value&&(countryarray=wevpncountries),$j.each(countryarray,function(a,b){dropdown.append($j("").attr("value",b.name).text(b.name))})}}function PopulateCityDropdown(vpnclient){for(var vpnno=1;6>vpnno;vpnno++){if("all"!=vpnclient&&vpnno!=vpnclient)continue;let dropdown=$j("#vpnmgr_vpn"+vpnno+"_cityname");dropdown.empty(),"NordVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?(dropdown.append(""),dropdown.prop("selectedIndex",0),cityarray=nordvpncountries):"PIA"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?cityarray=piacountries:"WeVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value&&(cityarray=wevpncountries),$j.each(cityarray,function(key,entry){return entry.name!=eval("document.form.vpnmgr_vpn"+vpnno+"_countryname").value||($j.each(entry.cities,function(a,b){dropdown.append($j("").attr("value",b.name).text(b.name))}),!1)})}}function ScheduleModeToggle(a){var b=a.name,c=a.value,d=b.substring(0,b.lastIndexOf("_"));"EveryX"==c?(showhide(d+"_schedulefrequency",!0),showhide(d+"_customhours",!1),showhide(d+"_custommins",!1),"hours"==$j("#"+d+"_everyxselect").val()?(showhide(d+"_spanxhours",!0),showhide(d+"_spanxminutes",!1)):"minutes"==$j("#"+d+"_everyxselect").val()&&(showhide(d+"_spanxhours",!1),showhide(d+"_spanxminutes",!0))):"Custom"==c&&(showhide(d+"_schedulefrequency",!1),showhide(d+"_customhours",!0),showhide(d+"_custommins",!0))}function EveryXToggle(a){var b=a.name,c=a.value,d=b.substring(0,b.lastIndexOf("_"));"hours"==c?(showhide(d+"_spanxhours",!0),showhide(d+"_spanxminutes",!1)):"minutes"==c&&(showhide(d+"_spanxhours",!1),showhide(d+"_spanxminutes",!0)),Validate_ScheduleValue($j("[name="+d+"_everyxvalue]")[0])}function Validate_Schedule(a,b){var c=a.name,d=a.value.split(","),e=0;"hours"==b?e=23:"mins"==b&&(e=59);for(var f="false",g=0;ge||0>1*d[g])&&(f="true");return"true"==f?($j(a).addClass("invalid"),!1):($j(a).removeClass("invalid"),!0)}function Validate_ScheduleValue(a){var b=a.name,c=1*a.value,d=b.substring(0,b.lastIndexOf("_")),e=0,f=$j("#"+d+"_everyxselect").val();return"hours"==f?e=24:"minutes"==f&&(e=30),c>e||c<1||1>a.value.length?($j(a).addClass("invalid"),!1):($j(a).removeClass("invalid"),!0)}function Validate_All(){for(var validationfailed=!1,i=1;6>i;i++)"EveryX"==eval("document.form.vpn"+i+"_schedulemode").value?Validate_ScheduleValue(eval("document.form.vpn"+i+"_everyxvalue"))||(validationfailed=!0):"Custom"==eval("document.form.vpn"+i+"_schedulemode").value&&(Validate_Schedule(eval("document.form.vpnmgr_vpn"+i+"_schhours"),"hours")||(validationfailed=!0),Validate_Schedule(eval("document.form.vpnmgr_vpn"+i+"_schmins"),"mins")||(validationfailed=!0));return!validationfailed||(alert("Validation for some fields failed. Please correct invalid values and try again."),!1)}function get_conf_file(){$j.ajax({url:"/ext/vpnmgr/config.htm",dataType:"text",error:function(){setTimeout(get_conf_file,1e3)},success:function(data){var settings=data.split("\n");settings.reverse(),settings=settings.filter(Boolean);var settingcount=settings.length;window.vpnmgr_settings=[];for(var i=0;ii;i++)eval("document.form.vpnmgr_vpn"+i+"_countryname").value=window.vpnmgr_settings.filter(function(a){return a[0]=="vpn"+i+"_countryname"})[0][1],""==eval("document.form.vpnmgr_vpn"+i+"_countryname").value?$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!0):""!=eval("document.form.vpnmgr_vpn"+i+"_countryname").value&&$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!1),""==eval("document.form.vpnmgr_vpn"+i+"_countryname").value&&1==eval("document.form.vpnmgr_vpn"+i+"_countryname").length&&$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!0);PopulateCityDropdown("all");for(var i=1;6>i;i++)eval("document.form.vpnmgr_vpn"+i+"_cityname").value=window.vpnmgr_settings.filter(function(a){return a[0]=="vpn"+i+"_cityname"})[0][1],0==eval("document.form.vpnmgr_vpn"+i+"_cityname").length||1==eval("document.form.vpnmgr_vpn"+i+"_cityname").length&&""==eval("document.form.vpnmgr_vpn"+i+"_cityname").value?$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!0):0i;i++)eval("document.form.vpnmgr_vpn"+i+"_usn").value=eval("document.form.vpn"+i+"_usn").value,eval("document.form.vpnmgr_vpn"+i+"_pwd").value=eval("document.form.vpn"+i+"_pwd").value,-1==$j("[name=vpnmgr_vpn"+i+"_schhours]").val().indexOf("/")?-1==$j("[name=vpnmgr_vpn"+i+"_schmins]").val().indexOf("/")?eval("document.form.vpn"+i+"_schedulemode").value="Custom":(eval("document.form.vpn"+i+"_schedulemode").value="EveryX",eval("document.form.vpn"+i+"_everyxselect").value="minutes",eval("document.form.vpn"+i+"_everyxvalue").value=$j("[name=vpnmgr_vpn"+i+"_schmins]").val().split("/")[1]):(eval("document.form.vpn"+i+"_schedulemode").value="EveryX",eval("document.form.vpn"+i+"_everyxselect").value="hours",eval("document.form.vpn"+i+"_everyxvalue").value=$j("[name=vpnmgr_vpn"+i+"_schhours]").val().split("/")[1]),ScheduleModeToggle($j("#vpn"+i+"_schmode_"+$j("[name=vpn"+i+"_schedulemode]:checked").val().toLowerCase())[0]);showhide("imgRefreshCachedData",!1),showhide("refreshcacheddata_text",!1),showhide("btnRefreshCachedData",!0),AddEventHandlers()}})}function GetCookie(a,b){var c;if(null!=(c=cookie.get("vpnmgr_"+a)))return cookie.get("vpnmgr_"+a);return"string"==b?"":"number"==b?0:void 0}function SetCookie(a,b){cookie.set("vpnmgr_"+a,b,31)}function SetCurrentPage(){document.form.next_page.value=window.location.pathname.substring(1),document.form.current_page.value=window.location.pathname.substring(1)}function reload(){location.reload(!0)}function pass_checked(a,b){switchType(a,b.checked,!0)}function SaveConfig(){if(Validate_All()){for(var i=1;6>i;i++)if("EveryX"==eval("document.form.vpn"+i+"_schedulemode").value)if("hours"==eval("document.form.vpn"+i+"_everyxselect").value){var everyxvalue=1*eval("document.form.vpn"+i+"_everyxvalue").value;eval("document.form.vpnmgr_vpn"+i+"_schmins").value=0,eval("document.form.vpnmgr_vpn"+i+"_schhours").value=24==everyxvalue?0:"*/"+everyxvalue}else if("minutes"==eval("document.form.vpn"+i+"_everyxselect").value){eval("document.form.vpnmgr_vpn"+i+"_schhours").value=0;var everyxvalue=1*eval("document.form.vpn"+i+"_everyxvalue").value;eval("document.form.vpnmgr_vpn"+i+"_schmins").value="*/"+everyxvalue}$j("[name*=vpnmgr_]").prop("disabled",!1),document.getElementById("amng_custom").value=JSON.stringify($j("form").serializeObject());var action_script_tmp="start_vpnmgr";document.form.action_script.value="start_vpnmgr";var restart_time=15;document.form.action_wait.value=15,showLoading(),document.form.submit()}else return!1}function initial(){SetCurrentPage(),LoadCustomSettings(),show_menu(),GetNordVPNCountryData(),ScriptUpdateLayout()}function BuildConfigTable(a,b){var c="
 
";return c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="
"+b+" Configuration (click to expand/collapse)
",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="
Description"+$j("input[name="+a+"_desc]").val()+"
Managed by vpnmgr?
VPN Provider
Username
Password   
Type
Protocol
Country
City
Scheduled update/reload?
Schedule Days",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="
Schedule Mode",c+="
FrequencyEvery ",c+="",c+=" ",c+=" (between 1 and 24)",c+=" (between 1 and 30)",c+="
Schedule Hours
Schedule Minutes
",c+="
",c}function AddEventHandlers(){$j(".collapsible-jquery").click(function(){$j(this).siblings().toggle("fast",function(){"none"==$j(this).css("display")?SetCookie($j(this).siblings()[0].id,"collapsed"):SetCookie($j(this).siblings()[0].id,"expanded")})}),$j(".collapsible-jquery").each(function(){"collapsed"==GetCookie($j(this)[0].id,"string")?$j(this).siblings().toggle(!1):$j(this).siblings().toggle(!0)})}$j.fn.serializeObject=function(){var b=custom_settings,c=this.serializeArray();$j.each(c,function(){b[this.name]!==void 0&&-1!=this.name.indexOf("vpnmgr")&&-1==this.name.indexOf("version")&&-1==this.name.indexOf("schdays")&&-1==this.name.indexOf("countryid")&&-1==this.name.indexOf("cityid")?(!b[this.name].push&&(b[this.name]=[b[this.name]]),b[this.name].push(this.value||"")):-1!=this.name.indexOf("vpnmgr")&&-1==this.name.indexOf("version")&&-1==this.name.indexOf("schdays")&&-1==this.name.indexOf("countryid")&&-1==this.name.indexOf("cityid")&&(b[this.name]=this.value||"")});for(var a,d=1;6>d;d++){a=[],$j.each($j("input[name='vpnmgr_vpn"+d+"_schdays']:checked"),function(){a.push($j(this).val())});var e=a.join(",");"Mon,Tues,Wed,Thurs,Fri,Sat,Sun"==e&&(e="*"),b["vpnmgr_vpn"+d+"_schdays"]=e,""==$j("select[name='vpnmgr_vpn"+d+"_countryname']").val()||"PIA"==$j("input[name='vpnmgr_vpn"+d+"_provider']:checked").val()?(b["vpnmgr_vpn"+d+"_countryid"]=0,b["vpnmgr_vpn"+d+"_cityid"]=0):""==$j("select[name='vpnmgr_vpn"+d+"_countryname']").val()||"WeVPN"==$j("input[name='vpnmgr_vpn"+d+"_provider']:checked").val()?(b["vpnmgr_vpn"+d+"_countryid"]=0,b["vpnmgr_vpn"+d+"_cityid"]=0):(b["vpnmgr_vpn"+d+"_countryid"]=nordvpncountries.filter(function(a){return a.name==$j("select[name='vpnmgr_vpn"+d+"_countryname']").val()}).map(function(a){return a.id})[0],b["vpnmgr_vpn"+d+"_cityid"]=""==$j("select[name='vpnmgr_vpn"+d+"_cityname']").val()?0:nordvpncountries.filter(function(a){return a.name==$j("select[name='vpnmgr_vpn"+d+"_countryname']").val()})[0].cities.filter(function(a){return a.name==$j("select[name='vpnmgr_vpn"+d+"_cityname']").val()}).map(function(a){return a.id})[0])}return b};function ScriptUpdateLayout(){var a=GetVersionNumber("local"),b=GetVersionNumber("server");$j("#vpnmgr_version_local").text(a),a!=b&&"N/A"!=b&&($j("#vpnmgr_version_server").text("Updated version available: "+b),showhide("btnChkUpdate",!1),showhide("vpnmgr_version_server",!0),showhide("btnDoUpdate",!0))}function update_status(){$j.ajax({url:"/ext/vpnmgr/detect_update.js",dataType:"script",timeout:3e3,error:function(){setTimeout(update_status,1e3)},success:function(){"InProgress"==updatestatus?setTimeout(update_status,1e3):(document.getElementById("imgChkUpdate").style.display="none",showhide("vpnmgr_version_server",!0),"None"==updatestatus?($j("#vpnmgr_version_server").text("No update available"),showhide("btnChkUpdate",!0),showhide("btnDoUpdate",!1)):($j("#vpnmgr_version_server").text("Updated version available: "+updatestatus),showhide("btnChkUpdate",!1),showhide("btnDoUpdate",!0)))}})}function CheckUpdate(){showhide("btnChkUpdate",!1),document.formScriptActions.action_script.value="start_vpnmgrcheckupdate",document.formScriptActions.submit(),document.getElementById("imgChkUpdate").style.display="",setTimeout(update_status,2e3)}function DoUpdate(){document.form.action_script.value="start_vpnmgrdoupdate";document.form.action_wait.value=10,showLoading(),document.form.submit()}function getserverload_status(){$j.ajax({url:"/ext/vpnmgr/vpnmgrserverloads.js",dataType:"script",timeout:1e3,error:function(){},success:function(data){clearInterval(getserverloadinterval),showhide("imgGetServerLoad",!1),showhide("getserverload_text",!0);for(var i=1;5>=i;i++)try{-1==$j("#vpnmgr_vpn"+i+"_desc").html().indexOf("|")?$j("#vpnmgr_vpn"+i+"_desc").html($j("#vpnmgr_vpn"+i+"_desc").html()+" | "+eval("vpn"+i+"_serverload")+"%"):$j("#vpnmgr_vpn"+i+"_desc").html($j("#vpnmgr_vpn"+i+"_desc").html().substring(0,$j("#vpnmgr_vpn"+i+"_desc").html().indexOf("|")-1)+" | "+eval("vpn"+i+"_serverload")+"%")}catch(a){continue}setTimeout(showhide,3e3,"getserverload_text",!1),setTimeout(showhide,3100,"btnGetServerLoad",!0)}})}function GetServerLoad(){showhide("btnGetServerLoad",!1),document.formScriptActions.action_script.value="start_vpnmgrgetserverload",document.formScriptActions.submit(),showhide("imgGetServerLoad",!0),showhide("getserverload_text",!1),setTimeout(StartGetServerLoadInterval,1e3)}function StartGetServerLoadInterval(){getserverloadinterval=setInterval(getserverload_status,1e3)}function RefreshCachedData(){showhide("btnRefreshCachedData",!1),document.formScriptActions.action_script.value="start_vpnmgrrefreshcacheddata",document.formScriptActions.submit(),showhide("imgRefreshCachedData",!0),showhide("refreshcacheddata_text",!1),setTimeout(StartRefreshCachedDataInterval,1e3)}function StartRefreshCachedDataInterval(){refreshcacheddatainterval=setInterval(refreshcacheddata_status,1e3)}var refreshcount=1;function refreshcacheddata_status(){refreshcount++,$j.ajax({url:"/ext/vpnmgr/detect_vpnmgr.js",dataType:"script",timeout:1e3,error:function(){},success:function(){"InProgress"==refreshcacheddatastatus?(showhide("imgRefreshCachedData",!0),showhide("refreshcacheddata_text",!0),document.getElementById("refreshcacheddata_text").innerHTML="Cached data refresh in progress - "+refreshcount+"s elapsed"):"Done"==refreshcacheddatastatus?(document.getElementById("refreshcacheddata_text").innerHTML="Refreshing data...",refreshcount=1,clearInterval(refreshcacheddatainterval),PostRefreshCachedData()):"LOCKED"==refreshcacheddatastatus&&(showhide("imgRefreshCachedData",!1),document.getElementById("refreshcacheddata_text").innerHTML="Cached data refresh already running!",showhide("refreshcacheddata_text",!0),showhide("btnRefreshCachedData",!0),clearInterval(refreshcacheddatainterval))}})}function PostRefreshCachedData(){for(var a=1;6>a;a++)$j("#table_config_vpn"+a).prev("div").remove(),$j("#table_config_vpn"+a).remove();setTimeout(GetNordVPNCountryData,3e3)}function GetVersionNumber(a){var b;return"local"==a?b=custom_settings.vpnmgr_version_local:"server"==a&&(b=custom_settings.vpnmgr_version_server),"undefined"==typeof b||null==b?"N/A":b}function GetNordVPNCountryData(){$j.ajax({url:"/ext/vpnmgr/nordvpn_countrydata.htm",dataType:"json",error:function(){setTimeout(GetNordVPNCountryData,1e3)},success:function(a){nordvpncountries=a,GetPIACountryData()}})}function GetPIACountryData(){$j.ajax({url:"/ext/vpnmgr/pia_countrydata.htm",dataType:"text",error:function(){setTimeout(GetPIACountryData,1e3)},success:function(a){piacountries=parseCountryData(a),GetWeVPNCountryData()}})}function GetWeVPNCountryData(){$j.ajax({url:"/ext/vpnmgr/wevpn_countrydata.htm",dataType:"text",error:function(){setTimeout(GetWeVPNCountryData,1e3)},success:function(a){wevpncountries=parseCountryData(a),get_conf_file()}})}function parseCountryData(a){var b=[],c=[];c=a.split("\n"),c=c.filter(Boolean);var d=[],e=[],f=[],g=[],h=[],i=[],j=[],k=[],l=[],m=[],n=[],o=[],p=[],q=[],r=[],s=[],t=[],u=[],v=[],w=[],x=[],y=[],z=[],A=[],B=[],C=[],D=[],E=[],F=[],G=[],H=[],I=[],J=[];$j.each(c,function(a,b){if("AU"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("AU ","")),e.push(c),b="Australia"}else if("CA"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("CA ","")),f.push(c),b="Canada"}else if("DE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("DE ","")),g.push(c),b="Germany"}else if("US"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("US ","")),h.push(c),b="United States"}else if("AT"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("AT ","")),k.push(c),b="Austria"}else if("BE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("BE ","")),l.push(c),b="Belgium"}else if("BG"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("BG ","")),m.push(c),b="Bulgaria"}else if("BR"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("BR ","")),n.push(c),b="Brazil"}else if("CH"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("CH ","")),o.push(c),b="Switzerland"}else if("CZ"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("CZ ","")),p.push(c),b="Czech Republic"}else if("DK"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("DK ","")),q.push(c),b="Denmark"}else if("ES"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("ES ","")),r.push(c),b="Spain"}else if("FR"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("FR ","")),s.push(c),b="France"}else if("HK"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("HK ","")),t.push(c),b="Hong Kong"}else if("HU"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("HU ","")),u.push(c),b="Hungary"}else if("IE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IE ","")),v.push(c),b="Ireland"}else if("IL"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IL ","")),w.push(c),b="Israel"}else if("IN"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IN ","")),x.push(c),b="India"}else if("IT"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IT ","")),y.push(c),b="Italy"}else if("JP"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("JP ","")),z.push(c),b="Japan"}else if("MX"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("MX ","")),A.push(c),b="Mexico"}else if("NL"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("NL ","")),B.push(c),b="Netherlands"}else if("NO"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("NO ","")),C.push(c),b="Norway"}else if("NZ"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("NZ ","")),D.push(c),b="New Zealand"}else if("PL"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("PL ","")),E.push(c),b="Poland"}else if("RO"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("RO ","")),F.push(c),b="Romania"}else if("RS"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("RS ","")),G.push(c),b="Serbia"}else if("SE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("SE ","")),H.push(c),b="Sweden"}else if("SG"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("SG ","")),I.push(c),b="Singapore"}else if("UAE"==getCountryCode(b)||"AE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("UAE ","").replaceAll("AE ","")),i.push(c),b="United Arab Emirates"}else if("UK"==getCountryCode(b)||"GB"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("UK ","").replaceAll("GB ","")),j.push(c),b="United Kingdom"}else if("ZA"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("ZA ","")),J.push(c),b="South Africa"}else b=capitalizeFirstLetter(b.replaceAll("_"," "));d.push(b)}),d.sort();var K=[];for(let c=0;c"),cityarray=nordvpncountries):"PIA"==eval("document.form."+prefix+"_provider").value?cityarray=piacountries:"WeVPN"==eval("document.form."+prefix+"_provider").value&&(cityarray=wevpncountries),$j.each(cityarray,function(a,b){return b.name!=$j("select[name="+prefix+"_countryname]").val()||($j.each(b.cities,function(a,b){dropdown.append($j("").attr("value",b.name).text(b.name))}),2==dropdown[0].length&&0==dropdown.find("option:first-child").val().length?dropdown.prop("selectedIndex",0):dropdown.prop("selectedIndex",0),!1)}),""==inputvalue?dropdown.prop("disabled",!0):""!=inputvalue&&dropdown.prop("disabled",!1),0==dropdown[0].length?dropdown.prop("disabled",!0):dropdown.prop("disabled",!1)}function capitalizeFirstLetter(a){return a.replace(/(^\w{1})|(\s{1}\w{1})/g,a=>a.toUpperCase())}function getCountryCode(a){return a=a.replaceAll(" ","_"),-1==a.indexOf("_")?a.toUpperCase():a.substring(0,a.indexOf("_")).toUpperCase()}String.prototype.replaceAll=function(a,b){var c=a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),d=new RegExp(c,"ig");return this.replace(d,b)}; +var refreshcacheddatainterval,getserverloadinterval,$j=jQuery.noConflict(),daysofweek=["Mon","Tues","Wed","Thurs","Fri","Sat","Sun"],nordvpncountries=[],piacountries=[],wevpncountries=[];function SettingHint(a){for(var b=document.getElementsByTagName("a"),c=0;cvpnno;vpnno++){if("all"!=vpnclient&&vpnno!=vpnclient)continue;let dropdown=$j("#vpnmgr_vpn"+vpnno+"_countryname");dropdown.empty();var countryarray=[];"NordVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?(dropdown.append(""),dropdown.prop("selectedIndex",0),countryarray=nordvpncountries):"PIA"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?countryarray=piacountries:"WeVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value&&(countryarray=wevpncountries),$j.each(countryarray,function(a,b){dropdown.append($j("").attr("value",b.name).text(b.name))})}}function PopulateCityDropdown(vpnclient){for(var vpnno=1;6>vpnno;vpnno++){if("all"!=vpnclient&&vpnno!=vpnclient)continue;let dropdown=$j("#vpnmgr_vpn"+vpnno+"_cityname");dropdown.empty(),"NordVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?(dropdown.append(""),dropdown.prop("selectedIndex",0),cityarray=nordvpncountries):"PIA"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value?cityarray=piacountries:"WeVPN"==eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value&&(cityarray=wevpncountries),$j.each(cityarray,function(key,entry){return entry.name!=eval("document.form.vpnmgr_vpn"+vpnno+"_countryname").value||($j.each(entry.cities,function(a,b){dropdown.append($j("").attr("value",b.name).text(b.name))}),!1)})}}function ScheduleModeToggle(a){var b=a.name,c=a.value,d=b.substring(0,b.lastIndexOf("_"));"EveryX"==c?(showhide(d+"_schedulefrequency",!0),showhide(d+"_customhours",!1),showhide(d+"_custommins",!1),"hours"==$j("#"+d+"_everyxselect").val()?(showhide(d+"_spanxhours",!0),showhide(d+"_spanxminutes",!1)):"minutes"==$j("#"+d+"_everyxselect").val()&&(showhide(d+"_spanxhours",!1),showhide(d+"_spanxminutes",!0))):"Custom"==c&&(showhide(d+"_schedulefrequency",!1),showhide(d+"_customhours",!0),showhide(d+"_custommins",!0))}function EveryXToggle(a){var b=a.name,c=a.value,d=b.substring(0,b.lastIndexOf("_"));"hours"==c?(showhide(d+"_spanxhours",!0),showhide(d+"_spanxminutes",!1)):"minutes"==c&&(showhide(d+"_spanxhours",!1),showhide(d+"_spanxminutes",!0)),Validate_ScheduleValue($j("[name="+d+"_everyxvalue]")[0])}function Validate_Schedule(a,b){var c=a.name,d=a.value.split(","),e=0;"hours"==b?e=23:"mins"==b&&(e=59);for(var f="false",g=0;ge||0>1*d[g])&&(f="true");return"true"==f?($j(a).addClass("invalid"),!1):($j(a).removeClass("invalid"),!0)}function Validate_ScheduleValue(a){var b=a.name,c=1*a.value,d=b.substring(0,b.lastIndexOf("_")),e=0,f=$j("#"+d+"_everyxselect").val();return"hours"==f?e=24:"minutes"==f&&(e=30),c>e||c<1||1>a.value.length?($j(a).addClass("invalid"),!1):($j(a).removeClass("invalid"),!0)}function Validate_All(){for(var validationfailed=!1,i=1;6>i;i++)"EveryX"==eval("document.form.vpn"+i+"_schedulemode").value?Validate_ScheduleValue(eval("document.form.vpn"+i+"_everyxvalue"))||(validationfailed=!0):"Custom"==eval("document.form.vpn"+i+"_schedulemode").value&&(Validate_Schedule(eval("document.form.vpnmgr_vpn"+i+"_schhours"),"hours")||(validationfailed=!0),Validate_Schedule(eval("document.form.vpnmgr_vpn"+i+"_schmins"),"mins")||(validationfailed=!0));return!validationfailed||(alert("Validation for some fields failed. Please correct invalid values and try again."),!1)}function get_conf_file(){$j.ajax({url:"/ext/vpnmgr/config.htm",dataType:"text",error:function(){setTimeout(get_conf_file,1e3)},success:function(data){var settings=data.split("\n");settings.reverse(),settings=settings.filter(Boolean);var settingcount=settings.length;window.vpnmgr_settings=[];for(var i=0;ii;i++)eval("document.form.vpnmgr_vpn"+i+"_countryname").value=window.vpnmgr_settings.filter(function(a){return a[0]=="vpn"+i+"_countryname"})[0][1],""==eval("document.form.vpnmgr_vpn"+i+"_countryname").value?$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!0):""!=eval("document.form.vpnmgr_vpn"+i+"_countryname").value&&$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!1),""==eval("document.form.vpnmgr_vpn"+i+"_countryname").value&&1==eval("document.form.vpnmgr_vpn"+i+"_countryname").length&&$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!0);PopulateCityDropdown("all");for(var i=1;6>i;i++)eval("document.form.vpnmgr_vpn"+i+"_cityname").value=window.vpnmgr_settings.filter(function(a){return a[0]=="vpn"+i+"_cityname"})[0][1],0==eval("document.form.vpnmgr_vpn"+i+"_cityname").length||1==eval("document.form.vpnmgr_vpn"+i+"_cityname").length&&""==eval("document.form.vpnmgr_vpn"+i+"_cityname").value?$j("#vpnmgr_vpn"+i+"_cityname").prop("disabled",!0):0i;i++)eval("document.form.vpnmgr_vpn"+i+"_usn").value=eval("document.form.vpn"+i+"_usn").value,eval("document.form.vpnmgr_vpn"+i+"_pwd").value=eval("document.form.vpn"+i+"_pwd").value,-1==$j("[name=vpnmgr_vpn"+i+"_schhours]").val().indexOf("/")?-1==$j("[name=vpnmgr_vpn"+i+"_schmins]").val().indexOf("/")?eval("document.form.vpn"+i+"_schedulemode").value="Custom":(eval("document.form.vpn"+i+"_schedulemode").value="EveryX",eval("document.form.vpn"+i+"_everyxselect").value="minutes",eval("document.form.vpn"+i+"_everyxvalue").value=$j("[name=vpnmgr_vpn"+i+"_schmins]").val().split("/")[1]):(eval("document.form.vpn"+i+"_schedulemode").value="EveryX",eval("document.form.vpn"+i+"_everyxselect").value="hours",eval("document.form.vpn"+i+"_everyxvalue").value=$j("[name=vpnmgr_vpn"+i+"_schhours]").val().split("/")[1]),ScheduleModeToggle($j("#vpn"+i+"_schmode_"+$j("[name=vpn"+i+"_schedulemode]:checked").val().toLowerCase())[0]);showhide("imgRefreshCachedData",!1),showhide("refreshcacheddata_text",!1),showhide("btnRefreshCachedData",!0),AddEventHandlers()}})}function GetCookie(a,b){if(null!=cookie.get("vpnmgr_"+a))return cookie.get("vpnmgr_"+a);return"string"==b?"":"number"==b?0:void 0}function SetCookie(a,b){cookie.set("vpnmgr_"+a,b,3650)}function SetCurrentPage(){document.form.next_page.value=window.location.pathname.substring(1),document.form.current_page.value=window.location.pathname.substring(1)}function reload(){location.reload(!0)}function pass_checked(a,b){switchType(a,b.checked,!0)}function SaveConfig(){if(Validate_All()){for(var i=1;6>i;i++)if("EveryX"==eval("document.form.vpn"+i+"_schedulemode").value)if("hours"==eval("document.form.vpn"+i+"_everyxselect").value){var everyxvalue=1*eval("document.form.vpn"+i+"_everyxvalue").value;eval("document.form.vpnmgr_vpn"+i+"_schmins").value=0,eval("document.form.vpnmgr_vpn"+i+"_schhours").value=24==everyxvalue?0:"*/"+everyxvalue}else if("minutes"==eval("document.form.vpn"+i+"_everyxselect").value){eval("document.form.vpnmgr_vpn"+i+"_schhours").value=0;var everyxvalue=1*eval("document.form.vpn"+i+"_everyxvalue").value;eval("document.form.vpnmgr_vpn"+i+"_schmins").value="*/"+everyxvalue}$j("[name*=vpnmgr_]").prop("disabled",!1),document.getElementById("amng_custom").value=JSON.stringify($j("form").serializeObject());var action_script_tmp="start_vpnmgr";document.form.action_script.value="start_vpnmgr";var restart_time=15;document.form.action_wait.value=15,showLoading(),document.form.submit()}else return!1}function initial(){SetCurrentPage(),LoadCustomSettings(),show_menu(),GetNordVPNCountryData(),ScriptUpdateLayout()}function BuildConfigTable(a,b){var c="
 
";return c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="
"+b+" Configuration (click to expand/collapse)
",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="
Description"+$j("input[name="+a+"_desc]").val()+"
Managed by vpnmgr?
VPN Provider
Username
Password   
Use vpnmgr custom settings?
Type
Protocol
Country
City
Scheduled update/reload?
Schedule Days",c+="",c+="",c+="",c+="",c+="",c+="",c+="",c+="
Schedule Mode",c+="
FrequencyEvery ",c+="",c+=" ",c+=" (between 1 and 24)",c+=" (between 1 and 30)",c+="
Schedule Hours
Schedule Minutes
",c+="
",c}function AddEventHandlers(){$j(".collapsible-jquery").click(function(){$j(this).siblings().toggle("fast",function(){"none"==$j(this).css("display")?SetCookie($j(this).siblings()[0].id,"collapsed"):SetCookie($j(this).siblings()[0].id,"expanded")})}),$j(".collapsible-jquery").each(function(){"collapsed"==GetCookie($j(this)[0].id,"string")?$j(this).siblings().toggle(!1):$j(this).siblings().toggle(!0)})}$j.fn.serializeObject=function(){var b=custom_settings,c=this.serializeArray();$j.each(c,function(){b[this.name]!==void 0&&-1!=this.name.indexOf("vpnmgr")&&-1==this.name.indexOf("version")&&-1==this.name.indexOf("schdays")&&-1==this.name.indexOf("countryid")&&-1==this.name.indexOf("cityid")?(!b[this.name].push&&(b[this.name]=[b[this.name]]),b[this.name].push(this.value||"")):-1!=this.name.indexOf("vpnmgr")&&-1==this.name.indexOf("version")&&-1==this.name.indexOf("schdays")&&-1==this.name.indexOf("countryid")&&-1==this.name.indexOf("cityid")&&(b[this.name]=this.value||"")});for(var a,d=1;6>d;d++){a=[],$j.each($j("input[name=\"vpnmgr_vpn"+d+"_schdays\"]:checked"),function(){a.push($j(this).val())});var e=a.join(",");"Mon,Tues,Wed,Thurs,Fri,Sat,Sun"==e&&(e="*"),b["vpnmgr_vpn"+d+"_schdays"]=e,""==$j("select[name=\"vpnmgr_vpn"+d+"_countryname\"]").val()||"PIA"==$j("input[name=\"vpnmgr_vpn"+d+"_provider\"]:checked").val()?(b["vpnmgr_vpn"+d+"_countryid"]=0,b["vpnmgr_vpn"+d+"_cityid"]=0):""==$j("select[name=\"vpnmgr_vpn"+d+"_countryname\"]").val()||"WeVPN"==$j("input[name=\"vpnmgr_vpn"+d+"_provider\"]:checked").val()?(b["vpnmgr_vpn"+d+"_countryid"]=0,b["vpnmgr_vpn"+d+"_cityid"]=0):(b["vpnmgr_vpn"+d+"_countryid"]=nordvpncountries.filter(function(a){return a.name==$j("select[name=\"vpnmgr_vpn"+d+"_countryname\"]").val()}).map(function(a){return a.id})[0],b["vpnmgr_vpn"+d+"_cityid"]=""==$j("select[name=\"vpnmgr_vpn"+d+"_cityname\"]").val()?0:nordvpncountries.filter(function(a){return a.name==$j("select[name=\"vpnmgr_vpn"+d+"_countryname\"]").val()})[0].cities.filter(function(a){return a.name==$j("select[name=\"vpnmgr_vpn"+d+"_cityname\"]").val()}).map(function(a){return a.id})[0])}return b};function ScriptUpdateLayout(){var a=GetVersionNumber("local"),b=GetVersionNumber("server");$j("#vpnmgr_version_local").text(a),a!=b&&"N/A"!=b&&($j("#vpnmgr_version_server").text("Updated version available: "+b),showhide("btnChkUpdate",!1),showhide("vpnmgr_version_server",!0),showhide("btnDoUpdate",!0))}function update_status(){$j.ajax({url:"/ext/vpnmgr/detect_update.js",dataType:"script",error:function(){setTimeout(update_status,1e3)},success:function(){"InProgress"==updatestatus?setTimeout(update_status,1e3):(document.getElementById("imgChkUpdate").style.display="none",showhide("vpnmgr_version_server",!0),"None"==updatestatus?($j("#vpnmgr_version_server").text("No update available"),showhide("btnChkUpdate",!0),showhide("btnDoUpdate",!1)):($j("#vpnmgr_version_server").text("Updated version available: "+updatestatus),showhide("btnChkUpdate",!1),showhide("btnDoUpdate",!0)))}})}function CheckUpdate(){showhide("btnChkUpdate",!1),document.formScriptActions.action_script.value="start_vpnmgrcheckupdate",document.formScriptActions.submit(),document.getElementById("imgChkUpdate").style.display="",setTimeout(update_status,2e3)}function DoUpdate(){document.form.action_script.value="start_vpnmgrdoupdate";document.form.action_wait.value=10,showLoading(),document.form.submit()}function getserverload_status(){$j.ajax({url:"/ext/vpnmgr/vpnmgrserverloads.js",dataType:"script",error:function(){},success:function(data){clearInterval(getserverloadinterval),showhide("imgGetServerLoad",!1),showhide("getserverload_text",!0);for(var i=1;5>=i;i++)try{-1==$j("#vpnmgr_vpn"+i+"_desc").html().indexOf("|")?$j("#vpnmgr_vpn"+i+"_desc").html($j("#vpnmgr_vpn"+i+"_desc").html()+" | "+eval("vpn"+i+"_serverload")+"%"):$j("#vpnmgr_vpn"+i+"_desc").html($j("#vpnmgr_vpn"+i+"_desc").html().substring(0,$j("#vpnmgr_vpn"+i+"_desc").html().indexOf("|")-1)+" | "+eval("vpn"+i+"_serverload")+"%")}catch(a){continue}setTimeout(showhide,3e3,"getserverload_text",!1),setTimeout(showhide,3100,"btnGetServerLoad",!0)}})}function GetServerLoad(){showhide("btnGetServerLoad",!1),document.formScriptActions.action_script.value="start_vpnmgrgetserverload",document.formScriptActions.submit(),showhide("imgGetServerLoad",!0),showhide("getserverload_text",!1),setTimeout(StartGetServerLoadInterval,5e3)}function StartGetServerLoadInterval(){getserverloadinterval=setInterval(getserverload_status,1e3)}function RefreshCachedData(){showhide("btnRefreshCachedData",!1),document.formScriptActions.action_script.value="start_vpnmgrrefreshcacheddata",document.formScriptActions.submit(),showhide("imgRefreshCachedData",!0),showhide("refreshcacheddata_text",!1),setTimeout(StartRefreshCachedDataInterval,5e3)}function StartRefreshCachedDataInterval(){refreshcacheddatainterval=setInterval(refreshcacheddata_status,1e3)}var refreshcount=1;function refreshcacheddata_status(){refreshcount++,$j.ajax({url:"/ext/vpnmgr/detect_vpnmgr.js",dataType:"script",error:function(){},success:function(){"InProgress"==refreshcacheddatastatus?(showhide("imgRefreshCachedData",!0),showhide("refreshcacheddata_text",!0),document.getElementById("refreshcacheddata_text").innerHTML="Cached data refresh in progress - "+refreshcount+"s elapsed"):"Done"==refreshcacheddatastatus?(document.getElementById("refreshcacheddata_text").innerHTML="Refreshing data...",refreshcount=1,clearInterval(refreshcacheddatainterval),PostRefreshCachedData()):"LOCKED"==refreshcacheddatastatus&&(showhide("imgRefreshCachedData",!1),document.getElementById("refreshcacheddata_text").innerHTML="Cached data refresh already running!",showhide("refreshcacheddata_text",!0),showhide("btnRefreshCachedData",!0),clearInterval(refreshcacheddatainterval))}})}function PostRefreshCachedData(){for(var a=1;6>a;a++)$j("#table_config_vpn"+a).prev("div").remove(),$j("#table_config_vpn"+a).remove();setTimeout(GetNordVPNCountryData,3e3)}function GetVersionNumber(a){var b;return"local"==a?b=custom_settings.vpnmgr_version_local:"server"==a&&(b=custom_settings.vpnmgr_version_server),"undefined"==typeof b||null==b?"N/A":b}function GetNordVPNCountryData(){$j.ajax({url:"/ext/vpnmgr/nordvpn_countrydata.htm",dataType:"json",error:function(){setTimeout(GetNordVPNCountryData,1e3)},success:function(a){nordvpncountries=a,GetPIACountryData()}})}function GetPIACountryData(){$j.ajax({url:"/ext/vpnmgr/pia_countrydata.htm",dataType:"text",error:function(){setTimeout(GetPIACountryData,1e3)},success:function(a){piacountries=parseCountryData(a),GetWeVPNCountryData()}})}function GetWeVPNCountryData(){$j.ajax({url:"/ext/vpnmgr/wevpn_countrydata.htm",dataType:"text",error:function(){setTimeout(GetWeVPNCountryData,1e3)},success:function(a){wevpncountries=parseCountryData(a),get_conf_file()}})}function parseCountryData(a){var b=[],c=[];c=a.split("\n"),c=c.filter(Boolean);var d=[],e=[],f=[],g=[],h=[],i=[],j=[],k=[],l=[],m=[],n=[],o=[],p=[],q=[],r=[],s=[],t=[],u=[],v=[],w=[],x=[],y=[],z=[],A=[],B=[],C=[],D=[],E=[],F=[],G=[],H=[],I=[],J=[];$j.each(c,function(a,b){if("AU"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("AU ","")),e.push(c),b="Australia"}else if("CA"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("CA ","")),f.push(c),b="Canada"}else if("DE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("DE ","")),g.push(c),b="Germany"}else if("US"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("US ","")),h.push(c),b="United States"}else if("AT"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("AT ","")),k.push(c),b="Austria"}else if("BE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("BE ","")),l.push(c),b="Belgium"}else if("BG"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("BG ","")),m.push(c),b="Bulgaria"}else if("BR"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("BR ","")),n.push(c),b="Brazil"}else if("CH"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("CH ","")),o.push(c),b="Switzerland"}else if("CZ"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("CZ ","")),p.push(c),b="Czech Republic"}else if("DK"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("DK ","")),q.push(c),b="Denmark"}else if("ES"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("ES ","")),r.push(c),b="Spain"}else if("FR"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("FR ","")),s.push(c),b="France"}else if("HK"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("HK ","")),t.push(c),b="Hong Kong"}else if("HU"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("HU ","")),u.push(c),b="Hungary"}else if("IE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IE ","")),v.push(c),b="Ireland"}else if("IL"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IL ","")),w.push(c),b="Israel"}else if("IN"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IN ","")),x.push(c),b="India"}else if("IT"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("IT ","")),y.push(c),b="Italy"}else if("JP"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("JP ","")),z.push(c),b="Japan"}else if("MX"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("MX ","")),A.push(c),b="Mexico"}else if("NL"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("NL ","")),B.push(c),b="Netherlands"}else if("NO"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("NO ","")),C.push(c),b="Norway"}else if("NZ"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("NZ ","")),D.push(c),b="New Zealand"}else if("PL"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("PL ","")),E.push(c),b="Poland"}else if("RO"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("RO ","")),F.push(c),b="Romania"}else if("RS"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("RS ","")),G.push(c),b="Serbia"}else if("SE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("SE ","")),H.push(c),b="Sweden"}else if("SG"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("SG ","")),I.push(c),b="Singapore"}else if("UAE"==getCountryCode(b)||"AE"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("UAE ","").replaceAll("AE ","")),i.push(c),b="United Arab Emirates"}else if("UK"==getCountryCode(b)||"GB"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("UK ","").replaceAll("GB ","")),j.push(c),b="United Kingdom"}else if("ZA"==getCountryCode(b)){var c={};c.name=capitalizeFirstLetter(b.replaceAll("_"," ").replaceAll("ZA ","")),J.push(c),b="South Africa"}else b=capitalizeFirstLetter(b.replaceAll("_"," "));d.push(b)}),d.sort();var K=[];for(let c=0;c"),cityarray=nordvpncountries):"PIA"==eval("document.form."+prefix+"_provider").value?cityarray=piacountries:"WeVPN"==eval("document.form."+prefix+"_provider").value&&(cityarray=wevpncountries),$j.each(cityarray,function(a,b){return b.name!=$j("select[name="+prefix+"_countryname]").val()||($j.each(b.cities,function(a,b){dropdown.append($j("").attr("value",b.name).text(b.name))}),2==dropdown[0].length&&0==dropdown.find("option:first-child").val().length?dropdown.prop("selectedIndex",0):dropdown.prop("selectedIndex",0),!1)}),""==inputvalue?dropdown.prop("disabled",!0):""!=inputvalue&&dropdown.prop("disabled",!1),0==dropdown[0].length?dropdown.prop("disabled",!0):dropdown.prop("disabled",!1)}function capitalizeFirstLetter(a){return a.replace(/(^\w{1})|(\s{1}\w{1})/g,a=>a.toUpperCase())}function getCountryCode(a){return a=a.replaceAll(" ","_"),-1==a.indexOf("_")?a.toUpperCase():a.substring(0,a.indexOf("_")).toUpperCase()}String.prototype.replaceAll=function(a,b){var c=a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),d=new RegExp(c,"ig");return this.replace(d,b)}; diff --git a/vpnmgr_www.css b/vpnmgr_www.css new file mode 100644 index 0000000..ce3dd12 --- /dev/null +++ b/vpnmgr_www.css @@ -0,0 +1,82 @@ +p { +font-weight: bolder; +} + +thead.collapsible-jquery { + color: white; + padding: 0px; + width: 100%; + border: none; + text-align: left; + outline: none; + cursor: pointer; +} + +.SettingsTable { + table-layout: fixed !important; + width: 745px !important; + text-align: left; +} + +.SettingsTable input { + text-align: left; + margin-left: 3px !important; +} + +.SettingsTable label { + margin-right: 10px !important; +} + +.SettingsTable th { + background-color: #1F2D35 !important; + background: #2F3A3E !important; + border-bottom: none !important; + border-top: none !important; + font-size: 12px !important; + color: white !important; + padding: 4px !important; + font-weight: bolder !important; + padding: 0px !important; +} + +.SettingsTable td { + padding: 4px 4px 4px 10px !important; + word-wrap: break-word !important; + overflow-wrap: break-word !important; + border-right: none; + border-left: none; +} + +.SettingsTable span.settingname { + background-color: #1F2D35 !important; + background: #2F3A3E !important; +} + +.SettingsTable td.settingname { + border-right: solid 1px black; + background-color: #1F2D35 !important; + background: #2F3A3E !important; + font-weight: bolder !important; +} + +.SettingsTable td.settingvalue { + text-align: left !important; + border-right: solid 1px black; +} + +.SettingsTable th:first-child{ + border-left: none !important; +} + +.SettingsTable th:last-child { + border-right: none !important; +} + +.SettingsTable .invalid { + background-color: darkred !important; +} + +.SettingsTable .disabled { + background-color: #CCCCCC !important; + color: #888888 !important; +} diff --git a/vpnmgr_www.js b/vpnmgr_www.js index f4275e5..e0a3c17 100644 --- a/vpnmgr_www.js +++ b/vpnmgr_www.js @@ -1,5 +1,5 @@ var $j = jQuery.noConflict(); -var daysofweek = ["Mon","Tues","Wed","Thurs","Fri","Sat","Sun"]; +var daysofweek = ['Mon','Tues','Wed','Thurs','Fri','Sat','Sun']; var nordvpncountries = []; var piacountries = []; @@ -13,61 +13,62 @@ function SettingHint(hintid){ for (var i=0;i 0){ - dropdown.prop("disabled",false); + dropdown.prop('disabled',false); } } @@ -123,36 +124,36 @@ function ScheduleOptionsEnableDisable(forminput){ var inputname = forminput.name; var inputvalue = forminput.value; var prefix = inputname.substring(0,inputname.lastIndexOf('_')); - var prefix2 = prefix.replace("vpnmgr_",""); + var prefix2 = prefix.replace('vpnmgr_',''); - var fieldnames = ["schhours","schmins"]; - var fieldnames2 = ["schedulemode","everyxselect","everyxvalue"]; + var fieldnames = ['schhours','schmins']; + var fieldnames2 = ['schedulemode','everyxselect','everyxvalue']; - if(eval("document.form."+prefix+"_managed").value == "true"){ - if(inputvalue == "false"){ + if(eval('document.form.'+prefix+'_managed').value == 'true'){ + if(inputvalue == 'false'){ for (var i = 0; i < fieldnames.length; i++){ - $j('input[name='+prefix+'_'+fieldnames[i]+']').addClass("disabled"); - $j('input[name='+prefix+'_'+fieldnames[i]+']').prop("disabled",true); + $j('input[name='+prefix+'_'+fieldnames[i]+']').addClass('disabled'); + $j('input[name='+prefix+'_'+fieldnames[i]+']').prop('disabled',true); } for (var i = 0; i < daysofweek.length; i++){ - $j('#'+prefix+'_'+daysofweek[i].toLowerCase()).prop("disabled",true); + $j('#'+prefix+'_'+daysofweek[i].toLowerCase()).prop('disabled',true); } for (var i = 0; i < fieldnames2.length; i++){ - $j('[name='+prefix2+'_'+fieldnames2[i]+']').addClass("disabled"); - $j('[name='+prefix2+'_'+fieldnames2[i]+']').prop("disabled",true); + $j('[name='+prefix2+'_'+fieldnames2[i]+']').addClass('disabled'); + $j('[name='+prefix2+'_'+fieldnames2[i]+']').prop('disabled',true); } } - else if(inputvalue == "true"){ + else if(inputvalue == 'true'){ for (var i = 0; i < fieldnames.length; i++){ - $j('input[name='+prefix+'_'+fieldnames[i]+']').removeClass("disabled"); - $j('input[name='+prefix+'_'+fieldnames[i]+']').prop("disabled",false); + $j('input[name='+prefix+'_'+fieldnames[i]+']').removeClass('disabled'); + $j('input[name='+prefix+'_'+fieldnames[i]+']').prop('disabled',false); } for (var i = 0; i < daysofweek.length; i++){ - $j('#'+prefix+'_'+daysofweek[i].toLowerCase()).prop("disabled",false); + $j('#'+prefix+'_'+daysofweek[i].toLowerCase()).prop('disabled',false); } for (var i = 0; i < fieldnames2.length; i++){ - $j('[name='+prefix2+'_'+fieldnames2[i]+']').removeClass("disabled"); - $j('[name='+prefix2+'_'+fieldnames2[i]+']').prop("disabled",false); + $j('[name='+prefix2+'_'+fieldnames2[i]+']').removeClass('disabled'); + $j('[name='+prefix2+'_'+fieldnames2[i]+']').prop('disabled',false); } } } @@ -160,7 +161,7 @@ function ScheduleOptionsEnableDisable(forminput){ function PopulateCountryDropdown(vpnclient){ for (var vpnno = 1; vpnno < 6; vpnno++){ - if(vpnclient != "all"){ + if(vpnclient != 'all'){ if(vpnno != vpnclient){ continue; } @@ -170,27 +171,27 @@ function PopulateCountryDropdown(vpnclient){ var countryarray = []; - if(eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value == "NordVPN"){ + if(eval('document.form.vpnmgr_vpn'+vpnno+'_provider').value == 'NordVPN'){ dropdown.append(''); - dropdown.prop('selectedIndex', 0); + dropdown.prop('selectedIndex',0); countryarray = nordvpncountries; } - else if(eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value == "PIA"){ + else if(eval('document.form.vpnmgr_vpn'+vpnno+'_provider').value == 'PIA'){ countryarray = piacountries; } - else if(eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value == "WeVPN"){ + else if(eval('document.form.vpnmgr_vpn'+vpnno+'_provider').value == 'WeVPN'){ countryarray = wevpncountries; } - $j.each(countryarray, function (key, entry){ - dropdown.append($j('').attr('value', entry.name).text(entry.name)); + $j.each(countryarray,function (key,entry){ + dropdown.append($j('').attr('value',entry.name).text(entry.name)); }); } } function PopulateCityDropdown(vpnclient){ for (var vpnno = 1; vpnno < 6; vpnno++){ - if(vpnclient != "all"){ + if(vpnclient != 'all'){ if(vpnno != vpnclient){ continue; } @@ -198,25 +199,25 @@ function PopulateCityDropdown(vpnclient){ let dropdown = $j('#vpnmgr_vpn'+vpnno+'_cityname'); dropdown.empty(); - if(eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value == "NordVPN"){ + if(eval('document.form.vpnmgr_vpn'+vpnno+'_provider').value == 'NordVPN'){ dropdown.append(''); - dropdown.prop('selectedIndex', 0); + dropdown.prop('selectedIndex',0); cityarray = nordvpncountries; } - else if(eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value == "PIA"){ + else if(eval('document.form.vpnmgr_vpn'+vpnno+'_provider').value == 'PIA'){ cityarray = piacountries; } - else if(eval("document.form.vpnmgr_vpn"+vpnno+"_provider").value == "WeVPN"){ + else if(eval('document.form.vpnmgr_vpn'+vpnno+'_provider').value == 'WeVPN'){ cityarray = wevpncountries; } - $j.each(cityarray, function (key, entry){ - if(entry.name != eval("document.form.vpnmgr_vpn"+vpnno+"_countryname").value){ + $j.each(cityarray,function (key,entry){ + if(entry.name != eval('document.form.vpnmgr_vpn'+vpnno+'_countryname').value){ return true; } else{ - $j.each(entry.cities, function (key2, entry2){ - dropdown.append($j('').attr('value', entry2.name).text(entry2.name)); + $j.each(entry.cities,function (key2,entry2){ + dropdown.append($j('').attr('value',entry2.name).text(entry2.name)); }); return false; } @@ -229,23 +230,23 @@ function ScheduleModeToggle(forminput){ var inputvalue = forminput.value; var prefix = inputname.substring(0,inputname.lastIndexOf('_')); - if(inputvalue == "EveryX"){ - showhide(prefix+"_schedulefrequency",true); - showhide(prefix+"_customhours",false); - showhide(prefix+"_custommins",false); - if($j("#"+prefix+"_everyxselect").val() == "hours"){ - showhide(prefix+"_spanxhours",true); - showhide(prefix+"_spanxminutes",false); - } - else if($j("#"+prefix+"_everyxselect").val() == "minutes"){ - showhide(prefix+"_spanxhours",false); - showhide(prefix+"_spanxminutes",true); + if(inputvalue == 'EveryX'){ + showhide(prefix+'_schedulefrequency',true); + showhide(prefix+'_customhours',false); + showhide(prefix+'_custommins',false); + if($j('#'+prefix+'_everyxselect').val() == 'hours'){ + showhide(prefix+'_spanxhours',true); + showhide(prefix+'_spanxminutes',false); + } + else if($j('#'+prefix+'_everyxselect').val() == 'minutes'){ + showhide(prefix+'_spanxhours',false); + showhide(prefix+'_spanxminutes',true); } } - else if(inputvalue == "Custom"){ - showhide(prefix+"_schedulefrequency",false); - showhide(prefix+"_customhours",true); - showhide(prefix+"_custommins",true); + else if(inputvalue == 'Custom'){ + showhide(prefix+'_schedulefrequency',false); + showhide(prefix+'_customhours',true); + showhide(prefix+'_custommins',true); } } @@ -254,16 +255,16 @@ function EveryXToggle(forminput){ var inputvalue = forminput.value; var prefix = inputname.substring(0,inputname.lastIndexOf('_')); - if(inputvalue == "hours"){ - showhide(prefix+"_spanxhours",true); - showhide(prefix+"_spanxminutes",false); + if(inputvalue == 'hours'){ + showhide(prefix+'_spanxhours',true); + showhide(prefix+'_spanxminutes',false); } - else if(inputvalue == "minutes"){ - showhide(prefix+"_spanxhours",false); - showhide(prefix+"_spanxminutes",true); + else if(inputvalue == 'minutes'){ + showhide(prefix+'_spanxhours',false); + showhide(prefix+'_spanxminutes',true); } - Validate_ScheduleValue($j("[name="+prefix+"_everyxvalue]")[0]); + Validate_ScheduleValue($j('[name='+prefix+'_everyxvalue]')[0]); } function Validate_Schedule(forminput,hoursmins){ @@ -271,43 +272,43 @@ function Validate_Schedule(forminput,hoursmins){ var inputvalues = forminput.value.split(','); var upperlimit = 0; - if(hoursmins == "hours"){ + if(hoursmins == 'hours'){ upperlimit = 23; } - else if (hoursmins == "mins"){ + else if (hoursmins == 'mins'){ upperlimit = 59; } - var validationfailed = "false"; + var validationfailed = 'false'; for(var i=0; i < inputvalues.length; i++){ - if(inputvalues[i] == "*" && i == 0){ - validationfailed = "false"; + if(inputvalues[i] == '*' && i == 0){ + validationfailed = 'false'; } - else if(inputvalues[i] == "*" && i != 0){ - validationfailed = "true"; + else if(inputvalues[i] == '*' && i != 0){ + validationfailed = 'true'; } - else if(inputvalues[0] == "*" && i > 0){ - validationfailed = "true"; + else if(inputvalues[0] == '*' && i > 0){ + validationfailed = 'true'; } - else if(inputvalues[i] == ""){ - validationfailed = "true"; + else if(inputvalues[i] == ''){ + validationfailed = 'true'; } else if(! isNaN(inputvalues[i]*1)){ if((inputvalues[i]*1) > upperlimit || (inputvalues[i]*1) < 0){ - validationfailed = "true"; + validationfailed = 'true'; } } else{ - validationfailed = "true"; + validationfailed = 'true'; } } - if(validationfailed == "true"){ - $j(forminput).addClass("invalid"); + if(validationfailed == 'true'){ + $j(forminput).addClass('invalid'); return false; } else{ - $j(forminput).removeClass("invalid"); + $j(forminput).removeClass('invalid'); return true; } } @@ -320,21 +321,21 @@ function Validate_ScheduleValue(forminput){ var upperlimit = 0; var lowerlimit = 1; - var unittype = $j("#"+prefix+"_everyxselect").val(); + var unittype = $j('#'+prefix+'_everyxselect').val(); - if(unittype == "hours"){ + if(unittype == 'hours'){ upperlimit = 24; } - else if(unittype == "minutes"){ + else if(unittype == 'minutes'){ upperlimit = 30; } if(inputvalue > upperlimit || inputvalue < lowerlimit || forminput.value.length < 1){ - $j(forminput).addClass("invalid"); + $j(forminput).addClass('invalid'); return false; } else{ - $j(forminput).removeClass("invalid"); + $j(forminput).removeClass('invalid'); return true; } } @@ -342,16 +343,16 @@ function Validate_ScheduleValue(forminput){ function Validate_All(){ var validationfailed = false; for(var i=1; i < 6; i++){ - if(eval("document.form.vpn"+i+"_schedulemode").value == "EveryX"){ - if(! Validate_ScheduleValue(eval("document.form.vpn"+i+"_everyxvalue"))) validationfailed=true; + if(eval('document.form.vpn'+i+'_schedulemode').value == 'EveryX'){ + if(! Validate_ScheduleValue(eval('document.form.vpn'+i+'_everyxvalue'))) validationfailed=true; } - else if(eval("document.form.vpn"+i+"_schedulemode").value == "Custom"){ - if(! Validate_Schedule(eval("document.form.vpnmgr_vpn"+i+"_schhours"),"hours")) validationfailed=true; - if(! Validate_Schedule(eval("document.form.vpnmgr_vpn"+i+"_schmins"),"mins")) validationfailed=true; + else if(eval('document.form.vpn'+i+'_schedulemode').value == 'Custom'){ + if(! Validate_Schedule(eval('document.form.vpnmgr_vpn'+i+'_schhours'),'hours')) validationfailed=true; + if(! Validate_Schedule(eval('document.form.vpnmgr_vpn'+i+'_schmins'),'mins')) validationfailed=true; } } if(validationfailed){ - alert("Validation for some fields failed. Please correct invalid values and try again."); + alert('Validation for some fields failed. Please correct invalid values and try again.'); return false; } else{ @@ -364,107 +365,107 @@ function get_conf_file(){ url: '/ext/vpnmgr/config.htm', dataType: 'text', error: function(xhr){ - setTimeout(get_conf_file, 1000); + setTimeout(get_conf_file,1000); }, success: function(data){ - var settings = data.split("\n"); + var settings = data.split('\n'); settings.reverse(); settings = settings.filter(Boolean); var settingcount = settings.length; - window["vpnmgr_settings"] = []; + window['vpnmgr_settings'] = []; for (var i = 0; i < settingcount; i++){ - if (settings[i].indexOf("#") != -1){ + if (settings[i].indexOf('#') != -1){ continue } - var setting = settings[i].split("="); - window["vpnmgr_settings"].unshift(setting); + var setting = settings[i].split('='); + window['vpnmgr_settings'].unshift(setting); } for (var vpnno = 5; vpnno >= 1; vpnno--){ - $j("#table_scripttools").after(BuildConfigTable("vpn"+vpnno,"VPN Client "+vpnno)); + $j('#table_scripttools').after(BuildConfigTable('vpn'+vpnno,'VPN Client '+vpnno)); } - for (var i = 0; i < window["vpnmgr_settings"].length; i++){ - let settingname = window["vpnmgr_settings"][i][0]; - let settingvalue = window["vpnmgr_settings"][i][1]; - if(settingname.indexOf("cityid") != -1 || settingname.indexOf("countryid") != -1 || settingname.indexOf("countryname") != -1 || settingname.indexOf("cityname") != -1) continue; - if(settingname.indexOf("schdays") == -1){ - eval("document.form.vpnmgr_"+settingname).value = settingvalue; - if(settingname.indexOf("managed") != -1) OptionsEnableDisable($j("#vpnmgr_"+settingname.replace("_managed","")+"_man_"+settingvalue)[0],true); - if(settingname.indexOf("schenabled") != -1) ScheduleOptionsEnableDisable($j("#vpnmgr_"+settingname.replace("_schenabled","")+"_sch_"+settingvalue)[0]); - if(settingname.indexOf("provider") != -1) VPNTypesToggle($j("#vpnmgr_"+settingname.replace("_provider","")+"_prov_"+settingvalue.toLowerCase())[0]); + for (var i = 0; i < window['vpnmgr_settings'].length; i++){ + let settingname = window['vpnmgr_settings'][i][0]; + let settingvalue = window['vpnmgr_settings'][i][1]; + if(settingname.indexOf('cityid') != -1 || settingname.indexOf('countryid') != -1 || settingname.indexOf('countryname') != -1 || settingname.indexOf('cityname') != -1) continue; + if(settingname.indexOf('schdays') == -1){ + eval('document.form.vpnmgr_'+settingname).value = settingvalue; + if(settingname.indexOf('managed') != -1) OptionsEnableDisable($j('#vpnmgr_'+settingname.replace('_managed','')+'_man_'+settingvalue)[0],true); + if(settingname.indexOf('schenabled') != -1) ScheduleOptionsEnableDisable($j('#vpnmgr_'+settingname.replace('_schenabled','')+'_sch_'+settingvalue)[0]); + if(settingname.indexOf('provider') != -1) VPNTypesToggle($j('#vpnmgr_'+settingname.replace('_provider','')+'_prov_'+settingvalue.toLowerCase())[0]); } else{ - if(settingvalue == "*"){ + if(settingvalue == '*'){ for (var i2 = 0; i2 < daysofweek.length; i2++){ - $j("#vpnmgr_"+settingname.substring(0,vpnmgr_settings[i][0].indexOf('_'))+"_"+daysofweek[i2].toLowerCase()).prop("checked",true); + $j('#vpnmgr_'+settingname.substring(0,vpnmgr_settings[i][0].indexOf('_'))+'_'+daysofweek[i2].toLowerCase()).prop('checked',true); } } else{ var schdayarray = settingvalue.split(','); for (var i2 = 0; i2 < schdayarray.length; i2++){ - $j("#vpnmgr_"+settingname.substring(0,vpnmgr_settings[i][0].indexOf('_'))+"_"+schdayarray[i2].toLowerCase()).prop("checked",true); + $j('#vpnmgr_'+settingname.substring(0,vpnmgr_settings[i][0].indexOf('_'))+'_'+schdayarray[i2].toLowerCase()).prop('checked',true); } } } } - PopulateCountryDropdown("all"); + PopulateCountryDropdown('all'); for (var i = 1; i < 6; i++){ - eval("document.form.vpnmgr_vpn"+i+"_countryname").value = window["vpnmgr_settings"].filter(function(item){ - return item[0] == "vpn"+i+"_countryname"; + eval('document.form.vpnmgr_vpn'+i+'_countryname').value = window['vpnmgr_settings'].filter(function(item){ + return item[0] == 'vpn'+i+'_countryname'; })[0][1]; - if(eval("document.form.vpnmgr_vpn"+i+"_countryname").value == ""){ - $j('#vpnmgr_vpn'+i+'_cityname').prop("disabled",true); + if(eval('document.form.vpnmgr_vpn'+i+'_countryname').value == ''){ + $j('#vpnmgr_vpn'+i+'_cityname').prop('disabled',true); } - else if(eval("document.form.vpnmgr_vpn"+i+"_countryname").value != ""){ - $j('#vpnmgr_vpn'+i+'_cityname').prop("disabled",false); + else if(eval('document.form.vpnmgr_vpn'+i+'_countryname').value != ''){ + $j('#vpnmgr_vpn'+i+'_cityname').prop('disabled',false); } - if(eval("document.form.vpnmgr_vpn"+i+"_countryname").value == "" && eval("document.form.vpnmgr_vpn"+i+"_countryname").length == 1){ - $j('#vpnmgr_vpn'+i+'_cityname').prop("disabled",true); + if(eval('document.form.vpnmgr_vpn'+i+'_countryname').value == '' && eval('document.form.vpnmgr_vpn'+i+'_countryname').length == 1){ + $j('#vpnmgr_vpn'+i+'_cityname').prop('disabled',true); } } - PopulateCityDropdown("all"); + PopulateCityDropdown('all'); for (var i = 1; i < 6; i++){ - eval("document.form.vpnmgr_vpn"+i+"_cityname").value = window["vpnmgr_settings"].filter(function(item){ - return item[0] == "vpn"+i+"_cityname"; + eval('document.form.vpnmgr_vpn'+i+'_cityname').value = window['vpnmgr_settings'].filter(function(item){ + return item[0] == 'vpn'+i+'_cityname'; })[0][1]; - if((eval("document.form.vpnmgr_vpn"+i+"_cityname").length == 0) || (eval("document.form.vpnmgr_vpn"+i+"_cityname").length == 1 && eval("document.form.vpnmgr_vpn"+i+"_cityname").value == "")){ - $j('#vpnmgr_vpn'+i+'_cityname').prop("disabled",true); + if((eval('document.form.vpnmgr_vpn'+i+'_cityname').length == 0) || (eval('document.form.vpnmgr_vpn'+i+'_cityname').length == 1 && eval('document.form.vpnmgr_vpn'+i+'_cityname').value == '')){ + $j('#vpnmgr_vpn'+i+'_cityname').prop('disabled',true); } - else if(eval("document.form.vpnmgr_vpn"+i+"_cityname").length > 0){ - $j('#vpnmgr_vpn'+i+'_cityname').prop("disabled",false); + else if(eval('document.form.vpnmgr_vpn'+i+'_cityname').length > 0){ + $j('#vpnmgr_vpn'+i+'_cityname').prop('disabled',false); } } for (var i = 1; i < 6; i++){ - eval("document.form.vpnmgr_vpn"+i+"_usn").value = eval("document.form.vpn"+i+"_usn").value; - eval("document.form.vpnmgr_vpn"+i+"_pwd").value = eval("document.form.vpn"+i+"_pwd").value; + eval('document.form.vpnmgr_vpn'+i+'_usn').value = eval('document.form.vpn'+i+'_usn').value; + eval('document.form.vpnmgr_vpn'+i+'_pwd').value = eval('document.form.vpn'+i+'_pwd').value; if($j('[name=vpnmgr_vpn'+i+'_schhours]').val().indexOf('/') != -1){ - eval("document.form.vpn"+i+"_schedulemode").value = "EveryX"; - eval("document.form.vpn"+i+"_everyxselect").value = "hours"; - eval("document.form.vpn"+i+"_everyxvalue").value = $j('[name=vpnmgr_vpn'+i+'_schhours]').val().split('/')[1]; + eval('document.form.vpn'+i+'_schedulemode').value = 'EveryX'; + eval('document.form.vpn'+i+'_everyxselect').value = 'hours'; + eval('document.form.vpn'+i+'_everyxvalue').value = $j('[name=vpnmgr_vpn'+i+'_schhours]').val().split('/')[1]; } else if($j('[name=vpnmgr_vpn'+i+'_schmins]').val().indexOf('/') != -1){ - eval("document.form.vpn"+i+"_schedulemode").value = "EveryX"; - eval("document.form.vpn"+i+"_everyxselect").value = "minutes"; - eval("document.form.vpn"+i+"_everyxvalue").value = $j('[name=vpnmgr_vpn'+i+'_schmins]').val().split('/')[1]; + eval('document.form.vpn'+i+'_schedulemode').value = 'EveryX'; + eval('document.form.vpn'+i+'_everyxselect').value = 'minutes'; + eval('document.form.vpn'+i+'_everyxvalue').value = $j('[name=vpnmgr_vpn'+i+'_schmins]').val().split('/')[1]; } else{ - eval("document.form.vpn"+i+"_schedulemode").value = "Custom"; + eval('document.form.vpn'+i+'_schedulemode').value = 'Custom'; } ScheduleModeToggle($j('#vpn'+i+'_schmode_'+$j('[name=vpn'+i+'_schedulemode]:checked').val().toLowerCase())[0]); } - showhide("imgRefreshCachedData", false); - showhide("refreshcacheddata_text", false); - showhide("btnRefreshCachedData", true); + showhide('imgRefreshCachedData',false); + showhide('refreshcacheddata_text',false); + showhide('btnRefreshCachedData',true); AddEventHandlers(); } @@ -472,22 +473,21 @@ function get_conf_file(){ } function GetCookie(cookiename,returntype){ - var s; - if((s = cookie.get("vpnmgr_"+cookiename)) != null){ - return cookie.get("vpnmgr_"+cookiename); + if(cookie.get('vpnmgr_'+cookiename) != null){ + return cookie.get('vpnmgr_'+cookiename); } else{ - if(returntype == "string"){ - return ""; + if(returntype == 'string'){ + return ''; } - else if(returntype == "number"){ + else if(returntype == 'number'){ return 0; } } } function SetCookie(cookiename,cookievalue){ - cookie.set("vpnmgr_"+cookiename, cookievalue, 31); + cookie.set('vpnmgr_'+cookiename,cookievalue,10*365); } function SetCurrentPage(){ @@ -500,34 +500,34 @@ function reload(){ } function pass_checked(obj,showobj){ -switchType(obj, showobj.checked, true); +switchType(obj,showobj.checked,true); } function SaveConfig(){ if(Validate_All()){ for(var i=1; i < 6; i++){ - if(eval("document.form.vpn"+i+"_schedulemode").value == "EveryX"){ - if(eval("document.form.vpn"+i+"_everyxselect").value == "hours"){ - var everyxvalue = eval("document.form.vpn"+i+"_everyxvalue").value*1; - eval("document.form.vpnmgr_vpn"+i+"_schmins").value = 0; + if(eval('document.form.vpn'+i+'_schedulemode').value == 'EveryX'){ + if(eval('document.form.vpn'+i+'_everyxselect').value == 'hours'){ + var everyxvalue = eval('document.form.vpn'+i+'_everyxvalue').value*1; + eval('document.form.vpnmgr_vpn'+i+'_schmins').value = 0; if(everyxvalue == 24){ - eval("document.form.vpnmgr_vpn"+i+"_schhours").value = 0; + eval('document.form.vpnmgr_vpn'+i+'_schhours').value = 0; } else{ - eval("document.form.vpnmgr_vpn"+i+"_schhours").value = "*/"+everyxvalue; + eval('document.form.vpnmgr_vpn'+i+'_schhours').value = '*/'+everyxvalue; } } - else if(eval("document.form.vpn"+i+"_everyxselect").value == "minutes"){ - eval("document.form.vpnmgr_vpn"+i+"_schhours").value = 0; - var everyxvalue = eval("document.form.vpn"+i+"_everyxvalue").value*1; - eval("document.form.vpnmgr_vpn"+i+"_schmins").value = "*/"+everyxvalue; + else if(eval('document.form.vpn'+i+'_everyxselect').value == 'minutes'){ + eval('document.form.vpnmgr_vpn'+i+'_schhours').value = 0; + var everyxvalue = eval('document.form.vpn'+i+'_everyxvalue').value*1; + eval('document.form.vpnmgr_vpn'+i+'_schmins').value = '*/'+everyxvalue; } } } - $j('[name*=vpnmgr_]').prop("disabled",false); + $j('[name*=vpnmgr_]').prop('disabled',false); document.getElementById('amng_custom').value = JSON.stringify($j('form').serializeObject()); - var action_script_tmp = "start_vpnmgr"; + var action_script_tmp = 'start_vpnmgr'; document.form.action_script.value = action_script_tmp; var restart_time = 15; document.form.action_wait.value = restart_time; @@ -569,12 +569,12 @@ function BuildConfigTable(prefix,title){ /* MANAGEMENT ENABLED */ charthtml+=''; - charthtml+='Managed by vpnmgr?'; + charthtml+='Managed by vpnmgr?'; charthtml+=''; /* PROVIDER */ charthtml+=''; - charthtml+='VPN Provider'; + charthtml+='VPN Provider'; charthtml+=''; /* USERNAME ENABLED */ @@ -587,14 +587,19 @@ function BuildConfigTable(prefix,title){ charthtml+='Password   '; charthtml+=''; + /* CUSTOM SETTINGS */ + charthtml+=''; + charthtml+='Use vpnmgr custom settings?'; + charthtml+=''; + /* TYPE */ charthtml+=''; - charthtml+='Type'; + charthtml+='Type'; charthtml+=''; /* PROTOCOL */ charthtml+=''; - charthtml+='Protocol'; + charthtml+='Protocol'; charthtml+=''; /* COUNTRY */ @@ -609,31 +614,31 @@ function BuildConfigTable(prefix,title){ /* SCHEDULE ENABLED */ charthtml+=''; - charthtml+='Scheduled update/reload?'; + charthtml+='Scheduled update/reload?'; charthtml+=''; /* SCHEDULE DAYS */ charthtml+=''; charthtml+='Schedule Days'; - charthtml+=''; - charthtml+=''; - charthtml+=''; - charthtml+=''; - charthtml+=''; - charthtml+=''; - charthtml+=''; + charthtml+=''; + charthtml+=''; + charthtml+=''; + charthtml+=''; + charthtml+=''; + charthtml+=''; + charthtml+=''; charthtml+=''; /* SCHEDULE MODE */ charthtml+=''; - charthtml+='Schedule Mode'; + charthtml+='Schedule Mode'; charthtml+=''; /* SCHEDULE FREQUENCY */ charthtml+=''; charthtml+='Frequency'; charthtml+='Every '; - charthtml+=''; + charthtml+=''; charthtml+=' '; charthtml+=' (between 1 and 24)'; @@ -658,18 +663,18 @@ function BuildConfigTable(prefix,title){ } function AddEventHandlers(){ - $j(".collapsible-jquery").click(function(){ - $j(this).siblings().toggle("fast",function(){ - if($j(this).css("display") == "none"){ - SetCookie($j(this).siblings()[0].id,"collapsed"); + $j('.collapsible-jquery').click(function(){ + $j(this).siblings().toggle('fast',function(){ + if($j(this).css('display') == 'none'){ + SetCookie($j(this).siblings()[0].id,'collapsed'); } else{ - SetCookie($j(this).siblings()[0].id,"expanded"); + SetCookie($j(this).siblings()[0].id,'expanded'); } }) }); - $j(".collapsible-jquery").each(function(index,element){ - if(GetCookie($j(this)[0].id,"string") == "collapsed"){ + $j('.collapsible-jquery').each(function(index,element){ + if(GetCookie($j(this)[0].id,'string') == 'collapsed'){ $j(this).siblings().toggle(false); } else{ @@ -681,49 +686,49 @@ function AddEventHandlers(){ $j.fn.serializeObject = function(){ var o = custom_settings; var a = this.serializeArray(); - $j.each(a, function(){ - if (o[this.name] !== undefined && this.name.indexOf("vpnmgr") != -1 && this.name.indexOf("version") == -1 && this.name.indexOf("schdays") == -1 && this.name.indexOf("countryid") == -1 && this.name.indexOf("cityid") == -1){ + $j.each(a,function(){ + if (o[this.name] !== undefined && this.name.indexOf('vpnmgr') != -1 && this.name.indexOf('version') == -1 && this.name.indexOf('schdays') == -1 && this.name.indexOf('countryid') == -1 && this.name.indexOf('cityid') == -1){ if (!o[this.name].push){ o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } - else if (this.name.indexOf("vpnmgr") != -1 && this.name.indexOf("version") == -1 && this.name.indexOf("schdays") == -1 && this.name.indexOf("countryid") == -1 && this.name.indexOf("cityid") == -1){ + else if (this.name.indexOf('vpnmgr') != -1 && this.name.indexOf('version') == -1 && this.name.indexOf('schdays') == -1 && this.name.indexOf('countryid') == -1 && this.name.indexOf('cityid') == -1){ o[this.name] = this.value || ''; } }); for(var i=1; i < 6; i++){ var schdays = []; - $j.each($j("input[name='vpnmgr_vpn"+i+"_schdays']:checked"), function(){ + $j.each($j('input[name="vpnmgr_vpn'+i+'_schdays"]:checked'),function(){ schdays.push($j(this).val()); }); - var schdaysstring = schdays.join(","); - if(schdaysstring == "Mon,Tues,Wed,Thurs,Fri,Sat,Sun"){ - schdaysstring = "*"; + var schdaysstring = schdays.join(','); + if(schdaysstring == 'Mon,Tues,Wed,Thurs,Fri,Sat,Sun'){ + schdaysstring = '*'; } - o["vpnmgr_vpn"+i+"_schdays"] = schdaysstring; + o['vpnmgr_vpn'+i+'_schdays'] = schdaysstring; - if($j("select[name='vpnmgr_vpn"+i+"_countryname']").val() == "" || $j("input[name='vpnmgr_vpn"+i+"_provider']:checked").val() == "PIA"){ - o["vpnmgr_vpn"+i+"_countryid"] = 0; - o["vpnmgr_vpn"+i+"_cityid"] = 0; + if($j('select[name="vpnmgr_vpn'+i+'_countryname"]').val() == '' || $j('input[name="vpnmgr_vpn'+i+'_provider"]:checked').val() == 'PIA'){ + o['vpnmgr_vpn'+i+'_countryid'] = 0; + o['vpnmgr_vpn'+i+'_cityid'] = 0; } - else if($j("select[name='vpnmgr_vpn"+i+"_countryname']").val() == "" || $j("input[name='vpnmgr_vpn"+i+"_provider']:checked").val() == "WeVPN"){ - o["vpnmgr_vpn"+i+"_countryid"] = 0; - o["vpnmgr_vpn"+i+"_cityid"] = 0; + else if($j('select[name="vpnmgr_vpn'+i+'_countryname"]').val() == '' || $j('input[name="vpnmgr_vpn'+i+'_provider"]:checked').val() == 'WeVPN'){ + o['vpnmgr_vpn'+i+'_countryid'] = 0; + o['vpnmgr_vpn'+i+'_cityid'] = 0; } else{ - o["vpnmgr_vpn"+i+"_countryid"] = nordvpncountries.filter(function(item){ - return item.name == $j("select[name='vpnmgr_vpn"+i+"_countryname']").val(); + o['vpnmgr_vpn'+i+'_countryid'] = nordvpncountries.filter(function(item){ + return item.name == $j('select[name="vpnmgr_vpn'+i+'_countryname"]').val(); }).map(function(d){return d.id})[0]; - if($j("select[name='vpnmgr_vpn"+i+"_cityname']").val() == ""){ - o["vpnmgr_vpn"+i+"_cityid"] = 0; + if($j('select[name="vpnmgr_vpn'+i+'_cityname"]').val() == ''){ + o['vpnmgr_vpn'+i+'_cityid'] = 0; } else{ - o["vpnmgr_vpn"+i+"_cityid"] = nordvpncountries.filter(function(item){ - return item.name == $j("select[name='vpnmgr_vpn"+i+"_countryname']").val(); + o['vpnmgr_vpn'+i+'_cityid'] = nordvpncountries.filter(function(item){ + return item.name == $j('select[name="vpnmgr_vpn'+i+'_countryname"]').val(); })[0].cities.filter(function(item){ - return item.name == $j("select[name='vpnmgr_vpn"+i+"_cityname']").val(); + return item.name == $j('select[name="vpnmgr_vpn'+i+'_cityname"]').val(); }).map(function(d){return d.id})[0]; } } @@ -732,15 +737,15 @@ $j.fn.serializeObject = function(){ }; function ScriptUpdateLayout(){ - var localver = GetVersionNumber("local"); - var serverver = GetVersionNumber("server"); - $j("#vpnmgr_version_local").text(localver); + var localver = GetVersionNumber('local'); + var serverver = GetVersionNumber('server'); + $j('#vpnmgr_version_local').text(localver); - if (localver != serverver && serverver != "N/A"){ - $j("#vpnmgr_version_server").text("Updated version available: "+serverver); - showhide("btnChkUpdate", false); - showhide("vpnmgr_version_server", true); - showhide("btnDoUpdate", true); + if (localver != serverver && serverver != 'N/A'){ + $j('#vpnmgr_version_server').text('Updated version available: '+serverver); + showhide('btnChkUpdate',false); + showhide('vpnmgr_version_server',true); + showhide('btnDoUpdate',true); } } @@ -748,26 +753,25 @@ function update_status(){ $j.ajax({ url: '/ext/vpnmgr/detect_update.js', dataType: 'script', - timeout: 3000, error: function(xhr){ - setTimeout(update_status, 1000); + setTimeout(update_status,1000); }, success: function(){ - if (updatestatus == "InProgress"){ - setTimeout(update_status, 1000); + if (updatestatus == 'InProgress'){ + setTimeout(update_status,1000); } else{ - document.getElementById("imgChkUpdate").style.display = "none"; - showhide("vpnmgr_version_server", true); - if(updatestatus != "None"){ - $j("#vpnmgr_version_server").text("Updated version available: "+updatestatus); - showhide("btnChkUpdate", false); - showhide("btnDoUpdate", true); + document.getElementById('imgChkUpdate').style.display = 'none'; + showhide('vpnmgr_version_server',true); + if(updatestatus != 'None'){ + $j('#vpnmgr_version_server').text('Updated version available: '+updatestatus); + showhide('btnChkUpdate',false); + showhide('btnDoUpdate',true); } else{ - $j("#vpnmgr_version_server").text("No update available"); - showhide("btnChkUpdate", true); - showhide("btnDoUpdate", false); + $j('#vpnmgr_version_server').text('No update available'); + showhide('btnChkUpdate',true); + showhide('btnDoUpdate',false); } } } @@ -775,15 +779,15 @@ function update_status(){ } function CheckUpdate(){ - showhide("btnChkUpdate", false); - document.formScriptActions.action_script.value="start_vpnmgrcheckupdate"; + showhide('btnChkUpdate',false); + document.formScriptActions.action_script.value='start_vpnmgrcheckupdate'; document.formScriptActions.submit(); - document.getElementById("imgChkUpdate").style.display = ""; - setTimeout(update_status, 2000); + document.getElementById('imgChkUpdate').style.display = ''; + setTimeout(update_status,2000); } function DoUpdate(){ - var action_script_tmp = "start_vpnmgrdoupdate"; + var action_script_tmp = 'start_vpnmgrdoupdate'; document.form.action_script.value = action_script_tmp; var restart_time = 10; document.form.action_wait.value = restart_time; @@ -795,58 +799,57 @@ function getserverload_status(){ $j.ajax({ url: '/ext/vpnmgr/vpnmgrserverloads.js', dataType: 'script', - timeout: 1000, error: function(xhr){ //do nothing }, success: function(data){ clearInterval(getserverloadinterval); - showhide("imgGetServerLoad", false); - showhide("getserverload_text", true); + showhide('imgGetServerLoad',false); + showhide('getserverload_text',true); for(var i=1; i<=5; i++){ try{ - if($j("#vpnmgr_vpn"+i+"_desc").html().indexOf("|") != -1){ - $j("#vpnmgr_vpn"+i+"_desc").html($j("#vpnmgr_vpn"+i+"_desc").html().substring(0,$j("#vpnmgr_vpn"+i+"_desc").html().indexOf("|")-1) + " | " + eval("vpn"+i+"_serverload") + "%"); + if($j('#vpnmgr_vpn'+i+'_desc').html().indexOf('|') != -1){ + $j('#vpnmgr_vpn'+i+'_desc').html($j('#vpnmgr_vpn'+i+'_desc').html().substring(0,$j('#vpnmgr_vpn'+i+'_desc').html().indexOf('|')-1)+' | '+eval('vpn'+i+'_serverload')+'%'); } else{ - $j("#vpnmgr_vpn"+i+"_desc").html($j("#vpnmgr_vpn"+i+"_desc").html() + " | " + eval("vpn"+i+"_serverload") + "%"); + $j('#vpnmgr_vpn'+i+'_desc').html($j('#vpnmgr_vpn'+i+'_desc').html()+' | '+eval('vpn'+i+'_serverload')+'%'); } } catch(err){ continue; } } - setTimeout(showhide, 3000,'getserverload_text',false); - setTimeout(showhide, 3100,'btnGetServerLoad',true); + setTimeout(showhide,3000,'getserverload_text',false); + setTimeout(showhide,3100,'btnGetServerLoad',true); } }); } function GetServerLoad(){ - showhide("btnGetServerLoad", false); - document.formScriptActions.action_script.value = "start_vpnmgrgetserverload"; + showhide('btnGetServerLoad',false); + document.formScriptActions.action_script.value = 'start_vpnmgrgetserverload'; document.formScriptActions.submit(); - showhide("imgGetServerLoad", true); - showhide("getserverload_text", false); - setTimeout(StartGetServerLoadInterval, 1000); + showhide('imgGetServerLoad',true); + showhide('getserverload_text',false); + setTimeout(StartGetServerLoadInterval,5000); } function StartGetServerLoadInterval(){ - getserverloadinterval = setInterval(getserverload_status, 1000); + getserverloadinterval = setInterval(getserverload_status,1000); } function RefreshCachedData(){ - showhide("btnRefreshCachedData", false); - document.formScriptActions.action_script.value = "start_vpnmgrrefreshcacheddata"; + showhide('btnRefreshCachedData',false); + document.formScriptActions.action_script.value = 'start_vpnmgrrefreshcacheddata'; document.formScriptActions.submit(); - showhide("imgRefreshCachedData", true); - showhide("refreshcacheddata_text", false); - setTimeout(StartRefreshCachedDataInterval, 1000); + showhide('imgRefreshCachedData',true); + showhide('refreshcacheddata_text',false); + setTimeout(StartRefreshCachedDataInterval,5000); } function StartRefreshCachedDataInterval(){ - refreshcacheddatainterval = setInterval(refreshcacheddata_status, 1000); + refreshcacheddatainterval = setInterval(refreshcacheddata_status,1000); } var refreshcount=1; @@ -855,27 +858,26 @@ function refreshcacheddata_status(){ $j.ajax({ url: '/ext/vpnmgr/detect_vpnmgr.js', dataType: 'script', - timeout: 1000, error: function(xhr){ //do nothing }, success: function(){ - if (refreshcacheddatastatus == "InProgress"){ - showhide("imgRefreshCachedData", true); - showhide("refreshcacheddata_text", true); - document.getElementById("refreshcacheddata_text").innerHTML = "Cached data refresh in progress - " + refreshcount + "s elapsed"; + if (refreshcacheddatastatus == 'InProgress'){ + showhide('imgRefreshCachedData',true); + showhide('refreshcacheddata_text',true); + document.getElementById('refreshcacheddata_text').innerHTML = 'Cached data refresh in progress - '+refreshcount+'s elapsed'; } - else if (refreshcacheddatastatus == "Done"){ - document.getElementById("refreshcacheddata_text").innerHTML = "Refreshing data..."; + else if (refreshcacheddatastatus == 'Done'){ + document.getElementById('refreshcacheddata_text').innerHTML = 'Refreshing data...'; refreshcount=1; clearInterval(refreshcacheddatainterval); PostRefreshCachedData(); } - else if (refreshcacheddatastatus == "LOCKED"){ - showhide("imgRefreshCachedData", false); - document.getElementById("refreshcacheddata_text").innerHTML = "Cached data refresh already running!"; - showhide("refreshcacheddata_text", true); - showhide("btnRefreshCachedData", true); + else if (refreshcacheddatastatus == 'LOCKED'){ + showhide('imgRefreshCachedData',false); + document.getElementById('refreshcacheddata_text').innerHTML = 'Cached data refresh already running!'; + showhide('refreshcacheddata_text',true); + showhide('btnRefreshCachedData',true); clearInterval(refreshcacheddatainterval); } } @@ -884,23 +886,23 @@ function refreshcacheddata_status(){ function PostRefreshCachedData(){ for (var vpnno = 1; vpnno < 6; vpnno++){ - $j("#table_config_vpn"+vpnno).prev("div").remove(); - $j("#table_config_vpn"+vpnno).remove(); + $j('#table_config_vpn'+vpnno).prev('div').remove(); + $j('#table_config_vpn'+vpnno).remove(); } - setTimeout(GetNordVPNCountryData, 3000); + setTimeout(GetNordVPNCountryData,3000); } function GetVersionNumber(versiontype){ var versionprop; - if(versiontype == "local"){ + if(versiontype == 'local'){ versionprop = custom_settings.vpnmgr_version_local; } - else if(versiontype == "server"){ + else if(versiontype == 'server'){ versionprop = custom_settings.vpnmgr_version_server; } if(typeof versionprop == 'undefined' || versionprop == null){ - return "N/A"; + return 'N/A'; } else{ return versionprop; @@ -912,7 +914,7 @@ function GetNordVPNCountryData(){ url: '/ext/vpnmgr/nordvpn_countrydata.htm', dataType: 'json', error: function(xhr){ - setTimeout(GetNordVPNCountryData, 1000); + setTimeout(GetNordVPNCountryData,1000); }, success: function(data){ nordvpncountries = data; @@ -926,7 +928,7 @@ function GetPIACountryData(){ url: '/ext/vpnmgr/pia_countrydata.htm', dataType: 'text', error: function(xhr){ - setTimeout(GetPIACountryData, 1000); + setTimeout(GetPIACountryData,1000); }, success: function(data){ piacountries = parseCountryData(data); @@ -940,7 +942,7 @@ function GetWeVPNCountryData(){ url: '/ext/vpnmgr/wevpn_countrydata.htm', dataType: 'text', error: function(xhr){ - setTimeout(GetWeVPNCountryData, 1000); + setTimeout(GetWeVPNCountryData,1000); }, success: function(data){ wevpncountries = parseCountryData(data); @@ -991,201 +993,201 @@ function parseCountryData(rawcountrydata){ var citiesSG = []; var citiesZA = []; - $j.each(tmpcountries, function (index, value){ - if(getCountryCode(value) == "AU"){ + $j.each(tmpcountries,function (index,value){ + if(getCountryCode(value) == 'AU'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("AU ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('AU ','')); citiesAU.push(obj); - value = "Australia"; + value = 'Australia'; } - else if(getCountryCode(value) == "CA"){ + else if(getCountryCode(value) == 'CA'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("CA ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('CA ','')); citiesCA.push(obj); - value = "Canada"; + value = 'Canada'; } - else if(getCountryCode(value) == "DE"){ + else if(getCountryCode(value) == 'DE'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("DE ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('DE ','')); citiesDE.push(obj); - value = "Germany"; + value = 'Germany'; } - else if(getCountryCode(value) == "US"){ + else if(getCountryCode(value) == 'US'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("US ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('US ','')); citiesUS.push(obj); - value = "United States"; + value = 'United States'; } - else if(getCountryCode(value) == "AT"){ + else if(getCountryCode(value) == 'AT'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("AT ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('AT ','')); citiesAT.push(obj); - value = "Austria"; + value = 'Austria'; } - else if(getCountryCode(value) == "BE"){ + else if(getCountryCode(value) == 'BE'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("BE ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('BE ','')); citiesBE.push(obj); - value = "Belgium"; + value = 'Belgium'; } - else if(getCountryCode(value) == "BG"){ + else if(getCountryCode(value) == 'BG'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("BG ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('BG ','')); citiesBG.push(obj); - value = "Bulgaria"; + value = 'Bulgaria'; } - else if(getCountryCode(value) == "BR"){ + else if(getCountryCode(value) == 'BR'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("BR ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('BR ','')); citiesBR.push(obj); - value = "Brazil"; + value = 'Brazil'; } - else if(getCountryCode(value) == "CH"){ + else if(getCountryCode(value) == 'CH'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("CH ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('CH ','')); citiesCH.push(obj); - value = "Switzerland"; + value = 'Switzerland'; } - else if(getCountryCode(value) == "CZ"){ + else if(getCountryCode(value) == 'CZ'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("CZ ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('CZ ','')); citiesCZ.push(obj); - value = "Czech Republic"; + value = 'Czech Republic'; } - else if(getCountryCode(value) == "DK"){ + else if(getCountryCode(value) == 'DK'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("DK ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('DK ','')); citiesDK.push(obj); - value = "Denmark"; + value = 'Denmark'; } - else if(getCountryCode(value) == "ES"){ + else if(getCountryCode(value) == 'ES'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("ES ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('ES ','')); citiesES.push(obj); - value = "Spain"; + value = 'Spain'; } - else if(getCountryCode(value) == "FR"){ + else if(getCountryCode(value) == 'FR'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("FR ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('FR ','')); citiesFR.push(obj); - value = "France"; + value = 'France'; } - else if(getCountryCode(value) == "HK"){ + else if(getCountryCode(value) == 'HK'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("HK ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('HK ','')); citiesHK.push(obj); - value = "Hong Kong"; + value = 'Hong Kong'; } - else if(getCountryCode(value) == "HU"){ + else if(getCountryCode(value) == 'HU'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("HU ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('HU ','')); citiesHU.push(obj); - value = "Hungary"; + value = 'Hungary'; } - else if(getCountryCode(value) == "IE"){ + else if(getCountryCode(value) == 'IE'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("IE ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('IE ','')); citiesIE.push(obj); - value = "Ireland"; + value = 'Ireland'; } - else if(getCountryCode(value) == "IL"){ + else if(getCountryCode(value) == 'IL'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("IL ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('IL ','')); citiesIL.push(obj); - value = "Israel"; + value = 'Israel'; } - else if(getCountryCode(value) == "IN"){ + else if(getCountryCode(value) == 'IN'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("IN ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('IN ','')); citiesIN.push(obj); - value = "India"; + value = 'India'; } - else if(getCountryCode(value) == "IT"){ + else if(getCountryCode(value) == 'IT'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("IT ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('IT ','')); citiesIT.push(obj); - value = "Italy"; + value = 'Italy'; } - else if(getCountryCode(value) == "JP"){ + else if(getCountryCode(value) == 'JP'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("JP ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('JP ','')); citiesJP.push(obj); - value = "Japan"; + value = 'Japan'; } - else if(getCountryCode(value) == "MX"){ + else if(getCountryCode(value) == 'MX'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("MX ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('MX ','')); citiesMX.push(obj); - value = "Mexico"; + value = 'Mexico'; } - else if(getCountryCode(value) == "NL"){ + else if(getCountryCode(value) == 'NL'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("NL ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('NL ','')); citiesNL.push(obj); - value = "Netherlands"; + value = 'Netherlands'; } - else if(getCountryCode(value) == "NO"){ + else if(getCountryCode(value) == 'NO'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("NO ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('NO ','')); citiesNO.push(obj); - value = "Norway"; + value = 'Norway'; } - else if(getCountryCode(value) == "NZ"){ + else if(getCountryCode(value) == 'NZ'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("NZ ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('NZ ','')); citiesNZ.push(obj); - value = "New Zealand"; + value = 'New Zealand'; } - else if(getCountryCode(value) == "PL"){ + else if(getCountryCode(value) == 'PL'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("PL ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('PL ','')); citiesPL.push(obj); - value = "Poland"; + value = 'Poland'; } - else if(getCountryCode(value) == "RO"){ + else if(getCountryCode(value) == 'RO'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("RO ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('RO ','')); citiesRO.push(obj); - value = "Romania"; + value = 'Romania'; } - else if(getCountryCode(value) == "RS"){ + else if(getCountryCode(value) == 'RS'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("RS ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('RS ','')); citiesRS.push(obj); - value = "Serbia"; + value = 'Serbia'; } - else if(getCountryCode(value) == "SE"){ + else if(getCountryCode(value) == 'SE'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("SE ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('SE ','')); citiesSE.push(obj); - value = "Sweden"; + value = 'Sweden'; } - else if(getCountryCode(value) == "SG"){ + else if(getCountryCode(value) == 'SG'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("SG ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('SG ','')); citiesSG.push(obj); - value = "Singapore"; + value = 'Singapore'; } - else if(getCountryCode(value) == "UAE" || getCountryCode(value) == "AE"){ + else if(getCountryCode(value) == 'UAE' || getCountryCode(value) == 'AE'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("UAE ","").replaceAll("AE ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('UAE ','').replaceAll('AE ','')); citiesUAE.push(obj); - value = "United Arab Emirates"; + value = 'United Arab Emirates'; } - else if(getCountryCode(value) == "UK" || getCountryCode(value) == "GB"){ + else if(getCountryCode(value) == 'UK' || getCountryCode(value) == 'GB'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("UK ","").replaceAll("GB ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('UK ','').replaceAll('GB ','')); citiesUK.push(obj); - value = "United Kingdom"; + value = 'United Kingdom'; } - else if(getCountryCode(value) == "ZA"){ + else if(getCountryCode(value) == 'ZA'){ var obj = {}; - obj["name"] = capitalizeFirstLetter(value.replaceAll("_"," ").replaceAll("ZA ","")); + obj['name'] = capitalizeFirstLetter(value.replaceAll('_',' ').replaceAll('ZA ','')); citiesZA.push(obj); - value = "South Africa"; + value = 'South Africa'; } else{ - value = capitalizeFirstLetter(value.replaceAll("_"," ")); + value = capitalizeFirstLetter(value.replaceAll('_',' ')); } tmpcountriessorted.push(value) @@ -1193,114 +1195,114 @@ function parseCountryData(rawcountrydata){ tmpcountriessorted.sort(); var unique = []; - for( let i = 0; i < tmpcountriessorted.length; i++ ){ - if( !unique[tmpcountriessorted[i]]){ + for(let i = 0; i < tmpcountriessorted.length; i++){ + if(!unique[tmpcountriessorted[i]]){ var obj = {}; - obj["name"]=tmpcountriessorted[i]; + obj['name']=tmpcountriessorted[i]; parsedarray.push(obj); unique[tmpcountriessorted[i]] = 1; } } - $j.each(parsedarray, function (key, entry){ - if(entry.name == "Australia"){ - entry["cities"] = citiesAU; + $j.each(parsedarray,function (key,entry){ + if(entry.name == 'Australia'){ + entry['cities'] = citiesAU; } - else if(entry.name == "Canada"){ - entry["cities"] = citiesCA; + else if(entry.name == 'Canada'){ + entry['cities'] = citiesCA; } - else if(entry.name == "Germany"){ - entry["cities"] = citiesDE; + else if(entry.name == 'Germany'){ + entry['cities'] = citiesDE; } - else if(entry.name == "United States"){ - entry["cities"] = citiesUS; + else if(entry.name == 'United States'){ + entry['cities'] = citiesUS; } - else if(entry.name == "United Arab Emirates"){ - entry["cities"] = citiesUAE; + else if(entry.name == 'United Arab Emirates'){ + entry['cities'] = citiesUAE; } - else if(entry.name == "United Kingdom"){ - entry["cities"] = citiesUK; + else if(entry.name == 'United Kingdom'){ + entry['cities'] = citiesUK; } - else if(entry.name == "Austria"){ - entry["cities"] = citiesAT; + else if(entry.name == 'Austria'){ + entry['cities'] = citiesAT; } - else if(entry.name == "Belgium"){ - entry["cities"] = citiesBE; + else if(entry.name == 'Belgium'){ + entry['cities'] = citiesBE; } - else if(entry.name == "Bulgaria"){ - entry["cities"] = citiesBG; + else if(entry.name == 'Bulgaria'){ + entry['cities'] = citiesBG; } - else if(entry.name == "Brazil"){ - entry["cities"] = citiesBR; + else if(entry.name == 'Brazil'){ + entry['cities'] = citiesBR; } - else if(entry.name == "Switzerland"){ - entry["cities"] = citiesCH; + else if(entry.name == 'Switzerland'){ + entry['cities'] = citiesCH; } - else if(entry.name == "Czech Republic"){ - entry["cities"] = citiesCZ; + else if(entry.name == 'Czech Republic'){ + entry['cities'] = citiesCZ; } - else if(entry.name == "Denmark"){ - entry["cities"] = citiesDK; + else if(entry.name == 'Denmark'){ + entry['cities'] = citiesDK; } - else if(entry.name == "Spain"){ - entry["cities"] = citiesES; + else if(entry.name == 'Spain'){ + entry['cities'] = citiesES; } - else if(entry.name == "France"){ - entry["cities"] = citiesFR; + else if(entry.name == 'France'){ + entry['cities'] = citiesFR; } - else if(entry.name == "Hong Kong"){ - entry["cities"] = citiesHK; + else if(entry.name == 'Hong Kong'){ + entry['cities'] = citiesHK; } - else if(entry.name == "Hungary"){ - entry["cities"] = citiesHU; + else if(entry.name == 'Hungary'){ + entry['cities'] = citiesHU; } - else if(entry.name == "Ireland"){ - entry["cities"] = citiesIE; + else if(entry.name == 'Ireland'){ + entry['cities'] = citiesIE; } - else if(entry.name == "Israel"){ - entry["cities"] = citiesIL; + else if(entry.name == 'Israel'){ + entry['cities'] = citiesIL; } - else if(entry.name == "India"){ - entry["cities"] = citiesIN; + else if(entry.name == 'India'){ + entry['cities'] = citiesIN; } - else if(entry.name == "Italy"){ - entry["cities"] = citiesIT; + else if(entry.name == 'Italy'){ + entry['cities'] = citiesIT; } - else if(entry.name == "Japan"){ - entry["cities"] = citiesJP; + else if(entry.name == 'Japan'){ + entry['cities'] = citiesJP; } - else if(entry.name == "Mexico"){ - entry["cities"] = citiesMX; + else if(entry.name == 'Mexico'){ + entry['cities'] = citiesMX; } - else if(entry.name == "Netherlands"){ - entry["cities"] = citiesNL; + else if(entry.name == 'Netherlands'){ + entry['cities'] = citiesNL; } - else if(entry.name == "Norway"){ - entry["cities"] = citiesNO; + else if(entry.name == 'Norway'){ + entry['cities'] = citiesNO; } - else if(entry.name == "New Zealand"){ - entry["cities"] = citiesNZ; + else if(entry.name == 'New Zealand'){ + entry['cities'] = citiesNZ; } - else if(entry.name == "Poland"){ - entry["cities"] = citiesPL; + else if(entry.name == 'Poland'){ + entry['cities'] = citiesPL; } - else if(entry.name == "Romania"){ - entry["cities"] = citiesRO; + else if(entry.name == 'Romania'){ + entry['cities'] = citiesRO; } - else if(entry.name == "Serbia"){ - entry["cities"] = citiesRS; + else if(entry.name == 'Serbia'){ + entry['cities'] = citiesRS; } - else if(entry.name == "Sweden"){ - entry["cities"] = citiesSE; + else if(entry.name == 'Sweden'){ + entry['cities'] = citiesSE; } - else if(entry.name == "Singapore"){ - entry["cities"] = citiesSG; + else if(entry.name == 'Singapore'){ + entry['cities'] = citiesSG; } - else if(entry.name == "South Africa"){ - entry["cities"] = citiesZA; + else if(entry.name == 'South Africa'){ + entry['cities'] = citiesZA; } else{ - entry["cities"] = []; + entry['cities'] = []; } }); @@ -1315,70 +1317,70 @@ function setCitiesforCountry(forminput){ let dropdown = $j('select[name='+prefix+'_cityname]'); dropdown.empty(); - if(eval("document.form."+prefix+"_provider").value == "NordVPN"){ + if(eval('document.form.'+prefix+'_provider').value == 'NordVPN'){ dropdown.append(''); cityarray = nordvpncountries; } - else if(eval("document.form."+prefix+"_provider").value == "PIA"){ + else if(eval('document.form.'+prefix+'_provider').value == 'PIA'){ cityarray = piacountries; } - else if(eval("document.form."+prefix+"_provider").value == "WeVPN"){ + else if(eval('document.form.'+prefix+'_provider').value == 'WeVPN'){ cityarray = wevpncountries; } - $j.each(cityarray, function (key, entry){ + $j.each(cityarray,function (key,entry){ if(entry.name != $j('select[name='+prefix+'_countryname]').val()){ return true; } else{ - $j.each(entry.cities, function (key2, entry2){ - dropdown.append($j('').attr('value', entry2.name).text(entry2.name)); + $j.each(entry.cities,function (key2,entry2){ + dropdown.append($j('').attr('value',entry2.name).text(entry2.name)); }); - if(dropdown[0].length == 2 && dropdown.find("option:first-child").val().length == 0){ - //dropdown.find("option:first-child").remove(); - dropdown.prop('selectedIndex', 0); + if(dropdown[0].length == 2 && dropdown.find('option:first-child').val().length == 0){ + //dropdown.find('option:first-child').remove(); + dropdown.prop('selectedIndex',0); } else{ - dropdown.prop('selectedIndex', 0); + dropdown.prop('selectedIndex',0); } return false; } }); - if(inputvalue == ""){ - dropdown.prop("disabled",true); + if(inputvalue == ''){ + dropdown.prop('disabled',true); } - else if(inputvalue != ""){ - dropdown.prop("disabled",false); + else if(inputvalue != ''){ + dropdown.prop('disabled',false); } if(dropdown[0].length == 0){ - dropdown.prop("disabled",true); + dropdown.prop('disabled',true); } else{ - dropdown.prop("disabled",false); + dropdown.prop('disabled',false); } } function capitalizeFirstLetter(string){ - return string.replace(/(^\w{1})|(\s{1}\w{1})/g, match => match.toUpperCase()); + return string.replace(/(^\w{1})|(\s{1}\w{1})/g,match => match.toUpperCase()); } function getCountryCode(string){ - string = string.replaceAll(" ","_"); - if(string.indexOf("_") != -1){ - return string.substring(0,string.indexOf("_")).toUpperCase(); + string = string.replaceAll(' ','_'); + if(string.indexOf('_') != -1){ + return string.substring(0,string.indexOf('_')).toUpperCase(); } else{ return string.toUpperCase(); } } -String.prototype.replaceAll = function(strReplace, strWith){ - // See http://stackoverflow.com/a/3561711/556609 - var esc = strReplace.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); - var reg = new RegExp(esc, 'ig'); - return this.replace(reg, strWith); +String.prototype.replaceAll = function(strReplace,strWith){ + /* See http://stackoverflow.com/a/3561711/556609 */ + var esc = strReplace.replace(/[-\/\\^$*+?.()|[\]{}]/g,'\\$&'); + var reg = new RegExp(esc,'ig'); + return this.replace(reg,strWith); };