2024-03-22 04:54:28 +01:00
|
|
|
package SrvMngr::Controller::Emailsettings;
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# heading : System
|
|
|
|
# description : E-mail
|
|
|
|
# navigation : 4000 500
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# routes : end
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
2024-10-18 12:46:27 +02:00
|
|
|
use constant FALSE => 0;
|
|
|
|
use constant TRUE => 1;
|
2024-03-22 04:54:28 +01:00
|
|
|
use Locale::gettext;
|
|
|
|
use SrvMngr::I18N;
|
|
|
|
use SrvMngr qw(theme_list init_session ip_number_or_blank);
|
|
|
|
use esmith::ConfigDB;
|
|
|
|
use esmith::AccountsDB;
|
|
|
|
use esmith::util;
|
|
|
|
use File::Basename;
|
|
|
|
our $pattern_db = esmith::ConfigDB->open("mailpatterns");
|
|
|
|
our $cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
|
|
|
|
|
|
|
sub main {
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info($c->log_req);
|
|
|
|
my %mai_datas = ();
|
2025-01-14 13:49:31 +01:00
|
|
|
my $title = $c->l('mai_FORM_TITLE');
|
2024-03-22 04:54:28 +01:00
|
|
|
$mai_datas{'trt'} = 'LIST';
|
2024-10-18 12:46:27 +02:00
|
|
|
$mai_datas{fetchmailmethod} = $c->l($cdb->get_prop('fetchmail', 'Method'));
|
2025-01-14 13:49:31 +01:00
|
|
|
$c->stash(title => $title, notif => '', mai_datas => \%mai_datas);
|
2024-03-22 04:54:28 +01:00
|
|
|
$c->render(template => 'emailsettings');
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub main
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub do_display {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
my $rt = $c->current_route;
|
|
|
|
my $trt = ($c->param('trt') || 'LIST');
|
2024-03-22 04:54:28 +01:00
|
|
|
my %mai_datas = ();
|
2025-01-14 13:49:31 +01:00
|
|
|
my $title = $c->l('mai_FORM_TITLE');
|
2024-03-22 04:54:28 +01:00
|
|
|
my ($notif, $dest) = '';
|
|
|
|
$mai_datas{'trt'} = $trt;
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($trt eq 'ACC') {
|
|
|
|
$dest = 'emailaccess';
|
|
|
|
$mai_datas{fetchmailmethod} = $cdb->get_prop('fetchmail', 'Method');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'FIL') {
|
|
|
|
$dest = 'emailfilter';
|
|
|
|
$mai_datas{'virusstatus'} = $c->get_virus_status();
|
|
|
|
$mai_datas{'spamstatus'} = $cdb->get_prop('spamassassin', 'status');
|
|
|
|
$mai_datas{'spamsensitivity'} = $cdb->get_prop('spamassassin', 'Sensitivity', 'medium');
|
|
|
|
$mai_datas{'spamtaglevel'} = $cdb->get_prop('spamassassin', 'TagLevel') || '0';
|
|
|
|
$mai_datas{'spamrejectlevel'} = $cdb->get_prop('spamassassin', 'RejectLevel') || '0';
|
|
|
|
$mai_datas{spamsortspam} = $cdb->get_prop('spamassassin', 'SortSpam');
|
|
|
|
$mai_datas{spamsubjecttag} = $cdb->get_prop('spamassassin', 'SubjectTag');
|
|
|
|
$mai_datas{spamsubject} = $cdb->get_prop('spamassassin', 'Subject');
|
|
|
|
} ## end if ($trt eq 'FIL')
|
|
|
|
|
|
|
|
if ($trt eq 'REC') {
|
|
|
|
$dest = 'emailreceive';
|
|
|
|
$mai_datas{fetchmailmethod} = $cdb->get_prop('fetchmail', 'Method');
|
|
|
|
$mai_datas{freqoffice} = $cdb->get_prop('fetchmail', 'FreqOffice');
|
|
|
|
$mai_datas{freqoutside} = $cdb->get_prop('fetchmail', 'FreqOutside');
|
|
|
|
$mai_datas{freqweekend} = $cdb->get_prop('fetchmail', 'FreqWeekend');
|
|
|
|
$mai_datas{secondarymailserver} = $cdb->get_prop('fetchmail', 'SecondaryMailServer');
|
|
|
|
$mai_datas{secondarymailaccount} = $cdb->get_prop('fetchmail', 'SecondaryMailAccount');
|
|
|
|
$mai_datas{secondarymailpassword} = $cdb->get_prop('fetchmail', 'SecondaryMailPassword');
|
|
|
|
$mai_datas{specifyheader} = get_secondary_mail_use_envelope();
|
|
|
|
$mai_datas{secondarymailenvelope} = $cdb->get_prop('fetchmail', 'SecondaryMailEnvelope');
|
|
|
|
} ## end if ($trt eq 'REC')
|
|
|
|
|
|
|
|
if ($trt eq 'DEL') {
|
|
|
|
$dest = 'emaildeliver';
|
|
|
|
$mai_datas{emailunknownuser} = $cdb->get_value('EmailUnknownUser') || '"returntosender';
|
|
|
|
$mai_datas{delegatemailserver} = $cdb->get_value('DelegateMailServer');
|
|
|
|
$mai_datas{smtpsmarthost} = $cdb->get_value('SMTPSmartHost');
|
|
|
|
$mai_datas{smtpauthproxystatus} = $cdb->get_prop('smtp-auth-proxy', 'status') || 'disabled';
|
|
|
|
$mai_datas{smtpauthproxyuserid} = $cdb->get_prop('smtp-auth-proxy', 'Userid') || '';
|
|
|
|
$mai_datas{smtpauthproxypassword} = $cdb->get_prop('smtp-auth-proxy', 'Passwd') || '';
|
|
|
|
} ## end if ($trt eq 'DEL')
|
|
|
|
$c->stash(title => $title, notif => $notif, mai_datas => \%mai_datas);
|
|
|
|
return $c->render(template => $dest);
|
|
|
|
} ## end sub do_display
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub do_update {
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info($c->log_req);
|
2025-01-14 13:49:31 +01:00
|
|
|
my $rt = $c->current_route;
|
|
|
|
my $trt = $c->param('trt');
|
2024-03-22 04:54:28 +01:00
|
|
|
my %mai_datas = ();
|
|
|
|
$mai_datas{trt} = $trt;
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2024-03-22 04:54:28 +01:00
|
|
|
my $title = $c->l('mai_FORM_TITLE');
|
|
|
|
my ($dest, $res, $result) = '';
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($trt eq 'ACC') {
|
|
|
|
$dest = 'emailaccess';
|
|
|
|
|
|
|
|
# $mai_datas{xxx} = $c->param('XXX');
|
|
|
|
# controls
|
|
|
|
# $res = xxxxxxx( $c );
|
|
|
|
# $result .= $res unless $res eq 'OK';
|
|
|
|
if (!$result) {
|
|
|
|
$res = $c->change_settings_access();
|
|
|
|
$result .= $res unless $res eq 'OK';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$result = $c->l('mai_SUCCESS');
|
|
|
|
}
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($trt eq 'ACC')
|
|
|
|
|
|
|
|
if ($trt eq 'FIL') {
|
|
|
|
$dest = 'emailfilter';
|
|
|
|
|
|
|
|
# $mai_datas{xxx} = $c->param('XXX');
|
|
|
|
# controls
|
|
|
|
# $res = zzzzzz( $c );
|
|
|
|
# $result .= $res unless $res eq 'OK';
|
|
|
|
if (!$result) {
|
|
|
|
$res = $c->change_settings_filtering();
|
|
|
|
$result .= $res unless $res eq 'OK';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$result = $c->l('mai_SUCCESS');
|
|
|
|
}
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($trt eq 'FIL')
|
|
|
|
|
|
|
|
if ($trt eq 'REC') {
|
|
|
|
$dest = 'emailreceive';
|
|
|
|
|
|
|
|
# $mai_datas{xxx} = $c->param('XXX');
|
|
|
|
# controls
|
|
|
|
# $res = yyyyyyyyy( $c );
|
|
|
|
# $result .= $res unless $res eq 'OK';
|
|
|
|
if (!$result) {
|
|
|
|
$res = $c->change_settings_reception();
|
|
|
|
$result .= $res unless $res eq 'OK';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$result = $c->l('mai_SUCCESS');
|
|
|
|
}
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($trt eq 'REC')
|
|
|
|
|
|
|
|
if ($trt eq 'DEL') {
|
|
|
|
$dest = 'emaildeliver';
|
|
|
|
|
|
|
|
# $mai_datas{xxx} = $c->param('XXX');
|
|
|
|
# controls
|
|
|
|
$res = $c->ip_number_or_blank($c->param('DelegateMailServer'));
|
|
|
|
$result .= $res . ' DMS <br>' unless $res eq 'OK';
|
|
|
|
$res = $c->validate_smarthost($c->param('SMTPSmartHost'));
|
|
|
|
$result .= $res . ' SH <br>' unless $res eq 'OK';
|
|
|
|
$res = $c->nonblank_if_smtpauth($c->param('SMTPSmartHost'));
|
|
|
|
$result .= $res . ' SH <br>' unless $res eq 'OK';
|
|
|
|
$res = $c->nonblank_if_smtpauth($c->param('SMTPAUTHPROXY_Userid'));
|
|
|
|
$result .= $res . ' USR <br>' unless $res eq 'OK';
|
|
|
|
$res = $c->nonblank_if_smtpauth($c->param('SMTPAUTHPROXY_Passwd'));
|
|
|
|
$result .= $res . ' PWD <br>' unless $res eq 'OK';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$res = $c->change_settings_delivery();
|
|
|
|
$result .= $res unless $res eq 'OK';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$result = $c->l('mai_SUCCESS');
|
|
|
|
}
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($trt eq 'DEL')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# common part
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($res ne 'OK') {
|
|
|
|
$c->stash(error => $result);
|
|
|
|
$c->stash(title => $title, mai_datas => \%mai_datas);
|
|
|
|
return $c->render($dest);
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
my $message = "emailsettings updates $trt DONE";
|
|
|
|
$c->app->log->info($message);
|
2025-01-14 13:49:31 +01:00
|
|
|
$c->flash(success => $result);
|
2024-03-22 04:54:28 +01:00
|
|
|
$c->redirect_to("/emailsettings");
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub do_update
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_virus_status {
|
|
|
|
my ($c, $localise) = @_;
|
|
|
|
my $status = $cdb->get_prop("qpsmtpd", 'VirusScan') || 'disabled';
|
|
|
|
return $localise ? $c->localise_status($status) : $status;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_virus_status
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_spam_status {
|
|
|
|
my ($c, $localise) = @_;
|
|
|
|
my $status = $cdb->get_prop('spamassassin', 'status') || 'disabled';
|
|
|
|
return $localise ? $c->localise_status($status) : $status;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_spam_status
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub localise_status {
|
|
|
|
my ($c, $status) = @_;
|
|
|
|
return $c->l($status eq 'enabled' ? $c->l('ENABLED') : $c->l('DISABLED'));
|
|
|
|
}
|
|
|
|
|
2024-10-18 12:46:27 +02:00
|
|
|
sub get_db_prop {
|
2024-03-22 04:54:28 +01:00
|
|
|
my ($c, $item, $prop, $default) = @_;
|
|
|
|
return $cdb->get_prop($item, $prop) || $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_value {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $item = shift;
|
|
|
|
return $cdb->get_value($item) || '';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_value
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_emailunknownuser_status {
|
|
|
|
my ($c, $localise) = @_;
|
|
|
|
my $options = $c->get_emailunknownuser_options();
|
|
|
|
my $val = $cdb->get_value('EmailUnknownUser') || "returntosender";
|
|
|
|
return $localise ? $c->l($options->{$val}) : $val;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_emailunknownuser_status
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_patterns_status {
|
|
|
|
my ($c, $localise) = @_;
|
|
|
|
my $status = $cdb->get_prop("qpsmtpd", 'PatternsScan') || 'disabled';
|
|
|
|
return $localise ? $c->localise_status($status) : $status;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_patterns_status
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub adjust_patterns {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
my @selected = @{ $c->every_param('BlockExecutableContent') };
|
|
|
|
|
|
|
|
foreach my $pattern ($pattern_db->get_all_by_prop(type => "pattern")) {
|
|
|
|
my $status
|
|
|
|
= (grep $pattern->key eq $_, @selected)
|
|
|
|
? 'enabled'
|
|
|
|
: 'disabled';
|
2024-03-22 04:54:28 +01:00
|
|
|
$pattern->set_prop('Status', $status);
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end foreach my $pattern ($pattern_db...)
|
2024-03-22 04:54:28 +01:00
|
|
|
$pattern_db->reload;
|
|
|
|
return scalar @selected;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub adjust_patterns
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_current_pop3_access {
|
|
|
|
my ($c, $localise) = @_;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $pop3Status = $cdb->get_prop('pop3', 'status') || 'enabled';
|
|
|
|
my $pop3Access = $cdb->get_prop('pop3', 'access') || 'private';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $pop3sStatus = $cdb->get_prop('pop3s', 'status') || 'enabled';
|
|
|
|
my $pop3sAccess = $cdb->get_prop('pop3s', 'access') || 'private';
|
2025-01-14 13:49:31 +01:00
|
|
|
my $options = get_pop_options();
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($pop3Status ne 'enabled' && $pop3sStatus ne 'enabled') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{disabled}) : 'disabled';
|
2025-01-14 13:49:31 +01:00
|
|
|
} elsif ($pop3Status eq 'enabled' && $pop3Access eq 'public') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{public}) : 'public';
|
2025-01-14 13:49:31 +01:00
|
|
|
} elsif ($pop3sStatus eq 'enabled' && $pop3sAccess eq 'public') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{publicSSL}) : 'publicSSL';
|
|
|
|
}
|
|
|
|
return $localise ? $c->l($options->{private}) : 'private';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_current_pop3_access
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_current_imap_access {
|
|
|
|
my ($c, $localise) = @_;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $imapStatus = $cdb->get_prop('imap', 'status') || 'enabled';
|
|
|
|
my $imapAccess = $cdb->get_prop('imap', 'access') || 'private';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $imapsStatus = $cdb->get_prop('imaps', 'status') || 'enabled';
|
|
|
|
my $imapsAccess = $cdb->get_prop('imaps', 'access') || 'private';
|
2025-01-14 13:49:31 +01:00
|
|
|
my $options = get_imap_options();
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($imapStatus ne 'enabled' || $imapAccess eq 'localhost') && $imapsStatus ne 'enabled') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{disabled}) : 'disabled';
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($imapStatus eq 'enabled' && $imapAccess eq 'public') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{public}) : 'public';
|
2025-01-14 13:49:31 +01:00
|
|
|
} elsif ($imapsStatus eq 'enabled' && $imapsAccess eq 'public') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{publicSSL}) : 'publicSSL';
|
|
|
|
}
|
|
|
|
return $localise ? $c->l($options->{private}) : 'private';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_current_imap_access
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2024-10-18 12:46:27 +02:00
|
|
|
sub get_current_smtp_ssl_auth {
|
|
|
|
my ($c, $localise, $soru, $debug) = @_;
|
|
|
|
die "Error: \$soru must be either 's' or 'u':$soru.\n" unless $soru eq 's' || $soru eq 'u';
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2024-10-18 12:46:27 +02:00
|
|
|
|
|
|
|
# Initialize variables with default values
|
|
|
|
my $smtpStatus = 'none';
|
|
|
|
my $smtpAccess = 'none';
|
2025-01-14 13:49:31 +01:00
|
|
|
my $smtpAuth = 'disabled'; # assuming 'disabled' as a default
|
2024-10-18 12:46:27 +02:00
|
|
|
|
|
|
|
# Fetch SMTP settings based on the value of `$soru`
|
|
|
|
if ($soru eq "u") {
|
2025-01-14 13:49:31 +01:00
|
|
|
$smtpStatus = $cdb->get_prop('uqpsmtpd', 'status') || 'enabled'; # Fetch from uqpsmtpd
|
2024-10-18 12:46:27 +02:00
|
|
|
$smtpAccess = $cdb->get_prop('uqpsmtpd', 'access') || 'public';
|
2025-01-14 13:49:31 +01:00
|
|
|
$smtpAuth = 'enabled'; # Assuming authentication is enabled in this context
|
|
|
|
} else {
|
|
|
|
$smtpStatus = $cdb->get_prop('sqpsmtpd', 'status') || 'enabled'; # Fetch from sqpsmtpd
|
|
|
|
$smtpAccess = $cdb->get_prop('sqpsmtpd', 'access') || 'public';
|
|
|
|
$smtpAuth = 'enabled'; # Assuming authentication is enabled in this context
|
2024-10-18 12:46:27 +02:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-10-18 12:46:27 +02:00
|
|
|
# Retrieve SMTP SSL authentication options
|
|
|
|
my $options = $c->get_smtp_ssl_auth_options();
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($soru eq "u" && $debug) {
|
|
|
|
$c->stash('smtp' =>
|
|
|
|
[ $smtpStatus, $smtpAccess, $smtpAuth, $soru, $options->{$smtpAccess}, $c->l($options->{$smtpAccess}) ]
|
|
|
|
);
|
|
|
|
|
|
|
|
# die "Stop $soru in get_current_smtp_ssl_auth";
|
|
|
|
} ## end if ($soru eq "u" && $debug)
|
2024-10-18 12:46:27 +02:00
|
|
|
|
|
|
|
# Return appropriate message based on SMTP settings
|
|
|
|
if ($smtpStatus eq 'enabled' && $smtpAuth eq 'enabled') {
|
|
|
|
return $localise ? $c->l($options->{$smtpAccess}) : $smtpAccess;
|
|
|
|
}
|
|
|
|
return $localise ? $c->l($options->{disabled}) : 'disabled';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_current_smtp_ssl_auth
|
2024-10-18 12:46:27 +02:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
sub get_current_smtp_auth {
|
|
|
|
my ($c, $localise) = @_;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $smtpStatus = $cdb->get_prop('qpsmtpd', 'status') || 'enabled';
|
|
|
|
my $smtpAuth = $cdb->get_prop('qpsmtpd', 'Authentication') || 'enabled';
|
|
|
|
my $options = get_smtp_auth_options();
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($smtpStatus eq 'enabled' && $smtpAuth eq 'disabled') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{public}) : 'public';
|
2025-01-14 13:49:31 +01:00
|
|
|
} elsif ($smtpStatus eq 'enabled' && $smtpAuth eq 'enabled') {
|
2024-03-22 04:54:28 +01:00
|
|
|
return $localise ? $c->l($options->{publicSSL}) : 'publicSSL';
|
|
|
|
}
|
|
|
|
return $localise ? $c->l($options->{disabled}) : 'disabled';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_current_smtp_auth
|
2024-10-18 12:46:27 +02:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
sub get_current_webmail_status {
|
2025-01-14 13:49:31 +01:00
|
|
|
my ($c, $localise) = @_;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# determine status of webmail
|
|
|
|
my $WebmailStatus = "disabled";
|
|
|
|
my $RoundcubeStatus = $cdb->get_prop('roundcube', 'status') || 'disabled';
|
|
|
|
my $MysqlStatus = $cdb->get_prop('mariadb', 'status') || 'disabled';
|
|
|
|
my $PHPStatus = $cdb->get_prop('php81-php-fpm', 'status') || 'disabled';
|
|
|
|
my $Networkaccess = $cdb->get_prop('roundcube', 'access') || 'disabled';
|
|
|
|
|
|
|
|
# all 3 components must be on for webmail to be working
|
|
|
|
if ( ($RoundcubeStatus eq "enabled")
|
|
|
|
&& ($MysqlStatus eq "enabled")
|
|
|
|
&& ($PHPStatus eq "enabled")
|
|
|
|
&& ($Networkaccess eq "public"))
|
2024-03-22 04:54:28 +01:00
|
|
|
{
|
2025-01-14 13:49:31 +01:00
|
|
|
$WebmailStatus = "enabledSSL";
|
|
|
|
} elsif (($RoundcubeStatus eq "enabled")
|
|
|
|
&& ($MysqlStatus eq "enabled")
|
|
|
|
&& ($PHPStatus eq "enabled")
|
|
|
|
&& ($Networkaccess eq "private"))
|
2024-03-22 04:54:28 +01:00
|
|
|
{
|
2025-01-14 13:49:31 +01:00
|
|
|
$WebmailStatus = "localnetworkSSL";
|
|
|
|
} ## end elsif (($RoundcubeStatus ...))
|
|
|
|
my $options = get_webmail_options();
|
|
|
|
return $localise
|
|
|
|
? $c->l($options->{$WebmailStatus})
|
|
|
|
: $WebmailStatus;
|
|
|
|
} ## end sub get_current_webmail_status
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_pop_opt {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
return [
|
|
|
|
[ $c->l('DISABLED') => 'disabled' ],
|
|
|
|
[ $c->l('NETWORKS_ALLOW_LOCAL') => 'private' ],
|
|
|
|
[ $c->l('mai_SECURE_POP3') => 'publicSSL' ],
|
|
|
|
[ $c->l('mai_INSECURE_POP3') => 'public' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_pop_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_pop_options {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = @_;
|
2024-03-22 04:54:28 +01:00
|
|
|
my %options = (
|
2025-01-14 13:49:31 +01:00
|
|
|
disabled => 'DISABLED',
|
|
|
|
private => 'NETWORKS_ALLOW_LOCAL',
|
|
|
|
publicSSL => 'mai_SECURE_POP3'
|
2024-03-22 04:54:28 +01:00
|
|
|
);
|
|
|
|
my $access = $cdb->get_prop('pop3', 'access') || 'private';
|
|
|
|
$options{public} = 'mai_INSECURE_POP3' if ($access eq 'public');
|
|
|
|
\%options;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_pop_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_imap_opt {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
return [
|
|
|
|
[ $c->l('DISABLED') => 'disabled' ],
|
|
|
|
[ $c->l('NETWORKS_ALLOW_LOCAL') => 'private' ],
|
|
|
|
[ $c->l('mai_SECURE_IMAP') => 'publicSSL' ],
|
|
|
|
[ $c->l('mai_INSECURE_IMAP') => 'public' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_imap_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_imap_options {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
2024-03-22 04:54:28 +01:00
|
|
|
my %options = (
|
2025-01-14 13:49:31 +01:00
|
|
|
disabled => 'DISABLED',
|
|
|
|
private => 'NETWORKS_ALLOW_LOCAL',
|
|
|
|
publicSSL => 'mai_SECURE_IMAP'
|
2024-03-22 04:54:28 +01:00
|
|
|
);
|
|
|
|
my $access = $cdb->get_prop('imap', 'access') || 'private';
|
|
|
|
$options{public} = 'mai_INSECURE_IMAP' if ($access eq 'public');
|
|
|
|
\%options;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_imap_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2024-10-18 12:46:27 +02:00
|
|
|
sub get_smtp_auth_opt {
|
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
return [
|
|
|
|
[ $c->l('mai_SECURE_SMTP') => 'publicSSL' ],
|
|
|
|
[ $c->l('Only allow insecure access') => 'public' ],
|
|
|
|
[ $c->l('DISABLED') => 'disabled' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_smtp_auth_opt
|
2024-10-18 12:46:27 +02:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
sub get_smtp_auth_options {
|
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
my %options = (publicSSL => 'mai_SECURE_SMTP', public => 'Only allow insecure access', disabled => 'DISABLED');
|
2024-10-18 12:46:27 +02:00
|
|
|
return \%options;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_smtp_auth_options
|
2024-10-18 12:46:27 +02:00
|
|
|
|
|
|
|
sub get_smtp_ssl_auth_options {
|
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
my %options = (public => 'Allow public access', local => 'Allow local access only', disabled => 'DISABLED');
|
2024-10-18 12:46:27 +02:00
|
|
|
return \%options;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_smtp_ssl_auth_options
|
2024-10-18 12:46:27 +02:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
sub get_smtp_ssl_auth_opt {
|
2024-10-18 12:46:27 +02:00
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
return [
|
|
|
|
[ $c->l('Allow public access') => 'public' ],
|
|
|
|
[ $c->l('Allow local access only') => 'local' ],
|
|
|
|
[ $c->l('DISABLED') => 'disabled' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_smtp_ssl_auth_opt
|
2024-10-18 12:46:27 +02:00
|
|
|
|
|
|
|
sub get_key_by_value {
|
|
|
|
my ($hash_ref, $target_value) = @_;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-10-18 12:46:27 +02:00
|
|
|
# Iterate over the hash
|
|
|
|
while (my ($key, $value) = each %$hash_ref) {
|
|
|
|
return $key if $value eq $target_value;
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
return undef; # Return undef if no match is found
|
|
|
|
} ## end sub get_key_by_value
|
|
|
|
|
2024-10-18 12:46:27 +02:00
|
|
|
sub get_value_by_key {
|
|
|
|
my ($hash_ref, $key) = @_;
|
2025-01-14 13:49:31 +01:00
|
|
|
return $hash_ref->{$key}; # Return the value associated with the key
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_webmail_opt {
|
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
return [
|
|
|
|
[ $c->l('DISABLED') => 'disabled' ],
|
|
|
|
[ $c->l('mai_ENABLED_SECURE_ONLY') => 'enabledSSL' ],
|
|
|
|
[ $c->l('mai_ONLY_LOCAL_NETWORK_SSL') => 'localnetworkSSL' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_webmail_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
sub get_webmail_options {
|
|
|
|
my $c = shift;
|
|
|
|
my %options = (
|
|
|
|
disabled => 'DISABLED',
|
|
|
|
enabledSSL => 'mai_ENABLED_SECURE_ONLY',
|
|
|
|
localnetworkSSL => 'mai_ONLY_LOCAL_NETWORK_SSL'
|
|
|
|
);
|
2024-09-24 18:37:52 +02:00
|
|
|
return \%options;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_webmail_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_retrieval_opt {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
2024-03-22 04:54:28 +01:00
|
|
|
return $cdb->get("SystemMode")->value eq "servergateway-private"
|
2025-01-14 13:49:31 +01:00
|
|
|
? [ $c->l('mai_MULTIDROP') => 'multidrop' ]
|
|
|
|
: [
|
|
|
|
[ $c->l('mai_STANDARD') => 'standard' ],
|
|
|
|
[ $c->l('mai_ETRN') => 'etrn' ],
|
|
|
|
[ $c->l('mai_MULTIDROP') => 'multidrop' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_retrieval_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_emailunknownuser_options {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
my $accounts = esmith::AccountsDB->open_ro();
|
|
|
|
my %existingAccounts = (
|
|
|
|
'admin' => $c->l("mai_FORWARD_TO_ADMIN"),
|
|
|
|
'returntosender' => $c->l("mai_RETURN_TO_SENDER")
|
|
|
|
);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
foreach my $account ($accounts->get_all) {
|
|
|
|
next if $account->key eq 'everyone';
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($account->prop('type') =~ /(user|group|pseudonym)/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$existingAccounts{ $account->key } = $c->l("mai_FORWARD_TO") . " " . $account->key;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end foreach my $account ($accounts...)
|
|
|
|
return (\%existingAccounts);
|
|
|
|
} ## end sub get_emailunknownuser_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_emailunknownuser_opt {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $accounts = esmith::AccountsDB->open_ro();
|
2025-01-14 13:49:31 +01:00
|
|
|
my @existingAccounts
|
|
|
|
= ([ $c->l("mai_FORWARD_TO_ADMIN") => 'admin' ], [ $c->l("mai_RETURN_TO_SENDER") => 'returntosender' ]);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
foreach my $account ($accounts->get_all) {
|
|
|
|
next if $account->key eq 'everyone';
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($account->prop('type') =~ /(user|group|pseudonym)/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
push @existingAccounts, [ $c->l("mai_FORWARD_TO") . " " . $account->key => $account->key ];
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end foreach my $account ($accounts...)
|
|
|
|
return (\@existingAccounts);
|
|
|
|
} ## end sub get_emailunknownuser_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_patterns_opt {
|
|
|
|
my $c = shift;
|
|
|
|
my @options;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
foreach my $pattern ($pattern_db->get_all_by_prop(type => "pattern")) {
|
2024-03-22 04:54:28 +01:00
|
|
|
my %props = $pattern->props;
|
|
|
|
push @options, [ $props{'Description'} => $pattern->key ];
|
|
|
|
}
|
|
|
|
return \@options;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_patterns_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_patterns_current_opt {
|
|
|
|
my $c = shift;
|
|
|
|
my @selected;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
foreach my $pattern ($pattern_db->get_all_by_prop(type => "pattern")) {
|
2024-03-22 04:54:28 +01:00
|
|
|
my %props = $pattern->props;
|
|
|
|
push @selected, $pattern->key if ($props{'Status'} eq 'enabled');
|
|
|
|
}
|
|
|
|
return \@selected;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_patterns_current_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_spam_level_options {
|
2025-01-14 13:49:31 +01:00
|
|
|
return [ 0 .. 20 ];
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_spam_sensitivity_opt {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
return [
|
|
|
|
[ $c->l('mai_VERYLOW') => 'verylow' ],
|
|
|
|
[ $c->l('mai_LOW') => 'low' ],
|
|
|
|
[ $c->l('mai_MEDIUM') => 'medium' ],
|
|
|
|
[ $c->l('mai_HIGH') => 'high' ],
|
|
|
|
[ $c->l('mai_VERYHIGH') => 'veryhigh' ],
|
|
|
|
[ $c->l('mai_CUSTOM') => 'custom' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_spam_sensitivity_opt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub fetchmail_freq {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
return [
|
|
|
|
[ $c->l('mai_NEVER') => 'never' ],
|
|
|
|
[ $c->l('mai_EVERY5MIN') => 'every5min' ],
|
|
|
|
[ $c->l('mai_EVERY15MIN') => 'every15min' ],
|
|
|
|
[ $c->l('mai_EVERY30MIN') => 'every30min' ],
|
|
|
|
[ $c->l('mai_EVERYHOUR') => 'everyhour' ],
|
|
|
|
[ $c->l('mai_EVERY2HRS') => 'every2hrs' ]
|
|
|
|
];
|
|
|
|
} ## end sub fetchmail_freq
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub display_multidrop {
|
|
|
|
my $status = $cdb->get_prop('fetchmail', 'status') || 'disabled';
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# XXX FIXME - WIP
|
2024-03-22 04:54:28 +01:00
|
|
|
# Only display ETRN/multidrop settings if relevant
|
|
|
|
# To do this, we need an "Show ETRN/multidrop settings" button
|
|
|
|
# in standard mode.
|
|
|
|
# return ($status eq 'enabled');
|
2025-01-14 13:49:31 +01:00
|
|
|
return 1;
|
|
|
|
} ## end sub display_multidrop
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub change_settings_reception {
|
|
|
|
my $c = shift;
|
2024-09-24 18:37:52 +02:00
|
|
|
$cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2025-01-14 13:49:31 +01:00
|
|
|
my $FetchmailMethod = ($c->param('FetchmailMethod') || 'standard');
|
|
|
|
my $FetchmailFreqOffice = ($c->param('FreqOffice') || 'every15min');
|
|
|
|
my $FetchmailFreqOutside = ($c->param('FreqOutside') || 'everyhour');
|
|
|
|
my $FetchmailFreqWeekend = ($c->param('FreqWeekend') || 'everyhour');
|
|
|
|
my $SpecifyHeader = ($c->param('SpecifyHeader') || 'off');
|
|
|
|
my $fetchmail
|
|
|
|
= $cdb->get('fetchmail') || $cdb->new_record("fetchmail", { type => "service", status => "disabled" });
|
|
|
|
|
|
|
|
if ($FetchmailMethod eq 'standard') {
|
|
|
|
$fetchmail->set_prop('status', 'disabled');
|
|
|
|
$fetchmail->set_prop('Method', $FetchmailMethod);
|
|
|
|
} else {
|
|
|
|
$fetchmail->set_prop('status', 'enabled');
|
|
|
|
$fetchmail->set_prop('Method', $FetchmailMethod);
|
|
|
|
$fetchmail->set_prop('SecondaryMailServer', $c->param('SecondaryMailServer'))
|
|
|
|
unless ($c->param('SecondaryMailServer') eq '');
|
|
|
|
$fetchmail->set_prop('FreqOffice', $FetchmailFreqOffice);
|
|
|
|
$fetchmail->set_prop('FreqOutside', $FetchmailFreqOutside);
|
|
|
|
$fetchmail->set_prop('FreqWeekend', $FetchmailFreqWeekend);
|
|
|
|
$fetchmail->set_prop('SecondaryMailAccount', $c->param('SecondaryMailAccount'))
|
|
|
|
unless ($c->param('SecondaryMailAccount') eq '');
|
|
|
|
$fetchmail->set_prop('SecondaryMailPassword', $c->param('SecondaryMailPassword'))
|
|
|
|
unless ($c->param('SecondaryMailPassword') eq '');
|
|
|
|
|
|
|
|
if ($SpecifyHeader eq 'on') {
|
|
|
|
$fetchmail->merge_props('SecondaryMailEnvelope' => $c->param('SecondaryMailEnvelope'));
|
|
|
|
} else {
|
2024-03-22 04:54:28 +01:00
|
|
|
$fetchmail->delete_prop('SecondaryMailEnvelope');
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end else [ if ($FetchmailMethod eq...)]
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# Need code here for all 3 options - 25, 465 ad 587
|
|
|
|
# Options for 25 are enabled and disabled
|
|
|
|
# for 465 and 587 are (access) public, local and (status) disabled
|
2024-10-18 12:46:27 +02:00
|
|
|
#my $smtpAuth = ($c->param('SMTPAuth') || 'public');
|
|
|
|
#if ($smtpAuth eq 'public') {
|
2025-01-14 13:49:31 +01:00
|
|
|
#$cdb->set_prop("qpsmtpd", "Authentication", "enabled" );
|
|
|
|
#$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" );
|
2024-10-18 12:46:27 +02:00
|
|
|
#} elsif ($smtpAuth eq 'publicSSL') {
|
2025-01-14 13:49:31 +01:00
|
|
|
#$cdb->set_prop("qpsmtpd", "Authentication", "disabled" );
|
|
|
|
#$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" );
|
2024-10-18 12:46:27 +02:00
|
|
|
#} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
#$cdb->set_prop("qpsmtpd", "Authentication", "disabled" );
|
|
|
|
#$cdb->set_prop("sqpsmtpd", "Authentication", "disabled" );
|
2024-10-18 12:46:27 +02:00
|
|
|
#}
|
2025-01-14 13:49:31 +01:00
|
|
|
my @keys = qw(qpsmtpd uqpsmtpd sqpsmtpd);
|
|
|
|
|
|
|
|
foreach my $key (@keys) {
|
|
|
|
my $param_name
|
|
|
|
= $key eq 'qpsmtpd' ? 'SMTPAuth'
|
|
|
|
: $key eq 'uqpsmtpd' ? 'uSMTPAuth'
|
|
|
|
: 'sSMTPAuth'; # Defaults to 'sSMTPAuth' for 'sqpsmtpd'
|
|
|
|
my $SMTPAuth = $c->param($param_name);
|
|
|
|
|
|
|
|
if ($SMTPAuth eq 'disabled') {
|
|
|
|
$cdb->set_prop($key, 'status', 'disabled');
|
|
|
|
$cdb->set_prop($key, 'access', 'disabled');
|
|
|
|
} else {
|
|
|
|
$cdb->set_prop($key, 'status', 'enabled');
|
|
|
|
|
|
|
|
if ($key eq 'qpsmtpd') {
|
|
|
|
my $auth_status = $SMTPAuth eq 'publicSSL' ? 'enabled' : 'disabled';
|
|
|
|
$cdb->set_prop($key, 'Authentication', $auth_status);
|
|
|
|
$cdb->set_prop($key, 'access', 'public');
|
|
|
|
} else {
|
|
|
|
$cdb->set_prop($key, 'Authentication', 'enabled');
|
|
|
|
my $auth_key = ($key eq 'uqpsmtpd') ? 'uSMTPAuth' : 'sSMTPAuth';
|
|
|
|
my $access_value = $c->param($auth_key) eq 'public' ? 'public' : 'local';
|
|
|
|
$cdb->set_prop($key, 'access', $access_value);
|
|
|
|
} ## end else [ if ($key eq 'qpsmtpd')]
|
|
|
|
} ## end else [ if ($SMTPAuth eq 'disabled')]
|
|
|
|
} ## end foreach my $key (@keys)
|
|
|
|
|
|
|
|
unless (system("/sbin/e-smith/signal-event", "email-update") == 0) {
|
|
|
|
return $c->l('mai_ERROR_UPDATING_CONFIGURATION');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
return 'OK';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub change_settings_reception
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub change_settings_delivery {
|
|
|
|
my ($c) = shift;
|
2024-09-24 18:37:52 +02:00
|
|
|
$cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2024-03-22 04:54:28 +01:00
|
|
|
my $EmailUnknownUser = ($c->param('EmailUnknownUser') || 'returntosender');
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_value('SMTPSmartHost', $c->param('SMTPSmartHost'));
|
2024-03-22 04:54:28 +01:00
|
|
|
$cdb->set_value('DelegateMailServer', $c->param('DelegateMailServer'));
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_value('EmailUnknownUser', $EmailUnknownUser);
|
2024-03-22 04:54:28 +01:00
|
|
|
my $proxy = $cdb->get('smtp-auth-proxy');
|
|
|
|
my %props = $proxy->props;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
for (qw(Userid Passwd status)) {
|
2024-03-22 04:54:28 +01:00
|
|
|
$props{$_} = $c->param("SMTPAUTHPROXY_$_");
|
|
|
|
}
|
|
|
|
$proxy->merge_props(%props);
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless (system("/sbin/e-smith/signal-event", "email-update") == 0) {
|
|
|
|
return $c->l('mai_ERROR_UPDATING_CONFIGURATION');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
return 'OK';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub change_settings_delivery
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub change_settings_access {
|
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2024-03-22 04:54:28 +01:00
|
|
|
my $pop3Access = ($c->param('POPAccess') || 'private');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($pop3Access eq 'disabled') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('pop3', "status", "disabled");
|
|
|
|
$cdb->set_prop('pop3s', "status", "disabled");
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('pop3', "status", "enabled");
|
|
|
|
$cdb->set_prop('pop3s', "status", "enabled");
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($pop3Access eq 'public') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('pop3', "access", "public");
|
|
|
|
$cdb->set_prop('pop3s', "access", "public");
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($pop3Access eq 'publicSSL') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('pop3', "access", "private");
|
|
|
|
$cdb->set_prop('pop3s', "access", "public");
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('pop3', "access", "private");
|
|
|
|
$cdb->set_prop('pop3s', "access", "private");
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
my $imapAccess = ($c->param('IMAPAccess') || 'private');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($imapAccess eq 'disabled') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('imap', "status", "enabled");
|
|
|
|
$cdb->set_prop('imap', "access", "localhost");
|
|
|
|
$cdb->set_prop('imaps', "status", "disabled");
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($imapAccess eq 'public') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('imap', "status", "enabled");
|
|
|
|
$cdb->set_prop('imap', "access", "public");
|
|
|
|
$cdb->set_prop('imaps', "status", "enabled");
|
|
|
|
$cdb->set_prop('imaps', "access", "public");
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($imapAccess eq 'publicSSL') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('imap', "status", "enabled");
|
|
|
|
$cdb->set_prop('imap', "access", "private");
|
|
|
|
$cdb->set_prop('imaps', "status", "enabled");
|
|
|
|
$cdb->set_prop('imaps', "access", "public");
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('imap', "status", "enabled");
|
|
|
|
$cdb->set_prop('imap', "access", "private");
|
|
|
|
$cdb->set_prop('imaps', "status", "enabled");
|
|
|
|
$cdb->set_prop('imaps', "access", "private");
|
|
|
|
} ## end else [ if ($imapAccess eq 'disabled')]
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# Set webmail state in configuration database, and access
|
|
|
|
# type for SSL
|
|
|
|
# PHP and MySQL should always be on, and are enabled by default
|
|
|
|
# We don't do anything with them here.
|
|
|
|
#------------------------------------------------------------
|
|
|
|
my $webmail = ($c->param('WebMail') || 'disabled');
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($webmail eq "enabledSSL") {
|
|
|
|
$cdb->set_prop('php81-php-fpm', "status", "enabled");
|
|
|
|
$cdb->set_prop('mariadb', "status", "enabled");
|
|
|
|
$cdb->set_prop('roundcube', "status", 'enabled');
|
|
|
|
$cdb->set_prop('roundcube', "access", "public");
|
|
|
|
} elsif ($webmail eq "localnetworkSSL") {
|
|
|
|
$cdb->set_prop('php81-php-fpm', "status", "enabled");
|
|
|
|
$cdb->set_prop('mariadb', "status", "enabled");
|
|
|
|
$cdb->set_prop('roundcube', "status", 'enabled');
|
|
|
|
$cdb->set_prop('roundcube', "access", "private");
|
|
|
|
} else {
|
|
|
|
$cdb->set_prop('roundcube', "status", 'disabled');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless (system("/sbin/e-smith/signal-event", "email-update") == 0) {
|
|
|
|
return $c->l('mai_ERROR_UPDATING_CONFIGURATION');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
return 'OK';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub change_settings_access
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub change_settings_filtering {
|
|
|
|
my $c = shift;
|
2024-09-24 18:37:52 +02:00
|
|
|
$cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2025-01-14 13:49:31 +01:00
|
|
|
my $virus_status = ($c->param('VirusStatus') || 'disabled');
|
2024-03-22 04:54:28 +01:00
|
|
|
$cdb->set_prop("qpsmtpd", 'VirusScan', $virus_status);
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
for my $param (
|
|
|
|
qw(
|
|
|
|
status
|
|
|
|
Sensitivity
|
|
|
|
TagLevel
|
|
|
|
RejectLevel
|
|
|
|
SortSpam
|
|
|
|
Subject
|
|
|
|
SubjectTag)
|
|
|
|
)
|
2024-03-22 04:54:28 +01:00
|
|
|
{
|
2025-01-14 13:49:31 +01:00
|
|
|
$cdb->set_prop('spamassassin', $param, $c->param("Spam$param"));
|
|
|
|
} ## end for my $param (qw( status...))
|
2024-03-22 04:54:28 +01:00
|
|
|
my $patterns_status = $c->adjust_patterns() ? 'enabled' : 'disabled';
|
|
|
|
$cdb->set_prop("qpsmtpd", 'PatternsScan', $patterns_status);
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless (system("/sbin/e-smith/signal-event", "email-update") == 0) {
|
|
|
|
return $c->l('mai_ERROR_UPDATING_CONFIGURATION');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
return 'OK';
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub change_settings_filtering
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
#sub blank_or_ip_number {
|
|
|
|
# my ($c, $value) = @_;
|
|
|
|
# return 'OK' unless (defined $value); # undef is blank
|
|
|
|
# return 'OK' if ($value =~ /^$/); # blank is blank
|
|
|
|
# return $c->call_fm_validation("ip_number",$value,''); # otherwise, validate the input
|
|
|
|
#}
|
|
|
|
sub nonblank_if_smtpauth {
|
|
|
|
my ($c, $value) = @_;
|
|
|
|
return "OK" unless ($c->param("SMTPAUTHPROXY_status") eq 'enabled');
|
|
|
|
return ($value =~ /\S+/) ? "OK" : $c->l('mai_VALIDATION_SMTPAUTH_NONBLANK');
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_secondary_mail_use_envelope {
|
|
|
|
my $use_envelope = $cdb->get_prop('fetchmail', 'SecondaryMailEnvelope');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if (defined $use_envelope) {
|
2024-03-22 04:54:28 +01:00
|
|
|
return ('on');
|
|
|
|
} else {
|
|
|
|
return ('off');
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_secondary_mail_use_envelope
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub validate_smarthost {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $fm = shift;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $smarthost = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
return ('OK') if ($smarthost =~ /^(\S+\.\S+)$/);
|
|
|
|
return ('OK') if ($smarthost eq '');
|
2024-03-22 04:54:28 +01:00
|
|
|
return "INVALID_SMARTHOST";
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub validate_smarthost
|
|
|
|
1;
|