diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings-Custom.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings-Custom.pm new file mode 100644 index 0000000..f43a506 --- /dev/null +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings-Custom.pm @@ -0,0 +1,1171 @@ +# +# 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("mai_RETURN_TO_SENDER") + ); + + 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("mai_RETURN_TO_SENDER") => '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('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 + +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; \ No newline at end of file diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm index 87f5d61..b468010 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings.pm @@ -1,816 +1,438 @@ package SrvMngr::Controller::Emailsettings; - +# +# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +# Remember that each route must be unique (else they just overwrite each other). +# you cannot have get and post on the same name and url. +# #---------------------------------------------------------------------- # heading : System -# description : E-mail +# description : E-Mail # navigation : 4000 400 # +# name : emailsettings, method : get, url : /emailsettings, ctlact : Emailsettings#main +# name : emailsettingsu, method : post, url : /emailsettingsu, ctlact : Emailsettings#do_update +# name : emailsettingsd, method : get, url : /emailsettingsd, ctlact : Emailsettings#do_display # # routes : end +# +# Documentation: https://wiki.contribs.org/Emailsettings #---------------------------------------------------------------------- + +# +# Scheme of things: +# +# TBA!! + use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; + use constant FALSE => 0; use constant TRUE => 1; + use Locale::gettext; use SrvMngr::I18N; -use SrvMngr qw(theme_list init_session ip_number_or_blank); -use esmith::ConfigDB::UTF8; -use esmith::AccountsDB::UTF8; +use SrvMngr qw(theme_list init_session); + +use Data::Dumper; + use esmith::util; -use File::Basename; -our $pattern_db; -our $cdb; +use esmith::util::network; +use esmith::ConfigDB::UTF8; +use esmith::AccountsDB; +use esmith::NetworksDB::UTF8; +use esmith::HostsDB; +use esmith::DomainsDB::UTF8; + +my $cdb; +my $adb; +my $ndb; +my $hdb; +my $ddb; + +my %mai_data; + +require '/usr/share/smanager/lib/SrvMngr/Controller/Emailsettings-Custom.pm'; #The code that is to be added by the developer sub main { +# +# Initial entry - route is "/" +# +#set initial panel +#for initial panel: + #Specifiy panel to enter + #load up _data hash with DB fields + #load up stash with pointer(s) to control fields hash(= get-)) + #and a pointer to the prefix_data hash +#render initial panel + + my $c = shift; + $c->app->log->info( $c->log_req ); + + #The most common ones - you might want to delete some of these if they are not used. + $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"); + + %mai_data = (); + my $title = $c->l('mai_E-Mail'); + my $modul = ''; + + $mai_data{'trt'} = 'FRONT'; + + #Load any DB entries into the _data area so as they are preset in the form + # which DB - this only really works if the initial panel is a PARAMS type panel and not a TABLE + my $db = $cdb; #pickup local or global db or Default to config + + + $c->do_display($mai_data{'trt'}); + +} + +# Post request with params - submit from the form +sub do_update { +# +# Return after submit pushed on panel (this is a post) - route is "/u" +# parameters in the params hash. +# +#load up all params into prefix_data hash: +#By panel (series of if statements - only one executed): + #call validate-PANEL() - return ret = ok or error message + +#if validation not ok: + #render back to current panel with error message in stash +#otherwise: + #By panel (series of if statements - only one executed): + #do whatever is required: call perform-PANEL() - return 'ok' or Error Message + #call signal-event for any global actions specified (check it exists - error and continue?) + #if action smeserver--update exists + #signal_event smeserver--update + #call signal-event for any specific actions for thids panel (check it exists first - error and continue) + #set success in stash + #if no "nextpanel" entry: + #set firstpanel + #else + #set nextpanel + #call render + 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 + my $modul = ''; + + #The most common ones - you might want to delete some of these if they are not used. + $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"); + + my $title = $c->l('mai_E-Mail'); + + # Accessing all POST/GET parameters + my $params = $c->req->params->to_hash; + + # Get number of POST parameters + #my $num_params = keys scaler %$params; + + #Params are available in the hash "params" - copy to the prefix_data hash + #while (my ($key, $value) = each %{$c->req->params->to_hash}) { + # $mai_data{$key} = $value; + #} + + # the value of trt will tell you which panel has returned + my $trt = $c->param('trt') || 'FRONT'; #hidden control on every form. + my $ret = 'ok'; + + #Validate the parameters in a custom sub one for each panel (although only one of these will be executed) + my $thispanel; + + if ($trt eq 'FRONT'){ + #Validate form parameters for panel FRONT + $ret = $c->validate_FRONT(\%mai_data); + $thispanel = 'FRONT'; + } + + if ($trt eq 'ACC'){ + #Validate form parameters for panel ACC + $ret = $c->validate_ACC(\%mai_data); + $thispanel = 'ACC'; + } + + if ($trt eq 'FIL'){ + #Validate form parameters for panel FIL + $ret = $c->validate_FIL(\%mai_data); + $thispanel = 'FIL'; + } + + if ($trt eq 'REC'){ + #Validate form parameters for panel REC + $ret = $c->validate_REC(\%mai_data); + $thispanel = 'REC'; + } + + if ($trt eq 'DEL'){ + #Validate form parameters for panel DEL + $ret = $c->validate_DEL(\%mai_data); + $thispanel = 'DEL'; + } + + if ($ret ne 'ok'){ + $c->stash(error => $c->l($ret)); + $c->do_display($thispanel); + } else { + #Do whatever is needed, including writing values to the DB + if ($trt eq 'FRONT'){ + #do whatever is required ... + $ret = $c->perform_FRONT(\%mai_data); + if ($ret ne 'ok') { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + mai_data => \%mai_data + ); + $c->render(template => "emailsettings"); + return + } else { + $c->stash( success => $c->l('mai_FRONT_panel_action_was_successful')); #A bit bland - edit it in the lex file + } + } + + if ($trt eq 'ACC'){ + #do whatever is required ... + $ret = $c->perform_ACC(\%mai_data); + if ($ret ne 'ok') { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + mai_data => \%mai_data + ); + $c->render(template => "emailsettings"); + return + } else { + $c->stash( success => $c->l('mai_ACC_panel_action_was_successful')); #A bit bland - edit it in the lex file + } + } + + if ($trt eq 'FIL'){ + #do whatever is required ... + $ret = $c->perform_FIL(\%mai_data); + if ($ret ne 'ok') { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + mai_data => \%mai_data + ); + $c->render(template => "emailsettings"); + return + } else { + $c->stash( success => $c->l('mai_FIL_panel_action_was_successful')); #A bit bland - edit it in the lex file + } + } + + if ($trt eq 'REC'){ + #do whatever is required ... + $ret = $c->perform_REC(\%mai_data); + if ($ret ne 'ok') { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + mai_data => \%mai_data + ); + $c->render(template => "emailsettings"); + return + } else { + $c->stash( success => $c->l('mai_REC_panel_action_was_successful')); #A bit bland - edit it in the lex file + } + } + + if ($trt eq 'DEL'){ + #do whatever is required ... + $ret = $c->perform_DEL(\%mai_data); + if ($ret ne 'ok') { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->stash( + title => $title, + modul => $modul, + mai_data => \%mai_data + ); + $c->render(template => "emailsettings"); + return + } else { + $c->stash( success => $c->l('mai_DEL_panel_action_was_successful')); #A bit bland - edit it in the lex file + } + } + + # and call any signal-events needed + #TBD + # Setup shared data and call panel + if ('none' eq 'none') { + $mai_data{'trt'} = 'FRONT'; + } else { + $mai_data{'trt'} = 'none'; + } + $c->do_display($mai_data{'trt'}); + } +} 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"; +# +# Return after link clicked in table (this is a get) - route is "/d" +# Expects ?trt=PANEL&selected="TableRowName" plus any other required +# +# OR it maybe a post from the main panel to add a new record +# +#load up all supplied params into prefix_data hash +#call get-selected-PANEL() - returns hash of all relevent parameters +#load up returned hash into prefix_data +#render - to called panel - 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; + my ($c,$trt) = @_; $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) = ''; - 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
' unless $res eq 'OK'; - $res = $c->validate_smarthost($c->param('SMTPSmartHost')); - $result .= $res . ' SH
' unless $res eq 'OK'; - $res = $c->nonblank_if_smtpauth($c->param('SMTPSmartHost')); - $result .= $res . ' SH
' unless $res eq 'OK'; - $res = $c->nonblank_if_smtpauth($c->param('SMTPAUTHPROXY_Userid')); - $result .= $res . ' USR
' unless $res eq 'OK'; - $res = $c->nonblank_if_smtpauth($c->param('SMTPAUTHPROXY_Passwd')); - $result .= $res . ' PWD
' 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') - - # common part - if ($res ne 'OK') { - $c->stash(error => $result); - $c->stash(title => $title, mai_datas => \%mai_datas); - return $c->render($dest); - } - my $message = "emailsettings updates $trt DONE"; - $c->app->log->info($message); - $c->flash(success => $result); - $c->redirect_to("/emailsettings"); -} ## end sub do_update - -sub get_virus_status { - my ($c, $localise) = @_; - 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 $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) = @_; - return $cdb->get_prop($item, $prop) || $default; -} - -sub get_value { - my $c = shift; - my $item = shift; - return $cdb->get_value($item) || ''; -} ## end sub get_value - -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; -} ## end sub get_emailunknownuser_status - -sub get_patterns_status { - my ($c, $localise) = @_; - 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 $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 $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) = @_; - 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 $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) = @_; - - # 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 $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 %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; - 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("mai_RETURN_TO_SENDER") - ); - - 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("mai_RETURN_TO_SENDER") => '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 @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; - - 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('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 - -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::ConfigDBi::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" ); + #The most common ones - you might want to delete some of these if they are not used. + $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"); + + my $title = $c->l('mai_E-Mail'); + my $modul = ''; + + # Accessing all parameters + my $params = $c->req->params->to_hash; + + # Get number of parameters + my $num_params = keys %$params; + + #Tag as Post or Get (ie. create new entry or edit existing one + my $is_new_record = ($c->req->method() eq 'POST'); + + #Params are available in the hash "params" - copy to the prefix_data hash + #while (my ($key, $value) = each %{$c->req->params->to_hash}) { + # $mai_data{$key} = $value; #} - 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'); + # the value of trt will tell you which panel has returned + if (! $trt){ + $trt = $c->param('trt') || 'FRONT'; #Indicates where to go now + } + + # Now add in the params from the selected row from the table + + my %selectedrow; + + if ($trt eq 'FRONT'){ + #Validate Get selected row (if applicable) FRONT + %selectedrow = $c->get_selected_FRONT($mai_data{'Selected'},$is_new_record); + } + + if ($trt eq 'ACC'){ + #Validate Get selected row (if applicable) ACC + %selectedrow = $c->get_selected_ACC($mai_data{'Selected'},$is_new_record); + } + + if ($trt eq 'FIL'){ + #Validate Get selected row (if applicable) FIL + %selectedrow = $c->get_selected_FIL($mai_data{'Selected'},$is_new_record); + } + + if ($trt eq 'REC'){ + #Validate Get selected row (if applicable) REC + %selectedrow = $c->get_selected_REC($mai_data{'Selected'},$is_new_record); + } + + if ($trt eq 'DEL'){ + #Validate Get selected row (if applicable) DEL + %selectedrow = $c->get_selected_DEL($mai_data{'Selected'},$is_new_record); + } + + + #Copy in the selected row params to the prefix_data hash to pass to the panel + while (my ($key, $value) = each %selectedrow){ + $mai_data{$key} = $value; } - return 'OK'; -} ## 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 'OK'; -} ## 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 'OK'; -} ## 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 'OK'; -} ## 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 { - 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 $fm = shift; - my $smarthost = shift; - return ('OK') if ($smarthost =~ /^(\S+\.\S+)$/); - return ('OK') if ($smarthost eq ''); - return "INVALID_SMARTHOST"; -} ## end sub validate_smarthost -1; + # Where to go now + $mai_data{'trt'} = $trt; + + # Set up other shared data according to the panel to go to + + if ($trt eq 'FRONT'){ + # pickup any other contents needed and load them into hash shared with panel + my %returned_hash; + # subroutine returns a hash directly + %returned_hash = $c->get_data_for_panel_FRONT(); + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $mai_data{$key} = $value; + } + } + + if ($trt eq 'ACC'){ + # pickup any other contents needed and load them into hash shared with panel + my %returned_hash; + # subroutine returns a hash directly + %returned_hash = $c->get_data_for_panel_ACC(); + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $mai_data{$key} = $value; + } + } + + if ($trt eq 'FIL'){ + # pickup any other contents needed and load them into hash shared with panel + my %returned_hash; + # subroutine returns a hash directly + %returned_hash = $c->get_data_for_panel_FIL(); + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $mai_data{$key} = $value; + } + } + + if ($trt eq 'REC'){ + # pickup any other contents needed and load them into hash shared with panel + my %returned_hash; + # subroutine returns a hash directly + %returned_hash = $c->get_data_for_panel_REC(); + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $mai_data{$key} = $value; + } + } + + if ($trt eq 'DEL'){ + # pickup any other contents needed and load them into hash shared with panel + my %returned_hash; + # subroutine returns a hash directly + %returned_hash = $c->get_data_for_panel_DEL(); + # Copy each key-value pair from the returned hash to the prefix data hash + while (my ($key, $value) = each %returned_hash) { + $mai_data{$key} = $value; + } + } + + + # and table control fields + + + # Data for panel + $c->stash( + title => $title, + modul => $modul, + mai_data => \%mai_data + ); + $c->render(template => "emailsettings"); +} +1; \ No newline at end of file diff --git a/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Emailsettings/emailsettings_en.lex b/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Emailsettings/emailsettings_en.lex index 1e511fc..43e3a61 100644 --- a/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Emailsettings/emailsettings_en.lex +++ b/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Emailsettings/emailsettings_en.lex @@ -1,6 +1,5 @@ - 'mai_FORM_TITLE' => 'E-mail settings', -'E-mail' => 'E-mail', +'mai_E-Mail' => 'E-mail', 'mai_SUCCESS' => 'The new e-mail settings have been saved.', 'mai_NEVER' => 'not at all', 'mai_EVERY5MIN' => 'Every 5 minutes', @@ -20,7 +19,7 @@ for dialup connections), or multi-drop (for dialup connections if ETRN is not supported by your Internet provider). Note that multi-drop mode is the only option available when the server is configured in private server and gateway mode.', -'mai_LABEL_DELEGATE' => 'Address of internal mail server', +'mai_LABEL_DELEGATE' => 'IP Address of internal mail server', 'mai_TITLE_DELEGATE' => 'Delegate mail servers', 'mai_DESC_DELEGATE' => 'Your server includes a complete, full-featured e-mail server. However, if for some reason you wish to delegate e-mail processing to @@ -79,10 +78,9 @@ destination (recommended in most cases) or can deliver them via your Internet provider\'s SMTP server (recommended if you have an unreliable Internet connection or are using a residential Internet service). If using your Internet provider\'s SMTP server, specify -its hostname or IP address below. Otherwise leave this field -blank.', -'mai_INVALID_SMARTHOST' => 'The smarthost name you entered is not a valid internet domain name -and is not blank', +its hostname or IP address below. Otherwise leave this field blank.', +'mai_INVALID_SMARTHOST' => 'The smarthost name you entered is not a valid internet domain name and is not blank', +'mai_INVALID_DELEGATE' => 'The delegate host name you entered is not a valid IP Address and is not blank', 'mai_DESC_POP_ACCESS_CONTROL' => 'You can control POP3 server access. The setting \'Allow access only from local networks\' allows POP3 access only from your local network(s). The POP3S setting can be used to provide @@ -150,5 +148,9 @@ The value for this tag can be defined below.', 'mai_LABEL_SMARTHOST_SMTPAUTH_STATUS' => 'SMTP Authentication for Internet provider', 'mai_LABEL_SMARTHOST_SMTPAUTH_USERID' => 'Mail server user id', 'mai_LABEL_SMARTHOST_SMTPAUTH_PASSWD' => 'Mail server password', -'mai_VALIDATION_SMTPAUTH_NONBLANK' => 'This field cannot be left blank if SMTP Authentication is +'mai_VALIDATION_SMTPAUTH_NONBLANK' => 'The user id and password fields cannot be left blank if SMTP Authentication is enabled.', +'mai_ACC_panel_action_was_successful' => 'Email access settings saved sucessfully', +'mai_DEL_panel_action_was_successful' => 'Email delivery settings saved sucessfully', +'mai_FIL_panel_action_was_successful' => 'Email filtering settings saved sucessfully', +'mai_REC_panel_action_was_successful' => 'Email receive settings saved sucessfully', \ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/public/css/emailsettings.css b/root/usr/share/smanager/themes/default/public/css/emailsettings.css new file mode 100644 index 0000000..7a9223d --- /dev/null +++ b/root/usr/share/smanager/themes/default/public/css/emailsettings.css @@ -0,0 +1,14 @@ +/* +Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +*/ +.Emailsettings-panel {} +.name {} +.rout {} +.name {} +.rout {} +.name {} +.rout {} +.name {} +.rout {} +.name {} +.rout {} diff --git a/root/usr/share/smanager/themes/default/public/js/emailsettings.js b/root/usr/share/smanager/themes/default/public/js/emailsettings.js new file mode 100644 index 0000000..6d99c37 --- /dev/null +++ b/root/usr/share/smanager/themes/default/public/js/emailsettings.js @@ -0,0 +1,5 @@ +// +//Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +// +$(document).ready(function() { +}); diff --git a/root/usr/share/smanager/themes/default/templates/emailaccess.html.ep b/root/usr/share/smanager/themes/default/templates/emailaccess.html.ep deleted file mode 100644 index 54c6cfb..0000000 --- a/root/usr/share/smanager/themes/default/templates/emailaccess.html.ep +++ /dev/null @@ -1,57 +0,0 @@ -% layout 'default', title => "Sme server 2 - emailaccess"; - -% content_for 'module' => begin -
- - % if (config->{debug} == 1) { -

- %= dumper $c->current_route - %= dumper $mai_datas -

- % } - - % if ( stash 'error' ) { -
- %= $c->render_to_string(inline => stash 'error') -
- %} - -

