2FAuth/public/build/assets/Import-1adbb4d1.js
2024-03-03 22:50:28 +01:00

2 lines
14 KiB
JavaScript
Vendored

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