Migrate Laysense to upstream LaySite 1.4.3 with external site data

This commit is contained in:
2026-11-27 17:47:31 +08:00
parent b8eb9b35eb
commit 1d2cb2ed1e
277 changed files with 9049 additions and 3222 deletions
+3 -1
View File
@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace App\Http;
use App\Config\Environment;
final class Request extends \support\Request
{
private const LOOPBACK = ['127.0.0.1', '::1'];
@@ -21,7 +23,7 @@ final class Request extends \support\Request
private function fromTrustedProxy(): bool
{
$configured = getenv('LAYSENSE_TRUSTED_PROXIES');
$configured = Environment::get('LAYSITE_TRUSTED_PROXIES');
$trusted = $configured === false ? self::LOOPBACK : array_map('trim', explode(',', $configured));
return in_array($this->getRemoteIp(), $trusted, true);
+39
View File
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace App\Http;
use App\Config\Environment;
use support\Request;
use support\Response;
use Workerman\Protocols\Http\Session;
final class VisitorSession
{
private const COOKIE = 'LAYSITE_VISITOR';
public static function open(?Request $request): ?Session
{
$id = $request?->cookie(self::COOKIE);
return is_string($id) && preg_match('/^visitor-[a-f0-9]{64}$/D', $id) ? new Session($id) : null;
}
public static function create(): Session
{
return new Session('visitor-' . bin2hex(random_bytes(32)));
}
public static function cookie(Response $response, ?Session $session, int $seconds): Response
{
return $response->cookie(self::COOKIE, $session?->getId() ?? '', $seconds, '/',
secure: Environment::get('LAYSITE_SECURE_COOKIES') === '1', httpOnly: true, sameSite: 'Lax');
}
public static function profile(?Request $request): ?array
{
$profile = self::open($request)?->get('profile');
return is_array($profile) && ($profile['expires'] ?? 0) > time() ? $profile : null;
}
}