| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- /**
- * BCJD 导航 - 数据库初始化脚本
- *
- * 使用 OOP 类库重构。
- * 访问此文件一次即可自动建库建表并导入现有数据。
- * ⚠️ 执行完毕后建议删除或限制访问此文件!
- */
- require_once __DIR__ . '/init.php';
- use BCJD\Database;
- header('Content-Type: text/html; charset=utf-8');
- try {
- // 1. 先创建数据库
- $pdo = Database::rawConnection();
- $pdo->exec(sprintf(
- 'CREATE DATABASE IF NOT EXISTS `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci',
- DB_NAME
- ));
- $pdo->exec(sprintf('USE `%s`', DB_NAME));
- echo "✅ 数据库创建/确认成功<br>\n";
- // 2. 创建 links 表
- $pdo->exec("
- CREATE TABLE IF NOT EXISTS `links` (
- `id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
- `title` VARCHAR(100) NOT NULL COMMENT '链接标题',
- `url` VARCHAR(500) NOT NULL COMMENT '链接地址',
- `description` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '描述',
- `icon_svg` TEXT NOT NULL COMMENT 'SVG 图标代码',
- `group_name` VARCHAR(50) NOT NULL DEFAULT 'default' COMMENT '分组名称',
- `group_label` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '分组显示标签',
- `group_hint` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '分组提示文字',
- `keywords` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '搜索关键词',
- `tag_label` VARCHAR(30) NOT NULL DEFAULT '' COMMENT '标签文字',
- `tag_class` VARCHAR(30) NOT NULL DEFAULT '' COMMENT '标签样式类',
- `meta_domain` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '域名/元信息',
- `sort_order` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '排序',
- `is_private` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1=需登录,0=公开',
- `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
- INDEX `idx_group` (`group_name`),
- INDEX `idx_private` (`is_private`),
- INDEX `idx_sort` (`sort_order`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
- ");
- echo "✅ links 表创建/确认成功<br>\n";
- // 3. 导入初始数据(如果表为空)
- $count = $pdo->query("SELECT COUNT(*) FROM links")->fetchColumn();
- if ($count > 0) {
- echo "⚠️ links 表已有 {$count} 条记录,跳过数据导入<br>\n";
- } else {
- $stmt = $pdo->prepare("
- INSERT INTO `links` (`title`, `url`, `description`, `icon_svg`, `group_name`, `group_label`, `group_hint`, `keywords`, `tag_label`, `tag_class`, `meta_domain`, `sort_order`, `is_private`)
- VALUES (:title, :url, :description, :icon_svg, :group_name, :group_label, :group_hint, :keywords, :tag_label, :tag_class, :meta_domain, :sort_order, :is_private)
- ");
- $links = [
- // ===== 应用 - 公开 =====
- [
- 'title' => 'Monica',
- 'url' => 'https://monica.bcjd.net',
- 'description' => '个人关系/联系人管理类应用入口。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M12 21s-7-4.4-9-9.2C1.3 8 3.4 5 6.8 5c1.8 0 3 .9 3.7 1.8C11.2 5.9 12.4 5 14.2 5 17.6 5 19.7 8 21 11.8 19 16.6 12 21 12 21Z" stroke="currentColor" stroke-width="1.7"/></svg>',
- 'group_name' => 'apps',
- 'group_label' => '应用',
- 'group_hint' => '常用入口',
- 'keywords' => 'monica crm 联系人 个人 管理',
- 'tag_label' => 'App',
- 'tag_class' => 'ok',
- 'meta_domain' => 'monica.bcjd.net',
- 'sort_order' => 1,
- 'is_private' => 0,
- ],
- [
- 'title' => 'Gogs',
- 'url' => 'https://gogs.bcjd.net',
- 'description' => 'Git 仓库服务入口(代码托管/协作)。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M7 7h10v10H7V7Z" stroke="currentColor" stroke-width="1.7"/><path d="M9 9h6M9 12h6M9 15h4" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>',
- 'group_name' => 'apps',
- 'group_label' => '应用',
- 'group_hint' => '常用入口',
- 'keywords' => 'gogs git 代码 仓库 dev',
- 'tag_label' => 'Dev',
- 'tag_class' => 'ok',
- 'meta_domain' => 'gogs.bcjd.net',
- 'sort_order' => 2,
- 'is_private' => 0,
- ],
- [
- 'title' => 'Docker',
- 'url' => 'https://docker.bcjd.net',
- 'description' => '容器管理入口(例如 Portainer)。建议仅管理员使用。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M4 7.5 12 3l8 4.5v9L12 21l-8-4.5v-9Z" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/><path d="M12 3v18" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" opacity=".75"/><path d="M4 7.5 12 12l8-4.5" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round" opacity=".75"/></svg>',
- 'group_name' => 'apps',
- 'group_label' => '应用',
- 'group_hint' => '常用入口',
- 'keywords' => 'docker portainer 容器 运维 管理',
- 'tag_label' => 'Ops',
- 'tag_class' => 'ok',
- 'meta_domain' => 'docker.bcjd.net',
- 'sort_order' => 3,
- 'is_private' => 1,
- ],
- // ===== 运维/管理 - 私有 =====
- [
- 'title' => 'Webmin',
- 'url' => 'https://webmin.bcjd.net',
- 'description' => '服务器管理面板入口。请确认账号安全与访问来源。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M12 2l8 4v6c0 5-3.5 9.4-8 10-4.5-.6-8-5-8-10V6l8-4Z" stroke="currentColor" stroke-width="1.7"/></svg>',
- 'group_name' => 'ops',
- 'group_label' => '运维 / 管理',
- 'group_hint' => '<span style="color:var(--danger)">谨慎操作</span>(建议仅管理员使用)',
- 'keywords' => 'webmin 运维 管理 面板 linux',
- 'tag_label' => 'Admin',
- 'tag_class' => 'warn',
- 'meta_domain' => 'webmin.bcjd.net',
- 'sort_order' => 10,
- 'is_private' => 1,
- ],
- [
- 'title' => 'phpMyAdmin',
- 'url' => 'https://phpmyadmin.bcjd.net',
- 'description' => '数据库管理入口。请避免在不可信网络下使用。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M6 7c0 2.2 2.7 4 6 4s6-1.8 6-4-2.7-4-6-4-6 1.8-6 4Z" stroke="currentColor" stroke-width="1.7"/><path d="M6 7v10c0 2.2 2.7 4 6 4s6-1.8 6-4V7" stroke="currentColor" stroke-width="1.7"/></svg>',
- 'group_name' => 'ops',
- 'group_label' => '运维 / 管理',
- 'group_hint' => '<span style="color:var(--danger)">谨慎操作</span>(建议仅管理员使用)',
- 'keywords' => 'phpmyadmin mysql mariadb 数据库 管理',
- 'tag_label' => 'DB',
- 'tag_class' => 'warn',
- 'meta_domain' => 'phpmyadmin.bcjd.net',
- 'sort_order' => 11,
- 'is_private' => 1,
- ],
- [
- 'title' => 'Mail',
- 'url' => 'https://mail.bcjd.net',
- 'description' => '邮箱系统入口(WebMail/邮件访问)。建议注意账号与设备安全。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M4 7h16v10H4V7Z" stroke="currentColor" stroke-width="1.7"/><path d="M4 8l8 6 8-6" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/></svg>',
- 'group_name' => 'ops',
- 'group_label' => '运维 / 管理',
- 'group_hint' => '<span style="color:var(--danger)">谨慎操作</span>(建议仅管理员使用)',
- 'keywords' => 'mail 邮箱 邮件 webmail 收件箱 管理 运维 smtp imap',
- 'tag_label' => 'Mail',
- 'tag_class' => 'warn',
- 'meta_domain' => 'mail.bcjd.net',
- 'sort_order' => 12,
- 'is_private' => 1,
- ],
- // ===== 站点 - 公开 =====
- [
- 'title' => 'www.bcjd.net',
- 'url' => 'https://www.bcjd.net',
- 'description' => '网站主页/内容入口。你可以把此导航页部署在这里。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M4 10.5 12 4l8 6.5V20a1 1 0 0 1-1 1h-5v-6H10v6H5a1 1 0 0 1-1-1v-9.5Z" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/></svg>',
- 'group_name' => 'sites',
- 'group_label' => '站点',
- 'group_hint' => '对外主页 / 内容入口',
- 'keywords' => 'bcjd 主站 www 首页',
- 'tag_label' => 'Web',
- 'tag_class' => 'ok',
- 'meta_domain' => '主站入口',
- 'sort_order' => 20,
- 'is_private' => 0,
- ],
- [
- 'title' => 'www.qyqy.org',
- 'url' => 'https://www.qyqy.org',
- 'description' => 'qyqy.org 的 www 入口。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M4 6h16v12H4V6Z" stroke="currentColor" stroke-width="1.7"/><path d="M7 9h10M7 12h8M7 15h6" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>',
- 'group_name' => 'sites',
- 'group_label' => '站点',
- 'group_hint' => '对外主页 / 内容入口',
- 'keywords' => 'qyqy 网站 www',
- 'tag_label' => 'Web',
- 'tag_class' => '',
- 'meta_domain' => '站点入口',
- 'sort_order' => 21,
- 'is_private' => 0,
- ],
- [
- 'title' => 'www.mahaoyun.com',
- 'url' => 'https://www.mahaoyun.com',
- 'description' => 'mahaoyun.com 的 www 入口。',
- 'icon_svg' => '<svg viewBox="0 0 24 24" fill="none"><path d="M12 3l9 6-9 6-9-6 9-6Z" stroke="currentColor" stroke-width="1.7"/><path d="M3 9v8l9 6 9-6V9" stroke="currentColor" stroke-width="1.7"/></svg>',
- 'group_name' => 'sites',
- 'group_label' => '站点',
- 'group_hint' => '对外主页 / 内容入口',
- 'keywords' => 'mahaoyun 网站 www',
- 'tag_label' => 'Web',
- 'tag_class' => '',
- 'meta_domain' => '站点入口',
- 'sort_order' => 22,
- 'is_private' => 0,
- ],
- ];
- foreach ($links as $link) {
- $stmt->execute($link);
- }
- echo '✅ 已导入 ' . count($links) . ' 条链接数据<br>';
- }
- echo '<hr><p style="color:green;font-weight:bold">🎉 数据库初始化完成!</p>';
- echo '<p>👉 <a href="public/index.php">访问首页</a> | 👉 <a href="public/admin.php">管理面板</a></p>';
- echo '<p style="color:red;font-weight:bold">⚠️ 出于安全考虑,建议你现在删除或重命名本文件(db_init.php)!</p>';
- } catch (\PDOException $e) {
- echo '<p style="color:red">❌ 数据库错误:' . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . '</p>';
- }
|