[3981] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Free Mail |
---|
[3987] | 4 | Version: 1.0.7 |
---|
[3981] | 5 | Description: Plugin modifie l entete des mails en cas de SPAM |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=309 |
---|
| 7 | Author: cljosse |
---|
| 8 | Author URI:http://cljosse.e3b.org |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | define('Free_Mail_DIR' , basename(dirname(__FILE__))); |
---|
| 13 | define('Free_Mail_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 14 | include_once (Free_Mail_PATH.'include/constants.php'); |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | add_event_handler('send_mail', 'clj_send_mail',1 , 6); |
---|
| 19 | |
---|
| 20 | function clj_send_mail($result, $mailto, $subject, $content, $headers, $args) |
---|
| 21 | { |
---|
| 22 | global $conf, $user, $lang_info, $conf_mail; |
---|
| 23 | |
---|
[3987] | 24 | $conf_free = explode("," , $conf['free_mail']); |
---|
| 25 | |
---|
| 26 | if ( isset($conf['free_mail_173']) ) $conf_free = explode("," , $conf['free_mail_173']) ; |
---|
| 27 | |
---|
| 28 | |
---|
[3981] | 29 | $infos=Get_données(); |
---|
| 30 | |
---|
[3987] | 31 | $nb_mails = $infos->nb_mails ; |
---|
[3981] | 32 | $next_day = $infos->next_day ; |
---|
| 33 | $reste = $infos->reste ; |
---|
| 34 | $quarantaine = $infos->quarantaine ; |
---|
| 35 | $admins = $infos->admins ; |
---|
| 36 | |
---|
[3987] | 37 | $ret=" false" ; |
---|
[3981] | 38 | |
---|
| 39 | |
---|
| 40 | //================= réécriture de l'entête =============================== |
---|
| 41 | |
---|
| 42 | if (!isset( $mailto)){ echo 'erreur maito absent'; exit(); } |
---|
| 43 | if (empty( $mailto)) { |
---|
| 44 | |
---|
[3987] | 45 | // |
---|
[3981] | 46 | //$mailto=""; |
---|
[3987] | 47 | if ($conf_free[0]=='on') |
---|
| 48 | { |
---|
| 49 | $mailto=$conf_mail['email_webmaster']; |
---|
| 50 | } |
---|
| 51 | if ($conf_free[1]=='on') |
---|
| 52 | { |
---|
[3981] | 53 | if (!empty($args['Cc'])) |
---|
| 54 | { |
---|
| 55 | $headers= corrige_headers('Cc:',$headers); |
---|
| 56 | } |
---|
| 57 | if (!empty($args['Bcc'])) |
---|
| 58 | { |
---|
| 59 | $headers = corrige_headers('Bcc',$headers); |
---|
| 60 | } |
---|
[3987] | 61 | } |
---|
[3981] | 62 | |
---|
| 63 | } |
---|
[3987] | 64 | if ($conf_free[2]=='on') |
---|
| 65 | { |
---|
| 66 | $texte = "This is a multi-part message in MIME format.\n"; |
---|
| 67 | |
---|
| 68 | $texte .= "-----=".$conf_mail['boundary_key']."\n"; |
---|
| 69 | $texte .= "Ceci est un message est au format MIME.\n"; |
---|
| 70 | $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; |
---|
| 71 | $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; |
---|
| 72 | $texte .= $args['content']; // A voir texte brut... |
---|
| 73 | |
---|
| 74 | $texte .= "\n\n"; |
---|
| 75 | |
---|
| 76 | $content =$texte .$content ; |
---|
| 77 | } |
---|
| 78 | |
---|
[3981] | 79 | $ret=false; |
---|
| 80 | if ( $reste <=0 ) { |
---|
| 81 | ob_start(); |
---|
| 82 | $ret = mail($mailto, $subject, $content, $headers); |
---|
| 83 | $message = ob_get_contents()."\n"; |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | //ob_flush(); |
---|
| 87 | ob_end_clean(); |
---|
| 88 | //Trop de spam |
---|
[3987] | 89 | $pos = strpos(strtolower($message), 'spam'); |
---|
[3981] | 90 | $query = ' |
---|
| 91 | UPDATE '.FREE_MAIL_TABLE.' |
---|
| 92 | SET message="'. $message.'. " |
---|
| 93 | ;'; |
---|
| 94 | pwg_query($query); |
---|
| 95 | |
---|
| 96 | if ($pos === false) { |
---|
[3987] | 97 | if ($nb_mails==0) { |
---|
| 98 | $date_mail=time(); |
---|
[3981] | 99 | $query = ' |
---|
| 100 | UPDATE '.FREE_MAIL_TABLE.' |
---|
[3987] | 101 | SET date_mail="'. $date_mail.'" |
---|
[3981] | 102 | ;'; |
---|
| 103 | pwg_query($query); |
---|
| 104 | } |
---|
| 105 | $next_day = time() + (0); //20 secondes |
---|
| 106 | $query = ' |
---|
| 107 | UPDATE '.FREE_MAIL_TABLE.' |
---|
[3987] | 108 | SET date_quarantaine="'. $next_day .'" |
---|
[3981] | 109 | ;'; |
---|
| 110 | pwg_query($query); |
---|
| 111 | |
---|
[3987] | 112 | $nb_mails += 1; |
---|
[3981] | 113 | $query = ' |
---|
| 114 | UPDATE '.FREE_MAIL_TABLE.' |
---|
[3987] | 115 | SET nb_mails="'. $nb_mails.'" |
---|
[3981] | 116 | ;'; |
---|
| 117 | pwg_query($query); |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | if ($ret) { |
---|
| 121 | |
---|
| 122 | return $ret; |
---|
| 123 | |
---|
| 124 | } |
---|
| 125 | echo '<pre>'; |
---|
| 126 | echo ' |
---|
| 127 | ---- La fonction mail à retournée [false] ------ |
---|
| 128 | '; |
---|
| 129 | echo 'mailto: '.$mailto.' |
---|
| 130 | '; |
---|
[3987] | 131 | echo 'conf_free[0]='.$conf_free[0].' Envoie du mail vers le webmaster par le header(To) ; essayer de passer la variable à "on" si "off" |
---|
| 132 | '; |
---|
| 133 | echo 'conf_free[1]='.$conf_free[1].' Modifie le format des headers (Bcc,Cc) ; essayer de passer la variable à "on" si "off" |
---|
| 134 | '; |
---|
| 135 | echo 'conf_free[2]='.$conf_free[2].' Envoie une partie texte dans le header(spam) ; essayer de passer la variable à "on" si "off" |
---|
| 136 | '; |
---|
| 137 | echo "pour modifier la variable 'conf_free' modifier le fichier include/config_local.inc.php. |
---|
| 138 | En ajoutant la variable: |
---|
| 139 | conf['free_mail_173'] = off,on,on ; |
---|
| 140 | |
---|
| 141 | "; |
---|
[3981] | 142 | echo ' |
---|
| 143 | -------- MESSAGE ----------------- |
---|
| 144 | '; |
---|
| 145 | print_r($message) ; |
---|
| 146 | echo ' |
---|
| 147 | --------HEADERS ----------------- |
---|
| 148 | '; |
---|
| 149 | print_r($headers) ; |
---|
| 150 | echo ' |
---|
| 151 | --------CONTENT ----------------- |
---|
| 152 | '; |
---|
| 153 | print_r($content) ; |
---|
| 154 | echo '</pre>' ; |
---|
| 155 | exit(); |
---|
| 156 | |
---|
| 157 | } else { |
---|
| 158 | echo $message; |
---|
| 159 | $ret=false; |
---|
| 160 | } |
---|
| 161 | //================================================================== |
---|
| 162 | |
---|
| 163 | if ($ret) { |
---|
| 164 | return $ret; |
---|
| 165 | }else{ |
---|
| 166 | $next_day = time() + (2 * 24 * 60 * 60); |
---|
| 167 | echo "Attention defaut d'envoie de mails " .$ret. "\n" ; |
---|
| 168 | $query = ' |
---|
| 169 | UPDATE '.FREE_MAIL_TABLE.' |
---|
[3987] | 170 | SET date_quarantaine="'. $next_day.'" |
---|
[3981] | 171 | ;'; |
---|
| 172 | pwg_query($query); |
---|
| 173 | $reste=($next_day-time()) /3600 ; |
---|
| 174 | exit(); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | }else{ |
---|
| 180 | |
---|
| 181 | /* echo '<pre>'; |
---|
| 182 | print_r ($headers); |
---|
| 183 | print_r($content ); |
---|
| 184 | echo '</pre>'; |
---|
| 185 | */ |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | if ($reste >= 1) { |
---|
| 189 | echo '<pre>'; |
---|
| 190 | print "Attention il ya eu un défaut d'envoie de mails encore |
---|
| 191 | ". (int ) $reste . "H |
---|
| 192 | avant le déblocage." ; |
---|
| 193 | } |
---|
| 194 | else{echo '<pre>'; |
---|
| 195 | print "Il faut attendre au minimun 20 sec avent un deuxième envoie encore avant le déblocage." ; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | echo '</pre>'; |
---|
| 199 | echo ' |
---|
| 200 | <a href="admin.php">RETOUR </a> |
---|
| 201 | '; |
---|
| 202 | |
---|
| 203 | echo "Dernier message :".$message. " reçu."; |
---|
| 204 | |
---|
| 205 | exit(); |
---|
| 206 | |
---|
| 207 | echo 'ARGS: '; |
---|
| 208 | print_r($args) ; |
---|
| 209 | echo ' |
---|
| 210 | ---------------------------------------------------- |
---|
| 211 | MAIL TO: |
---|
| 212 | ' ; |
---|
| 213 | print_r($mailto) ; |
---|
| 214 | |
---|
| 215 | echo ' |
---|
| 216 | ---------------------------------------------------- |
---|
| 217 | HEADER |
---|
| 218 | ' ; |
---|
| 219 | print_r($headers) ; |
---|
| 220 | echo ' |
---|
| 221 | ---------------------------------------------------- |
---|
| 222 | content |
---|
| 223 | ' ; |
---|
| 224 | |
---|
| 225 | print_r($content) ; |
---|
| 226 | echo '</pre>' ; |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | //================================================================================= |
---|
| 235 | function Get_colonne_de($table) |
---|
| 236 | { |
---|
| 237 | $columns_of = array(); |
---|
| 238 | $query = 'DESC '.$table.';'; |
---|
| 239 | $result = mysql_query($query); |
---|
| 240 | $columns_of[$table] = array(); |
---|
| 241 | while ($row = mysql_fetch_row($result)) |
---|
| 242 | { |
---|
| 243 | array_push($columns_of[$table], $row[0]); |
---|
| 244 | } |
---|
| 245 | return $columns_of; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | function Get_données() |
---|
| 249 | { |
---|
| 250 | global $conf, $user; |
---|
| 251 | |
---|
| 252 | $nb = Get_colonne_de(FREE_MAIL_TABLE); |
---|
| 253 | $table=$nb[FREE_MAIL_TABLE]; |
---|
| 254 | //================================================================================ |
---|
[3987] | 255 | if (!in_array( "nb_mails",$table)) { |
---|
| 256 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `nb_mails` INT NOT NULL default '0' "; |
---|
[3981] | 257 | pwg_query($query); } |
---|
[3987] | 258 | if (!in_array( "date_mail",$table)) { |
---|
| 259 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `date_mail` INT NOT NULL default '0' "; |
---|
[3981] | 260 | pwg_query($query); } |
---|
| 261 | if (!in_array( "quarantaine",$table)) { |
---|
| 262 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `quarantaine` bool NOT NULL "; |
---|
| 263 | pwg_query($query); } |
---|
| 264 | if (!in_array( "message",$table)) { |
---|
| 265 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `message` TEXT "; |
---|
| 266 | pwg_query($query); } |
---|
| 267 | $query = " |
---|
| 268 | SELECT COUNT(*) |
---|
| 269 | FROM ".FREE_MAIL_TABLE." |
---|
| 270 | ;"; |
---|
| 271 | //============================================================================== |
---|
| 272 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
| 273 | if ($count == 0) |
---|
| 274 | { |
---|
| 275 | $next_day = time() ; |
---|
[3987] | 276 | $date_quarantaine=''; |
---|
[3981] | 277 | $q = ' |
---|
[3987] | 278 | INSERT INTO '.FREE_MAIL_TABLE.' (id,nb_mails, date_quarantaine,date_mail, quarantaine,message) |
---|
[3981] | 279 | VALUES (1,0,"'. $next_day.'","'. $next_day.'" ,false,".") |
---|
| 280 | ;'; |
---|
| 281 | pwg_query($q); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | |
---|
| 285 | $query = " |
---|
| 286 | SELECT * |
---|
| 287 | FROM ".FREE_MAIL_TABLE." |
---|
| 288 | ;"; |
---|
| 289 | $data = mysql_fetch_array(pwg_query($query)); |
---|
| 290 | // limite 2000 par semaine. |
---|
| 291 | |
---|
[3987] | 292 | $infos->nb_mails = $data['nb_mails']; |
---|
| 293 | $infos->next_day = $data['date_quarantaine']; |
---|
[3981] | 294 | |
---|
[3987] | 295 | $infos->reste =(float) ( $data['date_quarantaine'] - time())/3600 ; |
---|
[3981] | 296 | |
---|
| 297 | $infos->quarantaine = $data['quarantaine']; |
---|
| 298 | $infos->message = $data['message']; |
---|
| 299 | //============================================================ |
---|
| 300 | |
---|
| 301 | $admins = array(); |
---|
| 302 | |
---|
| 303 | $query = ' |
---|
| 304 | select |
---|
| 305 | U.'.$conf['user_fields']['username'].' as username, |
---|
| 306 | U.'.$conf['user_fields']['email'].' as mail_address |
---|
| 307 | from |
---|
| 308 | '.USERS_TABLE.' as U, |
---|
| 309 | '.USER_INFOS_TABLE.' as I |
---|
| 310 | where |
---|
| 311 | I.user_id = U.'.$conf['user_fields']['id'].' and |
---|
| 312 | I.status in (\'webmaster\', \'admin\') and |
---|
| 313 | I.adviser = \'false\' and |
---|
| 314 | '.$conf['user_fields']['email'].' is not null and |
---|
| 315 | I.user_id <> '.$user['id'].' |
---|
| 316 | order by |
---|
| 317 | username |
---|
| 318 | '; |
---|
| 319 | |
---|
| 320 | $datas = pwg_query($query); |
---|
| 321 | if (!empty($datas)) |
---|
| 322 | { |
---|
| 323 | while ($admin = mysql_fetch_array($datas)) |
---|
| 324 | { |
---|
| 325 | if (!empty($admin['mail_address'])) |
---|
| 326 | { |
---|
| 327 | // array_push($admins, format_email($admin['username'], $admin['mail_address'])); |
---|
| 328 | $temp= $admin['mail_address'] ; |
---|
| 329 | array_push($admins,$temp); |
---|
| 330 | } |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | if (count($admins) > 0) |
---|
| 335 | { |
---|
| 336 | |
---|
| 337 | } |
---|
| 338 | $infos->admins = $admins ; |
---|
| 339 | return $infos; |
---|
| 340 | //======================================================================== |
---|
| 341 | echo '<pre>'; |
---|
| 342 | echo FREE_MAIL_TABLE; |
---|
| 343 | echo ' |
---|
| 344 | ----------- ADMINS ---------------------------------------- |
---|
| 345 | '; |
---|
| 346 | print_r ($admins); |
---|
| 347 | echo ' |
---|
| 348 | ------------------------------------------------------------------- |
---|
| 349 | '; |
---|
| 350 | print_r ($infos); |
---|
| 351 | echo '</pre>'; |
---|
| 352 | |
---|
| 353 | |
---|
| 354 | |
---|
| 355 | |
---|
| 356 | } |
---|
| 357 | function corrige_headers($Carbonne,$headers) |
---|
| 358 | { |
---|
| 359 | global $conf_statistics,$conf_mail; |
---|
| 360 | $mailto=""; |
---|
| 361 | /* if ($conf_free_mail[1] == 'on') { |
---|
| 362 | $mailto=$conf_mail['email_webmaster']; |
---|
| 363 | } |
---|
| 364 | */ |
---|
| 365 | $splitter="|".$Carbonne.":(.*)\n|U"; |
---|
| 366 | preg_match_all($splitter,$headers, $out,PREG_PATTERN_ORDER); |
---|
| 367 | $val=array(); |
---|
| 368 | $match=array("<",">"); |
---|
| 369 | $string=array("","") ; |
---|
| 370 | foreach($out as $messages) |
---|
| 371 | { |
---|
| 372 | $val[]= $messages[0] ; |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | |
---|
| 376 | $val[1]= str_replace( $match,$string,$val[0] ) ; |
---|
| 377 | $src=$val[0]; |
---|
| 378 | |
---|
| 379 | $splitter="|\"(.*)\"|U"; |
---|
| 380 | preg_match_all($splitter,$val[1], $out,PREG_PATTERN_ORDER); |
---|
| 381 | $string=array(); |
---|
| 382 | $string = array_fill( 0, count($out), ''); |
---|
| 383 | $dest = str_replace($out[0], $string, $val[1]) ; |
---|
| 384 | /* if ($conf_free_mail[1] == 'on') |
---|
| 385 | $dest=str_replace($mailto.',', '', $dest) ; |
---|
| 386 | $dest=str_replace($mailto, '', $dest) ; |
---|
| 387 | } |
---|
| 388 | */ |
---|
| 389 | $headers = str_replace( $src,$dest, $headers) ; |
---|
| 390 | return $headers; |
---|
| 391 | //============================================================================================================== |
---|
| 392 | |
---|
| 393 | |
---|
| 394 | } |
---|
| 395 | ?> |
---|