public function __get($name)
 {
     if ($name == 'tpl') {
         if (!$this->_templateInitialized) {
             $this->initTemplate();
         }
         return $this->_template;
     }
     if ($name == 'router') {
         return Router::getInstance();
     }
     if ($name == 'session') {
         return Session::getInstance();
     }
     if ($name == 'config') {
         return Config::getInstance();
     }
     if ($name == 'log') {
         return Logger::getInstance();
     }
     if ($name == 'language') {
         return Language::getInstance();
     }
     if ($name == 'model') {
         return Model::getInstance();
     }
 }
Exemplo n.º 2
0
 function invalidate($sid = null)
 {
     if ($sid === null) {
         $sid = $this->request()->meta('sid');
     }
     return Session::invalidate($sid);
 }
Exemplo n.º 3
0
 public function __invoke(array $record)
 {
     if ($record['level'] < $this->level) {
         return $record;
     }
     if (Session::current()) {
         $record['extra']['user'] = (int) Session::current('UserID');
     } else {
         if (is_numeric(@Process::get('type'))) {
             $record['extra']['user'] = (int) Process::get('type');
         }
     }
     return $record;
 }
Exemplo n.º 4
0
 public function resolve(Request $req, Response $res)
 {
     $req->user = new User();
     // User from CLI
     switch ($req->client('type')) {
         case 'cli':
             // Retrieve user context from process data, then CLI argument.
             $userId = (int) Process::get('type');
             if (!$userId) {
                 $req->cli()->options('u', array('alias' => 'user', 'type' => 'integer', 'describe' => 'Idenitfier of target context user.'));
                 $userId = (int) $req->meta('user');
             }
             if ($userId) {
                 $req->user->load($userId);
             }
             unset($userId);
             break;
         default:
             // Session ID provided, validate it.
             $sid = $req->meta('sid');
             if ($sid) {
                 $ret = Session::ensure($sid, $req->meta('token'), $req->fingerprint());
                 // Session doesn't exist, delete the cookie.
                 if ($ret === false || $ret === Session::ERR_EXPIRED) {
                     $res->cookie('__sid', '', time() - 3600);
                 } else {
                     if (is_integer($ret)) {
                         switch ($ret) {
                             // note: System should treat as public user.
                             case Session::ERR_INVALID:
                                 break;
                         }
                     } else {
                         // Success, proceed.
                         $req->user->load(Session::current('username'));
                         unset($req->user->password);
                     }
                 }
             } else {
                 if ($this->setupSession && !@\core\Node::get('User')) {
                     $req->user->data(['id' => 0, 'groups' => ['Administrators'], 'username' => '__default']);
                 }
             }
             break;
     }
 }
