From: John Dong Date: Fri, 31 Aug 2007 14:31:12 +0000 (-0400) Subject: My first gigantic-blob commit.... X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/bf220bde847fd30e9bf0d00dd7c9aff31265c810 My first gigantic-blob commit.... * Refactor voter list to a separate page * Rename mapvoters to list_voters * Clean up div tags * Fixed gmap api key syntax to not error out in production * TODO: Generate a real api key for selectricity.org * Fixed performance issue with when IANA private addresses timeout DNS request. --- diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index da2903d..d8d3d59 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -161,14 +161,13 @@ 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) next unless location.lng and location.lat diff --git a/app/views/quickvote/list_voters.rhtml b/app/views/quickvote/list_voters.rhtml new file mode 100644 index 0000000..795ab45 --- /dev/null +++ b/app/views/quickvote/list_voters.rhtml @@ -0,0 +1,49 @@ +<%= GMap.header %> + +
+ Quickvote + Voters +
+ +
+<%= @map.to_html %> +<%= @map.div(:width => 550, :height => 400) %> +

+ + + + + +<% for voter in @election.voters %> + <% next unless voter.voted? %> + + + + + + +<% end %> +
IP/HostOrganization Name
<% 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= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)%> + <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%> + + <%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 %> + <%=h err%> + <% rescue NoMethodError %> + DNS Unreachable + DNS Unreachable + <% end %> +
+ diff --git a/app/views/quickvote/mapvoters.rhtml b/app/views/quickvote/mapvoters.rhtml deleted file mode 100644 index 8f94cd0..0000000 --- a/app/views/quickvote/mapvoters.rhtml +++ /dev/null @@ -1,3 +0,0 @@ -<%= GMap.header %> -<%= @map.to_html %> -<%= @map.div(:width => 800, :height => 400) %> diff --git a/app/views/quickvote/results.rhtml b/app/views/quickvote/results.rhtml index f4f6f2d..52810fe 100644 --- a/app/views/quickvote/results.rhtml +++ b/app/views/quickvote/results.rhtml @@ -46,41 +46,7 @@ -

<%= link_to "[Stalk Voters]", :controller => "quickvote", :action => "mapvoters", :id => @election.id %>

- - - - - - -<% for voter in @election.voters %> - <% next unless voter.voted? %> - - - - - - - -<% end %> -
IP/HostOriginVote
<% 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)%> - - <%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 %> - <%=h err%> - <% rescue NoMethodError %> - DNS Unreachable - DNS Unreachable - <% end %> - <%= voter.vote.votestring %>
- +

<%= link_to "[View All Voters]", :controller => "quickvote", :action => "list_voters", :id => @election.id %>