PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/cakesocial.local/app/vendors/whois/testsuite.php

https://github.com/miamiruby/cakestuff
PHP | 192 lines | 117 code | 39 blank | 36 comment | 26 complexity | 1e7c843d4246cd16a7b9472d57706bc4 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT
  1. #!/usr/local/bin/php -n
  2. <?php
  3. /*
  4. Whois.php PHP classes to conduct whois queries
  5. Copyright (C)1999,2005 easyDNS Technologies Inc. & Mark Jeftovic
  6. Maintained by David Saez (david@ols.es)
  7. For the most recent version of this package visit:
  8. http://www.phpwhois.org
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. // Read domain list to test
  22. $lines = file('./test.txt');
  23. $domains = array();
  24. foreach ($lines as $key => $line)
  25. {
  26. $pos = strpos($line,'/');
  27. if ($pos !== false) $line = substr($line,0,$pos);
  28. $line = trim($line);
  29. if ($line=='') continue;
  30. $parts = explode(' ',str_replace("\t",' ',$line));
  31. for ($i=1;$i<count($parts);$i++)
  32. if ($parts[$i]!='')
  33. $domains[] = $parts[$i];
  34. }
  35. // Load previous results
  36. $fp = fopen('testsuite.txt','rt');
  37. if (!$fp)
  38. $results = array();
  39. else
  40. {
  41. $results = unserialize(fgets($fp));
  42. fclose($fp);
  43. }
  44. // Test domains
  45. include('whois.main.php');
  46. $whois = new Whois();
  47. set_file_buffer(STDIN, 0);
  48. foreach ($domains as $key => $domain)
  49. {
  50. echo "\nTesting $domain ---------------------------------\n";
  51. $result = $whois->Lookup($domain);
  52. unset($result['rawdata']);
  53. if (!isset($results[$domain]))
  54. {
  55. print_r($result);
  56. $res = get_answer("Add result for $domain");
  57. if ($res)
  58. {
  59. // Add as it is
  60. unset($result['regrinfo']['disclaimer']);
  61. $results[$domain] = $result;
  62. save_results();
  63. }
  64. }
  65. else
  66. {
  67. // Compare with previous result
  68. unset($result['regrinfo']['disclaimer']);
  69. unset($results[$domain]['regrinfo']['disclaimer']);
  70. $diff = array_diff_assoc_recursive($result,$results[$domain]);
  71. if (is_array($diff))
  72. {
  73. print_r($diff);
  74. $res = get_answer("Accept differences for $domain");
  75. if ($res)
  76. {
  77. // Add as it is
  78. $results[$domain] = $result;
  79. save_results();
  80. }
  81. }
  82. else
  83. echo "Handler for domain $domain gives same results as before ...\n";
  84. }
  85. }
  86. save_results();
  87. //--------------------------------------------------------------------------
  88. function save_results()
  89. {
  90. global $results;
  91. $fp = fopen('testsuite.txt','wt');
  92. fputs($fp, serialize($results));
  93. fclose($fp);
  94. }
  95. //--------------------------------------------------------------------------
  96. function get_answer($question)
  97. {
  98. echo "\n------ $question ? (y/n/a/c) ";
  99. while (true)
  100. {
  101. $res = trim(fgetc(STDIN));
  102. if ($res=='a') exit();
  103. if ($res=='c')
  104. {
  105. save_results();
  106. exit();
  107. }
  108. if ($res=='y') return true;
  109. if ($res=='n') return false;
  110. }
  111. }
  112. //--------------------------------------------------------------------------
  113. function array_diff_assoc_recursive($array1, $array2)
  114. {
  115. foreach($array1 as $key => $value)
  116. {
  117. if (is_array($value))
  118. {
  119. if (!is_array($array2[$key]))
  120. {
  121. $difference[$key] = array( 'previous' => $array2[$key], 'actual' => $value);
  122. }
  123. else
  124. {
  125. $new_diff = array_diff_assoc_recursive($value, $array2[$key]);
  126. if ($new_diff != false)
  127. {
  128. $difference[$key] = $new_diff;
  129. }
  130. }
  131. }
  132. else
  133. if (!isset($array2[$key]) || $array2[$key] != $value)
  134. {
  135. $difference[$key] = array( 'previous' => $array2[$key], 'actual' => $value);
  136. }
  137. }
  138. // Search missing items
  139. foreach($array2 as $key => $value)
  140. {
  141. if (!isset($array1[$key]))
  142. $difference[$key] = array( 'previous' => $value, 'actual' => '(missing)');
  143. }
  144. return !isset($difference) ? false : $difference;
  145. }
  146. ?>