Launch LaySite visual editor and MCP workspace

This commit is contained in:
2026-11-22 23:26:08 +08:00
commit 1bb0554608
159 changed files with 11103 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace App\Http;
final class Request extends \support\Request
{
private const LOOPBACK = ['127.0.0.1', '::1'];
public function clientAddress(): string
{
$peer = $this->getRemoteIp();
$forwarded = $this->header('x-real-ip', '');
if (!$this->fromTrustedProxy() || !filter_var($forwarded, FILTER_VALIDATE_IP)) {
return $peer;
}
return inet_ntop(inet_pton($forwarded));
}
private function fromTrustedProxy(): bool
{
$configured = getenv('LAYSITE_TRUSTED_PROXIES');
$trusted = $configured === false ? self::LOOPBACK : array_map('trim', explode(',', $configured));
return in_array($this->getRemoteIp(), $trusted, true);
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace App\Http;
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: getenv('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;
}
}