* section name class -
* submit button class -
* reset button class -
*/
var $css = array('main' => 'configmanMain',
'type' => 'configmanType',
'type_text' => 'configmanTypeText',
'var' => 'configmanVar',
'value' => 'configmanValue',
'error' => 'configmanError',
'existing' => 'configmanExisting',
'comment' => 'configmanComment',
'section' => 'configmanSection',
'submit' => 'configmanSubmit',
'reset' => 'configmanReset');
/**
* Comment line separator
*/
var $comment_separator = " ";
/**
* Confirmation text to appear when the 'Revert back' button is clicked
*
* Note: this will be entered in a javascript function surrounded by single quotes,
* so make sure you escape properly
*/
var $reset_confirm_text = "This will revert all values back, any changes you\\'ve made will be lost. Are you sure you want to continue?";
/**
* row color 1
*/
var $row_color_1 = "#DAEBFC";
/**
* row color 2
*/
var $row_color_2 = "#C1DDF9";
/////////////
// methods
/////////////
/**
* Constructor
*
* @param string $config config file to use
*/
function config_webedit($config)
{
// run base constructor
$this->config_base($config);
}
/**
* Build form
*
* @param string $section Section to display (empty string: all sections)
* @param string $post_action URL to post to (";
return implode("\n", $form);
}
/**
* Update config
*
* @param array $configman Result of form post ($CONFIGMAN array)
* @param array $configman_info Result of form post ($CONFIGMAN_INFO array)
* @return bool true on success, false otherwise
*/
function update($configman, $configman_info)
{
$func_name = 'update';
if (empty($configman_info['action']) || empty($configman_info['size']) || empty($configman_info['mtime'])) {
if ($this->debug) $this->_debug("$func_name: Required info not included in array");
return false;
}
// get rid of magic crap
$this->strip_magic_slashes($configman);
$this->strip_magic_slashes($configman_info);
if ($this->is_file_valid() && is_writable($this->config)) {
// check action
if ($configman_info['action'] !== 'modify') {
if ($this->debug) $this->_debug("$func_name: Incorrect action");
return false;
}
// check file size
if ((int)$configman_info['size'] !== filesize($this->config)) {
if ($this->debug) $this->_debug("$func_name: Config file sizes do not match");
return false;
}
// check modification time
if ((int)$configman_info['mtime'] !== filemtime($this->config)) {
if ($this->debug) $this->_debug("$func_name: Config file has already been modified (modification time mismatch)");
return false;
}
$config = file($this->config);
} else {
$this->_error("Config file does not exist or is unreadable or unwritable");
return false;
}
$new = array();
foreach ($config as $num => $line) {
$line = rtrim($line);
if (!isset($configman[$num])) {
$new[] = $line;
continue;
}
if (preg_match('!^(\s*)'.$this->regex_type.'?('.$this->regex_var.')(\.'.$this->regex_assoc.')?(\s*'.
preg_quote($this->separator).'\s*)(.*)$!i', $line, $match)) {
// set new type
if (isset($configman[$num]['type'])) {
$new_type = $configman[$num]['type'];
} else {
$new_type = $match[2];
}
// set new value
$new_val = $configman[$num]['value'];
$new[] = $match[1].$new_type.$match[3].$match[4].$match[5].$new_val;
continue;
}
$new[] = $line;
}
$fp = @fopen($this->config, "w");
if (!$fp) {
if ($this->debug) $this->_debug("$func_name: Could not create/access file");
return false;
} else {
// exclusive lock
flock($fp, 2);
$result = @fwrite($fp, implode("\n", $new));
// release lock
flock($fp, 3);
fclose($fp);
if (!$result) {
if ($this->debug) $this->_debug("$func_name: Could not write to file");
return false;
} else {
if ($this->debug) $this->_debug("$func_name: Config file written");
// touch file with modification time of main config file (used for comparison)
touch($this->config);
return true;
}
}
// should not reach here
return false;
}
}
?>