예제 #1
0
 /**
  * start a session
  */
 public static function start()
 {
     $params =& $GLOBALS['gJConfig']->sessions;
     // do not start the session if the request is made from the command line or if sessions are disabled in configuration
     if ($GLOBALS['gJCoord']->request instanceof jCmdLineRequest || !$params['start']) {
         return false;
     }
     //make sure that the session cookie is only for the current application
     if (!$params['shared_session']) {
         session_set_cookie_params(0, $GLOBALS['gJConfig']->urlengine['basePath']);
     }
     if ($params['storage'] != '') {
         /* on debian/ubuntu (maybe others), garbage collector launch probability is set to 0
            and replaced by a simple cron job which is not enough for jSession (different path, db storage, ...),
            so we set it to 1 as PHP's default value */
         if (!ini_get('session.gc_probability')) {
             ini_set('session.gc_probability', '1');
         }
         switch ($params['storage']) {
             case 'dao':
                 session_set_save_handler(array(__CLASS__, 'daoOpen'), array(__CLASS__, 'daoClose'), array(__CLASS__, 'daoRead'), array(__CLASS__, 'daoWrite'), array(__CLASS__, 'daoDestroy'), array(__CLASS__, 'daoGarbageCollector'));
                 self::$_params = $params;
                 break;
             case 'files':
                 session_save_path($params['files_path']);
                 break;
         }
     }
     if ($params['name'] != '') {
         #ifnot ENABLE_OPTIMIZED_SOURCE
         if (!preg_match('#^[a-zA-Z0-9]+$#', $params['name'])) {
             // regexp check because session name can only be alpha numeric according to the php documentation
             throw new jException('jelix~errors.jsession.name.invalid');
         }
         #endif
         session_name($params['name']);
     }
     if (isset($params['_class_to_load'])) {
         foreach ($params['_class_to_load'] as $file) {
             require_once $file;
         }
     }
     session_start();
     return true;
 }
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     $errorLog->setFormat(jApp::config()->error_handling['messageLogFormat']);
     jLog::log($errorLog, $type);
     $this->allErrorMessages[] = $errorLog;
     if ($type != 'error') {
         return;
     }
     $this->errorMessage = $errorLog;
     while (ob_get_level() && @ob_end_clean()) {
     }
     if ($this->response) {
         $resp = $this->response;
     } else {
         require_once JELIX_LIB_CORE_PATH . 'response/jResponseCmdline.class.php';
         $resp = $this->response = new jResponseCmdline();
     }
     $resp->outputErrors();
     jSession::end();
     exit(1);
 }
예제 #3
0
 /**
  * main method : launch the execution of the action.
  *
  * This method should be called in a entry point.
  *
  * @param  jRequest  $request the request object. It is required if a descendant of jCoordinator did not called setRequest before
  */
 public function process($request = null)
 {
     jLog::log("process: start");
     try {
         if ($request) {
             $this->setRequest($request);
         }
         jSession::start();
         $ctrl = $this->getController($this->action);
     } catch (jException $e) {
         $config = jApp::config();
         if ($config->urlengine['notfoundAct'] == '') {
             throw $e;
         }
         if (!jSession::isStarted()) {
             jSession::start();
         }
         try {
             jLog::log("Exception: get notfoundact ctrl (" . $config->urlengine['notfoundAct'] . ")");
             $this->action = new jSelectorAct($config->urlengine['notfoundAct']);
             $ctrl = $this->getController($this->action);
         } catch (jException $e2) {
             throw $e;
         }
     }
     jApp::pushCurrentModule($this->moduleName);
     if (count($this->plugins)) {
         $pluginparams = array();
         if (isset($ctrl->pluginParams['*'])) {
             $pluginparams = $ctrl->pluginParams['*'];
         }
         if (isset($ctrl->pluginParams[$this->action->method])) {
             $pluginparams = array_merge($pluginparams, $ctrl->pluginParams[$this->action->method]);
         }
         jLog::dump($pluginparams, "process: plugin params");
         foreach ($this->plugins as $name => $obj) {
             jLog::log("process: beforeAction on plugin {$name}");
             $result = $this->plugins[$name]->beforeAction($pluginparams);
             if ($result) {
                 $this->action = $result;
                 jApp::popCurrentModule();
                 jApp::pushCurrentModule($result->module);
                 jLog::log("process: beforeAction said to do internal redirect to " . $result->module . "~" . $result->resource);
                 $this->moduleName = $result->module;
                 $this->actionName = $result->resource;
                 $ctrl = $this->getController($this->action);
                 break;
             }
         }
     }
     jLog::log('process: call action');
     $this->response = $ctrl->{$this->action->method}();
     if ($this->response == null) {
         throw new jException('jelix~errors.response.missing', $this->action->toString());
     }
     jLog::log('process: response: ' . get_class($this->response));
     if (get_class($this->response) == 'jResponseRedirect') {
         jLog::log('process: redirection to ' . $this->response->action);
     } else {
         if (get_class($this->response) == 'jResponseRedirectUrl') {
             jLog::log('process: redirection to ' . $this->response->url);
         }
     }
     foreach ($this->plugins as $name => $obj) {
         jLog::log('process: beforeOutput on plugin ' . $name);
         $this->plugins[$name]->beforeOutput();
     }
     jLog::log('process: call response output');
     $this->response->output();
     foreach ($this->plugins as $name => $obj) {
         jLog::log('process: afterProcess on plugin ' . $name);
         $this->plugins[$name]->afterProcess();
     }
     jApp::popCurrentModule();
     jSession::end();
     jLog::log('process: end');
 }
					<ul class="nav pull-right">
						<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php 
echo $user->name;
?>
<b class="caret"></b></a>
							<ul class="dropdown-menu">
								<li class=""><a href="<?php 
echo jRoute::_('index.php?option=com_virtuemart&view=user');
?>
"><i class="icon icon-user"></i> <?php 
echo jText::_('COM_VIRTUEMART_YOUR_ACCOUNT_DETAILS');
?>
</a></li>
								<li class="divider"></li>
								<li class=""><a href="<?php 
echo jRoute::_('index.php?option=com_users&task=user.logout&' . jSession::getFormToken() . '=1&return=' . base64_encode('index.php?option=com_virtuemart'));
?>
"><i class="icon icon-exit"></i> <?php 
echo jText::_('COM_VIRTUEMART_BUTTON_LOGOUT');
?>
</a></li>
							</ul>
						</li>
					</ul>
				</div>
			</div>
		</div>
	</nav>
	<?php 
if (count($messages)) {
    foreach ($messages as $message) {
예제 #5
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     if ($this->request) {
         // we have config, so we can process "normally"
         $errorLog->setFormat($gJConfig->error_handling['messageLogFormat']);
         jLog::log($errorLog, $type);
         // if non fatal error, it is finished
         if ($type != 'error') {
             return;
         }
         $this->errorMessage = $errorLog;
         while (ob_get_level()) {
             ob_end_clean();
         }
         $resp = $this->request->getErrorResponse($this->response);
         $resp->outputErrors();
         jSession::end();
     } elseif ($type != 'error') {
         $this->initErrorMessages[] = $errorLog;
         return;
     } else {
         // fatal error appeared during init, let's display an HTML page
         // since we don't know the request, we cannot return a response
         // corresponding to the expected protocol
         while (ob_get_level()) {
             ob_end_clean();
         }
         // log into file
         @error_log($errorLog->getFormatedMessage(), 3, jApp::logPath('errors.log'));
         // if accept text/html
         if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
             if (file_exists(jApp::appPath('responses/error.en_US.php'))) {
                 $file = jApp::appPath('responses/error.en_US.php');
             } else {
                 $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
             }
             $HEADBOTTOM = '';
             $BODYTOP = '';
             $BODYBOTTOM = '';
             $basePath = '';
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/html');
             include $file;
         } else {
             // output text response
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/plain');
             echo 'Error during initialization.';
         }
     }
     exit(1);
 }
예제 #6
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     $errorLog->setFormat(jApp::config()->error_handling['messageLogFormat']);
     jLog::log($errorLog, $type);
     // if non fatal error, it is finished, continue the execution of the action
     if ($type != 'error') {
         return;
     }
     $this->errorMessage = $errorLog;
     while (ob_get_level() && @ob_end_clean()) {
     }
     $resp = $this->request->getErrorResponse($this->response);
     $resp->outputErrors();
     jSession::end();
     exit(1);
 }
