-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoutput_http_searches.lua
71 lines (51 loc) · 1.9 KB
/
output_http_searches.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--
-- Log searches performed over HTTP.
-- Copyright (C) 2013-2014 Guy Martin <[email protected]>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--
output_http_searches = pom.output.new("http_searches", "Log searches performed by users on HTTP web sites", {
{ "log_file", "string", "http_searches.log", "Log filename" },
{ "match", "string", "[&?]q=([^&]*)", "Lua pattern to match" }
})
function output_http_searches:process_request(evt)
local data = evt.data
local url = data["url"]
if not url then
return
end
local match = string.match(url, self.match)
if not match then
return
end
local server = data["server_name"]
local client = data["client_addr"]
self.logfile:write("Client " .. client .. " searched for \"" .. match .. "\" on " .. server .. "\n")
self.logfile:flush()
end
function output_http_searches:open()
-- Open the log file
self.logfile = io.open(self:param_get("log_file"), "a")
-- Listen to HTTP request event
self:event_listen_start("http_request", nil, self.process_request)
-- Copy the match parameter for faster execution
self.match = self:param_get("match")
end
function output_http_searches:close()
if self.logfile then
self.logfile:close()
end
self:event_listen_stop("http_request")
end