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 ***********************************************************************/
13 // Type of requirement for positive test result
21 // test mysql server version
24 $test['descr'] = _('MySQL version'). ' >=4.1';
26 $test['test'] = mysql_get_server_info();
27 $test['result'] = $test['test']>='4.1';
28 $test['comments'] = _('Upgrade MySQL server to version at least 4.1');
32 // test php mysql extension
33 function tst_phpmysql()
35 $test['descr'] = _('PHP MySQL extension');
37 $test['result'] = function_exists('gettext');
38 $test['test'] = $test['result'] ? _('Yes'): _('No');
40 $test['comments'] = _('Your PHP has to have MySQL extension enabled.');
46 $test['descr'] = _('PHP version').' >=4.3.3';
48 $test['test'] = phpversion();
49 $test['result'] = $test['test']>='4.3.3';
50 $test['comments'] = _('Upgrade PHP to version at least 4.3.3');
57 $test['descr'] = _('Server system');
59 $test['test'] = PHP_OS;
60 $test['result'] = true;
65 function tst_sessionpath()
67 $test['descr'] = _('Session save path');
69 $test['test'] = session_save_path();
70 $test['result'] = true;
75 function tst_install()
79 $test['descr'] = _('Removed install wizard folder');
81 $test['result'] = !is_dir($path_to_root.'/install');
82 $test['test'] = _('Not removed');
83 $test['comments'] = _('Remove or rename install wizard folder for security reasons.');
88 function tst_browser()
90 $test['descr'] = _('Browser type');
92 $test['test'] = $_SERVER['HTTP_USER_AGENT'];
93 $test['result'] = true;
94 $test['comments'] = _('Any browser is supported');
101 $test['descr'] = _('Http server type');
102 $test['test'] = $_SERVER['SERVER_SOFTWARE'];
104 $test['result'] = true;
105 $test['comments'] = _('Any server is supported');
110 function tst_gettext()
112 $test['descr'] = _('Native gettext');
113 $test['test'] = function_exists('gettext') ? _('Yes'): _('No');
115 $test['result'] = true;
116 $test['comments'] = _('In case of no getext support, php emulation is used');
124 $test['descr'] = _('Debugging mode');
126 $test['test'] = $go_debug ? _("Yes") : _("No");
127 $test['result'] = $go_debug != 0;
128 $test['comments'] = _('To switch debugging on set $go_debug>0 in config.php file');
133 function tst_logging()
135 global $error_logfile;
137 $test['descr'] = _('Error logging');
139 // if error lgging is on, but log file does not exists try write
140 if ($error_logfile && !is_file($error_logfile))
142 @fclose(@fopen($error_logfile, 'w'));
144 $test['result'] = @$error_logfile != '' && is_writable($error_logfile);
145 $test['test'] = @$error_logfile == '' ? _("Disabled") : $error_logfile;
147 if (@$error_logfile == '')
148 $test['comments'] = _('To switch error logging set $error_logging in config.php file');
150 if (!is_writable($error_logfile))
151 $test['comments'] = _('Log file is not writeable');
156 // Installed FA database structure version
158 function tst_dbversion()
161 $test['descr'] = _('Current database version');
163 $test['test'] = get_company_pref('version_id');
164 $test['result'] = $test['test'] == $db_version;
165 $test['comments'] = _('Database structure seems to be not upgraded to current version')
172 function tst_subdirs($install=false)
174 global $db_connections;
176 $comps = $install ? array('0') : array_keys($db_connections);
178 $comp_subdirs = array('images', 'pdf_files', 'backup','js_cache');
180 $test['descr'] = _('Company subdirectories consistency');
182 $test['test'] = array(company_path().'/*');
183 foreach($comp_subdirs as $sub) {
184 $test['test'][] = company_path().'/*/'.$sub;
186 $test['result'] = true;
188 $comp_path = company_path();
189 foreach ($comps as $n) {
190 $path = company_path($n);
191 if (!is_dir($path) || !is_writable($path) ) {
192 $test['result'] = false;
193 $test['comments'][] = sprintf(_("'%s' is not writeable"), $path);
196 foreach($comp_subdirs as $sub) {
197 $spath = $path.'/'.$sub;
198 if (!is_dir($spath) || !is_writable($spath) ) {
199 $test['result'] = false;
200 $test['comments'][] = sprintf(_("'%s' is not writeable"), $spath);
202 $dir = opendir($spath);
203 while (false !== ($fname = readdir($dir))) {
204 // check only *.js files. Manually installed package can contain other
205 // non-writable files which are non-crucial for normal operations
206 if (preg_match('/.*(\.js)/', $fname) && !is_writable("$spath/$fname")) {
207 $test['result'] = false;
208 $test['comments'][] = sprintf(_("'%s' is not writeable"), "$spath/$fname");
217 function tst_tmpdir()
219 global $path_to_root;
221 $test['descr'] = _('Temporary directory');
223 $test['test'] = $path_to_root.'/tmp';
224 $test['result'] = is_dir($test['test']) && is_writable($test['test']);
225 $test['comments'][] = sprintf(_("'%s' is not writeable"), $test['test']);
231 global $installed_languages, $path_to_root;
233 $test['descr'] = _('Language configuration consistency');
235 $test['result'] = true;
236 $test['comments'] = array();
238 $fname = $path_to_root.'/lang';
239 $test['test'][] = $fname;
240 if (!(is_dir($fname) && is_writable($fname))) {
241 $test['result'] = false;
242 $test['comments'][] = _("Languages folder should be writeable.");
245 $fname = $path_to_root.'/lang/installed_languages.inc';
246 $test['test'][] = $fname;
247 if (!(is_file($fname) && is_writable($fname))) {
248 $test['result'] = false;
249 $test['comments'][] = _("Languages configuration file should be writeable.");
254 foreach ($installed_languages as $lang) {
255 $langs[] = $lang['code'];
256 if ($lang['code'] == 'en_GB') continue; // native FA language
258 $file = $path_to_root.'/lang/'.$lang['code'].'/LC_MESSAGES/'.$lang['code'];
259 if (@$lang['version'])
260 $file .= '-'.$lang['version'];
261 $file .= function_exists('gettext') ? '.mo' : '.po';
263 if (!is_file($file)) {
264 $test['result'] = false;
265 $test['comments'][] = sprintf( _('Missing %s translation file.'), $file);
267 if (!$_SESSION['get_text']->check_support($lang['code'], $lang['encoding']))
269 $test['result'] = false;
270 $test['comments'][] = sprintf(_('Missing system locale: %s'), $lang['code'].".".$lang['encoding']);
274 $test['test'] = $langs;
279 function tst_config($install)
281 global $path_to_root;
283 $test['descr'] = _('Main config file');
284 $test['test'] = $path_to_root.'/config.php';
287 $writable = check_write($test['test']);
288 $test['result'] = $writable==1;
289 $test['comments'][] = $writable == 0 ?
290 sprintf(_("Can't write '%s' file. Check FA directory write permissions."), $test['test'])
291 : sprintf(_("'%s' file exists."), $test['test']);
294 $test['result'] = is_file($test['test']) && !is_writable($test['test']);
295 $test['comments'][] = sprintf(_("'%s' file should be read-only"), $test['test']);
300 function tst_dbconfig()
302 global $path_to_root;
304 $test['descr'] = _('Database auth file');
306 $test['test'] = $path_to_root.'/config_db.php';
307 $test['result'] = is_file($test['test']) && !is_writable($test['test']);
308 $test['comments'][] = sprintf(_("'%s' file should be read-only if you do not plan to add or change companies"), $test['test']);
313 function tst_extconfig($install)
315 global $path_to_root, $db_connections;
317 $comps = $install ? array('0') : array_keys($db_connections);
319 $test['descr'] = _('Extensions system');
321 $fname = $path_to_root.'/installed_extensions.php';
322 $test['test'][] = $fname;
323 $test['result'] = is_file($fname) && is_writable($fname);
324 $test['test'][] = company_path().'/*/installed_extensions.php';
326 foreach ($comps as $n) {
327 $path = company_path($n);
328 if (!is_dir($path)) continue;
330 $path .= "/installed_extensions.php";
331 if (!is_file($path) || !is_writable($path) ) {
332 $test['result'] = false;
333 $test['comments'][] = sprintf(_("'%s' is not writeable"), $path);
337 $fname = $path_to_root.'/modules';
338 $test['test'][] = $fname;
339 $test['result'] &= is_dir($fname) && is_writable($fname);
341 $fname = $path_to_root.'/modules/_cache';
342 $test['test'][] = $fname;
343 $test['result'] &= is_dir($fname) && is_writable($fname);
345 $fname = $path_to_root.'/themes';
346 $test['test'][] = $fname;
347 $test['result'] &= is_dir($fname) && is_writable($fname);
349 $fname = $path_to_root.'/sql';
350 $test['test'][] = $fname;
351 $test['result'] &= is_dir($fname) && is_writable($fname);
354 $test['comments'][] = _("Extensions configuration files and directories should be writeable");
356 $themedir = opendir($fname);
357 while (false !== ($fname = readdir($themedir)))
359 if ($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path_to_root.'/themes/'.$fname)
360 && !in_array($fname, array('aqua', 'cool', 'default')))
362 $test['test'][] = $fname;
363 $test['result'] = is_writable($path_to_root.'/themes/'.$fname);
364 if (!$test['result']) {
365 $test['comments'][] =
366 sprintf(_("Non-standard theme directory '%s' is not writable"), $fname);
373 $test['test'][] = 'OpenSSL PHP extension';
374 if (!extension_loaded('openssl')) {
375 $test['result'] = false;
376 $test['comments'][] = _("OpenSSL PHP extension have to be enabled to use extension repository system.");
377 } elseif (!function_exists('openssl_verify')) {
378 $test['result'] = false;
379 $test['comments'][] = _("OpenSSL have to be available on your server to use extension repository system.");
384 function display_system_tests($install = false)
389 $system_tests = array('tst_php', 'tst_phpmysql', 'tst_system', 'tst_config',
390 'tst_subdirs', 'tst_langs', 'tst_tmpdir', 'tst_sessionpath', 'tst_extconfig'
393 $system_tests = array('tst_mysql', 'tst_php', 'tst_server', 'tst_system', 'tst_browser',
394 'tst_gettext', 'tst_debug', 'tst_logging',
395 'tst_dbversion', 'tst_subdirs', 'tst_langs', 'tst_tmpdir', 'tst_sessionpath',
396 'tst_install', 'tst_dbconfig', 'tst_config', 'tst_extconfig'
400 start_table(TABLESTYLE, "width=80%");
401 $th = array(_("Test"), _('Test type'), _("Value"), _("Comments"));
405 $k = 0; //row colour counter
406 foreach ($system_tests as $test)
408 alt_table_row_color($k);
409 $result = $test($install);
410 if (!$result) continue;
412 label_cell($result['descr']);
413 label_cell($test_level[$result['type']]);
415 $res = is_array(@$result['test']) ? implode('<br>', $result['test'])
419 $comm = is_array(@$result['comments']) ? implode('<br>', $result['comments'])
420 : @$result['comments'];
421 $color = ($result['result'] ? 'green':
422 ($result['type']==3 ? 'red' :
423 ($result['type']==2 ? 'orange' : 'green')));
424 label_cell("<span style='color:$color'>".
425 ($result['result'] ? _('Ok') : '<b>'.$comm.'</b>').'</span>');
427 $ret = $ret && (($result['result']!=0) || ($result['type'] < 3));