From 028f8adcfdd7cdca01a76f47a418f35585395b8e Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 28 Mar 2020 21:34:58 +0100 Subject: [PATCH] configurable license warning --- lam/lib/config.inc | 50 ++++++++++++++++++++++++++++++-- lam/tests/lib/LAMCfgMainTest.php | 21 ++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 8637d8e0..65db3327 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 addresses (comma separated) */ + 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,24 @@ 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; + } + } ?> diff --git a/lam/tests/lib/LAMCfgMainTest.php b/lam/tests/lib/LAMCfgMainTest.php index 827c3213..7a41aceb 100644 --- a/lam/tests/lib/LAMCfgMainTest.php +++ b/lam/tests/lib/LAMCfgMainTest.php @@ -71,4 +71,25 @@ class LAMCfgMainTest extends TestCase { $this->assertEquals('user123', $this->conf->mailUser); } + /** + * License related settings. + */ + public function testLicense() { + $this->assertEquals(LAMCfgMain::LICENSE_WARNING_SCREEN, $this->conf->getLicenseWarningType()); + $this->conf->licenseEmailTo = 'TO'; + $this->conf->licenseEmailFrom = 'FROM'; + $this->conf->licenseEmailDateSent = 'date'; + $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_ALL; + $this->conf->setLicenseLines(array('123', '456')); + + $this->conf->save(); + $this->conf = new LAMCfgMain($this->file); + + $this->assertEquals('TO', $this->conf->licenseEmailTo); + $this->assertEquals('FROM', $this->conf->licenseEmailFrom); + $this->assertEquals('date', $this->conf->licenseEmailDateSent); + $this->assertEquals(LAMCfgMain::LICENSE_WARNING_ALL, $this->conf->licenseWarningType); + $this->assertEquals(array('123', '456'), $this->conf->getLicenseLines()); + } + } \ No newline at end of file