Last active
December 8, 2020 16:11
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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