Skip to content

Commit

Permalink
#4 - Bugfix - Fixed the empty license id
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Brinkmann <doyl@dsh.icu>
  • Loading branch information
Thomas Brinkmann committed Feb 10, 2022
1 parent f298a50 commit 5281311
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 75 deletions.
41 changes: 2 additions & 39 deletions modules/servers/tekbasewhmcs/Manager/ApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* File Created: Saturday, 14th August 2021 12:00:08 pm
* Author: Thomas Brinkmann (doyl@dsh.icu)
* -----
* Last Modified: Tuesday, 24th August 2021 5:24:39 pm
* Last Modified: Thursday, 10th February 2022 7:20:33 pm
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
Expand Down Expand Up @@ -128,46 +128,9 @@ public function ExecuteApi(string $method, array $data, $LicenseId = null) {
$response = curl_exec($curl);
$data = json_decode($response);



$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Check the HTTP Status code
switch ($httpCode) {
case 200:
$error_status = ["StatusCode" => "200", "Message" => "Success"];
return ($data);
break;
case 201:
$error_status = ["StatusCode" => "201", "Message" => "Created"];
return ($data);
break;
case 204:
$error_status = ["StatusCode" => "204", "Message" => "No Centent, Success"];
break;
case 400:
$error_status = ["StatusCode" => "400", "Message" => "Bad Request invalid json."];
break;
case 425:
$error_status = ["StatusCode" => "422", "Message" => "Unprocessable Entity"];
break;
case 404:
$error_status = ["StatusCode" => "404", "Message" => "API/Endpoint not found"];
break;
case 500:
$error_status = ["StatusCode" => "500", "Message" => "Server replied with an error."];
break;
case 502:
$error_status = ["StatusCode" => "502", "Message" => "servers may be down or being upgraded. Hopefully they'll be OK soon!"];
break;
case 503:
$error_status = ["StatusCode" => "503", "Message" => "service unavailable. Hopefully they'll be OK soon!"];
break;
default:
$error_status = ["StatusCode" => $httpCode, "Message" => "Undocumented error: " . $httpCode . " : " . curl_error($curl), "response" => json_encode($response)];
break;
}
curl_close($curl);
return $error_status;
return $data;
}


