intel-screenbot

An Ingress Intel Map Bot for Hangoutsbot
git clone git://archive.git.mtrnord.blog/MTRNord/intel-screenbot.git
Log | Files | Refs | README | LICENSE

commit c122c8aef1aaa2e18b7233ce715126c64bd2b044
parent 53950ad200df8e1e3805c42f30bcec993fc19bad
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 15 Nov 2016 08:57:54 +0100

Fix pass maillogin

Diffstat:
Mscreencap_iitc.js | 67++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mscreencap_intel.js | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 123 insertions(+), 9 deletions(-)

diff --git a/screencap_iitc.js b/screencap_iitc.js @@ -32,13 +32,52 @@ function validateEmail(email) { } if (validateEmail(SACSID)) { - firePlainLogin(SACSID, CSRF); - afterPlainLogin(IntelURL, search); + loadCookies(function() { + if (config.SACSID == undefined || config.SACSID == '') { + firePlainLogin(); + } else { + addCookies(config.SACSID, config.CSRF); + announce('Using cookies to log in'); + afterCookieLogin(); + } + }); }else { addCookies(SACSID, CSRF); afterCookieLogin(IntelURL, search); } +function loadCookies(callback) { + if(fs.exists(cookiespath)) { + var stream = fs.open(cookiespath, 'r'); + + while(!stream.atEnd()) { + var line = stream.readLine().split('='); + if(line[0] === 'SACSID') { + SACSID = line[1]; + } else if(line[0] === 'csrftoken') { + CSRF = line[1]; + } else { + config.SACSID = ''; + config.CSRF = ''; + } + } + stream.close(); + } +} + +function isSignedIn() { + return page.evaluate(function() { + return document.getElementsByTagName('a')[0].innerText.trim() !== 'Sign in'; + }); +} + +function storeCookies() { + var cookies = page.cookies; + fs.write(cookiespath, '', 'w'); + for(var i in cookies) { + fs.write(cookiespath, cookies[i].name + '=' + cookies[i].value +'\n', 'a'); + } +} function firePlainLogin(SACSID, CSRF) { page.open('https://www.ingress.com/intel', function (status) { @@ -91,7 +130,7 @@ function login(l, p) { document.getElementById('challenge').submit(); }); } - window.setTimeout(afterPlainLogin, loginTimeout); + window.setTimeout(afterPlainLogin(IntelURL, search), loginTimeout); }, loginTimeout) }, loginTimeout / 10); } @@ -100,8 +139,13 @@ function afterPlainLogin(IntelURL, search) { page.viewportSize = { width: '1920', height: '1080' }; page.open(IntelURL, function(status) { if (status !== 'success') {quit('unable to connect to remote server')} - page.injectJs('https://code.jquery.com/jquery-3.1.1.min.js'); + if (!isSignedIn()) { + announce('Something went wrong. Please, sign in to Google via your browser and restart ICE. Don\'t worry, your Ingress account will not be affected.'); + quit(); + } setTimeout(function() { + page.injectJs('https://code.jquery.com/jquery-3.1.1.min.js'); + storeCookies(); page.evaluate(function() { localStorage['ingress.intelmap.layergroupdisplayed'] = JSON.stringify({ "Unclaimed Portals":Boolean(1 === 1), @@ -230,8 +274,21 @@ function afterCookieLogin(IntelURL, search) { page.viewportSize = { width: '1920', height: '1080' }; page.open(IntelURL, function(status) { if (status !== 'success') {quit('unable to connect to remote server')} - page.injectJs('https://code.jquery.com/jquery-3.1.1.min.js'); + if(!isSignedIn()) { + if(fs.exists(cookiespath)) { + fs.remove(cookiespath); + } + if(validateEmail(SACSID)) { + page.deleteCookie('SACSID'); + page.deleteCookie('csrftoken'); + firePlainLogin(SACSID, CSRF); + return; + } else { + quit('Cookies are obsolete. Update your config file.'); + } + } setTimeout(function() { + page.injectJs('https://code.jquery.com/jquery-3.1.1.min.js'); page.evaluate(function() { localStorage['ingress.intelmap.layergroupdisplayed'] = JSON.stringify({ "Unclaimed Portals":Boolean(1 === 1), diff --git a/screencap_intel.js b/screencap_intel.js @@ -28,8 +28,15 @@ function validateEmail(email) { } if (validateEmail(SACSID)) { - firePlainLogin(SACSID, CSRF); - afterPlainLogin(IntelURL); + loadCookies(function() { + if (config.SACSID == undefined || config.SACSID == '') { + firePlainLogin(); + } else { + addCookies(config.SACSID, config.CSRF); + announce('Using cookies to log in'); + afterCookieLogin(); + } + }); }else { addCookies(SACSID, CSRF); afterCookieLogin(IntelURL, search); @@ -50,6 +57,39 @@ function firePlainLogin(SACSID, CSRF) { }); } +function loadCookies(callback) { + if(fs.exists(cookiespath)) { + var stream = fs.open(cookiespath, 'r'); + + while(!stream.atEnd()) { + var line = stream.readLine().split('='); + if(line[0] === 'SACSID') { + config.SACSID = line[1]; + } else if(line[0] === 'csrftoken') { + config.CSRF = line[1]; + } else { + config.SACSID = ''; + config.CSRF = ''; + } + } + stream.close(); + } +} + +function isSignedIn() { + return page.evaluate(function() { + return document.getElementsByTagName('a')[0].innerText.trim() !== 'Sign in'; + }); +} + +function storeCookies() { + var cookies = page.cookies; + fs.write(cookiespath, '', 'w'); + for(var i in cookies) { + fs.write(cookiespath, cookies[i].name + '=' + cookies[i].value +'\n', 'a'); + } +} + function login(l, p) { page.evaluate(function (l) { document.getElementById('Email').value = l; @@ -92,7 +132,7 @@ function login(l, p) { document.getElementById('challenge').submit(); }); } - window.setTimeout(afterPlainLogin, loginTimeout); + window.setTimeout(afterPlainLogin(IntelURL, search), loginTimeout); }, loginTimeout) }, loginTimeout / 10); } @@ -101,7 +141,12 @@ function afterPlainLogin(IntelURL, search) { page.open(IntelURL, function(status) { if (status !== 'success') {quit('unable to connect to remote server')} + if (!isSignedIn()) { + announce('Something went wrong. Please, sign in to Google via your browser and restart ICE. Don\'t worry, your Ingress account will not be affected.'); + quit(); + } setTimeout(function() { + storeCookies(); waitFor({ timeout: 240000, check: function () { @@ -172,7 +217,19 @@ function waitFor ($config) { function afterCookieLogin(IntelURL, search) { page.open(IntelURL, function(status) { if (status !== 'success') {quit('unable to connect to remote server')} - + if(!isSignedIn()) { + if(fs.exists(cookiespath)) { + fs.remove(cookiespath); + } + if(validateEmail(SACSID)) { + page.deleteCookie('SACSID'); + page.deleteCookie('csrftoken'); + firePlainLogin(SACSID, CSRF); + return; + } else { + quit('Cookies are obsolete. Update your config file.'); + } + } setTimeout(function() { waitFor({ timeout: 240000,