4 * GForge 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
13 // make sure we're not compressing output if we are making a tarball
14 if (isset($_GET['view']) && $_GET['view'] == 'tar') {
18 require_once('../env.inc.php');
19 require_once $gfwww.'include/pre.php';
20 require_once $gfwww.'scm/include/scm_utils.php';
21 require_once $gfwww.'scm/include/viewvc_utils.php';
23 if (!forge_get_config('use_scm')) {
27 // Get the project name from query
28 if(getStringFromGet('root') && strpos(getStringFromGet('root'), ';') === false) {
29 $projectName = getStringFromGet('root');
31 $queryString = getStringFromServer('QUERY_STRING');
32 if(preg_match_all('/[;]?([^\?;=]+)=([^;]+)/', $queryString, $matches, PREG_SET_ORDER)) {
33 for($i = 0, $size = sizeof($matches); $i < $size; $i++) {
34 $query[$matches[$i][1]] = urldecode($matches[$i][2]);
36 $projectName = $query['root'];
39 // Remove eventual leading /root/ or root/
40 $projectName = ereg_replace('^..[^/]*/','', $projectName);
46 $Group =& group_get_object_by_name($projectName);
47 if (!$Group || !is_object($Group) || $Group->isError()) {
50 if (!$Group->usesSCM()) {
51 exit_error(_('Error'), _('Error - This project has turned off SCM.'));
54 // check if the scm_box is located in another server
55 $scm_box = $Group->getSCMBox();
56 //$external_scm = (gethostbyname(forge_get_config('web_host')) != gethostbyname($scm_box));
57 $external_scm = !$sys_scm_single_host;
59 if (session_loggedin()) {
60 if (user_ismember($Group->getID())) {
61 $perm = & $Group->getPermission(session_get_user());
63 if (!($perm && is_object($perm) && $perm->isCVSReader()) && !$Group->enableAnonSCM()) {
64 exit_permission_denied();
66 } else if (!$Group->enableAnonSCM()) {
67 exit_permission_denied();
70 } else if (!$Group->enableAnonSCM()) { // user is not logged in... check if group accepts anonymous CVS
71 exit_permission_denied();
75 //$server_script = "/cgi-bin/viewcvs.cgi";
76 $server_script = $GLOBALS["sys_path_to_scmweb"]."/viewcvs.cgi";
77 // remove leading / (if any)
78 $server_script = preg_replace("/^\\//", "", $server_script);
80 // pass the parameters passed to this script to the remote script in the same fashion
81 $script_url = "http://".$scm_box."/".$server_script.$_SERVER["PATH_INFO"]."?".$_SERVER["QUERY_STRING"];
82 $fh = @fopen($script_url, "r");
84 exit_error('Error', 'Could not open script <b>'.$script_url.'</b>.');
87 // start reading the output of the script (in 8k chunks)
90 $content .= fread($fh, 8192);
93 if (viewcvs_is_html()) {
94 // Now, we must replace the occurencies of $server_script with this script
95 // (do this only of outputting HTML)
96 // We must do this because we can't pass the environment variable SCRIPT_NAME
97 // to the cvsweb script (maybe this can be fixed in the future?)
98 $content = str_replace("/".$server_script, $_SERVER["SCRIPT_NAME"], $content);
101 $unix_name = $Group->getUnixName();
103 // Call to ViewCVS CGI locally (see viewcvs_utils.php)
105 // see what type of plugin this project if using
106 if ($Group->usesPlugin('scmcvs')) {
108 } else if ($Group->usesPlugin('scmsvn')) {
112 $content = viewcvs_execute($unix_name, $repos_type);
115 // Set content type header from the value set by ViewCVS
116 // No other headers are generated by ViewCVS because in generate_etags
117 // is set to 0 in the ViewCVS config file
119 $line = strtok($content,SEPARATOR);
120 while ($line && !$found) {
121 if (preg_match('/^Content-Type:(.*)$/',$line,$matches)) {
122 header('Content-Type:' . $matches[1]);
125 $line = strtok(SEPARATOR);
127 $content = substr($content, strpos($content,$line));
129 if (viewcvs_is_html()) {
130 // If we output html and we found the mbstring extension, we
131 // should try to encode the output of ViewCVS in UTF-8
132 if (extension_loaded('mbstring')) {
133 $encoding = mb_detect_encoding($content, 'UTF-8, ISO-8859-1');
134 if($encoding != 'UTF-8') {
135 $content = mb_convert_encoding($content, 'UTF-8', $encoding);
140 // TODO does not seem to work when allow_tar = 1 in ViewCVS conf
141 // (allow to generate on the fly a tar.gz): the generated file
142 // seems to be corrupted