1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Mail supervisor |
---|
4 | Version: 1.5.9 |
---|
5 | Description: Mail supervisor surveille l'envoie des mails. |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315 |
---|
7 | Author: cljosse |
---|
8 | Author URI:http://cljosse.free.fr |
---|
9 | */ |
---|
10 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
11 | if (!defined('mail_superv_DIR')) define('mail_superv_DIR' , basename(dirname(__FILE__))); |
---|
12 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
13 | |
---|
14 | $MAIL_SUPERV_PATH_ABS = str_replace('\\','/',dirname(__FILE__) ); |
---|
15 | if (!defined('MAIL_SUPERV_PATH_ABS')) define( 'MAIL_SUPERV_PATH_ABS', $MAIL_SUPERV_PATH_ABS."/"); |
---|
16 | |
---|
17 | global $conf,$mails_options,$mails_donnees ; |
---|
18 | |
---|
19 | include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' ); |
---|
20 | include_once(MAIL_SUPERV_PATH.'mail_super.inc.php'); |
---|
21 | global $mail_supervisor,$clj; |
---|
22 | |
---|
23 | $mail_supervisor = new mail_supervisor(); |
---|
24 | |
---|
25 | include_once(MAIL_SUPERV_PATH.'mail_send.inc.php'); |
---|
26 | $clj = new clj(); |
---|
27 | |
---|
28 | |
---|
29 | include_once (MAIL_SUPERV_PATH.'include/constants.php'); |
---|
30 | //=============================================== |
---|
31 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
32 | |
---|
33 | $mail_supervisor->Get_Options($mails_options,"mail_superv"); |
---|
34 | $mails_donnees=$mail_supervisor->Get_Datas(); |
---|
35 | |
---|
36 | /* EVENT_HANDLER_PRIORITY_NEUTRAL */ |
---|
37 | add_event_handler('loc_after_page_header', array(&$mail_supervisor,'init') ); |
---|
38 | add_event_handler('loc_begin_page_tail', array(&$mail_supervisor,'affiche_message') ); |
---|
39 | add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu') ); |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | //=========================================================================================== |
---|
44 | add_event_handler('send_mail',array(&$clj,'send_mail'),EVENT_HANDLER_PRIORITY_NEUTRAL - 1, 6); |
---|
45 | add_event_handler('send_mail_to',array(&$clj,'send_mail_to') ); |
---|
46 | add_event_handler('send_mail_subject',array(&$clj,'send_mail_subject') ); |
---|
47 | add_event_handler('send_mail_content',array(&$clj,'send_mail_content') ); |
---|
48 | add_event_handler('send_mail_headers',array(&$clj,'send_mail_headers') ); |
---|
49 | |
---|
50 | //========================================================================================== |
---|
51 | |
---|
52 | |
---|
53 | function clj_send_mail($result, $mailto, $subject, $content, $headers, $args,$nb_destinataires) { |
---|
54 | global $conf, $user, $lang_info; |
---|
55 | global $conf_mail,$mails_options,$mails_donnees ; |
---|
56 | global $template,$page ,$erreur_message,$infos_message, $lang; |
---|
57 | global $errors; |
---|
58 | |
---|
59 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
60 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
61 | |
---|
62 | $arg_trigg= array($mailto, $subject, $content, $headers, $args); |
---|
63 | trigger_event('mail_supervisor_clj_mail',$arg_trigg); |
---|
64 | if (empty($mail_supervisor)) |
---|
65 | $mail_supervisor = new mail_supervisor(); |
---|
66 | |
---|
67 | $message =""; |
---|
68 | if (!isset($infos_message)) { $infos_message = ""; } |
---|
69 | if (!isset($erreur_message)) { $erreur_message = ''; } |
---|
70 | |
---|
71 | $envoie_ok=true ; |
---|
72 | //======== verification si envoie de mail ou blocage connexion ===================== |
---|
73 | if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' ) { |
---|
74 | if (kill_list()) { |
---|
75 | $nb_destinataires=0; ; |
---|
76 | $envoie_ok= false ; |
---|
77 | $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ; |
---|
78 | $infos_message = l10n('Sv_mail_not_send')."<BR />"; |
---|
79 | if ($mails_options['no_connect'] == 'on' ){ |
---|
80 | if ($user['status'] == 'webmaster'){ |
---|
81 | //---------- continuer si web master ---------- |
---|
82 | }else{ |
---|
83 | trigger_event('mail_supervisor_send_mail', "DIE(KILL) : " . $ip . ' = ' . $user['status']); |
---|
84 | if (!isset($_GET['admin'])) { |
---|
85 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
---|
86 | }elseif ($_GET['admin'] != 'piwigo') |
---|
87 | { |
---|
88 | die('blacklist Hacking attempt!'); |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | trigger_event('mail_supervisor_send_mail', "Kill : " . $ip . ' = ' . $user['status'] . "noconnect==off"); |
---|
93 | return true; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | // lecture donnees ------------- |
---|
98 | $nb_mails = $mails_donnees['nb_mails'] ; |
---|
99 | $next_day = $mails_donnees['date_mail'] ; |
---|
100 | $reste = $mails_donnees['reste'] ; |
---|
101 | $rest_mail = $mails_donnees['rest_mail'] ; |
---|
102 | if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){ |
---|
103 | $mails_donnees['nb_mails'] =0 ; |
---|
104 | $mails_donnees['date_mail'] = time(); |
---|
105 | } |
---|
106 | $rest_spam = $mails_donnees['rest_spam'] ; |
---|
107 | if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){ |
---|
108 | $mails_donnees['nb_spams'] =0 ; |
---|
109 | $mails_donnees['date_spam'] = time(); |
---|
110 | } |
---|
111 | $alerte = ( $mails_donnees['reste'] >0 ) ? true : false ; |
---|
112 | $alerte_mail = ( $mails_donnees['nb_mails'] > $mails_donnees['nb_mails_maxi']-1 ) ? true : false ; |
---|
113 | $alerte_spam = ( $mails_donnees['nb_spams'] > $mails_donnees['nb_spams_maxi']-1 ) ? true : false ; |
---|
114 | //============================= |
---|
115 | // TEST envoie Message |
---|
116 | //============================= |
---|
117 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) { |
---|
118 | $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ." {". $lang_info['language_name'] ."}"."<br />"; |
---|
119 | $infos_message .="Mailto:" .$mailto ."<br />"; |
---|
120 | if(isset($args['Bcc']) && count($args['Bcc'])>0) $infos_message .="Bcc: " . implode(",",$args['Bcc'])."<br />"; |
---|
121 | if(isset($args['Cc'])&& count($args['Cc'])>0) $infos_message .="Cc: " . implode(",",$args['Cc'])."<br />"; |
---|
122 | //============================================ |
---|
123 | // Photographie |
---|
124 | //============================================ |
---|
125 | $ret="false"; |
---|
126 | ob_start(); |
---|
127 | if ($nb_destinataires > 0) { |
---|
128 | if( $envoie_ok) $ret = mail($mailto, $subject,$content, $headers); |
---|
129 | }else{ |
---|
130 | echo l10n('Sv_no_receiver_available'); |
---|
131 | } |
---|
132 | $message .= ob_get_contents(); |
---|
133 | ob_end_clean(); |
---|
134 | |
---|
135 | $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message); |
---|
136 | |
---|
137 | trigger_event('mail_supervisor_mail', $arg_trigg ); |
---|
138 | $mails_donnees['message']=$message; |
---|
139 | $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content); |
---|
140 | } else { |
---|
141 | //================== Est en quarantaine ======================= |
---|
142 | |
---|
143 | $erreur_message .= l10n('Sv_To_day_is')."<br />"; |
---|
144 | if ($alerte_spam ) { |
---|
145 | $type="Spams"; |
---|
146 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
147 | $d2=$mails_donnees['nb_spams']; |
---|
148 | $d3= $mails_donnees['rest_spam']; |
---|
149 | $d4=time()+$d3 ; |
---|
150 | } |
---|
151 | if ($alerte_mail) { |
---|
152 | $type="Mails"; |
---|
153 | $d1=$mails_donnees['nb_mails']. ' \\ ' . $mails_donnees['nb_mails_maxi'];; |
---|
154 | $d2=$mails_donnees['date_mail']; |
---|
155 | $d3= $mails_donnees['rest_mail']; |
---|
156 | $d4=time()+$d3 ; |
---|
157 | } |
---|
158 | if ($alerte) { |
---|
159 | $type="Spams(Quarantaine)"; |
---|
160 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
161 | $d2=$mails_donnees['date_quarantaine']; |
---|
162 | $d3= $mails_donnees['reste']; |
---|
163 | $d4=time()+$d3 ; |
---|
164 | } |
---|
165 | $d2=date(l10n('Sv_formatdate'),$d2); |
---|
166 | $d3=int_to_heure($d3) ; |
---|
167 | $d4=date(l10n('Sv_formatdate'),$d4); |
---|
168 | if ($alerte_mail) { |
---|
169 | $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
170 | }else{ |
---|
171 | $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
172 | } |
---|
173 | $ret = "Error ". $type." : "; |
---|
174 | $ret .= l10n('Sv_mail_not_send'); |
---|
175 | $infos_message .= l10n('Sv_mail_not_send'); |
---|
176 | } |
---|
177 | $infos_message .= "<hr>"; |
---|
178 | |
---|
179 | trigger_event('mail_supervisor_message', $infos_message ); |
---|
180 | $mail_supervisor->sauve_donnees(); |
---|
181 | $mail_supervisor->affiche_message(); |
---|
182 | return $ret ;// |
---|
183 | } |
---|
184 | //=========================================================================================== |
---|
185 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content){ |
---|
186 | global $conf, $user, $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; |
---|
187 | $match=array("<",">"); |
---|
188 | $string=array("<",">") ; |
---|
189 | // $headers=str_replace( $match,$string, $headers); |
---|
190 | // Warning: mail() has been disabled for security reasons |
---|
191 | $est_un_spam =!(strpos(strtolower($message), 'spam') === false); |
---|
192 | |
---|
193 | $log_message = " :".sprintf(l10n('Sv_debug_message'), |
---|
194 | ($ret==true)? "true" : "false", |
---|
195 | "\n".$message , |
---|
196 | "\n".$mailto , |
---|
197 | "\n".$subject , |
---|
198 | "\n".$headers , |
---|
199 | "\n".$content , |
---|
200 | "\n".$nb_destinataires) ; |
---|
201 | |
---|
202 | if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { |
---|
203 | //=============== La fonction mail retourne une erreur ========================= |
---|
204 | $ret="Error"; |
---|
205 | // Bad recipient address syntax |
---|
206 | $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); |
---|
207 | if ( !($pos1 === false) ){ |
---|
208 | $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .'; |
---|
209 | $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; |
---|
210 | } |
---|
211 | $erreur_message .=$ret . " :".sprintf(l10n('Sv_debug_message'), |
---|
212 | ($ret==true)? "true" : "false", |
---|
213 | htmlspecialchars($message) , |
---|
214 | htmlspecialchars( $mailto) , |
---|
215 | htmlspecialchars($subject) , |
---|
216 | htmlspecialchars($headers) , |
---|
217 | htmlspecialchars($content) , |
---|
218 | $nb_destinataires ); |
---|
219 | |
---|
220 | Mail_supervisor_log($mailto,$log_message) ; |
---|
221 | |
---|
222 | }else{ |
---|
223 | if( isset($mails_options['debug_mail']) && $mails_options['debug_mail']=="on") { |
---|
224 | $infos_message .="DEBUG : " .sprintf(l10n('Sv_debug_message'), |
---|
225 | ($ret==true)? "true" : "false", |
---|
226 | htmlspecialchars( $message) , |
---|
227 | htmlspecialchars( $mailto) , |
---|
228 | htmlspecialchars($subject) , |
---|
229 | htmlspecialchars($headers) , |
---|
230 | htmlspecialchars($content) , |
---|
231 | $nb_destinataires ); |
---|
232 | |
---|
233 | Mail_supervisor_log($mailto,"DEBUG :" . ($log_message)) ; |
---|
234 | } |
---|
235 | } |
---|
236 | //================================================================= |
---|
237 | if ($est_un_spam == false){ |
---|
238 | if ($mails_donnees['nb_mails']==0) { $mails_donnees['date_mail'] = time(); } |
---|
239 | $mails_donnees['nb_mails'] += $nb_destinataires; |
---|
240 | } else { |
---|
241 | $ret="Error spam"; |
---|
242 | $mails_donnees['nb_spams'] += $nb_destinataires; |
---|
243 | //--- Detection de spam ------------------ |
---|
244 | if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time(); } |
---|
245 | |
---|
246 | $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); |
---|
247 | if ( $trop_de_spam ) { |
---|
248 | $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams']; |
---|
249 | |
---|
250 | $mails_donnees['date_quarantaine']= time() ; |
---|
251 | $mails_donnees['quarantaine']= true ; |
---|
252 | $infos_message .= $mail_supervisor->Memo_Var($mails_donnees); |
---|
253 | } |
---|
254 | } |
---|
255 | return $ret ; |
---|
256 | } |
---|
257 | //============================================================ |
---|
258 | global $ms_file_log,$dir,$clj_pwd; |
---|
259 | |
---|
260 | |
---|
261 | $clj_pwd=$conf['local_data_dir'].'/Pwd'; |
---|
262 | if (!is_dir($clj_pwd)){ |
---|
263 | $umask = umask(0); |
---|
264 | $mkd = @mkdir($clj_pwd, 0755, true ); |
---|
265 | umask($umask); |
---|
266 | if ($mkd==false){ |
---|
267 | echo "<pre>PWD:$clj_pwd"; |
---|
268 | fatal_error( "$clj_pwd ".l10n('no write access')); |
---|
269 | return false; |
---|
270 | } |
---|
271 | } |
---|
272 | //================================================== |
---|
273 | $dir=$conf['local_data_dir'].'/Mail_supervisor_log'; |
---|
274 | if (!is_dir($dir)){ |
---|
275 | $umask = umask(0); |
---|
276 | $mkd = @mkdir($dir, 0755, true ); |
---|
277 | umask($umask); |
---|
278 | if ($mkd==false){ |
---|
279 | echo "<pre>Dir:$dir"; |
---|
280 | fatal_error( "$dir ".l10n('no write access')); |
---|
281 | return false; |
---|
282 | } |
---|
283 | } |
---|
284 | //================================================== |
---|
285 | //add_event_handler('loc_begin_page_header', 'set_access' ); |
---|
286 | function set_access(){ |
---|
287 | global $user; |
---|
288 | global $ms_file_log,$dir,$clj_pwd; |
---|
289 | global $user,$conf; |
---|
290 | $pwd=$clj_pwd; |
---|
291 | |
---|
292 | if(!file_exists( $pwd.'/.htpasswd') || !file_exists( $dir.'/.htaccess')){ |
---|
293 | //========================================================= |
---|
294 | // Creation liste mot de passe |
---|
295 | //========================================================= |
---|
296 | $server=$_SERVER["SERVER_NAME"]; |
---|
297 | $server_ip=$_SERVER["SERVER_ADDR"]; |
---|
298 | $user_ip=$_SERVER["REMOTE_ADDR"]; |
---|
299 | $pattern ="/(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1}[0-9]|[1-9])\.){1}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9])\.){2}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]){1}))/" ; |
---|
300 | $local=preg_match($pattern,$user_ip); |
---|
301 | |
---|
302 | $file = $pwd.'/.htpasswd'; |
---|
303 | $htmes1 =$conf['db_user'].":".$conf['db_password']."\n"; |
---|
304 | $htmes2 =$conf['db_user'].":".crypt($conf['db_password'], 'rl')."\n"; |
---|
305 | if(preg_match("/free/i",$server)||$local) |
---|
306 | $htmes=$htmes1; |
---|
307 | else |
---|
308 | $htmes=$htmes2; |
---|
309 | //==== Ecriture fichier texte |
---|
310 | |
---|
311 | $fp = fopen ( $file , "w"); |
---|
312 | fwrite($fp , $htmes,strlen($htmes)); |
---|
313 | fclose ($fp); |
---|
314 | |
---|
315 | $file = $pwd.'/.htaccess'; |
---|
316 | @file_put_contents( $file, "deny for all" ); |
---|
317 | //========================================================= |
---|
318 | // Creation fichier htaccess |
---|
319 | //========================================================= |
---|
320 | $racine=explode("/",$_SERVER["PHP_SELF"] ); |
---|
321 | $racine = $racine[1] ; |
---|
322 | if(preg_match("/free/i",$server)) { |
---|
323 | $AuthUserFile='PerlSetVar AuthFile '.$racine.'/_data/Pwd' .'/.htpasswd'; |
---|
324 | }else{ |
---|
325 | if($local) |
---|
326 | $AuthUserFile='AuthUserFile '.realpath($pwd).'\\.htpasswd'."\n".'AuthGroupFile /dev/null'; |
---|
327 | else |
---|
328 | $AuthUserFile='AuthUserFile '.realpath($pwd).'\\.htpasswd'."\n".'AuthGroupFile /dev/null'; |
---|
329 | } |
---|
330 | |
---|
331 | //============================================================ |
---|
332 | $htmes=$AuthUserFile."\n". |
---|
333 | 'AuthName "Mail_supervisor_log"'."\n". |
---|
334 | 'AuthType Basic'."\n". |
---|
335 | '<limit GET>'."\n". |
---|
336 | 'require valid-user'."\n". |
---|
337 | '</Limit>'; |
---|
338 | $file = $dir.'/.htaccess'; |
---|
339 | @file_put_contents( $file, $htmes ); |
---|
340 | //============================================================ |
---|
341 | |
---|
342 | } |
---|
343 | |
---|
344 | } |
---|
345 | |
---|
346 | if($ms_file_log=="") $ms_file_log = $dir."/"."pw1.html"; |
---|
347 | |
---|
348 | |
---|
349 | //============================================================ |
---|
350 | function Mail_supervisor_log($label_,$lines){ |
---|
351 | global $ms_file_log,$conf; |
---|
352 | $nb_lignes=600 ; |
---|
353 | $t= var_export( $lines, true ); |
---|
354 | $s = htmlspecialchars( $lines); |
---|
355 | $s = ( $lines); |
---|
356 | if (!file_exists($ms_file_log)) { |
---|
357 | $handle = fopen($ms_file_log, 'w'); |
---|
358 | fwrite($handle, "\n"); |
---|
359 | fclose($handle); |
---|
360 | } |
---|
361 | $tableau=file($ms_file_log); |
---|
362 | $handle = fopen($ms_file_log, 'a'); |
---|
363 | $nb=count ($tableau); |
---|
364 | if($nb>$nb_lignes) { |
---|
365 | $handle = fopen($ms_file_log, 'w'); |
---|
366 | fwrite($handle, $nb. " > " . $nb_lignes . " RAZ " ."\n"); |
---|
367 | } |
---|
368 | //rewind ($handle); // Go back to the beginning |
---|
369 | //fwrite ($handle, sprintf("%5d ", $nb)); // Don't forget to increment the counter |
---|
370 | $s="\n".date('Y m d H:m:s ')."\n".$s; |
---|
371 | |
---|
372 | |
---|
373 | //$s= nl2br($s); |
---|
374 | |
---|
375 | if( $s !="") fwrite($handle,$s ); |
---|
376 | fclose($handle); |
---|
377 | } |
---|
378 | |
---|
379 | |
---|
380 | |
---|
381 | ?> |
---|