Skip to content
Open
7 changes: 3 additions & 4 deletions apis/enhance_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ public function __construct($server_label, $hostname, $org_id, $api_token)
$this->org_id = $org_id;
$this->api_token = $api_token;

// Construct API URL with port 2087 if not already specified
$port = (strpos($hostname, ':') !== false) ? '' : ':2087';
$this->apiUrl = 'https://' . $hostname . $port . '/api';
// Construct API URL
$this->apiUrl = 'https://' . $hostname . '/api';
}

/**
Expand Down Expand Up @@ -989,4 +988,4 @@ public function testConnection()
// Test with the known working endpoint
return $this->apiRequest('version', [], 'GET');
}
}
}
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.1",
"version": "2.1.0",
"name": "Enhance.name",
"description": "Enhance.description",
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions config/enhance.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Please note: If you have purchased more than 1 hosting service from us, login to the panel using the original password.

You can manage your website through the Enhance control panel:
Panel URL: https://{module.hostname}:2087
Panel URL: https://{module.hostname}

SSH Access (for advanced users):
Host: {module.hostname}
Expand All @@ -41,7 +41,7 @@
Password: <strong>{service.password}</strong></p>
<p><strong>Please note: If you have purchased more than 1 hosting service from us, login to the panel using the original password.</strong></p>
<p><strong>You can manage your website through the Enhance control panel:</strong><br />
Panel URL: <a href="https://{module.hostname}:2087" target="_blank">https://{module.hostname}:2087</a></p>
Panel URL: <a href="https://{module.hostname}" target="_blank">https://{module.hostname}</a></p>
<p><strong>SSH Access (for advanced users):</strong><br />
Host: <strong>{module.hostname}</strong><br />
Username: <strong>{service.username}</strong><br />
Expand Down
106 changes: 98 additions & 8 deletions enhance.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,27 @@ public function install()
*/
public function upgrade($current_version)
{
//// if (version_compare($current_version, '1.1.0', '<')) {
//// // Preform actions here such as re-adding cron tasks, setting new meta fields, and more
//// }
if (version_compare($current_version, '2.1.0', '<')) {
if (!isset($this->ModuleManager)) {
Loader::loadModels($this, ['ModuleManager']);
}
if (!isset($this->Record)) {
Loader::loadComponents($this, ['Record']);
}

// Client meta was stored under the module row ID instead of the
// module ID. Re-key the affected records to the correct module ID.
$modules = $this->ModuleManager->getByClass('enhance');
foreach ($modules as $module) {
$rows = $this->ModuleManager->getRows($module->id);
foreach ($rows as $row) {
$this->Record->where('module_id', '=', $row->id)
->where('module_row_id', '=', 0)
->where('key', 'in', ['enhance_org_id', 'enhance_login_id'])
->update('module_client_meta', ['module_id' => $module->id]);
}
}
}
}

/**
Expand Down Expand Up @@ -525,12 +543,12 @@ public function addService(
$existing_org_id_obj = $this->ModuleClientMeta->get(
$vars['client_id'],
'enhance_org_id',
$row->id
$row->module_id
);
$existing_login_id_obj = $this->ModuleClientMeta->get(
$vars['client_id'],
'enhance_login_id',
$row->id
$row->module_id
);

// Extract values from objects (ModuleClientMeta returns objects with ->value property)
Expand Down Expand Up @@ -640,7 +658,7 @@ public function addService(
if (!$existing_org_id && $customer_org_id && isset($response['login_id'])) {
$this->ModuleClientMeta->set(
$vars['client_id'],
$row->id,
$row->module_id,
0,
[
['key' => 'enhance_org_id', 'value' => $customer_org_id, 'encrypted' => 0],
Expand Down Expand Up @@ -772,6 +790,78 @@ public function editService($package, $service, array $vars = null, $parent_pack
return $return;
}

/**
* Updates the package for the service on the remote server. Sets Input errors on failure,
* preventing the service's package from being changed.
*
* @param stdClass $package_from A stdClass object representing the current package
* @param stdClass $package_to A stdClass object representing the new package
* @param stdClass $service A stdClass object representing the current service
* @param stdClass $parent_package A stdClass object representing the parent
* service's selected package (if the current service is an addon service)
* @param stdClass $parent_service A stdClass object representing the parent
* service of the service being changed (if the current service is an addon service)
* @return mixed null to maintain the existing meta fields
* @see Module::getModule()
* @see Module::getModuleRow()
*/
public function changeServicePackage(
$package_from,
$package_to,
$service,
$parent_package = null,
$parent_service = null
) {
if (($row = $this->getModuleRow())) {
// Only update the subscription if the plan has changed
if ($package_from->meta->package != $package_to->meta->package) {
$api = $this->getApi(
$row->meta->server_label,
$row->meta->hostname,
$row->meta->org_id,
$row->meta->api_token
);

$service_fields = $this->serviceFieldsToObject($service->fields);

// Resolve customer_org_id from service fields, falling back to ModuleClientMeta
$customer_org_id = isset($service_fields->customer_org_id) ? $service_fields->customer_org_id : null;
if (!$customer_org_id) {
if (!isset($this->ModuleClientMeta)) {
Loader::loadModels($this, ['ModuleClientMeta']);
}
$meta = $this->ModuleClientMeta->get($service->client_id, 'enhance_org_id', $row->module_id);
$customer_org_id = $meta ? $meta->value : null;
}

if (isset($customer_org_id) && isset($service_fields->subscription_id)) {
$this->log($row->meta->hostname . '|changeServicePackage', 'Changing subscription: ' . $service_fields->subscription_id . ' to plan: ' . $package_to->meta->package, 'input', true);

$response = $api->updateCustomerSubscription(
$customer_org_id,
$service_fields->subscription_id,
['planId' => intval($package_to->meta->package)]
);

$success = false;

if (($errors = $response->errors())) {
$this->Input->setErrors(['api' => $errors]);
} else {
$success = true;
}

$this->log($row->meta->hostname . '|changeServicePackage', 'Change package result: ' . ($success ? 'success' : 'failed'), 'output', $success);
} else {
$this->log($row->meta->hostname . '|changeServicePackage', 'Missing customer_org_id or subscription_id', 'output', false);
$this->Input->setErrors(['api' => ['Missing required service fields for package change']]);
}
}
}

return null;
}

