From 844ef76853914d83ccd2c4390ce92811c606b717 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 2 Feb 2017 05:39:08 -0800 Subject: Implement *dry-run* variable for testing. --- sample-config.txr | 1 + txrban.txr | 14 +++++++++----- 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)))) -- cgit v1.2.3