Skip to content

Instantly share code, notes, and snippets.

@wvengen wvengen/update-freevpn.sh
Last active Apr 28, 2019

Embed
What would you like to do?
Update on-demand PPTP configuration for free VPNs
#!/bin/sh
#
# Update freevpn.se pptp configuration
#
# Since the password changes now and then, it's useful to update it automatically.
# Make sure you've installed lynx. Tested on Debian.
#
URL=https://www.freevpn.se/accounts/
PEERNAME=freevpn.se
# Gather data
TMP=`mktemp -t pptpupdate.XXXXXXXXXX`
lynx -dump "$URL" >"$TMP"
HOST=`cat "$TMP" | sed 's/^.*IP:\s*\([\.0-9]\+\).*$/\1/p;d' | head -n 1`
USER=`cat "$TMP" | sed 's/^.*Username:\s*\(\w\+\).*$/\1/p;d' | head -n 1`
PASS=`cat "$TMP" | sed 's/^.*Password:\s*\(\S\+\).*$/\1/p;d' | head -n 1`
[ "$HOST" -a "$USER" -a "$PASS" ] || exit 1
# Regenerate peer config
cat >"/etc/ppp/peers/$PEERNAME" <<-EOF
remotename $PEERNAME
linkname $PEERNAME
ipparam $PEERNAME
pty "pptp '$HOST' --nolaunchpppd "
name "$USER"
require-mppe
file /etc/ppp/options.pptp
EOF
# Update password
umask 077
grep -v '\b'"$PEERNAME"'\b' </etc/ppp/chap-secrets >/etc/ppp/chap-secrets.new &&
echo "$USER $PEERNAME $PASS" >>/etc/ppp/chap-secrets.new &&
mv /etc/ppp/chap-secrets.new /etc/ppp/chap-secrets
# Cleanup
rm -f "$TMP"
# Make sure you've installed lynx. Tested on Debian.
#
# On-demand dial configuration, expects routing script in /etc/ppp/010route.
#
# If run with the "start" argument, the vpn will be started right away (on demand).
#
# Based on: https://gist.github.com/wvengen/4d6977afbb349ed369ddafdf02cdcc60
#
URL=http://freevpnaccess.com/
PEERNAME=freevpnaccess.com
COUNTRY=UK
# Gather data
TMP=`mktemp -t pptpupdate.XXXXXXXXXX`
lynx -dump "$URL" | grep '\b'"$COUNTRY"'\b.*\bPPTP\b' >"$TMP"
HOST=`cat "$TMP" | sed 's/^.*\s\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\s.*$/\1/p;d' | head -n 1`
PASS=`cat "$TMP" | sed 's/^.*\s\([0-9][0-9][0-9][0-9]\)\s*$/\1/p;d' | head -n 1`
USER=freevpnaccess.com
[ "$HOST" -a "$USER" -a "$PASS" ] || exit 1
# Regenerate peer config
cat >"/etc/ppp/peers/$PEERNAME" <<-EOF
remotename $PEERNAME
linkname $PEERNAME
ipparam $PEERNAME
pty "pptp '$HOST' --nolaunchpppd "
name "$USER"
require-mppe
persist
demand
idle 300
holdoff 10
file /etc/ppp/options.pptp
EOF
# Update password
umask 077
grep -v '\b'"$PEERNAME"'\b' </etc/ppp/chap-secrets >/etc/ppp/chap-secrets.new &&
echo "$USER $PEERNAME $PASS" >>/etc/ppp/chap-secrets.new &&
mv /etc/ppp/chap-secrets.new /etc/ppp/chap-secrets
# Cleanup
rm -f "$TMP"
if [ "$1" = "start" ]; then
pon "$PEERNAME" && \
sleep 2 && \
/etc/ppp/ip-up.d/010route
fi
@tuxutku

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.