diff --git a/lam/help/help.inc b/lam/help/help.inc index f7fbf00d..fee47b77 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -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.') diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 90f86732..91098b0e 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -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 */ diff --git a/lam/lib/config.inc b/lam/lib/config.inc index cba83e0a..409553bf 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -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++) { diff --git a/lam/templates/config/mainmanage.php b/lam/templates/config/mainmanage.php index 6d444a01..633e4daf 100644 --- a/lam/templates/config/mainmanage.php +++ b/lam/templates/config/mainmanage.php @@ -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' diff --git a/lam/tests/lib/LAMCfgMainTest.php b/lam/tests/lib/LAMCfgMainTest.php new file mode 100644 index 00000000..207759d4 --- /dev/null +++ b/lam/tests/lib/LAMCfgMainTest.php @@ -0,0 +1,76 @@ +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); + } + +} \ No newline at end of file