Edit File by line
/home/barbar84/www/wp-conte.../plugins/file-man.../applicat.../library/js/commands
File: netmount.js
/**
[0] Fix | Delete
* @class elFinder command "netmount"
[1] Fix | Delete
* Mount network volume with user credentials.
[2] Fix | Delete
*
[3] Fix | Delete
* @author Dmitry (dio) Levashov
[4] Fix | Delete
**/
[5] Fix | Delete
elFinder.prototype.commands.netmount = function() {
[6] Fix | Delete
"use strict";
[7] Fix | Delete
var self = this,
[8] Fix | Delete
hasMenus = false,
[9] Fix | Delete
content;
[10] Fix | Delete
[11] Fix | Delete
this.alwaysEnabled = true;
[12] Fix | Delete
this.updateOnSelect = false;
[13] Fix | Delete
[14] Fix | Delete
this.drivers = [];
[15] Fix | Delete
[16] Fix | Delete
this.handlers = {
[17] Fix | Delete
load : function() {
[18] Fix | Delete
var fm = self.fm;
[19] Fix | Delete
if (fm.cookieEnabled) {
[20] Fix | Delete
fm.one('open', function() {
[21] Fix | Delete
self.drivers = fm.netDrivers;
[22] Fix | Delete
if (self.drivers.length) {
[23] Fix | Delete
$.each(self.drivers, function() {
[24] Fix | Delete
var d = self.options[this];
[25] Fix | Delete
if (d) {
[26] Fix | Delete
hasMenus = true;
[27] Fix | Delete
if (d.integrateInfo) {
[28] Fix | Delete
fm.trigger('helpIntegration', Object.assign({cmd: 'netmount'}, d.integrateInfo));
[29] Fix | Delete
}
[30] Fix | Delete
}
[31] Fix | Delete
});
[32] Fix | Delete
}
[33] Fix | Delete
});
[34] Fix | Delete
}
[35] Fix | Delete
}
[36] Fix | Delete
};
[37] Fix | Delete
[38] Fix | Delete
this.getstate = function() {
[39] Fix | Delete
return hasMenus ? 0 : -1;
[40] Fix | Delete
};
[41] Fix | Delete
[42] Fix | Delete
this.exec = function() {
[43] Fix | Delete
var fm = self.fm,
[44] Fix | Delete
dfrd = $.Deferred(),
[45] Fix | Delete
o = self.options,
[46] Fix | Delete
create = function() {
[47] Fix | Delete
var winFocus = function() {
[48] Fix | Delete
inputs.protocol.trigger('change', 'winfocus');
[49] Fix | Delete
},
[50] Fix | Delete
inputs = {
[51] Fix | Delete
protocol : $('<select></select>')
[52] Fix | Delete
.on('change', function(e, data){
[53] Fix | Delete
var protocol = this.value;
[54] Fix | Delete
content.find('.elfinder-netmount-tr').hide();
[55] Fix | Delete
content.find('.elfinder-netmount-tr-'+protocol).show();
[56] Fix | Delete
dialogNode && dialogNode.children('.ui-dialog-buttonpane:first').find('button').show();
[57] Fix | Delete
if (typeof o[protocol].select == 'function') {
[58] Fix | Delete
o[protocol].select(fm, e, data);
[59] Fix | Delete
}
[60] Fix | Delete
})
[61] Fix | Delete
.addClass('ui-corner-all')
[62] Fix | Delete
},
[63] Fix | Delete
opts = {
[64] Fix | Delete
title : fm.i18n('netMountDialogTitle'),
[65] Fix | Delete
resizable : true,
[66] Fix | Delete
modal : true,
[67] Fix | Delete
destroyOnClose : false,
[68] Fix | Delete
open : function() {
[69] Fix | Delete
$(window).on('focus.'+fm.namespace, winFocus);
[70] Fix | Delete
inputs.protocol.trigger('change');
[71] Fix | Delete
},
[72] Fix | Delete
close : function() {
[73] Fix | Delete
dfrd.state() == 'pending' && dfrd.reject();
[74] Fix | Delete
$(window).off('focus.'+fm.namespace, winFocus);
[75] Fix | Delete
},
[76] Fix | Delete
buttons : {}
[77] Fix | Delete
},
[78] Fix | Delete
doMount = function() {
[79] Fix | Delete
var protocol = inputs.protocol.val(),
[80] Fix | Delete
data = {cmd : 'netmount', protocol: protocol},
[81] Fix | Delete
cur = o[protocol],
[82] Fix | Delete
mnt2res;
[83] Fix | Delete
$.each(content.find('input.elfinder-netmount-inputs-'+protocol), function(name, input) {
[84] Fix | Delete
var val, elm;
[85] Fix | Delete
elm = $(input);
[86] Fix | Delete
if (elm.is(':radio,:checkbox')) {
[87] Fix | Delete
if (elm.is(':checked')) {
[88] Fix | Delete
val = $.trim(elm.val());
[89] Fix | Delete
}
[90] Fix | Delete
} else {
[91] Fix | Delete
val = $.trim(elm.val());
[92] Fix | Delete
}
[93] Fix | Delete
if (val) {
[94] Fix | Delete
data[input.name] = val;
[95] Fix | Delete
}
[96] Fix | Delete
});
[97] Fix | Delete
[98] Fix | Delete
if (!data.host) {
[99] Fix | Delete
return fm.trigger('error', {error : 'errNetMountHostReq', opts : {modal: true}});
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
if (data.mnt2res) {
[103] Fix | Delete
mnt2res = true;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
fm.request({data : data, notify : {type : 'netmount', cnt : 1, hideCnt : true}})
[107] Fix | Delete
.done(function(data) {
[108] Fix | Delete
var pdir;
[109] Fix | Delete
if (data.added && data.added.length) {
[110] Fix | Delete
mnt2res && inputs.protocol.trigger('change', 'reset');
[111] Fix | Delete
if (data.added[0].phash) {
[112] Fix | Delete
if (pdir = fm.file(data.added[0].phash)) {
[113] Fix | Delete
if (! pdir.dirs) {
[114] Fix | Delete
pdir.dirs = 1;
[115] Fix | Delete
fm.change({ changed: [ pdir ] });
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
fm.one('netmountdone', function() {
[120] Fix | Delete
fm.exec('open', data.added[0].hash);
[121] Fix | Delete
});
[122] Fix | Delete
}
[123] Fix | Delete
dfrd.resolve();
[124] Fix | Delete
})
[125] Fix | Delete
.fail(function(error) {
[126] Fix | Delete
if (cur.fail && typeof cur.fail == 'function') {
[127] Fix | Delete
cur.fail(fm, fm.parseError(error));
[128] Fix | Delete
}
[129] Fix | Delete
dfrd.reject(error);
[130] Fix | Delete
});
[131] Fix | Delete
[132] Fix | Delete
self.dialog.elfinderdialog('close');
[133] Fix | Delete
},
[134] Fix | Delete
form = $('<form autocomplete="off"></form>').on('keydown', 'input', function(e) {
[135] Fix | Delete
var comp = true,
[136] Fix | Delete
next;
[137] Fix | Delete
if (e.keyCode === $.ui.keyCode.ENTER) {
[138] Fix | Delete
$.each(form.find('input:visible:not(.elfinder-input-optional)'), function() {
[139] Fix | Delete
if ($(this).val() === '') {
[140] Fix | Delete
comp = false;
[141] Fix | Delete
next = $(this);
[142] Fix | Delete
return false;
[143] Fix | Delete
}
[144] Fix | Delete
});
[145] Fix | Delete
if (comp) {
[146] Fix | Delete
doMount();
[147] Fix | Delete
} else {
[148] Fix | Delete
next.trigger('focus');
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
}),
[152] Fix | Delete
hidden = $('<div></div>'),
[153] Fix | Delete
dialog;
[154] Fix | Delete
[155] Fix | Delete
content = $('<table class="elfinder-info-tb elfinder-netmount-tb"></table>')
[156] Fix | Delete
.append($('<tr></tr>').append($('<td>'+fm.i18n('protocol')+'</td>')).append($('<td></td>').append(inputs.protocol)));
[157] Fix | Delete
[158] Fix | Delete
$.each(self.drivers, function(i, protocol) {
[159] Fix | Delete
if (o[protocol]) {
[160] Fix | Delete
inputs.protocol.append('<option value="'+protocol+'">'+fm.i18n(o[protocol].name || protocol)+'</option>');
[161] Fix | Delete
$.each(o[protocol].inputs, function(name, input) {
[162] Fix | Delete
input.attr('name', name);
[163] Fix | Delete
if (input.attr('type') != 'hidden') {
[164] Fix | Delete
input.addClass('ui-corner-all elfinder-netmount-inputs-'+protocol);
[165] Fix | Delete
content.append($('<tr></tr>').addClass('elfinder-netmount-tr elfinder-netmount-tr-'+protocol).append($('<td>'+fm.i18n(name)+'</td>')).append($('<td></td>').append(input)));
[166] Fix | Delete
} else {
[167] Fix | Delete
input.addClass('elfinder-netmount-inputs-'+protocol);
[168] Fix | Delete
hidden.append(input);
[169] Fix | Delete
}
[170] Fix | Delete
});
[171] Fix | Delete
o[protocol].protocol = inputs.protocol;
[172] Fix | Delete
}
[173] Fix | Delete
});
[174] Fix | Delete
[175] Fix | Delete
content.append(hidden);
[176] Fix | Delete
[177] Fix | Delete
content.find('.elfinder-netmount-tr').hide();
[178] Fix | Delete
content.find('.elfinder-netmount-tr-' + self.drivers[0]).show();
[179] Fix | Delete
[180] Fix | Delete
opts.buttons[fm.i18n('btnMount')] = doMount;
[181] Fix | Delete
[182] Fix | Delete
opts.buttons[fm.i18n('btnCancel')] = function() {
[183] Fix | Delete
self.dialog.elfinderdialog('close');
[184] Fix | Delete
};
[185] Fix | Delete
[186] Fix | Delete
content.find('select,input').addClass('elfinder-tabstop');
[187] Fix | Delete
[188] Fix | Delete
dialog = self.fmDialog(form.append(content), opts).ready(function() {
[189] Fix | Delete
inputs.protocol.trigger('change');
[190] Fix | Delete
dialog.elfinderdialog('posInit');
[191] Fix | Delete
});
[192] Fix | Delete
dialogNode = dialog.closest('.ui-dialog');
[193] Fix | Delete
return dialog;
[194] Fix | Delete
},
[195] Fix | Delete
dialogNode;
[196] Fix | Delete
[197] Fix | Delete
if (!self.dialog) {
[198] Fix | Delete
self.dialog = create();
[199] Fix | Delete
} else {
[200] Fix | Delete
self.dialog.elfinderdialog('open');
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
return dfrd.promise();
[204] Fix | Delete
};
[205] Fix | Delete
[206] Fix | Delete
self.fm.bind('netmount', function(e) {
[207] Fix | Delete
var d = e.data || null,
[208] Fix | Delete
o = self.options,
[209] Fix | Delete
done = function() {
[210] Fix | Delete
if (o[d.protocol] && typeof o[d.protocol].done == 'function') {
[211] Fix | Delete
o[d.protocol].done(self.fm, d);
[212] Fix | Delete
content.find('select,input').addClass('elfinder-tabstop');
[213] Fix | Delete
self.dialog.elfinderdialog('tabstopsInit');
[214] Fix | Delete
}
[215] Fix | Delete
};
[216] Fix | Delete
if (d && d.protocol) {
[217] Fix | Delete
if (d.mode && d.mode === 'redirect') {
[218] Fix | Delete
// To support of third-party cookie blocking (ITP) on CORS
[219] Fix | Delete
// On iOS and iPadOS 13.4 and Safari 13.1 on macOS, the session cannot be continued when redirecting OAuth in CORS mode
[220] Fix | Delete
self.fm.request({
[221] Fix | Delete
data : {cmd : 'netmount', protocol : d.protocol, host: d.host, user : 'init', pass : 'return', options: d.options},
[222] Fix | Delete
preventDefault : true
[223] Fix | Delete
}).done(function(data) {
[224] Fix | Delete
d = JSON.parse(data.body);
[225] Fix | Delete
done();
[226] Fix | Delete
});
[227] Fix | Delete
} else {
[228] Fix | Delete
done();
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
});
[232] Fix | Delete
[233] Fix | Delete
};
[234] Fix | Delete
[235] Fix | Delete
elFinder.prototype.commands.netunmount = function() {
[236] Fix | Delete
var self = this;
[237] Fix | Delete
[238] Fix | Delete
this.alwaysEnabled = true;
[239] Fix | Delete
this.updateOnSelect = false;
[240] Fix | Delete
[241] Fix | Delete
this.drivers = [];
[242] Fix | Delete
[243] Fix | Delete
this.handlers = {
[244] Fix | Delete
load : function() {
[245] Fix | Delete
this.drivers = this.fm.netDrivers;
[246] Fix | Delete
}
[247] Fix | Delete
};
[248] Fix | Delete
[249] Fix | Delete
this.getstate = function(sel) {
[250] Fix | Delete
var fm = this.fm,
[251] Fix | Delete
file;
[252] Fix | Delete
return !!sel && this.drivers.length && !this._disabled && (file = fm.file(sel[0])) && file.netkey ? 0 : -1;
[253] Fix | Delete
};
[254] Fix | Delete
[255] Fix | Delete
this.exec = function(hashes) {
[256] Fix | Delete
var self = this,
[257] Fix | Delete
fm = this.fm,
[258] Fix | Delete
dfrd = $.Deferred()
[259] Fix | Delete
.fail(function(error) {
[260] Fix | Delete
error && fm.error(error);
[261] Fix | Delete
}),
[262] Fix | Delete
drive = fm.file(hashes[0]),
[263] Fix | Delete
childrenRoots = function(hash) {
[264] Fix | Delete
var roots = [],
[265] Fix | Delete
work;
[266] Fix | Delete
if (fm.leafRoots) {
[267] Fix | Delete
work = [];
[268] Fix | Delete
$.each(fm.leafRoots, function(phash, hashes) {
[269] Fix | Delete
var parents = fm.parents(phash),
[270] Fix | Delete
idx, deep;
[271] Fix | Delete
if ((idx = $.inArray(hash, parents)) !== -1) {
[272] Fix | Delete
idx = parents.length - idx;
[273] Fix | Delete
$.each(hashes, function(i, h) {
[274] Fix | Delete
work.push({i: idx, hash: h});
[275] Fix | Delete
});
[276] Fix | Delete
}
[277] Fix | Delete
});
[278] Fix | Delete
if (work.length) {
[279] Fix | Delete
work.sort(function(a, b) { return a.i < b.i; });
[280] Fix | Delete
$.each(work, function(i, o) {
[281] Fix | Delete
roots.push(o.hash);
[282] Fix | Delete
});
[283] Fix | Delete
}
[284] Fix | Delete
}
[285] Fix | Delete
return roots;
[286] Fix | Delete
};
[287] Fix | Delete
[288] Fix | Delete
if (this._disabled) {
[289] Fix | Delete
return dfrd.reject();
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
if (dfrd.state() == 'pending') {
[293] Fix | Delete
fm.confirm({
[294] Fix | Delete
title : self.title,
[295] Fix | Delete
text : fm.i18n('confirmUnmount', drive.name),
[296] Fix | Delete
accept : {
[297] Fix | Delete
label : 'btnUnmount',
[298] Fix | Delete
callback : function() {
[299] Fix | Delete
var target = drive.hash,
[300] Fix | Delete
roots = childrenRoots(target),
[301] Fix | Delete
requests = [],
[302] Fix | Delete
removed = [],
[303] Fix | Delete
doUmount = function() {
[304] Fix | Delete
$.when(requests).done(function() {
[305] Fix | Delete
fm.request({
[306] Fix | Delete
data : {cmd : 'netmount', protocol : 'netunmount', host: drive.netkey, user : target, pass : 'dum'},
[307] Fix | Delete
notify : {type : 'netunmount', cnt : 1, hideCnt : true},
[308] Fix | Delete
preventFail : true
[309] Fix | Delete
})
[310] Fix | Delete
.fail(function(error) {
[311] Fix | Delete
dfrd.reject(error);
[312] Fix | Delete
})
[313] Fix | Delete
.done(function(data) {
[314] Fix | Delete
drive.volumeid && delete fm.volumeExpires[drive.volumeid];
[315] Fix | Delete
dfrd.resolve();
[316] Fix | Delete
});
[317] Fix | Delete
}).fail(function(error) {
[318] Fix | Delete
if (removed.length) {
[319] Fix | Delete
fm.remove({ removed: removed });
[320] Fix | Delete
}
[321] Fix | Delete
dfrd.reject(error);
[322] Fix | Delete
});
[323] Fix | Delete
};
[324] Fix | Delete
[325] Fix | Delete
if (roots.length) {
[326] Fix | Delete
fm.confirm({
[327] Fix | Delete
title : self.title,
[328] Fix | Delete
text : (function() {
[329] Fix | Delete
var msgs = ['unmountChildren'];
[330] Fix | Delete
$.each(roots, function(i, hash) {
[331] Fix | Delete
msgs.push([fm.file(hash).name]);
[332] Fix | Delete
});
[333] Fix | Delete
return msgs;
[334] Fix | Delete
})(),
[335] Fix | Delete
accept : {
[336] Fix | Delete
label : 'btnUnmount',
[337] Fix | Delete
callback : function() {
[338] Fix | Delete
$.each(roots, function(i, hash) {
[339] Fix | Delete
var d = fm.file(hash);
[340] Fix | Delete
if (d.netkey) {
[341] Fix | Delete
requests.push(fm.request({
[342] Fix | Delete
data : {cmd : 'netmount', protocol : 'netunmount', host: d.netkey, user : d.hash, pass : 'dum'},
[343] Fix | Delete
notify : {type : 'netunmount', cnt : 1, hideCnt : true},
[344] Fix | Delete
preventDefault : true
[345] Fix | Delete
}).done(function(data) {
[346] Fix | Delete
if (data.removed) {
[347] Fix | Delete
d.volumeid && delete fm.volumeExpires[d.volumeid];
[348] Fix | Delete
removed = removed.concat(data.removed);
[349] Fix | Delete
}
[350] Fix | Delete
}));
[351] Fix | Delete
}
[352] Fix | Delete
});
[353] Fix | Delete
doUmount();
[354] Fix | Delete
}
[355] Fix | Delete
},
[356] Fix | Delete
cancel : {
[357] Fix | Delete
label : 'btnCancel',
[358] Fix | Delete
callback : function() {
[359] Fix | Delete
dfrd.reject();
[360] Fix | Delete
}
[361] Fix | Delete
}
[362] Fix | Delete
});
[363] Fix | Delete
} else {
[364] Fix | Delete
requests = null;
[365] Fix | Delete
doUmount();
[366] Fix | Delete
}
[367] Fix | Delete
}
[368] Fix | Delete
},
[369] Fix | Delete
cancel : {
[370] Fix | Delete
label : 'btnCancel',
[371] Fix | Delete
callback : function() { dfrd.reject(); }
[372] Fix | Delete
}
[373] Fix | Delete
});
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
return dfrd;
[377] Fix | Delete
};
[378] Fix | Delete
[379] Fix | Delete
};
[380] Fix | Delete
[381] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function