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 if (!isset($no_gz_buffer) || !$no_gz_buffer) {
49 ob_start("ob_gzhandler");
52 // Database access and other passwords when on the web
53 function setconfigfromoldsources ($sec, $var, $serv, $env, $glob) {
54 if (getenv ('SERVER_SOFTWARE')) {
55 if (function_exists ('apache_request_headers')) {
56 $headers = apache_request_headers() ;
61 if (isset ($headers[$serv])) {
62 forge_define_config_item ($var, $sec,
67 if (isset ($_ENV[$env])) {
68 forge_define_config_item ($var, $sec,
72 if (isset ($GLOBALS[$glob])) {
73 forge_define_config_item ($var, $sec,
79 if (file_exists ($gfcgfile)) {
80 require_once $gfcgfile ;
83 setconfigfromoldsources ('core', 'database_host',
84 'GForgeDbhost', 'sys_gfdbhost', 'sys_dbhost') ;
85 setconfigfromoldsources ('core', 'database_port',
86 'GForgeDbport', 'sys_gfdbport', 'sys_dbport') ;
87 setconfigfromoldsources ('core', 'database_name',
88 'GForgeDbname', 'sys_gfdbname', 'sys_dbname') ;
89 setconfigfromoldsources ('core', 'database_user',
90 'GForgeDbuser', 'sys_gfdbuser', 'sys_dbuser') ;
91 setconfigfromoldsources ('core', 'database_password',
92 'GForgeDbpasswd', 'sys_gfdbpasswd', 'sys_dbpasswd') ;
93 setconfigfromoldsources ('core', 'ldap_password',
94 'GForgeLdapPasswd', 'sys_gfldap_passwd', NULL) ;
95 setconfigfromoldsources ('core', 'jabber_password',
96 'GForgeJabberPasswd', 'sys_gfjabber_pass', NULL) ;
98 forge_define_config_item ('source_path', 'core', $fusionforge_basedir) ;
99 forge_define_config_item ('data_path', 'core', '/var/lib/gforge') ;
100 forge_define_config_item ('chroot', 'core', '$core/data_path/chroot') ;
101 forge_define_config_item ('config_path', 'core', '/etc/gforge') ;
103 require_once $gfcommon.'include/config-vars.php';
105 forge_read_config_file ($gfconfig.'/config.ini') ;
106 forge_read_config_dir ($gfconfig.'/config.ini.d/') ;
107 if (($ecf = forge_get_config ('extra_config_files')) != NULL) {
108 $ecfa = explode (',', $ecf) ;
109 foreach ($ecfa as $cf) {
111 forge_read_config_file ($cf) ;
114 if (($ecd = forge_get_config ('extra_config_dirs')) != NULL) {
115 $ecda = explode (',', $ecd) ;
116 foreach ($ecda as $cd) {
118 forge_read_config_dir ($cd) ;
122 forge_define_config_item ('installation_environment', 'core', 'production') ;
123 $installation_environment = forge_get_config ('installation_environment') ;
124 if ($installation_environment == 'development' || $installation_environment == 'integration')
125 $default_sysdebug_enable = 'true';
127 $default_sysdebug_enable = 'false';
128 forge_define_config_item ('sysdebug_enable', 'core', $default_sysdebug_enable) ;
129 forge_set_config_item_bool ('sysdebug_enable', 'core') ;
130 forge_define_config_item ('sysdebug_phphandler', 'core', 'true') ;
131 forge_set_config_item_bool ('sysdebug_phphandler', 'core') ;
132 forge_define_config_item ('sysdebug_backtraces', 'core', 'false') ;
133 forge_set_config_item_bool ('sysdebug_backtraces', 'core') ;
134 forge_define_config_item ('sysdebug_ignored', 'core', 'false') ;
135 forge_set_config_item_bool ('sysdebug_ignored', 'core') ;
136 forge_define_config_item ('sysdebug_dbquery', 'core', 'false') ;
137 forge_set_config_item_bool ('sysdebug_dbquery', 'core') ;
138 forge_define_config_item ('sysdebug_xmlstarlet', 'core', 'false') ;
139 forge_set_config_item_bool ('sysdebug_xmlstarlet', 'core') ;
140 forge_define_config_item ('sysdebug_akelos', 'core', 'false') ;
141 forge_set_config_item_bool ('sysdebug_akelos', 'core') ;
142 // Load extra func to add extras func like debug
143 $sysdebug_enable = forge_get_config('sysdebug_enable');
147 * we could use xhtml-rdfa-1.dtd but would need to
148 * mirror the entire XHTML/1.1 shebang then, too
151 'dtdfile' => 'xhtml1-strict.dtd',
152 'doctype' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
154 /* the original XHTML/1.0 Transitional */
155 'transitional-orig' => array(
156 'dtdfile' => 'xhtml1-transitional.dtd',
157 'doctype' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
159 /* XHTML/1.0 Transitional + RDFa 1.0 */
160 'transitional' => array(
161 'dtdfile' => 'xhtml10t-rdfa10.dtd',
162 'doctype' => '<!DOCTYPE html SYSTEM "http://evolvis.org/DTD/xhtml10t-rdfa10.dtd">'
166 $sysXMLNSs = 'xmlns="http://www.w3.org/1999/xhtml"';
167 if (!$sysdebug_enable || !forge_get_config('sysdebug_xmlstarlet')) {
169 'dc' => 'http://purl.org/dc/elements/1.1/',
170 'doap' => 'http://usefulinc.com/ns/doap#',
171 'foaf' => 'http://xmlns.com/foaf/0.1/',
172 'planetforge' => 'http://coclico-project.org/ontology/planetforge#',
173 'sioc' => 'http://rdfs.org/sioc/ns#',
174 ) as $key => $value) {
175 $sysXMLNSs .= ' xmlns:' . $key . '="' . $value . '"';
179 if ($sysdebug_enable && getenv('SERVER_SOFTWARE')) {
180 require $gfcommon.'include/extras-debug.php';
182 $sysdebug_dbquery = false;
184 function sysdebug_off($hdr=false, $replace=true, $resp=false) {
185 if ($hdr !== false) {
186 if ($resp === false) {
187 header($hdr, $replace);
189 header($hdr, $replace, $resp);
195 function sysdebug_lazymode($enable) {
198 function sysdebug_ajaxbody($enable=true) {
203 // Get constants used for flags or status
204 require $gfcommon.'include/constants.php';
207 // Base error library for new objects
208 require_once $gfcommon.'include/Error.class.php';
210 // Database abstraction
211 // From here database is required
212 if (forge_get_config('database_name')!=""){
213 require_once $gfcommon.'include/database-pgsql.php';
215 // Authentication and access control
216 require_once $gfcommon.'include/session.php';
217 require_once $gfcommon.'include/RBACEngine.class.php';
221 require_once $gfcommon.'include/System.class.php';
222 forge_define_config_item('account_manager_type', 'core', 'UNIX') ;
223 require_once $gfcommon.'include/system/'.forge_get_config('account_manager_type').'.class.php';
224 $amt = forge_get_config('account_manager_type') ;
227 // User-related classes and functions
228 require_once $gfcommon.'include/User.class.php';
230 // Project-related classes and functions
231 require_once $gfcommon.'include/Group.class.php';
233 // Permission-related functions
234 require_once $gfcommon.'include/Permission.class.php';
237 require_once $gfcommon.'include/Plugin.class.php' ;
238 require_once $gfcommon.'include/PluginManager.class.php' ;
240 // SCM-specific plugins subsystem
241 require_once $gfcommon.'include/SCMPlugin.class.php' ;
243 // Authentication-specific plugins subsystem
244 require_once $gfcommon.'include/AuthPlugin.class.php' ;
246 if (getenv ('FUSIONFORGE_NO_PLUGINS') != 'true') {
247 setup_plugin_manager () ;
251 if (forge_get_config('use_jabber')) {
252 require_once $gfcommon.'include/Jabber.class.php';
255 ini_set('date.timezone', forge_get_config ('default_timezone'));
257 if (isset($_SERVER['SERVER_SOFTWARE'])) { // We're on the web
258 // Detect upload larger that upload allowed size.
259 if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) &&
260 empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0 )
262 $displayMaxSize = ini_get('post_max_size');
264 switch ( substr($displayMaxSize,-1) )
267 $displayMaxSize = $displayMaxSize * 1024;
269 $displayMaxSize = $displayMaxSize * 1024;
271 $displayMaxSize = $displayMaxSize * 1024;
274 $error_msg = sprintf(_('Posted data is too large. %1$s exceeds the maximum size of %2$s'),
275 human_readable_bytes($_SERVER['CONTENT_LENGTH']), human_readable_bytes($displayMaxSize));
278 // exit_error() and variants (for the web)
279 require_once $gfcommon.'include/exit.php';
281 // Library to determine browser settings
282 require_once $gfwww.'include/browser.php';
284 // HTML layout class, may be overriden by the Theme class
285 require_once $gfwww.'include/Layout.class.php';
287 // Various HTML utilities
288 require_once $gfcommon.'include/utils.php';
290 // Various HTML libs like button bar, themable
291 require_once $gfwww.'include/html.php';
293 // Forms key generation
294 require_once $gfcommon.'include/forms.php';
296 // Determine if there's a web session running
299 plugin_hook('after_session_set');
302 if (!session_loggedin() && forge_get_config ('force_login') == 1 ) {
303 $expl_pathinfo = explode('/',getStringFromServer('REQUEST_URI'));
304 if (getStringFromServer('REQUEST_URI')!='/' && $expl_pathinfo[1]!='account' && $expl_pathinfo[1]!='export' ) exit_not_logged_in();
305 // Show proj* export even if not logged in when force login
306 // If not default web project page would be broken
307 if ($expl_pathinfo[1]=='export' && !preg_match('/^proj/', $expl_pathinfo[2])) exit_not_logged_in();
310 // Insert this page view into the database
311 require_once $gfwww.'include/logger.php';
313 // If logged in, set up a $LUSER var referencing
314 // the logged in user's object
316 if (session_loggedin()) {
317 $LUSER =& session_get_user();
318 $use_tooltips = $LUSER->usesTooltips();
319 putenv ('TZ='. $LUSER->getTimeZone());
320 header ('Cache-Control: private');
321 require_once forge_get_config('themes_root').'/'.$LUSER->setUpTheme().'/Theme.class.php';
324 require_once forge_get_config('themes_root').'/'.forge_get_config('default_theme').'/Theme.class.php';
326 $HTML = new Theme () ;
327 } else { // Script run from cron or a command line
328 require_once $gfcommon.'include/squal_exit.php';
332 require_once $gfcommon.'include/gettext.php';
333 require_once $gfcommon.'include/group_section_texts.php';
335 setup_gettext_from_context();
339 $feedback = htmlspecialchars(getStringFromRequest('feedback', $feedback));
340 $error_msg = htmlspecialchars(getStringFromRequest('error_msg', $error_msg));
341 $warning_msg = htmlspecialchars(getStringFromRequest('warning_msg', $warning_msg));
348 $LUSER - Logged in user object
355 // c-file-style: "bsd"