"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallRulesPage"],{1026:(e,t,s)=>{s.r(t),s.d(t,{SORT_ASC:()=>u,SORT_DESC:()=>d,default:()=>h});var o=s(270),r=s(272),n=s.n(r),a=s(271),l=s(89);const i=l.Locale.getTranslate("components.list"),c=l.Locale.getSection("components.list"),u="ASC",d="DESC",p="all",m={set(e,t){localStorage.setItem(e,JSON.stringify(t))},get(e){const t=localStorage.getItem(e);return JSON.parse(t)}},g=e=>`list-sort_${e}`,y=e=>`list-page_${e}`,f=({id:e,data:t,columns:s,itemsPerPage:r=25,itemsPerPageOptions:n=[10,25,100,p],sortColumn:l,sortDirection:d=u,searchField:f,locale:h={},emptyView:b,emptyFilteredView:x,toolbar:P,selection:j=[],onSelectionChange:w,searchBarInputProps:T,rowKey:C="key",useStorage:R=!0,...S})=>{const{sortColumn:F,sortDirection:k,setSortState:q}=((e,{sortColumn:t,sortDirection:s})=>{const[{sortColumn:r,sortDirection:n},a]=(0,o.useState)({sortColumn:m.get(g(e))?.sortColumn??t,sortDirection:m.get(g(e))?.sortDirection??s});return{sortColumn:r,sortDirection:n,setSortState:t=>{a((e=>({...e,...t}))),m.set(g(e),{...m.get(g(e)),...t})}}})(e,{sortColumn:l??s.find((({sortable:e})=>e))?.key,sortDirection:d}),{page:v,itemsPerPage:L,searchPattern:E,setPageState:A}=((e,{itemsPerPage:t},s=!0)=>{const r=s?{page:m.get(y(e))?.page,itemsPerPage:m.get(y(e))?.itemsPerPage,searchPattern:m.get(y(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&&m.set(y(e),{...m.get(y(e)),...t})}}})(e,{itemsPerPage:n.includes(r)?r:n[0]},R),D=(0,o.useMemo)((()=>E?x??(0,o.jsx)(a.ListEmptyView,{reason:"filtered",title:(0,o.jsx)(i,{content:"emptyViewFilteredTitle"}),description:(0,o.jsx)(i,{content:"emptyViewFilteredDescription"}),"data-testid":"list-empty-view-filtered"}):b??(0,o.jsx)(a.ListEmptyView,{title:(0,o.jsx)(i,{content:"emptyViewTitle"})})),[E,b,x]),M=(0,o.useMemo)((()=>s.map((({sortDataField:e,...t})=>t))),[s]),O=(0,o.useMemo)((()=>f&&E?t.filter((e=>(Array.isArray(f)?f:[f]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(E.toLowerCase()))))):t),[t,E,f]),B=(0,o.useMemo)((()=>{if(!F)return O;const e=s.find((({key:e})=>e===F))?.sortDataField??F,t=s.find((({key:e})=>e===F))?.sort??((t,s)=>t[e]<s[e]?-1:t[e]>s[e]?1:0);return[...O].sort(((e,s)=>u===k?t(e,s):t(s,e)))}),[O,F,k,s]),V=(0,o.useMemo)((()=>{if(L===p)return B;const e=L*(v-1),t=e+L;return B.slice(e,t)}),[v,B,L]),$=(0,o.useCallback)((e=>{A({searchPattern:e}),e!==E&&A({page:1})}),[E]),I=(0,o.useCallback)((e=>{A({itemsPerPage:e});(e===p?1:Math.ceil(O.length/e))<v&&A({page:1})}),[O.length,v]);return(0,o.useEffect)((()=>{if("function"==typeof w&&j.length){const e=O.map((e=>{return t=e,"function"==typeof(s=C)?s(t):t[s];var t,s})).filter((e=>j.includes(e)));w(e)}}),[O]),(0,o.jsx)(a.List,{pagination:(0,o.jsx)(a.Pagination,{current:v,total:L===p?1:Math.ceil(O.length/L),onSelect:e=>A({page:e}),itemsPerPage:L,itemsPerPageOptions:n,onItemsPerPageChange:I}),toolbar:(P||f)&&(0,o.jsxs)(a.Toolbar,{children:[P,f&&(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:c.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:E,...T??{}},onTyping:$})})]})]}),totalRows:O.length,sortColumn:F,sortDirection:k,onSortChange:q,columns:M,data:V,filtered:!!E,locale:{totalRows:({totalRows:e})=>c.formatMessage("recordsTotal",{total:e}),...h},emptyView:D,onSelectionChange:w,selection:j,rowKey:C,...S})};f.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 h=f},2091:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(272),r=s(271),n=s(89),a=s(270),l=s(511),i=s(637),c=s(548);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=l.gql`
    mutation UpdateFirewallRule($input: UpdateFirewallRuleInput!) {
        updateFirewallRule(input: $input) {
            key
        }
    }
`,b=({rule:e,isOpen:t=!1,onClose:o})=>{const[n,l]=(0,a.useState)(null),[b,x]=(0,a.useState)(null),[P,j]=(0,a.useState)({}),{key:w,...T}=e||{};(0,a.useEffect)((()=>{l(w?T:{name:p.lmsg("newRule"),action:f,port:"",protocol:"TCP",profiles:[],remoteAddresses:[],isEnabled:!0}),x(null),j({})}),[t,w]);const[C]=(0,i.useMutation)(h,{onCompleted:()=>{(0,c.addToast)({intent:"success",message:(0,a.jsx)(u,{content:w?"successEdit":"successNew"})}),o()},refetchQueries:[{query:s(878)}],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},2090:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(272),r=s(271),n=s(89),a=s(1026),l=s(511),i=s(637),c=s(270),u=s(548),d=s(878),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=l.gql`
    mutation ToggleFirewallRuleStatus($key: String!, $enable: Boolean!) {
        toggleFirewallRule(input: { key: $key, enable: $enable }) {
            key
        }
    }
`,h=l.gql`
    mutation DeleteFirewallRule($keys: [String!]!) {
        deleteFirewallRule(input: { keys: $keys }) {
            keys
        }
    }
`,b=({rules:e,onEditRule:t})=>{const[s,o]=(0,c.useState)([]),[n,l]=(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,i.useMutation)(f,{refetchQueries:[{query:p()}],awaitRefetchQueries:!0}),[C]=(0,i.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:(0,c.jsx)(m,{content:"buttonAddHint"}),"aria-label":y.lmsg("buttonAddHint"),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{l([]),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)("a",{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=>l(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},2089:(e,t,s)=>{s.r(t),s.d(t,{default:()=>m});var o=s(89),r=s(323),n=s(611),a=s(2090),l=s(2084),i=s(2091),c=s(598),u=s(270),d=s(878),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}}}))},2084:(e,t,s)=>{s.r(t),s.d(t,{default:()=>d,withFirewallTabs:()=>u});var o=s(270),r=s(592),n=s(593),a=s(271),l=s(89),i=s(655);const c=()=>{const{pathname:e}=(0,r.useLocation)(),t=(0,o.useMemo)((()=>[{title:l.Locale.getSection("components.pages.firewall-general").lmsg("title"),url:"/cp/firewall/general",id:"tabGeneral"},{title:l.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),url:"/cp/firewall/icmp",id:"tabIcmp"},{title:l.Locale.getSection("components.pages.firewall-rules").lmsg("title"),url:"/cp/firewall/rules",id:"tabRules"}]),[]),s=(0,o.useMemo)((()=>t.findIndex((({url:t})=>(0,n.matchPath)(t,e)))+1),[t,e]);return(0,o.jsx)(a.Tabs,{active:s,children:t.map((({url:e,...t})=>(0,o.jsx)(a.Tab,{component:i.default,to:e,...t},e)))})},u=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},d=c}}]);
//# sourceMappingURL=FirewallRulesPage.js.map?7f778648949a0cfca86b