Mercurial > prosody-modules
comparison mod_audit/mod_audit.lua @ 5731:1bdc6b5979ee
mod_audit: Use new module API for period/time ranges
It was added around the same time as the parse_duration function
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 26 Nov 2023 21:51:12 +0100 |
| parents | c77010f25b14 |
| children | 08a635862201 |
comparison
equal
deleted
inserted
replaced
| 5730:6592c444e85c | 5731:1bdc6b5979ee |
|---|---|
| 1 module:set_global(); | 1 module:set_global(); |
| 2 | 2 |
| 3 local time_now = os.time; | 3 local time_now = os.time; |
| 4 local parse_duration = require "util.human.io".parse_duration; | |
| 5 local ip = require "util.ip"; | 4 local ip = require "util.ip"; |
| 6 local st = require "util.stanza"; | 5 local st = require "util.stanza"; |
| 7 local moduleapi = require "core.moduleapi"; | 6 local moduleapi = require "core.moduleapi"; |
| 8 | 7 |
| 9 local host_wide_user = "@"; | 8 local host_wide_user = "@"; |
| 10 | 9 |
| 11 local cleanup_after = module:get_option_string("audit_log_expires_after", "28d"); | 10 local cleanup_after = module:get_option_period("audit_log_expires_after", "28d"); |
| 12 if cleanup_after == "never" then | |
| 13 cleanup_after = nil; | |
| 14 else | |
| 15 cleanup_after = parse_duration(cleanup_after); | |
| 16 end | |
| 17 | 11 |
| 18 local attach_ips = module:get_option_boolean("audit_log_ips", true); | 12 local attach_ips = module:get_option_boolean("audit_log_ips", true); |
| 19 local attach_ipv4_prefix = module:get_option_number("audit_log_ipv4_prefix", nil); | 13 local attach_ipv4_prefix = module:get_option_number("audit_log_ipv4_prefix", nil); |
| 20 local attach_ipv6_prefix = module:get_option_number("audit_log_ipv6_prefix", nil); | 14 local attach_ipv6_prefix = module:get_option_number("audit_log_ipv6_prefix", nil); |
| 21 | 15 |
| 138 local id, err = store:append(nil, nil, stanza, extra and extra.timestamp or time_now(), user_key); | 132 local id, err = store:append(nil, nil, stanza, extra and extra.timestamp or time_now(), user_key); |
| 139 if not id then | 133 if not id then |
| 140 if err == "quota-limit" then | 134 if err == "quota-limit" then |
| 141 local limit = store.caps and store.caps.quota or 1000; | 135 local limit = store.caps and store.caps.quota or 1000; |
| 142 local truncate_to = math.floor(limit * 0.99); | 136 local truncate_to = math.floor(limit * 0.99); |
| 143 if type(cleanup_after) == "number" then | 137 if cleanup_after ~= math.huge then |
| 144 module:log("debug", "Audit log has reached quota - forcing prune"); | 138 module:log("debug", "Audit log has reached quota - forcing prune"); |
| 145 if prune_audit_log(host) then | 139 if prune_audit_log(host) then |
| 146 -- Retry append | 140 -- Retry append |
| 147 id, err = store:append(nil, nil, stanza, extra and extra.timestamp or time_now(), user_key); | 141 id, err = store:append(nil, nil, stanza, extra and extra.timestamp or time_now(), user_key); |
| 148 end | 142 end |
