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
14 define ('SEPARATOR', "\n\t\r\0\x0B");
17 * viewcvs_is_html() - Test if ViewCVS returns HTML.
19 * @return true if the content type of the ViewCVS is text/html.
21 function viewcvs_is_html() {
22 $request_uri = getStringFromServer('REQUEST_URI');
23 $query_string = getStringFromServer('QUERY_STRING');
25 return (strpos($request_uri,"*checkout*") === false &&
26 strpos($query_string,"view=graphimg") === false &&
27 strpos($query_string,"view=patch") === false &&
28 strpos($query_string,"view=tar") === false &&
29 strpos($request_uri,"*docroot*") === false &&
30 strpos($request_uri,"makepatch=1") === false);
34 * make_arg_cmd_safe() - Make strings safe for the command line.
36 * @param string The argument that needs to be cleaned.
37 * @return string The argument with dangerous shell characters escaped.
39 function make_arg_cmd_safe($arg) {
40 if (get_magic_quotes_gpc()) {
41 $arg = stripslashes($arg);
43 return escapeshellcmd($arg);
47 * viewcvs_execute() - Call to viewcvs.cgi and returned the output.
49 * @return String the output of the ViewCVS command.
51 function viewcvs_execute($repos_name, $repos_type) {
54 $request_uri = getStringFromServer('REQUEST_URI');
55 $query_string = getStringFromServer('QUERY_STRING');
57 $viewcvs_path = $GLOBALS['sys_urlroot'].'/scm/viewvc';
59 // this is very important ...
60 if (getStringFromServer('PATH_INFO') == '') {
63 $path = getStringFromServer('PATH_INFO');
64 // hack: path must always end with /
65 if (strrpos($path,'/') != (strlen($path)-1)) {
70 if ($repos_type == "cvs") {
71 $repos_root = $GLOBALS['cvsdir_prefix'].'/'.$repos_name;
72 } else if ($repos_type == "svn") {
73 $repos_root = $GLOBALS['svndir_prefix'].'/'.$repos_name;
75 die("Invalid repository type");
78 if (!is_dir($repos_root)) {
79 $content = _('The repository for this project isn\'t created yet. It will be created in the next few minutes.');
83 $query_string = str_replace('\\&', '&', make_arg_cmd_safe($query_string));
84 $query_string = str_replace('\\*', '*', $query_string);
86 $path = str_replace('\\*', '*', make_arg_cmd_safe($path));
87 $command = 'HTTP_COOKIE="'.make_arg_cmd_safe(getStringFromServer('HTTP_COOKIE')).'" '.
88 'REMOTE_ADDR="'.make_arg_cmd_safe(getStringFromServer('REMOTE_ADDR')).'" '.
89 'QUERY_STRING="'.$query_string.'" '.
90 'SERVER_SOFTWARE="'.make_arg_cmd_safe(getStringFromServer('SERVER_SOFTWARE')).'" '.
91 'SCRIPT_NAME="'.make_arg_cmd_safe(getStringFromServer('SCRIPT_NAME')).'" '.
92 'HTTP_USER_AGENT="'.make_arg_cmd_safe(getStringFromServer('HTTP_USER_AGENT')).'" '.
93 'HTTP_ACCEPT_ENCODING="'.make_arg_cmd_safe(getStringFromServer('HTTP_ACCEPT_ENCODING')).'" '.
94 'HTTP_ACCEPT_LANGUAGE="'.make_arg_cmd_safe(getStringFromServer('HTTP_ACCEPT_LANGUAGE')).'" '.
95 'PATH_INFO="'.$path.'" '.
96 'PATH="'.make_arg_cmd_safe(getStringFromServer('PATH')).'" '.
97 'REPOSITORY_ROOT="'.make_arg_cmd_safe($repos_root).'" '.
98 'REPOSITORY_TYPE="'.$repos_type.'" '.
99 'REPOSITORY_NAME="'.make_arg_cmd_safe($repos_name).'" '.
100 'HTTP_HOST="'.make_arg_cmd_safe(getStringFromServer('HTTP_HOST')).'" '.
101 'DOCROOT="/themes/'.$GLOBALS['sys_theme'].'/viewvc" '.
102 $viewcvs_path.'/bin/cgi/viewvc.cgi 2>&1';
106 $content = ob_get_contents();