19,6 → 19,8 |
|
# == configuration ============================= |
|
my $base_dir = dirname($0); |
|
our $host = '127.0.0.1'; |
our $port; |
our $password; |
26,8 → 28,9 |
our $db_user; |
our $db_password; |
our $log_level = 0; # 0 - none, 9 - all |
our $sudo = '/usr/local/bin/sudo'; # path to sudo |
|
my $config_name = dirname($0) . "/backend.conf"; |
my $config_name = "$base_dir/backend.conf"; |
require "$config_name"; # read the config |
|
# == constants ================================= |
63,6 → 66,7 |
my $code_db_error = 502; |
my $code_db_close_error = 503; |
my $code_db_inconsistent = 504; |
my $code_exec_error = 505; |
|
# == internal global variables ================= |
|
70,6 → 74,8 |
my $database_connection; |
my $database_in_use = 0; |
|
# == functions ================================= |
|
sub connection_loop |
{ |
# listen for connections |
236,13 → 242,16 |
my $res_action = save_to_db($request, "transport", |
{ domain => $oldName }, |
{ domain => $name, comment => $comment, transport => 'virtual:' } ); |
# FIXME: transport => 'procmail:'? |
# FIXME: transport => 'procmail:'? then restart mail system by transport change too |
|
if($res_action eq 'insert' || $res_action eq 'update') { |
if($res_action eq 'insert' || ($res_action eq 'update' && $name ne $oldName)) { |
return "error" unless(restart_mail_system()); |
} |
|
# FIXME: move maildirs, update users and aliases tables if 'update' |
if($oldName ne $name) { |
my $call_res = call_external_script($request, 'delete_domain.sh', [ $oldName ]); |
log_debug("delete_domain.sh: $call_res"); |
} |
|
return $res_action; |
} |
295,11 → 304,14 |
{ "name" => \&validate_domain } ); |
return unless(%params); |
|
# FIXME: delete maildirs, update users and aliases tables (or are they already deleted by frontend?) |
|
my $res_action = delete_from_db($request, "transport", |
{ domain => $params{"name"} } ); |
|
if($res_action ne 'error') { |
my $call_res = call_external_script($request, 'delete_domain.sh', [ $params{"name"} ]); |
log_debug("delete_domain.sh: $call_res"); |
} |
|
if($res_action eq 'delete') { |
return unless(restart_mail_system()); |
set_request_code($request, $code_ok, "Domain deleted"); |
360,8 → 372,9 |
# 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' |
my $call_res = call_external_script($request, 'move_mailbox.sh', |
[ (defined($systemUser) ? $systemUser : ""), "$oldDomain/$oldLogin", "$domain/$login" ]); |
log_debug("move_mailbox.sh: $call_res"); |
|
return $res_action; |
} |
436,7 → 449,9 |
"domain" => \&validate_domain } ); |
return unless(%params); |
|
# FIXME remove the maildir |
my $call_res = call_external_script($request, 'delete_mailbox.sh', |
[ "$params{'domain'}/$params{'login'}" ]); |
log_debug("delete_mailbox.sh: $call_res"); |
|
# get mailid |
my $dbh = db_begin($request); |
735,7 → 750,8 |
{ |
my $request = shift @_; |
|
log_debug("Mail system restarted"); |
my $call_res = call_external_script($request, 'restart_mail_system.sh'); |
log_debug("restart_mail_system.sh: $call_res"); |
|
return 1; |
} |
933,10 → 949,34 |
return $res_action; |
} |
|
sub call_external_script |
{ |
my $request = shift @_; |
my $script = shift @_; |
my $params = shift @_; |
|
my @args; |
push @args, "$base_dir/$script"; |
push @args, @$params if($params); |
|
my $res = system($sudo, @args); |
if($res == -1) { |
set_request_code($request, $code_exec_error, "Cannot execute script: $!"); |
return undef; |
} |
elsif($res & 127) { |
set_request_code($request, $code_exec_error, "Script died with signal " . ($res & 127)); |
return undef; |
} |
else { |
return ($res >> 8); |
} |
} |
|
sub strip_request_password |
{ |
$_ = shift @_; |
s/^$password_header.*$/$password_header*****/gm; |
s/^$password_header.*$/$password_header*****/gm; # comment this line out to see password in log |
return $_; |
} |
|