mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-25 04:27:22 +08:00
finish support with otane
This commit is contained in:
@@ -41,7 +41,7 @@ class AttendanceMigrate extends Command
|
|||||||
{
|
{
|
||||||
$rep = new AttendanceRepository();
|
$rep = new AttendanceRepository();
|
||||||
$result = $rep->migrateAttendance();
|
$result = $rep->migrateAttendance();
|
||||||
$log = sprintf('[%s], %s, result: %s, query: %s', REQUEST_ID, __METHOD__, var_export($result, true), last_query());
|
$log = sprintf('[%s], %s, result: %s, query: %s', nexus() ? nexus()->getRequestId() : 'NO_REQUEST_ID', __METHOD__, var_export($result, true), last_query());
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class BackuAll extends Command
|
|||||||
$result = $rep->backupAll();
|
$result = $rep->backupAll();
|
||||||
$log = sprintf(
|
$log = sprintf(
|
||||||
'[%s], %s, result: %s',
|
'[%s], %s, result: %s',
|
||||||
REQUEST_ID, __METHOD__, var_export($result, true)
|
nexus()->getRequestId(), __METHOD__, var_export($result, true)
|
||||||
);
|
);
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class BackupCronjob extends Command
|
|||||||
$result = $rep->cronjobBackup();
|
$result = $rep->cronjobBackup();
|
||||||
$log = sprintf(
|
$log = sprintf(
|
||||||
'[%s], %s, result: %s',
|
'[%s], %s, result: %s',
|
||||||
REQUEST_ID, __METHOD__, var_export($result, true)
|
nexus()->getRequestId(), __METHOD__, var_export($result, true)
|
||||||
);
|
);
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class BackupDatabase extends Command
|
|||||||
{
|
{
|
||||||
$rep = new ToolRepository();
|
$rep = new ToolRepository();
|
||||||
$result = $rep->backupDatabase();
|
$result = $rep->backupDatabase();
|
||||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class BackupWeb extends Command
|
|||||||
{
|
{
|
||||||
$rep = new ToolRepository();
|
$rep = new ToolRepository();
|
||||||
$result = $rep->backupWeb();
|
$result = $rep->backupWeb();
|
||||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class DeleteExpiredToken extends Command
|
|||||||
|
|
||||||
$query->where('last_used_at', '<', Carbon::now()->subDays($days));
|
$query->where('last_used_at', '<', Carbon::now()->subDays($days));
|
||||||
$result = $query->delete();
|
$result = $query->delete();
|
||||||
$log = sprintf('[%s], %s, result: %s, query: %s', REQUEST_ID, __METHOD__, var_export($result, true), last_query());
|
$log = sprintf('[%s], %s, result: %s, query: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true), last_query());
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class ExamAssign extends Command
|
|||||||
$end = $this->option('end');
|
$end = $this->option('end');
|
||||||
$this->info(sprintf('uid: %s, examId: %s, begin: %s, end: %s', $uid, $examId, $begin, $end));
|
$this->info(sprintf('uid: %s, examId: %s, begin: %s, end: %s', $uid, $examId, $begin, $end));
|
||||||
$result = $examRep->assignToUser($uid, $examId, $begin, $end);
|
$result = $examRep->assignToUser($uid, $examId, $begin, $end);
|
||||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class ExamAssignCronjob extends Command
|
|||||||
{
|
{
|
||||||
$examRep = new ExamRepository();
|
$examRep = new ExamRepository();
|
||||||
$result = $examRep->cronjonAssign();
|
$result = $examRep->cronjonAssign();
|
||||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class ExamCheckoutCronjob extends Command
|
|||||||
$ignoreTimeRange = $this->option('ignore-time-range');
|
$ignoreTimeRange = $this->option('ignore-time-range');
|
||||||
$this->info('ignore-time-range: ' . var_export($ignoreTimeRange, true));
|
$this->info('ignore-time-range: ' . var_export($ignoreTimeRange, true));
|
||||||
$result = $examRep->cronjobCheckout($ignoreTimeRange);
|
$result = $examRep->cronjobCheckout($ignoreTimeRange);
|
||||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class ExamUpdateProgress extends Command
|
|||||||
$uid = $this->argument('uid');
|
$uid = $this->argument('uid');
|
||||||
$examRep = new ExamRepository();
|
$examRep = new ExamRepository();
|
||||||
$result = $examRep->updateProgress($uid);
|
$result = $examRep->updateProgress($uid);
|
||||||
$this->info(REQUEST_ID . ", result: " . var_export($result, true));
|
$this->info(nexus()->getRequestId() . ", result: " . var_export($result, true));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class HitAndRunUpdateStatus extends Command
|
|||||||
$result = $rep->cronjobUpdateStatus($uid, $torrentId);
|
$result = $rep->cronjobUpdateStatus($uid, $torrentId);
|
||||||
$log = sprintf(
|
$log = sprintf(
|
||||||
'[%s], %s, uid: %s, torrentId: %s, result: %s',
|
'[%s], %s, uid: %s, torrentId: %s, result: %s',
|
||||||
REQUEST_ID, __METHOD__, $uid, $torrentId, var_export($result, true)
|
nexus()->getRequestId(), __METHOD__, $uid, $torrentId, var_export($result, true)
|
||||||
);
|
);
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class MigrateTorrentTag extends Command
|
|||||||
{
|
{
|
||||||
$rep = new TagRepository();
|
$rep = new TagRepository();
|
||||||
$result = $rep->migrateTorrentTag();
|
$result = $rep->migrateTorrentTag();
|
||||||
$log = sprintf('[%s], %s, result: %s, query: %s', REQUEST_ID, __METHOD__, var_export($result, true), last_query());
|
$log = sprintf('[%s], %s, result: %s, query: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true), last_query());
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -65,8 +65,11 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$redis = Redis::connection()->client();
|
$peerId = '-UT355W-%af%b0ky%86N%a6%17i%f8%c1%0a';
|
||||||
$r = $redis->get('5da94a358e67cb5181166ae2611c2fd9');
|
$peerId = '-UT355W-%af%b0ky%86N%a6%17i%f8%c1%0a';
|
||||||
|
$peerId = '-UT355W-%AF%B0ky%86N%A6%17i%F8%C1';
|
||||||
|
$peerId = '-UT355W-%AF%B0ky%86N%A6%17i%F8%C1%0A';
|
||||||
|
$r = strlen(urldecode($peerId));
|
||||||
dd($r);
|
dd($r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class UserResetPassword extends Command
|
|||||||
|
|
||||||
$rep = new UserRepository();
|
$rep = new UserRepository();
|
||||||
$result = $rep->resetPassword($uid, $password, $passwordConfirmation);
|
$result = $rep->resetPassword($uid, $password, $passwordConfirmation);
|
||||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
$log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true));
|
||||||
$this->info($log);
|
$this->info($log);
|
||||||
do_log($log);
|
do_log($log);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class Kernel extends HttpKernel
|
|||||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||||
\App\Http\Middleware\TrimStrings::class,
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
// \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
// \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||||
|
\App\Http\Middleware\BootNexus::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Nexus\Nexus;
|
||||||
|
|
||||||
|
class BootNexus
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
Nexus::boot();
|
||||||
|
do_log(sprintf(
|
||||||
|
"Nexus booted. request.server: %s, request.header: %s, request.query: %s, request.input: %s",
|
||||||
|
nexus_json_encode($request->server()), nexus_json_encode($request->header()), nexus_json_encode($request->query()), nexus_json_encode($request->input())
|
||||||
|
));
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ class Permission
|
|||||||
{
|
{
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
if (!$user || (IS_PLATFORM_ADMIN && !$user->canAccessAdmin())) {
|
if (!$user || (nexus()->isPlatformAdmin() && !$user->canAccessAdmin())) {
|
||||||
do_log("denied!");
|
do_log("denied!");
|
||||||
throw new UnauthorizedException('Unauthorized!');
|
throw new UnauthorizedException('Unauthorized!');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ class Platform
|
|||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next)
|
public function handle(Request $request, Closure $next)
|
||||||
{
|
{
|
||||||
do_log(nexus_json_encode($_SERVER));
|
if (empty(nexus()->getPlatform())) {
|
||||||
if (empty(CURRENT_PLATFORM)) {
|
|
||||||
throw new \InvalidArgumentException("Require platform header.");
|
throw new \InvalidArgumentException("Require platform header.");
|
||||||
}
|
}
|
||||||
if (!in_array(CURRENT_PLATFORM, PLATFORMS)) {
|
if (!nexus()->isPlatformValid()) {
|
||||||
throw new \InvalidArgumentException("Invalid platform: " . CURRENT_PLATFORM);
|
throw new \InvalidArgumentException("Invalid platform: " . CURRENT_PLATFORM);
|
||||||
}
|
}
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|||||||
@@ -15,5 +15,7 @@ class TrimStrings extends Middleware
|
|||||||
'current_password',
|
'current_password',
|
||||||
'password',
|
'password',
|
||||||
'password_confirmation',
|
'password_confirmation',
|
||||||
|
'peer_id',
|
||||||
|
'info_hash',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Nexus\Nexus;
|
||||||
|
|
||||||
|
class ResetNexus
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param mixed $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event): void
|
||||||
|
{
|
||||||
|
Nexus::flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ class NexusFormatter
|
|||||||
|
|
||||||
protected function formatter()
|
protected function formatter()
|
||||||
{
|
{
|
||||||
$format = "[%datetime%] [" . REQUEST_ID . "] %channel%.%level_name%: %message% %context% %extra%\n";
|
$format = "[%datetime%] [" . nexus()->getRequestId() . "] %channel%.%level_name%: %message% %context% %extra%\n";
|
||||||
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) {
|
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) {
|
||||||
$formatter->includeStacktraces();
|
$formatter->includeStacktraces();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use Illuminate\Support\Facades\App;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Nexus\Nexus;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -28,5 +29,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
// JsonResource::withoutWrapping();
|
// JsonResource::withoutWrapping();
|
||||||
DB::connection(config('database.default'))->enableQueryLog();
|
DB::connection(config('database.default'))->enableQueryLog();
|
||||||
|
// Nexus::boot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ class AgentAllowRepository extends BaseRepository
|
|||||||
$agentAllowId = $agentAllow->id;
|
$agentAllowId = $agentAllow->id;
|
||||||
$logPrefix = "[ID: $agentAllowId]";
|
$logPrefix = "[ID: $agentAllowId]";
|
||||||
$isPeerIdAllowed = $isAgentAllowed = $isPeerIdTooLow = $isAgentTooLow = false;
|
$isPeerIdAllowed = $isAgentAllowed = $isPeerIdTooLow = $isAgentTooLow = false;
|
||||||
//check peer_id
|
//check peer_id, when handle scrape request, no peer_id, so let it pass
|
||||||
if ($agentAllow->peer_id_pattern == '') {
|
if ($agentAllow->peer_id_pattern == '' || $peerId === null) {
|
||||||
$isPeerIdAllowed = true;
|
$isPeerIdAllowed = true;
|
||||||
} else {
|
} else {
|
||||||
$pattern = $agentAllow->peer_id_pattern;
|
$pattern = $agentAllow->peer_id_pattern;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class AuthenticateRepository extends BaseRepository
|
|||||||
if (!$user || md5($user->secret . $password . $user->secret) != $user->passhash) {
|
if (!$user || md5($user->secret . $password . $user->secret) != $user->passhash) {
|
||||||
throw new \InvalidArgumentException('Username or password invalid.');
|
throw new \InvalidArgumentException('Username or password invalid.');
|
||||||
}
|
}
|
||||||
if (IS_PLATFORM_ADMIN && !$user->canAccessAdmin()) {
|
if (nexus()->isPlatformAdmin() && !$user->canAccessAdmin()) {
|
||||||
throw new UnauthorizedException('Unauthorized!');
|
throw new UnauthorizedException('Unauthorized!');
|
||||||
}
|
}
|
||||||
$user->checkIsNormal();
|
$user->checkIsNormal();
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.system_info.$name"),
|
'text' => nexus_trans("dashboard.system_info.$name"),
|
||||||
'value' => $_SERVER['SERVER_SOFTWARE'],
|
'value' => $_SERVER['SERVER_SOFTWARE'] ?? '',
|
||||||
];
|
];
|
||||||
$name = 'load_average';
|
$name = 'load_average';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
|
|||||||
@@ -51,11 +51,10 @@ class TrackerRepository extends BaseRepository
|
|||||||
|
|
||||||
public function announce(Request $request): \Illuminate\Http\Response
|
public function announce(Request $request): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
do_log(nexus_json_encode($_SERVER));
|
do_log("queryString: " . $request->getQueryString());
|
||||||
try {
|
try {
|
||||||
$withPeers = false;
|
$withPeers = false;
|
||||||
$queries = $this->checkAnnounceFields($request);
|
$queries = $this->checkAnnounceFields($request);
|
||||||
do_log("[QUERIES] " . json_encode(Arr::only($queries, ['ip', 'user_agent', 'uploaded', 'downloaded', 'left', 'event'])), 'debug');
|
|
||||||
$user = $this->checkUser($request);
|
$user = $this->checkUser($request);
|
||||||
$clientAllow = $this->checkClient($request);
|
$clientAllow = $this->checkClient($request);
|
||||||
$torrent = $this->checkTorrent($queries, $user);
|
$torrent = $this->checkTorrent($queries, $user);
|
||||||
@@ -108,7 +107,7 @@ class TrackerRepository extends BaseRepository
|
|||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
//other system exception
|
//other system exception
|
||||||
do_log("[" . get_class($exception) . "] " . $exception->getMessage() . "\n" . $exception->getTraceAsString(), 'error');
|
do_log("[" . get_class($exception) . "] " . $exception->getMessage() . "\n" . $exception->getTraceAsString(), 'error');
|
||||||
$repDict = $this->generateFailedAnnounceResponse("system error, report to sysop please, hint: " . REQUEST_ID);
|
$repDict = $this->generateFailedAnnounceResponse("system error, report to sysop please, hint: " . nexus()->getRequestId());
|
||||||
} finally {
|
} finally {
|
||||||
if (isset($user) && count($this->userUpdates)) {
|
if (isset($user) && count($this->userUpdates)) {
|
||||||
$user->update($this->userUpdates);
|
$user->update($this->userUpdates);
|
||||||
@@ -218,8 +217,8 @@ class TrackerRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (['info_hash', 'peer_id'] as $item) {
|
foreach (['info_hash', 'peer_id'] as $item) {
|
||||||
if (\strlen((string) $queries[$item]) !== 20) {
|
if (($length = \strlen((string) $queries[$item])) !== 20) {
|
||||||
throw new TrackerException("Invalid $item ! $item is not 20 bytes long");
|
throw new TrackerException("Invalid $item ! $item is not 20 bytes long($length)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,7 +501,7 @@ class TrackerRepository extends BaseRepository
|
|||||||
unset($queries['key']);
|
unset($queries['key']);
|
||||||
$lockKey = md5(http_build_query($queries));
|
$lockKey = md5(http_build_query($queries));
|
||||||
$redis = Redis::connection()->client();
|
$redis = Redis::connection()->client();
|
||||||
if (!$redis->set($lockKey, NEXUS_START, ['nx', 'ex' => self::MIN_ANNOUNCE_WAIT_SECOND])) {
|
if (!$redis->set($lockKey, nexus()->getStartTimestamp(), ['nx', 'ex' => 5])) {
|
||||||
do_log('[RE_ANNOUNCE]');
|
do_log('[RE_ANNOUNCE]');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -654,6 +653,7 @@ class TrackerRepository extends BaseRepository
|
|||||||
|
|
||||||
protected function sendFinalAnnounceResponse($repDict): \Illuminate\Http\Response
|
protected function sendFinalAnnounceResponse($repDict): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
|
do_log("[repDict] " . nexus_json_encode($repDict));
|
||||||
return \response(Bencode::encode($repDict))
|
return \response(Bencode::encode($repDict))
|
||||||
->withHeaders(['Content-Type' => 'text/plain; charset=utf-8'])
|
->withHeaders(['Content-Type' => 'text/plain; charset=utf-8'])
|
||||||
->withHeaders(['Connection' => 'close'])
|
->withHeaders(['Connection' => 'close'])
|
||||||
@@ -776,7 +776,7 @@ class TrackerRepository extends BaseRepository
|
|||||||
|
|
||||||
public function scrape(Request $request): \Illuminate\Http\Response
|
public function scrape(Request $request): \Illuminate\Http\Response
|
||||||
{
|
{
|
||||||
do_log(nexus_json_encode($_SERVER));
|
do_log("queryString: " . $request->getQueryString());
|
||||||
try {
|
try {
|
||||||
$infoHashArr = $this->checkScrapeFields($request);
|
$infoHashArr = $this->checkScrapeFields($request);
|
||||||
$user = $this->checkUser($request);
|
$user = $this->checkUser($request);
|
||||||
@@ -785,6 +785,9 @@ class TrackerRepository extends BaseRepository
|
|||||||
if ($user->clientselect != $clientAllow->id) {
|
if ($user->clientselect != $clientAllow->id) {
|
||||||
$this->userUpdates['clientselect'] = $clientAllow->id;
|
$this->userUpdates['clientselect'] = $clientAllow->id;
|
||||||
}
|
}
|
||||||
|
if ($user->showclienterror == 'yes') {
|
||||||
|
$this->userUpdates['showclienterror'] = 'no';
|
||||||
|
}
|
||||||
$repDict = $this->generateScrapeResponse($infoHashArr);
|
$repDict = $this->generateScrapeResponse($infoHashArr);
|
||||||
} catch (ClientNotAllowedException $exception) {
|
} catch (ClientNotAllowedException $exception) {
|
||||||
do_log("[ClientNotAllowedException] " . $exception->getMessage());
|
do_log("[ClientNotAllowedException] " . $exception->getMessage());
|
||||||
@@ -797,8 +800,9 @@ class TrackerRepository extends BaseRepository
|
|||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
//other system exception
|
//other system exception
|
||||||
do_log("[" . get_class($exception) . "] " . $exception->getMessage() . "\n" . $exception->getTraceAsString(), 'error');
|
do_log("[" . get_class($exception) . "] " . $exception->getMessage() . "\n" . $exception->getTraceAsString(), 'error');
|
||||||
$repDict = $this->generateFailedAnnounceResponse("system error, report to sysop please, hint: " . REQUEST_ID);
|
$repDict = $this->generateFailedAnnounceResponse("system error, report to sysop please, hint: " . nexus()->getRequestId());
|
||||||
} finally {
|
} finally {
|
||||||
|
do_log("userUpdates: " . nexus_json_encode($this->userUpdates));
|
||||||
if (isset($user) && count($this->userUpdates)) {
|
if (isset($user) && count($this->userUpdates)) {
|
||||||
$user->update($this->userUpdates);
|
$user->update($this->userUpdates);
|
||||||
do_log(last_query(), 'debug');
|
do_log(last_query(), 'debug');
|
||||||
@@ -817,7 +821,7 @@ class TrackerRepository extends BaseRepository
|
|||||||
} else {
|
} else {
|
||||||
foreach ($info_hash_array as $item) {
|
foreach ($info_hash_array as $item) {
|
||||||
if (strlen($item) != 20) {
|
if (strlen($item) != 20) {
|
||||||
throw new TrackerException("Invalid info_hash ! :attribute is not 20 bytes long");
|
throw new TrackerException("Invalid info_hash ! info_hash is not 20 bytes long");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -852,7 +856,7 @@ class TrackerRepository extends BaseRepository
|
|||||||
return Cache::remember($cacheKey, 60, function () use ($infoHash) {
|
return Cache::remember($cacheKey, 60, function () use ($infoHash) {
|
||||||
$fieldRaw = 'id, owner, sp_state, seeders, leechers, added, banned, hr, visible, last_action, times_completed';
|
$fieldRaw = 'id, owner, sp_state, seeders, leechers, added, banned, hr, visible, last_action, times_completed';
|
||||||
$torrent = Torrent::query()->where('info_hash', $infoHash)->selectRaw($fieldRaw)->first();
|
$torrent = Torrent::query()->where('info_hash', $infoHash)->selectRaw($fieldRaw)->first();
|
||||||
do_log("cache miss, from database: " . last_query() . ", and get: " . $torrent->id);
|
do_log("[getTorrentByInfoHash] cache miss, from database: " . last_query() . ", and get: " . $torrent->id);
|
||||||
return $torrent;
|
return $torrent;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('LARAVEL_START') || define('LARAVEL_START', microtime(true));
|
defined('LARAVEL_START') || define('LARAVEL_START', microtime(true));
|
||||||
defined('NEXUS_START') || define('NEXUS_START', LARAVEL_START);
|
|
||||||
defined('IN_NEXUS') || define('IN_NEXUS', false);
|
defined('IN_NEXUS') || define('IN_NEXUS', false);
|
||||||
require dirname(__DIR__) . '/include/constants.php';
|
require dirname(__DIR__) . '/include/constants.php';
|
||||||
require dirname(__DIR__) . '/include/globalfunctions.php';
|
require dirname(__DIR__) . '/include/globalfunctions.php';
|
||||||
require dirname(__DIR__) . '/include/functions.php';
|
require dirname(__DIR__) . '/include/functions.php';
|
||||||
|
if (!RUNNING_IN_OCTANE) {
|
||||||
|
\Nexus\Nexus::boot();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Create The Application
|
| Create The Application
|
||||||
|
|||||||
+2
-1
@@ -70,7 +70,7 @@ return [
|
|||||||
RequestReceived::class => [
|
RequestReceived::class => [
|
||||||
...Octane::prepareApplicationForNextOperation(),
|
...Octane::prepareApplicationForNextOperation(),
|
||||||
...Octane::prepareApplicationForNextRequest(),
|
...Octane::prepareApplicationForNextRequest(),
|
||||||
//
|
\App\Listeners\ResetNexus::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
RequestHandled::class => [
|
RequestHandled::class => [
|
||||||
@@ -189,6 +189,7 @@ return [
|
|||||||
'routes',
|
'routes',
|
||||||
'composer.lock',
|
'composer.lock',
|
||||||
'.env',
|
'.env',
|
||||||
|
'include/**/*.php',
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
define('NEXUS_START', microtime(true));
|
|
||||||
define('IN_NEXUS', true);
|
define('IN_NEXUS', true);
|
||||||
$rootpath = dirname(__DIR__) . '/';
|
$rootpath = dirname(__DIR__) . '/';
|
||||||
set_include_path(get_include_path() . PATH_SEPARATOR . $rootpath);
|
set_include_path(get_include_path() . PATH_SEPARATOR . $rootpath);
|
||||||
@@ -9,3 +8,4 @@ require $rootpath . 'include/core.php';
|
|||||||
require $rootpath . 'classes/class_advertisement.php';
|
require $rootpath . 'classes/class_advertisement.php';
|
||||||
require $rootpath . 'classes/class_attendance.php';
|
require $rootpath . 'classes/class_attendance.php';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('NEXUS_START') || define('NEXUS_START', microtime(true));
|
|
||||||
defined('IN_NEXUS') || define('IN_NEXUS', true);
|
defined('IN_NEXUS') || define('IN_NEXUS', true);
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', true);
|
defined('IN_TRACKER') || define('IN_TRACKER', true);
|
||||||
$rootpath= dirname(__DIR__) . '/';
|
$rootpath= dirname(__DIR__) . '/';
|
||||||
@@ -7,5 +6,6 @@ require_once $rootpath . 'include/constants.php';
|
|||||||
require_once $rootpath . 'include/globalfunctions.php';
|
require_once $rootpath . 'include/globalfunctions.php';
|
||||||
require_once $rootpath . 'include/functions_announce.php';
|
require_once $rootpath . 'include/functions_announce.php';
|
||||||
require_once $rootpath . 'vendor/autoload.php';
|
require_once $rootpath . 'vendor/autoload.php';
|
||||||
|
\Nexus\Nexus::boot();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ die('Hacking attempt!');
|
|||||||
|
|
||||||
function printProgress($msg) {
|
function printProgress($msg) {
|
||||||
$br = php_sapi_name() == 'cli' ? "\n" : "<br />";
|
$br = php_sapi_name() == 'cli' ? "\n" : "<br />";
|
||||||
echo sprintf("[%s] [%s] %s ... done!%s", date('Y-m-d H:i:s'), REQUEST_ID, $msg, $br);
|
echo sprintf("[%s] [%s] %s ... done!%s", date('Y-m-d H:i:s'), nexus()->getRequestId(), $msg, $br);
|
||||||
}
|
}
|
||||||
|
|
||||||
function torrent_promotion_expire($days, $type = 2, $targettype = 1){
|
function torrent_promotion_expire($days, $type = 2, $targettype = 1){
|
||||||
|
|||||||
+31
-24
@@ -7,31 +7,38 @@ defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
|||||||
defined('NEXUSWIKIURL') || define("NEXUSWIKIURL","https://doc.nexusphp.org");
|
defined('NEXUSWIKIURL') || define("NEXUSWIKIURL","https://doc.nexusphp.org");
|
||||||
defined('VERSION') || define("VERSION","Powered by <a href=\"aboutnexus.php\">".PROJECTNAME."</a>");
|
defined('VERSION') || define("VERSION","Powered by <a href=\"aboutnexus.php\">".PROJECTNAME."</a>");
|
||||||
defined('THISTRACKER') || define("THISTRACKER","General");
|
defined('THISTRACKER') || define("THISTRACKER","General");
|
||||||
$showversion = " - Powered by ".PROJECTNAME;
|
|
||||||
defined('ROOT_PATH') || define('ROOT_PATH', dirname(__DIR__) . '/');
|
defined('ROOT_PATH') || define('ROOT_PATH', dirname(__DIR__) . '/');
|
||||||
defined('CURRENT_SCRIPT') || define('CURRENT_SCRIPT', strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true));
|
if (!defined('RUNNING_IN_OCTANE')) {
|
||||||
defined('IS_ANNOUNCE') || define('IS_ANNOUNCE', CURRENT_SCRIPT == 'announce');
|
if (!empty($_SERVER['PWD']) && str_contains($_SERVER['PWD'], 'vendor/laravel/octane/bin')) {
|
||||||
|
define('RUNNING_IN_OCTANE', true);
|
||||||
defined('PLATFORM_ADMIN') || define('PLATFORM_ADMIN', 'admin');
|
|
||||||
defined('PLATFORM_USER') || define('PLATFORM_USER', 'user');
|
|
||||||
defined('PLATFORMS') || define('PLATFORMS', [PLATFORM_ADMIN, PLATFORM_USER]);
|
|
||||||
defined('CURRENT_PLATFORM') || define('CURRENT_PLATFORM', $_SERVER['HTTP_PLATFORM'] ?? '');
|
|
||||||
defined('IS_PLATFORM_ADMIN') || define('IS_PLATFORM_ADMIN', CURRENT_PLATFORM == PLATFORM_ADMIN);
|
|
||||||
defined('IS_PLATFORM_USER') || define('IS_PLATFORM_USER', CURRENT_PLATFORM == PLATFORM_USER);
|
|
||||||
|
|
||||||
|
|
||||||
//define the REQUEST_ID
|
|
||||||
if (!defined('REQUEST_ID')) {
|
|
||||||
if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
|
|
||||||
$requestId = $_SERVER['HTTP_X_REQUEST_ID'];
|
|
||||||
} elseif (!empty($_SERVER['REQUEST_ID'])) {
|
|
||||||
$requestId = $_SERVER['REQUEST_ID'];
|
|
||||||
} else {
|
} else {
|
||||||
$prefix = ($_SERVER['SCRIPT_FILENAME'] ?? '') . implode('', $_SERVER['argv'] ?? []);
|
define('RUNNING_IN_OCTANE', false);
|
||||||
$prefix = substr(md5($prefix), 0, 4);
|
|
||||||
// 4 + 23 = 27 characters, after replace '.', 26
|
|
||||||
$requestId = str_replace('.', '', uniqid($prefix, true));
|
|
||||||
$requestId .= bin2hex(random_bytes(3));
|
|
||||||
}
|
}
|
||||||
define('REQUEST_ID', $requestId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//defined('CURRENT_SCRIPT') || define('CURRENT_SCRIPT', strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true));
|
||||||
|
//defined('IS_ANNOUNCE') || define('IS_ANNOUNCE', CURRENT_SCRIPT == 'announce');
|
||||||
|
//
|
||||||
|
//defined('PLATFORM_ADMIN') || define('PLATFORM_ADMIN', 'admin');
|
||||||
|
//defined('PLATFORM_USER') || define('PLATFORM_USER', 'user');
|
||||||
|
//defined('PLATFORMS') || define('PLATFORMS', [PLATFORM_ADMIN, PLATFORM_USER]);
|
||||||
|
//defined('CURRENT_PLATFORM') || define('CURRENT_PLATFORM', $_SERVER['HTTP_PLATFORM'] ?? '');
|
||||||
|
//defined('IS_PLATFORM_ADMIN') || define('IS_PLATFORM_ADMIN', CURRENT_PLATFORM == PLATFORM_ADMIN);
|
||||||
|
//defined('IS_PLATFORM_USER') || define('IS_PLATFORM_USER', CURRENT_PLATFORM == PLATFORM_USER);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////define the REQUEST_ID
|
||||||
|
//if (!defined('REQUEST_ID')) {
|
||||||
|
// if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
|
||||||
|
// $requestId = $_SERVER['HTTP_X_REQUEST_ID'];
|
||||||
|
// } elseif (!empty($_SERVER['REQUEST_ID'])) {
|
||||||
|
// $requestId = $_SERVER['REQUEST_ID'];
|
||||||
|
// } else {
|
||||||
|
// $prefix = ($_SERVER['SCRIPT_FILENAME'] ?? '') . implode('', $_SERVER['argv'] ?? []);
|
||||||
|
// $prefix = substr(md5($prefix), 0, 4);
|
||||||
|
// // 4 + 23 = 27 characters, after replace '.', 26
|
||||||
|
// $requestId = str_replace('.', '', uniqid($prefix, true));
|
||||||
|
// $requestId .= bin2hex(random_bytes(3));
|
||||||
|
// }
|
||||||
|
// define('REQUEST_ID', $requestId);
|
||||||
|
//}
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/constants.php';
|
require_once __DIR__ . '/constants.php';
|
||||||
require_once $rootpath . 'vendor/autoload.php';
|
require_once $rootpath . 'vendor/autoload.php';
|
||||||
|
\Nexus\Nexus::boot();
|
||||||
if (!file_exists($rootpath . '.env')) {
|
if (!file_exists($rootpath . '.env')) {
|
||||||
$installScriptRelativePath = 'install/install.php';
|
$installScriptRelativePath = 'install/install.php';
|
||||||
$installScriptFile = $rootpath . "public/$installScriptRelativePath";
|
$installScriptFile = $rootpath . "public/$installScriptRelativePath";
|
||||||
@@ -17,7 +18,7 @@ ini_set('date.timezone', nexus_config('nexus.timezone'));
|
|||||||
ini_set('error_reporting', E_ALL);
|
ini_set('error_reporting', E_ALL);
|
||||||
ini_set('display_errors', 0);
|
ini_set('display_errors', 0);
|
||||||
|
|
||||||
if (!in_array(CURRENT_SCRIPT, ['announce', 'scrape'])) {
|
if (!in_array(nexus()->getScript(), ['announce', 'scrape'])) {
|
||||||
require $rootpath . get_langfile_path("functions.php");
|
require $rootpath . get_langfile_path("functions.php");
|
||||||
checkGuestVisit();
|
checkGuestVisit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2274,7 +2274,7 @@ function get_style_highlight()
|
|||||||
function stdhead($title = "", $msgalert = true, $script = "", $place = "")
|
function stdhead($title = "", $msgalert = true, $script = "", $place = "")
|
||||||
{
|
{
|
||||||
global $lang_functions;
|
global $lang_functions;
|
||||||
global $CURUSER, $CURLANGDIR, $USERUPDATESET, $iplog1, $oldip, $SITE_ONLINE, $FUNDS, $SITENAME, $SLOGAN, $logo_main, $BASEURL, $offlinemsg, $showversion,$enabledonation, $staffmem_class, $titlekeywords_tweak, $metakeywords_tweak, $metadescription_tweak, $cssdate_tweak, $deletenotransfertwo_account, $neverdelete_account, $iniupload_main;
|
global $CURUSER, $CURLANGDIR, $USERUPDATESET, $iplog1, $oldip, $SITE_ONLINE, $FUNDS, $SITENAME, $SLOGAN, $logo_main, $BASEURL, $offlinemsg,$enabledonation, $staffmem_class, $titlekeywords_tweak, $metakeywords_tweak, $metadescription_tweak, $cssdate_tweak, $deletenotransfertwo_account, $neverdelete_account, $iniupload_main;
|
||||||
global $tstart;
|
global $tstart;
|
||||||
global $Cache;
|
global $Cache;
|
||||||
global $Advertisement;
|
global $Advertisement;
|
||||||
@@ -2302,7 +2302,7 @@ function stdhead($title = "", $msgalert = true, $script = "", $place = "")
|
|||||||
$title = $SITENAME." :: " . htmlspecialchars($title);
|
$title = $SITENAME." :: " . htmlspecialchars($title);
|
||||||
if ($titlekeywords_tweak)
|
if ($titlekeywords_tweak)
|
||||||
$title .= " ".htmlspecialchars($titlekeywords_tweak);
|
$title .= " ".htmlspecialchars($titlekeywords_tweak);
|
||||||
$title .= $showversion;
|
$title .= " - Powered by ".PROJECTNAME;
|
||||||
if ($SITE_ONLINE == "no") {
|
if ($SITE_ONLINE == "no") {
|
||||||
if (get_user_class() < UC_ADMINISTRATOR) {
|
if (get_user_class() < UC_ADMINISTRATOR) {
|
||||||
die($lang_functions['std_site_down_for_maintenance']);
|
die($lang_functions['std_site_down_for_maintenance']);
|
||||||
@@ -2660,7 +2660,7 @@ function stdfoot() {
|
|||||||
}
|
}
|
||||||
// Variables for End Time
|
// Variables for End Time
|
||||||
$tend = microtime(true);
|
$tend = microtime(true);
|
||||||
$totaltime = ($tend - NEXUS_START);
|
$totaltime = ($tend - nexus()->getStartTimestamp());
|
||||||
$year = substr($datefounded, 0, 4);
|
$year = substr($datefounded, 0, 4);
|
||||||
$yearfounded = ($year ? $year : 2007);
|
$yearfounded = ($year ? $year : 2007);
|
||||||
print(" (c) "." <a href=\"" . get_protocol_prefix() . $BASEURL."\" target=\"_self\">".$SITENAME."</a> ".($icplicense_main ? " ".$icplicense_main." " : "").(date("Y") != $yearfounded ? $yearfounded."-" : "").date("Y")." ".VERSION."<br /><br />");
|
print(" (c) "." <a href=\"" . get_protocol_prefix() . $BASEURL."\" target=\"_self\">".$SITENAME."</a> ".($icplicense_main ? " ".$icplicense_main." " : "").(date("Y") != $yearfounded ? $yearfounded."-" : "").date("Y")." ".VERSION."<br /><br />");
|
||||||
@@ -2812,7 +2812,7 @@ function base64 ($string, $encode=true) {
|
|||||||
function loggedinorreturn($mainpage = false) {
|
function loggedinorreturn($mainpage = false) {
|
||||||
global $CURUSER,$BASEURL;
|
global $CURUSER,$BASEURL;
|
||||||
if (!$CURUSER) {
|
if (!$CURUSER) {
|
||||||
if (CURRENT_SCRIPT == 'ajax') {
|
if (nexus()->getScript() == 'ajax') {
|
||||||
exit(fail('Not login!', $_POST));
|
exit(fail('Not login!', $_POST));
|
||||||
}
|
}
|
||||||
if ($mainpage)
|
if ($mainpage)
|
||||||
@@ -4840,7 +4840,7 @@ function checkGuestVisit()
|
|||||||
if (empty($guestVisitType) || $guestVisitType == 'normal') {
|
if (empty($guestVisitType) || $guestVisitType == 'normal') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (in_array(CURRENT_SCRIPT, ['login', 'takelogin', 'image']) && canDoLogin()) {
|
if (in_array(nexus()->getScript(), ['login', 'takelogin', 'image']) && canDoLogin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5225,7 +5225,7 @@ function list_require_search_box_id()
|
|||||||
'userdetails' => [$setting['browsecat'], $setting['specialcat']],
|
'userdetails' => [$setting['browsecat'], $setting['specialcat']],
|
||||||
'offers' => [$setting['browsecat'], $setting['specialcat']],
|
'offers' => [$setting['browsecat'], $setting['specialcat']],
|
||||||
];
|
];
|
||||||
return $maps[CURRENT_SCRIPT] ?? [];
|
return $maps[nexus()->getScript()] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function can_access_torrent($torrent)
|
function can_access_torrent($torrent)
|
||||||
|
|||||||
@@ -344,6 +344,7 @@ function request_local_api($api)
|
|||||||
$options = [
|
$options = [
|
||||||
CURLOPT_URL => sprintf('%s?%s', trim($api, '/'), $_SERVER['QUERY_STRING']),
|
CURLOPT_URL => sprintf('%s?%s', trim($api, '/'), $_SERVER['QUERY_STRING']),
|
||||||
CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"],
|
CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"],
|
||||||
|
CURLOPT_HTTPHEADER => ['REQUEST_ID: ' . nexus()->getRequestId(), 'Platform: tracker'],
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_SSL_VERIFYPEER => false,
|
CURLOPT_SSL_VERIFYPEER => false,
|
||||||
CURLOPT_TIMEOUT => 60,
|
CURLOPT_TIMEOUT => 60,
|
||||||
|
|||||||
+33
-33
@@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use JetBrains\PhpStorm\Pure;
|
||||||
|
|
||||||
function get_global_sp_state()
|
function get_global_sp_state()
|
||||||
{
|
{
|
||||||
global $Cache;
|
global $Cache;
|
||||||
@@ -155,10 +158,13 @@ function nexus_dd($vars)
|
|||||||
*/
|
*/
|
||||||
function do_log($log, $level = 'info')
|
function do_log($log, $level = 'info')
|
||||||
{
|
{
|
||||||
static $uid, $passkey, $env, $sequence, $setLogLevel;
|
static $env, $setLogLevel;
|
||||||
if (is_null($setLogLevel)) {
|
if (is_null($setLogLevel)) {
|
||||||
$setLogLevel = nexus_env('LOG_LEVEL', 'debug');
|
$setLogLevel = nexus_env('LOG_LEVEL', 'debug');
|
||||||
}
|
}
|
||||||
|
if (is_null($env)) {
|
||||||
|
$env = nexus_env('APP_ENV', 'production');
|
||||||
|
}
|
||||||
$logLevels = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'];
|
$logLevels = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'];
|
||||||
$setLogLevelKey = array_search($setLogLevel, $logLevels);
|
$setLogLevelKey = array_search($setLogLevel, $logLevels);
|
||||||
$currentLogLevelKey = array_search($level, $logLevels);
|
$currentLogLevelKey = array_search($level, $logLevels);
|
||||||
@@ -175,32 +181,25 @@ function do_log($log, $level = 'info')
|
|||||||
if (($fd = fopen($logFile, 'a')) === false) {
|
if (($fd = fopen($logFile, 'a')) === false) {
|
||||||
$fd = fopen(sys_get_temp_dir() . '/nexus.log', 'a');
|
$fd = fopen(sys_get_temp_dir() . '/nexus.log', 'a');
|
||||||
}
|
}
|
||||||
if (is_null($uid)) {
|
if (IN_NEXUS) {
|
||||||
$sequence = 0;
|
global $CURUSER;
|
||||||
if (IN_NEXUS) {
|
$user = $CURUSER;
|
||||||
global $CURUSER;
|
$uid = $user['id'] ?? 0;
|
||||||
$user = $CURUSER;
|
$passkey = $user['passkey'] ?? $_REQUEST['passkey'] ?? $_REQUEST['authkey'] ?? '';
|
||||||
$uid = $user['id'] ?? 0;
|
|
||||||
$passkey = $user['passkey'] ?? $_REQUEST['passkey'] ?? $_REQUEST['authkey'] ?? '';
|
|
||||||
$env = nexus_env('APP_ENV');
|
|
||||||
} else {
|
|
||||||
$user = \Illuminate\Support\Facades\Auth::user();
|
|
||||||
$uid = $user->id ?? 0;
|
|
||||||
$passkey = $user->passkey ?? $_REQUEST['passkey'] ?? $_REQUEST['authkey'] ?? '';
|
|
||||||
$env = env('APP_ENV');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$sequence++;
|
$user = \Illuminate\Support\Facades\Auth::user();
|
||||||
|
$uid = $user->id ?? 0;
|
||||||
|
$passkey = $user->passkey ?? request('passkey', request('authkey', ''));
|
||||||
}
|
}
|
||||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||||
$content = sprintf(
|
$content = sprintf(
|
||||||
"[%s] [%s] [%s] [%s] [%s] [%s] %s.%s %s:%s %s%s%s %s%s",
|
"[%s] [%s] [%s] [%s] [%s] [%s] %s.%s %s:%s %s%s%s %s%s",
|
||||||
date('Y-m-d H:i:s'),
|
date('Y-m-d H:i:s'),
|
||||||
defined('REQUEST_ID') ? REQUEST_ID : '',
|
nexus() ? nexus()->getRequestId() : 'NO_REQUEST_ID',
|
||||||
|
nexus() ? nexus()->getLogSequence() : 0,
|
||||||
|
sprintf('%.3f', microtime(true) - (nexus() ? nexus()->getStartTimestamp() : 0)),
|
||||||
$uid,
|
$uid,
|
||||||
$passkey,
|
$passkey,
|
||||||
$sequence,
|
|
||||||
sprintf('%.3f', microtime(true) - NEXUS_START),
|
|
||||||
$env, $level,
|
$env, $level,
|
||||||
$backtrace[0]['file'] ?? '',
|
$backtrace[0]['file'] ?? '',
|
||||||
$backtrace[0]['line'] ?? '',
|
$backtrace[0]['line'] ?? '',
|
||||||
@@ -212,6 +211,9 @@ function do_log($log, $level = 'info')
|
|||||||
);
|
);
|
||||||
fwrite($fd, $content);
|
fwrite($fd, $content);
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
|
if (nexus()) {
|
||||||
|
nexus()->incrementLogSequence();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLogFile()
|
function getLogFile()
|
||||||
@@ -483,26 +485,19 @@ function api(...$args)
|
|||||||
$msg = $args[1];
|
$msg = $args[1];
|
||||||
$data = $args[2];
|
$data = $args[2];
|
||||||
}
|
}
|
||||||
if (defined('LARAVEL_START')) {
|
if ($data instanceof \Illuminate\Http\Resources\Json\ResourceCollection || $data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
|
||||||
$start = LARAVEL_START;
|
$data = $data->response()->getData(true);
|
||||||
if ($data instanceof \Illuminate\Http\Resources\Json\ResourceCollection || $data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
|
if (isset($data['data']) && count($data) == 1) {
|
||||||
$data = $data->response()->getData(true);
|
//单纯的集合,无分页等其数据
|
||||||
if (isset($data['data']) && count($data) == 1) {
|
$data = $data['data'];
|
||||||
//单纯的集合,无分页等其数据
|
|
||||||
$data = $data['data'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} elseif (defined('NEXUS_START')) {
|
|
||||||
$start = NEXUS_START;
|
|
||||||
} else {
|
|
||||||
throw new \RuntimeException("no constant START is defined.");
|
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'ret' => (int)$ret,
|
'ret' => (int)$ret,
|
||||||
'msg' => (string)$msg,
|
'msg' => (string)$msg,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'time' => (float)number_format(microtime(true) - $start, 3),
|
'time' => (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3),
|
||||||
'rid' => REQUEST_ID,
|
'rid' => nexus()->getRequestId(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,3 +664,8 @@ function get_hr_ratio($uped, $downed)
|
|||||||
|
|
||||||
return $ratio;
|
return $ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nexus()
|
||||||
|
{
|
||||||
|
return \Nexus\Nexus::instance();
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
namespace Nexus\Core;
|
||||||
|
|
||||||
|
class Constant
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @todo check RoadRunner environment
|
||||||
|
*/
|
||||||
|
public function define()
|
||||||
|
{
|
||||||
|
if (!empty($_SERVER['PWD']) && str_contains($_SERVER['PWD'], 'vendor/laravel/octane/bin')) {
|
||||||
|
$this->defineForOctane();
|
||||||
|
} else {
|
||||||
|
$this->defineForFPM();
|
||||||
|
}
|
||||||
|
$this->defineCommon();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defineForFPM()
|
||||||
|
{
|
||||||
|
defined('CURRENT_SCRIPT') || define('CURRENT_SCRIPT', strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true));
|
||||||
|
defined('CURRENT_PLATFORM') || define('CURRENT_PLATFORM', $_SERVER['HTTP_PLATFORM'] ?? '');
|
||||||
|
$requestId = '';
|
||||||
|
if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
|
||||||
|
$requestId = $_SERVER['HTTP_X_REQUEST_ID'];
|
||||||
|
} elseif (!empty($_SERVER['REQUEST_ID'])) {
|
||||||
|
$requestId = $_SERVER['REQUEST_ID'];
|
||||||
|
}
|
||||||
|
define('REQUEST_ID', $requestId ?: $this->generateRequestId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defineForOctane()
|
||||||
|
{
|
||||||
|
$request = request();
|
||||||
|
defined('CURRENT_SCRIPT') || define('CURRENT_SCRIPT', $request->header('script_filename', ''));
|
||||||
|
defined('CURRENT_PLATFORM') || define('CURRENT_PLATFORM', $request->header('platform', ''));
|
||||||
|
$requestId = $request->header('request_id', '');
|
||||||
|
define('REQUEST_ID', $requestId ?: $this->generateRequestId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateRequestId()
|
||||||
|
{
|
||||||
|
$prefix = ($_SERVER['SCRIPT_FILENAME'] ?? '') . implode('', $_SERVER['argv'] ?? []);
|
||||||
|
$prefix = substr(md5($prefix), 0, 4);
|
||||||
|
// 4 + 23 = 27 characters, after replace '.', 26
|
||||||
|
$requestId = str_replace('.', '', uniqid($prefix, true));
|
||||||
|
$requestId .= bin2hex(random_bytes(3));
|
||||||
|
return $requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defineCommon()
|
||||||
|
{
|
||||||
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.6.0');
|
||||||
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-03-14');
|
||||||
|
defined('ROOT_PATH') || define('ROOT_PATH', dirname(dirname(__DIR__)) . '/');
|
||||||
|
defined('IN_TRACKER') || define('IN_TRACKER', true);
|
||||||
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
defined('NEXUSWIKIURL') || define("NEXUSWIKIURL","https://doc.nexusphp.org");
|
||||||
|
defined('VERSION') || define("VERSION","Powered by <a href=\"aboutnexus.php\">".PROJECTNAME."</a>");
|
||||||
|
defined('THISTRACKER') || define("THISTRACKER","General");
|
||||||
|
|
||||||
|
defined('PLATFORM_ADMIN') || define('PLATFORM_ADMIN', 'admin');
|
||||||
|
defined('PLATFORM_USER') || define('PLATFORM_USER', 'user');
|
||||||
|
defined('PLATFORMS') || define('PLATFORMS', [PLATFORM_ADMIN, PLATFORM_USER]);
|
||||||
|
defined('IS_PLATFORM_ADMIN') || define('IS_PLATFORM_ADMIN', CURRENT_PLATFORM == PLATFORM_ADMIN);
|
||||||
|
defined('IS_PLATFORM_USER') || define('IS_PLATFORM_USER', CURRENT_PLATFORM == PLATFORM_USER);
|
||||||
|
defined('IS_ANNOUNCE') || define('IS_ANNOUNCE', CURRENT_SCRIPT == 'announce');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+176
@@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
namespace Nexus;
|
||||||
|
|
||||||
|
final class Nexus
|
||||||
|
{
|
||||||
|
private string $requestId;
|
||||||
|
|
||||||
|
private int $logSequence = 0;
|
||||||
|
|
||||||
|
private float $startTimestamp;
|
||||||
|
|
||||||
|
private string $script;
|
||||||
|
|
||||||
|
private string $platform;
|
||||||
|
|
||||||
|
private static bool $booted = false;
|
||||||
|
|
||||||
|
private static ?Nexus $instance = null;
|
||||||
|
|
||||||
|
const PLATFORM_USER = 'user';
|
||||||
|
const PLATFORM_ADMIN = 'admin';
|
||||||
|
const PLATFORM_TRACKER = 'tracker';
|
||||||
|
const PLATFORMS = [self::PLATFORM_USER, self::PLATFORM_ADMIN, self::PLATFORM_TRACKER];
|
||||||
|
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function __clone()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function instance()
|
||||||
|
{
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequestId(): string
|
||||||
|
{
|
||||||
|
return $this->requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStartTimestamp(): float
|
||||||
|
{
|
||||||
|
return $this->startTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getPlatform(): string
|
||||||
|
{
|
||||||
|
return $this->platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getScript(): string
|
||||||
|
{
|
||||||
|
return $this->script;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLogSequence(): int
|
||||||
|
{
|
||||||
|
return $this->logSequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isPlatformValid(): bool
|
||||||
|
{
|
||||||
|
return in_array($this->platform, self::PLATFORMS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isPlatformAdmin(): bool
|
||||||
|
{
|
||||||
|
return $this->platform == self::PLATFORM_ADMIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isPlatformUser(): bool
|
||||||
|
{
|
||||||
|
return $this->platform == self::PLATFORM_USER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isScriptAnnounce(): bool
|
||||||
|
{
|
||||||
|
return $this->script == 'announce';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function incrementLogSequence()
|
||||||
|
{
|
||||||
|
$this->logSequence++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function runningInOctane(): bool
|
||||||
|
{
|
||||||
|
if (defined('RUNNING_IN_OCTANE') && RUNNING_IN_OCTANE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateRequestId(): string
|
||||||
|
{
|
||||||
|
$prefix = ($_SERVER['SCRIPT_FILENAME'] ?? '') . implode('', $_SERVER['argv'] ?? []);
|
||||||
|
$prefix = substr(md5($prefix), 0, 4);
|
||||||
|
// 4 + 23 = 27 characters, after replace '.', 26
|
||||||
|
$requestId = str_replace('.', '', uniqid($prefix, true));
|
||||||
|
$requestId .= bin2hex(random_bytes(3));
|
||||||
|
return $requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function boot()
|
||||||
|
{
|
||||||
|
if (self::$booted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$instance = new self();
|
||||||
|
$instance->setStartTimestamp();
|
||||||
|
$instance->setRequestId();
|
||||||
|
$instance->setScript();
|
||||||
|
$instance->setPlatform();
|
||||||
|
self::$instance = $instance;
|
||||||
|
self::$booted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function flush()
|
||||||
|
{
|
||||||
|
self::$booted = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setRequestId()
|
||||||
|
{
|
||||||
|
$requestId = '';
|
||||||
|
if ($this->runningInOctane()) {
|
||||||
|
$request = request();
|
||||||
|
$requestId = $request->server('request_id', $request->header('request_id', ''));
|
||||||
|
} else {
|
||||||
|
if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
|
||||||
|
$requestId = $_SERVER['HTTP_X_REQUEST_ID'];
|
||||||
|
} elseif (!empty($_SERVER['REQUEST_ID'])) {
|
||||||
|
$requestId = $_SERVER['REQUEST_ID'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($requestId)) {
|
||||||
|
$requestId = $this->generateRequestId();
|
||||||
|
}
|
||||||
|
$this->requestId = $requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setScript()
|
||||||
|
{
|
||||||
|
if ($this->runningInOctane()) {
|
||||||
|
$request = request();
|
||||||
|
$script = $request->header('script_filename', '');
|
||||||
|
} else {
|
||||||
|
$script = strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true);
|
||||||
|
}
|
||||||
|
$this->script = $script;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setStartTimestamp()
|
||||||
|
{
|
||||||
|
$this->startTimestamp = microtime(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setPlatform()
|
||||||
|
{
|
||||||
|
if ($this->runningInOctane()) {
|
||||||
|
$request = request();
|
||||||
|
$platform = $request->header('platform', '');
|
||||||
|
} else {
|
||||||
|
$platform = $_SERVER['HTTP_PLATFORM'] ?? '';
|
||||||
|
}
|
||||||
|
$this->platform = $platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -14,7 +14,7 @@ $tagKeyById = $tagRep->createBasicQuery()->get()->keyBy('id');
|
|||||||
$renderKeyArr = $tagKeyById->keys()->toArray();
|
$renderKeyArr = $tagKeyById->keys()->toArray();
|
||||||
|
|
||||||
//check searchbox
|
//check searchbox
|
||||||
switch (CURRENT_SCRIPT) {
|
switch (nexus()->getScript()) {
|
||||||
case 'torrents':
|
case 'torrents':
|
||||||
$sectiontype = $browsecatmode;
|
$sectiontype = $browsecatmode;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user