mirror of
https://github.com/MCSManager/MCSManager.git
synced 2024-11-21 03:12:10 +08:00
65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
const ftpServerInterface = require('./ftpserver');
|
||
const userModel = require('../model/UserModel');
|
||
const permission = require('../helper/Permission');
|
||
const serverModel = require('../model/ServerModel');
|
||
|
||
ftpServerInterface.createFTPServer({
|
||
getInitialCwd: function () {
|
||
return '/';
|
||
},
|
||
getRoot: function (connected) {
|
||
let username = connected.username;
|
||
let arrName = username.split('.');
|
||
|
||
if (arrName.length != 2) return false;
|
||
|
||
let realName = arrName[0];
|
||
let serverName = arrName[1];
|
||
if (!realName || !serverName) return false;
|
||
|
||
let user = userModel.userCenter().get(realName);
|
||
//if (serverModel.ServerManager().isExist(serverName) && permission.isCanServer(realName, serverName)) {
|
||
|
||
let dataModel = serverModel.ServerManager().getServer(serverName).dataModel || null;
|
||
if (dataModel) return dataModel.cwd;
|
||
|
||
//}
|
||
// connected.close();
|
||
//return null;
|
||
|
||
// return process.cwd() + '/' + connected.username;
|
||
},
|
||
pasvPortRangeStart: 1025,
|
||
pasvPortRangeEnd: 1050,
|
||
tlsOptions: null,
|
||
allowUnauthorizedTls: false,
|
||
useWriteFile: false, //true 则客户端上传的文件将缓冲在内存中,然后使用写入磁盘writeFile。
|
||
useReadFile: false,
|
||
maxStatsAtOnce: 10,
|
||
// uploadMaxSlurpSize: uploadMaxSlurpSize // N/A unless 'useWriteFile' is true.
|
||
});
|
||
|
||
|
||
|
||
ftpServerInterface.initFTPServerListener({
|
||
loginCheck: (connection, username, password) => {
|
||
let usname = username || '';
|
||
let arrName = usname.split('.');
|
||
let serverName = arrName[1];
|
||
let userName = arrName[0];
|
||
if (serverModel.ServerManager().isExist(serverName) && permission.isCanServer(userName, serverName)) {
|
||
try {
|
||
return userModel.loginUser(userName, password);
|
||
} catch (e) {
|
||
return false;
|
||
}
|
||
}
|
||
return false;
|
||
},
|
||
error: () => {
|
||
return false;
|
||
}
|
||
});
|
||
|
||
//run
|
||
ftpServerInterface.runFTPServer(); |