travail sur les inscriptions aux listes mailman de maniere distante (ie en utilisant juste les script cgi accessible en web) + rajout de constantes pour ces inscriptions de mailman + creation d'un fonction de log dans un fichier (peut etre utile pour debugger)

This commit is contained in:
jlb 2003-03-05 17:22:02 +00:00
parent 469d715c48
commit 467d2fac19
7 changed files with 204 additions and 47 deletions

View File

@ -578,48 +578,153 @@ class Adherent
}
/*
* Ajoute le user aux mailing-list
* Ajoute le user aux differents abonneents automatiques
* (mailing-list, spip, glasnost etc etc ..)
*
*/
Function add_to_list($email,$list)
Function add_to_abo()
{
$err=0;
// mailman
if (defined("MAIN_USE_MAILMAN") && MAIN_USE_MAILMAN == 1)
{
if(!$this->add_to_mailman()){
$err+=1;
}
}
if ($err>0){
// error
return 0;
}else{
return 1;
}
}
/*
* supprime le user des differents abonnements automatiques
* (mailing-list, spip, glasnost etc etc ..)
*
*/
Function del_to_abo()
{
$err=0;
// mailman
if (defined("MAIN_USE_MAILMAN") && MAIN_USE_MAILMAN == 1)
{
if(!$this->del_to_mailman()){
$err+=1;
}
}
if ($err>0){
// error
return 0;
}else{
return 1;
}
}
/*
*
*
*/
Function add_to_mailman($email,$list,$mailmandir)
Function add_to_mailman()
{
if (!file_exists($mailmandir)) {
mkdir($mailmandir, 0777);
}
if (!file_exists("$mailmandir/$list")) {
mkdir("$mailmandir/$list", 0777);
}
if (!file_exists("$mailmandir/$list/subscribe")) {
mkdir("$mailmandir/$list/subscribe", 0777);
}
if (!file_exists("$mailmandir/$list/subscribe/$email")) {
touch("$mailmandir/$list/subscribe/$email");
}
if (defined("MAIN_MAILMAN_URL") && MAIN_MAILMAN_URL != '' && defined("MAIN_MAILMAN_LISTS") && MAIN_MAILMAN_LISTS != '')
{
$lists=explode(',',MAIN_MAILMAN_LISTS);
foreach ($lists as $list)
{
// on remplace dans l'url le nom de la liste ainsi
// que l'email et le mot de passe
$patterns = array (
'/%LISTE%/',
'/%EMAIL%/',
'/%PASS%/'
);
$replace = array (
$list,
$this->email,
$this->pass
);
$curl_url = preg_replace ($patterns, $replace, MAIN_MAILMAN_URL);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$curl_url");
//curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_POST, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5");
//--- Start buffering
//ob_start();
$result=curl_exec ($ch);
logfile($result);
//--- End buffering and clean output
//ob_end_clean();
if (curl_error($ch) > 0)
{
// error
return 0;
}
curl_close ($ch);
}
return 1;
}else{
return 0;
}
}
Function del_to_mailman($email,$list,$mailmandir)
Function del_to_mailman()
{
if (!file_exists($mailmandir)) {
mkdir($mailmandir, 0777);
}
if (!file_exists("$mailmandir/$list")) {
mkdir("$mailmandir/$list", 0777);
}
if (!file_exists("$mailmandir/$list/unsubscribe")) {
mkdir("$mailmandir/$list/unsubscribe", 0777);
}
if (!file_exists("$mailmandir/$list/unsubscribe/$email")) {
touch("$mailmandir/$list/unsubscribe/$email");
}
if (defined("MAIN_MAILMAN_UNSUB_URL") && MAIN_MAILMAN_UNSUB_URL != '' && defined("MAIN_MAILMAN_LISTS") && MAIN_MAILMAN_LISTS != '')
{
$lists=explode(',',MAIN_MAILMAN_LISTS);
foreach ($lists as $list)
{
// on remplace dans l'url le nom de la liste ainsi
// que l'email et le mot de passe
$patterns = array (
'/%LISTE%/',
'/%EMAIL%/',
'/%PASS%/'
);
$replace = array (
$list,
$this->email,
$this->pass
);
$curl_url = preg_replace ($patterns, $replace, MAIN_MAILMAN_UNSUB_URL);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$curl_url");
//curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_POST, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5");
//--- Start buffering
//ob_start();
$result=curl_exec ($ch);
logfile($result);
//--- End buffering and clean output
//ob_end_clean();
if (curl_error($ch) > 0)
{
// error
return 0;
}
curl_close ($ch);
}
return 1;
}else{
return 0;
}
}
}
?>

View File

@ -30,6 +30,7 @@ require($GLOBALS["DOCUMENT_ROOT"]."/paiement.class.php");
$db = new Db();
$adho = new AdherentOptions($db);
$errmsg='';
if ($HTTP_POST_VARS["action"] == 'cotisation')
{
@ -104,6 +105,14 @@ if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] =
{
$adh->send_an_email($adh->email,$conf->adherent->email_valid,$conf->adherent->email_valid_subject);
}
// rajoute l'utilisateur dans les divers abonnements ..
if (!$adh->add_to_abo())
{
// error
$errmsg="echec du rajout de l'utilisateur aux mailing-lists";
}
/*
if ($conf->adherent->use_mailman == 1)
{
foreach ($conf->adherent->mailman_lists as $key)
@ -111,7 +120,7 @@ if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] =
$adh->add_to_mailman($adh->email,$key,$conf->adherent->mailman_dir);
}
}
*/
}
if ($HTTP_POST_VARS["action"] == 'confirm_resign' && $HTTP_POST_VARS["confirm"] == yes)
@ -122,6 +131,14 @@ if ($HTTP_POST_VARS["action"] == 'confirm_resign' && $HTTP_POST_VARS["confirm"]
$adh->send_an_email($adh->email,$conf->adherent->email_resil,$conf->adherent->email_resil_subject);
// supprime l'utilisateur des divers abonnements ..
if (!$adh->del_to_abo())
{
// error
$errmsg="echec du rajout de l'utilisateur aux mailing-lists";
}
/*
if ($conf->adherent->use_mailman == 1)
{
foreach ($conf->adherent->mailman_lists as $key)
@ -129,6 +146,7 @@ if ($HTTP_POST_VARS["action"] == 'confirm_resign' && $HTTP_POST_VARS["confirm"]
$adh->del_to_mailman($adh->email,$key,$conf->adherent->mailman_dir);
}
}
*/
}
@ -139,6 +157,14 @@ llxHeader();
/* Création d'une fiche */
/* */
/* ************************************************************************** */
if ($errmsg != ''){
print '<table cellspacing="0" border="1" width="100%" cellpadding="3">';
print '<th>Erreur dans l\'execution du formulaire</th>';
print "<tr><td class=\"delete\"><b>$errmsg</b></td></tr>\n";
// print "<FONT COLOR=\"red\">$errmsg</FONT>\n";
print '</table>';
}
// fetch optionals attributes and labels
$adho->fetch_optionals();

View File

