"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallRulesPage"],{1642:(e,t,s)=>{s.r(t),s.d(t,{SORT_ASC:()=>d,SORT_DESC:()=>u,default:()=>g});var o=s(236),n=s(238),l=s.n(n),r=s(237),i=s(87);const a=i.Locale.getTranslate("components.list"),c=i.Locale.getSection("components.list"),d="ASC",u="DESC",p="all",m=({data:e,columns:t,itemsPerPage:s,itemsPerPageOptions:n,sortColumn:l,sortDirection:i,searchField:u,locale:m,emptyView:g,emptyFilteredView:y,toolbar:f,selection:b,onSelectionChange:h,searchBarInputProps:x,rowKey:j,...w})=>{const[T,P]=(0,o.useState)(1),[R,F]=(0,o.useState)(l??t.find((({sortable:e})=>e))?.key),[C,S]=(0,o.useState)(i),[k,v]=(0,o.useState)(n.includes(s)?s:n[0]),[q,L]=(0,o.useState)(""),E=(0,o.useMemo)((()=>q?y??(0,o.jsx)(r.ListEmptyView,{reason:"filtered",title:(0,o.jsx)(a,{content:"emptyViewFilteredTitle"}),description:(0,o.jsx)(a,{content:"emptyViewFilteredDescription"})}):g??(0,o.jsx)(r.ListEmptyView,{title:(0,o.jsx)(a,{content:"emptyViewTitle"})})),[q,g,y]),A=(0,o.useMemo)((()=>u?e.filter((e=>(Array.isArray(u)?u:[u]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(q.toLowerCase()))))):e),[e,q,u]),M=(0,o.useMemo)((()=>{if(!R)return A;const e=t.find((({key:e})=>e===R))?.sortDataField??R,s=t.find((({key:e})=>e===R))?.sort??((t,s)=>t[e]<s[e]?-1:t[e]>s[e]?1:0);return[...A].sort(((e,t)=>d===C?s(e,t):s(t,e)))}),[A,R,C,t]),B=(0,o.useMemo)((()=>{if(k===p)return M;const e=k*(T-1),t=e+k;return M.slice(e,t)}),[T,M,k]),O=(0,o.useCallback)((e=>{L(e),e!==q&&P(1)}),[q]),V=(0,o.useCallback)((e=>{v(e);(e===p?1:Math.ceil(A.length/e))<T&&P(1)}),[A.length,T]);return(0,o.useEffect)((()=>{if("function"==typeof h&&b.length){const e=A.map((e=>{return t=e,"function"==typeof(s=j)?s(t):t[s];var t,s})).filter((e=>b.includes(e)));h(e)}}),[A]),(0,o.jsx)(r.List,{pagination:(0,o.jsx)(r.Pagination,{current:T,total:k===p?1:Math.ceil(A.length/k),onSelect:e=>P(e),itemsPerPage:k,itemsPerPageOptions:n,onItemsPerPageChange:V}),toolbar:(f||u)&&(0,o.jsxs)(r.Toolbar,{children:[f,u&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.ToolbarExpander,{}),(0,o.jsx)(r.ToolbarGroup,{title:"",children:(0,o.jsx)(r.SearchBar,{inputProps:{placeholder:c.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",...x??{}},onTyping:O})})]})]}),totalRows:A.length,sortColumn:R,sortDirection:C,onSortChange:({sortColumn:e,sortDirection:t})=>{F(e),S(t)},columns:t,data:B,filtered:!!q,locale:{totalRows:({totalRows:e})=>c.formatMessage("recordsTotal",{total:e}),...m},emptyView:E,onSelectionChange:h,selection:b,rowKey:j,...w})};m.propTypes={data:l().array.isRequired,columns:l().array.isRequired,itemsPerPage:l().number,itemsPerPageOptions:l().array,sortColumn:l().string,sortDirection:l().string,searchField:l().oneOfType([l().string,l().arrayOf(l().string.isRequired)]),locale:l().object,emptyView:l().node,emptyFilteredView:l().node,toolbar:l().node,onSelectionChange:l().func,selection:l().array,rowKey:l().oneOfType([l().string,l().func]),searchBarInputProps:l().object},m.defaultProps={itemsPerPage:25,itemsPerPageOptions:[10,25,100,p],sortColumn:void 0,sortDirection:d,searchField:void 0,locale:{},emptyView:void 0,emptyFilteredView:void 0,toolbar:void 0,onSelectionChange:void 0,selection:[],searchBarInputProps:void 0,rowKey:"key"};const g=m},1826:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(238),n=s(237),l=s(87),r=s(236),i=s(443),a=s(709),c=s(684);const d=l.Locale.getTranslate("admin.components.forms.firewall-rule"),u=l.Locale.getTranslate("components.buttons"),p=l.Locale.getSection("admin.components.forms.firewall-rule"),m="DOMAIN",g="PRIVATE",y="PUBLIC",f="ALLOW",b=i.gql`
    mutation UpdateFirewallRule($input: UpdateFirewallRuleInput!) {
        updateFirewallRule(input: $input) {
            key
        }
    }
`,h=({rule:e,isOpen:t,onClose:o})=>{const[l,i]=(0,r.useState)(null),[h,x]=(0,r.useState)(null),[j,w]=(0,r.useState)({}),{key:T,...P}=e||{};(0,r.useEffect)((()=>{i(T?P:{name:p.lmsg("newRule"),action:f,port:"",protocol:"TCP",profiles:[],remoteAddresses:[],isEnabled:!0}),x(null),w({})}),[t,T]);const[R]=(0,a.useMutation)(b,{onCompleted:()=>{(0,c.addToast)({intent:"success",message:(0,r.jsx)(d,{content:T?"successEdit":"successNew"})}),o()},refetchQueries:[{query:s(811)}],awaitRefetchQueries:!0});return(0,r.jsx)(n.Drawer,{"data-type":"firewall-rule",title:(0,r.jsx)(d,{content:e?"titleEdit":"titleNew"}),isOpen:t,onClose:o,size:"sm",form:{state:h,errors:j,applyButton:!1,onSubmit:async({name:e,action:t,port:s,protocol:o,profiles:n,remoteAddresses:l,isEnabled:r})=>{x("submit"),w({});try{await R({variables:{input:{key:T,name:e,action:t,port:s,protocol:o,profiles:n,remoteAddresses:l,isEnabled:r}}})}catch({graphQLErrors:e}){if("validate"===e[0].extensions.category){const t=e[0].extensions.messages;w(t)}else(0,c.addToast)({intent:"danger",message:e[0].message})}finally{x(null)}},values:l,submitButton:{id:"btn-ok",name:"ok",children:(0,r.jsx)(u,{content:"save"})},cancelButton:{id:"btn-cancel",name:"cancel",children:(0,r.jsx)(u,{content:"cancel"}),onClick:o}},children:(0,r.jsxs)(n.Section,{title:"",children:[(0,r.jsx)(n.FormFieldCheckbox,{name:"isEnabled",label:(0,r.jsx)(d,{content:"isEnabled"})}),(0,r.jsx)(n.FormFieldText,{name:"name",label:(0,r.jsx)(d,{content:"name"}),size:"lg",required:!0}),(0,r.jsx)(n.FormField,{name:"profiles",label:(0,r.jsx)(d,{content:"profiles"}),description:(0,r.jsx)(d,{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,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.FormFieldCheckbox,{id:"profileDomain",label:(0,r.jsx)(d,{content:"profileDomain"}),value:s(m),onChange:e=>o(m,e)}),(0,r.jsx)(n.FormFieldCheckbox,{id:"profilePrivate",label:(0,r.jsx)(d,{content:"profilePrivate"}),value:s(g),onChange:e=>o(g,e)}),(0,r.jsx)(n.FormFieldCheckbox,{id:"profilePublic",label:(0,r.jsx)(d,{content:"profilePublic"}),value:s(y),onChange:e=>o(y,e)})]})}}),(0,r.jsx)(n.FormFieldRadioButtons,{name:"action",label:(0,r.jsx)(d,{content:"action"}),options:[{value:f,label:(0,r.jsx)(d,{content:"actionAllow"})},{value:"BLOCK",label:(0,r.jsx)(d,{content:"actionBlock"})}]}),(0,r.jsxs)(n.FormField,{label:(0,r.jsx)(d,{content:"port"}),required:!0,children:[(0,r.jsx)(n.FormFieldText,{name:"port",label:null,description:(0,r.jsx)(d,{content:"portHint"})}),(0,r.jsx)(n.FormFieldRadioButtons,{name:"protocol",label:null,options:[{value:"TCP",label:(0,r.jsx)(d,{content:"protocolTcp"})},{value:"UDP",label:(0,r.jsx)(d,{content:"protocolUdp"})}]})]}),(0,r.jsx)(n.FormFieldText,{name:"remoteAddresses",label:(0,r.jsx)(d,{content:"remoteAddresses"}),description:(0,r.jsx)(d,{content:"remoteAddressesHint"}),multi:!0})]})})};h.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},h.defaultProps={rule:void 0,isOpen:!1};const x=h},1825:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(238),n=s(237),l=s(87),r=s(1642),i=s(443),a=s(709),c=s(236),d=s(684),u=s(811),p=s.n(u);const m=l.Locale.getTranslate("admin.components.lists.firewallrules"),g=l.Locale.getTranslate("components.buttons"),y=l.Locale.getSection("admin.components.lists.firewallrules"),f=i.gql`
    mutation ToggleFirewallRuleStatus($key: String!, $enable: Boolean!) {
        toggleFirewallRule(input: { key: $key, enable: $enable }) {
            key
        }
    }
`,b=i.gql`
    mutation DeleteFirewallRule($keys: [String!]!) {
        deleteFirewallRule(input: { keys: $keys }) {
            keys
        }
    }
`,h=({rules:e,onEditRule:t})=>{const[s,o]=(0,c.useState)([]),[l,i]=(0,c.useState)([]),[u,h]=(0,c.useState)([]),x=(0,c.useMemo)((()=>e.map((({action:e,isReadonly:t,remoteAddresses:s,port:o,protocol:n,profiles:l,...r})=>({description:y.lmsg("descriptionText",{action:y.lmsg(e.toLowerCase()),from:s.length?s.join(", "):y.lmsg("fromAll"),port:`${o}/${n}`,profiles:l.sort().join(", ").toLowerCase()}),disabled:t,action:e,remoteAddresses:s,port:o,protocol:n,profiles:l,...r})))),[e]),j=(0,c.useMemo)((()=>["name","description"]),[]),w=(0,c.useMemo)((()=>e.filter((({key:e})=>l.includes(e)))),[e,l]),[T,{loading:P}]=(0,a.useMutation)(f,{refetchQueries:[{query:p()}],awaitRefetchQueries:!0}),[R]=(0,a.useMutation)(b,{refetchQueries:[{query:p()}],awaitRefetchQueries:!0});return(0,c.jsx)(r.default,{toolbar:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(n.ToolbarGroup,{title:y.lmsg("groupAdd"),children:(0,c.jsx)(n.Button,{id:"addFirewallRule",intent:"primary",icon:"plus",tooltip:(0,c.jsx)(m,{content:"buttonAddHint"}),"aria-label":y.lmsg("buttonAddHint"),onClick:t})}),(0,c.jsx)(n.ToolbarGroup,{title:y.lmsg("groupActions"),children:(0,c.jsx)(n.ListOperation,{critical:!0,noSelectionText:(0,c.jsx)(m,{content:"removeEmptySelection"}),confirmationText:y.formatMessage("removeConfirmation",{name:(0,c.jsx)("b",{children:w[0]?.name}),count:w.length}),actionButtonText:(0,c.jsx)(g,{content:"yesRemove"}),cancelButtonText:(0,c.jsx)(g,{content:"cancel"}),children:(0,c.jsx)(n.Button,{id:"removeFirewallRule",onClick:async()=>{h(l);try{const{data:{deleteFirewallRule:{keys:e}}}=await R({variables:{keys:l}});e.length>0&&(0,d.addToast)({intent:"success",message:(0,c.jsx)(m,{content:"removeSuccess"})})}catch({graphQLErrors:e}){e.forEach((({message:e,debugMessage:t})=>{(0,d.addToast)({intent:"danger",message:t||e})}))}finally{i([]),h([])}},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)(n.Switch,{id:`toggle-${e}`,tooltip:(0,c.jsx)(m,{content:t?"on":"off"}),checked:t,loading:P&&s.includes(e),onChange:()=>(async(e,t)=>{try{o((t=>[...t,e])),await T({variables:{key:e,enable:t}})}catch(e){(0,d.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)("a",{onClick:()=>t(e),children:e.name})},{key:"description",title:(0,c.jsx)(m,{content:"description"}),sortable:!0}],data:x,searchField:j,sortColumn:"name",selection:l,onSelectionChange:e=>i(e),loadingRows:u,emptyView:(0,c.jsx)(n.ListEmptyView,{actions:(0,c.jsx)(n.Button,{id:"addFirewallRule",intent:"primary",tooltip:(0,c.jsx)(m,{content:"buttonAddHint"}),onClick:t,children:(0,c.jsx)(m,{content:"buttonAdd"})})})})};h.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=h},1824:(e,t,s)=>{s.r(t),s.d(t,{default:()=>m});var o=s(87),n=s(282),l=s(692),r=s(1825),i=s(1819),a=s(1826),c=s(686),d=s(236),u=s(811),p=s.n(u);const m=(0,l.withPageLayout)((0,i.withFirewallTabs)((()=>{const{data:{server:{firewall:{rules:e}}}}=(0,c.useQuery)(p()),[t,s]=(0,d.useState)(),[o,n]=(0,d.useState)(!1),l=(0,d.useCallback)((e=>{s(e),n(!0)}),[]),i=(0,d.useCallback)((()=>n(!1)),[]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(a.default,{rule:t,isOpen:o,onClose:i}),(0,d.jsx)(r.default,{rules:e,onEditRule:l})]})})),(()=>{const{showFrames:e,pageHeader:t,pageSidebar:s}=(0,n.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}}}))},1819:(e,t,s)=>{s.r(t),s.d(t,{default:()=>u,withFirewallTabs:()=>d});var o=s(236),n=s(679),l=s(680),r=s(237),i=s(87),a=s(722);const c=()=>{const{pathname:e}=(0,n.useLocation)(),t=(0,o.useMemo)((()=>[{title:i.Locale.getSection("components.pages.firewall-general").lmsg("title"),url:"/cp/firewall/general",id:"tabGeneral"},{title:i.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),url:"/cp/firewall/icmp",id:"tabIcmp"},{title:i.Locale.getSection("components.pages.firewall-rules").lmsg("title"),url:"/cp/firewall/rules",id:"tabRules"}]),[]),s=(0,o.useMemo)((()=>t.findIndex((({url:t})=>(0,l.matchPath)(t,e)))+1),[t,e]);return(0,o.jsx)(r.Tabs,{active:s,children:t.map((({url:e,...t})=>(0,o.jsx)(r.Tab,{component:a.default,to:e,...t},e)))})},d=e=>{const t=t=>(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(c,{...t}),(0,o.jsx)(e,{...t})]});return t.displayName=`withFirewallTabs(${e.displayName||e.name||"Component"})`,t.WrappedComponent=e,t},u=c}}]);
//# sourceMappingURL=FirewallRulesPage.js.map?28aba210af61f428d25b