From 8387cd8ae35a0ad94a49a27ad8622bb7b8ed2b06 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Feb 2014 17:21:41 +0100 Subject: [PATCH 1/4] Add option to change email settings in admin section Fix issue #7166 --- settings/admin.php | 10 ++++ settings/admin/controller.php | 83 +++++++++++++++++++++++++++++++++ settings/css/settings.css | 12 +++++ settings/js/admin.js | 38 +++++++++++++++ settings/routes.php | 3 ++ settings/templates/admin.php | 88 +++++++++++++++++++++++++++++++++++ 6 files changed, 234 insertions(+) create mode 100644 settings/admin/controller.php diff --git a/settings/admin.php b/settings/admin.php index c0e4570658..42477bfc1c 100755 --- a/settings/admin.php +++ b/settings/admin.php @@ -21,6 +21,16 @@ $entries=OC_Log_Owncloud::getEntries(3); $entriesremain = count(OC_Log_Owncloud::getEntries(4)) > 3; $tmpl->assign('loglevel', OC_Config::getValue( "loglevel", 2 )); +$tmpl->assign('mail_domain', OC_Config::getValue( "mail_domain", '' )); +$tmpl->assign('mail_from_address', OC_Config::getValue( "mail_from_address", '' )); +$tmpl->assign('mail_smtpmode', OC_Config::getValue( "mail_smtpmode", '' )); +$tmpl->assign('mail_smtpsecure', OC_Config::getValue( "mail_smtpsecure", '' )); +$tmpl->assign('mail_smtphost', OC_Config::getValue( "mail_smtphost", '' )); +$tmpl->assign('mail_smtpport', OC_Config::getValue( "mail_smtpport", '' )); +$tmpl->assign('mail_smtpauthtype', OC_Config::getValue( "mail_smtpauthtype", '' )); +$tmpl->assign('mail_smtpauth', OC_Config::getValue( "mail_smtpauth", false )); +$tmpl->assign('mail_smtpname', OC_Config::getValue( "mail_smtpname", '' )); +$tmpl->assign('mail_smtppassword', OC_Config::getValue( "mail_smtppassword", '' )); $tmpl->assign('entries', $entries); $tmpl->assign('entriesremain', $entriesremain); $tmpl->assign('htaccessworking', $htaccessworking); diff --git a/settings/admin/controller.php b/settings/admin/controller.php new file mode 100644 index 0000000000..9bbcd35658 --- /dev/null +++ b/settings/admin/controller.php @@ -0,0 +1,83 @@ +. +*/ + +namespace OC\Settings\Admin; + +class Controller { + public static function setMailSettings($args) { + \OC_Util::checkAdminUser(); + \OCP\JSON::callCheck(); + + $l = \OC_L10N::get('settings'); + + $smtp_settings = array( + 'mail_domain' => null, + 'mail_from_address' => null, + 'mail_smtpmode' => array('sendmail', 'smtp', 'qmail', 'php'), + 'mail_smtpsecure' => array('', 'ssl', 'tls'), + 'mail_smtphost' => null, + 'mail_smtpport' => null, + 'mail_smtpauthtype' => array('LOGIN', 'PLAIN', 'NTLM'), + 'mail_smtpauth' => true, + 'mail_smtpname' => null, + 'mail_smtppassword' => null, + ); + + foreach ($smtp_settings as $setting => $validate) { + if (!$validate) { + if (!isset($_POST[$setting]) || $_POST[$setting] === '') { + \OC_Config::deleteKey( $setting ); + } else { + \OC_Config::setValue( $setting, $_POST[$setting] ); + } + } + else if (is_bool($validate)) { + if (!empty($_POST[$setting])) { + \OC_Config::setValue( $setting, (bool) $_POST[$setting] ); + } else { + \OC_Config::deleteKey( $setting ); + } + } + else if (is_array($validate)) { + if (!isset($_POST[$setting]) || $_POST[$setting] === '') { + \OC_Config::deleteKey( $setting ); + } else if (in_array($_POST[$setting], $validate)) { + \OC_Config::setValue( $setting, $_POST[$setting] ); + } else { + $message = $l->t('Invalid value supplied for %s', array(self::getFieldname($setting, $l))); + \OC_JSON::error( array( "data" => array( "message" => $message)) ); + exit; + } + } + } + + \OC_JSON::success(array("data" => array( "message" => $l->t("Saved") ))); + } + + public static function getFieldname($setting, $l) { + switch ($setting) { + case 'mail_smtpmode': + return $l->t( 'SMTP mode' ); + case 'mail_smtpsecure': + return $l->t( 'Secure SMTP' ); + case 'mail_smtpauthtype': + return $l->t( 'Authentification method for SMTP' ); + } + } +} diff --git a/settings/css/settings.css b/settings/css/settings.css index 8a96885b78..ad205e761c 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -150,6 +150,18 @@ span.connectionwarning {color:#933; font-weight:bold; } input[type=radio] { width:1em; } table.shareAPI td { padding-bottom: 0.8em; } +#mail_settings p label:first-child { + display: inline-block; + width: 300px; + text-align: right; +} +#mail_settings p select:nth-child(2) { + width: 143px; +} +#mail_smtpport { + width: 40px; +} + /* HELP */ .pressed {background-color:#DDD;} diff --git a/settings/js/admin.js b/settings/js/admin.js index e957bd68f1..f39f53d413 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -34,4 +34,42 @@ $(document).ready(function(){ $('#security').change(function(){ $.post(OC.filePath('settings','ajax','setsecurity.php'), { enforceHTTPS: $('#forcessl').val() },function(){} ); }); + + $('#mail_smtpauth').change(function() { + if (!this.checked) { + $('#mail_credentials').toggle(false); + } else { + $('#mail_credentials').toggle(true); + } + }); + + $('#mail_settings').change(function(){ + OC.msg.startSaving('#mail_settings .msg'); + var post = $( "#mail_settings" ).serialize(); + $.post(OC.Router.generate('settings_mail_settings'), post, function(data){ + OC.msg.finishedSaving('#mail_settings .msg', data); + }); + }); }); + +OC.msg={ + startSaving:function(selector){ + $(selector) + .html( t('settings', 'Saving...') ) + .removeClass('success') + .removeClass('error') + .stop(true, true) + .show(); + }, + finishedSaving:function(selector, data){ + if( data.status === "success" ){ + $(selector).html( data.data.message ) + .addClass('success') + .stop(true, true) + .delay(3000) + .fadeOut(900); + }else{ + $(selector).html( data.data.message ).addClass('error'); + } + } +}; diff --git a/settings/routes.php b/settings/routes.php index 60f9d8e100..aa16ad491f 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -70,6 +70,9 @@ $this->create('settings_ajax_getlog', '/settings/ajax/getlog.php') ->actionInclude('settings/ajax/getlog.php'); $this->create('settings_ajax_setloglevel', '/settings/ajax/setloglevel.php') ->actionInclude('settings/ajax/setloglevel.php'); +$this->create('settings_mail_settings', '/settings/admin/mailsettings') + ->post() + ->action('OC\Settings\Admin\Controller', 'setMailSettings'); $this->create('settings_ajax_setsecurity', '/settings/ajax/setsecurity.php') ->actionInclude('settings/ajax/setsecurity.php'); $this->create('isadmin', '/settings/js/isadmin.js') diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 0eabffb931..d81840b5b6 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -11,6 +11,27 @@ $levelLabels = array( $l->t( 'Errors and fatal issues' ), $l->t( 'Fatal issues only' ), ); + +$mail_smtpauthtype = array( + '' => $l->t('None'), + 'LOGIN' => $l->t('Login'), + 'PLAIN' => $l->t('Plain'), + 'NTLM' => $l->t('NT LAN Manager'), +); + +$mail_smtpsecure = array( + '' => $l->t('None'), + 'ssl' => $l->t('SSL'), + 'tls' => $l->t('TLS'), +); + +$mail_smtpmode = array( + 'sendmail', + 'smtp', + 'qmail', + 'php', +); + ?> +
+

t('Email Server'));?>

+ +

t('This is used for sending out notifications.')); ?>

+ +

+ + + + + +

+ +

+ + + + /> + +

+ + + +

+ + ' /> + : + ' /> +

+ +

+ + ' /> + @ + ' /> +

+ +
+

t('Log'));?>

t('Log level'));?> - - > $name): $selected = ''; if ($secure == $_['mail_smtpsecure']): @@ -301,7 +301,14 @@ if (!$_['internetconnectionworking']) {

- + + ' /> + @ + ' /> +

+ + - -

- +

-

- - ' /> - @ - ' /> +

From 9847912257de1910f99879caac8ea925fb85caed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 26 Feb 2014 13:10:46 +0100 Subject: [PATCH 4/4] Remove unused variables, add doc blocks and break lines Fix #7166 --- core/js/js.js | 4 ++-- settings/admin/controller.php | 18 ++++++++++++++---- settings/js/admin.js | 2 +- settings/templates/admin.php | 29 ++++++++++++++++++++--------- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/core/js/js.js b/core/js/js.js index ac79f13a6d..88b70723dd 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -468,8 +468,8 @@ OC.addStyle.loaded=[]; OC.addScript.loaded=[]; OC.msg={ - startSaving:function(selector, message){ - OC.msg.startAction(selector, t('settings', 'Saving...')); + startSaving:function(selector){ + OC.msg.startAction(selector, t('core', 'Saving...')); }, finishedSaving:function(selector, data){ OC.msg.finishedAction(selector, data); diff --git a/settings/admin/controller.php b/settings/admin/controller.php index 9bbcd35658..a075d77436 100644 --- a/settings/admin/controller.php +++ b/settings/admin/controller.php @@ -20,7 +20,10 @@ namespace OC\Settings\Admin; class Controller { - public static function setMailSettings($args) { + /** + * Set mail settings + */ + public static function setMailSettings() { \OC_Util::checkAdminUser(); \OCP\JSON::callCheck(); @@ -70,14 +73,21 @@ class Controller { \OC_JSON::success(array("data" => array( "message" => $l->t("Saved") ))); } + /** + * Get the field name to use it in error messages + * + * @param $setting string + * @param $l \OC_L10N + * @return string + */ public static function getFieldname($setting, $l) { switch ($setting) { case 'mail_smtpmode': - return $l->t( 'SMTP mode' ); + return $l->t( 'Send mode' ); case 'mail_smtpsecure': - return $l->t( 'Secure SMTP' ); + return $l->t( 'Encryption' ); case 'mail_smtpauthtype': - return $l->t( 'Authentification method for SMTP' ); + return $l->t( 'Authentification method' ); } } } diff --git a/settings/js/admin.js b/settings/js/admin.js index e2bc125b8f..5ea6a5af2d 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -44,7 +44,7 @@ $(document).ready(function(){ }); $('#mail_smtpmode').change(function() { - if ($(this).val() != 'smtp') { + if ($(this).val() !== 'smtp') { $('#setting_smtpauth').addClass('hidden'); $('#setting_smtphost').addClass('hidden'); $('#mail_smtpsecure_label').addClass('hidden'); diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 377c05eb4b..139a9dd076 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -288,8 +288,12 @@ if (!$_['internetconnectionworking']) { - - > $name): $selected = ''; if ($secure == $_['mail_smtpsecure']): @@ -302,9 +306,11 @@ if (!$_['internetconnectionworking']) {

- ' /> + ' /> @ - ' /> + ' />