r11121 - in prelude-correlator/trunk/plugins/lua: . ruleset

[email protected]
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
Author: yoann
Date: 2009-04-06 16:23:31 +0200 (Mon, 06 Apr 2009)
New Revision: 11121

Modified:
   prelude-correlator/trunk/plugins/lua/lua.c
   prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua
Log:
Add logging from Lua ruleset. Define info(), warn(), and error() logging function,
available from Lua, using prelude_log().

Modified: prelude-correlator/trunk/plugins/lua/lua.c
===================================================================
--- prelude-correlator/trunk/plugins/lua/lua.c	2009-04-06 11:42:12 UTC (rev 11120)
+++ prelude-correlator/trunk/plugins/lua/lua.c	2009-04-06 14:23:31 UTC (rev 11121)
@@ -200,7 +200,32 @@
 }
 
 
+static int l_generic(lua_State *lstate, int level)
+{
+        if ( ! lua_isstring(lstate, 1) )
+                return -1;
 
+        prelude_log(level, "%s\n", lua_tostring(lstate, 1));
+
+        return 0;
+}
+
+static int l_info(lua_State *lstate)
+{
+        return l_generic(lstate, PRELUDE_LOG_INFO);
+}
+
+static int l_warning(lua_State *lstate)
+{
+        return l_generic(lstate, PRELUDE_LOG_WARN);
+}
+
+static int l_error(lua_State *lstate)
+{
+        return l_generic(lstate, PRELUDE_LOG_ERR);
+}
+
+
 static int lua_activate(prelude_option_t *opt, const char *optarg, prelude_string_t *err, void *context)
 {
         int ret;
@@ -235,6 +260,15 @@
 
         prelude_plugin_instance_set_plugin_data(context, new);
 
+        lua_pushcfunction(new->lstate, l_info);
+        lua_setglobal(new->lstate, "info");
+
+        lua_pushcfunction(new->lstate, l_warning);
+        lua_setglobal(new->lstate, "warn");
+
+        lua_pushcfunction(new->lstate, l_error);
+        lua_setglobal(new->lstate, "error");
+
         lua_pushstring(new->lstate, PRELUDE_CORRELATOR_LIB_DIR);
         lua_setglobal(new->lstate, "PRELUDE_CORRELATOR_LIB_DIR");
 

Modified: prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua
===================================================================
--- prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua	2009-04-06 11:42:12 UTC (rev 11120)
+++ prelude-correlator/trunk/plugins/lua/ruleset/dshield.lua	2009-04-06 14:23:31 UTC (rev 11121)
@@ -20,7 +20,6 @@
 -- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 --
 
-
 local DSHIELD_RELOAD = 7 * 24 * 60 * 60
 local DSHIELD_URL = "http://www.dshield.org/ipsascii.html?limit=10000"
 
@@ -54,9 +53,9 @@
                 return load_dshield_data(fname, attr)
         end
 
-        print("Downloading host list from dshield, this might take some time...")
+        info("Downloading host list from dshield, this might take some time...")
         body = http.request(DSHIELD_URL)
-        print("Downloading done, processing data.")
+        info("Downloading done, processing data.")
 
         fd = io.output(fname)
         fd:write(body)

_______________________________________________
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.