1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
#!/usr/local/bin/perl
# edit_user.cgi
# Display a form for editing or adding a user. This can be a local user,
# or a domain mailbox user
require './virtual-server-lib.pl';
&ReadParse();
if ($in{'dom'}) {
$d = &get_domain($in{'dom'});
&can_edit_domain($d) || &error($text{'users_ecannot'});
}
else {
$access{'local'} || &error($text{'users_ecannot2'});
}
$din = $d ? &domain_in($d) : undef;
if ($in{'new'}) {
&ui_print_header($din, $text{'user_create'}, "");
$user = &create_initial_user($d);
}
else {
&ui_print_header($din, $text{'user_edit'}, "");
@users = &list_domain_users($d);
($user) = grep { $_->{'user'} eq $in{'user'} &&
$_->{'unix'} == $in{'unix'} } @users;
$mailbox = $d && $d->{'user'} eq $user->{'user'} && $user->{'unix'};
}
print &check_clicks_function();
print "<form action=save_user.cgi>\n";
print "<input type=hidden name=new value='$in{'new'}'>\n";
print "<input type=hidden name=dom value='$in{'dom'}'>\n";
print "<input type=hidden name=old value='$in{'user'}'>\n";
print "<input type=hidden name=unix value='$in{'unix'}'>\n";
print "<table border>\n";
print "<tr $tb> <td><b>",$mailbox ? $text{'user_mheader'} :
$d ? $text{'user_header'} : $text{'user_lheader'},
"</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print "<tr> <td><b>",&hlink($text{'user_user'}, "username"),"</b></td>\n";
if ($mailbox) {
print "<td><tt>$user->{'user'}</tt></td> </tr>\n";
$pop3 = $user->{'user'};
}
else {
$pop3 = $d && !$user->{'noappend'} ?
&remove_userdom($user->{'user'}, $d) : $user->{'user'};
print "<td><input name=user size=13 value='$pop3'>",
$d ? "\@$d->{'dom'}\n" : "\n";
if ($pop3 ne $user->{'user'}) {
print " ",&text('user_pop3', "<tt>$user->{'user'}</tt>");
}
print "</td> </tr>\n";
print "<input type=hidden name=oldpop3 value='$pop3'>\n";
}
# Real name - only for true Unix users or LDAP persons
if ($user->{'person'}) {
print "<tr> <td><b>",&hlink($text{'user_real'}, "realname"),"</b></td>\n";
if ($mailbox) {
print "<td>$user->{'real'}</td> </tr>\n";
}
else {
print "<td><input name=real size=25 value='$user->{'real'}'></td> </tr>\n";
}
}
# Password cannot be edited for domain owners (because it is the domain pass)
if (!$mailbox) {
print "<tr> <td><b>",&hlink($text{'user_pass'}, "password"),"</b></td>\n";
if ($in{'new'}) {
print "<td><input name=pass type=password size=13></td> </tr>\n";
}
else {
print "<td><input type=radio name=pass_def value=1 checked> ",
"$text{'user_passdef'}\n";
if (defined($user->{'plainpass'})) {
print "($user->{'plainpass'})\n";
}
print "<input type=radio name=pass_def value=0> $text{'user_passset'}\n";
print "<input name=pass type=password size=13></td> </tr>\n";
}
}
if ((&master_admin() || $config{'edit_homes'}) && $d && $d->{'home'} &&
!$mailbox && !$user->{'fixedhome'}) {
# Show home directory editing field
local $auto = $in{'new'} || $user->{'home'} eq "$d->{'home'}/$config{'homes_dir'}/$pop3";
print "<tr> <td><b>", &hlink($text{'user_home'}, "userhome"), "</b></td>\n";
printf "<td><input type=radio name=home_def value=1 %s> %s\n",
$auto ? "checked" : "", $text{'user_home1'};
printf "<input type=radio name=home_def value=0 %s> %s\n",
$auto ? "" : "checked", &text('user_homeunder');
printf "<input name=home size=20 value='%s'></td> </tr>\n",
$auto ? "" : substr($user->{'home'}, length($d->{'home'})+1);
}
if ((&master_admin() || $config{'edit_ftp'}) && !$mailbox && $user->{'unix'}) {
# Show FTP shell field
print "<tr> <td><b>", &hlink($text{'user_ftp'}, "ftp"), "</b></td>\n";
$ftp = $user->{'qmail'} && !$user->{'shell'} ? -2 :
$user->{'shell'} eq $config{'ftp_shell'} ? 1 :
$config{'jail_shell'} &&
$user->{'shell'} eq $config{'jail_shell'} ? 2 :
$in{'new'} || $user->{'shell'} eq $config{'shell'} ? 0 : -1;
print "<td>";
if ($ftp == -1) {
print &text('user_shell', "<tt>$user->{'shell'}</tt>");
}
elsif ($ftp == -2) {
print &text('user_qmail');
}
else {
printf "<input type=radio name=ftp value=1 %s> %s\n",
$ftp == 1 ? "checked" : "", $text{'yes'};
if ($config{'jail_shell'}) {
printf "<input type=radio name=ftp value=2 %s> %s\n",
$ftp == 2 ? "checked" : "", $text{'user_jail'};
}
printf "<input type=radio name=ftp value=0 %s> %s\n",
$ftp == 0 ? "checked" : "", $text{'no'};
}
print "</td> </tr>\n";
}
# Find and show all plugin features
foreach $f (@mail_plugins) {
$input = &plugin_call($f, "mailbox_inputs", $user, $in{'new'}, $d);
print $input;
}
print "<tr> <td colspan=2><hr></td> </tr>\n";
if ($d && !$user->{'noprimary'}) {
# Show primary email address field
print "<tr> <td><b>", &hlink($text{'user_mailbox'}, "mailbox"), "</b></td>\n";
printf "<td><input type=radio name=mailbox value=1 %s> %s\n",
$user->{'email'} || $in{'new'} ? "checked" : "", $text{'yes'};
printf "<input type=radio name=mailbox value=0 %s> %s</td> </tr>\n",
$user->{'email'} || $in{'new'} ? "" : "checked", $text{'no'};
}
if ($user->{'mailquota'}) {
# Show Qmail/VPOPMail quota field
print "<tr> <td><b>",&hlink($text{'user_qquota'},"qmailquota"),"</b></td>\n";
print "<td>",&ui_radio("qquota_def", $user->{'qquota'} ? 0 : 1,
[ [ 1, $text{'form_unlimit'} ],
[ 0, " " ] ]);
print &ui_textbox("qquota", $user->{'qquota'} || "", 10)," ",
$text{'form_bytes'},"</td> </tr>\n";
}
if (!$mailbox && $user->{'unix'}) {
# Show quotas field(s)
$qsame = $config{'home_quotas'} eq $config{'mail_quotas'};
if ($config{'home_quotas'}) {
print "<tr> <td><b>", &hlink($qsame ? $text{'user_umquota'} : $text{'user_uquota'}, "diskquota"), "</b></td>\n";
"a_field("quota", $user->{'quota'}, $user->{'uquota'},
$config{'home_quotas'});
}
if ($config{'mail_quotas'} && !$qsame) {
print "<tr> <td><b>", &hlink($text{'user_mquota'}, "diskmquota"), "</b></td>\n";
"a_field("mquota", $user->{'mquota'}, $user->{'umquota'},
$config{'mail_quotas'});
}
}
if (!$in{'new'}) {
local ($sz, $umf) = &mail_file_size($user);
print "<tr> <td>",
&hlink("<b>$text{'user_mail'}</b>", "mailfile"),"</td>\n";
local $link = &read_mail_link($user, $d);
print "<td><tt>$umf</tt>\n";
if ($link) { print "<a href='$link'>$text{'user_read'}</a></td>\n"; }
print "</tr>\n";
}
print "<tr> <td valign=top>",
&hlink("<b>$text{'user_extra'}</b>", "extraemail"),"</td>\n";
print "<td><textarea name=extra rows=5 cols=30>\n";
foreach $e (@{$user->{'extraemail'}}) {
print "$e\n";
}
print "</textarea></td> </tr>\n";
# Show address for confirmation email
if ($in{'new'} && &will_send_user_email($d)) {
print "<tr> <td><b>",&hlink($text{'user_newmail'},"newmail"),"</b></td>\n";
printf "<td><input type=radio name=newmail_def value=1 %s> %s\n",
"checked", $text{'user_newmail1'};
printf "<input type=radio name=newmail_def value=0 %s> %s\n",
"", $text{'user_newmail0'};
print "<input name=newmail size=20></td> </tr>\n";
}
# Show forwarding setup for this user
print "<tr> <td colspan=2><hr></td> </tr>\n";
&alias_form($user->{'to'},
&hlink("<b>$text{'user_aliases'}</b>", "userdest"),
$d, "user", $in{'user'});
print "</table></td></tr></table>\n";
print "<table><tr>\n";
if ($in{'new'}) {
print "<td><input type=submit value='$text{'create'}'></td>\n";
}
else {
print "<td><input type=submit value='$text{'save'}'></td>\n";
print "<td><input type=submit name=delete ",
"value='$text{'delete'}' onClick='check_clicks(form)'></td>\n"
if (!$mailbox);
}
print "</table></form>\n";
if ($d) {
if ($single_domain_mode) {
&ui_print_footer("list_users.cgi?dom=$in{'dom'}", $text{'users_return'},
"", $text{'index_return2'});
}
else {
&ui_print_footer("list_users.cgi?dom=$in{'dom'}", $text{'users_return'},
"edit_domain.cgi?dom=$in{'dom'}", $text{'edit_return'},
"", $text{'index_return'});
}
}
else {
&ui_print_footer("", $text{'index_return'});
}
# quota_field(name, value, used, filesystem)
sub quota_field
{
local @defmquota = split (/ /,$config{'defmquota'});
if (&master_admin() || $config{'edit_quota'}) {
# Show inputs for editing quotas
printf "<td><input type=radio name=%s_def value=1 %s> %s\n",
$_[0], $_[1] || $in{'new'} ? "" : "checked", $text{'form_unlimit'};
printf "<input type=radio name=%s_def value=0 %s>\n",
$_[0], $_[1] || $in{'new'} ? "checked" : "";
if (!$in{'new'}) {
print "a_input($_[0], $_[1] || "", $_[3]),"\n";
print &text('user_used', "a_show($_[2], $_[3])),"\n";
}
else {
if ( !@defmquota or $#defmquota eq 0 ) {
print "a_input($_[0], $config{'defmquota'} || "", $_[3]),"\n";
} else {
print "<select name=$_[0]>\n";
foreach $i (@defmquota) {
chomp $i;
print "<option value=\"$i\">$i</option>\n";
}
print "<option value=\"-1\">$text{'other'}</option></select>\n";
print "<input name=other$_[0] size=15> $text{'form_b'}\n";
}
}
print "</td> </tr>\n";
}
else {
# Just show current settings, or default
print "<td>";
local $q = $in{'new'} ? $defmquota[0] : $_[1];
print ($q ? "a_show($q, $_[3]) : $text{'form_unlimit'}),"\n";
print &text('user_used', "a_show($_[2], $_[3])) if (!$in{'new'});
print "</td> </tr>\n";
}
}
|