Expand Down
11 changes: 6 additions & 5 deletions modules/servers/tekbasewhmcs/Manager/DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* File Created: Saturday, 14th August 2021 12:11:27 pm
* Author: Thomas Brinkmann (doyl@dsh.icu)
* -----
* Last Modified: Saturday, 28th August 2021 10:26:14 am
* Last Modified: Thursday, 10th February 2022 6:48:14 pm
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
Expand All @@ -31,6 +31,7 @@ class DatabaseManager {

public static function Init() {


// Create a new table.
try {
if (!(new Capsule)->schema()->hasTable('mod_tekbase_licenses'))
Expand All @@ -41,10 +42,10 @@ function ($table) {
$table->integer('serviceid');
$table->string('customerid');
$table->integer('licenseid');
$table->text('licensekey');
$table->string('siteip');
$table->string('siteurl');
$table->string('sitepath');
$table->text('licensekey')->nullable();
$table->string('siteip')->nullable();
$table->string('siteurl')->nullable();
$table->string('sitepath')->nullable();
$table->string('version');
$table->boolean('cms');
$table->boolean('shop');
Expand Down
76 changes: 45 additions & 31 deletions modules/servers/tekbasewhmcs/Services/ProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* File Created: Saturday, 14th August 2021 2:28:30 pm
* Author: Thomas Brinkmann (doyl@dsh.icu)
* -----
* Last Modified: Tuesday, 24th August 2021 5:58:16 pm
* Last Modified: Thursday, 10th February 2022 7:38:44 pm
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
Expand All @@ -33,7 +33,7 @@ class ProductService {
*/
public function createService($vars){
if (DatabaseManager::AlreadyExists($vars['serviceid']))
return "There is already a licese available.";
return "There is already a license available.";

$package = false;
$license = new License();
Expand All @@ -53,18 +53,21 @@ public function createService($vars){
$license->cms = $vars['configoptions']['cms'];
$license->shop = $vars['configoptions']['shop'];

// Checking if the Customfield is exists
if ( isset($vars['customfields']['siteurl'] ) ){
$ip = gethostbyname(parse_url($vars['customfields']['siteurl'], PHP_URL_HOST));
$license->siteurl = $vars['customfields']['siteurl'];
$license->siteip = $ip;
}
// Checking if the Customfield is exists
if ( isset($vars['customfields']['siteurl'] ) && isset($vars['customfields']['sitepath'] ) ){
if ( $vars['customfields']['siteurl'] !== "" ){
$ip = gethostbyname(parse_url($vars['customfields']['siteurl'], PHP_URL_HOST));
$license->siteurl = $vars['customfields']['siteurl'];
$license->siteip = $ip;
}

if ( $vars['customfields']['sitepath'] !== "" ){
$license->sitepath = $vars['customfields']['sitepath'];
}

if ( isset($vars['customfields']['sitepath'] ) ){
$license->sitepath = $vars['customfields']['sitepath'];
}


if ($package){
$license->gwislots = $vars['configoptions']['Resources'];
$license->rwislots = $vars['configoptions']['Resources'];
Expand All @@ -78,23 +81,31 @@ public function createService($vars){
}


$licenseData = (array)$license;

if (empty($license->sitepath)){
unset($licenseData["sitepath"]);

}

if (empty($license->siteurl)){
unset($licenseData["siteurl"]);
unset($licenseData["siteip"]);
}

$answer = (new LicenseService)->addLicense($username, $licenseData);

$answer = (new LicenseService)->addLicense($username, (array)$license);
if ($answer->message != "SUCCESSFUL"){
return $answer->message;
}

$license->id = $answer->id;
$license->key = $answer->key;
if ($answer->key == null){
$license->key = "<b><font color='#FF000'>Not retrieved yet.</font></b><br/>To retrieve the License Key make sure you've set url and path at the settings!";
logActivity(json_encode($answer));
}

//Check if Key isn't null
if ($answer->key != null){
$license->key = $answer->key;
$license->id = $answer->id;
}


return $license->save();
return $license->save() ? "success" : "Database error could not save the license!";

}

Expand Down Expand Up @@ -143,15 +154,18 @@ public function upgradeService($vars){
$license->vwislots = $vars['configoptions']['vwislots'];
}


$answer = (new LicenseService)->updateLicense($license);

//Check if Key isn't null
if ($answer->message != null){
if ($answer->message == "SUCCESSFUL")
return $license->save();
if ($answer->key != null){
$license->key = $answer->key;
}

return false;
if ($answer->message != "SUCCESSFUL"){
return $answer->message;
}

return $license->save() ? "success" : "License could not be saved!";
}

/** Executes on service suspend
Expand All @@ -162,7 +176,7 @@ public function upgradeService($vars){
public function suspendService($vars){
$license = new License($vars['serviceid']);
$answer =(new LicenseService)->suspendLicense($license);
return $answer->message == "SUCCESSFUL";
return $answer->message == "SUCCESSFUL" ? "success" : $answer->message;
}


Expand All @@ -174,7 +188,7 @@ public function suspendService($vars){
public function unsuspendService($vars){
$license = new License($vars['serviceid']);
$answer =(new LicenseService)->unsuspendLicense($license);
return $answer->message == "SUCCESSFUL";
return $answer->message == "SUCCESSFUL" ? "success" : $answer->message;
}


Expand All @@ -188,10 +202,10 @@ public function terminateService($vars){
$license = new License($vars['serviceid']);
$answer =(new LicenseService)->deleteLicense($license);
if ($answer->message == "SUCCESSFUL"){
return DatabaseManager::DeleteLicense($license);
return DatabaseManager::DeleteLicense($license) ? "success" : "Error while deleting license from database!";
}
return false;

return $answer->message;
}


Expand Down

0 comments on commit 5281311

Please sign in to comment.