Basic finish

pull/63/head
ibuler 2016-09-29 11:10:15 +08:00
parent 8d08639a5c
commit 83c826247e
5 changed files with 360 additions and 67 deletions

View File

@ -4,6 +4,8 @@
<list default="true" id="2eef964a-b574-48e0-859a-c282c4760328" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/config.lua" afterPath="$PROJECT_DIR$/config.lua" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/core.lua" afterPath="$PROJECT_DIR$/core.lua" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/test.lua" afterPath="$PROJECT_DIR$/test.lua" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/test2.lua" afterPath="$PROJECT_DIR$/test2.lua" />
</list>
<ignored path="ngx_lua_waf.iws" />
<ignored path=".idea/workspace.xml" />
@ -27,9 +29,29 @@
<leaf>
<file leaf-file-name="core.lua" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/core.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="95">
<caret line="82" column="7" selection-start-line="82" selection-start-column="7" selection-end-line="82" selection-end-column="7" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="test.lua" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="16">
<caret line="20" column="0" selection-start-line="20" selection-start-column="0" selection-end-line="20" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="test2.lua" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test2.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="209">
<caret line="104" column="6" selection-start-line="104" selection-start-column="6" selection-end-line="104" selection-end-column="6" />
<caret line="13" column="14" selection-start-line="13" selection-start-column="14" selection-end-line="13" selection-end-column="14" />
<folding />
</state>
</provider>
@ -38,8 +60,8 @@
<file leaf-file-name="config.lua" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/config.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="22" column="8" selection-start-line="22" selection-start-column="8" selection-end-line="22" selection-end-column="8" />
<state relative-caret-position="361">
<caret line="19" column="11" selection-start-line="19" selection-start-column="11" selection-end-line="19" selection-end-column="11" />
<folding />
</state>
</provider>
@ -75,6 +97,8 @@
<list>
<option value="$PROJECT_DIR$/init.lua" />
<option value="$PROJECT_DIR$/config.lua" />
<option value="$PROJECT_DIR$/test.lua" />
<option value="$PROJECT_DIR$/test2.lua" />
<option value="$PROJECT_DIR$/core.lua" />
</list>
</option>
@ -86,8 +110,8 @@
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="49" />
<option name="y" value="23" />
<option name="x" value="8" />
<option name="y" value="24" />
<option name="width" value="1260" />
<option name="height" value="709" />
</component>
@ -144,9 +168,248 @@
<property name="last_opened_file_path" value="$PROJECT_DIR$/../lua-resty-waf" />
<property name="WebServerToolWindowFactoryState" value="false" />
</component>
<component name="RunManager" selected="Lua Script.test2.lua">
<configuration default="false" name="test2.lua" type="#com.sylvanaar.idea.Lua.run.LuaConfigurationType" factoryName="Lua Script" temporary="true">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="INTERPRETER_PATH" value="/usr/local/bin/luajit" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PARENT_ENVS" value="true" />
<option name="ALTERNATE_INTERPRETER" value="true" />
<envs />
<module name="ngx_lua_waf" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test2.lua" />
<option name="PARAMETERS" value="" />
<method />
</configuration>
<configuration default="true" type="#com.sylvanaar.idea.Lua.run.LuaConfigurationType" factoryName="Lua Script">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="INTERPRETER_PATH" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="ALTERNATE_INTERPRETER" value="false" />
<envs />
<module name="ngx_lua_waf" />
<option name="SCRIPT_NAME" value="" />
<option name="PARAMETERS" value="" />
<method />
</configuration>
<configuration default="true" type="DjangoTestsConfigurationType" factoryName="Django tests">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="TARGET" value="" />
<option name="SETTINGS_FILE" value="" />
<option name="CUSTOM_SETTINGS" value="false" />
<option name="USE_OPTIONS" value="false" />
<option name="OPTIONS" value="" />
<method />
</configuration>
<configuration default="true" type="JavascriptDebugType" factoryName="JavaScript Debug">
<method />
</configuration>
<configuration default="true" type="PyBehaveRunConfigurationType" factoryName="Behave">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="ADDITIONAL_ARGS" value="" />
<method />
</configuration>
<configuration default="true" type="PyLettuceRunConfigurationType" factoryName="Lettuce">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="ADDITIONAL_ARGS" value="" />
<method />
</configuration>
<configuration default="true" type="PythonConfigurationType" factoryName="Python">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<method />
</configuration>
<configuration default="true" type="Tox" factoryName="Tox">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<module name="ngx_lua_waf" />
<method />
</configuration>
<configuration default="true" type="js.build_tools.gulp" factoryName="Gulp.js">
<method />
</configuration>
<configuration default="true" type="js.build_tools.npm" factoryName="npm">
<command value="run-script" />
<scripts />
<node-interpreter value="project" />
<envs />
<method />
</configuration>
<configuration default="true" type="tests" factoryName="Attests">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="" />
<option name="CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="FOLDER_NAME" value="" />
<option name="TEST_TYPE" value="TEST_SCRIPT" />
<option name="PATTERN" value="" />
<option name="USE_PATTERN" value="false" />
<method />
</configuration>
<configuration default="true" type="tests" factoryName="Doctests">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="" />
<option name="CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="FOLDER_NAME" value="" />
<option name="TEST_TYPE" value="TEST_SCRIPT" />
<option name="PATTERN" value="" />
<option name="USE_PATTERN" value="false" />
<method />
</configuration>
<configuration default="true" type="tests" factoryName="Nosetests">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="" />
<option name="CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="FOLDER_NAME" value="" />
<option name="TEST_TYPE" value="TEST_SCRIPT" />
<option name="PATTERN" value="" />
<option name="USE_PATTERN" value="false" />
<option name="PARAMS" value="" />
<option name="USE_PARAM" value="false" />
<method />
</configuration>
<configuration default="true" type="tests" factoryName="Unittests">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="" />
<option name="CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="FOLDER_NAME" value="" />
<option name="TEST_TYPE" value="TEST_SCRIPT" />
<option name="PATTERN" value="" />
<option name="USE_PATTERN" value="false" />
<option name="PUREUNITTEST" value="true" />
<option name="PARAMS" value="" />
<option name="USE_PARAM" value="false" />
<method />
</configuration>
<configuration default="true" type="tests" factoryName="py.test">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="ngx_lua_waf" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="" />
<option name="CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="FOLDER_NAME" value="" />
<option name="TEST_TYPE" value="TEST_SCRIPT" />
<option name="PATTERN" value="" />
<option name="USE_PATTERN" value="false" />
<option name="testToRun" value="" />
<option name="keywords" value="" />
<option name="params" value="" />
<option name="USE_PARAM" value="false" />
<option name="USE_KEYWORD" value="false" />
<method />
</configuration>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="Lua Script.test2.lua" />
</list>
<recent_temporary>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="Lua Script.test2.lua" />
</list>
</recent_temporary>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="2eef964a-b574-48e0-859a-c282c4760328" name="Default" comment="" />
@ -158,7 +421,7 @@
<servers />
</component>
<component name="ToolWindowManager">
<frame x="49" y="23" width="1260" height="709" extended-state="0" />
<frame x="8" y="24" width="1260" height="709" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24958949" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
@ -168,20 +431,28 @@
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.06482982" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="Vcs.Log.UiProperties">
<option name="RECENTLY_FILTERED_USER_GROUPS">
<collection />
</option>
<option name="RECENTLY_FILTERED_BRANCH_GROUPS">
<collection />
</option>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
@ -232,16 +503,32 @@
</entry>
<entry file="file://$PROJECT_DIR$/config.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="22" column="8" selection-start-line="22" selection-start-column="8" selection-end-line="22" selection-end-column="8" />
<state relative-caret-position="361">
<caret line="19" column="11" selection-start-line="19" selection-start-column="11" selection-end-line="19" selection-end-column="11" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test2.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="209">
<caret line="13" column="14" selection-start-line="13" selection-start-column="14" selection-end-line="13" selection-end-column="14" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="16">
<caret line="20" column="0" selection-start-line="20" selection-start-column="0" selection-end-line="20" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/core.lua">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="209">
<caret line="104" column="6" selection-start-line="104" selection-start-column="6" selection-end-line="104" selection-end-column="6" />
<state relative-caret-position="95">
<caret line="82" column="7" selection-start-line="82" selection-start-column="7" selection-end-line="82" selection-end-column="7" />
<folding />
</state>
</provider>

