mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-01-11 15:03:20 -05:00
DB record expire in config + Mesh folder optimizations
This commit is contained in:
parent
c83bf89a80
commit
8e835fcbb2
6
db.js
6
db.js
@ -35,6 +35,12 @@ module.exports.CreateDB = function (parent) {
|
|||||||
obj.identifier = null;
|
obj.identifier = null;
|
||||||
obj.dbKey = null;
|
obj.dbKey = null;
|
||||||
|
|
||||||
|
// Read expiration time from configuration file
|
||||||
|
if (typeof obj.parent.args.dbexpire == 'object') {
|
||||||
|
if (typeof obj.parent.args.dbexpire.events == 'number') { expireEventsSeconds = obj.parent.args.dbexpire.events; }
|
||||||
|
if (typeof obj.parent.args.dbexpire.powerevents == 'number') { expirePowerEventsSeconds = obj.parent.args.dbexpire.powerevents; }
|
||||||
|
}
|
||||||
|
|
||||||
if (obj.parent.args.mongodb) {
|
if (obj.parent.args.mongodb) {
|
||||||
// Use MongoDB
|
// Use MongoDB
|
||||||
obj.databaseType = 2;
|
obj.databaseType = 2;
|
||||||
|
22
meshuser.js
22
meshuser.js
@ -386,7 +386,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
case 'files':
|
case 'files':
|
||||||
{
|
{
|
||||||
// Send the full list of server files to the browser app
|
// Send the full list of server files to the browser app
|
||||||
if ((user != null) && (user.siteadmin != null) && (user.siteadmin & 8) != 0) { updateUserFiles(user, ws, domain); }
|
updateUserFiles(user, ws, domain);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'fileoperation':
|
case 'fileoperation':
|
||||||
@ -411,6 +411,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the entire mesh folder is empty, remove it.
|
||||||
|
// TODO: Should only check this when we deleted something in the mesh root folder.
|
||||||
|
try {
|
||||||
|
if (command.path[0].startsWith('mesh//')) {
|
||||||
|
path = meshPathToRealPath([command.path[0]], user);
|
||||||
|
obj.fs.readdir(path, function (err, dir) { if ((err == null) && (dir.length == 0)) { obj.fs.rmdir(path, function (err) { }); } });
|
||||||
|
}
|
||||||
|
} catch (ex) { }
|
||||||
}
|
}
|
||||||
else if ((command.fileop == 'rename') && (obj.common.IsFilenameValid(command.oldname) == true) && (obj.common.IsFilenameValid(command.newname) == true)) { try { obj.fs.renameSync(path + "/" + command.oldname, path + "/" + command.newname); } catch (e) { } } // Rename
|
else if ((command.fileop == 'rename') && (obj.common.IsFilenameValid(command.oldname) == true) && (obj.common.IsFilenameValid(command.newname) == true)) { try { obj.fs.renameSync(path + "/" + command.oldname, path + "/" + command.newname); } catch (e) { } } // Rename
|
||||||
else if ((command.fileop == 'copy') || (command.fileop == 'move')) {
|
else if ((command.fileop == 'copy') || (command.fileop == 'move')) {
|
||||||
@ -1981,6 +1990,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
};
|
};
|
||||||
|
|
||||||
function updateUserFiles(user, ws, domain) {
|
function updateUserFiles(user, ws, domain) {
|
||||||
|
if ((user == null) || (user.siteadmin == null) || ((user.siteadmin & 8) == 0)) return;
|
||||||
|
|
||||||
// Request the list of server files
|
// Request the list of server files
|
||||||
var files = { action: 'files', filetree: { n: 'Root', f: {} } };
|
var files = { action: 'files', filetree: { n: 'Root', f: {} } };
|
||||||
|
|
||||||
@ -1994,6 +2005,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
try {
|
try {
|
||||||
files.filetree.f[user._id].f = readFilesRec(obj.path.join(obj.parent.filespath, domainx + "/user-" + usersplit[2]));
|
files.filetree.f[user._id].f = readFilesRec(obj.path.join(obj.parent.filespath, domainx + "/user-" + usersplit[2]));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// TODO: We may want to fake this file structure until it's needed.
|
||||||
// Got an error, try to create all the folders and try again...
|
// Got an error, try to create all the folders and try again...
|
||||||
try { obj.fs.mkdirSync(obj.parent.filespath); } catch (e) { }
|
try { obj.fs.mkdirSync(obj.parent.filespath); } catch (e) { }
|
||||||
try { obj.fs.mkdirSync(obj.path.join(obj.parent.filespath, domainx)); } catch (e) { }
|
try { obj.fs.mkdirSync(obj.path.join(obj.parent.filespath, domainx)); } catch (e) { }
|
||||||
@ -2013,13 +2025,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
|
|
||||||
// Read all files recursively
|
// Read all files recursively
|
||||||
try {
|
try {
|
||||||
files.filetree.f[mesh._id].f = readFilesRec(obj.parent.path.join(__dirname, "files/" + domainx + "/mesh-" + meshsplit[2]));
|
files.filetree.f[mesh._id].f = readFilesRec(obj.parent.path.join(obj.parent.filespath, domainx + "/mesh-" + meshsplit[2]));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Got an error, try to create all the folders and try again...
|
files.filetree.f[mesh._id].f = {}; // Got an error, return empty folder. We will create the folder only when needed.
|
||||||
try { obj.fs.mkdirSync(obj.parent.filespath); } catch (e) { }
|
|
||||||
try { obj.fs.mkdirSync(obj.parent.path.join(obj.parent.filespath, domainx)); } catch (e) { }
|
|
||||||
try { obj.fs.mkdirSync(obj.parent.path.join(obj.parent.filespath, domainx + "/mesh-" + meshsplit[2])); } catch (e) { }
|
|
||||||
try { files.filetree.f[mesh._id].f = readFilesRec(obj.parent.path.join(obj.parent.filespath, domainx + "/mesh-" + meshsplit[2])); } catch (e) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "meshcentral",
|
"name": "meshcentral",
|
||||||
"version": "0.2.8-u",
|
"version": "0.2.8-v",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Remote Management",
|
"Remote Management",
|
||||||
"Intel AMT",
|
"Intel AMT",
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
"__comment__" : "This is a sample configuration file, edit a section and remove the _ in front of the name. Refer to the user's guide for details.",
|
"__comment__" : "This is a sample configuration file, edit a section and remove the _ in front of the name. Refer to the user's guide for details.",
|
||||||
"settings": {
|
"settings": {
|
||||||
"_MongoDb": "mongodb://127.0.0.1:27017/meshcentral",
|
"_MongoDb": "mongodb://127.0.0.1:27017/meshcentral",
|
||||||
"_MongoDbCol": "meshcentral",
|
|
||||||
"_WANonly": true,
|
"_WANonly": true,
|
||||||
"_LANonly": true,
|
"_LANonly": true,
|
||||||
"_Minify": 1,
|
"_Minify": 1,
|
||||||
"_SessionTime": 30,
|
"_SessionTime": 30,
|
||||||
"_SessionKey": "MyReallySecretPassword1",
|
"_SessionKey": "MyReallySecretPassword1",
|
||||||
"_DbEncryptKey": "MyReallySecretPassword2",
|
"_DbEncryptKey": "MyReallySecretPassword2",
|
||||||
|
"_DbExpire": { "events": 1728000, "powerevents": 864000 },
|
||||||
"_Port": 443,
|
"_Port": 443,
|
||||||
"_RedirPort": 80,
|
"_RedirPort": 80,
|
||||||
"_AllowLoginToken": true,
|
"_AllowLoginToken": true,
|
||||||
|
@ -1410,6 +1410,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
|||||||
// Get total bytes in the path
|
// Get total bytes in the path
|
||||||
var totalsize = readTotalFileSize(xfile.fullpath);
|
var totalsize = readTotalFileSize(xfile.fullpath);
|
||||||
if ((xfile.quota == null) || (totalsize < xfile.quota)) { // Check if the quota is not already broken
|
if ((xfile.quota == null) || (totalsize < xfile.quota)) { // Check if the quota is not already broken
|
||||||
|
|
||||||
|
// See if we need to create the folder
|
||||||
|
var domainx = 'domain';
|
||||||
|
if (domain.id.length > 0) { domainx = 'domain-' + usersplit[1]; }
|
||||||
|
try { obj.fs.mkdirSync(obj.parent.filespath); } catch (e) { }
|
||||||
|
try { obj.fs.mkdirSync(obj.parent.path.join(obj.parent.filespath, domainx)); } catch (e) { }
|
||||||
|
try { obj.fs.mkdirSync(xfile.fullpath); } catch (e) { }
|
||||||
|
|
||||||
if (fields.name != null) {
|
if (fields.name != null) {
|
||||||
// Upload method where all the file data is within the fields.
|
// Upload method where all the file data is within the fields.
|
||||||
var names = fields.name[0].split('*'), sizes = fields.size[0].split('*'), types = fields.type[0].split('*'), datas = fields.data[0].split('*');
|
var names = fields.name[0].split('*'), sizes = fields.size[0].split('*'), types = fields.type[0].split('*'), datas = fields.data[0].split('*');
|
||||||
|
Loading…
Reference in New Issue
Block a user