Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2018-03-16 14:10:29 +00:00 committed by StyleCI Bot
parent d45d2d887e
commit c6a0a04731
5 changed files with 55 additions and 56 deletions

View File

@ -2,7 +2,6 @@
class HTTPProxy implements \danog\MadelineProto\Proxy class HTTPProxy implements \danog\MadelineProto\Proxy
{ {
private $sock; private $sock;
private $protocol; private $protocol;
private $timeout = ['sec' => 0, 'usec' => 0]; private $timeout = ['sec' => 0, 'usec' => 0];
@ -29,7 +28,7 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
{ {
if ($this->sock !== null) { if ($this->sock !== null) {
fclose($this->sock); fclose($this->sock);
$this->sock = NULL; $this->sock = null;
} }
} }
@ -64,13 +63,13 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
if (isset($this->options['host']) && isset($this->options['port']) && if (isset($this->options['host']) && isset($this->options['port']) &&
true === $this->use_connect) { true === $this->use_connect) {
if ($this->domain === AF_INET6 && strpos($address, ':') !== false) { if ($this->domain === AF_INET6 && strpos($address, ':') !== false) {
$address = '[' . $address . ']'; $address = '['.$address.']';
} }
fwrite($this->sock, "CONNECT " . $address . ":" . $port . " HTTP/1.1\r\n" . fwrite($this->sock, 'CONNECT '.$address.':'.$port." HTTP/1.1\r\n".
"Accept: */*\r\n" . "Accept: */*\r\n".
"Host: " . $address . ":" . $port . "\r\n" . 'Host: '.$address.':'.$port."\r\n".
$this->getProxyAuthHeader() . $this->getProxyAuthHeader().
"connection: keep-Alive\r\n" . "connection: keep-Alive\r\n".
"\r\n"); "\r\n");
$response = ''; $response = '';
@ -79,39 +78,43 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
$status = $status || (strpos($line, 'HTTP') !== false); $status = $status || (strpos($line, 'HTTP') !== false);
if ($status) { if ($status) {
$response .= $line; $response .= $line;
if (!chop($line)) if (!rtrim($line)) {
break; break;
}
} }
} }
if (substr($response, 0, 13) !== "HTTP/1.1 200 ") if (substr($response, 0, 13) !== 'HTTP/1.1 200 ') {
return false; return false;
}
} }
if (true === $this->use_ssl) { if (true === $this->use_ssl) {
$modes = array( $modes = [
STREAM_CRYPTO_METHOD_TLS_CLIENT, STREAM_CRYPTO_METHOD_TLS_CLIENT,
STREAM_CRYPTO_METHOD_SSLv3_CLIENT, STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
STREAM_CRYPTO_METHOD_SSLv23_CLIENT, STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
STREAM_CRYPTO_METHOD_SSLv2_CLIENT STREAM_CRYPTO_METHOD_SSLv2_CLIENT,
); ];
$contextOptions = array( $contextOptions = [
'ssl' => array( 'ssl' => [
'verify_peer' => false, 'verify_peer' => false,
'verify_peer_name' => false, 'verify_peer_name' => false,
), ],
); ];
stream_context_set_option($this->sock, $contextOptions); stream_context_set_option($this->sock, $contextOptions);
$success = false; $success = false;
foreach ($modes as $mode) foreach ($modes as $mode) {
{
$success = stream_socket_enable_crypto($this->sock, true, $mode); $success = stream_socket_enable_crypto($this->sock, true, $mode);
if ($success) if ($success) {
return true; return true;
}
} }
return false; return false;
} }
return true; return true;
} }
@ -162,6 +165,7 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
return true; return true;
} }
throw new \danog\MadelineProto\Exception('Not supported'); throw new \danog\MadelineProto\Exception('Not supported');
} }
@ -175,7 +179,8 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
if (!isset($this->options['user']) || !isset($this->options['pass'])) { if (!isset($this->options['user']) || !isset($this->options['pass'])) {
return ''; return '';
} }
return "Proxy-Authorization: Basic " . base64_encode($this->options['user'] . ":" . $this->options['pass']) . "\r\n";
return 'Proxy-Authorization: Basic '.base64_encode($this->options['user'].':'.$this->options['pass'])."\r\n";
} }
public function getProxyHeaders() public function getProxyHeaders()
@ -187,5 +192,4 @@ class HTTPProxy implements \danog\MadelineProto\Proxy
{ {
$this->options = $extra; $this->options = $extra;
} }
} }

View File

@ -116,13 +116,12 @@ If not, see <http://www.gnu.org/licenses/>.
{ {
throw new \danog\MadelineProto\Exception('Not supported'); throw new \danog\MadelineProto\Exception('Not supported');
} }
public function setExtra(array $extra = []) public function setExtra(array $extra = [])
{ {
} }
public function getProxyHeaders() public function getProxyHeaders()
{ {
return ''; return '';
} }
@ -236,7 +235,7 @@ if (!extension_loaded('pthreads')) {
return $port ? ['host' => $address, 'port' => $port] : ['host' => $address]; return $port ? ['host' => $address, 'port' => $port] : ['host' => $address];
} }
public function getProxyHeaders() public function getProxyHeaders()
{ {
return ''; return '';
} }

View File

@ -152,12 +152,12 @@ class Connection
$proxy = '\\FSocket'; $proxy = '\\FSocket';
} }
$this->sock = new $proxy($ipv6 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, strpos($this->protocol, 'https') === 0 ? PHP_INT_MAX : ($has_proxy ? PHP_INT_MAX - 1 : getprotobyname('tcp'))); $this->sock = new $proxy($ipv6 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, strpos($this->protocol, 'https') === 0 ? PHP_INT_MAX : ($has_proxy ? PHP_INT_MAX - 1 : getprotobyname('tcp')));
if ($has_proxy ) { if ($has_proxy) {
if ($this->extra !== []) { if ($this->extra !== []) {
$this->sock->setExtra($this->extra); $this->sock->setExtra($this->extra);
} }
if ($this->protocol === 'http') { if ($this->protocol === 'http') {
$this->parsed['path'] = $this->parsed['scheme'] . '://' . $this->parsed['host'] . $this->parsed['path'] = $this->parsed['scheme'].'://'.$this->parsed['host'].
$this->parsed['path']; $this->parsed['path'];
$port = 80; $port = 80;
} elseif ($this->protocol === 'https') { } elseif ($this->protocol === 'https') {
@ -361,7 +361,7 @@ class Connection
break; break;
case 'http': case 'http':
case 'https': case 'https':
$this->write('POST '.$this->parsed['path']." HTTP/1.1\r\nHost: ".$this->parsed['host'].':'.$this->port."\r\n" . $this->sock->getProxyHeaders() . "Content-Type: application/x-www-form-urlencoded\r\nConnection: keep-alive\r\nKeep-Alive: timeout=100000, max=10000000\r\nContent-Length: ".strlen($message)."\r\n\r\n".$message); $this->write('POST '.$this->parsed['path']." HTTP/1.1\r\nHost: ".$this->parsed['host'].':'.$this->port."\r\n".$this->sock->getProxyHeaders()."Content-Type: application/x-www-form-urlencoded\r\nConnection: keep-alive\r\nKeep-Alive: timeout=100000, max=10000000\r\nContent-Length: ".strlen($message)."\r\n\r\n".$message);
break; break;
case 'udp': case 'udp':
throw new Exception(\danog\MadelineProto\Lang::$current_lang['protocol_not_implemented']); throw new Exception(\danog\MadelineProto\Lang::$current_lang['protocol_not_implemented']);

View File

@ -44,7 +44,7 @@ interface Proxy
public function getPeerName($port = true); public function getPeerName($port = true);
public function getSockName($port = true); public function getSockName($port = true);
public function getProxyHeaders(); public function getProxyHeaders();
public function setExtra(array $extra = []); public function setExtra(array $extra = []);

View File

@ -34,42 +34,38 @@ if (file_exists('web_data.php')) {
require_once 'web_data.php'; require_once 'web_data.php';
} }
/** /**
* Set default context proxy for file_get_contents * Set default context proxy for file_get_contents.
*
*/ */
$default_opts = [
$default_opts = array( 'http' => [
'http' => array( 'proxy' => 'tcp://host:port',
'proxy' => "tcp://host:port",
'request_fulluri' => true, 'request_fulluri' => true,
/* Only if your proxy requires authentication */ /* Only if your proxy requires authentication */
'header' => array( 'header' => [
"Proxy-Authorization: Basic " . base64_encode("proxy_user:proxy_pass") 'Proxy-Authorization: Basic '.base64_encode('proxy_user:proxy_pass'),
) ],
), ],
'https' => array( 'https' => [
'proxy' => "tcp://host:port", 'proxy' => 'tcp://host:port',
'request_fulluri' => true, 'request_fulluri' => true,
/* Only if your proxy requires authentication */ /* Only if your proxy requires authentication */
'header' => array( 'header' => [
"Proxy-Authorization: Basic " . base64_encode("proxy_user:proxy_pass") 'Proxy-Authorization: Basic '.base64_encode('proxy_user:proxy_pass'),
) ],
), ],
'tls' => array( 'tls' => [
'proxy' => "tcp://host:port", 'proxy' => 'tcp://host:port',
'request_fulluri' => true, 'request_fulluri' => true,
/* Only if your proxy requires authentication */ /* Only if your proxy requires authentication */
'header' => array( 'header' => [
"Proxy-Authorization: Basic " . base64_encode("proxy_user:proxy_pass") 'Proxy-Authorization: Basic '.base64_encode('proxy_user:proxy_pass'),
) ],
) ],
); ];
$default = stream_context_set_default($default_opts); $default = stream_context_set_default($default_opts);
echo 'Deserializing MadelineProto from testing.madeline...'.PHP_EOL; echo 'Deserializing MadelineProto from testing.madeline...'.PHP_EOL;
$MadelineProto = false; $MadelineProto = false;