2FAuth/public/build/assets/Import-a314083d.js
2023-12-29 17:55:28 +01:00

2 lines
11 KiB
JavaScript
Vendored

import{P as nt,b as lt,a as rt,c as ct,r as k,d as q,I as f,v as V,x as ut,o as dt,J as ft,e as h,f as n,g as r,m as c,p as v,i as a,E as pt,h as e,t as i,U as E,n as T,k as M,l as d,j as p,w as R,F as J,G as L,T as _t,O as mt}from"./app-7741c0f3.js";import{F as B}from"./Form-5d38519d.js";import{_ as ht}from"./OtpDisplay-f057e3eb.js";import{S as vt}from"./Spinner-1b0ef575.js";import{u as gt}from"./bus-7cf82b9d.js";/*! 2FAuth version 5.0.2 - Copyright (c) 2023 Bubka - https://github.com/Bubka/2FAuth */const wt={class:"title has-text-grey-dark"},kt={key:0},yt={class:"block is-size-7-mobile"},bt={class:"mb-2"},$t={class:"columns"},Ct={class:"column"},At={class:"block"},xt={class:"card"},Ft={class:"card-content"},zt={class:"media"},St={class:"media-left"},qt={class:"image is-32x32"},Vt={class:"media-content"},Et=["innerHTML"],Tt={class:"subtitle is-6 is-size-7-mobile"},Bt={class:"card-footer"},Nt={class:"block"},Ot={class:"card"},Pt={class:"card-content"},Ut={class:"media"},It={class:"media-left"},Mt={class:"image is-32x32"},Rt={class:"media-content"},Jt={class:"title is-5 has-text-grey"},Lt={class:"subtitle is-6 is-size-7-mobile"},jt={class:"card-footer"},Dt={class:"title is-5 has-text-grey-dark"},Wt={class:"block is-size-7-mobile"},Gt={class:"table is-size-7-mobile is-fullwidth"},Ht=e("thead",null,[e("tr",null,[e("th"),e("th",null,"Plain text"),e("th",null,"QR code"),e("th",null,"JSON")])],-1),Kt=e("th",null,"Google Authenticator",-1),Qt=e("td",null,null,-1),Xt=e("td",null,null,-1),Yt=e("th",null,"Aegis Auth",-1),Zt=e("td",null,null,-1),te=e("th",null,"2FAS auth",-1),ee=e("td",null,null,-1),se=e("td",null,null,-1),oe=e("th",null,"2FAuth",-1),ie=e("td",null,null,-1),ae=e("td",null,null,-1),ne={key:1},le={key:2},re={class:"block is-size-7-mobile"},ce={class:"mb-2"},ue={class:"is-flex is-justify-content-space-between"},de=["onClick","title"],fe=["src","alt"],pe={key:1,class:"is-flex-grow-1 has-ellipsis"},_e={key:2,class:"tags is-flex-wrap-nowrap"},me=["onClick","title"],he=["onClick","title"],ve={key:3,class:"has-nowrap"},ge={key:0,class:"has-text-success"},we={key:1,class:"has-text-danger"},ke={class:"is-size-6 is-size-7-mobile"},ye={class:"is-family-primary has-text-grey"},be={key:0,class:"has-text-danger"},$e={key:1,class:"has-text-warning"},Ce={key:2},Ae={key:0,class:"mt-2 is-size-7 is-pulled-right"},xe={key:1,class:"mt-2 is-size-7 is-pulled-right"},Fe={key:0,class:"control"},Ne={__name:"Import",setup(ze){const j=nt("2fauth"),_=lt(),D=rt(),x=gt(),W=ct(),y=k(null),F=k(null),z=k(null),b=q(new B({service:"",account:"",otp_type:"",icon:"",secret:"",algorithm:"",digits:null,counter:null,period:null})),$=q(new B({file:null,withSecret:!0})),C=q(new B({qrcode:null,withSecret:!0})),g=k(!1);f("twofaccounts.import.qr_code"),f("twofaccounts.import.plain_text");const l=k([]),m=k(!1),A=V(()=>l.value.filter(t=>t.imported==-1&&t.id>-2).length),N=V(()=>l.value.filter(t=>t.id===-1&&t.imported===-1).length),G=V(()=>l.value.filter(t=>t.imported===1).length);ut(g,t=>{var s;t==!1&&((s=y.value)==null||s.clearOTP())}),dt(()=>{x.migrationUri&&(O(x.migrationUri),x.migrationUri=null)});async function O(t){m.value=!0,await ft.migrate(t,{returnError:!0}).then(s=>{s.data.forEach(u=>{u.imported=-1,l.value.push(u)}),U()}).catch(s=>{_.alert({text:f(s.response.data.message)})}),m.value=!1}function H(){var t;confirm(f("twofaccounts.confirm.discard_duplicates"))&&(_.clear(),(t=y.value)==null||t.clearOTP(),l.value=l.value.filter(s=>s.id!==-1))}function K(){var t;confirm(f("twofaccounts.confirm.discard_all"))&&(_.clear(),(t=y.value)==null||t.clearOTP(),l.value=[])}function Q(t){confirm(f("twofaccounts.confirm.discard"))&&l.value.splice(t,1)}async function X(){for(let t=0;t<l.value.length;t++)l.value[t].imported==-1&&await P(t)}async function P(t){b.fill(l.value[t]),await b.post("/api/v1/twofaccounts",{returnError:!0}).then(s=>{l.value[t].imported=1,l.value[t].id=s.data.id,delete s.data.secret,W.items.push(s.data)}).catch(s=>{l.value[t].imported=0,l.value[t].id=0,l.value[t].errors=b.errors.flatten()})}function Y(t){b.fill(l.value[t]),g.value=!0,mt().then(()=>{y.value.show()})}function Z(){$.clear(),m.value=!0,$.file=F.value.files[0],$.upload("/api/v1/twofaccounts/migration",{returnError:!0}).then(t=>{t.data.forEach(s=>{s.imported=-1,l.value.push(s)}),U()}).catch(t=>{t.response.status===422?t.response.data.errors.file==null&&_.alert({text:f("errors.invalid_2fa_data")}):_.alert({text:t.response.data.message})}),m.value=!1}function tt(){C.clear(),m.value=!0,C.qrcode=z.value.files[0],C.upload("/api/v1/qrcode/decode",{returnError:!0}).then(t=>{O(t.data.data)}).catch(t=>{t.response.status===422?t.response.data.errors.qrcode==null&&_.alert({text:f("errors.invalid_2fa_data")}):_.alert({text:t.response.data.message})}),m.value=!1}function U(){_.success({text:f("twofaccounts.import.x_valid_accounts_found",{count:A.value})})}return(t,s)=>{const u=h("FontAwesomeIcon"),I=h("FieldError"),et=h("RouterLink"),st=h("ButtonBackCloseCancel"),ot=h("VueFooter"),it=h("ResponsiveWidthWrapper"),at=h("modal");return n(),r("div",null,[c(it,null,{default:v(()=>[e("h1",wt,i(t.$t("twofaccounts.import.import")),1),!a(m)&&a(l).length==0?(n(),r("div",kt,[e("div",yt,[e("p",bt,i(t.$t("twofaccounts.import.import_legend")),1),e("p",null,i(t.$t("twofaccounts.import.import_legend_afterpart")),1)]),e("div",$t,[e("div",Ct,[e("div",At,[e("div",xt,[e("div",Ft,[e("div",zt,[e("div",St,[e("figure",qt,[c(a(E),null,{default:v(({mode:o})=>[c(u,{icon:["fas","qrcode"],size:"2x",class:T(o=="dark"?"has-text-grey-darker":"has-text-grey-lighter")},null,8,["class"])]),_:1})])]),e("div",Vt,[e("p",{class:"title is-5 has-text-grey",innerHTML:t.$t("twofaccounts.import.qr_code")},null,8,Et),e("p",Tt,i(t.$t("twofaccounts.import.supported_formats_for_qrcode_upload")),1)])]),a(C).errors.hasAny("qrcode")?(n(),M(I,{key:0,error:a(C).errors.get("qrcode"),field:"qrcode"},null,8,["error"])):d("",!0)]),e("footer",Bt,[c(et,{id:"btnCapture",to:{name:"capture"},class:"card-footer-item"},{default:v(()=>[p(i(t.$t("twofaccounts.import.scan")),1)]),_:1}),e("a",{role:"button",tabindex:"0",class:"card-footer-item is-relative",onKeyup:s[0]||(s[0]=R(o=>a(z).click(),["enter"]))},[e("input",{"aria-hidden":"true",tabindex:"-1",class:"file-input",type:"file",accept:"image/*",onChange:tt,ref_key:"qrcodeInput",ref:z},null,544),p(" "+i(t.$t("twofaccounts.import.upload")),1)],32)])])]),e("div",Nt,[e("div",Ot,[e("div",Pt,[e("div",Ut,[e("div",It,[e("figure",Mt,[c(a(E),null,{default:v(({mode:o})=>[c(u,{icon:["fas","file-lines"],size:"2x",class:T(o=="dark"?"has-text-grey-darker":"has-text-grey-lighter")},null,8,["class"])]),_:1})])]),e("div",Rt,[e("p",Jt,i(t.$t("twofaccounts.import.text_file")),1),e("p",Lt,i(t.$t("twofaccounts.import.supported_formats_for_file_upload")),1)])]),a($).errors.hasAny("file")?(n(),M(I,{key:0,error:a($).errors.get("file"),field:"file"},null,8,["error"])):d("",!0)]),e("footer",jt,[e("a",{role:"button",tabindex:"0",class:"card-footer-item is-relative",onKeyup:s[1]||(s[1]=R(o=>a(F).click(),["enter"]))},[e("input",{"aria-hidden":"true",tabindex:"-1",class:"file-input",type:"file",accept:"text/plain,application/json,text/csv,.2fas",onChange:Z,ref_key:"fileInput",ref:F},null,544),p(" "+i(t.$t("twofaccounts.import.upload")),1)],32)])])])])]),e("h2",Dt,i(t.$t("twofaccounts.import.supported_migration_formats")),1),e("div",Wt,[c(u,{icon:["fas","fa-triangle-exclamation"],class:"has-text-warning-dark"}),p(" "+i(t.$t("twofaccounts.import.do_not_set_password_or_encryption")),1)]),e("table",Gt,[Ht,e("tbody",null,[e("tr",null,[Kt,Qt,e("td",null,[c(u,{icon:["fas","circle-check"]})]),Xt]),e("tr",null,[Yt,e("td",null,[c(u,{icon:["fas","circle-check"]})]),Zt,e("td",null,[c(u,{icon:["fas","circle-check"]})])]),e("tr",null,[te,ee,se,e("td",null,[c(u,{icon:["fas","circle-check"]})])]),e("tr",null,[oe,ie,ae,e("td",null,[c(u,{icon:["fas","circle-check"]})])])])])])):a(m)&&a(l).length===0?(n(),r("div",ne,[c(vt,{type:"fullscreen-overlay",isVisible:!0,message:"twofaccounts.import.parsing_data"},null,8,["message"])])):(n(),r("div",le,[e("div",re,[e("p",ce,i(t.$t("twofaccounts.import.submitted_data_parsed_now_accounts_are_awaiting_import")),1),e("p",null,i(t.$t("twofaccounts.import.use_buttons_to_save_or_discard")),1)]),(n(!0),r(J,null,L(a(l),(o,S)=>(n(),r("div",{key:o.name,class:"group-item is-size-5 is-size-6-mobile"},[e("div",ue,[o.id>-2&&o.imported!==0?(n(),r("div",{key:0,class:"is-flex-grow-1 has-ellipsis is-clickable",onClick:w=>Y(S),title:t.$t("twofaccounts.import.generate_a_test_password")},[o.icon&&a(D).preferences.showAccountsIcons?(n(),r("img",{key:0,class:"import-icon",src:a(j).config.subdirectory+"/storage/icons/"+o.icon,alt:t.$t("twofaccounts.icon_for_account_x_at_service_y",{account:o.account,service:o.service})},null,8,fe)):d("",!0),p(" "+i(o.account),1)],8,de)):(n(),r("div",pe,i(o.account),1)),o.imported===-1?(n(),r("div",_e,[c(a(E),null,{default:v(({mode:w})=>[e("button",{class:T(["button tag",{"is-dark has-text-grey-light":w=="dark"}]),onClick:Se=>Q(S),title:t.$t("twofaccounts.import.discard_this_account")},[c(u,{icon:["fas","trash"]})],10,me)]),_:2},1024),o.id>-2?(n(),r("button",{key:0,class:"button tag is-link",onClick:w=>P(S),title:t.$t("twofaccounts.import.import_this_account")},i(t.$t("twofaccounts.import.to_import")),9,he)):d("",!0)])):(n(),r("div",ve,[o.imported===1?(n(),r("span",ge,[p(i(t.$t("twofaccounts.import.imported"))+" ",1),c(u,{icon:["fas","check"]})])):(n(),r("span",we,[p(i(t.$t("twofaccounts.import.failure"))+" ",1),c(u,{icon:["fas","times"]})]))]))]),e("div",ke,[e("div",ye,i(t.$t("twofaccounts.import.issuer"))+": "+i(o.service),1),o.id===-2?(n(),r("div",be,[c(u,{class:"mr-1",icon:["fas","times-circle"]}),p(i(o.secret),1)])):d("",!0),o.id===-1&&o.imported!==1&&!o.errors?(n(),r("div",$e,[c(u,{class:"mr-1",icon:["fas","exclamation-circle"]}),p(i(t.$t("twofaccounts.import.possible_duplicate")),1)])):d("",!0),o.errors?(n(),r("ul",Ce,[(n(!0),r(J,null,L(o.errors,w=>(n(),r("li",{key:w,class:"has-text-danger"},i(w),1))),128))])):d("",!0)])]))),128)),a(A)>0?(n(),r("div",Ae,[a(N)?(n(),r("button",{key:0,onClick:s[2]||(s[2]=o=>H()),class:"has-text-grey button is-small is-ghost"},i(t.$t("twofaccounts.import.discard_duplicates"))+" ("+i(a(N))+")",1)):d("",!0),e("button",{onClick:s[3]||(s[3]=o=>K()),class:"has-text-grey button is-small is-ghost"},i(t.$t("twofaccounts.import.discard_all")),1)])):d("",!0),a(G)==a(l).length?(n(),r("div",xe,[e("button",{onClick:s[4]||(s[4]=o=>l.value=[]),class:"has-text-grey button is-small is-ghost"},i(t.$t("commons.clear")),1)])):d("",!0)])),c(ot,{showButtons:!0},{default:v(()=>[a(A)>0?(n(),r("p",Fe,[e("button",{class:"button is-link is-rounded is-focus",onClick:X},[e("span",null,i(t.$t("twofaccounts.import.import_all"))+" ("+i(a(A))+")",1)])])):d("",!0),c(st,{returnTo:{name:"accounts"},action:a(A)>0?"cancel":"close"},null,8,["action"])]),_:1})]),_:1}),c(at,{modelValue:a(g),"onUpdate:modelValue":s[8]||(s[8]=o=>pt(g)?g.value=o:null)},{default:v(()=>[c(ht,_t({ref_key:"otpDisplay",ref:y},a(b).data(),{onIncrementHotp:s[5]||(s[5]=()=>{}),onValidationError:s[6]||(s[6]=()=>{}),onPleaseCloseMe:s[7]||(s[7]=o=>g.value=!1)}),null,16)]),_:1},8,["modelValue"])])}}};export{Ne as default};