diff --git a/cluster-useradmin/add.cgi b/cluster-useradmin/add.cgi index fc87281fd..a14a37b96 100755 --- a/cluster-useradmin/add.cgi +++ b/cluster-useradmin/add.cgi @@ -24,6 +24,7 @@ else { } &ui_print_header(undef, $text{'add_title'}, ""); + print "$msg

\n"; # Setup error handler for down hosts diff --git a/cluster-useradmin/cluster-useradmin-lib.pl b/cluster-useradmin/cluster-useradmin-lib.pl index 5667ab9b8..bd5baa008 100755 --- a/cluster-useradmin/cluster-useradmin-lib.pl +++ b/cluster-useradmin/cluster-useradmin-lib.pl @@ -13,23 +13,23 @@ use WebminCore; # Returns a list of all hosts whose users are being managed by this module sub list_useradmin_hosts { -local %smap = map { $_->{'id'}, $_ } &list_servers(); -local $hdir = "$module_config_directory/hosts"; -opendir(DIR, $hdir); -local ($h, @rv); -foreach $h (readdir(DIR)) { +my %smap = map { $_->{'id'}, $_ } &list_servers(); +my $hdir = "$module_config_directory/hosts"; +my @rv; +opendir(DIR, $hdir) || return (); +foreach my $h (readdir(DIR)) { next if ($h eq "." || $h eq ".." || !-d "$hdir/$h"); - local %host = ( 'id', $h ); + my %host = ( 'id', $h ); next if (!$smap{$h}); # underlying server was deleted opendir(UDIR, "$hdir/$h"); foreach $f (readdir(UDIR)) { if ($f =~ /^(\S+)\.user$/) { - local %user; + my %user; &read_file("$hdir/$h/$f", \%user); push(@{$host{'users'}}, \%user); } elsif ($f =~ /^(\S+)\.group$/) { - local %group; + my %group; &read_file("$hdir/$h/$f", \%group); push(@{$host{'groups'}}, \%group); } @@ -44,32 +44,34 @@ return @rv; # save_useradmin_host(&host) sub save_useradmin_host { -local $hdir = "$module_config_directory/hosts"; -local %oldfile; +my ($host) = @_; +my $hdir = "$module_config_directory/hosts"; +my %oldfile; mkdir($hdir, 0700); -if (-d "$hdir/$_[0]->{'id'}") { - opendir(DIR, "$hdir/$_[0]->{'id'}"); - map { $oldfile{$_}++ } readdir(DIR); +if (-d "$hdir/$host->{'id'}") { + opendir(DIR, "$hdir/$host->{'id'}"); + %oldfile = map { $_, 1 } readdir(DIR); closedir(DIR); } else { - mkdir("$hdir/$_[0]->{'id'}", 0700); + mkdir("$hdir/$hist->{'id'}", 0700); } -foreach $u (@{$_[0]->{'users'}}) { - &write_file("$hdir/$_[0]->{'id'}/$u->{'user'}.user", $u); +foreach my $u (@{$host->{'users'}}) { + &write_file("$hdir/$host->{'id'}/$u->{'user'}.user", $u); delete($oldfile{"$u->{'user'}.user"}); } -foreach $g (@{$_[0]->{'groups'}}) { - &write_file("$hdir/$_[0]->{'id'}/$g->{'group'}.group", $g); +foreach my $g (@{$host->{'groups'}}) { + &write_file("$hdir/$host->{'id'}/$g->{'group'}.group", $g); delete($oldfile{"$g->{'group'}.group"}); } -unlink(map { "$hdir/$_[0]->{'id'}/$_" } keys %oldfile); +unlink(map { "$hdir/$host->{'id'}/$_" } keys %oldfile); } # delete_useradmin_host(&host) sub delete_useradmin_host { -system("rm -rf '$module_config_directory/hosts/$_[0]->{'id'}'"); +my ($host) = @_; +&unlink_file("$module_config_directory/hosts/$host->{'id'}"); } # list_servers() @@ -77,7 +79,7 @@ system("rm -rf '$module_config_directory/hosts/$_[0]->{'id'}'"); # managed, plus this server sub list_servers { -local @servers = &servers::list_servers_sorted(); +my @servers = &servers::list_servers_sorted(); return ( &servers::this_server(), grep { $_->{'user'} } @servers ); } @@ -86,6 +88,7 @@ return ( &servers::this_server(), grep { $_->{'user'} } @servers ); # parent dirs sub auto_home_dir { +my ($base, $user) = @_; if ($uconfig{'home_style'} == 0) { return $_[0]."/".$_[1]; } @@ -105,99 +108,90 @@ elsif ($uconfig{'home_style'} == 3) { # server_name(&server) sub server_name { -return $_[0]->{'desc'} ? $_[0]->{'desc'} : $_[0]->{'host'}; +my ($server) = @_; +return $server->{'desc'} || $server->{'host'}; } # supports_gothers(&server) # Returns 1 if some server supports group syncing, 0 if not sub supports_gothers { -local $vers = $remote_server_version{$_[0]->{'host'}} || - &remote_foreign_call($_[0]->{'host'}, "useradmin", - "get_webmin_version"); +my ($server) = @_; +my $vers = $remote_server_version{$server->{'host'}} || + &remote_foreign_call($server->{'host'}, "useradmin", + "get_webmin_version"); return $vers >= 1.090; } -# create_on_input(desc, [no-donthave], [multiple]) +# create_on_input([no-donthave], [multiple]) +# Returns a selector for a server or group to create users on sub create_on_input { -local @hosts = &list_useradmin_hosts(); -local @servers = &list_servers(); -if ($_[0]) { - print " $_[0]\n"; - print "\n"; - } -if ($_[2]) { - print "\n"; - } -print "\n"; -print "\n" if (!$_[1]); -local @groups = &servers::list_all_groups(\@servers); -local $h; +my ($nodont, $mul) = @_; +my @hosts = &list_useradmin_hosts(); +my @servers = &list_servers(); +my @opts = ( [ -1, $text{'uedit_all'} ] ); +push(@opts, [ -2, $text{'uedit_donthave'} ] ) if (!$nodont); +my @groups = &servers::list_all_groups(\@servers); +my $h; foreach $h (@hosts) { - local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers; + my ($s) = grep { $_->{'id'} == $h->{'id'} } @servers; if ($s) { - print "\n"; + push(@opts, [ $s->{'id'}, &server_name($s) ]); $gothost{$s->{'host'}}++; } } -local $g; -foreach $g (@groups) { - local ($found, $m); +foreach my $g (@groups) { + my ($found, $m); foreach $m (@{$g->{'members'}}) { - ($found++, last) if ($gothost{$m}); + $found++ if ($gothost{$m}); } - print "\n" if ($found); + push(@opts, [ "group_$g->{'name'}", + &text('uedit_group', $g->{'name'}) ]) if ($found); } -print "\n"; -if ($_[0]) { - print " \n"; - } +return &ui_select("server", undef, \@opts, $mul ? 5 : 1, $mul); } # create_on_parse(prefix, &already, name, [no-print]) +# Returns a list of selected hosts from an input created by create_on_input sub create_on_parse { -local @allhosts = &list_useradmin_hosts(); -local @servers = &list_servers(); -local @hosts; -local $server; +my ($pfx, $already, $name, $noprint) = @_; +my @allhosts = &list_useradmin_hosts(); +my @servers = &list_servers(); +my @hosts; +my $server; foreach $server (split(/\0/, $in{'server'})) { if ($server == -2) { # Check who has it already - local %already = map { $_->{'id'}, 1 } @{$_[1]}; + my %already = map { $_->{'id'}, 1 } @$already; push(@hosts, grep { !$already{$_->{'id'}} } @allhosts); - print "",&text($_[0].'3', $_[2]),"

