"use strict";(globalThis.webpackChunkPlesk=globalThis.webpackChunkPlesk||[]).push([["components/pages/FirewallRulesPage"],{1477(e,t,s){s.r(t),s.d(t,{SORT_ASC:()=>i,SORT_DESC:()=>c,default:()=>y});var o=s(396),r=s(786),n=s.n(r),a=s(397);const l=s(95).Locale.getSection("components.list"),i="ASC",c="DESC",u="all",d={set(e,t){localStorage.setItem(e,JSON.stringify(t))},get(e){const t=localStorage.getItem(e);return JSON.parse(t)}},p=e=>`list-sort_${e}`,m=e=>`list-page_${e}`,g=({id:e,data:t,columns:s,itemsPerPage:r=25,itemsPerPageOptions:n=[10,25,100,u],sortColumn:c,sortDirection:g=i,searchField:y,locale:f={},emptyView:h,emptyFilteredView:b,toolbar:x,selection:P=[],onSelectionChange:j,searchBarInputProps:w,rowKey:T="key",useStorage:C=!0,...R})=>{const{sortColumn:S,sortDirection:F,setSortState:k}=((e,{sortColumn:t,sortDirection:s})=>{const[{sortColumn:r,sortDirection:n},a]=(0,o.useState)({sortColumn:d.get(p(e))?.sortColumn??t,sortDirection:d.get(p(e))?.sortDirection??s});return{sortColumn:r,sortDirection:n,setSortState:t=>{a(e=>({...e,...t})),d.set(p(e),{...d.get(p(e)),...t})}}})(e,{sortColumn:c??s.find(({sortable:e})=>e)?.key,sortDirection:g}),{page:q,itemsPerPage:v,searchPattern:L,setPageState:E}=((e,{itemsPerPage:t},s=!0)=>{const r=s?{page:d.get(m(e))?.page,itemsPerPage:d.get(m(e))?.itemsPerPage,searchPattern:d.get(m(e))?.searchPattern}:{},[{page:n,itemsPerPage:a,searchPattern:l},i]=(0,o.useState)({page:r.page??1,itemsPerPage:r.itemsPerPage??t,searchPattern:r.searchPattern??""});return{page:n,itemsPerPage:a,searchPattern:l,setPageState:t=>{i(e=>({...e,...t})),s&&d.set(m(e),{...d.get(m(e)),...t})}}})(e,{itemsPerPage:n.includes(r)?r:n[0]},C),A=(0,o.useMemo)(()=>L?b??(0,o.jsx)(a.ListEmptyView,{reason:"filtered","data-testid":"list-empty-view-filtered"}):h??(0,o.jsx)(a.ListEmptyView,{}),[L,h,b]),D=(0,o.useMemo)(()=>s.map(({sortDataField:e,...t})=>t),[s]),M=(0,o.useMemo)(()=>y&&L?t.filter(e=>(Array.isArray(y)?y:[y]).some(t=>e[t]&&String(e[t]).toLowerCase().includes(L.toLowerCase()))):t,[t,L,y]),O=(0,o.useMemo)(()=>{if(!S)return M;const e=s.find(({key:e})=>e===S)?.sortDataField??S,t=s.find(({key:e})=>e===S)?.sort??((t,s)=>t[e]<s[e]?-1:t[e]>s[e]?1:0);return[...M].sort((e,s)=>i===F?t(e,s):t(s,e))},[M,S,F,s]),B=(0,o.useMemo)(()=>{if(v===u)return O;const e=v*(q-1),t=e+v;return O.slice(e,t)},[q,O,v]),$=(0,o.useCallback)(e=>{E({searchPattern:e}),e!==L&&E({page:1})},[L]),V=(0,o.useCallback)(e=>{E({itemsPerPage:e});(e===u?1:Math.ceil(M.length/e))<q&&E({page:1})},[M.length,q]);return(0,o.useEffect)(()=>{if("function"==typeof j&&P.length){const e=M.map(e=>{return t=e,"function"==typeof(s=T)?s(t):t[s];var t,s}).filter(e=>P.includes(e));j(e)}},[M]),(0,o.jsx)(a.List,{pagination:(0,o.jsx)(a.Pagination,{current:q,total:v===u?1:Math.ceil(M.length/v),onSelect:e=>E({page:e}),itemsPerPage:v,itemsPerPageOptions:n,onItemsPerPageChange:V}),toolbar:(x||y)&&(0,o.jsxs)(a.Toolbar,{children:[x,y&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(a.ToolbarExpander,{}),(0,o.jsx)(a.ToolbarGroup,{title:"",children:(0,o.jsx)(a.SearchBar,{inputProps:{placeholder:l.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:L,...w??{}},onTyping:$})})]})]}),totalRows:M.length,sortColumn:S,sortDirection:F,onSortChange:k,columns:D,data:B,filtered:!!L,locale:{totalRows:({totalRows:e})=>l.formatMessage("recordsTotal",{total:e}),...f},emptyView:A,onSelectionChange:j,selection:P,rowKey:T,...R})};g.propTypes={id:n().string.isRequired,data:n().array.isRequired,columns:n().array.isRequired,itemsPerPage:n().number,itemsPerPageOptions:n().array,sortColumn:n().string,sortDirection:n().string,searchField:n().oneOfType([n().string,n().arrayOf(n().string.isRequired)]),locale:n().object,emptyView:n().node,emptyFilteredView:n().node,toolbar:n().node,onSelectionChange:n().func,selection:n().array,rowKey:n().oneOfType([n().string,n().func]),searchBarInputProps:n().object,useStorage:n().bool};const y=g},2604(e,t,s){s.r(t),s.d(t,{default:()=>x});var o=s(786),r=s(397),n=s(95),a=s(396),l=s(809),i=s(700),c=s(663);const u=n.Locale.getTranslate("admin.components.forms.firewall-rule"),d=n.Locale.getTranslate("components.buttons"),p=n.Locale.getSection("admin.components.forms.firewall-rule"),m="DOMAIN",g="PRIVATE",y="PUBLIC",f="ALLOW",h=i.gql`
    mutation UpdateFirewallRule($input: UpdateFirewallRuleInput!) {
        updateFirewallRule(input: $input) {
            key
        }
    }
`,b=({rule:e,isOpen:t=!1,onClose:o})=>{const[n,i]=(0,a.useState)(null),[b,x]=(0,a.useState)(null),[P,j]=(0,a.useState)({}),{key:w,...T}=e||{};(0,a.useEffect)(()=>{i(w?T:{name:p.lmsg("newRule"),action:f,port:"",protocol:"TCP",profiles:[],remoteAddresses:[],isEnabled:!0}),x(null),j({})},[t,w]);const[C]=(0,l.useMutation)(h,{onCompleted:()=>{(0,c.addToast)({intent:"success",message:(0,a.jsx)(u,{content:w?"successEdit":"successNew"})}),o()},refetchQueries:[{query:s(768)}],awaitRefetchQueries:!0});return(0,a.jsx)(r.Drawer,{"data-type":"firewall-rule",title:(0,a.jsx)(u,{content:e?"titleEdit":"titleNew"}),isOpen:t,onClose:o,size:"sm",form:{state:b,errors:P,applyButton:!1,onSubmit:async({name:e,action:t,port:s,protocol:o,profiles:r,remoteAddresses:n,isEnabled:a})=>{x("submit"),j({});try{await C({variables:{input:{key:w,name:e,action:t,port:s,protocol:o,profiles:r,remoteAddresses:n,isEnabled:a}}})}catch(e){const{graphQLErrors:t}=e;if(t?.length)if("validate"===t[0].extensions?.category){const e=t[0].extensions.messages;j(e)}else(0,c.addToast)({intent:"danger",message:t[0].message});else(0,c.addToast)({intent:"danger",message:e.message})}finally{x(null)}},values:n,submitButton:{id:"btn-ok",name:"ok",children:(0,a.jsx)(d,{content:"save"})},cancelButton:{id:"btn-cancel",name:"cancel",children:(0,a.jsx)(d,{content:"cancel"}),onClick:o}},children:(0,a.jsxs)(r.Section,{title:"",children:[(0,a.jsx)(r.FormFieldCheckbox,{name:"isEnabled",label:(0,a.jsx)(u,{content:"isEnabled"})}),(0,a.jsx)(r.FormFieldText,{name:"name",label:(0,a.jsx)(u,{content:"name"}),size:"lg",required:!0}),(0,a.jsx)(r.FormField,{name:"profiles",label:(0,a.jsx)(u,{content:"profiles"}),description:(0,a.jsx)(u,{content:"profilesHint"}),required:!0,children:({getValue:e,setValue:t})=>{const s=t=>(e()||[]).includes(t),o=(s,o)=>t(o?[...e(),s]:e().filter(e=>e!==s));return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.FormFieldCheckbox,{id:"profileDomain",label:(0,a.jsx)(u,{content:"profileDomain"}),value:s(m),onChange:e=>o(m,e)}),(0,a.jsx)(r.FormFieldCheckbox,{id:"profilePrivate",label:(0,a.jsx)(u,{content:"profilePrivate"}),value:s(g),onChange:e=>o(g,e)}),(0,a.jsx)(r.FormFieldCheckbox,{id:"profilePublic",label:(0,a.jsx)(u,{content:"profilePublic"}),value:s(y),onChange:e=>o(y,e)})]})}}),(0,a.jsx)(r.FormFieldRadioButtons,{name:"action",label:(0,a.jsx)(u,{content:"action"}),options:[{value:f,label:(0,a.jsx)(u,{content:"actionAllow"})},{value:"BLOCK",label:(0,a.jsx)(u,{content:"actionBlock"})}]}),(0,a.jsxs)(r.FormField,{label:(0,a.jsx)(u,{content:"port"}),required:!0,children:[(0,a.jsx)(r.FormFieldText,{name:"port",label:null,description:(0,a.jsx)(u,{content:"portHint"})}),(0,a.jsx)(r.FormFieldRadioButtons,{name:"protocol",label:null,options:[{value:"TCP",label:(0,a.jsx)(u,{content:"protocolTcp"})},{value:"UDP",label:(0,a.jsx)(u,{content:"protocolUdp"})}]})]}),(0,a.jsx)(r.FormFieldText,{name:"remoteAddresses",label:(0,a.jsx)(u,{content:"remoteAddresses"}),description:(0,a.jsx)(u,{content:"remoteAddressesHint"}),multi:!0})]})})};b.propTypes={rule:o.PropTypes.shape({key:o.PropTypes.string.isRequired,name:o.PropTypes.string.isRequired,action:o.PropTypes.string.isRequired,port:o.PropTypes.string.isRequired,protocol:o.PropTypes.string.isRequired,profiles:o.PropTypes.array.isRequired,remoteAddresses:o.PropTypes.array.isRequired,isEnabled:o.PropTypes.bool.isRequired}),isOpen:o.PropTypes.bool,onClose:o.PropTypes.func.isRequired};const x=b},2603(e,t,s){s.r(t),s.d(t,{default:()=>x});var o=s(786),r=s(397),n=s(95),a=s(1477),l=s(809),i=s(700),c=s(396),u=s(663),d=s(768),p=s.n(d);const m=n.Locale.getTranslate("admin.components.lists.firewallrules"),g=n.Locale.getTranslate("components.buttons"),y=n.Locale.getSection("admin.components.lists.firewallrules"),f=i.gql`
    mutation ToggleFirewallRuleStatus($key: String!, $enable: Boolean!) {
        toggleFirewallRule(input: { key: $key, enable: $enable }) {
            key
        }
    }
`,h=i.gql`
    mutation DeleteFirewallRule($keys: [String!]!) {
        deleteFirewallRule(input: { keys: $keys }) {
            keys
        }
    }
`,b=({rules:e,onEditRule:t})=>{const[s,o]=(0,c.useState)([]),[n,i]=(0,c.useState)([]),[d,b]=(0,c.useState)([]),x=(0,c.useMemo)(()=>e.map(({action:e,isReadonly:t,remoteAddresses:s,port:o,protocol:r,profiles:n,...a})=>({description:y.lmsg("descriptionText",{action:y.lmsg(e.toLowerCase()),from:s.length?s.join(", "):y.lmsg("fromAll"),port:`${o}/${r}`,profiles:[...n].sort().join(", ").toLowerCase()}),disabled:t,action:e,remoteAddresses:s,port:o,protocol:r,profiles:n,...a})),[e]),P=(0,c.useMemo)(()=>["name","description"],[]),j=(0,c.useMemo)(()=>e.filter(({key:e})=>n.includes(e)),[e,n]),[w,{loading:T}]=(0,l.useMutation)(f,{refetchQueries:[{query:p()}],awaitRefetchQueries:!0}),[C]=(0,l.useMutation)(h,{refetchQueries:[{query:p()}],awaitRefetchQueries:!0});return(0,c.jsx)(a.default,{id:"firewall-rules-list",toolbar:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(r.ToolbarGroup,{title:y.lmsg("groupAdd"),children:(0,c.jsx)(r.Button,{id:"addFirewallRule",intent:"primary",icon:"plus",tooltip:y.lmsg("buttonAddHint"),tooltipAsLabel:!0,onClick:t})}),(0,c.jsx)(r.ToolbarGroup,{title:y.lmsg("groupActions"),children:(0,c.jsx)(r.ListOperation,{critical:!0,noSelectionText:(0,c.jsx)(m,{content:"removeEmptySelection"}),confirmationText:y.formatMessage("removeConfirmation",{name:(0,c.jsx)("b",{children:j[0]?.name}),count:j.length}),actionButtonText:(0,c.jsx)(g,{content:"yesRemove"}),cancelButtonText:(0,c.jsx)(g,{content:"cancel"}),children:(0,c.jsx)(r.Button,{id:"removeFirewallRule",onClick:async()=>{b(n);try{const{data:{deleteFirewallRule:{keys:e}}}=await C({variables:{keys:n}});e.length>0&&(0,u.addToast)({intent:"success",message:(0,c.jsx)(m,{content:"removeSuccess"})})}catch({graphQLErrors:e}){e.forEach(({message:e,debugMessage:t})=>{(0,u.addToast)({intent:"danger",message:t||e})})}finally{i([]),b([])}},children:(0,c.jsx)(m,{content:"buttonRemove"})})})})]}),columns:[{key:"status",title:(0,c.jsx)(m,{content:"status"}),sortable:!0,sortDataField:"isEnabled",width:"1%",render:({key:e,isEnabled:t})=>(0,c.jsx)(r.Switch,{id:`toggle-${e}`,tooltip:(0,c.jsx)(m,{content:t?"on":"off"}),checked:t,loading:T&&s.includes(e),onChange:()=>(async(e,t)=>{try{o(t=>[...t,e]),await w({variables:{key:e,enable:t}})}catch(e){(0,u.addToast)({intent:"danger",message:e.message})}finally{o(t=>t.filter(t=>t!==e))}})(e,!t)})},{key:"name",title:(0,c.jsx)(m,{content:"name"}),type:"title",sortable:!0,render:e=>e.disabled?e.name:(0,c.jsx)(r.Link,{onClick:()=>t(e),children:e.name})},{key:"description",title:(0,c.jsx)(m,{content:"description"}),sortable:!0}],data:x,searchField:P,sortColumn:"name",selection:n,onSelectionChange:e=>i(e),loadingRows:d,emptyView:(0,c.jsx)(r.ListEmptyView,{actions:(0,c.jsx)(r.Button,{id:"addFirewallRule",intent:"primary",tooltip:(0,c.jsx)(m,{content:"buttonAddHint"}),onClick:t,children:(0,c.jsx)(m,{content:"buttonAdd"})})})})};b.propTypes={rules:o.PropTypes.arrayOf(o.PropTypes.shape({key:o.PropTypes.string.isRequired,name:o.PropTypes.string.isRequired,action:o.PropTypes.string.isRequired,port:o.PropTypes.string.isRequired,protocol:o.PropTypes.string.isRequired,profiles:o.PropTypes.array.isRequired,remoteAddresses:o.PropTypes.array.isRequired,isEnabled:o.PropTypes.bool.isRequired,isReadonly:o.PropTypes.bool.isRequired})).isRequired,onEditRule:o.PropTypes.func.isRequired};const x=b},2602(e,t,s){s.r(t),s.d(t,{default:()=>m});var o=s(95),r=s(462),n=s(800),a=s(2603),l=s(2597),i=s(2604),c=s(738),u=s(396),d=s(768),p=s.n(d);const m=(0,n.withPageLayout)((0,l.withFirewallTabs)(()=>{const{data:{server:{firewall:{rules:e}}}}=(0,c.useQuery)(p()),[t,s]=(0,u.useState)(),[o,r]=(0,u.useState)(!1),n=(0,u.useCallback)(e=>{s(e),r(!0)},[]),l=(0,u.useCallback)(()=>r(!1),[]);return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(i.default,{rule:t,isOpen:o,onClose:l}),(0,u.jsx)(a.default,{rules:e,onEditRule:n})]})}),()=>{const{showFrames:e,pageHeader:t,pageSidebar:s}=(0,r.default)();return{showFrames:e,pageHeader:{...t,helpMenu:{...t.helpMenu,helpContext:"firewall_interface"}},pageSidebar:s,pageContentHeader:{breadcrumbs:[s.isPowerUserPanel?null:{title:o.Locale.getSection("components.pages.home").lmsg("title"),href:"/admin/home"},{title:o.Locale.getSection("admin.controllers.server.tools").lmsg("title"),href:"/admin/server/tools"},{title:o.Locale.getSection("components.pages.firewall").lmsg("title"),href:"/cp/firewall"},{title:o.Locale.getSection("components.pages.firewall-rules").lmsg("title"),href:"/cp/firewall/rules"}].filter(Boolean),tabs:[],tabsHasRootPage:!0}}})},2597(e,t,s){s.r(t),s.d(t,{default:()=>u,withFirewallTabs:()=>c});var o=s(396),r=s(717),n=s(397),a=s(95),l=s(831);const i=()=>{const{pathname:e}=(0,r.useLocation)(),t=(0,o.useMemo)(()=>[{title:a.Locale.getSection("components.pages.firewall-general").lmsg("title"),url:"/cp/firewall/general",id:"tabGeneral"},{title:a.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),url:"/cp/firewall/icmp",id:"tabIcmp"},{title:a.Locale.getSection("components.pages.firewall-rules").lmsg("title"),url:"/cp/firewall/rules",id:"tabRules"}],[]),s=(0,o.useMemo)(()=>t.findIndex(({url:t})=>(0,r.matchPath)(t,e))+1,[t,e]);return(0,o.jsx)(n.Tabs,{active:s,children:t.map(({url:e,...t})=>(0,o.jsx)(n.Tab,{component:l.default,to:e,...t},e))})},c=e=>{const t=t=>(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i,{...t}),(0,o.jsx)(e,{...t})]});return t.displayName=`withFirewallTabs(${e.displayName||e.name||"Component"})`,t.WrappedComponent=e,t},u=i}}]);
//# sourceMappingURL=FirewallRulesPage.js.map?46ea7c88364be1c54e9b