Handle hostnames with upper-case letters
[webmin.git] / cluster-useradmin / refresh.cgi
1 #!/usr/local/bin/perl
2 # refresh.cgi
3 # Reload the lists of users and groups from all managed hosts
4
5 require './cluster-useradmin-lib.pl';
6 &ReadParse();
7 &ui_print_header(undef, $text{'refresh_title'}, "");
8 $| = 1;
9
10 # Setup error handler for down hosts
11 sub ref_error
12 {
13 $ref_error_msg = join("", @_);
14 }
15 &remote_error_setup(\&ref_error);
16
17 @hosts = &list_useradmin_hosts();
18 @servers = &list_servers();
19 if (defined($in{'id'})) {
20         @hosts = grep { $_->{'id'} == $in{'id'} } @hosts;
21         local ($s) = grep { $_->{'id'} == $hosts[0]->{'id'} } @servers;
22         print "<b>",&text('refresh_header5', undef,
23                           &server_name($s)),"</b><p>\n";
24         }
25 else {
26         @hosts = &create_on_parse("refresh_header");
27         }
28 foreach $h (@hosts) {
29         $ref_error_msg = undef;
30         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
31         if ($s) {
32                 # Refresh the list
33                 local $d = $s->{'desc'} ? $s->{'desc'} : $s->{'host'};
34                 &remote_foreign_require($s->{'host'}, "useradmin",
35                                         "user-lib.pl");
36                 if ($ref_error_msg) {
37                         # Host is down ..
38                         print &text('refresh_failed', $d,
39                                     $ref_error_msg),"<br>\n";
40                         next;
41                         }
42                 local $ousers = @{$h->{'users'}};
43                 local $ogroups = @{$h->{'groups'}};
44                 local @rusers = &remote_foreign_call($s->{'host'}, "useradmin",
45                                                      "list_users");
46                 local @rgroups = &remote_foreign_call($s->{'host'}, "useradmin",
47                                                       "list_groups");
48                 $h->{'users'} = \@rusers;
49                 $h->{'groups'} = \@rgroups;
50                 print &text('refresh_host', $d),"\n";
51                 local @ad;
52                 if (@rusers > $ousers) {
53                         push(@ad, &text('refresh_uadd', @rusers - $ousers));
54                         }
55                 elsif (@rusers < $ousers) {
56                         push(@ad, &text('refresh_udel', $ousers - @rusers));
57                         }
58                 if (@rgroups > $ogroups) {
59                         push(@ad, &text('refresh_gadd', @rgroups - $ogroups));
60                         }
61                 elsif (@rgroups < $ogroups) {
62                         push(@ad, &text('refresh_gdel', $ogroups - @rgroups));
63                         }
64                 if (@ad) {
65                         print "(",join(", ", @ad),")";
66                         }
67                 &save_useradmin_host($h);
68                 print "<br>\n";
69                 }
70         else {
71                 # remove from managed list
72                 &delete_useradmin_host($h);
73                 print &text('refresh_del', $h->{'id'}),"<br>\n";
74                 }
75         }
76 print "<p><b>$text{'refresh_done'}</b><p>\n";
77 &webmin_log("refresh");
78
79 &remote_finished();
80 if (defined($in{'id'})) {
81         &ui_print_footer("edit_host.cgi?id=$in{'id'}", $text{'host_return'},
82                          "", $text{'index_return'});
83         }
84 else {
85         &ui_print_footer("", $text{'index_return'});
86         }
87