This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
67 lines (62 loc) · 2.35 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require __DIR__ . '/_config.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
pre {
background-color: #eee;
color: #222;
margin: 0;
padding: 10px;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}
</style>
<title>Web hook log viewer</title>
</head>
<body>
<h1>Web hook log viewer</h1>
<h2>Log files.</h2>
<?php
$DI = new \FilesystemIterator(__DIR__, \FilesystemIterator::SKIP_DOTS);
$DI = new \CallbackFilterIterator(
$DI,
function ($item) {
return strtolower($item->getExtension()) === 'txt' ? true : false;
}
);
$II = new \IteratorIterator($DI);
echo '<div style="margin-bottom: 40px;">' . "\n";
if (is_iterable($II) && iterator_count($II) > 0) {
foreach ($II as $File) {
echo ' <a href="view.php?file=' . rawurlencode($File->getFilename()) . '">' . $File->getFilename() . '</a>';
echo ' <br>' . "\n";
}// endforeach;
unset($File);
} else {
echo ' There is no log files.' . "\n";
}// endif;
echo ' </div>' . "\n";
unset($DI, $II);
if (
isset($_GET['file']) &&
stripos($_GET['file'], '..') === false &&
is_file(__DIR__ . DIRECTORY_SEPARATOR . trim(str_replace(['\\', '/', DIRECTORY_SEPARATOR], '', $_GET['file']))) &&
strtolower(pathinfo(trim($_GET['file']), PATHINFO_EXTENSION)) === 'txt'
) {
echo ' <h2>File content of "' . htmlspecialchars(trim($_GET['file']), ENT_QUOTES) . '"</h2>' . "\n";
$fileContents = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . trim(str_replace(['\\', '/', DIRECTORY_SEPARATOR], '', $_GET['file'])));
if (is_string($fileContents)) {
$fileContents = trim($fileContents);
}
echo ' <pre>' . print_r($fileContents, true) . '</pre>' . "\n";
unset($fileContents);
}// endif; view file contents.
?>
</body>
</html>