SecHub/index.php
2026-05-26 01:11:55 +08:00

198 lines
6.6 KiB
PHP

<?php
/**
* SecHub - 网络安全工具导航页
*/
// 定义JSON文件路径
$jsonDir = __DIR__ . '/assets/json/';
/**
* 读取JSON文件并返回数据
* @param string $filePath JSON文件路径
* @return array 解析后的数据数组
*/
function loadJsonData($filePath) {
if (!file_exists($filePath)) {
return [];
}
$content = file_get_contents($filePath);
if ($content === false) {
return [];
}
$data = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
error_log("JSON解析错误: " . json_last_error_msg());
return [];
}
return is_array($data) ? $data : [];
}
/**
* 获取所有JSON文件并自动识别栏目配置
* @param string $jsonDir JSON目录路径
* @return array 栏目配置数组
*/
function getSectionsConfig($jsonDir) {
$sections = [];
$jsonFiles = glob($jsonDir . '*.json');
foreach ($jsonFiles as $file) {
$filename = basename($file);
$data = loadJsonData($file);
if (!empty($data) && isset($data[0]['section'])) {
$sections[$filename] = [
'title' => $data[0]['section'],
'file' => $filename,
'items' => array_slice($data, 1)
];
} else {
$sections[$filename] = [
'title' => pathinfo($filename, PATHINFO_FILENAME),
'file' => $filename,
'items' => $data
];
}
}
return $sections;
}
/**
* 渲染卡片HTML
* @param array $item 项目数据
* @return string HTML字符串
*/
function renderCard($item) {
$name = htmlspecialchars($item['name'] ?? '未命名');
$url = htmlspecialchars($item['url'] ?? '#');
$description = htmlspecialchars($item['description'] ?? '暂无简介');
return "
<div class=\"card\" onclick=\"window.open('{$url}', '_blank')\">
<div class=\"card-header\">
<h3 class=\"card-title\">{$name}</h3>
<a href=\"{$url}\" target=\"_blank\" class=\"card-link\" onclick=\"event.stopPropagation()\">{$url}</a>
</div>
<p class=\"card-description\">{$description}</p>
</div>";
}
// 自动获取栏目配置
$sections = getSectionsConfig($jsonDir);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SecHub - 网络安全工具集</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="container">
<header>
<h1>SecHub 网安工具集</h1>
<p>一站式网络安全工具与资源导航平台</p>
<button id="theme-toggle" class="theme-toggle" title="点击切换白天/黑夜模式">
<span class="theme-icon">🌙</span>
<span class="theme-tooltip">切换主题</span>
</button>
</header>
<?php foreach ($sections as $key => $config): ?>
<?php
$items = $config['items'] ?? [];
?>
<section class="section">
<h2 class="section-title">
<?= htmlspecialchars($config['title']) ?>
</h2>
<?php if (empty($items)): ?>
<div class="empty-state">
<p>暂无数据,请在 <?= htmlspecialchars($config['file']) ?> 中添加项目</p>
</div>
<?php else: ?>
<div class="cards-grid">
<?php foreach ($items as $item): ?>
<?= renderCard($item) ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section>
<?php endforeach; ?>
<footer class="panel-footer">
<div class="footer-content">
<p class="copyright">&copy; <?= date('Y') ?> <a href="https://git.masonliu.com/MasonLiu/SecHub" target="_blank" rel="noopener noreferrer">SecHub - 网络安全工具集</a></p>
<p class="copyright">Gaming Master Cybersecurity | MasonLiu</p>
<div class="beian-info">
<a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer" class="beian-link">蜀ICP备2026025173号</a>
<span class="beian-divider">|</span>
<a href="https://beian.mps.gov.cn/#/query/webSearch?code=51162302000285" target="_blank" rel="noopener noreferrer" class="beian-link">
<img src="/assets/imgs/beian.png" alt="公安备案" width="16" height="16" class="beian-icon"/>
<span>川公网安备51162302000285号</span>
</a>
</div>
</div>
</footer>
</div>
<script>
// 黑夜模式切换功能
(function() {
const themeToggle = document.getElementById('theme-toggle');
const themeIcon = themeToggle.querySelector('.theme-icon');
const body = document.body;
// 从localStorage读取主题设置
const currentTheme = localStorage.getItem('theme') || 'light';
// 应用保存的主题
if (currentTheme === 'dark') {
body.classList.add('dark-mode');
themeIcon.textContent = '☀️';
}
// 首次访问显示提示
if (!localStorage.getItem('themeHintShown')) {
setTimeout(() => {
showThemeHint();
localStorage.setItem('themeHintShown', 'true');
}, 1500);
}
// 切换主题
themeToggle.addEventListener('click', function() {
body.classList.toggle('dark-mode');
if (body.classList.contains('dark-mode')) {
themeIcon.textContent = '☀️';
localStorage.setItem('theme', 'dark');
} else {
themeIcon.textContent = '🌙';
localStorage.setItem('theme', 'light');
}
});
// 显示提示函数
function showThemeHint() {
const tooltip = themeToggle.querySelector('.theme-tooltip');
tooltip.classList.add('show');
// 3秒后隐藏提示
setTimeout(() => {
tooltip.classList.remove('show');
}, 3000);
}
})();
</script>
</body>
</html>