4 * FusionForge ViewCVS PHP wrapper.
6 * Portion of this file is inspired from the ViewCVS wrapper
8 * Copyright (c) Xerox Corporation, CodeX / CodeX Team, 2001,2002. All Rights Reserved.
9 * http://codex.xerox.com
11 * Copyright 2010 (c), Franck Villaume
12 * http://fusionforge.org
14 * This file is part of FusionForge.
16 * FusionForge is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * FusionForge is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with FusionForge; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 // make sure we're not compressing output if we are making a tarball
32 if (isset($_GET['view']) && $_GET['view'] == 'tar') {
36 require_once('../env.inc.php');
37 require_once $gfcommon.'include/pre.php';
38 require_once $gfwww.'scm/include/scm_utils.php';
39 require_once $gfwww.'scm/include/viewvc_utils.php';
41 if (!forge_get_config('use_scm')) {
42 exit_disabled('home');
45 // Get the project name from query
46 if(getStringFromGet('root') && strpos(getStringFromGet('root'), ';') === false) {
47 $projectName = getStringFromGet('root');
49 $queryString = getStringFromServer('QUERY_STRING');
50 if(preg_match_all('/[;]?([^\?;=]+)=([^;]+)/', $queryString, $matches, PREG_SET_ORDER)) {
51 for($i = 0, $size = sizeof($matches); $i < $size; $i++) {
52 $query[$matches[$i][1]] = urldecode($matches[$i][2]);
54 $projectName = $query['root'];
57 // Remove eventual leading /root/ or root/
58 $projectName = ereg_replace('^..[^/]*/','', $projectName);
64 $Group =& group_get_object_by_name($projectName);
65 if (!$Group || !is_object($Group)) {
67 } else if ( $Group->isError()) {
68 exit_error($Group->getErrorMessage(),'home');
70 if (!$Group->usesSCM()) {
71 exit_disabled('home');
74 // check if the scm_box is located in another server
75 $scm_box = $Group->getSCMBox();
76 //$external_scm = (gethostbyname(forge_get_config('web_host')) != gethostbyname($scm_box));
77 $external_scm = !$sys_scm_single_host;
79 if (!forge_check_perm ('scm', $group->getID(), 'read')) {
80 exit_permission_denied('home');
84 //$server_script = "/cgi-bin/viewcvs.cgi";
85 $server_script = $GLOBALS["sys_path_to_scmweb"]."/viewcvs.cgi";
86 // remove leading / (if any)
87 $server_script = preg_replace("/^\\//", "", $server_script);
89 // pass the parameters passed to this script to the remote script in the same fashion
90 $script_url = "http://".$scm_box."/".$server_script.$_SERVER["PATH_INFO"]."?".$_SERVER["QUERY_STRING"];
91 $fh = @fopen($script_url, "r");
93 exit_error(sprintf(_('Could not open script %s.'),$script_url),'home');
96 // start reading the output of the script (in 8k chunks)
99 $content .= fread($fh, 8192);
102 if (viewcvs_is_html()) {
103 // Now, we must replace the occurencies of $server_script with this script
104 // (do this only of outputting HTML)
105 // We must do this because we can't pass the environment variable SCRIPT_NAME
106 // to the cvsweb script (maybe this can be fixed in the future?)
107 $content = str_replace("/".$server_script, $_SERVER["SCRIPT_NAME"], $content);
110 $unix_name = $Group->getUnixName();
112 // Call to ViewCVS CGI locally (see viewcvs_utils.php)
114 // see what type of plugin this project if using
115 if ($Group->usesPlugin('scmcvs')) {
117 } else if ($Group->usesPlugin('scmsvn')) {
121 $content = viewcvs_execute($unix_name, $repos_type);
124 // Set content type header from the value set by ViewCVS
125 // No other headers are generated by ViewCVS because in generate_etags
126 // is set to 0 in the ViewCVS config file
128 $line = strtok($content,SEPARATOR);
129 while ($line && !$found) {
130 if (preg_match('/^Content-Type:(.*)$/',$line,$matches)) {
131 header('Content-Type:' . $matches[1]);
134 $line = strtok(SEPARATOR);
136 $content = substr($content, strpos($content,$line));
138 if (viewcvs_is_html()) {
139 // If we output html and we found the mbstring extension, we
140 // should try to encode the output of ViewCVS in UTF-8
141 if (extension_loaded('mbstring')) {
142 $encoding = mb_detect_encoding($content, 'UTF-8, ISO-8859-1');
143 if($encoding != 'UTF-8') {
144 $content = mb_convert_encoding($content, 'UTF-8', $encoding);
149 // TODO does not seem to work when allow_tar = 1 in ViewCVS conf
150 // (allow to generate on the fly a tar.gz): the generated file
151 // seems to be corrupted
157 // c-file-style: "bsd"