Example #1
0
 public function getContent(HTTPRequest $request)
 {
     $parse = $this->displayViewVcHeader($request);
     $headers = "";
     $body = "";
     //this is very important. default path must be /
     $path = "/";
     if ($request->getFromServer('PATH_INFO') != "") {
         $path = $request->getFromServer('PATH_INFO');
         // hack: path must always end with /
         if (strrpos($path, "/") != strlen($path) - 1) {
             $path .= "/";
         }
     }
     $command = 'HTTP_COOKIE=' . $this->escapeStringFromServer($request, 'HTTP_COOKIE') . ' ' . 'HTTP_USER_AGENT=' . $this->escapeStringFromServer($request, 'HTTP_USER_AGENT') . ' ' . 'REMOTE_ADDR=' . escapeshellarg(HTTPRequest::instance()->getIPAddress()) . ' ' . 'QUERY_STRING=' . $this->cleanQueryString($request) . ' ' . 'SERVER_SOFTWARE=' . $this->escapeStringFromServer($request, 'SERVER_SOFTWARE') . ' ' . 'SCRIPT_NAME=' . $this->escapeStringFromServer($request, 'SCRIPT_NAME') . ' ' . 'HTTP_ACCEPT_ENCODING=' . $this->escapeStringFromServer($request, 'HTTP_ACCEPT_ENCODING') . ' ' . 'HTTP_ACCEPT_LANGUAGE=' . $this->escapeStringFromServer($request, 'HTTP_ACCEPT_LANGUAGE') . ' ' . 'PATH_INFO=' . $this->setLocaleOnFileName($path) . ' ' . 'PATH=' . $this->escapeStringFromServer($request, 'PATH') . ' ' . 'HTTP_HOST=' . $this->escapeStringFromServer($request, 'HTTP_HOST') . ' ' . 'DOCUMENT_ROOT=' . $this->escapeStringFromServer($request, 'DOCUMENT_ROOT') . ' ' . 'CODENDI_LOCAL_INC=' . $this->escapeStringFromServer($request, 'CODENDI_LOCAL_INC') . ' ' . '/var/www/cgi-bin/viewvc.cgi 2>&1';
     $content = $this->setLocaleOnCommand($command);
     list($headers, $body) = http_split_header_body($content);
     $content_type_line = strtok($content, "\n\t\r\v");
     $viewvc_content_type = $this->getViewVcContentType($content_type_line, $path);
     $content = substr($content, strpos($content, $content_type_line));
     $location_line = strtok($content, "\n\t\r\v");
     $viewvc_location = $this->getViewVcLocationHeader($location_line);
     if ($viewvc_location) {
         $content = substr($content, strpos($content, $location_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 = stripos($content, "<body");
         $begin_doc = strpos($content, ">", $begin_body) + 1;
         $length = strpos($content, "</body>\n</html>") - $begin_doc;
         // Now insert references, and display
         return util_make_reference_links(substr($content, $begin_doc, $length), $request->get('group_id'));
     } else {
         if ($viewvc_location) {
             $redirect = new \URLRedirect();
             $redirect->makeReturnToUrl($request, $viewvc_location);
             // TODO: need to test this
             // header('Location: '.$viewvc_location);
             // exit(1);
         }
         header('Content-Type:' . $viewvc_content_type . '; charset=utf-8');
         return $body;
     }
 }
Example #2
0
/**
 * 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;
    }
}