comparison mod_audit/mod_audit.lua @ 5707:9a5fca9f90a6

mod_audit: Parse IP into util.ip object once and reuse Mostly for my own sanity
author Kim Alvefur <zash@zash.se>
date Mon, 13 Nov 2023 12:05:17 +0100
parents 655f90b149a4
children 37ba9478b387
comparison
equal deleted inserted replaced
5706:655f90b149a4 5707:9a5fca9f90a6
81 end 81 end
82 if session.type then 82 if session.type then
83 attr.type = session.type; 83 attr.type = session.type;
84 end 84 end
85 local stanza = st.stanza("session", attr); 85 local stanza = st.stanza("session", attr);
86 if attach_ips and session.ip then 86 local remote_ip = session.ip and ip.new_ip(session.ip);
87 local remote_ip, network = session.ip; 87 if attach_ips and remote_ip then
88 local network;
88 if attach_ipv4_prefix or attach_ipv6_prefix then 89 if attach_ipv4_prefix or attach_ipv6_prefix then
89 network = get_ip_network(remote_ip); 90 network = get_ip_network(remote_ip);
90 end 91 end
91 stanza:text_tag("remote-ip", network or remote_ip.normal); 92 stanza:text_tag("remote-ip", network or remote_ip.normal);
92 end 93 end
93 if attach_location and session.ip then 94 if attach_location and remote_ip then
94 local remote_ip = ip.new_ip(session.ip);
95 local geoip_country = ip.proto == "IPv6" and geoip6_country or geoip4_country; 95 local geoip_country = ip.proto == "IPv6" and geoip6_country or geoip4_country;
96 stanza:tag("location", { 96 stanza:tag("location", {
97 country = geoip_country:query_by_addr(remote_ip.normal); 97 country = geoip_country:query_by_addr(remote_ip.normal);
98 }):up(); 98 }):up();
99 end 99 end