Changeset 1722

Show
Ignore:
Timestamp:
07/31/08 14:46:18 (4 months ago)
Author:
dbryson
Message:

more addition and fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • community_hive/trunk/community_hive_web/app/controllers/urls_controller.rb

    r1720 r1722  
    99      redirect_to :action => 'index' 
    1010    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) 
    1315    end 
    1416  end 
    15  
     17   
     18  # Show the details of a Url 
    1619  def show 
    1720    @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) 
    1923  end 
    2024end 
  • community_hive/trunk/community_hive_web/app/models/history_url.rb

    r1719 r1722  
    11require 'uri' 
    22class HistoryUrl < ActiveRecord::Base 
    3   # Is this connection needed? Will we show *who* reported this? 
    4   belongs_to :user 
    53   
    64  # Shorten URLs for displaying on website 
     5  # returns only the domain 
    76  def host 
    87    u = URI.parse(self.url) 
    98    u.host 
    109  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 
    1527  end 
    1628   
     29    
    1730end 
  • community_hive/trunk/community_hive_web/app/views/urls/index.html.erb

    r1719 r1722  
    11<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  
    11<h2>Search Urls</h2> 
    22<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' %> 
    74<br/> 
    85<table cellpadding="10px" style="border: none;"> 
    96 <tbody> 
    107  <tr> 
    11    <td><%= image_tag 'suspicious.png'%> suspicious</td> 
     8   <td><%= image_tag 'suspicious.png' %> suspicious</td> 
    129   <td><%= image_tag 'ok.png'%> ok</td> 
    1310   <td><%= image_tag 'unknown.png'%> unknown</td> 
  • community_hive/trunk/community_hive_web/app/views/urls/show.html.erb

    r1720 r1722  
    11<h2>Details on the Url</h2> 
    22<br/> 
    3 <table cellpadding="5px"
     3<table cellpadding="5px" style="background: #eee;"
    44  <tbody> 
    55    <tr> 
    6       <td>Overall Status:</td> 
     6      <td>Latest Status:</td> 
    77      <td><%= status_image(@u.status) %></td> 
    88    </tr> 
     
    1212    </tr> 
    1313     <tr> 
    14       <td>Number in DB:</td> 
    15       <td><%= @count %></td> 
     14      <td>Number of times reported :</td> 
     15      <td><%= @count %></td> 
    1616    </tr> 
    1717    <tr> 
     
    2121   </tbody> 
    2222</table> 
     23<% if @bad_past %> 
     24<p style="color: red;">This URL has been found to contain malware in the past</p> 
     25<% end %> 
    2326<br/> 
    2427Complete Url: