Merge pull request #7174 from owncloud/issue/7166

Add option to change email settings in admin section
This commit is contained in:
Jan-Christoph Borchardt 2014-02-26 14:41:07 +01:00
commit d9a153dbe9
9 changed files with 279 additions and 44 deletions

View File

@ -7,28 +7,6 @@
* See the COPYING-README file.
*/
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');
}
}
};
$(document).ready(function(){
// Trigger ajax on recoveryAdmin status change
var enabledStatus = $('#adminEnableRecovery').val();

View File

@ -467,6 +467,34 @@ OC.search.lastResults={};
OC.addStyle.loaded=[];
OC.addScript.loaded=[];
OC.msg={
startSaving:function(selector){
OC.msg.startAction(selector, t('core', 'Saving...'));
},
finishedSaving:function(selector, data){
OC.msg.finishedAction(selector, data);
},
startAction:function(selector, message){
$(selector)
.html( message )
.removeClass('success')
.removeClass('error')
.stop(true, true)
.show();
},
finishedAction: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');
}
}
};
OC.Notification={
queuedNotifications: [],
getDefaultNotificationFunction: null,

View File

@ -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);

View File

@ -0,0 +1,93 @@
<?php
/**
* @author Joas Schilling
* @copyright 2014 Joas Schilling nickvergessen@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OC\Settings\Admin;
class Controller {
/**
* Set mail settings
*/
public static function setMailSettings() {
\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") )));
}
/**
* 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( 'Send mode' );
case 'mail_smtpsecure':
return $l->t( 'Encryption' );
case 'mail_smtpauthtype':
return $l->t( 'Authentification method' );
}
}
}

View File

@ -155,6 +155,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;}

View File

@ -34,4 +34,38 @@ $(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').addClass('hidden');
} else {
$('#mail_credentials').removeClass('hidden');
}
});
$('#mail_smtpmode').change(function() {
if ($(this).val() !== 'smtp') {
$('#setting_smtpauth').addClass('hidden');
$('#setting_smtphost').addClass('hidden');
$('#mail_smtpsecure_label').addClass('hidden');
$('#mail_smtpsecure').addClass('hidden');
$('#mail_credentials').addClass('hidden');
} else {
$('#setting_smtpauth').removeClass('hidden');
$('#setting_smtphost').removeClass('hidden');
$('#mail_smtpsecure_label').removeClass('hidden');
$('#mail_smtpsecure').removeClass('hidden');
if ($('#mail_smtpauth').attr('checked')) {
$('#mail_credentials').removeClass('hidden');
}
}
});
$('#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);
});
});
});

View File

@ -315,25 +315,3 @@ OC.Encryption.msg={
}
}
};
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');
}
}
};

View File

@ -70,5 +70,8 @@ $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');

View File

@ -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',
);
?>
<?php
@ -250,6 +271,84 @@ if (!$_['internetconnectionworking']) {
</table>
</fieldset>
<fieldset id="mail_settings" class="personalblock">
<h2><?php p($l->t('Email Server'));?> <span class="msg"></span></h2>
<p><?php p($l->t('This is used for sending out notifications.')); ?></p>
<p>
<label for="mail_smtpmode"><?php p($l->t( 'Send mode' )); ?></label>
<select name='mail_smtpmode' id='mail_smtpmode'>
<?php foreach ($mail_smtpmode as $smtpmode):
$selected = '';
if ($smtpmode == $_['mail_smtpmode']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($smtpmode)?>' <?php p($selected) ?>><?php p($smtpmode) ?></option>
<?php endforeach;?>
</select>
<label id="mail_smtpsecure_label" for="mail_smtpsecure"
<?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<?php p($l->t( 'Encryption' )); ?>
</label>
<select name="mail_smtpsecure" id="mail_smtpsecure"
<?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<?php foreach ($mail_smtpsecure as $secure => $name):
$selected = '';
if ($secure == $_['mail_smtpsecure']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($secure)?>' <?php p($selected) ?>><?php p($name) ?></option>
<?php endforeach;?>
</select>
</p>
<p>
<label for="mail_from_address"><?php p($l->t( 'From address' )); ?></label>
<input type="text" name='mail_from_address' id="mail_from_address" placeholder="<?php p('mail')?>"
value='<?php p($_['mail_from_address']) ?>' />
@
<input type="text" name='mail_domain' id="mail_domain" placeholder="<?php p('example.com')?>"
value='<?php p($_['mail_domain']) ?>' />
</p>
<p id="setting_smtpauth" <?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtpauthtype"><?php p($l->t( 'Authentification method' )); ?></label>
<select name='mail_smtpauthtype' id='mail_smtpauthtype'>
<?php foreach ($mail_smtpauthtype as $authtype => $name):
$selected = '';
if ($authtype == $_['mail_smtpauthtype']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($authtype)?>' <?php p($selected) ?>><?php p($name) ?></option>
<?php endforeach;?>
</select>
<input type="checkbox" name="mail_smtpauth" id="mail_smtpauth" value="1"
<?php if ($_['mail_smtpauth']) print_unescaped('checked="checked"'); ?> />
<label for="mail_smtpauth"><?php p($l->t( 'Authentication required' )); ?></label>
</p>
<p id="setting_smtphost" <?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtphost"><?php p($l->t( 'Server address' )); ?></label>
<input type="text" name='mail_smtphost' id="mail_smtphost" placeholder="<?php p('smtp.example.com')?>"
value='<?php p($_['mail_smtphost']) ?>' />
:
<input type="text" name='mail_smtpport' id="mail_smtpport" placeholder="<?php p($l->t('Port'))?>"
value='<?php p($_['mail_smtpport']) ?>' />
</p>
<p id="mail_credentials" <?php if (!$_['mail_smtpauth'] || $_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtpname"><?php p($l->t( 'Credentials' )); ?></label>
<input type="text" name='mail_smtpname' id="mail_smtpname" placeholder="<?php p($l->t('SMTP Username'))?>"
value='<?php p($_['mail_smtpname']) ?>' />
<input type="password" name='mail_smtppassword' id="mail_smtppassword"
placeholder="<?php p($l->t('SMTP Password'))?>" value='<?php p($_['mail_smtppassword']) ?>' />
</p>
</fieldset>
<fieldset class="personalblock">
<h2><?php p($l->t('Log'));?></h2>
<?php p($l->t('Log level'));?> <select name='loglevel' id='loglevel'>