Improved Windows agent crash logs and mobile phone login page

Ylian Saint-Hilaire committed May 23, 2018 at 21:43 UTC 098841fdc151afd88af5ca8f3ee4a20a1cb73246
12 files changed +129 -143
agents/MeshCmd-signed.exe
Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ
agents/MeshCmd64-signed.exe
Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ
agents/MeshService-signed.exe
Binary files a/agents/MeshService-signed.exe and b/agents/MeshService-signed.exe differ
agents/MeshService.exe
Binary files a/agents/MeshService.exe and b/agents/MeshService.exe differ
agents/MeshService64-signed.exe
Binary files a/agents/MeshService64-signed.exe and b/agents/MeshService64-signed.exe differ
agents/MeshService64.exe
Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.1.7-r",
3 + "version": "0.1.7-s",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
public/images/mainwelcome-90.png
Binary files /dev/null and b/public/images/mainwelcome-90.png differ
views/login-mobile.handlebars
+51 -53
@@ -29,23 +29,19 @@
29 <div id=container>
30 <div id=mastheadx></div>
31 <div id=masthead style="background-color:#036;background-repeat:no-repeat;height:50px;width:100%;overflow:hidden">
32 - <div style="float:left;height:66px;color:#c8c8c8;padding-left:10px;padding-top:4px">
32 + <div style="float:left;height:66px;color:#c8c8c8;padding-left:10px;padding-top:6px">
33 <strong><font style="font-size:36px;font-family:Arial,Helvetica,sans-serif">{{{title}}}</font></strong>
34 </div>
35 - <div style="float:left;height:66px;color:#c8c8c8;padding-left:5px;padding-top:7px">
35 + <div style="float:left;height:66px;color:#c8c8c8;padding-left:5px;padding-top:10px">
36 <strong><font style="font-size:12px;font-family:Arial,Helvetica,sans-serif">{{{title2}}}</font></strong>
37 </div>
38 </div>
39 - <div id=page_content style="overflow-y:scroll;position:absolute;bottom:32px;top:50px">
40 - <div id=column_l style="padding:10px">
41 - <div align=center>
42 - <img alt="" src=images/icons50.png width=300 height=50 />
43 - </div>
44 - <p>Connect to your devices anywhere using MeshCentral, the remote monitoring and management web site. Get started by creating an account if you don't have one already.</p>
45 - <table style=width:100%>
39 + <div id=page_content style="overflow-y:scroll;position:absolute;bottom:32px;top:50px;width:100%;display:flex;align-items:center">
40 + <div id=column_l style="padding:10px;width:100%">
41 + <table style="width:100%">
42 <tr>
43 <td align=center>
48 - <div id=loginpanel style="background-color:#979797;border-radius:16px;width:260px;padding:16px;text-align:center;display:none">
44 + <div id=loginpanel style="background-color:#979797;border-radius:16px;width:260px;padding:16px;text-align:center;clear:both;display:none">
45 <form action="login" method=post>
46 <div id=message1>
47 {{{message}}}
@@ -76,50 +72,52 @@
72 </div>
73 </form>
74 </div>
79 - <div id=createpanel style="background-color: #979797;border-radius:16px;width:260px;padding:16px;text-align:center;display:none">
80 - <form action=createaccount method=post>
81 - <div id=message2>
82 - {{{message}}}
83 - </div>
84 - <div>
85 - <b>Account Creation</b>
86 - </div>
87 - <table>
88 - <tr>
89 - <td align=right width=100>Username:</td>
90 - <td><input id=ausername type=text name=username onchange=validateCreate(1) maxlength=64 onkeydown=haltReturn(event) onkeyup=validateCreate(1,event) /></td>
91 - </tr>
92 - <tr>
93 - <td align=right width=100>Email:</td>
94 - <td><input id=aemail type=text name=email onchange=validateCreate(2) maxlength=256 onkeydown=haltReturn(event) onkeyup=validateCreate(2,event) /></td>
95 - </tr>
96 - <tr>
97 - <td align=right>Password:</td>
98 - <td><input id=apassword1 type=password name=password1 autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(3) onkeyup=validateCreate(3,event) /></td>
99 - </tr>
100 - <tr>
101 - <td align=right>Password:</td>
102 - <td><input id=apassword2 type=password name=password2 autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(4) onkeyup=validateCreate(4,event) /></td>
103 - </tr>
104 - <tr>
105 - <td align=right>Pass Hint:</td>
106 - <td><input id=apasswordhint type=text name=apasswordhint autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(5) onkeyup=validateCreate(5,event) /></td>
107 - </tr>
108 - <tr id=newAccountPass title="Enter the account creation token">
109 - <td align=right>Creation Token:</td>
110 - <td><input id=anewaccountpass type=password name=anewaccountpass autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(6) onkeyup=validateCreate(6,event) /></td>
111 - </tr>
112 - <tr>
113 - <td colspan=2>
114 - <div style=float:right><input id=createButton type=submit value="Create Account" disabled="disabled" /></div>
115 - <div id=passWarning style="padding-top:6px"></div>
116 - </td>
117 - </tr>
118 - </table>
119 - <hr /><a onclick=xgo(1) style=cursor:pointer>Back to login</a>
120 - </form>
75 + <div id=createpanel style="display:none">
76 + <div style="background-color: #979797;border-radius:16px;width:260px;padding:16px;text-align:center;clear:both">
77 + <form action=createaccount method=post>
78 + <div id=message2>
79 + {{{message}}}
80 + </div>
81 + <div>
82 + <b>Account Creation</b>
83 + </div>
84 + <table>
85 + <tr>
86 + <td align=right width=100>Username:</td>
87 + <td><input id=ausername type=text name=username onchange=validateCreate(1) maxlength=64 onkeydown=haltReturn(event) onkeyup=validateCreate(1,event) /></td>
88 + </tr>
89 + <tr>
90 + <td align=right width=100>Email:</td>
91 + <td><input id=aemail type=text name=email onchange=validateCreate(2) maxlength=256 onkeydown=haltReturn(event) onkeyup=validateCreate(2,event) /></td>
92 + </tr>
93 + <tr>
94 + <td align=right>Password:</td>
95 + <td><input id=apassword1 type=password name=password1 autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(3) onkeyup=validateCreate(3,event) /></td>
96 + </tr>
97 + <tr>
98 + <td align=right>Password:</td>
99 + <td><input id=apassword2 type=password name=password2 autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(4) onkeyup=validateCreate(4,event) /></td>
100 + </tr>
101 + <tr>
102 + <td align=right>Pass Hint:</td>
103 + <td><input id=apasswordhint type=text name=apasswordhint autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(5) onkeyup=validateCreate(5,event) /></td>
104 + </tr>
105 + <tr id=newAccountPass title="Enter the account creation token">
106 + <td align=right>Creation Token:</td>
107 + <td><input id=anewaccountpass type=password name=anewaccountpass autocomplete=off maxlength=256 onkeydown=haltReturn(event) onchange=validateCreate(6) onkeyup=validateCreate(6,event) /></td>
108 + </tr>
109 + <tr>
110 + <td colspan=2>
111 + <div style=float:right><input id=createButton type=submit value="Create Account" disabled="disabled" /></div>
112 + <div id=passWarning style="padding-top:6px"></div>
113 + </td>
114 + </tr>
115 + </table>
116 + <hr /><a onclick=xgo(1) style=cursor:pointer>Back to login</a>
117 + </form>
118 + </div>
119 </div>
122 - <div id=resetpanel style="background-color: #979797;border-radius:16px;width:260px;padding:16px;text-align:center;display:none">
120 + <div id=resetpanel style="background-color: #979797;border-radius:16px;width:260px;padding:16px;text-align:center;display:none;clear:both">
121 <form action=resetaccount method=post>
122 <div id=message3>
123 {{{message}}}
views/terms-mobile.handlebars
+2 -8
@@ -24,7 +24,7 @@
24 }
25 </style>
26 </head>
27 -<body onload="if (typeof(startup) !== 'undefined') startup();" style="overflow-y:hidden;margin:0;padding:0;border:0;color:black;font-size:13px;font-family:\'Trebuchet MS\', Arial, Helvetica, sans-serif">
27 +<body onload="if (typeof(startup) !== 'undefined') startup();" style="overflow-y:hidden;max-width:100%;margin:0;padding:0;border:0;color:black;font-size:13px;font-family:\'Trebuchet MS\', Arial, Helvetica, sans-serif">
28 <div id="container">
29 <!-- Begin Masthead -->
30 <div id=masthead style="background-color:#036;background-repeat:no-repeat;height:50px;width:100%;overflow:hidden">
@@ -146,12 +146,6 @@
146 <p class="MsoNormal">
147 <span>This software uses code from <a href="http://www.webtoolkit.info/javascript-base64.html">http://www.webtoolkit.info/javascript-base64.html</a> licensed under the <a href="http://creativecommons.org/licenses/by/2.0/uk/legalcode">http://creativecommons.org/licenses/by/2.0/uk/legalcode</a> and its source can be downloaded from <a href="http://www.webtoolkit.info/javascript-base64.html">http://www.webtoolkit.info/javascript-base64.html</a>.<o:p></o:p></span>
148 </p>
149 - <p class="MsoNormal">
150 - <b>8.Android LibJPEG</b>
151 - </p>
152 - <p class="MsoNormal">
153 - This software uses code from <span style="color:#1F497D"><a href="https://github.com/android/platform_external_jpeg">https://github.com/android/platform_external_jpeg</a> </span>licensed under<span style="color:#1F497D"> <a href="https://github.com/android/platform_external_jpeg/blob/master/NOTICE">https://github.com/android/platform_external_jpeg/blob/master/NOTICE</a><o:p></o:p></span>
154 - </p>
149 <br />
150 </div>
151 </div>
@@ -159,7 +153,7 @@
153 <table cellpadding=0 cellspacing=6 style=width:100%>
154 <tr>
155 <td style=text-align:left;color:white>{{{footer}}}</td>
162 - <td style=text-align:right>{{{rootCertLink}}}&nbsp;<a href="/">Login</a></td>
156 + <td style=text-align:right>{{{rootCertLink}}}&nbsp;<a href="/">Back</a></td>
157 </tr>
158 </table>
159 </div>
views/terms.handlebars
+1 -7
@@ -131,12 +131,6 @@
131 <p class="MsoNormal">
132 <span>This software uses code from <a href="http://www.webtoolkit.info/javascript-base64.html">http://www.webtoolkit.info/javascript-base64.html</a> licensed under the <a href="http://creativecommons.org/licenses/by/2.0/uk/legalcode">http://creativecommons.org/licenses/by/2.0/uk/legalcode</a> and its source can be downloaded from <a href="http://www.webtoolkit.info/javascript-base64.html">http://www.webtoolkit.info/javascript-base64.html</a>.<o:p></o:p></span>
133 </p>
134 - <p class="MsoNormal">
135 - <b>8.Android LibJPEG</b>
136 - </p>
137 - <p class="MsoNormal">
138 - This software uses code from <span style="color:#1F497D"><a href="https://github.com/android/platform_external_jpeg">https://github.com/android/platform_external_jpeg</a> </span>licensed under<span style="color:#1F497D"> <a href="https://github.com/android/platform_external_jpeg/blob/master/NOTICE">https://github.com/android/platform_external_jpeg/blob/master/NOTICE</a><o:p></o:p></span>
139 - </p>
134 <br />
135 </div>
136 </div>
@@ -144,7 +138,7 @@
138 <table cellpadding="0" cellspacing="10" style="width: 100%">
139 <tr>
140 <td style="text-align:left"></td>
147 - <td style="text-align:right"><a href="/">Login</a></td>
141 + <td style="text-align:right"><a href="/">Back</a></td>
142 </tr>
143 </table>
144 </div>
webserver.js
+74 -74
@@ -55,7 +55,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
55 obj.meshRelayHandler = require('./meshrelay.js')
56 obj.meshUserHandler = require('./meshuser.js')
57 obj.interceptor = require('./interceptor');
58 -
58 +
59 // Variables
60 obj.parent = parent;
61 obj.filespath = parent.filespath;
@@ -119,7 +119,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
119 obj.sessionsCount = {}; // Merged session counters, used when doing server peering. UserId --> SessionCount
120 obj.wsrelays = {}; // Id -> Relay
121 obj.wsPeerRelays = {}; // Id -> { ServerId, Time }
122 -
122 +
123 // Setup randoms
124 obj.crypto.randomBytes(48, function (err, buf) { obj.httpAuthRandom = buf; });
125 obj.crypto.randomBytes(16, function (err, buf) { obj.httpAuthRealm = buf.toString('hex'); });
@@ -147,7 +147,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
147 obj.tlsServer = require('https').createServer(tlsOptions, obj.app);
148 obj.expressWs = require('express-ws')(obj.app, obj.tlsServer);
149 }
150 -
150 +
151 // Setup middleware
152 obj.app.engine('handlebars', obj.exphbs({})); // defaultLayout: 'main'
153 obj.app.set('view engine', 'handlebars');
@@ -157,7 +157,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
157 saveUninitialized: false, // don't create session until something stored
158 secret: secret // If multiple instances of this server are behind a load-balancer, this secret must be the same for all instances
159 }));
160 -
160 +
161 // Session-persisted message middleware
162 obj.app.use(function (req, res, next) {
163 if (req.session != null) {
@@ -187,7 +187,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
187 }
188 }
189 });
190 -
190 +
191 // Fetch all meshes from the database, keep this in memory
192 obj.db.GetAllType('mesh', function (err, docs) { for (var i in docs) { obj.meshes[docs[i]._id] = docs[i]; } });
193
@@ -279,7 +279,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
279 if ((d != null) && (d.dns == null)) return parent.config.domains[x[1].toLowerCase()];
280 return parent.config.domains[''];
281 }
282 -
282 +
283 function handleLogoutRequest(req, res) {
284 var domain = checkUserIpAddress(req, res);
285 if (domain == null) return;
@@ -293,7 +293,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
293 res.redirect(domain.url);
294 });
295 }
296 -
296 +
297 function handleLoginRequest(req, res) {
298 var domain = checkUserIpAddress(req, res);
299 if (domain == null) return;
@@ -345,7 +345,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
345 }
346 });
347 }
348 -
348 +
349 function handleCreateAccountRequest(req, res) {
350 var domain = checkUserIpAddress(req, res);
351 if (domain == null) return;
@@ -479,7 +479,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
479 res.render(obj.path.join(__dirname, 'views/message'), { title: domain.title, title2: domain.title2, title3: 'Account Verification', message: 'Verified email <b>' + EscapeHtml(user.email) + '</b> for user account <b>' + EscapeHtml(user.name) + '</b>. <a href="' + domain.url + '">Go to login page</a>.' });
480
481 // Send a notification
482 - obj.parent.DispatchEvent([user._id], obj, { action: 'notify', value: 'Email verified:<br /><b>' + EscapeHtml(userinfo.email) + '</b>.' , nolog: 1 })
482 + obj.parent.DispatchEvent([user._id], obj, { action: 'notify', value: 'Email verified:<br /><b>' + EscapeHtml(userinfo.email) + '</b>.', nolog: 1 })
483 }
484 });
485 }
@@ -538,7 +538,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
538 if (!req.session || !req.session.userid || !req.body.apassword1 || (req.body.apassword1 != req.body.apassword2) || (req.session.domainid != domain.id)) { res.redirect(domain.url); return; }
539 var user = obj.users[req.session.userid];
540 if (!user) return;
541 -
541 +
542 // Check if the password is correct
543 obj.authenticate(user.name, req.body.apassword1, domain, function (err, userid) {
544 var user = obj.users[userid];
@@ -571,14 +571,14 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
571 }
572 });
573 }
574 -
574 +
575 // Handle password changes
576 function handlePasswordChangeRequest(req, res) {
577 var domain = checkUserIpAddress(req, res);
578 if (domain == null) return;
579 // Check if the user is logged and we have all required parameters
580 if (!req.session || !req.session.userid || !req.body.apassword1 || (req.body.apassword1 != req.body.apassword2) || (req.session.domainid != domain.id)) { res.redirect(domain.url); return; }
581 -
581 +
582 // Update the password
583 require('./pass').hash(req.body.apassword1, function (err, salt, hash) {
584 if (err) throw err;
@@ -708,7 +708,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
708 if (obj.args.webrtc == true) { features += 128; } // Enable WebRTC (Default false for now)
709 if (obj.args.clickonce !== false) { features += 256; } // Enable ClickOnce (Default true)
710 if (obj.args.allowhighqualitydesktop == true) { features += 512; } // Enable AllowHighQualityDesktop (Default false)
711 -
711 +
712 // Send the master web application
713 if ((!obj.args.user) && (obj.args.nousers != true) && (nologout == false)) { logoutcontrol += ' <a href=' + domain.url + 'logout?' + Math.random() + ' style=color:white>Logout</a>'; } // If a default user is in use or no user mode, don't display the logout button
714 var httpsPort = ((obj.args.aliasport == null) ? obj.args.port : obj.args.aliasport); // Use HTTPS alias port is specified
@@ -719,10 +719,10 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
719 delete req.session.loginmode; // Clear this state, if the user hits refresh, we want to go back to the login page.
720 if ((parent.config != null) && (parent.config.settings != null) && (parent.config.settings.allowframing == true)) { features += 32; } // Allow site within iframe
721 var httpsPort = ((obj.args.aliasport == null) ? obj.args.port : obj.args.aliasport); // Use HTTPS alias port is specified
722 - res.render(obj.path.join(__dirname, isModuleBrowser(req) ?'views/login-mobile':'views/login'), { loginmode: loginmode, rootCertLink: getRootCertLink(), title: domain.title, title2: domain.title2, newAccount: domain.newaccounts, newAccountPass: (((domain.newaccountspass == null) || (domain.newaccountspass == '')) ? 0 : 1), serverDnsName: getWebServerName(domain), serverPublicPort: httpsPort, emailcheck: obj.parent.mailserver != null, features: features, footer: (domain.footer == null) ? '' : domain.footer });
722 + res.render(obj.path.join(__dirname, isModuleBrowser(req) ? 'views/login-mobile' : 'views/login'), { loginmode: loginmode, rootCertLink: getRootCertLink(), title: domain.title, title2: domain.title2, newAccount: domain.newaccounts, newAccountPass: (((domain.newaccountspass == null) || (domain.newaccountspass == '')) ? 0 : 1), serverDnsName: getWebServerName(domain), serverPublicPort: httpsPort, emailcheck: obj.parent.mailserver != null, features: features, footer: (domain.footer == null) ? '' : domain.footer });
723 }
724 }
725 -
725 +
726 // Get the link to the root certificate if needed
727 function getRootCertLink() {
728 // TODO: This is not quite right, we need to check if the HTTPS certificate is issued from MeshCentralRoot, if so, add this download link.
@@ -738,9 +738,9 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
738 if (req.session && req.session.userid) {
739 if (req.session.domainid != domain.id) { req.session.destroy(function () { res.redirect(domain.url); }); return; } // Check is the session is for the correct domain
740 var user = obj.users[req.session.userid];
741 - res.render(obj.path.join(__dirname, isModuleBrowser(req)?'views/terms-mobile':'views/terms'), { title: domain.title, title2: domain.title2, logoutControl: 'Welcome ' + user.name + '. <a href=' + domain.url + 'logout?' + Math.random() + ' style=color:white>Logout</a>' });
741 + res.render(obj.path.join(__dirname, isModuleBrowser(req) ? 'views/terms-mobile' : 'views/terms'), { title: domain.title, title2: domain.title2, logoutControl: 'Welcome ' + user.name + '. <a href=' + domain.url + 'logout?' + Math.random() + ' style=color:white>Logout</a>' });
742 } else {
743 - res.render(obj.path.join(__dirname, isModuleBrowser(req)?'views/terms-mobile':'views/terms'), { title: domain.title, title2: domain.title2 });
743 + res.render(obj.path.join(__dirname, isModuleBrowser(req) ? 'views/terms-mobile' : 'views/terms'), { title: domain.title, title2: domain.title2 });
744 }
745 }
746
@@ -771,7 +771,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
771
772 // Figure out the MPS port, use the alias if set
773 var mpsport = ((obj.args.mpsaliasport != null) ? obj.args.mpsaliasport : obj.args.mpsport);
774 -
774 +
775 if ((serverNameSplit.length == 4) && (parseInt(serverNameSplit[0]) == serverNameSplit[0]) && (parseInt(serverNameSplit[1]) == serverNameSplit[1]) && (parseInt(serverNameSplit[2]) == serverNameSplit[2]) && (parseInt(serverNameSplit[3]) == serverNameSplit[3])) {
776 // Server name is an IPv4 address
777 var filepath = obj.parent.path.join(__dirname, 'public/scripts/cira_setup_script_ip.mescript');
@@ -837,7 +837,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
837 });
838 }
839 }
840 -
840 +
841 // Handle user public file downloads
842 function handleDownloadUserFiles(req, res) {
843 var domain = checkUserIpAddress(req, res);
@@ -847,7 +847,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
847 if (domain.id != '') { domainname = 'domain-' + domain.id; }
848 var path = obj.path.join(obj.filespath, domainname + "/user-" + spliturl[2] + "/Public");
849 for (var i = 3; i < spliturl.length; i++) { if (obj.common.IsFilenameValid(spliturl[i]) == true) { path += '/' + spliturl[i]; filename = spliturl[i]; } else { res.sendStatus(404); return; } }
850 -
850 +
851 var stat = null;
852 try { stat = obj.fs.statSync(path) } catch (e) { }
853 if ((stat != null) && ((stat.mode & 0x004000) == 0)) {
@@ -855,7 +855,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
855 res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename=\"' + filename + '\"' });
856 try { res.sendFile(obj.path.resolve(__dirname, path)); } catch (e) { res.sendStatus(404); }
857 } else {
858 - res.render(obj.path.join(__dirname, 'views/download'), { rootCertLink: getRootCertLink(), title: domain.title, title2: domain.title2, message: "<a href='" + req.path + "?download=1'>" + filename + "</a>, " + stat.size + " byte" + ((stat.size < 2)?'':'s') + "." });
858 + res.render(obj.path.join(__dirname, 'views/download'), { rootCertLink: getRootCertLink(), title: domain.title, title2: domain.title2, message: "<a href='" + req.path + "?download=1'>" + filename + "</a>, " + stat.size + " byte" + ((stat.size < 2) ? '' : 's') + "." });
859 }
860 } else {
861 res.render(obj.path.join(__dirname, 'views/download'), { rootCertLink: getRootCertLink(), title: domain.title, title2: domain.title2, message: "Invalid file link, please check the URL again." });
@@ -863,7 +863,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
863 }
864
865 // Take a "user/domain/userid/path/file" format and return the actual server disk file path if access is allowed
866 - obj.getServerFilePath = function(user, domain, path) {
866 + obj.getServerFilePath = function (user, domain, path) {
867 var splitpath = path.split('/'), serverpath = obj.path.join(obj.filespath, 'domain'), filename = '';
868 if ((splitpath.length < 3) || (splitpath[0] != 'user' && splitpath[0] != 'mesh') || (splitpath[1] != domain.id)) return null; // Basic validation
869 var objid = splitpath[0] + '/' + splitpath[1] + '/' + splitpath[2];
@@ -877,7 +877,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
877 }
878
879 // Return the maximum number of bytes allowed in the user account "My Files".
880 - obj.getQuota = function(objid, domain) {
880 + obj.getQuota = function (objid, domain) {
881 if (objid == null) return 0;
882 if (objid.startsWith('user/')) {
883 var user = obj.users[objid];
@@ -907,7 +907,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
907 res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename=\"' + file.name + '\"' });
908 try { res.sendFile(file.fullpath); } catch (e) { res.sendStatus(404); }
909 }
910 -
910 +
911 // Upload a MeshCore.js file to the server
912 function handleUploadMeshCoreFile(req, res) {
913 var domain = checkUserIpAddress(req, res);
@@ -915,7 +915,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
915 if ((domain.id !== '') || (!req.session) || (req.session == null) || (!req.session.userid)) { res.sendStatus(401); return; }
916 var user = obj.users[req.session.userid];
917 if (user.siteadmin != 0xFFFFFFFF) { res.sendStatus(401); return; } // Check if we have mesh core upload rights (Full admin only)
918 -
918 +
919 var multiparty = require('multiparty');
920 var form = new multiparty.Form();
921 form.parse(req, function (err, fields, files) {
@@ -987,7 +987,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
987 res.send('');
988 });
989 }
990 -
990 +
991 // Subscribe to all events we are allowed to receive
992 obj.subscribe = function (userid, target) {
993 var user = obj.users[userid];
@@ -1035,11 +1035,11 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1035 if (docs.length == 0) { console.log('ERR: Node not found'); return; }
1036 var node = docs[0];
1037 if (!node.intelamt) { console.log('ERR: Not AMT node'); return; }
1038 -
1038 +
1039 // Check if this user has permission to manage this computer
1040 var meshlinks = user.links[node.meshid];
1041 if ((!meshlinks) || (!meshlinks.rights) || ((meshlinks.rights & MESHRIGHT_REMOTECONTROL) == 0)) { console.log('ERR: Access denied (2)'); return; }
1042 -
1042 +
1043 // Check what connectivity is available for this node
1044 var state = parent.GetConnectivityState(req.query.host);
1045 var conn = 0;
@@ -1075,7 +1075,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1075 //if (node.intelamt.tls == 0) port = 16992; // DEBUG: Allow TLS flag to set TLS mode within CIRA
1076 if (ciraconn.tag.boundPorts.indexOf(16992) >= 0) port = 16992; // RELEASE: Always use non-TLS mode if available within CIRA
1077 if (req.query.p == 2) port += 2;
1078 -
1078 +
1079 // Setup a new CIRA channel
1080 if ((port == 16993) || (port == 16995)) {
1081 // Perform TLS - ( TODO: THIS IS BROKEN on Intel AMT v7 but works on v10, Not sure why )
@@ -1108,7 +1108,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1108 var tlsock = new TLSSocket(ser, tlsoptions);
1109 tlsock.on('error', function (err) { Debug(1, "CIRA TLS Connection Error ", err); });
1110 tlsock.on('secureConnect', function () { Debug(2, "CIRA Secure TLS Connection"); ws.resume(); });
1111 -
1111 +
1112 // Decrypted tunnel from TLS communcation to be forwarded to websocket
1113 tlsock.on('data', function (data) {
1114 // AMT/TLS ---> WS
@@ -1128,7 +1128,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1128 ws.forwardclient.xtls = 0;
1129 ws.resume();
1130 }
1131 -
1131 +
1132 // When data is received from the web socket, forward the data into the associated CIRA cahnnel.
1133 // If the CIRA connection is pending, the CIRA channel has built-in buffering, so we are ok sending anyway.
1134 ws.on('message', function (msg) {
@@ -1146,23 +1146,23 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1146 Debug(1, 'Websocket relay closed.');
1147 if (ws.forwardclient && ws.forwardclient.close) { ws.forwardclient.close(); } // TODO: If TLS is used, we need to close the socket that is wrapped by TLS
1148 });
1149 -
1149 +
1150 ws.forwardclient.onStateChange = function (ciraconn, state) {
1151 Debug(2, 'Relay CIRA state change', state);
1152 if (state == 0) { try { ws.close(); } catch (e) { } }
1153 }
1154 -
1154 +
1155 ws.forwardclient.onData = function (ciraconn, data) {
1156 Debug(4, 'Relay CIRA data', data.length);
1157 if (ws.interceptor) { data = ws.interceptor.processAmtData(data); } // Run data thru interceptor
1158 if (data.length > 0) { try { ws.send(data); } catch (e) { } } // TODO: Add TLS support
1159 }
1160 -
1160 +
1161 ws.forwardclient.onSendOk = function (ciraconn) {
1162 // TODO: Flow control? (Dont' really need it with AMT, but would be nice)
1163 //console.log('onSendOk');
1164 }
1165 -
1165 +
1166 // Fetch Intel AMT credentials & Setup interceptor
1167 if (req.query.p == 1) {
1168 Debug(3, 'INTERCEPTOR1', { host: node.host, port: port, user: node.intelamt.user, pass: node.intelamt.pass });
@@ -1177,7 +1177,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1177
1178 return;
1179 }
1180 -
1180 +
1181 // If Intel AMT direct connection is possible, option a direct socket
1182 if ((conn & 4) != 0) { // We got a new web socket connection, initiate a TCP connection to the target Intel AMT host/port.
1183 Debug(2, 'Opening relay TCP socket connection to ' + req.query.host + '.');
@@ -1203,7 +1203,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1203 var port = 16992;
1204 if (node.intelamt.tls > 0) port = 16993; // This is a direct connection, use TLS when possible
1205 if (req.query.p == 2) port += 2;
1206 -
1206 +
1207 if (node.intelamt.tls == 0) {
1208 // If this is TCP (without TLS) set a normal TCP socket
1209 ws.forwardclient = new obj.net.Socket();
@@ -1224,30 +1224,30 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1224 ws.forwardclient.xstate = 0;
1225 ws.forwardclient.forwardwsocket = ws;
1226 }
1227 -
1227 +
1228 // When we receive data on the TCP connection, forward it back into the web socket connection.
1229 ws.forwardclient.on('data', function (data) {
1230 Debug(1, 'TCP relay data from ' + node.host + ', ' + data.length + ' bytes.'); // DEBUG
1231 if (ws.interceptor) { data = ws.interceptor.processAmtData(data); } // Run data thru interceptor
1232 try { ws.send(new Buffer(data, 'binary')); } catch (e) { }
1233 });
1234 -
1234 +
1235 // If the TCP connection closes, disconnect the associated web socket.
1236 ws.forwardclient.on('close', function () {
1237 Debug(1, 'TCP relay disconnected from ' + node.host + '.');
1238 try { ws.close(); } catch (e) { }
1239 });
1240 -
1240 +
1241 // If the TCP connection causes an error, disconnect the associated web socket.
1242 ws.forwardclient.on('error', function (err) {
1243 Debug(1, 'TCP relay error from ' + node.host + ': ' + err.errno);
1244 try { ws.close(); } catch (e) { }
1245 });
1246 -
1246 +
1247 // Fetch Intel AMT credentials & Setup interceptor
1248 if (req.query.p == 1) { ws.interceptor = obj.interceptor.CreateHttpInterceptor({ host: node.host, port: port, user: node.intelamt.user, pass: node.intelamt.pass }); }
1249 else if (req.query.p == 2) { ws.interceptor = obj.interceptor.CreateRedirInterceptor({ user: node.intelamt.user, pass: node.intelamt.pass }); }
1250 -
1250 +
1251 if (node.intelamt.tls == 0) {
1252 // A TCP connection to Intel AMT just connected, start forwarding.
1253 ws.forwardclient.connect(port, node.host, function () {
@@ -1284,7 +1284,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1284 // If closed, do nothing
1285 ws.on('close', function (req) { });
1286 }
1287 -
1287 +
1288 // Get the total size of all files in a folder and all sub-folders. (TODO: try to make all async version)
1289 function readTotalFileSize(path) {
1290 var r = 0, dir;
@@ -1295,7 +1295,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1295 }
1296 return r;
1297 }
1298 -
1298 +
1299 // Delete a folder and all sub items. (TODO: try to make all async version)
1300 function deleteFolderRec(path) {
1301 if (obj.fs.existsSync(path) == false) return;
@@ -1305,7 +1305,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1305 });
1306 obj.fs.rmdirSync(path);
1307 };
1308 -
1308 +
1309 // Handle Intel AMT events
1310 // To subscribe, add "http://server:port/amtevents.ashx" to Intel AMT subscriptions.
1311 obj.handleAmtEventRequest = function (req, res) {
@@ -1316,29 +1316,29 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1316 if (authstr.substring(0, 7) == "Digest ") {
1317 var auth = obj.common.parseNameValueList(obj.common.quoteSplit(authstr.substring(7)));
1318 if ((req.url === auth.uri) && (obj.httpAuthRealm === auth.realm) && (auth.opaque === obj.crypto.createHmac('SHA384', obj.httpAuthRandom).update(auth.nonce).digest('hex'))) {
1319 -
1319 +
1320 // Read the data, we need to get the arg field
1321 var eventData = '';
1322 req.on('data', function (chunk) { eventData += chunk; });
1323 req.on('end', function () {
1324 -
1324 +
1325 // Completed event read, let get the argument that must contain the nodeid
1326 var i = eventData.indexOf('<m:arg xmlns:m="http://x.com">');
1327 if (i > 0) {
1328 var nodeid = eventData.substring(i + 30, i + 30 + 64);
1329 if (nodeid.length == 64) {
1330 var nodekey = 'node/' + domain.id + '/' + nodeid;
1331 -
1331 +
1332 // See if this node exists in the database
1333 obj.db.Get(nodekey, function (err, nodes) {
1334 if (nodes.length == 1) {
1335 // Yes, the node exists, compute Intel AMT digest password
1336 var node = nodes[0];
1337 var amtpass = obj.crypto.createHash('sha384').update(auth.username.toLowerCase() + ":" + nodeid + ":" + obj.parent.dbconfig.amtWsEventSecret).digest("base64").substring(0, 12).split("/").join("x").split("\\").join("x");
1338 -
1338 +
1339 // Check the MD5 hash
1340 if (auth.response === obj.common.ComputeDigesthash(auth.username, amtpass, auth.realm, "POST", auth.uri, auth.qop, auth.nonce, auth.nc, auth.cnonce)) {
1341 -
1341 +
1342 // This is an authenticated Intel AMT event, update the host address
1343 var amthost = req.connection.remoteAddress;
1344 if (amthost.substring(0, 7) === '::ffff:') { amthost = amthost.substring(7); }
@@ -1359,10 +1359,10 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1359 obj.parent.DispatchEvent(['*', node.meshid], obj, event);
1360 }
1361 }
1362 -
1362 +
1363 parent.amtEventHandler.handleAmtEvent(eventData, nodeid, amthost);
1364 //res.send('OK');
1365 -
1365 +
1366 return;
1367 }
1368 }
@@ -1374,7 +1374,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1374 }
1375 }
1376 } catch (e) { console.log(e); }
1377 -
1377 +
1378 // Send authentication response
1379 obj.crypto.randomBytes(48, function (err, buf) {
1380 var nonce = buf.toString('hex'), opaque = obj.crypto.createHmac('SHA384', obj.httpAuthRandom).update(nonce).digest('hex');
@@ -1382,7 +1382,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1382 res.sendStatus(401);
1383 });
1384 }
1385 -
1385 +
1386 // Handle a server backup request
1387 function handleBackupRequest(req, res) {
1388 var domain = checkUserIpAddress(req, res);
@@ -1394,16 +1394,16 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1394 // Require modules
1395 var fs = require('fs');
1396 var archive = require('archiver')('zip', { level: 9 }); // Sets the compression method to maximum.
1397 -
1397 +
1398 // Good practice to catch this error explicitly
1399 archive.on('error', function (err) { throw err; });
1400 -
1400 +
1401 // Set the archive name
1402 res.attachment(domain.title + '-Backup-' + new Date().toLocaleDateString().replace('/', '-').replace('/', '-') + '.zip');
1403
1404 // Pipe archive data to the file
1405 archive.pipe(res);
1406 -
1406 +
1407 // Append all of the files for this backup
1408 var backupList = ['config.json', 'meshcentral.db', 'agentserver-cert-private.key', 'agentserver-cert-public.crt', 'mpsserver-cert-private.key', 'mpsserver-cert-public.crt', 'data/root-cert-private.key', 'root-cert-public.crt', 'webserver-cert-private.key', 'webserver-cert-public.crt'];
1409 for (var i in backupList) {
@@ -1415,7 +1415,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1415 // Finalize the archive (ie we are done appending files but streams have to finish yet)
1416 archive.finalize();
1417 }
1418 -
1418 +
1419 // Handle a server restore request
1420 function handleRestoreRequest(req, res) {
1421 var domain = checkUserIpAddress(req, res);
@@ -1423,7 +1423,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1423 if ((domain.id !== '') || (!req.session) || (req.session == null) || (!req.session.userid) || (obj.parent.args.noserverbackup == 1)) { res.sendStatus(401); return; }
1424 var user = obj.users[req.session.userid];
1425 if ((user.siteadmin & 4) == 0) { res.sendStatus(401); return; } // Check if we have server restore rights
1426 -
1426 +
1427 var multiparty = require('multiparty');
1428 var form = new multiparty.Form();
1429 form.parse(req, function (err, fields, files) {
@@ -1431,7 +1431,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1431 parent.Stop(files.datafile[0].path);
1432 });
1433 }
1434 -
1434 +
1435 // Handle a request to download a mesh agent
1436 obj.handleMeshAgentRequest = function (req, res) {
1437 var domain = checkUserIpAddress(req, res);
@@ -1646,7 +1646,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1646 // Setup all HTTP handlers
1647 obj.app.get('/backup.zip', handleBackupRequest);
1648 obj.app.post('/restoreserver.ashx', handleRestoreRequest);
1649 - if (parent.multiServer != null) { obj.app.ws('/meshserver.ashx', function (ws, req) { parent.multiServer.CreatePeerInServer(parent.multiServer, ws, req); } ); }
1649 + if (parent.multiServer != null) { obj.app.ws('/meshserver.ashx', function (ws, req) { parent.multiServer.CreatePeerInServer(parent.multiServer, ws, req); }); }
1650 for (var i in parent.config.domains) {
1651 if (parent.config.domains[i].dns != null) { continue; } // This is a subdomain with a DNS name, no added HTTP bindings needed.
1652 var url = parent.config.domains[i].url;
@@ -1713,7 +1713,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1713 }
1714
1715 // Force mesh agent disconnection
1716 - obj.forceMeshAgentDisconnect = function(user, domain, nodeid, disconnectMode) {
1716 + obj.forceMeshAgentDisconnect = function (user, domain, nodeid, disconnectMode) {
1717 if (nodeid == null) return;
1718 var splitnode = nodeid.split('/');
1719 if ((splitnode.length != 3) || (splitnode[1] != domain.id)) return; // Check that nodeid is valid and part of our domain
@@ -1726,7 +1726,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1726 }
1727
1728 // Send the core module to the mesh agent
1729 - obj.sendMeshAgentCore = function(user, domain, nodeid, core) {
1729 + obj.sendMeshAgentCore = function (user, domain, nodeid, core) {
1730 if (nodeid == null) return;
1731 var splitnode = nodeid.split('/');
1732 if ((splitnode.length != 3) || (splitnode[1] != domain.id)) return; // Check that nodeid is valid and part of our domain
@@ -1754,7 +1754,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1754 }
1755 }
1756 }
1757 -
1757 +
1758 // Get the server path of a user or mesh object
1759 function getServerRootFilePath(obj) {
1760 if ((typeof obj != 'object') || (obj.domain == null) || (obj._id == null)) return null;
@@ -1763,7 +1763,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1763 if (obj.domain !== '') domainname = 'domain-' + obj.domain;
1764 return obj.path.join(obj.filespath, domainname + "/" + splitname[0] + "-" + splitname[2]);
1765 }
1766 -
1766 +
1767 // Read entire file and return it in callback function
1768 function readEntireTextFile(filepath, func) {
1769 var called = false;
@@ -1806,13 +1806,13 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1806 // Start server on a free port
1807 CheckListenPort(obj.args.port, StartWebServer);
1808
1809 -/*
1810 - obj.wssessions = {}; // UserId --> Array Of Sessions
1811 - obj.wssessions2 = {}; // "UserId + SessionRnd" --> Session (Note that the SessionId is the UserId + / + SessionRnd)
1812 - obj.wsPeerSessions = {}; // ServerId --> Array Of "UserId + SessionRnd"
1813 - obj.wsPeerSessions2 = {}; // "UserId + SessionRnd" --> ServerId
1814 - obj.wsPeerSessions3 = {}; // ServerId --> UserId --> [ SessionId ]
1815 -*/
1809 + /*
1810 + obj.wssessions = {}; // UserId --> Array Of Sessions
1811 + obj.wssessions2 = {}; // "UserId + SessionRnd" --> Session (Note that the SessionId is the UserId + / + SessionRnd)
1812 + obj.wsPeerSessions = {}; // ServerId --> Array Of "UserId + SessionRnd"
1813 + obj.wsPeerSessions2 = {}; // "UserId + SessionRnd" --> ServerId
1814 + obj.wsPeerSessions3 = {}; // ServerId --> UserId --> [ SessionId ]
1815 + */
1816
1817 // Count sessions and event any changes
1818 obj.recountSessions = function (changedSessionId) {
@@ -1872,10 +1872,10 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1872 }
1873
1874 // Return true if a mobile browser is detected.
1875 - // This code comes from "http://detectmobilebrowsers.com/", This is free and unencumbered software released into the public domain. For more information, please refer to the http://unlicense.org/
1875 + // This code comes from "http://detectmobilebrowsers.com/" and was modified, This is free and unencumbered software released into the public domain. For more information, please refer to the http://unlicense.org/
1876 function isModuleBrowser(req) {
1877 var ua = req.headers['user-agent'].toLowerCase();
1878 - return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(ua) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(ua.substr(0, 4)));
1878 + return (/(android|bb\d+|meego).+mobile|mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(ua) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(ua.substr(0, 4)));
1879 }
1880
1881 return obj;