-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.php
34 lines (34 loc) · 1.3 KB
/
build.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
<?php
/**
* This scripts pre-generates the php-safe-functions.php script (containing only one array)
* @package php-safe-functions
* @author Yannick Warnier <[email protected]>
*/
/**
* Initialize the reading
*/
$file = 'functions.txt';
$destFile = 'php-safe-functions.php';
$resultString = '<?php'."\n".
'/**'."\n".
' * This list is a whitelist of safe functions to use in combination'."\n".
' * with the disable_functions parameter of php.ini, for example, you'."\n".
' * could reuse the $safeFunctionsIni string like this at the beginning'."\n".
' * of your script:'."\n".
' * <?php'."\n".
' * require \'php-safe-functions.php\';'."\n".
' * ini_set(\'disable_functions\', $safeFunctionsIni);'."\n".
' * // Your script here'."\n".
' **/'."\n\n";
$resultStringIni = '';
$resultArray = '';
// Read file containing all existing functions, assuming it is in functions.txt
$lines = file($file);
foreach ($lines as $line) {
if (substr($line, 0, 1) == '/') { continue; }
$resultStringIni .= trim($line).",";
$resultArray .= " '".trim($line)."',\n";
}
$resultString .= '$safeFunctionsIni = "'.substr($resultStringIni,0,-1)."\";\n";
$resultString .= '$safeFunctionsArray = array('."\n".$resultArray.')'."\n";
file_put_contents($destFile, $resultString);