diff --git a/README.md b/README.md index 85867e0..abba2a3 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,6 @@ qq交流群 : 624214498,欢迎有兴趣的童鞋提交PR, 持续更新中 .... - [x] 支持熔断策略调整 - - [x] 支持配置数据持久 - [x] 支持动态节点扩展 @@ -76,6 +75,10 @@ qq交流群 : 624214498,欢迎有兴趣的童鞋提交PR, 持续更新中 .... - [x] 支持多级日志生成 +- [x] 支持插件二次开发 + +- [ ] 支持安装部署脚本 + - [x] 支持定制WAF策略 @@ -94,27 +97,19 @@ qq交流群 : 624214498,欢迎有兴趣的童鞋提交PR, 持续更新中 .... -- [ ] 支持配置灰度发布 - -- [ ] 支持权限身份控制 - -- [x] 支持插件二次开发 - -- [x] 支持版本迭代数据同步 - -- [ ] 支持集群部署数据同步 - -- [ ] 支持安装部署脚本 +- [x] 【插件】支持版本迭代数据同步 -- [ ] 支持多语言管理界面 +- [ ] 【插件】支持配置灰度发布 +- [ ] 【插件】支持权限身份控制 +- [ ] 【插件】支持集群部署数据同步 -- [ ] 支持健康检查日志分析 +- [ ] 【插件】支持健康检查日志分析 -- [ ] 支持熔断限流日志分析 +- [ ] 【插件】支持熔断限流日志分析 -- [ ] 支持路由负载日志分析 +- [ ] 【插件】支持路由负载日志分析 # 更新日志 diff --git a/api/router/tl_ops_api_get_balance.lua b/api/router/tl_ops_api_get_balance.lua index 1a1218e..a57581b 100644 --- a/api/router/tl_ops_api_get_balance.lua +++ b/api/router/tl_ops_api_get_balance.lua @@ -4,15 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -cjson.encode_empty_table_as_object(false) - -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance"); -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local snowflake = require("lib.snowflake") +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance") +local tl_ops_constant_balance = require("constant.tl_ops_constant_balance") +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt +local tl_ops_utils_func = require("utils.tl_ops_utils_func") +local cjson = require("cjson.safe"); +cjson.encode_empty_table_as_object(false) local Router = function() local code_str = cache:get(tl_ops_constant_balance.cache_key.options) diff --git a/api/router/tl_ops_api_get_balance_api.lua b/api/router/tl_ops_api_get_balance_api.lua index f69fc8e..a8f097b 100644 --- a/api/router/tl_ops_api_get_balance_api.lua +++ b/api/router/tl_ops_api_get_balance_api.lua @@ -4,15 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-api"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api") +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-api"); -local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - local Router = function() local rule, _ = cache:get(tl_ops_constant_balance_api.cache_key.rule); if not rule or rule == nil then diff --git a/api/router/tl_ops_api_get_balance_cookie.lua b/api/router/tl_ops_api_get_balance_cookie.lua index c9a6798..98d7c0c 100644 --- a/api/router/tl_ops_api_get_balance_cookie.lua +++ b/api/router/tl_ops_api_get_balance_cookie.lua @@ -4,15 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-cookie"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie") +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-cookie"); -local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - local Router = function() local rule, _ = cache:get(tl_ops_constant_balance_cookie.cache_key.rule); if not rule or rule == nil then diff --git a/api/router/tl_ops_api_get_balance_header.lua b/api/router/tl_ops_api_get_balance_header.lua index b959fa2..dc3ca2c 100644 --- a/api/router/tl_ops_api_get_balance_header.lua +++ b/api/router/tl_ops_api_get_balance_header.lua @@ -4,16 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-header"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header") +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-header"); -local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - - local Router = function() local rule, _ = cache:get(tl_ops_constant_balance_header.cache_key.rule); if not rule or rule == nil then diff --git a/api/router/tl_ops_api_get_balance_param.lua b/api/router/tl_ops_api_get_balance_param.lua index 591fedc..67d0477 100644 --- a/api/router/tl_ops_api_get_balance_param.lua +++ b/api/router/tl_ops_api_get_balance_param.lua @@ -4,15 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-param"); +local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param") +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-param"); -local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - local Router = function() local rule, _ = cache:get(tl_ops_constant_balance_param.cache_key.rule); if not rule or rule == nil then diff --git a/api/router/tl_ops_api_get_health.lua b/api/router/tl_ops_api_get_health.lua index b862817..a2d46ff 100644 --- a/api/router/tl_ops_api_get_health.lua +++ b/api/router/tl_ops_api_get_health.lua @@ -4,14 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-health"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local cache = require("cache.tl_ops_cache"):new("tl-ops-health"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - local Router = function() local list_str, _ = cache:get(tl_ops_constant_health.cache_key.options_list); diff --git a/api/router/tl_ops_api_get_limit.lua b/api/router/tl_ops_api_get_limit.lua index c48968f..a79edae 100644 --- a/api/router/tl_ops_api_get_limit.lua +++ b/api/router/tl_ops_api_get_limit.lua @@ -4,14 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -cjson.encode_empty_table_as_object(false) -local cache = require("cache.tl_ops_cache"):new("tl-ops-limit"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); +cjson.encode_empty_table_as_object(false) local Router = function() local fuse_list_str, _ = cache:get(tl_ops_constant_limit.fuse.cache_key.options_list); diff --git a/api/router/tl_ops_api_get_service.lua b/api/router/tl_ops_api_get_service.lua index 94874f8..5b60f18 100644 --- a/api/router/tl_ops_api_get_service.lua +++ b/api/router/tl_ops_api_get_service.lua @@ -5,13 +5,12 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-service"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local cache = require("cache.tl_ops_cache"):new("tl-ops-service"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - local Router = function() local rule, _ = cache:get(tl_ops_constant_service.cache_key.service_rule); diff --git a/api/router/tl_ops_api_get_state.lua b/api/router/tl_ops_api_get_state.lua index 1fb37a5..9bc2e23 100644 --- a/api/router/tl_ops_api_get_state.lua +++ b/api/router/tl_ops_api_get_state.lua @@ -4,31 +4,27 @@ -- @author iamtsm -- @email 1905333456@qq.com - -local cjson = require("cjson"); +local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); +local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); +local tl_ops_limit = require("limit.tl_ops_limit"); +local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); +local cache_limit = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); +local cache_health = require("cache.tl_ops_cache_core"):new("tl-ops-health"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local shared = ngx.shared.tlopsbalance +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); - -local tl_ops_limit = require("limit.tl_ops_limit"); - -local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); -local cache_limit = require("cache.tl_ops_cache"):new("tl-ops-limit"); -local cache_health = require("cache.tl_ops_cache"):new("tl-ops-health"); - -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local shared = ngx.shared.tlopsbalance local Router = function() --返回的cache state local cache_state = { - service = {}, health = {}, limit = {}, balance = {}, other = {} + service = {}, health = {}, limit = {}, balance = {}, waf = {}, other = {} } - -- 服务相关状态 local list_str, _ = cache_service:get(tl_ops_constant_service.cache_key.service_list); if not list_str or list_str == nil then @@ -63,12 +59,21 @@ local Router = function() limit_version_cache = 0 --"version cache nil" end + -- waf统计 + local waf_count_name_service = "tl-ops-waf-count-" .. tl_ops_constant_waf.count.interval; + local waf_cache_count_service = require("cache.tl_ops_cache_core"):new(waf_count_name_service); + local waf_success_cache_service = waf_cache_count_service:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.waf_interval_success, service_name, nil)) + if not waf_success_cache_service then + waf_success_cache_service = "{}" + end + cache_state.service[service_name] = { health_lock = health_lock_cache, health_version = health_version_cache, health_uncheck = health_uncheck_cache, limit_state = limit_state_cache, limit_version = limit_version_cache, + waf_success = waf_success_cache_service } cache_state.service[service_name].nodes = { } @@ -151,13 +156,20 @@ local Router = function() end end - local count_name = "tl-ops-balance-count-" .. tl_ops_constant_balance.count.interval; - local cache_balance_count = require("cache.tl_ops_cache"):new(count_name); - local balance_success_cache = cache_balance_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_balance.cache_key.balance_interval_success, node.service, node_id)) + local balance_count_name = "tl-ops-balance-count-" .. tl_ops_constant_balance.count.interval; + local balance_cache_count = require("cache.tl_ops_cache_core"):new(balance_count_name); + local balance_success_cache = balance_cache_count:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_balance.cache_key.balance_interval_success, node.service, node_id)) if not balance_success_cache then balance_success_cache = "{}" end + local waf_count_name_node = "tl-ops-waf-count-" .. tl_ops_constant_waf.count.interval; + local waf_cache_count_node = require("cache.tl_ops_cache_core"):new(waf_count_name_node); + local waf_success_cache_node = waf_cache_count_node:get001(tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.waf_interval_success, node.service, node_id)) + if not waf_success_cache_node then + waf_success_cache_node = "{}" + end + cache_state.service[service_name].nodes[node.name] = { health_state = health_node_state_cache, health_failed = health_node_failed_cache, @@ -171,6 +183,7 @@ local Router = function() limit_pre_time = limit_pre_time, limit_bucket = limit_bucket, balance_success = cjson.decode(balance_success_cache), + waf_success = cjson.decode(waf_success_cache_node), } end end @@ -189,7 +202,6 @@ local Router = function() health_timers_str = "{}" --"timers nil" end local health_timer_list = cjson.decode(health_timers_str) - cache_state.health['timer_list'] = health_timer_list cache_state.health['options_list'] = health_options_list @@ -207,36 +219,24 @@ local Router = function() limit_timers_str = "{}" --"timers nil" end local limit_timer_list = cjson.decode(limit_timers_str) - - -- local pre_time = shared:get(tl_ops_constant_limit.global_token.cache_key.pre_time) - -- if not pre_time then - -- pre_time = "nil" --"pre_time nil" - -- end - -- local token_bucket = shared:get(tl_ops_constant_limit.global_token.cache_key.token_bucket) - -- if not token_bucket then - -- token_bucket = "nil" --"token_bucket nil" - -- end - -- local warm = shared:get(tl_ops_constant_limit.global_token.cache_key.warm) - -- if not warm then - -- warm = "nil" --"warm nil" - -- end - -- local lock = shared:get(tl_ops_constant_limit.global_token.cache_key.lock) - -- if not lock then - -- lock = "nil" --"lock nil" - -- end - -- cache_state.limit['pre_time'] = pre_time - -- cache_state.limit['token_bucket'] = token_bucket - -- cache_state.limit['warm'] = warm - -- cache_state.limit['lock'] = lock cache_state.health['timer_list'] = limit_timer_list cache_state.limit['option_list'] = limit_options_list - -- 路由相关 cache_state.balance['count_interval'] = tl_ops_constant_balance.count.interval + -- waf相关 + local waf_count_name_global = "tl-ops-waf-count-" .. tl_ops_constant_waf.count.interval; + local waf_cache_count_global = require("cache.tl_ops_cache_core"):new(waf_count_name_global); + local waf_success_cache_global = waf_cache_count_global:get001(tl_ops_constant_waf.cache_key.waf_interval_success) + if not waf_success_cache_global then + waf_success_cache_global = "{}" + end + cache_state.waf['waf_success'] = cjson.decode(waf_success_cache_global) + + -- 其他 -- cache_state.other['dict_keys'] = shared:get_keys(1024) diff --git a/api/router/tl_ops_api_get_store.lua b/api/router/tl_ops_api_get_store.lua index 2aa4d1a..090a56d 100644 --- a/api/router/tl_ops_api_get_store.lua +++ b/api/router/tl_ops_api_get_store.lua @@ -4,17 +4,17 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_api_store"); +local tl_ops_manage_env = require("tl_ops_manage_env") +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_api_store"); -local tl_ops_env = require("tl_ops_manage_env") -- 读取文件 local read = function( filename ) - local store_file_name = tl_ops_env.log.store_dir .. filename + local store_file_name = tl_ops_manage_env.log.store_dir .. filename local store_file_io, _ = io.open(store_file_name, "r") if not store_file_io then tlog:err("failed to open file in read: " .. store_file_name) diff --git a/api/router/tl_ops_api_get_waf.lua b/api/router/tl_ops_api_get_waf.lua index 8e4e6c1..c1018e6 100644 --- a/api/router/tl_ops_api_get_waf.lua +++ b/api/router/tl_ops_api_get_waf.lua @@ -4,14 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf"); -local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf"); +local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); +cjson.encode_empty_table_as_object(false) local Router = function() diff --git a/api/router/tl_ops_api_get_waf_api.lua b/api/router/tl_ops_api_get_waf_api.lua index 81e84e0..88832a0 100644 --- a/api/router/tl_ops_api_get_waf_api.lua +++ b/api/router/tl_ops_api_get_waf_api.lua @@ -4,14 +4,15 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); + +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-api"); +local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-api"); -local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() local scope, _ = cache:get(tl_ops_constant_waf_api.cache_key.scope); diff --git a/api/router/tl_ops_api_get_waf_cc.lua b/api/router/tl_ops_api_get_waf_cc.lua index 248f4f6..7b4d97d 100644 --- a/api/router/tl_ops_api_get_waf_cc.lua +++ b/api/router/tl_ops_api_get_waf_cc.lua @@ -4,14 +4,15 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); + +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cc"); +local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-cc"); -local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() local scope, _ = cache:get(tl_ops_constant_waf_cc.cache_key.scope); diff --git a/api/router/tl_ops_api_get_waf_cookie.lua b/api/router/tl_ops_api_get_waf_cookie.lua index c76ff6a..bbf4d18 100644 --- a/api/router/tl_ops_api_get_waf_cookie.lua +++ b/api/router/tl_ops_api_get_waf_cookie.lua @@ -4,14 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cookie"); +local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-cookie"); -local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() local scope, _ = cache:get(tl_ops_constant_waf_cookie.cache_key.scope); diff --git a/api/router/tl_ops_api_get_waf_header.lua b/api/router/tl_ops_api_get_waf_header.lua index 396dd84..a8bcfd3 100644 --- a/api/router/tl_ops_api_get_waf_header.lua +++ b/api/router/tl_ops_api_get_waf_header.lua @@ -4,14 +4,15 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); + +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-header"); +local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-header"); -local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() local scope, _ = cache:get(tl_ops_constant_waf_header.cache_key.scope); diff --git a/api/router/tl_ops_api_get_waf_ip.lua b/api/router/tl_ops_api_get_waf_ip.lua index bb3e354..566e170 100644 --- a/api/router/tl_ops_api_get_waf_ip.lua +++ b/api/router/tl_ops_api_get_waf_ip.lua @@ -4,14 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-ip"); +local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-ip"); -local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() local scope, _ = cache:get(tl_ops_constant_waf_ip.cache_key.scope); diff --git a/api/router/tl_ops_api_get_waf_param.lua b/api/router/tl_ops_api_get_waf_param.lua index 1a4843f..ef2aeb3 100644 --- a/api/router/tl_ops_api_get_waf_param.lua +++ b/api/router/tl_ops_api_get_waf_param.lua @@ -4,14 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-param"); +local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-param"); -local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() local scope, _ = cache:get(tl_ops_constant_waf_param.cache_key.scope); diff --git a/api/router/tl_ops_api_set_balance.lua b/api/router/tl_ops_api_set_balance.lua index 133172c..2e19d5a 100644 --- a/api/router/tl_ops_api_set_balance.lua +++ b/api/router/tl_ops_api_set_balance.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance"); +local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance"); -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_balance_api.lua b/api/router/tl_ops_api_set_balance_api.lua index fe93e9a..ec0cc2e 100644 --- a/api/router/tl_ops_api_set_balance_api.lua +++ b/api/router/tl_ops_api_set_balance_api.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-api"); +local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-api"); -local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_balance_cookie.lua b/api/router/tl_ops_api_set_balance_cookie.lua index efe1add..cfac827 100644 --- a/api/router/tl_ops_api_set_balance_cookie.lua +++ b/api/router/tl_ops_api_set_balance_cookie.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-cookie"); +local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-cookie"); -local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_balance_header.lua b/api/router/tl_ops_api_set_balance_header.lua index 879d009..77cdc28 100644 --- a/api/router/tl_ops_api_set_balance_header.lua +++ b/api/router/tl_ops_api_set_balance_header.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-header"); +local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-header"); -local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_balance_param.lua b/api/router/tl_ops_api_set_balance_param.lua index 2f22b2b..e06fb0c 100644 --- a/api/router/tl_ops_api_set_balance_param.lua +++ b/api/router/tl_ops_api_set_balance_param.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-param"); +local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-balance-param"); -local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_health.lua b/api/router/tl_ops_api_set_health.lua index 01a50f4..e0d4b54 100644 --- a/api/router/tl_ops_api_set_health.lua +++ b/api/router/tl_ops_api_set_health.lua @@ -4,13 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-health"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_health_check_version = require("health.tl_ops_health_check_version") +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local cache = require("cache.tl_ops_cache"):new("tl-ops-health"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_health_check_version = require("health.tl_ops_health_check_version") local Router = function() diff --git a/api/router/tl_ops_api_set_limit.lua b/api/router/tl_ops_api_set_limit.lua index ca49b02..51659b6 100644 --- a/api/router/tl_ops_api_set_limit.lua +++ b/api/router/tl_ops_api_set_limit.lua @@ -4,14 +4,15 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); + +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); +local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local cache = require("cache.tl_ops_cache"):new("tl-ops-limit"); -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") local Router = function() -- fuse配置 diff --git a/api/router/tl_ops_api_set_service.lua b/api/router/tl_ops_api_set_service.lua index c97ff74..d833f99 100644 --- a/api/router/tl_ops_api_set_service.lua +++ b/api/router/tl_ops_api_set_service.lua @@ -5,16 +5,16 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); -local snowflake = require("lib.snowflake"); -local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health"); -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_health_check_version = require("health.tl_ops_health_check_version") -local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") +local cjson = require("cjson.safe"); +local snowflake = require("lib.snowflake"); +local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health"); +local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_health_check_version = require("health.tl_ops_health_check_version") +local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") local Router = function() @@ -100,7 +100,7 @@ local Router = function() -- 新增service逻辑分支 if has_new_service_name == true and new_service_name ~= '' then -- 同步健康检查配置 - local cache_health = require("cache.tl_ops_cache"):new("tl-ops-health"); + local cache_health = require("cache.tl_ops_cache_core"):new("tl-ops-health"); local health_list_str, _ = cache_health:get(tl_ops_constant_health.cache_key.options_list); if not health_list_str or health_list_str == nil then tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found health list", _); @@ -117,7 +117,7 @@ local Router = function() end -- 同步熔断配置 - local cache_limit = require("cache.tl_ops_cache"):new("tl-ops-limit"); + local cache_limit = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); local limit_list_str, _ = cache_limit:get(tl_ops_constant_limit.fuse.cache_key.options_list); if not limit_list_str or limit_list_str == nil then tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found limit fuse list", _); diff --git a/api/router/tl_ops_api_set_state.lua b/api/router/tl_ops_api_set_state.lua index 214bed4..fc5fcf4 100644 --- a/api/router/tl_ops_api_set_state.lua +++ b/api/router/tl_ops_api_set_state.lua @@ -5,17 +5,16 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local tl_ops_health_check_version = require("health.tl_ops_health_check_version") +local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_state"); +local shared = ngx.shared.tlopsbalance +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local tl_ops_health_check_version = require("health.tl_ops_health_check_version") -local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); - -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_state"); -local shared = ngx.shared.tlopsbalance local Router = function() local tl_ops_state_cmd, _ = tl_ops_utils_func:get_req_post_args_by_name("cmd", 1); diff --git a/api/router/tl_ops_api_set_waf.lua b/api/router/tl_ops_api_set_waf.lua index a499e76..dc9bc4e 100644 --- a/api/router/tl_ops_api_set_waf.lua +++ b/api/router/tl_ops_api_set_waf.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf"); +local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf"); -local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_waf_api.lua b/api/router/tl_ops_api_set_waf_api.lua index edac9b3..80a27f2 100644 --- a/api/router/tl_ops_api_set_waf_api.lua +++ b/api/router/tl_ops_api_set_waf_api.lua @@ -4,15 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com - -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-api"); +local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-api"); -local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - local Router = function() diff --git a/api/router/tl_ops_api_set_waf_cc.lua b/api/router/tl_ops_api_set_waf_cc.lua index fc52847..52d2669 100644 --- a/api/router/tl_ops_api_set_waf_cc.lua +++ b/api/router/tl_ops_api_set_waf_cc.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cc"); +local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-cc"); -local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_waf_cookie.lua b/api/router/tl_ops_api_set_waf_cookie.lua index 0c365bc..14949d0 100644 --- a/api/router/tl_ops_api_set_waf_cookie.lua +++ b/api/router/tl_ops_api_set_waf_cookie.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cookie"); +local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-cookie"); -local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_waf_header.lua b/api/router/tl_ops_api_set_waf_header.lua index 6915f93..05c0a69 100644 --- a/api/router/tl_ops_api_set_waf_header.lua +++ b/api/router/tl_ops_api_set_waf_header.lua @@ -4,15 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com - -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-header"); +local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-header"); -local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - local Router = function() diff --git a/api/router/tl_ops_api_set_waf_ip.lua b/api/router/tl_ops_api_set_waf_ip.lua index b58ef5f..6a73c92 100644 --- a/api/router/tl_ops_api_set_waf_ip.lua +++ b/api/router/tl_ops_api_set_waf_ip.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-ip"); +local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-ip"); -local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local Router = function() diff --git a/api/router/tl_ops_api_set_waf_param.lua b/api/router/tl_ops_api_set_waf_param.lua index 95596ab..4ecc613 100644 --- a/api/router/tl_ops_api_set_waf_param.lua +++ b/api/router/tl_ops_api_set_waf_param.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); -cjson.encode_empty_table_as_object(false) -local snowflake = require("lib.snowflake"); -local cache = require("cache.tl_ops_cache"):new("tl-ops-waf-param"); +local snowflake = require("lib.snowflake"); +local cache = require("cache.tl_ops_cache_core"):new("tl-ops-waf-param"); local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); +cjson.encode_empty_table_as_object(false) local Router = function() diff --git a/api/tl_ops_api.lua b/api/tl_ops_api.lua index b3429b6..5669cfa 100644 --- a/api/tl_ops_api.lua +++ b/api/tl_ops_api.lua @@ -4,21 +4,17 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_api_core = require("api.tl_ops_api_core"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_api_router"); +local tl_ops_api_core = require("api.tl_ops_api_core"); local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_api_router"); - local _M = {} function _M:init( ) local request_uri = tl_ops_utils_func:get_req_uri() - for uri ,router in pairs(tl_ops_api_core) do if ngx.re.find(request_uri, uri, 'jo') then - tlog:dbg("访问接口 : request_uri=",request_uri) - router() ngx.exit(200) end diff --git a/balance/count/tl_ops_balance_count.lua b/balance/count/tl_ops_balance_count.lua index 430ceb8..181222c 100644 --- a/balance/count/tl_ops_balance_count.lua +++ b/balance/count/tl_ops_balance_count.lua @@ -4,11 +4,10 @@ -- @author iamtsm -- @email 1905333456@qq.com - local tl_ops_balance_count_core = require("balance.count.tl_ops_balance_count_core"); -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local shared = ngx.shared.tlopsbalance; +local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local shared = ngx.shared.tlopsbalance; local _M = {} diff --git a/balance/count/tl_ops_balance_count_core.lua b/balance/count/tl_ops_balance_count_core.lua index 4b11167..293d38d 100644 --- a/balance/count/tl_ops_balance_count_core.lua +++ b/balance/count/tl_ops_balance_count_core.lua @@ -4,16 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_balance_count"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); -local tl_ops_manage_env = require("tl_ops_manage_env") - -local lock = require("lib.lock"); -local shared = ngx.shared.tlopsbalance; +local cjson = require("cjson.safe") +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_balance_count") +local tl_ops_utils_func = require("utils.tl_ops_utils_func") +local tl_ops_constant_balance = require("constant.tl_ops_constant_balance") +local tl_ops_constant_service = require("constant.tl_ops_constant_service") +local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service") +local tl_ops_manage_env = require("tl_ops_manage_env") +local shared = ngx.shared.tlopsbalance local _M = { @@ -46,7 +44,7 @@ local tl_ops_balance_count = function() -- 控制细度 ,以周期为分割,仅用store持久 local count_name = "tl-ops-balance-count-" .. tl_ops_constant_balance.count.interval; - local cache_balance_count = require("cache.tl_ops_cache"):new(count_name); + local cache_balance_count = require("cache.tl_ops_cache_core"):new(count_name); for service_name, nodes in pairs(service_list) do if nodes == nil then @@ -70,7 +68,7 @@ local tl_ops_balance_count = function() local cur_count = cur_succ_count + cur_fail_count if cur_count == 0 then - tlog:err("balance count async err , succ=",cur_succ_count,",fail=",cur_fail_count,",service_name=",service_name,",node_id=",node_id) + tlog:dbg("balance count not need sync , succ=",cur_succ_count,",fail=",cur_fail_count,",service_name=",service_name,",node_id=",node_id) else -- push to list local success_key = tl_ops_utils_func:gen_node_key(tl_ops_constant_balance.cache_key.balance_interval_success, service_name, node_id) diff --git a/balance/tl_ops_balance_core.lua b/balance/tl_ops_balance_core.lua index 91df950..b261bdf 100644 --- a/balance/tl_ops_balance_core.lua +++ b/balance/tl_ops_balance_core.lua @@ -5,30 +5,26 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); - -local tl_ops_balance_core_api = require("balance.tl_ops_balance_core_api"); -local tl_ops_balance_core_cookie = require("balance.tl_ops_balance_core_cookie"); -local tl_ops_balance_core_header = require("balance.tl_ops_balance_core_header"); -local tl_ops_balance_core_param = require("balance.tl_ops_balance_core_param"); - -local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); -local cache_balance = require("cache.tl_ops_cache"):new("tl-ops-balance"); - -local balance_count = require("balance.count.tl_ops_balance_count"); - -local tl_ops_limit_fuse_token_bucket = require("limit.fuse.tl_ops_limit_fuse_token_bucket"); +local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); +local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); +local tl_ops_balance_core_api = require("balance.tl_ops_balance_core_api"); +local tl_ops_balance_core_cookie = require("balance.tl_ops_balance_core_cookie"); +local tl_ops_balance_core_header = require("balance.tl_ops_balance_core_header"); +local tl_ops_balance_core_param = require("balance.tl_ops_balance_core_param"); +local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); +local cache_balance = require("cache.tl_ops_cache_core"):new("tl-ops-balance"); +local balance_count = require("balance.count.tl_ops_balance_count"); +local waf = require("waf.tl_ops_waf") +local tl_ops_limit_fuse_token_bucket= require("limit.fuse.tl_ops_limit_fuse_token_bucket"); local tl_ops_limit_fuse_leak_bucket = require("limit.fuse.tl_ops_limit_fuse_leak_bucket"); -local tl_ops_limit = require("limit.tl_ops_limit"); - -local cjson = require("cjson"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_manage_env = require("tl_ops_manage_env") - -local shared = ngx.shared.tlopsbalance +local tl_ops_limit = require("limit.tl_ops_limit"); +local cjson = require("cjson.safe"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_manage_env = require("tl_ops_manage_env") +local shared = ngx.shared.tlopsbalance local _M = { @@ -155,6 +151,9 @@ function _M:tl_ops_balance_core_balance() end end + -- 服务层waf + waf:init(tl_ops_constant_waf_scope.service); + -- 节点下线 if not node_state or node_state == false then balance_count:tl_ops_balance_count_incr_fail(node.service, node_id) diff --git a/balance/tl_ops_balance_core_api.lua b/balance/tl_ops_balance_core_api.lua index f3404c3..521f0a3 100644 --- a/balance/tl_ops_balance_core_api.lua +++ b/balance/tl_ops_balance_core_api.lua @@ -4,15 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local cache_api = require("cache.tl_ops_cache"):new("tl-ops-balance-api"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local shared = ngx.shared.tlopsbalance -local find = ngx.re.find +local cjson = require("cjson.safe"); +local cache_api = require("cache.tl_ops_cache_core"):new("tl-ops-balance-api"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local shared = ngx.shared.tlopsbalance +local find = ngx.re.find local tl_ops_balance_api_service_matcher = function(service_list_table) local matcher = nil @@ -75,30 +74,32 @@ local tl_ops_balance_api_service_matcher = function(service_list_table) end end - - if not matcher or type(matcher) ~= 'table' then return nil, nil, nil, nil end local service_list = service_list_table[matcher.service] - - -- node balance local node_id = matcher.node -- lua index start 1 - if node_id then - node = service_list[tonumber(node_id) + 1] - else - -- random balance - math.randomseed(#request_uri) - node_id = tonumber(math.random(0,1) % #service_list_table[matcher.service]) + 1 - node = service_list[node_id] - end local host = matcher.host if not host or host == nil then host = "" end + -- 指定节点 + if api_rule == tl_ops_constant_balance_api.rule.point then + if node_id ~= nil then + node = service_list[tonumber(node_id) + 1] + else + return nil, nil, nil, host + end + -- 服务内随机 + elseif api_rule == tl_ops_constant_balance_api.rule.random then + math.randomseed(#request_uri) + node_id = tonumber(math.random(0,1) % #service_list_table[matcher.service]) + 1 + node = service_list[node_id] + end + -- 获取当前节点健康状态 local key = tl_ops_utils_func:gen_node_key(tl_ops_constant_health.cache_key.state, matcher.service, node_id) local node_state , _ = shared:get(key) diff --git a/balance/tl_ops_balance_core_cookie.lua b/balance/tl_ops_balance_core_cookie.lua index ff1324d..24e383a 100644 --- a/balance/tl_ops_balance_core_cookie.lua +++ b/balance/tl_ops_balance_core_cookie.lua @@ -4,15 +4,15 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local cache_cookie = require("cache.tl_ops_cache"):new("tl-ops-balance-cookie"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); +local cache_cookie = require("cache.tl_ops_cache_core"):new("tl-ops-balance-cookie"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local shared = ngx.shared.tlopsbalance +local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local shared = ngx.shared.tlopsbalance -- 获取命中的cookie路由项 @@ -81,14 +81,23 @@ local tl_ops_balance_cookie_service_matcher = function(service_list_table) end local service_list = service_list_table[matcher.service] - - -- node balance local node_id = matcher.node -- lua index start 1 - if node_id then - node = service_list[tonumber(node_id) + 1] - else - -- random balance - math.randomseed(#matcher.key) + + local host = matcher.host + if not host or host == nil then + host = "" + end + + -- 指定节点 + if api_rule == tl_ops_constant_balance_api.rule.point then + if node_id ~= nil then + node = service_list[tonumber(node_id) + 1] + else + return nil, nil, nil, host + end + -- 服务内随机 + elseif api_rule == tl_ops_constant_balance_api.rule.random then + math.randomseed(#request_uri) node_id = tonumber(math.random(0,1) % #service_list_table[matcher.service]) + 1 node = service_list[node_id] end @@ -96,12 +105,6 @@ local tl_ops_balance_cookie_service_matcher = function(service_list_table) -- 获取当前节点健康状态 local key = tl_ops_utils_func:gen_node_key(tl_ops_constant_health.cache_key.state, matcher.service, node_id) local node_state , _ = shared:get(key) - - - local host = matcher.host - if not host or host == nil then - host = "" - end return node, node_state, node_id, host end diff --git a/balance/tl_ops_balance_core_header.lua b/balance/tl_ops_balance_core_header.lua index 46d1b28..e2dcec8 100644 --- a/balance/tl_ops_balance_core_header.lua +++ b/balance/tl_ops_balance_core_header.lua @@ -4,15 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local cache_header = require("cache.tl_ops_cache"):new("tl-ops-balance-header"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local shared = ngx.shared.tlopsbalance +local cjson = require("cjson.safe"); +local cache_header = require("cache.tl_ops_cache_core"):new("tl-ops-balance-header"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local shared = ngx.shared.tlopsbalance -- 获取命中的header路由项 @@ -84,14 +83,23 @@ local tl_ops_balance_header_service_matcher = function(service_list_table) end local service_list = service_list_table[matcher.service] - - -- node balance local node_id = matcher.node -- lua index start 1 - if node_id then - node = service_list[tonumber(node_id) + 1] - else - -- random balance - math.randomseed(#matcher.key) + + local host = matcher.host + if not host or host == nil then + host = "" + end + + -- 指定节点 + if api_rule == tl_ops_constant_balance_api.rule.point then + if node_id ~= nil then + node = service_list[tonumber(node_id) + 1] + else + return nil, nil, nil, host + end + -- 服务内随机 + elseif api_rule == tl_ops_constant_balance_api.rule.random then + math.randomseed(#request_uri) node_id = tonumber(math.random(0,1) % #service_list_table[matcher.service]) + 1 node = service_list[node_id] end @@ -100,13 +108,6 @@ local tl_ops_balance_header_service_matcher = function(service_list_table) local key = tl_ops_utils_func:gen_node_key(tl_ops_constant_health.cache_key.state, matcher.service, node_id) local node_state , _ = shared:get(key) - - local host = matcher.host - if not host or host == nil then - host = "" - end - - return node, node_state, node_id, host end diff --git a/balance/tl_ops_balance_core_param.lua b/balance/tl_ops_balance_core_param.lua index 1d5cb2d..d3886a8 100644 --- a/balance/tl_ops_balance_core_param.lua +++ b/balance/tl_ops_balance_core_param.lua @@ -4,15 +4,15 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local cache_param = require("cache.tl_ops_cache"):new("tl-ops-balance-param"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local cjson = require("cjson.safe"); +local cache_param = require("cache.tl_ops_cache_core"):new("tl-ops-balance-param"); +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local shared = ngx.shared.tlopsbalance +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local shared = ngx.shared.tlopsbalance -- 获取命中的param路由项 @@ -82,14 +82,23 @@ local tl_ops_balance_param_service_matcher = function(service_list_table) end local service_list = service_list_table[matcher.service] - - -- node balance local node_id = matcher.node -- lua index start 1 - if node_id then - node = service_list[tonumber(node_id) + 1] - else - -- random balance - math.randomseed(#matcher.key) + + local host = matcher.host + if not host or host == nil then + host = "" + end + + -- 指定节点 + if api_rule == tl_ops_constant_balance_api.rule.point then + if node_id ~= nil then + node = service_list[tonumber(node_id) + 1] + else + return nil, nil, nil, host + end + -- 服务内随机 + elseif api_rule == tl_ops_constant_balance_api.rule.random then + math.randomseed(#request_uri) node_id = tonumber(math.random(0,1) % #service_list_table[matcher.service]) + 1 node = service_list[node_id] end @@ -98,13 +107,6 @@ local tl_ops_balance_param_service_matcher = function(service_list_table) local key = tl_ops_utils_func:gen_node_key(tl_ops_constant_health.cache_key.state, matcher.service, node_id) local node_state , _ = shared:get(key) - - local host = matcher.host - if not host or host == nil then - host = "" - end - - return node, node_state, node_id, host end diff --git a/cache/tl_ops_cache.lua b/cache/tl_ops_cache.lua index 7a0474f..0d5454b 100644 --- a/cache/tl_ops_cache.lua +++ b/cache/tl_ops_cache.lua @@ -1,545 +1,38 @@ --- tl_ops_cache --- en : cache manager --- zn : 对外缓存管理工具 --- 六种模式,000分别代表dict,redis,store, 例如 : 101代表开启dict,store模式 --- @author iamtsm --- @email 1905333456@qq.com - -local cache_redis = require("cache.tl_ops_cache_redis"):new(); -local cache_dict = require("cache.tl_ops_cache_dict"):new(); -local constant_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_env = require("tl_ops_manage_env") - --- 是否开启redis -local use_redis = tl_ops_env.cache.redis; - - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - -local _M = new_tab(0, 50) -_M._VERSION = '0.02' -local mt = { __index = _M } - - -function _M:new(business) - local cache_store = require("cache.tl_ops_cache_store"):new(business); - return setmetatable({ - business = business, - cache_store = cache_store - }, mt) -end - - - ---[[ - store 模式 -]] -function _M:get001( key ) - if key == nil then - return nil; - end - - -- load from store - local res_store ,_ = self.cache_store:get(key); - if res_store and res_store ~= nil then - return res_store; - end - - return nil , "failed get " .. key; -end - -function _M:set001(key, value) - if key == nil then - return nil; - end - - -- set store - local set_store ,_ = self.cache_store:set(key, value); - if not set_store then - return nil, "failed set to store in 001 " .. key; - end - - return constant_rt.ok; -end - -function _M:del001(key) - if key == nil then - return nil; - end - - -- del store - local del_store ,_ = self.cache_store:del(key); - if not del_store then - return nil, "failed to del store in 001 " .. key; - end - - return constant_rt.ok; -end - - ---[[ - redis 模式 -]] -function _M:get010( key ) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- load from redis - local res_redis ,_ = cache_redis:get(key); - if res_redis and res_redis ~= nil then - return res_redis; - end - - return nil , "failed get " .. key; -end - -function _M:set010(key, value) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- set redis - local set_redis ,_ = cache_redis:set(key, value); - if not set_redis then - return nil, "failed set to redis in 010 " .. key; - end - - return constant_rt.ok; -end - -function _M:del010(key) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- del redis - local del_redis ,_ = cache_dict:del(key); - if not del_redis then - return nil, "failed to del redis in 010 " .. key; - end - - return constant_rt.ok; -end - - ---[[ - redis-store 模式 -]] -function _M:get011( key ) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- load from redis - local res_redis ,_ = cache_redis:get(key); - if res_redis and res_redis ~= nil then - return res_redis; - end - - - -- load from store - local res_store ,_ = self.cache_store:get(key); - if res_store and res_store ~= nil then - - -- set to redis - local set_res ,_ = cache_redis:set(key, res_store); - if not set_res then - return nil, "failed set to redis in 011 " .. key; - end - - return res_store; - end - - return nil , "failed get " .. key; -end - -function _M:set011(key, value) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- set store - local set_store ,_ = self.cache_store:set(key, value); - if not set_store then - return nil, "failed set to store in 011 " .. key; - end - - - -- set redis - local set_redis ,_ = cache_redis:set(key, value); - if not set_redis then - return nil, "failed set to redis in 011 " .. key; - end - - - return constant_rt.ok; -end - -function _M:del011(key) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- del store - local del_store ,_ = self.cache_store:del(key); - if not del_store then - return nil, "failed to del store in 011 " .. key; - end - - -- del redis - local del_redis ,_ = cache_dict:del(key); - if not del_redis then - return nil, "failed to del redis in 011" .. key; - end - - return constant_rt.ok; -end - - ---[[ - dict 模式 -]] -function _M:get100( key ) - if key == nil then - return nil; - end - - -- load from dict - local res_dict ,_ = cache_dict:get(key); - if res_dict and res_dict ~= nil then - return res_dict; - end - - return nil , "failed get " .. key; -end - -function _M:set100(key, value) - if key == nil then - return nil; - end - - -- set dict - local set_dict ,_ = cache_dict:set(key, value); - if not set_dict then - return nil, "failed set to dict in 100 " .. key; - end - - - return constant_rt.ok; -end - -function _M:del100(key) - if key == nil then - return nil; - end - - -- del dict - local del_dict ,_ = cache_dict:del(key); - if not del_dict then - return nil, "failed to del dict in 100 " .. key; - end - - - return constant_rt.ok; -end - - ---[[ - dict-store模式 -]] -function _M:get101( key ) - if key == nil then - return nil; - end - - -- load from dict - local res_dict ,_ = cache_dict:get(key); - if res_dict and res_dict ~= nil then - return res_dict; - end - - -- load from store - local res_store ,_ = self.cache_store:get(key); - if res_store and res_store ~= nil then - - -- set to dict - local set_res ,_ = cache_dict:set(key, res_store); - if not set_res then - return nil, "failed set to dict in 101 " .. key; - end - - return res_store; - end - - return nil , "failed get " .. key; -end - -function _M:set101(key, value) - if key == nil then - return nil; - end - - -- set store - local set_store ,_ = self.cache_store:set(key, value); - if not set_store then - return nil, "failed set to store in 101 " .. key; - end - - - -- set dict - local set_dict ,_ = cache_dict:set(key, value); - if not set_dict then - return nil, "failed set to dict in 101" .. key; - end - - - return constant_rt.ok; -end - -function _M:del101(key) - if key == nil then - return nil; - end - - -- del store - local del_store ,_ = self.cache_store:del(key); - if not del_store then - return nil, "failed to del store in 101 " .. key; - end - - -- del dict - local del_dict ,_ = cache_dict:del(key); - if not del_dict then - return nil, "failed to del dict in 101 " .. key; - end - - - return constant_rt.ok; -end - - ---[[ - dict-redis 模式 -]] -function _M:get110( key ) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- load from dict - local res_dict ,_ = cache_dict:get(key); - if res_dict and res_dict ~= nil then - return res_dict; - end - - -- load from redis - local res_redis ,_ = cache_redis:get(key); - if res_redis and res_redis ~= nil then - -- set to dict - local set_res ,_ = cache_dict:set(key, res_redis); - if not set_res then - return nil, "failed set to dict in 110 " .. key; - end - return res_redis; - end - - return nil , "failed get " .. key; -end - -function _M:set110(key, value) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- set redis - local set_redis ,_ = cache_redis:set(key, value); - if not set_redis then - return nil, "failed set to redis in 110 " .. key; - end - - -- set dict - local set_dict ,_ = cache_dict:set(key, value); - if not set_dict then - return nil, "failed set to dict in 110 " .. key; - end - - return constant_rt.ok; -end - -function _M:del110(key) - if not use_redis then - return nil , "un open redis cache " .. key; - end - - if key == nil then - return nil; - end - - -- del redis - local del_redis ,_ = cache_dict:del(key); - if not del_redis then - return nil, "failed to del redis in 110 " .. key; - end - - -- del dict - local del_dict ,_ = cache_dict:del(key); - if not del_dict then - return nil, "failed to del dict in 110 " .. key; - end - - - return constant_rt.ok; -end - - - ---[[ - dict-redis-store 模式 -]] -function _M:get( key ) - if key == nil then - return nil; - end - - -- load from dict - local res_dict ,_ = cache_dict:get(key); - if res_dict and res_dict ~= nil then - return res_dict; - end - - - - if use_redis then - -- load from redis - local res_redis ,_ = cache_redis:get(key); - if res_redis and res_redis ~= nil then - -- set to dict - local set_res ,_ = cache_dict:set(key, res_redis); - if not set_res then - return nil, "failed set to dict by redis res " .. key; - end - return res_redis; - end - end - - -- load from store - local res_store ,_ = self.cache_store:get(key); - if res_store and res_store ~= nil then - - if use_redis then - -- set to redis - local set_res ,_ = cache_redis:set(key, res_store); - if not set_res then - return nil, "failed set to redis by store res " .. key; - end - end - - -- set to dict - local set_res ,_ = cache_dict:set(key, res_store); - if not set_res then - return nil, "failed set to dict by redis res " .. key; - end - - return res_store; - end - - return nil , "failed get " .. key; -end - -function _M:set(key, value) - if key == nil then - return nil; - end - - -- set store - local set_store ,_ = self.cache_store:set(key, value); - if not set_store then - return nil, "failed set to store " .. key; - end - - if use_redis then - -- set redis - local set_redis ,_ = cache_redis:set(key, value); - if not set_redis then - return nil, "failed set to redis after set store " .. key; - end - end - - -- set dict - local set_dict ,_ = cache_dict:set(key, value); - if not set_dict then - return nil, "failed set to dict after set redis" .. key; - end - - - return constant_rt.ok; -end - -function _M:del(key) - if key == nil then - return nil; - end - - -- del store - local del_store ,_ = self.cache_store:del(key); - if not del_store then - return nil, "failed to del store " .. key; - end - - if use_redis then - -- del redis - local del_redis ,_ = cache_dict:del(key); - if not del_redis then - return nil, "failed to del redis after del store" .. key; - end - end - - -- del dict - local del_dict ,_ = cache_dict:del(key); - if not del_dict then - return nil, "failed to del dict after set redis" .. key; - end - - - return constant_rt.ok; -end - - - -return _M; \ No newline at end of file +-- cache业务集合 + +local service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); +local limit = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); +local health = require("cache.tl_ops_cache_core"):new("tl-ops-health"); + +local balance = require("cache.tl_ops_cache_core"):new("tl-ops-balance"); +local balance_api = require("cache.tl_ops_cache_core"):new("tl-ops-balance-api"); +local balance_param = require("cache.tl_ops_cache_core"):new("tl-ops-balance-param"); +local balance_header = require("cache.tl_ops_cache_core"):new("tl-ops-balance-header"); +local balance_cookie = require("cache.tl_ops_cache_core"):new("tl-ops-balance-cookie"); + +local waf = require("cache.tl_ops_cache_core"):new("tl-ops-waf"); +local waf_api = require("cache.tl_ops_cache_core"):new("tl-ops-waf-api"); +local waf_ip = require("cache.tl_ops_cache_core"):new("tl-ops-waf-ip"); +local waf_cookie = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cookie"); +local waf_header = require("cache.tl_ops_cache_core"):new("tl-ops-waf-header"); +local waf_cc = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cc"); +local waf_param = require("cache.tl_ops_cache_core"):new("tl-ops-waf-param"); + + +return { + service = service, + health = health, + limit = limit, + balance = balance, + balance_api = balance_api, + balance_param = balance_param, + balance_header = balance_header, + balance_cookie = balance_cookie, + waf = waf, + waf_ip = waf_ip, + waf_api = waf_api, + waf_cc = waf_cc, + waf_header = waf_header, + waf_cookie = waf_cookie, + waf_param = waf_param, +} \ No newline at end of file diff --git a/cache/tl_ops_cache_core.lua b/cache/tl_ops_cache_core.lua new file mode 100644 index 0000000..6ce17b9 --- /dev/null +++ b/cache/tl_ops_cache_core.lua @@ -0,0 +1,539 @@ +-- tl_ops_cache +-- en : cache manager +-- zn : 对外缓存管理工具 +-- 六种模式,000分别代表dict,redis,store, 例如 : 101代表开启dict,store模式 +-- @author iamtsm +-- @email 1905333456@qq.com + +local cache_redis = require("cache.tl_ops_cache_redis"):new(); +local cache_dict = require("cache.tl_ops_cache_dict"):new(); +local constant_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; +local tl_ops_manage_env = require("tl_ops_manage_env") +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local use_redis = tl_ops_manage_env.cache.redis; + + +local _M = tl_ops_utils_func:new_tab(0, 20) +_M._VERSION = '0.02' +local mt = { __index = _M } + + +function _M:new(business) + local cache_store = require("cache.tl_ops_cache_store"):new(business); + return setmetatable({ + business = business, + cache_store = cache_store + }, mt) +end + + + +--[[ + store 模式 +]] +function _M:get001( key ) + if key == nil then + return nil; + end + + -- load from store + local res_store ,_ = self.cache_store:get(key); + if res_store and res_store ~= nil then + return res_store; + end + + return nil , "failed get " .. key; +end + +function _M:set001(key, value) + if key == nil then + return nil; + end + + -- set store + local set_store ,_ = self.cache_store:set(key, value); + if not set_store then + return nil, "failed set to store in 001 " .. key; + end + + return constant_rt.ok; +end + +function _M:del001(key) + if key == nil then + return nil; + end + + -- del store + local del_store ,_ = self.cache_store:del(key); + if not del_store then + return nil, "failed to del store in 001 " .. key; + end + + return constant_rt.ok; +end + + +--[[ + redis 模式 +]] +function _M:get010( key ) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- load from redis + local res_redis ,_ = cache_redis:get(key); + if res_redis and res_redis ~= nil then + return res_redis; + end + + return nil , "failed get " .. key; +end + +function _M:set010(key, value) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- set redis + local set_redis ,_ = cache_redis:set(key, value); + if not set_redis then + return nil, "failed set to redis in 010 " .. key; + end + + return constant_rt.ok; +end + +function _M:del010(key) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- del redis + local del_redis ,_ = cache_dict:del(key); + if not del_redis then + return nil, "failed to del redis in 010 " .. key; + end + + return constant_rt.ok; +end + + +--[[ + redis-store 模式 +]] +function _M:get011( key ) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- load from redis + local res_redis ,_ = cache_redis:get(key); + if res_redis and res_redis ~= nil then + return res_redis; + end + + + -- load from store + local res_store ,_ = self.cache_store:get(key); + if res_store and res_store ~= nil then + + -- set to redis + local set_res ,_ = cache_redis:set(key, res_store); + if not set_res then + return nil, "failed set to redis in 011 " .. key; + end + + return res_store; + end + + return nil , "failed get " .. key; +end + +function _M:set011(key, value) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- set store + local set_store ,_ = self.cache_store:set(key, value); + if not set_store then + return nil, "failed set to store in 011 " .. key; + end + + + -- set redis + local set_redis ,_ = cache_redis:set(key, value); + if not set_redis then + return nil, "failed set to redis in 011 " .. key; + end + + + return constant_rt.ok; +end + +function _M:del011(key) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- del store + local del_store ,_ = self.cache_store:del(key); + if not del_store then + return nil, "failed to del store in 011 " .. key; + end + + -- del redis + local del_redis ,_ = cache_dict:del(key); + if not del_redis then + return nil, "failed to del redis in 011" .. key; + end + + return constant_rt.ok; +end + + +--[[ + dict 模式 +]] +function _M:get100( key ) + if key == nil then + return nil; + end + + -- load from dict + local res_dict ,_ = cache_dict:get(key); + if res_dict and res_dict ~= nil then + return res_dict; + end + + return nil , "failed get " .. key; +end + +function _M:set100(key, value) + if key == nil then + return nil; + end + + -- set dict + local set_dict ,_ = cache_dict:set(key, value); + if not set_dict then + return nil, "failed set to dict in 100 " .. key; + end + + + return constant_rt.ok; +end + +function _M:del100(key) + if key == nil then + return nil; + end + + -- del dict + local del_dict ,_ = cache_dict:del(key); + if not del_dict then + return nil, "failed to del dict in 100 " .. key; + end + + + return constant_rt.ok; +end + + +--[[ + dict-store模式 +]] +function _M:get101( key ) + if key == nil then + return nil; + end + + -- load from dict + local res_dict ,_ = cache_dict:get(key); + if res_dict and res_dict ~= nil then + return res_dict; + end + + -- load from store + local res_store ,_ = self.cache_store:get(key); + if res_store and res_store ~= nil then + + -- set to dict + local set_res ,_ = cache_dict:set(key, res_store); + if not set_res then + return nil, "failed set to dict in 101 " .. key; + end + + return res_store; + end + + return nil , "failed get " .. key; +end + +function _M:set101(key, value) + if key == nil then + return nil; + end + + -- set store + local set_store ,_ = self.cache_store:set(key, value); + if not set_store then + return nil, "failed set to store in 101 " .. key; + end + + + -- set dict + local set_dict ,_ = cache_dict:set(key, value); + if not set_dict then + return nil, "failed set to dict in 101" .. key; + end + + + return constant_rt.ok; +end + +function _M:del101(key) + if key == nil then + return nil; + end + + -- del store + local del_store ,_ = self.cache_store:del(key); + if not del_store then + return nil, "failed to del store in 101 " .. key; + end + + -- del dict + local del_dict ,_ = cache_dict:del(key); + if not del_dict then + return nil, "failed to del dict in 101 " .. key; + end + + + return constant_rt.ok; +end + + +--[[ + dict-redis 模式 +]] +function _M:get110( key ) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- load from dict + local res_dict ,_ = cache_dict:get(key); + if res_dict and res_dict ~= nil then + return res_dict; + end + + -- load from redis + local res_redis ,_ = cache_redis:get(key); + if res_redis and res_redis ~= nil then + -- set to dict + local set_res ,_ = cache_dict:set(key, res_redis); + if not set_res then + return nil, "failed set to dict in 110 " .. key; + end + return res_redis; + end + + return nil , "failed get " .. key; +end + +function _M:set110(key, value) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- set redis + local set_redis ,_ = cache_redis:set(key, value); + if not set_redis then + return nil, "failed set to redis in 110 " .. key; + end + + -- set dict + local set_dict ,_ = cache_dict:set(key, value); + if not set_dict then + return nil, "failed set to dict in 110 " .. key; + end + + return constant_rt.ok; +end + +function _M:del110(key) + if not use_redis then + return nil , "un open redis cache " .. key; + end + + if key == nil then + return nil; + end + + -- del redis + local del_redis ,_ = cache_dict:del(key); + if not del_redis then + return nil, "failed to del redis in 110 " .. key; + end + + -- del dict + local del_dict ,_ = cache_dict:del(key); + if not del_dict then + return nil, "failed to del dict in 110 " .. key; + end + + + return constant_rt.ok; +end + + + +--[[ + dict-redis-store 模式 +]] +function _M:get( key ) + if key == nil then + return nil; + end + + -- load from dict + local res_dict ,_ = cache_dict:get(key); + if res_dict and res_dict ~= nil then + return res_dict; + end + + + + if use_redis then + -- load from redis + local res_redis ,_ = cache_redis:get(key); + if res_redis and res_redis ~= nil then + -- set to dict + local set_res ,_ = cache_dict:set(key, res_redis); + if not set_res then + return nil, "failed set to dict by redis res " .. key; + end + return res_redis; + end + end + + -- load from store + local res_store ,_ = self.cache_store:get(key); + if res_store and res_store ~= nil then + + if use_redis then + -- set to redis + local set_res ,_ = cache_redis:set(key, res_store); + if not set_res then + return nil, "failed set to redis by store res " .. key; + end + end + + -- set to dict + local set_res ,_ = cache_dict:set(key, res_store); + if not set_res then + return nil, "failed set to dict by redis res " .. key; + end + + return res_store; + end + + return nil , "failed get " .. key; +end + +function _M:set(key, value) + if key == nil then + return nil; + end + + -- set store + local set_store ,_ = self.cache_store:set(key, value); + if not set_store then + return nil, "failed set to store " .. key; + end + + if use_redis then + -- set redis + local set_redis ,_ = cache_redis:set(key, value); + if not set_redis then + return nil, "failed set to redis after set store " .. key; + end + end + + -- set dict + local set_dict ,_ = cache_dict:set(key, value); + if not set_dict then + return nil, "failed set to dict after set redis" .. key; + end + + + return constant_rt.ok; +end + +function _M:del(key) + if key == nil then + return nil; + end + + -- del store + local del_store ,_ = self.cache_store:del(key); + if not del_store then + return nil, "failed to del store " .. key; + end + + if use_redis then + -- del redis + local del_redis ,_ = cache_dict:del(key); + if not del_redis then + return nil, "failed to del redis after del store" .. key; + end + end + + -- del dict + local del_dict ,_ = cache_dict:del(key); + if not del_dict then + return nil, "failed to del dict after set redis" .. key; + end + + + return constant_rt.ok; +end + + + +return _M; \ No newline at end of file diff --git a/cache/tl_ops_cache_dict.lua b/cache/tl_ops_cache_dict.lua index a953190..e47c3c5 100644 --- a/cache/tl_ops_cache_dict.lua +++ b/cache/tl_ops_cache_dict.lua @@ -4,21 +4,14 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cache_dict = ngx.shared.tlopsbalance; -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_cache_dict"); +local cache_dict = ngx.shared.tlopsbalance; +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_cache_dict"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - - -local _M = new_tab(0, 50) +local _M = tl_ops_utils_func:new_tab(0, 20) _M._VERSION = '0.02' local mt = { __index = _M } - -- get function _M:get( key ) if key == nil then diff --git a/cache/tl_ops_cache_redis.lua b/cache/tl_ops_cache_redis.lua index 3d99767..97171d5 100644 --- a/cache/tl_ops_cache_redis.lua +++ b/cache/tl_ops_cache_redis.lua @@ -4,17 +4,11 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cache_redis = require("lib.iredis"):new(); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_cache_redis"); +local cache_redis = require("lib.iredis"):new(); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_cache_redis"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - - -local _M = new_tab(0, 50) +local _M = tl_ops_utils_func:new_tab(0, 20) _M._VERSION = '0.02' local mt = { __index = _M } diff --git a/cache/tl_ops_cache_store.lua b/cache/tl_ops_cache_store.lua index bf05c23..a608bac 100644 --- a/cache/tl_ops_cache_store.lua +++ b/cache/tl_ops_cache_store.lua @@ -5,15 +5,10 @@ -- @email 1905333456@qq.com -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_cache_store"); - - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_cache_store"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local _M = new_tab(0, 50) +local _M = tl_ops_utils_func:new_tab(0, 20) _M._VERSION = '0.02' local mt = { __index = _M } diff --git a/conf/tl_ops_manage.conf b/conf/tl_ops_manage.conf index c73d7cd..51919f9 100644 --- a/conf/tl_ops_manage.conf +++ b/conf/tl_ops_manage.conf @@ -1,12 +1,14 @@ lua_shared_dict tlopsbalance 100m; lua_shared_dict tlopswaf 100m; +lua_shared_dict tlopsplugin 100m; init_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init(); + tlops = require("tl_ops_manage") + tlops:tl_ops_process_init(); } init_worker_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init_worker(); + tlops:tl_ops_process_init_worker(); } server { @@ -29,29 +31,29 @@ server { add_header Access-Control-Allow-Methods *; rewrite_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init_rewrite(); + tlops:tl_ops_process_init_rewrite(); } set $node ''; access_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init_access(); + tlops:tl_ops_process_init_access(); } proxy_pass $node; content_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init_content(); + tlops:tl_ops_process_init_content(); } header_filter_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init_header(); + tlops:tl_ops_process_init_header(); } body_filter_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init_body(); + tlops:tl_ops_process_init_body(); } log_by_lua_block { - require("tl_ops_manage"):tl_ops_process_init_log(); + tlops:tl_ops_process_init_log(); } } diff --git a/constant/tl_ops_constant.lua b/constant/tl_ops_constant.lua new file mode 100644 index 0000000..0d0a32e --- /dev/null +++ b/constant/tl_ops_constant.lua @@ -0,0 +1,40 @@ +-- constant数据集合 + +local comm = require("constant.tl_ops_constant_comm"); +local service = require("constant.tl_ops_constant_service"); +local health = require("constant.tl_ops_constant_health") +local limit = require("constant.tl_ops_constant_limit"); +local balance = require("constant.tl_ops_constant_balance"); +local balance_api = require("constant.tl_ops_constant_balance_api"); +local balance_param = require("constant.tl_ops_constant_balance_param"); +local balance_header = require("constant.tl_ops_constant_balance_header"); +local balance_cookie = require("constant.tl_ops_constant_balance_cookie"); +local waf = require("constant.tl_ops_constant_waf"); +local waf_scope = require("constant.tl_ops_constant_waf_scope"); +local waf_ip = require("constant.tl_ops_constant_waf_ip"); +local waf_api = require("constant.tl_ops_constant_waf_api"); +local waf_cc = require("constant.tl_ops_constant_waf_cc"); +local waf_header = require("constant.tl_ops_constant_waf_header"); +local waf_cookie = require("constant.tl_ops_constant_waf_cookie"); +local waf_param = require("constant.tl_ops_constant_waf_param"); + + +return { + comm = comm, + service = service, + health = health, + limit = limit, + balance = balance, + balance_api = balance_api, + balance_param = balance_param, + balance_header = balance_header, + balance_cookie = balance_cookie, + waf = waf, + waf_scope = waf_scope, + waf_ip = waf_ip, + waf_api = waf_api, + waf_cc = waf_cc, + waf_header = waf_header, + waf_cookie = waf_cookie, + waf_param = waf_param, +} \ No newline at end of file diff --git a/constant/tl_ops_constant_balance.lua b/constant/tl_ops_constant_balance.lua index 32570e5..9854b77 100644 --- a/constant/tl_ops_constant_balance.lua +++ b/constant/tl_ops_constant_balance.lua @@ -1,8 +1,8 @@ -local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); -local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); -local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); -local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); +local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); +local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); +local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -- 基础路由功能定义 @@ -19,8 +19,8 @@ local tl_ops_constant_balance = { token_limit = "tl_ops_balance_token_limit_err_code", leak_limit = "tl_ops_balance_leak_limit_err_code", offline = "tl_ops_balance_offline_err_code", - req_succ = "tl_ops_balance_req_succ", -- 以服务节点为单位路由请求成功次数记录 (区间) int - req_fail = "tl_ops_balance_req_fail", -- 以服务节点为单位路由请求失败次数记录 (总量) int + req_succ = "tl_ops_balance_req_succ", -- 以服务节点为单位路由请求成功次数 int + req_fail = "tl_ops_balance_req_fail", -- 以服务节点为单位路由请求失败次数 int balance_interval_success = "tl_ops_balance_interval_success", -- 以服务节点为单位,周期内成功次数集合 list }, api = { diff --git a/constant/tl_ops_constant_limit.lua b/constant/tl_ops_constant_limit.lua index 4ebac43..6742283 100644 --- a/constant/tl_ops_constant_limit.lua +++ b/constant/tl_ops_constant_limit.lua @@ -1,5 +1,5 @@ -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -- 令牌桶配置 local token = { --服务令牌桶配置 diff --git a/constant/tl_ops_constant_service.lua b/constant/tl_ops_constant_service.lua index e0b036d..941ee5e 100644 --- a/constant/tl_ops_constant_service.lua +++ b/constant/tl_ops_constant_service.lua @@ -1,5 +1,5 @@ -local tl_ops_status = require("constant.tl_ops_constant_comm").tl_ops_status; -local snowflake = require("lib.snowflake"); +local tl_ops_status = require("constant.tl_ops_constant_comm").tl_ops_status; +local snowflake = require("lib.snowflake"); -- service 默认列表 local tl_ops_constant_service = { cache_key = { diff --git a/constant/tl_ops_constant_waf.lua b/constant/tl_ops_constant_waf.lua index a42de11..f526a3a 100644 --- a/constant/tl_ops_constant_waf.lua +++ b/constant/tl_ops_constant_waf.lua @@ -1,15 +1,16 @@ -local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); -local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); -local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); -local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); -local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); -local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); +local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); +local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); +local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); +local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); +local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -- waf规则配置 local tl_ops_constant_waf = { cache_key = { + lock = "tl_ops_waf_lock", options = "tl_ops_waf_options", ip = "tl_ops_waf_ip_err_code", api = "tl_ops_waf_api_err_code", @@ -17,6 +18,14 @@ local tl_ops_constant_waf = { header = "tl_ops_waf_header_err_code", cookie = "tl_ops_waf_cookie_err_code", param = "tl_ops_waf_param_err_code", + + req_ip = "tl_ops_waf_req_ip", -- waf统计, waf-ip命中次数 + req_api = "tl_ops_waf_req_api", + req_cc = "tl_ops_waf_req_cc", + req_header = "tl_ops_waf_req_header", + req_cookie = "tl_ops_waf_req_cookie", + req_param = "tl_ops_waf_req_param", + waf_interval_success = "tl_ops_waf_interval_success", -- 以服务节点为单位,周期内拦截成功次数集合 list }, ip = { list = tl_ops_constant_waf_ip.list, diff --git a/constant/tl_ops_constant_waf_api.lua b/constant/tl_ops_constant_waf_api.lua index da9f171..a66e084 100644 --- a/constant/tl_ops_constant_waf_api.lua +++ b/constant/tl_ops_constant_waf_api.lua @@ -1,5 +1,5 @@ -local snowflake = require("lib.snowflake"); -local scope = require("constant.tl_ops_constant_waf_scope"); +local snowflake = require("lib.snowflake"); +local scope = require("constant.tl_ops_constant_waf_scope"); -- api waf默认列表 local tl_ops_constant_waf_api = { diff --git a/constant/tl_ops_constant_waf_cc.lua b/constant/tl_ops_constant_waf_cc.lua index ad05742..8e96fc6 100644 --- a/constant/tl_ops_constant_waf_cc.lua +++ b/constant/tl_ops_constant_waf_cc.lua @@ -1,5 +1,5 @@ -local snowflake = require("lib.snowflake"); -local scope = require("constant.tl_ops_constant_waf_scope"); +local snowflake = require("lib.snowflake"); +local scope = require("constant.tl_ops_constant_waf_scope"); -- cc waf默认列表 local tl_ops_constant_waf_cc = { diff --git a/constant/tl_ops_constant_waf_cookie.lua b/constant/tl_ops_constant_waf_cookie.lua index 2c14422..f16b321 100644 --- a/constant/tl_ops_constant_waf_cookie.lua +++ b/constant/tl_ops_constant_waf_cookie.lua @@ -1,5 +1,5 @@ local snowflake = require("lib.snowflake"); -local scope = require("constant.tl_ops_constant_waf_scope"); +local scope = require("constant.tl_ops_constant_waf_scope"); -- cookie waf默认列表 local tl_ops_constant_waf_cookie = { diff --git a/constant/tl_ops_constant_waf_header.lua b/constant/tl_ops_constant_waf_header.lua index 2a60a91..7594b69 100644 --- a/constant/tl_ops_constant_waf_header.lua +++ b/constant/tl_ops_constant_waf_header.lua @@ -1,5 +1,5 @@ -local snowflake = require("lib.snowflake"); -local scope = require("constant.tl_ops_constant_waf_scope"); +local snowflake = require("lib.snowflake"); +local scope = require("constant.tl_ops_constant_waf_scope"); -- header waf默认列表 local tl_ops_constant_waf_header = { diff --git a/constant/tl_ops_constant_waf_ip.lua b/constant/tl_ops_constant_waf_ip.lua index 484f6ed..83f92a0 100644 --- a/constant/tl_ops_constant_waf_ip.lua +++ b/constant/tl_ops_constant_waf_ip.lua @@ -1,5 +1,5 @@ local snowflake = require("lib.snowflake"); -local scope = require("constant.tl_ops_constant_waf_scope"); +local scope = require("constant.tl_ops_constant_waf_scope"); -- ip waf默认列表 local tl_ops_constant_waf_ip = { diff --git a/constant/tl_ops_constant_waf_param.lua b/constant/tl_ops_constant_waf_param.lua index 2a84cb9..0189926 100644 --- a/constant/tl_ops_constant_waf_param.lua +++ b/constant/tl_ops_constant_waf_param.lua @@ -1,5 +1,5 @@ local snowflake = require("lib.snowflake"); -local scope = require("constant.tl_ops_constant_waf_scope"); +local scope = require("constant.tl_ops_constant_waf_scope"); -- param waf默认列表 local tl_ops_constant_waf_param = { diff --git a/constant/tl_ops_constant_waf_scope.lua b/constant/tl_ops_constant_waf_scope.lua index 6a8b6a8..e042cf8 100644 --- a/constant/tl_ops_constant_waf_scope.lua +++ b/constant/tl_ops_constant_waf_scope.lua @@ -3,7 +3,6 @@ local scope = { global = "global", -- 全局waf service = "service", -- 服务级别waf - node = "node", -- 节点级别waf } return scope \ No newline at end of file diff --git a/doc/change.md b/doc/change.md index 56544a1..e2a9198 100644 --- a/doc/change.md +++ b/doc/change.md @@ -1,6 +1,31 @@ ## 事务更新日程 +2022-07-07 + + 1. 支持waf统计器 + + 2. 支持服务级别waf + + 3. 支持动态waf级别切换 + + 4. 移除节点级别waf + + 5. 调整负载逻辑规则 + + 6. 优化插件开发流程 + + 7. 调整同步器作为插件引入 + + 8. 优化代码格式规范 + + 9. 修复管理台修改配置不生效bug + + 10. 修复waf过滤条件判断错误 + + 11. 事务日程调整 + + 2022-07-04 1. 支持插件开发 diff --git a/doc/tl-ops-store.md b/doc/tl-ops-store.md index 558a6f0..fe3fd1a 100644 --- a/doc/tl-ops-store.md +++ b/doc/tl-ops-store.md @@ -7,7 +7,7 @@ ### 1.1 引入cache依赖 按照场景需要创建对应的business-name,每个business-name是一个存储文件和一个对应索引文件 ``` - local cache = require("cache.tl_ops_cache"):new("business-name"); + local cache = require("cache.tl_ops_cache_core"):new("business-name"); ``` ### 1.2 按需调用 diff --git a/health/tl_ops_health.lua b/health/tl_ops_health.lua index 79cb87d..1045eb9 100644 --- a/health/tl_ops_health.lua +++ b/health/tl_ops_health.lua @@ -4,10 +4,10 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_health_check = require("health.tl_ops_health_check"); -local tl_ops_health_check_dynamic_conf = require("health.tl_ops_health_check_dynamic_conf") -local tl_ops_constant_health = require("constant.tl_ops_constant_health"); -local tl_ops_health_check_version = require("health.tl_ops_health_check_version") +local tl_ops_health_check = require("health.tl_ops_health_check"); +local tl_ops_health_check_dynamic_conf = require("health.tl_ops_health_check_dynamic_conf") +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local tl_ops_health_check_version = require("health.tl_ops_health_check_version") local _M = {} diff --git a/health/tl_ops_health_check.lua b/health/tl_ops_health_check.lua index d995b7e..5c76cdf 100644 --- a/health/tl_ops_health_check.lua +++ b/health/tl_ops_health_check.lua @@ -4,19 +4,16 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health"); -local timer_tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_options_timer"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local tl_ops_health_check_dynamic_conf = require("health.tl_ops_health_check_dynamic_conf") -local tl_ops_health_check_version = require("health.tl_ops_health_check_version") - -local tl_ops_status = require("constant.tl_ops_constant_comm").tl_ops_status; -local nx_socket = ngx.socket.tcp -local shared = ngx.shared.tlopsbalance -local find = ngx.re.find +local cjson = require("cjson.safe") +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health") +local tl_ops_utils_func = require("utils.tl_ops_utils_func") +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local tl_ops_health_check_dynamic_conf = require("health.tl_ops_health_check_dynamic_conf") +local tl_ops_health_check_version = require("health.tl_ops_health_check_version") +local tl_ops_status = require("constant.tl_ops_constant_comm").tl_ops_status; +local nx_socket = ngx.socket.tcp +local shared = ngx.shared.tlopsbalance +local find = ngx.re.find @@ -25,13 +22,6 @@ local _M = { } local mt = { __index = _M } - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - - local tl_ops_health_check, tl_ops_health_check_main , tl_ops_health_check_get_lock, @@ -84,7 +74,7 @@ end -- 对给定配置内容进行初始化,对配置进行默认值给定和过滤 tl_ops_health_check_default_confs = function (options, services) - local confs = new_tab(#options, 0) + local confs = tl_ops_utils_func:new_tab(#options, 0) tlog:dbg("tl_ops_health_check_default_confs start") diff --git a/health/tl_ops_health_check_dynamic_conf.lua b/health/tl_ops_health_check_dynamic_conf.lua index d3a33ff..6d144db 100644 --- a/health/tl_ops_health_check_dynamic_conf.lua +++ b/health/tl_ops_health_check_dynamic_conf.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_check_dynamic_conf"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local cache_health = require("cache.tl_ops_cache"):new("tl-ops-health"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local shared = ngx.shared.tlopsbalance +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_check_dynamic_conf"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local cache_health = require("cache.tl_ops_cache_core"):new("tl-ops-health"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service"); +local shared = ngx.shared.tlopsbalance -- 需要提前定义,定时器访问不了 local tl_ops_health_check_dynamic_conf_add_timer_check; @@ -114,7 +114,7 @@ local tl_ops_health_check_dynamic_conf_add_check = function() end local dynamic_options = cjson.decode(options_str) - local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); + local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); local service_str, _ = cache_service:get(tl_ops_constant_service.cache_key.service_list) if not service_str then tlog:err("[add-check] load dynamic service failed , service_str=",service_str) @@ -224,7 +224,7 @@ end -- 同步service配置 local tl_ops_health_check_dynamic_conf_change_service_node_async = function( conf ) - local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); + local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); local service_str, _ = cache_service:get(tl_ops_constant_service.cache_key.service_list) if not service_str then tlog:err("[change-check] load dynamic service failed , service_str=",service_str) diff --git a/health/tl_ops_health_check_version.lua b/health/tl_ops_health_check_version.lua index 35b4b89..2100b87 100644 --- a/health/tl_ops_health_check_version.lua +++ b/health/tl_ops_health_check_version.lua @@ -5,11 +5,11 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_check_version"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local cache_dict = ngx.shared.tlopsbalance; +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_check_version"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local cache_dict = ngx.shared.tlopsbalance; local _M = { _VERSION = '0.02' diff --git a/limit/fuse/tl_ops_limit_fuse.lua b/limit/fuse/tl_ops_limit_fuse.lua index bb10db3..8e2fd4e 100644 --- a/limit/fuse/tl_ops_limit_fuse.lua +++ b/limit/fuse/tl_ops_limit_fuse.lua @@ -4,11 +4,10 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_limit_fuse_check_dynamic_conf = require("limit.fuse.tl_ops_limit_fuse_check_dynamic_conf") -local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") -local tl_ops_limit_fuse_check = require("limit.fuse.tl_ops_limit_fuse_check") - -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") +local tl_ops_limit_fuse_check_dynamic_conf = require("limit.fuse.tl_ops_limit_fuse_check_dynamic_conf") +local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") +local tl_ops_limit_fuse_check = require("limit.fuse.tl_ops_limit_fuse_check") +local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") local _M = {} function _M:init( ) diff --git a/limit/fuse/tl_ops_limit_fuse_check.lua b/limit/fuse/tl_ops_limit_fuse_check.lua index 0d2f72a..4af6dbe 100644 --- a/limit/fuse/tl_ops_limit_fuse_check.lua +++ b/limit/fuse/tl_ops_limit_fuse_check.lua @@ -5,26 +5,17 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local tl_ops_limit_fuse_check_dynamic_conf = require("limit.fuse.tl_ops_limit_fuse_check_dynamic_conf") -local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") -local tl_ops_limit_token_bucket = require("limit.fuse.tl_ops_limit_fuse_token_bucket"); -local tl_ops_limit_leak_bucket = require("limit.fuse.tl_ops_limit_fuse_leak_bucket"); - -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); - -local shared = ngx.shared.tlopsbalance - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_limit_fuse_check_dynamic_conf = require("limit.fuse.tl_ops_limit_fuse_check_dynamic_conf") +local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") +local tl_ops_limit_token_bucket = require("limit.fuse.tl_ops_limit_fuse_token_bucket"); +local tl_ops_limit_leak_bucket = require("limit.fuse.tl_ops_limit_fuse_leak_bucket"); +local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") +local tl_ops_constant_health = require("constant.tl_ops_constant_health") +local tl_ops_constant_service = require("constant.tl_ops_constant_service") +local shared = ngx.shared.tlopsbalance local _STATE = { LIMIT_FUSE_CLOSE = 0, -- 熔断器关闭 @@ -95,7 +86,7 @@ end tl_ops_limit_fuse_default_confs = function(options, services) - local confs = new_tab(#options, 0) + local confs = tl_ops_utils_func:new_tab(#options, 0) tlog:dbg("tl_ops_limit_fuse_default_confs start") diff --git a/limit/fuse/tl_ops_limit_fuse_check_dynamic_conf.lua b/limit/fuse/tl_ops_limit_fuse_check_dynamic_conf.lua index ca4e636..dba30ab 100644 --- a/limit/fuse/tl_ops_limit_fuse_check_dynamic_conf.lua +++ b/limit/fuse/tl_ops_limit_fuse_check_dynamic_conf.lua @@ -4,13 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse_check_dynamic_conf"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") -local cache_limit = require("cache.tl_ops_cache"):new("tl-ops-limit"); -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local shared = ngx.shared.tlopsbalance +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse_check_dynamic_conf"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") +local cache_limit = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); +local tl_ops_constant_service = require("constant.tl_ops_constant_service") +local shared = ngx.shared.tlopsbalance local tl_ops_limit_fuse_check_dynamic_conf_add_timer_check; @@ -116,7 +116,7 @@ local tl_ops_limit_fuse_check_dynamic_conf_add_check = function() end local dynamic_options = cjson.decode(options_str) - local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); + local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); local service_str, _ = cache_service:get(tl_ops_constant_service.cache_key.service_list) if not service_str then tlog:err("[add-check] load dynamic service failed , service_str=",service_str) @@ -274,7 +274,7 @@ end -- 同步service node配置 local tl_ops_limit_fuse_dynamic_conf_change_service_node_async = function( conf ) - local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); + local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service"); local service_str, _ = cache_service:get(tl_ops_constant_service.cache_key.service_list) if not service_str then tlog:err("[change-check] load dynamic service failed , service_str=",service_str) diff --git a/limit/fuse/tl_ops_limit_fuse_check_version.lua b/limit/fuse/tl_ops_limit_fuse_check_version.lua index 5ef4ec0..78708f9 100644 --- a/limit/fuse/tl_ops_limit_fuse_check_version.lua +++ b/limit/fuse/tl_ops_limit_fuse_check_version.lua @@ -5,11 +5,11 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_check_version"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_health_check_version"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") -local cache_dict = ngx.shared.tlopsbalance; +local cache_dict = ngx.shared.tlopsbalance; local _M = { _VERSION = '0.02' diff --git a/limit/fuse/tl_ops_limit_fuse_leak_bucket.lua b/limit/fuse/tl_ops_limit_fuse_leak_bucket.lua index c76442c..d55e02d 100644 --- a/limit/fuse/tl_ops_limit_fuse_leak_bucket.lua +++ b/limit/fuse/tl_ops_limit_fuse_leak_bucket.lua @@ -4,13 +4,12 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse_leak_bucket"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse_leak_bucket"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") -local cache_limit = require("cache.tl_ops_cache"):new("tl-ops-limit"); - -local shared = ngx.shared.tlopsbalance +local cache_limit = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); +local shared = ngx.shared.tlopsbalance local _M = { _VERSION = '0.02' diff --git a/limit/fuse/tl_ops_limit_fuse_token_bucket.lua b/limit/fuse/tl_ops_limit_fuse_token_bucket.lua index 4af4dc8..d8fd5b0 100644 --- a/limit/fuse/tl_ops_limit_fuse_token_bucket.lua +++ b/limit/fuse/tl_ops_limit_fuse_token_bucket.lua @@ -4,13 +4,12 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse_token_bucket"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_fuse_token_bucket"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") -local cache_limit = require("cache.tl_ops_cache"):new("tl-ops-limit"); - -local shared = ngx.shared.tlopsbalance +local cache_limit = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); +local shared = ngx.shared.tlopsbalance local _M = { diff --git a/limit/tl_ops_limit.lua b/limit/tl_ops_limit.lua index 32bf7a2..070ad14 100644 --- a/limit/tl_ops_limit.lua +++ b/limit/tl_ops_limit.lua @@ -5,9 +5,9 @@ -- @email 1905333456@qq.com -local cache_limit = require("cache.tl_ops_cache"):new("tl-ops-limit"); +local cache_limit = require("cache.tl_ops_cache_core"):new("tl-ops-limit"); local tl_ops_constant_limit = require("constant.tl_ops_constant_limit") -local cjson = require("cjson"); +local cjson = require("cjson.safe"); -- 获取限流器 local tl_ops_limit_get_limiter = function( service_name, node_id ) diff --git a/limit/tl_ops_limit_leak_bucket.lua b/limit/tl_ops_limit_leak_bucket.lua index 52f8785..36ee25c 100644 --- a/limit/tl_ops_limit_leak_bucket.lua +++ b/limit/tl_ops_limit_leak_bucket.lua @@ -4,17 +4,11 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_leak_bucket"); +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_leak_bucket"); local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - - local _M = { _VERSION = '0.01' } diff --git a/limit/tl_ops_limit_sliding_window.lua b/limit/tl_ops_limit_sliding_window.lua index 449c599..aa4ce13 100644 --- a/limit/tl_ops_limit_sliding_window.lua +++ b/limit/tl_ops_limit_sliding_window.lua @@ -5,17 +5,11 @@ -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_sliding_window"); +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_sliding_window"); local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - - local _M = { _VERSION = '0.02' } diff --git a/limit/tl_ops_limit_token_bucket.lua b/limit/tl_ops_limit_token_bucket.lua index 8001e2b..c71c7cb 100644 --- a/limit/tl_ops_limit_token_bucket.lua +++ b/limit/tl_ops_limit_token_bucket.lua @@ -4,11 +4,11 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_token_bucket"); +local cjson = require("cjson.safe"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_limit_token_bucket"); local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local lock = require("lib.lock"); -local shared = ngx.shared.tlopsbalance +local lock = require("lib.lock"); +local shared = ngx.shared.tlopsbalance local _M = { diff --git a/plugins/tl_ops_api_authentication/tl_ops_plugin_core.lua b/plugins/tl_ops_api_authentication/tl_ops_plugin_core.lua deleted file mode 100644 index e85f30f..0000000 --- a/plugins/tl_ops_api_authentication/tl_ops_plugin_core.lua +++ /dev/null @@ -1,88 +0,0 @@ --- tl_ops_api_authentication --- en : api_authentication --- zn : 管理台权限身份认证插件 --- @author iamtsm --- @email 1905333456@qq.com - -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_api_authentication"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - - -local _M = {} - -_M._VERSION = '0.01' -_M.plugin = new_tab(0, 50) - - -local mt = { __index = _M } - - -function _M:new() - return setmetatable({}, mt) -end - - --- init_worker阶段执行plugin -function _M:tl_ops_process_init_worker() - - tlog:dbg("api_authentication plugin tl_ops_process_init_worker") - - - return true, "ok" -end - --- rewrite阶段执行plugin -function _M:tl_ops_process_init_rewrite() - - tlog:dbg("api_authentication plugin tl_ops_process_init_rewrite") - - return true, "ok" -end - --- access阶段执行plugin -function _M:tl_ops_process_init_access() - - tlog:dbg("api_authentication plugin tl_ops_process_init_access") - - return true, "ok" -end - --- content阶段执行plugin -function _M:tl_ops_process_init_content() - - tlog:dbg("api_authentication plugin tl_ops_process_init_content") - - return true, "ok" -end - --- header阶段执行plugin -function _M:tl_ops_process_init_header() - - tlog:dbg("api_authentication plugin tl_ops_process_init_header") - - return true, "ok" -end - --- body阶段执行plugin -function _M:tl_ops_process_init_body() - - tlog:dbg("api_authentication plugin tl_ops_process_init_body") - - return true, "ok" -end - --- log阶段执行plugin -function _M:tl_ops_process_init_log() - - tlog:dbg("api_authentication plugin tl_ops_process_init_log") - - return true, "ok" -end - - -return _M diff --git a/plugins/tl_ops_cluster_sync/tl_ops_plugin_core.lua b/plugins/tl_ops_cluster_sync/tl_ops_plugin_core.lua deleted file mode 100644 index 1d438fb..0000000 --- a/plugins/tl_ops_cluster_sync/tl_ops_plugin_core.lua +++ /dev/null @@ -1,86 +0,0 @@ --- tl_ops_plugin_cluster_sync --- en : cluster_sync --- zn : 集群数据同步插件 --- @author iamtsm --- @email 1905333456@qq.com - -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_cluster_sync"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - -local _M = { - _VERSION = '0.01' -} - -local mt = { __index = _M } - - -function _M:new(options) - local plugin = {} - return setmetatable(plugin, mt) -end - - --- init_worker阶段执行plugin -function _M:tl_ops_process_init_worker() - - tlog:dbg("cluster_sync plugin tl_ops_process_init_worker") - - - return true, "ok" -end - --- rewrite阶段执行plugin -function _M:tl_ops_process_init_rewrite() - - tlog:dbg("cluster_sync plugin tl_ops_process_init_rewrite") - - return true, "ok" -end - --- access阶段执行plugin -function _M:tl_ops_process_init_access() - - tlog:dbg("cluster_sync plugin tl_ops_process_init_access") - - return true, "ok" -end - --- content阶段执行plugin -function _M:tl_ops_process_init_content() - - tlog:dbg("cluster_sync plugin tl_ops_process_init_content") - - return true, "ok" -end - --- header阶段执行plugin -function _M:tl_ops_process_init_header() - - tlog:dbg("cluster_sync plugin tl_ops_process_init_header") - - return true, "ok" -end - --- body阶段执行plugin -function _M:tl_ops_process_init_body() - - tlog:dbg("cluster_sync plugin tl_ops_process_init_body") - - return true, "ok" -end - --- log阶段执行plugin -function _M:tl_ops_process_init_log() - - tlog:dbg("cluster_sync plugin tl_ops_process_init_log") - - return true, "ok" -end - - -return _M diff --git a/plugins/tl_ops_log_analyze/tl_ops_plugin_core.lua b/plugins/tl_ops_log_analyze/tl_ops_plugin_core.lua deleted file mode 100644 index 50f4c0c..0000000 --- a/plugins/tl_ops_log_analyze/tl_ops_plugin_core.lua +++ /dev/null @@ -1,86 +0,0 @@ --- tl_ops_plugin_log_analyze --- en : log_analyze --- zn : 日志分析统计插件 --- @author iamtsm --- @email 1905333456@qq.com - -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_log_analyze"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - -local _M = { - _VERSION = '0.01' -} - -local mt = { __index = _M } - - -function _M:new(options) - local plugin = {} - return setmetatable(plugin, mt) -end - - --- init_worker阶段执行plugin -function _M:tl_ops_process_init_worker() - - tlog:dbg("log_analyze plugin tl_ops_process_init_worker") - - - return true, "ok" -end - --- rewrite阶段执行plugin -function _M:tl_ops_process_init_rewrite() - - tlog:dbg("log_analyze plugin tl_ops_process_init_rewrite") - - return true, "ok" -end - --- access阶段执行plugin -function _M:tl_ops_process_init_access() - - tlog:dbg("log_analyze plugin tl_ops_process_init_access") - - return true, "ok" -end - --- content阶段执行plugin -function _M:tl_ops_process_init_content() - - tlog:dbg("log_analyze plugin tl_ops_process_init_content") - - return true, "ok" -end - --- header阶段执行plugin -function _M:tl_ops_process_init_header() - - tlog:dbg("log_analyze plugin tl_ops_process_init_header") - - return true, "ok" -end - --- body阶段执行plugin -function _M:tl_ops_process_init_body() - - tlog:dbg("log_analyze plugin tl_ops_process_init_body") - - return true, "ok" -end - --- log阶段执行plugin -function _M:tl_ops_process_init_log() - - tlog:dbg("log_analyze plugin tl_ops_process_init_log") - - return true, "ok" -end - - -return _M diff --git a/plugins/tl_ops_plugin.lua b/plugins/tl_ops_plugin.lua new file mode 100644 index 0000000..fc6a1b4 --- /dev/null +++ b/plugins/tl_ops_plugin.lua @@ -0,0 +1,188 @@ +-- tl_ops_plugin +-- en : plugin +-- zn : 插件模块 +-- @author iamtsm +-- @email 1905333456@qq.com + +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin") +local require = require +local tl_ops_manage_env = require("tl_ops_manage_env") +local tl_ops_utils_func = require("utils.tl_ops_utils_func") + + +local _M = { + _VERSION = '0.01' +} + +local mt = { __index = _M } + + +function _M:new() + local plugins = tl_ops_utils_func:new_tab(0, 50) + return setmetatable({plugins = plugins}, mt) +end + + +-- 获取所有插件 +function _M:tl_ops_process_get_plugins() + return self.plugins +end + +-- 插件加载器 +function _M:tl_ops_process_load_plugins() + local open = tl_ops_manage_env.plugin.open + if not open then + tlog:dbg("tl_ops_process_load_plugins close") + return + end + + local module = tl_ops_manage_env.plugin.module + if not module then + tlog:dbg("tl_ops_process_load_plugins no module") + return + end + + for i = 1, #module do + local name = module[i] + local status, plugin = pcall(require, "plugins.tl_ops_" .. name .. ".tl_ops_plugin_core") + if status then + if plugin and type(plugin) == 'table' then + if type(plugin.new) == 'function' then + table.insert(self.plugins, { + name = name, + func = plugin:new() + }) + else + tlog:dbg("tl_ops_process_load_plugins plugin no new func err, name=",name,",plugin=",plugin) + end + else + tlog:dbg("tl_ops_process_load_plugins plugin err, name=",name,",plugin=",plugin) + end + else + tlog:dbg("tl_ops_process_load_plugins status err, name=",name,",status=",status) + end + end + + tlog:dbg("tl_ops_process_load_plugins , module=",module,",plugin=",self.plugins) +end + + +-- init_worker阶段执行 +function _M:tl_ops_process_init_worker() + local lock_key = "tl_ops_plugin_process_worker_lock" + local lock_time = 5 + if not tl_ops_utils_func:tl_ops_worker_lock(lock_key, lock_time) then + return + end + + for i = 1, #self.plugins do + local plugin = self.plugins[i] + if type(plugin.func.tl_ops_process_init_worker) == 'function' then + local ok, _ = plugin.func:tl_ops_process_init_worker() + if not ok then + tlog:err("tl_ops_process_init_worker process err , name=",plugin.name, ", ",_) + else + tlog:dbg("tl_ops_process_init_worker process ok , name=",plugin.name, ", ",_) + end + end + end +end + + +-- rewrite阶段执行 +function _M:tl_ops_process_init_rewrite() + for i = 1, #self.plugins do + local plugin = self.plugins[i] + if type(plugin.func.tl_ops_process_init_rewrite) == 'function' then + local ok, _ = plugin.func:tl_ops_process_init_rewrite() + if not ok then + tlog:err("tl_ops_process_init_rewrite process err , name=",plugin.name, ", ",_) + else + tlog:dbg("tl_ops_process_init_rewrite process ok , name=",plugin.name, ", ",_) + end + end + end +end + + +-- access阶段执行 +function _M:tl_ops_process_init_access() + for i = 1, #self.plugins do + local plugin = self.plugins[i] + if type(plugin.func.tl_ops_process_init_access) == 'function' then + local ok, _ = plugin.func:tl_ops_process_init_access() + if not ok then + tlog:err("tl_ops_process_init_access process err , name=",plugin.name, ", ",_) + else + tlog:dbg("tl_ops_process_init_access process ok , name=",plugin.name, ", ",_) + end + end + end +end + + +-- content阶段执行 +function _M:tl_ops_process_init_content() + for i = 1, #self.plugins do + local plugin = self.plugins[i] + if type(plugin.func.tl_ops_process_init_content) == 'function' then + local ok, _ = plugin.func:tl_ops_process_init_content() + if not ok then + tlog:err("tl_ops_process_init_content process err , name=",plugin.name, ", ",_) + else + tlog:dbg("tl_ops_process_init_content process ok , name=",plugin.name, ", ",_) + end + end + end +end + + +-- header阶段执行 +function _M:tl_ops_process_init_header() + for i = 1, #self.plugins do + local plugin = self.plugins[i] + if type(plugin.func.tl_ops_process_init_header) == 'function' then + local ok, _ = plugin.func:tl_ops_process_init_header() + if not ok then + tlog:err("tl_ops_process_init_header process err , name=",plugin.name, ", ",_) + else + tlog:dbg("tl_ops_process_init_header process ok , name=",plugin.name, ", ",_) + end + end + end +end + + +-- body阶段执行 +function _M:tl_ops_process_init_body() + for i = 1, #self.plugins do + local plugin = self.plugins[i] + if type(plugin.func.tl_ops_process_init_body) == 'function' then + local ok, _ = plugin.func:tl_ops_process_init_body() + if not ok then + tlog:err("tl_ops_process_init_body process err , name=",plugin.name, ", ",_) + else + tlog:dbg("tl_ops_process_init_body process ok , name=",plugin.name, ", ",_) + end + end + end +end + + +-- log阶段执行 +function _M:tl_ops_process_init_log() + for i = 1, #self.plugins do + local plugin = self.plugins[i] + if type(plugin.func.tl_ops_process_init_log) == 'function' then + local ok, _ = plugin.func:tl_ops_process_init_log() + if not ok then + tlog:err("tl_ops_process_init_log process err , name=",plugin.name, ", ",_) + else + tlog:dbg("tl_ops_process_init_log process ok , name=",plugin.name, ", ",_) + end + end + end +end + + +return _M diff --git a/plugins/tl_ops_sync/sync.lua b/plugins/tl_ops_sync/sync.lua new file mode 100644 index 0000000..33c4cd4 --- /dev/null +++ b/plugins/tl_ops_sync/sync.lua @@ -0,0 +1,75 @@ +-- tl_ops_sync +-- en : sync data , load data to memory +-- zn : 同步数据接口,预热数据 +-- @author iamtsm +-- @email 1905333456@qq.com + +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_sync") +local sync_constant_fields = require("plugins.tl_ops_sync.sync_constant_fields") +local sync_constant_data = require("plugins.tl_ops_sync.sync_constant_data") +local sync_env = tlops.env.sync +local utils = tlops.utils +local shared = tlops.balance_shared + + +local _M = { + _VERSION = '0.01', +} +local mt = { __index = _M } + + +-- 核心逻辑 +local tl_ops_sync_timer = function(premature, args) + if premature then + return + end + + local sync_fields_env = sync_env.fields + if sync_fields_env.open then + local module = sync_fields_env.module + if module then + for i = 1, #module do + local res = sync_constant_fields:sync_constant_fields_module(module[i]); + tlog:dbg("sync_constant_fields , module=",module[i],",res=",res) + end + else + tlog:dbg("sync_constant_fields no module, module=",module) + end + end + + local sync_data_env = sync_env.data + if sync_data_env.open then + local module = sync_data_env.module + if module then + for i = 1, #module do + local res = sync_constant_data:sync_constant_data_module(module[i]); + tlog:dbg("sync_constant_data , module=",module[i],",res=",res) + end + else + tlog:dbg("sync_constant_data no module, module=",module) + end + end +end + + +-- 启动器 +function _M:tl_ops_sync_timer_start( ) + local lock_key = "tl_ops_plugin_sync_lock" + local lock_time = 5 + if not utils:tl_ops_worker_lock(lock_key, lock_time) then + return + end + + local ok, _ = ngx.timer.at(0, tl_ops_sync_timer, nil) + if not ok then + tlog:err("tl_ops_sync_timer start failed to run , create timer failed " ,_) + return nil + end +end + + +function _M:new() + return setmetatable({}, mt) +end + +return _M diff --git a/plugins/tl_ops_sync/sync_constant_data.lua b/plugins/tl_ops_sync/sync_constant_data.lua new file mode 100644 index 0000000..99f296a --- /dev/null +++ b/plugins/tl_ops_sync/sync_constant_data.lua @@ -0,0 +1,587 @@ +-- sync_constant_data +-- en : sync constant data to shared dict +-- zn : 同步在文件中的静态配置到共享内存中,和store的数据进行合并 +-- @author iamtsm +-- @email 1905333456@qq.com + +-- constant +local constant_service = tlops.constant.service +local constant_health = tlops.constant.health +local constant_limit = tlops.constant.limit +local constant_balance = tlops.constant.balance +local constant_balance_api = tlops.constant.balance_api +local constant_balance_param = tlops.constant.balance_param +local constant_balance_header = tlops.constant.balance_header +local constant_balance_cookie = tlops.constant.balance_cookie +local constant_waf = tlops.constant.waf +local constant_waf_ip = tlops.constant.waf_ip +local constant_waf_api = tlops.constant.waf_api +local constant_waf_cc = tlops.constant.waf_cc +local constant_waf_header = tlops.constant.waf_header +local constant_waf_cookie = tlops.constant.waf_cookie +local constant_waf_param = tlops.constant.waf_param +local tl_ops_rt = tlops.constant.comm.tl_ops_rt; +-- cache +local cache_service = tlops.cache.service +local cache_limit = tlops.cache.limit +local cache_health = tlops.cache.health +local cache_balance_api = tlops.cache.balance_api +local cache_balance_param = tlops.cache.balance_param +local cache_balance_header = tlops.cache.balance_header +local cache_balance_cookie = tlops.cache.balance_cookie +local cache_balance = tlops.cache.balance +local cache_waf_api = tlops.cache.waf_api +local cache_waf_ip = tlops.cache.waf_ip +local cache_waf_cookie = tlops.cache.waf_cookie +local cache_waf_header = tlops.cache.waf_header +local cache_waf_cc = tlops.cache.waf_cc +local cache_waf_param = tlops.cache.waf_param +local cache_waf = tlops.cache.waf +-- utils +local utils = tlops.utils +local cjson = require("cjson.safe"); +cjson.encode_empty_table_as_object(false) +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_sync_constant_data"); + + +local _M = { + _VERSION = '0.01' +} + + +-- 静态文件中的未同步到store的配置数据 +local sync_constant_data_need_sync = function (constant_data, store_data) + local add = {} + for i = 1, #constant_data do + local synced = false + for j = 1, #store_data do + if constant_data[i]['id'] == store_data[j]['id'] then + synced = true + break + end + end + if not synced then + table.insert(add, constant_data[i]) + end + end + return add +end + + +--+++++++++++++++路由策略数据同步合并,预热+++++++++++++++-- + + +-- api策略静态配置数据 +local sync_constant_data_balance_api = function () + local cache_key_list = constant_balance_api.cache_key.list + + local data_str, _ = cache_balance_api:get(cache_key_list); + if not data_str then + local res, _ = cache_balance_api:set(cache_key_list, cjson.encode(constant_balance.api.list)) + if not res then + tlog:err("sync_constant_data_balance_api new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_api new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_balance_api err, old=",data) + return tl_ops_rt.error + end + + -- 静态配置 + local constant_data = constant_balance.api.list + + -- 获取需要同步的配置 + local add_point = sync_constant_data_need_sync(constant_data.point, data.point) + for i = 1, #add_point do + table.insert(data.point, add_point[i]) + end + + -- 获取需要同步的配置 + local add_random = sync_constant_data_need_sync(constant_data.random, data.random) + for i = 1, #add_random do + table.insert(data.random, add_random[i]) + end + + local res = cache_balance_api:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_balance_api err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_api done, new=",data) + + return tl_ops_rt.ok +end + +-- cookie策略静态配置数据 +local sync_constant_data_balance_cookie = function () + local cache_key_list = constant_balance_cookie.cache_key.list + + local data_str, _ = cache_balance_cookie:get(cache_key_list); + if not data_str then + local res, _ = cache_balance_cookie:set(cache_key_list, cjson.encode(constant_balance.cookie.list)) + if not res then + tlog:err("sync_constant_data_balance_cookie new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_cookie new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_balance_cookie err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_cookie start, old=",data) + + -- 静态配置 + local constant_data = constant_balance.cookie.list + + -- 获取需要同步的配置 + local add_point = sync_constant_data_need_sync(constant_data.point, data.point) + for i = 1, #add_point do + table.insert(data.point, add_point[i]) + end + + -- 获取需要同步的配置 + local add_random = sync_constant_data_need_sync(constant_data.random, data.random) + for i = 1, #add_random do + table.insert(data.random, add_random[i]) + end + + local res = cache_balance_cookie:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_balance_cookie err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_cookie done, new=",data) + + return tl_ops_rt.ok +end + +-- header策略静态配置数据 +local sync_constant_data_balance_header = function () + local cache_key_list = constant_balance_header.cache_key.list + + local data_str, _ = cache_balance_header:get(cache_key_list); + if not data_str then + local res, _ = cache_balance_header:set(cache_key_list, cjson.encode(constant_balance.header.list)) + if not res then + tlog:err("sync_constant_data_balance_header new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_header new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_balance_header err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_header start, old=",data) + + -- 静态配置 + local constant_data = constant_balance.header.list + + -- 获取需要同步的配置 + local add_point = sync_constant_data_need_sync(constant_data.point, data.point) + for i = 1, #add_point do + table.insert(data.point, add_point[i]) + end + + -- 获取需要同步的配置 + local add_random = sync_constant_data_need_sync(constant_data.random, data.random) + for i = 1, #add_random do + table.insert(data.random, add_random[i]) + end + + local res = cache_balance_header:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_balance_header err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_header done, new=",data) + + return tl_ops_rt.ok +end + +-- param策略静态配置数据 +local sync_constant_data_balance_param = function () + local cache_key_list = constant_balance_param.cache_key.list + + local data_str, _ = cache_balance_param:get(cache_key_list); + if not data_str then + local res, _ = cache_balance_param:set(cache_key_list, cjson.encode(constant_balance.param.list)) + if not res then + tlog:err("sync_constant_data_balance_param new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_param new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_balance_param err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_param start, old=",data) + + -- 静态配置 + local constant_data = constant_balance.param.list + + -- 获取需要同步的配置 + local add_point = sync_constant_data_need_sync(constant_data.point, data.point) + for i = 1, #add_point do + table.insert(data.point, add_point[i]) + end + + -- 获取需要同步的配置 + local add_random = sync_constant_data_need_sync(constant_data.random, data.random) + for i = 1, #add_random do + table.insert(data.random, add_random[i]) + end + + local res = cache_balance_param:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_balance_param err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_balance_param done, new=",data) + + return tl_ops_rt.ok +end + + + +--+++++++++++++++WAF策略数据同步合并,预热+++++++++++++++-- + +-- waf ip策略静态配置数据 +local sync_constant_data_waf_ip = function () + local cache_key_list = constant_waf_ip.cache_key.list + + local data_str, _ = cache_waf_ip:get(cache_key_list); + if not data_str then + local res, _ = cache_waf_ip:set(cache_key_list, cjson.encode(constant_waf.ip.list)) + if not res then + tlog:err("sync_constant_data_waf_ip new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_ip new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_waf_ip err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_ip start, old=",data) + + -- 静态配置 + local constant_data = constant_waf.ip.list + + -- 获取需要同步的配置 + local add = sync_constant_data_need_sync(constant_data, data) + for i = 1, #add do + table.insert(data, add[i]) + end + + local res = cache_waf_ip:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_waf_ip err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_ip done, new=",data) + + return tl_ops_rt.ok +end + +-- waf api策略静态配置数据 +local sync_constant_data_waf_api = function () + local cache_key_list = constant_waf_api.cache_key.list + + local data_str, _ = cache_waf_api:get(cache_key_list); + if not data_str then + local res, _ = cache_waf_api:set(cache_key_list, cjson.encode(constant_waf.api.list)) + if not res then + tlog:err("sync_constant_data_waf_api new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_api new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_waf_api err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_api start, old=",data) + + -- 静态配置 + local constant_data = constant_waf.api.list + + -- 获取需要同步的配置 + local add = sync_constant_data_need_sync(constant_data, data) + for i = 1, #add do + table.insert(data, add[i]) + end + + local res = cache_waf_api:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_waf_api err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_api done, new=",data) + + return tl_ops_rt.ok +end + +-- waf cookie策略静态配置数据 +local sync_constant_data_waf_cookie = function () + local cache_key_list = constant_waf_cookie.cache_key.list + + local data_str, _ = cache_waf_cookie:get(cache_key_list); + if not data_str then + local res, _ = cache_waf_cookie:set(cache_key_list, cjson.encode(constant_waf.cookie.list)) + if not res then + tlog:err("sync_constant_data_waf_cookie new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_cookie new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_waf_cookie err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_cookie start, old=",data) + + -- 静态配置 + local constant_data = constant_waf.cookie.list + + -- 获取需要同步的配置 + local add = sync_constant_data_need_sync(constant_data, data) + for i = 1, #add do + table.insert(data, add[i]) + end + + local res = cache_waf_cookie:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_waf_cookie err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_cookie done, new=",data) + + return tl_ops_rt.ok +end + +-- waf header策略静态配置数据 +local sync_constant_data_waf_header = function () + local cache_key_list = constant_waf_header.cache_key.list + + local data_str, _ = cache_waf_header:get(cache_key_list); + if not data_str then + local res, _ = cache_waf_header:set(cache_key_list, cjson.encode(constant_waf.header.list)) + if not res then + tlog:err("sync_constant_data_waf_header new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_header new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_waf_header err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_header start, old=",data) + + -- 静态配置 + local constant_data = constant_waf.header.list + + -- 获取需要同步的配置 + local add = sync_constant_data_need_sync(constant_data, data) + for i = 1, #add do + table.insert(data, add[i]) + end + + local res = cache_waf_header:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_waf_header err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_header done, new=",data) + + return tl_ops_rt.ok +end + +-- waf param策略静态配置数据 +local sync_constant_data_waf_param = function () + local cache_key_list = constant_waf_param.cache_key.list + + local data_str, _ = cache_waf_param:get(cache_key_list); + if not data_str then + local res, _ = cache_waf_param:set(cache_key_list, cjson.encode(constant_waf.param.list)) + if not res then + tlog:err("sync_constant_data_waf_param new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_param new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_waf_param err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_param start, old=",data) + + -- 静态配置 + local constant_data = constant_waf.param.list + + -- 获取需要同步的配置 + local add = sync_constant_data_need_sync(constant_data, data) + for i = 1, #add do + table.insert(data, add[i]) + end + + local res = cache_waf_param:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_waf_param err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_param done, new=",data) + + return tl_ops_rt.ok +end + +-- waf cc策略静态配置数据 +local sync_constant_data_waf_cc = function () + local cache_key_list = constant_waf_cc.cache_key.list + + local data_str, _ = cache_waf_cc:get(cache_key_list); + if not data_str then + local res, _ = cache_waf_cc:set(cache_key_list, cjson.encode(constant_waf.cc.list)) + if not res then + tlog:err("sync_constant_data_waf_cc new store data err, res=",res) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_cc new store data, res=",res) + return tl_ops_rt.ok + end + + local data = cjson.decode(data_str); + if not data and type(data) ~= 'table' then + tlog:err("sync_constant_data_waf_cc err, old=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_cc start, old=",data) + + -- 静态配置 + local constant_data = constant_waf.cc.list + + -- 获取需要同步的配置 + local add = sync_constant_data_need_sync(constant_data, data) + for i = 1, #add do + table.insert(data, add[i]) + end + + local res = cache_waf_cc:set(cache_key_list, cjson.encode(data)) + if not res then + tlog:err("sync_constant_data_waf_cc err, res=",res,",new=",data) + return tl_ops_rt.error + end + + tlog:dbg("sync_constant_data_waf_cc done, new=",data) + + return tl_ops_rt.ok +end + + + + +function _M:sync_constant_data_module( module ) + + if module == 'balance-api' then + return sync_constant_data_balance_api() + end + + if module == 'balance-cookie' then + return sync_constant_data_balance_cookie() + end + + if module == 'balance-header' then + return sync_constant_data_balance_header() + end + + if module == 'balance-param' then + return sync_constant_data_balance_param() + end + + if module == 'waf-api' then + return sync_constant_data_waf_api() + end + + if module == 'waf-ip' then + return sync_constant_data_waf_ip() + end + + if module == 'waf-header' then + return sync_constant_data_waf_header() + end + + if module == 'waf-cookie' then + return sync_constant_data_waf_cookie() + end + + if module == 'waf-param' then + return sync_constant_data_waf_param() + end + + if module == 'waf-cc' then + return sync_constant_data_waf_cc() + end +end + + +return _M \ No newline at end of file diff --git a/sync/tl_ops_sync_constant_fields.lua b/plugins/tl_ops_sync/sync_constant_fields.lua similarity index 51% rename from sync/tl_ops_sync_constant_fields.lua rename to plugins/tl_ops_sync/sync_constant_fields.lua index 0298069..34c4253 100644 --- a/sync/tl_ops_sync_constant_fields.lua +++ b/plugins/tl_ops_sync/sync_constant_fields.lua @@ -1,109 +1,96 @@ --- tl_ops_sync_constant_fields +-- sync_constant_fields -- en : sync new fileds -- zn : 同步由于功能迭代引起的模块字段变更。 -- @author iamtsm -- @email 1905333456@qq.com -local cjson = require("cjson"); -cjson.encode_empty_table_as_object(false) - -- constant -local tl_ops_constant_service = require("constant.tl_ops_constant_service"); -local tl_ops_constant_health = require("constant.tl_ops_constant_health") -local tl_ops_constant_limit = require("constant.tl_ops_constant_limit"); - -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); -local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); -local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); -local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); - -local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); -local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); -local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); -local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); -local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); -local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); -local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); - +local constant_service = tlops.constant.service +local constant_health = tlops.constant.health +local constant_limit = tlops.constant.limit +local constant_balance = tlops.constant.balance +local constant_balance_api = tlops.constant.balance_api +local constant_balance_param = tlops.constant.balance_param +local constant_balance_header = tlops.constant.balance_header +local constant_balance_cookie = tlops.constant.balance_cookie +local constant_waf = tlops.constant.waf +local constant_waf_ip = tlops.constant.waf_ip +local constant_waf_api = tlops.constant.waf_api +local constant_waf_cc = tlops.constant.waf_cc +local constant_waf_header = tlops.constant.waf_header +local constant_waf_cookie = tlops.constant.waf_cookie +local constant_waf_param = tlops.constant.waf_param +local tl_ops_rt = tlops.constant.comm.tl_ops_rt; -- cache -local cache_service = require("cache.tl_ops_cache"):new("tl-ops-service"); -local cache_limit = require("cache.tl_ops_cache"):new("tl-ops-limit"); -local cache_health = require("cache.tl_ops_cache"):new("tl-ops-health"); - -local cache_balance_api = require("cache.tl_ops_cache"):new("tl-ops-balance-api"); -local cache_balance_param = require("cache.tl_ops_cache"):new("tl-ops-balance-param"); -local cache_balance_header = require("cache.tl_ops_cache"):new("tl-ops-balance-header"); -local cache_balance_cookie = require("cache.tl_ops_cache"):new("tl-ops-balance-cookie"); -local cache_balance = require("cache.tl_ops_cache"):new("tl-ops-balance"); - -local cache_waf_api = require("cache.tl_ops_cache"):new("tl-ops-waf-api"); -local cache_waf_ip = require("cache.tl_ops_cache"):new("tl-ops-waf-ip"); -local cache_waf_cookie = require("cache.tl_ops_cache"):new("tl-ops-waf-cookie"); -local cache_waf_header = require("cache.tl_ops_cache"):new("tl-ops-waf-header"); -local cache_waf_cc = require("cache.tl_ops_cache"):new("tl-ops-waf-cc"); -local cache_waf_param = require("cache.tl_ops_cache"):new("tl-ops-waf-param"); -local cache_waf = require("cache.tl_ops_cache"):new("tl-ops-waf"); - +local cache_service = tlops.cache.service +local cache_limit = tlops.cache.limit +local cache_health = tlops.cache.health +local cache_balance_api = tlops.cache.balance_api +local cache_balance_param = tlops.cache.balance_param +local cache_balance_header = tlops.cache.balance_header +local cache_balance_cookie = tlops.cache.balance_cookie +local cache_balance = tlops.cache.balance +local cache_waf_api = tlops.cache.waf_api +local cache_waf_ip = tlops.cache.waf_ip +local cache_waf_cookie = tlops.cache.waf_cookie +local cache_waf_header = tlops.cache.waf_header +local cache_waf_cc = tlops.cache.waf_cc +local cache_waf_param = tlops.cache.waf_param +local cache_waf = tlops.cache.waf -- utils -local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") -local tl_ops_health_check_version = require("health.tl_ops_health_check_version") -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_sync_constant_fields"); +local utils = tlops.utils +local tl_ops_limit_fuse_check_version = require("limit.fuse.tl_ops_limit_fuse_check_version") +local tl_ops_health_check_version = require("health.tl_ops_health_check_version") +local cjson = require("cjson.safe"); +cjson.encode_empty_table_as_object(false) +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_sync_constant_fields"); local _M = { _VERSION = '0.01' } -local mt = { __index = _M } - - -function _M:new( ) - return setmetatable({}, mt) -end --+++++++++++++++服务节点数据同步+++++++++++++++-- -- 服务节点数据同步 -local tl_ops_sync_constant_fields_service = function () +local sync_constant_fields_service = function () - local cache_key = tl_ops_constant_service.cache_key.service_list - local cache_rule_key = tl_ops_constant_service.cache_key.service_rule - local demo = tl_ops_constant_service.demo + local cache_key = constant_service.cache_key.service_list + local cache_rule_key = constant_service.cache_key.service_rule + local demo = constant_service.demo local data_str, _ = cache_service:get(cache_key); if not data_str then - local res, _ = cache_service:set(cache_key, cjson.encode(tl_ops_constant_service.list)) + local res, _ = cache_service:set(cache_key, cjson.encode(constant_service.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_service new store list err, res=",res) + tlog:err("sync_constant_fields_service new store list err, res=",res) return tl_ops_rt.error end data_str, _ = cache_service:get(cache_key); - tlog:dbg("tl_ops_sync_constant_fields_service new store data, res=",res) + tlog:dbg("sync_constant_fields_service new store data, res=",res) end local data_rule_str, _ = cache_service:get(cache_rule_key); if not data_rule_str then - local res, _ = cache_service:set(cache_rule_key, tl_ops_constant_service.rule.auto_load) + local res, _ = cache_service:set(cache_rule_key, constant_service.rule.auto_load) if not res then - tlog:err("tl_ops_sync_constant_fields_service new store rule err, res=",res) + tlog:err("sync_constant_fields_service new store rule err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_service new store rule, res=",res) + tlog:dbg("sync_constant_fields_service new store rule, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_service err, old=",data) + tlog:err("sync_constant_fields_service err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_service start, old=",data) + tlog:dbg("sync_constant_fields_service start, old=",data) local add_keys = {} @@ -126,11 +113,11 @@ local tl_ops_sync_constant_fields_service = function () local res = cache_service:set(cache_key, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_service err, res=",res,",new=",data) + tlog:err("sync_constant_fields_service err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_service done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_service done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end @@ -138,31 +125,31 @@ end --+++++++++++++++健康检查数据同步+++++++++++++++-- -- 健康检查数据同步 -local tl_ops_sync_constant_fields_health = function () +local sync_constant_fields_health = function () - local cache_key = tl_ops_constant_health.cache_key.options_list - local demo = tl_ops_constant_health.demo + local cache_key = constant_health.cache_key.options_list + local demo = constant_health.demo local data_str, _ = cache_health:get(cache_key); if not data_str then - local res, _ = cache_health:set(cache_key, cjson.encode(tl_ops_constant_health.options)) + local res, _ = cache_health:set(cache_key, cjson.encode(constant_health.options)) if not res then - tlog:err("tl_ops_sync_constant_fields_health new store err, res=",res) + tlog:err("sync_constant_fields_health new store err, res=",res) return tl_ops_rt.error end data_str, _ = cache_health:get(cache_key); - tlog:dbg("tl_ops_sync_constant_fields_health new store, res=",res) + tlog:dbg("sync_constant_fields_health new store, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_health err, old=",data) + tlog:err("sync_constant_fields_health err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_health start, old=",data) + tlog:dbg("sync_constant_fields_health start, old=",data) local add_keys = {} @@ -180,19 +167,19 @@ local tl_ops_sync_constant_fields_health = function () local res = cache_health:set(cache_key, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_health err, res=",res,",new=",data) + tlog:err("sync_constant_fields_health err, res=",res,",new=",data) return tl_ops_rt.error end - for i = 1, #tl_ops_constant_health.options do - local option = tl_ops_constant_health.options[i] + for i = 1, #constant_health.options do + local option = constant_health.options[i] local service_name = option.check_service_name if service_name then tl_ops_health_check_version.incr_service_version(service_name) end end - tlog:dbg("tl_ops_sync_constant_fields_health done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_health done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end @@ -200,30 +187,30 @@ end --+++++++++++++++限流熔断数据同步+++++++++++++++-- -- 熔断数据同步 -local tl_ops_sync_constant_fields_limit = function () - local cache_key = tl_ops_constant_limit.fuse.cache_key.options_list - local demo = tl_ops_constant_limit.fuse.demo +local sync_constant_fields_limit = function () + local cache_key = constant_limit.fuse.cache_key.options_list + local demo = constant_limit.fuse.demo local data_str, _ = cache_limit:get(cache_key); if not data_str then - local res, _ = cache_limit:set(cache_key, cjson.encode(tl_ops_constant_limit.fuse.options)) + local res, _ = cache_limit:set(cache_key, cjson.encode(constant_limit.fuse.options)) if not res then - tlog:err("tl_ops_sync_constant_fields_limit new store err, res=",res) + tlog:err("sync_constant_fields_limit new store err, res=",res) return tl_ops_rt.error end data_str, _ = cache_limit:get(cache_key); - tlog:dbg("tl_ops_sync_constant_fields_limit new store, res=",res) + tlog:dbg("sync_constant_fields_limit new store, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_limit err, old=",data) + tlog:err("sync_constant_fields_limit err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_limit start, old=",data) + tlog:dbg("sync_constant_fields_limit start, old=",data) local add_keys = {} @@ -241,48 +228,48 @@ local tl_ops_sync_constant_fields_limit = function () local res = cache_limit:set(cache_key, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_limit err, res=",res,",new=",data) + tlog:err("sync_constant_fields_limit err, res=",res,",new=",data) return tl_ops_rt.error end - for i = 1, #tl_ops_constant_limit.fuse.options do - local option = tl_ops_constant_limit.fuse.options[i] + for i = 1, #constant_limit.fuse.options do + local option = constant_limit.fuse.options[i] local service_name = option.service_name if service_name then tl_ops_limit_fuse_check_version.incr_service_version(service_name) end end - tlog:dbg("tl_ops_sync_constant_fields_limit done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_limit done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- 限流数据同步 token -local tl_ops_sync_constant_fields_limit_token = function () - local cache_key = tl_ops_constant_limit.token.cache_key.options_list - local demo = tl_ops_constant_limit.token.demo +local sync_constant_fields_limit_token = function () + local cache_key = constant_limit.token.cache_key.options_list + local demo = constant_limit.token.demo local data_str, _ = cache_limit:get(cache_key); if not data_str then - local res, _ = cache_limit:set(cache_key, cjson.encode(tl_ops_constant_limit.token.options)) + local res, _ = cache_limit:set(cache_key, cjson.encode(constant_limit.token.options)) if not res then - tlog:err("tl_ops_sync_constant_fields_limit_token new store err, res=",res) + tlog:err("sync_constant_fields_limit_token new store err, res=",res) return tl_ops_rt.error end data_str, _ = cache_limit:get(cache_key); - tlog:dbg("tl_ops_sync_constant_fields_limit_token new store, res=",res) + tlog:dbg("sync_constant_fields_limit_token new store, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_limit_token err, old=",data) + tlog:err("sync_constant_fields_limit_token err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_limit_token start, old=",data) + tlog:dbg("sync_constant_fields_limit_token start, old=",data) local add_keys = {} @@ -300,48 +287,48 @@ local tl_ops_sync_constant_fields_limit_token = function () local res = cache_limit:set(cache_key, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_limit_token err, res=",res,",new=",data) + tlog:err("sync_constant_fields_limit_token err, res=",res,",new=",data) return tl_ops_rt.error end - for i = 1, #tl_ops_constant_limit.fuse.options do - local option = tl_ops_constant_limit.fuse.options[i] + for i = 1, #constant_limit.fuse.options do + local option = constant_limit.fuse.options[i] local service_name = option.service_name if service_name then tl_ops_limit_fuse_check_version.incr_service_version(service_name) end end - tlog:dbg("tl_ops_sync_constant_fields_limit_token done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_limit_token done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- 限流数据同步 leak -local tl_ops_sync_constant_fields_limit_leak = function () - local cache_key = tl_ops_constant_limit.leak.cache_key.options_list - local demo = tl_ops_constant_limit.leak.demo +local sync_constant_fields_limit_leak = function () + local cache_key = constant_limit.leak.cache_key.options_list + local demo = constant_limit.leak.demo local data_str, _ = cache_limit:get(cache_key); if not data_str then - local res, _ = cache_limit:set(cache_key, cjson.encode(tl_ops_constant_limit.leak.options)) + local res, _ = cache_limit:set(cache_key, cjson.encode(constant_limit.leak.options)) if not res then - tlog:err("tl_ops_sync_constant_fields_limit_leak new store err, res=",res) + tlog:err("sync_constant_fields_limit_leak new store err, res=",res) return tl_ops_rt.error end data_str, _ = cache_limit:get(cache_key); - tlog:dbg("tl_ops_sync_constant_fields_limit_leak new store, res=",res) + tlog:dbg("sync_constant_fields_limit_leak new store, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_limit_leak err, old=",data) + tlog:err("sync_constant_fields_limit_leak err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_limit_leak start, old=",data) + tlog:dbg("sync_constant_fields_limit_leak start, old=",data) local add_keys = {} @@ -357,8 +344,8 @@ local tl_ops_sync_constant_fields_limit_leak = function () end end - for i = 1, #tl_ops_constant_limit.fuse.options do - local option = tl_ops_constant_limit.fuse.options[i] + for i = 1, #constant_limit.fuse.options do + local option = constant_limit.fuse.options[i] local service_name = option.service_name if service_name then tl_ops_limit_fuse_check_version.incr_service_version(service_name) @@ -367,11 +354,11 @@ local tl_ops_sync_constant_fields_limit_leak = function () local res = cache_limit:set(cache_key, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_limit_leak err, res=",res,",new=",data) + tlog:err("sync_constant_fields_limit_leak err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_limit_leak done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_limit_leak done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end @@ -379,31 +366,31 @@ end --+++++++++++++++路由数据同步+++++++++++++++-- -- 路由配置数据同步 -local tl_ops_sync_constant_fields_balance = function () +local sync_constant_fields_balance = function () - local cache_key = tl_ops_constant_balance.cache_key.options - local demo = tl_ops_constant_balance.demo + local cache_key = constant_balance.cache_key.options + local demo = constant_balance.demo local data_str, _ = cache_balance:get(cache_key); if not data_str then - local res, _ = cache_balance:set(cache_key, cjson.encode(tl_ops_constant_balance.options)) + local res, _ = cache_balance:set(cache_key, cjson.encode(constant_balance.options)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance new store err, res=",res) + tlog:err("sync_constant_fields_balance new store err, res=",res) return tl_ops_rt.error end data_str, _ = cache_balance:get(cache_key); - tlog:dbg("tl_ops_sync_constant_fields_balance new store, res=",res) + tlog:dbg("sync_constant_fields_balance new store, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_balance err, old=",data) + tlog:err("sync_constant_fields_balance err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance start, old=",data) + tlog:dbg("sync_constant_fields_balance start, old=",data) local add_keys = {} @@ -419,53 +406,53 @@ local tl_ops_sync_constant_fields_balance = function () local res = cache_balance:set(cache_key, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance err, res=",res,",new=",data) + tlog:err("sync_constant_fields_balance err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_balance done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- api策略数据同步 -local tl_ops_sync_constant_fields_balance_api = function () - local cache_key_list = tl_ops_constant_balance_api.cache_key.list; - local cache_key_rule = tl_ops_constant_balance_api.cache_key.rule +local sync_constant_fields_balance_api = function () + local cache_key_list = constant_balance_api.cache_key.list; + local cache_key_rule = constant_balance_api.cache_key.rule - local demo = tl_ops_constant_balance_api.demo + local demo = constant_balance_api.demo local data_str, _ = cache_balance_api:get(cache_key_list); if not data_str then - local res, _ = cache_balance_api:set(cache_key_list, cjson.encode(tl_ops_constant_balance.api.list)) + local res, _ = cache_balance_api:set(cache_key_list, cjson.encode(constant_balance.api.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_api new store data err, res=",res) + tlog:err("sync_constant_fields_balance_api new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_balance_api:get(cache_key_list) - tlog:dbg("tl_ops_sync_constant_fields_balance_api new store data, res=",res) + tlog:dbg("sync_constant_fields_balance_api new store data, res=",res) end local data_rule_str, _ = cache_balance_api:get(cache_key_rule); if not data_rule_str then - local res, _ = cache_balance_api:set(cache_key_rule, tl_ops_constant_balance.api.rule) + local res, _ = cache_balance_api:set(cache_key_rule, constant_balance.api.rule) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_api new store rule err, res=",res) + tlog:err("sync_constant_fields_balance_api new store rule err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_api new store rule, res=",res) + tlog:dbg("sync_constant_fields_balance_api new store rule, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_balance_api err, old=",data) + tlog:err("sync_constant_fields_balance_api err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_api start, old=",data) + tlog:dbg("sync_constant_fields_balance_api start, old=",data) local add_keys = {} @@ -499,53 +486,53 @@ local tl_ops_sync_constant_fields_balance_api = function () local res = cache_balance_api:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_api err, res=",res,",new=",data) + tlog:err("sync_constant_fields_balance_api err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_api done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_balance_api done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- cookie策略数据同步 -local tl_ops_sync_constant_fields_balance_cookie = function () - local cache_key_list = tl_ops_constant_balance_cookie.cache_key.list - local cache_key_rule = tl_ops_constant_balance_cookie.cache_key.rule +local sync_constant_fields_balance_cookie = function () + local cache_key_list = constant_balance_cookie.cache_key.list + local cache_key_rule = constant_balance_cookie.cache_key.rule - local demo = tl_ops_constant_balance_cookie.demo + local demo = constant_balance_cookie.demo local data_str, _ = cache_balance_cookie:get(cache_key_list); if not data_str then - local res, _ = cache_balance_cookie:set(cache_key_list, cjson.encode(tl_ops_constant_balance.cookie.list)) + local res, _ = cache_balance_cookie:set(cache_key_list, cjson.encode(constant_balance.cookie.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_cookie new store data err, res=",res) + tlog:err("sync_constant_fields_balance_cookie new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_balance_cookie:get(cache_key_list); - tlog:dbg("tl_ops_sync_constant_fields_balance_cookie new store data, res=",res) + tlog:dbg("sync_constant_fields_balance_cookie new store data, res=",res) end local data_rule_str, _ = cache_balance_cookie:get(cache_key_rule); if not data_rule_str then - local res, _ = cache_balance_cookie:set(cache_key_rule, tl_ops_constant_balance.cookie.rule) + local res, _ = cache_balance_cookie:set(cache_key_rule, constant_balance.cookie.rule) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_cookie new store rule err, res=",res) + tlog:err("sync_constant_fields_balance_cookie new store rule err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_api new store rule, res=",res) + tlog:dbg("sync_constant_fields_balance_api new store rule, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_balance_cookie err, old=",data) + tlog:err("sync_constant_fields_balance_cookie err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_cookie start, old=",data) + tlog:dbg("sync_constant_fields_balance_cookie start, old=",data) local add_keys = {} @@ -579,54 +566,54 @@ local tl_ops_sync_constant_fields_balance_cookie = function () local res = cache_balance_cookie:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_cookie err, res=",res,",new=",data) + tlog:err("sync_constant_fields_balance_cookie err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_cookie done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_balance_cookie done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- header策略数据同步 -local tl_ops_sync_constant_fields_balance_header = function () - local cache_key_list = tl_ops_constant_balance_header.cache_key.list - local cache_key_rule = tl_ops_constant_balance_header.cache_key.rule +local sync_constant_fields_balance_header = function () + local cache_key_list = constant_balance_header.cache_key.list + local cache_key_rule = constant_balance_header.cache_key.rule - local demo = tl_ops_constant_balance_header.demo + local demo = constant_balance_header.demo local data_str, _ = cache_balance_header:get(cache_key_list); if not data_str then - local res, _ = cache_balance_header:set(cache_key_list, cjson.encode(tl_ops_constant_balance.header.list)) + local res, _ = cache_balance_header:set(cache_key_list, cjson.encode(constant_balance.header.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_header new store data err, res=",res) + tlog:err("sync_constant_fields_balance_header new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_balance_header:get(cache_key_list); - tlog:dbg("tl_ops_sync_constant_fields_balance_header new store data, res=",res) + tlog:dbg("sync_constant_fields_balance_header new store data, res=",res) end local data_rule_str, _ = cache_balance_header:get(cache_key_rule); if not data_rule_str then - local res, _ = cache_balance_header:set(cache_key_rule, tl_ops_constant_balance.header.rule) + local res, _ = cache_balance_header:set(cache_key_rule, constant_balance.header.rule) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_header new store rule err, res=",res) + tlog:err("sync_constant_fields_balance_header new store rule err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_header new store rule, res=",res) + tlog:dbg("sync_constant_fields_balance_header new store rule, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_balance_header err, old=",data) + tlog:err("sync_constant_fields_balance_header err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_header start, old=",data) + tlog:dbg("sync_constant_fields_balance_header start, old=",data) local add_keys = {} @@ -660,53 +647,53 @@ local tl_ops_sync_constant_fields_balance_header = function () local res = cache_balance_header:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_header err, res=",res,",new=",data) + tlog:err("sync_constant_fields_balance_header err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_header done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_balance_header done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- param策略数据同步 -local tl_ops_sync_constant_fields_balance_param = function () - local cache_key_list = tl_ops_constant_balance_param.cache_key.list - local cache_key_rule = tl_ops_constant_balance_param.cache_key.rule +local sync_constant_fields_balance_param = function () + local cache_key_list = constant_balance_param.cache_key.list + local cache_key_rule = constant_balance_param.cache_key.rule - local demo = tl_ops_constant_balance_param.demo + local demo = constant_balance_param.demo local data_str, _ = cache_balance_param:get(cache_key_list); if not data_str then - local res, _ = cache_balance_param:set(cache_key_list, cjson.encode(tl_ops_constant_balance.param.list)) + local res, _ = cache_balance_param:set(cache_key_list, cjson.encode(constant_balance.param.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_param new store data err, res=",res) + tlog:err("sync_constant_fields_balance_param new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_balance_param:get(cache_key_list); - tlog:dbg("tl_ops_sync_constant_fields_balance_param new store data, res=",res) + tlog:dbg("sync_constant_fields_balance_param new store data, res=",res) end local data_rule_str, _ = cache_balance_param:get(cache_key_rule); if not data_rule_str then - local res, _ = cache_balance_param:set(cache_key_rule, tl_ops_constant_balance.param.rule) + local res, _ = cache_balance_param:set(cache_key_rule, constant_balance.param.rule) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_param new store rule err, res=",res) + tlog:err("sync_constant_fields_balance_param new store rule err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_param new store rule, res=",res) + tlog:dbg("sync_constant_fields_balance_param new store rule, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_balance_param err, old=",data) + tlog:err("sync_constant_fields_balance_param err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_param start, old=",data) + tlog:dbg("sync_constant_fields_balance_param start, old=",data) local add_keys = {} @@ -740,11 +727,11 @@ local tl_ops_sync_constant_fields_balance_param = function () local res = cache_balance_param:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_balance_param err, res=",res,",new=",data) + tlog:err("sync_constant_fields_balance_param err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_balance_param done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_balance_param done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end @@ -752,31 +739,31 @@ end --+++++++++++++++WAF数据同步+++++++++++++++-- -- waf配置数据同步 -local tl_ops_sync_constant_fields_waf = function () - tlog:dbg("xxxx : ",tl_ops_constant_waf) - local cache_key = tl_ops_constant_waf.cache_key.options - local demo = tl_ops_constant_waf.demo +local sync_constant_fields_waf = function () + tlog:dbg("xxxx : ",constant_waf) + local cache_key = constant_waf.cache_key.options + local demo = constant_waf.demo local data_str, _ = cache_waf:get(cache_key); if not data_str then - local res, _ = cache_waf:set(cache_key, cjson.encode(tl_ops_constant_waf.options)) + local res, _ = cache_waf:set(cache_key, cjson.encode(constant_waf.options)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf new store err, res=",res) + tlog:err("sync_constant_fields_waf new store err, res=",res) return tl_ops_rt.error end data_str, _ = cache_waf:get(cache_key); - tlog:dbg("tl_ops_sync_constant_fields_waf new store, res=",res) + tlog:dbg("sync_constant_fields_waf new store, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_waf err, old=",data) + tlog:err("sync_constant_fields_waf err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf start, old=",data) + tlog:dbg("sync_constant_fields_waf start, old=",data) local add_keys = {} @@ -792,65 +779,65 @@ local tl_ops_sync_constant_fields_waf = function () local res = cache_waf:set(cache_key, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf err, res=",res,",new=",data) + tlog:err("sync_constant_fields_waf err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_waf done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- api waf规则数据同步 -local tl_ops_sync_constant_fields_waf_api = function () - local cache_key_list = tl_ops_constant_waf_api.cache_key.list; - local cache_key_scope = tl_ops_constant_waf_api.cache_key.scope - local cache_key_open = tl_ops_constant_waf_api.cache_key.open +local sync_constant_fields_waf_api = function () + local cache_key_list = constant_waf_api.cache_key.list; + local cache_key_scope = constant_waf_api.cache_key.scope + local cache_key_open = constant_waf_api.cache_key.open - local demo = tl_ops_constant_waf_api.demo + local demo = constant_waf_api.demo local data_str, _ = cache_waf_api:get(cache_key_list); if not data_str then - local res, _ = cache_waf_api:set(cache_key_list, cjson.encode(tl_ops_constant_waf.api.list)) + local res, _ = cache_waf_api:set(cache_key_list, cjson.encode(constant_waf.api.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_api new store data err, res=",res) + tlog:err("sync_constant_fields_waf_api new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_waf_api:get(cache_key_list) - tlog:dbg("tl_ops_sync_constant_fields_waf_api new store data, res=",res) + tlog:dbg("sync_constant_fields_waf_api new store data, res=",res) end local data_scope, _ = cache_waf_api:get(cache_key_scope); if not data_scope then - local res, _ = cache_waf_api:set(cache_key_scope, tl_ops_constant_waf.api.scope) + local res, _ = cache_waf_api:set(cache_key_scope, constant_waf.api.scope) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_api new store scope err, res=",res) + tlog:err("sync_constant_fields_waf_api new store scope err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_api new store scope, res=",res) + tlog:dbg("sync_constant_fields_waf_api new store scope, res=",res) end local data_open, _ = cache_waf_api:get(cache_key_open); if not data_open then - local res, _ = cache_waf_api:set(cache_key_open, tl_ops_constant_waf.api.open) + local res, _ = cache_waf_api:set(cache_key_open, constant_waf.api.open) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_api new store open err, res=",res) + tlog:err("sync_constant_fields_waf_api new store open err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_api new store open, res=",res) + tlog:dbg("sync_constant_fields_waf_api new store open, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_waf_api err, old=",data) + tlog:err("sync_constant_fields_waf_api err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_api start, old=",data) + tlog:dbg("sync_constant_fields_waf_api start, old=",data) local add_keys = {} @@ -870,65 +857,65 @@ local tl_ops_sync_constant_fields_waf_api = function () local res = cache_waf_api:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_api err, res=",res,",new=",data) + tlog:err("sync_constant_fields_waf_api err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_api done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_waf_api done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- ip waf规则数据同步 -local tl_ops_sync_constant_fields_waf_ip = function () - local cache_key_list = tl_ops_constant_waf_ip.cache_key.list; - local cache_key_scope = tl_ops_constant_waf_ip.cache_key.scope - local cache_key_open = tl_ops_constant_waf_ip.cache_key.open +local sync_constant_fields_waf_ip = function () + local cache_key_list = constant_waf_ip.cache_key.list; + local cache_key_scope = constant_waf_ip.cache_key.scope + local cache_key_open = constant_waf_ip.cache_key.open - local demo = tl_ops_constant_waf_ip.demo + local demo = constant_waf_ip.demo local data_str, _ = cache_waf_ip:get(cache_key_list); if not data_str then - local res, _ = cache_waf_ip:set(cache_key_list, cjson.encode(tl_ops_constant_waf.ip.list)) + local res, _ = cache_waf_ip:set(cache_key_list, cjson.encode(constant_waf.ip.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_ip new store data err, res=",res) + tlog:err("sync_constant_fields_waf_ip new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_waf_ip:get(cache_key_list) - tlog:dbg("tl_ops_sync_constant_fields_waf_ip new store data, res=",res) + tlog:dbg("sync_constant_fields_waf_ip new store data, res=",res) end local data_scope, _ = cache_waf_ip:get(cache_key_scope); if not data_scope then - local res, _ = cache_waf_ip:set(cache_key_scope, tl_ops_constant_waf.ip.scope) + local res, _ = cache_waf_ip:set(cache_key_scope, constant_waf.ip.scope) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_ip new store scope err, res=",res) + tlog:err("sync_constant_fields_waf_ip new store scope err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_ip new store scope, res=",res) + tlog:dbg("sync_constant_fields_waf_ip new store scope, res=",res) end local data_open, _ = cache_waf_ip:get(cache_key_open); if not data_open then - local res, _ = cache_waf_ip:set(cache_key_open, tl_ops_constant_waf.ip.open) + local res, _ = cache_waf_ip:set(cache_key_open, constant_waf.ip.open) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_ip new store open err, res=",res) + tlog:err("sync_constant_fields_waf_ip new store open err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_ip new store open, res=",res) + tlog:dbg("sync_constant_fields_waf_ip new store open, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_waf_ip err, old=",data) + tlog:err("sync_constant_fields_waf_ip err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_ip start, old=",data) + tlog:dbg("sync_constant_fields_waf_ip start, old=",data) local add_keys = {} @@ -948,65 +935,65 @@ local tl_ops_sync_constant_fields_waf_ip = function () local res = cache_waf_ip:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_ip err, res=",res,",new=",data) + tlog:err("sync_constant_fields_waf_ip err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_ip done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_waf_ip done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- cookie waf规则数据同步 -local tl_ops_sync_constant_fields_waf_cookie = function () - local cache_key_list = tl_ops_constant_waf_cookie.cache_key.list; - local cache_key_scope = tl_ops_constant_waf_cookie.cache_key.scope - local cache_key_open = tl_ops_constant_waf_cookie.cache_key.open +local sync_constant_fields_waf_cookie = function () + local cache_key_list = constant_waf_cookie.cache_key.list; + local cache_key_scope = constant_waf_cookie.cache_key.scope + local cache_key_open = constant_waf_cookie.cache_key.open - local demo = tl_ops_constant_waf_cookie.demo + local demo = constant_waf_cookie.demo local data_str, _ = cache_waf_cookie:get(cache_key_list); if not data_str then - local res, _ = cache_waf_cookie:set(cache_key_list, cjson.encode(tl_ops_constant_waf.cookie.list)) + local res, _ = cache_waf_cookie:set(cache_key_list, cjson.encode(constant_waf.cookie.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cookie new store data err, res=",res) + tlog:err("sync_constant_fields_waf_cookie new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_waf_cookie:get(cache_key_list) - tlog:dbg("tl_ops_sync_constant_fields_waf_cookie new store data, res=",res) + tlog:dbg("sync_constant_fields_waf_cookie new store data, res=",res) end local data_scope, _ = cache_waf_cookie:get(cache_key_scope); if not data_scope then - local res, _ = cache_waf_cookie:set(cache_key_scope, tl_ops_constant_waf.cookie.scope) + local res, _ = cache_waf_cookie:set(cache_key_scope, constant_waf.cookie.scope) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cookie new store scope err, res=",res) + tlog:err("sync_constant_fields_waf_cookie new store scope err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cookie new store scope, res=",res) + tlog:dbg("sync_constant_fields_waf_cookie new store scope, res=",res) end local data_open, _ = cache_waf_cookie:get(cache_key_open); if not data_open then - local res, _ = cache_waf_cookie:set(cache_key_open, tl_ops_constant_waf.cookie.open) + local res, _ = cache_waf_cookie:set(cache_key_open, constant_waf.cookie.open) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cookie new store open err, res=",res) + tlog:err("sync_constant_fields_waf_cookie new store open err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cookie new store open, res=",res) + tlog:dbg("sync_constant_fields_waf_cookie new store open, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_waf_cookie err, old=",data) + tlog:err("sync_constant_fields_waf_cookie err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cookie start, old=",data) + tlog:dbg("sync_constant_fields_waf_cookie start, old=",data) local add_keys = {} @@ -1026,65 +1013,65 @@ local tl_ops_sync_constant_fields_waf_cookie = function () local res = cache_waf_cookie:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cookie err, res=",res,",new=",data) + tlog:err("sync_constant_fields_waf_cookie err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cookie done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_waf_cookie done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- header waf规则数据同步 -local tl_ops_sync_constant_fields_waf_header = function () - local cache_key_list = tl_ops_constant_waf_header.cache_key.list; - local cache_key_scope = tl_ops_constant_waf_header.cache_key.scope - local cache_key_open = tl_ops_constant_waf_header.cache_key.open +local sync_constant_fields_waf_header = function () + local cache_key_list = constant_waf_header.cache_key.list; + local cache_key_scope = constant_waf_header.cache_key.scope + local cache_key_open = constant_waf_header.cache_key.open - local demo = tl_ops_constant_waf_header.demo + local demo = constant_waf_header.demo local data_str, _ = cache_waf_header:get(cache_key_list); if not data_str then - local res, _ = cache_waf_header:set(cache_key_list, cjson.encode(tl_ops_constant_waf.header.list)) + local res, _ = cache_waf_header:set(cache_key_list, cjson.encode(constant_waf.header.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_header new store data err, res=",res) + tlog:err("sync_constant_fields_waf_header new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_waf_header:get(cache_key_list) - tlog:dbg("tl_ops_sync_constant_fields_waf_header new store data, res=",res) + tlog:dbg("sync_constant_fields_waf_header new store data, res=",res) end local data_scope, _ = cache_waf_header:get(cache_key_scope); if not data_scope then - local res, _ = cache_waf_header:set(cache_key_scope, tl_ops_constant_waf.header.scope) + local res, _ = cache_waf_header:set(cache_key_scope, constant_waf.header.scope) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_header new store scope err, res=",res) + tlog:err("sync_constant_fields_waf_header new store scope err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_header new store scope, res=",res) + tlog:dbg("sync_constant_fields_waf_header new store scope, res=",res) end local data_open, _ = cache_waf_header:get(cache_key_open); if not data_open then - local res, _ = cache_waf_header:set(cache_key_open, tl_ops_constant_waf.header.open) + local res, _ = cache_waf_header:set(cache_key_open, constant_waf.header.open) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_header new store open err, res=",res) + tlog:err("sync_constant_fields_waf_header new store open err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_header new store open, res=",res) + tlog:dbg("sync_constant_fields_waf_header new store open, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_waf_header err, old=",data) + tlog:err("sync_constant_fields_waf_header err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_header start, old=",data) + tlog:dbg("sync_constant_fields_waf_header start, old=",data) local add_keys = {} @@ -1104,65 +1091,65 @@ local tl_ops_sync_constant_fields_waf_header = function () local res = cache_waf_header:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_header err, res=",res,",new=",data) + tlog:err("sync_constant_fields_waf_header err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_header done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_waf_header done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- param waf规则数据同步 -local tl_ops_sync_constant_fields_waf_param = function () - local cache_key_list = tl_ops_constant_waf_param.cache_key.list; - local cache_key_scope = tl_ops_constant_waf_param.cache_key.scope - local cache_key_open = tl_ops_constant_waf_param.cache_key.open +local sync_constant_fields_waf_param = function () + local cache_key_list = constant_waf_param.cache_key.list; + local cache_key_scope = constant_waf_param.cache_key.scope + local cache_key_open = constant_waf_param.cache_key.open - local demo = tl_ops_constant_waf_param.demo + local demo = constant_waf_param.demo local data_str, _ = cache_waf_param:get(cache_key_list); if not data_str then - local res, _ = cache_waf_param:set(cache_key_list, cjson.encode(tl_ops_constant_waf.param.list)) + local res, _ = cache_waf_param:set(cache_key_list, cjson.encode(constant_waf.param.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_param new store data err, res=",res) + tlog:err("sync_constant_fields_waf_param new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_waf_param:get(cache_key_list) - tlog:dbg("tl_ops_sync_constant_fields_waf_param new store data, res=",res) + tlog:dbg("sync_constant_fields_waf_param new store data, res=",res) end local data_scope, _ = cache_waf_param:get(cache_key_scope); if not data_scope then - local res, _ = cache_waf_param:set(cache_key_scope, tl_ops_constant_waf.param.scope) + local res, _ = cache_waf_param:set(cache_key_scope, constant_waf.param.scope) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_param new store scope err, res=",res) + tlog:err("sync_constant_fields_waf_param new store scope err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_param new store scope, res=",res) + tlog:dbg("sync_constant_fields_waf_param new store scope, res=",res) end local data_open, _ = cache_waf_param:get(cache_key_open); if not data_open then - local res, _ = cache_waf_param:set(cache_key_open, tl_ops_constant_waf.param.open) + local res, _ = cache_waf_param:set(cache_key_open, constant_waf.param.open) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_param new store open err, res=",res) + tlog:err("sync_constant_fields_waf_param new store open err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_param new store open, res=",res) + tlog:dbg("sync_constant_fields_waf_param new store open, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_waf_param err, old=",data) + tlog:err("sync_constant_fields_waf_param err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_param start, old=",data) + tlog:dbg("sync_constant_fields_waf_param start, old=",data) local add_keys = {} @@ -1182,65 +1169,65 @@ local tl_ops_sync_constant_fields_waf_param = function () local res = cache_waf_param:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_param err, res=",res,",new=",data) + tlog:err("sync_constant_fields_waf_param err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_param done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_waf_param done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -- cc waf规则数据同步 -local tl_ops_sync_constant_fields_waf_cc = function () - local cache_key_list = tl_ops_constant_waf_cc.cache_key.list; - local cache_key_scope = tl_ops_constant_waf_cc.cache_key.scope - local cache_key_open = tl_ops_constant_waf_cc.cache_key.open +local sync_constant_fields_waf_cc = function () + local cache_key_list = constant_waf_cc.cache_key.list; + local cache_key_scope = constant_waf_cc.cache_key.scope + local cache_key_open = constant_waf_cc.cache_key.open - local demo = tl_ops_constant_waf_cc.demo + local demo = constant_waf_cc.demo local data_str, _ = cache_waf_cc:get(cache_key_list); if not data_str then - local res, _ = cache_waf_cc:set(cache_key_list, cjson.encode(tl_ops_constant_waf.cc.list)) + local res, _ = cache_waf_cc:set(cache_key_list, cjson.encode(constant_waf.cc.list)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cc new store data err, res=",res) + tlog:err("sync_constant_fields_waf_cc new store data err, res=",res) return tl_ops_rt.error end data_str, _ = cache_waf_cc:get(cache_key_list) - tlog:dbg("tl_ops_sync_constant_fields_waf_cc new store data, res=",res) + tlog:dbg("sync_constant_fields_waf_cc new store data, res=",res) end local data_scope, _ = cache_waf_cc:get(cache_key_scope); if not data_scope then - local res, _ = cache_waf_cc:set(cache_key_scope, tl_ops_constant_waf.cc.scope) + local res, _ = cache_waf_cc:set(cache_key_scope, constant_waf.cc.scope) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cc new store scope err, res=",res) + tlog:err("sync_constant_fields_waf_cc new store scope err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cc new store scope, res=",res) + tlog:dbg("sync_constant_fields_waf_cc new store scope, res=",res) end local data_open, _ = cache_waf_cc:get(cache_key_open); if not data_open then - local res, _ = cache_waf_cc:set(cache_key_open, tl_ops_constant_waf.cc.open) + local res, _ = cache_waf_cc:set(cache_key_open, constant_waf.cc.open) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cc new store open err, res=",res) + tlog:err("sync_constant_fields_waf_cc new store open err, res=",res) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cc new store open, res=",res) + tlog:dbg("sync_constant_fields_waf_cc new store open, res=",res) end local data = cjson.decode(data_str); if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_fields_waf_cc err, old=",data) + tlog:err("sync_constant_fields_waf_cc err, old=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cc start, old=",data) + tlog:dbg("sync_constant_fields_waf_cc start, old=",data) local add_keys = {} @@ -1260,85 +1247,85 @@ local tl_ops_sync_constant_fields_waf_cc = function () local res = cache_waf_cc:set(cache_key_list, cjson.encode(data)) if not res then - tlog:err("tl_ops_sync_constant_fields_waf_cc err, res=",res,",new=",data) + tlog:err("sync_constant_fields_waf_cc err, res=",res,",new=",data) return tl_ops_rt.error end - tlog:dbg("tl_ops_sync_constant_fields_waf_cc done, new=",data,",add_keys=",add_keys) + tlog:dbg("sync_constant_fields_waf_cc done, new=",data,",add_keys=",add_keys) return tl_ops_rt.ok end -function _M:tl_ops_sync_constant_fields_module( module ) +function _M:sync_constant_fields_module( module ) if module == 'service' then - return tl_ops_sync_constant_fields_service() + return sync_constant_fields_service() end if module == 'health' then - return tl_ops_sync_constant_fields_health() + return sync_constant_fields_health() end if module == 'limit-fuse' then - return tl_ops_sync_constant_fields_limit() + return sync_constant_fields_limit() end if module == 'limit-token' then - return tl_ops_sync_constant_fields_limit_token() + return sync_constant_fields_limit_token() end if module == 'limit-leak' then - return tl_ops_sync_constant_fields_limit_leak() + return sync_constant_fields_limit_leak() end if module == 'balance' then - return tl_ops_sync_constant_fields_balance() + return sync_constant_fields_balance() end if module == 'balance-api' then - return tl_ops_sync_constant_fields_balance_api() + return sync_constant_fields_balance_api() end if module == 'balance-cookie' then - return tl_ops_sync_constant_fields_balance_cookie() + return sync_constant_fields_balance_cookie() end if module == 'balance-header' then - return tl_ops_sync_constant_fields_balance_header() + return sync_constant_fields_balance_header() end if module == 'balance-param' then - return tl_ops_sync_constant_fields_balance_param() + return sync_constant_fields_balance_param() end if module == 'waf' then - return tl_ops_sync_constant_fields_waf() + return sync_constant_fields_waf() end if module == 'waf-api' then - return tl_ops_sync_constant_fields_waf_api() + return sync_constant_fields_waf_api() end if module == 'waf-ip' then - return tl_ops_sync_constant_fields_waf_ip() + return sync_constant_fields_waf_ip() end if module == 'waf-header' then - return tl_ops_sync_constant_fields_waf_header() + return sync_constant_fields_waf_header() end if module == 'waf-cookie' then - return tl_ops_sync_constant_fields_waf_cookie() + return sync_constant_fields_waf_cookie() end if module == 'waf-param' then - return tl_ops_sync_constant_fields_waf_param() + return sync_constant_fields_waf_param() end if module == 'waf-cc' then - return tl_ops_sync_constant_fields_waf_cc() + return sync_constant_fields_waf_cc() end end diff --git a/plugins/tl_ops_sync/tl_ops_plugin_core.lua b/plugins/tl_ops_sync/tl_ops_plugin_core.lua new file mode 100644 index 0000000..99b502f --- /dev/null +++ b/plugins/tl_ops_sync/tl_ops_plugin_core.lua @@ -0,0 +1,33 @@ +-- tl_ops_plugin_sync +-- en : sync +-- zn : 同步器插件 +-- @author iamtsm +-- @email 1905333456@qq.com + +local plugin_sync = require("plugins.tl_ops_sync.sync"); + +local _M = { + _VERSION = '0.01' +} + +local mt = { __index = _M } + + +function _M:new(options) + if not options then + options = {} + end + return setmetatable(options, mt) +end + + +-- init_worker阶段执行plugin +function _M:tl_ops_process_init_worker() + + -- 启动同步器 + plugin_sync:tl_ops_sync_timer_start() + + return true, "ok" +end + +return _M diff --git a/plugins/tl_ops_template/tl_ops_plugin_core.lua b/plugins/tl_ops_template/tl_ops_plugin_core.lua index d8a4df5..3f004ef 100644 --- a/plugins/tl_ops_template/tl_ops_plugin_core.lua +++ b/plugins/tl_ops_template/tl_ops_plugin_core.lua @@ -7,11 +7,6 @@ local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_template"); local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - local _M = { _VERSION = '0.01' } @@ -20,8 +15,10 @@ local mt = { __index = _M } function _M:new(options) - local plugin = {} - return setmetatable(plugin, mt) + if not options then + options = {} + end + return setmetatable(options, mt) end diff --git a/sync/tl_ops_sync.lua b/sync/tl_ops_sync.lua deleted file mode 100644 index 96ec033..0000000 --- a/sync/tl_ops_sync.lua +++ /dev/null @@ -1,19 +0,0 @@ --- tl_ops_sync --- en : sync data/fields --- zn : 同步数据接口 --- @author iamtsm --- @email 1905333456@qq.com - -local tl_ops_sync_core = require("sync.tl_ops_sync_core"); - -local _M = {} - - -function _M:init( ) - -- 启动同步器 - local sync = tl_ops_sync_core:new() - sync:tl_ops_sync_timer_start() -end - - -return _M diff --git a/sync/tl_ops_sync_constant_data.lua b/sync/tl_ops_sync_constant_data.lua deleted file mode 100644 index 552ba2d..0000000 --- a/sync/tl_ops_sync_constant_data.lua +++ /dev/null @@ -1,589 +0,0 @@ --- tl_ops_sync_constant_data --- en : sync constant data to shared dict --- zn : 同步在文件中的静态配置到共享内存中,和store的数据进行合并 --- @author iamtsm --- @email 1905333456@qq.com - -local cjson = require("cjson"); -cjson.encode_empty_table_as_object(false) - --- balance -local tl_ops_constant_balance = require("constant.tl_ops_constant_balance"); -local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api"); -local tl_ops_constant_balance_param = require("constant.tl_ops_constant_balance_param"); -local tl_ops_constant_balance_header = require("constant.tl_ops_constant_balance_header"); -local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie"); -local cache_balance_api = require("cache.tl_ops_cache"):new("tl-ops-balance-api"); -local cache_balance_param = require("cache.tl_ops_cache"):new("tl-ops-balance-param"); -local cache_balance_header = require("cache.tl_ops_cache"):new("tl-ops-balance-header"); -local cache_balance_cookie = require("cache.tl_ops_cache"):new("tl-ops-balance-cookie"); - - --- waf -local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); -local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); -local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); -local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); -local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); -local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); -local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); -local cache_waf_api = require("cache.tl_ops_cache"):new("tl-ops-waf-api"); -local cache_waf_ip = require("cache.tl_ops_cache"):new("tl-ops-waf-ip"); -local cache_waf_cookie = require("cache.tl_ops_cache"):new("tl-ops-waf-cookie"); -local cache_waf_header = require("cache.tl_ops_cache"):new("tl-ops-waf-header"); -local cache_waf_cc = require("cache.tl_ops_cache"):new("tl-ops-waf-cc"); -local cache_waf_param = require("cache.tl_ops_cache"):new("tl-ops-waf-param"); - --- utils -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_sync_constant_data"); - - -local _M = { - _VERSION = '0.01' -} -local mt = { __index = _M } - - -function _M:new( ) - return setmetatable({}, mt) -end - - --- 静态文件中的未同步到store的配置数据 -local tl_ops_sync_constant_data_need_sync = function (constant_data, store_data) - local add = {} - for i = 1, #constant_data do - local synced = false - for j = 1, #store_data do - if constant_data[i]['id'] == store_data[j]['id'] then - synced = true - break - end - end - if not synced then - table.insert(add, constant_data[i]) - end - end - return add -end - - ---+++++++++++++++路由策略数据同步合并,预热+++++++++++++++-- - - --- api策略静态配置数据 -local tl_ops_sync_constant_data_balance_api = function () - local cache_key_list = tl_ops_constant_balance_api.cache_key.list - - local data_str, _ = cache_balance_api:get(cache_key_list); - if not data_str then - local res, _ = cache_balance_api:set(cache_key_list, cjson.encode(tl_ops_constant_balance.api.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_api new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_api new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_balance_api err, old=",data) - return tl_ops_rt.error - end - - -- 静态配置 - local constant_data = tl_ops_constant_balance.api.list - - -- 获取需要同步的配置 - local add_point = tl_ops_sync_constant_data_need_sync(constant_data.point, data.point) - for i = 1, #add_point do - table.insert(data.point, add_point[i]) - end - - -- 获取需要同步的配置 - local add_random = tl_ops_sync_constant_data_need_sync(constant_data.random, data.random) - for i = 1, #add_random do - table.insert(data.random, add_random[i]) - end - - local res = cache_balance_api:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_api err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_api done, new=",data) - - return tl_ops_rt.ok -end - --- cookie策略静态配置数据 -local tl_ops_sync_constant_data_balance_cookie = function () - local cache_key_list = tl_ops_constant_balance_cookie.cache_key.list - - local data_str, _ = cache_balance_cookie:get(cache_key_list); - if not data_str then - local res, _ = cache_balance_cookie:set(cache_key_list, cjson.encode(tl_ops_constant_balance.cookie.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_cookie new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_cookie new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_balance_cookie err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_cookie start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_balance.cookie.list - - -- 获取需要同步的配置 - local add_point = tl_ops_sync_constant_data_need_sync(constant_data.point, data.point) - for i = 1, #add_point do - table.insert(data.point, add_point[i]) - end - - -- 获取需要同步的配置 - local add_random = tl_ops_sync_constant_data_need_sync(constant_data.random, data.random) - for i = 1, #add_random do - table.insert(data.random, add_random[i]) - end - - local res = cache_balance_cookie:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_cookie err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_cookie done, new=",data) - - return tl_ops_rt.ok -end - --- header策略静态配置数据 -local tl_ops_sync_constant_data_balance_header = function () - local cache_key_list = tl_ops_constant_balance_header.cache_key.list - - local data_str, _ = cache_balance_header:get(cache_key_list); - if not data_str then - local res, _ = cache_balance_header:set(cache_key_list, cjson.encode(tl_ops_constant_balance.header.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_header new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_header new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_balance_header err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_header start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_balance.header.list - - -- 获取需要同步的配置 - local add_point = tl_ops_sync_constant_data_need_sync(constant_data.point, data.point) - for i = 1, #add_point do - table.insert(data.point, add_point[i]) - end - - -- 获取需要同步的配置 - local add_random = tl_ops_sync_constant_data_need_sync(constant_data.random, data.random) - for i = 1, #add_random do - table.insert(data.random, add_random[i]) - end - - local res = cache_balance_header:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_header err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_header done, new=",data) - - return tl_ops_rt.ok -end - --- param策略静态配置数据 -local tl_ops_sync_constant_data_balance_param = function () - local cache_key_list = tl_ops_constant_balance_param.cache_key.list - - local data_str, _ = cache_balance_param:get(cache_key_list); - if not data_str then - local res, _ = cache_balance_param:set(cache_key_list, cjson.encode(tl_ops_constant_balance.param.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_param new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_param new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_balance_param err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_param start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_balance.param.list - - -- 获取需要同步的配置 - local add_point = tl_ops_sync_constant_data_need_sync(constant_data.point, data.point) - for i = 1, #add_point do - table.insert(data.point, add_point[i]) - end - - -- 获取需要同步的配置 - local add_random = tl_ops_sync_constant_data_need_sync(constant_data.random, data.random) - for i = 1, #add_random do - table.insert(data.random, add_random[i]) - end - - local res = cache_balance_param:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_balance_param err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_balance_param done, new=",data) - - return tl_ops_rt.ok -end - - - ---+++++++++++++++WAF策略数据同步合并,预热+++++++++++++++-- - --- waf ip策略静态配置数据 -local tl_ops_sync_constant_data_waf_ip = function () - local cache_key_list = tl_ops_constant_waf_ip.cache_key.list - - local data_str, _ = cache_waf_ip:get(cache_key_list); - if not data_str then - local res, _ = cache_waf_ip:set(cache_key_list, cjson.encode(tl_ops_constant_waf.ip.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_ip new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_ip new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_waf_ip err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_ip start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_waf.ip.list - - -- 获取需要同步的配置 - local add = tl_ops_sync_constant_data_need_sync(constant_data, data) - for i = 1, #add do - table.insert(data, add[i]) - end - - local res = cache_waf_ip:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_ip err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_ip done, new=",data) - - return tl_ops_rt.ok -end - --- waf api策略静态配置数据 -local tl_ops_sync_constant_data_waf_api = function () - local cache_key_list = tl_ops_constant_waf_api.cache_key.list - - local data_str, _ = cache_waf_api:get(cache_key_list); - if not data_str then - local res, _ = cache_waf_api:set(cache_key_list, cjson.encode(tl_ops_constant_waf.api.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_api new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_api new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_waf_api err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_api start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_waf.api.list - - -- 获取需要同步的配置 - local add = tl_ops_sync_constant_data_need_sync(constant_data, data) - for i = 1, #add do - table.insert(data, add[i]) - end - - local res = cache_waf_api:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_api err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_api done, new=",data) - - return tl_ops_rt.ok -end - --- waf cookie策略静态配置数据 -local tl_ops_sync_constant_data_waf_cookie = function () - local cache_key_list = tl_ops_constant_waf_cookie.cache_key.list - - local data_str, _ = cache_waf_cookie:get(cache_key_list); - if not data_str then - local res, _ = cache_waf_cookie:set(cache_key_list, cjson.encode(tl_ops_constant_waf.cookie.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_cookie new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_cookie new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_waf_cookie err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_cookie start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_waf.cookie.list - - -- 获取需要同步的配置 - local add = tl_ops_sync_constant_data_need_sync(constant_data, data) - for i = 1, #add do - table.insert(data, add[i]) - end - - local res = cache_waf_cookie:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_cookie err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_cookie done, new=",data) - - return tl_ops_rt.ok -end - --- waf header策略静态配置数据 -local tl_ops_sync_constant_data_waf_header = function () - local cache_key_list = tl_ops_constant_waf_header.cache_key.list - - local data_str, _ = cache_waf_header:get(cache_key_list); - if not data_str then - local res, _ = cache_waf_header:set(cache_key_list, cjson.encode(tl_ops_constant_waf.header.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_header new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_header new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_waf_header err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_header start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_waf.header.list - - -- 获取需要同步的配置 - local add = tl_ops_sync_constant_data_need_sync(constant_data, data) - for i = 1, #add do - table.insert(data, add[i]) - end - - local res = cache_waf_header:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_header err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_header done, new=",data) - - return tl_ops_rt.ok -end - --- waf param策略静态配置数据 -local tl_ops_sync_constant_data_waf_param = function () - local cache_key_list = tl_ops_constant_waf_param.cache_key.list - - local data_str, _ = cache_waf_param:get(cache_key_list); - if not data_str then - local res, _ = cache_waf_param:set(cache_key_list, cjson.encode(tl_ops_constant_waf.param.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_param new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_param new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_waf_param err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_param start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_waf.param.list - - -- 获取需要同步的配置 - local add = tl_ops_sync_constant_data_need_sync(constant_data, data) - for i = 1, #add do - table.insert(data, add[i]) - end - - local res = cache_waf_param:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_param err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_param done, new=",data) - - return tl_ops_rt.ok -end - --- waf cc策略静态配置数据 -local tl_ops_sync_constant_data_waf_cc = function () - local cache_key_list = tl_ops_constant_waf_cc.cache_key.list - - local data_str, _ = cache_waf_cc:get(cache_key_list); - if not data_str then - local res, _ = cache_waf_cc:set(cache_key_list, cjson.encode(tl_ops_constant_waf.cc.list)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_cc new store data err, res=",res) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_cc new store data, res=",res) - return tl_ops_rt.ok - end - - local data = cjson.decode(data_str); - if not data and type(data) ~= 'table' then - tlog:err("tl_ops_sync_constant_data_waf_cc err, old=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_cc start, old=",data) - - -- 静态配置 - local constant_data = tl_ops_constant_waf.cc.list - - -- 获取需要同步的配置 - local add = tl_ops_sync_constant_data_need_sync(constant_data, data) - for i = 1, #add do - table.insert(data, add[i]) - end - - local res = cache_waf_cc:set(cache_key_list, cjson.encode(data)) - if not res then - tlog:err("tl_ops_sync_constant_data_waf_cc err, res=",res,",new=",data) - return tl_ops_rt.error - end - - tlog:dbg("tl_ops_sync_constant_data_waf_cc done, new=",data) - - return tl_ops_rt.ok -end - - - - -function _M:tl_ops_sync_constant_data_module( module ) - - if module == 'balance-api' then - return tl_ops_sync_constant_data_balance_api() - end - - if module == 'balance-cookie' then - return tl_ops_sync_constant_data_balance_cookie() - end - - if module == 'balance-header' then - return tl_ops_sync_constant_data_balance_header() - end - - if module == 'balance-param' then - return tl_ops_sync_constant_data_balance_param() - end - - if module == 'waf-api' then - return tl_ops_sync_constant_data_waf_api() - end - - if module == 'waf-ip' then - return tl_ops_sync_constant_data_waf_ip() - end - - if module == 'waf-header' then - return tl_ops_sync_constant_data_waf_header() - end - - if module == 'waf-cookie' then - return tl_ops_sync_constant_data_waf_cookie() - end - - if module == 'waf-param' then - return tl_ops_sync_constant_data_waf_param() - end - - if module == 'waf-cc' then - return tl_ops_sync_constant_data_waf_cc() - end -end - - -return _M \ No newline at end of file diff --git a/sync/tl_ops_sync_core.lua b/sync/tl_ops_sync_core.lua deleted file mode 100644 index d4c5164..0000000 --- a/sync/tl_ops_sync_core.lua +++ /dev/null @@ -1,83 +0,0 @@ --- tl_ops_sync --- en : sync data , load data to memory --- zn : 同步数据接口,预热数据 --- @author iamtsm --- @email 1905333456@qq.com - -local tl_ops_sync_constant_fields = require("sync.tl_ops_sync_constant_fields"):new(); -local tl_ops_sync_constant_data = require("sync.tl_ops_sync_constant_data"):new(); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_sync"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local tl_ops_manage_env = require("tl_ops_manage_env") -local sync_env = tl_ops_manage_env.sync - -local lock = require("lib.lock"); -local shared = ngx.shared.tlopsbalance; - - -local _M = { - _VERSION = '0.01', -} -local mt = { __index = _M } - - --- 核心逻辑 -local tl_ops_sync_timer = function(premature, args) - if premature then - return - end - - local sync_fields_data = {} - local sync_fields_env = sync_env.fields - if sync_fields_env.open then - local module = sync_fields_env.module - if module then - for i = 1, #module do - local res = tl_ops_sync_constant_fields:tl_ops_sync_constant_fields_module(module[i]); - sync_fields_data[module[i]] = res - tlog:dbg("tl_ops_sync_constant_fields , module=",module[i],",res=",res) - end - else - tlog:dbg("tl_ops_sync_constant_fields no module, module=",module) - end - end - - local sync_constant_data = {} - local sync_data_env = sync_env.data - if sync_data_env.open then - local module = sync_data_env.module - if module then - for i = 1, #module do - local res = tl_ops_sync_constant_data:tl_ops_sync_constant_data_module(module[i]); - sync_fields_data[module[i]] = res - tlog:dbg("tl_ops_sync_constant_data , module=",module[i],",res=",res) - end - else - tlog:dbg("tl_ops_sync_constant_data no module, module=",module) - end - end -end - - --- 启动器 -function _M:tl_ops_sync_timer_start( ) - local lock_key = "tl_ops_sync_lock" - local lock_time = 5 - if not tl_ops_utils_func:tl_ops_worker_lock(lock_key, lock_time) then - return - end - - local ok, _ = ngx.timer.at(0, tl_ops_sync_timer, nil) - if not ok then - tlog:err("tl_ops_sync_timer start failed to run , create timer failed " ,_) - return nil - end -end - - -function _M:new() - return setmetatable({}, mt) -end - -return _M diff --git a/tl_ops_manage.lua b/tl_ops_manage.lua index b3fb27c..469f324 100644 --- a/tl_ops_manage.lua +++ b/tl_ops_manage.lua @@ -4,103 +4,118 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_manage"); - - -local _M = {} -_M._VERSION = '0.01' +-- module +local m_health = require("health.tl_ops_health") +local m_limit_fuse = require("limit.fuse.tl_ops_limit_fuse") +local m_balance_count = require("balance.count.tl_ops_balance_count") +local m_plugin = require("plugins.tl_ops_plugin"):new() +local m_waf = require("waf.tl_ops_waf") +local m_waf_count = require("waf.count.tl_ops_waf_count") +local m_api = require("api.tl_ops_api") +local m_balance = require("balance.tl_ops_balance") + +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_manage"); +local utils = require("utils.tl_ops_utils_func"); +local env = require("tl_ops_manage_env") +local constant = require("constant.tl_ops_constant") +local cache = require("cache.tl_ops_cache") +local tlops_api = require("api.tl_ops_api_core") +local balance_shared = ngx.shared.tlopsbalance +local plugin_shared = ngx.shared.tlopsplugin +local waf_shared = ngx.shared.tlopswaf + + +local _M = { + env = env, + cache = cache, + utils = utils, + constant = constant, + plugins = {}, + tlops_api = tlops_api, + waf_shared = waf_shared, + plugin_shared = plugin_shared, + balance_shared = balance_shared, +} -- init阶段执行 function _M:tl_ops_process_init() + -- 加载所有插件 + m_plugin:tl_ops_process_load_plugins(); + _M.plugins = m_plugin:tl_ops_process_get_plugins() end -- init_worker阶段执行 function _M:tl_ops_process_init_worker() - -- 启动健康检查 - require("health.tl_ops_health"):init(); + m_health:init(); -- 启动限流熔断 - require("limit.fuse.tl_ops_limit_fuse"):init(); + m_limit_fuse:init(); -- 启动路由统计 - require("balance.count.tl_ops_balance_count"):init(); - - -- 启动数据同步/预热 - require("sync.tl_ops_sync"):init(); - - -- 加载插件 - require("tl_ops_plugin"):tl_ops_process_init_worker(); + m_balance_count:init(); + + -- 启动waf统计 + m_waf_count:init(); + -- 执行插件 + m_plugin:tl_ops_process_init_worker(); end -- rewrite阶段执行 function _M:tl_ops_process_init_rewrite() - -- 启动waf - local scope = require("constant.tl_ops_constant_waf_scope"); - require("waf.tl_ops_waf"):init(scope.global); - - -- 加载插件 - require("tl_ops_plugin"):tl_ops_process_init_rewrite(); + m_waf:init(constant.waf_scope.global); + -- 执行插件 + m_plugin:tl_ops_process_init_rewrite(); end -- access阶段执行 function _M:tl_ops_process_init_access() - -- 加载api - require("api.tl_ops_api"):init(); + m_api:init(); -- 启动负载均衡 - require("balance.tl_ops_balance"):init(); - - -- 加载插件 - require("tl_ops_plugin"):tl_ops_process_init_access(); + m_balance:init(); + -- 执行插件 + m_plugin:tl_ops_process_init_access(); end -- content阶段执行 function _M:tl_ops_process_init_content() - - -- 加载插件 - require("tl_ops_plugin"):tl_ops_process_init_content(); - + -- 执行插件 + m_plugin:tl_ops_process_init_content(); end -- header阶段执行 function _M:tl_ops_process_init_header() - - -- 加载插件 - require("tl_ops_plugin"):tl_ops_process_init_header(); - + -- 执行插件 + m_plugin:tl_ops_process_init_header(); end -- body阶段执行 function _M:tl_ops_process_init_body() - - -- 加载插件 - require("tl_ops_plugin"):tl_ops_process_init_body(); - + -- 执行插件 + m_plugin:tl_ops_process_init_body(); end -- log阶段执行 function _M:tl_ops_process_init_log() - - -- 加载插件 - require("tl_ops_plugin"):tl_ops_process_init_log(); - + -- 执行插件 + m_plugin:tl_ops_process_init_log(); end diff --git a/tl_ops_manage_env.lua b/tl_ops_manage_env.lua index c84d464..86e326f 100644 --- a/tl_ops_manage_env.lua +++ b/tl_ops_manage_env.lua @@ -20,14 +20,14 @@ return { zn :日志输出目录,所有模块的日志都将输出到此目录下,注意:需要填写 ‘绝对路径’ ]] - log_dir = "F:/code/tl-open-source/tl-ops-manage/", + log_dir = "/path/to/tl-open-source/tl-ops-manage/", --[[ en :data storage directory, the directory where the module data is stored, Notice: need to fill in the 'absolute path' zn :数据存放目录,模块的数据存放的目录,注意:需要填写 ‘绝对路径’ ]] - store_dir = "F:/code/tl-open-source/tl-ops-manage/store/", + store_dir = "/path/to/tl-open-source/tl-ops-manage/store/", }, cache = { --[[ @@ -35,7 +35,7 @@ return { zn :是否开启redis缓存,注意,开启此选项需要先安装redis。 ]] - redis = true + redis = false }, sync = { fields = { @@ -165,7 +165,7 @@ return { zn :插件模块定义,引入的插件需要在此定义好才能被加载。否则将不生效 ]] module = { - "log_analyze", "api_authentication", "cluster_sync","template" + "template", "sync" } } } diff --git a/tl_ops_plugin.lua b/tl_ops_plugin.lua deleted file mode 100644 index 26f29ee..0000000 --- a/tl_ops_plugin.lua +++ /dev/null @@ -1,213 +0,0 @@ --- tl_ops_plugin --- en : plugin --- zn : 插件模块 --- @author iamtsm --- @email 1905333456@qq.com - -local tl_ops_manage_env = require("tl_ops_manage_env"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); - -local ok, new_tab = pcall(require, "table.new") -if not ok or type(new_tab) ~= "function" then - new_tab = function (narr, nrec) return {} end -end - - -local _M = { - _VERSION = '0.01' -} - -local mt = { __index = _M } - - -function _M:new(options) - local plugin = {} - return setmetatable(plugin, mt) -end - - --- 插件加载器 -local tl_ops_process_load_plugins = function() - local plugin = new_tab(0, 50) - - local open = tl_ops_manage_env.plugin.open - if not open then - tlog:dbg("tl_ops_process_load_plugins close") - return - end - - local module = tl_ops_manage_env.plugin.module - if not module then - tlog:dbg("tl_ops_process_load_plugins no module") - return - end - - for i = 1, #module do - local name = module[i] - local plug = require("plugins.tl_ops_" .. name .. ".tl_ops_plugin_core") - table.insert(plugin, { - name = name, - func = plug - }) - end - - tlog:dbg("tl_ops_process_load_plugins , module=",module,",plugin=",plugin) - - return plugin -end - - --- init_worker阶段执行 -function _M:tl_ops_process_init_worker() - local lock_key = "tl_ops_plugin_process_worker_lock" - local lock_time = 5 - if not tl_ops_utils_func:tl_ops_worker_lock(lock_key, lock_time) then - return - end - - local plugins = tl_ops_process_load_plugins() - - for i = 1, #plugins do - local plugin = plugins[i] - if type(plugin.func) == 'table' then - local ok, _ = plugin.func:new():tl_ops_process_init_worker() - if not ok then - tlog:dbg("tl_ops_process_init_worker process err , name=",plugin.name, ", ",_) - else - tlog:dbg("tl_ops_process_init_worker process ok , name=",plugin.name, ", ",_) - end - else - tlog:dbg("tl_ops_process_init_worker not func err , name=",plugin.name, ", ",_) - end - end -end - - --- rewrite阶段执行 -function _M:tl_ops_process_init_rewrite() - - local plugins = tl_ops_process_load_plugins() - - for i = 1, #plugins do - local plugin = plugins[i] - if type(plugin.func) == 'table' then - local ok, _ = plugin.func:new():tl_ops_process_init_rewrite() - if not ok then - tlog:dbg("tl_ops_process_init_rewrite process err , name=",plugin.name, ", ",_) - else - tlog:dbg("tl_ops_process_init_rewrite process ok , name=",plugin.name, ", ",_) - end - else - tlog:dbg("tl_ops_process_init_rewrite not func err , name=",plugin.name, ", ",_) - end - end -end - - --- access阶段执行 -function _M:tl_ops_process_init_access() - - local plugins = tl_ops_process_load_plugins() - - for i = 1, #plugins do - local plugin = plugins[i] - if type(plugin.func) == 'table' then - local ok, _ = plugin.func:new():tl_ops_process_init_access() - if not ok then - tlog:dbg("tl_ops_process_init_access process err , name=",plugin.name, ", ",_) - else - tlog:dbg("tl_ops_process_init_access process ok , name=",plugin.name, ", ",_) - end - else - tlog:dbg("tl_ops_process_init_access not func err , name=",plugin.name, ", ",_) - end - end -end - - --- content阶段执行 -function _M:tl_ops_process_init_content() - - local plugins = tl_ops_process_load_plugins() - - for i = 1, #plugins do - local plugin = plugins[i] - if type(plugin.func) == 'table' then - local ok, _ = plugin.func:new():tl_ops_process_init_content() - if not ok then - tlog:dbg("tl_ops_process_init_content process err , name=",plugin.name, ", ",_) - else - tlog:dbg("tl_ops_process_init_content process ok , name=",plugin.name, ", ",_) - end - else - tlog:dbg("tl_ops_process_init_content not func err , name=",plugin.name, ", ",_) - end - end -end - - --- header阶段执行 -function _M:tl_ops_process_init_header() - - local plugins = tl_ops_process_load_plugins() - - for i = 1, #plugins do - local plugin = plugins[i] - if type(plugin.func) == 'table' then - local ok, _ = plugin.func:new():tl_ops_process_init_header() - if not ok then - tlog:dbg("tl_ops_process_init_header process err , name=",plugin.name, ", ",_) - else - tlog:dbg("tl_ops_process_init_header process ok , name=",plugin.name, ", ",_) - end - else - tlog:dbg("tl_ops_process_init_header not func err , name=",plugin.name, ", ",_) - end - end -end - - --- body阶段执行 -function _M:tl_ops_process_init_body() - - local plugins = tl_ops_process_load_plugins() - - for i = 1, #plugins do - local plugin = plugins[i] - if type(plugin.func) == 'table' then - local ok, _ = plugin.func:new():tl_ops_process_init_body() - if not ok then - tlog:dbg("tl_ops_process_init_body process err , name=",plugin.name, ", ",_) - else - tlog:dbg("tl_ops_process_init_body process ok , name=",plugin.name, ", ",_) - end - else - tlog:dbg("tl_ops_process_init_body not func err , name=",plugin.name, ", ",_) - end - end -end - - --- log阶段执行 -function _M:tl_ops_process_init_log() - - local plugins = tl_ops_process_load_plugins() - - for i = 1, #plugins do - local plugin = plugins[i] - if type(plugin.func) == 'table' then - local ok, _ = plugin.func:new():tl_ops_process_init_log() - if not ok then - tlog:dbg("tl_ops_process_init_log process err , name=",plugin.name, ", ",_) - else - tlog:dbg("tl_ops_process_init_log process ok , name=",plugin.name, ", ",_) - end - else - tlog:dbg("tl_ops_process_init_log not func err , name=",plugin.name, ", ",_) - end - end -end - - -return _M diff --git a/utils/tl_ops_utils_func.lua b/utils/tl_ops_utils_func.lua index a42e39a..1264f64 100644 --- a/utils/tl_ops_utils_func.lua +++ b/utils/tl_ops_utils_func.lua @@ -4,14 +4,24 @@ -- @author iamtsm -- @email 1905333456@qq.com -local cjson, _ = require("cjson"); -local lock = require("lib.lock"); +local cjson, _ = require("cjson.safe"); +local lock = require("lib.lock"); +local shared = ngx.shared.tlopsbalance; +local find = ngx.re.find -local shared = ngx.shared.tlopsbalance; -local find = ngx.re.find local _M = {} +-- new tab +function _M:new_tab(narr, nrec) + local ok, new_tab = pcall(require, "table.new") + if not ok or type(new_tab) ~= "function" then + new_tab = function (narr, nrec) return {} end + end + return new_tab(narr, nrec) +end + + -- 获取当前路径 -- @split : 截取的路径字符 -- @appent : 补充的路径字符 diff --git a/utils/tl_ops_utils_log.lua b/utils/tl_ops_utils_log.lua index 9b3e46f..799a449 100644 --- a/utils/tl_ops_utils_log.lua +++ b/utils/tl_ops_utils_log.lua @@ -4,9 +4,8 @@ -- @author iamtsm -- @email 1905333456@qq.com -local ngx = require "ngx" -local cjson_safe = require("cjson.safe") -local tl_ops_env = require("tl_ops_manage_env") +local cjson_safe = require("cjson.safe") +local tl_ops_manage_env = require("tl_ops_manage_env") local _M = { debug = 1, @@ -96,10 +95,10 @@ function _M:new(module) self.__index = self return setmetatable({ - level = tl_ops_env.log.level, + level = tl_ops_manage_env.log.level, module = module, - dir = tl_ops_env.log.log_dir, - format_json = tl_ops_env.log.format_json + dir = tl_ops_manage_env.log.log_dir, + format_json = tl_ops_manage_env.log.format_json }, self) end diff --git a/utils/tl_ops_utils_store.lua b/utils/tl_ops_utils_store.lua index 0f26b90..65ae2c8 100644 --- a/utils/tl_ops_utils_store.lua +++ b/utils/tl_ops_utils_store.lua @@ -4,12 +4,11 @@ -- @author iamtsm -- @email 1905333456@qq.com -local ngx = require "ngx" -local cjson = require("cjson.safe") -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_utils_store"); +local cjson = require("cjson.safe") +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_utils_store"); local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; -local tl_ops_env = require("tl_ops_manage_env") +local tl_ops_manage_env = require("tl_ops_manage_env") +local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt; local _M = {} @@ -125,7 +124,7 @@ end function _M:new(business) local store_conf = { - path = tl_ops_env.log.store_dir, + path = tl_ops_manage_env.log.store_dir, business = business } setmetatable(store_conf, self) diff --git a/waf/count/tl_ops_waf_count.lua b/waf/count/tl_ops_waf_count.lua index 1cdf4e3..b8d6a91 100644 --- a/waf/count/tl_ops_waf_count.lua +++ b/waf/count/tl_ops_waf_count.lua @@ -2,4 +2,37 @@ -- en : waf count core api -- zn : waf统计对外接口 -- @author iamtsm --- @email 1905333456@qq.com \ No newline at end of file +-- @email 1905333456@qq.com + + +local tl_ops_waf_count_core = require("waf.count.tl_ops_waf_count_core"); +local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local shared = ngx.shared.tlopswaf; + +local _M = {} + + +function _M:init( ) + -- 启动路由统计 + local waf_count = tl_ops_waf_count_core:new(); + waf_count:tl_ops_waf_count_timer_start() +end + + +-- incr waf count +function _M:tl_ops_waf_count_incr_key(cache_key, service_name, node_id) + local key = cache_key + if service_name ~= nil or node_id ~= nil then + key = tl_ops_utils_func:gen_node_key(cache_key, service_name, node_id) + end + local count = shared:get(key) + if not count then + shared:set(key, 0); + end + shared:incr(key, 1) +end + + + +return _M \ No newline at end of file diff --git a/waf/count/tl_ops_waf_count_core.lua b/waf/count/tl_ops_waf_count_core.lua index 0ca94e5..91e1306 100644 --- a/waf/count/tl_ops_waf_count_core.lua +++ b/waf/count/tl_ops_waf_count_core.lua @@ -2,4 +2,209 @@ -- en : waf count core impl -- zn : waf统计实现 -- @author iamtsm --- @email 1905333456@qq.com \ No newline at end of file +-- @email 1905333456@qq.com + + +local cjson = require("cjson.safe") +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_count") +local tl_ops_utils_func = require("utils.tl_ops_utils_func") +local tl_ops_constant_waf = require("constant.tl_ops_constant_waf") +local tl_ops_constant_service = require("constant.tl_ops_constant_service") +local cache_service = require("cache.tl_ops_cache_core"):new("tl-ops-service") +local tl_ops_manage_env = require("tl_ops_manage_env") +local shared = ngx.shared.tlopswaf + + +local _M = { + _VERSION = '0.01', +} +local mt = { __index = _M } + + +-- 需要提前定义,定时器访问不了 +local tl_ops_waf_count_timer + + + +local tl_ops_waf_count_keys = function(waf_interval_success_key, service_name, node_id) + + local req_ip_key = tl_ops_constant_waf.cache_key.req_ip + if service_name ~= nil or node_id ~= nil then + req_ip_key = tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.req_ip, service_name, node_id) + end + local req_ip_count = shared:get(req_ip_key) + if not req_ip_count then + req_ip_count = 0 + end + + local req_api_key = tl_ops_constant_waf.cache_key.req_api + if service_name ~= nil or node_id ~= nil then + req_api_key = tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.req_api, service_name, node_id) + end + local req_api_count = shared:get(req_api_key) + if not req_api_count then + req_api_count = 0 + end + + local req_cc_key = tl_ops_constant_waf.cache_key.req_cc + if service_name ~= nil or node_id ~= nil then + req_cc_key = tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.req_cc, service_name, node_id) + end + local req_cc_count = shared:get(req_cc_key) + if not req_cc_count then + req_cc_count = 0 + end + + local req_cookie_key = tl_ops_constant_waf.cache_key.req_cookie + if service_name ~= nil or node_id ~= nil then + req_cookie_key = tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.req_cookie, service_name, node_id) + end + local req_cookie_count = shared:get(req_cookie_key) + if not req_cookie_count then + req_cookie_count = 0 + end + + local req_header_key = tl_ops_constant_waf.cache_key.req_header + if service_name ~= nil or node_id ~= nil then + req_header_key = tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.req_header, service_name, node_id) + end + local req_header_count = shared:get(req_header_key) + if not req_header_count then + req_header_count = 0 + end + + local req_param_key = tl_ops_constant_waf.cache_key.req_param + if service_name ~= nil or node_id ~= nil then + req_param_key = tl_ops_utils_func:gen_node_key(tl_ops_constant_waf.cache_key.req_param, service_name, node_id) + end + local req_param_count = shared:get(req_param_key) + if not req_param_count then + req_param_count = 0 + end + + local cur_count = req_ip_count + req_api_count + req_cc_count + req_cookie_count + req_header_count + req_param_count + if cur_count == 0 then + tlog:dbg("waf count dont need async , cur_count=",cur_count,",service_name=",service_name,",node_id=",node_id) + else + -- push to list + local key = tl_ops_utils_func:gen_node_key(waf_interval_success_key, service_name, node_id) + local waf_interval_success = cache_waf_count:get001(key) + if not waf_interval_success then + waf_interval_success = {} + else + waf_interval_success = cjson.decode(waf_interval_success) + end + + waf_interval_success[os.date("%Y-%m-%d %H:%M:%S", ngx.now())] = cur_count + local ok, _ = cache_waf_count:set001(key, cjson.encode(waf_interval_success)) + if not ok then + tlog:err("waf success count async err ,key=",key,",cur_count=",cur_count,",err=",_) + end + + -- rest cur_count + local ok, _ = shared:set(req_ip_key, 0) + if not ok then + tlog:err("waf req_ip_key count reset err ,req_ip_key=",req_ip_key,",cur_count=",cur_count) + end + ok, _ = shared:set(req_api_key, 0) + if not ok then + tlog:err("waf req_api_key count reset err ,req_api_key=",req_api_key,",cur_count=",cur_count) + end + ok, _ = shared:set(req_cc_key, 0) + if not ok then + tlog:err("waf req_cc_key count reset err ,req_cc_key=",req_cc_key,",cur_count=",cur_count) + end + ok, _ = shared:set(req_cookie_key, 0) + if not ok then + tlog:err("waf req_cookie_key count reset err ,req_cookie_key=",req_cookie_key,",cur_count=",cur_count) + end + ok, _ = shared:set(req_header_key, 0) + if not ok then + tlog:err("waf req_header_key count reset err ,req_header_key=",req_header_key,",cur_count=",cur_count) + end + ok, _ = shared:set(req_param_key, 0) + if not ok then + tlog:err("waf req_param_key count reset err ,req_param_key=",req_param_key,",cur_count=",cur_count) + end + + tlog:dbg("waf count async ok ,key=",key,",waf_interval_success=",waf_interval_success) + end + +end + + +-- 统计器 : 持久化数据 +local tl_ops_waf_count = function() + local lock_key = tl_ops_constant_waf.cache_key.lock + local lock_time = tl_ops_constant_waf.count.interval - 0.01 + if not tl_ops_utils_func:tl_ops_worker_lock(lock_key, lock_time) then + return + end + + local service_list = nil + local service_list_str, _ = cache_service:get(tl_ops_constant_service.cache_key.service_list); + if not service_list_str then + -- use default + service_list = tl_ops_constant_service.list + else + service_list = cjson.decode(service_list_str); + end + + + -- 控制细度 ,以周期为分割,仅用store持久 + local count_name = "tl-ops-waf-count-" .. tl_ops_constant_waf.count.interval; + local cache_waf_count = require("cache.tl_ops_cache_core"):new(count_name); + + for service_name, nodes in pairs(service_list) do + if nodes == nil then + tlog:err("nodes nil") + return + end + -- 服务级别waf + tl_ops_waf_count_keys(tl_ops_constant_waf.cache_key.waf_interval_success, service_name, nil) + end + -- 全局级别waf + tl_ops_waf_count_keys(tl_ops_constant_waf.cache_key.waf_interval_success, nil, nil) +end + + + +-- 统计waf次数周期默认为5min,可调整配置 +tl_ops_waf_count_timer = function(premature, args) + if premature then + return + end + + local ok, _ = pcall(tl_ops_waf_count) + if not ok then + tlog:err("failed to pcall : " , _) + end + + local ok, _ = ngx.timer.at(tl_ops_constant_waf.count.interval, tl_ops_waf_count_timer, args) + if not ok then + tlog:err("failed to create timer: " , _) + end + +end + +-- 启动 +function _M:tl_ops_waf_count_timer_start() + if not tl_ops_manage_env.waf.counting then + tlog:err("waf counting not open " ,_) + return + end + + local ok, _ = ngx.timer.at(0, tl_ops_waf_count_timer, nil) + if not ok then + tlog:err("failed to run default args , create timer failed " ,_) + return nil + end +end + + +function _M:new() + return setmetatable({}, mt) +end + + +return _M \ No newline at end of file diff --git a/waf/tl_ops_waf.lua b/waf/tl_ops_waf.lua index 706021d..852d98a 100644 --- a/waf/tl_ops_waf.lua +++ b/waf/tl_ops_waf.lua @@ -4,8 +4,8 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_waf_core = require("waf.tl_ops_waf_core"):new(); -local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); +local tl_ops_waf_core = require("waf.tl_ops_waf_core"):new(); +local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope") local _M = {} @@ -16,8 +16,6 @@ function _M:init(scope) tl_ops_waf_core:tl_ops_waf_global_core() elseif scope == tl_ops_constant_waf_scope.service then tl_ops_waf_core:tl_ops_waf_service_core() - elseif scope == tl_ops_constant_waf_scope.node then - tl_ops_waf_core:tl_ops_waf_node_core() end end diff --git a/waf/tl_ops_waf_core.lua b/waf/tl_ops_waf_core.lua index aac2be7..b39f4b2 100644 --- a/waf/tl_ops_waf_core.lua +++ b/waf/tl_ops_waf_core.lua @@ -4,21 +4,18 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_waf_core_api = require("waf.tl_ops_waf_core_api"); -local tl_ops_waf_core_ip = require("waf.tl_ops_waf_core_ip"); -local tl_ops_waf_core_cc = require("waf.tl_ops_waf_core_cc"); -local tl_ops_waf_core_header = require("waf.tl_ops_waf_core_header"); -local tl_ops_waf_core_cookie = require("waf.tl_ops_waf_core_cookie"); -local tl_ops_waf_core_param = require("waf.tl_ops_waf_core_param"); - -local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); - -local cache_waf = require("cache.tl_ops_cache"):new("tl-ops-waf"); - -local cjson = require("cjson"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local tl_ops_manage_env = require("tl_ops_manage_env") -local shared = ngx.shared.tlopsbalance +local tl_ops_waf_core_api = require("waf.tl_ops_waf_core_api"); +local tl_ops_waf_core_ip = require("waf.tl_ops_waf_core_ip"); +local tl_ops_waf_core_cc = require("waf.tl_ops_waf_core_cc"); +local tl_ops_waf_core_header = require("waf.tl_ops_waf_core_header"); +local tl_ops_waf_core_cookie = require("waf.tl_ops_waf_core_cookie"); +local tl_ops_waf_core_param = require("waf.tl_ops_waf_core_param"); +local tl_ops_constant_waf = require("constant.tl_ops_constant_waf"); +local cache_waf = require("cache.tl_ops_cache_core"):new("tl-ops-waf"); +local cjson = require("cjson.safe"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local tl_ops_manage_env = require("tl_ops_manage_env") +local shared = ngx.shared.tlopsbalance local _M = { @@ -31,7 +28,7 @@ local mt = { __index = _M } function _M:tl_ops_waf_global_core() -- 关闭 - if tl_ops_manage_env.waf.open then + if not tl_ops_manage_env.waf.open then return true end @@ -97,7 +94,7 @@ end -- 服务waf核心流程 function _M:tl_ops_waf_service_core() -- 关闭 - if tl_ops_manage_env.waf.open then + if not tl_ops_manage_env.waf.open then return true end @@ -160,72 +157,6 @@ function _M:tl_ops_waf_service_core() return true end --- 节点waf核心流程 -function _M:tl_ops_waf_node_core() - -- 关闭 - if tl_ops_manage_env.waf.open then - return true - end - - -- waf错误码配置 - local code_str = cache_waf:get(tl_ops_constant_waf.cache_key.options) - if not code_str then - ngx.header['Tl-Waf-Mode'] = "n-empty"; - ngx.exit(506) - return - end - local code = cjson.decode(code_str); - if not code and type(code) ~= 'table' then - ngx.header['Tl-Waf-Mode'] = "n-empty"; - ngx.exit(506) - return - end - - local waf = tl_ops_waf_core_ip.tl_ops_waf_core_ip_filter_node_pass() - if not waf then - ngx.header['Tl-Waf-Mode'] = "n-ip"; - ngx.exit(code[tl_ops_constant_waf.cache_key.ip]) - return - end - - waf = tl_ops_waf_core_api.tl_ops_waf_core_api_filter_node_pass() - if not waf then - ngx.header['Tl-Waf-Mode'] = "n-api"; - ngx.exit(code[tl_ops_constant_waf.cache_key.api]) - return - end - - waf = tl_ops_waf_core_cc.tl_ops_waf_core_cc_filter_node_pass() - if not waf then - ngx.header['Tl-Waf-Mode'] = "n-cc"; - ngx.exit(code[tl_ops_constant_waf.cache_key.cc]) - return - end - - waf = tl_ops_waf_core_header.tl_ops_waf_core_header_filter_node_pass() - if not waf then - ngx.header['Tl-Waf-Mode'] = "n-header"; - ngx.exit(code[tl_ops_constant_waf.cache_key.header]) - return - end - - waf = tl_ops_waf_core_cookie.tl_ops_waf_core_cookie_filter_node_pass() - if not waf then - ngx.header['Tl-Waf-Mode'] = "n-cookie"; - ngx.exit(code[tl_ops_constant_waf.cache_key.cookie]) - return - end - - waf = tl_ops_waf_core_param.tl_ops_waf_core_param_filter_node_pass() - if not waf then - ngx.header['Tl-Waf-Mode'] = "n-param"; - ngx.exit(code[tl_ops_constant_waf.cache_key.param]) - return - end - - return true -end - function _M:new() return setmetatable({}, mt) diff --git a/waf/tl_ops_waf_core_api.lua b/waf/tl_ops_waf_core_api.lua index 78a1876..7a5a306 100644 --- a/waf/tl_ops_waf_core_api.lua +++ b/waf/tl_ops_waf_core_api.lua @@ -4,13 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); +local tl_ops_constant_waf_api = require("constant.tl_ops_constant_waf_api"); local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local cache_api = require("cache.tl_ops_cache"):new("tl-ops-waf-api"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_api"); -local find = ngx.re.find -local cjson = require("cjson"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cache_api = require("cache.tl_ops_cache_core"):new("tl-ops-waf-api"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_api"); +local find = ngx.re.find +local cjson = require("cjson.safe"); @@ -20,12 +20,12 @@ local tl_ops_waf_core_api_filter_global_pass = function() -- 作用域 local api_scope, _ = cache_api:get(tl_ops_constant_waf_api.cache_key.scope); if not api_scope then - return false + return true end -- 根据作用域进行waf拦截 if api_scope ~= tl_ops_constant_waf_scope.global then - return false + return true end -- 是否开启拦截 @@ -37,12 +37,12 @@ local tl_ops_waf_core_api_filter_global_pass = function() -- 配置列表 local api_list, _ = cache_api:get(tl_ops_constant_waf_api.cache_key.list); if not api_list then - return false + return true end local api_list_table = cjson.decode(api_list); if not api_list_table then - return false + return true end -- 获取当前url @@ -124,18 +124,18 @@ end -- true : 通过, false : 拦截 local tl_ops_waf_core_api_filter_service_pass = function(service_name) if not service_name then - return false + return true end -- 作用域 local api_scope, _ = cache_api:get(tl_ops_constant_waf_api.cache_key.scope); if not api_scope then - return false + return true end -- 根据作用域进行waf拦截 if api_scope ~= tl_ops_constant_waf_scope.service then - return false + return true end -- 是否开启拦截 @@ -147,12 +147,12 @@ local tl_ops_waf_core_api_filter_service_pass = function(service_name) -- 配置列表 local api_list, _ = cache_api:get(tl_ops_constant_waf_api.cache_key.list); if not api_list then - return false + return true end local api_list_table = cjson.decode(api_list); if not api_list_table then - return false + return true end -- 获取当前url @@ -247,153 +247,8 @@ local tl_ops_waf_core_api_filter_service_pass = function(service_name) end --- 匹配到节点层拦截 --- true : 通过, false : 拦截 -local tl_ops_waf_core_api_filter_node_pass = function(service_name, node_id) - if not service_name or not node_id then - return false - end - - -- 作用域 - local api_scope, _ = cache_api:get(tl_ops_constant_waf_api.cache_key.scope); - if not api_scope then - return false - end - - -- 根据作用域进行waf拦截 - if api_scope ~= tl_ops_constant_waf_scope.node then - return false - end - - -- 是否开启拦截 - local open, _ = cache_api:get(tl_ops_constant_waf_api.cache_key.open); - if not open then - return true - end - - -- 配置列表 - local api_list, _ = cache_api:get(tl_ops_constant_waf_api.cache_key.list); - if not api_list then - return false - end - - local api_list_table = cjson.decode(api_list); - if not api_list_table then - return false - end - - -- 获取当前url - local request_uri = tl_ops_utils_func:get_req_uri(); - if not request_uri then - return true - end - - local cur_host = ngx.var.host - if not cur_host then - return true - end - - tlog:dbg("tl_ops_waf_api get list ok, scope=",api_scope, ",host=",cur_host,",uri=",request_uri,",list=",api_list_table) - - -- 优先处理白名单 - for _, api in ipairs(api_list_table) do - repeat - local value = api.value - local host = api.host - local service = api.service - local node = api.node - local white = api.white - -- 非白名单跳过 - if not white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(request_uri , value , 'joi'); - if not res then - break - end - -- api白名单,不用后续比对,直接通过 - return true - until true - end - - for _, api in ipairs(api_list_table) do - repeat - local value = api.value - local host = api.host - local service = api.service - local node = api.node - local white = api.white - -- 此前已处理白名单 - if white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(request_uri , value , 'joi'); - if not res then - break - end - -- 命中规则的api - return false - until true - end - - tlog:dbg("tl_ops_waf_api done") - - return true -end - return { tl_ops_waf_core_api_filter_global_pass = tl_ops_waf_core_api_filter_global_pass, tl_ops_waf_core_api_filter_service_pass = tl_ops_waf_core_api_filter_service_pass, - tl_ops_waf_core_api_filter_node_pass = tl_ops_waf_core_api_filter_node_pass } \ No newline at end of file diff --git a/waf/tl_ops_waf_core_cc.lua b/waf/tl_ops_waf_core_cc.lua index b6e4b88..6513278 100644 --- a/waf/tl_ops_waf_core_cc.lua +++ b/waf/tl_ops_waf_core_cc.lua @@ -4,41 +4,40 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); +local tl_ops_constant_waf_cc = require("constant.tl_ops_constant_waf_cc"); local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local cache_cc = require("cache.tl_ops_cache"):new("tl-ops-waf-cc"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_cc"); -local find = ngx.re.find -local cjson = require("cjson"); - -local shared_balance = ngx.shared.tlopsbalance -local shared_waf = ngx.shared.tlopswaf -local MAX_URL_LEN = 50 +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cache_cc = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cc"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_cc"); +local find = ngx.re.find +local cjson = require("cjson.safe"); +local shared_balance = ngx.shared.tlopsbalance +local shared_waf = ngx.shared.tlopswaf +local MAX_URL_LEN = 50 -- 全局拦截 -- true : 通过, false : 拦截 -local tl_ops_waf_core_cc_filter_global_pass = function() +local tl_ops_waf_core_cc_filter_global_pass = function() -- 作用域 local cc_scope, _ = cache_cc:get(tl_ops_constant_waf_cc.cache_key.scope); if not cc_scope then - return false + return true end -- 根据作用域进行waf拦截 if cc_scope ~= tl_ops_constant_waf_scope.global then - return false + return true end -- 配置列表 local cc_list, _ = cache_cc:get(tl_ops_constant_waf_cc.cache_key.list); if not cc_list then - return false + return true end local cc_list_table = cjson.decode(cc_list); if not cc_list_table then - return false + return true end -- 获取当前url @@ -100,122 +99,29 @@ end -- true : 通过, false : 拦截 local tl_ops_waf_core_cc_filter_service_pass = function(service_name) if not service_name then - return false + return true end -- 作用域 local cc_scope, _ = cache_cc:get(tl_ops_constant_waf_cc.cache_key.scope); if not cc_scope then - return false + return true end -- 根据作用域进行waf拦截 if cc_scope ~= tl_ops_constant_waf_scope.service then - return false - end - - -- 配置列表 - local cc_list, _ = cache_cc:get(tl_ops_constant_waf_cc.cache_key.list); - if not cc_list then - return false - end - - local cc_list_table = cjson.decode(cc_list); - if not cc_list_table then - return false - end - - -- 获取当前url - local request_uri = string.sub(tl_ops_utils_func:get_req_uri(), 1, MAX_URL_LEN); - if not request_uri then - request_uri = "" - end - -- 获取当前ip - local ip = tl_ops_utils_func:get_req_ip(); - if not ip then - ip = "" - end - -- cc key - local cc_key = tl_ops_constant_waf_cc.cache_key.prefix .. ip .. request_uri - - local cur_host = ngx.var.host - if not cur_host then return true end - - tlog:dbg("tl_ops_waf_cc get list ok, scope=",cc_scope, ",host=",cur_host,",cc_key=",cc_key,",list=",cc_list_table) - - for _, cc in ipairs(cc_list_table) do - repeat - local host = cc.host - local service = cc.service - local time = cc.time - local count = cc.count - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 首次 - local res, _ = shared_waf:get(cc_key) - if not res then - shared_waf:set(cc_key, 1, time) - break - end - -- 没有达到cc次数 - if res < count then - shared_waf:incr(cc_key, 1) - break - end - -- 触发cc - return false - until true - end - - tlog:dbg("tl_ops_waf_cc done") - - return true -end - - --- 匹配到节点层拦截 --- true : 通过, false : 拦截 -local tl_ops_waf_core_cc_filter_node_pass = function(service_name, node_id) - if not service_name or not node_id then - return false - end - - -- 作用域 - local cc_scope, _ = cache_cc:get(tl_ops_constant_waf_cc.cache_key.scope); - if not cc_scope then - return false - end - - -- 根据作用域进行waf拦截 - if cc_scope ~= tl_ops_constant_waf_scope.node then - return false - end -- 配置列表 local cc_list, _ = cache_cc:get(tl_ops_constant_waf_cc.cache_key.list); if not cc_list then - return false + return true end local cc_list_table = cjson.decode(cc_list); if not cc_list_table then - return false + return true end -- 获取当前url @@ -242,7 +148,6 @@ local tl_ops_waf_core_cc_filter_node_pass = function(service_name, node_id) repeat local host = cc.host local service = cc.service - local node = cc.node local time = cc.time local count = cc.count -- 域名为空跳过规则 @@ -261,14 +166,6 @@ local tl_ops_waf_core_cc_filter_node_pass = function(service_name, node_id) if service ~= service_name then break end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end -- 首次 local res, _ = shared_waf:get(cc_key) if not res then @@ -291,8 +188,8 @@ local tl_ops_waf_core_cc_filter_node_pass = function(service_name, node_id) end + return { tl_ops_waf_core_cc_filter_global_pass = tl_ops_waf_core_cc_filter_global_pass, tl_ops_waf_core_cc_filter_service_pass = tl_ops_waf_core_cc_filter_service_pass, - tl_ops_waf_core_cc_filter_node_pass = tl_ops_waf_core_cc_filter_node_pass } \ No newline at end of file diff --git a/waf/tl_ops_waf_core_cookie.lua b/waf/tl_ops_waf_core_cookie.lua index df0b387..99722e8 100644 --- a/waf/tl_ops_waf_core_cookie.lua +++ b/waf/tl_ops_waf_core_cookie.lua @@ -4,14 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); -local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); - -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local cache_cookie = require("cache.tl_ops_cache"):new("tl-ops-waf-cookie"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_cookie"); -local find = ngx.re.find -local cjson = require("cjson"); +local tl_ops_constant_waf_cookie = require("constant.tl_ops_constant_waf_cookie"); +local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cache_cookie = require("cache.tl_ops_cache_core"):new("tl-ops-waf-cookie"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_cookie"); +local find = ngx.re.find +local cjson = require("cjson.safe"); -- 全局拦截 @@ -20,12 +19,12 @@ local tl_ops_waf_core_cookie_filter_global_pass = function() -- 作用域 local cookie_scope, _ = cache_cookie:get(tl_ops_constant_waf_cookie.cache_key.scope); if not cookie_scope then - return false + return true end -- 根据作用域进行waf拦截 if cookie_scope ~= tl_ops_constant_waf_scope.global then - return false + return true end -- 是否开启拦截 @@ -37,12 +36,12 @@ local tl_ops_waf_core_cookie_filter_global_pass = function() -- 配置列表 local cookie_list, _ = cache_cookie:get(tl_ops_constant_waf_cookie.cache_key.list); if not cookie_list then - return false + return true end local cookie_list_table = cjson.decode(cookie_list); if not cookie_list_table then - return false + return true end -- 获取当前cookie @@ -123,18 +122,18 @@ end -- true : 通过, false : 拦截 local tl_ops_waf_core_cookie_filter_service_pass = function(service_name) if not service_name then - return false + return true end -- 作用域 local cookie_scope, _ = cache_cookie:get(tl_ops_constant_waf_cookie.cache_key.scope); if not cookie_scope then - return false + return true end -- 根据作用域进行waf拦截 if cookie_scope ~= tl_ops_constant_waf_scope.service then - return false + return true end -- 是否开启拦截 @@ -146,139 +145,12 @@ local tl_ops_waf_core_cookie_filter_service_pass = function(service_name) -- 配置列表 local cookie_list, _ = cache_cookie:get(tl_ops_constant_waf_cookie.cache_key.list); if not cookie_list then - return false - end - - local cookie_list_table = cjson.decode(cookie_list); - if not cookie_list_table then - return false - end - - -- 获取当前cookie - local cookie_string, _ = ngx.var.http_cookie - if not cookie_string then - return true - end - - local cur_host = ngx.var.host - if not cur_host then - return true - end - - tlog:dbg("tl_ops_waf_cookie get list ok, scope=",cookie_scope, ",host=",cur_host,",cookie_string=",cookie_string,",list=",cookie_list_table) - - -- 优先处理白名单 - for _, cookie in ipairs(cookie_list_table) do - repeat - local value = cookie.value - local host = cookie.host - local service = cookie.service - local white = cookie.white - -- 非白名单跳过 - if not white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(cookie_string , value , 'joi'); - if not res then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 白名单,不用后续比对,直接通过 - return true - until true - end - - for _, cookie in ipairs(cookie_list_table) do - repeat - local value = cookie.value - local host = cookie.host - local service = cookie.service - local white = cookie.white - -- 此前已处理白名单 - if white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(request_uri , value , 'joi'); - if not res then - break - end - -- 命中规则的cookie - return false - until true - end - - tlog:dbg("tl_ops_waf_cookie done") - - return true -end - - --- 匹配到节点层拦截 --- true : 通过, false : 拦截 -local tl_ops_waf_core_cookie_filter_node_pass = function(service_name, node_id) - if not service_name or not node_id then - return false - end - - -- 作用域 - local cookie_scope, _ = cache_cookie:get(tl_ops_constant_waf_cookie.cache_key.scope); - if not cookie_scope then - return false - end - - -- 根据作用域进行waf拦截 - if cookie_scope ~= tl_ops_constant_waf_scope.node then - return false - end - - -- 是否开启拦截 - local open, _ = cache_cookie:get(tl_ops_constant_waf_cookie.cache_key.open); - if not open then return true end - - -- 配置列表 - local cookie_list, _ = cache_cookie:get(tl_ops_constant_waf_cookie.cache_key.list); - if not cookie_list then - return false - end local cookie_list_table = cjson.decode(cookie_list); if not cookie_list_table then - return false + return true end -- 获取当前cookie @@ -286,7 +158,7 @@ local tl_ops_waf_core_cookie_filter_node_pass = function(service_name, node_id) if not cookie_string then return true end - + local cur_host = ngx.var.host if not cur_host then return true @@ -300,7 +172,6 @@ local tl_ops_waf_core_cookie_filter_node_pass = function(service_name, node_id) local value = cookie.value local host = cookie.host local service = cookie.service - local node = cookie.node local white = cookie.white -- 非白名单跳过 if not white then @@ -326,14 +197,6 @@ local tl_ops_waf_core_cookie_filter_node_pass = function(service_name, node_id) -- 服务不匹配 if service ~= service_name then break - end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break end -- 白名单,不用后续比对,直接通过 return true @@ -345,7 +208,6 @@ local tl_ops_waf_core_cookie_filter_node_pass = function(service_name, node_id) local value = cookie.value local host = cookie.host local service = cookie.service - local node = cookie.node local white = cookie.white -- 此前已处理白名单 if white then @@ -367,14 +229,6 @@ local tl_ops_waf_core_cookie_filter_node_pass = function(service_name, node_id) if service ~= service_name then break end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end -- 未命中拦截规则,进行下一个 local res, _ = find(request_uri , value , 'joi'); if not res then @@ -394,5 +248,4 @@ end return { tl_ops_waf_core_cookie_filter_global_pass = tl_ops_waf_core_cookie_filter_global_pass, tl_ops_waf_core_cookie_filter_service_pass = tl_ops_waf_core_cookie_filter_service_pass, - tl_ops_waf_core_cookie_filter_node_pass = tl_ops_waf_core_cookie_filter_node_pass } \ No newline at end of file diff --git a/waf/tl_ops_waf_core_header.lua b/waf/tl_ops_waf_core_header.lua index b8bbfcd..ad3f8cc 100644 --- a/waf/tl_ops_waf_core_header.lua +++ b/waf/tl_ops_waf_core_header.lua @@ -4,13 +4,13 @@ -- @author iamtsm -- @email 1905333456@qq.com -local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header"); -local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local cache_header = require("cache.tl_ops_cache"):new("tl-ops-waf-header"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_header"); -local find = ngx.re.find -local cjson = require("cjson"); +local tl_ops_constant_waf_header = require("constant.tl_ops_constant_waf_header") +local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope") +local tl_ops_utils_func = require("utils.tl_ops_utils_func") +local cache_header = require("cache.tl_ops_cache_core"):new("tl-ops-waf-header") +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_header") +local find = ngx.re.find +local cjson = require("cjson.safe") -- 全局拦截 @@ -19,12 +19,12 @@ local tl_ops_waf_core_header_filter_global_pass = function() -- 作用域 local header_scope, _ = cache_header:get(tl_ops_constant_waf_header.cache_key.scope); if not header_scope then - return false + return true end -- 根据作用域进行waf拦截 if header_scope ~= tl_ops_constant_waf_scope.global then - return false + return true end -- 是否开启拦截 @@ -36,12 +36,12 @@ local tl_ops_waf_core_header_filter_global_pass = function() -- 配置列表 local header_list, _ = cache_header:get(tl_ops_constant_waf_header.cache_key.list); if not header_list then - return false + return true end local header_list_table = cjson.decode(header_list); if not header_list_table then - return false + return true end -- 获取当前header @@ -152,18 +152,18 @@ end -- true : 通过, false : 拦截 local tl_ops_waf_core_header_filter_service_pass = function(service_name) if not service_name then - return false + return true end -- 作用域 local header_scope, _ = cache_header:get(tl_ops_constant_waf_header.cache_key.scope); if not header_scope then - return false + return true end -- 根据作用域进行waf拦截 if header_scope ~= tl_ops_constant_waf_scope.service then - return false + return true end -- 是否开启拦截 @@ -175,12 +175,12 @@ local tl_ops_waf_core_header_filter_service_pass = function(service_name) -- 配置列表 local header_list, _ = cache_header:get(tl_ops_constant_waf_header.cache_key.list); if not header_list then - return false + return true end local header_list_table = cjson.decode(header_list); if not header_list_table then - return false + return true end -- 获取当前header @@ -306,183 +306,8 @@ local tl_ops_waf_core_header_filter_service_pass = function(service_name) end --- 匹配到节点层拦截 --- true : 通过, false : 拦截 -local tl_ops_waf_core_header_filter_node_pass = function(service_name, node_id) - if not service_name or not node_id then - return false - end - - -- 作用域 - local header_scope, _ = cache_header:get(tl_ops_constant_waf_header.cache_key.scope); - if not header_scope then - return false - end - - -- 根据作用域进行waf拦截 - if header_scope ~= tl_ops_constant_waf_scope.node then - return false - end - - -- 配置列表 - local header_list, _ = cache_header:get(tl_ops_constant_waf_header.cache_key.list); - if not header_list then - return false - end - - -- 是否开启拦截 - local open, _ = cache_header:get(tl_ops_constant_waf_header.cache_key.open); - if not open then - return true - end - - local header_list_table = cjson.decode(header_list); - if not header_list_table then - return false - end - - -- 获取当前header - local headers, _ = ngx.req.get_headers(); - if not headers then - return true - end - - local cur_host = ngx.var.host - if not cur_host then - return true - end - - tlog:dbg("tl_ops_waf_header get list ok, scope=",header_scope, ",host=",cur_host,",headers=",headers,",list=",header_list_table) - - -- 优先处理白名单 - for _, header in ipairs(header_list_table) do - repeat - local keys = header.keys - local value = header.value - local host = header.host - local service = header.service - local node = header.node - local white = header.white - -- 非白名单跳过 - if not white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end - -- 请求头键列表为空 - if not keys then - break - end - -- 请求头值列表过滤 - for _, key in pairs(keys) do - repeat - -- 值为空 - if headers[key] == nil or headers[key] == '' then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(headers[key] , value , 'joi'); - if not res then - break - end - -- 白名单,不用后续比对,直接通过 - return true - until true - end - break - until true - end - - for _, header in ipairs(header_list_table) do - repeat - local keys = header.keys - local value = header.value - local host = header.host - local service = header.service - local node = header.node - local white = header.white - -- 此前已处理白名单 - if white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end - -- 请求头键列表为空 - if not keys then - break - end - -- 请求头值列表过滤 - for _, key in pairs(keys) do - repeat - -- 值为空 - if headers[key] == nil or headers[key] == '' then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(headers[key] , value , 'joi'); - if not res then - break - end - -- 命中规则的header - return false - until true - end - break - until true - end - - tlog:dbg("tl_ops_waf_header done") - - return true -end - return { tl_ops_waf_core_header_filter_global_pass = tl_ops_waf_core_header_filter_global_pass, tl_ops_waf_core_header_filter_service_pass = tl_ops_waf_core_header_filter_service_pass, - tl_ops_waf_core_header_filter_node_pass = tl_ops_waf_core_header_filter_node_pass } \ No newline at end of file diff --git a/waf/tl_ops_waf_core_ip.lua b/waf/tl_ops_waf_core_ip.lua index cec79f4..6f49bee 100644 --- a/waf/tl_ops_waf_core_ip.lua +++ b/waf/tl_ops_waf_core_ip.lua @@ -5,13 +5,13 @@ -- @email 1905333456@qq.com -local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); -local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local cache_ip = require("cache.tl_ops_cache"):new("tl-ops-waf-ip"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_ip"); -local find = ngx.re.find -local cjson = require("cjson"); +local tl_ops_constant_waf_ip = require("constant.tl_ops_constant_waf_ip"); +local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope") +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cache_ip = require("cache.tl_ops_cache_core"):new("tl-ops-waf-ip"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_ip"); +local find = ngx.re.find +local cjson = require("cjson.safe"); -- 全局拦截 -- true : 通过, false : 拦截 @@ -19,12 +19,12 @@ local tl_ops_waf_core_ip_filter_global_pass = function() -- 作用域 local ip_scope, _ = cache_ip:get(tl_ops_constant_waf_ip.cache_key.scope); if not ip_scope then - return false + return true end -- 根据作用域进行waf拦截 if ip_scope ~= tl_ops_constant_waf_scope.global then - return false + return true end -- 是否开启拦截 @@ -36,12 +36,12 @@ local tl_ops_waf_core_ip_filter_global_pass = function() -- 配置列表 local ip_list, _ = cache_ip:get(tl_ops_constant_waf_ip.cache_key.list); if not ip_list then - return false + return true end local ip_list_table = cjson.decode(ip_list); if not ip_list_table then - return false + return true end -- 获取当前ip @@ -122,18 +122,18 @@ end -- true : 通过, false : 拦截 local tl_ops_waf_core_ip_filter_service_pass = function(service_name) if not service_name then - return false + return true end -- 作用域 local ip_scope, _ = cache_ip:get(tl_ops_constant_waf_ip.cache_key.scope); if not ip_scope then - return false + return true end -- 根据作用域进行waf拦截 if ip_scope ~= tl_ops_constant_waf_scope.service then - return false + return true end -- 是否开启拦截 @@ -145,140 +145,12 @@ local tl_ops_waf_core_ip_filter_service_pass = function(service_name) -- 配置列表 local ip_list, _ = cache_ip:get(tl_ops_constant_waf_ip.cache_key.list); if not ip_list then - return false - end - - local ip_list_table = cjson.decode(ip_list); - if not ip_list_table then - return false - end - - -- 获取当前ip - local cur_ip = tl_ops_utils_func:get_req_ip(); - if not cur_ip then - return true - end - - local cur_host = ngx.var.host - if not cur_host then - return true - end - - tlog:dbg("tl_ops_waf_ip get list ok, scope=",ip_scope, ",host=",cur_host,",ip=",cur_ip,",list=",ip_list_table) - - -- 优先处理白名单 - for _, ip in ipairs(ip_list_table) do - repeat - local value = ip.value - local host = ip.host - local service = ip.service - local white = ip.white - -- 非白名单跳过 - if not white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(cur_ip , value , 'joi'); - if not res then - break - end - -- 白名单,不用后续比对,直接通过 - return true - until true - end - - - for _, ip in ipairs(ip_list_table) do - repeat - local value = ip.value - local host = ip.host - local service = ip.service - local white = ip.white - -- 此前已处理白名单 - if white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 未命中拦截规则,进行下一个 - local res, _ = find(cur_ip , value , 'joi'); - if not res then - break - end - -- 命中规则的ip - return false - until true - end - - tlog:dbg("tl_ops_waf_ip done") - - return true -end - - --- 匹配到节点层拦截 --- true : 通过, false : 拦截 -local tl_ops_waf_core_ip_filter_node_pass = function(service_name, node_id) - if not service_name or not node_id then - return false - end - - -- 作用域 - local ip_scope, _ = cache_ip:get(tl_ops_constant_waf_ip.cache_key.scope); - if not ip_scope then - return false - end - - -- 根据作用域进行waf拦截 - if ip_scope ~= tl_ops_constant_waf_scope.node then - return false - end - - -- 是否开启拦截 - local open, _ = cache_ip:get(tl_ops_constant_waf_ip.cache_key.open); - if not open then return true end - -- 配置列表 - local ip_list, _ = cache_ip:get(tl_ops_constant_waf_ip.cache_key.list); - if not ip_list then - return false - end - local ip_list_table = cjson.decode(ip_list); if not ip_list_table then - return false + return true end -- 获取当前ip @@ -300,7 +172,6 @@ local tl_ops_waf_core_ip_filter_node_pass = function(service_name, node_id) local value = ip.value local host = ip.host local service = ip.service - local node = ip.node local white = ip.white -- 非白名单跳过 if not white then @@ -322,14 +193,6 @@ local tl_ops_waf_core_ip_filter_node_pass = function(service_name, node_id) if service ~= service_name then break end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end -- 未命中拦截规则,进行下一个 local res, _ = find(cur_ip , value , 'joi'); if not res then @@ -346,7 +209,6 @@ local tl_ops_waf_core_ip_filter_node_pass = function(service_name, node_id) local value = ip.value local host = ip.host local service = ip.service - local node = ip.node local white = ip.white -- 此前已处理白名单 if white then @@ -368,14 +230,6 @@ local tl_ops_waf_core_ip_filter_node_pass = function(service_name, node_id) if service ~= service_name then break end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end -- 未命中拦截规则,进行下一个 local res, _ = find(cur_ip , value , 'joi'); if not res then @@ -395,5 +249,4 @@ end return { tl_ops_waf_core_ip_filter_global_pass = tl_ops_waf_core_ip_filter_global_pass, tl_ops_waf_core_ip_filter_service_pass = tl_ops_waf_core_ip_filter_service_pass, - tl_ops_waf_core_ip_filter_node_pass = tl_ops_waf_core_ip_filter_node_pass } \ No newline at end of file diff --git a/waf/tl_ops_waf_core_param.lua b/waf/tl_ops_waf_core_param.lua index f2b36c6..8987700 100644 --- a/waf/tl_ops_waf_core_param.lua +++ b/waf/tl_ops_waf_core_param.lua @@ -5,14 +5,13 @@ -- @email 1905333456@qq.com local tl_ops_constant_waf_param = require("constant.tl_ops_constant_waf_param"); -local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope"); -local tl_ops_utils_func = require("utils.tl_ops_utils_func"); -local cache_param = require("cache.tl_ops_cache"):new("tl-ops-waf-param"); -local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_param"); -local cjson = require("cjson"); - -local unescape = ngx.unescape_uri -local find = ngx.re.find +local tl_ops_constant_waf_scope = require("constant.tl_ops_constant_waf_scope") +local tl_ops_utils_func = require("utils.tl_ops_utils_func"); +local cache_param = require("cache.tl_ops_cache_core"):new("tl-ops-waf-param"); +local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_waf_param"); +local cjson = require("cjson.safe"); +local unescape = ngx.unescape_uri +local find = ngx.re.find -- 全局拦截 @@ -21,12 +20,12 @@ local tl_ops_waf_core_param_filter_global_pass = function() -- 作用域 local param_scope, _ = cache_param:get(tl_ops_constant_waf_param.cache_key.scope); if not param_scope then - return false + return true end -- 根据作用域进行waf拦截 if param_scope ~= tl_ops_constant_waf_scope.global then - return false + return true end -- 是否开启拦截 @@ -38,12 +37,12 @@ local tl_ops_waf_core_param_filter_global_pass = function() -- 配置列表 local param_list, _ = cache_param:get(tl_ops_constant_waf_param.cache_key.list); if not param_list then - return false + return true end local param_list_table = cjson.decode(param_list); if not param_list_table then - return false + return true end -- 获取当前参数 @@ -143,18 +142,18 @@ end -- true : 通过, false : 拦截 local tl_ops_waf_core_param_filter_service_pass = function(service_name) if not service_name then - return false + return true end -- 作用域 local param_scope, _ = cache_param:get(tl_ops_constant_waf_param.cache_key.scope); if not param_scope then - return false + return true end -- 根据作用域进行waf拦截 if param_scope ~= tl_ops_constant_waf_scope.service then - return false + return true end -- 是否开启拦截 @@ -166,12 +165,12 @@ local tl_ops_waf_core_param_filter_service_pass = function(service_name) -- 配置列表 local param_list, _ = cache_param:get(tl_ops_constant_waf_param.cache_key.list); if not param_list then - return false + return true end local param_list_table = cjson.decode(param_list); if not param_list_table then - return false + return true end -- 获取当前参数 @@ -277,165 +276,8 @@ local tl_ops_waf_core_param_filter_service_pass = function(service_name) end --- 匹配到节点层拦截 --- true : 通过, false : 拦截 -local tl_ops_waf_core_param_filter_node_pass = function(service_name, node_id) - if not service_name or not node_id then - return false - end - - -- 作用域 - local param_scope, _ = cache_param:get(tl_ops_constant_waf_param.cache_key.scope); - if not param_scope then - return false - end - - -- 根据作用域进行waf拦截 - if param_scope ~= tl_ops_constant_waf_scope.node then - return false - end - - -- 是否开启拦截 - local open, _ = cache_param:get(tl_ops_constant_waf_param.cache_key.open); - if not open then - return true - end - - -- 配置列表 - local param_list, _ = cache_param:get(tl_ops_constant_waf_param.cache_key.list); - if not param_list then - return false - end - - local param_list_table = cjson.decode(param_list); - if not param_list_table then - return false - end - - -- 获取当前参数 - local args = ngx.req.get_uri_args() - if not args then - return true - end - - local cur_host = ngx.var.host - if not cur_host then - return true - end - - tlog:dbg("tl_ops_waf_param get list ok, scope=",param_scope, ",host=",cur_host,",param=",args,",list=",param_list_table) - - -- 优先处理白名单 - for _, param in ipairs(param_list_table) do - repeat - local value = param.value - local host = param.host - local service = param.service - local node = param.node - local white = param.white - -- 非白名单跳过 - if not white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end - -- 参数k-v对比 - for arg_k ,arg_v in pairs(args) do - repeat - -- 未命中拦截规则,进行下一个 - local res, _ = find(unescape(arg_k .. "=" .. arg_v) , value , 'joi'); - if not res then - break - end - -- 白名单,不用后续比对,直接通过 - return true - until true - end - break - until true - end - - for _, param in ipairs(param_list_table) do - repeat - local value = param.value - local host = param.host - local service = param.service - local node = param.node - local white = param.white - -- 此前已处理白名单 - if white then - break - end - -- 域名为空跳过规则 - if host == nil or host == '' then - break - end - -- 域名不匹配跳过规则 - if host ~= "*" and host ~= cur_host then - break - end - -- 服务为空 - if service == nil or service == '' then - break - end - -- 服务不匹配 - if service ~= service_name then - break - end - -- 节点为空 - if node == nil or node == '' then - break - end - -- 节点不匹配 - if node ~= node_id then - break - end - -- 参数k-v对比 - for arg_k ,arg_v in pairs(args) do - repeat - -- 未命中拦截规则,进行下一个 - local res, _ = find(unescape(arg_k .. "=" .. arg_v) , value , 'joi'); - if not res then - break - end - -- 命中规则的param - return false - until true - end - break - until true - end - - tlog:dbg("tl_ops_waf_param done") - - return true -end - return { tl_ops_waf_core_param_filter_global_pass = tl_ops_waf_core_param_filter_global_pass, tl_ops_waf_core_param_filter_service_pass = tl_ops_waf_core_param_filter_service_pass, - tl_ops_waf_core_param_filter_node_pass = tl_ops_waf_core_param_filter_node_pass } \ No newline at end of file diff --git a/web/balance/tl_ops_web_api.js b/web/balance/tl_ops_web_api.js index 7a11fa7..05ba65b 100644 --- a/web/balance/tl_ops_web_api.js +++ b/web/balance/tl_ops_web_api.js @@ -358,7 +358,7 @@ const tl_ops_api_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_balance_api_list[rule].forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/balance/tl_ops_web_cookie.js b/web/balance/tl_ops_web_cookie.js index e71087c..ceb4622 100644 --- a/web/balance/tl_ops_web_cookie.js +++ b/web/balance/tl_ops_web_cookie.js @@ -260,6 +260,7 @@ const tl_ops_web_cookie_add = function () { if(!tl_ops_cookie_data_add_filter(data)){ return; } + $.ajax(tl_ajax_data({ url: '/tlops/balance/cookie/set', data : JSON.stringify(res_data), @@ -293,6 +294,7 @@ const tl_ops_web_cookie_edit = function (evtdata) { if(!tl_ops_cookie_data_edit_filter(data)){ return; } + $.ajax(tl_ajax_data({ url: '/tlops/balance/cookie/set', data : JSON.stringify(res_data), @@ -387,7 +389,7 @@ const tl_ops_cookie_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_balance_cookie_list[rule].forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/balance/tl_ops_web_header.js b/web/balance/tl_ops_web_header.js index e583a28..cf7610b 100644 --- a/web/balance/tl_ops_web_header.js +++ b/web/balance/tl_ops_web_header.js @@ -387,7 +387,7 @@ const tl_ops_header_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_balance_header_list[rule].forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/balance/tl_ops_web_param.js b/web/balance/tl_ops_web_param.js index 285cef7..20526d4 100644 --- a/web/balance/tl_ops_web_param.js +++ b/web/balance/tl_ops_web_param.js @@ -385,7 +385,7 @@ const tl_ops_param_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_balance_param_list[rule].forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/service/tl_ops_web_service.js b/web/service/tl_ops_web_service.js index 6450411..2e988f2 100644 --- a/web/service/tl_ops_web_service.js +++ b/web/service/tl_ops_web_service.js @@ -73,6 +73,11 @@ const tl_ops_web_service_cols = function () { allNodeOnline = false; } } + if(Object.keys(nodes).length === 0){ //无节点 + allNodeOnline = false; + } + }else{ //无节点 + allNodeOnline = false; } } if( allNodeOnline ){ @@ -90,7 +95,10 @@ const tl_ops_web_service_cols = function () { field: 'oper', title: '服务健康',width:"25%", templet : (d)=>{ let isNodeEmpty = d.node.length === 0; - let isChecking = !state_data.service[d.name].health_uncheck; + let isChecking = false; + if(state_data.service[d.name]){ + isChecking = !state_data.service[d.name].health_uncheck + } let isAutoLoad = rule === 'auto_load' return `
{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/waf/tl_ops_web_waf_api.js b/web/waf/tl_ops_web_waf_api.js index 1ed1825..1b2f05b 100644 --- a/web/waf/tl_ops_web_waf_api.js +++ b/web/waf/tl_ops_web_waf_api.js @@ -48,17 +48,15 @@ const tl_ops_web_waf_api_cols = function () { type:'checkbox',fixed : 'left', width: "5%" }, { field: 'id', title: 'ID',width:"10%" - }, { + }, { field: 'host', title: '域名',width:"15%" }, { - field: 'value', title: '正则过滤', width:"15%" - }, { - field: 'service', title: '所属服务',width:"10%" - }, { - field: 'node', title: '节点索引',width:"10%" - }, { + field: 'value', title: '正则过滤', width:"20%" + }, { + field: 'service', title: '所属服务',width:"15%" + }, { field: 'white', title: '白名单',width:"10%" - }, { + }, { field: 'updatetime', title: '更新时间',width:"15%", }, { width: "10%", @@ -100,7 +98,7 @@ const tl_ops_web_waf_api_render = function () { id="tl-waf-api-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_api_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-api-scope','点击切换作用域,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -143,7 +141,7 @@ const tl_ops_web_waf_api_reload = function (matcher) { id="tl-waf-api-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_api_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-api-scope','点击切换策略,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -197,18 +195,22 @@ const tl_ops_web_waf_api_change_scope = function () { return; } - layer.msg("暂不支持切换") + if(scope === 'global'){ + scope = 'service'; + }else if(scope === 'service'){ + scope = 'global'; + } - // res_data.tl_ops_waf_api_scope = scope; + res_data.tl_ops_waf_api_scope = scope; - // $.ajax(tl_ajax_data({ - // url: '/tlops/waf/api/set', - // data : JSON.stringify(res_data), - // contentType : "application/json", - // success : (res)=>{ - // tl_ops_web_waf_api_reload() - // } - // })); + $.ajax(tl_ajax_data({ + url: '/tlops/waf/api/set', + data : JSON.stringify(res_data), + contentType : "application/json", + success : (res)=>{ + tl_ops_web_waf_api_reload() + } + })); } @@ -251,7 +253,7 @@ const tl_ops_web_waf_api_edit = function (evtdata) { layer.open({ type: 2 ,title: '编辑API-WAF配置' - ,content: 'tl_ops_web_waf_api_form.html?service='+evtdata.service+"&node="+evtdata.node+"&white="+evtdata.white + ,content: 'tl_ops_web_waf_api_form.html?service='+evtdata.service+"&white="+evtdata.white+"&scope="+res_data.tl_ops_waf_api_scope ,maxmin: true ,minStack:false ,area: ['700px', '600px'] @@ -300,9 +302,6 @@ const tl_ops_waf_api_data_add_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -342,9 +341,6 @@ const tl_ops_waf_api_data_edit_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -355,7 +351,7 @@ const tl_ops_waf_api_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_waf_api_list.forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/waf/tl_ops_web_waf_api_form.html b/web/waf/tl_ops_web_waf_api_form.html index 46e7a9b..0985142 100644 --- a/web/waf/tl_ops_web_waf_api_form.html +++ b/web/waf/tl_ops_web_waf_api_form.html @@ -74,27 +74,7 @@
{{# } }} - -
- - +
diff --git a/web/waf/tl_ops_web_waf_api_form.js b/web/waf/tl_ops_web_waf_api_form.js index 21362bf..02b434e 100644 --- a/web/waf/tl_ops_web_waf_api_form.js +++ b/web/waf/tl_ops_web_waf_api_form.js @@ -3,11 +3,7 @@ const _form_id_name = "tl-ops-web-waf-api-form"; const _form_select_view_id_name = "tl-ops-web-waf-api-form-service-view"; const _form_select_tlp_id_name = "tl-ops-web-waf-api-form-service-tpl"; -const _form_select_service_id_name = "tl-ops-web-waf-api-form-service"; -const _form_select_node_view_id_name = "tl-ops-web-waf-api-form-service-node-view"; -const _form_select_node_tlp_id_name = "tl-ops-web-waf-api-form-service-node-tpl"; -const _form_select_node_service_id_name = "tl-ops-web-waf-api-form-service-node"; let service_data = {}; const tl_ops_web_waf_api_form_main = async function (){ @@ -16,17 +12,10 @@ const tl_ops_web_waf_api_form_main = async function (){ window.laytpl = layui.laytpl; window.layedit = layui.layedit; - // let rule_args = tl_request_get_param("rule"); - // if(rule_args === 'random'){ - // document.querySelector("#"+_form_select_node_view_id_name).style = 'display:none'; - // } - - //监听select - form.on('select', function(data){ - if(data.elem.id === _form_select_service_id_name){//service - tl_ops_web_waf_api_form_select_service_node_render(data.value) - } - }); + let scope_args = tl_request_get_param("scope"); + if(scope_args === 'global'){ + document.querySelector("#"+_form_select_view_id_name).style = 'display:none'; + } let res = await axios.get("/tlops/service/list"); res = res.data; @@ -39,9 +28,8 @@ const tl_ops_web_waf_api_form_main = async function (){ //处理编辑情况 let service_args = tl_request_get_param("service"); - let node_args = tl_request_get_param("node"); let white_args = tl_request_get_param("white"); - if(service_args || node_args || white_args){ + if(service_args || white_args){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { service : service_args })) @@ -49,12 +37,6 @@ const tl_ops_web_waf_api_form_main = async function (){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { white : white_args })) - - //渲染完tpl,进行编辑赋值 - tl_ops_web_waf_api_form_select_service_node_render( service_args ) - form.val(_form_id_name, Object.assign(form.val(_form_id_name), { - node : node_args - })) } }; @@ -67,16 +49,3 @@ const tl_ops_web_waf_api_form_select_service_render = function( ){ }); form.render() } - -const tl_ops_web_waf_api_form_select_service_node_render = function( service_name ){ - laytpl(document.getElementById(_form_select_node_tlp_id_name).innerHTML).render((()=>{ - if(!service_name){ - return [] - } - return service_data[service_name]; - })(), (html)=>{ - document.getElementById(_form_select_node_view_id_name).innerHTML = html; - }); - form.render() -} - diff --git a/web/waf/tl_ops_web_waf_cc.js b/web/waf/tl_ops_web_waf_cc.js index 9768dab..06b4ca5 100644 --- a/web/waf/tl_ops_web_waf_cc.js +++ b/web/waf/tl_ops_web_waf_cc.js @@ -48,17 +48,15 @@ const tl_ops_web_waf_cc_cols = function () { type:'checkbox',fixed : 'left', width: "5%" }, { field: 'id', title: 'ID',width:"10%" - }, { + }, { field: 'host', title: '域名',width:"15%" }, { - field: 'time', title: '时间周期', width:"10%" - }, { - field: 'count', title: '触发次数', width:"10%" - }, { + field: 'time', title: '时间周期', width:"15%" + }, { + field: 'count', title: '触发次数', width:"15%" + }, { field: 'service', title: '所属服务',width:"15%" - }, { - field: 'node', title: '节点索引',width:"10%" - }, { + }, { field: 'updatetime', title: '更新时间',width:"15%", }, { width: "10%", @@ -100,7 +98,7 @@ const tl_ops_web_waf_cc_render = function () { id="tl-waf-cc-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_cc_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-cc-scope','点击切换作用域,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -143,8 +141,8 @@ const tl_ops_web_waf_cc_reload = function (matcher) { id="tl-waf-cc-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_cc_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-cc-scope','点击切换策略,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; - + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; + return { "code": res.code, "msg": res.msg, @@ -197,18 +195,22 @@ const tl_ops_web_waf_cc_change_scope = function () { return; } - layer.msg("暂不支持切换") + if(scope === 'global'){ + scope = 'service'; + }else if(scope === 'service'){ + scope = 'global'; + } - // res_data.tl_ops_waf_cc_scope = scope; + res_data.tl_ops_waf_cc_scope = scope; - // $.ajax(tl_ajax_data({ - // url: '/tlops/waf/cc/set', - // data : JSON.stringify(res_data), - // contentType : "application/json", - // success : (res)=>{ - // tl_ops_web_waf_cc_reload() - // } - // })); + $.ajax(tl_ajax_data({ + url: '/tlops/waf/cc/set', + data : JSON.stringify(res_data), + contentType : "application/json", + success : (res)=>{ + tl_ops_web_waf_cc_reload() + } + })); } @@ -251,7 +253,7 @@ const tl_ops_web_waf_cc_edit = function (evtdata) { layer.open({ type: 2 ,title: '编辑CC-WAF配置' - ,content: 'tl_ops_web_waf_cc_form.html?service='+evtdata.service+"&node="+evtdata.node + ,content: 'tl_ops_web_waf_cc_form.html?service='+evtdata.service+"&scope="+res_data.tl_ops_waf_cc_scope ,maxmin: true ,minStack:false ,area: ['700px', '600px'] @@ -297,7 +299,7 @@ const tl_ops_waf_cc_data_add_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node' || key === 'time' || key === 'count'){ + if(key === 'time' || key === 'count'){ data.field[key] = parseInt(data.field[key]) } } @@ -329,16 +331,13 @@ const tl_ops_waf_cc_data_edit_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } - if(key === 'node' || key === 'time' || key === 'count'){ + if(key === 'time' || key === 'count'){ data.field[key] = parseInt(data.field[key]) } } let cur_list = [] res_data.tl_ops_waf_cc_list.forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/waf/tl_ops_web_waf_cc_form.html b/web/waf/tl_ops_web_waf_cc_form.html index bf9ebff..97ce4ed 100644 --- a/web/waf/tl_ops_web_waf_cc_form.html +++ b/web/waf/tl_ops_web_waf_cc_form.html @@ -75,26 +75,6 @@ {{# } }} -
- -
diff --git a/web/waf/tl_ops_web_waf_cc_form.js b/web/waf/tl_ops_web_waf_cc_form.js index 8f592b8..053d4cb 100644 --- a/web/waf/tl_ops_web_waf_cc_form.js +++ b/web/waf/tl_ops_web_waf_cc_form.js @@ -3,11 +3,7 @@ const _form_id_name = "tl-ops-web-waf-cc-form"; const _form_select_view_id_name = "tl-ops-web-waf-cc-form-service-view"; const _form_select_tlp_id_name = "tl-ops-web-waf-cc-form-service-tpl"; -const _form_select_service_id_name = "tl-ops-web-waf-cc-form-service"; -const _form_select_node_view_id_name = "tl-ops-web-waf-cc-form-service-node-view"; -const _form_select_node_tlp_id_name = "tl-ops-web-waf-cc-form-service-node-tpl"; -const _form_select_node_service_id_name = "tl-ops-web-waf-cc-form-service-node"; let service_data = {}; const tl_ops_web_waf_cc_form_main = async function (){ @@ -16,17 +12,10 @@ const tl_ops_web_waf_cc_form_main = async function (){ window.laytpl = layui.laytpl; window.layedit = layui.layedit; - // let rule_args = tl_request_get_param("rule"); - // if(rule_args === 'random'){ - // document.querySelector("#"+_form_select_node_view_id_name).style = 'display:none'; - // } - - //监听select - form.on('select', function(data){ - if(data.elem.id === _form_select_service_id_name){//service - tl_ops_web_waf_cc_form_select_service_node_render(data.value) - } - }); + let scope_args = tl_request_get_param("scope"); + if(scope_args === 'global'){ + document.querySelector("#"+_form_select_view_id_name).style = 'display:none'; + } let res = await axios.get("/tlops/service/list"); res = res.data; @@ -39,17 +28,10 @@ const tl_ops_web_waf_cc_form_main = async function (){ //处理编辑情况 let service_args = tl_request_get_param("service"); - let node_args = tl_request_get_param("node"); - if(service_args || node_args){ + if(service_args){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { service : service_args })) - - //渲染完tpl,进行编辑赋值 - tl_ops_web_waf_cc_form_select_service_node_render( service_args ) - form.val(_form_id_name, Object.assign(form.val(_form_id_name), { - node : node_args - })) } }; @@ -62,16 +44,3 @@ const tl_ops_web_waf_cc_form_select_service_render = function( ){ }); form.render() } - -const tl_ops_web_waf_cc_form_select_service_node_render = function( service_name ){ - laytpl(document.getElementById(_form_select_node_tlp_id_name).innerHTML).render((()=>{ - if(!service_name){ - return [] - } - return service_data[service_name]; - })(), (html)=>{ - document.getElementById(_form_select_node_view_id_name).innerHTML = html; - }); - form.render() -} - diff --git a/web/waf/tl_ops_web_waf_cookie.js b/web/waf/tl_ops_web_waf_cookie.js index e7f09cf..72c54e6 100644 --- a/web/waf/tl_ops_web_waf_cookie.js +++ b/web/waf/tl_ops_web_waf_cookie.js @@ -48,17 +48,15 @@ const tl_ops_web_waf_cookie_cols = function () { type:'checkbox',fixed : 'left', width: "5%" }, { field: 'id', title: 'ID',width:"10%" - }, { + }, { field: 'host', title: '域名',width:"15%" }, { - field: 'value', title: '正则过滤', width:"15%" - }, { - field: 'service', title: '所属服务',width:"10%" - }, { - field: 'node', title: '节点索引',width:"10%" - }, { + field: 'value', title: '正则过滤', width:"20%" + }, { + field: 'service', title: '所属服务',width:"15%" + }, { field: 'white', title: '白名单',width:"10%" - }, { + }, { field: 'updatetime', title: '更新时间',width:"15%", }, { width: "10%", @@ -100,7 +98,7 @@ const tl_ops_web_waf_cookie_render = function () { id="tl-waf-cookie-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_cookie_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-cookie-scope','点击切换作用域,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -143,8 +141,8 @@ const tl_ops_web_waf_cookie_reload = function (matcher) { id="tl-waf-cookie-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_cookie_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-cookie-scope','点击切换策略,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; - + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; + return { "code": res.code, "msg": res.msg, @@ -197,18 +195,22 @@ const tl_ops_web_waf_cookie_change_scope = function () { return; } - layer.msg("暂不支持切换") + if(scope === 'global'){ + scope = 'service'; + }else if(scope === 'service'){ + scope = 'global'; + } - // res_data.tl_ops_waf_cookie_scope = scope; + res_data.tl_ops_waf_cookie_scope = scope; - // $.ajax(tl_ajax_data({ - // url: '/tlops/waf/cookie/set', - // data : JSON.stringify(res_data), - // contentType : "application/json", - // success : (res)=>{ - // tl_ops_web_waf_cookie_reload() - // } - // })); + $.ajax(tl_ajax_data({ + url: '/tlops/waf/cookie/set', + data : JSON.stringify(res_data), + contentType : "application/json", + success : (res)=>{ + tl_ops_web_waf_cookie_reload() + } + })); } @@ -251,7 +253,7 @@ const tl_ops_web_waf_cookie_edit = function (evtdata) { layer.open({ type: 2 ,title: '编辑COOKIE-WAF配置' - ,content: 'tl_ops_web_waf_cookie_form.html?service='+evtdata.service+"&node="+evtdata.node+"&white="+evtdata.white + ,content: 'tl_ops_web_waf_cookie_form.html?service='+evtdata.service+"&white="+evtdata.white+"&scope="+res_data.tl_ops_waf_cookie_scope ,maxmin: true ,minStack:false ,area: ['700px', '600px'] @@ -300,9 +302,6 @@ const tl_ops_waf_cookie_data_add_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -342,9 +341,6 @@ const tl_ops_waf_cookie_data_edit_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -355,7 +351,7 @@ const tl_ops_waf_cookie_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_waf_cookie_list.forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/waf/tl_ops_web_waf_cookie_form.html b/web/waf/tl_ops_web_waf_cookie_form.html index c45feba..6b766d7 100644 --- a/web/waf/tl_ops_web_waf_cookie_form.html +++ b/web/waf/tl_ops_web_waf_cookie_form.html @@ -75,26 +75,6 @@ {{# } }} - - -
diff --git a/web/waf/tl_ops_web_waf_cookie_form.js b/web/waf/tl_ops_web_waf_cookie_form.js index 18a3ca3..8967672 100644 --- a/web/waf/tl_ops_web_waf_cookie_form.js +++ b/web/waf/tl_ops_web_waf_cookie_form.js @@ -3,11 +3,7 @@ const _form_id_name = "tl-ops-web-waf-cookie-form"; const _form_select_view_id_name = "tl-ops-web-waf-cookie-form-service-view"; const _form_select_tlp_id_name = "tl-ops-web-waf-cookie-form-service-tpl"; -const _form_select_service_id_name = "tl-ops-web-waf-cookie-form-service"; -const _form_select_node_view_id_name = "tl-ops-web-waf-cookie-form-service-node-view"; -const _form_select_node_tlp_id_name = "tl-ops-web-waf-cookie-form-service-node-tpl"; -const _form_select_node_service_id_name = "tl-ops-web-waf-cookie-form-service-node"; let service_data = {}; const tl_ops_web_waf_cookie_form_main = async function (){ @@ -16,17 +12,10 @@ const tl_ops_web_waf_cookie_form_main = async function (){ window.laytpl = layui.laytpl; window.layedit = layui.layedit; - // let rule_args = tl_request_get_param("rule"); - // if(rule_args === 'random'){ - // document.querySelector("#"+_form_select_node_view_id_name).style = 'display:none'; - // } - - //监听select - form.on('select', function(data){ - if(data.elem.id === _form_select_service_id_name){//service - tl_ops_web_waf_cookie_form_select_service_node_render(data.value) - } - }); + let scope_args = tl_request_get_param("scope"); + if(scope_args === 'global'){ + document.querySelector("#"+_form_select_view_id_name).style = 'display:none'; + } let res = await axios.get("/tlops/service/list"); res = res.data; @@ -39,9 +28,8 @@ const tl_ops_web_waf_cookie_form_main = async function (){ //处理编辑情况 let service_args = tl_request_get_param("service"); - let node_args = tl_request_get_param("node"); let white_args = tl_request_get_param("white"); - if(service_args || node_args || white_args){ + if(service_args || white_args){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { service : service_args })) @@ -49,12 +37,6 @@ const tl_ops_web_waf_cookie_form_main = async function (){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { white : white_args })) - - //渲染完tpl,进行编辑赋值 - tl_ops_web_waf_cookie_form_select_service_node_render( service_args ) - form.val(_form_id_name, Object.assign(form.val(_form_id_name), { - node : node_args - })) } }; @@ -67,16 +49,3 @@ const tl_ops_web_waf_cookie_form_select_service_render = function( ){ }); form.render() } - -const tl_ops_web_waf_cookie_form_select_service_node_render = function( service_name ){ - laytpl(document.getElementById(_form_select_node_tlp_id_name).innerHTML).render((()=>{ - if(!service_name){ - return [] - } - return service_data[service_name]; - })(), (html)=>{ - document.getElementById(_form_select_node_view_id_name).innerHTML = html; - }); - form.render() -} - diff --git a/web/waf/tl_ops_web_waf_header.js b/web/waf/tl_ops_web_waf_header.js index 9791ceb..9e935f1 100644 --- a/web/waf/tl_ops_web_waf_header.js +++ b/web/waf/tl_ops_web_waf_header.js @@ -53,13 +53,11 @@ const tl_ops_web_waf_header_cols = function () { }, { field: 'keys', title: 'header键', width:"15%" }, { - field: 'value', title: '正则过滤', width:"10%" + field: 'value', title: '正则过滤', width:"15%" }, { field: 'service', title: '所属服务',width:"10%" }, { - field: 'node', title: '节点索引',width:"8%" - }, { - field: 'white', title: '白名单',width:"7%" + field: 'white', title: '白名单',width:"10%" }, { field: 'updatetime', title: '更新时间',width:"15%", }, { @@ -102,8 +100,7 @@ const tl_ops_web_waf_header_render = function () { id="tl-waf-header-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_header_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-header-scope','点击切换作用域,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; - + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, "msg": res.msg, @@ -145,8 +142,7 @@ const tl_ops_web_waf_header_reload = function (matcher) { id="tl-waf-header-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_header_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-header-scope','点击切换策略,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; - + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, "msg": res.msg, @@ -199,18 +195,22 @@ const tl_ops_web_waf_header_change_scope = function () { return; } - layer.msg("暂不支持切换") + if(scope === 'global'){ + scope = 'service'; + }else if(scope === 'service'){ + scope = 'global'; + } - // res_data.tl_ops_waf_header_scope = scope; + res_data.tl_ops_waf_header_scope = scope; - // $.ajax(tl_ajax_data({ - // url: '/tlops/waf/header/set', - // data : JSON.stringify(res_data), - // contentType : "application/json", - // success : (res)=>{ - // tl_ops_web_waf_header_reload() - // } - // })); + $.ajax(tl_ajax_data({ + url: '/tlops/waf/header/set', + data : JSON.stringify(res_data), + contentType : "application/json", + success : (res)=>{ + tl_ops_web_waf_header_reload() + } + })); } @@ -253,7 +253,7 @@ const tl_ops_web_waf_header_edit = function (evtdata) { layer.open({ type: 2 ,title: '编辑HEADER-WAF配置' - ,content: 'tl_ops_web_waf_header_form.html?service='+evtdata.service+"&node="+evtdata.node+"&white="+evtdata.white + ,content: 'tl_ops_web_waf_header_form.html?service='+evtdata.service+"&white="+evtdata.white+"&scope="+res_data.tl_ops_waf_header_scope ,maxmin: true ,minStack:false ,area: ['700px', '600px'] @@ -302,9 +302,6 @@ const tl_ops_waf_header_data_add_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -352,9 +349,6 @@ const tl_ops_waf_header_data_edit_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -374,7 +368,7 @@ const tl_ops_waf_header_data_edit_filter = function( data ) { let cur_list = [] res_data.tl_ops_waf_header_list.forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/waf/tl_ops_web_waf_header_form.html b/web/waf/tl_ops_web_waf_header_form.html index ff3993d..10125b2 100644 --- a/web/waf/tl_ops_web_waf_header_form.html +++ b/web/waf/tl_ops_web_waf_header_form.html @@ -83,26 +83,6 @@ {{# } }} -
- -
diff --git a/web/waf/tl_ops_web_waf_header_form.js b/web/waf/tl_ops_web_waf_header_form.js index 31135af..10f2d8a 100644 --- a/web/waf/tl_ops_web_waf_header_form.js +++ b/web/waf/tl_ops_web_waf_header_form.js @@ -3,11 +3,7 @@ const _form_id_name = "tl-ops-web-waf-header-form"; const _form_select_view_id_name = "tl-ops-web-waf-header-form-service-view"; const _form_select_tlp_id_name = "tl-ops-web-waf-header-form-service-tpl"; -const _form_select_service_id_name = "tl-ops-web-waf-header-form-service"; -const _form_select_node_view_id_name = "tl-ops-web-waf-header-form-service-node-view"; -const _form_select_node_tlp_id_name = "tl-ops-web-waf-header-form-service-node-tpl"; -const _form_select_node_service_id_name = "tl-ops-web-waf-header-form-service-node"; let service_data = {}; const tl_ops_web_waf_header_form_main = async function (){ @@ -16,17 +12,10 @@ const tl_ops_web_waf_header_form_main = async function (){ window.laytpl = layui.laytpl; window.layedit = layui.layedit; - // let rule_args = tl_request_get_param("rule"); - // if(rule_args === 'random'){ - // document.querySelector("#"+_form_select_node_view_id_name).style = 'display:none'; - // } - - //监听select - form.on('select', function(data){ - if(data.elem.id === _form_select_service_id_name){//service - tl_ops_web_waf_header_form_select_service_node_render(data.value) - } - }); + let scope_args = tl_request_get_param("scope"); + if(scope_args === 'global'){ + document.querySelector("#"+_form_select_view_id_name).style = 'display:none'; + } let res = await axios.get("/tlops/service/list"); res = res.data; @@ -39,9 +28,8 @@ const tl_ops_web_waf_header_form_main = async function (){ //处理编辑情况 let service_args = tl_request_get_param("service"); - let node_args = tl_request_get_param("node"); let white_args = tl_request_get_param("white"); - if(service_args || node_args || white_args){ + if(service_args || white_args){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { service : service_args })) @@ -49,12 +37,6 @@ const tl_ops_web_waf_header_form_main = async function (){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { white : white_args })) - - //渲染完tpl,进行编辑赋值 - tl_ops_web_waf_header_form_select_service_node_render( service_args ) - form.val(_form_id_name, Object.assign(form.val(_form_id_name), { - node : node_args - })) } }; @@ -67,16 +49,3 @@ const tl_ops_web_waf_header_form_select_service_render = function( ){ }); form.render() } - -const tl_ops_web_waf_header_form_select_service_node_render = function( service_name ){ - laytpl(document.getElementById(_form_select_node_tlp_id_name).innerHTML).render((()=>{ - if(!service_name){ - return [] - } - return service_data[service_name]; - })(), (html)=>{ - document.getElementById(_form_select_node_view_id_name).innerHTML = html; - }); - form.render() -} - diff --git a/web/waf/tl_ops_web_waf_ip.js b/web/waf/tl_ops_web_waf_ip.js index e2a1bb4..2ae00d5 100644 --- a/web/waf/tl_ops_web_waf_ip.js +++ b/web/waf/tl_ops_web_waf_ip.js @@ -48,17 +48,15 @@ const tl_ops_web_waf_ip_cols = function () { type:'checkbox',fixed : 'left', width: "5%" }, { field: 'id', title: 'ID',width:"10%" - }, { + }, { field: 'host', title: '域名',width:"15%" }, { - field: 'value', title: '正则过滤', width:"15%" - }, { - field: 'service', title: '所属服务',width:"10%" - }, { - field: 'node', title: '节点索引',width:"10%" - }, { + field: 'value', title: '正则过滤', width:"20%" + }, { + field: 'service', title: '所属服务',width:"15%" + }, { field: 'white', title: '白名单',width:"10%" - }, { + }, { field: 'updatetime', title: '更新时间',width:"15%", }, { width: "10%", @@ -100,7 +98,7 @@ const tl_ops_web_waf_ip_render = function () { id="tl-waf-ip-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_ip_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-ip-scope','点击切换作用域,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -143,7 +141,7 @@ const tl_ops_web_waf_ip_reload = function (matcher) { id="tl-waf-ip-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_ip_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-ip-scope','点击切换策略,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -197,18 +195,22 @@ const tl_ops_web_waf_ip_change_scope = function () { return; } - layer.msg("暂不支持切换") + if(scope === 'global'){ + scope = 'service'; + }else if(scope === 'service'){ + scope = 'global'; + } - // res_data.tl_ops_waf_ip_scope = scope; + res_data.tl_ops_waf_ip_scope = scope; - // $.ajax(tl_ajax_data({ - // url: '/tlops/waf/ip/set', - // data : JSON.stringify(res_data), - // contentType : "application/json", - // success : (res)=>{ - // tl_ops_web_waf_ip_reload() - // } - // })); + $.ajax(tl_ajax_data({ + url: '/tlops/waf/ip/set', + data : JSON.stringify(res_data), + contentType : "application/json", + success : (res)=>{ + tl_ops_web_waf_ip_reload() + } + })); } @@ -251,7 +253,7 @@ const tl_ops_web_waf_ip_edit = function (evtdata) { layer.open({ type: 2 ,title: '编辑IP-WAF配置' - ,content: 'tl_ops_web_waf_ip_form.html?service='+evtdata.service+"&node="+evtdata.node+"&white="+evtdata.white + ,content: 'tl_ops_web_waf_ip_form.html?service='+evtdata.service+"&white="+evtdata.white+"&scope="+res_data.tl_ops_waf_ip_scope ,maxmin: true ,minStack:false ,area: ['700px', '600px'] @@ -300,9 +302,6 @@ const tl_ops_waf_ip_data_add_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -342,9 +341,6 @@ const tl_ops_waf_ip_data_edit_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -355,7 +351,7 @@ const tl_ops_waf_ip_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_waf_ip_list.forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/waf/tl_ops_web_waf_ip_form.html b/web/waf/tl_ops_web_waf_ip_form.html index b188496..31adc5b 100644 --- a/web/waf/tl_ops_web_waf_ip_form.html +++ b/web/waf/tl_ops_web_waf_ip_form.html @@ -75,26 +75,6 @@ {{# } }} -
- -
diff --git a/web/waf/tl_ops_web_waf_ip_form.js b/web/waf/tl_ops_web_waf_ip_form.js index 3abcae1..f1bb4b1 100644 --- a/web/waf/tl_ops_web_waf_ip_form.js +++ b/web/waf/tl_ops_web_waf_ip_form.js @@ -3,11 +3,7 @@ const _form_id_name = "tl-ops-web-waf-ip-form"; const _form_select_view_id_name = "tl-ops-web-waf-ip-form-service-view"; const _form_select_tlp_id_name = "tl-ops-web-waf-ip-form-service-tpl"; -const _form_select_service_id_name = "tl-ops-web-waf-ip-form-service"; -const _form_select_node_view_id_name = "tl-ops-web-waf-ip-form-service-node-view"; -const _form_select_node_tlp_id_name = "tl-ops-web-waf-ip-form-service-node-tpl"; -const _form_select_node_service_id_name = "tl-ops-web-waf-ip-form-service-node"; let service_data = {}; const tl_ops_web_waf_ip_form_main = async function (){ @@ -16,17 +12,10 @@ const tl_ops_web_waf_ip_form_main = async function (){ window.laytpl = layui.laytpl; window.layedit = layui.layedit; - // let rule_args = tl_request_get_param("rule"); - // if(rule_args === 'random'){ - // document.querySelector("#"+_form_select_node_view_id_name).style = 'display:none'; - // } - - //监听select - form.on('select', function(data){ - if(data.elem.id === _form_select_service_id_name){//service - tl_ops_web_waf_ip_form_select_service_node_render(data.value) - } - }); + let scope_args = tl_request_get_param("scope"); + if(scope_args === 'global'){ + document.querySelector("#"+_form_select_view_id_name).style = 'display:none'; + } let res = await axios.get("/tlops/service/list"); res = res.data; @@ -39,9 +28,8 @@ const tl_ops_web_waf_ip_form_main = async function (){ //处理编辑情况 let service_args = tl_request_get_param("service"); - let node_args = tl_request_get_param("node"); let white_args = tl_request_get_param("white"); - if(service_args || node_args || white_args){ + if(service_args || white_args){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { service : service_args })) @@ -49,12 +37,6 @@ const tl_ops_web_waf_ip_form_main = async function (){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { white : white_args })) - - //渲染完tpl,进行编辑赋值 - tl_ops_web_waf_ip_form_select_service_node_render( service_args ) - form.val(_form_id_name, Object.assign(form.val(_form_id_name), { - node : node_args - })) } }; @@ -67,16 +49,3 @@ const tl_ops_web_waf_ip_form_select_service_render = function( ){ }); form.render() } - -const tl_ops_web_waf_ip_form_select_service_node_render = function( service_name ){ - laytpl(document.getElementById(_form_select_node_tlp_id_name).innerHTML).render((()=>{ - if(!service_name){ - return [] - } - return service_data[service_name]; - })(), (html)=>{ - document.getElementById(_form_select_node_view_id_name).innerHTML = html; - }); - form.render() -} - diff --git a/web/waf/tl_ops_web_waf_param.js b/web/waf/tl_ops_web_waf_param.js index 4624f89..8a7a024 100644 --- a/web/waf/tl_ops_web_waf_param.js +++ b/web/waf/tl_ops_web_waf_param.js @@ -48,17 +48,15 @@ const tl_ops_web_waf_param_cols = function () { type:'checkbox',fixed : 'left', width: "5%" }, { field: 'id', title: 'ID',width:"10%" - }, { + }, { field: 'host', title: '域名',width:"15%" }, { - field: 'value', title: '正则过滤', width:"15%" - }, { - field: 'service', title: '所属服务',width:"10%" - }, { - field: 'node', title: '节点索引',width:"10%" - }, { + field: 'value', title: '正则过滤', width:"20%" + }, { + field: 'service', title: '所属服务',width:"15%" + }, { field: 'white', title: '白名单',width:"10%" - }, { + }, { field: 'updatetime', title: '更新时间',width:"15%", }, { width: "10%", @@ -100,7 +98,7 @@ const tl_ops_web_waf_param_render = function () { id="tl-waf-param-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_param_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-param-scope','点击切换作用域,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -143,7 +141,7 @@ const tl_ops_web_waf_param_reload = function (matcher) { id="tl-waf-param-scope" onmouseleave="tl_mouse_leave_tips()" onclick="tl_ops_web_waf_param_change_scope()" onmouseenter="tl_mouse_enter_tips('tl-waf-param-scope','点击切换策略,切换将实时生效')"> ${scope} - ( ${scope === 'global' ? '全局级别WAF' : (scope === 'service' ? '服务级别WAF': '节点级别WAF')} )`; + ( ${scope === 'global' ? '全局级别WAF' : '服务级别WAF'} )`; return { "code": res.code, @@ -197,18 +195,22 @@ const tl_ops_web_waf_param_change_scope = function () { return; } - layer.msg("暂不支持切换") + if(scope === 'global'){ + scope = 'service'; + }else if(scope === 'service'){ + scope = 'global'; + } - // res_data.tl_ops_waf_param_scope = scope; + res_data.tl_ops_waf_param_scope = scope; - // $.ajax(tl_ajax_data({ - // url: '/tlops/waf/param/set', - // data : JSON.stringify(res_data), - // contentType : "application/json", - // success : (res)=>{ - // tl_ops_web_waf_param_reload() - // } - // })); + $.ajax(tl_ajax_data({ + url: '/tlops/waf/param/set', + data : JSON.stringify(res_data), + contentType : "application/json", + success : (res)=>{ + tl_ops_web_waf_param_reload() + } + })); } @@ -251,7 +253,7 @@ const tl_ops_web_waf_param_edit = function (evtdata) { layer.open({ type: 2 ,title: '编辑PARAM-WAF配置' - ,content: 'tl_ops_web_waf_param_form.html?service='+evtdata.service+"&node="+evtdata.node+"&white="+evtdata.white + ,content: 'tl_ops_web_waf_param_form.html?service='+evtdata.service+"&white="+evtdata.white+"&scope="+res_data.tl_ops_waf_param_scope ,maxmin: true ,minStack:false ,area: ['700px', '600px'] @@ -300,9 +302,6 @@ const tl_ops_waf_param_data_add_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -342,9 +341,6 @@ const tl_ops_waf_param_data_edit_filter = function( data ) { layer.msg(key + "未填写") return false; } - if(key === 'node'){ - data.field[key] = parseInt(data.field[key]) - } if(key === 'white'){ if(data.field[key] === 'true'){ data.field[key] = true @@ -355,7 +351,7 @@ const tl_ops_waf_param_data_edit_filter = function( data ) { } let cur_list = [] res_data.tl_ops_waf_param_list.forEach((item)=>{ - if(item.id === data.field.id){ + if(parseInt(item.id) === parseInt(data.field.id)){ data.field.change = true; item = data.field; } diff --git a/web/waf/tl_ops_web_waf_param_form.html b/web/waf/tl_ops_web_waf_param_form.html index 05ad08f..c8c66f4 100644 --- a/web/waf/tl_ops_web_waf_param_form.html +++ b/web/waf/tl_ops_web_waf_param_form.html @@ -75,26 +75,6 @@ {{# } }} -
- -
diff --git a/web/waf/tl_ops_web_waf_param_form.js b/web/waf/tl_ops_web_waf_param_form.js index d28bd5d..48c01a4 100644 --- a/web/waf/tl_ops_web_waf_param_form.js +++ b/web/waf/tl_ops_web_waf_param_form.js @@ -3,11 +3,7 @@ const _form_id_name = "tl-ops-web-waf-param-form"; const _form_select_view_id_name = "tl-ops-web-waf-param-form-service-view"; const _form_select_tlp_id_name = "tl-ops-web-waf-param-form-service-tpl"; -const _form_select_service_id_name = "tl-ops-web-waf-param-form-service"; -const _form_select_node_view_id_name = "tl-ops-web-waf-param-form-service-node-view"; -const _form_select_node_tlp_id_name = "tl-ops-web-waf-param-form-service-node-tpl"; -const _form_select_node_service_id_name = "tl-ops-web-waf-param-form-service-node"; let service_data = {}; const tl_ops_web_waf_param_form_main = async function (){ @@ -16,17 +12,10 @@ const tl_ops_web_waf_param_form_main = async function (){ window.laytpl = layui.laytpl; window.layedit = layui.layedit; - // let rule_args = tl_request_get_param("rule"); - // if(rule_args === 'random'){ - // document.querySelector("#"+_form_select_node_view_id_name).style = 'display:none'; - // } - - //监听select - form.on('select', function(data){ - if(data.elem.id === _form_select_service_id_name){//service - tl_ops_web_waf_param_form_select_service_node_render(data.value) - } - }); + let scope_args = tl_request_get_param("scope"); + if(scope_args === 'global'){ + document.querySelector("#"+_form_select_view_id_name).style = 'display:none'; + } let res = await axios.get("/tlops/service/list"); res = res.data; @@ -39,9 +28,8 @@ const tl_ops_web_waf_param_form_main = async function (){ //处理编辑情况 let service_args = tl_request_get_param("service"); - let node_args = tl_request_get_param("node"); let white_args = tl_request_get_param("white"); - if(service_args || node_args || white_args){ + if(service_args || white_args){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { service : service_args })) @@ -49,12 +37,6 @@ const tl_ops_web_waf_param_form_main = async function (){ form.val(_form_id_name, Object.assign(form.val(_form_id_name), { white : white_args })) - - //渲染完tpl,进行编辑赋值 - tl_ops_web_waf_param_form_select_service_node_render( service_args ) - form.val(_form_id_name, Object.assign(form.val(_form_id_name), { - node : node_args - })) } }; @@ -67,16 +49,3 @@ const tl_ops_web_waf_param_form_select_service_render = function( ){ }); form.render() } - -const tl_ops_web_waf_param_form_select_service_node_render = function( service_name ){ - laytpl(document.getElementById(_form_select_node_tlp_id_name).innerHTML).render((()=>{ - if(!service_name){ - return [] - } - return service_data[service_name]; - })(), (html)=>{ - document.getElementById(_form_select_node_view_id_name).innerHTML = html; - }); - form.render() -} -