be11290b444cad0bb0bbb0258b4e264bb60343ee
[selectricity] / app / views / quickvote / list_voters.rhtml
1 <%= GMap.header %> 
2 <%require('whois/whois') %>
3 <div id="title-header">
4     <span class="header">Quickvote</span>
5       <span class="subheader">Voters</span>
6     </div>
7     
8   <div class="clear-div"></div>
9 <%= @map.to_html %>  
10 <%= @map.div(:width => 550, :height => 400) %> 
11 <br><br>
12 <table class="voterbox">
13 <tr>
14 <th>IP/Host</th>
15 <th>Organization Name</th>
16 </tr>
17 <% for voter in @election.voters %>
18   <% next unless voter.voted? %>
19   <tr>
20     <td><% begin %>
21         <% raise ArgumentError.new, "Local Server" if voter.ipaddress == "127.0.0.1" %>
22         <% raise ArgumentError.new, "XML-RPC Voter" if voter.ipaddress == "XMLRPC Request" %>
23         <% # Test for intranet addresses to avoid untimely DNS timeouts.
24            # Of course the last regex is horrible; matches a few extra IP's that aren't intranet
25           raise ArgumentError.new, "Intranet: #{voter.ipaddress}" if voter.ipaddress =~
26             /^192\.168/ or voter.ipaddress =~ /^10\./ or voter.ipaddress =~ /^169\.254/ or
27             voter.ipaddress =~ /^172\.[1-3]/
28             %>
29             <% w=nil
30             puts "WHOIS #{voter.ipaddress}"
31             if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
32             elsif Cache
33               puts "CREATE"
34               w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
35               puts "SEARCH"
36               w.search_whois
37               puts "DONE"
38               Cache.set("WHOIS:#{voter.ipaddress}", w)
39             else
40               w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
41               w.search_whois
42             end
43             
44             %>
45         <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%>
46       </td>
47       <td>
48         <%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 %>
49         <% if org =~ /IANA/ %>
50           <%= "No additional information" %>
51         <% else %>
52           <%= h(org) %>
53         <% end %>
54
55     <% rescue ArgumentError => err %>
56       <%=h err %>
57     </td>
58     <td><%=h err%>
59     <% rescue NoMethodError %>
60       DNS Unreachable
61     </td>
62     <td> DNS Unreachable
63     <% end %>
64     </td>
65   </tr>
66 <% end %>
67 </table>
68

Benjamin Mako Hill || Want to submit a patch?