]> projects.mako.cc - selectricity/commitdiff
merged in changes from devel
author<mako@atdot.cc> <>
Fri, 31 Aug 2007 15:13:42 +0000 (11:13 -0400)
committer<mako@atdot.cc> <>
Fri, 31 Aug 2007 15:13:42 +0000 (11:13 -0400)
app/controllers/quickvote_controller.rb
app/views/layouts/frontpage.rhtml
app/views/quickvote/list_voters.rhtml [new file with mode: 0644]
app/views/quickvote/mapvoters.rhtml [deleted file]
app/views/quickvote/results.rhtml
config/gmaps_api_key.yml
lib/whois/whois.rb

index da2903d1a01fa3fecf1f5d0a665c49801f5ff538..b9c790f40f872fa99048f10aec38cc76abc348a1 100644 (file)
@@ -161,15 +161,21 @@ class QuickvoteController < ApplicationController
     redirect_to quickvote_url( :ident => params[:ident] )
   end
                
-  def mapvoters
+  def list_voters
     @map = GMap.new("map_div_id") 
     @map.control_init(:large_map => true, :map_type => true) 
     center = nil
-
-    QuickVote.ident_to_quickvote(params[:id]).voters.each do |voter|
+    @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
index 6531dc47bd9df4819177645ee3ac750d8f4ecb42..de173c280e7560b8229113d4500ac9a89ff87a2d 100644 (file)
 
     <div id="header">
       <div id="top-bar">
-        <a href="/account/login">login</a>
-          &nbsp;&nbsp;&nbsp;<a href="/account/signup">sign up</a>
-          &nbsp;&nbsp;&nbsp;<a href="/site/about">help/about</a>
+       <% if session[:user]%>
+       <%= link_to User.find(session[:user]).login.capitalize,
+                  :controller => "account",
+                  :action => "summary", :id => session[:user][:id] %>
+       &nbsp;&nbsp;<%= link_to( 'Log out', :controller => 'account', 
+                       :action => 'logout' )%>
+       <% else %>
+      <%= link_to("login", :controller => "account", :action => "login")
+      %>
+      &nbsp;&nbsp;<%= link_to("sign up", :controller => "account", 
+                                :action => "signup")%>
+    <% end -%>
+      &nbsp;&nbsp;<%= link_to ("help/about", :controller => "site", 
+                               :action => 'about')%>
       </div>
          <a href="index.html"><h1>selectricity: voting machinery for the masses</h1></a>
     </div>
diff --git a/app/views/quickvote/list_voters.rhtml b/app/views/quickvote/list_voters.rhtml
new file mode 100644 (file)
index 0000000..ea276d7
--- /dev/null
@@ -0,0 +1,64 @@
+<%= GMap.header %> 
+<%require('whois/whois') %>
+<div id="title-header">
+    <span class="header">Quickvote</span>
+      <span class="subheader">Voters</span>
+    </div>
+    
+  <div class="clear-div"></div>
+<%= @map.to_html %>  
+<%= @map.div(:width => 550, :height => 400) %> 
+<br><br>
+<table class="voterbox">
+<tr>
+<th>IP/Host</th>
+<th>Organization Name</th>
+</tr>
+<% for voter in @election.voters %>
+  <% next unless voter.voted? %>
+  <tr>
+    <td><% begin %>
+        <% raise ArgumentError.new, "Local Server" if voter.ipaddress == "127.0.0.1" %>
+        <% raise ArgumentError.new, "XML-RPC Voter" if voter.ipaddress == "XMLRPC Request" %>
+        <% # Test for intranet addresses to avoid untimely DNS timeouts.
+           # Of course the last regex is horrible; matches a few extra IP's that aren't intranet
+          raise ArgumentError.new, "Intranet: #{voter.ipaddress}" if voter.ipaddress =~
+            /^192\.168/ or voter.ipaddress =~ /^10\./ or voter.ipaddress =~ /^169\.254/ or
+            voter.ipaddress =~ /^172\.[1-3]/
+            %>
+            <% w=nil
+            if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
+            elsif Cache
+              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
+              w.search_whois
+              Cache.set("WHOIS:#{voter.ipaddress}", w)
+            else
+              w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
+              w.search_whois
+            end
+            
+            %>
+        <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%>
+      </td>
+      <td>
+        <%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 %>
+    </td>
+    <td><%=h err%>
+    <% rescue NoMethodError %>
+      DNS Unreachable
+    </td>
+    <td> DNS Unreachable
+    <% end %>
+    </td>
+  </tr>
+<% end %>
+</table>
+
diff --git a/app/views/quickvote/mapvoters.rhtml b/app/views/quickvote/mapvoters.rhtml
deleted file mode 100644 (file)
index 8f94cd0..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= GMap.header %>
-<%= @map.to_html %>  
-<%= @map.div(:width => 800, :height => 400) %>  
index f4f6f2d812aa93e98ad46c453d728a7c9900a79d..52810fe543d228a1b43391b82ddce41feffeab2f 100644 (file)
   <span class="subheader"></span>
 </div>
 
