Handle hostnames with upper-case letters
[webmin.git] / cluster-software / compare.cgi
1 #!/usr/local/bin/perl
2 # Do an actual comparison
3
4 require './cluster-software-lib.pl';
5 &error_setup($text{'compare_err'});
6 &ReadParse();
7
8 # Work out which servers to use
9 if ($in{'all'}) {
10         @hosts = &list_software_hosts();
11         }
12 else {
13         @allhosts = &list_software_hosts();
14         @servers = &list_servers();
15         @groups = &servers::list_all_groups(\@servers);
16         foreach $s (split(/\0/, $in{'hosts'})) {
17                 if ($s =~ /^group_(.*)$/) {
18                         # Add all group members
19                         ($group) = grep { $_->{'name'} eq $1 } @groups;
20                         foreach $m (@{$group->{'members'}}) {
21                                 ($server) =grep { $_->{'host'} eq $m } @servers;
22                                 ($host) = grep { $_->{'id'} eq $server->{'id'} } @allhosts;
23                                 push(@hosts, $host) if ($host);
24                                 }
25                         }
26                 else {
27                         # Add one host
28                         ($host) = grep { $_->{'id'} eq $s } @allhosts;
29                         push(@hosts, $host) if ($host);
30                         }
31                 }
32         }
33 @hosts >= 2 || &error($text{'compare_etwo'});
34
35 &ui_print_header(undef, $text{'compare_title'}, "");
36
37 # Find union of all packages
38 foreach $h (@hosts) {
39         foreach $p (@{$h->{'packages'}}) {
40                 $p->{'host'} = $h;
41                 push(@{$packs{$p->{'name'}}}, $p);
42                 }
43         }
44
45 # Show results by package
46 %smap = map { $_->{'id'}, $_ } &list_servers();
47 print &ui_columns_start([ $text{'compare_pack'},
48                           map { &server_name($smap{$_->{'id'}}) } @hosts ]);
49 foreach $pn (sort { $a cmp $b } (keys %packs)) {
50         local @row = ( "<a href='edit_pack.cgi?package=$pn'>$pn</a>" );
51         local $ok = 1;
52         foreach $h (@hosts) {
53                 local ($ph) = grep { $_->{'host'} eq $h } @{$packs{$pn}};
54                 if (!$ph) {
55                         push(@row, $text{'compare_miss'});
56                         $ok = 0;
57                         }
58                 else {
59                         push(@row, $ph->{'version'} || $text{'compare_got'});
60                         if ($ph->{'version'} &&
61                             $ph->{'version'} != $packs{$pn}->[0]->{'version'}) {
62                                 $ok = 0;
63                                 }
64                         }
65                 }
66         if (!$ok || $in{'showall'}) {
67                 print &ui_columns_row(\@row);
68                 }
69         }
70 print &ui_columns_end();
71
72 &ui_print_footer("", $text{'index_return'});