DMARC: fix rua, ruf and ri. Still work to do on selections.

This commit is contained in:
Philippe PITTOLI 2024-04-15 00:06:03 +02:00
parent 1beab72cde
commit b70874a621

View File

@ -267,7 +267,6 @@ type State =
, dmarc_mail :: String , dmarc_mail :: String
, dmarc_mail_limit :: Maybe Int , dmarc_mail_limit :: Maybe Int
, dmarc_ri :: Maybe Int
, dkim :: DKIM.DKIM , dkim :: DKIM.DKIM
, dmarc :: DMARC.DMARC , dmarc :: DMARC.DMARC
@ -329,7 +328,6 @@ initialState domain =
, dmarc_mail: "" , dmarc_mail: ""
, dmarc_mail_limit: Nothing , dmarc_mail_limit: Nothing
, dmarc_ri: Nothing
, current_tab: Zone , current_tab: Zone
} }
@ -573,9 +571,9 @@ render state
, Bulma.hr , Bulma.hr
, Bulma.div_content [Bulma.explanation Explanations.dmarc_contact] , Bulma.div_content [Bulma.explanation Explanations.dmarc_contact]
, maybe (Bulma.p "There is no address to send aggregated reports to.") , maybe (Bulma.p "There is no address to send aggregated reports to.")
(display_dmarc_mail_addresses "Addresses to contact for aggregated reports" DMARC_remove_rua) current_ruas (display_dmarc_mail_addresses "Addresses to contact for aggregated reports" DMARC_remove_rua) state.dmarc.rua
, maybe (Bulma.p "There is no address to send detailed reports to.") , maybe (Bulma.p "There is no address to send detailed reports to.")
(display_dmarc_mail_addresses "Addresses to contact for detailed reports" DMARC_remove_ruf) current_rufs (display_dmarc_mail_addresses "Addresses to contact for detailed reports" DMARC_remove_ruf) state.dmarc.ruf
, Bulma.hr , Bulma.hr
, render_dmarc_mail_errors , render_dmarc_mail_errors
@ -587,7 +585,7 @@ render state
, Bulma.hr , Bulma.hr
, Bulma.div_content [Bulma.explanation Explanations.dmarc_ri] , Bulma.div_content [Bulma.explanation Explanations.dmarc_ri]
, Bulma.box_input "idDMARCri" "Report interval (in seconds)" "86400" DMARC_ri (maybe "0" show state.dmarc_ri) , Bulma.box_input "idDMARCri" "Report interval (in seconds)" "86400" DMARC_ri (maybe "0" show state.dmarc.ri)
] ]
render_dmarc_mail_errors render_dmarc_mail_errors
@ -595,12 +593,6 @@ render state
then Bulma.notification_danger_block' then Bulma.notification_danger_block'
$ [ Bulma.h3 "Invalid mail 😥" ] <> map (Bulma.p <<< show_error_email) state._dmarc_mail_errors $ [ Bulma.h3 "Invalid mail 😥" ] <> map (Bulma.p <<< show_error_email) state._dmarc_mail_errors
else HH.div_ [ ] else HH.div_ [ ]
current_ruas = case state._currentRR.dmarc of
Nothing -> Nothing
Just dmarc -> dmarc.rua
current_rufs = case state._currentRR.dmarc of
Nothing -> Nothing
Just dmarc -> dmarc.ruf
display_domain_side = (if state._currentRR.name == (state._domain <> ".") then "" else "." <> state._domain) display_domain_side = (if state._currentRR.name == (state._domain <> ".") then "" else "." <> state._domain)
newtokenbtn = Bulma.btn (maybe "🏁​ Ask for a token" (\_ -> "🏁​ Ask for a new token") state._currentRR.token) (NewToken state._currentRR.rrid) newtokenbtn = Bulma.btn (maybe "🏁​ Ask for a token" (\_ -> "🏁​ Ask for a new token") state._currentRR.token) (NewToken state._currentRR.rrid)
@ -776,7 +768,6 @@ handleAction = case _ of
, spf_modifier_v = "" , spf_modifier_v = ""
, dmarc_mail = "" , dmarc_mail = ""
, dmarc_mail_limit = Nothing , dmarc_mail_limit = Nothing
, dmarc_ri = Nothing
, _dmarc_mail_errors = [] , _dmarc_mail_errors = []
} }
@ -865,22 +856,17 @@ handleAction = case _ of
DMARC_mail v -> H.modify_ _ { dmarc_mail = v } DMARC_mail v -> H.modify_ _ { dmarc_mail = v }
DMARC_mail_limit v -> H.modify_ _ { dmarc_mail_limit = Just $ fromMaybe 0 $ fromString v } DMARC_mail_limit v -> H.modify_ _ { dmarc_mail_limit = Just $ fromMaybe 0 $ fromString v }
DMARC_ri v -> H.modify_ _ { dmarc_ri = fromString v } DMARC_ri v -> H.modify_ _ { dmarc { ri = fromString v } }
DMARC_rua_Add -> do DMARC_rua_Add -> do
state <- H.get state <- H.get
case Email.email state.dmarc_mail of case Email.email state.dmarc_mail of
Left errors -> H.modify_ _ { _dmarc_mail_errors = errors } Left errors -> H.modify_ _ { _dmarc_mail_errors = errors }
Right _ -> do Right _ -> do
let current_ruas = case state._currentRR.dmarc of let current_ruas = fromMaybe [] state.dmarc.rua
Nothing -> []
Just dmarc -> fromMaybe [] dmarc.rua
dmarc_mail = state.dmarc_mail dmarc_mail = state.dmarc_mail
dmarc_mail_limit = state.dmarc_mail_limit dmarc_mail_limit = state.dmarc_mail_limit
new_list = current_ruas <> [ {mail: dmarc_mail, limit: dmarc_mail_limit} ] new_list = current_ruas <> [ {mail: dmarc_mail, limit: dmarc_mail_limit} ]
new_dmarc = case state._currentRR.dmarc of H.modify_ _ { dmarc { rua = Just new_list }}
Nothing -> DMARC.emptyDMARCRR { rua = Just new_list }
Just dmarc -> dmarc { rua = Just new_list }
H.modify_ _ { _currentRR { dmarc = Just new_dmarc } }
handleAction $ ResetTemporaryValues handleAction $ ResetTemporaryValues
DMARC_ruf_Add -> do DMARC_ruf_Add -> do
@ -888,16 +874,11 @@ handleAction = case _ of
case Email.email state.dmarc_mail of case Email.email state.dmarc_mail of
Left errors -> H.modify_ _ { _dmarc_mail_errors = errors } Left errors -> H.modify_ _ { _dmarc_mail_errors = errors }
Right _ -> do Right _ -> do
let current_rufs = case state._currentRR.dmarc of let current_rufs = fromMaybe [] state.dmarc.ruf
Nothing -> []
Just dmarc -> fromMaybe [] dmarc.ruf
dmarc_mail = state.dmarc_mail dmarc_mail = state.dmarc_mail
dmarc_mail_limit = state.dmarc_mail_limit dmarc_mail_limit = state.dmarc_mail_limit
new_list = current_rufs <> [ {mail: dmarc_mail, limit: dmarc_mail_limit} ] new_list = current_rufs <> [ {mail: dmarc_mail, limit: dmarc_mail_limit} ]
new_dmarc = case state._currentRR.dmarc of H.modify_ _ { dmarc { ruf = Just new_list } }
Nothing -> DMARC.emptyDMARCRR { ruf = Just new_list }
Just dmarc -> dmarc { ruf = Just new_list }
H.modify_ _ { _currentRR { dmarc = Just new_dmarc } }
handleAction $ ResetTemporaryValues handleAction $ ResetTemporaryValues
DMARC_remove_rua i -> do DMARC_remove_rua i -> do