Changeset 1722
- Timestamp:
- 07/31/08 14:46:18 (4 months ago)
- Files:
-
- community_hive/trunk/community_hive_web/app/controllers/statistics_controller.rb (added)
- community_hive/trunk/community_hive_web/app/controllers/urls_controller.rb (modified) (1 diff)
- community_hive/trunk/community_hive_web/app/helpers/statistics_helper.rb (added)
- community_hive/trunk/community_hive_web/app/models/history_url.rb (modified) (1 diff)
- community_hive/trunk/community_hive_web/app/views/urls/_search_form.html.erb (added)
- community_hive/trunk/community_hive_web/app/views/urls/index.html.erb (modified) (1 diff)
- community_hive/trunk/community_hive_web/app/views/urls/search.html.erb (modified) (1 diff)
- community_hive/trunk/community_hive_web/app/views/urls/show.html.erb (modified) (3 diffs)
- community_hive/trunk/community_hive_web/test/functional/statistics_controller_test.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
community_hive/trunk/community_hive_web/app/controllers/urls_controller.rb
r1720 r1722 9 9 redirect_to :action => 'index' 10 10 else 11 @list = HistoryUrl.paginate(:conditions => ["url like ?","%#{@q}%"],:page => params[:page], :per_page => 10) 12 # @list = HistoryUrl.search(@q) 11 @list = HistoryUrl.paginate(:conditions => ["url like ?","http://#{@q}%"], 12 :group => 'url', 13 :order => 'time_at DESC', 14 :page => params[:page], :per_page => 10) 13 15 end 14 16 end 15 17 18 # Show the details of a Url 16 19 def show 17 20 @u = HistoryUrl.find(params[:id]) 18 @count = HistoryUrl.count(:conditions => ["url = ?",@u.url]) 21 @count = HistoryUrl.count(:conditions => ["url = ?", @u.url]) 22 @bad_past = HistoryUrl.had_malware_in_the_past?(@u,@count) 19 23 end 20 24 end community_hive/trunk/community_hive_web/app/models/history_url.rb
r1719 r1722 1 1 require 'uri' 2 2 class HistoryUrl < ActiveRecord::Base 3 # Is this connection needed? Will we show *who* reported this?4 belongs_to :user5 3 6 4 # Shorten URLs for displaying on website 5 # returns only the domain 7 6 def host 8 7 u = URI.parse(self.url) 9 8 u.host 10 9 end 11 12 # Like search 13 def self.search(value) 14 find(:all, :conditions => ["url like ?","%#{value}%"]) 10 11 # Has the given URL had any malware in the past? 12 # We only care to check the history if the current Url 13 # is reporting "OK". So, only do the additional query IF: 14 # 1. the current object IS NOT suspicious AND 15 # 2. there is more than one of the same URL in the database 16 # returns true or false 17 def self.had_malware_in_the_past?(url_obj,cnt) 18 result = false 19 unless url_obj.status == 'suspicious' 20 if cnt > 1 21 logger.info("DID THE HISTORY CHECK") 22 a = HistoryUrl.find(:all,:conditions => ["url = ? and status = ?",url_obj.url,"suspicious"]) 23 result = a.size > 0 24 end 25 end 26 result 15 27 end 16 28 29 17 30 end community_hive/trunk/community_hive_web/app/views/urls/index.html.erb
r1719 r1722 1 1 <h2>Search for a Url</h2> 2 <p>Check our catalog of Urls we've already processed.</p> 3 <% form_tag :action => 'search' do %> 4 <%= text_field_tag 'q', '', :size => '50' %> 5 <%= submit_tag 'Search' %> 6 <% end %> 2 <p>Check our catalog for a Urls</p> 3 <%= render :partial => 'search_form' %> 4 community_hive/trunk/community_hive_web/app/views/urls/search.html.erb
r1720 r1722 1 1 <h2>Search Urls</h2> 2 2 <br/> 3 <% form_tag :action => 'search' do %> 4 <%= text_field_tag 'q', @q, :size => '50' %> 5 <%= submit_tag 'Search' %> 6 <% end %> 3 <%= render :partial => 'search_form' %> 7 4 <br/> 8 5 <table cellpadding="10px" style="border: none;"> 9 6 <tbody> 10 7 <tr> 11 <td><%= image_tag 'suspicious.png' %> suspicious</td>8 <td><%= image_tag 'suspicious.png' %> suspicious</td> 12 9 <td><%= image_tag 'ok.png'%> ok</td> 13 10 <td><%= image_tag 'unknown.png'%> unknown</td> community_hive/trunk/community_hive_web/app/views/urls/show.html.erb
r1720 r1722 1 1 <h2>Details on the Url</h2> 2 2 <br/> 3 <table cellpadding="5px" >3 <table cellpadding="5px" style="background: #eee;"> 4 4 <tbody> 5 5 <tr> 6 <td> OverallStatus:</td>6 <td>Latest Status:</td> 7 7 <td><%= status_image(@u.status) %></td> 8 8 </tr> … … 12 12 </tr> 13 13 <tr> 14 <td>Number in DB:</td>15 <td><%= @count %></td>14 <td>Number of times reported :</td> 15 <td><%= @count %></td> 16 16 </tr> 17 17 <tr> … … 21 21 </tbody> 22 22 </table> 23 <% if @bad_past %> 24 <p style="color: red;">This URL has been found to contain malware in the past</p> 25 <% end %> 23 26 <br/> 24 27 Complete Url:
