forked from SimpleMachines/BuildTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-eof.php
More file actions
executable file
·93 lines (73 loc) · 2.79 KB
/
check-eof.php
File metadata and controls
executable file
·93 lines (73 loc) · 2.79 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2021 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 RC3
*/
// Stuff we will ignore.
$ignoreFiles = array(
// Build tools
'./other/buildtools/[A-Za-z0-9-_]+.php',
// Cache and miscellaneous.
'\./cache/data_[A-Za-z0-9-_]\.php',
'\./other/db_last_error.php',
// Installer and ugprade are not a worry.
'\./other/install.php',
'\./other/upgrade.php',
'\./other/upgrade-helper.php',
// Minify Stuff.
'\./Sources/minify/[A-Za-z0-9/-]+\.php',
// random_compat().
'\./Sources/random_compat/\w+\.php',
// ReCaptcha Stuff.
'\./Sources/ReCaptcha/[A-Za-z0-9]+\.php',
'\./Sources/ReCaptcha/RequestMethod/[A-Za-z0-9]+\.php',
// Punycode Stuff.
'\./Sources/punycode/[A-Za-z0-9]+\.php',
'\./Sources/punycode/Exception/[A-Za-z0-9]+\.php',
// We will ignore Settings.php if this is a live dev site.
'\./Settings.php',
'\./Settings_bak.php',
'\./db_last_error.php',
);
// No file? Thats bad.
if (!isset($_SERVER['argv'], $_SERVER['argv'][1]))
fatalError('Error: No File specified' . "\n");
// The file has to exist.
$currentFile = $_SERVER['argv'][1];
if (!file_exists($currentFile))
fatalError('Error: File does not exist' . "\n");
// Is this ignored?
foreach ($ignoreFiles as $if)
if (preg_match('~' . $if . '~i', $currentFile))
die;
// Less efficent than opening a file with fopen, but we want to be sure to get the right end of the file. file_get_contents
$file = fopen($currentFile, 'r');
// Error?
if ($file === false)
fatalError('Error: Unable to open file ' . $currentFile . "\n");
// Seek the end minus some bytes.
fseek($file, -100, SEEK_END);
$contents = fread($file, 100);
// There is some white space here.
if (preg_match('~\?>\s+$~', $contents, $matches))
fatalError('Error: End of File contains extra spaces in ' . $currentFile . "\n");
// Test to see if its there even, SMF 2.1 base package needs it there in our main files to allow package manager to properly handle end operations. Customizations do not need it.
if (!preg_match('~\?>$~', $contents, $matches))
fatalError('Error: End of File missing in ' . $currentFile . "\n");
// Test to see if a function/class ending is here but with no return (because we are OCD).
if (preg_match('~}([\r]?\n)?\?>~', $contents, $matches))
fatalError('Error: Incorrect return(s) after last function/class but before EOF in ' . $currentFile . "\n");
// Test to see if a string ending is here but with no return (because we are OCD).
if (preg_match('~;([\r]?\n)?\?>~', $contents, $matches))
fatalError('Error: Incorrect return(s) after last string but before EOF in ' . $currentFile . "\n");
function fatalError($msg)
{
fwrite(STDERR, $msg);
die;
}