diff --git a/agents/meshcore.js b/agents/meshcore.js index 0105fea1..947e0d37 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -707,10 +707,9 @@ function createMeshCore(agent) { break; } case 'rm': { - // Remove many files or folders + // Delete, possibly recursive delete for (var i in cmd.delfiles) { - var fullpath = obj.path.join(cmd.path, cmd.delfiles[i]); - try { fs.unlinkSync(fullpath); } catch (e) { console.log(e); } + try { deleteFolderRecursive(obj.path.join(cmd.path, cmd.delfiles[i]), cmd.rec); } catch (e) { } } break; } @@ -1758,6 +1757,23 @@ function createMeshCore(agent) { obj.osamtstack.IPS_KVMRedirectionSettingData_DataChannelWrite(Buffer.from(x).toString('base64'), function () { }); } + // Delete a directory with a files and directories within it + function deleteFolderRecursive(path, rec) { + if (fs.existsSync(path)) { + if (rec == true) { + fs.readdirSync(obj.path.join(path, '*')).forEach(function (file, index) { + var curPath = obj.path.join(path, file); + if (fs.statSync(curPath).isDirectory()) { // recurse + deleteFolderRecursive(curPath, true); + } else { // delete file + fs.unlinkSync(curPath); + } + }); + } + fs.unlinkSync(path); + } + }; + return obj; } diff --git a/letsEncrypt.js b/letsEncrypt.js index f8c4a2fc..d1149c25 100644 --- a/letsEncrypt.js +++ b/letsEncrypt.js @@ -41,6 +41,7 @@ module.exports.CreateLetsEncrypt = function (parent) { // Create the main GreenLock code module. var greenlockargs = { + version: 'draft-12', server: (obj.parent.config.letsencrypt.production === true) ? greenlock.productionServerUrl : greenlock.stagingServerUrl, store: leStore, challenges: { 'http-01': leHttpChallenge }, diff --git a/meshagent.js b/meshagent.js index 4fdab39a..8074926e 100644 --- a/meshagent.js +++ b/meshagent.js @@ -64,6 +64,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { obj.db.Remove(obj.dbNodeKey); // Remove node with that id obj.db.Remove('if' + obj.dbNodeKey); // Remove interface information obj.db.Remove('nt' + obj.dbNodeKey); // Remove notes + obj.db.Remove('lc' + obj.dbNodeKey); // Remove last connect time obj.db.RemoveNode(obj.dbNodeKey); // Remove all entries with node:id // Event node deletion @@ -75,6 +76,9 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { if ((state.connectivity & 1) != 0) { obj.parent.wsagents[obj.dbNodeKey].close(); } // Disconnect mesh agent if ((state.connectivity & 2) != 0) { obj.parent.parent.mpsserver.close(obj.parent.parent.mpsserver.ciraConnections[obj.dbNodeKey]); } // Disconnect CIRA connection } + } else { + // Update the last connect time + obj.db.Set({ _id: 'lc' + obj.dbNodeKey, type: 'lastconnect', domain: domain.id, time: obj.connectTime }); } delete obj.nodeid; }; diff --git a/meshuser.js b/meshuser.js index 12461d98..b49ae8a1 100644 --- a/meshuser.js +++ b/meshuser.js @@ -129,13 +129,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { if ((user == null) || (obj.common.validateString(command.action, 3, 32) == false)) return; // User must be set and action must be a string between 3 and 32 chars switch (command.action) { - case 'ping': { ws.send(JSON.stringify({ action: 'pong' })); break; } + case 'ping': { try { ws.send(JSON.stringify({ action: 'pong' })); } catch (ex) { } break; } case 'meshes': { // Request a list of all meshes this user as rights to var docs = []; for (i in user.links) { if (obj.parent.meshes[i]) { docs.push(obj.parent.meshes[i]); } } - ws.send(JSON.stringify({ action: 'meshes', meshes: docs, tag: command.tag })); + try { ws.send(JSON.stringify({ action: 'meshes', meshes: docs, tag: command.tag })); } catch (ex) { } break; } case 'nodes': @@ -175,7 +175,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { r[meshid].push(docs[i]); } - ws.send(JSON.stringify({ action: 'nodes', nodes: r, tag: command.tag })); + try { ws.send(JSON.stringify({ action: 'nodes', nodes: r, tag: command.tag })); } catch (ex) { } }); break; } @@ -219,11 +219,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { } } } - ws.send(JSON.stringify({ action: 'powertimeline', nodeid: command.nodeid, timeline: timeline, tag: command.tag })); + try { ws.send(JSON.stringify({ action: 'powertimeline', nodeid: command.nodeid, timeline: timeline, tag: command.tag })); } catch (ex) { } } else { // No records found, send current state if we have it var state = obj.parent.parent.GetConnectivityState(command.nodeid); - if (state != null) { ws.send(JSON.stringify({ action: 'powertimeline', nodeid: command.nodeid, timeline: [state.powerState, Date.now(), state.powerState], tag: command.tag })); } + if (state != null) { try { ws.send(JSON.stringify({ action: 'powertimeline', nodeid: command.nodeid, timeline: [state.powerState, Date.now(), state.powerState], tag: command.tag })); } catch (ex) { } } } }); break; @@ -254,7 +254,19 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { if (path == null) break; if ((command.fileop == 'createfolder') && (obj.common.IsFilenameValid(command.newfolder) == true)) { try { obj.fs.mkdirSync(path + "/" + command.newfolder); } catch (e) { } } // Create a new folder - else if (command.fileop == 'delete') { if (obj.common.validateArray(command.delfiles, 1) == false) return; for (i in command.delfiles) { if (obj.common.IsFilenameValid(command.delfiles[i]) == true) { var fullpath = path + "/" + command.delfiles[i]; try { obj.fs.rmdirSync(fullpath); } catch (e) { try { obj.fs.unlinkSync(fullpath); } catch (e) { } } } } } // Delete + else if (command.fileop == 'delete') { // Delete + if (obj.common.validateArray(command.delfiles, 1) == false) return; + for (i in command.delfiles) { + if (obj.common.IsFilenameValid(command.delfiles[i]) == true) { + var fullpath = obj.path.join(path, command.delfiles[i]); + if (command.rec == true) { + deleteFolderRecursive(fullpath); // TODO, make this an async function + } else { + try { obj.fs.rmdirSync(fullpath); } catch (e) { try { obj.fs.unlinkSync(fullpath); } catch (e) { } } + } + } + } + } else if ((command.fileop == 'rename') && (obj.common.IsFilenameValid(command.oldname) == true) && (obj.common.IsFilenameValid(command.newname) == true)) { try { obj.fs.renameSync(path + "/" + command.oldname, path + "/" + command.newname); } catch (e) { } } // Rename else if ((command.fileop == 'copy') || (command.fileop == 'move')) { if (obj.common.validateArray(command.names, 1) == false) return; @@ -366,7 +378,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { docs.push(userinfo); } } - ws.send(JSON.stringify({ action: 'users', users: docs, tag: command.tag })); + try { ws.send(JSON.stringify({ action: 'users', users: docs, tag: command.tag })); } catch (ex) { } break; } case 'changeemail': @@ -378,7 +390,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { obj.db.GetUserWithVerifiedEmail(domain.id, command.email, function (err, docs) { if (docs.length > 0) { // Notify the duplicate email error - ws.send(JSON.stringify({ action: 'msg', type: 'notify', value: 'Failed to change email address, another account already using: ' + EscapeHtml(command.email) + '.' })); + try { ws.send(JSON.stringify({ action: 'msg', type: 'notify', value: 'Failed to change email address, another account already using: ' + EscapeHtml(command.email) + '.' })); } catch (ex) { } } else { // Update the user's email var oldemail = user.email; @@ -434,7 +446,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { // We have peer servers, use more complex session counting for (i in obj.parent.sessionsCount) { if (i.split('/')[1] == domain.id) { wssessions[i] = obj.parent.sessionsCount[i]; } } } - ws.send(JSON.stringify({ action: 'wssessioncount', wssessions: wssessions, tag: command.tag })); // wssessions is: userid --> count + try { ws.send(JSON.stringify({ action: 'wssessioncount', wssessions: wssessions, tag: command.tag })); } catch (ex) { } // wssessions is: userid --> count break; } case 'deleteuser': @@ -572,7 +584,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { { // Check the server version if ((user.siteadmin & 16) == 0) break; - obj.parent.parent.getLatestServerVersion(function (currentVersion, latestVersion) { ws.send(JSON.stringify({ action: 'serverversion', current: currentVersion, latest: latestVersion })); }); + obj.parent.parent.getLatestServerVersion(function (currentVersion, latestVersion) { try { ws.send(JSON.stringify({ action: 'serverversion', current: currentVersion, latest: latestVersion })); } catch (ex) { } }); break; } case 'serverupdate': @@ -586,7 +598,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { { // Load the server error log if ((user.siteadmin & 16) == 0) break; - obj.parent.parent.readEntireTextFile(obj.parent.parent.getConfigFilePath('mesherrors.txt'), function (data) { ws.send(JSON.stringify({ action: 'servererrors', data: data })); } ); + obj.parent.parent.readEntireTextFile(obj.parent.parent.getConfigFilePath('mesherrors.txt'), function (data) { try { ws.send(JSON.stringify({ action: 'servererrors', data: data })); } catch (ex) { } } ); break; } case 'serverclearerrorlog': @@ -823,6 +835,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { obj.db.Remove(node._id); // Remove node with that id obj.db.Remove('if' + node._id); // Remove interface information obj.db.Remove('nt' + node._id); // Remove notes + obj.db.Remove('lc' + node._id); // Remove last connect time obj.db.RemoveNode(node._id); // Remove all entries with node:id // Event node deletion @@ -894,7 +907,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { }); } // Confirm we may be doing something (TODO) - ws.send(JSON.stringify({ action: 'wakedevices' })); + try { ws.send(JSON.stringify({ action: 'wakedevices' })); } catch (ex) { } } break; @@ -931,7 +944,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { }); } // Confirm we may be doing something (TODO) - ws.send(JSON.stringify({ action: 'poweraction' })); + try { ws.send(JSON.stringify({ action: 'poweraction' })); } catch (ex) { } } break; } @@ -978,20 +991,20 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { // Get the device obj.db.Get(command.nodeid, function (err, nodes) { - if (nodes.length != 1) { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, netif: null })); return; } + if (nodes.length != 1) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, netif: null })); } catch (ex) { } return; } var node = nodes[0]; // Get the mesh for this device mesh = obj.parent.meshes[node.meshid]; if (mesh) { // Check if this user has rights to do this - if (mesh.links[user._id] == null || (mesh.links[user._id].rights == 0)) { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, netif: null })); return; } + if (mesh.links[user._id] == null || (mesh.links[user._id].rights == 0)) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, netif: null })); } catch (ex) { } return; } // Get network information about this node obj.db.Get('if' + command.nodeid, function (err, netinfos) { - if (netinfos.length != 1) { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, netif: null })); return; } + if (netinfos.length != 1) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, netif: null })); } catch (ex) { } return; } var netinfo = netinfos[0]; - ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, updateTime: netinfo.updateTime, netif: netinfo.netif })); + try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, updateTime: netinfo.updateTime, netif: netinfo.netif })); } catch (ex) { } }); } }); @@ -1122,7 +1135,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want to agent to TCP connect to a remote address if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want to agent to TCP connect to a remote port command.cookie = obj.parent.parent.encodeCookie(cookieContent); - ws.send(JSON.stringify(command)); + try { ws.send(JSON.stringify(command)); } catch (ex) { } } } }); @@ -1220,8 +1233,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { // Get the notes about this node obj.db.Get('nt' + command.id, function (err, notes) { - if (notes.length != 1) { ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: null })); return; } - ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: notes[0].value })); + try { + if (notes.length != 1) { ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: null })); return; } + ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: notes[0].value })); + } catch (ex) { } }); } }); @@ -1234,15 +1249,19 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { // Get the notes about this node obj.db.Get('nt' + command.id, function (err, notes) { - if (notes.length != 1) { ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: null })); return; } - ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: notes[0].value })); + try { + if (notes.length != 1) { ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: null })); return; } + ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: notes[0].value })); + } catch (ex) { } }); } } else if ((idtype == 'user') && ((user.siteadmin & 2) != 0)) { // Get the notes about this node obj.db.Get('nt' + command.id, function (err, notes) { - if (notes.length != 1) { ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: null })); return; } - ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: notes[0].value })); + try { + if (notes.length != 1) { ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: null })); return; } + ws.send(JSON.stringify({ action: 'getNotes', id: command.id, notes: notes[0].value })); + } catch (ex) { } }); } @@ -1288,13 +1307,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { if (obj.args.notls == true) { serverinfo.https = false; } else { serverinfo.https = true; serverinfo.redirport = obj.args.redirport; } // Send server information - ws.send(JSON.stringify({ action: 'serverinfo', serverinfo: serverinfo })); + try { ws.send(JSON.stringify({ action: 'serverinfo', serverinfo: serverinfo })); } catch (ex) { } // Send user information to web socket, this is the first thing we send var userinfo = obj.common.Clone(obj.parent.users[req.session.userid]); delete userinfo.salt; delete userinfo.hash; - ws.send(JSON.stringify({ action: 'userinfo', userinfo: userinfo })); + try { ws.send(JSON.stringify({ action: 'userinfo', userinfo: userinfo })); } catch (ex) { } } catch (e) { console.log(e); } // Read entire file and return it in callback function @@ -1329,6 +1348,22 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { return r; } + // Delete a directory with a files and directories within it + // TODO, make this an async function + function deleteFolderRecursive(path) { + if (obj.fs.existsSync(path)) { + obj.fs.readdirSync(path).forEach(function (file, index) { + var curPath = obj.path.join(path, file);; + if (obj.fs.lstatSync(curPath).isDirectory()) { // recurse + deleteFolderRecursive(curPath); + } else { // delete file + obj.fs.unlinkSync(curPath); + } + }); + obj.fs.rmdirSync(path); + } + }; + function updateUserFiles(user, ws, domain) { // Request the list of server files var files = { action: 'files', filetree: { n: 'Root', f: {} } }; @@ -1375,7 +1410,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { } // Respond - ws.send(JSON.stringify(files)); + try { ws.send(JSON.stringify(files)); } catch (ex) { } } function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&').replace(/>/g, '>').replace(/ MeshCentral
{{{title}}}
{{{title2}}}

{{{logoutControl}}}


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

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index d1115e28..6e4423eb 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -4264,12 +4264,13 @@ } function p13getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; } + function p13getFileSelDirCount() { var cc = 0, checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "999")) cc++; } return cc; } function p13getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fd'); return checkboxes.length; } function p13selectallfile() { var nv = (p13getFileSelCount() == 0), checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p13setActions(); } function p13createfolder() { setDialogMode(2, "New Folder", 3, p13createfolderEx, ''); focusTextBox('p13renameinput'); p13fileNameCheck(); } function p13createfolderEx() { files.sendText({ action: 'mkdir', reqid: 1, path: p13filetreelocation.join('/') + '/' + Q('p13renameinput').value }); p13folderup(999); } - function p13deletefile() { var cc = getFileSelCount(); setDialogMode(2, "Delete", 3, p13deletefileEx, (cc > 1)?('Delete ' + cc + ' selected items?'):('Delete selected item?')); } - function p13deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(p13filetree.dir[checkboxes[i].value].n); } } files.sendText({ action: 'rm', reqid: 1, path: p13filetreelocation.join('/'), delfiles: delfiles }); p13folderup(999); } + function p13deletefile() { var cc = p13getFileSelCount(), rec = (p13getFileSelDirCount() > 0) ? "

Recursive delete
" : ""; setDialogMode(2, "Delete", 3, p13deletefileEx, (cc > 1) ? ('Delete ' + cc + ' selected items?' + rec) : ('Delete selected item?' + rec)); } + function p13deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(p13filetree.dir[checkboxes[i].value].n); } } files.sendText({ action: 'rm', reqid: 1, path: p13filetreelocation.join('/'), delfiles: delfiles, rec: Q('p13recdeleteinput').checked }); p13folderup(999); } function p13renamefile() { var renamefile, checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { renamefile = p13filetree.dir[checkboxes[i].value].n; } } setDialogMode(2, "Rename", 3, p13renamefileEx, '', { action: 'rename', path: p13filetreelocation.join('/'), oldname: renamefile}); focusTextBox('p13renameinput'); p13fileNameCheck(); } function p13renamefileEx(b, t) { t.newname = Q('p13renameinput').value; files.sendText(t); p13folderup(999); } function p13fileNameCheck(e) { var x = isFilenameValid(Q('p13renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e != null) && (e.keyCode == 13)) { dialogclose(1); } } @@ -5208,7 +5209,8 @@ QE('p5PasteButton', (p5clipboard != null) && (p5clipboard.length > 0) && (filetreelocation.length > 0)); } - function getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; } + function getFileSelCount(includeDirs) { var cc = 0, checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; } + function getFileSelDirCount() { var cc = 0, checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "999")) cc++; } return cc; } function getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fc'); return checkboxes.length; } function p5selectallfile() { var nv = (getFileSelCount() == 0), checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p5setActions(); } function setupBackPointers(x) { if (x.f != null) { var fs = 0, fc = 0; for (var i in x.f) { setupBackPointers(x.f[i]); x.f[i].parent = x; if (x.f[i].s) { fs += x.f[i].s; } if (x.f[i].c) { fc += x.f[i].c; } if (x.f[i].t == 3) { fc++; } } x.s = fs; x.c = fc; } return x; } @@ -5217,11 +5219,11 @@ function p5folderset(x) { filetreelocation.push(decodeURIComponent(x)); updateFiles(); } function p5createfolder() { setDialogMode(2, "New Folder", 3, p5createfolderEx, ''); focusTextBox('p5renameinput'); p5fileNameCheck(); } function p5createfolderEx() { meshserver.send({ action: 'fileoperation', fileop: 'createfolder', path: filetreelocation, newfolder: Q('p5renameinput').value}); } - function p5deletefile() { var cc = getFileSelCount(); setDialogMode(2, "Delete", 3, p5deletefileEx, (cc > 1)?('Delete ' + cc + ' selected items?'):('Delete selected item?')); } - function p5deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(checkboxes[i].value); } } meshserver.send({ action: 'fileoperation', fileop: 'delete', path: filetreelocation, delfiles: delfiles}); } + function p5deletefile() { var cc = getFileSelCount(), rec = (getFileSelDirCount() > 0) ? "

Recursive delete
" : ""; setDialogMode(2, "Delete", 3, p5deletefileEx, (cc > 1) ? ('Delete ' + cc + ' selected items?' + rec) : ('Delete selected item?' + rec)); } + function p5deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(checkboxes[i].value); } } meshserver.send({ action: 'fileoperation', fileop: 'delete', path: filetreelocation, delfiles: delfiles, rec: Q('p5recdeleteinput').checked }); } function p5renamefile() { var renamefile, checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { renamefile = checkboxes[i].value; } } setDialogMode(2, "Rename", 3, p5renamefileEx, '', { action: 'fileoperation', fileop: 'rename', path: filetreelocation, oldname: renamefile}); focusTextBox('p5renameinput'); p5fileNameCheck(); } function p5renamefileEx(b, t) { t.newname = Q('p5renameinput').value; meshserver.send(t); } - function p5fileNameCheck(e) { var x = isFilenameValid(Q('p5renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e.keyCode == 13)) { dialogclose(1); } } + function p5fileNameCheck(e) { var x = isFilenameValid(Q('p5renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e && e.keyCode == 13)) { dialogclose(1); } } var isFilenameValid = (function(){ var x1=/^[^\\/:\*\?"<>\|]+$/, x2=/^\./, x3=/^(nul|prn|con|lpt[0-9]|com[0-9])(\.|$)/i; return function isFilenameValid(fname){ return x1.test(fname)&&!x2.test(fname)&&!x3.test(fname)&&(fname[0] != '.'); } })(); function p5uploadFile() { setDialogMode(2, "Upload File", 3, p5uploadFileEx, '
'); updateUploadDialogOk('p5uploadinput'); } function p5uploadFileEx() { Q('p5loginSubmit').click(); }