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 "✅ 数据库创建/确认成功
\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 表创建/确认成功
\n";
// 3. 导入初始数据(如果表为空)
$count = $pdo->query("SELECT COUNT(*) FROM links")->fetchColumn();
if ($count > 0) {
echo "⚠️ links 表已有 {$count} 条记录,跳过数据导入
\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' => '',
'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' => '',
'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' => '',
'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' => '',
'group_name' => 'ops',
'group_label' => '运维 / 管理',
'group_hint' => '谨慎操作(建议仅管理员使用)',
'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' => '',
'group_name' => 'ops',
'group_label' => '运维 / 管理',
'group_hint' => '谨慎操作(建议仅管理员使用)',
'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' => '',
'group_name' => 'ops',
'group_label' => '运维 / 管理',
'group_hint' => '谨慎操作(建议仅管理员使用)',
'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' => '',
'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' => '',
'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' => '',
'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) . ' 条链接数据
';
}
echo '
🎉 数据库初始化完成!
'; echo ''; echo '⚠️ 出于安全考虑,建议你现在删除或重命名本文件(db_init.php)!
'; } catch (\PDOException $e) { echo '❌ 数据库错误:' . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . '
'; }