Last active
May 31, 2024 19:51
-
-
Save LXGaming/e7f766bdf0e88966f5c98e20728210f8 to your computer and use it in GitHub Desktop.
Caddy - Invert Request Matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(negate) { | |
# Set the initial values | |
vars {args.0} false | |
vars {args.1} true | |
# On match invert the values | |
vars @{args.0} {args.0} true | |
vars @{args.0} {args.1} false | |
# Create the inverse matcher | |
@{args.1} `{vars.{args.1}} != false` | |
} | |
example.com { | |
@allowed remote_ip 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 127.0.0.1/8 | |
import negate allowed denied | |
# Example | |
handle @allowed { | |
respond "Allowed: {vars.allowed} / {vars.denied}" | |
} | |
# Example | |
handle @denied { | |
respond "Denied: {vars.allowed} / {vars.denied}" | |
} | |
# Example | |
respond @denied 403 | |
skip_log @allowed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment