UNPKG

klioso

Version:

Multi-Service Provider Management System for WordPress and Web Development with Enhanced Scanner

2 lines (1 loc) 16.7 kB
import{a as m,j as e,H as B}from"./app-DZ07njAd.js";import{A as U}from"./AuthenticatedLayout-BKOGad_C.js";import{B as F}from"./Button-D6Jcp-tA.js";import{F as N}from"./Form-DWGkysrX.js";import"./ApplicationLogo-GDc3W5ND.js";import"./transition-BCwV6od8.js";function Q({websites:W=[]}){const[w,I]=m.useState("url"),[d,T]=m.useState({url:"",scanType:"plugins",autoSync:!1}),[$,z]=m.useState(""),[_,C]=m.useState(!1),[n,y]=m.useState(null),[k,c]=m.useState(""),[j,p]=m.useState(null),[b,f]=m.useState(new Set),[P,v]=m.useState(""),[O,A]=m.useState(!1);m.useEffect(()=>{if(P){const s=setTimeout(()=>v(""),5e3);return()=>clearTimeout(s)}},[P]),m.useEffect(()=>{if(k){const s=setTimeout(()=>c(""),8e3);return()=>clearTimeout(s)}},[k]);const x=(s,t,l=null)=>{p({percent:s,stage:t,timeLeft:l||Math.max(0,(100-s)*100)})},R=(s,t,l,o=3e3)=>{const r=Math.max(t-s,1),a=o/r;let i=s;const g=setInterval(()=>{if(i<t){i+=1;const u=Math.max(0,(100-i)/100*8e3);p({percent:i,stage:l,timeLeft:u})}else clearInterval(g)},a);return g},E=async s=>{var l;if(s.preventDefault(),!d.url){c("URL is required to perform the scan.");return}C(!0),c(""),y(null),v(""),f(new Set);let t=null;try{x(10,"Initializing scan...");const o=(l=document.querySelector('meta[name="csrf-token"]'))==null?void 0:l.getAttribute("content");if(!o)throw new Error("CSRF token not found. Please refresh the page.");x(20,"Connecting to website..."),t=R(20,60,"Scanning website for WordPress components...",4e3);const r=await fetch("/scan",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":o,Accept:"application/json"},body:JSON.stringify({url:d.url,scan_type:d.scanType})});clearInterval(t),x(80,"Processing scan results...",2e3),await new Promise(i=>setTimeout(i,500));const a=await r.json();if(x(95,"Finalizing results...",500),r.ok&&a.success){y(a.data);const i=a.data.plugins?a.data.plugins.length:0,g=a.data.themes?a.data.themes.length:0;let u=`Scan completed successfully! Found ${i} plugins`;if(g>0&&(u+=` and ${g} themes`),u+=".",d.autoSync&&a.data.auto_sync_results){const h=a.data.auto_sync_results.synced_plugins||0;u+=` Auto-sync added ${h} new plugins to the database.`}v(u),!d.autoSync&&a.data.plugins&&f(new Set(a.data.plugins.map((h,S)=>S))),x(100,"Scan completed successfully!",0),setTimeout(()=>{p(null)},1500)}else if(r.status===422){clearInterval(t);const i=a.errors?Object.values(a.errors).flat().join(", "):a.message||"Validation failed";c("Validation error: "+i),p(null)}else clearInterval(t),c(a.message||`Request failed with status ${r.status}`),p(null)}catch(o){clearInterval(t),c("Failed to perform scan: "+o.message),p(null)}finally{C(!1)}},L=async s=>{var l;if(s.preventDefault(),!$)return;C(!0),c(""),y(null),v(""),f(new Set);let t=null;try{x(10,"Initializing website scan...");const o=(l=document.querySelector('meta[name="csrf-token"]'))==null?void 0:l.getAttribute("content");if(!o)throw new Error("CSRF token not found. Please refresh the page.");x(25,"Connecting to website database..."),t=R(25,65,"Scanning website database for plugins and themes...",3500);const r=await fetch(`/websites/${$}/scan`,{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":o,Accept:"application/json"},body:JSON.stringify({scan_type:d.scanType,auto_sync:d.autoSync})});clearInterval(t),x(80,"Processing website scan results...",1500),await new Promise(i=>setTimeout(i,500));const a=await r.json();if(x(95,"Finalizing website scan...",500),a.success){y(a.data);const i=a.data.plugins?a.data.plugins.length:0,g=a.data.themes?a.data.themes.length:0;let u=`Website scan completed successfully! Found ${i} plugins`;if(g>0&&(u+=` and ${g} themes`),u+=".",d.autoSync&&a.data.auto_sync_results){const h=a.data.auto_sync_results.synced_plugins||0;u+=` Auto-sync added ${h} new plugins to the website database.`}v(u),!d.autoSync&&a.data.plugins&&f(new Set(a.data.plugins.map((h,S)=>S))),x(100,"Website scan completed successfully!",0),setTimeout(()=>{p(null)},1500)}else clearInterval(t),c(a.message||"Scan failed"),p(null)}catch(o){clearInterval(t),c("Failed to perform scan: "+o.message),p(null)}finally{C(!1)}},D=async s=>{var t;try{const l=(t=document.querySelector('meta[name="csrf-token"]'))==null?void 0:t.getAttribute("content");if(!l){alert("CSRF token not found. Please refresh the page.");return}const r=await(await fetch("/scanner/add-plugin",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":l,Accept:"application/json"},body:JSON.stringify({name:s.name,description:s.description,slug:s.slug})})).json();r.success?y(a=>({...a,plugins:a.plugins.map(i=>i.name===s.name?{...i,in_database:!0,database_id:r.plugin.id}:i)})):alert("Failed to add plugin to database")}catch(l){alert("Failed to add plugin: "+l.message)}},M=(s,t)=>{const l=new Set(b);t?l.add(s):l.delete(s),f(l)},q=s=>{s&&(n!=null&&n.plugins)?f(new Set(n.plugins.map((t,l)=>l))):f(new Set)},V=async()=>{var s;if(b.size===0){c("Please select plugins to add to database.");return}A(!0),c("");try{const t=Array.from(b).map(a=>({index:a,plugin:n.plugins[a]})).filter(a=>!a.plugin.in_database);if(t.length===0){c("All selected plugins are already in the database."),A(!1);return}const l=(s=document.querySelector('meta[name="csrf-token"]'))==null?void 0:s.getAttribute("content");if(!l){c("CSRF token not found. Please refresh the page."),A(!1);return}const r=await(await fetch("/scanner/bulk-add-plugins",{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":l,Accept:"application/json"},body:JSON.stringify({plugins:t.map(a=>({name:a.plugin.name,description:a.plugin.description,slug:a.plugin.slug}))})})).json();r.success?(y(a=>({...a,plugins:a.plugins.map((i,g)=>{if(t.find(h=>h.index===g)){const h=r.plugins.find(S=>S.name===i.name);return{...i,in_database:!0,database_id:h==null?void 0:h.id}}return i})})),f(new Set),v(`Successfully added ${r.plugins.length} plugins to the database!`)):c(r.message||"Failed to add plugins to database")}catch(t){c("Failed to add plugins: "+t.message)}finally{A(!1)}};return e.jsxs(U,{children:[e.jsx(B,{title:"WordPress Scanner"}),e.jsx("div",{className:"py-12",children:e.jsx("div",{className:"max-w-7xl mx-auto sm:px-6 lg:px-8",children:e.jsx("div",{className:"bg-white overflow-hidden shadow-sm sm:rounded-lg",children:e.jsxs("div",{className:"p-6 bg-white border-b border-gray-200",children:[e.jsx("div",{className:"flex justify-between items-center mb-6",children:e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:"WordPress Scanner"})}),e.jsx("div",{className:"border-b border-gray-200 mb-6",children:e.jsxs("nav",{className:"-mb-px flex space-x-8",children:[e.jsx("button",{onClick:()=>I("url"),className:`py-2 px-1 border-b-2 font-medium text-sm ${w==="url"?"border-indigo-500 text-indigo-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:"URL Scan"}),e.jsx("button",{onClick:()=>I("website"),className:`py-2 px-1 border-b-2 font-medium text-sm ${w==="website"?"border-indigo-500 text-indigo-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:"Website Scan"})]})}),w==="url"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:"Scan WordPress Website"}),e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"Enter a website URL to scan for WordPress installation, plugins, themes, and security vulnerabilities."})]}),e.jsxs("form",{onSubmit:E,className:"space-y-4",children:[e.jsx(N.Input,{id:"url",label:"Website URL",type:"url",value:d.url,onChange:s=>T(t=>({...t,url:s.target.value})),placeholder:"https://example.com",required:!0}),e.jsxs(N.Select,{id:"scan-type",label:"Scan Type",value:d.scanType,onChange:s=>T(t=>({...t,scanType:s.target.value})),children:[e.jsx("option",{value:"plugins",children:"Plugins Only"}),e.jsx("option",{value:"themes",children:"Themes Only"}),e.jsx("option",{value:"vulnerabilities",children:"Vulnerabilities Only"}),e.jsx("option",{value:"all",children:"All (Comprehensive)"})]}),e.jsx(F,{type:"submit",disabled:_,children:_?"Scanning...":"Start Scan"})]})]}),w==="website"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:"Scan Existing Website"}),e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"Select a website from your database to scan and optionally sync the results."})]}),e.jsxs("form",{onSubmit:L,className:"space-y-4",children:[e.jsxs(N.Select,{id:"website-select",label:"Website",value:$,onChange:s=>z(s.target.value),required:!0,children:[e.jsx("option",{value:"",children:"Select a website"}),W.map(s=>e.jsxs("option",{value:s.id,children:[s.domain_name," ",s.client_name&&`(${s.client_name})`]},s.id))]}),e.jsxs(N.Select,{id:"website-scan-type",label:"Scan Type",value:d.scanType,onChange:s=>T(t=>({...t,scanType:s.target.value})),children:[e.jsx("option",{value:"plugins",children:"Plugins Only"}),e.jsx("option",{value:"themes",children:"Themes Only"}),e.jsx("option",{value:"vulnerabilities",children:"Vulnerabilities Only"}),e.jsx("option",{value:"all",children:"All (Comprehensive)"})]}),e.jsx(N.Checkbox,{id:"auto-sync",label:"Auto-sync discovered plugins to website","aria-describedby":"auto-sync-description",checked:d.autoSync,onChange:s=>T(t=>({...t,autoSync:s.target.checked}))}),e.jsx("p",{id:"auto-sync-description",className:"text-xs text-gray-500 -mt-2",children:"Automatically synchronize discovered plugins with the selected website's database."}),e.jsx(F,{type:"submit",disabled:_,children:_?"Scanning...":"Start Scan"})]})]}),j&&e.jsxs("div",{className:"mt-6 p-4 bg-blue-50 border border-blue-200 rounded-md",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"text-sm font-medium text-blue-900",children:"Scanning in Progress"}),e.jsxs("div",{className:"flex items-center text-sm text-blue-700",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-blue-600 mr-2"}),j.timeLeft>0?`${Math.ceil(j.timeLeft/1e3)}s remaining`:"Almost done..."]})]}),e.jsx("div",{className:"w-full bg-blue-200 rounded-full h-2.5 mb-2",children:e.jsx("div",{className:"bg-blue-600 h-2.5 rounded-full transition-all duration-500 ease-out",style:{width:`${j.percent}%`}})}),e.jsxs("p",{className:"text-sm text-blue-700",children:[j.stage," (",j.percent,"%)"]})]}),P&&e.jsx("div",{className:"mt-6 p-4 bg-green-50 border border-green-200 rounded-md",children:e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-green-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})}),e.jsx("div",{className:"ml-3",children:e.jsx("p",{className:"text-sm font-medium text-green-800",children:P})})]})}),k&&e.jsx("div",{className:"mt-6 p-4 bg-red-50 border border-red-200 rounded-md",children:e.jsx("div",{className:"flex",children:e.jsxs("div",{className:"ml-3",children:[e.jsx("h3",{className:"text-sm font-medium text-red-800",children:"Error"}),e.jsx("div",{className:"mt-2 text-sm text-red-700",children:e.jsx("p",{children:k})})]})})}),n&&e.jsxs("div",{className:"mt-8 space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"Scan Results"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"WordPress Detected:"}),e.jsx("span",{className:`ml-2 px-2 py-1 rounded text-xs ${n.wordpress_detected?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:n.wordpress_detected?"Yes":"No"})]}),n.wordpress_version&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Version:"}),e.jsx("span",{className:"ml-2",children:n.wordpress_version})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Scan Time:"}),e.jsx("span",{className:"ml-2",children:new Date().toLocaleString()})]})]})]}),n.plugins&&n.plugins.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("h4",{className:"text-lg font-medium text-gray-900",children:["Detected Plugins (",n.plugins.length,")"]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center text-sm text-gray-600",children:[e.jsx("input",{type:"checkbox",id:"select-all-plugins",className:"mr-2 h-4 w-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500",checked:b.size===n.plugins.length&&n.plugins.length>0,onChange:s=>q(s.target.checked)}),e.jsxs("label",{htmlFor:"select-all-plugins",children:["Select All (",b.size," selected)"]})]}),b.size>0&&e.jsx(F,{onClick:V,disabled:O,size:"sm",variant:"outline",children:O?`Adding ${b.size} plugins...`:`Add ${b.size} to Database`})]})]}),e.jsx("div",{className:"space-y-3",children:n.plugins.map((s,t)=>e.jsx("div",{className:"bg-white border rounded-lg p-4",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1",children:[e.jsx("input",{type:"checkbox",id:`plugin-${t}`,className:"mt-1 h-4 w-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500",checked:b.has(t),onChange:l=>M(t,l.target.checked)}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h5",{className:"font-medium",children:s.name}),s.description&&e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:s.description}),e.jsxs("div",{className:"flex gap-4 mt-2 text-sm",children:[s.version&&e.jsxs("span",{children:[e.jsx("strong",{children:"Version:"})," ",s.version]}),s.slug&&e.jsxs("span",{children:[e.jsx("strong",{children:"Slug:"})," ",s.slug]}),e.jsx("span",{className:`px-2 py-1 rounded text-xs ${s.status==="active"?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"}`,children:s.status}),s.in_database!==void 0&&e.jsx("span",{className:`px-2 py-1 rounded text-xs ${s.in_database?"bg-blue-100 text-blue-800":"bg-yellow-100 text-yellow-800"}`,children:s.in_database?"In Database":"Not in Database"}),s.is_paid!==void 0&&e.jsx("span",{className:`px-2 py-1 rounded text-xs ${s.is_paid?"bg-purple-100 text-purple-800":"bg-green-100 text-green-800"}`,children:s.is_paid?"Paid":"Free"})]})]})]}),e.jsx("div",{className:"ml-4",children:!s.in_database&&e.jsx(F,{onClick:()=>D(s),size:"sm",variant:"outline",children:"Add to Database"})})]})},t))})]}),n.themes&&n.themes.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-lg font-medium text-gray-900 mb-4",children:["Detected Themes (",n.themes.length,")"]}),e.jsx("div",{className:"space-y-3",children:n.themes.map((s,t)=>e.jsx("div",{className:"bg-white border rounded-lg p-4",children:e.jsx("div",{className:"flex justify-between items-start",children:e.jsxs("div",{children:[e.jsx("h5",{className:"font-medium",children:s.name}),e.jsxs("div",{className:"flex gap-4 mt-2 text-sm",children:[s.slug&&e.jsxs("span",{children:[e.jsx("strong",{children:"Slug:"})," ",s.slug]}),e.jsx("span",{className:`px-2 py-1 rounded text-xs ${s.status==="active"?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"}`,children:s.status})]})]})})},t))})]}),n.vulnerabilities&&n.vulnerabilities.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-lg font-medium text-gray-900 mb-4",children:["Security Vulnerabilities (",n.vulnerabilities.length,")"]}),e.jsx("div",{className:"space-y-3",children:n.vulnerabilities.map((s,t)=>e.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4",children:e.jsx("div",{className:"flex justify-between items-start",children:e.jsxs("div",{children:[e.jsx("h5",{className:"font-medium text-red-900",children:s.title}),e.jsx("p",{className:"text-sm text-red-700 mt-1",children:s.description}),e.jsx("div",{className:"flex gap-4 mt-2 text-sm",children:e.jsxs("span",{className:`px-2 py-1 rounded text-xs ${s.severity==="high"?"bg-red-100 text-red-800":s.severity==="medium"?"bg-yellow-100 text-yellow-800":"bg-blue-100 text-blue-800"}`,children:[s.severity," severity"]})})]})})},t))})]}),(!n.plugins||n.plugins.length===0)&&(!n.themes||n.themes.length===0)&&(!n.vulnerabilities||n.vulnerabilities.length===0)&&e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-gray-500",children:"No plugins, themes, or vulnerabilities found."})})]})]})})})})]})}export{Q as default};