Skip to content
Open
Changes from 1 commit
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
50 changes: 38 additions & 12 deletions modules/registrars/openprovider/OpenProvider/API/APITools.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function createNameserversArray($params, $apiHelper = null)
// }

if ($params['test_mode'] == 'on' && $apiHelper != null) {

for ($i = 1; $i <= 5; $i++) {
$ns = $params["ns{$i}"];
if (!$ns) {
Expand All @@ -36,6 +36,16 @@ public static function createNameserversArray($params, $apiHelper = null)
$nsName = trim($nsParts[0]);
$nsIp = empty($nsParts[1]) ? null : trim($nsParts[1]);

// Glue records (NS is a child of the domain) require an IP.
// External nameservers must be accepted as-is without IP lookup.
$domainFqdn = strtolower($params['sld'] . '.' . $params['tld']);
$isGlue = str_ends_with(strtolower($nsName), '.' . $domainFqdn);
Comment thread
avishka-ra marked this conversation as resolved.
Outdated

if (!$isGlue) {
$nameServers[] = new \OpenProvider\API\DomainNameServer(['name' => $nsName]);
continue;
}
Comment thread
avishka-ra marked this conversation as resolved.

//Try to get IP from searchNsRequest in REST API
if (empty($nsIp)) {
$myNameServerList = $apiHelper->getNameserverList($nsName);
Expand All @@ -52,9 +62,12 @@ public static function createNameserversArray($params, $apiHelper = null)
$nsIp = gethostbyname($nsName);
if (!filter_var($nsIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$nsIp = "";
throw new \Exception("Invalid nameserver name: {$nsName}");
throw new \Exception(
"Could not resolve IP for glue record nameserver '{$nsName}'. "
. "Please register it in OpenProvider before initiating the transfer."
Comment thread
avishka-ra marked this conversation as resolved.
Outdated
);
}
}
}
Comment thread
avishka-ra marked this conversation as resolved.

if (!empty($nsIp) && !empty($nsName)) {
$nameServers[] = new \OpenProvider\API\DomainNameServer(array(
Expand All @@ -65,13 +78,13 @@ public static function createNameserversArray($params, $apiHelper = null)
}

if (count($nameServers) < 2) {
throw new \Exception('You must enter minimum 2 nameservers');
throw new \Exception('You must provide at least 2 nameservers.');
}

return $nameServers;
}

$invalidNameServer = false;
$invalidGlueNameServers = [];
for ($i = 1; $i <= 5; $i++) {
$ns = $params["ns{$i}"];
if (!$ns) {
Expand All @@ -82,6 +95,16 @@ public static function createNameserversArray($params, $apiHelper = null)
$nsName = trim($nsParts[0]);
$nsIp = empty($nsParts[1]) ? null : trim($nsParts[1]);

// Glue records (NS is a child of the domain) require an IP.
// External nameservers must be accepted as-is without IP lookup.
$domainFqdn = strtolower($params['sld'] . '.' . $params['tld']);
$isGlue = str_ends_with(strtolower($nsName), '.' . $domainFqdn);

if (!$isGlue) {
$nameServers[] = new \OpenProvider\API\DomainNameServer(['name' => $nsName]);
continue;
}
Comment thread
avishka-ra marked this conversation as resolved.

if (empty($nsIp)) {
$api = new \OpenProvider\API\API();
$api->setParams($params);
Expand All @@ -99,8 +122,8 @@ public static function createNameserversArray($params, $apiHelper = null)
$nsIp = gethostbyname($nsName);
if (!filter_var($nsIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$nsIp = "";
$invalidNameServer = true;
logModuleCall('openprovider', 'createNameserversArray', $nsName, "Invalid nameserver name: {$nsName}", null, null);
$invalidGlueNameServers[] = $nsName;
logModuleCall('openprovider', 'createNameserversArray', $nsName, "Could not resolve IP for glue record nameserver: {$nsName}", null, null);
}
}

Expand All @@ -113,11 +136,14 @@ public static function createNameserversArray($params, $apiHelper = null)
}

if (count($nameServers) < 2) {
if($invalidNameServer) {
throw new \Exception('You must enter minimum 2 nameservers. Invalid nameserver found. Please check the module log.');
}else{
throw new \Exception('You must enter minimum 2 nameservers');
}
if (!empty($invalidGlueNameServers)) {
$names = implode(', ', $invalidGlueNameServers);
throw new \Exception(
"Could not resolve IP for glue record nameserver(s): {$names}. "
. "Please register them in OpenProvider before initiating the transfer."
Comment thread
avishka-ra marked this conversation as resolved.
Outdated
);
}
throw new \Exception('You must provide at least 2 nameservers.');
}

return $nameServers;
Expand Down