From 755a2a577dbbfbdb90c3a2ee7c319b3c28f98876 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Tue, 27 Feb 2024 19:26:37 +0100 Subject: [PATCH] Can ask `dnsmanagerd` for the final zonefile, fancy display. --- src/App/Container.purs | 3 ++- src/App/ZoneInterface.purs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/App/Container.purs b/src/App/Container.purs index 3b4a56a..db1a4d9 100644 --- a/src/App/Container.purs +++ b/src/App/Container.purs @@ -637,9 +637,10 @@ handleAction = case _ of m@(DNSManager.MkRRAdded response) -> do handleAction $ Log $ SuccessLog $ "Resource Record added: " <> response.rr.rrtype handleAction $ DispatchDNSMessage m - (DNSManager.MkGeneratedZoneFile response) -> do + m@(DNSManager.MkGeneratedZoneFile response) -> do handleAction $ Log $ SuccessLog $ "Received the generated zonefile for " <> response.domain handleAction $ Log $ SuccessLog $ "TODO: show it, " <> response.zonefile + handleAction $ DispatchDNSMessage m (DNSManager.MkInvalidDomainName _) -> do handleAction $ Log $ ErrorLog $ "The domain is not valid!" m@(DNSManager.MkDomainDeleted response) -> do diff --git a/src/App/ZoneInterface.purs b/src/App/ZoneInterface.purs index 5925b84..a09be19 100644 --- a/src/App/ZoneInterface.purs +++ b/src/App/ZoneInterface.purs @@ -134,6 +134,9 @@ data Action -- | Automatically closes the modal. | RemoveRR RRId + -- | Ask `dnsmanagerd` for the generated zone file. + | AskZoneFile + data RRModal = NoModal | NewRRModal AcceptedRRTypes @@ -175,6 +178,8 @@ type State = -- Unique RR form. , _currentRR :: ResourceRecord , _currentRR_errors :: Array Validation.Error + + , _zonefile :: Maybe String } component :: forall m. MonadAff m => H.Component Query Input Output m @@ -235,6 +240,7 @@ initialState domain = , _currentRR: default_empty_rr -- List of errors within the form in new RR modal. , _currentRR_errors: [] + , _zonefile: Nothing } type SortableRecord l = Record (rrtype :: String, rrid :: Int | l) @@ -253,6 +259,7 @@ render state , render_resources $ sorted state._resources , Bulma.hr , render_new_records state + , render_zonefile state._zonefile ] ] where @@ -605,6 +612,14 @@ handleAction = case _ of -- Modal doesn't need to be active anymore. handleAction CancelModal + AskZoneFile -> do + state <- H.get + H.raise $ Log $ SystemLog $ "Asking for the '" <> state._domain <> "' zonefile" + message <- H.liftEffect + $ DNSManager.serialize + $ DNSManager.MkAskGeneratedZoneFile { domain: state._domain } + H.raise $ MessageToSend message + handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a) handleQuery = case _ of @@ -622,6 +637,8 @@ handleQuery = case _ of -- Remove the resource record. state <- H.get H.modify_ _ { _resources = A.filter (\rr -> rr.rrid /= response.rrid) state._resources } + (DNSManager.MkGeneratedZoneFile response) -> do + H.modify_ _ { _zonefile = Just response.zonefile } (DNSManager.MkZone response) -> do add_entries response.zone.resources @@ -793,7 +810,6 @@ render_new_records :: forall (w :: Type). State -> HH.HTML w Action render_new_records _ = Bulma.hdiv [ Bulma.h1 "Adding new records" - , Bulma.hr -- use "level" to get horizontal buttons next to each other (probably vertical on mobile) , Bulma.level [ Bulma.btn "A" (CreateNewRRModal A) @@ -804,8 +820,23 @@ render_new_records _ , Bulma.btn "MX" (CreateNewRRModal MX) , Bulma.btn "SRV" (CreateNewRRModal SRV) ] [] + , Bulma.hr + , Bulma.h1 "Special records about the mail system (soon)" + -- use "level" to get horizontal buttons next to each other (probably vertical on mobile) + , Bulma.level [ + Bulma.btn_ro (C.is_small <> C.is_warning) "SPF" + , Bulma.btn_ro (C.is_small <> C.is_warning) "DKIM" + , Bulma.btn_ro (C.is_small <> C.is_warning) "DMARC" + ] [] + , Bulma.hr + , Bulma.level [ + Bulma.btn "Get the final zone file." AskZoneFile + ] [HH.text "For debug purposes. ⚠"] ] +render_zonefile :: forall (w :: Type). Maybe String -> HH.HTML w Action +render_zonefile zonefile = Bulma.box [ maybe (HH.text "") (\x -> HH.pre_ [HH.text x]) zonefile ] + -- ACTIONS first :: forall a. (a -> Boolean) -> Array a -> Maybe a