1var synocredential=function(e){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var t=null;function i(){return new Promise(e=>{synowebapi.promises.request({api:"SYNO.Remote.Credential.Challenge",method:"get",version:1}).then(t=>t&&t.challenge?e([void 0,t.challenge]):e([t]))})}class s{constructor(e={}){this.opt=e}makeid(e){for(var t="",i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",s=i.length,o=0;o<e;o++)t+=i.charAt(Math.floor(Math.random()*s));return t}async execute(e){return this.login(Object.assign({challenge_getter:i},e))}async login(e={}){Object.assign(this.opt,e);let i=e=>{this.opt.callback(e,this.opt)},s=this.opt.url,o=this.opt.scope,n=this.opt.audience,r=this.opt.redirect_uri||window.origin,a=this.opt.client_id||"webui",c=this.opt.session||"webui",h=this.opt.forceLogin,l={capture:!1};if(!s||""===s)return i({message:"no request url."}),this.cancel();if(null!=t&&!t.closed)return void t.focus();if(!(t=window.open("about:blank","childWindow","width=600,height=800,toolbar=no,menubar=no")))return i({message:"open child window failed."}),this.cancel();const[u,d]=await this.opt.challenge_getter();if(u||!d||""===d)return i({message:"challenge_getter execute failed."}),this.cancel();var g,f;f=e=>{let t=s.split("/")[0]+"//"+s.split("/")[2].split("?")[0],o=r.split("/")[0]+"//"+r.split("/")[2].split("?")[0];e.origin.toUpperCase()!==o.toUpperCase()&&e.origin.toUpperCase()!==t.toUpperCase()||e.target.origin.toUpperCase()===window.origin.toUpperCase()&&(clearInterval(g),window.removeEventListener("message",f,l),e.data&&e.data.code?e.data.rs?i({code:e.data.code,challenge:d,rs:e.data.rs}):i({code:e.data.code,challenge:d}):i({message:"request code failed."}))},s+="?forceDesktop=1",s+="&client_id="+a,s+="&code_challenge="+d,s+="&code_challenge_method=S256",s+="&response_type=code",s+="&opener="+encodeURIComponent(window.origin),s+="&redirect_uri="+encodeURIComponent(r),s+="&state="+this.makeid(10),o&&(s+="&scope="+encodeURIComponent(o)),n&&(s+="&audience="+encodeURIComponent(n)),c&&(s+="&session="+c),h&&(s+="&force_login="+h),window.addEventListener("message",f,l),t.location=s,g=setInterval(()=>{t&&t.closed&&(clearInterval(g),window.removeEventListener("message",f,l),i({closed:!0}))},500)}logout(e){let t=this.opt.end_session_url+"?post_logout_redirect_uri="+this.opt.logout_redirect_uri+"&id_token_hint="+e;window.open(t,"childWindow","width=600,height=800,toolbar=no,menubar=no")}cancel(){t&&!t.closed&&t.close()}}const{createHash:o,randomBytes:n}=e;function r(e){return function(e,t){let i="";const s=n(e),o=Math.pow(2,8),r=o/Math.min(t.length,o);for(let o=0;o<e;o++){i+=t[Math.floor(s[o]/r)]}return i}(e,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~")}function a(e){const t=o("sha256").update(e).digest("base64");return t.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var c=function(e){if(e||(e=43),e<43||e>128)throw`Expected a length between 43 and 128. Received ${e}.`;const t=r(e);return{code_challenge:a(t),code_verifier:t}};var h=function(e,t){return a(e)===t};c.verifyChallenge=h;const l="function"==typeof atob,u="function"==typeof btoa,d="function"==typeof Buffer,g=("function"==typeof TextDecoder&&new TextDecoder,"function"==typeof TextEncoder?new TextEncoder:void 0),f=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],p=(e=>{let t={};return e.forEach((e,i)=>t[e]=i),t})(f),m=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,_=String.fromCharCode.bind(String),k="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):(e,t=(e=>e))=>new Uint8Array(Array.prototype.slice.call(e,0).map(t)),y=e=>e.replace(/[+\/]/g,e=>"+"==e?"-":"_").replace(/=+$/m,""),w=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),S=e=>{let t,i,s,o,n="";const r=e.length%3;for(let r=0;r<e.length;){if((i=e.charCodeAt(r++))>255||(s=e.charCodeAt(r++))>255||(o=e.charCodeAt(r++))>255)throw new TypeError("invalid character found");t=i<<16|s<<8|o,n+=f[t>>18&63]+f[t>>12&63]+f[t>>6&63]+f[63&t]}return r?n.slice(0,r-3)+"===".substring(r):n},b=u?e=>btoa(e):d?e=>Buffer.from(e,"binary").toString("base64"):S,v=d?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let i=0,s=e.length;i<s;i+=4096)t.push(_.apply(null,e.subarray(i,i+4096)));return b(t.join(""))},O=(e,t=!1)=>t?y(v(e)):v(e),A=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?_(192|t>>>6)+_(128|63&t):_(224|t>>>12&15)+_(128|t>>>6&63)+_(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return _(240|t>>>18&7)+_(128|t>>>12&63)+_(128|t>>>6&63)+_(128|63&t)},C=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,N=e=>e.replace(C,A),R=d?e=>Buffer.from(e,"utf8").toString("base64"):g?e=>v(g.encode(e)):e=>b(N(e)),P=(e,t=!1)=>t?y(R(e)):R(e),I=e=>
1{if(e=e.replace(/\s+/g,""),!m.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let t,i,s,o="";for(let n=0;n<e.length;)t=p[e.charAt(n++)]<<18|p[e.charAt(n++)]<<12|(i=p[e.charAt(n++)])<<6|(s=p[e.charAt(n++)]),o+=64===i?_(t>>16&255):64===s?_(t>>16&255,t>>8&255):_(t>>16&255,t>>8&255,255&t);return o},E=l?e=>atob(w(e)):d?e=>Buffer.from(e,"base64").toString("binary"):I,T=d?e=>k(Buffer.from(e,"base64")):e=>k(E(e),e=>e.charCodeAt(0)),D=e=>T(M(e)),M=e=>w(e.replace(/[-_]/g,e=>"-"==e?"+":"/")),U=P,L=O,H=D;class Y{constructor(e){return this.__noise_c=e,this}init(e,t,i,s){var o=Array();if("initiator"===t&&!i)return this.key_pair=o,!1;let n=this.__noise_c;if(s)o.push(s);else{let t;if("Noise_IK_25519_ChaChaPoly_BLAKE2b"===e&&(t=n.CreateKeyPair(n.constants.NOISE_DH_CURVE25519)),!t)return!1;o=t}return t="initiator"===t?n.constants.NOISE_ROLE_INITIATOR:n.constants.NOISE_ROLE_RESPONDER,this._handshake_state=n.HandshakeState(e,t),this._handshake_state.Initialize(null,o[0],i,null),this.key_pair=o,!0}writeMessage(e=""){var t=this._handshake_state;if(t)return t.WriteMessage(e)}readMessage(e){var t=this._handshake_state;if(t)return t.ReadMessage(e,!0),t.GetRemotePublicKey()}split(){var e=this._handshake_state;if(e){var t=e.Split();return t[0].n=0,t[1].n=0,this.__cipher_states=t,t}}encrypt(e,t){var i=this.__cipher_states;if(i)return i[0].EncryptWithAd(e,t)}getNonceNum(){var e=this.__cipher_states;if(e)return e[0].n++}}class x{constructor(e,t={}){return x._instance||(this.__noise_c=e,this.running=!1,this.opt={},this.info=Object.assign({headers:{},hsh:"",account:"",lhstime:Date.now(),authtok:""},t),x._instance=this),x._instance}issue(e={}){var t=e.callback;if("function"!=typeof t)return t({code:1e3,message:"no callback"});var i=e.url;return"string"!=typeof i?t({code:1e3,message:"no url"}):this.running?t({code:1e3,message:"already running."}):(this.running=!0,Object.assign(this.opt,e),this.runner=new s,void this.runner.login({url:i,challenge_getter:e.challenge_getter,forceLogin:"yes",callback:this.onLoginCallback.bind(this)}))}onLoginCallback(e,t){let i=this.opt.callback;this.running=!1,e&&e.challenge&&e.code&&e.rs?i({url:t.url,challenge:e.challenge,code:e.code,rs:e.rs}):e&&e.message?i({code:1002,mssage:e.message}):e&&e.closed?i({code:1001}):i({code:1002,message:"Unknow"})}CreateChallenge(){return this._challenge=c(),this._challenge.code_challenge}GetLoginParams(e,t){var i=Object.assign({api:"SYNO.API.Auth",version:6,method:"login",session:"webui"},e);if(!this.__noise_c)return i;if(this.noise=new Y(this.__noise_c),!this.info.authtok)try{this.info.authtok=JSON.parse(localStorage.getItem("lastHS")).authtok}catch{}let s=""!==this.info.authtok?H(this.info.authtok):void 0,o=H(t);if(!this.noise.init("Noise_IK_25519_ChaChaPoly_BLAKE2b","initiator",o,s))return i;let n=JSON.stringify({time:Math.floor(Date.now()/1e3)});return i.ik_message=L(this.noise.writeMessage(n),!0),i.version=7,e.code&&(i=Object.assign({type:"code",grant_type:"authorzation_code",code_verifier:this._challenge?this._challenge.code_verifier:"",client_id:""},i)),i}SetLoginResult(e){return this.info.cookie&&(e.sid&&(this.info.cookie.id=e.sid),e.device_id&&(this.info.cookie.did=e.device_id)),e.synotoken&&(this.info.headers["X-SYNO-TOKEN"]=e.synotoken,SYNO.SDS.Session.SynoToken=e.synotoken,localStorage.setItem("SynoToken",e.synotoken)),this.noise&&e.account&&e.ik_message&&this.noise.readMessage(H(e.ik_message))&&(this.info.hsh=L(this.noise._handshake_state.GetHandshakeHash(),!0),this.noise.split(),localStorage.setItem("lastHS",JSON.stringify({authtok:this.info.authtok=L(this.noise.key_pair[0],!0),account:this.info.account=e.account,lhstime:this.info.lhstime}))),this.info}GetLogoutParams(e){return Object.assign({api:"SYNO.API.Auth",method:"logout",version:7},e)}SetLogoutResult(){return delete this.noise,this.info.cookie&&delete this.info.cookie.id,delete this.info.headers["X-SYNO-TOKEN"],this.info.account="",this.info.authtok="",this.info}GetSuspendParams(e){return Object.assign({api:"SYNO.API.Auth",method:"suspend",version:7},e)}SetSuspendResult(){return delete this.noise,this.info.cookie&&delete this.info.cookie.id,delete this.info.headers["X-SYNO-TOKEN"],this.info}GetResumeParams(e,t){if(!this.__noise_c||!t)return;if(!this.info.account||!this.info.authtok)return;var i=localStorage.getItem("lastHS");if(i){var s=JSON.parse(i);s.account===this.info.account&&s.authtok!==this.info.authtok&&s.lhstime>this.info.lhstime&&(this.info.authtok=s.authtok,this.info.lhstime=s.lhstime)}let o=H(this.info.authtok),n=H(t);if(this.noise=new Y(this.__noise_c),!this.noise.init("Noise_KK_25519_ChaChaPoly_BLAKE2b","initiator",n,o))return;let r=JSON.stringify({time:Math.floor(Date.now()/1e3)});return Object.assign({api:"SYNO.API.Auth",version:7,method:"resume",session:"webui",account:this.info.account,kk_message:L(this.noise.writeMessage(r),!0)},e)}SetResumeResult(e){return this.info.cookie&&e.sid&&(this.info.cookie.id=e.sid),e.synotoken&&(this.info.headers["X-SYNO-TOKEN"]=e.synotoken,SYNO.SDS.Session.SynoToken=e.synotoken),this.noise&&e.kk_message&&this.noise.readMessage(H(e.kk_message))&&(this.info.hsh=L(this.noise._handshake_state.GetHandshakeHash(),!0),this.noise.split(),this.info.authtok=L(this.noise.key_pair[0],!0)),this.info}
1GetRequestParams(){return{}}GetRequestHeaders(e={}){if(e=Object.assign(e,this.info.headers),this.info.cookie){let t=this.info.cookie;e.Cookie=Object.keys(t).map(e=>e+"="+t[e]).join("; ")}let t=this.GetRequestHash();return t&&(e["X-SYNO-HASH"]=t),e}SetAccount(e){this.info.account=e}GetAccount(){return this.inf.account}SetAuthtok(e){this.info.authtok=e}GetAuthtok(){return this.info.authtok}GetRequestHash(){if(this.noise){var e=this.noise.encrypt(new Uint8Array,new Uint8Array),t=this.noise.getNonceNum(),i=this.info.hsh.slice(0,8);return e&&void 0!==t&&i?i+L(e,!0)+"."+U(""+t,!0):""}return""}WaitForReady(){return new Promise(e=>{this.resumePromise?this.resumePromise.then(e).catch(e):e()})}GetRemoteKey(){let e=document.cookie.match(/_SSID=[^;]+/);if(e)return e[0].split("=")[1]}Resume(){return this.resumePromise?this.resumePromise:(this.resumePromise=new Promise((e,t)=>{let i=this.GetRemoteKey();if(!i)return void t({code:119,message:"make resume parameters failed."});let s=this.GetResumeParams({enable_syno_token:"yes"},i);if(!i||!s)return void t({code:119,message:"make resume parameters failed."});let o=this;synowebapi.create().request({url:"webapi/entry.cgi?api=SYNO.API.Auth",requestFormat:"raw",responseFormat:"raw",method:"POST",params:s,callback:function(i,s){i&&s.data&&s.data.kk_message?(o.SetResumeResult(s.data),e()):t({code:119,message:"resume noise failed."})}})}),this.resumePromise.finally(()=>this.resumePromise=void 0))}}class G{async check(e){let t=e.forceLegacyMode||!1,i=e.url,s=e.appWin;return!0===t||!await this.isRemoteSupport(i)||!await this.isRemoteVisible(i,s)}issue(e){let t=e.appWin,i=e.callback,s=!1;SYNO.SDS.JSLoad("SYNO.SDS.Utils.AccountPasswordDialog",()=>{let e=SYNO.SDS.Utils.AccountPasswordDialog.openDialog(t,(e,t)=>{if(t&&e&&(""===e.account||""===e.passwd))return void t(!1,{text:_T("login","error_cantlogin"),clear:!0});let o;t||e||(s=!0),t&&(o=(e,i)=>{e&&(s=!0),t(e,i)}),i(e,o)});e.mon(e,"beforeclose",()=>{s||i()})},this)}isRemoteSupport(e){return new Promise((t,i)=>{synowebapi.request({api:"SYNO.Remote.Credential.Info",method:"get",version:1,params:{url:e},callback:(e,s)=>{e&&s?t(s.support_code_login):i(1002)}})})}isRemoteVisible(e,t){return new Promise((function(i,s){var o=new XMLHttpRequest;o.open("GET",e+"/webman/pingpong.cgi?action=cors"),o.onload=()=>{200==o.status?i(!0):i(!1,1002)},o.timeout=2e3,o.onerror=()=>{if(e.startsWith("https")){var s=String.format(_T("login","remote_network_error"),e);t&&t._isVue?(async()=>{i("confirm"===await t.getMsgBox().confirm(null,s))})():t?t.getMsgBox().confirm("",s,e=>{i("yes"===e)},this):i(!0)}else i(!1)},o.ontimeout=o.onerror,o.send()}))}}return x.PKCEClient=s,x.Issue=async function(e){let t=new G,s=e.callback,o=e.url,n={};if(o)try{n=new URL(o)}catch{return void s({code:1002,mssage:"url is invalid."})}else if(!e.mustHaveCredential)return void s({code:1002,mssage:"url is empty"});this.options=Object.assign({},e,{callback:((i,o)=>{if(i&&(i.challenge&&i.code&&i.rs||i.account&&i.passwd)){let r={protocol:"http:"===n.protocol?"http":"https",host:n.hostname||"",port:n.port||("http:"===n.protocol?"80":"443"),application:e.session};i.code?(r.code=i.code,r.rs=i.rs,r.challenge=i.challenge):(r.account=i.account,r.passwd=i.passwd,r.otp=i.otp),synowebapi.request({api:"SYNO.Remote.Credential",method:"set",version:1,params:r,callback:(e,i)=>{if(e&&i&&i.credential)o&&o(!0),s(i.credential);else if(1004===i.code&&o)i.errors&&403===i.errors.code?o(!1,{status:"need_otp"}):i.errors&&404===i.errors.code?o(!1,{text:_T("login","error_otp_failed"),clear:!0}):o(!1,{text:_T("login","error_cantlogin"),clear:!0});else if(1004===i.code){r.code&&i&&i.errors&&i.errors.code&&400===i.errors.code&&this.options.appWin||s({code:1004,auth_error:i.errors});let e=this,o=this.options.appWin;new Promise((e,t)=>{let i=_T("login","is_weblogin_failback_password");o._isVue?(async()=>{"confirm"===await o.getMsgBox().confirm(null,i)?e():t()})():o.getMsgBox().confirm("",i,i=>{"yes"===i?e():t()})}).then(()=>{e.running=!0,t.issue(e.options)},()=>{s({code:1004,auth_error:i.errors})})}else o?o(!1,{text:_T("login","error_cantlogin"),clear:!0}):s({code:1003,success:e,data:i})}})}else i&&i.message?(o&&o(!0),s({code:1002,mssage:i.message})):(o&&o(!0),s({code:1001}))}).bind(this)});let r=!0;try{r=await t.check(this.options)}catch(t){if(o="",n={},1002===t&&!e.mustHaveCredential)return void s({code:1002,mssage:"server connect failed."})}if(r)this.running=!0,t.issue(this.options);else{let e=new x;this.options.challenge_getter=i,e.issue(this.options)}},x}(crypto);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.