Merge pull request #91 from LDAPAccountManager/licenseMail
License mail
This commit is contained in:
commit
9cf564e500
|
@ -1,6 +1,7 @@
|
||||||
June 2020 7.2
|
June 2020 7.2
|
||||||
- LAM Pro:
|
- LAM Pro:
|
||||||
-> EMail sending can be done via SMTP without local mail server
|
-> 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
|
17.03.2020 7.1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
7.1
|
7.2.DEV
|
||||||
|
|
|
@ -60,6 +60,10 @@
|
||||||
<para>When you entered the license key then the license details can be
|
<para>When you entered the license key then the license details can be
|
||||||
seen on LAM configuration overview page.</para>
|
seen on LAM configuration overview page.</para>
|
||||||
|
|
||||||
|
<para>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.</para>
|
||||||
|
|
||||||
<screenshot>
|
<screenshot>
|
||||||
<mediaobject>
|
<mediaobject>
|
||||||
<imageobject>
|
<imageobject>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 70 KiB |
|
@ -237,6 +237,12 @@ $helpArray = array (
|
||||||
"Text" => _('Password to unlock SSH key file.')),
|
"Text" => _('Password to unlock SSH key file.')),
|
||||||
'287' => array ("Headline" => _('Licence'),
|
'287' => array ("Headline" => _('Licence'),
|
||||||
"Text" => _('Please enter your licence key.')),
|
"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
|
// 300 - 399
|
||||||
// profile editor, file upload
|
// profile editor, file upload
|
||||||
"301" => array ("Headline" => _("RDN identifier"),
|
"301" => array ("Headline" => _("RDN identifier"),
|
||||||
|
|
|
@ -2548,6 +2548,15 @@ class LAMCfgMain {
|
||||||
/** PHP error reporting setting as E_ALL | E_STRICT */
|
/** PHP error reporting setting as E_ALL | E_STRICT */
|
||||||
const ERROR_REPORTING_ALL = 'all';
|
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 */
|
/** Default profile */
|
||||||
public $default;
|
public $default;
|
||||||
|
|
||||||
|
@ -2617,6 +2626,18 @@ class LAMCfgMain {
|
||||||
/** license data */
|
/** license data */
|
||||||
private $license = '';
|
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) */
|
/** mail server (server:port) */
|
||||||
public $mailServer = '';
|
public $mailServer = '';
|
||||||
|
|
||||||
|
@ -2634,7 +2655,8 @@ class LAMCfgMain {
|
||||||
'passwordMustNotContainUser', 'passwordMustNotContain3Chars',
|
'passwordMustNotContainUser', 'passwordMustNotContain3Chars',
|
||||||
'externalPwdCheckUrl',
|
'externalPwdCheckUrl',
|
||||||
'errorReporting', 'encryptSession', 'allowedHostsSelfService',
|
'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)) {
|
if (!in_array("license", $saved)) {
|
||||||
array_push($file_array, "\n\n# License\n" . "license: " . $this->license);
|
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)) {
|
if (!in_array("mailServer", $saved)) {
|
||||||
array_push($file_array, "\n" . "mailServer: " . $this->mailServer);
|
array_push($file_array, "\n" . "mailServer: " . $this->mailServer);
|
||||||
}
|
}
|
||||||
|
@ -3094,12 +3128,56 @@ class LAMCfgMain {
|
||||||
/**
|
/**
|
||||||
* Sets the license key as multiple lines.
|
* Sets the license key as multiple lines.
|
||||||
*
|
*
|
||||||
* @param String $license license
|
* @param String[] $licenseLines license lines
|
||||||
*/
|
*/
|
||||||
public function setLicenseLines($licenseLines) {
|
public function setLicenseLines($licenseLines) {
|
||||||
$this->license = implode(LAMConfig::LINE_SEPARATOR, $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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -106,6 +106,17 @@ if (isset($_POST['submitFormData'])) {
|
||||||
$licenseLines = explode("\n", $_POST['license']);
|
$licenseLines = explode("\n", $_POST['license']);
|
||||||
$licenseLines = array_map('trim', $licenseLines);
|
$licenseLines = array_map('trim', $licenseLines);
|
||||||
$cfg->setLicenseLines($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
|
// set session timeout
|
||||||
$cfg->sessionTimeout = $_POST['sessionTimeout'];
|
$cfg->sessionTimeout = $_POST['sessionTimeout'];
|
||||||
|
@ -307,6 +318,30 @@ printHeaderContents(_("Edit general settings"), '../..');
|
||||||
if (isLAMProVersion()) {
|
if (isLAMProVersion()) {
|
||||||
$row->add(new htmlSubTitle(_('Licence')), 12);
|
$row->add(new htmlSubTitle(_('Licence')), 12);
|
||||||
$row->add(new htmlResponsiveInputTextarea('license', implode("\n", $cfg->getLicenseLines()), null, 10, _('Licence'), '287'), 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);
|
$row->add(new htmlSpacer(null, '1rem'), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -453,8 +453,18 @@ function display_LoginPage($licenseValidator, $error_message) {
|
||||||
<br><br>
|
<br><br>
|
||||||
<?PHP
|
<?PHP
|
||||||
if (isLAMProVersion() && $licenseValidator->isExpiringSoon()) {
|
if (isLAMProVersion() && $licenseValidator->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'));
|
$expirationDate = $licenseValidator->getLicense()->getExpirationDate()->format('Y-m-d');
|
||||||
StatusMessage('WARN', $licenseMessage);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
|
@ -71,4 +71,53 @@ class LAMCfgMainTest extends TestCase {
|
||||||
$this->assertEquals('user123', $this->conf->mailUser);
|
$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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue