1
0
mirror of synced 2024-11-29 08:06:04 +03:00

Improve defining VPN variables

This commit is contained in:
hwdsl2 2016-06-11 15:36:43 -05:00
parent deb2f75eb9
commit 59c7227587
2 changed files with 20 additions and 14 deletions

View File

@ -18,12 +18,13 @@
# =========================================================== # ===========================================================
# Define your own values for these variables # Define your own values for these variables
# - IPsec pre-shared key, VPN username and password
# - All values MUST be placed inside 'single quotes' # - All values MUST be placed inside 'single quotes'
# - DO NOT use these characters within values: \ " ' # - DO NOT use these characters within values: \ " '
VPN_IPSEC_PSK=${VPN_IPSEC_PSK:-'your_ipsec_pre_shared_key'} YOUR_IPSEC_PSK=''
VPN_USER=${VPN_USER:-'your_vpn_username'} YOUR_USERNAME=''
VPN_PASSWORD=${VPN_PASSWORD:-'your_vpn_password'} YOUR_PASSWORD=''
# Important Notes: https://git.io/vpnnotes # Important Notes: https://git.io/vpnnotes
# Setup VPN Clients: https://git.io/vpnclients # Setup VPN Clients: https://git.io/vpnclients
@ -64,18 +65,20 @@ EOF
exit 1 exit 1
fi fi
[ "$VPN_IPSEC_PSK" = "your_ipsec_pre_shared_key" ] && VPN_IPSEC_PSK='' [ -n "$YOUR_IPSEC_PSK" ] && VPN_IPSEC_PSK="$YOUR_IPSEC_PSK"
[ "$VPN_USER" = "your_vpn_username" ] && VPN_USER='' [ -n "$YOUR_USERNAME" ] && VPN_USER="$YOUR_USERNAME"
[ "$VPN_PASSWORD" = "your_vpn_password" ] && VPN_PASSWORD='' [ -n "$YOUR_PASSWORD" ] && VPN_PASSWORD="$YOUR_PASSWORD"
if [ -z "$VPN_IPSEC_PSK" ] && [ -z "$VPN_USER" ] && [ -z "$VPN_PASSWORD" ]; then if [ -z "$VPN_IPSEC_PSK" ] && [ -z "$VPN_USER" ] && [ -z "$VPN_PASSWORD" ]; then
echo "VPN credentials not set by user. Generating random PSK and password..."
echo
VPN_IPSEC_PSK="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" VPN_IPSEC_PSK="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)"
VPN_USER=vpnuser VPN_USER=vpnuser
VPN_PASSWORD="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" VPN_PASSWORD="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)"
fi fi
if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then
echoerr "VPN credentials must be specified. Edit the script and re-enter them." echoerr "All VPN credentials must be specified. Edit the script and re-enter them."
exit 1 exit 1
fi fi

View File

@ -18,12 +18,13 @@
# =========================================================== # ===========================================================
# Define your own values for these variables # Define your own values for these variables
# - IPsec pre-shared key, VPN username and password
# - All values MUST be placed inside 'single quotes' # - All values MUST be placed inside 'single quotes'
# - DO NOT use these characters within values: \ " ' # - DO NOT use these characters within values: \ " '
VPN_IPSEC_PSK=${VPN_IPSEC_PSK:-'your_ipsec_pre_shared_key'} YOUR_IPSEC_PSK=''
VPN_USER=${VPN_USER:-'your_vpn_username'} YOUR_USERNAME=''
VPN_PASSWORD=${VPN_PASSWORD:-'your_vpn_password'} YOUR_PASSWORD=''
# Important Notes: https://git.io/vpnnotes # Important Notes: https://git.io/vpnnotes
# Setup VPN Clients: https://git.io/vpnclients # Setup VPN Clients: https://git.io/vpnclients
@ -68,18 +69,20 @@ EOF
exit 1 exit 1
fi fi
[ "$VPN_IPSEC_PSK" = "your_ipsec_pre_shared_key" ] && VPN_IPSEC_PSK='' [ -n "$YOUR_IPSEC_PSK" ] && VPN_IPSEC_PSK="$YOUR_IPSEC_PSK"
[ "$VPN_USER" = "your_vpn_username" ] && VPN_USER='' [ -n "$YOUR_USERNAME" ] && VPN_USER="$YOUR_USERNAME"
[ "$VPN_PASSWORD" = "your_vpn_password" ] && VPN_PASSWORD='' [ -n "$YOUR_PASSWORD" ] && VPN_PASSWORD="$YOUR_PASSWORD"
if [ -z "$VPN_IPSEC_PSK" ] && [ -z "$VPN_USER" ] && [ -z "$VPN_PASSWORD" ]; then if [ -z "$VPN_IPSEC_PSK" ] && [ -z "$VPN_USER" ] && [ -z "$VPN_PASSWORD" ]; then
echo "VPN credentials not set by user. Generating random PSK and password..."
echo
VPN_IPSEC_PSK="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" VPN_IPSEC_PSK="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)"
VPN_USER=vpnuser VPN_USER=vpnuser
VPN_PASSWORD="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)" VPN_PASSWORD="$(< /dev/urandom tr -dc 'A-HJ-NPR-Za-km-z2-9' | head -c 16)"
fi fi
if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then
echoerr "VPN credentials must be specified. Edit the script and re-enter them." echoerr "All VPN credentials must be specified. Edit the script and re-enter them."
exit 1 exit 1
fi fi