summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-02-02 05:39:08 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-02-02 05:44:32 -0800
commit844ef76853914d83ccd2c4390ce92811c606b717 (patch)
tree3efd736ade99efe3d1033cfdad231faf773b7a03
parentd3537462d567dcd80c060af9c602ddc618f4255b (diff)
downloadtxrban-844ef76853914d83ccd2c4390ce92811c606b717.tar.gz
txrban-844ef76853914d83ccd2c4390ce92811c606b717.tar.bz2
txrban-844ef76853914d83ccd2c4390ce92811c606b717.zip
Implement *dry-run* variable for testing.
-rw-r--r--sample-config.txr1
-rw-r--r--txrban.txr14
2 files changed, 10 insertions, 5 deletions
diff --git a/sample-config.txr b/sample-config.txr
index 28a82fa..48f2a4b 100644
--- a/sample-config.txr
+++ b/sample-config.txr
@@ -7,3 +7,4 @@
@(bind *long-ban* 3600)
@(bind *ban-duration*
@(list 300 900 3600 (* 6 3600) (* 24 3600) (* 7 24 3600)))
+@(bind *dry-run* nil)
diff --git a/txrban.txr b/txrban.txr
index d150e33..f66f76e 100644
--- a/txrban.txr
+++ b/txrban.txr
@@ -54,7 +54,8 @@
(new-until (+ time howlong)))
(cond
((not cli.banned)
- (sh `@{*off*}iptables -I INPUT 1 -s @{cli.ip} -i @{*iface*} -j DROP`)
+ (unless *dry-run*
+ (sh `@{*off*}iptables -I INPUT 1 -s @{cli.ip} -i @{*iface*} -j DROP`))
(debug "banned ~a for ~a starting on ~a\n" cli.ip
(hrtime howlong) (time-string-local time "%c"))
(set cli.banned (rcons time new-until)))
@@ -85,11 +86,14 @@
(unban cli))))
(defun unban (cli)
- (sh `@{*off*}iptables -D INPUT -s @{cli.ip} -i @{*iface*} -j DROP`)
+ (unless *dry-run*
+ (sh `@{*off*}iptables -D INPUT -s @{cli.ip} -i @{*iface*} -j DROP`))
(debug "unbanned ~a\n" cli.ip)
(set cli.banned nil))
(cond
- (t (daemon nil nil)
- (openlog `txrban-@self` log-pid log-authpriv))
- (nil (set *stdlog* *stdout*))))
+ (*dry-run*
+ (set *stdlog* *stdout*))
+ (t
+ (daemon nil nil)
+ (openlog `txrban-@self` log-pid log-authpriv))))