View File

@ -18,9 +18,9 @@ _M.defaults = {
cc_deny_seconds = 600,
cc_deny_code = 404,
log_path = "/tmp/nginx_waf.log",
ip_white_list = {},
ip_black_list = {},
ip_black_code = 403,
white_ip_list = {},
black_ip_list = {},
black_return_code = 403,
}
return _M

View File

@ -14,6 +14,7 @@ local get_headers = ngx.req.get_headers
local config = require "config"
local iputils = require "iputils"
local mt = {__index=_M }
local limit = ngx.shared.limit
local function get_client_ip()
local ip = get_headers()["X-Real-IP"]
@ -42,6 +43,7 @@ end
function _M.new(self, name)
local t = {}
name = name or ""
t["name"] = name
t["config"] = _M.table_copy(config.defaults)
return setmetatable(t, mt)
@ -58,7 +60,6 @@ function _M.deny_cc(self)
local ip = get_client_ip()
local token = ip..":"..uri
local limit = ngx.shared.limit
local req, _ = limit:get(token)
if req then
@ -71,11 +72,9 @@ function _M.deny_cc(self)
end
elseif req == max_visit then
if self.config.active then
self:log("[Deny_cc] Block " .. token)
ngx.exit(self.config.cc_deny_code)
else
self:log("[Deny_cc] FakeBlock " .. token)
end
self:log("[Deny_cc] Block "..token)
limit:incr(token, 1)
return true
else
@ -87,27 +86,34 @@ function _M.deny_cc(self)
end
function _M.log(self, msg)
ngx.log(ngx.WARN, self.config.log_path)
if log_inited[self.config.log_path] == nil then
log_inited[self.config.log_path] = io.open(self.config.log_path, 'ab')
log_inited[self.config.log_path] = io.open(self.config.log_path, 'a')
end
self.fd = log_inited[self.config.log_path]
self.fd:write(msg .. '\n')
if self.config.active then
self.fd:write(ngx.localtime().." [ACTIVE] ".."["..self.name.."] "..msg..'\n')
else
self.fd:write(ngx.localtime().." [MONITOR] ".."["..self.name.."] "..msg..'\n')
end
self.fd:flush()
end
function _M.in_white_ip_list(self)
local ip = get_client_ip()
local is_white_token = ip.."white"
local is_white, _ = limit:get(is_white_token)
local white_ip_token = ip.."white"
local is_white, _ = limit:get(white_ip_token)
if is_white then
return true
end
local white_ip_list = self.config.white_ip_list
if next(white_ip_list) ~= nil then
local white_ip_list = self.config.white_ip_list
for _, wip in paris(white_ip_list) do
for _, wip in pairs(white_ip_list) do
if ip == wip or iputils.ip_in_cidrs(ip, wip) then
limit:set(white_ip_token, true, 3600)
self:log("[White_ip] In white list passed: "..ip)
return true
end
end
@ -116,20 +122,26 @@ function _M.in_white_ip_list(self)
end
function _M.in_black_ip_list(self)
local limit = ngx.shared.limit
local ip = get_client_ip()
local is_block_token = ip.."block"
local is_block, _ = limit:get(is_block_token)
local block_ip_token = ip.."block"
local is_block, _ = limit:get(block_ip_token)
if is_block then
ngx.exit(self.config.ip_black_code)
if self.config.active then
ngx.exit(self.config.black_return_code)
end
return true
end
if next(white_ip_list) ~= nil then
local black_ip_list = self.config.white_ip_list
for _, bip in paris(black_ip_list) do
local black_ip_list = self.config.black_ip_list
if next(black_ip_list) ~= nil then
for _, bip in pairs(black_ip_list) do
if ip == bip or iputils.ip_in_cidrs(ip, bip) then
limit:set(is_block_token, true, 3600)
ngx.exit(self.config.ip_black_code)
limit:set(block_ip_token, true, 3600)
self:log("[Black_ip] In black list denied: "..ip)
if self.config.active then
ngx.exit(self.config.black_return_code)
end
return true
end
end
@ -139,7 +151,6 @@ function _M.in_black_ip_list(self)
end
function _M.run(self)
ngx.log(ngx.WARN, 'Start running waf')
if self:in_black_ip_list() then
elseif self:in_white_ip_list() then
elseif self.config.cc_deny and self:deny_cc() then

