Software /
code /
prosody-modules
Comparison
mod_admin_web/admin_web/mod_admin_web.lua @ 309:5ec9125575fc
mod_admin_web: Handle paths without trailing slash
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Thu, 06 Jan 2011 23:41:45 +0100 |
parent | 304:8f3499ae1e27 |
child | 317:4f78f5020aa9 |
comparison
equal
deleted
inserted
replaced
308:f406e300d709 | 309:5ec9125575fc |
---|---|
28 local http_base = (prosody.paths.plugins or "./plugins/") .. "admin_web/www_files"; | 28 local http_base = (prosody.paths.plugins or "./plugins/") .. "admin_web/www_files"; |
29 | 29 |
30 local xmlns_c2s_session = "http://prosody.im/streams/c2s"; | 30 local xmlns_c2s_session = "http://prosody.im/streams/c2s"; |
31 local xmlns_s2s_session = "http://prosody.im/streams/s2s"; | 31 local xmlns_s2s_session = "http://prosody.im/streams/s2s"; |
32 | 32 |
33 local response_301 = { status = "301 Moved Permanently" }; | |
33 local response_400 = { status = "400 Bad Request", body = "<h1>Bad Request</h1>Sorry, we didn't understand your request :(" }; | 34 local response_400 = { status = "400 Bad Request", body = "<h1>Bad Request</h1>Sorry, we didn't understand your request :(" }; |
34 local response_403 = { status = "403 Forbidden", body = "<h1>Forbidden</h1>You don't have permission to view the contents of this directory :(" }; | 35 local response_403 = { status = "403 Forbidden", body = "<h1>Forbidden</h1>You don't have permission to view the contents of this directory :(" }; |
35 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" }; | 36 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" }; |
36 | 37 |
37 local mime_map = { | 38 local mime_map = { |
114 end | 115 end |
115 end | 116 end |
116 return path; | 117 return path; |
117 end | 118 end |
118 | 119 |
119 function serve_file(path) | 120 function serve_file(path, base) |
120 local full_path = http_base..path; | 121 local full_path = http_base..path; |
121 if stat(full_path, "mode") == "directory" then | 122 if stat(full_path, "mode") == "directory" then |
123 if not path:find("/$") then | |
124 local response = response_301; | |
125 response.headers = { ["Location"] = base .. "/" }; | |
126 return response; | |
127 end | |
122 if stat(full_path.."/index.html", "mode") == "file" then | 128 if stat(full_path.."/index.html", "mode") == "file" then |
123 return serve_file(path.."/index.html"); | 129 return serve_file(path.."/index.html"); |
124 end | 130 end |
125 return response_403; | 131 return response_403; |
126 end | 132 end |
141 end | 147 end |
142 | 148 |
143 local function handle_file_request(method, body, request) | 149 local function handle_file_request(method, body, request) |
144 local path = preprocess_path(request.url.path); | 150 local path = preprocess_path(request.url.path); |
145 if not path then return response_400; end | 151 if not path then return response_400; end |
146 path = path:gsub("^/[^/]+", ""); -- Strip /admin/ | 152 path_stripped = path:gsub("^/[^/]+", ""); -- Strip /admin/ |
147 return serve_file(path); | 153 return serve_file(path_stripped, path); |
148 end | 154 end |
149 | 155 |
150 function module.load() | 156 function module.load() |
151 local http_conf = config.get("*", "core", "webadmin_http_ports"); | 157 local http_conf = config.get("*", "core", "webadmin_http_ports"); |
152 | 158 |