Mercurial > prosody-modules
annotate mod_firewall/marks.lib.lua @ 6557:2d916ba3253c
mod_firewall: marks: Fix shell commands
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 24 May 2026 20:04:03 +0100 |
| parents | f9d93d7cd6d5 |
| children |
| rev | line source |
|---|---|
|
6557
2d916ba3253c
mod_firewall: marks: Fix shell commands
Matthew Wild <mwild1@gmail.com>
parents:
6550
diff
changeset
|
1 local jid = require "prosody.util.jid"; |
|
2d916ba3253c
mod_firewall: marks: Fix shell commands
Matthew Wild <mwild1@gmail.com>
parents:
6550
diff
changeset
|
2 |
|
6549
d2e50b587721
mod_firewall: marks: switch to keyval+ store API
Matthew Wild <mwild1@gmail.com>
parents:
6548
diff
changeset
|
3 local mark_storage = module:open_store("firewall_marks", "keyval+"); |
|
2894
165d2877eeac
mod_firewall: Add experimental user-centric persistent marks behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
|
165d2877eeac
mod_firewall: Add experimental user-centric persistent marks behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local user_sessions = prosody.hosts[module.host].sessions; |
|
165d2877eeac
mod_firewall: Add experimental user-centric persistent marks behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
|
6548
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
7 module:hook("resource-bind", function (event) |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
8 local session = event.session; |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
9 local username = session.username; |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
10 local user = user_sessions[username]; |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
11 local marks = user.firewall_marks; |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
12 if not marks then |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
13 marks = mark_storage:get(username) or {}; |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
14 user.firewall_marks = marks; -- luacheck: ignore 122 |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
15 end |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
16 session.firewall_marks = marks; |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
17 end); |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
18 |
|
430584888704
mod_firewall: marks: load marks from storage on login
Matthew Wild <mwild1@gmail.com>
parents:
5542
diff
changeset
|
19 |
|
5536
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
20 module:hook("firewall/marked/user", function (event) |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
21 local user = user_sessions[event.username]; |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
22 local marks = user and user.firewall_marks; |
|
5541
3804ee5117ca
mod_firewall: Load marks from storage on demand rather than at login
Matthew Wild <mwild1@gmail.com>
parents:
5536
diff
changeset
|
23 if user and not marks then |
|
3804ee5117ca
mod_firewall: Load marks from storage on demand rather than at login
Matthew Wild <mwild1@gmail.com>
parents:
5536
diff
changeset
|
24 -- Load marks from storage to cache on the user object |
|
3804ee5117ca
mod_firewall: Load marks from storage on demand rather than at login
Matthew Wild <mwild1@gmail.com>
parents:
5536
diff
changeset
|
25 marks = mark_storage:get(event.username) or {}; |
|
3804ee5117ca
mod_firewall: Load marks from storage on demand rather than at login
Matthew Wild <mwild1@gmail.com>
parents:
5536
diff
changeset
|
26 user.firewall_marks = marks; --luacheck: ignore 122 |
|
3804ee5117ca
mod_firewall: Load marks from storage on demand rather than at login
Matthew Wild <mwild1@gmail.com>
parents:
5536
diff
changeset
|
27 end |
|
5536
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
28 if marks then |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
29 marks[event.mark] = event.timestamp; |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
30 end |
|
6549
d2e50b587721
mod_firewall: marks: switch to keyval+ store API
Matthew Wild <mwild1@gmail.com>
parents:
6548
diff
changeset
|
31 local ok, err = mark_storage:set_key(event.username, event.mark, event.timestamp); |
|
5536
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
32 if not ok then |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
33 module:log("error", "Failed to mark user %q with %q: %s", event.username, event.mark, err); |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
34 end |
|
5542
048284447643
mod_firewall: Add console commands to mark/unmark users
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
35 return true; |
|
048284447643
mod_firewall: Add console commands to mark/unmark users
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
36 end, -1); |
|
2894
165d2877eeac
mod_firewall: Add experimental user-centric persistent marks behind a feature flag
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
|
5536
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
38 module:hook("firewall/unmarked/user", function (event) |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
39 local user = user_sessions[event.username]; |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
40 local marks = user and user.firewall_marks; |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
41 if marks then |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
42 marks[event.mark] = nil; |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
43 end |
|
6549
d2e50b587721
mod_firewall: marks: switch to keyval+ store API
Matthew Wild <mwild1@gmail.com>
parents:
6548
diff
changeset
|
44 local ok, err = mark_storage:set_key(event.username, event.mark, nil); |
|
5536
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
45 if not ok then |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
46 module:log("error", "Failed to unmark user %q with %q: %s", event.username, event.mark, err); |
|
96dec7681af8
mod_firewall: Update user marks to store instantly via map store
Matthew Wild <mwild1@gmail.com>
parents:
2894
diff
changeset
|
47 end |
|
5542
048284447643
mod_firewall: Add console commands to mark/unmark users
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
48 return true; |
|
048284447643
mod_firewall: Add console commands to mark/unmark users
Matthew Wild <mwild1@gmail.com>
parents:
5541
diff
changeset
|
49 end, -1); |
|
6550
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
50 |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
51 module:add_item("shell-command", { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
52 section = "firewall"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
53 section_desc = "mod_firewall commands"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
54 name = "mark"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
55 desc = "Add a firewall mark to a user account"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
56 args = { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
57 { name = "user_jid", type = "string" }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
58 { name = "mark_name", type = "string" }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
59 }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
60 host_selector = "user_jid"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
61 handler = function(self, user_jid, mark_name) --luacheck: ignore 212/self 212/host |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
62 local username, host = jid.split(user_jid); |
|
6557
2d916ba3253c
mod_firewall: marks: Fix shell commands
Matthew Wild <mwild1@gmail.com>
parents:
6550
diff
changeset
|
63 if not username or not prosody.hosts[host] then |
|
6550
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
64 return nil, "Invalid JID supplied"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
65 elseif not idsafe(mark_name) then |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
66 return nil, "Invalid characters in mark name"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
67 end |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
68 if not module:fire_event("firewall/marked/user", { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
69 username = session.username; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
70 mark = mark_name; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
71 timestamp = os.time(); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
72 }) then |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
73 return nil, "Failed to set mark"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
74 end |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
75 return true, "Marked"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
76 end; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
77 }); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
78 |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
79 module:add_item("shell-command", { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
80 section = "firewall"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
81 section_desc = "mod_firewall commands"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
82 name = "unmark"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
83 desc = "Remove a firewall mark from a user account"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
84 args = { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
85 { name = "user_jid", type = "string" }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
86 { name = "mark_name", type = "string" }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
87 }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
88 host_selector = "user_jid"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
89 handler = function(self, user_jid, mark_name) --luacheck: ignore 212/self 212/host |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
90 local username, host = jid.split(user_jid); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
91 if not username or not hosts[host] then |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
92 return nil, "Invalid JID supplied"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
93 elseif not idsafe(mark_name) then |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
94 return nil, "Invalid characters in mark name"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
95 end |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
96 if not module:fire_event("firewall/unmarked/user", { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
97 username = session.username; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
98 mark = mark_name; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
99 timestamp = os.time(); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
100 }) then |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
101 return nil, "Failed to remove mark"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
102 end |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
103 return true, "Unmarked"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
104 end; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
105 }); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
106 |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
107 module:add_item("shell-command", { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
108 section = "firewall"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
109 section_desc = "mod_firewall commands"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
110 name = "marked"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
111 desc = "List all user accounts with a specific firewall mark"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
112 args = { |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
113 { name = "host", type = "string" }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
114 { name = "mark_name", type = "string" }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
115 }; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
116 host_selector = "host"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
117 handler = function(self, host, mark_name) --luacheck: ignore 212/self 212/host |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
118 if not idsafe(mark_name) then |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
119 return nil, "Invalid characters in mark name"; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
120 end |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
121 local users = mark_storage:get_key_from_all(mark_name); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
122 local usernames = {}; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
123 for username in it.keys(users) do |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
124 table.insert(usernames, username); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
125 end |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
126 table.sort(usernames, function (a, b) |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
127 return users[a] < users[b]; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
128 end); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
129 for _, username in ipairs(usernames) do |
|
6557
2d916ba3253c
mod_firewall: marks: Fix shell commands
Matthew Wild <mwild1@gmail.com>
parents:
6550
diff
changeset
|
130 self.session.print(username, os.date("%Y-%m-%d %R:%s", users[username])); |
|
6550
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
131 end |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
132 return true, ("Showing %d users"):format(#usernames); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
133 end; |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
134 }); |
|
f9d93d7cd6d5
mod_firewall: marks: Add commands for managing marks
Matthew Wild <mwild1@gmail.com>
parents:
6549
diff
changeset
|
135 |
