Handle hostnames with upper-case letters
[webmin.git] / webmin_search.cgi
1 #!/usr/local/bin/perl
2 # Search Webmin modules and help pages and text and config.info
3
4 $trust_unknown_referers = 1;
5 BEGIN { push(@INC, ".."); };
6 use WebminCore;
7
8 &init_config();
9 do 'webmin-search-lib.pl';
10 &ReadParse();
11
12 $prod = &get_product_name();
13 $ucprod = ucfirst($prod);
14 &ui_print_unbuffered_header(undef,
15         $in{'title'} || &text('wsearch_title', $ucprod), "", undef, 0, 1);
16
17 # Validate search text
18 $re = $in{'search'};
19 if ($re !~ /\S/) {
20         &error($text{'wsearch_esearch'});
21         }
22 $re =~ s/^\s+//;
23 $re =~ s/\s+$//;
24
25 # Find modules to search
26 $mods = undef;
27 if ($in{'mod'}) {
28         $mods = [ ];
29         my %infos = map { $_->{'dir'}, $_ } &get_all_module_infos();
30         foreach my $mn (split(/\0/, $in{'mod'})) {
31                 my $minfo = $infos{$mn};
32                 push(@$mods, $minfo) if ($minfo);
33                 }
34         }
35
36 # Do the search
37 print &text('wsearch_searching', "<i>".&html_escape($re)."</i>"),"\n";
38 @rv = &search_webmin($re, \&print_search_dot, $mods);
39 print &text('wsearch_found', scalar(@rv)),"<p>\n";
40
41 # Show in table
42 if (@rv) {
43         print &ui_columns_start(
44                 [ $text{'wsearch_htext'}, $text{'wsearch_htype'},
45                   $text{'wsearch_hmod'}, $text{'wsearch_hcgis'} ], 100);
46         foreach my $r (@rv) {
47                 $hi = &highlight_text($r->{'text'});
48                 if ($r->{'link'}) {
49                         $hi = "<a href='$r->{'link'}'>$hi</a>";
50                         }
51                 @links = ( );
52                 foreach my $c (@{$r->{'cgis'}}) {
53                         ($cmod, $cpage) = split(/\//, $c);
54                         ($cpage, $cargs) = split(/\?/, $cpage);
55                         $ctitle = &cgi_page_title($cmod, $cpage) || $cpage;
56                         if ($r->{'mod'}->{'installed'}) {
57                                 $cargs ||= &cgi_page_args($cmod, $cpage);
58                                 }
59                         else {
60                                 # For modules that aren't installed, linking
61                                 # to a CGI is likely useless
62                                 $cargs ||= "none";
63                                 }
64                         if ($cargs eq "none") {
65                                 push(@links, $ctitle);
66                                 }
67                         else {
68                                 $cargs = "?".$cargs if ($cargs ne '' &&
69                                                         $cargs !~ /^(\/|%2F)/);
70                                 push(@links,
71                                    "<a href='$cmod/$cpage$cargs'>$ctitle</a>");
72                                 }
73                         }
74                 if (@links > 2) {
75                         @links = ( @links[0..1], "..." );
76                         }
77                 print &ui_columns_row([
78                         $hi,
79                         $text{'wsearch_type_'.$r->{'type'}},
80                         "<a href='$r->{'mod'}->{'dir'}/'>$r->{'mod'}->{'desc'}</a>",
81                         &ui_links_row(\@links),
82                         ]);
83                 }
84         print &ui_columns_end();
85         }
86 else {
87         print "<b>",&text('wsearch_enone',
88                 "<tt>".&html_escape($re)."</tt>"),"</b><p>\n";
89         }
90
91 &ui_print_footer();
92
93 # print_search_dot()
94 # Print one dot per second
95 sub print_search_dot
96 {
97 local $now = time();
98 if ($now > $last_print_search_dot) {
99         print ". ";
100         $last_print_search_dot = $now;
101         }
102 }
103