Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cPFence/41c32ca43ecd1423ae9ff6d12437af8a to your computer and use it in GitHub Desktop.
Save cPFence/41c32ca43ecd1423ae9ff6d12437af8a to your computer and use it in GitHub Desktop.
function enhance_ClientArea($params)
{
$systemUrl = Setting::getValue('SystemURL');
$webmailLink = 'https://webmail.example.com/';
$domain = $params['domain'];
$domainIP = gethostbyname($domain);
$serviceId = $params['serviceid'];
$buttonStyle = 'display: inline-block; padding: 10px 16px; margin: 4px 6px 10px 0; background-color: #0073e6; color: #fff; border: none; border-radius: 5px; font-size: 14px; cursor: pointer; text-decoration: none; transition: background-color 0.3s ease;';
$buttonHover = 'this.style.backgroundColor=\'#005bb5\'';
$websiteId = 'Not found';
$serverToUse = '';
try {
$api = get_api_client($params);
$clientsdetails = $params['clientsdetails'];
$orgId = fetch_org($api, $clientsdetails, $params);
$apiKey = $params['serveraccesshash'];
$headers = [
"Authorization: Bearer $apiKey",
"Content-Type: application/json"
];
$cpEnhanceUrl = 'https://' . $params['serverhostname'] . '/api';
$websitesUrl = "{$cpEnhanceUrl}/orgs/{$orgId}/websites";
$ch = curl_init($websitesUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if (!empty($data['items']) && is_array($data['items'])) {
foreach ($data['items'] as $website) {
if (!empty($website['domain']['domain']) && $website['domain']['domain'] === $domain) {
$websiteId = $website['id'];
$serverToUse = isset($website['appServerName']) ? $website['appServerName'] : '';
break;
}
}
}
} catch (Exception $e) {
$websiteId = 'Error: ' . $e->getMessage();
}
$analyticsURL = "https://{$domain}/traffic-reports/?site_id={$websiteId}";
$code = '
<div style="border: 1px solid #ccc; padding: 15px; border-radius: 6px; background: #f9f9f9; max-width: 600px;">
<h3 style="margin: 0 0 1em; font-weight: 600;">Quick Access & Stats</h3>
<form action="' . $systemUrl . '/clientarea.php" method="POST" target="_blank" style="display:inline;">
<input type="hidden" name="action" value="productdetails">
<input type="hidden" name="id" value="' . $serviceId . '">
<input type="hidden" name="dosinglesignon" value="1">
<button type="submit" style="' . $buttonStyle . '" onmouseover="' . $buttonHover . '" onmouseout="this.style.backgroundColor=\'#0073e6\'">
Control Panel Login
</button>
</form>
<a href="' . $webmailLink . '" target="_blank" style="' . $buttonStyle . '" onmouseover="' . $buttonHover . '" onmouseout="this.style.backgroundColor=\'#0073e6\'">
Webmail Login
</a>
<a href="' . $analyticsURL . '" target="_blank" style="' . $buttonStyle . '" onmouseover="' . $buttonHover . '" onmouseout="this.style.backgroundColor=\'#0073e6\'">
Traffic Analytics
</a>
<div style="margin-top: 1em;">
<p>Domain: ' . $domain . '</p>
<p>Server IP: ' . $domainIP . '</p>
<p>Website ID: ' . $websiteId . '</p>
<p>Hosting Server: ' . $serverToUse . '</p>
</div>
</div>';
return $code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment