Skip to content

Commit

Permalink
feature(license-validation-fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonvandebroek committed Nov 25, 2023
1 parent dba2943 commit 57f32f1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<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.5</version>
<licence>agpl</licence>
<version>2.0.6</version>
<licence>agplv3</licence>
<author mail="[email protected]" homepage="https://www.sendent.nl">Sendent B.V.</author>
<namespace>Sendent</namespace>

Expand Down
15 changes: 13 additions & 2 deletions lib/Controller/LicenseApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,12 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
elseif (count($result) > 0 && $result[0]->getLevel() == License::ERROR_VALIDATING) {
$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();
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));
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",$level, $licensekey, $dateExpiration, $dateLastCheck, $email, $group));
}
else {
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-"));
Expand All @@ -403,7 +407,14 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
}
} 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" ,"-", "-", "-", "-", "-"));
$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();
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" ,$level, $licensekey, $dateExpiration, $dateLastCheck, $email, $group));
}
}
/**
Expand Down
10 changes: 8 additions & 2 deletions lib/Controller/StatusApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function index(): DataResponse {
$statusobj->maxusersgrace = 0;
$statusobj->maxusers = 0;
$statusobj->currentusers = 0;
$statusobj->validlicense = false;

$statusobj->validLicense = false;
try{
// Finds out user's license
$result = $this->licenseservice->findUserLicense($this->userId);

Expand All @@ -65,7 +65,9 @@ public function index(): DataResponse {

// Renews license if needed
if ($result->isCheckNeeded()) {

$result = $this->licensemanager->renewLicense($result);

}

// Gets all license status information
Expand Down Expand Up @@ -97,6 +99,10 @@ public function index(): DataResponse {
}
}

}
catch (Exception $e) {

}
// Returns license status
return new DataResponse($statusobj);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Http/AppVersionHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ public function latest($assembly): ?AppVersionResponse {

return $appVersionResponse;
}
else{
return new AppVersionResponse();
}
} catch (Exception $e) {
$this->logger->error('AppVersionHttpClient-latest-EXCEPTION: ' . $e->getMessage(), [
'exception' => $e,
]);
return null;
return new AppVersionResponse();
}
}
}
3 changes: 2 additions & 1 deletion lib/Http/LicenseHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class LicenseHttpClient {
protected $baseUrl;

//public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "https://api.scwcloud.sendent.nl/") {
public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "http://127.0.0.1:8085/") {
public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "https://api.scwcloud.sendent.dev/") {
//public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "http://127.0.0.1:8085/") {
$this->client = $clientService->newClient();
$this->logger = $logger;
$this->baseUrl = $baseUrl;
Expand Down
12 changes: 9 additions & 3 deletions lib/Service/LicenseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function pingLicensing(License $license): void {
try {
error_log(print_r('Pinging licensing server with license ' . $license->getId(), true));
$this->logger->info('Pinging licensing server with license ' . $license->getId());
$license = $this->subscriptionvalidationhttpclient->validate($license);
$pingResultLicense = $this->subscriptionvalidationhttpclient->validate($license);
} catch (Exception $e) {
$this->logger->error('Error while pinging licensing server');
}
Expand Down Expand Up @@ -92,7 +92,10 @@ public function renewLicense(License $license) {
$license->getNcgroup()
);
}
} else {
} else if($this->isLocalValid($license)){
return $license;
}
else{
$license = new License();
$license->setLevel("nolicense");
return $license;
Expand Down Expand Up @@ -157,7 +160,10 @@ public function activateLicense(License $license) {
$level,
$license->getNcgroup()
);
} else {
} else if($this->isLocalValid($license)){
return $license;
}
else{
$license = new License();
$license->setLevel("nolicense");
return $license;
Expand Down
6 changes: 6 additions & 0 deletions lib/Service/LicenseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ public function findUserLicense(string $userId) {
return null;
} else {
$this->logger->debug('Found license: ' . $license[0]->getId());
if ($this->valueIsLicenseKeyFilePath($license[0]->getLicensekey()) !== false) {
$license[0]->setLicensekey($this->FileStorageManager->getLicenseContent());
}
if ($this->valueIsLicenseKeyFilePath($license[0]->getLicensekeytoken()) !== false) {
$license[0]->setLicensekeytoken($this->FileStorageManager->getCurrentlyActiveLicenseContent());
}
return $license[0];
}
}
Expand Down

0 comments on commit 57f32f1

Please sign in to comment.