Browse Source

Added logging option

master
Sebastian 1 year ago
parent
commit
cc965fd5c2
Signed by: Sebastian Huebner <sebastian@hueb-ner.de> GPG Key ID: AFA10CBFE4391C0C
2 changed files with 17 additions and 1 deletions
  1. 3
    0
      config.cfg.lua
  2. 14
    1
      wmia.lua

+ 3
- 0
config.cfg.lua View File

@@ -12,4 +12,7 @@ config.html_root = './html/'
-- the domain, which is shown on the html page (default: localhost)
config.domain = 'wmi.kokolor.es'

-- enable logging (default: false)
config.logging = true

return config

+ 14
- 1
wmia.lua View File

@@ -22,7 +22,8 @@ local function loadconfig(cfg)
host = 'localhost',
port = 9090,
html_root = './html/',
domain = 'localhost'
domain = 'localhost',
logging = false
}
end
@@ -185,6 +186,18 @@ local function wmia_handler(_, stream)
local req_path = req_headers:get(':path'):lower() -- get path from, beginning from the last /
local ip

if CONFIG.logging then
-- date method path httpversion useragent
local log_format = '[%s] "%s %s HTTP/%g" "%s"\n'
io.stdout:write(log_format:format(
os.date("%d/%b/%Y:%H:%M:%S %z"),
req_method or '-',
req_path or '-',
stream.connection.version,
req_headers:get('user-agent') or '-'
))
end

-- only GET and HEAD is allowed, response to others with status 403
if req_method == 'GET' or req_method == 'HEAD' then
ip = get_req_ip(select(2, stream:peername()), req_headers)

Loading…
Cancel
Save