Mercurial > prosody-hg
annotate plugins/mod_account_activity.lua @ 14150:2a66728d9e29 13.0 13.0.5
mod_proxy65: Consistently apply authorization checks
The module checked for authorization when a client asked for the address:port
of the proxy service. It did not check for authorization when processing a
request to activate a bytestream. This meant that any unauthenticated party
able to guess the IP/port and XMPP domain of a proxy65 service (generally low
difficulty) would be able to use the proxy to relay traffic between two
connections.
This factors out the permission check, and applies it to every request type.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 29 Apr 2026 11:40:43 +0100 |
| parents | f463e101fbd9 |
| children | 04c3687b5641 0c81b8fede94 |
| rev | line source |
|---|---|
|
13667
3052eae50c98
mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents:
13665
diff
changeset
|
1 local jid = require "prosody.util.jid"; |
|
13665
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local time = os.time; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local store = module:open_store(nil, "keyval+"); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 module:hook("authentication-success", function(event) |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local session = event.session; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 if session.username then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 store:set_key(session.username, "timestamp", time()); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 end); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 module:hook("resource-unbind", function(event) |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local session = event.session; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 if session.username then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 store:set_key(session.username, "timestamp", time()); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local user_sessions = prosody.hosts[module.host].sessions; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 function get_last_active(username) --luacheck: ignore 131/get_last_active |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 if user_sessions[username] then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 return os.time(), true; -- Currently connected |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 else |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local last_activity = store:get(username); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 if not last_activity then return nil; end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 return last_activity.timestamp; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 module:add_item("shell-command", { |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 section = "user"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 section_desc = "View user activity data"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 name = "activity"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 desc = "View the last recorded user activity for an account"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 args = { { name = "jid"; type = "string" } }; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 host_selector = "jid"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 handler = function(self, userjid) --luacheck: ignore 212/self |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local username = jid.prepped_split(userjid); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 local last_timestamp, is_online = get_last_active(username); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 if not last_timestamp then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 return true, "No activity"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return true, ("%s (%s)"):format(os.date("%Y-%m-%d %H:%M:%S", last_timestamp), (is_online and "online" or "offline")); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 }); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 module:add_item("shell-command", { |
|
13668
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
50 section = "user"; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
51 section_desc = "View user activity data"; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
52 name = "list_inactive"; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
53 desc = "List inactive user accounts"; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
54 args = { |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
55 { name = "host"; type = "string" }; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
56 { name = "duration"; type = "string" }; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
57 }; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
58 host_selector = "host"; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
59 handler = function(self, host, duration) --luacheck: ignore 212/self |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
60 local um = require "prosody.core.usermanager"; |
|
13682
0055c177a54c
mod_account_activity: Fix error when no duration specified in shell command
Matthew Wild <mwild1@gmail.com>
parents:
13668
diff
changeset
|
61 local duration_sec = require "prosody.util.human.io".parse_duration(duration or ""); |
|
13668
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
62 if not duration_sec then |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
63 return false, ("Invalid duration %q - try something like \"30d\""):format(duration); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
64 end |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
65 |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
66 local now = os.time(); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
67 local n_inactive, n_unknown = 0, 0; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
68 |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
69 for username in um.users(host) do |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
70 local last_active = store:get_key(username, "timestamp"); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
71 if not last_active then |
|
14047
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
72 local user_info = um.get_account_info(username, host); |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
73 local created_at; |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
74 if user_info then |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
75 created_at = user_info.created; |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
76 if created_at and (now - created_at) > duration_sec then |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
77 self.session.print(username, ""); |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
78 n_inactive = n_inactive + 1; |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
79 end |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
80 end |
|
f463e101fbd9
mod_account_activity: Handle authentication provider returning no user info
Matthew Wild <mwild1@gmail.com>
parents:
13682
diff
changeset
|
81 if not created_at then |
|
13668
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
82 n_unknown = n_unknown + 1; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
83 end |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
84 elseif (now - last_active) > duration_sec then |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
85 self.session.print(username, os.date("%Y-%m-%dT%T", last_active)); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
86 n_inactive = n_inactive + 1; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
87 end |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
88 end |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
89 |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
90 if n_unknown > 0 then |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
91 return true, ("%d accounts inactive since %s (%d unknown)"):format(n_inactive, os.date("%Y-%m-%dT%T", now - duration_sec), n_unknown); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
92 end |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
93 return true, ("%d accounts inactive since %s"):format(n_inactive, os.date("%Y-%m-%dT%T", now - duration_sec)); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
94 end; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
95 }); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
96 |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
97 module:add_item("shell-command", { |
|
13665
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 section = "migrate"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 section_desc = "Perform data migrations"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 name = "account_activity_lastlog2"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 desc = "Migrate account activity information from mod_lastlog2"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 args = { { name = "host"; type = "string" } }; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 host_selector = "host"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 handler = function(self, host) --luacheck: ignore 212/host |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 local lastlog2 = module:open_store("lastlog2", "keyval+"); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 local n_updated, n_errors, n_skipped = 0, 0, 0; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 |
|
13667
3052eae50c98
mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents:
13665
diff
changeset
|
108 local async = require "prosody.util.async"; |
|
13665
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
|
13667
3052eae50c98
mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents:
13665
diff
changeset
|
110 local p = require "prosody.util.promise".new(function (resolve) |
|
13665
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 local async_runner = async.runner(function () |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 local n = 0; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 for username in lastlog2:items() do |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 n = n + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 if n % 100 == 0 then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 self.session.print(("Processed %d..."):format(n)); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 async.sleep(0); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 local lastlog2_data = lastlog2:get(username); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 if lastlog2_data then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 local current_data, err = store:get(username); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 if not current_data then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 if not err then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 current_data = {}; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 else |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 n_errors = n_errors + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 if current_data then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 local imported_timestamp = current_data.timestamp; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 local latest; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 for k, v in pairs(lastlog2_data) do |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 if k ~= "registered" and (not latest or v.timestamp > latest) then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 latest = v.timestamp; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 if latest and (not imported_timestamp or imported_timestamp < latest) then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 local ok, err = store:set_key(username, "timestamp", latest); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 if ok then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 n_updated = n_updated + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 else |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 self.session.print(("WW: Failed to import %q: %s"):format(username, err)); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 n_errors = n_errors + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 else |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 n_skipped = n_skipped + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 return resolve(("%d accounts imported, %d errors, %d skipped"):format(n_updated, n_errors, n_skipped)); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 end); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 async_runner:run(true); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 end); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 return p; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 }); |
