Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
const createSourceClient = ({type, password, url, username}: Source) => {
let client
switch (type) {
case 'webdav':
client = createClient(url, {
username,
password,
})
break
}
return client
}
constructor(options) {
super(options);
const client = createClient(
options.connection.credentials.server,
{
username: options.connection.credentials.username,
password: options.connection.credentials.password,
}
);
options.getPath = function(file) {
if (options.uploadFolderPath[options.uploadFolderPath.length - 1] !== '/') {
options.uploadFolderPath += '/';
}
return options.uploadFolderPath + file._id;
};
client.stat(options.uploadFolderPath).catch(function(err) {
if (err.status === '404') {
async getWebdavFileList(accountId, path) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid User', { method: 'addNewWebdavAccount' });
}
if (!settings.get('Webdav_Integration_Enabled')) {
throw new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', { method: 'addNewWebdavAccount' });
}
const account = WebdavAccounts.findOne({ _id: accountId, user_id: Meteor.userId() });
if (!account) {
throw new Meteor.Error('error-invalid-account', 'Invalid WebDAV Account', { method: 'addNewWebdavAccount' });
}
const client = createClient(
account.server_url,
{
username: account.username,
password: account.password,
}
);
try {
const data = await client.getDirectoryContents(path);
return { success: true, data };
} catch (error) {
return { success: false, message: 'could-not-access-webdav', error };
}
},
});
constructor(serverConfig, cred) {
if (cred.token) {
this._client = createClient(
serverConfig,
{ token: cred.token },
);
} else {
this._client = createClient(
serverConfig,
{
username: cred.username,
password: cred.password,
},
);
}
}
export function getWebDAVConnection(remoteURL, username, password) {
const webdavClient = username
? createWebDAVClient(remoteURL, { username, password })
: createWebDAVClient(remoteURL);
return testRemoteFSConnection(webdavClient).then(() => wrapWebDAVClient(webdavClient));
}
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid User', { method: 'addWebdavAccount' });
}
if (!settings.get('Webdav_Integration_Enabled')) {
throw new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', { method: 'addWebdavAccount' });
}
check(formData, Match.ObjectIncluding({
serverURL: String,
username: String,
pass: String,
}));
const client = createClient(
formData.serverURL,
{
username: formData.username,
password: formData.pass,
}
);
try {
await client.stat('/');
} catch (error) {
return { success: false, message: 'could-not-access-webdav', error };
}
const accountData = {
user_id: userId,
server_url: formData.serverURL,
async getWebdavFileList(accountId, path) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid User', { method: 'addNewWebdavAccount' });
}
if (!settings.get('Webdav_Integration_Enabled')) {
throw new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', { method: 'addNewWebdavAccount' });
}
const account = WebdavAccounts.findOne({ _id: accountId, user_id: Meteor.userId() });
if (!account) {
throw new Meteor.Error('error-invalid-account', 'Invalid WebDAV Account', { method: 'addNewWebdavAccount' });
}
const client = createClient(
account.server_url,
{
username: account.username,
password: account.password,
}
);
try {
const data = await client.getDirectoryContents(path);
return { success: true, data };
} catch (error) {
return { success: false, message: 'could-not-access-webdav', error };
}
},
});