98
98
trimsp lists
99
99
fast_el_cnt " $lists " " " lists_cnt
100
100
101
- iplist_dir=" $datadir /ip_lists"
102
-
103
- status_file=" $iplist_dir /status"
104
-
105
101
failed_lists_cnt=0
106
102
107
103
[ " $_fw_backend " = ipt ] && raw_mode=" -r"
@@ -130,10 +126,10 @@ trap 'set +f; rm -f \"$iplist_dir/\"*.iplist 2>/dev/null; eval "$trap_args_unloc
130
126
# check for valid action and translate *run action to *apply action
131
127
# *apply does the same thing whether we want to update, apply(refresh) or to add a new ip list, which is why this translation is needed
132
128
case " $action_run " in
133
- add) action_apply=add ;;
129
+ add) action_apply=add; [ ! " $lists " ] && die " no list id's were specified! " ;;
134
130
# if firewall is in incoherent state, force re-fetch
135
131
update) action_apply=add; check_lists_coherence || force=" -f" ;;
136
- remove) action_apply=remove ;;
132
+ remove) action_apply=remove; rm_lists= " $lists " ;;
137
133
restore)
138
134
check_lists_coherence -n 2> /dev/null && { echolog " Geoip firewall rules and sets are Ok. Exiting." ; die 0; }
139
135
if [ " $nobackup " ]; then
@@ -157,22 +153,24 @@ esac
157
153
158
154
# ### Daemon loop
159
155
156
+ unset echolists ok_lists missing_lists lists_fetch fetched_lists
157
+
160
158
[ ! " $daemon_mode " ] && max_attempts=1
161
- attempt=0 secs=4 ok_lists=' ' missing_lists=
159
+ case " $action_run " in add|update) lists_fetch=" $lists " ;; * ) max_attempts=1; esac
160
+
161
+ attempt=0 secs=4
162
162
while true ; do
163
163
attempt=$(( attempt+ 1 ))
164
164
secs=$(( secs+ 1 ))
165
165
[ " $daemon_mode " ] && [ $attempt -gt $max_attempts ] && die " Giving up."
166
166
167
167
# ## Fetch ip lists
168
168
169
- if [ " $action_apply " = add ]; then
170
- [ ! " $lists " ] && die " no list id's were specified!"
171
-
169
+ if [ " $action_apply " = add ] && [ " $lists_fetch " ]; then
172
170
# mark all lists as failed in the status file before launching *fetch. if *fetch completes successfully, it will reset this
173
- setstatus " $status_file " " FailedLists=$lists "
171
+ setstatus " $status_file " " FailedLists=$lists_fetch "
174
172
175
- call_script " $i_script -fetch.sh" -l " $lists " -p " $iplist_dir " -s " $status_file " -u " $dl_source " " $force " " $raw_mode "
173
+ call_script " $i_script -fetch.sh" -l " $lists_fetch " -p " $iplist_dir " -s " $status_file " -u " $dl_source " " $force " " $raw_mode "
176
174
177
175
# read *fetch results from the status file
178
176
getstatus " $status_file " FailedLists failed_lists &&
@@ -197,14 +195,16 @@ while true; do
197
195
198
196
# ## Apply ip lists
199
197
200
- san_str -s lists " $fetched_lists $ok_lists "
198
+ lists_fetch=
199
+ san_str -s ok_lists " $fetched_lists $ok_lists "
200
+ san_str -s apply_lists " $ok_lists $rm_lists "
201
201
apply_rv=0
202
202
case " $action_run " in update|add|remove)
203
- [ ! " $lists " ] && {
203
+ [ ! " $apply_lists " ] && {
204
204
echolog " Firewall reconfiguration isn't required." ; die 0
205
205
}
206
206
207
- call_script " $i_script -apply.sh" " $action_apply " -l " $lists " ; apply_rv=$?
207
+ call_script " $i_script -apply.sh" " $action_apply " -l " $apply_lists " ; apply_rv=$?
208
208
set +f; rm " $iplist_dir /" * .iplist 2> /dev/null; set -f
209
209
210
210
case " $apply_rv " in
@@ -213,7 +213,7 @@ while true; do
213
213
echolog -err " *apply exited with code '254'. $FAIL execute action '$action_apply '." ;;
214
214
* ) debugprint " NOTE: *apply exited with error code '$apply_rv '." ; die " $apply_rv "
215
215
esac
216
- echolists=" for lists '$lists '"
216
+ echolists=" for lists '$ok_lists$rm_lists '"
217
217
esac
218
218
219
219
if check_lists_coherence; then
0 commit comments