Skip to content

Commit

Permalink
Revert "We'll have an additional RC for PHP 7, so ipv6_v6only will be…
Browse files Browse the repository at this point in the history
… in 7.0.0 already"

This reverts commit 9340b92.

(sigh)
  • Loading branch information
bwoebi committed Nov 10, 2015
1 parent 4c06483 commit 54efc23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
30 changes: 25 additions & 5 deletions lib/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public function expose(string $address, int $port): Host {
}

if ($address === "*") {
$this->interfaces[] = ["0.0.0.0", $port];
$this->interfaces[] = ["::", $port];
return $this;
if (self::separateIPv4Binding()) {
$this->interfaces[] = ["0.0.0.0", $port];
}

$address = "::";
}

if (!@inet_pton($address)) {
Expand Down Expand Up @@ -158,13 +160,28 @@ public function redirect(string $absoluteUri, int $redirectCode = 307): Host {

$this->redirect = function(Request $req, Response $res) use ($redirectUri, $redirectCode) {
$res->setStatus($redirectCode);
$res->setHeader("Location", $redirectUri . $req->getUri());
$res->setHeader("Location", $redirectUri . $req->uri);
$res->end();
};

return $this;
}

private static function separateIPv4Binding(): bool {
static $separateIPv6 = null;

if ($separateIPv6 === null) {
// PHP 7.0.0 doesn't have ipv6_v6only socket option yet
if (PHP_VERSION_ID < 70001) {
$separateIPv6 = !file_exists("/proc/sys/net/ipv6/bindv6only") || trim(file_get_contents("/proc/sys/net/ipv6/bindv6only"));
} else {
$separateIPv6 = true;
}
}

return $separateIPv6;
}

/**
* Retrieve an associative array summarizing the host definition
*
Expand All @@ -181,7 +198,10 @@ public function export(): array {
if (isset($this->interfaces)) {
$interfaces = array_unique($this->interfaces, SORT_REGULAR);
} else {
$interfaces = [["::", $defaultPort], ["0.0.0.0", $defaultPort]];
$interfaces = [["::", $defaultPort]];
if (self::separateIPv4Binding()) {
$interfaces[] = ["0.0.0.0", $defaultPort];
}
}

return [
Expand Down
1 change: 1 addition & 0 deletions lib/Vhost.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public function setCrypto(array $tls) {
}

if (time() > $cert['validTo_time_t']) {
date_default_timezone_set(@date_default_timezone_get());
$expiration = date('Y-m-d', $cert['validTo_time_t']);
trigger_error(
"TLS certificate `{$certBase}` for host `{$this}` expired {$expiration}; web " .
Expand Down

0 comments on commit 54efc23

Please sign in to comment.