4
//===============================
5
// This small PHP script updates
6
// the configuration file
7
//===============================
9
// This is the path to the config file we are
11
define('CONFIG_FILE', '/var/www/config.inc.php');
13
// Get the current contents of the config file
14
$contents = file_get_contents(CONFIG_FILE);
16
// Read the configuration options to be changed from STDIN
19
// Read a line from STDIN that contains '='
20
$input_line = fgets(STDIN);
22
if($input_line === FALSE)
24
if(strpos($input_line, '=') === FALSE)
27
// Extract the key / value from the line
28
list($key, $value) = explode('=', trim($input_line), 2);
30
// Replace all occurrences of the key with
31
// the key's new value.
32
$contents = preg_replace('/^\$THINKUP_CFG\[\'' . preg_quote($key) . '\'\](\s*)=.*$/m',
33
"\$THINKUP_CFG['$key']\$1= $value;",
37
// Open the file for writing and write the new contents
38
$file = fopen(CONFIG_FILE, 'w');
39
fwrite($file, $contents);