Compare commits
3
Commits
v1.0.0
..
bd1890c0dd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd1890c0dd | ||
|
|
584455c66d | ||
|
|
01ede89dcd |
@@ -0,0 +1,14 @@
|
||||
# 站点对外地址。上线时改为实际域名。
|
||||
LAYSITE_SITE_URL=http://127.0.0.1:8787
|
||||
# HTTPS 部署时取消注释。
|
||||
# LAYSITE_SECURE_COOKIES=1
|
||||
|
||||
# 有需要时覆盖默认值。相对路径以项目根目录为基准。
|
||||
# LAYSITE_LISTEN=http://127.0.0.1:8787
|
||||
# LAYSITE_WORKERS=2
|
||||
# LAYSITE_DB=storage/laysite.sqlite
|
||||
# LAYSITE_MEDIA_DIR=storage/media
|
||||
# LAYSITE_TRUSTED_PROXIES=127.0.0.1,::1
|
||||
|
||||
# 启用 MCP 时填写至少 32 字符的令牌。
|
||||
# LAYSITE_MCP_TOKEN=
|
||||
@@ -8,12 +8,15 @@
|
||||
|
||||
```sh
|
||||
composer install --no-dev
|
||||
(umask 077; cp .env.example .env)
|
||||
php bin/install.php
|
||||
php bin/admin.php editor@example.com
|
||||
php start.php start
|
||||
```
|
||||
|
||||
打开 `http://127.0.0.1:8787/admin`。重设管理员密码可用 `php bin/admin.php reset editor@example.com`。该操作会使该账户的旧会话失效。应用使用进程环境变量,可在 systemd 服务或启动脚本中设置。
|
||||
打开 `http://127.0.0.1:8787/admin`。重设管理员密码可用 `php bin/admin.php reset editor@example.com`,该账户的旧会话随之失效。
|
||||
|
||||
站点运行配置集中在项目根目录的 `.env`。本地开发可直接使用示例值,部署时将站点地址改为实际域名并按需启用其他选项。已有的 systemd 或启动脚本可继续设置进程环境变量,同名值优先生效。修改 `.env` 后重启 Webman。
|
||||
|
||||
| 环境变量 | 用途 |
|
||||
| --- | --- |
|
||||
@@ -25,7 +28,6 @@ php start.php start
|
||||
| `LAYSITE_SECURE_COOKIES` | 生产 HTTPS 设为 `1`。本机 HTTP 留空 |
|
||||
| `LAYSITE_TRUSTED_PROXIES` | 信任的反代 IP,默认 `127.0.0.1,::1` |
|
||||
| `LAYSITE_MCP_TOKEN` | MCP Bearer 密钥,至少 32 字符。未设置时端点关闭 |
|
||||
| `LAYSITE_OAUTH_*` | 会员页头选用的客户端密钥,按新建配置时填写的名称设置 |
|
||||
|
||||
## 页面与站点设计
|
||||
|
||||
@@ -37,18 +39,20 @@ php start.php start
|
||||
|
||||
### 会员页头
|
||||
|
||||
在「站点设计 → 页头」选择「会员导航」,启用用户区,并选择认证方式。将已配置的页头用作默认、或应用于要开放登录的页面。
|
||||
在「站点设计 → 页头」选择「会员导航」并勾选「用户区」,即可设置认证。将配置好的页头用作默认,或应用于需要登录的页面。
|
||||
|
||||
| 模式 | 填写内容 |
|
||||
| --- | --- |
|
||||
| OpenID Connect | Issuer、客户端 ID 和客户端密钥环境变量。LaySite 通过发现文档获取端点和签名公钥,使用 `openid profile email` 及附加范围 |
|
||||
| OAuth 2.0 + 用户资料 | 授权、令牌和用户资料三个 HTTPS 地址、客户端 ID、客户端密钥环境变量、权限范围及稳定的用户 ID 字段。名称和头像字段默认使用 `name`、`picture` |
|
||||
| OpenID Connect | Issuer、客户端 ID 和客户端密钥。LaySite 通过发现文档获取端点和签名公钥,使用 `openid profile email` 及附加范围 |
|
||||
| OAuth 2.0 + 用户资料 | 授权、令牌和用户资料三个 HTTPS 地址、客户端 ID、客户端密钥、权限范围及稳定的用户 ID 字段。名称和头像字段默认使用 `name`、`picture` |
|
||||
|
||||
在提供商中注册由站点域名拼接的回调 `https://example.com/account/callback`。密钥写入进程环境,配置页填写类似 `LAYSITE_OAUTH_MEMBER_SECRET` 的变量名。两个模式均使用授权码、state 和 PKCE S256,可按提供商要求选择 HTTP Basic 或表单客户端密钥。通过验证后,访客头像会链接到 `/account`。访客会话与管理员登录分开,退出用户中心时结束本地访客会话。
|
||||
在提供商中注册由站点域名拼接的回调 `https://example.com/account/callback`。两个模式均使用授权码、state 和 PKCE S256,可按提供商要求选择 HTTP Basic 或表单客户端密钥。通过验证后,访客头像会链接到 `/account`。访客会话与管理员登录分开,退出用户中心时结束本地访客会话。
|
||||
|
||||
每套会员页头的客户端密钥加密存入 SQLite。编辑现有配置时,密钥留空可保留已保存的值。更换身份提供商或客户端 ID 时需重新填写。加密密钥由程序生成并保存在数据库旁的 `.key` 文件,例如 `storage/laysite.sqlite.key`,权限为 `0600`。直接迁移 SQLite 文件时须同时迁移这个文件,并将文件所有者设为运行账户。
|
||||
|
||||
## MCP
|
||||
|
||||
`POST /mcp` 提供无状态 Streamable HTTP JSON-RPC。使用 `openssl rand -hex 32` 生成令牌,然后设置 `LAYSITE_MCP_TOKEN` 并重启 Webman。客户端使用 HTTPS 站点地址及 `Authorization: Bearer <TOKEN>`。
|
||||
`POST /mcp` 提供无状态 Streamable HTTP JSON-RPC。使用 `openssl rand -hex 32` 生成令牌,在 `.env` 中设置 `LAYSITE_MCP_TOKEN`,然后重启 Webman。客户端使用 HTTPS 站点地址及 `Authorization: Bearer <TOKEN>`。
|
||||
|
||||
支持 MCP `2025-11-25`、`2025-06-18`、`2025-03-26`。客户端配置示例(字段名称按客户端调整):
|
||||
|
||||
@@ -75,7 +79,7 @@ Agent 可以编辑草稿,管理员在画布里检查、细改及发布。草
|
||||
|
||||
## 站点备份与更新
|
||||
|
||||
「站点设计 → 站点备份」支持导出和确认后覆盖导入。备份包是包含版本化 JSON 清单和校验和的 TAR,包含页面、区块、文章、站点设置、布局、配色和媒体数据。管理员密码、运行环境密钥和登录会话由目标安装独立管理。备份存放在站点公开目录外。
|
||||
「站点设计 → 站点备份」支持导出和确认后覆盖导入。备份包是包含版本化 JSON 清单和校验和的 TAR,包含页面、区块、文章、站点设置、布局、配色和媒体数据。管理员密码、OAuth 客户端密钥、运行环境密钥和登录会话由目标安装独立管理。导入到原站点时,身份提供商配置一致的同一套页头会保留客户端密钥。导入到新站点后,在对应会员页头重新填写。备份存放在站点公开目录外。
|
||||
|
||||
当前导出格式为 v2,导入兼容 v1 的基础内容备份并补齐空的设计库。未来格式会保留迁移入口,遇到较新的不兼容格式时提示升级。上传大小受 Webman 与外层代理限制,较大站点可使用 CLI。
|
||||
|
||||
@@ -84,16 +88,18 @@ php bin/backup.php export /srv/backups/laysite-2026-11.tar
|
||||
php bin/backup.php import /srv/backups/laysite-2026-11.tar --replace
|
||||
```
|
||||
|
||||
使用 Git 标签选择更新版本。更新命令先备份,再检出所选版本、安装锁定依赖并运行 SQLite 初始化或迁移。更新时暂停 Webman,更新结束后用原进程环境重新启动。保持源代码工作区干净,并将备份放到部署路径之外。
|
||||
使用 Git 标签选择更新版本。更新命令先备份,再检出所选版本、安装锁定依赖并运行 SQLite 初始化或迁移。更新时暂停 Webman,更新结束后重新启动。保持源代码工作区干净,并将备份放到部署路径之外。
|
||||
|
||||
```sh
|
||||
bin/update.sh check
|
||||
bin/update.sh v1.0.0 /srv/backups/pre-update.tar
|
||||
bin/update.sh v1.1.0 /srv/backups/pre-update.tar
|
||||
```
|
||||
|
||||
从 v1.0.0 升级时,让执行迁移的进程能读到原先填写的 `LAYSITE_OAUTH_*` 值。升级会将这些密钥转存到 SQLite,成功后即可移除旧变量。若迁移时缺少某个旧值,在对应会员页头补填密钥即可启用登录。
|
||||
|
||||
## 生产反代
|
||||
|
||||
配置 `LAYSITE_SITE_URL=https://example.com` 和 `LAYSITE_SECURE_COOKIES=1`。下列示例假定代理和 Webman 在同一主机。代理应以实际访客来源覆盖 `X-Real-IP`,并将项目文件、数据库和媒体存储保持在公开根目录之外。
|
||||
在 `.env` 配置 `LAYSITE_SITE_URL=https://example.com` 和 `LAYSITE_SECURE_COOKIES=1`。下列示例假定代理和 Webman 在同一主机。代理应以实际访客来源覆盖 `X-Real-IP`,并将项目文件、数据库和媒体存储保持在公开根目录之外。
|
||||
|
||||
### Nginx
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Config;
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
final class Environment
|
||||
{
|
||||
private static ?array $values = null;
|
||||
|
||||
public static function load(): void
|
||||
{
|
||||
if (self::$values !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = Dotenv::createArrayBacked(dirname(__DIR__, 2))->safeLoad();
|
||||
self::$values = getenv() + $file;
|
||||
}
|
||||
|
||||
public static function get(string $name): string|false
|
||||
{
|
||||
self::load();
|
||||
|
||||
return self::$values[$name] ?? false;
|
||||
}
|
||||
|
||||
public static function path(string $name, string $default): string
|
||||
{
|
||||
$path = self::get($name) ?: $default;
|
||||
|
||||
return str_starts_with($path, '/') ? $path : dirname(__DIR__, 2) . '/' . $path;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ use RuntimeException;
|
||||
|
||||
final class Assets
|
||||
{
|
||||
public const DEFAULT_ICON = '/assets/system/laysite-mark.webp';
|
||||
|
||||
public static function cdn(string $value): string
|
||||
{
|
||||
$value = rtrim(trim($value), '/');
|
||||
|
||||
@@ -4,26 +4,32 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use App\Config\Environment;
|
||||
use PDO;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
final class Database
|
||||
{
|
||||
private const SCHEMA_VERSION = 1;
|
||||
private const SCHEMA_VERSION = 2;
|
||||
// Avoid reusing a deleted ID that may still be open in an editing form.
|
||||
public const NEXT_ARTICLE_ID = 'MAX(COALESCE((SELECT MAX(id) FROM articles), 0),
|
||||
COALESCE((SELECT MAX(article_id) FROM article_deletions), 0)) + 1';
|
||||
|
||||
private static ?PDO $connection = null;
|
||||
|
||||
public static function path(): string
|
||||
{
|
||||
return Environment::path('LAYSITE_DB', 'storage/laysite.sqlite');
|
||||
}
|
||||
|
||||
public static function connect(): PDO
|
||||
{
|
||||
if (self::$connection !== null) {
|
||||
return self::$connection;
|
||||
}
|
||||
|
||||
$path = getenv('LAYSITE_DB') ?: dirname(__DIR__, 2) . '/storage/laysite.sqlite';
|
||||
$path = self::path();
|
||||
if (!is_dir(dirname($path)) && !mkdir(dirname($path), 0750, true) && !is_dir(dirname($path))) {
|
||||
throw new RuntimeException('无法创建 SQLite 存放目录。');
|
||||
}
|
||||
@@ -65,6 +71,9 @@ final class Database
|
||||
foreach (Repository::CATEGORIES as $slug => $name) {
|
||||
$category->execute([$slug, $name]);
|
||||
}
|
||||
if ($version < 2) {
|
||||
OAuthCredentials::migrateLegacy($pdo);
|
||||
}
|
||||
if ($version < self::SCHEMA_VERSION) {
|
||||
$pdo->exec('PRAGMA user_version = ' . self::SCHEMA_VERSION);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
final class DesignFieldError extends RuntimeException
|
||||
{
|
||||
public function __construct(public readonly string $field, string $message)
|
||||
{
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,9 @@ final class DesignLibrary
|
||||
if ($id < 1) {
|
||||
return null;
|
||||
}
|
||||
$query = Database::connect()->prepare('SELECT * FROM design_presets WHERE id = ? AND kind = ?');
|
||||
$query = Database::connect()->prepare('SELECT design_presets.*, credentials.revision AS credential_revision
|
||||
FROM design_presets LEFT JOIN layout_oauth_credentials credentials ON credentials.layout_id = design_presets.id
|
||||
WHERE design_presets.id = ? AND kind = ?');
|
||||
$query->execute([$id, $kind]);
|
||||
$row = $query->fetch();
|
||||
if (!$row) {
|
||||
@@ -91,14 +93,14 @@ final class DesignLibrary
|
||||
public static function normalize(string $kind, string $preset, array $data): array
|
||||
{
|
||||
if (!isset(self::PRESETS[$kind][$preset])) {
|
||||
throw new RuntimeException('请选择可用的组件模板。');
|
||||
throw new DesignFieldError('preset', '请选择可用的组件模板。');
|
||||
}
|
||||
if ($kind === 'palette') {
|
||||
$colors = [];
|
||||
foreach (self::COLORS as $key => [, $default]) {
|
||||
$color = $data[$key] ?? $default;
|
||||
if (!is_string($color) || !preg_match('/^#[\da-f]{6}$/iD', $color)) {
|
||||
throw new RuntimeException('颜色必须使用六位十六进制表示。');
|
||||
throw new DesignFieldError($key, '颜色必须使用六位十六进制表示。');
|
||||
}
|
||||
$colors[$key] = strtolower($color);
|
||||
}
|
||||
@@ -108,23 +110,27 @@ final class DesignLibrary
|
||||
|
||||
$clean = self::defaults($kind);
|
||||
foreach (['brand' => 100, 'text' => 1200, 'legal' => 300, 'logo' => 1000] as $field => $limit) {
|
||||
$clean[$field] = self::string($data[$field] ?? '', $limit);
|
||||
$clean[$field] = self::string($data[$field] ?? '', $limit, $field);
|
||||
}
|
||||
if ($clean['logo'] !== '' && !Html::url($clean['logo'], true)) {
|
||||
throw new RuntimeException('请检查站点标识地址。');
|
||||
throw new DesignFieldError('logo', '请检查站点标识地址。');
|
||||
}
|
||||
$components = $data['components'] ?? $clean['components'];
|
||||
if (!is_array($components) || !array_is_list($components)) {
|
||||
throw new RuntimeException('组件顺序无效。');
|
||||
throw new DesignFieldError('components', '组件顺序无效。');
|
||||
}
|
||||
foreach ($components as $component) {
|
||||
if (!is_string($component) || !isset(self::COMPONENTS[$kind][$component])) {
|
||||
throw new RuntimeException('布局包含未知组件。');
|
||||
throw new DesignFieldError('components', '布局包含未知组件。');
|
||||
}
|
||||
}
|
||||
$clean['components'] = array_values(array_unique($components));
|
||||
$clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20);
|
||||
try {
|
||||
$clean['action'] = Buttons::validate($data['action'] ?? []);
|
||||
} catch (RuntimeException $error) {
|
||||
throw new DesignFieldError('action', $error->getMessage());
|
||||
}
|
||||
$clean['provider'] = $kind === 'header' && $preset === 'member'
|
||||
? self::provider($data['provider'] ?? []) : [];
|
||||
|
||||
@@ -138,41 +144,67 @@ final class DesignLibrary
|
||||
return [];
|
||||
}
|
||||
if (!in_array($mode, ['oidc', 'oauth2'], true)) {
|
||||
throw new RuntimeException('请选择 OIDC 或 OAuth 2.0。');
|
||||
throw new DesignFieldError('provider_mode', '请选择 OIDC 或 OAuth 2.0。');
|
||||
}
|
||||
$result = ['mode' => $mode];
|
||||
foreach (['client_id', 'secret_env', 'scope', 'issuer', 'authorization', 'token', 'userinfo', 'subject_field', 'name_field', 'avatar_field', 'token_auth'] as $field) {
|
||||
$result[$field] = self::string($data[$field] ?? '', 600);
|
||||
foreach (['client_id', 'scope', 'issuer', 'authorization', 'token', 'userinfo', 'subject_field', 'name_field', 'avatar_field', 'token_auth'] as $field) {
|
||||
$result[$field] = self::string($data[$field] ?? '', 600, 'provider_' . $field);
|
||||
}
|
||||
if (!in_array($result['token_auth'], ['', 'client_secret_basic', 'client_secret_post'], true)) {
|
||||
throw new RuntimeException('令牌端点认证方式无效。');
|
||||
throw new DesignFieldError('provider_token_auth', '令牌端点认证方式无效。');
|
||||
}
|
||||
if ($result['client_id'] === '' || !preg_match('/^LAYSITE_OAUTH_[A-Z0-9_]{1,45}$/D', $result['secret_env'])) {
|
||||
throw new RuntimeException('填写客户端 ID 和以 LAYSITE_OAUTH_ 开头的客户端密钥环境变量名。');
|
||||
if ($result['client_id'] === '') {
|
||||
throw new DesignFieldError('provider_client_id', '请填写客户端 ID。');
|
||||
}
|
||||
foreach ($mode === 'oidc' ? ['issuer'] : ['authorization', 'token', 'userinfo'] as $field) {
|
||||
$url = parse_url($result[$field]);
|
||||
if (!$url || ($url['scheme'] ?? '') !== 'https' || empty($url['host'])
|
||||
|| isset($url['user']) || isset($url['pass']) || isset($url['fragment']) || ($field === 'issuer' && isset($url['query'])) || !Html::url($result[$field], true)) {
|
||||
throw new RuntimeException('认证端点必须使用完整的 HTTPS 地址。');
|
||||
throw new DesignFieldError('provider_' . $field, '认证端点必须使用完整的 HTTPS 地址。');
|
||||
}
|
||||
}
|
||||
if ($mode === 'oauth2' && $result['subject_field'] === '') {
|
||||
throw new RuntimeException('OAuth 2.0 用户资料需要指定稳定的用户 ID 字段。');
|
||||
throw new DesignFieldError('provider_subject_field', 'OAuth 2.0 用户资料需要指定稳定的用户 ID 字段。');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function save(string $kind, ?int $id, string $name, string $preset, array $data, int $version, bool $default): int
|
||||
public static function hasAccount(string $preset, array $components): bool
|
||||
{
|
||||
$name = self::string($name, 100);
|
||||
if ($name === '') {
|
||||
throw new RuntimeException('请填写配置名称。');
|
||||
return $preset === 'member' && in_array('account', $components, true);
|
||||
}
|
||||
$payload = Database::json(self::normalize($kind, $preset, $data));
|
||||
|
||||
return Database::write(function (PDO $pdo) use ($kind, $id, $name, $preset, $payload, $version, $default): int {
|
||||
public static function identity(?array $layout): ?string
|
||||
{
|
||||
if (empty($layout['credential_revision']) || empty($layout['payload']['provider'])
|
||||
|| !self::hasAccount($layout['preset'], $layout['payload']['components'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return hash('sha256', Database::json([$layout['payload']['provider'], $layout['credential_revision']]));
|
||||
}
|
||||
|
||||
public static function save(string $kind, ?int $id, string $name, string $preset, array $data, int $version, bool $default, string $secret = ''): int
|
||||
{
|
||||
$name = self::string($name, 100, 'name');
|
||||
if ($name === '') {
|
||||
throw new DesignFieldError('name', '请填写配置名称。');
|
||||
}
|
||||
$clean = self::normalize($kind, $preset, $data);
|
||||
$payload = Database::json($clean);
|
||||
$provider = $clean['provider'] ?? [];
|
||||
$active = $provider !== [] && self::hasAccount($preset, $clean['components']);
|
||||
|
||||
return Database::write(function (PDO $pdo) use ($kind, $id, $name, $preset, $payload, $version, $default, $provider, $active, $secret): int {
|
||||
if ($active && $secret === '') {
|
||||
$saved = $id === null ? null : self::find($id, $kind);
|
||||
$fields = array_flip(['mode', 'issuer', 'authorization', 'token', 'userinfo', 'client_id']);
|
||||
if (empty($saved['credential_revision'])
|
||||
|| array_intersect_key($provider, $fields) !== array_intersect_key($saved['payload']['provider'], $fields)) {
|
||||
throw new DesignFieldError('provider_secret', '启用登录或变更身份提供商时,请填写客户端密钥。');
|
||||
}
|
||||
}
|
||||
if ($id === null) {
|
||||
$pdo->prepare('INSERT INTO design_presets (kind, name, preset, payload) VALUES (?, ?, ?, ?)')->execute([$kind, $name, $preset, $payload]);
|
||||
$id = (int) $pdo->lastInsertId();
|
||||
@@ -183,6 +215,13 @@ final class DesignLibrary
|
||||
throw new RuntimeException('配置已更新,请重新打开后再保存。');
|
||||
}
|
||||
}
|
||||
if ($kind === 'header') {
|
||||
if ($provider === []) {
|
||||
$pdo->prepare('DELETE FROM layout_oauth_credentials WHERE layout_id = ?')->execute([$id]);
|
||||
} elseif ($active && $secret !== '') {
|
||||
OAuthCredentials::store($pdo, $id, $secret);
|
||||
}
|
||||
}
|
||||
if ($kind !== 'palette') {
|
||||
$site = json_decode($pdo->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
if ($default) {
|
||||
@@ -197,10 +236,10 @@ final class DesignLibrary
|
||||
});
|
||||
}
|
||||
|
||||
private static function string(mixed $value, int $limit): string
|
||||
private static function string(mixed $value, int $limit, string $field): string
|
||||
{
|
||||
if (!is_string($value) || !mb_check_encoding($value, 'UTF-8') || mb_strlen($value) > $limit) {
|
||||
throw new RuntimeException('配置包含无效或过长的文字。');
|
||||
throw new DesignFieldError($field, '配置包含无效或过长的文字。');
|
||||
}
|
||||
|
||||
return trim($value);
|
||||
|
||||
@@ -19,12 +19,8 @@ final class IdentityProvider
|
||||
private readonly Client $http;
|
||||
private array $oidc = [];
|
||||
|
||||
public function __construct(private readonly array $config)
|
||||
public function __construct(private readonly array $config, string $secret)
|
||||
{
|
||||
$secret = getenv($config['secret_env']);
|
||||
if (!is_string($secret) || $secret === '') {
|
||||
throw new RuntimeException('身份服务的客户端密钥尚未配置。');
|
||||
}
|
||||
$this->http = new Client(['timeout' => 8, 'connect_timeout' => 4, 'allow_redirects' => false]);
|
||||
$scope = preg_split('/\s+/', trim($config['scope']), -1, PREG_SPLIT_NO_EMPTY);
|
||||
$authorization = $config['authorization'];
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use App\Config\Environment;
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use DOMXPath;
|
||||
@@ -84,7 +85,7 @@ final class Media
|
||||
|
||||
public static function directory(): string
|
||||
{
|
||||
return rtrim(getenv('LAYSITE_MEDIA_DIR') ?: dirname(__DIR__, 2) . '/storage/media', '/');
|
||||
return rtrim(Environment::path('LAYSITE_MEDIA_DIR', 'storage/media'), '/');
|
||||
}
|
||||
|
||||
public static function validateBackup(string $path, string $name, string $mime, int $size): void
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use App\Config\Environment;
|
||||
use PDO;
|
||||
use RuntimeException;
|
||||
|
||||
final class OAuthCredentials
|
||||
{
|
||||
private const CIPHER = 'aes-256-gcm';
|
||||
private const KEY_BYTES = 32;
|
||||
private const NONCE_BYTES = 12;
|
||||
private const TAG_BYTES = 16;
|
||||
|
||||
public static function store(PDO $pdo, int $layout, string $secret): void
|
||||
{
|
||||
if ($secret === '' || strlen($secret) > 4096 || str_contains($secret, "\0")) {
|
||||
throw new DesignFieldError('provider_secret', '客户端密钥为空或格式无效。');
|
||||
}
|
||||
$revision = bin2hex(random_bytes(16));
|
||||
$nonce = random_bytes(self::NONCE_BYTES);
|
||||
$ciphertext = openssl_encrypt($secret, self::CIPHER, self::key(create: true), OPENSSL_RAW_DATA, $nonce,
|
||||
$tag, self::context($layout, $revision), self::TAG_BYTES);
|
||||
if ($ciphertext === false) {
|
||||
throw new RuntimeException('无法加密客户端密钥。');
|
||||
}
|
||||
$pdo->prepare('INSERT INTO layout_oauth_credentials (layout_id, revision, encrypted_secret) VALUES (?, ?, ?)
|
||||
ON CONFLICT (layout_id) DO UPDATE SET revision = excluded.revision, encrypted_secret = excluded.encrypted_secret')
|
||||
->execute([$layout, $revision, base64_encode($nonce . $tag . $ciphertext)]);
|
||||
}
|
||||
|
||||
public static function read(int $layout, string $revision): string
|
||||
{
|
||||
$query = Database::connect()->prepare('SELECT encrypted_secret FROM layout_oauth_credentials WHERE layout_id = ? AND revision = ?');
|
||||
$query->execute([$layout, $revision]);
|
||||
$value = $query->fetchColumn();
|
||||
$encrypted = is_string($value) ? base64_decode($value, true) : false;
|
||||
if ($encrypted === false || strlen($encrypted) <= self::NONCE_BYTES + self::TAG_BYTES) {
|
||||
throw new RuntimeException('客户端密钥尚未配置或已更新。');
|
||||
}
|
||||
$secret = openssl_decrypt(substr($encrypted, self::NONCE_BYTES + self::TAG_BYTES), self::CIPHER, self::key(),
|
||||
OPENSSL_RAW_DATA, substr($encrypted, 0, self::NONCE_BYTES), substr($encrypted, self::NONCE_BYTES, self::TAG_BYTES),
|
||||
self::context($layout, $revision));
|
||||
if ($secret === false) {
|
||||
throw new RuntimeException('无法解密客户端密钥。');
|
||||
}
|
||||
|
||||
return $secret;
|
||||
}
|
||||
|
||||
public static function migrateLegacy(PDO $pdo): void
|
||||
{
|
||||
$layouts = $pdo->query("SELECT id, payload FROM design_presets WHERE kind = 'header' AND preset = 'member'")->fetchAll();
|
||||
$update = $pdo->prepare('UPDATE design_presets SET payload = ?, version = version + 1 WHERE id = ?');
|
||||
foreach ($layouts as $layout) {
|
||||
$payload = json_decode($layout['payload'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$variable = $payload['provider']['secret_env'] ?? null;
|
||||
if (!is_string($variable)) {
|
||||
continue;
|
||||
}
|
||||
unset($payload['provider']['secret_env']);
|
||||
if (preg_match('/^LAYSITE_OAUTH_[A-Z0-9_]{1,45}$/D', $variable)) {
|
||||
$secret = Environment::get($variable);
|
||||
if (is_string($secret) && $secret !== '') {
|
||||
self::store($pdo, (int) $layout['id'], $secret);
|
||||
}
|
||||
}
|
||||
$update->execute([Database::json($payload), $layout['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function context(int $layout, string $revision): string
|
||||
{
|
||||
return 'laysite-oauth:' . $layout . ':' . $revision;
|
||||
}
|
||||
|
||||
private static function key(bool $create = false): string
|
||||
{
|
||||
$path = Database::path() . '.key';
|
||||
if (is_link($path)) {
|
||||
throw new RuntimeException('密钥文件不能使用符号链接。');
|
||||
}
|
||||
$mask = umask(0077);
|
||||
try {
|
||||
$file = is_file($path) || $create ? @fopen($path, $create ? 'c+b' : 'rb') : false;
|
||||
} finally {
|
||||
umask($mask);
|
||||
}
|
||||
if ($file === false) {
|
||||
throw new RuntimeException('无法打开站点密钥文件。');
|
||||
}
|
||||
try {
|
||||
if (!flock($file, $create ? LOCK_EX : LOCK_SH) || (fstat($file)['mode'] & 0077) !== 0) {
|
||||
throw new RuntimeException('站点密钥文件需能上锁,并且只能由运行用户访问。');
|
||||
}
|
||||
$key = stream_get_contents($file, self::KEY_BYTES + 1);
|
||||
if ($create && $key === '') {
|
||||
$key = random_bytes(self::KEY_BYTES);
|
||||
if (fwrite($file, $key) !== self::KEY_BYTES || !fflush($file)) {
|
||||
ftruncate($file, 0);
|
||||
throw new RuntimeException('无法写入站点密钥文件。');
|
||||
}
|
||||
}
|
||||
if (!is_string($key) || strlen($key) !== self::KEY_BYTES) {
|
||||
throw new RuntimeException('站点密钥文件格式无效。');
|
||||
}
|
||||
|
||||
return $key;
|
||||
} finally {
|
||||
fclose($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use RuntimeException;
|
||||
|
||||
final class PageDraft
|
||||
{
|
||||
public const RESERVED = ['admin', 'assets', 'home', 'account', 'mcp', 'palette', 'favicon'];
|
||||
public const RESERVED = ['admin', 'assets', 'home', 'account', 'mcp', 'palette'];
|
||||
|
||||
public static function slug(mixed $value, array $reserved = self::RESERVED): string
|
||||
{
|
||||
|
||||
@@ -179,7 +179,7 @@ final class SiteBackup
|
||||
}
|
||||
$tables['site_settings'] = [['id' => 1, 'payload' => Database::json($site)]];
|
||||
foreach ($tables['pages'] as &$row) {
|
||||
PageDraft::slug($row['slug'] ?? null, ['admin', 'assets', 'account', 'mcp', 'palette', 'favicon']);
|
||||
PageDraft::slug($row['slug'] ?? null, array_diff(PageDraft::RESERVED, ['home']));
|
||||
self::validateAssetUrl($row['image'] ?? '', true);
|
||||
$row['actions'] = Database::json(Buttons::validate(self::decode($row['actions'] ?? '[]')));
|
||||
$row['quicklinks'] = Database::json(Buttons::validate(self::decode($row['quicklinks'] ?? '[]'), 20));
|
||||
@@ -227,6 +227,9 @@ final class SiteBackup
|
||||
|
||||
private static function replaceTables(PDO $pdo, array $tables): void
|
||||
{
|
||||
$credentials = array_column($pdo->query("SELECT layout_id, revision, encrypted_secret, payload
|
||||
FROM layout_oauth_credentials JOIN design_presets ON id = layout_id
|
||||
WHERE kind = 'header' AND preset = 'member'")->fetchAll(), null, 'layout_id');
|
||||
$revisions = [];
|
||||
foreach (self::TABLES as $table) {
|
||||
$columns = array_column($pdo->query('PRAGMA table_info(' . $table . ')')->fetchAll(), 'name');
|
||||
@@ -250,6 +253,18 @@ final class SiteBackup
|
||||
$query->execute(array_values($row));
|
||||
}
|
||||
}
|
||||
|
||||
$insert = $pdo->prepare('INSERT INTO layout_oauth_credentials (layout_id, revision, encrypted_secret) VALUES (?, ?, ?)');
|
||||
foreach ($tables['design_presets'] as $layout) {
|
||||
$saved = $credentials[$layout['id']] ?? null;
|
||||
if (!$saved || $layout['kind'] !== 'header' || $layout['preset'] !== 'member') {
|
||||
continue;
|
||||
}
|
||||
$provider = self::decode($layout['payload'])['provider'] ?? [];
|
||||
if ($provider && $provider === (self::decode($saved['payload'])['provider'] ?? [])) {
|
||||
$insert->execute([$layout['id'], $saved['revision'], $saved['encrypted_secret']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function selection(array $designs, string $kind, mixed $id): ?int
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use App\Config\Environment;
|
||||
use App\Http\VisitorSession;
|
||||
use support\Response;
|
||||
|
||||
@@ -19,13 +20,14 @@ final class View
|
||||
$data['header'] = DesignLibrary::layout('header', $data['site'], $page);
|
||||
$data['footer'] = DesignLibrary::layout('footer', $data['site'], $page);
|
||||
$data['visitor'] = null;
|
||||
$provider = $data['header']['payload']['provider'];
|
||||
$personalized = $provider !== [] && in_array('account', $data['header']['payload']['components'], true)
|
||||
$identity = DesignLibrary::identity($data['header']);
|
||||
$data['member'] = $identity !== null;
|
||||
$personalized = $data['member']
|
||||
&& ($page['visibility']['header'] ?? true) && empty($data['previewMode']);
|
||||
if ($personalized) {
|
||||
$profile = VisitorSession::profile(request());
|
||||
if (($profile['layout'] ?? null) === $data['header']['id']
|
||||
&& ($profile['config'] ?? null) === hash('sha256', json_encode($provider, JSON_THROW_ON_ERROR))) {
|
||||
&& ($profile['config'] ?? null) === $identity) {
|
||||
$data['visitor'] = $profile;
|
||||
}
|
||||
}
|
||||
@@ -79,7 +81,7 @@ final class View
|
||||
|
||||
public static function absolute(string $path): string
|
||||
{
|
||||
return rtrim(getenv('LAYSITE_SITE_URL') ?: 'http://127.0.0.1:8787', '/') . $path;
|
||||
return rtrim(Environment::get('LAYSITE_SITE_URL') ?: 'http://127.0.0.1:8787', '/') . $path;
|
||||
}
|
||||
|
||||
public static function date(?string $value, string $format = 'Y年n月j日'): string
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\IdentityProvider;
|
||||
use App\Content\OAuthCredentials;
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
use App\Http\VisitorSession;
|
||||
@@ -17,17 +18,18 @@ final class AccountController
|
||||
{
|
||||
public function login(Request $request, string $id): Response
|
||||
{
|
||||
$config = $this->provider((int) $id);
|
||||
if ($config === []) {
|
||||
$layout = DesignLibrary::find((int) $id, 'header');
|
||||
$identity = DesignLibrary::identity($layout);
|
||||
if ($identity === null) {
|
||||
return $this->page($request, '该用户区尚未配置登录。', 404);
|
||||
}
|
||||
try {
|
||||
$provider = new IdentityProvider($config);
|
||||
$provider = new IdentityProvider($layout['payload']['provider'], OAuthCredentials::read((int) $id, $layout['credential_revision']));
|
||||
$nonce = bin2hex(random_bytes(32));
|
||||
$url = $provider->authorization($nonce);
|
||||
$session = VisitorSession::create();
|
||||
$session->set('flow', [
|
||||
'layout' => (int) $id, 'config' => $this->fingerprint($config), 'nonce' => $nonce,
|
||||
'layout' => (int) $id, 'config' => $identity, 'nonce' => $nonce,
|
||||
'state' => $provider->client->getState(), 'proof' => $provider->client->getPkceCode(), 'expires' => time() + 600,
|
||||
]);
|
||||
$session->save();
|
||||
@@ -51,11 +53,12 @@ final class AccountController
|
||||
$session->flush();
|
||||
$session->save();
|
||||
try {
|
||||
$config = $this->provider($flow['layout']);
|
||||
if (!$config || $this->fingerprint($config) !== $flow['config']) {
|
||||
$layout = DesignLibrary::find($flow['layout'], 'header');
|
||||
if (DesignLibrary::identity($layout) !== $flow['config']) {
|
||||
return $this->page($request, '登录配置已变更,请重新登录。', 409);
|
||||
}
|
||||
$profile = (new IdentityProvider($config))->profile($code, $flow['proof'], $flow['nonce']);
|
||||
$secret = OAuthCredentials::read($flow['layout'], $layout['credential_revision']);
|
||||
$profile = (new IdentityProvider($layout['payload']['provider'], $secret))->profile($code, $flow['proof'], $flow['nonce']);
|
||||
$current = VisitorSession::create();
|
||||
$current->set('profile', $profile + [
|
||||
'layout' => $flow['layout'], 'config' => $flow['config'], 'expires' => time() + 28800, 'logout' => bin2hex(random_bytes(32)),
|
||||
@@ -91,20 +94,17 @@ final class AccountController
|
||||
{
|
||||
return View::render('account', [
|
||||
'site' => (new Repository())->site(), 'title' => '用户中心', 'description' => '', 'path' => '/account',
|
||||
'error' => $error, 'profile' => VisitorSession::profile($request), 'noindex' => true,
|
||||
'error' => $error, 'profile' => $this->profile($request), 'noindex' => true,
|
||||
], $status)->withHeader('Cache-Control', 'private, no-store');
|
||||
}
|
||||
|
||||
private function provider(int $id): array
|
||||
private function profile(Request $request): ?array
|
||||
{
|
||||
$row = DesignLibrary::find($id, 'header');
|
||||
|
||||
return ($row['preset'] ?? '') === 'member' && in_array('account', $row['payload']['components'], true)
|
||||
? $row['payload']['provider'] : [];
|
||||
$profile = VisitorSession::profile($request);
|
||||
if ($profile && DesignLibrary::identity(DesignLibrary::find($profile['layout'], 'header')) === $profile['config']) {
|
||||
return $profile;
|
||||
}
|
||||
|
||||
private function fingerprint(array $config): string
|
||||
{
|
||||
return hash('sha256', json_encode($config, JSON_THROW_ON_ERROR));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,6 +648,7 @@ class AdminController
|
||||
if ($request->isAjax() && $status >= 400) {
|
||||
return $this->json([
|
||||
'message' => $data['error'] ?? $data['title'],
|
||||
...(!empty($data['field']) ? ['field' => $data['field']] : []),
|
||||
...($status === 403 ? ['csrf' => $token] : []),
|
||||
], $status);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Assets;
|
||||
use App\Content\Buttons;
|
||||
use App\Content\DesignFieldError;
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
@@ -40,11 +40,17 @@ final class DesignController extends AdminController
|
||||
return $this->error($request, '找不到这项设计配置。', 404);
|
||||
}
|
||||
$error = '';
|
||||
$field = '';
|
||||
$secret = '';
|
||||
$links = SiteDesign::linkText($item['payload']['links'] ?? []);
|
||||
$default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id;
|
||||
if ($request->method() === 'POST') {
|
||||
try {
|
||||
$savedProvider = $item['payload']['provider'] ?? [];
|
||||
$item['name'] = $this->input($request, 'name');
|
||||
$item['preset'] = $this->input($request, 'preset');
|
||||
$item['version'] = $this->version($request);
|
||||
$default = $request->post('make_default') === '1';
|
||||
if ($kind === 'palette') {
|
||||
foreach (DesignLibrary::COLORS as $color => $definition) {
|
||||
$item['payload'][$color] = $this->input($request, $color);
|
||||
@@ -52,31 +58,47 @@ final class DesignController extends AdminController
|
||||
} else {
|
||||
$url = $this->input($request, 'action_url');
|
||||
$label = $this->input($request, 'action_label');
|
||||
$links = $this->input($request, 'links', trimValue: false);
|
||||
$item['payload'] = [
|
||||
'components' => $request->post('components', []),
|
||||
'brand' => $this->input($request, 'brand'), 'logo' => $this->input($request, 'logo'),
|
||||
'text' => $this->input($request, 'text'), 'legal' => $this->input($request, 'legal'),
|
||||
'links' => SiteDesign::parseLinks($this->input($request, 'links')),
|
||||
'action' => $url === '' && $label === '' ? [] : [[$url, $label, $this->input($request, 'action_style'), $request->post('action_blank') === '1']],
|
||||
'provider' => [],
|
||||
'provider' => $savedProvider,
|
||||
];
|
||||
foreach (['mode', 'issuer', 'authorization', 'token', 'userinfo', 'client_id', 'secret_env', 'scope', 'subject_field', 'name_field', 'avatar_field', 'token_auth'] as $field) {
|
||||
$components = $item['payload']['components'];
|
||||
if ($kind === 'header' && is_array($components) && DesignLibrary::hasAccount($item['preset'], $components)) {
|
||||
foreach (['mode', 'issuer', 'authorization', 'token', 'userinfo', 'client_id', 'scope', 'subject_field', 'name_field', 'avatar_field', 'token_auth'] as $field) {
|
||||
$item['payload']['provider'][$field] = $this->input($request, 'provider_' . $field);
|
||||
}
|
||||
$secret = $this->input($request, 'provider_secret', trimValue: false);
|
||||
}
|
||||
$default = $request->post('make_default') === '1';
|
||||
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $this->version($request), $default);
|
||||
try {
|
||||
$item['payload']['links'] = SiteDesign::parseLinks($links);
|
||||
} catch (RuntimeException $ex) {
|
||||
throw new DesignFieldError('links', $ex->getMessage());
|
||||
}
|
||||
}
|
||||
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $item['version'], $default, $secret);
|
||||
|
||||
return $this->success($request, "/admin/design/$kind/$id?saved=1");
|
||||
} catch (RuntimeException $ex) {
|
||||
$error = $this->validationMessage($ex);
|
||||
$item['payload'] = DesignLibrary::defaults($kind);
|
||||
$field = $ex instanceof DesignFieldError ? $ex->field : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($kind !== 'palette') {
|
||||
$components = $item['payload']['components'];
|
||||
$item['payload']['components'] = is_array($components) ? array_values(array_intersect(
|
||||
array_filter($components, 'is_string'), array_keys(DesignLibrary::COMPONENTS[$kind])
|
||||
)) : [];
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-design-edit', [
|
||||
'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default,
|
||||
'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'error' => $error, 'field' => $field, 'links' => $links, 'reenterSecret' => $error !== '' && $secret !== '',
|
||||
'saved' => $error === '' && $request->get('saved') === '1',
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
@@ -111,7 +133,7 @@ final class DesignController extends AdminController
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
public function preview(Request $request, string $kind, string $id): Response
|
||||
public function previewDesign(Request $request, string $kind, string $id): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Config\Environment;
|
||||
use App\Content\BlockTemplates;
|
||||
use App\Content\Database;
|
||||
use App\Content\DesignLibrary;
|
||||
@@ -26,7 +27,7 @@ final class McpController
|
||||
if ($origin !== null && $origin !== '' && $origin !== rtrim(View::absolute(''), '/')) {
|
||||
return new Response(403, ['Cache-Control' => 'no-store']);
|
||||
}
|
||||
$secret = getenv('LAYSITE_MCP_TOKEN');
|
||||
$secret = Environment::get('LAYSITE_MCP_TOKEN');
|
||||
$header = $request->header('authorization', '');
|
||||
if (!is_string($secret) || strlen($secret) < 32 || !is_string($header) || !hash_equals('Bearer ' . $secret, $header)) {
|
||||
return new Response(401, ['WWW-Authenticate' => 'Bearer realm="LaySite MCP"', 'Cache-Control' => 'no-store']);
|
||||
|
||||
@@ -23,23 +23,22 @@ final class MediaController
|
||||
'Content-Type' => $media['mime'], 'X-Content-Type-Options' => 'nosniff',
|
||||
'Content-Security-Policy' => "default-src 'none'; sandbox",
|
||||
'Cache-Control' => 'public, max-age=31536000, immutable',
|
||||
'Access-Control-Allow-Origin' => '*', 'Accept-Ranges' => 'bytes',
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
];
|
||||
$range = $request->header('range');
|
||||
if ($range === null) {
|
||||
return (new Response(200, $headers + ['Content-Length' => (string) $length]))->withFile($path);
|
||||
return (new Response(200, $headers))->withFile($path);
|
||||
}
|
||||
$unsatisfiable = $headers + ['Accept-Ranges' => 'bytes', 'Content-Range' => "bytes */$length"];
|
||||
if (!preg_match('/^bytes=(\d*)-(\d*)$/D', $range, $parts) || $parts[1] === '' && $parts[2] === '') {
|
||||
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
|
||||
return new Response(416, $unsatisfiable);
|
||||
}
|
||||
$start = $parts[1] === '' ? max(0, $length - (int) $parts[2]) : (int) $parts[1];
|
||||
$end = $parts[1] === '' || $parts[2] === '' ? $length - 1 : min($length - 1, (int) $parts[2]);
|
||||
if ($end < $start) {
|
||||
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
|
||||
return new Response(416, $unsatisfiable);
|
||||
}
|
||||
$count = $end - $start + 1;
|
||||
|
||||
return (new Response(206, $headers + ['Content-Length' => (string) $count, 'Content-Range' => "bytes $start-$end/$length"]))
|
||||
->withFile($path, $start, $count);
|
||||
return (new Response(206, $headers))->withFile($path, $start, $end - $start + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Assets;
|
||||
use App\Content\Html;
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
use FastRoute\Dispatcher;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Webman\Route;
|
||||
|
||||
final class SiteController
|
||||
{
|
||||
@@ -215,14 +218,21 @@ final class SiteController
|
||||
"User-agent: *\nAllow: /\nDisallow: /admin\nSitemap: " . View::absolute('/sitemap.xml') . "\n");
|
||||
}
|
||||
|
||||
public function favicon(Request $request): Response
|
||||
{
|
||||
return View::redirect(Assets::DEFAULT_ICON, 301);
|
||||
}
|
||||
|
||||
public function missing(Request $request): Response
|
||||
{
|
||||
$path = $request->path();
|
||||
if ($request->method() === 'GET' && strlen($path) > 1 && str_ends_with($path, '/')) {
|
||||
if (in_array($request->method(), ['GET', 'HEAD'], true) && strlen($path) > 1 && str_ends_with($path, '/')) {
|
||||
$normal = rtrim($path, '/');
|
||||
$entry = preg_match('~^/(?:admin|account)(?:/|$)~D', $normal)
|
||||
&& Route::dispatch($request->method(), $normal)[0] === Dispatcher::FOUND;
|
||||
$single = preg_match('~^/[a-z0-9-]+$~D', $normal);
|
||||
$known = $single && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published' && $normal !== '/home';
|
||||
if ($known || preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
||||
if ($entry || ($single && $normal !== '/home' && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published')
|
||||
|| preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
||||
$query = $request->queryString();
|
||||
|
||||
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Controller;
|
||||
use App\Content\BlockTemplates;
|
||||
use App\Content\Html;
|
||||
use App\Content\Media;
|
||||
use App\Content\PageDraft;
|
||||
use App\Content\PageTemplates;
|
||||
use App\Content\Repository;
|
||||
use App\Http\Request;
|
||||
@@ -29,7 +30,7 @@ final class StudioController extends AdminController
|
||||
$data['name'] = $this->input($request, 'name');
|
||||
$data['slug'] = $this->input($request, 'slug');
|
||||
try {
|
||||
if (!$this->slug($data['slug']) || in_array($data['slug'], ['admin', 'assets', 'home', 'account', 'mcp', 'palette', 'favicon'], true)
|
||||
if (!$this->slug($data['slug']) || in_array($data['slug'], PageDraft::RESERVED, true)
|
||||
|| $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||
throw new RuntimeException('请填写页面名称及可用的网址标识。');
|
||||
}
|
||||
|
||||
@@ -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('LAYSITE_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);
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Config\Environment;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Workerman\Protocols\Http\Session;
|
||||
@@ -26,7 +27,7 @@ final class VisitorSession
|
||||
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');
|
||||
secure: Environment::get('LAYSITE_SECURE_COOKIES') === '1', httpOnly: true, sameSite: 'Lax');
|
||||
}
|
||||
|
||||
public static function profile(?Request $request): ?array
|
||||
|
||||
@@ -1,81 +1,100 @@
|
||||
<?php
|
||||
use App\Content\Buttons;
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$data = $item['payload'];
|
||||
$action = $data['action'][0] ?? [];
|
||||
$provider = $data['provider'] ?? [];
|
||||
$errorId = static fn (string $name): string => 'design-error-' . View::escape($name);
|
||||
$describe = static fn (string $name): string => ' aria-describedby="' . $errorId($name) . '"'
|
||||
. ($field === $name ? ' aria-invalid="true"' : '');
|
||||
$fieldError = static function (string $name) use ($errorId, $field, $error, $e): void {
|
||||
$invalid = $field === $name;
|
||||
?>
|
||||
<small class="design-field-error" id="<?= $errorId($name) ?>" data-field-error="<?= $e($name) ?>" role="alert" tabindex="-1"<?= $invalid ? '' : ' hidden' ?>><?= $invalid ? $e($error) : '' ?></small>
|
||||
<?php
|
||||
};
|
||||
?>
|
||||
<a class="back-link" href="/admin/design">返回站点设计</a>
|
||||
<header class="admin-heading">
|
||||
<h1><?= $e(['header' => '页头组件', 'footer' => '页脚组件', 'palette' => '配色方案'][$kind]) ?></h1>
|
||||
<?php if ($key !== 'new'): ?><a class="button button-outline" href="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>/preview" target="_blank" rel="noopener noreferrer">预览已保存的配置</a><?php endif ?>
|
||||
</header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<?= View::fragment('admin-feedback', ['error' => $field === '' ? $error : '', 'saved' => $saved]) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
|
||||
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required></label>
|
||||
<label>布局模板<select name="preset" data-layout-preset>
|
||||
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
|
||||
<label>布局模板<select name="preset" data-layout-preset<?= $describe('preset') ?>>
|
||||
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
|
||||
<option value="<?= $e($preset) ?>" <?= $preset === $item['preset'] ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
</select><?php $fieldError('preset'); ?></label>
|
||||
<?php if ($kind === 'palette'): ?>
|
||||
<div class="palette-fields">
|
||||
<?php foreach (DesignLibrary::COLORS as $color => [$label, $fallback]): ?>
|
||||
<label><?= $e($label) ?><input type="color" name="<?= $e($color) ?>" value="<?= $e($data[$color] ?? $fallback) ?>"></label>
|
||||
<label><?= $e($label) ?><input type="<?= $field === $color ? 'text' : 'color' ?>" name="<?= $e($color) ?>" value="<?= $e($data[$color] ?? $fallback) ?>"<?= $describe($color) ?>><?php $fieldError($color); ?></label>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<fieldset class="admin-options"><legend>组件及顺序</legend>
|
||||
<fieldset class="admin-options"<?= $describe('components') ?>><legend>组件及顺序</legend>
|
||||
<ul class="admin-list layout-components" data-layout-components>
|
||||
<?php foreach (array_unique([...$data['components'], ...array_keys(DesignLibrary::COMPONENTS[$kind])]) as $component): ?>
|
||||
<li><label><input type="checkbox" name="components[]" value="<?= $e($component) ?>" <?= in_array($component, $data['components'], true) ? 'checked' : '' ?>><?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?></label>
|
||||
<div class="actions"><button type="button" class="button button-outline" data-component-move="-1">上移</button><button type="button" class="button button-outline" data-component-move="1">下移</button></div></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php $fieldError('components'); ?>
|
||||
</fieldset>
|
||||
<div class="form-grid">
|
||||
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"></label>
|
||||
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo']]) ?>
|
||||
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"<?= $describe('brand') ?>><?php $fieldError('brand'); ?></label>
|
||||
<div>
|
||||
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo'],
|
||||
'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?>
|
||||
<?php $fieldError('logo'); ?>
|
||||
</div>
|
||||
<label>链接列表<textarea name="links" rows="4"><?= $e(SiteDesign::linkText($data['links'])) ?></textarea><small>每行填写「名称 | 链接」。</small></label>
|
||||
</div>
|
||||
<label>链接列表<textarea name="links" rows="4"<?= $describe('links') ?>><?= $e($links) ?></textarea><small>每行填写「名称 | 链接」。</small><?php $fieldError('links'); ?></label>
|
||||
<?php if ($kind === 'header'): ?>
|
||||
<fieldset class="admin-options form-grid"><legend>行动按钮</legend>
|
||||
<fieldset class="admin-options form-grid"<?= $describe('action') ?>><legend>行动按钮</legend>
|
||||
<label>文案<input name="action_label" maxlength="70" value="<?= $e($action[1] ?? '') ?>"></label>
|
||||
<label>链接<input name="action_url" maxlength="1000" value="<?= $e($action[0] ?? '') ?>"></label>
|
||||
<label>样式<select name="action_style"><?php foreach (Buttons::STYLES as $style => $label): ?>
|
||||
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||
<?php endforeach ?></select></label>
|
||||
<label><span><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</span></label>
|
||||
<?php $fieldError('action'); ?>
|
||||
</fieldset>
|
||||
<fieldset class="admin-options form-grid" data-provider-settings><legend>用户区认证</legend>
|
||||
<label>认证方式<select name="provider_mode"><option value="">关闭</option>
|
||||
<fieldset class="admin-options form-grid" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $data['components']) ? '' : ' hidden' ?>><legend>用户区认证</legend>
|
||||
<label>认证方式<select name="provider_mode"<?= $describe('provider_mode') ?>><option value="">关闭</option>
|
||||
<?php foreach (['oidc' => 'OpenID Connect', 'oauth2' => 'OAuth 2.0 + 用户资料'] as $mode => $label): ?>
|
||||
<option value="<?= $e($mode) ?>" <?= ($provider['mode'] ?? '') === $mode ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<label>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"></label>
|
||||
<label>客户端密钥环境变量<input name="provider_secret_env" value="<?= $e($provider['secret_env'] ?? '') ?>" placeholder="LAYSITE_OAUTH_MEMBER_SECRET"></label>
|
||||
<label>令牌端点认证<select name="provider_token_auth">
|
||||
</select><?php $fieldError('provider_mode'); ?></label>
|
||||
<label data-provider-field>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"<?= $describe('provider_client_id') ?>><?php $fieldError('provider_client_id'); ?></label>
|
||||
<label data-provider-field>客户端密钥
|
||||
<input type="password" name="provider_secret" maxlength="4096" autocomplete="new-password"<?= $describe('provider_secret') ?>>
|
||||
<?php $fieldError('provider_secret'); ?>
|
||||
<?php if ($reenterSecret && $field !== 'provider_secret'): ?><small>请重新输入本次提交的客户端密钥。</small><?php endif ?>
|
||||
<?php if (!empty($item['credential_revision'])): ?><small>留空会保留已保存的密钥。</small><?php endif ?>
|
||||
</label>
|
||||
<label data-provider-field>令牌端点认证<select name="provider_token_auth"<?= $describe('provider_token_auth') ?>>
|
||||
<?php foreach (['' => '自动', 'client_secret_basic' => 'HTTP Basic', 'client_secret_post' => '表单客户端密钥'] as $method => $label): ?>
|
||||
<option value="<?= $e($method) ?>" <?= ($provider['token_auth'] ?? '') === $method ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<label>权限范围<input name="provider_scope" value="<?= $e($provider['scope'] ?? '') ?>" placeholder="openid profile email"></label>
|
||||
<label data-provider-mode="oidc">OIDC Issuer<input name="provider_issuer" value="<?= $e($provider['issuer'] ?? '') ?>" placeholder="https://id.example.com"></label>
|
||||
<?php foreach (['authorization' => '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $field => $label): ?>
|
||||
<label data-provider-mode="oauth2"><?= $e($label) ?><input name="provider_<?= $e($field) ?>" value="<?= $e($provider[$field] ?? '') ?>"></label>
|
||||
</select><?php $fieldError('provider_token_auth'); ?></label>
|
||||
<label data-provider-field>权限范围<input name="provider_scope" value="<?= $e($provider['scope'] ?? '') ?>" placeholder="openid profile email"<?= $describe('provider_scope') ?>><?php $fieldError('provider_scope'); ?></label>
|
||||
<label data-provider-mode="oidc">OIDC Issuer<input name="provider_issuer" value="<?= $e($provider['issuer'] ?? '') ?>" placeholder="https://id.example.com"<?= $describe('provider_issuer') ?>><?php $fieldError('provider_issuer'); ?></label>
|
||||
<?php foreach (['authorization' => '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $providerField => $label): ?>
|
||||
<label data-provider-mode="oauth2"><?= $e($label) ?><input name="provider_<?= $e($providerField) ?>" value="<?= $e($provider[$providerField] ?? '') ?>"<?= $describe('provider_' . $providerField) ?>><?php $fieldError('provider_' . $providerField); ?></label>
|
||||
<?php endforeach ?>
|
||||
<p class="field-note">回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
|
||||
<p class="field-note" data-provider-field>回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
|
||||
</fieldset>
|
||||
<?php else: ?>
|
||||
<label>说明文字<textarea name="text" rows="3"><?= $e($data['text']) ?></textarea></label>
|
||||
<label>版权文字<input name="legal" value="<?= $e($data['legal']) ?>"></label>
|
||||
<label>说明文字<textarea name="text" rows="3"<?= $describe('text') ?>><?= $e($data['text']) ?></textarea><?php $fieldError('text'); ?></label>
|
||||
<label>版权文字<input name="legal" value="<?= $e($data['legal']) ?>"<?= $describe('legal') ?>><?php $fieldError('legal'); ?></label>
|
||||
<?php endif ?>
|
||||
<label><span><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></span></label>
|
||||
<?php endif ?>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
use App\Content\Assets;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
@@ -16,7 +17,7 @@ $active = match (true) {
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<link rel="icon" href="/assets/system/laysite-mark.webp" type="image/webp">
|
||||
<link rel="icon" href="<?= $e(Assets::DEFAULT_ICON) ?>" type="image/webp">
|
||||
<title><?= $e($title) ?> CMS</title>
|
||||
<link rel="stylesheet" href="/assets/site.css">
|
||||
<link rel="stylesheet" href="/assets/admin.css">
|
||||
|
||||
@@ -5,7 +5,6 @@ use App\Content\View;
|
||||
$e = View::escape(...);
|
||||
$data = $header['payload'];
|
||||
$brand = $data['brand'] ?: $site['name'];
|
||||
$member = $header['preset'] === 'member' && $data['provider'] !== [];
|
||||
?>
|
||||
<header class="masthead masthead-<?= $e($header['preset']) ?>"<?= $showHeader ? '' : ' hidden' ?>>
|
||||
<div class="wrap masthead-inner">
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ $showFooter = $page['visibility']['footer'] ?? true;
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?= $e($title) ?></title>
|
||||
<link rel="icon" href="<?= $e(Assets::DEFAULT_ICON) ?>" type="image/webp">
|
||||
<meta name="description" content="<?= $e($description) ?>">
|
||||
<meta name="theme-color" content="#f5f7fb">
|
||||
<?php if ($canonical): ?>
|
||||
@@ -50,7 +51,7 @@ $showFooter = $page['visibility']['footer'] ?? true;
|
||||
<body>
|
||||
<a class="skip-link" href="#main-content">跳到内容</a>
|
||||
<?php if ($showHeader || !empty($canvas)): ?>
|
||||
<?= View::fragment('header', compact('header', 'site', 'showHeader', 'visitor', 'path')) ?>
|
||||
<?= View::fragment('header', compact('header', 'site', 'showHeader', 'visitor', 'member', 'path')) ?>
|
||||
<?php endif ?>
|
||||
<main id="main-content"<?= $theme !== '' ? ' class="page-theme theme-' . $e($theme) . '"' : '' ?> tabindex="-1"><?= $content ?></main>
|
||||
<?php if ($showFooter || !empty($canvas)): ?>
|
||||
|
||||
@@ -4,6 +4,6 @@ use App\Content\View;
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<div class="asset-field">
|
||||
<label><?= $e($label) ?><input name="<?= $e($name) ?>" value="<?= $e($value) ?>" maxlength="1000"></label>
|
||||
<label><?= $e($label) ?><input name="<?= $e($name) ?>" value="<?= $e($value) ?>" maxlength="1000"<?php if (isset($describedBy)): ?> aria-describedby="<?= $e($describedBy) ?>"<?php endif ?><?= !empty($invalid) ? ' aria-invalid="true"' : '' ?>></label>
|
||||
<button type="button" class="button button-outline" data-asset-pick="<?= $e($name) ?>" data-asset-type="image/">媒体库</button>
|
||||
</div>
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
"description": "LaySite visual editor and content management system",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"ext-curl": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-fileinfo": "*",
|
||||
@@ -14,7 +15,7 @@
|
||||
"league/commonmark": "^2.8",
|
||||
"league/oauth2-client": "^2.8",
|
||||
"monolog/monolog": "^3.0",
|
||||
"php": "^8.2",
|
||||
"vlucas/phpdotenv": "^5.6",
|
||||
"workerman/webman-framework": "^2.2"
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
Generated
+397
-3
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "45db06869e345d093c2aa4f7825b56c9",
|
||||
"content-hash": "766a207ffd06133d3e55efe2f93c68a1",
|
||||
"packages": [
|
||||
{
|
||||
"name": "dflydev/dot-access-data",
|
||||
@@ -157,6 +157,69 @@
|
||||
"time": "2026-11-17T00:25:19+00:00",
|
||||
"published-time": "2026-11-17T19:16:00+00:00"
|
||||
},
|
||||
{
|
||||
"name": "graham-campbell/result-type",
|
||||
"version": "v1.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GrahamCampbell/Result-Type.git",
|
||||
"reference": "adccca3324eece92ca35463648c12b9e6293c05b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/adccca3324eece92ca35463648c12b9e6293c05b",
|
||||
"reference": "adccca3324eece92ca35463648c12b9e6293c05b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.10"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5.52 || ^9.6.34 || ^10.5.63 || ^11.5.55 || ^12.5.14"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GrahamCampbell\\ResultType\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "An Implementation Of The Result Type",
|
||||
"keywords": [
|
||||
"Graham Campbell",
|
||||
"GrahamCampbell",
|
||||
"Result Type",
|
||||
"Result-Type",
|
||||
"result"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
|
||||
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.2.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-08-24T09:06:52+00:00",
|
||||
"published-time": "2026-08-24T09:07:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "8.5.5",
|
||||
@@ -1072,6 +1135,82 @@
|
||||
"time": "2026-07-09T19:38:47+00:00",
|
||||
"published-time": "2026-07-09T19:39:54+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
"version": "1.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/schmittjoh/php-option.git",
|
||||
"reference": "67b192b6a42ec03944b972d6e633ddec78ad2c6d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/67b192b6a42ec03944b972d6e633ddec78ad2c6d",
|
||||
"reference": "67b192b6a42ec03944b972d6e633ddec78ad2c6d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.54 || ^9.6.36 || ^10.5.64 || ^11.5.56 || ^12.5.33"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "1.9-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOption\\": "src/PhpOption/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Johannes M. Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh"
|
||||
},
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "Option Type for PHP",
|
||||
"keywords": [
|
||||
"language",
|
||||
"option",
|
||||
"php",
|
||||
"type"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/schmittjoh/php-option/issues",
|
||||
"source": "https://github.com/schmittjoh/php-option/tree/1.10.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-08-24T00:54:40+00:00",
|
||||
"published-time": "2026-08-24T01:09:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "2.0.2",
|
||||
@@ -1463,6 +1602,176 @@
|
||||
"time": "2026-09-16T14:15:10+00:00",
|
||||
"published-time": "2026-11-04T11:25:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.37.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "141046a8f9477948ff284fa65be2095baafb94f2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/141046a8f9477948ff284fa65be2095baafb94f2",
|
||||
"reference": "141046a8f9477948ff284fa65be2095baafb94f2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/polyfill",
|
||||
"name": "symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"ctype",
|
||||
"polyfill",
|
||||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.37.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-04-10T16:19:22+00:00",
|
||||
"published-time": "2026-04-26T14:44:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.43.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "122889ed24dc000165bcbfd77ec412f15cbdfc6a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/122889ed24dc000165bcbfd77ec412f15cbdfc6a",
|
||||
"reference": "122889ed24dc000165bcbfd77ec412f15cbdfc6a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-iconv": "*",
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/polyfill",
|
||||
"name": "symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.43.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-10-28T09:35:49+00:00",
|
||||
"published-time": "2026-10-28T10:07:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php80",
|
||||
"version": "v1.43.0",
|
||||
@@ -1629,6 +1938,91 @@
|
||||
"time": "2026-09-25T15:50:05+00:00",
|
||||
"published-time": "2026-09-30T10:23:32+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"version": "v5.8.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpdotenv/phpdotenv.git",
|
||||
"reference": "ba37876e98122ca15151247ce1187d20ee8bf4e0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpdotenv/phpdotenv/zipball/ba37876e98122ca15151247ce1187d20ee8bf4e0",
|
||||
"reference": "ba37876e98122ca15151247ce1187d20ee8bf4e0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-pcre": "*",
|
||||
"graham-campbell/result-type": "^1.2",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.10",
|
||||
"symfony/polyfill-ctype": "^1.26",
|
||||
"symfony/polyfill-mbstring": "^1.26",
|
||||
"symfony/polyfill-php80": "^1.26"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"ext-filter": "*",
|
||||
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-filter": "Required to use the boolean validator."
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "5.8-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dotenv\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
"email": "vance@vancelucas.com",
|
||||
"homepage": "https://github.com/vlucas"
|
||||
}
|
||||
],
|
||||
"description": "Loads environment variables from `.env` to `$_ENV` and `$_SERVER` automagically, and optionally to `getenv()`.",
|
||||
"keywords": [
|
||||
"dotenv",
|
||||
"env",
|
||||
"environment"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/phpdotenv/phpdotenv/issues",
|
||||
"source": "https://github.com/phpdotenv/phpdotenv/tree/v5.8.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-11-23T00:53:11+00:00",
|
||||
"published-time": "2026-11-23T00:53:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "workerman/coroutine",
|
||||
"version": "v1.1.7",
|
||||
@@ -1822,14 +2216,14 @@
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": "^8.2",
|
||||
"ext-curl": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-fileinfo": "*",
|
||||
"ext-mbstring": "*",
|
||||
"ext-openssl": "*",
|
||||
"ext-pdo_sqlite": "*",
|
||||
"ext-phar": "*",
|
||||
"php": "^8.2"
|
||||
"ext-phar": "*"
|
||||
},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.11.0"
|
||||
|
||||
+4
-2
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
use App\Config\Environment;
|
||||
|
||||
return [
|
||||
'webman' => [
|
||||
'handler' => Webman\App::class,
|
||||
'listen' => getenv('LAYSITE_LISTEN') ?: 'http://127.0.0.1:8787',
|
||||
'count' => max(1, (int) (getenv('LAYSITE_WORKERS') ?: 2)),
|
||||
'listen' => Environment::get('LAYSITE_LISTEN') ?: 'http://127.0.0.1:8787',
|
||||
'count' => max(1, (int) (Environment::get('LAYSITE_WORKERS') ?: 2)),
|
||||
'constructor' => [
|
||||
'requestClass' => App\Http\Request::class,
|
||||
'logger' => support\Log::channel('default'),
|
||||
|
||||
+2
-1
@@ -25,6 +25,7 @@ Route::get('/articles/feed/{slug:[a-z0-9-]+}/{key:[a-z0-9-]+}', [SiteController:
|
||||
Route::get('/articles/{slug:[a-z0-9-]+}', [SiteController::class, 'article']);
|
||||
Route::get('/robots.txt', [SiteController::class, 'robots']);
|
||||
Route::get('/sitemap.xml', [SiteController::class, 'sitemap']);
|
||||
Route::get('/favicon.ico', [SiteController::class, 'favicon']);
|
||||
|
||||
Route::add(['GET', 'POST'], '/admin/login', [AdminController::class, 'login']);
|
||||
Route::post('/admin/logout', [AdminController::class, 'logout']);
|
||||
@@ -43,7 +44,7 @@ Route::add(['GET', 'POST'], '/admin/settings', [DesignController::class, 'site']
|
||||
Route::add(['GET', 'POST'], '/admin/backup', [BackupController::class, 'index']);
|
||||
Route::get('/admin/backup/download', [BackupController::class, 'export']);
|
||||
Route::get('/admin/design', [DesignController::class, 'index']);
|
||||
Route::get('/admin/design/{kind:header|footer|palette}/{id:[0-9]+}/preview', [DesignController::class, 'preview']);
|
||||
Route::get('/admin/design/{kind:header|footer|palette}/{id:[0-9]+}/preview', [DesignController::class, 'previewDesign']);
|
||||
Route::add(['GET', 'POST'], '/admin/design/{kind:header|footer|palette}/{key:new|[0-9]+}', [DesignController::class, 'edit']);
|
||||
Route::get('/palette/{id:[0-9]+}.css', [DesignController::class, 'palette']);
|
||||
Route::add(['GET', 'POST'], '/admin/media', [StudioController::class, 'media']);
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Config\Environment;
|
||||
|
||||
return [
|
||||
'type' => 'file',
|
||||
'handler' => Webman\Session\FileSessionHandler::class,
|
||||
@@ -9,6 +11,6 @@ return [
|
||||
'cookie_lifetime' => 0,
|
||||
'cookie_path' => '/admin',
|
||||
'http_only' => true,
|
||||
'secure' => getenv('LAYSITE_SECURE_COOKIES') === '1',
|
||||
'secure' => Environment::get('LAYSITE_SECURE_COOKIES') === '1',
|
||||
'same_site' => 'Lax',
|
||||
];
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
}
|
||||
.admin-form textarea { resize: vertical; }
|
||||
.admin-form small, .field-note { color: var(--muted); font-size: .875rem; font-weight: 400; }
|
||||
.admin-form .design-field-error { color: #9c252a; grid-column: 1 / -1; }
|
||||
.admin-form [aria-invalid=true] { border-color: #9c252a; }
|
||||
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
|
||||
.form-submit { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
|
||||
.form-submit label { min-width: 10rem; }
|
||||
|
||||
+28
-4
@@ -9,15 +9,20 @@ jQuery(function ($) {
|
||||
});
|
||||
$('[data-provider-settings]').each(function () {
|
||||
const $settings = $(this);
|
||||
const $preset = $settings.closest('form').find('[data-layout-preset]');
|
||||
const $form = $settings.closest('form');
|
||||
const $preset = $form.find('[data-layout-preset]');
|
||||
const $account = $form.find('[name="components[]"][value=account]');
|
||||
const $mode = $settings.find('[name=provider_mode]');
|
||||
const sync = () => {
|
||||
$settings.prop('hidden', $preset.val() !== 'member');
|
||||
const mode = $mode.val();
|
||||
const active = $preset.val() === 'member' && $account.is(':checked');
|
||||
$settings.prop({hidden: !active, disabled: !active});
|
||||
$settings.find('[data-provider-field]').prop('hidden', !mode);
|
||||
$settings.find('[data-provider-mode]').each(function () {
|
||||
$(this).prop('hidden', this.dataset.providerMode !== $mode.val());
|
||||
$(this).prop('hidden', this.dataset.providerMode !== mode);
|
||||
});
|
||||
};
|
||||
$preset.add($mode).on('change', sync);
|
||||
$preset.add($mode).add($account).on('change', sync);
|
||||
sync();
|
||||
});
|
||||
|
||||
@@ -88,6 +93,21 @@ jQuery(function ($) {
|
||||
$feedback.prop('hidden', false).trigger('focus');
|
||||
}
|
||||
|
||||
function designFieldError($form, response) {
|
||||
if (!response?.field) return false;
|
||||
const $feedback = $form.find('[data-field-error]').filter(function () {
|
||||
return this.dataset.fieldError === response.field;
|
||||
});
|
||||
$feedback.text(response.message).prop('hidden', false);
|
||||
if (!$feedback.is(':visible')) return false;
|
||||
|
||||
$form.find('[aria-describedby]').filter(function () {
|
||||
return this.getAttribute('aria-describedby') === $feedback.attr('id');
|
||||
}).attr('aria-invalid', 'true');
|
||||
$feedback.trigger('focus');
|
||||
return true;
|
||||
}
|
||||
|
||||
document.addEventListener('invalid', (event) => {
|
||||
if (event.target.form?.method.toLowerCase() === 'post') clearSavedStatus();
|
||||
}, true);
|
||||
@@ -104,6 +124,8 @@ jQuery(function ($) {
|
||||
const $submit = $form.find(':submit:enabled');
|
||||
const multipart = $form.attr('enctype') === 'multipart/form-data';
|
||||
$form.attr('aria-busy', 'true').children('.ajax-feedback').prop('hidden', true);
|
||||
$form.find('[data-field-error]').text('').prop('hidden', true);
|
||||
$form.find('[aria-describedby^="design-error-"]').removeAttr('aria-invalid');
|
||||
$submit.prop('disabled', true);
|
||||
$form.triggerHandler('studio:busy', [true]);
|
||||
|
||||
@@ -143,7 +165,9 @@ jQuery(function ($) {
|
||||
return;
|
||||
}
|
||||
finish();
|
||||
if (!designFieldError($form, response)) {
|
||||
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@ CREATE TABLE IF NOT EXISTS design_presets (
|
||||
payload TEXT NOT NULL,
|
||||
version INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS layout_oauth_credentials (
|
||||
layout_id INTEGER PRIMARY KEY REFERENCES design_presets(id) ON DELETE CASCADE,
|
||||
revision TEXT NOT NULL,
|
||||
encrypted_secret TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS pages (
|
||||
slug TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
|
||||
@@ -6,6 +6,9 @@ declare(strict_types=1);
|
||||
chdir(__DIR__);
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Read process variables before Webman loads .env in the worker bootstrap.
|
||||
App\Config\Environment::load();
|
||||
|
||||
$sessionPath = __DIR__ . '/runtime/sessions';
|
||||
if (!is_dir($sessionPath) && !mkdir($sessionPath, 0750, true) && !is_dir($sessionPath)) {
|
||||
throw new RuntimeException('无法创建会话目录。');
|
||||
|
||||
Reference in New Issue
Block a user