forked from joelagnel/validation-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.html
222 lines (181 loc) · 6.03 KB
/
list.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<html>
<head>
<!--
Amazon S3 Bucket listing.
Copyright (C) 2008 Francesco Pasqualini
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<title>Bucket listing</title>
<SCRIPT>
//document.write(window.location.search);
function getSpace(s,l){
var ret = "";
while(s.length+ret.length<l){
ret = ret + " ";
}
return ret;
}
location.querystring = (function() {
// The return is a collection of key/value pairs
var result = {};
// Gets the query string with a preceeding '?'
var querystring = location.search;
// document.location.search is empty if a query string is absent
if (!querystring)
return result;
// substring(1) to remove the '?'
var pairs = querystring.substring(1).split("&");
var splitPair;
// Load the key/values of the return collection
for (var i = 0; i < pairs.length; i++) {
splitPair = pairs[i].split("=");
result[splitPair[0]] = splitPair[1];
}
return result;
})();
function createRequestObject(){
var request_o; //declare the variable to hold the object.
var browser = navigator.appName; //find the browser name
if(browser == "Microsoft Internet Explorer"){
/* Create the object using MSIE's method */
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
/* Create the object using other browser's method */
request_o = new XMLHttpRequest();
}
return request_o; //return the object
}
/* You can get more specific with version information by using
parseInt(navigator.appVersion)
Which will extract an integer value containing the version
of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject();
function getList(){
http.open('get', location.protocol+'//'+location.hostname+'/?prefix='+location.pathname.replace(/list.html$/, '').replace(/^\//, ''));
http.onreadystatechange = handleList;
http.send(null);
}
function handleList(){
/* Make sure that the transaction has finished. The XMLHttpRequest object
has a property called readyState with several states:
0: Uninitialized
1: Loading
2: Loaded
3: Interactive
4: Finished */
if(http.readyState == 4){ //Finished loading the response
/* We have got the response from the server-side script,
let us see just what it was. using the responseText property of
the XMLHttpRequest object. */
var response = http.responseXML;
filex = response.getElementsByTagName('Contents');
res = '';
fileList = new Array();
for(i=0; i<filex.length; i++){
fileData =new Array();
fileList[i] = fileData;
size = filex[i].getElementsByTagName('Size')[0].firstChild.data;
name = filex[i].getElementsByTagName('Key')[0].firstChild.data;
lastmod = filex[i].getElementsByTagName('LastModified')[0].firstChild.data;
link = '<A HREF="'+location.protocol+'//'+location.hostname+'/'+name.replace(/\+/g, '%2B')+'">'+name+'</A>';
fileData[0] = name;
fileData[1] = size;
fileData[2] = lastmod;
fileData[3] = link;
}
fileList.sort(getSort());
//document.write(getSort());
for(i=0; i<fileList.length; i++){ //length is the same as count($array)
fileData = fileList[i];
name = fileData[0];
size = fileData[1];
lastmod = fileData[2];
link = fileData[3];
res = res + getSpace(size,15) +size + " B ";
res = res + " "+ getSpace(lastmod,20)+ lastmod + " ";
res = res + " "+ link+ getSpace(name,50) + " ";
res = res + "<BR>";
}
document.getElementById('bucket_list').innerHTML = "<PRE>"+getLink()+"<BR>"+res+"</PRE>" ;
}
}
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return null;
}
function sortSize(a,b) {
if(parseInt(a[1]) > parseInt(b[1])) return 1;
if(parseInt(a[1]) < parseInt(b[1])) return -1;
return 0;
}
function sortSizeDesc(a,b) { return (-sortSize(a,b)); }
function sortLastmod(a,b) {
if(a[2] > b[2]) return 1;
if(a[2] < b[2]) return -1;
return 0;
}
function sortLastmodDesc(a,b) { return (-sortLastmod(a,b)); }
function sortName(a,b) {
if(a[0] > b[0]) return 1;
if(a[0] < b[0]) return -1;
return 0;
}
function sortNameDesc(a,b) { return -sortName(a,b); }
//document.write('http://'+location.hostname);
function getSort(){
var s = getQueryVariable("sort");
var d = getQueryVariable("sortdir");
if(s=='size'){ return d == 'desc' ? sortSizeDesc : sortSize};
if(s=='name'){ return d == 'desc' ? sortNameDesc : sortName};
if(s=='lastmod'){ return d == 'desc' ? sortLastmodDesc : sortLastmod};
return sortName;
}
function getLink(){
return " "+getLinkSize() + " " + getLinkLastmod() + " " + getLinkName() + " " ;
}
function getNextSortDir(sortCol){
if (sortCol == getQueryVariable("sort"))
return getQueryVariable("sortdir") == 'desc' ? 'asc' : 'desc';
return 'asc'
}
function getLinkSize(){
return "<A HREF=\"?sort=size&sortdir=" +getNextSortDir('size') +"\">Size</A>";
}
function getLinkName(){
return "<A HREF=\"?sort=name&sortdir=" +getNextSortDir('name') +"\">Name</A>";
}
function getLinkLastmod(){
return "<A HREF=\"?sort=lastmod&sortdir=" +getNextSortDir('lastmod') +"\">Lastmodified</A>";
}
</SCRIPT>
</head>
<body onLoad="getList();">
<div id="bucket_list">
<!--This is where we'll be displaying the products once they're loaded-->
</div>
<BR>
<SMALL>
<PRE>
Amazon S3 Bucket list v 1.1
</PRE>
</SMALL>
</body>
</html>