Mercurial > prosody-modules
annotate mod_dnsbl/mod_dnsbl.lua @ 6257:fa45ae704b79
mod_cloud_notify: Update Readme
diff --git a/mod_cloud_notify/README.md b/mod_cloud_notify/README.md
--- a/mod_cloud_notify/README.md
+++ b/mod_cloud_notify/README.md
@@ -1,109 +1,106 @@
----
-labels:
-- 'Stage-Beta'
-summary: 'XEP-0357: Cloud push notifications'
----
+# Introduction
-Introduction
-============
+This module enables support for sending "push notifications" to clients
+that need it, typically those running on certain mobile devices.
-This module enables support for sending "push notifications" to clients that
-need it, typically those running on certain mobile devices.
+As well as this module, your client must support push notifications (the
+apps that need it generally do, of course) and the app developer's push
+gateway must be reachable from your Prosody server (this happens over a
+normal XMPP server-to-server 's2s' connection).
-As well as this module, your client must support push notifications (the apps
-that need it generally do, of course) and the app developer's push gateway
-must be reachable from your Prosody server (this happens over a normal XMPP
-server-to-server 's2s' connection).
-
-Details
-=======
+# Details
Some platforms, notably Apple's iOS and many versions of Android, impose
-limits that prevent applications from running or accessing the network in the
-background. This makes it difficult or impossible for an XMPP application to
-remain reliably connected to a server to receive messages.
-
-In order for messaging and other apps to receive notifications, the OS vendors
-run proprietary servers that their OS maintains a permanent connection to in
-the background. Then they provide APIs to application developers that allow
-sending notifications to specific devices via those servers.
+limits that prevent applications from running or accessing the network
+in the background. This makes it difficult or impossible for an XMPP
+application to remain reliably connected to a server to receive
+messages.
-When you connect to your server with an app that requires push notifications,
-it will use this module to set up a "push registration". When you receive
-a message but your device is not connected to the server, this module will
-generate a notification and send it to the push gateway operated by your
-application's developers). Their gateway will then connect to your device's
-OS vendor and ask them to forward the notification to your device. When your
-device receives the notification, it will display it or wake up the app so it
-can connect to XMPP and receive any pending messages.
+In order for messaging and other apps to receive notifications, the OS
+vendors run proprietary servers that their OS maintains a permanent
+connection to in the background. Then they provide APIs to application
+developers that allow sending notifications to specific devices via
+those servers.
-This protocol is described for developers in [XEP-0357: Push Notifications].
+When you connect to your server with an app that requires push
+notifications, it will use this module to set up a "push registration".
+When you receive a message but your device is not connected to the
+server, this module will generate a notification and send it to the push
+gateway operated by your application's developers). Their gateway will
+then connect to your device's OS vendor and ask them to forward the
+notification to your device. When your device receives the notification,
+it will display it or wake up the app so it can connect to XMPP and
+receive any pending messages.
-For this module to work reliably, you must have [mod_smacks], [mod_mam] and
-[mod_carbons] also enabled on your server.
+This protocol is described for developers in \[XEP-0357: Push
+Notifications\].
+
+For this module to work reliably, you must have \[mod_smacks\],
+\[mod_mam\] and \[mod_carbons\] also enabled on your server.
-Some clients, notably Siskin and Snikket iOS need some additional extensions
-that are not currently defined in a standard XEP. To support these clients,
-see [mod_cloud_notify_extensions].
+Some clients, notably Siskin and Snikket iOS need some additional
+extensions that are not currently defined in a standard XEP. To support
+these clients, see \[mod_cloud_notify_extensions\].
-Configuration
-=============
+# Configuration
- Option Default Description
- ------------------------------------ ----------------- -------------------------------------------------------------------------------------------------------------------
- `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty
- `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled
- `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached)
- `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours)
- `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended.
- `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended.
+ Option Default Description
+ -------------------------------------- ---------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty
+ `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled
+ `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached)
+ `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours)
+ `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended.
+ `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended.
-(\*) There are privacy implications for enabling these options.
+(\*) There are privacy implications for enabling these options.[^1]
-Internal design notes
-=====================
+# Internal design notes
-App servers are notified about offline messages, messages stored by [mod_mam]
-or messages waiting in the smacks queue.
-The business rules outlined [here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) are all honored[^2].
+App servers are notified about offline messages, messages stored by
+\[mod_mam\] or messages waiting in the smacks queue. The business rules
+outlined
+[here](//mail.jabber.org/pipermail/standards/2016-February/030925.html)
+are all honored[^2].
-To cooperate with [mod_smacks] this module consumes some events:
-`smacks-ack-delayed`, `smacks-hibernation-start` and `smacks-hibernation-end`.
-These events allow this module to send out notifications for messages received
-while the session is hibernated by [mod_smacks] or even when smacks
-acknowledgements for messages are delayed by a certain amount of seconds
-configurable with the [mod_smacks] setting `smacks_max_ack_delay`.
+To cooperate with \[mod_smacks\] this module consumes some events:
+`smacks-ack-delayed`, `smacks-hibernation-start` and
+`smacks-hibernation-end`. These events allow this module to send out
+notifications for messages received while the session is hibernated by
+\[mod_smacks\] or even when smacks acknowledgements for messages are
+delayed by a certain amount of seconds configurable with the
+\[mod_smacks\] setting `smacks_max_ack_delay`.
-The `smacks_max_ack_delay` setting allows to send out notifications to clients
-which aren't already in smacks hibernation state (because the read timeout or
-connection close didn't already happen) but also aren't responding to acknowledgement
-request in a timely manner. This setting thus allows conversations to be smoother
-under such circumstances.
+The `smacks_max_ack_delay` setting allows to send out notifications to
+clients which aren't already in smacks hibernation state (because the
+read timeout or connection close didn't already happen) but also aren't
+responding to acknowledgement request in a timely manner. This setting
+thus allows conversations to be smoother under such circumstances.
-The new event `cloud-notify-ping` can be used by any module to send out a cloud
-notification to either all registered endpoints for the given user or only the endpoints
-given in the event data.
+The new event `cloud-notify-ping` can be used by any module to send out
+a cloud notification to either all registered endpoints for the given
+user or only the endpoints given in the event data.
-The config setting `push_notification_important_body` can be used to specify an alternative
-body text to send to the remote pubsub node if the stanza is encrypted or has a body.
-This way the real contents of the message aren't revealed to the push appserver but it
-can still see that the push is important.
-This is used by Chatsecure on iOS to send out high priority pushes in those cases for example.
+The config setting `push_notification_important_body` can be used to
+specify an alternative body text to send to the remote pubsub node if
+the stanza is encrypted or has a body. This way the real contents of the
+message aren't revealed to the push appserver but it can still see that
+the push is important. This is used by Chatsecure on iOS to send out
+high priority pushes in those cases for example.
-Compatibility
-=============
-
-**Note:** This module should be used with Lua 5.2 and higher. Using it with
-Lua 5.1 may cause push notifications to not be sent to some clients.
+# Compatibility
------- -----------------------------------------------------------------------------
- trunk Works
- 0.12 Works
- 0.11 Works
- 0.10 Works
- 0.9 Support dropped, use last supported version [675726ab06d3](//hg.prosody.im/prosody-modules/raw-file/675726ab06d3/mod_cloud_notify/mod_cloud_notify.lua)
------- -----------------------------------------------------------------------------
+**Note:** This module should be used with Lua 5.2 and higher. Using it
+with Lua 5.1 may cause push notifications to not be sent to some
+clients.
+ ------- -----------------------------------------------------------------
+ trunk Works as of 25-06-13
+ 13 Works
+ 0.12 Works
+ ------- -----------------------------------------------------------------
-[^1]: The service which is expected to forward notifications to something like Google Cloud Messaging or Apple Notification Service
-[^2]: [business_rules.markdown](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.markdown)
+[^1]: The service which is expected to forward notifications to
+ something like Google Cloud Messaging or Apple Notification Service
+
+[^2]: [business_rules.md](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.md)
| author | Menel <menel@snikket.de> |
|---|---|
| date | Fri, 13 Jun 2025 10:36:52 +0200 |
| parents | 99860e1b817d |
| children | ec4a0e4d950e |
| rev | line source |
|---|---|
|
6133
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local lfs = require "lfs"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local adns = require "net.adns"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local it = require "util.iterators"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local parse_cidr = require "util.ip".parse_cidr; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local parse_ip = require "util.ip".new_ip; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local promise = require "util.promise"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local set = require "util.set"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local st = require "util.stanza"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local render_message = require "util.interpolation".new("%b{}", function (s) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 return s; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local trie = module:require("mod_anti_spam/trie"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local dnsbls_config_raw = module:get_option("dnsbls"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local default_dnsbl_flag = module:get_option_string("dnsbl_flag", "dnsbl_hit"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local default_dnsbl_message = module:get_option("dnsbl_message"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 if not dnsbls_config_raw then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 module:log_status("error", "No 'dnsbls' in config file"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 return; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local dnsbls = set.new(); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local dnsbls_config = {}; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 for k, v in ipairs(dnsbls_config_raw) do |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local dnsbl_name, dnsbl_config; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 if type(k) == "string" then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 dnsbl_name = k; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 dnsbl_config = v; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 else |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 dnsbl_name = v; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 dnsbl_config = {}; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 dnsbls:add(dnsbl_name); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 dnsbls_config[dnsbl_name] = dnsbl_config; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 local function read_dnsbl_file(filename) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 local t = trie.new(); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 local f, err = io.open(filename); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 if not f then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 module:log("error", "Failed to read file: %s", err); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 return t; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local n_line, n_added = 0, 0; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 for line in f:lines() do |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 n_line = n_line + 1; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 line = line:gsub("#.+$", ""):match("^%s*(.-)%s*$"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 if line == "" then -- luacheck: ignore 542 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 -- Skip |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 else |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 local parsed_ip, parsed_bits = parse_cidr(line); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 if not parsed_ip then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 -- Skip |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 module:log("warn", "Failed to parse IP/CIDR on %s:%d", filename, n_line); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 else |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 if not parsed_bits then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 -- Default to full length of IP address |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 parsed_bits = #parsed_ip.packed * 8; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 t:add_subnet(parsed_ip, parsed_bits); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 n_added = n_added + 1; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 module:log("info", "Loaded %d entries from %s", n_added, filename); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 return t; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 local ipsets = {}; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 local ipsets_last_updated = {}; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 function reload_file_dnsbls() |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 for dnsbl in dnsbls do |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 if dnsbl:byte(1) == 64 then -- '@' |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 local filename = dnsbl:sub(2); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 local file_last_updated = lfs.attributes(filename, "change"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 if (ipsets_last_updated[dnsbl] or 0) < file_last_updated then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 ipsets[dnsbl] = read_dnsbl_file(filename); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 ipsets_last_updated[dnsbl] = file_last_updated; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 module:hook_global("config-reloaded", reload_file_dnsbls); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 reload_file_dnsbls(); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 local mod_flags = module:depends("flags"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 local function reverse(ip, suffix) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 local a,b,c,d = ip:match("^(%d+).(%d+).(%d+).(%d+)$"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 if not a then return end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 return ("%d.%d.%d.%d.%s"):format(d,c,b,a, suffix); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 function check_dnsbl(ip_address, dnsbl, callback, ud) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 if dnsbl:byte(1) == 64 then -- '@' |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 local parsed_ip = parse_ip(ip_address); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 if not parsed_ip then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 module:log("warn", "Failed to parse IP address: %s", ip_address); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 callback(ud, false, dnsbl); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 return; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 callback(ud, not not ipsets[dnsbl]:contains_ip(parsed_ip), dnsbl); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 return; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 else |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 if ip_address:sub(1,7):lower() == "::ffff:" then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 ip_address = ip_address:sub(8); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 local rbl_ip = reverse(ip_address, dnsbl); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 if not rbl_ip then return; end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 module:log("debug", "Sending DNSBL lookup for %s", ip_address); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 adns.lookup(function (reply) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 local hit = not not (reply and reply[1]); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 module:log("debug", "Received DNSBL result for %s: %s", ip_address, hit and "present" or "absent"); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 callback(ud, hit, dnsbl); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 end, rbl_ip); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 local function handle_dnsbl_register_result(registration_event, hit, dnsbl) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 if not hit then return; end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 if registration_event.dnsbl_match then return; end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 registration_event.dnsbl_match = true; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 local username = registration_event.username; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 local flag = dnsbls_config[dnsbl].flag or default_dnsbl_flag; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 module:log("info", "Flagging %s for user %s registered from %s matching %s", flag, username, registration_event.ip, dnsbl); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 mod_flags:add_flag(username, flag, "Matched "..dnsbl); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 local msg = dnsbls_config[dnsbl].message or default_dnsbl_message; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 if msg then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 module:log("debug", "Sending warning message to %s", username); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 local msg_stanza = st.message( |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 { |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 to = username.."@"..module.host; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 from = module.host; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 }, |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 render_message(msg, { registration = registration_event }) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 ); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 module:send(msg_stanza); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 module:hook("user-registered", function (event) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 local session = event.session; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 local ip = event.ip or (session and session.ip); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 if not ip then return; end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 if not event.ip then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 event.ip = ip; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 for dnsbl in dnsbls do |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 check_dnsbl(ip, dnsbl, handle_dnsbl_register_result, event); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 end); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 module:add_item("account-trait", { |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 name = "register-dnsbl-hit"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 prob_bad_true = 0.6; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 prob_bad_false = 0.4; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 }); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 module:hook("get-account-traits", function (event) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 event.traits["register-dnsbl-hit"] = mod_flags.has_flag(event.username, default_dnsbl_flag); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 end); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 module:add_item("shell-command", { |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 section = "dnsbl"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 section_desc = "Manage DNS blocklists"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 name = "lists"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 desc = "Show all lists currently in use on the specified host"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 args = { |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 { name = "host", type = "string" }; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 }; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 host_selector = "host"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 handler = function(self, host) --luacheck: ignore 212/self 212/host |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 local count = 0; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 for list in dnsbls do |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 count = count + 1; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 self.session.print(list); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 return true, ("%d lists"):format(count); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 end; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 }); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 module:add_item("shell-command", { |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 section = "dnsbl"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 section_desc = "Manage DNS blocklists"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 name = "check"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 desc = "Check an IP against the configured block lists"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 args = { |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 { name = "host", type = "string" }; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 { name = "ip_address", type = "string" }; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 }; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 host_selector = "host"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 handler = function(self, host, ip_address) --luacheck: ignore 212/self 212/host |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 local parsed_ip = parse_ip(ip_address); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 if not parsed_ip then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 return false, "Failed to parse IP address"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 local matches, total = 0, 0; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 local promises = {}; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 for dnsbl in dnsbls do |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 total = total + 1; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 promises[dnsbl] = promise.new(function (resolve) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 check_dnsbl(parsed_ip, dnsbl, resolve, true); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 end); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 return promise.all_settled(promises):next(function (results) |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 for dnsbl, result in it.sorted_pairs(results) do |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 local msg; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 if result.status == "fulfilled" then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 if result.value then |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 msg = "[X]"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 matches = matches + 1; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 else |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 msg = "[ ]"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 else |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 msg = "[?]"; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 print(msg, dnsbl); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 end |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 return ("Found in %d of %d lists"):format(matches, total); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 end); |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 end; |
|
99860e1b817d
mod_dnsbl: Flag accounts registered by IPs matching blocklists
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 }); |
