Files
SM2Gen/output/Emailsettings/Emailsettings-Custom.new.pm

1171 lines
41 KiB
Perl
Raw Normal View History

#
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20
#
#
# Routines to be edited by the developer to provide content and validation for parameters
# and provison of the control data for table(s)
#
use esmith::util;
use esmith::util::network;
use esmith::ConfigDB::UTF8;
use esmith::AccountsDB;
use esmith::NetworksDB::UTF8;
use esmith::HostsDB;
use esmith::DomainsDB::UTF8;
use Data::Validate::IP qw(is_ipv4 is_ipv6);
use constant FALSE => 0;
use constant TRUE => 1;
#The most common ones - open DB when required.
our $cdb;
my $adb;
my $ndb;
my $hdb;
my $ddb;
#The most common ones - you might want to use these if you need to make sure that the DB is refreshed.
#$cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
#$adb = esmith::AccountsDB->open() || die(\"Couldn"t open Accounts db");
#$ndb = esmith::NetworksDB->open() || die("Couldn"t open Network db\");
#$hdb = esmith::HostsDB::UTF8->open() || die(\"Couldn"t open Hosts db");
#$ddb = esmith::DomainsDB::UTF8->open() || die("Couldn"t open Domains db\");
# Validation routines - parameters for each panel
sub validate_FRONT {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
# Validation for each field
my $ret = "";
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub validate_ACC {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
# Validation for each field
my $ret = "";
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub validate_FIL {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
# Validation for each field
my $ret = "";
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub validate_REC {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
# Validation for each field
my $ret = "";
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub validate_DEL {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
# Validation for each field
my ($retult,$ret) = "";
CHECKS: {
$ret = $c->validate_ip_or_blank($c->param("DelegateMailServer"));
$c->app->log->info(\"$c->param("DelegateMailServer") $ret\");
if ($ret ne "ok") {
#$retult = $c->l($ret);
last CHECKS;
}
$ret = $c->validate_smarthost($c->param("SMTPSmartHost"));
if ($ret ne "ok") {
#$retult = $c->l($ret);
last CHECKS;
}
$ret = $c->nonblank_if_smtpauth($c->param("SMTPSmartHost"));
if ($ret ne "ok") {
#$retult = $c->l($ret);
last CHECKS;
}
$ret = $c->nonblank_if_smtpauth($c->param("SMTPAUTHPROXY_Userid"));
if ($ret ne "ok") {
#$retult = $c->l($ret);
last CHECKS;
}
$ret = $c->nonblank_if_smtpauth($c->param("SMTPAUTHPROXY_Passwd"));
if ($ret ne "ok") {
#$retult = $c->l($ret);
last CHECKS;
}
$ret = $c->change_settings_delivery();
if ($ret ne "ok") {
#$retult = $ret;
last CHECKS;
}
#$result = "";
}
# $ret now contains the first error or the null (success) message
if ($ret eq "") {$ret = "ok";}
return $ret;
}
# Get singleton data for each panel
sub get_data_for_panel_FRONT {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
my %ret = (
"Data1"=>"Data for FRONT", #Example
# fields from Inputs in FRONT $fields["FRONT"]
"fetchmailmethod" => $cdb->get_prop("fetchmail", "Method"),
);
return %ret;
}
sub get_data_for_panel_ACC {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
my %ret = (
# fields from Inputs in ACC $fields["ACC"]
"fetchmailmethod" => $cdb->get_prop("fetchmail", "Method"),
);
return %ret;
}
sub get_data_for_panel_FIL {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
my %ret = (
# fields from Inputs in FIL $fields["FIL"]
"virusstatus" => $c->get_virus_status(),
"spamstatus" => $cdb->get_prop("spamassassin", "status"),
"spamsensitivity" => $cdb->get_prop("spamassassin", "Sensitivity", "medium"),
"spamtaglevel" => $cdb->get_prop("spamassassin", "TagLevel") || "0",
"spamrejectlevel" => $cdb->get_prop("spamassassin", "RejectLevel") || "0",
"spamsortspam" => $cdb->get_prop("spamassassin", "SortSpam"),
"spamsubjecttag" => $cdb->get_prop("spamassassin", "SubjectTag"),
"spamsubject" => $cdb->get_prop("spamassassin", "Subject"),
);
return %ret;
}
sub get_data_for_panel_REC {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
my %ret = (
"Data1"=>"Data for REC", #Example
# fields from Inputs in REC $fields["REC"]
"fetchmailmethod" => $cdb->get_prop("fetchmail", "Method"),
"freqoffice" => $cdb->get_prop("fetchmail", "FreqOffice"),
"freqoutside" => $cdb->get_prop("fetchmail", "FreqOutside"),
"freqweekend" => $cdb->get_prop("fetchmail", "FreqWeekend"),
"secondarymailserver" => $cdb->get_prop("fetchmail", "SecondaryMailServer"),
"secondarymailaccount" => $cdb->get_prop("fetchmail", "SecondaryMailAccount"),
"secondarymailpassword" => $cdb->get_prop("fetchmail", "SecondaryMailPassword"),
"specifyheader" => get_secondary_mail_use_envelope(),
"secondarymailenvelope" => $cdb->get_prop("fetchmail", "SecondaryMailEnvelope"),
);
return %ret;
}
sub get_data_for_panel_DEL {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
my %ret = (
# fields from Inputs in DEL $fields["DEL"]
"emailunknownuser" => $cdb->get_value("EmailUnknownUser") || "\"returntosender",
"delegatemailserver" => $cdb->get_value("DelegateMailServer"),
"smtpsmarthost" => $cdb->get_value("SMTPSmartHost"),
"smtpauthproxystatus" => $cdb->get_prop("smtp-auth-proxy", "status") || "disabled",
"smtpauthproxyuserid" => $cdb->get_prop("smtp-auth-proxy", "Userid") || "",
"smtpauthproxypassword" => $cdb->get_prop("smtp-auth-proxy", "Passwd") || "",
);
return %ret;
}
# Get control data for table(s)
# Return hash with values from row in which link clicked on table
sub get_selected_FRONT {
my $c = shift;
my $selected = shift; #Parameter is name of selected row.
my $is_new_record = shift; #Indicates new record required (defaults)
my %ret = ();
#gather the values here
return %ret;
}
sub get_selected_ACC {
my $c = shift;
my $selected = shift; #Parameter is name of selected row.
my $is_new_record = shift; #Indicates new record required (defaults)
my %ret = ();
#gather the values here
return %ret;
}
sub get_selected_FIL {
my $c = shift;
my $selected = shift; #Parameter is name of selected row.
my $is_new_record = shift; #Indicates new record required (defaults)
my %ret = ();
#gather the values here
return %ret;
}
sub get_selected_REC {
my $c = shift;
my $selected = shift; #Parameter is name of selected row.
my $is_new_record = shift; #Indicates new record required (defaults)
my %ret = ();
#gather the values here
return %ret;
}
sub get_selected_DEL {
my $c = shift;
my $selected = shift; #Parameter is name of selected row.
my $is_new_record = shift; #Indicates new record required (defaults)
my %ret = ();
#gather the values here
return %ret;
}
#after sucessful modify or create or whatever and submit then perfom (if the params validate)
sub perform_FRONT {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
my $ret = "";
my $db = $cdb; #maybe one of the others
my $dbkey = "ChangeThis";
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub perform_ACC {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
my $ret = "";
my $db = $cdb; #maybe one of the others
my $dbkey = "ChangeThis";
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
$ret = $c->change_settings_access();
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub perform_FIL {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
my $ret = "";
my $db = $cdb; #maybe one of the others
my $dbkey = "ChangeThis";
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
$ret = $c->change_settings_filtering();
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub perform_REC {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
my $ret = "";
my $db = $cdb; #maybe one of the others
my $dbkey = "ChangeThis";
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
$ret = $c->change_settings_reception();
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub perform_DEL {
my $c = shift;
my $mai_data = shift; #Data hash as parameter
my $ret = "";
my $db = $cdb; #maybe one of the others
my $dbkey = "ChangeThis";
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
$ret = $c->change_settings_delivery();
if ($ret eq "") {$ret = "ok";}
return $ret;
}
sub create_link{
# WIP
my ($c,$route, $panel, $index) = @_;
my $link = "$route?trt=$panel&Selected=$index";
return $link;
}
sub get_virus_status {
my ($c, $localise) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
my $status = $cdb->get_prop(\"qpsmtpd\", "VirusScan") || "disabled";
return $localise ? $c->localise_status($status) : $status;
} ## end sub get_virus_status
sub get_spam_status {
my ($c, $localise) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
my $status = $cdb->get_prop("spamassassin", "status") || "disabled";
return $localise ? $c->localise_status($status) : $status;
} ## end sub get_spam_status
sub localise_status {
my ($c, $status) = @_;
return $c->l($status eq "enabled" ? $c->l("ENABLED") : $c->l("DISABLED"));
}
sub get_db_prop {
my ($c, $item, $prop, $default) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
return $cdb->get_prop($item, $prop) || $default;
}
sub get_value {
my $c = shift;
my $item = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
return $cdb->get_value($item) || "";
} ## end sub get_value
sub get_emailunknownuser_status {
my ($c, $localise) = @_;
my $options = $c->get_emailunknownuser_options();
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
my $val = $cdb->get_value("EmailUnknownUser") || \"returntosender\";
return $localise ? $c->l($options->{$val}) : $val;
} ## end sub get_emailunknownuser_status
sub get_patterns_status {
my ($c, $localise) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
my $status = $cdb->get_prop("qpsmtpd", "PatternsScan") || "disabled";
return $localise ? $c->localise_status($status) : $status;
} ## end sub get_patterns_status
sub adjust_patterns {
my $c = shift;
my @selected = @{ $c->every_param("BlockExecutableContent") };
$pattern_db = esmith::ConfigDB::UTF8->open("mailpatterns");
foreach my $pattern ($pattern_db->get_all_by_prop(type => "pattern")) {
my $status
= (grep $pattern->key eq $_, @selected)
? "enabled"
: "disabled";
$pattern->set_prop("Status", $status);
} ## end foreach my $pattern ($pattern_db...)
$pattern_db->reload;
return scalar @selected;
} ## end sub adjust_patterns
sub get_current_pop3_access {
my ($c, $localise) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
my $pop3Status = $cdb->get_prop("pop3", "status") || "enabled";
my $pop3Access = $cdb->get_prop("pop3", "access") || "private";
my $pop3sStatus = $cdb->get_prop("pop3s", "status") || "enabled";
my $pop3sAccess = $cdb->get_prop("pop3s", "access") || "private";
my $options = get_pop_options();
if ($pop3Status ne "enabled" && $pop3sStatus ne "enabled") {
return $localise ? $c->l($options->{disabled}) : "disabled";
} elsif ($pop3Status eq "enabled" && $pop3Access eq "public") {
return $localise ? $c->l($options->{public}) : "public";
} elsif ($pop3sStatus eq "enabled" && $pop3sAccess eq "public") {
return $localise ? $c->l($options->{publicSSL}) : "publicSSL";
}
return $localise ? $c->l($options->{private}) : "private";
} ## end sub get_current_pop3_access
sub get_current_imap_access {
my ($c, $localise) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
my $imapStatus = $cdb->get_prop("imap", "status") || "enabled";
my $imapAccess = $cdb->get_prop("imap", "access") || "private";
my $imapsStatus = $cdb->get_prop("imaps", "status") || "enabled";
my $imapsAccess = $cdb->get_prop("imaps", "access") || "private";
my $options = get_imap_options();
if (($imapStatus ne "enabled" || $imapAccess eq "localhost") && $imapsStatus ne "enabled") {
return $localise ? $c->l($options->{disabled}) : "disabled";
}
if ($imapStatus eq "enabled" && $imapAccess eq "public") {
return $localise ? $c->l($options->{public}) : "public";
} elsif ($imapsStatus eq "enabled" && $imapsAccess eq "public") {
return $localise ? $c->l($options->{publicSSL}) : "publicSSL";
}
return $localise ? $c->l($options->{private}) : "private";
} ## end sub get_current_imap_access
sub get_current_smtp_ssl_auth {
my ($c, $localise, $soru, $debug) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
die \"Error: \$soru must be either "s" or "u":$soru.\n\" unless $soru eq "s" || $soru eq "u";
$cdb = esmith::ConfigDB::UTF8->open || die \"Couldn"t open config db";
# Initialize variables with default values
my $smtpStatus = "none";
my $smtpAccess = "none";
my $smtpAuth = "disabled"; # assuming "disabled" as a default
# Fetch SMTP settings based on the value of `$soru`
if ($soru eq "u") {
$smtpStatus = $cdb->get_prop("uqpsmtpd", "status") || "enabled"; # Fetch from uqpsmtpd
$smtpAccess = $cdb->get_prop("uqpsmtpd", "access") || "public";
$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
}
# Retrieve SMTP SSL authentication options
my $options = $c->get_smtp_ssl_auth_options();
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)
# 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";
} ## end sub get_current_smtp_ssl_auth
sub get_current_smtp_auth {
my ($c, $localise) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
my $smtpStatus = $cdb->get_prop("qpsmtpd", "status") || "enabled";
my $smtpAuth = $cdb->get_prop("qpsmtpd", "Authentication") || "enabled";
my $options = get_smtp_auth_options();
if ($smtpStatus eq "enabled" && $smtpAuth eq "disabled") {
return $localise ? $c->l($options->{public}) : "public";
} elsif ($smtpStatus eq "enabled" && $smtpAuth eq "enabled") {
return $localise ? $c->l($options->{publicSSL}) : "publicSSL";
}
return $localise ? $c->l($options->{disabled}) : "disabled";
} ## end sub get_current_smtp_auth
sub get_current_webmail_status {
my ($c, $localise) = @_;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
# 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"))
{
$WebmailStatus = "enabledSSL";
} elsif (($RoundcubeStatus eq "enabled")
&& ($MysqlStatus eq "enabled")
&& ($PHPStatus eq "enabled")
&& ($Networkaccess eq "private"))
{
$WebmailStatus = "localnetworkSSL";
} ## end elsif (($RoundcubeStatus ...))
my $options = get_webmail_options();
return $localise
? $c->l($options->{$WebmailStatus})
: $WebmailStatus;
} ## end sub get_current_webmail_status
sub get_pop_opt {
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
sub get_pop_options {
my $c = @_;
my %options = (
disabled => "DISABLED",
private => "NETWORKS_ALLOW_LOCAL",
publicSSL => "mai_SECURE_POP3"
);
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
my $access = $cdb->get_prop("pop3", "access") || "private";
$options{public} = "mai_INSECURE_POP3" if ($access eq "public");
\%options;
} ## end sub get_pop_options
sub get_imap_opt {
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
sub get_imap_options {
my $c = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die(\"Couldn"t open config db");
my %options = (
disabled => "DISABLED",
private => "NETWORKS_ALLOW_LOCAL",
publicSSL => "mai_SECURE_IMAP"
);
my $access = $cdb->get_prop("imap", "access") || "private";
$options{public} = "mai_INSECURE_IMAP" if ($access eq "public");
\%options;
} ## end sub get_imap_options
sub get_smtp_auth_opt {
my $c = shift;
return [
[ $c->l("mai_SECURE_SMTP") => "publicSSL" ],
[ $c->l("Only allow insecure access") => "public" ],
[ $c->l("DISABLED") => "disabled" ]
];
} ## end sub get_smtp_auth_opt
sub get_smtp_auth_options {
my $c = shift;
my %options = (publicSSL => "mai_SECURE_SMTP", public => "Only allow insecure access", disabled => "DISABLED");
return \%options;
} ## end sub get_smtp_auth_options
sub get_smtp_ssl_auth_options {
my $c = shift;
my %options = (public => "Allow public access", local => "Allow local access only", disabled => "DISABLED");
return \%options;
} ## end sub get_smtp_ssl_auth_options
sub get_smtp_ssl_auth_opt {
my $c = shift;
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
sub get_key_by_value {
my ($hash_ref, $target_value) = @_;
# Iterate over the hash
while (my ($key, $value) = each %$hash_ref) {
return $key if $value eq $target_value;
}
return undef; # Return undef if no match is found
} ## end sub get_key_by_value
sub get_value_by_key {
my ($hash_ref, $key) = @_;
return $hash_ref->{$key}; # Return the value associated with the key
}
sub get_webmail_opt {
my $c = shift;
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
sub get_webmail_options {
my $c = shift;
my %options = (
disabled => "DISABLED",
enabledSSL => "mai_ENABLED_SECURE_ONLY",
localnetworkSSL => "mai_ONLY_LOCAL_NETWORK_SSL"
);
return \%options;
} ## end sub get_webmail_options
sub get_retrieval_opt {
my $c = shift;
my $cdb = esmith::ConfigDB::UTF8->open() || die("Couldn"t open config db\");
return $cdb->get(\"SystemMode\")->value eq \"servergateway-private\"
? [ $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
sub get_emailunknownuser_options {
my $c = shift;
my $accounts = esmith::AccountsDB::UTF8->open_ro();
my %existingAccounts = (
"admin" => $c->l(\"mai_FORWARD_TO_ADMIN\"),
"returntosender" => $c->l(\"Reject\")
);
foreach my $account ($accounts->get_all) {
next if $account->key eq "everyone";
if ($account->prop("type") =~ /(user|group|pseudonym)/) {
$existingAccounts{ $account->key } = $c->l(\"mai_FORWARD_TO\") . \" \" . $account->key;
}
} ## end foreach my $account ($accounts...)
return (\%existingAccounts);
} ## end sub get_emailunknownuser_options
sub get_emailunknownuser_opt {
my $c = shift;
my $accounts = esmith::AccountsDB::UTF8->open_ro();
my @existingAccounts
= ([ $c->l(\"mai_FORWARD_TO_ADMIN\") => "admin" ], [ $c->l(\"Reject\") => "returntosender" ]);
foreach my $account ($accounts->get_all) {
next if $account->key eq "everyone";
if ($account->prop("type") =~ /(user|group|pseudonym)/) {
push @existingAccounts, [ $c->l(\"mai_FORWARD_TO\") . \" \" . $account->key => $account->key ];
}
} ## end foreach my $account ($accounts...)
return (\@existingAccounts);
} ## end sub get_emailunknownuser_opt
sub get_patterns_opt {
my $c = shift;
my $pattern_db = esmith::ConfigDB::UTF8->open(\"mailpatterns\");
my @options;
foreach my $pattern ($pattern_db->get_all_by_prop(type => \"pattern\")) {
my %props = $pattern->props;
push @options, [ $props{"Description"} => $pattern->key ];
}
return \@options;
} ## end sub get_patterns_opt
sub get_patterns_current_opt {
my $c = shift;
my @selected;
my $pattern_db = esmith::ConfigDB::UTF8->open(\"mailpatterns\");
foreach my $pattern ($pattern_db->get_all_by_prop(type => \"pattern\")) {
my %props = $pattern->props;
push @selected, $pattern->key if ($props{"Status"} eq "enabled");
}
return \@selected;
} ## end sub get_patterns_current_opt
sub get_spam_level_options {
return [ 0 .. 20 ];
}
sub get_spam_sensitivity_opt {
my $c = shift;
return [
[ $c->l("mai_VERYLOW") => "verylow" ],
[ $c->l("Low") => "low" ],
[ $c->l("Medium") => "medium" ],
[ $c->l("High") => "high" ],
[ $c->l("mai_VERYHIGH") => "veryhigh" ],
[ $c->l("Custom") => "custom" ]
];
} ## end sub get_spam_sensitivity_opt
sub fetchmail_freq {
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
sub display_multidrop {
my $status = $cdb->get_prop("fetchmail", "status") || "disabled";
# XXX FIXME - WIP
# 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");
return 1;
} ## end sub display_multidrop
sub change_settings_reception {
my $c = shift;
$cdb = esmith::ConfigDB::UTF8->open || die \"Couldn"t open config db";
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 {
$fetchmail->delete_prop("SecondaryMailEnvelope");
}
} ## end else [ if ($FetchmailMethod eq...)]
# 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
#my $smtpAuth = ($c->param("SMTPAuth") || "public");
#if ($smtpAuth eq "public") {
#$cdb->set_prop("qpsmtpd", "Authentication", "enabled" );
#$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" );
#} elsif ($smtpAuth eq "publicSSL") {
#$cdb->set_prop("qpsmtpd", "Authentication", "disabled" );
#$cdb->set_prop("sqpsmtpd", "Authentication", "enabled" );
#} else {
#$cdb->set_prop("qpsmtpd", "Authentication", "disabled" );
#$cdb->set_prop("sqpsmtpd", "Authentication", "disabled" );
#}
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");
}
return "";
} ## end sub change_settings_reception
sub change_settings_delivery {
my ($c) = shift;
$cdb = esmith::ConfigDB::UTF8->open || die "Couldn"t open config db\";
my $EmailUnknownUser = ($c->param("EmailUnknownUser") || "returntosender");
$cdb->set_value("SMTPSmartHost", $c->param("SMTPSmartHost"));
$cdb->set_value("DelegateMailServer", $c->param("DelegateMailServer"));
$cdb->set_value("EmailUnknownUser", $EmailUnknownUser);
my $proxy = $cdb->get("smtp-auth-proxy");
my %props = $proxy->props;
for (qw(Userid Passwd status)) {
$props{$_} = $c->param(\"SMTPAUTHPROXY_$_\");
}
$proxy->merge_props(%props);
unless (system(\"/sbin/e-smith/signal-event\", \"email-update\") == 0) {
return $c->l("mai_ERROR_UPDATING_CONFIGURATION");
}
return "";
} ## end sub change_settings_delivery
sub change_settings_access {
my $c = shift;
$cdb = esmith::ConfigDB::UTF8->open || die \"Couldn"t open config db";
my $pop3Access = ($c->param("POPAccess") || "private");
if ($pop3Access eq "disabled") {
$cdb->set_prop("pop3", "status", "disabled");
$cdb->set_prop("pop3s", "status", "disabled");
} else {
$cdb->set_prop("pop3", "status", "enabled");
$cdb->set_prop("pop3s", "status", "enabled");
}
if ($pop3Access eq "public") {
$cdb->set_prop("pop3", "access", "public");
$cdb->set_prop("pop3s", "access", "public");
} elsif ($pop3Access eq "publicSSL") {
$cdb->set_prop("pop3", "access", "private");
$cdb->set_prop("pop3s", "access", "public");
} else {
$cdb->set_prop("pop3", "access", "private");
$cdb->set_prop("pop3s", "access", "private");
}
my $imapAccess = ($c->param("IMAPAccess") || "private");
if ($imapAccess eq "disabled") {
$cdb->set_prop("imap", "status", "enabled");
$cdb->set_prop("imap", "access", "localhost");
$cdb->set_prop("imaps", "status", "disabled");
} elsif ($imapAccess eq "public") {
$cdb->set_prop("imap", "status", "enabled");
$cdb->set_prop("imap", "access", "public");
$cdb->set_prop("imaps", "status", "enabled");
$cdb->set_prop("imaps", "access", "public");
} elsif ($imapAccess eq "publicSSL") {
$cdb->set_prop("imap", "status", "enabled");
$cdb->set_prop("imap", "access", "private");
$cdb->set_prop("imaps", "status", "enabled");
$cdb->set_prop("imaps", "access", "public");
} else {
$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")]
#------------------------------------------------------------
# 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");
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");
}
unless (system(\"/sbin/e-smith/signal-event\", \"email-update\") == 0) {
return $c->l("mai_ERROR_UPDATING_CONFIGURATION");
}
return "";
} ## end sub change_settings_access
sub change_settings_filtering {
my $c = shift;
$cdb = esmith::ConfigDB::UTF8->open || die \"Couldn"t open config db";
my $virus_status = ($c->param("VirusStatus") || "disabled");
$cdb->set_prop("qpsmtpd", "VirusScan", $virus_status);
for my $param (
qw(
status
Sensitivity
TagLevel
RejectLevel
SortSpam
Subject
SubjectTag)
)
{
$cdb->set_prop("spamassassin", $param, $c->param("Spam$param"));
} ## end for my $param (qw( status...))
my $patterns_status = $c->adjust_patterns() ? "enabled" : "disabled";
$cdb->set_prop("qpsmtpd", "PatternsScan", $patterns_status);
unless (system("/sbin/e-smith/signal-event", "email-update") == 0) {
return $c->l("mai_ERROR_UPDATING_CONFIGURATION");
}
return "";
} ## end sub change_settings_filtering
#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 {
$cdb = esmith::ConfigDB::UTF8->open || die "Couldn"t open config db\";
my $use_envelope = $cdb->get_prop("fetchmail", "SecondaryMailEnvelope");
if (defined $use_envelope) {
return ("on");
} else {
return ("off");
}
} ## end sub get_secondary_mail_use_envelope
sub validate_smarthost {
my $c = shift;
my $smarthost = shift;
return ("ok") if ($smarthost =~ /^(\S+\.\S+)$/);
return ("ok") if ($smarthost eq "");
return \"mai_INVALID_SMARTHOST\";
} ## end sub validate_smarthost
sub validate_ip_or_blank {
my ($c,$ip) = @_;
return "ok" if $ip eq "";
return "ok" if is_ipv4($ip) || is_ipv6($ip);
return \"mai_INVALID_DELEGATE\";
}
# From earlier version - delete this once conversion is done.
#sub main {
#my $c = shift;
#$c->app->log->info($c->log_req);
#$pattern_db = esmith::ConfigDB::UTF8->open(\"mailpatterns\");
#$cdb = esmith::ConfigDB::UTF8->open || die \"Couldn"t open config db";
#my %mai_datas = ();
#my $title = $c->l("mai_FORM_TITLE");
#$mai_datas{"trt"} = "LIST";
#$mai_datas{fetchmailmethod} = $c->l($cdb->get_prop("fetchmail", "Method"));
#$c->stash(title => $title, notif => "", mai_datas => \%mai_datas);
#$c->render(template => "emailsettings");
#} ## end sub main
#sub do_display {
#my $c = shift;
#my $rt = $c->current_route;
#my $trt = ($c->param("trt") || "LIST");
#my %mai_datas = ();
#my $title = $c->l("mai_FORM_TITLE");
#my ($notif, $dest) = "";
#$mai_datas{"trt"} = $trt;
#$cdb = esmith::ConfigDB::UTF8->open || die "Couldn"t open config db\";
#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
#sub do_update {
#my $c = shift;
#$c->app->log->info($c->log_req);
#my $rt = $c->current_route;
#my $trt = $c->param("trt");
#my %mai_datas = ();
#$mai_datas{trt} = $trt;
#$cdb = esmith::ConfigDB::UTF8->open || die \"Couldn"t open config db";
#my $title = $c->l("mai_FORM_TITLE");
#my ($dest, $res, $result) = "";
#$dest = "/emailsettings&trt=$trt";
#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";
#my ($result,$res) = "";
#CHECKS: {
#$res = $c->validate_ip_or_blank($c->param("DelegateMailServer"));
#if ($res ne "OK") {
#$result = $c->l($res);
#last CHECKS;
#}
#$res = $c->validate_smarthost($c->param("SMTPSmartHost"));
#if ($res ne "OK") {
#$result = $c->l($res);
#last CHECKS;
#}
#$res = $c->nonblank_if_smtpauth($c->param("SMTPSmartHost"));
#if ($res ne "OK") {
#$result = $c->l($res);
#last CHECKS;
#}
#$res = $c->nonblank_if_smtpauth($c->param("SMTPAUTHPROXY_Userid"));
#if ($res ne "OK") {
#$result = $c->l($res);
#last CHECKS;
#}
#$res = $c->nonblank_if_smtpauth($c->param("SMTPAUTHPROXY_Passwd"));
#if ($res ne "OK") {
#$result = $c->l($res);
#last CHECKS;
#}
#$res = $c->change_settings_delivery();
#if ($res ne "OK") {
#$result = $res;
#last CHECKS;
#}
#$result = $c->l("mai_SUCCESS");
#}
## $result now contains the first error or the success message
#} ## end if ($trt eq "DEL")
## common part
#if ($res ne "OK") {
#$c->stash(error => $result);
#$c->stash(title => $title, mai_datas => \%mai_datas);
#return $c->redirect_to($dest);
#} else {
#my $message = "emailsettings updates $trt DONE";
#$c->app->log->info($message);
#$c->flash(success => $result);
#}
#$c->redirect_to("/emailsettings");
#} ## end sub do_update
1;