#!/usr/local/bin/perl
# user_chooser.cgi
# This CGI generated the HTML for choosing a user or list of users.
$trust_unknown_referers = 1;
BEGIN { push(@INC, "."); };
use WebminCore;
&init_config();
if (&get_product_name() eq 'usermin') {
&switch_to_remote_user();
}
&ReadParse(undef, undef, 2);
%access = &get_module_acl();
if ($in{'multi'}) {
# selecting multiple users.
if ($in{'frame'} == 0) {
# base frame
&PrintHeader();
print "\n";
print "
$text{'users_title1'}\n";
print "\n";
}
elsif ($in{'frame'} == 1) {
# list of all users to choose from
&popup_header();
print "\n";
print "";
print &ui_textbox("filter",$text{'ui_filterbox'}, 50, 0, undef,"style='width:100%;color:#aaa;' onkeyup=\"filter_match(this.value);\" onfocus=\"if (this.value == '".$text{'ui_filterbox'}."') {this.value = '';this.style.color='#000';}\" onblur=\"if (this.value == '') {this.value = '".$text{'ui_filterbox'}."';this.style.color='#aaa';}\"");
print &ui_hr("style='width:100%;'")."
";
print "$text{'users_all'}\n";
print "\n";
my $cnt = 0;
foreach $u (&get_users_list()) {
if ($in{'user'} eq $u->[0]) { print "\n"; }
else { print "
\n"; }
$u->[0] =~ s/\\/\\\\/g;
print "[6], \"'\")]}\")'>@{[&html_escape($u->[0])]} | \n";
print "",&html_escape($u->[6])," |
\n";
$cnt++;
}
print "
\n";
if ( $cnt >= 10 ) {
print "";
print "";
}
&popup_footer();
}
elsif ($in{'frame'} == 2) {
# show chosen users
&popup_header();
print "$text{'users_sel'}\n";
print <<'EOF';
EOF
&popup_footer();
}
elsif ($in{'frame'} == 3) {
# output OK and Cancel buttons
&popup_header();
print "\n";
print "\n";
&popup_footer();
}
}
else {
# selecting just one user .. display a list of all users to choose from
&popup_header($text{'users_title2'});
print "\n";
print "";
print &ui_textbox("filter",$text{'ui_filterbox'}, 50, 0, undef,"style='width:100%;color:#aaa;' onkeyup=\"filter_match(this.value);\" onfocus=\"if (this.value == '".$text{'ui_filterbox'}."') {this.value = '';this.style.color='#000'}\" onblur=\"if (this.value == '') {this.value = '".$text{'ui_filterbox'}."';this.style.color='#aaa';}\"");
print &ui_hr("style='width:100%;'")."
";
print "\n";
my $cnt = 0;
foreach $u (&get_users_list()) {
if ($in{'user'} eq $u->[0]) { print "\n"; }
else { print "
\n"; }
print "@{[&html_escape($u->[0])]} | \n";
print "@{[&html_escape($u->[6])]} |
\n";
$cnt++;
}
print "
\n";
if ( $cnt >= 10 ) {
print "";
print "";
}
&popup_footer();
}
sub get_users_list
{
local(@uinfo, @users, %ucan, %found);
if ($access{'uedit_mode'} == 2 || $access{'uedit_mode'} == 3) {
map { $ucan{$_}++ } split(/\s+/, $access{'uedit'});
}
setpwent();
local %doneu;
while(@uinfo = getpwent()) {
next if ($doneu{$uinfo[0]}++);
if ($access{'uedit_mode'} == 5 && $access{'uedit'} !~ /^\d+$/) {
# Get group for matching by group name
@ginfo = getgrgid($uinfo[3]);
}
if ($access{'uedit_mode'} == 0 ||
$access{'uedit_mode'} == 2 && $ucan{$uinfo[0]} ||
$access{'uedit_mode'} == 3 && !$ucan{$uinfo[0]} ||
$access{'uedit_mode'} == 4 &&
(!$access{'uedit'} || $uinfo[2] >= $access{'uedit'}) &&
(!$access{'uedit2'} || $uinfo[2] <= $access{'uedit2'}) ||
$access{'uedit_mode'} == 5 &&
($access{'uedit'} =~ /^\d+$/ && $uinfo[3] == $access{'uedit'} ||
$ginfo[0] eq $access{'uedit'})) {
push(@users, [ @uinfo ]) if (!$found{$uinfo[0]}++);
}
}
endpwent() if ($gconfig{'os_type'} ne 'hpux');
return sort { $a->[0] cmp $b->[0] } @users;
}