[26522] | 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); |
---|
[30719] | 65 | add_event_handler('contact_form_check', 'stop_spammers_checks', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[26522] | 66 | function stop_spammers_checks($action, $comment) |
---|
| 67 | { |
---|
[30719] | 68 | global $page; |
---|
| 69 | |
---|
[26522] | 70 | if (!stop_spammers_check_stopforumspam()) |
---|
| 71 | { |
---|
[30719] | 72 | $page['errors'][] = l10n('IP address rejected'); |
---|
[26522] | 73 | return 'reject'; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | return $action; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | function stop_spammers_check_stopforumspam() |
---|
| 80 | { |
---|
[27641] | 81 | global $conf; |
---|
| 82 | |
---|
| 83 | if (!isset($conf['stop_spammers_sfs_threshold'])) |
---|
| 84 | { |
---|
| 85 | $conf['stop_spammers_sfs_threshold'] = 50; |
---|
| 86 | } |
---|
| 87 | |
---|
[26522] | 88 | $ip = $_SERVER['REMOTE_ADDR']; |
---|
| 89 | |
---|
| 90 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 91 | |
---|
| 92 | $query = ' |
---|
| 93 | SELECT * |
---|
| 94 | FROM '.STOP_SPAMMERS_TABLE.' |
---|
| 95 | WHERE ip = \''.$ip.'\' |
---|
| 96 | ;'; |
---|
| 97 | $blocked = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 98 | if (!empty($blocked)) |
---|
| 99 | { |
---|
| 100 | single_update( |
---|
| 101 | STOP_SPAMMERS_TABLE, |
---|
| 102 | array('last_update' => $dbnow, 'occurrences' => $blocked['occurrences']+1), |
---|
| 103 | array('id' => $blocked['id']) |
---|
| 104 | ); |
---|
| 105 | |
---|
| 106 | return false; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | // file_put_contents('/tmp/sfs.log', "==== ".date('c')." ".__FUNCTION__.' : '.$ip."\n", FILE_APPEND); |
---|
| 110 | |
---|
| 111 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 112 | |
---|
| 113 | $sfs_url = 'http://www.stopforumspam.com/api?ip='.$ip.'&f=serial&confidence'; |
---|
| 114 | fetchRemote($sfs_url, $result); |
---|
| 115 | $result = unserialize($result); |
---|
| 116 | |
---|
| 117 | if (isset($result['ip']['confidence'])) |
---|
| 118 | { |
---|
[27641] | 119 | if ($result['ip']['confidence'] > $conf['stop_spammers_sfs_threshold']) |
---|
[26522] | 120 | { |
---|
| 121 | single_insert( |
---|
| 122 | STOP_SPAMMERS_TABLE, |
---|
| 123 | array( |
---|
| 124 | 'ip' => $ip, |
---|
| 125 | 'blocker' => 'stopforumspam', |
---|
| 126 | 'since' => $dbnow, |
---|
| 127 | 'last_update' => $dbnow, |
---|
| 128 | 'occurrences' => 1, |
---|
| 129 | ) |
---|
| 130 | ); |
---|
| 131 | |
---|
| 132 | return false; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | return true; |
---|
| 137 | } |
---|
| 138 | ?> |
---|