diff --git a/lam/HISTORY b/lam/HISTORY index 5ee66f67..b71088c7 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -1,6 +1,7 @@ June 2020 7.2 - LAM Pro: -> EMail sending can be done via SMTP without local mail server + -> License expiration warning can be sent via email or disabled 17.03.2020 7.1 diff --git a/lam/VERSION b/lam/VERSION index 0f0fefae..610207b4 100644 --- a/lam/VERSION +++ b/lam/VERSION @@ -1 +1 @@ -7.1 +7.2.DEV diff --git a/lam/docs/manual-sources/chapter-configuration.xml b/lam/docs/manual-sources/chapter-configuration.xml index 27481c7f..cc1ce670 100644 --- a/lam/docs/manual-sources/chapter-configuration.xml +++ b/lam/docs/manual-sources/chapter-configuration.xml @@ -60,6 +60,10 @@ When you entered the license key then the license details can be seen on LAM configuration overview page. + By default, LAM Pro will show a warning message on the login page + 3 weeks before expiration. You can disable this here and/or send out an + email instead. + diff --git a/lam/docs/manual-sources/images/configGeneral7.png b/lam/docs/manual-sources/images/configGeneral7.png index dd4e1869..c0decd8d 100644 Binary files a/lam/docs/manual-sources/images/configGeneral7.png and b/lam/docs/manual-sources/images/configGeneral7.png differ diff --git a/lam/help/help.inc b/lam/help/help.inc index 5719c896..b3cbe109 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -237,6 +237,12 @@ $helpArray = array ( "Text" => _('Password to unlock SSH key file.')), '287' => array ("Headline" => _('Licence'), "Text" => _('Please enter your licence key.')), + '288' => array ("Headline" => _('Expiration warning'), + "Text" => _('Please select how to be warned before your license expires.')), + '289' => array ("Headline" => _('From address'), + "Text" => _('This email address will be set as sender address of all mails.')), + '290' => array ("Headline" => _('TO address'), + "Text" => _('This email address will be set as TO address for the mails.')), // 300 - 399 // profile editor, file upload "301" => array ("Headline" => _("RDN identifier"), diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 8637d8e0..87616d83 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -2548,6 +2548,15 @@ class LAMCfgMain { /** PHP error reporting setting as E_ALL | E_STRICT */ const ERROR_REPORTING_ALL = 'all'; + /** send license warnings via email */ + const LICENSE_WARNING_EMAIL = 'email'; + /** display license warnings on screen */ + const LICENSE_WARNING_SCREEN = 'screen'; + /** send license warnings via email + display on screen */ + const LICENSE_WARNING_ALL = 'all'; + /** no license warning */ + const LICENSE_WARNING_NONE = 'none'; + /** Default profile */ public $default; @@ -2617,6 +2626,18 @@ class LAMCfgMain { /** license data */ private $license = ''; + /** license warning email from address */ + public $licenseEmailFrom = ''; + + /** license warning email TO address */ + public $licenseEmailTo = ''; + + /** license warning email was last sent for this expiration date */ + public $licenseEmailDateSent = ''; + + /** type of license warning (email/screen/both/none) */ + public $licenseWarningType = ''; + /** mail server (server:port) */ public $mailServer = ''; @@ -2634,7 +2655,8 @@ class LAMCfgMain { 'passwordMustNotContainUser', 'passwordMustNotContain3Chars', 'externalPwdCheckUrl', 'errorReporting', 'encryptSession', 'allowedHostsSelfService', - 'license', 'mailServer', 'mailUser', 'mailPassword' + 'license', 'licenseEmailFrom', 'licenseEmailTo', 'licenseWarningType', 'licenseEmailDateSent', + 'mailServer', 'mailUser', 'mailPassword' ); /** @@ -2783,6 +2805,18 @@ class LAMCfgMain { if (!in_array("license", $saved)) { array_push($file_array, "\n\n# License\n" . "license: " . $this->license); } + if (!in_array("licenseEmailFrom", $saved)) { + array_push($file_array, "\n" . "licenseEmailFrom: " . $this->licenseEmailFrom); + } + if (!in_array("licenseEmailTo", $saved)) { + array_push($file_array, "\n" . "licenseEmailTo: " . $this->licenseEmailTo); + } + if (!in_array("licenseEmailDateSent", $saved)) { + array_push($file_array, "\n" . "licenseEmailDateSent: " . $this->licenseEmailDateSent); + } + if (!in_array("licenseWarningType", $saved)) { + array_push($file_array, "\n" . "licenseWarningType: " . $this->licenseWarningType); + } if (!in_array("mailServer", $saved)) { array_push($file_array, "\n" . "mailServer: " . $this->mailServer); } @@ -3094,12 +3128,56 @@ class LAMCfgMain { /** * Sets the license key as multiple lines. * - * @param String $license license + * @param String[] $licenseLines license lines */ public function setLicenseLines($licenseLines) { $this->license = implode(LAMConfig::LINE_SEPARATOR, $licenseLines); } + /** + * Returns the license warning type (screen/email/both/none). + * + * @return string warning type + */ + public function getLicenseWarningType() { + if (empty($this->licenseWarningType)) { + return self::LICENSE_WARNING_SCREEN; + } + return $this->licenseWarningType; + } + + /** + * Returns if the license warning should be shown on screen. + * + * @return bool show on screen + */ + public function showLicenseWarningOnScreen() { + $type = $this->getLicenseWarningType(); + return ($type === self::LICENSE_WARNING_ALL) || ($type === self::LICENSE_WARNING_SCREEN); + } + + /** + * Returns if the license warning should be sent via email. + * + * @return bool send via email + */ + public function sendLicenseWarningByEmail() { + $type = $this->getLicenseWarningType(); + return ($type === self::LICENSE_WARNING_ALL) || ($type === self::LICENSE_WARNING_EMAIL); + } + + /** + * Returns if the license warning was already sent. + * + * @param int $timeStamp time stamp + */ + public function wasLicenseWarningSent($timeStamp) { + if (empty($this->licenseEmailDateSent)) { + return false; + } + return $timeStamp == $this->licenseEmailDateSent; + } + } ?> diff --git a/lam/templates/config/mainmanage.php b/lam/templates/config/mainmanage.php index 1bc22955..5562d4f7 100644 --- a/lam/templates/config/mainmanage.php +++ b/lam/templates/config/mainmanage.php @@ -106,6 +106,17 @@ if (isset($_POST['submitFormData'])) { $licenseLines = explode("\n", $_POST['license']); $licenseLines = array_map('trim', $licenseLines); $cfg->setLicenseLines($licenseLines); + $cfg->licenseWarningType = $_POST['licenseWarningType']; + $cfg->licenseEmailFrom = $_POST['licenseEmailFrom']; + $cfg->licenseEmailTo = $_POST['licenseEmailTo']; + if ((($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_EMAIL) || ($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_ALL)) + && !get_preg($cfg->licenseEmailFrom, 'email')) { + $errors[] = _('License') . ': ' . _('From address') . ' - ' . _('Please enter a valid email address!'); + } + if ((($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_EMAIL) || ($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_ALL)) + && !get_preg($cfg->licenseEmailTo, 'email')) { + $errors[] = _('License') . ': ' . _('TO address') . ' - ' . _('Please enter a valid email address!'); + } } // set session timeout $cfg->sessionTimeout = $_POST['sessionTimeout']; @@ -307,6 +318,30 @@ printHeaderContents(_("Edit general settings"), '../..'); if (isLAMProVersion()) { $row->add(new htmlSubTitle(_('Licence')), 12); $row->add(new htmlResponsiveInputTextarea('license', implode("\n", $cfg->getLicenseLines()), null, 10, _('Licence'), '287'), 12); + $warningOptions = array( + _('Screen') => LAMCfgMain::LICENSE_WARNING_SCREEN, + _('Email') => LAMCfgMain::LICENSE_WARNING_EMAIL, + _('Both') => LAMCfgMain::LICENSE_WARNING_ALL, + _('None') => LAMCfgMain::LICENSE_WARNING_NONE, + ); + $warningTypeSelect = new htmlResponsiveSelect('licenseWarningType', $warningOptions, array($cfg->getLicenseWarningType()), _('Expiration warning'), '288'); + $warningTypeSelect->setHasDescriptiveElements(true); + $warningTypeSelect->setSortElements(false); + $warningTypeSelect->setTableRowsToHide(array( + LAMCfgMain::LICENSE_WARNING_SCREEN => array('licenseEmailFrom', 'licenseEmailTo'), + LAMCfgMain::LICENSE_WARNING_NONE => array('licenseEmailFrom', 'licenseEmailTo'), + )); + $warningTypeSelect->setTableRowsToShow(array( + LAMCfgMain::LICENSE_WARNING_EMAIL => array('licenseEmailFrom', 'licenseEmailTo'), + LAMCfgMain::LICENSE_WARNING_ALL => array('licenseEmailFrom', 'licenseEmailTo'), + )); + $row->add($warningTypeSelect, 12); + $licenseFrom = new htmlResponsiveInputField(_('From address'), 'licenseEmailFrom', $cfg->licenseEmailFrom, '289'); + $licenseFrom->setRequired(true); + $row->add($licenseFrom, 12); + $licenseTo = new htmlResponsiveInputField(_('TO address'), 'licenseEmailTo', $cfg->licenseEmailTo, '290'); + $licenseTo->setRequired(true); + $row->add($licenseTo, 12); $row->add(new htmlSpacer(null, '1rem'), true); } diff --git a/lam/templates/login.php b/lam/templates/login.php index 4ff31b6e..4cb74df6 100644 --- a/lam/templates/login.php +++ b/lam/templates/login.php @@ -453,8 +453,18 @@ function display_LoginPage($licenseValidator, $error_message) {

isExpiringSoon()) { - $licenseMessage = sprintf(_('Your licence expires on %s. You need to purchase a new licence to be able to use LAM Pro after this date.'), $licenseValidator->getLicense()->getExpirationDate()->format('Y-m-d')); - StatusMessage('WARN', $licenseMessage); + $expirationDate = $licenseValidator->getLicense()->getExpirationDate()->format('Y-m-d'); + $expirationTimeStamp = $licenseValidator->getLicense()->getExpirationDate()->getTimestamp(); + if ($cfgMain->showLicenseWarningOnScreen()) { + $licenseMessage = sprintf(_('Your licence expires on %s. You need to purchase a new licence to be able to use LAM Pro after this date.'), $expirationDate); + StatusMessage('WARN', $licenseMessage); + } + if ($cfgMain->sendLicenseWarningByEmail() && !$cfgMain->wasLicenseWarningSent($expirationTimeStamp)) { + $cfgMain->licenseEmailDateSent = $expirationTimeStamp; + $cfgMain->save(); + $mailer = new \LAM\ENV\LicenseWarningMailer($cfgMain); + $mailer->sendMail($expirationDate); + } } ?>

diff --git a/lam/tests/lib/LAMCfgMainTest.php b/lam/tests/lib/LAMCfgMainTest.php index 827c3213..aa4b2d64 100644 --- a/lam/tests/lib/LAMCfgMainTest.php +++ b/lam/tests/lib/LAMCfgMainTest.php @@ -71,4 +71,53 @@ class LAMCfgMainTest extends TestCase { $this->assertEquals('user123', $this->conf->mailUser); } + /** + * License related settings. + */ + public function testLicense() { + $timestamp = '12345'; + $this->assertEquals(LAMCfgMain::LICENSE_WARNING_SCREEN, $this->conf->getLicenseWarningType()); + $this->assertFalse($this->conf->wasLicenseWarningSent($timestamp)); + $this->conf->licenseEmailTo = 'TO'; + $this->conf->licenseEmailFrom = 'FROM'; + $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_ALL; + $this->conf->setLicenseLines(array('123', '456')); + $this->conf->licenseEmailDateSent = $timestamp; + + $this->conf->save(); + $this->conf = new LAMCfgMain($this->file); + + $this->assertEquals('TO', $this->conf->licenseEmailTo); + $this->assertEquals('FROM', $this->conf->licenseEmailFrom); + $this->assertEquals($timestamp, $this->conf->licenseEmailDateSent); + $this->assertTrue($this->conf->wasLicenseWarningSent($timestamp)); + $this->assertEquals(LAMCfgMain::LICENSE_WARNING_ALL, $this->conf->licenseWarningType); + $this->assertEquals(array('123', '456'), $this->conf->getLicenseLines()); + } + + /** + * License warning type related settings. + */ + public function testLicenseWarningTypes() { + $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_ALL; + + $this->assertTrue($this->conf->sendLicenseWarningByEmail()); + $this->assertTrue($this->conf->showLicenseWarningOnScreen()); + + $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_EMAIL; + + $this->assertTrue($this->conf->sendLicenseWarningByEmail()); + $this->assertFalse($this->conf->showLicenseWarningOnScreen()); + + $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_SCREEN; + + $this->assertFalse($this->conf->sendLicenseWarningByEmail()); + $this->assertTrue($this->conf->showLicenseWarningOnScreen()); + + $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_NONE; + + $this->assertFalse($this->conf->sendLicenseWarningByEmail()); + $this->assertFalse($this->conf->showLicenseWarningOnScreen()); + } + } \ No newline at end of file