From: Ralph Ronnquist Date: Sat, 1 Jan 2022 11:01:55 +0000 (+1100) Subject: add net option and minor code polishing X-Git-Tag: 0.1~36 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=d0a5e6f8bb58cd5ed78b293bffaeae3398e1e4ab;p=rrq%2Fhourglass.git add net option and minor code polishing --- diff --git a/ipset-control.lsp b/ipset-control.lsp index 9c9bf93..899e37a 100644 --- a/ipset-control.lsp +++ b/ipset-control.lsp @@ -1,15 +1,18 @@ # Should load from "ipset.cfg" -(constant 'TABLE "TIMO" 'NET "192.168.104.0/24" - 'IPSET "/sbin/ipset" ) +(constant 'IPSET "/sbin/ipset" 'TABLE "TIMO" ) -# Apply "add" or "del" on the controllable as needed, and exit +;; Return current low-leve "close" or "open" status +(define (current-status) + (if (exec (format "%s list %s | grep %s" IPSET TABLE NET)) "close" "open")) + +;; Ensure low-level setting is "close" or "open" as given (define (control cmd reason) - (let ((a (case cmd ("open" "del") ("close" "add") (true "XXX")))) - (when (!= cmd (if (exec (format "%s list %s | grep %s" IPSET TABLE NET)) - "close" "open")) - (! (println (date-value) (format " ipset-control (%s): " reason) - (format "%s %s %s %s" IPSET a TABLE NET))))) - (exit 0)) + (when (!= cmd (current-status)) + (let ((todo (case cmd ("open" "del") ("close" "add") (true "XXX")))) + (! (println (date-value) + (format " ipset-control (%s): " reason) + (format "%s %s %s %s" IPSET todo TABLE NET))))) + ) "ipset-control.lsp"