ruleset: emit time ranges when both start and stop times are specified
[project/firewall4.git] / root / usr / share / firewall4 / templates / redirect.uc
index 592af0f7949b4ca0ab2586cb936d80212cc8d543..5b81f64bab240e0bfd8e9e809de06285d0b3a1cc 100644 (file)
        {{ fw4.ipproto(redirect.family) }} saddr {{ fw4.set(redirect.saddrs_pos) }} {%+ endif -%}
 {%+ if (redirect.saddrs_neg): -%}
        {{ fw4.ipproto(redirect.family) }} saddr != {{ fw4.set(redirect.saddrs_neg) }} {%+ endif -%}
+{%+ for (let a in redirect.saddrs_masked): -%}
+       {{ fw4.ipproto(redirect.family) }} saddr & {{ a.mask }} {{ a.invert ? '!=' : '==' }} {{ a.addr }} {%+ endfor -%}
 {%+ if (redirect.daddrs_pos): -%}
        {{ fw4.ipproto(redirect.family) }} daddr {{ fw4.set(redirect.daddrs_pos) }} {%+ endif -%}
 {%+ if (redirect.daddrs_neg): -%}
        {{ fw4.ipproto(redirect.family) }} daddr != {{ fw4.set(redirect.daddrs_neg) }} {%+ endif -%}
+{%+ for (let a in redirect.daddrs_masked): -%}
+       {{ fw4.ipproto(redirect.family) }} daddr & {{ a.mask }} {{ a.invert ? '!=' : '==' }} {{ a.addr }} {%+ endfor -%}
 {%+ if (redirect.sports_pos): -%}
        {{ redirect.proto.name }} sport {{ fw4.set(redirect.sports_pos) }} {%+ endif -%}
 {%+ if (redirect.sports_neg): -%}
 {%+ if (redirect.limit): -%}
        limit rate {{ redirect.limit.rate }}/{{ redirect.limit.unit }}
        {%- if (redirect.limit_burst): %} burst {{ redirect.limit_burst }} packets{% endif %} {%+ endif -%}
-{%+ if (redirect.start_date): -%}
-       meta time >= {{
-               exists(redirect.start_date, "hour") ? fw4.datetime(redirect.start_date) : fw4.date(redirect.start_date)
-       }} {%+ endif -%}
-{%+ if (redirect.stop_date): -%}
-       meta time <= {{
-               exists(redirect.stop_date, "hour") ? fw4.datetime(redirect.stop_date) : fw4.date(redirect.stop_date)
-       }} {%+ endif -%}
-{%+ if (redirect.start_time): -%}
-       meta hour >= {{ fw4.time(redirect.start_time) }} {%+ endif -%}
-{%+ if (redirect.stop_time): -%}
-       meta hour <= {{ fw4.time(redirect.stop_time) }} {%+ endif -%}
+{%+ if (redirect.start_date && redirect.stop_date): -%}
+       meta time {{ fw4.datestamp(redirect.start_date) }}-{{ fw4.datestamp(redirect.stop_date) }} {%+
+   elif (redirect.start_date): -%}
+       meta time >= {{ fw4.datestamp(redirect.start_date) }} {%+
+   elif (redirect.stop_date): -%}
+       meta time <= {{ fw4.datestamp(redirect.stop_date) }} {%+
+   endif -%}
+{%+ if (redirect.start_time && redirect.stop_time): -%}
+       meta hour {{ fw4.time(redirect.start_time) }}-{{ fw4.time(redirect.stop_time) }} {%+
+   elif (redirect.start_time): -%}
+       meta hour >= {{ fw4.time(redirect.start_time) }} {%+
+   elif (redirect.stop_time): -%}
+       meta hour <= {{ fw4.time(redirect.stop_time) }} {%+
+   endif -%}
 {%+ if (redirect.weekdays): -%}
        meta day{% if (redirect.weekdays.invert): %} !={% endif %} {{ fw4.set(redirect.weekdays.days) }} {%+ endif -%}
 {%+ if (redirect.mark && redirect.mark.mask < 0xFFFFFFFF): -%}
@@ -62,6 +68,6 @@
 {%- elif (redirect.target == "accept" || redirect.target == "masquerade"): -%}
        {{ redirect.target }}
 {%- else -%}
-       {{ redirect.target }} {{ redirect.raddr ? fw4.host(redirect.raddr) : '' }}
+       {{ redirect.target }} {{ redirect.raddr ? fw4.host(redirect.raddr, redirect.rport != null) : '' }}
        {%- if (redirect.rport): %}:{{ fw4.port(redirect.rport) }}{% endif %}
-{% endif %} comment {{ fw4.quote("!fw4: " + redirect.name, true) }}
+{% endif %} comment {{ fw4.quote(`!fw4: ${redirect.name}`, true) }}