[Frontaccounting-cvs_updates] frontaccount/admin system_diagnostics.php, NONE, 1.1.2.2 create_coy.p
Brought to you by:
frontaccounting,
itronics
From: itronics <itr...@us...> - 2009-12-24 11:29:14
|
Update of /cvsroot/frontaccounting/frontaccount/admin In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv31936/admin Modified Files: Tag: unstable create_coy.php Added Files: Tag: unstable system_diagnostics.php Log Message: Merged changes from main trunk 2.2.1-2.2.2 --- NEW FILE: system_diagnostics.php --- <?php /********************************************************************** Copyright (C) FrontAccounting, LLC. Released under the terms of the GNU General Public License, GPL, as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here <http://www.gnu.org/licenses/gpl-3.0.html>. ***********************************************************************/ $page_security = 'SA_SOFTWAREUPGRADE'; $path_to_root=".."; include($path_to_root . "/includes/session.inc"); page(_($help_context = "System Diagnostics")); include($path_to_root . "/includes/ui.inc"); // Type of requirement for positive test result $test_level = array( 0 => _('Info'), 1 => _('Optional'), 2 => _('Recomended'), 3 => _('Required ') ); $system_tests = array('tst_mysql', 'tst_php', 'tst_server', 'tst_system', 'tst_browser', 'tst_gettext', 'tst_debug', 'tst_logging', 'tst_dbversion', 'tst_subdirs', 'tst_langs', 'tst_tmpdir', 'tst_sessionpath', 'tst_dbconfig', 'tst_config', 'tst_extconfig' ); function tst_mysql() { $test['descr'] = _('MySQL version'). ' >3.23.58'; $test['type'] = 3; $test['test'] = mysql_get_server_info(); $test['result'] = $test['test']>'3.23.58'; $test['comments'] = _('Upgrade MySQL server to version at least 3.23.58'); return $test; } function tst_php() { $test['descr'] = _('PHP version').' >4.3.2'; $test['type'] = 3; $test['test'] = phpversion(); $test['result'] = $test['test']>'4.3.2'; $test['comments'] = _('Upgrade PHP to version at least 4.3.2'); return $test; } function tst_system() { $test['descr'] = _('Server system'); $test['type'] = 0; $test['test'] = PHP_OS; $test['result'] = true; return $test; } function tst_sessionpath() { $test['descr'] = _('Session save path'); $test['type'] = 0; $test['test'] = session_save_path(); $test['result'] = true; return $test; } function tst_browser() { $test['descr'] = _('Browser type'); $test['type'] = 0; $test['test'] = $_SERVER['HTTP_USER_AGENT']; $test['result'] = true; $test['comments'] = _('Any browser is supported'); return $test; } function tst_server() { $test['descr'] = _('Http server type'); $test['test'] = $_SERVER['SERVER_SOFTWARE']; $test['type'] = 0; $test['result'] = true; $test['comments'] = _('Any server is supported'); return $test; } function tst_gettext() { $test['descr'] = _('Native gettext'); $test['test'] = function_exists('gettext') ? _('Yes'): _('No'); $test['type'] = 1; $test['result'] = true; $test['comments'] = _('In case of no getext support, php emulation is used'); return $test; } function tst_debug() { global $go_debug; $test['descr'] = _('Debugging mode'); $test['type'] = 0; $test['test'] = $go_debug ? _("Yes") : _("No"); $test['result'] = $go_debug != 0; $test['comments'] = _('To switch debugging on set $go_debug=1 in config.php file'); return $test; } function tst_logging() { global $error_logfile; $test['descr'] = _('Error logging'); $test['type'] = 2; // if error lgging is on, but log file does not exists try write if ($error_logfile && !is_file($error_logfile)) { @fclose(@fopen($error_logfile, 'w')); } $test['result'] = @$error_logfile != '' && is_writable($error_logfile); $test['test'] = @$error_logfile == '' ? _("Disabled") : $error_logfile; if (@$error_logfile == '') $test['comments'] = _('To switch error logging set $error_logging in config.php file'); else if (!is_writable($error_logfile)) $test['comments'] = _('Log file is not writeable'); return $test; } // // Installed FA database structure version // function tst_dbversion() { $test['descr'] = _('Current database version'); $test['type'] = 3; $test['test'] = get_company_pref('version_id'); $test['result'] = $test['test'] == '2.2'; $test['comments'] = _('Database structure seems to be not upgraded to current version') .' (2.2)'; return $test; } function tst_subdirs() { global $db_connections, $comp_path; $comp_subdirs = array('images', 'pdf_files', 'backup','js_cache'); $test['descr'] = _('Company subdirectories consistency'); $test['type'] = 3; $test['test'] = array($comp_path.'/*'); foreach($comp_subdirs as $sub) { $test['test'][] = $comp_path.'/*/'.$sub; } $test['result'] = true; if (!is_dir($comp_path) || !is_writable($comp_path) ) { $test['result'] = false; $test['comments'][] = sprintf(_("'%s' is not writeable"), $comp_path); return $test; }; foreach ($db_connections as $n => $comp) { $path = "$comp_path/$n"; if (!is_dir($path) || !is_writable($path) ) { $test['result'] = false; $test['comments'][] = sprintf(_("'%s' is not writeable"), $path); continue; }; foreach($comp_subdirs as $sub) { $spath = $path.'/'.$sub; if (!is_dir($spath) || !is_writable($spath) ) { $test['result'] = false; $test['comments'][] = sprintf(_("'%s' is not writeable"), $spath); } } } return $test; } function tst_tmpdir() { global $path_to_root; $test['descr'] = _('Temporary directory'); $test['type'] = 3; $test['test'] = $path_to_root.'/tmp'; $test['result'] = is_dir($test['test']) && is_writable($test['test']); $test['comments'][] = sprintf(_("'%s' is not writeable"), $test['test']); return $test; } function tst_langs() { global $installed_languages, $path_to_root; $test['descr'] = _('Language configuration consistency'); $test['type'] = 3; $test['result'] = true; $test['comments'] = array(); $old = setlocale(LC_MESSAGES, '0'); $langs = array(); foreach ($installed_languages as $lang) { $langs[] = $lang['code']; if ($lang['code'] == 'en_GB') continue; // native FA language $file = $path_to_root.'/lang/'.$lang['code'].'/LC_MESSAGES/'.$lang['code']; $file .= function_exists('gettext') ? '.mo' : '.po'; if (!is_file($file)) { $test['result'] = false; $test['comments'][] = sprintf( _('Missing %s translation file.'), $file); } if (!setlocale(LC_MESSAGES, $lang['code'].".".$lang['encoding'])) { $test['result'] = false; $test['comments'][] = sprintf(_('Missing system locale: %s'), $lang['code'].".".$lang['encoding']); }; } setlocale(LC_MESSAGES, $old); $test['test'] = $langs; return $test; } function tst_config() { global $path_to_root; $test['descr'] = _('Main config file'); $test['type'] = 2; $test['test'] = $path_to_root.'/config.php'; $test['result'] = is_file($test['test']) && !is_writable($test['test']); $test['comments'][] = sprintf(_("'%s' file should be read-only"), $test['test']); return $test; } function tst_dbconfig() { global $path_to_root; $test['descr'] = _('Database auth file'); $test['type'] = 2; $test['test'] = $path_to_root.'/config_db.php'; $test['result'] = is_file($test['test']) && !is_writable($test['test']); $test['comments'][] = sprintf(_("'%s' file should be read-only if you do not plan to add or change companies"), $test['test']); return $test; } function tst_extconfig() { global $path_to_root, $db_connections, $comp_path; $test['descr'] = _('Extensions configuration files'); $test['type'] = 3; $test['test'] = $path_to_root.'/installed_extensions.php'; $test['result'] = is_file($test['test']) && is_writable($test['test']); $test['test'] . ','.$comp_path.'/*/installed_extensions.php'; $test['comments'][] = sprintf(_("'%s' file should be writeable"), $test['test']); foreach ($db_connections as $n => $comp) { $path = "$comp_path/$n"; if (!is_dir($path)) continue; $path .= "/installed_extensions.php"; if (!is_file($path) || !is_writable($path) ) { $test['result'] = false; $test['comments'][] = sprintf(_("'%s' is not writeable"), $path); continue; }; } return $test; } //------------------------------------------------------------------------------------------------- start_table("$table_style width=80%"); $th = array(_("Test"), _('Test type'), _("Value"), _("Comments")); table_header($th); $k = 0; //row colour counter foreach ($system_tests as $test) { alt_table_row_color($k); $result = $test(); if (!$result) continue; label_cell($result['descr']); label_cell($test_level[$result['type']]); $res = is_array(@$result['test']) ? implode('<br>', $result['test']) : $result['test']; label_cell($res); $comm = is_array(@$result['comments']) ? implode('<br>', $result['comments']) : @$result['comments']; label_cell($result['result'] ? _('Ok') : '<b>'.$comm.'</b>'); end_row(); } end_table(); end_page(); ?> Index: create_coy.php =================================================================== RCS file: /cvsroot/frontaccounting/frontaccount/admin/create_coy.php,v retrieving revision 1.3.2.21 retrieving revision 1.3.2.22 diff -C2 -d -r1.3.2.21 -r1.3.2.22 *** create_coy.php 30 Nov 2009 09:02:32 -0000 1.3.2.21 --- create_coy.php 24 Dec 2009 11:29:02 -0000 1.3.2.22 *************** *** 53,57 **** return false; } ! if ($_POST['tbpref'] == 0 || $con['tbpref'] == '') { display_error(_("You cannot have table set without prefix together with prefixed sets in the same database.")); --- 53,57 ---- return false; } ! if (($_POST['tbpref'] == 0) ^ ($con['tbpref'] == '')) { display_error(_("You cannot have table set without prefix together with prefixed sets in the same database.")); *************** *** 161,180 **** function handle_delete() { ! global $comp_path, $def_coy, $db_connections, $comp_subdirs; $id = $_GET['id']; ! $cdir = $comp_path.'/'.$id; ! @flush_dir($cdir, true); ! if (!rmdir($cdir)) { ! display_error(_("Cannot remove company data directory ") . $cdir); return; } ! for($i = $id+1; $i < count($db_connections); $i++) { if (!rename($comp_path.'/'.$i, $comp_path.'/'.($i-1))) { display_error(_("Cannot rename company subdirectory")); return; ! } } $err = remove_connection($id); --- 161,197 ---- function handle_delete() { ! global $comp_path, $def_coy, $db_connections, $comp_subdirs, $path_to_root; $id = $_GET['id']; ! // First make sure all company directories from the one under removal are writable. ! // Without this after operation we end up with changed per-company owners! ! for($i = $id; $i < count($db_connections); $i++) { ! if (!is_dir($comp_path.'/'.$i) || !is_writable($comp_path.'/'.$i)) { ! display_error(_('Broken company subdirectories system. You have to remove this company manually.')); ! return; ! } ! } ! // make sure config file is writable ! if (!is_writeable($path_to_root . "/config_db.php")) { ! display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation.")); return; } ! // rename directory to temporary name to ensure all ! // other subdirectories will have right owners even after ! // unsuccessfull removal. ! $cdir = $comp_path.'/'.$id; ! $tmpname = $comp_path.'/old_'.$id; ! if (!@rename($cdir, $tmpname)) { ! display_error(_('Cannot rename subdirectory to temporary name.')); ! return; ! } ! // 'shift' company directories names ! for ($i = $id+1; $i < count($db_connections); $i++) { if (!rename($comp_path.'/'.$i, $comp_path.'/'.($i-1))) { display_error(_("Cannot rename company subdirectory")); return; ! } } $err = remove_connection($id); *************** *** 191,196 **** else if ($error == -3) display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation.")); ! if ($error != 0) return; meta_forward($_SERVER['PHP_SELF']); --- 208,222 ---- else if ($error == -3) display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation.")); ! if ($error != 0) { ! @rename($tmpname, $cdir); return; + } + // finally remove renamed company directory + @flush_dir($tmpname, true); + if (!@rmdir($tmpname)) + { + display_error(_("Cannot remove temporary renamed company data directory ") . $tmpname); + return; + } meta_forward($_SERVER['PHP_SELF']); |