<%= $title%>

- - %= form_for '/emailsettingd' => (method => 'POST') => begin - - %=l 'mai_DESC_POP_ACCESS_CONTROL' - -

- %=l 'mai_LABEL_POP_ACCESS_CONTROL' - - % param 'POPAccess' => $c->get_current_pop3_access() unless param 'POPAccess'; - %= select_field 'POPAccess' => $c->get_pop_opt(), class => 'input' -

- - %=l 'mai_DESC_IMAP_ACCESS_CONTROL' - -

- %=l 'mai_LABEL_IMAP_ACCESS_CONTROL' - - % param 'IMAPAccess' => $c->get_current_imap_access() unless param 'IMAPAccess'; - %= select_field 'IMAPAccess' => $c->get_imap_opt(), class => 'input' -

- - %=l 'mai_DESC_WEBMAIL' - -

- %=l 'mai_LABEL_WEBMAIL' - - % param 'WebMail' => $c->get_current_webmail_status() unless param 'WebMail'; - %= select_field 'WebMail' => $c->get_webmail_opt(), class => 'input' -

- - % my $btn = l('SAVE'); - %= submit_button "$btn", class => 'action' - - %= hidden_field 'trt' => 'ACC' - % end - -
-%end diff --git a/root/usr/share/smanager/themes/default/templates/emaildeliver.html.ep b/root/usr/share/smanager/themes/default/templates/emaildeliver.html.ep deleted file mode 100644 index 7895529..0000000 --- a/root/usr/share/smanager/themes/default/templates/emaildeliver.html.ep +++ /dev/null @@ -1,92 +0,0 @@ -% layout 'default', title => "Sme server 2 - emaildeliver"; - -% content_for 'module' => begin -
- - % if (config->{debug} == 1) { -

- %= dumper $c->current_route - %= dumper $mai_datas -

- % } - - % if ( stash 'error' ) { -
- %= $c->render_to_string(inline => stash 'error') -
- %} - -

