mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3488 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
268 lines
7.1 KiB
HTML
268 lines
7.1 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title></title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
|
|
<script type="text/javascript" src="isAllowed.js"></script>
|
|
<!--
|
|
BY DEFAULT THIS FILE DOES NOT WORK SO THAT YOU DON'T ACCIDENTALLY EXPOSE
|
|
ALL OF YOUR XHR-ENABLED SERVICES ON YOUR SITE.
|
|
|
|
In order for this file to work, you should define a function with the following signature:
|
|
|
|
function isAllowedRequest(request){
|
|
return false;
|
|
}
|
|
|
|
Return true out of the function if you want to allow the cross-domain request.
|
|
|
|
DON'T DEFINE THIS FUNCTION IN THIS FILE! Define it in a separate file called isAllowed.js
|
|
and include it in this page with a script tag that has a src attribute pointing to the file.
|
|
See the very first script tag in this file for an example. You do not have to place the
|
|
script file in the same directory as this file, just update the path above if you move it
|
|
somewhere else.
|
|
|
|
Customize the isAllowedRequest function to restrict what types of requests are allowed
|
|
for this server. The request object has the following properties:
|
|
- requestHeaders: an object with the request headers that are to be added to
|
|
the XHR request.
|
|
- method: the HTTP method (GET, POST, etc...)
|
|
- uri: The URI for the request.
|
|
- data: The URL-encoded data for the request. For a GET request, this would
|
|
be the querystring parameters. For a POST request, it wll be the
|
|
body data.
|
|
-->
|
|
<script type="text/javascript">
|
|
// <!--
|
|
/*
|
|
See xip_client.html for more info on the xip fragment identifier protocol.
|
|
|
|
This page uses Dojo to do the actual XMLHttpRequest (XHR) to the server, but you could
|
|
replace the Dojo references with your own XHR code if you like. But keep the other xip
|
|
code to communicate back to the xip client frame.
|
|
*/
|
|
djConfig = {
|
|
parseWidgets: false
|
|
}
|
|
// -->
|
|
</script>
|
|
<script type="text/javascript" src="../../dojo.js"></script>
|
|
<script type="text/javascript">
|
|
// <!--
|
|
dojo.require("dojo.io.*");
|
|
|
|
//Choosing 1024 as an arbitrary limit for the URL sizes.
|
|
//Anecdotal info seems to indicate this is safe to use in all
|
|
//modern browsers.
|
|
xipUrlLimit = 1024;
|
|
xipIdCounter = 1;
|
|
|
|
function xipServerInit(){
|
|
xipCurrentHash = "";
|
|
xipRequestMessage = "";
|
|
xipResponseParts = [];
|
|
xipPartIndex = 0;
|
|
}
|
|
|
|
function xipServerLoaded(){
|
|
xipServerInit();
|
|
xipClientUrl = decodeURIComponent(window.location.hash.substring(1, window.location.hash.length));
|
|
|
|
setInterval(pollHash, 10);
|
|
setClientUrl("loaded");
|
|
}
|
|
|
|
function pollHash(){
|
|
//Can't use location.hash because at least Firefox does a decodeURIComponent on it.
|
|
var urlParts = window.location.href.split("#");
|
|
if(urlParts.length == 2){
|
|
var newHash = urlParts[1];
|
|
if(newHash != xipCurrentHash){
|
|
try{
|
|
messageReceived(newHash);
|
|
}catch(e){
|
|
//Make sure to not keep processing the error hash value.
|
|
xipCurrentHash = newHash;
|
|
throw e;
|
|
}
|
|
xipCurrentHash = newHash;
|
|
}
|
|
}
|
|
}
|
|
|
|
function messageReceived(urlEncodedMessage){
|
|
//Split off xip header.
|
|
var parts = urlEncodedMessage.split(":");
|
|
var command = parts[1];
|
|
urlEncodedMessage = parts[2] || "";
|
|
|
|
switch(command){
|
|
case "ok":
|
|
sendResponsePart();
|
|
break;
|
|
case "start":
|
|
xipRequestMessage = "";
|
|
xipRequestMessage += urlEncodedMessage;
|
|
setClientUrl("ok");
|
|
break;
|
|
case "part":
|
|
xipRequestMessage += urlEncodedMessage;
|
|
setClientUrl("ok");
|
|
break;
|
|
case "end":
|
|
setClientUrl("ok");
|
|
xipRequestMessage += urlEncodedMessage;
|
|
sendXhr();
|
|
break;
|
|
}
|
|
}
|
|
|
|
function sendResponse(urlEncodedData){
|
|
//Break the message into parts, if necessary.
|
|
xipResponseParts = [];
|
|
var resData = urlEncodedData;
|
|
var urlLength = xipClientUrl.length;
|
|
var partLength = xipUrlLimit - urlLength;
|
|
var resIndex = 0;
|
|
|
|
while((resData.length - resIndex) + urlLength > xipUrlLimit){
|
|
xipResponseParts.push(resData.substring(resIndex, resIndex + partLength));
|
|
resIndex += partLength;
|
|
}
|
|
xipResponseParts.push(resData.substring(resIndex, resData.length));
|
|
|
|
xipPartIndex = 0;
|
|
sendResponsePart();
|
|
}
|
|
|
|
function sendResponsePart(){
|
|
if(xipPartIndex < xipResponseParts.length){
|
|
//Get the message part.
|
|
var partData = xipResponseParts[xipPartIndex];
|
|
|
|
//Get the command.
|
|
var cmd = "part";
|
|
if(xipPartIndex + 1 == xipResponseParts.length){
|
|
cmd = "end";
|
|
}else if (xipPartIndex == 0){
|
|
cmd = "start";
|
|
}
|
|
|
|
setClientUrl(cmd, partData);
|
|
xipPartIndex++;
|
|
}else{
|
|
xipServerInit();
|
|
}
|
|
}
|
|
|
|
function setClientUrl(cmd, message){
|
|
var clientUrl = xipClientUrl + "#" + (xipIdCounter++) + ":" + cmd;
|
|
if(message){
|
|
clientUrl += ":" + message;
|
|
}
|
|
|
|
//Safari won't let us replace across domains.
|
|
if(navigator.userAgent.indexOf("Safari") == -1){
|
|
parent.location.replace(clientUrl);
|
|
}else{
|
|
parent.location = clientUrl;
|
|
}
|
|
}
|
|
|
|
function sendXhr(){
|
|
//Decode data and pull off the fields that are sent by
|
|
//dojo.io.XhrIframeProxy.clientFrameLoaded()
|
|
/*
|
|
requestHeaders: reqHeaders.join("\r\n"),
|
|
method: facade.method,
|
|
uri: facade.uri,
|
|
data: facade._bodyData
|
|
*/
|
|
var request = {};
|
|
var nvPairs = xipRequestMessage.split("&");
|
|
var i = 0;
|
|
var nameValue = null;
|
|
for(i = 0; i < nvPairs.length; i++){
|
|
if(nvPairs[i]){
|
|
var nameValue = nvPairs[i].split("=");
|
|
request[decodeURIComponent(nameValue[0])] = decodeURIComponent(nameValue[1]);
|
|
}
|
|
}
|
|
|
|
//Split up the request headers, if any.
|
|
var headers = {};
|
|
if(request.requestHeaders){
|
|
nvPairs = request.requestHeaders.split("\r\n");
|
|
for(i = 0; i < nvPairs.length; i++){
|
|
if(nvPairs[i]){
|
|
nameValue = nvPairs[i].split(": ");
|
|
headers[decodeURIComponent(nameValue[0])] = decodeURIComponent(nameValue[1]);
|
|
}
|
|
}
|
|
|
|
request.requestHeaders = headers;
|
|
}
|
|
|
|
if(isAllowedRequest(request)){
|
|
var kwArgs = {
|
|
url: request.uri,
|
|
handle: function(type, data, xhr, args){
|
|
/* Need to pull off and return the following data:
|
|
- responseHeaders
|
|
- status
|
|
- statusText
|
|
- responseText
|
|
*/
|
|
var response = {};
|
|
|
|
if(typeof(xhr.getAllResponseHeaders) != "undefined"){
|
|
var allHeaders = xhr.getAllResponseHeaders();
|
|
if(allHeaders){
|
|
response.responseHeaders = allHeaders;
|
|
}
|
|
}
|
|
|
|
if(xhr.status == 0 || xhr.status){
|
|
response.status = xhr.status;
|
|
}
|
|
|
|
if(xhr.statusText){
|
|
response.statusText = xhr.statusText;
|
|
}
|
|
|
|
if(data){
|
|
response.responseText = data;
|
|
}
|
|
|
|
sendResponse(dojo.io.argsFromMap(response, "utf8"));
|
|
}
|
|
};
|
|
|
|
if(request.method){
|
|
kwArgs.method = request.method;
|
|
}
|
|
if(request.requestHeaders){
|
|
kwArgs.headers = request.requestHeaders;
|
|
}
|
|
if(request.data){
|
|
kwArgs.postContent = request.data;
|
|
}
|
|
|
|
dojo.io.bind(kwArgs);
|
|
}
|
|
}
|
|
|
|
dojo.addOnLoad(xipServerLoaded);
|
|
// -->
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<h4>The Dojo Toolkit -- xip_server.html</h4>
|
|
|
|
<p>This file is used for Dojo's XMLHttpRequest Iframe Proxy. This is the the file
|
|
that should go on the server that will actually be doing the XHR request.</p>
|
|
</body>
|
|
</html>
|