-
-
Save onefork/bf7f32c430f2aa9c1fcd7f6321b8bcf8 to your computer and use it in GitHub Desktop.
LANCOM auto-login bash script wget client openwrt
This file contains 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 | |
# place this file at: /etc/hotplug.d/iface/99-login-lancom | |
# Configurations | |
LANCOM_USERNAME=email%40domain.com | |
LANCOM_PASSWORD=123456 | |
LANCOM_DELAY_UP=3 | |
COOKIE_JAR_PATH=/tmp/lancom-cookie-jar.$INTERFACE | |
. /lib/functions.sh | |
clean () { | |
[ -f $COOKIE_JAR_PATH ] && rm -f $COOKIE_JAR_PATH | |
} | |
attempt () { | |
local INDICATOR="ACTION=\"http://192.168." | |
local POST_URL="" | |
local DOMAIN_URL="" | |
local TARGET="http://www.spiegel.de" | |
logger -t LancomLogin "Trying to fetch a website" | |
DATA="$(curl --insecure --interface $DEVICE --location --cookie-jar $COOKIE_JAR_PATH $TARGET)" | |
logger -t LancomLogin "Trying to get post url" | |
POST_URL="$(echo "$DATA" | grep $INDICATOR | cut -d \" -f 6 | sed -r 's/\&/\&/g')" | |
if [ -n "$POST_URL" ]; then | |
logger -t LancomLogin "Post URL found, trying to login" | |
curl \ | |
--insecure \ | |
--interface $DEVICE \ | |
--location \ | |
--cookie-jar $COOKIE_JAR_PATH \ | |
--header 'cache-control: no-cache' \ | |
--header 'content-type: application/x-www-form-urlencoded' \ | |
--data "refreshdir=&refreshhost=www.spiegel.de&refreshssl=0&userid=${LANCOM_USERNAME}&password=${LANCOM_PASSWORD}&AGB=on" \ | |
"$DOMAIN_URL$POST_URL" | |
fi | |
clean | |
} | |
if [ "$DEVICE" != "lo" ] && [ "$DEVICE" != "br-lan" ]; then | |
case "$ACTION" in | |
ifup) | |
logger -t LancomLogin "Starting on $INTERFACE:$DEVICE -> $ACTION" | |
logger -t LancomLogin "Waiting $LANCOM_DELAY_UP seconds before attempt" | |
sleep $LANCOM_DELAY_UP; | |
logger -t LancomLogin "Attempting to login at LANCOM" | |
attempt | |
;; | |
update) | |
logger -t LancomLogin "Starting on $INTERFACE:$DEVICE -> $ACTION" | |
logger -t LancomLogin "Attempting to update login at LANCOM" | |
attempt | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment