Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function searchServer(serverId) {
let serverInfo = await getServer(serverId)
if (serverInfo === null) {
console.error("serverInfo not found");
return
}
let client = createClient(serverInfo.url, serverInfo.username, serverInfo.password)
createClient.setFetchMethod(window.fetch);
/**
* returns Object:[]DirInfo
*/
let bfs = async function () {
let queue = ['/']
let foundDirectories = []
while (queue.length) {
let path = queue.shift()
// TODO: Implement depth better
if (path.split('/').length > SEARCH_DEPTH)
break; // We've exceeded search depth
let contents = await client.getDirectoryContents(path, { credentials: 'omit' });
let foundKDBXInDir = false;
public connect(username: string = null, password: string = null) {
// clear the promise that retrieves the root dir
this.currentlyGettingList = null;
this.fileList = null;
if (this.sessionService.getCurrentUser() != null) {
if (username === null && password == null) {
username = this.sessionService.getCurrentUser().cloudUserName;
password = this.sessionService.getCurrentUser().cloudPasswordDec;
}
this.client = webdav.createClient(
AppConfig.settings.webdav.remote_url,
{
username: username,
password: password
}
);
}
}
async uploadFileToWebdav(accountId, fileData, name) {
const uploadFolder = 'Rocket.Chat Uploads/';
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid User', { method: 'uploadFileToWebdav' });
}
if (!settings.get('Webdav_Integration_Enabled')) {
throw new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', { method: 'uploadFileToWebdav' });
}
const account = WebdavAccounts.findOne({ _id: accountId });
if (!account) {
throw new Meteor.Error('error-invalid-account', 'Invalid WebDAV Account', { method: 'uploadFileToWebdav' });
}
const client = createClient(
account.server_url,
{
username: account.username,
password: account.password,
}
);
const future = new Future();
// create buffer stream from file data
let bufferStream = new stream.PassThrough();
if (fileData) {
bufferStream.end(fileData);
} else {
bufferStream = null;
}
return getServer(serverId).then(serverInfo => {
if (serverInfo === null)
return []
let client = createClient(serverInfo.url, serverInfo.username, serverInfo.password)
createClient.setFetchMethod(window.fetch);
return client.getDirectoryContents(directory, { credentials: 'omit' }).then(contents => {
// map from directory contents to DBInfo type.
return contents.filter(element => {
return element.filename.indexOf('.kdbx') >= 1
}).map(element => {
return {
title: element.basename,
path: element.filename,
serverId: serverId
}
})
})
})
}
function addServer(url, username, password) {
let client = createClient(url, username, password)
createClient.setFetchMethod((a, b) => {
return window.fetch(a, b);
})
return client.getDirectoryContents('/', { credentials: 'omit' }).then(contents => {
// success!
let serverInfo = {
url: url,
username: username,
password: password
}
return settings.getSetWebdavServerList().then(serverList => {
serverList = serverList.length ? serverList : []
let matches = serverList.filter((elem, i, a) => {
return (elem.url == serverInfo.url
&& elem.username == serverInfo.username
&& elem.password == serverInfo.password)
})
var createLink = function (text, item, cell, selectedItems) {
var link = $('<a>');
// Calculate path
var path = text.substr(currentPath.length);
var href = text;
if (path === '') {
path = '.';
}
if (currentPath.length > text.length) {
path = '..';
}
if (item.getContentType() === File.TYPE.DIRECTORY) {
href = '#path=' + item.getPath();
link.click(function () {
self.dispatch(new SelectionEvent(item, true));
});
}
var selected = selectedItems.indexOf(item) >= 0;
// Checkbox
var checkbox = $('<input>');
checkbox.attr('type', 'checkbox');
checkbox.prop('checked', selected);
checkbox.click(function () {
var checked = checkbox.prop('checked');
self.dispatch(new SelectionEvent(item, checked));
});
cell.append(checkbox);</a>
var file = new File(response, rootPath);
if(file.getContentType() === File.TYPE.DIRECTORY) {
folders[file.getPath()] = file;
}
files.addItem(file);
});
// Artificially add the parent folder
var parentPath = PathUtil.getParentPath(self.getCurrentPath());
var parentFolder = folders[parentPath];
if(parentFolder) {
files.addItem(parentFolder);
}
// Sort
files.sort(File.COMPARATOR);
return files;
};
it("accepts an agent instance", function(done) {
const agent = new http.Agent({});
const client = createClient(
"http://localhost:" + createServer.test.port + "/webdav/server",
{
username: createServer.test.username,
password: createServer.test.password,
httpAgent: agent
}
);
client.readdir("/", (err, contents) => {
expect(err).to.be.null;
expect(contents).to.have.lengthOf(4);
done();
});
});
});
it("accepts an agent instance", function(done) {
const agent = new http.Agent({});
const client = createClient(
"http://localhost:" + createServer.test.port + "/webdav/server",
{
username: createServer.test.username,
password: createServer.test.password,
httpAgent: agent
}
);
client.readdir("/", (err, contents) => {
expect(err).to.be.null;
expect(contents).to.have.lengthOf(4);
done();
});
});
});
function createWebDAVClient() {
return createClient(
"http://localhost:" + createServer.test.port + "/webdav/server",
{
username: createServer.test.username,
password: createServer.test.password
}
)
}