class e{static name="Lodash";static version="1.2.2";static about(){return console.log(`\n🟧 ${this.name} v${this.version}\n`)}static get(e={},t="",n=void 0){Array.isArray(t)||(t=this.toPath(t));const s=t.reduce(((e,t)=>Object(e)[t]),e);return void 0===s?n:s}static set(e={},t="",n){return Array.isArray(t)||(t=this.toPath(t)),t.slice(0,-1).reduce(((e,n,s)=>Object(e[n])===e[n]?e[n]:e[n]=/^\d+$/.test(t[s+1])?[]:{}),e)[t[t.length-1]]=n,e}static unset(e={},t=""){return Array.isArray(t)||(t=this.toPath(t)),t.reduce(((e,n,s)=>s===t.length-1?(delete e[n],!0):Object(e)[n]),e)}static toPath(e){return e.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean)}static escape(e){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(/[&<>"']/g,(e=>t[e]))}static unescape(e){const t={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"};return e.replace(/&amp;|&lt;|&gt;|&quot;|&#39;/g,(e=>t[e]))}}class t{static name="$Storage";static version="1.0.9";static about(){return console.log(`\n🟧 ${this.name} v${this.version}\n`)}static data=null;static dataFile="box.dat";static#e=/^@(?<key>[^.]+)(?:\.(?<path>.*))?$/;static#t(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":"undefined"!=typeof Egern?"Egern":void 0}static getItem(t=new String,n=null){let s=n;if(!0===t.startsWith("@")){const{key:n,path:o}=t.match(this.#e)?.groups;t=n;let r=this.getItem(t,{});"object"!=typeof r&&(r={}),s=e.get(r,o);try{s=JSON.parse(s)}catch(e){}}else{switch(this.#t()){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":s=$persistentStore.read(t);break;case"Quantumult X":s=$prefs.valueForKey(t);break;case"Node.js":this.data=this.#n(this.dataFile),s=this.data?.[t];break;default:s=this.data?.[t]||null}try{s=JSON.parse(s)}catch(e){}}return s??n}static setItem(t=new String,n=new String){let s=!1;if("object"==typeof n)n=JSON.stringify(n);else n=String(n);if(!0===t.startsWith("@")){const{key:o,path:r}=t.match(this.#e)?.groups;t=o;let i=this.getItem(t,{});"object"!=typeof i&&(i={}),e.set(i,r,n),s=this.setItem(t,i)}else switch(this.#t()){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":s=$persistentStore.write(n,t);break;case"Quantumult X":s=$prefs.setValueForKey(n,t);break;case"Node.js":this.data=this.#n(this.dataFile),this.data[t]=n,this.#s(this.dataFile),s=!0;break;default:s=this.data?.[t]||null}return s}static removeItem(t){let n=!1;if(!0===t.startsWith("@")){const{key:s,path:o}=t.match(this.#e)?.groups;t=s;let r=this.getItem(t);"object"!=typeof r&&(r={}),keyValue=e.unset(r,o),n=this.setItem(t,r)}else switch(this.#t()){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":case"Node.js":default:n=!1;break;case"Quantumult X":n=$prefs.removeValueForKey(t)}return n}static clear(){let e=!1;switch(this.#t()){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":case"Node.js":default:e=!1;break;case"Quantumult X":e=$prefs.removeAllValues()}return e}static#n(e){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(e),n=this.path.resolve(process.cwd(),e),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(n);if(!s&&!o)return{};{const e=s?t:n;try{return JSON.parse(this.fs.readFileSync(e))}catch(e){return{}}}}}static#s(e=this.dataFile){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(e),n=this.path.resolve(process.cwd(),e),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(n),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):o?this.fs.writeFileSync(n,r):this.fs.writeFileSync(t,r)}}}class n{static name="ENV";static version="1.7.1";static about(){return console.log(`\n🟧 ${this.name} v${this.version}\n`)}constructor(e,t){console.log(`\n🟧 ${n.name} v${n.version}\n`),this.name=e,this.logs=[],this.isMute=!1,this.isMuteLog=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,t),this.log(`\n🚩 开始!\n${e}\n`)}platform(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":"undefined"!=typeof Egern?"Egern":void 0}isNode(){return"Node.js"===this.platform()}isQuanX(){return"Quantumult X"===this.platform()}isSurge(){return"Surge"===this.platform()}isLoon(){return"Loon"===this.platform()}isShadowrocket(){return"Shadowrocket"===this.platform()}isStash(){return"Stash"===this.platform()}isEgern(){return"Egern"===this.platform()}async getScript(e){return await this.fetch(e).then((e=>e.body))}async runScript(e,n){let s=t.getItem("@chavy_boxjs_userCfgs.httpapi");s=s?.replace?.(/\n/g,"")?.trim();let o=t.getItem("@chavy_boxjs_userCfgs.httpapi_timeout");o=1*o??20,o=n?.timeout??o;const[r,i]=s.split("@"),a={url:`http://${i}/v1/scripting/evaluate`,body:{script_text:e,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};await this.fetch(a).then((e=>e.body),(e=>this.logErr(e)))}initGotEnv(e){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,e&&(e.headers=e.headers?e.headers:{},void 0===e.headers.Cookie&&void 0===e.cookieJar&&(e.cookieJar=this.ckjar))}async fetch(t={}||"",n={}){switch(t.constructor){case Object:t={...t,...n};break;case String:t={url:t,...n}}t.method||(t.method="GET",(t.body??t.bodyBytes)&&(t.method="POST")),delete t.headers?.["Content-Length"],delete t.headers?.["content-length"];const s=t.method.toLocaleLowerCase();switch(this.platform()){case"Loon":case"Surge":case"Stash":case"Egern":case"Shadowrocket":default:return delete t.id,t.policy&&(this.isLoon()&&(t.node=t.policy),this.isStash()&&e.set(t,"headers.X-Stash-Selected-Proxy",encodeURI(t.policy))),ArrayBuffer.isView(t.body)&&(t["binary-mode"]=!0),await new Promise(((e,n)=>{$httpClient[s](t,((s,o,r)=>{s?n(s):(o.ok=/^2\d\d$/.test(o.status),o.statusCode=o.status,r&&(o.body=r,1==t["binary-mode"]&&(o.bodyBytes=r)),e(o))}))}));case"Quantumult X":return t.policy&&e.set(t,"opts.policy",t.policy),delete t.charset,delete t.host,delete t.path,delete t.policy,delete t.scheme,delete t.sessionIndex,delete t.statusCode,t.body instanceof ArrayBuffer?(t.bodyBytes=t.body,delete t.body):ArrayBuffer.isView(t.body)?(t.bodyBytes=t.body.buffer.slice(t.body.byteOffset,t.body.byteLength+t.body.byteOffset),delete object.body):t.body&&delete t.bodyBytes,await $task.fetch(t).then((e=>(e.ok=/^2\d\d$/.test(e.statusCode),e.status=e.statusCode,e)),(e=>Promise.reject(e.error)));case"Node.js":let n=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;return await this.got[s](o,r).on("redirect",((e,t)=>{try{if(e.headers["set-cookie"]){const n=e.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();n&&this.ckjar.setCookieSync(n,null),t.cookieJar=this.ckjar}}catch(e){this.logErr(e)}})).then((e=>(e.statusCode=e.status,e.body=n.decode(e.rawBody,this.encoding),e.bodyBytes=e.rawBody,e)),(e=>Promise.reject(e.message)))}}time(e,t=null){const n=t?new Date(t):new Date;let s={"M+":n.getMonth()+1,"d+":n.getDate(),"H+":n.getHours(),"m+":n.getMinutes(),"s+":n.getSeconds(),"q+":Math.floor((n.getMonth()+3)/3),S:n.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(n.getFullYear()+"").substr(4-RegExp.$1.length)));for(let t in s)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?s[t]:("00"+s[t]).substr((""+s[t]).length)));return e}msg(e=name,t="",n="",s){const o=e=>{switch(typeof e){case void 0:return e;case"string":switch(this.platform()){case"Surge":case"Stash":case"Egern":default:return{url:e};case"Loon":case"Shadowrocket":return e;case"Quantumult X":return{"open-url":e};case"Node.js":return}case"object":switch(this.platform()){case"Surge":case"Stash":case"Egern":case"Shadowrocket":default:return{url:e.url||e.openUrl||e["open-url"]};case"Loon":return{openUrl:e.openUrl||e.url||e["open-url"],mediaUrl:e.mediaUrl||e["media-url"]};case"Quantumult X":return{"open-url":e["open-url"]||e.url||e.openUrl,"media-url":e["media-url"]||e.mediaUrl,"update-pasteboard":e["update-pasteboard"]||e.updatePasteboard};case"Node.js":return}default:return}};if(!this.isMute)switch(this.platform()){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":default:$notification.post(e,t,n,o(s));break;case"Quantumult X":$notify(e,t,n,o(s));case"Node.js":}if(!this.isMuteLog){let s=["","==============📣系统通知📣=============="];s.push(e),t&&s.push(t),n&&s.push(n),console.log(s.join("\n")),this.logs=this.logs.concat(s)}}log(...e){e.length>0&&(this.logs=[...this.logs,...e]),console.log(e.join(this.logSeparator))}logErr(e){switch(this.platform()){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️ ${this.name}, 错误!`,e);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e.stack)}}wait(e){return new Promise((t=>setTimeout(t,e)))}done(t={}){const n=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🚩 ${this.name}, 结束! 🕛 ${n} 秒`,""),this.platform()){case"Surge":t.policy&&e.set(t,"headers.X-Surge-Policy",t.policy),$done(t);break;case"Loon":t.policy&&(t.node=t.policy),$done(t);break;case"Stash":t.policy&&e.set(t,"headers.X-Stash-Selected-Proxy",encodeURI(t.policy)),$done(t);break;case"Egern":case"Shadowrocket":default:$done(t);break;case"Quantumult X":t.policy&&e.set(t,"opts.policy",t.policy),delete t.charset,delete t.host,delete t.method,delete t.opt,delete t.path,delete t.policy,delete t.scheme,delete t.sessionIndex,delete t.statusCode,t.body instanceof ArrayBuffer?(t.bodyBytes=t.body,delete t.body):ArrayBuffer.isView(t.body)?(t.bodyBytes=t.body.buffer.slice(t.body.byteOffset,t.body.byteLength+t.body.byteOffset),delete t.body):t.body&&delete t.bodyBytes,$done(t);break;case"Node.js":process.exit(1)}}}function s(n,s,o){let r=t.getItem(n,o),i={};if("undefined"!=typeof $argument&&Boolean($argument)){let t=Object.fromEntries($argument.split("&").map((e=>e.split("=").map((e=>e.replace(/\"/g,""))))));for(let n in t)e.set(i,n,t[n])}const a={Settings:o?.Default?.Settings||{},Configs:o?.Default?.Configs||{},Caches:{}};Array.isArray(s)||(s=[s]);for(let e of s)a.Settings={...a.Settings,...o?.[e]?.Settings,...i,...r?.[e]?.Settings},a.Configs={...a.Configs,...o?.[e]?.Configs},r?.[e]?.Caches&&"string"==typeof r?.[e]?.Caches&&(r[e].Caches=JSON.parse(r?.[e]?.Caches)),a.Caches={...a.Caches,...r?.[e]?.Caches};return function e(t,n){for(var s in t){var o=t[s];t[s]="object"==typeof o&&null!==o?e(o,n):n(s,o)}return t}(a.Settings,((e,t)=>("true"===t||"false"===t?t=JSON.parse(t):"string"==typeof t&&(t=t.includes(",")?t.split(",").map((e=>c(e))):c(t)),t))),a;function c(e){return e&&!isNaN(e)&&(e=parseInt(e,10)),e}}var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i={exports:{}};var a,c,l={exports:{}};function u(){return a||(a=1,l.exports=(e=e||function(e,t){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==o&&o.crypto&&(n=o.crypto),!n)try{n=require("crypto")}catch(e){}var s=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},r=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),i={},a=i.lib={},c=a.Base={extend:function(e){var t=r(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},l=a.WordArray=c.extend({init:function(e,n){e=this.words=e||[],this.sigBytes=n!=t?n:4*e.length},toString:function(e){return(e||d).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes,o=e.sigBytes;if(this.clamp(),s%4)for(var r=0;r<o;r++){var i=n[r>>>2]>>>24-r%4*8&255;t[s+r>>>2]|=i<<24-(s+r)%4*8}else for(var a=0;a<o;a+=4)t[s+a>>>2]=n[a>>>2];return this.sigBytes+=o,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=c.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],n=0;n<e;n+=4)t.push(s());return new l.init(t,e)}}),u=i.enc={},d=u.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,s=[],o=0;o<n;o++){var r=t[o>>>2]>>>24-o%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s<t;s+=2)n[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new l.init(n,t/2)}},p=u.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,s=[],o=0;o<n;o++){var r=t[o>>>2]>>>24-o%4*8&255;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s<t;s++)n[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new l.init(n,t)}},h=u.Utf8={stringify:function(e){try{return decodeURIComponent(escape(p.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return p.parse(unescape(encodeURIComponent(e)))}},f=a.BufferedBlockAlgorithm=c.extend({reset:function(){this._data=new l.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n,s=this._data,o=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,u=e.min(4*c,r);if(c){for(var d=0;d<c;d+=i)this._doProcessBlock(o,d);n=o.splice(0,c),s.sigBytes-=u}return new l.init(n,u)},clone:function(){var e=c.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});a.Hasher=f.extend({cfg:c.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new g.HMAC.init(e,n).finalize(t)}}});var g=i.algo={};return i}(Math),e)),l.exports;var e}var d=r(i.exports=(c=u(),function(){var e=c,t=e.lib.WordArray;function n(e,n,s){for(var o=[],r=0,i=0;i<n;i++)if(i%4){var a=s[e.charCodeAt(i-1)]<<i%4*2|s[e.charCodeAt(i)]>>>6-i%4*2;o[r>>>2]|=a<<24-r%4*8,r++}return t.create(o,r)}e.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,s=this._map;e.clamp();for(var o=[],r=0;r<n;r+=3)for(var i=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;a<4&&r+.75*a<n;a++)o.push(s.charAt(i>>>6*(3-a)&63));var c=s.charAt(64);if(c)for(;o.length%4;)o.push(c);return o.join("")},parse:function(e){var t=e.length,s=this._map,o=this._reverseMap;if(!o){o=this._reverseMap=[];for(var r=0;r<s.length;r++)o[s.charCodeAt(r)]=r}var i=s.charAt(64);if(i){var a=e.indexOf(i);-1!==a&&(t=a)}return n(e,t,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),c.enc.Base64)),p={Switch:!0},h={Settings:p},f={Switch:!0,Title:"☁ 𝙒𝘼𝙍𝙋 𝙄𝙣𝙛𝙤",Icon:"lock.icloud.fill",IconColor:"#f48220",BackgroundColor:"#f6821f",Language:"auto"},g={Request:{url:"https://api.cloudflareclient.com",headers:{authorization:null,"content-Type":"application/json","user-agent":"1.1.1.1/6.22","cf-client-version":"i-6.22-2308151957.1"}},i18n:{"zh-Hans":{IPv4:"IPv4",IPv6:"IPv6",COLO:"托管中心",WARP_Level:"隐私保护",Account_Type:"账户类型",Data_Info:"流量信息",Unknown:"未知",Fail:"获取失败",WARP_Level_Off:"关闭",WARP_Level_On:"开启",WARP_Level_Plus:"增强",Account_Type_unlimited:"无限版",Account_Type_limited:"有限版",Account_Type_team:"团队版",Account_Type_plus:"WARP+",Account_Type_free:"免费版",Data_Info_Used:"已用",Data_Info_Residual:"剩余",Data_Info_Total:"总计",Data_Info_Unlimited:"无限"},"zh-Hant":{IPv4:"IPv4",IPv6:"IPv6",COLO:"託管中心",WARP_Level:"隱私保護",Account_Type:"賬戶類型",Data_Info:"流量信息",Unknown:"未知",Fail:"獲取失敗",WARP_Level_Off:"關閉",WARP_Level_On:"開啟",WARP_Level_Plus:"增強",Account_Type_unlimited:"無限版",Account_Type_limited:"有限版",Account_Type_team:"團隊版",Account_Type_plus:"WARP+",Account_Type_free:"免費版",Data_Info_Used:"已用",Data_Info_Residual:"剩餘",Data_Info_Total:"總計",Data_Info_Unlimited:"無限"},en:{IPv4:"IPv4",IPv6:"IPv6",COLO:"Colo Center",WARP_Level:"WARP Level",Account_Type:"Account Type",Data_Info:"Data Info.",Unknown:"Unknown",Fail:"Fail to Get",WARP_Level_Off:"OFF",WARP_Level_On:"ON",WARP_Level_Plus:"PLUS",Account_Type_unlimited:"Unlimited",Account_Type_limited:"Limited",Account_Type_team:"Team",Account_Type_plus:"WARP+",Account_Type_free:"Free",Data_Info_Used:"Used",Data_Info_Residual:"Remaining",Data_Info_Total:"Earned",Data_Info_Unlimited:"Unlimited"}}},y={Settings:f,Configs:g},m={Switch:!0,setupMode:"ChangeKeypair",Verify:{RegistrationId:null,Mode:"Token",Content:null}},v={Settings:m},S={Switch:!0,IPServer:"ipw.cn",Verify:{Mode:"Token",Content:""},zone:{id:"",name:"",dns_records:[{id:"",type:"A",name:"",content:"",ttl:1,proxied:!1}]}},_={Request:{url:"https://api.cloudflare.com/client/v4",headers:{"content-type":"application/json"}}},$={Settings:S,Configs:_},w={Switch:!0,setupMode:null,deviceType:"iOS",Verify:{License:null,Mode:"Token",Content:null,RegistrationId:null}},b={Request:{url:"https://api.cloudflareclient.com",headers:{authorization:null,"content-Type":"application/json","user-agent":"1.1.1.1/6.22","cf-client-version":"i-6.22-2308151957.1"}},Environment:{iOS:{Type:"i",Version:"v0i2308151957",headers:{"user-agent":"1.1.1.1/6.22","cf-client-version":"i-6.22-2308151957.1"}},macOS:{Type:"m",Version:"v0i2109031904",headers:{"user-agent":"1.1.1.1/2109031904.1 CFNetwork/1327.0.4 Darwin/21.2.0","cf-client-version":"m-2021.12.1.0-0"}},Android:{Type:"a",Version:"v0a1922",headers:{"user-agent":"okhttp/3.12.1","cf-client-version":"a-6.3-1922"}},Windows:{Type:"w",Version:"",headers:{"user-agent":"","cf-client-version":""}},Linux:{Type:"l",Version:"",headers:{"user-agent":"","cf-client-version":""}}}},k={Settings:w,Configs:b},C={Switch:!0,PrivateKey:"",PublicKey:""},A={interface:{addresses:{v4:"",v6:""}},peers:[{public_key:"",endpoint:{host:"",v4:"",v6:""}}]},P={Settings:C,Configs:A},x=Database={Default:Object.freeze({__proto__:null,Settings:p,default:h}),Panel:Object.freeze({__proto__:null,Configs:g,Settings:f,default:y}),"1dot1dot1dot1":Object.freeze({__proto__:null,Settings:m,default:v}),DNS:Object.freeze({__proto__:null,Configs:_,Settings:S,default:$}),WARP:Object.freeze({__proto__:null,Configs:b,Settings:w,default:k}),VPN:Object.freeze({__proto__:null,Configs:A,Settings:C,default:P})};const I=new n("☁ Cloudflare: 1️⃣ 1.1.1.1 v3.0.1(4).response"),O=class{static name="URI";static version="1.2.7";static about(){return console.log(`\n🟧 ${this.name} v${this.version}\n`)}static#o={scheme:"",host:"",path:"",query:{}};static parse(e){let t=e.match(/(?:(?<scheme>.+):\/\/(?<host>[^/]+))?\/?(?<path>[^?]+)?\??(?<query>[^?]+)?/)?.groups??null;if(t?.path?t.paths=t.path.split("/"):t.path="",t?.paths){const e=t.paths[t.paths.length-1];if(e?.includes(".")){const n=e.split(".");t.format=n[n.length-1]}}return t?.query&&(t.query=Object.fromEntries(t.query.split("&").map((e=>e.split("="))))),t}static stringify(e=this.#o){let t="";return e?.scheme&&e?.host&&(t+=e.scheme+"://"+e.host),e?.path&&(t+=e?.host?"/"+e.path:e.path),e?.query&&(t+="?"+Object.entries(e.query).map((e=>e.join("="))).join("&")),t}}.parse($request.url);I.log(`⚠ URL: ${JSON.stringify(O)}`,"");const j=$request.method;O.host,O.path;const R=O.paths;I.log(`⚠ METHOD: ${j}`,"");const T=($response.headers?.["Content-Type"]??$response.headers?.["content-type"])?.split(";")?.[0];I.log(`⚠ FORMAT: ${T}`,""),(async()=>{const{Settings:n,Caches:o,Configs:r}=function(t,n,o){console.log("☑️ Set Environment Variables","");let{Settings:r,Caches:i,Configs:a}=s(t,n,o);switch(r.Verify?.Mode){case"Token":e.set(a,"Request.headers.authorization",`Bearer ${r.Verify?.Content}`);break;case"ServiceKey":e.set(a,"Request.headers.x-auth-user-service-key",r.Verify?.Content);break;case"Key":e.set(r,"Verify.Content",Array.from(r.Verify?.Content.split("\n"))),e.set(a,"Request.headers.x-auth-key",r.Verify?.Content[0]),e.set(a,"Request.headers.x-auth-email",r.Verify?.Content[1]);break;default:console.log(`无可用授权方式\nMode=${r.Verify?.Mode}\nContent=${r.Verify?.Content}`);case void 0:}return r.zone?.dns_records&&(r.zone.dns_records=Array.from(r.zone.dns_records.split("\n")),r.zone.dns_records.forEach(((e,t)=>{r.zone.dns_records[t]=Object.fromEntries(e.split("&").map((e=>e.split("=")))),r.zone.dns_records[t].proxied=JSON.parse(r.zone.dns_records[t].proxied)}))),console.log(`✅ Set Environment Variables, Settings: ${typeof r}, Settings内容: ${JSON.stringify(r)}`,""),{Settings:r,Caches:i,Configs:a}}("Cloudflare","1dot1dot1dot1",x);switch(I.log(`⚠ Settings.Switch: ${n?.Switch}`,""),n.Switch){case!0:default:const e=s("WireGuard","VPN",x),o=($request?.headers?.Authorization??$request?.headers?.authorization)?.match(/Bearer (\S*)/)?.[1],r=`/${R[1]}/${R[2]}`==`/reg/${n.Verify.RegistrationId}`?"RegistrationId":"/reg"==`/${R[1]}`?"Registration":void 0;I.log(`🚧 KIND: ${r}`,"");let i={};switch(T){case void 0:case"application/x-www-form-urlencoded":case"text/plain":default:case"application/x-mpegURL":case"application/x-mpegurl":case"application/vnd.apple.mpegurl":case"audio/mpegurl":case"text/xml":case"text/html":case"text/plist":case"application/xml":case"application/plist":case"application/x-plist":case"text/vtt":case"application/vtt":break;case"text/json":case"application/json":switch(i=JSON.parse($response.body),Array.isArray(i.messages)&&i.messages.forEach((e=>I.msg(I.name,`code: ${e.code}`,`message: ${e.message}`))),i.success){case!0:const n=i?.result?.[0]??i?.result;if(n){n.config.reserved=await async function(e="AAAA"){I.log("⚠ Set Reserved","");let t=n(d.parse(e).toString(),2);return I.log("🎉 Set Reserved",`reserved: ${t}`,""),t;function n(e,t){let n=[];for(var s=0,o=e.length;s<o/t;s++)n.push(parseInt("0x"+e.slice(t*s,t*(s+1)),16));return n}}(n?.config?.client_id),await async function(e,n,s){return I.log("☑️ Set Configs",""),t.setItem(`@${e}.${n}.Configs.interface.addresses.v4`,s?.interface?.addresses?.v4),t.setItem(`@${e}.${n}.Configs.interface.addresses.v6`,s?.interface?.addresses?.v6),t.setItem(`@${e}.${n}.Configs.Reserved`,s?.reserved),t.setItem(`@${e}.${n}.Configs.peers[0].public_key`,s?.peers?.[0]?.public_key),t.setItem(`@${e}.${n}.Configs.peers[0].endpoint.host`,s?.peers?.[0]?.endpoint?.host),t.setItem(`@${e}.${n}.Configs.peers[0].endpoint.v4`,s?.peers?.[0]?.endpoint?.v4),t.setItem(`@${e}.${n}.Configs.peers[0].endpoint.v6`,s?.peers?.[0]?.endpoint?.v6),I.log("✅ Set Configs","")}("WireGuard","VPN",n.config);const s=await async function(e,t){I.log("☑️ Set Message","");const n=`当前客户端公钥为:\n${e.key}\n用户设置公钥为:\n${t?.Settings?.PublicKey??"未设置，请到BoxJs面板中进行设置"}\n如两者一致，下列配置有效`;let s=`有效性验证:\n${n}\n\n\n⚠️注意留存本文件\n\n\n`;switch(I.platform()){case"Surge":s+=`Surge用配置:\n${`[Proxy]\nWARP = wireguard, section-name=Cloudflare, test-url=http://cp.cloudflare.com/generate_204\n\n[WireGuard Cloudflare]\nprivate-key = ${t?.Settings?.PrivateKey}\nself-ip = ${e?.config?.interface?.addresses?.v4}\nself-ip-v6 = ${e?.config?.interface?.addresses?.v6}\ndns-server = 1.1.1.1, 2606:4700:4700::1111\nmtu = 1280\npeer = (public-key = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=, allowed-ips = "0.0.0.0/0, ::/0", endpoint = engage.nanocat.cloud:2408, keepalive = 45, client-id = ${e?.config?.reserved?.[0]}/${e?.config?.reserved?.[1]}/${e?.config?.reserved?.[2]})`}`;break;case"Loon":s+=`Loon用配置:\n${`[Proxy]\nWARP = wireguard, interface-ip=${e?.config?.interface?.addresses?.v4}, interface-ipv6=${e?.config?.interface?.addresses?.v6}, private-key="${t?.Settings?.PrivateKey}", mtu=1280, dns=1.1.1.1, dnsv6=2606:4700:4700::1111, keepalive=45, peers=[{public-key="bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=", allowed-ips="0.0.0.0/0, ::/0", endpoint=engage.nanocat.cloud:2408, reserved=[${e?.config?.reserved}]}]`}`;break;case"Shadowrocket":s+=`Shadowrocket用配置:\n${`[Proxy]\nWARP = wireguard, section-name=Cloudflare, test-url=http://cp.cloudflare.com/generate_204\n\n[WireGuard Cloudflare]\nprivate-key = ${t?.Settings?.PrivateKey}\nself-ip = ${e?.config?.interface?.addresses?.v4}\nself-ip-v6 = ${e?.config?.interface?.addresses?.v6}\ndns-server = 1.1.1.1, 2606:4700:4700::1111\nmtu = 1280\npeer = (public-key = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=, allowed-ips = "0.0.0.0/0, ::/0", endpoint = engage.nanocat.cloud:2408, keepalive = 45, client-id = ${e?.config?.reserved?.[0]}/${e?.config?.reserved?.[1]}/${e?.config?.reserved?.[2]})`}\n\n\nShadowrocket点击一键添加:\nshadowrocket://add/${`wg://engage.nanocat.cloud:2408?publicKey=bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=&privateKey=${t?.Settings?.PrivateKey}&ip=${e?.config?.interface?.addresses?.v4}&dns=1.1.1.1&mtu=1280&keepalive=45&udp=1&reserved=${e?.config?.reserved?.[0]}/${e?.config?.reserved?.[1]}/${e?.config?.reserved?.[2]}#☁️%20Cloudflare%20for%20${e?.account?.account_type}`}`;break;case"Stash":s+=`Stash用配置:\n${`name: Cloudflare\ntype: wireguard\nserver: engage.nanocat.cloud # domain is supported\nport: 2408\nip: ${e?.config?.interface?.addresses?.v4}\nipv6: ${e?.config?.interface?.addresses?.v6} # optional\nprivate-key: ${t?.Settings?.PrivateKey}\npublic-key: bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo= # peer public key\n# preshared-key: # optional\ndns: [1.1.1.1, 2606:4700:4700::1111] # optional\nmtu: 1280 # optional\nreserved: [${e?.config?.reserved}] # optional\nkeepalive: 45 # optional\n# underlying-proxy: # optional\n#   type: trojan\n#   server: your-underlying-proxy\n#   port: 443\n#   password: your-password`}`;break;case"Node.js":break;case"Quantumult X":s+="Quantumult X不支持 Wireguard 协议，仅显示提取后完整配置"}const o=JSON.stringify(e);s+=`\n\n\n完整配置内容:\n${o}`;const r=encodeURIComponent(`☁️ Cloudflare for ${e?.account?.account_type}配置文件`),i=`mailto:engage@nanocat.me?subject=${r}&body=${encodeURIComponent(s)}`;return I.log("✅ Set Message",`message: ${i}`,""),i}(n,e);switch(r){case"Registration":"GET"!==$request.method&&"PUT"!==$request.method||(I.msg(I.name,`检测到${n?.account?.account_type}配置文件`,`点击此通知在“邮件”中打开，查看完整配置。\n设备注册ID:\n${n?.id}\n设备令牌Token:\n${o}\n客户端公钥:\n${n?.key}\n节点公钥:\n${n?.config?.peers?.[0]?.public_key}`,s),I.log(I.name,`检测到${n?.account?.account_type}配置文件`,`原始配置文件:\n注意！文本内容未转义！字符串中可能包含额外字符！\n${JSON.stringify(n)}`,""));break;case"RegistrationId":"PUT"===$request.method&&(I.msg(I.name,"重置密钥",`点击此通知在“邮件”中打开，查看完整配置。\n收到回复数据，当前客户端公钥为:\n${n?.key}\n用户设置公钥为:\n${e?.Settings?.PublicKey}\n如两者一致，则替换成功`,s),I.log(I.name,`检测到${n?.account?.account_type}配置文件`,`原始配置文件:\n注意！文本内容未转义！字符串中可能包含额外字符！\n${JSON.stringify(n)}`,""))}}case!1:Array.isArray(i.errors)&&i.errors.forEach((e=>{I.msg(I.name,`code: ${e.code}`,`message: ${e.message}`)}));break;case void 0:throw new Error($response)}case"application/protobuf":case"application/x-protobuf":case"application/vnd.google.protobuf":case"application/grpc":case"application/grpc+proto":case"application/octet-stream":}case!1:}})().catch((e=>I.logErr(e))).finally((()=>I.done($response)));