View File

@ -9,7 +9,6 @@
local _M = {}
_M.version = '0.1.1'
local util = require "resty.waf.util"
local mt = {__index=_M}
@ -19,23 +18,20 @@ end
local config = {'hello', 'world' }
local _a = {}
function _M:new()
return setmetatable({}, mt)
function _M.new(self, name)
name = name or 0
return setmetatable({name=name}, mt)
end
function _M:name()
local name = {'guang', 'hong', 'wei' }
name_new = util.table_copy(name)
print(table.concat(name_new, ','))
function _M.get_name(self)
print(self.name)
end
function _M.get_version()
local name = _M.name()
print(name)
end
--function _M.get_version()
-- local name = _M.name()
-- print(name)
--end
return _a
return _M

View File

@ -7,25 +7,24 @@
--
local lua_waf = require "core"
local iputils = require "iputils"
--local lua_waf = require "core"
local lua_waf = require "test"
local waf = lua_waf:new("test")
local waf2 = lua_waf:new("jj")
for k, v in pairs(waf["config"]) do
print(k, v)
end
waf:set_option("active", true)
for k, v in pairs(waf["config"]) do
print(k, v)
end
print(waf.config.active)
print(waf.name)
--for k, v in pairs(waf["config"]) do
-- print(k, v)
--end
--
--waf:set_option("active", true)
--
--for k, v in pairs(waf["config"]) do
-- pritt(k, v)
--end
--print(waf.config.active)
--
-- waf:deny_cc()
-- waf2:deny_cc()
waf:log("hello world")
waf2:log("world")
print(iputils.ip2bin("192.168.1.1"))
--waf:log("hello world")
--waf2:log("world")
--waf:get_name()