]> projects.mako.cc - selectricity/commitdiff
Hack WHOIS lib to implement a 5-second timeout on DNS resolution.
authorJohn Dong <jdong@mit.edu>
Fri, 31 Aug 2007 15:43:41 +0000 (11:43 -0400)
committerJohn Dong <jdong@mit.edu>
Fri, 31 Aug 2007 15:43:41 +0000 (11:43 -0400)
app/views/quickvote/list_voters.rhtml
lib/whois/whois.rb

index 695794fc3f536d4776897b845b0460b548ba4086..be11290b444cad0bb0bbb0258b4e264bb60343ee 100644 (file)
@@ -1,5 +1,5 @@
 <%= GMap.header %> 
 <%= GMap.header %> 
-
+<%require('whois/whois') %>
 <div id="title-header">
     <span class="header">Quickvote</span>
       <span class="subheader">Voters</span>
 <div id="title-header">
     <span class="header">Quickvote</span>
       <span class="subheader">Voters</span>
             if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
             elsif Cache
               puts "CREATE"
             if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
             elsif Cache
               puts "CREATE"
-              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),false)
+              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
               puts "SEARCH"
               w.search_whois
               puts "DONE"
               Cache.set("WHOIS:#{voter.ipaddress}", w)
             else
               puts "SEARCH"
               w.search_whois
               puts "DONE"
               Cache.set("WHOIS:#{voter.ipaddress}", w)
             else
-              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),false)
+              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
               w.search_whois
             end
             
               w.search_whois
             end
             
         <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%>
       </td>
       <td>
         <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%>
       </td>
       <td>
-        <%=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 %>
 
     <% rescue ArgumentError => err %>
       <%=h err %>
index 88c735ba4f4309a0d3746646f4bc5ad731c69263..7cc6e9d1eea43efef502e6ac0d4ea406f156b440 100755 (executable)
@@ -4,6 +4,8 @@ require 'socket'
 require 'resolv'
 require 'ipaddr'
 require 'yaml'
 require 'resolv'
 require 'ipaddr'
 require 'yaml'
+require 'timeout'
+
 require File.dirname(__FILE__) + '/server/server'
 
 # Module for manage all Whois Class
 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
         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
                 else
                     @host = nil
                 end

Benjamin Mako Hill || Want to submit a patch?