-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-eof.php
executable file
·69 lines (59 loc) · 2.41 KB
/
check-eof.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
68
69
<?php
/**************************************************************
* Simple Desk Project - www.simpledesk.net *
***************************************************************
* An advanced help desk modification built on SMF *
***************************************************************
* *
* * Copyright 2022 - SimpleDesk.net *
* *
* This file and its contents are subject to the license *
* included with this distribution, license.txt, which *
* states that this software is New BSD Licensed. *
* Any questions, please contact SimpleDesk.net *
* *
***************************************************************
* SimpleDesk Version: 2.1 Beta 1 *
* File Info: check-eof.php *
**************************************************************/
// Stuff we will ignore.
$ignoreFiles = array(
'\.github/',
'\.buildTools/',
);
// 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");
// It exists! Leave.
elseif (preg_match('~}$~', $contents, $matches))
die();
// There is some white space here.
if (preg_match('~\';\s+$~', $contents, $matches))
fatalError('Error: End of File Strings contains extra spaces in ' . $currentFile . "\n");
// It exists! Leave.
elseif (preg_match('~\';$~', $contents, $matches))
die();
function fatalError($msg)
{
fwrite(STDERR, $msg);
die;
}