Skip to content

Commit

Permalink
Both Socket.io feeds working in CoffeeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
fw42 committed May 20, 2013
1 parent 30dc739 commit e4e08ab
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ all: static
static: static/js/honeymap.js

static/js/honeymap.js: static/coffee/*
coffee -cj static/js/honeymap.js static/coffee
coffee -cj static/js/honeymap.js static/coffee/*.coffee static/coffee/feeds/socketio.coffee

clean:
rm static/js/honeymap.js
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ HoneyMap is a web application which visualizes a live stream of
GPS locations on a SVG world map. In principle, it can be used
with any stream of GPS data. For our application, we use honeypot
captures, provided by several [hpfeeds](https://github.com/rep/hpfeeds)
from the [Honeynet Project](http://www.honeynet.org/).
from the [Honeynet Project](http://www.honeynet.org/). For more information
on our instance of HoneyMap, see
[HoneyMap - Visualizing Worldwide Attacks in Real-Time](http://www.honeynet.org/node/960).

It is written in [CoffeeScript](http://coffeescript.org/) and makes use of
[jQuery](http://jquery.com/), [node.js](http://nodejs.org/),
Expand Down
8 changes: 4 additions & 4 deletions static/coffee/feeds/random.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ class Feed
constructor: (map, log, pause) ->
@map = map
@log = log
window.setInterval((=> window.setTimeout(@randomPoint, Math.random() * pause)), 2 * pause)
window.setInterval((=> window.setTimeout(@handler, Math.random() * pause)), 2 * pause)

randomPoint: =>
handler: =>
while true
lat = Math.random() * 180 - 90
lng = Math.random() * 360 - 180
marker = new Marker(@map, lat, lng)
marker = new Marker(@map, lat, lng, "random")
break if marker.regionCode
@map.addMarker(marker)
@log.add "New event in " + marker.regionName() + " (" + lat.toFixed(2) + ", " + lng.toFixed(2) + ")"
@log.add "New event in " + marker.regionName() + " " + marker.name()
39 changes: 39 additions & 0 deletions static/coffee/feeds/socketio.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Feed
constructor: (map, log) ->
@map = map
@log = log
@socket = io.connect('/');
@socket.on("marker", @handler)

handler: (data) =>
lat1 = data.latitude
lng1 = data.longitude
return unless lat1 and lng1
src = new Marker(@map, lat1, lng1, data.type, "src", data.countrycode, data.city)
return if src.x == 0 and src.y == 0
lat2 = data.latitude2
lng2 = data.longitude2
if lat2 and lng2
dst = new Marker(@map, lat2, lng2, data.type, "dst", data.countrycode2, data.city2)
if dst.x == 0 and dst.y == 0 then dst = null
@addLog(src, dst, data.md5)
@map.addMarker(src)
@map.addMarker(dst) if dst

addLog: (src, dst, md5) ->
return unless src.regionName()
timestamp = new Date().toTimeString().substring(0,8)
attacktype = if src.eventName == "thug.events" then "scan" else "attack"
logstr = """
<div class="log_timestamp">#{timestamp}</div>
<div class="log_bracket">&lt;</div>#{src.eventName}<div class="log_bracket">&gt;</div>
New #{attacktype} from <div class="log_country">#{src.location()}</div>
<small>#{src.name()}</small>
"""
if dst and dst.regionName()
logstr += " to <div class=\"log_country\">#{dst.location()}</div> <small>#{dst.name()}</small>"
if md5
logstr += " <div class=\"log_bracket2\">[</div>" + \
"<div class=\"log_info\"><a href=\"http://www.virustotal.com/search/?query=#{md5}\">#{md5.substr(0,9)}</a></div>" + \
"<div class=\"log_bracket2\">]</div>"
@log.add logstr
14 changes: 14 additions & 0 deletions static/coffee/feeds/socketio_random.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Feed
constructor: (map, log) ->
@map = map
@log = log
@socket = io.connect('/')
@socket.on("marker", @handler)

handler: (data) =>
lat = data.lat
lng = data.lng
marker = new Marker(@map, lat, lng, "socketio_random")
return unless marker.regionCode
@map.addMarker(marker)
@log.add "New event in " + marker.regionName() + " " + marker.name()
13 changes: 7 additions & 6 deletions static/coffee/honeymap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Honeymap
else
return null

regionName: (regionCode) ->
@mapObj.getRegionName(regionCode)

incMarkerCount: (marker) ->
@hits.marker[marker.id()] ||= {}
@hits.marker[marker.id()][marker.eventName] ||= 0
Expand All @@ -90,12 +93,8 @@ class Honeymap
@captions[marker.id()] = marker.caption()
@incMarkerCount(marker)
@updateRegionColors()

# only add new markers div's to jVectorMap which do not exist yet
if @mapObj.markers[marker.id()]
console.log(marker.id() + " already exists")
return

return if @mapObj.markers[marker.id()]
@hits.marker["total"]++
if @hits.marker["total"] > config.markersMaxVisible then @removeOldestMarker()
@mapObj.addMarker(marker.id(), { latLng: marker.gps(), name: marker.name(), style: @config.colors[marker.type] }, [])
Expand All @@ -105,5 +104,7 @@ class Honeymap
total = 0
summary = "<hr/>"
for type, count of hits
summary += "<b>" + type + "</b>: " + (total += (count ||= 0)) + "<br/>"
count ||= 0
summary += "<b>#{type}</b>: #{count}<br/>"
total += count
summary + "<hr/><b>total</b>: " + total + " events"
3 changes: 1 addition & 2 deletions static/coffee/log.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ class Log
@fitSize()

fitSize: ->
@elem.width(0.5 * jQuery(document).width())
@elem.width(0.6 * jQuery(document).width())
@elem.css("margin-top", 0.03 * jQuery(document).height())
@elem.height(0.15 * jQuery(document).height())

clearOld: ->
entries = @elem.find("div.log_entry")
if entries.length >= @max
console.log("clearing")
entries.slice(0, entries.length/2).remove()
@elem.find("br").nextUntil('div.log_entry', 'br').remove()

Expand Down
2 changes: 1 addition & 1 deletion static/coffee/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jQuery(document).ready ->
log.add "<b>Welcome to HoneyMap. This is a BETA version! Bug reports welcome :-)</b>"
log.add "Note that this is not <b>all</b> honeypots of the Honeynet Project,"
log.add "only those who voluntarily publish their captures to hpfeeds!"
log.add "<br/>"
log.add ""

new Feed(honeymap, log, 500)
7 changes: 4 additions & 3 deletions static/coffee/marker.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Marker
constructor: (map, lat, lng, type, eventName, regionCode, cityName) ->
constructor: (map, lat, lng, eventName, type, regionCode, cityName) ->
@map = map
@lat = lat
@lng = lng
Expand Down Expand Up @@ -29,6 +29,7 @@ class Marker
return caption

id: -> @lat + "," + @lng
name: -> "(" + @lat + ", " + @lng + ")"
name: -> "(" + @lat.toFixed(2) + ", " + @lng.toFixed(2) + ")"
gps: -> [ @lat, @lng ]
regionName: -> @map.mapObj.getRegionName(@regionCode) if @regionCode
regionName: -> @map.regionName(@regionCode) if @regionCode
location: -> (if @cityName then @cityName + ", " else "") + @regionName()
4 changes: 2 additions & 2 deletions static/honeymap.css → static/css/honeymap.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ a {
position: absolute;
left: 1%;
bottom: 1%;
max-width: 20%;
max-width: 15%;
}

#logo1 img, #logo2 img {
Expand All @@ -63,7 +63,7 @@ a {
position: absolute;
right: 1%;
bottom: 1%;
max-width: 20%;
max-width: 15%;
}

#helpbtn {
Expand Down
25 changes: 20 additions & 5 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

<head>
<title>HoneyMap</title>
<link rel="stylesheet" href="honeymap.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="css/honeymap.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="extern/jquery-jvectormap-1.0.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="extern/bootstrap.min.css" type="text/css" media="screen"/>
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono' rel='stylesheet' type='text/css'>
<meta content="Florian Weingarten, Mark Schloesser" name="author" />
<meta content="Florian Weingarten, Mark Schloesser, Johannes Gilger" name="author" />
<script src="extern/jquery-1.7.2.min.js"></script>
<script src="extern/jquery-jvectormap-1.0.min.js"></script>
<script src="extern/jquery-jvectormap-world-mill-en.js"></script>
Expand Down Expand Up @@ -58,9 +58,24 @@ <h4>Technology</h4>
Sourcecode for this project is available on <a href="https://github.com/fw42/honeymap/">GitHub</a>.
<h4>Authors</h4>
<ul>
<li>Florian Weingarten (<a href="mailto:flo@hackvalue.de">flo@hackvalue.de</a>) (<a href="https://twitter.com/fw1729">@fw1729</a>)</li>
<li>Mark Schloesser (<a href="mailto:ms@mwcollect.org">ms@mwcollect.org</a>) (<a href="https://twitter.com/repmovsb">@repmovsb</a>)</li>
<li>Johannes Gilger (<a href="mailto:heipei@heipei.net">heipei@heipei.net</a>) (<a href="https://twitter.com/heipei">@heipei</a>)</li>
<li>
Florian Weingarten
(<a href="mailto:flo@hackvalue.de">flo@hackvalue.de</a>)
(<a href="https://twitter.com/fw1729">@fw1729</a>)
(<a href="https://github.com/fw42/">fw42</a>)
</li>
<li>
Mark Schloesser
(<a href="mailto:ms@mwcollect.org">ms@mwcollect.org</a>)
(<a href="https://twitter.com/repmovsb">@repmovsb</a>)
(<a href="https://github.com/rep">rep</a>)
</li>
<li>
Johannes Gilger
(<a href="mailto:heipei@heipei.net">heipei@heipei.net</a>)
(<a href="https://twitter.com/heipei">@heipei</a>)
(<a href="https://github.com/heipei">heipei</a>)
</li>
</ul>

<h3>Frequently Asked Questions</h3>
Expand Down
Loading

0 comments on commit e4e08ab

Please sign in to comment.