-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathknox.js
152 lines (135 loc) · 5.02 KB
/
knox.js
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
function listStatus()
{
// restjs.useJSON();
var req = new XMLHttpRequest()
req.onerror=function() {
}
req.onreadystatechange=function() {
// hide(document.getElementById('login'));
if (req.readyState == 4 && req.status == 200) {
// hide(document.getElementById('login'));
myFunction(req.responseText);
}
else {
if (req.readyState == 4 && req.status == 403) {
hide(document.getElementById('login'));
document.getElementById("path").innerHTML= getPathParameter() + "<br/>";
document.getElementById("listing").innerHTML= '<p style="color:red">Forbidden</p><a href="?topology=' + getParameterByName("topology") + '&path=' + getParentDir() + '">..</a>\n' + "<br/>";
}
else {
// alert(req.readyState + " " + req.status);
}
}
}
req.open("get", getWebHDFSURL() + "?op=LISTSTATUS", true, null, null)
req.setRequestHeader('Content-Type', 'application/json');
req.withCredentials = true;
req.send(null)
}
function hide (elements, specifiedDisplay) {
var computedDisplay, element, index;
elements = elements.length ? elements : [elements];
for (index = 0; index < elements.length; index++) {
element = elements[index];
element.style.display = '';
element.style.display = 'none';
}
}
function getWebHDFSURL() {
return "https://" + getWebHDFSPath() + getParameterByName("path");
}
function getWebHDFSPath() {
var webhdfs;
var topo = getParameterByName("topology");
if (topo === "") {
webhdfs = "127.0.0.1:8443/gateway/sandbox/webhdfs/v1";
}
else {
webhdfs = topo + "webhdfs/v1";
}
return webhdfs;
}
function myFunction(response) {
var value = response;
document.getElementById("path").innerHTML= getPathParameter() + "<br/>";
document.getElementById("listing").innerHTML= '<a href="?topology=' + getParameterByName("topology") + '&path=' + getPathParameter() + '">..</a>\n' + "<br/>";
var obj = JSON.parse(response);
console.log();
var link = "";
var listing = "_";
document.getElementById("listing").innerHTML= '<a href="?topology=' + getParameterByName("topology") + '&path=' + getPathParameter() + '">.</a>\n' + "<br/>";
document.getElementById("listing").innerHTML += '<a href="?topology=' + getParameterByName("topology") + '&path=' + getParentDir() + '">..</a>\n' + "<br/>";
for(var i=0; i < obj.FileStatuses.FileStatus.length; i++){
listing = "_";
if (obj.FileStatuses.FileStatus[i].type == "DIRECTORY" ) {
listing = "d";
}
listing += toSymbolic(parseInt(obj.FileStatuses.FileStatus[i].permission)) + " " +
obj.FileStatuses.FileStatus[i].permission + " " +
obj.FileStatuses.FileStatus[i].owner + " " +
obj.FileStatuses.FileStatus[i].group + " " +
obj.FileStatuses.FileStatus[i].length + " " +
convertTime(parseInt(obj.FileStatuses.FileStatus[i].modificationTime)) + " " +
obj.FileStatuses.FileStatus[i].replication + " " +
'<a href="?topology=' + getParameterByName("topology") + '&path=' + getPathParameter() + obj.FileStatuses.FileStatus[i].pathSuffix + '">' + obj.FileStatuses.FileStatus[i].pathSuffix + '</a>';
document.getElementById("listing").innerHTML+="<br/>" + listing;
}
hide(document.getElementById('login', 'none'));
}
function getPathParameter() {
var path = getParameterByName("path");
if (!path.endsWith("/")) {
path = path + "/";
}
return path;
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function getParentDir() {
var wd = getPathParameter();
var dirs = wd.split('/');
next = "/";
if (dirs.length > 1) {
for (var i = 0; i < dirs.length-2; i++) {
next = next + dirs[i];
if (!next.endsWith("/")) {
next += "/";
}
}
}
return next;
}
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
function convertTime(timeMilliSecs) {
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(timeMilliSecs/1000);
return d;
}
function toSymbolic ( octal, output ) {
var digits, binary, block=[]
, output = output || 'array';
if (octal > 777) octal = new String(octal).substring(1, 4);
if ( !isOctalValid( octal ) ) {
throw new Error( "Permission octal representation is not valid: " + octal );
}
digits = ( octal ).toString().split('');
digits.forEach( function ( d, index ) {
var symbole = '';
binary = (parseInt(d)).toString(2);
symbole += ( binary >= 100 ) ? 'r' : '-';
symbole += ( (binary-100) >= 10 ) ? 'w' : '-';
symbole += ((binary-100) == 1 || (binary-110) == 1 ) ? 'x' : '-';
block[index] = symbole;
});
return ( 'string' == output.toLowerCase() ) ? block.join('') : block ;
}
function isOctalValid ( octal ) {
if ( !octal ) return false;
return !!( parseInt(octal) && octal > 100 && octal < 778 );
}