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 require_once $gfcommon.'include/escapingUtils.php';
25 require_once $gfcommon.'include/config.php';
27 if (isset($_SERVER) && array_key_exists('PHP_SELF', $_SERVER) && $_SERVER['PHP_SELF']) {
28 $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
31 if (isset($GLOBALS) && array_key_exists('PHP_SELF', $GLOBALS) && $GLOBALS['PHP_SELF']) {
32 $GLOBALS['PHP_SELF'] = htmlspecialchars($GLOBALS['PHP_SELF']);
35 // Block link prefetching (Moz prefetching, Google Web Accelerator, others)
36 // http://www.google.com/webmasters/faq.html#prefetchblock
37 if (getStringFromServer('HTTP_X_moz') === 'prefetch'){
38 header(getStringFromServer('SERVER_PROTOCOL') . ' 404 Prefetch Forbidden');
39 trigger_error('Prefetch request forbidden.');
43 if (!isset($no_gz_buffer) || !$no_gz_buffer) {
44 ob_start("ob_gzhandler");
47 // Database access and other passwords when on the web
48 function setconfigfromoldsources ($sec, $var, $serv, $env, $glob) {
49 if (getenv ('SERVER_SOFTWARE')) {
50 if (function_exists ('apache_request_headers')) {
51 $headers = apache_request_headers() ;
56 if (isset ($headers[$serv])) {
57 forge_define_config_item ($var, $sec,
62 if (isset ($_ENV[$env])) {
63 forge_define_config_item ($var, $sec,
67 if (isset ($GLOBALS[$glob])) {
68 forge_define_config_item ($var, $sec,
74 if (file_exists ($gfcgfile)) {
75 require_once $gfcgfile ;
78 setconfigfromoldsources ('core', 'database_host',
79 'GForgeDbhost', 'sys_gfdbhost', 'sys_dbhost') ;
80 setconfigfromoldsources ('core', 'database_port',
81 'GForgeDbport', 'sys_gfdbport', 'sys_dbport') ;
82 setconfigfromoldsources ('core', 'database_name',
83 'GForgeDbname', 'sys_gfdbname', 'sys_dbname') ;
84 setconfigfromoldsources ('core', 'database_user',
85 'GForgeDbuser', 'sys_gfdbuser', 'sys_dbuser') ;
86 setconfigfromoldsources ('core', 'database_password',
87 'GForgeDbpasswd', 'sys_gfdbpasswd', 'sys_dbpasswd') ;
88 setconfigfromoldsources ('core', 'ldap_password',
89 'GForgeLdapPasswd', 'sys_gfldap_passwd', NULL) ;
90 setconfigfromoldsources ('core', 'jabber_password',
91 'GForgeJabberPasswd', 'sys_gfjabber_pass', NULL) ;
93 forge_define_config_item ('source_path', 'core', $fusionforge_basedir) ;
94 forge_define_config_item ('data_path', 'core', '/var/lib/gforge') ;
95 forge_define_config_item ('chroot', 'core', '$core/data_path/chroot') ;
96 forge_define_config_item ('config_path', 'core', '/etc/gforge') ;
98 require_once $gfcommon.'include/config-vars.php';
100 forge_read_config_file ($gfconfig.'/config.ini') ;
101 forge_read_config_dir ($gfconfig.'/config.ini.d/') ;
102 if (($ecf = forge_get_config ('extra_config_files')) != NULL) {
103 $ecfa = explode (',', $ecf) ;
104 foreach ($ecfa as $cf) {
106 forge_read_config_file ($cf) ;
109 if (($ecd = forge_get_config ('extra_config_dirs')) != NULL) {
110 $ecda = explode (',', $ecd) ;
111 foreach ($ecda as $cd) {
113 forge_read_config_dir ($cd) ;
117 forge_define_config_item ('installation_environment', 'core', 'production') ;
118 $installation_environment = forge_get_config ('installation_environment') ;
119 if ($installation_environment == 'development' || $installation_environment == 'integration')
120 $default_sysdebug_enable = 'true';
122 $default_sysdebug_enable = 'false';
123 forge_define_config_item ('sysdebug_enable', 'core', $default_sysdebug_enable) ;
124 forge_set_config_item_bool ('sysdebug_enable', 'core') ;
125 forge_define_config_item ('sysdebug_phphandler', 'core', 'true') ;
126 forge_set_config_item_bool ('sysdebug_phphandler', 'core') ;
127 forge_define_config_item ('sysdebug_backtraces', 'core', 'false') ;
128 forge_set_config_item_bool ('sysdebug_backtraces', 'core') ;
129 forge_define_config_item ('sysdebug_ignored', 'core', 'false') ;
130 forge_set_config_item_bool ('sysdebug_ignored', 'core') ;
131 forge_define_config_item ('sysdebug_xmlstarlet', 'core', 'false') ;
132 forge_set_config_item_bool ('sysdebug_xmlstarlet', 'core') ;
133 forge_define_config_item ('sysdebug_akelos', 'core', 'false') ;
134 forge_set_config_item_bool ('sysdebug_akelos', 'core') ;
135 // Load extra func to add extras func like debug
136 $sysdebug_enable = forge_get_config('sysdebug_enable');
137 if ($sysdebug_enable) {
138 require $gfcommon.'include/extras-debug.php';
141 // Get constants used for flags or status
142 require $gfcommon.'include/constants.php';
144 // Declare and init variables to store messages
149 // Base error library for new objects
150 require_once $gfcommon.'include/Error.class.php';
152 // Database abstraction
153 require_once $gfcommon.'include/database-pgsql.php';
155 // Authentication and access control
156 require_once $gfcommon.'include/session.php';
157 require_once $gfcommon.'include/RBACEngine.class.php';
161 require_once $gfcommon.'include/System.class.php';
162 forge_define_config_item('account_manager_type', 'core', 'UNIX') ;
163 require_once $gfcommon.'include/system/'.forge_get_config('account_manager_type').'.class.php';
164 $amt = forge_get_config('account_manager_type') ;
167 // User-related classes and functions
168 require_once $gfcommon.'include/User.class.php';
170 // Project-related classes and functions
171 require_once $gfcommon.'include/Group.class.php';
173 // Permission-related functions
174 require_once $gfcommon.'include/Permission.class.php';
177 require_once $gfcommon.'include/Plugin.class.php' ;
178 require_once $gfcommon.'include/PluginManager.class.php' ;
180 // SCM-specific plugins subsystem
181 require_once $gfcommon.'include/SCMPlugin.class.php' ;
183 setup_plugin_manager () ;
186 if (forge_get_config('use_jabber')) {
187 require_once $gfcommon.'include/Jabber.class.php';
190 ini_set('date.timezone', forge_get_config ('default_timezone'));
192 if (isset($_SERVER['SERVER_SOFTWARE'])) { // We're on the web
193 // exit_error() and variants (for the web)
194 require_once $gfcommon.'include/exit.php';
196 // Library to determine browser settings
197 require_once $gfwww.'include/browser.php';
199 // HTML layout class, may be overriden by the Theme class
200 require_once $gfwww.'include/Layout.class.php';
202 // Various HTML utilities
203 require_once $gfcommon.'include/utils.php';
205 // Various HTML libs like button bar, themable
206 require_once $gfwww.'include/html.php';
208 // Forms key generation
209 require_once $gfcommon.'include/forms.php';
211 // Determine if there's a web session running
214 plugin_hook('after_session_set');
217 if (!session_loggedin() && forge_get_config ('force_login') == 1 ) {
218 $expl_pathinfo = explode('/',getStringFromServer('REQUEST_URI'));
219 if (getStringFromServer('REQUEST_URI')!='/' && $expl_pathinfo[1]!='account' && $expl_pathinfo[1]!='export' ) exit_not_logged_in();
220 // Show proj* export even if not logged in when force login
221 // If not default web project page would be broken
222 if ($expl_pathinfo[1]=='export' && !ereg("^proj", $expl_pathinfo[2])) exit_not_logged_in();
225 // Insert this page view into the database
226 require_once $gfwww.'include/logger.php';
228 // If logged in, set up a $LUSER var referencing
229 // the logged in user's object
231 if (session_loggedin()) {
232 $LUSER =& session_get_user();
233 $LUSER->setUpTheme();
234 putenv ('TZ='. $LUSER->getTimeZone());
235 header ('Cache-Control: private');
236 require_once forge_get_config('themes_root').'/'.$LUSER->setUpTheme().'/Theme.class.php';
238 require_once forge_get_config('themes_root').'/'.forge_get_config('default_theme').'/Theme.class.php';
240 $HTML = new Theme () ;
241 } else { // Script run from cron or a command line
242 require_once $gfcommon.'include/squal_exit.php';
246 require_once $gfcommon.'include/gettext.php';
247 require_once $gfcommon.'include/group_section_texts.php';
249 setup_gettext_from_context();
256 $LUSER - Logged in user object
263 // c-file-style: "bsd"