Пример #1
0
 /**
  * Initialization, it sets DB information, request arguments and so on.
  *
  * @see This function should be called only once
  * @return void
  */
 public function init()
 {
     // fix missing HTTP_RAW_POST_DATA in PHP 5.6 and above
     if (!isset($GLOBALS['HTTP_RAW_POST_DATA']) && version_compare(PHP_VERSION, '5.6.0', '>=') === TRUE) {
         $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input");
         // If content is not XML or JSON, unset
         if (!preg_match('/^[\\<\\{\\[]/', $GLOBALS['HTTP_RAW_POST_DATA'])) {
             unset($GLOBALS['HTTP_RAW_POST_DATA']);
         }
     }
     // set context variables in $GLOBALS (backward compatibility)
     $GLOBALS['__Context__'] = $this;
     $GLOBALS['lang'] =& $this->lang;
     $this->_COOKIE = $_COOKIE;
     // 20140429 editor/image_link
     $this->_checkGlobalVars();
     $this->setRequestMethod('');
     $this->_setXmlRpcArgument();
     $this->_setJSONRequestArgument();
     $this->_setRequestArgument();
     $this->_setUploadedArgument();
     $this->loadDBInfo();
     if ($this->db_info->use_sitelock == 'Y') {
         if (is_array($this->db_info->sitelock_whitelist)) {
             $whitelist = $this->db_info->sitelock_whitelist;
         }
         if (!IpFilter::filter($whitelist)) {
             $title = $this->db_info->sitelock_title ? $this->db_info->sitelock_title : 'Maintenance in progress...';
             $message = $this->db_info->sitelock_message;
             define('_XE_SITELOCK_', TRUE);
             define('_XE_SITELOCK_TITLE_', $title);
             define('_XE_SITELOCK_MESSAGE_', $message);
             header("HTTP/1.1 403 Forbidden");
             if (FileHandler::exists(_XE_PATH_ . 'common/tpl/sitelock.user.html')) {
                 include _XE_PATH_ . 'common/tpl/sitelock.user.html';
             } else {
                 include _XE_PATH_ . 'common/tpl/sitelock.html';
             }
             exit;
         }
     }
     // If XE is installed, get virtual site information
     if (self::isInstalled()) {
         $oModuleModel = getModel('module');
         $site_module_info = $oModuleModel->getDefaultMid();
         if (!isset($site_module_info)) {
             $site_module_info = new stdClass();
         }
         // if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config
         if ($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url) {
             $site_module_info->domain = $this->db_info->default_url;
         }
         self::set('site_module_info', $site_module_info);
         if ($site_module_info->site_srl && isSiteID($site_module_info->domain)) {
             self::set('vid', $site_module_info->domain, TRUE);
         }
         if (!isset($this->db_info)) {
             $this->db_info = new stdClass();
         }
         $this->db_info->lang_type = $site_module_info->default_language;
         if (!$this->db_info->lang_type) {
             $this->db_info->lang_type = 'ko';
         }
         if (!$this->db_info->use_db_session) {
             $this->db_info->use_db_session = 'N';
         }
     }
     // Load Language File
     $lang_supported = self::loadLangSelected();
     // Retrieve language type set in user's cookie
     if ($this->lang_type = self::get('l')) {
         if ($_COOKIE['lang_type'] != $this->lang_type) {
             setcookie('lang_type', $this->lang_type, $_SERVER['REQUEST_TIME'] + 3600 * 24 * 1000, '/');
         }
     } elseif ($_COOKIE['lang_type']) {
         $this->lang_type = $_COOKIE['lang_type'];
     }
     // If it's not exists, follow default language type set in db_info
     if (!$this->lang_type) {
         $this->lang_type = $this->db_info->lang_type;
     }
     // if still lang_type has not been set or has not-supported type , set as Korean.
     if (!$this->lang_type) {
         $this->lang_type = 'ko';
     }
     if (is_array($lang_supported) && !isset($lang_supported[$this->lang_type])) {
         $this->lang_type = 'ko';
     }
     self::set('lang_supported', $lang_supported);
     self::setLangType($this->lang_type);
     // Load languages
     $this->lang = Rhymix\Framework\Lang::getInstance($this->lang_type);
     $this->lang->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
     $this->lang->loadDirectory(RX_BASEDIR . 'modules/module/lang', 'module');
     // set session handler
     if (self::isInstalled() && $this->db_info->use_db_session == 'Y') {
         $oSessionModel = getModel('session');
         $oSessionController = getController('session');
         session_set_save_handler(array(&$oSessionController, 'open'), array(&$oSessionController, 'close'), array(&$oSessionModel, 'read'), array(&$oSessionController, 'write'), array(&$oSessionController, 'destroy'), array(&$oSessionController, 'gc'));
     }
     // start session if it was previously started
     $session_name = session_name();
     $session_id = NULL;
     if ($session_id = $_POST[$session_name]) {
         session_id($session_id);
     } else {
         $session_id = $_COOKIE[$session_name];
     }
     if ($session_id !== NULL || $this->db_info->delay_session != 'Y') {
         $this->setCacheControl(0, false);
         session_start();
     } else {
         ob_start();
         $this->setCacheControl(-1, true);
         register_shutdown_function(array($this, 'checkSessionStatus'));
         $_SESSION = array();
     }
     // set authentication information in Context and session
     if (self::isInstalled()) {
         $oModuleModel = getModel('module');
         $oModuleModel->loadModuleExtends();
         $oMemberModel = getModel('member');
         $oMemberController = getController('member');
         if ($oMemberController && $oMemberModel) {
             // if signed in, validate it.
             if ($oMemberModel->isLogged()) {
                 $oMemberController->setSessionInfo();
             } elseif ($_COOKIE['xeak']) {
                 $oMemberController->doAutologin();
             }
             self::set('is_logged', $oMemberModel->isLogged());
             if ($oMemberModel->isLogged()) {
                 self::set('logged_info', $oMemberModel->getLoggedInfo());
             }
         }
     }
     // check if using rewrite module
     $this->allow_rewrite = $this->db_info->use_rewrite == 'Y' ? TRUE : FALSE;
     // set locations for javascript use
     $url = array();
     $current_url = self::getRequestUri();
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         if ($this->get_vars) {
             $url = array();
             foreach ($this->get_vars as $key => $val) {
                 if (is_array($val) && count($val) > 0) {
                     foreach ($val as $k => $v) {
                         $url[] = $key . '[' . $k . ']=' . urlencode($v);
                     }
                 } elseif ($val) {
                     $url[] = $key . '=' . urlencode($val);
                 }
             }
             $current_url = self::getRequestUri();
             if ($url) {
                 $current_url .= '?' . join('&', $url);
             }
         } else {
             $current_url = self::getUrl();
         }
     } else {
         $current_url = self::getRequestUri();
     }
     self::set('current_url', $current_url);
     self::set('request_uri', self::getRequestUri());
     if (strpos($current_url, 'xn--') !== FALSE) {
         self::set('current_url', self::decodeIdna($current_url));
     }
     if (strpos(self::getRequestUri(), 'xn--') !== FALSE) {
         self::set('request_uri', self::decodeIdna(self::getRequestUri()));
     }
 }
Пример #2
0
/**
 * Get is current user crawler
 *
 * @param string $agent if set, use this value instead HTTP_USER_AGENT
 * @return bool
 */
function isCrawler($agent = NULL)
{
    if (!$agent) {
        $agent = $_SERVER['HTTP_USER_AGENT'];
    }
    $check_agent = array('bot', 'spider', 'spyder', 'crawl', 'http://', 'google', 'yahoo', 'slurp', 'yeti', 'daum', 'teoma', 'fish', 'hanrss', 'facebook', 'yandex', 'infoseek', 'askjeeves', 'stackrambler');
    $check_ip = array();
    foreach ($check_agent as $str) {
        if (stristr($agent, $str) != FALSE) {
            return TRUE;
        }
    }
    return IpFilter::filter($check_ip);
}
Пример #3
0
 /**
  * Initialization, it sets DB information, request arguments and so on.
  *
  * @see This function should be called only once
  * @return void
  */
 function init()
 {
     // set context variables in $GLOBALS (to use in display handler)
     $this->context =& $GLOBALS['__Context__'];
     $this->context->lang =& $GLOBALS['lang'];
     $this->context->_COOKIE = $_COOKIE;
     // 20140429 editor/image_link
     $this->_checkGlobalVars();
     $this->setRequestMethod('');
     $this->_setXmlRpcArgument();
     $this->_setJSONRequestArgument();
     $this->_setRequestArgument();
     $this->_setUploadedArgument();
     $this->loadDBInfo();
     if ($this->db_info->use_sitelock == 'Y') {
         if (is_array($this->db_info->sitelock_whitelist)) {
             $whitelist = $this->db_info->sitelock_whitelist;
         }
         if (!IpFilter::filter($whitelist)) {
             $title = $this->db_info->sitelock_title ? $this->db_info->sitelock_title : 'Maintenance in progress...';
             $message = $this->db_info->sitelock_message;
             define('_XE_SITELOCK_', TRUE);
             define('_XE_SITELOCK_TITLE_', $title);
             define('_XE_SITELOCK_MESSAGE_', $message);
             header("HTTP/1.1 403 Forbidden");
             include _XE_PATH_ . 'common/tpl/sitelock.html';
             exit;
         }
     }
     // If XE is installed, get virtual site information
     if (self::isInstalled()) {
         $oModuleModel = getModel('module');
         $site_module_info = $oModuleModel->getDefaultMid();
         if (!isset($site_module_info)) {
             $site_module_info = new stdClass();
         }
         // if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config
         if ($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url) {
             $site_module_info->domain = $this->db_info->default_url;
         }
         $this->set('site_module_info', $site_module_info);
         if ($site_module_info->site_srl && isSiteID($site_module_info->domain)) {
             $this->set('vid', $site_module_info->domain, TRUE);
         }
         if (!isset($this->db_info)) {
             $this->db_info = new stdClass();
         }
         $this->db_info->lang_type = $site_module_info->default_language;
         if (!$this->db_info->lang_type) {
             $this->db_info->lang_type = 'en';
         }
         if (!$this->db_info->use_db_session) {
             $this->db_info->use_db_session = 'N';
         }
     }
     // Load Language File
     $lang_supported = $this->loadLangSelected();
     // Retrieve language type set in user's cookie
     if ($this->lang_type = $this->get('l')) {
         if ($_COOKIE['lang_type'] != $this->lang_type) {
             setcookie('lang_type', $this->lang_type, $_SERVER['REQUEST_TIME'] + 3600 * 24 * 1000, '/');
         }
     } elseif ($_COOKIE['lang_type']) {
         $this->lang_type = $_COOKIE['lang_type'];
     }
     // If it's not exists, follow default language type set in db_info
     if (!$this->lang_type) {
         $this->lang_type = $this->db_info->lang_type;
     }
     // if still lang_type has not been set or has not-supported type , set as English.
     if (!$this->lang_type) {
         $this->lang_type = 'en';
     }
     if (is_array($lang_supported) && !isset($lang_supported[$this->lang_type])) {
         $this->lang_type = 'en';
     }
     $this->set('lang_supported', $lang_supported);
     $this->setLangType($this->lang_type);
     // load module module's language file according to language setting
     $this->loadLang(_XE_PATH_ . 'modules/module/lang');
     // set session handler
     if (self::isInstalled() && $this->db_info->use_db_session == 'Y') {
         $oSessionModel = getModel('session');
         $oSessionController = getController('session');
         session_set_save_handler(array(&$oSessionController, 'open'), array(&$oSessionController, 'close'), array(&$oSessionModel, 'read'), array(&$oSessionController, 'write'), array(&$oSessionController, 'destroy'), array(&$oSessionController, 'gc'));
     }
     session_start();
     if ($sess = $_POST[session_name()]) {
         session_id($sess);
     }
     // set authentication information in Context and session
     if (self::isInstalled()) {
         $oModuleModel = getModel('module');
         $oModuleModel->loadModuleExtends();
         $oMemberModel = getModel('member');
         $oMemberController = getController('member');
         if ($oMemberController && $oMemberModel) {
             // if signed in, validate it.
             if ($oMemberModel->isLogged()) {
                 $oMemberController->setSessionInfo();
             } elseif ($_COOKIE['xeak']) {
                 $oMemberController->doAutologin();
             }
             $this->set('is_logged', $oMemberModel->isLogged());
             $this->set('logged_info', $oMemberModel->getLoggedInfo());
         }
     }
     // load common language file
     $this->lang =& $GLOBALS['lang'];
     $this->loadLang(_XE_PATH_ . 'common/lang/');
     // check if using rewrite module
     $this->allow_rewrite = $this->db_info->use_rewrite == 'Y' ? TRUE : FALSE;
     // set locations for javascript use
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         if ($this->get_vars) {
             $url = array();
             foreach ($this->get_vars as $key => $val) {
                 if (is_array($val) && count($val) > 0) {
                     foreach ($val as $k => $v) {
                         $url[] = $key . '[' . $k . ']=' . urlencode($v);
                     }
                 } elseif ($val) {
                     $url[] = $key . '=' . urlencode($val);
                 }
             }
             $this->set('current_url', self::getRequestUri() . '?' . join('&', $url));
         } else {
             $this->set('current_url', $this->getUrl());
         }
     } else {
         $this->set('current_url', self::getRequestUri());
     }
     $this->set('request_uri', self::getRequestUri());
 }
Пример #4
0
 /**
  * check allowed target ip address when  login for admin. 
  *
  * @return boolean (true : allowed, false : refuse)
  */
 function getMemberAdminIPCheck()
 {
     $db_info = Context::getDBInfo();
     $admin_ip_list = $db_info->admin_ip_list;
     if (!$admin_ip_list) {
         return true;
     }
     if (!is_array($admin_ip_list)) {
         $admin_ip_list = explode(',', $admin_ip_list);
     }
     if (!count($admin_ip_list) || IpFilter::filter($admin_ip_list)) {
         return true;
     } else {
         return false;
     }
 }
Пример #5
0
/**
 * Get is current user crawler
 *
 * @param string $agent if set, use this value instead HTTP_USER_AGENT
 * @return bool
 */
function isCrawler($agent = NULL)
{
    if (!$agent) {
        $agent = $_SERVER['HTTP_USER_AGENT'];
    }
    $check_agent = array('bot', 'spider', 'google', 'yahoo', 'daum', 'teoma', 'fish', 'hanrss', 'facebook');
    $check_ip = array('211.245.21.110-211.245.21.119');
    foreach ($check_agent as $str) {
        if (stristr($agent, $str) != FALSE) {
            return TRUE;
        }
    }
    return IpFilter::filter($check_ip);
}