3 # Create a new Webmin group across multiple servers
5 require './cluster-webmin-lib.pl';
7 &error_setup($text{'group_err1'});
8 @hosts = &list_webmin_hosts();
11 $in{'name'} =~ /^[A-z0-9\-\_\.]+$/ ||
12 &error(&text('user_ename', $in{'name'}));
14 # Setup error handler for down hosts
17 $group_error_msg = join("", @_);
19 &remote_error_setup(\&group_error);
21 # Work out which hosts to create on
22 &ui_print_header(undef, $text{'group_title1'}, "");
24 local ($alr) = grep { $_->{'name'} eq $in{'name'} } @{$h->{'groups'}};
25 push(@already, $h) if ($alr);
27 @hosts = &create_on_parse('group_doing', \@already, $in{'name'});
29 foreach $ug (@{$h->{'users'}}, @{$h->{'groups'}}) {
30 $taken{$ug->{'name'}}++;
33 $taken{$in{'name'}} && &error(&text('user_etaken', $in{'name'}));
35 @servers = &list_servers();
38 local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
39 local ($rh = "READ$p", $wh = "WRITE$p");
43 &remote_foreign_require($s->{'host'}, "acl", "acl-lib.pl");
44 if ($group_error_msg) {
46 print $wh &serialise_variable([ 0, $group_error_msg ]);
51 local %newgrp = ( 'name', $in{'name'} );
52 local @mods = ( split(/\0/, $in{'mods1'}),
53 split(/\0/, $in{'mods2'}),
54 split(/\0/, $in{'mods3'}) );
57 # Add group to the chosen group
58 ($group) = grep { $_->{'name'} eq $in{'group'} }
61 # Doesn't exist on this server
62 print $wh &serialise_variable(
63 [ 0, $text{'user_egroup'} ]);
66 push(@{$group->{'members'}}, $newgrp{'name'});
67 &remote_foreign_call($s->{'host'}, "acl", "modify_group",
68 $group->{'name'}, $group);
70 # Add modules from group
74 if (&indexof($m, @{$group->{'modules'}}) < 0);
76 @mods = &unique(@mods, @{$group->{'modules'}});
77 $newgrp{'ownmods'} = \@ownmods;
79 # Copy ACL files for group
80 &remote_foreign_call($s->{'host'}, "acl", "copy_acl_files",
81 $group->{'name'}, $newgrp{'name'},
82 [ @{$group->{'modules'}}, "" ]);
85 $newgrp{'modules'} = \@mods;
86 &remote_foreign_call($s->{'host'}, "acl", "create_group", \%newgrp);
87 push(@{$h->{'groups'}}, \%newgrp);
88 &save_webmin_host($h);
90 # Restart the remote webmin
91 print $wh &serialise_variable([ 1 ]);
92 &remote_foreign_call($s->{'host'}, "acl", "restart_miniserv");
99 # Read back the results
101 foreach $h (@hosts) {
102 local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
103 local $d = &server_name($s);
104 local $rh = "READ$p";
106 local $rv = &unserialise_variable($line);
109 if ($rv && $rv->[0] == 1) {
111 print &text('group_success', $d),"<br>\n";
114 # Something went wrong
115 print &text('group_failed', $d, $rv->[1]),"<br>\n";
120 print "<p><b>$text{'group_done'}</b><p>\n";
123 &ui_print_footer("", $text{'index_return'});