\n" if (!$_[3]); + print "",&text($pfx.'3', $name),"

\n" if (!$noprint); } elsif ($server =~ /^group_(.*)/) { # Install on members of some group - local ($group) = grep { $_->{'name'} eq $1 } + my ($group) = grep { $_->{'name'} eq $1 } &servers::list_all_groups(\@servers); - push(@hosts, grep { local $hid = $_->{'id'}; - local ($s) = grep { $_->{'id'} == $hid } @servers; + push(@hosts, grep { my $hid = $_->{'id'}; + my ($s) = grep { $_->{'id'} == $hid } @servers; &indexof($s->{'host'}, @{$group->{'members'}}) >= 0 } @allhosts); - print "",&text($_[0].'4', $_[2], $group->{'name'}), - "

\n" if (!$_[3]); + print "",&text($pfx.'4', $name, $group->{'name'}), + "

\n" if (!$noprint); } elsif ($server != -1) { # Just install on one host - local ($onehost) = grep { $_->{'id'} == $server } @allhosts; + my ($onehost) = grep { $_->{'id'} == $server } @allhosts; push(@hosts, $onehost); - local ($s) = grep { $_->{'id'} == $onehost->{'id'} } @servers; - print "",&text($_[0].'5', $_[2], - &server_name($s)),"

