Work on ui-lib conversion

This commit is contained in:
Jamie Cameron
2020-10-20 15:30:55 -07:00
parent 546ea972de
commit 2cb5d88637
6 changed files with 115 additions and 131 deletions

View File

@@ -24,6 +24,7 @@ else {
}
&ui_print_header(undef, $text{'add_title'}, "");
print "<b>$msg</b><p>\n";
# Setup error handler for down hosts

View File

@@ -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 "<tr> <td><b>$_[0]</b></td>\n";
print "<td colspan=2>\n";
}
if ($_[2]) {
print "<select name=server size=5 multiple>\n";
}
else {
print "<select name=server>\n";
}
print "<option value=-1>$text{'uedit_all'}</option>\n";
print "<option value=-2>$text{'uedit_donthave'}</option>\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 "<option value='$s->{'id'}'>",
$s->{'desc'} ? $s->{'desc'} : $s->{'host'},"</option>\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 "<option value='group_$g->{'name'}'>",
&text('uedit_group', $g->{'name'}),"</option>\n" if ($found);
push(@opts, [ "group_$g->{'name'}",
&text('uedit_group', $g->{'name'}) ]) if ($found);
}
print "</select>\n";
if ($_[0]) {
print "</td> </tr>\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 "<b>",&text($_[0].'3', $_[2]),"</b><p>\n" if (!$_[3]);
print "<b>",&text($pfx.'3', $name),"</b><p>\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 "<b>",&text($_[0].'4', $_[2], $group->{'name'}),
"</b><p>\n" if (!$_[3]);
print "<b>",&text($pfx.'4', $name, $group->{'name'}),
"</b><p>\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 "<b>",&text($_[0].'5', $_[2],
&server_name($s)),"</b><p>\n" if (!$_[3]);
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($_[0], join(" ", @names)),
"</b><p>\n" if (!$_[3]);
print "<b>",&text($pfx, join(" ", @names)),
"</b><p>\n" if (!$noprint);
}
}
return &unique(@hosts);

View File

@@ -50,7 +50,8 @@ print "<td><input type=radio name=others value=1 checked> $text{'yes'}</td>\n";
print "<td><input type=radio name=others value=0> $text{'no'}</td> </tr>\n";
# Show server selection input
&create_on_input($text{'uedit_servers'});
print "<tr> <td>$text{'uedit_servers'}</td> ",
"<td>",&create_on_input(),"</td> </tr>\n";
print "</table></td> </tr></table><p></p><p></p>\n";

View File

@@ -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 "<td>\n";
print "<form action=refresh.cgi>\n";
print "<input type=submit value='$text{'index_refresh'}'>\n";
&create_on_input(undef, 1);
print &create_on_input(1);
print "</form>\n";
print "</td>\n";
}

View File

@@ -7,68 +7,55 @@ require './cluster-useradmin-lib.pl';
&ui_print_header(undef, $text{'sync_title'}, "");
print "$text{'sync_desc'}<p>\n";
print "<form action=sync.cgi>\n";
print "<table width='100%'>\n";
print "<tr> <td valign=top><b>$text{'sync_hosts'}</b></td> <td>\n";
&create_on_input(undef, 1, 1);
print "</td> </tr>\n";
print &ui_form_start("sync.cgi", "post");
print &ui_table_start($text{'sync_hosts'}, undef, 2);
print "<tr> <td valign=top><b>$text{'sync_users'}</b></td> <td>\n";
print "<input type=radio name=users_mode value=1> ",
"$text{'sync_uall'}&nbsp;&nbsp;\n";
print "<input type=radio name=users_mode value=0 checked> ",
"$text{'sync_unone'}<br>\n";
print "<input type=radio name=users_mode value=2> ",
"$text{'sync_usel'}\n";
print "<input name=usel size=30> ",&user_chooser_button("usel", 1),"<br>\n";
print "<input type=radio name=users_mode value=3> ",
"$text{'sync_unot'}\n";
print "<input name=unot size=30> ",&user_chooser_button("unot", 1),"<br>\n";
print "<input type=radio name=users_mode value=4> ",
"$text{'sync_uuid'}\n";
print "<input name=uuid1 size=6> - <input name=uuid2 size=6><br>\n";
print "<input type=radio name=users_mode value=5> ",
"$text{'sync_ugid'}\n";
print &unix_group_input("ugid"),"<br>\n";
print "</td> </tr>\n";
# Hosts to sync
print &ui_table_row($text{'sync_hosts'},
&create_on_input(1, 1));
print "<tr> <td valign=top><b>$text{'sync_groups'}</b></td> <td>\n";
print "<input type=radio name=groups_mode value=1> ",
"$text{'sync_gall'}&nbsp;&nbsp;\n";
print "<input type=radio name=groups_mode value=0 checked> ",
"$text{'sync_gnone'}<br>\n";
print "<input type=radio name=groups_mode value=2> ",
"$text{'sync_gsel'}\n";
print "<input name=gsel size=30> ",&group_chooser_button("gsel", 1),"<br>\n";
print "<input type=radio name=groups_mode value=3> ",
"$text{'sync_gnot'}\n";
print "<input name=gnot size=30> ",&group_chooser_button("gnot", 1),"<br>\n";
print "<input type=radio name=groups_mode value=4> ",
"$text{'sync_ggid'}\n";
print "<input name=ggid1 size=6> - <input name=ggid2 size=6><br>\n";
print "</td> </tr>\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 "<tr> <td><b>$text{'sync_test'}</b></td>\n";
print "<td><input type=radio name=test value=1> $text{'yes'}\n";
print "<input type=radio name=test value=0 checked> $text{'no'}</td> </tr>\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 "<tr> <td><b>$text{'sync_makehome'}</b></td>\n";
print "<td><input type=radio name=makehome value=1 checked> $text{'yes'}\n";
print "<input type=radio name=makehome value=0> $text{'no'}</td>\n";
print "</tr>\n";
# Test mode?
print &ui_table_row($text{'sync_test'},
&ui_yesno_radio("test", 0));
print "<tr> <td><b>$text{'sync_copy'}</b></td>\n";
print "<td><input type=radio name=copy_files value=1 checked> $text{'yes'}\n";
print "<input type=radio name=copy_files value=0> $text{'no'}</td>\n";
print "</tr>\n";
# Create home dir?
print &ui_table_row($text{'sync_makehome'},
&ui_yesno_radio("makehome", 1));
print "<tr> <td><b>$text{'sync_others'}</b></td>\n";
print "<td><input type=radio name=others value=1 checked> $text{'yes'}\n";
print "<input type=radio name=others value=0> $text{'no'}</td> </tr>\n";
# Copy home dir files?
print &ui_table_row($text{'sync_copy'},
&ui_yesno_radio("copy_files", 1));
print "</table><p></p><p></p>\n";
print "<input type=submit value='$text{'sync_ok'}'></form>\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'});

View File

@@ -246,7 +246,8 @@ print "<td><input type=radio name=others value=1 checked> $text{'yes'}</td>\n";
print "<td><input type=radio name=others value=0> $text{'no'}</td> </tr>\n";
# Show selector for hosts to create on
&create_on_input($text{'uedit_servers'});
print "<tr> <td><b>$text{'uedit_servers'}</b></td> ",
"<td>",&create_on_input(),"</td> </tr>\n";
print "</table></td> </tr></table><p></p><p></p>\n";