Added meshuser command handler functions
Noah Zalev committed
Jul 20, 2021 at 22:43 UTC
669878077dd1e829e13a4b03d3676c98ac6ce238
1 file changed
+64
-65
meshuser.js
+64
-65
@@ -635,28 +635,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
635
});
636
break;
637
}
638
- case 'serverstats':
639
- {
640
- // Only accept if the "My Server" tab is allowed for this domain
641
- if (domain.myserver === false) break;
642
-
643
- if ((user.siteadmin & 21) == 0) return; // Only site administrators with "site backup" or "site restore" or "site update" permissions can use this.
644
- if (common.validateInt(command.interval, 1000, 1000000) == false) {
645
- // Clear the timer
646
- if (obj.serverStatsTimer != null) { clearInterval(obj.serverStatsTimer); delete obj.serverStatsTimer; }
647
- } else {
648
- // Set the timer
649
- obj.SendServerStats();
650
- obj.serverStatsTimer = setInterval(obj.SendServerStats, command.interval);
651
- }
652
- break;
653
- }
654
- case 'meshes':
655
- {
656
- // Request a list of all meshes this user as rights to
657
- try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { }
658
- break;
659
- }
638
case 'nodes':
639
{
640
var links = [], extraids = null, err = null;
@@ -812,12 +790,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
790
});
791
break;
792
}
815
- case 'files':
816
- {
817
- // Send the full list of server files to the browser app
818
- updateUserFiles(user, ws, domain);
819
- break;
820
- }
793
case 'fileoperation':
794
{
795
// Check permissions
@@ -1060,22 +1032,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1032
});
1033
break;
1034
}
1063
- case 'users':
1064
- {
1065
- // Request a list of all users
1066
- if ((user.siteadmin & 2) == 0) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'users', responseid: command.responseid, result: 'Access denied' })); } catch (ex) { } } break; }
1067
- var docs = [];
1068
- for (i in parent.users) {
1069
- if (((obj.crossDomain === true) || (parent.users[i].domain == domain.id)) && (parent.users[i].name != '~')) {
1070
- // If we are part of a user group, we can only see other members of our own group
1071
- if ((obj.crossDomain === true) || (user.groups == null) || (user.groups.length == 0) || ((parent.users[i].groups != null) && (findOne(parent.users[i].groups, user.groups)))) {
1072
- docs.push(parent.CloneSafeUser(parent.users[i]));
1073
- }
1074
- }
1075
- }
1076
- try { ws.send(JSON.stringify({ action: 'users', users: docs, tag: command.tag })); } catch (ex) { }
1077
- break;
1078
- }
1035
case 'changelang':
1036
{
1037
// Do not allow this command when logged in using a login token
@@ -2400,18 +2356,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2356
});
2357
break;
2358
}
2403
- case 'serverversion':
2404
- {
2405
- // Do not allow this command when logged in using a login token
2406
- if (req.session.loginToken != null) break;
2407
-
2408
- // Check the server version
2409
- if ((user.siteadmin & 16) == 0) break;
2410
- if ((domain.myserver === false) || ((domain.myserver != null) && (domain.myserver !== true) && (domain.myserver.upgrade !== true))) break;
2411
- //parent.parent.getLatestServerVersion(function (currentVersion, latestVersion) { try { ws.send(JSON.stringify({ action: 'serverversion', current: currentVersion, latest: latestVersion })); } catch (ex) { } });
2412
- parent.parent.getServerTags(function (tags, err) { try { ws.send(JSON.stringify({ action: 'serverversion', tags: tags })); } catch (ex) { } });
2413
- break;
2414
- }
2359
case 'serverupdate':
2360
{
2361
// Do not allow this command when logged in using a login token
@@ -2424,14 +2368,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2368
parent.parent.performServerUpdate(command.version);
2369
break;
2370
}
2427
- case 'servererrors':
2428
- {
2429
- // Load the server error log
2430
- if ((user.siteadmin & 16) == 0) break;
2431
- if ((domain.myserver === false) || ((domain.myserver != null) && (domain.myserver !== true) && (domain.myserver.errorlog !== true))) break;
2432
- fs.readFile(parent.parent.getConfigFilePath('mesherrors.txt'), 'utf8', function (err, data) { try { ws.send(JSON.stringify({ action: 'servererrors', data: data })); } catch (ex) { } });
2433
- break;
2434
- }
2371
case 'serverclearerrorlog':
2372
{
2373
// Clear the server error log
@@ -5474,10 +5410,16 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5410
}
5411
5412
const serverCommands = {
5413
+ 'files': serverCommandFiles,
5414
'getnetworkinfo': serverCommandGetNetworkInfo,
5415
'getsysinfo': serverCommandGetSysInfo,
5416
'lastconnect': serverCommandLastConnect,
5480
- 'serverconsole': serverCommandServerConsole
5417
+ 'meshes': serverCommandMeshes,
5418
+ 'serverconsole': serverCommandServerConsole,
5419
+ 'servererrors': serverCommandServerErrors,
5420
+ 'serverstats': serverCommandServerStats,
5421
+ 'serverversion': serverCommandServerVersion,
5422
+ 'users': serverCommandUsers
5423
};
5424
5425
const serverUserCommands = {
@@ -5532,6 +5474,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5474
'webstats': [serverUserCommandWebStats, ""]
5475
};
5476
5477
+ function serverCommandFiles(command) {
5478
+ // Send the full list of server files to the browser app
5479
+ updateUserFiles(user, ws, domain);
5480
+ }
5481
+
5482
function serverCommandGetNetworkInfo(command) {
5483
if (!validNodeIdAndDomain(command)) return;
5484
@@ -5600,6 +5547,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5547
});
5548
}
5549
5550
+ function serverCommandMeshes(command) {
5551
+ // Request a list of all meshes this user as rights to
5552
+ try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { }
5553
+ }
5554
+
5555
function serverCommandServerConsole(command) {
5556
// Do not allow this command when logged in using a login token
5557
if (req.session.loginToken != null) return;
@@ -5623,6 +5575,53 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5575
if (cmdData.result != '') { try { ws.send(JSON.stringify({ action: 'serverconsole', value: cmdData.result, tag: command.tag })); } catch (ex) { } }
5576
}
5577
5578
+ function serverCommandServerErrors(command) {
5579
+ // Load the server error log
5580
+ if ((user.siteadmin & 16) == 0) return;
5581
+ if ((domain.myserver === false) || ((domain.myserver != null) && (domain.myserver !== true) && (domain.myserver.errorlog !== true))) return;
5582
+ fs.readFile(parent.parent.getConfigFilePath('mesherrors.txt'), 'utf8', function (err, data) { try { ws.send(JSON.stringify({ action: 'servererrors', data: data })); } catch (ex) { } });
5583
+ }
5584
+
5585
+ function serverCommandServerStats(command) {
5586
+ // Only accept if the "My Server" tab is allowed for this domain
5587
+ if (domain.myserver === false) return;
5588
+
5589
+ if ((user.siteadmin & 21) == 0) return; // Only site administrators with "site backup" or "site restore" or "site update" permissions can use this.
5590
+ if (common.validateInt(command.interval, 1000, 1000000) == false) {
5591
+ // Clear the timer
5592
+ if (obj.serverStatsTimer != null) { clearInterval(obj.serverStatsTimer); delete obj.serverStatsTimer; }
5593
+ } else {
5594
+ // Set the timer
5595
+ obj.SendServerStats();
5596
+ obj.serverStatsTimer = setInterval(obj.SendServerStats, command.interval);
5597
+ }
5598
+ }
5599
+
5600
+ function serverCommandServerVersion(command) {
5601
+ // Do not allow this command when logged in using a login token
5602
+ if (req.session.loginToken != null) return;
5603
+
5604
+ // Check the server version
5605
+ if ((user.siteadmin & 16) == 0) return;
5606
+ if ((domain.myserver === false) || ((domain.myserver != null) && (domain.myserver !== true) && (domain.myserver.upgrade !== true))) return;
5607
+ parent.parent.getServerTags(function (tags, err) { try { ws.send(JSON.stringify({ action: 'serverversion', tags: tags })); } catch (ex) { } });
5608
+ }
5609
+
5610
+ function serverCommandUsers(command) {
5611
+ // Request a list of all users
5612
+ if ((user.siteadmin & 2) == 0) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'users', responseid: command.responseid, result: 'Access denied' })); } catch (ex) { } } return; }
5613
+ var docs = [];
5614
+ for (i in parent.users) {
5615
+ if (((obj.crossDomain === true) || (parent.users[i].domain == domain.id)) && (parent.users[i].name != '~')) {
5616
+ // If we are part of a user group, we can only see other members of our own group
5617
+ if ((obj.crossDomain === true) || (user.groups == null) || (user.groups.length == 0) || ((parent.users[i].groups != null) && (findOne(parent.users[i].groups, user.groups)))) {
5618
+ docs.push(parent.CloneSafeUser(parent.users[i]));
5619
+ }
5620
+ }
5621
+ }
5622
+ try { ws.send(JSON.stringify({ action: 'users', users: docs, tag: command.tag })); } catch (ex) { }
5623
+ }
5624
+
5625
5626
function serverUserCommandHelp(cmdData) {
5627
var fin = '', f = '', availcommands = [];