/** * The function for processing a message to see if it might be SPAM * returns: * 0 if the message is SPAM * 1 if the message might be SPAM (it will be marked for moderation) * 2 if the message is not SPAM * * @param string $author Author field from the posting * @param string $email Email field from the posting * @param string $website Website field from the posting * @param string $body The text of the comment * @param string $imageLink A link to the album/image on which the post was made * @param string $ip the IP address of the comment poster * * @return int */ function filterMessage($author, $email, $website, $body, $imageLink, $ip) { // set keys Mollom::setPublicKey(getOption('public_key')); Mollom::setPrivateKey(getOption('private_key')); $servers = Mollom::getServerList(); Mollom::setServerList($servers); // get feedback try { $feedback = Mollom::checkContent(null, null, $body, $author, $website, $email); } catch (Exception $e) { // mark comment for moderation, Mollom is acting strange } // process feedback if (in_array($feedback['spam'], array('unsure', 'unknow'))) { $result = 1; } elseif ($feedback['spam'] == 'ham') { $result = 2; } elseif ($feedback['spam'] == 'spam') { $result = 0; } return $result; }
/** * Check if comment is spam using Mollom. * * @param Comment $comment The Comment object * @param string $public_key The Mollom public key * @param string $private_key The Mollom private key * * @return void * * @since 2.0 */ public function mollom($comment, $public_key = '', $private_key = '') { // check if curl functions are available if (!function_exists('curl_init')) { return; } // load mollom class $this->app->loader->register('Mollom', 'libraries:mollom/mollom.php'); // set keys and get servers Mollom::setPublicKey($public_key); Mollom::setPrivateKey($private_key); Mollom::setServerList(Mollom::getServerList()); // check comment $feedback = Mollom::checkContent(null, null, $comment->content, $comment->author, $comment->url, $comment->email); // set state if ($feedback['spam'] != 'ham') { $comment->state = Comment::STATE_SPAM; } }
private function performChecks() { $request = JRequest::get(); // Calc check if ($this->params->get('type_calc')) { if ($this->_session->get('rot13', null, 'easycalccheck') == 1) { $spamcheckresult = base64_decode(str_rot13($this->_session->get('spamcheckresult', null, 'easycalccheck'))); } else { $spamcheckresult = base64_decode($this->_session->get('spamcheckresult', null, 'easycalccheck')); } $spamcheck = JRequest::getInt($this->_session->get('spamcheck', null, 'easycalccheck'), '', 'post'); $this->_session->clear('rot13', 'easycalccheck'); $this->_session->clear('spamcheck', 'easycalccheck'); $this->_session->clear('spamcheckresult', 'easycalccheck'); if (!is_numeric($spamcheckresult) || $spamcheckresult != $spamcheck) { return false; // Failed } } // Hidden field if ($this->params->get('type_hidden')) { $hidden_field = $this->_session->get('hidden_field', null, 'easycalccheck'); $this->_session->clear('hidden_field', 'easycalccheck'); if (JRequest::getVar($hidden_field, '', 'post')) { return false; // Hidden field was filled out - failed } } // Time lock if ($this->params->get('type_time')) { $time = $this->_session->get('time', null, 'easycalccheck'); $this->_session->clear('time', 'easycalccheck'); if (time() - $this->params->get('type_time_sec') <= $time) { return false; // Submitted too fast - failed } } // Own Question // Conversion to lower case if ($this->params->get('question')) { $answer = strtolower(JRequest::getString($this->_session->get('question', null, 'easycalccheck'), '', 'post')); $this->_session->clear('question', 'easycalccheck'); if ($answer != strtolower($this->params->get('question_a'))) { return false; // Question wasn't answered - failed } } // StopForumSpam - Check the IP Address // Further informations: http://www.stopforumspam.com if ($this->params->get('stopforumspam')) { $url = 'http://www.stopforumspam.com/api?ip=' . $this->_session->get('ip', null, 'easycalccheck'); // Function test - Comment out to test - Important: Enter a active Spam-IP // $ip = '88.180.52.46'; // $url = 'http://www.stopforumspam.com/api?ip='.$ip; $response = false; $is_spam = false; if (function_exists('curl_init')) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); } if ($response) { preg_match('#<appears>(.*)</appears>#', $response, $out); $is_spam = $out[1]; } else { $response = @fopen($url, 'r'); if ($response) { while (!feof($response)) { $line = fgets($response, 1024); if (preg_match('#<appears>(.*)</appears>#', $line, $out)) { $is_spam = $out[1]; break; } } fclose($response); } } if ($is_spam == 'yes' and $response == true) { return false; // Spam-IP - failed } } // Honeypot Project // Further informations: http://www.projecthoneypot.org/home.php // BL ACCESS KEY - http://www.projecthoneypot.org/httpbl_configure.php if ($this->params->get('honeypot')) { require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'honeypot.php'; $http_blKey = $this->params->get('honeypot_key'); if ($http_blKey) { $http_bl = new http_bl($http_blKey); $result = $http_bl->query($this->_session->get('ip', null, 'easycalccheck')); // Function test - Comment out to test - Important: Enter a active Spam-IP // $ip = '117.21.224.251'; // $result = $http_bl->query($ip); if ($result == 2) { return false; } } } // Akismet // Further informations: http://akismet.com/ if ($this->params->get('akismet')) { require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'akismet.php'; $akismet_key = $this->params->get('akismet_key'); if ($akismet_key) { $akismet_url = JURI::getInstance()->toString(); $name = ''; $email = ''; $url = ''; $comment = ''; if ($request['option'] == 'com_contact') { $name = $request['jform']['contact_name']; $email = $request['jform']['contact_email']; $comment = $request['jform']['contact_message']; } elseif ($request['option'] == 'com_users') { $name = $request['jform']['name']; $email = $request['jform']['email1']; if (isset($request['jform']['email'])) { $email = $request['jform']['email']; } } elseif ($request['option'] == 'com_comprofiler') { $name = $request['name']; $email = $request['email']; if (isset($request['checkusername'])) { $name = $request['checkusername']; } if (isset($request['checkemail'])) { $email = $request['checkemail']; } } elseif ($request['option'] == 'com_easybookreloaded') { $name = $request['gbname']; $email = $request['gbmail']; $comment = $request['gbtext']; if (isset($request['gbpage'])) { $url = $request['gbpage']; } } elseif ($request['option'] == 'com_phocaguestbook') { $name = $request['pgusername']; $email = $request['email']; $comment = $request['pgbcontent']; } elseif ($request['option'] == 'com_dfcontact') { $name = $request['name']; $email = $request['email']; $comment = $request['message']; } elseif ($request['option'] == 'com_flexicontact') { $name = $request['from_name']; $email = $request['from_email']; $comment = $request['area_data']; } elseif ($request['option'] == 'com_alfcontact') { $name = $request['name']; $email = $request['email']; $comment = $request['message']; } elseif ($request['option'] == 'com_community') { $name = $request['usernamepass']; $email = $request['emailpass']; } elseif ($request['option'] == 'com_virtuemart') { $name = $request['name']; $email = $request['email']; $comment = $request['comment']; } elseif ($request['option'] == 'com_jshopping') { $name = $request['f_name']; $email = $request['email']; } $akismet = new Akismet($akismet_url, $akismet_key); $akismet->setCommentAuthor($name); $akismet->setCommentAuthorEmail($email); $akismet->setCommentAuthorURL($url); $akismet->setCommentContent($comment); if ($akismet->isCommentSpam()) { return false; } } } // ReCaptcha // Further informations: http://www.google.com/recaptcha if ($this->params->get('recaptcha') and $this->params->get('recaptcha_publickey') and $this->params->get('recaptcha_privatekey')) { require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'recaptchalib.php'; $privatekey = $this->params->get('recaptcha_privatekey'); $resp = recaptcha_check_answer($privatekey, $this->_session->get('ip', null, 'easycalccheck'), $request['recaptcha_challenge_field'], $request['recaptcha_response_field']); if (!$resp->is_valid) { return false; } } // Botscout - Check the IP Address // Further informations: http://botscout.com/ if ($this->params->get('botscout') and $this->params->get('botscout_key')) { $url = 'http://botscout.com/test/?ip=' . $this->_session->get('ip', null, 'easycalccheck') . '&key=' . $this->params->get('botscout_key'); // Function test - Comment out to test - Important: Enter a active Spam-IP // $ip = '87.103.128.199'; // $url = 'http://botscout.com/test/?ip='.$ip.'&key='.$this->params->get('botscout_key'); $response = false; $is_spam = false; if (function_exists('curl_init')) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); } if ($response) { $is_spam = substr($response, 0, 1); } else { $response = @fopen($url, 'r'); if ($response) { while (!feof($response)) { $line = fgets($response, 1024); $is_spam = substr($line, 0, 1); } fclose($response); } } if ($is_spam == 'Y' and $response == true) { // Spam-IP - failed return false; } } // Mollom // Further informations: http://mollom.com/ if ($this->params->get('mollom') and $this->params->get('mollom_publickey') and $this->params->get('mollom_privatekey')) { require_once dirname(__FILE__) . DS . 'easycalccheckplus' . DS . 'mollom.php'; Mollom::setPublicKey($this->params->get('mollom_publickey')); Mollom::setPrivateKey($this->params->get('mollom_privatekey')); $servers = Mollom::getServerList(); $name = ''; $email = ''; $url = ''; $comment = ''; if ($request['option'] == 'com_contact') { $name = $request['jform']['contact_name']; $email = $request['jform']['contact_email']; $comment = $request['jform']['contact_message']; } elseif ($request['option'] == 'com_users') { $name = $request['jform']['name']; $email = $request['jform']['email1']; if (isset($request['jform']['email'])) { $email = $request['jform']['email']; } } elseif ($request['option'] == 'com_comprofiler') { $name = $request['name']; $email = $request['email']; if (isset($request['checkusername'])) { $name = $request['checkusername']; } if (isset($request['checkemail'])) { $email = $request['checkemail']; } } elseif ($request['option'] == 'com_easybookreloaded') { $name = $request['gbname']; $email = $request['gbmail']; $comment = $request['gbtext']; if (isset($request['gbpage'])) { $url = $request['gbpage']; } } elseif ($request['option'] == 'com_phocaguestbook') { $name = $request['pgusername']; $email = $request['email']; $comment = $request['pgbcontent']; } elseif ($request['option'] == 'com_dfcontact') { $name = $request['name']; $email = $request['email']; $comment = $request['message']; } elseif ($request['option'] == 'com_flexicontact') { $name = $request['from_name']; $email = $request['from_email']; $comment = $request['area_data']; } elseif ($request['option'] == 'com_alfcontact') { $name = $request['name']; $email = $request['email']; $comment = $request['message']; } elseif ($request['option'] == 'com_community') { $name = $request['usernamepass']; $email = $request['emailpass']; } elseif ($request['option'] == 'com_virtuemart') { $name = $request['name']; $email = $request['email']; $comment = $request['comment']; } elseif ($request['option'] == 'com_jshopping') { $name = $request['f_name']; $email = $request['email']; } $feedback = Mollom::checkContent(null, null, $comment, $name, $url, $email); if ($feedback['spam'] == 'spam') { return false; } } $this->_session->clear('ip', 'easycalccheck'); $this->_session->clear('saved_data', 'easycalccheck'); return true; }
public function action_comment_insert_before(Comment $comment) { if ($comment->info->mollom_session_id) { return; } $user = User::identify(); $author_name = $comment->name; $author_url = $comment->url ? $comment->url : null; $author_email = $comment->email ? $comment->email : null; $author_id = $user->loggedin ? $user->id : null; $author_open_id = $user instanceof User && $user->info->openid_url ? $user->info->openid_url : null; $post_body = $comment->content; try { $result = Mollom::checkContent(null, null, $post_body, $author_name, $author_url, $author_email, $author_open_id, $author_id); $comment->info->mollom_session_id = $result['session_id']; $comment->info->mollom_quality = $result['quality']; switch ($result['spam']) { case 'spam': $comment->status = 'spam'; if ($comment->info->spamcheck) { $comment->info->spamcheck[] = _t('Flagged as Spam by Mollom', 'mollom'); } else { $comment->info->spamcheck = array(_t('Flagged as Spam by Mollom', 'mollom')); } break; case 'ham': // Mollom is 100% it is ham, so approve it $comment->status = 'ham'; return; break; case 'unsure': case 'unknown': // make it spam until we are sure $comment->status = 'spam'; Plugins::act('mollom_fallback', Controller::get_handler()->handler_vars, $comment); return; break; } } catch (Exception $e) { EventLog::log($e->getMessage(), 'notice', 'comment', 'Mollom'); } }
private function internalCheck($retry = true) { if (Session::has('mollom/sessionid')) { $sessID = Session::get('mollom/sessionid'); } else { $sessID = null; } try { $result = Mollom::checkContent($sessID, $this->title, $this->body, $this->authorName, $this->authorWebsite, $this->authorEmail, $this->authorOpenID, $this->authorID); Session::set('mollom/sessionid', $result['session_id']); if ($result['spam'] == 'ham') { return PropertySpamStatus::OK; } else if ($result['spam'] == 'spam') { return PropertySpamStatus::SPAM; } else { return PropertySpamStatus::UNKNOWN; } } catch (KeyNotSetException $e) { return PropertySpamStatus::UNKNOWN; } catch (InternalException $e) { return PropertySpamStatus::UNKNOWN; } catch (OutdatedServerListException $e) { CoOrg::config()->set('mollom/serverlist', Mollom::getServerList()); CoOrg::config()->save(); return $retry ? $this->internalCheck(false) : PropertySpamStatus::UNKNOWN; } catch (NoServerListException $e) { CoOrg::config()->set('mollom/serverlist', Mollom::getServerList()); CoOrg::config()->save(); return $retry ? $this->internalCheck(false) : PropertySpamStatus::UNKNOWN; } }