Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23635/plugins/serendipity_event_spamblock
Modified Files:
serendipity_event_spamblock.php
Added Files:
captcha_2.png captcha_3.png captcha_4.png captcha_7.png
captcha_9.png captcha_a.png captcha_b.png captcha_c.png
captcha_d.png captcha_e.png captcha_f.png captcha_h.png
captcha_j.png captcha_k.png captcha_l.png captcha_m.png
captcha_n.png captcha_p.png captcha_q.png captcha_r.png
captcha_t.png captcha_u.png captcha_v.png captcha_w.png
captcha_x.png captcha_y.png captcha_z.png
Log Message:
Captcha fallback on non-gdlib hosts.
Added ability to write a plaintext logfile for rejected/moderated comments.
--- NEW FILE: captcha_y.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_x.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_z.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_w.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_p.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_3.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_r.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_m.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_l.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_n.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_k.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_e.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_d.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_f.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_a.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_4.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_9.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_2.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_u.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_t.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_v.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_q.png ---
(This appears to be a binary file; contents omitted.)
Index: serendipity_event_spamblock.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- serendipity_event_spamblock.php 22 Sep 2004 15:37:21 -0000 1.9
+++ serendipity_event_spamblock.php 23 Sep 2004 12:31:57 -0000 1.10
@@ -36,6 +36,9 @@
@define('PLUGIN_EVENT_SPAMBLOCK_NOTICE_MODERATION', 'Because of some conditions, your comment has been marked to require moderation by the owner of this blog.');
@define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHA_COLOR', 'Background color of the captcha');
@define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHA_COLOR_DESC', 'Enter RGB values: 0,255,255');
+
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGFILE', 'Logfile location');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LOGFILE_DESC', 'Information about rejected/moderated posts can be written to a logfile. Set this to an empty string if you want to disable logging.');
break;
}
@@ -54,11 +57,13 @@
'external_plugin' => true,
'frontend_comment' => true
));
- $propbag->add('configuration', array('killswitch', 'bodyclone', 'ipflood', 'rbl', 'captchas', 'captchas_ttl', 'captcha_color', 'forcemoderation', 'links_moderate', 'links_reject'));
+ $propbag->add('configuration', array('killswitch', 'bodyclone', 'ipflood', 'rbl', 'captchas', 'captchas_ttl', 'captcha_color', 'forcemoderation', 'links_moderate', 'links_reject', 'logfile'));
}
function introspect_config_item($name, &$propbag)
{
+ global $serendipity;
+
switch($name) {
case 'bodyclone':
$propbag->add('type', 'boolean');
@@ -68,12 +73,10 @@
break;
case 'captchas':
- if (function_exists('imagettftext')) {
- $propbag->add('type', 'boolean');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_DESC);
- $propbag->add('default', true);
- }
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_DESC);
+ $propbag->add('default', true);
break;
case 'killswitch':
@@ -83,6 +86,13 @@
$propbag->add('default', false);
break;
+ case 'logfile':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_LOGFILE);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_LOGFILE_DESC);
+ $propbag->add('default', $serendipity['serendipityPath'] . 'spamblock_captcha.log');
+ break;
+
case 'ipflood':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD);
@@ -151,7 +161,7 @@
if (isset($hooks[$event])) {
$captchas_ttl = $this->get_config('captchas_ttl', 7);
- $captchas = (serendipity_db_bool($this->get_config('captchas', true)) && function_exists('imagettftext') ? true : false);
+ $captchas = (serendipity_db_bool($this->get_config('captchas', true)) ? true : false);
// Check if the entry is older than the allowed amount of time. Enforce kaptchas if that is true
// of if kaptchas are activated for every entry
$show_captcha = ($captchas && isset($eventData['timestamp']) && ($captchas_ttl < 1 || ($eventData['timestamp'] < (time() - ($captchas_ttl*60*60*24)))) ? true : false);
@@ -160,13 +170,23 @@
$links_moderate = $this->get_config('links_moderate', 10);
$links_reject = $this->get_config('links_reject', 20);
+ if (function_exists('imagettftext')) {
+ $max_char = 5;
+ $min_char = 3;
+ $use_gd = true;
+ } else {
+ $max_char = $min_char = 5;
+ $use_gd = true;
+ }
+
switch($event) {
case 'frontend_saveComment':
if (!is_array($eventData) || serendipity_db_bool($eventData['allow_comments'])) {
-
+ $logfile = $this->get_config('logfile', $serendipity['serendipityPath'] . 'spamblock_captcha.log');
if ( $this->get_config('killswitch', false) === true ) {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_KILLSWITCH;
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH, $addData);
return false;
}
@@ -177,6 +197,7 @@
if (is_array($row) && $row['counter'] > 0) {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH, $addData);
return false;
}
}
@@ -188,6 +209,7 @@
if (is_array($row) && $row['last_post'] > (time() - $this->get_config('ipflood', 2)*60)) {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_IP;
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD, $addData);
return false;
}
}
@@ -207,6 +229,7 @@
if (gethostbyname($rblhost) != $rblhost) {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_RBL;
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_RBL, $addData);
return false;
}
}
@@ -218,6 +241,7 @@
if (!isset($serendipity['POST']['captcha']) || strtolower($serendipity['POST']['captcha']) != strtolower($_SESSION['spamblock']['captcha'])) {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_CAPTCHAS;
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS, $addData);
return false;
}
}
@@ -226,6 +250,7 @@
if ($forcemoderation > 0 && $eventData['timestamp'] < (time() - ($forcemoderation * 60 * 60 * 24))) {
$eventData['moderate_comments'] = true;
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_NOTICE_MODERATION;
+ $this->log($logfile, $eventData['id'], 'MODERATE', PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATION, $addData);
return false;
}
@@ -233,12 +258,14 @@
if ($links_reject > 0 && $link_count > $links_reject) {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_LINKS_REJECT, $addData);
return false;
}
if ($links_moderate > 0 && $link_count > $links_moderate) {
$eventData['moderate_comments'] = true;
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_NOTICE_MODERATION;
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_LINKS_MODERATE, $addData);
return false;
}
}
@@ -249,10 +276,25 @@
if ($show_captcha) {
echo '<div class="serendipity_commentDirection">';
if (!isset($serendipity['POST']['preview']) || strtolower($serendipity['POST']['captcha'] != strtolower($_SESSION['spamblock']['captcha']))) {
- printf('<br />' . PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC . '<br /><label for="captcha"><img src="%s" title="%s" alt="CAPTCHA" class="captcha" /></label><br />',
- $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . md5(time()),
- htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2)
- );
+ echo '<br />' . PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC . '<br /><label for="captcha">';
+ if ($use_gd) {
+ printf('<img src="%s" title="%s" alt="CAPTCHA" class="captcha" />',
+ $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . md5(time()),
+ htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2)
+ );
+ } else {
+ $bgcolors = explode(',', $this->get_config('captcha_color', '255,0,255'));
+ $hexval = '#' . dechex(trim($bgcolors[0])) . dechex(trim($bgcolors[1])) . dechex(trim($bgcolors[2]));
+ echo '<div style="background-color: ' . $hexval . '">';
+ for ($i = 1; $i <= $max_char; $i++) {
+ printf('<img src="%s" title="%s" alt="CAPTCHA ' . $i . '" class="captcha" />',
+ $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . $i . '_' . md5(time()),
+ htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2)
+ );
+ }
+ echo '</div>';
+ }
+ echo '</label><br />';
echo PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3 . '<input type="text" size="5" name="serendipity[captcha]" value="" id="captcha" />';
} elseif (isset($serendipity['POST']['captcha'])) {
echo '<input type="hidden" name="serendipity[captcha]" value="' . htmlspecialchars($serendipity['POST']['captcha']) . '" />';
@@ -273,59 +315,67 @@
$methods = array('captcha');
- if (!in_array($parts[0], $methods) || !function_exists('imagettftext')) {
+ if (!in_array($parts[0], $methods)) {
return;
}
+ mt_srand(time());
$width = 120;
$height = 40;
- $max_char = 5;
- $min_char = 3;
- $bgcolors = explode(',', $this->get_config('captcha_color', '255,255,255'));
+ $bgcolors = explode(',', $this->get_config('captcha_color', '255,255,255'));
$fontfiles = array('Comic_Sans_MS.ttf', 'Impact.ttf', 'Verdana.ttf');
$chars = array(2, 3, 4, 7, 9); // 1, 5, 6 and 8 may look like characters.
$chars = array_merge($chars, array('A','B','C','D','E','F','H','J','K','L','M','N','P','Q','R','T','U','V','W','X','Y','Z')); // I, O, S may look like numbers
- $strings = array_rand($chars, mt_rand($max_char, $min_char));
- $string = '';
- foreach($strings AS $idx => $charidx) {
- $string .= $chars[$charidx];
- }
- $_SESSION['spamblock'] = array('captcha' => $string);
- $font = $serendipity['serendipityPath'] . 'plugins/serendipity_event_spamblock/' . $fontfiles[array_rand($fontfiles)];
- if (!file_exists($font)) {
- die(PLUGIN_EVENT_SPAMBLOCK_ERROR_NOTTF);
+ if ($use_gd || $parts[1] == '1') {
+ $strings = array_rand($chars, mt_rand($max_char, $min_char));
+ $string = '';
+ foreach($strings AS $idx => $charidx) {
+ $string .= $chars[$charidx];
+ }
+ $_SESSION['spamblock'] = array('captcha' => $string);
}
- header('Content-Type: image/jpeg');
- $image = imagecreate($width, $height);
- imagecolorallocate($image, trim($bgcolors[0]), trim($bgcolors[1]), trim($bgcolors[2]));
- // imagettftext($image, 10, 1, 1, 15, imagecolorallocate($image, 255, 255, 255), $font, 'String: ' . $string);
+ if ($use_gd) {
+ $font = $serendipity['serendipityPath'] . 'plugins/serendipity_event_spamblock/' . $fontfiles[array_rand($fontfiles)];
+ if (!file_exists($font)) {
+ die(PLUGIN_EVENT_SPAMBLOCK_ERROR_NOTTF);
+ }
- $pos_x = 5;
- foreach($strings AS $idx => $charidx) {
- $color = imagecolorallocate($image, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50,255));
- $size = mt_rand(15, 21);
- $angle = mt_rand(-20, 20);
- $pos_y = ceil($height - (mt_rand($size/3, $size/2)));
+ header('Content-Type: image/jpeg');
+ $image = imagecreate($width, $height);
+ imagecolorallocate($image, trim($bgcolors[0]), trim($bgcolors[1]), trim($bgcolors[2]));
+ // imagettftext($image, 10, 1, 1, 15, imagecolorallocate($image, 255, 255, 255), $font, 'String: ' . $string);
- imagettftext(
- $image,
- $size,
- $angle,
- $pos_x,
- $pos_y,
- $color,
- $font,
- $chars[$charidx]
- );
+ $pos_x = 5;
+ foreach($strings AS $idx => $charidx) {
+ $color = imagecolorallocate($image, mt_rand(50, 235), mt_rand(50, 235), mt_rand(50,235));
+ $size = mt_rand(15, 21);
+ $angle = mt_rand(-20, 20);
+ $pos_y = ceil($height - (mt_rand($size/3, $size/2)));
- $pos_x = $pos_x + $size + 2;
+ imagettftext(
+ $image,
+ $size,
+ $angle,
+ $pos_x,
+ $pos_y,
+ $color,
+ $font,
+ $chars[$charidx]
+ );
+ $pos_x = $pos_x + $size + 2;
+
+ }
+ imagejpeg($image, '', 90);
+ imagedestroy($image);
+ } else {
+ header('Content-Type: image/png');
+ $output_char = strtolower($_SESSION['spamblock']['captcha']{$parts[1] - 1});
+ echo file_get_contents($serendipity['serendipityPath'] . 'plugins/serendipity_event_spamblock/captcha_' . $output_char . '.png');
}
- imagejpeg($image, '', 90);
- imagedestroy($image);
return true;
break;
@@ -337,6 +387,33 @@
return false;
}
}
+
+ function log($log, $id, $switch, $reason, $comment) {
+ global $serendipity;
+
+ if (empty($log)) {
+ return;
+ }
+
+ $logfile = @fopen($log, 'a');
+ if ($logfile) {
+ fwrite($logfile, sprintf(
+ '[%s] - [%s: %s] - [#%d, Name "%s", E-Mail "%s", URL "%s", User-Agent "%s", IP %s] - [%s]',
+
+ date('%Y-%m-%d'),
+ $switch,
+ $reason,
+ $id,
+ str_replace("\n", ' ', $comment['name']),
+ str_replace("\n", ' ', $comment['email']),
+ str_replace("\n", ' ', $comment['url']),
+ str_replace("\n", ' ', $_SERVER['HTTP_USER_AGENT']),
+ $_SERVER['REMOTE_ADDR'],
+ str_replace("\n", ' ', $comment['comment'])
+ ));
+ fclose($logfile);
+ }
+ }
}
/* vim: set sts=4 ts=4 expandtab : */
--- NEW FILE: captcha_h.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_j.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_7.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_c.png ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: captcha_b.png ---
(This appears to be a binary file; contents omitted.)
|