OSDN Git Service

.ru, .tz, .za
[pukiwiki/pukiwiki_sandbox.git] / spam / spam.php
index 8739d2a..128fbfa 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: spam.php,v 1.183 2007/06/16 13:50:30 henoheno Exp $
+// $Id: spam.php,v 1.191 2007/06/24 03:13:09 henoheno Exp $
 // Copyright (C) 2006-2007 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 //
@@ -189,7 +189,7 @@ function uri_pickup($string = '')
                        // 3: Host
                        '\[[0-9a-f:.]+\]' . '|' .                               // IPv6([colon-hex and dot]): RFC2732
                        '(?:[0-9]{1,3}\.){3}[0-9]{1,3}' . '|' . // IPv4(dot-decimal): 001.22.3.44
-                       '[a-z0-9][a-z0-9.-]+[a-z0-9]' .                 // hostname(FQDN) : foo.example.org
+                       '[a-z0-9_-][a-z0-9_.-]+[a-z0-9_-]' .            // hostname(FQDN) : foo.example.org
                ')' .
                '(?::([0-9]*))?' .                                      // 4: Port
                '((?:/+[^\s<>"\'\[\]/\#]+)*/+)?' .      // 5: Directory path or path-info
@@ -1521,54 +1521,47 @@ function summarize_detail_newtral($progress = array())
            ! is_array($progress['hosts']) ||
            empty($progress['hosts'])) return '';
 
