Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lost control of new server created on whmcs 8.1.x #109

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Change Log

## v2.0.5 (2021-04-21)
### Bug
* Fixes Doesn't show server details in client area [#88](https://github.com/vultr/whmcs-vultr/issues/88)
* Fixes After WHMCS 8 upgrade server creation failed [#91](https://github.com/vultr/whmcs-vultr/issues/91)
* Fixes WHMCS 8.0.2 successfully created the virtual machine, but failed to manage it [#92](https://github.com/vultr/whmcs-vultr/issues/92)
* Fixes Virtual machine ID [#105](https://github.com/vultr/whmcs-vultr/issues/105)
* Can't deploy server in WHMCS 8.1.1 [#106](https://github.com/vultr/whmcs-vultr/issues/106)
### Features
* Various bug fixes
* Quality of life improvements

### Changes
* Updated all deprecated
`use Illuminate\Database\Capsule\Manager as Capsule;`
To:
`use WHMCS\Database\Capsule;`

As recommended by WHMCS.
https://developers.whmcs.com/advanced/db-interaction/

Please NOTE: That I have incorporated some, but NOT all of the fixes from [#101](https://github.com/vultr/whmcs-vultr/issues/101)
All original credit for those things should be attributed to @jazz7381 and that PR could most likely be closed as mine incorporates the working stuff from there and more.

Also included is a pretty extensive port of the VultrAPI class to V2 which is not in use yet, but is pretty close to being able to be used.

The main issue appears to have been in addVMCustomFields where it was failing to add the subid to tblcustomfieldsvalues
whattheserver@453c76e

This in turn causes the creation to fail and allows customers to keep trying to create servers they thought failed but are detached from the client area and costing the Reseller money and time wasted going to clean those up and reattaching only one to the account manually.

## v2.0.4 (2019-09-19)
### Bug
* Fixes UI Issue where OS would reset upon save [#36](https://github.com/vultr/whmcs-vultr/pull/36)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# WHMCS Module

## Note: This module is community driven, it is no longer actively maintained.
## Note: This module is community driven, it is no longer actively maintained.
I recommend switching to the ModulesGarden one recently released.
https://www.modulesgarden.com/products/whmcs/vultr-vps

## System Requirements

Expand Down
2 changes: 1 addition & 1 deletion addons/vultr/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Configuration extends main\mgLibs\process\AbstractConfiguration
* Module version
* @var string
*/
public $version = '2.0.4';
public $version = '2.0.5';

/**
* Module author
Expand Down
4 changes: 2 additions & 2 deletions addons/vultr/helpers/ProductsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static function prepareConfigurableOptions($vultrAPI, $productID)
{
$checkIsset = DB::table('tblproductconfiglinks')->where('pid', $productID)->get();

if ($checkIsset)
if (count($checkIsset) > 0)
{
return array('status' => false, 'message' => 'Product configurable options already exist!');
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public static function getProductConfigOptions($productID, $field = 'all', $defa
public static function customFields($productID)
{
$result = DB::table('tblcustomfields')->where('fieldname', 'subid|Virtual machine ID')->where('type', 'product')->where('relid', $productID)->select('id')->get();
if (!$result)
if (count($result) < 1)
{
DB::table('tblcustomfields')->insert(array('type' => 'product', 'relid' => $productID, 'fieldname' => 'subid|Virtual machine ID', 'fieldtype' => 'text', 'adminonly' => 'on'));
return array('status' => true, 'reload' => true, 'message' => 'success');
Expand Down
8 changes: 4 additions & 4 deletions addons/vultr/hooks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;
use MGModule\vultr as main;

require_once(dirname(dirname(__DIR__)) . "/servers/vultr/helper/vultr.helper.php");
Expand Down Expand Up @@ -39,7 +39,7 @@ function vultrCronJob()

function getConfigOptionId($optionname)
{
$optionId = \WHMCS\Database\Capsule::table("tblproducts")
$optionId = Capsule::table("tblproducts")
->join("tblproductconfiglinks", "tblproductconfiglinks.pid", "=", "tblproducts.id")
->join("tblproductconfiggroups", "tblproductconfiggroups.id", "=", "tblproductconfiglinks.gid")
->join("tblproductconfigoptions", "tblproductconfigoptions.gid", "=", "tblproductconfiggroups.id")
Expand Down Expand Up @@ -126,7 +126,7 @@ function getConfigOptionId($optionname)
require_once 'Loader.php';
new main\Loader();

$productInfo = WHMCS\Database\Capsule::table("tblproducts")
$productInfo = Capsule::table("tblproducts")
->select("tblproducts.configoption2", "tblproducts.servertype")
->where("tblproducts.id", "=", $_SESSION['cart']['products'][$_GET['i']]['pid'])
->first();
Expand All @@ -137,7 +137,7 @@ function getConfigOptionId($optionname)
}

$productPlanId = $productInfo->configoption2;
$apiToken = \WHMCS\Database\Capsule::table("tbladdonmodules")
$apiToken = Capsule::table("tbladdonmodules")
->select("tbladdonmodules.value")
->where("tbladdonmodules.module", "=", "vultr")
->where("tbladdonmodules.setting", "=", "apiToken")
Expand Down
2 changes: 1 addition & 1 deletion servers/vultr/class/vultr.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

class Vultr
{
Expand Down
2 changes: 1 addition & 1 deletion servers/vultr/controller/dns.controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

class DnsController extends VultrController
{
Expand Down
38 changes: 30 additions & 8 deletions servers/vultr/controller/main.controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

class MainController extends VultrController
{
Expand Down Expand Up @@ -333,16 +333,34 @@ public function createAction()
}

$vm = $this->vultrAPI->create($vmParams);

if (is_array($vm))

// For debugging only. Can comment out the create statement above and then uncomment the below to simulate being passed a SUBID/instanced id to confirm the weird issues.
// $vm = [
// "SUBID" => "46109452",
// "v2_id" => "6593a82e-bd1f-4a5f-9396-322ffdd4bd22"
// ];

// die(var_dump($vm));
// using if/else to detect v1 api subid/instance id or v2api
if (isset($vm['SUBID']) && mb_strlen($vm['SUBID']) == 8 ) {
$vmid = $vm['SUBID']; // $vm['SUBID'] or $vm['v2_id'] https://www.vultr.com/api/v1/#server_create
} elseif (isset($vm['v2_id'])) {
$vmid = $vm['v2_id']; //
} elseif (isset($vm['instance']['id'])) {
$vmid = $vm['instance']['id']; // $vm['instance']['id'] new v2API responses https://www.vultr.com/api/#operation/create-instance
} else {
$vmid = false; // no instance or server ID was found.
}
//die(var_dump($vmid));
if ($vmid !== false) // Bail and show an error to contact support if no server id created or returned
{
$this->addVMCustomFields($vm['SUBID']);
$this->addVMCustomFields($vmid);
SessionHelper::setFlashMessage('success', LangHelper::T('main.create.created_success'));
$this->redirect('clientarea.php?action=productdetails&id=' . $this->serviceID);
}
else
{
SessionHelper::setFlashMessage('danger', $vm);
SessionHelper::setFlashMessage('danger', 'Server creation was unsuccessful! Please contact Support!. Do not try to recreate. It will fail.');
}
}
}
Expand Down Expand Up @@ -372,7 +390,8 @@ public function createAction()
}

private function addVMCustomFields($SUBID)
{
{

$customField = Capsule::table('tblcustomfields')
->where('type', 'product')
->where('relid', $this->params['packageid'])
Expand All @@ -383,16 +402,19 @@ private function addVMCustomFields($SUBID)
->where('fieldid', $customField[0]->id)
->where('relid', $this->serviceID)->get();
if ($customFieldValue)
{
{
$customFieldValue = Capsule::table('tblcustomfieldsvalues')
->where('fieldid', $customField[0]->id)
->where('relid', $this->serviceID)->update(array('value' => $SUBID));
}
else
{
{ // die(" Die before insert normal :" . var_dump($this->serviceID).PHP_EOL); never hits here which was the old fallback and seems worthless??
Capsule::table('tblcustomfieldsvalues')->insert(array('fieldid' => $customField[0]->id, 'relid' => $this->serviceID, 'value' => $SUBID));
}

}
// die('Die before inserting tblcustomfieldsvalues '); // This is what was actually needed to fix the missing subid issue not being entered into tblcustomfieldsvalues.
Capsule::table('tblcustomfieldsvalues')->insert(array('fieldid' => $this->params['packageid'], 'relid' => $this->serviceID, 'value' => $SUBID));
}

public function deleteAction()
Expand Down
4 changes: 2 additions & 2 deletions servers/vultr/controller/scripts.controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

class ScriptsController extends VultrController
{
Expand All @@ -26,7 +26,7 @@ public function deleteAction()
{
$id = filter_input(INPUT_GET, 'vultrID', FILTER_VALIDATE_INT);
$allow = Capsule::table('vultr_scripts')->where('SCRIPTID', $id)->where('client_id', $this->clientID)->first();
if (!empty($allow))
if (!empty($allow)) // this may need to be fixed to if (count($allow) > 0) but have not tested changing it yet to count
{
if ($this->getVultrAPI())
{
Expand Down
2 changes: 1 addition & 1 deletion servers/vultr/controller/snapshots.controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

class SnapshotsController extends VultrController
{
Expand Down
5 changes: 3 additions & 2 deletions servers/vultr/controller/sshkeys.controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

class SSHKeysController extends VultrController
{
Expand All @@ -15,7 +15,8 @@ public function indexAction()
if ($this->getVultrAPI())
{
$allowKeys = Capsule::table('vultr_sshkeys')->where('client_id', $this->clientID)->get();
if (empty($allowKeys))
// if (empty($allowKeys)) https://github.com/vultr/whmcs-vultr/pull/101/files#diff-e528d8e5801f95b469223f6b1d473b92f3699c420a7db69af5063ca8e61713b9
if (count($allowKeys) < 1)
{
return array();
}
Expand Down
2 changes: 1 addition & 1 deletion servers/vultr/controller/vultr.controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

class VultrController
{
Expand Down
6 changes: 3 additions & 3 deletions servers/vultr/helper/vultr.helper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

if (!class_exists('VultrHelper'))
{
Expand Down Expand Up @@ -490,7 +490,7 @@ public static function getAvailableIsos($isosList)
public static function getUserScripts($clientID, $scripts)
{
$allowScripts = Capsule::table('vultr_scripts')->where('client_id', $clientID)->get();
if (empty($allowScripts))
if (count($allowScripts) < 1)
{
return array();
}
Expand Down Expand Up @@ -521,7 +521,7 @@ public static function getUserScripts($clientID, $scripts)
public static function getUserSSHKeys($clientID, $keys)
{
$allowKeys = Capsule::table('vultr_sshkeys')->where('client_id', $clientID)->get();
if (empty($allowKeys))
if (count($allowKeys) < 1)
{
return array();
}
Expand Down
2 changes: 1 addition & 1 deletion servers/vultr/hooks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use WHMCS\Database\Capsule;

require 'loader.php';

Expand Down
Loading