Mercurial > prosody-modules
comparison mod_register_dnsbl/mod_register_dnsbl.lua @ 2891:84670bac7348
mod_register_dnsbl: Use util.net for IP address parsing
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 23 Feb 2018 21:59:28 +0100 |
| parents | 6412595e2046 |
| children | bf9fc41bf7ad |
comparison
equal
deleted
inserted
replaced
| 2890:6412595e2046 | 2891:84670bac7348 |
|---|---|
| 1 local adns = require "net.adns"; | 1 local adns = require "net.adns"; |
| 2 local async = require "util.async"; | 2 local async = require "util.async"; |
| 3 local inet_pton = require "util.net".pton; | |
| 3 | 4 |
| 4 local rbl = module:get_option_string("registration_rbl"); | 5 local rbl = module:get_option_string("registration_rbl"); |
| 5 | 6 |
| 6 local function reverse(ip, suffix) | 7 local function reverse(ip, suffix) |
| 7 local a,b,c,d = ip:match("^(%d+).(%d+).(%d+).(%d+)$"); | 8 local n, err = inet_pton(ip); |
| 8 if not a then return end | 9 if not n then return n, err end |
| 9 return ("%d.%d.%d.%d.%s"):format(d,c,b,a, suffix); | 10 if #n == 4 then |
| 11 local a,b,c,d = n:byte(1,4); | |
| 12 return ("%d.%d.%d.%d.%s"):format(d,c,b,a, suffix); | |
| 13 end | |
| 10 end | 14 end |
| 11 | 15 |
| 12 module:hook("user-registering", function (event) | 16 module:hook("user-registering", function (event) |
| 13 local session, ip = event.session, event.ip; | 17 local session, ip = event.session, event.ip; |
| 14 if not ip then | 18 if not ip then |
