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 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
10 * http://codex.xerox.com
12 * Copyright 2010, Franck Villaume - Capgemini
13 * Copyright 2012, Franck Villaume - TrivialDev
14 * http://fusionforge.org
16 * This file is part of FusionForge. FusionForge is free software;
17 * you can redistribute it and/or modify it under the terms of the
18 * GNU General Public License as published by the Free Software
19 * Foundation; either version 2 of the Licence, or (at your option)
22 * FusionForge is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
29 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 // make sure we're not compressing output if we are making a tarball
33 if (isset($_GET['view']) && $_GET['view'] == 'tar') {
37 require_once('../env.inc.php');
38 require_once $gfcommon.'include/pre.php';
39 require_once $gfwww.'scm/include/scm_utils.php';
40 require_once $gfwww.'scm/include/viewvc_utils.php';
42 if (!forge_get_config('use_scm')) {
46 // Get the project name from query
48 if(getStringFromGet('root') && strpos(getStringFromGet('root'), ';') === false) {
49 $projectName = getStringFromGet('root');
51 $queryString = getStringFromServer('QUERY_STRING');
52 if(preg_match_all('/[;]?([^\?;=]+)=([^;]+)/', $queryString, $matches, PREG_SET_ORDER)) {
53 for($i = 0, $size = sizeof($matches); $i < $size; $i++) {
54 $query[$matches[$i][1]] = urldecode($matches[$i][2]);
56 $projectName = $query['root'];
59 // Remove eventual leading /root/ or root/
60 $projectName = preg_replace('%^..[^/]*/%','', $projectName);
66 $Group = group_get_object_by_name($projectName);
67 if (!$Group || !is_object($Group)) {
69 } else if ( $Group->isError()) {
70 exit_error($Group->getErrorMessage(),'summary');
72 if (!$Group->usesSCM()) {
76 // check if the scm_box is located in another server
77 $scm_box = $Group->getSCMBox();
78 //$external_scm = (gethostbyname(forge_get_config('web_host')) != gethostbyname($scm_box));
79 $external_scm = !forge_get_config('scm_single_host');
81 if (!forge_check_perm('scm', $Group->getID(), 'read')) {
82 exit_permission_denied('scm');
86 //$server_script = "/cgi-bin/viewcvs.cgi";
87 $server_script = $GLOBALS["sys_path_to_scmweb"]."/viewcvs.cgi";
88 // remove leading / (if any)
89 $server_script = preg_replace("/^\\//", "", $server_script);
91 // pass the parameters passed to this script to the remote script in the same fashion
92 $script_url = "http://".$scm_box."/".$server_script.$_SERVER["PATH_INFO"]."?".$_SERVER["QUERY_STRING"];
93 $fh = @fopen($script_url, "r");
95 exit_error(sprintf(_('Could not open script %s.'),$script_url),'home');
98 // start reading the output of the script (in 8k chunks)
101 $content .= fread($fh, 8192);
104 if (viewcvs_is_html()) {
105 // Now, we must replace the occurencies of $server_script with this script
106 // (do this only of outputting HTML)
107 // We must do this because we can't pass the environment variable SCRIPT_NAME
108 // to the cvsweb script (maybe this can be fixed in the future?)
109 $content = str_replace("/".$server_script, $_SERVER["SCRIPT_NAME"], $content);
112 $unix_name = $Group->getUnixName();
114 // Call to ViewCVS CGI locally (see viewcvs_utils.php)
116 // see what type of plugin this project if using
117 if ($Group->usesPlugin('scmcvs')) {
119 } else if ($Group->usesPlugin('scmsvn')) {
123 $content = viewcvs_execute($unix_name, $repos_type);
126 // Set content type header from the value set by ViewCVS
127 // No other headers are generated by ViewCVS because in generate_etags
128 // is set to 0 in the ViewCVS config file
130 $line = strtok($content,SEPARATOR);
132 if ($line == 'Status: 301 Moved') {
135 $line = strtok(SEPARATOR);
140 while ($line && !$found) {
141 if (preg_match('/^Content-Type:(.*)$/',$line,$matches)) {
142 header('Content-Type:' . $matches[1]);
145 $line = strtok(SEPARATOR);
147 $content = substr($content, strpos($content,$line));
149 if (viewcvs_is_html()) {
150 // If we output html and we found the mbstring extension, we
151 // should try to encode the output of ViewCVS in UTF-8
152 if (extension_loaded('mbstring')) {
153 $encoding = mb_detect_encoding($content, 'UTF-8, ISO-8859-1');
154 if($encoding != 'UTF-8') {
155 $content = mb_convert_encoding($content, 'UTF-8', $encoding);
158 scm_header(array('title'=>_("SCM Repository"),
159 'group'=>$Group->getID()));
164 // TODO does not seem to work when allow_tar = 1 in ViewCVS conf
165 // (allow to generate on the fly a tar.gz): the generated file
166 // seems to be corrupted
172 // c-file-style: "bsd"