system_specs.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * This script gathers system specification details for use with bug reporting
  4. * and anyone else who needs it.
  5. *
  6. * @copyright &copy; 1999-2008 The SquirrelMail Project Team
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. * @version $Id$
  9. * @package plugins
  10. * @subpackage bug_report
  11. */
  12. /**
  13. * converts array to string
  14. *
  15. * @param array $array array that has to be displayed
  16. * @return string
  17. * @access private
  18. */
  19. function Show_Array($array) {
  20. $str = '';
  21. foreach ($array as $key => $value) {
  22. if ($key != 0 || $value != '') {
  23. $str .= " * $key = $value\n";
  24. }
  25. }
  26. if ($str == '') {
  27. return " * Nothing listed\n";
  28. }
  29. return $str;
  30. }
  31. /**
  32. * converts plugin's array to string and adds version numbers
  33. * @return string preformated text with installed plugin's information
  34. * @access private
  35. */
  36. function br_show_plugins() {
  37. global $plugins;
  38. $str = '';
  39. if (is_array($plugins) && $plugins!=array()) {
  40. foreach ($plugins as $key => $plugin_name) {
  41. // note that some plugins may not have been loaded up by now
  42. // so we do that here to make sure... also turn on output
  43. // buffering so they don't screw up our output with spacing
  44. // or newlines
  45. //
  46. ob_start();
  47. use_plugin($plugin_name);
  48. ob_end_clean();
  49. if ($key != 0 || $plugin_name != '') {
  50. $english_name = get_plugin_requirement($plugin_name, 'english_name');
  51. $str .= " * $key = " . (!empty($english_name) ? $english_name . " ($plugin_name) " : "$plugin_name ") . get_plugin_version($plugin_name, TRUE) . "\n";
  52. }
  53. }
  54. // compatibility plugin can be used without needing to enable it in sm config
  55. if (file_exists(SM_PATH . 'plugins/compatibility/setup.php')
  56. && ! in_array('compatibility',$plugins)) {
  57. $str.= ' * Compatibility (compatibility) ' . get_plugin_version('compatibility', TRUE) . "\n";
  58. }
  59. }
  60. if ($str == '') {
  61. return " * Nothing listed\n";
  62. }
  63. return $str;
  64. }
  65. /**
  66. * Retrieve long text string containing semi-formatted (simple text
  67. * with newlines and spaces for indentation) SquirrelMail system
  68. * specs
  69. *
  70. * @return array A three-element array, the first element containing
  71. * the string of system specs, the second one containing
  72. * a list of any warnings that may have occurred, keyed
  73. * by a warning "type" (which is used to key the corrections
  74. * array next), and the third element of which is a list
  75. * of sub-arrays keyed by warning "type": the sub-arrays
  76. * are lists of correction messages associated with the
  77. * warnings. The second and third return elements may
  78. * be empty arrays if no warnings were found.
  79. *
  80. * @since 1.5.2
  81. *
  82. */
  83. function get_system_specs() {
  84. //FIXME: configtest and this plugin should be using the same code to generate the basic SM system specifications and setup detection
  85. global $imapServerAddress, $username, $imapPort, $imap_server_type,
  86. $use_imap_tls, $ldap_server;
  87. // load required libraries
  88. //
  89. include_once(SM_PATH . 'functions/imap_general.php');
  90. $browscap = ini_get('browscap');
  91. if(!empty($browscap)) {
  92. $browser = get_browser();
  93. }
  94. $warnings = array();
  95. $corrections = array();
  96. sqgetGlobalVar('HTTP_USER_AGENT', $HTTP_USER_AGENT, SQ_SERVER);
  97. if ( ! sqgetGlobalVar('HTTP_USER_AGENT', $HTTP_USER_AGENT, SQ_SERVER) )
  98. $HTTP_USER_AGENT="Browser information is not available.";
  99. $body_top = "My browser information:\n" .
  100. ' '.$HTTP_USER_AGENT . "\n" ;
  101. if(isset($browser)) {
  102. $body_top .= " get_browser() information (List)\n" .
  103. Show_Array((array) $browser);
  104. }
  105. $body_top .= "\nMy web server information:\n" .
  106. " PHP Version " . phpversion() . "\n" .
  107. " PHP Extensions (List)\n" .
  108. Show_Array(get_loaded_extensions()) .
  109. "\nSquirrelMail-specific information:\n" .
  110. " Version: " . SM_VERSION . "\n" .
  111. " Plugins (List)\n" .
  112. br_show_plugins() . "\n";
  113. if (!empty($ldap_server[0]) && $ldap_server[0] && ! extension_loaded('ldap')) {
  114. $warnings['ldap'] = "LDAP server defined in SquirrelMail config, " .
  115. "but the module is not loaded in PHP";
  116. $corrections['ldap'][] = "Reconfigure PHP with the option '--with-ldap'";
  117. $corrections['ldap'][] = "Then recompile PHP and reinstall";
  118. $corrections['ldap'][] = "-- OR --";
  119. $corrections['ldap'][] = "Reconfigure SquirrelMail to not use LDAP";
  120. }
  121. $body = "\nMy IMAP server information:\n" .
  122. " Server type: $imap_server_type\n";
  123. $imapServerAddress = sqimap_get_user_server($imapServerAddress, $username);
  124. $imap_stream = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
  125. if ($imap_stream) {
  126. $body.= ' Capabilities: ';
  127. if ($imap_capabilities = sqimap_capability($imap_stream)) {
  128. foreach ($imap_capabilities as $capability => $value) {
  129. $body.= $capability . (is_bool($value) ? ' ' : "=$value ");
  130. }
  131. }
  132. $body.="\n";
  133. sqimap_logout($imap_stream);
  134. } else {
  135. $body .= " Unable to connect to IMAP server to get information.\n";
  136. $warnings['imap'] = "Unable to connect to IMAP server";
  137. $corrections['imap'][] = "Make sure you specified the correct mail server";
  138. $corrections['imap'][] = "Make sure the mail server is running IMAP, not POP";
  139. $corrections['imap'][] = "Make sure the server responds to port $imapPort";
  140. }
  141. $warning_num = 0;
  142. if (!empty($warnings)) {
  143. foreach ($warnings as $key => $value) {
  144. if ($warning_num == 0) {
  145. $body_top .= "WARNINGS WERE REPORTED WITH YOUR SETUP:\n";
  146. $body_top = "WARNINGS WERE REPORTED WITH YOUR SETUP -- SEE BELOW\n\n$body_top";
  147. }
  148. $warning_num ++;
  149. $body_top .= "\n$value\n";
  150. foreach ($corrections[$key] as $corr_val) {
  151. $body_top .= " * $corr_val\n";
  152. }
  153. }
  154. $body_top .= "\n$warning_num warning(s) reported.\n";
  155. $body_top .= "----------------------------------------------\n";
  156. }
  157. $body = $body_top . $body;
  158. return array($body, $warnings, $corrections);
  159. }