function processRequest($matches)
 {
     // Verify that the request type is acceptable.
     if (!is_null($this->requestTypeWhiteList)) {
         $requestIsAcceptable = false;
         foreach ($this->requestTypeWhiteList as $requestType) {
             if ($_SERVER['REQUEST_METHOD'] == $requestType) {
                 $requestIsAcceptable = true;
                 break;
             }
         }
         if (!$requestIsAcceptable) {
             throw new Exception("The request type is not acceptable.");
         }
     }
     $imagingServiceUri = PccConfig::getImagingService() . $_SERVER['PATH_INFO'];
     // Add only the white-listed query parameters to the outgoing request.
     $queryParameters = "";
     if (!is_null($this->queryParameterWhiteList)) {
         foreach ($this->queryParameterWhiteList as $key) {
             $data = $_GET[$key];
             if (!is_null($data)) {
                 if (!empty($queryParameters)) {
                     $queryParameters .= "&";
                 }
                 $queryParameters .= $key . '=' . urlencode($data);
             }
         }
     }
     if (!empty($queryParameters)) {
         $imagingServiceUri .= '?' . $queryParameters;
     }
     // Add only the white-listed request header items to the outgoing request.
     $headerList = '';
     $body = '';
     if (!is_null($this->requestHeaderWhiteList)) {
         foreach ($this->requestHeaderWhiteList as $key) {
             $data = $_SERVER[$key];
             if (!is_null($data)) {
                 $headerList = "{$headerList}{$key}: {$data}\r\n";
             }
         }
     }
     $acsApiKey = PccConfig::getApiKey();
     $headerList = "{$headerList}Acs-Api-Key: {$acsApiKey}\r\n";
     if ($_SERVER['REQUEST_METHOD'] == 'POST' || $_SERVER['REQUEST_METHOD'] == 'PUT') {
         $body = @file_get_contents('php://input');
     }
     $options = array('http' => array('method' => $_SERVER['REQUEST_METHOD'], 'header' => $headerList, 'content' => $body));
     $context = stream_context_create($options);
     $result = file_get_contents($imagingServiceUri, false, $context);
     // Retrieve HTTP status code
     list($version, $status_code, $msg) = explode(' ', $http_response_header[0], 3);
     // Add only the white-listed response header items to the response (plus the status code)
     if ($status_code == 0) {
         // The imaging service currently returns 0 status sometimes.
         $status_code = 200;
     }
     header("{$version} {$status_code} {$msg}");
     if (!is_null($this->responseHeaderWhiteList)) {
         foreach ($this->responseHeaderWhiteList as $key) {
             foreach ($http_response_header as $value) {
                 if (preg_match("/^{$key}:/i", $value)) {
                     // Successful match
                     header($value, TRUE);
                 }
             }
         }
     }
     // Return the body of the response only if it did not fail.
     if ($status_code == 200) {
         echo $result;
     }
 }
