Added max cache duration, reduced max paste size
This commit is contained in:
parent
32e4be15b0
commit
b46d823da3
3 changed files with 10 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
vrel 0.1.5:
|
vrel 0.1.5:
|
||||||
- Doubled the default maximum lifetime (3 months -> 6 months).
|
- Reduced max paste size (15MB -> 10MB).
|
||||||
|
- Doubled the default max lifetime (3 months -> 6 months).
|
||||||
- Added an optional configuration file.
|
- Added an optional configuration file.
|
||||||
- Added syntax setting per-paste.
|
- Added syntax setting per-paste.
|
||||||
- Sender IP storing should work with proxies.
|
- Sender IP storing should work with proxies.
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ return {
|
||||||
-- Default lifetime of a paste in the web interface
|
-- Default lifetime of a paste in the web interface
|
||||||
defaultLifetime = 86400, -- 1 day
|
defaultLifetime = 86400, -- 1 day
|
||||||
-- Maximal size of a request/paste
|
-- Maximal size of a request/paste
|
||||||
requestMaxDataSize = 15728640, -- 15MB
|
requestMaxDataSize = 10485760, -- 10MB
|
||||||
-- Pygments style name
|
-- Pygments style name
|
||||||
pygmentsStyle = "monokai",
|
pygmentsStyle = "monokai",
|
||||||
-- Extra CSS applied to syntax-highlighted blocks (with and without Pygments)
|
-- Extra CSS applied to syntax-highlighted blocks (with and without Pygments)
|
||||||
|
|
@ -25,6 +25,8 @@ return {
|
||||||
timeout = 1, -- 1 second
|
timeout = 1, -- 1 second
|
||||||
-- Debug mode
|
-- Debug mode
|
||||||
debug = false,
|
debug = false,
|
||||||
-- Time interval to remove expired webserver cache entries (seconds)
|
-- Cached pages lifetime
|
||||||
|
cacheDuration = 3600, -- 1 hour
|
||||||
|
-- Time interval to remove expired cache entries (seconds)
|
||||||
cacheCleanInterval = 3600 -- 1 hour
|
cacheCleanInterval = 3600 -- 1 hour
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
vrel.lua
8
vrel.lua
|
|
@ -4,7 +4,7 @@
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
local hasConfigFile, config = pcall(dofile, "config.lua") if not hasConfigFile then config = {} end
|
local hasConfigFile, config = pcall(dofile, "config.lua") if not hasConfigFile then config = {} end
|
||||||
-- Basic HTTP server --
|
-- Basic HTTP server --
|
||||||
local httpd, requestMaxDataSize = nil, config.requestMaxDataSize or 15728640 -- max post/paste data size (bytes) (15MB)
|
local httpd, requestMaxDataSize = nil, config.requestMaxDataSize or 10485760 -- max post/paste data size (bytes) (10MB)
|
||||||
httpd = {
|
httpd = {
|
||||||
log = function(str, ...) print("["..os.date().."] "..str:format(...)) end, -- log a message (str:format(...))
|
log = function(str, ...) print("["..os.date().."] "..str:format(...)) end, -- log a message (str:format(...))
|
||||||
peername = function(client) return ("%s:%s"):format(client:getpeername()) end, -- returns a nice display name for the client (address:port)
|
peername = function(client) return ("%s:%s"):format(client:getpeername()) end, -- returns a nice display name for the client (address:port)
|
||||||
|
|
@ -221,7 +221,7 @@ end
|
||||||
httpd.start(config.address or "*", config.port or 8155, { -- Pages
|
httpd.start(config.address or "*", config.port or 8155, { -- Pages
|
||||||
["/([^/]*)"] = function(request, name)
|
["/([^/]*)"] = function(request, name)
|
||||||
if forbiddenName[name] then return end
|
if forbiddenName[name] then return end
|
||||||
if #name == 0 then return { cache = 3600, "200 OK", {["Content-Type"] = "text/html"}, [[<!DOCTYPE html><html><head><meta charset=utf-8><title>vrel</title><style>
|
if #name == 0 then return { cache = config.cacheDuration or 3600, "200 OK", {["Content-Type"] = "text/html"}, [[<!DOCTYPE html><html><head><meta charset=utf-8><title>vrel</title><style>
|
||||||
* { padding: 0em; margin: 0em; color: #F8F8F2; background-color: #000000; font-size: 0.95em; font-family: mono, sans; border-style: none; }
|
* { padding: 0em; margin: 0em; color: #F8F8F2; background-color: #000000; font-size: 0.95em; font-family: mono, sans; border-style: none; }
|
||||||
form * { background-color: #272822; }
|
form * { background-color: #272822; }
|
||||||
textarea[name=data] { resize: none; position: fixed; width: 100%; height: calc(100% - 2.75em); /* 2.75em = textsize + 2*margin topbar */ }
|
textarea[name=data] { resize: none; position: fixed; width: 100%; height: calc(100% - 2.75em); /* 2.75em = textsize + 2*margin topbar */ }
|
||||||
|
|
@ -238,11 +238,11 @@ httpd.start(config.address or "*", config.port or 8155, { -- Pages
|
||||||
<textarea name=data required autofocus placeholder="paste your text here"></textarea>
|
<textarea name=data required autofocus placeholder="paste your text here"></textarea>
|
||||||
</form></body></html>]] }
|
</form></body></html>]] }
|
||||||
else local paste = get(name:match("^[^.]+"), request) or { data = "paste not found", syntax = "text", expire = os.time() }
|
else local paste = get(name:match("^[^.]+"), request) or { data = "paste not found", syntax = "text", expire = os.time() }
|
||||||
return { cache = not paste.burnOnRead and paste.expire - os.time(), "200 OK", {["Content-Type"] = "text/html"},
|
return { cache = not paste.burnOnRead and math.min(paste.expire - os.time(), config.cacheDuration or 3600), "200 OK", {["Content-Type"] = "text/html"},
|
||||||
([[<!DOCTYPE html><html><head><meta charset=utf-8><title>%s - vrel</title><style>%s</style></head><body>%s</body></html>]]):format(name, highlight(paste, name:lower():match("%.([a-z]+)$"))) }
|
([[<!DOCTYPE html><html><head><meta charset=utf-8><title>%s - vrel</title><style>%s</style></head><body>%s</body></html>]]):format(name, highlight(paste, name:lower():match("%.([a-z]+)$"))) }
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
["/g/(.+)"] = function(request, name) local d = get(name, request) return d and { cache = d.expire - os.time(), "200 OK", {["Content-Type"] = "text; charset=utf-8"}, d.data } or nil end,
|
["/g/(.+)"] = function(request, name) local d = get(name, request) return d and { cache = math.min(d.expire - os.time(), config.cacheDuration or 3600), "200 OK", {["Content-Type"] = "text; charset=utf-8"}, d.data } or nil end,
|
||||||
["/p"] = function(request)
|
["/p"] = function(request)
|
||||||
if request.method == "POST" and request.post.data then
|
if request.method == "POST" and request.post.data then
|
||||||
local name, paste = post({ lifetime = (tonumber(request.post.lifetime) or defaultLifetime)*(request.post.web and 1 or 1), burnOnRead = request.post.burnOnRead == "on",
|
local name, paste = post({ lifetime = (tonumber(request.post.lifetime) or defaultLifetime)*(request.post.web and 1 or 1), burnOnRead = request.post.burnOnRead == "on",
|
||||||
|
|
|
||||||
Reference in a new issue