|
|
@@ -8,12 +8,14 @@ local threads = {} |
|
|
|
|
|
|
|
-- initial configuration |
|
|
|
local config = {} |
|
|
|
config.path = "/var/gopher" |
|
|
|
config.path = "/var/www/gopher" |
|
|
|
config.hostname = "shadowkat.net" |
|
|
|
config.port = 70 |
|
|
|
config.bindport = 7000 |
|
|
|
config.dirinfo = true |
|
|
|
config.timer = 0.1 |
|
|
|
config.cgi = true |
|
|
|
--config.cgipattern = ".*" -- todo |
|
|
|
|
|
|
|
-- load the config as a lua script |
|
|
|
if tArgs[1] then |
|
|
@@ -54,9 +56,10 @@ local function detectft(path) -- tries to detect the file type |
|
|
|
end |
|
|
|
if path:sub(-4) == ".png" or path:sub(-4) == ".jpg" or path:sub(-5) == ".jpeg" or path:sub(-4) == ".bmp" or path:sub(-4) == "gif" then |
|
|
|
return "I" |
|
|
|
end |
|
|
|
if path:sub(-5) == ".html" or path:sub(-4) == ".htm" then |
|
|
|
elseif path:sub(-5) == ".html" or path:sub(-4) == ".htm" then |
|
|
|
return "h" |
|
|
|
elseif path:sub(-10) == ".gopherdir" then |
|
|
|
return "1" |
|
|
|
end |
|
|
|
return "0" |
|
|
|
end |
|
|
@@ -73,7 +76,7 @@ local function handleConnect(client) |
|
|
|
local attr = fs.attributes(path) |
|
|
|
if attr then |
|
|
|
if attr.mode:sub(1,3) == "dir" then |
|
|
|
if lfs.attributes(path.."/.gopherdir.cgi") then |
|
|
|
if lfs.attributes(path.."/.gopherdir.cgi") and config.cgi then |
|
|
|
local f = io.popen(path.."/.gopherdir.cgi") |
|
|
|
coroutine.yield() |
|
|
|
client:send(f:read("*a")) |
|
|
@@ -93,7 +96,7 @@ local function handleConnect(client) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
if path:sub(-4) == ".cgi" then |
|
|
|
if path:sub(-4) == ".cgi" and config.cgi then |
|
|
|
local f = io.popen(path) |
|
|
|
coroutine.yield() |
|
|
|
client:send(f:read("*a")) |
|
|
|