Comparison

plugins/mod_http_file_share.lua @ 11311:9edda2026e57

mod_http_file_share: Add basic access control Partly lifted from mod_external_services
author Kim Alvefur <zash@zash.se>
date Tue, 26 Jan 2021 14:39:11 +0100
parent 11310:d1a0f2e918c0
child 11312:aade4a6179a3
comparison
equal deleted inserted replaced
11310:d1a0f2e918c0 11311:9edda2026e57
26 -- id, <request>, time, owner 26 -- id, <request>, time, owner
27 27
28 local secret = module:get_option_string(module.name.."_secret", require"util.id".long()); 28 local secret = module:get_option_string(module.name.."_secret", require"util.id".long());
29 local external_base_url = module:get_option_string(module.name .. "_base_url"); 29 local external_base_url = module:get_option_string(module.name .. "_base_url");
30 30
31 local access = module:get_option_set(module.name .. "_access", {});
32
31 if not external_base_url then 33 if not external_base_url then
32 module:depends("http"); 34 module:depends("http");
33 end 35 end
34 36
35 function may_upload(uploader, filename, filesize, filetype) -- > boolean, error 37 function may_upload(uploader, filename, filesize, filetype) -- > boolean, error
36 -- TODO authz 38 local uploader_host = jid.host(uploader);
39 if not ((access:empty() and prosody.hosts[uploader_host]) or access:contains(uploader) or access:contains(uploader_host)) then
40 return false;
41 end
42
37 return true; 43 return true;
38 end 44 end
39 45
40 function get_authz(uploader, filename, filesize, filetype, slot) 46 function get_authz(uploader, filename, filesize, filetype, slot)
41 return "Bearer "..jwt.sign(secret, { 47 return "Bearer "..jwt.sign(secret, {