Author: yoann
Date: 2009-04-03 16:45:16 +0200 (Fri, 03 Apr 2009)
New Revision: 11111
Modified:
prelude-correlator/trunk/plugins/lua/lib.lua
prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua
Log:
Replace dshield split() function implementation with a generic string.split()
implementation defined in lib.lua. Additionally, this version will provide
much better performance.
Modified: prelude-correlator/trunk/plugins/lua/lib.lua
===================================================================
--- prelude-correlator/trunk/plugins/lua/lib.lua 2009-04-03 14:45:11 UTC (rev 11110)
+++ prelude-correlator/trunk/plugins/lua/lib.lua 2009-04-03 14:45:16 UTC (rev 11111)
@@ -139,3 +139,24 @@
return false
end
+
+
+function string.split(str, pattern)
+ local ret = {}
+ local start = 1
+ local plen = string.len(pattern)
+
+ while true do
+ local pos = string.find(str, pattern, start, true)
+ if not pos then
+ break
+ end
+
+ table.insert(ret, string.sub(str, start, pos - 1))
+ start = pos + plen
+ end
+
+ table.insert(ret, string.sub(str, start))
+ return ret
+end
+
Modified: prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua
===================================================================
--- prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua 2009-04-03 14:45:11 UTC (rev 11110)
+++ prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua 2009-04-03 14:45:16 UTC (rev 11111)
@@ -32,30 +32,6 @@
-function split(str, patt)
- vals = {}; valindex = 0; word = ""
- -- need to add a trailing separator to catch the last value.
- str = str .. patt
- for i = 1, string.len(str) do
-
- cha = string.sub(str, i, i)
- if cha ~= patt then
- word = word .. cha
- else
- if word ~= nil then
- vals[valindex] = word
- valindex = valindex + 1
- word = ""
- else
- -- in case we get a line with no data.
- break
- end
- end
-
- end
- return vals
-end
-
function make_zeroed_str(quad)
if tonumber(quad) < 100 and tonumber(quad) >= 10 then
return "0" .. quad
@@ -68,7 +44,7 @@
end
function normalize_ip(ipaddr)
- quads = split(ipaddr,".")
+ quads = string.split(ipaddr,".")
q1 = make_zeroed_str(quads[0])
q2 = make_zeroed_str(quads[1])
@@ -88,7 +64,7 @@
for i, source in ipairs(result[1]) do
normalized_ip = normalize_ip(source)
for line in io.lines() do
- val = split(line, "\t")
+ val = string.split(line, "\t")
if not string.find(val[0],"^#.*") then
if string.find(val[0], normalized_ip) then
local ctx = Context.update("DSHIELD_DB_" .. source, { threshold = 1 })
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.