Handle hostnames with upper-case letters
[webmin.git] / help / search.cgi
1 #!/usr/local/bin/perl
2 # search.cgi
3 # Search help for the selected modules and display the results
4
5 require './help-lib.pl';
6 &ReadParse();
7 &error_setup($text{'search_err'});
8
9 # Parse and validate inputs
10 $in{'terms'} || &error($text{'search_eterms'});
11 if ($in{'all'}) {
12         @mods = map { $_->[0] } &list_modules();
13         }
14 else {
15         $in{'mods'} || &error($text{'search_emods'});
16         @mods = split(/\0/, $in{'mods'});
17         }
18
19 &ui_print_header(undef, $text{'search_title'}, "", "search");
20
21 # Do the search
22 ($terms = $in{'terms'}) =~ s/\\/\\\\/g;
23 foreach $m (@mods) {
24         local %minfo = &get_module_info($m);
25         local $dir = "../$m/help";
26         local @pfx;
27         opendir(DIR, $dir);
28         while($f = readdir(DIR)) {
29                 push(@pfx, $1) if ($f =~ /^([^\.]+)\.html$/);
30                 }
31         closedir(DIR);
32         foreach $p (&unique(@pfx)) {
33                 local $file = &help_file($dir, $p);
34                 open(HELP, $file);
35                 local @st = stat($file);
36                 read(HELP, $help, $st[7]);
37                 close(HELP);
38                 if ($help =~ /<header>([^<]+)<\/header>/) {
39                         $header = $1;
40                         }
41                 else { next; }
42                 $help =~ s/<include\s+(\S+)>/inchelp($1)/ge;
43                 $help =~ s/<[^>]+>//g;
44                 if ($help =~ /(.*)(\Q$terms\E)(.*)/i) {
45                         push(@match, [ $m, $minfo{'desc'}, $p,
46                                        $header, "$1<b>$2</b>$3" ] );
47                         }
48                 }
49         }
50
51 # Display the results
52 if (@match) {
53         print "<b>",&text('search_results', "<tt>$terms</tt>"),"</b><p>\n";
54         print "<table border width=100%>\n";
55         print "<tr $tb> <td><b>$text{'search_page'}</b></td> ",
56               "<td><b>$text{'search_mod'}</b></td> ",
57               "<td><b>$text{'search_line'}</b></td> </tr>\n";
58         foreach $m (@match) {
59                 print "<tr $cb>\n";
60                 print "<td>",&hlink($m->[3], $m->[2], $m->[0]),"</td>\n";
61                 print "<td>$m->[1]</td>\n";
62                 print "<td>$m->[4]</td>\n";
63                 print "</tr>\n";
64                 }
65         print "</table><p>\n";
66         }
67 else {
68         print "<p><b>$text{'search_none'}</b> <p>\n";
69         }
70 &ui_print_footer("", $text{'index_return'});
71
72
73 # help_file(dir, prefix)
74 sub help_file
75 {
76 local $lang = "$_[0]/$_[1].$current_lang.html";
77 local $def = "$_[0]/$_[1].html";
78 return -r $lang ? $lang : $def;
79 }
80
81 # inchelp(path)
82 sub inchelp
83 {
84 local $inc;
85 local $ipath = &help_file($dir, $_[0]);
86 open(INC, $ipath) || return "<i>".&text('search_einclude', $_[0])."</i><br>\n";
87 local @st = stat(INC);
88 read(INC, $inc, $st[7]);
89 close(INC);
90 return $inc;
91 }
92
93