New: Add action "Test server connectivity"
This commit is contained in:
parent
0d268f0f3a
commit
61a2df3919
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2007-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -14,15 +14,12 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/admin/mails.php
|
||||
\brief Page de configuration des emails
|
||||
\version $Revision$
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
@ -112,10 +109,17 @@ if ($_POST["action"] == 'send' && ! $_POST["cancel"])
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Affichage page
|
||||
*/
|
||||
|
||||
$port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port');
|
||||
if (! $port) $port=25;
|
||||
$server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP');
|
||||
if (! $server) $server='127.0.0.1';
|
||||
|
||||
|
||||
llxHeader();
|
||||
|
||||
print_fiche_titre($langs->trans("EMailsSetup"),'','setup');
|
||||
@ -175,6 +179,9 @@ else
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTP_SERVER.'</td></tr>';
|
||||
|
||||
// $var=!$var;
|
||||
// print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_SERVER",ini_get('SMTPs')?ini_get('SMTPs'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_SERVER.'</td></tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_EMAIL_FROM.'</td></tr>';
|
||||
|
||||
@ -186,19 +193,43 @@ else
|
||||
|
||||
// Boutons actions
|
||||
print '<div class="tabsAction">';
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test">'.$langs->trans("DoTest").'</a>';
|
||||
if (function_exists('fsockopen') && $port && $server)
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
|
||||
}
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test">'.$langs->trans("DoTestSend").'</a>';
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
// Affichage formulaire de TEST
|
||||
if ($_GET["action"] == 'testconnect')
|
||||
{
|
||||
print '<br>';
|
||||
print_titre($langs->trans("DoTestServerAvailability"));
|
||||
|
||||
// Cree l'objet formulaire mail
|
||||
include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
|
||||
$mail = new CMailFile('','','','');
|
||||
$result=$mail->check_server_port($server,$port);
|
||||
if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
|
||||
else
|
||||
{
|
||||
print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
|
||||
if ($mail->error) print ' - '.$mail->error;
|
||||
print '</div>';
|
||||
}
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
// Affichage formulaire de TEST
|
||||
if ($_GET["action"] == 'test')
|
||||
{
|
||||
print '<br>';
|
||||
print_titre($langs->trans("TestMailing"));
|
||||
print_titre($langs->trans("DoTestSend"));
|
||||
|
||||
// Cr<43><72> l'objet formulaire mail
|
||||
include_once("../html.formmail.class.php");
|
||||
// Cree l'objet formulaire mail
|
||||
include_once(DOL_DOCUMENT_ROOT."/html.formmail.class.php");
|
||||
$formmail = new FormMail($db);
|
||||
$formmail->fromname = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
$formmail->frommail = $conf->global->MAIN_MAIL_EMAIL_FROM;
|
||||
@ -215,7 +246,7 @@ else
|
||||
$formmail->withcancel=1;
|
||||
// Tableau des substitutions
|
||||
$formmail->substit=$substitutionarrayfortest;
|
||||
// Tableau des param<EFBFBD>tres compl<70>mentaires du post
|
||||
// Tableau des parametres complementaires du post
|
||||
$formmail->param["action"]="send";
|
||||
$formmail->param["models"]="body";
|
||||
$formmail->param["mailid"]=$mil->id;
|
||||
|
||||
2545
htdocs/includes/smtps/SMTPs.php
Normal file
2545
htdocs/includes/smtps/SMTPs.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -163,7 +163,7 @@ EMailsDesc=This page allows you to overwrite your PHP parameters for emails send
|
||||
MAIN_MAIL_SMTP_PORT=SMTP Port (By default in php.ini: <b>%s</b>)
|
||||
MAIN_MAIL_SMTP_SERVER=SMTP Host (By default in php.ini: <b>%s</b>)
|
||||
MAIN_MAIL_EMAIL_FROM=Sender EMail for automatic emails (By default in php.ini: <b>%s</b>)
|
||||
MAIN_DISABLE_ALL_MAILS=Disable all emails sendings (for test purposes)
|
||||
MAIN_DISABLE_ALL_MAILS=Disable all emails sendings (for test purposes or demos)
|
||||
ModuleSetup=Module setup
|
||||
ModulesSetup=Modules setup
|
||||
ModuleFamilyBase=System
|
||||
@ -188,6 +188,10 @@ CallUpdatePage=Go on page that update database structure and datas %s.
|
||||
LastStableVersion=Last stable version
|
||||
GenericMaskCodes=You may enter all mask of numbering. In this mask, the following tags could be used:<br><b>{000000}</b> correspond to a number which will be incremented on each %s. Enter as many zeros as the desired length of the counter. The counter will be completed by zeros at the left in order to have as many zeros as the mask. <br><b>{000000+000}</b> same as previous but a corresponding offset to the number to the right of + is applied beginning by first %s. <br><b>{000000@x}</b> same as previous but counter is reset to zero when month x is reached (x between 1 and 12). If this option is used, tag {yy} is required and also {mm} if x is 2 or higher. <br><b>{dd}</b> day (01 à 31).<br><b>{mm}</b> month (01 à 12).<br><b>{yy}</b>, <b>{yyyy}</b> or <b>{y}</b> year over 2, 4 or 1 numbers.<br>All other characters in the mask will remain intact.<br>Spaces are not allowed.<br><br><u>Example on the 99th %s of the third party TheCompany done 31/01/2007:</u><br><b>ABC{yy}{mm}-{000000}</b> will give <b>ABC0701-000099</b><br><b>{0000+100}-ZZZ/{dd}/XXX</b> will give <b>0199-ZZZ/31/XXX</b><br>
|
||||
GenericNumRefModelDesc=Return a customizable number according to a defined mask.
|
||||
ServerAvailableOnIPOrPort=Server not available at address <b>%s</b> on port <b>%s</b>
|
||||
ServerNotAvailableOnIPOrPort=Server is available at address <b>%s</b> on port <b>%s</b>
|
||||
DoTestServerAvailability=Test server connectivity
|
||||
DoTestSend=Test sending
|
||||
|
||||
# Modules
|
||||
Module0Name=Users & groups
|
||||
|
||||
@ -162,7 +162,7 @@ EMailsDesc=Cette page permet de remplacer les param
|
||||
MAIN_MAIL_SMTP_PORT=Port du serveur SMTP (Par défaut dans php.ini: <b>%s</b>)
|
||||
MAIN_MAIL_SMTP_SERVER=Nom host ou ip du serveur SMTP (Par défaut dans php.ini: <b>%s</b>)
|
||||
MAIN_MAIL_EMAIL_FROM=EMail émetteur pour envoi emails automatiques (Par défaut dans php.ini: <b>%s</b>)
|
||||
MAIN_DISABLE_ALL_MAILS=Désactiver globalement tout envoi de mails (pour mode test)
|
||||
MAIN_DISABLE_ALL_MAILS=Désactiver globalement tout envoi de mails (pour mode test ou démos)
|
||||
ModuleSetup=Configuration du module
|
||||
ModulesSetup=Configuration des modules
|
||||
ModuleFamilyBase=Système
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
* or see http://www.gnu.org/
|
||||
*
|
||||
* Lots of code inspired from Dan Potter's CMailFile class
|
||||
* If chunk_split does not works on your system, change the call to chunk_split
|
||||
* to _chunk_split
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -157,7 +155,6 @@ class CMailFile
|
||||
$fd = fopen($sourcefile, "r");
|
||||
$contents = fread($fd, filesize($sourcefile));
|
||||
$encoded = chunk_split(base64_encode($contents), 68, $this->eol);
|
||||
//$encoded = _chunk_split(base64_encode($contents));
|
||||
fclose($fd);
|
||||
return $encoded;
|
||||
}
|
||||
@ -180,7 +177,7 @@ class CMailFile
|
||||
dolibarr_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject);
|
||||
dolibarr_syslog("CMailFile::sendfile header=\n".$this->headers);
|
||||
//dolibarr_syslog("CMailFile::sendfile message=\n".$message);
|
||||
//$this->send_to_file();
|
||||
//$this->dump_mail();
|
||||
|
||||
$errorlevel=error_reporting();
|
||||
error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
|
||||
@ -244,10 +241,9 @@ class CMailFile
|
||||
|
||||
|
||||
/**
|
||||
* \brief Ecrit le mail dans un fichier.
|
||||
* Utilisation pour le debuggage
|
||||
* \brief Ecrit le mail dans un fichier. Utilisation pour le debuggage.
|
||||
*/
|
||||
function send_to_file()
|
||||
function dump_mail()
|
||||
{
|
||||
if (@is_writeable("/tmp")) // Avoid fatal error on fopen with open_basedir
|
||||
{
|
||||
@ -408,7 +404,73 @@ class CMailFile
|
||||
$out = $out . "--" . $this->mime_boundary . "--" . $this->eol;
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function check_server_port($host,$port)
|
||||
{
|
||||
$_retVal=0;
|
||||
|
||||
if (function_exists('fsockopen'))
|
||||
{
|
||||
//See if we can connect to the SMTP server
|
||||
if ( $socket = @fsockopen($host, // Host to 'hit', IP or domain
|
||||
$port, // which Port number to use
|
||||
$errno, // actual system level error
|
||||
$errstr, // and any text that goes with the error
|
||||
5) ) // timeout for reading/writing data over the socket
|
||||
{
|
||||
// Windows still does not have support for this timeout function
|
||||
if (function_exists('socket_set_timeout'))
|
||||
socket_set_timeout($socket, 5, 0);
|
||||
|
||||
// Check response from Server
|
||||
if ( $_retVal = $this->server_parse($socket, "220") )
|
||||
$_retVal = $socket;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = 'Error '.$errno.' - '.$errstr;
|
||||
}
|
||||
}
|
||||
return $_retVal;
|
||||
}
|
||||
|
||||
// This function has been modified as provided
|
||||
// by SirSir to allow multiline responses when
|
||||
// using SMTP Extensions
|
||||
//
|
||||
function server_parse($socket, $response)
|
||||
{
|
||||
/**
|
||||
* Default return value
|
||||
*
|
||||
* Returns constructed SELECT Object string or boolean upon failure
|
||||
* Default value is set at TRUE
|
||||
*
|
||||
* @var mixed $_retVal Indicates if Object was created or not
|
||||
* @access private
|
||||
* @static
|
||||
*/
|
||||
$_retVal = true;
|
||||
$server_response = '';
|
||||
|
||||
while ( substr($server_response,3,1) != ' ' )
|
||||
{
|
||||
if( !( $server_response = fgets($socket, 256) ) )
|
||||
{
|
||||
$this->error="Couldn't get mail server response codes";
|
||||
$_retVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( !( substr($server_response, 0, 3) == $response ) )
|
||||
{
|
||||
$this->error="Ran into problems sending Mail.\r\nResponse: $server_response";
|
||||
$_retVal = false;
|
||||
}
|
||||
|
||||
return $_retVal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -466,31 +528,4 @@ function getValidAddress($adresses,$format)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Permet de diviser une chaine (RFC2045)
|
||||
\param str
|
||||
\remarks function chunk_split qui remplace celle de php si necessaire
|
||||
\remarks 76 caracteres par ligne, termine par "\n"
|
||||
*/
|
||||
function _chunk_split($str)
|
||||
{
|
||||
$stmp = $str;
|
||||
$len = strlen($stmp);
|
||||
$out = "";
|
||||
while ($len > 0) {
|
||||
if ($len >= 76) {
|
||||
$out = $out . substr($stmp, 0, 76) . "\n";
|
||||
$stmp = substr($stmp, 76);
|
||||
$len = $len - 76;
|
||||
}
|
||||
else {
|
||||
$out = $out . $stmp . "\n";
|
||||
$stmp = ""; $len = 0;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user