<%= $title%>

- - %= form_for '/emailsettingd' => (method => 'POST') => begin - -

- %=l 'mai_TITLE_UNKNOWN' -

- - %=l 'mai_DESC_UNKNOWN' - -

- %=l 'mai_LABEL_UNKNOWN' - - % param 'EmailUnknownUser' => $mai_datas->{emailunknownuser} unless param 'EmailUnknownUser'; - %= select_field 'EmailUnknownUser' => $c->get_emailunknownuser_opt(), class => 'input' -

- - -

- %=l 'mai_TITLE_DELEGATE' -

- - %=l 'mai_DESC_DELEGATE' - -

- %=l 'mai_LABEL_DELEGATE' - - % param 'DelegateMailServer' => $mai_datas->{delegatemailserver} unless param 'DelegateMailServer'; - %= text_field 'DelegateMailServer', class => 'input' -

- - -

- %=l 'mai_TITLE_SMARTHOST' -

- - %=l 'mai_DESC_SMARTHOST' - -

- %=l 'mai_LABEL_SMARTHOST' - - % param 'SMTPSmartHost' => $mai_datas->{smtpsmarthost} unless param 'SMTPSmartHost'; - %= text_field 'SMTPSmartHost', class => 'input' -

- -

- %=l 'mai_LABEL_SMARTHOST_SMTPAUTH_STATUS' - - % param 'SMTPAUTHPROXY_status' => $mai_datas->{smtpauthproxystatus} unless param 'SMTPAUTHPROXY_status'; - %= select_field 'SMTPAUTHPROXY_status' => [[(l 'DISABLED') => 'disabled'], [(l 'ENABLED') => 'enabled']], class => 'input' -

