2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_SOFTWAREUPGRADE';
15 include($path_to_root . "/includes/session.inc");
17 page(_($help_context = "System Diagnostics"));
19 include($path_to_root . "/includes/ui.inc");
21 // Type of requirement for positive test result
29 $system_tests = array('tst_mysql', 'tst_php', 'tst_server', 'tst_system', 'tst_browser',
30 'tst_gettext', 'tst_debug', 'tst_logging',
31 'tst_dbversion', 'tst_subdirs', 'tst_langs', 'tst_tmpdir', 'tst_sessionpath',
32 'tst_dbconfig', 'tst_config', 'tst_extconfig'
37 $test['descr'] = _('MySQL version'). ' >=4.1';
39 $test['test'] = mysql_get_server_info();
40 $test['result'] = $test['test']>='4.1';
41 $test['comments'] = _('Upgrade MySQL server to version at least 4.1');
48 $test['descr'] = _('PHP version').' >=4.3.3';
50 $test['test'] = phpversion();
51 $test['result'] = $test['test']>='4.3.3';
52 $test['comments'] = _('Upgrade PHP to version at least 4.3.3');
59 $test['descr'] = _('Server system');
61 $test['test'] = PHP_OS;
62 $test['result'] = true;
67 function tst_sessionpath()
69 $test['descr'] = _('Session save path');
71 $test['test'] = session_save_path();
72 $test['result'] = true;
77 function tst_browser()
79 $test['descr'] = _('Browser type');
81 $test['test'] = $_SERVER['HTTP_USER_AGENT'];
82 $test['result'] = true;
83 $test['comments'] = _('Any browser is supported');
90 $test['descr'] = _('Http server type');
91 $test['test'] = $_SERVER['SERVER_SOFTWARE'];
93 $test['result'] = true;
94 $test['comments'] = _('Any server is supported');
99 function tst_gettext()
101 $test['descr'] = _('Native gettext');
102 $test['test'] = function_exists('gettext') ? _('Yes'): _('No');
104 $test['result'] = true;
105 $test['comments'] = _('In case of no getext support, php emulation is used');
113 $test['descr'] = _('Debugging mode');
115 $test['test'] = $go_debug ? _("Yes") : _("No");
116 $test['result'] = $go_debug != 0;
117 $test['comments'] = _('To switch debugging on set $go_debug>0 in config.php file');
122 function tst_logging()
124 global $error_logfile;
126 $test['descr'] = _('Error logging');
128 // if error lgging is on, but log file does not exists try write
129 if ($error_logfile && !is_file($error_logfile))
131 @fclose(@fopen($error_logfile, 'w'));
133 $test['result'] = @$error_logfile != '' && is_writable($error_logfile);
134 $test['test'] = @$error_logfile == '' ? _("Disabled") : $error_logfile;
136 if (@$error_logfile == '')
137 $test['comments'] = _('To switch error logging set $error_logging in config.php file');
139 if (!is_writable($error_logfile))
140 $test['comments'] = _('Log file is not writeable');
145 // Installed FA database structure version
147 function tst_dbversion()
149 global $core_version;
150 $test['descr'] = _('Current database version');
152 $test['test'] = get_company_pref('version_id');
153 $test['result'] = $test['test'] == $core_version;
154 $test['comments'] = _('Database structure seems to be not upgraded to current version')
161 function tst_subdirs()
163 global $db_connections;
165 $comp_subdirs = array('images', 'pdf_files', 'backup','js_cache');
167 $test['descr'] = _('Company subdirectories consistency');
169 $test['test'] = array(company_path().'/*');
170 foreach($comp_subdirs as $sub) {
171 $test['test'][] = company_path().'/*/'.$sub;
173 $test['result'] = true;
175 $comp_path = company_path();
176 if (!is_dir($comp_path) || !is_writable($comp_path) ) {
177 $test['result'] = false;
178 $test['comments'][] = sprintf(_("'%s' is not writeable"), $comp_path);
181 foreach ($db_connections as $n => $comp) {
182 $path = company_path($n);
183 if (!is_dir($path) || !is_writable($path) ) {
184 $test['result'] = false;
185 $test['comments'][] = sprintf(_("'%s' is not writeable"), $path);
188 foreach($comp_subdirs as $sub) {
189 $spath = $path.'/'.$sub;
190 if (!is_dir($spath) || !is_writable($spath) ) {
191 $test['result'] = false;
192 $test['comments'][] = sprintf(_("'%s' is not writeable"), $spath);
194 $dir = opendir($spath);
195 while (false !== ($fname = readdir($dir))) {
196 // check only *.js files. Manually installed package can contain other
197 // non-writable files which are non-crucial for normal operations
198 if (preg_match('/.*(\.js)/', $fname) && !is_writable("$spath/$fname")) {
199 $test['result'] = false;
200 $test['comments'][] = sprintf(_("'%s' is not writeable"), "$spath/$fname");
209 function tst_tmpdir()
211 global $path_to_root;
213 $test['descr'] = _('Temporary directory');
215 $test['test'] = $path_to_root.'/tmp';
216 $test['result'] = is_dir($test['test']) && is_writable($test['test']);
217 $test['comments'][] = sprintf(_("'%s' is not writeable"), $test['test']);
223 global $installed_languages, $path_to_root;
225 $test['descr'] = _('Language configuration consistency');
227 $test['result'] = true;
228 $test['comments'] = array();
230 $fname = $path_to_root.'/lang';
231 $test['test'][] = $fname;
232 if (!(is_dir($fname) && is_writable($fname))) {
233 $test['result'] = false;
234 $test['comments'][] = _("Languages folder should be writeable.");
237 $fname = $path_to_root.'/lang/installed_languages.inc';
238 $test['test'][] = $fname;
239 if (!(is_file($fname) && is_writable($fname))) {
240 $test['result'] = false;
241 $test['comments'][] = _("Languages configuration file should be writeable.");
246 foreach ($installed_languages as $lang) {
247 $langs[] = $lang['code'];
248 if ($lang['code'] == 'en_GB') continue; // native FA language
250 $file = $path_to_root.'/lang/'.$lang['code'].'/LC_MESSAGES/'.$lang['code'];
251 if (@$lang['version'])
252 $file .= '-'.$lang['version'];
253 $file .= function_exists('gettext') ? '.mo' : '.po';
255 if (!is_file($file)) {
256 $test['result'] = false;
257 $test['comments'][] = sprintf( _('Missing %s translation file.'), $file);
259 if (!$_SESSION['get_text']->check_support($lang['code'], $lang['encoding']))
261 $test['result'] = false;
262 $test['comments'][] = sprintf(_('Missing system locale: %s'), $lang['code'].".".$lang['encoding']);
266 $test['test'] = $langs;
271 function tst_config()
273 global $path_to_root;
275 $test['descr'] = _('Main config file');
277 $test['test'] = $path_to_root.'/config.php';
278 $test['result'] = is_file($test['test']) && !is_writable($test['test']);
279 $test['comments'][] = sprintf(_("'%s' file should be read-only"), $test['test']);
283 function tst_dbconfig()
285 global $path_to_root;
287 $test['descr'] = _('Database auth file');
289 $test['test'] = $path_to_root.'/config_db.php';
290 $test['result'] = is_file($test['test']) && !is_writable($test['test']);
291 $test['comments'][] = sprintf(_("'%s' file should be read-only if you do not plan to add or change companies"), $test['test']);
296 function tst_extconfig()
298 global $path_to_root, $db_connections;
300 $test['descr'] = _('Extensions system');
302 $fname = $path_to_root.'/installed_extensions.php';
303 $test['test'][] = $fname;
304 $test['result'] = is_file($fname) && is_writable($fname);
305 $test['test'][] = company_path().'/*/installed_extensions.php';
307 foreach ($db_connections as $n => $comp) {
308 $path = company_path($n);
309 if (!is_dir($path)) continue;
311 $path .= "/installed_extensions.php";
312 if (!is_file($path) || !is_writable($path) ) {
313 $test['result'] = false;
314 $test['comments'][] = sprintf(_("'%s' is not writeable"), $path);
318 $fname = $path_to_root.'/modules';
319 $test['test'][] = $fname;
320 $test['result'] &= is_dir($fname) && is_writable($fname);
321 $fname = $path_to_root.'/modules/_cache';
323 $test['test'][] = $fname;
324 $test['result'] &= is_dir($fname) && is_writable($fname);
325 $fname = $path_to_root.'/themes';
327 $test['test'][] = $fname;
328 $test['result'] &= is_dir($fname) && is_writable($fname);
330 $test['comments'][] = _("Extensions configuration files and directories should be writeable");
332 $themedir = opendir($fname);
333 while (false !== ($fname = readdir($themedir)))
335 if ($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path_to_root.'/themes/'.$fname)
336 && !in_array($fname, array('aqua', 'cool', 'default')))
338 $test['test'][] = $fname;
339 $test['result'] = is_writable($path_to_root.'/themes/'.$fname);
340 if (!$test['result']) {
341 $test['comments'][] =
342 sprintf(_("Non-standard theme directory '%s' is not writable"), $fname);
349 $test['test'][] = 'OpenSSL PHP extension';
350 if (!extension_loaded('openssl')) {
351 $test['result'] = false;
352 $test['comments'][] = _("OpenSSL PHP extension have to be enabled to use extension repository system.");
353 } elseif (!function_exists('openssl_verify')) {
354 $test['result'] = false;
355 $test['comments'][] = _("OpenSSL have to be available on your server to use extension repository system.");
359 //-------------------------------------------------------------------------------------------------
361 start_table(TABLESTYLE, "width=80%");
362 $th = array(_("Test"), _('Test type'), _("Value"), _("Comments"));
365 $k = 0; //row colour counter
366 foreach ($system_tests as $test)
368 alt_table_row_color($k);
370 if (!$result) continue;
371 label_cell($result['descr']);
372 label_cell($test_level[$result['type']]);
374 $res = is_array(@$result['test']) ? implode('<br>', $result['test'])
378 $comm = is_array(@$result['comments']) ? implode('<br>', $result['comments'])
379 : @$result['comments'];
380 $color = ($result['result'] ? 'green':
381 ($result['type']==3 ? 'red' :
382 ($result['type']==2 ? 'orange' : 'green')));
383 label_cell("<span style='color:$color'>".
384 ($result['result'] ? _('Ok') : '<b>'.$comm.'</b>').'</span>');