Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 231 lines (209 sloc) 13.365 kb
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
1 <?PHP
2 /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
4 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6d98ba7 Test git to cvs synchro
Regis Houssin authored
7 * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
8 * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
9 * Copyright (C) 2006 Andre Cianfarani <andre.cianfarani@acdeveloppement.net>
10 * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
37ead2f @eldy Fix: Avoid errors into rpm packages
eldy authored
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
24 */
25
26 /**
27 * \file htdocs/filefunc.inc.php
28 * \ingroup core
abde2ef @eldy Fix: definition of DOL_DOCUMENT_ROOT mus be done only into environment i...
eldy authored
29 * \brief File that include conf.php file and commons lib like functions.lib.php
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
30 */
31
567b456 Fix: avoid phpunit error
Regis Houssin authored
32 if (! defined('DOL_VERSION')) define('DOL_VERSION','3.2.0-alpha'); // Also defined in htdocs/install/inc.php (Ex: x.y.z-alpha, x.y.z)
33 if (! defined('EURO')) define('EURO',chr(128));
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
34
35 // Definition des constantes syslog
784f696 @eldy Qual: Some fixes to make working with PHP option error_reporting
eldy authored
36 if (! defined('LOG_DEBUG'))
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
37 {
784f696 @eldy Qual: Some fixes to make working with PHP option error_reporting
eldy authored
38 if (function_exists("define_syslog_variables"))
39 {
40 define_syslog_variables(); // Deprecated since php 5.3.0, syslog variables no longer need to be initialized
41 }
42 else
43 {
44 // Pour PHP sans syslog (comme sous Windows)
45 define('LOG_EMERG',0);
46 define('LOG_ALERT',1);
47 define('LOG_CRIT',2);
48 define('LOG_ERR',3);
49 define('LOG_WARNING',4);
50 define('LOG_NOTICE',5);
51 define('LOG_INFO',6);
52 define('LOG_DEBUG',7);
53 }
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
54 }
55
56 // Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL)
57 error_reporting(E_ALL ^ E_NOTICE);
784f696 @eldy Qual: Some fixes to make working with PHP option error_reporting
eldy authored
58 //error_reporting(E_ALL | E_STRICT);
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
59
60
5efe1cd Fix: Perl-style comments are not allowed. Use "// Comment." or "/* comme...
Regis Houssin authored
61 // Define vars
53e1579 @eldy Fix: Code could not works for debian packages
eldy authored
62 $conffiletoshowshort = "conf.php";
5efe1cd Fix: Perl-style comments are not allowed. Use "// Comment." or "/* comme...
Regis Houssin authored
63 // Define localization of conf file
53e1579 @eldy Fix: Code could not works for debian packages
eldy authored
64 $conffile = "conf/conf.php";
65 $conffiletoshow = "htdocs/conf/conf.php";
5efe1cd Fix: Perl-style comments are not allowed. Use "// Comment." or "/* comme...
Regis Houssin authored
66 // For debian/redhat like systems
67 //$conffile = "/etc/dolibarr/conf.php";
68 //$conffiletoshow = "/etc/dolibarr/conf.php";
53e1579 @eldy Fix: Code could not works for debian packages
eldy authored
69
70
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
71 // Include configuration
53e1579 @eldy Fix: Code could not works for debian packages
eldy authored
72 $result=@include_once($conffile);
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
73 if (! $result && ! empty($_SERVER["GATEWAY_INTERFACE"])) // If install not done and we are in a web session
74 {
c4d7e87 @eldy Autodetect url relative path
eldy authored
75 header("Location: install/index.php");
76 exit;
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
77 }
78
79 if (empty($dolibarr_main_db_port)) $dolibarr_main_db_port=0; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
80 if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
81 if (empty($dolibarr_main_db_prefix)) $dolibarr_main_db_prefix='llx_';
82 if (empty($dolibarr_main_db_character_set)) $dolibarr_main_db_character_set='latin1'; // Old installation
83 if (empty($dolibarr_main_db_collation)) $dolibarr_main_db_collation='latin1_swedish_ci'; // Old installation
84 if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0;
85 if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey='';
86 if (empty($dolibarr_main_limit_users)) $dolibarr_main_limit_users=0;
87 if (empty($dolibarr_mailing_limit_sendbyweb)) $dolibarr_mailing_limit_sendbyweb=0;
88 if (empty($force_charset_do_notuse)) $force_charset_do_notuse='UTF-8';
89
90 // Security: CSRF protection
91 // This test check if referrer ($_SERVER['HTTP_REFERER']) is same web site than Dolibarr ($_SERVER['HTTP_HOST'])
92 // when we post forms (we allow GET to allow direct link to access a particular page).
93 if (! defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && ! empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET' && ! empty($_SERVER['HTTP_HOST']) && ! empty($_SERVER['HTTP_REFERER']) && ! preg_match('/'.preg_quote($_SERVER['HTTP_HOST'],'/').'/i', $_SERVER['HTTP_REFERER']))
94 {
c4d7e87 @eldy Autodetect url relative path
eldy authored
95 //print 'HTTP_POST='.$_SERVER['HTTP_HOST'].' HTTP_REFERER='.$_SERVER['HTTP_REFERER'];
96 print "Access refused by CSRF protection in main.inc.php.\n";
97 print "If you access your server behind a proxy using url rewriting, you might add the line \$dolibarr_nocsrfcheck=1 into your conf.php file.\n";
98 die;
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
99 }
100 if (empty($dolibarr_main_db_host))
101 {
477cd46 @eldy Enhance debian package
eldy authored
102 print 'Dolibarr setup is not yet complete.<br><br>'."\n";
103 print '<a href="install/index.php">Click here to finish Dolibarr install process</a> ...'."\n";
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
104 die;
105 }
106 if (empty($dolibarr_main_url_root))
107 {
108 print 'Value for parameter \'dolibarr_main_url_root\' is not defined in your \'htdocs\conf\conf.php\' file.<br>'."\n";
109 print 'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)'."\n";
110 die;
111 }
112 if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
113 if (empty($dolibarr_main_data_root))
114 {
115 // Si repertoire documents non defini, on utilise celui par defaut
116 $dolibarr_main_data_root=str_replace("/htdocs","",$dolibarr_main_document_root);
117 $dolibarr_main_data_root.="/documents";
118 }
119
120 // Define some constants
b934bee @eldy Fix: Definition of alt url should use same syntax than main url (so full...
eldy authored
121 define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir (defined only for some code that want to be compatible with old versions without this parameter)
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
122 define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents)
123 define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem core php (htdocs)
b934bee @eldy Fix: Definition of alt url should use same syntax than main url (so full...
eldy authored
124 if (! empty($dolibarr_main_document_root_alt))
125 {
c4d7e87 @eldy Autodetect url relative path
eldy authored
126 define('DOL_DOCUMENT_ROOT_ALT', $dolibarr_main_document_root_alt); // Filesystem paths to alternate core php (alternate htdocs)
b934bee @eldy Fix: Definition of alt url should use same syntax than main url (so full...
eldy authored
127 }
d31dbaf @eldy Now dolibarr_main_url_root is detected automatically. Value in conf file...
eldy authored
128 // Define DOL_MAIN_URL_ROOT and DOL_URL_ROOT
022ad87 @eldy Removed useless code
eldy authored
129 $tmp='';
d4a49a1 @eldy Fix: If autodetect fails, we use config
eldy authored
130 $found=0;
131 $real_dolibarr_main_document_root=str_replace('\\','/',realpath($dolibarr_main_document_root));
132 $pathroot=$_SERVER["DOCUMENT_ROOT"];
133 $paths=explode('/',str_replace('\\','/',$_SERVER["SCRIPT_NAME"]));
134 $concatpath='';
4d65503 @eldy New: Enhance form to post a new member
eldy authored
135 foreach($paths as $tmppath)
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
136 {
4d65503 @eldy New: Enhance form to post a new member
eldy authored
137 if ($tmppath) $concatpath.='/'.$tmppath;
d4a49a1 @eldy Fix: If autodetect fails, we use config
eldy authored
138 //print $real_$dolibarr_main_document_root.'-'.realpath($pathroot.$concatpath).'<br>';
139 if ($real_dolibarr_main_document_root == realpath($pathroot.$concatpath))
140 {
141 $tmp3=$concatpath;
142 //print "Found relative url = ".$tmp3;
143 $found=1;
144 break;
145 }
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
146 }
29bfeab @eldy Fix: Alt url
eldy authored
147 if (! $found) // If autodetect fails (Ie: when uing apache alias that point outside default DOCUMENT_ROOT.
245866a @eldy Autodetect url relative path
eldy authored
148 {
149 $tmp=$dolibarr_main_url_root;
150 }
d4a49a1 @eldy Fix: If autodetect fails, we use config
eldy authored
151 else $tmp='http'.((empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on')?'':'s').'://'.$_SERVER["SERVER_NAME"].((empty($_SERVER["SERVER_PORT"])||$_SERVER["SERVER_PORT"]==80)?'':':'.$_SERVER["SERVER_PORT"]).($tmp3?(preg_match('/^\//',$tmp3)?'':'/').$tmp3:'');
152 //print "tmp1=".$tmp1." tmp2=".$tmp2." tmp3=".$tmp3." tmp=".$tmp;
153
d31dbaf @eldy Now dolibarr_main_url_root is detected automatically. Value in conf file...
eldy authored
154 if (! empty($dolibarr_main_force_https)) $tmp=preg_replace('/^http:/i','https:',$tmp);
155 define('DOL_MAIN_URL_ROOT', $tmp); // URL absolute root (https://sss/dolibarr, ...)
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
156 $uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
d31dbaf @eldy Now dolibarr_main_url_root is detected automatically. Value in conf file...
eldy authored
157 $suburi = strstr($uri, '/'); // $suburi contains url without domain
158 if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now ''
159 define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
160 // Define DOL_MAIN_URL_ROOT_ALT and DOL_URL_ROOT_ALT
b934bee @eldy Fix: Definition of alt url should use same syntax than main url (so full...
eldy authored
161 if (! empty($dolibarr_main_url_root_alt))
162 {
29bfeab @eldy Fix: Alt url
eldy authored
163 $altpart=str_replace($dolibarr_main_url_root,'',$dolibarr_main_url_root_alt);
fcf4bcd @eldy Can use javascript files with full http link
eldy authored
164 if (! preg_match('/^\//',$altpart) && ! empty($altpart)) { $tmp_alt=$dolibarr_main_url_root_alt; } // Manage case url=http://localhost/aaa and url_alt=http://localhost/aaabbb
165 else $tmp_alt=$tmp.((preg_match('/\/$/',$tmp)||preg_match('/^\//',$altpart))?'':'/').$altpart;
166 //$tmp_alt=$dolibarr_main_url_root_alt;
167 define('DOL_MAIN_URL_ROOT_ALT', $tmp_alt); // URL absolute root (https://sss/dolibarr/custom, ...)
c4d7e87 @eldy Autodetect url relative path
eldy authored
168 $uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT_ALT')); // $uri contains url without http*
169 $suburi = strstr($uri, '/'); // $suburi contains url without domain
170 if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now ''
171 define('DOL_URL_ROOT_ALT', $suburi); // URL relative root ('', '/dolibarr/custom', ...)
b934bee @eldy Fix: Definition of alt url should use same syntax than main url (so full...
eldy authored
172 }
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
173 // Define prefix
174 define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
fcf4bcd @eldy Can use javascript files with full http link
eldy authored
175 //print DOL_URL_ROOT.'-'.DOL_URL_ROOT_ALT;
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
176
abde2ef @eldy Fix: definition of DOL_DOCUMENT_ROOT mus be done only into environment i...
eldy authored
177
178 /*
179 * Define PATH to external libraries
180 * To use other version than embeded libraries, define here constant to path. Use '' to use include class path autodetect.
181 */
182 // Path to root libraries
4e302fa @eldy Qual: Centralise declaratin of external lib artichow at one location.
eldy authored
183 if (! defined('ADODB_PATH')) { define('ADODB_PATH', (!isset($dolibarr_lib_ADODB_PATH))?DOL_DOCUMENT_ROOT.'/includes/adodbtime/':(empty($dolibarr_lib_ADODB_PATH)?'':$dolibarr_lib_ADODB_PATH.'/')); }
184 if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', (!isset($dolibarr_lib_TCPDF_PATH))?DOL_DOCUMENT_ROOT.'/includes/tcpdf/':(empty($dolibarr_lib_TCPDF_PATH)?'':$dolibarr_lib_TCPDF_PATH.'/')); }
185 if (! defined('FPDFI_PATH')) { define('FPDFI_PATH', (!isset($dolibarr_lib_FPDFI_PATH))?DOL_DOCUMENT_ROOT.'/includes/fpdfi/':(empty($dolibarr_lib_FPDFI_PATH)?'':$dolibarr_lib_FPDFI_PATH.'/')); }
186 if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH))?DOL_DOCUMENT_ROOT.'/includes/nusoap/lib/':(empty($dolibarr_lib_NUSOAP_PATH)?'':$dolibarr_lib_NUSOAP_PATH.'/')); }
187 if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH))?DOL_DOCUMENT_ROOT.'/includes/phpexcel/':(empty($dolibarr_lib_PHPEXCEL_PATH)?'':$dolibarr_lib_PHPEXCEL_PATH.'/')); }
abde2ef @eldy Fix: definition of DOL_DOCUMENT_ROOT mus be done only into environment i...
eldy authored
188 if (! defined('GEOIP_PATH')) { define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH))?DOL_DOCUMENT_ROOT.'/includes/geoip/':(empty($dolibarr_lib_GEOIP_PATH)?'':$dolibarr_lib_GEOIP_PATH.'/')); }
189 if (! defined('ODTPHP_PATH')) { define('ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH))?DOL_DOCUMENT_ROOT.'/includes/odtphp/':(empty($dolibarr_lib_ODTPHP_PATH)?'':$dolibarr_lib_ODTPHP_PATH.'/')); }
190 if (! defined('ODTPHP_PATHTOPCLZIP')) { define('ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP))?DOL_DOCUMENT_ROOT.'/includes/odtphp/zip/pclzip/':(empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP)?'':$dolibarr_lib_ODTPHP_PATHTOPCLZIP.'/')); }
4e302fa @eldy Qual: Centralise declaratin of external lib artichow at one location.
eldy authored
191 if (! defined('ARTICHOW_PATH')) { define('ARTICHOW_PATH', (!isset($dolibarr_lib_ARTICHOW))?DOL_DOCUMENT_ROOT.'/includes/artichow/':(empty($dolibarr_lib_ARTICHOW)?'':$dolibarr_lib_ARTICHOW.'/')); }
abde2ef @eldy Fix: definition of DOL_DOCUMENT_ROOT mus be done only into environment i...
eldy authored
192 // Other required path
4e302fa @eldy Qual: Centralise declaratin of external lib artichow at one location.
eldy authored
193 if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/artichow/font':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
abde2ef @eldy Fix: definition of DOL_DOCUMENT_ROOT mus be done only into environment i...
eldy authored
194 if (! defined('ARTICHOW_FONT_NAMES')) { define('ARTICHOW_FONT_NAMES', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?'Tuffy,TuffyBold,TuffyBoldItalic,TuffyItalic':'DejaVuSans,DejaVuSans-Bold,DejaVuSans-BoldOblique,DejaVuSans-Oblique'); }
195 if (! defined('DOL_DEFAULT_TTF')) { define('DOL_DEFAULT_TTF', (!isset($dolibarr_font_DOL_DEFAULT_TTF))?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/Aerial.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF)?'':$dolibarr_font_DOL_DEFAULT_TTF)); }
196 if (! defined('DOL_DEFAULT_TTF_BOLD')) { define('DOL_DEFAULT_TTF_BOLD', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/AerialBd.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?'':$dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
197 // Old path to root deprecated (no more used).
198 //if (! defined('FPDF_PATH')) { define('FPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/fpdf/'); }
199
200
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
201 /*
202 * Include functions
203 */
204
abde2ef @eldy Fix: definition of DOL_DOCUMENT_ROOT mus be done only into environment i...
eldy authored
205 if (! defined('ADODB_DATE_VERSION')) include_once(ADODB_PATH.'adodb-time.inc.php');
206
56d6cbe [task #216] Move lib in core directory
Regis Houssin authored
207 if (! file_exists(DOL_DOCUMENT_ROOT ."/core/lib/functions.lib.php"))
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
208 {
209 print "Error: Dolibarr config file content seems to be not correctly defined.<br>\n";
210 print "Please run dolibarr setup by calling page <b>/install</b>.<br>\n";
211 exit;
212 }
213
56d6cbe [task #216] Move lib in core directory
Regis Houssin authored
214 include_once(DOL_DOCUMENT_ROOT ."/core/lib/functions.lib.php"); // Need 970ko memory (1.1 in 2.2)
c65238b [task #216] Move lib in core directory
Regis Houssin authored
215 include_once(DOL_DOCUMENT_ROOT ."/core/lib/security.lib.php"); // Include by default
20991ab @eldy Fix: Another try to make usage of alt feature working.
eldy authored
216
217 // If password is encoded, we decode it
218 if (preg_match('/crypted:/i',$dolibarr_main_db_pass) || ! empty($dolibarr_main_db_encrypted_pass))
219 {
220 if (preg_match('/crypted:/i',$dolibarr_main_db_pass))
221 {
222 $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
223 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
224 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted
225 }
226 else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
227 }
228 //print memory_get_usage();
229
230 ?>
Something went wrong with that request. Please try again.