- -

- %=l 'mai_LABEL_SMARTHOST_SMTPAUTH_USERID' - - % param 'SMTPAUTHPROXY_Userid' => $mai_datas->{smtpauthproxyuserid} unless param 'SMTPAUTHPROXY_Userid'; - %= text_field 'SMTPAUTHPROXY_Userid', class => 'input' -

- -

- %=l 'mai_LABEL_SMARTHOST_SMTPAUTH_PASSWD' - - % param 'SMTPAUTHPROXY_Passwd' => $mai_datas->{smtpauthproxypassword} unless param 'SMTPAUTHPROXY_Passwd'; - %= password_field 'SMTPAUTHPROXY_Passwd', class => 'input' -

- - % my $btn = l('SAVE'); - %= submit_button "$btn", class => 'action' - - %= hidden_field 'trt' => 'DEL' - % end - -
-%end \ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/emailfilter.html.ep b/root/usr/share/smanager/themes/default/templates/emailfilter.html.ep deleted file mode 100644 index c31aaa8..0000000 --- a/root/usr/share/smanager/themes/default/templates/emailfilter.html.ep +++ /dev/null @@ -1,101 +0,0 @@ -% layout 'default', title => "Sme server 2 - emailfilter"; - -% content_for 'module' => begin -
- - % if (config->{debug} == 1) { -

- %= dumper $c->current_route - %= dumper $mai_datas -

- % } - - % if ( stash 'error' ) { -
- %= $c->render_to_string(inline => stash 'error') -
- %} - -

<%= $title%>

- - %= form_for '/emailsettingd' => (method => 'POST') => begin - - %=l 'mai_DESC_VIRUS_SCAN' - -

- %=l 'mai_LABEL_VIRUS_SCAN' - - % param 'VirusStatus' => $mai_datas->{virusstatus} unless param 'VirusStatus'; - %= select_field 'VirusStatus' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' -

- - %=l 'mai_DESC_SPAM_SCAN' - -

- %=l 'mai_LABEL_SPAM_SCAN' - - % param 'Spamstatus' => $mai_datas->{spamstatus} unless param 'Spamstatus'; - %= select_field 'Spamstatus' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' -

- -

- %=l 'mai_LABEL_SPAM_SENSITIVITY' - - % param 'SpamSensitivity' => $mai_datas->{spamsensitivity} unless param 'SpamSensitivity'; - %= select_field 'SpamSensitivity' => $c->get_spam_sensitivity_opt(), class => 'input' -

- -

- %=l 'mai_LABEL_SPAM_TAGLEVEL' - - % param 'SpamTagLevel' => $mai_datas->{spamtaglevel} unless param 'SpamTagLevel'; - %= select_field 'SpamTagLevel' => $c->get_spam_level_options(), class => 'input' -

- -

- %=l 'mai_LABEL_SPAM_REJECTLEVEL' - - % param 'SpamRejectLevel' => $mai_datas->{spamrejectlevel} unless param 'SpamRejectLevel'; - %= select_field 'SpamRejectLevel' => $c->get_spam_level_options(), class => 'input' -

- -

- %=l 'mai_LABEL_SORTSPAM' - - % param 'SpamSortSpam' => $mai_datas->{spamsortspam} unless param 'SpamSortSpam'; - %= select_field 'SpamSortSpam' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' -

- - %=l 'mai_DESC_SPAM_SUBJECT' - -

- %=l 'mai_LABEL_SPAM_SUBJECTTAG' - - % param 'SpamSubjectTag' => $mai_datas->{spamsubjecttag} unless param 'SpamSubjectTag'; - %= select_field 'SpamSubjectTag' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' -

- -

- %=l 'mai_LABEL_SPAM_SUBJECT' - - % param 'SpamSubject' => $mai_datas->{spamsubject} unless param 'SpamSubject'; - %= text_field 'SpamSubject' => class => 'input' -

- - %=l 'mai_DESC_BLOCK_EXECUTABLE_CONTENT' - -

- %=l 'mai_LABEL_CONTENT_TO_BLOCK' - - % param 'BlockExecutableContent' => $c->get_patterns_current_opt() unless param 'BlockExecutableContent'; - %= select_field 'BlockExecutableContent' => $c->get_patterns_opt(), class => 'input', multiple => "1" -

- - % my $btn = l('SAVE'); - %= submit_button "$btn", class => 'action' - - %= hidden_field 'trt' => 'FIL' - % end - -
-%end \ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/emailreceive.html.ep b/root/usr/share/smanager/themes/default/templates/emailreceive.html.ep deleted file mode 100644 index c1d146c..0000000 --- a/root/usr/share/smanager/themes/default/templates/emailreceive.html.ep +++ /dev/null @@ -1,167 +0,0 @@ -% layout 'default', title => "Sme server 2 - emailreceive"; - -% content_for 'module' => begin - -% use constant FALSE => 0; -% use constant TRUE => 1; - -
- - % if (config->{debug} == 1) { -

- %= dumper $c->current_route - %= dumper $mai_datas - %= dumper $c->param('SMTPAuth') -

- % } - - % if ( stash 'error' ) { -
- %= $c->render_to_string(inline => stash 'error') -
- %} - -

<%= $title%>

- - %= form_for '/emailsettingd' => (method => 'POST') => begin - - %=l 'mai_DESC_MODE' - -

- %=l 'mai_LABEL_MODE' - - % param 'FetchmailMethod' => $mai_datas->{fetchmailmethod} unless param 'FetchmailMethod'; - - %= select_field 'FetchmailMethod' => $c->get_retrieval_opt(), class => 'input' -

- - %#=l 'mai_DESC_SMTP_AUTH_CONTROL' -
- %= l "SMTP port (25) main purpose is to receive emails from another server, STARTTLS is always offered, but auth if offered is only if STARTTLS is also used by client." -
- %= l "SMTPS port (465) will require implicit SSL/TLS then authenticate to send." -
- %= l "SMTP Submission port (587) will require STARTTLS, then authenticate to send." -
- - % my $smtp_mesg=l('SMTP port %u allow client to authenticate:'); -

- %= sprintf($smtp_mesg,$c->get_db_prop('qpsmtpd','TCPPort',25)); - - % param 'SMTPAuth' => $c->get_current_smtp_auth( FALSE ) unless param 'SMTPAuth'; - - %= select_field 'SMTPAuth' => $c->get_smtp_auth_opt(), class => 'input' -

- - % my $smtp_mesg=l('SMTPS SSL/TLS auth: port %u status:'); -

