Overview

Packages

  • Horde
  • None

Classes

  • Horde_Application
  • Horde_Test

Functions

  • _
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Test:: class provides functions used in the test scripts
  4:  * used in the various applications (test.php).
  5:  *
  6:  * Copyright 1999-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (LGPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 10:  *
 11:  * @author   Chuck Hagenbuch <chuck@horde.org>
 12:  * @author   Jon Parise <jon@horde.org>
 13:  * @author   Brent J. Nordquist <bjn@horde.org>
 14:  * @author   Michael Slusarz <slusarz@horde.org>
 15:  * @category Horde
 16:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 17:  * @package  Horde
 18:  */
 19: 
 20: /* If gettext is not loaded, define a dummy _() function so that
 21:  * including any file with gettext strings won't cause a fatal error,
 22:  * causing test.php to return a blank page. */
 23: if (!function_exists('_')) {
 24:     function _($s) { return $s; }
 25: }
 26: 
 27: class Horde_Test
 28: {
 29:     /**
 30:      * The PHP version of the system.
 31:      *
 32:      * @var array
 33:      */
 34:     protected $_phpver;
 35: 
 36:     /**
 37:      * Supported versions of PHP.
 38:      *
 39:      * @var array
 40:      */
 41:     protected $_supported = array(
 42:         '5.2', '5.3'
 43:     );
 44: 
 45:     /**
 46:      * The module list
 47:      * <pre>
 48:      * KEY:   module name
 49:      * VALUE: Either the description or an array with the following entries:
 50:      *        descrip: (string) Module description
 51:      *        error: (string) Error message
 52:      *        fatal: (boolean) Is missing module fatal?
 53:      *        function: (string) Reference to function to run. If function
 54:      *                  returns boolean true, error message will be output.
 55:      *                  If function returns a string, this error message
 56:      *                  will be used.
 57:      *        phpver: (string) The PHP version above which to do the test
 58:      * </pre>
 59:      *
 60:      * @var array
 61:      */
 62:     protected $_moduleList = array(
 63:         'ctype' => array(
 64:             'descrip' => 'Ctype Support',
 65:             'error' => 'The ctype functions are required by the help system, the weather portal blocks, and a few Horde applications.'
 66:         ),
 67:         'dom' => array(
 68:             'descrip' => 'DOM XML Support',
 69:             'error' => 'Horde will not run without the dom extension. Don\'t compile PHP with <code>--disable-all/--disable-dom</code>, or enable the dom extension individually before continuing.',
 70:             'fatal' => true
 71:         ),
 72:         'fileinfo' => array(
 73:             'descrip' => 'MIME Magic Support (fileinfo)',
 74:             'error' => 'The fileinfo PECL module is used to provide MIME Magic scanning on unknown data. See horde/docs/INSTALL for information on how to install PECL extensions.'
 75:         ),
 76:         'fileinfo_check' => array(
 77:             'descrip' => 'MIME Magic Support (fileinfo) - Configuration',
 78:             'error' => 'The fileinfo module could not open the default MIME Magic database location. You will need to manually specify the MIME Magic database location in the config file.',
 79:             'function' => '_checkFileinfo'
 80:         ),
 81:         'ftp' => array(
 82:             'descrip' => 'FTP Support',
 83:             'error' => 'FTP support is only required if you want to authenticate against an FTP server, upload your configuration files with FTP, or use an FTP server for file storage.'
 84:         ),
 85:         'gd' => array(
 86:             'descrip' => 'GD Support',
 87:             'error' => 'Horde will use the GD extension to perform manipulations on image data. You can also use either the ImageMagick software or Imagick extension to do these manipulations instead.'
 88:         ),
 89:         'gettext' => array(
 90:             'descrip' => 'Gettext Support',
 91:             'error' => 'Horde will not run without gettext support. Compile PHP with <code>--with-gettext</code> before continuing.',
 92:             'fatal' => true
 93:         ),
 94:         'geoip' => array(
 95:             'descrip' => 'GeoIP Support (PECL extension)',
 96:             'error' => 'Horde can optionally use the GeoIP extension to provide faster country name lookups.'
 97:         ),
 98:         'hash' => array(
 99:             'descrip' => 'Hash Support',
100:             'error' => 'Horde will not run without the hash extension. Don\'t compile PHP with <code>--disable-all/--disable-hash</code>, or enable the hash extension individually before continuing.',
101:             'fatal' => true
102:         ),
103:         'iconv' => array(
104:             'descrip' => 'Iconv Support',
105:             'error' => 'If you want to take full advantage of Horde\'s localization features and character set support, you will need the iconv extension.'
106:         ),
107:         'iconv_libiconv' => array(
108:             'descrip' => 'GNU Iconv Support',
109:             'error' => 'For best results make sure the iconv extension is linked against GNU libiconv.',
110:             'function' => '_checkIconvImplementation'
111:         ),
112:         'intl' => array(
113:             'descrip' => 'Internationalization Support',
114:             'error' => 'Horde requires the intl module to handle Internationalized Domain Names. This module can either be compiled with PHP 5.3.0+ (requires <code>--enable-intl</code>) or can be installed via PECL.'
115:         ),
116:         'imagick' => array(
117:             'descrip' => 'Imagick Library',
118:             'error' => 'Horde can make use of the Imagick Library, if it is installed on your system.  It is highly recommended to use either ImageMagick\'s convert utility or the Imagick php library for faster results.'
119:         ),
120:         'json' => array(
121:             'descrip' => 'JSON Support',
122:             'error' => 'Horde will not run without the json extension. Don\'t compile PHP with <code>--disable-all/--disable-json</code>, or enable the json extension individually before continuing.',
123:             'fatal' => true
124:         ),
125:         'ldap' => array(
126:             'descrip' => 'LDAP Support',
127:             'error' => 'LDAP support is only required if you want to use an LDAP server for anything like authentication, address books, or preference storage.'
128:         ),
129:         'lzf' => array(
130:             'descrip' => 'LZF Compression Support (PECL extension)',
131:             'error' => 'If the lzf PECL module is available, Horde can compress some cached data in your session to make your session size smaller.'
132:         ),
133:         'mbstring' => array(
134:             'descrip' => 'Mbstring Support',
135:             'error' => 'If you want to take full advantage of Horde\'s localization features and character set support, you will need the mbstring extension.'
136:         ),
137:         'memcache' => array(
138:             'descrip' => 'memcached Support (memcache) (PECL extension)',
139:             'error' => 'The memcache PECL module is only needed if you are using a memcached server for caching or sessions. See horde/docs/INSTALL for information on how to install PECL/PHP extensions.'
140:         ),
141:         'mysql' => array(
142:             'descrip' => 'MySQL Support',
143:             'error' => 'The MySQL extension is only required if you want to use a MySQL database server for data storage.'
144:         ),
145:         'openssl' => array(
146:             'descrip' => 'OpenSSL Support',
147:             'error' => 'The OpenSSL extension is required for any kind of S/MIME support.'
148:         ),
149:         'pam' => array(
150:             'descrip' => 'PAM Support',
151:             'error' => 'The PAM extension is required to allow PAM authentication to be used.',
152:             'function' => '_checkPam'
153:         ),
154:         'pcre' => array(
155:             'descrip' => 'PCRE Support',
156:             'error' => 'Horde will not run without the pcre extension. Don\'t compile PHP with <code>--disable-all/--without-pcre-regex</code>, or enable the pcre extension individually before continuing.',
157:             'fatal' => true
158:         ),
159:         'pdo' => array(
160:             'descrip' => 'PDO',
161:             'error' => 'The PDO extension is required if you plan on using a database backend other than mysql or mysqli with Horde_Db.',
162:         ),
163:         'pgsql' => array(
164:             'descrip' => 'PostgreSQL Support',
165:             'error' => 'The PostgreSQL extension is only required if you want to use a PostgreSQL database server for data storage.'
166:         ),
167:         'session' => array(
168:             'descrip' => 'Session Support',
169:             'fatal' => true
170:         ),
171:         'SimpleXML' => array(
172:             'descrip' => 'SimpleXML support',
173:             'error' => 'Horde will not run without the SimpleXML extension. Don\'t compile PHP with <code>--disable-all/--disable-simplexml</code>, or enable the SimpleXML extension individually before continuing.',
174:             'fatal' => true
175:         ),
176:         'tidy' => array(
177:             'descrip' => 'Tidy support',
178:             'error' => 'The tidy PHP extension is used to sanitize HTML data.'
179:         ),
180:         'xml' => array(
181:             'descrip' => 'XML Parser support',
182:             'error' => 'Horde will not run without the xml extension. Don\'t compile PHP with <code>--disable-all/--without-xml</code>, or enable the xml extension individually before continuing.',
183:             'fatal' => true,
184:             'function' => '_checkLibxmlVersion'
185:         ),
186:         'zlib' => array(
187:             'descrip' => 'Zlib Support',
188:             'error' => 'The zlib module is highly recommended for use with Horde.  It allows page compression and handling of ZIP and GZ data. Compile PHP with <code>--with-zlib</code> to activate.'
189:         )
190:     );
191: 
192:     /**
193:      * PHP settings list.
194:      * <pre>
195:      * KEY:   setting name
196:      * VALUE: An array with the following entries:
197:      *        error: (string) Error message.
198:      *        function: (string) Reference to function to run. If function
199:      *                  returns non-empty value, error message will be output.
200:      *        setting: (mixed) Either a boolean (whether setting should be
201:      *                 on or off) or 'value', which will simply output the
202:      *                 value of the setting.
203:      * </pre>
204:      *
205:      * @var array
206:      */
207:     protected $_settingsList = array(
208:         'allow_url_include' => array(
209:             'setting' => false,
210:             'error' => 'This is a security hazard. Horde will attempt to disable automatically, but it is best to manually disable also.'
211:         ),
212:         'magic_quotes_runtime' => array(
213:             'setting' => false,
214:             'error' => 'magic_quotes_runtime may cause problems with database inserts, etc. Horde will attempt to disable automatically, but it is best to manually disable also.'
215:         ),
216:         'magic_quotes_sybase' => array(
217:             'setting' => false,
218:             'error' => 'magic_quotes_sybase may cause problems with database inserts, etc. Horde will attempt to disable automatically, but it is best to manually disable also.'
219:         ),
220:         'memory_limit' => array(
221:             'setting' => 'value',
222:             'error' => 'If PHP\'s internal memory limit is not set high enough Horde will not be able to handle large data items. It is recommended to set the value of memory_limit in php.ini to at least 64M.',
223:             'function' => '_checkMemoryLimit'
224:         ),
225:         'register_globals' => array(
226:             'setting' => false,
227:             'error' => 'Register globals has been deprecated in PHP 5. Horde will fatally exit if it is set. Turn it off.'
228:         ),
229:         'safe_mode' => array(
230:             'setting' => false,
231:             'error' => 'If safe_mode is enabled, Horde cannot set enviroment variables, which means Horde will be unable to translate the user interface into different languages.'
232:         ),
233:         'session.auto_start' => array(
234:             'setting' => false,
235:             'error' => 'Horde won\'t work with automatically started sessions, because it explicitly creates new session when necessary to protect against session fixations.'
236:         ),
237:         'session.gc_divisor' => array(
238:             'setting' => 'value',
239:             'error' => 'PHP automatically garbage collects old session information, as long as this setting (and session.gc_probability) are set to non-zero. It is recommended that this value be "10000" or higher (see docs/INSTALL).',
240:             'function' => '_checkGcDivisor'
241:         ),
242:         'session.gc_probability' => array(
243:             'setting' => 'value',
244:             'error' => 'PHP automatically garbage collects old session information, as long as this setting (and session.gc_divisor) are set to non-zero. It is recommended that this value be "1".',
245:             'function' => '_checkGcProbability'
246:         ),
247:         'session.use_trans_sid' => array(
248:             'setting' => false,
249:             'error' => 'Horde will work with session.use_trans_sid turned on, but you may see double session-ids in your URLs, and if the session name in php.ini differs from the session name configured in Horde, you may get two session ids and see other odd behavior. The URL-rewriting that use_trans_sid does also tends to break XHTML compliance. In short, you should really disable this.'
250:         ),
251:         'tidy.clean_output' => array(
252:             'setting' => false,
253:             'error' => 'This will break output of any dynamically created, non-HTML content. Horde will attempt to disable automatically, but it is best to manually disable also.'
254:         ),
255:         'zend_accelerator.compress_all' => array(
256:             'setting' => false,
257:             'error' => 'You should not enable output compression unconditionally because some browsers and scripts don\'t work well with output compression. Enable compression in Horde\'s configuration instead, so that we have full control over the conditions where to enable and disable it.'
258:         ),
259:         'zend.ze1_compatibility_mode' => array(
260:             'setting' => false,
261:             'error' => 'Unneeded, deprecated PHP 4 compatibility option. Horde will attempt to disable automatically, but it is best to manually disable also.'
262:         ),
263:         'zlib.output_compression' => array(
264:             'setting' => false,
265:             'error' => 'You should not enable output compression unconditionally because some browsers and scripts don\'t work well with output compression. Enable compression in Horde\'s configuration instead, so that we have full control over the conditions where to enable and disable it.'
266:         )
267:     );
268: 
269:     /**
270:      * PEAR modules list.
271:      * <pre>
272:      * KEY:   PEAR class name
273:      * VALUE: An array with the following entries:
274:      *        depends: (?) This module depends on another module.
275:      *        error: (string) Error message.
276:      *        function: (string) Reference to function to run if module is
277:      *                  found.
278:      *        path: (string) The path to the PEAR module. Only needed if
279:      *                 KEY is not autoloadable.
280:      *        required: (boolean) Is this PEAR module required?
281:      * </pre>
282:      *
283:      * @var array
284:      */
285:     protected $_pearList = array(
286:         'Auth_SASL' => array(
287:             'error' => 'Horde will work without the Auth_SASL class, but if you use Access Control Lists in IMP you should be aware that without this class passwords will be sent to the IMAP server in plain text when retrieving ACLs.'
288:         ),
289:         'Cache' => array(
290:             'error' => 'Cache is used by the Services_Weather module on the weather applet/block on the portal page.'
291:         ),
292:         'Crypt_Blowfish' => array(
293:             'error' => 'Crypt_Blowfish is required to store authentication credentials securely within the session data.',
294:             'required' => true
295:         ),
296:         'Date' => array(
297:             'path' => 'Date/Calc.php',
298:             'error' => 'Horde requires the Date_Calc class for Kronolith to calculate dates.'
299:         ),
300:         'HTTP_Request' => array(
301:             'error' => 'Parts of Horde (Jonah, the XML-RPC client/server) use the HTTP_Request library to retrieve URLs and do other HTTP requests.'
302:         ),
303:         'HTTP_WebDAV_Server' => array(
304:             'error' => 'The HTTP_WebDAV_Server is required if you want to use the WebDAV interface of Horde, e.g. to access calendars or tasklists with external clients.'
305:         ),
306:         'MDB2' => array(
307:             'error' => 'You will need MDB2 if you are using the SQL driver for Shares.',
308:         ),
309:         'Net_DNS2' => array(
310:             'error' => 'Net_DNS2 can speed up hostname lookups against broken DNS servers.'
311:         ),
312:         'Net_SMTP' => array(
313:             'error' => 'Make sure you are using the Net_SMTP module if you want "smtp" to work as a mailer option.'
314:         ),
315:         'Net_Socket' => array(
316:             'error' => 'Make sure you are using a version of PEAR which includes the Net_Socket class, or that you have installed the Net_Socket package seperately. See the INSTALL file for instructions on installing Net_Socket.'
317:         ),
318:         'Services_Weather' => array(
319:             'error' => 'Services_Weather is used by the weather applet/block on the portal page.'
320:         ),
321:         'XML_Serializer' => array(
322:             'error' => 'XML_Serializer is used by the Services_Weather module on the weather applet/block on the portal page.'
323:         )
324:     );
325: 
326:     /**
327:      * Required configuration files.
328:      * <pre>
329:      * KEY:   file path
330:      * VALUE: The error message to use (null to use default message)
331:      * </pre>
332:      *
333:      * @var array
334:      */
335:     protected $_fileList = array(
336:         'config/conf.php' => null,
337:     );
338: 
339:     /**
340:      * Inter-Horde application dependencies.
341:      * <pre>
342:      * KEY:   app name
343:      * VALUE: An array with the following entries:
344:      *        error: (string) Error message.
345:      *        version: (string) Minimum version required of the app.
346:      * </pre>
347:      *
348:      * @var array
349:      */
350:     protected $_appList = array();
351: 
352:     /**
353:      * Constructor.
354:      */
355:     public function __construct()
356:     {
357:         /* Store the PHP version information. */
358:         $this->_phpver = $this->_splitPhpVersion(PHP_VERSION);
359: 
360:         /* We want to be as verbose as possible here. */
361:         error_reporting(E_ALL);
362: 
363:         /* Set character encoding. */
364:         header('Content-type: text/html; charset=UTF-8');
365:         header('Vary: Accept-Language');
366:     }
367: 
368:     /**
369:      * Parse PHP version.
370:      *
371:      * @param string $version  A PHP-style version string (X.X.X).
372:      *
373:      * @param array  The parsed string.
374:      *               Keys: 'major', 'minor', 'subminor', 'class'
375:      */
376:     protected function _splitPhpVersion($version)
377:     {
378:         /* First pick off major version, and lower-case the rest. */
379:         if ((strlen($version) >= 3) && ($version[1] == '.')) {
380:             $phpver['major'] = substr($version, 0, 3);
381:             $version = substr(strtolower($version), 3);
382:         } else {
383:             $phpver['major'] = $version;
384:             $phpver['class'] = 'unknown';
385:             return $phpver;
386:         }
387: 
388:         if ($version[0] == '.') {
389:             $version = substr($version, 1);
390:         }
391: 
392:         /* Next, determine if this is 4.0b or 4.0rc; if so, there is no
393:            minor, the rest is the subminor, and class is set to beta. */
394:         $s = strspn($version, '0123456789');
395:         if ($s == 0) {
396:             $phpver['subminor'] = $version;
397:             $phpver['class'] = 'beta';
398:             return $phpver;
399:         }
400: 
401:         /* Otherwise, this is non-beta;  the numeric part is the minor,
402:            the rest is either a classification (dev, cvs) or a subminor
403:            version (rc<x>, pl<x>). */
404:         $phpver['minor'] = substr($version, 0, $s);
405:         if ((strlen($version) > $s) &&
406:             (($version[$s] == '.') || ($version[$s] == '-'))) {
407:             ++$s;
408:         }
409:         $phpver['subminor'] = substr($version, $s);
410:         if (($phpver['subminor'] == 'cvs') ||
411:             ($phpver['subminor'] == 'dev') ||
412:             (substr($phpver['subminor'], 0, 2) == 'rc')) {
413:             unset($phpver['subminor']);
414:             $phpver['class'] = 'dev';
415:         } else {
416:             if (!$phpver['subminor']) {
417:                 unset($phpver['subminor']);
418:             }
419:             $phpver['class'] = 'release';
420:         }
421: 
422:         return $phpver;
423:     }
424: 
425:     /**
426:      * Check the list of PHP modules.
427:      *
428:      * @return string  The HTML output.
429:      */
430:     public function phpModuleCheck()
431:     {
432:         $output = '';
433: 
434:         foreach ($this->_moduleList as $key => $val) {
435:             $error_msg = $mod_test = $status_out = $fatal = null;
436:             $test_function = null;
437:             $entry = array();
438: 
439:             if (is_array($val)) {
440:                 $descrip = $val['descrip'];
441:                 $fatal = !empty($val['fatal']);
442:                 if (isset($val['phpver']) &&
443:                     (version_compare(PHP_VERSION, $val['phpver']) == -1)) {
444:                     $mod_test = true;
445:                     $status_out = 'N/A';
446:                 }
447:                 if (isset($val['error'])) {
448:                     $error_msg = $val['error'];
449:                 }
450:                 if (isset($val['function'])) {
451:                     $test_function = $val['function'];
452:                 }
453:             } else {
454:                 $descrip = $val;
455:             }
456: 
457:             if (is_null($status_out)) {
458:                 if (is_null($test_function)) {
459:                     $mod_test = extension_loaded($key);
460:                 } else {
461:                     $mod_test = call_user_func(array($this, $test_function));
462:                     if (is_string($mod_test)) {
463:                         $error_msg = $mod_test;
464:                         $mod_test = false;
465:                     }
466:                 }
467:                 $status_out = $this->_status($mod_test, $fatal);
468:             }
469: 
470:             $entry[] = $descrip;
471:             $entry[] = $status_out;
472: 
473:             if (!is_null($error_msg) && !$mod_test) {
474:                 $entry[] = $error_msg;
475:                 if (!$fatal) {
476:                     $entry[] = 1;
477:                 }
478:             }
479: 
480:             $output .= $this->_outputLine($entry);
481: 
482:             if ($fatal && !$mod_test) {
483:                 echo $output;
484:                 exit;
485:             }
486:         }
487: 
488:         return $output;
489:     }
490: 
491:     /**
492:      * Additional check for iconv module implementation.
493:      *
494:      * @return boolean  False on error.
495:      */
496:     protected function _checkIconvImplementation()
497:     {
498:         return extension_loaded('iconv') &&
499:                in_array(ICONV_IMPL, array('libiconv', 'glibc'));
500:     }
501: 
502:     /**
503:      * Additional check for libxml version.
504:      *
505:      * @return boolean  False on error.
506:      */
507:     protected function _checkLibxmlVersion()
508:     {
509:         if (!extension_loaded('xml')) {
510:             return false;
511:         }
512:         if (LIBXML_VERSION < 20700) {
513:             return 'The libxml version is too old. libxml 2.7 or later is required.';
514:         }
515:         return true;
516:     }
517: 
518:     /**
519:      * Additional check for fileinfo module.
520:      *
521:      * @return boolean  False on error.
522:      */
523:     protected function _checkFileinfo()
524:     {
525:         if (extension_loaded('fileinfo') &&
526:             ($res = @finfo_open())) {
527:             finfo_close($res);
528:             return true;
529:         }
530: 
531:         return false;
532:     }
533: 
534:     /**
535:      */
536:     protected function _checkPam()
537:     {
538:         if (extension_loaded('pam')) {
539:             return true;
540:         }
541: 
542:         if (extension_loaded('pam_auth')) {
543:             return 'The PAM extension is required to allow PAM authentication to be used. You have an improper PAM extension loaded. Some installations (e.g. Debian, Ubuntu) ship with an altered version of the PAM extension. You must uninstall this extension and reinstall from PECL.';
544:         }
545: 
546:         return false;
547:     }
548: 
549:     /**
550:      * Checks the list of PHP settings.
551:      *
552:      * @params array $settings  The list of settings to check.
553:      *
554:      * @return string  The HTML output.
555:      */
556:     public function phpSettingCheck($settings = null)
557:     {
558:         $output = '';
559: 
560:         if (is_null($settings)) {
561:             $settings = $this->_settingsList;
562:         }
563: 
564:         foreach ($settings as $key => $val) {
565:             $entry = array();
566:             if (is_bool($val['setting'])) {
567:                 $result = (ini_get($key) == $val['setting']);
568:                 $entry[] = $key . ' ' . (($val['setting'] === true) ? 'enabled' : 'disabled');
569:                 $entry[] = $this->_status($result);
570:                 if (!$result &&
571:                     (!isset($val['function']) ||
572:                      call_user_func(array($this, $val['function'])))) {
573:                     $entry[] = $val['error'];
574:                 }
575:             } elseif ($val['setting'] == 'value') {
576:                 $entry[] = $key . ' value';
577:                 $entry[] = ini_get($key);
578:                 if (!empty($val['error']) &&
579:                     (!isset($val['function']) ||
580:                      call_user_func(array($this, $val['function'])))) {
581:                     $entry[] = $val['error'];
582:                     $entry[] = 1;
583:                 }
584:             }
585:             $output .= $this->_outputLine($entry);
586:         }
587: 
588:         return $output;
589:     }
590: 
591:     /**
592:      * Check the list of PEAR modules.
593:      *
594:      * @return string  The HTML output.
595:      */
596:     public function pearModuleCheck()
597:     {
598:         $output = '';
599: 
600:         /* Turn tracking of errors on. */
601:         ini_set('track_errors', 1);
602: 
603:         /* Print the include_path. */
604:         $output .= $this->_outputLine(array("<strong>PEAR Search Path (PHP's include_path)</strong>", '&nbsp;<tt>' . ini_get('include_path') . '</tt>'));
605: 
606:         /* Check for PEAR in general. */
607:         $entry = array();
608:         $entry[] = 'PEAR';
609:         $entry[] = $this->_status(!isset($php_errormsg));
610:         if (isset($php_errormsg)) {
611:             $entry[] = 'Check your PHP include_path setting to make sure it has the PEAR library directory.';
612:             $output .= $this->_outputLine($entry);
613:             ini_restore('track_errors');
614:             return $output;
615:         }
616:         $output .= $this->_outputLine($entry);
617: 
618:         /* Go through module list. */
619:         $succeeded = array();
620:         foreach ($this->_pearList as $key => $val) {
621:             $entry = array();
622: 
623:             /* If this module depends on another module that we
624:              * haven't succesfully found, fail the test. */
625:             if (!empty($val['depends']) && empty($succeeded[$val['depends']])) {
626:                 $result = false;
627:             } elseif (empty($val['path'])) {
628:                 $result = @class_exists($key);
629:             } else {
630:                 $result = @include_once $val['path'];
631:             }
632:             $error_msg = $val['error'];
633:             if ($result && isset($val['function'])) {
634:                 $func_output = call_user_func(array($this, $val['function']));
635:                 if ($func_output) {
636:                     $result = false;
637:                     $error_msg = $func_output;
638:                 }
639:             }
640:             $entry[] = $key;
641:             $entry[] = $this->_status($result, !empty($val['required']));
642: 
643:             if ($result) {
644:                 $succeeded[$key] = true;
645:             } else {
646:                 if (!empty($val['required'])) {
647:                     $error_msg .= ' THIS IS A REQUIRED MODULE!';
648:                 }
649:                 $entry[] = $error_msg;
650:                 if (empty($val['required'])) {
651:                     $entry[] = 1;
652:                 }
653:             }
654: 
655:             $output .= $this->_outputLine($entry);
656:         }
657: 
658:         /* Restore previous value of 'track_errors'. */
659:         ini_restore('track_errors');
660: 
661:         return $output;
662:     }
663: 
664:     /**
665:      * Additional check for 'session.gc_divisor'.
666:      *
667:      * @return boolean  Returns true if error string should be displayed.
668:      */
669:     protected function _checkMemoryLimit()
670:     {
671:         $memlimit = trim(ini_get('memory_limit'));
672:         switch (strtolower(substr($memlimit, -1))) {
673:         case 'g':
674:             $memlimit *= 1024;
675:             // Fall-through
676: 
677:         case 'm':
678:             $memlimit *= 1024;
679:             // Fall-through
680: 
681:         case 'k':
682:             $memlimit *= 1024;
683:             // Fall-through
684:         }
685: 
686:         return ($memlimit < 67108864);
687:     }
688: 
689:     /**
690:      * Additional check for 'session.gc_divisor'.
691:      *
692:      * @return boolean  Returns true if error string should be displayed.
693:      */
694:     protected function _checkGcDivisor()
695:     {
696:         return (ini_get('session.gc_divisor') < 10000);
697:     }
698: 
699:     /**
700:      * Additional check for 'session.gc_probability'.
701:      *
702:      * @return boolean  Returns true if error string should be displayed.
703:      */
704:     protected function _checkGcProbability()
705:     {
706:         return !(ini_get('session.gc_probability') &&
707:                  ini_get('session.gc_divisor'));
708:     }
709: 
710:     /**
711:      * Check the list of required files
712:      *
713:      * @return string  The HTML output.
714:      */
715:     public function requiredFileCheck()
716:     {
717:         $output = '';
718:         $filedir = $GLOBALS['registry']->get('fileroot');
719: 
720:         foreach ($this->_fileList as $key => $val) {
721:             $entry = array();
722:             $result = file_exists($filedir . '/' . $key);
723: 
724:             $entry[] = $key;
725:             $entry[] = $this->_status($result);
726: 
727:             if (!$result) {
728:                 if (empty($val)) {
729:                     $text = 'The file <code>' . $key . '</code> appears to be missing.';
730:                     if ($key == 'config/conf.php') {
731:                         $text .= ' You need to login to Horde as an administrator and create the initial configuration file.';
732:                     } else {
733:                         $text .= ' You probably just forgot to copy <code>' . $key . '.dist</code> over. While you do that, take a look at the settings and make sure they are appropriate for your site.';
734:                     }
735: 
736:                     $entry[] = $text;
737:                 } else {
738:                     $entry[] = $val;
739:                 }
740:             }
741: 
742:             $output .= $this->_outputLine($entry);
743:         }
744: 
745:         return $output;
746:     }
747: 
748:     /**
749:      * Check the list of required Horde applications.
750:      *
751:      * @return string  The HTML output.
752:      */
753:     public function requiredAppCheck()
754:     {
755:         $output = '';
756: 
757:         $horde_apps = $GLOBALS['registry']->listApps(null, true, null);
758: 
759:         foreach ($this->_appList as $key => $val) {
760:             $entry = array();
761:             $entry[] = $key;
762: 
763:             if (!isset($horde_apps[$key])) {
764:                 $entry[] = $this->_status(false, false);
765:                 $entry[] = $val['error'];
766:                 $entry[] = 1;
767:             } else {
768:                 /* Strip '-git', and H# (ver) from version string. */
769:                 $origver = $GLOBALS['registry']->getVersion($key);
770:                 $appver = preg_replace('/(H\d) \((.*)\)/', '$2', str_replace('-git', '', $origver));
771:                 if (version_compare($val['version'], $appver) === 1) {
772:                     $entry[] = $this->_status(false, false) . ' (Have version: ' . $origver . '; Need version: ' . $val['version'] . ')';
773:                     $entry[] = $val['error'];
774:                     $entry[] = 1;
775:                 } else {
776:                     $entry[] = $this->_status(true) . ' (Version: ' . $origver . ')';
777:                 }
778:             }
779:             $output .= $this->_outputLine($entry);
780:         }
781: 
782:         return $output;
783:     }
784: 
785:     /**
786:      * Obtain information on the PHP version.
787:      *
788:      * @return object stdClass  TODO
789:      */
790:     public function getPhpVersionInformation()
791:     {
792:         $output = new stdClass;
793:         $vers_check = true;
794: 
795:         $testscript = Horde::selfUrl(true);
796:         $output->phpinfo = $testscript->copy()->add('mode', 'phpinfo');
797:         $output->extensions = $testscript->copy()->add('mode', 'extensions');
798:         $output->version = PHP_VERSION;
799:         $output->major = $this->_phpver['major'];
800:         if (isset($this->_phpver['minor'])) {
801:             $output->minor = $this->_phpver['minor'];
802:         }
803:         if (isset($this->_phpver['subminor'])) {
804:             $output->subminor = $this->_phpver['subminor'];
805:         }
806:         $output->class = $this->_phpver['class'];
807: 
808:         $output->status_color = 'red';
809:         if ($output->major < '5.2') {
810:             $output->status = 'This version of PHP is not supported. You need to upgrade to a more recent version.';
811:             $vers_check = false;
812:         } elseif (in_array($output->major, $this->_supported)) {
813:             $output->status = 'You are running a supported version of PHP.';
814:             $output->status_color = 'green';
815:         } else {
816:             $output->status = 'This version of PHP has not been fully tested with this version of Horde.';
817:             $output->status_color = 'orange';
818:         }
819: 
820:         if (!$vers_check) {
821:             $output->version_check = 'Horde requires PHP 5.2.0 or greater.';
822:         }
823: 
824:         return $output;
825:     }
826: 
827:     /**
828:      * Output the results of a status check.
829:      *
830:      * @param boolean $bool      The result of the status check.
831:      * @param boolean $required  Whether the checked item is required.
832:      *
833:      * @return string  The HTML of the result of the status check.
834:      */
835:     protected function _status($bool, $required = true)
836:     {
837:         if ($bool) {
838:             return '<strong style="color:green">Yes</strong>';
839:         } elseif ($required) {
840:             return '<strong style="color:red">No</strong>';
841:         }
842: 
843:         return '<strong style="color:orange">No</strong>';
844:     }
845: 
846:     /**
847:      * Internal output function.
848:      *
849:      * @param array $entry  Array with the following values:
850:      * <pre>
851:      * 1st value: Header
852:      * 2nd value: Test Result
853:      * 3rd value: Error message (if present)
854:      * 4th value: Error level (if present): 0 = error, 1 = warning
855:      * </pre>
856:      *
857:      * @return string  HTML output.
858:      */
859:     protected function _outputLine($entry)
860:     {
861:         $output = '<li>' . array_shift($entry) . ': ' . array_shift($entry);
862:         if (!empty($entry)) {
863:             $msg = array_shift($entry);
864:             $output .= '<br /><strong style="color:' . (empty($entry) || !array_shift($entry) ? 'red' : 'orange') . '">' . $msg . "</strong>\n";
865:         }
866: 
867:         return $output . "</li>\n";
868:     }
869: 
870:     /**
871:      * Any application specific tests that need to be done.
872:      *
873:      * @return string  HTML output.
874:      */
875:     public function appTests()
876:     {
877:         /* File upload information. */
878:         $upload_check = $this->phpSettingCheck(array(
879:             'file_uploads' => array(
880:                 'error' => 'file_uploads must be enabled for some features like sending emails with IMP.',
881:                 'setting' => true
882:             )
883:         ));
884:         $upload_tmp_dir = ($dir = ini_get('upload_tmp_dir'))
885:             ? '<li>upload_tmp_dir: <strong style="color:"' . (is_writable($dir) ? 'green' : 'red') . '">' . $dir . '</strong></li>'
886:             : '';
887: 
888:         $ret = '<h1>File Uploads</h1><ul>' .
889:             $upload_check .
890:             $upload_tmp_dir .
891:             '<li>upload_max_filesize: ' . ini_get('upload_max_filesize') . '</li>'.
892:             '<li>post_max_size: ' . ini_get('post_max_size') . '<br />' .
893:             'This value should be several times the expect largest upload size (notwithstanding any upload limits present in an application). Any upload that exceeds this size will cause any state information sent along with the uploaded data to be lost. This is a PHP limitation and can not be worked around.'.
894:             '</li></ul>';
895: 
896:         /* Determine if 'static' is writable by the web user. */
897:         $ret .= '<h1>Local File Permissions</h1><ul>' .
898:             '<li>Is <tt>' . htmlspecialchars(HORDE_BASE) . '/static</tt> writable by the web server user? ';
899:         $ret .= is_writable(HORDE_BASE . '/static')
900:             ? '<strong style="color:green">Yes</strong>'
901:             : "<strong style=\"color:red\">No</strong><br /><strong style=\"color:orange\">If caching javascript and CSS files by storing them in static files (HIGHLY RECOMMENDED), this directory must be writable as the user the web server runs as.</strong>";
902: 
903:         if (extension_loaded('imagick')) {
904:             $im = new Imagick();
905:             $imagick = is_callable(array($im, 'getIteratorIndex'));
906:             $ret .= '</li></ul><h1>Imagick</h1><ul>' .
907:                 '<li>Imagick compiled against current ImageMagick version: ' . ($imagick ? 'Yes' : 'No');
908:         }
909: 
910:         return $ret . '</li></ul>';
911:     }
912: 
913: }
914: 
API documentation generated by ApiGen