[or-cvs] r16574: {} A first stab at automated xml generation of google maps of t (in projects/dir-stats/trunk: . google-mapping)

ioerror at seul.org ioerror at seul.org
Sun Aug 17 04:33:38 UTC 2008


Author: ioerror
Date: 2008-08-17 00:33:38 -0400 (Sun, 17 Aug 2008)
New Revision: 16574

Added:
   projects/dir-stats/trunk/google-mapping/
   projects/dir-stats/trunk/google-mapping/README
   projects/dir-stats/trunk/google-mapping/routers-geo-ip-gmaps.py
   projects/dir-stats/trunk/google-mapping/v3-tormap.html
Log:
A first stab at automated xml generation of google maps of the nodes in the v3 consensus.


Added: projects/dir-stats/trunk/google-mapping/README
===================================================================
--- projects/dir-stats/trunk/google-mapping/README	                        (rev 0)
+++ projects/dir-stats/trunk/google-mapping/README	2008-08-17 04:33:38 UTC (rev 16574)
@@ -0,0 +1,28 @@
+This directory will someday hold a useful set of programs for creating google
+(or other) interactive maps.  The idea is to visual data about the Tor network
+in an automated manner. A secondary goal is to have interactive visualizations.
+
+Currently, to generate an XML file, you'll need a copy of a cached-routers or
+cached-descriptors to parse.
+
+To get useful geoip information, you'll need a copy of the maxmind geoip
+database:
+
+    http://www.maxmind.com/download/geoip/database/
+
+It is possible to automate the xml in cron like so:
+
+    ioerror at moria:~$ crontab -l
+    # m h  dom mon dow   command
+    # http_proxy=http://127.0.0.1:8118/
+    PYTHONPATH=/home/ioerror/python-lib//lib/python
+    5,10,15,20,25,30,35,40,45,50,55 * * * * routers-geo-ip-gmaps.py > tor-data.xml
+
+In addition to the generated xml file, you'll also need a web page that parses it.
+The clients who visit the site do half of the heavy lifting. The other half is
+done by google. I borrowed an example google maps API html page from the
+'apache-geo-map' project. It needs work but it is functional. I have included
+it here as v3-tormap.html. The current version of the html has a google api key
+that authorizes the map to run from anywhere on freehaven.net/~ioerror/. If
+this doesn't work for you, please get your own google api key. :-)
+

Added: projects/dir-stats/trunk/google-mapping/routers-geo-ip-gmaps.py
===================================================================
--- projects/dir-stats/trunk/google-mapping/routers-geo-ip-gmaps.py	                        (rev 0)
+++ projects/dir-stats/trunk/google-mapping/routers-geo-ip-gmaps.py	2008-08-17 04:33:38 UTC (rev 16574)
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+# 
+# This program parses /var/lib/tor/cached-routers 
+# It output data in an "XML" format for use with the googlemaps API
+# crontab -l
+# m h  dom mon dow   command
+# http_proxy=http://127.0.0.1:8118/
+# 5,10,15,20,25,30,35,40,45,50,55 * * * * geo-ip-gmaps.py > tor-map-data.xml
+#
+#
+
+import GeoIP
+import sys
+import re
+
+# You may need to fetch this from maxmind
+# http://www.maxmind.com/download/geoip/database/
+gi = GeoIP.open("GeoLiteCity.dat",GeoIP.GEOIP_STANDARD)
+
+# Operate on a copy unless you have privs to open /var/lib/tor/cached-routers
+file = open("/var/lib/tor/cached-descriptors", "r")
+line = file.readline()
+
+print "<markers>"
+while line:
+    if line.startswith("router "):
+        (type, nodeName, ipAddress, OrPort, other, DirPort ) = line.split() 
+        gir = gi.record_by_addr(ipAddress)
+        if gir != None:
+            print "<marker lat=\"" + str(gir['latitude']) + "\" lng=\"" + str(gir['longitude']) + "\" html=\""+ str(nodeName) + " " + str(ipAddress) + " " + str(gir['city']) + ", " + str(gir['country_name']) + " \"/>\n"
+#        else:
+#            print "Unable to find GeoIP information for ipAddress"
+    line = file.readline()
+print "</markers>"


Property changes on: projects/dir-stats/trunk/google-mapping/routers-geo-ip-gmaps.py
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/dir-stats/trunk/google-mapping/v3-tormap.html
===================================================================
--- projects/dir-stats/trunk/google-mapping/v3-tormap.html	                        (rev 0)
+++ projects/dir-stats/trunk/google-mapping/v3-tormap.html	2008-08-17 04:33:38 UTC (rev 16574)
@@ -0,0 +1,103 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<!--
+    This file was part of apache-geo-map.
+
+    Apache-Geo-Map is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+--!>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title/>Tor routers</title>
+	<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAZppAL_7U2NkcqCqOn5Z07hRjnWo-QCEjXIWTp78ptHAhKGVlIhT-CzmPqXZT0LtlFeGkY7Rvo6chRg" type="text/javascript"></script>
+
+  </head>
+  <body onunload="GUnload()">
+
+<h1>Tor (V3 consensus only) servers worldwide</h1>
+
+
+           <div id="map" style="width: 850px; height: 600px"></div>
+
+    <noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b> 
+      However, it seems JavaScript is either disabled or not supported by your browser. 
+      To view Google Maps, enable JavaScript by changing your browser options, and then 
+      try again.
+    </noscript>
+
+
+    <script type="text/javascript">
+
+    if (GBrowserIsCompatible()) {
+      var side_bar_html = "";
+    
+      var gmarkers = [];
+      var htmls = [];
+      var i = 0;
+      
+      var gicons = [];
+      gicons["blue"] = new GIcon(G_DEFAULT_ICON, "blue.png");
+      gicons["yellow"] = new GIcon(G_DEFAULT_ICON, "yellow.png");
+
+      function createMarker(point,name,html,icontype) {
+        var marker = new GMarker(point, gicons[icontype]);
+        GEvent.addListener(marker, "click", function() {
+          marker.openInfoWindowHtml(html);
+        });
+        gmarkers[i] = marker;
+        htmls[i] = html;
+        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
+        i++;
+        return marker;
+      }
+
+
+      function myclick(i) {
+        gmarkers[i].openInfoWindowHtml(htmls[i]);
+      }
+
+
+      var map = new GMap2(document.getElementById("map"));
+      map.addControl(new GLargeMapControl());
+      map.addControl(new GMapTypeControl());
+      map.setCenter(new GLatLng(51.499633, -0.709283), 2);
+
+
+      var request = GXmlHttp.create();
+      request.open("GET", "tor-data.xml", true);
+      request.onreadystatechange = function() {
+        if (request.readyState == 4) {
+          var xmlDoc = GXml.parse(request.responseText);
+          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
+          
+          for (var i = 0; i < markers.length; i++) {
+            var lat = parseFloat(markers[i].getAttribute("lat"));
+            var lng = parseFloat(markers[i].getAttribute("lng"));
+            var point = new GLatLng(lat,lng);
+            var html = markers[i].getAttribute("html");
+            var label = markers[i].getAttribute("label");
+            var icontype = markers[i].getAttribute("icon");
+            var marker = createMarker(point,label,html,icontype);
+            map.addOverlay(marker);
+          }
+          document.getElementById("side_bar").innerHTML = side_bar_html;
+        }
+      }
+      request.send(null);
+    }
+
+    else {
+      alert("Sorry, the Google Maps API is not compatible with this browser");
+    }
+    </script>
+  </body>
+
+</html>
+
+
+
+



More information about the tor-commits mailing list