From 78f286cbda3abc5ff2bff683884f20111e515264 Mon Sep 17 00:00:00 2001 From: Arnold Bechtoldt Date: Tue, 21 Aug 2012 20:08:20 +0200 Subject: [PATCH] Implement *deactivate-catchall*-feature, refs #fixes 1114 Signed-off-by: Arnold Bechtoldt --- actions/admin/settings/150.mail.php | 8 +++ customer_email.php | 61 ++++++++++++------- install/froxlor.sql | 3 +- .../updates/froxlor/0.9/update_0.9.inc.php | 11 ++++ .../function.storeSettingResetCatchall.php | 43 +++++++++++++ lib/tables.inc.php | 2 +- lng/english.lng.php | 7 +++ lng/german.lng.php | 7 +++ templates/Froxlor/customer/email/emails.tpl | 2 +- .../Froxlor/customer/email/emails_email.tpl | 2 +- 10 files changed, 121 insertions(+), 25 deletions(-) create mode 100644 lib/functions/settings/function.storeSettingResetCatchall.php diff --git a/actions/admin/settings/150.mail.php b/actions/admin/settings/150.mail.php index fc514f37..041b5347 100644 --- a/actions/admin/settings/150.mail.php +++ b/actions/admin/settings/150.mail.php @@ -99,6 +99,14 @@ return array( 'type' => 'hidden', 'default' => 0, ), + 'system_catchall_enabled' => array( + 'label' => $lng['serversettings']['catchall_enabled'], + 'settinggroup' => 'catchall', + 'varname' => 'catchall_enabled', + 'type' => 'bool', + 'default' => true, + 'save_method' => 'storeSettingResetCatchall', + ), ), ), ), diff --git a/customer_email.php b/customer_email.php index 590605ce..b8225488 100644 --- a/customer_email.php +++ b/customer_email.php @@ -284,6 +284,12 @@ elseif($page == 'emails') //$iscatchall = makeyesno('iscatchall', '1', '0', '0'); $email_add_data = include_once dirname(__FILE__).'/lib/formfields/customer/email/formfield.emails_add.php'; + + if ( $settings['catchall']['catchall_enabled'] != '1' ) + { + unset($email_add_data['emails_add']['sections']['section_a']['fields']['iscatchall']); + } + $email_add_form = htmlform::genHTMLForm($email_add_data); $title = $email_add_data['emails_add']['title']; @@ -330,6 +336,12 @@ elseif($page == 'emails') $result = htmlentities_array($result); $email_edit_data = include_once dirname(__FILE__).'/lib/formfields/customer/email/formfield.emails_edit.php'; + + if ( $settings['catchall']['catchall_enabled'] != '1' ) + { + unset($email_edit_data['emails_edit']['sections']['section_a']['fields']['mail_catchall']); + } + $email_edit_form = htmlform::genHTMLForm($email_edit_data); $title = $email_edit_data['emails_edit']['title']; @@ -341,34 +353,41 @@ elseif($page == 'emails') elseif($action == 'togglecatchall' && $id != 0) { - $result = $db->query_first("SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid`, `popaccountid` FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'"); - - if(isset($result['email']) - && $result['email'] != '') + if ( $settings['catchall']['catchall_enabled'] == '1' ) { - if($result['iscatchall'] == '1') - { - $db->query("UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `email` = '" . $db->escape($result['email_full']) . "', `iscatchall` = '0' WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$result['id'] . "'"); - } - else - { - $email_parts = explode('@', $result['email_full']); - $email = '@' . $email_parts[1]; - $email_check = $db->query_first("SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid` FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `email`='" . $db->escape($email) . "' AND `customerid`='" . (int)$userinfo['customerid'] . "'"); + $result = $db->query_first("SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid`, `popaccountid` FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'"); - if($email_check['email'] == $email) + if(isset($result['email']) + && $result['email'] != '') + { + if($result['iscatchall'] == '1') { - standard_error('youhavealreadyacatchallforthisdomain'); - exit; + $db->query("UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `email` = '" . $db->escape($result['email_full']) . "', `iscatchall` = '0' WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$result['id'] . "'"); } else { - $db->query("UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `email` = '$email' , `iscatchall` = '1' WHERE `customerid`='" . $userinfo['customerid'] . "' AND `id`='" . $result['id'] . "'"); - $log->logAction(USR_ACTION, LOG_INFO, "edited email address '" . $email . "'"); - } - } + $email_parts = explode('@', $result['email_full']); + $email = '@' . $email_parts[1]; + $email_check = $db->query_first("SELECT `id`, `email`, `email_full`, `iscatchall`, `destination`, `customerid` FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `email`='" . $db->escape($email) . "' AND `customerid`='" . (int)$userinfo['customerid'] . "'"); - redirectTo($filename, Array('page' => $page, 'action' => 'edit', 'id' => $id, 's' => $s)); + if($email_check['email'] == $email) + { + standard_error('youhavealreadyacatchallforthisdomain'); + exit; + } + else + { + $db->query("UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `email` = '$email' , `iscatchall` = '1' WHERE `customerid`='" . $userinfo['customerid'] . "' AND `id`='" . $result['id'] . "'"); + $log->logAction(USR_ACTION, LOG_INFO, "edited email address '" . $email . "'"); + } + } + + redirectTo($filename, Array('page' => $page, 'action' => 'edit', 'id' => $id, 's' => $s)); + } + } + else + { + standard_error(array('operationnotpermitted', 'featureisdisabled'), 'Catchall'); } } } diff --git a/install/froxlor.sql b/install/froxlor.sql index 138eb1f3..442d5e68 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -337,6 +337,7 @@ CREATE TABLE `panel_settings` ( INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES + ('catchall', 'catchall_enabled', '1'), ('session', 'allow_multiple_login', '0'), ('session', 'sessiontimeout', '600'), ('customer', 'accountprefix', 'web'), @@ -530,7 +531,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'allow_preset', '1'), ('panel', 'allow_preset_admin', '0'), ('panel', 'password_regex', ''), - ('panel', 'version', '0.9.28-svn4'); + ('panel', 'version', '0.9.28-svn5'); diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index 07646e7a..f759c382 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -1951,3 +1951,14 @@ if(isFroxlorVersion('0.9.28-svn3')) updateToVersion('0.9.28-svn4'); } + +if(isFroxlorVersion('0.9.28-svn4')) { + showUpdateStep("Updating from 0.9.28-svn4 to 0.9.28-svn5"); + + // Catchall functionality (enabled by default) see #1114 + $db->query("INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('catchall', 'catchall_enabled', '1');"); + + lastStepStatus(0); + + updateToVersion('0.9.28-svn5'); +} diff --git a/lib/functions/settings/function.storeSettingResetCatchall.php b/lib/functions/settings/function.storeSettingResetCatchall.php new file mode 100644 index 00000000..b65a0c0a --- /dev/null +++ b/lib/functions/settings/function.storeSettingResetCatchall.php @@ -0,0 +1,43 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Functions + * + */ + +function storeSettingResetCatchall($fieldname, $fielddata, $newfieldvalue) +{ + $returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue); + + if($returnvalue !== false + && is_array($fielddata) + && isset($fielddata['settinggroup']) + && $fielddata['settinggroup'] == 'catchall' + && isset($fielddata['varname']) + && $fielddata['varname'] == 'catchall_enabled' + && $newfieldvalue == '0') + { + global $db; + $result = $db->query("SELECT `id`, `email`, `email_full`, `iscatchall` FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `iscatchall`='1'"); + + while($result_row = $db->fetch_array($result)) + { + $db->query("UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `email` = '" . $db->escape($result_row['email_full']) . "', `iscatchall` = '0' WHERE `id`='" . (int)$result_row['id'] . "'"); + } + } + + return $returnvalue; +} + +?> diff --git a/lib/tables.inc.php b/lib/tables.inc.php index 63f6f1c4..3f388c54 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -73,6 +73,6 @@ define('PACKAGE_ENABLED', 2); // VERSION INFO -$version = '0.9.28-svn4'; +$version = '0.9.28-svn5'; $dbversion = '2'; $branding = ''; diff --git a/lng/english.lng.php b/lng/english.lng.php index d01b40df..08f766a1 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1921,3 +1921,10 @@ $lng['admin']['speciallogwarning'] = 'WARNING: By changing this setting you will $lng['serversettings']['vmail_maildirname']['title'] = 'Maildir name'; $lng['serversettings']['vmail_maildirname']['description'] = 'Maildir directory into user\'s account. Normally \'Maildir\', in some implementations \'.maildir\', and directly into user\'s directory if left blank.'; $lng['tasks']['remove_emailacc_files'] = 'Delete customer e-mail data.'; + +// ADDED IN 0.9.28-svn5 +$lng['error']['operationnotpermitted'] = 'Operation not permitted!'; +$lng['error']['featureisdisabled'] = 'Feature %s is disabled. Please contact your service provider.'; +$lng['serversettings']['catchall_enabled']['title'] = 'Use Catchall'; +$lng['serversettings']['catchall_enabled']['description'] = 'Do you want to provide your customers the catchall-feature?'; + diff --git a/lng/german.lng.php b/lng/german.lng.php index 548f3946..661581f5 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1646,3 +1646,10 @@ $lng['serversettings']['phpfpm_settings']['idle_timeout']['description'] = 'Time $lng['panel']['cancel'] = 'abbrechen'; $lng['admin']['delete_statistics'] = 'Statistiken Löschen'; $lng['admin']['speciallogwarning'] = 'ACHTUNG: Durch diese Einstellungen werden Sie alle bisherige Statistiken dieser Domain verlieren. Wenn Sie dabei wirklich sicher sind, geben Sie bitte folgenden Text in das nachfolgende Textfeld ein: "'.$lng['admin']['delete_statistics'].'" und bestätigen Sie mit "'.$lng['panel']['delete'].'".

