initial commit
[map.git] / honeymap-master / static / feed_socketio_hpfeeds.js
1 var socket = io.connect('/');
2
3 function set_marker_caption(id, lat, lng, countrycode, city) {
4   markercaptions[id] = "<small>(" + lat + ", " + lng + ")</small><br/>";
5   if(city) {
6     markercaptions[id] += "<big>" + city + "</big> (" + countrycode + ")";
7   }
8 }
9
10 socket.on('marker', function(data) {
11   var lat1 = data.latitude,  lng1 = data.longitude,
12       lat2 = data.latitude2, lng2 = data.longitude2;
13
14   if(lat1 == null || lng1 == null) {
15     return;
16   }
17
18   var p1 = mapobj.latLngToPoint(lat1,lng1);
19   if(p1.x == 0 && p1.y == 0) { return; }
20
21   var region1;
22   if(data.countrycode != null && mapobj.regions[data.countrycode] != null) {
23     region1 = mapobj.regions[data.countrycode].config.name;
24   } else {
25     region1 = get_regionname_ll(lat1, lng1);
26   }
27
28   var region2;
29   if(data.countrycode2 != null && mapobj.regions[data.countrycode2] != null) {
30     region2 = mapobj.regions[data.countrycode2].config.name;
31   } else {
32     region2 = get_regionname_ll(lat2, lng2);
33   }
34
35   if(region1 != null) {
36     var logstr;
37
38     if(data.type == null) { data.type = "other"; }
39
40     logstr  = '<div class="log_timestamp">';
41     logstr += new Date().toTimeString().substring(0,8);
42     logstr += "</div>";
43     logstr += ' <div class="log_bracket">&lt;</div>' + data.type + '<div class="log_bracket">&gt;</div> ';
44     logstr += 'New ' + (data.type == "thug.events" ? "scan" : "attack") + ' from ' + 
45       '<div class="log_country">' + (data.city ? (data.city + ", ") : "") + region1 + '</div>' + 
46       ' <small>(' + lat1.toFixed(2) + "," + lng1.toFixed(2) + ")</small>";
47
48     if(region2 != null) {
49       logstr += ' to <div class="log_country">' + (data.city2 ? (data.city2 + ", ") : "") + region2 + "</div>" +
50         " <small>(" + lat2.toFixed(2) + "," + lng2.toFixed(2) + ")</small>";
51     }
52
53     if(data.md5) {
54       logstr += ' <div class="log_bracket2">[</div><div class="log_info">md5: <a href="http://www.virustotal.com/search/?query=' + data.md5 + '">' + data.md5 + '</a><div class="log_bracket2">]</div></div>';
55     }
56     add_log(logstr);
57   }
58
59   add_marker_ll(lat1, lng1, 'src', data.type, data.countrycode);
60   set_marker_caption(lat1+","+lng1, lat1, lng1, data.countrycode, data.city);
61   update_regioncolors();
62
63   if(lat2 == null || lng2 == null) { return; }
64   var p2 = mapobj.latLngToPoint(lat2,lng2);
65   if(p2.x == 0 || p2.y == 0) { return; }
66   add_marker_ll(lat2, lng2, 'dst', data.type, data.countrycode2);
67   set_marker_caption(lat2+","+lng2, lat2, lng2, data.countrycode2, data.city2);
68
69 });