226,27 → 226,7 |
set_request_code($request, $code_ignored, "Not interesting in system users"); |
} |
|
sub save_domain |
{ |
my $request = shift @_; |
my $oldName = shift @_; |
my $name = shift @_; |
my $comment = shift @_; |
|
my $res_action = save_to_db($request, "transport", |
{ domain => $oldName }, |
{ domain => $name, comment => $comment, transport => 'virtual:' } ); |
# FIXME: transport => 'procmail:'? |
|
if($res_action eq 'insert' || $res_action eq 'update') { |
return "error" unless(restart_mail_system()); |
} |
|
# FIXME: move maildirs, update users and aliases tables if 'update' |
|
return $res_action; |
} |
|
# FIXME: merge with handle_domain_modify |
sub handle_domain_create |
{ |
my $request = shift @_; |
256,13 → 236,19 |
"comment" => \&validate_comment } ); |
return unless(%params); |
|
my $res_action = save_domain($request, $params{"name"}, |
$params{"name"}, $params{"comment"}); |
my $res_action = save_to_db($request, "transport", |
{ domain => $params{"name"} }, |
{ domain => $params{"name"}, comment => $params{"comment"}, |
transport => 'virtual:' } ); |
|
# FIXME: transport => 'procmail:'? |
|
if($res_action eq 'update') { |
return unless(restart_mail_system()); |
set_request_code($request, $code_ok_but, "Domain exists, modified"); |
} |
elsif($res_action eq 'insert') { |
return unless(restart_mail_system()); |
set_request_code($request, $code_ok, "Domain created"); |
} |
} |
277,13 → 263,19 |
"comment" => \&validate_comment } ); |
return unless(%params); |
|
my $res_action = save_domain($request, $params{"oldName"}, |
$params{"name"}, $params{"comment"}); |
# FIXME: move maildirs, update users and aliases tables |
|
my $res_action = save_to_db($request, "transport", |
{ domain => $params{"oldName"} }, |
{ domain => $params{"name"}, comment => $params{"comment"}, |
transport => 'virtual:' } ); |
|
if($res_action eq 'update') { |
return unless(restart_mail_system()); |
set_request_code($request, $code_ok, "Domain modified"); |
} |
elsif($res_action eq 'insert') { |
return unless(restart_mail_system()); |
set_request_code($request, $code_ok_but, "Domain not found, created"); |
} |
} |
323,7 → 315,6 |
{ mailid => "$id\@$domain" }); |
return 0 if($res_action2 eq "error"); |
|
# create alias loop |
my $res_action3 = save_to_db($request, "aliases", |
{ alias => "$id\@$domain", rcpt => "$id\@$domain" }, |
{ alias => "$id\@$domain", rcpt => "$id\@$domain", |
333,39 → 324,7 |
return 1; |
} |
|
sub save_mailbox |
{ |
my $request = shift @_; |
my $oldLogin = shift @_; |
my $oldDomain = shift @_; |
my $login = shift @_; |
my $domain = shift @_; |
my $password = shift @_; |
my $expired = shift @_; |
my $comment = shift @_; |
my $systemUser = shift @_; |
|
# insert or update main information |
my $id; |
my $res_action = save_to_db($request, "users", |
{ login => "$oldLogin\@$oldDomain" }, |
{ login => "$login\@$domain", |
password => $password, |
maildir => "$domain/$login/", |
expired => $expired, |
comment => $comment, |
uid => $systemUser }, |
\$id); |
|
# set mailid for the new record |
return "error" unless(update_mailbox_mailid($request, $id, $login, $domain)); |
|
# FIXME create an empty maildir if 'insert' |
# FIXME move the old maildir if 'update' |
|
return $res_action; |
} |
|
# FIXME: merge with handle_mailbox_modify |
sub handle_mailbox_create |
{ |
my $request = shift @_; |
380,14 → 339,24 |
"spamCheck" => \&validate_boolean } ); |
return unless(%params); |
|
my $res_action = save_mailbox($request, |
$params{'login'}, $params{'domain'}, |
$params{'login'}, $params{'domain'}, |
$params{"password"}, |
($params{"enabled"} eq "true" ? 0 : 1), |
$params{"comment"}, |
($params{"systemUser"} ? $params{"systemUser"} : undef)); |
# insert or update main information |
my $id; |
my $res_action = save_to_db($request, "users", |
{ login => "$params{'login'}\@$params{'domain'}" }, |
{ login => "$params{'login'}\@$params{'domain'}", |
password => $params{"password"}, |
maildir => "$params{'domain'}/$params{'login'}/", |
expired => ($params{"enabled"} eq "true" ? 0 : 1), |
comment => $params{"comment"}, |
uid => ($params{"systemUser"} ? $params{"systemUser"} : undef) }, |
\$id); |
|
# set mailid for the new record |
return unless(update_mailbox_mailid($request, $id, $params{'login'}, $params{'domain'})); |
|
# FIXME create an empty maildir |
|
# result |
if($res_action eq 'update') { |
set_request_code($request, $code_ok_but, "Mailbox exists, modified"); |
} |
412,14 → 381,24 |
"spamCheck" => \&validate_boolean } ); |
return unless(%params); |
|
my $res_action = save_mailbox($request, |
$params{'oldLogin'}, $params{'oldDomain'}, |
$params{'login'}, $params{'domain'}, |
$params{"password"}, |
($params{"enabled"} eq "true" ? 0 : 1), |
$params{"comment"}, |
($params{"systemUser"} ? $params{"systemUser"} : undef)); |
# FIXME move the old maildir |
|
# insert or update main information |
my $id; |
my $res_action = save_to_db($request, "users", |
{ login => "$params{'oldLogin'}\@$params{'oldDomain'}" }, |
{ login => "$params{'login'}\@$params{'domain'}", |
password => $params{"password"}, |
maildir => "$params{'domain'}/$params{'login'}/", |
expired => ($params{"enabled"} eq "true" ? "0" : "1"), |
comment => $params{"comment"}, |
uid => ($params{"systemUser"} ? $params{"systemUser"} : undef) }, |
\$id); |
|
# set mailid for the new record |
return unless(update_mailbox_mailid($request, $id, $params{'login'}, $params{'domain'})); |
|
# result |
if($res_action eq 'update') { |
set_request_code($request, $code_ok, "Mailbox modified"); |
} |
518,50 → 497,36 |
return 1; |
} |
|
sub save_mail_alias |
# FIXME merge with handle_mail_alias_modify |
sub handle_mail_alias_create |
{ |
my $request = shift @_; |
my $oldAddress = shift @_; |
my $oldDomain = shift @_; |
my $address = shift @_; |
my $domain = shift @_; |
my $comment = shift @_; |
my $rcpts = shift @_; |
my %params = parse_command_params($request, shift @_, |
{ "address" => \&validate_name, |
"domain" => \&validate_domain, |
"enabled" => \&validate_boolean, |
"comment" => \&validate_comment } ); |
return unless(%params); |
my @rcpts = parse_command_array($request, @_); |
|
# validate recipients |
foreach (@$rcpts) { |
foreach (@rcpts) { |
unless(validate_email($_)) { |
set_request_code($request, $code_wrong_params, "Wrong email $_"); |
return "error"; |
return; |
} |
} |
|
# delete all from db |
my $del_action = delete_from_db($request, "aliases", |
{ alias => "$oldAddress\@$oldDomain" } ); |
return "error" if($del_action eq "error"); |
{ alias => "$params{'address'}\@$params{'domain'}" } ); |
return if($del_action eq "error"); |
|
# save new |
return "error" unless(save_mail_alias_dest($request, $address, $domain, |
$comment, $rcpts)); |
return unless(save_mail_alias_dest($request, $params{'address'}, $params{'domain'}, |
$params{'comment'}, \@rcpts)); |
|
return $del_action; |
} |
|
sub handle_mail_alias_create |
{ |
my $request = shift @_; |
my %params = parse_command_params($request, shift @_, |
{ "address" => \&validate_name, |
"domain" => \&validate_domain, |
"enabled" => \&validate_boolean, |
"comment" => \&validate_comment } ); |
return unless(%params); |
my @rcpts = parse_command_array($request, @_); |
|
my $del_action = save_mail_alias($request, $params{'address'}, $params{'domain'}, |
$params{'address'}, $params{'domain'}, $params{'comment'}, \@rcpts); |
|
# result |
if($del_action eq 'delete') { |
set_request_code($request, $code_ok_but, "Mail alias exists, modified"); |
} |
583,9 → 548,24 |
return unless(%params); |
my @rcpts = parse_command_array($request, @_); |
|
my $del_action = save_mail_alias($request, $params{'oldAddress'}, $params{'oldDomain'}, |
$params{'address'}, $params{'domain'}, $params{'comment'}, \@rcpts); |
# validate recipients |
foreach (@rcpts) { |
unless(validate_email($_)) { |
set_request_code($request, $code_wrong_params, "Wrong email $_"); |
return; |
} |
} |
|
# delete all from db |
my $del_action = delete_from_db($request, "aliases", |
{ alias => "$params{'oldAddress'}\@$params{'oldDomain'}" } ); |
return if($del_action eq "error"); |
|
# save new |
return unless(save_mail_alias_dest($request, $params{'address'}, $params{'domain'}, |
$params{'comment'}, \@rcpts)); |
|
# result |
if($del_action eq 'delete') { |
set_request_code($request, $code_ok, "Mail alias modified"); |
} |
622,13 → 602,13 |
sub validate_comment |
{ |
$_ = shift @_; |
return /^[^\0-\10\13\14\16-\31]*$/ ? 1 : 0; # deny control chars expect \n \r and \t |
return /^.*$/ ? 1 : 0; # FIXME allow part of control chars only |
} |
|
sub validate_password |
{ |
$_ = shift @_; |
return /^[A-Za-z0-9.\/]{13}$/ ? 1 : 0; # crypt password |
return /^.*$/ ? 1 : 0; # FIXME |
} |
|
sub validate_domain |
661,7 → 641,7 |
$_ = shift @_; |
return 0 unless /^[0-9]*$/; |
|
return ($_ eq '' || $_ >= 1000) ? 1 : 0; # additional security check |
return ($_ >= 1000) ? 1 : 0; # additional security check |
} |
|
sub decode_param |
936,7 → 916,7 |
sub strip_request_password |
{ |
$_ = shift @_; |
s/^$password_header.*$/$password_header*****/gm; |
s/^password=.*$/password=*****/gm; |
return $_; |
} |
|