From c0746e0e0274f313294b057ca561b507d79abc07 Mon Sep 17 00:00:00 2001 From: zyx Date: Sat, 27 Jan 2024 19:50:53 +0800 Subject: [PATCH 1/3] add logger --- logs/logfile.log | 6 + source/modules/filemanager/index.js | 1810 +++++++++++++++------------ source/modules/logger.js | 14 + 3 files changed, 1023 insertions(+), 807 deletions(-) create mode 100644 logs/logfile.log create mode 100644 source/modules/logger.js diff --git a/logs/logfile.log b/logs/logfile.log new file mode 100644 index 00000000..15f8a36d --- /dev/null +++ b/logs/logfile.log @@ -0,0 +1,6 @@ +File uploaded successfully: 微信图片_20240110091111.jpg +File uploaded successfully: 张郁璇-回执单.jpg +File uploaded successfully: config.json +File uploaded successfully: config.json +File download successfully: /var/www/html/uploadfiles/test.txt +2024/1/27 下午6:35:53 - File uploaded successfully: config.json diff --git a/source/modules/filemanager/index.js b/source/modules/filemanager/index.js index 5b4aa014..bba4a677 100644 --- a/source/modules/filemanager/index.js +++ b/source/modules/filemanager/index.js @@ -3,76 +3,85 @@ * 更新:2016/05/14 * 作者:蚁逅 */ -'use strict'; +"use strict"; -const Files = require('./files'); -const Tasks = require('./tasks'); -const Folder = require('./folder'); -const ENCODES = require('../../base/encodes'); +const Files = require("./files"); +const Tasks = require("./tasks"); +const Folder = require("./folder"); +const logger = require('../logger') +const ENCODES = require("../../base/encodes"); -const fs = require('fs'); -const iconv = require('iconv-lite'); -const crypto = require('crypto'); +const fs = require("fs"); +const iconv = require("iconv-lite"); +const crypto = require("crypto"); const mime = require("mime"); const PATH = require("path"); const dialog = antSword.remote.dialog; - // 加载语言模板 -const LANG = antSword['language']['filemanager']; -const LANG_T = antSword['language']['toastr']; +const LANG = antSword["language"]["filemanager"]; +const LANG_T = antSword["language"]["toastr"]; class FileManager { - constructor(opts) { - const tabbar = antSword['tabbar']; + const tabbar = antSword["tabbar"]; const hash = String(Math.random()).substr(2, 10); tabbar.addTab( `tab_filemanager_${hash}`, - ` ${opts['ip']}`, - null, null, true, true + ` ${opts["ip"]}`, + null, + null, + true, + true ); // 创建框架 const cell = tabbar.cells(`tab_filemanager_${hash}`); // 增加到全局变量方便调试 - antSword['modules']['filemanager'] = antSword['modules']['filemanager'] || {}; - antSword['modules']['filemanager'][hash] = this; + antSword["modules"]["filemanager"] = + antSword["modules"]["filemanager"] || {}; + antSword["modules"]["filemanager"][hash] = this; let config = { openfileintab: false, bookmarks: {}, }; - this.config = JSON.parse(antSword['storage']("adefault_filemanager", false, JSON.stringify(config))); + this.config = JSON.parse( + antSword["storage"]("adefault_filemanager", false, JSON.stringify(config)) + ); this.isWin = true; - this.path = '/'; - this.home = '/'; + this.path = "/"; + this.home = "/"; this.devices = []; // this.cache = {}; this.cell = cell; this.opts = opts; - this.cache = new antSword['CacheManager'](opts['_id']); - this.core = new antSword['core'][opts['type']](opts); + this.cache = new antSword["CacheManager"](opts["_id"]); + this.core = new antSword["core"][opts["type"]](opts); this.win = new dhtmlXWindows(); this.win.attachViewportTo(this.cell.cell); // 获取基本信息 - const cache_info = this.cache.get('info'); + const cache_info = this.cache.get("info"); if (cache_info) { this.initUI(cache_info); } else { this.cell.progressOn(); - this.core.request( - this.core.base.info() - ).then((ret) => { - this.initUI(ret['text']); - this.cell.progressOff(); - }).catch((err) => { - this.cell.progressOff(); - this.cell.close(); - toastr.error((typeof(err) === 'object') ? JSON.stringify(err) : String(err), LANG_T['error']); - }); + this.core + .request(this.core.base.info()) + .then((ret) => { + this.initUI(ret["text"]); + this.cell.progressOff(); + }) + .catch((err) => { + this.cell.progressOff(); + this.cell.close(); + toastr.error( + typeof err === "object" ? JSON.stringify(err) : String(err), + LANG_T["error"] + ); + }); // this.core.base.info((ret) => { // this.initUI(ret); // this.cell.progressOff(); @@ -87,36 +96,38 @@ class FileManager { // 初始化UI initUI(ret) { // 判断获取数据是否正确 - let info = ret.split('\t'); + let info = ret.split("\t"); if (!info.length >= 2) { - toastr.error('Loading infomations failed!
' + ret, LANG_T['error']); - this.cache.del('info'); + toastr.error("Loading infomations failed!
" + ret, LANG_T["error"]); + this.cache.del("info"); return this.cell.close(); - }; - let info_path = info[0].replace(/\\/g, '/').replace(/\.$/, ''); + } + let info_path = info[0].replace(/\\/g, "/").replace(/\.$/, ""); let info_drive = info[1]; // 判断是否为linux - if (info_path.substr(0, 1) === '/') { + if (info_path.substr(0, 1) === "/") { this.isWin = false; } else { // windows 盘符统一大写 - info_path = `${info_path.substr(0, 1).toUpperCase()}${info_path.substr(1)}`; + info_path = `${info_path.substr(0, 1).toUpperCase()}${info_path.substr( + 1 + )}`; info_drive = info_drive.toUpperCase(); - }; + } this.path = info_path; this.home = info_path; - info_drive.split(':').map((_) => { + info_drive.split(":").map((_) => { if (!_) { - return - }; - this.devices.push(_ === '/' ? _ : _ + ':/'); + return; + } + this.devices.push(_ === "/" ? _ : _ + ":/"); }); // 模块对象 - const layout = this.cell.attachLayout('3L'); - this.folder = new Folder(layout.cells('a'), this); - this.files = new Files(layout.cells('b'), this); - this.tasks = new Tasks(layout.cells('c'), this); + const layout = this.cell.attachLayout("3L"); + this.folder = new Folder(layout.cells("a"), this); + this.files = new Files(layout.cells("b"), this); + this.tasks = new Tasks(layout.cells("c"), this); this.folder.cell.progressOn(); this.files.cell.progressOn(); @@ -130,155 +141,124 @@ class FileManager { // storage('save_key').get('{}') // storage('save_key').set('{a:123}') storage(key) { - let md5 = crypto.createHash('md5'); - md5.update(this.opts['url']); - const k = `${md5.digest('hex').substr(0, 11)}_${key}` + let md5 = crypto.createHash("md5"); + md5.update(this.opts["url"]); + const k = `${md5.digest("hex").substr(0, 11)}_${key}`; return { get: (def) => localStorage.getItem(k) || def, - set: (val) => localStorage.setItem(k, val) - } + set: (val) => localStorage.setItem(k, val), + }; } // 获取目录文件列表 getFiles(p, callback) { - let self = this; - if (self.isWin) { // 处理输入为 f:\ 这种情况 - p = p.replace(/\\/g, '/'); - p = p.substr(1, 2) == ":/" ? `${p.substr(0, 1).toUpperCase()}${p.substr(1)}` : p; + if (self.isWin) { + // 处理输入为 f:\ 这种情况 + p = p.replace(/\\/g, "/"); + p = + p.substr(1, 2) == ":/" + ? `${p.substr(0, 1).toUpperCase()}${p.substr(1)}` + : p; } let path = this.changePath(p); - if (self.isWin) { // 处理输入为 f: 这种情况 - path = path.substr(1, 2) == ":/" ? `${path.substr(0, 1).toUpperCase()}${path.substr(1)}` : path; + if (self.isWin) { + // 处理输入为 f: 这种情况 + path = + path.substr(1, 2) == ":/" + ? `${path.substr(0, 1).toUpperCase()}${path.substr(1)}` + : path; } let cache; - if (!path.endsWith('/')) { - path += '/' - }; + if (!path.endsWith("/")) { + path += "/"; + } this.path = path; - let cache_tag = 'filemanager-files-' + Buffer.from(this.path).toString('base64'); - - // 判断是否有缓存 - // if (cache = this.cache[path]) { - // return callback(cache); - // }; - if ((this.opts.otherConf || {})['filemanager-cache'] !== 0 && (cache = this.cache.get(cache_tag))) { + let cache_tag = + "filemanager-files-" + Buffer.from(this.path).toString("base64"); + if ( + (this.opts.otherConf || {})["filemanager-cache"] !== 0 && + (cache = this.cache.get(cache_tag)) + ) { return callback(JSON.parse(cache)); - }; - - this.core.request( - this.core.filemanager.dir({ - path: path - }) - ).then((res) => { - let ret = antSword.unxss(res['text']); - // 判断是否出错 - if (ret.startsWith('ERROR://')) { - callback([]); - return toastr.error(ret.substr(9), LANG_T['error']); - }; - let tmp = ret.split('\n'); - - tmp.sort(); - - let folders = []; - let files = []; + } - tmp.map((t) => { - let _ = t.split('\t'); - let d = { - name: _[0], - time: _[1], - size: _[2], - attr: _[3] - } - if (_[0].endsWith('/')) { - folders.push(d); - } else { - files.push(d); + this.core + .request( + this.core.filemanager.dir({ + path: path, + }) + ) + .then((res) => { + let ret = antSword.unxss(res["text"]); + // 判断是否出错 + if (ret.startsWith("ERROR://")) { + callback([]); + return toastr.error(ret.substr(9), LANG_T["error"]); } - }); + let tmp = ret.split("\n"); - let data = folders.concat(files); - callback(data); + tmp.sort(); - // 增加缓存 - // self.cache[path] = data; - this.cache.set(cache_tag, JSON.stringify(data)); - }).catch((err) => { - toastr.error((err instanceof Object) ? JSON.stringify(err) : String(err), LANG_T['error']); - this.folder.cell.progressOff(); - this.files.cell.progressOff(); - }) + let folders = []; + let files = []; - // this.core.filemanager.dir({ - // path: path - // }, (ret) => { - // // 判断是否出错 - // if (ret.startsWith('ERROR://')) { - // callback([]); - // return toastr.error(ret.substr(9), LANG_T['error']); - // }; - // let tmp = ret.split('\n'); - // - // tmp.sort(); - // - // let folders = []; - // let files = []; - // - // tmp.map( (t) => { - // let _ = t.split('\t'); - // let d = { - // name: _[0], - // time: _[1], - // size: _[2], - // attr: _[3] - // } - // if (_[0].endsWith('/')) { - // folders.push(d); - // }else{ - // files.push(d); - // } - // } ); - // - // let data = folders.concat(files); - // callback(data); - // - // // 增加缓存 - // // self.cache[path] = data; - // this.cache.set(cache_tag, JSON.stringify(data)); - // }, (err) => { - // toastr.error((err instanceof Object) ? JSON.stringify(err) : String(err), LANG_T['error']); - // }); + tmp.map((t) => { + let _ = t.split("\t"); + let d = { + name: _[0], + time: _[1], + size: _[2], + attr: _[3], + }; + if (_[0].endsWith("/")) { + folders.push(d); + } else { + files.push(d); + } + }); + + let data = folders.concat(files); + callback(data); + this.cache.set(cache_tag, JSON.stringify(data)); + }) + .catch((err) => { + toastr.error( + err instanceof Object ? JSON.stringify(err) : String(err), + LANG_T["error"] + ); + this.folder.cell.progressOff(); + this.files.cell.progressOff(); + }); } // 更改目录,返回最终绝对路径 changePath(path) { - if (!this.path.endsWith('/')) { - this.path += '/'; - }; - if (!path.endsWith('/')) { - path += '/'; - }; + if (!this.path.endsWith("/")) { + this.path += "/"; + } + if (!path.endsWith("/")) { + path += "/"; + } // 如果是当前目录,返回 - if (path === './') { + if (path === "./") { return this.path; // 如果是上级目录,则判断是否为最后一级?返回最后一级:返回上一级 - } else if (path === '../') { - let _ = this.path.split('/'); + } else if (path === "../") { + let _ = this.path.split("/"); if (_.length === 2) { - return _.join('/'); + return _.join("/"); } else if (_.length > 2) { _.pop(); _.pop(); - _.length === 1 ? _.push('') : 0; - return _.join('/'); + _.length === 1 ? _.push("") : 0; + return _.join("/"); } else { return this.path; } // 如果是根目录,返回 - } else if (path.startsWith('/') || path.substr(1, 2) === ':/') { + } else if (path.startsWith("/") || path.substr(1, 2) === ":/") { return path; // 如果是相对路径,返回绝对全路径 } else { @@ -286,18 +266,17 @@ class FileManager { } } - // 删除文件/目录 + // 删除文件/目录 TODO(zyx) deleteFile(files) { - let self = this; layer.confirm( - LANG['delete']['confirm'](files.length > 1 ? files.length : files[0]), // 已在 lang 中过滤 + LANG["delete"]["confirm"](files.length > 1 ? files.length : files[0]), // 已在 lang 中过滤 { icon: 2, shift: 6, //skin: 'layui-layer-molv', - title: ` ${LANG['delete']['title']}`, + title: ` ${LANG["delete"]["title"]}`, }, (_) => { layer.close(_); @@ -306,233 +285,329 @@ class FileManager { ((p) => { const path = this.path + p; this.files.cell.progressOn(); - this.core.request( - this.core.filemanager.delete({ - path: path + this.core + .request( + this.core.filemanager.delete({ + path: path, + }) + ) + .then((res) => { + let ret = res["text"]; + this.files.cell.progressOff(); + if (ret === "1") { + const logMessage = `File deleted successfully: ${path}`; + console.log(logMessage); + logger.appendToLogFile(logMessage);// 写入到日志文件 + toastr.success( + LANG["delete"]["success"](path), + LANG_T["success"] + ); + this.files.refreshPath(); + } else { + // 文件删除失败的逻辑 + const logMessage = `Failed to delete file: ${path}, Error: ${ + ret === "0" ? false : ret + }`; + console.error(logMessage); + logger.appendToLogFile(logMessage);; // 写入到日志文件 + + toastr.error( + LANG["delete"]["error"](path, ret === "0" ? false : ret), + LANG_T["error"] + ); + } }) - ).then((res) => { - let ret = res['text']; - this.files.cell.progressOff(); - if (ret === '1') { - toastr.success(LANG['delete']['success'](path), LANG_T['success']); - this.files.refreshPath(); - } else { - toastr.error(LANG['delete']['error'](path, ret === '0' ? false : ret), LANG_T['error']); - } - }).catch((err) => { - this.files.cell.progressOff(); - toastr.error(LANG['delete']['error'](path, err), LANG_T['error']); - }); - // this.core.filemanager.delete({ - // path: path - // }, (ret) => { - // this.files.cell.progressOff(); - // if (ret === '1') { - // toastr.success(LANG['delete']['success'](path), LANG_T['success']); - // this.files.refreshPath(); - // }else{ - // toastr.error(LANG['delete']['error'](path, ret === '0' ? false : ret), LANG_T['error']); - // } - // }, (err) => { - // this.files.cell.progressOff(); - // toastr.error(LANG['delete']['error'](path, err), LANG_T['error']); - // }) + .catch((err) => { + this.files.cell.progressOff(); + // 请求失败的逻辑 + const logMessage = `Failed to delete file: ${path}, Error: ${err}`; + console.error(logMessage); + toastr.error( + LANG["delete"]["error"](path, err), + LANG_T["error"] + ); + logger.appendToLogFile(logMessage);; // 写入到日志文件 + }); })(p); }); } - ) - + ); } - // 粘贴文件/文件夹 + // 粘贴文件/文件夹 TODO(zyx) // source: 复制源文件/目录 // name: 复制文件/目录名 pasteFile(source, name) { - const target = this.path + name; this.files.cell.progressOn(); - this.core.request( - this.core.filemanager.copy({ - path: source, - target: target - }) - ).then((res) => { - let ret = res['text']; - this.files.cell.progressOff(); - if (ret === '1') { - // 刷新目录 - this.files.refreshPath(); - // 删除缓存 - delete this.files.Clipboard[name]; - toastr.success(LANG['paste']['success'](name), LANG_T['success']); - } else { - toastr.error(LANG['paste']['error'](name, ret === '0' ? false : ret), LANG_T['error']); - } - }).catch((err) => { - toastr.error(LANG['paste']['error'](name, err), LANG_T['error']); - }); - } - - // 重命名 - renameFile(name) { - const isDir = name.endsWith('/'); - layer.prompt({ - value: antSword.noxss(name.replace(/\/$/, '')), - title: ` ${LANG['rename']['title']} (${antSword.noxss(name)})` - }, (value, index, elem) => { - this.files.cell.progressOn(); - this.core.request( - this.core.filemanager.rename({ - path: this.path + name, - name: this.path + value + ((isDir && !value.endsWith('/')) ? '/' : '') + this.core + .request( + this.core.filemanager.copy({ + path: source, + target: target, }) - ).then((res) => { - let ret = res['text']; + ) + .then((res) => { + let ret = res["text"]; this.files.cell.progressOff(); - if (ret === '1') { + if (ret === "1") { + // 刷新目录 this.files.refreshPath(); - toastr.success(LANG['rename']['success'], LANG_T['success']); + // 删除缓存 + delete this.files.Clipboard[name]; + toastr.success(LANG["paste"]["success"](name), LANG_T["success"]); } else { - toastr.error(LANG['rename']['error'](ret === '0' ? false : ret), LANG_T['error']); + toastr.error( + LANG["paste"]["error"](name, ret === "0" ? false : ret), + LANG_T["error"] + ); } - }).catch((err) => { - toastr.error(LANG['rename']['error'](err), LANG_T['error']); + }) + .catch((err) => { + toastr.error(LANG["paste"]["error"](name, err), LANG_T["error"]); }); - layer.close(index); - }); } - // 新建目录 + // 重命名 + renameFile(name) { + const isDir = name.endsWith("/"); + layer.prompt( + { + value: antSword.noxss(name.replace(/\/$/, "")), + title: ` ${ + LANG["rename"]["title"] + } (${antSword.noxss(name)})`, + }, + (value, index, elem) => { + this.files.cell.progressOn(); + this.core + .request( + this.core.filemanager.rename({ + path: this.path + name, + name: + this.path + value + (isDir && !value.endsWith("/") ? "/" : ""), + }) + ) + .then((res) => { + let ret = res["text"]; + this.files.cell.progressOff(); + if (ret === "1") { + this.files.refreshPath(); + toastr.success(LANG["rename"]["success"], LANG_T["success"]); + const logMessage = `File/Direcotry ${name} renamed to ${value}`; + logger.appendToLogFile(logMessage); + } else { + toastr.error( + LANG["rename"]["error"](ret === "0" ? false : ret), + LANG_T["error"] + ); + } + }) + .catch((err) => { + toastr.error(LANG["rename"]["error"](err), LANG_T["error"]); + }); + layer.close(index); + } + ); + } + + // 新建目录 TODO(zyx) createFolder() { - layer.prompt({ - value: LANG['createFolder']['value'], - title: ` ${LANG['createFolder']['title']}` - }, (value, i, e) => { - this.files.cell.progressOn(); - this.core.request( - this.core.filemanager.mkdir({ - path: this.path + value - }) - ).then((res) => { - let ret = res['text']; - this.files.cell.progressOff(); - if (ret === '1') { - this.files.refreshPath(); - toastr.success(LANG['createFolder']['success'](value), LANG_T['success']); - } else { - toastr.error(LANG['createFolder']['error'](value, ret === '0' ? false : ret), LANG_T['error']); - } - }).catch((err) => { - toastr.error(LANG['createFolder']['error'](value, err), LANG_T['error']); - }); - layer.close(i); - }); + layer.prompt( + { + value: LANG["createFolder"]["value"], + title: ` ${LANG["createFolder"]["title"]}`, + }, + (value, i, e) => { + this.files.cell.progressOn(); + this.core + .request( + this.core.filemanager.mkdir({ + path: this.path + value, + }) + ) + .then((res) => { + let ret = res["text"]; + this.files.cell.progressOff(); + if (ret === "1") { + this.files.refreshPath(); + toastr.success( + LANG["createFolder"]["success"](value), + LANG_T["success"] + ); + const logMessage = `create folder ${value}`; + logger.appendToLogFile(logMessage); + + } else { + toastr.error( + LANG["createFolder"]["error"](value, ret === "0" ? false : ret), + LANG_T["error"] + ); + } + }) + .catch((err) => { + toastr.error( + LANG["createFolder"]["error"](value, err), + LANG_T["error"] + ); + }); + layer.close(i); + } + ); } - // 新建文件 + // 新建文件 TODO(zyx) createFile() { - layer.prompt({ - value: LANG['createFile']['value'], - title: ` ${LANG['createFile']['title']}` - }, (value, i, e) => { - this.files.cell.progressOn(); - - // 发起http请求 - this.core.request( - this.core.filemanager.create_file({ - path: this.path + value, - content: '#Halo AntSword!' - }) - ).then((res) => { - let ret = res['text']; - this.files.cell.progressOff(); - if (ret === '1') { - this.files.refreshPath(); - toastr.success(LANG['createFile']['success'](value), LANG_T['success']); - } else { - toastr.error(LANG['createFile']['error'](value, ret === '0' ? false : ret), LANG_T['error']); - } - }).catch((err) => { - toastr.error(LANG['createFile']['error'](value, err), LANG_T['error']); - }); - layer.close(i); - }) + layer.prompt( + { + value: LANG["createFile"]["value"], + title: ` ${LANG["createFile"]["title"]}`, + }, + (value, i, e) => { + this.files.cell.progressOn(); + + // 发起http请求 + this.core + .request( + this.core.filemanager.create_file({ + path: this.path + value, + content: "#Halo AntSword!", + }) + ) + .then((res) => { + let ret = res["text"]; + this.files.cell.progressOff(); + if (ret === "1") { + this.files.refreshPath(); + toastr.success( + LANG["createFile"]["success"](value), + LANG_T["success"] + ); + const logMessage = `create file ${value}`; + logger.appendToLogFile(logMessage) + } else { + toastr.error( + LANG["createFile"]["error"](value, ret === "0" ? false : ret), + LANG_T["error"] + ); + } + }) + .catch((err) => { + toastr.error( + LANG["createFile"]["error"](value, err), + LANG_T["error"] + ); + }); + layer.close(i); + } + ); } - // 重命名文件/夹 + // 重命名文件/夹 TODO(zyx) retimeFile(name, oldtime) { - layer.prompt({ - value: oldtime, - title: ` ${LANG['retime']['title']} (${antSword.noxss(name)})`, - content: `` - }, (value, i, e) => { - this.files.cell.progressOn(); - let path = this.path; - if (this.isWin) { - path = path.replace(/\//g, '\\') - } - // http request - this.core.request( - this.core.filemanager.retime({ - // path: this.path + name, - path: path + name, - time: value - }) - ).then((res) => { - let ret = res['text']; - this.files.cell.progressOff(); - if (ret === '1') { - this.files.refreshPath(); - toastr.success(LANG['retime']['success'](name), LANG_T['success']); - } else { - toastr.error(LANG['retime']['error'](name, ret === '0' ? false : ret), LANG_T['error']); + layer.prompt( + { + value: oldtime, + title: ` ${ + LANG["retime"]["title"] + } (${antSword.noxss(name)})`, + content: ``, + }, + (value, i, e) => { + this.files.cell.progressOn(); + let path = this.path; + if (this.isWin) { + path = path.replace(/\//g, "\\"); } - }).catch((err) => { - toastr.error(LANG['retime']['error'](name, err), LANG_T['error']); - }); - layer.close(i); - }) + // http request + this.core + .request( + this.core.filemanager.retime({ + // path: this.path + name, + path: path + name, + time: value, + }) + ) + .then((res) => { + let ret = res["text"]; + this.files.cell.progressOff(); + if (ret === "1") { + this.files.refreshPath(); + toastr.success( + LANG["retime"]["success"](name), + LANG_T["success"] + ); + } else { + toastr.error( + LANG["retime"]["error"](name, ret === "0" ? false : ret), + LANG_T["error"] + ); + } + }) + .catch((err) => { + toastr.error(LANG["retime"]["error"](name, err), LANG_T["error"]); + }); + layer.close(i); + } + ); } // 设置文件和目录权限 chmodFile(name, oldmod) { - layer.prompt({ - value: antSword.noxss(oldmod), - title: ` ${LANG['chmod']['title']} (${antSword.noxss(name)})`, - }, (value, i, e) => { - if (this.core.constructor.name == "PSWINDOWS" && !value.match(/^(-|d)(-|a)(-|r)(-|h)(-|s)$/)) { - toastr.error("PS FileMode Pattern Error, eg: -arh-", LANG_T['error']); - return - } else if (this.core.constructor.name != "PSWINDOWS" && !value.match(/^[0-7]{4}$/)) { - toastr.error(LANG['chmod']['check'], LANG_T['error']); - return - } - this.files.cell.progressOn(); - let path = this.path; - if (this.isWin) { - path = path.replace(/\//g, '\\') - } - // http request - this.core.request( - this.core.filemanager.chmod({ - path: path + name, - mode: value - }) - ).then((res) => { - let ret = res['text']; - this.files.cell.progressOff(); - if (ret === '1') { - this.files.refreshPath(); - toastr.success(LANG['chmod']['success'](name), LANG_T['success']); - } else { - toastr.error(LANG['chmod']['error'](name, ret === '0' ? false : ret), LANG_T['error']); + layer.prompt( + { + value: antSword.noxss(oldmod), + title: ` ${ + LANG["chmod"]["title"] + } (${antSword.noxss(name)})`, + }, + (value, i, e) => { + if ( + this.core.constructor.name == "PSWINDOWS" && + !value.match(/^(-|d)(-|a)(-|r)(-|h)(-|s)$/) + ) { + toastr.error("PS FileMode Pattern Error, eg: -arh-", LANG_T["error"]); + return; + } else if ( + this.core.constructor.name != "PSWINDOWS" && + !value.match(/^[0-7]{4}$/) + ) { + toastr.error(LANG["chmod"]["check"], LANG_T["error"]); + return; } - }).catch((err) => { - toastr.error(LANG['chmod']['error'](name, err), LANG_T['error']); - }); - layer.close(i); - }); + this.files.cell.progressOn(); + let path = this.path; + if (this.isWin) { + path = path.replace(/\//g, "\\"); + } + // http request + this.core + .request( + this.core.filemanager.chmod({ + path: path + name, + mode: value, + }) + ) + .then((res) => { + let ret = res["text"]; + this.files.cell.progressOff(); + if (ret === "1") { + this.files.refreshPath(); + toastr.success(LANG["chmod"]["success"](name), LANG_T["success"]); + } else { + toastr.error( + LANG["chmod"]["error"](name, ret === "0" ? false : ret), + LANG_T["error"] + ); + } + }) + .catch((err) => { + toastr.error(LANG["chmod"]["error"](name, err), LANG_T["error"]); + }); + layer.close(i); + } + ); } // 预览文件(图片、视频) @@ -540,90 +615,121 @@ class FileManager { let that = this; const remote_path = this.path + name; const win = that.createWin({ - title: 'Loading File: ' + antSword.noxss(remote_path), + title: "Loading File: " + antSword.noxss(remote_path), width: 800, height: 600, }); var filemime = mime.getType(name); - let savepath = PATH.join(process.env.AS_WORKDIR, `antData/.temp/`, Buffer.from(name).toString("hex")); - win.cell.lastChild['style']['overflow'] = 'scroll'; - win.cell.lastChild['style']['textAlign'] = 'center'; + let savepath = PATH.join( + process.env.AS_WORKDIR, + `antData/.temp/`, + Buffer.from(name).toString("hex") + ); + win.cell.lastChild["style"]["overflow"] = "scroll"; + win.cell.lastChild["style"]["textAlign"] = "center"; let down_size = 0; - this.core.download( - savepath, this.core.filemanager.download_file({ - path: remote_path - }), (_size) => { - down_size += _size; - let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100); - if (!(down_progress % 5)) { - win.setText(`Preview File: ${antSword.noxss(remote_path)} ${down_progress}%`); - }; - } - ).then((_size) => { - if (_size === size) { - win.setText(`Preview File: ${antSword.noxss(remote_path)}`); - let buff = fs.readFileSync(savepath); - switch (filemime) { - default: let data = Buffer.from(buff).toString('base64'); - win.attachHTMLString(``); - break; + this.core + .download( + savepath, + this.core.filemanager.download_file({ + path: remote_path, + }), + (_size) => { + down_size += _size; + let down_progress = parseInt( + parseFloat(down_size / size).toFixed(2) * 100 + ); + if (!(down_progress % 5)) { + win.setText( + `Preview File: ${antSword.noxss(remote_path)} ${down_progress}%` + ); + } } - fs.unlink(savepath); - } else { - fs.unlink(savepath); - throw Error(`Load Error: downsize ${_size} != ${size}`); - } - }).catch((err) => { - - }); + ) + .then((_size) => { + if (_size === size) { + win.setText(`Preview File: ${antSword.noxss(remote_path)}`); + let buff = fs.readFileSync(savepath); + switch (filemime) { + default: + let data = Buffer.from(buff).toString("base64"); + win.attachHTMLString( + `` + ); + break; + } + fs.unlink(savepath); + } else { + fs.unlink(savepath); + throw Error(`Load Error: downsize ${_size} != ${size}`); + } + }) + .catch((err) => {}); } // 下载文件 downloadFile(name, size) { const path = this.path + name; - const task = this.tasks.new(LANG['download']['task']['name'], path, LANG['download']['task']['wait']); + const task = this.tasks.new( + LANG["download"]["task"]["name"], + path, + LANG["download"]["task"]["wait"] + ); // 获取要保存的路径 - dialog.showSaveDialog({ - title: LANG['download']['title'], - defaultPath: name - }, (filePath) => { - if (!filePath) { - return task.end(LANG['download']['task']['cancel']) - }; - task.update(LANG['download']['task']['start']); - let down_size = 0; - // 删除旧文件(如果存在 - if (fs.existsSync(filePath)) { - fs.unlinkSync(filePath); - } - this.core.download( - filePath, this.core.filemanager.download_file({ - path: path - }), (_size) => { - // 计算进度百分比 - down_size += _size; - let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100); - - if (!(down_progress % 5)) { - task.update(down_progress + '%'); - }; + dialog.showSaveDialog( + { + title: LANG["download"]["title"], + defaultPath: name, + }, + (filePath) => { + if (!filePath) { + return task.end(LANG["download"]["task"]["cancel"]); } - ).then((_size) => { - if (_size === size) { - task.success(LANG['download']['task']['success']); - toastr.success(LANG['download']['success'](name), LANG_T['success']); - // }else if (_size === 21) { - // task.failed('len=' + _size); - } else { - throw Error(`SizeErr: ${_size} != ${size}`); - // task.failed(LANG['download']['task']['error']()) + task.update(LANG["download"]["task"]["start"]); + let down_size = 0; + // 删除旧文件(如果存在 + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath); } - }).catch((err) => { - task.failed(LANG['download']['task']['error'](err)); - toastr.error(LANG['download']['error'](name, err), LANG_T['error']); - }); - }); + this.core + .download( + filePath, + this.core.filemanager.download_file({ + path: path, + }), + (_size) => { + // 计算进度百分比 + down_size += _size; + let down_progress = parseInt( + parseFloat(down_size / size).toFixed(2) * 100 + ); + + if (!(down_progress % 5)) { + task.update(down_progress + "%"); + } + } + ) + .then((_size) => { + if (_size === size) { + task.success(LANG["download"]["task"]["success"]); + toastr.success( + LANG["download"]["success"](name), + LANG_T["success"] + ); + const logMessage = `File download successfully: ${path}`; + logger.appendToLogFile(logMessage);// 写入到日志文件 + } else { + throw Error(`SizeErr: ${_size} != ${size}`); + // task.failed(LANG['download']['task']['error']()) + } + }) + .catch((err) => { + task.failed(LANG["download"]["task"]["error"](err)); + toastr.error(LANG["download"]["error"](name, err), LANG_T["error"]); + }); + } + ); } // 下载多个文件 @@ -631,8 +737,8 @@ class FileManager { downloadFileMulti(names = []) { let self = this; let selectPaths = dialog.showOpenDialog({ - title: LANG['download']['title'], - properties: ['openDirectory'], + title: LANG["download"]["title"], + properties: ["openDirectory"], }); let savePath = null; if (selectPaths && selectPaths.length === 1) { @@ -643,30 +749,42 @@ class FileManager { } names.forEach((item) => { const path = self.path + item.name; - const task = self - .tasks - .new(LANG['download']['task']['name'], path, LANG['download']['task']['wait']); - task.update(LANG['download']['task']['start']); + const task = self.tasks.new( + LANG["download"]["task"]["name"], + path, + LANG["download"]["task"]["wait"] + ); + task.update(LANG["download"]["task"]["start"]); let down_size = 0; let filePath = PATH.join(savePath, item.name); // 删除旧文件(如果存在 if (fs.existsSync(filePath)) { fs.unlinkSync(filePath); } - self.core.download(filePath, self.core.filemanager.download_file({ - path: path - }), (_size) => { - // 计算进度百分比 - down_size += _size; - let down_progress = parseInt(parseFloat(down_size / item.size).toFixed(2) * 100); - if (!(down_progress % 5)) { - task.update(down_progress + '%'); - }; - }) + self.core + .download( + filePath, + self.core.filemanager.download_file({ + path: path, + }), + (_size) => { + // 计算进度百分比 + down_size += _size; + let down_progress = parseInt( + parseFloat(down_size / item.size).toFixed(2) * 100 + ); + if (!(down_progress % 5)) { + task.update(down_progress + "%"); + } + } + ) .then((_size) => { if (_size === item.size) { - task.success(LANG['download']['task']['success']); - toastr.success(LANG['download']['success'](name), LANG_T['success']); + task.success(LANG["download"]["task"]["success"]); + toastr.success( + LANG["download"]["success"](name), + LANG_T["success"] + ); // }else if (_size === 21) { task.failed('len=' + _size); } else { throw Error(`SizeErr: ${_size} != ${item.size}`); @@ -674,8 +792,8 @@ class FileManager { } }) .catch((err) => { - task.failed(LANG['download']['task']['error'](err)); - toastr.error(LANG['download']['error'](name, err), LANG_T['error']); + task.failed(LANG["download"]["task"]["error"](err)); + toastr.error(LANG["download"]["error"](name, err), LANG_T["error"]); }); }); } @@ -686,50 +804,62 @@ class FileManager { let hash = +new Date(); // 获取URL let _index = layer.prompt({ - title: ` ${LANG['wget']['title']}`, - content: '

