mirror of
https://git.shadowkat.net/izaya/tiny-gopherd.git
synced 2024-10-08 15:33:43 -04:00
Compare commits
2 Commits
022699f899
...
6b058c1efa
Author | SHA1 | Date | |
---|---|---|---|
|
6b058c1efa | ||
|
d79488d48a |
@ -6,5 +6,6 @@ config.port = 70 -- the external port of the server
|
|||||||
config.bindport = 7000 -- the port to actually bind to
|
config.bindport = 7000 -- the port to actually bind to
|
||||||
config.dirinfo = true -- whether to output some extra info in automatic directory indexes
|
config.dirinfo = true -- whether to output some extra info in automatic directory indexes
|
||||||
config.timer = 0.1 -- main loop timer
|
config.timer = 0.1 -- main loop timer
|
||||||
|
config.cgi = true -- whether to enable server-side scripts
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
13
gopherd.lua
13
gopherd.lua
@ -8,12 +8,14 @@ local threads = {}
|
|||||||
|
|
||||||
-- initial configuration
|
-- initial configuration
|
||||||
local config = {}
|
local config = {}
|
||||||
config.path = "/var/gopher"
|
config.path = "/var/www/gopher"
|
||||||
config.hostname = "shadowkat.net"
|
config.hostname = "shadowkat.net"
|
||||||
config.port = 70
|
config.port = 70
|
||||||
config.bindport = 7000
|
config.bindport = 7000
|
||||||
config.dirinfo = true
|
config.dirinfo = true
|
||||||
config.timer = 0.1
|
config.timer = 0.1
|
||||||
|
config.cgi = true
|
||||||
|
--config.cgipattern = ".*" -- todo
|
||||||
|
|
||||||
-- load the config as a lua script
|
-- load the config as a lua script
|
||||||
if tArgs[1] then
|
if tArgs[1] then
|
||||||
@ -54,9 +56,10 @@ local function detectft(path) -- tries to detect the file type
|
|||||||
end
|
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
|
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"
|
return "I"
|
||||||
end
|
elseif path:sub(-5) == ".html" or path:sub(-4) == ".htm" then
|
||||||
if path:sub(-5) == ".html" or path:sub(-4) == ".htm" then
|
|
||||||
return "h"
|
return "h"
|
||||||
|
elseif path:sub(-10) == ".gopherdir" then
|
||||||
|
return "1"
|
||||||
end
|
end
|
||||||
return "0"
|
return "0"
|
||||||
end
|
end
|
||||||
@ -73,7 +76,7 @@ local function handleConnect(client)
|
|||||||
local attr = fs.attributes(path)
|
local attr = fs.attributes(path)
|
||||||
if attr then
|
if attr then
|
||||||
if attr.mode:sub(1,3) == "dir" 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")
|
local f = io.popen(path.."/.gopherdir.cgi")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
client:send(f:read("*a"))
|
client:send(f:read("*a"))
|
||||||
@ -93,7 +96,7 @@ local function handleConnect(client)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if path:sub(-4) == ".cgi" then
|
if path:sub(-4) == ".cgi" and config.cgi then
|
||||||
local f = io.popen(path)
|
local f = io.popen(path)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
client:send(f:read("*a"))
|
client:send(f:read("*a"))
|
||||||
|
14
install/tiny-gopherd.service
Normal file
14
install/tiny-gopherd.service
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Tiny gopher daemon
|
||||||
|
After=network.target
|
||||||
|
StartLimitIntervalSec=0
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
RestartSec=1
|
||||||
|
User=www-data
|
||||||
|
ExecStart=/usr/bin/env lua /var/www//gopherd.lua /etc/tiny-gopherd.cfg
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user