Git Product home page Git Product logo

Comments (9)

b1v1r avatar b1v1r commented on September 24, 2024

In what context do you get this error? I assume you are trying to build a lua rule or lua module? Perhaps you can post an example of what you are trying to do.

from ironbee.

fajrirahmat avatar fajrirahmat commented on September 24, 2024

I'm sorry. i have done some mistake. I am trying to build lua rule.

I got another error: "attempt to call method 'logInfo' (a nil value)".

example of whai i am trying to do:

local ib = ...
if ib == nil then
return 0
end

ib:logInfo("Testing")
return 0

from ironbee.

b1v1r avatar b1v1r commented on September 24, 2024

Instead of lua rules, I suggest using lua modules. It is very likely that lua rules will be deprecated in favor of modules. This is primarily since writing lua modules has become so easy and is much more flexible and performant than lua rules.

You can use the clipp utility to test this with raw HTTP request.http and response.http files (this is with latest master ironbee):

clipp raw:request.http,response.http ironbee:ironbee-lua.conf

ironbee-lua.conf:

### Logging
LogLevel info

### Load Modules
LoadModule "ibmod_htp.so"
LoadModule "ibmod_lua.so"
LuaLoadModule "test.lua"

### Auditing
AuditEngine RelevantOnly
AuditLogIndex auditlog-index.log
AuditLogBaseDir /tmp/ironbee
AuditLogSubDirFormat "%Y%m%d-%H%M"
AuditLogDirMode 0755
AuditLogFileMode 0644
AuditLogParts all

### Buffering
RequestBuffering On
ResponseBuffering On

### Rule Diagnostics Logging
RuleEngineLogData event audit
RuleEngineLogLevel info
#Set RuleEngineDebugLogLevel Trace

### Sites
<Site default>
    SiteId 95AB11F0-B195-480C-AF0B-752E98AEB20E
    Service *:*
    Hostname *

</Site>

test.lua:

-- ========================================================
-- Lua test module.
--
-- This code is executed on load (LuaLoadModule directive).
-- ========================================================

-- Get an IronBee module handle, passed in as an argument.
local ibmod = ...
if ibmod == nil then
    -- Return failure (non-zero).
    return 1
end

ibmod:logInfo("Loading module: test.lua")

-- Callback to process the request header.
local process_request_header = function(tx)
    tx:logInfo("Processing request header.")

    -- Iterate and log out defined fields.
    for _,name in ipairs(tx:getFieldList()) do
        tx:logInfo("FIELD: %s", name)
        local f = tx:get(name)
        if type(f) == "table" then
            for _,rec in ipairs(f) do
                local k,v = unpack(rec)
                tx:logInfo("%s:%s[%s] = %s", name, k, type(v), tostring(v))
            end
        else
            tx:logInfo("%s[%s] = %s", name, type(f), tostring(f))
        end
    end

    -- Return success (zero).
    return 0
end

-- Register callbacks with events.
ibmod:request_header_finished_event(process_request_header)

ibmod:logInfo("Finished loading module: test.lua")

-- Return success (zero).
return 0

from ironbee.

fajrirahmat avatar fajrirahmat commented on September 24, 2024

I did it, but when I tried using rex_pcre,, error loading module 'rex_pcre' from file '/usr/local/lib/lua/5.1/rex_pcre.so' appears.

test.lua


local ibmod = ...
local rex = require 'rex_pcre'
if ibmod == nil then
    return 1
end
ibmod:logInfo("Loading module : test.lua -- Fajri Rahmat")
local process_request_header = function(tx)
    tx:logInfo("Processing request header")
    for _,name in ipairs(tx:getFieldList()) do
        tx:logInfo("FIELD : %s", name)
        local f = tx:get(name)
        if type(f) == "table" then
            for _,rec in ipairs(f) do
                local k,v = unpack(f)
                tx:logInfo("%s:%s[%s] = %s -- Fajri Rahmat",name,k,type(v), tostring(v))
            end
        else
            tx:logInfo("%s[%s] = %s",name,type(f),tostring(f))
        end
    end
    return 0
end
ibmod:request_header_finished_event(process_request_header)
ibmod:logInfo("Finished loading module : test.lua")
return 0

from ironbee.

b1v1r avatar b1v1r commented on September 24, 2024

What is the full error you are getting? If it is not finding the rex_pcre, then perhaps you need to append to the package.cpath?

package.cpath = package.cpath .. ";/usr/local/share/luarocks/lib/lua/5.1/?.so"
local rex = require 'rex_pcre'

from ironbee.

fajrirahmat avatar fajrirahmat commented on September 24, 2024

Error as following :

ironbee: 02022014.09h08m51s ERROR     -  Error loading module /usr/local/ironbee/etc/ironbee/test.lua: error loading module 'rex_pcre' from file '/usr/local/lib/lua/5.1/rex_pcre.so':\n\t/usr/local/lib/lua/5.1/rex_pcre.so: undefined symbol: lua_checkstack

this error only appear when I try to use 'rex_pcre' at lua module.

from ironbee.

b1v1r avatar b1v1r commented on September 24, 2024

I have a fix in latest master (1599825). Can you try this version?

from ironbee.

fajrirahmat avatar fajrirahmat commented on September 24, 2024

oke ,, thank's. it works...

from ironbee.

b1v1r avatar b1v1r commented on September 24, 2024

Excellent. Thanks for testing.

from ironbee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.