var DEBUG=!1;
(function(){var b=function(b){DEBUG&&top.console.log(b)},f=top.gSTB,m=function(){var b=0,c;for(c in f)f.hasOwnProperty&&b++;return b}(),n=f.GetDeviceModelExt(),r=f.GetDeviceMacAddress(),y=f.GetDeviceSerialNumber(),w={method:"GET",async:!0,headers:{},data:null,body:null,timeout:3E4,type:"text",onload:function(){},onerror:function(){},ontimeout:null,onabort:null},u=Object.keys(w),q=[],g=!1,c={host:null,authHost:null,lang:"en",session:{accessToken:null,refreshToken:null,userId:null,macAlgorithm:null,
                macKey:null},request:function(k,d){var e=fetch(),p=f.GetLanLinkStatus(),l=f.GetWifiLinkStatus(),h="Model: "+n+"; Link: ",a;if(g)DEBUG&&(b("request locked"),b("push "+k)),q.push({url:k,options:d});else{g=!0;d=d||{};if(k&&("string"===typeof k||k instanceof String)&&0<k.length){if(d&&"object"===typeof d)for(a=0;a<u.length;a++)void 0===d[u[a]]&&(d[u[a]]=w[u[a]]);e=fetch();DEBUG&&b(JSON.stringify([d.method,c.host+"/"+k,d.async]));e.open(d.method,c.host+"/"+k,d.async);e.setRequestHeader("Authorization",
            "Bearer "+c.session.accessToken);e.setRequestHeader("Content-Type","application/json");e.setRequestHeader("Accept-Language",c.lang);e.setRequestHeader("X-User-Agent",h+(p&&l?"Ethernet,WiFi":l?"WiFi":p?"Ethernet":""));if(d.headers&&"object"===typeof d.headers)for(p=Object.keys(d.headers),a=0;a<p.length;a++)e.setRequestHeader(p[a],d.headers[p[a]]);e.responseType=d.type;e.timeout=d.timeout;e.onload=function(){var a=!1;try{a=JSON.parse(this.responseText)}catch(t){a=!1}DEBUG&&(b("ONLOAD!!!!!!!!!!!!!!!!!!!!!!"),
            b(JSON.stringify([this.status,this.responseText])));if(200===this.status){try{d.onload(!a,a)}catch(t){DEBUG&&b("Exception thrown "+t.message,t);if(c.onfail)c.onfail("Exception thrown "+t.message,t);if(d.onerror)try{d.onerror.call(e,t)}catch(v){DEBUG&&b("Exception thrown "+v.message,v)}}g=!1;0<q.length&&(a=q.shift(),c.request(a.url,a.options))}else if(401===this.status)c.session.refreshToken?c.auth.refreshToken(c.session.refreshToken,function(a){a?(DEBUG&&b(a),c.auth.login({password:"",login:""},function(a,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         e){DEBUG&&(b(a),b(JSON.stringify(a)),b(JSON.stringify(e)));if(a)if("invalid_grant"===a.error)c.oncredenitalsrequired(function(){g=!1;c.request(k,d)});else if("access_denied"===a.error&&"Account disabled"===a.error_description)c.oncredenitalsrequired(function(){},{error:a});else g=!1,c.request(k,d);else g=!1,c.request(k,d)})):(g=!1,c.request(k,d))}):c.auth.login({password:"",login:""},function(a,e){DEBUG&&(b(JSON.stringify(a)),b(JSON.stringify(e)));if(a)if("invalid_grant"===a.error)c.oncredenitalsrequired(function(){g=
            !1;c.request(k,d)});else"access_denied"===a.error&&"Account disabled"===a.error_description?(c.reload(),c.oncredenitalsrequired(function(){},{error:a})):(g=!1,c.request(k,d));else g=!1,c.request(k,d)});else if(a&&"access_denied"===a.error&&"Account disabled"===a.error_description)c.oncredenitalsrequired(function(){},{error:error}),g=!0;else{g=!1;try{d.onload(this.status,this.responseText)}catch(t){if(d.onerror)try{d.onerror.call(e,t)}catch(v){}}0<q.length&&(a=q.shift(),c.request(a.url,a.options))}};
                e.onerror=function(){DEBUG&&b("request error");if(d.onerror)try{d.onerror.call(e)}catch(x){}if(c.onfail)c.onfail("Network error "+e.status);g=!1;0<q.length&&(data=q.shift(),c.request(data.url,data.options))};e.ontimeout=function(){DEBUG&&b("request timeout");if(d.ontimeout)try{d.ontimeout.call(e)}catch(x){}g=!1;0<q.length&&(data=q.shift(),c.request(data.url,data.options))};e.onabort=function(){DEBUG&&b("client REQUEST ABORTED");if(d.onabort)try{d.onabort.call(e)}catch(t){}g=!1;if(0<q.length){var a=
                    q.shift();c.request(a.url,a.options)}};DEBUG&&b("SENDED");e.send(d.body);return e}return!1}},auth:{login:function(k,d){var e=Math.random().toString(36).substring(2),p=fetch(),l=Math.random().toString(36).substring(2),h=Math.round(Date.now()/1E3),a=f.GetHashVersion1(l,h);l=a+"."+l+"."+h;h=[];var g=f.GetUID();DEBUG&&b("hash "+a);if("false"===a)setTimeout(function(){c.auth.login(k,d)},5E3);else{switch(window.core.device.model){case "AuraHD4":case "MAG322":case "MAG324":if(g=f.GetUID("device_id","1729452065727304",
                    3),a=f.GetUID("device_id",e,5),e=e+"."+a,0<g.length&&0<a.length)break;default:g=f.GetUID(),e=(a=f.GetUID("device_id",e))?e+"."+a:""}p.open("POST",c.authHost,!0);p.setRequestHeader("Content-Type","application/x-www-form-urlencoded");p.timeout=1E4;p.onload=function(){DEBUG&&(b("login responseText "+this.responseText),b("login status "+this.status));if(200===this.status){try{var a=JSON.parse(this.responseText)}catch(v){a={}}a.access_token&&a.user_id?(c.session.accessToken=a.access_token,c.session.refreshToken=
                    a.refresh_token,c.session.userId=a.user_id,a.mac_algorithm&&(c.session.macAlgorithm=a.mac_algorithm),a.mac_key&&(c.session.macKey=a.api.mac_key,c.session.macAlgorithm=a.api.mac_algorithm),a.api&&a.api.v3&&(c.session.macKey=a.api.v3.mac_key,c.session.macAlgorithm=a.api.v3.mac_algorithm),c.saveCallback&&c.saveCallback(),d(!1)):d(a,a)}else d(this.status+" : "+this.responseText,{})};p.ontimeout=function(){d("onerror "+this.status+" : "+this.responseText,!1)};p.onerror=function(){d("onerror "+this.status+
                    " : "+this.responseText,!1)};h.push("grant_type=password");h.push("client_type=STB");h.push("username="+encodeURIComponent(k.login));h.push("password="+encodeURIComponent(k.password));h.push("mac="+encodeURIComponent(r));h.push("serial_number="+encodeURIComponent(y));h.push("stb_type="+encodeURIComponent(n));h.push("model="+encodeURIComponent(n));h.push("device_id="+encodeURIComponent(g));h.push("device_id2="+encodeURIComponent(e));h.push("version="+encodeURIComponent(f.Version()));h.push("hw_version="+
                    encodeURIComponent(l));h.push("api_signature="+encodeURIComponent(m));DEBUG&&b(h.join("&"));p.send(h.join("&"))}},refreshToken:function(k,d){var e=fetch(),g=Math.random().toString(36).substring(2),l=Math.round(Date.now()/1E3),h=f.GetHashVersion1(g,l);g=h+"."+g+"."+l;l=[];DEBUG&&b("hash "+h);"false"===h?setTimeout(function(){c.auth.refreshToken(k,d)},5E3):(e.open("POST",c.authHost,!0),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onload=function(){DEBUG&&b("refresh token status "+
                    this.status);if(200===this.status){try{var a=JSON.parse(this.responseText)}catch(x){a={}}DEBUG&&b("refresh token responseText "+this.responseText);a.access_token&&a.user_id?(c.session.accessToken=a.access_token,c.session.refreshToken=a.refresh_token,c.session.userId=a.user_id,a.mac_algorithm&&(c.session.macAlgorithm=a.mac_algorithm),a.mac_key&&(c.session.macKey=a.api.mac_key,c.session.macAlgorithm=a.api.mac_algorithm),a.api&&a.api.v3&&(c.session.macKey=a.api.v3.mac_key,c.session.macAlgorithm=a.api.v3.mac_algorithm),
                c.saveCallback&&c.saveCallback(),d(!1)):d(a,a)}else d(this.status+" : "+this.responseText,{})},e.onerror=function(){DEBUG&&b("onerror");d(!0,{})},l.push("grant_type=refresh_token"),l.push("refresh_token="+encodeURIComponent(k)),l.push("hw_version="+encodeURIComponent(g)),l.push("model="+encodeURIComponent(n)),l.push("mac="+encodeURIComponent(r)),l.push("client_type=STB"),l.push("api_signature="+encodeURIComponent(m)),DEBUG&&b(l.join("&")),e.send(l.join("&")))}}};return c})();
