(Separate good/bad hosts from $hosts)
+
+ if ((! $asap || ! $is_spam) && isset($method['badhost'])) {
+ $list = get_blocklist('pre');
+ $blocked = blocklist_distiller($hosts, array_keys($list), $asap);
+ foreach($list as $key => $type){
+ if (! $type) unset($blocked[$key]); // Ignore goodhost etc
+ }
+ unset($list);
+ if (! empty($blocked)) $is_spam['badhost'] = TRUE;
+ }
+
+ // Return if ...
+ if ($asap && $is_spam) return $progress;
+
+ // Remove blocked from $pickups
+ foreach(array_keys($pickups) as $key) {
+ if (! isset($hosts[$key])) {
+ unset($pickups[$key]);
+ }
+ }
+
+ // ----------------------------------------
// URI: Check quantity
+
$sum['quantity'] += count($pickups);
// URI quantity
if ((! $asap || ! $is_spam) && isset($method['quantity']) &&
@@ -1323,7 +433,9 @@ function check_uri_spam($target = '', $method = array())
$is_spam['quantity'] = TRUE;
}
+ // ----------------------------------------
// URI: used inside HTML anchor tag pair
+
if ((! $asap || ! $is_spam) && isset($method['uri_anchor'])) {
$key = 'uri_anchor';
foreach($pickups as $pickup) {
@@ -1339,7 +451,9 @@ function check_uri_spam($target = '', $method = array())
}
}
+ // ----------------------------------------
// URI: used inside 'BBCode' pair
+
if ((! $asap || ! $is_spam) && isset($method['uri_bbcode'])) {
$key = 'uri_bbcode';
foreach($pickups as $pickup) {
@@ -1355,7 +469,9 @@ function check_uri_spam($target = '', $method = array())
}
}
+ // ----------------------------------------
// URI: Uniqueness (and removing non-uniques)
+
if ((! $asap || ! $is_spam) && isset($method['non_uniquri'])) {
$uris = array();
@@ -1380,10 +496,12 @@ function check_uri_spam($target = '', $method = array())
// Return if ...
if ($asap && $is_spam) return $progress;
+ // ----------------------------------------
// Host: Uniqueness (uniq / non-uniq)
- foreach ($pickups as $pickup) $hosts[] = & $pickup['host'];
+
$hosts = array_unique($hosts);
- $sum['uniqhost'] += count($hosts);
+
+ if (isset($sum['uniqhost'])) $sum['uniqhost'] += count($hosts);
if ((! $asap || ! $is_spam) && isset($method['non_uniqhost'])) {
$sum['non_uniqhost'] = $sum['quantity'] - $sum['uniqhost'];
if ($sum['non_uniqhost'] > $method['non_uniqhost']) {
@@ -1394,79 +512,32 @@ function check_uri_spam($target = '', $method = array())
// Return if ...
if ($asap && $is_spam) return $progress;
+ // ----------------------------------------
// URI: Bad host (Separate good/bad hosts from $hosts)
- if ((! $asap || ! $is_spam) && isset($method['badhost'])) {
- // is_badhost()
- $list = get_blocklist('list');
- $blocked = blocklist_distiller($hosts, array_keys($list), $asap);
+ if ((! $asap || ! $is_spam) && isset($method['badhost'])) {
+ $list = get_blocklist('list');
+ $blocked = array_merge_leaves(
+ $blocked,
+ blocklist_distiller($hosts, array_keys($list), $asap),
+ FALSE
+ );
foreach($list as $key=>$type){
if (! $type) unset($blocked[$key]); // Ignore goodhost etc
}
unset($list);
-
if (! empty($blocked)) $is_spam['badhost'] = TRUE;
}
- return $progress;
-}
-
-// Count leaves (A leaf = value that is not an array, or an empty array)
-function array_count_leaves($array = array(), $count_empty = FALSE)
-{
- if (! is_array($array) || (empty($array) && $count_empty)) return 1;
-
- // Recurse
- $count = 0;
- foreach ($array as $part) {
- $count += array_count_leaves($part, $count_empty);
- }
- return $count;
-}
-
-// An array-leaves to a flat array
-function array_flat_leaves($array, $unique = TRUE)
-{
- if (! is_array($array)) return $array;
-
- $tmp = array();
- foreach(array_keys($array) as $key) {
- if (is_array($array[$key])) {
- // Recurse
- foreach(array_flat_leaves($array[$key]) as $_value) {
- $tmp[] = $_value;
- }
- } else {
- $tmp[] = & $array[$key];
- }
- }
+ // Return if ...
+ //if ($asap && $is_spam) return $progress;
- return $unique ? array_values(array_unique($tmp)) : $tmp;
-}
+ // ----------------------------------------
+ // End
-// An array() to an array leaf
-function array_leaf($array = array('A', 'B', 'C.D'), $stem = FALSE, $edge = TRUE)
-{
- if (! is_array($array)) return $array;
-
- $leaf = array();
- $tmp = & $leaf;
- foreach($array as $arg) {
- if (! is_string($arg) && ! is_int($arg)) continue;
- $tmp[$arg] = array();
- $parent = & $tmp;
- $tmp = & $tmp[$arg];
- }
- if ($stem) {
- $parent[key($parent)] = & $edge;
- } else {
- $parent = key($parent);
- }
-
- return $leaf; // array('A' => array('B' => 'C.D'))
+ return $progress;
}
-
// ---------------------
// Reporting
@@ -1539,7 +610,7 @@ function summarize_detail_newtral($progress = array())
} else {
$rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'A.foo.bar'
}
- $trie = array_merge_recursive($trie, array($resp => array($rest => NULL)));
+ $trie = array_merge_leaves($trie, array($resp => array($rest => NULL)), FALSE);
}
// Format: var_export_shrink() -like output
@@ -1555,9 +626,9 @@ function summarize_detail_newtral($progress = array())
$subs = array();
foreach(array_keys($trie[$key]) as $sub) {
if ($sub == '') {
- $subs[] = $key;
+ $subs[] = $key; // 'example.com'
} else {
- $subs[] = $sub . '.' . $key;
+ $subs[] = $sub . '. '; // 'A.foo.bar. '
}
}
$result[] = ' \'' . $key . '\' => \'' . implode(', ', $subs) . '\',';
@@ -1570,73 +641,6 @@ function summarize_detail_newtral($progress = array())
')';
}
-// ksort() by domain
-function ksort_by_domain(& $array)
-{
- $sort = array();
- foreach(array_keys($array) as $key) {
- $sort[delimiter_reverse($key)] = $key;
- }
- ksort($sort, SORT_STRING);
- $result = array();
- foreach($sort as $key) {
- $result[$key] = & $array[$key];
- }
- $array = $result;
-}
-
-// Check responsibility-root of the FQDN
-// 'foo.bar.example.com' => 'example.com' (.com has the last whois for it)
-// 'foo.bar.example.au' => 'example.au' (.au has the last whois for it)
-// 'foo.bar.example.edu.au' => 'example.edu.au' (.edu.au has the last whois for it)
-// 'foo.bar.example.act.edu.au' => 'example.act.edu.au' (.act.edu.au has the last whois for it)
-function whois_responsibility($fqdn = 'foo.bar.example.com', $parent = FALSE, $implicit = TRUE)
-{
- static $domain;
-
- if ($fqdn === NULL) {
- $domain = NULL; // Unset
- return '';
- }
- if (! is_string($fqdn)) return '';
-
- if (is_ip($fqdn)) return $fqdn;
-
- if (! isset($domain)) {
- $domain = array();
- if (file_exists(DOMAIN_INI_FILE)) {
- include(DOMAIN_INI_FILE); // Set
- }
- }
-
- $result = array();
- $dcursor = & $domain;
- $array = array_reverse(explode('.', $fqdn));
- $i = 0;
- while(TRUE) {
- if (! isset($array[$i])) break;
- $acursor = $array[$i];
- if (is_array($dcursor) && isset($dcursor[$acursor])) {
- $result[] = & $array[$i];
- $dcursor = & $dcursor[$acursor];
- } else {
- if (! $parent && isset($acursor)) {
- $result[] = & $array[$i]; // Whois servers must know this subdomain
- }
- break;
- }
- ++$i;
- }
-
- // Implicit responsibility: Top-Level-Domains must not be yours
- // 'bar.foo.something' => 'foo.something'
- if ($implicit && count($result) == 1 && count($array) > 1) {
- $result[] = & $array[1];
- }
-
- return $result ? implode('.', array_reverse($result)) : '';
-}
-
// ---------------------
// Exit
@@ -1660,7 +664,7 @@ function spam_exit($mode = '', $data = array())
break;
case 'dump':
echo('' . "\n");
- echo htmlspecialchars(var_export($data, TRUE));
+ echo htmlsc(var_export($data, TRUE));
echo('
' . "\n");
break;
};