webmin/useradmin/edit_user.cgi

641 lines
19 KiB
Plaintext
Raw Permalink Normal View History

2007-04-12 20:24:50 +00:00
#!/usr/local/bin/perl
# edit_user.cgi
# Display a form for editing a user, or creating a new user
require './user-lib.pl';
use Time::Local;
2007-04-12 20:24:50 +00:00
&ReadParse();
2008-08-16 00:50:56 +00:00
# Show header and get the user
2016-05-25 19:15:40 +02:00
@ulist = &list_users();
$n = $in{'user'};
2016-05-25 19:15:40 +02:00
if ($n eq '') {
# Creating a new user
2007-04-12 20:24:50 +00:00
$access{'ucreate'} || &error($text{'uedit_ecreate'});
&ui_print_header(undef, $text{'uedit_title2'}, "", "create_user");
2016-05-25 19:15:40 +02:00
if ($in{'clone'} ne '') {
($clone_hash) = grep { $_->{'user'} eq $in{'clone'} } @ulist;
$clone_hash || &error($text{'uedit_egone'});
%uinfo = %$clone_hash;
&can_edit_user(\%access, \%uinfo) || &error($text{'uedit_eedit'});
$uinfo{'user'} = '';
}
2007-04-12 20:24:50 +00:00
}
else {
2016-05-25 19:15:40 +02:00
# Editing an existing one
($uinfo_hash) = grep { $_->{'user'} eq $n } @ulist;
$uinfo_hash || &error($text{'uedit_egone'});
%uinfo = %$uinfo_hash;
2007-04-12 20:24:50 +00:00
&can_edit_user(\%access, \%uinfo) || &error($text{'uedit_eedit'});
&ui_print_header(undef, $text{'uedit_title'}, "", "edit_user");
}
2008-08-22 01:29:11 +00:00
@tds = ( "width=30%" );
2007-04-12 20:24:50 +00:00
# build list of used shells
%shells = map { $_, 1 } split(/,/, $config{'shells'});
@shlist = ($config{'default_shell'} ? ( $config{'default_shell'} ) : ( ));
push(@shlist, "/bin/sh", "/bin/csh", "/bin/false") if ($shells{'fixed'});
&build_user_used(\%used, $shells{'passwd'} ? \@shlist : undef);
if ($shells{'shells'}) {
open(SHELLS, "</etc/shells");
2007-04-12 20:24:50 +00:00
while(<SHELLS>) {
s/\r|\n//g;
s/#.*$//;
push(@shlist, $_) if (/\S/);
}
close(SHELLS);
}
2008-08-16 00:50:56 +00:00
# Start of the form
print &ui_form_start("save_user.cgi", "post");
print &ui_hidden("old", $n) if ($n ne "");
2008-08-22 01:29:11 +00:00
print &ui_table_start($text{'uedit_details'}, "width=100%", 2, \@tds);
2007-04-12 20:24:50 +00:00
2008-08-16 00:50:56 +00:00
# Username
2007-04-12 20:24:50 +00:00
if ($n eq "" && $config{'new_user_group'} && $access{'gcreate'}) {
$onch = "newgid.value = user.value";
}
if ($access{'urename'} || $n eq "") {
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'user'}, "user"),
&ui_textbox("user", $uinfo{'user'}, 40, 0, undef,
2008-08-16 00:50:56 +00:00
"onChange='$onch'"));
2007-04-12 20:24:50 +00:00
}
else {
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'user'}, "user"),
"<tt>".&html_escape($uinfo{'user'})."</tt>");
2007-04-12 20:24:50 +00:00
print &ui_hidden("user", $uinfo{'user'}),"\n";
}
2008-08-16 00:50:56 +00:00
# User ID
if ($n ne "") {
# Existing user, just show field to edit
2008-08-21 20:37:37 +00:00
$uidfield = &ui_textbox("uid", $uinfo{'uid'}, 10);
2008-08-16 00:50:56 +00:00
}
2007-04-12 20:24:50 +00:00
else {
2008-08-16 00:50:56 +00:00
# Work out which UID modes are available
@uidmodes = ( );
$defuid = &allocate_uid(\%used);
if ($access{'autouid'}) {
2008-08-22 01:29:11 +00:00
push(@uidmodes, [ 1, $text{'uedit_uid_def'} ]);
2008-08-16 00:50:56 +00:00
}
if ($access{'calcuid'}) {
2008-08-22 01:29:11 +00:00
push(@uidmodes, [ 2, $text{'uedit_uid_calc'} ]);
2008-08-16 00:50:56 +00:00
}
if ($access{'useruid'}) {
push(@uidmodes, [ 0, &ui_textbox("uid", $defuid, 10) ]);
}
if (@uidmodes == 1) {
$uidfield = &ui_hidden("uid_def", $uidmodes[0]->[0]).
$uidmodes[0]->[1];
}
else {
$uidfield = &ui_radio("uid_def", $config{'uid_mode'},
\@uidmodes);
}
2007-04-12 20:24:50 +00:00
}
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'uid'}, "uid"), $uidfield);
2007-04-12 20:24:50 +00:00
2008-08-16 00:50:56 +00:00
# Real name
2007-04-12 20:24:50 +00:00
if ($config{'extra_real'}) {
2008-08-16 00:50:56 +00:00
# Has separate name, office, work and home phone parts
2007-04-12 20:24:50 +00:00
local @real = split(/,/, $uinfo{'real'}, 5);
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'real'}, "real"),
&ui_textbox("real", $real[0], 40));
2007-04-12 20:24:50 +00:00
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'office'}, "office"),
&ui_textbox("office", $real[1], 20));
2007-04-12 20:24:50 +00:00
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'workph'}, "workph"),
&ui_textbox("workph", $real[2], 20));
2007-04-12 20:24:50 +00:00
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'homeph'}, "homeph"),
&ui_textbox("homeph", $real[3], 20));
2007-04-12 20:24:50 +00:00
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'extra'}, "extra"),
&ui_textbox("extra", $real[4], 20));
2007-04-12 20:24:50 +00:00
}
else {
2008-08-16 00:50:56 +00:00
# Just a name
2008-09-02 05:06:38 +00:00
$uinfo{'real'} =~ s/,*$//; # Strip empty extra fields
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'real'}, "real"),
2008-08-21 20:37:37 +00:00
&ui_textbox("real", $uinfo{'real'}, 40));
2007-04-12 20:24:50 +00:00
}
# Show input for home directory
if ($access{'autohome'}) {
2011-08-26 09:11:52 -07:00
# Automatic, cannot be changed
2008-08-16 00:50:56 +00:00
$homefield = $text{'uedit_auto'}.
2011-08-26 09:11:52 -07:00
($n eq "" ? "" : " ( <tt>$uinfo{'home'}</tt> )" );
2007-04-12 20:24:50 +00:00
}
else {
if ($config{'home_base'}) {
2008-08-16 00:50:56 +00:00
# Can be automatic
2007-04-12 20:24:50 +00:00
local $grp = &my_getgrgid($uinfo{'gid'});
2008-08-21 20:37:37 +00:00
local $hb = $n eq "" ||
&auto_home_dir($config{'home_base'},
$uinfo{'user'}, $grp) eq $uinfo{'home'};
2008-08-16 00:50:56 +00:00
$homefield = &ui_radio("home_base", $hb ? 1 : 0,
2008-08-22 01:29:11 +00:00
[ [ 1, $text{'uedit_auto'}."<br>" ],
[ 0, $text{'uedit_manual'}." ".
&ui_filebox("home", $hb ? "" : $uinfo{'home'},
40, 0, undef, undef, 1) ] ]);
2007-04-12 20:24:50 +00:00
}
else {
2008-08-16 00:50:56 +00:00
# Allow any directory
$homefield = &ui_filebox("home", $uinfo{'home'}, 25, 0,
undef, undef, 1);
2007-04-12 20:24:50 +00:00
}
}
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'home'}, "home"),
$homefield);
2007-04-12 20:24:50 +00:00
# Show shell drop-down
2009-03-24 19:27:16 +00:00
push(@shlist, $uinfo{'shell'}) if ($n ne "" && $uinfo{'shell'});
2007-04-12 20:24:50 +00:00
if ($access{'shells'} ne "*") {
# Limit to shells from ACL
2009-03-24 19:27:16 +00:00
@shlist = $n ne "" ? ($uinfo{'shell'}) : ();
2007-04-12 20:24:50 +00:00
push(@shlist, split(/\s+/, $access{'shells'}));
$shells = 1;
}
$shells = 1 if ($access{'noother'});
@shlist = &unique(@shlist);
2009-03-24 19:27:16 +00:00
if ($n ne "" && !$uinfo{'shell'}) {
# No shell!
push(@shlist, [ "", "&lt;None&gt;" ]);
}
2008-08-16 00:50:56 +00:00
push(@shlist, [ "*", $text{'uedit_other'} ]) if (!$shells);
2008-11-01 17:09:27 +00:00
$firstshell = ref($shlist[0]) ? $shlist[0]->[0] : $shlist[0];
2008-08-16 00:50:56 +00:00
print &ui_table_row(&hlink($text{'shell'}, "shell"),
2008-11-01 17:09:27 +00:00
&ui_select("shell", $n eq "" ? $config{'default_shell'} || $firstshell
: $uinfo{'shell'},
\@shlist, 1, 0, 0, 0,
2008-08-21 20:37:37 +00:00
"onChange='form.othersh.disabled = form.shell.value != \"*\"'").
2008-11-01 17:09:27 +00:00
($shells ? "" : &ui_filebox("othersh", undef, 40, 1)));
2007-04-12 20:24:50 +00:00
2008-08-21 20:37:37 +00:00
# Get the password, generate random if needed
2016-05-27 17:50:40 -07:00
$pass = $in{'clone'} ne "" ? $uinfo{'pass'} :
$n ne "" ? $uinfo{'pass'} : $config{'lock_string'};
2009-03-24 19:27:16 +00:00
if ($n eq "" && $config{'random_password'}) {
$random_password = &generate_random_password();
2007-04-12 20:24:50 +00:00
}
2008-08-21 20:37:37 +00:00
2008-06-10 00:12:14 +00:00
# Check if temporary locking is supported
if (&supports_temporary_disable()) {
2009-03-24 19:27:16 +00:00
if ($n ne "" && $pass ne $config{'lock_string'} && $pass ne "") {
2008-06-10 00:12:14 +00:00
# Can disable if not already locked, or if a new account
$can_disable = 1;
if ($pass =~ /^\Q$disable_string\E/) {
$disabled = 1;
$pass =~ s/^\Q$disable_string\E//;
}
}
2009-03-24 19:27:16 +00:00
elsif ($n eq "") {
2008-06-10 00:12:14 +00:00
$can_disable = 1;
2007-04-12 20:24:50 +00:00
}
}
2008-08-21 20:37:37 +00:00
# Show password field
2025-01-27 21:55:06 -08:00
$passmode = $random_password ne "" ? 3 :
$pass eq "" ? 0 :
$pass eq $config{'lock_string'} ? 1 :
$pass && $pass ne $config{'lock_string'} ? 2 : -1;
2008-08-21 20:37:37 +00:00
$pffunc = $config{'passwd_stars'} ? \&ui_password : \&ui_textbox;
2025-01-27 21:44:53 -08:00
my @modes;
2023-04-27 23:11:55 +03:00
if ($passmode eq '0' || $config{'empty_mode'}) {
2025-01-27 21:44:53 -08:00
push(@modes, [ 0, $config{'empty_mode'} ? $text{'none1'} : $text{'none2'} ]);
2023-04-27 23:11:55 +03:00
}
2025-01-27 21:44:53 -08:00
push(@modes,[ 1, $text{'nologin'} ],
2008-08-21 20:37:37 +00:00
[ 3, $text{'clear'},
&$pffunc("pass", $config{'random_password'} && $n eq "" ?
$random_password : "", 15, undef, undef,
'autocomplete="off" autocorrect="off" '.
'autocapitalize="none"') ],
2008-08-21 20:37:37 +00:00
$access{'nocrypt'} ?
( [ 2, $text{'nochange'},
&ui_hidden("encpass", $pass) ] ) :
( [ 2, $text{'encrypted'},
2023-04-27 23:11:55 +03:00
&ui_textbox("encpass", $passmode == 2 ? $pass : "", 60) ] ));
print &ui_table_row(&hlink($text{'pass'}, "pass"),
2025-01-27 21:44:53 -08:00
&ui_radio_table("passmode", $passmode, \@modes).
2008-08-21 20:37:37 +00:00
($can_disable ? "&nbsp;&nbsp;".&ui_checkbox("disable", 1,
2008-08-22 01:29:11 +00:00
$text{'uedit_disabled'}, $disabled) : "")
);
2007-04-12 20:24:50 +00:00
# Show SSH public key field, for new users
if ($n eq '') {
print &ui_table_row(&hlink($text{'sshkey'}, "sshkey"),
&ui_textarea("sshkey", undef, 3, 60), 3);
}
2008-08-21 20:37:37 +00:00
print &ui_table_end();
2007-04-12 20:24:50 +00:00
$pft = &passfiles_type();
if (($pft == 1 || $pft == 6) && $access{'peopt'}) {
2008-08-21 20:37:37 +00:00
# Additional user fields for BSD users
2008-08-22 01:29:11 +00:00
print &ui_table_start($text{'uedit_passopts'}, "width=100%", 4, \@tds);
2008-08-21 20:37:37 +00:00
# Last change date
2007-04-12 20:24:50 +00:00
if ($uinfo{'change'}) {
@tm = localtime($uinfo{'change'});
$cday = $tm[3];
$cmon = $tm[4]+1;
$cyear = $tm[5]+1900;
$chour = sprintf "%2.2d", $tm[2];
$cmin = sprintf "%2.2d", $tm[1];
}
print "<td>";
&date_input($cday, $cmon, $cyear, 'change');
2008-08-21 20:37:37 +00:00
print &ui_table_row(&hlink($text{'change2'}, "change2"),
&date_input($cday, $cmon, $cyear, 'change').
" ".&ui_textbox("changeh", $chour, 3).
2013-03-12 22:24:29 -07:00
":".&ui_textbox("changemi", $cmin, 3), 3);
2007-04-12 20:24:50 +00:00
2008-08-21 20:37:37 +00:00
# Expiry date
2007-04-12 20:24:50 +00:00
if ($n eq "") {
if ($config{'default_expire'} =~
/^(\d+)\/(\d+)\/(\d+)$/) {
$eday = $1;
$emon = $2;
$eyear = $3;
$ehour = "00";
$emin = "00";
}
}
elsif ($uinfo{'expire'}) {
@tm = localtime($uinfo{'expire'});
$eday = $tm[3];
$emon = $tm[4]+1;
$eyear = $tm[5]+1900;
$ehour = sprintf "%2.2d", $tm[2];
$emin = sprintf "%2.2d", $tm[1];
}
2008-08-21 20:37:37 +00:00
print &ui_table_row(&hlink($text{'expire2'}, "expire2"),
&date_input($eday, $emon, $eyear, 'expire').
" ".&ui_textbox("expireh", $ehour, 3).
2013-03-12 22:24:29 -07:00
":".&ui_textbox("expiremi", $emin, 3), 3);
2008-08-21 20:37:37 +00:00
# BSD login class
print &ui_table_row(&hlink($text{'class'}, "class"),
&ui_textbox("class", $uinfo{'class'}, 10));
print &ui_table_end();
2007-04-12 20:24:50 +00:00
}
elsif (($pft == 2 || $pft == 5) && $access{'peopt'}) {
# System has a shadow password file as well.. which means it supports
# password expiry and so on
2008-08-22 01:29:11 +00:00
print &ui_table_start($text{'uedit_passopts'}, "width=100%", 4, \@tds);
2008-06-21 00:50:24 +00:00
# Last change date
2008-06-21 00:50:24 +00:00
local $max = $n eq "" ? $config{'default_max'} : $uinfo{'max'};
2008-08-21 20:37:37 +00:00
print &ui_table_row(&hlink($text{'change'}, "change"),
($uinfo{'change'} ? &make_date(timelocal(
gmtime($uinfo{'change'} * 60*60*24)),1) :
2008-08-21 20:37:37 +00:00
$n eq "" ? $text{'uedit_never'} :
$text{'uedit_unknown'}));
2007-04-12 20:24:50 +00:00
if ($pft == 2) {
2008-08-21 20:37:37 +00:00
# Expiry date
2007-04-12 20:24:50 +00:00
if ($n eq "") {
if ($config{'default_expire'} =~
/^(\d+)\/(\d+)\/(\d+)$/) {
$eday = $1;
$emon = $2;
$eyear = $3;
}
}
elsif ($uinfo{'expire'}) {
2008-08-21 20:37:37 +00:00
@tm = localtime(timelocal(gmtime($uinfo{'expire'} *
60*60*24)));
2007-04-12 20:24:50 +00:00
$eday = $tm[3];
$emon = $tm[4]+1;
$eyear = $tm[5]+1900;
}
2008-08-21 20:37:37 +00:00
print &ui_table_row(&hlink($text{'expire'}, "expire"),
&date_input($eday, $emon, $eyear, 'expire'));
2007-04-12 20:24:50 +00:00
}
else {
2008-08-21 20:37:37 +00:00
# Ask at first login?
print &ui_table_row(&hlink($text{'ask'}, "ask"),
&ui_yesno_radio("ask", $uinfo{'change'} eq '0'));
2007-04-12 20:24:50 +00:00
}
2008-08-21 20:37:37 +00:00
# Minimum and maximum days for changing
print &ui_table_row(&hlink($text{'min'}, "min"),
&ui_textbox("min", $n eq "" ? $config{'default_min'} :
$uinfo{'min'}, 5));
2007-04-12 20:24:50 +00:00
2008-08-21 20:37:37 +00:00
print &ui_table_row(&hlink($text{'max'}, "max"),
&ui_textbox("max", $n eq "" ? $config{'default_max'} :
$uinfo{'max'}, 5));
2007-04-12 20:24:50 +00:00
if ($pft == 2) {
2008-08-21 20:37:37 +00:00
# Warning and inactive days. Only available when full shadow
# files are used
print &ui_table_row(&hlink($text{'warn'}, "warn"),
&ui_textbox("warn", $n eq "" ? $config{'default_warn'}
: $uinfo{'warn'}, 5));
print &ui_table_row(&hlink($text{'inactive'}, "inactive"),
&ui_textbox("inactive", $n eq "" ?
$config{'default_inactive'} :
$uinfo{'inactive'}, 5));
}
2008-08-21 20:37:37 +00:00
# Force change at next login
if (($max || $gconfig{'os_type'} =~ /-linux$/) && $pft == 2) {
print &ui_table_row(
&hlink($text{'uedit_forcechange'}, 'forcechange'),
&ui_yesno_radio("forcechange", 0));
2007-04-12 20:24:50 +00:00
}
2008-08-21 20:37:37 +00:00
print &ui_table_end();
2007-04-12 20:24:50 +00:00
}
elsif ($pft == 4 && $access{'peopt'}) {
# System has extra AIX password information
2008-08-22 01:29:11 +00:00
print &ui_table_start($text{'uedit_passopts'}, "width=100%", 4, \@tds);
2007-04-12 20:24:50 +00:00
2008-08-22 01:29:11 +00:00
# Last change date and time
print &ui_table_row(&hlink($text{'change'}, "change"),
($uinfo{'change'} ? &make_date($uinfo{'change'}) :
$n eq "" ? $text{'uedit_never'} :
$text{'uedit_unknown'}));
2007-04-12 20:24:50 +00:00
2008-10-15 21:53:52 +00:00
if ($uinfo{'expire'} =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/) {
2007-04-12 20:24:50 +00:00
$emon = $1;
$eday = $2;
$ehour = $3;
$emin = $4;
$eyear = $5;
if ($eyear > 38) {
$eyear += 1900;
}
else {
$eyear += 2000;
}
}
$emon =~ s/0(\d)/$1/; # strip leading 0
2008-08-22 01:29:11 +00:00
print &ui_table_row(&hlink($text{'expire'}, "expire"),
2008-10-15 21:53:52 +00:00
&ui_radio("expire_def", $uinfo{'expire'} eq '' ? 1 :
$uinfo{'expire'} eq '0' ? 2 : 0,
[ [ 1, $text{'uedit_sys'} ],
[ 2, $text{'uedit_never'} ],
[ 0, &date_input($eday, $emon, $eyear, 'expire').
" ".&ui_textbox("expireh", $ehour, 3).
2008-10-20 17:52:45 +00:00
"/".&ui_textbox("expiremi", $emin, 3) ] ]), 3);
2008-08-22 01:29:11 +00:00
# Minimum and maximum ages in weeks
print &ui_table_row(&hlink($text{'min_weeks'}, "min_weeks"),
2008-10-20 17:52:45 +00:00
&ui_opt_textbox("min", $uinfo{'min'}, 5, $text{'uedit_sys'}), 3);
2008-08-22 01:29:11 +00:00
print &ui_table_row(&hlink($text{'max_weeks'}, "max_weeks"),
2008-10-20 17:52:45 +00:00
&ui_opt_textbox("max", $uinfo{'max'}, 5, $text{'uedit_sys'}), 3);
2008-08-22 01:29:11 +00:00
# Warning days
print &ui_table_row(&hlink($text{'warn'}, "warn"),
2008-10-20 17:52:45 +00:00
&ui_opt_textbox("warn", $uinfo{'warn'}, 5, $text{'uedit_sys'}), 3);
2008-08-22 01:29:11 +00:00
# AIX-specific flags
print &ui_table_row(&hlink($text{'flags'}, "flags"),
&ui_checkbox("flags", "admin", $text{'uedit_admin'},
$uinfo{'admin'})."<br>".
&ui_checkbox("flags", "admchg", $text{'uedit_admchg'},
$uinfo{'admchg'})."<br>".
&ui_checkbox("flags", "nocheck", $text{'uedit_nocheck'},
2008-10-20 17:52:45 +00:00
$uinfo{'nocheck'}), 3);
2008-08-22 01:29:11 +00:00
print &ui_table_end();
}
# Group memberships section
print &ui_table_start($text{'uedit_gmem'}, "width=100%", 4, \@tds);
# Primary group
@groupopts = ( );
$gidmode = 0;
2007-04-12 20:24:50 +00:00
if ($n eq "" && $access{'gcreate'}) {
2008-08-22 01:29:11 +00:00
# Has option to create a group
push(@groupopts, [ 2, $text{'uedit_samg'} ]);
push(@groupopts, [ 1, $text{'uedit_newg'},
&ui_textbox("newgid", undef, 20) ]);
$gidmode = $config{'new_user_group'} ? 2 : 0;
2007-04-12 20:24:50 +00:00
}
if ($access{'ugroups'} eq "*" || $access{'uedit_gmode'} >= 3) {
2008-08-22 01:29:11 +00:00
# Group can be chosen with popup window
2007-04-12 20:24:50 +00:00
local $w = 300;
local $h = 200;
if ($gconfig{'db_sizeuser'}) {
($w, $h) = split(/x/, $gconfig{'db_sizeuser'});
}
2008-08-22 01:29:11 +00:00
push(@groupopts, [ 0, $text{'uedit_oldg'},
&ui_textbox("gid", $n eq "" ? $config{'default_group'} :
scalar(&my_getgrgid($uinfo{'gid'})), 13)." ".
&popup_window_button("my_group_chooser.cgi?multi=0", $w, $h,
1, [ [ "ifield", "gid", "group" ] ]) ]);
2007-04-12 20:24:50 +00:00
}
else {
2008-08-22 01:29:11 +00:00
# From fixed menu of groups
$cg = $uinfo{'gid'} ? &my_getgrgid($uinfo{'gid'}) : undef;
2008-08-22 01:29:11 +00:00
@gl = &unique($cg ? ($cg) : (),
&split_quoted_string($access{'ugroups'}));
push(@groupopts, [ 0, $text{'uedit_oldg'},
&ui_select("gid", $cg, \@gl) ]);
}
if (@groupopts == 1) {
$groupfield = $groupopts[0]->[2];
}
else {
$groupfield = &ui_radio_table("gidmode", $gidmode, \@groupopts);
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
print &ui_table_row(&hlink($text{'group'}, "group"), $groupfield, 3);
2007-04-12 20:24:50 +00:00
2008-08-22 01:29:11 +00:00
# Work out which secondary groups the user is in
2007-04-12 20:24:50 +00:00
if ($config{'secmode'} != 1) {
@defsecs = &split_quoted_string($config{'default_secs'});
@glist = &list_groups();
2011-12-27 16:10:39 -08:00
@glist = &sort_groups(\@glist, $config{'sort_mode'});
2007-04-12 20:24:50 +00:00
%ingroups = ( );
foreach $g (@glist) {
@mems = split(/,/ , $g->{'members'});
$ismem = &indexof($uinfo{'user'}, @mems) >= 0;
2016-05-27 17:50:40 -07:00
if ($in{'clone'} ne '') {
$ismem ||= &indexof($in{'clone'}, @mems) >= 0;
}
2007-04-12 20:24:50 +00:00
if ($n eq "") {
$ismem = 1 if (&indexof($g->{'group'}, @defsecs) >= 0);
}
$ingroups{$g->{'group'}} = $ismem;
}
}
if ($config{'secmode'} == 0) {
# Show secondary groups with select menu
2008-08-22 01:29:11 +00:00
@canglist = ( );
2007-04-12 20:24:50 +00:00
foreach $g (@glist) {
next if (!&can_use_group(\%access, $g->{'group'}) &&
!$ingroups{$g->{'group'}});
2011-10-19 00:18:32 -02:00
push(@canglist, [ $g->{'group'}, &html_escape($g->{'group'}) ]);
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
@ingroups = map { [ $_, $_ ] } sort { $a cmp $b }
grep { $ingroups{$_} } (keys %ingroups);
$secfield = &ui_multi_select("sgid", \@ingroups, \@canglist, 5, 1, 0,
$text{'uedit_allg'}, $text{'uedit_ing'});
2007-04-12 20:24:50 +00:00
}
elsif ($config{'secmode'} == 2) {
# Show a text box
@insecs = ( );
foreach $g (@glist) {
if ($ingroups{$g->{'group'}}) {
push(@insecs, $g->{'group'});
}
}
2008-08-22 01:29:11 +00:00
$secfield = &ui_textarea("sgid", join("\n", @insecs), 5, 20);
2007-04-12 20:24:50 +00:00
}
else {
# Don't show
2008-08-22 01:29:11 +00:00
$secfield = undef;
}
if ($secfield) {
print &ui_table_row(&hlink($text{'uedit_2nd'}, "2nd"), $secfield, 3);
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
print &ui_table_end();
2007-04-12 20:24:50 +00:00
if ($n ne "") {
# Editing a user - show options for moving home directory, changing IDs
# and updating in other modules
if ($access{'movehome'} == 1 || $access{'chuid'} == 1 ||
$access{'chgid'} == 1 || $access{'mothers'} == 1) {
2008-08-22 01:29:11 +00:00
print &ui_table_start($text{'onsave'}, "width=100%", 2, \@tds);
2007-04-12 20:24:50 +00:00
2007-12-07 18:06:30 +00:00
# Move home directory
2007-04-12 20:24:50 +00:00
if ($access{'movehome'} == 1) {
2007-12-07 18:06:30 +00:00
print &ui_table_row(
&hlink($text{'uedit_movehome'}, "movehome"),
&ui_yesno_radio("movehome", 1));
2007-04-12 20:24:50 +00:00
}
2007-12-07 18:06:30 +00:00
# Change UID on files
2007-04-12 20:24:50 +00:00
if ($access{'chuid'} == 1) {
2007-12-07 18:06:30 +00:00
print &ui_table_row(
&hlink($text{'uedit_chuid'},"chuid"),
&ui_radio("chuid", 1,
[ [ 0, $text{'no'} ],
[ 1, $text{'home'} ],
[ 2, $text{'uedit_allfiles'} ] ]));
2007-04-12 20:24:50 +00:00
}
2007-12-07 18:06:30 +00:00
# Change GID on files
2007-04-12 20:24:50 +00:00
if ($access{'chgid'} == 1) {
2007-12-07 18:06:30 +00:00
print &ui_table_row(
&hlink($text{'uedit_chgid'},"chgid"),
&ui_radio("chgid", 1,
[ [ 0, $text{'no'} ],
[ 1, $text{'home'} ],
[ 2, $text{'uedit_allfiles'} ] ]));
2007-04-12 20:24:50 +00:00
}
2007-12-07 18:06:30 +00:00
# Modify in other modules
2007-04-12 20:24:50 +00:00
if ($access{'mothers'} == 1) {
2007-12-07 18:06:30 +00:00
print &ui_table_row(
&hlink($text{'uedit_mothers'},"others"),
&ui_yesno_radio("others",
$config{'default_other'} ? 1 : 0));
2007-04-12 20:24:50 +00:00
}
2007-12-07 18:06:30 +00:00
# Rename group, if the same and if editable
@ginfo = &my_getgrgid($uinfo{'gid'});
if ($ginfo[0] eq $uinfo{'user'}) {
($group) = grep { $_->{'gid'} == $uinfo{'gid'} }
&list_groups();
if (&can_edit_group(\%access, $group)) {
print &ui_table_row(
&hlink($text{'uedit_grename'},"grename"),
&ui_yesno_radio("grename", 1));
}
}
print &ui_table_end(),"<p>\n";
2007-04-12 20:24:50 +00:00
}
}
else {
# Creating a user - show options for creating home directory, copying
# skel files and creating in other modules
if ($access{'makehome'} == 1 || $access{'copy'} == 1 ||
$access{'cothers'} == 1) {
2008-08-22 01:29:11 +00:00
print &ui_table_start($text{'uedit_oncreate'}, "width=100%",
2, \@tds);
2007-04-12 20:24:50 +00:00
2008-08-22 01:29:11 +00:00
# Create home dir
2007-04-12 20:24:50 +00:00
if ($access{'makehome'} == 1) {
2008-08-22 01:29:11 +00:00
print &ui_table_row(
&hlink($text{'uedit_makehome'}, "makehome"),
&ui_yesno_radio("makehome", 1));
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
# Copy skel files
2007-04-12 20:24:50 +00:00
if ($config{'user_files'} =~ /\S/ && $access{'copy'} == 1) {
2008-08-22 01:29:11 +00:00
print &ui_table_row(
&hlink($text{'uedit_copy'}, "copy_files"),
&ui_yesno_radio("copy_files", 1));
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
# Create in other modules
2007-04-12 20:24:50 +00:00
if ($access{'cothers'} == 1) {
2008-08-22 01:29:11 +00:00
print &ui_table_row(
&hlink($text{'uedit_cothers'},"others"),
&ui_yesno_radio("others",
$config{'default_other'}));
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
print &ui_table_end();
2007-04-12 20:24:50 +00:00
}
}
2008-08-22 01:29:11 +00:00
2007-04-12 20:24:50 +00:00
if ($n ne "") {
2008-08-22 01:29:11 +00:00
# Buttons for saving and other actions
@buts = ( [ undef, $text{'save'} ] );
2007-04-12 20:24:50 +00:00
2008-08-22 01:29:11 +00:00
# List logins by user
push(@buts, [ "list", $text{'uedit_logins'} ]);
2007-04-12 20:24:50 +00:00
2008-08-22 01:29:11 +00:00
# Link to the mailboxes module, if installed
2007-04-12 20:24:50 +00:00
if (&foreign_available("mailboxes") &&
&foreign_installed("mailboxes", 1)) {
2008-08-22 01:29:11 +00:00
push(@buts, [ "mailboxes", $text{'uedit_mail'} ]);
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
# Link to Usermin for switching user
2007-04-12 20:24:50 +00:00
if (&foreign_available("usermin") &&
&foreign_installed("usermin", 1) &&
(%uacl = &get_module_acl("usermin") &&
$uacl{'sessions'})) {
# Link to Usermin module for switching to some user
&foreign_require("usermin", "usermin-lib.pl");
local %uminiserv;
&usermin::get_usermin_miniserv_config(\%uminiserv);
if ($uminiserv{'session'}) {
push(@buts, [ "switch", $text{'uedit_swit'}, undef, 0,
"onClick='form.target=\"_blank\"'" ]);
2007-04-12 20:24:50 +00:00
}
}
2016-05-25 19:15:40 +02:00
# Clone user
if ($access{'ucreate'}) {
2016-05-26 11:33:35 -07:00
push(@buts, [ "clone", $text{'uedit_clone'} ]);
2016-05-25 19:15:40 +02:00
}
2008-08-22 01:29:11 +00:00
# Delete user
2007-04-12 20:24:50 +00:00
if ($access{'udelete'}) {
2008-08-22 01:29:11 +00:00
push(@buts, [ "delete", $text{'delete'} ]);
2007-04-12 20:24:50 +00:00
}
2008-08-22 01:29:11 +00:00
print &ui_form_end(\@buts);
2007-04-12 20:24:50 +00:00
}
else {
2008-08-22 01:29:11 +00:00
# Create button
print &ui_form_end([ [ undef, $text{'create'} ] ]);
2007-04-12 20:24:50 +00:00
}
2008-08-14 18:52:36 +00:00
&ui_print_footer("index.cgi?mode=users", $text{'index_return'});
2007-04-12 20:24:50 +00:00