mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-24 06:05:53 -05:00
Added device events and admin change of user email
This commit is contained in:
parent
e90878364f
commit
17e5000ef8
1
db.js
1
db.js
@ -99,6 +99,7 @@ module.exports.CreateDB = function (args, datapath) {
|
||||
obj.StoreEvent = function (ids, source, event) { obj.file.insert(event); }
|
||||
obj.GetEvents = function (ids, domain, func) { if (obj.databaseType == 1) { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).exec(func); } else { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }, func) } }
|
||||
obj.GetEventsWithLimit = function (ids, domain, limit, func) { if (obj.databaseType == 1) { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit, func); } }
|
||||
obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { if (obj.databaseType == 1) { obj.file.find({ type: 'event', domain: domain, nodeid: nodeid }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit, func); } }
|
||||
obj.RemoveMesh = function (id) { obj.file.remove({ mesh: id }, { multi: true }); obj.file.remove({ _id: id }); obj.file.remove({ _id: 'nt' + id }); }
|
||||
obj.RemoveAllEvents = function (domain) { obj.file.remove({ type: 'event', domain: domain }, { multi: true }); }
|
||||
obj.MakeSiteAdmin = function (username, domain) { obj.Get('user/' + domain + '/' + username, function (err, docs) { if (docs.length == 1) { docs[0].siteadmin = 0xFFFFFFFF; obj.Set(docs[0]); } }); }
|
||||
|
37
meshuser.js
37
meshuser.js
@ -278,18 +278,34 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
|
||||
}
|
||||
case 'events':
|
||||
{
|
||||
// Setup the event filter
|
||||
var filter = user.subscriptions;
|
||||
// User filtered events
|
||||
if ((command.user != null) && ((user.siteadmin & 2) != 0)) { // SITERIGHT_MANAGEUSERS
|
||||
// TODO: Add the meshes command.user has access to
|
||||
filter = ['user/' + domain.id + '/' + command.user.toLowerCase()];
|
||||
}
|
||||
if ((command.limit == null) || (typeof command.limit != 'number')) {
|
||||
// Send the list of all events for this session
|
||||
obj.db.GetEvents(filter, domain.id, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } });
|
||||
} else {
|
||||
// TODO: Add the meshes command.user has access to (???)
|
||||
var filter = ['user/' + domain.id + '/' + command.user.toLowerCase()];
|
||||
if ((command.limit == null) || (typeof command.limit != 'number')) {
|
||||
// Send the list of all events for this session
|
||||
obj.db.GetEvents(filter, domain.id, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } });
|
||||
} else {
|
||||
// Send the list of most recent events for this session, up to 'limit' count
|
||||
obj.db.GetEventsWithLimit(filter, domain.id, command.limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } });
|
||||
}
|
||||
} else if (obj.common.validateString(command.nodeid, 0, 128) == true) { // Device filtered events
|
||||
// TODO: Check that the user has access to this nodeid
|
||||
var limit = 10000;
|
||||
if (obj.common.validateInt(command.limit, 1, 60000) == true) { limit = command.limit; }
|
||||
|
||||
// Send the list of most recent events for this session, up to 'limit' count
|
||||
obj.db.GetEventsWithLimit(filter, domain.id, command.limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } });
|
||||
obj.db.GetNodeEventsWithLimit(command.nodeid, domain.id, limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, nodeid: command.nodeid, tag: command.tag })); } catch (ex) { } });
|
||||
} else {
|
||||
// All events
|
||||
var filter = user.subscriptions;
|
||||
if ((command.limit == null) || (typeof command.limit != 'number')) {
|
||||
// Send the list of all events for this session
|
||||
obj.db.GetEvents(filter, domain.id, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } });
|
||||
} else {
|
||||
// Send the list of most recent events for this session, up to 'limit' count
|
||||
obj.db.GetEventsWithLimit(filter, domain.id, command.limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } });
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -443,6 +459,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
|
||||
var chguserid = 'user/' + domain.id + '/' + command.name.toLowerCase(), chguser = obj.parent.users[chguserid], change = 0;
|
||||
if (chguser) {
|
||||
if (obj.common.validateString(command.email, 1, 256) && (chguser.email != command.email)) { chguser.email = command.email; change = 1; }
|
||||
if ((command.emailVerified === true || command.emailVerified === false) && (chguser.emailVerified != command.emailVerified)) { chguser.emailVerified = command.emailVerified; change = 1; }
|
||||
if (obj.common.validateInt(command.quota, 0) && (command.quota != chguser.quota)) { chguser.quota = command.quota; if (chguser.quota == null) { delete chguser.quota; } change = 1; }
|
||||
if ((user.siteadmin == 0xFFFFFFFF) && obj.common.validateInt(command.siteadmin) && (chguser.siteadmin != command.siteadmin)) { chguser.siteadmin = command.siteadmin; change = 1 }
|
||||
if (change == 1) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "meshcentral",
|
||||
"version": "0.1.6-l",
|
||||
"version": "0.1.6-m",
|
||||
"keywords": [
|
||||
"Remote Management",
|
||||
"Intel AMT",
|
||||
|
@ -35,9 +35,10 @@
|
||||
<div id="cxterminal" class="cmtext" onclick="cmaction(2)">Terminal</div>
|
||||
<div id="cxdesktop" class="cmtext" onclick="cmaction(3)">Desktop</div>
|
||||
<div id="cxfiles" class="cmtext" onclick="cmaction(4)">Files</div>
|
||||
<div id="cxconsole" class="cmtext" onclick="cmaction(5)">Console</div>
|
||||
<div id="cxevents" class="cmtext" onclick="cmaction(5)">Events</div>
|
||||
<div id="cxconsole" class="cmtext" onclick="cmaction(6)">Console</div>
|
||||
<hr id="cxmgroupsplit" />
|
||||
<div id="cxmdesktop" class="cmtext" onclick="cmaction(6)" style=display:none>Multi-Desktop</div>
|
||||
<div id="cxmdesktop" class="cmtext" onclick="cmaction(7)" style=display:none>Multi-Desktop</div>
|
||||
</div>
|
||||
<div id="meshContextMenu" class="contextMenu" style="display: none; min-width: 0px">
|
||||
<div id="cxselectall" class="cmtext" onclick="cmmeshaction(1)">Select All</div>
|
||||
@ -82,6 +83,7 @@
|
||||
<td id=MainDevDesktop style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(11)>Desktop</td>
|
||||
<td id=MainDevTerminal style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(12)>Terminal</td>
|
||||
<td id=MainDevFiles style=width:100px;height:24px;cursor:pointer;display:none class=style3 onclick=go(13)>Files</td>
|
||||
<td id=MainDevEvents style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(16)>Events</td>
|
||||
<td id=MainDevAmt style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(14)>Intel® AMT</td>
|
||||
<td id=MainDevConsole style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(15)>Console</td>
|
||||
<td class=style3 style=height:24px> </td>
|
||||
@ -547,6 +549,28 @@
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div id=p16 style=display:none>
|
||||
<div id="p16title"><h1><span id=p16deviceName></span> - Events</h1></div>
|
||||
<div style=width:100%;height:24px;background-color:#d3d9d6;margin-bottom:4px>
|
||||
<div class=style7 style=width:16px;height:100%;float:left> </div>
|
||||
<div class=h1 style=height:100%;float:left> </div>
|
||||
<!--<div class=style14 style=height:100%;float:left> <input id=p31deleteall type=button style=display:none value="Delete All..." /> </div>-->
|
||||
<div class=style14 style=height:100%;float:left> <input type=button value=Refresh onclick=refreshDeviceEvents() /> </div>
|
||||
<div class="auto-style1" style="height:100%;float:right">
|
||||
Show
|
||||
<select id=p16limitdropdown onchange=refreshDeviceEvents()>
|
||||
<option value=60>Last 60</option>
|
||||
<option value=120>Last 120</option>
|
||||
<option value=250>Last 250</option>
|
||||
<option value=500>Last 500</option>
|
||||
<option value=1000>Last 1000</option>
|
||||
</select>
|
||||
<div style="height:100%;width:20px;float:right;background-color:#ffffff"></div>
|
||||
<div class=h2 style=height:100%;float:right> </div>
|
||||
</div>
|
||||
</div>
|
||||
<div id=p16events style="max-height:600px;overflow-y:scroll"></div>
|
||||
</div>
|
||||
<div id=p20 style=display:none>
|
||||
<h1><span id=p20meshName></span> - General</h1>
|
||||
<p id=p20info></p>
|
||||
@ -773,6 +797,7 @@
|
||||
QV('p13title', !(hide & 8));
|
||||
QV('p14title', !(hide & 8));
|
||||
QV('p15title', !(hide & 8));
|
||||
QV('p16title', !(hide & 8));
|
||||
}
|
||||
p1updateInfo();
|
||||
|
||||
@ -1073,7 +1098,10 @@
|
||||
break;
|
||||
}
|
||||
case 'events': {
|
||||
if ((message.user != null) && (message.user == currentUser.name)) {
|
||||
if ((message.nodeid != null) && (message.nodeid == currentNode._id)) {
|
||||
currentDeviceEvents = message.events;
|
||||
devevents_update();
|
||||
} else if ((message.user != null) && (message.user == currentUser.name)) {
|
||||
currentUserEvents = message.events;
|
||||
userEvents_update();
|
||||
} else {
|
||||
@ -2077,8 +2105,9 @@
|
||||
if (action == 2) gotoDevice(nodeid, 12); // Desktop
|
||||
if (action == 3) gotoDevice(nodeid, 11); // Terminal
|
||||
if (action == 4) gotoDevice(nodeid, 13); // Files
|
||||
if (action == 5) gotoDevice(nodeid, 15); // Console
|
||||
if (action == 6) { Q('viewselect').value = 3; Q('viewselect').onchange(); Q('autoConnectDesktopCheckbox').checked = true; Q('autoConnectDesktopCheckbox').onclick(); } // Multi-Desktop
|
||||
if (action == 5) gotoDevice(nodeid, 16); // Events
|
||||
if (action == 6) gotoDevice(nodeid, 15); // Console
|
||||
if (action == 7) { Q('viewselect').value = 3; Q('viewselect').onchange(); Q('autoConnectDesktopCheckbox').checked = true; Q('autoConnectDesktopCheckbox').onclick(); } // Multi-Desktop
|
||||
}
|
||||
|
||||
function cmmeshaction(action) {
|
||||
@ -2736,6 +2765,7 @@
|
||||
QH('p13deviceName', nname);
|
||||
QH('p14deviceName', nname);
|
||||
QH('p15deviceName', nname);
|
||||
QH('p16deviceName', nname);
|
||||
|
||||
// Node attributes
|
||||
var x = '<table style=width:100%>';
|
||||
@ -2892,6 +2922,9 @@
|
||||
// Reset the desktop tools
|
||||
QV('DeskTools', false);
|
||||
showDeskToolsProcesses();
|
||||
|
||||
// Ask for device events
|
||||
refreshDeviceEvents();
|
||||
}
|
||||
setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
|
||||
if (!panel) panel = 10;
|
||||
@ -4115,6 +4148,61 @@
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// DEVICE EVENTS
|
||||
//
|
||||
|
||||
var currentDeviceEvents = null;
|
||||
function devevents_update() {
|
||||
var x = '', dateHeader = null;
|
||||
for (var i in currentDeviceEvents) {
|
||||
var event = currentDeviceEvents[i];
|
||||
var time = new Date(event.time);
|
||||
if (time.toLocaleDateString() != dateHeader) {
|
||||
if (dateHeader != null) x += '</table>';
|
||||
x += '<table style=width:100% cellpadding=0 cellspacing=0><tr><td class=DevSt>' + time.toLocaleDateString() + '</td></tr>';
|
||||
dateHeader = time.toLocaleDateString();
|
||||
}
|
||||
var icon = 'si3';
|
||||
if (event.etype == 'user') icon = 'm2';
|
||||
if (event.etype == 'server') icon = 'si3';
|
||||
|
||||
var msg = event.msg.split('(R)').join('®');
|
||||
//if (event.username && event.username != userinfo.name) { msg += ': ' + event.username; }
|
||||
x += '<tr><td><div class=bar18 style=height:18px;width:100%;font-size:medium>';
|
||||
x += '<div style=float:left;height:18px;width:18px;background-color:white><div class=' + icon + ' style=width:16px;margin-top:1px;margin-left:2px;height:16px></div></div>';
|
||||
x += '<div class=g1 style=height:18px;float:left></div><div class=g2 style=height:18px;float:right></div>';
|
||||
x += '<div style=font-size:14px><span style=width:300px>' + time.toLocaleTimeString() + ' - ' + msg + '</span></div></div></td></tr>';
|
||||
}
|
||||
if (dateHeader != null) x += '</table>';
|
||||
if (x == '') x = "<br><i>No Events Found</i><br><br>";
|
||||
QH('p16events', x);
|
||||
}
|
||||
|
||||
/*
|
||||
function showDeleteAllEventsDialog() {
|
||||
if (xxdialogMode) return;
|
||||
var x = "Delete all events in the server event log?<br /><br />";
|
||||
x += "<input id=p3check type=checkbox onchange=validateDeleteAllEventsDialog() />Confirm";
|
||||
setDialogMode(2, "Delete All Events", 3, showDeleteAllEventsDialogEx, x);
|
||||
validateDeleteAllEventsDialog();
|
||||
}
|
||||
|
||||
function validateDeleteAllEventsDialog() {
|
||||
QE('idx_dlgOkButton', Q('p3check').checked);
|
||||
}
|
||||
|
||||
function showDeleteAllEventsDialogEx(buttons, tag) {
|
||||
meshserver.send({ action: 'clearevents' });
|
||||
}
|
||||
*/
|
||||
|
||||
function refreshDeviceEvents() {
|
||||
//currentDeviceEvents = null;
|
||||
//QH('p16events', '');
|
||||
meshserver.send({ action: 'events', nodeid: currentNode._id, limit: parseInt(p16limitdropdown.value) });
|
||||
}
|
||||
|
||||
//
|
||||
// CONSOLE
|
||||
//
|
||||
@ -4292,7 +4380,7 @@
|
||||
Q('dp2email').focus();
|
||||
}
|
||||
|
||||
function account_validateEmail(e) {
|
||||
function account_validateEmail(e, email) {
|
||||
var x = Q('dp2email').value.split('@');
|
||||
x = (x.length == 2) && (x[0].length > 0) && (x[1].split('.').length > 1) && (x[1].length > 2) && (Q('dp2email').value.length < 1024) && (Q('dp2email').value != userinfo.email);
|
||||
QE('idx_dlgOkButton', x);
|
||||
@ -5061,11 +5149,13 @@
|
||||
|
||||
// Show user attributes
|
||||
var x = '<div style=min-height:80px><table style=width:100%>';
|
||||
if (user.email) x += addDeviceAttribute('Email', '<a style=cursor:pointer onclick=doemail(event,\"' + user.email + '\")>' + EscapeHtml(user.email) + '</a>');
|
||||
x += addDeviceAttribute('Creation', new Date(user.creation).toLocaleString());
|
||||
if (user.login) x += addDeviceAttribute('Last Login', new Date(user.login).toLocaleString());
|
||||
var email = user.email?EscapeHtml(user.email):'<i>Not set</i>', everify = '';
|
||||
if (serverinfo.emailcheck) { everify = ((user.emailVerified == true)?'':', Unverified'); }
|
||||
x += addDeviceAttribute('Email', "<a style=cursor:pointer onclick=p30showUserEmailChangeDialog(event,\"" + userid + "\")>" + email + everify + '</a> <a style=cursor:pointer onclick=doemail(event,\"' + user.email + '\")><img src="images/link1.png" /></a>');
|
||||
x += addDeviceAttribute('Server Rights', "<a style=cursor:pointer onclick=showUserAdminDialog(event,\"" + userid + "\")>" + msg + "</a>");
|
||||
if (user.quota) x += addDeviceAttribute('Server Quota', EscapeHtml(parseInt(user.quota) / 1024) + ' k');
|
||||
x += addDeviceAttribute('Creation', new Date(user.creation).toLocaleString());
|
||||
if (user.login) x += addDeviceAttribute('Last Login', new Date(user.login).toLocaleString());
|
||||
|
||||
x += '</table></div><br />';
|
||||
|
||||
@ -5104,6 +5194,34 @@
|
||||
refreshUsersEvents();
|
||||
}
|
||||
|
||||
// Display the user's email change dialog box
|
||||
function p30showUserEmailChangeDialog(event) {
|
||||
if (xxdialogMode) return;
|
||||
var x = '';
|
||||
x += addHtmlValue('Email', '<input id=dp30email style=width:230px maxlength=32 onchange=p30validateEmail() onkeyup=p30validateEmail() />');
|
||||
if (serverinfo.emailcheck) { x += addHtmlValue('Status', '<select id=dp30verified style=width:230px onchange=p30validateEmail()><option value=0>Not verified</option><option value=1>Verified</option></select>'); }
|
||||
setDialogMode(2, "Change Email for " + EscapeHtml(currentUser.name), 3, p30showUserEmailChangeDialogEx, x);
|
||||
Q('dp30email').focus();
|
||||
Q('dp30email').value = currentUser.email;
|
||||
if (serverinfo.emailcheck) { Q('dp30verified').value = currentUser.emailVerified?1:0; }
|
||||
p30validateEmail();
|
||||
}
|
||||
|
||||
// Perform validation on the user's email change dialog box
|
||||
function p30validateEmail() {
|
||||
var v = Q('dp30email').value, x = v.split('@');
|
||||
x = (x.length == 2) && (x[0].length > 0) && (x[1].split('.').length > 1) && (x[1].length > 2) && (v.length < 1024) && ((v != userinfo.email) || ((serverinfo.emailcheck == true) && (Q('dp30verified').value != (userinfo.emailVerified?1:0))));
|
||||
QE('idx_dlgOkButton', x);
|
||||
}
|
||||
|
||||
// Send to the server the new user's email address and validation status
|
||||
function p30showUserEmailChangeDialogEx() {
|
||||
var x = { action: 'edituser', name: currentUser.name, email: Q('dp30email').value };
|
||||
if (serverinfo.emailcheck) { x.emailVerified = (Q('dp30verified').value == 1); }
|
||||
meshserver.send(x);
|
||||
}
|
||||
|
||||
// Display the user's password change dialog box
|
||||
function p30showUserChangePassDialog() {
|
||||
if (xxdialogMode) return;
|
||||
var x = '';
|
||||
@ -5464,6 +5582,7 @@
|
||||
QS('MainDevDesktop').backgroundColor = ((x == 11) ? "#003366" : "#808080");
|
||||
QS('MainDevTerminal').backgroundColor = ((x == 12) ? "#003366" : "#808080");
|
||||
QS('MainDevFiles').backgroundColor = ((x == 13) ? "#003366" : "#808080");
|
||||
QS('MainDevEvents').backgroundColor = ((x == 16) ? "#003366" : "#808080");
|
||||
QS('MainDevAmt').backgroundColor = ((x == 14) ? "#003366" : "#808080");
|
||||
QS('MainDevConsole').backgroundColor = ((x == 15) ? "#003366" : "#808080");
|
||||
QV('MeshSubMenuSpan', x >= 20 && x < 30);
|
||||
|
Loading…
Reference in New Issue
Block a user