annotate mod_file_management/mod_file_management.lua @ 6261:1c62edeb9147

mod_pastebin: Update Readme diff --git a/mod_pastebin/README.md b/mod_pastebin/README.md --- a/mod_pastebin/README.md +++ b/mod_pastebin/README.md @@ -37,12 +37,14 @@ For example: Pastes will be available by default at `http://<your-prosody>:5280/pastebin/` by default. -In Prosody 0.9 and later this can be changed with [HTTP -settings](https://prosody.im/doc/http). +Ports and path can be changed with [HTTP +settings](https://prosody.im/doc/http), for example like: -In 0.8 and older this can be changed with `pastebin_ports` (see below), -or you can forward another external URL from your web server to Prosody, -use `pastebin_url` to set that URL. +``` {.lua} + http_paths = { + pastebin = "/$host-paste"; + } +``` # Discovery @@ -82,27 +84,16 @@ The line and character tresholds are adv pastebin_line_threshold The maximum number of lines a message may have before it is sent to the pastebin. (default 4 lines) pastebin_trigger A string of characters (e.g. "!paste ") which if detected at the start of a message, always sends the message to the pastebin, regardless of length. (default: not set) pastebin_expire_after Number of hours after which to expire (remove) a paste, defaults to 24. Set to 0 to store pastes permanently on disk. - pastebin_ports List of ports to run the HTTP server on, same format as mod_httpserver's http_ports[^1] - pastebin_url Base URL to display for pastebin links, must end with / and redirect to Prosody's built-in HTTP server[^2] # Compatibility - ------ ------- - trunk Works + ------ --------------------- + trunk Works as of 25-06-13 + 13 Works 0.12 Works - 0.11 Works - 0.10 Works - 0.9 Works - 0.8 Works - ------ ------- + ------ --------------------- # Todo - Maximum paste length - Web interface to submit pastes? - -[^1]: As of Prosody 0.9, `pastebin_ports` is replaced by `http_ports`, - see [Prosody HTTP server documentation](https://prosody.im/doc/http) - -[^2]: See also - [http_external_url](https://prosody.im/doc/http#external_url)
author Menel <menel@snikket.de>
date Fri, 13 Jun 2025 11:39:58 +0200
parents d43623bdf91b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3663
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 -- mod_file_management
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 --
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 -- Copyright (C) 2019 Emmanuel Gil Peyrot
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 --
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 -- This file is MIT/X11 licensed.
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 --
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 module:depends("http_upload");
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 local dataform_new = require "util.dataforms".new;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 local adhoc_new = module:require "adhoc".new;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 local adhoc_simple_form = require "util.adhoc".new_simple_form;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 local adhoc_initial_data_form = require "util.adhoc".new_initial_data_form;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 local url = require "socket.url";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 local lfs = require "lfs";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 local datamanager = require "util.datamanager";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 local jid_prepped_split = require "util.jid".prepped_split;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 local join_path = require "util.paths".join;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 local t_concat = table.concat;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 local t_insert = table.insert;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 local storage_path = module:get_option_string("http_upload_path", join_path(prosody.paths.data, "http_upload"));
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 local function get_url(dir, filename)
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 local slot_url = url.parse(module:http_url("upload"));
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 slot_url.path = url.parse_path(slot_url.path or "/");
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 t_insert(slot_url.path, dir);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 t_insert(slot_url.path, filename);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 slot_url.path.is_directory = false;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 slot_url.path = url.build_path(slot_url.path);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 return url.build(slot_url);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 local list_form = dataform_new {
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 title = "List files for user";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 instructions = "Select the JID of a user to list the files they have uploaded.";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 {
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 type = "hidden";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 name = "FORM_TYPE";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 value = "http://prosody.im/protocol/file_management#list";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 {
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 type = "jid-single";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 name = "accountjid";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 required = true;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 label = "JID";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 module:provides("adhoc", adhoc_new("File Management", "http://prosody.im/protocol/file_management#list", adhoc_simple_form(list_form, function (data, errors)
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 if errors then
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 local errmsg = {};
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 for name, text in pairs(errors) do
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 errmsg[#errmsg + 1] = name .. ": " .. text;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 local jid = data.accountjid;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 local user, host = jid_prepped_split(jid);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 local uploads, err = datamanager.list_load(user, host, "http_upload");
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 if err then
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 return { status = "completed", error = "File upload data not found for user "..jid.."." };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 local result = {};
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 for i, upload in ipairs(uploads) do
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 module:log("debug", "http_upload_management#list %d %q", i, upload);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 if upload.dir ~= nil then
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 t_insert(result, get_url(upload.dir, upload.filename));
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 else
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 -- upload.filename was pointing to a path on the file system…
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 -- TODO: Try to guess the URL from that.
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 return { status = "completed", info = t_concat(result, "\n") };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 end), "admin"));