X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fconfigtest.php;h=f3155b8f1673c663b8de7ecc0796cb435188eb89;hb=5facc3fca35506c6d0cbcf0233b63d275c6ee2a6;hp=ede53d588fd7231911d5f3ab611a979ffaf4d324;hpb=3047e291f2982efe9501ec790faafd3da843d22d;p=squirrelmail.git diff --git a/src/configtest.php b/src/configtest.php index ede53d58..f3155b8f 100644 --- a/src/configtest.php +++ b/src/configtest.php @@ -3,7 +3,7 @@ /** * SquirrelMail configtest script * - * @copyright 2003-2012 The SquirrelMail Project Team + * @copyright 2003-2017 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail @@ -120,6 +120,9 @@ if (file_exists(SM_PATH . 'config/config_local.php')) { require(SM_PATH . 'config/config_local.php'); } +sqGetGlobalVar('REMOTE_ADDR',$client_ip,SQ_SERVER); +sqGetGlobalVar('SERVER_ADDR',$server_ip,SQ_SERVER); + /** * Include Compatibility plugin if available. */ @@ -175,8 +178,6 @@ if(!in_array('strings.php', $included)) { /* Block remote use of script */ if (! $allow_remote_configtest) { - sqGetGlobalVar('REMOTE_ADDR',$client_ip,SQ_SERVER); - sqGetGlobalVar('SERVER_ADDR',$server_ip,SQ_SERVER); if ((! isset($client_ip) || $client_ip!='127.0.0.1') && (! isset($client_ip) || ! isset($server_ip) || $client_ip!=$server_ip)) { @@ -631,7 +632,10 @@ if($useSendmail) { echo $IND . "sendmail OK
\n"; } else { - $stream = fsockopen( ($use_smtp_tls==1?'tls://':'').$smtpServerAddress, $smtpPort, + // NB: Using "ssl://" ensures the highest possible TLS version + // will be negotiated with the server (whereas "tls://" only + // uses TLS version 1.0) + $stream = fsockopen( ($use_smtp_tls==1?'ssl://':'').$smtpServerAddress, $smtpPort, $errorNumber, $errorString); if(!$stream) { do_err("Error connecting to SMTP server \"$smtpServerAddress:$smtpPort\".". @@ -735,7 +739,10 @@ if($useSendmail) { echo "Checking IMAP service....
\n"; /** Can we open a connection? */ -$stream = fsockopen( ($use_imap_tls==1?'tls://':'').$imapServerAddress, $imapPort, +// NB: Using "ssl://" ensures the highest possible TLS version +// will be negotiated with the server (whereas "tls://" only +// uses TLS version 1.0) +$stream = fsockopen( ($use_imap_tls==1?'ssl://':'').$imapServerAddress, $imapPort, $errorNumber, $errorString); if(!$stream) { do_err("Error connecting to IMAP server \"$imapServerAddress:$imapPort\".". @@ -924,70 +931,113 @@ if (isset($_ENV['TZ'])) { } echo ".
\n"; -// Pear DB tests +// Database tests echo "Checking database functions...
\n"; if($addrbook_dsn || $prefs_dsn || $addrbook_global_dsn) { - @include_once('DB.php'); - if (class_exists('DB')) { - echo "$IND PHP Pear DB support is present.
\n"; - $db_functions=array( - 'dbase' => 'dbase_open', - 'fbsql' => 'fbsql_connect', - 'interbase' => 'ibase_connect', - 'informix' => 'ifx_connect', - 'msql' => 'msql_connect', - 'mssql' => 'mssql_connect', - 'mysql' => 'mysql_connect', - 'mysqli' => 'mysqli_connect', - 'oci8' => 'ocilogon', - 'odbc' => 'odbc_connect', - 'pgsql' => 'pg_connect', - 'sqlite' => 'sqlite_open', - 'sybase' => 'sybase_connect' - ); - - $dsns = array(); - if($prefs_dsn) { - $dsns['preferences'] = $prefs_dsn; - } - if($addrbook_dsn) { - $dsns['addressbook'] = $addrbook_dsn; - } - if($addrbook_global_dsn) { - $dsns['global addressbook'] = $addrbook_global_dsn; - } - - foreach($dsns as $type => $dsn) { - $aDsn = explode(':', $dsn); - $dbtype = array_shift($aDsn); + $dsns = array(); + if($prefs_dsn) { + $dsns['preferences'] = $prefs_dsn; + } + if($addrbook_dsn) { + $dsns['addressbook'] = $addrbook_dsn; + } + if($addrbook_global_dsn) { + $dsns['global addressbook'] = $addrbook_global_dsn; + } - if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) { - echo "$IND$dbtype database support present.
\n"; - } elseif(!(bool)ini_get('enable_dl') || (bool)ini_get('safe_mode')) { - do_err($dbtype.' database support not present!'); - } else { - // Non-fatal error - do_err($dbtype.' database support not present or not configured! - Trying to dynamically load '.$dbtype.' extension. - Please note that it is advisable to not rely on dynamic loading of extensions.', FALSE); - } + global $disable_pdo, $use_pdo; + if (empty($disable_pdo) && class_exists('PDO')) + $use_pdo = TRUE; + else + $use_pdo = FALSE; + if ($use_pdo) { - // now, test this interface: + // test connecting to each DSN + foreach($dsns as $type => $dsn) { - $dbh = DB::connect($dsn, true); - if (DB::isError($dbh)) { - do_err('Database error: '. sm_encode_html_special_chars(DB::errorMessage($dbh)) . + // parse and convert DSN to PDO style + // $matches will contain: + // 1: database type + // 2: username + // 3: password + // 4: hostname + // 5: database name +//TODO: add support for unix_socket and charset + if (!preg_match('|^(.+)://(.+):(.+)@(.+)/(.+)$|i', $dsn, $matches)) { + return $this->set_error(_("Could not parse prefs DSN")); + do_err('DSN parse error in ' .$type .' DSN.'); + } + if (preg_match('|^(.+):(\d+)$|', $matches[4], $host_port_matches)) { + $matches[4] = $host_port_matches[1]; + $matches[6] = $host_port_matches[2]; + } else + $matches[6] = NULL; + $pdo_prefs_dsn = $matches[1] . ':host=' . $matches[4] . (!empty($matches[6]) ? ';port=' . $matches[6] : '') . ';dbname=' . $matches[5]; + try { + $dbh = new PDO($pdo_prefs_dsn, $matches[2], $matches[3]); + } catch (Exception $e) { + do_err('Database error: '. sm_encode_html_special_chars($e->getMessage()) . ' in ' .$type .' DSN.'); } - $dbh->disconnect(); echo "$IND$type database connect successful.
\n"; } + } else { - $db_error='Required PHP PEAR DB support is not available.' - .' Is PEAR installed and is the include path set correctly to find DB.php?' - .' The include path is now: "' . ini_get('include_path') . '".'; - do_err($db_error); + @include_once('DB.php'); + if (class_exists('DB')) { + echo "$IND PHP Pear DB support is present, however it is deprecated and PHP PDO is recommended.
\n" + .(!empty($disable_pdo) ? "$IND You have set \$disable_pdo - if you experience errors below, try removing that.
\n" : ''); + $db_functions=array( + 'dbase' => 'dbase_open', + 'fbsql' => 'fbsql_connect', + 'interbase' => 'ibase_connect', + 'informix' => 'ifx_connect', + 'msql' => 'msql_connect', + 'mssql' => 'mssql_connect', + 'mysql' => 'mysql_connect', + 'mysqli' => 'mysqli_connect', + 'oci8' => 'ocilogon', + 'odbc' => 'odbc_connect', + 'pgsql' => 'pg_connect', + 'sqlite' => 'sqlite_open', + 'sybase' => 'sybase_connect' + ); + + foreach($dsns as $type => $dsn) { + $aDsn = explode(':', $dsn); + $dbtype = array_shift($aDsn); + + if(isset($db_functions[$dbtype]) && function_exists($db_functions[$dbtype])) { + echo "$IND$dbtype database support present.
\n"; + } elseif(!(bool)ini_get('enable_dl') || (bool)ini_get('safe_mode')) { + do_err($dbtype.' database support not present!'); + } else { + // Non-fatal error + do_err($dbtype.' database support not present or not configured! + Trying to dynamically load '.$dbtype.' extension. + Please note that it is advisable to not rely on dynamic loading of extensions.', FALSE); + } + + + // now, test this interface: + + $dbh = DB::connect($dsn, true); + if (DB::isError($dbh)) { + do_err('Database error: '. sm_encode_html_special_chars(DB::errorMessage($dbh)) . + ' in ' .$type .' DSN.'); + } + $dbh->disconnect(); + echo "$IND$type database connect successful.
\n"; + } + } else { + $db_error='Required PHP PDO or PEAR DB support is not available.' + .(!empty($disable_pdo) ? ' You have set $disable_pdo - please try removing that.' : '') + .' PDO should come preinstalled with PHP version 5.1 or higher.' + .' Otherwise, is PEAR installed and is the include path set correctly to find DB.php?' + .' The include path is now: "' . ini_get('include_path') . '".'; + do_err($db_error); + } } } else { echo $IND."not using database functionality.
\n";