芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/cansahcab.gob.mx/media/plg_system_webauthn/js/management.min.js
window.Joomla=window.Joomla||{},((e,t)=>{const n=(e,t="")=>{let a="";return Object.keys(e).forEach((r=>{if("object"!=typeof e[r])return a.length>0&&(a+="&"),void(a+=""===t?`${encodeURIComponent(r)}=${encodeURIComponent(e[r])}`:`${encodeURIComponent(t)}[${encodeURIComponent(r)}]=${encodeURIComponent(e[r])}`);a+=`${n(e[r],r)}`})),a},a=t=>{e.renderMessages({error:[t]})};e.plgSystemWebauthnCreateCredentials=(r,l)=>{if(!("credentials"in navigator))return void e.renderMessages({error:[e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_NO_BROWSER_SUPPORT")]});const o=t.getElementById(r);if(!o)return;const s=JSON.parse(atob(o.dataset.public_key)),i=atob(o.dataset.postback_url),d=e=>btoa(String.fromCharCode(...e)),c=e=>{let t=e.replace(/-/g,"+").replace(/_/g,"/");const n=t.length%4;if(n){if(1===n)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");t+=new Array(5-n).join("=")}return t};s.challenge=Uint8Array.from(window.atob(c(s.challenge)),(e=>e.charCodeAt(0))),s.user.id=Uint8Array.from(window.atob(s.user.id),(e=>e.charCodeAt(0))),s.excludeCredentials&&(s.excludeCredentials=s.excludeCredentials.map((e=>(e.id=Uint8Array.from(window.atob(c(e.id)),(e=>e.charCodeAt(0))),e)))),navigator.credentials.create({publicKey:s}).then((r=>{const o={id:r.id,type:r.type,rawId:d(new Uint8Array(r.rawId)),response:{clientDataJSON:d(new Uint8Array(r.response.clientDataJSON)),attestationObject:d(new Uint8Array(r.response.attestationObject))}},s={option:"com_ajax",group:"system",plugin:"webauthn",format:"raw",akaction:"create",encoding:"raw",data:btoa(JSON.stringify(o))};e.request({url:i,method:"POST",data:n(s),onSuccess(n){const a=t.querySelectorAll(l);if(!a)return;a[0].outerHTML=n,e.plgSystemWebauthnInitialize()},onError:e=>{a(`${e.status} ${e.statusText}`)}})})).catch((e=>{a(e)}))},e.plgSystemWebauthnEditLabel=(r,l)=>{const o=t.getElementById(l);if(!o)return!1;const s=atob(o.dataset.postback_url),i=r.parentElement.parentElement,d=i.dataset.credential_id,c=i.querySelectorAll("td"),u=c[0],m=c[1].querySelectorAll("button"),b=m[0],p=m[1],_=u.innerText,E=t.createElement("input");E.type="text",E.name="label",E.defaultValue=_;const g=t.createElement("button");g.className="btn btn-success btn-sm",g.innerText=e.Text._("PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_SAVE_LABEL"),g.addEventListener("click",(()=>{const t=E.value;if(""!==t){const r={option:"com_ajax",group:"system",plugin:"webauthn",format:"json",encoding:"json",akaction:"savelabel",credential_id:d,new_label:t};e.request({url:s,method:"POST",data:n(r),onSuccess(t){let n=!1;try{n=JSON.parse(t)}catch(e){n="true"===t}!0!==n&&a(e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_LABEL_NOT_SAVED"))},onError:t=>{a(`${e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_LABEL_NOT_SAVED")} -- ${t.status} ${t.statusText}`)}})}return u.innerText=t,b.disabled=!1,p.disabled=!1,!1}),!1);const S=t.createElement("button");return S.className="btn btn-danger btn-sm",S.innerText=e.Text._("PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_CANCEL_LABEL"),S.addEventListener("click",(()=>(u.innerText=_,b.disabled=!1,p.disabled=!1,!1)),!1),u.innerHTML="",u.appendChild(E),u.appendChild(g),u.appendChild(S),b.disabled=!0,p.disabled=!0,!1},e.plgSystemWebauthnDelete=(r,l)=>{const o=t.getElementById(l);if(!o)return!1;const s=atob(o.dataset.postback_url),i=r.parentElement.parentElement,d=i.dataset.credential_id,c=i.querySelectorAll("td")[1].querySelectorAll("button"),u=c[0],m=c[1];u.disabled=!0,m.disabled=!0;const b={option:"com_ajax",group:"system",plugin:"webauthn",format:"json",encoding:"json",akaction:"delete",credential_id:d};return e.request({url:s,method:"POST",data:n(b),onSuccess(t){let n=!1;try{n=JSON.parse(t)}catch(e){n="true"===t}!0===n?i.parentElement.removeChild(i):a(e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_NOT_DELETED"))},onError:t=>{u.disabled=!1,m.disabled=!1,a(`${e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_NOT_DELETED")} -- ${t.status} ${t.statusText}`)}}),!1},e.plgSystemWebauthnAddOnClick=t=>(t.preventDefault(),e.plgSystemWebauthnCreateCredentials(t.currentTarget.getAttribute("data-random-id"),"#plg_system_webauthn-management-interface"),!1),e.plgSystemWebauthnEditOnClick=t=>(t.preventDefault(),e.plgSystemWebauthnEditLabel(t.currentTarget,t.currentTarget.getAttribute("data-random-id")),!1),e.plgSystemWebauthnDeleteOnClick=t=>(t.preventDefault(),e.plgSystemWebauthnDelete(t.currentTarget,t.currentTarget.getAttribute("data-random-id")),!1),e.plgSystemWebauthnInitialize=()=>{const n=t.getElementById("plg_system_webauthn-manage-add");n&&n.addEventListener("click",e.plgSystemWebauthnAddOnClick);const a=[].slice.call(t.querySelectorAll(".plg_system_webauthn-manage-edit"));a.length&&a.forEach((t=>{t.addEventListener("click",e.plgSystemWebauthnEditOnClick)}));const r=[].slice.call(t.querySelectorAll(".plg_system_webauthn-manage-delete"));r.length&&r.forEach((t=>{t.addEventListener("click",e.plgSystemWebauthnDeleteOnClick)}))},e.plgSystemWebauthnInitialize()})(Joomla,document);