Launch LaySite visual editor and MCP workspace

This commit is contained in:
2026-11-22 23:26:08 +08:00
commit 1bb0554608
159 changed files with 11103 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Content\Database;
use App\Content\Passwords;
use App\Content\Repository;
$reset = ($argv[1] ?? '') === 'reset';
$email = strtolower(trim($argv[$reset ? 2 : 1] ?? ''));
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
fwrite(STDERR, "用法:php bin/admin.php [reset] admin@example.com\n");
exit(1);
}
fwrite(STDERR, "请输入至少 8 字符的管理员密码:");
$tty = function_exists('stream_isatty') && stream_isatty(STDIN);
if ($tty) {
exec('stty -echo');
}
try {
$password = rtrim((string) fgets(STDIN), "\r\n");
} finally {
if ($tty) {
exec('stty echo');
}
fwrite(STDERR, "\n");
}
if (!Passwords::isValidNew($password)) {
fwrite(STDERR, "密码至少 8 个字符,最多 72 字节。\n");
exit(1);
}
Database::initialize();
$hash = password_hash($password, PASSWORD_DEFAULT);
if ($reset) {
$repo = new Repository();
$user = $repo->administrator($email);
if (!$user || !$repo->changePassword($user, $hash)) {
fwrite(STDERR, "未能重设密码。请确认邮箱对应的账户存在,且未被同时修改。\n");
exit(1);
}
fwrite(STDOUT, "密码已重设,旧会话将失效。\n");
exit(0);
}
$query = Database::connect()->prepare('INSERT INTO users (email, password_hash) VALUES (?, ?)
ON CONFLICT (email) DO UPDATE SET password_hash = excluded.password_hash');
$query->execute([$email, $hash]);
fwrite(STDOUT, "管理员账户已就绪。\n");
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Content\SiteBackup;
[$command, $path, $confirm] = array_pad(array_slice($argv, 1), 3, null);
if (!is_string($path) || ($command !== 'export' && ($command !== 'import' || $confirm !== '--replace'))) {
fwrite(STDERR, "Usage: php bin/backup.php export snapshot.tar | import snapshot.tar --replace\n");
exit(2);
}
$path = str_starts_with($path, '/') ? $path : getcwd() . '/' . $path;
try {
if ($command === 'export') {
SiteBackup::export($path);
} else {
SiteBackup::import($path);
}
echo ($command === 'export' ? '备份已导出。' : '站点已还原。') . PHP_EOL;
} catch (Throwable $error) {
fwrite(STDERR, $error->getMessage() . PHP_EOL);
exit(1);
}
+11
View File
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Content\Database;
umask(0027);
Database::initialize();
fwrite(STDOUT, "SQLite 已初始化。现有内容会保留。\n");
Executable
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
php_bin=${LAYSITE_PHP:-php}
composer_bin=${LAYSITE_COMPOSER:-composer}
target=${1:-check}
if [ "$target" = check ]; then
git fetch origin --tags
git describe --tags --always
git tag --list 'v[0-9]*' --sort=-version:refname
exit 0
fi
if ! printf '%s\n' "$target" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$' || [ "$#" -ne 2 ]; then
printf '%s\n' 'Usage: bin/update.sh check | vX.Y.Z /path/snapshot.tar' >&2
exit 2
fi
if [ -n "$(git status --porcelain)" ]; then
printf '%s\n' 'Commit or set aside local source changes before updating.' >&2
exit 1
fi
git fetch origin --tags
current=$(git rev-parse HEAD)
next=$(git rev-parse --verify "refs/tags/$target^{commit}")
git merge-base --is-ancestor "$current" "$next"
"$php_bin" bin/backup.php export "$2"
if git switch --detach "$next" &&
"$composer_bin" install --no-dev --prefer-dist --no-interaction --no-scripts &&
"$php_bin" bin/install.php
then
printf 'Updated to %s. Start Webman with the original site environment.\n' "$target"
else
git switch --detach "$current"
"$composer_bin" install --no-dev --prefer-dist --no-interaction --no-scripts
printf 'Update failed. The prior source version is checked out and the backup is at %s.\n' "$2" >&2
exit 1
fi