Commit 191d9bf9 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Check for spam domains in forum posts (bug #663039)


Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 5ccbb142
......@@ -36,6 +36,7 @@ safe_require('interaction', 'forum');
require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('pieforms/pieform.php');
require_once('antispam.php');
$postid = param_integer('id', 0);
......@@ -175,6 +176,12 @@ $editform = pieform(array(
),
));
function editpost_validate(Pieform $form, $values) {
if ($baddomain = get_first_blacklisted_domain($values['body'])) {
$form->set_error('body', get_string('blacklisteddomaininurl', 'mahara', $baddomain));
}
}
function editpost_submit(Pieform $form, $values) {
global $USER, $SESSION;
$postid = param_integer('id');
......
......@@ -36,6 +36,7 @@ safe_require('interaction', 'forum');
require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('pieforms/pieform.php');
require_once('antispam.php');
$userid = $USER->get('id');
$topicid = param_integer('id', 0);
......@@ -164,6 +165,18 @@ if(!$moderator){
$editform = pieform($editform);
function addtopic_validate(Pieform $form, $values) {
if ($baddomain = get_first_blacklisted_domain($values['body'])) {
$form->set_error('body', get_string('blacklisteddomaininurl', 'mahara', $baddomain));
}
}
function edittopic_validate(Pieform $form, $values) {
if ($baddomain = get_first_blacklisted_domain($values['body'])) {
$form->set_error('body', get_string('blacklisteddomaininurl', 'mahara', $baddomain));
}
}
function addtopic_submit(Pieform $form, $values) {
global $USER, $SESSION;
$forumid = param_integer('forum');
......
......@@ -526,6 +526,7 @@ $string['sendmessage'] = 'Send message';
$string['spamtrap'] = 'Spam trap';
$string['formerror'] = 'There was an error processing your submission. Please try again.';
$string['formerroremail'] = 'Contact us at %s if you continue to have problems.';
$string['blacklisteddomaininurl'] = 'A url in this field contains the blacklisted domain %s.';
$string['notinstallable'] = 'Not installable!';
$string['installedplugins'] = 'Installed plugins';
......
......@@ -45,6 +45,13 @@ function new_spam_trap($fields) {
return new $spamclass($fields);
}
function get_first_blacklisted_domain($text) {
$spamtrap = new_spam_trap(array());
if ($baddomain = $spamtrap->has_blacklisted_urls($text)) {
return $baddomain;
}
}
// windows has no checkdnsrr until PHP 5.3
if (!function_exists('checkdnsrr')) {
function checkdnsrr($host, $type='MX') {
......
......@@ -66,7 +66,7 @@ class AdvancedSpamTrap extends SimpleSpamTrap {
$domain = $match[2];
foreach ($blacklists as $bl) {
if (checkdnsrr($domain . '.' . $bl, 'A')) {
return true;
return $domain;
}
}
return false;
......@@ -82,5 +82,17 @@ class AdvancedSpamTrap extends SimpleSpamTrap {
}
return $score;
}
// Call this when you want to know if there's a url with a
// blacklisted domain in some text but you don't care how many
// non-blacklisted ones there are.
public function has_blacklisted_urls($string) {
foreach ($this->get_urls($string) as $url) {
if ($domain = $this->blacklisted_url($url)) {
return $domain;
}
}
return false;
}
}
......@@ -54,4 +54,8 @@ class NoneSpamTrap {
}
return false;
}
public function has_blacklisted_urls($string) {
return false;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment