|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Tembo EPP client library |
| 3 | + * Namingo EPP client library |
4 | 4 | * |
5 | | - * Written in 2023 by Taras Kondratyuk (https://getpinga.com) |
| 5 | + * Written in 2023-2024 by Taras Kondratyuk (https://namingo.org) |
6 | 6 | * Based on xpanel/epp-bundle written in 2019 by Lilian Rudenco ([email protected]) |
7 | 7 | * |
8 | 8 | * @license MIT |
@@ -124,9 +124,18 @@ public function writeRequest($xml) |
124 | 124 | if (fwrite($this->resource, pack('N', (strlen($xml) + 4)) . $xml) === false) { |
125 | 125 | throw new EppException('Error writing to the connection.'); |
126 | 126 | } |
127 | | - $r = simplexml_load_string($this->readResponse()); |
128 | | - if (isset($r->response) && $r->response->result->attributes()->code >= 2000) { |
129 | | - throw new EppException($r->response->result->msg); |
| 127 | + $responseXml = $this->readResponse(); |
| 128 | + // Try to load the XML without namespace first |
| 129 | + $r = simplexml_load_string($responseXml); |
| 130 | + if ($r === false || !isset($r->response)) { |
| 131 | + // If loading without namespace fails, try loading with the epp namespace |
| 132 | + $r = simplexml_load_string($responseXml, null, 0, 'epp', true); |
| 133 | + } |
| 134 | + if ($r === false) { |
| 135 | + throw new EppException('Error parsing the XML response.'); |
| 136 | + } |
| 137 | + if (isset($r->response->result) && (int)$r->response->result->attributes()->code >= 2000) { |
| 138 | + throw new EppException((string)$r->response->result->msg); |
130 | 139 | } |
131 | 140 | return $r; |
132 | 141 | } |
@@ -188,10 +197,10 @@ public function login($params = array()) |
188 | 197 | $from[] = '/{{ clID }}/'; |
189 | 198 | $to[] = htmlspecialchars($params['clID']); |
190 | 199 | $from[] = '/{{ pwd }}/'; |
191 | | - $to[] = htmlspecialchars($params['pw']); |
| 200 | + $to[] = '<![CDATA[' . $params['pw'] . ']]>'; |
192 | 201 | if (isset($params['newpw']) && !empty($params['newpw'])) { |
193 | 202 | $from[] = '/{{ newpw }}/'; |
194 | | - $to[] = PHP_EOL . ' <newPW>' . htmlspecialchars($params['newpw']) . '</newPW>'; |
| 203 | + $to[] = PHP_EOL . ' <newPW><![CDATA[' . $params['newpw'] . ']]></newPW>'; |
195 | 204 | } else { |
196 | 205 | $from[] = '/{{ newpw }}/'; |
197 | 206 | $to[] = ''; |
@@ -2703,6 +2712,38 @@ public function pollAck($params = array()) |
2703 | 2712 | return $return; |
2704 | 2713 | } |
2705 | 2714 |
|
| 2715 | + /** |
| 2716 | + * rawXml |
| 2717 | + */ |
| 2718 | + public function rawXml($params = array()) |
| 2719 | + { |
| 2720 | + if (!$this->isLoggedIn) { |
| 2721 | + return array( |
| 2722 | + 'code' => 2002, |
| 2723 | + 'msg' => 'Command use error' |
| 2724 | + ); |
| 2725 | + } |
| 2726 | + |
| 2727 | + $return = array(); |
| 2728 | + try { |
| 2729 | + $r = $this->writeRequest($params['xml']); |
| 2730 | + $code = (int)$r->response->result->attributes()->code; |
| 2731 | + $msg = (string)$r->response->result->msg; |
| 2732 | + |
| 2733 | + $return = array( |
| 2734 | + 'code' => $code, |
| 2735 | + 'msg' => $msg, |
| 2736 | + 'xml' => $r->asXML() |
| 2737 | + ); |
| 2738 | + } catch (\Exception $e) { |
| 2739 | + $return = array( |
| 2740 | + 'error' => $e->getMessage() |
| 2741 | + ); |
| 2742 | + } |
| 2743 | + |
| 2744 | + return $return; |
| 2745 | + } |
| 2746 | + |
2706 | 2747 | public function _response_log($content) |
2707 | 2748 | { |
2708 | 2749 | // Add formatted content to the log |
|
0 commit comments