From 7086992b22c50b7697b8e489c966e49f16f0d7fb Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sat, 7 May 2016 17:48:42 +0200 Subject: [PATCH] filter: localise time_based_rules variable usage Even though we take a hit for running through the filter rules array again, it's the first step for sidestepping the need to use the config to inject our cron job and flush the rules in mid-reload... --- src/etc/inc/filter.inc | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc index ef11127b9..30843535c 100644 --- a/src/etc/inc/filter.inc +++ b/src/etc/inc/filter.inc @@ -30,9 +30,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -/* For installing cron job of schedules */ -$time_based_rules = false; - /* Create a global array to avoid errors on rulesets. */ $GatewaysList = array(); @@ -162,11 +159,14 @@ function filter_delete_states_for_down_gateways() function filter_configure_sync() { - global $config, $time_based_rules, $filterdns, $aliases; + global $config, $filterdns, $aliases; /* holds the tables to be flushed *AFTER* the filter is fully loaded */ $after_filter_configure_run = array(); + /* For installing cron job of schedules */ + $time_based_rules = false; + $FilterIflist = filter_generate_optcfg_array(); /* Use filter lock to not allow concurrent filter reloads during this run. */ @@ -364,10 +364,14 @@ function filter_configure_sync() } /* if time based rules are enabled then swap in the set */ - if ($time_based_rules == true) { - filter_tdr_install_cron(true); - } else { - filter_tdr_install_cron(false); + if (isset($config['filter']['rule'])) { + foreach ($config['filter']['rule'] as $rule) { + if (isset($rule['sched']) && !empty($rule['sched'])) { + $time_based_rules = true; + break; + } + } + filter_tdr_install_cron($time_based_rules); } if (file_exists("/var/run/booting")) { @@ -2748,7 +2752,7 @@ function filter_generate_user_rule(&$FilterIflist, $rule) function filter_rules_generate(&$FilterIflist) { - global $config, $time_based_rules, $GatewaysList; + global $config, $GatewaysList; $fix_rule_label = 'fix_rule_label'; @@ -3248,9 +3252,6 @@ EOD; $rule_arr3[] = filter_generate_user_rule_arr($FilterIflist, $rule); } } - if (isset($rule['sched']) && !empty($rule['sched'])) { - $time_based_rules = true; - } } $ipfrules .= "\n# User-defined rules follow\n";