Exemplo n.º 5
0
}
if (defined('LOGGER_MAIL') && LOGGER_MAIL && defined('LOGGER_MAIL_TO_EMAIL') && defined('LOGGER_MAIL_TO_NAME') && !static::getDebug()) {
    $mailConfig = array('fromEmail' => ADMIN_EMAIL, 'fromName' => $language->getVar('site_name'), 'toEmail' => LOGGER_MAIL_TO_EMAIL, 'toName' => LOGGER_MAIL_TO_NAME, 'mailSubject' => $language->getVar('site_name') . '  logs');
    $log->attach(new Mail($mailConfig));
}
if (defined('LOGGER_ERROR') && LOGGER_ERROR) {
    $exc->attach(new Log());
    $err->attach(new Log());
}
// Config router host
if (!defined('HOSTNAME')) {
    throw new \Exception('Miss hostname constant');
}
Router::setHost(HOSTNAME);
// Auto set language, by session
$languageLoaded = Language::getInstance()->getLanguage();
$langSession = Session::getInstance()->get('language');
if (!is_null($langSession) && $langSession != $languageLoaded) {
    $language->setLanguage($langSession);
    $languageLoaded = $langSession;
}
// Auto set language, by cookie
$langCookie = Cookie::get('language');
if (!is_null($langCookie) && $langCookie != $languageLoaded) {
    $language->setLanguage($langCookie);
    $languageLoaded = $langSession;
}
// Security
Security::autorun();
// Clean
unset($bench, $globalizer, $language, $exc, $err, $log);
Exemplo n.º 6
0
 protected function _check($ip, $userAgent)
 {
     if (Http::getQuery($this->_trapName) && !Validate::isGoogleBot()) {
         $isBadCrawler = false;
         $isGoodCrawler = false;
         if ($this->_badCrawlerFile) {
             $badCrawlerXml = simplexml_load_file($this->_badCrawlerFile);
             if (is_null($badCrawlerXml) || !$badCrawlerXml) {
                 throw new \Exception('Invalid xml file : "' . $this->_badCrawlerFile . '"');
             }
         }
         if ($this->_goodCrawlerFile) {
             $goodCrawlerXml = simplexml_load_file($this->_goodCrawlerFile);
             if (is_null($goodCrawlerXml) || !$goodCrawlerXml) {
                 throw new \Exception('Invalid xml file : "' . $this->_goodCrawlerFile . '"');
             }
         }
         if ($badCrawlerXml) {
             $badCrawlerList = $badCrawlerXml->crawler;
             foreach ($badCrawlerList as $crawler) {
                 if (isset($crawler->ip) && (string) $crawler->ip == $ip) {
                     $isBadCrawler = true;
                 }
                 if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) {
                     $isBadCrawler = true;
                 }
                 if ($isBadCrawler) {
                     $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
                     Session::getInstance()->add(md5($ip . 'badcrawler'), true, true, true);
                     Router::getInstance()->show403(true);
                     break;
                 }
             }
             unset($crawler);
         }
         if ($goodCrawlerXml) {
             $goodCrawlerList = $goodCrawlerXml->crawler;
             foreach ($goodCrawlerList as $crawler) {
                 if (isset($crawler->ip) && (string) $crawler->ip == $ip) {
                     $isGoodCrawler = true;
                 }
                 if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) {
                     $isGoodCrawler = true;
                 }
                 if ($isGoodCrawler) {
                     $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
                     break;
                 }
             }
             unset($crawler);
         }
         // unknown
         if (!$isBadCrawler && !$isGoodCrawler) {
             $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
         }
     }
 }
Exemplo n.º 7
0
 public static function isConnected()
 {
     return Session::getInstance()->get('isConnected');
 }
Exemplo n.º 8
0
 protected function _display($captchaType)
 {
     $this->create(Session::getInstance()->get($this->getFormName() . 'Captcha'), $captchaType);
     Header::sentHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
     Header::sentHeader('Cache-Control', 'post-check=0, pre-check=0', false);
     Header::sentHeader('Pragma', 'no-cache');
     Header::sentHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
     if ($captchaType == 'image') {
         Header::sentHeader('Content-Type', 'image/' . $this->_imageFormat);
         // display captcha
         switch ($this->_imageFormat) {
             case 'png':
                 imagepng($this->_imageContents);
                 break;
             case 'jpg':
                 imagejpeg($this->_imageContents);
                 break;
             case 'gif':
                 imagegif($this->_imageContents);
                 break;
         }
     } elseif ($captchaType == 'audio') {
         Header::sentHeader('Content-Type', 'audio/x-wav');
         Header::sentHeader('Content-Length', (string) strlen($this->_audioContents));
         // display captcha
         echo $this->_audioContents;
     }
 }
Exemplo n.º 9
0
 public function flush()
 {
     Session::getInstance()->delete($this->getFormName() . 'CsrfToken', true);
     if ($this->_timeValidity > 0) {
         Session::getInstance()->delete($this->getFormName() . 'CsrfTokenTime', true);
     }
     $this->_token = null;
 }