forked from vbonamy/esup-wayf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-config.php
executable file
·58 lines (45 loc) · 1.54 KB
/
update-config.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
<?php
// This script reads an existing config.php and generates
// a new file config.new.php merging the default configuration file
// config.dist.php with the (customized) config.php
if (isset($_SERVER['REMOTE_ADDR'])){
exit('No direct script access allowed');
}
if (!file_exists('config.dist.php')) {
die('The default configuration file config.dist.php does not exist in this directory!');
}
if (!file_exists('config.php')) {
die('The configuration file config.php does not exist in this directory!');
}
require_once('config.php');
echo "Parsing current configuration and default configuration...\n";
$fp = fopen('config.new.php', 'w') or die("Cannot open file 'config.new.php' for writing!") ;
$distConfigFile = file('config.dist.php');
$currentConfigFile = file('config.php');
$configSettings = Array();
foreach ($currentConfigFile as $line){
if (preg_match('|^\s*(\$(.+?)\s*=.+;)|', $line, $matches)){
$var = $matches[2];
$configSettings[$var] = $matches[1];
}
}
echo "Merging configurations...\n";
foreach ($distConfigFile as $line){
fwrite($fp, $line);
if (preg_match('|^(\s*)\/\/\$(.+) =|', $line, $matches)){
$indent = $matches[1];
$var = $matches[2];
if (isset($configSettings[$var])){
echo "* Using from current configuration: ";
echo $configSettings[$var]."\n";
$config = $indent.$configSettings[$var]."\n";
fwrite($fp, $config);
}
}
}
fclose($fp);
echo <<<NOTE
A new configuration file 'config.new.php' was created. Please replace the
current configuration file 'config.php' with this new file after reviewing it.
NOTE;
?>