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