| 1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
| 1422 |
alexandre_ |
11 |
|
|
|
12 |
|
| 1318 |
alexandre_ |
13 |
dojo.render.name = dojo.hostenv.name_ = "dashboard";
|
|
|
14 |
dojo.hostenv.println = function (message) {
|
|
|
15 |
return alert(message);
|
|
|
16 |
};
|
|
|
17 |
dojo.hostenv.getXmlhttpObject = function (kwArgs) {
|
|
|
18 |
if (widget.system && kwArgs) {
|
|
|
19 |
if ((kwArgs.contentType && kwArgs.contentType.indexOf("text/") != 0) || (kwArgs.headers && kwArgs.headers["content-type"] && kwArgs.headers["content-type"].indexOf("text/") != 0)) {
|
|
|
20 |
var curl = new dojo.hostenv.CurlRequest;
|
|
|
21 |
curl._save = true;
|
|
|
22 |
return curl;
|
|
|
23 |
} else {
|
|
|
24 |
if (kwArgs.method && kwArgs.method.toUpperCase() == "HEAD") {
|
|
|
25 |
return new dojo.hostenv.CurlRequest;
|
|
|
26 |
} else {
|
|
|
27 |
if (kwArgs.headers && kwArgs.header.referer) {
|
|
|
28 |
return new dojo.hostenv.CurlRequest;
|
|
|
29 |
}
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
return new XMLHttpRequest;
|
|
|
34 |
};
|
|
|
35 |
dojo.hostenv.CurlRequest = function () {
|
|
|
36 |
this.onreadystatechange = null;
|
|
|
37 |
this.readyState = 0;
|
|
|
38 |
this.responseText = "";
|
|
|
39 |
this.responseXML = null;
|
|
|
40 |
this.status = 0;
|
|
|
41 |
this.statusText = "";
|
|
|
42 |
this._method = "";
|
|
|
43 |
this._url = "";
|
|
|
44 |
this._async = true;
|
|
|
45 |
this._referrer = "";
|
|
|
46 |
this._headers = [];
|
|
|
47 |
this._save = false;
|
|
|
48 |
this._responseHeader = "";
|
|
|
49 |
this._responseHeaders = {};
|
|
|
50 |
this._fileName = "";
|
|
|
51 |
this._username = "";
|
|
|
52 |
this._password = "";
|
|
|
53 |
};
|
|
|
54 |
dojo.hostenv.CurlRequest.prototype.open = function (method, url, async, username, password) {
|
|
|
55 |
this._method = method;
|
|
|
56 |
this._url = url;
|
|
|
57 |
if (async) {
|
|
|
58 |
this._async = async;
|
|
|
59 |
}
|
|
|
60 |
if (username) {
|
|
|
61 |
this._username = username;
|
|
|
62 |
}
|
|
|
63 |
if (password) {
|
|
|
64 |
this._password = password;
|
|
|
65 |
}
|
|
|
66 |
};
|
|
|
67 |
dojo.hostenv.CurlRequest.prototype.setRequestHeader = function (label, value) {
|
|
|
68 |
switch (label) {
|
|
|
69 |
case "Referer":
|
|
|
70 |
this._referrer = value;
|
|
|
71 |
break;
|
|
|
72 |
case "content-type":
|
|
|
73 |
break;
|
|
|
74 |
default:
|
|
|
75 |
this._headers.push(label + "=" + value);
|
|
|
76 |
break;
|
|
|
77 |
}
|
|
|
78 |
};
|
|
|
79 |
dojo.hostenv.CurlRequest.prototype.getAllResponseHeaders = function () {
|
|
|
80 |
return this._responseHeader;
|
|
|
81 |
};
|
|
|
82 |
dojo.hostenv.CurlRequest.prototype.getResponseHeader = function (headerLabel) {
|
|
|
83 |
return this._responseHeaders[headerLabel];
|
|
|
84 |
};
|
|
|
85 |
dojo.hostenv.CurlRequest.prototype.send = function (content) {
|
|
|
86 |
this.readyState = 1;
|
|
|
87 |
if (this.onreadystatechange) {
|
|
|
88 |
this.onreadystatechange.call(this);
|
|
|
89 |
}
|
|
|
90 |
var query = {sS:""};
|
|
|
91 |
if (this._referrer) {
|
|
|
92 |
query.e = this._referrer;
|
|
|
93 |
}
|
|
|
94 |
if (this._headers.length) {
|
|
|
95 |
query.H = this._headers.join("&");
|
|
|
96 |
}
|
|
|
97 |
if (this._username) {
|
|
|
98 |
if (this._password) {
|
|
|
99 |
query.u = this._username + ":" + this._password;
|
|
|
100 |
} else {
|
|
|
101 |
query.u = this._username;
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
if (content) {
|
|
|
105 |
query.d = this.content;
|
|
|
106 |
if (this._method != "POST") {
|
|
|
107 |
query.G = "";
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
if (this._method == "HEAD") {
|
|
|
111 |
query.I = "";
|
|
|
112 |
} else {
|
|
|
113 |
if (this._save) {
|
|
|
114 |
query.I = "";
|
|
|
115 |
} else {
|
|
|
116 |
query.i = "";
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
var system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
|
|
|
120 |
this.readyState = 2;
|
|
|
121 |
if (this.onreadystatechange) {
|
|
|
122 |
this.onreadystatechange.call(this);
|
|
|
123 |
}
|
|
|
124 |
if (system.errorString) {
|
|
|
125 |
this.responseText = system.errorString;
|
|
|
126 |
this.status = 0;
|
|
|
127 |
} else {
|
|
|
128 |
if (this._save) {
|
|
|
129 |
this._responseHeader = system.outputString;
|
|
|
130 |
} else {
|
|
|
131 |
var split = system.outputString.replace(/\r/g, "").split("\n\n", 2);
|
|
|
132 |
this._responseHeader = split[0];
|
|
|
133 |
this.responseText = split[1];
|
|
|
134 |
}
|
|
|
135 |
split = this._responseHeader.split("\n");
|
|
|
136 |
this.statusText = split.shift();
|
|
|
137 |
this.status = this.statusText.split(" ")[1];
|
|
|
138 |
for (var i = 0, header; header = split[i]; i++) {
|
|
|
139 |
var header_split = header.split(": ", 2);
|
|
|
140 |
this._responseHeaders[header_split[0]] = header_split[1];
|
|
|
141 |
}
|
|
|
142 |
if (this._save) {
|
|
|
143 |
widget.system("/bin/mkdir cache", null);
|
|
|
144 |
this._fileName = this._url.split("/").pop().replace(/\W/g, "");
|
|
|
145 |
this._fileName += "." + this._responseHeaders["Content-Type"].replace(/[\r\n]/g, "").split("/").pop();
|
|
|
146 |
delete query.I;
|
|
|
147 |
query.o = "cache/" + this._fileName;
|
|
|
148 |
system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
|
|
|
149 |
if (!system.errorString) {
|
|
|
150 |
this.responseText = "cache/" + this._fileName;
|
|
|
151 |
}
|
|
|
152 |
} else {
|
|
|
153 |
if (this._method == "HEAD") {
|
|
|
154 |
this.responseText = this._responseHeader;
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
this.readyState = 4;
|
|
|
159 |
if (this.onreadystatechange) {
|
|
|
160 |
this.onreadystatechange.call(this);
|
|
|
161 |
}
|
|
|
162 |
};
|
|
|
163 |
dojo.hostenv.CurlRequest._formatCall = function (query, url) {
|
|
|
164 |
var call = ["/usr/bin/curl"];
|
|
|
165 |
for (var key in query) {
|
|
|
166 |
if (query[key] != "") {
|
|
|
167 |
call.push("-" + key + " '" + query[key].replace(/'/g, "'") + "'");
|
|
|
168 |
} else {
|
|
|
169 |
call.push("-" + key);
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
call.push("'" + url.replace(/'/g, "'") + "'");
|
|
|
173 |
return call.join(" ");
|
|
|
174 |
};
|
|
|
175 |
dojo.hostenv.exit = function () {
|
|
|
176 |
if (widget.system) {
|
|
|
177 |
widget.system("/bin/rm -rf cache/*", null);
|
|
|
178 |
}
|
|
|
179 |
};
|
|
|
180 |
|