Publish LaySite copyright notice and AGPL license

This commit is contained in:
2026-11-25 22:16:38 +08:00
parent acf59c9dfc
commit 080f146fef
10 changed files with 68 additions and 8 deletions
+13 -2
View File
@@ -8,7 +8,18 @@ use Composer\InstalledVersions;
final class Licenses
{
public const PROJECT = 'AGPL-3.0-only';
public const PROJECT = 'AGPL-3.0-or-later';
public const PROJECT_NAME = 'GNU Affero General Public License v3.0';
public const PROJECT_PATH = '/.laysite/license';
public static function projectText(): ?string
{
$root = dirname(__DIR__, 2);
$notice = @file_get_contents($root . '/NOTICE');
$license = @file_get_contents($root . '/LICENSE');
return $notice === false || $license === false ? null : rtrim($notice) . "\n\n" . $license;
}
public static function dependencies(): array
{
@@ -48,7 +59,7 @@ final class Licenses
public static function text(string $key): ?string
{
$path = $key === 'laysite' ? dirname(__DIR__, 2) . '/LICENSE' : (self::dependencies()[$key]['file'] ?? null);
$path = self::dependencies()[$key]['file'] ?? null;
$text = $path === null ? false : @file_get_contents($path);
return $text === false ? null : $text;
+1 -1
View File
@@ -8,7 +8,7 @@ use RuntimeException;
final class PageDraft
{
public const RESERVED = ['admin', 'assets', 'home', 'account', 'mcp', 'palette'];
public const RESERVED = ['.', '.laysite', 'admin', 'assets', 'home', 'account', 'mcp', 'palette'];
public static function slug(mixed $value, array $reserved = self::RESERVED, bool $includeSpecial = false): string
{
+10
View File
@@ -7,6 +7,7 @@ namespace App\Controller;
use App\Content\Assets;
use App\Content\CanvasStyle;
use App\Content\Html;
use App\Content\Licenses;
use App\Content\Repository;
use App\Content\View;
use FastRoute\Dispatcher;
@@ -21,6 +22,15 @@ final class SiteController
return $this->page($request, 'home');
}
public function license(Request $request): Response
{
$text = Licenses::projectText();
return new Response($text === null ? 404 : 200, [
'Content-Type' => 'text/plain; charset=utf-8', 'X-Content-Type-Options' => 'nosniff',
], $text ?? 'License not found.');
}
public function page(Request $request, string $slug): Response
{
$repo = new Repository();
+3 -1
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Middleware;
use App\Content\Licenses;
use App\Content\Repository;
use App\Content\SystemPage;
use App\Controller\SiteController;
@@ -16,7 +17,8 @@ final class SiteStatus implements MiddlewareInterface
public function process(Request $request, callable $handler): Response
{
$path = $request->path();
if ($path === '/admin' || str_starts_with($path, '/admin/')) {
if ($path === '/admin' || str_starts_with($path, '/admin/')
|| ($path === Licenses::PROJECT_PATH && in_array($request->method(), ['GET', 'HEAD'], true))) {
return $handler($request);
}
+2 -2
View File
@@ -31,8 +31,8 @@ $e = View::escape(...);
<section class="admin-panel admin-licenses" aria-labelledby="system-licenses-title">
<h2 id="system-licenses-title">开源许可证</h2>
<div class="admin-license-project">
<div><strong>LaySite</strong><p>GNU Affero General Public License v3.0(<?= $e(Licenses::PROJECT) ?>)</p></div>
<a href="/admin/about/license/laysite" target="_blank" rel="noopener noreferrer">查看许可证全文</a>
<div><strong>LaySite</strong><p><?= $e(Licenses::PROJECT_NAME) ?>(<?= $e(Licenses::PROJECT) ?>)</p></div>
<a href="<?= $e(Licenses::PROJECT_PATH) ?>" target="_blank" rel="noopener noreferrer">查看许可证全文</a>
</div>
<details class="admin-options admin-about-details">
<summary>第三方项目与许可</summary>