1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Stop Spammers |
---|
4 | Version: auto |
---|
5 | Description: Fight against spammers |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid= |
---|
7 | Author: plg |
---|
8 | Author URI: http://le-gall.net/pierrick |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) |
---|
12 | { |
---|
13 | die('Hacking attempt!'); |
---|
14 | } |
---|
15 | |
---|
16 | global $prefixeTable; |
---|
17 | |
---|
18 | // +-----------------------------------------------------------------------+ |
---|
19 | // | Define plugin constants | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | defined('STOP_SPAMMERS_ID') or define('STOP_SPAMMERS_ID', basename(dirname(__FILE__))); |
---|
23 | define('STOP_SPAMMERS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
24 | define('STOP_SPAMMERS_TABLE', $prefixeTable.'stop_spammers'); |
---|
25 | define('STOP_SPAMMERS_VERSION', 'auto'); |
---|
26 | |
---|
27 | // init the plugin |
---|
28 | add_event_handler('init', 'stop_spammers_init'); |
---|
29 | /** |
---|
30 | * plugin initialization |
---|
31 | * - check for upgrades |
---|
32 | * - unserialize configuration |
---|
33 | * - load language |
---|
34 | */ |
---|
35 | function stop_spammers_init() |
---|
36 | { |
---|
37 | global $conf, $user, $pwg_loaded_plugins; |
---|
38 | |
---|
39 | // apply upgrade if needed |
---|
40 | if ( |
---|
41 | STOP_SPAMMERS_VERSION == 'auto' or |
---|
42 | $pwg_loaded_plugins[STOP_SPAMMERS_ID]['version'] == 'auto' or |
---|
43 | version_compare($pwg_loaded_plugins[STOP_SPAMMERS_ID]['version'], STOP_SPAMMERS_VERSION, '<') |
---|
44 | ) |
---|
45 | { |
---|
46 | // call install function |
---|
47 | include_once(STOP_SPAMMERS_PATH.'include/install.inc.php'); |
---|
48 | stop_spammers_install(); |
---|
49 | |
---|
50 | // update plugin version in database |
---|
51 | if ( $pwg_loaded_plugins[STOP_SPAMMERS_ID]['version'] != 'auto' and STOP_SPAMMERS_VERSION != 'auto' ) |
---|
52 | { |
---|
53 | $query = ' |
---|
54 | UPDATE '. PLUGINS_TABLE .' |
---|
55 | SET version = "'. STOP_SPAMMERS_VERSION .'" |
---|
56 | WHERE id = "'. STOP_SPAMMERS_ID .'"'; |
---|
57 | pwg_query($query); |
---|
58 | |
---|
59 | $pwg_loaded_plugins[STOP_SPAMMERS_ID]['version'] = STOP_SPAMMERS_VERSION; |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | add_event_handler('user_comment_check', 'stop_spammers_checks', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
65 | function stop_spammers_checks($action, $comment) |
---|
66 | { |
---|
67 | if (!stop_spammers_check_stopforumspam()) |
---|
68 | { |
---|
69 | return 'reject'; |
---|
70 | } |
---|
71 | |
---|
72 | return $action; |
---|
73 | } |
---|
74 | |
---|
75 | function stop_spammers_check_stopforumspam() |
---|
76 | { |
---|
77 | global $conf; |
---|
78 | |
---|
79 | if (!isset($conf['stop_spammers_sfs_threshold'])) |
---|
80 | { |
---|
81 | $conf['stop_spammers_sfs_threshold'] = 50; |
---|
82 | } |
---|
83 | |
---|
84 | $ip = $_SERVER['REMOTE_ADDR']; |
---|
85 | |
---|
86 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
87 | |
---|
88 | $query = ' |
---|
89 | SELECT * |
---|
90 | FROM '.STOP_SPAMMERS_TABLE.' |
---|
91 | WHERE ip = \''.$ip.'\' |
---|
92 | ;'; |
---|
93 | $blocked = pwg_db_fetch_assoc(pwg_query($query)); |
---|
94 | if (!empty($blocked)) |
---|
95 | { |
---|
96 | single_update( |
---|
97 | STOP_SPAMMERS_TABLE, |
---|
98 | array('last_update' => $dbnow, 'occurrences' => $blocked['occurrences']+1), |
---|
99 | array('id' => $blocked['id']) |
---|
100 | ); |
---|
101 | |
---|
102 | return false; |
---|
103 | } |
---|
104 | |
---|
105 | // file_put_contents('/tmp/sfs.log', "==== ".date('c')." ".__FUNCTION__.' : '.$ip."\n", FILE_APPEND); |
---|
106 | |
---|
107 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
108 | |
---|
109 | $sfs_url = 'http://www.stopforumspam.com/api?ip='.$ip.'&f=serial&confidence'; |
---|
110 | fetchRemote($sfs_url, $result); |
---|
111 | $result = unserialize($result); |
---|
112 | |
---|
113 | if (isset($result['ip']['confidence'])) |
---|
114 | { |
---|
115 | if ($result['ip']['confidence'] > $conf['stop_spammers_sfs_threshold']) |
---|
116 | { |
---|
117 | single_insert( |
---|
118 | STOP_SPAMMERS_TABLE, |
---|
119 | array( |
---|
120 | 'ip' => $ip, |
---|
121 | 'blocker' => 'stopforumspam', |
---|
122 | 'since' => $dbnow, |
---|
123 | 'last_update' => $dbnow, |
---|
124 | 'occurrences' => 1, |
---|
125 | ) |
---|
126 | ); |
---|
127 | |
---|
128 | return false; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | return true; |
---|
133 | } |
---|
134 | ?> |
---|