/** * Sets parameter in PPTP configuration file. * * @param string $parameter parameter in options file * @param string $value value for given parameter * * @access private * @return void */ protected function _set_config_parameter($parameter, $value) { clearos_profile(__METHOD__, __LINE__); $file = new File(self::FILE_CONFIG); $match = $file->replace_lines("/^{$parameter}\\s*/i", "{$parameter} {$value}\n"); if (!$match) { $file->add_lines_after("{$parameter} {$value}\n", "/^[^#]/"); } }
/** * Set the APC notification email. * * @param string $email a valid email * * @return void * @throws Engine_Exception Validation_Exception */ function set_email($email) { clearos_profile(__METHOD__, __LINE__); // Validation // ---------- Validation_Exception::is_valid($this->validate_email($email)); $file = new File(self::FILE_APC_CONTROL, TRUE); try { $file->replace_lines('/^export SYSADMIN=.*/', 'export SYSADMIN=' . $email . "\n"); } catch (Exception $e) { throw new Engine_Exception(clearos_exception_message($e), CLEAROS_ERROR); } }
/** * Generic set routine. * * @param string $key key name * @param string $value value for the key * @param string $offset value offset * @param string $default default value for key if it does not exist * * @access private * @return void * @throws Engine_Exception */ protected function _set_parameter($key, $value, $offset, $default) { clearos_profile(__METHOD__, __LINE__); if (!$this->is_loaded) { $this->_load_config(); } // Do offset magic //---------------- $fullvalue = ''; if ($offset == self::CONSTANT_NO_OFFSET) { $fullvalue = $value; } else { if (isset($this->config[$key])) { $items = preg_split('/\\s+/', $this->config[$key]['line'][1]); $items[$offset - 1] = $value; foreach ($items as $item) { $fullvalue .= $item . ' '; } } else { $fullvalue = $default; } } $this->is_loaded = FALSE; $this->config = array(); // Update tag if it exists //------------------------ $replacement = trim("{$key} {$fullvalue}"); // space cleanup $file = new File(self::FILE_CONFIG, TRUE); $match = $file->replace_one_line("/^{$key}\\s*/i", "{$replacement}\n"); if (!$match) { try { $file->add_lines_after("{$replacement}\n", "/^# {0,1}{$key} /"); } catch (File_No_Match_Exception $e) { $file->add_lines_before("{$replacement}\n", "/^#/"); } } }
/** * Sets a parameter in the config file. * * @param string $key name of the key in the config file * @param string $value value for the key * * @access private * @return void * @throws Engine_Exception */ protected function _set_parameter($key, $value) { clearos_profile(__METHOD__, __LINE__); $file = new File(self::FILE_CONFIG); $match = $file->replace_lines("/^{$key}\\s*=/", "{$key}={$value}\n"); if ($match === 0) { $match = $file->replace_lines("/^#\\s*{$key}\\s*=/", "{$key}={$value}\n"); if ($match === 0) { $file->add_lines("{$key}={$value}\n"); } } $this->is_loaded = FALSE; }