Example #1
0
 /**
  * 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", "/^[^#]/");
     }
 }
Example #2
0
 /**
  * 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);
     }
 }
Example #3
0
 /**
  * Adds (or updates) a time definition for use with an ACL.
  *
  * @param string  $name   time name
  * @param array   $dow    an array of days of week
  * @param string  $start  start hour/min
  * @param string  $end    end hour/min
  * @param boolean $update TRUE if we are updating an existing entry
  *
  * @return void
  * @throws Engine_Exception, Validation_Exception
  */
 public function set_time_definition($name, $dow, $start, $end, $update = FALSE)
 {
     clearos_profile(__METHOD__, __LINE__);
     // Validate
     // --------
     Validation_Exception::is_valid($this->validate_name($name));
     // Check for existing
     if (!$update) {
         $times = $this->get_time_definition_list();
         foreach ($times as $time) {
             if ($name == $time['name']) {
                 throw new Validation_Exception(lang('web_proxy_time_definition_exists'));
             }
         }
     }
     Validation_Exception::is_valid($this->validate_day_of_week($dow));
     $formatted_dow = implode('', array_values($dow));
     if (strtotime($start) > strtotime($end)) {
         throw new Validation_Exception(lang('web_proxy_start_time_later_than_end_time'));
     } else {
         $time_range = $start . '-' . $end;
     }
     if (!$this->is_loaded) {
         $this->_load_config();
     }
     // Implant into acl section
     //-------------------------
     $file = new File(self::FILE_ACLS_CONFIG, TRUE);
     $replacement = "acl cleartime-{$name} time {$formatted_dow} " . $time_range . "\n";
     $match = $file->replace_lines("/acl cleartime-{$name} time.*\$/", $replacement);
     if (!$match) {
         $file->add_lines($replacement);
     }
     $this->is_loaded = FALSE;
     $this->config = array();
 }
Example #4
0
 /**
  * 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;
 }