I would like to connect an ESP8266 based sensor on a wifi network protected by a captive portal (I've no other option, and I cannot ask for derogation). I have a login/password to connect.
From a basic computer, when I'm connected to the network and I do an Internet request (for example, I search "bl" on google), I got a page like this : https://url:1003/fgtauth?12291a0aff04200a
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
...
</style>
<body>
<div class="oc">
<div class="ic">
<form action="/" method="post">
<input type="hidden" name="4Tredir" value= "https://www.google.com/search?q=test&ie=utf-8&oe=utf-8">
<input type="hidden" name="magic" value="12291a0aff04200a">
<input type="hidden" name="answer" value="0">
<h1 class="logo">
GENERAL CONDITIONS
</h1>
<p>
I. OBJET <br /> <br />
Some blabla..
</p>
<h2>
Do you agree to the above terms?
</h2>
<div class="fec">
<input type="submit" value= "Yes, I agree" onclick="sb('1')">
<input type="submit" value= "No, I decline" onclick="sb('0')">
</div>
</form>
</div>
</div>
<script>
function sb(val) {
document.forms[0].answer.value = val;
document.forms[0].submit();
}
</script>
</body>
</html>
So, we see in this page that we get a "magic value" that is in fact an id for the session. When I click the agree button, I get this page https://url:1003/ :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
...
</style>
<title>
Firewall Authentication
</title>
</head>
<body>
<div class="oc">
<div class="ic">
<form action="/" method="post">
<input type="hidden" name="4Tredir" value= "https://www.google.com/search?q=bl&ie=utf-8&oe=utf-8">
<input type="hidden" name="magic" value="122713150676bec1">
<h1 class="logo">
Authentication Required
</h1>
<h2>
Please enter your username and password to continue.
</h2>
<div class="fer">
<label for="ft_un">
Username:
</label>
<input name="username" id="ft_un" style="width:245px">
<br>
</div>
<div class="fer">
<label for="ft_pd">
Password:
</label>
<input name="password" id="ft_pd" type="password" style="width:245px">
</div>
<div class="fer">
<input type="submit" value= "Continue">
</div>
</form>
</div>
</div>
</body>
</html>
Here, I fill user and password and it will send them to the server that returns a blank page with OK.
So, I would like to do this step from an ESP8266. I see that in two steps :
- request a page
- get the result and store the magic
- fake an "agree" request page
- fake a "user/id/magic" request page
An example of requesting page for ESP8266 can be found here : https://github.com/iobridge/ThingSpeak-Arduino-Examples/blob/master/Ethernet/Arduino_to_ThingSpeak.ino We see here, that we can send POST request as :
client.print("POST /update HTTP/1.1\n");
Here, there is a good example to parse a page : http://blog.nyl.io/esp8266-led-arduino/
So, I might do it with that and post the answer, but first I need some clues about how to create the above "fake" requests.
Any ideas ?