"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallRulesPage"],{1096:(e,t,s)=>{s.r(t),s.d(t,{SORT_ASC:()=>d,SORT_DESC:()=>u,default:()=>h});var o=s(245),r=s(247),n=s.n(r),a=s(246),i=s(90);const l=i.Locale.getTranslate("components.list"),c=i.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:i,sortDirection:u,searchField:f,locale:h,emptyView:b,emptyFilteredView:x,toolbar:P,selection:j,onSelectionChange:w,searchBarInputProps:T,rowKey:C,...R})=>{const{sortColumn:F,sortDirection:S,setSortState:k}=((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:i??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},a]=(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=>{a((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)(a.ListEmptyView,{reason:"filtered",title:(0,o.jsx)(l,{content:"emptyViewFilteredTitle"}),description:(0,o.jsx)(l,{content:"emptyViewFilteredDescription"})}):b??(0,o.jsx)(a.ListEmptyView,{title:(0,o.jsx)(l,{content:"emptyViewTitle"})})),[L,b,x]),D=(0,o.useMemo)((()=>s.map((({sortDataField:e,...t})=>t))),[s]),M=(0,o.useMemo)((()=>f&&L?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(!F)return M;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[...M].sort(((e,s)=>d===S?t(e,s):t(s,e)))}),[M,F,S,s]),B=(0,o.useMemo)((()=>{if(q===p)return O;const e=q*(v-1),t=e+q;return O.slice(e,t)}),[v,O,q]),V=(0,o.useCallback)((e=>{E({searchPattern:e}),e!==L&&E({page:1})}),[L]),$=(0,o.useCallback)((e=>{E({itemsPerPage:e});(e===p?1:Math.ceil(M.length/e))<v&&E({page:1})}),[M.length,v]);return(0,o.useEffect)((()=>{if("function"==typeof w&&j.length){const e=M.map((e=>{return t=e,"function"==typeof(s=C)?s(t):t[s];var t,s})).filter((e=>j.includes(e)));w(e)}}),[M]),(0,o.jsx)(a.List,{pagination:(0,o.jsx)(a.Pagination,{current:v,total:q===p?1:Math.ceil(M.length/q),onSelect:e=>E({page:e}),itemsPerPage:q,itemsPerPageOptions:n,onItemsPerPageChange:$}),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:L,...T??{}},onTyping:V})})]})]}),totalRows:M.length,sortColumn:F,sortDirection:S,onSortChange:k,columns:D,data:B,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},1960:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(247),r=s(246),n=s(90),a=s(245),i=s(458),l=s(774),c=s(688);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=i.gql`
    mutation UpdateFirewallRule($input: UpdateFirewallRuleInput!) {
        updateFirewallRule(input: $input) {
            key
        }
    }
`,b=({rule:e,isOpen:t,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)(d,{content:w?"successEdit":"successNew"})}),o()},refetchQueries:[{query:s(938)}],awaitRefetchQueries:!0});return(0,a.jsx)(r.Drawer,{"data-type":"firewall-rule",title:(0,a.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: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)(u,{content:"save"})},cancelButton:{id:"btn-cancel",name:"cancel",children:(0,a.jsx)(u,{content:"cancel"}),onClick:o}},children:(0,a.jsxs)(r.Section,{title:"",children:[(0,a.jsx)(r.FormFieldCheckbox,{name:"isEnabled",label:(0,a.jsx)(d,{content:"isEnabled"})}),(0,a.jsx)(r.FormFieldText,{name:"name",label:(0,a.jsx)(d,{content:"name"}),size:"lg",required:!0}),(0,a.jsx)(r.FormField,{name:"profiles",label:(0,a.jsx)(d,{content:"profiles"}),description:(0,a.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,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.FormFieldCheckbox,{id:"profileDomain",label:(0,a.jsx)(d,{content:"profileDomain"}),value:s(m),onChange:e=>o(m,e)}),(0,a.jsx)(r.FormFieldCheckbox,{id:"profilePrivate",label:(0,a.jsx)(d,{content:"profilePrivate"}),value:s(g),onChange:e=>o(g,e)}),(0,a.jsx)(r.FormFieldCheckbox,{id:"profilePublic",label:(0,a.jsx)(d,{content:"profilePublic"}),value:s(y),onChange:e=>o(y,e)})]})}}),(0,a.jsx)(r.FormFieldRadioButtons,{name:"action",label:(0,a.jsx)(d,{content:"action"}),options:[{value:f,label:(0,a.jsx)(d,{content:"actionAllow"})},{value:"BLOCK",label:(0,a.jsx)(d,{content:"actionBlock"})}]}),(0,a.jsxs)(r.FormField,{label:(0,a.jsx)(d,{content:"port"}),required:!0,children:[(0,a.jsx)(r.FormFieldText,{name:"port",label:null,description:(0,a.jsx)(d,{content:"portHint"})}),(0,a.jsx)(r.FormFieldRadioButtons,{name:"protocol",label:null,options:[{value:"TCP",label:(0,a.jsx)(d,{content:"protocolTcp"})},{value:"UDP",label:(0,a.jsx)(d,{content:"protocolUdp"})}]})]}),(0,a.jsx)(r.FormFieldText,{name:"remoteAddresses",label:(0,a.jsx)(d,{content:"remoteAddresses"}),description:(0,a.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},1959:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(247),r=s(246),n=s(90),a=s(1096),i=s(458),l=s(774),c=s(245),d=s(688),u=s(938),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=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)([]),[u,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:(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{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,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=>i(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},1958:(e,t,s)=>{s.r(t),s.d(t,{default:()=>m});var o=s(90),r=s(293),n=s(751),a=s(1959),i=s(1953),l=s(1960),c=s(745),d=s(245),u=s(938),p=s.n(u);const m=(0,n.withPageLayout)((0,i.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)}),[]),i=(0,d.useCallback)((()=>r(!1)),[]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.default,{rule:t,isOpen:o,onClose:i}),(0,d.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}}}))},1953:(e,t,s)=>{s.r(t),s.d(t,{default:()=>u,withFirewallTabs:()=>d});var o=s(245),r=s(739),n=s(740),a=s(246),i=s(90),l=s(787);const c=()=>{const{pathname:e}=(0,r.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,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:l.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?4bdcf88358a0460017eb