2 // $Id: spam.php,v 1.194 2007/06/29 13:58:29 henoheno Exp $
3 // Copyright (C) 2006-2007 PukiWiki Developers Team
4 // License: GPL v2 or (at your option) any later version
6 // Functions for Concept-work of spam-uri metrics
8 // (PHP 4 >= 4.3.0): preg_match_all(PREG_OFFSET_CAPTURE): $method['uri_XXX'] related feature
10 if (! defined('SPAM_INI_FILE')) define('SPAM_INI_FILE', 'spam.ini.php');
11 if (! defined('DOMAIN_INI_FILE')) define('DOMAIN_INI_FILE', 'domain.ini.php');
13 // ---------------------
16 // (PHP 4 >= 4.2.0): var_export(): mail-reporting and dump related
17 if (! function_exists('var_export')) {
18 function var_export() {
19 return 'var_export() is not found on this server' . "\n";
23 // (PHP 4 >= 4.2.0): preg_grep() enables invert option
24 function preg_grep_invert($pattern = '//', $input = array())
27 if (! isset($invert)) $invert = defined('PREG_GREP_INVERT');
30 return preg_grep($pattern, $input, PREG_GREP_INVERT);
32 $result = preg_grep($pattern, $input);
34 return array_diff($input, preg_grep($pattern, $input));
43 // Very roughly, shrink the lines of var_export()
44 // NOTE: If the same data exists, it must be corrupted.
45 function var_export_shrink($expression, $return = FALSE, $ignore_numeric_keys = FALSE)
47 $result = var_export($expression, TRUE);
49 $result = preg_replace(
50 // Remove a newline and spaces
51 '# => \n *array \(#', ' => array (',
55 if ($ignore_numeric_keys) {
56 $result =preg_replace(
57 // Remove numeric keys
58 '#^( *)[0-9]+ => #m', '$1',
71 // Remove redundant values from array()
72 function array_unique_recursive($array = array())
74 if (! is_array($array)) return $array;
77 foreach($array as $key => $value){
78 if (is_array($value)) {
79 $array[$key] = array_unique_recursive($value);
81 if (isset($tmp[$value])) {
92 // Renumber all numeric keys from 0
93 function array_renumber_numeric_keys(& $array)
95 if (! is_array($array)) return $array;
99 foreach($array as $key => $value){
100 if (is_array($value)) array_renumber_numeric_keys($array[$key]); // Recurse
101 if (is_numeric($key)) $tmp[$key] = ++$count;
103 array_rename_keys($array, $tmp);
108 // Roughly strings(1) using PCRE
109 // This function is useful to:
110 // * Reduce the size of data, from removing unprintable binary data
111 // * Detect _bare_strings_ from binary data
113 // http://www.freebsd.org/cgi/man.cgi?query=strings (Man-page of GNU strings)
114 // http://www.pcre.org/pcre.txt
115 // Note: mb_ereg_replace() is one of mbstring extension's functions
116 // and need to init its encoding.
117 function strings($binary = '', $min_len = 4, $ignore_space = FALSE, $multibyte = FALSE)
120 $binary = (is_array($binary) || $binary === TRUE) ? '' : strval($binary);
122 $regex = $ignore_space ?
123 '[^[:graph:] \t\n]+' : // Remove "\0" etc, and readable spaces
124 '[^[:graph:][:space:]]+'; // Preserve readable spaces if possible
126 $binary = $multibyte ?
127 mb_ereg_replace($regex, "\n", $binary) :
128 preg_replace('/' . $regex . '/s', "\n", $binary);
131 $binary = preg_replace(
146 // The last character seems "\n" or not
147 $br = (! empty($binary) && $binary[strlen($binary) - 1] == "\n") ? "\n" : '';
149 $min_len = min(1024, intval($min_len));
150 $regex = '/^.{' . $min_len . ',}/S';
151 $binary = implode("\n", preg_grep($regex, explode("\n", $binary))) . $br;
157 // Reverse $string with specified delimiter
158 function delimiter_reverse($string = 'foo.bar.example.com', $from_delim = '.', $to_delim = '.')
160 if (! is_string($string) || ! is_string($from_delim) || ! is_string($to_delim))
163 // com.example.bar.foo
164 return implode($to_delim, array_reverse(explode($from_delim, $string)));
168 // ---------------------
171 // Return an array of URIs in the $string
172 // [OK] http://nasty.example.org#nasty_string
173 // [OK] http://nasty.example.org:80/foo/xxx#nasty_string/bar
174 // [OK] ftp://nasty.example.org:80/dfsdfs
175 // [OK] ftp://cnn.example.com&story=breaking_news@10.0.0.1/top_story.htm (from RFC3986)
176 function uri_pickup($string = '')
178 if (! is_string($string)) return array();
180 // Not available for: IDN(ignored)
183 // scheme://userinfo@host:port/path/or/pathinfo/maybefile.and?query=string#fragment
184 // Refer RFC3986 (Regex below is not strict)
185 '#(\b[a-z][a-z0-9.+-]{1,8}):[/\\\]+' . // 1: Scheme
187 '([^\s<>"\'\[\]/\#?@]*)' . // 2: Userinfo (Username)
191 '\[[0-9a-f:.]+\]' . '|' . // IPv6([colon-hex and dot]): RFC2732
192 '(?:[0-9]{1,3}\.){3}[0-9]{1,3}' . '|' . // IPv4(dot-decimal): 001.22.3.44
193 '[a-z0-9_-][a-z0-9_.-]+[a-z0-9_-]' . // hostname(FQDN) : foo.example.org
195 '(?::([0-9]*))?' . // 4: Port
196 '((?:/+[^\s<>"\'\[\]/\#]+)*/+)?' . // 5: Directory path or path-info
197 '([^\s<>"\'\[\]\#?]+)?' . // 6: File?
198 '(?:\?([^\s<>"\'\[\]\#]+))?' . // 7: Query string
199 '(?:\#([a-z0-9._~%!$&\'()*+,;=:@-]*))?' . // 8: Fragment
201 $string, $array, PREG_SET_ORDER | PREG_OFFSET_CAPTURE
205 static $parts = array(
206 1 => 'scheme', 2 => 'userinfo', 3 => 'host', 4 => 'port',
207 5 => 'path', 6 => 'file', 7 => 'query', 8 => 'fragment'
209 $default = array('');
210 foreach(array_keys($array) as $uri) {
211 $_uri = & $array[$uri];
212 array_rename_keys($_uri, $parts, TRUE, $default);
213 $offset = $_uri['scheme'][1]; // Scheme's offset = URI's offset
214 foreach(array_keys($_uri) as $part) {
215 $_uri[$part] = & $_uri[$part][0]; // Remove offsets
219 foreach(array_keys($array) as $uri) {
220 $_uri = & $array[$uri];
221 if ($_uri['scheme'] === '') {
222 unset($array[$uri]); // Considererd harmless
225 unset($_uri[0]); // Matched string itself
226 $_uri['area']['offset'] = $offset; // Area offset for area_measure()
232 // Normalize an array of URI arrays
233 // NOTE: Give me the uri_pickup() results
234 function uri_pickup_normalize(& $pickups, $destructive = TRUE)
236 if (! is_array($pickups)) return $pickups;
239 foreach (array_keys($pickups) as $key) {
240 $_key = & $pickups[$key];
241 $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
242 $_key['host'] = isset($_key['host']) ? host_normalize($_key['host']) : '';
243 $_key['port'] = isset($_key['port']) ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
244 $_key['path'] = isset($_key['path']) ? strtolower(path_normalize($_key['path'])) : '';
245 $_key['file'] = isset($_key['file']) ? file_normalize($_key['file']) : '';
246 $_key['query'] = isset($_key['query']) ? query_normalize($_key['query']) : '';
247 $_key['fragment'] = isset($_key['fragment']) ? strtolower($_key['fragment']) : '';
250 foreach (array_keys($pickups) as $key) {
251 $_key = & $pickups[$key];
252 $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
253 $_key['host'] = isset($_key['host']) ? strtolower($_key['host']) : '';
254 $_key['port'] = isset($_key['port']) ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
255 $_key['path'] = isset($_key['path']) ? path_normalize($_key['path']) : '';
262 // An URI array => An URI (See uri_pickup())
264 // $pickups = uri_pickup('a string include some URIs');
266 // foreach (array_keys($pickups) as $key) {
267 // $uris[$key] = uri_pickup_implode($pickups[$key]);
269 function uri_pickup_implode($uri = array())
271 if (empty($uri) || ! is_array($uri)) return NULL;
274 if (isset($uri['scheme']) && $uri['scheme'] !== '') {
275 $tmp[] = & $uri['scheme'];
278 if (isset($uri['userinfo']) && $uri['userinfo'] !== '') {
279 $tmp[] = & $uri['userinfo'];
282 if (isset($uri['host']) && $uri['host'] !== '') {
283 $tmp[] = & $uri['host'];
285 if (isset($uri['port']) && $uri['port'] !== '') {
287 $tmp[] = & $uri['port'];
289 if (isset($uri['path']) && $uri['path'] !== '') {
290 $tmp[] = & $uri['path'];
292 if (isset($uri['file']) && $uri['file'] !== '') {
293 $tmp[] = & $uri['file'];
295 if (isset($uri['query']) && $uri['query'] !== '') {
297 $tmp[] = & $uri['query'];
299 if (isset($uri['fragment']) && $uri['fragment'] !== '') {
301 $tmp[] = & $uri['fragment'];
304 return implode('', $tmp);
307 // $array['something'] => $array['wanted']
308 function array_rename_keys(& $array, $keys = array('from' => 'to'), $force = FALSE, $default = '')
310 if (! is_array($array) || ! is_array($keys)) return FALSE;
312 // Nondestructive test
314 foreach(array_keys($keys) as $from)
315 if (! isset($array[$from]))
318 foreach($keys as $from => $to) {
319 if ($from === $to) continue;
320 if (! $force || isset($array[$from])) {
321 $array[$to] = & $array[$from];
322 unset($array[$from]);
324 $array[$to] = $default;
331 // ---------------------
334 // Pickup all of markup areas
335 function area_pickup($string = '', $method = array())
338 if (empty($method)) return $area;
340 // Anchor tag pair by preg_match and preg_match_all()
342 // [OK] <a href= >Good site!</a>
343 // [OK] <a href= "#" >test</a>
344 // [OK] <a href="http://nasty.example.com">visit http://nasty.example.com/</a>
345 // [OK] <a href=\'http://nasty.example.com/\' >discount foobar</a>
346 // [NG] <a href="http://ng.example.com">visit http://ng.example.com _not_ended_
347 $regex = '#<a\b[^>]*\bhref\b[^>]*>.*?</a\b[^>]*(>)#is';
348 if (isset($method['area_anchor'])) {
350 $count = isset($method['asap']) ?
351 preg_match($regex, $string) :
352 preg_match_all($regex, $string, $areas);
353 if (! empty($count)) $area['area_anchor'] = $count;
355 if (isset($method['uri_anchor'])) {
357 preg_match_all($regex, $string, $areas, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
358 foreach(array_keys($areas) as $_area) {
359 $areas[$_area] = array(
360 $areas[$_area][0][1], // Area start (<a href>)
361 $areas[$_area][1][1], // Area end (</a>)
364 if (! empty($areas)) $area['uri_anchor'] = $areas;
367 // phpBB's "BBCode" pair by preg_match and preg_match_all()
369 // [OK] [url]http://nasty.example.com/[/url]
370 // [OK] [link]http://nasty.example.com/[/link]
371 // [OK] [url=http://nasty.example.com]visit http://nasty.example.com/[/url]
372 // [OK] [link http://nasty.example.com/]buy something[/link]
373 $regex = '#\[(url|link)\b[^\]]*\].*?\[/\1\b[^\]]*(\])#is';
374 if (isset($method['area_bbcode'])) {
376 $count = isset($method['asap']) ?
377 preg_match($regex, $string) :
378 preg_match_all($regex, $string, $areas, PREG_SET_ORDER);
379 if (! empty($count)) $area['area_bbcode'] = $count;
381 if (isset($method['uri_bbcode'])) {
383 preg_match_all($regex, $string, $areas, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
384 foreach(array_keys($areas) as $_area) {
385 $areas[$_area] = array(
386 $areas[$_area][0][1], // Area start ([url])
387 $areas[$_area][2][1], // Area end ([/url])
390 if (! empty($areas)) $area['uri_bbcode'] = $areas;
393 // Various Wiki syntax
394 // [text_or_uri>text_or_uri]
395 // [text_or_uri:text_or_uri]
396 // [text_or_uri|text_or_uri]
397 // [text_or_uri->text_or_uri]
398 // [text_or_uri text_or_uri] // MediaWiki
399 // MediaWiki: [http://nasty.example.com/ visit http://nasty.example.com/]
404 // If in doubt, it's a little doubtful
405 // if (Area => inside <= Area) $brief += -1
406 function area_measure($areas, & $array, $belief = -1, $a_key = 'area', $o_key = 'offset')
408 if (! is_array($areas) || ! is_array($array)) return;
410 $areas_keys = array_keys($areas);
411 foreach(array_keys($array) as $u_index) {
412 $offset = isset($array[$u_index][$o_key]) ?
413 intval($array[$u_index][$o_key]) : 0;
414 foreach($areas_keys as $a_index) {
415 if (isset($array[$u_index][$a_key])) {
416 $offset_s = intval($areas[$a_index][0]);
417 $offset_e = intval($areas[$a_index][1]);
418 // [Area => inside <= Area]
419 if ($offset_s < $offset && $offset < $offset_e) {
420 $array[$u_index][$a_key] += $belief;
427 // ---------------------
430 // Preprocess: Removing uninterest part for URI detection
431 function spam_uri_removing_hocus_pocus($binary = '', $method = array())
433 $length = 4 ; // 'http'(1) and '://'(2) and 'fqdn'(1)
434 if (is_array($method)) {
435 // '<a'(2) or 'href='(5) or '>'(1) or '</a>'(4)
436 // '[uri'(4) or ']'(1) or '[/uri]'(6)
437 if (isset($method['area_anchor']) || isset($method['uri_anchor']) ||
438 isset($method['area_bbcode']) || isset($method['uri_bbcode']))
439 $length = 1; // Seems not effective
442 // Removing sequential spaces and too short lines
443 $binary = strings($binary, $length, TRUE, FALSE); // Multibyte NOT needed
445 // Remove words (has no '<>[]:') between spaces
446 $binary = preg_replace('/[ \t][\w.,()\ \t]+[ \t]/', ' ', $binary);
451 // Preprocess: Domain exposure callback (See spam_uri_pickup_preprocess())
452 // http://victim.example.org/?foo+site:nasty.example.com+bar
453 // => http://nasty.example.com/?refer=victim.example.org
454 // NOTE: 'refer=' is not so good for (at this time).
455 // Consider about using IP address of the victim, try to avoid that.
456 function _preg_replace_callback_domain_exposure($matches = array())
460 // Preserve the victim URI as a complicity or ...
461 if (isset($matches[5])) {
463 $matches[1] . '://' . // scheme
464 $matches[2] . '/' . // victim.example.org
465 $matches[3]; // The rest of all (before victim)
469 if (isset($matches[4])) {
471 $matches[1] . '://' . // scheme
472 $matches[4] . // nasty.example.com
473 '/?refer=' . strtolower($matches[2]) . // victim.example.org
480 // Preprocess: rawurldecode() and adding space(s) and something
481 // to detect/count some URIs _if possible_
482 // NOTE: It's maybe danger to var_dump(result). [e.g. 'javascript:']
483 // [OK] http://victim.example.org/?site:nasty.example.org
484 // [OK] http://victim.example.org/nasty.example.org
485 // [OK] http://victim.example.org/go?http%3A%2F%2Fnasty.example.org
486 // [OK] http://victim.example.org/http://nasty.example.org
487 function spam_uri_pickup_preprocess($string = '', $method = array())
489 if (! is_string($string)) return '';
491 $string = spam_uri_removing_hocus_pocus(rawurldecode($string), $method);
492 //var_dump(htmlspecialchars($string));
494 // Domain exposure (simple)
495 // http://victim.example.org/nasty.example.org/path#frag
496 // => http://nasty.example.org/?refer=victim.example.org and original
497 $string = preg_replace(
500 'ime\.nu' . '|' . // 2ch.net
501 'ime\.st' . '|' . // 2ch.net
502 'link\.toolbot\.com' . '|' .
505 '/([a-z0-9.%_-]+\.[a-z0-9.%_-]+)#i', // nasty.example.org
506 'http://$2/?refer=$1 $0', // Preserve $0 or remove?
510 // Domain exposure (gate-big5)
511 // http://victim.example.org/gate/big5/nasty.example.org/path
512 // => http://nasty.example.org/?refer=victim.example.org and original
513 $string = preg_replace(
516 'big5.51job.com' . '|' .
517 'big5.china.com' . '|' .
518 'big5.xinhuanet.com' . '|' .
521 '/([a-z0-9.%_-]+\.[a-z0-9.%_-]+)' .
522 '#i', // nasty.example.org
523 'http://$2/?refer=$1 $0', // Preserve $0 or remove?
527 // Domain exposure (See _preg_replace_callback_domain_exposure())
528 $string = preg_replace_callback(
530 '#(http)://' . // 1:Scheme
533 // Something Google: http://www.google.com/supported_domains
534 '(?:[a-z0-9.]+\.)?google\.[a-z]{2,3}(?:\.[a-z]{2})?' .
537 // http://es.altavista.com/web/results?q=site%3Anasty.example.org+foobar
538 '(?:[a-z0-9.]+\.)?altavista.com' .
544 // http://sads.myspace.com/Modules/Search/Pages/Search.aspx?_snip_&searchString=site:nasty.example.org
545 // also searchresults.myspace.com
546 '(?:[a-z0-9.]+\.)?myspace.com' .
548 'search.orange.co.uk' .
553 '([a-z0-9?=&.%_/\'\\\+-]+)' . // 3:path/?query=foo+bar+
554 '\bsite:([a-z0-9.%_-]+\.[a-z0-9.%_-]+)' . // 4:site:nasty.example.com
555 '()' . // 5:Preserve or remove?
558 '_preg_replace_callback_domain_exposure',
562 // URI exposure (uriuri => uri uri)
563 $string = preg_replace(
565 '#(?<! )(?:https?|ftp):/#i',
566 // '#[a-z][a-z0-9.+-]{1,8}://#i',
567 // '#[a-z][a-z0-9.+-]{1,8}://#i'
576 // Main function of spam-uri pickup,
577 // A wrapper function of uri_pickup()
578 function spam_uri_pickup($string = '', $method = array())
580 if (! is_array($method) || empty($method)) {
581 $method = check_uri_spam_method();
584 $string = spam_uri_pickup_preprocess($string, $method);
586 $array = uri_pickup($string);
588 // Area elevation of URIs, for '(especially external)link' intension
589 if (! empty($array)) {
591 if (isset($method['uri_anchor'])) $_method['uri_anchor'] = & $method['uri_anchor'];
592 if (isset($method['uri_bbcode'])) $_method['uri_bbcode'] = & $method['uri_bbcode'];
593 $areas = area_pickup($string, $_method, TRUE);
594 if (! empty($areas)) {
595 $area_shadow = array();
596 foreach (array_keys($array) as $key) {
597 $area_shadow[$key] = & $array[$key]['area'];
598 foreach (array_keys($_method) as $_key) {
599 $area_shadow[$key][$_key] = 0;
602 foreach (array_keys($_method) as $_key) {
603 if (isset($areas[$_key])) {
604 area_measure($areas[$_key], $area_shadow, 1, $_key);
610 // Remove 'offset's for area_measure()
611 foreach(array_keys($array) as $key)
612 unset($array[$key]['area']['offset']);
618 // ---------------------
621 // Scheme normalization: Renaming the schemes
622 // snntp://example.org => nntps://example.org
623 // NOTE: Keep the static lists simple. See also port_normalize().
624 function scheme_normalize($scheme = '', $abbrevs_harmfull = TRUE)
626 // Abbreviations they have no intention of link
627 static $abbrevs = array(
632 // Aliases => normalized ones
633 static $aliases = array(
643 if (! is_string($scheme)) return '';
645 $scheme = strtolower($scheme);
646 if (isset($abbrevs[$scheme])) {
647 $scheme = $abbrevs_harmfull ? $abbrevs[$scheme] : '';
649 if (isset($aliases[$scheme])) {
650 $scheme = $aliases[$scheme];
656 // Hostname normlization (Destructive)
657 // www.foo => www.foo ('foo' seems TLD)
658 // www.foo.bar => foo.bar
659 // www.10.20 => www.10.20 (Invalid hostname)
661 // 'www' is mostly used as traditional hostname of WWW server.
662 // 'www.foo.bar' may be identical with 'foo.bar'.
663 function host_normalize($host = '')
665 if (! is_string($host)) return '';
667 $host = strtolower($host);
669 if (preg_match('/^www\.(.+\.[a-z]+)$/', $host, $matches)) {
676 // Port normalization: Suppress the (redundant) default port
677 // HTTP://example.org:80/ => http://example.org/
678 // HTTP://example.org:8080/ => http://example.org:8080/
679 // HTTPS://example.org:443/ => https://example.org/
680 function port_normalize($port, $scheme, $scheme_normalize = FALSE)
682 // Schemes that users _maybe_ want to add protocol-handlers
683 // to their web browsers. (and attackers _maybe_ want to use ...)
684 // Reference: http://www.iana.org/assignments/port-numbers
685 static $array = array(
686 // scheme => default port
712 // intval() converts '0-1' to '0', so preg_match() rejects these invalid ones
713 if (! is_numeric($port) || $port < 0 || preg_match('/[^0-9]/i', $port))
716 $port = intval($port);
717 if ($scheme_normalize) $scheme = scheme_normalize($scheme);
718 if (isset($array[$scheme]) && $port == $array[$scheme])
719 $port = ''; // Ignore the defaults
724 // Path normalization
725 // http://example.org => http://example.org/
726 // http://example.org#hoge => http://example.org/#hoge
727 // http://example.org/path/a/b/./c////./d => http://example.org/path/a/b/c/d
728 // http://example.org/path/../../a/../back => http://example.org/back
729 function path_normalize($path = '', $divider = '/', $add_root = TRUE)
731 if (! is_string($divider)) return is_string($path) ? $path : '';
734 $first_div = & $divider;
738 if (! is_string($path) || $path == '') return $first_div;
740 if (strpos($path, $divider, strlen($path) - strlen($divider)) === FALSE) {
743 $last_div = & $divider;
746 $array = explode($divider, $path);
748 // Remove paddings ('//' and '/./')
749 foreach(array_keys($array) as $key) {
750 if ($array[$key] == '' || $array[$key] == '.') {
755 // Remove back-tracks ('/../')
757 foreach($array as $value) {
758 if ($value == '..') {
761 array_push($tmp, $value);
769 return $first_div . implode($divider, $array) . $last_div;
773 // DirectoryIndex normalize (Destructive and rough)
774 // TODO: sample.en.ja.html.gz => sample.html
775 function file_normalize($file = 'index.html.en')
777 static $simple_defaults = array(
778 'default.htm' => TRUE,
779 'default.html' => TRUE,
780 'default.asp' => TRUE,
781 'default.aspx' => TRUE,
782 'index' => TRUE, // Some system can omit the suffix
785 static $content_suffix = array(
786 // index.xxx, sample.xxx
801 static $language_suffix = array(
802 // Reference: Apache 2.0.59 'AddLanguage' default
831 // Reference: Apache 2.0.59 default 'index.html' variants
837 static $charset_suffix = array(
838 // Reference: Apache 2.0.59 'AddCharset' default
839 'iso8859-1' => TRUE, // ISO-8859-1
840 'latin1' => TRUE, // ISO-8859-1
841 'iso8859-2' => TRUE, // ISO-8859-2
842 'latin2' => TRUE, // ISO-8859-2
843 'cen' => TRUE, // ISO-8859-2
844 'iso8859-3' => TRUE, // ISO-8859-3
845 'latin3' => TRUE, // ISO-8859-3
846 'iso8859-4' => TRUE, // ISO-8859-4
847 'latin4' => TRUE, // ISO-8859-4
848 'iso8859-5' => TRUE, // ISO-8859-5
849 'latin5' => TRUE, // ISO-8859-5
850 'cyr' => TRUE, // ISO-8859-5
851 'iso-ru' => TRUE, // ISO-8859-5
852 'iso8859-6' => TRUE, // ISO-8859-6
853 'latin6' => TRUE, // ISO-8859-6
854 'arb' => TRUE, // ISO-8859-6
855 'iso8859-7' => TRUE, // ISO-8859-7
856 'latin7' => TRUE, // ISO-8859-7
857 'grk' => TRUE, // ISO-8859-7
858 'iso8859-8' => TRUE, // ISO-8859-8
859 'latin8' => TRUE, // ISO-8859-8
860 'heb' => TRUE, // ISO-8859-8
861 'iso8859-9' => TRUE, // ISO-8859-9
862 'latin9' => TRUE, // ISO-8859-9
863 'trk' => TRUE, // ISO-8859-9
864 'iso2022-jp'=> TRUE, // ISO-2022-JP
865 'jis' => TRUE, // ISO-2022-JP
866 'iso2022-kr'=> TRUE, // ISO-2022-KR
867 'kis' => TRUE, // ISO-2022-KR
868 'iso2022-cn'=> TRUE, // ISO-2022-CN
869 'cis' => TRUE, // ISO-2022-CN
871 'cp-1251' => TRUE, // ru, WINDOWS-1251
872 'win-1251' => TRUE, // ru, WINDOWS-1251
873 'cp866' => TRUE, // ru
874 'koi8-r' => TRUE, // ru, KOI8-r
875 'koi8-ru' => TRUE, // ru, KOI8-r
876 'koi8-uk' => TRUE, // ru, KOI8-ru
877 'ua' => TRUE, // ru, KOI8-ru
878 'ucs2' => TRUE, // ru, ISO-10646-UCS-2
879 'ucs4' => TRUE, // ru, ISO-10646-UCS-4
882 // Reference: Apache 2.0.59 default 'index.html' variants
887 // May uncompress by web browsers on the fly
888 // Must be at the last of the filename
889 // Reference: Apache 2.0.59 'AddEncoding'
890 static $encoding_suffix = array(
895 if (! is_string($file)) return '';
896 $_file = strtolower($file);
897 if (isset($simple_defaults[$_file])) return '';
900 // Roughly removing language/character-set/encoding suffixes
902 // * Apache 2 document about 'Content-negotiaton', 'mod_mime' and 'mod_negotiation'
903 // http://httpd.apache.org/docs/2.0/content-negotiation.html
904 // http://httpd.apache.org/docs/2.0/mod/mod_mime.html
905 // http://httpd.apache.org/docs/2.0/mod/mod_negotiation.html
906 // * http://www.iana.org/assignments/character-sets
907 // * RFC3066: Tags for the Identification of Languages
908 // http://www.ietf.org/rfc/rfc3066.txt
909 // * ISO 639: codes of 'language names'
910 $suffixes = explode('.', $_file);
911 $body = array_shift($suffixes);
913 // Remove the last .gz/.z
914 $last_key = end(array_keys($suffixes));
915 if (isset($encoding_suffix[$suffixes[$last_key]])) {
916 unset($suffixes[$last_key]);
919 // Cut language and charset suffixes
920 foreach($suffixes as $key => $value){
921 if (isset($language_suffix[$value]) || isset($charset_suffix[$value])) {
922 unset($suffixes[$key]);
925 if (empty($suffixes)) return $body;
928 $count = count($suffixes);
930 $current = current($suffixes);
931 if ($body == 'index' && $count == 1 && isset($content_suffix[$current])) return '';
936 // Sort query-strings if possible (Destructive and rough)
937 // [OK] &&&&f=d&b&d&c&a=0dd => a=0dd&b&c&d&f=d
938 // [OK] nothing==&eg=dummy&eg=padding&eg=foobar => eg=foobar
939 function query_normalize($string = '', $equal = TRUE, $equal_cutempty = TRUE, $stortolower = TRUE)
941 if (! is_string($string)) return '';
942 if ($stortolower) $string = strtolower($string);
944 $array = explode('&', $string);
946 // Remove '&' paddings
947 foreach(array_keys($array) as $key) {
948 if ($array[$key] == '') {
953 // Consider '='-sepalated input and paddings
955 $equals = $not_equals = array();
956 foreach ($array as $part) {
957 if (strpos($part, '=') === FALSE) {
958 $not_equals[] = $part;
960 list($key, $value) = explode('=', $part, 2);
961 $value = ltrim($value, '=');
962 if (! $equal_cutempty || $value != '') {
963 $equals[$key] = $value;
968 $array = & $not_equals;
969 foreach ($equals as $key => $value) {
970 $array[] = $key . '=' . $value;
976 return implode('&', $array);
979 // ---------------------
980 // Part One : Checker
982 // Rough implementation of globbing
984 // USAGE: $regex = '/^' . generate_glob_regex('*.txt', '/') . '$/i';
986 function generate_glob_regex($string = '', $divider = '/')
988 static $from = array(
991 // 22 => '[', // Maybe cause regex compilation error (e.g. '[]')
1007 if (! is_string($string)) return '';
1009 $string = str_replace($from, $mid, $string); // Hide
1010 $string = preg_quote($string, $divider);
1011 $string = str_replace($mid, $to, $string); // Unhide
1016 // Rough hostname checker
1018 // TODO: Strict digit, 0x, CIDR, IPv6
1019 function is_ip($string = '')
1021 if (preg_match('/^' .
1022 '(?:[0-9]{1,3}\.){3}[0-9]{1,3}' . '|' .
1023 '(?:[0-9]{1,3}\.){1,3}' . '$/',
1025 return 4; // Seems IPv4(dot-decimal)
1027 return 0; // Seems not IP
1031 // Generate host (FQDN, IPv4, ...) regex
1032 // 'localhost' : Matches with 'localhost' only
1033 // 'example.org' : Matches with 'example.org' only (See host_normalize() about 'www')
1034 // '.example.org' : Matches with ALL FQDN ended with '.example.org'
1035 // '*.example.org' : Almost the same of '.example.org' except 'www.example.org'
1036 // '10.20.30.40' : Matches with IPv4 address '10.20.30.40' only
1037 // [TODO] '192.' : Matches with all IPv4 hosts started with '192.'
1038 // TODO: IPv4, CIDR?, IPv6
1039 function generate_host_regex($string = '', $divider = '/')
1041 if (! is_string($string)) return '';
1043 if (mb_strpos($string, '.') === FALSE)
1044 return generate_glob_regex($string, $divider);
1047 if (is_ip($string)) {
1049 return generate_glob_regex($string, $divider);
1051 // FQDN or something
1052 $part = explode('.', $string, 2);
1053 if ($part[0] == '') {
1054 $part[0] = '(?:.*\.)?'; // And all related FQDN
1055 } else if ($part[0] == '*') {
1056 $part[0] = '.*\.'; // All subdomains/hosts only
1058 return generate_glob_regex($string, $divider);
1060 $part[1] = generate_glob_regex($part[1], $divider);
1061 return implode('', $part);
1065 function get_blocklist($list = '')
1069 if ($list === NULL) {
1070 $regexes = NULL; // Unset
1074 if (! isset($regexes)) {
1076 if (file_exists(SPAM_INI_FILE)) {
1077 $blocklist = array();
1078 include(SPAM_INI_FILE);
1079 // $blocklist['badhost'] = array(
1080 // '*.blogspot.com', // Blog services's subdomains (only)
1081 // 'IANA-examples' => '#^(?:.*\.)?example\.(?:com|net|org)$#',
1083 if (isset($blocklist['list'])) {
1084 $regexes['list'] = & $blocklist['list'];
1087 $blocklist['list'] = array(
1088 'goodhost' => FALSE,
1092 foreach(array_keys($blocklist['list']) as $_list) {
1093 if (! isset($blocklist[$_list])) continue;
1094 foreach ($blocklist[$_list] as $key => $value) {
1095 if (is_array($value)) {
1096 $regexes[$_list][$key] = array();
1097 foreach($value as $_key => $_value) {
1098 get_blocklist_add($regexes[$_list][$key], $_key, $_value);
1101 get_blocklist_add($regexes[$_list], $key, $value);
1104 unset($blocklist[$_list]);
1110 return $regexes; // ALL
1111 } else if (isset($regexes[$list])) {
1112 return $regexes[$list];
1118 // Subroutine of get_blocklist()
1119 function get_blocklist_add(& $array, $key = 0, $value = '*.example.org')
1121 if (is_string($key)) {
1122 $array[$key] = & $value; // Treat $value as a regex
1124 $array[$value] = '/^' . generate_host_regex($value, '/') . '$/i';
1128 // Blocklist metrics: Separate $host, to $blocked and not blocked
1129 function blocklist_distiller(& $hosts, $keys = array('goodhost', 'badhost'), $asap = FALSE)
1131 if (! is_array($hosts)) $hosts = array($hosts);
1132 if (! is_array($keys)) $keys = array($keys);
1134 $list = get_blocklist('list');
1137 foreach($keys as $key){
1138 foreach (get_blocklist($key) as $label => $regex) {
1139 if (is_array($regex)) {
1140 foreach($regex as $_label => $_regex) {
1141 $group = preg_grep($_regex, $hosts);
1143 $hosts = array_diff($hosts, $group);
1144 $blocked[$key][$label][$_label] = $group;
1145 if ($asap && $list[$key]) break;
1149 $group = preg_grep($regex, $hosts);
1151 $hosts = array_diff($hosts, $group);
1152 $blocked[$key][$label] = $group;
1153 if ($asap && $list[$key]) break;
1162 // Default (enabled) methods and thresholds (for content insertion)
1163 function check_uri_spam_method($times = 1, $t_area = 0, $rule = TRUE)
1165 $times = intval($times);
1166 $t_area = intval($t_area);
1170 'quantity' => 8 * $times, // Allow N URIs
1171 'non_uniqhost' => 3 * $times, // Allow N duped (and normalized) Hosts
1172 //'non_uniquri'=> 3 * $times, // Allow N duped (and normalized) URIs
1175 'area_anchor' => $t_area, // Using <a href> HTML tag
1176 'area_bbcode' => $t_area, // Using [url] or [link] BBCode
1177 //'uri_anchor' => $t_area, // URI inside <a href> HTML tag
1178 //'uri_bbcode' => $t_area, // URI inside [url] or [link] BBCode
1183 //'asap' => TRUE, // Quit or return As Soon As Possible
1184 'uniqhost' => TRUE, // Show uniq host (at block notification mail)
1185 'badhost' => TRUE, // Check badhost
1191 // Remove non-$positive values
1192 foreach (array_keys($positive) as $key) {
1193 if ($positive[$key] < 0) unset($positive[$key]);
1196 return $positive + $bool;
1199 // Simple/fast spam check
1200 function check_uri_spam($target = '', $method = array())
1205 // Theme to do => Dummy, optional value, or optional array()
1207 //'uniqhost' => TRUE,
1208 //'non_uniqhost'=> 3,
1209 //'non_uniquri' => 3,
1210 //'badhost' => TRUE,
1211 //'area_anchor' => 0,
1212 //'area_bbcode' => 0,
1213 //'uri_anchor' => 0,
1214 //'uri_bbcode' => 0,
1217 // Theme => Volume found (int)
1220 // Flag. If someting defined here,
1221 // one or more spam will be included
1226 //'category' => array(
1231 // Hosts not blocked
1236 $sum = & $progress['sum'];
1237 $is_spam = & $progress['is_spam'];
1238 $progress['method'] = & $method; // Argument
1239 $blocked = & $progress['blocked'];
1240 $hosts = & $progress['hosts'];
1241 $asap = isset($method['asap']);
1244 if (! is_array($method) || empty($method)) {
1245 $method = check_uri_spam_method();
1247 foreach(array_keys($method) as $key) {
1248 if (! isset($sum[$key])) $sum[$key] = 0;
1250 if (! isset($sum['quantity'])) $sum['quantity'] = 0;
1252 if (is_array($target)) {
1253 foreach($target as $str) {
1254 if (! is_string($str)) continue;
1256 $_progress = check_uri_spam($str, $method); // Recurse
1259 $_sum = & $_progress['sum'];
1260 foreach (array_keys($_sum) as $key) {
1261 if (! isset($sum[$key])) {
1262 $sum[$key] = & $_sum[$key];
1264 $sum[$key] += $_sum[$key];
1269 $_is_spam = & $_progress['is_spam'];
1270 foreach (array_keys($_is_spam) as $key) {
1271 $is_spam[$key] = TRUE;
1274 if ($asap && $is_spam) break;
1277 $blocked = array_merge_recursive($blocked, $_progress['blocked']);
1278 $hosts = array_merge_recursive($hosts, $_progress['hosts']);
1282 $blocked = array_unique_recursive($blocked);
1283 $hosts = array_unique_recursive($hosts);
1285 // Recount $sum['badhost']
1286 $sum['badhost'] = array_count_leaves($blocked);
1291 // Area: There's HTML anchor tag
1292 if ((! $asap || ! $is_spam) && isset($method['area_anchor'])) {
1293 $key = 'area_anchor';
1294 $_asap = isset($method['asap']) ? array('asap' => TRUE) : array();
1295 $result = area_pickup($target, array($key => TRUE) + $_asap);
1297 $sum[$key] = $result[$key];
1298 if (isset($method[$key]) && $sum[$key] > $method[$key]) {
1299 $is_spam[$key] = TRUE;
1304 // Area: There's 'BBCode' linking tag
1305 if ((! $asap || ! $is_spam) && isset($method['area_bbcode'])) {
1306 $key = 'area_bbcode';
1307 $_asap = isset($method['asap']) ? array('asap' => TRUE) : array();
1308 $result = area_pickup($target, array($key => TRUE) + $_asap);
1310 $sum[$key] = $result[$key];
1311 if (isset($method[$key]) && $sum[$key] > $method[$key]) {
1312 $is_spam[$key] = TRUE;
1318 if ($asap && $is_spam) return $progress;
1321 $pickups = uri_pickup_normalize(spam_uri_pickup($target, $method));
1324 if (empty($pickups)) return $progress;
1326 // URI: Check quantity
1327 $sum['quantity'] += count($pickups);
1329 if ((! $asap || ! $is_spam) && isset($method['quantity']) &&
1330 $sum['quantity'] > $method['quantity']) {
1331 $is_spam['quantity'] = TRUE;
1334 // URI: used inside HTML anchor tag pair
1335 if ((! $asap || ! $is_spam) && isset($method['uri_anchor'])) {
1336 $key = 'uri_anchor';
1337 foreach($pickups as $pickup) {
1338 if (isset($pickup['area'][$key])) {
1339 $sum[$key] += $pickup['area'][$key];
1340 if(isset($method[$key]) &&
1341 $sum[$key] > $method[$key]) {
1342 $is_spam[$key] = TRUE;
1343 if ($asap && $is_spam) break;
1345 if ($asap && $is_spam) break;
1350 // URI: used inside 'BBCode' pair
1351 if ((! $asap || ! $is_spam) && isset($method['uri_bbcode'])) {
1352 $key = 'uri_bbcode';
1353 foreach($pickups as $pickup) {
1354 if (isset($pickup['area'][$key])) {
1355 $sum[$key] += $pickup['area'][$key];
1356 if(isset($method[$key]) &&
1357 $sum[$key] > $method[$key]) {
1358 $is_spam[$key] = TRUE;
1359 if ($asap && $is_spam) break;
1361 if ($asap && $is_spam) break;
1366 // URI: Uniqueness (and removing non-uniques)
1367 if ((! $asap || ! $is_spam) && isset($method['non_uniquri'])) {
1370 foreach (array_keys($pickups) as $key) {
1371 $uris[$key] = uri_pickup_implode($pickups[$key]);
1373 $count = count($uris);
1374 $uris = array_unique($uris);
1375 $sum['non_uniquri'] += $count - count($uris);
1376 if ($sum['non_uniquri'] > $method['non_uniquri']) {
1377 $is_spam['non_uniquri'] = TRUE;
1379 if (! $asap || ! $is_spam) {
1380 foreach (array_diff(array_keys($pickups),
1381 array_keys($uris)) as $remove) {
1382 unset($pickups[$remove]);
1389 if ($asap && $is_spam) return $progress;
1391 // Host: Uniqueness (uniq / non-uniq)
1392 foreach ($pickups as $pickup) $hosts[] = & $pickup['host'];
1393 $hosts = array_unique($hosts);
1394 $sum['uniqhost'] += count($hosts);
1395 if ((! $asap || ! $is_spam) && isset($method['non_uniqhost'])) {
1396 $sum['non_uniqhost'] = $sum['quantity'] - $sum['uniqhost'];
1397 if ($sum['non_uniqhost'] > $method['non_uniqhost']) {
1398 $is_spam['non_uniqhost'] = TRUE;
1403 if ($asap && $is_spam) return $progress;
1405 // URI: Bad host (Separate good/bad hosts from $hosts)
1406 if ((! $asap || ! $is_spam) && isset($method['badhost'])) {
1409 $list = get_blocklist('list');
1410 $blocked = blocklist_distiller($hosts, array_keys($list), $asap);
1411 foreach($list as $key=>$type){
1412 if (! $type) unset($blocked[$key]); // Ignore goodhost etc
1416 if (! empty($blocked)) $is_spam['badhost'] = TRUE;
1422 // Count leaves (A leaf = value that is not an array, or an empty array)
1423 function array_count_leaves($array = array(), $count_empty = FALSE)
1425 if (! is_array($array) || (empty($array) && $count_empty)) return 1;
1429 foreach ($array as $part) {
1430 $count += array_count_leaves($part, $count_empty);
1435 // An array-leaves to a flat array
1436 function array_flat_leaves($array, $unique = TRUE)
1438 if (! is_array($array)) return $array;
1441 foreach(array_keys($array) as $key) {
1442 if (is_array($array[$key])) {
1444 foreach(array_flat_leaves($array[$key]) as $_value) {
1448 $tmp[] = & $array[$key];
1452 return $unique ? array_values(array_unique($tmp)) : $tmp;
1455 // An array() to an array leaf
1456 function array_leaf($array = array('A', 'B', 'C.D'), $stem = FALSE, $edge = TRUE)
1458 if (! is_array($array)) return $array;
1462 foreach($array as $arg) {
1463 if (! is_string($arg) && ! is_int($arg)) continue;
1464 $tmp[$arg] = array();
1466 $tmp = & $tmp[$arg];
1469 $parent[key($parent)] = & $edge;
1471 $parent = key($parent);
1474 return $leaf; // array('A' => array('B' => 'C.D'))
1478 // ---------------------
1481 // Summarize $progress (blocked only)
1482 function summarize_spam_progress($progress = array(), $blockedonly = FALSE)
1485 $tmp = array_keys($progress['is_spam']);
1488 $method = & $progress['method'];
1489 if (isset($progress['sum'])) {
1490 foreach ($progress['sum'] as $key => $value) {
1491 if (isset($method[$key]) && $value) {
1492 $tmp[] = $key . '(' . $value . ')';
1498 return implode(', ', $tmp);
1501 function summarize_detail_badhost($progress = array())
1503 if (! isset($progress['blocked']) || empty($progress['blocked'])) return '';
1507 foreach($progress['blocked'] as $list => $lvalue) {
1508 foreach($lvalue as $group => $gvalue) {
1509 $flat = implode(', ', array_flat_leaves($gvalue));
1510 if ($flat === $group) {
1511 $blocked[$list][] = $flat;
1513 $blocked[$list][$group] = $flat;
1519 // From: 'A-1' => array('ie.to')
1520 // To: 'A-1' => 'ie.to'
1521 foreach($blocked as $list => $lvalue) {
1522 if (is_array($lvalue) &&
1523 count($lvalue) == 1 &&
1524 is_numeric(key($lvalue))) {
1525 $blocked[$list] = current($lvalue);
1529 return var_export_shrink($blocked, TRUE, TRUE);
1532 function summarize_detail_newtral($progress = array())
1534 if (! isset($progress['hosts']) ||
1535 ! is_array($progress['hosts']) ||
1536 empty($progress['hosts'])) return '';
1538 // Generate a responsible $trie
1540 foreach($progress['hosts'] as $value) {
1541 // 'A.foo.bar.example.com'
1542 $resp = whois_responsibility($value); // 'example.com'
1544 // One or more test, or do nothing here
1545 $resp = strval($value);
1548 $rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'A.foo.bar'
1550 $trie = array_merge_recursive($trie, array($resp => array($rest => NULL)));
1553 // Format: var_export_shrink() -like output
1555 ksort_by_domain($trie);
1556 foreach(array_keys($trie) as $key) {
1557 ksort_by_domain($trie[$key]);
1558 if (count($trie[$key]) == 1 && key($trie[$key]) == '') {
1559 // Just one 'responsibility.example.com'
1560 $result[] = ' \'' . $key . '\',';
1562 // One subdomain-or-host, or several ones
1564 foreach(array_keys($trie[$key]) as $sub) {
1568 $subs[] = $sub . '.' . $key;
1571 $result[] = ' \'' . $key . '\' => \'' . implode(', ', $subs) . '\',';
1577 implode("\n", $result) . "\n" .
1581 // ksort() by domain
1582 function ksort_by_domain(& $array)
1585 foreach(array_keys($array) as $key) {
1586 $sort[delimiter_reverse($key)] = $key;
1588 ksort($sort, SORT_STRING);
1590 foreach($sort as $key) {
1591 $result[$key] = & $array[$key];
1596 // Check responsibility-root of the FQDN
1597 // 'foo.bar.example.com' => 'example.com' (.com has the last whois for it)
1598 // 'foo.bar.example.au' => 'example.au' (.au has the last whois for it)
1599 // 'foo.bar.example.edu.au' => 'example.edu.au' (.edu.au has the last whois for it)
1600 // 'foo.bar.example.act.edu.au' => 'example.act.edu.au' (.act.edu.au has the last whois for it)
1601 function whois_responsibility($fqdn = 'foo.bar.example.com', $parent = FALSE, $implicit = TRUE)
1605 if ($fqdn === NULL) {
1606 $domain = NULL; // Unset
1609 if (! is_string($fqdn)) return '';
1611 if (is_ip($fqdn)) return $fqdn;
1613 if (! isset($domain)) {
1615 if (file_exists(DOMAIN_INI_FILE)) {
1616 include(DOMAIN_INI_FILE); // Set
1621 $dcursor = & $domain;
1622 $array = array_reverse(explode('.', $fqdn));
1625 if (! isset($array[$i])) break;
1626 $acursor = $array[$i];
1627 if (is_array($dcursor) && isset($dcursor[$acursor])) {
1628 $result[] = & $array[$i];
1629 $dcursor = & $dcursor[$acursor];
1631 if (! $parent && isset($acursor)) {
1632 $result[] = & $array[$i]; // Whois servers must know this subdomain
1639 // Implicit responsibility: Top-Level-Domains must not be yours
1640 // 'bar.foo.something' => 'foo.something'
1641 if ($implicit && count($result) == 1 && count($array) > 1) {
1642 $result[] = & $array[1];
1645 return $result ? implode('.', array_reverse($result)) : '';
1649 // ---------------------
1653 function spam_dispose()
1655 get_blocklist(NULL);
1656 whois_responsibility(NULL);
1659 // Common bahavior for blocking
1660 // NOTE: Call this function from various blocking feature, to disgueise the reason 'why blocked'
1661 function spam_exit($mode = '', $data = array())
1670 echo('<pre>' . "\n");
1671 echo htmlspecialchars(var_export($data, TRUE));
1672 echo('</pre>' . "\n");
1676 if ($exit) exit; // Force exit
1680 // ---------------------
1683 // TODO: Record them
1684 // Simple/fast spam filter ($target: 'a string' or an array())
1685 function pkwk_spamfilter($action, $page, $target = array('title' => ''), $method = array(), $exitmode = '')
1687 $progress = check_uri_spam($target, $method);
1689 if (empty($progress['is_spam'])) {
1693 // TODO: detect encoding from $target for mbstring functions
1695 // foreach(array_keys($target) as $key) {
1696 // $tmp[strings($key, 0, FALSE, TRUE)] = strings($target[$key], 0, FALSE, TRUE); // Removing "\0" etc
1698 // $target = & $tmp;
1700 pkwk_spamnotify($action, $page, $target, $progress, $method);
1701 spam_exit($exitmode, $progress);
1705 // ---------------------
1706 // PukiWiki original
1708 // Mail to administrator(s)
1709 function pkwk_spamnotify($action, $page, $target = array('title' => ''), $progress = array(), $method = array())
1711 global $notify, $notify_subject;
1713 if (! $notify) return;
1715 $asap = isset($method['asap']);
1717 $summary['ACTION'] = 'Blocked by: ' . summarize_spam_progress($progress, TRUE);
1719 $summary['METRICS'] = summarize_spam_progress($progress);
1722 $tmp = summarize_detail_badhost($progress);
1723 if ($tmp != '') $summary['DETAIL_BADHOST'] = $tmp;
1725 $tmp = summarize_detail_newtral($progress);
1726 if (! $asap && $tmp != '') $summary['DETAIL_NEUTRAL_HOST'] = $tmp;
1728 $summary['COMMENT'] = $action;
1729 $summary['PAGE'] = '[blocked] ' . (is_pagename($page) ? $page : '');
1730 $summary['URI'] = get_script_uri() . '?' . rawurlencode($page);
1731 $summary['USER_AGENT'] = TRUE;
1732 $summary['REMOTE_ADDR'] = TRUE;
1733 pkwk_mail_notify($notify_subject, var_export($target, TRUE), $summary, TRUE);