Source for file configtest.php

Documentation is available at configtest.php

  1. <?php
  2.  
  3. /**
  4.  * SquirrelMail configtest script
  5.  *
  6.  * @copyright &copy; 2003-2006 The SquirrelMail Project Team
  7.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8.  * @version $Id: configtest.php,v 1.9.2.24 2006/10/07 11:58:42 tokul Exp $
  9.  * @package squirrelmail
  10.  * @subpackage config
  11.  */
  12.  
  13. /**********************************************************
  14.  * NOTE: you do not need to change this script!             *
  15.  * If it throws errors you need to adjust your config.      *
  16.  ************************************************************/
  17.  
  18.  
  19. function do_err($str, $exit = TRUE) {
  20.     global $IND;
  21.     echo '<p>'.$IND.'<font color="red"><b>ERROR:</b></font> ' .$str. "</p>\n";
  22.     if($exit) {
  23.          echo '</body></html>';
  24.          exit;
  25.     }
  26. }
  27.  
  28. /** @ignore */
  29. define('SM_PATH', '../');
  30.  
  31. /*
  32.  * Load config before output begins.
  33.  * functions/global.php cleans environment, then loads
  34.  * functions/strings.php and config/config.php
  35.  */
  36. if (file_exists(SM_PATH . 'config/config.php')) {
  37.     include(SM_PATH . 'functions/global.php');
  38. }
  39. $IND = str_repeat('&nbsp;',4);
  40.  
  41. // this must be done before the output is started because it may use the
  42. // session
  43. $test_location = get_location();
  44. ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  45. <html>
  46. <head>
  47.     <meta name="robots" content="noindex,nofollow">
  48.     <title>SquirrelMail configtest</title>
  49. </head>
  50. <body>
  51. <h1>SquirrelMail configtest</h1>
  52.  
  53. <p>This script will try to check some aspects of your SquirrelMail configuration
  54. and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt>
  55. in the <tt>config/</tt> directory first before you run this script.</p>
  56.  
  57. <?php
  58.  
  59.  
  60. $included = array_map('basename', get_included_files() );
  61. if(!in_array('config.php', $included)) {
  62.     if(!file_exists(SM_PATH . 'config/config.php')) {
  63.         do_err('Config file '.SM_PATH . 'config/config.php does not exist!<br />'.
  64.                'You need to run <tt>conf.pl</tt> first.');
  65.     }
  66.     do_err('Could not read '.SM_PATH.'config/config.php! Check file permissions.');
  67. }
  68. if(!in_array('strings.php', $included)) {
  69.     do_err('Could not include '.SM_PATH.'functions/strings.php!<br />'.
  70.            'Check permissions on that file.');
  71. }
  72.  
  73. /* checking PHP specs */
  74.  
  75. echo "<p><table>\n<tr><td>SquirrelMail version:</td><td><b>" . $version . "</b></td></tr>\n" .
  76.      '<tr><td>Config file version:</td><td><b>' . $config_version . "</b></td></tr>\n" .
  77.      '<tr><td>Config file last modified:</td><td><b>' . 
  78.          date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')) .
  79.          "</b></td></tr>\n</table>\n</p>\n\n";
  80.  
  81. echo "Checking PHP configuration...<br />\n";
  82.  
  83. if(!check_php_version(4,0,6)) {
  84.     do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.0.6');
  85. }
  86.  
  87. echo $IND . 'PHP version ' . PHP_VERSION . " OK.<br />\n";
  88.  
  89. $php_exts = array('session','pcre');
  90. $diff = array_diff($php_exts, get_loaded_extensions());
  91. if(count($diff)) {
  92.     do_err('Required PHP extensions missing: '.implode(', ',$diff) );
  93. }
  94.  
  95. echo $IND . "PHP extensions OK.<br />\n";
  96.  
  97. /* dangerous php settings */
  98. /** mbstring.func_overload<>0 fix. See cvs HEAD comments. */
  99. if (function_exists('mb_internal_encoding') &&
  100.     check_php_version(4,2,0) &&
  101.     (int)ini_get('mbstring.func_overload')!=0) {
  102.     $mb_error='You have enabled mbstring overloading.'
  103.         .' It can cause problems with SquirrelMail scripts that rely on single byte string functions.';
  104.     do_err($mb_error);
  105. }
  106.  
  107. /**
  108.  * We code with register_globals = off. SquirrelMail should work in such setup
  109.  * since 1.2.9 and 1.3.0. Running SquirrelMail with register_globals = on can
  110.  * cause variable corruption and security issues. Globals can be turned off in
  111.  * php.ini, webserver config and .htaccess files. Scripts can turn off globals only
  112.  * in php 4.2.3 or older.
  113.  */
  114. if ((bool) ini_get('register_globals') && 
  115.     ini_get('register_globals') != 'off') {
  116.     $rg_error='You have enabled PHP register_globals.'
  117.         .' Running PHP installation with register_globals=on can cause problems.'
  118.         .' See <a href="http://www.php.net/manual/en/security.registerglobals.php">'
  119.         .'security information about register_globals</a>.';
  120.     do_err($rg_error,false);
  121. }
  122.  
  123. /* checking paths */
  124.  
  125. echo "Checking paths...<br />\n";
  126.  
  127. if(!file_exists($data_dir)) {
  128.     do_err("Data dir ($data_dir) does not exist!");
  129. } 
  130. if(!is_dir($data_dir)) {
  131.     do_err("Data dir ($data_dir) is not a directory!");
  132. } 
  133. // datadir should be executable - but no clean way to test on that
  134. if(!is_writable($data_dir)) {
  135.     do_err("I cannot write to data dir ($data_dir)!");
  136. }
  137.  
  138. // todo_ornot: actually write something and read it back.
  139. echo $IND . "Data dir OK.<br />\n";
  140.  
  141.  
  142. if($data_dir == $attachment_dir) {
  143.     echo $IND . "Attachment dir is the same as data dir.<br />\n";
  144. } else {
  145.     if(!file_exists($attachment_dir)) {
  146.         do_err("Attachment dir ($attachment_dir) does not exist!");
  147.     } 
  148.     if (!is_dir($attachment_dir)) {
  149.         do_err("Attachment dir ($attachment_dir) is not a directory!");
  150.     } 
  151.     if (!is_writable($attachment_dir)) {
  152.         do_err("I cannot write to attachment dir ($attachment_dir)!");
  153.     }
  154.     echo $IND . "Attachment dir OK.<br />\n";
  155. }
  156.  
  157.  
  158. /* check plugins and themes */
  159. if (isset($plugins[0])) {
  160.     foreach($plugins as $plugin) {
  161.         if(!file_exists(SM_PATH .'plugins/'.$plugin)) {
  162.             do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE);
  163.         } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) {
  164.             do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE);
  165.         }
  166.     }
  167.     echo $IND . "Plugins OK.<br />\n";
  168. } else {
  169.     echo $IND . "Plugins are not enabled in config.<br />\n";
  170. }
  171. foreach($theme as $thm) {
  172.     if(!file_exists($thm['PATH'])) {
  173.         do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE);
  174.     } elseif(!is_readable($thm['PATH'])) {
  175.         do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE);
  176.     }
  177. }
  178.  
  179. echo $IND . "Themes OK.<br />\n";
  180.  
  181. if ( $squirrelmail_default_language != 'en_US' ) {
  182.     $loc_path = SM_PATH .'locale/'.$squirrelmail_default_language.'/LC_MESSAGES/squirrelmail.mo';
  183.     if( ! file_exists( $loc_path ) ) {
  184.         do_err('You have set <i>' . $squirrelmail_default_language . 
  185.             '</i> as your default language, but I cannot find this translation (should be '.
  186.             'in <tt>' . $loc_path . '</tt>). Please note that you have to download translations '.
  187.             'separately from the main SquirrelMail package.', FALSE);
  188.     } elseif ( ! is_readable( $loc_path ) ) {
  189.         do_err('You have set <i>' . $squirrelmail_default_language . 
  190.             '</i> as your default language, but I cannot read this translation (file '.
  191.             'in <tt>' . $loc_path . '</tt> unreadable).', FALSE);
  192.     } else {
  193.         echo $IND . "Default language OK.<br />\n";
  194.     }
  195. } else {
  196.     echo $IND . "Default language OK.<br />\n";
  197. }
  198.  
  199.  
  200. echo $IND . "Base URL detected as: <tt>" . htmlspecialchars($test_location) .
  201.     "</tt> (location base " . (empty($config_location_base) ? 'autodetected' : 'set to <tt>' .
  202.     htmlspecialchars($config_location_base)."</tt>") . ")<br />\n";
  203.  
  204. /* check outgoing mail */
  205.  
  206. if($use_smtp_tls || $use_imap_tls) {
  207.     if(!check_php_version(4,3,0)) {
  208.         do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
  209.     }
  210.     if(!extension_loaded('openssl')) {
  211.         do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
  212.     }
  213. }
  214.  
  215. echo "Checking outgoing mail service....<br />\n";
  216.  
  217. if($useSendmail) {
  218.     // is_executable also checks for existance, but we want to be as precise as possible with the errors
  219.         if(!file_exists($sendmail_path)) {
  220.         do_err("Location of sendmail program incorrect ($sendmail_path)!");
  221.     } 
  222.     if(!is_executable($sendmail_path)) {
  223.         do_err("I cannot execute the sendmail program ($sendmail_path)!");
  224.     }
  225.  
  226.     echo $IND . "sendmail OK<br />\n";
  227. } else {
  228.     $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort,
  229.                         $errorNumber, $errorString);
  230.     if(!$stream) {
  231.         do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
  232.             "Server error: ($errorNumber) ".htmlspecialchars($errorString));
  233.     }
  234.  
  235.     // check for SMTP code; should be 2xx to allow us access
  236.         $smtpline = fgets($stream, 1024);
  237.     if(((int) $smtpline{0}) > 3) {
  238.         do_err("Error connecting to SMTP server. Server error: ".
  239.         htmlspecialchars($smtpline));
  240.     }
  241.  
  242.     fputs($stream, 'QUIT');
  243.     fclose($stream);
  244.     echo $IND . 'SMTP server OK (<tt><small>'.
  245.         trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n";
  246.  
  247.     /* POP before SMTP */
  248.     if($pop_before_smtp) {
  249.         $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str);
  250.         if (!$stream) {
  251.             do_err("Error connecting to POP Server ($smtpServerAddress:110) "
  252.                   . $err_no . ' : ' . htmlspecialchars($err_str));
  253.         }
  254.  
  255.         $tmp = fgets($stream, 1024);
  256.         if (substr($tmp, 0, 3) != '+OK') {
  257.             do_err("Error connecting to POP Server ($smtpServerAddress:110)"
  258.                   . ' '.htmlspecialchars($tmp));
  259.         }
  260.         fputs($stream, 'QUIT');
  261.         fclose($stream);
  262.         echo $IND . "POP-before-SMTP OK.<br />\n";
  263.     }
  264. }
  265.  
  266. /**
  267.  * Check the IMAP server
  268.  */
  269. echo "Checking IMAP service....<br />\n";
  270.  
  271. /** Can we open a connection? */
  272. $stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort,
  273.                        $errorNumber, $errorString);
  274. if(!$stream) {
  275.     do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
  276.         "Server error: ($errorNumber) ".
  277.     htmlspecialchars($errorString));
  278. }
  279.  
  280. /** Is the first response 'OK'? */
  281. $imapline = fgets($stream, 1024);
  282. if(substr($imapline, 0,4) != '* OK') {
  283.    do_err('Error connecting to IMAP server. Server error: '.
  284.        htmlspecialchars($imapline));
  285. }
  286.  
  287. echo $IND . 'IMAP server ready (<tt><small>'.
  288.     htmlspecialchars(trim($imapline))."</small></tt>)<br />\n";
  289.  
  290. /** Check capabilities */
  291. fputs($stream, "A001 CAPABILITY\r\n");
  292. $capline = fgets($stream, 1024);
  293.  
  294. echo $IND . 'Capabilities: <tt>'.htmlspecialchars($capline)."</tt><br />\n";
  295.  
  296. if($imap_auth_mech == 'login' && stristr($capline, 'LOGINDISABLED') !== FALSE) {
  297.     do_err('Your server doesn\'t allow plaintext logins. '.
  298.         'Try enabling another authentication mechanism like CRAM-MD5, DIGEST-MD5 or TLS-encryption '.
  299.         'in the SquirrelMail configuration.', FALSE);
  300. }
  301.  
  302. if (stristr($capline, 'XMAGICTRASH') !== false) {
  303.     $magic_trash = 'It looks like IMAP_MOVE_EXPUNGE_TO_TRASH option is turned on '
  304.         .'in your Courier IMAP configuration. Courier does not provide tools that '
  305.         .'allow to detect folder used for Trash or commands are not documented. '
  306.         .'SquirrelMail can\'t detect special trash folder. SquirrelMail manages '
  307.         .'all message deletion or move operations internally and '
  308.         .'IMAP_MOVE_EXPUNGE_TO_TRASH option can cause errors in message and '
  309.         .'folder management operations. Please turn off IMAP_MOVE_EXPUNGE_TO_TRASH '
  310.         .'option in Courier imapd configuration.';
  311.     do_err($magic_trash,false);
  312. }
  313.  
  314. /* add warning about IMAP delivery */
  315. if (stristr($capline, 'XCOURIEROUTBOX') !== false) {
  316.     $courier_outbox = 'OUTBOX setting is enabled in your Courier imapd '
  317.         .'configuration. SquirrelMail uses standard SMTP protocol or sendmail '
  318.         .'binary to send emails. Courier IMAP delivery method is not supported'
  319.         .' and can create duplicate email messages.';
  320.     do_err($courier_outbox,false);
  321. }
  322.  
  323. /** OK, close connection */
  324. fputs($stream, "A002 LOGOUT\r\n");
  325. fclose($stream);
  326.  
  327. echo "Checking internationalization (i18n) settings...<br />\n";
  328. echo "$IND gettext - ";
  329. if (function_exists('gettext')) {
  330.     echo "Gettext functions are available. You must have appropriate system locales compiled.<br />\n";
  331. } else {
  332.     echo "Gettext functions are unavailable. SquirrelMail will use slower internal gettext functions.<br />\n";
  333. }
  334. echo "$IND mbstring - ";
  335. if (function_exists('mb_detect_encoding')) {
  336.     echo "Mbstring functions are available.<br />\n";
  337. } else {
  338.     echo "Mbstring functions are unavailable. Japanese translation won't work.<br />\n";
  339. }
  340. echo "$IND recode - ";
  341. if (function_exists('recode')) {
  342.     echo "Recode functions are available.<br />\n";
  343. } elseif (isset($use_php_recode) && $use_php_recode) {
  344.     echo "Recode functions are unavailable.<br />\n";
  345.     do_err('Your configuration requires recode support, but recode support is missing.');
  346. } else {
  347.     echo "Recode functions are unavailable.<br />\n";
  348. }
  349. echo "$IND iconv - ";
  350. if (function_exists('iconv')) {
  351.     echo "Iconv functions are available.<br />\n";
  352. } elseif (isset($use_php_iconv) && $use_php_iconv) {
  353.     echo "Iconv functions are unavailable.<br />\n";
  354.     do_err('Your configuration requires iconv support, but iconv support is missing.');
  355. } else {
  356.     echo "Iconv functions are unavailable.<br />\n";
  357. }
  358. // same test as in include/validate.php
  359. echo "$IND timezone - ";
  360. if ( (!ini_get('safe_mode')) ||
  361.     !strcmp(ini_get('safe_mode_allowed_env_vars'),'') ||
  362.     preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) {
  363.         echo "Webmail users can change their time zone settings.<br />\n";
  364. } else {
  365.     echo "Webmail users can't change their time zone settings.<br />\n";
  366. }
  367.  
  368.  
  369. // Pear DB tests
  370. echo "Checking database functions...<br />\n";
  371. if(!empty($addrbook_dsn) || !empty($prefs_dsn) || !empty($addrbook_global_dsn)) {
  372.     @include_once('DB.php');
  373.     if (class_exists('DB')) {
  374.         echo "$IND PHP Pear DB support is present.<br />\n";
  375.         $db_functions=array(
  376.             'dbase' => 'dbase_open', 
  377.             'fbsql' => 'fbsql_connect', 
  378.             'interbase' => 'ibase_connect', 
  379.             'informix' => 'ifx_connect',
  380.             'msql' => 'msql_connect',
  381.             'mssql' => 'mssql_connect',
  382.             'mysql' => 'mysql_connect',
  383.             'mysqli' => 'mysqli_connect',
  384.             'oci8' => 'ocilogon',
  385.             'odbc' => 'odbc_connect',
  386.             'pgsql' => 'pg_connect',
  387.             'sqlite' => 'sqlite_open',
  388.             'sybase' => 'sybase_connect'
  389.             );
  390.  
  391.         $dsns = array();
  392.         if($prefs_dsn) {
  393.             $dsns['preferences'] = $prefs_dsn;
  394.         }
  395.         if($addrbook_dsn) {
  396.             $dsns['addressbook'] = $addrbook_dsn;
  397.         }
  398.         if($addrbook_global_dsn) {
  399.             $dsns['global addressbook'] = $addrbook_global_dsn;
  400.         }
  401.  
  402.         foreach($dsns as $type => $dsn) {
  403.             $aDsn = explode(':', $dsn);
  404.             $dbtype = array_shift($aDsn);
  405.             if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) {
  406.                 echo "$IND$dbtype database support present.<br />\n";
  407.  
  408.                 // now, test this interface:
  409.  
  410.                 
  411.                 $dbh = DB::connect($dsn, true);
  412.                 if (DB::isError($dbh)) {
  413.                     do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) .
  414.                         ' in ' .$type .' DSN.');
  415.                 }
  416.                 $dbh->disconnect();
  417.                 echo "$IND$type database connect successful.<br />\n";
  418.  
  419.             } else {
  420.                 do_err($dbtype.' database support not present!');
  421.             }
  422.         }
  423.     } else {
  424.         do_err('Required PHP PEAR DB support is not available. Is PEAR installed and is the
  425.             include path set correctly to find <tt>DB.php</tt>? The include path is now:
  426.             "<tt>' . ini_get('include_path') . '</tt>".');
  427.     }
  428. } else {
  429.     echo $IND."not using database functionality.<br />\n";
  430. }
  431. ?>
  432.  
  433. <p>Congratulations, your SquirrelMail setup looks fine to me!</p>
  434.  
  435. <p><a href="login.php">Login now</a></p>
  436.  
  437. </body>
  438. </html>
  439. <?php
  440. // vim: et ts=4
  441. ?>

Documentation generated on Sat, 07 Oct 2006 16:30:21 +0300 by phpDocumentor 1.3.0RC6