From fd53a3d9c7efc776c6dcfba69d9cc88f9e67767c Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 18 Jul 2019 15:21:41 -0700 Subject: [PATCH] Added notification settings feature --- agents/meshinstall-initd.sh | 2 +- agents/modules_meshcore/amt-manage.js | 2 +- meshuser.js | 5 +++ package.json | 2 +- views/default-min.handlebars | 2 +- views/default.handlebars | 44 ++++++++++++++++++++++++++- 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/agents/meshinstall-initd.sh b/agents/meshinstall-initd.sh index 31a39b79..58f05148 100644 --- a/agents/meshinstall-initd.sh +++ b/agents/meshinstall-initd.sh @@ -34,7 +34,7 @@ stop() { pid=$( cat "$PIDFILE" ) if kill -0 $pid 2>/dev/null; then echo 'Stopping service…' >&2 - kill -16 $pid + kill -15 $pid echo 'Service stopped' >&2 else echo 'Service not running' diff --git a/agents/modules_meshcore/amt-manage.js b/agents/modules_meshcore/amt-manage.js index 7b7389a5..6d3b8a82 100644 --- a/agents/modules_meshcore/amt-manage.js +++ b/agents/modules_meshcore/amt-manage.js @@ -110,7 +110,7 @@ function AmtManager(agent, db, isdebug) { } // Sent to the entire group, no sessionid or userid specified. - if (notify != null) { agent.SendCommand({ "action": "msg", "type": "notify", "value": notify, "tag": "general" }); } + if (notify != null) { agent.SendCommand({ "action": "msg", "type": "notify", "value": notify, "tag": "general", "amtMessage": amtMessage }); } } // Launch LMS diff --git a/meshuser.js b/meshuser.js index e062cb18..3fcb5ed2 100644 --- a/meshuser.js +++ b/meshuser.js @@ -310,6 +310,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Send user information to web socket, this is the first thing we send try { ws.send(JSON.stringify({ action: 'userinfo', userinfo: parent.CloneSafeUser(parent.users[user._id]) })); } catch (ex) { } + // Send user web state + db.Get('ws' + user._id, function (err, docs) { + if (docs.length == 1) { try { ws.send(JSON.stringify({ action: 'event', event: { action: 'userWebState', state: docs[0].state, nolog: 1 } })); } catch (ex) { } } + }); + // We are all set, start receiving data ws._socket.resume(); }); diff --git a/package.json b/package.json index 3ae66b41..51f47f90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.8-d", + "version": "0.3.8-e", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default-min.handlebars b/views/default-min.handlebars index f4d7a6a5..2631e27c 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ - {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index dea7559a..c0f8ffcb 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -260,6 +260,7 @@

+ Notification Settings
Change password
Delete account
@@ -1432,6 +1433,8 @@ // Node was found, dispatch the message if (message.type == 'console') { p15consoleReceive(nodes[index], message.value); } // This is a console message. else if (message.type == 'notify') { // This is a notification message. + var n = getstore('notifications', 0); + if (((n & 8) == 0) && (message.amtMessage != null)) { break; } // Intel AMT desktop & terminal messages should be ignored. var n = { text: message.value, title: message.title, icon: message.icon }; if (message.nodeid != null) { n.nodeid = message.nodeid; } if (message.tag != null) { n.tag = message.tag; } @@ -1942,6 +1945,19 @@ if (index != -1) { var node = nodes[index]; + // Event the connection change if needed + var n = getstore('notifications', 0); + if (n & 2) { + if (((node.conn & 1) == 0) && ((message.event.conn & 1) != 0)) { addNotification({ text: 'Agent connected', title: node.name, icon: node.icon, nodeid: node._id }); } + if (((node.conn & 2) == 0) && ((message.event.conn & 2) != 0)) { addNotification({ text: 'Intel AMT detected', title: node.name, icon: node.icon, nodeid: node._id }); } + if (((node.conn & 4) == 0) && ((message.event.conn & 4) != 0)) { addNotification({ text: 'Intel AMT CIRA connected', title: node.name, icon: node.icon, nodeid: node._id }); } + } + if (n & 4) { + if (((node.conn & 1) != 0) && ((message.event.conn & 1) == 0)) { addNotification({ text: 'Agent disconnected', title: node.name, icon: node.icon, nodeid: node._id }); } + if (((node.conn & 2) != 0) && ((message.event.conn & 2) == 0)) { addNotification({ text: 'Intel AMT not detected', title: node.name, icon: node.icon, nodeid: node._id }); } + if (((node.conn & 4) != 0) && ((message.event.conn & 4) == 0)) { addNotification({ text: 'Intel AMT CIRA disconnected', title: node.name, icon: node.icon, nodeid: node._id }); } + } + // Change the node connection state node.conn = message.event.conn; node.pwr = message.event.pwr; @@ -6052,6 +6068,31 @@ return false; } + function account_showAccountNotifySettings() { + if (xxdialogMode) return false; + var x = ''; + x += '

Notification sound.
'; + x += '
Device connections.
'; + x += '
Device disconnections.
'; + x += '
Intel® AMT desktop and serial events.
'; + setDialogMode(2, "Notification Settings", 3, account_showAccountNotifySettingsEx, x); + var n = getstore('notifications', 0); + Q('p2notifyPlayNotifySound').checked = (n & 1); + Q('p2notifyIntelDeviceConnect').checked = (n & 2); + Q('p2notifyIntelDeviceDisconnect').checked = (n & 4); + Q('p2notifyIntelAmtKvmActions').checked = (n & 8); + return false; + } + + function account_showAccountNotifySettingsEx() { + var n = 0; + n += Q('p2notifyPlayNotifySound').checked ? 1 : 0; + n += Q('p2notifyIntelDeviceConnect').checked ? 2 : 0; + n += Q('p2notifyIntelDeviceDisconnect').checked ? 4 : 0; + n += Q('p2notifyIntelAmtKvmActions').checked ? 8 : 0; + putstore('notifications', n); + } + function account_showVerifyEmail() { if (xxdialogMode || (userinfo.emailVerified == true) || (serverinfo.emailcheck != true)) return false; var x = "Click ok to send a verification mail to:
" + EscapeHtml(userinfo.email) + "
Please wait a few minute to receive the verification."; @@ -7879,7 +7920,8 @@ notifications.unshift(n); setNotificationCount(notifications.length); clickNotificationIcon(true); - Q('chimes').play(); + var notifySettings = getstore('notifications', 0); + if (notifySettings & 1) { Q('chimes').play(); } // If web notifications are granted, use it. var notification = null;