修复错误

This commit is contained in:
2025-03-02 18:37:50 +08:00
parent ef65c15c2a
commit 7153217140
2 changed files with 14 additions and 11 deletions

View File

@@ -11,14 +11,14 @@ foreach ($directory as $folderinfo) {
} }
foreach ($folders as $folder) { foreach ($folders as $folder) {
$subDirectory = new DirectoryIterator(dirname(__FILE__) . $folder); $subDirectory = new DirectoryIterator(dirname(__FILE__) . '/' . $folder);
foreach ($subDirectory as $fileinfo) { foreach ($subDirectory as $fileinfo) {
if ($fileinfo->isFile() && $fileinfo->getExtension() == 'html') { if ($fileinfo->isFile() && $fileinfo->getExtension() == 'html') {
$files[] = $folder . '/' . $fileinfo->getFilename(); $files[] = $folder . '/' . $fileinfo->getFilename();
} }
} }
} }
sort($folder); sort($folders);
sort($files); sort($files);
?> ?>
@@ -37,12 +37,15 @@ sort($files);
<?php <?php
if (isset($_GET['file'])) { if (isset($_GET['file'])) {
$file = $_GET['file']; $file = $_GET['file'];
$filePath = dirname(__FILE__) . '/' . $file; // Validate file path to prevent directory traversal
if (file_exists($filePath) && is_readable($filePath)) { $realPath = realpath(dirname(__FILE__) . '/' . $file);
if (pathinfo($filePath, PATHINFO_EXTENSION) == 'php') { $basePath = realpath(dirname(__FILE__));
include $filePath;
if ($realPath && strpos($realPath, $basePath) === 0 && file_exists($realPath) && is_readable($realPath)) {
if (pathinfo($realPath, PATHINFO_EXTENSION) == 'php') {
include $realPath;
} else { } else {
echo file_get_contents($filePath); echo file_get_contents($realPath);
} }
} else { } else {
echo '<p>File not found or not readable.</p>'; echo '<p>File not found or not readable.</p>';

View File

@@ -1,15 +1,15 @@
<?php require_once("./include/db_info.inc.php"); ?> <?php require_once "./include/db_info.inc.php"; ?>
<?php $show_title = "$MSG_DEMO - $OJ_NAME"; ?> <?php $show_title = "$MSG_DEMO - $OJ_NAME"; ?>
<?php require("./template/$OJ_TEMPLATE/header.php"); ?> <?php require "./template/$OJ_TEMPLATE/header.php"; ?>
<div class="padding"> <div class="padding">
<div class="container-fluid"> <div class="container-fluid">
<?php require("./demos/index.php"); ?> <?php require "./demos/index.php"; ?>
</div> </div>
</div> </div>
</div> </div>
<?php require("./template/$OJ_TEMPLATE/footer.php"); ?> <?php require "./template/$OJ_TEMPLATE/footer.php"; ?>