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 @@ -21,10 +21,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 @@ -43,7 +50,7 @@ private function replaceDnsMenuItem($primarySidebar)
if (!$dnsManagement = $domainDetailsManagement->getChild('Manage DNS Host Records'))
return;

if ($url = DNS::getDnsUrlOrFail($_REQUEST['domainid'])) {
if ($url = $this->dnsHelper->getDnsUrlOrFail($_REQUEST['domainid'])) {
// Update the URL.
$dnsManagement->setUri($url);

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

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']))
{
$urlOne = $_SERVER['HTTP_REFERER'];
$url_decoded = html_entity_decode($urlOne);
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 @@ -112,6 +117,35 @@ public function save($params)
}
}

public function redirectDnsManagementPage ($params)
{
if($url = $this->dnsHelper->getDnsUrlOrFail($params['domainid'], true))
{
$urlOne = $_SERVER['HTTP_REFERER'];
$url_decoded = html_entity_decode($urlOne);

// JavaScript confirm dialog
echo '<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
var userConfirmed = confirm("Do you want to open in New Tab?");
if (userConfirmed) {
var newWindow = window.open("' . $url . '", "_blank"); // Open OP DNS management page in a new tab
if (newWindow) {
window.location.href = "' . $url_decoded . '"; // Redirect to previous page
newWindow.focus(); // Focus on the new tab
} else {
alert("New tab opening blocked! Please allow it for this site.");
window.location.href = "' . $url . '"; // Redirect to OP DNS management page
}
} else {
window.location.href = "' . $url . '"; // Redirect to OP DNS management page
}
});
</script>';
exit;
}
}

/**
* @param array $records
*
Expand Down
17 changes: 16 additions & 1 deletion modules/registrars/openprovider/OpenProvider/API/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,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 Expand Up @@ -605,7 +621,6 @@ public function getTldMeta(string $tld): array
);
}


/**
* @param ResponseInterface $response
* @return array
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 @@ -130,6 +131,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
2 changes: 1 addition & 1 deletion modules/registrars/openprovider/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"require": {
"wedevelopcoffee/wpower": "2.2.*",
"viison/address-splitter": "^0.3.2",
"openprovider/rest-client-php": "2.0.2-beta",
"openprovider/rest-client-php": "dev-v1beta",
"symfony/serializer": "^5.2",
"psr/log": "^1.1",
"symfony/property-access": "^5.2",
Expand Down
20 changes: 10 additions & 10 deletions modules/registrars/openprovider/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
18 changes: 15 additions & 3 deletions modules/registrars/openprovider/openprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright Copyright (c) Openprovider 2018
*/

use \OpenProvider\WhmcsRegistrar\src\Configuration;
use OpenProvider\WhmcsRegistrar\src\Configuration;
use WHMCS\Exception\Module\InvalidConfiguration;

if (!defined("WHMCS")) {
Expand Down 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 @@ -282,7 +283,7 @@ function openprovider_AutoRenewSync($params)
* @return array
*/
function openprovider_Sync($paramsArray)
{
{
return openprovider_registrar_launch_decorator('domainSync', $paramsArray);
}

Expand Down Expand Up @@ -342,6 +343,16 @@ 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 All @@ -358,7 +369,7 @@ function openprovider_config_validate($params)
$baseUrl = Configuration::get('restapi_url_sandbox');
}

$url = "{$baseUrl}{$resourcePath}";
$url = "{$baseUrl}{$resourcePath}";

$data = array(
"username" => $username,
Expand All @@ -375,6 +386,7 @@ function openprovider_config_validate($params)
curl_setopt($curl, CURLOPT_POSTFIELDS, $encodedData);
$result = curl_exec($curl);
curl_close($curl);

$response = json_decode($result);
if (!$response->data->token || !$response->data->reseller_id) {
throw new InvalidConfiguration("Credentials are Invalid for $env Environment");
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
5 changes: 1 addition & 4 deletions modules/registrars/openprovider/vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
throw new RuntimeException($err);
}

require_once __DIR__ . '/composer/autoload_real.php';
Expand Down
Loading