4 * Utilitary class for the GForge ViewCVS 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 2012, Franck Villaume - TrivialDev
12 * http://fusionforge.org
14 * This file is part of FusionForge. FusionForge is free software;
15 * you can redistribute it and/or modify it under the terms of the
16 * GNU General Public License as published by the Free Software
17 * Foundation; either version 2 of the Licence, or (at your option)
20 * FusionForge is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 define ('SEPARATOR', "\n\t\r\0\x0B");
35 * viewcvs_is_html() - Test if ViewCVS returns HTML.
37 * @return true if the content type of the ViewCVS is text/html.
39 function viewcvs_is_html() {
40 $request_uri = getStringFromServer('REQUEST_URI');
41 $query_string = getStringFromServer('QUERY_STRING');
43 return (strpos($request_uri,"*checkout*") === false &&
44 strpos($query_string,"view=graphimg") === false &&
45 strpos($query_string,"view=patch") === false &&
46 strpos($query_string,"view=tar") === false &&
47 strpos($request_uri,"*docroot*") === false &&
48 strpos($request_uri,"makepatch=1") === false);
52 * make_arg_cmd_safe() - Make strings safe for the command line.
54 * @param string The argument that needs to be cleaned.
55 * @return string The argument with dangerous shell characters escaped.
57 function make_arg_cmd_safe($arg) {
58 if (get_magic_quotes_gpc()) {
59 $arg = stripslashes($arg);
61 return escapeshellcmd($arg);
65 * viewcvs_execute() - Call to viewcvs.cgi and returned the output.
67 * @return String the output of the ViewCVS command.
69 function viewcvs_execute($repos_name, $repos_type) {
70 $request_uri = getStringFromServer('REQUEST_URI');
71 $query_string = getStringFromServer('QUERY_STRING');
72 $query_string = preg_replace('/group_id=[0-9]+&/','',$query_string);
73 $viewcvs_path = forge_get_config('url_root').'/scm/viewvc';
75 // this is very important ...
76 $path = getStringFromServer('PATH_INFO');
78 $path = getStringFromServer('ORIG_PATH_INFO');
82 // hack: path must always end with /
83 if ($path[strlen($path)-1] != '/') {
90 if ($repos_type == "cvs") {
91 $repos_root = forge_get_config('repos_path', 'scmcvs').'/'.$repos_name;
92 } else if ($repos_type == "svn") {
93 $repos_root = forge_get_config('repos_path', 'scmsvn').'/'.$repos_name;
95 die("Invalid repository type");
98 if (!is_dir($repos_root)) {
99 $content = _('The repository for this project isn\'t created yet. It will be created in the next few minutes.');
103 $query_string = str_replace('\\&', '&', make_arg_cmd_safe($query_string));
104 $query_string = str_replace('\\*', '*', $query_string);
106 $path = str_replace('\\*', '*', make_arg_cmd_safe($path));
107 $command = 'HTTP_COOKIE="'.make_arg_cmd_safe(getStringFromServer('HTTP_COOKIE')).'" '.
108 'REMOTE_ADDR="'.make_arg_cmd_safe(getStringFromServer('REMOTE_ADDR')).'" '.
109 'QUERY_STRING="'.$query_string.'" '.
110 'SERVER_SOFTWARE="'.make_arg_cmd_safe(getStringFromServer('SERVER_SOFTWARE')).'" '.
111 'SCRIPT_NAME="'.make_arg_cmd_safe(getStringFromServer('SCRIPT_NAME')).'" '.
112 'HTTP_USER_AGENT="'.make_arg_cmd_safe(getStringFromServer('HTTP_USER_AGENT')).'" '.
113 'HTTP_ACCEPT_ENCODING="'.make_arg_cmd_safe(getStringFromServer('HTTP_ACCEPT_ENCODING')).'" '.
114 'HTTP_ACCEPT_LANGUAGE="'.make_arg_cmd_safe(getStringFromServer('HTTP_ACCEPT_LANGUAGE')).'" '.
115 'PATH_INFO="'.$path.'" '.
116 'PATH="'.make_arg_cmd_safe(getStringFromServer('PATH')).'" '.
117 'REPOSITORY_ROOT="'.make_arg_cmd_safe($repos_root).'" '.
118 'REPOSITORY_TYPE="'.$repos_type.'" '.
119 'REPOSITORY_NAME="'.make_arg_cmd_safe($repos_name).'" '.
120 'HTTP_HOST="'.make_arg_cmd_safe(getStringFromServer('HTTP_HOST')).'" '.
121 'DOCROOT="/themes/'.forge_get_config('default_theme').'/viewvc" '.
122 $viewcvs_path.'/bin/cgi/viewvc.cgi 2>&1';
126 $content = ob_get_contents();
133 // c-file-style: "bsd"