1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cSystemtest {
25:
26: 27: 28: 29: 30:
31: const CON_SETUP_MIN_PHP_VERSION = '5.2.0';
32:
33: 34: 35: 36: 37:
38: const C_SEVERITY_NONE = 1;
39:
40: 41: 42: 43: 44:
45: const C_SEVERITY_INFO = 2;
46:
47: 48: 49: 50: 51: 52:
53: const C_SEVERITY_WARNING = 3;
54:
55: 56: 57: 58: 59: 60:
61: const C_SEVERITY_ERROR = 4;
62:
63: 64: 65: 66: 67: 68:
69: const CON_PREDICT_SUFFICIENT = 1;
70:
71: 72: 73: 74: 75: 76:
77: const CON_PREDICT_NOTPREDICTABLE = 2;
78:
79: 80: 81: 82: 83: 84:
85: const CON_PREDICT_CHANGEPERM_SAMEOWNER = 3;
86:
87: 88: 89: 90: 91: 92:
93: const CON_PREDICT_CHANGEPERM_SAMEGROUP = 4;
94:
95: 96: 97: 98: 99: 100:
101: const CON_PREDICT_CHANGEPERM_OTHERS = 5;
102:
103: 104: 105: 106: 107: 108:
109: const CON_PREDICT_CHANGEUSER = 6;
110:
111: 112: 113: 114: 115: 116:
117: const CON_PREDICT_CHANGEGROUP = 7;
118:
119: 120: 121: 122: 123: 124:
125: const CON_PREDICT_WINDOWS = 8;
126:
127: 128: 129: 130: 131: 132:
133: const CON_BASEDIR_NORESTRICTION = 1;
134:
135: 136: 137: 138: 139: 140:
141: const CON_BASEDIR_DOTRESTRICTION = 2;
142:
143: 144: 145: 146: 147: 148:
149: const CON_BASEDIR_RESTRICTIONSUFFICIENT = 3;
150:
151: 152: 153: 154: 155: 156:
157: const CON_BASEDIR_INCOMPATIBLE = 4;
158:
159: 160: 161: 162: 163: 164:
165: const CON_EXTENSION_AVAILABLE = 1;
166:
167: 168: 169: 170: 171: 172:
173: const CON_EXTENSION_UNAVAILABLE = 2;
174:
175: 176: 177: 178: 179: 180:
181: const CON_EXTENSION_CANTCHECK = 3;
182:
183: 184: 185: 186: 187: 188:
189: const CON_IMAGERESIZE_GD = 1;
190:
191: 192: 193: 194: 195: 196:
197: const CON_IMAGERESIZE_IMAGEMAGICK = 2;
198:
199: 200: 201: 202: 203: 204:
205: const CON_IMAGERESIZE_CANTCHECK = 3;
206:
207: 208: 209: 210: 211: 212:
213: const CON_IMAGERESIZE_NOTHINGAVAILABLE = 4;
214:
215: 216: 217: 218: 219: 220:
221: const CON_MYSQL_OK = 1;
222:
223: 224: 225: 226: 227: 228: 229:
230: const CON_MYSQL_STRICT_MODE = 2;
231:
232: 233: 234: 235: 236: 237: 238:
239: const CON_MYSQL_CANT_CONNECT = 3;
240:
241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252:
253: protected $_messages;
254:
255: 256: 257: 258: 259:
260: protected $_config;
261:
262: 263: 264: 265: 266: 267:
268: public function __construct($config) {
269: $this->_config = $config;
270: }
271:
272: 273: 274: 275: 276: 277:
278: public function runTests($testFileSystem = true) {
279: $this->storeResult($this->testPHPVersion(), self::C_SEVERITY_ERROR, sprintf(i18n("PHP Version lower than %s"), self::CON_SETUP_MIN_PHP_VERSION), sprintf(i18n("CONTENIDO requires PHP %s or higher as it uses functionality first introduced with this version. Please update your PHP version."), self::CON_SETUP_MIN_PHP_VERSION), i18n("The PHP version is higher than ") . self::CON_SETUP_MIN_PHP_VERSION);
280: $this->storeResult($this->testFileUploadSetting(), self::C_SEVERITY_WARNING, i18n("File uploads disabled"), sprintf(i18n("Your PHP version is not configured for file uploads. You can't upload files using CONTENIDO's file manager unless you configure PHP for file uploads. See %s for more information"), '<a target="_blank" href="http://www.php.net/manual/en/ini.core.php#ini.file-uploads">http://www.php.net/manual/en/ini.core.php#ini.file-uploads</a>'), i18n("PHP file upload is enabled"));
281: $this->storeResult($this->testMagicQuotesRuntimeSetting(), self::C_SEVERITY_ERROR, i18n("PHP setting 'magic_quotes_runtime' is turned on"), i18n("The PHP setting 'magic_quotes_runtime' is turned on. CONTENIDO has been developed to comply with magic_quotes_runtime=Off as this is the PHP default setting. You have to change this directive to make CONTENIDO work."), i18n("'magic_quotes_runtime' is turned off"));
282: $this->storeResult($this->testMagicQuotesSybaseSetting(), self::C_SEVERITY_ERROR, i18n("PHP Setting 'magic_quotes_sybase' is turned on"), i18n("The PHP Setting 'magic_quotes_sybase' is turned on. CONTENIDO has been developed to comply with magic_quotes_sybase=Off as this is the PHP default setting. You have to change this directive to make CONTENIDO work."), i18n("'magic_quotes_sybase' is turned off"));
283: $this->storeResult($this->testMaxExecutionTime(), self::C_SEVERITY_WARNING, i18n("PHP maximum execution time is less than 30 seconds"), i18n("PHP is configured for a maximum execution time of less than 30 seconds. This could cause problems with slow web servers and/or long operations in the backend. Our recommended execution time is 120 seconds on slow web servers, 60 seconds for medium ones and 30 seconds for fast web servers."), i18n("PHP allows execution times longer than 30 seconds"));
284: $this->storeResult($this->testZIPArchive(), self::C_SEVERITY_WARNING, i18n("The class ZipArchive could not be found"), i18n("This could cause some problems, but CONTENIDO is able to run without it. You should check your PHP installation."), i18n("The ZipArchive class is enabled"));
285:
286: $test = $this->checkOpenBasedirCompatibility();
287: switch ($test) {
288: case self::CON_BASEDIR_NORESTRICTION:
289: $this->storeResult(true, self::C_SEVERITY_ERROR, "", "", i18n("open_basedir directive doesn't enforce any restrictions"));
290: break;
291: case self::CON_BASEDIR_DOTRESTRICTION:
292: $this->storeResult(false, self::C_SEVERITY_ERROR, i18n("open_basedir directive set to '.'"), i18n("The directive open_basedir is set to '.' (e.g. current directory). This means that CONTENIDO is unable to access files in a logical upper level in the filesystem. This will cause problems managing the CONTENIDO frontends. Either add the full path of this CONTENIDO installation to the open_basedir directive, or turn it off completely."));
293: break;
294: case self::CON_BASEDIR_RESTRICTIONSUFFICIENT:
295: $this->storeResult(false, self::C_SEVERITY_INFO, i18n("open_basedir setting might be insufficient"), i18n("Setup believes that the PHP directive open_basedir is configured sufficient, however, if you encounter errors like 'open_basedir restriction in effect. File <filename> is not within the allowed path(s): <path>', you have to adjust the open_basedir directive"));
296: break;
297: case self::CON_BASEDIR_INCOMPATIBLE:
298: $this->storeResult(false, self::C_SEVERITY_ERROR, i18n("open_basedir directive incompatible"), i18n("Setup has checked your PHP open_basedir directive and reckons that it is not sufficient. Please change the directive to include the CONTENIDO installation or turn it off completely."));
299: break;
300: }
301:
302: $this->storeResult($this->testMemoryLimit(), self::C_SEVERITY_WARNING, i18n("PHP memory_limit directive too small"), i18n("The memory_limit directive is set to 32 MB or lower. This might be not enough for CONTENIDO to operate correctly. We recommend to disable this setting completely, as this can cause problems with large CONTENIDO projects."), i18n("Memory limit is either high enough or deactivated"));
303: $this->storeResult($this->testPHPSQLSafeMode(), self::C_SEVERITY_ERROR, i18n("PHP sql.safe_mode turned on"), i18n("The PHP directive sql.safe_mode is turned on. This causes problems with the SQL queries issued by CONTENIDO. Please turn that directive off."), i18n("sql.safe_mode is deactivated"));
304: $this->storeResult($this->isPHPExtensionLoaded("gd") == self::CON_EXTENSION_AVAILABLE, self::C_SEVERITY_WARNING, i18n("PHP GD-Extension is not loaded"), i18n("The PHP GD-Extension is not loaded. Some third-party modules rely on the GD functionality. If you don't enable the GD extension, you will encounter problems with modules like galleries."), i18n("GD extension loaded"));
305: if ($this->isPHPExtensionLoaded("gd") == self::CON_EXTENSION_AVAILABLE) {
306: $this->storeResult($this->testGDGIFRead(), self::C_SEVERITY_INFO, i18n("GD-Library GIF read support missing"), i18n("Your GD version doesn't support reading GIF files. This might cause problems with some modules."), i18n("GD is able to read GIFs"));
307: $this->storeResult($this->testGDGIFWrite(), self::C_SEVERITY_INFO, i18n("GD-Library GIF write support missing"), i18n("Your GD version doesn't support writing GIF files. This might cause problems with some modules."), i18n("GD is able to write GIFs"));
308: $this->storeResult($this->testGDJPEGRead(), self::C_SEVERITY_INFO, i18n("GD-Library JPEG read support missing"), i18n("Your GD version doesn't support reading JPEG files. This might cause problems with some modules."), i18n("GD is able to read JPEGs"));
309: $this->storeResult($this->testGDJPEGWrite(), self::C_SEVERITY_INFO, i18n("GD-Library JPEG write support missing"), i18n("Your GD version doesn't support writing JPEG files. This might cause problems with some modules."), i18n("GD is able to write JPEGs"));
310: $this->storeResult($this->testGDPNGRead(), self::C_SEVERITY_INFO, i18n("GD-Library PNG read support missing"), i18n("Your GD version doesn't support reading PNG files. This might cause problems with some modules."), i18n("GD is able to read PNGs"));
311: $this->storeResult($this->testGDPNGWrite(), self::C_SEVERITY_INFO, i18n("GD-Library PNG write support missing"), i18n("Your GD version doesn't support writing PNG files. This might cause problems with some modules."), i18n("GD is able to write PNGs"));
312: }
313: $this->storeResult($this->isPHPExtensionLoaded("pcre") == self::CON_EXTENSION_AVAILABLE, self::C_SEVERITY_ERROR, i18n("PHP PCRE Extension is not loaded"), i18n("The PHP PCRE Extension is not loaded. CONTENIDO uses PCRE-functions like preg_repace and preg_match and won't work without the PCRE Extension."), i18n("PCRE extension loaded"));
314: $this->storeResult($this->isPHPExtensionLoaded("xml") == self::CON_EXTENSION_AVAILABLE, self::C_SEVERITY_ERROR, i18n("PHP XML Extension is not loaded"), i18n("The PHP XML Extension is not loaded. CONTENIDO won't work without the XML Extension."), i18n("XML extension loaded"));
315: $this->storeResult($this->testDOMDocument(), self::C_SEVERITY_ERROR, i18n("Class 'DOMDocument' is not available"), i18n("The class DOMDocument could not be found. Please check your PHP installation and enable the XML extension if necessary. CONTENIDO won't work without it."), i18n("DOMDocument is available"));
316: $this->storeResult($this->testXMLParserCreate(), self::C_SEVERITY_ERROR, i18n("Function 'xml_parser_create' is not available"), i18n("The function xml_parser_create could not be found. Please check your PHP installation and enable the XML extension if necessary. CONTENIDO won't work without it."), i18n("xml_parser_create is available"));
317:
318: $result = $this->checkImageResizer();
319: switch ($result) {
320: case self::CON_IMAGERESIZE_CANTCHECK:
321: $this->storeResult(false, self::C_SEVERITY_WARNING, i18n("Unable to check for a suitable image resizer"), i18n("Setup has tried to check for a suitable image resizer (which is, for exampl, required for thumbnail creation), but was not able to clearly identify one. If thumbnails won't work, make sure you've got either the GD-extension or ImageMagick available."));
322: break;
323: case self::CON_IMAGERESIZE_NOTHINGAVAILABLE:
324: $this->storeResult(false, self::C_SEVERITY_ERROR, i18n("No suitable image resizer available"), i18n("Setup checked your image resizing support, however, it was unable to find a suitable image resizer. Thumbnails won't work correctly or won't be looking good. Install the GD-Extension or ImageMagick"));
325: break;
326: case self::CON_IMAGERESIZE_GD:
327: $this->storeResult(true, self::C_SEVERITY_WARNING, "", "", i18n("GD extension is available and usable to handle images"));
328: break;
329: case self::CON_IMAGERESIZE_IMAGEMAGICK:
330: $this->storeResult(true, self::C_SEVERITY_WARNING, "", "", i18n("ImageMagick extension is available and usable to handle images"));
331: break;
332: }
333:
334: $this->storeResult($this->testIconv(), self::C_SEVERITY_ERROR, i18n("PHP iconv functions are not available."), i18n("PHP has been compiled with the --without-iconv directive. CONTENIDO won't work without the iconv functions."), i18n("iconv is available"));
335:
336: $result = $this->testMySQL($this->_config['db']['connection']['host'], $this->_config['db']['connection']['user'], $this->_config['db']['connection']['password']);
337: switch ($result) {
338: case self::CON_MYSQL_OK:
339: $this->storeResult(true, self::C_SEVERITY_ERROR, "", "", i18n("Database connection works"));
340: break;
341: case self::CON_MYSQL_STRICT_MODE:
342: $this->storeResult(false, self::C_SEVERITY_ERROR, i18n('MySQL is running in strict mode'), i18n('MySQL is running in strict mode, CONTENIDO will not work with this mode. Please change your sql_mode!'));
343: break;
344: default:
345: $this->storeResult(false, self::C_SEVERITY_ERROR, i18n("MySQL database connect failed"), sprintf(i18n("Setup was unable to connect to the MySQL Server (Server %s, Username %s). Please correct the MySQL data and try again.<br><br>The error message given was: %s"), $this->_config['db']['connection']['host'], $this->_config['db']['connection']['user'], $result));
346: }
347:
348: if ($testFileSystem) {
349: $this->storeResult($this->testFilesystem(), self::C_SEVERITY_WARNING, i18n("Permission error"), i18n("CONTENIDO doesn't have the necessary permissions to write all the files it needs. Please check your filesystem permissions."), i18n("Filesystem checks"), i18n("CONTENIDO has all the necessary permissions to read and write files"));
350: }
351: }
352:
353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366:
367: public function storeResult($result, $severity, $errorHeadline = "", $errorMessage = "", $successHeadline = "", $successMessage = "") {
368: if ($result) {
369: $this->_messages[] = array(
370: "result" => $result,
371: "severity" => $severity,
372: "headline" => $successHeadline,
373: "message" => $successMessage
374: );
375: } else {
376: $this->_messages[] = array(
377: "result" => $result,
378: "severity" => $severity,
379: "headline" => $errorHeadline,
380: "message" => $errorMessage
381: );
382: }
383: }
384:
385: 386: 387: 388: 389: 390:
391: public function getResults() {
392: return $this->_messages;
393: }
394:
395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423:
424: protected function getFileInfo($sFilename) {
425: if (!cFileHandler::exists($sFilename)) {
426: return false;
427: }
428:
429: $oiFilePermissions = fileperms($sFilename);
430: if ($oiFilePermissions === false) {
431: return false;
432: }
433:
434: switch (true) {
435: case (($oiFilePermissions & 0xC000) == 0xC000):
436: $info = 's';
437: $type = "socket";
438: break;
439: case (($oiFilePermissions & 0xA000) == 0xA000):
440: $info = 'l';
441: $type = "symbolic link";
442: break;
443: case (($oiFilePermissions & 0x8000) == 0x8000):
444: $info = '-';
445: $type = "regular file";
446: break;
447: case (($oiFilePermissions & 0x6000) == 0x6000):
448: $info = 'b';
449: $type = "block special";
450: break;
451: case (($oiFilePermissions & 0x4000) == 0x4000):
452: $info = 'd';
453: $type = "directory";
454: break;
455: case (($oiFilePermissions & 0x2000) == 0x2000):
456: $info = 'c';
457: $type = "character special";
458: break;
459: case (($oiFilePermissions & 0x1000) == 0x1000):
460: $info = 'p';
461: $type = "FIFO pipe";
462: break;
463: default:
464: $info = "u";
465: $type = "Unknown";
466: break;
467: }
468:
469: $aFileinfo = array();
470: $aFileinfo["info"] = $info;
471: $aFileinfo["type"] = $type;
472: $aFileinfo["owner"]["read"] = ($oiFilePermissions & 0x0100)? true : false;
473: $aFileinfo["owner"]["write"] = ($oiFilePermissions & 0x0080)? true : false;
474: $aFileinfo["group"]["read"] = ($oiFilePermissions & 0x0020)? true : false;
475: $aFileinfo["group"]["write"] = ($oiFilePermissions & 0x0010)? true : false;
476: $aFileinfo["others"]["read"] = ($oiFilePermissions & 0x0004)? true : false;
477: $aFileinfo["others"]["write"] = ($oiFilePermissions & 0x0002)? true : false;
478: $aFileinfo["owner"]["id"] = fileowner($sFilename);
479: $aFileinfo["group"]["id"] = filegroup($sFilename);
480: return ($aFileinfo);
481: }
482:
483: 484: 485: 486: 487: 488:
489: protected function canWriteFile($filename) {
490: clearstatcache();
491: if (is_file($filename)) {
492: return is_writable($filename);
493: } else {
494: return is_writable(dirname($filename));
495: }
496: }
497:
498: 499: 500: 501: 502: 503:
504: protected function canWriteDir($dirname) {
505: clearstatcache();
506: return is_dir($dirname) && is_writable($dirname);
507: }
508:
509: 510: 511: 512: 513:
514: protected function getServerUID() {
515: if (function_exists("posix_getuid")) {
516: return posix_getuid();
517: }
518:
519: $sFilename = md5(mt_rand()) . ".txt";
520:
521: if (is_writeable(".")) {
522: cFileHandler::create($sFilename, "test");
523: $iUserId = fileowner($sFilename);
524: cFileHandler::remove($sFilename);
525:
526: return ($iUserId);
527: } else {
528: if (is_writeable("/tmp/")) {
529: cFileHandler::create("/tmp/" . $sFilename, "w");
530: $iUserId = fileowner("/tmp/" . $sFilename);
531: cFileHandler::remove("/tmp/" . $sFilename);
532:
533: return ($iUserId);
534: }
535: return false;
536: }
537: }
538:
539: 540: 541: 542: 543:
544: protected function getServerGID() {
545: if (function_exists("posix_getgid")) {
546: return posix_getgid();
547: }
548:
549: $sFilename = md5(mt_rand()) . ".txt";
550:
551: if (is_writeable(".")) {
552: cFileHandler::create($sFilename, "test");
553: $iUserId = filegroup($sFilename);
554: cFileHandler::remove($sFilename);
555:
556: return ($iUserId);
557: } else {
558: return false;
559: }
560: }
561:
562: 563: 564: 565: 566: 567: 568:
569: protected function predictCorrectFilepermissions($file) {
570:
571:
572: if ($this->isWindows()) {
573: return self::CON_PREDICT_WINDOWS;
574: }
575:
576:
577:
578:
579: if (is_writable($file) && is_readable($file)) {
580: return self::CON_PREDICT_SUFFICIENT;
581: }
582:
583:
584:
585:
586: $iServerUID = $this->getServerUID();
587: if ($iServerUID === false) {
588: return self::CON_PREDICT_NOTPREDICTABLE;
589: }
590:
591:
592:
593:
594: $iServerGID = $this->getServerGID();
595: if ($iServerGID === false) {
596: return self::CON_PREDICT_NOTPREDICTABLE;
597: }
598:
599: $aFilePermissions = $this->getFileInfo($file);
600:
601: if ($this->getSafeModeStatus()) {
602:
603: if ($iServerUID == $aFilePermissions["owner"]["id"]) {
604: return self::CON_PREDICT_CHANGEPERM_SAMEOWNER;
605: }
606:
607: if ($this->getSafeModeGidStatus()) {
608:
609: if ($iServerGID == $aFilePermissions["group"]["id"]) {
610: return self::CON_PREDICT_CHANGEPERM_SAMEGROUP;
611: }
612:
613: return self::CON_PREDICT_CHANGEGROUP;
614: }
615: } else {
616:
617: if ($iServerUID == $aFilePermissions["owner"]["id"]) {
618: return self::CON_PREDICT_CHANGEPERM_SAMEOWNER;
619: }
620:
621: if ($iServerGID == $aFilePermissions["group"]["id"]) {
622: return self::CON_PREDICT_CHANGEPERM_SAMEGROUP;
623: }
624:
625: return self::CON_PREDICT_CHANGEPERM_OTHERS;
626: }
627: }
628:
629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639:
640: protected function testSingleFile($filename, $severity, $dir = false) {
641: if (strpos($filename, $this->_config["path"]["frontend"]) === 0) {
642: $length = strlen($this->_config["path"]["frontend"]) + 1;
643: $shortFilename = substr($filename, $length);
644: } else {
645: $shortFilename = $filename;
646: }
647:
648: if (!$dir) {
649: $status = $this->canWriteFile($filename);
650: } else {
651: $status = $this->canWriteDir($filename);
652: }
653:
654: $title = sprintf(i18n("Can't write %s"), $shortFilename);
655: $message = sprintf(i18n("Setup or CONTENIDO can't write to the file %s. Please change the file permissions to correct this problem."), $shortFilename);
656:
657: if ($status == false) {
658: if (cFileHandler::exists($filename)) {
659: $perm = $this->predictCorrectFilepermissions($filename);
660:
661: switch ($perm) {
662: case self::CON_PREDICT_WINDOWS:
663: $predictMessage = i18n("Your Server runs Windows. Due to that, Setup can't recommend any file permissions.");
664: break;
665: case self::CON_PREDICT_NOTPREDICTABLE:
666: $predictMessage = sprintf(i18n("Due to a very restrictive environment, an advise is not possible. Ask your system administrator to enable write access to the file %s, especially in environments where ACL (Access Control Lists) are used."), $shortFilename);
667: break;
668: case self::CON_PREDICT_CHANGEPERM_SAMEOWNER:
669: $mfileperms = substr(sprintf("%o", fileperms($filename)), -3);
670: $mfileperms{0} = intval($mfileperms{0}) | 0x6;
671: $predictMessage = sprintf(i18n("Your web server and the owner of your files are identical. You need to enable write access for the owner, e.g. using chmod u+rw %s, setting the file mask to %s or set the owner to allow writing the file."), $shortFilename, $mfileperms);
672: break;
673: case self::CON_PREDICT_CHANGEPERM_SAMEGROUP:
674: $mfileperms = substr(sprintf("%o", fileperms($filename)), -3);
675: $mfileperms{1} = intval($mfileperms{1}) | 0x6;
676: $predictMessage = sprintf(i18n("Your web server's group and the group of your files are identical. You need to enable write access for the group, e.g. using chmod g+rw %s, setting the file mask to %s or set the group to allow writing the file."), $shortFilename, $mfileperms);
677: break;
678: case self::CON_PREDICT_CHANGEPERM_OTHERS:
679: $mfileperms = substr(sprintf("%o", fileperms($filename)), -3);
680: $mfileperms{2} = intval($mfileperms{2}) | 0x6;
681: $predictMessage = sprintf(i18n("Your web server is not equal to the file owner, and is not in the webserver's group. It would be highly insecure to allow world write acess to the files. If you want to install anyways, enable write access for all others, e.g. using chmod o+rw %s, setting the file mask to %s or set the others to allow writing the file."), $shortFilename, $mfileperms);
682: break;
683: }
684: } else {
685: $target = dirname($filename);
686:
687: $perm = $this->predictCorrectFilepermissions($target);
688:
689: switch ($perm) {
690: case self::CON_PREDICT_WINDOWS:
691: $predictMessage = i18n("Your Server runs Windows. Due to that, Setup can't recommend any directory permissions.");
692: break;
693: case self::CON_PREDICT_NOTPREDICTABLE:
694: $predictMessage = sprintf(i18n("Due to a very restrictive environment, an advise is not possible. Ask your system administrator to enable write access to the file or directory %s, especially in environments where ACL (Access Control Lists) are used."), dirname($shortFilename));
695: break;
696: case self::CON_PREDICT_CHANGEPERM_SAMEOWNER:
697: $mfileperms = substr(sprintf("%o", @fileperms($target)), -3);
698: $mfileperms{0} = intval($mfileperms{0}) | 0x6;
699: $predictMessage = sprintf(i18n("Your web server and the owner of your directory are identical. You need to enable write access for the owner, e.g. using chmod u+rw %s, setting the directory mask to %s or set the owner to allow writing the directory."), dirname($shortFilename), $mfileperms);
700: break;
701: case self::CON_PREDICT_CHANGEPERM_SAMEGROUP:
702: $mfileperms = substr(sprintf("%o", @fileperms($target)), -3);
703: $mfileperms{1} = intval($mfileperms{1}) | 0x6;
704: $predictMessage = sprintf(i18n("Your web server's group and the group of your directory are identical. You need to enable write access for the group, e.g. using chmod g+rw %s, setting the directory mask to %s or set the group to allow writing the directory."), dirname($shortFilename), $mfileperms);
705: break;
706: case self::CON_PREDICT_CHANGEPERM_OTHERS:
707: $mfileperms = substr(sprintf("%o", @fileperms($target)), -3);
708: $mfileperms{2} = intval($mfileperms{2}) | 0x6;
709: $predictMessage = sprintf(i18n("Your web server is not equal to the directory owner, and is not in the webserver's group. It would be highly insecure to allow world write acess to the directory. If you want to install anyways, enable write access for all others, e.g. using chmod o+rw %s, setting the directory mask to %s or set the others to allow writing the directory."), dirname($shortFilename), $mfileperms);
710: break;
711: }
712: }
713:
714: $this->storeResult(false, $severity, $title, $message . "<br /><br />" . $predictMessage);
715: if ($title && $message) {
716: $status = false;
717: }
718: }
719:
720: return $status;
721: }
722:
723: 724: 725: 726: 727: 728:
729: protected function getPHPIniSetting($setting) {
730:
731: $value = @ini_get($setting);
732:
733: return $value;
734: }
735:
736: 737: 738: 739: 740: 741:
742: protected function getAsBytes($val) {
743: if (strlen($val) == 0) {
744: return 0;
745: }
746: $val = trim($val);
747: $last = $val{strlen($val) - 1};
748: switch ($last) {
749: case 'k':
750: case 'K':
751: return (int) $val * 1024;
752: break;
753: case 'm':
754: case 'M':
755: return (int) $val * 1048576;
756: break;
757: case 'g':
758: case 'G':
759: return (int) $val * 1048576 * 1024;
760: break;
761: default:
762: return $val;
763: }
764: }
765:
766: 767: 768: 769: 770: 771: 772: 773: 774:
775: protected function doMySQLConnect($host, $username, $password) {
776: $aOptions = array(
777: 'connection' => array(
778: 'host' => $host,
779: 'user' => $username,
780: 'password' => $password
781: )
782: );
783: try {
784: $db = new cDb($aOptions);
785: } catch (cDbException $e) {
786: return array(
787: $db,
788: false
789: );
790: }
791:
792: if ($db->connect() == 0) {
793: return array(
794: $db,
795: false
796: );
797: } else {
798: return array(
799: $db,
800: true
801: );
802: }
803: }
804:
805: 806: 807: 808: 809: 810:
811: public function isPHPExtensionLoaded($extension) {
812: $value = extension_loaded($extension);
813:
814: if ($value === NULL) {
815: return self::CON_EXTENSION_CANTCHECK;
816: }
817:
818: if ($value === true) {
819: return self::CON_EXTENSION_AVAILABLE;
820: }
821:
822: if ($value === false) {
823: return self::CON_EXTENSION_UNAVAILABLE;
824: }
825: }
826:
827: 828: 829: 830: 831:
832: public function isWindows() {
833: if (strtolower(substr(PHP_OS, 0, 3)) == "win") {
834: return true;
835: } else {
836: return false;
837: }
838: }
839:
840: 841: 842: 843: 844:
845: public function testPHPVersion() {
846: if (version_compare(phpversion(), CON_SETUP_MIN_PHP_VERSION, '>=') == true) {
847: return true;
848: } else {
849: return false;
850: }
851: }
852:
853: public function getSafeModeStatus() {
854: if ($this->getPHPIniSetting("safe_mode") == "1") {
855: return true;
856: } else {
857: return false;
858: }
859: }
860:
861: public function getSafeModeGidStatus() {
862: if ($this->getPHPIniSetting("safe_mode_gid") == "1") {
863: return true;
864: } else {
865: return false;
866: }
867: }
868:
869: public function testXMLParserCreate() {
870: return function_exists("xml_parser_create");
871: }
872:
873: public function testFileUploadSetting() {
874: return $this->getPHPIniSetting('file_uploads');
875: }
876:
877: public function testMagicQuotesRuntimeSetting() {
878: return !$this->getPHPIniSetting('magic_quotes_runtime');
879: }
880:
881: public function testMagicQuotesSybaseSetting() {
882: return !$this->getPHPIniSetting('magic_quotes_sybase');
883: }
884:
885: public function testMaxExecutionTime() {
886: return intval($this->getPHPIniSetting('max_execution_time')) >= 30;
887: }
888:
889: public function testZIPArchive() {
890: return class_exists("ZipArchive");
891: }
892:
893: public function testMemoryLimit() {
894: $memoryLimit = $this->getAsBytes($this->getPHPIniSetting("memory_limit"));
895: return ($memoryLimit > 1024 * 1024 * 32) || ($memoryLimit == 0);
896: }
897:
898: public function testPHPSQLSafeMode() {
899: return !$this->getPHPIniSetting('sql.safe_mode');
900: }
901:
902: public function testDOMDocument() {
903: return class_exists("DOMDocument");
904: }
905:
906: public function testPHPExtension($ext) {
907: return $this->isPHPExtensionLoaded($ext) == CON_EXTENSION_AVAILABLE;
908: }
909:
910: public function testIconv() {
911: return function_exists("iconv");
912: }
913:
914: public function testGDGIFRead() {
915: if (($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_AVAILABLE) && ($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_CANTCHECK)) {
916: return false;
917: }
918: return function_exists("imagecreatefromgif");
919: }
920:
921: public function testGDGIFWrite() {
922: if (($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_AVAILABLE) && ($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_CANTCHECK)) {
923: return false;
924: }
925: return function_exists("imagegif");
926: }
927:
928: public function testGDJPEGRead() {
929: if (($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_AVAILABLE) && ($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_CANTCHECK)) {
930: return false;
931: }
932: return function_exists("imagecreatefromjpeg");
933: }
934:
935: public function testGDJPEGWrite() {
936: if (($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_AVAILABLE) && ($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_CANTCHECK)) {
937: return false;
938: }
939: return function_exists("imagejpeg");
940: }
941:
942: public function testGDPNGRead() {
943: if (($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_AVAILABLE) && ($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_CANTCHECK)) {
944: return false;
945: }
946: return function_exists("imagecreatefrompng");
947: }
948:
949: public function testGDPNGWrite() {
950: if (($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_AVAILABLE) && ($this->isPHPExtensionLoaded('gd') != self::CON_EXTENSION_CANTCHECK)) {
951: return false;
952: }
953: return function_exists("imagepng");
954: }
955:
956: public function testMySQLExtension() {
957: if ($this->isPHPExtensionLoaded("mysql") == self::CON_EXTENSION_AVAILABLE) {
958: return true;
959: } else {
960: return false;
961: }
962: }
963:
964: public function testMySQLiExtension() {
965: if ($this->isPHPExtensionLoaded("mysqli") == self::CON_EXTENSION_AVAILABLE) {
966: return true;
967: } else {
968: return false;
969: }
970: }
971:
972: public function testMySQLModeStrict($host, $username, $password) {
973:
974: $dbCfg = array(
975: 'connection' => array(
976: 'host' => $host,
977: 'user' => $username,
978: 'password' => $password
979: )
980: );
981:
982: $db = new cDb($dbCfg);
983: $db->query('SELECT LOWER(@@GLOBAL.sql_mode) AS sql_mode');
984: if ($db->nextRecord()) {
985: if (strpos($db->f('sql_mode'), 'strict_trans_tables') !== false || strpos($db->f('sql_mode'), 'strict_all_tables') !== false) {
986: return false;
987: }
988: }
989: return true;
990: }
991:
992: public function testMySQL($host, $username, $password) {
993: list($handle, $status) = $this->doMySQLConnect($host, $username, $password);
994:
995: $errorMessage = "";
996: if ($this->testMySQLiExtension() && !$this->testMySQLExtension()) {
997: $errorMessage = mysqli_error($handle->getLinkId());
998: } else {
999: $errorMessage = mysql_error();
1000: }
1001: if ($errorMessage != "") {
1002: return $errorMessage;
1003: }
1004:
1005: if ($handle->getLinkId()->errno == 1045) {
1006: return self::CON_MYSQL_CANT_CONNECT;
1007: }
1008:
1009: if (!$this->testMySQLModeStrict($host, $username, $password)) {
1010: return self::CON_MYSQL_STRICT_MODE;
1011: }
1012:
1013: return self::CON_MYSQL_OK;
1014: }
1015:
1016: public function testFilesystem($testConfig = true, $testFrontend = true) {
1017: global $cfgClient;
1018:
1019: $status = true;
1020:
1021: $files = array(
1022:
1023: array(
1024: 'filename' => $this->_config['path']['contenido_logs'] . "errorlog.txt",
1025: 'severity' => self::C_SEVERITY_WARNING
1026: ),
1027: array(
1028: 'filename' => $this->_config['path']['contenido_logs'] . "setuplog.txt",
1029: 'severity' => self::C_SEVERITY_WARNING
1030: ),
1031: array(
1032: 'filename' => $this->_config['path']['contenido_cronlog'] . "pseudo-cron.log",
1033: 'severity' => self::C_SEVERITY_WARNING
1034: ),
1035: array(
1036: 'filename' => $this->_config['path']['contenido_cronlog'] . "session_cleanup.php.job",
1037: 'severity' => self::C_SEVERITY_WARNING
1038: ),
1039: array(
1040: 'filename' => $this->_config['path']['contenido_cronlog'] . "send_reminder.php.job",
1041: 'severity' => self::C_SEVERITY_WARNING
1042: ),
1043: array(
1044: 'filename' => $this->_config['path']['contenido_cronlog'] . "optimize_database.php.job",
1045: 'severity' => self::C_SEVERITY_WARNING
1046: ),
1047: array(
1048: 'filename' => $this->_config['path']['contenido_cronlog'] . "move_old_stats.php.job",
1049: 'severity' => self::C_SEVERITY_WARNING
1050: ),
1051: array(
1052: 'filename' => $this->_config['path']['contenido_cronlog'] . "move_articles.php.job",
1053: 'severity' => self::C_SEVERITY_WARNING
1054: ),
1055: array(
1056: 'filename' => $this->_config['path']['contenido_cronlog'] . "linkchecker.php.job",
1057: 'severity' => self::C_SEVERITY_WARNING
1058: ),
1059: array(
1060: 'filename' => $this->_config['path']['contenido_cronlog'] . "run_newsletter_job.php.job",
1061: 'severity' => self::C_SEVERITY_WARNING
1062: ),
1063: array(
1064: 'filename' => $this->_config['path']['contenido_cronlog'] . "setfrontenduserstate.php.job",
1065: 'severity' => self::C_SEVERITY_WARNING
1066: ),
1067: array(
1068: 'filename' => $this->_config['path']['contenido_cronlog'] . "advance_workflow.php.job",
1069: 'severity' => self::C_SEVERITY_WARNING
1070: ),
1071: array(
1072: 'filename' => $this->_config['path']['contenido_cache'],
1073: 'severity' => self::C_SEVERITY_WARNING,
1074: 'dir' => true
1075: ),
1076: array(
1077: 'filename' => $this->_config['path']['contenido_temp'],
1078: 'severity' => self::C_SEVERITY_WARNING,
1079: 'dir' => true
1080: ),
1081: array(
1082: 'filename' => $this->_config['path']['contenido_config'] . "config.php",
1083: 'severity' => self::C_SEVERITY_ERROR,
1084: 'config' => $testConfig
1085: )
1086: );
1087:
1088: $frontendFiles = array(
1089: "cache",
1090: "cache/code",
1091: "css",
1092: "data",
1093: "data/layouts",
1094: "data/logs",
1095: "data/modules",
1096: "data/version",
1097: "data/version/css",
1098: "data/version/js",
1099: "data/version/layout",
1100: "data/version/module",
1101: "data/version/templates",
1102: "js",
1103: "templates",
1104: "upload"
1105: );
1106:
1107: $ret = true;
1108: foreach ($files as $key => $file) {
1109:
1110: $name = $file['filename'];
1111: $severity = $file['severity'];
1112: $dir = $file['dir'];
1113: $frontend = $file['frontend'];
1114: $config = $file['config'];
1115:
1116: if (array_key_exists('frontend', $file) && $frontend != false) {
1117: $ret = $this->testSingleFile($name, $severity, $frontend);
1118: } else if (array_key_exists('config', $file) && $config != false) {
1119: $ret = $this->testSingleFile($name, $severity);
1120: } else if (!array_key_exists('frontend', $file) && !array_key_exists('config', $file)) {
1121: $ret = $this->testSingleFile($name, $severity, $config);
1122: }
1123: if ($ret == false) {
1124: $status = false;
1125: }
1126: }
1127:
1128: if ($testFrontend) {
1129: foreach ($cfgClient as $oneClient) {
1130: if (!is_array($oneClient)) {
1131: continue;
1132: }
1133: foreach ($frontendFiles as $file) {
1134: $ret = $this->testSingleFile($oneClient["path"]["frontend"] . $file, self::C_SEVERITY_WARNING, true);
1135: if ($ret == false) {
1136: $status = false;
1137: }
1138: }
1139: }
1140: }
1141:
1142: return $status;
1143: }
1144:
1145: public function testFrontendFolderCreation() {
1146: $directories = array(
1147: "cms/cache",
1148: "cms/cache/code",
1149: "cms/css",
1150: "cms/data",
1151: "cms/data/layouts",
1152: "cms/data/modules",
1153: "cms/data/version",
1154: "cms/data/version/css",
1155: "cms/data/version/js",
1156: "cms/data/version/layout",
1157: "cms/data/version/module",
1158: "cms/data/version/templates",
1159: "cms/js",
1160: "cms/templates",
1161: "cms/upload"
1162: );
1163:
1164: $ret = true;
1165:
1166: foreach ($directories as $dir) {
1167: if (!cFileHandler::exists("../" . $dir)) {
1168: if (!mkdir("../" . $dir)) {
1169: $ret = false;
1170: $this->storeResult(false, self::C_SEVERITY_WARNING, sprintf(i18n("Could not find or create directory %s"), $dir), i18n("The frontend expects certain directories to exist and it needs to be able to write to these directories."));
1171: } else {
1172: if (!cFileHandler::chmod("../" . $dir, "777")) {
1173: $ret = false;
1174: $this->storeResult(false, self::C_SEVERITY_WARNING, sprintf(i18n("Could not find or create directory %s"), $dir), i18n("The frontend expects certain directories to exist and it needs to be able to write to these directories."));
1175: }
1176: }
1177: }
1178: }
1179:
1180: return $ret;
1181: }
1182:
1183: 1184: 1185: 1186: 1187: 1188:
1189: public function checkOpenBasedirCompatibility() {
1190: $value = $this->getPHPIniSetting("open_basedir");
1191:
1192: if ($this->isWindows()) {
1193: $aBasedirEntries = explode(";", $value);
1194: } else {
1195: $aBasedirEntries = explode(":", $value);
1196: }
1197:
1198: if (count($aBasedirEntries) == 1 && $aBasedirEntries[0] == $value) {
1199: return self::CON_BASEDIR_NORESTRICTION;
1200: }
1201:
1202: if (in_array(".", $aBasedirEntries) && count($aBasedirEntries) == 1) {
1203: return self::CON_BASEDIR_DOTRESTRICTION;
1204: }
1205:
1206: $sCurrentDirectory = getcwd();
1207:
1208: foreach ($aBasedirEntries as $entry) {
1209: if (stristr($sCurrentDirectory, $entry)) {
1210: return self::CON_BASEDIR_RESTRICTIONSUFFICIENT;
1211: }
1212: }
1213:
1214: return self::CON_BASEDIR_INCOMPATIBLE;
1215: }
1216:
1217: 1218: 1219: 1220: 1221:
1222: public function checkImageResizer() {
1223: $iGDStatus = $this->isPHPExtensionLoaded('gd');
1224:
1225: if ($iGDStatus == self::CON_EXTENSION_AVAILABLE) {
1226: return self::CON_IMAGERESIZE_GD;
1227: }
1228:
1229: if (function_exists('imagecreate')) {
1230: return self::CON_IMAGERESIZE_GD;
1231: }
1232:
1233: checkAndInclude($this->_config['path']['contenido'] . 'includes/functions.api.images.php');
1234: if (capiIsImageMagickAvailable()) {
1235: return self::CON_IMAGERESIZE_IMAGEMAGICK;
1236: }
1237:
1238: if ($iGDStatus === self::CON_EXTENSION_CANTCHECK) {
1239: return self::CON_IMAGERESIZE_CANTCHECK;
1240: } else {
1241: return self::CON_IMAGERESIZE_NOTHINGAVAILABLE;
1242: }
1243: }
1244:
1245: }
1246:
1247: ?>