/**
* Suspends the service on the remote server. Sets Input errors on failure,
* preventing the service from being suspended.
Expand Down Expand Up @@ -1347,7 +1437,7 @@ public function tabChangePassword(
$existing_login_id_obj = $this->ModuleClientMeta->get(
$service->client_id,
'enhance_login_id',
$row->id
$row->module_id
);

if (isset($existing_login_id_obj->value)) {
Expand Down Expand Up @@ -1436,7 +1526,7 @@ public function tabClientChangePassword(
$existing_login_id_obj = $this->ModuleClientMeta->get(
$service->client_id,
'enhance_login_id',
$row->id
$row->module_id
);

if (isset($existing_login_id_obj->value)) {
Expand Down
2 changes: 1 addition & 1 deletion views/default/admin_service_info.pdt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<?php } else { ?>
<a href="https://<?php echo isset($module_row->meta->hostname)
? $this->Html->safe($module_row->meta->hostname)
: ''; ?>:2087" target="_blank"><?php $this->_('Enhance.service_info.option_login'); ?></a>
: ''; ?>" target="_blank"><?php $this->_('Enhance.service_info.option_login'); ?></a>
<?php } ?>
</td>
</tr>
Expand Down
79 changes: 39 additions & 40 deletions views/default/client_service_info.pdt
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
<?php /** @var View $this **/ ?>

<div class="table-responsive">
<table class="table table-curved table-striped">
<thead>
<tr>
<th><i class="fas fa-share fa-flip-vertical"></i></th>
<th><?php $this->_('Enhance.service_info.username'); ?></th>
<th><?php $this->_('Enhance.service_info.email'); ?></th>
<th><?php $this->_('Enhance.service_info.password'); ?></th>
<th><?php $this->_('Enhance.service_info.options'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td><?php echo isset($service_fields->username)
? $this->Html->safe($service_fields->username)
: null; ?></td>
<td><?php echo isset($service_fields->customer_email)
? $this->Html->safe($service_fields->customer_email)
: null; ?></td>
<td><?php echo isset($service_fields->password)
? $this->Html->safe($service_fields->password)
: null; ?></td>
<td>
<?php if ($login_url ?? null) { ?>
<a href="<?php echo isset($login_url)
? $this->Html->safe($login_url)
: null; ?>" target="_blank"><?php $this->_('Enhance.service_info.option_login'); ?></a>
<?php } else { ?>
<a href="https://<?php echo isset($module_row->meta->hostname)
? $this->Html->safe($module_row->meta->hostname)
: ''; ?>:2087" target="_blank"><?php $this->_('Enhance.service_info.option_login'); ?></a>
<?php } ?>
</td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive">
<table class="table table-curved table-striped">
<thead>
<tr>
<th><i class="fas fa-share fa-flip-vertical"></i></th>
<th><?php $this->_('Enhance.service_info.username'); ?></th>
<th><?php $this->_('Enhance.service_info.email'); ?></th>
<th><?php $this->_('Enhance.service_info.password'); ?></th>
<th><?php $this->_('Enhance.service_info.options'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td><?php echo (isset($service_fields->username) ? $this->Html->safe($service_fields->username) : null); ?>
</td>
<td><?php echo (isset($service_fields->customer_email) ? $this->Html->safe($service_fields->customer_email) : null); ?>
</td>
<td><?php echo (isset($service_fields->password) ? $this->Html->safe($service_fields->password) : null); ?>
</td>
<td>
<?php
if ((isset($login_url) ? $login_url : null)) {
?>
<a href="<?php echo (isset($login_url) ? $this->Html->safe($login_url) : null); ?>"
target="_blank"><?php $this->_('Enhance.service_info.option_login'); ?></a>
<?php
} else {
?>
<a href="https://<?php echo (isset($module_row->meta->hostname) ? $this->Html->safe($module_row->meta->hostname) : ''); ?>"
target="_blank"><?php $this->_('Enhance.service_info.option_login'); ?></a>
<?php
}
?>
</td>
</tr>
</tbody>
</table>
</div>