2FAuth/public/build/assets/Import-6ebcd5b1.js
2024-02-23 15:31:08 +01:00

2 lines
11 KiB
JavaScript
Vendored

import{Q 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,K 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 B,k as M,l as d,j as p,w as R,F as L,G as j,V as _t,P as mt}from"./app-06176200.js";import{F as T}from"./Form-87bc0477.js";import{_ as ht}from"./OtpDisplay-6b6605f3.js";import{S as vt}from"./Spinner-1a29b2e3.js";import{u as gt}from"./bus-01c5df37.js";/*! 2FAuth version 5.0.4 - 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"],Bt={class:"subtitle is-6 is-size-7-mobile"},Tt={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"},Lt={class:"title is-5 has-text-grey"},jt={class:"subtitle is-6 is-size-7-mobile"},Dt={class:"card-footer"},Jt={class:"title is-5 has-text-grey-dark"},Kt={class:"block is-size-7-mobile"},Wt={class:"table is-size-7-mobile is-fullwidth"},Gt=e("thead",null,[e("tr",null,[e("th"),e("th",null,"Plain text"),e("th",null,"QR code"),e("th",null,"JSON")])],-1),Ht=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 D=nt("2fauth"),_=lt(),J=rt(),x=gt(),K=ct(),y=k(null),F=k(null),z=k(null),b=q(new T({service:"",account:"",otp_type:"",icon:"",secret:"",algorithm:"",digits:null,counter:null,period:null})),$=q(new T({file:null,withSecret:!0})),C=q(new T({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),W=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 G(){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 H(){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,K.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:B(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",Bt,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",Tt,[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:B(o=="dark"?"has-text-grey-darker":"has-text-grey-lighter")},null,8,["class"])]),_:1})])]),e("div",Rt,[e("p",Lt,i(t.$t("twofaccounts.import.text_file")),1),e("p",jt,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",Dt,[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",Jt,i(t.$t("twofaccounts.import.supported_migration_formats")),1),e("div",Kt,[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",Wt,[Gt,e("tbody",null,[e("tr",null,[Ht,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(L,null,j(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(J).preferences.showAccountsIcons?(n(),r("img",{key:0,class:"import-icon",src:a(D).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:B(["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(L,null,j(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=>G()),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=>H()),class:"has-text-grey button is-small is-ghost"},i(t.$t("twofaccounts.import.discard_all")),1)])):d("",!0),a(W)==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};