Files
OpenVPN-Monitoring-Simple/deploy/ui-dist/assets/Analytics-D8_MsU7I.js
T
ayurishchevandClaude Sonnet 5.5 f8cdcd0fc6 Backup and Restore: packages, Local/S3/SFTP/FTP destinations, UI and API
Encrypted packages (databases, PKI, client profiles) with safe restore and
a pre-restore safety copy, usable for server-to-server migration across
container and system-service installs. New Management page, ovp_backups
volume, migrations code in the profiler image, server name in package names.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-07 09:38:09 +03:00

2 lines
9.4 KiB
JavaScript

import{r as _,a as U,o as G,u as Z,b as q,c as r,d as t,t as i,e as I,f as J,g as f,w as z,v as K,h as Q,F as E,i as j,j as Y,k as d,n as $}from"./index-BsVv6gaD.js";import{C as H}from"./vendor-charts-Bcjh2pZL.js";import"./vendor-ui-jlFFG6nm.js";const tt={class:"kpi-grid mb-4"},et={class:"stat-item"},st={class:"stat-content"},at={class:"stat-item"},ot={class:"stat-content"},lt={class:"stat-item"},nt={class:"stat-content"},it={class:"card mb-4"},rt={class:"card-header d-flex justify-content-between align-items-center flex-wrap"},dt={class:"chart-header-controls"},ct={class:"d-flex align-items-center"},ut={class:"toggle-wrapper me-2"},mt={class:"toggle-switch"},ft={class:"card-body"},pt={class:"chart-container"},vt={class:"row"},ht={class:"col-lg-7"},_t={class:"card"},gt={class:"card-body p-0"},bt={class:"table-responsive"},xt={class:"table"},yt={key:0},Ct={key:1},kt={class:"user-select-all fw-bold",style:{color:"var(--text-heading)"}},wt={class:"font-monospace text-muted"},St={class:"d-flex align-items-center"},Rt={class:"progress flex-grow-1",style:{height:"6px"}},Tt={class:"ms-2 small text-muted w-25 text-end"},At={class:"col-lg-5"},Dt={class:"card mb-4"},Mt={class:"card-body p-3",style:{"min-height":"120px","max-height":"200px","overflow-y":"auto"}},Et={key:0,class:"text-muted text-center py-3 mb-0"},Nt={key:1,class:"text-muted text-center py-3 mb-0"},Lt={key:2,class:"list-group list-group-flush"},Bt={class:"fw-bold small"},Ut={class:"text-muted",style:{"font-size":"0.75rem"}},It={class:"badge status-warning text-dark"},zt={class:"card"},jt={class:"card-body d-flex align-items-center justify-content-around p-4",style:{"min-height":"200px"}},Ht={class:"pie-container",style:{width:"140px",height:"140px",flex:"0 0 auto"}},Ot={class:"ms-3 flex-grow-1"},Vt={class:"mb-3"},Ft={class:"h5 mb-0",style:{color:"var(--text-heading)"}},Pt={class:"h5 mb-0",style:{color:"var(--text-heading)"}},Wt=96,Jt={__name:"Analytics",setup(Xt){const{fetchAnalytics:O,fetchCertificates:V}=Y(),{formatBytes:C,parseServerDate:F}=J(),{config:P}=Z(),w=_(null),S=_(null);let g=null,b=null;const p=U({analytics:!0,certs:!0}),x=_("24h"),y=_(!1),o=U({concurrentUsers:"-",totalTraffic:0,expiringCerts:"-",totalReceived:0,totalSent:0,totalReceivedString:"-",totalSentString:"-"}),R=_([]),T=_([]);let N=null;const A=async()=>{p.analytics=!0;try{const a=await O(x.value);a.success&&W(a.data)}catch(a){console.error(a)}finally{p.analytics=!1}},L=async()=>{p.certs=!0;try{const a=await V();if(a.success&&Array.isArray(a.data)){const e=a.data.filter(s=>!s.is_revoked&&!s.is_expired&&s.days_remaining!==null&&s.days_remaining<=45);o.expiringCerts=e.length,T.value=e.sort((s,n)=>(s.days_remaining||0)-(n.days_remaining||0))}}catch(a){console.error(a)}finally{p.certs=!1}},W=a=>{o.concurrentUsers=a.max_concurrent_24h||0;const e=a.traffic_distribution||{rx:0,tx:0};o.totalReceived=Number(e.rx||0),o.totalSent=Number(e.tx||0),o.totalTraffic=o.totalReceived+o.totalSent,o.totalReceivedString=C(o.totalReceived),o.totalSentString=C(o.totalSent),R.value=(a.top_clients_24h||[]).map(s=>({name:s.common_name,total:Number(s.total_traffic||0),percent:o.totalTraffic>0?(Number(s.total_traffic)/o.totalTraffic*100).toFixed(1):0})),N=a.global_history_24h||[],D(),B()},D=()=>{if(!w.value)return;g&&g.destroy();const a=X(N,Wt),e=[],s=[],n=[];a.forEach(c=>{const m=F(c.timestamp);let u="";x.value.includes("h")||x.value==="1d"?u=m.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):u=m.toLocaleDateString([],{month:"short",day:"numeric"})+" "+m.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),e.push(u),y.value?(s.push(c.rx_rate_mbps||0),n.push(c.tx_rate_mbps||0)):(s.push(c.bytes_received/(1024*1024)),n.push(c.bytes_sent/(1024*1024)))});const l=document.documentElement.getAttribute("data-theme")==="dark",v=l?"rgba(240, 246, 252, 0.1)":"rgba(0,0,0,0.05)",h=l?"#8b949e":"#6c757d",k=w.value.getContext("2d");g=new H(k,{type:"line",data:{labels:e,datasets:[{label:y.value?"RX Mbps":"Received (MB)",data:s,borderColor:"#1652B8",backgroundColor:"rgba(22, 82, 184, 0.15)",borderWidth:2,fill:!0,tension:.3,pointRadius:3,pointHoverRadius:4},{label:y.value?"TX Mbps":"Sent (MB)",data:n,borderColor:"#EC7C31",backgroundColor:"rgba(236, 124, 49, 0.15)",borderWidth:2,fill:!0,tension:.3,pointRadius:3,pointHoverRadius:4}]},options:{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{labels:{color:h}}},scales:{x:{ticks:{color:h,maxTicksLimit:8},grid:{color:v}},y:{beginAtZero:!0,ticks:{color:h},grid:{color:v}}}}})},B=()=>{if(!S.value)return;b&&b.destroy();const a=S.value.getContext("2d"),s=document.documentElement.getAttribute("data-theme")==="dark"?"#161b22":"#ffffff";b=new H(a,{type:"doughnut",data:{labels:["Received","Sent"],datasets:[{data:[o.totalReceived,o.totalSent],backgroundColor:["#1652B8","#EC7C31"],borderColor:s,borderWidth:2,hoverOffset:4}]},options:{responsive:!0,maintainAspectRatio:!1,cutout:"70%",plugins:{legend:{display:!1}}}})},X=(a,e)=>{if(!a||a.length===0)return[];if(a.length<=e)return a.map(l=>({timestamp:l.timestamp,bytes_received:l.total_rx,bytes_sent:l.total_tx,rx_rate_mbps:l.total_rx_rate,tx_rate_mbps:l.total_tx_rate}));const s=Math.ceil(a.length/e),n=[];for(let l=0;l<a.length;l+=s){const v=a.slice(l,l+s);if(v.length===0)continue;let h=0,k=0,c=0,m=0;v.forEach(u=>{h+=u.total_rx||0,k+=u.total_tx||0,c=Math.max(c,u.total_rx_rate||0),m=Math.max(m,u.total_tx_rate||0)}),n.push({timestamp:v[0].timestamp,bytes_received:h,bytes_sent:k,rx_rate_mbps:c,tx_rate_mbps:m})}return n};let M;return G(()=>{A(),L(),new MutationObserver(s=>{s.forEach(n=>{n.type==="attributes"&&n.attributeName==="data-theme"&&(D(),B())})}).observe(document.documentElement,{attributes:!0});const e=P.value?.refresh_interval||3e4;M=setInterval(()=>{A(),L()},e)}),q(()=>{M&&clearInterval(M),g&&g.destroy(),b&&b.destroy()}),(a,e)=>(d(),r(E,null,[t("div",tt,[t("div",et,[t("div",st,[t("h3",null,i(o.concurrentUsers),1),e[2]||(e[2]=t("p",{class:"stat-label"},"Concurrent Users (Peak)",-1))])]),t("div",at,[t("div",ot,[t("h3",null,i(I(C)(o.totalTraffic)),1),e[3]||(e[3]=t("p",{class:"stat-label"},"Traffic Volume (Total)",-1))])]),t("div",lt,[t("div",nt,[t("h3",null,i(o.expiringCerts),1),e[4]||(e[4]=t("p",{class:"stat-label"},"Expiring Soon (In 45 Days)",-1))])])]),t("div",it,[t("div",rt,[e[8]||(e[8]=t("span",null,[t("i",{class:"fas fa-chart-area me-2"}),f("Traffic Overview")],-1)),t("div",dt,[z(t("select",{class:"form-select form-select-sm",style:{width:"auto"},"onUpdate:modelValue":e[0]||(e[0]=s=>x.value=s),onChange:A},[...e[5]||(e[5]=[t("option",{value:"24h"},"Last 24 Hours",-1),t("option",{value:"7d"},"Last 7 Days",-1),t("option",{value:"30d"},"Last 1 Month",-1)])],544),[[K,x.value]]),t("div",ct,[t("div",ut,[t("label",mt,[z(t("input",{type:"checkbox",id:"vizToggle","onUpdate:modelValue":e[1]||(e[1]=s=>y.value=s),onChange:D},null,544),[[Q,y.value]]),e[6]||(e[6]=t("span",{class:"toggle-slider"},null,-1))])]),e[7]||(e[7]=t("label",{class:"small fw-bold user-select-none",style:{color:"var(--text-heading)",cursor:"pointer"},for:"vizToggle"}," Speed ",-1))])])]),t("div",ft,[t("div",pt,[t("canvas",{ref_key:"mainChartRef",ref:w},null,512)])])]),t("div",vt,[t("div",ht,[t("div",_t,[e[12]||(e[12]=t("div",{class:"card-header"},[t("i",{class:"fas fa-trophy me-2"}),f("TOP-10 Active Clients ")],-1)),t("div",gt,[t("div",bt,[t("table",xt,[e[11]||(e[11]=t("thead",null,[t("tr",null,[t("th",null,"Client Name"),t("th",null,"Total Data"),t("th",null,"Activity Share")])],-1)),t("tbody",null,[p.analytics?(d(),r("tr",yt,[...e[9]||(e[9]=[t("td",{colspan:"3",class:"text-center py-4 text-muted"},"Loading...",-1)])])):R.value.length===0?(d(),r("tr",Ct,[...e[10]||(e[10]=[t("td",{colspan:"3",class:"text-center py-4 text-muted"},"No data available",-1)])])):(d(!0),r(E,{key:2},j(R.value,s=>(d(),r("tr",{key:s.name},[t("td",null,[t("span",kt,i(s.name),1)]),t("td",wt,i(I(C)(s.total)),1),t("td",null,[t("div",St,[t("div",Rt,[t("div",{class:"progress-bar",role:"progressbar",style:$({width:s.percent+"%",backgroundColor:"#EC7C31"})},null,4)]),t("span",Tt,i(s.percent)+"%",1)])])]))),128))])])])])])]),t("div",At,[t("div",Dt,[e[14]||(e[14]=t("div",{class:"card-header d-flex justify-content-between align-items-center"},[t("span",null,[t("i",{class:"fas fa-exclamation-circle me-2"}),f("Certificate Alerts")]),t("span",{class:"badge bg-secondary",style:{"font-size":"0.7em"}},"Next 45 Days")],-1)),t("div",Mt,[p.certs?(d(),r("p",Et,"Checking certificates...")):T.value.length===0?(d(),r("p",Nt,[...e[13]||(e[13]=[t("i",{class:"fas fa-check-circle text-success me-2"},null,-1),f("All Good ",-1)])])):(d(),r("div",Lt,[(d(!0),r(E,null,j(T.value,s=>(d(),r("div",{key:s.username,class:"list-group-item px-0 py-2 d-flex justify-content-between align-items-center border-0"},[t("div",null,[t("div",Bt,i(s.username),1),t("div",Ut,"Expires: "+i(s.expiration_date),1)]),t("span",It,i(s.days_remaining)+" days",1)]))),128))]))])]),t("div",zt,[e[17]||(e[17]=t("div",{class:"card-header"},[t("i",{class:"fas fa-chart-pie me-2"}),f("Traffic Distribution ")],-1)),t("div",jt,[t("div",Ht,[t("canvas",{ref_key:"pieChartRef",ref:S},null,512)]),t("div",Ot,[t("div",Vt,[e[15]||(e[15]=t("div",{class:"small text-muted mb-1"},[t("span",{class:"legend-dot",style:{background:"#1652B8"}}),f("Download ")],-1)),t("div",Ft,i(o.totalReceivedString),1)]),t("div",null,[e[16]||(e[16]=t("div",{class:"small text-muted mb-1"},[t("span",{class:"legend-dot",style:{background:"#EC7C31"}}),f("Upload")],-1)),t("div",Pt,i(o.totalSentString),1)])])])])])])],64))}};export{Jt as default};