# cluster-useradmin-lib.pl # common functions for managing users across a cluster BEGIN { push(@INC, ".."); }; use WebminCore; &init_config(); &foreign_require("servers", "servers-lib.pl"); %useradmin_text = &load_language("useradmin"); %text = ( %useradmin_text, %text ); %uconfig = &foreign_config("useradmin"); # list_useradmin_hosts() # Returns a list of all hosts whose users are being managed by this module sub list_useradmin_hosts { 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"); my %host = ( 'id', $h ); next if (!$smap{$h}); # underlying server was deleted opendir(UDIR, "$hdir/$h"); foreach $f (readdir(UDIR)) { if ($f =~ /^(\S+)\.user$/) { my %user; &read_file("$hdir/$h/$f", \%user); push(@{$host{'users'}}, \%user); } elsif ($f =~ /^(\S+)\.group$/) { my %group; &read_file("$hdir/$h/$f", \%group); push(@{$host{'groups'}}, \%group); } } closedir(UDIR); push(@rv, \%host); } closedir(DIR); return @rv; } # save_useradmin_host(&host) sub save_useradmin_host { my ($host) = @_; my $hdir = "$module_config_directory/hosts"; my %oldfile; mkdir($hdir, 0700); if (-d "$hdir/$host->{'id'}") { opendir(DIR, "$hdir/$host->{'id'}"); %oldfile = map { $_, 1 } readdir(DIR); closedir(DIR); } else { mkdir("$hdir/$host->{'id'}", 0700); } foreach my $u (@{$host->{'users'}}) { &write_file("$hdir/$host->{'id'}/$u->{'user'}.user", $u); delete($oldfile{"$u->{'user'}.user"}); } foreach my $g (@{$host->{'groups'}}) { &write_file("$hdir/$host->{'id'}/$g->{'group'}.group", $g); delete($oldfile{"$g->{'group'}.group"}); } unlink(map { "$hdir/$host->{'id'}/$_" } keys %oldfile); } # delete_useradmin_host(&host) sub delete_useradmin_host { my ($host) = @_; &unlink_file("$module_config_directory/hosts/$host->{'id'}"); } # list_servers() # Returns a list of all servers from the webmin servers module that can be # managed, plus this server sub list_servers { my @servers = &servers::list_servers_sorted(); return ( &servers::this_server(), grep { $_->{'user'} } @servers ); } # auto_home_dir(base, username) # Returns an automatically generated home directory, and creates needed # parent dirs sub auto_home_dir { my ($base, $user) = @_; if ($uconfig{'home_style'} == 0) { return $_[0]."/".$_[1]; } elsif ($uconfig{'home_style'} == 1) { return $_[0]."/".substr($_[1], 0, 1)."/".$_[1]; } elsif ($uconfig{'home_style'} == 2) { return $_[0]."/".substr($_[1], 0, 1)."/". substr($_[1], 0, 2)."/".$_[1]; } elsif ($uconfig{'home_style'} == 3) { return $_[0]."/".substr($_[1], 0, 1)."/". substr($_[1], 1, 1)."/".$_[1]; } } # server_name(&server) sub server_name { my ($server) = @_; my @w; push(@w, $server->{'host'} || &get_system_hostname()); push(@w, "(".$server->{'desc'}.")") if ($server->{'desc'}); return join(" ", @w); } # supports_gothers(&server) # Returns 1 if some server supports group syncing, 0 if not sub supports_gothers { 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([no-donthave], [multiple]) # Returns a selector for a server or group to create users on sub create_on_input { 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) { my ($s) = grep { $_->{'id'} == $h->{'id'} } @servers; if ($s) { push(@opts, [ $s->{'id'}, &server_name($s) ]); $gothost{$s->{'host'}}++; } } foreach my $g (@groups) { my ($found, $m); foreach $m (@{$g->{'members'}}) { $found++ if ($gothost{$m}); } push(@opts, [ "group_$g->{'name'}", &text('uedit_group', $g->{'name'}) ]) if ($found); } 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 { 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 my %already = map { $_->{'id'}, 1 } @$already; push(@hosts, grep { !$already{$_->{'id'}} } @allhosts); print "<b>",&text($pfx.'3', $name),"</b><p>\n" if (!$noprint); } elsif ($server =~ /^group_(.*)/) { # Install on members of some group my ($group) = grep { $_->{'name'} eq $1 } &servers::list_all_groups(\@servers); push(@hosts, grep { my $hid = $_->{'id'}; my ($s) = grep { $_->{'id'} == $hid } @servers; &indexof($s->{'host'}, @{$group->{'members'}}) >= 0 } @allhosts); print "<b>",&text($pfx.'4', $name, $group->{'name'}), "</b><p>\n" if (!$noprint); } elsif ($server != -1) { # Just install on one host my ($onehost) = grep { $_->{'id'} == $server } @allhosts; push(@hosts, $onehost); my ($s) = grep { $_->{'id'} == $onehost->{'id'} } @servers; print "<b>",&text($pfx.'5', $name, &server_name($s)),"</b><p>\n" if (!$noprint); } else { # Installing on every host push(@hosts, @allhosts); print "<b>",&text($pfx, join(" ", @names)), "</b><p>\n" if (!$noprint); } } return &unique(@hosts); } 1;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
help | Folder | 0755 |
|
|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 273 B | 0644 |
|
add.cgi | File | 2.09 KB | 0755 |
|
cluster-useradmin-lib.pl | File | 5.51 KB | 0755 |
|
config | File | 150 B | 0644 |
|
config.info | File | 566 B | 0644 |
|
config.info.ca | File | 655 B | 0644 |
|
config.info.cs | File | 79 B | 0644 |
|
config.info.de | File | 657 B | 0644 |
|
config.info.es | File | 78 B | 0644 |
|
config.info.fr | File | 758 B | 0644 |
|
config.info.hr | File | 0 B | 0644 |
|
config.info.hu | File | 0 B | 0644 |
|
config.info.ms | File | 131 B | 0644 |
|
config.info.nl | File | 129 B | 0644 |
|
config.info.no | File | 137 B | 0644 |
|
config.info.pl | File | 121 B | 0644 |
|
create_group.cgi | File | 3.32 KB | 0755 |
|
create_user.cgi | File | 9.72 KB | 0755 |
|
delete_group.cgi | File | 3.61 KB | 0755 |
|
delete_host.cgi | File | 257 B | 0755 |
|
delete_user.cgi | File | 5.22 KB | 0755 |
|
edit_group.cgi | File | 5.39 KB | 0755 |
|
edit_host.cgi | File | 1.96 KB | 0755 |
|
edit_user.cgi | File | 17.68 KB | 0755 |
|
group_form.cgi | File | 2.29 KB | 0755 |
|
index.cgi | File | 4.98 KB | 0755 |
|
log_parser.pl | File | 542 B | 0755 |
|
module.info | File | 387 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 259 B | 0644 |
|
module.info.ar | File | 0 B | 0644 |
|
module.info.ar.auto | File | 392 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 489 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 487 B | 0644 |
|
module.info.ca | File | 265 B | 0644 |
|
module.info.ca.auto | File | 29 B | 0644 |
|
module.info.cs | File | 40 B | 0644 |
|
module.info.cs.auto | File | 247 B | 0644 |
|
module.info.da | File | 0 B | 0644 |
|
module.info.da.auto | File | 249 B | 0644 |
|
module.info.de | File | 147 B | 0644 |
|
module.info.de.auto | File | 24 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 521 B | 0644 |
|
module.info.es | File | 36 B | 0644 |
|
module.info.es.auto | File | 228 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 275 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 406 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 291 B | 0644 |
|
module.info.fr | File | 44 B | 0644 |
|
module.info.fr.auto | File | 260 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 316 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 261 B | 0644 |
|
module.info.hu | File | 31 B | 0644 |
|
module.info.hu.auto | File | 285 B | 0644 |
|
module.info.it | File | 0 B | 0644 |
|
module.info.it.auto | File | 253 B | 0644 |
|
module.info.ja | File | 0 B | 0644 |
|
module.info.ja.auto | File | 361 B | 0644 |
|
module.info.ko | File | 0 B | 0644 |
|
module.info.ko.auto | File | 310 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 298 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 274 B | 0644 |
|
module.info.ms | File | 247 B | 0644 |
|
module.info.ms.auto | File | 25 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 282 B | 0644 |
|
module.info.nl | File | 40 B | 0644 |
|
module.info.nl.auto | File | 242 B | 0644 |
|
module.info.no | File | 36 B | 0644 |
|
module.info.no.auto | File | 225 B | 0644 |
|
module.info.pl | File | 240 B | 0644 |
|
module.info.pl.auto | File | 29 B | 0644 |
|
module.info.pt | File | 0 B | 0644 |
|
module.info.pt.auto | File | 282 B | 0644 |
|
module.info.pt_BR | File | 0 B | 0644 |
|
module.info.pt_BR.auto | File | 291 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 301 B | 0644 |
|
module.info.ru | File | 0 B | 0644 |
|
module.info.ru.auto | File | 477 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 305 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 266 B | 0644 |
|
module.info.sv | File | 0 B | 0644 |
|
module.info.sv.auto | File | 265 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 597 B | 0644 |
|
module.info.tr | File | 0 B | 0644 |
|
module.info.tr.auto | File | 291 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 456 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 468 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 287 B | 0644 |
|
module.info.zh | File | 0 B | 0644 |
|
module.info.zh.auto | File | 244 B | 0644 |
|
module.info.zh_TW | File | 0 B | 0644 |
|
module.info.zh_TW.auto | File | 253 B | 0644 |
|
prefs.info | File | 28 B | 0644 |
|
refresh.cgi | File | 2.31 KB | 0755 |
|
save_group.cgi | File | 4.65 KB | 0755 |
|
save_user.cgi | File | 12.76 KB | 0755 |
|
search_group.cgi | File | 1.69 KB | 0755 |
|
search_user.cgi | File | 1.73 KB | 0755 |
|
sync.cgi | File | 4.92 KB | 0755 |
|
sync_form.cgi | File | 1.75 KB | 0755 |
|
user_form.cgi | File | 5.66 KB | 0755 |
|