\n" if (!$_[3]); + my ($s) = grep { $_->{'id'} == $onehost->{'id'} } @servers; + print "",&text($pfx.'5', $name, + &server_name($s)),"

\n" if (!$noprint); } else { # Installing on every host push(@hosts, @allhosts); - print "",&text($_[0], join(" ", @names)), - "

\n" if (!$_[3]); + print "",&text($pfx, join(" ", @names)), + "

\n" if (!$noprint); } } return &unique(@hosts); diff --git a/cluster-useradmin/group_form.cgi b/cluster-useradmin/group_form.cgi index f74007a7d..6dac60fa5 100755 --- a/cluster-useradmin/group_form.cgi +++ b/cluster-useradmin/group_form.cgi @@ -50,7 +50,8 @@ print " $text{'yes'}\n"; print " $text{'no'} \n"; # Show server selection input -&create_on_input($text{'uedit_servers'}); +print " $text{'uedit_servers'} ", + "",&create_on_input()," \n"; print "

\n"; diff --git a/cluster-useradmin/index.cgi b/cluster-useradmin/index.cgi index c7b1d3371..c33f4c5a9 100755 --- a/cluster-useradmin/index.cgi +++ b/cluster-useradmin/index.cgi @@ -98,8 +98,8 @@ if ($config{'conf_add_user'} == 0 && $config{'conf_allow_sync'} == 0 && $config{'conf_find_user'} == 0 && $config{'conf_find_group'} == 0) { - # If we have configured EVERY possible 'host' action off, then don't show - # the header/horizontal-rule/etc... + # If we have configured EVERY possible 'host' action off, then don't + # show the header/horizontal-rule/etc... @hosts = (); } @@ -205,7 +205,7 @@ if (@hosts) { print "\n"; print "
\n"; print "\n"; - &create_on_input(undef, 1); + print &create_on_input(1); print "
\n"; print "\n"; } diff --git a/cluster-useradmin/sync_form.cgi b/cluster-useradmin/sync_form.cgi index af8470806..3dd2b171e 100755 --- a/cluster-useradmin/sync_form.cgi +++ b/cluster-useradmin/sync_form.cgi @@ -7,68 +7,55 @@ require './cluster-useradmin-lib.pl'; &ui_print_header(undef, $text{'sync_title'}, ""); print "$text{'sync_desc'}

\n"; -print "

