Software /
code /
prosody-modules
Annotate
mod_block_registrations/mod_block_registrations.lua @ 5173:460f78654864
mod_muc_rtbl: also filter messages
This was a bit tricky because we don't want to run the JIDs
through SHA256 on each message. Took a while to come up with this
simple plan of just caching the SHA256 of the JIDs on the
occupants.
This will leave some dirt in the occupants after unloading the
module, but that should be ok; once they cycle the room, the
hashes will be gone.
This is direly needed, otherwise, there is a tight race between
the moderation activities and the actors joining the room.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 21 Feb 2023 21:37:27 +0100 |
parent | 5065:368bf9b06484 |
rev | line source |
---|---|
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local st = require "util.stanza"; |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local nodeprep = require "util.encodings".stringprep.nodeprep; |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
5065
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
4 local block_users = module:get_option_set("block_registrations_users", { |
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
5 "abuse", "admin", "administrator", "hostmaster", "info", "news", |
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
6 "noc", "operator", "owner", "postmaster", "register", "registration", |
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
7 "root", "security", "service", "signup", "support", "sysadmin", |
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
8 "sysop", "system", "test", "trouble", "webmaster", "www", "xmpp", |
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
9 }); |
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local block_patterns = module:get_option_set("block_registrations_matching", {}); |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local require_pattern = module:get_option_string("block_registrations_require"); |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 function is_blocked(username) |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 -- Check if the username is simply blocked |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 if block_users:contains(username) then return true; end |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 for pattern in block_patterns do |
1697
27aa58ed3e2e
mod_block_registrations: string.find is faster than string.match when only needing a boolean answer
Kim Alvefur <zash@zash.se>
parents:
1331
diff
changeset
|
18 if username:find(pattern) then |
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 return true; |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 -- Not blocked, but check that username matches allowed pattern |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 if require_pattern and not username:match(require_pattern) then |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 return true; |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
1331
dbaa67babeb4
mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents:
1053
diff
changeset
|
28 module:hook("user-registering", function(event) |
dbaa67babeb4
mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents:
1053
diff
changeset
|
29 local username = event.username; |
dbaa67babeb4
mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents:
1053
diff
changeset
|
30 if is_blocked(username) then |
dbaa67babeb4
mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents:
1053
diff
changeset
|
31 event.allowed = false; |
dbaa67babeb4
mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents:
1053
diff
changeset
|
32 return true; |
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end, 10); |