Handle hostnames with upper-case letters
[webmin.git] / cluster-software / search.cgi
1 #!/usr/local/bin/perl
2 # search.cgi
3 # Display a list of packages where the name or description matches some string
4
5 require './cluster-software-lib.pl';
6 &ReadParse();
7
8 $s = $in{'search'};
9 @hosts = &list_software_hosts();
10 @servers = &list_servers();
11 foreach $h (@hosts) {
12         $anymatch = 0;
13         foreach $p (@{$h->{'packages'}}) {
14                 if (($p->{'name'} =~ /\Q$s\E/i || $p->{'desc'} =~ /\Q$s\E/i) &&
15                     !$already{$p->{'name'}}++) {
16                         push(@match, $p);
17                         $anymatch = 1;
18                         }
19                 }
20         if ($anymatch) {
21                 push(@servs, &host_to_server($h));
22                 }
23         }
24 if (@match == 1) {
25         &redirect("edit_pack.cgi?package=".&urlize($match[0]->{'name'}));
26         exit;
27         }
28
29 &ui_print_header(undef, $text{'search_title'}, "", "search");
30 if (@match) {
31         @match = sort { lc($a->{'name'}) cmp lc($b->{'name'}) } @match;
32         print "<b>",&text('search_match', "<tt>$s</tt>"),"</b><br>\n";
33
34         print &ui_form_start("delete_packs.cgi", "post");
35         print &ui_hidden("search", $in{'search'}),"\n";
36         @links = ( &select_all_link("del", 0),
37                    &select_invert_link("del", 0) );
38         @tds = ( "width=5" );
39         print &ui_links_row(\@links);
40         print &ui_columns_start([ "",
41                                   $text{'search_pack'},
42                                   $text{'search_class'},
43                                   $text{'search_desc'} ], 100, 0, \@tds);
44         foreach $i (@match) {
45                 local @cols;
46                 push(@cols, "<a href=\"edit_pack.cgi?search=$s&package=".
47                       &urlize($i->{'name'})."\">$i->{'name'}</a>");
48                 $c = $i->{'class'};
49                 push(@cols, $i->{'class'} || $text{'search_none'});
50                 push(@cols, $i->{'desc'});
51                 print &ui_checked_columns_row(\@cols, \@tds,
52                                               "del", $i->{'name'});
53                 }
54         print &ui_columns_end();
55         print &ui_links_row(\@links);
56
57         # Show button to delete, and servers to remove from
58         print &ui_submit($text{'search_delete'}),"\n";
59         print &ui_select("server", undef,
60                          [ [ -1, $text{'edit_all'} ],
61                            map { [ $_->{'id'}, &server_name($_) ] } @servs ]);
62         print &ui_form_end();
63         }
64 else {
65         print "<b>",&text('search_nomatch', "<tt>$s</tt>"),"</b>\n";
66         }
67
68 &ui_print_footer("", $text{'index_return'});
69