diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Gemfile | 5 | ||||
-rw-r--r-- | Gemfile.lock | 6 | ||||
-rw-r--r-- | app/assets/stylesheets/application.css | 1 | ||||
-rw-r--r-- | app/assets/stylesheets/screen.css | 11 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 25 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 6 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 2 | ||||
-rw-r--r-- | app/models/bug.rb | 6 | ||||
-rw-r--r-- | app/models/cve.rb | 8 | ||||
-rw-r--r-- | app/models/cve_comment.rb | 5 | ||||
-rw-r--r-- | app/models/glsa.rb | 4 | ||||
-rw-r--r-- | app/models/revision.rb | 12 | ||||
-rw-r--r-- | app/views/layouts/application.html.erb | 34 | ||||
-rw-r--r-- | app/views/search/_cve_row.html.erb | 6 | ||||
-rw-r--r-- | app/views/search/_cves.html.erb | 13 | ||||
-rw-r--r-- | app/views/search/_glsas.html.erb | 14 | ||||
-rw-r--r-- | app/views/search/results.html.erb | 13 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | config/sphinx.yml | 9 | ||||
-rw-r--r-- | test/functional/search_controller_test.rb | 7 | ||||
-rw-r--r-- | test/unit/helpers/search_helper_test.rb | 4 |
22 files changed, 175 insertions, 20 deletions
@@ -14,3 +14,5 @@ coverage .idea .rvmrc *.tmproj +*.sphinx.conf +db/sphinx @@ -28,6 +28,7 @@ gem 'capistrano' group :development do # To use debugger gem 'ruby-debug' + gem 'require_relative' end gem "mechanize" @@ -36,10 +37,12 @@ gem "diff-lcs", :require => "diff/lcs" gem "nokogiri" gem "text-format", :require => "text/format" +gem "thinking-sphinx", "=2.0.7" + # gem "rdoc" group :test do gem "rcov" gem "ci_reporter" gem "rspec" -end
\ No newline at end of file +end diff --git a/Gemfile.lock b/Gemfile.lock index 4ea881f..7c6df90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,6 +113,7 @@ GEM rcov (0.9.9) rdoc (3.9.2) require_relative (1.0.2) + riddle (1.4.0) rspec (2.6.0) rspec-core (~> 2.6.0) rspec-expectations (~> 2.6.0) @@ -136,6 +137,9 @@ GEM rack (~> 1.0) tilt (~> 1.1, != 1.3.0) text-format (1.0.0) + thinking-sphinx (2.0.7) + activerecord (>= 3.0.3) + riddle (>= 1.3.3) thor (0.14.6) tilt (1.3.2) treetop (1.4.10) @@ -164,8 +168,10 @@ DEPENDENCIES prototype-rails rails (= 3.1.0.rc6) rcov + require_relative rspec ruby-debug sass-rails (~> 3.1.0.rc6) text-format + thinking-sphinx (= 2.0.7) uglifier diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 58fbcb5..fc3f853 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -6,4 +6,5 @@ *= require screen *= require admin *= require modalbox + *= require cve */
\ No newline at end of file diff --git a/app/assets/stylesheets/screen.css b/app/assets/stylesheets/screen.css index 77b5c7f..e9956d9 100644 --- a/app/assets/stylesheets/screen.css +++ b/app/assets/stylesheets/screen.css @@ -149,6 +149,7 @@ div#menu #search { right: 200px; font-size: 80%; margin-top: 17px; + color: white; } div#menu #search input { @@ -556,4 +557,14 @@ table.glsamaker-table td { padding-bottom: .4em; border-right: 1px dotted #4C3E61; border-bottom: 1px solid #4C3E61; +} + +/** search **/ +span.match { + color: #4C3E61; + font-weight: bold; +} + +.nowrap { + white-space: nowrap; }
\ No newline at end of file diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb new file mode 100644 index 0000000..ee5440a --- /dev/null +++ b/app/controllers/search_controller.rb @@ -0,0 +1,25 @@ +class SearchController < ApplicationController + def index + end + + def results + search = ThinkingSphinx.search params[:q], :max_matches => 1000, :per_page => 1000 + + @results = {} + search.each do |result| + klass = result.class.to_s + @results[klass] = [] unless @results.include? klass + @results[klass] << result + end + + if @results.include? 'Revision' + @results['Glsa'] = [] unless @results['Glsa'] + + @results['Revision'].each do |rev| + @results['Glsa'] << rev.glsa + end + + @results['Glsa'].uniq! + end + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 778d8f6..de8366d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,7 +1,7 @@ # ===GLSAMaker v2 -# Copyright (C) 2009-10 Alex Legler <a3li@gentoo.org> -# Copyright (C) 2006-2007 Jean-Philippe Lang -# Copyright (C) 2008 Robert Buchholz <rbug@gentoo.org> and Tobias Heinlein <keytoaster@gentoo.org> +# Copyright (C) 2009-11 Alex Legler <a3li@gentoo.org> +# Copyright (C) 2006-07 Jean-Philippe Lang +# Copyright (C) 2008 Robert Buchholz <rbu@gentoo.org> and Tobias Heinlein <keytoaster@gentoo.org> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb new file mode 100644 index 0000000..b3ce20a --- /dev/null +++ b/app/helpers/search_helper.rb @@ -0,0 +1,2 @@ +module SearchHelper +end diff --git a/app/models/bug.rb b/app/models/bug.rb index 00e2d6d..9772d2a 100644 --- a/app/models/bug.rb +++ b/app/models/bug.rb @@ -13,6 +13,12 @@ class Bug < ActiveRecord::Base belongs_to :revision + define_index do + indexes title + + has revision_id + end + def cc self.arches end diff --git a/app/models/cve.rb b/app/models/cve.rb index 9b46bab..47c3167 100644 --- a/app/models/cve.rb +++ b/app/models/cve.rb @@ -17,6 +17,14 @@ class Cve < ActiveRecord::Base has_many :cve_changes, :class_name => "CveChange", :foreign_key => "cve_id" has_many :assignments, :class_name => "CveAssignment", :foreign_key => "cve_id" + define_index do + indexes cve_id, :sortable => true + indexes state, :sortable => true + indexes summary + + has published_at, last_changed_at + end + def to_s(line_length = 78) str = "#{self.cve_id} #{"(%s):" % url}\n" str += " " + Glsamaker::help.word_wrap(self.summary, line_length-2).gsub(/\n/, "\n ") diff --git a/app/models/cve_comment.rb b/app/models/cve_comment.rb index 4c6b8c1..9ce0e31 100644 --- a/app/models/cve_comment.rb +++ b/app/models/cve_comment.rb @@ -1,4 +1,9 @@ class CveComment < ActiveRecord::Base belongs_to :cve belongs_to :user, :class_name => "User", :foreign_key => "user_id" + + define_index do + indexes comment + has user_id, cve_id + end end
\ No newline at end of file diff --git a/app/models/glsa.rb b/app/models/glsa.rb index ab1ff18..f06b0c9 100644 --- a/app/models/glsa.rb +++ b/app/models/glsa.rb @@ -20,6 +20,10 @@ class Glsa < ActiveRecord::Base has_many :revisions has_many :comments + + define_index do + indexes glsa_id, :sortable => true + end # Returns the last revision object, referring to the current state of things def last_revision diff --git a/app/models/revision.rb b/app/models/revision.rb index 3e029ba..5715b94 100644 --- a/app/models/revision.rb +++ b/app/models/revision.rb @@ -33,6 +33,18 @@ class Revision < ActiveRecord::Base end end + define_index do + indexes title + indexes synopsis + indexes description + indexes impact + indexes workaround + indexes resolution + indexes is_release + + has glsa_id, revid, release_revision + end + # Returns an Array of Integers of the bugs linked to this revision def get_linked_bugs self.bugs.map do |bug| diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 144c814..4e4cb41 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -29,25 +29,27 @@ <map name="m_logo" id="m_logo"> <area shape="rect" coords="95,0,252,42" href="#" alt="Home" /> </map> - <!--<div id="search"> TODO - <form action="/search/index/glsamaker2" method="get"> - <a href="/search/index/glsamaker2" accesskey="4">Search</a>: - <input accesskey="f" class="small" id="q" name="q" size="20" type="text" /> + <div id="search"> + <%= form_tag(search_path, :method => 'get') do -%> + <label for="q">Search:</label> + <input accesskey="f" class="small" id="q" name="q" size="20" type="text" value="<%= params[:q] %>" /> <select name="at"> - <option selected="selected">Everywhere</option> - <option disabled="disabled" style="text-align: center">————</option> - <option value="glsa">GLSAs</option> - <option value="glsa-request"> Requests</option> - <option value="glsa-draft"> Drafts</option> - <option value="glsa-sent"> Archive</option> - <option disabled="disabled" style="text-align: center">————</option> - <option disabled="disabled">Vulnerability intelligence</option> - <option value="cve"> CVEs</option> - <option value="secunia"> Secunia Advisories</option> + <option value="everywhere" selected="selected">Everywhere</option> + <!--<optgroup label="Advisories"> + <option value="glsa">All GLSAs</option> + <option value="glsa-requests">Requests</option> + <option value="glsa-drafts">Drafts</option> + <option value="glsa-archive">Archive</option> + </optgroup> + <optgroup label="Vulnerability Intelligence"> + <option value="cve">CVEs</option> + <option value="cve-assigned">Assigned CVEs</option> + <option value="cve-new">New CVEs</option> + </optgroup>--> </select> - </form> - </div>--> + <% end -%> + </div> <ul> <li><%= link_to "New…", new_glsa_path, :class => 'new' %></li> <li style="margin-right: 2em;"> </li> diff --git a/app/views/search/_cve_row.html.erb b/app/views/search/_cve_row.html.erb new file mode 100644 index 0000000..ba641cd --- /dev/null +++ b/app/views/search/_cve_row.html.erb @@ -0,0 +1,6 @@ +<tr> + <td class="nowrap"><%= link_to_function cve.colorize(:cve_id).html_safe, "cvepopup('#{cve.cve_id}')" %></td> + <td><%= cve.state %></td> + <td><%= sanitize(cve.excerpts.summary, :tags => 'span', :attributes => 'class') %></td> + <td><%= cve.cvss %></td> +</tr>
\ No newline at end of file diff --git a/app/views/search/_cves.html.erb b/app/views/search/_cves.html.erb new file mode 100644 index 0000000..e3f66ab --- /dev/null +++ b/app/views/search/_cves.html.erb @@ -0,0 +1,13 @@ +<div class="box"> + <h2>CVEs</h2> + + <table class="glsamaker-table"> + <tr align="left"> + <th>ID</th> + <th>State</th> + <th>Summary</th> + <th>CVSS Score</th> + </tr> + <%= render :partial => "cve_row", :collection => results, :as => :cve %> + </table> +</div>
\ No newline at end of file diff --git a/app/views/search/_glsas.html.erb b/app/views/search/_glsas.html.erb new file mode 100644 index 0000000..cfa4c59 --- /dev/null +++ b/app/views/search/_glsas.html.erb @@ -0,0 +1,14 @@ +<div class="box"> + <h2>GLSAs</h2> + + <table class="glsamaker-table"> + <tr align="left"> + <th>ID</th> + <th>State</th> + <th>Title</th> + <th>Last changed at/by</th> + <% if current_user.is_el_jefe? %><th>Admin</th><% end %> + </tr> + <%= render :partial => "/glsa/glsa_row", :collection => results, :as => :glsa, :locals => { :view => :archive } %> + </table> +</div>
\ No newline at end of file diff --git a/app/views/search/results.html.erb b/app/views/search/results.html.erb new file mode 100644 index 0000000..c3aa24c --- /dev/null +++ b/app/views/search/results.html.erb @@ -0,0 +1,13 @@ +<h1>Search results for "<%= params[:q] %>"</h1> + +<%- if @results.include? 'Glsa' -%> +<%= render :partial => "glsas", :locals => {:results => @results['Glsa']} %> +<%- end -%> + +<%- if @results.include? 'Cve' -%> +<%= render :partial => "cves", :locals => {:results => @results['Cve']} %> +<%- end -%> + +<%- if @results.empty? -%> +<%= image_tag 'icons/error.png' %> No results found. :( +<%- end -%>
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 00807da..6c1f882 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,8 @@ Glsamaker::Application.routes.draw do match 'cve/list.:format' => 'cve#list', :as => :cve + match 'search/results' => 'search#results', :as => :search + match 'admin' => 'admin/index#index' resources :glsas, :controller => 'glsa' do diff --git a/config/sphinx.yml b/config/sphinx.yml new file mode 100644 index 0000000..d866a5a --- /dev/null +++ b/config/sphinx.yml @@ -0,0 +1,9 @@ +development: + enable_star: true + min_infix_len: 3 +test: + enable_star: true + min_infix_len: 3 +production: + enable_star: true + min_infix_len: 3
\ No newline at end of file diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb new file mode 100644 index 0000000..bfbf22d --- /dev/null +++ b/test/functional/search_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SearchControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/search_helper_test.rb b/test/unit/helpers/search_helper_test.rb new file mode 100644 index 0000000..3034163 --- /dev/null +++ b/test/unit/helpers/search_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class SearchHelperTest < ActionView::TestCase +end |