1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16:
17: error_reporting(E_ALL ^E_NOTICE);
18:
19:
20: header('Content-Type: text/html; charset=ISO-8859-1');
21:
22:
23:
24: if (version_compare(PHP_VERSION, '5.0.0', '<')) {
25: die("You need PHP >= 5.0.0 for CONTENIDO. Sorry, even the setup doesn't work otherwise. Your version: " . PHP_VERSION . "\n");
26: }
27:
28: 29: 30: 31: 32: 33: 34: 35:
36: if (!defined('CON_ENVIRONMENT')) {
37: if (getenv('CONTENIDO_ENVIRONMENT')) {
38: $sEnvironment = getenv('CONTENIDO_ENVIRONMENT');
39: } else if (getenv('CON_ENVIRONMENT')) {
40: $sEnvironment = getenv('CON_ENVIRONMENT');
41: } else {
42:
43: $sEnvironment = 'production';
44: }
45:
46: define('CON_ENVIRONMENT', $sEnvironment);
47: }
48:
49: 50: 51: 52: 53:
54: function checkAndInclude($filename) {
55: if (file_exists($filename) && is_readable($filename)) {
56: include_once($filename);
57: } else {
58: echo "<pre>";
59: echo "Setup was unable to include necessary files. The file $filename was not found. Solutions:\n\n";
60: echo "- Make sure that all files are correctly uploaded to the server.\n";
61: echo "- Make sure that include_path is set to '.' (of course, it can contain also other directories). Your include path is: " . ini_get("include_path") . "\n";
62: echo "</pre>";
63: }
64: }
65:
66:
67: checkAndInclude(CON_FRONTEND_PATH . '/contenido/classes/class.filehandler.php');
68: checkAndInclude(CON_FRONTEND_PATH . '/contenido/classes/class.requestvalidator.php');
69:
70: 71: 72: 73:
74: $installationPath = str_replace('\\', '/', realpath(dirname(__FILE__) . '/../..'));
75: $configPath = $installationPath . '/data/config/' . CON_ENVIRONMENT;
76: if (!cFileHandler::exists($configPath)) {
77:
78: mkdir($configPath);
79:
80: if (!cFileHandler::exists($configPath)) {
81: throw new cException('Can not create environment directory: data folder is not writable');
82: }
83:
84: $configPathProduction = $installationPath . '/data/config/production/';
85:
86: $directoryIterator = new DirectoryIterator($configPathProduction);
87:
88: foreach ($directoryIterator as $dirContent) {
89:
90: if ($dirContent->isFile() && !$dirContent->isDot()) {
91:
92: $configFileName = $dirContent->getFilename();
93:
94: $source = $configPathProduction . $configFileName;
95:
96: $target = $configPath . '/' . $configFileName;
97:
98: if(!copy($source, $target)) {
99: throw new cException('Can not copy configuration files for the environment: environment folder is not writable');
100: }
101: }
102: }
103: }
104:
105: try {
106: $requestValidator = cRequestValidator::getInstance();
107: $requestValidator->checkParams();
108: } catch (cFileNotFoundException $e) {
109: die($e->getMessage());
110: }
111:
112: session_start();
113:
114: if (is_array($_REQUEST)) {
115: foreach ($_REQUEST as $key => $value) {
116: if ($key == 'c') {
117:
118: continue;
119: }
120: if (($value != '' && $key != 'dbpass' && $key != 'adminpass' && $key != 'adminpassrepeat') || ($key == 'dbpass' && $_REQUEST['dbpass_changed'] == 'true') || ($key == 'adminpass' && $_REQUEST['adminpass_changed'] == 'true') || ($key == 'adminpassrepeat' && $_REQUEST['adminpassrepeat_changed'] == 'true')) {
121: $_SESSION[$key] = $value;
122: }
123: }
124: }
125:
126:
127: $maxExecutionTime = (int) ini_get('max_execution_time');
128: if ($maxExecutionTime < 60 && $maxExecutionTime !== 0) {
129: ini_set('max_execution_time', 60);
130: }
131:
132:
133: global $cfg;
134:
135: $cfg['path']['frontend'] = CON_FRONTEND_PATH;
136: $cfg['path']['contenido'] = $cfg['path']['frontend'] . '/contenido/';
137: $cfg['path']['contenido_config'] = CON_FRONTEND_PATH . '/data/config/' . CON_ENVIRONMENT . '/';
138:
139:
140: $cfg['sql']['sqlprefix'] = (isset($_SESSION['dbprefix'])) ? $_SESSION['dbprefix'] : 'con';
141: $cfg['db'] = array(
142: 'connection' => array(
143: 'host' => (isset($_SESSION['dbhost'])) ? $_SESSION['dbhost'] : '',
144: 'database' => (isset($_SESSION['dbname'])) ? $_SESSION['dbname'] : '',
145: 'user' => (isset($_SESSION['dbuser'])) ? $_SESSION['dbuser'] : '',
146: 'password' => (isset($_SESSION['dbpass'])) ? $_SESSION['dbpass'] : '',
147: 'charset' => (isset($_SESSION['dbcharset'])) ? $_SESSION['dbcharset'] : ''
148: ),
149: 'haltBehavior' => 'report',
150: 'haltMsgPrefix' => (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] . ' ' : '',
151: 'enableProfiling' => false,
152: );
153:
154: checkAndInclude($cfg['path']['contenido_config'] . 'config.path.php');
155: checkAndInclude($cfg['path']['contenido_config'] . 'config.misc.php');
156: checkAndInclude($cfg['path']['contenido_config'] . 'cfg_sql.inc.php');
157:
158:
159: if ($cfg['php_settings'] && is_array($cfg['php_settings'])) {
160: foreach ($cfg['php_settings'] as $settingName => $value) {
161:
162: if ($settingName !== 'date.timezone') {
163: @ini_set($settingName, $value);
164: }
165: }
166: }
167: error_reporting($cfg['php_error_reporting']);
168:
169:
170: $timezoneCfg = $cfg['php_settings']['date.timezone'];
171: if (!empty($timezoneCfg) && ini_get('date.timezone') !== $timezoneCfg) {
172:
173: date_default_timezone_set($timezoneCfg);
174: } else if (empty($timezoneCfg) && (ini_get('date.timezone') === '' || ini_get('date.timezone') === false)) {
175:
176: date_default_timezone_set('UTC');
177: }
178:
179:
180: checkAndInclude($cfg['path']['contenido'] . $cfg['path']['classes'] . 'class.autoload.php');
181: cAutoload::initialize($cfg);
182:
183:
184:
185: cHTML::setGenerateXHTML(false);
186:
187:
188: checkAndInclude(CON_SETUP_PATH . '/lib/defines.php');
189: checkAndInclude($cfg['path']['contenido'] . 'includes/functions.php54.php');
190: checkAndInclude($cfg['path']['contenido'] . 'includes/functions.i18n.php');
191: checkAndInclude($cfg['path']['contenido'] . 'includes/api/functions.api.general.php');
192: checkAndInclude($cfg['path']['contenido'] . 'includes/functions.general.php');
193: checkAndInclude($cfg['path']['contenido'] . 'classes/class.template.php');
194: checkAndInclude(CON_SETUP_PATH . '/lib/class.setupcontrols.php');
195: checkAndInclude(CON_SETUP_PATH . '/lib/functions.filesystem.php');
196: checkAndInclude(CON_SETUP_PATH . '/lib/functions.environment.php');
197: checkAndInclude(CON_SETUP_PATH . '/lib/functions.safe_mode.php');
198: checkAndInclude(CON_SETUP_PATH . '/lib/functions.mysql.php');
199: checkAndInclude(CON_SETUP_PATH . '/lib/functions.phpinfo.php');
200: checkAndInclude(CON_SETUP_PATH . '/lib/functions.libraries.php');
201: checkAndInclude(CON_SETUP_PATH . '/lib/functions.system.php');
202: checkAndInclude(CON_SETUP_PATH . '/lib/functions.sql.php');
203: checkAndInclude(CON_SETUP_PATH . '/lib/functions.setup.php');
204: checkAndInclude(CON_SETUP_PATH . '/lib/class.setupmask.php');
205:
206:
207: if (false === isPHPCompatible()) {
208: $sNotInstallableReason = 'php_version';
209: checkAndInclude(CON_SETUP_PATH . '/steps/notinstallable.php');
210: }
211:
212:
213: if (getPHPIniSetting('session.use_cookies') == 0) {
214: $sNotInstallableReason = 'session_use_cookies';
215: checkAndInclude(CON_SETUP_PATH . '/steps/notinstallable.php');
216: }
217:
218:
219: $extension = getMySQLDatabaseExtension();
220: if (!is_null($extension)) {
221: $cfg['database_extension'] = $extension;
222: } else {
223: $sNotInstallableReason = 'database_extension';
224: checkAndInclude(CON_SETUP_PATH . '/steps/notinstallable.php');
225: }
226:
227: if (isset($_SESSION['language'])) {
228: i18nInit('locale/', $_SESSION['language'], 'setup');
229: }
230: