refactor: improve code structure and readability

- Standardized the formatting across ISNICSync.php and eppClient.php for better consistency and readability, making future maintenance and debugging efforts more efficient.
- Adjusted the use of whitespace and alignment in both files to follow best coding practices, enhancing code clarity and developer experience.
- Simplified control structures for improved logic flow and reduced complexity in error handling and network communication processes.
- Ensured that all modified functions and error messages remain functional with clearer, more standardized error handling to minimize runtime errors and facilitate easier error tracking.

This refactor does not introduce any new features or significantly alter existing functionality but sets a solid foundation for more reliable and maintainable codebase.
This commit is contained in:
Kumi 2024-05-19 20:13:58 +02:00
parent 0047b66f53
commit 6e18fa423d
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 259 additions and 271 deletions

View file

@ -2,13 +2,13 @@
require_once "eppClient.php"; require_once "eppClient.php";
use Pinga\Tembo\eppClient; use Pinga\Tembo\eppClient;
$config = include "config.php"; $config = include "config.php";
$c = $config["db"]; $c = $config["db"];
$registrar = "ISNIC"; $registrar = "ISNIC";
try try {
{
// Establish the PDO connection // Establish the PDO connection
$dsn = $c["type"] . ":host=" . $c["host"] . ";port=" . $c["port"] . ";dbname=" . $c["name"]; $dsn = $c["type"] . ":host=" . $c["host"] . ";port=" . $c["port"] . ";dbname=" . $c["name"];
$pdo = new PDO($dsn, $c["user"], $c["password"]); $pdo = new PDO($dsn, $c["user"], $c["password"]);
@ -27,52 +27,42 @@ try
$config = []; $config = [];
foreach ($rows as $row) foreach ($rows as $row) {
{
$config = json_decode($row["config"], true); $config = json_decode($row["config"], true);
$registrar_id = $row["id"]; $registrar_id = $row["id"];
} }
if (empty($config)) if (empty($config)) {
{
throw new Exception("Database cannot be accessed right now."); throw new Exception("Database cannot be accessed right now.");
} }
} catch (PDOException $e) {
}
catch(PDOException $e)
{
echo "Database error: " . $e->getMessage(); echo "Database error: " . $e->getMessage();
} } catch (Exception $e) {
catch(Exception $e)
{
echo "General error: " . $e->getMessage(); echo "General error: " . $e->getMessage();
} }
function connectEpp(string $registry, $config) function connectEpp(string $registry, $config)
{ {
try try {
{
$epp = new eppClient(); $epp = new eppClient();
$info = [ $info = [
"host" => $config["host"], "host" => $config["host"],
"port" => $config["port"], "timeout" => 30, "tls" => "1.3", "bind" => false, "bindip" => "1.2.3.4:0", "verify_peer" => false, "verify_peer_name" => false, "port" => $config["port"], "timeout" => 30, "tls" => "1.3", "bind" => false, "bindip" => "1.2.3.4:0", "verify_peer" => false, "verify_peer_name" => false,
"verify_host" => false, "cafile" => "", "local_cert" => $config["ssl_cert"], "local_pk" => $config["ssl_key"], "passphrase" => "", "allow_self_signed" => true, ]; "verify_host" => false, "cafile" => "", "local_cert" => $config["ssl_cert"], "local_pk" => $config["ssl_key"], "passphrase" => "", "allow_self_signed" => true,
];
$epp->connect($info); $epp->connect($info);
$login = $epp->login(["clID" => $config["username"], "pw" => $config["password"], $login = $epp->login([
"prefix" => "tembo", ]); "clID" => $config["username"], "pw" => $config["password"],
if (array_key_exists("error", $login)) "prefix" => "tembo",
{ ]);
if (array_key_exists("error", $login)) {
echo "Login Error: " . $login["error"] . PHP_EOL; echo "Login Error: " . $login["error"] . PHP_EOL;
exit(); exit();
} } else {
else
{
echo "Login Result: " . $login["code"] . ": " . $login["msg"][0] . PHP_EOL; echo "Login Result: " . $login["code"] . ": " . $login["msg"][0] . PHP_EOL;
} }
return $epp; return $epp;
} } catch (EppException $e) {
catch(EppException $e)
{
return "Error : " . $e->getMessage(); return "Error : " . $e->getMessage();
} }
} }
@ -121,9 +111,9 @@ try {
$serverProhibited = count(array_intersect($serverStatuses, $statuses)) === count($serverStatuses); $serverProhibited = count(array_intersect($serverStatuses, $statuses)) === count($serverStatuses);
if ($clientProhibited || $serverProhibited) { if ($clientProhibited || $serverProhibited) {
$locked = 1; $locked = 1;
} else { } else {
$locked = 0; $locked = 0;
} }
// Prepare the UPDATE statement // Prepare the UPDATE statement
@ -150,6 +140,6 @@ try {
echo "Logout Result: " . $logout["code"] . ": " . $logout["msg"][0] . PHP_EOL; echo "Logout Result: " . $logout["code"] . ": " . $logout["msg"][0] . PHP_EOL;
} catch (PDOException $e) { } catch (PDOException $e) {
echo "Database error: " . $e->getMessage(); echo "Database error: " . $e->getMessage();
} catch(EppException $e) { } catch (EppException $e) {
echo "Error: ", $e->getMessage(); echo "Error: ", $e->getMessage();
} }

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Tembo EPP client library * Tembo EPP client library
* *
@ -42,15 +43,15 @@ class eppClient
} }
$opts = array( $opts = array(
'ssl' => array( 'ssl' => array(
'verify_peer' => (bool)$params['verify_peer'], 'verify_peer' => (bool)$params['verify_peer'],
'verify_peer_name' => (bool)$params['verify_peer_name'], 'verify_peer_name' => (bool)$params['verify_peer_name'],
'verify_host' => (bool)$params['verify_host'], 'verify_host' => (bool)$params['verify_host'],
'cafile' => (string)$params['cafile'], 'cafile' => (string)$params['cafile'],
'local_cert' => (string)$params['local_cert'], 'local_cert' => (string)$params['local_cert'],
'local_pk' => (string)$params['local_pk'], 'local_pk' => (string)$params['local_pk'],
'passphrase' => (string)$params['passphrase'], 'passphrase' => (string)$params['passphrase'],
'allow_self_signed' => (bool)$params['allow_self_signed'], 'allow_self_signed' => (bool)$params['allow_self_signed'],
'min_tls_version' => $tls 'min_tls_version' => $tls
) )
); );
if ($bind) { if ($bind) {
@ -93,18 +94,18 @@ class eppClient
if (fwrite($this->resource, pack('N', (strlen($xml) + 4)) . $xml) === false) { if (fwrite($this->resource, pack('N', (strlen($xml) + 4)) . $xml) === false) {
throw new exception('Error writing to the connection.'); throw new exception('Error writing to the connection.');
} }
$xml_string = $this->readResponse(); $xml_string = $this->readResponse();
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$r = simplexml_load_string($xml_string, 'SimpleXMLElement', LIBXML_DTDLOAD | LIBXML_NOENT); $r = simplexml_load_string($xml_string, 'SimpleXMLElement', LIBXML_DTDLOAD | LIBXML_NOENT);
if ($r instanceof SimpleXMLElement) { if ($r instanceof SimpleXMLElement) {
$r->registerXPathNamespace('e', 'urn:ietf:params:xml:ns:epp-1.0'); $r->registerXPathNamespace('e', 'urn:ietf:params:xml:ns:epp-1.0');
$r->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $r->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$r->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0'); $r->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0');
$r->registerXPathNamespace('contact', 'urn:ietf:params:xml:ns:contact-1.0'); $r->registerXPathNamespace('contact', 'urn:ietf:params:xml:ns:contact-1.0');
$r->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0'); $r->registerXPathNamespace('host', 'urn:ietf:params:xml:ns:host-1.0');
$r->registerXPathNamespace('rgp', 'urn:ietf:params:xml:ns:rgp-1.0'); $r->registerXPathNamespace('rgp', 'urn:ietf:params:xml:ns:rgp-1.0');
} }
if (isset($r->response) && $r->response->result->attributes()->code >= 2000) { if (isset($r->response) && $r->response->result->attributes()->code >= 2000) {
throw new \exception($r->response->result->msg); throw new \exception($r->response->result->msg);
} }
@ -123,8 +124,8 @@ class eppClient
} }
/** /**
* wrapper for functions * wrapper for functions
*/ */
public function __call($func, $args) public function __call($func, $args)
{ {
if (!function_exists($func)) { if (!function_exists($func)) {
@ -170,11 +171,11 @@ class eppClient
$from[] = '/{{ pwd }}/'; $from[] = '/{{ pwd }}/';
$to[] = htmlspecialchars($params['pw']); $to[] = htmlspecialchars($params['pw']);
if (isset($params['newpw']) && !empty($params['newpw'])) { if (isset($params['newpw']) && !empty($params['newpw'])) {
$from[] = '/{{ newpw }}/'; $from[] = '/{{ newpw }}/';
$to[] = PHP_EOL . ' <newPW>' . htmlspecialchars($params['newpw']) . '</newPW>'; $to[] = PHP_EOL . ' <newPW>' . htmlspecialchars($params['newpw']) . '</newPW>';
} else { } else {
$from[] = '/{{ newpw }}/'; $from[] = '/{{ newpw }}/';
$to[] = ''; $to[] = '';
} }
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$microtime = str_replace('.', '', round(microtime(1), 3)); $microtime = str_replace('.', '', round(microtime(1), 3));
@ -460,10 +461,10 @@ class eppClient
$from = $to = array(); $from = $to = array();
$from[] = '/{{ name }}/'; $from[] = '/{{ name }}/';
$to[] = htmlspecialchars($params['hostname']); $to[] = htmlspecialchars($params['hostname']);
$from[] = '/{{ ip }}/'; $from[] = '/{{ ip }}/';
$to[] = htmlspecialchars($params['ipaddress']); $to[] = htmlspecialchars($params['ipaddress']);
$from[] = '/{{ v }}/'; $from[] = '/{{ v }}/';
$to[] = (preg_match('/:/', $params['ipaddress']) ? 'v6' : 'v4'); $to[] = (preg_match('/:/', $params['ipaddress']) ? 'v6' : 'v4');
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$clTRID = str_replace('.', '', round(microtime(1), 3)); $clTRID = str_replace('.', '', round(microtime(1), 3));
$to[] = htmlspecialchars($this->prefix . '-host-create-' . $clTRID); $to[] = htmlspecialchars($this->prefix . '-host-create-' . $clTRID);
@ -519,16 +520,16 @@ class eppClient
$return = array(); $return = array();
try { try {
$from = $to = array(); $from = $to = array();
$from[] = '/{{ name }}/'; $from[] = '/{{ name }}/';
$to[] = htmlspecialchars($params['hostname']); $to[] = htmlspecialchars($params['hostname']);
$from[] = '/{{ ip1 }}/'; $from[] = '/{{ ip1 }}/';
$to[] = htmlspecialchars($params['currentipaddress']); $to[] = htmlspecialchars($params['currentipaddress']);
$from[] = '/{{ v1 }}/'; $from[] = '/{{ v1 }}/';
$to[] = (preg_match('/:/', $params['currentipaddress']) ? 'v6' : 'v4'); $to[] = (preg_match('/:/', $params['currentipaddress']) ? 'v6' : 'v4');
$from[] = '/{{ ip2 }}/'; $from[] = '/{{ ip2 }}/';
$to[] = htmlspecialchars($params['newipaddress']); $to[] = htmlspecialchars($params['newipaddress']);
$from[] = '/{{ v2 }}/'; $from[] = '/{{ v2 }}/';
$to[] = (preg_match('/:/', $params['newipaddress']) ? 'v6' : 'v4'); $to[] = (preg_match('/:/', $params['newipaddress']) ? 'v6' : 'v4');
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$clTRID = str_replace('.', '', round(microtime(1), 3)); $clTRID = str_replace('.', '', round(microtime(1), 3));
$to[] = htmlspecialchars($this->prefix . '-host-update-' . $clTRID); $to[] = htmlspecialchars($this->prefix . '-host-update-' . $clTRID);
@ -1359,14 +1360,14 @@ class eppClient
$from = $to = array(); $from = $to = array();
$text = ''; $text = '';
foreach ($add as $k => $v) { foreach ($add as $k => $v) {
$text.= '<domain:hostObj>' . $v . '</domain:hostObj>' . "\n"; $text .= '<domain:hostObj>' . $v . '</domain:hostObj>' . "\n";
} }
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = (empty($text) ? '' : "<domain:add><domain:ns>\n{$text}</domain:ns></domain:add>\n"); $to[] = (empty($text) ? '' : "<domain:add><domain:ns>\n{$text}</domain:ns></domain:add>\n");
$text = ''; $text = '';
foreach ($rem as $k => $v) { foreach ($rem as $k => $v) {
$text.= '<domain:hostObj>' . $v . '</domain:hostObj>' . "\n"; $text .= '<domain:hostObj>' . $v . '</domain:hostObj>' . "\n";
} }
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
@ -1428,21 +1429,21 @@ class eppClient
$from = $to = array(); $from = $to = array();
$from[] = '/{{ name }}/'; $from[] = '/{{ name }}/';
$to[] = htmlspecialchars($params['domainname']); $to[] = htmlspecialchars($params['domainname']);
if ($params['contacttype'] === 'registrant') { if ($params['contacttype'] === 'registrant') {
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = ""; $to[] = "";
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
$to[] = ""; $to[] = "";
$from[] = '/{{ chg }}/'; $from[] = '/{{ chg }}/';
$to[] = "<domain:chg><domain:registrant>".htmlspecialchars($params['new_contactid'])."</domain:registrant></domain:chg>\n"; $to[] = "<domain:chg><domain:registrant>" . htmlspecialchars($params['new_contactid']) . "</domain:registrant></domain:chg>\n";
} else { } else {
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = "<domain:add><domain:contact type=\"".htmlspecialchars($params['contacttype'])."\">".htmlspecialchars($params['new_contactid'])."</domain:contact></domain:add>\n"; $to[] = "<domain:add><domain:contact type=\"" . htmlspecialchars($params['contacttype']) . "\">" . htmlspecialchars($params['new_contactid']) . "</domain:contact></domain:add>\n";
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
$to[] = "<domain:rem><domain:contact type=\"".htmlspecialchars($params['contacttype'])."\">".htmlspecialchars($params['old_contactid'])."</domain:contact></domain:rem>\n"; $to[] = "<domain:rem><domain:contact type=\"" . htmlspecialchars($params['contacttype']) . "\">" . htmlspecialchars($params['old_contactid']) . "</domain:contact></domain:rem>\n";
$from[] = '/{{ chg }}/'; $from[] = '/{{ chg }}/';
$to[] = ""; $to[] = "";
} }
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$clTRID = str_replace('.', '', round(microtime(1), 3)); $clTRID = str_replace('.', '', round(microtime(1), 3));
$to[] = htmlspecialchars($this->prefix . '-domain-updateContact-' . $clTRID); $to[] = htmlspecialchars($this->prefix . '-domain-updateContact-' . $clTRID);
@ -1500,17 +1501,17 @@ class eppClient
$from = $to = array(); $from = $to = array();
$from[] = '/{{ name }}/'; $from[] = '/{{ name }}/';
$to[] = htmlspecialchars($params['domainname']); $to[] = htmlspecialchars($params['domainname']);
if ($params['command'] === 'add') { if ($params['command'] === 'add') {
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = "<domain:add><domain:status s=\"".htmlspecialchars($params['status'])."\"/></domain:add>\n"; $to[] = "<domain:add><domain:status s=\"" . htmlspecialchars($params['status']) . "\"/></domain:add>\n";
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
$to[] = ""; $to[] = "";
} else if ($params['command'] === 'rem') { } else if ($params['command'] === 'rem') {
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = ""; $to[] = "";
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
$to[] = "<domain:rem><domain:status s=\"".htmlspecialchars($params['status'])."\"/></domain:rem>\n"; $to[] = "<domain:rem><domain:status s=\"" . htmlspecialchars($params['status']) . "\"/></domain:rem>\n";
} }
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$clTRID = str_replace('.', '', round(microtime(1), 3)); $clTRID = str_replace('.', '', round(microtime(1), 3));
$to[] = htmlspecialchars($this->prefix . '-domain-updateStatus-' . $clTRID); $to[] = htmlspecialchars($this->prefix . '-domain-updateStatus-' . $clTRID);
@ -1628,57 +1629,57 @@ class eppClient
$from = $to = array(); $from = $to = array();
$from[] = '/{{ name }}/'; $from[] = '/{{ name }}/';
$to[] = htmlspecialchars($params['domainname']); $to[] = htmlspecialchars($params['domainname']);
if ($params['command'] == 'add') { if ($params['command'] == 'add') {
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = "<secDNS:add> $to[] = "<secDNS:add>
<secDNS:dsData> <secDNS:dsData>
<secDNS:keyTag>".htmlspecialchars($params['keyTag_1'])."</secDNS:keyTag> <secDNS:keyTag>" . htmlspecialchars($params['keyTag_1']) . "</secDNS:keyTag>
<secDNS:alg>".htmlspecialchars($params['alg_1'])."</secDNS:alg> <secDNS:alg>" . htmlspecialchars($params['alg_1']) . "</secDNS:alg>
<secDNS:digestType>".htmlspecialchars($params['digestType_1'])."</secDNS:digestType> <secDNS:digestType>" . htmlspecialchars($params['digestType_1']) . "</secDNS:digestType>
<secDNS:digest>".htmlspecialchars($params['digest_1'])."</secDNS:digest> <secDNS:digest>" . htmlspecialchars($params['digest_1']) . "</secDNS:digest>
</secDNS:dsData> </secDNS:dsData>
</secDNS:add>"; </secDNS:add>";
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
$to[] = ""; $to[] = "";
$from[] = '/{{ addrem }}/'; $from[] = '/{{ addrem }}/';
$to[] = ""; $to[] = "";
} else if ($params['command'] == 'rem') { } else if ($params['command'] == 'rem') {
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = ""; $to[] = "";
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
$to[] = "<secDNS:rem> $to[] = "<secDNS:rem>
<secDNS:dsData> <secDNS:dsData>
<secDNS:keyTag>".htmlspecialchars($params['keyTag_1'])."</secDNS:keyTag> <secDNS:keyTag>" . htmlspecialchars($params['keyTag_1']) . "</secDNS:keyTag>
<secDNS:alg>".htmlspecialchars($params['alg_1'])."</secDNS:alg> <secDNS:alg>" . htmlspecialchars($params['alg_1']) . "</secDNS:alg>
<secDNS:digestType>".htmlspecialchars($params['digestType_1'])."</secDNS:digestType> <secDNS:digestType>" . htmlspecialchars($params['digestType_1']) . "</secDNS:digestType>
<secDNS:digest>".htmlspecialchars($params['digest_1'])."</secDNS:digest> <secDNS:digest>" . htmlspecialchars($params['digest_1']) . "</secDNS:digest>
</secDNS:dsData> </secDNS:dsData>
</secDNS:rem>"; </secDNS:rem>";
$from[] = '/{{ addrem }}/'; $from[] = '/{{ addrem }}/';
$to[] = ""; $to[] = "";
} else if ($params['command'] == 'addrem') { } else if ($params['command'] == 'addrem') {
$from[] = '/{{ add }}/'; $from[] = '/{{ add }}/';
$to[] = ""; $to[] = "";
$from[] = '/{{ rem }}/'; $from[] = '/{{ rem }}/';
$to[] = ""; $to[] = "";
$from[] = '/{{ addrem }}/'; $from[] = '/{{ addrem }}/';
$to[] = "<secDNS:rem> $to[] = "<secDNS:rem>
<secDNS:dsData> <secDNS:dsData>
<secDNS:keyTag>".htmlspecialchars($params['keyTag_1'])."</secDNS:keyTag> <secDNS:keyTag>" . htmlspecialchars($params['keyTag_1']) . "</secDNS:keyTag>
<secDNS:alg>".htmlspecialchars($params['alg_1'])."</secDNS:alg> <secDNS:alg>" . htmlspecialchars($params['alg_1']) . "</secDNS:alg>
<secDNS:digestType>".htmlspecialchars($params['digestType_1'])."</secDNS:digestType> <secDNS:digestType>" . htmlspecialchars($params['digestType_1']) . "</secDNS:digestType>
<secDNS:digest>".htmlspecialchars($params['digest_1'])."</secDNS:digest> <secDNS:digest>" . htmlspecialchars($params['digest_1']) . "</secDNS:digest>
</secDNS:dsData> </secDNS:dsData>
</secDNS:rem> </secDNS:rem>
<secDNS:add> <secDNS:add>
<secDNS:dsData> <secDNS:dsData>
<secDNS:keyTag>".htmlspecialchars($params['keyTag_2'])."</secDNS:keyTag> <secDNS:keyTag>" . htmlspecialchars($params['keyTag_2']) . "</secDNS:keyTag>
<secDNS:alg>".htmlspecialchars($params['alg_2'])."</secDNS:alg> <secDNS:alg>" . htmlspecialchars($params['alg_2']) . "</secDNS:alg>
<secDNS:digestType>".htmlspecialchars($params['digestType_2'])."</secDNS:digestType> <secDNS:digestType>" . htmlspecialchars($params['digestType_2']) . "</secDNS:digestType>
<secDNS:digest>".htmlspecialchars($params['digest_2'])."</secDNS:digest> <secDNS:digest>" . htmlspecialchars($params['digest_2']) . "</secDNS:digest>
</secDNS:dsData> </secDNS:dsData>
</secDNS:add>"; </secDNS:add>";
} }
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$clTRID = str_replace('.', '', round(microtime(1), 3)); $clTRID = str_replace('.', '', round(microtime(1), 3));
$to[] = htmlspecialchars($this->prefix . '-domain-updateDNSSEC-' . $clTRID); $to[] = htmlspecialchars($this->prefix . '-domain-updateDNSSEC-' . $clTRID);
@ -1742,43 +1743,43 @@ class eppClient
$from = $to = array(); $from = $to = array();
$from[] = '/{{ name }}/'; $from[] = '/{{ name }}/';
$to[] = htmlspecialchars($params['domainname']); $to[] = htmlspecialchars($params['domainname']);
switch (htmlspecialchars($params['op'])) { switch (htmlspecialchars($params['op'])) {
case 'request': case 'request':
$from[] = '/{{ years }}/'; $from[] = '/{{ years }}/';
$to[] = (int)($params['years']); $to[] = (int)($params['years']);
$from[] = '/{{ authInfoPw }}/'; $from[] = '/{{ authInfoPw }}/';
$to[] = htmlspecialchars($params['authInfoPw']); $to[] = htmlspecialchars($params['authInfoPw']);
$xmltype = 'req'; $xmltype = 'req';
break; break;
case 'query': case 'query':
$from[] = '/{{ type }}/'; $from[] = '/{{ type }}/';
$to[] = 'query'; $to[] = 'query';
$xmltype = 'oth'; $xmltype = 'oth';
break; break;
case 'cancel': case 'cancel':
$from[] = '/{{ type }}/'; $from[] = '/{{ type }}/';
$to[] = 'cancel'; $to[] = 'cancel';
$xmltype = 'oth'; $xmltype = 'oth';
break; break;
case 'reject': case 'reject':
$from[] = '/{{ type }}/'; $from[] = '/{{ type }}/';
$to[] = 'reject'; $to[] = 'reject';
$xmltype = 'oth'; $xmltype = 'oth';
break; break;
case 'approve': case 'approve':
$xmltype = 'apr'; $xmltype = 'apr';
break; break;
default: default:
throw new EppException('Invalid value for transfer:op specified.'); throw new EppException('Invalid value for transfer:op specified.');
break; break;
} }
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$clTRID = str_replace('.', '', round(microtime(1), 3)); $clTRID = str_replace('.', '', round(microtime(1), 3));
$to[] = htmlspecialchars($this->prefix . '-domain-transfer-' . $clTRID); $to[] = htmlspecialchars($this->prefix . '-domain-transfer-' . $clTRID);
$from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims"; $from[] = "/<\w+:\w+>\s*<\/\w+:\w+>\s+/ims";
$to[] = ''; $to[] = '';
if ($xmltype === 'req') { if ($xmltype === 'req') {
$xml = preg_replace($from, $to, '<?xml version="1.0" encoding="UTF-8" standalone="no"?> $xml = preg_replace($from, $to, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
@ -1797,32 +1798,31 @@ class eppClient
</command> </command>
</epp>'); </epp>');
$r = $this->writeRequest($xml); $r = $this->writeRequest($xml);
$code = (int)$r->response->result->attributes()->code; $code = (int)$r->response->result->attributes()->code;
$msg = (string)$r->response->result->msg; $msg = (string)$r->response->result->msg;
$r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->trnData; $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->trnData;
$name = (string)$r->name; $name = (string)$r->name;
$trStatus = (string)$r->trStatus; $trStatus = (string)$r->trStatus;
$reID = (string)$r->reID; $reID = (string)$r->reID;
$reDate = (string)$r->reDate; $reDate = (string)$r->reDate;
$acID = (string)$r->acID; $acID = (string)$r->acID;
$acDate = (string)$r->acDate; $acDate = (string)$r->acDate;
$exDate = (string)$r->exDate; $exDate = (string)$r->exDate;
$return = array( $return = array(
'code' => $code, 'code' => $code,
'msg' => $msg, 'msg' => $msg,
'name' => $name, 'name' => $name,
'trStatus' => $trStatus, 'trStatus' => $trStatus,
'reID' => $reID, 'reID' => $reID,
'reDate' => $reDate, 'reDate' => $reDate,
'acID' => $acID, 'acID' => $acID,
'acDate' => $acDate, 'acDate' => $acDate,
'exDate' => $exDate 'exDate' => $exDate
); );
} else if ($xmltype === 'apr') {
} else if ($xmltype === 'apr') { $xml = preg_replace($from, $to, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
$xml = preg_replace($from, $to, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
@ -1837,26 +1837,25 @@ class eppClient
</command> </command>
</epp>'); </epp>');
$r = $this->writeRequest($xml); $r = $this->writeRequest($xml);
$code = (int)$r->response->result->attributes()->code; $code = (int)$r->response->result->attributes()->code;
$msg = (string)$r->response->result->msg; $msg = (string)$r->response->result->msg;
$r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->Data; $r = $r->response->resData->children('urn:ietf:params:xml:ns:domain-1.0')->Data;
$name = (string)$r->name; $name = (string)$r->name;
$trStatus = (string)$r->trStatus; $trStatus = (string)$r->trStatus;
$reID = (string)$r->reID; $reID = (string)$r->reID;
$reDate = (string)$r->reDate; $reDate = (string)$r->reDate;
$return = array( $return = array(
'code' => $code, 'code' => $code,
'msg' => $msg, 'msg' => $msg,
'name' => $name, 'name' => $name,
'trStatus' => $trStatus, 'trStatus' => $trStatus,
'reID' => $reID, 'reID' => $reID,
'reDate' => $reDate 'reDate' => $reDate
); );
} else if ($xmltype === 'oth') {
} else if ($xmltype === 'oth') { $xml = preg_replace($from, $to, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
$xml = preg_replace($from, $to, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
@ -1871,16 +1870,15 @@ class eppClient
</command> </command>
</epp>'); </epp>');
$r = $this->writeRequest($xml); $r = $this->writeRequest($xml);
$code = (int)$r->response->result->attributes()->code; $code = (int)$r->response->result->attributes()->code;
$msg = (string)$r->response->result->msg; $msg = (string)$r->response->result->msg;
$return = array( $return = array(
'code' => $code, 'code' => $code,
'msg' => $msg 'msg' => $msg
); );
}
}
} catch (\Exception $e) { } catch (\Exception $e) {
$return = array( $return = array(
'error' => $e->getMessage() 'error' => $e->getMessage()
@ -1923,9 +1921,9 @@ class eppClient
$from[] = '/{{ registrant }}/'; $from[] = '/{{ registrant }}/';
$to[] = htmlspecialchars($params['registrant']); $to[] = htmlspecialchars($params['registrant']);
$text = ''; $text = '';
foreach ($params['contacts'] as $contactType => $contactID) { foreach ($params['contacts'] as $contactType => $contactID) {
$text .= '<domain:contact type="' . $contactType . '">' . $contactID . '</domain:contact>' . "\n"; $text .= '<domain:contact type="' . $contactType . '">' . $contactID . '</domain:contact>' . "\n";
} }
$from[] = '/{{ contacts }}/'; $from[] = '/{{ contacts }}/';
$to[] = $text; $to[] = $text;
$from[] = '/{{ authInfoPw }}/'; $from[] = '/{{ authInfoPw }}/';
@ -2015,36 +2013,36 @@ class eppClient
$from[] = '/{{ registrant }}/'; $from[] = '/{{ registrant }}/';
$to[] = htmlspecialchars($params['registrant']); $to[] = htmlspecialchars($params['registrant']);
$text = ''; $text = '';
foreach ($params['contacts'] as $contactType => $contactID) { foreach ($params['contacts'] as $contactType => $contactID) {
$text .= '<domain:contact type="' . $contactType . '">' . $contactID . '</domain:contact>' . "\n"; $text .= '<domain:contact type="' . $contactType . '">' . $contactID . '</domain:contact>' . "\n";
} }
$from[] = '/{{ contacts }}/'; $from[] = '/{{ contacts }}/';
$to[] = $text; $to[] = $text;
$from[] = '/{{ authInfoPw }}/'; $from[] = '/{{ authInfoPw }}/';
$to[] = htmlspecialchars($params['authInfoPw']); $to[] = htmlspecialchars($params['authInfoPw']);
if ($params['dnssec_records'] == 1) { if ($params['dnssec_records'] == 1) {
$from[] = '/{{ dnssec_data }}/'; $from[] = '/{{ dnssec_data }}/';
$to[] = "<secDNS:dsData> $to[] = "<secDNS:dsData>
<secDNS:keyTag>".htmlspecialchars($params['keyTag_1'])."</secDNS:keyTag> <secDNS:keyTag>" . htmlspecialchars($params['keyTag_1']) . "</secDNS:keyTag>
<secDNS:alg>".htmlspecialchars($params['alg_1'])."</secDNS:alg> <secDNS:alg>" . htmlspecialchars($params['alg_1']) . "</secDNS:alg>
<secDNS:digestType>".htmlspecialchars($params['digestType_1'])."</secDNS:digestType> <secDNS:digestType>" . htmlspecialchars($params['digestType_1']) . "</secDNS:digestType>
<secDNS:digest>".htmlspecialchars($params['digest_1'])."</secDNS:digest> <secDNS:digest>" . htmlspecialchars($params['digest_1']) . "</secDNS:digest>
</secDNS:dsData>"; </secDNS:dsData>";
} else if ($params['dnssec_records'] == 2) { } else if ($params['dnssec_records'] == 2) {
$from[] = '/{{ dnssec_data }}/'; $from[] = '/{{ dnssec_data }}/';
$to[] = "<secDNS:dsData> $to[] = "<secDNS:dsData>
<secDNS:keyTag>".htmlspecialchars($params['keyTag_1'])."</secDNS:keyTag> <secDNS:keyTag>" . htmlspecialchars($params['keyTag_1']) . "</secDNS:keyTag>
<secDNS:alg>".htmlspecialchars($params['alg_1'])."</secDNS:alg> <secDNS:alg>" . htmlspecialchars($params['alg_1']) . "</secDNS:alg>
<secDNS:digestType>".htmlspecialchars($params['digestType_1'])."</secDNS:digestType> <secDNS:digestType>" . htmlspecialchars($params['digestType_1']) . "</secDNS:digestType>
<secDNS:digest>".htmlspecialchars($params['digest_1'])."</secDNS:digest> <secDNS:digest>" . htmlspecialchars($params['digest_1']) . "</secDNS:digest>
</secDNS:dsData> </secDNS:dsData>
<secDNS:dsData> <secDNS:dsData>
<secDNS:keyTag>".htmlspecialchars($params['keyTag_2'])."</secDNS:keyTag> <secDNS:keyTag>" . htmlspecialchars($params['keyTag_2']) . "</secDNS:keyTag>
<secDNS:alg>".htmlspecialchars($params['alg_2'])."</secDNS:alg> <secDNS:alg>" . htmlspecialchars($params['alg_2']) . "</secDNS:alg>
<secDNS:digestType>".htmlspecialchars($params['digestType_2'])."</secDNS:digestType> <secDNS:digestType>" . htmlspecialchars($params['digestType_2']) . "</secDNS:digestType>
<secDNS:digest>".htmlspecialchars($params['digest_2'])."</secDNS:digest> <secDNS:digest>" . htmlspecialchars($params['digest_2']) . "</secDNS:digest>
</secDNS:dsData>"; </secDNS:dsData>";
} }
$from[] = '/{{ clTRID }}/'; $from[] = '/{{ clTRID }}/';
$clTRID = str_replace('.', '', round(microtime(1), 3)); $clTRID = str_replace('.', '', round(microtime(1), 3));
$to[] = htmlspecialchars($this->prefix . '-domain-createDNSSEC-' . $clTRID); $to[] = htmlspecialchars($this->prefix . '-domain-createDNSSEC-' . $clTRID);
@ -2137,9 +2135,9 @@ class eppClient
$from[] = '/{{ registrant }}/'; $from[] = '/{{ registrant }}/';
$to[] = htmlspecialchars($params['registrant']); $to[] = htmlspecialchars($params['registrant']);
$text = ''; $text = '';
foreach ($params['contacts'] as $contactType => $contactID) { foreach ($params['contacts'] as $contactType => $contactID) {
$text .= '<domain:contact type="' . $contactType . '">' . $contactID . '</domain:contact>' . "\n"; $text .= '<domain:contact type="' . $contactType . '">' . $contactID . '</domain:contact>' . "\n";
} }
$from[] = '/{{ contacts }}/'; $from[] = '/{{ contacts }}/';
$to[] = $text; $to[] = $text;
$from[] = '/{{ authInfoPw }}/'; $from[] = '/{{ authInfoPw }}/';
@ -2529,10 +2527,10 @@ class eppClient
$r = $this->writeRequest($xml); $r = $this->writeRequest($xml);
$code = (int)$r->response->result->attributes()->code; $code = (int)$r->response->result->attributes()->code;
$msg = (string)$r->response->result->msg; $msg = (string)$r->response->result->msg;
$messages = (int)($r->response->msgQ->attributes()->count ?? 0); $messages = (int)($r->response->msgQ->attributes()->count ?? 0);
$last_id = (int)($r->response->msgQ->attributes()->id ?? 0); $last_id = (int)($r->response->msgQ->attributes()->id ?? 0);
$qDate = (string)($r->response->msgQ->qDate ?? ''); $qDate = (string)($r->response->msgQ->qDate ?? '');
$last_msg = (string)($r->response->msgQ->msg ?? ''); $last_msg = (string)($r->response->msgQ->msg ?? '');
$return = array( $return = array(
'code' => $code, 'code' => $code,