4 Unlike with ../edit/spam_deface, this plugin allows to really block
5 people from adding links. However, you must put the forbidden domain
6 names and URL search patterns on the page named "BlockedLinks"
7 instead. But this allows you to separate between banned and blocked
10 - useful for aggressive link spammers
11 - can be used in conjunction with one of the _deface plugins, but
12 then must be loaded _before_ any of the other ones
15 define("EWIKI_PAGE_BLOCKED", "BlockedLinks");
16 $ewiki_config["info_refs_once"] = 1; // disable {refs} info/ for old versions
18 $ewiki_t["en"]["BLOCKED_URL"] = "Sorry boy, but we couldn't accept your submission, because one or more of the contained links is on our blacklist. All newly submitted have been added, ha ha - and depending on the admins preferences a Google complaint has been sent. Now go away.";
21 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_antispam_urlblock";
22 function ewiki_edit_save_antispam_urlblock(&$save, &$old_data) {
24 global $ewiki_errmsg, $ewiki_id;
25 $BLOCK = EWIKI_PAGE_BLOCKED;
27 preg_match_all('°(http://[^\s*<>"\'\[\]\#]+)°', $save["content"], $save_urls);
28 preg_match_all('°(http://[^\s*<>"\'\[\]\#]+)°', $old_data["content"], $old_urls);
30 $added_urls = array_diff($save_urls[1], $old_urls[1]);
32 foreach ($added_urls as $i=>$url) {
34 #-- test against BannedLinks, then deface (filter page) URL
35 if (ewiki_blocked_link($url, $BLOCK)) {
37 unset($added_urls[$i]);
45 #-- add new URLs to our BannedLinks page
46 if ($new = count($added_urls)) {
48 foreach ($added_urls as $d) {
49 $d = preg_replace('#^.+//(?:www\.)?#', '', $d);
50 $d = preg_replace('#^([^/]+)(/.*)?$*', '$1', $d);
52 $content .= "\n* [$d] (auto-added by spam attack on [$ewiki_id])";
56 ewiki_db::APPEND($BLOCK, $content);
58 $date = strftime("%c", time());
59 ewiki_append_to_page("SpamLog", "\n* spam attack on [$ewiki_id] from $_SERVER[REMOTE_ADDRESS]:$_SERVER[REMOTE_PORT] ($_SERVER[HTTP_USER_AGENT]) happend at $date, around {$new} of the {$old} added URLs were already on BlockedLinks");
62 #-- error reporting method for ["edit_save"]
64 $ewiki_errmsg = ewiki_t("BLOCKED_URL");
71 function ewiki_blocked_link($href, $LinkPage=EWIKI_PAGE_BLOCKED) {
72 global $ewiki_config, $ewiki_plugins;
74 if (! ($href = trim(strtolower(urldecode($href)))) ) {
78 #-- buffer list of banned urls
79 if (!isset($ewiki_config[$LinkPage])) {
80 $data = ewiki_db::GET($LinkPage);
81 $ewiki_config[$LinkPage] = trim(strtolower($data["refs"]));
85 if ($b = &$ewiki_config[$LinkPage]) {
86 if (strpos($b, $href) !== false) { // quick string check
89 foreach (explode("\n", $b) as $bad) { // use as patterns
90 if (strlen($bad) && (strpos($href, $bad) !== false)) {
97 if ($pf_a = $ewiki_plugins["ban_lookup"]) {
98 foreach ($pf_a as $pf) {