@ -192,9 +192,6 @@ class ServiceConf {
class AdherentConf {
Function AdherentConf() {
$this->enabled = 0;
$this->use_mailman = 1;
$this->mailman_dir = "/home/httpd/adherents.j1b.org/htdocs/adherents/ml/mailman";
$this->mailman_lists = array('lists1','list2');
$this->email_new = "Merci de votre inscription. Votre adhesion devrait etre rapidement validee.\nVoici le rappel des coordonnees que vous avez rentrees (toute information erronee entrainera la non validation de votre inscription) :\n\n%INFO%\n\nVous pouvez a tout moment, grace a votre login et mot de passe, modifier vos coordonnees a l'adresse suivante :\n%SERVEUR%public/adherents/\n\n";
$this->email_new_subject = 'Vos coordonnees sur %SERVEUR%';
$this->email_edit = "Voici le rappel des coordonnees que vous avez modifiees (toute information erronee entrainera la non validation de votre inscription) :\n\n%INFO%\n\nVous pouvez a tout moment, grace a votre login et mot de passe, modifier vos coordonnees a l'adresse suivante :\n%SERVEUR%public/adherents/\n\n";

View File

@ -1,5 +1,6 @@
<?PHP
/* Copyright (C) 2000,2001 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
*
* 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
@ -637,4 +638,37 @@ function tab_count($basename,$bc1,$bc2,$ftc) {
$db->close();
}
/*
* logfile : permet de logguer dans un fichier
* cette fonction ne fonctionenra que si et seulement si le fichier de
* la constante globale MAIN_DEBUG existe et vaut 1
*/
function logfile($str,$log="/var/log/dolibarr/dolibarr.log")
{
if (defined("MAIN_DEBUG") && MAIN_DEBUG ==1)
{
if (!file_exists($log))
{
if (!$file=fopen($log,"w"))
{
return 0;
}
}
else
{
if (!$file=fopen($log,"a+"))
{
return 0;
}
}
$logentry=date("[d/M/Y:H:i:s] ").$str."\n";
if(!fwrite($file,$logentry)) {
fclose($file);
return 0;
}
fclose($file);
return 1;
}
}
?>

View File

@ -112,18 +112,7 @@ if (defined("MAIN_MAIL_NEW_SUBJECT"))
{
$conf->adherent->email_new_subject=MAIN_MAIL_NEW_SUBJECT;
}
if (defined("MAIN_MAILMAN_DIR"))
{
$conf->adherent->mailman_dir=MAIN_MAILMAN_DIR;
}
if (defined("MAIN_MAILMAN_LISTS"))
{
$conf->adherent->mailman_lists=explode(',',MAIN_MAILMAN_DIR);
}
if (defined("MAIN_USE_MAILMAN"))
{
$conf->adherent->use_mailman=MAIN_USE_MAILMAN;
}
/*
*/
if(!isset($application_lang))

View File

@ -52,8 +52,10 @@ INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_MAIL_NEW_SUBJECT',
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_MAIL_EDIT_SUBJECT','Votre fiche a ete editee sur %SERVEUR%','chaine','Sujet du mail d\'edition');
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_USE_MAILMAN','1','yesno','Utilisation de Mailman');
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_MAILMAN_LIST','lists1,lists2','chaine','Les listes sur lesquelles inscrire les adherents');
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_MAILMAN_DIR','/home/httpd/adherents.j1b.org/htdocs/adherents/ml/mailman','chaine','Repertoire dans lequel les nouveaux adherents aux listes sont ecris');
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_MAILMAN_UNSUB_URL','http://lists.ipsyn.net/cgi-bin/mailman/handle_opts/%LISTE%/%EMAIL%?upw=%PASS%&unsub=Unsubscribe','chaine','Url de desinscription aux listes mailman');
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_MAILMAN_URL','http://lists.ipsyn.net/cgi-bin/mailman/subscribe/%LISTE%/?email=%EMAIL%&pw=%PASS%&pw-conf=%PASS%','chaine','url pour les inscriptions mailman');
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_MAILMAN_LISTS','test-test,test-test2','chaine','Listes auxquelles inscrire les nouveaux adherents');
INSERT INTO llx_const (name, value, type, note) VALUES ('MAIN_DEBUG','1','yesno','Debug ..');
--
-- Constantes

View File

@ -16,6 +16,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# ce script prend l'intergralite des adherents valide et les mets dans
# une mailing-liste. ce script est utilie si l'on souhaite avoir une
# mailing-liste avec uniquement les adherents valides.
use DBI;
use strict;
# get the command line option