Compare commits

..

1 Commits

Author SHA1 Message Date
35cf69cd73 Adding time to log for debugging 2014-02-07 18:16:24 -07:00

29
app.js
View File

@ -1,8 +1,7 @@
var url = require('url'),
querystring = require('querystring'),
http = require('http'),
scraper = require('scraper'),
refreshinterval = 10; // in seconds
scraper = require('scraper');
var hotspots = {
cartel: {
@ -34,16 +33,18 @@ function checkForRedirect () {
}
function isThisARedirect (res) {
var currentDate = new Date();
if (res.statusCode == 301 || res.statusCode == 302) {
console.log("Redirect? HOW SUSPICIOUS.");
console.log(currentDate.toTimeString()+": Redirect? HOW SUSPICIOUS.");
redirecting(res);
}
else {
console.log("No redirect, nothing to see here...");
console.log(currentDate.toTimeString()+": No redirect, nothing to see here...");
}
}
function redirecting (res) {
var currentDate = new Date();
var _url = url.parse(res.headers.location);
console.log("Scrape: "+res.headers.location);
@ -52,7 +53,7 @@ function redirecting (res) {
var found = false;
for (var k in hotspots) {
if (!found && hotspots[k].check($)) {
console.log(k.toUpperCase()+" WANTS YOU TO LOG IN");
console.log(currentDate.toTimeString()+": "+k.toUpperCase()+" WANTS YOU TO LOG IN");
connectToNetwork(hotspots[k].credentials, mergeObjects(_url, hotspots[k].postOptions));
return;
}
@ -105,20 +106,6 @@ function mergeObjects (obj1, obj2) {
return obj;
}
// process command line arguments
process.argv.forEach(function (val, index, array) {
if(val == "-h" || val == "--help")
{
console.log("To change refresh interval: -t [number of seconds]\r\n\r\n");
}
if(val == "-t"){
if(process.argv[index+1] > 0) {
refreshinterval = process.argv[index+1];
}
}
}
);
console.log("Cool! I'll check the wifi every "+refreshinterval+" seconds, just keep me running...");
setInterval(checkForRedirect, refreshinterval*1000);
console.log("Cool! I'll check the wifi every 10 seconds, just keep me running...");
setInterval(checkForRedirect, 10000);
checkForRedirect();