tips:blacklist_test
Blacklist Test
This little script helps to check a text against the blacklist - nice for debugging it.
<?php require_once("inc/init.php"); $text = $_POST['text']; function checkit($file,$text){ $blockfile = (array) @file(DOKU_CONF.$file); $ln=0; $text = preg_replace('!(\b)(www\.[\w.:?\-;,]+?\.[\w.:?\-;,]+?[\w/\#~:.?+=&%@\!\-.:?\-;,]+?)([.:?\-;,]*[^\w/\#~:.?+=&%@\!\-.:?\-;,])!i','\1http://\2 \2\3',$text); foreach($blockfile as $block){ $i++; $block = preg_replace('/#.*$/','',$block); $block = trim($block); if(empty($block)) continue; if(preg_match('#('.$block.')#si',$text,$matches)){ $pos = strpos($text,$matches[0]); $s = max(0,$pos - 15); $l = strlen($matches[0])+30; $snip = substr($text,$s,$l); print '<li>'; print "$file line $i: "; print htmlspecialchars($block); print "<br /><pre>".htmlspecialchars($snip)."</pre>"; print '</li>'; } } } header('Content-Type: text/html; charset=utf-8'); ?> <html> <head><title>Spamcheck</title></head> <body> <form method="post" accept-charset="utf-8"> <textarea name="text" cols="50" rows="10"><?php echo htmlspecialchars($text)?></textarea><br /> <input type="submit" /> </form> <ul> <?php if($text){ checkit('wordblock.conf',$text); checkit('wordblock.local.conf',$text); } ?> </ul> </body> </html>
Logging of blocked Attacks
This small change makes it possible to log blocked attacks in \DATA\meta\wordblock.log and can also be used for block lists debugging.
But need a modification of a original DokuWiki file.
File: \inc\common.php
Search Line:
if(preg_match('#('.join('|',$re).')#si',$text, $match=array())) { return true; }
Change:
if(preg_match('#('.join('|',$re).')#si',$text, $match=array())) { preg_match('#('.join('|',$re).')#si',$text, $match); io_saveFile($conf['metadir'].'/wordblock.log', date($conf['dformat'])."\t".$match[0]."\t".$ID.$_SERVER['REMOTE_USER']."\t".$_SERVER['REMOTE_ADDR'].":".$_SERVER['SERVER_PORT']."\t".gethostbyaddr($_SERVER['REMOTE_ADDR'])."\t".$_SERVER['HTTP_USER_AGENT']."\n",true); return true; }
tips/blacklist_test.txt · Last modified: 2010-10-08 20:37 by Aleksandr