aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_auth_results.lua
Commit message (Expand)AuthorAgeFilesLines
* [Fix] Fix ARC signing after fixing another bug in it...Vsevolod Stakhov2019-05-131-1/+4
* [Minor] Pet luacheckVsevolod Stakhov2019-03-071-2/+0
* [Minor] Improve authentication results outputVsevolod Stakhov2019-03-071-9/+28
* [Project] Rework DKIM AR to support RFC6008Vsevolod Stakhov2018-12-011-16/+40
* [Minor] Fix misprintVsevolod Stakhov2018-12-011-1/+1
* [Feature] Improve SPF results in Authentication-ResultsVsevolod Stakhov2018-11-301-6/+43
* [Minor] Delete unusedVsevolod Stakhov2018-09-251-3/+0
* [Fix] Prefer 'MTA-Name' when producing authentication resultsVsevolod Stakhov2018-07-171-1/+2
* [Fix] Fix AuthservIdAndrey Igoshin2018-05-021-2/+4
* [Minor] Fix syntax errorVsevolod Stakhov2018-04-171-1/+1
* [Minor] Simplify auth=pass generation of AR/AAR headerbjoe2k42018-04-161-17/+8
* [Minor] Cache hostname valueVsevolod Stakhov2018-04-161-3/+4
* [Minor] Improve AuthservID generation in AR-headerbjoe2k42018-03-301-4/+4
* [Refactor] Rename all lua libraries in the common wayVsevolod Stakhov2018-02-231-0/+203
.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
--[[
Copyright (c) 2017, Vsevolod Stakhov <vsevolod@highsecure.ru>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]--

local rspamd_logger = require "rspamd_logger"
local torch
local exports = {}

local lua_nn_models = {}

local conf_section = rspamd_config:get_all_opt("nn_models")

if conf_section then
  if rspamd_config:has_torch() then
    torch = require "torch"
    torch.setnumthreads(1)
  end
end

if torch then
  exports.load_rspamd_nn = function()
    local function gen_process_callback(name)
      return function(str)
        if str then
          local f = torch.MemoryFile(torch.CharStorage():string(str))
          local ret, tnn_or_err = pcall(function() f:readObject() end)
          if not ret then
            rspamd_logger.errx(rspamd_config, "cannot load neural net model %s: %s",
              name, tnn_or_err)
          else
            rspamd_logger.infox(rspamd_config, "loaded NN model %s: %s bytes",
              name, #str)
            lua_nn_models[name] = tnn_or_err
          end
        end
      end
    end

    if conf_section and type(conf_section) == 'table' then
      for k,v in pairs(conf_section) do
        if not rspamd_config:add_map(v, "nn map " .. k, gen_process_callback(k)) then
          rspamd_logger.warnx(rspamd_config, 'cannot load NN map %1', k)
        end
      end
    end
  end
  exports.try_rspamd_nn = function(name, input)
    if not lua_nn_models.name then
      return false, 0.0
    else
      local ret, res_or_err = pcall(function() lua_nn_models.name:forward(input) end)
      if not ret then
        rspamd_logger.errx(rspamd_config, "cannot run neural net model %s: %s",
          name, res_or_err)
      else
        return true, tonumber(res_or_err)
      end
    end

    return false, 0.0
  end
else
  exports.load_rspamd_nn = function()
  end
  exports.try_rspamd_nn = function(name, input)
    return false,0.0
  end
end

return exports