Loading...

Viewing Fixee

Language: PHP (View Plain Text)

March 19, 2012 1:48 am

  1. <?php
  2. /*
  3. Whois.php PHP classes to conduct whois queries
  4.  
  5. Copyright (C)1999,2005 easyDNS Technologies Inc. & Mark Jeftovic
  6.  
  7. Maintained by David Saez (david@ols.es)
  8.  
  9. For the most recent version of this package visit:
  10.  
  11. http://www.phpwhois.org
  12.  
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26. */
  27.  
  28. //-------------------------------------------------------------------------
  29.  
  30. function generic_parser_a ($rawdata, $translate, $contacts, $main='domain', $dateformat='dmy')
  31. {
  32. $blocks = generic_parser_a_blocks($rawdata,$translate,$disclaimer);
  33.  
  34. if (isset($disclaimer) && is_array($disclaimer))
  35. $ret['disclaimer']=$disclaimer;
  36.  
  37. if (empty($blocks) || !is_array(@$blocks['main']))
  38. {
  39. $ret['registered']='no';
  40. return $ret;
  41. }
  42.  
  43. $r=$blocks['main'];
  44.  
  45. $ret['registered']='yes';
  46.  
  47. while (list($key,$val)=each($contacts))
  48. if (isset($r[$key]))
  49. {
  50. if (is_array(@$r[$key]))
  51. $blk=@$r[$key][count(@$r[$key])-1];
  52. else
  53. $blk=@$r[$key];
  54.  
  55. $blk = strtoupper(strtok($blk,' '));
  56. if (isset($blocks[$blk])) $ret[$val] = @$blocks[$blk];
  57. unset($r[$key]);
  58. }
  59.  
  60. if ($main)
  61. $ret[$main]=$r;
  62.  
  63. format_dates($ret,$dateformat);
  64.  
  65. return $ret;
  66. }
  67.  
  68. //-------------------------------------------------------------------------
  69.  
  70. function generic_parser_a_blocks ($rawdata, $translate, &$disclaimer)
  71. {
  72. $r = array();
  73. $newblock = false;
  74. $hasdata = false;
  75. $block = array();
  76. $blocks = false;
  77. $gkey = 'main';
  78. $dend = false;
  79.  
  80. while (list($key,$val)=each($rawdata))
  81. {
  82. $val=trim($val);
  83.  
  84. if ($val != '' && ($val[0] == '%' || $val[0] == '#'))
  85. {
  86. if (!$dend) $disclaimer[]=trim(substr($val,1));
  87. continue;
  88. }
  89. if ($val=='')
  90. {
  91. $newblock=true;
  92. continue;
  93. }
  94. if ($newblock && $hasdata)
  95. {
  96. $blocks[$gkey]=$block;
  97. $block=array();
  98. $gkey='';
  99. }
  100. $dend=true;
  101. $newblock=false;
  102. $k=trim(strtok($val,':'));
  103. $v=trim(substr(strstr($val,':'),1));
  104.  
  105. if ($v=='') continue;
  106.  
  107. $hasdata=true;
  108.  
  109. if (isset($translate[$k]))
  110. {
  111. $k=$translate[$k];
  112. if ($k=='') continue;
  113. if (strstr($k,'.'))
  114. {
  115. eval("\$block".getvarname($k)."=\$v;");
  116. continue;
  117. }
  118. }
  119. else $k=strtolower($k);
  120.  
  121. if ($k=='handle')
  122. {
  123. $v = strtok($v,' ');
  124. $gkey = strtoupper($v);
  125. }
  126.  
  127. if (isset($block[$k]) && is_array($block[$k]))
  128. $block[$k][]=$v;
  129. else
  130. if (!isset($block[$k]) || $block[$k]=='')
  131. $block[$k]=$v;
  132. else
  133. {
  134. $x=$block[$k];
  135. unset($block[$k]);
  136. $block[$k][]=$x;
  137. $block[$k][]=$v;
  138. }
  139. }
  140.  
  141. if ($hasdata) $blocks[$gkey]=$block;
  142.  
  143. return $blocks;
  144. }
  145.  
  146. //-------------------------------------------------------------------------
  147.  
  148. function generic_parser_b ( $rawdata, $items, $dateformat='mdy', $hasreg=true, $scanall=false )
  149.  
  150. {
  151. $r = '';
  152. $disok = true;
  153.  
  154. while (list($key,$val) = each($rawdata))
  155. {
  156. if (trim($val) != '')
  157. {
  158. if (($val[0]=='%' || $val[0]=='#') && $disok)
  159. {
  160. $r['disclaimer'][] = trim(substr($val,1));
  161. $disok = true;
  162. continue;
  163. }
  164.  
  165. $disok = false;
  166. reset($items);
  167.  
  168. while (list($match, $field)=each($items))
  169. {
  170. $pos = strpos($val,$match);
  171.  
  172. if ($pos !== false)
  173. {
  174. if ($field!='')
  175. {
  176. $var = '$r'.getvarname($field);
  177. $itm = trim(substr($val,$pos+strlen($match)));
  178.  
  179. if ($itm!='')
  180. eval($var.'="'.str_replace('"','\"',$itm).'";');
  181. }
  182.  
  183. if (!$scanall)
  184. break;
  185. }
  186. }
  187. }
  188. }
  189.  
  190. if (empty($r))
  191. {
  192. if ($hasreg) $r['registered'] = 'no';
  193. }
  194. else
  195. {
  196. if ($hasreg) $r['registered'] = 'yes';
  197.  
  198. $r = format_dates($r, $dateformat);
  199. }
  200.  
  201. return $r;
  202. }
  203.  
  204. //-------------------------------------------------------------------------
  205.  
  206. function getvarname ( $vdef )
  207. {
  208. $parts=explode(".",$vdef);
  209. $var="";
  210.  
  211. while (list($fn,$mn)=each($parts))
  212. if ($mn=="")
  213. $var=$var."[]";
  214. else $var=$var."[\"".$mn."\"]";
  215.  
  216. return $var;
  217. }
  218.  
  219. //-------------------------------------------------------------------------
  220.  
  221. function get_blocks ( $rawdata, $items, $partial_match = false )
  222. {
  223.  
  224. $r = array();
  225. $endtag='';
  226.  
  227. while (list($key,$val) = each($rawdata))
  228. {
  229. $val = trim($val);
  230. if ($val == '') continue;
  231.  
  232. $found = false;
  233. reset($items);
  234.  
  235. while (list($field, $match) = each($items))
  236. {
  237. $pos = strpos($val,$match);
  238.  
  239. if ($field != '' && $pos !== false)
  240. {
  241. if ($val == $match)
  242. {
  243. $found = true;
  244. $endtag = '';
  245. $line = $val;
  246. break;
  247. }
  248.  
  249. $last = substr($val,-1,1);
  250.  
  251. if ($last == ':' || $last == '-' || $last == ']')
  252. {
  253. $found = true;
  254. $endtag = $last;
  255. $line = $val;
  256. break;
  257. }
  258. else
  259. {
  260. $var = getvarname(strtok($field,'#'));
  261. $itm = trim(substr($val,$pos+strlen($match)));
  262. eval('$r'.$var.'=$itm;');
  263. }
  264. }
  265. }
  266.  
  267. if (!$found) continue;
  268.  
  269. $block = array();
  270.  
  271. // Block found, get data ...
  272.  
  273. while (list($key,$val) = each($rawdata))
  274. {
  275. $val = trim($val);
  276.  
  277. if ($val == '' || $val == str_repeat($val[0],strlen($val))) continue;
  278.  
  279. $last = substr($val,-1,1);
  280.  
  281. if ($last == $endtag) {
  282. // Another block found
  283. prev($rawdata);
  284. break;
  285. }
  286.  
  287. if ($endtag == '' || $partial_match)
  288. {
  289. //Check if this line starts another block
  290. reset($items);
  291. $et = false;
  292.  
  293. while (list($field, $match) = each($items))
  294. {
  295. $pos = strpos($val,$match);
  296.  
  297. if ($pos !== false && $pos == 0)
  298. {
  299. $et = true;
  300. break;
  301. }
  302. }
  303.  
  304. if ($et)
  305. {
  306. // Another block found
  307. prev($rawdata);
  308. break;
  309. }
  310. }
  311.  
  312. $block[]=$val;
  313. }
  314.  
  315. reset($items);
  316.  
  317. if (empty($block)) continue;
  318.  
  319. while (list($field, $match)=each($items))
  320. {
  321. $pos = strpos($line,$match);
  322.  
  323. if ($pos !== false)
  324. {
  325. $var = getvarname(strtok($field,'#'));
  326. if ($var != '[]') eval('$r'.$var.'=$block;');
  327. }
  328. }
  329. }
  330.  
  331. return $r;
  332. }
  333.  
  334. //-------------------------------------------------------------------------
  335.  
  336. function easy_parser($data_str, $items, $date_format, $translate = false ,
  337. $has_org = false, $partial_match = false )
  338. {
  339. $r = get_blocks($data_str, $items, $partial_match);
  340. $r = get_contacts($r, $translate, $has_org);
  341. format_dates($r, $date_format);
  342. return $r;
  343. }
  344.  
  345. //-------------------------------------------------------------------------
  346.  
  347. function get_contacts ( $array, $extra_items='', $has_org= false )
  348. {
  349. if (isset($array['billing']))
  350. $array['billing'] = get_contact($array['billing'], $extra_items, $has_org);
  351.  
  352. if (isset($array['tech']))
  353. $array['tech'] = get_contact($array['tech'], $extra_items, $has_org);
  354.  
  355. if (isset($array['zone']))
  356. $array['zone'] = get_contact($array['zone'], $extra_items, $has_org);
  357.  
  358. if (isset($array['admin']))
  359. $array['admin'] = get_contact($array['admin'], $extra_items, $has_org);
  360.  
  361. if (isset($array['owner']))
  362. $array['owner'] = get_contact($array['owner'], $extra_items, $has_org);
  363.  
  364. return $array;
  365. }
  366.  
  367. //-------------------------------------------------------------------------
  368.  
  369. function get_contact ( $array, $extra_items='', $has_org= false )
  370. {
  371.  
  372. if (!is_array($array))
  373. return array();
  374.  
  375. $items = array (
  376. 'fax..:' => 'fax',
  377. 'fax.' => 'fax',
  378. 'fax -' => 'fax',
  379. 'fax-' => 'fax',
  380. 'fax::' => 'fax',
  381. 'fax:' => 'fax',
  382. '[fax]' => 'fax',
  383. '(fax)' => 'fax',
  384. 'fax' => 'fax',
  385. 'tel.' => 'phone',
  386. 'tel:' => 'phone',
  387. 'phone::' => 'phone',
  388. 'phone:' => 'phone',
  389. 'phone-' => 'phone',
  390. 'phone -' => 'phone',
  391. 'email:' => 'email',
  392. 'e-mail:' => 'email',
  393. 'company name:' => 'organization',
  394. 'first name:' => 'name.first',
  395. 'last name:' => 'name.last',
  396. 'street:' => 'address.street',
  397. 'language:' => '',
  398. 'location:' => 'address.city',
  399. 'country:' => 'address.country',
  400. 'name:' => 'name'
  401. );
  402.  
  403. if ($extra_items)
  404. $items = array_merge($extra_items,$items);
  405.  
  406. while (list($key,$val)=each($array))
  407. {
  408. $ok=true;
  409.  
  410. while ($ok)
  411. {
  412. reset($items);
  413. $ok = false;
  414.  
  415. while (list($match,$field) = each($items))
  416. {
  417. $pos = strpos(strtolower($val),$match);
  418.  
  419. if ($pos === false) continue;
  420.  
  421. $itm = trim(substr($val,$pos+strlen($match)));
  422.  
  423. if ($field != '' && $itm != '')
  424. {
  425. eval('$r'.getvarname($field).'=$itm;');
  426. }
  427.  
  428. $val = trim(substr($val,0,$pos));
  429.  
  430. if ($val == '')
  431. {
  432. unset($array[$key]);
  433. break;
  434. }
  435. else
  436. {
  437. $array[$key] = $val;
  438. $ok = true;
  439. }
  440. //break;
  441. }
  442.  
  443. if (preg_match("/([+]*[-0-9\(\)\. x]){7,}/", $val, $matches))
  444. {
  445. $phone = trim(str_replace(' ','',$matches[0]));
  446.  
  447. if (strlen($phone) > 8 && !preg_match('/[0-9]{5}\-[0-9]{3}/',$phone))
  448. {
  449. if (isset($r['phone']))
  450. {
  451. if (isset($r['fax'])) continue;
  452. $r['fax'] = trim($matches[0]);
  453. }
  454. else
  455. {
  456. $r['phone'] = trim($matches[0]);
  457. }
  458.  
  459. $val = str_replace($matches[0],'',$val);
  460.  
  461. if ($val == '')
  462. {
  463. unset($array[$key]);
  464. continue;
  465. }
  466. else
  467. {
  468. $array[$key] = $val;
  469. $ok = true;
  470. }
  471. }
  472. }
  473.  
  474. if (preg_match('/([-0-9a-zA-Z._+&\/=]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6})/',$val, $matches))
  475. {
  476. $r['email'] = $matches[0];
  477.  
  478. $val = str_replace($matches[0],'',$val);
  479. $val = trim(str_replace('()','',$val));
  480.  
  481. if ($val == '')
  482. {
  483. unset($array[$key]);
  484. continue;
  485. }
  486. else
  487. {
  488. if (!isset($r['name']))
  489. {
  490. $r['name'] = $val;
  491. unset($array[$key]);
  492. }
  493. else
  494. $array[$key] = $val;
  495.  
  496. $ok = true;
  497. }
  498. }
  499. }
  500. }
  501.  
  502. if (!isset($r['name']) && count($array)>0)
  503. {
  504. $r['name'] = array_shift($array);
  505. }
  506.  
  507. if ($has_org && count($array)>0)
  508. {
  509. $r['organization'] = array_shift($array);
  510. }
  511.  
  512. if (isset($r['name']) && is_array(@$r['name']))
  513. {
  514. $r['name'] = implode(@$r['name'],' ');
  515. }
  516.  
  517. if (!empty($array))
  518. {
  519. if (isset($r['address']))
  520. $r['address'] = array_merge(@$r['address'],$array);
  521. else
  522. $r['address'] = $array;
  523. }
  524.  
  525. return $r;
  526. }
  527.  
  528. //-------------------------------------------------------------------------
  529.  
  530. function format_dates (&$res,$format='mdy')
  531. {
  532. if (!is_array($res)) return $res;
  533.  
  534. reset($res);
  535.  
  536. while (list($key, $val) = each($res))
  537. {
  538. if (is_array($val))
  539. {
  540. if (!is_numeric($key) && ($key=='expires' || $key=='created' || $key=='changed'))
  541. {
  542. $res[$key]=get_date($val[0],$format);
  543. }
  544. else
  545. {
  546. $res[$key]=format_dates($val,$format);
  547. }
  548. }
  549. else
  550. {
  551. if (!is_numeric($key) && ($key=='expires' || $key=='created' || $key=='changed'))
  552. {
  553. $res[$key]=get_date($val,$format);
  554. }
  555. }
  556. }
  557.  
  558. return $res;
  559. }
  560.  
  561. //-------------------------------------------------------------------------
  562.  
  563. function get_date($date,$format)
  564. {
  565. $months = array( 'jan'=>1, 'ene'=>1, 'feb'=>2, 'mar'=>3, 'apr'=>4, 'abr'=>4,
  566. 'may'=>5, 'jun'=>6, 'jul'=>7, 'aug'=>8, 'ago'=>8, 'sep'=>9,
  567. 'oct'=>10, 'nov'=>11, 'dec'=>12, 'dic'=>12 );
  568.  
  569. $parts = explode(' ',$date);
  570.  
  571. if (strpos(@$parts[0],'@') !== false)
  572. {
  573. unset($parts[0]);
  574. $date = implode(' ',$parts);
  575. }
  576.  
  577. $date = str_replace(',',' ',trim($date));
  578. $date = str_replace('.',' ',$date);
  579. $date = str_replace('-',' ',$date);
  580. $date = str_replace('/',' ',$date);
  581. $date = str_replace("\t",' ',$date);
  582.  
  583. $parts = explode(' ',$date);
  584.  
  585. if ((strlen(@$parts[0]) == 8 || count($parts) == 1) && is_numeric(@$parts[0]))
  586. {
  587. $val = @$parts[0];
  588. for ($p=$i=0; $i<3; $i++)
  589. {
  590. if ($format[$i] != 'Y')
  591. {
  592. $res[$format[$i]] = substr($val,$p,2);
  593. $p += 2;
  594. }
  595. else
  596. {
  597. $res['y'] = substr($val,$p,4);
  598. $p += 4;
  599. }
  600. }
  601. }
  602. else
  603. {
  604. $format = strtolower($format);
  605.  
  606. for ($p=$i=0; $p<count($parts) && $i<strlen($format); $p++)
  607. {
  608. if (trim(@$parts[$p]) == '')
  609. continue;
  610.  
  611. if ($format[$i] != '-')
  612. {
  613. $res[$format[$i]] = @$parts[$p];
  614. }
  615. $i++;
  616. }
  617. }
  618.  
  619. $ok = false;
  620.  
  621. while (!$ok)
  622. {
  623. reset($res);
  624. $ok = true;
  625.  
  626. while (list($key, $val) = each($res))
  627. {
  628. if ($val == '' || $key == '') continue;
  629.  
  630. if (!is_numeric($val) && isset($months[substr(strtolower($val),0,3)]))
  631. {
  632. $res[$key] = $res['m'];
  633. $res['m'] = $months[substr(strtolower($val),0,3)];
  634. $ok = false;
  635. break;
  636. }
  637.  
  638. if ($key != 'y' && $key != 'Y' && $val > 1900)
  639. {
  640. $res[$key] = $res['y'];
  641. $res['y'] = $val;
  642. $ok = false;
  643. break;
  644. }
  645. }
  646. }
  647.  
  648. if ($res['m'] > 12)
  649. {
  650. $v = $res['m'];
  651. $res['m'] = $res['d'];
  652. $res['d'] = $v;
  653. }
  654.  
  655. if ($res['y'] < 70)
  656. $res['y'] += 2000;
  657. else
  658. if ($res['y'] <= 99)
  659. $res['y'] += 1900;
  660.  
  661. return sprintf("%.4d-%02d-%02d",$res['y'],$res['m'],$res['d']);
  662. }
  663.  
  664. ?>
OriginalFixee
No Fixees have been posted!
As soon as a Fixee is posted, it will appear here automatically.
No need to refresh.