-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(initialversion-single-lifetime-license-support)
- Loading branch information
1 parent
9bc5931
commit dba2943
Showing
12 changed files
with
478 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<name>Sendent</name> | ||
<summary lang="en">Sendent allows you to securely exchange files and emails</summary> | ||
<description lang="en">Sendent allows you to securely exchange files and emails. Sendent is linked to Microsoft Outlook, so you can continue to work from your trusted email program while you mail more easily and securely. Very useful, for example, to share privacy-sensitive documents or content or to send attachments that are normally too large to email. All files are uploaded to your personal Nextcloud environment from which you determine who has access to them.</description> | ||
<version>2.0.4</version> | ||
<version>2.0.5</version> | ||
<licence>agpl</licence> | ||
<author mail="[email protected]" homepage="https://www.sendent.nl">Sendent B.V.</author> | ||
<namespace>Sendent</namespace> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,43 @@ public function show(): DataResponse { | |
} | ||
|
||
} | ||
/** | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* Returns license status for current user | ||
* | ||
* @return DataResponse | ||
*/ | ||
public function showInternal(): DataResponse { | ||
|
||
$this->logger->info('Getting license information for user ' . $this->userId); | ||
|
||
// Gets groups for which specific settings and/or license are defined | ||
// Groups are ordered from highest priority to lowest | ||
$sendentGroups = $this->appConfig->getAppValue('sendentGroups', ''); | ||
$sendentGroups = $sendentGroups !== '' ? json_decode($sendentGroups) : []; | ||
|
||
// Gets user groups | ||
$user = $this->userManager->get($this->userId); | ||
$userGroups = $this->groupManager->getUserGroups($user); | ||
$userGroups = array_map(function ($group) { | ||
return $group->getGid(); | ||
}, $userGroups); | ||
|
||
// Gets user groups that are sendentGroups | ||
$userSendentGroups = array_intersect($sendentGroups, $userGroups); | ||
|
||
// Returns settings for 1st matching group | ||
if (count($userSendentGroups)) { | ||
$this->logger->info('First matching group of user ' . $this->userId . ' is ' . $userSendentGroups[array_keys($userSendentGroups)[0]]); | ||
return $this->showForNCGroup($userSendentGroups[array_keys($userSendentGroups)[0]]); | ||
} else { | ||
$this->logger->info('User ' . $this->userId . ' is not member of any sendent group'); | ||
return $this->showForNCGroup(''); | ||
} | ||
|
||
} | ||
/** | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
|
@@ -146,16 +182,17 @@ public function showForNCGroup(string $ncgroup = ''): DataResponse { | |
if (is_array($result) && count($result) > 0 | ||
&& $result[0]->getLevel() != "Error_clear" && $result[0]->getLevel() != "Error_incomplete") { | ||
} else { | ||
throw new Exception(); | ||
//throw new Exception(); | ||
} | ||
} | ||
} catch (Exception $e) { | ||
$this->logger->error('Error while renewing license ' . $result[0]->getId()); | ||
$this->logger->error('Error while renewing license ' . $result[0]->getId() . '\r\n' . $e); | ||
} | ||
|
||
// Reports license status | ||
$email = $result[0]->getEmail(); | ||
$licensekey = $result[0]->getLicensekey(); | ||
$licensekey = $result[0]->getLicensekeytoken(); | ||
$this->logger->info('License key returned is: ' . $licensekey); | ||
$dateExpiration = $result[0]->getDatelicenseend(); | ||
$dateLastCheck = $result[0]->getDatelastchecked(); | ||
$level = $result[0]->getLevel(); | ||
|
@@ -166,58 +203,216 @@ public function showForNCGroup(string $ncgroup = ''): DataResponse { | |
if ($result[0]->isCleared()) { | ||
$status = $this->l->t("No license configured"); | ||
$statusKind = "nolicense"; | ||
} elseif ($result[0]->isIncomplete()) { | ||
} | ||
elseif ($result[0]->isIncomplete()) { | ||
$status = $this->l->t("Missing email address or license key."); | ||
$statusKind = "error_incomplete"; | ||
} elseif ($result[0]->isCheckNeeded()) { | ||
} | ||
elseif ($result[0]->isCheckNeeded()) { | ||
$status = $this->l->t("Revalidation of your license is required"); | ||
$statusKind = "check"; | ||
} elseif ($result[0]->isLicenseExpired()) { | ||
} | ||
elseif ($result[0]->isLicenseRenewedOrSwitched()) { | ||
$status = $this->l->t("Current license has been changed.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s if you experience issues with configuring your license key.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "check"; | ||
} | ||
elseif ($result[0]->isLicenseInactive()) { | ||
$status = $this->l->t("Current license has been deactivated by Sendent.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s for more information.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "check"; | ||
} | ||
elseif ($result[0]->isLicenseSuspended()) { | ||
$status = $this->l->t("Current license has been suspended by Sendent.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s for more information.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "check"; | ||
} | ||
elseif ($result[0]->isLicenseExpired()) { | ||
$status = $this->l->t("Current license has expired.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s if you experience issues with configuring your license key.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "expired"; | ||
} elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired()) { | ||
} | ||
elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired()) { | ||
$status = $this->l->t("Current license is valid"); | ||
$statusKind = "valid"; | ||
} elseif (!$this->licensemanager->isWithinUserCount($result[0]) && $this->licensemanager->isWithinGraceUserCount($result[0])) { | ||
} | ||
elseif (!$this->licensemanager->isWithinUserCount($result[0]) && $this->licensemanager->isWithinGraceUserCount($result[0])) { | ||
$status = $this->l->t("Current amount of active users exceeds licensed amount. Some users might not be able to use Sendent."); | ||
$statusKind = "userlimit"; | ||
} elseif (!$this->licensemanager->isWithinUserCount($result[0]) && !$this->licensemanager->isWithinGraceUserCount($result[0])) { | ||
} | ||
elseif (!$this->licensemanager->isWithinUserCount($result[0]) && !$this->licensemanager->isWithinGraceUserCount($result[0])) { | ||
$status = $this->l->t("Current amount of active users exceeds licensed amount. Additional users trying to use Sendent will be prevented from doing so."); | ||
$statusKind = "userlimit"; | ||
} | ||
return new DataResponse(new LicenseStatus($status, $statusKind, $level,$licensekey, $dateExpiration, $dateLastCheck, $email, $group)); | ||
} elseif (count($result) > 0 && $result[0]->getLevel() == "Error_incomplete") { | ||
} | ||
elseif (count($result) > 0 && $result[0]->getLevel() == "Error_incomplete") { | ||
$email = $result[0]->getEmail(); | ||
$licensekey = $result[0]->getLicensekey(); | ||
$group = $result[0]->getNcgroup(); | ||
$status = $this->l->t('Missing (or incorrect) email address or license key. %1$sContact support%2$s to get your correct license information.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
return new DataResponse(new LicenseStatus($status, "error_incomplete" ,"-", $licensekey, "-", "-", $email, $group)); | ||
} elseif (count($result) > 0 && $result[0]->getLevel() == License::ERROR_VALIDATING) { | ||
} | ||
elseif (count($result) > 0 && $result[0]->getLevel() == License::ERROR_VALIDATING) { | ||
$email = $result[0]->getEmail(); | ||
$licensekey = $result[0]->getLicensekey(); | ||
$group = $result[0]->getNcgroup(); | ||
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "error_validating","-", $licensekey, "-", "-", $email, $group)); | ||
} else { | ||
} | ||
else { | ||
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-")); | ||
} | ||
} else { | ||
} | ||
else { | ||
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-")); | ||
} | ||
} catch (Exception $e) { | ||
$this->logger->error('Cannot verify license'); | ||
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "fatal" ,"-", "-", "-", "-", "-")); | ||
} | ||
} | ||
/** | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* Returns license status for group $ncgroup | ||
* | ||
* @param string $ncgroup | ||
* @return DataResponse | ||
*/ | ||
public function showForNCGroupInternal(string $ncgroup = ''): DataResponse { | ||
|
||
if ($ncgroup === "") { | ||
$this->logger->info('Getting license information for default group'); | ||
} else { | ||
$this->logger->info('Getting license information for group ' . $ncgroup); | ||
} | ||
|
||
try { | ||
// Gets license for group $ncgroup | ||
$result = $this->service->findByGroup($ncgroup); | ||
if (isset($result) && $result !== null && $result !== false && is_array($result) && count($result) === 0) { | ||
// No license for group $ncgroup, getting default license | ||
$result = $this->service->findByGroup(''); | ||
} | ||
|
||
if (isset($result) && $result !== null && $result !== false) { | ||
if (is_array($result) && count($result) > 0 | ||
&& $result[0]->getLevel() != "Error_clear" && $result[0]->getLevel() != "Error_incomplete") { | ||
|
||
|
||
$this->logger->info('Check needed for license ' . $result[0]->getId()); | ||
try { | ||
$this->licensemanager->renewLicense($result[0]); | ||
$result = $this->service->findByGroup($result[0]->getNcgroup()); | ||
if (isset($result) && $result !== null && $result !== false) { | ||
if (is_array($result) && count($result) > 0 | ||
&& $result[0]->getLevel() != "Error_clear" && $result[0]->getLevel() != "Error_incomplete") { | ||
} else { | ||
//throw new Exception(); | ||
} | ||
} | ||
} catch (Exception $e) { | ||
$this->logger->error('Error while renewing license ' . $result[0]->getId() . '\r\n' . $e); | ||
} | ||
|
||
// Reports license status | ||
$email = $result[0]->getEmail(); | ||
$licensekey = $result[0]->getLicensekey(); | ||
$this->logger->info('License key returned is: ' . $licensekey); | ||
$dateExpiration = $result[0]->getDatelicenseend(); | ||
$dateLastCheck = $result[0]->getDatelastchecked(); | ||
$level = $result[0]->getLevel(); | ||
$group = $result[0]->getNcgroup(); | ||
$statusKind = ""; | ||
$status = ""; | ||
|
||
if ($result[0]->isCleared()) { | ||
$status = $this->l->t("No license configured"); | ||
$statusKind = "nolicense"; | ||
} | ||
elseif ($result[0]->isIncomplete()) { | ||
$status = $this->l->t("Missing email address or license key."); | ||
$statusKind = "error_incomplete"; | ||
} | ||
elseif ($result[0]->isCheckNeeded()) { | ||
$status = $this->l->t("Revalidation of your license is required"); | ||
$statusKind = "check"; | ||
} | ||
elseif ($result[0]->isLicenseRenewedOrSwitched()) { | ||
$status = $this->l->t("Current license has been changed.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s if you experience issues with configuring your license key.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "check"; | ||
} | ||
elseif ($result[0]->isLicenseInactive()) { | ||
$status = $this->l->t("Current license has been deactivated by Sendent.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s for more information.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "check"; | ||
} | ||
elseif ($result[0]->isLicenseSuspended()) { | ||
$status = $this->l->t("Current license has been suspended by Sendent.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s for more information.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "check"; | ||
} | ||
elseif ($result[0]->isLicenseExpired()) { | ||
$status = $this->l->t("Current license has expired.") . | ||
"</br>" . | ||
$this->l->t('%1$sContact support%2$s if you experience issues with configuring your license key.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
$statusKind = "expired"; | ||
} | ||
elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired()) { | ||
$status = $this->l->t("Current license is valid"); | ||
$statusKind = "valid"; | ||
} | ||
elseif (!$this->licensemanager->isWithinUserCount($result[0]) && $this->licensemanager->isWithinGraceUserCount($result[0])) { | ||
$status = $this->l->t("Current amount of active users exceeds licensed amount. Some users might not be able to use Sendent."); | ||
$statusKind = "userlimit"; | ||
} | ||
elseif (!$this->licensemanager->isWithinUserCount($result[0]) && !$this->licensemanager->isWithinGraceUserCount($result[0])) { | ||
$status = $this->l->t("Current amount of active users exceeds licensed amount. Additional users trying to use Sendent will be prevented from doing so."); | ||
$statusKind = "userlimit"; | ||
} | ||
return new DataResponse(new LicenseStatus($status, $statusKind, $level,$licensekey, $dateExpiration, $dateLastCheck, $email, $group)); | ||
} | ||
elseif (count($result) > 0 && $result[0]->getLevel() == "Error_incomplete") { | ||
$email = $result[0]->getEmail(); | ||
$licensekey = $result[0]->getLicensekey(); | ||
$group = $result[0]->getNcgroup(); | ||
$status = $this->l->t('Missing (or incorrect) email address or license key. %1$sContact support%2$s to get your correct license information.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]); | ||
return new DataResponse(new LicenseStatus($status, "error_incomplete" ,"-", $licensekey, "-", "-", $email, $group)); | ||
} | ||
elseif (count($result) > 0 && $result[0]->getLevel() == License::ERROR_VALIDATING) { | ||
$email = $result[0]->getEmail(); | ||
$licensekey = $result[0]->getLicensekey(); | ||
$group = $result[0]->getNcgroup(); | ||
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "error_validating","-", $licensekey, "-", "-", $email, $group)); | ||
} | ||
else { | ||
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-")); | ||
} | ||
} | ||
else { | ||
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-")); | ||
} | ||
} catch (Exception $e) { | ||
$this->logger->error('Cannot verify license'); | ||
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "fatal" ,"-", "-", "-", "-", "-")); | ||
} | ||
} | ||
/** | ||
* @param string $license | ||
* @param string $email | ||
* @param string $ncgroup | ||
*/ | ||
public function create(string $license, string $email, string $ncgroup) { | ||
return $this->licensemanager->createLicense($license, $email, $ncgroup); | ||
return $this->licensemanager->createLicense($license, '','', $email, $ncgroup); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.