public function bootstrap($configuration) { if (!$this->bootstrapped) { import('com.solarix.ampoliros.core.AmpConfig'); import('carthag.core.Registry'); $registry = Registry::instance(); $amp_cfg = new AmpConfig($configuration); $registry->setEntry('amp.config', $amp_cfg); // Ampoliros 3000 style environment variable. Usage is deprecated. $gEnv = array(); $GLOBALS['gEnv'] =& $gEnv; $GLOBALS['gEnv']['runtime']['bootstrap'] = 0; // **************************************************************************** // Ampoliros filesystem and urls // **************************************************************************** // Trees define('PUBLIC_TREE', $amp_cfg->getKey('PUBLIC_TREE')); define('PRIVATE_TREE', $amp_cfg->getKey('PRIVATE_TREE')); define('SITES_TREE', $amp_cfg->getKey('SITES_TREE')); define('ADMIN_PATH', PUBLIC_TREE . 'admin/'); define('AMP_PATH', PUBLIC_TREE . 'root/'); define('CGI_PATH', PUBLIC_TREE . 'cgi/'); define('CONFIG_PATH', PRIVATE_TREE . 'etc/'); define('HANDLER_PATH', PRIVATE_TREE . 'var/handlers/'); define('INITDB_PATH', PRIVATE_TREE . 'var/db/'); define('LIBRARY_PATH', PRIVATE_TREE . 'var/lib/'); define('MODULE_PATH', PRIVATE_TREE . 'var/modules/'); define('SITESTUFF_PATH', PRIVATE_TREE . 'var/sites/'); define('TMP_PATH', PRIVATE_TREE . 'tmp/'); // Urls define('AMP_HOST', $amp_cfg->Value('AMP_HOST')); define('AMP_URL', $amp_cfg->Value('AMP_URL')); define('AMP_ROOTURL', $amp_cfg->Value('AMP_ROOTURL')); define('ADMIN_URL', $amp_cfg->Value('ADMIN_URL')); define('CGI_URL', $amp_cfg->Value('CGI_URL')); // **************************************************************************** // Environment // **************************************************************************** // PHP if (strlen($amp_cfg->Value('PHP_MEMORY_LIMIT'))) { $gEnv['core']['php']['memorylimit'] = $amp_cfg->Value('PHP_MEMORY_LIMIT'); } else { $gEnv['core']['php']['memorylimit'] = '64M'; } ini_set('memory_limit', $gEnv['core']['php']['memorylimit']); if (strlen($amp_cfg->Value('PHP_EXECUTION_TIME_LIMIT'))) { $gEnv['core']['php']['timelimit'] = $amp_cfg->Value('PHP_EXECUTION_TIME_LIMIT'); } else { $gEnv['core']['php']['timelimit'] = 0; } set_time_limit($gEnv['core']['php']['timelimit']); ignore_user_abort(TRUE); set_magic_quotes_runtime(0); // **************************************************************************** // Ampoliros state, mode, interface and edition // **************************************************************************** // Defines define('AMP_SETUP_LOCK', TMP_PATH . '.setup'); define('AMP_UPGRADINGSYSTEM_LOCK', TMP_PATH . '.upgrading_system'); // Wait until system is in upgrade phase if (!defined('AMPOLIROS_OVERRIDE_LOCK')) { while (file_exists(AMP_UPGRADINGSYSTEM_LOCK)) { $this->state = Ampoliros::STATE_UPGRADE; clearstatcache(); sleep(1); } } // Check if system is in setup phase and set the state if (file_exists(AMP_SETUP_LOCK)) { define('AMPOLIROS_SETUP_PHASE', TRUE); $this->state = Ampoliros::STATE_SETUP; if (extension_loaded('APD')) { apd_set_session_trace(35); } } else { switch ($amp_cfg->Value('AMP_STATE')) { case 'debug': $this->state = Ampoliros::STATE_DEBUG; if (extension_loaded('APD')) { apd_set_session_trace(35); } break; case 'development': $this->state = Ampoliros::STATE_DEVELOPMENT; break; case 'production': $this->state = Ampoliros::STATE_PRODUCTION; break; default: if ($amp_cfg->Value('DEBUG') == '1') { $this->state = Ampoliros::STATE_DEBUG; define('DEBUG', true); } else { $this->state = Ampoliros::STATE_PRODUCTION; } } } // Interface $this->interface = Ampoliros::INTERFACE_UNKNOWN; // Mode $this->mode = Ampoliros::MODE_ROOT; // Edition if ($amp_cfg->Value('AMP_EDITION') == 'enterprise') { $this->edition = Ampoliros::EDITION_ENTERPRISE; } else { $this->edition = Ampoliros::EDITION_ASP; } // **************************************************************************** // Pid and shutdown function // **************************************************************************** if ($this->state != Ampoliros::STATE_SETUP) { $this->pid = md5(microtime()); touch(TMP_PATH . 'pids/' . $this->pid, time()); register_shutdown_function(array($this, 'shutdown')); } // **************************************************************************** // Session // **************************************************************************** // This must be before session_start if (strlen($amp_cfg->Value('SESSION_LIFETIME'))) { $gEnv['core']['session']['lifetime'] = $amp_cfg->Value('SESSION_LIFETIME') * 60; } else { $gEnv['core']['session']['lifetime'] = 1440 * 60 * 365; } // A year ini_set('session.gc_maxlifetime', $gEnv['core']['session']['lifetime']); ini_set('session.cookie_lifetime', $gEnv['core']['session']['lifetime']); // Start output buffer handler if ($amp_cfg->Value('AMP_COMPRESSED_OB') == '1') { define('AMP_COMPRESSED_OB', TRUE); } else { define('AMP_COMPRESSED_OB', FALSE); } if (!headers_sent()) { if (AMP_COMPRESSED_OB) { ob_start('ob_gzhandler'); } if ($this->state != Ampoliros::STATE_SETUP) { ini_set('session.save_path', TMP_PATH . 'phpsessions/'); } session_start(); } $gEnv['runtime']['sessionid'] = session_id(); // **************************************************************************** // Ampoliros network // **************************************************************************** define('AMP_NAME', $amp_cfg->Value('AMP_NAME')); $gEnv['core']['network']['name'] = AMP_NAME; define('AMP_DOMAIN', $amp_cfg->Value('AMP_DOMAIN')); $gEnv['core']['network']['domain'] = AMP_DOMAIN; define('AMP_DNS', $amp_cfg->Value('AMP_DNS')); $gEnv['core']['network']['dns'] = AMP_DNS; // **************************************************************************** // Ampoliros error handler // **************************************************************************** if ($this->state != Ampoliros::STATE_SETUP) { define('PHP_LOG', $amp_cfg->getKey('PRIVATE_TREE') . 'var/log/php.log'); } else { define('PHP_LOG', $amp_cfg->getKey('PRIVATE_TREE') . 'var/log/amp.log'); } $gEnv['core']['error']['log'] = PHP_LOG; set_error_handler(array($this, 'errorHandler')); // **************************************************************************** // Ampoliros root // **************************************************************************** define('AMP_COUNTRY', $amp_cfg->Value('AMP_COUNTRY')); $gEnv['root']['locale']['country'] = AMP_COUNTRY; define('AMP_LANG', $amp_cfg->Value('AMP_LANG')); $gEnv['root']['locale']['language'] = AMP_LANG; define('AMP_LOG', $amp_cfg->getKey('PRIVATE_TREE') . 'var/log/amp.log'); $gEnv['root']['log'] = AMP_LOG; import('com.solarix.ampoliros.db.DBLayerFactory'); define('AMP_DBTYPE', $amp_cfg->Value('AMP_DBTYPE')); define('AMP_DBNAME', $amp_cfg->Value('AMP_DBNAME')); define('AMP_DBHOST', $amp_cfg->Value('AMP_DBHOST')); define('AMP_DBPORT', $amp_cfg->Value('AMP_DBPORT')); define('AMP_DBUSER', $amp_cfg->Value('AMP_DBUSER')); define('AMP_DBPASS', $amp_cfg->Value('AMP_DBPASS')); define('AMP_DBLOG', $amp_cfg->getKey('PRIVATE_TREE') . 'var/log/ampdb.log'); $gEnv['root']['dblog'] = AMP_DBLOG; if ($amp_cfg->Value('AMP_DBDEBUG') == '1') { define('AMP_DBDEBUG', true); } if ($this->state != Ampoliros::STATE_SETUP) { // Ampoliros central database // $amp_db_args = array(); $amp_db_args['dbtype'] = AMP_DBTYPE; $amp_db_args['dbname'] = AMP_DBNAME; $amp_db_args['dbhost'] = AMP_DBHOST; $amp_db_args['dbport'] = AMP_DBPORT; $amp_db_args['dbuser'] = AMP_DBUSER; $amp_db_args['dbpass'] = AMP_DBPASS; $amp_db_args['dblog'] = AMP_DBLOG; $db_fact = new DBLayerFactory(); $amp_db = $db_fact->NewDbLayer($amp_db_args); if (!$amp_db->Connect($amp_db_args)) { $this->abort('Database not connected', Ampoliros::INTERFACE_CONSOLE); } unset($amp_db_args); $registry->setEntry('amp.root.db', $amp_db); } // **************************************************************************** // Ampoliros remote // **************************************************************************** define('AMP_REMOTE_LOG', $amp_cfg->getKey('PRIVATE_TREE') . 'var/log/remote.log'); $gEnv['remote']['log'] = AMP_REMOTE_LOG; // **************************************************************************** // Run time state and interface defined data // **************************************************************************** // Debugger if ($this->state == Ampoliros::STATE_DEBUG) { import('carthag.dev.LoadTime'); $loadtimer = new LoadTime(LoadTime::LOADTIME_MODE_CONTINUOUS); $registry->setEntry('amp.loadtime', $loadtimer); $loadtimer->Mark('start'); $dbloadtimer = new LoadTime(LoadTime::LOADTIME_MODE_STARTSTOP); $registry->setEntry('amp.dbloadtime', $dbloadtimer); } $gEnv['runtime']['disp'] = $this->array_merge_clobber($this->array_merge_clobber($_GET, $_POST), $_FILES); // Interface settings if ($amp_cfg->Value('AMP_HUI_COMMENTS') == '1' or $this->state == Ampoliros::STATE_DEBUG) { define('AMP_HUI_COMMENTS', TRUE); } else { define('AMP_HUI_COMMENTS', FALSE); } $gEnv['hui']['theme']['default'] = 'amp4000'; define('ROOTCRONTAB', $amp_cfg->Value('ROOTCRONTAB')); // Security $security_reports_interval = $amp_cfg->Value('SECURITY_REPORTS_INTERVAL'); if ($security_reports_interval > 0) { $last_security_report = $amp_cfg->Value('LAST_SECURITY_REPORT'); if (!$last_security_report or $last_security_report < time() - $security_reports_interval * 3600 * 24) { import('com.solarix.ampoliros.security.SecurityLayer'); $amp_security = new SecurityLayer(); $amp_security->SendReport(); unset($amp_security); } } unset($security_reports_interval); // Maintenance $maintenance_interval = $amp_cfg->Value('MAINTENANCE_INTERVAL'); if ($this->state != Ampoliros::STATE_MAINTENANCE and $maintenance_interval > 0) { $last_maintenance = $amp_cfg->Value('LAST_MAINTENANCE'); if (!$last_maintenance or $last_maintenance < time() - $maintenance_interval * 3600 * 24) { import('com.solarix.ampoliros.maintenance.AmpolirosMaintenanceHandler'); $amp_maintenance = new AmpolirosMaintenanceHandler(); $amp_maintenance->DoMaintenance(); $amp_maintenance->SendReport(); unset($amp_maintenance); } } unset($maintenance_interval); // **************************************************************************** // Backward compatibility // **************************************************************************** $gEnv['core']['config'] = $amp_cfg; // Web server define('HTTPD_GROUP', $amp_cfg->Value('HTTPD_GROUP')); define('HTTPD_USER', $amp_cfg->Value('HTTPD_USER')); $gEnv['core']['webserver']['group'] = HTTPD_GROUP; $gEnv['core']['webserver']['user'] = HTTPD_USER; // Ampoliros 2000 style environment variable. Usage is deprecated. global $env; $env = array(); $env['ampcfg'] = $gEnv['core']['config']; $env['amplocale'] = AMP_LANG; $env['disp'] =& $gEnv['runtime']['disp']; // OOPHtml $env['defaultcss'] = 'default.css'; $gEnv['runtime']['pid'] = $this->pid; define('AMP_STATE_SETUP', Ampoliros::STATE_SETUP); define('AMP_STATE_DEVELOPMENT', Ampoliros::STATE_DEVELOPMENT); define('AMP_STATE_DEBUG', Ampoliros::STATE_DEBUG); define('AMP_STATE_PRODUCTION', Ampoliros::STATE_PRODUCTION); define('AMP_STATE_UPGRADE', Ampoliros::STATE_UPGRADE); define('AMP_STATE_MAINTENANCE', Ampoliros::STATE_MAINTENANCE); define('AMP_INTERFACE_UNKNOWN', Ampoliros::INTERFACE_UNKNOWN); define('AMP_INTERFACE_CONSOLE', Ampoliros::INTERFACE_CONSOLE); define('AMP_INTERFACE_WEB', Ampoliros::INTERFACE_WEB); define('AMP_INTERFACE_REMOTE', Ampoliros::INTERFACE_REMOTE); define('AMP_INTERFACE_GUI', Ampoliros::INTERFACE_GUI); define('AMP_INTERFACE_EXTERNAL', Ampoliros::INTERFACE_EXTERNAL); define('AMP_MODE_ROOT', Ampoliros::MODE_ROOT); define('AMP_MODE_SITE', Ampoliros::MODE_SITE); define('AMP_EDITION_ASP', Ampoliros::EDITION_ASP); define('AMP_EDITION_ENTERPRISE', Ampoliros::EDITION_ENTERPRISE); define('STORESTUFF_PATH', PRIVATE_TREE . 'var/sites/'); define('LOG_PATH', PRIVATE_TREE . 'var/log/'); define('CATALOG_PATH', PRIVATE_TREE . 'var/locale/'); define('BIN_PATH', PRIVATE_TREE . 'var/bin/'); define('HELP_PATH', PRIVATE_TREE . 'var/help/'); $gEnv['core']['filesystem']['public'] = PUBLIC_TREE; $gEnv['core']['filesystem']['private'] = PRIVATE_TREE; $gEnv['core']['filesystem']['sites'] = SITES_TREE; $gEnv['core']['state'] = $this->state; $gEnv['core']['mode'] = $this->mode; $gEnv['core']['interface'] = $this->interface; $gEnv['root']['db'] = $amp_db; $env['ampdb'] = $gEnv['root']['db']; $gEnv['runtime']['modules'] = array(); $gEnv['runtime']['debug']['loadtime'] = $loadtimer; $env['debug']['loadtime'] = $gEnv['runtime']['debug']['loadtime']; $gEnv['runtime']['debug']['dbloadtime'] = $dbloadtimer; $env['hui'] =& $gEnv['hui']; $gEnv['core']['edition'] = $this->edition; // **************************************************************************** // Auto exec routines // **************************************************************************** // Module reupdate check if (file_exists(TMP_PATH . 'modinst/reupdate')) { import('com.solarix.ampoliros.module.Module'); $tmp_mod = new Module($amp_db, ''); $tmp_mod->Install(TMP_PATH . 'modinst/reupdate'); clearstatcache(); if (file_exists(TMP_PATH . 'modinst/reupdate')) { unlink(TMP_PATH . 'modinst/reupdate'); } } // Startup hook if ($this->state != Ampoliros::STATE_SETUP) { import('com.solarix.ampoliros.util.Hook'); $hook = new Hook($amp_db, 'ampoliros', 'instance'); switch ($hook->CallHooks('startup', $null, '')) { case Hook::RESULT_ABORT: $this->abort('Bootstrap aborted', Ampoliros::INTERFACE_CONSOLE); break; } } // Bootstrap end $this->bootstrapped = true; $GLOBALS['gEnv']['runtime']['bootstrap'] = $this->bootstrapped; } }