Hi,
I live in a place with free Wifi. I want my linux to auto login
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>internet hotspot > login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;���>
<style type="text/css">
</head>
<body>
<p>
<form name="sendin" action="http://123.123.123.123/login" method="post">
<input type="hidden" name="username" />
<input type="hidden" name="password" />
<input type="hidden" name="dst" value="" />
<input type="hidden" name="popup" value="true" />
</form>
<script type="text/javascript" src="/md5.js"></script>
<script type="text/javascript">
<!--
function doLogin() {
document.sendin.username.value = document.login.username.value;
document.sendin.password.value = hexMD5('\273' + document.login.password.value + '\051\201\065\307\230\243\253\341\030\275\115\145\356\257\105\360');
document.sendin.submit();
return false;
}
//-->
</script>
<div align="center">
</div>
<table width="100%" style="margin-top: 10%;">
<tr>
<td align="center" valign="middle">
<div class="notice" style="color: #c1c1c1; font-size: 9px">Bitte loggen Sie sich ein, um den Hotspot zu nutzen<br />Freie, langsamere Nutzung ist ebenfalls m��glich, <a style="color: #FF8080"href="http://123.123.123.123/login?dst=&username=blablabla">hier clicken</a>.</div><br />
<table width="280" height="280" style="border: 1px solid #cccccc; padding: 0px;" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="bottom" height="175" colspan="2">
<form name="login" action="http://123.123.123.123/login" method="post"
onSubmit="return doLogin()" >
<input type="hidden" name="dst" value="" />
<input type="hidden" name="popup" value="true" />
<table width="100" style="background-color: #ffffff">
<tr><td align="right">login</td>
<td><input style="width: 80px" name="username" type="text" value=""/></td>
</tr>
<tr><td align="right">password</td>
<td><input style="width: 80px" name="password" type="password"/></td>
</tr>
<tr><td> </td>
<td><input type="submit" value="OK" /></td>
</tr>
</table>
</form>
</td>
</tr>
<tr><td align="center"><a href="http://www.providername" target="_blank" style="border: none;"><img src="img/logobottom.png" alt="provider" /></a></td></tr>
</table>
<br /><div style="color: #c1c1c1; font-size: 9px">Powered by</div>
</td>
</tr>
</table>
<script type="text/javascript">
<!--
document.login.username.focus();
//-->
</script>
</body>
</html>
The link to activate the free wifi is
href="http://123.123.123.123/login?dst=&username=blablabla
wget doesnt do the job, as i guess the password is md5’ed before it gets sent.
so i guess i need to use some tool that can work with the md5.js java script
Has anyone built a bashscript before that does the job?
Solved it.
elinks and python. With python you can spawn a process and make it input to it automatically
The rest is easy. Keep checking if advert is necessary and download it via script etc.
@bastibasti , I have the same problem as yours but i dont have much programming skills even though i understand html. Can you please explain how you solved the problem in details
plazturz I think I got the way, I’ll try tonight and if it work, i will share the script.
well, elinks and python didn’t work because elinks don’t support javascript and the login page have javascript funtions
I found a solution…
Selenium + python…
This the script:
#!/usr/bin/python
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('YOURHOMEPAGELOGIN') #Here put your page login
elem = browser.find_elements_by_name('username')
elem[1].send_keys('XXXXXX') #here put your username
elem = browser.find_elements_by_name('password')
elem[1].send_keys('XXXXXX' + Keys.RETURN) #here put your password
browser.quit()
This works for me on a linux terminal with python and selenium.
Here have the steps to install selenium for python: https://pypi.python.org/pypi/selenium
I’d really need such s script for the microtik router itself…
sbandur
November 29, 2016, 9:25pm
8
I am using such a script on my DD-WRT ROUTER, to connect to local MIKROTIK FREE WiFi HOTSPOT.
Script also works on every linux distro! – Just rename the *.startup file to *.sh.
You have to Configure the script for Your WiFi hotspot!
For more info, You can contact me on seba.bandur(at)gmail.com .
Script and configuration info will be updated soon on GitHub.
GitHub project:
Auto connect and reconnect to Mikrotik free WiFi point on DD-WRT router
Main script:
Log server displays simple info on connection status on port 88 "localhost:88":
#!/bin/sh
LOG_FILE="/tmp/FreeWiFi_LOG.log"
sleep 20
rm $LOG_FILE
touch $LOG_FIL
echo "FreeWiFi LOG server using simple netcat" >> $LOG_FILE
echo "Author: Sebastijan Bandur, seba.bandur@gmail.com" >> $LOG_FILE
echo "Server started: $(date)" >> $LOG_FILE
echo "---------------------------------------" >> $LOG_FILE
while true ;
do
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c < $LOG_FILE)\r\n\r\n"; cat $LOG_FILE; } | nc -l -p 88;
done
======================================================================================
SCRIPT
#!/bin/sh
LOGIN_ROUTER="http://starse.wifipoint.net/login?username=T-C8%3AB3%3A73%3A3B%3A45%3AD3"
LOGOUT="http://starse.wifipoint.net/logout"
LOGIN="http://starse.wifipoint.net/login"
USER=$ROUTER_USER
STATUS_URL="http://starse.wifipoint.net/status"
LOGIN_URL=$LOGIN_ROUTER
GET_TIME_PAUSE=0
MAIN_SLEEP=60
BOOT_SLEEP=30
LOGOUT_WHEN_LEFT_S=$(($MAIN_SLEEP+5))
AQUIRE_TIME_RETRY=10
LOG_FILE="/tmp/FreeWiFi_LOG.log"
#before first login sleep for 60s
echo "$(date), BOOT OK. Waiting $BOOT_SLEEP seconds." >> $LOG_FILE
sleep $BOOT_SLEEP
LOGIN_NR=1
RUN=1
# UNCOMENT FOR DEBUGING
#set -x
while [ $RUN -eq 1 ]
do
#LOGIN
CONN_STATUS=0
R=1
echo -n "$(date), Connecting ... " >> $LOG_FILE
while [ $CONN_STATUS -eq 0 ]
do
echo -n "$R " >> $LOG_FILE
CONN_STATUS=$(wget -T 2 -q -O - "$@" "$LOGIN_URL" | grep -c "You are logged in")
if [ $CONN_STATUS -eq 0 ]
then
sleep 1
fi
R=$((R+1))
done
echo "OK: $(date +%H:%M:%S)" >> $LOG_FILE
#AQUIRE TIME LEFT
#WAIT FOR NTP SERVER
TIME_NOW=$(date +%s)
if [ $TIME_NOW -lt 300 ]
then
echo -n "$(date), NTP Time ... " >> $LOG_FILE
NTP=1
while true
do
echo -n "$NTP " >> $LOG_FILE
SEC=$(date +%s)
if [ $SEC -gt 300 ]
then
echo "OK: $(date +%H:%M:%S)" >> $LOG_FILE
break
fi
NTP=$((NTP+1))
sleep 1
done
fi
WHOLE_START=$(date +%s)
echo -n "$(date), Login time ... " >> $LOG_FILE
I=1
T=0
TIME_OK=0
while [ $TIME_OK -eq 0 ]
do
echo -n "$I " >> $LOG_FILE
STATUS_PAGE=$(wget -T 2 -q -O - "$@" "$STATUS_URL")
STA=$?
# sleep $GET_TIME_PAUSE
if [ "$STATUS_PAGE" = "" ]
then
echo -n "PAGE_ERR " >> $LOG_FILE
sleep 1
I=$((I+1))
continue
fi
MINUTES=$(echo $STATUS_PAGE | grep -o '/ [0-9]*m' | tr -d 'm' | tr -d ' ' | tr -d '/')
if [ "$MINUTES" = "" ]
then
echo -n "TIME_ERR " >> $LOG_FILE
sleep 1
I=$((I+1))
continue
fi
T=$MINUTES
if [ $T -gt 0 ]
then
TIME_OK=1
echo "OK: $MINUTES minutes left." >> $LOG_FILE
I=$((I+1))
break
fi
if [ $I -gt $AQUIRE_TIME_RETRY ]
then
echo "FAIL. Restarting script ..." >> $LOG_FILE
TIME_OK=1
sleep 1
continue 1
fi
I=$((I+1))
done
echo "1...5....10...15...20...25...30...35...40...45...50...55...60" >> $LOG_FILE
#WAIT PERIOD
#CALC TIME
S=$(($T*60))
NOW=$(date +%s)
ELPASSED=$(($NOW-$WHOLE_START))
LEFT=$(($S-$ELPASSED))
while [ $LEFT -gt $LOGOUT_WHEN_LEFT_S ]
do
# check for internet connection - ping google DNS
P=$(ping -c 1 -w 2 8.8.4.4 &> /dev/null)
PING_OK=$?
# SET PING ms TO 0 ON FAIL
if [ $PING_OK -eq 1 ]
then
PING=0
echo -n "-" >> $LOG_FILE
else
PING=1
echo -n "+" >> $LOG_FILE
fi
sleep $MAIN_SLEEP
#CALC TIME
NOW=$(date +%s)
ELPASSED=$(($NOW-$WHOLE_START))
LEFT=$(($S-$ELPASSED))
done
echo "|" >> $LOG_FILE
#LOGOUT
echo "$(date), Connection finished ..." >> $LOG_FILE
OUT=$(wget -T 2 -q -O - "$@" $LOGOUT)
LOGIN_NR=$(($LOGIN_NR+1))
done