- %= sprintf($smtp_mesg,$c->get_db_prop('sqpsmtpd','TCPPort',465)); - - % param 'sSMTPAuth' => $c->get_current_smtp_ssl_auth(FALSE,'s', TRUE) unless param 'sSMTPAuth'; - - %= select_field 'sSMTPAuth' => $c->get_smtp_ssl_auth_opt(), class => 'input' -

- - %my $smtp_mesg=l('Submission port %u status:'); -

- %= sprintf($smtp_mesg,$c->get_db_prop('uqpsmtpd','TCPPort',587)); - - % param 'uSMTPAuth' => $c->get_current_smtp_ssl_auth(FALSE,'u', TRUE) unless param 'uSMTPAuth'; - - %= select_field 'uSMTPAuth' => $c->get_smtp_ssl_auth_opt(), class => 'input' -

- - -

- %=l 'mai_TITLE_SECONDARY' -

- - %=l 'mai_DESC_SECONDARY' - -

- %=l 'mai_LABEL_SECONDARY' - - % param 'SecondaryMailServer' => $mai_datas->{secondarymailserver} unless param 'SecondaryMailServer'; - %= text_field 'SecondaryMailServer', class => 'input' -

- - %=l 'mai_DESC_FETCH_PERIOD' - -

- %=l 'mai_LABEL_FETCH_PERIOD' - - % param 'FreqOffice' => $mai_datas->{freqoffice} unless param 'FreqOffice'; - %= select_field 'FreqOffice' => $c->fetchmail_freq(), class => 'input' -

- -

- %=l 'mai_LABEL_FETCH_PERIOD_NIGHTS' - - % param 'FreqOutside' => $mai_datas->{freqoutside} unless param 'FreqOutside'; - %= select_field 'FreqOutside' => $c->fetchmail_freq(), class => 'input' -

- -

- %=l 'mai_LABEL_FETCH_PERIOD_WEEKENDS' - - % param 'FreqWeekend' => $mai_datas->{freqweekend} unless param 'FreqWeekend'; - %= select_field 'FreqWeekend' => $c->fetchmail_freq(), class => 'input' -

- -

- %=l 'mai_LABEL_POP_ACCOUNT' - - % param 'SecondaryMailAccount' => $mai_datas->{secondarymailaccount} unless param 'SecondaryMailAccount'; - %= text_field 'SecondaryMailAccount', class => 'input' -

- -

- %=l 'mai_LABEL_POP_PASS' - - % param 'SecondaryMailPassword' => $mai_datas->{secondarymailpassword} unless param 'SecondaryMailPassword'; - %= password_field 'SecondaryMailPassword', class => 'input' -

- -

- %=l 'mai_LABEL_SORT_METHOD' - - % param 'SpecifyHeader' => $mai_datas->{specifyheader} unless param 'SpecifyHeader'; - %= select_field 'SpecifyHeader' => [[(l 'mai_DEFAULT') => 'off'], [(l 'mai_SPECIFY_BELOW') => 'on']], class => 'input' -

- -

- %=l 'mai_LABEL_SORT_HEADER' - - % param 'SecondaryMailEnvelope' => $mai_datas->{secondarymailenvelope} unless param 'SecondaryMailEnvelope'; - %= text_field 'SecondaryMailEnvelope', class => 'input' -

- - % my $btn = l('SAVE'); - %= submit_button "$btn", class => 'action' - - %= hidden_field 'trt' => 'REC' - % end - -
-%end \ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/emailsettings.html.ep b/root/usr/share/smanager/themes/default/templates/emailsettings.html.ep index 13b749c..bcedb64 100644 --- a/root/usr/share/smanager/themes/default/templates/emailsettings.html.ep +++ b/root/usr/share/smanager/themes/default/templates/emailsettings.html.ep @@ -1,155 +1,72 @@ -% layout 'default', title => "Sme server 2 - emailsettings"; - +%# +%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +%# +% layout 'default', title => "Sme server 2 - E-Mail", share_dir => './'; +%# css specific to this panel: % content_for 'module' => begin +%= stylesheet '/css/emailsettings.css' +%= javascript '/js/emailsettings.js' % use constant FALSE => 0; % use constant TRUE => 1; -
+
- % if (config->{debug} == TRUE) { -

- %= dumper $c->current_route - %= dumper $mai_datas -

+ % if (config->{debug} == 1) { +
+		%= dumper $c->current_route
+		%= dumper $mai_data->{trt}
+	
+ % } + +

<%=$title%>

+ + % if ( stash('modul')) { + %= $c->render_to_string(inline => stash('modul') ); % } - % if ( stash 'error' ) { -
- %= $c->render_to_string(inline => stash 'error') -
- %} + %if ($c->stash('first')) { +

+ %=$c->render_to_string(inline =>$c->l($c->stash('first'))) +

-

<%= $title%>

+ %} elsif ($c->stash('success')) { +
+ %= $c->l($c->stash('success')); +
+
- %= form_for 'emailsettings' => (method => 'POST') => begin -

- %=l 'mai_LABEL_POP_ACCESS_CONTROL' - - %= $c->get_current_pop3_access( TRUE ) -

+ %} elsif ($c->stash('error')) { +
+ %= $c->l($c->stash('error')); +
+
+ %} -

- %=l 'mai_LABEL_IMAP_ACCESS_CONTROL' - - %= $c->get_current_imap_access( TRUE ) -

- -

- %=l 'mai_LABEL_WEBMAIL' - - %= $c->get_current_webmail_status( TRUE ) -

- - % my $btn = l('mai_DESC_STATE_ACCESS_BUTTON'); -
- %= submit_button "$btn", class => 'action' -
- - %= hidden_field 'trt' => 'ACC' - % end -
- - - - %= form_for 'emailsettings' => (method => 'POST') => begin -

- %=l 'mai_LABEL_VIRUS_SCAN' - - %= $c->get_virus_status(TRUE) -

- -

- %=l 'mai_LABEL_SPAM_SCAN' - - %= $c->get_spam_status(TRUE) -

- -

- %=l 'mai_LABEL_BLOCK_EXECUTABLE_CONTENT' - - %= $c->get_patterns_status(TRUE) -

- - % my $btn = l('mai_DESC_STATE_FILTERING_BUTTON'); -
- %= submit_button "$btn", class => 'action' -
- - %= hidden_field 'trt' => 'FIL' - % end -
- - - - %= form_for 'emailsettings' => (method => 'POST') => begin -

- %=l 'mai_LABEL_MODE' - - %= $mai_datas->{fetchmailmethod} -

+ %#Routing to partials according to trt parameter. + %#This ought to be cascading if/then/elsif, but is easier to just stack the if/then's rather like a case statement' + + % if ($mai_data->{trt} eq "FRONT") { + %= include 'partials/_mai_FRONT' + %} + + % if ($mai_data->{trt} eq "ACC") { + %= include 'partials/_mai_ACC' + %} + + % if ($mai_data->{trt} eq "FIL") { + %= include 'partials/_mai_FIL' + %} + + % if ($mai_data->{trt} eq "REC") { + %= include 'partials/_mai_REC' + %} + + % if ($mai_data->{trt} eq "DEL") { + %= include 'partials/_mai_DEL' + %} - % my $smtp_mesg; - % $smtp_mesg=l('SMTP port %u allow client to authenticate:'); -

- %= sprintf($smtp_mesg,$c->get_db_prop('qpsmtpd','TCPPort',25)); - - %= $c->get_current_smtp_auth( TRUE ) -

- - % $smtp_mesg=l('SMTPS SSL/TLS auth: port %u status:'); -

- %= sprintf($smtp_mesg,$c->get_db_prop('sqpsmtpd','TCPPort',465)); - - %= $c->get_current_smtp_ssl_auth( TRUE, 's', FALSE ) -

- - % $smtp_mesg=l 'Submission port %u status:'; -

- %= sprintf($smtp_mesg,$c->get_db_prop('uqpsmtpd','TCPPort',587)); - - %= $c->get_current_smtp_ssl_auth( TRUE,'u', FALSE ) -

-
- - % my $btn = l('mai_DESC_STATE_RECEPTION_BUTTON'); -
- %= submit_button "$btn", class => 'action' -
- - %= hidden_field 'trt' => 'REC' - % end -
- - - - %= form_for 'emailsettings' => (method => 'POST') => begin -

- %=l 'mai_LABEL_UNKNOWN' - - %= $c->get_emailunknownuser_status( TRUE ) -

- -

- %=l 'mai_LABEL_DELEGATE' - - %= $c->get_value('DelegateMailServer') -

- -

- %=l 'mai_LABEL_SMARTHOST' - - %= $c->get_value('SMTPSmartHost') -

- - % my $btn = l('mai_DESC_STATE_DELIVERY_BUTTON'); -
- %= submit_button "$btn", class => 'action' -
- - %= hidden_field 'trt' => 'DEL' - % end
%end \ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/partials/_mai_ACC.html.ep b/root/usr/share/smanager/themes/default/templates/partials/_mai_ACC.html.ep new file mode 100644 index 0000000..5397ad9 --- /dev/null +++ b/root/usr/share/smanager/themes/default/templates/partials/_mai_ACC.html.ep @@ -0,0 +1,54 @@ +%# +%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +%# +
+%# + % if (config->{debug} == 1) { +
+			%= dumper $mai_data
+		
+ % } + % my $btn = l('SAVE'); + % $c->param(Selected => undef); #This may need deleting for a params panel - only needed for a table + +