-       $result = '';
-
        // Generate a responsible $trie
        $trie = array();
        foreach($progress['hosts'] as $value) {
-
-               // array('example.com', 'bar', 'foo')
+               // 'A.foo.bar.example.com'
                $resp = whois_responsibility($value);   // 'example.com'
-               $rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'foo.bar'
-               if ($rest) {
-                       $parts = explode('.', delimiter_reverse('.' . $rest));
-                       array_unshift($parts, $resp);
+               if (empty($resp)) {
+                       // One or more test, or do nothing here
+                       $resp = strval($value);
+                       $rest = '';
                } else {
-                       $parts = array($resp, $rest);
-               }
-
-               $trie = array_merge_recursive(
-                       $trie,
-                       array_leaf($parts, TRUE, $value)
-               );
-       }
-
-       // Sort and flatten -- 'A.foo.bar.example.com, B.foo.bar.example.com'
-       foreach(array_keys($trie) as $key) {
-               if (is_array($trie[$key])) {
-                       ksort_by_domain($trie[$key]);
-
-                       $trie[$key] = implode(', ', array_flat_leaves($trie[$key]));
-                       //$trie[$key] = var_export($trie[$key], TRUE);  // DEBUG
+                       $rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'A.foo.bar'
                }
+               $trie = array_merge_recursive($trie, array($resp => array($rest => NULL)));
        }
 
+       // Format: var_export_shrink() -like output
+       $result = array();
        ksort_by_domain($trie);
-
-       // Format: From array('foobar' => 'foobar') to 'foobar'
-       $tmp = array();
-       foreach($trie as $key => $value) {
-               if ($trie[$key] == $key) {
-                       // 'responsibility.example.com'
-                       $tmp[] = '  \'' . $key . '\',';
+       foreach(array_keys($trie) as $key) {
+               ksort_by_domain($trie[$key]);
+               if (count($trie[$key]) == 1 && key($trie[$key]) == '') {
+                       // Just one 'responsibility.example.com'
+                       $result[] = '  \'' . $key . '\',';
                } else {
-                       // 'subdomain-or-host.responsibility.example.com'
-                       $tmp[] = '  \'.' . $key . '\' => \'' . $trie[$key] . '\',';
+                       // One subdomain-or-host, or several ones
+                       $subs = array();
+                       foreach(array_keys($trie[$key]) as $sub) {
+                               if ($sub == '') {
+                                       $subs[] = $key;
+                               } else {
+                                       $subs[] = $sub . '.' . $key;
+                               }
+                       }
+                       $result[] = '  \'' . $key . '\' => \'' . implode(', ', $subs) . '\',';
                }
                unset($trie[$key]);
        }
-
-       return 'array (' . "\n" . implode("\n", $tmp) . "\n" . ')';
+       return
+               'array (' . "\n" .
+                       implode("\n", $result) . "\n" .
+               ')';
 }
 
 // ksort() by domain
@@ -1635,6 +1628,17 @@ function whois_responsibility($fqdn = 'foo.bar.example.com', $parent = FALSE, $i
                        'info'  => TRUE,
                ),
 
+               // ccTLD: Bahrain
+               // NIC  : http://www.inet.com.bh/ (.bh policies not found)
+               // Whois: (Not available) http://www.inet.com.bh/
+               'bh' => array(
+                       // Observed
+                       'com' => TRUE,
+                       'edu' => TRUE,
+                       'gov' => TRUE,
+                       'org' => TRUE,
+               ),
+
                // ccTLD: China
                // NIC  : http://www.cnnic.net.cn/en/index/
                // Whois: http://ewhois.cnnic.cn/
@@ -1687,6 +1691,25 @@ function whois_responsibility($fqdn = 'foo.bar.example.com', $parent = FALSE, $i
                        'zj' => TRUE,
                ),
 
+               // ccTLD: India
+               // NIC  : http://www.inregistry.in/
+               // Whois: http://www.inregistry.in/whois_search/
+               'in' => array(
+                       // Policies http://www.inregistry.in/policies/
+                       'ac'   => TRUE,
+                       'co'   => TRUE,
+                       'firm' => TRUE,
+                       'gen'  => TRUE,
+                       'gov'  => TRUE,
+                       'ind'  => TRUE,
+                       'mil'  => TRUE,
+                       'net'  => TRUE,
+                       'org'  => TRUE,
+                       'res'  => TRUE,
+                       // Reserved Names by the government (for the 2nd level)
+                       // http://www.inregistry.in/policies/reserved_names
+               ),
+
                // ccTLD: South Korea
                // NIC  : http://www.nic.or.kr/english/
                // Whois: http://whois.nida.or.kr/english/
@@ -1739,6 +1762,7 @@ function whois_responsibility($fqdn = 'foo.bar.example.com', $parent = FALSE, $i
                        'ac' => TRUE,
                        'ad' => TRUE,
                        'co' => TRUE,
+                       'ed' => TRUE,
                        'go' => TRUE,
                        'gr' => TRUE,
                        'lg' => TRUE,
@@ -1812,6 +1836,211 @@ function whois_responsibility($fqdn = 'foo.bar.example.com', $parent = FALSE, $i
                        'yokohama'  => TRUE,
                ),
 
+               // ccTLD: Mexico
+               // NIC  : http://www.nic.mx/
+               // Whois: http://www.nic.mx/es/Busqueda.Who_Is
+               'mx' => array(
+                       // Politicas Generales de Nombres de Dominio
+                       // http://www.nic.mx/es/Politicas?CATEGORY=INDICE
+                       'com'  => TRUE,
+                       'edu'  => TRUE,
+                       'gob'  => TRUE,
+                       'net'  => TRUE,
+                       'org'  => TRUE,
+               ),
+
+               // ccTLD: Russia
+               // NIC  : http://www.cctld.ru/en/
+               // Whois: http://www.ripn.net:8080/nic/whois/en/
+               'ru' => array(
+                       // List of Reserved second-level Domain Names
+                       // http://www.cctld.ru/en/doc/detail.php?id21=20&i21=2
+
+                       // Organizational
+                       'ac'   => TRUE,
+                       'com'  => TRUE,
+                       'edu'  => TRUE,
+                       'gov'  => TRUE,
+                       'int'  => TRUE,
+                       'mil'  => TRUE,
+                       'net'  => TRUE,
+                       'org'  => TRUE,
+                       'pp'   => TRUE,
+                       //'test' => TRUE,
+
+                       // Geographic
+                       'adygeya'     => TRUE,
+                       'altai'       => TRUE,
+                       'amur'        => TRUE,
+                       'amursk'      => TRUE,
+                       'arkhangelsk' => TRUE,
+                       'astrakhan'   => TRUE,
+                       'baikal'      => TRUE,
+                       'bashkiria'   => TRUE,
+                       'belgorod'    => TRUE,
+                       'bir'         => TRUE,
+                       'bryansk'     => TRUE,
+                       'buryatia'    => TRUE,
+                       'cbg'         => TRUE,
+                       'chel'        => TRUE,
+                       'chelyabinsk' => TRUE,
+                       'chita'       => TRUE,
+                       'chukotka'    => TRUE,
+                       'chuvashia'   => TRUE,
+                       'cmw'         => TRUE,
+                       'dagestan'    => TRUE,
+                       'dudinka'     => TRUE,
+                       'e-burg'      => TRUE,
+                       'fareast'     => TRUE,
+                       'grozny'      => TRUE,
+                       'irkutsk'     => TRUE,
+                       'ivanovo'     => TRUE,
+                       'izhevsk'     => TRUE,
+                       'jamal'       => TRUE,
+                       'jar'         => TRUE,
+                       'joshkar-ola' => TRUE,
+                       'k-uralsk'    => TRUE,
+                       'kalmykia'    => TRUE,
+                       'kaluga'      => TRUE,
+                       'kamchatka'   => TRUE,
+                       'karelia'     => TRUE,
+                       'kazan'       => TRUE,
+                       'kchr'        => TRUE,
+                       'kemerovo'    => TRUE,
+                       'khabarovsk'  => TRUE,
+                       'khakassia'   => TRUE,
+                       'khv'         => TRUE,
+                       'kirov'       => TRUE,
+                       'kms'         => TRUE,
+                       'koenig'      => TRUE,
+                       'komi'        => TRUE,
+                       'kostroma'    => TRUE,
+                       'krasnoyarsk' => TRUE,
+                       'kuban'       => TRUE,
+                       'kurgan'      => TRUE,
+                       'kursk'       => TRUE,
+                       'kustanai'    => TRUE,
+                       'kuzbass'     => TRUE,
+                       'lipetsk'     => TRUE,
+                       'magadan'     => TRUE,
+                       'magnitka'    => TRUE,
+                       'mari-el'     => TRUE,
+                       'mari'        => TRUE,
+                       'marine'      => TRUE,
+                       'mordovia'    => TRUE,
+                       'mosreg'      => TRUE,
+                       'msk'         => TRUE,
+                       'murmansk'    => TRUE,
+                       'mytis'       => TRUE,
+                       'nakhodka'    => TRUE,
+                       'nalchik'     => TRUE,
+                       'nkz'         => TRUE,
+                       'nnov'        => TRUE,
+                       'norilsk'     => TRUE,
+                       'nov'         => TRUE,
+                       'novosibirsk' => TRUE,
+                       'nsk'         => TRUE,
+                       'omsk'        => TRUE,
+                       'orenburg'    => TRUE,
+                       'oryol'       => TRUE,
+                       'oskol'       => TRUE,
+                       'palana'      => TRUE,
+                       'penza'       => TRUE,
+                       'perm'        => TRUE,
+                       'pskov'       => TRUE,
+                       'ptz'         => TRUE,
+                       'pyatigorsk'  => TRUE,
+                       'rnd'         => TRUE,
+                       'rubtsovsk'   => TRUE,
+                       'ryazan'      => TRUE,
+                       'sakhalin'    => TRUE,
+                       'samara'      => TRUE,
+                       'saratov'     => TRUE,
+                       'simbirsk'    => TRUE,
+                       'smolensk'    => TRUE,
+                       'snz'         => TRUE,
+                       'spb'         => TRUE,
+                       'stavropol'   => TRUE,
+                       'stv'         => TRUE,
+                       'surgut'      => TRUE,
+                       'syzran'      => TRUE,
+                       'tambov'      => TRUE,
+                       'tatarstan'   => TRUE,
+                       'tom'         => TRUE,
+                       'tomsk'       => TRUE,
+                       'tsaritsyn'   => TRUE,
+                       'tsk'         => TRUE,
+                       'tula'        => TRUE,
+                       'tuva'        => TRUE,
+                       'tver'        => TRUE,
+                       'tyumen'      => TRUE,
+                       'udm'         => TRUE,
+                       'udmurtia'    => TRUE,
+                       'ulan-ude'    => TRUE,
+                       'vdonsk'      => TRUE,
+                       'vladikavkaz' => TRUE,
+                       'vladimir'    => TRUE,
+                       'vladivostok' => TRUE,
+                       'volgograd'   => TRUE,
+                       'vologda'     => TRUE,
+                       'voronezh'    => TRUE,
+                       'vrn'         => TRUE,
+                       'vyatka'      => TRUE,
+                       'yakutia'     => TRUE,
+                       'yamal'       => TRUE,
+                       'yaroslavl'   => TRUE,
+                       'yekaterinburg'     => TRUE,
+                       'yuzhno-sakhalinsk' => TRUE,
+                       'zgrad'       => TRUE,
+               ),
+
+               // ccTLD: Seychelles
+               // NIC  : http://www.nic.sc/
+               // Whois: (Not available)
+               'sc' => array(
+                       // http://www.nic.sc/policies.html
+                       'com' => TRUE,
+                       'edu' => TRUE,
+                       'gov' => TRUE,
+                       'net' => TRUE,
+                       'org' => TRUE,
+               ),
+
+               // ccTLD: Taiwan
+               // NIC  : http://www.twnic.net.tw/
+               // Whois: http://www.twnic.net.tw/
+               'tw' => array(
+                       // Guidelines for Administration of Domain Name Registration
+                       // http://www.twnic.net.tw/english/dn/dn_02.htm
+                       // II. Types of TWNIC Domain Names and Application Requirements
+                       // http://www.twnic.net.tw/english/dn/dn_02_b.htm
+                       'club' => TRUE,
+                       'com'  => TRUE,
+                       'ebiz' => TRUE,
+                       'edu'  => TRUE,
+                       'game' => TRUE,
+                       'gov'  => TRUE,
+                       'idv'  => TRUE,
+                       'mil'  => TRUE,
+                       'net'  => TRUE,
+                       'org'  => TRUE,
+                       // Reserved words for the 2nd level
+                       // http://mydn.twnic.net.tw/en/dn02/INDEX.htm
+               ),
+
+               // ccTLD: Tanzania
+               // NIC  : http://www.psg.com/dns/tz/
+               // Whois: (Not available)
+               'tz' => array(
+                       //  TZ DOMAIN NAMING STRUCTURE
+                       // http://www.psg.com/dns/tz/tz.txt
+                       'ac' => TRUE,
+                       'co' => TRUE,
+                       'go' => TRUE,
+                       'ne' => TRUE,
+                       'or' => TRUE,
+               ),
+
                // ccTLD: Ukraine
                // NIC  : http://www.nic.net.ua/
                // Whois: http://whois.com.ua/
@@ -1971,15 +2200,51 @@ function whois_responsibility($fqdn = 'foo.bar.example.com', $parent = FALSE, $i
                        'wv' => TRUE, // West Virginia
                        'wy' => TRUE, // Wyoming
                ),
+
+               // ccTLD: South Africa
+               // NIC  : http://www.zadna.org.za/
+               // Whois: 
+               //   ac.za  http://www.tenet.ac.za/cgi/cgi_domainquery.exe
+               //   co.za  http://co.za/whois.shtml
+               //   gov.za http://dnsadmin.gov.za/
+               //   org.za http://www.org.za/
+               'za' => array(
+                       // Second-level subdomains of .ZA
+                       // http://www.zadna.org.za/slds.html
+                       'ac'   => TRUE,
+                       'city' => TRUE,
+                       'co'   => TRUE,
+                       'edu'  => TRUE,
+                       'gov'  => TRUE,
+                       'law'  => TRUE,
+                       'mil'  => TRUE,
+                       'nom'  => TRUE,
+                       'org'  => TRUE,
+                       'school' => array(
+                               // Provincial Domains
+                               // http://www.esn.org.za/dns/
+                               'ecape' => TRUE,
+                               'fs.'   => TRUE,
+                               'gp'    => TRUE,
+                               'kzn'   => TRUE,
+                               'lp'    => TRUE,
+                               'mpm'   => TRUE,
+                               'ncape' => TRUE,
+                               'nw'    => TRUE,
+                               'wcape' => TRUE,
+                       ),
+               ),
        );
 
        if (! is_string($fqdn)) return '';
+       if (is_ip($fqdn))       return $fqdn;
 
        $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];
@@ -2016,8 +2281,8 @@ function spam_dispose()
 // NOTE: Call this function from various blocking feature, to disgueise the reason 'why blocked'
 function spam_exit($mode = '', $data = array())
 {
-
        $exit = TRUE;
+
        switch ($mode) {
                case '':
                        echo("\n");