-
-
Save SmartFinn/aec9267db348c0bffd6045e07294e2cd to your computer and use it in GitHub Desktop.
Simple script to extract the ever-changing credentials from Twitter (Facebook) account 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 social media | |
# based on https://gist.github.com/tobidope/8568487 | |
# | |
# https://gist.github.com/SmartFinn/aec9267db348c0bffd6045e07294e2cd | |
readonly CONN_ID="vpnbook" | |
readonly WEBPAGE="https://nitter.net/vpnbook/rss" | |
readonly AUTH_FILE_TMP="/tmp/vpnbook.$$" | |
readonly AUTH_FILE="/etc/openvpn/vpnbook.auth" | |
_cleanup() { | |
rm -f "$AUTH_FILE_TMP" | |
} | |
trap _cleanup HUP INT TERM | |
_info() { | |
logger -s -p 6 -t "$(basename "$0")" "$@" | |
} | |
_success() { | |
logger -s -p 6 -t "$(basename "$0")" "$@" | |
_cleanup | |
exit 0 | |
} | |
_fail() { | |
logger -s -p 3 -t "$(basename "$0")" "$@" | |
_cleanup | |
exit 1 | |
} | |
_get_openvpn_instance() { | |
pgrep -lf openvpn | awk -v pattern="$CONN_ID" '$0 ~ pattern { print $1 }' | |
} | |
_load_credentials() { | |
curl -sk -o- "$WEBPAGE" | awk -v RS='<[^>]+>' -v OFS='\n' ' | |
BEGIN { exit_value = 1 } | |
/Password:[ ]/ { print $5,$7; exit_value = 0; exit } | |
END { exit exit_value } | |
' | |
} | |
if _load_credentials > "$AUTH_FILE_TMP"; then | |
if cmp -s "$AUTH_FILE_TMP" "$AUTH_FILE"; then | |
_success "credentials are not changed" | |
else | |
mv -f "$AUTH_FILE_TMP" "$AUTH_FILE" | |
_info "credentials are saved" | |
if kill -HUP "$(_get_openvpn_instance)"; then | |
_success "Trying to restart OpenVPN($CONN_ID)" | |
else | |
_fail "Unable to restart OpenVPN($CONN_ID)" | |
fi | |
fi | |
else | |
_fail "Failed to get credentials" | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment