├── adm └── style │ ├── event │ └── acp_overall_footer_after.html │ └── stopforumspam_body.html ├── styles ├── prosilver │ └── template │ │ └── event │ │ ├── posting_editor_subject_before.html │ │ ├── ucp_pm_viewmessage_post_buttons_before.html │ │ └── viewtopic_body_post_buttons_before.html ├── all │ └── template │ │ └── event │ │ └── overall_footer_after.html └── scaffoldBB │ └── template │ └── event │ ├── ucp_pm_viewmessage_post_buttons_before.html │ ├── posting_editor_subject_before.html │ └── viewtopic_body_post_buttons_before.html ├── config ├── routing.yml └── services.yml ├── migrations ├── version_121.php ├── version_122.php ├── version_101.php ├── version_120.php ├── version_100.php ├── version_104.php ├── version_103.php └── version_102.php ├── acp ├── stopforumspam_info.php └── stopforumspam_module.php ├── controller ├── admin_interface.php └── admin_controller.php ├── composer.json ├── language └── en │ ├── sfs_mcp.php │ ├── acp │ ├── info_acp_stopforumspam.php │ └── acp_stopforumspam.php │ └── stopforumspam.php ├── ext.php ├── core ├── sfsgroups.php ├── sfsapi.php ├── report_pm_to_sfs.php └── reporttosfs.php ├── license.txt └── event └── main_listener.php /adm/style/event/acp_overall_footer_after.html: -------------------------------------------------------------------------------- 1 | {% if SFS_POSTS_PMS_COUNT %} 2 | 15 | {% endif %} -------------------------------------------------------------------------------- /styles/prosilver/template/event/posting_editor_subject_before.html: -------------------------------------------------------------------------------- 1 | {% if SFS %} 2 |
3 |
4 |
5 |
6 | {% endif %} -------------------------------------------------------------------------------- /styles/all/template/event/overall_footer_after.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /styles/prosilver/template/event/ucp_pm_viewmessage_post_buttons_before.html: -------------------------------------------------------------------------------- 1 | {% if S_SFS %} 2 |
  • 3 | {{ lang('REPORT_TO_SFS') }} 4 |
  • 5 | {% endif %} 6 | -------------------------------------------------------------------------------- /styles/prosilver/template/event/viewtopic_body_post_buttons_before.html: -------------------------------------------------------------------------------- 1 | {% if postrow.S_SFS %} 2 |
  • 3 | 4 | 5 | {{ lang('BUTTON_SFS') }} 6 | 7 |
  • 8 | {% endif %} 9 | -------------------------------------------------------------------------------- /styles/scaffoldBB/template/event/ucp_pm_viewmessage_post_buttons_before.html: -------------------------------------------------------------------------------- 1 | {% if S_SFS %} 2 |
  • 3 | {{ lang('REPORT_TO_SFS') }} 4 |
  • 5 | {% endif %} 6 | -------------------------------------------------------------------------------- /styles/scaffoldBB/template/event/posting_editor_subject_before.html: -------------------------------------------------------------------------------- 1 | {% if SFS %} 2 |
    3 |
    4 |
    5 |
    6 | {% endif %} -------------------------------------------------------------------------------- /styles/scaffoldBB/template/event/viewtopic_body_post_buttons_before.html: -------------------------------------------------------------------------------- 1 | {% if postrow.S_SFS %} 2 |
  • 3 | 4 | 5 | {{ lang('BUTTON_SFS') }} 6 | 7 |
  • 8 | {% endif %} 9 | -------------------------------------------------------------------------------- /config/routing.yml: -------------------------------------------------------------------------------- 1 | rmcgirr83_stopforumspam_core_reporttosfs: 2 | path: /reporttosfs/{postid}/{posterid} 3 | defaults: { _controller: rmcgirr83.stopforumspam.core.reporttosfs:reporttosfs } 4 | requirements: 5 | postid: \d+ 6 | posterid: \d+ 7 | 8 | rmcgirr83_stopforumspam_core_report_pm_to_sfs: 9 | path: /reportpmtosfs/{postid}/{posterid} 10 | defaults: { _controller: rmcgirr83.stopforumspam.core.report_pm_to_sfs:report_pm_to_sfs } 11 | requirements: 12 | postid: \d+ 13 | posterid: \d+ 14 | -------------------------------------------------------------------------------- /migrations/version_121.php: -------------------------------------------------------------------------------- 1 | '\rmcgirr83\stopforumspam\acp\stopforumspam_module', 20 | 'title' => 'SFS_CONTROL', 21 | 'version' => '1.1.0', 22 | 'modes' => [ 23 | 'settings' => ['title' => 'SFS_CONTROL', 'auth' => 'ext_rmcgirr83/stopforumspam && acl_a_board', 'cat' => ['SFS_CONTROL']], 24 | ], 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /migrations/version_122.php: -------------------------------------------------------------------------------- 1 | tpl_name = 'stopforumspam_body'; 23 | $this->page_title = $phpbb_container->get('language')->lang('SFS_CONTROL'); 24 | 25 | // Get an instance of the admin controller 26 | $admin_controller = $phpbb_container->get('rmcgirr83.stopforumspam.admin.controller'); 27 | 28 | // Make the $u_action url available in the admin controller 29 | $admin_controller->set_page_url($this->u_action); 30 | 31 | $admin_controller->display_options(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /migrations/version_101.php: -------------------------------------------------------------------------------- 1 | config['sfs_version']) && version_compare($this->config['sfs_version'], '1.0.1', '>='); 23 | } 24 | 25 | static public function depends_on() 26 | { 27 | return array('\rmcgirr83\stopforumspam\migrations\version_100'); 28 | } 29 | 30 | public function update_data() 31 | { 32 | return array( 33 | array('config.remove', array('sfs_api_key')), 34 | array('config.update', array('sfs_version', '1.0.1')), 35 | ); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /migrations/version_120.php: -------------------------------------------------------------------------------- 1 | [ 29 | $this->table_prefix . 'privmsgs' => [ 30 | 'sfs_reported' => ['BOOL', 0], 31 | ], 32 | ], 33 | ]; 34 | } 35 | public function revert_schema() 36 | { 37 | return [ 38 | 'drop_columns' => [ 39 | $this->table_prefix . 'privmsgs' => [ 40 | 'sfs_reported', 41 | ], 42 | ], 43 | ]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rmcgirr83/stopforumspam", 3 | "type": "phpbb-extension", 4 | "description": "Queries the stop forum spam database on registration and posting. Extension settings are found under the extension tab of the forum. This extension requires at least phpBB version 3.3.", 5 | "homepage": "https://github.com/rmcgirr83/stopforumspam", 6 | "version": "1.4.8", 7 | "time": "2025-04-27", 8 | "license": "GPL-2.0-only", 9 | "authors": [ 10 | { 11 | "name": "Rich McGirr", 12 | "homepage": "https://www.phpbb.com/customise/db/author/rmcgirr83/contributions", 13 | "role": "Lead Developer" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=7.4", 18 | "phpbb/phpbb": ">=3.3", 19 | "composer/installers": "~1.0" 20 | }, 21 | "extra": { 22 | "display-name": "Stop Forum Spam", 23 | "soft-require": { 24 | "phpbb/phpbb": ">=3.3" 25 | }, 26 | "version-check": { 27 | "host": "www.phpbb.com", 28 | "directory": "/customise/db/extension/phpbb_3.1_stop_forum_spam", 29 | "filename": "version_check", 30 | "ssl": true 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /migrations/version_100.php: -------------------------------------------------------------------------------- 1 | config['sfs_version']) && version_compare($this->config['sfs_version'], '1.0.0', '>='); 22 | } 23 | 24 | static public function depends_on() 25 | { 26 | return array('\phpbb\db\migration\data\v31x\v314rc1'); 27 | } 28 | 29 | public function update_data() 30 | { 31 | return array( 32 | array('config.add', array('sfs_version', '1.0.0')), 33 | array('config.add', array('allow_sfs', 1)), 34 | array('config.add', array('sfs_threshold', 5)), 35 | array('config.add', array('sfs_ban_ip', 0)), 36 | array('config.add', array('sfs_log_message', 0)), 37 | array('config.add', array('sfs_down', 0)), 38 | array('config.add', array('sfs_api_key', '')), 39 | ); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /language/en/sfs_mcp.php: -------------------------------------------------------------------------------- 1 | 'User was reported to Stop Forum Spam
    » %1$s', 38 | ]); 39 | -------------------------------------------------------------------------------- /migrations/version_104.php: -------------------------------------------------------------------------------- 1 | array( 38 | $this->table_prefix . 'posts' => array( 39 | 'sfs_reported' => array('BOOL', 0), 40 | ), 41 | ), 42 | ); 43 | } 44 | public function revert_schema() 45 | { 46 | return array( 47 | 'drop_columns' => array( 48 | $this->table_prefix . 'posts' => array( 49 | 'sfs_reported', 50 | ), 51 | ), 52 | ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /config/services.yml: -------------------------------------------------------------------------------- 1 | services: 2 | _defaults: 3 | autowire: true 4 | bind: 5 | $auth: '@auth' 6 | $cache: '@cache' 7 | $config: '@config' 8 | $container: '@service_container' 9 | $db: '@dbal.conn' 10 | $helper: '@controller.helper' 11 | $language: '@language' 12 | $log: '@log' 13 | $request: '@request' 14 | $template: '@template' 15 | $user: '@user' 16 | $root_path: '%core.root_path%' 17 | $php_ext: '%core.php_ext%' 18 | $sfsgroups: '@rmcgirr83.stopforumspam.core.sfsgroups' 19 | $sfsapi: '@rmcgirr83.stopforumspam.core.sfsapi' 20 | $contactadmin: '@?rmcgirr83.contactadmin.main.controller' 21 | 22 | rmcgirr83.stopforumspam.admin.controller: 23 | class: rmcgirr83\stopforumspam\controller\admin_controller 24 | 25 | rmcgirr83.stopforumspam.mainlistener: 26 | class: rmcgirr83\stopforumspam\event\main_listener 27 | tags: 28 | - { name: event.listener } 29 | 30 | rmcgirr83.stopforumspam.core.reporttosfs: 31 | class: rmcgirr83\stopforumspam\core\reporttosfs 32 | 33 | rmcgirr83.stopforumspam.core.report_pm_to_sfs: 34 | class: rmcgirr83\stopforumspam\core\report_pm_to_sfs 35 | 36 | rmcgirr83.stopforumspam.core.sfsgroups: 37 | class: rmcgirr83\stopforumspam\core\sfsgroups 38 | 39 | rmcgirr83.stopforumspam.core.sfsapi: 40 | class: rmcgirr83\stopforumspam\core\sfsapi 41 | -------------------------------------------------------------------------------- /ext.php: -------------------------------------------------------------------------------- 1 | container->get('config'); 31 | $language = $this->container->get('language'); 32 | 33 | $enableable = (phpbb_version_compare($config['version'], self::PHPBB_MIN_VERSION, '>=')); 34 | if (!$enableable) 35 | { 36 | $language->add_lang('stopforumspam', 'rmcgirr83/stopforumspam'); 37 | 38 | trigger_error($language->lang('EXTENSION_REQUIREMENTS', self::PHPBB_MIN_VERSION), E_USER_WARNING); 39 | } 40 | 41 | // check for curl being installed 42 | $curl_has_ssl = false; 43 | $curl_installed = extension_loaded('curl'); 44 | if ($curl_installed) 45 | { 46 | $curl_version = curl_version(); 47 | $curl_has_ssl = $curl_version['features'] & CURL_VERSION_SSL; 48 | } 49 | 50 | $enableable = ($curl_installed && $curl_has_ssl) ? true : false; 51 | if (!$enableable) 52 | { 53 | $language->add_lang('stopforumspam', 'rmcgirr83/stopforumspam'); 54 | 55 | trigger_error($language->lang('CURL_REQUIREMENTS'), E_USER_WARNING); 56 | } 57 | 58 | return $enableable; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /migrations/version_103.php: -------------------------------------------------------------------------------- 1 | container->get('config_text'); 30 | 31 | $this->settings = unserialize($config_text->get('sfs_settings')); 32 | 33 | return array( 34 | array('config.add', array('allow_sfs', $this->get('allow_sfs', 1))), 35 | array('config.add', array('sfs_threshold', $this->get('sfs_threshold', 5))), 36 | array('config.add', array('sfs_ban_ip', $this->get('sfs_ban_ip', 0))), 37 | array('config.add', array('sfs_log_message', $this->get('sfs_log_message', 0))), 38 | array('config.add', array('sfs_down', $this->get('sfs_down', 0))), 39 | array('config.add', array('sfs_by_name', $this->get('sfs_by_name', 1))), 40 | array('config.add', array('sfs_by_email', $this->get('sfs_by_email', 1))), 41 | array('config.add', array('sfs_by_ip', $this->get('sfs_by_ip', 1))), 42 | array('config.add', array('sfs_ban_reason', $this->get('sfs_ban_reason', 1))), 43 | array('config.remove', array('sfs_version')), 44 | array('config_text.remove', array('sfs_settings')), 45 | ); 46 | } 47 | 48 | protected function get($name, $default) 49 | { 50 | return isset($this->settings[$name]) ? (int) $this->settings[$name] : $default; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /migrations/version_102.php: -------------------------------------------------------------------------------- 1 | config['sfs_version']) && version_compare($this->config['sfs_version'], '1.0.2', '>='); 23 | } 24 | 25 | static public function depends_on() 26 | { 27 | return array('\rmcgirr83\stopforumspam\migrations\version_101'); 28 | } 29 | 30 | public function update_data() 31 | { 32 | 33 | $settings_ary = array( 34 | 'allow_sfs' => $this->config->offsetGet('allow_sfs'), 35 | 'sfs_threshold' => $this->config->offsetGet('sfs_threshold'), 36 | 'sfs_ban_ip' => $this->config->offsetGet('sfs_ban_ip'), 37 | 'sfs_log_message' => $this->config->offsetGet('sfs_log_message'), 38 | 'sfs_down' => $this->config->offsetGet('sfs_down'), 39 | 'sfs_by_name' => 1, 40 | 'sfs_by_email' => 1, 41 | 'sfs_by_ip' => 1, 42 | 'sfs_ban_reason' => 1, 43 | ); 44 | $settings = serialize($settings_ary); 45 | 46 | return array( 47 | array('config_text.add', array('sfs_settings', $settings)), 48 | array('config.remove', array('allow_sfs')), 49 | array('config.remove', array('sfs_threshold')), 50 | array('config.remove', array('sfs_ban_ip')), 51 | array('config.remove', array('sfs_log_message')), 52 | array('config.remove', array('sfs_down')), 53 | array('config.update', array('sfs_version', '1.0.2')), 54 | array('module.add', array( 55 | 'acp', 56 | 'ACP_CAT_DOT_MODS', 57 | 'ACP_SFS_TITLE' 58 | )), 59 | 60 | array('module.add', array( 61 | 'acp', 62 | 'ACP_SFS_TITLE', 63 | array( 64 | 'module_basename' => '\rmcgirr83\stopforumspam\acp\stopforumspam_module', 65 | 'modes' => array('settings'), 66 | ), 67 | )), 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /language/en/acp/info_acp_stopforumspam.php: -------------------------------------------------------------------------------- 1 | 'Stop Forum Spam', 39 | 'SFS_CONTROL' => 'Stop Forum Spam Settings', 40 | // ACP message logs 41 | 'LOG_SFS_MESSAGE' => 'Stop Forum Spam triggered:
    Username: %1$s
    IP: %2$s
    Email: %3$s', 42 | 'LOG_SFS_DOWN' => 'Stop Forum Spam was down during a registration or a forum post', 43 | 'LOG_SFS_DOWN_USER_ALLOWED' => 'Stop Forum Spam was down. Following user was allowed on the forum:
    Username: %1$s
    IP:%2$s
    Email: %3$s', 44 | 'LOG_SFS_NEED_CURL' => 'The stop forum spam extension needs cURL to work correctly. Please speak to your server host to get cURL installed and active.', 45 | 'LOG_SFS_CURL_ERROR' => 'Stop Forum Spam cURL error
    » %1$s', 46 | 'LOG_SFS_CONFIG_SAVED' => 'Stop Forum Spam settings changed', 47 | 'LOG_SFS_REPORTED' => 'User was reported to Stop Forum Spam
    » %1$s', 48 | 'LOG_SFS_PM_REPORTED' => 'Users PM was reported to Stop Forum Spam
    » %1$s', 49 | 'LOG_SFS_REPORTED_CLEARED' => 'Reported posts and private messages to stop forum spam were cleared', 50 | 'LOG_ADMINSMODS_CACHE_BUILT' => 'Stop forum spam Admins and Mods cache was built', 51 | ]); 52 | -------------------------------------------------------------------------------- /core/sfsgroups.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 32 | $this->cache = $cache; 33 | } 34 | 35 | /* 36 | * getadminsmods generate a cache of users who are mods of forums and merge with the already existing cache of admins and mods 37 | * this is used in the listener as well as reporttosfs files 38 | * @param $forum_id the id of a forum 39 | * @return null 40 | * @access public 41 | */ 42 | public function getadminsmods($forum_id) 43 | { 44 | $admins_mods = $this->cache->get('_sfs_adminsmods'); 45 | 46 | // ensure the cache was built in the ACP 47 | if (!$admins_mods) 48 | { 49 | $admins_mods = []; 50 | } 51 | 52 | if ($forum_id) 53 | { 54 | // now get just the moderators of the forum 55 | $forum_mods = $this->auth->acl_get_list(false, 'm_', $forum_id); 56 | $forum_mods = (!empty($forum_mods[$forum_id]['m_'])) ? $forum_mods[$forum_id]['m_'] : []; 57 | 58 | // merge the arrays 59 | $admins_mods = array_unique(array_merge($admins_mods, $forum_mods)); 60 | 61 | } 62 | 63 | return $admins_mods; 64 | } 65 | 66 | /* 67 | * build_adminsmods_cache generate a cache of users who are admins and global mods 68 | * this is used in the listener as well as reporttosfs/reportpms files 69 | * @return null 70 | * @access public 71 | */ 72 | public function build_adminsmods_cache() 73 | { 74 | if (($this->cache->get('_sfs_adminsmods')) === false) 75 | { 76 | // Grab an array of user_id's with admin permissions 77 | $admin_ary = $this->auth->acl_get_list(false, 'a_', false); 78 | $admin_ary = (!empty($admin_ary[0]['a_'])) ? $admin_ary[0]['a_'] : []; 79 | 80 | // Grab an array of user id's with global mod permissions 81 | $mod_ary = $this->auth->acl_get_list(false,'m_', false); 82 | $mod_ary = (!empty($mod_ary[0]['m_'])) ? $mod_ary[0]['m_'] : []; 83 | 84 | $admins_mods = array_unique(array_merge($admin_ary, $mod_ary)); 85 | 86 | // cache this data for ever 87 | $this->cache->put('_sfs_adminsmods', $admins_mods); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /language/en/stopforumspam.php: -------------------------------------------------------------------------------- 1 | 'You are not allowed to report the anonymous account.', 40 | 'CANNOT_REPORT_ADMINS_MODS' => 'You can’t report admins or mods of this forum.', 41 | 'FORUM_NOT_EXIST' => 'The forum selected does not exist.', 42 | 'INFO_NOT_FOUND' => 'The combination of poster id and post id doesn’t exist.', 43 | 'POST_NOT_EXIST' => 'The post you requested does not exist.', 44 | 'NO_SOUP_FOR_YOU' => 'No soup for you! It looks like you have been flagged as a spammer.
    If you feel this decision was made in error %scontact the board admin%s.', 45 | 'NO_SOUP_FOR_YOU_NO_CONTACT' => 'No soup for you! It looks like you have been flagged as a spammer.', 46 | 'PM_NOT_EXIST' => 'PM doesn’t exist', 47 | 'SFS_ANONYMIZED_IP' => 'The IP of the user has been anonymized, set to 127.0.0.1, probably due to an extension.', 48 | 'SFS_MISSING_DATA' => 'Not all information is provided to report to Stop Forum Spam.', 49 | 'SFS_FREQUENCY' => ' » found in sfs database %d times', 50 | 'SFS_IP_STOPPED' => '%1$s', 51 | 'SFS_USERNAME_STOPPED' => '%1$s', 52 | 'SFS_EMAIL_STOPPED' => '%1$s', 53 | 'SFS_ERROR_MESSAGE' => 'Unfortunately we can’t process your request now due to problems with an external party. You can try again later.', 54 | 'SFS_BANNED' => [ 55 | 1 => 'Found in the Stop Forum Spam database once', 56 | 2 => 'Found in the Stop Forum Spam database %d times', 57 | ], 58 | 'SFS_MARKED_TOXIC' => ' » Email domain marked as TOXIC', 59 | 'SFS_USER_BANNED' => 'Banned due to a post on the forum', 60 | 'SFS_REPORTED' => 'Post has already been reported', 61 | 'SFS_PM_REPORTED' => 'PM has already been reported', 62 | 'REPORT_TO_SFS' => 'Report to Stop Forum Spam', 63 | 'BUTTON_SFS' => 'Report to SFS', 64 | 'SFS_SUCCESS_MESSAGE' => 'User was successfully reported to the stop forum database', 65 | 'SFS_WAS_REPORTED' => 'Post was reported to Stop Forum Spam', 66 | 'SFS_PM_WAS_REPORTED' => 'PM was reported to Stop Forum Spam', 67 | 'SFS_PM_REPORT_NOT_ALLOWED' => 'Reporting is not allowed', 68 | 'SFS_NEED_CURL' => 'The extension requires cURL which doesn’t seem to be installed', 69 | 'EXTENSION_REQUIREMENTS' => 'Extension requires at least phpBB version %1$s. You need to update your version of phpBB to utilize this extension.', 70 | 'CURL_REQUIREMENTS' => 'Extension requires cURL be installed and compiled with a valid ssl certificate on this server', 71 | 'CURL_ERROR' => 'cURL error', 72 | 'INVALID_IP_ADDRESS' => 'Invalid IP address', 73 | 'SFS_CONFIRM' => 'Report to stop forum database?', 74 | 'SFS_SUCCESS' => 'Stop forum spam successful', 75 | 'SFS_OPERATION_CANCELED' => 'Operation canceled', 76 | 'SFS_NOT_CHECKED' => ' » Parameter wasn’t checked per settings in extension', 77 | ]); 78 | -------------------------------------------------------------------------------- /core/sfsapi.php: -------------------------------------------------------------------------------- 1 | config = $config; 50 | $this->language = $language; 51 | $this->log = $log; 52 | $this->user = $user; 53 | $this->root_path = $root_path; 54 | $this->php_ext = $php_ext; 55 | } 56 | 57 | /* 58 | * sfsapi 59 | * @param $type whether we are adding or querying 60 | * @param $username the users name 61 | * @param $userip the users ip 62 | * @param $useremail the users email addy 63 | * @param $apikey the api key of the forum 64 | * @return bool|string return true on success or false on failure or string on curl error 65 | */ 66 | public function sfsapi($type, $username, $userip, $useremail, $evidence = '', $apikey = '') 67 | { 68 | // We'll use curl..most servers have it installed as default 69 | if (!function_exists('curl_init')) 70 | { 71 | // no cURL no extension 72 | $this->config->set('allow_sfs', false); 73 | 74 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_NEED_CURL'); 75 | 76 | return false; 77 | } 78 | 79 | if ($type == 'add') 80 | { 81 | $url = 'https://www.stopforumspam.com/add.php'; 82 | $data = [ 83 | 'username' => $username, 84 | 'ip' => $userip, 85 | 'email' => $useremail, 86 | 'evidence' => $evidence, 87 | 'api_key' => $apikey 88 | ]; 89 | 90 | $data = http_build_query($data); 91 | } 92 | else 93 | { 94 | $url = 'https://api.stopforumspam.org/api'; 95 | $data = [ 96 | 'username' => $username, 97 | 'email' => $useremail, 98 | 'ip' => $userip 99 | ]; 100 | 101 | $data = http_build_query($data); 102 | $data = $data . '&nobadusername&json'; 103 | } 104 | 105 | $ch = curl_init($url); 106 | 107 | curl_setopt_array($ch, [ 108 | CURLOPT_POST => 1, 109 | CURLOPT_POSTFIELDS => $data, 110 | CURLOPT_RETURNTRANSFER => true, 111 | CURLOPT_TIMEOUT => 5, 112 | CURLOPT_CONNECTTIMEOUT => 5, 113 | CURLOPT_FAILONERROR => true, //Required for HTTP error codes to be reported via our call to curl_error($ch)// 114 | ]); 115 | 116 | $contents = curl_exec($ch); 117 | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 118 | 119 | // if curl isn't set correctly on server 120 | if ($contents === false) 121 | { 122 | $error_message = array($this->language->lang('CURL_ERROR') => curl_error($ch)); 123 | // If there is a curl error, log the error 124 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_CURL_ERROR', false, [$error_message[$this->language->lang('CURL_ERROR')]]); 125 | } 126 | curl_close($ch); 127 | 128 | if (isset($error_message)) 129 | { 130 | return json_encode($error_message); 131 | } 132 | 133 | // if nothing is returned (SFS is down) 134 | if ($httpcode != 200) 135 | { 136 | return false; 137 | } 138 | 139 | if ($type == 'add' && $httpcode == 200) 140 | { 141 | return true; 142 | } 143 | 144 | // We made it this far, returns the results of the curl request 145 | return $contents; 146 | } 147 | 148 | /* 149 | * sfs_ban 150 | * @param $type ban by either IP or username 151 | * @param $user_info the users info of who we are banning 152 | * @return null 153 | */ 154 | public function sfs_ban($type, $user_info, $check = 0) 155 | { 156 | if (!function_exists('user_ban')) 157 | { 158 | include($this->root_path . 'includes/functions_user.' . $this->php_ext); 159 | } 160 | 161 | if ($this->config['sfs_ban_ip']) 162 | { 163 | $lang_display = ($type == 'user') ? $this->language->lang('SFS_USER_BANNED') : $this->language->lang('SFS_BANNED', (int) $check); 164 | $ban_reason = (!empty($this->config['sfs_ban_reason'])) ? $lang_display : ''; 165 | // ban the nub 166 | user_ban($type, $user_info, (int) $this->config['sfs_ban_time'], 0, false, $lang_display, $ban_reason); 167 | } 168 | return; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /language/en/acp/acp_stopforumspam.php: -------------------------------------------------------------------------------- 1 | 'Settings', 39 | 'SFS_ENABLED' => 'Enable Stop Forum Spam', 40 | 'SFS_ENABLED_EXPLAIN' => 'Enable or disable the extension. This applies to both user registration and guest posts.', 41 | 'SFS_THRESHOLD_SCORE' => 'Stop Forum Spam threshold', 42 | 'SFS_THRESHOLD_SCORE_EXPLAIN' => 'The extension will check against a threshold (e.g., the number of times a user name, email or IP address is found within the stop forum database). You can input any number between 1 and 99. The lower the number the greater the possibility of a false positive.', 43 | 'SFS_LOG_MESSAGE' => 'Log a message', 44 | 'SFS_LOG_MESSAGE_EXPLAIN' => 'If set as yes messages will be logged in the ACP in either the admin or user logs stating the action done.', 45 | 'SFS_BAN_IP' => 'Ban User', 46 | 'SFS_BAN_IP_EXPLAIN' => 'If set as yes the users IP or user name will be banned per the setting of “Length of ban”', 47 | 'SFS_BAN_REASON' => 'Display reason if banned', 48 | 'SFS_BAN_REASON_EXPLAIN' => 'If “Ban User” is set to yes, you can choose to display a message to the banned user or not.', 49 | 'SFS_DOWN' => 'Allow if Stop Forum Spam is down', 50 | 'SFS_DOWN_EXPLAIN' => 'Should registration/posting go through if the stop forum spam website is down', 51 | 'SFS_API_KEY' => 'Stop Forum Spam API key', 52 | 'SFS_API_KEY_EXPLAIN' => 'If you want to submit spammers to the Stop Forum Spam database, input your API key from stop forum spam here. You must be registered on the SFS website to get an API key', 53 | 'SFS_NEED_CACHE' => 'There is an API key but no cache was built for admins and mods. Please click the button to generate the cache for admins and mods otherwise they can be reported.', 54 | 'SFS_NOTIFY' => 'Board Notification', 55 | 'SFS_NOTIFY_EXPLAIN' => 'If set yes and there is an API key set above, then board notifications will also be triggered when a post is reported to stop forum spam', 56 | 'SFS_CLEAR' => 'Reset reported posts', 57 | 'SFS_CLEAR_EXPLAIN' => 'Will reset all posts ( %1s total ) and private messages ( %2s total ) reported to stop forum spam', 58 | 'SFS_CLEAR_SURE' => 'Clear SFS reports', 59 | 'SFS_CLEAR_SURE_CONFIRM' => 'Are you sure you want to clear all reported posts and private messages?', 60 | 'SFS_BUILD' => 'Build cache of Admins and Mods', 61 | 'SFS_BUILD_EXPLAIN' => 'Builds a cache of Admins and Global Mods for use when reporting to SFS', 62 | 'SFS_NEEDS_API' => 'To build the cache you need an API key from stop forum spam', 63 | // ACP messages 64 | 'SFS_BY_NAME' => 'Check against user name', 65 | 'SFS_BY_EMAIL' => 'Check against email', 66 | 'SFS_BY_IP' => 'Check against IP', 67 | 'SFS_ALLOW_PM_REPORT' => 'Allow reporting of PMs', 68 | 'SFS_PM_REPORT_EXPLAIN' => 'If you have an API key and allow this then any user can report a PM to stop forum spam. Your users maybe “indiscriminate” so it might be best if you leave this set to no.', 69 | 'TOO_SMALL_SFS_THRESHOLD' => 'The threshold value is too small.', 70 | 'TOO_LARGE_SFS_THRESHOLD' => 'The threshold value is too large.', 71 | 'SFS_SETTINGS_ERROR' => 'There was an error saving your settings. Please submit the back trace with your error report.', 72 | 'SFS_SETTINGS_SUCCESS' => 'The settings were successfully saved.', 73 | 'SFS_REPORTED_CLEARED' => 'Posts and private messages reported to stop forum spam were reset.', 74 | //Donation 75 | 'PAYPAL_IMAGE_URL' => 'https://www.paypalobjects.com/webstatic/en_US/i/btn/png/silver-pill-paypal-26px.png', 76 | 'PAYPAL_ALT' => 'Donate using PayPal', 77 | 'BUY_ME_A_BEER_URL' => 'https://paypal.me/RMcGirr83', 78 | 'BUY_ME_A_BEER' => 'Buy me a beer for creating this extension', 79 | 'BUY_ME_A_BEER_SHORT' => 'Make a donation for this extension', 80 | 'BUY_ME_A_BEER_EXPLAIN' => 'This extension is completely free. It is a project that I spend my time on for the enjoyment and use of the phpBB community. If you enjoy using this extension, or if it has benefited your forum, please consider buying me a beer. It would be greatly appreciated. ', 81 | 'SFS_CONTACTADMIN_EXT' => 'Allow on Contactadmin Extension', 82 | 'SFS_CONTACTADMIN_EXT_EXPLAIN' => 'If set yes and the contact admin extension is installed, this extension will integrate with the contact admin extension.' 83 | ]); 84 | -------------------------------------------------------------------------------- /adm/style/stopforumspam_body.html: -------------------------------------------------------------------------------- 1 | {% INCLUDE 'overall_header.html' %} 2 | 3 |

    {{ lang('SFS_CONTROL') }}

    4 |
    5 | {{ lang('BUY_ME_A_BEER') }} 6 |
    7 |

    {{ lang('BUY_ME_A_BEER_EXPLAIN') }}
    8 |
    {{ lang('PAYPAL_ALT') }}
    9 |
    10 |
    11 | {% if CURL_ACTIVE %} 12 |

    {{ lang('WARNING') }}

    13 |

    {{ CURL_ACTIVE }}

    14 |
    15 | {% endif %} 16 | {% if NOTICE %} 17 |
    18 |

    {{ NOTICE }}

    19 |
    20 | {% endif %} 21 | {% if ERROR %} 22 |

    {{ lang('WARNING') }}

    23 |

    {{ ERROR }}

    24 |
    25 | {% endif %} 26 | 27 |
    28 |
    29 |
    30 |
    31 |
    {{ lang('YES') }}   32 | {{ lang('NO') }}
    33 |
    34 |
    35 |
    36 |
    {{ lang('YES') }}   37 | {{ lang('NO') }}
    38 |
    39 |
    40 |
    41 |
    {{ lang('YES') }}   42 | {{ lang('NO') }}
    43 |
    44 |
    45 |
    46 |
    {{ lang('YES') }}   47 | {{ lang('NO') }}
    48 |
    49 |
    50 |

    {{ lang('SFS_THRESHOLD_SCORE_EXPLAIN') }}
    51 |
    52 |
    53 |
    54 |

    {{ lang('SFS_BAN_IP_EXPLAIN') }}
    55 |
    {{ lang('YES') }}   56 | {{ lang('NO') }}
    57 |
    58 |
    59 |
    60 |
    61 |
    62 |
    63 |

    {{ lang('SFS_BAN_REASON_EXPLAIN') }}
    64 |
    {{ lang('YES') }}   65 | {{ lang('NO') }}
    66 |
    67 |
    68 |

    {{ lang('SFS_LOG_MESSAGE_EXPLAIN') }}
    69 |
    {{ lang('YES') }}   70 | {{ lang('NO') }}
    71 |
    72 |
    73 |

    {{ lang('SFS_DOWN_EXPLAIN') }}
    74 |
    {{ lang('YES') }}   75 | {{ lang('NO') }}
    76 |
    77 |
    78 |

    {{ lang('SFS_API_KEY_EXPLAIN') }}
    79 |
    80 |
    81 |
    82 |

    {{ lang('SFS_PM_REPORT_EXPLAIN') }}
    83 |
    {{ lang('YES') }}   84 | {{ lang('NO') }}
    85 |
    86 |
    87 |

    {{ lang('SFS_NOTIFY_EXPLAIN') }}
    88 |
    {{ lang('YES') }}   89 | {{ lang('NO') }}
    90 |
    91 | {% if S_CONTACTADMIN %} 92 |
    93 |

    {{ lang('SFS_CONTACTADMIN_EXT_EXPLAIN') }}
    94 |
    {{ lang('YES') }}   95 | {{ lang('NO') }}
    96 |
    97 | {% endif %} 98 |

    99 |   100 | 101 |

    102 | {{ S_FORM_TOKEN }} 103 |
    104 |
    105 |
    106 | {% if SFS_POSTS_PMS_COUNT %} 107 |
    108 |

    {{ lang('SFS_CLEAR_EXPLAIN', POSTS_REPORTED, PMS_REPORTED) }}
    109 |
    {{ lang('RUN') }}
    110 |
    111 | {% endif %} 112 |
    113 |

    {{ lang('SFS_BUILD_EXPLAIN') }}
    114 |
    {{ lang('RUN') }}
    115 |
    116 |
    117 | {% INCLUDE 'overall_footer.html' %} 118 | -------------------------------------------------------------------------------- /core/report_pm_to_sfs.php: -------------------------------------------------------------------------------- 1 | config = $config; 81 | $this->db = $db; 82 | $this->helper = $helper; 83 | $this->language = $language; 84 | $this->log = $log; 85 | $this->request = $request; 86 | $this->template = $template; 87 | $this->user = $user; 88 | $this->sfsgroups = $sfsgroups; 89 | $this->sfsapi = $sfsapi; 90 | $this->container = $container; 91 | } 92 | 93 | /* 94 | * report_pm_to_sfs 95 | * @param int $postid the pm msgid 96 | * @param int $posterid the author id of the pm 97 | * @return json response 98 | */ 99 | public function report_pm_to_sfs($postid, $posterid) 100 | { 101 | $postid = (int) $postid; 102 | $posterid = (int) $posterid; 103 | 104 | $this->language->add_lang('stopforumspam', 'rmcgirr83/stopforumspam'); 105 | 106 | $admins_mods = $this->sfsgroups->getadminsmods(0); 107 | 108 | // Check if reporting PMs is enabled 109 | if (!$this->config['allow_pm_report'] || in_array($posterid, $admins_mods) || empty($this->config['sfs_report_pm'])) 110 | { 111 | throw new http_exception(403, 'SFS_PM_REPORT_NOT_ALLOWED'); 112 | } 113 | 114 | if (empty($this->config['allow_sfs']) || empty($this->config['sfs_api_key'])) 115 | { 116 | throw new http_exception(403, 'SFS_MISSING_DATA'); 117 | } 118 | 119 | // postid must be greater than 0 120 | if ($postid <= 0) 121 | { 122 | throw new http_exception(403, 'PM_NOT_EXIST'); 123 | } 124 | 125 | $sql = 'SELECT pm.sfs_reported, pm.author_id, pm.author_ip, u.username, u.user_email 126 | FROM ' . PRIVMSGS_TABLE . ' pm 127 | LEFT JOIN ' . USERS_TABLE . ' u on pm.author_id = u.user_id 128 | WHERE pm.msg_id = ' . (int) $postid . ' AND pm.author_id = ' . (int) $posterid; 129 | $result = $this->db->sql_query($sql); 130 | $row = $this->db->sql_fetchrow($result); 131 | $this->db->sql_freeresult($result); 132 | 133 | // info must exist 134 | if (!$row) 135 | { 136 | throw new http_exception(403, 'INFO_NOT_FOUND'); 137 | } 138 | 139 | $username = $row['username']; 140 | $userip = $row['author_ip']; 141 | $useremail = $row['user_email']; 142 | $sfs_reported = (int) $row['sfs_reported']; 143 | 144 | // ensure the IP is something other than 127.0.0.1 which can happen if the anonymised extension is installed 145 | if (filter_var($userip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === false) 146 | { 147 | throw new http_exception(403, 'SFS_ANONYMIZED_IP'); 148 | } 149 | 150 | if ($sfs_reported) 151 | { 152 | throw new http_exception(403, 'SFS_PM_REPORTED'); 153 | } 154 | 155 | // fix confirm box non-ajax error (controller must return) 156 | if ($this->request->is_set_post('cancel') && !$this->request->is_ajax()) 157 | { 158 | return $this->helper->message('SFS_OPERATION_CANCELED'); 159 | } 160 | 161 | if (confirm_box(true)) 162 | { 163 | $response = $this->sfsapi->sfsapi('add', $username, $userip, $useremail, $this->config['sfs_api_key']); 164 | 165 | if (!$response && $this->request->is_ajax()) 166 | { 167 | $data = [ 168 | 'MESSAGE_TITLE' => $this->user->lang('ERROR'), 169 | 'MESSAGE_TEXT' => $this->user->lang('SFS_ERROR_MESSAGE'), 170 | 'success' => false, 171 | ]; 172 | return new JsonResponse($data); 173 | } 174 | else if (!$response) 175 | { 176 | $this->template->assign_vars([ 177 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'), 178 | 'MESSAGE_TEXT' => $this->language->lang('SFS_ERROR_MESSAGE') 179 | ]); 180 | 181 | return $this->helper->render('message_body.html'); 182 | } 183 | 184 | // Report the uhmmm reported? 185 | if ($this->config['sfs_notify']) 186 | { 187 | $this->check_report($postid); 188 | } 189 | 190 | $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' 191 | SET sfs_reported = 1 192 | WHERE msg_id = ' . (int) $postid; 193 | $this->db->sql_query($sql); 194 | 195 | $sfs_username = $this->language->lang('SFS_USERNAME_STOPPED', $username); 196 | 197 | $this->log->add('mod', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_PM_REPORTED', false, [$sfs_username, 'msg_id' => $postid]); 198 | 199 | if ($this->request->is_ajax()) 200 | { 201 | $data = [ 202 | 'MESSAGE_TITLE' => $this->language->lang('SFS_SUCCESS'), 203 | 'MESSAGE_TEXT' => $this->language->lang('SFS_SUCCESS_MESSAGE'), 204 | 'success' => true, 205 | 'postid' => $postid, 206 | ]; 207 | 208 | return new JsonResponse($data); 209 | } 210 | else 211 | { 212 | $this->template->assign_vars([ 213 | 'MESSAGE_TITLE' => $this->language->lang('SFS_SUCCESS'), 214 | 'MESSAGE_TEXT' => $this->language->lang('SFS_SUCCESS_MESSAGE') 215 | ]); 216 | 217 | return $this->helper->render('message_body.html'); 218 | } 219 | } 220 | else 221 | { 222 | if ($this->request->is_ajax()) 223 | { 224 | confirm_box( 225 | false, 226 | $this->language->lang('SFS_CONFIRM'), 227 | '', 228 | 'confirm_body.html', 229 | $this->helper->route( 230 | 'rmcgirr83_stopforumspam_core_report_pm_to_sfs', 231 | [ 232 | 'postid' => $postid, 233 | 'posterid' => $posterid, 234 | ], 235 | true, 236 | false, 237 | UrlGeneratorInterface::ABSOLUTE_URL 238 | ) 239 | ); 240 | } 241 | else 242 | { 243 | confirm_box(false, $this->language->lang('SFS_CONFIRM')); 244 | } 245 | } 246 | } 247 | 248 | /* 249 | * check_report check to see if the PM msg has already been reported 250 | * @param int $msg_id msg_id from the report to sfs 251 | * @return json response if found 252 | */ 253 | private function check_report($msg_id) 254 | { 255 | $sql = 'SELECT * 256 | FROM ' . PRIVMSGS_TABLE . ' 257 | WHERE msg_id = ' . (int) $msg_id; 258 | $result = $this->db->sql_query($sql); 259 | $report_data = $this->db->sql_fetchrow($result); 260 | $this->db->sql_freeresult($result); 261 | 262 | if (!$report_data && $this->request->is_ajax()) 263 | { 264 | $data = [ 265 | 'MESSAGE_TITLE' => $this->user->lang('ERROR'), 266 | 'MESSAGE_TEXT' => $this->user->lang('PM_NOT_EXIST'), 267 | 'success' => false, 268 | ]; 269 | return new JsonResponse($data); 270 | } 271 | else if (!$report_data) 272 | { 273 | $this->template->assign_vars([ 274 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'), 275 | 'MESSAGE_TEXT' => $this->language->lang('PM_NOT_EXIST'), 276 | ]); 277 | 278 | return $this->helper->render('message_body.html'); 279 | } 280 | 281 | // if the pm isn't reported, then report it 282 | if (!$report_data['message_reported']) 283 | { 284 | $report_name = 'other'; 285 | $report_text = $this->user->lang('SFS_PM_WAS_REPORTED'); 286 | 287 | $sql = 'SELECT * 288 | FROM ' . REPORTS_REASONS_TABLE . " 289 | WHERE reason_title = '" . $this->db->sql_escape($report_name). "'"; 290 | $result = $this->db->sql_query($sql); 291 | $row = $this->db->sql_fetchrow($result); 292 | $this->db->sql_freeresult($result); 293 | 294 | $phpbb_notifications = $this->container->get('phpbb.report.handlers.report_handler_pm'); 295 | $phpbb_notifications->add_report($msg_id, $row['reason_id'], $report_text, 0); 296 | } 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /core/reporttosfs.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 94 | $this->config = $config; 95 | $this->helper = $helper; 96 | $this->db = $db; 97 | $this->language = $language; 98 | $this->log = $log; 99 | $this->request = $request; 100 | $this->template = $template; 101 | $this->user = $user; 102 | $this->sfsgroups = $sfsgroups; 103 | $this->sfsapi = $sfsapi; 104 | $this->container = $container; 105 | $this->root_path = $root_path; 106 | $this->php_ext = $php_ext; 107 | } 108 | 109 | /* 110 | * reporttosfs reporting of post to stopforum database 111 | * @param int $postid postid of the post 112 | * @param int $posterid posterid that made the post 113 | * @return json response 114 | */ 115 | public function reporttosfs($postid, $posterid) 116 | { 117 | $postid = (int) $postid; 118 | $posterid = (int) $posterid; 119 | 120 | // don't allow banning of anonymous user 121 | if ($posterid == ANONYMOUS) 122 | { 123 | throw new http_exception(403, 'CANNOT_REPORT_ANONYMOUS'); 124 | } 125 | 126 | // post id must be greater than 0 127 | if ($postid <= 0) 128 | { 129 | throw new http_exception(403, 'POST_NOT_EXIST'); 130 | } 131 | 132 | $sql = 'SELECT p.*, u.username, u.user_email 133 | FROM ' . POSTS_TABLE . ' p 134 | LEFT JOIN ' . USERS_TABLE . ' u on p.poster_id = u.user_id 135 | WHERE p.post_id = ' . (int) $postid . ' AND p.poster_id = ' . (int) $posterid; 136 | $result = $this->db->sql_query($sql); 137 | $row = $this->db->sql_fetchrow($result); 138 | $this->db->sql_freeresult($result); 139 | 140 | // info must exist 141 | if (!$row) 142 | { 143 | throw new http_exception(403, 'INFO_NOT_FOUND'); 144 | } 145 | 146 | if (!function_exists('generate_text_for_display')) 147 | { 148 | include($this->root_path . 'includes/functions_privmsgs.' . $this->php_ext); 149 | } 150 | $username = $row['username']; 151 | $userip = $row['poster_ip']; 152 | $useremail = $row['user_email']; 153 | $forumid = (int) $row['forum_id']; 154 | $topicid = (int) $row['topic_id']; 155 | $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0); 156 | $parse_flags |= ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0); 157 | $evidence = generate_text_for_display($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, true); 158 | $sfs_reported = (int) $row['sfs_reported']; 159 | 160 | $admins_mods = $this->sfsgroups->getadminsmods($forumid); 161 | 162 | if (in_array($posterid, $admins_mods)) 163 | { 164 | throw new http_exception(403, 'CANNOT_REPORT_ADMINS_MODS'); 165 | } 166 | 167 | // ensure the IP is something other than 127.0.0.1 which can happen if the anonymised extension is installed 168 | if (filter_var($userip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === false) 169 | { 170 | throw new http_exception(403, 'SFS_ANONYMIZED_IP'); 171 | } 172 | 173 | if ($sfs_reported) 174 | { 175 | throw new http_exception(403, 'SFS_REPORTED'); 176 | } 177 | 178 | if (empty($this->config['allow_sfs']) || empty($this->config['sfs_api_key']) || empty($useremail) || empty($userip)) 179 | { 180 | throw new http_exception(403, 'SFS_MISSING_DATA'); 181 | } 182 | 183 | // fix confirm box non-ajax error (controller must return) 184 | if ($this->request->is_set_post('cancel') && !$this->request->is_ajax()) 185 | { 186 | $message = $this->language->lang('SFS_OPERATION_CANCELED') . '

    ' . $this->language->lang('RETURN_TOPIC', 'root_path}viewtopic.$this->php_ext?t=" . $topicid) . '">', ''); 187 | 188 | return $this->helper->message($message); 189 | } 190 | 191 | if (confirm_box(true)) 192 | { 193 | $response = $this->sfsapi->sfsapi('add', $username, $userip, $useremail, $evidence, $this->config['sfs_api_key']); 194 | 195 | $json_decode = json_decode($response, true); 196 | // ajax stuffs 197 | if (isset($json_decode[$this->language->lang('CURL_ERROR')]) && $this->request->is_ajax()) 198 | { 199 | $data = [ 200 | 'MESSAGE_TITLE' => $this->language->lang('AJAX_ERROR_TITLE'), 201 | 'MESSAGE_TEXT' => $json_decode[$this->language->lang('CURL_ERROR')], 202 | 'success' => false, 203 | ]; 204 | return new JsonResponse($data); 205 | } 206 | else if (!$response && $this->request->is_ajax()) 207 | { 208 | $data = [ 209 | 'MESSAGE_TITLE' => $this->language->lang('AJAX_ERROR_TITLE'), 210 | 'MESSAGE_TEXT' => $this->language->lang('SFS_ERROR_MESSAGE'), 211 | 'success' => false, 212 | ]; 213 | return new JsonResponse($data); 214 | } 215 | //non-ajax stuffs 216 | else if (isset($json_decode[$this->language->lang('CURL_ERROR')])) 217 | { 218 | $this->template->assign_vars([ 219 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'), 220 | 'MESSAGE_TEXT' => $json_decode[$this->language->lang('CURL_ERROR')] 221 | ]); 222 | 223 | return $this->helper->render('message_body.html'); 224 | } 225 | else if (!$response) 226 | { 227 | $this->template->assign_vars([ 228 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'), 229 | 'MESSAGE_TEXT' => $this->language->lang('SFS_ERROR_MESSAGE') 230 | ]); 231 | 232 | return $this->helper->render('message_body.html'); 233 | } 234 | 235 | // Report the uhmmm reported? 236 | if ($this->config['sfs_notify']) 237 | { 238 | $this->check_report($postid); 239 | } 240 | 241 | $sql = 'UPDATE ' . POSTS_TABLE . ' 242 | SET sfs_reported = 1 243 | WHERE post_id = ' . (int) $postid; 244 | $this->db->sql_query($sql); 245 | 246 | $sfs_username = $this->language->lang('SFS_USERNAME_STOPPED', $username); 247 | 248 | $this->sfsapi->sfs_ban('user', $username); 249 | 250 | $this->log->add('mod', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_REPORTED', false, [$sfs_username, 'forum_id' => $forumid, 'topic_id' => $topicid, 'post_id' => $postid]); 251 | 252 | if ($this->request->is_ajax()) 253 | { 254 | $data = [ 255 | 'MESSAGE_TITLE' => $this->language->lang('SFS_SUCCESS'), 256 | 'MESSAGE_TEXT' => $this->language->lang('SFS_SUCCESS_MESSAGE'), 257 | 'success' => true, 258 | 'postid' => $postid, 259 | ]; 260 | return new JsonResponse($data); 261 | } 262 | else 263 | { 264 | $this->template->assign_vars([ 265 | 'MESSAGE_TITLE' => $this->language->lang('SFS_SUCCESS'), 266 | 'MESSAGE_TEXT' => $this->language->lang('SFS_SUCCESS_MESSAGE') 267 | ]); 268 | 269 | return $this->helper->render('message_body.html'); 270 | } 271 | } 272 | else 273 | { 274 | if ($this->request->is_ajax()) 275 | { 276 | confirm_box( 277 | false, 278 | $this->language->lang('SFS_CONFIRM'), 279 | '', 280 | 'confirm_body.html', 281 | $this->helper->route( 282 | 'rmcgirr83_stopforumspam_core_reporttosfs', 283 | [ 284 | 'postid' => $postid, 285 | 'posterid' => $posterid, 286 | ], 287 | true, 288 | false, 289 | UrlGeneratorInterface::ABSOLUTE_URL 290 | ) 291 | ); 292 | } 293 | else 294 | { 295 | confirm_box(false, $this->language->lang('SFS_CONFIRM')); 296 | } 297 | } 298 | } 299 | 300 | /* 301 | * check_report check to see if the post msg has already been reported 302 | * @param $postid postid from the report to sfs 303 | * @return json|html response if found 304 | */ 305 | private function check_report($postid) 306 | { 307 | $sql = 'SELECT * 308 | FROM ' . POSTS_TABLE . ' 309 | WHERE post_id = ' . (int) $postid; 310 | $result = $this->db->sql_query($sql); 311 | $report_data = $this->db->sql_fetchrow($result); 312 | $this->db->sql_freeresult($result); 313 | 314 | if (!$report_data && $this->request->is_ajax()) 315 | { 316 | $data = [ 317 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'), 318 | 'MESSAGE_TEXT' => $this->language->lang('POST_NOT_EXIST'), 319 | 'success' => false, 320 | ]; 321 | return new JsonResponse($data); 322 | } 323 | else if (!$report_data) 324 | { 325 | $this->template->assign_vars([ 326 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'), 327 | 'MESSAGE_TEXT' => $this->language->lang('POST_NOT_EXIST'), 328 | ]); 329 | 330 | return $this->helper->render('message_body.html'); 331 | } 332 | 333 | // if the post isn't reported, then report it 334 | if (!$report_data['post_reported']) 335 | { 336 | $report_name = 'other'; 337 | $report_text = $this->language->lang('SFS_WAS_REPORTED'); 338 | 339 | $sql = 'SELECT * 340 | FROM ' . REPORTS_REASONS_TABLE . " 341 | WHERE reason_title = '" . $this->db->sql_escape($report_name). "'"; 342 | $result = $this->db->sql_query($sql); 343 | $row = $this->db->sql_fetchrow($result); 344 | $this->db->sql_freeresult($result); 345 | 346 | $phpbb_notifications = $this->container->get('phpbb.report.handlers.report_handler_post'); 347 | $phpbb_notifications->add_report($postid, $row['reason_id'], $report_text, 0); 348 | } 349 | } 350 | } 351 | -------------------------------------------------------------------------------- /controller/admin_controller.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 104 | $this->config = $config; 105 | $this->db = $db; 106 | $this->language = $language; 107 | $this->log = $log; 108 | $this->request = $request; 109 | $this->template = $template; 110 | $this->user = $user; 111 | $this->sfsgroups = $sfsgroups; 112 | $this->root_path = $root_path; 113 | $this->php_ext = $php_ext; 114 | $this->contactadmin = $contactadmin; 115 | } 116 | 117 | /** 118 | * Display the options a user can configure for this extension 119 | * 120 | * @return null 121 | * @access public 122 | */ 123 | public function display_options() 124 | { 125 | // Add the language files 126 | $this->language->add_lang('acp/acp_stopforumspam', 'rmcgirr83/stopforumspam'); 127 | $this->language->add_lang('acp/ban'); 128 | 129 | $action = $this->request->variable('action', ''); 130 | 131 | add_form_key('sfs'); 132 | $curl_active = $this->allow_sfs(); 133 | 134 | $cache_built = ''; 135 | if (!$this->cache->get('_sfs_adminsmods') && $this->config['sfs_api_key']) 136 | { 137 | $cache_built = $this->language->lang('SFS_NEED_CACHE'); 138 | } 139 | 140 | $sql = 'SELECT COUNT(sfs_reported) AS stat 141 | FROM ' . POSTS_TABLE . ' 142 | WHERE sfs_reported = 1'; 143 | $result = $this->db->sql_query($sql); 144 | $row = $this->db->sql_fetchfield('stat'); 145 | $this->db->sql_freeresult($result); 146 | 147 | $posts_reported = $row; 148 | 149 | $sql = 'SELECT COUNT(sfs_reported) AS stat 150 | FROM ' . PRIVMSGS_TABLE . ' 151 | WHERE sfs_reported = 1'; 152 | $result = $this->db->sql_query($sql); 153 | $row = $this->db->sql_fetchfield('stat'); 154 | $this->db->sql_freeresult($result); 155 | 156 | $pms_reported = $row; 157 | 158 | $sfs_posts_pms_count = (int) $posts_reported + (int) $pms_reported; 159 | 160 | switch ($action) 161 | { 162 | case 'sfsclrreports': 163 | //if none have been reported there's nothing to do 164 | if (empty($sfs_posts_pms_count)) 165 | { 166 | return false; 167 | } 168 | 169 | if (confirm_box(true)) 170 | { 171 | $this->sfsclrreports(); 172 | } 173 | else 174 | { 175 | confirm_box(false, 'SFS_CLEAR_SURE'); 176 | } 177 | break; 178 | 179 | case 'build_adminsmods': 180 | 181 | $this->build_adminsmods(); 182 | 183 | break; 184 | } 185 | 186 | if ($this->request->is_set_post('submit')) 187 | { 188 | // Test if the submitted form is valid 189 | if (!check_form_key('sfs')) 190 | { 191 | trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action)); 192 | } 193 | 194 | if (!function_exists('validate_data')) 195 | { 196 | include($this->root_path . 'includes/functions_user.' . $this->php_ext); 197 | } 198 | 199 | $has_api_key = $this->request->variable('sfs_api_key', '', true); 200 | 201 | $check_row = ['sfs_threshold' => $this->request->variable('sfs_threshold', 0)]; 202 | $validate_row = ['sfs_threshold' => ['num', false, 1, 99]]; 203 | $error = validate_data($check_row, $validate_row); 204 | 205 | if (!sizeof($error)) 206 | { 207 | if (!empty($has_api_key)) 208 | { 209 | $this->sfsgroups->build_adminsmods_cache(); 210 | } 211 | 212 | // Set the options the user configured 213 | $this->set_options(); 214 | 215 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_CONFIG_SAVED'); 216 | 217 | trigger_error($this->language->lang('SFS_SETTINGS_SUCCESS') . adm_back_link($this->u_action)); 218 | } 219 | } 220 | 221 | $this->template->assign_vars([ 222 | 'ERROR' => isset($error) ? ((sizeof($error)) ? implode('
    ', $error) : '') : '', 223 | 'SFS_API_KEY' => $this->config['sfs_api_key'], 224 | 'ALLOW_SFS' => ($this->config['allow_sfs'] && $curl_active) ? true : false, 225 | 'CURL_ACTIVE' => (!$curl_active) ? $this->language->lang('LOG_SFS_NEED_CURL') : false, 226 | 'SFS_THRESHOLD' => (int) $this->config['sfs_threshold'], 227 | 'SFS_BAN_IP' => ($this->config['sfs_ban_ip']) ? true : false, 228 | 'SFS_LOG_MESSAGE' => ($this->config['sfs_log_message']) ? true : false, 229 | 'SFS_DOWN' => ($this->config['sfs_down']) ? true : false, 230 | 'SFS_BY_NAME' => ($this->config['sfs_by_name']) ? true : false, 231 | 'SFS_BY_EMAIL' => ($this->config['sfs_by_email']) ? true : false, 232 | 'SFS_BY_IP' => ($this->config['sfs_by_ip']) ? true : false, 233 | 'SFS_BAN_REASON' => ($this->config['sfs_ban_reason']) ? true : false, 234 | 'SFS_REPORT_PM' => ($this->config['sfs_report_pm']) ? true : false, 235 | 'SFS_BAN_TIME' => $this->display_ban_time($this->config['sfs_ban_time']), 236 | 'SFS_NOTIFY' => ($this->config['sfs_notify']) ? true : false, 237 | 'SFS_POSTS_PMS_COUNT' => $sfs_posts_pms_count, 238 | 'SFS_CONTACTADMIN' => ($this->config['sfs_contactadmin']) ? true : false, 239 | 'NOTICE' => $cache_built, 240 | 'POSTS_REPORTED' => (int) $posts_reported, 241 | 'PMS_REPORTED' => (int) $pms_reported, 242 | 'S_CONTACTADMIN' => ($this->contactadmin) ? true : false, 243 | 244 | 'U_BUILD_CACHE' => $this->u_action . '&action=build_adminsmods', 245 | 'U_CLR_REPORTS' => $this->u_action . '&action=sfsclrreports', 246 | 'U_ACTION' => $this->u_action, 247 | ]); 248 | } 249 | 250 | /** 251 | * Set the options a user can configure 252 | * 253 | * @return void 254 | * @access protected 255 | */ 256 | protected function set_options() 257 | { 258 | $this->config->set('sfs_threshold', $this->request->variable('sfs_threshold', 0)); 259 | $this->config->set('allow_sfs', $this->request->variable('allow_sfs', 0)); 260 | $this->config->set('sfs_ban_ip', $this->request->variable('sfs_ban_ip', 0)); 261 | $this->config->set('sfs_log_message', $this->request->variable('sfs_log_message', 0)); 262 | $this->config->set('sfs_down', $this->request->variable('sfs_down', 0)); 263 | $this->config->set('sfs_by_name', $this->request->variable('sfs_by_name', 0)); 264 | $this->config->set('sfs_by_email', $this->request->variable('sfs_by_email', 0)); 265 | $this->config->set('sfs_by_ip', $this->request->variable('sfs_by_ip', 0)); 266 | $this->config->set('sfs_ban_reason', $this->request->variable('sfs_ban_reason', 0)); 267 | $this->config->set('sfs_api_key', $this->request->variable('sfs_api_key', '', true)); 268 | $this->config->set('sfs_ban_time', $this->request->variable('sfs_ban_time', 0)); 269 | $this->config->set('sfs_notify', $this->request->variable('sfs_notify', 0)); 270 | $this->config->set('sfs_report_pm', $this->request->variable('sfs_report_pm', 0)); 271 | $this->config->set('sfs_contactadmin', $this->request->variable('sfs_contactadmin', 0)); 272 | } 273 | 274 | /** 275 | * Ensure cURL is active on server 276 | * 277 | * @return bool 278 | * @access protected 279 | */ 280 | protected function allow_sfs() 281 | { 282 | // Determine if cURL is enabled on the server 283 | $curl = false; 284 | if (function_exists('curl_init')) 285 | { 286 | $curl = true; 287 | } 288 | 289 | if (!$curl) 290 | { 291 | $this->config->set('allow_sfs', false); 292 | } 293 | 294 | return $curl; 295 | } 296 | /** 297 | * Generate a select of ban time options 298 | * 299 | * @return string 300 | * @access protected 301 | */ 302 | protected function display_ban_time($ban_time = 0) 303 | { 304 | // Ban length options 305 | $ban_text = [0 => $this->language->lang('PERMANENT'), 30 => $this->language->lang('30_MINS'), 60 => $this->language->lang('1_HOUR'), 360 => $this->language->lang('6_HOURS'), 1440 => $this->language->lang('1_DAY'), 10080 => $this->language->lang('7_DAYS'), 20160 => $this->language->lang('2_WEEKS'), 40320 => $this->language->lang('1_MONTH'), 524160 => $this->language->lang('1_YEAR')]; 306 | 307 | $ban_options = ''; 308 | foreach ($ban_text as $length => $text) 309 | { 310 | $selected = ($length == $ban_time) ? ' selected="selected"' : ''; 311 | $ban_options .= ""; 312 | } 313 | 314 | return $ban_options; 315 | } 316 | 317 | /** 318 | * Clear reported posts and pms 319 | * 320 | * @return json response 321 | * @access protected 322 | */ 323 | protected function sfsclrreports() 324 | { 325 | $sql = 'UPDATE ' . POSTS_TABLE . ' SET sfs_reported = 0 326 | WHERE sfs_reported = 1'; 327 | $this->db->sql_query($sql); 328 | 329 | $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET sfs_reported = 0 330 | WHERE sfs_reported = 1'; 331 | $this->db->sql_query($sql); 332 | 333 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_REPORTED_CLEARED'); 334 | 335 | $data = [ 336 | 'MESSAGE_TITLE' => $this->language->lang('SUCCESS'), 337 | 'MESSAGE_TEXT' => $this->language->lang('SFS_REPORTED_CLEARED'), 338 | 'success' => true, 339 | ]; 340 | 341 | $json_response = new json_response; 342 | $json_response->send($data); 343 | } 344 | 345 | /** 346 | * Generate admin and mods cache 347 | * 348 | * @return json response 349 | * @access protected 350 | */ 351 | protected function build_adminsmods() 352 | { 353 | if (empty($this->config['sfs_api_key'])) 354 | { 355 | trigger_error('SFS_NEEDS_API'); 356 | } 357 | 358 | $this->sfsgroups->build_adminsmods_cache(); 359 | 360 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ADMINSMODS_CACHE_BUILT'); 361 | 362 | $data = [ 363 | 'MESSAGE_TITLE' => $this->language->lang('SUCCESS'), 364 | 'MESSAGE_TEXT' => $this->language->lang('LOG_ADMINSMODS_CACHE_BUILT'), 365 | 'success' => true, 366 | ]; 367 | 368 | $json_response = new json_response; 369 | $json_response->send($data); 370 | } 371 | 372 | /** 373 | * Set page url 374 | * 375 | * @param string $u_action Custom form action 376 | * @return null 377 | * @access public 378 | */ 379 | public function set_page_url($u_action) 380 | { 381 | $this->u_action = $u_action; 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /event/main_listener.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 92 | $this->cache = $cache; 93 | $this->config = $config; 94 | $this->helper = $helper; 95 | $this->language = $language; 96 | $this->log = $log; 97 | $this->request = $request; 98 | $this->template = $template; 99 | $this->user = $user; 100 | $this->sfsgroups = $sfsgroups; 101 | $this->sfsapi = $sfsapi; 102 | $this->root_path = $root_path; 103 | $this->php_ext = $php_ext; 104 | $this->contactadmin = $contactadmin; 105 | } 106 | 107 | static public function getSubscribedEvents() 108 | { 109 | return [ 110 | 'core.user_setup_after' => 'user_setup_after', 111 | 'core.ucp_register_data_after' => 'user_sfs_validate_registration', 112 | 'core.posting_modify_template_vars' => 'poster_data_email', 113 | 'core.posting_modify_message_text' => 'poster_modify_message_text', 114 | 'core.posting_modify_submission_errors' => 'user_sfs_validate_posting', 115 | 'core.group_add_user_after' => 'update_sfs_admin_mods', 116 | 'core.group_delete_user_after' => 'update_sfs_admin_mods', 117 | // report to sfs? 118 | 'core.viewtopic_before_f_read_check' => 'viewtopic_before_f_read_check', 119 | 'core.viewtopic_post_rowset_data' => 'viewtopic_post_rowset_data', 120 | 'core.viewtopic_modify_post_row' => 'viewtopic_modify_post_row', 121 | 'core.ucp_pm_view_message' => 'ucp_pm_view_message', 122 | // Custom events for integration with Contact Admin Extension 123 | 'rmcgirr83.contactadmin.modify_data_and_error' => 'user_sfs_validate_registration', 124 | // phpBB default contact us page 125 | 'core.message_admin_form_submit_before' => 'message_admin_form_submit_before', 126 | ]; 127 | } 128 | 129 | /** 130 | * Check for and create if needed admins and mods cache 131 | * 132 | * @param object $event The event object 133 | * @return void 134 | * @access public 135 | */ 136 | public function user_setup_after($event) 137 | { 138 | $this->language->add_lang(['sfs_mcp', 'stopforumspam'], 'rmcgirr83/stopforumspam'); 139 | $this->sfsgroups->build_adminsmods_cache(); 140 | } 141 | 142 | /* 143 | * user_sfs_validate_registration validate a users registration event 144 | * 145 | * @param $event the event object 146 | * @return null 147 | * @access public 148 | */ 149 | public function user_sfs_validate_registration($event) 150 | { 151 | if ($this->config['allow_sfs'] == false) 152 | { 153 | return false; 154 | } 155 | 156 | if ($this->user->page['page_name'] == 'app.' . $this->php_ext . '/contactadmin' && !$this->config['sfs_contactadmin']) 157 | { 158 | return false; 159 | } 160 | 161 | $error_array = $event['error']; 162 | 163 | // validate the user ip 164 | $userip_error = $this->validate_ip($this->user->ip); 165 | if ($userip_error) 166 | { 167 | $error_array[] = $userip_error; 168 | } 169 | 170 | /* On registration and only when all errors have cleared 171 | * do not want the admin message area to fill up 172 | */ 173 | if (!sizeof($error_array)) 174 | { 175 | $check = $this->stopforumspam_check($event['data']['username'], $this->user->ip, $event['data']['email']); 176 | 177 | if ($check) 178 | { 179 | if ($this->config['sfs_down'] && $check === 'sfs_down') 180 | { 181 | return; 182 | } 183 | $error_array[] = $this->show_message($check); 184 | // now ban the spammer by IP 185 | if (is_int($check) && $this->config['sfs_ban_ip']) 186 | { 187 | $this->sfsapi->sfs_ban('ip', $this->user->ip, (int) $check); 188 | } 189 | } 190 | } 191 | $event['error'] = $error_array; 192 | } 193 | 194 | /* 195 | * poster_data_email inject email address into posting if allowed for guests 196 | * 197 | * @param $event the event object 198 | * @return void 199 | * @access public 200 | */ 201 | public function poster_data_email($event) 202 | { 203 | if ($this->user->data['user_id'] == ANONYMOUS && $this->config['allow_sfs']) 204 | { 205 | // Output the data vars to the template 206 | $this->template->assign_vars([ 207 | 'SFS' => true, 208 | 'EMAIL' => $this->request->variable('email', ''), 209 | ]); 210 | } 211 | } 212 | 213 | /* 214 | * poster_modify_message_text inject email address into post data for validation 215 | * 216 | * @param $event the event object 217 | * @return void 218 | * @access public 219 | */ 220 | public function poster_modify_message_text($event) 221 | { 222 | if ($event['mode'] == 'post' && $this->user->data['user_id'] == ANONYMOUS && $this->config['allow_sfs']) 223 | { 224 | $event['post_data'] = array_merge($event['post_data'], [ 225 | 'email' => strtolower($this->request->variable('email', '')), 226 | 'username' => strtolower($this->request->variable('username', '')), 227 | 'user_ip' => $this->user->ip 228 | ]); 229 | } 230 | } 231 | 232 | /* 233 | * user_sfs_validate_posting validate username and email for guest posting 234 | * 235 | * @param $event the event object 236 | * @return void 237 | * @access public 238 | */ 239 | public function user_sfs_validate_posting($event) 240 | { 241 | $error_array = $event['error']; 242 | 243 | if ($this->user->data['user_id'] == ANONYMOUS && $this->config['allow_sfs']) 244 | { 245 | $this->language->add_lang('ucp'); 246 | 247 | if (!function_exists('phpbb_validate_email')) 248 | { 249 | include($this->root_path . 'includes/functions_user.' . $this->php_ext); 250 | } 251 | 252 | // ensure email is populated on posting 253 | $error = $this->validate_email($event['post_data']['email']); 254 | if ($error) 255 | { 256 | $error_array[] = $this->language->lang($error . '_EMAIL'); 257 | } 258 | // I just hate empty usernames for guest posting 259 | if (empty($event['post_data']['username'])) 260 | { 261 | $username_error = $this->validate_username($event['post_data']['username']); 262 | if ($username_error) 263 | { 264 | $error_array[] = $username_error; 265 | } 266 | } 267 | 268 | // validate the user ip 269 | $userip_error = $this->validate_ip($event['post_data']['user_ip']); 270 | if ($userip_error) 271 | { 272 | $error_array[] = $userip_error; 273 | } 274 | 275 | if (!sizeof($error_array)) 276 | { 277 | $check = $this->stopforumspam_check($event['post_data']['username'], $this->user->ip, $event['post_data']['email']); 278 | 279 | if ($check) 280 | { 281 | if ($this->config['sfs_down'] && is_string($check)) 282 | { 283 | return; 284 | } 285 | $error_array[] = $this->show_message($check); 286 | 287 | // now ban the spammer by IP 288 | if (is_int($check)) 289 | { 290 | $this->sfsapi->sfs_ban('ip', $this->user->ip, (int) $check); 291 | } 292 | } 293 | } 294 | } 295 | $event['error'] = $error_array; 296 | } 297 | 298 | /* 299 | * update_sfs_admin_mods update admin and mods cache when adding|deleting users to|from a group 300 | * @param $event event object 301 | * @return void 302 | * @access public 303 | */ 304 | public function update_sfs_admin_mods($event) 305 | { 306 | // can't determine group id by default so always run this when updating groups 307 | // apparently no way to get around this 308 | $this->cache->destroy('_sfs_adminsmods'); 309 | $this->sfsgroups->build_adminsmods_cache(); 310 | } 311 | 312 | /* 313 | * viewtopic_before_f_read_check() inject lang vars and grab admins and mods 314 | * @param $event event object 315 | * @return void 316 | * @access public 317 | */ 318 | public function viewtopic_before_f_read_check($event) 319 | { 320 | if ($this->config['allow_sfs']) 321 | { 322 | if (!empty($this->config['sfs_api_key'])) 323 | { 324 | // get mods and admins 325 | $this->sfs_admins_mods = $this->sfsgroups->getadminsmods($event['forum_id']); 326 | } 327 | } 328 | } 329 | 330 | /* 331 | * viewtopic_post_rowset_data add the posters ip into the rowset 332 | * @param $event event object 333 | * @return void 334 | * @access public 335 | */ 336 | public function viewtopic_post_rowset_data($event) 337 | { 338 | $rowset = $event['rowset_data']; 339 | $row = $event['row']; 340 | 341 | $rowset['poster_ip'] = $row['poster_ip']; 342 | $rowset['user_email'] = $row['user_email']; 343 | $rowset['sfs_reported'] = $row['sfs_reported']; 344 | 345 | $event['rowset_data'] = $rowset; 346 | } 347 | 348 | /* 349 | * viewtopic_modify_post_row show a link to admins and mods to report the spammer 350 | * @param $event event object 351 | * @return void 352 | * @access public 353 | */ 354 | public function viewtopic_modify_post_row($event) 355 | { 356 | if (empty($this->config['allow_sfs']) || empty($this->config['sfs_api_key'])) 357 | { 358 | return; 359 | } 360 | 361 | $row = $event['row']; 362 | 363 | // ensure we have an IP and email address..this may happen if users have "post" bots on the forum 364 | // also ensure the IP is something other than 127.0.0.1 which can happen if the anonymised extension is installed 365 | if (empty($this->validate_ip($row['poster_ip'])) && filter_var($row['poster_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) 366 | { 367 | $sfs_report_allowed = (!empty($row['user_email']) && $event['poster_id'] != ANONYMOUS && !$row['sfs_reported']) ? true : false; 368 | 369 | if ($sfs_report_allowed && in_array($this->user->data['user_id'], $this->sfs_admins_mods) && !in_array((int) $event['poster_id'], $this->sfs_admins_mods)) 370 | { 371 | $reporttosfs_url = $this->helper->route('rmcgirr83_stopforumspam_core_reporttosfs', ['postid' => (int) $row['post_id'], 'posterid' => (int) $event['poster_id']]); 372 | $event['post_row'] = array_merge($event['post_row'], [ 373 | 'S_SFS' => true, 374 | 'U_SFS' => $reporttosfs_url, 375 | ]); 376 | } 377 | } 378 | } 379 | 380 | /* 381 | * ucp_pm_view_message show a link to report a spammer 382 | * @param $event event object 383 | * @return bool 384 | * @access public 385 | */ 386 | public function ucp_pm_view_message($event) 387 | { 388 | $user_info = $event['user_info']; 389 | 390 | $allowed = ($this->config['allow_sfs'] && $this->config['allow_pm_report'] && !empty($this->config['sfs_api_key']) && $this->config['sfs_report_pm']) ? true : false; 391 | 392 | if (!$allowed || $this->user->data['user_id'] == $user_info['user_id']) 393 | { 394 | return false; 395 | } 396 | 397 | // get mods and admins 398 | $this->sfs_admins_mods = $this->sfsgroups->getadminsmods(0); 399 | 400 | if (in_array((int) $user_info['user_id'], $this->sfs_admins_mods)) 401 | { 402 | return false; 403 | } 404 | 405 | $message_row = $event['message_row']; 406 | 407 | // ensure we have an IP and email address..this may happen if users have "post" bots on the forum 408 | // also ensure the IP is something other than 127.0.0.1 which can happen if the anonymised extension is installed 409 | if (empty($this->validate_ip($user_info['author_ip'])) && filter_var($user_info['author_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) 410 | { 411 | $sfs_report_allowed = (!empty($user_info['user_email'])) ? true : false; 412 | 413 | if ($sfs_report_allowed && !$message_row['sfs_reported'] ) 414 | { 415 | $reporttosfs_url = $this->helper->route('rmcgirr83_stopforumspam_core_report_pm_to_sfs', ['postid' => (int) $message_row['msg_id'], 'posterid' => (int) $user_info['user_id']]); 416 | 417 | $event['msg_data'] = array_merge($event['msg_data'], [ 418 | 'S_SFS' => true, 419 | 'U_SFS' => $reporttosfs_url, 420 | ]); 421 | } 422 | } 423 | } 424 | 425 | /* 426 | * message_admin_form_submit_before 427 | * 428 | * @param $event the event object 429 | * @return null 430 | * @access public 431 | */ 432 | public function message_admin_form_submit_before($event) 433 | { 434 | if ($this->config['allow_sfs'] == false) 435 | { 436 | return false; 437 | } 438 | 439 | $errors = $event['errors']; 440 | 441 | // validate the user ip 442 | $userip_error = $this->validate_ip($this->user->ip); 443 | if ($userip_error) 444 | { 445 | $errors[] = $userip_error; 446 | } 447 | 448 | /* On registration and only when all errors have cleared 449 | * do not want the admin message area to fill up 450 | */ 451 | if (!sizeof($errors)) 452 | { 453 | $check = $this->stopforumspam_check($this->request->variable('name', '', true), $this->user->ip, $this->request->variable('email', '')); 454 | 455 | if ($check) 456 | { 457 | if ($this->config['sfs_down'] && $check === 'sfs_down') 458 | { 459 | return; 460 | } 461 | $errors[] = $this->show_message($check); 462 | // now ban the spammer by IP 463 | if (is_int($check) && $this->config['sfs_ban_ip']) 464 | { 465 | $this->sfsapi->sfs_ban('ip', $this->user->ip, (int) $check); 466 | } 467 | } 468 | } 469 | $event['errors'] = $errors; 470 | } 471 | 472 | /* 473 | * show_message 474 | * @param string $check the type of check we are, uhmmm, checking 475 | * @return string 476 | * @access private 477 | */ 478 | private function show_message($check = '') 479 | { 480 | if ($check === 'sfs_down') 481 | { 482 | return $this->language->lang('SFS_ERROR_MESSAGE'); 483 | } 484 | else 485 | { 486 | if ($this->contactadmin !== null && !empty($this->config['contactadmin_enable'])) 487 | { 488 | $message = $this->language->lang('NO_SOUP_FOR_YOU', '', ''); 489 | } 490 | else if ($this->config['contact_admin_form_enable']) 491 | { 492 | $link = ($this->config['email_enable']) ? append_sid("{$this->root_path}memberlist.$this->php_ext", 'mode=contactadmin') : 'mailto:' . phpbb_get_board_contact($this->config, $this->php_ext); 493 | $message = $this->language->lang('NO_SOUP_FOR_YOU', '',''); 494 | } 495 | else 496 | { 497 | $message = $this->language->lang('NO_SOUP_FOR_YOU_NO_CONTACT'); 498 | } 499 | return $message; 500 | } 501 | } 502 | 503 | /* 504 | * stopforumspam_check 505 | * @param string $username username from the forum inputs 506 | * @param string $ip the users ip 507 | * @param string $email email from the forum inputs 508 | * @return bool|string true if found, false if not, string if other 509 | * @access private 510 | */ 511 | private function stopforumspam_check($username, $ip, $email) 512 | { 513 | 514 | $sfs_log_message = !empty($this->config['sfs_log_message']) ? $this->config['sfs_log_message'] : false; 515 | 516 | // Threshold score to reject registration and/or guest posting 517 | $sfs_threshold = !empty($this->config['sfs_threshold']) ? $this->config['sfs_threshold'] : 1; 518 | 519 | // Query the SFS database and pull the data into script 520 | $json = $this->sfsapi->sfsapi('query', $username, $ip, $email); 521 | 522 | $json_decode = json_decode($json, true); 523 | 524 | // If there is a curl error as set in sfs_api, log the error 525 | if (isset($json_decode[$this->language->lang('CURL_ERROR')])) 526 | { 527 | return 'sfs_down'; 528 | } 529 | 530 | // Check if user is a spammer, but only if we successfully got the SFS data 531 | if (isset($json_decode['success'])) 532 | { 533 | $username_freq = (int) $json_decode['username']['frequency']; 534 | $email_freq = (int) $json_decode['email']['frequency']; 535 | $ip_freq = (int) $json_decode['ip']['frequency']; 536 | 537 | // ACP settings in effect 538 | if ($this->config['sfs_by_name'] == false) 539 | { 540 | $username_freq = 0; 541 | } 542 | 543 | if ($this->config['sfs_by_email'] == false) 544 | { 545 | $email_freq = 0; 546 | } 547 | 548 | if ($this->config['sfs_by_ip'] == false) 549 | { 550 | $ip_freq = 0; 551 | } 552 | // Return the total score 553 | $spam_score = (int) ($username_freq + $email_freq + $ip_freq); 554 | 555 | // If we've got a spammer we'll take away their soup! 556 | if ($spam_score >= $sfs_threshold) 557 | { 558 | if ($sfs_log_message) 559 | { 560 | $this->log_message($username, $ip, 'LOG_SFS_MESSAGE', $email, $username_freq, $ip_freq, $email_freq); 561 | } 562 | //user is a spammer 563 | return $spam_score; 564 | } 565 | else 566 | { 567 | return false; 568 | } 569 | } 570 | else 571 | { 572 | if ($sfs_log_message) 573 | { 574 | if ($this->config['sfs_down']) 575 | { 576 | $this->log->add('admin', $username, $ip, 'LOG_SFS_DOWN_USER_ALLOWED', $email); 577 | } 578 | else 579 | { 580 | $this->log->add('admin', $username, $ip, 'LOG_SFS_DOWN', $email); 581 | } 582 | } 583 | return 'sfs_down'; 584 | } 585 | } 586 | 587 | /* 588 | * log_message function used in this class to inject messages into the logs 589 | * @param string $username the users name 590 | * @param string $ip the users ip 591 | * @param string $message the message we are injecting 592 | * @param string $email email from the forum inputs 593 | * @return void 594 | * @access private 595 | */ 596 | private function log_message($username, $ip, $message, $email, $username_score = 0, $ip_score = 0, $email_score = 0) 597 | { 598 | 599 | $sfs_ip = $this->language->lang('SFS_IP_STOPPED', $ip); 600 | $sfs_username = $this->language->lang('SFS_USERNAME_STOPPED', $username); 601 | $sfs_email = $this->language->lang('SFS_EMAIL_STOPPED', $email); 602 | 603 | if ($this->config['sfs_by_name'] == false) 604 | { 605 | $username_score = $this->language->lang('SFS_NOT_CHECKED'); 606 | } 607 | else 608 | { 609 | $username_score = $this->language->lang('SFS_FREQUENCY', $username_score); 610 | } 611 | 612 | if ($this->config['sfs_by_email'] == false) 613 | { 614 | $email_score = $this->language->lang('SFS_NOT_CHECKED'); 615 | } 616 | else 617 | { 618 | if ($email_score == (int) 255) 619 | { 620 | $email_score = $this->language->lang('SFS_MARKED_TOXIC'); 621 | } 622 | else 623 | { 624 | $email_score = $this->language->lang('SFS_FREQUENCY', $email_score); 625 | } 626 | } 627 | 628 | if ($this->config['sfs_by_ip'] == false) 629 | { 630 | $ip_score = $this->language->lang('SFS_NOT_CHECKED'); 631 | } 632 | else 633 | { 634 | $ip_score = $this->language->lang('SFS_FREQUENCY', $ip_score); 635 | } 636 | $sfs_ip .= $ip_score; 637 | $sfs_username .= $username_score; 638 | $sfs_email .= $email_score; 639 | 640 | $this->log->add('user', $this->user->data['user_id'], $ip, $message, false, ['reportee_id' => $this->user->data['user_id'], $sfs_username, $sfs_ip, $sfs_email]); 641 | } 642 | 643 | /* 644 | * validate_email function used in this class to validate a guest posters email address 645 | * @param string $email email from the forum inputs 646 | * @return string 647 | * @access private 648 | */ 649 | private function validate_email($email) 650 | { 651 | $error = validate_user_email($email); 652 | 653 | return $error; 654 | } 655 | 656 | /* 657 | * validate_username function used in this class to validate a guest posters username 658 | * @param string $username username from the forum inputs 659 | * @return array 660 | * @access private 661 | */ 662 | private function validate_username($username) 663 | { 664 | $error = []; 665 | if (($result = validate_username($username)) !== false) 666 | { 667 | $error[] = $this->language->lang($result . '_USERNAME'); 668 | } 669 | 670 | if (($result = validate_string($username, false, $this->config['min_name_chars'], $this->config['max_name_chars'])) !== false) 671 | { 672 | $min_max_amount = ($result == 'TOO_SHORT') ? $this->config['min_name_chars'] : $this->config['max_name_chars']; 673 | $error[] = $this->language->lang('FIELD_' . $result, $min_max_amount, $this->language->lang('USERNAME')); 674 | } 675 | 676 | return $error; 677 | } 678 | 679 | /* 680 | * validate_ip function used in this class to validate an ip address 681 | * @param string $ip the users ip 682 | * @return string 683 | * @access private 684 | */ 685 | private function validate_ip($ip) 686 | { 687 | $error = ''; 688 | 689 | if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === false) 690 | { 691 | $error = $this->language->lang('INVALID_IP_ADDRESS'); 692 | } 693 | 694 | return $error; 695 | } 696 | } 697 | --------------------------------------------------------------------------------