Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ class ClientAreaPrimarySidebarController
* @var ApiHelper
*/
private $apiHelper;

public function __construct(ApiHelper $apiHelper)
/**
* @var DNS
*/
private $dnsHelper;
/**
* ConfigController constructor.
*/
public function __construct(ApiHelper $apiHelper, DNS $dnsHelper)
{
$this->apiHelper = $apiHelper;
$this->dnsHelper = $dnsHelper;
}

public function show($primarySidebar)
Expand All @@ -52,7 +59,7 @@ private function replaceDnsMenuItem($primarySidebar)
return;
}

if ($url = DNS::getDnsUrlOrFail($domainId)) {
if ($url = $this->dnsHelper->getDnsUrlOrFail($domainId)) {
// Update the URL.
$dnsManagement->setUri($url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@
*/

class DnsAuthController {
/**
* @var DNS
*/
private $dnsHelper;
/**
* ConfigController constructor.
*/
public function __construct(DNS $dnsHelper)
{
$this->dnsHelper = $dnsHelper;
}

public function redirectDnsManagementPage($params)
{
if ($url = DNS::getDnsUrlOrFail($params['domainid'])) {
if($url = $this->dnsHelper->getDnsUrlOrFail($params['domainid'])) {

// Fallback if referer is not set or is not same-origin
$defaultPreviousUrl = 'clientarea.php?action=domains';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OpenProvider\API\Domain;
use WeDevelopCoffee\wPower\Controllers\BaseController;
use WeDevelopCoffee\wPower\Core\Core;
use OpenProvider\WhmcsRegistrar\helpers\DNS;

class DnsController extends BaseController
{
Expand All @@ -26,16 +27,20 @@ class DnsController extends BaseController
* @var ApiHelper
*/
private $apiHelper;

/**
* @var DNS
*/
private $dnsHelper;
/**
* ConfigController constructor.
*/
public function __construct(Core $core, Domain $domain, ApiHelper $apiHelper)
public function __construct(Core $core, Domain $domain, ApiHelper $apiHelper, DNS $dnsHelper)
{
parent::__construct($core);

$this->domain = $domain;
$this->apiHelper = $apiHelper;
$this->dnsHelper = $dnsHelper;
}

/**
Expand Down Expand Up @@ -115,6 +120,62 @@ public function save($params)
}
}

public function redirectDnsManagementPage ($params)
{
$url = $this->dnsHelper->getDnsUrlOrFail($params['domainid'], true);

if (!$url) {
return [
'error' => 'Unable to generate DNS Management URL.',
];
}

$previousUrl = isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] !== ''
? $_SERVER['REQUEST_URI']
: '/';

if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] !== '') {
$referer = $_SERVER['HTTP_REFERER'];
$refererParts = parse_url($referer);

if (
is_array($refererParts) &&
isset($refererParts['host'], $_SERVER['HTTP_HOST']) &&
strtolower($refererParts['host']) === strtolower($_SERVER['HTTP_HOST'])
) {
$previousUrl = $referer;
}
}

$encodedUrl = json_encode($url, JSON_UNESCAPED_SLASHES);
$encodedPreviousUrl = json_encode($previousUrl, JSON_UNESCAPED_SLASHES);

echo '<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
var targetUrl = ' . $encodedUrl . ';
var previousUrl = ' . $encodedPreviousUrl . ';

var userConfirmed = confirm("Do you want to open in New Tab?");

if (userConfirmed) {
var newWindow = window.open(targetUrl, "_blank");

if (newWindow) {
window.location.href = previousUrl;
newWindow.focus();
} else {
alert("New tab opening blocked! Please allow it for this site.");
window.location.href = targetUrl;
}
} else {
window.location.href = targetUrl;
}
});
</script>';

exit;
}

private function isZoneNotFound(\Throwable $e): bool
{
if ((int) $e->getCode() === 872) {
Expand Down
16 changes: 16 additions & 0 deletions modules/registrars/openprovider/OpenProvider/API/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,22 @@ public function deleteDnsRecords(Domain $domain): array
return [];
}

/**
* @param string $domain
* @param string $zone_provider
* @return array
* @throws \Exception
*/
public function getDnsDomainToken(string $domain, string $zone_provider): array
{
$args = [
'domain' => $domain,
'zone_provider' => $zone_provider,
];

return $this->buildResponse($this->apiClient->call('createDomainTokenRequest', $args));
}

/**
* @param string $handle
* @param bool $formattedForWhmcs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Openprovider\Api\Rest\Client\Person\Api\ResellerServiceApi;
use Openprovider\Api\Rest\Client\Tld\Api\TldServiceApi;
use Openprovider\Api\Rest\Client\Domain\Api\AuthCodeApi;
use Openprovider\Api\Rest\Client\Dns\Api\DomainTokenApi;

class CommandMapping
{
Expand Down Expand Up @@ -134,6 +135,10 @@ class CommandMapping
self::COMMAND_MAP_METHOD => 'createZone',
self::COMMAND_MAP_CLASS => ZoneServiceApi::class,
],
'createDomainTokenRequest' => [
self::COMMAND_MAP_METHOD => 'createToken',
self::COMMAND_MAP_CLASS => DomainTokenApi::class
],

// Nameservers
'searchNsRequest' => [
Expand Down
48 changes: 38 additions & 10 deletions modules/registrars/openprovider/helpers/DNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,69 @@

namespace OpenProvider\WhmcsRegistrar\helpers;

use OpenProvider\API\ApiHelper;
use OpenProvider\WhmcsRegistrar\src\Configuration;
use OpenProvider\WhmcsRegistrar\src\OpenProvider;
use OpenProvider\WhmcsRegistrar\helpers\DomainFullNameToDomainObject;
use WHMCS\Database\Capsule;

class DNS
{
/**
* @var ApiHelper
*/
private $apiHelper;

/**
* ConfigController constructor.
*/
public function __construct(ApiHelper $apiHelper)
{
$this->apiHelper = $apiHelper;
}

/**
* Get the DNS URL
*
* @return bool|void
* @param int $domain_id
* @param bool $skipConfigCheck Whether to ignore useNewDnsManagerFeature flag
* @return string|bool
*/
public static function getDnsUrlOrFail($domain_id)
public function getDnsUrlOrFail($domain_id, bool $skipConfigCheck = false)
{
// Get the domain details
$domain = Capsule::table('tbldomains')
->where('id', $domain_id)
->first();

if (!$domain) {
return false;
}

// Check if OpenProvider is the provider
if($domain->registrar != 'openprovider' || $domain->status != 'Active')
return false;

// Check if we are allowed to make a redirect.
$newDnsStatus = Configuration::getOrDefault('useNewDnsManagerFeature', false);
// Client-side feature toggle (unless skipped)
if (!$skipConfigCheck) {

// Check if we are allowed to make a redirect
$newDnsStatus = Configuration::getOrDefault('useNewDnsManagerFeature', false);

if($newDnsStatus != true)
return false;
if ($newDnsStatus !== true) {
return false;
}
}

$op_domain_obj = DomainFullNameToDomainObject::convert($domain->domain);

// Let's get the URL.
try {
$OpenProvider = new OpenProvider();
return $OpenProvider->api->getDnsSingleDomainTokenUrl($domain->domain)['url'];
$domainOp = $this->apiHelper->getDomain($op_domain_obj);
$zoneProvider = !empty($domainOp['isSectigoDnsEnabled']) ? 'sectigo' : 'openprovider';
$response = $this->apiHelper->getDnsDomainToken($domain->domain, $zoneProvider);
return $response['url'] ?? false;
} catch (\Exception $e) {
\logModuleCall('OpenProvider', 'Fetching generateSingleDomainTokenRequest', $domain->domain, @$response, $e->getMessage(), [htmlentities($params['Password']), $params['Password']]);
logModuleCall('OpenProvider','getDnsDomainToken',$domain->domain,$e->getMessage(),'', '');
return false;
}
}
Expand Down
12 changes: 12 additions & 0 deletions modules/registrars/openprovider/openprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function openprovider_AdminCustomButtonArray()
$buttonarray = array(
"Auto-renew Sync" => "AutoRenewSync",
"Sync" => "Sync",
"Manage DNS Zone" => "AdminManageDnsZone",
);

return $buttonarray;
Expand Down Expand Up @@ -342,6 +343,17 @@ function openprovider_ResendIRTPVerificationEmail(array $params)
return openprovider_registrar_launch_decorator('resendIRTPVerificationEmail', $params);
}

/**
* Admin Manage Dns Zone
*
* @param array $params
* @return mixed
*/
function openprovider_AdminManageDnsZone($params)
{
return openprovider_registrar_launch_decorator('adminManageDnsZone', $params);
}


function openprovider_config_validate($params)
{
Expand Down
1 change: 1 addition & 0 deletions modules/registrars/openprovider/routes/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// DNS
'getDns' => 'DnsController@get',
'saveDns' => 'DnsController@save',
'adminManageDnsZone' => 'DnsController@redirectDnsManagementPage',

// Contact
'getContactDetails' => 'ContactController@getDetails',
Expand Down