Commit 13dd9584 authored by Chris's avatar Chris

synchro avec la branche 0.4b

parent 5470fef0
PHPMyEmail 0.3 (MAIL_PHP)
PHPMyEmail 0.4 (MAIL_PHP)
PHPMyEmail is a free secure and network capable (via SMTP protocol) alternative to mail() PHP function.
......@@ -16,6 +16,7 @@ http://sourceforge.net/tracker/?group_id=207762&atid=1002979
=========================
MAINTAINERS
=========================
Chris <chris@teria.org>
Nickilo <nickilo@teria.org>
......@@ -34,15 +35,20 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
INSTALLATION (as root user)
=========================
tar -xvzf PHPMyEmail-0.2.tar.gz
tar -xvzf PHPMyEmail-0.4.tar.gz
cd PHPMyEmail
chmod +x install.sh
./install.sh
phpize
./configure --with-mysql
make && make install
Note : "--with-mysql" is optional if you want quotas using mysql
=========================
CONFIGURATION
CONFIGURATION (php.ini)
=========================
extension=phpmyemail.so
; Enable (1) or not (0) mail quotas using mysql
mail_php.enable_mysql=0
; Enable (1) or not (0) sasl authentication
......@@ -112,9 +118,11 @@ $content : Content to be sent. If mail_php.enable_headers=1, must contain the Fr
$smtp_server (optional) : if mail_php.smtp_server="none", $smtp_server is used
$smtp_port (optional) : if mail_php.smtp_port="none", $smtp_port is used
$ssl_on (optional) : if mail_php.smtp_server="none", $ssl_on is used, default off
=========================
TEST
=========================
A php test file named PhpMyEmail-test.php is included into the package
Please edit the file to fill up the needed varaibles.
Then use the follwing command to test :
......
dnl
dnl config.m4
dnl
dnl Copyright (c) 2008-2014, Teria.org . All rights reserved.
dnl
dnl These libraries and programs are free software; you can
dnl redistribute them and/or modify them under the terms of the GNU
dnl Lesser General Public License as published by the Free Software
dnl Foundation; either version 2 of the License, or (at your option)
dnl any later version.
dnl
dnl These libraries and programs are distributed in the hope that
dnl they will be useful, but WITHOUT ANY WARRANTY; without even the
dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
dnl PURPOSE. See the GNU Lesser General Public License for more
dnl details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with these librararies and programs; if not, write
dnl to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
dnl Floor, Boston, MA 02110-1301 USA
dnl
AC_DEFUN([WITH_MYSQL], [
AC_MSG_CHECKING(for mysql_config executable)
if test -x $withval -a -f $withval
then
MYSQL_CONFIG=$withval
elif test -x $withval/bin/mysql_config -a -f $withval/bin/mysql_config
then
MYSQL_CONFIG=$withval/bin/mysql_config
fi
if test -x /usr/local/mysql/bin/mysql_config -a -f /usr/local/mysql/bin/mysql_config
then
MYSQL_CONFIG=/usr/local/mysql/bin/mysql_config
elif test -x /usr/bin/mysql_config -a -f /usr/bin/mysql_config
then
MYSQL_CONFIG=/usr/bin/mysql_config
fi
if test "x$MYSQL_CONFIG" = "x"
then
AC_MSG_RESULT(not found)
exit 3
else
ADDFLAGS=`$MYSQL_CONFIG --cflags`
CFLAGS="$CFLAGS $ADDFLAGS"
CXXFLAGS="$CXXFLAGS $ADDFLAGS"
LDFLAGS="$LDFLAGS "`$MYSQL_CONFIG --libs_r`""
AC_MSG_RESULT($MYSQL_CONFIG)
fi
])
PHP_ARG_ENABLE(phpmyemail, whether to enable phpmyemail support,
[ --enable-phpmyemail Enable phpmyemail support])
PHP_ARG_WITH(mysql, enable support for MySQL,
[ --with-mysql=DIR Location of MySQL base directory], no, no)
if test -z "$PHP_ZLIB_DIR"; then
PHP_ARG_WITH(zlib-dir, for the location of libz,
[ --with-zlib-dir[=DIR] MySQL: Set the path to libz install prefix], no, no)
fi
if test "$PHP_PHPMYEMAIL" != "no"; then
AC_CONFIG_HEADERS()
if test "$PHP_MYSQL" != "no"; then
WITH_MYSQL()
AC_DEFINE(USE_MYSQL, 1, [Whether you have MySQL])
fi
PHP_NEW_EXTENSION(phpmyemail, phpmyemail.c, $ext_shared)
fi
#!/bin/bash
# compilation
cc -fpic -DCOMPILE_DL=1 -I/usr/include -I/usr/include/mysql -I/usr/include/php/Zend -I/usr/include/php/TSRM -I/usr/include/php/main -I/usr/include/php -c -o smtp.o smtp.c
cc -shared -L/usr/local/lib -rdynamic -L/usr/lib64/mysql -lmysqlclient -o mail_php.so smtp.o
# detect php.ini location dans $configFile
configFile="none";
for file in `find /etc -name "php.ini"`; do
echo "Is $file the correct Php configuration file ? (y/n)";
read reponse;
echo "";
if [[ $reponse && $reponse = "y" ]];then
configFile=$file;
break;
fi
done
if [ $configFile = "none" ];then
# demander a l utilisateur de saisir le nom du fichier de conf
echo "Please enter the location of you php.ini ( ex : /etc/php.ini ) ";
read $configFile
echo "";
fi
# verifier que le fichier existe
if [ -e $configFile ];then
echo "Php.ini found.";
echo "";
else
echo "Error : php configuration file not found !";
exit;
fi
# trouver l emplacement des extensions de php
extensionDir="none";
for file in `grep "extension_dir" $configFile | grep "=" | awk -F"\"" '{ print $2 }' `; do
echo "Is $file the correct Php extension dir ? (y/n)";
read reponse;
echo "";
if [[ $reponse && $reponse = "y" ]];then
extensionDir=$file;
break;
fi
done
if [ $extensionDir = "none" ];then
# demander a l utilisateur de saisir le nom du rep des extensions php
echo "Please enter the directory of php extensions ( ex : /usr/lib/php/extensions/ )";
read $extensionDir;
echo "";
fi
# verifier que le repertoire existe
if [ -d $extensionDir ];then
echo "Extension dir exist.";
else
echo "Error extension dir does not exist !";
exit;
fi
# verifier que l user courant a les droit d ecriture sur le rep d extension
if [ -w $extensionDir ];then
echo "Extension dir is writable";
else
echo "Error extension dir is not writable by the current user !";
exit;
fi
# tout est pret, on copie le fichier
cp mail_php.so $extensionDir && chown root:root $extensionDir/mail_php.so
# demander si on modifie le fichier de conf php.ini
echo "Would you like us to add the module inclusion into php.ini ? ( only for the first installation ! )";
read reponse;
echo "";
if [[ $reponse && $reponse = "y" ]];then
echo "" >> $configFile
echo ";[ MAIL PHP ]" >> $configFile
echo "extension=mail_php.so" >> $configFile
echo "mail_php.enable_mysql=0" >> $configFile
echo "mail_php.enable_sasl=1" >> $configFile
echo "mail_php.enable_headers=0" >> $configFile
echo "mail_php.smtp_server=\"none\"" >> $configFile
echo "mail_php.smtp_port=25" >> $configFile
echo "mail_php.smtp_helo=\"EHLO mail_php.teria.org\"" >> $configFile
echo "mail_php.smtp_auth=\"AUTH LOGIN\"" >> $configFile
echo "mail_php.mysql_server=\"server.mysql.ld\"" >> $configFile
echo "mail_php.mysql_login=\"root\"" >> $configFile
echo "mail_php.mysql_password=\"\"" >> $configFile
echo "mail_php.mysql_base=\"mail_php\"" >> $configFile
echo "mail_php.footer=0" >> $configFile
echo "mail_php.footerContent=\"Demo footer\"" >> $configFile
echo "mail_php.enable_ssl=0" >> $configFile
echo "mail_php.enable_debug=0" >> $configFile
echo "mail_php.date=0" >> $configFile
echo "" >> $configFile
echo "Now you can edit the mail_php options in your php.ini to fit your needs";
echo "";
else
echo "For the module to run, you have to add the following line to your php.ini file :";
echo "extension=mail_php.so";
echo "mail_php.enable_mysql=0";
echo "mail_php.enable_sasl=1";
echo "mail_php.enable_headers=0";
echo "mail_php.smtp_server=\"none\"";
echo "mail_php.smtp_port=25";
echo "mail_php.smtp_helo=\"EHLO mail_php.teria.org\"";
echo "mail_php.smtp_auth=\"AUTH LOGIN\"";
echo "mail_php.mysql_server=\"server.mysql.ld\"";
echo "mail_php.mysql_login=\"root\"";
echo "mail_php.mysql_password=\"\"";
echo "mail_php.mysql_base=\"mail_php\"";
echo "mail_php.footer=0"
echo "mail_php.footerContent=\"Demo footer\""
echo "mail_php.enable_ssl=0";
echo "mail_php.enable_debug=0";
echo "mail_php.date=0";
echo "";
fi
# demander si on redemarre apache
echo "Would you like to restart apache now ?";
read reponse;
echo "";
if [[ $reponse && $reponse = "y" ]];then
apachectl restart;
fi
/*
* php_phpmyemail.h
*
* Copyright (c) 2008-2014, Teria.org . All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
#define PHPMYEMAIL_DESCRIPTION "Module Mail teria"
#define PHPMYEMAIL_VERSION "0.4b"
extern zend_module_entry phpmyemail_module_entry;
#define phpext_phpmyemail_ptr &phpmyemail_module_entry
#ifdef PHP_WIN32
# define PHP_PHPMYEMAIL_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_PHPMYEMAIL_API __attribute__ ((visibility("default")))
#else
# define PHP_PHPMYEMAIL_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
/* The size of all error message buffers */
#define ERRSTR_BUFSIZE 512
const size_t errstr_bufsize = ERRSTR_BUFSIZE;
char errstr[ERRSTR_BUFSIZE];
/* Declaration of exported functions */
ZEND_FUNCTION(mail_php);
PHP_MINIT_FUNCTION(mail_php);
PHP_MSHUTDOWN_FUNCTION(mail_php);
PHP_INI_BEGIN()
PHP_INI_ENTRY("mail_php.enable_mysql", "0", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.enable_sasl", "0", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.enable_headers", "0", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.smtp_server", "none", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.smtp_port","25", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.smtp_helo","smtp_helo", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.smtp_auth","auth_method", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.mysql_server","my_mysql_hostname", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.mysql_login","login", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.mysql_password","password", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.mysql_base","base", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.footer","0", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.footerContent","Demo footer", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.enable_debug","0", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.enable_ssl","0", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail_php.date","0", PHP_INI_SYSTEM, NULL)
PHP_INI_END()
/*
* phpmyemail.c
*
* Copyright (c) 2008-2014, Teria.org . All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_phpmyemail.h"
#include "phpmyemail_util.c"
PHP_MINIT_FUNCTION(mail_php) {
REGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(mail_php) {
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
zend_function_entry phpmyemail_functions[] =
{
ZEND_FE(mail_php, NULL)
{NULL, NULL, NULL}
};
zend_module_entry phpmyemail_module_entry = {
STANDARD_MODULE_HEADER,
PHPMYEMAIL_DESCRIPTION,
phpmyemail_functions,
PHP_MINIT(mail_php),
PHP_MSHUTDOWN(mail_php),
NULL,
NULL,
NULL,
PHPMYEMAIL_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_PHPMYEMAIL
ZEND_GET_MODULE(phpmyemail)
#endif
ZEND_FUNCTION(mail_php)
{
char *login;
int login_len;
char *pass;
int pass_len;
char *from;
int from_len;
char *to;
int to_len;
char *reply;
int reply_len;
char *content;
int content_len;
char *subject;
int subject_len;
char *smtp_server="none";
int smtp_server_len=4;
char *smtp_port="none";
int smtp_port_len=4;
char *ssl_on="none";
int ssl_on_len=4;
/* Variables recovery */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssssss|sss", &login, &login_len, &pass, &pass_len, &to, &to_len, &from, &from_len, &reply, &reply_len, &subject, &subject_len, &content, &content_len, &smtp_server, &smtp_server_len, &smtp_port, &smtp_port_len, &ssl_on, &ssl_on_len) == FAILURE) {
return;
}
#ifdef USE_MYSQL
if (INI_BOOL("mail_php.enable_mysql")) {
if (sql(from)!=0) {
RETURN_STRING("Rights or quota error.",1);
}
}
#endif
struct sockaddr_in serverSockAddr; /* Socket Address */
struct hostent *serverHostEnt; /* Host description */
in_addr_t hostAddr; /* Hostname address */
bzero(&serverSockAddr,sizeof(serverSockAddr));
/* IP address to long integer conversion */
/* hostAddr = inet_addr(server_name); */
/* si le parametre du fichier de conf est none pour le smtp, on lis l'argument */
if (strcmp(INI_STR("mail_php.smtp_server"),"none")==0) {
hostAddr = inet_addr(smtp_server);
/* Si le serveur SMTP n'est pas force, on lis le parametre SSL */
if (strcmp(ssl_on,"1")==0) {
sslOn=1;
} else {
sslOn=0;
}
} else {
hostAddr = inet_addr(INI_STR("mail_php.smtp_server"));
/* Le ssl est pilote par le fichier de configuration */
if (INI_BOOL("mail_php.enable_ssl")) {
sslOn=1;
} else {
sslOn=0;
}
}
if ( (in_addr_t)hostAddr != (in_addr_t)-1)
bcopy(&hostAddr,&serverSockAddr.sin_addr,sizeof(hostAddr));
else /* If a name is given */
{
serverHostEnt = gethostbyname(INI_STR("mail_php.smtp_server"));
/* si le parametre du fichier de conf est none pour le smtp, on lis l'argument */
if (strcmp(INI_STR("mail_php.smtp_server"),"none")==0) {
serverHostEnt = gethostbyname(smtp_server);
} else {
serverHostEnt = gethostbyname(INI_STR("mail_php.smtp_server"));
}
if (serverHostEnt == NULL) {
zend_printf("Gethost ERROR\n");
exit(0);
}
bcopy(serverHostEnt->h_addr,&serverSockAddr.sin_addr,serverHostEnt->h_length);
}
/* si le parametre du fichier de conf est none pour le port smtp, on lis l'argument */
if (strcmp(INI_STR("mail_php.smtp_port"),"none")==0) {
serverSockAddr.sin_port = htons(atoi(smtp_port)); /* smtp port from parameter */
} else {
serverSockAddr.sin_port = htons(INI_INT("mail_php.smtp_port")); /* smtp port from ini */
}
serverSockAddr.sin_family = AF_INET; /* AF_*** : INET=internet */
/* Socket Creation */
if ( (to_server_socket = socket(AF_INET,SOCK_STREAM,0)) < 0) {
zend_printf("Client socket creation issue\n");
exit(0);
}
/* Connection query */
if(connect(to_server_socket,(struct sockaddr *)&serverSockAddr,sizeof(serverSockAddr))<0) {
zend_printf("Connection timeout\n");
exit(0);
}
/* Envoi du mail */
appli(login,pass,from,to,reply,subject,content);
/* Close connection */
shutdown(to_server_socket,2);
close(to_server_socket);
}
This diff is collapsed.
/*
* phpmyemail_util.h
*
* Copyright (c) 2008-2014, Teria.org . All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
/*
*
* Constants
*
*/
#define PACKET_SIZE 1024
/* Socket vers le serveur de mail */
int to_server_socket = -1;
/* Configuration du ssl on ou off */
int sslOn=0;
/* Le ssl est pret */
int sslReady=0;
/* Constante pour l'encodage en base 64 */
static const char table64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/*
*
* Functions
*
*/
void
appli(); /* Ecrit le contenu du mail */
int
writen(int fd, char *ptr, int n); /* Envoi vers le serveur de mail */
int
readn(int fd, char *ptr, int n); /* Lecture depuis le serveur de mail */
#ifdef USE_MYSQL
int
sql(char *from);
#endif
size_t
base64_encode(const char *inp, size_t insize, char **outptr);
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment