Software / code / prosody
Annotate
plugins/mod_account_activity.lua @ 13801:a5d5fefb8b68 13.0
mod_tls: Enable Prosody's certificate checking for incoming s2s connections (fixes #1916) (thanks Damian, Zash)
Various options in Prosody allow control over the behaviour of the certificate
verification process For example, some deployments choose to allow falling
back to traditional "dialback" authentication (XEP-0220), while others verify
via DANE, hard-coded fingerprints, or other custom plugins.
Implementing this flexibility requires us to override OpenSSL's default
certificate verification, to allow Prosody to verify the certificate itself,
apply custom policies and make decisions based on the outcome.
To enable our custom logic, we have to suppress OpenSSL's default behaviour of
aborting the connection with a TLS alert message. With LuaSec, this can be
achieved by using the verifyext "lsec_continue" flag.
We also need to use the lsec_ignore_purpose flag, because XMPP s2s uses server
certificates as "client" certificates (for mutual TLS verification in outgoing
s2s connections).
Commit 99d2100d2918 moved these settings out of the defaults and into mod_s2s,
because we only really need these changes for s2s, and they should be opt-in,
rather than automatically applied to all TLS services we offer.
That commit was incomplete, because it only added the flags for incoming
direct TLS connections. StartTLS connections are handled by mod_tls, which was
not applying the lsec_* flags. It previously worked because they were already
in the defaults.
This resulted in incoming s2s connections with "invalid" certificates being
aborted early by OpenSSL, even if settings such as `s2s_secure_auth = false`
or DANE were present in the config.
Outgoing s2s connections inherit verify "none" from the defaults, which means
OpenSSL will receive the cert but will not terminate the connection when it is
deemed invalid. This means we don't need lsec_continue there, and we also
don't need lsec_ignore_purpose (because the remote peer is a "server").
Wondering why we can't just use verify "none" for incoming s2s? It's because
in that mode, OpenSSL won't request a certificate from the peer for incoming
connections. Setting verify "peer" is how you ask OpenSSL to request a
certificate from the client, but also what triggers its built-in verification.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 01 Apr 2025 17:26:56 +0100 |
| parent | 13682:0055c177a54c |
| 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 |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
72 local created_at = um.get_account_info(username, host).created; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
73 if created_at and (now - created_at) > duration_sec then |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
74 self.session.print(username, ""); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
75 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
|
76 elseif not created_at then |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
77 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
|
78 end |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 end |
|
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 |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
85 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
|
86 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
|
87 end |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
88 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
|
89 end; |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
90 }); |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
91 |
|
6be7de547a25
mod_account_activity: Add shell command to list inactive accounts
Matthew Wild <mwild1@gmail.com>
parents:
13667
diff
changeset
|
92 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
|
93 section = "migrate"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 section_desc = "Perform data migrations"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 name = "account_activity_lastlog2"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 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
|
97 args = { { name = "host"; type = "string" } }; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 host_selector = "host"; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 |
|
13667
3052eae50c98
mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents:
13665
diff
changeset
|
103 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
|
104 |
|
13667
3052eae50c98
mod_account_activity: Fix required module names
Matthew Wild <mwild1@gmail.com>
parents:
13665
diff
changeset
|
105 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
|
106 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
|
107 local n = 0; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 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
|
109 n = n + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 if n % 100 == 0 then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 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
|
112 async.sleep(0); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 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
|
115 if lastlog2_data then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 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
|
117 if not current_data then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 if not err then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 current_data = {}; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 else |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 n_errors = n_errors + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 if current_data then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 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
|
126 local latest; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 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
|
128 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
|
129 latest = v.timestamp; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 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
|
133 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
|
134 if ok then |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 n_updated = n_updated + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 else |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 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
|
138 n_errors = n_errors + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 else |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 n_skipped = n_skipped + 1; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 end |
|
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 end |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 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
|
147 end); |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 async_runner:run(true); |
|
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 return p; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 end; |
|
30a91d819913
mod_account_activity: Record an account's last activity timestamp
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 }); |