Skip to content

Commit

Permalink
Merge pull request #2 from ConanDoyl/development
Browse files Browse the repository at this point in the history
Code improvements
  • Loading branch information
ConanDoyl authored Aug 28, 2021
2 parents b44fe25 + d7ae214 commit d6a032c
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 74 deletions.
9 changes: 5 additions & 4 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: Sunday, 15th August 2021 6:08:51 pm
* Last Modified: Tuesday, 24th August 2021 5:24:39 pm
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
Expand All @@ -29,12 +29,13 @@ class ApiManager {
protected $Url;

public function __construct(){
$server = Capsule::table('tblservers')->where('type', 'tekbasewhmcs')->where('active', '1')->select('username', 'password', 'secure')->first();
$server = (new Capsule)->table('tblservers')->where('type', 'tekbasewhmcs')->where('active', '1')->select('username', 'password', 'secure')->first();
$this->setUsername($server->username);
$this->setPassword(decrypt($server->password));
if ($server->secure == "on"){
$this->setURL('http://api.tekbase.de/v1/reseller/'. $this->getUsername() . "/" );

if ($server->secure == "on")
$this->setURL('https://api.tekbase.de/v1/reseller/' . $this->getUsername() . "/");
} else { $this->setURL('http://api.tekbase.de/v1/reseller/'. $this->getUsername() . "/" ); }

}

Expand Down
40 changes: 21 additions & 19 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: Sunday, 15th August 2021 6:08:44 pm
* Last Modified: Saturday, 28th August 2021 10:26:14 am
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
Expand All @@ -20,7 +20,9 @@
*/
namespace ConanDoyl\TekbaseWhmcs\Manager;

use Exception;
use WHMCS\Database\Capsule;
use Carbon\Carbon;
use ConanDoyl\TekbaseWhmcs\Models\License;


Expand All @@ -31,8 +33,8 @@ public static function Init() {

// Create a new table.
try {
if (!Capsule::schema()->hasTable('mod_tekbase_licenses'))
Capsule::schema()->create(
if (!(new Capsule)->schema()->hasTable('mod_tekbase_licenses'))
(new Capsule)->schema()->create(
'mod_tekbase_licenses',
function ($table) {
$table->increments('id');
Expand All @@ -53,7 +55,7 @@ function ($table) {
$table->timestamps();
}
);
} catch (\Exception $e) {
} catch (Exception $e) {
logModuleCall(
'tekbasewhmcs',
__FUNCTION__,
Expand All @@ -68,7 +70,7 @@ function ($table) {

public static function Destroy() {
try {
Capsule::dropIfExists('mod_tekbase_licenses');
(new Capsule)->dropIfExists('mod_tekbase_licenses');
} catch (\Exception $e) {
logModuleCall(
'tekbasewhmcs',
Expand All @@ -82,20 +84,20 @@ public static function Destroy() {


public static function GetLicense(int $id) {
if (Capsule::table('mod_tekbase_licenses')->where('licenseid', $id)->count() > 0){
return Capsule::table('mod_tekbase_licenses')->where('licenseid', $id)->first();
if ((new Capsule)->table('mod_tekbase_licenses')->where('licenseid', $id)->count() > 0){
return (new Capsule)->table('mod_tekbase_licenses')->where('licenseid', $id)->first();
} else {
return Capsule::table('mod_tekbase_licenses')->where('serviceid', $id)->first();
return (new Capsule)->table('mod_tekbase_licenses')->where('serviceid', $id)->first();
}
}

public static function FindLicenseByService($serviceid) {
return new License((Capsule::table('mod_tekbase_licenses')->where('serviceid', $serviceid)->first())->licenseid);
return new License(((new Capsule)->table('mod_tekbase_licenses')->where('serviceid', $serviceid)->first())->licenseid);
}

public static function UpdateLicense(License $license) {
if (Capsule::table('mod_tekbase_licenses')->where('licenseid', $license->id)->count() > 0 ){
return Capsule::table('mod_tekbase_licenses')->where('licenseid', $license->id)->update([
if ((new Capsule)->table('mod_tekbase_licenses')->where('licenseid', $license->id)->count() > 0 ){
return (new Capsule)->table('mod_tekbase_licenses')->where('licenseid', $license->id)->update([

'serviceid' => $license->serviceid,
'customerid' => $license->customer,
Expand All @@ -110,11 +112,11 @@ public static function UpdateLicense(License $license) {
'gwislots' => $license->gwislots,
'rwislots' => $license->rwislots,
'swislots' => $license->swislots,
"updated_at" => \Carbon\Carbon::now()
"updated_at" => (new Carbon)->now()

]) == 1;
} else {
return Capsule::table('mod_tekbase_licenses')->insert([
return (new Capsule)->table('mod_tekbase_licenses')->insert([

'serviceid' => $license->serviceid,
'customerid' => $license->customer,
Expand All @@ -129,32 +131,32 @@ public static function UpdateLicense(License $license) {
'gwislots' => $license->gwislots,
'rwislots' => $license->rwislots,
'swislots' => $license->swislots,
"updated_at" => \Carbon\Carbon::now(),
"created_at" => \Carbon\Carbon::now()
"updated_at" => (new Carbon)->now(),
"created_at" => (new Carbon)->now()

]);
}
}


public static function FindCustomFields($serviceid){
return Capsule::table('tblcustomfieldsvalues')->where('tblcustomfieldsvalues.relid', $serviceid)
return (new Capsule)->table('tblcustomfieldsvalues')->where('tblcustomfieldsvalues.relid', $serviceid)
->join('tblcustomfields', 'tblcustomfieldsvalues.fieldid', '=', 'tblcustomfields.id')
->select('tblcustomfieldsvalues.id as valueID', 'tblcustomfieldsvalues.fieldid', 'tblcustomfieldsvalues.relid', 'tblcustomfields.id', 'tblcustomfields.fieldname')->get();
}

public static function UpdateCustomfield ($id, $serviceid, $value){
return Capsule::table('tblcustomfieldsvalues')->where('id', $id)->where('relid', $serviceid)->update([
return (new Capsule)->table('tblcustomfieldsvalues')->where('id', $id)->where('relid', $serviceid)->update([
"value" => $value
]) == 1;
}

public static function DeleteLicense(License $license){
return Capsule::table('mod_tekbase_licenses')->where('licenseid', $license->id)->where('serviceid', $license->serviceid)->delete() > 0;
return (new Capsule)->table('mod_tekbase_licenses')->where('licenseid', $license->id)->where('serviceid', $license->serviceid)->delete() > 0;
}

public static function AlreadyExists($serviceid){
return Capsule::table('mod_tekbase_licenses')->where('serviceid', $serviceid)->count() > 0;
return (new Capsule)->table('mod_tekbase_licenses')->where('serviceid', $serviceid)->count() > 0;
}


Expand Down
107 changes: 107 additions & 0 deletions modules/servers/tekbasewhmcs/Models/HttpRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/*
* ###############################################################################
* File: HttpRequest.php
* Project: Models
* File Created: Saturday, 28th August 2021 10:40:24 am
* Author: Thomas Brinkmann (doyl@dsh.icu)
* -----
* Last Modified: Saturday, 28th August 2021 12:57:51 pm
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
* -----
* License Text
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* -----
* ###############################################################################
*/
namespace ConanDoyl\TekbaseWhmcs\Models;


class HttpRequest {

protected $post;
protected $get;

public function __construct() {
$this->post = filter_input_array(INPUT_POST);
$this->get = filter_input_array(INPUT_GET);
}


/** Returns the variable from the POST or GET variable
* @param mixed $type INPUT_GET, INPUT_POST
* @param mixed $variable
*
* @return mixed
*/
public function get($type, $variable){
switch($type){

case INPUT_GET:
return filter_input($type, $variable);
break;

case INPUT_POST:
return filter_input($type, $variable);
break;
}
}

/** Returns the full array of the POST|GET variable
* @param mixed $type INPUT_GET, INPUT_POST
*
* @return array|false|null
*/
public function getAll($type){
switch($type){

case INPUT_GET:
return $this->get;
break;

case INPUT_POST:
return $this->post;
break;
}
}

/** Returns the current page as string
* @return string
*/
public function getCurrentPage(){
$page = $this->get(INPUT_GET, 'page');
if (isset($page)){
if ($page != ""){
return $page;
}
return "home";
}
return "home";
}


/** Checks if the Variable is set
* @param mixed $type INPUT_GET, INPUT_POST
* @param mixed $key The key we're looking for
*
* @return bool
*/
public function hasKey($type, $value){
switch($type){

case INPUT_GET:
return in_array($value, $this->get);
break;

case INPUT_POST:
return in_array($value, $this->post);
break;
}

}

}
40 changes: 21 additions & 19 deletions modules/servers/tekbasewhmcs/Models/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* File Created: Saturday, 14th August 2021 2:32:01 pm
* Author: Thomas Brinkmann (doyl@dsh.icu)
* -----
* Last Modified: Sunday, 15th August 2021 6:08:32 pm
* Last Modified: Tuesday, 24th August 2021 5:35:43 pm
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
Expand Down Expand Up @@ -44,9 +44,23 @@ class License {
/** Load the License with $id or creante a new object
* @param null $id
*/
public function __construct($id = null) {
if ($id != null){
$__lic = DatabaseManager::GetLicense($id);
public function __construct($licenseId = null) {
// Set default values
$this->customer = (new LicenseService)->generateRandomString();
$this->key = "";
$this->siteip = "";
$this->siteurl = "";
$this->sitepath = "";
$this->version = "private";
$this->cms = 0;
$this->shop = 0;
$this->gwislots = 0;
$this->rwislots = 0;
$this->swislots = 0;
$this->vwislots = 0;

if ($licenseId != null){
$__lic = (new DatabaseManager)->GetLicense($licenseId);
$this->id = $__lic->licenseid;
$this->serviceid = $__lic->serviceid;
$this->customer = $__lic->customerid;
Expand All @@ -61,21 +75,9 @@ public function __construct($id = null) {
$this->rwislots = $__lic->rwislots;
$this->swislots = $__lic->swislots;
$this->vwislots = $__lic->vwislots;
} else {
// Set default values
$this->customer = (new LicenseService)->generateRandomString();
$this->key = "";
$this->siteip = "";
$this->siteurl = "";
$this->sitepath = "";
$this->version = "private";
$this->cms = 0;
$this->shop = 0;
$this->gwislots = 0;
$this->rwislots = 0;
$this->swislots = 0;
$this->vwislots = 0;
}


}


Expand All @@ -84,7 +86,7 @@ public function __construct($id = null) {
* @return boolean
*/
public function save(){
return DatabaseManager::UpdateLicense($this);
return (new DatabaseManager)->UpdateLicense($this);
}


Expand Down
16 changes: 12 additions & 4 deletions modules/servers/tekbasewhmcs/Services/LicenseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* File Created: Saturday, 14th August 2021 1:12:21 pm
* Author: Thomas Brinkmann (doyl@dsh.icu)
* -----
* Last Modified: Sunday, 15th August 2021 6:08:27 pm
* Last Modified: Tuesday, 24th August 2021 5:38:09 pm
* Modified By: Thomas Brinkmann (doyl@dsh.icu>)
* -----
* Copyright 2021 - Thomas Brinkmann. All Rights Reserved.
Expand Down Expand Up @@ -40,7 +40,8 @@ public function countLicenses() {
*
* @return array
*/
public function getAllLicenses($onlyActives = false) { throw new Exception('Not implemented'); }
#public function getAllLicenses($onlyActives = false) { throw new Exception('Not implemented'); }
public function getAllLicenses() { throw new Exception('Not implemented'); }



Expand All @@ -49,7 +50,8 @@ public function getAllLicenses($onlyActives = false) { throw new Exception('Not
*
* @return object
*/
public function getLicense(int $licenseid) { throw new Exception('Not implemented'); }
#public function getLicense(int $licenseid) { throw new Exception('Not implemented'); }
public function getLicense() { throw new Exception('Not implemented'); }



Expand All @@ -60,7 +62,8 @@ public function getLicense(int $licenseid) { throw new Exception('Not implemente
*
* @return object
*/
public function getLicenseKey(int $licenseid, int $version = 8) { throw new Exception('Not implemented'); }
#public function getLicenseKey(int $licenseid, int $version = 8) { throw new Exception('Not implemented'); }
public function getLicenseKey() { throw new Exception('Not implemented'); }



Expand Down Expand Up @@ -154,5 +157,10 @@ public function generateRandomString($length = 12) {
}
return $randomString;
}


public static function Test(){
return "sddsd";
}

}
Loading

0 comments on commit d6a032c

Please sign in to comment.