', - btn: ['wget'], + title: ` ${LANG["wget"]["title"]}`, + content: + '

', + btn: ["wget"], yes: (i) => { - let _url = $(`#url_${hash}`); let _path = $(`#path_${hash}`); let url = _url.val(); let path = _path.val(); - if (url.split('/').length < 4) { + if (url.split("/").length < 4) { _url.focus(); - return toastr.warning(LANG['wget']['check'], LANG_T['warning']); - }; + return toastr.warning(LANG["wget"]["check"], LANG_T["warning"]); + } if (path.length < 1) { return _path.focus(); - }; - const task = this.tasks.new(LANG['wget']['task']['name'], `${url} -> ${path}`); - task.update(LANG['wget']['task']['start']); + } + const task = this.tasks.new( + LANG["wget"]["task"]["name"], + `${url} -> ${path}` + ); + task.update(LANG["wget"]["task"]["start"]); // http request - this.core.request( - this.core.filemanager.wget({ - url: url, - path: path + this.core + .request( + this.core.filemanager.wget({ + url: url, + path: path, + }) + ) + .then((res) => { + let ret = res["text"]; + // 下载成功?当前目录?刷新:删除缓存 + if (ret === "1") { + task.success(LANG["wget"]["task"]["success"]); + let _ = path.substr(0, path.lastIndexOf("/") + 1); + this.files.refreshPath(_ === self.path ? false : _); + } else { + task.failed(LANG["wget"]["task"]["failed"](ret)); + } }) - ).then((res) => { - let ret = res['text']; - // 下载成功?当前目录?刷新:删除缓存 - if (ret === '1') { - task.success(LANG['wget']['task']['success']); - let _ = path.substr(0, path.lastIndexOf('/') + 1); - this.files.refreshPath((_ === self.path) ? false : _); - } else { - task.failed(LANG['wget']['task']['failed'](ret)); - } - }).catch((err) => { - task.failed(LANG['wget']['task']['error'](err)); - }); + .catch((err) => { + task.failed(LANG["wget"]["task"]["error"](err)); + }); layer.close(i); - } + }, }); - $(`#layui-layer${_index}`).css('width', '400px'); + $(`#layui-layer${_index}`).css("width", "400px"); } /** @@ -747,124 +877,164 @@ class FileManager { if (Array.isArray(_filePaths) && _filePaths.length > 0) { return res(_filePaths); } - dialog.showOpenDialog({ - properties: ['openFile', 'multiSelections'] - }, (_filePaths) => { - if (!_filePaths) { - return - }; - return res(_filePaths); - }) - }).then((filePaths) => { - // 初始化任务 - filePaths.map((f) => { - const fileName = f.substr(f.lastIndexOf(PATH.sep) + 1); - tasks[f] = this.tasks.new(LANG['upload']['task']['name'], `${fileName} => ${path}`, 'Waiting for uploading..'); - }); - return filePaths; - }).then((filePaths) => { - // 文件上传(逐个队列上传 - const upload = () => { - new Promise((res, rej) => { - // 获取单个上传文件 - let filePath = filePaths.shift(); - if (filePath) { - res(filePath); - } - }).then((filePath) => { - // 上传单个 - let buffIndex = 0; - let buff = []; - // 分段上传大小,默认0.5M(jsp 超过1M响应会出错) - let dataSplit = 500 * 1024; - if (parseInt((this.opts.otherConf || {})['upload-fragment']) > 0) { - dataSplit = parseInt((this.opts.otherConf || {})['upload-fragment']) * 1024; - } - let task = tasks[filePath]; - // 获取文件名 - let fileName = filePath.substr(filePath.lastIndexOf(PATH.sep) + 1); - // 读取文件buff - let fileBuff; - try { - fileBuff = fs.readFileSync(filePath); - } catch (e) { - return task.failed(e); - } - // 文件数据分段 - let buffLength = fileBuff.length; - while (buffIndex <= buffLength) { - let buffSplit = fileBuff.slice(buffIndex, buffIndex + dataSplit); - buffIndex += dataSplit; - buff.push(buffSplit); + dialog.showOpenDialog( + { + properties: ["openFile", "multiSelections"], + }, + (_filePaths) => { + if (!_filePaths) { + return; } - // 开始上传 - const uploadBuffFunc = (_buff) => { - new Promise((res, rej) => { - let _b = _buff.shift(); - if (_b) { - res(_b); - } else { - // 上传完毕 - task.success(LANG['upload']['task']['success']); - toastr.success(LANG['upload']['success'](fileName), LANG_T['success']); - // 刷新缓存 - this.files.refreshPath(path === this.path ? '' : path); - // 继续上传 - return upload(); - } - }).then((b) => { - // 更新进度条 - task.update(`${parseInt((buffLength - (b.length * _buff.length)) / buffLength * 100)}%`); - this.core.request( - this.core.filemanager.upload_file({ - path: path + fileName, - content: b - }) - ).then((res) => { - let ret = res['text']; - if (ret === '1') { - return uploadBuffFunc(_buff); - } - task.failed(LANG['upload']['task']['failed'](ret)); - toastr.error(LANG['upload']['error']( - fileName, - ret === '0' ? '' : `
${ret}` - ), LANG_T['error']); - }).catch((err) => { - // 出错后友好提示 - let errmsg = err; - if (err.hasOwnProperty('status') && err.hasOwnProperty('response')) { - errmsg = `${err.status} ${err.response.res.statusMessage}`; - switch (err.status) { - case 413: - errmsg += `${LANG['upload']['task']['httperr_413']}`; - break; - default: - break; - } - } else if (err.hasOwnProperty('errno')) { - switch (err.errno) { - case 'ETIME': - errmsg = `${LANG['upload']['task']['httperr_etime']}`; - break; - case 'ECONNREFUSED': - errmsg = `${LANG['upload']['task']['httperr_econnrefused']}`; - break; - default: - errmsg = `${err.errno} ${err.code}`; - break; + return res(_filePaths); + } + ); + }) + .then((filePaths) => { + // 初始化任务 + filePaths.map((f) => { + const fileName = f.substr(f.lastIndexOf(PATH.sep) + 1); + tasks[f] = this.tasks.new( + LANG["upload"]["task"]["name"], + `${fileName} => ${path}`, + "Waiting for uploading.." + ); + }); + return filePaths; + }) + .then((filePaths) => { + // 文件上传(逐个队列上传 + const upload = () => { + new Promise((res, rej) => { + // 获取单个上传文件 + let filePath = filePaths.shift(); + if (filePath) { + res(filePath); + } + }).then((filePath) => { + // 上传单个 + let buffIndex = 0; + let buff = []; + // 分段上传大小,默认0.5M(jsp 超过1M响应会出错) + let dataSplit = 500 * 1024; + if (parseInt((this.opts.otherConf || {})["upload-fragment"]) > 0) { + dataSplit = + parseInt((this.opts.otherConf || {})["upload-fragment"]) * 1024; + } + let task = tasks[filePath]; + // 获取文件名 + let fileName = filePath.substr(filePath.lastIndexOf(PATH.sep) + 1); + // 读取文件buff + let fileBuff; + try { + fileBuff = fs.readFileSync(filePath); + } catch (e) { + return task.failed(e); + } + // 文件数据分段 + let buffLength = fileBuff.length; + while (buffIndex <= buffLength) { + let buffSplit = fileBuff.slice(buffIndex, buffIndex + dataSplit); + buffIndex += dataSplit; + buff.push(buffSplit); + } + // 开始上传 + const uploadBuffFunc = (_buff) => { + new Promise((res, rej) => { + let _b = _buff.shift(); + if (_b) { + res(_b); + } else { + // 上传完毕 + task.success(LANG["upload"]["task"]["success"]); + toastr.success( + LANG["upload"]["success"](fileName), + LANG_T["success"] + ); + // 刷新缓存 + this.files.refreshPath(path === this.path ? "" : path); + + try { + const logMessage = `File uploaded successfully: ${fileName}` + logger.appendToLogFile(logMessage); + console.log("File uploaded successfully."); + } catch (err) { + console.error( + `Error appending to ${logFilePath}:`, + err.message + ); } + // 继续上传 + return upload(); } - task.failed(LANG['upload']['task']['error'](errmsg)); - toastr.error(LANG['upload']['error'](fileName, errmsg), LANG_T['error']); + }).then((b) => { + // 更新进度条 + task.update( + `${parseInt( + ((buffLength - b.length * _buff.length) / buffLength) * 100 + )}%` + ); + this.core + .request( + this.core.filemanager.upload_file({ + path: path + fileName, + content: b, + }) + ) + .then((res) => { + let ret = res["text"]; + if (ret === "1") { + return uploadBuffFunc(_buff); + } + task.failed(LANG["upload"]["task"]["failed"](ret)); + toastr.error( + LANG["upload"]["error"]( + fileName, + ret === "0" ? "" : `
${ret}` + ), + LANG_T["error"] + ); + }) + .catch((err) => { + // 出错后友好提示 + let errmsg = err; + if ( + err.hasOwnProperty("status") && + err.hasOwnProperty("response") + ) { + errmsg = `${err.status} ${err.response.res.statusMessage}`; + switch (err.status) { + case 413: + errmsg += `${LANG["upload"]["task"]["httperr_413"]}`; + break; + default: + break; + } + } else if (err.hasOwnProperty("errno")) { + switch (err.errno) { + case "ETIME": + errmsg = `${LANG["upload"]["task"]["httperr_etime"]}`; + break; + case "ECONNREFUSED": + errmsg = `${LANG["upload"]["task"]["httperr_econnrefused"]}`; + break; + default: + errmsg = `${err.errno} ${err.code}`; + break; + } + } + task.failed(LANG["upload"]["task"]["error"](errmsg)); + toastr.error( + LANG["upload"]["error"](fileName, errmsg), + LANG_T["error"] + ); + }); }); - }) - } - uploadBuffFunc(buff); - }); - }; - upload(); - }); + }; + uploadBuffFunc(buff); + }); + }; + upload(); + }); } // 编辑文件 @@ -872,71 +1042,74 @@ class FileManager { let self = this; let path = this.path + name; let editor = null; - let codes = ''; + let codes = ""; let win; - let hinttext = ''; - let tooltip = `IP:${this.opts['ip']} File:`; + let hinttext = ""; + let tooltip = `IP:${this.opts["ip"]} File:`; if (openfileintab == false) { win = this.createWin({ - title: LANG['editor']['title'](antSword.noxss(path)), - width: 800 + title: LANG["editor"]["title"](antSword.noxss(path)), + width: 800, }); win.maximize(); } else { let _id = String(Math.random()).substr(5, 10); - antSword['tabbar'].addTab( + antSword["tabbar"].addTab( `tab_file_${_id}`, ` ${antSword.noxss(name)}`, - null, null, true, true + null, + null, + true, + true ); - win = antSword['tabbar'].cells(`tab_file_${_id}`); + win = antSword["tabbar"].cells(`tab_file_${_id}`); let hitpath = path; if (path.length > 100) { - let tmpbuf = Buffer.alloc(100, '.'); + let tmpbuf = Buffer.alloc(100, "."); tmpbuf.write(this.path, 0, 100 - name.length - 4); - tmpbuf.write('/', 100 - name.length - 1); + tmpbuf.write("/", 100 - name.length - 1); tmpbuf.write(name, 100 - name.length); hitpath = tmpbuf.toString(); } - hinttext = `IP:${this.opts['ip']} File:`; + hinttext = `IP:${this.opts["ip"]} File:`; } win.progressOn(); // 检测文件后缀 - let ext = name.substr(name.lastIndexOf('.') + 1); + let ext = name.substr(name.lastIndexOf(".") + 1); let ext_dict = { - 'php': 'php', - 'c': 'c_cpp', - 'cpp': 'c_cpp', - 'h': 'c_cpp', - 'coffee': 'coffee', - 'cfm': 'coldfusion', - 'css': 'css', - 'go': 'golang', - 'html': 'html', - 'ini': 'ini', - 'conf': 'ini', - 'jade': 'jade', - 'java': 'java', - 'js': 'javascript', - 'json': 'json', - 'jsp': 'jsp', - 'jsx': 'jsx', - 'less': 'less', - 'lua': 'lua', - 'md': 'markdown', - 'sql': 'sql', - 'pl': 'perl', - 'py': 'python', - 'rb': 'ruby', - 'sh': 'sh', - 'txt': 'text', - 'xml': 'xml' - } - if (!(ext in ext_dict)) { - ext = 'txt' + php: "php", + c: "c_cpp", + cpp: "c_cpp", + h: "c_cpp", + coffee: "coffee", + cfm: "coldfusion", + css: "css", + go: "golang", + html: "html", + ini: "ini", + conf: "ini", + jade: "jade", + java: "java", + js: "javascript", + json: "json", + jsp: "jsp", + jsx: "jsx", + less: "less", + lua: "lua", + md: "markdown", + sql: "sql", + pl: "perl", + py: "python", + rb: "ruby", + sh: "sh", + txt: "text", + xml: "xml", }; + if (!(ext in ext_dict)) { + ext = "txt"; + } // 创建窗口工具栏 let toolbar = win.attachToolbar(); let _options = []; @@ -945,202 +1118,221 @@ class FileManager { let _opt = { id: `mode_${_ext}`, text: `${_ext} (.${_})`, - icon: 'code', - type: 'button' + icon: "code", + type: "button", }; - (_ === ext) ? _opt['selected'] = true: 0; + _ === ext ? (_opt["selected"] = true) : 0; _options.push(_opt); } - toolbar.loadStruct([{ - id: 'hinttext', - type: 'text', - text: hinttext + toolbar.loadStruct([ + { + id: "hinttext", + type: "text", + text: hinttext, }, { - id: 'filepath', - type: 'buttonInput', + id: "filepath", + type: "buttonInput", width: 500, value: antSword.noxss(path), }, { - type: 'separator' + type: "separator", }, { - type: 'spacer' + type: "spacer", }, { - id: 'refresh', - type: 'button', - icon: 'refresh', - text: LANG['editor']['toolbar']['refresh'] + id: "refresh", + type: "button", + icon: "refresh", + text: LANG["editor"]["toolbar"]["refresh"], }, { - id: 'save', - type: 'button', - icon: 'save', - text: LANG['editor']['toolbar']['save'] + id: "save", + type: "button", + icon: "save", + text: LANG["editor"]["toolbar"]["save"], }, { - type: 'separator' + type: "separator", }, { - id: 'encode', - type: 'buttonSelect', - icon: 'language', + id: "encode", + type: "buttonSelect", + icon: "language", openAll: true, - text: LANG['editor']['toolbar']['encode'], + text: LANG["editor"]["toolbar"]["encode"], options: (() => { let ret = []; ENCODES.map((_) => { let _opt_ = { id: `encode_${_}`, text: _, - icon: 'font', - type: 'button' + icon: "font", + type: "button", }; - (_ === self.opts['encode'] ? _opt_['selected'] = true : 0); + _ === self.opts["encode"] ? (_opt_["selected"] = true) : 0; ret.push(_opt_); }); return ret; - })() - }, { - id: 'mode', - type: 'buttonSelect', - icon: 'th-list', + })(), + }, + { + id: "mode", + type: "buttonSelect", + icon: "th-list", openAll: true, - text: LANG['editor']['toolbar']['mode'], - options: _options + text: LANG["editor"]["toolbar"]["mode"], + options: _options, }, ]); - toolbar.setItemToolTip('hinttext', tooltip); - toolbar.attachEvent('onClick', (id) => { - if (id === 'save') { + toolbar.setItemToolTip("hinttext", tooltip); + toolbar.attachEvent("onClick", (id) => { + if (id === "save") { // 保存代码 win.progressOn(); - self.core.request( - self.core.filemanager.create_file({ - path: path, - content: editor.session.getValue() || '#Halo AntSword!' + self.core + .request( + self.core.filemanager.create_file({ + path: path, + content: editor.session.getValue() || "#Halo AntSword!", + }) + ) + .then((res) => { + let ret = res["text"]; + win.progressOff(); + if (ret === "1") { + toastr.success( + LANG["editor"]["success"](path), + LANG_T["success"] + ); + // 刷新目录(显示更改时间、大小等) + self.files.refreshPath(); + } else { + toastr.error( + LANG["editor"]["error"](path, ret === "0" ? "" : "
" + ret), + LANG_T["error"] + ); + } }) - ).then((res) => { - let ret = res['text']; - win.progressOff(); - if (ret === '1') { - toastr.success(LANG['editor']['success'](path), LANG_T['success']); - // 刷新目录(显示更改时间、大小等) - self.files.refreshPath(); - } else { - toastr.error(LANG['editor']['error'](path, ret === '0' ? '' : '
' + ret), LANG_T['error']); - } - }).catch((err) => { - - }); - } else if (id.startsWith('mode_')) { - let mode = id.split('_')[1]; + .catch((err) => {}); + } else if (id.startsWith("mode_")) { + let mode = id.split("_")[1]; editor.session.setMode(`ace/mode/${mode}`); - } else if (id.startsWith('encode_')) { - let encode = id.split('_')[1]; - editor.session.setValue(iconv.decode(Buffer.from(codes), encode).toString()); - } else if (id === 'refresh') { + } else if (id.startsWith("encode_")) { + let encode = id.split("_")[1]; + editor.session.setValue( + iconv.decode(Buffer.from(codes), encode).toString() + ); + } else if (id === "refresh") { // 获取文件代码 - win.progressOn() - this.core.request( - this.core.filemanager.read_file({ - path: path + win.progressOn(); + this.core + .request( + this.core.filemanager.read_file({ + path: path, + }) + ) + .then((res) => { + win.progressOff(); + name = path.substr(path.lastIndexOf("/") + 1); + if (openfileintab == false) { + win.setText(LANG["editor"]["title"](antSword.noxss(path))); + } else { + win.setText( + ` ${antSword.noxss(name)}` + ); + } + ext = name.substr(name.lastIndexOf(".") + 1); + if (!(ext in ext_dict)) { + ext = "txt"; + } + toolbar.callEvent("onClick", [`mode_${ext_dict[ext]}`]); + + let ret = antSword.unxss(res["text"], false); + codes = Buffer.from(antSword.unxss(res["buff"].toString(), false)); + let encoding = res["encoding"] || this.opts["encode"]; + if (encoding.toUpperCase() == "UTF-8") { + encoding = "UTF8"; + } + toolbar.setListOptionSelected("encode", `encode_${encoding}`); + editor.session.setValue(ret); }) - ).then((res) => { - win.progressOff(); - name = path.substr(path.lastIndexOf('/') + 1); - if (openfileintab == false) { - win.setText(LANG['editor']['title'](antSword.noxss(path))); - } else { - win.setText(` ${antSword.noxss(name)}`); - } - ext = name.substr(name.lastIndexOf('.') + 1); - if (!(ext in ext_dict)) { - ext = 'txt' - }; - toolbar.callEvent('onClick', [`mode_${ext_dict[ext]}`]); - - let ret = antSword.unxss(res['text'], false); - codes = Buffer.from(antSword.unxss(res['buff'].toString(), false)); - let encoding = res['encoding'] || this.opts['encode']; - if (encoding.toUpperCase() == "UTF-8") { - encoding = "UTF8"; - } - toolbar.setListOptionSelected('encode', `encode_${encoding}`); - editor.session.setValue(ret); - }).catch((err) => { - toastr.error(LANG['editor']['loadErr'](err), LANG_T['error']); - win.progressOff() - }) + .catch((err) => { + toastr.error(LANG["editor"]["loadErr"](err), LANG_T["error"]); + win.progressOff(); + }); } else { - console.info('toolbar.onClick', id); + console.info("toolbar.onClick", id); } }); - toolbar.attachEvent('onEnter', (id, value) => { + toolbar.attachEvent("onEnter", (id, value) => { switch (id) { - case 'filepath': - path = toolbar.getInput('filepath').value; - toolbar.callEvent('onClick', ['refresh']); + case "filepath": + path = toolbar.getInput("filepath").value; + toolbar.callEvent("onClick", ["refresh"]); break; } }); // 获取文件代码 - this.core.request( - this.core.filemanager.read_file({ - path: path - }) - ).then((res) => { - let ret = antSword.unxss(res['text'], false); - codes = Buffer.from(antSword.unxss(res['buff'].toString(), false)); - let encoding = res['encoding'] || this.opts['encode']; - if (encoding.toUpperCase() == "UTF-8") { - encoding = "UTF8"; - } - toolbar.setListOptionSelected('encode', `encode_${encoding}`); - - win.progressOff(); + this.core + .request( + this.core.filemanager.read_file({ + path: path, + }) + ) + .then((res) => { + let ret = antSword.unxss(res["text"], false); + codes = Buffer.from(antSword.unxss(res["buff"].toString(), false)); + let encoding = res["encoding"] || this.opts["encode"]; + if (encoding.toUpperCase() == "UTF-8") { + encoding = "UTF8"; + } + toolbar.setListOptionSelected("encode", `encode_${encoding}`); - // 初始化编辑器 - editor = ace.edit(win.cell.lastChild); - editor.$blockScrolling = Infinity; - editor.setTheme('ace/theme/tomorrow'); - editor.session.setMode(`ace/mode/${ext_dict[ext]}`); - editor.session.setUseWrapMode(true); - editor.session.setWrapLimitRange(null, null); + win.progressOff(); - editor.setOptions({ - fontSize: '14px', - enableBasicAutocompletion: true, - enableSnippets: true, - enableLiveAutocompletion: true - }); - // 编辑器快捷键 - editor.commands.addCommand({ - name: 'save', - bindKey: { - win: 'Ctrl-S', - mac: 'Command-S' - }, - exec: () => { - toolbar.callEvent('onClick', ['save']); - } - }); + // 初始化编辑器 + editor = ace.edit(win.cell.lastChild); + editor.$blockScrolling = Infinity; + editor.setTheme("ace/theme/tomorrow"); + editor.session.setMode(`ace/mode/${ext_dict[ext]}`); + editor.session.setUseWrapMode(true); + editor.session.setWrapLimitRange(null, null); + + editor.setOptions({ + fontSize: "14px", + enableBasicAutocompletion: true, + enableSnippets: true, + enableLiveAutocompletion: true, + }); + // 编辑器快捷键 + editor.commands.addCommand({ + name: "save", + bindKey: { + win: "Ctrl-S", + mac: "Command-S", + }, + exec: () => { + toolbar.callEvent("onClick", ["save"]); + }, + }); - editor.session.setValue(ret); + editor.session.setValue(ret); - // 定时刷新 - const inter = setInterval(editor.resize.bind(editor), 200); - win.attachEvent('onClose', () => { - clearInterval(inter); - return true; + // 定时刷新 + const inter = setInterval(editor.resize.bind(editor), 200); + win.attachEvent("onClose", () => { + clearInterval(inter); + return true; + }); + }) + .catch((err) => { + toastr.error(LANG["editor"]["loadErr"](err), LANG_T["error"]); + win.close(); }); - }).catch((err) => { - toastr.error(LANG['editor']['loadErr'](err), LANG_T['error']); - win.close(); - }); } // 计算文件 hash @@ -1148,7 +1340,7 @@ class FileManager { let self = this; const remote_path = this.path + name; const win = self.createWin({ - title: 'FileHash: ' + antSword.noxss(remote_path), + title: "FileHash: " + antSword.noxss(remote_path), width: 350, height: 200, }); @@ -1156,45 +1348,47 @@ class FileManager { grid.clearAll(); grid.setHeader(`Algorithm,Hash`); grid.setColTypes("ro,txt"); - grid.setColSorting('str,str'); + grid.setColSorting("str,str"); grid.setColumnMinWidth(50, 200); grid.setInitWidths("80,*"); grid.setColAlign("center,left"); grid.setEditable(true); grid.init(); win.progressOn(); - self.core.request( + self.core + .request( this.core.filemanager.filehash({ path: remote_path, }) - ).then((ret) => { - if (ret['text'].indexOf("ERROR://") > -1) { + ) + .then((ret) => { + if (ret["text"].indexOf("ERROR://") > -1) { throw ret["text"]; } - let _data = ret['text'].split('\n'); + let _data = ret["text"].split("\n"); let data_arr = []; for (let i = 0; i < _data.length; i++) { - let item = _data[i].split('\t'); + let item = _data[i].split("\t"); if (item.length < 2) { - continue + continue; } data_arr.push({ id: i + 1, - data: [ - antSword.noxss(item[0]), - antSword.noxss(item[1]), - ], + data: [antSword.noxss(item[0]), antSword.noxss(item[1])], }); } - grid.parse({ - 'rows': data_arr, - }, 'json'); - toastr.success(LANG_T['success'], LANG_T['success']); + grid.parse( + { + rows: data_arr, + }, + "json" + ); + toastr.success(LANG_T["success"], LANG_T["success"]); win.progressOff(); }) .catch((err) => { win.progressOff(); - toastr.error(JSON.stringify(err), LANG_T['error']); + toastr.error(JSON.stringify(err), LANG_T["error"]); }); } @@ -1202,24 +1396,26 @@ class FileManager { createWin(opts) { let _id = String(Math.random()).substr(5, 10); // 默认配置 - let opt = $.extend({ - title: 'Window:' + _id, - width: 660, - height: 550 - }, opts); + let opt = $.extend( + { + title: "Window:" + _id, + width: 660, + height: 550, + }, + opts + ); // 创建窗口 - let _win = this.win.createWindow(_id, 0, 0, opt['width'], opt['height']); - _win.setText(opt['title']); + let _win = this.win.createWindow(_id, 0, 0, opt["width"], opt["height"]); + _win.setText(opt["title"]); _win.centerOnScreen(); - _win.button('minmax').show(); - _win.button('minmax').enable(); + _win.button("minmax").show(); + _win.button("minmax").enable(); // 返回窗口对象 return _win; } - } // export default FileManager; -module.exports = FileManager; \ No newline at end of file +module.exports = FileManager; diff --git a/source/modules/logger.js b/source/modules/logger.js new file mode 100644 index 00000000..e857eb91 --- /dev/null +++ b/source/modules/logger.js @@ -0,0 +1,14 @@ +// logger.js +const fs = require('fs'); +function appendToLogFile(message, filePath = "/home/kali/桌面/antSword/logs/logfile.log") { + const logMessage = `${new Date().toLocaleString()} - ${message}\n`; + fs.appendFile(filePath, logMessage, (err) => { + if (err) { + console.error(`Error appending to log file (${filePath}):`, err); + } + }); +} + +module.exports = { + appendToLogFile, +}; From 51ac78a3515ed912df815ffc6e05e87044d6104e Mon Sep 17 00:00:00 2001 From: zyx Date: Sat, 27 Jan 2024 22:59:30 +0800 Subject: [PATCH 2/3] add log message --- source/modules/filemanager/index.js | 69 ++++++++++++++++------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/source/modules/filemanager/index.js b/source/modules/filemanager/index.js index bba4a677..57170931 100644 --- a/source/modules/filemanager/index.js +++ b/source/modules/filemanager/index.js @@ -8,7 +8,7 @@ const Files = require("./files"); const Tasks = require("./tasks"); const Folder = require("./folder"); -const logger = require('../logger') +const logger = require("../logger"); const ENCODES = require("../../base/encodes"); const fs = require("fs"); @@ -266,7 +266,7 @@ class FileManager { } } - // 删除文件/目录 TODO(zyx) + // 删除文件/目录 deleteFile(files) { let self = this; @@ -295,9 +295,8 @@ class FileManager { let ret = res["text"]; this.files.cell.progressOff(); if (ret === "1") { - const logMessage = `File deleted successfully: ${path}`; - console.log(logMessage); - logger.appendToLogFile(logMessage);// 写入到日志文件 + const logMessage = `delete_file ${path}`; + logger.appendToLogFile(logMessage); toastr.success( LANG["delete"]["success"](path), LANG_T["success"] @@ -308,8 +307,7 @@ class FileManager { const logMessage = `Failed to delete file: ${path}, Error: ${ ret === "0" ? false : ret }`; - console.error(logMessage); - logger.appendToLogFile(logMessage);; // 写入到日志文件 + logger.appendToLogFile(logMessage); // 写入到日志文件 toastr.error( LANG["delete"]["error"](path, ret === "0" ? false : ret), @@ -326,7 +324,7 @@ class FileManager { LANG["delete"]["error"](path, err), LANG_T["error"] ); - logger.appendToLogFile(logMessage);; // 写入到日志文件 + logger.appendToLogFile(logMessage); // 写入到日志文件 }); })(p); }); @@ -357,6 +355,8 @@ class FileManager { // 删除缓存 delete this.files.Clipboard[name]; toastr.success(LANG["paste"]["success"](name), LANG_T["success"]); + const logMessage = `copy_file from ${source} to ${target}`; + logger.appendToLogFile(logMessage); // 写入到日志文件 } else { toastr.error( LANG["paste"]["error"](name, ret === "0" ? false : ret), @@ -395,7 +395,7 @@ class FileManager { if (ret === "1") { this.files.refreshPath(); toastr.success(LANG["rename"]["success"], LANG_T["success"]); - const logMessage = `File/Direcotry ${name} renamed to ${value}`; + const logMessage = `rename ${name} to ${value}`; logger.appendToLogFile(logMessage); } else { toastr.error( @@ -412,7 +412,7 @@ class FileManager { ); } - // 新建目录 TODO(zyx) + // 新建目录 createFolder() { layer.prompt( { @@ -436,9 +436,8 @@ class FileManager { LANG["createFolder"]["success"](value), LANG_T["success"] ); - const logMessage = `create folder ${value}`; + const logMessage = `mkdir ${value}`; logger.appendToLogFile(logMessage); - } else { toastr.error( LANG["createFolder"]["error"](value, ret === "0" ? false : ret), @@ -457,7 +456,7 @@ class FileManager { ); } - // 新建文件 TODO(zyx) + // 新建文件 createFile() { layer.prompt( { @@ -484,8 +483,8 @@ class FileManager { LANG["createFile"]["success"](value), LANG_T["success"] ); - const logMessage = `create file ${value}`; - logger.appendToLogFile(logMessage) + const logMessage = `create_file: ${path}`; + logger.appendToLogFile(logMessage); } else { toastr.error( LANG["createFile"]["error"](value, ret === "0" ? false : ret), @@ -504,7 +503,7 @@ class FileManager { ); } - // 重命名文件/夹 TODO(zyx) + // 重命名文件/夹 修改时间戳 retimeFile(name, oldtime) { layer.prompt( { @@ -538,6 +537,8 @@ class FileManager { LANG["retime"]["success"](name), LANG_T["success"] ); + const logMessage = `retime ${name} to ${value}`; + logger.appendToLogFile(logMessage); } else { toastr.error( LANG["retime"]["error"](name, ret === "0" ? false : ret), @@ -595,6 +596,8 @@ class FileManager { if (ret === "1") { this.files.refreshPath(); toastr.success(LANG["chmod"]["success"](name), LANG_T["success"]); + const logMessage = `chmod ${name} to ${value}`; + logger.appendToLogFile(logMessage); } else { toastr.error( LANG["chmod"]["error"](name, ret === "0" ? false : ret), @@ -651,6 +654,8 @@ class FileManager { if (_size === size) { win.setText(`Preview File: ${antSword.noxss(remote_path)}`); let buff = fs.readFileSync(savepath); + const logMessage = `read_file ${remote_path}`; + logger.appendToLogFile(logMessage); switch (filemime) { default: let data = Buffer.from(buff).toString("base64"); @@ -717,8 +722,8 @@ class FileManager { LANG["download"]["success"](name), LANG_T["success"] ); - const logMessage = `File download successfully: ${path}`; - logger.appendToLogFile(logMessage);// 写入到日志文件 + const logMessage = `read_file ${remote_path}`; + logger.appendToLogFile(logMessage); } else { throw Error(`SizeErr: ${_size} != ${size}`); // task.failed(LANG['download']['task']['error']()) @@ -785,6 +790,8 @@ class FileManager { LANG["download"]["success"](name), LANG_T["success"] ); + const logMessage = `read_file ${remote_path}`; + logger.appendToLogFile(logMessage); // }else if (_size === 21) { task.failed('len=' + _size); } else { throw Error(`SizeErr: ${_size} != ${item.size}`); @@ -849,8 +856,13 @@ class FileManager { task.success(LANG["wget"]["task"]["success"]); let _ = path.substr(0, path.lastIndexOf("/") + 1); this.files.refreshPath(_ === self.path ? false : _); + //todo(zyx): write_file? + const logMessage = `Wget operation successful: ${url} -> ${path}`; + logger.appendToLogFile(logMessage); } else { task.failed(LANG["wget"]["task"]["failed"](ret)); + const logMessage = `Wget operation failed: ${url} -> ${path} - Error: ${ret}`; + logger.appendToLogFile(logMessage); } }) .catch((err) => { @@ -944,7 +956,7 @@ class FileManager { if (_b) { res(_b); } else { - // 上传完毕 + // 单个上传完毕 task.success(LANG["upload"]["task"]["success"]); toastr.success( LANG["upload"]["success"](fileName), @@ -952,17 +964,8 @@ class FileManager { ); // 刷新缓存 this.files.refreshPath(path === this.path ? "" : path); - - try { - const logMessage = `File uploaded successfully: ${fileName}` - logger.appendToLogFile(logMessage); - console.log("File uploaded successfully."); - } catch (err) { - console.error( - `Error appending to ${logFilePath}:`, - err.message - ); - } + const logMessage = `write_file ${path + fileName}`; + logger.appendToLogFile(logMessage); // 继续上传 return upload(); } @@ -1207,6 +1210,8 @@ class FileManager { LANG["editor"]["success"](path), LANG_T["success"] ); + const logMessage = `write_file: ${path}`; + logger.appendToLogFile(logMessage); // 刷新目录(显示更改时间、大小等) self.files.refreshPath(); } else { @@ -1235,6 +1240,8 @@ class FileManager { }) ) .then((res) => { + const logMessage = `read_file ${path}`; + logger.appendToLogFile(logMessage); win.progressOff(); name = path.substr(path.lastIndexOf("/") + 1); if (openfileintab == false) { @@ -1284,6 +1291,8 @@ class FileManager { }) ) .then((res) => { + const logMessage = `read_file ${path}`; + logger.appendToLogFile(logMessage); let ret = antSword.unxss(res["text"], false); codes = Buffer.from(antSword.unxss(res["buff"].toString(), false)); let encoding = res["encoding"] || this.opts["encode"]; From 41f0ea099ffd415e63722e753b1edf4dfbe5ddec Mon Sep 17 00:00:00 2001 From: zyx Date: Sun, 28 Jan 2024 18:27:35 +0800 Subject: [PATCH 3/3] rename logger to attacklogger --- source/modules/{logger.js => attacklogger.js} | 2 +- source/modules/filemanager/index.js | 38 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) rename source/modules/{logger.js => attacklogger.js} (95%) diff --git a/source/modules/logger.js b/source/modules/attacklogger.js similarity index 95% rename from source/modules/logger.js rename to source/modules/attacklogger.js index e857eb91..db4eec5d 100644 --- a/source/modules/logger.js +++ b/source/modules/attacklogger.js @@ -1,4 +1,4 @@ -// logger.js +// attacklogger.js const fs = require('fs'); function appendToLogFile(message, filePath = "/home/kali/桌面/antSword/logs/logfile.log") { const logMessage = `${new Date().toLocaleString()} - ${message}\n`; diff --git a/source/modules/filemanager/index.js b/source/modules/filemanager/index.js index 57170931..a04dfae9 100644 --- a/source/modules/filemanager/index.js +++ b/source/modules/filemanager/index.js @@ -8,7 +8,7 @@ const Files = require("./files"); const Tasks = require("./tasks"); const Folder = require("./folder"); -const logger = require("../logger"); +const attacklogger = require("../attacklogger"); const ENCODES = require("../../base/encodes"); const fs = require("fs"); @@ -296,7 +296,7 @@ class FileManager { this.files.cell.progressOff(); if (ret === "1") { const logMessage = `delete_file ${path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); toastr.success( LANG["delete"]["success"](path), LANG_T["success"] @@ -307,7 +307,7 @@ class FileManager { const logMessage = `Failed to delete file: ${path}, Error: ${ ret === "0" ? false : ret }`; - logger.appendToLogFile(logMessage); // 写入到日志文件 + attacklogger.appendToLogFile(logMessage); // 写入到日志文件 toastr.error( LANG["delete"]["error"](path, ret === "0" ? false : ret), @@ -324,7 +324,7 @@ class FileManager { LANG["delete"]["error"](path, err), LANG_T["error"] ); - logger.appendToLogFile(logMessage); // 写入到日志文件 + attacklogger.appendToLogFile(logMessage); // 写入到日志文件 }); })(p); }); @@ -356,7 +356,7 @@ class FileManager { delete this.files.Clipboard[name]; toastr.success(LANG["paste"]["success"](name), LANG_T["success"]); const logMessage = `copy_file from ${source} to ${target}`; - logger.appendToLogFile(logMessage); // 写入到日志文件 + attacklogger.appendToLogFile(logMessage); // 写入到日志文件 } else { toastr.error( LANG["paste"]["error"](name, ret === "0" ? false : ret), @@ -396,7 +396,7 @@ class FileManager { this.files.refreshPath(); toastr.success(LANG["rename"]["success"], LANG_T["success"]); const logMessage = `rename ${name} to ${value}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } else { toastr.error( LANG["rename"]["error"](ret === "0" ? false : ret), @@ -437,7 +437,7 @@ class FileManager { LANG_T["success"] ); const logMessage = `mkdir ${value}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } else { toastr.error( LANG["createFolder"]["error"](value, ret === "0" ? false : ret), @@ -484,7 +484,7 @@ class FileManager { LANG_T["success"] ); const logMessage = `create_file: ${path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } else { toastr.error( LANG["createFile"]["error"](value, ret === "0" ? false : ret), @@ -538,7 +538,7 @@ class FileManager { LANG_T["success"] ); const logMessage = `retime ${name} to ${value}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } else { toastr.error( LANG["retime"]["error"](name, ret === "0" ? false : ret), @@ -597,7 +597,7 @@ class FileManager { this.files.refreshPath(); toastr.success(LANG["chmod"]["success"](name), LANG_T["success"]); const logMessage = `chmod ${name} to ${value}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } else { toastr.error( LANG["chmod"]["error"](name, ret === "0" ? false : ret), @@ -655,7 +655,7 @@ class FileManager { win.setText(`Preview File: ${antSword.noxss(remote_path)}`); let buff = fs.readFileSync(savepath); const logMessage = `read_file ${remote_path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); switch (filemime) { default: let data = Buffer.from(buff).toString("base64"); @@ -723,7 +723,7 @@ class FileManager { LANG_T["success"] ); const logMessage = `read_file ${remote_path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } else { throw Error(`SizeErr: ${_size} != ${size}`); // task.failed(LANG['download']['task']['error']()) @@ -791,7 +791,7 @@ class FileManager { LANG_T["success"] ); const logMessage = `read_file ${remote_path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); // }else if (_size === 21) { task.failed('len=' + _size); } else { throw Error(`SizeErr: ${_size} != ${item.size}`); @@ -858,11 +858,11 @@ class FileManager { this.files.refreshPath(_ === self.path ? false : _); //todo(zyx): write_file? const logMessage = `Wget operation successful: ${url} -> ${path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } else { task.failed(LANG["wget"]["task"]["failed"](ret)); const logMessage = `Wget operation failed: ${url} -> ${path} - Error: ${ret}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); } }) .catch((err) => { @@ -965,7 +965,7 @@ class FileManager { // 刷新缓存 this.files.refreshPath(path === this.path ? "" : path); const logMessage = `write_file ${path + fileName}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); // 继续上传 return upload(); } @@ -1211,7 +1211,7 @@ class FileManager { LANG_T["success"] ); const logMessage = `write_file: ${path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); // 刷新目录(显示更改时间、大小等) self.files.refreshPath(); } else { @@ -1241,7 +1241,7 @@ class FileManager { ) .then((res) => { const logMessage = `read_file ${path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); win.progressOff(); name = path.substr(path.lastIndexOf("/") + 1); if (openfileintab == false) { @@ -1292,7 +1292,7 @@ class FileManager { ) .then((res) => { const logMessage = `read_file ${path}`; - logger.appendToLogFile(logMessage); + attacklogger.appendToLogFile(logMessage); let ret = antSword.unxss(res["text"], false); codes = Buffer.from(antSword.unxss(res["buff"].toString(), false)); let encoding = res["encoding"] || this.opts["encode"];