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