<?php
require_once('config.php');
$articles = array_diff(scandir(__DIR__), PRIVATE_FILES);
$article_links = array_map(function ($path) {
return "<a onclick='goto(\"$path\");' class='has-cursor-pointer' style='color: blue'>$path</a>";
}, $articles);
$article_links[] = "<a onclick='goto(\"\");' class='has-cursor-pointer' style='color: blue'>首頁</a>";
$article_links = join('、', $article_links);
?>
<!DOCTYPE html>
<html data-background="secondary" class="is-light">
<head>
<title>我的部落格 - CTF</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/4.2.5/tocas.min.css">
<meta charset="UTF-8" />
</head>
<body>
<div class="ts-container is-narrow">
<div class="ts-space is-big"></div>
<div class="ts-header is-huge is-center-aligned is-heavy">我的部落格</div>
<div class="ts-space is-big"></div>
<p>請輸入文章代號</p>
<form id="form" class="ts-input is-large is-fluid is-solid is-start-icon">
<span class="ts-icon is-magnifying-glass-icon"></span>
<input type="text" id="page" name="page" placeholder="ceh.html" value="<?= $_GET['page'] ?>" />
<button id="btn" class="ts-button is-circular is-outlined">Go!</button>
</form>
<div class="ts-space"></div>
<p>文章列表:<?= $article_links ?></p>
<div class="ts-space"></div>
</div>
<div class="ts-divider"></div>
<div class="ts-space is-large"></div>
<div class="ts-container is-narrow">
<?php
if (strlen($_GET['page'] ?? '') == 0) {
highlight_file(__FILE__);
} else {
$article = @file_get_contents($_GET['page']);
if (preg_match('#FLAG#i', $article))
echo FORBIDDEN;
else
echo $article;
}
?>
</div>
<div class="ts-space is-huge"></div>
<script>
function goto(name) {
document.getElementById('page').value = name;
document.getElementById('form').submit();
}
</script>
<script src="/assets/js/clarity.js"></script>
</body>
</html>