Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Magento\Framework\HTTP\Client; class Socket implements \Magento\Framework..
Decoded Output download
<?php
namespace Magento\Framework\HTTP\Client; class Socket implements \Magento\Framework\HTTP\ClientInterface { private $_host = "localhost"; private $_port = 80; private $_sock = null; private $_headers = array(); private $_postFields = array(); private $_cookies = array(); private $_responseHeaders = array(); private $_responseBody = ''; private $_responseStatus = 0; private $_timeout = 300; private $_redirectCount = 0; public function setTimeout($value) { $this->_timeout = (int) $value; } public function __construct($host = null, $port = 80) { if ($host) { $this->connect($host, (int) $port); } } public function connect($host, $port = 80) { $this->_host = $host; $this->_port = (int) $port; } public function disconnect() { @fclose($this->_sock); } public function setHeaders($headers) { $this->_headers = $headers; } public function addHeader($name, $value) { $this->_headers[$name] = $value; } public function removeHeader($name) { unset($this->_headers[$name]); } public function setCredentials($login, $pass) { $val = base64_encode("{$login}:{$pass}"); $this->addHeader("Authorization", "Basic {$val}"); } public function addCookie($name, $value) { $this->_cookies[$name] = $value; } public function removeCookie($name) { unset($this->_cookies[$name]); } public function setCookies($cookies) { $this->_cookies = $cookies; } public function removeCookies() { $this->setCookies(array()); } public function get($uri) { $this->makeRequest("GET", $this->parseUrl($uri)); } protected function parseUrl($uri) { $parts = parse_url($uri); if (!empty($parts["user"]) && !empty($parts["pass"])) { $this->setCredentials($parts["user"], $parts["pass"]); } if (!empty($parts["port"])) { $this->_port = (int) $parts["port"]; } if (!empty($parts["host"])) { $this->_host = $parts["host"]; } else { throw new \InvalidArgumentException("Uri doesn't contain host part"); } if (!empty($parts["path"])) { $requestUri = $parts["path"]; } else { throw new \InvalidArgumentException("Uri doesn't contain path part"); } if (!empty($parts["query"])) { $requestUri .= "?" . $parts["query"]; } return $requestUri; } public function post($uri, $params) { $this->makeRequest("POST", $this->parseUrl($uri), $params); } public function getHeaders() { return $this->_responseHeaders; } public function getBody() { return $this->_responseBody; } public function getCookies() { if (empty($this->_responseHeaders["Set-Cookie"])) { return array(); } $out = array(); foreach ($this->_responseHeaders["Set-Cookie"] as $row) { $values = explode("; ", $row ?? ''); $c = count($values); if (!$c) { continue; } list($key, $val) = explode("=", $values[0]); if ($val === null) { continue; } $out[trim($key)] = trim($val); } return $out; } public function getCookiesFull() { if (empty($this->_responseHeaders["Set-Cookie"])) { return array(); } $out = array(); foreach ($this->_responseHeaders["Set-Cookie"] as $row) { $values = explode("; ", $row ?? ''); $c = count($values); if (!$c) { continue; } list($key, $val) = explode("=", $values[0]); if ($val === null) { continue; } $out[trim($key)] = array("value" => trim($val)); array_shift($values); $c--; if (!$c) { continue; } for ($i = 0; $i < $c; $i++) { list($subkey, $val) = explode("=", $values[$i]); $out[trim($key)][trim($subkey)] = $val !== null ? trim($val) : ''; } } return $out; } protected function processResponseHeaders() { $crlf = "
"; $this->_responseHeaders = array(); while (!feof($this->_sock)) { $line = fgets($this->_sock, 1024); if ($line === $crlf) { return; } $name = $value = ''; $out = explode(": ", trim($line), 2); if (count($out) == 2) { $name = $out[0]; $value = $out[1]; } if (!empty($value)) { if ($name == "Set-Cookie") { if (!isset($this->_responseHeaders[$name])) { $this->_responseHeaders[$name] = array(); } $this->_responseHeaders[$name][] = $value; } else { $this->_responseHeaders[$name] = $value; } } } } protected function processResponseBody() { $this->_responseBody = ''; while (!feof($this->_sock)) { $this->_responseBody .= @fread($this->_sock, 1024); } } protected function processResponse() { $response = ''; $responseLine = trim(fgets($this->_sock, 1024)); $line = explode(" ", $responseLine, 3); if (count($line) != 3) { return $this->doError("Invalid response line returned from server: " . $responseLine); } $this->_responseStatus = (int) $line[1]; $this->processResponseHeaders(); $this->processRedirect(); $this->processResponseBody(); } protected function processRedirect() { } public function getStatus() { return $this->_responseStatus; } protected function makeRequest($method, $uri, $params = array()) { $errno = $errstr = ''; $this->_sock = @fsockopen($this->_host, $this->_port, $errno, $errstr, $this->_timeout); if (!$this->_sock) { return $this->doError(sprintf("[errno: %d] %s", $errno, $errstr)); } $crlf = "
\xa"; $isPost = $method == "POST"; $appendHeaders = array(); $paramsStr = false; if ($isPost && $params) { $paramsStr = is_array($params) ? http_build_query($params) : $params; $appendHeaders["Content-type"] = "application/x-www-form-urlencoded"; $appendHeaders["Content-length"] = strlen($paramsStr); } $out = "{$method} {$uri} HTTP/1.1{$crlf}"; $out .= $this->headersToString($appendHeaders); $out .= $crlf; if ($paramsStr) { $out .= $paramsStr . $crlf; } fwrite($this->_sock, $out); $this->processResponse(); } public function doError($string) { throw new \Exception($string); } protected function headersToString($append = array()) { $headers = array(); $headers["Host"] = $this->_host; $headers["Connection"] = "close"; $headers = array_merge($headers, $this->_headers, $append); $str = array(); foreach ($headers as $k => $v) { $str[] = "{$k}: {$v}\xd\xa"; } return implode($str); } public function setOptions($arr) { } public function setOption($name, $value) { } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Magento\Framework\HTTP\Client; class Socket implements \Magento\Framework\HTTP\ClientInterface { private $_host = "\x6c\157\143\x61\x6c\150\157\163\164"; private $_port = 80; private $_sock = null; private $_headers = array(); private $_postFields = array(); private $_cookies = array(); private $_responseHeaders = array(); private $_responseBody = ''; private $_responseStatus = 0; private $_timeout = 300; private $_redirectCount = 0; public function setTimeout($value) { $this->_timeout = (int) $value; } public function __construct($host = null, $port = 80) { if ($host) { $this->connect($host, (int) $port); } } public function connect($host, $port = 80) { $this->_host = $host; $this->_port = (int) $port; } public function disconnect() { @fclose($this->_sock); } public function setHeaders($headers) { $this->_headers = $headers; } public function addHeader($name, $value) { $this->_headers[$name] = $value; } public function removeHeader($name) { unset($this->_headers[$name]); } public function setCredentials($login, $pass) { $val = base64_encode("{$login}\72{$pass}"); $this->addHeader("\101\165\x74\150\157\162\x69\172\141\164\x69\x6f\156", "\x42\x61\x73\151\143\40{$val}"); } public function addCookie($name, $value) { $this->_cookies[$name] = $value; } public function removeCookie($name) { unset($this->_cookies[$name]); } public function setCookies($cookies) { $this->_cookies = $cookies; } public function removeCookies() { $this->setCookies(array()); } public function get($uri) { $this->makeRequest("\107\x45\124", $this->parseUrl($uri)); } protected function parseUrl($uri) { $parts = parse_url($uri); if (!empty($parts["\x75\x73\x65\162"]) && !empty($parts["\x70\141\163\x73"])) { $this->setCredentials($parts["\165\x73\145\162"], $parts["\x70\141\x73\x73"]); } if (!empty($parts["\x70\157\162\x74"])) { $this->_port = (int) $parts["\160\157\x72\164"]; } if (!empty($parts["\150\x6f\x73\164"])) { $this->_host = $parts["\150\x6f\x73\x74"]; } else { throw new \InvalidArgumentException("\x55\x72\151\x20\144\x6f\x65\163\x6e\47\x74\40\x63\x6f\x6e\164\x61\x69\156\x20\150\x6f\163\x74\40\160\141\162\164"); } if (!empty($parts["\160\x61\x74\x68"])) { $requestUri = $parts["\160\x61\164\x68"]; } else { throw new \InvalidArgumentException("\125\162\151\x20\x64\x6f\x65\163\156\47\x74\x20\143\x6f\x6e\x74\141\151\156\40\160\x61\x74\x68\x20\x70\141\x72\x74"); } if (!empty($parts["\x71\165\145\x72\171"])) { $requestUri .= "\77" . $parts["\x71\165\x65\162\x79"]; } return $requestUri; } public function post($uri, $params) { $this->makeRequest("\x50\117\x53\124", $this->parseUrl($uri), $params); } public function getHeaders() { return $this->_responseHeaders; } public function getBody() { return $this->_responseBody; } public function getCookies() { if (empty($this->_responseHeaders["\x53\x65\164\55\x43\157\x6f\x6b\151\x65"])) { return array(); } $out = array(); foreach ($this->_responseHeaders["\x53\145\x74\55\103\157\157\153\x69\145"] as $row) { $values = explode("\x3b\40", $row ?? ''); $c = count($values); if (!$c) { continue; } list($key, $val) = explode("\75", $values[0]); if ($val === null) { continue; } $out[trim($key)] = trim($val); } return $out; } public function getCookiesFull() { if (empty($this->_responseHeaders["\123\145\164\55\103\x6f\157\153\x69\145"])) { return array(); } $out = array(); foreach ($this->_responseHeaders["\x53\x65\164\55\x43\x6f\157\x6b\x69\145"] as $row) { $values = explode("\73\40", $row ?? ''); $c = count($values); if (!$c) { continue; } list($key, $val) = explode("\75", $values[0]); if ($val === null) { continue; } $out[trim($key)] = array("\x76\141\154\x75\x65" => trim($val)); array_shift($values); $c--; if (!$c) { continue; } for ($i = 0; $i < $c; $i++) { list($subkey, $val) = explode("\75", $values[$i]); $out[trim($key)][trim($subkey)] = $val !== null ? trim($val) : ''; } } return $out; } protected function processResponseHeaders() { $crlf = "\15\12"; $this->_responseHeaders = array(); while (!feof($this->_sock)) { $line = fgets($this->_sock, 1024); if ($line === $crlf) { return; } $name = $value = ''; $out = explode("\72\x20", trim($line), 2); if (count($out) == 2) { $name = $out[0]; $value = $out[1]; } if (!empty($value)) { if ($name == "\123\x65\x74\x2d\103\157\157\153\151\x65") { if (!isset($this->_responseHeaders[$name])) { $this->_responseHeaders[$name] = array(); } $this->_responseHeaders[$name][] = $value; } else { $this->_responseHeaders[$name] = $value; } } } } protected function processResponseBody() { $this->_responseBody = ''; while (!feof($this->_sock)) { $this->_responseBody .= @fread($this->_sock, 1024); } } protected function processResponse() { $response = ''; $responseLine = trim(fgets($this->_sock, 1024)); $line = explode("\x20", $responseLine, 3); if (count($line) != 3) { return $this->doError("\x49\x6e\166\x61\x6c\151\144\x20\162\145\163\x70\157\x6e\x73\145\x20\154\151\x6e\x65\x20\x72\x65\x74\x75\x72\x6e\x65\x64\x20\146\x72\x6f\x6d\40\163\x65\x72\x76\x65\162\72\40" . $responseLine); } $this->_responseStatus = (int) $line[1]; $this->processResponseHeaders(); $this->processRedirect(); $this->processResponseBody(); } protected function processRedirect() { } public function getStatus() { return $this->_responseStatus; } protected function makeRequest($method, $uri, $params = array()) { $errno = $errstr = ''; $this->_sock = @fsockopen($this->_host, $this->_port, $errno, $errstr, $this->_timeout); if (!$this->_sock) { return $this->doError(sprintf("\x5b\145\x72\162\156\157\72\x20\x25\x64\x5d\x20\x25\x73", $errno, $errstr)); } $crlf = "\15\xa"; $isPost = $method == "\x50\x4f\123\124"; $appendHeaders = array(); $paramsStr = false; if ($isPost && $params) { $paramsStr = is_array($params) ? http_build_query($params) : $params; $appendHeaders["\x43\x6f\x6e\164\145\156\x74\x2d\164\x79\160\145"] = "\141\160\x70\x6c\x69\x63\x61\x74\151\x6f\x6e\57\x78\55\x77\167\167\x2d\x66\x6f\162\x6d\x2d\x75\162\x6c\145\x6e\143\x6f\144\145\x64"; $appendHeaders["\x43\x6f\x6e\164\x65\156\x74\x2d\x6c\145\x6e\147\x74\x68"] = strlen($paramsStr); } $out = "{$method}\40{$uri}\40\x48\124\124\x50\57\x31\56\x31{$crlf}"; $out .= $this->headersToString($appendHeaders); $out .= $crlf; if ($paramsStr) { $out .= $paramsStr . $crlf; } fwrite($this->_sock, $out); $this->processResponse(); } public function doError($string) { throw new \Exception($string); } protected function headersToString($append = array()) { $headers = array(); $headers["\x48\157\x73\164"] = $this->_host; $headers["\103\157\x6e\x6e\x65\x63\164\151\x6f\156"] = "\143\154\x6f\163\145"; $headers = array_merge($headers, $this->_headers, $append); $str = array(); foreach ($headers as $k => $v) { $str[] = "{$k}\72\40{$v}\xd\xa"; } return implode($str); } public function setOptions($arr) { } public function setOption($name, $value) { } }
Function Calls
| None |
Stats
| MD5 | ddce08c2abce5143bbf9edf8d76de0a0 |
| Eval Count | 0 |
| Decode Time | 101 ms |