mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 14:13:48 +03:00
logging: Inline Caddyfile syntax for ip_mask
filter (#6094)
This commit is contained in:
parent
e7a534d0a3
commit
91ec75441a
2 changed files with 27 additions and 0 deletions
|
@ -21,6 +21,7 @@ log {
|
||||||
ipv4 24
|
ipv4 24
|
||||||
ipv6 32
|
ipv6 32
|
||||||
}
|
}
|
||||||
|
request>client_ip ip_mask 16 32
|
||||||
request>headers>Regexp regexp secret REDACTED
|
request>headers>Regexp regexp secret REDACTED
|
||||||
request>headers>Hash hash
|
request>headers>Hash hash
|
||||||
}
|
}
|
||||||
|
@ -41,6 +42,11 @@ log {
|
||||||
},
|
},
|
||||||
"encoder": {
|
"encoder": {
|
||||||
"fields": {
|
"fields": {
|
||||||
|
"request\u003eclient_ip": {
|
||||||
|
"filter": "ip_mask",
|
||||||
|
"ipv4_cidr": 16,
|
||||||
|
"ipv6_cidr": 32
|
||||||
|
},
|
||||||
"request\u003eheaders\u003eAuthorization": {
|
"request\u003eheaders\u003eAuthorization": {
|
||||||
"filter": "replace",
|
"filter": "replace",
|
||||||
"value": "REDACTED"
|
"value": "REDACTED"
|
||||||
|
|
|
@ -169,6 +169,27 @@ func (IPMaskFilter) CaddyModule() caddy.ModuleInfo {
|
||||||
// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
|
// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
|
||||||
func (m *IPMaskFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
func (m *IPMaskFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
d.Next() // consume filter name
|
d.Next() // consume filter name
|
||||||
|
|
||||||
|
args := d.RemainingArgs()
|
||||||
|
if len(args) > 2 {
|
||||||
|
return d.Errf("too many arguments")
|
||||||
|
}
|
||||||
|
if len(args) > 0 {
|
||||||
|
val, err := strconv.Atoi(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return d.Errf("error parsing %s: %v", args[0], err)
|
||||||
|
}
|
||||||
|
m.IPv4MaskRaw = val
|
||||||
|
|
||||||
|
if len(args) > 1 {
|
||||||
|
val, err := strconv.Atoi(args[1])
|
||||||
|
if err != nil {
|
||||||
|
return d.Errf("error parsing %s: %v", args[1], err)
|
||||||
|
}
|
||||||
|
m.IPv6MaskRaw = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for d.NextBlock(0) {
|
for d.NextBlock(0) {
|
||||||
switch d.Val() {
|
switch d.Val() {
|
||||||
case "ipv4":
|
case "ipv4":
|
||||||
|
|
Loading…
Reference in a new issue