"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallRulesPage"],{1129:(e,t,s)=>{s.r(t),s.d(t,{SORT_ASC:()=>u,SORT_DESC:()=>d,default:()=>h});var o=s(270),n=s(272),r=s.n(n),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:n=25,itemsPerPageOptions:r=[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",...R})=>{const{sortColumn:S,sortDirection:F,setSortState:k}=((e,{sortColumn:t,sortDirection:s})=>{const[{sortColumn:n,sortDirection:r},a]=(0,o.useState)({sortColumn:m.get(g(e))?.sortColumn??t,sortDirection:m.get(g(e))?.sortDirection??s});return{sortColumn:n,sortDirection:r,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:q,itemsPerPage:v,searchPattern:L,setPageState:E}=((e,{itemsPerPage:t})=>{const[{page:s,itemsPerPage:n,searchPattern:r},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:n,searchPattern:r,setPageState:t=>{a((e=>({...e,...t}))),m.set(y(e),{...m.get(y(e)),...t})}}})(e,{itemsPerPage:r.includes(n)?n:r[0]}),A=(0,o.useMemo)((()=>L?x??(0,o.jsx)(a.ListEmptyView,{reason:"filtered",title:(0,o.jsx)(i,{content:"emptyViewFilteredTitle"}),description:(0,o.jsx)(i,{content:"emptyViewFilteredDescription"})}):b??(0,o.jsx)(a.ListEmptyView,{title:(0,o.jsx)(i,{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(!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)=>u===F?t(e,s):t(s,e)))}),[M,S,F,s]),B=(0,o.useMemo)((()=>{if(v===p)return O;const e=v*(q-1),t=e+v;return O.slice(e,t)}),[q,O,v]),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))<q&&E({page:1})}),[M.length,q]);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:q,total:v===p?1:Math.ceil(M.length/v),onSelect:e=>E({page:e}),itemsPerPage:v,itemsPerPageOptions:r,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:S,sortDirection:F,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:r().string.isRequired,data:r().array.isRequired,columns:r().array.isRequired,itemsPerPage:r().number,itemsPerPageOptions:r().array,sortColumn:r().string,sortDirection:r().string,searchField:r().oneOfType([r().string,r().arrayOf(r().string.isRequired)]),locale:r().object,emptyView:r().node,emptyFilteredView:r().node,toolbar:r().node,onSelectionChange:r().func,selection:r().array,rowKey:r().oneOfType([r().string,r().func]),searchBarInputProps:r().object};const h=f},2012:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(272),n=s(271),r=s(89),a=s(270),l=s(495),i=s(614),c=s(530);const u=r.Locale.getTranslate("admin.components.forms.firewall-rule"),d=r.Locale.getTranslate("components.buttons"),p=r.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[r,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(809)}],awaitRefetchQueries:!0});return(0,a.jsx)(n.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:n,remoteAddresses:r,isEnabled:a})=>{x("submit"),j({});try{await C({variables:{input:{key:w,name:e,action:t,port:s,protocol:o,profiles:n,remoteAddresses:r,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:r,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)(n.Section,{title:"",children:[(0,a.jsx)(n.FormFieldCheckbox,{name:"isEnabled",label:(0,a.jsx)(u,{content:"isEnabled"})}),(0,a.jsx)(n.FormFieldText,{name:"name",label:(0,a.jsx)(u,{content:"name"}),size:"lg",required:!0}),(0,a.jsx)(n.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)(n.FormFieldCheckbox,{id:"profileDomain",label:(0,a.jsx)(u,{content:"profileDomain"}),value:s(m),onChange:e=>o(m,e)}),(0,a.jsx)(n.FormFieldCheckbox,{id:"profilePrivate",label:(0,a.jsx)(u,{content:"profilePrivate"}),value:s(g),onChange:e=>o(g,e)}),(0,a.jsx)(n.FormFieldCheckbox,{id:"profilePublic",label:(0,a.jsx)(u,{content:"profilePublic"}),value:s(y),onChange:e=>o(y,e)})]})}}),(0,a.jsx)(n.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)(n.FormField,{label:(0,a.jsx)(u,{content:"port"}),required:!0,children:[(0,a.jsx)(n.FormFieldText,{name:"port",label:null,description:(0,a.jsx)(u,{content:"portHint"})}),(0,a.jsx)(n.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)(n.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},2011:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var o=s(272),n=s(271),r=s(89),a=s(1129),l=s(495),i=s(614),c=s(270),u=s(530),d=s(809),p=s.n(d);const m=r.Locale.getTranslate("admin.components.lists.firewallrules"),g=r.Locale.getTranslate("components.buttons"),y=r.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)([]),[r,l]=(0,c.useState)([]),[d,b]=(0,c.useState)([]),x=(0,c.useMemo)((()=>e.map((({action:e,isReadonly:t,remoteAddresses:s,port:o,protocol:n,profiles:r,...a})=>({description:y.lmsg("descriptionText",{action:y.lmsg(e.toLowerCase()),from:s.length?s.join(", "):y.lmsg("fromAll"),port:`${o}/${n}`,profiles:[...r].sort().join(", ").toLowerCase()}),disabled:t,action:e,remoteAddresses:s,port:o,protocol:n,profiles:r,...a})))),[e]),P=(0,c.useMemo)((()=>["name","description"]),[]),j=(0,c.useMemo)((()=>e.filter((({key:e})=>r.includes(e)))),[e,r]),[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)(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:j[0]?.name}),count:j.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()=>{b(r);try{const{data:{deleteFirewallRule:{keys:e}}}=await C({variables:{keys:r}});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)(n.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:r,onSelectionChange:e=>l(e),loadingRows:d,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"})})})})};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},2010:(e,t,s)=>{s.r(t),s.d(t,{default:()=>m});var o=s(89),n=s(313),r=s(590),a=s(2011),l=s(2005),i=s(2012),c=s(579),u=s(270),d=s(809),p=s.n(d);const m=(0,r.withPageLayout)((0,l.withFirewallTabs)((()=>{const{data:{server:{firewall:{rules:e}}}}=(0,c.useQuery)(p()),[t,s]=(0,u.useState)(),[o,n]=(0,u.useState)(!1),r=(0,u.useCallback)((e=>{s(e),n(!0)}),[]),l=(0,u.useCallback)((()=>n(!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:r})]})})),(()=>{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}}}))},2005:(e,t,s)=>{s.r(t),s.d(t,{default:()=>d,withFirewallTabs:()=>u});var o=s(270),n=s(574),r=s(575),a=s(271),l=s(89),i=s(630);const c=()=>{const{pathname:e}=(0,n.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,r.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?fb1f201c1f708ac08423