Compare commits

..

1 Commits

Author SHA1 Message Date
b33a766b7a Added an option for CLI-specified refresh interval 2013-01-26 20:12:30 -07:00

29
app.js
View File

@ -1,7 +1,8 @@
var url = require('url'),
querystring = require('querystring'),
http = require('http'),
scraper = require('scraper');
scraper = require('scraper'),
refreshinterval = 10; // in seconds
var hotspots = {
cartel: {
@ -33,18 +34,16 @@ function checkForRedirect () {
}
function isThisARedirect (res) {
var currentDate = new Date();
if (res.statusCode == 301 || res.statusCode == 302) {
console.log(currentDate.toTimeString()+": Redirect? HOW SUSPICIOUS.");
console.log("Redirect? HOW SUSPICIOUS.");
redirecting(res);
}
else {
console.log(currentDate.toTimeString()+": No redirect, nothing to see here...");
console.log("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);
@ -53,7 +52,7 @@ function redirecting (res) {
var found = false;
for (var k in hotspots) {
if (!found && hotspots[k].check($)) {
console.log(currentDate.toTimeString()+": "+k.toUpperCase()+" WANTS YOU TO LOG IN");
console.log(k.toUpperCase()+" WANTS YOU TO LOG IN");
connectToNetwork(hotspots[k].credentials, mergeObjects(_url, hotspots[k].postOptions));
return;
}
@ -106,6 +105,20 @@ function mergeObjects (obj1, obj2) {
return obj;
}
console.log("Cool! I'll check the wifi every 10 seconds, just keep me running...");
setInterval(checkForRedirect, 10000);
// 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);
checkForRedirect();