예제 #2
0
    }
} else {
    // If there was no 'document' parameter, but a 'viewingSessionId'
    // value exists, there is viewing session already so we don't
    // need to do anything else. This case is true when viewing attachments
    // of email message document types (.EML and .MSG).
    $viewingSessionId = stripslashes($_GET['viewingSessionId']);
    if (!empty($viewingSessionId)) {
        // Request properties about the viewing session from PCCIS.
        // The properties will include an identifier of the source document
        // from which the attachment was obtained. The name of the attachment
        // is also available. These values are used to just to provide
        // contextual information to the user.
        //   GET http://localhost:18681/PCCIS/V1/ViewingSession/u{Viewing Session ID}
        //
        $url = PccConfig::getImagingService() . "/ViewingSession/u" . urlencode($viewingSessionId);
        $result = file_get_contents($url);
        $response = json_decode($result);
        $document = $response->origin->sourceDocument . ":{" . $response->attachmentDisplayName . "}";
    } else {
        echo 'You must include the name of a document in the URL.<br/>';
        $link = $_SERVER['PHP_SELF'] . '?document=sample.doc';
        echo 'For example, click on this link: <a href="' . $link . '">' . $link . '</a>';
        return;
    }
}
?>
<!DOCTYPE html>
<html>
    <head id="Head1" runat="server">
        <meta charset="utf-8"/>
 $folder = PccConfig::getDocumentsPath();
 if (!is_writable($folder)) {
     header('HTTP/1.0 403 Forbidden');
     echo '<h1>403 Forbidden</h1>';
     return;
 }
 if (strstr($documentQueryParameter, "http://") || strstr($documentQueryParameter, "https://")) {
     $document = $documentQueryParameter;
 } else {
     $filenam = basename($documentQueryParameter);
     $filename = uniqid() . $filenam;
     $document = Utils::combine($folder, $filename);
 }
 $extension = pathinfo($document, PATHINFO_EXTENSION);
 $retval = move_uploaded_file($_FILES['file']['tmp_name'], $document);
 $correctPath = PccConfig::isFileSafeToOpen($document);
 if (!$correctPath) {
     header('HTTP/1.0 403 Forbidden');
     echo '<h1>403 Forbidden</h1>';
     return;
 }
 //$data = array('viewingSessionId' => $viewingSessionId);
 $data = array('filename' => $filename);
 $common = array();
 $jsonString = json_encode($data);
 //$format = $_REQUEST["f"];
 $format = $_GET["f"];
 if ($format == "jsonp") {
     header('Content-Type: text/html');
     echo "<script> window.res = " . $jsonString . ";</script>";
     // echo $jsonString;
 /**
  * parses the pcc.config file and stores the contents
  * @param string $config_path path or name of config file
  */
 public static function parse($config_path)
 {
     $parser = xml_parser_create();
     //xml_set_object($parser, $this);
     xml_set_element_handler($parser, array(PccConfig, 'tagStart'), array(PccConfig, 'tagEnd'));
     xml_set_character_data_handler($parser, array(PccConfig, 'tagContent'));
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     $xml = file_get_contents($config_path);
     if (!xml_parse($parser, str_replace(array("\n", "\r", "\t"), '', $xml))) {
         echo xml_error_string(xml_get_error_code($parser));
     }
     PccConfig::$documentPath = PccConfig::processPath(PccConfig::$documentPath, realpath(dirname(__FILE__)));
     PccConfig::$markupsPath = PccConfig::processPath(PccConfig::$markupsPath, realpath(dirname(__FILE__)));
     PccConfig::$imageStampPath = PccConfig::processPath(PccConfig::$imageStampPath, realpath(dirname(__FILE__)));
     PccConfig::$webServiceUrl = PccConfig::$webServiceScheme . '://' . PccConfig::$webServiceHost . ':' . PccConfig::$webServicePort . '/' . PccConfig::$webServicePath;
 }
예제 #5
0
function getImageStamp($matches)
{
    $requestedFormat = $_GET['format'];
    $file = base64_decode($matches[1]);
    $stampPath = PccConfig::getImageStampPath();
    $filepath = $stampPath . $file;
    if (!file_exists($filepath)) {
        throw new Exception('Image not found.');
    }
    $fileParts = explode('.', $file);
    $sourceImageFormat = strtolower($fileParts[1]);
    $acceptableFormats = explode(',', str_replace('.', '', PccConfig::getValidImageStampTypes()));
    if (!in_array($sourceImageFormat, $acceptableFormats)) {
        throw new Exception('Image format is not valid.');
    }
    $lastModifiedTime = filemtime($filepath);
    if ($lastModifiedTime === false) {
        throw new Exception('Modify date unknown');
    }
    if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
        $ifModifiedSinceTime = strtotime(preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']));
        if ($ifModifiedSinceTime >= $lastModifiedTime) {
            // Is the Cached version the most recent?
            header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
            return;
        }
    }
    header('Last-Modified: ' . date('r', $lastModifiedTime));
    header('Pragma: public');
    header('Cache-Control: max-age=86400');
    header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400));
    if ($requestedFormat == 'Base64') {
        $outputFormat = $requestedFormat;
    } else {
        $outputFormat = $sourceImageFormat;
    }
    $ext = strtolower(array_pop(explode('.', $filepath)));
    $mime_types = array('png' => 'image/png', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif');
    if (array_key_exists($ext, $mime_types)) {
        $imageType = $mime_types[$ext];
    } else {
        throw new Exception('Image type not supported.');
    }
    switch ($outputFormat) {
        case 'gif':
        case 'jpg':
        case 'jpeg':
        case 'png':
            header("Content-Type: {$imageType}");
            echo file_get_contents($filepath);
            break;
        case 'Base64':
            header("Content-Type: application/json");
            $base64Data = base64_encode(file_get_contents($filepath));
            echo json_encode(array('dataHash' => sha1($base64Data), 'dataUrl' => 'data: ' . $imageType . ';base64,' . $base64Data));
            break;
    }
}
        fclose($fileHandle);
        $options = array('http' => array('method' => 'PUT', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n", 'content' => $fileContents));
        // Upload File to PCCIS.
        //   PUT http://localhost:18681/PCCIS/V1/ViewingSessions/u{Viewing Session ID}/SourceFile?FileExtension={File Extension}
        // Note the "u" prefixed to the Viewing Session ID. This is required when providing
        //   an unencoded Viewing Session ID, which is what PCCIS returns from the initial POST.
        //
        $url = PccConfig::getImagingService() . "/ViewingSession/u{$viewingSessionId}/SourceFile?FileExtension={$extension}";
        $context = stream_context_create($options);
        file_get_contents($url, false, $context);
        $data = array('viewer' => 'HTML5');
        $options = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n", 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'content' => json_encode($data)));
        // Start Viewing Session in PCCIS.
        //   POST http://localhost:18681/PCCIS/V1/ViewingSessions/u{Viewing Session ID}/Notification/SessionStarted
        //
        $url = PccConfig::getImagingService() . "/ViewingSession/u{$viewingSessionId}/Notification/SessionStarted";
        $context = stream_context_create($options);
        file_get_contents($url, false, $context);
    } else {
        $url = PccConfig::getImagingService() . "/ViewingSession/u{$viewingSessionId}/Notification/SessionStopped";
        $data = array('endUserMessage' => "Document not found: {$documentQueryParameter}", 'httpStatus' => 504);
        $options = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n", 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'content' => json_encode($data)));
        $context = stream_context_create($options);
        file_get_contents($url, false, $context);
    }
    $data = array('viewingSessionId' => $viewingSessionId);
    echo json_encode($data);
} else {
    $data = array('error' => 'document parameter is required');
    echo json_encode($data);
}