-
Notifications
You must be signed in to change notification settings - Fork 16
/
check-smf-index.php
62 lines (52 loc) · 1.32 KB
/
check-smf-index.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
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2024 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 1
*/
$ignoreIndexFiles = [
'\.\/\.',
'\./other',
'\./vendor',
];
$contents = <<<END
<?php
// Try to handle it with the upper level index.php. (it should know what to do.)
if (file_exists(dirname(__DIR__) . '/index.php'))
include (dirname(__DIR__) . '/index.php');
else
exit;
?>
END;
try
{
$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator('.', RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD
);
foreach ($iter as $currentDirectory => $dir) {
if (!$dir->isDir())
continue;
foreach ($ignoreIndexFiles as $if) {
if (preg_match('~' . $if . '~i', $currentDirectory)) {
continue 2;
}
}
if (!file_exists($currentDirectory . '/index.php')) {
throw new Exception('Index file missing in ' . $currentDirectory);
}
if (file_get_contents($currentDirectory . '/index.php') != $contents) {
throw new Exception('Index content does not match in ' . $currentDirectory);
}
}
}
catch (Exception $e) {
fwrite(STDERR, $e->getMessage());
exit(1);
}