local date = FastCGI.env.PATH_INFO
local index = {}
local nfiles = 0
local pipe = io.popen("ls /var/www/isparp.co.uk/public/angband/irclogs/")
if pipe then
for line in pipe:lines() do
if string.find(line, "^%d%d%d%d%-%d%d%-%d%d$") then
index[nfiles + 1] = line
index[line] = nfiles + 1
nfiles = nfiles + 1
end
end
end
local status = 404
if date == "/today" then
status = 302
page = os.date("!%Y-%m-%d")
elseif date == "/latest" or date == "/" then
status = 302
page = index[nfiles]
elseif string.find(date, "^/%d%d%d%d%-%d%d%-%d%d$") then
status = 200
page = string.sub(date, 2)
end
header("Status", status)
if status == 404 then
>>
IRC logs: #angband-dev / Not found
404 Not found
<<
elseif status == 302 then
header("Location", page)
>>
IRC logs: #angband-dev / Redirecting
302 Redirecting to <@page@>
<<
else
>>
IRC logs: #angband-dev / <@page@>
<<
divert()
local prevpage = index[index[page] - 1]
local nextpage = index[index[page] + 1]
vdprint("")
local lognav = undivert()
local file = io.open("/var/www/isparp.co.uk/public/angband/irclogs/"..page, "r")
if not file then
vdprint("Doesn't exist.
")
else
>>
<<
vdprint(lognav)
vdprint("")
begin_streaming()
for line in file:lines() do
local c = string.sub(line, 7, 7)
local class
if c == "<" then
class = "speech"
elseif c == "*" then
class = "action"
elseif c == "-" then
-- class = "misc"
if string.find(line, "has quit") then
class = "quit"
elseif string.find(line, "has left") then
class = "leave"
elseif string.find(line, "has joined") then
class = "join"
elseif string.find(line, "[Tt]opic") then
class = "topic"
end
end
if class then
line = escapeEntities(line)
vdprint("- ", line, "
\n")
end
end
file:close()
vdprint("
")
vdprint(lognav)
end
end
>>
<<