CMS Made Simple es uno de los administradores de contenido de gran popularidad y uso a través de Internet y CMSMailer es el módulo que permite el envío de correos para otros módulos del administrador. A continuación relato la experiencia y detalles técnicos para habilitar el envío de correos usando cifrado de datos SSL/TLS. Este tutorial se realizó y probó sobre las siguientes versiones de software:
- PHP 5.2.13
- CMSMadeSimple 1.6.6
- CMSMailer 1.73.14
- INTRODUCCIÓN
A pesar de que el cifrado de datos SSL/TLS existe desde varios años y su soporte ha sido integrado en las librerias de los diferentes lenguajes de programación, me encontre con la sorpresa de que el módulo CMSMailer aún no cuenta con soporte para cifrado de datos. Buscando en google pude encontrar este articulo http://dev.cmsmadesimple.org/feature_request/view/1961 en el que Robert Sherby pública un parche que suple esta necesidad. - MODIFICACIONES
Para lograr el objetivo se han de modificar los siguientes archivos del módulo:CMSMailer.module.php
action.defaultadmin.php
lang/en_US.php
phpmailer/class.phpmailer.php
phpmailer/class.smtp.php
templates/prefs.tpl
- CMSMailer.module.php
Se modificará este archivo para agregar soporte para el atributoprotocol
.
Index: CMSMailer.module.php =================================================================== --- CMSMailer.module.php (revision 24) +++ CMSMailer.module.php (working copy) @@ -174,6 +174,7 @@ $this->SetPreference('mailer', 'smtp'); $this->SetPreference('host', 'localhost'); $this->SetPreference('port', 25 ); + $this->SetPreference('protocol', ''); $this->SetPreference('from', 'root@localhost'); $this->SetPreference('fromuser', 'CMS Administrator'); $this->SetPreference('sendmail', '/usr/sbin/sendmail'); @@ -219,6 +220,7 @@ $this->RemovePreference('mailer'); $this->RemovePreference('host'); $this->RemovePreference('port'); + $this->RemovePreference('protocol'); $this->RemovePreference('from'); $this->RemovePreference('fromuser'); $this->RemovePreference('sendmail'); @@ -285,6 +287,7 @@ $this->the_mailer->Timeout = $this->GetPreference('timeout'); $this->the_mailer->Sendmail = $this->GetPreference('sendmail'); $this->the_mailer->Port = $this->GetPreference('port'); + $this->the_mailer->Protocol = $this->GetPreference('protocol'); $this->the_mailer->Mailer = $this->GetPreference('mailer'); $this->the_mailer->FromName = $this->GetPreference('fromuser'); $this->the_mailer->From = $this->GetPreference('from'); @@ -331,6 +334,11 @@ $this->SetPreference('port',$params['input_port']); } + if( isset( $params['input_protocol'] ) ) + { + $this->SetPreference('protocol',$params['input_protocol']); + } + if( isset( $params['input_from'] ) ) { $this->SetPreference('from',$params['input_from']); @@ -591,6 +599,18 @@ $this->the_mailer->Port = $txt; } + function GetProtocol() + { + $this->_load(); + return $this->the_mailer->Protocol; + } + + function SetProtocol( $txt ) + { + $this->_load(); + $this->the_mailer->Protocol = $txt; + } + function GetPriority() { $this->_load();
- action.defaultadmin.php
Se modificará este archivo para agregar soporte para la configuración del atributoprotocol
agregando un control de tipo radio button que permite seleccionar si se requiere cifrado de datos SSL ó TLS.Index: action.defaultadmin.php =================================================================== --- action.defaultadmin.php (revision 24) +++ action.defaultadmin.php (working copy) @@ -58,6 +58,11 @@ $this->GetPreference('port'), 6, 8)); + $this->smarty->assign('prompt_protocol', $this->Lang('protocol')); + $this->smarty->assign('info_protocol', $this->Lang('info_protocol')); + $this->smarty->assign('input_protocol', + $this->CreateInputRadioGroup( $id, 'input_protocol',Array( $this->Lang('protocol_none') => '',$this->Lang('protocol_ssl') => 'ssl',$this->Lang('protocol_tls') => 'tls' ),$this->GetPreference('protocol') )); + $this->smarty->assign('prompt_from', $this->Lang('from')); $this->smarty->assign('info_from', $this->Lang('info_from')); $this->smarty->assign('input_from',
- lang/en_US.php
Se agregan los titulos de ayuda para la configuración del nuevo atributo.Index: lang/en_US.php =================================================================== --- lang/en_US.php (revision 24) +++ lang/en_US.php (working copy) @@ -15,6 +15,7 @@ $lang['mailer'] = 'Mailer method'; $lang['host'] = 'SMTP host name (or IP address)'; $lang['port'] = 'Port of SMTP server'; +$lang['protocol'] = 'Use encryption protocol'; $lang['from'] = 'From address'; $lang['fromuser'] = 'From Username'; $lang['sendmail'] = 'Sendmail location'; @@ -24,6 +25,7 @@ $lang['info_mailer'] = 'Mail method to use (sendmail, smtp, mail). Usually smtp is the most reliable.'; $lang['info_host'] = 'SMTP hostname (only valid for the smtp mailer method)'; $lang['info_port'] = 'SMTP port number (usually 25) (only valid for the smtp mailer method)'; +$lang['info_protocol'] = 'Encryption method to use (none, ssl, tls). SSL and TLS usually require setting the port to 465.'; $lang['info_from'] = 'Address used as the sender in all emails. Note, this email address must be set correctly for your host or you will have difficulty sending emails. If you do not know the proper value for this setting, you may need to contact your host.'; $lang['info_fromuser'] = 'Friendly name used for sending all emails'; $lang['info_sendmail'] = 'The complete path to your sendmail executable (only valid for the sendmail mailer method)'; @@ -317,4 +319,8 @@ Copyright © 2005, Robert Campbell <calguy1000@hotmail.com>. All Rights Are Reserved. This module has been released under the GNU Public License. You must agree to this license before using the module. '; + +$lang['protocol_none'] = 'None'; +$lang['protocol_ssl'] = 'SSL'; +$lang['protocol_tls'] = 'TLS'; ?>
- phpmailer/class.phpmailer.php
Se modificará este archivo para tener en cuenta el atributoprotocol
dentro de la firma del métodoConnect
.Index: phpmailer/class.phpmailer.php =================================================================== --- phpmailer/class.phpmailer.php (revision 24) +++ phpmailer/class.phpmailer.php (working copy) @@ -162,6 +162,12 @@ var $Port = 25; /** + * Sets the encryption protocol to use. + * @var string + */ + var $Protocol = ""; + + /** * Sets the SMTP HELO of the message (Default is $Hostname). * @var string */ @@ -542,7 +548,7 @@ $port = $this->Port; } - if($this->smtp->Connect($host, $port, $this->Timeout)) + if($this->smtp->Connect($host, $port, $this->Timeout, $this->Protocol)) { if ($this->Helo != '') $this->smtp->Hello($this->Helo);
- phpmailer/class.smtp.php
Se modificará este archivo para tener en cuenta el atributoprotocol
y así modificar el$host
agregando el protocolo a usar.Index: phpmailer/class.smtp.php =================================================================== --- phpmailer/class.smtp.php (revision 24) +++ phpmailer/class.smtp.php (working copy) @@ -79,7 +79,7 @@ * @access public * @return bool */ - function Connect($host,$port=0,$tval=30) { + function Connect($host,$port=0,$tval=30,$protocol="") { # set the error val to null so there is no confusion $this->error = null; @@ -97,6 +97,10 @@ $port = $this->SMTP_PORT; } + if(!empty($protocol)) { + $host = "$protocol://$host"; + } + #connect to the smtp server $this->smtp_conn = fsockopen($host, # the host of the server $port, # the port to use
- templates/prefs.tpl
Este archivo contiene la plantilla HTML de configuración del módulo. Se modifica para agregar el nuevo atributo.Index: templates/prefs.tpl =================================================================== --- templates/prefs.tpl (revision 24) +++ templates/prefs.tpl (working copy) @@ -18,6 +18,10 @@ {$input_port} {$info_port}
+ {$prompt_protocol}: + {$input_protocol} {$info_protocol} ++
{$prompt_from}: {$input_from} {$info_from} - CONFIGURACIÓN
Una vez modificados los archivos, se procederá a configurar el módulo de la siguiente forma: - ARCHIVOS
En el siguiente enlace encontrará el módulo con las modificaciones realizadas CMSMailer-1.73.14.xml
Siguenos en: