1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | * Codes pour avoir des forums ouverts |
---|
5 | * sur les tickets... |
---|
6 | * Mais les spammeurs sont trop corriaces ! |
---|
7 | * Ce code n'est plus actif |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | |
---|
12 | function doc_nospam_tester_spam($texte, $params) { |
---|
13 | $infos = analyser_spams($texte); |
---|
14 | if ($infos['nombre_liens'] > 0) { |
---|
15 | foreach ($params as $desc) { |
---|
16 | list($nom, $op, $val) = $desc; |
---|
17 | eval("\$test = (\$infos['$nom'] $op $val);"); |
---|
18 | if ($test) { |
---|
19 | return true; |
---|
20 | } |
---|
21 | } |
---|
22 | } |
---|
23 | return false; |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | // verifier qu'un ticket identique n'a pas ete publie il y a peu |
---|
28 | function test_doublon_ticket($champs, $table='spip_tickets'){ |
---|
29 | $champs[] = "maj>DATE_SUB(NOW(),INTERVAL 1 hour)"; |
---|
30 | return sql_countsel($table, $champs); |
---|
31 | } |
---|
32 | |
---|
33 | // verifier que cette ip n'en est pas a son N-ieme post en peu de temps |
---|
34 | // plus de 5 messages en 5 minutes c'est suspect ... |
---|
35 | function test_ticket_ip_furieuse(){ |
---|
36 | $champs = array(); |
---|
37 | $champs[] = 'ip=' . sql_quote($GLOBALS['ip']); |
---|
38 | $champs[] = "maj>DATE_SUB(NOW(),INTERVAL 10 minute)"; |
---|
39 | $nb1 = sql_countsel('spip_tickets',$champs); |
---|
40 | $nb2 = sql_countsel('spip_tickets_forum',$champs); |
---|
41 | if (($nb1 + $nb2) > 5) { |
---|
42 | return true; |
---|
43 | } |
---|
44 | return false; |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | // ne pas accepter ce qu'on peut appeler du spam |
---|
51 | function documentation_formulaire_verifier($flux){ |
---|
52 | if ($flux['args']['form'] == 'editer_ticket' |
---|
53 | OR $flux['args']['form'] == 'forum_ticket') { |
---|
54 | if (include_spip('inc/nospam')) { |
---|
55 | $is_commentaire = ($flux['args']['form'] == 'forum_ticket'); |
---|
56 | |
---|
57 | $testsA = $testsB = $testsC = $testsM = array( |
---|
58 | array('caracteres_texte_lien_min', '<', 4), |
---|
59 | array('nombre_liens', '>', 3), |
---|
60 | array('caracteres_utiles', '<', 10), |
---|
61 | ); |
---|
62 | $testsB[1][2] = 0; // nombre_liens > 0 |
---|
63 | $testsC[1][2] = 1; // nombre_liens > 1 |
---|
64 | $testsC[2][2] = 3; // caracteres_utiles < 3 |
---|
65 | $testsM[2][2] = 5; // caracteres_utiles < 5 |
---|
66 | |
---|
67 | if (!$is_commentaire) { // ticket |
---|
68 | if (doc_nospam_tester_spam(_request('texte'), $testsA) |
---|
69 | or doc_nospam_tester_spam(_request('titre'), $testsB) |
---|
70 | or doc_nospam_tester_spam(_request('exemple'), $testsC)) { |
---|
71 | $flux['data']['message_erreur'] .= _T('nospam:erreur_spam'); |
---|
72 | } |
---|
73 | } else { // commentaire |
---|
74 | if (doc_nospam_tester_spam(_request('texte'), $testsM)) { |
---|
75 | $flux['data']['message_erreur'] .= _T('nospam:erreur_spam'); |
---|
76 | } |
---|
77 | } |
---|
78 | // doublons |
---|
79 | $table = $is_commentaire ? 'spip_tickets_forum' : 'spip_tickets'; |
---|
80 | if (test_doublon_ticket(array('texte='. sql_quote(_request('texte'))), $table)) { |
---|
81 | $flux['data']['message_erreur'] .= _T('nospam:erreur_spam_doublon'); |
---|
82 | } |
---|
83 | // ip vilaine |
---|
84 | if (test_ticket_ip_furieuse()) { |
---|
85 | $flux['data']['message_erreur'] .= _T('nospam:erreur_spam_ip'); |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | return $flux; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | // autorisations correspondantes : |
---|
94 | function documentation_autoriser(){} |
---|
95 | |
---|
96 | // Autorisation de commenter des tickets |
---|
97 | function autoriser_ticket_commenter($faire, $type, $id, $qui, $opt){ |
---|
98 | // toujours |
---|
99 | return true; |
---|
100 | } |
---|
101 | |
---|
102 | // Autorisation de creer ou modifier des tickets |
---|
103 | function autoriser_ticket_creer($faire, $type, $id, $qui, $opt){ |
---|
104 | return autoriser("ecrire", "ticket", $id, $qui, $opt); |
---|
105 | } |
---|
106 | |
---|
107 | // Autorisation de creer ou modifier des tickets |
---|
108 | function autoriser_ticket_ecrire($faire, $type, $id, $qui, $opt){ |
---|
109 | // creer : toujours |
---|
110 | if (!intval($id)) return true; |
---|
111 | // modifier : admin ou le redacteur de ticket. |
---|
112 | if (!$qui['id_auteur']) return false; |
---|
113 | if ($qui['statut'] == '0minirezo' AND !$qui['restreint']) return true; |
---|
114 | return sql_allfetsel("id_auteur", "spip_tickets", "id_auteur=" . $qui['id_auteur']); |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | ?> |
---|