fix get host from octane

This commit is contained in:
xiaomlove
2022-04-07 19:08:02 +08:00
parent ebe47b1ba3
commit e12c94e651
3 changed files with 16 additions and 12 deletions
+1 -1
View File
@@ -722,7 +722,7 @@ class TrackerRepository extends BaseRepository
$peer->prev_action = $peer->last_action;
}
if ($queries['event'] == 'started') {
if ($queries['event'] == 'started' || !$peer->exists) {
$peer->started = $nowStr;
$peer->uploadoffset = $queries['uploaded'];
$peer->downloadoffset = $queries['downloaded'];
+8 -10
View File
@@ -458,14 +458,8 @@ function getSchemeAndHttpHost()
}
$isHttps = isHttps();
$protocol = $isHttps ? 'https' : 'http';
if (RUNNING_IN_OCTANE) {
$host = request()->server('HTTP_HOST', '');
} else {
$host = $_SERVER['HTTP_HOST'] ?? '';
}
$result = "$protocol://" . $host;
return $result;
$host = nexus()->getRequestHost();
return "$protocol://" . $host;
}
function getBaseUrl()
@@ -634,8 +628,12 @@ function get_tracker_schema_and_host($combine = false): array|string
global $https_announce_urls, $announce_urls;
$httpsAnnounceUrls = array_filter($https_announce_urls);
$log = "cookie: " . json_encode($_COOKIE) . ", https_announce_urls: " . json_encode($httpsAnnounceUrls);
if ((isset($_COOKIE["c_secure_tracker_ssl"]) && $_COOKIE["c_secure_tracker_ssl"] == base64("yeah")) || !empty($httpsAnnounceUrls)) {
$log .= ", c_secure_tracker_ssl = base64('yeah'): " . base64("yeah") . ", or not empty https_announce_urls";
if (
(isset($_COOKIE["c_secure_tracker_ssl"]) && $_COOKIE["c_secure_tracker_ssl"] == base64("yeah"))
|| !empty($httpsAnnounceUrls)
|| isHttps()
) {
$log .= ", c_secure_tracker_ssl = base64('yeah'): " . base64("yeah") . ", or not empty https_announce_urls, or isHttps()";
$tracker_ssl = true;
} else {
$tracker_ssl = false;
+7 -1
View File
@@ -107,9 +107,15 @@ final class Nexus
return $schema;
}
public function getRequestHost(): string
{
$host = $this->retrieveFromServer(['HTTP_HOST', 'host', ], true);
return (string)$host;
}
public function getRequestIp()
{
return $this->retrieveFromServer(['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_REMOTE_ADDR', 'REMOTE_ADDR']);
return $this->retrieveFromServer(['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'x-forwarded-for', 'HTTP_REMOTE_ADDR', 'REMOTE_ADDR'], true);
}
private function retrieveFromServer(array $fields, bool $includeHeader = false)