Added maxRecordingDays option.
Ylian Saint-Hilaire committed
Aug 31, 2021 at 23:31 UTC
7fbdd97666b96610ce4f7aa8137e202e404d6f20
3 files changed
+24
-17
meshcentral-config-schema.json
+5
-4
@@ -677,10 +677,11 @@
677
"properties": {
678
"onlySelectedUsers": { "type": "boolean", "default": false, "description": "When enabled, only device users with the session recording feature turned on will be recorded. When false, all users are recorded." },
679
"onlySelectedDeviceGroups": { "type": "boolean", "default": false, "description": "When enabled, only device groups with the session recording feature turned on will be recorded. When false, all devices are recorded." },
680
- "filepath": { "type": "string" },
681
- "index": { "type": "boolean", "default": false },
682
- "maxRecordings": { "type": "integer" },
683
- "maxRecordingSizeMegabytes": { "type": "integer" },
680
+ "filepath": { "type": "string", "description": "The file path where recording files are kept." },
681
+ "index": { "type": "boolean", "default": false, "description": "If true, automatically index remote desktop recordings so that the plays can skip to any place in the file." },
682
+ "maxRecordings": { "type": "integer", "default": null, "description": "Maximum number of recording files to keep." },
683
+ "maxRecordingDays": { "type": "integer", "default": null, "description": "Maximum number of days to keep a recording." },
684
+ "maxRecordingSizeMegabytes": { "type": "integer", "default": null, "description": "Maximum number of recordings in megabytes. Once exceed, remove the oldest recordings." },
685
"protocols": { "type": "array", "uniqueItems": true, "items": { "type": "integer" }, "description": "This is an array: 1 = Terminal, 2 = Desktop, 5 = Files, 100 = Intel AMT WSMAN, 101 = Intel AMT Redirection, 200 = Messenger" }
686
},
687
"required": [ "protocols" ]
meshdesktopmultiplex.js
+11
-6
@@ -827,10 +827,10 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
827
828
// If there is a recording quota, remove any old recordings if needed
829
function cleanUpRecordings() {
830
- if ((parent.cleanUpRecordingsActive !== true) && domain.sessionrecording && ((typeof domain.sessionrecording.maxrecordings == 'number') || (typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number'))) {
830
+ if ((parent.cleanUpRecordingsActive !== true) && domain.sessionrecording && ((typeof domain.sessionrecording.maxrecordings == 'number') || (typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number') || (typeof domain.sessionrecording.maxrecordingdays == 'number'))) {
831
parent.cleanUpRecordingsActive = true;
832
setTimeout(function () {
833
- var recPath = null, fs = require('fs');
833
+ var recPath = null, fs = require('fs'), now = Date.now();
834
if (domain.sessionrecording.filepath) { recPath = domain.sessionrecording.filepath; } else { recPath = parent.parent.recordpath; }
835
fs.readdir(recPath, function (err, files) {
836
if ((err != null) || (files == null)) { delete parent.cleanUpRecordingsActive; return; }
@@ -838,22 +838,27 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
838
for (var i in files) {
839
if (files[i].endsWith('.mcrec')) {
840
var j = files[i].indexOf('-');
841
- if (j > 0) { recfiles.push({ n: files[i], r: files[i].substring(j + 1), s: fs.statSync(parent.parent.path.join(recPath, files[i])).size }); }
841
+ if (j > 0) {
842
+ var stats = null;
843
+ try { stats = fs.statSync(parent.parent.path.join(recPath, files[i])); } catch (ex) { }
844
+ if (stats != null) { recfiles.push({ n: files[i], r: files[i].substring(j + 1), s: stats.size, t: stats.mtimeMs }); }
845
+ }
846
}
847
}
848
recfiles.sort(function (a, b) { if (a.r < b.r) return 1; if (a.r > b.r) return -1; return 0; });
849
var totalFiles = 0, totalSize = 0;
850
for (var i in recfiles) {
851
var overQuota = false;
848
- if ((typeof domain.sessionrecording.maxrecordings == 'number') && (totalFiles >= domain.sessionrecording.maxrecordings)) { overQuota = true; }
849
- else if ((typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number') && (totalSize >= (domain.sessionrecording.maxrecordingsizemegabytes * 1048576))) { overQuota = true; }
852
+ if ((typeof domain.sessionrecording.maxrecordings == 'number') && (domain.sessionrecording.maxrecordings > 0) && (totalFiles >= domain.sessionrecording.maxrecordings)) { overQuota = true; }
853
+ else if ((typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number') && (domain.sessionrecording.maxrecordingsizemegabytes > 0) && (totalSize >= (domain.sessionrecording.maxrecordingsizemegabytes * 1048576))) { overQuota = true; }
854
+ else if ((typeof domain.sessionrecording.maxrecordingdays == 'number') && (domain.sessionrecording.maxrecordingdays > 0) && (((now - recfiles[i].t) / 1000 / 60 / 60 / 24) >= domain.sessionrecording.maxrecordingdays)) { overQuota = true; }
855
if (overQuota) { fs.unlinkSync(parent.parent.path.join(recPath, recfiles[i].n)); }
856
totalFiles++;
857
totalSize += recfiles[i].s;
858
}
859
delete parent.cleanUpRecordingsActive;
860
});
856
- });
861
+ }, 500);
862
}
863
}
864
meshrelay.js
+8
-7
@@ -935,10 +935,10 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
935
936
// If there is a recording quota, remove any old recordings if needed
937
function cleanUpRecordings() {
938
- if ((parent.cleanUpRecordingsActive !== true) && domain.sessionrecording && ((typeof domain.sessionrecording.maxrecordings == 'number') || (typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number'))) {
938
+ if ((parent.cleanUpRecordingsActive !== true) && domain.sessionrecording && ((typeof domain.sessionrecording.maxrecordings == 'number') || (typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number') || (typeof domain.sessionrecording.maxrecordingdays == 'number'))) {
939
parent.cleanUpRecordingsActive = true;
940
setTimeout(function () {
941
- var recPath = null, fs = require('fs');
941
+ var recPath = null, fs = require('fs'), now = Date.now();
942
if (domain.sessionrecording.filepath) { recPath = domain.sessionrecording.filepath; } else { recPath = parent.parent.recordpath; }
943
fs.readdir(recPath, function (err, files) {
944
if ((err != null) || (files == null)) { delete parent.cleanUpRecordingsActive; return; }
@@ -947,9 +947,9 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
947
if (files[i].endsWith('.mcrec')) {
948
var j = files[i].indexOf('-');
949
if (j > 0) {
950
- var size = null;
951
- try { size = fs.statSync(parent.parent.path.join(recPath, files[i])).size } catch (ex) { }
952
- if (size != null) { recfiles.push({ n: files[i], r: files[i].substring(j + 1), s: size }); }
950
+ var stats = null;
951
+ try { stats = fs.statSync(parent.parent.path.join(recPath, files[i])); } catch (ex) { }
952
+ if (stats != null) { recfiles.push({ n: files[i], r: files[i].substring(j + 1), s: stats.size, t: stats.mtimeMs }); }
953
}
954
}
955
}
@@ -957,8 +957,9 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
957
var totalFiles = 0, totalSize = 0;
958
for (var i in recfiles) {
959
var overQuota = false;
960
- if ((typeof domain.sessionrecording.maxrecordings == 'number') && (totalFiles >= domain.sessionrecording.maxrecordings)) { overQuota = true; }
961
- else if ((typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number') && (totalSize >= (domain.sessionrecording.maxrecordingsizemegabytes * 1048576))) { overQuota = true; }
960
+ if ((typeof domain.sessionrecording.maxrecordings == 'number') && (domain.sessionrecording.maxrecordings > 0) && (totalFiles >= domain.sessionrecording.maxrecordings)) { overQuota = true; }
961
+ else if ((typeof domain.sessionrecording.maxrecordingsizemegabytes == 'number') && (domain.sessionrecording.maxrecordingsizemegabytes > 0) && (totalSize >= (domain.sessionrecording.maxrecordingsizemegabytes * 1048576))) { overQuota = true; }
962
+ else if ((typeof domain.sessionrecording.maxrecordingdays == 'number') && (domain.sessionrecording.maxrecordingdays > 0) && (((now - recfiles[i].t) / 1000 / 60 / 60 / 24) >= domain.sessionrecording.maxrecordingdays)) { overQuota = true; }
963
if (overQuota) { fs.unlinkSync(parent.parent.path.join(recPath, recfiles[i].n)); }
964
totalFiles++;
965
totalSize += recfiles[i].s;