\n"; -print "\n"; -print "\n"; +print &ui_form_start("sync.cgi", "post"); +print &ui_table_start($text{'sync_hosts'}, undef, 2); -print "\n"; +# Hosts to sync +print &ui_table_row($text{'sync_hosts'}, + &create_on_input(1, 1)); -print "\n"; +# Users to sync +print &ui_table_row($text{'sync_users'}, + &ui_radio_table("users_mode", 0, + [ [ 1, $text{'sync_uall'} ], + [ 0, $text{'sync_unone'} ], + [ 2, $text{'sync_usel'}, &ui_users_textbox("usel") ], + [ 3, $text{'sync_unot'}, &ui_users_textbox("unot") ], + [ 4, $text{'sync_uuid'}, &ui_textbox("uuid1", "", 6)." - ". + &ui_textbox("uuid2", "", 6) ], + [ 5, $text{'sync_ugid'}, &ui_group_textbox("ugid") ], + ])); -print "\n"; -print "\n"; +# Groups to sync +print &ui_table_row($text{'sync_groups'}, + &ui_radio_table("groups_mode", 0, + [ [ 1, $text{'sync_gall'} ], + [ 0, $text{'sync_gnone'} ], + [ 2, $text{'sync_gsel'}, &ui_groups_textbox("gsel") ], + [ 3, $text{'sync_gnot'}, &ui_groups_textbox("gnot") ], + [ 4, $text{'sync_ggid'}, &ui_textbox("ggid1", "", 6)." - ". + &ui_textbox("ggid2", "", 6) ], + ])); -print "\n"; -print "\n"; -print "\n"; +# Test mode? +print &ui_table_row($text{'sync_test'}, + &ui_yesno_radio("test", 0)); -print "\n"; -print "\n"; -print "\n"; +# Create home dir? +print &ui_table_row($text{'sync_makehome'}, + &ui_yesno_radio("makehome", 1)); -print "\n"; -print "\n"; +# Copy home dir files? +print &ui_table_row($text{'sync_copy'}, + &ui_yesno_radio("copy_files", 1)); -print "
$text{'sync_hosts'} \n"; -&create_on_input(undef, 1, 1); -print "
$text{'sync_users'} \n"; -print " ", - "$text{'sync_uall'}  \n"; -print " ", - "$text{'sync_unone'}
\n"; -print " ", - "$text{'sync_usel'}\n"; -print " ",&user_chooser_button("usel", 1),"
\n"; -print " ", - "$text{'sync_unot'}\n"; -print " ",&user_chooser_button("unot", 1),"
\n"; -print " ", - "$text{'sync_uuid'}\n"; -print " -
\n"; -print " ", - "$text{'sync_ugid'}\n"; -print &unix_group_input("ugid"),"
\n"; -print "
$text{'sync_groups'} \n"; -print " ", - "$text{'sync_gall'}  \n"; -print " ", - "$text{'sync_gnone'}
\n"; -print " ", - "$text{'sync_gsel'}\n"; -print " ",&group_chooser_button("gsel", 1),"
\n"; -print " ", - "$text{'sync_gnot'}\n"; -print " ",&group_chooser_button("gnot", 1),"
\n"; -print " ", - "$text{'sync_ggid'}\n"; -print " -
\n"; -print "
$text{'sync_test'} $text{'yes'}\n"; -print " $text{'no'}
$text{'sync_makehome'} $text{'yes'}\n"; -print " $text{'no'}
$text{'sync_copy'} $text{'yes'}\n"; -print " $text{'no'}
$text{'sync_others'} $text{'yes'}\n"; -print " $text{'no'}

\n"; -print "
\n"; +# Create in other modules? +print &ui_table_row($text{'sync_others'}, + &ui_yesno_radio("others", 1)); + +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'sync_ok'} ] ]); &ui_print_footer("", $text{'index_return'}); diff --git a/cluster-useradmin/user_form.cgi b/cluster-useradmin/user_form.cgi index aa084610d..f261974d0 100755 --- a/cluster-useradmin/user_form.cgi +++ b/cluster-useradmin/user_form.cgi @@ -246,7 +246,8 @@ print " $text{'yes'}\n"; print " $text{'no'} \n"; # Show selector for hosts to create on -&create_on_input($text{'uedit_servers'}); +print " $text{'uedit_servers'} ", + "",&create_on_input()," \n"; print "

\n";