From 0955a7c5f7317a0be848d43392cc0f937aed9bc2 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 12 Jun 2009 22:40:07 +0000 Subject: [PATCH] Allow linker to specify modules to search --- webmin-search-lib.pl | 20 ++++++++++++++------ webmin_search.cgi | 4 +++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/webmin-search-lib.pl b/webmin-search-lib.pl index 3e9816305..9d1b21954 100644 --- a/webmin-search-lib.pl +++ b/webmin-search-lib.pl @@ -1,6 +1,6 @@ # Functions for searching the webmin docs and UI -=head2 search_webmin(phrase, [callback-function]) +=head2 search_webmin(phrase, [callback-function], [&modules]) Searches all Webmin help pages, UI text, module names and config.info files for entries matching the given phrase or word. Returns them sorted by relevance @@ -19,7 +19,7 @@ order, each as a hash ref with the following keys : =cut sub search_webmin { -my ($re, $cbfunc) = @_; +my ($re, $cbfunc, $onlymods) = @_; # Work out this Webmin's URL base my $urlhost = $ENV{'HTTP_HOST'}; @@ -31,10 +31,18 @@ my $urlbase = ($ENV{'HTTPS'} eq 'ON' ? 'https://' : 'http://').$urlhost; # Search module names and add to results list my @rv = ( ); my $pn = &get_product_name(); -my @mods = sort { $b->{'longdesc'} cmp $a->{'longdesc'} } - grep { !$_->{'clone'} } - grep { !$_->{'noui'} && !$_->{$pn.'_noui'} } - &get_available_module_infos(); +my @mods; +if ($onlymods) { + # Modules specified by caller + @mods = @$onlymods; + } +else { + # All reasonabel modules + @mods = grep { !$_->{'clone'} } + grep { !$_->{'noui'} && !$_->{$pn.'_noui'} } + &get_available_module_infos(); + } +@mods = sort { $b->{'longdesc'} cmp $a->{'longdesc'} } @mods; foreach my $m (@mods) { if ($m->{'desc'} =~ /\Q$re\E/i) { # Module description match diff --git a/webmin_search.cgi b/webmin_search.cgi index 6ae8d6173..9f0123928 100644 --- a/webmin_search.cgi +++ b/webmin_search.cgi @@ -1,6 +1,7 @@ #!/usr/local/bin/perl # Search Webmin modules and help pages and text and config.info +$trust_unknown_referers = 1; BEGIN { push(@INC, ".."); }; use WebminCore; @@ -23,7 +24,8 @@ $re =~ s/\s+$//; # Do the search print &text('wsearch_searching', "".&html_escape($re).""),"\n"; -@rv = &search_webmin($re, \&print_search_dot); +@rv = &search_webmin($re, \&print_search_dot, + $in{'mod'} ? [ split(/\0/, $in{'mod'}) ] : undef); print &text('wsearch_found', scalar(@rv)),"

\n"; # Show in table