Comparison

mod_http_upload/mod_http_upload.lua @ 2689:0fc706855af9

mod_http_upload: Keep user- and hostname in locals
author Kim Alvefur <zash@zash.se>
date Sat, 15 Apr 2017 15:52:54 +0200
parent 2688:ef80c9d0ebff
child 2690:43ad92c5b91a
comparison
equal deleted inserted replaced
2688:ef80c9d0ebff 2689:0fc706855af9
105 end 105 end
106 return sum < quota; 106 return sum < quota;
107 end 107 end
108 108
109 local function handle_request(origin, stanza, xmlns, filename, filesize, mimetype) 109 local function handle_request(origin, stanza, xmlns, filename, filesize, mimetype)
110 local username, host = origin.username, origin.host;
110 -- local clients only 111 -- local clients only
111 if origin.type ~= "c2s" then 112 if origin.type ~= "c2s" then
112 module:log("debug", "Request for upload slot from a %s", origin.type); 113 module:log("debug", "Request for upload slot from a %s", origin.type);
113 origin.send(st.error_reply(stanza, "cancel", "not-authorized")); 114 origin.send(st.error_reply(stanza, "cancel", "not-authorized"));
114 return true; 115 return true;
117 if not filename or filename:find("/") then 118 if not filename or filename:find("/") then
118 module:log("debug", "Filename %q not allowed", filename or ""); 119 module:log("debug", "Filename %q not allowed", filename or "");
119 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid filename")); 120 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid filename"));
120 return true; 121 return true;
121 end 122 end
122 expire(origin.username, origin.host); 123 expire(username, host);
123 if not filesize then 124 if not filesize then
124 module:log("debug", "Missing file size"); 125 module:log("debug", "Missing file size");
125 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing or invalid file size")); 126 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing or invalid file size"));
126 return true; 127 return true;
127 elseif filesize > file_size_limit then 128 elseif filesize > file_size_limit then
128 module:log("debug", "File too large (%d > %d)", filesize, file_size_limit); 129 module:log("debug", "File too large (%d > %d)", filesize, file_size_limit);
129 origin.send(st.error_reply(stanza, "modify", "not-acceptable", "File too large") 130 origin.send(st.error_reply(stanza, "modify", "not-acceptable", "File too large")
130 :tag("file-too-large", {xmlns=xmlns}) 131 :tag("file-too-large", {xmlns=xmlns})
131 :tag("max-file-size"):text(tostring(file_size_limit))); 132 :tag("max-file-size"):text(tostring(file_size_limit)));
132 return true; 133 return true;
133 elseif not check_quota(origin.username, origin.host, filesize) then 134 elseif not check_quota(username, host, filesize) then
134 module:log("debug", "Upload of %dB by %s would exceed quota", filesize, origin.full_jid); 135 module:log("debug", "Upload of %dB by %s would exceed quota", filesize, origin.full_jid);
135 origin.send(st.error_reply(stanza, "wait", "resource-constraint", "Quota reached")); 136 origin.send(st.error_reply(stanza, "wait", "resource-constraint", "Quota reached"));
136 return true; 137 return true;
137 end 138 end
138 139
157 local random_dir; 158 local random_dir;
158 repeat random_dir = uuid(); 159 repeat random_dir = uuid();
159 until lfs.mkdir(join_path(storage_path, random_dir)) 160 until lfs.mkdir(join_path(storage_path, random_dir))
160 or not lfs.attributes(join_path(storage_path, random_dir, filename)) 161 or not lfs.attributes(join_path(storage_path, random_dir, filename))
161 162
162 datamanager.list_append(origin.username, origin.host, module.name, { 163 datamanager.list_append(username, host, module.name, {
163 filename = join_path(storage_path, random_dir, filename), size = filesize, time = os.time() }); 164 filename = join_path(storage_path, random_dir, filename), size = filesize, time = os.time() });
164 local slot = random_dir.."/"..filename; 165 local slot = random_dir.."/"..filename;
165 pending_slots[slot] = origin.full_jid; 166 pending_slots[slot] = origin.full_jid;
166 167
167 module:add_timer(900, function() 168 module:add_timer(900, function()