/** * call the viewvc.cgi and echo the parsed output */ function viewvc_utils_passcommand() { $parse = viewvc_utils_display_header(); $request_uri = getStringFromServer('REQUEST_URI'); //this is very important ... if (getStringFromServer('PATH_INFO') == "") { $path = "/"; //echo "no path<br>\n"; } else { $path = getStringFromServer('PATH_INFO'); // hack: path must always end with / if (strrpos($path, "/") != strlen($path) - 1) { $path .= "/"; } //echo "path=$path<br>\n"; } // "view=auto" is not well supported in wrapped mode. See SR 341 on Partners. $query_string = str_replace("view=auto", "view=markup", viewvc_utils_escape_string_from_server('QUERY_STRING')); $command = 'HTTP_COOKIE=' . viewvc_utils_escape_string_from_server('HTTP_COOKIE') . ' ' . 'HTTP_USER_AGENT=' . viewvc_utils_escape_string_from_server('HTTP_USER_AGENT') . ' ' . 'REMOTE_ADDR=' . escapeshellarg(HTTPRequest::getIPAddress()) . ' ' . 'QUERY_STRING=' . $query_string . ' ' . 'SERVER_SOFTWARE=' . viewvc_utils_escape_string_from_server('SERVER_SOFTWARE') . ' ' . 'SCRIPT_NAME=' . viewvc_utils_escape_string_from_server('SCRIPT_NAME') . ' ' . 'HTTP_ACCEPT_ENCODING=' . viewvc_utils_escape_string_from_server('HTTP_ACCEPT_ENCODING') . ' ' . 'HTTP_ACCEPT_LANGUAGE=' . viewvc_utils_escape_string_from_server('HTTP_ACCEPT_LANGUAGE') . ' ' . 'PATH_INFO=' . viewvc_utils_wrap_utf8_file_name($path) . ' ' . 'PATH=' . viewvc_utils_escape_string_from_server('PATH') . ' ' . 'HTTP_HOST=' . viewvc_utils_escape_string_from_server('HTTP_HOST') . ' ' . 'DOCUMENT_ROOT=' . viewvc_utils_escape_string_from_server('DOCUMENT_ROOT') . ' ' . 'CODENDI_LOCAL_INC=' . viewvc_utils_escape_string_from_server('CODENDI_LOCAL_INC') . ' ' . '/var/www/cgi-bin/viewvc.cgi 2>&1'; $content = viewvc_utils_wrap_utf8_exec($command); list($headers, $body) = http_split_header_body($content); // Set content type header from the value set by ViewVC // No other headers are generated by ViewVC because generate_etags // is set to 0 in the ViewVC config file $found = false; $line = strtok($content, "\n\t\r\v"); $pathInfo = pathinfo($path); while ($line && !$found) { if (preg_match('/^Content-Type:(.*)$/', $line, $matches)) { //Until Apache will support the office 2007 mime types by default //We should keep test on extension for IE to set the right Mime Type. $officeEtensions = array('docm' => 'application/vnd.ms-word.document.macroEnabled.12', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'); if (array_key_exists('extension', $pathInfo) && array_key_exists($pathInfo['extension'], $officeEtensions)) { $viewvc_content_type = $officeEtensions[$pathInfo['extension']]; } else { $viewvc_content_type = $matches[1]; } $found = true; } $line = strtok("\n\t\r\v"); } $content = substr($content, strpos($content, $line)); // Now look for 'Location:' header line (e.g. generated by 'view=redirect_pathrev' // parameter, used when browsing a directory at a certain revision number) $found = false; $line = strtok($content, "\n\t\r\v"); $viewvc_location = false; while ($line && !$found && strlen($line) > 1) { if (preg_match('/^Location:(.*)$/', $line, $matches)) { $viewvc_location = $matches[1]; $found = true; } $line = strtok("\n\t\r\v"); } if ($found) { $content = substr($content, strpos($content, $line)); } if ($parse) { //parse the html doc that we get from viewvc. //remove the http header part as well as the html header and //html body tags $begin_body = strpos($content, "<body"); if ($begin_body === false) { $begin_body = strpos($content, "<BODY"); $begin_doc = strpos($content, ">", $begin_body) + 1; } else { $begin_doc = strpos($content, ">", $begin_body) + 1; } $length = strpos($content, "</body>\n</html>") - $begin_doc; // Now insert references, and display echo util_make_reference_links(substr($content, $begin_doc, $length), $GLOBALS['group_id']); } else { if ($viewvc_location) { header('Location: ' . $viewvc_location); exit(1); } header('Content-Type:' . $viewvc_content_type . '; charset=utf-8'); echo $body; } }
exit_no_group(); } $root = $request->get('root'); $group_id = group_getid_by_name($root); if ($group_id === false) { exit_no_group(); } $vRootType = new Valid_WhiteList('roottype', array('svn')); $vRootType->setErrorMessage($Language->getText('svn_viewvc', 'bad_roottype')); $vRootType->required(); if ($request->valid($vRootType)) { if (!svn_utils_check_access(user_getname(), $root, viewvc_utils_getfile("/svn/viewvc.php"))) { exit_error($Language->getText('svn_viewvc', 'access_denied'), $Language->getText('svn_viewvc', 'acc_den_comment', session_make_url("/project/memberlist.php?group_id={$group_id}"))); } viewvc_utils_track_browsing($group_id, 'svn'); $display_header_footer = viewvc_utils_display_header(); if ($display_header_footer) { $prefix_title = ''; if ($path = viewvc_utils_getfile("/svn/viewvc.php")) { $prefix_title = basename($path) . ' - '; } $GLOBALS['HTML']->addStylesheet('/viewvc-static/styles.css'); svn_header(array('title' => $prefix_title . $Language->getText('svn_utils', 'browse_tree'), 'path' => '/' . urlencode(viewvc_utils_getfile("/svn/viewvc.php")))); } viewvc_utils_passcommand(); if ($display_header_footer) { site_footer(array()); } } else { svn_header(array('title' => $Language->getText('svn_utils', 'browse_tree'))); site_footer(array());