mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
improve Nexus boot
This commit is contained in:
@@ -134,8 +134,6 @@ class Test extends Command
|
|||||||
// $key = "dddd1";
|
// $key = "dddd1";
|
||||||
// $model = \App\Models\TorrentSecret::query()->where('id', 1)->first();
|
// $model = \App\Models\TorrentSecret::query()->where('id', 1)->first();
|
||||||
// \Nexus\Database\NexusDB::cache_put($key, $model);
|
// \Nexus\Database\NexusDB::cache_put($key, $model);
|
||||||
$value = NexusDB::cache_get("tracker_report_authkey_secret:1:10002");
|
|
||||||
dd($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ class Peer extends NexusModel
|
|||||||
} else {
|
} else {
|
||||||
$this->connectable = self::CONNECTABLE_NO;
|
$this->connectable = self::CONNECTABLE_NO;
|
||||||
}
|
}
|
||||||
Cache::put($cacheKey, $this->connectable, 600);
|
Cache::put($cacheKey, $this->connectable, 3600);
|
||||||
$log .= ", do check, connectable: " . $this->connectable;
|
$log .= ", do check, connectable: " . $this->connectable;
|
||||||
} else {
|
} else {
|
||||||
$log .= ", don't do check";
|
$log .= ", don't do check";
|
||||||
|
|||||||
@@ -826,19 +826,22 @@ class TrackerRepository extends BaseRepository
|
|||||||
|
|
||||||
private function checkScrapeFields(Request $request): array
|
private function checkScrapeFields(Request $request): array
|
||||||
{
|
{
|
||||||
preg_match_all('/info_hash=([^&]*)/i', urldecode($request->getQueryString()), $info_hash_match);
|
preg_match_all('/info_hash=([^&]*)/i', $request->getQueryString(), $info_hash_match);
|
||||||
|
|
||||||
$info_hash_array = $info_hash_match[1];
|
$info_hash_array = $info_hash_match[1];
|
||||||
|
$info_hash_original = [];
|
||||||
if (count($info_hash_array) < 1) {
|
if (count($info_hash_array) < 1) {
|
||||||
throw new TrackerException("key: info_hash is Missing !");
|
throw new TrackerException("key: info_hash is Missing !");
|
||||||
} else {
|
} else {
|
||||||
foreach ($info_hash_array as $item) {
|
foreach ($info_hash_array as $item) {
|
||||||
|
$item = urldecode($item);
|
||||||
if (($length = strlen($item)) != 20) {
|
if (($length = strlen($item)) != 20) {
|
||||||
throw new TrackerException("Invalid info_hash ! info_hash is not 20 bytes long($length)");
|
throw new TrackerException("Invalid info_hash ! info_hash is not 20 bytes long($length)");
|
||||||
}
|
}
|
||||||
|
$info_hash_original[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $info_hash_array;
|
return $info_hash_original;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+28
-43
@@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Nexus;
|
namespace Nexus;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
final class Nexus
|
final class Nexus
|
||||||
{
|
{
|
||||||
private string $requestId;
|
private string $requestId;
|
||||||
@@ -96,8 +99,8 @@ final class Nexus
|
|||||||
{
|
{
|
||||||
$schema = $this->retrieveFromServer(['HTTP_X_FORWARDED_PROTO', 'REQUEST_SCHEME', 'HTTP_SCHEME']);
|
$schema = $this->retrieveFromServer(['HTTP_X_FORWARDED_PROTO', 'REQUEST_SCHEME', 'HTTP_SCHEME']);
|
||||||
if (empty($schema)) {
|
if (empty($schema)) {
|
||||||
$tmp = $this->retrieveFromServer(['HTTPS']);
|
$https = $this->retrieveFromServer(['HTTPS']);
|
||||||
if ($tmp == 'on') {
|
if ($https == 'on') {
|
||||||
$schema = 'https';
|
$schema = 'https';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,24 +109,31 @@ final class Nexus
|
|||||||
|
|
||||||
public function getRequestIp()
|
public function getRequestIp()
|
||||||
{
|
{
|
||||||
$ip = $this->retrieveFromServer(['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_REMOTE_ADDR']);
|
return $this->retrieveFromServer(['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_REMOTE_ADDR', 'REMOTE_ADDR']);
|
||||||
if (empty($ip)) {
|
|
||||||
$ip = request()->getClientIp();
|
|
||||||
}
|
|
||||||
return $ip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function retrieveFromServer(array $fields)
|
private function retrieveFromServer(array $fields, bool $includeHeader = false)
|
||||||
{
|
{
|
||||||
if ($this->runningInOctane()) {
|
if ($this->runningInOctane()) {
|
||||||
$servers = request()->server();
|
$servers = request()->server();
|
||||||
|
$headers = request()->header();
|
||||||
} else {
|
} else {
|
||||||
$servers = $_SERVER;
|
$servers = $_SERVER;
|
||||||
|
$headers = getallheaders();
|
||||||
}
|
}
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
if (!empty($servers[$field])) {
|
$result = $servers[$field] ?? null;
|
||||||
do_log("got from $field");
|
if ($result !== null && $result !== '') {
|
||||||
return $servers[$field];
|
return $result;
|
||||||
|
}
|
||||||
|
if ($includeHeader) {
|
||||||
|
$result = $headers[$field] ?? null;
|
||||||
|
if (is_array($result)) {
|
||||||
|
$result = Arr::first($result);
|
||||||
|
}
|
||||||
|
if ($result !== null && $result !== '') {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,39 +179,20 @@ final class Nexus
|
|||||||
|
|
||||||
private function setRequestId()
|
private function setRequestId()
|
||||||
{
|
{
|
||||||
$requestId = '';
|
$requestId = $this->retrieveFromServer(['HTTP_X_REQUEST_ID', 'REQUEST_ID', 'Request-Id', 'request-id'], true);
|
||||||
$names = ['HTTP_X_REQUEST_ID', 'REQUEST_ID', 'Request-Id', 'request-id'];
|
|
||||||
if ($this->runningInOctane()) {
|
|
||||||
$request = request();
|
|
||||||
foreach ($names as $name) {
|
|
||||||
$requestId = $request->server($name, $request->header($name));
|
|
||||||
if (!empty($requestId)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($names as $name) {
|
|
||||||
$requestId = $_SERVER[$name] ?? '';
|
|
||||||
if (!empty($requestId)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($requestId)) {
|
if (empty($requestId)) {
|
||||||
$requestId = $this->generateRequestId();
|
$requestId = $this->generateRequestId();
|
||||||
}
|
}
|
||||||
$this->requestId = $requestId;
|
$this->requestId = (string)$requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setScript()
|
private function setScript()
|
||||||
{
|
{
|
||||||
if ($this->runningInOctane()) {
|
$script = $this->retrieveFromServer(['SCRIPT_FILENAME', 'SCRIPT_NAME', 'Script', 'script'], true);
|
||||||
$request = request();
|
if (str_contains($script, '.')) {
|
||||||
$script = $request->header('script_filename', '');
|
$script = strstr(basename($script), '.', true);
|
||||||
} else {
|
|
||||||
$script = strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true);
|
|
||||||
}
|
}
|
||||||
$this->script = $script;
|
$this->script = (string)$script;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setStartTimestamp()
|
private function setStartTimestamp()
|
||||||
@@ -211,13 +202,7 @@ final class Nexus
|
|||||||
|
|
||||||
private function setPlatform()
|
private function setPlatform()
|
||||||
{
|
{
|
||||||
if ($this->runningInOctane()) {
|
$this->platform = (string)$this->retrieveFromServer(['HTTP_PLATFORM', 'Platform', 'platform'], true);
|
||||||
$request = request();
|
|
||||||
$platform = $request->header('platform', '');
|
|
||||||
} else {
|
|
||||||
$platform = $_SERVER['HTTP_PLATFORM'] ?? '';
|
|
||||||
}
|
|
||||||
$this->platform = $platform;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function js(string $js, string $position, bool $isFile)
|
public static function js(string $js, string $position, bool $isFile)
|
||||||
|
|||||||
Reference in New Issue
Block a user