From: John Dong Date: Fri, 31 Aug 2007 15:44:38 +0000 (-0400) Subject: Merge jdong X-Git-Url: https://projects.mako.cc/source/selectricity-live/commitdiff_plain/8fed8cec71cd2da12b1e25be9cdca90087387e55?hp=92ef7d04cd30067674aac41195f69710cca01922 Merge jdong --- diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index d8d3d59..b9c790f 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -168,7 +168,14 @@ class QuickvoteController < ApplicationController @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 diff --git a/app/views/quickvote/list_voters.rhtml b/app/views/quickvote/list_voters.rhtml index 1672499..be11290 100644 --- a/app/views/quickvote/list_voters.rhtml +++ b/app/views/quickvote/list_voters.rhtml @@ -1,5 +1,5 @@ <%= GMap.header %> - +<%require('whois/whois') %>
Quickvote Voters @@ -27,10 +27,14 @@ voter.ipaddress =~ /^172\.[1-3]/ %> <% w=nil + puts "WHOIS #{voter.ipaddress}" if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}") elsif Cache + puts "CREATE" w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true) + puts "SEARCH" w.search_whois + puts "DONE" Cache.set("WHOIS:#{voter.ipaddress}", w) else w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true) @@ -41,7 +45,12 @@ <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%> - <%=h (w.all.grep(/^(OrgName|org-name)/)[0] or "").sub(/^(OrgName|org-name)\:/,'').strip -%> - <%= (w.all.grep(/^(NetName|netname)/)[0] or "").sub(/^(NetName|netname)\:/,'').strip %> + <%org=(w.all.grep(/^(OrgName|org-name)/)[0] or "").sub(/^(OrgName|org-name)\:/,'').strip+" - "+ (w.all.grep(/^(NetName|netname)/)[0] or "").sub(/^(NetName|netname)\:/,'').strip %> + <% if org =~ /IANA/ %> + <%= "No additional information" %> + <% else %> + <%= h(org) %> + <% end %> <% rescue ArgumentError => err %> <%=h err %> diff --git a/lib/whois/whois.rb b/lib/whois/whois.rb index 9b07aef..7cc6e9d 100755 --- a/lib/whois/whois.rb +++ b/lib/whois/whois.rb @@ -4,6 +4,8 @@ require 'socket' require 'resolv' require 'ipaddr' require 'yaml' +require 'timeout' + require File.dirname(__FILE__) + '/server/server' # Module for manage all Whois Class @@ -92,7 +94,11 @@ module Whois def search_host begin if @host_search - @host = Resolv.getname self.ip.to_s + begin + timeout(5) {@host = Resolv.getname self.ip.to_s} + rescue Timeout::Error + @host=nil + end else @host = nil end @@ -121,9 +127,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] - 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 Server::Ripe.new end end @@ -132,7 +139,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 - raise WhoisException.new("no server found for this IPv6 : #{self.ip}") + return Server::Ripe.new else return server end @@ -143,7 +150,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 - raise WhoisException.new("no server found for this IPv4 : #{self.ip}") + return Server::Ripe.new else return server end