<commit_before><?php
// Copyright (C) 2010-2012 Combodo SARL
//
//   This file is part of iTop.
//
//   iTop is free software; you can redistribute it and/or modify	
//   it under the terms of the GNU Affero General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   iTop is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Affero General Public License for more details.
//
//   You should have received a copy of the GNU Affero General Public License
//   along with iTop. If not, see <http://www.gnu.org/licenses/>


/**
 * 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');

$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';
	}

	$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: <strong>$sSmtpServer</strong>. 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 <em>sendmail_path=sendmail -t -i</em>");
			$bRet = false;
		}
		else
		{<commit_msg>#978 Email test utility always reporting "default SMTP port"<commit_after><?php
// Copyright (C) 2010-2012 Combodo SARL
//
//   This file is part of iTop.
//
//   iTop is free software; you can redistribute it and/or modify	
//   it under the terms of the GNU Affero General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   iTop is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Affero General Public License for more details.
//
//   You should have received a copy of the GNU Affero General Public License
//   along with iTop. If not, see <http://www.gnu.org/licenses/>


/**
 * 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');

$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';
	}

	$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: <strong>$sSmtpServer</strong>. 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 <em>sendmail_path=sendmail -t -i</em>");
			$bRet = false;
		}
		else
		{
{'fraction_non_alphanumeric': 0.12905296950240772, 'fraction_numerical': 0.009470304975922954, 'mean_word_length': 3.6674157303370785, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4399695', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2112, 'n_words': 682}