3 # Create missing users and groups on servers
5 require './cluster-webmin-lib.pl';
7 @hosts = &list_webmin_hosts();
8 @servers = &list_servers();
9 &ui_print_header(undef, $text{'sync_title'}, "");
11 # Work out which hosts
12 @phosts = &create_on_parse(undef, undef, undef, 1);
14 # Build lists of all users and group
16 local ($serv) = grep { $_->{'id'} == $h->{'id'} } @servers;
17 foreach $u (@{$h->{'users'}}) {
18 if (!$doneuser{$u->{'name'}}++) {
20 $u->{'source'} = $serv;
23 foreach $g (@{$h->{'groups'}}) {
24 if (!$donegroup{$g->{'name'}}++) {
26 $g->{'source'} = $serv;
31 # Find users and groups to sync
32 if ($in{'users_mode'} == 1) {
35 elsif ($in{'users_mode'} == 2) {
36 map { $usel{$_}++ } split(/\s+/, $in{'usel'});
37 @usync = grep { $usel{$_->{'name'}} } @ulist;
39 elsif ($in{'users_mode'} == 3) {
40 map { $unot{$_}++ } split(/\s+/, $in{'unot'});
41 @usync = grep { !$unot{$_->{'name'}} } @ulist;
44 if ($in{'groups_mode'} == 1) {
47 elsif ($in{'groups_mode'} == 2) {
48 map { $gsel{$_}++ } split(/\s+/, $in{'gsel'});
49 @gsync = grep { $gsel{$_->{'name'}} } @glist;
51 elsif ($in{'groups_mode'} == 3) {
52 map { $gnot{$_}++ } split(/\s+/, $in{'gnot'});
53 @gsync = grep { !$gnot{$_->{'name'}} } @glist;
56 # Setup error handler for down hosts
59 $add_error_msg = join("", @_);
61 &remote_error_setup(\&add_error);
63 # Sync on chosen hosts
64 foreach $host (@phosts) {
65 $add_error_msg = undef;
66 local ($serv) = grep { $_->{'id'} == $host->{'id'} } @servers;
67 print "<b>",&text('sync_on', &server_name($serv)),"</b><p>\n";
70 # Find missing users and groups
71 local (%usync, %gsync);
72 map { $usync{$_->{'name'}}++ } @{$host->{'users'}};
73 map { $gsync{$_->{'name'}}++ } @{$host->{'groups'}};
74 local @uneed = grep { !$usync{$_->{'name'}} } @usync;
75 local @gneed = grep { !$gsync{$_->{'name'}} } @gsync;
76 if (@uneed || @gneed) {
77 &remote_foreign_require($serv->{'host'},
79 $done_require{$serv->{'host'}}++;
82 print "$add_error_msg<p>\n";
87 # Create missing users
90 print &text('sync_ucreate', $u->{'name'}),"<br>\n";
92 &remote_foreign_call($serv->{'host'},
93 "acl", "create_user", $u);
94 push(@{$host->{'users'}}, $u);
96 print "$text{'refresh_done'}<p>\n";
99 print &text('sync_acl', $u->{'name'}),"<br>\n";
100 ©_acls_for($u, $serv, "user");
101 print "$text{'refresh_done'}<p>\n";
104 # Create missing groups
105 foreach $g (@gneed) {
106 print &text('sync_gcreate', $g->{'group'}),"<br>\n";
108 &remote_foreign_call($serv->{'host'},
109 "acl", "create_group", $g);
110 push(@{$host->{'groups'}}, $g);
112 print "$text{'refresh_done'}<p>\n";
114 print &text('sync_acl', $g->{'name'}),"<br>\n";
115 ©_acls_for($g, $serv, "group");
116 print "$text{'refresh_done'}<p>\n";
120 print "$text{'sync_restart'}<br>\n";
122 &remote_foreign_call($serv->{'host'}, "acl",
125 print "$text{'refresh_done'}<p>\n";
127 # Update in local list
128 &save_webmin_host($host);
131 print "$text{'sync_insync'}<p>\n";
135 &webmin_log("sync", undef, undef, \%in);
137 &ui_print_footer("", $text{'index_return'});
139 # copy_acls_for(&user|&group, &server)
140 # Copy all .acl files from the server on which a user or group does exist
141 # to the given server
144 local $source = $_[0]->{'source'};
145 &remote_foreign_require($source->{'host'}, "acl", "acl-lib.pl")
146 if (!$done_require{$source->{'host'}}++);
147 local $suffix = $_[2] eq "user" ? "module_acl" : "group_module_acl";
148 foreach $m (@{$_[0]->{'modules'}}) {
149 local %acl = &remote_foreign_call($source->{'host'}, "acl",
150 "get_".$suffix, $_[0]->{'name'},$m);
152 &remote_foreign_call($_[1]->{'host'}, "acl", "save_".$suffix,
153 \%acl, $_[0]->{'name'}, $m);