00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: pre.php 5319 2006-02-05 19:10:37Z yeupou $
00006 #
00007 # Copyright 1999-2000 (c) The SourceForge Crew
00008 # Copyright 2000-2003 (c) Free Software Foundation
00009 #
00010 # Copyright 2002-2005 (c) Mathieu Roy <yeupou--gna.org>
00011 #
00012 # The Savane project is free software; you can redistribute it and/or
00013 # modify it under the terms of the GNU General Public License
00014 # as published by the Free Software Foundation; either version 2
00015 # of the License, or (at your option) any later version.
00016 #
00017 # The Savane project is distributed in the hope that it will be useful,
00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 # GNU General Public License for more details.
00021 #
00022 # You should have received a copy of the GNU General Public License
00023 # along with the Savane project; if not, write to the Free Software
00024 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00025
00026 # Defines all of the Savane hosts, databases, etc.
00027 # This needs to be loaded first because the lines below depend upon it.
00028 if (getenv('SAVANE_CONF'))
00029 { require getenv('SAVANE_CONF').'/savannah.conf.php'; }
00030 elseif (getenv('SV_LOCAL_INC_PREFIX'))
00031 { require getenv('SV_LOCAL_INC_PREFIX').'/savannah.conf.php'; }
00032 else
00033 {
00034 # go back to default location
00035 require '/etc/savannah/savannah.conf.php';
00036 }
00037
00038 if ($GLOBALS['sys_url_topdir'] != '/')
00039 {
00040 $sys_home = $GLOBALS['sys_url_topdir'].'/';
00041 }
00042 else
00043 {
00044 $sys_home = $GLOBALS['sys_url_topdir'];
00045 }
00046
00047 # Defines the https url, if available -- no path is added since this
00048 # variable can be used with REQUEST_URI added.
00049 if (isset($GLOBALS['sys_https_host']))
00050 {
00051 $sys_https_url = 'https:
00052 }
00053 else
00054 {
00055 $sys_https_url = 'http:
00056 }
00057
00058
00059
00060 # require_directory
00061 # sources (requires) all specific include files of a module from
00062 # the include area (all include files of a module are arranged
00063 # in subdirectories in the includes area, so this routine sources
00064 # just all of the *.php files found in the module's subdirectory).
00065
00066 # Prevent declaration by users.
00067 if ($_GET['module'] ||
00068 $_POST['module'] ||
00069 $_COOKIE['module'] ||
00070 $_SERVER['module'] ||
00071 $_ENV['module'] ||
00072 $_FILES['module'] ||
00073 $_REQUEST['module'])
00074 { exit(); }
00075
00076 function require_directory ($module)
00077 {
00078 if ($module=="")
00079 { return; }
00080 if ($GLOBALS['directory_'.$module.'_is_loaded'])
00081 { return; }
00082
00083 $dir = $GLOBALS['sys_www_topdir'].'/include/'.$module;
00084 if (is_dir($dir))
00085 {
00086 $odir = opendir($dir);
00087 while ($file = readdir($odir))
00088 {
00089 if (eregi(".*\.(php)$", $file))
00090 {
00091 require $dir."/".$file;
00092 }
00093 }
00094 closedir($odir);
00095 }
00096
00097 $GLOBALS['directory_'.$module.'_is_loaded'] = 1;
00098 }
00099
00100 function get_module_include_dir ($phpself, $true_artifact=0, $true_dir=0)
00101 {
00102 $guess = basename(dirname($phpself));
00103
00104 if (!$true_dir && $guess == "admin")
00105 {
00106 # Need to go deeper
00107 $guess = basename(dirname(dirname($phpself)));
00108 }
00109
00110 if (!$true_artifact) {
00111 # we have some special cases:
00112 # - bugs, patch, task go in trackers
00113 # - news and forum go in news
00114 if (($guess == 'bugs') ||
00115 ($guess == 'patch') ||
00116 ($guess == 'task') ||
00117 ($guess == 'cookbook') ||
00118 ($guess == 'support'))
00119 {
00120 $guess = 'trackers';
00121 }
00122 else if ($guess == 'forum')
00123 {
00124 $guess = 'news';
00125 }
00126 }
00127
00128 return $guess;
00129 }
00130
00131
00132
00133
00134
00135 # sanitize user input, focusing register globals set to off
00136 require $GLOBALS['sys_www_topdir'].'/include/sane.php';
00137
00138 # version info
00139 require $GLOBALS['sys_www_topdir'].'/include/version.php';
00140
00141 # i18n setup
00142 require $GLOBALS['sys_www_topdir'].'/include/i18n.php';
00143
00144 # base error library for new objects
00145 require $GLOBALS['sys_www_topdir'].'/include/Error.class';
00146
00147 # database abstraction
00148 require $GLOBALS['sys_www_topdir'].'/include/database.php';
00149
00150 # user functions like get_name, logged_in, etc
00151 require $GLOBALS['sys_www_topdir'].'/include/user.php';
00152
00153 # various html utilities
00154 require $GLOBALS['sys_www_topdir'].'/include/utils.php';
00155
00156 # security library
00157 require $GLOBALS['sys_www_topdir'].'/include/session.php';
00158
00159 # theme - color scheme informations
00160 require $GLOBALS['sys_www_topdir'].'/include/theme.php';
00161
00162 # title, helper to find out appropriate info depending on the context,
00163 # like title
00164 require $GLOBALS['sys_www_topdir'].'/include/context.php';
00165
00166 # HTML layout class, may be overriden by the Theme class
00167 require $GLOBALS['sys_www_topdir'].'/include/Layout.class';
00168
00169 $HTML = new Layout();
00170
00171 # group functions like get_name, etc
00172 require $GLOBALS['sys_www_topdir'].'/include/Group.class';
00173
00174 # member functions like member_add, member_approve, etc
00175 require $GLOBALS['sys_www_topdir'].'/include/member.php';
00176
00177 # exit_error library
00178 require $GLOBALS['sys_www_topdir'].'/include/exit.php';
00179
00180 # send mail library
00181 require $GLOBALS['sys_www_topdir'].'/include/sendmail.php';
00182
00183 # various html libs like button bar, themable
00184 require $GLOBALS['sys_www_topdir'].'/include/html.php';
00185
00186 # graphics library
00187 require $GLOBALS['sys_www_topdir'].'/include/graphs.php';
00188
00189 # calendar library
00190 require $GLOBALS['sys_www_topdir'].'/include/calendar.php';
00191
00192 # forms library
00193 require $GLOBALS['sys_www_topdir'].'/include/form.php';
00194
00195 # search tools, frequently needed
00196 require_directory('search');
00197
00198 # left-hand nav library, themable
00199 require $GLOBALS['sys_www_topdir'].'/include/menu.php';
00200
00201
00202
00203
00204
00205
00206
00207 header("Content-Type: text/html; charset=utf-8");
00208
00209
00210
00211
00212
00213
00214 # Connect to db
00215 db_connect();
00216
00217 # sys_unix_group_name is maybe defined
00218 # in this case, we want sys_group_id
00219 if (isset($GLOBALS['sys_unix_group_name']))
00220 {
00221 $search_group = $GLOBALS['sys_unix_group_name'];
00222 $res_grp = db_query("SELECT group_id FROM groups WHERE unix_group_name='$search_group'");
00223 $sys_group_id = db_result($res_grp,0,'group_id');
00224 }
00225
00226
00227 # determine if they're logged in
00228 session_set();
00229
00230 # set up the user's timezone if logged in
00231 # redirect them from http to https if asked in their session table
00232 if (user_isloggedin())
00233 {
00234 putenv('TZ='.user_get_timezone());
00235
00236 if (!session_issecure() && session_needsstayinssl())
00237 {
00238 if ($GLOBALS['sys_https_host'] )
00239 {
00240 header('Location: https:
00241 }
00242 }
00243 }
00244
00245
00246
00247
00248
00249
00250
00251 # defines the artifact we are using
00252 define("ARTIFACT", get_module_include_dir($GLOBALS['REQUEST_URI'], 1));
00253
00254 # if we are on an artifact index page and we have only one argument which is
00255 # a numeric number, we suppose it is an item_id
00256 # Maybe it was a link shortcut like
00257 # blabla.org/task/?nnnn (blabla.org/task/?#nnnn cannot work because # is
00258 # ignored by PHP as tag for html anchors)
00259 if ((ARTIFACT == "bugs" ||
00260 ARTIFACT == "task" ||
00261 ARTIFACT == "support" ||
00262 ARTIFACT == "patch" ||
00263 ARTIFACT == "cookbook") &&
00264 is_numeric($_SERVER["argv"][0]))
00265 {
00266 $item_id = $_SERVER["argv"][0];
00267 $func = "detailitem";
00268 }
00269
00270
00271 # if we got an item_id and no group_id we need to get the appropriate
00272 # group_id
00273 if (!isset($group_id) && !isset($group_name) && isset($item_id))
00274 {
00275 $result = db_query("SELECT group_id FROM ".ARTIFACT." WHERE bug_id='$item_id'");
00276 if (db_numrows($result))
00277 { $group_id = db_result(($result),0,'group_id'); }
00278 else
00279 {
00280 exit_error(_("Item not found"));
00281 }
00282
00283 # Special case: if it the item is from the system group and we are on the
00284 # cookbook, we may want to pretend that an item belong a given group while
00285 # it actually belongs to the system group.
00286 if (ARTIFACT == 'cookbook' &&
00287 $group_id == $sys_group_id &&
00288 sane_get("comingfrom"))
00289 {
00290 $group_id = sane_get("comingfrom");
00291 }
00292
00293 }
00294
00295 # if we got a forum_id and no group_id, we need to get the appropriate
00296 # group_id
00297 # (FIXME: in the future it could follow the naming scheme of trackers)
00298 if (!isset($group_id) && !isset($group_name) && isset($forum_id))
00299 {
00300 $result = db_query("SELECT group_id FROM forum_group_list WHERE group_forum_id='$forum_id'");
00301 if ($result)
00302 { $group_id = db_result(($result),0,'group_id'); }
00303 }
00304
00305 # if we got a msg_id and no group_id, we need to get the appropriate
00306 # group_id
00307 # (FIXME: in the future it could follow the naming scheme of trackers)
00308 if (!isset($group_id) && !isset($group_name) && isset($msg_id))
00309 {
00310 $result = db_query("SELECT forum_group_list.group_id,forum_group_list.forum_name,forum.group_forum_id,forum.thread_id FROM forum_group_list,forum WHERE forum_group_list.group_forum_id=forum.group_forum_id AND forum.msg_id='$msg_id'");
00311 if ($result)
00312 { $group_id = db_result(($result),0,'group_id'); }
00313 }
00314
00315
00316 # defines group_id if group is set
00317 # defines group_name if group_id is set
00318 unset($res_grp);
00319 if (isset($group) && !isset($group_id))
00320 {
00321 $res_grp = db_query("SELECT group_id,status FROM groups WHERE unix_group_name='$group'");
00322 $group_id = db_result($res_grp,0,'group_id');
00323 $group_name = $group;
00324 }
00325 elseif (isset($group_id))
00326 {
00327 $res_grp = db_query("SELECT unix_group_name,status FROM groups WHERE group_id='$group_id'");
00328 $group_name = db_result($res_grp,0,'unix_group_name');
00329 }
00330
00331 # If group_id is defined, we are on a project page, we have several checks
00332 # to make
00333 if (isset($group_id))
00334 {
00335 if (!$res_grp)
00336 {
00337 $res_grp = db_query("SELECT unix_group_name,status FROM groups WHERE group_id='$group_id'");
00338 }
00339 # Check if the group truly exists
00340 if (!db_numrows($res_grp))
00341 {
00342 exit_error(_("Project not found"));
00343 }
00344
00345 # Ignore status of the project if being registered
00346 if (db_result($res_grp,0,'status') != 'I')
00347 {
00348 # Check if the project is active
00349 if (db_result($res_grp,0,'status') != 'A')
00350 {
00351 # No active but in Maintenance mode, it is ok for super user
00352 if (db_result($res_grp,0,'status') == 'M' && !user_is_super_user())
00353 {
00354 exit_error(_("This project is in maintenance mode"));
00355 }
00356 elseif (db_result($res_grp,0,'status') == 'M' && user_is_super_user())
00357 {
00358 fb(_("Note: this project is in maintenance mode"));
00359 }
00360 elseif (!user_is_super_user())
00361 {
00362 # Other cases, no access granted
00363 exit_error(_("This project is not in active state"));
00364 }
00365 }
00366 }
00367
00368 # check if we are on the correct page
00369 # (you can avoid it with $no_redirection=1)
00370 # if getTypeBaseHost() = "", we use the default host
00371 if (isset($group_id) && !$no_redirection)
00372 {
00373 $project = project_get_object($group_id);
00374 if (strcasecmp($HTTP_HOST, $project->getTypeBaseHost()) != 0 && $project->getTypeBaseHost())
00375 {
00376 header ('Location: http'.(session_issecure()?'s':'').':
00377 exit;
00378 }
00379 }
00380 }
00381
00382 # If requires/include for an artifact exists, load them all
00383 # In any case, set the ARTIFACT constant.
00384 require_directory(get_module_include_dir($GLOBALS['PHP_SELF']));
00385
00386 # Set the CONTEXT and SUBCONTEXT constants, useful to guess page titles
00387 # but also to find out if cookbook entries are relevant
00388 context_guess();
00389 # Set the AUDIENCE constant
00390 user_guess();
00391
00392 ?>