forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebmin_search.cgi
executable file
·103 lines (93 loc) · 2.4 KB
/
webmin_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
92
93
94
95
96
97
98
99
100
101
102
#!/usr/local/bin/perl
# Search Webmin modules and help pages and text and config.info
$trust_unknown_referers = 1;
BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
do 'webmin-search-lib.pl';
&ReadParse();
$prod = &get_product_name();
$ucprod = ucfirst($prod);
&ui_print_unbuffered_header(undef,
&html_escape($in{'title'}) || &text('wsearch_title', $ucprod), "", undef, 0, 1);
# Validate search text
$re = $in{'search'};
if ($re !~ /\S/) {
&error($text{'wsearch_esearch'});
}
$re =~ s/^\s+//;
$re =~ s/\s+$//;
# Find modules to search
$mods = undef;
if ($in{'mod'}) {
$mods = [ ];
my %infos = map { $_->{'dir'}, $_ } &get_all_module_infos();
foreach my $mn (split(/\0/, $in{'mod'})) {
my $minfo = $infos{$mn};
push(@$mods, $minfo) if ($minfo);
}
}
# Do the search
print &text('wsearch_searching', "<i>".&html_escape($re)."</i>"),"\n";
@rv = &search_webmin($re, \&print_search_dot, $mods);
print &text('wsearch_found', scalar(@rv)),"<p>\n";
# Show in table
if (@rv) {
print &ui_columns_start(
[ $text{'wsearch_htext'}, $text{'wsearch_htype'},
$text{'wsearch_hmod'}, $text{'wsearch_hcgis'} ], 100);
foreach my $r (@rv) {
$hi = &highlight_text($r->{'text'});
if ($r->{'link'}) {
$hi = "<a href='$r->{'link'}'>$hi</a>";
}
@links = ( );
foreach my $c (@{$r->{'cgis'}}) {
($cmod, $cpage) = split(/\//, $c);
($cpage, $cargs) = split(/\?/, $cpage);
$ctitle = &cgi_page_title($cmod, $cpage) || $cpage;
if ($r->{'mod'}->{'installed'}) {
$cargs ||= &cgi_page_args($cmod, $cpage);
}
else {
# For modules that aren't installed, linking
# to a CGI is likely useless
$cargs ||= "none";
}
if ($cargs eq "none") {
push(@links, $ctitle);
}
else {
$cargs = "?".$cargs if ($cargs ne '' &&
$cargs !~ /^(\/|%2F)/);
push(@links,
"<a href='$cmod/$cpage$cargs'>$ctitle</a>");
}
}
if (@links > 2) {
@links = ( @links[0..1], "..." );
}
print &ui_columns_row([
$hi,
$text{'wsearch_type_'.$r->{'type'}},
"<a href='$r->{'mod'}->{'dir'}/'>$r->{'mod'}->{'desc'}</a>",
&ui_links_row(\@links),
]);
}
print &ui_columns_end();
}
else {
print "<b>",&text('wsearch_enone',
"<tt>".&html_escape($re)."</tt>"),"</b><p>\n";
}
&ui_print_footer();
# print_search_dot()
# Print one dot per second
sub print_search_dot
{
local $now = time();
if ($now > $last_print_search_dot) {
print ". ";
$last_print_search_dot = $now;
}
}