bc-history.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. function bcHistoryEntry(hn,data){
  2. this.hn=hn
  3. this.data=data
  4. this.follow=false
  5. data=this.data
  6. this.counter_max =data[0]
  7. this.latlong =data[1]
  8. this.asn_list =data[2]
  9. this.hop_ip_list=data[3]
  10. this.telco_list =data[4]
  11. this.server_name_list =data[5]
  12. this.timestamp_list =data[6]
  13. this.country_code_list =data[7]
  14. this.unique_country_code_list =data[8]
  15. this.drawnLayers = new Array()
  16. this.index=0
  17. console.log("history entry for "+hn)
  18. this.state='hidden'
  19. this.speed= 1000 // animation speed in ms
  20. // console.log(data)
  21. this.show=function(){
  22. if(this.state==='hidden'){
  23. this.state='playing'
  24. this.stop_anim=false
  25. this.follow=true
  26. // console.log("showing "+this.hn + " state " + this.state )
  27. this.drawMarker()
  28. $("#status").html("Travelling to :")
  29. $("#url").html(this.hn)
  30. $(".header").show()
  31. }
  32. }
  33. this.makeLink = function(){
  34. link= '<center>'
  35. +'<h2>'+this.hn+' '
  36. if(this.state=='hidden')
  37. link =link +' <a href="#" title="play" onclick="bcHistory.play(\''+this.hn+'\')"><img src="images/play.png"/></a>'
  38. if(this.state=='playing')
  39. link =link +' <a href="#" title="stop" onclick="bcHistory.stop(\''+this.hn+'\')"><img src="images/stop.png"/></a>'
  40. if(this.state=='show')
  41. link =link +' <a href="#" title="hide" onclick="bcHistory.hide(\''+this.hn+'\')"><img src="images/hide.png"/></a>'
  42. link =link+' <a href="#" title="remove" onclick="bcHistory.remove(\''+this.hn+'\')"><img src="images/close.png"/></a>'
  43. +'</h2></center>'
  44. return link
  45. }
  46. this.drawMarker=function(){
  47. $("#url").html(this.hn)
  48. this.index=0
  49. this.delay = (100+this.timestamp_list[this.index]) //sets the animationspeed
  50. this.clusterGroups = {} //contains all country specific clusters
  51. this.makeClusterGroups(this.country_code_list) //initialize first cluster
  52. this.addStep() // initialize the animation
  53. }
  54. this.makeCustomMarker= function(){
  55. if (this.index < this.counter_max){
  56. var customIcon = new L.icon({
  57. iconUrl: 'images/markers/marker-icon-'+this.index+'.png',
  58. iconSize: [30, 30], // size of the icon
  59. iconAnchor: [15, 15], // point of the icon which will correspond to marker's location
  60. popupAnchor: [-150, 50] // point from which the popup should open relative to the iconAnchor
  61. });
  62. }
  63. if (this.index == this.counter_max){
  64. var customIcon = new L.icon({
  65. iconUrl: 'images/markers/marker-icon-last.png',
  66. iconSize: [30, 30], // size of the icon
  67. iconAnchor: [15, 15], // point of the icon which will correspond to marker's location
  68. popupAnchor: [-150, 0] // point from which the popup should open relative to the iconAnchor
  69. });
  70. }
  71. return customIcon
  72. }
  73. this.makeClusterGroups=function(country_code_list){
  74. for (var i = 0; i < this.unique_country_code_list.length; i++){
  75. if (this.unique_country_code_list[i] == this.country_code_list[this.index]){
  76. if (this.clusterGroups[this.unique_country_code_list[i]]){
  77. //checks if a cluster for the country already exists
  78. return
  79. }
  80. else
  81. //if not make it.
  82. this.clusterGroups[this.unique_country_code_list[i]] = new L.MarkerClusterGroup();
  83. }
  84. }
  85. }
  86. this.AddMarkerCluster= function(marker){
  87. this.clusterGroups[this.country_code_list[this.index]].addLayer(marker)
  88. map.addLayer(this.clusterGroups[this.country_code_list[this.index]])
  89. this.drawnLayers.push(this.clusterGroups[this.country_code_list[this.index]])
  90. }
  91. this.AddMarker =function(src){
  92. this.makeClusterGroups(this.country_code_list, this.index)
  93. // console.log(this.index)
  94. var marker = L.marker([src[0], src[1]],{icon: this.makeCustomMarker()})
  95. var popup = L.Popup({
  96. maxHeight: 50})
  97. var popupcontent = "<a href='https://en.wikipedia.org/wiki/"+this.country_code_list[this.index]+"' target='_blank'><img src='images/world/"+this.country_code_list[this.index]+".png'/></a>"
  98. +"<br />-------------<br />"
  99. +"IP: <br /><a onclick='bcHistory.display_by_ip(\""+this.hn+"\",\""+this.index+"\")' href='#'>"
  100. +this.hop_ip_list[this.index]+"</a><br />"
  101. +"Server name:<br /><a onclick='bcHistory.display_by_net(\""+this.hn+"\",\""+this.index+"\")' href='#'>"
  102. +this.server_name_list[this.index]+"</a><br />"
  103. //+"Network owner:<br /><b>"+this.telco_list[this.index]+"</b><br />"
  104. +"Network owner:<br /><a onclick='bcHistory.displayMetadata(\""+this.hn+"\",\""+this.index+"\")' href='#'>"
  105. +this.telco_list[this.index]+"</a>"
  106. //+" IP: <b>"+this.hop_ip_list[index]+"</b>"
  107. marker.bindPopup(popupcontent)
  108. this.AddMarkerCluster(marker, this.index)
  109. this.drawnLayers.push(marker)
  110. }
  111. this.displayMetadata=function(index){
  112. duck_link= "";// parse when no network owner available for DuckGo
  113. wikileaks_link= "";// parse when no network owner available for wikileaks
  114. if (this.telco_list[index] == "Unknown"){
  115. duck_link =duck_link;
  116. }else{
  117. duck_link =duck_link+"<a target='_blank' href='https://duckduckgo.com/?q="+this.telco_list[index]+"'>DuckGo</a><br />"
  118. }
  119. if (this.telco_list[index] == "Unknown"){
  120. wikileaks_link =wikileaks_link;
  121. }else{
  122. wikileaks_link =wikileaks_link+"<a target='_blank' href='https://search.wikileaks.org/?q="+this.telco_list[index]+"'>Wikileaks</a>"
  123. }
  124. $(".bc-custom-control").html("<a href='#' onclick='$(\".bc-custom-control\").hide()'><img src=\"images/close.png\" style=\"float:right\"/></a><br />"
  125. +"Network owner:<br /><b>"+this.telco_list[index]+"</a></b>"
  126. +"<br />-------------<br />"
  127. // aded DuckGoDuck
  128. +duck_link
  129. // added Wikileaks
  130. +wikileaks_link)
  131. $(".bc-custom-control").show()
  132. }
  133. this.display_by_net=function(index){
  134. asn_link= '' // parse when no asn available
  135. if (this.asn_list[index] == "Not Available"){
  136. asn_link =asn_link+"?";
  137. }else{
  138. asn_link =asn_link+"<a target='_blank' href='https://www.ultratools.com/tools/asnInfoResult?domainName="+this.asn_list[index]+"'>"+this.asn_list[index]+"</a>"
  139. }
  140. $(".bc-custom-control").html("<a href='#' onclick='$(\".bc-custom-control\").hide()'><img src=\"images/close.png\" style=\"float:right\"/></a><br />"
  141. +"Server name:<br /><b>"+this.server_name_list[index]+"</b>"
  142. +"<br />-------------<br />"
  143. +"ASN: <b>"+asn_link+"</b><br />"
  144. +"Lat,Long: <b>"
  145. +this.latlong[index]+ "</b>")
  146. $(".bc-custom-control").show()
  147. }
  148. this.display_by_ip=function(index){
  149. $(".bc-custom-control").html("<a href='#' onclick='$(\".bc-custom-control\").hide()'><img src=\"images/close.png\" style=\"float:right\"/></a><br />"
  150. +"IP: <b>"+this.hop_ip_list[index]+"</b>"
  151. +"<br />-------------<br />"
  152. // added Who.is
  153. +"<a target='_blank' href='https://who.is/whois-ip/ip-address/"+this.hop_ip_list[index]+"'>Whois</a><br />"
  154. // added Shodan.io
  155. +"<a target='_blank' href='https://www.shodan.io/search?query="+this.hop_ip_list[index]+"'>ShodanHQ</a><br />"
  156. // added Wolfram
  157. +"<a target='_blank' href='http://www.wolframalpha.com/input/?i="+this.hop_ip_list[index]+"'>Wolfram</a>")
  158. $(".bc-custom-control").show()
  159. }
  160. this.addStep=function (){
  161. if(this.stop_anim){
  162. // console.log(this.hn+" : addstep/stopping anim")
  163. this.stop_anim=false
  164. this.run_anim=false;
  165. return
  166. }
  167. // console.log(this.hn+" : add step "+this.index)
  168. var src = this.latlong[this.index]
  169. var dest = this.latlong[this.index]
  170. if (this.index < this.counter_max){
  171. var dest = this.latlong[this.index+1]
  172. }
  173. var b = new R.BezierAnim([src, dest])
  174. map.addLayer(b)
  175. this.drawnLayers.push(b)
  176. this.AddMarker(src, this.index)
  177. if (this.index < this.counter_max){
  178. map.panTo(this.latlong[this.index+1],{
  179. animate: true,
  180. duration: this.speed/1000
  181. })
  182. }
  183. else
  184. if (this.index == this.counter_max){
  185. map.panTo(this.latlong[this.index],{
  186. animate: true,
  187. duration: this.speed/1000
  188. })
  189. }
  190. window.setTimeout("bcHistory.process('"+this.hn+"')", this.speed)
  191. }
  192. this.processStep=function () {
  193. if(this.stop_anim){
  194. // console.log(this.hn+" : processstep/stopping anim")
  195. this.stop_anim=false
  196. this.run_anim=false;
  197. return
  198. }
  199. console.log(this.hn+" : process step "+this.index)
  200. this.delay = (100 + this.timestamp_list[this.index])
  201. if (this.index < this.counter_max){
  202. changeFavicon('images/world/'+this.country_code_list[this.index]+'.png')
  203. window.setTimeout("bcHistory.addStep('"+this.hn+"')",this.delay)
  204. }
  205. if (this.index == this.counter_max){
  206. // map.panTo(latlong[this.index]);
  207. changeFavicon('images/world/'+this.country_code_list[this.index]+'.png')
  208. this.run_anim=false
  209. this.state='show'
  210. $("#status").html("Showing...")
  211. // console.log('fin')
  212. // map.fitBounds([bounds])
  213. }
  214. this.index = this.index + 1
  215. }
  216. this.stop=function(){
  217. if(this.index >0){
  218. this.state='show'
  219. $("#status").html("Showing...")
  220. }
  221. this.stop_anim=true
  222. }
  223. this.hide=function() {
  224. // console.log ("hiding "+ this.hn)
  225. // if(this.state=='show'){
  226. $('.header').hide()
  227. this.index =0
  228. this.state='hidden'
  229. this.stop_anim=true
  230. for (i in this.drawnLayers){
  231. // console.log("removing layer "+i)
  232. // console.log(this.drawnLayers[i])
  233. if(map.hasLayer(this.drawnLayers[i]))
  234. map.removeLayer(this.drawnLayers[i])
  235. }
  236. this.drawnLayers=new Array()
  237. }
  238. // }
  239. }
  240. function bcHistoryClass(){
  241. this.cur_url="";
  242. this.last_url="";
  243. this.bcHistoryEntries = new Array
  244. this.find=function (hn){
  245. for (bcEntry in this.bcHistoryEntries){
  246. if (this.bcHistoryEntries[bcEntry].hn === hn){
  247. return this.bcHistoryEntries[bcEntry]
  248. }
  249. }
  250. return false;
  251. }
  252. this.process=function (hn){
  253. bce=this.find(hn)
  254. if(bce) bce.processStep()
  255. }
  256. this.addStep=function(hn){
  257. bce=this.find(hn)
  258. if(bce) bce.addStep()
  259. }
  260. this.render=function(){
  261. $("#history-content").html("");
  262. for (bcEntry in this.bcHistoryEntries){
  263. // console.log(bcHistoryEntries[bcEntry]);
  264. $("#history-content").append(this.bcHistoryEntries[bcEntry].makeLink())
  265. }
  266. }
  267. this.load=function(hn){
  268. // console.log("loadin "+hn);
  269. e=this.find(hn)
  270. if(e){
  271. e.show()
  272. return
  273. }
  274. // console.log("loadin "+hn+" failed !" );
  275. return false
  276. }
  277. this.play = function(hn){
  278. var bce=this.find(hn)
  279. if(!bce) return
  280. this.hideAll()
  281. bce.show()
  282. this.render()
  283. }
  284. this.hideAll = function(hn){
  285. for (bce in this.bcHistoryEntries)
  286. this.bcHistoryEntries[bce].hide()
  287. this.render()
  288. }
  289. this.hide = function(hn){
  290. var bce=this.find(hn)
  291. if(!bce) return
  292. bce.hide()
  293. this.render()
  294. }
  295. this.displayMetadata = function(hn,index){
  296. var bce=this.find(hn)
  297. if(!bce) return
  298. return bce.displayMetadata(index);
  299. }
  300. this.display_by_net = function(hn,index){
  301. var bce=this.find(hn)
  302. if(!bce) return
  303. return bce.display_by_net(index);
  304. }
  305. this.display_by_ip = function(hn,index){
  306. var bce=this.find(hn)
  307. if(!bce) return
  308. return bce.display_by_ip(index);
  309. }
  310. this.remove = function(hn){
  311. // console.log("removing " + hn)
  312. // console.log(this.bcHistoryEntries)
  313. for (bcEntry in this.bcHistoryEntries){
  314. if(this.bcHistoryEntries[bcEntry].hn === hn){
  315. // console.log("removing "+ this.bcHistoryEntries[bcEntry].hn +" | "+ hn)
  316. this.bcHistoryEntries[bcEntry].hide()
  317. this.bcHistoryEntries.splice(bcEntry,1)
  318. this.render()
  319. return
  320. }
  321. }
  322. }
  323. this.add = function(hn,data){
  324. // console.log("adding " + hn)
  325. var bce=this.find(hn)
  326. if(!bce){
  327. console.log("adding " + hn)
  328. bce=new bcHistoryEntry(hn,data)
  329. this.cur_url=hn
  330. this.bcHistoryEntries.push(bce)
  331. this.play(hn)
  332. }
  333. return bce
  334. }
  335. this.stop=function() {
  336. for(i=0;i<this.bcHistoryEntries.length;i++) {
  337. this.bcHistoryEntries[i].stop();
  338. }
  339. this.render()
  340. }
  341. }
  342. var bcHistory=new bcHistoryClass()
  343. var cur_url=""