-- directory=mg.request_info.uri -- Listing is generated via ls -l lsfd = io.popen("/bin/ls -lthL " .. mg.document_root .. directory) if lsfd.read then -- skip 'total' line lsfd:read() listing = "" -- For each line for line in lsfd:lines() do -- Get array of words from line words = {} for word in string.gmatch(line, "([^%s]+)") do words[#words + 1] = word end filename = words[9] if filename ~= "index.lua" then size = words[5] date = words[6] time = words[7] .. ' ' .. words[8] listing = listing .. "" end end lsfd:close() listing = listing .. "" listing = listing .. "
FilenameDate modifiedSize
" .. filename .. "" .. date .. " " .. time .. "" .. size .. "
Parent directory--
" else listing = "error" end -- Send the results mg.write("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n") mg.write([[ Contents of ]] .. directory .. [[

Contents of ]] .. directory .. [[

]] .. listing .. [[