Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
feat(auto idn conversion): for Object related commands
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed Aug 16, 2021
1 parent fbf9da3 commit a855500
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 171 deletions.
29 changes: 18 additions & 11 deletions src/APIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function setUserAgent($str, $rv, $modules = [])
{
$mods = empty($modules) ? "" : " " . implode(" ", $modules);
$this->ua = (
$str . " (" . PHP_OS . "; " . php_uname('m') . "; rv:" . $rv . ")" . $mods . " php-sdk/" . $this->getVersion() . " php/" . implode(".", [PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION])
$str . " (" . PHP_OS . "; " . php_uname("m") . "; rv:" . $rv . ")" . $mods . " php-sdk/" . $this->getVersion() . " php/" . implode(".", [PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION])
);
return $this;
}
Expand All @@ -186,7 +186,7 @@ public function setUserAgent($str, $rv, $modules = [])
public function getUserAgent()
{
if (!strlen($this->ua)) {
$this->ua = "PHP-SDK (" . PHP_OS . "; " . php_uname('m') . "; rv:" . $this->getVersion() . ") php/" . implode(".", [PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION]);
$this->ua = "PHP-SDK (" . PHP_OS . "; " . php_uname("m") . "; rv:" . $this->getVersion() . ") php/" . implode(".", [PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION]);
}
return $this->ua;
}
Expand Down Expand Up @@ -429,18 +429,25 @@ private function autoIDNConvert($cmd)
if (is_string($cmd) || preg_match("/^CONVERTIDN$/i", $cmd["COMMAND"])) {
return $cmd;
}
$keys = preg_grep("/^(DOMAIN|NAMESERVER|DNSZONE)([0-9]*)$/i", array_keys($cmd));
$cmdkeys = array_keys($cmd);
$prodregex = "/^(DOMAIN|NAMESERVER|DNSZONE|OBJECTID)([0-9]*)$/";
$keys = preg_grep($prodregex, $cmdkeys);
if (empty($keys)) {
return $cmd;
}
$toconvert = [];
$idxs = [];
foreach ($keys as $key) {
if (isset($cmd[$key])) {
if (preg_match('/[^a-z0-9\.\- ]/i', $cmd[$key])) {// maybe preg_grep as replacement
$toconvert[] = $cmd[$key];
$idxs[] = $key;
}
if (
isset($cmd[$key])
&& preg_match("/[^a-z0-9\.\- ]/i", $cmd[$key])
&& (
($key !== "OBJECTID")
|| preg_match("/^(DOMAIN|NAMESERVER|DNSZONE)$/", $cmd["OBJECTCLASS"])
)
) {
$toconvert[] = $cmd[$key];
$idxs[] = $key;
}
}
if (empty($toconvert)) {
Expand Down Expand Up @@ -495,8 +502,8 @@ public function request($cmd)
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => $this->getUserAgent(),
CURLOPT_HTTPHEADER => [
'Expect:',
'Content-type: text/html; charset=UTF-8'
"Expect:",
"Content-type: text/html; charset=UTF-8"
]
] + $this->curlopts);
$r = curl_exec($curl);
Expand Down Expand Up @@ -566,7 +573,7 @@ public function requestAllResponsePages($cmd)
* @param string $uid subuser account name
* @return $this
*/
public function setUserView($uid = '')
public function setUserView($uid = "")
{
$this->socketConfig->setUser($uid);
return $this;
Expand Down
8 changes: 4 additions & 4 deletions src/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Record
* e.g.
* <code>
* $data = [
* 'DOMAIN' => 'mydomain.com',
* 'USER' => 'test.user',
* "DOMAIN" => "mydomain.com",
* "USER" => "test.user",
* // ... further column data ...
* ];
* </code>
Expand All @@ -36,8 +36,8 @@ class Record
* e.g.
* <code>
* $data = [
* 'DOMAIN' => 'mydomain.com',
* 'USER' => 'test.user',
* "DOMAIN" => "mydomain.com",
* "USER" => "test.user",
* // ... further column data ...
* ];
* </code>
Expand Down
Loading

0 comments on commit a855500

Please sign in to comment.