Ejemplo n.º 1
0
 public function __construct($rig)
 {
     $this->_rigClient = $rig;
     $this->_config = Zend_Registry::get('config');
     $this->_logger = Sahara_Logger::getInstance();
     $this->_view = new Zend_View();
     $this->_view->setScriptPath(realpath(dirname(__FILE__) . '/Element/'));
 }
Ejemplo n.º 2
0
 /**
  * Initalisation.
  */
 public function init()
 {
     $this->_auth = Zend_Auth::getInstance();
     $this->_acl = new Sahara_Acl($this->_auth->getIdentity());
     $this->_logger = Sahara_Logger::getInstance();
     $this->_config = Zend_Registry::get('config');
     $this->_headPrefix = ($this->_config->page->title ? $this->_config->page->title : self::DEFAULT_HEAD_PREFIX) . ' - ';
     $this->_flashMessenger = $this->getHelper('FlashMessenger');
     $this->_redirector = $this->getHelper('Redirector');
 }
Ejemplo n.º 3
0
 /**
  * Error action.
  */
 public function errorAction()
 {
     $this->_config = Zend_Registry::get('config');
     $this->_logger = Sahara_Logger::getInstance();
     $errors = $this->_getParam('error_handler');
     switch ($errors->type) {
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
             /*---- 404 error -- controller or action not found. ---------*/
             $this->getResponse()->setHttpResponseCode(404);
             $this->view->code = 404;
             $this->view->message = '404 - Page not found';
             break;
         default:
             /*---- Application error. -----------------------------------*/
             /* Can we do some form of recovery. */
             if ($errors->exception instanceof Zend_Db_Adapter_Exception && self::_tryDatabaseRecovery()) {
                 /* Extract original request and redirect back to it. */
                 $params = $this->getAllParams();
                 $controller = $params['controller'];
                 $action = $params['action'];
                 unset($params['controller']);
                 unset($params['action']);
                 unset($params['module']);
                 unset($params['error_handler']);
                 $params['failover_retry'] = true;
                 $this->_request->clearParams();
                 $this->_request->setPost($params);
                 $this->_forward($controller, $action, null, $params);
                 /* Recovery succeeded, no need to perform error handling. */
                 return;
             }
             $this->_sendErrorEmail($errors);
             $this->_logger->fatal($this->view->message . ': ' . $errors->exception);
             $auth = Zend_Auth::getInstance()->clearIdentity();
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->code = 500;
             $this->view->message = '500 - Application Error';
             break;
     }
     $this->view->headTitle(($this->_config->page->title ? $this->_config->page->title : Sahara_Controller_Action_Acl::DEFAULT_HEAD_PREFIX) . ' - ' . 'Error Occurred', Zend_View_Helper_Placeholder_Container_Abstract::SET);
     /* Information that should have been populated by the action
      * pre-dispatch hook, but because this is an error fallback,
      * we assume nothing. */
     $this->view->userRole = self::PUESDO_ROLE_ERROR;
     $this->view->controller = 'index';
     $this->view->action = 'index';
     $this->view->env = APPLICATION_ENV;
     $this->view->exception = $errors->exception;
     $this->view->request = $errors->request;
 }
Ejemplo n.º 4
0
 /**
  * Gets a logger instance.
  *
  * @return Sahara_Logger instance
  */
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new Sahara_Logger();
     }
     return self::$_instance;
 }
Ejemplo n.º 5
0
 /**
  * Returns the home directory location.
  *
  * @return String home directory location.
  */
 public static function getHomeDirectoryLocation()
 {
     // TODO Make this abstract, make this OS agnostic
     list($jk, $user) = explode(':', Zend_Auth::getInstance()->getIdentity());
     exec("getent passwd `id -u {$user}`", $output, $ret);
     if ($ret != 0) {
         Sahara_Logger::getInstance()->error("Getting home directory for user {$user} failed, getent return code is " . "{$ret}.");
         return null;
     }
     $parts = explode(':', $output[0]);
     return $parts[5];
 }
Ejemplo n.º 6
0
 /**
  * Perform fail over to choose a database server to connect to.
  *
  * @param Zend_Config $config database configuration fields
  * @return bool whether fail over was able to connect to a server
  */
 public static function performFailover($config = false)
 {
     $logger = Sahara_Logger::getInstance();
     if (!$config && !($config = Zend_Registry::get('config')->database)) {
         throw new Exception('Database not configured.', 100);
     }
     $excludedId = -1;
     if (file_exists($config->failover->file)) {
         $ffile = new Zend_Config_Ini($config->failover->file);
         $excludedId = $ffile->dbindex;
     }
     foreach ($config->failover->params as $db => $params) {
         /* Check this isn't the excluded database. */
         $id = substr($db, 2);
         if ($id == $excludedId) {
             continue;
         }
         /* Merge configuration fields. */
         $dbconfig = $config->params->toArray();
         foreach ($params as $k => $v) {
             $dbconfig[$k] = $v;
         }
         try {
             /* Test connection. */
             $db = Zend_Db::factory($config->adapter, $dbconfig);
             $db->getConnection();
             /* If no exception was thrown connecting to the database, it probably is online
              * and we can register it. */
             $logger->info('Using fail over database server with index $id for database operations.');
             self::_registerDatabase($db);
             /* Write configuration for future requests. */
             $contents = '; Failover at ' . date(DATE_RFC2822) . "\n" . 'adapter = ' . $config->adapter . "\n" . "dbindex = {$id}\n";
             foreach ($dbconfig as $k => $v) {
                 $contents .= "params.{$k} = {$v}\n";
             }
             if (!file_put_contents($config->failover->file, $contents, LOCK_EX)) {
                 throw new Exception('Failed to write fail over file.', 100);
             }
             /* The written configuration file contains the database authentication credentials,
              * it should have restricted access to only the web server user. */
             if (!chmod($config->failover->file, 0600)) {
                 $logger->warn('Failed to change permissions of database configuration file \'' . $config->failover->file . '\' to only web server readable and writable, it should be ' . 'changed to having this permission.');
             }
             /* Found online database server. */
             return true;
         } catch (Zend_Db_Adapter_Exception $ex) {
             $logger->warn("Failed to connect to fail over database server with index '{$id}'. Error is " . $ex->getMessage() . '. Will attempt to connect to any remaining fail over servers.');
         }
     }
     /* No online database servers. */
     return false;
 }
Ejemplo n.º 7
0
 public function Sahara_AccessKey()
 {
     $this->_db = Sahara_Database::getDatabase();
     $this->_config = Zend_Registry::get('config');
     $this->_logger = Sahara_Logger::getInstance();
 }
Ejemplo n.º 8
0
 /**
  * Initialises the logger.
  *
  * @return unknown_type
  */
 protected function _initLogger()
 {
     require_once 'Sahara/Logger.php';
     // The autoloader isn't set up at this point
     Zend_Registry::set('logger', Sahara_Logger::getInstance());
 }
Ejemplo n.º 9
0
 public function __construct($user)
 {
     $this->_user = $user;
     $this->_logger = Sahara_Logger::getInstance();
 }