'; + +// ADDED IN 0.9.28-svn5 +$lng['error']['operationnotpermitted'] = 'Diese Aktion ist nicht erlaubt!'; +$lng['error']['featureisdisabled'] = 'Die Funktion %s wurde deaktiviert. Kontaktieren Sie bitte Ihren Dienstleister.'; +$lng['serversettings']['catchall_enabled']['title'] = 'Catchall verwenden'; +$lng['serversettings']['catchall_enabled']['description'] = 'Möchten Sie Ihren Kunden die Funktion Catchall zur Verfügung stellen?'; + diff --git a/templates/Froxlor/customer/email/emails.tpl b/templates/Froxlor/customer/email/emails.tpl index 996853e1..9e568693 100644 --- a/templates/Froxlor/customer/email/emails.tpl +++ b/templates/Froxlor/customer/email/emails.tpl @@ -28,7 +28,7 @@ {$lng['emails']['emailaddress']} {$arrowcode['m.email_full']} {$lng['emails']['forwarders']} {$arrowcode['m.destination']} {$lng['emails']['account']} - {$lng['emails']['catchall']} + {$lng['emails']['catchall']} {$lng['emails']['quota']} diff --git a/templates/Froxlor/customer/email/emails_email.tpl b/templates/Froxlor/customer/email/emails_email.tpl index c0307151..bf6a6dbf 100644 --- a/templates/Froxlor/customer/email/emails_email.tpl +++ b/templates/Froxlor/customer/email/emails_email.tpl @@ -2,7 +2,7 @@ {$row['email_full']}  {$row['destination']} {$lng['panel']['yes']}{$lng['panel']['no']} - {$lng['panel']['yes']}{$lng['panel']['no']} + {$lng['panel']['yes']}{$lng['panel']['no']} {$lng['emails']['noquota']}{$row['quota']} MB