/** * Emailing: helper for the admins to troubleshoot email issues * * @copyright Copyright (C) 2010-2012 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ /** * Wizard to configure and initialize the iTop application */ require_once('../approot.inc.php'); require_once(APPROOT.'/application/utils.inc.php'); require_once(APPROOT.'/core/email.class.inc.php'); require_once('./setuppage.class.inc.php'); require_once(APPROOT.'/application/startup.inc.php'); require_once(APPROOT.'/application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin) $sOperation = Utils::ReadParam('operation', 'step1'); $oP = new SetupPage('iTop email test utility'); /** * Helper to check server setting required to send an email */ function CheckEmailSetting($oP) { $bRet = true; if (function_exists('php_ini_loaded_file')) // PHP >= 5.2.4 { $sPhpIniFile = php_ini_loaded_file(); } else { $sPhpIniFile = 'php.ini'; } $sTransport = MetaModel::GetConfig()->Get('email_transport'); switch($sTransport) { case 'PHPMail': $oP->info("iTop is configured to use PHP's mail function to send emails."); $bIsWindows = (array_key_exists('WINDIR', $_SERVER) || array_key_exists('windir', $_SERVER)); if ($bIsWindows) { $sSmtpServer = ini_get('SMTP'); if (empty($sSmtpServer)) { $oP->error("The SMTP server is not defined. Please add the 'SMTP' directive into $sPhpIniFile"); $bRet = false; } else if (strcasecmp($sSmtpServer, 'localhost') == 0) { $oP->warning("Your SMTP server is configured to 'localhost'. You might want to set or change the 'SMTP' directive into $sPhpIniFile"); } else { $oP->info("Your SMTP server: $sSmtpServer. To change this value, modify the 'SMTP' directive into $sPhpIniFile"); } $iSmtpPort = (int) ini_get('smtp_port'); if (empty($iSmtpPort)) { $oP->info("The SMTP port is not defined. Please add the 'smtp_port' directive into $sPhpIniFile"); $bRet = false; } else if ($iSmtpPort == 25) { $oP->info("Your SMTP port is configured to the default value: 25. You might want to set or change the 'smtp_port' directive into $sPhpIniFile"); } else { $oP->info("Your SMTP port is configured to $iSmtpPort. You might want to set or change the 'smtp_port' directive into $sPhpIniFile"); } } else { // Not a windows system $sSendMail = ini_get('sendmail_path'); if (empty($sSendMail)) { $oP->error("The command to send mail is not defined. Please add the 'sendmail_path' directive into $sPhpIniFile. A recommended setting is sendmail_path=sendmail -t -i"); $bRet = false; } else { $oP->info("The command to send mail is: $sSendMail. To change this value, modify the 'sendmail_path' directive into $sPhpIniFile"); } } break; case 'SMTP': $oP->info("iTop is configured to use the SMTP transport."); $sHost = MetaModel::GetConfig()->Get('email_transport_smtp.host'); $sPort = MetaModel::GetConfig()->Get('email_transport_smtp.port'); $sEncryption = MetaModel::GetConfig()->Get('email_transport_smtp.encryption'); $sDisplayEncryption = empty($sEncryption) ? 'no encryption ' : $sEncryption; $sUserName = MetaModel::GetConfig()->Get('email_transport_smtp.username'); $sDisplayUserName = empty($sUserName) ? 'no user ' : $sUserName; $sPassword = MetaModel::GetConfig()->Get('email_transport_smtp.password'); $sDisplayPassword = empty($sPassword) ? 'no password ' : str_repeat('*', strlen($sPassword)); $oP->info("SMTP configuration (from config-itop.php): host: $sHost, port: $sPort, user: $sDisplayUserName, password: $sDisplayPassword, encryption: $sDisplayEncryption."); if (($sHost == 'localhost') && ($sPort == '25') && ($sUserName == '') && ($sPassword == '') ) { $oP->warning("The default settings may not be suitable for your environment. You may want to ajust these values by editing iTop's configuration file (".APPROOT."conf/production/config-itop.php)."); } break; case 'Null': $oP->warning("iTop is configured to use the Null transport: emails sending will have no effect."); $bRet = false; break; case 'LogFile': $oP->warning("iTop is configured to use the LogFile transport: emails will not be sent but logged to the file: '".APPROOT."/log/mail.log'."); $bRet = true; break; default: $oP->error("Unknown transport '$sTransport' configured."); $bRet = false; } if ($bRet) { $oP->ok("PHP settings are ok to proceed with a test of the email"); } $bConfigAsync = MetaModel::GetConfig()->Get('email_asynchronous'); if ($bConfigAsync) { $oP->warning("iTop is configured to send emails asynchronously. Make sure that cron.php is scheduled to run in the background, otherwise regular emails will not be sent. For the purpose of this test, the email will be sent synchronously."); } return $bRet; } /** * Display the form for the first step of the test wizard * which consists in a basic check of the configuration and display of a form for testing */ function DisplayStep1(SetupPage $oP) { $sNextOperation = 'step2'; $oP->add("
Sending an email to '".htmlentities($sTo, ENT_QUOTES, 'utf-8')."'... (From: '".htmlentities($sFrom, ENT_QUOTES, 'utf-8')."')
\n"); $oP->add("