-<p><%= link_to "[Stalk Voters]", :controller => "quickvote", :action => "mapvoters", :id => @election.id %></p>
-<table class="voterbox">
-<tr>
-<th>IP/Host</th>
-<th>Origin</th>
-<th>Vote</th>
-</tr>
-<% for voter in @election.voters %>
-  <% next unless voter.voted? %>
-  <tr>
-    <td><% begin %>
-        <% raise ArgumentError.new, "Local Server" if voter.ipaddress == "127.0.0.1" %>
-        <% raise ArgumentError.new, "XML-RPC Voter" if voter.ipaddress == "XMLRPC Request" %>
-        <% w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)%>
-        <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%>
-      </td>
-      <td>
-        <%w.search_whois%>
-        <%=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 %>
-    
-    <% rescue ArgumentError => err %>
-      <%=h err %>
-    </td>
-    <td><%=h err%>
-    <% rescue NoMethodError %>
-      DNS Unreachable
-    </td>
-    <td> DNS Unreachable
-    <% end %>
-    </td>
-  <td><%= voter.vote.votestring %></td>
-  </tr>
-<% end %>
-</table>
-
+<p><%= link_to "[View All Voters]", :controller => "quickvote", :action => "list_voters", :id => @election.id %></p>
 <br />
 
 <!--
index b1641f55acd6523f8a91f8a542eb60308c3c2b1a..b0c65fb0eb70554e97bc053b99e5d7049a16686f 100644 (file)
@@ -9,5 +9,4 @@ test:
  ABQIAAAAzMUFFnT9uH0xq39J0Y4kbhTJQa0g3IQ9GZqIMmInSLzwtGDKaBR6j135zrztfTGVOm2QlWnkaidDIQ\r
 \r
 production:\r
- thepochisuperstarmegashow.com: ABQIAAAAzMUFFnT9uH0Sfg76Y4kbhTJQa0g3IQ9GZqIMmInSLzwtGDmlRT6e90j135zat56yhJKQlWnkaidDIQ\r
- example.com: ABQIAAAAzMUFFnT9uH0Sfg98Y4kbhGFJQa0g3IQ9GZqIMmInSLrthJKGDmlRT98f4j135zat56yjRKQlWnkmod3TB\r
+ ABQIAAAA479zRK1hoNqMcKLTMuBcTRQ0mFvgRda1vOZQqJO6gQItognzGRQueA871M_O5_Q9Pd9xs4Ah4SNYTg\r
index 9b07aef9e5108a37d46b39e634fc29592a053d8d..7cc6e9d1eea43efef502e6ac0d4ea406f156b440 100755 (executable)
@@ -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

Benjamin Mako Hill || Want to submit a patch?