3 # Update a webmin user on all servers
5 require './cluster-webmin-lib.pl';
7 &ui_print_header(undef, $text{'user_title2'}, "");
8 print "<b>",&text('user_doing2', $in{'old'}),"</b><p>\n";
10 @allhosts = &list_webmin_hosts();
11 foreach $h (@allhosts) {
12 foreach $ug (@{$h->{'users'}}, @{$h->{'groups'}}) {
13 $taken{$ug->{'name'}}++;
18 $in{'name'} =~ /^[A-z0-9\-\_\.\@]+$/ ||
19 &error(&text('user_ename', $in{'name'}));
20 $in{'name'} ne $in{'old'} && $taken{$in{'name'}} &&
21 &error(&text('user_etaken', $in{'name'}));
22 $in{'pass_def'} == 0 && $in{'pass'} =~ /:/ && &error($text{'user_ecolon'});
23 if ($in{'ipmode'} > 0) {
24 @ips = split(/\s+/, $in{'ips'});
27 # Setup error handler for down hosts
30 $user_error_msg = join("", @_);
32 &remote_error_setup(\&user_error);
34 # Update the user on all servers that have him
35 foreach $h (@allhosts) {
36 foreach $u (@{$h->{'users'}}) {
37 if ($u->{'name'} eq $in{'old'}) {
43 @servers = &list_servers();
46 local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
47 local ($rh = "READ$p", $wh = "WRITE$p");
51 &remote_foreign_require($s->{'host'}, "acl", "acl-lib.pl");
52 if ($user_error_msg) {
54 print $wh &serialise_variable([ 0, $user_error_msg ]);
59 ($user) = grep { $_->{'name'} eq $in{'old'} } @{$h->{'users'}};
60 $user->{'name'} = $in{'name'};
61 if (!$in{'lang_def'}) {
62 $user->{'lang'} = $in{'lang'} ? $in{'lang'} : undef;
64 if (!$in{'theme_def'}) {
65 if ($in{'theme'} eq 'webmin') {
66 delete($user->{'theme'});
69 $user->{'theme'} = $in{'theme'};
72 if ($in{'ipmode'} == 0) {
73 delete($user->{'allow'});
74 delete($user->{'deny'});
76 elsif ($in{'ipmode'} == 1) {
77 $user->{'allow'} = join(" ", @ips);
78 delete($user->{'deny'});
80 elsif ($in{'ipmode'} == 2) {
81 delete($user->{'allow'});
82 $user->{'deny'} = join(" ", @ips);
84 if ($in{'pass_def'} == 0) {
85 $salt = chr(int(rand(26))+65).chr(int(rand(26))+65);
86 $user->{'pass'} = &unix_crypt($in{'pass'}, $salt);
89 elsif ($in{'pass_def'} == 3) {
90 $user->{'pass'} = 'x';
93 elsif ($in{'pass_def'} == 4) {
94 $user->{'pass'} = '*LK*';
97 elsif ($in{'pass_def'} == 5) {
98 $user->{'pass'} = 'e';
102 # Save module categorization setting
103 $user->{'notabs'} = $in{'notabs'};
105 # Work out which modules the user has
106 local @selmods = ( split(/\0/, $in{'mods1'}),
107 split(/\0/, $in{'mods2'}),
108 split(/\0/, $in{'mods3'}) );
109 local @mods = @{$user->{'modules'}};
110 if ($in{'mods_def'} == 2) {
113 elsif ($in{'mods_def'} == 3) {
114 @mods = &unique(@mods, @selmods);
116 elsif ($in{'mods_def'} == 0) {
117 @mods = grep { &indexof($_, @selmods) < 0 } @mods;
120 # Update old and new groups
121 foreach $g (@{$h->{'groups'}}) {
122 if (&indexof($in{'old'}, @{$g->{'members'}}) >= 0) {
126 if ($in{'group_def'}) {
130 ($group) = grep { $_->{'name'} eq $in{'group'} }
132 if (!$group && $in{'group'}) {
133 print $wh &serialise_variable(
134 [ 0, $text{'user_egroup'} ]);
138 if (($group ? $group->{'name'} : '') ne
139 ($oldgroup ? $oldgroup->{'name'} : '')) {
140 # Group has changed - update the member lists
142 $oldgroup->{'members'} =
143 [ grep { $_ ne $in{'old'} }
144 @{$oldgroup->{'members'}} ];
145 &remote_foreign_call($s->{'host'}, "acl",
146 "modify_group", $oldgroup->{'name'}, $oldgroup);
149 push(@{$group->{'members'}}, $in{'name'});
150 &remote_foreign_call($s->{'host'}, "acl",
151 "modify_group", $group->{'name'}, $group);
156 # Remove modules from the old group
157 @mods = grep { &indexof($_, @{$oldgroup->{'modules'}}) < 0 }
163 # Add modules from new group
166 if (&indexof($m, @{$group->{'modules'}}) < 0);
168 @mods = &unique(@mods, @{$group->{'modules'}});
169 &remote_foreign_call($s->{'host'}, "acl",
170 "copy_acl_files", $group->{'name'}, $in{'old'},
171 [ @{$group->{'modules'}}, "" ]);
174 $user->{'modules'} = \@mods;
175 $user->{'ownmods'} = \@ownmods;
176 &remote_foreign_call($s->{'host'}, "acl", "modify_user",
178 &save_webmin_host($h);
180 # Restart the remote webmin
181 print $wh &serialise_variable([ 1 ]);
182 &remote_foreign_call($s->{'host'}, "acl", "restart_miniserv");
189 # Read back the results
191 foreach $h (@hosts) {
192 local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
193 local $d = &server_name($s);
194 local $rh = "READ$p";
196 local $rv = &unserialise_variable($line);
199 if ($rv && $rv->[0] == 1) {
201 print &text('user_success2', $d),"<br>\n";
204 # Something went wrong
205 print &text('user_failed2', $d, $rv->[1]),"<br>\n";
210 print "<p><b>$text{'user_done'}</b><p>\n";
213 &ui_print_footer("", $text{'index_return'});