$value) { if (! PageExists($value)) unset($BlocklistPages[$key]); } } # This script only applies to editing (or the commentbox cookbook script), so # if we're not editing or commenting, just return. Partly borrowed from cmsb-blocklist.php. # Not sure why he added "diff" to the actions that this runs on. if (! ($action == 'edit' || $action == 'comment') || (count($BlocklistPages) < 1) || in_array ($page_name, $BlocklistPages) ) { return; } //Now that we know we're supposed to be here, set remaining variables SDV($BlocklistMessageFmt, "

$[This post has been blocked by the administrator]

"); SDV($BlockIPMessageFmt, "$[Remote server matches blocked server IP]: "); SDV($BlockTextMessageFmt, "$[Content matches blocklist content]: "); SDV($EnableWhyBlocked, 0); // default is to not let them know SDV($EnableBlocklistRegex, 0); // enables Perl-compatible regular expression search SDV($EnableUnBlocklist, 0); // new feature allowing de-listing of blocked items from cumulating blocklists // get blocklist texts foreach((array)$BlocklistPages as $key=>$oneblockpage) { $pn = FmtPageName($oneblockpage,$pagename); $page[$key] = ReadPage($pn); $pages[] = $page[$key]['text']; } $check = new BlocklistClass($EnableWhyBlocked, $EnableBlocklistRegex, $EnableUnBlocklist, $BlocklistMessageFmt, $BlockIPMessageFmt, $BlockTextMessageFmt); $check->blockCheck($pages); $Blocklisted = $check->Blockcount; class BlocklistClass { var $terms = array( 'block' => array(), 'regex' => array(), 'unblock' => array(), 'unregex' => array()); var $regex = array(); var $unblock = array(); function BlocklistClass($EnableWhyBlocked, $EnableBlocklistRegex, $EnableUnBlocklist, $BlocklistMessageFmt, $BlockIPMessageFmt, $BlockTextMessageFmt) { $this->why = $EnableWhyBlocked; $this->regex = $EnableBlocklistRegex; $this->unblock = $EnableUnBlocklist; $this->blockmsg = $BlocklistMessageFmt; $this->ipmsg = $BlockIPMessageFmt; $this->textmsg = $BlockTextMessageFmt; } // feed me an array of blocklist page texts function blockCheck($blocktexts) { $this->rawtexts = $blocktexts; $this->checkBlockIP(); if (($this->why == 0) && ($this->Blockcount > 0)) {$this->printMessages(); return;} $this->makeBlockTerms(); if ($this->unblock) $this->removeTerms('block'); if ($this->regex) { $this->makeRegexTerms(); if ($this->unblock) $this->removeTerms('regex'); } $this->checkBlockTerms(); if (($this->why == 0) && ($this->Blockcount > 0)) {$this->printMessages(); return;} if ($this->regex) $this->checkRegexTerms(); if ($this->Blockcount > 0) {$this->printMessages(); return;} } function checkBlockIP() { // Prep for IP checking list($ipa,$ipb,$ipc,$ipd) = explode('.', $_SERVER['REMOTE_ADDR']); // Check ip address against each blocklist page text foreach ($this->rawtexts as $text){ if (preg_match("/(\\D$ipa\\.$ipb\\.(\\D|$ipc)\\.($ipd)?\\D)/", $text, $matchedip)) { $this->Blockcount++ ; // increment counter $this->whymsg .= $this->ipmsg . $matchedip[1] . "\n"; // add a reason why the page is blocked return; } } } function makeBlockTerms() { foreach ($this->rawtexts as $text){ //catch and fix multiple block:'s on a single line and leading whitespace //(allows legacy format) $legacyfix['/\\s*block:/'] = '\nblock:'; if ($this->unblock) $legacyfix['/\\s*unblock:/'] = '\nunblock:'; if ($this->regex) {$legacyfix['/\\s*regex:/'] = '\nregex:'; if ($this->unregex) $legacyfix['/\\s*unregex:/'] = '\nunregex:'; } // Make an array of text that follows "block:" incl spaces & punct preg_match_all('/block:\s*(.+)/', $text, $blockterms); $this->terms['block'] = array_merge($this->terms['block'], $blockterms[1]); } } function removeTerms($type) { foreach ($this->rawtexts as $text){ //catch and fix multiple block:'s on a single line and leading whitespace //(allows legacy format) // Make an array of text that follows "unblock:" incl spaces & punct preg_match_all("/un$type:\s*(.+)/", $text, $unblockterms); $this->terms["un$type"] = array_merge($this->terms["un$type"], $unblockterms[1]); } // now unblock the terms foreach ($this->terms["un$type"] as $value){ $keys = array_keys($this->terms[$type], $value); if (count($keys)>0){ foreach ($keys as $key) unset($this->terms[$type][$key]); } } } function makeRegexTerms() { foreach ($this->rawtexts as $text){ // Make an array of text that follows "regex:" incl spaces & punct preg_match_all('/regex:(.+)/', $text, $regexterms); $this->terms['regex'] = array_merge($this->terms['regex'], $regexterms[1]); } } function checkBlockTerms() { //compares entries in the blocklist to the post content // Check posted page content against blocklist // Note: matches only on first, not repeated, offenses-per-criteria // If score/reasons are not being tallied, break out. foreach ($this->terms['block'] as $blockitem){ if (stristr(@$_POST['text'], $blockitem)) { $this->Blockcount++; if ($this->why == 0) return; $this->whymsg .= $this->textmsg . $blockitem . "\n"; } } } function checkRegexTerms() { //compares entries in the regex list to the post content // Note: matches only on first, not repeated, offenses-per-criteria // If score/reasons are not being tallied, break out. foreach ($this->terms['regex'] as $oneregex){ if (preg_match($oneregex, @$_POST['text'], $regexmatch)) { $this->Blockcount++; if ($this->why == 0) return; $this->whymsg .= $this->textmsg . $regexmatch[0] . "\n"; } } } function printMessages(){ global $EnablePost; global $MessagesFmt; $EnablePost = 0; unset($_POST['post']); unset($_POST['postattr']); unset($_POST['postedit']); // let the poster know they've been blocked $MessagesFmt[] .= $this->blockmsg; // if required, provide reasons if ($this->why == 1) $MessagesFmt[] = '
' . $this->whymsg . "
"; } }