Compare commits

...

3 Commits

4 changed files with 32 additions and 15 deletions

View File

@@ -16,13 +16,13 @@ use Domframework\Tcpclient;
*/ */
class TcpclientTest extends \PHPUnit_Framework_TestCase class TcpclientTest extends \PHPUnit_Framework_TestCase
{ {
public function testGoogleIPv4() public function testFournier38IPv4()
{ {
$tcpclient = new Tcpclient("www.google.fr", 80); $tcpclient = new Tcpclient("ipv4.fournier38.fr", 80);
$tcpclient->preferIPv4(true); $tcpclient->preferIPv4(true);
$tcpclient->connect(); $tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" . $tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" . "Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" . "User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" . "Accept: *" . "/*\r\n" .
"\r\n"); "\r\n");
@@ -34,12 +34,12 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK"); $this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
} }
public function testGoogleIPv4orIpv6() public function testFournier38IPv4orIpv6()
{ {
$tcpclient = new Tcpclient("www.google.fr", 80); $tcpclient = new Tcpclient("ip.fournier38.fr", 80);
$tcpclient->connect(); $tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" . $tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" . "Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" . "User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" . "Accept: *" . "/*\r\n" .
"\r\n"); "\r\n");
@@ -51,13 +51,13 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK"); $this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
} }
public function testGoogleSSL() public function testFournier38SSL()
{ {
$tcpclient = new Tcpclient("www.google.fr", 443); $tcpclient = new Tcpclient("ip.fournier38.fr", 443);
$tcpclient->connect(); $tcpclient->connect();
$tcpclient->cryptoEnable(true); $tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" . $tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" . "Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" . "User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" . "Accept: *" . "/*\r\n" .
"\r\n"); "\r\n");
@@ -69,13 +69,13 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK"); $this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
} }
public function testGoogleSSLIPv6() public function testFournier38SSLIPv6()
{ {
$tcpclient = new Tcpclient("ipv6.google.com", 443); $tcpclient = new Tcpclient("ipv6.fournier38.fr", 443);
$tcpclient->connect(); $tcpclient->connect();
$tcpclient->cryptoEnable(true); $tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" . $tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" . "Host: ipv6.fournier38.f\r\n" .
"User-Agent: DomFramework\r\n" . "User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" . "Accept: *" . "/*\r\n" .
"\r\n"); "\r\n");

View File

@@ -106,6 +106,7 @@ class Smtp
if ($errstr === "" && $php_errormsg !== "") { if ($errstr === "" && $php_errormsg !== "") {
$errstr = $php_errormsg; $errstr = $php_errormsg;
} }
$this->smtpStream = null;
throw new \Exception(sprintf(dgettext( throw new \Exception(sprintf(dgettext(
"domframework", "domframework",
"Can't connect to SMTP server : %s" "Can't connect to SMTP server : %s"
@@ -123,7 +124,11 @@ class Smtp
$this->putLine("STARTTLS\r\n"); $this->putLine("STARTTLS\r\n");
$context["ssl"]["verify_peer_name"] = $this->starttlsCheck; $context["ssl"]["verify_peer_name"] = $this->starttlsCheck;
$context["ssl"]["verify_peer"] = $this->starttlsCheck; $context["ssl"]["verify_peer"] = $this->starttlsCheck;
if (version_compare(PHP_VERSION, '8.3.0') <= 0) {
stream_context_set_option($this->smtpStream, $context); stream_context_set_option($this->smtpStream, $context);
} else {
stream_context_set_options($this->smtpStream, $context);
}
// The track_errors permit to create the $php_errormsg in case of // The track_errors permit to create the $php_errormsg in case of
// warning // warning
ini_set('track_errors', 1); ini_set('track_errors', 1);
@@ -135,6 +140,7 @@ class Smtp
) === ) ===
false false
) { ) {
$this->smtpStream = null;
throw new \Exception(sprintf(dgettext( throw new \Exception(sprintf(dgettext(
"domframework", "domframework",
"Can't activate STARTTLS %s" "Can't activate STARTTLS %s"
@@ -144,6 +150,7 @@ class Smtp
$this->debug("STARTTLS ACTIVATED\n"); $this->debug("STARTTLS ACTIVATED\n");
} }
} elseif ($this->starttls === "encrypt") { } elseif ($this->starttls === "encrypt") {
$this->smtpStream = null;
throw new \Exception(dgettext( throw new \Exception(dgettext(
"domframework", "domframework",
"Server doesn't supports STARTTLS" "Server doesn't supports STARTTLS"
@@ -166,6 +173,7 @@ class Smtp
$this->putLine("AUTH LOGIN " . base64_encode($this->user) . "\r\n"); $this->putLine("AUTH LOGIN " . base64_encode($this->user) . "\r\n");
$this->putLine(base64_encode($this->password) . "\r\n"); $this->putLine(base64_encode($this->password) . "\r\n");
} else { } else {
$this->smtpStream = null;
throw new \Exception( throw new \Exception(
dgettext( dgettext(
"domframework", "domframework",

View File

@@ -246,9 +246,14 @@ class Tcpclient
"capture_peer_cert_chain" => true, "capture_peer_cert_chain" => true,
"SNI_enabled" => true, "SNI_enabled" => true,
]]; ]];
$optionsMerged = [];
$optionsMerged["ssl"] = array_merge($optionsBase["ssl"], $options); $optionsMerged["ssl"] = array_merge($optionsBase["ssl"], $options);
stream_set_blocking($this->socket, true); stream_set_blocking($this->socket, true);
if (version_compare(PHP_VERSION, '8.3.0') <= 0) {
stream_context_set_option($this->socket, $optionsMerged); stream_context_set_option($this->socket, $optionsMerged);
} else {
stream_context_set_options($this->socket, $optionsMerged);
}
$php_errormsg = ""; $php_errormsg = "";
ini_set("track_errors", 1); ini_set("track_errors", 1);
$rc = @stream_socket_enable_crypto($this->socket, !!$val, $cryptoMethod); $rc = @stream_socket_enable_crypto($this->socket, !!$val, $cryptoMethod);

View File

@@ -496,7 +496,11 @@ class Tcpserver
"verify_peer_name" => false, "verify_peer_name" => false,
]]; ]];
stream_set_blocking($this->socket, true); stream_set_blocking($this->socket, true);
if (version_compare(PHP_VERSION, '8.3.0') <= 0) {
stream_context_set_option($this->socket, $options); stream_context_set_option($this->socket, $options);
} else {
stream_context_set_options($this->socket, $options);
}
return @stream_socket_enable_crypto($this->socket, !!$val, $cryptoMethod); return @stream_socket_enable_crypto($this->socket, !!$val, $cryptoMethod);
} }