/**
  * Get authorization instance, creates one if it doesn't already exist.
  *
  * @param Flux_Config $accessConfig
  * @param Flux_SessionData $sessionData
  * @return Flux_Authorization
  * @access public
  */
 public static function getInstance($accessConfig = null, $sessionData = null)
 {
     if (!self::$auth) {
         self::$auth = new Flux_Authorization($accessConfig, $sessionData);
     }
     return self::$auth;
 }
Example #2
0
 /**
  * Get sub-menu items for a particular module.
  *
  * @param string $moduleName
  * @return array
  */
 public function getSubMenuItems($moduleName = null)
 {
     $auth = Flux_Authorization::getInstance();
     $moduleName = $moduleName ? $moduleName : $this->moduleName;
     $subMenuItems = Flux::config('SubMenuItems');
     $allowedItems = array();
     if (!$subMenuItems instanceof Flux_Config || !($menus = $subMenuItems->get($moduleName)) instanceof Flux_Config) {
         return array();
     }
     foreach ($menus->toArray() as $actionName => $menuName) {
         if ($auth->actionAllowed($moduleName, $actionName)) {
             $allowedItems[] = array('name' => $menuName, 'module' => $moduleName, 'action' => $actionName);
         }
     }
     return $allowedItems;
 }
Example #3
0
    ini_set('session.gc_maxlifetime', $sessionExpireDuration);
    ini_set('session.name', $sessionKey);
    @session_start();
    if (empty($_SESSION[$sessionKey]) || !is_array($_SESSION[$sessionKey])) {
        $_SESSION[$sessionKey] = array();
    }
    // Initialize session data.
    Flux::$sessionData = new Flux_SessionData($_SESSION[$sessionKey], $hasUpdates);
    // Initialize authorization component.
    $accessConfig = Flux::parseConfigFile(FLUX_CONFIG_DIR . '/access.php');
    // Merge with add-on configs.
    foreach (Flux::$addons as $addon) {
        $accessConfig->merge($addon->accessConfig);
    }
    $accessConfig->set('unauthorized.index', AccountLevel::ANYONE);
    $authComponent = Flux_Authorization::getInstance($accessConfig, Flux::$sessionData);
    if (!Flux::config('DebugMode')) {
        ini_set('display_errors', 0);
    }
    // Dispatch requests->modules->actions->views.
    $dispatcher = Flux_Dispatcher::getInstance();
    $dispatcher->setDefaultModule(Flux::config('DefaultModule'));
    $dispatcher->dispatch(array('basePath' => Flux::config('BaseURI'), 'useCleanUrls' => Flux::config('UseCleanUrls'), 'modulePath' => FLUX_MODULE_DIR, 'themePath' => FLUX_THEME_DIR, 'themeName' => Flux::$sessionData->theme, 'missingActionModuleAction' => Flux::config('DebugMode') ? array('errors', 'missing_action') : array('main', 'page_not_found'), 'missingViewModuleAction' => Flux::config('DebugMode') ? array('errors', 'missing_view') : array('main', 'page_not_found')));
} catch (Exception $e) {
    $exceptionDir = FLUX_DATA_DIR . '/logs/errors/exceptions';
    if (is_writable($exceptionDir)) {
        require_once 'Flux/LogFile.php';
        $today = date('Ymd');
        $eLog = new Flux_LogFile("{$exceptionDir}/{$today}.log");
        // Log exception.
        $eLog->puts('(%s) Exception %s: %s', get_class($e), get_class($e), $e->getMessage());
Example #4
0
 /**
  * Dispatch current request to the correct action and render the view.
  *
  * @param array $options Options for the dispatcher.
  * @access public
  */
 public function dispatch($options = array())
 {
     $config = new Flux_Config($options);
     $basePath = $config->get('basePath');
     $paramsArr = $config->get('params');
     $modulePath = $config->get('modulePath');
     $themePath = $config->get('themePath');
     $themeName = $config->get('themeName');
     $defaultModule = $config->get('defaultModule');
     $defaultAction = $config->get('defaultAction');
     $missingActionModuleAction = $config->get('missingActionModuleAction');
     $missingViewModuleAction = $config->get('missingViewModuleAction');
     $useCleanUrls = $config->get('useCleanUrls');
     if (!$defaultModule && $this->defaultModule) {
         $defaultModule = $this->defaultModule;
     }
     if (!$defaultAction && $this->defaultAction) {
         $defaultAction = $this->defaultAction;
     }
     if (!$defaultModule) {
         throw new Flux_Error('Please set the default module with $dispatcher->setDefaultModule()');
     } elseif (!$defaultAction) {
         throw new Flux_Error('Please set the default action with $dispatcher->setDefaultAction()');
     }
     if (!$paramsArr) {
         $paramsArr =& $_REQUEST;
     }
     // Provide easier access to parameters.
     $params = new Flux_Config($paramsArr);
     $baseURI = Flux::config('BaseURI');
     if ($params->get('module')) {
         $safetyArr = array('..', '/', '\\');
         $moduleName = str_replace($safetyArr, '', $params->get('module'));
         if ($params->get('action')) {
             $actionName = str_replace($safetyArr, '', $params->get('action'));
         } else {
             $actionName = $defaultAction;
         }
     } elseif (Flux::config('UseCleanUrls')) {
         $baseURI = preg_replace('&/+&', '/', rtrim($baseURI, '/')) . '/';
         $requestURI = preg_replace('&/+&', '/', rtrim($_SERVER['REQUEST_URI'], '/')) . '/';
         $requestURI = preg_replace('&\\?.*?$&', '', $requestURI);
         $components = explode('/', trim((string) substr($requestURI, strlen($baseURI)), '/'));
         $moduleName = empty($components[0]) ? $defaultModule : $components[0];
         $actionName = empty($components[1]) ? $defaultAction : $components[1];
     } elseif (!$params->get('module') && !$params->get('action')) {
         $moduleName = $defaultModule;
         $actionName = $defaultAction;
     }
     // Authorization handling.
     $auth = Flux_Authorization::getInstance();
     if ($auth->actionAllowed($moduleName, $actionName) === false) {
         if (!Flux::$sessionData->isLoggedIn()) {
             Flux::$sessionData->setMessageData('Please log-in to continue.');
             $this->loginRequired($baseURI);
         } else {
             $moduleName = 'unauthorized';
             $actionName = $this->defaultAction;
         }
     }
     $params->set('module', $moduleName);
     $params->set('action', $actionName);
     $templateArray = array('params' => $params, 'basePath' => $basePath, 'modulePath' => $modulePath, 'moduleName' => $moduleName, 'themePath' => $themePath, 'themeName' => $themeName, 'actionName' => $actionName, 'viewName' => $actionName, 'headerName' => 'header', 'footerName' => 'footer', 'missingActionModuleAction' => $missingActionModuleAction, 'missingViewModuleAction' => $missingViewModuleAction, 'useCleanUrls' => $useCleanUrls);
     $templateConfig = new Flux_Config($templateArray);
     $template = new Flux_Template($templateConfig);
     // Default data available to all actions and views.
     $data = array('auth' => Flux_Authorization::getInstance(), 'session' => Flux::$sessionData, 'params' => $params);
     $template->setDefaultData($data);
     // Render template! :D
     $template->render();
 }