<%= $c->l('mai_DESC_STATE_ACCESS_BUTTON') %>


+ %= form_for "emailsettingsu" => (method => 'POST') => begin + % param 'trt' => $mai_data->{trt} unless param 'trt'; + %= hidden_field 'trt' => $mai_data->{trt} + %# Inputs etc in here. + %=l 'mai_DESC_POP_ACCESS_CONTROL' + +

+ %=l 'mai_LABEL_POP_ACCESS_CONTROL' + + % param 'POPAccess' => $c->get_current_pop3_access() unless param 'POPAccess'; + %= select_field 'POPAccess' => $c->get_pop_opt(), class => 'input' +

+ + %=l 'mai_DESC_IMAP_ACCESS_CONTROL' + +

+ %=l 'mai_LABEL_IMAP_ACCESS_CONTROL' + + % param 'IMAPAccess' => $c->get_current_imap_access() unless param 'IMAPAccess'; + %= select_field 'IMAPAccess' => $c->get_imap_opt(), class => 'input' +

+ + %=l 'mai_DESC_WEBMAIL' + +

+ %=l 'mai_LABEL_WEBMAIL' + + % param 'WebMail' => $c->get_current_webmail_status() unless param 'WebMail'; + %= select_field 'WebMail' => $c->get_webmail_opt(), class => 'input' +

+ + %# .... + %# Probably finally by a submit. + %= submit_button $btn, class => 'action' + %end +
\ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/partials/_mai_DEL.html.ep b/root/usr/share/smanager/themes/default/templates/partials/_mai_DEL.html.ep new file mode 100644 index 0000000..89655c0 --- /dev/null +++ b/root/usr/share/smanager/themes/default/templates/partials/_mai_DEL.html.ep @@ -0,0 +1,90 @@ +%# +%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +%# +
+%# + % if (config->{debug} == 1) { +
+			%= dumper $mai_data
+		
+ % } + % my $btn = l('SAVE'); + % $c->param(Selected => undef); #This may need deleting for a params panel - only needed for a table + +

<%= $c->l('mai_DESC_STATE_DELIVERY_BUTTON') %>

+ %= form_for "emailsettingsu" => (method => 'POST') => begin + % param 'trt' => $mai_data->{trt} unless param 'trt'; + %= hidden_field 'trt' => $mai_data->{trt} + %# Inputs etc in here. +

+ %=l 'mai_TITLE_UNKNOWN' +

+ + %=l 'mai_DESC_UNKNOWN' + +

+ %=l 'mai_LABEL_UNKNOWN' + + % param 'EmailUnknownUser' => $mai_data->{emailunknownuser} unless param 'EmailUnknownUser'; + %= select_field 'EmailUnknownUser' => $c->get_emailunknownuser_opt(), class => 'input' +

+ + +

+ %=l 'mai_TITLE_DELEGATE' +

+ + %=l 'mai_DESC_DELEGATE' + +

+ %=l 'mai_LABEL_DELEGATE' + + % param 'DelegateMailServer' => $mai_data->{delegatemailserver} unless param 'DelegateMailServer'; + %= text_field 'DelegateMailServer', class => 'input' +

+ + +

+ %=l 'mai_TITLE_SMARTHOST' +

+ + %=l 'mai_DESC_SMARTHOST' + +

+ %=l 'mai_LABEL_SMARTHOST' + + % param 'SMTPSmartHost' => $mai_data->{smtpsmarthost} unless param 'SMTPSmartHost'; + %= text_field 'SMTPSmartHost', class => 'input' +

+ +

+ %=l 'mai_LABEL_SMARTHOST_SMTPAUTH_STATUS' + + % param 'SMTPAUTHPROXY_status' => $mai_data->{smtpauthproxystatus} unless param 'SMTPAUTHPROXY_status'; + %= select_field 'SMTPAUTHPROXY_status' => [[(l 'DISABLED') => 'disabled'], [(l 'ENABLED') => 'enabled']], class => 'input' +

+ +

+ %=l 'mai_LABEL_SMARTHOST_SMTPAUTH_USERID' + + % param 'SMTPAUTHPROXY_Userid' => $mai_data->{smtpauthproxyuserid} unless param 'SMTPAUTHPROXY_Userid'; + %= text_field 'SMTPAUTHPROXY_Userid', class => 'input' +

+ +

+ %=l 'mai_LABEL_SMARTHOST_SMTPAUTH_PASSWD' + + % param 'SMTPAUTHPROXY_Passwd' => $mai_data->{smtpauthproxypassword} unless param 'SMTPAUTHPROXY_Passwd'; + %= password_field 'SMTPAUTHPROXY_Passwd', class => 'input' +

+ + + %# .... + %# Probably finally by a submit. + %= submit_button $btn, class => 'action' + %end +
\ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/partials/_mai_FIL.html.ep b/root/usr/share/smanager/themes/default/templates/partials/_mai_FIL.html.ep new file mode 100644 index 0000000..0293882 --- /dev/null +++ b/root/usr/share/smanager/themes/default/templates/partials/_mai_FIL.html.ep @@ -0,0 +1,98 @@ +%# +%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +%# +
+%# + % if (config->{debug} == 1) { +
+			%= dumper $mai_data
+		
+ % } + % my $btn = l('SAVE'); + % $c->param(Selected => undef); #This may need deleting for a params panel - only needed for a table + +

