1: <?php
2: /**
3: * Check register attempt for "spaminess" on stopforumspam.com
4: * Please see http://www.stopforumspam.com/usage before enabling for restrictions and conditions
5: *
6: * Assumes registration by POST with variables email and uname. This is true of the register scripts in
7: * core and the profile module.
8: *
9: * If the registrant is determined to be a spammer, the account is not created. The determination is
10: * made by inspecting the confidence level returned by the stopforumspam API. If that confidence, for
11: * any of user name, email or IP address, exceeds the configured $minimumConfidence, the registration
12: * is denied.
13: */
14: class Protector_postcommon_register_stopforumspam extends ProtectorFilterAbstract
15: {
16: /** @var float $minimumConfidence
17: * This is a percentage confidence as reported by stopforumspam api.
18: * When the reported confidence for any entry is above this, the registration will be denied.
19: */
20: protected $minimumConfidence = 65.0; // set at your desired threshold
21:
22: /**
23: * @return bool
24: */
25: public function execute()
26: {
27: // we only check the registration main post which should not match these conditions
28: if ($_SERVER['REQUEST_METHOD'] !== 'POST'
29: || !isset($_POST['email'])
30: || !isset($_POST['uname'])
31: ) {
32: return true;
33: }
34:
35: $report = array();
36: $report['email'] = isset($_POST['email']) ? $_POST['email'] : null;
37: $report['ip'] = $_SERVER['REMOTE_ADDR'];
38: $report['uname'] = isset($_POST['uname']) ? $_POST['uname'] : null;
39: $result = $this->protector->stopForumSpamLookup($report['email'], $report['ip'], $report['uname']);
40: if (false === $result || isset($result['http_code'])) {
41: // the lookup failed at the http level, log it for now?
42: $report['result'] = $result;
43: $this->protector->message = json_encode($report);
44: $this->protector->output_log('SFS-UNKNOWN');
45: return true;
46: }
47: foreach ($result as $entry) {
48: if (isset($entry['confidence']) && ((float) $entry['confidence'] > $this->minimumConfidence)) {
49: $report['result'] = $result;
50: $this->protector->message = json_encode($report);
51: $this->protector->output_log('SFS SPAM Registration');
52: // write any message as you like
53: echo 'This registration attempt has been denied. '
54: . 'If you feel this is in error, please contact the site administrator.';
55: exit;
56: }
57: }
58: }
59: }
60: