This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
1 lines (1 loc) · 77.6 KB
/
app.js
1
(()=>{"use strict";var e={3165:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(2037)),s=n(2231),o=n(6296),a=r(n(2399)),u=r(n(9688)),l=n(6547),d=r(n(6469)),c=r(n(2195)),f=r(n(7147)),g=r(n(1406)),y=n(5828),m=r(n(1017)),p=r(n(5004)),h=r(n(9511)),_=r(n(8097)),v=r(n(3685)),w=r(n(6634)),b=n(8264),S=n(8145),q=n(4069);async function I(){try{console.log(""),b.logger.warn("Program received EXIT command."),b.logger.info("Exit.")}catch(e){b.logger.error("ERROR:",e)}finally{process.exit(0)}}["SIGTERM","SIGINT","SIGQUIT"].forEach((function(e){process.on(e,(()=>{b.logger.warn(`${e} close process signal detected.`),I()}))})),process.stdin.on("data",(e=>{"exit"===e.toString().replace("\n","").replace("\r","").trim().toLowerCase()&&I()})),async function(){(0,l.initSystemConfig)(),0!=l.systemConfig.redisUrl.length&&(await a.default.initialize(l.systemConfig.redisUrl),u.default.setStorageType(u.default.TYPE.REDIS)),(0,o.initVersionManager)();const e=(0,o.getVersion)();console.log(`______ _______________________ ___ \n___ |/ /_ ____/_ ___/__ |/ /_____ _____________ _______ _____________\n__ /|_/ /_ / _____ \\__ /|_/ /_ __ \`/_ __ \\ __ \`/_ __ \`/ _ \\_ ___/\n_ / / / / /___ ____/ /_ / / / / /_/ /_ / / / /_/ /_ /_/ // __/ / \n/_/ /_/ \\____/ /____/ /_/ /_/ \\__,_/ /_/ /_/\\__,_/ _\\__, / \\___//_/ \n /____/ \n\n + Copyright (C) 2023 MCSManager <[email protected]>\n + Version ${e}\n`),f.default.existsSync(m.default.join(__dirname,"public"))||(console.log((0,s.$t)("app.developInfo")),process.exit(0)),await d.default.initialize(),await c.default.initialize();const t=__dirname,n=new g.default;n.on("error",(e=>{})),n.use((0,p.default)({multipart:!0,parsedMethods:["POST","PUT","DELETE","GET"]})),n.keys=[(0,y.v4)()],n.use((0,h.default)({key:(0,y.v4)(),maxAge:864e5,overwrite:!0,httpOnly:!0,signed:!0,rolling:!1,renew:!1,secure:!1},n)),n.use((async(e,t)=>{const n=["/api/overview","/api/files/status"];for(const r of n)if(e.URL.pathname.includes(r))return await t();b.logger.info(`[HTTP] ${e.method}: ${e.URL.href}`),b.logger.info(`[HTTP] IP: ${e.ip} USER: ${e.session.userName} UUID: ${e.session.uuid}`),await t()})),n.use(S.middleware),n.use((0,_.default)(m.default.join(t,"public"),{maxAge:864e3})),(0,q.index)(n),process.on("uncaughtException",(function(e){b.logger.error("ERROR (uncaughtException):",e)})),process.on("unhandledRejection",((e,t)=>{b.logger.error("ERROR (unhandledRejection):",e,t)})),function(e,t,n){const r=v.default.createServer(e.callback());r.on("error",(e=>{b.logger.error((0,s.$t)("app.httpSetupError")),b.logger.error(e),process.exit(1)})),r.listen(t,n),b.logger.info("=================================="),b.logger.info((0,s.$t)("app.panelStarted")),b.logger.info((0,s.$t)("app.reference")),b.logger.info((0,s.$t)("app.host",{port:t})),b.logger.info((0,s.$t)("app.portTip",{port:t})),b.logger.info((0,s.$t)("app.exitTip",{port:t})),b.logger.info("=================================="),"win32"==i.default.platform()&&(0,w.default)(`http://localhost:${t}/`).then((()=>{}))}(n,l.systemConfig.httpPort,l.systemConfig.httpIp)}().catch((e=>{b.logger.error("main() error:",e),process.exit(0)}))},299:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});class n{static set(e,t){n.map.set(e,t)}static get(e,t){return n.map.has(e)?n.map.get(e):t}static del(e){return n.map.delete(e)}}t.default=n,n.map=new Map},5739:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(){this.listenMap=new Map}requestForward(e,t){if(this.listenMap.has(t)){const n=this.listenMap.get(t);for(const t of n)if(t.id===e.id)throw new Error(`This Socket ${e.id} already exists in the specified instance listening table`);n.push(e)}else this.listenMap.set(t,[e])}cannelForward(e,t){if(!this.listenMap.has(t))throw new Error(`The specified ${t} does not exist in the listening table`);const n=this.listenMap.get(t);n.forEach(((t,r)=>{t.id===e.id&&n.splice(r,1)}))}forward(e,t){this.listenMap.get(e).forEach((e=>{e&&e.connected&&e.emit("instance/stdout",t)}))}forwardViaCallback(e,t){this.listenMap.has(e)&&this.listenMap.get(e).forEach((e=>{e&&e.connected&&t(e)}))}hasListenInstance(e){return this.listenMap.has(e)&&this.listenMap.get(e).length>0}}},9728:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.QueryWrapper=t.LocalFileSource=t.MySqlSource=t.QueryMapWrapper=void 0,t.QueryMapWrapper=class{constructor(e){this.map=e}select(e){const t=[];return this.map.forEach((n=>{e(n)&&t.push(n)})),t}page(e,t=1,n=10){const r=(t-1)*n,i=r+n;let s=e.length,o=0;for(;s>0;)s-=n,o++;return{page:t,pageSize:n,maxPage:o,data:e.slice(r,i)}}},t.MySqlSource=class{},t.LocalFileSource=class{constructor(e){this.data=e}selectPage(e,t=1,n=10){const r=[];return this.data.forEach((t=>{for(const n in e){const r=t[n],i=e[n];if("%"==i[0]){if(!r.includes(i.slice(1,i.length-1)))return!1}else if(i!==r)return!1}r.push(t)})),this.page(r,t,n)}page(e,t=1,n=10){const r=(t-1)*n,i=r+n;let s=e.length,o=0;for(;s>0;)s-=n,o++;return{page:t,pageSize:n,maxPage:o,total:e.length,data:e.slice(r,i)}}select(e){return null}update(e,t){}delete(e){}insert(e){}},t.QueryWrapper=class{constructor(e){this.dataSource=e}selectPage(e,t=1,n=10){return this.dataSource.selectPage(e,t,n)}}},933:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1017)),s=r(n(4470));class o{checkFileName(e){const t=["\\","/",".."];for(const n of t)if(e.includes(n))return!1;return!0}async store(e,t,n){const r=i.default.join(o.STIRAGE_DATA_PATH,e);if(s.default.existsSync(r)||s.default.mkdirsSync(r),!this.checkFileName(t))throw new Error(`UUID ${t} does not conform to specification`);const a=i.default.join(r,`${t}.json`),u=JSON.stringify(n,null,4);s.default.writeFileSync(a,u,{encoding:"utf-8"})}defineAttr(e,t){for(const n of Object.keys(e)){const r=t[n];void 0!==r&&(r instanceof Array?e[n]=r:r instanceof Object&&"object"==typeof r?this.defineAttr(e[n],r):e[n]=r)}return e}async load(e,t,n){const r=i.default.join(o.STIRAGE_DATA_PATH,e);if(s.default.existsSync(r)||s.default.mkdirsSync(r),!this.checkFileName(n))throw new Error(`UUID ${n} does not conform to specification`);const a=i.default.join(r,`${n}.json`);if(!s.default.existsSync(a))return null;const u=s.default.readFileSync(a,{encoding:"utf-8"}),l=JSON.parse(u),d=new t;return this.defineAttr(d,l)}async list(e){const t=i.default.join(o.STIRAGE_DATA_PATH,e);s.default.existsSync(t)||s.default.mkdirsSync(t);const n=s.default.readdirSync(t),r=new Array;return n.forEach((e=>{r.push(e.replace(i.default.extname(e),""))})),r}async delete(e,t){const n=i.default.join(o.STIRAGE_DATA_PATH,e,`${t}.json`);s.default.existsSync(n)&&s.default.removeSync(n)}}o.STIRAGE_DATA_PATH=i.default.normalize(i.default.join(process.cwd(),"data")),o.STIRAGE_INDEX_PATH=i.default.normalize(i.default.join(process.cwd(),"data","index")),t.default=new o},2399:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(7773),s=r(n(9688)),o=n(8264);t.default=new class{constructor(){this.client=(0,i.createClient)()}async connect(){try{await this.client.connect()}catch(e){o.logger.error("Error occurred while trying to dial redis\n"+e),o.logger.warn("Due to an unrecoverable error, daemon will temporarily store data in files."),s.default.setStorageType(0)}}async keys(e){return await this.client.keys(e)}async set(e,t){await this.client.set(e,t)}async get(e){return await this.client.get(e)}async del(e){await this.client.del(e)}async initialize(e){this.client=(0,i.createClient)({url:e}),o.logger.info("Attempting to connect to redis..."),await this.connect(),o.logger.info("Connected to redis!")}checkFileName(e){const t=["\\","/",".."];for(const n of t)if(e.includes(n))return!1;return!0}async store(e,t,n){if(!this.checkFileName(t))throw new Error(`UUID ${t} does not conform to specification`);await this.set(e+":"+t,JSON.stringify(n))}async load(e,t,n){if(!this.checkFileName(n))throw new Error(`UUID ${n} does not conform to specification`);let r=await this.get(e+":"+n);if(null==r)return null;const i=JSON.parse(r),s=new t;return this.defineAttr(s,i)}async list(e){let t=[],n=Array();if(t=await this.keys(e+"*"),null!=t&&0!=t.length)for(let r of t)n.push(r.replace(e+":",""));return n}async delete(e,t){if(!this.checkFileName(t))throw new Error(`UUID ${t} does not conform to specification`);await this.del(e+":"+t)}defineAttr(e,t){for(const n of Object.keys(e)){const r=t[n];void 0!==r&&(r instanceof Array?e[n]=r:r instanceof Object&&"object"==typeof r?this.defineAttr(e[n],r):e[n]=r)}return e}}},9688:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(933)),s=r(n(2399));t.default=new class{constructor(){this.storageSystem=i.default,this.TYPE={FILE:0,REDIS:1}}setStorageType(e){switch(e){case this.TYPE.FILE:this.storageSystem=i.default;break;case this.TYPE.REDIS:this.storageSystem=s.default;break;default:this.storageSystem=i.default}}getStorage(){return this.storageSystem}}},9857:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.systemInfo=void 0;const i=r(n(2037)),s=r(n(7411)),o=r(n(7147)),a={type:i.default.type(),hostname:i.default.hostname(),platform:i.default.platform(),release:i.default.release(),uptime:i.default.uptime(),cwd:process.cwd(),loadavg:i.default.loadavg(),freemem:0,cpuUsage:0,memUsage:0,totalmem:0,processCpu:0,processMem:0};function u(){a.freemem=i.default.freemem(),a.totalmem=i.default.totalmem(),a.memUsage=(i.default.totalmem()-i.default.freemem())/i.default.totalmem(),s.default.cpuUsage((e=>a.cpuUsage=e))}setInterval((()=>"linux"===i.default.platform()?function(){var e;try{const t=o.default.readFileSync("/proc/meminfo",{encoding:"utf-8"}).split("\n"),n={};t.forEach((e=>{const t=e.split(":");if(2===t.length){const e=t[0].replace(/ /gim,"").replace(/\t/gim,"").trim().toLowerCase();let r=t[1].replace(/ /gim,"").replace(/\t/gim,"").trim().toLowerCase();r=r.replace(/kb/gim,"").replace(/mb/gim,"").replace(/gb/gim,"");let i=parseInt(r);isNaN(i)&&(i=0),n[e]=i}}));const r=null!==(e=n.memavailable)&&void 0!==e?e:n.memfree,i=n.memtotal;a.freemem=1024*r,a.totalmem=1024*i,a.memUsage=(a.totalmem-a.freemem)/a.totalmem,s.default.cpuUsage((e=>a.cpuUsage=e))}catch(e){u()}}():"win32"===i.default.platform()?(a.freemem=i.default.freemem(),a.totalmem=i.default.totalmem(),a.memUsage=(i.default.totalmem()-i.default.freemem())/i.default.totalmem(),void s.default.cpuUsage((e=>a.cpuUsage=e))):u()),3e3),t.systemInfo=function(){return a}},2126:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1017)),s=r(n(4470));class o{checkFileName(e){const t=["\\","/",".."];for(const n of t)if(e.includes(n))return!1;return!0}store(e,t,n){const r=i.default.join(o.STIRAGE_DATA_PATH,e);if(s.default.existsSync(r)||s.default.mkdirsSync(r),!this.checkFileName(t))throw new Error(`UUID ${t} does not conform to specification`);const a=i.default.join(r,`${t}.json`),u=JSON.stringify(n,null,4);s.default.writeFileSync(a,u,{encoding:"utf-8"})}defineAttr(e,t){for(const n of Object.keys(e)){const r=t[n];void 0!==r&&(r instanceof Array?e[n]=r:r instanceof Object&&"object"==typeof r?this.defineAttr(e[n],r):e[n]=r)}return e}load(e,t,n){const r=i.default.join(o.STIRAGE_DATA_PATH,e);if(s.default.existsSync(r)||s.default.mkdirsSync(r),!this.checkFileName(n))throw new Error(`UUID ${n} does not conform to specification`);const a=i.default.join(r,`${n}.json`);if(!s.default.existsSync(a))return null;const u=s.default.readFileSync(a,{encoding:"utf-8"}),l=JSON.parse(u),d=new t;return this.defineAttr(d,l)}list(e){const t=i.default.join(o.STIRAGE_DATA_PATH,e);s.default.existsSync(t)||s.default.mkdirsSync(t);const n=s.default.readdirSync(t),r=new Array;return n.forEach((e=>{r.push(e.replace(i.default.extname(e),""))})),r}delete(e,t){const n=i.default.join(o.STIRAGE_DATA_PATH,e,`${t}.json`);s.default.existsSync(n)&&s.default.removeSync(n)}}o.STIRAGE_DATA_PATH=i.default.normalize(i.default.join(process.cwd(),"data")),o.STIRAGE_INDEX_PATH=i.default.normalize(i.default.join(process.cwd(),"data","index")),t.default=new o},9058:(e,t)=>{function n(e){return null==e}Object.defineProperty(t,"__esModule",{value:!0}),t.supposeValue=t.isEmpty=t.toBoolean=t.toNumber=t.toText=t.configureEntityParams=void 0,t.configureEntityParams=function(e,t,n,r){var i;const s=null!==(i=e[n])&&void 0!==i?i:null,o=null!=t[n]?t[n]:s;if(r!==Number)if(r!==String)if(r!==Boolean)if(r!==Array)e[n]=r?r(o):o;else{if(null==o)return e[n]=null;if(!(o instanceof Array))throw new Error("ConfigureEntityParams Error: Expected type to be Array, but got "+typeof o)}else e[n]=null!=o&&Boolean(o);else e[n]=null==o?null:String(o);else if(""===o||null==o)e[n]=null;else{if(isNaN(Number(o)))throw new Error("ConfigureEntityParams Error: Expected type to be Number, but got "+typeof o);e[n]=Number(o)}},t.toText=function(e){return n(e)?null:String(e)},t.toNumber=function(e){return n(e)||isNaN(Number(e))?null:Number(e)},t.toBoolean=function(e){return n(e)?null:Boolean(e)},t.isEmpty=n,t.supposeValue=function(e,t=null){return n(e)?t:e}},1423:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FILENAME_BLACKLIST=void 0,t.FILENAME_BLACKLIST=["\\","/",".","'",'"',"?","*","<",">"]},521:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RemoteServiceConfig=void 0,t.RemoteServiceConfig=class{constructor(){this.ip="",this.port=24444,this.remarks="",this.apiKey="",this.connectOpts={multiplex:!1,reconnectionDelayMax:3e3,timeout:3e3,reconnection:!0,reconnectionAttempts:20,rejectUnauthorized:!1}}}},3204:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(8087),s=n(8264),o=r(n(5153)),a=r(n(5739)),u=n(2231);class l{constructor(e,t){this.uuid=null,this.available=!1,this.socket=null,this.instanceStream=new a.default,this.uuid=e,this.config=t}connect(e){e&&(this.config.connectOpts=e);let t=`ws://${this.config.ip}:${this.config.port}`;0!==this.config.ip.indexOf("wss://")&&0!==this.config.ip.indexOf("ws://")||(t=`${this.config.ip}:${this.config.port}`);const n=`[${this.uuid}] [${t}/${this.config.remarks}]`;if(this.available&&(s.logger.info(`${(0,u.$t)("daemonInfo.resetConnect")}:${n}`),this.disconnect()),this.socket&&this.socket.hasListeners("connect"))return s.logger.info(`${(0,u.$t)("daemonInfo.replaceConnect")}:${n}`),this.refreshReconnect();s.logger.info(`${(0,u.$t)("daemonInfo.tryConnect")}:${n}`),this.socket=(0,i.io)(t,e),this.socket.on("connect",(async()=>{s.logger.info((0,u.$t)("daemonInfo.connect",{v:n})),await this.onConnect()})),this.socket.on("disconnect",(async()=>{s.logger.info((0,u.$t)("daemonInfo.disconnect",{v:n})),await this.onDisconnect()})),this.socket.on("connect_error",(async e=>{await this.onDisconnect()}))}async setLanguage(e){return e||(e=u.i18next.language),s.logger.info(`${(0,u.$t)("daemonInfo.setLanguage")} (${this.config.ip}:${this.config.port}/${this.config.remarks}) language: ${e}`),await new o.default(this).request("info/setting",{language:e})}async auth(e){e&&(this.config.apiKey=e);const t=`[${this.uuid}] [${this.config.ip}:${this.config.port}]`;try{return!0===await new o.default(this).request("auth",this.config.apiKey,5e3,!0)?(this.available=!0,await this.setLanguage(),s.logger.info((0,u.$t)("daemonInfo.authSuccess",{v:t})),!0):(this.available=!1,s.logger.warn((0,u.$t)("daemonInfo.authFailure",{v:t})),!1)}catch(e){return s.logger.warn((0,u.$t)("daemonInfo.authError",{v:t})),s.logger.warn(e),!1}}emit(e,t){return this.socket.emit(e,t)}async onDisconnect(){this.available=!1}async onConnect(){return await this.auth(this.config.apiKey)}disconnect(){if(this.socket){const e=`[${this.uuid}] [${this.config.ip}:${this.config.port}]`;s.logger.info((0,u.$t)("daemonInfo.closed",{v:e})),this.socket.removeAllListeners(),this.socket.disconnect(),this.socket.close(),delete this.socket}this.socket=null,this.available=!1}refreshReconnect(){this.disconnect(),this.connect()}}t.default=l,l.STATUS_OK=200,l.STATUS_ERR=500},3149:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(){this.httpPort=23333,this.httpIp=null,this.dataPort=23334,this.forwardType=1,this.crossDomain=!1,this.gzip=!1,this.maxCompress=1,this.maxDonwload=10,this.zipType=1,this.loginCheckIp=!0,this.loginInfo="",this.canFileManager=!0,this.language="en_us",this.quickInstallAddr="https://mcsmanager.oss-cn-guangzhou.aliyuncs.com/quick_install.json",this.redisUrl=""}}},1677:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.User=t.UserPassWordType=void 0,(n=t.UserPassWordType||(t.UserPassWordType={}))[n.md5=0]="md5",n[n.bcrypt=1]="bcrypt",t.User=class{constructor(){this.uuid="",this.userName="",this.passWord="",this.passWordType=null,this.salt="",this.permission=0,this.registerTime="",this.loginTime="",this.instances=[],this.apiKey="",this.isInit=!1}}},2231:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.i18next=t.$t=void 0;const i=r(n(8805));t.i18next=i.default;const s=r(n(4035)),o=r(n(5458));i.default.init({lng:"en_us",fallbackLng:"en_us",resources:{zh_cn:{translation:s.default},en_us:{translation:o.default}}});const a=i.default.t;t.$t=a},4069:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.index=void 0;const i=r(n(1511));n(6469),n(4419),n(2195),n(237);const s=r(n(658)),o=r(n(3176)),a=r(n(3665)),u=r(n(3601)),l=r(n(1594)),d=r(n(4225)),c=r(n(5598)),f=r(n(556)),g=r(n(286)),y=r(n(8179)),m=r(n(4374)),p=r(n(8377)),h=r(n(859));t.index=function(e){const t=new i.default({prefix:"/api"});t.use(s.default.routes()).use(s.default.allowedMethods()),t.use(c.default.routes()).use(c.default.allowedMethods()),t.use(d.default.routes()).use(d.default.allowedMethods()),t.use(f.default.routes()).use(f.default.allowedMethods()),t.use(g.default.routes()).use(g.default.allowedMethods()),t.use(y.default.routes()).use(y.default.allowedMethods()),t.use(m.default.routes()).use(m.default.allowedMethods()),t.use(a.default.routes()).use(a.default.allowedMethods()),t.use(u.default.routes()).use(u.default.allowedMethods()),t.use(o.default.routes()).use(o.default.allowedMethods()),t.use(p.default.routes()).use(p.default.allowedMethods()),t.use(l.default.routes()).use(l.default.allowedMethods()),t.use(h.default.routes()).use(h.default.allowedMethods()),e.use(t.routes()).use(t.allowedMethods())}},6746:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(299)),s=r(n(6469)),o=n(3210),a=n(2231);t.default=e=>async(t,n)=>{var r,u;if((null==e.speedLimit||!0===e.speedLimit)&&Number(e.level)<10&&!function(e){var t;const n="lastRequestTime",r=(new Date).getTime(),i=null===(t=e.session)||void 0===t?void 0:t[n];if(!e.session)return!1;if(i&&"number"==typeof i){if(r-i<300)return!1;e.session[n]=r}else e.session[n]=r;return!0}(t))return function(e){e.status=500,e.body=`[TooFast] ${(0,a.$t)("permission.tooFast")}`}(t);if(t.query.apikey){const r=String(t.query.apikey),i=(0,o.getUuidByApiKey)(r);return i&&i.permission>=Number(e.level)?await n():function(e){e.status=403,e.body=`[Forbidden] ${(0,a.$t)("permission.apiError")}`}(t)}if(!1!==e.token){if(!(0,o.isAjax)(t))return function(e){e.status=403,e.body=`[Forbidden] ${(0,a.$t)("permission.xmlhttprequestError")}`}(t);if(t.query.token!==(null===(r=t.session)||void 0===r?void 0:r.token))return function(e){e.status=403,e.body=`[Forbidden] ${(0,a.$t)("permission.forbiddenTokenError")}`}(t)}if(isNaN(parseInt(String(e.level))))return await n();if(!0===(null===(u=t.session)||void 0===u?void 0:u.login)&&t.session.uuid&&t.session.userName){const r=s.default.getInstance(t.session.uuid);if(r&&r.permission<0)return(0,o.logout)(t);if(r&&r.permission>=Number(e.level))return await n()}return i.default.set(o.ILLEGAL_ACCESS_KEY,i.default.get(o.ILLEGAL_ACCESS_KEY,0)+1),function(e){e.status=403,e.body=`[Forbidden] ${(0,a.$t)("permission.forbidden")}`}(t)}},8145:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.middleware=void 0;const i=n(2781),s=r(n(4419)),o=n(6547);t.middleware=async function(e,t){e.url.startsWith("/api/")&&s.default.addRequestCount();try{await t()}catch(t){e.body=t}if(o.systemConfig.crossDomain&&(e.response.set("Access-Control-Allow-Origin","*"),e.response.set("Access-Control-Allow-Methods","PUT, POST, GET, DELETE, OPTIONS"),e.response.set("Access-Control-Allow-Headers","Content-Type, Content-Length, Authorization, Accept, X-Requested-With")),e.cookies.set("MCSManager","Copyright 2022 https://github.com/mcsmanager"),e.response.set("X-Powered-By","https://github.com/mcsmanager"),e.body instanceof Error){const t=e.body;return e.status=500,void(e.body=JSON.stringify({status:e.status,data:t.message,time:(new Date).getTime()}))}if(!(e.body instanceof i.Stream)){if(404==e.status)return e.status=404,void(e.body=JSON.stringify({status:e.status,data:"[404] Not Found",time:(new Date).getTime()}));if("string"!=typeof e.body){if(null===e.body||!1===e.body||void 0===e.body)return e.status=500,void(e.body=JSON.stringify({status:500,data:e.body||null,time:(new Date).getTime()}));200!=e.status||(e.body=JSON.stringify({status:e.status,data:e.body,time:(new Date).getTime()}))}else{const t=e.status,n=e.body;e.body=JSON.stringify({status:t,data:n,time:(new Date).getTime()})}}}},5542:(e,t)=>{function n(e,t){if(e){for(const n in t){const r=t[n];if(null==e[n]||""===e[n])return!1;if(r!==Number)if(r!==String)if(r!==Date){if(r===Array&&!(e[n]instanceof Array)){const t=JSON.parse(e[n]);if(!(t instanceof Array))return!1;e[n]=t}if(r===Object&&!e[n])return!1}else{const t=new Date(e[n]).toString();if("Invalid Date"==t||null==t)return!1;e[n]=new Date(e[n])}else e[n]=String(e[n]);else if(e[n]=Number(e[n]),isNaN(e[n]))return!1}return!0}return!1}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return async(t,r)=>{try{let i=!0;return e.params&&!n(t.params,e.params)&&(i=!1),e.query&&!n(t.query,e.query)&&(i=!1),e.body&&!n(t.request.body,e.body)&&(i=!1),i?await r():function(e){e.status=400,e.body="Request parameters are incorrect"}(t)}catch(e){const n=e;t.status=500,t.body=`${n.message}`}}}},4374:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=n(3210),u=r(n(6469)),l=n(2231),d=new i.default({prefix:"/auth"});d.post("/",(0,s.default)({level:10}),(0,o.default)({body:{username:String,password:String,permission:Number}}),(async e=>{const t=String(e.request.body.username),n=String(e.request.body.password),r=Number(e.request.body.permission);if(!u.default.validatePassword(n))throw new Error((0,l.$t)("router.user.invalidPassword"));if(u.default.existUserName(t))throw new Error((0,l.$t)("router.user.existsUserName"));e.body=await(0,a.register)(e,t,n,r)})),d.del("/",(0,s.default)({level:10}),(async e=>{const t=e.request.body;try{for(const e of t)await u.default.deleteInstance(e);e.body=!0}catch(t){e.throw(500,(0,l.$t)("router.user.deleteFailure"))}})),d.get("/search",(0,s.default)({level:10}),(0,o.default)({query:{page:Number,page_size:Number}}),(async e=>{const t=e.query.userName,n=Number(e.query.page),r=Number(e.query.page_size),i={};t&&(i.userName=`%${t}%`);let s=u.default.getQueryWrapper().selectPage(i,n,r);s=JSON.parse(JSON.stringify(s)),s.data.forEach((e=>{delete e.passWord,delete e.salt})),e.body=s})),t.default=d},859:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=r(n(2195)),u=r(n(5153)),l=new i.default({prefix:"/environment"});l.get("/image",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=a.default.getInstance(t),r=await new u.default(n).request("environment/images",{});e.body=r}catch(t){e.body=t}})),l.post("/image",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=e.request.body,r=a.default.getInstance(t),i=await new u.default(r).request("environment/new_image",n);e.body=i}catch(t){e.body=t}})),l.delete("/image",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String,imageId:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.imageId),r=a.default.getInstance(t),i=await new u.default(r).request("environment/del_image",{imageId:n});e.body=i}catch(t){e.body=t}})),l.get("/containers",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=a.default.getInstance(t),r=await new u.default(n).request("environment/containers",{});e.body=r}catch(t){e.body=t}})),l.get("/networkModes",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=a.default.getInstance(t),r=await new u.default(n).request("environment/networkModes",{});e.body=r}catch(t){e.body=t}})),l.get("/progress",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=a.default.getInstance(t),r=await new u.default(n).request("environment/progress",{});e.body=r}catch(t){e.body=t}})),t.default=l},4225:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=r(n(2195)),u=r(n(5153)),l=n(6730),d=n(1254),c=n(2231),f=r(n(2167)),g=n(6547),y=new i.default({prefix:"/instance"});y.get("/",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t),i=await new u.default(r).request("instance/detail",{instanceUuid:n});e.body=i}catch(t){e.body=t}})),y.post("/",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=e.request.body,r=a.default.getInstance(t),i=await new u.default(r).request("instance/new",n);e.body=i}catch(t){e.body=t}})),y.post("/upload",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String,upload_dir:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=e.request.body,r=a.default.getInstance(t),i=(await new u.default(r).request("instance/new",n)).instanceUuid;if(!i)throw new Error((0,c.$t)("router.instance.createError"));const s=`${r.config.ip}:${r.config.port}`,o=(0,d.timeUuid)();await new u.default(r).request("passport/register",{name:"upload",password:o,parameter:{uploadDir:".",instanceUuid:i}}),e.body={instanceUuid:i,password:o,addr:s}}catch(t){e.body=t}})),y.put("/",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=e.request.body,i=a.default.getInstance(t),s=await new u.default(i).request("instance/update",{instanceUuid:n,config:r});e.body=s}catch(t){e.body=t}})),y.delete("/",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String},body:{uuids:Object,deleteFile:Boolean}}),(async e=>{try{const t=String(e.query.remote_uuid),n=e.request.body.uuids,r=e.request.body.deleteFile,i=a.default.getInstance(t),s=await new u.default(i).request("instance/delete",{instanceUuids:n,deleteFile:r});e.body=s}catch(t){e.body=t}})),y.post("/multi_open",(0,s.default)({level:10}),(async e=>{try{const t=e.request.body;(0,l.multiOperationForwarding)(t,(async(e,t)=>{const n=a.default.getInstance(e);new u.default(n).request("instance/open",{instanceUuids:t}).catch((()=>{}))})),e.body=!0}catch(t){e.body=t}})),y.post("/multi_stop",(0,s.default)({level:10}),(async e=>{try{const t=e.request.body;(0,l.multiOperationForwarding)(t,(async(e,t)=>{const n=a.default.getInstance(e);new u.default(n).request("instance/stop",{instanceUuids:t}).catch((()=>{}))})),e.body=!0}catch(t){e.body=t}})),y.post("/multi_kill",(0,s.default)({level:10}),(async e=>{try{const t=e.request.body;(0,l.multiOperationForwarding)(t,(async(e,t)=>{const n=a.default.getInstance(e);new u.default(n).request("instance/kill",{instanceUuids:t}).catch((e=>{}))})),e.body=!0}catch(t){e.body=t}})),y.get("/quick_install_list",(0,s.default)({level:10}),(async e=>{const t=g.systemConfig.quickInstallAddr;try{const n=await f.default.request({method:"GET",url:t});if(200!==n.status)throw new Error("Response code != 200");e.body=n.data}catch(t){e.body=[]}})),y.all("/forward",(0,s.default)({level:10}),(0,o.default)({query:{target:String}}),(async e=>{const t=String(e.query.target);try{const n=await f.default.request({method:e.request.method,url:t,data:e.request.body});if(200!==n.status)throw new Error("Response code != 200");e.body=n.data}catch(t){e.body=[]}})),t.default=y},658:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(2195)),a=r(n(4419)),u=r(n(5153)),l=r(n(2037)),d=n(9857),c=n(6296),f=r(n(299)),g=n(3210),y=new i.default({prefix:"/overview"});y.get("/",(0,s.default)({level:10,token:!1}),(async e=>{const t=new Array;for(const e of o.default.services.entries()){const n=e[1];let r={};try{r=await new u.default(n).request("info/overview")}catch(e){}r.uuid=n.uuid,r.ip=n.config.ip,r.port=n.config.port,r.available=n.available,r.remarks=n.config.remarks,t.push(r)}const n=(0,d.systemInfo)(),r={version:(0,c.getVersion)(),specifiedDaemonVersion:(0,c.specifiedDaemonVersion)(),process:{cpu:n.processCpu,memory:process.memoryUsage().rss,cwd:n.cwd},record:{logined:f.default.get(g.LOGIN_COUNT,0),illegalAccess:f.default.get(g.ILLEGAL_ACCESS_KEY,0),banips:f.default.get(g.BAN_IP_COUNT,0),loginFailed:f.default.get(g.LOGIN_FAILED_COUNT_KEY,0)},system:{user:l.default.userInfo(),time:(new Date).getTime(),totalmem:n.totalmem,freemem:n.freemem,type:n.type,version:l.default.version(),node:process.version,hostname:n.hostname,loadavg:n.loadavg,platform:n.platform,release:n.release,uptime:l.default.uptime(),cpu:n.cpuUsage},chart:{system:a.default.getSystemChartArray(),request:a.default.getStatusChartArray()},remoteCount:o.default.count(),remote:t};e.body=r})),t.default=y},556:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=r(n(2195)),u=r(n(5153)),l=new i.default({prefix:"/service"});l.get("/remote_services_list",(0,s.default)({level:10}),(async e=>{const t=new Array;for(const e of a.default.services.entries()){const n=e[1];t.push({uuid:n.uuid,ip:n.config.ip,port:n.config.port,available:n.available,remarks:n.config.remarks})}e.body=t})),l.get("/remote_service_instances",(0,s.default)({level:10}),(0,o.default)({query:{remote_uuid:String,page:Number,page_size:Number}}),(async e=>{const t=String(e.query.remote_uuid),n=Number(e.query.page),r=Number(e.query.page_size),i=e.query.instance_name,s=a.default.getInstance(t),o=await new u.default(s).request("instance/select",{page:n,pageSize:r,condition:{instanceName:i}});e.body=o})),l.get("/remote_services_system",(0,s.default)({level:10}),(async e=>{const t=new Array;for(const e of a.default.services.entries()){const n=e[1];let r=null;try{r=await new u.default(n).request("info/overview")}catch(e){continue}t.push(r)}e.body=t})),l.get("/remote_services",(0,s.default)({level:10}),(async e=>{const t=new Array;for(const e of a.default.services.entries()){const n=e[1];let r=[];try{r=await new u.default(n).request("instance/overview")}catch(e){}t.push({uuid:n.uuid,ip:n.config.ip,port:n.config.port,available:n.available,remarks:n.config.remarks,instances:r})}e.body=t})),l.post("/remote_service",(0,s.default)({level:10}),(0,o.default)({body:{apiKey:String,port:Number,ip:String,remarks:String}}),(async e=>{const t=e.request.body,n=await a.default.registerRemoteService({apiKey:t.apiKey,port:t.port,ip:t.ip,remarks:t.remarks||""});e.body=n.uuid})),l.put("/remote_service",(0,s.default)({level:10}),(0,o.default)({query:{uuid:String}}),(async e=>{const t=String(e.request.query.uuid),n=e.request.body;if(!a.default.services.has(t))throw new Error("Instance does not exist");await a.default.edit(t,{port:n.port,ip:n.ip,apiKey:n.apiKey,remarks:n.remarks}),e.body=!0})),l.delete("/remote_service",(0,s.default)({level:10}),(0,o.default)({query:{uuid:String}}),(async e=>{const t=String(e.request.query.uuid);if(!a.default.services.has(t))throw new Error("Instance does not exist");await a.default.deleteRemoteService(t),e.body=!0})),l.get("/link_remote_service",(0,s.default)({level:10}),(0,o.default)({query:{uuid:String}}),(async e=>{const t=String(e.request.query.uuid);if(!a.default.services.has(t))throw new Error("Instance does not exist");try{a.default.getInstance(t).connect(),e.body=!0}catch(t){e.body=t}})),t.default=l},1594:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(2195)),o=r(n(6746)),a=r(n(5542)),u=n(6547),l=n(8264),d=n(2231),c=r(n(6469)),f=new i.default({prefix:"/overview"});f.get("/setting",(0,o.default)({level:10}),(async e=>{e.body=u.systemConfig})),f.put("/setting",(0,a.default)({body:{}}),(0,o.default)({level:10}),(async e=>{const t=e.request.body;if(t)return null!=t.httpIp&&(u.systemConfig.httpIp=t.httpIp),null!=t.httpPort&&(u.systemConfig.httpPort=t.httpPort),null!=t.crossDomain&&(u.systemConfig.crossDomain=t.crossDomain),null!=t.gzip&&(u.systemConfig.gzip=t.gzip),null!=t.maxCompress&&(u.systemConfig.maxCompress=t.maxCompress),null!=t.maxDonwload&&(u.systemConfig.maxDonwload=t.maxDonwload),null!=t.zipType&&(u.systemConfig.zipType=t.zipType),null!=t.loginCheckIp&&(u.systemConfig.loginCheckIp=t.loginCheckIp),null!=t.forwardType&&(u.systemConfig.forwardType=Number(t.forwardType)),null!=t.dataPort&&(u.systemConfig.dataPort=Number(t.dataPort)),null!=t.loginInfo&&(u.systemConfig.loginInfo=String(t.loginInfo)),null!=t.canFileManager&&(u.systemConfig.canFileManager=Boolean(t.canFileManager)),null!=t.quickInstallAddr&&(u.systemConfig.quickInstallAddr=String(t.quickInstallAddr)),null!=t.language&&(l.logger.warn("Language change:",t.language),u.systemConfig.language=String(t.language),d.i18next.changeLanguage(u.systemConfig.language),s.default.changeDaemonLanguage(u.systemConfig.language)),(0,u.saveSystemConfig)(u.systemConfig),void(e.body="OK");e.body=new Error("The body is incorrect")})),f.put("/install",(async e=>{const t=e.request.body;if(0===c.default.objects.size)return null!=t.language&&(l.logger.warn("Language change:",t.language),u.systemConfig.language=String(t.language),d.i18next.changeLanguage(u.systemConfig.language),s.default.changeDaemonLanguage(u.systemConfig.language)),(0,u.saveSystemConfig)(u.systemConfig),void(e.body="OK");e.body=new Error("The MCSManager has been installed")})),t.default=f},3176:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(6469)),a=n(2231),u=new i.default({prefix:"/auth"});u.put("/",(0,s.default)({level:10}),(async e=>{const{uuid:t,config:n}=e.request.body,{passWord:r}=n;if(r&&!o.default.validatePassword(r))throw new Error((0,a.$t)("router.user.passwordCheck"));try{await o.default.edit(t,n),e.body=!0}catch(t){e.throw(500,t.message)}})),u.get("/overview",(0,s.default)({level:10}),(async e=>{const t=[];o.default.objects.forEach((e=>{t.push({uuid:e.uuid,userName:e.userName,permission:e.permission,instances:e.instances,loginTime:e.loginTime,registerTime:e.loginTime})})),e.body=t})),t.default=u},8179:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=n(3210),u=r(n(2195)),l=r(n(5153)),d=n(7382),c=n(2231),f=new i.default({prefix:"/protected_instance"});f.use((async(e,t)=>{const n=String(e.query.uuid),r=String(e.query.remote_uuid),i=(0,a.getUserUuid)(e);(0,d.isHaveInstanceByUuid)(i,r,n)?await t():(e.status=403,e.body=(0,c.$t)("permission.forbiddenInstance"))})),f.put("/low_permission",(0,s.default)({level:1}),(0,o.default)({query:{uuid:String,remote_uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=e.request.body,i={ie:String(r.ie),oe:String(r.oe),stopCommand:String(r.stopCommand)},s=u.default.getInstance(t);e.body=await new l.default(s).request("instance/update",{instanceUuid:n,config:i})}catch(t){e.body=t}})),t.default=f},286:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=r(n(2195)),u=r(n(5153)),l=n(1254),d=n(3210),c=n(7382),f=n(6547),g=n(2231),y=new i.default({prefix:"/files"});y.use((async(e,t)=>{const n=String(e.query.uuid),r=String(e.query.remote_uuid),i=(0,d.getUserUuid)(e);if(!1===f.systemConfig.canFileManager&&(0,d.getUserPermission)(e)<10)return e.status=403,void(e.body=new Error((0,g.$t)("router.file.off")));(0,c.isHaveInstanceByUuid)(i,r,n)?await t():(e.status=403,e.body=(0,g.$t)("permission.forbiddenInstance"))})),y.get("/status",(0,s.default)({level:1,speedLimit:!1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t),i=await new u.default(r).request("file/status",{instanceUuid:n});(0,c.isTopPermissionByUuid)((0,d.getUserUuid)(e))||delete i.disk,e.body=i}catch(t){e.body=t}})),y.get("/list",(0,s.default)({level:1,speedLimit:!1}),(0,o.default)({query:{remote_uuid:String,uuid:String,target:String,page:Number,page_size:Number}}),(async e=>{try{const t=String(e.query.target),n=String(e.query.remote_uuid),r=String(e.query.uuid),i=Number(e.query.page),s=Number(e.query.page_size),o=String(e.query.file_name),l=a.default.getInstance(n),d=await new u.default(l).request("file/list",{instanceUuid:r,target:t,pageSize:s,page:i,fileName:o});e.body=d}catch(t){e.body=t}})),y.put("/chmod",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{target:String,chmod:Number,deep:Boolean}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.request.body.target),i=Number(e.request.body.chmod),s=Number(e.request.body.deep),o=a.default.getInstance(t),l=await new u.default(o).request("file/chmod",{target:r,instanceUuid:n,chmod:i,deep:s});e.body=l}catch(t){e.body=t}})),y.post("/touch",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{target:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.request.body.target),i=a.default.getInstance(t),s=await new u.default(i).request("file/touch",{target:r,instanceUuid:n});e.body=s}catch(t){e.body=t}})),y.post("/mkdir",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{target:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.request.body.target),i=a.default.getInstance(t),s=await new u.default(i).request("file/mkdir",{target:r,instanceUuid:n});e.body=s}catch(t){e.body=t}})),y.put("/",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{target:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.request.body.target),i=e.request.body.text,s=a.default.getInstance(t),o=await new u.default(s).request("file/edit",{instanceUuid:n,target:r,text:i});e.body=o}catch(t){e.body=t}})),y.post("/copy",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{targets:Array}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=e.request.body.targets,i=a.default.getInstance(t),s=await new u.default(i).request("file/copy",{instanceUuid:n,targets:r});e.body=s}catch(t){e.body=t}})),y.put("/move",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{targets:Array}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=e.request.body.targets,i=a.default.getInstance(t),s=await new u.default(i).request("file/move",{instanceUuid:n,targets:r});e.body=s}catch(t){e.body=t}})),y.delete("/",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{targets:Object}}),(async e=>{try{const t=String(e.query.remote_uuid),n=e.query.uuid,r=e.request.body.targets,i=a.default.getInstance(t),s=await new u.default(i).request("file/delete",{instanceUuid:n,targets:r});e.body=s}catch(t){e.body=t}})),y.post("/compress",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{source:String,targets:Object,type:Number,code:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.request.body.source),i=e.request.body.targets,s=Number(e.request.body.type),o=String(e.request.body.code),l=a.default.getInstance(t);await new u.default(l).request("file/compress",{instanceUuid:n,targets:i,source:r,type:s,code:o}),e.body=!0}catch(t){e.body=t}})),y.all("/download",(0,s.default)({level:1}),(0,o.default)({query:{uuid:String,remote_uuid:String,file_name:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.file_name),i=a.default.getInstance(t),s=`${i.config.ip}:${i.config.port}`,o=(0,l.timeUuid)();await new u.default(i).request("passport/register",{name:"download",password:o,parameter:{fileName:r,instanceUuid:n}}),e.body={password:o,addr:s}}catch(t){e.body=t}})),y.all("/upload",(0,s.default)({level:1}),(0,o.default)({query:{uuid:String,remote_uuid:String,upload_dir:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.upload_dir),i=a.default.getInstance(t),s=`${i.config.ip}:${i.config.port}`,o=(0,l.timeUuid)();await new u.default(i).request("passport/register",{name:"upload",password:o,parameter:{uploadDir:r,instanceUuid:n}}),e.body={password:o,addr:s}}catch(t){e.body=t}})),t.default=y},3601:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=n(3210),a=r(n(6469)),u=n(3210),l=r(n(2195)),d=r(n(5153)),c=n(7382),f=r(n(5542)),g=n(5828),y=n(2231),m=new i.default({prefix:"/auth"});m.get("/token",(0,s.default)({level:1,token:!1,speedLimit:!1}),(async e=>{if(!(0,u.isAjax)(e))throw new Error("The request is not an Ajax request.");e.body=(0,u.getToken)(e)})),m.get("/",(0,s.default)({level:1,token:!1,speedLimit:!1}),(async e=>{let t=(0,o.getUserUuid)(e);const n=e.query.advanced;if((0,c.isTopPermissionByUuid)(t)&&e.query.uuid&&(t=String(e.query.uuid)),(0,u.isAjax)(e)){const r=a.default.getInstance(t);if(!r)throw new Error("The UID does not exist");let i=[];if(n){const e=r.instances;for(const t of e){const e=l.default.getInstance(t.serviceUuid);if(e)try{let n=await new d.default(e).request("instance/section",{instanceUuids:[t.instanceUuid]});n=n[0],i.push({hostIp:`${e.config.ip}:${e.config.port}`,remarks:e.config.remarks,instanceUuid:n.instanceUuid,serviceUuid:e.uuid,status:n.status,nickname:n.config.nickname,ie:n.config.ie,oe:n.config.oe,endTime:n.config.endTime,lastDatetime:n.config.lastDatetime,stopCommand:n.config.stopCommand})}catch(n){i.push({hostIp:`${e.config.ip}:${e.config.port}`,instanceUuid:t.instanceUuid,serviceUuid:t.serviceUuid,status:-1,nickname:"--"})}else i.push({hostIp:"-- Unknown --",instanceUuid:t.instanceUuid,serviceUuid:t.serviceUuid,status:-1,nickname:"--",remarks:"--"})}}else i=r.instances;e.body={uuid:r.uuid,userName:r.userName,loginTime:r.loginTime,registerTime:r.registerTime,instances:i,permission:r.permission,token:(0,u.getToken)(e),apiKey:r.apiKey,isInit:r.isInit}}})),m.put("/update",(0,s.default)({level:1}),(0,f.default)({body:{}}),(async e=>{const t=(0,o.getUserUuid)(e);if(t){const n=e.request.body,{passWord:r,isInit:i}=n;if(!a.default.validatePassword(r))throw new Error((0,y.$t)("router.user.passwordCheck"));await a.default.edit(t,{passWord:r,isInit:i}),e.body=!0}})),m.put("/api",(0,s.default)({level:1}),(0,f.default)({body:{}}),(async e=>{const t=(0,o.getUserUuid)(e),n=e.request.body.enable,r=a.default.getInstance(t);let i="";try{r&&(n?(i=(0,g.v4)().replace(/-/gim,""),await a.default.edit(t,{apiKey:i})):await a.default.edit(t,{apiKey:""})),e.body=i}catch(t){e.body=t}})),t.default=m},8377:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=r(n(2195)),u=r(n(5153)),l=n(3210),d=n(7382),c=n(1423),f=n(2231),g=new i.default({prefix:"/protected_schedule"});g.use((async(e,t)=>{const n=String(e.query.uuid),r=String(e.query.remote_uuid),i=(0,l.getUserUuid)(e);(0,d.isHaveInstanceByUuid)(i,r,n)?await t():(e.status=403,e.body=(0,f.$t)("permission.forbiddenInstance"))})),g.get("/",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=await new u.default(a.default.getInstance(t)).request("schedule/list",{instanceUuid:n});e.body=r}catch(t){e.body=t}})),g.post("/",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String},body:{name:String,count:Number,time:String,action:String,type:Number}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=e.request.body,i=String(r.name);c.FILENAME_BLACKLIST.forEach((e=>{if(i.includes(e))throw new Error((0,f.$t)("router.schedule.invalidName"))})),e.body=await new u.default(a.default.getInstance(t)).request("schedule/register",{instanceUuid:n,name:i,count:Number(r.count),time:String(r.time),action:String(r.action),payload:String(r.payload),type:Number(r.type)})}catch(t){e.body=t}})),g.delete("/",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.task_name);e.body=await new u.default(a.default.getInstance(t)).request("schedule/delete",{instanceUuid:n,name:r})}catch(t){e.body=t}})),t.default=g},5598:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(6746)),o=r(n(5542)),a=r(n(2195)),u=r(n(5153)),l=n(1254),d=n(3210),c=n(7382),f=n(2231),g=n(7382),y=n(9058),m=n(9058),p=n(9058),h=new i.default({prefix:"/protected_instance"});h.use((async(e,t)=>{const n=String(e.query.uuid),r=String(e.query.remote_uuid),i=(0,d.getUserUuid)(e);(0,c.isHaveInstanceByUuid)(i,r,n)?await t():(e.status=403,e.body=(0,f.$t)("permission.forbiddenInstance"))})),h.all("/open",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t),i=await new u.default(r).request("instance/open",{instanceUuids:[n]});e.body=i}catch(t){e.body=t}})),h.all("/stop",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t),i=await new u.default(r).request("instance/stop",{instanceUuids:[n]});e.body=i}catch(t){e.body=t}})),h.all("/command",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String,command:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.command),i=a.default.getInstance(t),s=await new u.default(i).request("instance/command",{instanceUuid:n,command:r});e.body=s}catch(t){e.body=t}})),h.all("/restart",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t),i=await new u.default(r).request("instance/restart",{instanceUuids:[n]});e.body=i}catch(t){e.body=t}})),h.all("/kill",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t),i=await new u.default(r).request("instance/kill",{instanceUuids:[n]});e.body=i}catch(t){e.body=t}})),h.post("/asynchronous",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String,task_name:String},body:{}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.task_name).toLowerCase().trim(),i=e.request.body;if(["quick_install"].includes(r)&&!(0,g.isTopPermissionByUuid)(e.session.uuid))throw new Error("illegal access");const s=a.default.getInstance(t),o=await new u.default(s).request("instance/asynchronous",{instanceUuid:n,taskName:r,parameter:i});e.body=o}catch(t){e.body=t}})),h.all("/stop_asynchronous",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=e.request.body,i=a.default.getInstance(t),s=await new u.default(i).request("instance/stop_asynchronous",{instanceUuid:n,parameter:r});e.body=s}catch(t){e.body=t}})),h.all("/query_asynchronous",(0,s.default)({level:10,speedLimit:!1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.task_name),i=e.request.body;if(!i.taskId&&!(0,g.isTopPermissionByUuid)((0,d.getUserUuid)(e)))throw new Error("Unauthorized access");const s=a.default.getInstance(t);e.body=await new u.default(s).request("instance/query_asynchronous",{instanceUuid:n,taskName:r,parameter:i})}catch(t){e.body=t}})),h.post("/stream_channel",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t),i=`${r.config.ip}:${r.config.port}`,s=(0,l.timeUuid)();await new u.default(r).request("passport/register",{name:"stream_channel",password:s,parameter:{instanceUuid:n}}),e.body={password:s,addr:i}}catch(t){e.body=t}})),h.post("/process_config/list",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=e.request.body.files,i=a.default.getInstance(t),s=await new u.default(i).request("instance/process_config/list",{instanceUuid:n,files:r});e.body=s}catch(t){e.body=t}})),h.get("/process_config/file",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String,fileName:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.fileName),i=String(e.query.type),s=a.default.getInstance(t),o=await new u.default(s).request("instance/process_config/file",{instanceUuid:n,fileName:r,config:null,type:i});e.body=o}catch(t){e.body=t}})),h.put("/process_config/file",(0,s.default)({level:1}),(0,o.default)({query:{remote_uuid:String,uuid:String,fileName:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=String(e.query.fileName),i=String(e.query.type),s=e.request.body,o=a.default.getInstance(t),l=await new u.default(o).request("instance/process_config/file",{instanceUuid:n,fileName:r,config:s,type:i});e.body=l}catch(t){e.body=t}})),h.put("/instance_update",(0,s.default)({level:1}),(0,o.default)({query:{uuid:String,remote_uuid:String},body:{}}),(async e=>{var t,n,r,i,s,o,l,d,c,f,g;try{const h=(0,y.toText)(e.query.remote_uuid),_=(0,y.toText)(e.query.uuid),v=e.request.body,w={ip:(0,y.toText)(null===(t=v.pingConfig)||void 0===t?void 0:t.ip),port:(0,p.toNumber)(null===(n=v.pingConfig)||void 0===n?void 0:n.port),type:null===(r=v.pingConfig)||void 0===r?void 0:r.type},b={autoStart:(0,m.toBoolean)(null===(i=v.eventTask)||void 0===i?void 0:i.autoStart),autoRestart:(0,m.toBoolean)(null===(s=v.eventTask)||void 0===s?void 0:s.autoRestart)},S={haveColor:(0,m.toBoolean)(null===(o=v.terminalOption)||void 0===o?void 0:o.haveColor),pty:(0,m.toBoolean)(null===(l=v.terminalOption)||void 0===l?void 0:l.pty),ptyWindowCol:(0,p.toNumber)(null===(d=v.terminalOption)||void 0===d?void 0:d.ptyWindowCol),ptyWindowRow:(0,p.toNumber)(null===(c=v.terminalOption)||void 0===c?void 0:c.ptyWindowRow)},q={openFrpTunnelId:(0,y.toText)(null===(f=v.extraServiceConfig)||void 0===f?void 0:f.openFrpTunnelId),openFrpToken:(0,y.toText)(null===(g=v.extraServiceConfig)||void 0===g?void 0:g.openFrpToken)},I=(0,y.isEmpty)(v.crlf)?null:(0,p.toNumber)(null==v?void 0:v.crlf),U=(0,y.isEmpty)(v.oe)?null:(0,y.toText)(null==v?void 0:v.oe),T=(0,y.isEmpty)(v.ie)?null:(0,y.toText)(null==v?void 0:v.ie),C=v.stopCommand?(0,y.toText)(v.stopCommand):null,k=a.default.getInstance(h),N=await new u.default(k).request("instance/update",{instanceUuid:_,config:{pingConfig:(0,y.isEmpty)(v.pingConfig)?null:w,eventTask:(0,y.isEmpty)(v.eventTask)?null:b,terminalOption:(0,y.isEmpty)(v.terminalOption)?null:S,extraServiceConfig:(0,y.isEmpty)(v.extraServiceConfig)?null:q,crlf:I,oe:U,ie:T,stopCommand:C}});e.body=N}catch(t){e.body=t}})),h.get("/outputlog",(0,s.default)({level:1,speedLimit:!1}),(0,o.default)({query:{remote_uuid:String,uuid:String}}),(async e=>{try{const t=String(e.query.remote_uuid),n=String(e.query.uuid),r=a.default.getInstance(t);let i=await new u.default(r).request("instance/outputlog",{instanceUuid:n});if(e.query.size){let t,n=e.query.size;n instanceof Array&&(n=n[0]),t=parseInt(n),n.toLowerCase().endsWith("kb")&&(t*=1024),i.length>t&&(i=i.slice(-t))}e.body=i}catch(t){e.body=t}})),t.default=h},3665:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1511)),s=r(n(5542)),o=r(n(6746)),a=n(3210),u=n(6547),l=r(n(6469)),d=n(8264),c=n(2231),f=r(n(2167)),g=new i.default({prefix:"/auth"});g.post("/login",(0,o.default)({token:!1,level:null}),(0,s.default)({body:{username:String,password:String}}),(async e=>{const t=String(e.request.body.username),n=String(e.request.body.password);if(!(0,a.checkBanIp)(e))throw new Error((0,c.$t)("router.login.ban"));if((0,a.check)(e))return e.body="Logined";if(!(0,a.login)(e,t,n))throw new Error((0,c.$t)("router.login.nameOrPassError"));e.body=!0})),g.get("/logout",(0,o.default)({token:!1,level:null,speedLimit:!1}),(async e=>{(0,a.logout)(e),e.body=!0})),g.all("/login_info",(0,o.default)({token:!1,level:null,speedLimit:!1}),(async e=>{e.body={loginInfo:u.systemConfig.loginInfo}})),g.all("/status",(0,o.default)({token:!1,level:null,speedLimit:!1}),(async e=>{let t=!0;0===l.default.objects.size&&(t=!1),e.body={isInstall:t,language:u.systemConfig.language||null}})),g.all("/install",(0,o.default)({token:!1,level:null}),(0,s.default)({body:{username:String,password:String}}),(async e=>{const t=e.request.body.username,n=e.request.body.password;if(0===l.default.objects.size){if(!l.default.validatePassword(n))throw new Error((0,c.$t)("router.user.passwordCheck"));return d.logger.info((0,c.$t)("router.login.init",{userName:t})),await l.default.create({userName:t,passWord:n,permission:10}),(0,a.login)(e,t,n),e.body=!0}throw new Error((0,c.$t)("router.user.installed"))})),g.all("/proxy",(0,s.default)({query:{target:String}}),(0,o.default)({level:10}),(async e=>{try{const t=await f.default.request({method:e.query.method||e.method,url:String(e.query.target)});if(200!==t.status)throw new Error("Response code != 200");e.body=t.data}catch(t){e.body=t}})),t.default=g},3858:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UniversalRemoteSubsystem=void 0;const r=n(5828);t.UniversalRemoteSubsystem=class{constructor(){this.services=new Map}setInstance(e,t){if(this.services.get(e))throw new Error("Instance already exists");this.services.set(e,t)}getInstance(e){return this.services.get(e)}deleteInstance(e){return this.services.delete(e)}randdomUuid(){return(0,r.v4)().replace(/-/gim,"")}}},6730:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.multiOperationForwarding=void 0,t.multiOperationForwarding=function(e,t){const n=new Map;for(const t of e){const e=t.serviceUuid,r=t.instanceUuid;n.has(e)?n.get(e).push(r):n.set(e,[r])}for(const e of n)t(e[0],e[1])}},8264:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.fullLocalTime=t.fullTime=t.logger=void 0;const i=r(n(4470)),s=r(n(8094)),o="logs/current.log";if(i.default.existsSync(o)){const e=new Date,t=`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()}_${e.getHours()}-${e.getMinutes()}-${e.getSeconds()}`;i.default.renameSync(o,`logs/${t}.log`)}s.default.configure({appenders:{out:{type:"stdout",layout:{type:"pattern",pattern:"[%d{MM/dd hh:mm:ss}] [%[%p%]] %m"}},app:{type:"file",filename:o,layout:{type:"pattern",pattern:"%d %p %m"}}},categories:{default:{appenders:["out","app"],level:"info"}}});const a=s.default.getLogger("default");t.logger=a,t.fullTime=function(){const e=new Date;return`${e.getFullYear()}/${e.getMonth()}/${e.getDate()}`},t.fullLocalTime=function(){return(new Date).toLocaleTimeString()}},3210:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getApiKey=t.isApiRequest=t.getUuidByApiKey=t.checkBanIp=t.isAjax=t.getToken=t.getUserUuid=t.getUserNameBySession=t.getUserPermission=t.register=t.logout=t.check=t.login=t.LOGIN_FAILED_COUNT_KEY=t.LOGIN_COUNT=t.ILLEGAL_ACCESS_KEY=t.LOGIN_FAILED_KEY=t.BAN_IP_COUNT=void 0;const i=r(n(6469)),s=n(1254),o=r(n(299)),a=n(6547),u=n(8264);function l(e){const t=i.default.getQueryWrapper().selectPage({apiKey:e},1,1);return 1===t.total?t.data[0]:null}function d(e){return!!e.query.apikey}function c(e){return String(e.query.apikey)}t.BAN_IP_COUNT="banip",t.LOGIN_FAILED_KEY="loginFailed",t.ILLEGAL_ACCESS_KEY="illegalAccess",t.LOGIN_COUNT="loginCount",t.LOGIN_FAILED_COUNT_KEY="loginFailedCount",t.login=function(e,n,r){o.default.set(t.LOGIN_COUNT,o.default.get(t.LOGIN_COUNT,0)+1);const a=e.socket.remoteAddress;if(i.default.checkUser({userName:n,passWord:r})){const r=o.default.get(t.LOGIN_FAILED_KEY);r&&delete r[a];const l=i.default.getUserByUserName(n);return l.loginTime=(new Date).toLocaleString(),e.session.login=!0,e.session.userName=n,e.session.uuid=l.uuid,e.session.token=(0,s.timeUuid)(),e.session.save(),u.logger.info(`[LOGIN] IP: ${a} Login ${n} successful!`),u.logger.info(`[LOGIN] Token: ${e.session.token}`),e.session.token}return o.default.set(t.LOGIN_FAILED_COUNT_KEY,o.default.get(t.LOGIN_FAILED_COUNT_KEY,0)+1),e.session.login=null,e.session.token=null,e.session.save(),u.logger.info(`[LOGIN] IP: ${a} login ${n} failed!`),null},t.check=function(e){return!!(e.session.login&&e.session.userName&&e.session.token)},t.logout=function(e){return e.session.login=null,e.session.userName=null,e.session.uuid=null,e.session.token=null,e.session.save(),!0},t.register=async function(e,t,n,r){let s=!0;return i.default.objects.forEach((e=>{e&&e.userName==t&&(s=!1)})),!!s&&(await i.default.create({userName:t,passWord:n,permission:r}),!0)},t.getUserPermission=function(e){var t;let n=null;return n=d(e)?l(c(e)):i.default.getInstance(e.session.uuid),n&&null!==(t=n.permission)&&void 0!==t?t:0},t.getUserNameBySession=function(e){if(d(e)){const t=l(c(e));return t?t.userName:null}return e.session.userName},t.getUserUuid=function(e){if(d(e)){const t=l(c(e));return t?t.uuid:null}return e.session.uuid},t.getToken=function(e){return e.session.token},t.isAjax=function(e){return e.header["x-requested-with"]&&"xmlhttprequest"===e.header["x-requested-with"].toString().toLocaleLowerCase()},t.checkBanIp=function(e){o.default.map.has(t.LOGIN_FAILED_KEY)||o.default.set(t.LOGIN_FAILED_KEY,{});const n=o.default.get(t.LOGIN_FAILED_KEY),r=e.socket.remoteAddress;return n[r]>10&&!0===a.systemConfig.loginCheckIp?(999!=n[r]&&(o.default.set(t.BAN_IP_COUNT,o.default.get(t.BAN_IP_COUNT,0)+1),setTimeout((()=>{delete n[r],o.default.set(t.BAN_IP_COUNT,o.default.get(t.BAN_IP_COUNT,1)-1)}),6e5)),n[r]=999,!1):(isNaN(Number(n[r]))?n[r]=1:n[r]=Number(n[r])+1,!0)},t.getUuidByApiKey=l,t.isApiRequest=d,t.getApiKey=c},1254:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.timeUuid=void 0;const r=n(5828);t.timeUuid=function(){let e=(0,r.v4)().replace(/-/gim,"");return e+=(new Date).getTime()+"",e}},7382:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.isHaveInstanceByUuid=t.isTopPermissionByUuid=t.isTopPermission=t.isHaveInstance=void 0;const i=r(n(6469));function s(e,t,n){if(o(e))return!0;if(e&&e.instances)for(const r of e.instances)if(t===r.serviceUuid&&n===r.instanceUuid)return!0;return!1}function o(e){return!!e&&e.permission>=10}t.isHaveInstance=s,t.isTopPermission=o,t.isTopPermissionByUuid=function(e){return o(i.default.getInstance(e))},t.isHaveInstanceByUuid=function(e,t,n){return s(i.default.getInstance(e),t,n)}},5153:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(5828),s=r(n(3204));class o extends Error{constructor(e){super(e)}}t.default=class{constructor(e){if(this.rService=e,!this.rService||!this.rService.socket)throw new Error("Unable to complete initialization, remote service does not exist.")}async request(e,t,n=6e3,r=!1){if(!this.rService.socket)throw new Error("The Socket must be SocketIOClient.Socket, Not null.");if(!this.rService.available&&!r)throw new Error("The remote daemon is not available. Try reconnecting to the remote daemon or check the configuration");if(!this.rService.socket.connected&&!r)throw new Error("The remote daemon connection is unavailable");return new Promise(((r,a)=>{const u=[(0,i.v4)(),(new Date).getTime()].join(""),l={uuid:u,data:t},d=setTimeout((()=>a(new o(`Request daemon:(${this.rService.config.ip}) [${e}] timeout`))),n),c=t=>{t.uuid===u&&(clearTimeout(d),this.rService.socket.removeEventListener(e,c),t.status==s.default.STATUS_OK?r(t.data):t.data.err?a(new o(t.data.err)):a(new o(t.data)))};this.rService.socket.on(e,c),this.rService.emit(e,l)}))}}},2195:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(8264),s=n(521),o=r(n(3204)),a=n(3858),u=r(n(9688)),l=r(n(4470)),d=r(n(1017)),c=n(2231);class f extends a.UniversalRemoteSubsystem{async initialize(){for(const e of await u.default.getStorage().list("RemoteServiceConfig")){const t=await u.default.getStorage().load("RemoteServiceConfig",s.RemoteServiceConfig,e),n=new o.default(e,t);this.setInstance(e,n),n.connect()}0===this.services.size&&await this.initConnectLocalhost(""),i.logger.info((0,c.$t)("systemRemoteService.nodeCount",{n:this.services.size})),setInterval((()=>this.connectionStatusCheckTask()),6e4)}async registerRemoteService(e){const t=await this.newInstance(e);return await u.default.getStorage().store("RemoteServiceConfig",t.uuid,t.config),t.connect(),t}async deleteRemoteService(e){this.getInstance(e)&&(this.getInstance(e).disconnect(),this.deleteInstance(e),await u.default.getStorage().delete("RemoteServiceConfig",e))}async newInstance(e){const t=new o.default(e.uuid||this.randdomUuid(),new s.RemoteServiceConfig);return this.setInstance(t.uuid,t),await this.edit(t.uuid,e),t}async edit(e,t){const n=this.getInstance(e);t.remarks&&(n.config.remarks=t.remarks),t.ip&&(n.config.ip=t.ip),t.port&&(n.config.port=t.port),t.apiKey&&(n.config.apiKey=t.apiKey),await u.default.getStorage().store("RemoteServiceConfig",n.uuid,n.config)}async initConnectLocalhost(e){const t="localhost",n=d.default.normalize(d.default.join(process.cwd(),"../daemon/data/Config/global.json"));if(i.logger.info((0,c.$t)("systemRemoteService.loadDaemonTitle",{localKeyFilePath:n})),l.default.existsSync(n)){i.logger.info((0,c.$t)("systemRemoteService.autoCheckDaemon"));const e=JSON.parse(l.default.readFileSync(n,{encoding:"utf-8"})),r=e.key,s=e.port;return await this.registerRemoteService({apiKey:r,port:s,ip:t})}if(e){const n=24444;return await this.registerRemoteService({apiKey:e,port:n,ip:t})}i.logger.warn((0,c.$t)("systemRemoteService.error")),setTimeout((()=>{if(0===this.services.size)return this.initConnectLocalhost()}),5e3)}count(){let e=0,t=0;return this.services.forEach((n=>{e++,n.available&&t++})),{available:t,total:e}}connectionStatusCheckTask(){var e;null===(e=this.services)||void 0===e||e.forEach((e=>{if(e&&!1===e.available)return i.logger.warn(`Daemon exception detected: ${e.config.remarks} ${e.config.ip}:${e.config.port}, reconnecting...`),e.connect()}))}changeDaemonLanguage(e){for(const t of this.services.entries())t[1].setLanguage(e)}}t.default=new f},6469:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(1490)),s=n(5828),o=n(1677),a=n(8264),u=r(n(9688)),l=n(9728),d=n(2231),c=r(n(8432));t.default=new class{constructor(){this.objects=new Map}async initialize(){for(const e of await u.default.getStorage().list("User")){const t=await u.default.getStorage().load("User",o.User,e);this.objects.set(e,t)}a.logger.info((0,d.$t)("systemUser.userCount",{n:this.objects.size}))}async create(e){const t=(0,s.v4)().replace(/-/gim,""),n=new o.User;return n.uuid=t,n.registerTime=(new Date).toLocaleString(),this.setInstance(t,n),await this.edit(n.uuid,e),await u.default.getStorage().store("User",n.uuid,n),n}async edit(e,t){const n=this.getInstance(e);t.userName&&(n.userName=t.userName),null!=t.isInit&&(n.isInit=Boolean(t.isInit)),t.permission&&(n.permission=t.permission),t.registerTime&&(n.registerTime=t.registerTime),t.loginTime&&(n.loginTime=t.loginTime),t.passWord&&(n.passWordType=o.UserPassWordType.bcrypt,n.passWord=c.default.hashSync(t.passWord,10)),t.instances&&this.setUserInstances(e,t.instances),null!=t.apiKey&&(n.apiKey=t.apiKey),await u.default.getStorage().store("User",e,n)}validatePassword(e=""){return!(e.length<9||e.length>36)&&/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])/.test(e)}checkUser(e){for(const[t,n]of this.objects)if(n.userName===e.userName)return n.passWordType===o.UserPassWordType.bcrypt?c.default.compareSync(e.passWord,n.passWord):(0,i.default)(e.passWord)===n.passWord;return!1}existUserName(e){let t=!1;return this.objects.forEach((n=>{if(n.userName===e)return t=!0})),t}setUserInstances(e,t){const n=this.getInstance(e);t.forEach((e=>{if(!e.serviceUuid||!e.instanceUuid)throw new Error("Type error, The instances of user must be IUserHaveInstance array.")})),n.instances=[],t.forEach((e=>{n.instances.push({instanceUuid:String(e.instanceUuid),serviceUuid:String(e.serviceUuid)})}))}getUserByUserName(e){for(const t of this.objects){const n=t[1];if(n.userName===e)return n}return null}getInstance(e){return this.objects.get(e)}setInstance(e,t){this.objects.set(e,t)}hasInstance(e){return this.objects.has(e)}async deleteInstance(e){this.hasInstance(e)&&(this.objects.delete(e),await u.default.getStorage().delete("User",e))}getQueryWrapper(){return new l.QueryWrapper(new l.LocalFileSource(this.objects))}}},4419:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=n(8264),s=n(9857),o=r(n(2195)),a=r(n(5153));class u{constructor(e,t){this.maxSize=e,this.arr=new Array;for(let n=0;n<e;n++)this.arr.push(t)}push(e){this.arr.length<this.maxSize||this.arr.shift(),this.arr.push(e)}getArray(){return this.arr}}t.default=new class{constructor(){this.countMap=new Map,this.systemChart=new u(60,{cpu:0,mem:0}),this.statusChart=new u(60,{value:0,totalInstance:0,runningInstance:0}),this.requestCount=0,setInterval((()=>{const e=(0,s.systemInfo)();e?this.systemChart.push({cpu:Number((100*e.cpuUsage).toFixed(1)),mem:Number((100*e.memUsage).toFixed(1))}):this.systemChart.push({cpu:0,mem:0})}),1e4),setInterval((async()=>{const e=new Array;for(const t of o.default.services.entries())try{e.push(await new a.default(t[1]).request("info/overview"))}catch(e){}let t=0,n=0;for(const r of e)r.instance&&(t+=r.instance.total,n+=r.instance.running);this.statusChart.push({value:this.requestCount,totalInstance:t,runningInstance:n}),this.requestCount=0}),1e4)}addRequestCount(){this.requestCount++}getSystemChartArray(){return this.systemChart.getArray()}getStatusChartArray(){return this.statusChart.getArray()}emitCountEvent(e){const t=this.countMap.get(e);t?this.countMap.set(e,t+1):this.countMap.set(e,1)}eventCount(e){return this.countMap.get(e)}emitLogEvent(e,t){const n=(new Date).toLocaleString();i.logger.info(`The object [${t}] triggered the [${e}] event at ${n}`)}}},237:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(2167)),s=n(6296),o=(new Date).getTime(),a=(0,s.getVersion)();async function u(){return await i.default.get("http://statistics.mcsmanager.com/",{params:{st:o,version:a},timeout:3e4})}setInterval((async()=>{try{return await u()}catch(e){}}),864e5),u().then((()=>{})).catch((()=>{}))},6547:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.systemConfig=t.saveSystemConfig=t.initSystemConfig=void 0;const i=r(n(3149)),s=r(n(2126)),o=n(2231);let a=null;t.systemConfig=a,t.initSystemConfig=function(){t.systemConfig=a=s.default.load("SystemConfig",i.default,"config"),a||(t.systemConfig=a=new i.default,s.default.store("SystemConfig","config",a)),a.language&&o.i18next.changeLanguage(a.language)},t.saveSystemConfig=function(e){s.default.store("SystemConfig","config",e)}},6296:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return i(t,e),t},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.specifiedDaemonVersion=t.getVersion=t.initVersionManager=void 0;const a=s(n(4470)),u=o(n(299)),l=n(8264),d="package.json";t.initVersionManager=function(){try{if(u.default.set("version","Unknown"),a.existsSync(d)){const e=JSON.parse(a.readFileSync(d,{encoding:"utf-8"}));e.version&&u.default.set("version",e.version)}}catch(e){l.logger.error("Version Check failure:",e)}},t.getVersion=function(){return u.default.get("version","Unknown")},t.specifiedDaemonVersion=function(){var e;try{return null!==(e=JSON.parse(a.readFileSync(d,{encoding:"utf-8"})).daemonVersion)&&void 0!==e?e:"1.0.0"}catch(e){return"1.0.0"}}},1511:e=>{e.exports=require("@koa/router")},2167:e=>{e.exports=require("axios")},8432:e=>{e.exports=require("bcryptjs")},4470:e=>{e.exports=require("fs-extra")},8805:e=>{e.exports=require("i18next")},1406:e=>{e.exports=require("koa")},5004:e=>{e.exports=require("koa-body")},9511:e=>{e.exports=require("koa-session")},8097:e=>{e.exports=require("koa-static")},8094:e=>{e.exports=require("log4js")},1490:e=>{e.exports=require("md5")},6634:e=>{e.exports=require("open")},7411:e=>{e.exports=require("os-utils")},7773:e=>{e.exports=require("redis")},8087:e=>{e.exports=require("socket.io-client")},5828:e=>{e.exports=require("uuid")},7147:e=>{e.exports=require("fs")},3685:e=>{e.exports=require("http")},2037:e=>{e.exports=require("os")},1017:e=>{e.exports=require("path")},2781:e=>{e.exports=require("stream")},5458:e=>{e.exports=JSON.parse('{"common":{"title":"Title"},"app":{"developInfo":"Unable to start! This is a developmenet project used by MCSManager developers.\\nPlease go to https://mcsmanager.com/ for installation instructions.\\nIf you insist to run this project in development mode, please manually create the following directory: public, src/public, put frontend static file in it to run.","panelStarted":"Panel started.","reference":"Project reference: https://github.com/mcsmanager","host":"Access address: http://localhost:{{port}}","portTip":"You need to open daemon port and port {{port}} for public access.","exitTip":"Use Ctrl+C to close this program.","httpSetupError":"The port may already be in use or the network device is unavailable."},"permission":{"forbidden":"Insufficient permission","forbiddenTokenError":"Failed to verify token (Token), access denied.","xmlhttprequestError":"Unable to find request head x-requested-with: xmlhttprequest","apiError":"Wrong key","forbiddenInstance":"[Forbidden] [Middleware] Incorrect parameters or illegal access.","tooFast":"Too many requests in a short time, please try again later."},"systemRemoteService":{"nodeCount":"Remote nodes: {{n}}","loadDaemonTitle":"Attempting to read local daemon {{localKeyFilePath}}","autoCheckDaemon":"Local daemon detected, trying to fetch key and port...","error":"Unable to load configuration from local daemon, please configure the daemon manually. Visit https://docs.mcsmanager.com/ for more information."},"systemUser":{"userCount":"Local users:{{n}}"},"router":{"user":{"invalidUserName":"Invalid username format","invalidPassword":"Invalid password format","existsUserName":"Username already exist.","deleteFailure":"Unable to delete user data","passwordCheck":"Password must contains the following: uppercase letter, lowercase letter, numbers, and a length between 9 and 36.","installed":"Unable to install panel: already installed. For reinstallation, backup and delete data folder."},"instance":{"createError":"Failed to create instance."},"file":{"off":"The system administrator has choose to restrict file management function for all users."},"schedule":{"invalidName":"Invalid task name"},"login":{"ban":"Your IP was blocked for 10 minutes due to multiple authentication failure.","nameOrPassError":"Incorrect username or password.","init":"[Installation] Initializing administrator account: {{userName}}","installed":"Unable to install panel: already installed. For reinstallation, backup and delete data folder."}},"daemonInfo":{"connect":"Remote node {{- v}} connected","disconnect":"Remote node {{- v}} disconnected","connectError":"Error connecting to remote node:{{- v}} ","authSuccess":"Remote node {{- v}} token verification succeed.","authFailure":"Remote node {{- v}} token verification failed.","authError":"Remote node {{- v}} token verification error.","closed":"Actively dissconnect from the remote node {{- v}} ","resetConnect":"User request to reconnect all available remote node, reconnecting...","replaceConnect":"User initiated a duplicate connection request, resetting the connection.","tryConnect":"Trying to connect remote node.","setLanguage":"Set node language."}}')},4035:e=>{e.exports=JSON.parse('{"common":{"title":"标题"},"app":{"developInfo":"无法启动,此项目是 MCSManager 开发人员所用项目,普通用户不可直接运行。\\n请前往 https://mcsmanager.com/ 了解最新的安装方式。\\n如果您要以开发模式运行,请创建 public,src/public 目录并放置前端静态文件再重新运行。","panelStarted":"控制面板端已启动","reference":"项目参考: https://github.com/mcsmanager","host":"访问地址: http://localhost:{{port}}","portTip":"软件公网访问需开放端口 {{port}} 与守护进程端口","exitTip":"关闭此程序请使用 Ctrl+C 快捷键","httpSetupError":"HTTP/Socket 服务启动错误,可能是端口被占用,权限不足或网卡设备不可用。"},"permission":{"forbidden":"权限不足","forbiddenTokenError":"令牌(Token)验证失败,拒绝访问","xmlhttprequestError":"无法找到请求头 x-requested-with: xmlhttprequest","apiError":"密钥不正确","forbiddenInstance":"[Forbidden] [中间件] 参数不正确或非法访问实例","tooFast":"请求速度过快,请稍后再进行操作"},"systemRemoteService":{"nodeCount":"远程节点数:{{n}}","loadDaemonTitle":"正在尝试读取本地守护进程 {{localKeyFilePath}}","autoCheckDaemon":"检测到本地守护进程,正在自动获取密钥和端口...","error":"无法自动获取本地守护进程配置文件,请前往面板手动连接守护进程,前往 https://docs.mcsmanager.com/ 了解更多。"},"systemUser":{"userCount":"本地用户数:{{n}}"},"router":{"user":{"invalidUserName":"非法的用户名格式","invalidPassword":"非法的密码格式","existsUserName":"用户名已经被占用","deleteFailure":"无法完成用户数据删除","passwordCheck":"密码不规范,必须为拥有大小写字母,数字,长度在9到36之间","installed":"管理员账号已经创建,不可重复创建"},"instance":{"createError":"创建实例失败"},"file":{"off":"管理员已限制全部用户使用文件管理功能"},"schedule":{"invalidName":"非法的计划任务名"},"login":{"ban":"身份验证次数过多,您的 IP 地址已被锁定 10 分钟","nameOrPassError":"账号或密码错误","init":"[安装面板] 正在初始化面板管理员账号: {{userName}}","installed":"面板已安装,无法重新安装,请备份并删除 data 文件夹以实现全新安装"}},"daemonInfo":{"connect":"远程节点 {{- v}} 已连接","disconnect":"远程节点 {{- v}} 已断开","connectError":"连接远程节点错误:{{- v}} ","authSuccess":"远程节点 {{- v}} 密钥验证通过","authFailure":"远程节点 {{- v}} 密钥验证拒绝","authError":"远程节点 {{- v}} 密钥验证错误","closed":"主动断开远程节点 {{- v}} ","resetConnect":"用户发起重连已可用状态的远程节点,正在重置连接通道","replaceConnect":"用户发起重复连接请求,现进行重置连接配置","tryConnect":"正在尝试连接远程节点","setLanguage":"设置节点语言"}}')}},t={};!function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.exports}(3165)})();