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 05334ff9e081735380dc9033d551d31184794c55
parent a7ad2fb8b29b6c9a8d502744b402926a193c3c74
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 15 Nov 2016 08:16:31 +0100

add experimental email/password login

Diffstat:
M__init__.py | 25++++++++++++++++---------
Mscreencap_iitc.js | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mscreencap_intel.js | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 289 insertions(+), 15 deletions(-)

diff --git a/__init__.py b/__init__.py @@ -168,14 +168,21 @@ def intel(bot, event, *args): url = bot.conversation_memory_get(event.conv_id, 'IntelURL') if bot.config.exists(["intel_screenbot", "SACSID"]): - SACSID = bot.config.get_by_path(["intel_screenbot", "SACSID"]) - else: - html = "<i><b>{}</b> No Intel SACSID Cookie has been added to config. Unable to authenticate".format(event.user.full_name) - yield from bot.coro_send_message(event.conv, html) - if bot.config.exists(["intel_screenbot", "CSRF"]): - CSRF = bot.config.get_by_path(["intel_screenbot", "CSRF"]) + if bot.config.exists(["intel_screenbot", "CSRF"]): + SACSID = bot.config.get_by_path(["intel_screenbot", "SACSID"]) + CSRF = bot.config.get_by_path(["intel_screenbot", "CSRF"]) + else: + html = "<i><b>{}</b> No Intel password has been added to config. Unable to authenticate".format(event.user.full_name) + yield from bot.coro_send_message(event.conv, html) + elif bot.config.exists(["intel_screenbot", "email"]): + if bot.config.exists(["intel_screenbot", "email"]): + SACSID = bot.config.get_by_path(["intel_screenbot", "email"]) + CSRF = bot.config.get_by_path(["intel_screenbot", "password"]) + else: + html = "<i><b>{}</b> No Intel password has been added to config. Unable to authenticate".format(event.user.full_name) + yield from bot.coro_send_message(event.conv, html) else: - html = "<i><b>{}</b> No Intel CSRF Cookie has been added to config. Unable to authenticate".format(event.user.full_name) + html = "<i><b>{}</b> No Intel SACSID Cookie or Email/password has been added to config. Unable to authenticate".format(event.user.full_name) yield from bot.coro_send_message(event.conv, html) if url is None: @@ -273,10 +280,10 @@ def iitc(bot, event, *args): plugins.append(plugin_objects["url"]) else: plugins = '' - + with open(plugins_filepath, 'w') as out: out.write(json.dumps(plugins)) - + try: loop = asyncio.get_event_loop() image_data = yield from _screencap("iitc", url, filepath, filename, SACSID, CSRF, plugins_filepath, search, bot, event) diff --git a/screencap_iitc.js b/screencap_iitc.js @@ -12,6 +12,7 @@ if (args.length === 1) { var filepath = args[4]; var plugins_file = args[5]; var search = 'nix'; + var loginTimeout = '10000'; }else{ if (args.length === 7){ var SACSID = args[1]; @@ -20,10 +21,166 @@ if (args.length === 1) { var filepath = args[4]; var search = args[5]; var plugins_file = args[6]; + var loginTimeout = '10000'; } } } +function validateEmail(email) { + var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(email); +} + +if (validateEmail(SACSID)) { + firePlainLogin(SACSID, CSRF); + afterPlainLogin(IntelURL, search); +}else { + addCookies(SACSID, CSRF); + afterCookieLogin(IntelURL, search); +} + + +function firePlainLogin(SACSID, CSRF) { + page.open('https://www.ingress.com/intel', function (status) { + if (status !== 'success') {quit('unable to connect to remote server')} + var link = page.evaluate(function () { + return document.getElementsByTagName('a')[0].href; + }); + page.open(link, function () { + login(SACSID, CSRF); + }); + }); +} + +function login(l, p) { + page.evaluate(function (l) { + document.getElementById('Email').value = l; + }, l); + page.evaluate(function () { + document.querySelector("#next").click(); + }); + window.setTimeout(function () { + page.evaluate(function (p) { + document.getElementById('Passwd').value = p; + }, p); + page.evaluate(function () { + document.querySelector("#next").click(); + }); + page.evaluate(function () { + document.getElementById('gaia_loginform').submit(); + }); + window.setTimeout(function () { + if (page.url.substring(0,40) === 'https://accounts.google.com/ServiceLogin') { + quit('login failed: wrong email and/or password'); + } + if (page.url.substring(0,40) === 'https://appengine.google.com/_ah/loginfo') { + page.evaluate(function () { + document.getElementById('persist_checkbox').checked = true; + document.getElementsByTagName('form').submit(); + }); + } + if (page.url.substring(0,44) === 'https://accounts.google.com/signin/challenge') { + twostep = system.stdin.readLine(); + } + if (twostep) { + page.evaluate(function (code) { + document.getElementById('totpPin').value = code; + }, twostep); + page.evaluate(function () { + document.getElementById('submit').click(); + document.getElementById('challenge').submit(); + }); + } + window.setTimeout(afterPlainLogin, loginTimeout); + }, loginTimeout) + }, loginTimeout / 10); +} + +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'); + setTimeout(function() { + page.evaluate(function() { + localStorage['ingress.intelmap.layergroupdisplayed'] = JSON.stringify({ + "Unclaimed Portals":Boolean(1 === 1), + "Level 1 Portals":Boolean(1 === 1), + "Level 2 Portals":Boolean((1 <= 2) && (8 >= 2)), + "Level 3 Portals":Boolean((1 <= 3) && (8 >= 3)), + "Level 4 Portals":Boolean((1 <= 4) && (8 >= 4)), + "Level 5 Portals":Boolean((1 <= 5) && (8 >= 5)), + "Level 6 Portals":Boolean((1 <= 6) && (8 >= 6)), + "Level 7 Portals":Boolean((1 <= 7) && (8 >= 7)), + "Level 8 Portals":Boolean(8 === 8), + "DEBUG Data Tiles":false, + "Artifacts":true, + "Ornaments":true + }); + var script = document.createElement('script'); + script.type='text/javascript'; + script.src='https://secure.jonatkins.com/iitc/release/total-conversion-build.user.js'; + document.head.insertBefore(script, document.head.lastChild); + }); + loadIitcPlugin('http://iitc.jonatkins.com/release/plugins/canvas-render.user.js'); + var plugins = JSON.parse(fs.read(plugins_file)); + for(var i in plugins){ + var plugin = plugins[i]; + if(plugin.match('^[a-zA-Z]+://')){ + loadIitcPlugin(plugin); + }else{ + loadLocalIitcPlugin(plugin); + } + } + setTimeout(function() { + if (search != "nix") { + page.evaluate(function(search) { + if (document.querySelector('#search')){ + window.setTimeout(function() { + document.getElementById("search").value=search; + var e = jQuery.Event("keypress"); + e.which = 13; + e.keyCode = 13; + $("#search").trigger(e); + }, 2000); + var checkExist = setInterval(function() { + if ($('.searchquery').length > 0) { + window.setTimeout(function() {$('.searchquery > :nth-child(2)').children()[0].click();}, 1000); + clearInterval(checkExist); + } + }, 100); + } + }, search); + } + waitFor({ + timeout: 240000, + check: function () { + return page.evaluate(function() { + if (document.querySelector('.map').textContent.indexOf('done') != -1) { + return true; + }else{ + return false; + } + }); + }, + success: function () { + hideDebris(); + prepare('1920', '1080'); + main(); + }, + error: function () { + hideDebris(); + prepare('1920', '1080'); + main(); + } + }); + }, "5000"); + }, "5000"); + }); +} + + + function addCookies(sacsid, csrf) { phantom.addCookie({ name: 'SACSID', @@ -69,9 +226,6 @@ function loadLocalIitcPlugin(src) { page.injectJs(src) } -addCookies(SACSID, CSRF); -afterCookieLogin(IntelURL, search); - function afterCookieLogin(IntelURL, search) { page.viewportSize = { width: '1920', height: '1080' }; page.open(IntelURL, function(status) { @@ -124,7 +278,7 @@ function afterCookieLogin(IntelURL, search) { window.setTimeout(function() {$('.searchquery > :nth-child(2)').children()[0].click();}, 1000); clearInterval(checkExist); } - }, 100); + }, 100); } }, search); } diff --git a/screencap_intel.js b/screencap_intel.js @@ -22,8 +22,121 @@ if (args.length === 1) { } } -addCookies(SACSID,CSRF); -afterCookieLogin(IntelURL, search); +function validateEmail(email) { + var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(email); +} + +if (validateEmail(SACSID)) { + firePlainLogin(SACSID, CSRF); + afterPlainLogin(IntelURL); +}else { + addCookies(SACSID, CSRF); + afterCookieLogin(IntelURL, search); +} + +function firePlainLogin(SACSID, CSRF) { + page.open('https://www.ingress.com/intel', function (status) { + + if (status !== 'success') {quit('unable to connect to remote server')} + + var link = page.evaluate(function () { + return document.getElementsByTagName('a')[0].href; + }); + + page.open(link, function () { + login(SACSID, CSRF); + }); + }); +} + +function login(l, p) { + page.evaluate(function (l) { + document.getElementById('Email').value = l; + }, l); + page.evaluate(function () { + document.querySelector("#next").click(); + }); + window.setTimeout(function () { + page.evaluate(function (p) { + document.getElementById('Passwd').value = p; + }, p); + page.evaluate(function () { + document.querySelector("#next").click(); + }); + page.evaluate(function () { + document.getElementById('gaia_loginform').submit(); + }); + window.setTimeout(function () { + if (page.url.substring(0,40) === 'https://accounts.google.com/ServiceLogin') { + quit('login failed: wrong email and/or password'); + } + + if (page.url.substring(0,40) === 'https://appengine.google.com/_ah/loginfo') { + page.evaluate(function () { + document.getElementById('persist_checkbox').checked = true; + document.getElementsByTagName('form').submit(); + }); + } + + if (page.url.substring(0,44) === 'https://accounts.google.com/signin/challenge') { + twostep = system.stdin.readLine(); + } + + if (twostep) { + page.evaluate(function (code) { + document.getElementById('totpPin').value = code; + }, twostep); + page.evaluate(function () { + document.getElementById('submit').click(); + document.getElementById('challenge').submit(); + }); + } + window.setTimeout(afterPlainLogin, loginTimeout); + }, loginTimeout) + }, loginTimeout / 10); +} + +function afterPlainLogin(IntelURL, search) { + page.open(IntelURL, function(status) { + if (status !== 'success') {quit('unable to connect to remote server')} + + setTimeout(function() { + waitFor({ + timeout: 240000, + check: function () { + return page.evaluate(function() { + if (document.querySelector('#percent_text').textContent.indexOf('90') != -1) { + if (!document.getElementById("loading_msg").style.display){ + return true; + }else{ + return false; + } + }else{ + return false; + } + }); + }, + success: function () { + page.evaluate(function() { + document.querySelector("#filters_container").style.display= 'none'; + }); + hideDebris(); + prepare('1920', '1080', search); + main(); + }, + error: function () { + page.evaluate(function() { + document.querySelector("#filters_container").style.display= 'none'; + }); + hideDebris(); + prepare('1920', '1080', search); + main(); + } + }); + }, "5000"); + }); +} function addCookies(sacsid, csrf) { phantom.addCookie({