2005-11-03 19:00:17 +01:00
< ? php
2016-02-22 18:45:00 +01:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2004 Sebastien DiCintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2007 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2012 Marcos GarcÃa < marcosgdf @ gmail . com >
* Copyright ( C ) 2016 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2005-11-03 19:00:17 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-11-03 19:00:17 +01:00
* ( 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
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:24:38 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2005-11-03 19:00:17 +01:00
*/
2005-11-04 02:28:28 +01:00
2012-01-29 20:57:40 +01:00
/**
* \file htdocs / install / inc . php
* \ingroup core
* \brief File that define environment for support pages
2009-11-04 23:23:48 +01:00
*/
2005-11-04 02:28:28 +01:00
2012-04-28 16:37:58 +02:00
// Just to define version DOL_VERSION
if ( ! defined ( 'DOL_INC_FOR_VERSION_ERROR' )) define ( 'DOL_INC_FOR_VERSION_ERROR' , '1' );
2012-08-22 23:11:24 +02:00
require_once '../filefunc.inc.php' ;
2008-04-19 23:52:14 +02:00
2012-10-07 20:04:07 +02:00
2012-12-05 00:45:10 +01:00
2012-04-28 16:37:58 +02:00
// Define DOL_DOCUMENT_ROOT and ADODB_PATH used for install/upgrade process
2011-09-07 15:27:50 +02:00
if ( ! defined ( 'DOL_DOCUMENT_ROOT' )) define ( 'DOL_DOCUMENT_ROOT' , '..' );
if ( ! defined ( 'ADODB_PATH' ))
{
$foundpath = DOL_DOCUMENT_ROOT . '/includes/adodbtime/' ;
if ( ! is_dir ( $foundpath )) $foundpath = '/usr/share/php/adodb/' ;
define ( 'ADODB_PATH' , $foundpath );
}
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once ADODB_PATH . 'adodb-time.inc.php' ;
2007-10-29 13:47:43 +01:00
2012-04-28 16:37:58 +02:00
// Avoid warnings with strict mode E_STRICT
2012-03-21 02:12:44 +01:00
$conf = new stdClass (); // instantiate $conf explicitely
2013-01-19 14:32:37 +01:00
$conf -> global = new stdClass ();
$conf -> file = new stdClass ();
$conf -> db = new stdClass ();
$conf -> syslog = new stdClass ();
2012-03-21 02:12:44 +01:00
2012-04-28 16:37:58 +02:00
// Force $_REQUEST["logtohtml"]
2009-01-12 20:36:40 +01:00
$_REQUEST [ " logtohtml " ] = 1 ;
2008-12-15 02:04:32 +01:00
2007-03-06 19:30:16 +01:00
// Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
// et non path absolu.
if ( isset ( $_SERVER [ " DOCUMENT_URI " ]) && $_SERVER [ " DOCUMENT_URI " ])
{
2011-09-29 22:21:57 +02:00
$_SERVER [ " PHP_SELF " ] = $_SERVER [ " DOCUMENT_URI " ];
2007-03-06 19:30:16 +01:00
}
2007-12-17 19:33:34 +01:00
2007-12-11 01:58:18 +01:00
$includeconferror = '' ;
2011-07-30 12:23:24 +02:00
2011-09-20 12:30:56 +02:00
// Define vars
2011-07-30 12:23:24 +02:00
$conffiletoshowshort = " conf.php " ;
2011-09-20 12:30:56 +02:00
// Define localization of conf file
2006-06-17 20:12:46 +02:00
$conffile = " ../conf/conf.php " ;
2011-07-30 12:23:24 +02:00
$conffiletoshow = " htdocs/conf/conf.php " ;
2011-09-20 12:30:56 +02:00
// For debian/redhat like systems
//$conffile = "/etc/dolibarr/conf.php";
//$conffiletoshow = "/etc/dolibarr/conf.php";
2011-08-04 14:07:29 +02:00
2009-08-26 20:59:13 +02:00
2016-02-06 17:19:57 +01:00
// Load conf file if it is already defined
if ( ! defined ( 'DONOTLOADCONF' ) && file_exists ( $conffile ) && filesize ( $conffile ) > 8 ) // Test on filesize is to ensure that conf file is more that an empty template with just <?php in first line
2006-10-20 23:42:57 +02:00
{
2012-08-23 02:04:35 +02:00
$result = include_once $conffile ; // Load conf file
2011-09-29 22:21:57 +02:00
if ( $result )
{
2013-07-14 20:20:52 +02:00
if ( empty ( $dolibarr_main_db_type )) $dolibarr_main_db_type = 'mysqli' ; // For backward compatibility
2016-04-17 15:39:46 +02:00
//Mysql driver support has been removed in favor of mysqli
if ( $dolibarr_main_db_type == 'mysql' ) {
$dolibarr_main_db_type = 'mysqli' ;
}
if ( empty ( $dolibarr_main_db_port ) && ( $dolibarr_main_db_type == 'mysqli' )) $dolibarr_main_db_port = '3306' ; // For backward compatibility
2012-10-07 20:04:07 +02:00
2012-07-02 19:30:37 +02:00
// Clean parameters
2015-10-12 15:25:36 +02:00
$dolibarr_main_data_root = isset ( $dolibarr_main_data_root ) ? trim ( $dolibarr_main_data_root ) : DOL_DOCUMENT_ROOT . '/../documents' ;
2012-07-02 19:30:37 +02:00
$dolibarr_main_url_root = isset ( $dolibarr_main_url_root ) ? trim ( $dolibarr_main_url_root ) : '' ;
$dolibarr_main_url_root_alt = isset ( $dolibarr_main_url_root_alt ) ? trim ( $dolibarr_main_url_root_alt ) : '' ;
$dolibarr_main_document_root = isset ( $dolibarr_main_document_root ) ? trim ( $dolibarr_main_document_root ) : '' ;
2012-03-18 22:51:11 +01:00
$dolibarr_main_document_root_alt = isset ( $dolibarr_main_document_root_alt ) ? trim ( $dolibarr_main_document_root_alt ) : '' ;
2011-09-29 22:21:57 +02:00
// Remove last / or \ on directories or url value
2012-03-07 14:21:49 +01:00
if ( ! empty ( $dolibarr_main_document_root ) && ! preg_match ( '/^[\\/]+$/' , $dolibarr_main_document_root )) $dolibarr_main_document_root = preg_replace ( '/[\\/]+$/' , '' , $dolibarr_main_document_root );
if ( ! empty ( $dolibarr_main_url_root ) && ! preg_match ( '/^[\\/]+$/' , $dolibarr_main_url_root )) $dolibarr_main_url_root = preg_replace ( '/[\\/]+$/' , '' , $dolibarr_main_url_root );
if ( ! empty ( $dolibarr_main_data_root ) && ! preg_match ( '/^[\\/]+$/' , $dolibarr_main_data_root )) $dolibarr_main_data_root = preg_replace ( '/[\\/]+$/' , '' , $dolibarr_main_data_root );
if ( ! empty ( $dolibarr_main_document_root_alt ) && ! preg_match ( '/^[\\/]+$/' , $dolibarr_main_document_root_alt )) $dolibarr_main_document_root_alt = preg_replace ( '/[\\/]+$/' , '' , $dolibarr_main_document_root_alt );
if ( ! empty ( $dolibarr_main_url_root_alt ) && ! preg_match ( '/^[\\/]+$/' , $dolibarr_main_url_root_alt )) $dolibarr_main_url_root_alt = preg_replace ( '/[\\/]+$/' , '' , $dolibarr_main_url_root_alt );
2011-09-29 22:21:57 +02:00
// Create conf object
if ( ! empty ( $dolibarr_main_document_root ))
{
$result = conf ( $dolibarr_main_document_root );
}
// Load database driver
if ( $result )
{
if ( ! empty ( $dolibarr_main_document_root ) && ! empty ( $dolibarr_main_db_type ))
{
2012-08-23 02:04:35 +02:00
$result = include_once $dolibarr_main_document_root . " /core/db/ " . $dolibarr_main_db_type . '.class.php' ;
2011-09-29 22:21:57 +02:00
if ( ! $result )
{
$includeconferror = 'ErrorBadValueForDolibarrMainDBType' ;
}
}
}
else
{
$includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot' ;
}
}
else
{
$includeconferror = 'ErrorBadFormatForConfFile' ;
}
2006-10-20 23:42:57 +02:00
}
2016-03-10 18:36:09 +01:00
$conf -> global -> MAIN_ENABLE_LOG_TO_HTML = 1 ;
2008-06-17 03:18:48 +02:00
2008-12-08 01:04:11 +01:00
// Define prefix
2009-01-20 00:32:18 +01:00
if ( ! isset ( $dolibarr_main_db_prefix ) || ! $dolibarr_main_db_prefix ) $dolibarr_main_db_prefix = 'llx_' ;
2007-11-09 00:06:00 +01:00
define ( 'MAIN_DB_PREFIX' ,( isset ( $dolibarr_main_db_prefix ) ? $dolibarr_main_db_prefix : '' ));
2008-12-08 01:04:11 +01:00
2010-10-03 02:12:54 +02:00
define ( 'DOL_CLASS_PATH' , 'class/' ); // Filsystem path to class dir
2015-10-12 15:25:36 +02:00
define ( 'DOL_DATA_ROOT' ,( isset ( $dolibarr_main_data_root ) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT . '/../documents' ));
2010-10-03 02:12:54 +02:00
define ( 'DOL_MAIN_URL_ROOT' , ( isset ( $dolibarr_main_url_root ) ? $dolibarr_main_url_root : '' )); // URL relative root
$uri = preg_replace ( '/^http(s?):\/\//i' , '' , constant ( 'DOL_MAIN_URL_ROOT' )); // $uri contains url without http*
2011-09-29 22:21:57 +02:00
$suburi = strstr ( $uri , '/' ); // $suburi contains url without domain
2010-10-03 02:12:54 +02:00
if ( $suburi == '/' ) $suburi = '' ; // If $suburi is /, it is now ''
define ( 'DOL_URL_ROOT' , $suburi ); // URL relative root ('', '/dolibarr', ...)
2009-08-26 20:59:13 +02:00
if ( empty ( $conf -> file -> character_set_client )) $conf -> file -> character_set_client = " UTF-8 " ;
if ( empty ( $conf -> db -> character_set )) $conf -> db -> character_set = 'utf8' ;
2016-11-07 01:53:34 +01:00
if ( empty ( $conf -> db -> dolibarr_main_db_collation )) $conf -> db -> dolibarr_main_db_collation = 'utf8_unicode_ci' ;
2009-08-26 20:59:13 +02:00
if ( empty ( $conf -> db -> dolibarr_main_db_encryption )) $conf -> db -> dolibarr_main_db_encryption = 0 ;
if ( empty ( $conf -> db -> dolibarr_main_db_cryptkey )) $conf -> db -> dolibarr_main_db_cryptkey = '' ;
2008-10-09 16:46:07 +02:00
if ( empty ( $conf -> db -> user )) $conf -> db -> user = '' ;
2008-04-04 02:30:57 +02:00
2010-10-03 02:12:54 +02:00
// Define array of document root directories
$conf -> file -> dol_document_root = array ( DOL_DOCUMENT_ROOT );
if ( ! empty ( $dolibarr_main_document_root_alt ))
{
// dolibarr_main_document_root_alt contains several directories
$values = preg_split ( '/[;,]/' , $dolibarr_main_document_root_alt );
foreach ( $values as $value )
{
$conf -> file -> dol_document_root [] = $value ;
}
}
2009-01-20 00:32:18 +01:00
2017-10-22 14:44:50 +02:00
// Security check (old method, when directory is renamed /install.lock)
if ( preg_match ( '/install\.lock/i' , $_SERVER [ " SCRIPT_FILENAME " ]))
2008-04-04 02:30:57 +02:00
{
2018-06-27 01:53:36 +02:00
if ( ! is_object ( $langs ))
{
2018-06-30 01:59:54 +02:00
$langs = new Translate ( '..' , $conf );
2018-06-27 01:53:36 +02:00
$langs -> setDefaultLang ( 'auto' );
}
$langs -> load ( " install " );
2018-06-24 15:44:13 +02:00
print $langs -> trans ( " YouTryInstallDisabledByDirLock " );
2011-07-11 12:53:37 +02:00
if ( ! empty ( $dolibarr_main_url_root ))
{
2018-06-24 15:44:13 +02:00
print 'Click on following link, <a href="' . $dolibarr_main_url_root . '/admin/index.php?mainmenu=home&leftmenu=setup' . ( isset ( $_POST [ " login " ]) ? '&username=' . urlencode ( $_POST [ " login " ]) : '' ) . '">' ;
print $langs -> trans ( " ClickHereToGoToApp " );
2011-09-29 22:21:57 +02:00
print '</a>' ;
2011-07-11 12:53:37 +02:00
}
2011-09-29 22:21:57 +02:00
exit ;
2008-04-04 02:30:57 +02:00
}
2016-01-08 11:57:18 +01:00
$lockfile = DOL_DATA_ROOT . '/install.lock' ;
2016-01-14 11:17:47 +01:00
if ( constant ( 'DOL_DATA_ROOT' ) === null ) {
2016-01-08 11:57:18 +01:00
// We don't have a configuration file yet
// Try to detect any lockfile in the default documents path
$lockfile = '../../documents/install.lock' ;
}
if ( @ file_exists ( $lockfile ))
2008-04-04 02:30:57 +02:00
{
2018-06-27 01:53:36 +02:00
if ( ! is_object ( $langs ))
{
2018-06-30 01:59:54 +02:00
$langs = new Translate ( '..' , $conf );
2018-06-27 01:53:36 +02:00
$langs -> setDefaultLang ( 'auto' );
}
$langs -> load ( " install " );
2018-06-24 15:44:13 +02:00
print $langs -> trans ( " YouTryInstallDisabledByFileLock " );
2011-09-29 22:21:57 +02:00
if ( ! empty ( $dolibarr_main_url_root ))
{
2018-06-24 15:44:13 +02:00
print $langs -> trans ( " ClickOnLinkOrRemoveManualy " ) . '<br>' ;
2011-09-29 22:21:57 +02:00
print '<a href="' . $dolibarr_main_url_root . '/admin/index.php?mainmenu=home&leftmenu=setup' . ( isset ( $_POST [ " login " ]) ? '&username=' . urlencode ( $_POST [ " login " ]) : '' ) . '">' ;
2018-06-24 15:44:13 +02:00
print $langs -> trans ( " ClickHereToGoToApp " );
2011-09-29 22:21:57 +02:00
print '</a>' ;
}
2011-07-11 12:53:37 +02:00
else
{
print 'If you always reach this page, you must remove install.lock file manually.<br>' ;
}
2011-09-29 22:21:57 +02:00
exit ;
2008-04-04 02:30:57 +02:00
}
2011-10-03 17:19:39 +02:00
// Force usage of log file for install and upgrades
2006-06-17 20:12:46 +02:00
$conf -> syslog -> enabled = 1 ;
2013-01-10 08:27:12 +01:00
$conf -> global -> SYSLOG_LEVEL = constant ( 'LOG_DEBUG' );
2013-01-28 11:43:49 +01:00
if ( ! defined ( 'SYSLOG_HANDLERS' )) define ( 'SYSLOG_HANDLERS' , '["mod_syslog_file"]' );
2013-01-10 08:27:12 +01:00
if ( ! defined ( 'SYSLOG_FILE' )) // To avoid warning on systems with constant already defined
{
if ( @ is_writable ( '/tmp' )) define ( 'SYSLOG_FILE' , '/tmp/dolibarr_install.log' );
else if ( ! empty ( $_ENV [ " TMP " ]) && @ is_writable ( $_ENV [ " TMP " ])) define ( 'SYSLOG_FILE' , $_ENV [ " TMP " ] . '/dolibarr_install.log' );
else if ( ! empty ( $_ENV [ " TEMP " ]) && @ is_writable ( $_ENV [ " TEMP " ])) define ( 'SYSLOG_FILE' , $_ENV [ " TEMP " ] . '/dolibarr_install.log' );
else if ( @ is_writable ( '../../../../' ) && @ file_exists ( '../../../../startdoliwamp.bat' )) define ( 'SYSLOG_FILE' , '../../../../dolibarr_install.log' ); // For DoliWamp
else if ( @ is_writable ( '../../' )) define ( 'SYSLOG_FILE' , '../../dolibarr_install.log' ); // For others
//print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
}
2018-01-19 11:43:55 +01:00
if ( defined ( 'SYSLOG_FILE' )) $conf -> global -> SYSLOG_FILE = constant ( 'SYSLOG_FILE' );
2013-01-10 08:27:12 +01:00
if ( ! defined ( 'SYSLOG_FILE_NO_ERROR' )) define ( 'SYSLOG_FILE_NO_ERROR' , 1 );
// We init log handler for install
$handlers = array ( 'mod_syslog_file' );
foreach ( $handlers as $handler )
{
$file = DOL_DOCUMENT_ROOT . '/core/modules/syslog/' . $handler . '.php' ;
if ( ! file_exists ( $file ))
{
throw new Exception ( 'Missing log handler file ' . $handler . '.php' );
}
require_once $file ;
$loghandlerinstance = new $handler ();
if ( ! $loghandlerinstance instanceof LogHandlerInterface )
{
throw new Exception ( 'Log handler does not extend LogHandlerInterface' );
}
2013-01-28 12:22:12 +01:00
if ( empty ( $conf -> loghandlers [ $handler ])) $conf -> loghandlers [ $handler ] = $loghandlerinstance ;
2013-01-10 08:27:12 +01:00
}
2012-12-27 15:22:40 +01:00
2011-03-07 23:35:35 +01:00
// Removed magic_quotes
2012-03-21 02:12:44 +01:00
if ( function_exists ( 'get_magic_quotes_gpc' )) // magic_quotes_* removed in PHP 5.4
2008-01-06 11:56:15 +01:00
{
2011-09-29 22:21:57 +02:00
if ( get_magic_quotes_gpc ())
{
// Forcing parameter setting magic_quotes_gpc and cleaning parameters
// (Otherwise he would have for each position, condition
// Reading stripslashes variable according to state get_magic_quotes_gpc).
// Off mode (recommended, you just do $db->escape when an insert / update.
function stripslashes_deep ( $value )
{
return ( is_array ( $value ) ? array_map ( 'stripslashes_deep' , $value ) : stripslashes ( $value ));
}
$_GET = array_map ( 'stripslashes_deep' , $_GET );
$_POST = array_map ( 'stripslashes_deep' , $_POST );
$_COOKIE = array_map ( 'stripslashes_deep' , $_COOKIE );
$_REQUEST = array_map ( 'stripslashes_deep' , $_REQUEST );
@ set_magic_quotes_runtime ( 0 );
}
2006-05-10 20:21:05 +02:00
}
2006-06-17 02:58:51 +02:00
// Defini objet langs
2008-12-08 01:04:11 +01:00
$langs = new Translate ( '..' , $conf );
2017-06-10 21:37:27 +02:00
if ( GETPOST ( 'lang' , 'aZ09' )) $langs -> setDefaultLang ( GETPOST ( 'lang' , 'aZ09' ));
2012-04-28 16:37:58 +02:00
else $langs -> setDefaultLang ( 'auto' );
2005-11-04 02:28:28 +01:00
$bc [ false ] = ' class="bg1"' ;
$bc [ true ] = ' class="bg2"' ;
2006-06-17 20:12:46 +02:00
2010-01-20 18:54:44 +01:00
/**
2011-09-29 22:21:57 +02:00
* Load conf file ( file must exists )
*
* @ param string $dolibarr_main_document_root Root directory of Dolibarr bin files
* @ return int < 0 if KO , > 0 if OK
2010-01-20 18:54:44 +01:00
*/
2007-10-04 19:07:15 +02:00
function conf ( $dolibarr_main_document_root )
{
2011-09-29 22:21:57 +02:00
global $conf ;
global $dolibarr_main_db_type ;
global $dolibarr_main_db_host ;
global $dolibarr_main_db_port ;
global $dolibarr_main_db_name ;
global $dolibarr_main_db_user ;
global $dolibarr_main_db_pass ;
global $character_set_client ;
2012-08-23 02:04:35 +02:00
$return = include_once $dolibarr_main_document_root . '/core/class/conf.class.php' ;
2011-09-29 22:21:57 +02:00
if ( ! $return ) return - 1 ;
$conf = new Conf ();
$conf -> db -> type = trim ( $dolibarr_main_db_type );
$conf -> db -> host = trim ( $dolibarr_main_db_host );
$conf -> db -> port = trim ( $dolibarr_main_db_port );
$conf -> db -> name = trim ( $dolibarr_main_db_name );
$conf -> db -> user = trim ( $dolibarr_main_db_user );
$conf -> db -> pass = trim ( $dolibarr_main_db_pass );
2016-11-07 01:53:34 +01:00
// Mysql driver support has been removed in favor of mysqli
if ( $conf -> db -> type == 'mysql' ) $conf -> db -> type = 'mysqli' ;
2011-09-29 22:21:57 +02:00
if ( empty ( $character_set_client )) $character_set_client = " UTF-8 " ;
$conf -> file -> character_set_client = strtoupper ( $character_set_client );
2016-11-07 01:53:34 +01:00
if ( empty ( $dolibarr_main_db_character_set )) $dolibarr_main_db_character_set = ( $conf -> db -> type == 'mysqli' ? 'utf8' : '' );
2011-09-29 22:21:57 +02:00
$conf -> db -> character_set = $dolibarr_main_db_character_set ;
2016-11-07 01:53:34 +01:00
if ( empty ( $dolibarr_main_db_collation )) $dolibarr_main_db_collation = ( $conf -> db -> type == 'mysqli' ? 'utf8_unicode_ci' : '' );
2011-09-29 22:21:57 +02:00
$conf -> db -> dolibarr_main_db_collation = $dolibarr_main_db_collation ;
if ( empty ( $dolibarr_main_db_encryption )) $dolibarr_main_db_encryption = 0 ;
$conf -> db -> dolibarr_main_db_encryption = $dolibarr_main_db_encryption ;
if ( empty ( $dolibarr_main_db_cryptkey )) $dolibarr_main_db_cryptkey = '' ;
$conf -> db -> dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey ;
2011-10-03 17:19:39 +02:00
// Force usage of log file for install and upgrades
2011-09-29 22:21:57 +02:00
$conf -> syslog -> enabled = 1 ;
$conf -> global -> SYSLOG_LEVEL = constant ( 'LOG_DEBUG' );
2013-01-14 17:12:13 +01:00
if ( ! defined ( 'SYSLOG_HANDLERS' )) define ( 'SYSLOG_HANDLERS' , '["mod_syslog_file"]' );
2011-09-29 22:21:57 +02:00
if ( ! defined ( 'SYSLOG_FILE' )) // To avoid warning on systems with constant already defined
{
if ( @ is_writable ( '/tmp' )) define ( 'SYSLOG_FILE' , '/tmp/dolibarr_install.log' );
else if ( ! empty ( $_ENV [ " TMP " ]) && @ is_writable ( $_ENV [ " TMP " ])) define ( 'SYSLOG_FILE' , $_ENV [ " TMP " ] . '/dolibarr_install.log' );
else if ( ! empty ( $_ENV [ " TEMP " ]) && @ is_writable ( $_ENV [ " TEMP " ])) define ( 'SYSLOG_FILE' , $_ENV [ " TEMP " ] . '/dolibarr_install.log' );
else if ( @ is_writable ( '../../../../' ) && @ file_exists ( '../../../../startdoliwamp.bat' )) define ( 'SYSLOG_FILE' , '../../../../dolibarr_install.log' ); // For DoliWamp
else if ( @ is_writable ( '../../' )) define ( 'SYSLOG_FILE' , '../../dolibarr_install.log' ); // For others
//print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
}
2018-01-19 11:43:55 +01:00
if ( defined ( 'SYSLOG_FILE' )) $conf -> global -> SYSLOG_FILE = constant ( 'SYSLOG_FILE' );
2011-10-03 17:19:39 +02:00
if ( ! defined ( 'SYSLOG_FILE_NO_ERROR' )) define ( 'SYSLOG_FILE_NO_ERROR' , 1 );
2013-03-30 14:27:13 +01:00
// We init log handler for install
$handlers = array ( 'mod_syslog_file' );
foreach ( $handlers as $handler )
{
$file = DOL_DOCUMENT_ROOT . '/core/modules/syslog/' . $handler . '.php' ;
if ( ! file_exists ( $file ))
{
throw new Exception ( 'Missing log handler file ' . $handler . '.php' );
}
2013-07-07 03:26:51 +02:00
2013-03-30 14:27:13 +01:00
require_once $file ;
$loghandlerinstance = new $handler ();
if ( ! $loghandlerinstance instanceof LogHandlerInterface )
{
throw new Exception ( 'Log handler does not extend LogHandlerInterface' );
}
2013-01-28 12:22:12 +01:00
if ( empty ( $conf -> loghandlers [ $handler ])) $conf -> loghandlers [ $handler ] = $loghandlerinstance ;
2013-03-30 14:27:13 +01:00
}
2013-07-07 03:26:51 +02:00
2011-09-29 22:21:57 +02:00
return 1 ;
2007-07-19 21:30:32 +02:00
}
2007-11-09 00:06:00 +01:00
2010-01-20 18:54:44 +01:00
/**
2012-04-28 16:37:58 +02:00
* Show HTML header of install pages
2010-01-20 18:54:44 +01:00
*
2012-10-08 02:45:58 +02:00
* @ param string $subtitle Title
2012-10-07 20:04:07 +02:00
* @ param string $next Next
* @ param string $action Action code ( 'set' or 'upgrade' )
* @ param string $param Param
* @ param string $forcejqueryurl Set jquery relative URL ( must end with / if defined )
2016-12-23 00:28:16 +01:00
* @ param string $csstable Css for table
2011-09-29 22:21:57 +02:00
* @ return void
2010-01-20 18:54:44 +01:00
*/
2016-12-23 00:28:16 +01:00
function pHeader ( $subtitle , $next , $action = 'set' , $param = '' , $forcejqueryurl = '' , $csstable = 'main-inside' )
2005-11-03 19:00:17 +01:00
{
2011-09-29 22:21:57 +02:00
global $conf ;
global $langs ;
$langs -> load ( " main " );
$langs -> load ( " admin " );
2018-06-24 15:44:13 +02:00
$langs -> load ( " install " );
2011-09-29 22:21:57 +02:00
2017-12-20 20:18:41 +01:00
$jquerytheme = 'base' ;
2012-12-05 00:45:10 +01:00
2012-10-08 02:45:58 +02:00
if ( $forcejqueryurl )
{
$jQueryCustomPath = $forcejqueryurl ;
$jQueryUiCustomPath = $forcejqueryurl ;
}
else
{
$jQueryCustomPath = ( defined ( 'JS_JQUERY' ) && constant ( 'JS_JQUERY' )) ? JS_JQUERY : false ;
$jQueryUiCustomPath = ( defined ( 'JS_JQUERY_UI' ) && constant ( 'JS_JQUERY_UI' )) ? JS_JQUERY_UI : false ;
}
// We force the content charset
2011-09-29 22:21:57 +02:00
header ( " Content-type: text/html; charset= " . $conf -> file -> character_set_client );
2017-05-09 21:01:37 +02:00
header ( " X-Content-Type-Options: nosniff " );
2017-06-17 18:03:53 +02:00
2016-12-17 08:48:41 +01:00
print '<!DOCTYPE HTML>' . " \n " ;
2011-09-29 22:21:57 +02:00
print '<html>' . " \n " ;
print '<head>' . " \n " ;
2018-04-22 12:10:53 +02:00
print '<meta charset="' . $conf -> file -> character_set_client . '">' . " \n " ;
2017-06-17 18:03:53 +02:00
print '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . " \n " ;
2018-04-22 12:10:53 +02:00
print '<meta name="generator" content="Dolibarr installer">' . " \n " ;
2012-04-28 16:37:58 +02:00
print '<link rel="stylesheet" type="text/css" href="default.css">' . " \n " ;
2012-10-07 20:04:07 +02:00
print '<!-- Includes CSS for JQuery -->' . " \n " ;
2012-10-08 02:45:58 +02:00
if ( $jQueryUiCustomPath ) print '<link rel="stylesheet" type="text/css" href="' . $jQueryUiCustomPath . 'css/' . $jquerytheme . '/jquery-ui.min.css" />' . " \n " ; // JQuery
2015-10-11 19:18:03 +02:00
else print '<link rel="stylesheet" type="text/css" href="../includes/jquery/css/' . $jquerytheme . '/jquery-ui.min.css" />' . " \n " ; // JQuery
2012-10-07 20:04:07 +02:00
print '<!-- Includes JS for JQuery -->' . " \n " ;
2012-10-08 02:45:58 +02:00
if ( $jQueryCustomPath ) print '<script type="text/javascript" src="' . $jQueryCustomPath . 'jquery.min.js"></script>' . " \n " ;
2015-07-06 16:34:58 +02:00
else print '<script type="text/javascript" src="../includes/jquery/js/jquery.min.js"></script>' . " \n " ;
2012-10-08 02:45:58 +02:00
if ( $jQueryUiCustomPath ) print '<script type="text/javascript" src="' . $jQueryUiCustomPath . 'jquery-ui.min.js"></script>' . " \n " ;
2015-10-11 19:18:03 +02:00
else print '<script type="text/javascript" src="../includes/jquery/js/jquery-ui.min.js"></script>' . " \n " ;
2012-10-07 20:04:07 +02:00
2011-09-29 22:21:57 +02:00
print '<title>' . $langs -> trans ( " DolibarrSetup " ) . '</title>' . " \n " ;
print '</head>' . " \n " ;
2012-10-07 20:04:07 +02:00
2011-09-29 22:21:57 +02:00
print '<body>' . " \n " ;
2012-10-07 20:04:07 +02:00
2016-12-23 00:28:16 +01:00
print '<div class="divlogoinstall" style="text-align:center">' ;
print '<img class="imglogoinstall" src="../theme/dolibarr_logo.png" alt="Dolibarr logo"><br>' ;
2012-10-08 02:45:58 +02:00
print DOL_VERSION ;
2016-12-23 00:28:16 +01:00
print '</div><br>' ;
2012-10-07 20:04:07 +02:00
2011-09-29 22:21:57 +02:00
print '<span class="titre">' . $langs -> trans ( " DolibarrSetup " );
2012-10-08 02:45:58 +02:00
if ( $subtitle ) {
print ' - ' . $subtitle ;
2011-09-29 22:21:57 +02:00
}
print '</span>' . " \n " ;
2016-12-13 02:18:14 +01:00
print '<form name="forminstall" style="width: 100%" action="' . $next . '.php' . ( $param ? '?' . $param : '' ) . '" method="POST">' . " \n " ;
2011-09-29 22:21:57 +02:00
print '<input type="hidden" name="testpost" value="ok">' . " \n " ;
print '<input type="hidden" name="action" value="' . $action . '">' . " \n " ;
print '<table class="main" width="100%"><tr><td>' . " \n " ;
2016-12-23 00:28:16 +01:00
print '<table class="' . $csstable . '" width="100%"><tr><td>' . " \n " ;
2005-11-03 19:00:17 +01:00
}
2005-11-04 02:28:28 +01:00
2010-01-20 18:54:44 +01:00
/**
2012-04-28 16:37:58 +02:00
* Print HTML footer of install pages
2010-01-20 18:54:44 +01:00
*
2016-05-09 11:06:18 +02:00
* @ param integer $nonext 1 = No button " Next step " , 2 = Show button but disabled with a link to enable
2012-04-28 16:37:58 +02:00
* @ param string $setuplang Language code
2011-09-29 22:21:57 +02:00
* @ param string $jscheckfunction Add a javascript check function
2015-03-17 00:21:17 +01:00
* @ param integer $withpleasewait Add also please wait tags
2011-09-29 22:21:57 +02:00
* @ return void
2010-01-20 18:54:44 +01:00
*/
2012-10-07 20:04:07 +02:00
function pFooter ( $nonext = 0 , $setuplang = '' , $jscheckfunction = '' , $withpleasewait = 0 )
2005-11-03 19:00:17 +01:00
{
2011-09-29 22:21:57 +02:00
global $conf , $langs ;
$langs -> load ( " main " );
2015-07-20 13:55:43 +02:00
$langs -> load ( " other " );
2011-09-29 22:21:57 +02:00
$langs -> load ( " admin " );
print '</td></tr></table>' . " \n " ;
print '</td></tr></table>' . " \n " ;
2015-12-31 12:02:22 +01:00
if ( ! $nonext || ( $nonext == '2' ))
2011-09-29 22:21:57 +02:00
{
2016-05-09 11:06:18 +02:00
print '<div class="nextbutton" id="nextbutton">' ;
if ( $nonext == '2' )
{
2017-06-17 18:03:53 +02:00
print $langs -> trans ( " ErrorFoundDuringMigration " , isset ( $_SERVER [ " REQUEST_URI " ]) ? $_SERVER [ " REQUEST_URI " ] . '&ignoreerrors=1' : '' ) . '<br><br>' ;
2016-05-09 11:06:18 +02:00
}
2017-06-10 21:37:27 +02:00
2016-05-09 11:06:18 +02:00
print '<input type="submit" ' . ( $nonext == '2' ? 'disabled="disabled" ' : '' ) . 'value="' . $langs -> trans ( " NextStep " ) . ' ->"' ;
2011-09-29 22:21:57 +02:00
if ( $jscheckfunction ) print ' onClick="return ' . $jscheckfunction . '();"' ;
print '></div>' ;
2012-10-07 20:04:07 +02:00
if ( $withpleasewait ) print '<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>' . $langs -> trans ( " NextStepMightLastALongTime " ) . '<br><br><div class="blinkwait">' . $langs -> trans ( " PleaseBePatient " ) . '</div></div>' ;
2011-09-29 22:21:57 +02:00
}
if ( $setuplang )
{
print '<input type="hidden" name="selectlang" value="' . $setuplang . '">' ;
}
print '</form>' . " \n " ;
// If there is some logs in buffer to show
if ( isset ( $conf -> logbuffer ) && count ( $conf -> logbuffer ))
{
print " \n " ;
print " <!-- Start of log output \n " ;
//print '<div class="hidden">'."\n";
foreach ( $conf -> logbuffer as $logline )
{
print $logline . " <br> \n " ;
}
//print '</div>'."\n";
print " End of log output --> \n " ;
print " \n " ;
}
print '</body>' . " \n " ;
print '</html>' . " \n " ;
2005-11-03 19:00:17 +01:00
}
2005-11-04 02:28:28 +01:00
2010-01-20 18:54:44 +01:00
/**
* Log function for install pages
*
2011-09-29 22:21:57 +02:00
* @ param string $message Message
* @ param int $level Level of log
* @ return void
2010-01-20 18:54:44 +01:00
*/
2007-10-10 01:28:27 +02:00
function dolibarr_install_syslog ( $message , $level = LOG_DEBUG )
2005-11-03 19:00:17 +01:00
{
2011-09-29 22:21:57 +02:00
if ( ! defined ( 'LOG_DEBUG' )) define ( 'LOG_DEBUG' , 6 );
dol_syslog ( $message , $level );
2006-06-17 02:58:51 +02:00
}
2016-02-22 18:45:00 +01:00
/**
* Automatically detect Dolibarr ' s main document root
*
* @ return string
*/
function detect_dolibarr_main_document_root ()
{
// If PHP is in CGI mode, SCRIPT_FILENAME is PHP's path.
// Since that's not what we want, we suggest $_SERVER["DOCUMENT_ROOT"]
2016-12-10 12:11:09 +01:00
if ( $_SERVER [ " SCRIPT_FILENAME " ] == 'php' || preg_match ( '/[\\/]php$/i' , $_SERVER [ " SCRIPT_FILENAME " ]) || preg_match ( '/php\.exe$/i' , $_SERVER [ " SCRIPT_FILENAME " ]))
{
2016-02-22 18:45:00 +01:00
$dolibarr_main_document_root = $_SERVER [ " DOCUMENT_ROOT " ];
if ( ! preg_match ( '/[\\/]dolibarr[\\/]htdocs$/i' , $dolibarr_main_document_root )) {
$dolibarr_main_document_root .= " /dolibarr/htdocs " ;
}
} else {
// We assume /install to be under /htdocs, so we get the parent directory of the current directory
$dolibarr_main_document_root = dirname ( dirname ( $_SERVER [ " SCRIPT_FILENAME " ]));
}
return $dolibarr_main_document_root ;
}
/**
* Automatically detect Dolibarr ' s main data root
*
* @ param string $dolibarr_main_document_root Current main document root
* @ return string
*/
function detect_dolibarr_main_data_root ( $dolibarr_main_document_root )
{
$dolibarr_main_data_root = preg_replace ( " / \ /htdocs $ / " , " " , $dolibarr_main_document_root );
$dolibarr_main_data_root .= " /documents " ;
return $dolibarr_main_data_root ;
}
/**
* Automatically detect Dolibarr ' s main URL root
*
* @ return string
*/
function detect_dolibarr_main_url_root ()
{
// If defined (Ie: Apache with Linux)
if ( isset ( $_SERVER [ " SCRIPT_URI " ])) {
$dolibarr_main_url_root = $_SERVER [ " SCRIPT_URI " ];
} // If defined (Ie: Apache with Caudium)
elseif ( isset ( $_SERVER [ " SERVER_URL " ]) && isset ( $_SERVER [ " DOCUMENT_URI " ])) {
$dolibarr_main_url_root = $_SERVER [ " SERVER_URL " ] . $_SERVER [ " DOCUMENT_URI " ];
} // If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
else {
$proto = 'http' ;
if ( ! empty ( $_SERVER [ " HTTP_HOST " ])) {
$serverport = $_SERVER [ " HTTP_HOST " ];
} else {
$serverport = $_SERVER [ " SERVER_NAME " ];
}
$dolibarr_main_url_root = $proto . " :// " . $serverport . $_SERVER [ " SCRIPT_NAME " ];
}
// Clean proposed URL
// We assume /install to be under /htdocs, so we get the parent path of the current URL
$dolibarr_main_url_root = dirname ( dirname ( $dolibarr_main_url_root ));
return $dolibarr_main_url_root ;
}
/**
* Replaces automatic database login by actual value
*
* @ param string $force_install_databaserootlogin Login
* @ return string
*/
function parse_database_login ( $force_install_databaserootlogin )
{
return preg_replace ( '/__SUPERUSERLOGIN__/' , 'root' , $force_install_databaserootlogin );
}
/**
* Replaces automatic database password by actual value
*
* @ param string $force_install_databaserootpass Password
* @ return string
*/
function parse_database_pass ( $force_install_databaserootpass )
{
return preg_replace ( '/__SUPERUSERPASSWORD__/' , '' , $force_install_databaserootpass );
}