diff options
author | Kim Alvefur <zash@zash.se> | 2021-01-27 17:29:26 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-01-27 17:29:26 +0100 |
commit | 9a74f504941160fe4da5a2830426fc5c403627ad (patch) | |
tree | 09b0d8c1da8f5c0c5dd8fad025997c7127318c1b | |
parent | 0d5bd3974d4801e962ec6fe63a5db280fc8e2668 (diff) | |
download | prosody-9a74f504941160fe4da5a2830426fc5c403627ad.tar.gz prosody-9a74f504941160fe4da5a2830426fc5c403627ad.zip |
mod_http_file_share: Add some logging
-rw-r--r-- | plugins/mod_http_file_share.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua index ad6a633c..e6f050a9 100644 --- a/plugins/mod_http_file_share.lua +++ b/plugins/mod_http_file_share.lua @@ -15,6 +15,8 @@ local dm = require "core.storagemanager".olddm; local jwt = require "util.jwt"; local errors = require "util.error"; local dataform = require "util.dataforms".new; +local dt = require "util.datetime"; +local hi = require "util.human.units"; local namespace = "urn:xmpp:http:upload:0"; @@ -52,6 +54,9 @@ local upload_errors = errors.init(module.name, namespace, { }; }); +-- Convenience wrapper for logging file sizes +local function B(bytes) return hi.format(bytes, "B", "b"); end + function may_upload(uploader, filename, filesize, filetype) -- > boolean, error local uploader_host = jid.host(uploader); if not ((access:empty() and prosody.hosts[uploader_host]) or access:contains(uploader) or access:contains(uploader_host)) then @@ -118,6 +123,7 @@ function handle_slot_request(event) return true; end + module:log("info", "Issuing upload slot to %s for %s", uploader, B(filesize)); local slot, storage_err = errors.coerce(uploads:append(nil, nil, request, os.time(), uploader)) if not slot then origin.send(st.error_reply(stanza, storage_err)); @@ -143,22 +149,27 @@ function handle_upload(event, path) -- PUT /upload/:slot local request = event.request; local authz = request.headers.authorization; if not authz or not authz:find"^Bearer ." then + module:log("debug", "Missing Authorization"); return 403; end local authed, upload_info = jwt.verify(secret, authz:match("^Bearer (.*)")); if not (authed and type(upload_info) == "table" and type(upload_info.exp) == "number") then + module:log("debug", "Unauthorized or invalid token: %s, %q", authed, upload_info); return 401; end if upload_info.exp < os.time() then + module:log("debug", "Authorization token expired on %s", dt.datetime(upload_info.exp)); return 410; end if not path or upload_info.slot ~= path:match("^[^/]+") then + module:log("debug", "Invalid upload slot: %q, path: %q", upload_info.slot, path); return 400; end local filename = dm.getpath(upload_info.slot, module.host, module.name, nil, true); if not request.body_sink then + module:log("debug", "Preparing to receive upload into %q, expecting %s", filename, B(upload_info.filesize)); local fh, err = errors.coerce(io.open(filename.."~", "w")); if not fh then return err; @@ -170,6 +181,8 @@ function handle_upload(event, path) -- PUT /upload/:slot end if request.body then + module:log("debug", "Complete upload available, %s", B(#request.body)); + -- Small enough to have been uploaded already local written, err = errors.coerce(request.body_sink:write(request.body)); if not written then return err; @@ -185,6 +198,7 @@ function handle_upload(event, path) -- PUT /upload/:slot uploaded, err = false, 413; end if uploaded then + module:log("debug", "Upload of %q completed, %s", filename, B(final_size)); assert(os.rename(filename.."~", filename)); return 201; else |