check.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /**
  3. * SquirrelMail time zone library - time zone validation script.
  4. *
  5. * @copyright &copy; 2005-2006 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package squirrelmail
  9. * @subpackage timezones
  10. */
  11. /** @ignore */
  12. define('SM_PATH','../../');
  13. /** Send http header */
  14. header('Content-Type: text/plain');
  15. /** Information about script */
  16. echo "--------------------------------------------\n"
  17. ." SquirrelMail time zone library test script\n"
  18. ."--------------------------------------------\n";
  19. /** load SM config */
  20. unset($time_zone_type);
  21. if (file_exists(SM_PATH.'config/config.php')) {
  22. include(SM_PATH.'config/config.php');
  23. } else {
  24. echo "SquirrelMail configuration file is missing.\n";
  25. exit();
  26. }
  27. /**
  28. * Script does not test, if standard time zone libraries are missing.
  29. * If they are missing or corrupted - php can fail, scream and show
  30. * finger or other parts of interpreter.
  31. */
  32. /** load original reference */
  33. include(SM_PATH.'include/timezones/standard_orig.php');
  34. /** move timezones to different array */
  35. $aTimeZonesOrig = $aTimeZones;
  36. unset($aTimeZones);
  37. if (! isset($time_zone_type) || $time_zone_type == 0 || $time_zone_type == 1) {
  38. /** load new time zone library */
  39. include(SM_PATH.'include/timezones/standard.php');
  40. } elseif ($time_zone_type == 2 || $time_zone_type == 3) {
  41. /** load custom time zone library */
  42. $aTimeZones=array();
  43. if (file_exists(SM_PATH . 'config/timezones.php')) {
  44. include(SM_PATH.'config/timezones.php');
  45. } else {
  46. echo "ERROR: config/timezones.php is missing.\n";
  47. exit();
  48. }
  49. } else {
  50. echo "ERROR: invalid value in time_zone_type configuration.\n";
  51. exit();
  52. }
  53. if (! isset($aTimeZones) || ! is_array($aTimeZones) || empty($aTimeZones)) {
  54. echo "ERROR: timezones array is missing or empty.\n";
  55. exit();
  56. }
  57. $error = false;
  58. /** test backward compatibility */
  59. echo "Testing backward compatibility:\n"
  60. ." Failed time zones:\n";
  61. foreach ($aTimeZonesOrig as $TzKey => $TzData) {
  62. if (! isset($aTimeZones[$TzKey])) {
  63. echo ' '.$TzKey."\n";
  64. $error = true;
  65. }
  66. }
  67. if (! $error) {
  68. echo " none. Looking good.\n";
  69. } else {
  70. // error is not fatal, but test should fail only with limited custom time zone sets
  71. }
  72. echo "\n";
  73. /** test forward compatibility */
  74. $error = false;
  75. echo "Testing forward compatibility:\n"
  76. ." New time zones:\n";
  77. foreach ($aTimeZones as $TzKey => $TzData) {
  78. if (! isset($aTimeZonesOrig[$TzKey])) {
  79. echo ' '.$TzKey."\n";
  80. $error = true;
  81. }
  82. }
  83. if (! $error) {
  84. echo " no new time zones.\n";
  85. } else {
  86. // error is not fatal. test should show new time zones, that are not
  87. // present in timezones.cfg
  88. }
  89. echo "\n";
  90. /** test links */
  91. $error = false;
  92. echo "Testing time zone links:\n"
  93. ." Failed time zone links:\n";
  94. foreach ($aTimeZones as $TzKey => $TzData) {
  95. if (isset($TzData['LINK']) && ! isset($aTimeZones[$TzData['LINK']]['TZ'])) {
  96. echo ' '.$TzKey.' = '.$TzData['LINK']."\n";
  97. $error = true;
  98. }
  99. }
  100. if (! $error) {
  101. echo " none. Looking good.\n";
  102. } else {
  103. // error is fatal. 'LINK' should always reffer to existing 'TZ' entries
  104. }
  105. echo "\n";
  106. /** Test TZ subkeys */
  107. $error = false;
  108. echo "Testing time zone TZ subkeys:\n"
  109. ." Failed time zone TZ subkeys:\n";
  110. foreach ($aTimeZones as $TzKey => $TzData) {
  111. if (! isset($TzData['LINK']) && ! isset($TzData['TZ'])) {
  112. echo ' '.$TzKey."\n";
  113. $error = true;
  114. }
  115. }
  116. if (! $error) {
  117. echo " none. Looking good.\n";
  118. } else {
  119. // LINK or TZ are required for strict time zones. Interface won't break, but
  120. // any error means inconsistency in time zone array.
  121. }
  122. echo "\n";
  123. /** Test NAME subkeys */
  124. $error = false;
  125. echo "Testing time zone NAME subkeys:\n"
  126. ." Time zones without NAME subkeys:\n";
  127. foreach ($aTimeZones as $TzKey => $TzData) {
  128. if (isset($TzData['TZ']) && ! isset($TzData['NAME'])) {
  129. echo ' '.$TzKey."\n";
  130. $error = true;
  131. }
  132. }
  133. if (! $error) {
  134. echo " none.\n";
  135. } else {
  136. // error is not fatal. It would be nice if all geographic locations
  137. // use some human readable name
  138. }
  139. echo "\n";
  140. /** Test NAME subkeys */
  141. $error = false;
  142. echo " Time zones with empty NAME subkeys:\n";
  143. foreach ($aTimeZones as $TzKey => $TzData) {
  144. if (isset($TzData['NAME']) && empty($TzData['NAME'])) {
  145. echo ' '.$TzKey."\n";
  146. $error = true;
  147. }
  148. }
  149. if (! $error) {
  150. echo " none. Looking good\n";
  151. } else {
  152. // error is fatal. NAME should not be empty string.
  153. }
  154. echo "\n";
  155. /** Test TZ subkeys with UCT/UTC/GMT offsets */
  156. $error = false;
  157. echo "Testing TZ subkeys with UCT/UTC/GMT offsets:\n"
  158. ." Time zones UCT/UTC/GMT offsets:\n";
  159. foreach ($aTimeZones as $TzKey => $TzData) {
  160. if (isset($TzData['TZ']) && preg_match("/^(UCT)|(UTC)|(GMT).+/i",$TzData['TZ'])) {
  161. echo ' '.$TzKey.' = '.$TzData['TZ']."\n";
  162. $error = true;
  163. }
  164. }
  165. if (! $error) {
  166. echo " none.\n";
  167. } else {
  168. // I think error is fatal for UCT with offsets. date('T',time()) is corrupted.
  169. }
  170. echo "\n";
  171. /** Test TZ subkeys with custom TZ values and no offsets */
  172. $error = false;
  173. echo "Testing TZ subkeys with custom TZ values and no offsets:\n"
  174. ." Time zones with custom TZ values and no offsets:\n";
  175. foreach ($aTimeZones as $TzKey => $TzData) {
  176. if (isset($TzData['TZ']) &&
  177. ! preg_match("/^((UCT)|(UTC)|(GMT).+)|(GMT)$/i",$TzData['TZ']) &&
  178. preg_match("/^[a-z]+$/i",$TzData['TZ'])) {
  179. echo ' '.$TzKey.' = '.$TzData['TZ']."\n";
  180. $error = true;
  181. }
  182. }
  183. if (! $error) {
  184. echo " none.\n";
  185. } else {
  186. // I think error is fatal. Time zone formating requires time zone name and offset from GMT.
  187. }
  188. echo "\n";
  189. echo "Done!\n";