import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,Bt as i,E as a,G as o,I as s,R as c,S as l,U as u,W as d,d as f,lt as ee,p,ut as m,v as h,x as g,y as _}from"./semi-65W_4I1v.js";import{F as v,I as te,L as y,S as b,b as x,c as S,d as C,i as ne,l as w,m as re,p as ie,s as T,u as ae,x as oe}from"./index-DNMXun-U.js";import{t as se}from"./project-options-CMQbwv_U.js";import{a as E}from"./AssetBits-DtqSAj0f.js";import{a as D,i as O,o as k}from"./assetTarget-D2PEjBAg.js";var A=e(t(),1),j={fofa:{label:`FOFA`,maxSize:1e4,defaultFields:`host,ip,port,domain,title,protocol,country,region,city,server`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`host,ip,port,domain`],[`Web 常用`,`host,title,ip,port,domain,protocol,server,icp,country,region,city`],[`情报增强`,`host,ip,port,domain,title,protocol,country,region,city,server,asn,org,icp,header,banner`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`登录页 + 中国`,`title="登录" && country="CN"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!0},zoomeye:{label:`ZoomEye`,maxSize:1e4,defaultFields:`ip,port,domain,hostname,title,service,app,country,city`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`ip,port,domain,hostname`],[`Web 常用`,`ip,port,domain,hostname,title,service,app,country,city`],[`情报增强`,`ip,port,domain,hostname,title,service,app,country,city,org,isp,ssl`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`SSH 服务`,`service="ssh"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!1},quake:{label:`Quake`,maxSize:1e4,defaultFields:`ip,port,domain,service.name,service.http.title,location.country_cn,location.province_cn,location.city_cn`,placeholder:`service.name:"http" AND country_cn:"中国"`,fieldPresets:[[`最小字段`,`ip,port,domain`],[`Web 常用`,`ip,port,domain,service.name,service.http.title,location.country_cn,location.city_cn`],[`情报增强`,`ip,port,domain,service.name,service.http.title,service.http.server,location.country_cn,location.province_cn,location.city_cn,asn`]],queryPresets:[[`HTTP + 中国`,`service.name:"http" AND country_cn:"中国"`],[`443 端口`,`port:443`],[`指定域名`,`domain:"example.com"`],[`指定 IP`,`ip:"1.1.1.1"`]],supportsFull:!0},shodan:{label:`Shodan`,maxSize:1e3,defaultFields:`ip_str,port,hostnames,domains,org,isp,location.country_name,location.city,product,transport`,placeholder:`product:nginx country:CN`,fieldPresets:[[`最小字段`,`ip_str,port,hostnames,domains`],[`Web 常用`,`ip_str,port,hostnames,domains,product,org,location.country_name,location.city`],[`情报增强`,`ip_str,port,hostnames,domains,org,isp,asn,location.country_name,location.city,product,transport,ssl.cert.subject.cn`]],queryPresets:[[`Nginx + 中国`,`product:nginx country:CN`],[`SSH 服务`,`port:22`],[`证书域名`,`ssl.cert.subject.cn:example.com`],[`Amazon 443`,`org:"Amazon" port:443`]],supportsFull:!1}},ce=Object.entries(j).map(([e,t])=>({value:e,label:t.label}));function le(e){return j[e]||j.fofa}function ue(e,t=5){let n=[`host`,`ip`,`port`,`domain`,`title`,`protocol`,`server`,`country`,`city`].filter(t=>e.includes(t)),r=e.filter(e=>!n.includes(e));return[...n,...r].slice(0,t)}function de(e,t){if(!e||typeof e!=`object`)return``;let n=t=>{for(let n of t){let t=e[n];if(Array.isArray(t)&&t.length)return String(t[0]);if(t)return String(t)}return``},r=n([`host`,`url`,`hostname`]);if(r)return r;let i=n([`domain`,`domains`,`hostnames`]);if(i)return i;let a=n([`ip`,`ip_str`]),o=e.port;return a?o?`${a}:${o}`:a:``}function fe(e,t){let n=new Set(t.map(Number));return(e||[]).filter((e,t)=>n.has(t))}var M=e(n(),1),{Text:N}=o;function P(e){if(e==null||e===``)return(0,M.jsx)(N,{type:`tertiary`,children:`—`});let t=Array.isArray(e)?e.join(`, `):typeof e==`object`?JSON.stringify(e):String(e);return(0,M.jsx)(E,{text:t,max:44})}function F(e,t){let n=de(e,t);return n?/^https?:\/\//i.test(n)?(0,M.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`info-collect-target-link`,children:(0,M.jsx)(E,{text:n,max:44})}):(0,M.jsx)(E,{text:n,max:44}):(0,M.jsx)(N,{type:`tertiary`,children:`—`})}function pe({fields:e,results:t,visibleFields:n,selectedKeys:r,onSelectionChange:i,onOpenDetail:a,loading:o}){let s=v(),l=Array.isArray(e)?e:[],u=(Array.isArray(n)?n:[]).filter(e=>l.includes(e)),d=[{title:s(`assets.target`,null,`目标`),dataIndex:`__target`,width:240,render:(e,t)=>F(t,l)},...u.map(e=>({title:e,dataIndex:e,render:(t,n)=>P(n[e])})),{title:s(`common.actions`,null,`操作`),dataIndex:`__actions`,width:90,render:(e,t)=>(0,M.jsx)(c,{theme:`borderless`,size:`small`,onClick:()=>a(t),children:s(`common.view`,null,`详情`)})}],f=(t||[]).map((e,t)=>({...e,__key:String(t),__index:t}));return(0,M.jsx)(T,{columns:d,dataSource:f,rowKey:`__key`,loading:o,pagination:!1,rowSelection:{selectedRowKeys:r,onChange:e=>i(e)},emptyText:s(`infoCollect.noResults`,null,`暂无结果`)})}var{Text:I}=o;function me({visible:e,provider:t,text:n,onClose:i,onApply:a}){let o=v(),[u,f]=(0,A.useState)(!1),[ee,p]=(0,A.useState)(null),[m,h]=(0,A.useState)(null),[g,_]=(0,A.useState)(``),[te,b]=(0,A.useState)(0);(0,A.useEffect)(()=>{if(!e)return;let r=String(n||``).trim();if(!r)return;let i=!1;return f(!0),p(null),h(null),_(``),y.post(`/fofa/parse`,{provider:t,text:r}).then(e=>{i||(h(e||{}),_(String(e?.query||``)))}).catch(e=>{i||p(e)}).finally(()=>{i||f(!1)}),()=>{i=!0}},[e,t,n,te]);let x=e=>{let t=String(g||``).trim();t&&a?.(t,!!e)},C=Array.isArray(m?.warnings)?m.warnings.filter(Boolean):[];return(0,M.jsx)(S,{visible:e,title:o(`infoCollect.parseResultTitle`,null,`语法解析结果`),width:640,onCancel:i,footer:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{theme:`borderless`,onClick:i,children:o(`common.cancel`,null,`取消`)}),(0,M.jsx)(c,{onClick:()=>x(!1),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApply`,null,`填入查询框`)}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,onClick:()=>x(!0),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApplyRun`,null,`填入并查询`)})]}),children:(0,M.jsxs)(s,{vertical:!0,align:`start`,spacing:10,style:{width:`100%`},children:[(0,M.jsxs)(I,{type:`tertiary`,children:[o(`infoCollect.naturalLanguageLabel`,null,`自然语言`),`:`,String(n||``).trim()||`—`]}),u&&(0,M.jsxs)(s,{children:[(0,M.jsx)(d,{size:`small`}),(0,M.jsx)(I,{type:`tertiary`,children:o(`infoCollect.parsePending`,null,`正在解析,请稍候…`)})]}),(0,M.jsx)(w,{error:ee,onRetry:()=>b(e=>e+1)}),m&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(l,{value:g,rows:3,className:`info-collect-parse-query`,onChange:_}),m.explanation&&(0,M.jsxs)(`div`,{className:`info-collect-parse-block`,children:[(0,M.jsx)(I,{strong:!0,size:`small`,children:o(`infoCollect.explanation`,null,`字段映射说明`)}),(0,M.jsx)(I,{type:`tertiary`,size:`small`,children:m.explanation})]}),C.length>0&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,description:C.join(`;`)})]})]})})}function L(e,t,n){if(e&&!Array.isArray(e)&&typeof e==`object`){let t=e[n];return Array.isArray(t)?t.filter(Boolean).join(`,`):t==null?``:String(t).trim()}let r=Array.isArray(t)?t.indexOf(n):-1;if(r<0||!Array.isArray(e))return``;let i=e[r];return i==null?``:String(i).trim()}function R(e,t,n){for(let r of n){let n=L(e,t,r);if(n)return n}return``}function z(e,t,n=`fofa`){let r=Number.parseInt(L(e,t,`port`),10),i=R(e,t,[`ip`,`ip_str`]),a=O(i)||D(i)?i.toLowerCase():``,o=R(e,t,[`domain`,`hostname`,`hostnames`,`domains`]).split(`,`)[0].replace(/^\[|\]$/g,``).replace(/^"|"$/g,``),s=o&&!O(o)&&!D(o)?k(o):``,c=R(e,t,[`protocol`,`service.name`,`transport`]).toLowerCase();return{host:R(e,t,[`host`,`hostname`]).split(`,`)[0].trim(),ip:a,port:Number.isFinite(r)?r:0,domain:s,protocol:/^[a-z][a-z0-9+.-]{0,31}$/.test(c)?c:``,title:R(e,t,[`title`,`service.http.title`]),server:R(e,t,[`server`,`product`]),country:R(e,t,[`country`,`location.country_cn`,`location.country_name`]),province:R(e,t,[`region`,`province`,`location.province_cn`]),city:R(e,t,[`city`,`location.city_cn`,`location.city`]),source:n||`fofa`,status:`active`}}async function he(e,{fields:t,provider:n,query:r,projectId:i,collectionName:a}){let o=(e||[]).map(e=>z(e,t,n)),s=o.filter(e=>e.host||e.ip||e.domain),c=o.length-s.length;if(!s.length)return{assets:s,invalidCount:c,created:0,updated:0,skipped:0};i&&s.forEach(e=>{e.project_id=i});let l={assets:s,source:n||`fofa`,source_query:r||``};i&&(l.collection={project_id:i,name:String(a||r||`导入资产`).trim()});let u=await y.post(`/assets/import`,l);return{assets:s,invalidCount:c,created:Number(u?.created||0),updated:Number(u?.updated||0),skipped:Number(u?.skipped||0),collection:u?.collection||null}}var{Text:B}=o,ge=`csf.info-collect.form`,V={provider:`fofa`,query:``,size:100,fields:j.fofa.defaultFields,full:!1};function H(){let e=v(),{hasPermission:t}=te(),n=t(`fofa:execute`),o=t(`asset:write`),[d,S]=ne(ge,V),[T,E]=(0,A.useState)(``),[D,O]=(0,A.useState)(!1),[k,j]=(0,A.useState)(null),[N,P]=(0,A.useState)(!1),[F,I]=(0,A.useState)(null),[L,R]=(0,A.useState)([]),[z,H]=(0,A.useState)([]),[U,_e]=(0,A.useState)(null),[ve,ye]=(0,A.useState)(!1),[be,xe]=(0,A.useState)([]),[W,Se]=(0,A.useState)(``),[Ce,we]=(0,A.useState)(``),G=le(d.provider),Te=G.label;(0,A.useEffect)(()=>{if(!t(`project:read`))return;let e=!1;return y.get(`/projects`,{limit:500}).then(t=>{e||xe(Array.isArray(t?.projects)?t.projects:[])}).catch(()=>{e||xe([])}),()=>{e=!0}},[t]),(0,A.useEffect)(()=>{H([]),R([]),j(null),I(null)},[d.provider]);let K=e=>S(t=>({...V,...t,...e})),Ee=e=>{let t=le(e);K({provider:e,fields:t.defaultFields,size:Math.min(Number(d.size||100),t.maxSize),full:!1})},q=Math.min(Math.max(Number(d.size||100),1),G.maxSize),J=async(t=1,r)=>{if(!n){b(e(`infoCollect.permissionDenied`,null,`当前账号没有 fofa:execute 权限`));return}let i=String(r??d.query??``).trim();if(!i)b(e(`infoCollect.enterFofaQuery`,null,`请输入查询语法`));else{P(!0),I(null);try{let e=await y.post(`/fofa/search`,{provider:d.provider,query:i,size:q,page:t,fields:d.fields,full:!!d.full});j(e),R([]),H(ue(e?.fields||[],5))}catch(e){I(e),j(null)}finally{P(!1)}}},De=()=>{S({...V}),j(null),I(null),R([]),H([]),E(``)},Y=Array.isArray(k?.fields)?k.fields:[],X=Array.isArray(k?.results)?k.results:[],Z=Number(k?.total||0),Q=Number(k?.size||q),$=Number(k?.page||1),Oe=async()=>{if(ve)return;if(!o){b(e(`infoCollect.noImportPermission`,null,`当前账号没有 asset:write 权限`));return}if(!L.length){b(e(`infoCollect.selectRowsFirst`,null,`请先选择需要入库的结果`));return}let t=fe(X,L);ye(!0);try{let n=await he(t,{fields:Y,provider:k?.provider||d.provider,query:k?.query||d.query,projectId:W,collectionName:Ce});if(!n.assets.length){b(e(`assets.noValidImportTarget`,null,`所选结果中没有可入库的有效资产目标`));return}let r=n.invalidCount?e(`assets.importDoneWithInvalid`,{created:n.created,updated:n.updated,invalid:n.invalidCount},`已新增 ${n.created} 条,更新 ${n.updated} 条,跳过 ${n.invalidCount} 条无有效目标的结果`):e(`assets.importDone`,{created:n.created,updated:n.updated},`已新增 ${n.created} 条,更新 ${n.updated} 条`),i=n.collection?.name?`,已写入资产库,并记下检索结果「${n.collection.name}」`:``;oe(`${r}${i}`),R([])}catch(t){x(t,e(`assets.importFailed`,null,`资产入库失败`))}finally{ye(!1)}},ke=(e,t)=>{K({query:e}),O(!1),t&&J(1,e)},Ae=(0,A.useMemo)(()=>U?Y.map(e=>{let t=U[e];return{label:e,value:Array.isArray(t)?t.join(`, `):t==null?`—`:String(t)}}):[],[U,Y]),je=k?e(`infoCollect.resultsMeta`,{total:Z,count:X.length,page:$,size:Q},`${Te} · 共 ${Z} 条 · 第 ${$} 页 · 每页 ${Q} 条 · 返回 ${X.length} 条`):``;return(0,M.jsxs)(`div`,{className:`info-collect-page`,children:[(0,M.jsx)(ie,{title:e(`infoCollectPage.title`,null,`信息收集`),description:`使用 FOFA 等空间测绘语法检索资产,并把结果直接入库。`,extra:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{icon:(0,M.jsx)(m,{}),onClick:()=>{k&&J($)},children:e(`common.refresh`,null,`刷新`)}),(0,M.jsx)(c,{onClick:De,children:e(`infoCollectPage.reset`,null,`重置`)})]})}),!n&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-permission`,description:e(`infoCollect.permissionDeniedHint`,null,`当前账号没有 fofa:execute 权限:查询、列字段与入库操作不可用,请联系管理员授权。`)}),(0,M.jsx)(w,{error:F,onRetry:()=>J($)}),(0,M.jsx)(re,{title:e(`infoCollectPage.fofaQuerySyntax`,null,`查询语法`),children:(0,M.jsxs)(`div`,{className:`info-collect-form`,children:[(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:d.provider,optionList:ce,onChange:Ee,style:{width:150}}),(0,M.jsxs)(`span`,{className:`info-collect-size`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnCount`,null,`返回数量`)}),(0,M.jsx)(g,{value:q,min:1,max:G.maxSize,onChange:e=>K({size:e}),style:{width:120}})]}),(0,M.jsx)(f,{checked:!!d.full,disabled:!G.supportsFull,onChange:e=>K({full:e})}),(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:`full`}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(ee,{}),onClick:()=>J(1),loading:N,disabled:!n,children:e(`infoCollectPage.confirm`,null,`查询`)}),(0,M.jsx)(c,{disabled:!T.trim()||!n,onClick:()=>O(!0),title:e(`infoCollectPage.parseBtnTitle`,null,`将自然语言解析为查询语法`),children:e(`infoCollectPage.parseBtn`,null,`AI 解析`)})]}),(0,M.jsx)(l,{value:d.query,rows:3,placeholder:`${Te}:${G.placeholder}`,className:`info-collect-query`,onChange:e=>K({query:e})}),(0,M.jsxs)(s,{wrap:!0,className:`info-collect-presets`,children:[(0,M.jsxs)(B,{type:`tertiary`,size:`small`,children:[e(`infoCollectPage.fillExample`,null,`示例`),`:`]}),G.queryPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({query:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnFields`,null,`返回字段`)}),(0,M.jsx)(u,{value:d.fields,onChange:e=>K({fields:e}),className:`info-collect-fields`,style:{width:420}}),G.fieldPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({fields:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:W,optionList:[{value:``,label:`不归入项目集合`},...se(be,e,{currentId:W})],placeholder:`归入项目`,style:{width:220},onChange:e=>Se(e||``)}),(0,M.jsx)(u,{value:Ce,disabled:!W,placeholder:`集合名称,留空则使用查询语句`,style:{width:280},onChange:we})]}),(0,M.jsx)(l,{value:T,rows:2,placeholder:e(`infoCollectPage.nlPlaceholder`,null,`自然语言:例如 找中国 Apache 站点,标题包含登录`),className:`info-collect-natural`,onChange:E})]})}),(0,M.jsxs)(re,{className:`info-collect-results`,title:e(`infoCollectPage.queryResults`,null,`查询结果`),extra:(0,M.jsxs)(s,{className:`info-collect-results-actions`,wrap:!0,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:je}),(0,M.jsx)(_,{multiple:!0,value:z,optionList:Y.map(e=>({value:e,label:e})),disabled:!Y.length,placeholder:e(`infoCollectPage.showColumns`,null,`显示字段`),maxTagCount:5,style:{minWidth:220},onChange:e=>{let t=(e||[]).slice(0,5);(e||[]).length>5&&b(`最多显示 5 个字段`),H(t)}}),(0,M.jsx)(c,{icon:(0,M.jsx)(i,{}),disabled:!o||!L.length,loading:ve,onClick:Oe,children:e(`assets.importSelected`,null,`入库所选`)})]}),children:[k?.warning&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-warning`,description:k.warning}),!k&&!N&&!F?(0,M.jsx)(a,{title:e(`infoCollect.noResults`,null,`暂无结果`),description:n?`输入查询语法后点击“查询”。`:`当前账号缺少 fofa:execute 权限。`,style:{padding:40}}):(0,M.jsx)(pe,{fields:Y,results:X,visibleFields:z,selectedKeys:L,onSelectionChange:R,onOpenDetail:_e,loading:N}),k&&Z>Q&&(0,M.jsx)(`div`,{className:`info-collect-pagination`,children:(0,M.jsx)(h,{total:Z,pageSize:Q,currentPage:$,onPageChange:e=>J(e),showTotal:!0})}),k&&(0,M.jsx)(B,{type:`tertiary`,size:`small`,className:`info-collect-selected-meta`,children:e(`infoCollectPage.selectedRows`,{count:L.length},`已选择 ${L.length} 条`)})]}),(0,M.jsx)(p,{visible:!!U,onCancel:()=>_e(null),title:e(`infoCollect.detailTitle`,null,`结果详情`),width:600,placement:`right`,children:U&&(0,M.jsxs)(`div`,{className:`info-collect-detail`,children:[(0,M.jsx)(B,{strong:!0,children:de(U,Y)||`—`}),(0,M.jsx)(C,{items:Ae,columns:1}),(0,M.jsx)(ae,{value:U,title:`原始 JSON`})]})}),(0,M.jsx)(me,{visible:D,provider:d.provider,text:T,onClose:()=>O(!1),onApply:ke})]})}export{H as default};