Permalink
Browse files

postscreen_stats: Use javascript local variables

Switched to array-variables for the javascript parts as
one would otherwise hit "too many local variables" errors
when viewing the generated Google-map.

patch from Dan Larsson - dl[at]tyfon.net
  • Loading branch information...
1 parent adf2375 commit 32514d65e7d8df7f422b2b33f04417b66d966dde Julien Vehent committed May 26, 2012
Showing with 13 additions and 9 deletions.
  1. +13 −9 postscreen_stats.py
View
@@ -504,6 +504,11 @@ def action_filter(self,filter):
<title>Postscreen GeoMap of Blocked IPs</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
+ var ip = new Array();
+ var marker_ip = new Array();
+ var desc_ip = new Array();
+ var info_window = new Array();
+
window.onload = function() {
var center = new google.maps.LatLng(0,0);
var mapOptions = {
@@ -513,27 +518,26 @@ def action_filter(self,filter):
};
var myMap = new google.maps.Map(
document.getElementById('map'),mapOptions
- );
+ );
'''
fd.write(mapcode)
incr = 0
for client in blocked_clients:
if type(ip_list[client].geoloc) is not NoneType \
and ip_list[client].geoloc.has_key('latitude') \
- and ip_list[client].geoloc.has_key('longitude') \
- and (ip_list[client].logs['CONNECT'] >= MAP_MIN_CONN):
+ and ip_list[client].geoloc.has_key('longitude'):
mapcode = '''
ip[''' + str(incr) + '''] = new google.maps.LatLng(''' \
+ str(ip_list[client].geoloc['latitude']) + "," \
+ str(ip_list[client].geoloc['longitude']) + ''');
- var marker_ip'''+str(incr)+''' = new google.maps.Marker({
- position: ip''' + str(incr) + ''',
+ marker_ip[''' + str(incr) + '''] = new google.maps.Marker({
+ position: ip[''' + str(incr) + '''],
map: myMap,
title: "''' + str(client) + '''"
});
- var desc_ip''' + str(incr) + ''' = '<div id="content">' +
+ desc_ip[''' + str(incr) + '''] = '<div id="content">' +
'<div id="siteNotice"></div><h2 id="firstHeading" class="firstHeading">' +
' ''' + str(client) + '''</h2><div id="bodyContent">' +
' '''
@@ -578,8 +582,8 @@ def action_filter(self,filter):
content: desc_ip[''' + str(incr) + '''],
maxWidth: 500
});
- google.maps.event.addListener(marker_ip'''+str(incr)+''', 'click', function() {
- infowindow'''+str(incr)+'''.open(myMap,marker_ip'''+str(incr)+''');
+ google.maps.event.addListener(marker_ip[''' + str(incr) + '''], 'click', function() {
+ info_window[''' + str(incr) + '''].open(myMap,marker_ip[''' + str(incr) + ''']);
});
'''
incr += 1
@@ -600,7 +604,7 @@ def action_filter(self,filter):
<h1>Postscreen Map of Blocked IPs</h1>
<div id="map">
</div>
- <p>mapping ''' + str(incr) + ''' blocked IPs</p>
+ <p>mapping ''' + str(len(blocked_clients)) + ''' blocked IPs</p>
<p>generated using <a href="https://github.com/jvehent/Postscreen-Stats">Postscreen-Stats</a> by <a href="http://1nw.eu/!j">Julien Vehent</a></p>
</body>
</html>

0 comments on commit 32514d6

Please sign in to comment.