"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallRulesPage"],{1701:(e,t,s)=>{s.r(t),s.d(t,{SORT_ASC:()=>d,SORT_DESC:()=>u,default:()=>h});var o=s(243),r=s(247),n=s.n(r),i=s(244),l=s(90);const a=l.Locale.getTranslate("components.list"),c=l.Locale.getSection("components.list"),d="ASC",u="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,itemsPerPageOptions:n,sortColumn:l,sortDirection:u,searchField:f,locale:h,emptyView:b,emptyFilteredView:x,toolbar:P,selection:j,onSelectionChange:w,searchBarInputProps:T,rowKey:C,...R})=>{const{sortColumn:S,sortDirection:F,setSortState:k}=((e,{sortColumn:t,sortDirection:s})=>{const[{sortColumn:r,sortDirection:n},i]=(0,o.useState)({sortColumn:m.get(g(e))?.sortColumn??t,sortDirection:m.get(g(e))?.sortDirection??s});return{sortColumn:r,sortDirection:n,setSortState:t=>{i((e=>({...e,...t}))),m.set(g(e),{...m.get(g(e)),...t})}}})(e,{sortColumn:l??s.find((({sortable:e})=>e))?.key,sortDirection:u}),{page:v,itemsPerPage:q,searchPattern:L,setPageState:E}=((e,{itemsPerPage:t})=>{const[{page:s,itemsPerPage:r,searchPattern:n},i]=(0,o.useState)({page:m.get(y(e))?.page??1,itemsPerPage:m.get(y(e))?.itemsPerPage??t,searchPattern:m.get(y(e))?.searchPattern??""});return{page:s,itemsPerPage:r,searchPattern:n,setPageState:t=>{i((e=>({...e,...t}))),m.set(y(e),{...m.get(y(e)),...t})}}})(e,{itemsPerPage:n.includes(r)?r:n[0]}),A=(0,o.useMemo)((()=>L?x??(0,o.jsx)(i.ListEmptyView,{reason:"filtered",title:(0,o.jsx)(a,{content:"emptyViewFilteredTitle"}),description:(0,o.jsx)(a,{content:"emptyViewFilteredDescription"})}):b??(0,o.jsx)(i.ListEmptyView,{title:(0,o.jsx)(a,{content:"emptyViewTitle"})})),[L,b,x]),D=(0,o.useMemo)((()=>f?t.filter((e=>(Array.isArray(f)?f:[f]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(L.toLowerCase()))))):t),[t,L,f]),O=(0,o.useMemo)((()=>{if(!S)return D;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[...D].sort(((e,s)=>d===F?t(e,s):t(s,e)))}),[D,S,F,s]),M=(0,o.useMemo)((()=>{if(q===p)return O;const e=q*(v-1),t=e+q;return O.slice(e,t)}),[v,O,q]),B=(0,o.useCallback)((e=>{E({searchPattern:e}),e!==L&&E({page:1})}),[L]),V=(0,o.useCallback)((e=>{E({itemsPerPage:e});(e===p?1:Math.ceil(D.length/e))<v&&E({page:1})}),[D.length,v]);return(0,o.useEffect)((()=>{if("function"==typeof w&&j.length){const e=D.map((e=>{return t=e,"function"==typeof(s=C)?s(t):t[s];var t,s})).filter((e=>j.includes(e)));w(e)}}),[D]),(0,o.jsx)(i.List,{pagination:(0,o.jsx)(i.Pagination,{current:v,total:q===p?1:Math.ceil(D.length/q),onSelect:e=>E({page:e}),itemsPerPage:q,itemsPerPageOptions:n,onItemsPerPageChange:V}),toolbar:(P||f)&&(0,o.jsxs)(i.Toolbar,{children:[P,f&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(i.ToolbarExpander,{}),(0,o.jsx)(i.ToolbarGroup,{title:"",children:(0,o.jsx)(i.SearchBar,{inputProps:{placeholder:c.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:L,...T??{}},onTyping:B})})]})]}),totalRows:D.length,sortColumn:S,sortDirection:F,onSortChange:k,columns:s,data:M,filtered:!!L,locale:{totalRows:({totalRows:e})=>c.formatMessage("recordsTotal",{total:e}),...h},emptyView:A,onSelectionChange:w,selection:j,rowKey:C,...R})};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},f.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 h=f},1885:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(247),r=s(244),n=s(90),i=s(243),l=s(445),a=s(762),c=s(237);const d=n.Locale.getTranslate("admin.components.forms.firewall-rule"),u=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,onClose:o})=>{const[n,l]=(0,i.useState)(null),[b,x]=(0,i.useState)(null),[P,j]=(0,i.useState)({}),{key:w,...T}=e||{};(0,i.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,a.useMutation)(h,{onCompleted:()=>{(0,c.addToast)({intent:"success",message:(0,i.jsx)(d,{content:w?"successEdit":"successNew"})}),o()},refetchQueries:[{query:s(864)}],awaitRefetchQueries:!0});return(0,i.jsx)(r.Drawer,{"data-type":"firewall-rule",title:(0,i.jsx)(d,{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:i})=>{x("submit"),j({});try{await C({variables:{input:{key:w,name:e,action:t,port:s,protocol:o,profiles:r,remoteAddresses:n,isEnabled:i}}})}catch({graphQLErrors:e}){if("validate"===e[0].extensions.category){const t=e[0].extensions.messages;j(t)}else(0,c.addToast)({intent:"danger",message:e[0].message})}finally{x(null)}},values:n,submitButton:{id:"btn-ok",name:"ok",children:(0,i.jsx)(u,{content:"save"})},cancelButton:{id:"btn-cancel",name:"cancel",children:(0,i.jsx)(u,{content:"cancel"}),onClick:o}},children:(0,i.jsxs)(r.Section,{title:"",children:[(0,i.jsx)(r.FormFieldCheckbox,{name:"isEnabled",label:(0,i.jsx)(d,{content:"isEnabled"})}),(0,i.jsx)(r.FormFieldText,{name:"name",label:(0,i.jsx)(d,{content:"name"}),size:"lg",required:!0}),(0,i.jsx)(r.FormField,{name:"profiles",label:(0,i.jsx)(d,{content:"profiles"}),description:(0,i.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,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(r.FormFieldCheckbox,{id:"profileDomain",label:(0,i.jsx)(d,{content:"profileDomain"}),value:s(m),onChange:e=>o(m,e)}),(0,i.jsx)(r.FormFieldCheckbox,{id:"profilePrivate",label:(0,i.jsx)(d,{content:"profilePrivate"}),value:s(g),onChange:e=>o(g,e)}),(0,i.jsx)(r.FormFieldCheckbox,{id:"profilePublic",label:(0,i.jsx)(d,{content:"profilePublic"}),value:s(y),onChange:e=>o(y,e)})]})}}),(0,i.jsx)(r.FormFieldRadioButtons,{name:"action",label:(0,i.jsx)(d,{content:"action"}),options:[{value:f,label:(0,i.jsx)(d,{content:"actionAllow"})},{value:"BLOCK",label:(0,i.jsx)(d,{content:"actionBlock"})}]}),(0,i.jsxs)(r.FormField,{label:(0,i.jsx)(d,{content:"port"}),required:!0,children:[(0,i.jsx)(r.FormFieldText,{name:"port",label:null,description:(0,i.jsx)(d,{content:"portHint"})}),(0,i.jsx)(r.FormFieldRadioButtons,{name:"protocol",label:null,options:[{value:"TCP",label:(0,i.jsx)(d,{content:"protocolTcp"})},{value:"UDP",label:(0,i.jsx)(d,{content:"protocolUdp"})}]})]}),(0,i.jsx)(r.FormFieldText,{name:"remoteAddresses",label:(0,i.jsx)(d,{content:"remoteAddresses"}),description:(0,i.jsx)(d,{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},b.defaultProps={rule:void 0,isOpen:!1};const x=b},1884:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(247),r=s(244),n=s(90),i=s(1701),l=s(445),a=s(762),c=s(243),d=s(237),u=s(864),p=s.n(u);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)([]),[u,b]=(0,c.useState)([]),x=(0,c.useMemo)((()=>e.map((({action:e,isReadonly:t,remoteAddresses:s,port:o,protocol:r,profiles:n,...i})=>({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,...i})))),[e]),P=(0,c.useMemo)((()=>["name","description"]),[]),j=(0,c.useMemo)((()=>e.filter((({key:e})=>n.includes(e)))),[e,n]),[w,{loading:T}]=(0,a.useMutation)(f,{refetchQueries:[{query:p()}],awaitRefetchQueries:!0}),[C]=(0,a.useMutation)(h,{refetchQueries:[{query:p()}],awaitRefetchQueries:!0});return(0,c.jsx)(i.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,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{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,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:P,sortColumn:"name",selection:n,onSelectionChange:e=>l(e),loadingRows:u,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},1883:(e,t,s)=>{s.r(t),s.d(t,{default:()=>m});var o=s(90),r=s(291),n=s(745),i=s(1884),l=s(1878),a=s(1885),c=s(739),d=s(243),u=s(864),p=s.n(u);const m=(0,n.withPageLayout)((0,l.withFirewallTabs)((()=>{const{data:{server:{firewall:{rules:e}}}}=(0,c.useQuery)(p()),[t,s]=(0,d.useState)(),[o,r]=(0,d.useState)(!1),n=(0,d.useCallback)((e=>{s(e),r(!0)}),[]),l=(0,d.useCallback)((()=>r(!1)),[]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(a.default,{rule:t,isOpen:o,onClose:l}),(0,d.jsx)(i.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}}}))},1878:(e,t,s)=>{s.r(t),s.d(t,{default:()=>u,withFirewallTabs:()=>d});var o=s(243),r=s(733),n=s(734),i=s(244),l=s(90),a=s(775);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)(i.Tabs,{active:s,children:t.map((({url:e,...t})=>(0,o.jsx)(i.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?29b1ba165acb6a433a72