Skip to content

Instantly share code, notes, and snippets.

@QROkes
Last active February 23, 2021 10:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QROkes/38845477e4f4674cb5a78d48939214a0 to your computer and use it in GitHub Desktop.
Save QROkes/38845477e4f4674cb5a78d48939214a0 to your computer and use it in GitHub Desktop.
Anti SPAM Registration Plugin for Question2Answer - StopForumSpam API
<?php
/*
File: qa-plugin/webinoly-custom/qa-plugin.php
Description: Anti SPAM Registration Plugin for Question2Answer
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/*
Plugin Name: StopForumSpam
Plugin URI: https://webinoly.com/support/
Plugin Description: Anti SPAM Registration Plugin for Question2Answer
Plugin Version: 1.0
Plugin Date: 2018-04-16
Plugin Author: QROkes
Plugin Author URI: https://qrokes.com/en/
Plugin License: GPLv2
Plugin Minimum Question2Answer Version: 1.8.0
Plugin Update Check URI:
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
qa_register_plugin_module( 'filter', 'qa-registration-blocker.php', 'qas_registration_blocker', 'Q2A Registration Blocker' );
<?php
class qas_registration_blocker
{
public function filter_email( &$email, $olduser )
{
// Manually Banned Domains
$banned_ids = array('mail.ru','edusath.com','vipcherry.com','163.com','alilen.pw','usamami.com','usgeek.org','ualusa.com','edumaga.com','vipitv.com','iwinedu.com','dixz.org');
$email_domain = substr( strrchr( $email, "@" ), 1 );
$log_path = '/tmp/q2a_spam_log.txt';
if ( in_array( strtolower($email_domain), $banned_ids ) )
return 'SPAM Protection is enabled!';
// StopForumSpam API Check
$ip = qa_remote_ip_address();
$json = file_get_contents('https://api.stopforumspam.org/api?email=' . $email . '&ip=' . $ip . '&expire=180&json');
$obj = json_decode($json,true);
if ( isset($obj['success']) && $obj['success'] == 1 && ( $obj['email']['appears'] == 1 or $obj['ip']['appears'] == 1 ) ) {
$data = date("d-M-Y|g:ia") . "|s" . $obj['success'] . "m" . $obj['email']['appears'] . "i" . $obj['ip']['appears'] . "|" . $ip . "|" . $email;
file_put_contents($log_path, $data.PHP_EOL , FILE_APPEND | LOCK_EX);
return 'SPAM Protection is Enabled!';
}elseif ( empty($json) or !isset($obj['success']) or $obj['success'] != 1 ) {
$data = date("d-M-Y|g:ia");
$data .= ( empty($json) || $json === false ? " [ERROR] SFS-Response: Error - " : " [ERROR] SFS-Response: Ok | " );
$data .= ( !isset($obj['success']) || $obj['success'] == 0 ? "Success: Error " : "Success: Ok " );
file_put_contents($log_path, $data.PHP_EOL , FILE_APPEND | LOCK_EX);
}
// Check for disposable or temporary email addresses.
$npmjs_json = file_get_contents('https://open.kickbox.com/v1/disposable/' . $email);
$npmjs_obj = json_decode($npmjs_json,true);
if ( isset($npmjs_obj['disposable']) && $npmjs_obj['disposable'] == true ) {
$data = date("d-M-Y|g:ia") . "|Disposable|" . $ip . "|" . $email;
file_put_contents($log_path, $data.PHP_EOL , FILE_APPEND | LOCK_EX);
return 'SPAM Protection is Enabled! (Disposable Email Addresses are not allowed)';
}elseif ( empty($npmjs_json) or !isset($npmjs_obj['disposable']) or $npmjs_obj['disposable'] != false ) {
$data = date("d-M-Y|g:ia");
$data .= ( empty($npmjs_json) || $npmjs_json === false ? " [ERROR] NPMJS-Response: Error - " : " [ERROR] NPMJS-Response: Ok | " );
$data .= ( !isset($npmjs_obj['disposable']) || $npmjs_obj['disposable'] != false ? "Success: Error " : "Success: Ok " );
file_put_contents($log_path, $data.PHP_EOL , FILE_APPEND | LOCK_EX);
}
}
}
@parthopdas
Copy link

Very useful. Well done! Please consider adding a repository for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment