3 * pre.php - Automatically prepend to every page.
5 * Copyright 1999-2001, VA Linux Systems
6 * Copyright 2010, Roland Mas <lolando@debian.org>
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 // Declare and init variables to store messages
29 require_once $gfcommon.'include/escapingUtils.php';
30 require_once $gfcommon.'include/config.php';
32 if (isset($_SERVER) && array_key_exists('PHP_SELF', $_SERVER) && $_SERVER['PHP_SELF']) {
33 $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
36 if (isset($GLOBALS) && array_key_exists('PHP_SELF', $GLOBALS) && $GLOBALS['PHP_SELF']) {
37 $GLOBALS['PHP_SELF'] = htmlspecialchars($GLOBALS['PHP_SELF']);
40 // Block link prefetching (Moz prefetching, Google Web Accelerator, others)
41 // http://www.google.com/webmasters/faq.html#prefetchblock
42 if (getStringFromServer('HTTP_X_moz') === 'prefetch'){
43 header(getStringFromServer('SERVER_PROTOCOL') . ' 404 Prefetch Forbidden');
44 trigger_error('Prefetch request forbidden.');
48 // Use latest rendering engine for IE (bypass compatibility mode)
49 if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], "msie")) {
50 header("X-UA-Compatible: IE=edge");
53 if (!isset($no_gz_buffer) || !$no_gz_buffer) {
54 ob_start("ob_gzhandler");
57 // Database access and other passwords when on the web
58 function setconfigfromoldsources ($sec, $var, $serv, $env, $glob) {
59 if (getenv ('SERVER_SOFTWARE')) {
60 if (function_exists ('apache_request_headers')) {
61 $headers = apache_request_headers() ;
66 if (isset ($headers[$serv])) {
67 forge_define_config_item ($var, $sec,
72 if (isset ($_ENV[$env])) {
73 forge_define_config_item ($var, $sec,
77 if (isset ($GLOBALS[$glob])) {
78 forge_define_config_item ($var, $sec,
84 if (file_exists ($gfcgfile)) {
85 require_once $gfcgfile ;
88 setconfigfromoldsources ('core', 'database_host',
89 'GForgeDbhost', 'sys_gfdbhost', 'sys_dbhost') ;
90 setconfigfromoldsources ('core', 'database_port',
91 'GForgeDbport', 'sys_gfdbport', 'sys_dbport') ;
92 setconfigfromoldsources ('core', 'database_name',
93 'GForgeDbname', 'sys_gfdbname', 'sys_dbname') ;
94 setconfigfromoldsources ('core', 'database_user',
95 'GForgeDbuser', 'sys_gfdbuser', 'sys_dbuser') ;
96 setconfigfromoldsources ('core', 'database_password',
97 'GForgeDbpasswd', 'sys_gfdbpasswd', 'sys_dbpasswd') ;
98 setconfigfromoldsources ('core', 'ldap_password',
99 'GForgeLdapPasswd', 'sys_gfldap_passwd', NULL) ;
100 setconfigfromoldsources ('core', 'jabber_password',
101 'GForgeJabberPasswd', 'sys_gfjabber_pass', NULL) ;
103 forge_define_config_item ('source_path', 'core', $fusionforge_basedir) ;
104 forge_define_config_item ('data_path', 'core', '/var/lib/gforge') ;
105 forge_define_config_item ('chroot', 'core', '$core/data_path/chroot') ;
106 forge_define_config_item ('config_path', 'core', '/etc/gforge') ;
108 require_once $gfcommon.'include/config-vars.php';
110 forge_read_config_file ($gfconfig.'/config.ini') ;
111 forge_read_config_dir ($gfconfig.'/config.ini.d/') ;
112 if (($ecf = forge_get_config ('extra_config_files')) != NULL) {
113 $ecfa = explode (',', $ecf) ;
114 foreach ($ecfa as $cf) {
116 forge_read_config_file ($cf) ;
119 if (($ecd = forge_get_config ('extra_config_dirs')) != NULL) {
120 $ecda = explode (',', $ecd) ;
121 foreach ($ecda as $cd) {
123 forge_read_config_dir ($cd) ;
127 forge_define_config_item ('installation_environment', 'core', 'production') ;
128 $installation_environment = forge_get_config ('installation_environment') ;
129 if ($installation_environment == 'development' || $installation_environment == 'integration')
130 $default_sysdebug_enable = 'true';
132 $default_sysdebug_enable = 'false';
133 forge_define_config_item ('sysdebug_enable', 'core', $default_sysdebug_enable) ;
134 forge_set_config_item_bool ('sysdebug_enable', 'core') ;
135 forge_define_config_item ('sysdebug_phphandler', 'core', 'true') ;
136 forge_set_config_item_bool ('sysdebug_phphandler', 'core') ;
137 forge_define_config_item ('sysdebug_backtraces', 'core', 'false') ;
138 forge_set_config_item_bool ('sysdebug_backtraces', 'core') ;
139 forge_define_config_item ('sysdebug_ignored', 'core', 'false') ;
140 forge_set_config_item_bool ('sysdebug_ignored', 'core') ;
141 forge_define_config_item ('sysdebug_dbquery', 'core', 'false') ;
142 forge_set_config_item_bool ('sysdebug_dbquery', 'core') ;
143 forge_define_config_item ('sysdebug_xmlstarlet', 'core', 'false') ;
144 forge_set_config_item_bool ('sysdebug_xmlstarlet', 'core') ;
145 forge_define_config_item ('sysdebug_akelos', 'core', 'false') ;
146 forge_set_config_item_bool ('sysdebug_akelos', 'core') ;
147 // Load extra func to add extras func like debug
148 $sysdebug_enable = forge_get_config('sysdebug_enable');
152 * we could use xhtml-rdfa-1.dtd but would need to
153 * mirror the entire XHTML/1.1 shebang then, too
156 'dtdfile' => 'xhtml1-strict.dtd',
157 'doctype' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
159 /* the original XHTML/1.0 Transitional */
160 'transitional-orig' => array(
161 'dtdfile' => 'xhtml1-transitional.dtd',
162 'doctype' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
164 /* XHTML/1.0 Transitional + RDFa 1.0 */
165 'transitional' => array(
166 'dtdfile' => 'xhtml10t-rdfa10.dtd',
167 'doctype' => '<!DOCTYPE html SYSTEM "http://evolvis.org/DTD/xhtml10t-rdfa10.dtd">'
171 $sysXMLNSs = 'xmlns="http://www.w3.org/1999/xhtml"';
172 if (!$sysdebug_enable || !forge_get_config('sysdebug_xmlstarlet')) {
174 'dc' => 'http://purl.org/dc/elements/1.1/',
175 'doap' => 'http://usefulinc.com/ns/doap#',
176 'foaf' => 'http://xmlns.com/foaf/0.1/',
177 'planetforge' => 'http://coclico-project.org/ontology/planetforge#',
178 'sioc' => 'http://rdfs.org/sioc/ns#',
179 ) as $key => $value) {
180 $sysXMLNSs .= ' xmlns:' . $key . '="' . $value . '"';
184 if ($sysdebug_enable && getenv('SERVER_SOFTWARE')) {
185 require $gfcommon.'include/extras-debug.php';
187 $sysdebug_dbquery = false;
189 function sysdebug_off($hdr=false, $replace=true, $resp=false) {
190 if ($hdr !== false) {
191 if ($resp === false) {
192 header($hdr, $replace);
194 header($hdr, $replace, $resp);
200 function sysdebug_lazymode($enable) {
203 function sysdebug_ajaxbody($enable=true) {
208 // Get constants used for flags or status
209 require $gfcommon.'include/constants.php';
212 // Base error library for new objects
213 require_once $gfcommon.'include/Error.class.php';
215 // Database abstraction
216 // From here database is required
217 if (forge_get_config('database_name')!=""){
218 require_once $gfcommon.'include/database-pgsql.php';
220 // Authentication and access control
221 require_once $gfcommon.'include/session.php';
222 require_once $gfcommon.'include/RBACEngine.class.php';
226 require_once $gfcommon.'include/System.class.php';
227 forge_define_config_item('account_manager_type', 'core', 'UNIX') ;
228 require_once $gfcommon.'include/system/'.forge_get_config('account_manager_type').'.class.php';
229 $amt = forge_get_config('account_manager_type') ;
232 // User-related classes and functions
233 require_once $gfcommon.'include/User.class.php';
235 // Project-related classes and functions
236 require_once $gfcommon.'include/Group.class.php';
238 // Permission-related functions
239 require_once $gfcommon.'include/Permission.class.php';
242 require_once $gfcommon.'include/Plugin.class.php' ;
243 require_once $gfcommon.'include/PluginManager.class.php' ;
245 // SCM-specific plugins subsystem
246 require_once $gfcommon.'include/SCMPlugin.class.php' ;
248 // Authentication-specific plugins subsystem
249 require_once $gfcommon.'include/AuthPlugin.class.php' ;
251 if (getenv ('FUSIONFORGE_NO_PLUGINS') != 'true') {
252 setup_plugin_manager () ;
256 if (forge_get_config('use_jabber')) {
257 require_once $gfcommon.'include/Jabber.class.php';
260 ini_set('date.timezone', forge_get_config ('default_timezone'));
262 if (isset($_SERVER['SERVER_SOFTWARE'])) { // We're on the web
263 // Detect upload larger that upload allowed size.
264 if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) &&
265 empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0 )
267 $displayMaxSize = ini_get('post_max_size');
269 switch ( substr($displayMaxSize,-1) )
272 $displayMaxSize = $displayMaxSize * 1024;
274 $displayMaxSize = $displayMaxSize * 1024;
276 $displayMaxSize = $displayMaxSize * 1024;
279 $error_msg = sprintf(_('Posted data is too large. %1$s exceeds the maximum size of %2$s'),
280 human_readable_bytes($_SERVER['CONTENT_LENGTH']), human_readable_bytes($displayMaxSize));
283 // exit_error() and variants (for the web)
284 require_once $gfcommon.'include/exit.php';
286 // Library to determine browser settings
287 require_once $gfwww.'include/browser.php';
289 // HTML layout class, may be overriden by the Theme class
290 require_once $gfwww.'include/Layout.class.php';
292 // Various HTML utilities
293 require_once $gfcommon.'include/utils.php';
295 // Various HTML libs like button bar, themable
296 require_once $gfwww.'include/html.php';
298 // Forms key generation
299 require_once $gfcommon.'include/forms.php';
301 // Determine if there's a web session running
304 plugin_hook('after_session_set');
307 if (!session_loggedin() && forge_get_config ('force_login') == 1 ) {
308 $expl_pathinfo = explode('/',getStringFromServer('REQUEST_URI'));
309 if (getStringFromServer('REQUEST_URI')!='/' && $expl_pathinfo[1]!='account' && $expl_pathinfo[1]!='export' ) exit_not_logged_in();
310 // Show proj* export even if not logged in when force login
311 // If not default web project page would be broken
312 if ($expl_pathinfo[1]=='export' && !preg_match('/^proj/', $expl_pathinfo[2])) exit_not_logged_in();
315 // Insert this page view into the database
316 require_once $gfwww.'include/logger.php';
318 // If logged in, set up a $LUSER var referencing
319 // the logged in user's object
321 if (session_loggedin()) {
322 $LUSER =& session_get_user();
323 $use_tooltips = $LUSER->usesTooltips();
324 putenv ('TZ='. $LUSER->getTimeZone());
325 header ('Cache-Control: private');
326 require_once forge_get_config('themes_root').'/'.$LUSER->setUpTheme().'/Theme.class.php';
329 require_once forge_get_config('themes_root').'/'.forge_get_config('default_theme').'/Theme.class.php';
331 $HTML = new Theme () ;
332 } else { // Script run from cron or a command line
333 require_once $gfcommon.'include/squal_exit.php';
337 require_once $gfcommon.'include/gettext.php';
338 require_once $gfcommon.'include/group_section_texts.php';
340 setup_gettext_from_context();
344 $feedback = htmlspecialchars(getStringFromRequest('feedback', $feedback));
345 $error_msg = htmlspecialchars(getStringFromRequest('error_msg', $error_msg));
346 $warning_msg = htmlspecialchars(getStringFromRequest('warning_msg', $warning_msg));
353 $LUSER - Logged in user object
360 // c-file-style: "bsd"