1
0
Files
build.ems/build/usr/local/omc/htdocs/front/js/usePCAP.BExFBUdp.js
2024-10-25 14:59:47 +08:00

2 lines
4.5 KiB
JavaScript

import{_ as x,W as P,b1 as b}from"./vendor/index.CRpmXtWV.js";const f="/",S=`${f.length===1&&f.indexOf("/")===0?"":f.indexOf("/")===-1?"/"+f:f}/wiregasm/worker.js`;class E{wk=null;options=null;constructor(n){if(!window.Worker){console.error("Sorry! Browser does not support Web Workers");return}n&&this.connect(n)}connect(n){this.options=n;try{const l=new Worker(n.url);l.onmessage=s=>{if(s.type==="message")try{typeof n.onmessage=="function"&&n.onmessage(s.data)}catch(m){console.error("worker message formatting error",m)}},l.onmessageerror=s=>{console.error("worker message error anomaly",s),typeof n.onclose=="function"&&n.onerror(s)},l.onerror=s=>{console.error("worker error anomaly",s),typeof n.onerror=="function"&&n.onerror(s)},this.wk=l}catch(l){typeof n.onerror=="function"&&n.onerror(l)}}send(n){return this.wk?(this.wk.postMessage(n),!0):(console.warn("worker unavailable"),!1)}close(){if(!this.wk){console.warn("worker unavailable");return}this.wk.terminate(),this.options&&typeof this.options.onclose=="function"&&this.options.onclose(1e3)}}const c=new E,d={id:"",idx:0,start:0,length:0};function W(){const e=x({initialized:!1,summary:{filename:"",file_type:"Wireshark/tcpdump/... - pcap",file_length:0,file_encap_type:"Ethernet",packet_count:0,start_time:0,stop_time:0,elapsed_time:0},columns:[],filter:"",filterError:null,currentFilter:"",selectedFrame:1,selectedPacket:{tree:[],data_sources:[]},packetFrameData:null,selectedTreeEntry:d,selectedDataSourceIndex:0,finishedProcessing:!1,totalFrames:0,packetFrames:[],nextPageNum:1,nextPageSize:40,nextPageLoad:!1});function n(){e.nextPageNum=1,e.selectedFrame=0,e.selectedPacket={tree:[],data_sources:[]},e.packetFrameData=null,e.selectedTreeEntry=d,e.selectedDataSourceIndex=0}function l(t,a){let r=new Map;if(a.tree&&a.tree.length>0)for(let o=0;o<a.tree.length;o++)l(`${t}-${o}`,a.tree[o]).forEach((_,w)=>{r.set(w,_)});else a.length>0&&r.set(t,{id:t,idx:a.data_source_idx,start:a.start,length:a.length});return r}function s(t){console.log("fnSelectedTreeEntry",t),e.selectedTreeEntry=t}function m(t,a){if(console.log("fnSelectedFindSelection",a),e.packetFrameData==null)return;let r=null;for(let[o,i]of e.packetFrameData)i.idx===t&&a>=i.start&&a<=i.start+i.length&&(r!=null&&e.packetFrameData.get(r).length>i.length,r=o);r!=null&&(e.selectedTreeEntry=e.packetFrameData.get(r))}function p(t){console.log("fnSelectedFrame",t,e.totalFrames),e.selectedFrame=t,c.send({type:"select",number:e.selectedFrame})}function h(){const t=e.packetFrames.length;console.log("fnScrollBottom",t),!e.nextPageLoad&&t<e.totalFrames&&(e.nextPageLoad=!0,e.nextPageNum++,u(e.filter,e.nextPageNum))}function k(){console.log("fnFilterFinish",e.filter),c.send({type:"check-filter",filter:e.filter})}function u(t,a=1){if(!(e.initialized&&e.finishedProcessing))return;const r=e.nextPageSize;c.send({type:"frames",filter:t,skip:(a-1)*r,limit:r})}function g(t){e.summary={filename:"",file_type:"Wireshark/tcpdump/... - pcap",file_length:0,file_encap_type:"Ethernet",packet_count:0,start_time:0,stop_time:0,elapsed_time:0},e.finishedProcessing=!1,c.send({type:"process",file:t})}async function y(){const t="test_ethernet.pcap",r=await(await fetch("/wiregasm/test_ethernet.pcap")).arrayBuffer();e.summary={filename:"",file_type:"Wireshark/tcpdump/... - pcap",file_length:0,file_encap_type:"Ethernet",packet_count:0,start_time:0,stop_time:0,elapsed_time:0},e.finishedProcessing=!1,c.send({type:"process-data",name:t,data:r})}function F(t){switch(t.type){case"status":console.info(t.status);break;case"error":console.warn(t.error);break;case"init":c.send({type:"columns"}),e.initialized=!0;break;case"columns":e.columns=t.data;break;case"frames":const{matched:a,frames:r}=t.data;e.totalFrames=a,e.nextPageNum==1?(e.packetFrames=r,r.length>0&&(e.selectedFrame=r[0].number,p(e.selectedFrame))):(e.packetFrames=e.packetFrames.concat(r),e.nextPageLoad=!1);break;case"selected":e.selectedPacket=t.data,e.packetFrameData=l("root",t.data),e.selectedTreeEntry=d,e.selectedDataSourceIndex=0;break;case"processed":e.finishedProcessing=!0,t.data.code===0&&(e.summary=t.data.summary),n(),u(e.filter);break;case"filter":const o=t.data;o.ok?(e.currentFilter=e.filter,e.filterError=null,n(),u(e.filter)):e.filterError=o.error;break;default:console.warn(t);break}}return P(()=>{const t={url:S,onmessage:F,onerror:a=>{console.error(a)}};c.connect(t)}),b(()=>{c.send({type:"close"})&&c.close()}),{state:e,handleSelectedTreeEntry:s,handleSelectedFindSelection:m,handleSelectedFrame:p,handleScrollBottom:h,handleFilterFrames:k,handleLoadExample:y,handleLoadFile:g}}export{d as N,W as u};