#!/usr/local/bin/perl
# user_chooser.cgi
# This CGI generated the HTML for choosing a user or list of users.
require './web-lib.pl';
&init_config();
&switch_to_remote_user();
&ReadParse();
%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
&header();
print "\n";
print "$text{'users_all'}\n";
print "\n";
foreach $u (&get_users_list()) {
if ($in{'user'} eq $u->[0]) { print "\n"; }
else { print "
\n"; }
$u->[6] =~ s/'/'/g;
print "$u->[0] | \n";
print "$u->[6] |
\n";
}
print "
\n";
}
elsif ($in{'frame'} == 2) {
# show chosen users
&header();
print "$text{'users_sel'}\n";
print <<'EOF';
EOF
}
elsif ($in{'frame'} == 3) {
# output OK and Cancel buttons
&header();
print "\n";
}
}
else {
# selecting just one user .. display a list of all users to choose from
&header();
print "\n";
print "$text{'users_title2'}\n";
print "\n";
foreach $u (&get_users_list()) {
if ($in{'user'} eq $u->[0]) { print "\n"; }
else { print "
\n"; }
print "$u->[0] | \n";
print "$u->[6] |
\n";
}
print "
\n";
}
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();
while(@uinfo = getpwent()) {
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 && $uinfo[3] == $access{'uedit'}) {
push(@users, [ @uinfo ]) if (!$found{$uinfo[0]}++);
}
}
endpwent() if ($gconfig{'os_type'} ne 'hpux');
return sort { $a->[0] cmp $b->[0] } @users;
}