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
|
#!/usr/bin/php
<?php
//===============================
// This small PHP script updates
// the configuration file
//===============================
// This is the path to the config file we are
// interested in.
define('CONFIG_FILE', '/var/www/config.inc.php');
// Get the current contents of the config file
$contents = file_get_contents(CONFIG_FILE);
// Read the configuration options to be changed from STDIN
while(TRUE)
{
// Read a line from STDIN that contains '='
$input_line = fgets(STDIN);
if($input_line === FALSE)
break;
if(strpos($input_line, '=') === FALSE)
continue;
// Extract the key / value from the line
list($key, $value) = explode('=', trim($input_line), 2);
// Replace all occurrences of the key with
// the key's new value.
$contents = preg_replace('/^\$THINKUP_CFG\[\'' . preg_quote($key) . '\'\](\s*)=.*$/m',
"\$THINKUP_CFG['$key']\$1= $value;",
$contents);
}
// Open the file for writing and write the new contents
$file = fopen(CONFIG_FILE, 'w');
fwrite($file, $contents);
fclose($file);
?>
|