dns-worker 1.2.1 → 1.2.2-alpha.20cfce0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.serverfull +8 -1
- package/dist/serverfull.mjs +294 -196
- package/dist/serverfull.mjs.map +4 -4
- package/migrations/0068_add_isp_hourly_rollups.sql +34 -0
- package/migrations/0069_drop_redundant_logs_indexes.sql +7 -0
- package/package.json +11 -10
- package/static/assets/AccountView-CqywJPAC.js +4 -0
- package/static/assets/{AnalyticsView-DPHx2dY5.js → AnalyticsView-D1LY_X2f.js} +2 -2
- package/static/assets/DestinationMap-CEtw2aBM.js +1 -0
- package/static/assets/FilteringView-BaOVBg9x.js +1 -0
- package/static/assets/LogsView-DMaq2SQ4.js +5 -0
- package/static/assets/{RulesView-CtQt9Fju.js → RulesView-1w0Gsfmf.js} +1 -1
- package/static/assets/SettingsView-BjAq5oi0.js +1 -0
- package/static/assets/{SetupView-DNfTcqJY.js → SetupView-Bl8r4gHO.js} +1 -1
- package/static/assets/{SwipeableDrawer-BuCjl9Vd.js → SwipeableDrawer-UY1QWnPj.js} +1 -1
- package/static/assets/SystemView-g6-diSqy.js +1 -0
- package/static/assets/{TrendChart-wgomUkAw.js → TrendChart-8stYkr8m.js} +1 -1
- package/static/assets/date-BRZZxWiW.js +1 -0
- package/static/assets/de-DE-B5QHxkUz.js +12 -0
- package/static/assets/es-ES-DVG_43hu.js +12 -0
- package/static/assets/fr-FR-C_o9fNbs.js +12 -0
- package/static/assets/index-Bw8TL1xo.js +17 -0
- package/static/assets/index-Dya4nLaI.css +2 -0
- package/static/assets/ja-JP-h0clNIRK.js +12 -0
- package/static/assets/ko-KR-Rr4R4ErI.js +12 -0
- package/static/assets/ru-RU-BKC7ewDw.js +12 -0
- package/static/assets/{services-BF0oUgkb.js → services-DFTZgwAw.js} +1 -1
- package/static/assets/{sqlite.worker-DfuIqYyd.js → sqlite.worker-D8vG3D1o.js} +7 -3
- package/static/assets/{useLogsE2ee-CARmudiz.js → useLogsE2ee-3yU9j9w3.js} +1 -1
- package/static/assets/{vendor-ui-core-C4974KNo.js → vendor-ui-core-CodM8CpF.js} +1 -1
- package/static/assets/vi-VN-DO0is0TQ.js +12 -0
- package/static/assets/zh-CN-D9qLjfXt.js +12 -0
- package/static/assets/zh-TW-qJFPjt4I.js +12 -0
- package/static/index.html +3 -3
- package/static/assets/AccountView-0QcFZ1Jr.js +0 -4
- package/static/assets/DestinationMap-B3EEJV7e.js +0 -1
- package/static/assets/FilteringView-PYhZsfXI.js +0 -1
- package/static/assets/LogsView-DS6lzitI.js +0 -5
- package/static/assets/SettingsView-B6nhXQtx.js +0 -1
- package/static/assets/SystemView-CpIEbDsf.js +0 -1
- package/static/assets/date-BFCCct66.js +0 -1
- package/static/assets/de-DE-DkZSdTly.js +0 -12
- package/static/assets/es-ES-B6WvDhm2.js +0 -12
- package/static/assets/fr-FR-83O7dpp-.js +0 -12
- package/static/assets/index-DEIEgGUw.js +0 -17
- package/static/assets/index-DzxNVvDJ.css +0 -2
- package/static/assets/ja-JP-TsIw1jL8.js +0 -12
- package/static/assets/ko-KR-BJCV1gAO.js +0 -12
- package/static/assets/ru-RU-D7sFMEOm.js +0 -12
- package/static/assets/vi-VN-B01Yq7PJ.js +0 -12
- package/static/assets/zh-CN-DmAkz3rO.js +0 -12
- package/static/assets/zh-TW-osJQe9X5.js +0 -12
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/services-DFTZgwAw.js","assets/index-Bw8TL1xo.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-DYK5a2J9.js","assets/vendor-i18next-DlmslyBB.js","assets/vendor-ui-core-CodM8CpF.js","assets/vendor-utils-Bab4qB3W.js","assets/index-Dya4nLaI.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,At as n,Ct as r,G as i,J as a,M as o,St as s,Tt as c,W as l,X as u,at as d,b as f,it as p,j as m,nn as h}from"./vendor-react-DYK5a2J9.js";import{S as g,b as _,x as v}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as y,D as b,E as x,F as S,H as C,N as w,P as T,S as E,T as D,a as O,f as k,h as A,l as j,o as M,p as N,r as P,u as F,w as I}from"./vendor-ui-core-CodM8CpF.js";import{_t as L}from"./vendor-utils-Bab4qB3W.js";import{A as R,S as z,_t as ee,ft as B,gn as te,gt as V,h as H,mt as ne,pt as U,w as W}from"./index-Bw8TL1xo.js";import{n as G,t as K}from"./formatCountryName-C6cFVUu2.js";import{t as q}from"./getFlagEmoji-Cd2A891A.js";import{i as re,n as ie,r as ae,t as oe}from"./useLogsE2ee-3yU9j9w3.js";import{t as J}from"./SwipeableDrawer-UY1QWnPj.js";var Y=e(g(),1),X=e(_(),1);const se=({range:e,setRange:t,customRange:n,setCustomRange:r,nowStr:i,fetchLogs:a,isMobile:o,logRetentionDays:c})=>{let{t:l}=h(),u=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}].filter(e=>e.days<=c).map(e=>e.key);return(0,X.jsx)(`div`,{className:`overflow-x-auto pb-1 -mx-4 px-4 md:mx-0 md:px-0`,children:(0,X.jsxs)(I,{minimal:o,variant:o?void 0:`minimal`,children:[u.map(n=>(0,X.jsx)(T,{active:e===n,onClick:()=>t(n),text:n.toUpperCase(),small:o},n)),(0,X.jsx)(x,{content:(0,X.jsxs)(`div`,{className:`p-4 space-y-2 w-64`,children:[(0,X.jsx)(w,{children:l(`analytics.customRange`)}),(0,X.jsx)(N,{label:l(`analytics.startTime`),children:(0,X.jsx)(k,{type:`datetime-local`,max:n.end||i,value:n.start,onChange:e=>r({...n,start:e.target.value})})}),(0,X.jsx)(N,{label:l(`analytics.endTime`),children:(0,X.jsx)(k,{type:`datetime-local`,min:n.start,max:i,value:n.end,onChange:e=>r({...n,end:e.target.value})})}),(0,X.jsx)(T,{fill:!0,intent:C.PRIMARY,text:l(`analytics.apply`),onClick:()=>{t(`custom`),a(`custom`,!0)}})]}),children:(0,X.jsx)(T,{active:e===`custom`,icon:(0,X.jsx)(s,{size:14}),text:o?``:l(`analytics.custom`),small:o})})]})})},ce=({statusFilter:e,setStatusFilter:t,isMobile:n})=>{let{t:r}=h(),i=(0,X.jsxs)(b,{children:[(0,X.jsx)(D,{icon:e===null?`tick`:void 0,text:r(`logs.allStatus`),onClick:()=>t(null)}),(0,X.jsx)(j,{}),(0,X.jsx)(D,{icon:e===`PASS`?`tick`:void 0,intent:C.SUCCESS,text:r(`logs.onlyPass`),onClick:()=>t(`PASS`)}),(0,X.jsx)(D,{icon:e===`BLOCK`?`tick`:void 0,intent:C.DANGER,text:r(`logs.onlyBlock`),onClick:()=>t(`BLOCK`)}),(0,X.jsx)(D,{icon:e===`REDIRECT`?`tick`:void 0,intent:C.WARNING,text:r(`logs.onlyRedirect`),onClick:()=>t(`REDIRECT`)})]}),a=(()=>{switch(e){case`PASS`:return{text:r(`logs.statusPass`),intent:C.SUCCESS};case`BLOCK`:return{text:r(`logs.statusBlock`),intent:C.DANGER};case`REDIRECT`:return{text:r(`logs.statusRedirect`),intent:C.WARNING};default:return{text:r(`logs.allStatus`),intent:C.NONE}}})();return(0,X.jsx)(x,{content:i,placement:`bottom-start`,children:(0,X.jsx)(T,{icon:(0,X.jsx)(d,{size:14}),rightIcon:`caret-down`,intent:a.intent,text:a.text,variant:`outlined`,fill:n})})},le=({accessPointIdFilter:e,setAccessPointIdFilter:t,accessPoints:n,isMobile:r})=>{let{t:i}=h(),o=(0,X.jsxs)(b,{children:[(0,X.jsx)(D,{icon:e===null?`tick`:void 0,text:i(`logs.allAccessPoint`),onClick:()=>t(null)}),(0,X.jsx)(j,{}),n.map(n=>(0,X.jsx)(D,{icon:e===n.id?`tick`:void 0,text:n.name,onClick:()=>t(n.id)},n.id))]}),s=e&&n.find(t=>t.id===e)?.name||i(`logs.allAccessPoint`);return(0,X.jsx)(x,{content:o,placement:`bottom-start`,children:(0,X.jsx)(T,{icon:(0,X.jsx)(a,{size:14}),rightIcon:`caret-down`,intent:e?C.PRIMARY:C.NONE,text:s,variant:`outlined`,fill:r})})},ue=Array.from(new Set(Object.values(G))).sort((e,t)=>e.localeCompare(t)),de=({destCountryFilter:e,setDestCountryFilter:t,isMobile:n})=>{let{t:r,i18n:i}=h(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``),l=(0,Y.useMemo)(()=>{let e=i.language;return ue.map(t=>{let n=K(t,e),r=K(t,`en`);return{code:t,name:n||r||t,searchStr:`${t} ${n} ${r}`.toLowerCase()}})},[i.language]),u=(0,Y.useMemo)(()=>{let e=s.trim().toLowerCase();return e?l.filter(t=>t.searchStr.includes(e)):l},[l,s]),d=(0,X.jsxs)(`div`,{className:`w-72 flex flex-col p-1.5`,children:[(0,X.jsx)(`div`,{className:`pb-1.5`,children:(0,X.jsx)(k,{leftIcon:`search`,placeholder:r(`logs.searchCountry`,`Search country...`),value:s,onChange:e=>c(e.target.value),small:!0,autoFocus:!0,rightElement:s?(0,X.jsx)(T,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>c(``)}):void 0})}),(0,X.jsxs)(b,{className:`max-h-64 overflow-y-auto`,children:[!s&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(D,{icon:e===null?`tick`:void 0,text:r(`logs.allCountry`),onClick:()=>{t(null),o(!1)}}),(0,X.jsx)(j,{})]}),u.length===0?(0,X.jsx)(D,{disabled:!0,text:r(`logs.noMatchingCountries`,`No matching countries found`)}):u.map(n=>(0,X.jsx)(D,{icon:e===n.code?`tick`:void 0,text:(0,X.jsxs)(`span`,{className:`flex items-center justify-between gap-2 w-full`,children:[(0,X.jsxs)(`span`,{className:`truncate`,children:[q(n.code),` `,n.name]}),(0,X.jsx)(`span`,{className:`text-xs text-gray-400 shrink-0 font-mono`,children:n.code})]}),onClick:()=>{t(n.code),o(!1)}},n.code))]})]}),f=e?`${q(e)} ${K(e,i.language)||e} (${e})`:r(`logs.allCountry`);return(0,X.jsx)(x,{content:d,placement:`bottom-start`,isOpen:a,onInteraction:e=>{o(e),e||c(``)},children:(0,X.jsx)(T,{icon:(0,X.jsx)(p,{size:14}),rightIcon:`caret-down`,intent:e?C.PRIMARY:C.NONE,text:f,variant:`outlined`,fill:n})})},fe=({profileId:e,range:t,customRange:n,destCountryFilter:r,accessPointIdFilter:a,ispFilter:o,setIspFilter:s,isMobile:c})=>{let{t:l}=h(),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)([]),[m,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(``),y=(0,Y.useRef)(``),w=`${e}:${t}:${n.start?Math.floor(new Date(n.start).getTime()/1e3):``}:${n.end?Math.floor(new Date(n.end).getTime()/1e3):``}:${r||``}:${a||``}`,E=async()=>{g(!0);try{let i=Math.floor(Date.now()/1e3),o,s=i,c=new URLSearchParams;if(t===`custom`&&n.start&&n.end)o=Math.floor(new Date(n.start).getTime()/1e3),s=Math.floor(new Date(n.end).getTime()/1e3),c.set(`range`,`custom`),c.set(`start`,String(o)),c.set(`end`,String(s));else{switch(t){case`10m`:o=i-600;break;case`1h`:o=i-3600;break;case`24h`:o=i-86400;break;case`7d`:o=i-604800;break;case`30d`:o=i-2592e3;break;default:o=i-3600;break}c.set(`range`,t)}r&&c.set(`country_code`,r),a&&c.set(`access_point_id`,a);let l=[],u=0;try{let t=await U(e,`isps`,c.toString());Array.isArray(t)&&t.length>0&&(l=t,u=t.reduce((e,t)=>e+(Number(t.count)||0),0))}catch(e){console.debug(`[IspFilter] Server ISP fetch failed, falling back to local DB:`,e)}try{let t=await W.queryISPs({profileId:e,countryCode:r||void 0,since:o,until:s,accessPointId:a||void 0});t&&t.length>0&&t.reduce((e,t)=>e+(Number(t.count)||0),0)>u&&(l=t)}catch(e){console.warn(`[IspFilter] Local SQLite query failed:`,e)}p(l),y.current=w}catch(e){console.error(`Failed to fetch ISPs for filter`,e)}finally{g(!1)}},O=e=>{d(e),e?y.current!==w&&E():v(``)},A=(0,Y.useMemo)(()=>{let e=_.trim().toLowerCase();return e?f.filter(t=>t.name.toLowerCase().includes(e)):f},[f,_]),M=(0,X.jsxs)(`div`,{className:`w-72 flex flex-col p-1.5`,children:[(0,X.jsx)(`div`,{className:`pb-1.5`,children:(0,X.jsx)(k,{leftIcon:`search`,placeholder:l(`logs.searchIsp`,`Search ISP...`),value:_,onChange:e=>v(e.target.value),small:!0,autoFocus:!0,rightElement:_?(0,X.jsx)(T,{icon:`cross`,variant:`minimal`,small:!0,onClick:()=>v(``)}):void 0})}),(0,X.jsx)(b,{className:`max-h-64 overflow-y-auto`,children:m?(0,X.jsxs)(`div`,{className:`flex items-center justify-center p-6 text-gray-500 gap-2`,children:[(0,X.jsx)(S,{size:16}),(0,X.jsx)(`span`,{className:`text-xs`,children:l(`logs.loadingIsps`,`Loading ISPs...`)})]}):(0,X.jsxs)(X.Fragment,{children:[!_&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(D,{icon:o===null?`tick`:void 0,text:l(`logs.allIsp`),onClick:()=>{s(null),d(!1)}}),(0,X.jsx)(j,{})]}),A.length===0?(0,X.jsx)(D,{disabled:!0,text:l(`logs.noMatchingIsps`,`No matching ISPs found`)}):A.map(e=>(0,X.jsx)(D,{icon:o===e.name?`tick`:void 0,text:(0,X.jsxs)(`span`,{className:`flex items-center justify-between gap-2 w-full`,children:[(0,X.jsx)(`span`,{className:`truncate`,title:e.name,children:e.name}),(0,X.jsx)(`span`,{className:`text-xs text-gray-400 shrink-0 font-mono`,children:e.count.toLocaleString()})]}),onClick:()=>{s(e.name),d(!1)}},e.name))]})})]}),N=o||l(`logs.allIsp`);return(0,X.jsx)(x,{content:M,placement:`bottom-start`,isOpen:u,onInteraction:O,children:(0,X.jsx)(T,{icon:(0,X.jsx)(i,{size:14}),rightIcon:`caret-down`,intent:o?C.PRIMARY:C.NONE,text:N,variant:`outlined`,fill:c})})},pe=({profileId:e,range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:o,isMobile:s,realtimeRefresh:c,setRealtimeRefresh:l,statusFilter:u,setStatusFilter:d,accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:m,destCountryFilter:g,setDestCountryFilter:_,ispFilter:v,setIspFilter:y,searchQuery:b,setSearchQuery:x,stats:S,logRetentionDays:w,onExport:E,exporting:D,loading:O=!1,syncing:j=!1})=>{let{t:M}=h(),[N,F]=(0,Y.useState)(!0),I=u!==null||f!==null||g!==null||v!==null;return(0,X.jsxs)(`div`,{className:`p-4 ${s&&N?`space-y-0`:`space-y-4`} shrink-0 bg-white/50 dark:bg-gray-900/50 backdrop-blur-sm border-b border-gray-100 dark:border-gray-800`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-center justify-between gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between w-full md:w-auto`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h2`,{className:`bp6-heading flex flex-wrap items-center gap-2 text-xl md:text-2xl m-0`,children:[M(`logs.title`),` `,(!s||!N)&&(0,X.jsx)(P,{minimal:!0,round:!0,children:t===`custom`?M(`analytics.custom`):t.toUpperCase()}),S&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(P,{minimal:!0,round:!0,children:S.total.toLocaleString()}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:C.SUCCESS,children:S.pass.toLocaleString()}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:C.DANGER,children:S.block.toLocaleString()}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:C.WARNING,children:S.redirect.toLocaleString()})]})]}),!s&&(0,X.jsx)(`p`,{className:`bp6-text-muted mt-1`,children:M(`logs.subtitle`)})]}),s&&(0,X.jsx)(T,{icon:N?`chevron-down`:`chevron-up`,variant:`minimal`,onClick:()=>F(!N)})]}),(!s||!N)&&(0,X.jsxs)(`div`,{className:`flex flex-col items-stretch md:items-end gap-2`,children:[(0,X.jsx)(se,{range:t,setRange:n,customRange:r,setCustomRange:i,nowStr:a,fetchLogs:o,isMobile:s,logRetentionDays:w}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-4`,children:[(0,X.jsx)(T,{icon:`download`,onClick:E,loading:D,title:M(`logs.export`,`Export Logs`),text:s?void 0:M(`logs.export`,`Export Logs`)}),(0,X.jsx)(A,{label:M(`logs.realtime`),checked:c,onChange:e=>l(e.target.checked),className:`mb-0!`}),(0,X.jsx)(T,{icon:`refresh`,onClick:()=>o(t,!0,!1,!0),loading:O||j,variant:`minimal`,small:s})]})]})]}),(!s||!N)&&(0,X.jsxs)(`div`,{className:`flex flex-col md:flex-row items-stretch md:items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 md:flex md:items-center gap-2`,children:[I&&(0,X.jsx)(`div`,{className:`col-span-2 md:contents`,children:(0,X.jsx)(T,{icon:`filter-remove`,onClick:()=>{d(null),p(null),_(null),y(null)},variant:`minimal`,title:M(`logs.clearFilters`),text:s?M(`logs.clearFilters`):void 0,fill:s})}),(0,X.jsx)(ce,{statusFilter:u,setStatusFilter:d,isMobile:s}),m.length>0&&(0,X.jsx)(le,{accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:m,isMobile:s}),(0,X.jsx)(de,{destCountryFilter:g,setDestCountryFilter:_,isMobile:s}),(0,X.jsx)(fe,{profileId:e,range:t,customRange:r,destCountryFilter:g,accessPointIdFilter:f,ispFilter:v,setIspFilter:y,isMobile:s})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-2 flex-1 md:max-w-md justify-end`,children:(0,X.jsx)(`div`,{className:`flex-1 md:max-w-xs`,children:(0,X.jsx)(k,{leftIcon:`search`,placeholder:M(`logs.searchPlaceholder`),value:b,onChange:e=>x(e.target.value),rightElement:b?(0,X.jsx)(T,{icon:`cross`,minimal:!0,onClick:()=>x(``)}):void 0,fill:!0})})})]})]})},me=({logs:e,setSelectedLog:n,setIsDrawerOpen:r,lastLogElementRef:i,prevLatestTimestamp:a,realtimeRefresh:o})=>{let{t:s}=h();return(0,X.jsx)(`div`,{className:`space-y-3 py-4`,children:e.map((c,l)=>{let u=o&&a!==null&&c.timestamp>a,d=(c.encrypt_version??0)>0||!!(c.kem_key_id||c.encrypted_payload),f=d&&(!c.domain||c.domain===`[Encrypted]`),p=d&&!!(c.domain&&c.domain!==`[Encrypted]`);return(0,X.jsxs)(E,{interactive:!0,onClick:()=>{n(c),r(!0)},className:L(`p-3 dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-800 shadow-sm overflow-hidden`,{"animate-row-glow":u}),ref:l===e.length-1?i:null,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-start mb-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[f?(0,X.jsx)(t,{size:14,className:`text-amber-500 shrink-0`}):(0,X.jsx)(`img`,{src:`/api/icon/${c.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm shrink-0`,alt:``,referrerPolicy:`no-referrer`,onError:e=>e.currentTarget.style.opacity=`0`}),(0,X.jsx)(`span`,{className:L(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":f}),children:f?s(`logs.encryptedRecord`,`[加密记录]`):c.domain}),p&&(0,X.jsx)(t,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})]}),(0,X.jsx)(P,{minimal:!0,round:!0,intent:c.action===`PASS`?C.SUCCESS:c.action===`BLOCK`?C.DANGER:C.WARNING,className:`text-[10px] shrink-0`,children:c.action})]}),(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-mono opacity-50`,children:new Date(c.timestamp*1e3).toLocaleTimeString([],{hour12:!1})}),(0,X.jsx)(`span`,{className:`text-[10px] bg-gray-100 dark:bg-gray-800 px-1 rounded opacity-60`,children:c.record_type}),c.access_point_name&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-50 truncate max-w-25`,children:c.access_point_name})]}),(0,X.jsx)(`div`,{className:`text-[10px] opacity-40 font-mono italic`,children:c.latency?`${c.latency}ms`:``})]})]},c.id)})})},he=({logs:e,setSelectedLog:n,setIsDrawerOpen:r,lastLogElementRef:i,prevLatestTimestamp:a,realtimeRefresh:o})=>{let{t:s}=h(),c=[{key:`time`,header:s(`logs.tableTime`),headerClassName:`w-24 rounded-tl-xl`,cellClassName:`font-mono text-[11px] opacity-60`,render:e=>new Date(e.timestamp*1e3).toLocaleTimeString([],{hour12:!1})},{key:`domain`,header:s(`logs.tableDomain`),headerClassName:`w-1/4`,render:e=>{let n=(e.encrypt_version??0)>0||!!(e.kem_key_id||e.encrypted_payload),r=n&&(!e.domain||e.domain===`[Encrypted]`),i=n&&!!(e.domain&&e.domain!==`[Encrypted]`);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[r?(0,X.jsx)(t,{size:14,className:`text-amber-500 shrink-0`}):(0,X.jsx)(`img`,{src:`/api/icon/${e.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm shrink-0`,alt:``,referrerPolicy:`no-referrer`}),(0,X.jsx)(`span`,{className:L(`font-bold text-sm truncate`,{"italic text-gray-400 dark:text-gray-500":r}),children:r?s(`logs.encryptedRecord`,`[加密记录]`):e.domain}),i&&(0,X.jsx)(`span`,{title:s(`settings.e2eeEnabled`,`已加密`),className:`inline-flex items-center`,children:(0,X.jsx)(t,{size:12,className:`text-emerald-500 shrink-0 opacity-80`})})]})}},{key:`answer`,header:s(`logs.tableAnswer`),headerClassName:`w-1/4`,cellClassName:`truncate font-mono text-[11px] opacity-70`,render:e=>e.answer||`-`},{key:`source`,header:s(`logs.tableSource`),headerClassName:`w-32`,render:e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(P,{minimal:!0,className:`font-mono text-[10px]`,title:e.geo_country||`Unknown`,children:q(e.geo_country)}),e.access_point_name&&(0,X.jsx)(`span`,{className:`text-xs opacity-70 truncate max-w-20`,title:e.access_point_name,children:e.access_point_name})]})},{key:`type`,header:s(`logs.tableType`),headerClassName:`w-20`,cellClassName:`text-center`,render:e=>(0,X.jsx)(`code`,{className:`text-[10px]`,children:e.record_type})},{key:`status`,header:s(`logs.tableStatus`),headerClassName:`w-28`,cellClassName:`text-center`,render:e=>(0,X.jsx)(`span`,{className:L(`bp6-tag`,`bp6-fill`,`bp6-minimal`,`bp6-round`,{"bp6-intent-success":e.action===`PASS`,"bp6-intent-danger":e.action===`BLOCK`,"bp6-intent-warning":e.action===`REDIRECT`}),children:(0,X.jsx)(`span`,{className:`bp6-text-overflow-ellipsis bp6-fill text-center`,children:e.action})})},{key:`reason`,header:s(`logs.tableReason`),headerClassName:`rounded-tr-xl`,cellClassName:`text-xs text-gray-500 italic truncate`,render:e=>e.reason||`-`}];return(0,X.jsx)(`div`,{className:`min-w-full inline-block align-middle py-0`,children:(0,X.jsx)(`div`,{className:`bg-white dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-800 shadow-sm overflow-visible`,children:(0,X.jsxs)(F,{interactive:!0,striped:!0,className:`w-full table-fixed`,children:[(0,X.jsx)(`thead`,{className:`sticky top-0 z-20 backdrop-blur-md`,children:(0,X.jsx)(`tr`,{children:c.map(e=>(0,X.jsx)(`th`,{className:L(`px-4 py-3 text-xs font-bold uppercase text-gray-500 bg-white/80 dark:bg-gray-900/80 border-b border-gray-100 dark:border-gray-800`,e.headerClassName),children:e.header},e.key))})}),(0,X.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:e.map((t,s)=>{let l=o&&a!==null&&t.timestamp>a;return(0,X.jsx)(`tr`,{onClick:()=>{n(t),r(!0)},className:L(`cursor-pointer`,{"animate-row-glow":l}),ref:s===e.length-1?i:null,children:c.map(e=>(0,X.jsx)(`td`,{className:L(`px-4 py-3`,e.cellClassName),children:e.render(t,s)},e.key))},t.id)})})]})})})},ge=({logs:e,loading:t,loadingMore:n,hasMore:i,realtimeRefresh:a,isMobile:o,searchQuery:s,scrollContainerRef:c,lastLogElementRef:l,prevLatestTimestamp:u,setSelectedLog:d,setIsDrawerOpen:f,logRetentionDays:p})=>{let{t:m}=h(),[g,_]=(0,Y.useState)(!1),v=(0,Y.useCallback)(()=>{c.current&&_(c.current.scrollTop>300)},[c]);return(0,Y.useEffect)(()=>{let e=c.current;if(e)return e.addEventListener(`scroll`,v,{passive:!0}),v(),()=>{e.removeEventListener(`scroll`,v)}},[c,v,e]),(0,X.jsxs)(`div`,{className:`flex-1 relative overflow-hidden flex flex-col min-h-0`,children:[(0,X.jsxs)(`div`,{ref:c,onScroll:v,className:L(`flex-1 overflow-y-auto`,o?`px-1`:`px-0`),children:[e.length===0&&!t?(0,X.jsx)(`div`,{className:`py-20`,children:(0,X.jsx)(y,{title:p===0?m(`logs.loggingDisabledTitle`,`日志记录已关闭`):m(s?`logs.noResults`:`logs.noRecords`),icon:p===0?`disable`:s?`search`:`outdated`,intent:p===0?C.WARNING:C.NONE,children:p===0?m(`logs.loggingDisabledDesc`,`当前配置的日志留存已设置为“关闭”,系统不记录任何查询日志。如需查看,请在设置中启用日志留存。`):s?m(`logs.noResultsDesc`,{query:s}):m(`logs.noRecordsDesc`)})}):o?(0,X.jsx)(me,{logs:e,setSelectedLog:d,setIsDrawerOpen:f,lastLogElementRef:l,prevLatestTimestamp:u,realtimeRefresh:a}):(0,X.jsx)(he,{logs:e,setSelectedLog:d,setIsDrawerOpen:f,lastLogElementRef:l,prevLatestTimestamp:u,realtimeRefresh:a}),(0,X.jsx)(`div`,{className:`p-6 flex flex-col items-center`,children:n?(0,X.jsx)(S,{size:16}):a?e.length>0&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`logs.realtimeLoadMoreTip`)}):!i&&e.length>0&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-30 italic`,children:m(`logs.loadedAll`,{count:e.length})})})]}),(0,X.jsx)(`div`,{className:L(`absolute z-30 pointer-events-none transition-all duration-300 ease-out`,o?`bottom-20 right-3`:`bottom-6 right-6`,g?`opacity-100 translate-y-0`:`opacity-0 translate-y-3`),children:(0,X.jsx)(`button`,{type:`button`,onClick:()=>{c.current?.scrollTo({top:0,behavior:`smooth`})},"aria-label":m(`logs.scrollToTop`),title:m(`logs.scrollToTop`),className:L(`pointer-events-auto group inline-flex items-center gap-1.5 rounded-full select-none`,`backdrop-blur-md bg-white/70 dark:bg-gray-900/70 hover:bg-white/90 dark:hover:bg-gray-800/90`,`border border-gray-200/80 dark:border-gray-700/80 hover:border-gray-300 dark:hover:border-gray-600`,`text-gray-700 dark:text-gray-200 hover:text-gray-950 dark:hover:text-white`,`shadow-sm hover:shadow active:scale-95 transition-all duration-200 cursor-pointer`,o?`px-2.5 py-1.5 text-[11px]`:`px-3.5 py-2 text-xs`),children:(0,X.jsx)(r,{size:o?13:15,strokeWidth:2.4,className:`transition-transform duration-200 group-hover:scale-105`})})})]})};function _e(e,t,n){let[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(e&&t?.id){o(!0),i(t);let e=new AbortController;return V(n,t.id,t.timestamp,{signal:e.signal}).then(async r=>{if(!e.signal.aborted)try{let e=r?.encrypt_version??t.encrypt_version,a=await R.decryptLogEntry(n,r);i(n=>({...n||t,...a,encrypt_version:e??a.encrypt_version}))}catch{i(e=>({...e||t,...r}))}}).catch(e=>{e.name!==`AbortError`&&(console.error(e),i(e=>e||t))}).finally(()=>{e.signal.aborted||o(!1)}),()=>{e.abort()}}else i(null)},[e,t?.id,n]),{detailedLog:r,loading:a}}const Z=({label:e,value:t,bold:n,italic:r})=>(0,X.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,X.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:e}),(0,X.jsx)(`span`,{className:L(`text-sm text-right`,n&&`font-bold`,r&&`italic`),children:t})]}),ve=({selectedLog:e,detailedLog:r,loading:i})=>{let{t:a}=h(),o=r?.encrypt_version??e.encrypt_version??(r?.kem_key_id||e.kem_key_id?2:0),s=o>0||!!(e.kem_key_id||e.encrypted_payload||r?.kem_key_id||r?.encrypted_payload),c=o===2||!!(e.kem_key_id||r?.kem_key_id),l=s&&(!e.domain||e.domain===`[Encrypted]`);return(0,X.jsx)(M,{title:a(`logs.basicInfo`),icon:(0,X.jsx)(n,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(Z,{label:a(`logs.detailDomain`),value:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-end font-bold`,children:[l?(0,X.jsx)(t,{size:14,className:`text-amber-500`}):(0,X.jsx)(`img`,{src:`/api/icon/${e.domain.replace(/^\*\./,``)}.ico`,className:`w-4 h-4 rounded-sm`,alt:``,referrerPolicy:`no-referrer`,onError:e=>e.currentTarget.style.display=`none`}),(0,X.jsx)(`span`,{className:L({"italic text-gray-400 dark:text-gray-500":l}),children:l?a(`logs.encryptedRecord`,`[加密记录]`):e.domain})]}),bold:!0}),(0,X.jsx)(Z,{label:a(`logs.detailType`),value:e.record_type}),(0,X.jsx)(Z,{label:a(`logs.detailLatency`),value:e.latency?`${e.latency} ms`:`-`}),(0,X.jsx)(Z,{label:a(`logs.detailAccessPoint`),value:(()=>{let t=r?.access_point_name||e.access_point_name,n=r?.access_point_id||e.access_point_id;return t?n&&n!==t?(0,X.jsx)(`span`,{title:n,className:`cursor-help`,children:t}):t:n?(0,X.jsx)(`span`,{className:`font-mono text-xs`,children:n}):i?(0,X.jsx)(S,{size:12}):`-`})()}),(0,X.jsx)(Z,{label:a(`logs.detailProfile`),value:r?.profile_name||r?.client_ip||e.client_ip||(i?(0,X.jsx)(S,{size:12}):`-`)}),(0,X.jsx)(Z,{label:a(`logs.detailTime`),value:H(new Date(e.timestamp*1e3))}),(0,X.jsx)(Z,{label:a(`logs.detailStatus`),value:(0,X.jsx)(P,{minimal:!0,intent:e.action===`PASS`?C.SUCCESS:e.action===`BLOCK`?C.DANGER:C.WARNING,children:e.action})}),(0,X.jsx)(Z,{label:a(`logs.detailUpstream`),value:r?.upstream||e.upstream||(i?(0,X.jsx)(S,{size:12}):`-`)}),(0,X.jsx)(Z,{label:a(`logs.detailReason`),value:e.reason||a(`logs.detailNoReason`),italic:!0}),(0,X.jsx)(Z,{label:a(`logs.detailECS`),value:r?.ecs||e.ecs||(i?(0,X.jsx)(S,{size:12}):`-`),italic:!0}),(0,X.jsx)(Z,{label:a(`logs.detailIsClientEncrypted`,`是否用户端加密`),value:s?(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 justify-end`,children:[(0,X.jsx)(t,{size:13,className:l?`text-amber-500`:`text-emerald-500`}),(0,X.jsxs)(`span`,{className:L(`text-xs font-medium`,l?`text-amber-600 dark:text-amber-400`:`text-emerald-600 dark:text-emerald-400`),children:[l?a(`logs.encryptedLocked`,`是 (未解锁)`):a(`logs.encryptedYes`,`是`),c?` (PQC)`:``]})]}):(0,X.jsx)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:a(`logs.notEncrypted`,`否`)})})]})})})},ye=({selectedLog:e})=>{let{t}=h(),n=e.record_type===`HTTPS`||e.record_type===`SVCB`||e.record_type===`TYPE65`||e.record_type===`TYPE64`,r=n&&(e.reason===`ECH Rewritten`||(e.reason?.toLowerCase().includes(`rewritten`)??!1));return(0,X.jsx)(M,{title:(0,X.jsxs)(`div`,{className:`flex items-center justify-between w-full pr-2`,children:[(0,X.jsx)(`span`,{children:t(`logs.resolutionResult`)}),r&&(0,X.jsx)(P,{minimal:!0,intent:C.PRIMARY,className:`text-xs`,children:t(`logs.rewritten`,`已重写`)})]}),icon:(0,X.jsx)(p,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:(0,X.jsx)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-3 font-mono text-xs break-all leading-relaxed rounded-lg`,children:(()=>{if(!e.answer)return t(`logs.noResult`);let r=e.answer.split(`
|
|
3
|
+
`).map(e=>e.trim()).filter(Boolean);return r.length===0?t(`logs.noResult`):(0,X.jsx)(`div`,{className:`space-y-2`,children:r.map((e,t)=>{let r=e.match(/^(\d+)\s+([^\s]+)(?:\s+(.*))?$/);if(r&&(n||e.includes(`alpn=`)||e.includes(`ech=`)||e.includes(`ipv4hint=`))){let e=r[1],n=r[2],i=(r[3]||``).split(/\s+/).filter(Boolean);return(0,X.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-2.5 rounded-md space-y-2 border border-gray-200 dark:border-gray-700`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsxs)(P,{minimal:!0,intent:C.PRIMARY,children:[`Priority `,e]}),(0,X.jsxs)(`span`,{className:`font-semibold text-gray-700 dark:text-gray-300`,children:[`Target: `,n]})]}),i.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5 pt-1 border-t border-gray-100 dark:border-gray-800 text-xs`,children:i.map((e,t)=>{let n=e.indexOf(`=`);if(n===-1)return(0,X.jsx)(P,{minimal:!0,className:`font-mono`,children:e},t);let r=e.substring(0,n),i=e.substring(n+1);return r===`ech`?(0,X.jsxs)(P,{minimal:!0,intent:C.SUCCESS,className:`font-mono break-all max-w-full select-all text-left whitespace-normal h-auto py-1 inline-block`,title:i,children:[(0,X.jsx)(`span`,{className:`font-bold`,children:`ech:`}),` `,i]},t):r===`alpn`?(0,X.jsxs)(P,{minimal:!0,intent:C.WARNING,className:`font-mono`,children:[(0,X.jsx)(`span`,{className:`font-bold`,children:`alpn:`}),` `,i]},t):(0,X.jsxs)(P,{minimal:!0,className:`font-mono`,children:[(0,X.jsxs)(`span`,{className:`font-bold`,children:[r,`:`]}),` `,i]},t)})})]},t)}return(0,X.jsx)(`div`,{className:`space-y-1`,children:e.split(`,`).map(e=>e.trim()).filter(Boolean).map((e,t)=>(0,X.jsx)(`div`,{className:`text-xs font-mono text-gray-800 dark:text-gray-200 select-all`,children:e},t))},t)})})})()})})})},be=({selectedLog:e,detailedLog:t,loading:n})=>{let{t:r,i18n:i}=h(),a=t?.client_ip||e.client_ip,o=t?.geo_country||e.geo_country,s=`Unknown`;if(o){let e=o.toUpperCase().trim();s=e===`LAN`||e===`LOCAL`||e===`PRIVATE`||e===`PRIVATE NETWORK`?r(`setup.privateNetwork`,`Private Network`):e===`UN`||e===`UNKNOWN`||e===`XX`?r(`common.unknown`,`Unknown`):K(o,i.language)||o}let c=t?.dest_country_code||e.dest_country_code,l=t?.dest_country||e.dest_country,d=t?.dest_isp||e.dest_isp,p=null,m=t?.dest_geoip||e.dest_geoip;if(m)try{let e=JSON.parse(m);!c&&e.country_code&&(c=e.country_code);let t=[e.city,e.region,e.country].filter(Boolean),n=l||c||void 0;p={locationTitle:t.length>0?t.join(`, `):n,isp:e.isp||d||void 0,as:e.as||void 0}}catch{}return!p&&(l||c||d)&&(p={locationTitle:l||c||void 0,isp:d||void 0}),(0,X.jsx)(M,{title:r(`logs.networkDetails`),icon:(0,X.jsx)(f,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-50 mb-1`,children:r(`logs.clientSource`)}),(0,X.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:a||(n?(0,X.jsx)(S,{size:12}):`-`)}),(o||n)&&(0,X.jsx)(P,{minimal:!0,title:s,children:o?q(o):`-`})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center mb-1`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-50`,children:r(`logs.destination`)}),(c||n)&&(0,X.jsx)(P,{minimal:!0,title:l||c||`Unknown`,children:c?q(c):`-`})]}),n&&!p?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,X.jsx)(S,{size:16})}):p?(0,X.jsx)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-3 rounded-lg mt-1`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(u,{size:16,className:`oklch(60.9% 0.126 221.723) mt-1 shrink-0`}),(0,X.jsxs)(`div`,{children:[p.locationTitle&&(0,X.jsx)(`div`,{className:`font-bold text-sm`,children:p.locationTitle}),(p.isp||p.as)&&(0,X.jsxs)(`div`,{className:`text-xs opacity-70 mt-1`,children:[p.isp,p.as&&(0,X.jsx)(`span`,{className:`opacity-60 block mt-0.5`,children:p.as})]})]})]})}):(0,X.jsx)(`div`,{className:`text-xs opacity-50 py-1`,children:`-`})]})]})})})},xe=({selectedLog:e,onQuickAction:t})=>{let{t:n}=h(),r=(e.encrypt_version??0)>0&&(!e.domain||e.domain===`[Encrypted]`);return(0,X.jsx)(M,{title:n(`logs.quickActions`),icon:(0,X.jsx)(l,{size:16}),className:`shadow-none! rounded-lg!`,children:(0,X.jsx)(O,{children:r?(0,X.jsx)(`p`,{className:`text-xs text-center text-gray-500 italic py-2 m-0`,children:n(`settings.e2eeUnlockPrompt`,`此记录已加密,请先解锁私钥后再进行操作。`)}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(T,{fill:!0,intent:C.SUCCESS,icon:(0,X.jsx)(o,{size:16}),text:n(`logs.actionAllow`),onClick:()=>t?.(e.domain,`ALLOW`)}),(0,X.jsx)(T,{fill:!0,intent:C.DANGER,icon:(0,X.jsx)(m,{size:16}),text:n(`logs.actionBlock`),onClick:()=>t?.(e.domain,`BLOCK`)}),(0,X.jsx)(T,{fill:!0,icon:(0,X.jsx)(c,{size:16}),text:n(`logs.actionRedirect`),onClick:()=>t?.(e.domain,`REDIRECT`,e.record_type)})]})})})},Se=({isDrawerOpen:e,setIsDrawerOpen:t,selectedLog:r,profileId:i,isMobile:a,onQuickAction:o})=>{let{t:s}=h(),{detailedLog:c,loading:l}=_e(e,r,i);return(0,X.jsx)(J,{isOpen:e&&r!==null,onClose:()=>t(!1),title:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(n,{size:18}),(0,X.jsx)(`span`,{children:s(`logs.logDetails`)})]}),icon:`info-sign`,size:a?`100%`:`450px`,children:r&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ve,{selectedLog:r,detailedLog:c,loading:l}),(0,X.jsx)(ye,{selectedLog:r}),(0,X.jsx)(be,{selectedLog:r,detailedLog:c,loading:l}),(0,X.jsx)(xe,{selectedLog:r,onQuickAction:o})]})})};function Ce(e){let[t,n]=(0,Y.useState)(`1h`),[r,i]=(0,Y.useState)({start:``,end:``}),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)([]),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``);return(0,Y.useEffect)(()=>{B(e).then(u).catch(console.error)},[e]),(0,Y.useEffect)(()=>{m(null)},[d]),{range:t,setRange:n,customRange:r,setCustomRange:i,statusFilter:a,setStatusFilter:o,accessPointIdFilter:s,setAccessPointIdFilter:c,accessPoints:l,destCountryFilter:d,setDestCountryFilter:f,ispFilter:p,setIspFilter:m,searchQuery:h,setSearchQuery:g}}function we(e){let[t,n]=(0,Y.useState)(30);return(0,Y.useEffect)(()=>{ne(e).then(e=>{try{let t=JSON.parse(e.settings||`{}`);n(t.log_retention_days===void 0?30:Number(t.log_retention_days))}catch(e){console.error(`[useProfileRetention] Failed to parse settings:`,e)}}).catch(e=>console.error(`[useProfileRetention] Failed to fetch profile details:`,e))},[e]),t}function Te(e,t){let n=Math.floor(Date.now()/1e3);if(e===`custom`&&t.start&&t.end)return{since:Math.floor(new Date(t.start).getTime()/1e3),until:Math.floor(new Date(t.end).getTime()/1e3)};let r;switch(e){case`10m`:r=n-600;break;case`1h`:r=n-3600;break;case`24h`:r=n-86400;break;case`7d`:r=n-604800;break;case`30d`:r=n-2592e3;break;default:r=n-3600;break}return{since:r,until:n}}function Q(e){if(!(!e||e.length===0)&&`serviceWorker`in navigator&&navigator.serviceWorker.controller){let t=Array.from(new Set(e.map(e=>e.domain)));navigator.serviceWorker.controller.postMessage({type:`PREFETCH_ICONS`,domains:t})}}async function Ee(e){let{profileId:t,currentRange:n,customRange:r,since:i,until:a,limit:o,isInitial:s,statusFilter:c,accessPointIdFilter:l,destCountryFilter:u,ispFilter:d,searchQuery:f,lastTimestamp:p,signal:m}=e,h=new URLSearchParams({range:n,limit:String(o)});n===`custom`&&r.start&&r.end&&(h.set(`start`,String(i)),h.set(`end`,String(a))),c&&h.set(`status`,c),l&&h.set(`access_point_id`,l),u&&h.set(`dest_country`,u),d&&h.set(`isp`,d),f&&h.set(`search`,f),!s&&p!==void 0&&h.set(`before`,String(p));let g=ee(t,h.toString(),{signal:m}),_=Promise.resolve(null);if(s){let e=new URLSearchParams({range:n});n===`custom`&&r.start&&r.end&&(e.set(`start`,String(i)),e.set(`end`,String(a))),f&&e.set(`search`,f),c&&e.set(`status`,c),l&&e.set(`access_point_id`,l),u&&e.set(`dest_country`,u),d&&e.set(`isp`,d),_=U(t,`summary`,e.toString(),{signal:m})}let[v,y]=await Promise.all([g,_]),b=null;if(y){let e={total:0,pass:0,block:0,redirect:0};y.forEach(t=>{let n=t.count;e.total+=n,t.action===`PASS`?e.pass=n:t.action===`BLOCK`?e.block=n:t.action===`REDIRECT`&&(e.redirect=n)}),b=e}return{logs:v||[],stats:b}}async function De(e,t,n,r){if(!await W.init()||t.aborted)return{success:!1};let{profileId:i,searchQuery:a,statusFilter:o,accessPointIdFilter:s,destCountryFilter:c,ispFilter:l,since:u,until:d,limit:f}=e,p=await W.queryLogs({profileId:i,search:a||void 0,action:o||void 0,accessPointId:s||void 0,destCountry:c||void 0,isp:l||void 0,since:u,until:d,before:void 0,limit:f,offset:0});if(t.aborted)return{success:!1};p.rows.length>0&&r&&r({rows:p.rows,hasMore:p.rows.length>=f,stats:p.stats});try{let e=await W.syncProfileLogs(i,void 0,u,t,n);if(!t.aborted&&(e>0||p.rows.length===0)&&(p=await W.queryLogs({profileId:i,search:a||void 0,action:o||void 0,accessPointId:s||void 0,destCountry:c||void 0,isp:l||void 0,since:u,until:d,before:void 0,limit:f,offset:0}),t.aborted))return{success:!1}}catch(e){e.name!==`AbortError`&&console.warn(`[localDbStrategy] Incremental sync error:`,e)}return p.rows.length>0?{success:!0,result:{rows:p.rows,hasMore:p.rows.length>=f,stats:p.stats}}:{success:!1}}async function Oe(e,t,n){if(!await W.init()||n.aborted)return{success:!1};let{profileId:r,searchQuery:i,statusFilter:a,accessPointIdFilter:o,destCountryFilter:s,ispFilter:c,since:l,until:u,limit:d}=e,f=await W.queryLogs({profileId:r,search:i||void 0,action:a||void 0,accessPointId:o||void 0,destCountry:s||void 0,isp:c||void 0,since:l,until:u,before:t,limit:d,offset:0});if(n.aborted)return{success:!1};if(f.rows.length>=d)return{success:!0,result:{rows:f.rows,hasMore:f.rows.length>=d}};if(t>l)try{let e=await W.backfillLogs(r,t,l,d,n);if(n.aborted)return{success:!1};if(e.length>0){let f=await W.queryLogs({profileId:r,search:i||void 0,action:a||void 0,accessPointId:o||void 0,destCountry:s||void 0,isp:c||void 0,since:l,until:u,before:t,limit:d,offset:0});return n.aborted?{success:!1}:{success:!0,result:{rows:f.rows,hasMore:f.rows.length>=d&&e.length>=d}}}return{success:!0,result:{rows:f.rows,hasMore:!1}}}catch(e){return e.name!==`AbortError`&&console.warn(`[localDbStrategy] Backfill error:`,e),{success:!0,result:{rows:f.rows,hasMore:!1}}}return{success:!0,result:{rows:f.rows,hasMore:!1}}}function ke({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c}){let[l,u]=(0,Y.useState)([]),[d,f]=(0,Y.useState)(!0),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(!0),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),C=(0,Y.useRef)([]);(0,Y.useEffect)(()=>{C.current=l},[l]);let w=(0,Y.useRef)(null),T=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>()=>{w.current&&w.current.abort()},[]),{logs:l,setLogs:u,loading:d,loadingMore:p,syncing:h,hasMore:_,setHasMore:v,stats:y,setStats:b,prevLatestTimestamp:x,setPrevLatestTimestamp:S,fetchLogs:(0,Y.useCallback)(async(t,l=!0,d=!1,p=!1)=>{w.current&&w.current.abort();let h=new AbortController;w.current=h,T.current=!0,l?f(!0):m(!0);try{let _=c?25:50,{since:y,until:x}=Te(t,n),E={profileId:e,searchQuery:s,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,since:y,until:x,limit:_},D=!1;if(l){d||g(!0);let l=new URLSearchParams({range:t});t===`custom`&&n.start&&n.end&&(l.set(`start`,String(y)),l.set(`end`,String(x))),s&&l.set(`search`,s),r&&l.set(`status`,r),i&&l.set(`access_point_id`,i),a&&l.set(`dest_country`,a),o&&l.set(`isp`,o),U(e,`summary`,l.toString(),{signal:h.signal}).then(e=>{if(h.signal.aborted||!e)return;let t={total:0,pass:0,block:0,redirect:0};e.forEach(e=>{let n=Number(e.count)||0;t.total+=n,e.action===`PASS`?t.pass=n:e.action===`BLOCK`?t.block=n:e.action===`REDIRECT`&&(t.redirect=n)}),b(t)}).catch(()=>{});let m=await De(E,h.signal,p,e=>{D=!0,S(d&&C.current.length>0?C.current[0].timestamp:null),u(e.rows),v(c?!1:e.hasMore),c&&e.rows.length>0&&z.updateCursor(e.rows[0].timestamp,e.rows[0].id),e.stats&&b(e.stats),f(!1)});if(h.signal.aborted)return;m.success&&m.result&&(D=!0,S(d&&C.current.length>0?C.current[0].timestamp:null),u(m.result.rows),v(c?!1:m.result.hasMore),c&&m.result.rows.length>0&&z.updateCursor(m.result.rows[0].timestamp,m.result.rows[0].id),m.result.stats&&b(m.result.stats))}else{let e=C.current.length>0?C.current[C.current.length-1].timestamp:void 0;if(e!==void 0){let t=await Oe(E,e,h.signal);if(h.signal.aborted)return;t.success&&t.result&&(D=!0,u(e=>[...e,...t.result.rows]),v(c?!1:t.result.hasMore))}else D=!0,v(!1)}if(D){Q(C.current),w.current===h&&(f(!1),m(!1),g(!1),T.current=!1);return}let O=await Ee({profileId:e,currentRange:t,customRange:n,since:y,until:x,limit:_,isInitial:l,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,lastTimestamp:!l&&C.current.length>0?C.current[C.current.length-1].timestamp:void 0,signal:h.signal});if(h.signal.aborted)return;l?(S(d&&C.current.length>0?C.current[0].timestamp:null),u(O.logs),v(c?!1:O.logs.length>=_),O.stats&&b(O.stats)):(u(e=>[...e,...O.logs]),v(c?!1:O.logs.length>=_)),O.logs.length>0&&(c&&z.updateCursor(O.logs[0].timestamp,O.logs[0].id),Q(O.logs))}catch(e){e.name!==`AbortError`&&console.error(e)}finally{w.current===h&&(f(!1),m(!1),g(!1),T.current=!1)}},[e,c,n,s,r,i,a,o]),isFetchingRef:T,logsRef:C}}function Ae({realtimeRefresh:e,statusFilter:t,accessPointIdFilter:n,destCountryFilter:r,ispFilter:i,searchQuery:a,pageSize:o,logsRef:s,setLogs:c,setStats:l,setPrevLatestTimestamp:u}){(0,Y.useEffect)(()=>{if(e)return z.onNewLogs(e=>{if(!e||e.length===0)return;let d=e.filter(e=>{if(t&&e.action!==t||n&&e.access_point_id!==n||r&&(e.dest_country_code||e.dest_country)!==r||i&&e.dest_isp!==i)return!1;if(a){let t=a.toLowerCase(),n=e.domain?.toLowerCase().includes(t),r=e.client_ip?.toLowerCase().includes(t),i=e.reason?.toLowerCase().includes(t);if(!n&&!r&&!i)return!1}return!0});d.length!==0&&(u(s.current.length>0?s.current[0].timestamp:null),c(e=>{let t=new Set(e.map(e=>`${e.timestamp}-${e.id}`)),n=d.filter(e=>!t.has(`${e.timestamp}-${e.id}`));return n.length===0?e:[...n,...e].slice(0,o)}),l(t=>{if(!t)return t;let n=0,r=0,i=0;for(let t of e)t.action===`PASS`?n++:t.action===`BLOCK`?r++:t.action===`REDIRECT`&&i++;return{total:t.total+e.length,pass:t.pass+n,block:t.block+r,redirect:t.redirect+i}}))})},[e,t,n,r,i,a,o,s,c,l,u])}function je({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c}){let l=we(e),{logs:u,setLogs:d,loading:f,loadingMore:p,syncing:m,hasMore:h,stats:g,setStats:_,prevLatestTimestamp:v,setPrevLatestTimestamp:y,fetchLogs:b,isFetchingRef:x,logsRef:S}=ke({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,realtimeRefresh:c});Ae({realtimeRefresh:c,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,pageSize:25,logsRef:S,setLogs:d,setStats:_,setPrevLatestTimestamp:y});let C=(0,Y.useRef)(null),w=(0,Y.useRef)(null),T=(0,Y.useCallback)(()=>{c||x.current||f||p||!h||b(t,!1)},[f,p,h,t,c,b,x]),E=(0,Y.useCallback)(e=>{w.current&&w.current.disconnect(),!(f||p||c||!h)&&(w.current=new IntersectionObserver(e=>{e[0]?.isIntersecting&&h&&!x.current&&T()},{root:C.current,rootMargin:`100px`}),e&&w.current.observe(e))},[f,p,h,T,c,x]);return(0,Y.useEffect)(()=>{if(t===`custom`&&(!n.start||!n.end))return;let e=setTimeout(()=>{b(t,!0)},s?500:0);return()=>clearTimeout(e)},[t,n.start,n.end,s,b]),{logs:u,loading:f,loadingMore:p,syncing:m,hasMore:h,stats:g,logRetentionDays:l,prevLatestTimestamp:v,scrollContainerRef:C,lastLogElementRef:E,fetchLogs:b,isFetchingRef:x,logsRef:S}}function Me({profileId:e,range:t,searchQuery:n,realtimeRefresh:r,scrollContainerRef:i,isFetchingRef:a,fetchLogs:o,logsRef:s}){let c=(0,Y.useRef)({range:t,searchQuery:n,fetchLogs:o,logsRef:s});(0,Y.useEffect)(()=>{c.current={range:t,searchQuery:n,fetchLogs:o,logsRef:s}}),(0,Y.useEffect)(()=>{if(!r){z.disconnect();return}let t=!1,n=null,o=()=>{n||=setInterval(()=>{let{range:e,searchQuery:n,fetchLogs:r}=c.current;!t&&document.visibilityState===`visible`&&i.current&&i.current.scrollTop<50&&!a.current&&!n&&e!==`custom`&&r(e,!0,!0)},8e3)},s=()=>{n&&=(clearInterval(n),null)},l=z.onStatusChange(e=>{t=e,e?s():o()}),u=c.current.logsRef.current,d=u.length>0?u[0]:null,f=d?d.timestamp:Math.floor(Date.now()/1e3)-60,p=d?d.id:0;z.connect(e,f,p);let m=setTimeout(()=>{t||o()},2500),h=()=>{if(document.visibilityState===`visible`)if(t){let e=c.current.logsRef.current,t=e.length>0?e[0]:null;t&&z.updateCursor(t.timestamp,t.id)}else{let{range:e,fetchLogs:t}=c.current;t(e,!0,!0)}};return document.addEventListener(`visibilitychange`,h),()=>{clearTimeout(m),s(),l(),z.disconnect(),document.removeEventListener(`visibilitychange`,h)}},[e,r])}function $(e){let t=new Date(e*1e3),n=-t.getTimezoneOffset(),r=n>=0?`+`:`-`,i=e=>String(e).padStart(2,`0`);return t.getFullYear()+`-`+i(t.getMonth()+1)+`-`+i(t.getDate())+`T`+i(t.getHours())+`:`+i(t.getMinutes())+`:`+i(t.getSeconds())+`.`+(e=>String(e).padStart(3,`0`))(t.getMilliseconds())+(n===0?`Z`:r+i(Math.floor(Math.abs(n)/60))+`:`+i(Math.abs(n)%60))}function Ne(e){let t=[`profile_id`,`access_point_id`,`time`,`client_ip`,`geo_country`,`domain`,`record_type`,`action`,`reason`,`answer`,`dest_geoip`,`ecs`,`upstream`,`latency`],n=[t.join(`,`)];for(let r of e){let e=t.map(e=>{let t=``;if(e===`time`)t=$(r.timestamp);else{let n=r[e];t=n==null?e===`dest_geoip`&&(r.dest_country_code||r.dest_country||r.dest_isp)?JSON.stringify({country_code:r.dest_country_code||``,country:r.dest_country||``,isp:r.dest_isp||``}):``:typeof n==`object`?JSON.stringify(n):String(n)}let n=t.replace(/"/g,`""`);return n.includes(`,`)||n.includes(`
|
|
4
|
+
`)||n.includes(`\r`)||n.includes(`"`)?`"${n}"`:n});n.push(e.join(`,`))}return n.join(`
|
|
5
|
+
`)}function Pe(e,t){let n=new Blob([e],{type:`text/csv;charset=utf-8;`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.setAttribute(`href`,r),i.setAttribute(`download`,t),document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function Fe(e,t,n,r){let i=e=>e.replace(/[:*?"<>|]/g,`-`),a=i($(t)),o=i($(n)),s=i(r.toString());return`query_logs_${e}_${a}_${o}${s?`_${s}`:``}.csv`}function Ie({profileId:e,range:t,customRange:n,statusFilter:r,accessPointIdFilter:i,destCountryFilter:a,ispFilter:o,searchQuery:s,toasterRef:c}){let{t:l}=h(),[u,d]=(0,Y.useState)(!1);return{exporting:u,handleExportLogs:async()=>{d(!0);try{let{since:u,until:d}=Te(t,n),f=new URLSearchParams({range:t});if(t===`custom`&&n.start&&n.end){let e=Math.floor(new Date(n.start).getTime()/1e3),t=Math.floor(new Date(n.end).getTime()/1e3);f.set(`start`,String(e)),f.set(`end`,String(t))}r&&f.set(`status`,r),i&&f.set(`access_point_id`,i),a&&f.set(`dest_country`,a),o&&f.set(`isp`,o),s&&f.set(`search`,s);let p=[],m=!1;try{if(await W.init()){let t=await W.queryLogs({profileId:e,search:s.trim()||void 0,action:r||void 0,accessPointId:i||void 0,destCountry:a||void 0,isp:o||void 0,since:u,until:d,limit:1e5});t&&Array.isArray(t.rows)&&t.rows.length>0&&(p=t.rows)}}catch(e){console.warn(`[LogExport] Local SQLite query failed or unavailable, falling back to server:`,e)}if(!p||p.length===0){m=!0;let{exportProfileLogs:t}=await v(async()=>{let{exportProfileLogs:e}=await import(`./services-DFTZgwAw.js`);return{exportProfileLogs:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),n=await t(e,f.toString());n&&Array.isArray(n)&&(p=n)}if(!p||p.length===0){c?.current?.show({message:l(`logs.noResults`,`No logs found to export`),intent:C.WARNING});return}if(p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0)){if(!R.isProfileUnlocked(e))try{await R.unlockProfile(e)}catch(e){console.warn(`[LogExport] Auto-unlock attempt failed or was cancelled:`,e)}p=await R.decryptLogsBatch(e,p),p.some(e=>(e.encrypt_version??(e.encrypted_payload?1:0))>0||e.domain===`[Encrypted]`)&&c?.current?.show({message:l(`logs.e2eeLockedExportWarning`,`部分日志处于加密状态且未解锁,导出的数据可能包含未解密内容。`),intent:C.WARNING,icon:`lock`})}m&&p.length>0&&W.batchInsertLogs(e,p).catch(e=>{console.warn(`[LogExport] Failed to cache exported logs into local SQLite:`,e)}),Pe(Ne(p),Fe(e,p[0].timestamp,p[p.length-1].timestamp,f)),c?.current?.show({message:l(`logs.exportSuccess`,`Logs exported successfully`),intent:C.SUCCESS})}catch(e){console.error(`Failed to export logs`,e),c?.current?.show({message:l(`logs.exportError`,`Failed to export logs`),intent:C.DANGER})}finally{d(!1)}}}}function Le({profileId:e,toasterRef:t}){let[n,r]=(0,Y.useState)(!1),i=Ce(e),a=je({profileId:e,realtimeRefresh:n,range:i.range,customRange:i.customRange,statusFilter:i.statusFilter,accessPointIdFilter:i.accessPointIdFilter,destCountryFilter:i.destCountryFilter,ispFilter:i.ispFilter,searchQuery:i.searchQuery});Me({profileId:e,realtimeRefresh:n,range:i.range,searchQuery:i.searchQuery,scrollContainerRef:a.scrollContainerRef,isFetchingRef:a.isFetchingRef,fetchLogs:a.fetchLogs,logsRef:a.logsRef});let o=Ie({profileId:e,range:i.range,customRange:i.customRange,statusFilter:i.statusFilter,accessPointIdFilter:i.accessPointIdFilter,destCountryFilter:i.destCountryFilter,ispFilter:i.ispFilter,searchQuery:i.searchQuery,toasterRef:t});return{realtimeRefresh:n,setRealtimeRefresh:r,...i,...a,...o}}const Re=({profileId:e,onQuickAction:t,toasterRef:n})=>{let r=te(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1),{realtimeRefresh:c,setRealtimeRefresh:l,range:u,setRange:d,customRange:f,setCustomRange:p,statusFilter:m,setStatusFilter:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,destCountryFilter:y,setDestCountryFilter:b,ispFilter:x,setIspFilter:C,searchQuery:w,setSearchQuery:T,logs:E,loading:D,loadingMore:O,syncing:k,hasMore:A,stats:j,logRetentionDays:M,prevLatestTimestamp:N,scrollContainerRef:P,lastLogElementRef:F,fetchLogs:I,exporting:L,handleExportLogs:R}=Le({profileId:e,toasterRef:n}),{isE2eeEnabled:z,isE2eeUnlocked:ee,unlocking:B,recoveryDialogOpen:V,setRecoveryDialogOpen:H,recoveryKeyInput:ne,setRecoveryKeyInput:U,recoveryError:W,setRecoveryError:G,rotatedKey:K,setRotatedKey:q,copiedKey:J,handleCopyRotatedKey:se,handleUnlockPasskey:ce,handleUnlockRecoveryKey:le}=oe({profileId:e,range:u,fetchLogs:I,toasterRef:n}),ue=new Date().toLocaleString(`sv-SE`).replace(` `,`T`).slice(0,16);return D&&E.length===0?(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,X.jsx)(S,{})}):(0,X.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden bg-gray-50/30 dark:bg-gray-950/10 max-w-7xl mx-auto w-full pt-14`,children:[(0,X.jsx)(pe,{profileId:e,range:u,setRange:d,customRange:f,setCustomRange:p,nowStr:ue,fetchLogs:I,isMobile:r,realtimeRefresh:c,setRealtimeRefresh:l,statusFilter:m,setStatusFilter:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,destCountryFilter:y,setDestCountryFilter:b,ispFilter:x,setIspFilter:C,searchQuery:w,setSearchQuery:T,stats:j,logRetentionDays:M,onExport:R,exporting:L,loading:D,syncing:k}),z&&!ee&&(0,X.jsx)(re,{isMobile:r,unlocking:B,onUnlockPasskey:ce,onOpenRecoveryDialog:()=>{G(``),U(``),H(!0)}}),(0,X.jsx)(ge,{logs:E,loading:D,loadingMore:O,hasMore:A,realtimeRefresh:c,isMobile:r,searchQuery:w,scrollContainerRef:P,lastLogElementRef:F,prevLatestTimestamp:N,setSelectedLog:a,setIsDrawerOpen:s,logRetentionDays:M}),(0,X.jsx)(Se,{isDrawerOpen:o,setIsDrawerOpen:s,selectedLog:i,profileId:e,isMobile:r,onQuickAction:t}),(0,X.jsx)(ae,{isOpen:V,onClose:()=>H(!1),recoveryKeyInput:ne,setRecoveryKeyInput:U,recoveryError:W,unlocking:B,onSubmit:le}),(0,X.jsx)(ie,{rotatedKey:K,onClose:()=>q(null),copiedKey:J,onCopyKey:se})]})};export{Re as LogsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{Ct as t,Et as n,It as r,Ot as i,V as a,_t as o,it as s,k as c,nn as l,w as u,wt as d}from"./vendor-react-DYK5a2J9.js";import{S as f,b as p}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as m,H as h,N as g,O as _,P as v,S as y,T as b,V as x,b as S,d as C,f as w,p as T,r as E,u as D,x as O,y as k}from"./vendor-ui-core-C4974KNo.js";import{_t as A}from"./vendor-utils-Bab4qB3W.js";import{Dt as j,H as M,_t as N,h as P,hn as F,lt as I,nt as L,pt as R}from"./index-DEIEgGUw.js";var z=e(f(),1),B=e(p(),1);const V=({newRule:e,setNewRule:t,addRule:n,loading:r})=>{let{t:i}=l();return(0,B.jsx)(O,{elevation:h.ONE,className:`mb-8 p-6`,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-col lg:flex-row justify-between gap-4 items-start lg:items-end`,children:[(0,B.jsx)(`div`,{className:`w-full lg:w-48`,children:(0,B.jsx)(T,{label:i(`rules.action`),labelFor:`rule-type`,className:`mb-0`,children:(0,B.jsx)(C,{id:`rule-type`,fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:i(`rules.typeBlock`),value:`BLOCK`},{label:i(`rules.typeAllow`),value:`ALLOW`},{label:i(`rules.typeRedirect`),value:`REDIRECT`}]})})}),(0,B.jsx)(`div`,{className:`flex-1 w-full`,children:(0,B.jsx)(T,{label:i(`rules.pattern`),labelFor:`rule-pattern`,className:`mb-0`,children:(0,B.jsx)(w,{id:`rule-pattern`,size:`large`,placeholder:i(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})}),e.type!==`REDIRECT`&&(0,B.jsx)(T,{label:``,labelFor:``,className:`mb-0`,children:(0,B.jsx)(g,{intent:x.PRIMARY,size:`large`,icon:(0,B.jsx)(a,{size:18}),onClick:n,loading:r,disabled:r,children:i(`rules.addRule`)})})]}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(s,{size:16}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:i(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4`,children:[(0,B.jsx)(T,{label:i(`rules.aRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(w,{placeholder:i(`rules.ipv4Placeholder`),value:e.v_a,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.aaaaRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(w,{placeholder:i(`rules.ipv6Placeholder`),value:e.v_aaaa,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.cnameRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(w,{placeholder:i(`rules.cnamePlaceholder`),value:e.v_cname,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.txtRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(w,{placeholder:i(`rules.txtPlaceholder`),value:e.v_txt,onChange:n=>t({...e,v_txt:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`mt-6 pt-4 border-t border-gray-200 dark:border-gray-700 flex justify-end`,children:(0,B.jsx)(g,{intent:x.PRIMARY,large:!0,icon:(0,B.jsx)(a,{size:18}),onClick:n,text:i(`rules.saveRedirectRule`),loading:r,disabled:r})})]})]})})},H=({rules:e,startEdit:r,getBlockDetail:a})=>{let{t:s}=l(),[u,f]=(0,z.useState)(`created_at`),[p,m]=(0,z.useState)(`desc`),h=e=>{u===e?m(e=>e===`asc`?`desc`:`asc`):(f(e),m(e===`created_at`?`desc`:`asc`))},g=e=>e.type===`REDIRECT`?[e.v_a,e.v_aaaa,e.v_cname,e.v_txt].filter(Boolean).join(` `):e.type===`BLOCK`?a():s(`rules.detailAllow`,`Forward to upstream`),_=(0,z.useMemo)(()=>[...e].sort((e,t)=>{let n=0;switch(u){case`action`:n=e.type.localeCompare(t.type);break;case`pattern`:n=e.pattern.localeCompare(t.pattern);break;case`details`:n=g(e).localeCompare(g(t));break;case`created_at`:n=(e.created_at??e.id)-(t.created_at??t.id);break}return n===0&&(n=e.id-t.id),p===`asc`?n:-n}),[e,u,p,a,s]),v=[{key:`action`,header:s(`rules.tableAction`),headerClassName:`w-32`,render:e=>(0,B.jsxs)(B.Fragment,{children:[e.type===`BLOCK`&&(0,B.jsx)(E,{intent:x.DANGER,minimal:!0,icon:(0,B.jsx)(c,{size:12,className:`mr-1`}),children:s(`rules.labelBlock`)}),e.type===`ALLOW`&&(0,B.jsx)(E,{intent:x.SUCCESS,minimal:!0,icon:(0,B.jsx)(o,{size:12,className:`mr-1`}),children:s(`rules.labelAllow`)}),e.type===`REDIRECT`&&(0,B.jsx)(E,{intent:x.WARNING,minimal:!0,icon:(0,B.jsx)(n,{size:12,className:`mr-1`}),children:s(`rules.labelRedirect`)})]})},{key:`pattern`,header:s(`rules.tablePattern`),headerClassName:`w-1/4`,cellClassName:`font-mono font-bold`,render:e=>(0,B.jsx)(`span`,{children:e.pattern})},{key:`details`,header:s(`rules.tableDetails`),cellClassName:`py-2`,render:e=>(0,B.jsx)(B.Fragment,{children:e.type===`REDIRECT`?(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.v_a&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`A: `,e.v_a]}),e.v_aaaa&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`AAAA: `,e.v_aaaa]}),e.v_cname&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`CNAME: `,e.v_cname]}),e.v_txt&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`TXT: `,e.v_txt]})]}):e.type===`BLOCK`?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:s(`rules.detailBlock`)}),(0,B.jsx)(E,{minimal:!0,round:!0,className:`text-[9px] px-1.5 opacity-70`,children:a()})]}):(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:s(`rules.detailAllow`)})})},{key:`created_at`,header:s(`rules.tableCreatedAt`,`添加时间`),headerClassName:`w-44`,cellClassName:`text-xs text-gray-500 align-middle`,render:e=>e.created_at?P(new Date(e.created_at*1e3)):`—`}];return(0,B.jsx)(`div`,{className:`w-full max-w-full overflow-x-auto pb-4`,children:(0,B.jsxs)(D,{interactive:!0,striped:!0,className:`w-full min-w-max whitespace-nowrap`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsx)(`tr`,{children:v.map(e=>(0,B.jsx)(`th`,{onClick:()=>h(e.key),className:A(e.headerClassName,`cursor-pointer select-none transition-colors hover:text-blue-500`),title:s(`rules.clickToSort`,`点击排序`),children:(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{children:e.header}),u===e.key?p===`asc`?(0,B.jsx)(t,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(i,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(d,{size:12,className:`opacity-30 hover:opacity-75 shrink-0`})]})},e.key))})}),(0,B.jsx)(`tbody`,{children:_.map(e=>(0,B.jsx)(`tr`,{onClick:()=>r(e),className:`cursor-pointer`,children:v.map(t=>(0,B.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id))})]})})},U=({editRule:e,setEditRule:t,saveEditRule:n,cancelEdit:r,deleteRule:i,isSaving:a,isDeleting:o})=>{let{t:c}=l();return(0,B.jsxs)(_,{isOpen:!!e,onClose:r,title:c(`rules.editRule`,`Edit Rule`),style:{width:`600px`},children:[(0,B.jsx)(S,{children:e&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(T,{label:c(`rules.action`),className:`w-40 mb-0`,children:(0,B.jsx)(C,{fill:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:c(`rules.typeBlock`),value:`BLOCK`},{label:c(`rules.typeAllow`),value:`ALLOW`},{label:c(`rules.typeRedirect`),value:`REDIRECT`}]})}),(0,B.jsx)(T,{label:c(`rules.pattern`),className:`flex-1 mb-0`,children:(0,B.jsx)(w,{placeholder:c(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c(`rules.wildcardDisclaimer`)}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(s,{size:14}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:c(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,B.jsx)(T,{label:c(`rules.aRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:c(`rules.ipv4Placeholder`),value:e.v_a||``,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.aaaaRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:c(`rules.ipv6Placeholder`),value:e.v_aaaa||``,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.cnameRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:c(`rules.cnamePlaceholder`),value:e.v_cname||``,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.txtRecord`),className:`mb-0`,children:(0,B.jsx)(w,{placeholder:c(`rules.txtPlaceholder`),value:e.v_txt||``,onChange:n=>t({...e,v_txt:n.target.value})})})]})]})]})}),(0,B.jsx)(k,{actions:(0,B.jsxs)(`div`,{className:`flex gap-2`,children:[(0,B.jsx)(g,{onClick:r,disabled:a||o,children:c(`rules.cancel`,`Cancel`)}),(0,B.jsx)(g,{intent:x.PRIMARY,onClick:n,loading:a,disabled:a||o,children:c(`rules.saveChanges`,`Save Changes`)})]}),children:(0,B.jsx)(g,{icon:(0,B.jsx)(u,{size:14}),intent:x.DANGER,text:c(`rules.delete`,`Delete`),onClick:()=>{e&&i(e.id)},loading:o,disabled:a||o})})]})},W=({profileId:e,prefill:t,onPrefillUsed:n,toasterRef:i})=>{let a=r(),[o,s]=(0,z.useState)([]),[c,u]=(0,z.useState)(null),[d,f]=(0,z.useState)(!0),[p,h]=(0,z.useState)(!1),[_,S]=(0,z.useState)(!1),[C,w]=(0,z.useState)(!1),{t:T}=l(),D=F(),[O,k]=(0,z.useState)({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),[P,W]=(0,z.useState)(null),[G,K]=(0,z.useState)(`www.okx.com`),[q,J]=(0,z.useState)(!1);(0,z.useEffect)(()=>{M().then(e=>{e.substituteDomain&&K(e.substituteDomain)}).catch(e=>console.warn(`Failed to fetch clientInfo for substituteDomain:`,e))},[]);let Y=(0,z.useMemo)(()=>{let e=window.location.hostname.trim().toLowerCase();return e?o.some(t=>{if(t.type!==`REDIRECT`)return!1;let n=t.pattern.trim().toLowerCase();return n===e||n===`*.${e}`}):!1},[o]),X=()=>{J(!1),k({type:`REDIRECT`,pattern:window.location.hostname,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:G||`www.okx.com`}),setTimeout(()=>{document.getElementById(`rule-pattern`)?.focus()},100)};(0,z.useEffect)(()=>{t&&(k({type:t.type,pattern:t.domain,include_subdomains:!1,v_a:t.recordType===`A`?`0.0.0.0`:``,v_aaaa:t.recordType===`AAAA`?`::`:``,v_txt:t.recordType===`TXT`?`Pre-filled`:``,v_cname:t.recordType===`CNAME`?`target.com`:``}),n?.())},[t,n]);let Z=async()=>{f(!0);try{let[t,n]=await Promise.all([N(e),R(e)]);s(t),u(JSON.parse(n.settings||`{}`))}catch(e){console.error(`Failed to fetch data`,e)}finally{f(!1)}};return(0,z.useEffect)(()=>{Z()},[e]),(0,B.jsxs)(`div`,{className:A(`md:px-8 w-full min-w-0 max-w-5xl mx-auto`,D?`p-1`:`px-8`),children:[(0,B.jsx)(`div`,{className:`mb-8`,children:(0,B.jsxs)(`div`,{className:`flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,B.jsxs)(`div`,{className:`w-full md:w-auto flex-1`,children:[D?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(m,{minimal:!0,fill:D,className:`flex-1`,children:[(0,B.jsx)(g,{active:!0,onClick:()=>a(`/dash/${e}/rules`),text:T(`rules.title`),large:!0}),(0,B.jsx)(g,{active:!1,onClick:()=>a(`/dash/${e}/filter`),text:T(`filtering.title`),large:!0})]}),d&&(0,B.jsx)(v,{size:16})]}):(0,B.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,B.jsx)(`h1`,{className:`bp6-heading m-0`,children:T(`rules.title`)}),d&&(0,B.jsx)(v,{size:20})]}),(0,B.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:T(`rules.subtitle`)})]}),!d&&!Y&&(0,B.jsx)(`div`,{className:`flex items-center gap-3 self-start md:self-auto`,children:(0,B.jsx)(b,{isOpen:q,onInteraction:J,placement:`bottom-end`,portalClassName:`z-20000`,content:(0,B.jsxs)(`div`,{className:`p-4 w-72 sm:w-80 space-y-3 text-sm`,children:[(0,B.jsx)(`p`,{className:`text-xs text-gray-700 dark:text-gray-300 leading-relaxed m-0`,children:T(`rules.addSelfRedirectPrompt`,`是否增加指向本站的 CNAME 规则,用于地区网络优化(中国大陆用户推荐)?`)}),(0,B.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,B.jsx)(g,{size:`small`,variant:`minimal`,text:T(`common.no`,`否`),onClick:()=>J(!1)}),(0,B.jsx)(g,{size:`small`,intent:x.PRIMARY,text:T(`common.yes`,`是`),onClick:X})]})]}),children:(0,B.jsx)(E,{minimal:!0,interactive:!0,intent:x.PRIMARY,className:`cursor-pointer select-none font-medium`,children:T(`rules.addSelfRedirectTag`,`增加本站重定向?`)})})})]})}),(0,B.jsx)(y,{intent:x.PRIMARY,icon:`info-sign`,className:`mb-6`,children:(0,B.jsx)(`p`,{children:T(`rules.wildcardDisclaimer`,`若要匹配子域名,需使用通配符 *.example.com ,example.com 不会匹配子域名。`)})}),(0,B.jsx)(V,{newRule:O,setNewRule:k,addRule:async()=>{let t=O.pattern.trim();if(!t){i?.current?.show({message:T(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:x.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:T(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:x.DANGER});return}h(!0);try{await L(e,{...O,pattern:t,include_subdomains:0}),i?.current?.show({message:T(`rules.addSuccess`,`Rule added successfully`),intent:x.SUCCESS}),k({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),await Z()}catch(e){i?.current?.show({message:e.message||T(`rules.addFailed`,`Failed to add rule`),intent:x.DANGER})}finally{h(!1)}},loading:p}),d&&o.length===0?(0,B.jsxs)(`div`,{className:`p-16 flex flex-col justify-center items-center gap-3`,children:[(0,B.jsx)(v,{size:32}),(0,B.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 font-medium`,children:T(`common.loading`,`加载中...`)})]}):o.length===0?(0,B.jsx)(y,{title:T(`rules.noRulesTitle`),children:T(`rules.noRulesDesc`)}):(0,B.jsxs)(`div`,{className:`relative`,children:[d&&(0,B.jsx)(`div`,{className:`absolute inset-0 bg-white/40 dark:bg-gray-900/40 backdrop-blur-xs flex items-center justify-center z-10 rounded-lg`,children:(0,B.jsx)(v,{size:32})}),(0,B.jsx)(H,{rules:o,startEdit:e=>{W({...e,include_subdomains:e.include_subdomains===1||e.include_subdomains===!0})},getBlockDetail:()=>{if(!c)return T(`rules.detailBlock`);switch(c.block_mode||`NULL_IP`){case`NXDOMAIN`:return`NXDOMAIN`;case`NODATA`:return`NODATA`;case`CUSTOM_IP`:return`${c.custom_block_ipv4||`0.0.0.0`} / ${c.custom_block_ipv6||`::`}`;default:return`0.0.0.0 / ::`}}})]}),(0,B.jsx)(U,{editRule:P,setEditRule:W,saveEditRule:async()=>{if(!P)return;let t=P.pattern.trim();if(!t){i?.current?.show({message:T(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:x.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.id!==P.id&&e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:T(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:x.DANGER});return}S(!0);try{await j(e,{...P,pattern:t,include_subdomains:0}),i?.current?.show({message:T(`rules.updateSuccess`,`Rule updated successfully`),intent:x.SUCCESS}),W(null),await Z()}catch(e){i?.current?.show({message:e.message||T(`rules.updateFailed`,`Failed to update rule`),intent:x.DANGER})}finally{S(!1)}},cancelEdit:()=>{W(null)},deleteRule:async t=>{w(!0);try{await I(e,t)}catch(e){console.error(e)}finally{w(!1)}W(null),await Z()},isSaving:_,isDeleting:C})]})};export{W as RulesView};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{Ct as t,Et as n,It as r,Ot as i,V as a,_t as o,it as s,k as c,nn as l,w as u,wt as d}from"./vendor-react-DYK5a2J9.js";import{S as f,b as p}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as m,E as h,F as g,H as _,P as v,S as y,U as b,b as x,d as S,f as C,k as w,p as T,r as E,u as D,w as O,y as k}from"./vendor-ui-core-CodM8CpF.js";import{_t as A}from"./vendor-utils-Bab4qB3W.js";import{H as j,Ot as M,gn as N,h as P,mt as F,nt as I,ut as L,vt as R}from"./index-Bw8TL1xo.js";var z=e(f(),1),B=e(p(),1);const V=({newRule:e,setNewRule:t,addRule:n,loading:r})=>{let{t:i}=l();return(0,B.jsx)(y,{elevation:b.ONE,className:`mb-8 p-6`,children:(0,B.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-col lg:flex-row justify-between gap-4 items-start lg:items-end`,children:[(0,B.jsx)(`div`,{className:`w-full lg:w-48`,children:(0,B.jsx)(T,{label:i(`rules.action`),labelFor:`rule-type`,className:`mb-0`,children:(0,B.jsx)(S,{id:`rule-type`,fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:i(`rules.typeBlock`),value:`BLOCK`},{label:i(`rules.typeAllow`),value:`ALLOW`},{label:i(`rules.typeRedirect`),value:`REDIRECT`}]})})}),(0,B.jsx)(`div`,{className:`flex-1 w-full`,children:(0,B.jsx)(T,{label:i(`rules.pattern`),labelFor:`rule-pattern`,className:`mb-0`,children:(0,B.jsx)(C,{id:`rule-pattern`,size:`large`,placeholder:i(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})}),e.type!==`REDIRECT`&&(0,B.jsx)(T,{label:``,labelFor:``,className:`mb-0`,children:(0,B.jsx)(v,{intent:_.PRIMARY,size:`large`,icon:(0,B.jsx)(a,{size:18}),onClick:n,loading:r,disabled:r,children:i(`rules.addRule`)})})]}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(s,{size:16}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:i(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4`,children:[(0,B.jsx)(T,{label:i(`rules.aRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.ipv4Placeholder`),value:e.v_a,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.aaaaRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.ipv6Placeholder`),value:e.v_aaaa,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.cnameRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.cnamePlaceholder`),value:e.v_cname,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:i(`rules.txtRecord`),labelInfo:i(`rules.optional`),children:(0,B.jsx)(C,{placeholder:i(`rules.txtPlaceholder`),value:e.v_txt,onChange:n=>t({...e,v_txt:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`mt-6 pt-4 border-t border-gray-200 dark:border-gray-700 flex justify-end`,children:(0,B.jsx)(v,{intent:_.PRIMARY,large:!0,icon:(0,B.jsx)(a,{size:18}),onClick:n,text:i(`rules.saveRedirectRule`),loading:r,disabled:r})})]})]})})},H=({rules:e,startEdit:r,getBlockDetail:a})=>{let{t:s}=l(),[u,f]=(0,z.useState)(`created_at`),[p,m]=(0,z.useState)(`desc`),h=e=>{u===e?m(e=>e===`asc`?`desc`:`asc`):(f(e),m(e===`created_at`?`desc`:`asc`))},g=e=>e.type===`REDIRECT`?[e.v_a,e.v_aaaa,e.v_cname,e.v_txt].filter(Boolean).join(` `):e.type===`BLOCK`?a():s(`rules.detailAllow`,`Forward to upstream`),v=(0,z.useMemo)(()=>[...e].sort((e,t)=>{let n=0;switch(u){case`action`:n=e.type.localeCompare(t.type);break;case`pattern`:n=e.pattern.localeCompare(t.pattern);break;case`details`:n=g(e).localeCompare(g(t));break;case`created_at`:n=(e.created_at??e.id)-(t.created_at??t.id);break}return n===0&&(n=e.id-t.id),p===`asc`?n:-n}),[e,u,p,a,s]),y=[{key:`action`,header:s(`rules.tableAction`),headerClassName:`w-32`,render:e=>(0,B.jsxs)(B.Fragment,{children:[e.type===`BLOCK`&&(0,B.jsx)(E,{intent:_.DANGER,minimal:!0,icon:(0,B.jsx)(c,{size:12,className:`mr-1`}),children:s(`rules.labelBlock`)}),e.type===`ALLOW`&&(0,B.jsx)(E,{intent:_.SUCCESS,minimal:!0,icon:(0,B.jsx)(o,{size:12,className:`mr-1`}),children:s(`rules.labelAllow`)}),e.type===`REDIRECT`&&(0,B.jsx)(E,{intent:_.WARNING,minimal:!0,icon:(0,B.jsx)(n,{size:12,className:`mr-1`}),children:s(`rules.labelRedirect`)})]})},{key:`pattern`,header:s(`rules.tablePattern`),headerClassName:`w-1/4`,cellClassName:`font-mono font-bold`,render:e=>(0,B.jsx)(`span`,{children:e.pattern})},{key:`details`,header:s(`rules.tableDetails`),cellClassName:`py-2`,render:e=>(0,B.jsx)(B.Fragment,{children:e.type===`REDIRECT`?(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.v_a&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`A: `,e.v_a]}),e.v_aaaa&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`AAAA: `,e.v_aaaa]}),e.v_cname&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`CNAME: `,e.v_cname]}),e.v_txt&&(0,B.jsxs)(E,{minimal:!0,className:`font-mono text-[10px]`,children:[`TXT: `,e.v_txt]})]}):e.type===`BLOCK`?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:s(`rules.detailBlock`)}),(0,B.jsx)(E,{minimal:!0,round:!0,className:`text-[9px] px-1.5 opacity-70`,children:a()})]}):(0,B.jsx)(`span`,{className:`text-gray-400 text-xs italic`,children:s(`rules.detailAllow`)})})},{key:`created_at`,header:s(`rules.tableCreatedAt`,`添加时间`),headerClassName:`w-44`,cellClassName:`text-xs text-gray-500 align-middle`,render:e=>e.created_at?P(new Date(e.created_at*1e3)):`—`}];return(0,B.jsx)(`div`,{className:`w-full max-w-full overflow-x-auto pb-4`,children:(0,B.jsxs)(D,{interactive:!0,striped:!0,className:`w-full min-w-max whitespace-nowrap`,children:[(0,B.jsx)(`thead`,{children:(0,B.jsx)(`tr`,{children:y.map(e=>(0,B.jsx)(`th`,{onClick:()=>h(e.key),className:A(e.headerClassName,`cursor-pointer select-none transition-colors hover:text-blue-500`),title:s(`rules.clickToSort`,`点击排序`),children:(0,B.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{children:e.header}),u===e.key?p===`asc`?(0,B.jsx)(t,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(i,{size:13,className:`text-blue-500 shrink-0`}):(0,B.jsx)(d,{size:12,className:`opacity-30 hover:opacity-75 shrink-0`})]})},e.key))})}),(0,B.jsx)(`tbody`,{children:v.map(e=>(0,B.jsx)(`tr`,{onClick:()=>r(e),className:`cursor-pointer`,children:y.map(t=>(0,B.jsx)(`td`,{className:t.cellClassName,children:t.render(e)},t.key))},e.id))})]})})},U=({editRule:e,setEditRule:t,saveEditRule:n,cancelEdit:r,deleteRule:i,isSaving:a,isDeleting:o})=>{let{t:c}=l();return(0,B.jsxs)(w,{isOpen:!!e,onClose:r,title:c(`rules.editRule`,`Edit Rule`),style:{width:`600px`},children:[(0,B.jsx)(x,{children:e&&(0,B.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(T,{label:c(`rules.action`),className:`w-40 mb-0`,children:(0,B.jsx)(S,{fill:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),options:[{label:c(`rules.typeBlock`),value:`BLOCK`},{label:c(`rules.typeAllow`),value:`ALLOW`},{label:c(`rules.typeRedirect`),value:`REDIRECT`}]})}),(0,B.jsx)(T,{label:c(`rules.pattern`),className:`flex-1 mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.patternPlaceholder`),value:e.pattern,onChange:n=>t({...e,pattern:n.target.value})})})]}),(0,B.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c(`rules.wildcardDisclaimer`)}),e.type===`REDIRECT`&&(0,B.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-blue-600 dark:text-blue-400`,children:[(0,B.jsx)(s,{size:14}),(0,B.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider`,children:c(`rules.redirectSettings`)})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,B.jsx)(T,{label:c(`rules.aRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.ipv4Placeholder`),value:e.v_a||``,onChange:n=>t({...e,v_a:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.aaaaRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.ipv6Placeholder`),value:e.v_aaaa||``,onChange:n=>t({...e,v_aaaa:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.cnameRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.cnamePlaceholder`),value:e.v_cname||``,onChange:n=>t({...e,v_cname:n.target.value})})}),(0,B.jsx)(T,{label:c(`rules.txtRecord`),className:`mb-0`,children:(0,B.jsx)(C,{placeholder:c(`rules.txtPlaceholder`),value:e.v_txt||``,onChange:n=>t({...e,v_txt:n.target.value})})})]})]})]})}),(0,B.jsx)(k,{actions:(0,B.jsxs)(`div`,{className:`flex gap-2`,children:[(0,B.jsx)(v,{onClick:r,disabled:a||o,children:c(`rules.cancel`,`Cancel`)}),(0,B.jsx)(v,{intent:_.PRIMARY,onClick:n,loading:a,disabled:a||o,children:c(`rules.saveChanges`,`Save Changes`)})]}),children:(0,B.jsx)(v,{icon:(0,B.jsx)(u,{size:14}),intent:_.DANGER,text:c(`rules.delete`,`Delete`),onClick:()=>{e&&i(e.id)},loading:o,disabled:a||o})})]})},W=({profileId:e,prefill:t,onPrefillUsed:n,toasterRef:i})=>{let a=r(),[o,s]=(0,z.useState)([]),[c,u]=(0,z.useState)(null),[d,f]=(0,z.useState)(!0),[p,y]=(0,z.useState)(!1),[b,x]=(0,z.useState)(!1),[S,C]=(0,z.useState)(!1),{t:w}=l(),T=N(),[D,k]=(0,z.useState)({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),[P,W]=(0,z.useState)(null),[G,K]=(0,z.useState)(`www.okx.com`),[q,J]=(0,z.useState)(!1);(0,z.useEffect)(()=>{j().then(e=>{e.substituteDomain&&K(e.substituteDomain)}).catch(e=>console.warn(`Failed to fetch clientInfo for substituteDomain:`,e))},[]);let Y=(0,z.useMemo)(()=>{let e=window.location.hostname.trim().toLowerCase();return e?o.some(t=>{if(t.type!==`REDIRECT`)return!1;let n=t.pattern.trim().toLowerCase();return n===e||n===`*.${e}`}):!1},[o]),X=()=>{J(!1),k({type:`REDIRECT`,pattern:window.location.hostname,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:G||`www.okx.com`}),setTimeout(()=>{document.getElementById(`rule-pattern`)?.focus()},100)};(0,z.useEffect)(()=>{t&&(k({type:t.type,pattern:t.domain,include_subdomains:!1,v_a:t.recordType===`A`?`0.0.0.0`:``,v_aaaa:t.recordType===`AAAA`?`::`:``,v_txt:t.recordType===`TXT`?`Pre-filled`:``,v_cname:t.recordType===`CNAME`?`target.com`:``}),n?.())},[t,n]);let Z=async()=>{f(!0);try{let[t,n]=await Promise.all([R(e),F(e)]);s(t),u(JSON.parse(n.settings||`{}`))}catch(e){console.error(`Failed to fetch data`,e)}finally{f(!1)}};return(0,z.useEffect)(()=>{Z()},[e]),(0,B.jsxs)(`div`,{className:A(`md:px-8 w-full min-w-0 max-w-5xl mx-auto`,T?`p-1`:`px-8`),children:[(0,B.jsx)(`div`,{className:`mb-8`,children:(0,B.jsxs)(`div`,{className:`flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,B.jsxs)(`div`,{className:`w-full md:w-auto flex-1`,children:[T?(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsxs)(O,{minimal:!0,fill:T,className:`flex-1`,children:[(0,B.jsx)(v,{active:!0,onClick:()=>a(`/dash/${e}/rules`),text:w(`rules.title`),large:!0}),(0,B.jsx)(v,{active:!1,onClick:()=>a(`/dash/${e}/filter`),text:w(`filtering.title`),large:!0})]}),d&&(0,B.jsx)(g,{size:16})]}):(0,B.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,B.jsx)(`h1`,{className:`bp6-heading m-0`,children:w(`rules.title`)}),d&&(0,B.jsx)(g,{size:20})]}),(0,B.jsx)(`p`,{className:`bp6-text-muted mt-2!`,children:w(`rules.subtitle`)})]}),!d&&!Y&&(0,B.jsx)(`div`,{className:`flex items-center gap-3 self-start md:self-auto`,children:(0,B.jsx)(h,{isOpen:q,onInteraction:J,placement:`bottom-end`,portalClassName:`z-20000`,content:(0,B.jsxs)(`div`,{className:`p-4 w-72 sm:w-80 space-y-3 text-sm`,children:[(0,B.jsx)(`p`,{className:`text-xs text-gray-700 dark:text-gray-300 leading-relaxed m-0`,children:w(`rules.addSelfRedirectPrompt`,`是否增加指向本站的 CNAME 规则,用于地区网络优化(中国大陆用户推荐)?`)}),(0,B.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,B.jsx)(v,{size:`small`,variant:`minimal`,text:w(`common.no`,`否`),onClick:()=>J(!1)}),(0,B.jsx)(v,{size:`small`,intent:_.PRIMARY,text:w(`common.yes`,`是`),onClick:X})]})]}),children:(0,B.jsx)(E,{minimal:!0,interactive:!0,intent:_.PRIMARY,className:`cursor-pointer select-none font-medium`,children:w(`rules.addSelfRedirectTag`,`增加本站重定向?`)})})})]})}),(0,B.jsx)(m,{intent:_.PRIMARY,icon:`info-sign`,className:`mb-6`,children:(0,B.jsx)(`p`,{children:w(`rules.wildcardDisclaimer`,`若要匹配子域名,需使用通配符 *.example.com ,example.com 不会匹配子域名。`)})}),(0,B.jsx)(V,{newRule:D,setNewRule:k,addRule:async()=>{let t=D.pattern.trim();if(!t){i?.current?.show({message:w(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:_.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:w(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:_.DANGER});return}y(!0);try{await I(e,{...D,pattern:t,include_subdomains:0}),i?.current?.show({message:w(`rules.addSuccess`,`Rule added successfully`),intent:_.SUCCESS}),k({type:`BLOCK`,pattern:``,include_subdomains:!1,v_a:``,v_aaaa:``,v_txt:``,v_cname:``}),await Z()}catch(e){i?.current?.show({message:e.message||w(`rules.addFailed`,`Failed to add rule`),intent:_.DANGER})}finally{y(!1)}},loading:p}),d&&o.length===0?(0,B.jsxs)(`div`,{className:`p-16 flex flex-col justify-center items-center gap-3`,children:[(0,B.jsx)(g,{size:32}),(0,B.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 font-medium`,children:w(`common.loading`,`加载中...`)})]}):o.length===0?(0,B.jsx)(m,{title:w(`rules.noRulesTitle`),children:w(`rules.noRulesDesc`)}):(0,B.jsxs)(`div`,{className:`relative`,children:[d&&(0,B.jsx)(`div`,{className:`absolute inset-0 bg-white/40 dark:bg-gray-900/40 backdrop-blur-xs flex items-center justify-center z-10 rounded-lg`,children:(0,B.jsx)(g,{size:32})}),(0,B.jsx)(H,{rules:o,startEdit:e=>{W({...e,include_subdomains:e.include_subdomains===1||e.include_subdomains===!0})},getBlockDetail:()=>{if(!c)return w(`rules.detailBlock`);switch(c.block_mode||`NULL_IP`){case`NXDOMAIN`:return`NXDOMAIN`;case`NODATA`:return`NODATA`;case`CUSTOM_IP`:return`${c.custom_block_ipv4||`0.0.0.0`} / ${c.custom_block_ipv6||`::`}`;default:return`0.0.0.0 / ::`}}})]}),(0,B.jsx)(U,{editRule:P,setEditRule:W,saveEditRule:async()=>{if(!P)return;let t=P.pattern.trim();if(!t){i?.current?.show({message:w(`rules.patternEmpty`,`Domain pattern cannot be empty`),intent:_.DANGER});return}let n=t.toLowerCase();if(o.some(e=>e.id!==P.id&&e.pattern.trim().toLowerCase()===n)){i?.current?.show({message:w(`rules.duplicatePattern`,`Rule for this domain already exists`),intent:_.DANGER});return}x(!0);try{await M(e,{...P,pattern:t,include_subdomains:0}),i?.current?.show({message:w(`rules.updateSuccess`,`Rule updated successfully`),intent:_.SUCCESS}),W(null),await Z()}catch(e){i?.current?.show({message:e.message||w(`rules.updateFailed`,`Failed to update rule`),intent:_.DANGER})}finally{x(!1)}},cancelEdit:()=>{W(null)},deleteRule:async t=>{C(!0);try{await L(e,t)}catch(e){console.error(e)}finally{C(!1)}W(null),await Z()},isSaving:b,isDeleting:S})]})};export{W as RulesView};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{$ as t,At as n,O as r,P as i,U as a,X as o,bt as s,ct as c,it as l,lt as u,mt as d,nn as f,rt as p,ut as m,v as h,w as g,y as _,yt as v}from"./vendor-react-DYK5a2J9.js";import{S as y,b}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as x,D as S,E as C,F as ee,H as w,M as T,N as E,O as D,P as O,S as k,T as A,U as j,V as M,_ as N,d as P,f as F,h as I,p as L,r as R,v as z,x as te}from"./vendor-ui-core-CodM8CpF.js";import{_t as ne}from"./vendor-utils-Bab4qB3W.js";import{Et as re,G as B,at as V,c as H,ht as U,kt as W,mt as G,q as K,vt as q,w as J,xt as Y}from"./index-Bw8TL1xo.js";import{t as X}from"./async-R_IFRE5c.js";var Z=e(y(),1),Q=e(b(),1);const ie=({profile:e,isEditingName:t,setIsEditingName:n,editName:r,setEditName:i,updateProfileName:o,exportProfile:c})=>{let{t:l}=f(),[d,p]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`mb-6 flex flex-col md:flex-row justify-between items-start md:items-center gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col justify-start`,children:[t?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsx)(z,{content:l(`common.profileNameFormatTip`,`Profile Name tip: 1-30 characters, duplicates not allowed`),isOpen:d,position:M.TOP,intent:w.PRIMARY,className:`flex-1`,children:(0,Q.jsx)(`div`,{className:`w-full block`,children:(0,Q.jsx)(F,{value:r,onChange:e=>i(e.target.value),onFocus:()=>p(!0),onBlur:()=>p(!1),autoFocus:!0,onKeyDown:t=>{t.key===`Enter`&&o(),t.key===`Escape`&&(n(!1),i(e?.name||``))}})})}),(0,Q.jsx)(O,{icon:(0,Q.jsx)(s,{size:16}),intent:w.SUCCESS,minimal:!0,onClick:o,disabled:!H.test(r)}),(0,Q.jsx)(O,{icon:(0,Q.jsx)(_,{size:16}),minimal:!0,onClick:()=>{n(!1),i(e?.name||``)}})]}):(0,Q.jsxs)(`div`,{className:`group flex items-center gap-2 mb-1 cursor-pointer`,onClick:()=>n(!0),children:[(0,Q.jsx)(`h2`,{className:`bp6-heading mb-0`,children:e?.name}),(0,Q.jsx)(O,{icon:(0,Q.jsx)(a,{size:14}),minimal:!0,className:`opacity-30 group-hover:opacity-100 transition-opacity`})]}),(0,Q.jsx)(`p`,{className:`bp6-text-muted`,children:l(`settings.subtitle`)})]}),(0,Q.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,Q.jsx)(O,{size:`large`,icon:(0,Q.jsx)(u,{size:18}),text:l(`settings.export`,`导出配置`),onClick:c})})]})},ae=()=>{let{t:e}=f(),[t,n]=(0,Z.useState)([]);return(0,Z.useEffect)(()=>{K().then(t=>{t&&Array.isArray(t)&&n(t.map(t=>({label:e(t.label),url:t.url})))}).catch(e=>console.warn(`Failed to fetch preset upstreams from API`,e))},[e]),t},oe=(e,t)=>{let{t:n}=f();return(0,Z.useMemo)(()=>{let e=t>0?t:30,r=n(`settings.retentionMaxSuffix`,`(最长)`),i=[{label:n(`settings.retentionDisabled`,`关闭 (隐私需要)`),value:0},{label:n(`settings.retention10m`,`10 分钟`),value:.007},{label:n(`settings.retention1h`,`1 小时`),value:.0416},{label:n(`settings.retention24h`,`24 小时`),value:1},{label:n(`settings.retention7d`,`7 天`),value:7},{label:n(`settings.retention30d`,`30 天`),value:30},{label:n(`settings.retention90d`,`90 天`),value:90},{label:n(`settings.retention180d`,`180 天`),value:180},{label:n(`settings.retention360d`,`360 天`),value:360}],a=i.filter(t=>t.value<=e);return e>0&&!a.some(t=>t.value===e)&&(a.push({label:`${e} ${n(`settings.daysUnit`,`天`)}`,value:e}),a.sort((e,t)=>e.value-t.value)),a.length===0?[i[0]]:a.map(t=>t.value===e&&t.value>0?{...t,label:`${t.label} ${r}`}:t)},[n,t])},$=({settings:e,setSettings:t})=>{let{t:n}=f(),r=(0,Q.jsx)(S,{className:`min-w-96`,children:ae().map((n,r)=>(0,Q.jsx)(A,{text:n.label,onClick:()=>t({...e,upstream:[n.url]}),labelElement:(0,Q.jsx)(`div`,{className:`flex flex-col items-end text-right`,children:(0,Q.jsx)(`span`,{className:`text-[9px] opacity-85 max-w-64 truncate`,title:n.url,children:n.url})})},r))});return(0,Q.jsxs)(k,{elevation:j.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Q.jsxs)(E,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Q.jsx)(i,{size:18,className:`text-blue-500`}),` `,n(`settings.upstreamTitle`)]}),(0,Q.jsx)(L,{label:`DoH (https://) / DoT (tls://) / DNS Stamp (sdns://) / ${n(`settings.classicDns`)}`,children:(0,Q.jsx)(F,{fill:!0,placeholder:`https://... | tls://... | sdns://... | 1.1.1.1`,value:e.upstream?.[0]||``,onChange:n=>t({...e,upstream:[n.target.value]}),onFocus:e=>e.target.select(),rightElement:(0,Q.jsx)(C,{content:r,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,Q.jsx)(O,{variant:`minimal`,icon:`chevron-down`})})})}),(0,Q.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.upstreamDesc`)})]})},se=({settings:e,setSettings:t})=>{let{t:n}=f();return(0,Q.jsxs)(k,{elevation:j.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Q.jsxs)(E,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Q.jsx)(r,{size:18,className:`text-green-500`}),` `,n(`settings.defaultPolicyTitle`)]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(L,{label:n(`settings.onNoMatch`),children:(0,Q.jsxs)(P,{fill:!0,value:e.default_policy,onChange:n=>t({...e,default_policy:n.target.value}),children:[(0,Q.jsx)(`option`,{value:`ALLOW`,children:n(`settings.allowAll`)}),(0,Q.jsx)(`option`,{value:`BLOCK`,children:n(`settings.blockAll`)})]})}),(0,Q.jsx)(N,{}),(0,Q.jsx)(L,{label:n(`settings.blockModeTitle`),helperText:n(`settings.blockModeDesc`),children:(0,Q.jsxs)(P,{fill:!0,value:e.block_mode||`NULL_IP`,onChange:n=>t({...e,block_mode:n.target.value}),children:[(0,Q.jsxs)(`option`,{value:`NULL_IP`,children:[`0.0.0.0 / :: (`,n(`settings.default`),`)`]}),(0,Q.jsxs)(`option`,{value:`NXDOMAIN`,children:[`NXDOMAIN (`,n(`settings.NXDOMAIN`),`)`]}),(0,Q.jsxs)(`option`,{value:`NODATA`,children:[`NODATA (`,n(`settings.NODATA`),`)`]}),(0,Q.jsx)(`option`,{value:`CUSTOM_IP`,children:n(`settings.customIP`)})]})}),e.block_mode===`CUSTOM_IP`&&(0,Q.jsxs)(`div`,{className:`space-y-2 animate-in fade-in slide-in-from-top-1`,children:[(0,Q.jsx)(F,{placeholder:`IPv4: 127.0.0.1`,value:e.custom_block_ipv4||``,onChange:n=>t({...e,custom_block_ipv4:n.target.value})}),(0,Q.jsx)(F,{placeholder:`IPv6: ::1`,value:e.custom_block_ipv6||``,onChange:n=>t({...e,custom_block_ipv6:n.target.value})})]})]})]})},ce=({settings:e,setSettings:t,isAdmin:n,maxRetentionDays:r})=>{let{t:i}=f(),a=oe(n,r);Z.useEffect(()=>{if(r>0&&e.log_retention_days>r&&a.length>0){let n=a[a.length-1];n&&e.log_retention_days!==n.value&&t({...e,log_retention_days:n.value})}},[r,e.log_retention_days,a,t]);let o=e.log_retention_days===0;return(0,Q.jsxs)(k,{elevation:j.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Q.jsxs)(E,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Q.jsx)(d,{size:18,className:`text-purple-500`}),` `,i(`settings.logRetentionTitle`)]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(L,{label:i(`settings.retentionDuration`),children:(0,Q.jsx)(P,{fill:!0,value:e.log_retention_days,onChange:n=>t({...e,log_retention_days:parseFloat(n.target.value)}),children:a.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,Q.jsx)(`p`,{className:`text-xs opacity-60`,children:o?i(`settings.retentionDisabledDesc`,`已关闭日志记录。系统将不会记录任何 DNS 查询日志并立即清空历史日志。`):i(`settings.retentionDesc`)}),(0,Q.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80`,children:[(0,Q.jsx)(I,{label:i(`settings.skipLogOnPass`,`不记录放行记录`),checked:!o&&!!e.skip_log_on_pass,disabled:o,onChange:n=>t({...e,skip_log_on_pass:n.currentTarget.checked})}),(0,Q.jsx)(`p`,{className:`text-xs opacity-60 mt-1`,children:i(`settings.skipLogOnPassDesc`,`启用后不记录正常放行的 DNS 查询,仅记录被拦截、重定向或解析失败的记录。可大幅减少存储占用与写操作。`)})]})]})]})},le=({profileId:e,toasterRef:t})=>{let{t:n}=f(),[r,i]=(0,Z.useState)(()=>J.getLocalRetentionDays()),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(!1),[d,h]=(0,Z.useState)(!1),_=(0,Z.useCallback)(async()=>{try{await J.init();let t=await J.getStorageInfo();o(t?.isOpfs??J.getIsOpfs());let n=t.profileStats.find(t=>t.profile_id===e);c(n?n.count:0)}catch(e){console.error(`[LocalRetentionCard] Failed to load storage info:`,e),o(J.getIsOpfs()),c(0)}},[e]);(0,Z.useEffect)(()=>{_()},[_]);let v=e=>{i(e),J.setLocalRetentionDays(e),_()};return(0,Q.jsxs)(k,{elevation:j.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Q.jsxs)(E,{className:`flex items-center gap-2 mb-4 font-bold`,children:[(0,Q.jsx)(m,{size:18,className:`text-cyan-500`}),` `,n(`settings.localRetentionTitle`,`本地存储与留存`)]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(L,{label:n(`settings.localRetentionDuration`,`本地保留时长`),children:(0,Q.jsxs)(P,{fill:!0,value:r,onChange:e=>v(parseInt(e.target.value,10)),children:[(0,Q.jsx)(`option`,{value:30,children:n(`settings.localRetention30d`,`30 天`)}),(0,Q.jsx)(`option`,{value:90,children:n(`settings.localRetention90d`,`90 天 (推荐)`)}),(0,Q.jsx)(`option`,{value:180,children:n(`settings.localRetention180d`,`180 天`)}),(0,Q.jsx)(`option`,{value:365,children:n(`settings.localRetention365d`,`365 天 (1 年)`)}),(0,Q.jsx)(`option`,{value:0,children:n(`settings.localRetentionUnlimited`,`永久保留 (直到手动清除)`)})]})}),(0,Q.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.localRetentionDesc`,`日志将持久化保存在当前浏览器本地的 SQLite 数据库 (OPFS) 中,提供秒级本地搜索并节省云端存储费用。超出此时长的本地日志将自动清除。`)}),(0,Q.jsxs)(`div`,{className:`pt-3 border-t border-gray-100 dark:border-gray-800/80 space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 opacity-70`,children:[(0,Q.jsx)(p,{size:14}),n(`settings.localEngineStorage`,`存储引擎`),`:`]}),(0,Q.jsx)(R,{minimal:!0,intent:a?w.SUCCESS:w.WARNING,className:`text-[11px]`,children:a?n(`settings.localEngineOpfs`,`OPFS 本地持久化`):n(`settings.localEngineMemory`,`内存临时存储 (无痕/私密模式)`)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsxs)(`span`,{className:`opacity-70`,children:[n(`settings.localCachedCount`,`本地已缓存日志`),`:`]}),(0,Q.jsx)(`span`,{className:`font-mono font-medium`,children:s===null?`...`:n(`settings.localCachedCountUnit`,`{{count}} 条记录`,{count:s})})]}),(0,Q.jsx)(`div`,{className:`pt-1 flex justify-end`,children:(0,Q.jsx)(O,{minimal:!0,small:!0,intent:w.DANGER,icon:(0,Q.jsx)(g,{size:13}),text:n(`settings.clearLocalData`,`清空本地日志`),disabled:s===0||s===null||d,onClick:()=>u(!0)})})]})]}),(0,Q.jsx)(D,{isOpen:l,confirmButtonText:n(`common.confirm`,`确认清空`),cancelButtonText:n(`common.cancel`,`取消`),intent:w.DANGER,icon:`trash`,onConfirm:async()=>{h(!0);try{await J.clearProfile(e),c(0),t?.current?.show({message:n(`settings.clearLocalDataSuccess`,`本地日志已成功清空`),intent:w.SUCCESS,icon:`tick`})}catch(e){console.error(`[LocalRetentionCard] Failed to clear local profile logs:`,e),t?.current?.show({message:n(`settings.clearLocalDataError`,`清空本地日志失败`),intent:w.DANGER,icon:`error`})}finally{h(!1),u(!1)}},onCancel:()=>u(!1),loading:d,children:(0,Q.jsx)(`p`,{children:n(`settings.clearLocalDataConfirm`,`确定要清空此配置在本地保存的所有日志吗?(云端日志不受影响)`)})})]})},ue=({settings:e,setSettings:t})=>{let{t:n}=f();return(0,Q.jsxs)(k,{elevation:j.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Q.jsxs)(E,{className:`flex items-center gap-2 mb-3 font-bold`,children:[(0,Q.jsx)(l,{size:18,className:`text-orange-500`}),` `,n(`settings.ecsTitle`)]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(I,{label:n(`settings.sendEcs`),checked:e.ecs.enabled,onChange:n=>t({...e,ecs:{...e.ecs,enabled:n.currentTarget.checked}})}),(0,Q.jsx)(I,{label:n(`settings.customSubnet`),disabled:!e.ecs.enabled,checked:!e.ecs.use_client_ip,onChange:n=>t({...e,ecs:{...e.ecs,use_client_ip:!n.currentTarget.checked}})}),(0,Q.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-gray-100 dark:border-gray-800`,children:[(0,Q.jsx)(L,{label:n(`settings.customIpv4`),labelInfo:n(`settings.ipv4Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,Q.jsx)(F,{placeholder:`0.0.0.0/0`,value:e.ecs.ipv4_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv4_cidr:n.target.value}})})}),(0,Q.jsx)(L,{label:n(`settings.customIpv6`),labelInfo:n(`settings.ipv6Hint`),disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),children:(0,Q.jsx)(F,{placeholder:`::/0`,value:e.ecs.ipv6_cidr||``,disabled:!(e.ecs.enabled&&!e.ecs.use_client_ip),onChange:n=>t({...e,ecs:{...e.ecs,ipv6_cidr:n.target.value}})})})]}),(0,Q.jsx)(`p`,{className:`text-xs opacity-60`,children:n(`settings.ecsUpstreamHint`)})]})]})};var de=[{domain:`cloudflare-ech.com`,isPreferred:!0},{domain:`crypto.cloudflare.com`,isPreferred:!1},{domain:`one.one.one.one`,isPreferred:!1},{domain:`www.cloudflare.com`,isPreferred:!1},{domain:`encryptedsni.com`,isPreferred:!1},{domain:`cdnjs.com`,isPreferred:!1}];const fe=({settings:e,setSettings:n})=>{let{t:r}=f(),[i,a]=Z.useState(de);Z.useEffect(()=>{B().then(e=>{Array.isArray(e)&&e.length>0&&a(e.map(e=>typeof e==`string`?{domain:e,isPreferred:e===`cloudflare-ech.com`}:{domain:e.domain,isPreferred:!!e.isPreferred}))}).catch(e=>console.warn(`Failed to fetch preset ECH fronting domains from API`,e))},[]);let o=typeof e.best_effort_ech==`boolean`?e.best_effort_ech:!!e.best_effort_ech?.enabled,s=typeof e.best_effort_ech==`object`&&e.best_effort_ech?.fronting_domain?e.best_effort_ech.fronting_domain:`cloudflare-ech.com`,l=t=>{n({...e,best_effort_ech:{enabled:t,fronting_domain:s||`cloudflare-ech.com`}})},u=t=>{n({...e,best_effort_ech:{enabled:o,fronting_domain:t}})},d=(0,Q.jsx)(S,{className:`min-w-72`,children:i.map(e=>(0,Q.jsx)(A,{text:e.domain,onClick:()=>u(e.domain),labelElement:e.isPreferred?(0,Q.jsx)(R,{minimal:!0,intent:w.PRIMARY,className:`text-[10px]`,children:r(`settings.echPreferred`,`首选`)}):void 0},e.domain))});return(0,Q.jsxs)(k,{elevation:j.ONE,className:`dark:bg-gray-900 dark:border-gray-800`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Q.jsxs)(E,{className:`flex items-center gap-2 m-0 font-bold text-purple-600 dark:text-purple-400`,children:[(0,Q.jsx)(t,{size:18}),` `,r(`settings.echTitle`)]}),(0,Q.jsx)(C,{placement:`bottom-end`,usePortal:!0,content:(0,Q.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,Q.jsx)(E,{children:r(`settings.whatIsEch`,`何为 ECH (Encrypted Client Hello)?`)}),(0,Q.jsx)(`p`,{className:`text-sm mb-2`,children:r(`settings.echHelpDesc`)}),(0,Q.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,Q.jsx)(`li`,{children:r(`settings.echHelpBenefit1`)}),(0,Q.jsx)(`li`,{children:r(`settings.echHelpBenefit2`)})]}),(0,Q.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,Q.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/Encrypted_Client_Hello`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,Q.jsx)(c,{size:10}),` `,r(`setup.learnMore`,`了解更多`)]})})]}),children:(0,Q.jsx)(O,{icon:`help`,variant:`minimal`,intent:w.NONE})})]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(I,{label:r(`settings.enableEch`,`启用重写 ECH`),checked:o,onChange:e=>l(e.currentTarget.checked)}),(0,Q.jsx)(`p`,{className:`text-xs opacity-60 leading-relaxed`,children:r(`settings.echDesc`,`针对由 Cloudflare 代理的域名,当查询 HTTPS (Type 65) 或 SVCB (Type 64) 记录且上游未配置 ECH 时,自动重写注入 ECH 参数以保护 SNI 隐私。`)}),o&&(0,Q.jsx)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100 dark:border-gray-800`,children:(0,Q.jsx)(L,{label:r(`settings.echFrontingTitle`,`表层 SNI (ECH Fronting)`),labelInfo:(0,Q.jsx)(`span`,{className:`text-xs opacity-60`,children:r(`settings.echFrontingDesc`,`TLS 握手外层可见的伪装域名`)}),children:(0,Q.jsx)(F,{fill:!0,placeholder:r(`settings.echFrontingCustomPlaceholder`,`输入自定义表层域名,例如 crypto.cloudflare.com`),value:s,onChange:e=>u(e.target.value),onFocus:e=>e.target.select(),className:`font-mono text-sm`,rightElement:(0,Q.jsx)(C,{content:d,placement:`bottom-end`,animation:`minimal`,arrow:!1,children:(0,Q.jsx)(O,{variant:`minimal`,icon:`chevron-down`})})})})})]})]})},pe=({testInput:e,setTestInput:t,handleDnsTest:r,testing:i,testResult:a})=>{let{t:s}=f();return(0,Q.jsxs)(k,{elevation:j.TWO,className:`dark:bg-gray-900 border-t-2 border-blue-500`,children:[(0,Q.jsxs)(E,{className:`flex items-center gap-2 mb-6 font-bold`,children:[(0,Q.jsx)(h,{size:20,className:`text-yellow-500 fill-yellow-500`}),` `,s(`settings.testToolTitle`)]}),(0,Q.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,Q.jsx)(L,{label:s(`settings.testDomain`),className:`mb-0`,children:(0,Q.jsx)(F,{fill:!0,large:!0,placeholder:s(`settings.domainPlaceholder`),value:e.domain,onChange:n=>t({...e,domain:n.target.value}),onKeyDown:e=>e.key===`Enter`&&r()})}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-4 items-end`,children:[(0,Q.jsx)(L,{label:s(`settings.recordType`),className:`w-32 mb-0`,children:(0,Q.jsxs)(P,{fill:!0,large:!0,value:e.type,onChange:n=>t({...e,type:n.target.value}),children:[(0,Q.jsx)(`option`,{value:`A`,children:`A`}),(0,Q.jsx)(`option`,{value:`AAAA`,children:`AAAA`}),(0,Q.jsx)(`option`,{value:`CNAME`,children:`CNAME`}),(0,Q.jsx)(`option`,{value:`TXT`,children:`TXT`})]})}),(0,Q.jsx)(L,{label:`\xA0`,className:`mb-0`,children:(0,Q.jsx)(O,{size:`large`,intent:w.PRIMARY,icon:`search`,text:s(`settings.runTest`),onClick:r,loading:i})})]}),a&&(0,Q.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 space-y-6 animate-in fade-in slide-in-from-top-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-4 items-center`,children:[(0,Q.jsx)(R,{large:!0,round:!0,intent:a.action===`PASS`?w.SUCCESS:a.action===`BLOCK`?w.DANGER:w.WARNING,className:`px-4 font-bold`,children:a.action}),(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.hitRule`)}),(0,Q.jsx)(`span`,{className:`text-sm font-bold`,children:a.reason||s(`settings.defaultAllow`)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col border-l border-gray-200 dark:border-gray-700 pl-4`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40`,children:s(`settings.parseLatency`)}),(0,Q.jsx)(`span`,{className:`text-sm font-mono font-bold`,children:a.latency?`${a.latency}ms`:`-`})]}),a.timings&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 border-l border-gray-200 dark:border-gray-700 pl-4 max-w-md`,children:Object.entries(a.timings).map(([e,t])=>(0,Q.jsxs)(`div`,{className:`flex gap-1 items-baseline`,children:[(0,Q.jsxs)(`span`,{className:`text-[9px] opacity-40 uppercase font-mono`,children:[e,`:`]}),(0,Q.jsxs)(`span`,{className:`text-[10px] font-mono font-bold`,children:[t,`ms`]})]},e))}),(0,Q.jsx)(N,{}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 bg-white dark:bg-gray-900 px-3 py-1.5 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,Q.jsx)(o,{size:14,className:`text-red-500`}),(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] uppercase font-bold opacity-40 leading-none`,children:s(`settings.sourceIp`)}),(0,Q.jsxs)(`span`,{className:`text-xs font-mono`,children:[a.client_ip,` (`,a.geo_country,`)`]})]})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`text-[10px] uppercase font-bold opacity-40 flex items-center gap-1`,children:[(0,Q.jsx)(n,{size:10}),` `,s(`settings.answerSection`)]}),(0,Q.jsx)(`div`,{className:`font-mono text-sm leading-relaxed bg-white dark:bg-gray-900 p-4 rounded-xl border border-gray-100 dark:border-gray-800 shadow-inner`,children:a.answers&&a.answers.length>0?a.answers.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex gap-4 py-1 border-b border-gray-50 dark:border-gray-800 last:border-0 hover:bg-blue-50/50 dark:hover:bg-blue-900/10 transition-colors px-2`,children:[(0,Q.jsx)(`span`,{className:`w-16 font-bold text-blue-500`,children:e.type}),(0,Q.jsx)(`span`,{className:`flex-1 dark:text-gray-300`,children:e.data}),(0,Q.jsxs)(`span`,{className:`text-[10px] opacity-30 italic`,children:[`TTL: `,e.ttl,`s`]})]},t)):(0,Q.jsx)(`div`,{className:`p-4 opacity-40 italic text-center`,children:s(`settings.noRecordsReturned`)})})]}),a.diagnostics&&(0,Q.jsx)(x,{minimal:!0,intent:a.action===`FAIL`?w.DANGER:w.NONE,className:`text-xs font-mono`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Q.jsx)(`span`,{className:`font-bold uppercase tracking-wider`,children:s(`settings.diagnostics`)}),(0,Q.jsx)(`span`,{className:`font-bold`,children:a.action===`FAIL`?a.diagnostics.status>0?`HTTP ${a.diagnostics.status}${a.diagnostics.status_text?` (${a.diagnostics.status_text})`:``}`:`Network / Connection Error`:a.diagnostics.method===`POST`||a.diagnostics.method===`GET`?`HTTP ${a.diagnostics.status}${a.diagnostics.status_text?` (${a.diagnostics.status_text})`:``}`:`Connected (OK)`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs opacity-80`,children:[(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 bg-gray-200 dark:bg-gray-700 rounded text-[10px] font-bold`,children:a.diagnostics.method}),(0,Q.jsx)(`span`,{className:`break-all`,children:a.diagnostics.upstream_url})]}),a.diagnostics.cf_ray&&(0,Q.jsxs)(`div`,{className:`text-[11px] opacity-75`,children:[`CF-Ray: `,(0,Q.jsx)(`span`,{className:`font-bold`,children:a.diagnostics.cf_ray})]}),a.diagnostics.error_detail&&a.action===`FAIL`&&(0,Q.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-950/40 rounded border border-red-200 dark:border-red-900/50 text-red-700 dark:text-red-300 break-words`,children:[(0,Q.jsxs)(`div`,{className:`font-bold mb-0.5`,children:[s(`settings.errorDetail`),`:`]}),(0,Q.jsx)(`div`,{children:a.diagnostics.error_detail})]}),a.diagnostics.response_body&&(0,Q.jsxs)(`div`,{className:`p-2 bg-gray-100 dark:bg-gray-900 rounded border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 break-words text-[11px]`,children:[(0,Q.jsxs)(`div`,{className:`font-bold mb-0.5 opacity-60`,children:[s(`settings.upstreamResponse`),`:`]}),(0,Q.jsx)(`div`,{className:`line-clamp-3`,children:a.diagnostics.response_body})]})]})})]})]})]})},me=({profileId:e,toasterRef:t,onLogsCleared:n})=>{let{t:r}=f(),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),c=async()=>{if(confirm(r(`settings.confirmClearProfileLogs`,`确定要清空当前配置的所有查询日志吗?此操作不可恢复。`))){s(!0);try{await V(e),await J.clearProfile(e).catch(()=>{}),t?.current?.show({message:r(`settings.clearProfileLogsSuccess`,`配置日志已成功清空`),intent:w.SUCCESS,icon:`tick`}),n?.()}catch(e){console.error(`[ProfileDangerZone] Clear profile logs failed:`,e);let n=e instanceof Error?e.message:String(e);t?.current?.show({message:n||r(`common.errorNetwork`,`网络请求失败`),intent:w.DANGER,icon:`error`})}finally{s(!1)}}};return(0,Q.jsxs)(`div`,{className:`space-y-4 pt-4 border-t border-gray-200 dark:border-gray-800`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between cursor-pointer select-none py-1 group`,onClick:()=>a(!i),role:`button`,tabIndex:0,"aria-expanded":i,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a(!i))},children:[(0,Q.jsxs)(T,{className:`text-red-500 flex items-center gap-2 m-0! group-hover:text-red-600 dark:group-hover:text-red-400 transition-colors`,children:[(0,Q.jsx)(g,{size:20}),` `,r(`settings.dangerZone`,`危险区域`)]}),(0,Q.jsx)(O,{variant:`minimal`,icon:(0,Q.jsx)(v,{size:18,className:ne(`transition-transform duration-200 text-red-500`,!i&&`-rotate-90`)}),text:i?r(`common.collapse`,`收起`):r(`common.expand`,`展开`),className:`text-red-500 hover:text-red-600 dark:hover:text-red-400`,onClick:e=>{e.stopPropagation(),a(!i)},"aria-label":i?r(`common.collapse`,`收起`):r(`common.expand`,`展开`)})]}),(0,Q.jsx)(te,{isOpen:i,keepChildrenMounted:!0,children:(0,Q.jsx)(`div`,{className:`space-y-4 pt-3`,children:(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:(0,Q.jsxs)(k,{elevation:j.ONE,className:`flex flex-col justify-between dark:bg-gray-900 dark:border-gray-800`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(T,{children:r(`settings.clearProfileLogs`,`清空当前配置所有日志`)}),(0,Q.jsx)(`p`,{className:`text-xs opacity-60 mb-3`,children:r(`settings.clearProfileLogsDesc`,`这将删除当前 DNS 配置生成的所有查询日志(包含服务端日志与本地缓存)。此操作不可恢复。`)})]}),(0,Q.jsx)(O,{fill:!0,intent:w.DANGER,text:r(`settings.clearProfileLogsBtn`,`立即清空配置日志`),icon:`trash`,loading:o,onClick:c})]})})})})]})},he=({profileId:e,toasterRef:t,currentUser:n,onSavingChange:r})=>{let[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!0),[u,d]=(0,Z.useState)(!1),{t:p}=f();(0,Z.useEffect)(()=>(r?.(u),()=>{r?.(!1)}),[u,r]);let m=(0,Z.useRef)(!0),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(0),v=e=>typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e)),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(``),[C,T]=(0,Z.useState)({domain:`o-o.myaddr.l.google.com`,type:`TXT`}),[E,D]=(0,Z.useState)(null),[O,k]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{m.current=!0,h.current&&=(clearTimeout(h.current),null),(async()=>{l(!0);try{let t=await G(e);a(t),S(t.name);let n=JSON.parse(t.settings);return g.current=v(n),s(n),i}catch(e){console.error(e)}finally{l(!1)}})()},[e]),(0,Z.useEffect)(()=>{if(!c&&o&&m.current){let e=setTimeout(()=>{m.current=!1,o&&(g.current=v(o))},500);return()=>clearTimeout(e)}},[c,o]),(0,Z.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]);let A=async()=>{if(!x||x===i?.name){b(!1);return}let n=i?.name||``;d(!0);try{await X(Y(e,x),1e4),a(e=>e?{...e,name:x}:null),b(!1),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:w.SUCCESS,icon:`tick`})}catch(e){console.error(e),S(n),b(!1);let r=e.message,i=r;r===`The profile name already exists`?i=p(`common.profileNameExists`,`The profile name already exists`):r===`Invalid Profile Name format`&&(i=p(`common.profileNameFormatError`,`Invalid Profile Name format`)),t?.current?.show({message:i||p(`common.saveFailed`,`保存失败`),intent:w.DANGER,icon:`error`})}finally{d(!1)}},j=(0,Z.useCallback)(async n=>{if(!n)return;let r=++_.current;d(!0);try{await X(W(e,n),1e4),r===_.current&&(g.current=v(n),t?.current?.show({message:p(`common.saveSuccess`,`保存成功`),intent:w.SUCCESS,icon:`tick`}))}catch(e){console.error(e),r===_.current&&(h.current&&=(clearTimeout(h.current),null),g.current&&s(v(g.current)),t?.current?.show({message:p(`common.saveFailed`,`保存失败`),intent:w.DANGER,icon:`error`}))}finally{r===_.current&&d(!1)}},[e,t,p]),M=(0,Z.useCallback)(e=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{j(e)},600)},[j]),N=(0,Z.useCallback)(e=>{s(e),m.current||M(e)},[M]);return c||!o?(0,Q.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,Q.jsx)(ee,{})}):(0,Q.jsxs)(`div`,{className:`p-0 sm:px-4 lg:px-8 max-w-5xl mx-auto space-y-8 pb-20`,children:[(0,Q.jsx)(ie,{profile:i,isEditingName:y,setIsEditingName:b,editName:x,setEditName:S,updateProfileName:A,exportProfile:async()=>{if(!(!i||!o))try{let[n,r]=await Promise.all([q(e).catch(()=>[]),U(e).catch(()=>[])]),a=new Set,s=(n||[]).filter(e=>{let t=(e.pattern||``).trim().toLowerCase();return!t||a.has(t)?!1:(a.add(t),!0)}),c=new Set,l=(r||[]).filter(e=>{let t=(e.url||``).trim().toLowerCase();return!t||c.has(t)?!1:(c.add(t),!0)}).map(e=>({url:e.url,enabled:!!e.enabled})),u={version:2,name:i.name,settings:o,rules:s,filters:l,exported_at:Math.floor(Date.now()/1e3)},d=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),f=URL.createObjectURL(d),m=document.createElement(`a`);m.href=f,m.download=`dns-worker-${i.name||e}.json`,document.body.appendChild(m),m.click(),document.body.removeChild(m),URL.revokeObjectURL(f),t?.current?.show({message:p(`settings.exportSuccess`,`配置成功导出`),intent:w.SUCCESS,icon:`download`})}catch(e){console.error(e),t?.current?.show({message:p(`settings.exportError`,`导出失败`),intent:w.DANGER,icon:`error`})}}}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,Q.jsx)($,{settings:o,setSettings:N}),(0,Q.jsx)(se,{settings:o,setSettings:N}),(0,Q.jsx)(ce,{settings:o,setSettings:N,isAdmin:n?.role===`admin`,maxRetentionDays:n?.max_log_retention_days??(n?.role===`admin`?30:7)}),(0,Q.jsx)(le,{profileId:e,toasterRef:t}),(0,Q.jsx)(ue,{settings:o,setSettings:N}),(0,Q.jsx)(fe,{settings:o,setSettings:N})]}),(0,Q.jsx)(pe,{testInput:C,setTestInput:T,handleDnsTest:async()=>{if(C.domain){k(!0),D(null);try{D(await re(e,C))}catch(e){console.error(e)}finally{k(!1)}}},testing:O,testResult:E}),(0,Q.jsx)(me,{profileId:e,toasterRef:t})]})};export{he as SettingsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{At as t,B as n,D as r,F as i,J as a,L as o,M as s,P as c,R as l,T as u,U as d,V as f,X as p,ct as m,ft as h,it as g,kt as _,nn as v,ot as y,q as b,st as x,w as S}from"./vendor-react-DYK5a2J9.js";import{S as C,b as w}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{A as T,B as E,F as D,L as O,M as k,N as A,O as j,P as M,R as N,S as P,T as F,V as I,a as L,d as R,f as z,i as B,n as V,o as H,r as U,v as W,z as G}from"./vendor-ui-core-C4974KNo.js";import{_t as K,t as ee,vt as q}from"./vendor-utils-Bab4qB3W.js";import{H as te,J as ne,Q as re,St as ie,U as ae,X as J,Y as oe,_ as se,a as ce,ct as le,dt as ue,et as de,h as fe,hn as pe,n as Y,pt as me,t as he,xt as ge}from"./index-DEIEgGUw.js";import{t as _e}from"./SwipeableDrawer-BuCjl9Vd.js";var X=e(C(),1),Z=e(w(),1);const ve=()=>{let{t:e}=v();return(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(T,{className:`font-bold text-gray-900 dark:text-white m-0`,children:e(`setup.title`)}),(0,Z.jsx)(`p`,{className:`bp6-text-muted m-0 mt-1`,children:e(`setup.subtitle`)})]}),(0,Z.jsx)(`div`,{className:`flex items-center`,children:(0,Z.jsx)(he,{})})]})},ye=({isVerifying:e,verifyResult:n,handleVerify:r,isMobile:i,clientInfo:a,showIp:o,setShowIp:l,showLocation:u,setShowLocation:d,traceInfo:f,edgeLocation:m})=>{let{t:h}=v(),{isServerfull:_}=Y(),[b,S]=(0,X.useState)(!1),C=(0,Z.jsxs)(`div`,{className:q(`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3 select-none h-full transition-all`,!_),children:[(0,Z.jsx)(c,{size:18,className:`text-purple-500 mt-1 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:_?h(`setup.serverLocation`,`服务器位置`):h(`setup.edgeServer`)}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,title:_?m||``:m||f?.colo||``,children:_?m||h(`setup.detecting`):m||f?.colo||h(`setup.detecting`)})]})]});return(0,Z.jsx)(H,{title:h(`setup.verifyConnection`),icon:(0,Z.jsx)(t,{size:16}),children:(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center justify-between bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center gap-4 text-center md:text-left`,children:[(0,Z.jsx)(`div`,{className:`p-3 rounded-full ${n?.success?`bg-green-100 text-green-600`:n?`bg-red-100 text-red-600`:`bg-blue-100 text-blue-600`}`,children:e?(0,Z.jsx)(M,{size:24}):n?.success?(0,Z.jsx)(s,{size:24}):(0,Z.jsx)(c,{size:24})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-bold text-lg`,children:e?h(`setup.verifying`):n?.success?h(`setup.connected`):h(`setup.notConnected`)}),(0,Z.jsx)(`div`,{className:`text-sm opacity-60`,children:n?.success?n.profileMatch?h(`setup.profileMatch`):h(`setup.profileMismatch`):h(`setup.verifyHint`)})]})]}),(0,Z.jsx)(A,{size:`large`,intent:n?.success?I.SUCCESS:I.PRIMARY,icon:`refresh`,text:h(`setup.refreshStatus`),onClick:r,loading:e,fill:i})]}),a&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4`,children:[(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(g,{size:18,className:`text-blue-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:h(`setup.egressIp`)}),(0,Z.jsx)(`button`,{onClick:()=>l(!o),className:`text-gray-400 hover:text-blue-500 transition-colors`,children:o?(0,Z.jsx)(y,{size:16}):(0,Z.jsx)(x,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-mono font-bold text-blue-600 dark:text-blue-400 truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!o&&`filter blur-[6px] select-none`),children:a.ip})})]})]}),(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(p,{size:18,className:`text-red-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:h(`setup.currentLocation`)}),(0,Z.jsx)(`button`,{onClick:()=>d(!u),className:`text-gray-400 hover:text-red-500 transition-colors`,children:u?(0,Z.jsx)(y,{size:16}):(0,Z.jsx)(x,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!u&&`filter blur-[6px] select-none`),children:(()=>{let e=[a.city,a.region,a.country].filter(e=>!!(e&&e!==`UNKNOWN`));return e.length>0?e.join(`, `):h(`setup.detecting`)})()})})]})]}),_?C:(0,Z.jsx)(F,{isOpen:b,onInteraction:S,placement:`bottom-end`,portalClassName:`z-20000`,fill:!0,targetProps:{className:`h-full`},content:(0,Z.jsxs)(`div`,{className:`p-3 select-text w-72 sm:w-80 max-w-[85vw] space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-mono font-bold text-gray-500 dark:text-gray-400 tracking-wide border-b border-gray-100 dark:border-gray-800 pb-1.5`,children:`/cdn-cgi/trace`}),(0,Z.jsx)(`pre`,{className:`m-0 font-mono text-xs leading-relaxed whitespace-pre-wrap break-all overflow-x-hidden max-h-64 overflow-y-auto text-gray-800 dark:text-gray-200`,children:f?.raw||h(`setup.noTraceData`,`暂无 Trace 数据`)})]}),children:C})]})]})})})},Q=({step:e,className:t,size:n=144})=>{let r=e===1?47:50,i=e===1?45.5:45;return(0,Z.jsx)(`div`,{"aria-hidden":`true`,className:K(`absolute -top-7 -left-7 pointer-events-none select-none z-0`,`text-blue-600/[0.08] dark:text-blue-400/[0.12]`,`transition-all duration-500 ease-out`,`blur-none group-hover:blur-md group-hover:opacity-0`,t),style:{width:n,height:n},children:(0,Z.jsxs)(`svg`,{viewBox:`0 0 100 100`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:`w-full h-full`,children:[(0,Z.jsx)(`circle`,{cx:`50`,cy:`50`,r:`46`,stroke:`currentColor`,strokeWidth:`4`}),(0,Z.jsx)(`text`,{x:r,y:i,textAnchor:`middle`,dominantBaseline:`central`,fill:`currentColor`,fontSize:`80`,fontWeight:`900`,fontFamily:`'Helvetica Neue', Helvetica, Arial, sans-serif`,children:e})]})})},be=({accessPoints:e,selectedApId:t,onSelectAp:n,accessPointName:r,onManageAccessPoints:o,isMobile:s})=>{let{t:c}=v();return(0,Z.jsxs)(H,{title:c(`setup.accessPointsCardTitle`,`接入点`),icon:(0,Z.jsx)(a,{size:16}),className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,children:[(0,Z.jsx)(Q,{step:1}),(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 w-full sm:w-auto`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 font-medium`,children:c(`setup.selectAccessPointToConfigure`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.length>0?(0,Z.jsx)(R,{value:t||``,onChange:e=>n(e.target.value),options:e.map(e=>({label:e.name,value:e.id})),className:`font-semibold text-gray-900 dark:text-gray-100`}):(0,Z.jsx)(`div`,{className:`font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:r||c(`setup.defaultAccessPointName`,`设备-1`)}),e.length>0&&(0,Z.jsx)(U,{minimal:!0,round:!0,intent:I.PRIMARY,className:`text-xs`,children:e.length})]})]}),(0,Z.jsx)(A,{variant:`outlined`,intent:I.NONE,icon:(0,Z.jsx)(i,{size:14}),text:c(`setup.manageAccessPoints`,`管理接入点`),onClick:o,fill:s,className:`shrink-0`})]})})]})},xe=({dohUrl:e,copyToClipboard:t,isMobile:n})=>{let{t:r}=v();return(0,Z.jsxs)(H,{title:r(`setup.accessPointTitle`,`Access DoH URL`),icon:`globe`,className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,rightElement:(0,Z.jsx)(F,{placement:`bottom-end`,usePortal:!0,content:(0,Z.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,Z.jsx)(k,{children:r(`setup.whatIsDoh`)}),(0,Z.jsx)(`p`,{className:`text-sm mb-2`,children:r(`setup.dohDesc`)}),(0,Z.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit1`)}),(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit2`)})]}),(0,Z.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,Z.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/DNS_over_HTTPS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,Z.jsx)(m,{size:10}),` `,r(`setup.learnMore`)]})})]}),children:(0,Z.jsx)(A,{icon:`help`,variant:`minimal`,intent:I.NONE})}),children:[(0,Z.jsx)(Q,{step:2}),(0,Z.jsx)(L,{children:(0,Z.jsxs)(`div`,{className:`w-full bg-gray-100 dark:bg-gray-800 p-3 rounded-lg border border-gray-200 dark:border-gray-700 flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-blue-600 dark:text-blue-400 break-all text-xs sm:text-sm`,children:e}),(0,Z.jsx)(A,{intent:I.PRIMARY,icon:`duplicate`,text:r(`setup.copyUrl`),fill:n,onClick:()=>t(e),className:`shrink-0 whitespace-nowrap min-w-fit w-auto`})]})})]})};function Se(e){let t=e.trim();try{return new URL(t.startsWith(`http://`)||t.startsWith(`https://`)?t:`https://${t}`).hostname||t}catch{return t.replace(/^https?:\/\//,``).split(`/`)[0].split(`:`)[0]||t}}function $(e,t){let n=(e||``).trim(),r=(t||``).trim();if(!r&&n.includes(`(`)&&n.endsWith(`)`)){let e=n.match(/^(.+?)\s*\((.+?)\)$/);e&&(n=e[1].trim(),r=e[2].trim())}let i=n&&n!==`DNS Worker`?n:``,a=r&&r!==`DNS Worker`?r:``;return i&&a?i.toLowerCase()===a.toLowerCase()?i:`${i} - ${a}`:i||a||``}function Ce(e,t,n,r){let i,a,o,s;typeof e==`object`?(i=e.profileKey,a=e.profileName,o=e.accessPointName,s=e.origin):(i=e,a=t,s=n||``,o=r);let c=s.trim(),l=Se(c),u=`${c}/${i}`,d=$(a,o),f=crypto.randomUUID(),p=crypto.randomUUID(),m=d?`DNS Worker - ${l} (${d})`:`DNS Worker (${l})`,h=d?`DNS Worker DoH - ${l} (${d})`:`DNS Worker DoH - ${l}`,g=d?`DNS Worker DoH configuration profile for ${d} via ${l}`:`DNS Worker DoH configuration profile via ${l}`,_=d?`Configures encrypted DNS over HTTPS (DoH) for ${d} via ${l}`:`Configures encrypted DNS over HTTPS (DoH) via ${l}`;return ee({PayloadContent:[{DNSSettings:{DNSProtocol:`HTTPS`,ServerHTTPVersion:3,ServerURL:u},OnDemandRules:[{Action:`Connect`,InterfaceTypeMatch:`WiFi`},{Action:`Connect`,InterfaceTypeMatch:`Cellular`},{Action:`Disconnect`}],PayloadDescription:_,PayloadDisplayName:h,PayloadIdentifier:`com.apple.dnsSettings.managed.${f}`,PayloadName:h,PayloadType:`com.apple.dnsSettings.managed`,PayloadUUID:f,PayloadVersion:1}],PayloadDescription:g,PayloadDisplayName:m,PayloadIdentifier:`com.dnsworker.profile.${i}`,PayloadName:m,PayloadRemovalDisallowed:!1,PayloadType:`Configuration`,PayloadUUID:p,PayloadVersion:1},{indent:` `})}const we=({isMobile:e,copyToClipboard:t,profileKey:n,profileName:i,accessPointName:a,currentIps:o,dotDomain:s})=>{let{t:c}=v(),{isCloudflare:d}=Y();return(0,Z.jsxs)(`div`,{className:`group relative overflow-hidden rounded-xl border border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 shadow-sm`,children:[(0,Z.jsx)(Q,{step:3}),(0,Z.jsxs)(V,{id:`setup-tabs`,renderActiveTabPanelOnly:!0,vertical:!e,size:`large`,className:K(`p-4 md:p-6 setup-tabs-container relative z-10 bg-transparent`,e&&[`[&_.bp6-tab-list]:overflow-x-auto!`,`[&_.bp6-tab-list]:flex-nowrap!`,`[&_.bp6-tab-list]:pb-1`,`[&_.bp6-tab-list]:scrollbar-none`,`[&_.bp6-tab-list]:[-ms-overflow-style:none]`,`[&_.bp6-tab-list::-webkit-scrollbar]:hidden`,`[&_.bp6-tab]:shrink-0`]),children:[(0,Z.jsx)(B,{id:`browsers`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(g,{size:16,className:`inline mr-2`}),c(`setup.browsers`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:c(`setup.browserTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.browserSteps`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 cursor-pointer`,onClick:()=>t(`chrome://settings/security`),children:c(`setup.browserTips`,`or copy this URL to the address bar: `)+`chrome://settings/security`})]})}),(0,Z.jsx)(B,{id:`apple`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(_,{size:16,className:`inline mr-2`}),c(`setup.apple`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:c(`setup.appleTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.appleDesc`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 text-center`,children:c(`setup.appleWarning`)}),(0,Z.jsxs)(`div`,{className:`p-6 bg-gray-50 dark:bg-gray-800 rounded-xl border border-dashed border-gray-300 dark:border-gray-700 flex flex-col items-center justify-center`,children:[(0,Z.jsx)(D,{icon:`document`,size:40,className:`opacity-20 mb-4`}),(0,Z.jsx)(A,{intent:I.PRIMARY,text:c(`setup.downloadConfig`),icon:`download`,onClick:()=>{let e=Ce({profileKey:n,profileName:i,accessPointName:a,origin:window.location.origin}),t=new Blob([e],{type:`application/x-apple-aspen-config`}),r=URL.createObjectURL(t),o=document.createElement(`a`);o.href=r;let s=$(i,a),c=Se(window.location.origin);o.download=`dns_worker-${(s||c).replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,`_`).replace(/_+/g,`_`).replace(/^_|_$/g,``)}-${n}.mobileconfig`,o.click(),URL.revokeObjectURL(r)}})]}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 mt-4! text-center`,children:c(`setup.appleInstallHint`)})]})}),(0,Z.jsx)(B,{id:`windows`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(b,{size:16,className:`inline mr-2`}),c(`setup.windows`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:c(`setup.windowsTitle`)}),(0,Z.jsxs)(`ol`,{className:`list-decimal list-inside space-y-4 text-sm leading-relaxed`,children:[(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`a`,{href:`ms-settings:network-status`,children:c(`setup.windowsStep0`)})}),(0,Z.jsx)(`li`,{children:c(`setup.windowsStep1`)}),(0,Z.jsxs)(`li`,{children:[c(`setup.windowsStep2`),(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:o.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(e.ip),icon:`duplicate`,className:`font-mono`,children:e.ip}),(0,Z.jsx)(`span`,{className:`text-[9px] opacity-50 ml-1 font-mono`,children:e.area})]},e.ip))})]}),(0,Z.jsx)(`li`,{children:c(`setup.windowsStep3`)}),(0,Z.jsx)(`li`,{children:c(`setup.windowsStep4`)})]})]})}),(0,Z.jsx)(B,{id:`linux`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(u,{size:16,className:`inline mr-2`}),c(`setup.linux`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:c(`setup.linuxTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.linuxDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:c(`setup.linuxStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`})}),(0,Z.jsx)(A,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`)}})]})]}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(`p`,{className:`text-sm font-bold`,children:c(`setup.linuxStep2`)})})]})}),(0,Z.jsx)(B,{id:`routeros`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(l,{size:16,className:`inline mr-2`}),c(`setup.routeros`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:c(`setup.routerosTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.routerosDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:c(`setup.routerosStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`})}),(0,Z.jsx)(A,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`)}})]})]}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.routerosNote`)}),(0,Z.jsxs)(`a`,{href:`https://help.mikrotik.com/docs/spaces/ROS/pages/37748767/DNS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-xs text-blue-500 hover:underline`,children:[(0,Z.jsx)(m,{size:10}),` `,c(`setup.routerosDocs`)]})]})}),(0,Z.jsx)(B,{id:`android`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(r,{size:16,className:`inline mr-2`}),c(`setup.android`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(k,{className:`font-bold`,children:c(`setup.androidTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.androidDesc`)}),d?(0,Z.jsxs)(P,{intent:I.WARNING,icon:`warning-sign`,className:`text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-semibold mb-1`,children:c(`setup.dotUnavailableCfTitle`)}),(0,Z.jsx)(`div`,{children:c(`setup.dotUnavailableCfDesc`)})]}):(()=>{let e=/^(\d{1,3}\.){3}\d{1,3}$/.test(window.location.hostname)||window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname.includes(`:`),r=(s||``).trim().replace(/^\*\./,``),i=!J(r)&&r||(e?``:window.location.hostname);return(0,Z.jsxs)(`div`,{className:`p-4 bg-gray-50 dark:bg-gray-800/60 rounded-xl border border-gray-200 dark:border-gray-700 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-gray-700 dark:text-gray-300`,children:c(`setup.androidDotTitle`,`私有 DNS (DoT / DoQ)`)}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c(`setup.androidDotDesc`,`支持 Android 原生“私有 DNS (DoT)”及各类现代 DoQ 客户端。提供商主机名:`)}),i?(0,Z.jsx)(`div`,{className:`space-y-3 pt-1`,children:(0,Z.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-2`,children:(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(`${n}.${i}`),icon:`duplicate`,className:`font-mono text-xs sm:text-sm py-1 px-3 self-start`,intent:I.PRIMARY,children:`${n}.${i}`})})}):(0,Z.jsx)(P,{intent:I.WARNING,icon:`warning-sign`,className:`text-xs`,children:c(`setup.androidIpNotice`,`检测到当前通过 IP 或本地地址访问面板。DoT / DoQ 仅接受域名,请在 .env 中配置 SERVERFULL_DOT_DOMAIN (例如 dns.example.com) 后刷新。`)})]})})(),!d&&(0,Z.jsx)(P,{intent:I.PRIMARY,icon:`info-sign`,className:`text-xs`,children:c(`setup.androidWarning`)})]})})]})]})};function Te({profileId:e,accessPoints:t,onRefresh:n,toasterRef:r}){let{t:i}=v(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(``);return{isAddDialogOpen:a,setIsAddDialogOpen:o,newApName:s,setNewApName:c,isAdding:l,renameApId:d,setRenameApId:f,renameApName:p,setRenameApName:m,isRenaming:h,rotatingApId:_,deletingApId:b,newApNameFocused:S,setNewApNameFocused:C,renameApNameFocused:w,setRenameApNameFocused:T,rotateConfirmApId:E,setRotateConfirmApId:D,isSearchOpen:O,setIsSearchOpen:k,searchQuery:A,setSearchQuery:j,filteredAccessPoints:t.filter(e=>e.name.toLowerCase().includes(A.toLowerCase())||e.token.toLowerCase().includes(A.toLowerCase())),isValidApName:e=>ce.test(e),handleAdd:async()=>{let a=s.trim();if(a){if(t.some(e=>e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:I.DANGER});return}u(!0);try{await de(e,a),r.current?.show({message:i(`setup.accessPointCreated`),intent:I.SUCCESS}),o(!1),c(``),n()}catch(e){let t=e.message||`Failed to create access point`,n=t;if(t.startsWith(`Access point limit exceeded`)){let e=t.match(/\(max (\d+)\)/),r=e?e[1]:`100`;n=i(`setup.accessPointLimitExceeded`,{max:r,defaultValue:`Access Point limit exceeded (max ${r})`})}r.current?.show({message:n,intent:I.DANGER})}finally{u(!1)}}},handleRename:async()=>{let a=p.trim();if(!(!a||!d)){if(t.some(e=>e.id!==d&&e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:I.DANGER});return}g(!0);try{await ge(e,d,a),r.current?.show({message:i(`setup.accessPointRenamed`),intent:I.SUCCESS}),f(null),n()}catch(e){r.current?.show({message:e.message||`Failed to rename access point`,intent:I.DANGER})}finally{g(!1)}}},handleRotate:async t=>{y(t);try{await ie(e,t),r.current?.show({message:i(`setup.tokenRotated`),intent:I.SUCCESS}),n()}catch(e){console.error(e)}finally{y(null)}},handleDelete:async t=>{if(confirm(i(`setup.deleteAccessPointConfirm`))){x(t);try{await le(e,t),r.current?.show({message:i(`setup.accessPointDeleted`),intent:I.SUCCESS}),n()}catch(e){console.error(e)}finally{x(null)}}}}}const Ee=({isOpen:e,onClose:t,newApName:n,setNewApName:r,newApNameFocused:i,setNewApNameFocused:a,handleAdd:o,isAdding:s,isValidApName:c})=>{let{t:l}=v();return(0,Z.jsxs)(j,{isOpen:e,onClose:t,title:l(`setup.addAccessPoint`),children:[(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:E.TOP,intent:I.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(z,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsxs)(`div`,{className:G,children:[(0,Z.jsx)(A,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(A,{intent:I.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.create`)})]})})]})},De=({isOpen:e,onClose:t,renameApName:n,setRenameApName:r,renameApNameFocused:i,setRenameApNameFocused:a,handleRename:o,isRenaming:s,isValidApName:c})=>{let{t:l}=v();return(0,Z.jsxs)(j,{isOpen:e,onClose:t,title:l(`setup.renameAccessPoint`),children:[(0,Z.jsx)(`div`,{className:O,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:E.TOP,intent:I.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(z,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsxs)(`div`,{className:G,children:[(0,Z.jsx)(A,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(A,{intent:I.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.save`)})]})})]})},Oe=({ap:e,totalApCount:t,toasterRef:r,onRenameTrigger:i,rotateConfirmApId:o,setRotateConfirmApId:s,rotatingApId:c,handleRotate:l,deletingApId:u,handleDelete:f})=>{let{t:p}=v();return(0,Z.jsx)(H,{title:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(a,{size:16}),(0,Z.jsx)(`span`,{children:e.name})]}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsxs)(L,{children:[(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`DoH URL`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono bg-blue-50 text-blue-600 dark:bg-blue-900/20 dark:text-blue-400 px-2 py-1 rounded cursor-pointer hover:bg-blue-100 dark:hover:bg-blue-900/40 transition-colors break-all`,onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/${e.token}`),r.current?.show({message:p(`setup.copied`),intent:I.SUCCESS})},title:p(`setup.copyUrl`),children:[(0,Z.jsx)(`span`,{className:`select-all`,children:`${window.location.origin}/${e.token}`}),(0,Z.jsx)(h,{size:14,className:`shrink-0`})]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:p(`setup.accessPointToken`)}),(0,Z.jsx)(`span`,{className:`text-sm font-mono bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded select-all break-all`,children:e.token})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`Created`}),(0,Z.jsx)(`span`,{className:`text-sm`,children:fe(new Date(e.created_at*1e3))})]})]}),(0,Z.jsxs)(`div`,{className:`mt-4 flex gap-2 flex-wrap`,children:[(0,Z.jsx)(A,{small:!0,icon:(0,Z.jsx)(d,{size:14}),text:p(`setup.renameAccessPoint`),onClick:()=>i(e.id,e.name)}),(0,Z.jsx)(F,{isOpen:o===e.id,onInteraction:e=>{e||s(null)},content:(0,Z.jsxs)(`div`,{className:`p-4 space-y-3 dark:bg-gray-800 dark:text-white max-w-xs`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed`,children:p(`setup.rotateTokenConfirmDesc`,`Rotating the key will immediately disconnect devices using the old key. Are you sure you want to continue?`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(A,{small:!0,minimal:!0,text:p(`common.cancel`,`Cancel`),onClick:()=>s(null)}),(0,Z.jsx)(A,{small:!0,intent:I.DANGER,text:p(`common.confirm`,`Confirm`),onClick:()=>{s(null),l(e.id)}})]})]}),placement:`top`,children:(0,Z.jsx)(A,{small:!0,icon:(0,Z.jsx)(n,{size:14}),text:p(`setup.rotateToken`),loading:c===e.id,onClick:()=>s(e.id)})}),(0,Z.jsx)(A,{small:!0,intent:I.DANGER,icon:(0,Z.jsx)(S,{size:14}),text:p(`setup.deleteAccessPoint`),loading:u===e.id,onClick:()=>f(e.id),disabled:t<=1,title:t<=1?`Cannot delete the only access point`:void 0})]})]})})},ke=({isOpen:e,onClose:t,profileId:n,isMobile:r,accessPoints:i,loading:a,onRefresh:s,toasterRef:c})=>{let{t:l}=v(),{isAddDialogOpen:u,setIsAddDialogOpen:d,newApName:p,setNewApName:m,isAdding:h,renameApId:g,setRenameApId:_,renameApName:y,setRenameApName:b,isRenaming:x,rotatingApId:S,deletingApId:C,newApNameFocused:w,setNewApNameFocused:T,renameApNameFocused:E,setRenameApNameFocused:D,rotateConfirmApId:O,setRotateConfirmApId:k,isSearchOpen:j,setIsSearchOpen:N,searchQuery:P,setSearchQuery:F,filteredAccessPoints:L,isValidApName:R,handleAdd:B,handleRename:V,handleRotate:H,handleDelete:U}=Te({profileId:n,accessPoints:i,onRefresh:s,toasterRef:c});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(_e,{isOpen:e,onClose:t,title:j?(0,Z.jsx)(z,{leftIcon:`search`,placeholder:l(`setup.searchAccessPoints`,`Search...`),value:P,onChange:e=>F(e.target.value),rightElement:(0,Z.jsx)(A,{icon:`cross`,minimal:!0,onClick:()=>{N(!1),F(``)}}),autoFocus:!0}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{children:l(`setup.manageAccessPoints`)}),(0,Z.jsx)(A,{icon:(0,Z.jsx)(o,{size:14}),minimal:!0,onClick:()=>N(!0),className:`opacity-50 hover:opacity-100`})]}),icon:`diagram-tree`,size:r?`100%`:`450px`,children:[(0,Z.jsx)(A,{fill:!0,intent:I.PRIMARY,icon:(0,Z.jsx)(f,{size:16}),text:l(`setup.addAccessPoint`),onClick:()=>d(!0),large:!0}),a?(0,Z.jsx)(`div`,{className:`flex justify-center p-8`,children:(0,Z.jsx)(M,{})}):(0,Z.jsx)(`div`,{className:`space-y-4 mt-4`,children:L.map(e=>(0,Z.jsx)(Oe,{ap:e,totalApCount:i.length,toasterRef:c,onRenameTrigger:(e,t)=>{_(e),b(t)},rotateConfirmApId:O,setRotateConfirmApId:k,rotatingApId:S,handleRotate:H,deletingApId:C,handleDelete:U},e.id))})]}),(0,Z.jsx)(Ee,{isOpen:u,onClose:()=>{d(!1),m(``)},newApName:p,setNewApName:m,newApNameFocused:w,setNewApNameFocused:T,handleAdd:B,isAdding:h,isValidApName:R}),(0,Z.jsx)(De,{isOpen:!!g,onClose:()=>_(null),renameApName:y,setRenameApName:b,renameApNameFocused:E,setRenameApNameFocused:D,handleRename:V,isRenaming:x,isValidApName:R})]})},Ae=({profileId:e,profileKey:t,profileName:n,toasterRef:r})=>{let i=pe(),{t:a}=v(),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),m=async()=>{l(!0);try{s(await ue(e))}catch(e){console.error(e)}finally{l(!1)}};(0,X.useEffect)(()=>{m()},[e]);let[h,g]=(0,X.useState)(n||``);(0,X.useEffect)(()=>{n?g(n):e&&me(e).then(e=>{e?.name&&g(e.name)}).catch(()=>{})},[e,n]);let _=(0,X.useMemo)(()=>o.length===0?null:o.find(e=>e.id===f)||o[0],[o,f]),y=_?_.token:t,b=_?_.name:void 0,x=`${window.location.origin}/${y}`,[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)(null),[P,F]=(0,X.useState)({ipv4:[],ipv6:[]}),[L,R]=(0,X.useState)(null),z=e=>{navigator.clipboard.writeText(e),r?.current?.show({message:a(`setup.copied`),intent:I.SUCCESS})},B=async()=>{T(!0),R(null);try{let[t,n]=await Promise.all([te(),oe()]);if(t.ip&&(t.country===`UNKNOWN`||!t.country))try{let e=await fetch(`/api/geoip?ip=${encodeURIComponent(t.ip)}`);if(e.ok){let n=await e.json();n.success&&(n.country&&(t.country=n.country),n.region&&(t.region=n.region),n.city&&(t.city=n.city),n.timezone?.id&&(t.timezone=n.timezone.id),n.connection?.org&&(t.asOrganization=n.connection.org))}}catch{}C(t),j(n),t.timezone&&t.timezone!==`UNKNOWN`&&se(t.timezone);let r=window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname===`::1`||window.location.hostname.startsWith(`192.168.`)||window.location.hostname.startsWith(`10.`)||/^172\.(1[6-9]|2\d|3[01])\./.test(window.location.hostname),i=!!(t.dotDomain&&!J(t.dotDomain));ae(r&&i||i?t.dotDomain:window.location.hostname||``).then(e=>N(e)).catch(e=>console.warn(`Failed fetching domain geo location:`,e));let a=t.substituteDomain||`www.okx.com`;ne().then(e=>{F(t=>t.ipv4.length>0||t.ipv6.length>0?t:{ipv4:e.ip?[e.ip]:[],ipv6:e.ipv6?[e.ipv6]:[]})}).catch(()=>{}),re(a).then(e=>{(e.ipv4.length>0||e.ipv6.length>0)&&F(e)}).catch(e=>console.warn(`Failed resolving substitute domain DNS IPs:`,e)),R({success:!!t.connectedProfileId,profileMatch:t.connectedProfileId===e})}catch(e){console.error(`Verification failed`,e)}finally{T(!1)}};(0,X.useEffect)(()=>{B()},[e]);let V=(0,X.useMemo)(()=>{let e=[],t=(P.ipv4||[]).slice(0,2),n=(P.ipv6||[]).slice(0,2),r=S?.substituteDomain||`www.okx.com`;for(let n of t)e.push({ip:n,area:`${r} IPv4`});for(let t of n)e.push({ip:t,area:`${r} IPv6`});return e},[P,S?.substituteDomain]);return(0,Z.jsxs)(`div`,{className:`mx-auto space-y-8 pb-24 ${i?`p-1`:`px-8 max-w-5xl`}`,children:[(0,Z.jsx)(ve,{isMobile:i}),(0,Z.jsx)(ye,{isVerifying:w,verifyResult:L,handleVerify:B,isMobile:i,clientInfo:S,showIp:E,setShowIp:D,showLocation:O,setShowLocation:k,traceInfo:A,edgeLocation:M}),(0,Z.jsx)(be,{accessPoints:o,selectedApId:_?.id||null,onSelectAp:p,accessPointName:b,onManageAccessPoints:()=>d(!0),isMobile:i}),(0,Z.jsx)(xe,{dohUrl:x,copyToClipboard:z,isMobile:i}),(0,Z.jsx)(we,{isMobile:i,copyToClipboard:z,profileKey:y,profileName:h||void 0,accessPointName:b,currentIps:V,dotDomain:S?.dotDomain}),(0,Z.jsx)(ke,{isOpen:u,onClose:()=>d(!1),profileId:e,isMobile:i,accessPoints:o,loading:c,onRefresh:m,toasterRef:r})]})};export{Ae as SetupView};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{At as t,B as n,D as r,F as i,J as a,L as o,M as s,P as c,R as l,T as u,U as d,V as f,X as p,ct as m,ft as h,it as g,kt as _,nn as v,ot as y,q as b,st as x,w as S}from"./vendor-react-DYK5a2J9.js";import{S as C,b as w}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{B as T,C as E,E as D,F as O,H as k,I as A,N as j,P as M,R as N,V as P,a as F,d as I,f as L,i as R,j as z,k as B,n as V,o as H,r as U,v as W,z as G}from"./vendor-ui-core-CodM8CpF.js";import{_t as K,t as ee,vt as q}from"./vendor-utils-Bab4qB3W.js";import{Ct as te,H as ne,J as re,Q as ie,St as ae,U as oe,X as J,Y as se,_ as ce,a as le,et as ue,ft as de,gn as fe,h as pe,lt as me,mt as he,n as Y,t as ge}from"./index-Bw8TL1xo.js";import{t as _e}from"./SwipeableDrawer-UY1QWnPj.js";var X=e(C(),1),Z=e(w(),1);const ve=()=>{let{t:e}=v();return(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(z,{className:`font-bold text-gray-900 dark:text-white m-0`,children:e(`setup.title`)}),(0,Z.jsx)(`p`,{className:`bp6-text-muted m-0 mt-1`,children:e(`setup.subtitle`)})]}),(0,Z.jsx)(`div`,{className:`flex items-center`,children:(0,Z.jsx)(ge,{})})]})},ye=({isVerifying:e,verifyResult:n,handleVerify:r,isMobile:i,clientInfo:a,showIp:o,setShowIp:l,showLocation:u,setShowLocation:d,traceInfo:f,edgeLocation:m})=>{let{t:h}=v(),{isServerfull:_}=Y(),[b,S]=(0,X.useState)(!1),C=(0,Z.jsxs)(`div`,{className:q(`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3 select-none h-full transition-all`,!_),children:[(0,Z.jsx)(c,{size:18,className:`text-purple-500 mt-1 shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:_?h(`setup.serverLocation`,`服务器位置`):h(`setup.edgeServer`)}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,title:_?m||``:m||f?.colo||``,children:_?m||h(`setup.detecting`):m||f?.colo||h(`setup.detecting`)})]})]});return(0,Z.jsx)(H,{title:h(`setup.verifyConnection`),icon:(0,Z.jsx)(t,{size:16}),children:(0,Z.jsx)(F,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center justify-between bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-100 dark:border-gray-800 gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col md:flex-row items-center gap-4 text-center md:text-left`,children:[(0,Z.jsx)(`div`,{className:`p-3 rounded-full ${n?.success?`bg-green-100 text-green-600`:n?`bg-red-100 text-red-600`:`bg-blue-100 text-blue-600`}`,children:e?(0,Z.jsx)(O,{size:24}):n?.success?(0,Z.jsx)(s,{size:24}):(0,Z.jsx)(c,{size:24})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`font-bold text-lg`,children:e?h(`setup.verifying`):n?.success?h(`setup.connected`):h(`setup.notConnected`)}),(0,Z.jsx)(`div`,{className:`text-sm opacity-60`,children:n?.success?n.profileMatch?h(`setup.profileMatch`):h(`setup.profileMismatch`):h(`setup.verifyHint`)})]})]}),(0,Z.jsx)(M,{size:`large`,intent:n?.success?k.SUCCESS:k.PRIMARY,icon:`refresh`,text:h(`setup.refreshStatus`),onClick:r,loading:e,fill:i})]}),a&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4`,children:[(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(g,{size:18,className:`text-blue-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:h(`setup.egressIp`)}),(0,Z.jsx)(`button`,{onClick:()=>l(!o),className:`text-gray-400 hover:text-blue-500 transition-colors`,children:o?(0,Z.jsx)(y,{size:16}):(0,Z.jsx)(x,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-mono font-bold text-blue-600 dark:text-blue-400 truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!o&&`filter blur-[6px] select-none`),children:a.ip})})]})]}),(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 p-4 rounded-lg border border-gray-100 dark:border-gray-800 shadow-sm flex items-start gap-3`,children:[(0,Z.jsx)(p,{size:18,className:`text-red-500 mt-1`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase font-bold opacity-40`,children:h(`setup.currentLocation`)}),(0,Z.jsx)(`button`,{onClick:()=>d(!u),className:`text-gray-400 hover:text-red-500 transition-colors`,children:u?(0,Z.jsx)(y,{size:16}):(0,Z.jsx)(x,{size:16})})]}),(0,Z.jsx)(`div`,{className:`font-bold truncate`,children:(0,Z.jsx)(`span`,{className:q(`transition-[filter] duration-200 inline-block`,!u&&`filter blur-[6px] select-none`),children:(()=>{let e=[a.city,a.region,a.country].filter(e=>!!(e&&e!==`UNKNOWN`));return e.length>0?e.join(`, `):h(`setup.detecting`)})()})})]})]}),_?C:(0,Z.jsx)(D,{isOpen:b,onInteraction:S,placement:`bottom-end`,portalClassName:`z-20000`,fill:!0,targetProps:{className:`h-full`},content:(0,Z.jsxs)(`div`,{className:`p-3 select-text w-72 sm:w-80 max-w-[85vw] space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-mono font-bold text-gray-500 dark:text-gray-400 tracking-wide border-b border-gray-100 dark:border-gray-800 pb-1.5`,children:`/cdn-cgi/trace`}),(0,Z.jsx)(`pre`,{className:`m-0 font-mono text-xs leading-relaxed whitespace-pre-wrap break-all overflow-x-hidden max-h-64 overflow-y-auto text-gray-800 dark:text-gray-200`,children:f?.raw||h(`setup.noTraceData`,`暂无 Trace 数据`)})]}),children:C})]})]})})})},Q=({step:e,className:t,size:n=144})=>{let r=e===1?47:50,i=e===1?45.5:45;return(0,Z.jsx)(`div`,{"aria-hidden":`true`,className:K(`absolute -top-7 -left-7 pointer-events-none select-none z-0`,`text-blue-600/[0.08] dark:text-blue-400/[0.12]`,`transition-all duration-500 ease-out`,`blur-none group-hover:blur-md group-hover:opacity-0`,t),style:{width:n,height:n},children:(0,Z.jsxs)(`svg`,{viewBox:`0 0 100 100`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:`w-full h-full`,children:[(0,Z.jsx)(`circle`,{cx:`50`,cy:`50`,r:`46`,stroke:`currentColor`,strokeWidth:`4`}),(0,Z.jsx)(`text`,{x:r,y:i,textAnchor:`middle`,dominantBaseline:`central`,fill:`currentColor`,fontSize:`80`,fontWeight:`900`,fontFamily:`'Helvetica Neue', Helvetica, Arial, sans-serif`,children:e})]})})},be=({accessPoints:e,selectedApId:t,onSelectAp:n,accessPointName:r,onManageAccessPoints:o,isMobile:s})=>{let{t:c}=v();return(0,Z.jsxs)(H,{title:c(`setup.accessPointsCardTitle`,`接入点`),icon:(0,Z.jsx)(a,{size:16}),className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,children:[(0,Z.jsx)(Q,{step:1}),(0,Z.jsx)(F,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 w-full sm:w-auto`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 font-medium`,children:c(`setup.selectAccessPointToConfigure`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.length>0?(0,Z.jsx)(I,{value:t||``,onChange:e=>n(e.target.value),options:e.map(e=>({label:e.name,value:e.id})),className:`font-semibold text-gray-900 dark:text-gray-100`}):(0,Z.jsx)(`div`,{className:`font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:r||c(`setup.defaultAccessPointName`,`设备-1`)}),e.length>0&&(0,Z.jsx)(U,{minimal:!0,round:!0,intent:k.PRIMARY,className:`text-xs`,children:e.length})]})]}),(0,Z.jsx)(M,{variant:`outlined`,intent:k.NONE,icon:(0,Z.jsx)(i,{size:14}),text:c(`setup.manageAccessPoints`,`管理接入点`),onClick:o,fill:s,className:`shrink-0`})]})})]})},xe=({dohUrl:e,copyToClipboard:t,isMobile:n})=>{let{t:r}=v();return(0,Z.jsxs)(H,{title:r(`setup.accessPointTitle`,`Access DoH URL`),icon:`globe`,className:`group relative overflow-hidden [&_.bp6-section-header]:relative [&_.bp6-section-header]:z-10 [&_.bp6-section-card]:relative [&_.bp6-section-card]:z-10`,rightElement:(0,Z.jsx)(D,{placement:`bottom-end`,usePortal:!0,content:(0,Z.jsxs)(`div`,{className:`p-4 max-w-sm`,children:[(0,Z.jsx)(j,{children:r(`setup.whatIsDoh`)}),(0,Z.jsx)(`p`,{className:`text-sm mb-2`,children:r(`setup.dohDesc`)}),(0,Z.jsxs)(`ul`,{className:`list-disc list-inside text-sm opacity-80 mb-3 space-y-1`,children:[(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit1`)}),(0,Z.jsx)(`li`,{children:r(`setup.dohBenefit2`)})]}),(0,Z.jsx)(`div`,{className:`text-xs border-t border-gray-100 dark:border-gray-700 pt-2`,children:(0,Z.jsxs)(`a`,{href:`https://en.wikipedia.org/wiki/DNS_over_HTTPS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-blue-500 hover:underline`,children:[(0,Z.jsx)(m,{size:10}),` `,r(`setup.learnMore`)]})})]}),children:(0,Z.jsx)(M,{icon:`help`,variant:`minimal`,intent:k.NONE})}),children:[(0,Z.jsx)(Q,{step:2}),(0,Z.jsx)(F,{children:(0,Z.jsxs)(`div`,{className:`w-full bg-gray-100 dark:bg-gray-800 p-3 rounded-lg border border-gray-200 dark:border-gray-700 flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-blue-600 dark:text-blue-400 break-all text-xs sm:text-sm`,children:e}),(0,Z.jsx)(M,{intent:k.PRIMARY,icon:`duplicate`,text:r(`setup.copyUrl`),fill:n,onClick:()=>t(e),className:`shrink-0 whitespace-nowrap min-w-fit w-auto`})]})})]})};function Se(e){let t=e.trim();try{return new URL(t.startsWith(`http://`)||t.startsWith(`https://`)?t:`https://${t}`).hostname||t}catch{return t.replace(/^https?:\/\//,``).split(`/`)[0].split(`:`)[0]||t}}function $(e,t){let n=(e||``).trim(),r=(t||``).trim();if(!r&&n.includes(`(`)&&n.endsWith(`)`)){let e=n.match(/^(.+?)\s*\((.+?)\)$/);e&&(n=e[1].trim(),r=e[2].trim())}let i=n&&n!==`DNS Worker`?n:``,a=r&&r!==`DNS Worker`?r:``;return i&&a?i.toLowerCase()===a.toLowerCase()?i:`${i} - ${a}`:i||a||``}function Ce(e,t,n,r){let i,a,o,s;typeof e==`object`?(i=e.profileKey,a=e.profileName,o=e.accessPointName,s=e.origin):(i=e,a=t,s=n||``,o=r);let c=s.trim(),l=Se(c),u=`${c}/${i}`,d=$(a,o),f=crypto.randomUUID(),p=crypto.randomUUID(),m=d?`DNS Worker - ${l} (${d})`:`DNS Worker (${l})`,h=d?`DNS Worker DoH - ${l} (${d})`:`DNS Worker DoH - ${l}`,g=d?`DNS Worker DoH configuration profile for ${d} via ${l}`:`DNS Worker DoH configuration profile via ${l}`,_=d?`Configures encrypted DNS over HTTPS (DoH) for ${d} via ${l}`:`Configures encrypted DNS over HTTPS (DoH) via ${l}`;return ee({PayloadContent:[{DNSSettings:{DNSProtocol:`HTTPS`,ServerHTTPVersion:3,ServerURL:u},OnDemandRules:[{Action:`Connect`,InterfaceTypeMatch:`WiFi`},{Action:`Connect`,InterfaceTypeMatch:`Cellular`},{Action:`Disconnect`}],PayloadDescription:_,PayloadDisplayName:h,PayloadIdentifier:`com.apple.dnsSettings.managed.${f}`,PayloadName:h,PayloadType:`com.apple.dnsSettings.managed`,PayloadUUID:f,PayloadVersion:1}],PayloadDescription:g,PayloadDisplayName:m,PayloadIdentifier:`com.dnsworker.profile.${i}`,PayloadName:m,PayloadRemovalDisallowed:!1,PayloadType:`Configuration`,PayloadUUID:p,PayloadVersion:1},{indent:` `})}const we=({isMobile:e,copyToClipboard:t,profileKey:n,profileName:i,accessPointName:a,currentIps:o,dotDomain:s})=>{let{t:c}=v(),{isCloudflare:d}=Y();return(0,Z.jsxs)(`div`,{className:`group relative overflow-hidden rounded-xl border border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 shadow-sm`,children:[(0,Z.jsx)(Q,{step:3}),(0,Z.jsxs)(V,{id:`setup-tabs`,renderActiveTabPanelOnly:!0,vertical:!e,size:`large`,className:K(`p-4 md:p-6 setup-tabs-container relative z-10 bg-transparent`,e&&[`[&_.bp6-tab-list]:overflow-x-auto!`,`[&_.bp6-tab-list]:flex-nowrap!`,`[&_.bp6-tab-list]:pb-1`,`[&_.bp6-tab-list]:scrollbar-none`,`[&_.bp6-tab-list]:[-ms-overflow-style:none]`,`[&_.bp6-tab-list::-webkit-scrollbar]:hidden`,`[&_.bp6-tab]:shrink-0`]),children:[(0,Z.jsx)(R,{id:`browsers`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(g,{size:16,className:`inline mr-2`}),c(`setup.browsers`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(j,{className:`font-bold`,children:c(`setup.browserTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.browserSteps`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 cursor-pointer`,onClick:()=>t(`chrome://settings/security`),children:c(`setup.browserTips`,`or copy this URL to the address bar: `)+`chrome://settings/security`})]})}),(0,Z.jsx)(R,{id:`apple`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(_,{size:16,className:`inline mr-2`}),c(`setup.apple`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(j,{className:`font-bold`,children:c(`setup.appleTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.appleDesc`)}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 text-center`,children:c(`setup.appleWarning`)}),(0,Z.jsxs)(`div`,{className:`p-6 bg-gray-50 dark:bg-gray-800 rounded-xl border border-dashed border-gray-300 dark:border-gray-700 flex flex-col items-center justify-center`,children:[(0,Z.jsx)(A,{icon:`document`,size:40,className:`opacity-20 mb-4`}),(0,Z.jsx)(M,{intent:k.PRIMARY,text:c(`setup.downloadConfig`),icon:`download`,onClick:()=>{let e=Ce({profileKey:n,profileName:i,accessPointName:a,origin:window.location.origin}),t=new Blob([e],{type:`application/x-apple-aspen-config`}),r=URL.createObjectURL(t),o=document.createElement(`a`);o.href=r;let s=$(i,a),c=Se(window.location.origin);o.download=`dns_worker-${(s||c).replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,`_`).replace(/_+/g,`_`).replace(/^_|_$/g,``)}-${n}.mobileconfig`,o.click(),URL.revokeObjectURL(r)}})]}),(0,Z.jsx)(`p`,{className:`text-[10px] opacity-50 mt-4! text-center`,children:c(`setup.appleInstallHint`)})]})}),(0,Z.jsx)(R,{id:`windows`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(b,{size:16,className:`inline mr-2`}),c(`setup.windows`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(j,{className:`font-bold`,children:c(`setup.windowsTitle`)}),(0,Z.jsxs)(`ol`,{className:`list-decimal list-inside space-y-4 text-sm leading-relaxed`,children:[(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`a`,{href:`ms-settings:network-status`,children:c(`setup.windowsStep0`)})}),(0,Z.jsx)(`li`,{children:c(`setup.windowsStep1`)}),(0,Z.jsxs)(`li`,{children:[c(`setup.windowsStep2`),(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:o.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(e.ip),icon:`duplicate`,className:`font-mono`,children:e.ip}),(0,Z.jsx)(`span`,{className:`text-[9px] opacity-50 ml-1 font-mono`,children:e.area})]},e.ip))})]}),(0,Z.jsx)(`li`,{children:c(`setup.windowsStep3`)}),(0,Z.jsx)(`li`,{children:c(`setup.windowsStep4`)})]})]})}),(0,Z.jsx)(R,{id:`linux`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(u,{size:16,className:`inline mr-2`}),c(`setup.linux`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(j,{className:`font-bold`,children:c(`setup.linuxTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.linuxDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:c(`setup.linuxStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`})}),(0,Z.jsx)(M,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`curl -sL "${window.location.origin}/setup.sh?key=${n}&origin=${window.location.origin}" | sudo bash`)}})]})]}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(`p`,{className:`text-sm font-bold`,children:c(`setup.linuxStep2`)})})]})}),(0,Z.jsx)(R,{id:`routeros`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(l,{size:16,className:`inline mr-2`}),c(`setup.routeros`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(j,{className:`font-bold`,children:c(`setup.routerosTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.routerosDesc`)}),(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-bold mb-2`,children:c(`setup.routerosStep1`)}),(0,Z.jsxs)(`div`,{className:`relative group`,children:[(0,Z.jsx)(`pre`,{className:`bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto text-xs font-mono border border-gray-200 dark:border-gray-700`,children:(0,Z.jsx)(`code`,{children:`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`})}),(0,Z.jsx)(M,{className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity`,icon:`duplicate`,minimal:!0,small:!0,onClick:()=>{t(`/ip dns set use-doh-server="${window.location.origin}/${n}" verify-doh-cert=yes`)}})]})]}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.routerosNote`)}),(0,Z.jsxs)(`a`,{href:`https://help.mikrotik.com/docs/spaces/ROS/pages/37748767/DNS`,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1 text-xs text-blue-500 hover:underline`,children:[(0,Z.jsx)(m,{size:10}),` `,c(`setup.routerosDocs`)]})]})}),(0,Z.jsx)(R,{id:`android`,title:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(r,{size:16,className:`inline mr-2`}),c(`setup.android`)]}),panel:(0,Z.jsxs)(`div`,{className:`space-y-4 md:ml-4 mt-4 md:mt-0`,children:[(0,Z.jsx)(j,{className:`font-bold`,children:c(`setup.androidTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:c(`setup.androidDesc`)}),d?(0,Z.jsxs)(E,{intent:k.WARNING,icon:`warning-sign`,className:`text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-semibold mb-1`,children:c(`setup.dotUnavailableCfTitle`)}),(0,Z.jsx)(`div`,{children:c(`setup.dotUnavailableCfDesc`)})]}):(()=>{let e=/^(\d{1,3}\.){3}\d{1,3}$/.test(window.location.hostname)||window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname.includes(`:`),r=(s||``).trim().replace(/^\*\./,``),i=!J(r)&&r||(e?``:window.location.hostname);return(0,Z.jsxs)(`div`,{className:`p-4 bg-gray-50 dark:bg-gray-800/60 rounded-xl border border-gray-200 dark:border-gray-700 space-y-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-gray-700 dark:text-gray-300`,children:c(`setup.androidDotTitle`,`私有 DNS (DoT / DoQ)`)}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c(`setup.androidDotDesc`,`支持 Android 原生“私有 DNS (DoT)”及各类现代 DoQ 客户端。提供商主机名:`)}),i?(0,Z.jsx)(`div`,{className:`space-y-3 pt-1`,children:(0,Z.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-2`,children:(0,Z.jsx)(U,{minimal:!0,interactive:!0,onClick:()=>t(`${n}.${i}`),icon:`duplicate`,className:`font-mono text-xs sm:text-sm py-1 px-3 self-start`,intent:k.PRIMARY,children:`${n}.${i}`})})}):(0,Z.jsx)(E,{intent:k.WARNING,icon:`warning-sign`,className:`text-xs`,children:c(`setup.androidIpNotice`,`检测到当前通过 IP 或本地地址访问面板。DoT / DoQ 仅接受域名,请在 .env 中配置 SERVERFULL_DOT_DOMAIN (例如 dns.example.com) 后刷新。`)})]})})(),!d&&(0,Z.jsx)(E,{intent:k.PRIMARY,icon:`info-sign`,className:`text-xs`,children:c(`setup.androidWarning`)})]})})]})]})};function Te({profileId:e,accessPoints:t,onRefresh:n,toasterRef:r}){let{t:i}=v(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(null),[O,A]=(0,X.useState)(!1),[j,M]=(0,X.useState)(``);return{isAddDialogOpen:a,setIsAddDialogOpen:o,newApName:s,setNewApName:c,isAdding:l,renameApId:d,setRenameApId:f,renameApName:p,setRenameApName:m,isRenaming:h,rotatingApId:_,deletingApId:b,newApNameFocused:S,setNewApNameFocused:C,renameApNameFocused:w,setRenameApNameFocused:T,rotateConfirmApId:E,setRotateConfirmApId:D,isSearchOpen:O,setIsSearchOpen:A,searchQuery:j,setSearchQuery:M,filteredAccessPoints:t.filter(e=>e.name.toLowerCase().includes(j.toLowerCase())||e.token.toLowerCase().includes(j.toLowerCase())),isValidApName:e=>le.test(e),handleAdd:async()=>{let a=s.trim();if(a){if(t.some(e=>e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:k.DANGER});return}u(!0);try{await ue(e,a),r.current?.show({message:i(`setup.accessPointCreated`),intent:k.SUCCESS}),o(!1),c(``),n()}catch(e){let t=e.message||`Failed to create access point`,n=t;if(t.startsWith(`Access point limit exceeded`)){let e=t.match(/\(max (\d+)\)/),r=e?e[1]:`100`;n=i(`setup.accessPointLimitExceeded`,{max:r,defaultValue:`Access Point limit exceeded (max ${r})`})}r.current?.show({message:n,intent:k.DANGER})}finally{u(!1)}}},handleRename:async()=>{let a=p.trim();if(!(!a||!d)){if(t.some(e=>e.id!==d&&e.name.toLowerCase()===a.toLowerCase())){r.current?.show({message:i(`setup.accessPointNameExists`,`Access Point name already exists`),intent:k.DANGER});return}g(!0);try{await ae(e,d,a),r.current?.show({message:i(`setup.accessPointRenamed`),intent:k.SUCCESS}),f(null),n()}catch(e){r.current?.show({message:e.message||`Failed to rename access point`,intent:k.DANGER})}finally{g(!1)}}},handleRotate:async t=>{y(t);try{await te(e,t),r.current?.show({message:i(`setup.tokenRotated`),intent:k.SUCCESS}),n()}catch(e){console.error(e)}finally{y(null)}},handleDelete:async t=>{if(confirm(i(`setup.deleteAccessPointConfirm`))){x(t);try{await me(e,t),r.current?.show({message:i(`setup.accessPointDeleted`),intent:k.SUCCESS}),n()}catch(e){console.error(e)}finally{x(null)}}}}}const Ee=({isOpen:e,onClose:t,newApName:n,setNewApName:r,newApNameFocused:i,setNewApNameFocused:a,handleAdd:o,isAdding:s,isValidApName:c})=>{let{t:l}=v();return(0,Z.jsxs)(B,{isOpen:e,onClose:t,title:l(`setup.addAccessPoint`),children:[(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:P.TOP,intent:k.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(L,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:G,children:(0,Z.jsxs)(`div`,{className:T,children:[(0,Z.jsx)(M,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(M,{intent:k.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.create`)})]})})]})},De=({isOpen:e,onClose:t,renameApName:n,setRenameApName:r,renameApNameFocused:i,setRenameApNameFocused:a,handleRename:o,isRenaming:s,isValidApName:c})=>{let{t:l}=v();return(0,Z.jsxs)(B,{isOpen:e,onClose:t,title:l(`setup.renameAccessPoint`),children:[(0,Z.jsx)(`div`,{className:N,children:(0,Z.jsx)(W,{content:l(`setup.accessPointNameFormatTip`,`1-30 characters, letters, numbers, hyphens and underscores allowed`),isOpen:i,position:P.TOP,intent:k.PRIMARY,className:`w-full`,children:(0,Z.jsx)(`div`,{className:`w-full block`,children:(0,Z.jsx)(L,{autoFocus:!0,large:!0,placeholder:l(`setup.accessPointName`),value:n,onChange:e=>r(e.target.value),onFocus:()=>a(!0),onBlur:()=>a(!1)})})})}),(0,Z.jsx)(`div`,{className:G,children:(0,Z.jsxs)(`div`,{className:T,children:[(0,Z.jsx)(M,{onClick:t,children:l(`common.cancel`,`Cancel`)}),(0,Z.jsx)(M,{intent:k.PRIMARY,onClick:o,loading:s,disabled:!c(n),children:l(`common.save`)})]})})]})},Oe=({ap:e,totalApCount:t,toasterRef:r,onRenameTrigger:i,rotateConfirmApId:o,setRotateConfirmApId:s,rotatingApId:c,handleRotate:l,deletingApId:u,handleDelete:f})=>{let{t:p}=v();return(0,Z.jsx)(H,{title:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(a,{size:16}),(0,Z.jsx)(`span`,{children:e.name})]}),className:`shadow-none! rounded-lg!`,children:(0,Z.jsxs)(F,{children:[(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`DoH URL`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-mono bg-blue-50 text-blue-600 dark:bg-blue-900/20 dark:text-blue-400 px-2 py-1 rounded cursor-pointer hover:bg-blue-100 dark:hover:bg-blue-900/40 transition-colors break-all`,onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/${e.token}`),r.current?.show({message:p(`setup.copied`),intent:k.SUCCESS})},title:p(`setup.copyUrl`),children:[(0,Z.jsx)(`span`,{className:`select-all`,children:`${window.location.origin}/${e.token}`}),(0,Z.jsx)(h,{size:14,className:`shrink-0`})]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:p(`setup.accessPointToken`)}),(0,Z.jsx)(`span`,{className:`text-sm font-mono bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded select-all break-all`,children:e.token})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between items-start gap-4`,children:[(0,Z.jsx)(`span`,{className:`text-xs opacity-50 mt-1`,children:`Created`}),(0,Z.jsx)(`span`,{className:`text-sm`,children:pe(new Date(e.created_at*1e3))})]})]}),(0,Z.jsxs)(`div`,{className:`mt-4 flex gap-2 flex-wrap`,children:[(0,Z.jsx)(M,{small:!0,icon:(0,Z.jsx)(d,{size:14}),text:p(`setup.renameAccessPoint`),onClick:()=>i(e.id,e.name)}),(0,Z.jsx)(D,{isOpen:o===e.id,onInteraction:e=>{e||s(null)},content:(0,Z.jsxs)(`div`,{className:`p-4 space-y-3 dark:bg-gray-800 dark:text-white max-w-xs`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed`,children:p(`setup.rotateTokenConfirmDesc`,`Rotating the key will immediately disconnect devices using the old key. Are you sure you want to continue?`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(M,{small:!0,minimal:!0,text:p(`common.cancel`,`Cancel`),onClick:()=>s(null)}),(0,Z.jsx)(M,{small:!0,intent:k.DANGER,text:p(`common.confirm`,`Confirm`),onClick:()=>{s(null),l(e.id)}})]})]}),placement:`top`,children:(0,Z.jsx)(M,{small:!0,icon:(0,Z.jsx)(n,{size:14}),text:p(`setup.rotateToken`),loading:c===e.id,onClick:()=>s(e.id)})}),(0,Z.jsx)(M,{small:!0,intent:k.DANGER,icon:(0,Z.jsx)(S,{size:14}),text:p(`setup.deleteAccessPoint`),loading:u===e.id,onClick:()=>f(e.id),disabled:t<=1,title:t<=1?`Cannot delete the only access point`:void 0})]})]})})},ke=({isOpen:e,onClose:t,profileId:n,isMobile:r,accessPoints:i,loading:a,onRefresh:s,toasterRef:c})=>{let{t:l}=v(),{isAddDialogOpen:u,setIsAddDialogOpen:d,newApName:p,setNewApName:m,isAdding:h,renameApId:g,setRenameApId:_,renameApName:y,setRenameApName:b,isRenaming:x,rotatingApId:S,deletingApId:C,newApNameFocused:w,setNewApNameFocused:T,renameApNameFocused:E,setRenameApNameFocused:D,rotateConfirmApId:A,setRotateConfirmApId:j,isSearchOpen:N,setIsSearchOpen:P,searchQuery:F,setSearchQuery:I,filteredAccessPoints:R,isValidApName:z,handleAdd:B,handleRename:V,handleRotate:H,handleDelete:U}=Te({profileId:n,accessPoints:i,onRefresh:s,toasterRef:c});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(_e,{isOpen:e,onClose:t,title:N?(0,Z.jsx)(L,{leftIcon:`search`,placeholder:l(`setup.searchAccessPoints`,`Search...`),value:F,onChange:e=>I(e.target.value),rightElement:(0,Z.jsx)(M,{icon:`cross`,minimal:!0,onClick:()=>{P(!1),I(``)}}),autoFocus:!0}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{children:l(`setup.manageAccessPoints`)}),(0,Z.jsx)(M,{icon:(0,Z.jsx)(o,{size:14}),minimal:!0,onClick:()=>P(!0),className:`opacity-50 hover:opacity-100`})]}),icon:`diagram-tree`,size:r?`100%`:`450px`,children:[(0,Z.jsx)(M,{fill:!0,intent:k.PRIMARY,icon:(0,Z.jsx)(f,{size:16}),text:l(`setup.addAccessPoint`),onClick:()=>d(!0),large:!0}),a?(0,Z.jsx)(`div`,{className:`flex justify-center p-8`,children:(0,Z.jsx)(O,{})}):(0,Z.jsx)(`div`,{className:`space-y-4 mt-4`,children:R.map(e=>(0,Z.jsx)(Oe,{ap:e,totalApCount:i.length,toasterRef:c,onRenameTrigger:(e,t)=>{_(e),b(t)},rotateConfirmApId:A,setRotateConfirmApId:j,rotatingApId:S,handleRotate:H,deletingApId:C,handleDelete:U},e.id))})]}),(0,Z.jsx)(Ee,{isOpen:u,onClose:()=>{d(!1),m(``)},newApName:p,setNewApName:m,newApNameFocused:w,setNewApNameFocused:T,handleAdd:B,isAdding:h,isValidApName:z}),(0,Z.jsx)(De,{isOpen:!!g,onClose:()=>_(null),renameApName:y,setRenameApName:b,renameApNameFocused:E,setRenameApNameFocused:D,handleRename:V,isRenaming:x,isValidApName:z})]})},Ae=({profileId:e,profileKey:t,profileName:n,toasterRef:r})=>{let i=fe(),{t:a}=v(),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),m=async()=>{l(!0);try{s(await de(e))}catch(e){console.error(e)}finally{l(!1)}};(0,X.useEffect)(()=>{m()},[e]);let[h,g]=(0,X.useState)(n||``);(0,X.useEffect)(()=>{n?g(n):e&&he(e).then(e=>{e?.name&&g(e.name)}).catch(()=>{})},[e,n]);let _=(0,X.useMemo)(()=>o.length===0?null:o.find(e=>e.id===f)||o[0],[o,f]),y=_?_.token:t,b=_?_.name:void 0,x=`${window.location.origin}/${y}`,[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,A]=(0,X.useState)(!1),[j,M]=(0,X.useState)(null),[N,P]=(0,X.useState)(null),[F,I]=(0,X.useState)({ipv4:[],ipv6:[]}),[L,R]=(0,X.useState)(null),z=e=>{navigator.clipboard.writeText(e),r?.current?.show({message:a(`setup.copied`),intent:k.SUCCESS})},B=async()=>{T(!0),R(null);try{let[t,n]=await Promise.all([ne(),se()]);if(t.ip&&(t.country===`UNKNOWN`||!t.country))try{let e=await fetch(`/api/geoip?ip=${encodeURIComponent(t.ip)}`);if(e.ok){let n=await e.json();n.success&&(n.country&&(t.country=n.country),n.region&&(t.region=n.region),n.city&&(t.city=n.city),n.timezone?.id&&(t.timezone=n.timezone.id),n.connection?.org&&(t.asOrganization=n.connection.org))}}catch{}C(t),M(n),t.timezone&&t.timezone!==`UNKNOWN`&&ce(t.timezone);let r=window.location.hostname===`localhost`||window.location.hostname===`127.0.0.1`||window.location.hostname===`::1`||window.location.hostname.startsWith(`192.168.`)||window.location.hostname.startsWith(`10.`)||/^172\.(1[6-9]|2\d|3[01])\./.test(window.location.hostname),i=!!(t.dotDomain&&!J(t.dotDomain));oe(r&&i||i?t.dotDomain:window.location.hostname||``).then(e=>P(e)).catch(e=>console.warn(`Failed fetching domain geo location:`,e));let a=t.substituteDomain||`www.okx.com`;re().then(e=>{I(t=>t.ipv4.length>0||t.ipv6.length>0?t:{ipv4:e.ip?[e.ip]:[],ipv6:e.ipv6?[e.ipv6]:[]})}).catch(()=>{}),ie(a).then(e=>{(e.ipv4.length>0||e.ipv6.length>0)&&I(e)}).catch(e=>console.warn(`Failed resolving substitute domain DNS IPs:`,e)),R({success:!!t.connectedProfileId,profileMatch:t.connectedProfileId===e})}catch(e){console.error(`Verification failed`,e)}finally{T(!1)}};(0,X.useEffect)(()=>{B()},[e]);let V=(0,X.useMemo)(()=>{let e=[],t=(F.ipv4||[]).slice(0,2),n=(F.ipv6||[]).slice(0,2),r=S?.substituteDomain||`www.okx.com`;for(let n of t)e.push({ip:n,area:`${r} IPv4`});for(let t of n)e.push({ip:t,area:`${r} IPv6`});return e},[F,S?.substituteDomain]);return(0,Z.jsxs)(`div`,{className:`mx-auto space-y-8 pb-24 ${i?`p-1`:`px-8 max-w-5xl`}`,children:[(0,Z.jsx)(ve,{isMobile:i}),(0,Z.jsx)(ye,{isVerifying:w,verifyResult:L,handleVerify:B,isMobile:i,clientInfo:S,showIp:E,setShowIp:D,showLocation:O,setShowLocation:A,traceInfo:j,edgeLocation:N}),(0,Z.jsx)(be,{accessPoints:o,selectedApId:_?.id||null,onSelectAp:p,accessPointName:b,onManageAccessPoints:()=>d(!0),isMobile:i}),(0,Z.jsx)(xe,{dohUrl:x,copyToClipboard:z,isMobile:i}),(0,Z.jsx)(we,{isMobile:i,copyToClipboard:z,profileKey:y,profileName:h||void 0,accessPointName:b,currentIps:V,dotDomain:S?.dotDomain}),(0,Z.jsx)(ke,{isOpen:u,onClose:()=>d(!1),profileId:e,isMobile:i,accessPoints:o,loading:c,onRefresh:m,toasterRef:r})]})};export{Ae as SetupView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{S as t,b as n}from"./vendor-icons-other-BTYC6Wvz.js";import{
|
|
1
|
+
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{S as t,b as n}from"./vendor-icons-other-BTYC6Wvz.js";import{V as r,g as i}from"./vendor-ui-core-CodM8CpF.js";var a=e(t(),1),o=e(n(),1);const s=({isOpen:e,onClose:t,title:n,icon:s,size:c,className:l,children:u,...d})=>{let f=(0,a.useRef)(null),p=e=>{let t=e.touches[0];f.current={x:t.clientX,y:t.clientY}},m=e=>{if(!f.current)return;let n=e.touches[0],r=n.clientX-f.current.x,i=n.clientY-f.current.y;r>80&&Math.abs(r)>Math.abs(i)*1.5&&(t(),f.current=null)},h=()=>{f.current=null},g=`dark:bg-gray-900 dark:text-white shadow-none! bg-transparent! bg-bulletin! backdrop-blur-sm! ${l||``}`;return(0,o.jsx)(i,{isOpen:e,onClose:t,title:n,icon:s,position:r.RIGHT,size:c,className:g,...d,children:(0,o.jsx)(`div`,{className:`p-6 space-y-4 overflow-y-auto h-full pb-safe`,onTouchStart:p,onTouchMove:m,onTouchEnd:h,children:u})})};export{s as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{B as t,C as n,H as r,I as i,M as a,N as o,S as s,at as c,et as l,gt as u,ht as d,nn as f,ut as p,w as m,x as h}from"./vendor-react-DYK5a2J9.js";import{S as g,b as _}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-DlmslyBB.js";import{C as v,E as y,H as b,M as x,N as S,P as C,S as w,U as T,_ as E,d as D,f as O,h as k,k as A,p as j,r as M,u as N}from"./vendor-ui-core-CodM8CpF.js";import{_t as P}from"./vendor-utils-Bab4qB3W.js";import{B as F,F as I,I as L,K as R,L as z,Lt as B,M as V,N as H,P as U,R as W,V as G,d as K,gn as q,h as J,l as ee,o as te,u as ne,z as Y}from"./index-Bw8TL1xo.js";import{t as X}from"./async-R_IFRE5c.js";var Z=e(g(),1),Q=e(_(),1);const $=({users:e,currentUserId:t,onRefresh:n,registrationEnabled:r=!0,maxUsers:i,onRefreshSettings:o,onSavingChange:s,toasterRef:c})=>{let{t:l}=f(),[u,d]=(0,Z.useState)(!1),[p,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(``),[y,S]=(0,Z.useState)(`user`),[E,P]=(0,Z.useState)(!1),[F,I]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(r),[z,B]=(0,Z.useState)(!1),U=i!=null&&i!==``?parseInt(String(i),10):0,W=U>0&&e.length>=U;(0,Z.useEffect)(()=>{R(r)},[r]);let q=async e=>{let t=L;R(e),B(!0),s?.(!0);try{await X(G({registration_enabled:String(e)}),1e4),c?.current?.show({message:l(`common.saveSuccess`,`保存成功`),intent:b.SUCCESS,icon:`tick`}),o?.()}catch(e){console.error(e),R(t),c?.current?.show({message:e.message||l(`common.saveFailed`,`保存失败`),intent:b.DANGER,icon:`error`})}finally{B(!1),s?.(!1)}},Y=async()=>{if(!ee.test(p)){alert(l(`account.formatTipUsername`));return}if(!te.test(_)){alert(l(`account.formatTipPassword`));return}P(!0);try{await V({username:p,password:await K(_,p),role:y}),d(!1),g(``),v(``),I(!1),n()}catch(e){console.error(e),alert(ne(e,l))}finally{P(!1)}},$=async e=>{if(confirm(l(`account.confirmDeleteUser`)))try{await H(e),n()}catch(e){console.error(e)}};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(a,{size:20,className:`text-red-500`}),(0,Q.jsx)(x,{style:{margin:0},children:l(`account.userManagement`)}),U>0?(0,Q.jsxs)(M,{minimal:!0,intent:W?b.DANGER:b.PRIMARY,round:!0,children:[e.length,` / `,U]}):(0,Q.jsx)(M,{minimal:!0,round:!0,children:e.length})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(k,{label:l(`account.enableRegistration`,`开放新用户注册`),checked:L,disabled:z,onChange:e=>q(e.currentTarget.checked),className:`mb-0`}),(0,Q.jsx)(C,{className:`whitespace-nowrap`,icon:(0,Q.jsx)(h,{size:16}),intent:b.SUCCESS,text:l(`account.createUser`),disabled:W,title:W?l(`auth.maxUsersReached`,`当前系统已达到用户数量上限,无法创建新用户。`):void 0,onClick:()=>d(!0)})]})]}),(0,Q.jsx)(w,{elevation:T.ONE,className:`p-0 overflow-hidden overflow-x-auto`,children:(0,Q.jsxs)(N,{interactive:!0,striped:!0,className:`w-full whitespace-nowrap`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.username`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.role`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:`MFA`}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:`ID`}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.createdAt`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.lastActive`)}),(0,Q.jsx)(`th`,{className:`whitespace-nowrap`,children:l(`account.lastResolve`)}),(0,Q.jsx)(`th`,{className:`text-right whitespace-nowrap`,children:l(`account.actions`)})]})}),(0,Q.jsx)(`tbody`,{children:e.map(e=>(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`td`,{className:`font-bold whitespace-nowrap`,children:e.username}),(0,Q.jsx)(`td`,{className:`whitespace-nowrap`,children:(0,Q.jsx)(M,{minimal:!0,intent:e.role===`admin`?b.DANGER:b.NONE,className:`whitespace-nowrap`,children:e.role===`admin`?l(`account.roleAdmin`):l(`account.roleUser`)})}),(0,Q.jsx)(`td`,{className:`whitespace-nowrap`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[!!e.totp_enabled&&(0,Q.jsx)(M,{minimal:!0,intent:b.SUCCESS,className:`whitespace-nowrap`,children:`TOTP`}),!!(e.passkeys_count&&e.passkeys_count>0)&&(0,Q.jsx)(M,{minimal:!0,intent:b.PRIMARY,className:`whitespace-nowrap`,children:`Passkey`}),!e.totp_enabled&&!(e.passkeys_count&&e.passkeys_count>0)&&(0,Q.jsx)(M,{minimal:!0,intent:b.NONE,style:{color:`#8a9ba8`},className:`whitespace-nowrap`,children:l(`account.mfaNone`,`无`)})]})}),(0,Q.jsx)(`td`,{className:`whitespace-nowrap`,children:(0,Q.jsx)(`code`,{className:`text-xs`,children:e.id})}),(0,Q.jsx)(`td`,{className:`text-xs text-gray-500 whitespace-nowrap`,children:e.created_at?J(new Date(e.created_at*1e3)):`-`}),(0,Q.jsx)(`td`,{className:`text-xs text-gray-500 whitespace-nowrap`,children:e.last_active_at?J(new Date(e.last_active_at*1e3)):`-`}),(0,Q.jsx)(`td`,{className:`text-xs text-gray-500 whitespace-nowrap`,children:e.last_resolve_at?J(new Date(e.last_resolve_at*1e3)):`-`}),(0,Q.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,Q.jsx)(`div`,{className:`inline-flex items-center gap-1`,children:(0,Q.jsx)(C,{minimal:!0,intent:b.DANGER,icon:(0,Q.jsx)(m,{size:14}),disabled:e.id===t,onClick:()=>$(e.id)})})})]},e.id))})]})}),(0,Q.jsx)(A,{isOpen:u,onClose:()=>{d(!1),I(!1)},title:l(`account.createNewUser`),icon:`user`,children:(0,Q.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,Q.jsx)(j,{label:l(`account.username`),children:(0,Q.jsx)(O,{value:p,onChange:e=>g(e.target.value),placeholder:l(`auth.usernamePlaceholder`)})}),(0,Q.jsx)(j,{label:l(`account.initialPassword`),children:(0,Q.jsx)(O,{type:F?`text`:`password`,value:_,onChange:e=>v(e.target.value),placeholder:l(`auth.passwordPlaceholder`),rightElement:(0,Q.jsx)(C,{minimal:!0,icon:F?`eye-open`:`eye-off`,onClick:()=>I(!F),title:F?l(`auth.hidePassword`,`Hide password`):l(`auth.showPassword`,`Show password`)})})}),(0,Q.jsx)(j,{label:l(`account.userRole`),children:(0,Q.jsx)(D,{fill:!0,value:y,onChange:e=>S(e.target.value),options:[{label:l(`account.roleUser`),value:`user`},{label:l(`account.roleAdmin`),value:`admin`}]})}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-6`,children:[(0,Q.jsx)(C,{text:l(`account.cancel`),onClick:()=>d(!1)}),(0,Q.jsx)(C,{intent:b.PRIMARY,text:l(`account.createNow`),loading:E,onClick:Y})]})]})})]})},re=({toasterRef:e,onSavingChange:t})=>{let{t:n}=f(),[r,a]=(0,Z.useState)(``),[o,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)([]),[g,_]=(0,Z.useState)(null),[D,k]=(0,Z.useState)(null),[A,N]=(0,Z.useState)([]),[P,F]=(0,Z.useState)(!1),[I,z]=(0,Z.useState)(null),[B,V]=(0,Z.useState)(null),H=(0,Z.useCallback)(async()=>{F(!0);try{N(await L())}catch(e){console.warn(`Failed to fetch distributed filter lists`,e)}finally{F(!1)}},[]);(0,Z.useEffect)(()=>{R().then(e=>{e&&Array.isArray(e)&&h(e.map(e=>({label:String(n(e.label,{defaultValue:e.label})),url:String(e.url||``)})))}).catch(e=>console.warn(`Failed to fetch preset filters`,e)),H()},[n,H]);let W=async()=>{let i=r.trim();if(i){p(!0),k(null),_(null),t?.(!0);try{let t=await U(i);_(t),a(``);let r=t.failedCount>0?n(`admin.distributeFilter.toastPartialSuccess`,`系统过滤列表已下发至 {{added}} 位用户,{{failed}} 位用户下发失败`,{added:t.addedCount,failed:t.failedCount}):n(`admin.distributeFilter.toastSuccess`,`系统过滤列表已成功下发至 {{count}} 位用户`,{count:t.addedCount});e?.current?.show({message:r,intent:t.failedCount>0&&t.addedCount===0?b.DANGER:t.failedCount>0?b.WARNING:b.SUCCESS,icon:t.failedCount>0&&t.addedCount===0?`error`:`tick`}),await H()}catch(t){let n=t instanceof Error?t.message:String(t);k(n),e?.current?.show({message:n,intent:b.DANGER,icon:`error`})}finally{p(!1),t?.(!1)}}},G=async r=>{z(r),V(null),t?.(!0);try{let t=await Y(r);e?.current?.show({message:n(`admin.distributeFilter.toastRevokeSuccess`,`已成功撤回系统过滤列表,移除了 {{count}} 位用户的系统规则`,{count:t.revokedCount}),intent:b.SUCCESS,icon:`tick`}),await H()}catch(t){let n=t instanceof Error?t.message:String(t);e?.current?.show({message:n,intent:b.DANGER,icon:`error`})}finally{z(null),t?.(!1)}};return(0,Q.jsxs)(w,{elevation:T.ZERO,className:`p-6 border border-gray-200 dark:border-gray-800 rounded-xl space-y-6`,children:[(0,Q.jsx)(`div`,{className:`flex items-start justify-between`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(x,{className:`flex items-center space-x-2 text-base font-semibold`,children:[(0,Q.jsx)(i,{className:`w-5 h-5 text-indigo-500`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.title`,`系统过滤列表 (管理员)`)})]}),(0,Q.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:n(`admin.distributeFilter.description`,`向系统中所有用户账号下发系统级过滤列表。规则自动继承并应用于所有用户账号,带有“系统”标签。如果用户已存在相同规则则自动跳过。`)})]})}),m.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 flex items-center space-x-1`,children:[(0,Q.jsx)(c,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.quickPresets`,`快捷预设`)})]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(e=>(0,Q.jsx)(C,{minimal:!0,small:!0,className:`text-xs`,intent:r===e.url?b.PRIMARY:b.NONE,onClick:()=>a(e.url),children:e.label},e.url))})]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(j,{label:n(`admin.distributeFilter.urlLabel`,`规则列表 URL`),labelFor:`distribute-filter-url`,helperText:n(`admin.distributeFilter.urlHelper`,`支持 AdGuard、Hosts、EasyList 等标准格式 URL`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Q.jsx)(O,{id:`distribute-filter-url`,fill:!0,placeholder:`https://example.com/filter.txt`,value:r,onChange:e=>a(e.target.value),disabled:o,className:`font-mono text-sm`,onKeyDown:e=>{e.key===`Enter`&&r.trim()&&!o&&W()}}),(0,Q.jsx)(C,{intent:b.PRIMARY,icon:(0,Q.jsx)(i,{className:`w-4 h-4 mr-1`}),text:n(`admin.distributeFilter.submitBtn`,`立即下发`),loading:o,disabled:!r.trim(),onClick:W,className:`shrink-0`})]})}),D&&(0,Q.jsxs)(v,{intent:b.DANGER,icon:null,children:[(0,Q.jsxs)(S,{className:`flex items-center gap-2 mb-2 font-semibold`,children:[(0,Q.jsx)(d,{className:`w-4 h-4 shrink-0`}),(0,Q.jsx)(`span`,{children:n(`common.error`,`错误`)})]}),(0,Q.jsx)(`div`,{className:`text-sm`,children:D})]}),g&&(0,Q.jsxs)(v,{intent:g.failedCount>0?g.addedCount>0?b.WARNING:b.DANGER:b.SUCCESS,icon:null,children:[(0,Q.jsxs)(S,{className:`flex items-center gap-2 mb-2 font-semibold`,children:[g.failedCount>0&&g.addedCount===0?(0,Q.jsx)(d,{className:`w-4 h-4 shrink-0 text-red-500`}):(0,Q.jsx)(u,{className:`w-4 h-4 shrink-0 text-green-500`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.resultTitle`,`下发执行完成`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{children:g.failedCount>0?n(`admin.distributeFilter.resultSummaryWithFailed`,`系统共 {{total}} 位用户:成功下发至 {{added}} 位用户,跳过 {{skipped}} 位已存在该规则的用户,{{failed}} 位用户下发失败。`,{total:g.totalUsers,added:g.addedCount,skipped:g.skippedCount,failed:g.failedCount}):n(`admin.distributeFilter.resultSummary`,`系统共 {{total}} 位用户:成功下发至 {{added}} 位用户,跳过 {{skipped}} 位已存在该规则的用户。`,{total:g.totalUsers,added:g.addedCount,skipped:g.skippedCount})}),g.addedUsernames.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 pt-1`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-gray-500`,children:[n(`admin.distributeFilter.addedUsers`,`下发成功用户`),`:`]}),g.addedUsernames.map(e=>(0,Q.jsx)(M,{intent:b.SUCCESS,minimal:!0,round:!0,children:e},e))]}),g.skippedUsernames.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 pt-1`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-gray-500`,children:[n(`admin.distributeFilter.skippedUsers`,`已存在规则用户`),`:`]}),g.skippedUsernames.map(e=>(0,Q.jsx)(M,{intent:b.NONE,minimal:!0,round:!0,children:e},e))]}),g.failedUsernames.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 pt-1`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-red-500 dark:text-red-400`,children:[n(`admin.distributeFilter.failedUsers`,`下发失败用户`),`:`]}),g.failedUsernames.map(e=>(0,Q.jsx)(M,{intent:b.DANGER,minimal:!0,round:!0,children:e},e))]})]})]})]}),(0,Q.jsx)(E,{}),(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`text-sm font-semibold flex items-center space-x-2`,children:[(0,Q.jsx)(l,{className:`w-4 h-4 text-indigo-500`}),(0,Q.jsx)(`span`,{children:n(`admin.distributeFilter.activeDistributedTitle`,`已下发系统规则`)})]}),A.length>0&&(0,Q.jsx)(M,{minimal:!0,round:!0,intent:b.PRIMARY,children:A.length})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:n(`admin.distributeFilter.activeDistributedDesc`,`当前处于系统下发状态且带有“系统”标签的规则列表。撤回后将从所有用户账号中移除此系统规则,用户自建的同名规则不受影响。`)}),P?(0,Q.jsx)(`div`,{className:`text-xs text-gray-400 py-3 text-center`,children:n(`common.loading`,`加载中...`)}):A.length===0?(0,Q.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-gray-500 py-4 px-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg text-center border border-dashed border-gray-200 dark:border-gray-700`,children:n(`admin.distributeFilter.noDistributedFilters`,`当前系统中无已下发的系统过滤列表`)}):(0,Q.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-gray-800 border border-gray-200 dark:border-gray-800 rounded-lg overflow-hidden`,children:A.map(e=>(0,Q.jsxs)(`div`,{className:`p-3 bg-white dark:bg-gray-900 flex flex-col sm:flex-row sm:items-center justify-between gap-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`font-mono text-xs text-gray-800 dark:text-gray-200 truncate select-all`,title:e.url,children:e.url}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-xs text-gray-500`,children:[(0,Q.jsx)(M,{minimal:!0,round:!0,intent:b.PRIMARY,children:n(`admin.distributeFilter.usersCount`,`{{count}} 位用户`,{count:e.userCount})}),e.usernames.length>0&&(0,Q.jsxs)(`span`,{className:`text-xs text-gray-400 truncate max-w-xs`,children:[`(`,e.usernames.join(`, `),`)`]})]})]}),(0,Q.jsx)(`div`,{className:`shrink-0`,children:(0,Q.jsx)(y,{isOpen:B===e.url,onInteraction:t=>V(t?e.url:null),placement:`top-end`,portalClassName:`z-20000`,content:(0,Q.jsxs)(`div`,{className:`p-3 space-y-3 max-w-xs`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold leading-relaxed m-0 text-gray-800 dark:text-gray-200`,children:n(`admin.distributeFilter.revokeConfirm`,`确定撤回此系统过滤列表?系统将从所有用户账号中移除此系统规则,用户自建的同名规则不受影响。`)}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(C,{small:!0,variant:`minimal`,text:n(`common.cancel`,`取消`),onClick:()=>V(null)}),(0,Q.jsx)(C,{small:!0,intent:b.DANGER,loading:I===e.url,text:n(`admin.distributeFilter.confirmRevoke`,`确认撤回`),onClick:()=>G(e.url)})]})]}),children:(0,Q.jsx)(C,{small:!0,intent:b.DANGER,minimal:!0,icon:(0,Q.jsx)(s,{className:`w-3.5 h-3.5`}),text:n(`admin.distributeFilter.revokeBtn`,`撤回`),loading:I===e.url,onClick:()=>V(e.url)})})})]},e.url))})]})]})},ie=({initialSettings:e,onRefresh:t,onSavingChange:n,toasterRef:r})=>{let{t:i}=f(),[a,s]=(0,Z.useState)(e),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{s(e)},[e]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(o,{size:20,className:`text-gray-500`}),(0,Q.jsx)(x,{style:{margin:0},children:i(`account.systemSettings`,`System Settings`)})]}),(0,Q.jsxs)(w,{elevation:T.ONE,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4`,children:[(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(x,{className:`text-sm font-bold opacity-70 text-blue-500`,children:`Cloudflare Turnstile`}),(0,Q.jsx)(j,{label:`Site Key`,children:(0,Q.jsx)(O,{value:a.turnstile_site_key||``,onChange:e=>s({...a,turnstile_site_key:e.target.value}),placeholder:`0x000...`})}),(0,Q.jsx)(j,{label:`Secret Key`,children:(0,Q.jsx)(O,{type:u?`text`:`password`,value:a.turnstile_secret_key||``,onChange:e=>s({...a,turnstile_secret_key:e.target.value}),placeholder:`0x000...`,rightElement:(0,Q.jsx)(C,{minimal:!0,icon:u?`eye-open`:`eye-off`,onClick:()=>d(!u),title:u?i(`auth.hidePassword`,`Hide password`):i(`auth.showPassword`,`Show password`)})})})]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(x,{className:`text-sm font-bold opacity-70 text-green-500`,children:i(`account.featureToggle`,`Feature Toggle`)}),(0,Q.jsx)(k,{label:i(`account.enableTurnstileSignup`,`Enable verification on Signup`),checked:a.turnstile_enabled_signup===`true`,onChange:e=>s({...a,turnstile_enabled_signup:String(e.currentTarget.checked)})}),(0,Q.jsx)(k,{label:i(`account.enableTurnstileLogin`,`Enable verification on Login`),checked:a.turnstile_enabled_login===`true`,onChange:e=>s({...a,turnstile_enabled_login:String(e.currentTarget.checked)})}),(0,Q.jsx)(E,{className:`my-2`}),(0,Q.jsx)(x,{className:`text-sm font-bold opacity-70 text-indigo-500`,children:i(`account.userLimits`,`User Quota`)}),(0,Q.jsx)(j,{label:i(`account.maxUsers`,`Max Users`),helperText:i(`account.maxUsersHelper`,`Maximum number of users allowed in the system (0 for unlimited).`),children:(0,Q.jsx)(O,{type:`number`,min:0,value:a.max_users||``,onChange:e=>s({...a,max_users:e.target.value}),placeholder:`0`})})]})]}),(0,Q.jsx)(E,{className:`my-4`}),(0,Q.jsx)(`div`,{className:`flex justify-end`,children:(0,Q.jsx)(C,{intent:b.PRIMARY,icon:`floppy-disk`,text:i(`common.save`,`Save`),loading:c,onClick:async()=>{l(!0),n?.(!0);try{await X(G({turnstile_site_key:a.turnstile_site_key||``,turnstile_secret_key:a.turnstile_secret_key||``,turnstile_enabled_signup:a.turnstile_enabled_signup||`false`,turnstile_enabled_login:a.turnstile_enabled_login||`false`,max_users:a.max_users||`0`}),1e4),r?.current?.show({message:i(`common.saveSuccess`,`保存成功`),intent:b.SUCCESS,icon:`tick`}),t()}catch(t){console.error(t),s(e),r?.current?.show({message:t.message||i(`common.saveFailed`,`保存失败`),intent:b.DANGER,icon:`error`})}finally{l(!1),n?.(!1)}}})})]})]})},ae=({status:e,onRefresh:n,toasterRef:i})=>{let{t:a}=f(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),m=e?.migrations,h=m?.completed??!1;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(p,{size:20,className:`text-gray-500`}),(0,Q.jsx)(x,{style:{margin:0},children:a(`account.databaseSettings`,`数据库 (管理员)`)})]}),m?(0,Q.jsx)(M,{large:!0,round:!0,intent:h?b.SUCCESS:b.WARNING,icon:h?(0,Q.jsx)(u,{size:16}):(0,Q.jsx)(d,{size:16}),className:`whitespace-nowrap self-start sm:self-auto`,children:h?a(`account.migrationCompleted`,`迁移已完成`):a(`account.migrationPending`,`有待执行迁移`)}):(0,Q.jsx)(M,{large:!0,round:!0,intent:b.NONE,className:`whitespace-nowrap self-start sm:self-auto`,children:a(`common.loading`,`加载中...`)})]}),(0,Q.jsx)(w,{elevation:T.ONE,children:(0,Q.jsxs)(`div`,{className:`space-y-5`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs uppercase font-semibold text-gray-500 tracking-wider`,children:a(`account.databaseEngine`,`数据库服务`)}),(0,Q.jsx)(`div`,{className:`text-sm font-medium mt-1`,children:(e=>e===`Turso`?`Turso (libSQL)`:e===`D1`?`Cloudflare D1`:e===`File`?`SQLite (Local File)`:e||`SQLite`)(e?.databaseService)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs uppercase font-semibold text-gray-500 tracking-wider`,children:a(`account.lastAppliedMigration`,`最近应用版本`)}),(0,Q.jsx)(`div`,{className:`text-sm font-medium font-mono text-gray-700 dark:text-gray-300 mt-1 truncate`,children:m?.lastApplied||a(`account.noMigrationsApplied`,`无`)})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-xs uppercase font-semibold text-gray-500 tracking-wider`,children:a(`account.migrationStatus`,`架构状态`)}),(0,Q.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-300 mt-1`,children:m?h?a(`account.migrationCompletedDesc`,{total:m?.totalAvailable||0}):a(`account.migrationPendingDesc`,{applied:m?.appliedCount||0,total:m?.totalAvailable||0,pending:m?.pendingCount||0}):a(`common.loading`,`加载中...`)})]}),!h&&m&&m.pendingFiles.length>0&&(0,Q.jsxs)(v,{intent:b.WARNING,icon:null,children:[(0,Q.jsxs)(S,{className:`flex items-center gap-2 mb-1 text-xs font-semibold`,children:[(0,Q.jsx)(d,{className:`w-4 h-4 shrink-0`}),(0,Q.jsx)(`span`,{children:a(`account.pendingMigrationsList`,`待应用的架构迁移文件:`)})]}),(0,Q.jsx)(`ul`,{className:`list-disc list-inside text-xs font-mono space-y-0.5 text-gray-700 dark:text-gray-300 max-h-32 overflow-y-auto`,children:m.pendingFiles.map(e=>(0,Q.jsx)(`li`,{children:e},e))})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-gray-100 dark:border-gray-800`,children:[(0,Q.jsx)(C,{minimal:!0,icon:(0,Q.jsx)(t,{size:14,className:c?`animate-spin`:``}),text:a(`account.checkMigration`,`刷新状态`),onClick:async()=>{l(!0);try{await n()}finally{l(!1)}},disabled:o||c}),(0,Q.jsx)(C,{intent:b.PRIMARY,icon:(0,Q.jsx)(r,{size:14}),text:o?a(`account.runningMigration`,`正在迁移...`):a(`account.runMigration`,`执行迁移`),loading:o,disabled:h||o,onClick:async()=>{s(!0);try{let e=await F();i?.current?.show({message:a(`account.migrationSuccess`,{count:e.appliedCount}),intent:b.SUCCESS,icon:`tick`}),await n()}catch(e){console.error(e),i?.current?.show({message:e.message||a(`account.migrationFailed`),intent:b.DANGER,icon:`error`})}finally{s(!1)}}})]})]})})]})},oe=({onSavingChange:e,toasterRef:t})=>{let[r,i]=(0,Z.useState)(null),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(!0),{t:u}=f(),d=q(),[p,m]=(0,Z.useState)({}),[h,g]=(0,Z.useState)(null),_=async()=>{try{s(await W())}catch(e){console.error(e)}},y=async()=>{try{m(await z())}catch(e){console.error(e)}},x=(0,Z.useCallback)(async()=>{try{g(await I())}catch(e){console.error(`Failed to fetch database status:`,e)}},[]),C=(0,Z.useCallback)(async()=>{try{let e=await B();i(e),e.role===`admin`&&(_(),y(),x())}catch(e){console.error(e)}finally{l(!1)}},[x]);return(0,Z.useEffect)(()=>{C()},[C]),c?(0,Q.jsx)(`div`,{className:`p-8 text-center`,children:u(`common.loading`,`加载中...`)}):r?.role===`admin`?(0,Q.jsxs)(`div`,{className:P(`max-w-5xl mx-auto space-y-8`,d?`p-0`:`px-8`),children:[(0,Q.jsxs)(`div`,{className:`flex justify-between items-start sm:items-end gap-3 flex-wrap sm:flex-nowrap`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`bp6-heading`,children:u(`system.title`,`系统管理`)}),(0,Q.jsx)(`p`,{className:`bp6-text-muted`,children:u(`system.subtitle`,`管理用户、系统过滤列表、系统配置与数据库维护`)})]}),(0,Q.jsx)(M,{large:!0,round:!0,intent:b.DANGER,icon:(0,Q.jsx)(a,{size:16}),className:`shrink-0 whitespace-nowrap`,children:u(`account.roleAdmin`,`管理员`)})]}),r?.jwt_secret_warning&&(0,Q.jsxs)(v,{intent:b.WARNING,icon:null,children:[(0,Q.jsxs)(S,{className:`flex items-center gap-2 mb-1 font-semibold`,children:[(0,Q.jsx)(n,{className:`w-4 h-4 shrink-0`}),(0,Q.jsx)(`span`,{children:u(`account.jwtSecretWarningTitle`)})]}),(0,Q.jsx)(`div`,{className:`text-sm leading-relaxed mt-1`,children:u(`account.jwtSecretWarningDesc`)})]}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)($,{users:o,currentUserId:r.id,onRefresh:_,registrationEnabled:p.registration_enabled!==`false`,maxUsers:p.max_users,onRefreshSettings:y,onSavingChange:e,toasterRef:t})}),(0,Q.jsx)(E,{}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)(re,{onSavingChange:e,toasterRef:t})}),(0,Q.jsx)(E,{}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)(ie,{initialSettings:p,onRefresh:y,onSavingChange:e,toasterRef:t})}),(0,Q.jsx)(E,{}),(0,Q.jsx)(`div`,{className:`space-y-4`,children:(0,Q.jsx)(ae,{status:h,onRefresh:x,toasterRef:t})})]}):(0,Q.jsx)(`div`,{className:P(`max-w-5xl mx-auto space-y-6`,d?`p-0`:`px-8`),children:(0,Q.jsx)(v,{intent:b.DANGER,icon:`error`,title:u(`system.accessDenied`,`访问受限`),children:u(`system.accessDeniedDesc`,`当前页面仅限管理员访问。`)})})};export{oe as SystemView};
|