<%= $c->l('mai_DESC_STATE_FILTERING_BUTTON') %>


+ %= form_for "emailsettingsu" => (method => 'POST') => begin + % param 'trt' => $mai_data->{trt} unless param 'trt'; + %= hidden_field 'trt' => $mai_data->{trt} + %# Inputs etc in here. + %=l 'mai_DESC_VIRUS_SCAN' + +

+ %=l 'mai_LABEL_VIRUS_SCAN' + + % param 'VirusStatus' => $mai_data->{virusstatus} unless param 'VirusStatus'; + %= select_field 'VirusStatus' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' +

+ + %=l 'mai_DESC_SPAM_SCAN' + +

+ %=l 'mai_LABEL_SPAM_SCAN' + + % param 'Spamstatus' => $mai_data->{spamstatus} unless param 'Spamstatus'; + %= select_field 'Spamstatus' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' +

+ +

+ %=l 'mai_LABEL_SPAM_SENSITIVITY' + + % param 'SpamSensitivity' => $mai_data->{spamsensitivity} unless param 'SpamSensitivity'; + %= select_field 'SpamSensitivity' => $c->get_spam_sensitivity_opt(), class => 'input' +

+ +

+ %=l 'mai_LABEL_SPAM_TAGLEVEL' + + % param 'SpamTagLevel' => $mai_data->{spamtaglevel} unless param 'SpamTagLevel'; + %= select_field 'SpamTagLevel' => $c->get_spam_level_options(), class => 'input' +

+ +

+ %=l 'mai_LABEL_SPAM_REJECTLEVEL' + + % param 'SpamRejectLevel' => $mai_data->{spamrejectlevel} unless param 'SpamRejectLevel'; + %= select_field 'SpamRejectLevel' => $c->get_spam_level_options(), class => 'input' +

+ +

+ %=l 'mai_LABEL_SORTSPAM' + + % param 'SpamSortSpam' => $mai_data->{spamsortspam} unless param 'SpamSortSpam'; + %= select_field 'SpamSortSpam' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' +

+ + %=l 'mai_DESC_SPAM_SUBJECT' + +

