Skip to content

Instantly share code, notes, and snippets.

@cusspvz
Last active September 11, 2021 00:58
Show Gist options
  • Save cusspvz/3ab1ea9110f4ef87f0d2e1cd134aca67 to your computer and use it in GitHub Desktop.
Save cusspvz/3ab1ea9110f4ef87f0d2e1cd134aca67 to your computer and use it in GitHub Desktop.
FON ZON / NOS auto-login bash script wget portugal non-wispr client openwrt
#!/bin/sh
# place this file at: /etc/hotplug.d/iface/99-login-fon
# Configurations
FON_USERNAME=email%40domain.com
FON_PASSWORD=123456
FON_DELAY_UP=3
COOKIE_JAR_PATH=/tmp/nos-fon-cookie-jar.$INTERFACE
. /lib/functions.sh
clean () {
[ -f $COOKIE_JAR_PATH ] && rm -f $COOKIE_JAR_PATH
}
logger -t FonLogin "Starting on $INTERFACE:$DEVICE -> $ACTION"
attempt () {
local INDICATOR="action=\"/nos"
local POST_URL=""
local DOMAIN_URL="https://captiveportal.nos.pt"
local TARGET="http://sapo.pt"
logger -t FonLogin "Trying to fetch a website"
DATA="$(curl --insecure --interface $DEVICE --location --cookie-jar $COOKIE_JAR_PATH $TARGET)"
logger -t FonLogin "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 FonLogin "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 "userFake=${FON_USERNAME}&UserName=NOS%2F${FON_USERNAME}&Password=${FON_PASSWORD}&rememberMe=true&_rememberMe=on" \
"$DOMAIN_URL$POST_URL"
fi
clean
}
case "$ACTION" in
ifup)
logger -t FonLogin "Waiting $FON_DELAY_UP seconds before attempt"
sleep $FON_DELAY_UP;
logger -t FonLogin "Attempting to login at FON"
attempt
;;
update)
logger -t FonLogin "Attempting to update login at FON"
attempt
;;
esac
@caredusales
Copy link

caredusales commented Nov 5, 2017

Ola José,

Uso um TP-LINK WR1043ND com o LEDE (Nova versão do OpenWRT) com duas interfaces wireless a WWAN ligado a NOS_WIFI_Fon e a interface wireless normal em bridge com as portas LAN, usei este script para tentar dar login automatico na FON mas não funcionou, sabes dizer se ainda estar a funcionar? ou se e preciso dizer ao script a interface?...

Cumps,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment