lua-resty-digitalelement

Query DigitalElement database files

lua-resty-digitalelement

Lua library for querying IPv4 addresses against DigitalElement NetAcuity databases which have been exported to a JSON file.

Installation

    opm get revcontent/lua-resty-digitalelement

Running

    # nginx.conf
    
    init_worker_by_lua_block {
    
      de = require("digitalelement")
      _, err = de.init({
        geo = { file = "/usr/local/digitalelement/geo.json" },
        vpn = { file = "/usr/local/digitalelement/vpn.json" }
      })
    
      if err then
        for k, v in pairs(err) do
          ngx.log(ngx.ERR, "Failed to load DigitalElement " .. k .. " database: " .. v)
        end
      end
    
    }


    local res, err = de.lookup("geo", ngx.var.remote_addr)
    if err then
      ngx.log(ngx.ERR, "IP Geo Lookup Failed: " .. err)
    else
      ngx.say(res["country"])
      ngx.say(res["region"])
      ngx.say(res["city"])
      -- ... additional database keys
    end
    
    local res, err = de.lookup("vpn", ngx.var.remote_addr)
    if err then
      ngx.log(ngx.ERR,"IP VPN Lookup Failed: " .. err)
    else
      ngx.say(res["vpn-proxy-type"])
      ngx.say(res["vpn-proxy-description"])
      ngx.say(res["vpn-proxy-names"])
      -- ... additional database keys
    end
    

Exporting DigitalElement Files

You'll need to have downloaded your databases to your local pc and install the netacuity-textfile-creator.sh utility. After doing that run the command below to generate the output file which can be imported by this package.

    ./netacuity-textfile-creator.sh --db_path=/path/to/db --db=1 --no_compress --output_format=json --output_file=./output.json

Creating Custom IP Range Files

If you want to utilize your own data to profile user IP addresses, create a file with each line being a single JSON string. The required key/value pairs are start-ip and end-ip.

    {"start-ip":"192.168.0.0","end-ip":"192.168.0.255","name":"My Home Network"}
    {"start-ip":"10.0.0.0","end-ip":"10.0.255.255","name":"My Work Network","contact":"user@domain"}
    {"start-ip":"74.2.11.3","end-ip":"74.2.11.3","name":"School","note":"Each range can have unique keys."}

Future Updates

  • Faster importing of data

  • Support CSV & compressed files

  • Better tries optimization, currently only the fourth octet is optimized. =back

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 89:

=over without closing =back

Authors

Richard Onyon (cebollia)

License

2bsd

Dependencies

Versions