1: <?php
2: require('QString.class.php');
3:
4: abstract class QInstallationValidator {
5: 6: 7: 8:
9: public static function Validate() {
10: $result = array();
11:
12: if(ini_get('safe_mode') ){
13: $obj = new QInstallationValidationResult();
14: $obj->strMessage = "Safe Mode is deprecated in PHP 5.3+ and is removed in PHP 6.0+." .
15: "Please disable this setting in php.ini";
16: $result[] = $obj;
17: }
18:
19: if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
20: $obj = new QInstallationValidationResult();
21: $obj->strMessage = "magic_quotes_gpc and magic_quotes_runtime " .
22: "need to be disabled\r\n";
23: $result[] = $obj;
24: }
25:
26: $docrootOnlyPath = __DOCROOT__;
27: $docrootWithSubdirPath = __DOCROOT__ . __DEVTOOLS_ASSETS__ . substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/"));
28:
29: $commonSubsequence = QString::LongestCommonSubsequence($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_FILENAME']);
30: $root = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - strlen($commonSubsequence));
31: $part1 = substr($_SERVER['PHP_SELF'], 1, strpos($_SERVER['PHP_SELF'], "/", 1) - 1);
32: $part2 = substr($root, strrpos($root, "/") + 1);
33: $virtualDir = substr($_SERVER['PHP_SELF'], 0, 0 - strlen($commonSubsequence));
34:
35:
36:
37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
52:
53: if (!is_dir($docrootOnlyPath)) {
54: $obj = new QInstallationValidationResult();
55: $obj->strMessage = 'Set the __DOCROOT__ constant in ' .
56: '/includes/configuration/configuration.inc.php. ' .
57: 'Most likely value: "' . $root . '"';
58: $result[] = $obj;
59: } else if (strlen(__VIRTUAL_DIRECTORY__) == 0 &&
60: !file_exists(__DOCROOT__ . $_SERVER['PHP_SELF'])) {
61: $obj = new QInstallationValidationResult();
62: $obj->strMessage = 'Set the __DOCROOT__ constant in ' .
63: '/includes/configuration/configuration.inc.php. ' .
64: 'Most likely value: "' . $root . '"';
65: $result[] = $obj;
66: }
67:
68: if (!file_exists($docrootWithSubdirPath)) {
69: $obj = new QInstallationValidationResult();
70: $obj->strMessage = 'Set the __SUBDIRECTORY__ constant in ' .
71: '/includes/configuration/configuration.inc.php. ' .
72: 'Most likely value: "/' . $part1 . '"';
73: $result[] = $obj;
74:
75:
76:
77: return $result;
78: }
79:
80: if (!file_exists(__INCLUDES__)) {
81:
82: $obj = new QInstallationValidationResult();
83: $obj->strMessage = 'Set the __INCLUDES__ constant in ' .
84: 'includes/configuration/configuration.inc.php. ';
85: $result[] = $obj;
86:
87:
88:
89: return $result;
90: }
91:
92:
93: self::checkTrailingSlash("__DOCROOT__", $result);
94: self::checkTrailingSlash("__SUBDIRECTORY__", $result);
95: self::checkTrailingSlash("__VIRTUAL_DIRECTORY__", $result);
96:
97: if (strcmp($commonSubsequence, $_SERVER['PHP_SELF']) != 0 && strlen(__VIRTUAL_DIRECTORY__) == 0) {
98: $obj = new QInstallationValidationResult();
99: $obj->strMessage = 'Set the __VIRTUAL_DIRECTORY__ constant in ' .
100: 'includes/configuration/configuration.inc.php. Most likely value: "' . $virtualDir . '"';
101: $result[] = $obj;
102: }
103:
104:
105:
106: require(__CONFIGURATION__. '/prepend.inc.php');
107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156:
157: if (!QFolder::isWritable(__CACHE__)) {
158: $obj = new QInstallationValidationResult();
159: $obj->strMessage = "Cache directory (" . __CACHE__ . ") needs to be writable";
160: $obj->strCommandToFix = "chmod 777 " . __CACHE__;
161: $result[] = $obj;
162: }
163:
164: if (!file_exists(__IMAGE_CACHE__)) {
165:
166: $obj = new QInstallationValidationResult();
167: $obj->strMessage = 'Create the "' . __IMAGE_CACHE__ . '" directory.';
168: $obj->strCommandToFix = "mkdir " . __IMAGE_CACHE__;
169: $result[] = $obj;
170: }
171: else if (!QFolder::isWritable(__IMAGE_CACHE__)) {
172: $obj = new QInstallationValidationResult();
173: $obj->strMessage = "Images cache directory (" . __IMAGE_CACHE__ . ") needs to be writable";
174: $obj->strCommandToFix = "chmod 777 " . __IMAGE_CACHE__;
175: $result[] = $obj;
176: }
177:
178: if (!QFolder::isWritable(__FILE_CACHE__)) {
179: $obj = new QInstallationValidationResult();
180: $obj->strMessage = "Cache directory (" . __FILE_CACHE__ . ") needs to be writable";
181: $obj->strCommandToFix = "chmod 777 " . __FILE_CACHE__;
182: $result[] = $obj;
183: }
184:
185: if (!QFolder::isWritable(__PURIFIER_CACHE__)) {
186: $obj = new QInstallationValidationResult();
187: $obj->strMessage = "Cache directory (" . __PURIFIER_CACHE__ . ") needs to be writable";
188: $obj->strCommandToFix = "chmod 777 " . __PURIFIER_CACHE__;
189: $result[] = $obj;
190: }
191:
192: if (!file_exists(__CONFIGURATION__ . '/codegen_options.json')) {
193:
194: $obj = new QInstallationValidationResult();
195: $obj->strMessage = 'Create the "' . __CONFIGURATION__ . '/codegen_options.json"' . ' file.';
196: $obj->strCommandToFix = "touch " . __CONFIGURATION__. '/codegen_options.json';
197: $result[] = $obj;
198: }
199: else if (!QFile::isWritable(__CONFIGURATION__ . '/codegen_options.json')) {
200: $obj = new QInstallationValidationResult();
201: $obj->strMessage = "The file (" . __CONFIGURATION__ . '/codegen_options.json' . ") needs to be writable";
202: $obj->strCommandToFix = "chmod 666 " . __CONFIGURATION__ . '/codegen_options.json';
203: $result[] = $obj;
204: }
205:
206: if (!file_exists(__PROJECT__ . '/forms')) {
207:
208: $obj = new QInstallationValidationResult();
209: $obj->strMessage = 'Create the "' . __PROJECT__ . '/forms"' . ' directory.';
210: $obj->strCommandToFix = "mkdir " . __PROJECT__. '/forms';
211: $result[] = $obj;
212: }
213: else if (!QFolder::isWritable(__PROJECT__ . '/forms')) {
214: $obj = new QInstallationValidationResult();
215: $obj->strMessage = "Forms directory (" . __PROJECT__ . '/forms' . ") needs to be writable";
216: $obj->strCommandToFix = "chmod 777 " . __PROJECT__ . '/forms';
217: $result[] = $obj;
218: }
219:
220: if (!file_exists(__PANEL__)) {
221:
222: $obj = new QInstallationValidationResult();
223: $obj->strMessage = 'Create the "' . __PANEL__ . '" directory.';
224: $obj->strCommandToFix = "mkdir " . __PANEL__;
225: $result[] = $obj;
226: }
227: else if (!QFolder::isWritable(__PANEL__)) {
228: $obj = new QInstallationValidationResult();
229: $obj->strMessage = "Panels directory (" . __PANEL__ . ") needs to be writable";
230: $obj->strCommandToFix = "chmod 777 " . __PANEL__;
231: $result[] = $obj;
232: }
233:
234: if (!file_exists(__DIALOG__)) {
235:
236: $obj = new QInstallationValidationResult();
237: $obj->strMessage = 'Create the "' . __DIALOG__ . '" directory.';
238: $obj->strCommandToFix = "mkdir " . __DIALOG__;
239: $result[] = $obj;
240: }
241: else if (!QFolder::isWritable(__DIALOG__)) {
242: $obj = new QInstallationValidationResult();
243: $obj->strMessage = "Panels directory (" . __DIALOG__ . ") needs to be writable";
244: $obj->strCommandToFix = "chmod 777 " . __DIALOG__;
245: $result[] = $obj;
246: }
247:
248: if (!QFolder::isWritable(__APP_CACHE__)) {
249: $obj = new QInstallationValidationResult();
250: $obj->strMessage = "Cache directory (" . __APP_CACHE__ . ") needs to be writable";
251: $obj->strCommandToFix = "chmod 777 " . __APP_CACHE__;
252: $result[] = $obj;
253: }
254:
255: if (!file_exists(__APP_IMAGE_CACHE__)) {
256:
257: $obj = new QInstallationValidationResult();
258: $obj->strMessage = 'Create the "' . __APP_IMAGE_CACHE__ . '" directory.';
259: $obj->strCommandToFix = "mkdir " . __APP_IMAGE_CACHE__;
260: $result[] = $obj;
261: }
262: else if (!QFolder::isWritable(__APP_IMAGE_CACHE__)) {
263: $obj = new QInstallationValidationResult();
264: $obj->strMessage = "Images cache directory (" . __APP_IMAGE_CACHE__ . ") needs to be writable";
265: $obj->strCommandToFix = "chmod 777 " . __APP_IMAGE_CACHE__;
266: $result[] = $obj;
267: }
268:
269: if (defined("__APP_UPLOAD__")) {
270: if (!file_exists(__APP_UPLOAD__)) {
271:
272: $obj = new QInstallationValidationResult();
273: $obj->strMessage = 'Create the "' . __APP_UPLOAD__ . '" directory.';
274: $obj->strCommandToFix = "mkdir " . __APP_UPLOAD__;
275: $result[] = $obj;
276: }
277: else if (!QFolder::isWritable(__APP_UPLOAD__)) {
278: $obj = new QInstallationValidationResult();
279: $obj->strMessage = "Uploads directory (" . __APP_UPLOAD__ . ") needs to be writable";
280: $obj->strCommandToFix = "chmod 777 " . __APP_UPLOAD__;
281: $result[] = $obj;
282: }
283: }
284:
285: if (defined("__QCUBED_UPLOAD__")) {
286: if (!file_exists(__QCUBED_UPLOAD__)) {
287:
288: $obj = new QInstallationValidationResult();
289: $obj->strMessage = 'Create the "' . __QCUBED_UPLOAD__ . '" directory.';
290: $obj->strCommandToFix = "mkdir " . __QCUBED_UPLOAD__;
291: $result[] = $obj;
292: }
293: else if (!QFolder::isWritable(__QCUBED_UPLOAD__)) {
294: $obj = new QInstallationValidationResult();
295: $obj->strMessage = "Uploads directory (" . __QCUBED_UPLOAD__ . ") needs to be writable";
296: $obj->strCommandToFix = "chmod 777 " . __QCUBED_UPLOAD__;
297: $result[] = $obj;
298: }
299: }
300:
301:
302: for ($i = 1; $i < 1 + sizeof(QApplication::$Database); $i++) {
303: if (!isset(QApplication::$Database[$i]))
304: continue;
305: $db = QApplication::$Database[$i];
306:
307:
308:
309: set_error_handler("__database_check_error");
310: try {
311: $db->Connect();
312: } catch (Exception $e) {
313: $obj = new QInstallationValidationResult();
314: $obj->strMessage = "Fix database configuration settings in " .
315: __CONFIGURATION__ . "/configuration.inc.php for adapter #"
316: . $i . ": " . $e->getMessage();
317: $result[] = $obj;
318: }
319: restore_error_handler();
320: }
321:
322: return $result;
323: }
324:
325: public static function checkTrailingSlash($strConstantName, & $result) {
326: if (QString::LastCharacter(constant($strConstantName)) == '/') {
327: $obj = new QInstallationValidationResult();
328: $obj->strMessage = 'Remove the trailing slash from the ' . $strConstantName . ' constant in ' .
329: '/includes/configuration/configuration.inc.php. ';
330: $result[] = $obj;
331: }
332: }
333:
334: }
335:
336: function __database_check_error($errno, $errstr, $errfile, $errline, $errcontext) {
337: throw new Exception(strip_tags($errstr));
338: }
339:
340: class QInstallationValidationResult {
341: 342: 343: 344: 345:
346: public $strMessage = "";
347:
348: 349: 350: 351: 352:
353: public $strCommandToFix = "";
354:
355: public function __toString() {
356: return $this->strMessage;
357: }
358: }