kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Source for file setup_inc.php

Documentation is available at setup_inc.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package kernel
  5.  * @subpackage functions
  6.  */
  7.  
  8. // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  9. // All Rights Reserved. See below for details and a complete list of authors.
  10. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  11. /**
  12.  * required setup
  13.  */
  14.  
  15. //ini_set( 'session.save_path', 'C:\somewhere\I\can\write' );
  16. $rootDir dirnamedirname__FILE__ ) );
  17. define'BIT_ROOT_PATH'empty$_SERVER['VHOST_DIR'$rootDir.'/' $_SERVER['VHOST_DIR'].'/' );
  18.  
  19. // immediately die on request to hack our database
  20. if(( !empty$_REQUEST['sort_mode'&& !is_array$_REQUEST['sort_mode'&& strpos$_REQUEST['sort_mode']'http' !== FALSE || !empty$_REQUEST['PGV_BASE_DIRECTORY'&& strpos$_REQUEST['PGV_BASE_DIRECTORY']'http' !== FALSE )) {
  21.     die;
  22. }
  23.  
  24. require_oncedirname__FILE__ ).'/bit_error_inc.php' );
  25. require_onceBIT_ROOT_PATH.'kernel/config_defaults_inc.php' );
  26. require_onceKERNEL_PKG_PATH.'kernel_lib.php' );
  27. require_onceKERNEL_PKG_PATH.'BitTimer.php' );
  28.  
  29. // set error reporting
  30.  
  31. // this is evil stuff and causes hell for us
  32. ini_set'session.use_trans_sid''Off' );
  33.  
  34. ifini_get'safe_mode' && ini_get'safe_mode_gid' )) {
  35.     umask0007 );
  36. }
  37.  
  38. // clean up $_GET and make sure others are clean as well
  39. if!empty$_GET && is_array$_GET && empty$gNoToxify ) ) {
  40.     detoxify$_GETTRUEFALSE );
  41.     $_REQUEST array_merge$_REQUEST$_GET );
  42. }
  43.  
  44. // Force a global ADODB db object so all classes share the same connection
  45. $dbClass 'BitDbAdodb';
  46. if!empty$gBitSystem ) ) {
  47.     switch$gBitDbSystem {
  48.         case 'pear':
  49.             $dbClass 'BitDbPear';
  50.             break;
  51.         default:
  52.             $dbClass 'BitDbAdodb';
  53.             break;
  54.     }
  55. }
  56. // the installer and select admin pages required DataDict to verify package installation
  57. global $gForceAdodb;
  58. if!empty$gForceAdodb )) {
  59.     $dbClass 'BitDbAdodb';
  60. }
  61. require_onceKERNEL_PKG_PATH.$dbClass.'.php' );
  62.  
  63. // =================== Global Classes ===================
  64. global $gBitDb;
  65. $gBitDb new $dbClass();
  66. ifdefined'QUERY_CACHE_ACTIVE' ) ) {
  67.     $gBitDb->setCaching();
  68. }
  69.  
  70. require_onceKERNEL_PKG_PATH.'BitSystem.php' );
  71. global $gBitSmarty$gBitSystem;
  72.  
  73. // make sure we only create one BitSmarty
  74. if!is_object$gBitSmarty ) ) {
  75.     $gBitSmarty new BitSmarty();
  76.     // set the default handler
  77.     $gBitSmarty->load_filter'pre''tr' );
  78.     // $gBitSmarty->load_filter('output','trimwhitespace');
  79.     ifisset$_REQUEST['highlight') ) {
  80.         $gBitSmarty->load_filter'output''highlight' );
  81.     }
  82. }
  83.  
  84. BitSystem::loadSingleton();
  85.  
  86. // first thing we do, is check to see if our version of bitweaver is up to date.
  87. // we need to know about this before any other package is loaded to ensure that we can exclude stuff that isn't backwards compatible.
  88. // BIT_INSTALL is set by the installer and LOGIN_VALIDATE is set in users/validate.php
  89. if!empty$gBitSystem->mConfig && version_compareMIN_BIT_VERSION$gBitSystem->getVersion()'>' && !defined'BIT_INSTALL' || defined'LOGIN_VALIDATE' ))) {
  90.     define'INSTALLER_FORCE'TRUE );
  91. }
  92.  
  93.  
  94. require_onceLANGUAGES_PKG_PATH.'BitLanguage.php' );
  95. BitLanguage::loadSingleton();
  96.  
  97. // collects information about the browser - needed for various browser specific theme settings
  98. require_onceUTIL_PKG_PATH.'phpsniff/phpSniff.class.php' );
  99. global $gSniffer;
  100. $gSniffer new phpSniff;
  101. $gBitSmarty->assign_by_ref'gBrowserInfo'$gSniffer->_browser_info );
  102.  
  103. // set various classes global
  104. global $gBitUser$gTicket$userlib$gBitDbType$gLibertySystem;
  105.  
  106. if$gBitSystem->isDatabaseValid() ) {
  107.  
  108.     // output compression
  109.     ifini_get'zlib.output_compression' == {
  110.         $gBitSmarty->assign'output_compression''zlib' );
  111.     elseif$gBitSystem->isFeatureActive'site_output_obzip' && !empty$_SERVER['SCRIPT_FILENAME'&& !preg_match'!/download.php$!'$_SERVER['SCRIPT_FILENAME')) {
  112.         ob_start"ob_gzhandler" );
  113.         $gBitSmarty->assign'output_compression''gzip' );
  114.     }
  115.  
  116.     // we need to allow up to 900 chars for this value in our 250 char table column
  117.     $gBitSystem->setConfig'site_keywords',
  118.         $gBitSystem->getConfig'site_keywords' ).
  119.         $gBitSystem->getConfig'site_keywords_1' ).
  120.         $gBitSystem->getConfig'site_keywords_2' ).
  121.         $gBitSystem->getConfig'site_keywords_3' )
  122.     );
  123.  
  124.     $host $gBitSystem->getConfig'kernel_server_name'$_SERVER['HTTP_HOST');
  125.     if!defined('BIT_BASE_URI' ) ) {
  126.         // Added check for IIS $_SERVER['HTTPS'] uses 'off' value - wolff_borg
  127.         define'BIT_BASE_URI''http'.(( !empty$_SERVER['HTTPS'&& $_SERVER['HTTPS'!= 'off' 's' '' ).'://'.$host );
  128.     }
  129.  
  130.     if!defined'BIT_BASE_PATH' ) ) {
  131.         $root_url_count strlenBIT_ROOT_URL );
  132.         $root_path_count strlenBIT_ROOT_PATH );
  133.         $path_end $root_path_count $root_url_count;
  134.         define'BIT_BASE_PATH'BIT_ROOT_URL == "/" BIT_ROOT_PATH substrBIT_ROOT_PATH0$path_end "/" ) );
  135.     }
  136.  
  137.     // Force full URI's for offline or exported content (newsletters, etc.)
  138.     $root !empty$_REQUEST['uri_mode'BIT_BASE_URI BIT_ROOT_URL;
  139.     if$root[strlen($root)-1!= '/' {
  140.         $root .= '/';
  141.     }
  142.     define'UTIL_PKG_URL'$root.'util/' );
  143.     define'LIBERTY_PKG_URL'$root.'liberty/' );
  144.  
  145.     // load only installed and active packages
  146.     $gBitSystem->scanPackages'bit_setup_inc.php'TRUE'active'TRUETRUE );
  147.     $gBitSmarty->scanPackagePluginDirs();
  148.  
  149.     iffile_existsCONFIG_PKG_PATH.'kernel/override_inc.php' ) ) {
  150.         // possible install specific customizations for multi-sites, staging sites, etc.
  151.         require_onceCONFIG_PKG_PATH.'kernel/override_inc.php' );
  152.     }
  153.  
  154.     // some plugins check for active packages, so we do this *after* package scanning
  155.     $gBitSmarty->assign_by_ref'gBitSystem'$gBitSystem );
  156.  
  157.     // some liberty plugins might need to run some functions.
  158.     // it's necessary that we call them early on after scanPackages() has been completed.
  159.     foreach$gLibertySystem->getPluginFunctions'preload_function' as $func {
  160.         $func();
  161.     }
  162.  
  163.     // TODO: XSS security check
  164.     if!empty$_REQUEST['tk'&& empty$_SERVER['bot') ) {
  165.         //$gBitUser->verifyTicket();
  166.     elseif!empty$_SERVER['bot') ) {
  167.     }
  168.  
  169.     // this will register and set up the dropdown menus and the application menus in modules
  170.     require_onceTHEMES_PKG_PATH.'menu_register_inc.php' );
  171.  
  172.     // added for virtual hosting suport
  173.     if!isset$bitdomain )) {
  174.         $bitdomain "";
  175.     else {
  176.         $bitdomain .= "/";
  177.     }
  178.     $gBitSystem->setConfig'bitdomain'$bitdomain );
  179.  
  180.     $gBitSmarty->assign"bitdomain"$bitdomain );
  181.     // Fix IIS servers not setting what they should set (ay ay IIS, ay ay)
  182.     if!isset$_SERVER['QUERY_STRING')) {
  183.         $_SERVER['QUERY_STRING''';
  184.     }
  185.     if!isset$_SERVER['REQUEST_URI'|| empty$_SERVER['REQUEST_URI')) {
  186.         $_SERVER['REQUEST_URI'$_SERVER['SCRIPT_NAME'].'/'.$_SERVER['QUERY_STRING'];
  187.     }
  188.     ifisset$_REQUEST['page')) {
  189.         $_REQUEST['page'strip_tags$_REQUEST['page');
  190.     }
  191.     global $gHideModules;
  192.     $gBitSmarty->assign_by_ref'gHideModules'$gHideModules );
  193.     $keywords $gBitSystem->getConfig'site_keywords' );
  194.     $gBitSmarty->assign_by_ref'metaKeywords'$keywords );
  195.  
  196.     // =================== Kernel ===================
  197.     //$gBitSmarty->assign_by_ref( "gBitSystemPackages", $gBitSystem->mPackages ); doesn't seem to be used - xing
  198.  
  199.     // check to see if admin has closed the site
  200.     if(( isset$_SERVER['SCRIPT_URL'&& $_SERVER['SCRIPT_URL'== USERS_PKG_URL.'validate.php' )) {
  201.         $bypass_siteclose_check 'y';
  202.     }
  203.     ifempty($gShellScript&& $gBitSystem->isFeatureActive'site_closed' && !$gBitUser->hasPermission'p_access_closed_site' && !isset$bypass_siteclose_check )) {
  204.         $_REQUEST['error'$gBitSystem->getConfig('site_closed_msg','&nbsp;');
  205.         includeKERNEL_PKG_PATH 'error_simple.php' );
  206.         exit;
  207.     }
  208.  
  209.     // check to see if max server load threshold is enabled
  210.     $site_use_load_threshold $gBitSystem->getConfig'site_use_load_threshold''n' );
  211.     // get average server load in the last minute. Keep quiet cause virtual hosts can give perm denied or openbase_dir is open_basedir on
  212.     if(@is_readable('/proc/loadavg'&& @($load file('/proc/loadavg'))) {
  213.         list($server_loadexplode(' '$load[0]);
  214.         $gBitSmarty->assign('server_load'$server_load);
  215.         if ($site_use_load_threshold == 'y' && !$gBitUser->hasPermission'p_access_closed_site' && !isset($bypass_siteclose_check)) {
  216.             $site_load_threshold $gBitSystem->getConfig('site_load_threshold'3);
  217.             if ($server_load $site_load_threshold{
  218.                 $_REQUEST['error'$gBitSystem->getConfig('site_busy_msg''Server is currently too busy; please come back later.');
  219.                 includeKERNEL_PKG_PATH 'error_simple.php' );
  220.                 exit;
  221.             }
  222.         }
  223.     }
  224.  
  225.     // if we are interactively translating the website, we force template caching on every page load.
  226.     if$gBitSystem->isFeatureActive'i18n_interactive_translation' && $gBitUser->hasPermission'p_languages_edit' ) ) {
  227.         $gBitSmarty->assign_by_ref"gBitTranslationHash"$gBitTranslationHash );
  228.     else {
  229.         // this has to be done since the permission can't be checked in BitLanguage::translate() as it's called too soon by prefilter.tr
  230.         $gBitSystem->setConfig'i18n_interactive_translation''n' );
  231.     }
  232.  
  233.     // All of the below deals with HTTPS - perhaps we should move this to a separate file
  234.     ifisset$_SERVER['HTTPS'&& $_SERVER['HTTPS'== 'on' {
  235.         $site_http_port 80;
  236.         $site_https_port = isset$_SERVER['SERVER_PORT'$_SERVER['SERVER_PORT'443;
  237.     else {
  238.         $site_https_port 443;
  239.         $site_http_port = isset$_SERVER['SERVER_PORT'$_SERVER['SERVER_PORT'80;
  240.     }
  241.  
  242.     if!$site_https_port $gBitSystem->getConfig'site_https_port'$site_https_port ) ) {
  243.         $gBitSystem->setConfig'site_https_port'$site_https_port );
  244.     }
  245.  
  246.     ifdefined'SECURE_BIT_BASE_URI' ) ) {
  247.         define'SECURE_BIT_BASE_URI''https://'.$host.($site_https_port!=443?$site_https_port:'') );
  248.     }
  249.  
  250.     // we need this for backwards compatibility - use $gBitSystem->getPrerference( 'max_records' ) if you need it, or else the spanish inquisition will come and poke you with a soft cushion
  251.     $max_records $gBitSystem->getConfig"max_records"10 );
  252.  
  253.     $gBitSmarty->assign('site_https_login'$gBitSystem->getConfig'site_https_login' ) );
  254.     $gBitSmarty->assign('site_https_login_required'$gBitSystem->getConfig'site_https_login_required' ) );
  255.  
  256.     $login_url USERS_PKG_URL 'validate.php';
  257.     $gBitSmarty->assign'login_url'$login_url );
  258.  
  259.     if$gBitSystem->isFeatureActive'site_https_login' || $gBitSystem->isFeatureActive'site_https_login_required' ) )    {
  260.         $http_login_url 'http://' $gBitSystem->getConfig'site_http_domain'$_SERVER['HTTP_HOST');
  261.         if$site_http_port != 80 {
  262.             $http_login_url .= ':'.$site_http_port;
  263.         }
  264.         $http_login_url .= $gBitSystem->getConfig'site_http_prefix'BIT_ROOT_URL ).USERS_PKG_URL.'login.php';
  265.  
  266.         $https_login_url 'https://'.$gBitSystem->getConfig'site_https_domain'$_SERVER['HTTP_HOST');
  267.         if$site_https_port != 443 {
  268.             $https_login_url .= ':'.$site_https_port;
  269.         }
  270.         $https_login_url .= $gBitSystem->getConfig'site_https_prefix'BIT_ROOT_URL ).USERS_PKG_URL.'login.php';
  271.  
  272.         $gBitSystem->setConfig'http_login_url'$http_login_url );
  273.         if$gBitSystem->isFeatureActive('site_https_login_required') ) {
  274.             // force the login_url to the https_login_url if needed
  275.             if!isset$_SERVER['HTTPS'&& $_SERVER['HTTPS'== 'on' )) {
  276.                 $gBitSmarty->assign'login_url'$https_login_url );
  277.             }
  278.         else {
  279.             $gBitSystem->setConfig'http_login_url'$http_login_url );
  280.             $gBitSystem->setConfig'https_login_url'$https_login_url );
  281.         }
  282.     }
  283.  
  284.     // if we have a valid user but their status is unsavory then completely cut them off from accessing the site
  285.     if$gBitUser->getField('content_status_id'){
  286.         $gBitSystem->scanPackages();
  287.         $gBitSystem->fatalErrortra'Access Denied' )."!" );
  288.     }
  289. }
  290.  
  291. // INSTALLER_FORCE was set earlier and here we force the installer if needed.
  292. ifdefined'INSTALLER_FORCE' )) {
  293.     $gBitSmarty->display"bitpackage:kernel/force_installer.tpl" );
  294.     die;
  295. }
  296. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:27 +0000 by phpDocumentor 1.5.0-lsces