예제 #7
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * Responses object should take care of the errorMessages property to display errors.
  * @param string  $toDo    a string which contains keyword indicating what to do with the error
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($toDo, $type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $conf = $gJConfig->error_handling;
     $doEchoByResponse = true;
     if ($this->request == null) {
         $message = 'JELIX PANIC ! Error during initialization !! ' . $message;
         $doEchoByResponse = false;
         $toDo .= ' EXIT';
     } elseif ($this->response == null) {
         $ret = $this->initDefaultResponseOfRequest();
         if (is_string($ret)) {
             $message = 'Double error ! 1)' . $ret . '; 2)' . $message;
             $doEchoByResponse = false;
         }
     }
     // When we are in cmdline we need to fix the remoteAddr
     $remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // url params including module and action
     if ($this->request) {
         $url = str_replace('array', 'url', var_export($this->request->params, true));
     } else {
         $url = 'Unknow url';
     }
     // formatting message
     $messageLog = strtr($conf['messageLogFormat'], array('%date%' => date("Y-m-d H:i:s"), '%ip%' => $remoteAddr, '%typeerror%' => $type, '%code%' => $code, '%msg%' => $message, '%url%' => $url, '%file%' => $file, '%line%' => $line, '\\t' => "\t", '\\n' => "\n"));
     if (strpos($toDo, 'TRACE') !== false) {
         $arr = debug_backtrace();
         $messageLog .= "\ttrace:";
         foreach ($arr as $k => $t) {
             $messageLog .= "\n\t{$k}\t" . (isset($t['class']) ? $t['class'] . $t['type'] : '') . $t['function'] . "()\t";
             $messageLog .= (isset($t['file']) ? $t['file'] : '[php]') . ' : ' . (isset($t['line']) ? $t['line'] : '');
         }
         $messageLog .= "\n";
     }
     $echoAsked = false;
     // traitement du message
     if (strpos($toDo, 'ECHOQUIET') !== false) {
         $echoAsked = true;
         if (!$doEchoByResponse) {
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/plain');
             echo 'JELIX PANIC ! Error during initialization !! ';
         } elseif ($this->addErrorMsg($type, $code, $conf['quietMessage'], '', '')) {
             $toDo .= ' EXIT';
         }
     } elseif (strpos($toDo, 'ECHO') !== false) {
         $echoAsked = true;
         if (!$doEchoByResponse) {
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/plain');
             echo $messageLog;
         } elseif ($this->addErrorMsg($type, $code, $message, $file, $line)) {
             $toDo .= ' EXIT';
         }
     }
     if (strpos($toDo, 'LOGFILE') !== false) {
         @error_log($messageLog, 3, JELIX_APP_LOG_PATH . $conf['logFile']);
     }
     if (strpos($toDo, 'MAIL') !== false) {
         error_log(wordwrap($messageLog, 70), 1, $conf['email'], $conf['emailHeaders']);
     }
     if (strpos($toDo, 'SYSLOG') !== false) {
         error_log($messageLog, 0);
     }
     if (strpos($toDo, 'EXIT') !== false) {
         if ($doEchoByResponse) {
             if ($this->response) {
                 $this->response->outputErrors();
             } else {
                 if ($echoAsked) {
                     header("HTTP/1.1 500 Internal jelix error");
                     header('Content-type: text/plain');
                     foreach ($this->errorMessages as $msg) {
                         echo $msg . "\n";
                     }
                 }
             }
         }
         jSession::end();
         exit;
     }
 }
예제 #8
0
 public static function start()
 {
     $params =& jApp::config()->sessions;
     if (jApp::coord()->request instanceof jCmdLineRequest || !$params['start']) {
         return false;
     }
     if (!$params['shared_session']) {
         session_set_cookie_params(0, jApp::config()->urlengine['basePath']);
     }
     if ($params['storage'] != '') {
         if (!ini_get('session.gc_probability')) {
             ini_set('session.gc_probability', '1');
         }
         switch ($params['storage']) {
             case 'dao':
                 session_set_save_handler(array(__CLASS__, 'daoOpen'), array(__CLASS__, 'daoClose'), array(__CLASS__, 'daoRead'), array(__CLASS__, 'daoWrite'), array(__CLASS__, 'daoDestroy'), array(__CLASS__, 'daoGarbageCollector'));
                 self::$_params = $params;
                 break;
             case 'files':
                 session_save_path($params['files_path']);
                 break;
         }
     }
     if ($params['name'] != '') {
         session_name($params['name']);
     }
     if (isset($params['_class_to_load'])) {
         foreach ($params['_class_to_load'] as $file) {
             require_once $file;
         }
     }
     session_start();
     return true;
 }
예제 #9
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     if ($this->request) {
         // we have config, so we can process "normally"
         $errorLog->setFormat($gJConfig->error_handling['messageLogFormat']);
         jLog::log($errorLog, $type);
         $this->allErrorMessages[] = $errorLog;
         // if non fatal error, it is finished
         if ($type != 'error') {
             return;
         }
         $this->errorMessage = $errorLog;
         while (ob_get_level()) {
             ob_end_clean();
         }
         if ($this->response) {
             $resp = $this->response;
         } else {
             $resp = $this->response = new jResponseCmdline();
         }
         $resp->outputErrors();
         jSession::end();
     } elseif ($type != 'error') {
         $this->allErrorMessages[] = $errorLog;
         $this->initErrorMessages[] = $errorLog;
         return;
     } else {
         // fatal error appeared during init, let's display a single message
         while (ob_get_level()) {
             ob_end_clean();
         }
         // log into file
         @error_log($errorLog->getFormatedMessage(), 3, jApp::logPath('errors.log'));
         // output text response
         echo 'Error during initialization: ' . $message . ' (' . $file . ' ' . $line . ")\n";
     }
     exit(1);
 }