| 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><table>\n<tr><td>SquirrelMail version:</td><td><b>" . $version . "</b></td></tr>\n" . |
| 74 | '<tr><td>Config file version:</td><td><b>' . $config_version . "</b></td></tr>\n" . |
| 75 | '<tr><td>Config file last modified:</td><td><b>' . |
| 76 | date ('d F Y H:i:s', filemtime(SM_PATH . 'config/config.php')) . |
| 77 | "</b></td></tr>\n</table>\n</p>\n\n"; |
| 78 | |
| 79 | echo "Checking PHP configuration...<br />\n"; |
| 80 | |
| 81 | if(!check_php_version(4,1,0)) { |
| 82 | do_err('Insufficient PHP version: '. PHP_VERSION . '! Minimum required: 4.1.0'); |
| 83 | } |
| 84 | |
| 85 | echo $IND . 'PHP version ' . PHP_VERSION . " OK.<br />\n"; |
| 86 | |
| 87 | $php_exts = array('session','pcre'); |
| 88 | $diff = array_diff($php_exts, get_loaded_extensions()); |
| 89 | if(count($diff)) { |
| 90 | do_err('Required PHP extensions missing: '.implode(', ',$diff) ); |
| 91 | } |
| 92 | |
| 93 | echo $IND . "PHP extensions OK.<br />\n"; |
| 94 | |
| 95 | |
| 96 | /* checking paths */ |
| 97 | |
| 98 | echo "Checking paths...<br />\n"; |
| 99 | |
| 100 | if(!file_exists($data_dir)) { |
| 101 | do_err("Data dir ($data_dir) does not exist!"); |
| 102 | } |
| 103 | if(!is_dir($data_dir)) { |
| 104 | do_err("Data dir ($data_dir) is not a directory!"); |
| 105 | } |
| 106 | if(!is_readable($data_dir)) { |
| 107 | do_err("I cannot read from data dir ($data_dir)!"); |
| 108 | } |
| 109 | if(!is_writable($data_dir)) { |
| 110 | do_err("I cannot write to data dir ($data_dir)!"); |
| 111 | } |
| 112 | |
| 113 | // todo_ornot: actually write something and read it back. |
| 114 | echo $IND . "Data dir OK.<br />\n"; |
| 115 | |
| 116 | |
| 117 | if($data_dir == $attachment_dir) { |
| 118 | echo $IND . "Attachment dir is the same as data dir.<br />\n"; |
| 119 | } else { |
| 120 | if(!file_exists($attachment_dir)) { |
| 121 | do_err("Attachment dir ($attachment_dir) does not exist!"); |
| 122 | } |
| 123 | if (!is_dir($attachment_dir)) { |
| 124 | do_err("Attachment dir ($attachment_dir) is not a directory!"); |
| 125 | } |
| 126 | if (!is_writable($attachment_dir)) { |
| 127 | do_err("I cannot write to attachment dir ($attachment_dir)!"); |
| 128 | } |
| 129 | echo $IND . "Attachment dir OK.<br />\n"; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | /* check plugins and themes */ |
| 134 | if (isset($plugins[0])) { |
| 135 | foreach($plugins as $plugin) { |
| 136 | if(!file_exists(SM_PATH .'plugins/'.$plugin)) { |
| 137 | do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot find it.', FALSE); |
| 138 | } elseif (!is_readable(SM_PATH .'plugins/'.$plugin.'/setup.php')) { |
| 139 | do_err('You have enabled the <i>'.$plugin.'</i> plugin but I cannot read its setup.php file.', FALSE); |
| 140 | } |
| 141 | } |
| 142 | echo $IND . "Plugins OK.<br />\n"; |
| 143 | } else { |
| 144 | echo $IND . "Plugins are not enabled in config.<br />\n"; |
| 145 | } |
| 146 | foreach($theme as $thm) { |
| 147 | if(!file_exists($thm['PATH'])) { |
| 148 | do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot find it ('.$thm['PATH'].').', FALSE); |
| 149 | } elseif(!is_readable($thm['PATH'])) { |
| 150 | do_err('You have enabled the <i>'.$thm['NAME'].'</i> theme but I cannot read it ('.$thm['PATH'].').', FALSE); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | echo $IND . "Themes OK.<br />\n"; |
| 155 | |
| 156 | |
| 157 | /* check outgoing mail */ |
| 158 | |
| 159 | if($use_smtp_tls || $use_imap_tls) { |
| 160 | if(!check_php_version(4,3,0)) { |
| 161 | do_err('You need at least PHP 4.3.0 for SMTP/IMAP TLS!'); |
| 162 | } |
| 163 | if(!extension_loaded('openssl')) { |
| 164 | do_err('You need the openssl PHP extension to use SMTP/IMAP TLS!'); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | echo "Checking outgoing mail service....<br />\n"; |
| 169 | |
| 170 | if($useSendmail) { |
| 171 | // is_executable also checks for existance, but we want to be as precise as possible with the errors |
| 172 | if(!file_exists($sendmail_path)) { |
| 173 | do_err("Location of sendmail program incorrect ($sendmail_path)!"); |
| 174 | } |
| 175 | if(!is_executable($sendmail_path)) { |
| 176 | do_err("I cannot execute the sendmail program ($sendmail_path)!"); |
| 177 | } |
| 178 | |
| 179 | echo $IND . "sendmail OK<br />\n"; |
| 180 | } else { |
| 181 | $stream = fsockopen( ($use_smtp_tls?'tls://':'').$smtpServerAddress, $smtpPort, |
| 182 | $errorNumber, $errorString); |
| 183 | if(!$stream) { |
| 184 | do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".". |
| 185 | "Server error: ($errorNumber) ".htmlspecialchars($errorString)); |
| 186 | } |
| 187 | |
| 188 | // check for SMTP code; should be 2xx to allow us access |
| 189 | $smtpline = fgets($stream, 1024); |
| 190 | if(((int) $smtpline{0}) > 3) { |
| 191 | do_err("Error connecting to SMTP server. Server error: ". |
| 192 | htmlspecialchars($smtpline)); |
| 193 | } |
| 194 | |
| 195 | fputs($stream, 'QUIT'); |
| 196 | fclose($stream); |
| 197 | echo $IND . 'SMTP server OK (<tt><small>'. |
| 198 | trim(htmlspecialchars($smtpline))."</small></tt>)<br />\n"; |
| 199 | |
| 200 | /* POP before SMTP */ |
| 201 | if($pop_before_smtp) { |
| 202 | $stream = fsockopen($smtpServerAddress, 110, $err_no, $err_str); |
| 203 | if (!$stream) { |
| 204 | do_err("Error connecting to POP Server ($smtpServerAddress:110) " |
| 205 | . $err_no . ' : ' . htmlspecialchars($err_str)); |
| 206 | } |
| 207 | |
| 208 | $tmp = fgets($stream, 1024); |
| 209 | if (substr($tmp, 0, 3) != '+OK') { |
| 210 | do_err("Error connecting to POP Server ($smtpServerAddress:110)" |
| 211 | . ' '.htmlspecialchars($tmp)); |
| 212 | } |
| 213 | fputs($stream, 'QUIT'); |
| 214 | fclose($stream); |
| 215 | echo $IND . "POP-before-SMTP OK.<br />\n"; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | echo "Checking IMAP service....<br />\n"; |
| 220 | |
| 221 | $stream = fsockopen( ($use_imap_tls?'tls://':'').$imapServerAddress, $imapPort, |
| 222 | $errorNumber, $errorString); |
| 223 | if(!$stream) { |
| 224 | do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".". |
| 225 | "Server error: ($errorNumber) ". |
| 226 | htmlspecialchars($errorString)); |
| 227 | } |
| 228 | |
| 229 | $imapline = fgets($stream, 1024); |
| 230 | if(substr($imapline, 0,4) != '* OK') { |
| 231 | do_err('Error connecting to IMAP server. Server error: '. |
| 232 | htmlspecialchars($imapline)); |
| 233 | } |
| 234 | |
| 235 | fputs($stream, '001 LOGOUT'); |
| 236 | fclose($stream); |
| 237 | |
| 238 | echo $IND . 'IMAP server OK (<tt><small>'. |
| 239 | htmlspecialchars(trim($imapline))."</small></tt>)<br />\n"; |
| 240 | |
| 241 | echo "Checking internationalization (i18n) settings...<br />\n"; |
| 242 | echo "$IND gettext - "; |
| 243 | if (function_exists('gettext')) { |
| 244 | echo "Gettext functions are available. You must have appropriate system locales compiled.<br />\n"; |
| 245 | } else { |
| 246 | echo "Gettext functions are unavailable. SquirrelMail will use slower internal gettext functions.<br />\n"; |
| 247 | } |
| 248 | echo "$IND mbstring - "; |
| 249 | if (function_exists('mb_detect_encoding')) { |
| 250 | echo "Mbstring functions are available.<br />\n"; |
| 251 | } else { |
| 252 | echo "Mbstring functions are unavailable. Japanese translation won't work.<br />\n"; |
| 253 | } |
| 254 | echo "$IND recode - "; |
| 255 | if (function_exists('recode')) { |
| 256 | echo "Recode functions are available.<br />\n"; |
| 257 | } elseif ($use_php_recode) { |
| 258 | echo "Recode functions are unavailable.<br />\n"; |
| 259 | do_err('Your configuration requires recode support, but recode support is missing.'); |
| 260 | } else { |
| 261 | echo "Recode functions are unavailable.<br />\n"; |
| 262 | } |
| 263 | echo "$IND iconv - "; |
| 264 | if (function_exists('iconv')) { |
| 265 | echo "Iconv functions are available.<br />\n"; |
| 266 | } elseif ($use_php_iconv) { |
| 267 | echo "Iconv functions are unavailable.<br />\n"; |
| 268 | do_err('Your configuration requires iconv support, but iconv support is missing.'); |
| 269 | } else { |
| 270 | echo "Iconv functions are unavailable.<br />\n"; |
| 271 | } |
| 272 | // same test as in include/validate.php |
| 273 | echo "$IND timezone - "; |
| 274 | if ( (!ini_get('safe_mode')) || |
| 275 | !strcmp(ini_get('safe_mode_allowed_env_vars'),'') || |
| 276 | preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')) ) { |
| 277 | echo "Webmail users can change their time zone settings.<br />\n"; |
| 278 | } else { |
| 279 | echo "Webmail users can't change their time zone settings.<br />\n"; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | // Pear DB tests |
| 284 | echo "Checking database functions...<br />\n"; |
| 285 | if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) { |
| 286 | @include_once('DB.php'); |
| 287 | if (class_exists('DB')) { |
| 288 | echo "$IND PHP Pear DB support is present.<br />\n"; |
| 289 | $db_functions=array( |
| 290 | 'dbase' => 'dbase_open', |
| 291 | 'fbsql' => 'fbsql_connect', |
| 292 | 'interbase' => 'ibase_connect', |
| 293 | 'informix' => 'ifx_connect', |
| 294 | 'msql' => 'msql_connect', |
| 295 | 'mssql' => 'mssql_connect', |
| 296 | 'mysql' => 'mysql_connect', |
| 297 | 'mysqli' => 'mysqli_connect', |
| 298 | 'oci8' => 'ocilogon', |
| 299 | 'odbc' => 'odbc_connect', |
| 300 | 'pgsql' => 'pgsql_connect', |
| 301 | 'sqlite' => 'sqlite_open', |
| 302 | 'sybase' => 'sybase_connect' |
| 303 | ); |
| 304 | |
| 305 | $dsns = array(); |
| 306 | if($prefs_dsn) $dsns['preferences'] = $prefs_dsn; |
| 307 | if($addrbook_dsn) $dsns['addressbook'] = $addrbook_dsn; |
| 308 | if($addrbook_global_dsn) $dsns['global addressbook'] = $addrbook_global_dsn; |
| 309 | |
| 310 | foreach($dsns as $type => $dsn) { |
| 311 | $dbtype = array_shift(explode(':', $dsn)); |
| 312 | if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) { |
| 313 | echo "$IND$dbtype database support present.<br />\n"; |
| 314 | |
| 315 | // now, test this interface: |
| 316 | |
| 317 | $dbh = DB::connect($dsn, true); |
| 318 | if (DB::isError($dbh)) { |
| 319 | do_err('Database error: '. htmlspecialchars(DB::errorMessage($dbh)) . |
| 320 | ' in ' .$type .' DSN.'); |
| 321 | } |
| 322 | $dbh->disconnect(); |
| 323 | echo "$IND$type database connect successful.<br />\n"; |
| 324 | |
| 325 | } else { |
| 326 | do_err($db.' database support not present!'); |
| 327 | } |
| 328 | } |
| 329 | } else { |
| 330 | do_err('Required PHP PEAR DB support is not available. Is PEAR installed and is the |
| 331 | include path set correctly to find <tt>DB.php</tt>? The include path is now: |
| 332 | "<tt>' . ini_get('include_path') . '</tt>".'); |
| 333 | } |
| 334 | } else { |
| 335 | echo $IND."not using database functionality.<br />\n"; |
| 336 | } |
| 337 | |
| 338 | // LDAP DB tests |
| 339 | echo "Checking LDAP functions...<br />\n"; |
| 340 | if( empty($ldap_server) ) { |
| 341 | echo $IND."not using LDAP functionality.<br />\n"; |
| 342 | } else { |
| 343 | if ( !function_exists(ldap_connect) ) { |
| 344 | do_err('Required LDAP support is not available.'); |
| 345 | } else { |
| 346 | echo "$IND LDAP support present.<br />\n"; |
| 347 | foreach ( $ldap_server as $param ) { |
| 348 | |
| 349 | $linkid = ldap_connect($param['host'], (empty($param['port']) ? 389 : $param['port']) ); |
| 350 | |
| 351 | if ( $linkid ) { |
| 352 | echo "$IND LDAP connect to ".$param['host']." successful: ".$linkid."<br />\n"; |
| 353 | |
| 354 | if ( !empty($param['protocol']) && |
| 355 | !ldap_set_option($linkid, LDAP_OPT_PROTOCOL_VERSION, $param['protocol']) ) { |
| 356 | do_err('Unable to set LDAP protocol'); |
| 357 | } |
| 358 | |
| 359 | if ( empty($param['binddn']) ) { |
| 360 | $bind = ldap_bind($linkid); |
| 361 | } else { |
| 362 | $bind = ldap_bind($param['binddn'], $param['bindpw']); |
| 363 | } |
| 364 | |
| 365 | if ( $bind ) { |
| 366 | echo "$IND LDAP Bind Successful <br />"; |
| 367 | } else { |
| 368 | do_err('Unable to Bind to LDAP Server'); |
| 369 | } |
| 370 | |
| 371 | ldap_close($linkid); |
| 372 | } else { |
| 373 | do_err('Connection to LDAP failed'); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | ?> |
| 379 | |
| 380 | <p>Congratulations, your SquirrelMail setup looks fine to me!</p> |
| 381 | |
| 382 | <p><a href="login.php">Login now</a></p> |
| 383 | |
| 384 | </body> |
| 385 | </html> |
| 386 | <?php |
| 387 | // vim: et ts=4 |