" ."$[This post has been blocked by the administrator]"); SDV($BlockIPMessageFmt, "$[Remote host matches blocked IP address: ]"); SDV($BlockTextMessageFmt, "Content matches blocked pattern: "); SDV($BlockedLogPageName, "$SiteGroup.Blocklog"); SDV($BlockedLogLinesMax, 100); // Number of entries to keep. // Should we even bother? if (!($action == 'edit' || $action == 'comment' || $action == 'diff')) { return; } // From a banned IP? No diff for you! if ($action == 'diff') { $EnableSimpleBlock = 1; } // For backward compatibility if (isset($BlocklistPage)) { $BlocklistPages[] = $BlocklistPage; } // Set default whitelist pages to $SiteGroup.Unblocklist, Main.Unlocklist, // if no Unblocklist pages have been specified. if (!isset($UnblocklistPages)) { $UnblocklistPages = array("$SiteGroup.Unblocklist", 'Main.Unblocklist'); } // Set default Blocklist pages to $SiteGroup.Blocklist, Main.Blocklist, // and $SiteGroup.FarmBlocklist if no Blocklist pages have been specified. if (!isset($BlocklistPages)) { $BlocklistPages = array("$SiteGroup.Blocklist", 'Main.Blocklist', "$SiteGroup.FarmBlocklist"); } $Blocklisted = 0; $Unblock_ar = array(); $page_name = ResolvePageName($pagename); foreach ($UnblocklistPages as $UnblocklistPage) { // Make sure the Blocklist page exists. if (! PageExists($UnblocklistPage)) { continue; } // Get the page contents. $pn = FmtPageName($UnblocklistPage, $page_name); $page = ReadPage($pn); // Build list of unblocked string patterns. $text_ar = explode("\n", $page['text']); foreach($text_ar as $k => $line) { if (strpos($line, 'unblock:') === FALSE) continue; $line = trim($line); $line_ar = explode('unblock:', $line); foreach($line_ar as $term) { $term = trim($term); if (!empty($term)) { $Unblock_ar[$term] = $term; } } } } foreach ($BlocklistPages as $BlocklistPage) { // Make sure the Blocklist page exists and this page isn't it. if (! PageExists($BlocklistPage) || $page_name == $BlocklistPage || $page_name == $BlockedLogPageName || in_array($page_name, $UnblocklistPages)) { continue; } // Get the page contents. $pn = FmtPageName($BlocklistPage, $page_name); $page = ReadPage($pn); // Check for blocked IP address. list($ipa, $ipb, $ipc, $ipd) = explode('.', $_SERVER['REMOTE_ADDR']); if (preg_match("/(\\D$ipa\\.$ipb\\.(\\D|$ipc)\\.($ipd)?\\D)/", $page['text'], $matchedip)) { $Blocklisted++; $WhyBlockedFmt .= $BlockIPMessageFmt.$matchedip[1]."\n"; } // Build list of blocked string patterns. $text_ar = explode("\n", $page['text']); foreach($text_ar as $k => $line) { if (strpos($line, 'block:') === FALSE) continue; $line = trim($line); $line_ar = explode('block:', $line); foreach($line_ar as $term) { $term = trim($term); if (!empty($term) && !$Unblock_ar[$term]) { $Block_ar[$term] = $term; } } } } // Look for matches. if ($Block_ar) { array_walk($Block_ar, 'BlocklistFindBlocked'); } // Disallow a blocked post. if (@$Blocklisted) { if ($EnableSimpleBlock == 1) { $action = 'browse'; return; } if ($action == 'comment' && $EnableCommentMessages == 1) { $page = ReadPage($page_name); $_POST['text'] = $page['text']; $action='edit'; $CommentBlocked = 1; } $EnablePost = 0; unset($_POST['post']); unset($_POST['postattr']); unset($_POST['postedit']); // Let the poster know they've been blocked. $MessagesFmt[] = $BlocklistMessageFmt; // Include the reason(s) for the blockage, if enabled. if ($EnableWhyBlocked == 1) { $MessagesFmt[] = "
$WhyBlockedFmt
"; if (@$CommentBlocked) { $MessagesFmt[] = "Please go back and submit your comment again, but without the blocked content."; } } } // Write an entry to the log once the page has been sent to the browser. if ($Blocklisted && $EnableLogBlocked == 1) { register_shutdown_function(LogBlocked, getcwd()); } /** * Check the posted page content against blocklist. * * Matches only on first, not repeated, offenses-per-criteria. */ function BlocklistFindBlocked(&$blockitem) { global $Blocklisted, $WhyBlockedFmt, $BlockTextMessageFmt; if (preg_match('!^".+"$!', $blockitem)) { $trimmed = trim($blockitem, '"'); if (!preg_match("!(^|[[:space:]])($trimmed)([[:punct:]]|[[:space:]]|$)!i", @$_POST['text'])) { return; } } elseif (stristr(@$_POST['text'], $blockitem) === FALSE) { return; } $Blocklisted++; $WhyBlockedFmt .="$BlockTextMessageFmt$blockitem\n"; } /** * Write information about the blocked post to the log page. * * Adapted from the ActionLog recipe Copyright 2005 by D.Faure * (dfaure@cpan.org) See http://www.pmwiki.org/wiki/Cookbook/ActionLog */ function LogBlocked($dir) { global $pagename, $action, $Author, $BlockedLogPageName, $BlockedLogSelfExclude, $BlockedLogLineFmt, $BlockedLogLinesMax, $WhyBlockedFmt; chdir($dir); $BlockedAuthor = (!empty($Author)) ? '\\\\'."\n($Author)" : ''; $WhyBlockedFmt = substr($WhyBlockedFmt, 0, -1); $WhyBlockedFmt = preg_replace('!'.PHP_EOL.'!', '\\\\\\\\'."\n", $WhyBlockedFmt); $pagename = FmtPageName('$Group.$Name', $pagename); $logpagename = FmtPageName('$Group.$Name', $BlockedLogPageName); $page = ReadPage($logpagename); if(!$page) return; Lock(2); if(substr($page['text'], -1, 1) != "\n") $page['text'] .= "\n"; $blocklogtime = time(); $blocklogtime = strftime("%m-%d\\\\\n%H:%M:%S", $blocklogtime); $page['text'] = "|| [-$blocklogtime-] ||[-[[$pagename]]-]" ."|| [-{$_SERVER['REMOTE_ADDR']}-][-$BlockedAuthor-] ||" ."[-$WhyBlockedFmt-]||\n".$page['text']; if (@$BlockedLogLinesMax > 0) $page['text'] = implode("\n", array_slice(explode("\n", $page['text'], $BlockedLogLinesMax + 1), 0, $BlockedLogLinesMax)); WritePage($logpagename, $page); Lock(0); } /* vim: set expandtab tabstop=2 shiftwidth=2: */