"Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/smzdm 9.9.6 rv:93.4 (iPhone13,4; iOS 14.5; zh_CN)/iphone_smzdmapp/9.9.6/wkwebview/jsbv_1.0.0",
"Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148/smzdm 9.9.0 rv:91 (iPhone 11 Pro Max; iOS 14.2; zh_CN)/iphone_smzdmapp/9.9.0/wkwebview/jsbv_1.0.0",
functionMagicData(l,f){letu={fs:undefined,data:{}};if(l.isNode){u.fs=require("fs");try{u.fs.accessSync("./magic.json",u.fs.constants.R_OK|u.fs.constants.W_OK)}catch(e){u.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}u.data=require("./magic.json")}consto=(e,t)=>{if(typeoft==="object"){returnfalse}else{returne===t}};consta=e=>{if(e==="true"){returntrue}elseif(e==="false"){returnfalse}elseif(typeofe==="undefined"){returnnull}else{returne}};constc=(e,t,r,s)=>{if(r){try{if(typeofe==="string")e=JSON.parse(e);if(e["magic_session"]===true){e=e[r]}else{e=null}}catch{e=null}}if(typeofe==="string"&&e!=="null"){try{e=JSON.parse(e)}catch{}}if(s===false&&!!e&&e["magic_session"]===true){e=null}if((e===null||typeofe==="undefined")&&t!==null&&typeoft!=="undefined"){e=t}e=a(e);returne};consti=t=>{if(typeoft==="string"){lete={};try{e=JSON.parse(t);constr=typeofe;if(r!=="object"||einstanceofArray||r==="bool"||e===null){e={}}}catch{}returne}elseif(tinstanceofArray||t===null||typeoft==="undefined"||t!==t||typeoft==="boolean"){return{}}else{returnt}};consty=(e,t=null,r="",s=false,n=null)=>{leti=n||u.data;if(!!i&&typeofi[e]!=="undefined"&&i[e]!==null){val=i[e]}else{val=!!r?{}:null}val=c(val,t,r,s);returnval};constd=(e,t=null,r="",s=false,n=null)=>{leti="";if(n||l.isNode){i=y(e,t,r,s,n)}else{if(l.isSurgeLike){i=$persistentStore.read(e)}elseif(l.isQuanX){i=$prefs.valueForKey(e)}i=c(i,t,r,s)}f.debug(`READ DATA [${e}]${!!r?`[${r}]`:""} <${typeofi}>\n${JSON.stringify(i)}`);returni};constp=(t,r,s="",e=null)=>{letn=e||u.data;n=i(n);if(!!s){lete=i(n[t]);e["magic_session"]=true;e[s]=r;n[t]=e}else{n[t]=r}if(e!==null){e=n}returnn};constg=(e,t,r="",s=null)=>{if(typeoft==="undefined"||t!==t){returnfalse}if(!l.isNode&&(typeoft==="boolean"||typeoft==="number")){t=String(t)}letn="";if(s||l.isNode){n=p(e,t,r,s)}else{if(!r){n=t}else{if(l.isSurgeLike){n=!!$persistentStore.read(e)?$persistentStore.read(e):n}elseif(l.isQuanX){n=!!$prefs.valueForKey(e)?$prefs.valueForKey(e):n}n=i(n);n["magic_session"]=true;n[r]=t}}if(!!n&&typeofn==="object"){n=JSON.stringify(n,"","\t")}f.debug(`WRITE DATA [${e}]${r?`[${r}]`:""} <${typeoft}>\n${JSON.stringify(t)}`);if(!s){if(l.isSurgeLike){return$persistentStore.write(n,e)}elseif(l.isQuanX){return$prefs.setValueForKey(n,e)}elseif(l.isNode){try{u.fs.writeFileSync("./magic.json",n);returntrue}catch(e){f.error(e);returnfalse}}}returntrue};conste=(t,r,s,n=o,i=null)=>{r=a(r);conste=d(t,null,s,false,i);if(n(e,r)===true){returnfalse}else{constl=g(t,r,s,i);lete=d(t,null,s,false,i);if(n===o&&typeofe==="object"){returnl}returnn(r,e)}};constS=(e,t,r)=>{lets=r||u.data;s=i(s);if(!!t){obj=i(s[e]);deleteobj[t];s[e]=obj}else{deletes[e]}if(!!r){r=s}returns};constt=(e,t="",r=null)=>{lets={};if(r||l.isNode){s=S(e,t,r);if(!r){u.fs.writeFileSync("./magic.json",JSON.stringify(s))}else{r=s}}else{if(!t){if(l.isStorm){return$persistentStore.remove(e)}elseif(l.isSurgeLike){return$persistentStore.write(null,e)}elseif(l.isQuanX){return$prefs.removeValueForKey(e)}}else{if(l.isSurgeLike){s=$persistentStore.read(e)}elseif(l.isQuanX){s=$prefs.valueForKey(e)}s=i(s);deletes[t];constn=JSON.stringify(s);g(e,n)}}f.debug(`DELETE KEY [${e}]${!!t?`[${t}]`:""}`)};constr=(e,t=null)=>{letr=[];lets=d(e,null,null,true,t);s=i(s);if(s["magic_session"]!==true){r=[]}else{r=Object.keys(s).filter(e=>e!=="magic_session")}f.debug(`READ ALL SESSIONS [${e}] <${typeofr}>\n${JSON.stringify(r)}`);returnr};return{read:d,write:g,del:t,update:e,allSessions:r,defaultValueComparator:o,convertToObject:i}}
// prettier-ignore
functionMagicHttp(l,u){constt="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1";constr="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59";letf;if(l.isNode){consta=require("axios");f=a.create()}classe{constructor(e=true){this.handlers=[];this.isRequest=e}use(e,t,r){this.handlers.push({fulfilled:e,rejected:t,synchronous:r?r.synchronous:false,runWhen:r?r.runWhen:null});returnthis.handlers.length-1}eject(e){if(this.handlers[e]){this.handlers[e]=null}}forEach(t){this.handlers.forEach(e=>{if(e!==null){t(e)}})}}functionn(e){letr={...e};if(!!r.params){if(!l.isNode){lete=Object.keys(r.params).map(e=>{constt=encodeURIComponent(e);r.url=r.url.replace(newRegExp(`${e}=[^&]*`,"ig"),"");r.url=r.url.replace(newRegExp(`${t}=[^&]*`,"ig"),"");return`${t}=${encodeURIComponent(r.params[e])}`}).join("&");if(r.url.indexOf("?")<0)r.url+="?";if(!/(&|\?)$/g.test(r.url)){r.url+="&"}r.url+=e;deleter.params;u.debug(`Params to QueryString: ${r.url}`)}}returnr}constd=(e,t)=>{letr=typeoft==="object"?{headers:{},...t}:{url:t,headers:{}};if(!r.method){r["method"]=e}r=n(r);if(r["rewrite"]===true){if(l.isSurge){r.headers["X-Surge-Skip-Scripting"]=false;deleter["rewrite"]}elseif(l.isQuanX){r["hints"]=false;deleter["rewrite"]}}if(l.isSurge){if(r["method"]!=="GET"&&typeofr.headers["Content-Type"]==="string"&&r.headers["Content-Type"].indexOf("application/json")>=0&&r.bodyinstanceofArray){r.body=JSON.stringify(r.body);u.debug(`Convert Array object to String: ${r.body}`)}}elseif(l.isQuanX){if(r.hasOwnProperty("body")&&typeofr["body"]!=="string")r["body"]=JSON.stringify(r["body"]);r["method"]=e}elseif(l.isNode){if(e==="POST"||e==="PUT"||e==="PATCH"||e==="DELETE"){r.data=r.data||r.body}elseif(e==="GET"){r.params=r.params||r.body}deleter.body}returnr};consth=(t,r=null)=>{if(t){lete={...t,config:t.config||r,status:t.statusCode||t.status,body:t.body||t.data||"",headers:t.headers||t.header};if(typeofe.body==="string"){try{e.body=JSON.parse(e.body)}catch{}}deletet.data;returne}else{lete={config:r,status:null,body:"",headers:{}};returne}};consto=n=>{if(!!n){deleten["Content-Length"];lete=newSet(["Accept","Accept-CH","Accept-Charset","Accept-Features","Accept-Encoding","Accept-Language","Accept-Ranges","Access-Control-Allow-Credentials","Access-Control-Allow-Origin","Access-Control-Allow-Methods","Access-Control-Allow-Headers","Access-Control-Max-Age","Access-Control-Expose-Headers","Access-Control-Request-Method","Access-Control-Request-Headers","Age","Allow","Alternates","Authorization","Cache-Control","Connection","Content-Encoding","Content-Language","ontent-Length","Content-Location","Content-Range","Content-Security-Policy","Content-Type","Cookie","DNT","Date","ETag","Expect","Expires","From","Host","If-Match","If-Modified-Since","If-None-Match","If-Range","If-Unmodified-Since","Last-Event-ID","Last-Modified","Link","Location","Max-Forwards","Negotiate","Origin","Pragma","Proxy-Authenticate","Proxy-Authorization","Range","Referer","Retry-After","Sec-Websocket-Extensions","Sec-Websocket-Key","Sec-Websocket-Origin","Sec-Websocket-Protocol","Sec-Websocket-Version","Server","Set-Cookie","Set-Cookie2","Strict-Transport-Security","TCN","TE","Trailer","Transfer-Encoding","Upgrade","User-Agent","Variant-Vary","Vary","Via","Warning","WWW-Authenticate","X-Content-Duration","X-Content-Security-Policy","X-DNSPrefetch-Control","X-Frame-Options","X-Requested-With"]);for(letrofObject.keys(n)){if(!e.has(r)){for(lettofe){lete=r.replace(newRegExp(t,"ig"),t);if(r!==e){n[e]=n[r];deleten[r];break}}}}if(!n["User-Agent"]){if(l.isNode){n["User-Agent"]=r}else{n["User-Agent"]=t}}returnn}returnn};constp=(t,r=null)=>{if(!!t&&t.status>=400){u.debug(`Raise exception when status code is ${t.status}`);lete={name:"RequestException",message:`Request failed with status code ${t.status}`,config:r||t.config,response:t};returne}};consts={request:newe,response:newe(false)}
// prettier-ignore
functionMagicNotification(r,f,l){lets=null;letu=null;constc=typeofMagicHttp==="function"?MagicHttp(f,l):undefined;conste=t=>{try{lete=t.replace(/\/+$/g,"");s=`${/^https?:\/\/([^/]*)/.exec(e)[0]}/push`;u=/\/([^\/]+)\/?$/.exec(e)[1]}catch(e){l.error(`Bark url error: ${e}.`)}};functiont(e=r,t="",i="",o=""){constn=i=>{try{lett={};if(typeofi==="string"){if(f.isLoon)t={openUrl:i};elseif(f.isQuanX)t={"open-url":i};elseif(f.isSurge)t={url:i}}elseif(typeofi==="object"){if(f.isLoon){t["openUrl"]=!!i["open-url"]?i["open-url"]:"";t["mediaUrl"]=!!i["media-url"]?i["media-url"]:""}elseif(f.isQuanX){t=!!i["open-url"]||!!i["media-url"]?i:{}}elseif(f.isSurge){lete=i["open-url"]||i["openUrl"];t=e?{url:e}:{}}}returnt}catch(e){l.error(`Failed to convert notification option, ${e}`)}returni};o=n(o);if(arguments.length==1){e=r;t="",i=arguments[0]}l.notify(`title:${e}\nsubTitle:${t}\nbody:${i}\noptions:${typeofo==="object"?JSON.stringify(o):o}`);if(f.isSurge){$notification.post(e,t,i,o)}elseif(f.isLoon){if(!!o)$notification.post(e,t,i,o);else$notification.post(e,t,i)}elseif(f.isQuanX){$notify(e,t,i,o)}if(s&&u&&typeofc!=="undefined"){p(e,t,i)}}functioni(e=r,t="",i="",o=""){if(l.level==="DEBUG"){if(arguments.length==1){e=r;t="",i=arguments[0]}this.notify(e,t,i,o)}}functionp(e=r,t="",i="",o=""){if(typeofc==="undefined"||typeofc.post==="undefined"){throw"Bark notification needs to import MagicHttp module."}letn={url:s,headers:{"Content-Type":"application/json; charset=utf-8"},body:{title:e,body:t?`${t}\n${i}`:i,device_key:u}};c.post(n).catch(e=>{l.error(`Bark notify error: ${e}`)})}return{post:t,debug:i,bark:p,setBark:e}}
// prettier-ignore
functionMagicUtils(r,h){conste=(o,i=5,l=0,a=null)=>{return(...e)=>{returnnewPromise((s,r)=>{functionn(...t){Promise.resolve().then(()=>o.apply(this,t)).then(e=>{if(typeofa==="function"){Promise.resolve().then(()=>a(e)).then(()=>{s(e)}).catch(e=>{if(i>=1){if(l>0)setTimeout(()=>n.apply(this,t),l);elsen.apply(this,t)}else{r(e)}i--})}else{s(e)}}).catch(e=>{h.error(e);if(i>=1&&l>0){setTimeout(()=>n.apply(this,t),l)}elseif(i>=1){n.apply(this,t)}else{r(e)}i--})}n.apply(this,e)})}};constt=(e,t="yyyy-MM-dd hh:mm:ss")=>{lets={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};if(/(y+)/.test(t))t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length));for(leteins)if(newRegExp("("+e+")").test(t))t=t.replace(RegExp.$1,RegExp.$1.length==1?s[e]:("00"+s[e]).substr((""+s[e]).length));returnt};consts=()=>{returnt(newDate,"yyyy-MM-dd hh:mm:ss")};constn=()=>{returnt(newDate,"yyyy-MM-dd")};consto=t=>{returnnewPromise(e=>setTimeout(e,t))};consti=(e,t=null)=>{if(r.isNode){consts=require("assert");if(t)s(e,t);elses(e)}else{if(e!==true){lete=`AssertionError: ${t||"The expression evaluated to a falsy value"}`;h.error(e)}}};return{retry:e,formatTime:t,now:s,today:n,sleep:o,assert:i}}
// prettier-ignore
functionMagicQingLong(e,s,r){leti="";leto="";letl="";letc="";letd="";letn="";constu="magic.json";constt=3e3;constp=MagicHttp(e,r);consta=(e,n,t,a,r)=>{i=e;l=n;c=t;o=a;d=r};functiong(e){i=i||s.read("magic_qlurl");n=n||s.read("magic_qltoken");returne}functionf(e){if(!i){i=s.read("magic_qlurl")}if(e.url.indexOf(i)<0){e.url=`${i}${e.url}`}return{...e,timeout:t}}functiony(e){e.params={...e.params,t:Date.now()};returne}functionh(e){n=n||s.read("magic_qltoken");if(n){e.headers["Authorization"]=`Bearer ${n}`}returne}functionm(e){l=l||s.read("magic_qlclient");if(!!l){e.url=e.url.replace("/api/","/open/")}returne}asyncfunctionb(e){try{constn=e.message||e.error||JSON.stringify(e);if((n.indexOf("NSURLErrorDomain")>=0&&n.indexOf("-1012")>=0||!!e.response&&e.response.status===401)&&!!e.config&&e.config.refreshToken!==true){r.warning(`Qinglong panel token has expired`);awaitv();e.config["refreshToken"]=true;returnawaitp.request(e.config.method,e.config)}else{returnPromise.reject(e)}}catch(e){returnPromise.reject(e)}}p.interceptors.request.use(g,undefined);p.interceptors.request.use(f,undefined);p.interceptors.request.use(m,undefined,{runWhen:e=>{returne.url.indexOf("api/user/login")<0&&e.url.indexOf("open/auth/token")<0}});p.interceptors.request.use(h,undefined,{runWhen:e=>{returne.url.indexOf("api/user/login")<0&&e.url.indexOf("open/auth/token")<0}});p.interceptors.request.use(y,undefined,{runWhen:e=>{returne.url.indexOf("open/auth/token")<0&&e.url.indexOf("t=")<0}});p.interceptors.response.use(undefined,b);asyncfunctionv(){l=l||s.read("magic_qlclient");c=c||s.read("magic_qlsecrt");o=o||s.read("magic_qlname");d=d||s.read("magic_qlpwd");if(i&&l&&c){awaitp.get({url:`/open/auth/token`,headers:{"Content-Type":"application/json"},params:{client_id:l,client_secret:c}}).then(e=>{r.info("Log in to Qinglong panel successfully");n=e.body.data.token;s.update("magic_qltoken",n);returnn}).catch(e=>{r.error(`Failed to log in to Qinglong panel.\n${e.message}`)})}elseif(i&&o&&d){awaitp.post({url:`/api/user/login`,headers:{"Content-Type":"application/json"},body:{username:o,password:d}}).then(e=>{r.info("Log in to Qinglong panel successfully");n=e.body.data.token;s.update("magic_qltoken",n);returnn}).catch(e=>{r.error(`Failed to log in to Qinglong panel.\n${e.message}`)})}}asyncfunctionN(n,t,a=null){i=i||s.read("magic_qlurl");if(a===null){lete=await$([{name:n,value:t}]);if(!!e&&e.length===1){returne[0]}}else{p.put({url:`/api/envs`,headers:{"Content-Type":"application/json"},body:{name:n,value:t,id:a}}).then(e=>{if(e.body.code===200){r.debug(`QINGLONG UPDATE ENV ${n} <${typeoft}> (${a})\n${JSON.stringify(t)}`);returntrue}else{r.error(`Failed to update Qinglong panel environment variable.\n${JSON.stringify(e)}`)}}).catch(e=>{r.error(`Failed to update Qinglong panel environment variable.\n${e.message}`);returnfalse})}}asyncfunction$(e){letn=[];awaitp.post({url:`/api/envs`,headers:{"Content-Type":"application/json"},body:e}).then(e=>{if(e.body.code===200){e.body.data.forEach(e=>{r.debug(`QINGLONG ADD ENV ${e.name} <${typeofe.value}> (${e.id})\n${JSON.stringify(e)}`);n.push(e.id)})}else{r.error(`Failed to add Qinglong panel environment variable.\n${JSON.stringify(e)}`)}}).catch(e=>{r.error(`Failed to add Qinglong panel environment variable.\n${e.message}`)});returnn}asyncfunctionO(n){returnawaitp.delete({url:`/api/envs`,headers:{Accept:"application/json","Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",Connection:"keep-alive","Content-Type":"application/json;charset=UTF-8","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30"},body:n}).then(e=>{if(e.body.code===200){r.debug(`QINGLONG DELETE ENV IDS: ${n}`);returntrue}else{r.error(`Failed to delete QingLong envs.\n${JSON.stringify(e)}`);returnfalse}}).catch(e=>{r.error(`Failed to delete QingLong envs.\n${e.message}`)})}asyncfunctionS(t=null,e=""){leta=[];awaitp.get({url:`/api/envs`,headers:{"Content-Type":"application/json"},params:{