{
:global Wan1CurrentState ([:len [/ip route find where comment="WAN1_ROUTE" and !disabled]] > 0)
:global Wan2CurrentState ([:len [/ip route find where comment="WAN2_ROUTE" and !disabled]] > 0)
:global Wan1State [:len [/interface list member find where list=INTERNET and interface=WAN1]];
:global Wan2State [:len [/interface list member find where list=INTERNET and interface=WAN2]];
:if ($Wan1State = 1 and $Wan1CurrentState = false) do={:log warning "WAN1 up, enabling WAN1_ROUTE";/ip route enable [find comment=WAN1_ROUTE];}
:if ($Wan1State = 0 and $Wan1CurrentState = true) do={:log warning "WAN1 down, disabling WAN1_ROUTE";/ip route disable [find comment=WAN1_ROUTE];}
:if ($Wan2State = 1 and $Wan2CurrentState = false) do={:log warning "WAN2 up, enabling WAN2_ROUTE";/ip route enable [find comment=WAN2_ROUTE];}
:if ($Wan2State = 0 and $Wan2CurrentState = true) do={:log warning "WAN2 down, disabling WAN2_ROUTE";/ip route disable [find comment=WAN2_ROUTE];}
}