Load site settings from dotenv and store OAuth credentials

This commit is contained in:
2026-11-23 16:53:29 +08:00
parent 1bb0554608
commit 01ede89dcd
27 changed files with 730 additions and 76 deletions
+14
View File
@@ -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=
+17 -11
View File
@@ -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
+1 -1
View File
@@ -1 +1 @@
1.0.0
1.1.0
+36
View File
@@ -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;
}
}
+11 -2
View File
@@ -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);
}
+42 -7
View File
@@ -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) {
@@ -141,14 +143,14 @@ final class DesignLibrary
throw new RuntimeException('请选择 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) {
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);
}
if (!in_array($result['token_auth'], ['', 'client_secret_basic', 'client_secret_post'], true)) {
throw new RuntimeException('令牌端点认证方式无效。');
}
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 RuntimeException('请填写客户端 ID。');
}
foreach ($mode === 'oidc' ? ['issuer'] : ['authorization', 'token', 'userinfo'] as $field) {
$url = parse_url($result[$field]);
@@ -164,15 +166,41 @@ final class DesignLibrary
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
{
return $preset === 'member' && in_array('account', $components, true);
}
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);
if ($name === '') {
throw new RuntimeException('请填写配置名称。');
}
$payload = Database::json(self::normalize($kind, $preset, $data));
$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): int {
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 RuntimeException('启用登录或变更身份提供商时,请填写客户端密钥。');
}
}
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 +211,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) {
+1 -5
View File
@@ -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'];
+2 -1
View File
@@ -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
+116
View File
@@ -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 RuntimeException('客户端密钥为空或格式无效。');
}
$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);
}
}
}
+15
View File
@@ -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
+6 -4
View File
@@ -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
+16 -16
View File
@@ -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;
}
}
+10 -4
View File
@@ -43,6 +43,8 @@ final class DesignController extends AdminController
$default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id;
if ($request->method() === 'POST') {
try {
$savedProvider = $item['payload']['provider'] ?? [];
$secret = '';
$item['name'] = $this->input($request, 'name');
$item['preset'] = $this->input($request, 'preset');
if ($kind === 'palette') {
@@ -58,14 +60,18 @@ final class DesignController extends AdminController
'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);
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $this->version($request), $default, $secret);
return $this->success($request, "/admin/design/$kind/$id?saved=1");
} catch (RuntimeException $ex) {
@@ -111,7 +117,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;
+2 -1
View File
@@ -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']);
+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('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);
+2 -1
View File
@@ -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
+9 -6
View File
@@ -53,25 +53,28 @@ $provider = $data['provider'] ?? [];
<?php endforeach ?></select></label>
<label><span><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</span></label>
</fieldset>
<fieldset class="admin-options form-grid" data-provider-settings><legend>用户区认证</legend>
<fieldset class="admin-options form-grid" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $data['components']) ? '' : ' hidden' ?>><legend>用户区认证</legend>
<label>认证方式<select name="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">
<label data-provider-field>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"></label>
<label data-provider-field>客户端密钥
<input type="password" name="provider_secret" maxlength="4096" autocomplete="new-password">
<?php if (!empty($item['credential_revision'])): ?><small>留空会保留已保存的密钥。</small><?php endif ?>
</label>
<label data-provider-field>令牌端点认证<select name="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-field>权限范围<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>
<?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>
-1
View File
@@ -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">
+1 -1
View File
@@ -50,7 +50,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)): ?>
+2 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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'),
+1 -1
View File
@@ -43,7 +43,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
View File
@@ -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',
];
+9 -4
View File
@@ -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();
});
+5
View File
@@ -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,
+3
View File
@@ -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('无法创建会话目录。');