+ %=l 'mai_LABEL_SPAM_SUBJECTTAG' + + % param 'SpamSubjectTag' => $mai_data->{spamsubjecttag} unless param 'SpamSubjectTag'; + %= select_field 'SpamSubjectTag' => [[(l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' +

+ +

+ %=l 'mai_LABEL_SPAM_SUBJECT' + + % param 'SpamSubject' => $mai_data->{spamsubject} unless param 'SpamSubject'; + %= text_field 'SpamSubject' => class => 'input' +

+ + %=l 'mai_DESC_BLOCK_EXECUTABLE_CONTENT' + +

+ %=l 'mai_LABEL_CONTENT_TO_BLOCK' + + % param 'BlockExecutableContent' => $c->get_patterns_current_opt() unless param 'BlockExecutableContent'; + %= select_field 'BlockExecutableContent' => $c->get_patterns_opt(), class => 'input', multiple => "1" +

+ + %# .... + %# Probably finally by a submit. + %= submit_button $btn, class => 'action' + %end +
\ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/partials/_mai_FRONT.html.ep b/root/usr/share/smanager/themes/default/templates/partials/_mai_FRONT.html.ep new file mode 100644 index 0000000..94e82d6 --- /dev/null +++ b/root/usr/share/smanager/themes/default/templates/partials/_mai_FRONT.html.ep @@ -0,0 +1,152 @@ +%# +%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +%# +
+%# + % if (config->{debug} == 1) { +
+			%= dumper $mai_data
+			
+
+ % } + % $c->param(Selected => undef); #This may need deleting for a params panel - only needed for a table + % my $btn = l('Modify'); +
+ <%= $c->l('mai_DESC_STATE_ACCESS_BUTTON') %> + %= form_for 'emailsettings' => (method => 'POST') => begin +

+ %=l 'mai_LABEL_POP_ACCESS_CONTROL' + + %= $c->get_current_pop3_access( TRUE ) +

+ +

+ %=l 'mai_LABEL_IMAP_ACCESS_CONTROL' + + %= $c->get_current_imap_access( TRUE ) +

+ +

+ %=l 'mai_LABEL_WEBMAIL' + + %= $c->get_current_webmail_status( TRUE ) +

+ +
+
+ %= submit_button "$btn", class => 'action' +
+ + %= hidden_field 'trt' => 'ACC' + % end +
+
+ + +
+ <%= $c->l('mai_DESC_STATE_FILTERING_BUTTON') %> + %= form_for 'emailsettings' => (method => 'POST') => begin +

+ %=l 'mai_LABEL_VIRUS_SCAN' + + %= $c->get_virus_status(TRUE) +

+ +

+ %=l 'mai_LABEL_SPAM_SCAN' + + %= $c->get_spam_status(TRUE) +

+ +

+ %=l 'mai_LABEL_BLOCK_EXECUTABLE_CONTENT' + + %= $c->get_patterns_status(TRUE) +

+ +
+
+ %= submit_button "$btn", class => 'action' +
+ + %= hidden_field 'trt' => 'FIL' + % end +
+
+ +
+ <%= $c->l('mai_DESC_STATE_RECEPTION_BUTTON') %> + %= form_for 'emailsettings' => (method => 'POST') => begin +

+ %=l 'mai_LABEL_MODE' + + %= $mai_data->{fetchmailmethod} +

+ + % my $smtp_mesg; + + % $smtp_mesg=l('SMTP port %u allow client to authenticate:'); +

+ %= sprintf($smtp_mesg,$c->get_db_prop('qpsmtpd','TCPPort',25)); + + %= $c->get_current_smtp_auth( TRUE ) +

+ + % $smtp_mesg=l('SMTPS SSL/TLS auth: port %u status:'); +

+ %= sprintf($smtp_mesg,$c->get_db_prop('sqpsmtpd','TCPPort',465)); + + %= $c->get_current_smtp_ssl_auth( TRUE, 's', FALSE ) +

+ + % $smtp_mesg=l 'Submission port %u status:'; +

+ %= sprintf($smtp_mesg,$c->get_db_prop('uqpsmtpd','TCPPort',587)); + + %= $c->get_current_smtp_ssl_auth( TRUE,'u', FALSE ) +

+
+ +
+ %= submit_button "$btn", class => 'action' +
+ + %= hidden_field 'trt' => 'REC' + % end +
+
+ +
+ <%= $c->l('mai_DESC_STATE_DELIVERY_BUTTON') %> + %= form_for 'emailsettings' => (method => 'POST') => begin +

+ %=l 'mai_LABEL_UNKNOWN' + + %= $c->get_emailunknownuser_status( TRUE ) +

+ +

+ %=l 'mai_LABEL_DELEGATE' + + %= $c->get_value('DelegateMailServer') +

+ +

+ %=l 'mai_LABEL_SMARTHOST' + + %= $c->get_value('SMTPSmartHost') +

+ +
+
+ %= submit_button "$btn", class => 'action' +
+ + %= hidden_field 'trt' => 'DEL' + % end +
+
\ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/partials/_mai_REC.html.ep b/root/usr/share/smanager/themes/default/templates/partials/_mai_REC.html.ep new file mode 100644 index 0000000..093dfa5 --- /dev/null +++ b/root/usr/share/smanager/themes/default/templates/partials/_mai_REC.html.ep @@ -0,0 +1,159 @@ +%# +%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-06-29 08:53:20 +%# +
+%# + % if (config->{debug} == 1) { +
+			%= dumper $mai_data
+		
+ % } + % my $btn = l('SAVE'); + % $c->param(Selected => undef); #This may need deleting for a params panel - only needed for a table + +

<%= $c->l('mai_DESC_STATE_RECEPTION_BUTTON') %>


+ %= form_for "emailsettingsu" => (method => 'POST') => begin + % param 'trt' => $mai_data->{trt} unless param 'trt'; + %= hidden_field 'trt' => $mai_data->{trt} + %# Inputs etc in here. + %=l 'mai_DESC_MODE' + +

+ %=l 'mai_LABEL_MODE' + + % param 'FetchmailMethod' => $mai_data->{fetchmailmethod} unless param 'FetchmailMethod'; + + %= select_field 'FetchmailMethod' => $c->get_retrieval_opt(), class => 'input' +

+ + %#=l 'mai_DESC_SMTP_AUTH_CONTROL' +
+ %= l "SMTP port (25) main purpose is to receive emails from another server, STARTTLS is always offered, but auth if offered is only if STARTTLS is also used by client." +
+ %= l "SMTPS port (465) will require implicit SSL/TLS then authenticate to send." +
+ %= l "SMTP Submission port (587) will require STARTTLS, then authenticate to send." +
+ + % my $smtp_mesg=l('SMTP port %u allow client to authenticate:'); +

+ %= sprintf($smtp_mesg,$c->get_db_prop('qpsmtpd','TCPPort',25)); + + % param 'SMTPAuth' => $c->get_current_smtp_auth( FALSE ) unless param 'SMTPAuth'; + + %= select_field 'SMTPAuth' => $c->get_smtp_auth_opt(), class => 'input' +

+ + % my $smtp_mesg=l('SMTPS SSL/TLS auth: port %u status:'); +

+ %= sprintf($smtp_mesg,$c->get_db_prop('sqpsmtpd','TCPPort',465)); + + % param 'sSMTPAuth' => $c->get_current_smtp_ssl_auth(FALSE,'s', TRUE) unless param 'sSMTPAuth'; + + %= select_field 'sSMTPAuth' => $c->get_smtp_ssl_auth_opt(), class => 'input' +

+ + %my $smtp_mesg=l('Submission port %u status:'); +

+ %= sprintf($smtp_mesg,$c->get_db_prop('uqpsmtpd','TCPPort',587)); + + % param 'uSMTPAuth' => $c->get_current_smtp_ssl_auth(FALSE,'u', TRUE) unless param 'uSMTPAuth'; + + %= select_field 'uSMTPAuth' => $c->get_smtp_ssl_auth_opt(), class => 'input' +

+ + +

+ %=l 'mai_TITLE_SECONDARY' +


+ + %=l 'mai_DESC_SECONDARY' + +

+ %=l 'mai_LABEL_SECONDARY' + + % param 'SecondaryMailServer' => $mai_data->{secondarymailserver} unless param 'SecondaryMailServer'; + %= text_field 'SecondaryMailServer', class => 'input' +

+ + %=l 'mai_DESC_FETCH_PERIOD' + +

+ %=l 'mai_LABEL_FETCH_PERIOD' + + % param 'FreqOffice' => $mai_data->{freqoffice} unless param 'FreqOffice'; + %= select_field 'FreqOffice' => $c->fetchmail_freq(), class => 'input' +

+ +

+ %=l 'mai_LABEL_FETCH_PERIOD_NIGHTS' + + % param 'FreqOutside' => $mai_data->{freqoutside} unless param 'FreqOutside'; + %= select_field 'FreqOutside' => $c->fetchmail_freq(), class => 'input' +

+ +

+ %=l 'mai_LABEL_FETCH_PERIOD_WEEKENDS' + + % param 'FreqWeekend' => $mai_data->{freqweekend} unless param 'FreqWeekend'; + %= select_field 'FreqWeekend' => $c->fetchmail_freq(), class => 'input' +

+ +

+ %=l 'mai_LABEL_POP_ACCOUNT' + + % param 'SecondaryMailAccount' => $mai_data->{secondarymailaccount} unless param 'SecondaryMailAccount'; + %= text_field 'SecondaryMailAccount', class => 'input' +

+ +

+ %=l 'mai_LABEL_POP_PASS' + + % param 'SecondaryMailPassword' => $mai_data->{secondarymailpassword} unless param 'SecondaryMailPassword'; + %= password_field 'SecondaryMailPassword', class => 'input' +

+ +

+ %=l 'mai_LABEL_SORT_METHOD' + + % param 'SpecifyHeader' => $mai_data->{specifyheader} unless param 'SpecifyHeader'; + %= select_field 'SpecifyHeader' => [[(l 'mai_DEFAULT') => 'off'], [(l 'mai_SPECIFY_BELOW') => 'on']], class => 'input' +

+ +

+ %=l 'mai_LABEL_SORT_HEADER' + + % param 'SecondaryMailEnvelope' => $mai_data->{secondarymailenvelope} unless param 'SecondaryMailEnvelope'; + %= text_field 'SecondaryMailEnvelope', class => 'input' +

+ + %# .... + %# Probably finally by a submit. + %= submit_button $btn, class => 'action' + %end +
\ No newline at end of file diff --git a/smeserver-manager.spec b/smeserver-manager.spec index dcd9bb6..611c245 100644 --- a/smeserver-manager.spec +++ b/smeserver-manager.spec @@ -2,7 +2,7 @@ Summary: Sme server navigation module : manager 2 %define name smeserver-manager Name: %{name} %define version 11.0.0 -%define release 96 +%define release 98 Version: %{version} Release: %{release}%{?dist} License: GPL @@ -36,6 +36,7 @@ Requires: perl(Net::Netmask) >= 1.9 Requires: perl(DBM::Deep) >= 2.0011-1 Requires: perl(Mojo::JWT) >= 0.08-1 #Requires: perl(Time::TAI64) >= 2.11 +Requires: perl(Data::Validate::IP) Requires: mutt >= 1.5.21 Requires: smeserver-manager-jsquery >= 1.0 Requires: smeserver-certificates >= 11.0 @@ -145,6 +146,12 @@ true %defattr(-,root,root) %changelog +* Sun Jun 29 2025 Brian Read 11.0.0-98.sme +- Re-factor email settings panel as error handling not working as expected. [SME: 12973] + +* Sat Jun 28 2025 Brian Read 11.0.0-97.sme +- fix error handling in emailsettings panel [SME: 12973] + * Fri Jun 27 2025 Brian Read 11.0.0-96.sme - Remove *.en files on install in spec file [SME: 13061]