Mercurial > prosody-modules
comparison mod_audit/mod_audit.lua @ 5325:11b37063d80a
mod_audit: Add some control over output columns via command-line flags
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 07 Apr 2023 13:25:34 +0100 |
| parents | 400ffa842576 |
| children | dc058fcc3fe3 |
comparison
equal
deleted
inserted
replaced
| 5324:18fd615c2733 | 5325:11b37063d80a |
|---|---|
| 153 { title = "Date", key = "when", width = 19, mapper = function (when) return os.date("%Y-%m-%d %R:%S", when); end }; | 153 { title = "Date", key = "when", width = 19, mapper = function (when) return os.date("%Y-%m-%d %R:%S", when); end }; |
| 154 { title = "Source", key = "source", width = "2p" }; | 154 { title = "Source", key = "source", width = "2p" }; |
| 155 { title = "Event", key = "event_type", width = "2p" }; | 155 { title = "Event", key = "event_type", width = "2p" }; |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 if not arg.global then | 158 if arg.show_user ~= false and (not arg.global or arg.show_user) then |
| 159 table.insert(colspec, { | 159 table.insert(colspec, { |
| 160 title = "User", key = "username", width = "2p", | 160 title = "User", key = "username", width = "2p", |
| 161 mapper = function (user) | 161 mapper = function (user) |
| 162 if user == "@" then return ""; end | 162 if user == "@" then return ""; end |
| 163 if user:sub(-#host-1, -1) == ("@"..host) then | 163 if user:sub(-#host-1, -1) == ("@"..host) then |
| 164 return (user:gsub("@.+$", "")); | 164 return (user:gsub("@.+$", "")); |
| 165 end | 165 end |
| 166 end; | 166 end; |
| 167 }); | 167 }); |
| 168 | 168 end |
| 169 if attach_ips then | 169 if arg.show_ip ~= false and (not arg.global and attach_ips or arg.show_ip) then |
| 170 table.insert(colspec, { | 170 table.insert(colspec, { |
| 171 title = "IP", key = "ip", width = "2p"; | 171 title = "IP", key = "ip", width = "2p"; |
| 172 }); | 172 }); |
| 173 end | 173 end |
| 174 if attach_location then | 174 if arg.show_location ~= false and (not arg.global and attach_location or arg.show_location) then |
| 175 table.insert(colspec, { | 175 table.insert(colspec, { |
| 176 title = "Location", key = "country", width = 2; | 176 title = "Location", key = "country", width = 2; |
| 177 }); | 177 }); |
| 178 end | |
| 179 end | 178 end |
| 180 | 179 |
| 181 local row, width = require "util.human.io".table(colspec); | 180 local row, width = require "util.human.io".table(colspec); |
| 182 | 181 |
| 183 print(string.rep("-", width)); | 182 print(string.rep("-", width)); |
