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'). ' >3.23.58';
39 $test['test'] = mysql_get_server_info();
40 $test['result'] = $test['test']>'3.23.58';
41 $test['comments'] = _('Upgrade MySQL server to version at least 3.23.58');
48 $test['descr'] = _('PHP version').' >4.3.2';
50 $test['test'] = phpversion();
51 $test['result'] = $test['test']>'4.3.2';
52 $test['comments'] = _('Upgrade PHP to version at least 4.3.2');
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=1 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 $test['descr'] = _('Current database version');
151 $test['test'] = get_company_pref('version_id');
152 $test['result'] = $test['test'] == '2.2';
153 $test['comments'] = _('Database structure seems to be not upgraded to current version')
160 function tst_subdirs()
162 global $db_connections, $comp_path;
164 $comp_subdirs = array('images', 'pdf_files', 'backup','js_cache');
166 $test['descr'] = _('Company subdirectories consistency');
168 $test['test'] = array($comp_path.'/*');
169 foreach($comp_subdirs as $sub) {
170 $test['test'][] = $comp_path.'/*/'.$sub;
172 $test['result'] = true;
174 if (!is_dir($comp_path) || !is_writable($comp_path) ) {
175 $test['result'] = false;
176 $test['comments'][] = sprintf(_("'%s' is not writeable"), $comp_path);
179 foreach ($db_connections as $n => $comp) {
180 $path = "$comp_path/$n";
181 if (!is_dir($path) || !is_writable($path) ) {
182 $test['result'] = false;
183 $test['comments'][] = sprintf(_("'%s' is not writeable"), $path);
186 foreach($comp_subdirs as $sub) {
187 $spath = $path.'/'.$sub;
188 if (!is_dir($spath) || !is_writable($spath) ) {
189 $test['result'] = false;
190 $test['comments'][] = sprintf(_("'%s' is not writeable"), $spath);
197 function tst_tmpdir()
199 global $path_to_root;
201 $test['descr'] = _('Temporary directory');
203 $test['test'] = $path_to_root.'/tmp';
204 $test['result'] = is_dir($test['test']) && is_writable($test['test']);
205 $test['comments'][] = sprintf(_("'%s' is not writeable"), $test['test']);
211 global $installed_languages, $path_to_root;
213 $test['descr'] = _('Language configuration consistency');
215 $test['result'] = true;
216 $test['comments'] = array();
218 $old = setlocale(LC_MESSAGES, '0');
222 foreach ($installed_languages as $lang) {
223 $langs[] = $lang['code'];
224 if ($lang['code'] == 'en_GB') continue; // native FA language
226 $file = $path_to_root.'/lang/'.$lang['code'].'/LC_MESSAGES/'.$lang['code'];
227 $file .= function_exists('gettext') ? '.mo' : '.po';
229 if (!is_file($file)) {
230 $test['result'] = false;
231 $test['comments'][] = sprintf( _('Missing %s translation file.'), $file);
233 if (!setlocale(LC_MESSAGES, $lang['code'].".".$lang['encoding']))
235 $test['result'] = false;
236 $test['comments'][] = sprintf(_('Missing system locale: %s'), $lang['code'].".".$lang['encoding']);
240 setlocale(LC_MESSAGES, $old);
242 $test['test'] = $langs;
247 function tst_config()
249 global $path_to_root;
251 $test['descr'] = _('Main config file');
253 $test['test'] = $path_to_root.'/config.php';
254 $test['result'] = is_file($test['test']) && !is_writable($test['test']);
255 $test['comments'][] = sprintf(_("'%s' file should be read-only"), $test['test']);
259 function tst_dbconfig()
261 global $path_to_root;
263 $test['descr'] = _('Database auth file');
265 $test['test'] = $path_to_root.'/config_db.php';
266 $test['result'] = is_file($test['test']) && !is_writable($test['test']);
267 $test['comments'][] = sprintf(_("'%s' file should be read-only if you do not plan to add or change companies"), $test['test']);
272 function tst_extconfig()
274 global $path_to_root, $db_connections, $comp_path;
276 $test['descr'] = _('Extensions configuration files');
278 $test['test'] = $path_to_root.'/installed_extensions.php';
279 $test['result'] = is_file($test['test']) && is_writable($test['test']);
280 $test['test'] . ','.$comp_path.'/*/installed_extensions.php';
281 $test['comments'][] = sprintf(_("'%s' file should be writeable"), $test['test']);
283 foreach ($db_connections as $n => $comp) {
284 $path = "$comp_path/$n";
285 if (!is_dir($path)) continue;
287 $path .= "/installed_extensions.php";
288 if (!is_file($path) || !is_writable($path) ) {
289 $test['result'] = false;
290 $test['comments'][] = sprintf(_("'%s' is not writeable"), $path);
296 //-------------------------------------------------------------------------------------------------
298 start_table("$table_style width=80%");
299 $th = array(_("Test"), _('Test type'), _("Value"), _("Comments"));
302 $k = 0; //row colour counter
303 foreach ($system_tests as $test)
305 alt_table_row_color($k);
307 if (!$result) continue;
308 label_cell($result['descr']);
309 label_cell($test_level[$result['type']]);
311 $res = is_array(@$result['test']) ? implode('<br>', $result['test'])
315 $comm = is_array(@$result['comments']) ? implode('<br>', $result['comments'])
316 : @$result['comments'];
317 label_cell($result['result'] ? _('Ok') : '<b>'.$comm.'</b>');