1<?php 2 3/** 4 * StopForumSpam plugin 5 * User: clay 6 * Date: 7/25/15 7 * Time: 6:02 PM 8 */ 9 10require("SpamLogger.php"); 11require("ResponseChecker.php"); 12 13class action_plugin_stopforumspam extends DokuWiki_Action_Plugin 14{ 15 private $db = 0; 16 public $databasefile = ''; 17 public $tolerance = 10.0; 18 19 protected $logger; 20 protected $checker; 21 22 public function __construct() { 23 24 $this->loadConfig(); 25 $this->tolerance = $this->conf['tolerance']; 26 27 $logpath = dirname(DOKU_CONF) . "/data/spamlogger"; 28 29 $this->logger = new SpamLogger($logpath); 30 $this->checker = new ResponseChecker($this->tolerance); 31 32 $this->success = true; 33 } 34 35 public function register(Doku_Event_Handler $controller) 36 { 37 $controller->register_hook('AUTH_USER_CHANGE', 'BEFORE', $this, "check_spammer_database"); 38 } 39 40 private function do_check($username, $email, $ip) 41 { 42 $uri = sprintf("http://api.stopforumspam.org/api?f=json&email=%s&username=%s&ip=%s", 43 urlencode($email), urlencode($username), urlencode($ip)); 44 $json = file_get_contents($uri); 45 return $json; 46 } 47 48 public function check_spammer_database(Doku_Event $event, $param) 49 { 50 $can_modify = true; 51 if ($event->data['type'] == 'create') { 52 53 $username = $event->data['params'][0]; 54 $email = $event->data['params'][3]; 55 $ip = $_SERVER['REMOTE_ADDR']; 56 $response = $this->do_check($username, $email, $ip); 57 58 if ($this->checker->userIsValid($response) === false) { 59 msg('Potentially a spammer', -1); 60 $event->preventDefault(); 61 } 62 $this->logger->LogAttempt($username, $email, $ip, $this->checker->trigger, 63 $this->checker->confidence, $this->checker->accepted); 64 65 } 66 } 67 68}