]> projects.mako.cc - selectricity-live/commitdiff
Fix WHOIS library not to puke on strange IP addresses
authorJohn Dong <jdong@mit.edu>
Fri, 31 Aug 2007 15:26:15 +0000 (11:26 -0400)
committerJohn Dong <jdong@mit.edu>
Fri, 31 Aug 2007 15:26:15 +0000 (11:26 -0400)
app/controllers/quickvote_controller.rb
app/views/quickvote/list_voters.rhtml
lib/whois/whois.rb

index d8d3d59e59139b9499c70c514cc77b8442203359..b9c790f40f872fa99048f10aec38cc76abc348a1 100644 (file)
@@ -168,7 +168,14 @@ class QuickvoteController < ApplicationController
     @election=QuickVote.ident_to_quickvote(params[:id])
     @election.voters.each do |voter|
       next unless voter.ipaddress
     @election=QuickVote.ident_to_quickvote(params[:id])
     @election.voters.each do |voter|
       next unless voter.ipaddress
-      location = GeoKit::Geocoders::IpGeocoder.geocode(voter.ipaddress)
+      location=nil
+      if Cache and location=Cache.get("GEO:#{voter.ipaddress}")
+      elsif Cache
+        location = GeoKit::Geocoders::IpGeocoder.geocode(voter.ipaddress)
+        Cache.set "GEO:#{voter.ipaddress}", location
+      else
+        location = GeoKit::Geocoders::IpGeocoder.geocode(voter.ipaddress)
+      end
       next unless location.lng and location.lat
 
       unless center
       next unless location.lng and location.lat
 
       unless center
index 1672499f0a3b38af7fe185ee5e750e4a5b703667..695794fc3f536d4776897b845b0460b548ba4086 100644 (file)
             voter.ipaddress =~ /^172\.[1-3]/
             %>
             <% w=nil
             voter.ipaddress =~ /^172\.[1-3]/
             %>
             <% w=nil
+            puts "WHOIS #{voter.ipaddress}"
             if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
             elsif Cache
             if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
             elsif Cache
-              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
+              puts "CREATE"
+              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),false)
+              puts "SEARCH"
               w.search_whois
               w.search_whois
+              puts "DONE"
               Cache.set("WHOIS:#{voter.ipaddress}", w)
             else
               Cache.set("WHOIS:#{voter.ipaddress}", w)
             else
-              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
+              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),false)
               w.search_whois
             end
             
               w.search_whois
             end
             
index 9b07aef9e5108a37d46b39e634fc29592a053d8d..88c735ba4f4309a0d3746646f4bc5ad731c69263 100755 (executable)
@@ -121,9 +121,10 @@ module Whois
           arr_tmp = ip_hash.sort{|b,c| c[0][/\/(.+)/, 1].to_i <=> b[0][/\/(.+)/, 1].to_i}
           arr_tmp.each do |l|
             ip_range = IPAddr.new l[0]
           arr_tmp = ip_hash.sort{|b,c| c[0][/\/(.+)/, 1].to_i <=> b[0][/\/(.+)/, 1].to_i}
           arr_tmp.each do |l|
             ip_range = IPAddr.new l[0]
-            if ip_range.include? self.ip
+            if ip_range.include? self.ip and l[1].length > 0
               return Object.instance_eval("Server::#{l[1]}.new")
             end
               return Object.instance_eval("Server::#{l[1]}.new")
             end
+            return Server::Ripe.new
           end
         end
 
           end
         end
 
@@ -132,7 +133,7 @@ module Whois
           ipv6_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv6.yaml')
           server = server_with_hash(ipv6_list)
           unless server.kind_of? Server::Server
           ipv6_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv6.yaml')
           server = server_with_hash(ipv6_list)
           unless server.kind_of? Server::Server
-            raise WhoisException.new("no server found for this IPv6 : #{self.ip}")
+            return Server::Ripe.new
           else
             return server
           end
           else
             return server
           end
@@ -143,7 +144,7 @@ module Whois
           ipv4_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv4.yaml')
           server = server_with_hash(ipv4_list)
           unless server.kind_of? Server::Server
           ipv4_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv4.yaml')
           server = server_with_hash(ipv4_list)
           unless server.kind_of? Server::Server
-            raise WhoisException.new("no server found for this IPv4 : #{self.ip}")
+            return Server::Ripe.new
           else
             return server
           end
           else
             return server
           end

Benjamin Mako Hill || Want to submit a patch?