Skip to content

Instantly share code, notes, and snippets.

@tobidope
Last active December 8, 2020 16:11
Show Gist options
  • Save tobidope/8568487 to your computer and use it in GitHub Desktop.
Save tobidope/8568487 to your computer and use it in GitHub Desktop.
Simple script to extract the ever changing credentials from the website of the VPN provider VPNBook. Especially useful on OpenWRT based routers.
#!/bin/sh
# Extracts the user and password for the VPNBook free VPN service
# out of their web site
# URL to the site containing user and password
SITE="http://www.vpnbook.com/freevpn"
# File where VPNBook credentials get stored
AUTH_FILE="/etc/openvpn/vpnbook.auth"
# Path to temporary file
AUTH_FILE_TMP="/tmp/vpnbook.$$"
cleanup() {
rm -f "$AUTH_FILE_TMP"
}
trap cleanup SIGHUP SIGINT SIGTERM
load_credentials() {
wget "$SITE" -q -O - |\
awk -F '[<>]' '
BEGIN { exit_value = 1 }
/Username:/ && !user_found { print $5; user_found = 1; next }
/Password:/ && user_found { print $5; exit_value = 0; exit }
END { exit exit_value }
'
}
if load_credentials > "$AUTH_FILE_TMP"; then
mv "$AUTH_FILE_TMP" "$AUTH_FILE"
exit 0
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment