Added function handlers for getcookie,emailuser
Noah Zalev committed
Jan 9, 2022 at 21:14 UTC
6ce252482fd63a4c1f6c89cc37194e4ac98943d5
1 file changed
+40
-39
meshuser.js
+40
-39
@@ -3014,26 +3014,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3014
}
3015
break;
3016
}
3017
- case 'getcookie':
3018
- {
3019
- // Check if this user has rights on this nodeid
3020
- if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
3021
- parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
3022
- if ((node == null) || ((rights & MESHRIGHT_REMOTECONTROL) == 0) || (visible == false)) return; // Access denied.
3023
-
3024
- // Add a user authentication cookie to a url
3025
- var cookieContent = { userid: user._id, domainid: user.domain };
3026
- if (command.nodeid) { cookieContent.nodeid = command.nodeid; }
3027
- if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want the agent to TCP connect to a remote address
3028
- if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want the agent to TCP connect to a remote port
3029
- if (command.ip) { cookieContent.ip = command.ip; } // Indicates the browser want to agent to relay a TCP connection to a IP:port
3030
- if (node.mtype == 3) { cookieContent.lc = 1; command.localRelay = true; } // Indicate this is for a local connection
3031
- command.cookie = parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey);
3032
- command.trustedCert = parent.isTrustedCert(domain);
3033
- try { ws.send(JSON.stringify(command)); } catch (ex) { }
3034
- });
3035
- break;
3036
- }
3017
case 'inviteAgent':
3018
{
3019
var err = null, mesh = null;
@@ -3527,25 +3507,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3507
delete obj.hardwareKeyRegistrationRequest;
3508
break;
3509
}
3530
- case 'emailuser': { // Send a email message to a user
3531
- var errMsg = null, emailuser = null;
3532
- if (domain.mailserver == null) { errMsg = 'Email server not enabled'; }
3533
- else if ((user.siteadmin & 2) == 0) { errMsg = 'No user management rights'; }
3534
- else if (common.validateString(command.userid, 1, 2048) == false) { errMsg = 'Invalid userid'; }
3535
- else if (common.validateString(command.subject, 1, 1000) == false) { errMsg = 'Invalid subject message'; }
3536
- else if (common.validateString(command.msg, 1, 10000) == false) { errMsg = 'Invalid message'; }
3537
- else {
3538
- emailuser = parent.users[command.userid];
3539
- if (emailuser == null) { errMsg = 'Invalid userid'; }
3540
- else if (emailuser.email == null) { errMsg = 'No validated email address for this user'; }
3541
- else if (emailuser.emailVerified !== true) { errMsg = 'No validated email address for this user'; }
3542
- }
3543
-
3544
- if (errMsg != null) { displayNotificationMessage(errMsg); break; }
3545
- domain.mailserver.sendMail(emailuser.email, command.subject, command.msg);
3546
- displayNotificationMessage("Email sent.", null, null, null, 14);
3547
- break;
3548
- }
3510
case 'getClip': {
3511
if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
3512
@@ -4925,7 +4886,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4886
'changelang': serverCommandChangeLang,
4887
'close': serverCommandClose,
4888
'confirmPhone': serverCommandConfirmPhone,
4889
+ 'emailuser': serverCommandEmailUser,
4890
'files': serverCommandFiles,
4891
+ 'getcookie': serverCommandGetCookie,
4892
'getnetworkinfo': serverCommandGetNetworkInfo,
4893
'getsysinfo': serverCommandGetSysInfo,
4894
'intersession': serverCommandInterSession,
@@ -5703,11 +5666,49 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5666
parent.parent.DispatchEvent(['*', 'server-users', user._id], obj, event);
5667
}
5668
5669
+ function serverCommandEmailUser(command) {
5670
+ var errMsg = null, emailuser = null;
5671
+ if (domain.mailserver == null) { errMsg = 'Email server not enabled'; }
5672
+ else if ((user.siteadmin & 2) == 0) { errMsg = 'No user management rights'; }
5673
+ else if (common.validateString(command.userid, 1, 2048) == false) { errMsg = 'Invalid userid'; }
5674
+ else if (common.validateString(command.subject, 1, 1000) == false) { errMsg = 'Invalid subject message'; }
5675
+ else if (common.validateString(command.msg, 1, 10000) == false) { errMsg = 'Invalid message'; }
5676
+ else {
5677
+ emailuser = parent.users[command.userid];
5678
+ if (emailuser == null) { errMsg = 'Invalid userid'; }
5679
+ else if (emailuser.email == null) { errMsg = 'No validated email address for this user'; }
5680
+ else if (emailuser.emailVerified !== true) { errMsg = 'No validated email address for this user'; }
5681
+ }
5682
+
5683
+ if (errMsg != null) { displayNotificationMessage(errMsg); return; }
5684
+ domain.mailserver.sendMail(emailuser.email, command.subject, command.msg);
5685
+ displayNotificationMessage("Email sent.", null, null, null, 14);
5686
+ }
5687
+
5688
function serverCommandFiles(command) {
5689
// Send the full list of server files to the browser app
5690
updateUserFiles(user, ws, domain);
5691
}
5692
5693
+ function serverCommandGetCookie(command) {
5694
+ // Check if this user has rights on this nodeid
5695
+ if (common.validateString(command.nodeid, 1, 1024) == false) return; // Check nodeid
5696
+ parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
5697
+ if ((node == null) || ((rights & MESHRIGHT_REMOTECONTROL) == 0) || (visible == false)) return; // Access denied.
5698
+
5699
+ // Add a user authentication cookie to a url
5700
+ var cookieContent = { userid: user._id, domainid: user.domain };
5701
+ if (command.nodeid) { cookieContent.nodeid = command.nodeid; }
5702
+ if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want the agent to TCP connect to a remote address
5703
+ if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want the agent to TCP connect to a remote port
5704
+ if (command.ip) { cookieContent.ip = command.ip; } // Indicates the browser want to agent to relay a TCP connection to a IP:port
5705
+ if (node.mtype == 3) { cookieContent.lc = 1; command.localRelay = true; } // Indicate this is for a local connection
5706
+ command.cookie = parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey);
5707
+ command.trustedCert = parent.isTrustedCert(domain);
5708
+ try { ws.send(JSON.stringify(command)); } catch (ex) { }
5709
+ });
5710
+ }
5711
+
5712
function serverCommandGetNetworkInfo(command) {
5713
if (!validNodeIdAndDomain(command)) return;
5714