Rev 5 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
4 | # |
||
5 | # generic Whois - Subprogram "cu" |
||
6 | # |
||
7 | # (c) 2011 by Daniel Marschall, ViaThinkSoft <www.viathinksoft.de> |
||
8 | # |
||
9 | # Distribution, usage etc. pp. regulated by the current version of GPL. |
||
10 | # |
||
11 | # |
||
12 | # |
||
13 | # History: |
||
14 | # 2011-06-07 mar Initial release |
||
15 | # 2012-01-16 mar Fixed uppercase(). Added non-available-detection |
||
16 | # |
||
17 | |||
18 | require_once __DIR__ . '/../../shared/php_includes/common_functions.inc.php'; |
||
19 | |||
20 | $domain = isset($argv[1]) ? $argv[1] : ''; |
||
21 | |||
22 | define('BEGIN', '<!-- InstanceBeginEditable name="MainRgn" -->'); |
||
23 | define('END', '<!-- InstanceEndEditable -->'); |
||
24 | |||
25 | $url = "http://www.nic.cu/dom_det.php?domsrch=$domain"; |
||
26 | |||
27 | $res = "% Parsing via regex from '$url'\n\n"; |
||
28 | |||
29 | $x = file_get_contents2($url); |
||
30 | |||
31 | preg_match_all('@'.preg_quote(BEGIN, '@').'(.*)'.preg_quote(END, '@').'@ismU', $x, $m); |
||
32 | |||
33 | if (!isset($m[1][0])) { |
||
34 | echo "Error while parsing the web content. Could not find limitations.\n"; |
||
35 | exit(1); |
||
36 | } |
||
37 | |||
38 | $x = $m[1][0]; |
||
39 | |||
40 | $x = strip_tags($x); |
||
41 | |||
42 | // é -> É @ strtoupper() |
||
43 | /* |
||
44 | $locals = array('es_ES@euro', 'es_ES', 'es'); |
||
45 | reset($locals); |
||
46 | while (list(, $locale) = each ($locals)) { |
||
47 | if ( setlocale(LC_CTYPE, $locale) == $locale ) { |
||
48 | break; // Exit when we were successfull |
||
49 | } |
||
50 | } |
||
51 | */ |
||
52 | |||
53 | $x = str_replace(' ', ' ', $x); |
||
54 | |||
55 | $x = html_entity_decode($x); |
||
56 | |||
57 | $x = preg_replace("| +|", ' ', $x); |
||
58 | $x = preg_replace("|\n *|", "\n", $x); |
||
59 | $x = preg_replace("| *\n|", "\n", $x); |
||
60 | $x = preg_replace("|\n+|", "\n", $x); |
||
61 | |||
62 | $x = str_replace(":\n", ": ", $x); |
||
63 | |||
64 | $special_words = array( |
||
65 | 'Detalles del dominio', |
||
66 | 'Información general del dominio', |
||
67 | 'DNS Primario', |
||
68 | 'Contacto Técnico', |
||
69 | 'Contacto Administrativo', |
||
70 | 'Contacto Financiero' |
||
71 | ); |
||
72 | |||
73 | foreach ($special_words as $s) { |
||
74 | $x = str_replace($s, "\n".uc_latin1($s)."\n", $x); |
||
75 | } |
||
76 | |||
77 | $x = str_replace('< Regresar a la página anterior', '', $x); |
||
78 | |||
79 | $x = make_tabs($x); |
||
80 | |||
81 | $x = trim($x); |
||
82 | |||
83 | if (strpos($x, 'Dominio: Organización: Dirección:') !== false) { |
||
84 | $x = 'Domain does not exist.'; |
||
85 | } |
||
86 | |||
87 | #does not work... |
||
88 | #if ($x == 'DETALLES DEL DOMINIO\n\nINFORMACIÓN GENERAL DEL DOMINIO\n\nDominio: Organización: Dirección:\n\nDNS\nNombre: Dirección IP:\nContacto\nNombre: Organización: Dirección: Teléfono: Fax:') { |
||
89 | if (md5($x) == '82f755ffa4a436159afec22d69be304c') { |
||
90 | $x = 'Domain not available.'; |
||
91 | } |
||
92 | |||
93 | echo $res.trim_each_line($x)."\n"; |