Example #1
0
 /**
  * send message to syslog
  * @param string $cpzonename
  * @param string $user
  * @param string $mac
  * @param string $ip
  * @param string $status
  * @param string $message
  */
 private function logportalauth($cpzonename, $user, $mac, $ip, $status, $message = "")
 {
     $message = trim($message);
     $message = "Zone : {$cpzonename} {$status}: {$user}, {$mac}, {$ip}, {$message}";
     $logger = new Syslog("logportalauth", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));
     $logger->info($message);
 }
Example #2
0
 /**
  * validate model and serialize data to config singleton object.
  *
  * @param bool $validateFullModel by default we only validate the fields we have changed
  * @param bool $disable_validation skip validation, be careful to use this!
  * @throws \Phalcon\Validation\Exception validation errors
  */
 public function serializeToConfig($validateFullModel = false, $disable_validation = false)
 {
     // create logger to save possible consistency issues to
     $logger = new Syslog("config", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));
     // Perform validation, collect all messages and raise exception if validation is not disabled.
     // If for some reason the developer chooses to ignore the errors, let's at least log there something
     // wrong in this model.
     $messages = $this->performValidation($validateFullModel);
     if ($messages->count() > 0) {
         $exception_msg = "";
         foreach ($messages as $msg) {
             $exception_msg .= "[" . $msg->getField() . "] " . $msg->getMessage() . "\n";
             // always log validation errors
             $logger->error(str_replace("\\", ".", get_class($this)) . "." . $msg->getField() . " " . $msg->getMessage());
         }
         if (!$disable_validation) {
             throw new \Phalcon\Validation\Exception($exception_msg);
         }
     }
     $this->internalSerializeToConfig();
 }
Example #3
0
 /**
  * insert new session information into this zone's database
  *
  * @param string $sessionid unique session id
  * @param Array() field content ( defined fields in "captiveportal")
  */
 public function insertSession($sessionid, $content)
 {
     if ($this->handle != null) {
         // construct insert query, using placeholders for bind variables
         $bind_values = array("sessionid" => $sessionid);
         $query = "insert into captiveportal (sessionid ";
         $query_values = "values (:sessionid ";
         foreach ($content as $fieldname => $fieldvalue) {
             // you may not alter data not described in $this->captiveportal_types
             if (array_key_exists($fieldname, $this->captiveportal_types)) {
                 $query .= "," . $fieldname . " ";
                 $query_values .= ", :" . $fieldname;
                 $bind_values[$fieldname] = $fieldvalue;
             }
         }
         $query .= " ) " . $query_values . ") ";
         try {
             $this->handle->execute($query, $bind_values, $this->captiveportal_types);
         } catch (\Exception $e) {
             $logger = new Syslog("logportalauth", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));
             $msg = "Trying to modify DB returned error (zone =  " . $this->zone . " ) : " . $e->getMessage() . " ";
             $logger->error($msg);
         }
     }
 }
Example #4
0
 /**
  * init new config object, try to load current configuration
  * (executed via Singleton)
  */
 protected function init()
 {
     $this->config_file = FactoryDefault::getDefault()->get('config')->globals->config_path . "config.xml";
     try {
         $this->load();
     } catch (\Exception $e) {
         $this->simplexml = null;
         // there was an issue with loading the config, try to restore the last backup
         $backups = $this->getBackups();
         $logger = new Syslog("config", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));
         if (count($backups) > 0) {
             // load last backup
             $logger->error(gettext('No valid config.xml found, attempting last known config restore.'));
             $this->restoreBackup($backups[0]);
         } else {
             // in case there are no backups, restore defaults.
             $logger->error(gettext('No valid config.xml found, attempting to restore factory config.'));
             $this->restoreBackup('/usr/local/etc/config.xml');
         }
     }
 }