From f563d546d5d2124a7e7c8cba3ca3eefa51d558ef Mon Sep 17 00:00:00 2001 From: viacheslav diomidov Date: Tue, 5 Oct 2021 14:11:33 +0300 Subject: [PATCH 1/3] BUGFIX EXTREST-137 simpleXml fix for & in values. --- src/Api/Client.php | 9 +++++++-- src/Api/Operator.php | 2 +- src/Api/Operator/Certificate.php | 2 +- src/Api/Operator/Customer.php | 2 +- src/Api/Operator/Database.php | 4 ++-- src/Api/Operator/DatabaseServer.php | 2 +- src/Api/Operator/Dns.php | 4 ++-- src/Api/Operator/DnsTemplate.php | 4 ++-- src/Api/Operator/Mail.php | 4 ++-- src/Api/Operator/ProtectedDirectory.php | 8 ++++---- src/Api/Operator/Reseller.php | 2 +- src/Api/Operator/Site.php | 6 +++--- src/Api/Operator/SiteAlias.php | 2 +- src/Api/Operator/Subdomain.php | 6 +++--- src/Api/Operator/Ui.php | 2 +- src/Api/Operator/Webspace.php | 4 ++-- tests/Utility/PasswordProvider.php | 2 +- 17 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/Api/Client.php b/src/Api/Client.php index 3f79d3f1..80e83be6 100644 --- a/src/Api/Client.php +++ b/src/Api/Client.php @@ -320,10 +320,15 @@ protected function _expandRequestShortSyntax($request, SimpleXMLElement $xml) { $parts = explode('.', $request); $node = $xml; + $lastParts = end($parts); foreach ($parts as $part) { @list($name, $value) = explode('=', $part); - $node = $node->addChild($name, $value); + if ($part !== $lastParts) { + $node = $node->addChild($name); + } else { + $node->{$name} = (string) $value; + } } return $xml->asXML(); @@ -345,7 +350,7 @@ protected function _arrayToXml(array $array, SimpleXMLElement $xml, $parentEl = if (is_array($value)) { $this->_arrayToXml($value, $this->_isAssocArray($value) ? $xml->addChild($el) : $xml, $el); } else { - $xml->addChild($el, $value); + $xml->{$el} = (string) $value; } } diff --git a/src/Api/Operator.php b/src/Api/Operator.php index bab9b2b3..7ab4af86 100644 --- a/src/Api/Operator.php +++ b/src/Api/Operator.php @@ -81,7 +81,7 @@ protected function _getItems($structClass, $infoTag, $field = null, $value = nul $filterTag = $getTag->addChild('filter'); if (!is_null($field)) { - $filterTag->addChild($field, $value); + $filterTag->{$field} = $value; } $getTag->addChild('dataset')->addChild($infoTag); diff --git a/src/Api/Operator/Certificate.php b/src/Api/Operator/Certificate.php index d82969a6..9113e148 100644 --- a/src/Api/Operator/Certificate.php +++ b/src/Api/Operator/Certificate.php @@ -18,7 +18,7 @@ public function generate($properties) $info = $packet->addChild($this->_wrapperTag)->addChild('generate')->addChild('info'); foreach ($properties as $name => $value) { - $info->addChild($name, $value); + $info->{$name} = $value; } $response = $this->_client->request($packet); diff --git a/src/Api/Operator/Customer.php b/src/Api/Operator/Customer.php index 6fcaec0d..d974c559 100644 --- a/src/Api/Operator/Customer.php +++ b/src/Api/Operator/Customer.php @@ -18,7 +18,7 @@ public function create($properties) $info = $packet->addChild($this->_wrapperTag)->addChild('add')->addChild('gen_info'); foreach ($properties as $name => $value) { - $info->addChild($name, $value); + $info->{$name} = $value; } $response = $this->_client->request($packet); diff --git a/src/Api/Operator/Database.php b/src/Api/Operator/Database.php index 30e1458a..8e5696ae 100644 --- a/src/Api/Operator/Database.php +++ b/src/Api/Operator/Database.php @@ -43,7 +43,7 @@ private function _process($command, array $properties) $info->$name = $value; continue; } - $info->addChild($name, $value); + $info->{$name} = $value; } return $this->_client->request($packet); @@ -135,7 +135,7 @@ private function _get($command, $field, $value) $filterTag = $getTag->addChild('filter'); if (!is_null($field)) { - $filterTag->addChild($field, $value); + $filterTag->{$field} = $value; } $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); diff --git a/src/Api/Operator/DatabaseServer.php b/src/Api/Operator/DatabaseServer.php index 482d1d81..fc338ea6 100644 --- a/src/Api/Operator/DatabaseServer.php +++ b/src/Api/Operator/DatabaseServer.php @@ -53,7 +53,7 @@ private function _get($field = null, $value = null) $filterTag = $getTag->addChild('filter'); if (!is_null($field)) { - $filterTag->addChild($field, $value); + $filterTag->{$field} = $value; } $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); diff --git a/src/Api/Operator/Dns.php b/src/Api/Operator/Dns.php index 0c64980e..30920a71 100644 --- a/src/Api/Operator/Dns.php +++ b/src/Api/Operator/Dns.php @@ -18,7 +18,7 @@ public function create($properties) $info = $packet->addChild($this->_wrapperTag)->addChild('add_rec'); foreach ($properties as $name => $value) { - $info->addChild($name, $value); + $info->{$name} = $value; } return new Struct\Info($this->_client->request($packet)); @@ -39,7 +39,7 @@ public function bulkCreate(array $records) $info = $packet->addChild($this->_wrapperTag)->addChild('add_rec'); foreach ($properties as $name => $value) { - $info->addChild($name, $value); + $info->{$name} = $value; } } diff --git a/src/Api/Operator/DnsTemplate.php b/src/Api/Operator/DnsTemplate.php index 4b79df77..18e66344 100644 --- a/src/Api/Operator/DnsTemplate.php +++ b/src/Api/Operator/DnsTemplate.php @@ -21,7 +21,7 @@ public function create(array $properties) unset($properties['site-id'], $properties['site-alias-id']); foreach ($properties as $name => $value) { - $info->addChild($name, $value); + $info->{$name} = $value; } return new Struct\Info($this->_client->request($packet)); @@ -53,7 +53,7 @@ public function getAll($field = null, $value = null) $filterTag = $getTag->addChild('filter'); if (!is_null($field)) { - $filterTag->addChild($field, $value); + $filterTag->{$field} = $value; } $getTag->addChild('template'); diff --git a/src/Api/Operator/Mail.php b/src/Api/Operator/Mail.php index 5d5b7fb4..0fa01380 100644 --- a/src/Api/Operator/Mail.php +++ b/src/Api/Operator/Mail.php @@ -28,7 +28,7 @@ public function create($name, $siteId, $mailbox = false, $password = '') $mailname->addChild('mailbox')->addChild('enabled', 'true'); } if (!empty($password)) { - $mailname->addChild('password')->addChild('value', $password); + $mailname->addChild('password')->value = $password; } $response = $this->_client->request($packet); @@ -48,7 +48,7 @@ public function delete($field, $value, $siteId) $packet = $this->_client->getPacket(); $filter = $packet->addChild($this->_wrapperTag)->addChild('remove')->addChild('filter'); $filter->addChild('site-id', $siteId); - $filter->addChild($field, $value); + $filter->{$field} = $value; $response = $this->_client->request($packet); return 'ok' === (string) $response->status; diff --git a/src/Api/Operator/ProtectedDirectory.php b/src/Api/Operator/ProtectedDirectory.php index af643b0a..b1ce6a95 100644 --- a/src/Api/Operator/ProtectedDirectory.php +++ b/src/Api/Operator/ProtectedDirectory.php @@ -81,9 +81,9 @@ public function addUser($protectedDirectory, $login, $password) $packet = $this->_client->getPacket(); $info = $packet->addChild($this->_wrapperTag)->addChild('add-user'); - $info->addChild('pd-id', $protectedDirectory->id); - $info->addChild('login', $login); - $info->addChild('password', $password); + $info->{'pd-id'} = $protectedDirectory->id; + $info->login = $login; + $info->password = $password; return new Struct\UserInfo($this->_client->request($packet)); } @@ -113,7 +113,7 @@ private function _get($command, $field, $value) $filterTag = $getTag->addChild('filter'); if (!is_null($field)) { - $filterTag->addChild($field, $value); + $filterTag->{$field} = $value; } $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); diff --git a/src/Api/Operator/Reseller.php b/src/Api/Operator/Reseller.php index 9ee8af0c..bcf76d32 100644 --- a/src/Api/Operator/Reseller.php +++ b/src/Api/Operator/Reseller.php @@ -18,7 +18,7 @@ public function create($properties) $info = $packet->addChild($this->_wrapperTag)->addChild('add')->addChild('gen-info'); foreach ($properties as $name => $value) { - $info->addChild($name, $value); + $info->{$name} = $value; } $response = $this->_client->request($packet); diff --git a/src/Api/Operator/Site.php b/src/Api/Operator/Site.php index 170f7e32..f92eae62 100644 --- a/src/Api/Operator/Site.php +++ b/src/Api/Operator/Site.php @@ -24,7 +24,7 @@ public function create(array $properties) if (!is_scalar($value)) { continue; } - $infoGeneral->addChild($name, $value); + $infoGeneral->{$name} = $value; } // set hosting properties @@ -32,8 +32,8 @@ public function create(array $properties) $hostingNode = $info->addChild('hosting')->addChild('vrt_hst'); foreach ($properties[static::PROPERTIES_HOSTING] as $name => $value) { $propertyNode = $hostingNode->addChild('property'); - $propertyNode->addChild('name', $name); - $propertyNode->addChild('value', $value); + $propertyNode->name = $name; + $propertyNode->value = $value; } } diff --git a/src/Api/Operator/SiteAlias.php b/src/Api/Operator/SiteAlias.php index be8f735c..5135e1cf 100644 --- a/src/Api/Operator/SiteAlias.php +++ b/src/Api/Operator/SiteAlias.php @@ -71,7 +71,7 @@ public function getAll($field = null, $value = null) $filterTag = $getTag->addChild('filter'); if (!is_null($field)) { - $filterTag->addChild($field, $value); + $filterTag->{$field} = $value; } $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); diff --git a/src/Api/Operator/Subdomain.php b/src/Api/Operator/Subdomain.php index ece56e4b..de1eb3a7 100644 --- a/src/Api/Operator/Subdomain.php +++ b/src/Api/Operator/Subdomain.php @@ -21,12 +21,12 @@ public function create($properties) if (is_array($value)) { foreach ($value as $propertyName => $propertyValue) { $property = $info->addChild($name); - $property->addChild('name', $propertyName); - $property->addChild('value', $propertyValue); + $property->name = $propertyName; + $property->value = $propertyValue; } continue; } - $info->addChild($name, $value); + $info->{$name} = $value; } $response = $this->_client->request($packet); diff --git a/src/Api/Operator/Ui.php b/src/Api/Operator/Ui.php index b2ac6576..187fcd24 100644 --- a/src/Api/Operator/Ui.php +++ b/src/Api/Operator/Ui.php @@ -31,7 +31,7 @@ public function createCustomButton($owner, $properties) $propertiesNode = $buttonNode->addChild('properties'); foreach ($properties as $name => $value) { - $propertiesNode->addChild($name, $value); + $propertiesNode->{$name} = $value; } $response = $this->_client->request($packet); diff --git a/src/Api/Operator/Webspace.php b/src/Api/Operator/Webspace.php index e389c576..2bfef7d6 100644 --- a/src/Api/Operator/Webspace.php +++ b/src/Api/Operator/Webspace.php @@ -81,8 +81,8 @@ public function create(array $properties, array $hostingProperties = null, $plan $infoHosting = $info->addChild('hosting')->addChild('vrt_hst'); foreach ($hostingProperties as $name => $value) { $property = $infoHosting->addChild('property'); - $property->addChild('name', $name); - $property->addChild('value', $value); + $property->name = $name; + $property->value = $value; } if (isset($properties['ip_address'])) { diff --git a/tests/Utility/PasswordProvider.php b/tests/Utility/PasswordProvider.php index 2083642d..1c306aa2 100644 --- a/tests/Utility/PasswordProvider.php +++ b/tests/Utility/PasswordProvider.php @@ -5,5 +5,5 @@ class PasswordProvider { - const STRONG_PASSWORD = 'test-PWD*1@42!13#'; + const STRONG_PASSWORD = 'test-&PWD*1@42!13#'; } From 796ea2c8eeead4e6c17793fcef60c2ba56d74c05 Mon Sep 17 00:00:00 2001 From: Alexandr Bashurov Date: Mon, 28 Mar 2022 20:25:14 +0700 Subject: [PATCH 2/3] BUGFIX EXTREST-143 Extend already set properties instead of overwriting them --- src/Api/Client.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Api/Client.php b/src/Api/Client.php index 80e83be6..fb2e4a94 100644 --- a/src/Api/Client.php +++ b/src/Api/Client.php @@ -349,8 +349,10 @@ protected function _arrayToXml(array $array, SimpleXMLElement $xml, $parentEl = $el = is_int($key) && $parentEl ? $parentEl : $key; if (is_array($value)) { $this->_arrayToXml($value, $this->_isAssocArray($value) ? $xml->addChild($el) : $xml, $el); - } else { + } elseif(!isset($xml->{$el})) { $xml->{$el} = (string) $value; + } else { + $xml->{$el}[] = (string) $value; } } From 561190e38da5f4937b674ba05912b73615f8d079 Mon Sep 17 00:00:00 2001 From: Alexandr Bashurov Date: Mon, 28 Mar 2022 23:57:08 +0700 Subject: [PATCH 3/3] BUGFIX EXTREST-143 Fix incorrect line formatting --- src/Api/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/Client.php b/src/Api/Client.php index fb2e4a94..ee5f7e51 100644 --- a/src/Api/Client.php +++ b/src/Api/Client.php @@ -349,7 +349,7 @@ protected function _arrayToXml(array $array, SimpleXMLElement $xml, $parentEl = $el = is_int($key) && $parentEl ? $parentEl : $key; if (is_array($value)) { $this->_arrayToXml($value, $this->_isAssocArray($value) ? $xml->addChild($el) : $xml, $el); - } elseif(!isset($xml->{$el})) { + } elseif (!isset($xml->{$el})) { $xml->{$el} = (string) $value; } else { $xml->{$el}[] = (string) $value;