| 1 | <?php |
| 2 | /** |
| 3 | * SquirrelMail configtest script |
| 4 | * |
| 5 | * Copyright (c) 2003-2004 The SquirrelMail Project Team |
| 6 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 7 | * |
| 8 | * @version $Id$ |
| 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 | function do_err($str, $exit = TRUE) { |
| 19 | global $IND; |
| 20 | echo '<p>'.$IND.'<font color="red"><b>ERROR:</b></font> ' .$str. "</p>\n"; |
| 21 | if($exit) { |
| 22 | echo '</body></html>'; |
| 23 | exit; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | $IND = str_repeat(' ',4); |
| 28 | |
| 29 | ob_implicit_flush(); |
| 30 | /** @ignore */ |
| 31 | define('SM_PATH', '../'); |
| 32 | |
| 33 | /* |
| 34 | * Load config before output begins. functions/strings.php depends on |
| 35 | * functions/globals.php. functions/global.php needs to be run before |
| 36 | * any html output starts. If config.php is missing, error will be displayed |
| 37 | * later. |
| 38 | */ |
| 39 | if (file_exists(SM_PATH . 'config/config.php')) { |
| 40 | include(SM_PATH . 'config/config.php'); |
| 41 | include(SM_PATH . 'functions/strings.php'); |
| 42 | } |
| 43 | ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 44 | <html> |
| 45 | <head> |
| 46 | <title>SquirrelMail configtest</title> |
| 47 | </head> |
| 48 | <body> |
| 49 | <h1>SquirrelMail configtest</h1> |
| 50 | |
| 51 | <p>This script will try to check some aspects of your SquirrelMail configuration |
| 52 | and point you to errors whereever it can find them. You need to go run <tt>conf.pl</tt> |
| 53 | in the <tt>config/</tt> directory first before you run this script.</p> |
| 54 | |
| 55 | <?php |
| 56 | |
| 57 | |
| 58 | $included = array_map('basename', get_included_files() ); |
| 59 | if(!in_array('config.php', $included)) { |
| 60 | if(!file_exists(SM_PATH . 'config/config.php')) { |
| 61 | do_err('Config file '.SM_PATH . 'config/config.php does not exist!<br />'. |
| 62 | 'You need to run <tt>conf.pl</tt> first.'); |
| 63 | } |
| 64 | do_err('Could not read '.SM_PATH.'config/config.php! Check file permissions.'); |
| 65 | } |
| 66 | if(!in_array('strings.php', $included)) { |
| 67 | do_err('Could not include '.SM_PATH.'functions/strings.php!<br />'. |
| 68 | 'Check permissions on that file.'); |
| 69 | } |
| 70 | |
| 71 | /* checking PHP specs */ |
| 72 | |
| 73 | echo '<p>SquirrelMail version: '.$version.'<br />'. |
| 74 | 'Config file version: '.$config_version . '<br />'. |
| 75 | 'Config file last modified: '.date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')).'</p>'; |
| 76 | |
| 77 | echo "Checking PHP configuration...<br />\n"; |
| 78 | |
| 79 | if(!check_php_version(4,1,0)) { |
| 80 | do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0'); |
| 81 | } |
| 82 | |
| 83 | echo $IND . 'PHP version '.PHP_VERSION.' OK.<br />'; |
| 84 | |
| 85 | $php_exts = array('session','pcre'); |
| 86 | $diff = array_diff($php_exts, get_loaded_extensions()); |
| 87 | if(count($diff)) { |
| 88 | do_err('Required PHP extensions missing: '.implode(', ',$diff) ); |
| 89 | } |
| 90 | |
| 91 | echo $IND . 'PHP extensions OK.<br />'; |
| 92 | |
| 93 | |
| 94 | /* checking paths */ |
| 95 | |
| 96 | echo "Checking paths...<br />\n"; |
| 97 | |
| 98 | if(!file_exists($data_dir)) { |
| 99 | do_err("Data dir ($data_dir) does not exist!"); |
| 100 | } |
| 101 | if(!is_dir($data_dir)) { |
| 102 | do_err("Data dir ($data_dir) is not a directory!"); |
| 103 | } |
| 104 | if(!is_readable($data_dir)) { |
| 105 | do_err("I cannot read from data dir ($data_dir)!"); |
| 106 | } |
| 107 | if(!is_writable($data_dir)) { |
| 108 | do_err("I cannot write to data dir ($data_dir)!"); |
| 109 | } |
| 110 | |
| 111 | // todo_ornot: actually write something and read it back. |
| 112 | echo $IND . "Data dir OK.<br />\n"; |
| 113 | |
| 114 | |
| 115 | if($data_dir == $attachment_dir) { |
| 116 | echo $IND . "Attachment dir is the same as data dir.<br />\n"; |
| 117 | } else { |
| 118 | if(!file_exists($attachment_dir)) { |
| 119 | do_err("Attachment dir ($attachment_dir) does not exist!"); |
| 120 | } |
| 121 | if (!is_dir($attachment_dir)) { |
| 122 | do_err("Attachment dir ($attachment_dir) is not a directory!"); |
| 123 | } |
| 124 | if (!is_writable($attachment_dir)) { |
| 125 | do_err("I cannot write to attachment dir ($attachment_dir)!"); |
| 126 | } |
| 127 | echo $IND . "Attachment dir OK.<br />\n"; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | /* check plugins and themes */ |
| 132 | if (isset($plugins[0])) { |
| 133 | foreach($plugins as $plugin) { |
| 134 | if(!file_exists(SM_PATH .'plugins/'.$plugin)) { |
| 135 | do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE); |
| 136 | } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) { |
| 137 | do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE); |
| 138 | } |
| 139 | } |
| 140 | echo $IND . "Plugins OK.<br />\n"; |
| 141 | } else { |
| 142 | echo $IND . "Plugins are not enabled in config.<br />\n"; |
| 143 | } |
| 144 | foreach($theme as $thm) { |
| 145 | if(!file_exists($thm['PATH'])) { |
| 146 | do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE); |
| 147 | } elseif(!is_readable($thm['PATH'])) { |
| 148 | do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | echo $IND . "Themes OK.<br />\n"; |
| 153 | |
| 154 | |
| 155 | /* check outgoing mail */ |
| 156 | |
| 157 | if($use_smtp_tls || $use_imap_tls) { |
| 158 | if(!check_php_version(4,3,0)) { |
| 159 | do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!'); |
| 160 | } |
| 161 | if(!extension_loaded('openssl')) { |
| 162 | do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!'); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | echo "Checking outgoing mail service....<br />\n"; |
| 167 | |
| 168 | if($useSendmail) { |
| 169 | // is_executable also checks for existance, but we want to be as precise as possible with the errors |
| 170 | if(!file_exists($sendmail_path)) { |
| 171 | do_err("Location of sendmail program incorrect ($sendmail_path)!"); |
| 172 | } |
| 173 | if(!is_executable($sendmail_path)) { |
| 174 | do_err("I cannot execute the sendmail program ($sendmail_path)!"); |
| 175 | } |
| 176 | |
| 177 | echo $IND . "sendmail OK<br />\n"; |
| 178 | } else { |
| 179 | $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort, |
| 180 | $errorNumber, $errorString); |
| 181 | if(!$stream) { |
| 182 | do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".". |
| 183 | "Server error: ($errorNumber) ".htmlspecialchars($errorString)); |
| 184 | } |
| 185 | |
| 186 | // check for SMTP code; should be 2xx to allow us access |
| 187 | $smtpline = fgets($stream, 1024); |
| 188 | if(((int) $smtpline{0}) > 3) { |
| 189 | do_err("Error connecting to SMTP server. Server error: ". |
| 190 | htmlspecialchars($smtpline)); |
| 191 | } |
| 192 | |
| 193 | fputs($stream, 'QUIT'); |
| 194 | fclose($stream); |
| 195 | echo $IND . 'SMTP server OK (<tt><small>'. |
| 196 | trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n"; |
| 197 | |
| 198 | /* POP before SMTP */ |
| 199 | if($pop_before_smtp) { |
| 200 | $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str); |
| 201 | if (!$stream) { |
| 202 | do_err("Error connecting to POP Server ($smtpServerAddress:110) " |
| 203 | . $err_no . ' : ' . htmlspecialchars($err_str)); |
| 204 | } |
| 205 | |
| 206 | $tmp = fgets($stream, 1024); |
| 207 | if (substr($tmp, 0, 3) != '+OK') { |
| 208 | do_err("Error connecting to POP Server ($smtpServerAddress:110)" |
| 209 | . ' '.htmlspecialchars($tmp)); |
| 210 | } |
| 211 | fputs($stream, 'QUIT'); |
| 212 | fclose($stream); |
| 213 | echo $IND . "POP-before-SMTP OK.<br />\n"; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | echo "Checking IMAP service....<br />\n"; |
| 218 | |
| 219 | $stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort, |
| 220 | $errorNumber, $errorString); |
| 221 | if(!$stream) { |
| 222 | do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".". |
| 223 | "Server error: ($errorNumber) ". |
| 224 | htmlspecialchars($errorString)); |
| 225 | } |
| 226 | |
| 227 | $imapline = fgets($stream, 1024); |
| 228 | if(substr($imapline, 0,4) != '* OK') { |
| 229 | do_err('Error connecting to IMAP server. Server error: '. |
| 230 | htmlspecialchars($imapline)); |
| 231 | } |
| 232 | |
| 233 | fputs($stream, '001 LOGOUT'); |
| 234 | fclose($stream); |
| 235 | |
| 236 | echo $IND . 'IMAP server OK (<tt><small>'. |
| 237 | htmlspecialchars(trim($imapline))."</small></tt>)<br />\n"; |
| 238 | |
| 239 | echo "Checking internationalization (i18n) settings:<br />\n"; |
| 240 | echo "$IND gettext - "; |
| 241 | if (function_exists('gettext')) { |
| 242 | echo "Gettext functions are available. You must have appropriate system locales compiled.<br />\n"; |
| 243 | } else { |
| 244 | echo "Gettext functions are unavailable. SquirrelMail will use slower internal gettext functions.<br />\n"; |
| 245 | } |
| 246 | echo "$IND mbstring - "; |
| 247 | if (function_exists('mb_detect_encoding')) { |
| 248 | echo "Mbstring functions are available.<br />\n"; |
| 249 | } else { |
| 250 | echo "Mbstring functions are unavailable. Japanese translation won't work.<br />\n"; |
| 251 | } |
| 252 | echo "$IND recode - "; |
| 253 | if (function_exists('recode')) { |
| 254 | echo "Recode functions are available.<br />\n"; |
| 255 | } elseif ($use_php_recode) { |
| 256 | echo "Recode functions are unavailable.<br />\n"; |
| 257 | do_err('Your configuration requires recode support, but recode support is missing.'); |
| 258 | } else { |
| 259 | echo "Recode functions are unavailable.<br />\n"; |
| 260 | } |
| 261 | echo "$IND iconv - "; |
| 262 | if (function_exists('iconv')) { |
| 263 | echo "Iconv functions are available.<br />\n"; |
| 264 | } elseif ($use_php_iconv) { |
| 265 | echo "Iconv functions are unavailable.<br />\n"; |
| 266 | do_err('Your configuration requires iconv support, but iconv support is missing.'); |
| 267 | } else { |
| 268 | echo "Iconv functions are unavailable.<br />\n"; |
| 269 | } |
| 270 | // same test as in include/validate.php |
| 271 | echo "$IND timezone - "; |
| 272 | if ( (!ini_get('safe_mode')) || |
| 273 | !strcmp(ini_get('safe_mode_allowed_env_vars'),'') || |
| 274 | preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) { |
| 275 | echo "Webmail users can change their time zone settings.<br />\n"; |
| 276 | } else { |
| 277 | echo "Webmail users can't change their time zone settings.<br />\n"; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | // Pear DB tests |
| 282 | echo "Checking database functions...<br />\n"; |
| 283 | if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) { |
| 284 | @include_once('DB.php'); |
| 285 | if (class_exists('DB')) { |
| 286 | echo "$IND PHP Pear DB support is present.<br />\n"; |
| 287 | $db_functions=array( |
| 288 | 'dbase' => 'dbase_open', |
| 289 | 'fbsql' => 'fbsql_connect', |
| 290 | 'interbase' => 'ibase_connect', |
| 291 | 'informix' => 'ifx_connect', |
| 292 | 'msql' => 'msql_connect', |
| 293 | 'mssql' => 'mssql_connect', |
| 294 | 'mysql' => 'mysql_connect', |
| 295 | 'mysqli' => 'mysqli_connect', |
| 296 | 'oci8' => 'ocilogon', |
| 297 | 'odbc' => 'odbc_connect', |
| 298 | 'pgsql' => 'pgsql_connect', |
| 299 | 'sqlite' => 'sqlite_open', |
| 300 | 'sybase' => 'sybase_connect' |
| 301 | ); |
| 302 | |
| 303 | $dsns = array(); |
| 304 | if($prefs_dsn) $dsns['preferences'] = $prefs_dsn; |
| 305 | if($addrbook_dsn) $dsns['addressbook'] = $addrbook_dsn; |
| 306 | if($addrbook_global_dsn) $dsns['global addressbook'] = $addrbook_global_dsn; |
| 307 | |
| 308 | foreach($dsns as $type => $dsn) { |
| 309 | $dbtype = array_shift(explode(':', $dsn)); |
| 310 | if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) { |
| 311 | echo "$IND$dbtype database support present.<br />\n"; |
| 312 | |
| 313 | // now, test this interface: |
| 314 | |
| 315 | $dbh = DB::connect($dsn, true); |
| 316 | if (DB::isError($dbh)) { |
| 317 | do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) . |
| 318 | ' in ' .$type .' DSN.'); |
| 319 | } |
| 320 | $dbh->disconnect(); |
| 321 | echo "$IND$type database connect successful.<br />\n"; |
| 322 | |
| 323 | } else { |
| 324 | do_err($db.' database support not present!'); |
| 325 | } |
| 326 | } |
| 327 | } else { |
| 328 | do_err('Required PHP Pear DB support is not available.');; |
| 329 | } |
| 330 | } else { |
| 331 | echo $IND."not using database functionality.<br />\n"; |
| 332 | } |
| 333 | ?> |
| 334 | |
| 335 | <p>Congratulations, your SquirrelMail setup looks fine to me!</p> |
| 336 | |
| 337 | <p><a href="login.php">Login now</a></p> |
| 338 | |
| 339 | </body> |
| 340 | </html> |