-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsecure-vendor-dir.php
More file actions
72 lines (60 loc) · 1.82 KB
/
secure-vendor-dir.php
File metadata and controls
72 lines (60 loc) · 1.82 KB
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
68
69
70
71
72
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2025 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 4
*/
// Get paths from the the composer.lock file.
$json = json_decode(file_get_contents('composer.lock'), true);
// Add index.php to any directories that will be included in our distribution packages.
$dist_dirs = ['./vendor'];
foreach ($json['packages'] as $package) {
$dist_dirs[] = './vendor/' . strstr($package['name'], '/', true);
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
'./vendor/' . strstr($package['name'], '/', true),
RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS,
),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
if ($item->isDir()) {
$dist_dirs[] = $item->getPathname();
}
}
}
foreach ($dist_dirs as $key => $dir) {
if (!file_exists($dir . '/index.php')) {
copy('./Sources/index.php', $dir . '/index.php');
}
}
// Never add index.php to any other vendor directories.
$dev_dirs = [];
foreach ($json['packages-dev'] as $package) {
$dev_dirs[] = './vendor/' . strstr($package['name'], '/', true);
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
'./vendor/' . strstr($package['name'], '/', true),
RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS,
),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
if ($item->isDir()) {
$dev_dirs[] = $item->getPathname();
}
}
}
foreach ($dev_dirs as $key => $dir) {
if (
file_exists($dir . '/index.php')
&& md5_file('./Sources/index.php') === md5_file($dir . '/index.php')
) {
unlink($dir . '/index.php');
}
}