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_extsget_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_dirdoes not exist!");
  129. if(!is_dir($data_dir)) {
  130.     do_err("Data dir ($data_diris not a directory!");
  131. // datadir should be executable - but no clean way to test on that
  132. if(!is_writable($data_dir)) {
  133.     do_err("I cannot write to data dir ($data_dir)!");
  134. }
  135.  
  136. // todo_ornot: actually write something and read it back.
  137. echo $IND "Data dir OK.<br />\n";
  138.  
  139.  
  140. if($data_dir == $attachment_dir{
  141.     echo $IND "Attachment dir is the same as data dir.<br />\n";
  142. else {
  143.     if(!file_exists($attachment_dir)) {
  144.         do_err("Attachment dir ($attachment_dirdoes not exist!");
  145.     
  146.     if (!is_dir($attachment_dir)) {
  147.         do_err("Attachment dir ($attachment_diris not a directory!");
  148.     
  149.     if (!is_writable($attachment_dir)) {
  150.         do_err("I cannot write to attachment dir ($attachment_dir)!");
  151.     }
  152.     echo $IND "Attachment dir OK.<br />\n";
  153. }
  154.  
  155.  
  156. /* check plugins and themes */
  157. if (isset($plugins[0])) {
  158.     foreach($plugins as $plugin{
  159.         if(!file_exists(SM_PATH .'plugins/'.$plugin)) {
  160.             do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.'FALSE);
  161.         elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) {
  162.             do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.'FALSE);
  163.         }
  164.     }
  165.     echo $IND "Plugins OK.<br />\n";
  166. else {
  167.     echo $IND "Plugins are not enabled in config.<br />\n";
  168. }
  169. foreach($theme as $thm{
  170.     if(!file_exists($thm['PATH'])) {
  171.         do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').'FALSE);
  172.     elseif(!is_readable($thm['PATH'])) {
  173.         do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').'FALSE);
  174.     }
  175. }
  176.  
  177. echo $IND "Themes OK.<br />\n";
  178.  
  179. if $squirrelmail_default_language != 'en_US' {
  180.     $loc_path SM_PATH .'locale/'.$squirrelmail_default_language.'/LC_MESSAGES/squirrelmail.mo';
  181.     iffile_exists$loc_path ) ) {
  182.         do_err('You have set <i>' $squirrelmail_default_language 
  183.             '</i> as your default language, but I cannot find this translation (should be '.
  184.             'in <tt>' $loc_path '</tt>). Please note that you have to download translations '.
  185.             'separately from the main SquirrelMail package.'FALSE);
  186.     elseif is_readable$loc_path ) ) {
  187.         do_err('You have set <i>' $squirrelmail_default_language 
  188.             '</i> as your default language, but I cannot read this translation (file '.
  189.             'in <tt>' $loc_path '</tt> unreadable).'FALSE);
  190.     else {
  191.         echo $IND "Default language OK.<br />\n";
  192.     }
  193. else {
  194.     echo $IND "Default language OK.<br />\n";
  195. }
  196.  
  197.  
  198. echo $IND "Base URL detected as: <tt>" htmlspecialchars($test_location.
  199.     "</tt> (location base " (empty($config_location_base'autodetected' 'set to <tt>' .
  200.     htmlspecialchars($config_location_base)."</tt>"")<br />\n";
  201.  
  202. /* check outgoing mail */
  203.  
  204. if($use_smtp_tls || $use_imap_tls{
  205.     if(!check_php_version(4,3,0)) {
  206.         do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!');
  207.     }
  208.     if(!extension_loaded('openssl')) {
  209.         do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!');
  210.     }
  211. }
  212.  
  213. echo "Checking outgoing mail service....<br />\n";
  214.  
  215. if($useSendmail{
  216.     // is_executable also checks for existance, but we want to be as precise as possible with the errors
  217.         if(!file_exists($sendmail_path)) {
  218.         do_err("Location of sendmail program incorrect ($sendmail_path)!");
  219.     
  220.     if(!is_executable($sendmail_path)) {
  221.         do_err("I cannot execute the sendmail program ($sendmail_path)!");
  222.     }
  223.  
  224.     echo $IND "sendmail OK<br />\n";
  225. else {
  226.     $stream fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress$smtpPort,
  227.                         $errorNumber$errorString);
  228.     if(!$stream{
  229.         do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".".
  230.             "Server error: ($errorNumber".htmlspecialchars($errorString));
  231.     }
  232.  
  233.     // check for SMTP code; should be 2xx to allow us access
  234.         $smtpline fgets($stream1024);
  235.     if(((int) $smtpline{0}3{
  236.         do_err("Error connecting to SMTP server. Server error: ".
  237.         htmlspecialchars($smtpline));
  238.     }
  239.  
  240.     fputs($stream'QUIT');
  241.     fclose($stream);
  242.     echo $IND 'SMTP server OK (<tt><small>'.
  243.         trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n";
  244.  
  245.     /* POP before SMTP */
  246.     if($pop_before_smtp{
  247.         $stream fsockopen($smtpServerAddress110$err_no$err_str);
  248.         if (!$stream{
  249.             do_err("Error connecting to POP Server ($smtpServerAddress:110) "
  250.                   . $err_no ' : ' htmlspecialchars($err_str));
  251.         }
  252.  
  253.         $tmp fgets($stream1024);
  254.         if (substr($tmp03!= '+OK'{
  255.             do_err("Error connecting to POP Server ($smtpServerAddress:110)"
  256.                   . ' '.htmlspecialchars($tmp));
  257.         }
  258.         fputs($stream'QUIT');
  259.         fclose($stream);
  260.         echo $IND "POP-before-SMTP OK.<br />\n";
  261.     }
  262. }
  263.  
  264. /**
  265.  * Check the IMAP server
  266.  */
  267. echo "Checking IMAP service....<br />\n";
  268.  
  269. /** Can we open a connection? */
  270. $stream fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress$imapPort,
  271.                        $errorNumber$errorString);
  272. if(!$stream{
  273.     do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".".
  274.         "Server error: ($errorNumber".
  275.     htmlspecialchars($errorString));
  276. }
  277.  
  278. /** Is the first response 'OK'? */
  279. $imapline fgets($stream1024);
  280. if(substr($imapline0,4!= '* OK'{
  281.    do_err('Error connecting to IMAP server. Server error: '.
  282.        htmlspecialchars($imapline));
  283. }
  284.  
  285. echo $IND 'IMAP server ready (<tt><small>'.
  286.     htmlspecialchars(trim($imapline))."</small></tt>)<br />\n";
  287.  
  288. /** Check capabilities */
  289. fputs($stream"A001 CAPABILITY\r\n");
  290. $capline fgets($stream1024);
  291.  
  292. echo $IND 'Capabilities: <tt>'.htmlspecialchars($capline)."</tt><br />\n";
  293.  
  294. if($imap_auth_mech == 'login' && stristr($capline'LOGINDISABLED'!== FALSE{
  295.     do_err('Your server doesn\'t allow plaintext logins. '.
  296.         'Try enabling another authentication mechanism like CRAM-MD5, DIGEST-MD5 or TLS-encryption '.
  297.         'in the SquirrelMail configuration.'FALSE);
  298. }
  299.  
  300. if (stristr($capline'XMAGICTRASH'!== false{
  301.     $magic_trash 'It looks like IMAP_MOVE_EXPUNGE_TO_TRASH option is turned on '
  302.         .'in your Courier IMAP configuration. Courier does not provide tools that '
  303.         .'allow to detect folder used for Trash or commands are not documented. '
  304.         .'SquirrelMail can\'t detect special trash folder. SquirrelMail manages '
  305.         .'all message deletion or move operations internally and '
  306.         .'IMAP_MOVE_EXPUNGE_TO_TRASH option can cause errors in message and '
  307.         .'folder management operations. Please turn off IMAP_MOVE_EXPUNGE_TO_TRASH '
  308.         .'option in Courier imapd configuration.';
  309.     do_err($magic_trash,false);
  310. }
  311.  
  312. /* add warning about IMAP delivery */
  313. if (stristr($capline'XCOURIEROUTBOX'!== false{
  314.     $courier_outbox 'OUTBOX setting is enabled in your Courier imapd '
  315.         .'configuration. SquirrelMail uses standard SMTP protocol or sendmail '
  316.         .'binary to send emails. Courier IMAP delivery method is not supported'
  317.         .' and can create duplicate email messages.';
  318.     do_err($courier_outbox,false);
  319. }
  320.  
  321. /** OK, close connection */
  322. fputs($stream"A002 LOGOUT\r\n");
  323. fclose($stream);
  324.  
  325. echo "Checking internationalization (i18n) settings...<br />\n";
  326. echo "$IND gettext - ";
  327. if (function_exists('gettext')) {
  328.     echo "Gettext functions are available. You must have appropriate system locales compiled.<br />\n";
  329. else {
  330.     echo "Gettext functions are unavailable. SquirrelMail will use slower internal gettext functions.<br />\n";
  331. }
  332. echo "$IND mbstring - ";
  333. if (function_exists('mb_detect_encoding')) {
  334.     echo "Mbstring functions are available.<br />\n";
  335. else {
  336.     echo "Mbstring functions are unavailable. Japanese translation won't work.<br />\n";
  337. }
  338. echo "$IND recode - ";
  339. if (function_exists('recode')) {
  340.     echo "Recode functions are available.<br />\n";
  341. elseif (isset($use_php_recode&& $use_php_recode{
  342.     echo "Recode functions are unavailable.<br />\n";
  343.     do_err('Your configuration requires recode support, but recode support is missing.');
  344. else {
  345.     echo "Recode functions are unavailable.<br />\n";
  346. }
  347. echo "$IND iconv - ";
  348. if (function_exists('iconv')) {
  349.     echo "Iconv functions are available.<br />\n";
  350. elseif (isset($use_php_iconv&& $use_php_iconv{
  351.     echo "Iconv functions are unavailable.<br />\n";
  352.     do_err('Your configuration requires iconv support, but iconv support is missing.');
  353. else {
  354.     echo "Iconv functions are unavailable.<br />\n";
  355. }
  356. // same test as in include/validate.php
  357. echo "$IND timezone - ";
  358. if ( (!ini_get('safe_mode')) ||
  359.     !strcmp(ini_get('safe_mode_allowed_env_vars'),''||
  360.     preg_match('/^([\w_]+,)*TZ/'ini_get('safe_mode_allowed_env_vars')) ) {
  361.         echo "Webmail users can change their time zone settings.<br />\n";
  362. else {
  363.     echo "Webmail users can't change their time zone settings.<br />\n";
  364. }
  365.  
  366.  
  367. // Pear DB tests
  368. echo "Checking database functions...<br />\n";
  369. if(!empty($addrbook_dsn|| !empty($prefs_dsn|| !empty($addrbook_global_dsn)) {
  370.     @include_once('DB.php');
  371.     if (class_exists('DB')) {
  372.         echo "$IND PHP Pear DB support is present.<br />\n";
  373.         $db_functions=array(
  374.             'dbase' => 'dbase_open'
  375.             'fbsql' => 'fbsql_connect'
  376.             'interbase' => 'ibase_connect'
  377.             'informix' => 'ifx_connect',
  378.             'msql' => 'msql_connect',
  379.             'mssql' => 'mssql_connect',
  380.             'mysql' => 'mysql_connect',
  381.             'mysqli' => 'mysqli_connect',
  382.             'oci8' => 'ocilogon',
  383.             'odbc' => 'odbc_connect',
  384.             'pgsql' => 'pg_connect',
  385.             'sqlite' => 'sqlite_open',
  386.             'sybase' => 'sybase_connect'
  387.             );
  388.  
  389.         $dsns array();
  390.         if($prefs_dsn{
  391.             $dsns['preferences'$prefs_dsn;
  392.         }
  393.         if($addrbook_dsn{
  394.             $dsns['addressbook'$addrbook_dsn;
  395.         }
  396.         if($addrbook_global_dsn{
  397.             $dsns['global addressbook'$addrbook_global_dsn;
  398.         }
  399.  
  400.         foreach($dsns as $type => $dsn{
  401.             $aDsn explode(':'$dsn);
  402.             $dbtype array_shift($aDsn);
  403.             if(isset($db_functions[$dbtype]&& function_exists($db_functions[$dbtype])) {
  404.                 echo "$IND$dbtype database support present.<br />\n";
  405.  
  406.                 // now, test this interface:
  407.  
  408.                 
  409.                 $dbh DB::connect($dsntrue);
  410.                 if (DB::isError($dbh)) {
  411.                     do_err('Database error: 'htmlspecialchars(DB::errorMessage($dbh)) .
  412.                         ' in ' .$type .' DSN.');
  413.                 }
  414.                 $dbh->disconnect();
  415.                 echo "$IND$type database connect successful.<br />\n";
  416.  
  417.             else {
  418.                 do_err($dbtype.' database support not present!');
  419.             }
  420.         }
  421.     else {
  422.         do_err('Required PHP PEAR DB support is not available. Is PEAR installed and is the
  423.             include path set correctly to find <tt>DB.php</tt>? The include path is now:
  424.             "<tt>' ini_get('include_path''</tt>".');
  425.     }
  426. else {
  427.     echo $IND."not using database functionality.<br />\n";
  428. }
  429. ?>
  430.  
  431. <p>Congratulations, your SquirrelMail setup looks fine to me!</p>
  432.  
  433. <p><a href="login.php">Login now</a></p>
  434.  
  435. </body>
  436. </html>
  437. <?php
  438. // vim: et ts=4
  439. ?>

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