new mail server options

This commit is contained in:
Roland Gruber 2020-03-09 21:40:15 +01:00
parent 44dff694c4
commit 0f40ba18c0
5 changed files with 128 additions and 5 deletions

View File

@ -181,6 +181,12 @@ $helpArray = array (
"Text" => _("Please enter the syslog remote server in format \"server:port\".")),
"252" => array ("Headline" => _("User DN"),
"Text" => _("Please enter a part of the user's DN to search for registered devices.")),
"253" => array ("Headline" => _("Mail server"),
"Text" => _("Please enter the server name and port of your SMTP server (e.g. localhost:25). If this setting is left empty then LAM will try to use a locally installed mail server. The server must support TLS.")),
"254" => array ("Headline" => _("User name"),
"Text" => _("SMTP user name")),
"255" => array ("Headline" => _("Password"),
"Text" => _("SMTP password")),
"260" => array ("Headline" => _("Additional LDAP filter"),
"Text" => _('Use this to enter an additional LDAP filter (e.g. "(cn!=admin)") to reduce the number of visible elements for this account type.')
. ' ' . _('You can use the wildcard @@LOGIN_DN@@ which will be substituted with the DN of the user who is currently logged in to LAM.')

View File

@ -638,6 +638,9 @@ function get_preg($argument, $regexp) {
case 'quotaNumber':
$pregexpr = '/^[[:digit:]]+[KMGTkmgt]?$/';
break;
case 'hostAndPort':
$pregexpr = '/^[[:alnum:]\\._-]+:[[:digit:]]+$/';
break;
}
if (($pregexpr != '') && preg_match($pregexpr, $argument)) {
/* Bug in php preg_match doesn't work correct with utf8 */

View File

@ -2620,6 +2620,15 @@ class LAMCfgMain {
/** license data */
private $license = '';
/** mail server (server:port) */
public $mailServer = '';
/** mail server user */
public $mailUser = '';
/** mail server password */
public $mailPassword = '';
/** list of data fields to save in config file */
private $settings = array("password", "default", "sessionTimeout",
"logLevel", "logDestination", "allowedHosts", "passwordMinLength",
@ -2628,14 +2637,21 @@ class LAMCfgMain {
'passwordMustNotContainUser', 'passwordMustNotContain3Chars',
'externalPwdCheckUrl',
"mailEOL", 'errorReporting', 'encryptSession', 'allowedHostsSelfService',
'license'
'license', 'mailServer', 'mailUser', 'mailPassword'
);
/**
* Loads preferences from config file
*
* @param string $fileName file path for config file
*/
function __construct() {
$this->conffile = __DIR__ . "/../config/config.cfg";
function __construct($fileName = null) {
if ($fileName === null) {
$this->conffile = __DIR__ . "/../config/config.cfg";
}
else {
$this->conffile = $fileName;
}
// set default values
$this->sessionTimeout = 30;
$this->logLevel = LOG_NOTICE;
@ -2773,6 +2789,15 @@ class LAMCfgMain {
if (!in_array("license", $saved)) {
array_push($file_array, "\n\n# License\n" . "license: " . $this->license);
}
if (!in_array("mailServer", $saved)) {
array_push($file_array, "\n" . "mailServer: " . $this->mailServer);
}
if (!in_array("mailUser", $saved)) {
array_push($file_array, "\n" . "mailUser: " . $this->mailUser);
}
if (!in_array("mailPassword", $saved)) {
array_push($file_array, "\n" . "mailPassword: " . $this->mailPassword);
}
$file = @fopen($this->conffile, "w");
if ($file) {
for ($i = 0; $i < sizeof($file_array); $i++) {

View File

@ -246,6 +246,12 @@ if (isset($_POST['submitFormData'])) {
// mail EOL
if (isLAMProVersion()) {
$cfg->mailEOL = $_POST['mailEOL'];
$cfg->mailUser = $_POST['mailUser'];
$cfg->mailPassword = $_POST['mailPassword'];
$cfg->mailServer = $_POST['mailServer'];
if (!empty($cfg->mailServer) && !get_preg($cfg->mailServer, 'hostAndPort')) {
$errors[] = _('Please enter the mail server with host name and port.');
}
}
$cfg->errorReporting = $_POST['errorReporting'];
// save settings
@ -452,9 +458,16 @@ printHeaderContents(_("Edit general settings"), '../..');
$errorLogSelect->setHasDescriptiveElements(true);
$row->add($errorLogSelect, 12);
// additional options
// mail options
if (isLAMProVersion()) {
$row->add(new htmlSubTitle(_('Additional options')), 12);
$row->add(new htmlSubTitle(_('Mail options')), 12);
$mailServer = new htmlResponsiveInputField(_("Mail server"), 'mailServer', $cfg->mailServer, '253');
$row->add($mailServer, 12);
$mailUser = new htmlResponsiveInputField(_("User name"), 'mailUser', $cfg->mailUser, '254');
$row->add($mailUser, 12);
$mailPassword = new htmlResponsiveInputField(_("Password"), 'mailPassword', $cfg->mailPassword, '255');
$mailPassword->setIsPassword(true);
$row->add($mailPassword, 12);
$mailEOLOptions = array(
_('Default (\r\n)') => 'default',
_('Non-standard (\n)') => 'unix'

View File

@ -0,0 +1,76 @@
<?php
use PHPUnit\Framework\TestCase;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2020 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
include_once __DIR__ . '/../../lib/config.inc';
/**
* LAMConfig test case.
*
* @author Roland Gruber
*/
class LAMConfigTest extends TestCase {
private $conf;
private $file;
/**
* Prepares the environment before running a test.
*/
protected function setUp(): void {
parent::setUp();
$tmpFile = tmpfile();
$this->file = stream_get_meta_data($tmpFile)['uri'];
fclose($tmpFile);
$tmpFile = fopen($this->file, 'w+');
fwrite($tmpFile, "\n");
fclose($tmpFile);
$this->conf = new LAMCfgMain($this->file);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown(): void {
$this->conf = null;
//unlink($this->file);
}
/**
* Mail related settings
*/
public function testMail() {
$this->conf->mailEOL = 'unix123';
$this->conf->mailServer = 'server:123';
$this->conf->mailPassword = 'pwd123';
$this->conf->mailUser = 'user123';
$this->conf->save();
$this->conf = new LAMCfgMain($this->file);
$this->assertEquals('unix123', $this->conf->mailEOL);
$this->assertEquals('server:123', $this->conf->mailServer);
$this->assertEquals('pwd123', $this->conf->mailPassword);
$this->assertEquals('user123', $this->conf->mailUser);
}
}