diff --git a/api/router/tl_ops_api_get_store.lua b/api/router/tl_ops_api_get_store.lua
index d0d8612..c9bacc9 100644
--- a/api/router/tl_ops_api_get_store.lua
+++ b/api/router/tl_ops_api_get_store.lua
@@ -101,6 +101,14 @@ local Router = function()
if not waf_cc_content then
waf_cc_content = {}
end
+ local auth, auth_size = read("tl-ops-auth.tlstore");
+ if not auth then
+ auth = {}
+ end
+ local time_alert, time_alert_size = read("tl-ops-time-alert.tlstore");
+ if not time_alert then
+ time_alert = {}
+ end
local res_data = {
api = {
@@ -207,6 +215,20 @@ local Router = function()
size = waf_cc_size,
version = #waf_cc_content,
list = waf_cc_content,
+ },
+ auth = {
+ id = 16,
+ name = "tl-ops-auth.tlstore",
+ size = auth_size,
+ version = #auth,
+ list = auth,
+ },
+ time_alert = {
+ id = 17,
+ name = "tl-ops-time-alert.tlstore",
+ size = time_alert_size,
+ version = #time_alert,
+ list = time_alert,
}
}
diff --git a/api/router/tl_ops_api_set_balance.lua b/api/router/tl_ops_api_set_balance.lua
index d550517..837658e 100644
--- a/api/router/tl_ops_api_set_balance.lua
+++ b/api/router/tl_ops_api_set_balance.lua
@@ -16,7 +16,7 @@ cjson.encode_empty_table_as_object(false)
local Router = function()
- local change = ""
+ local change = "success"
local service_empty, _ = tl_ops_utils_func:get_req_post_args_by_name("service_empty", 1);
if service_empty then
diff --git a/api/router/tl_ops_api_set_waf.lua b/api/router/tl_ops_api_set_waf.lua
index d8f416d..792e0ff 100644
--- a/api/router/tl_ops_api_set_waf.lua
+++ b/api/router/tl_ops_api_set_waf.lua
@@ -15,7 +15,7 @@ cjson.encode_empty_table_as_object(false)
local Router = function()
- local change = ""
+ local change = "success"
local waf_ip, _ = tl_ops_utils_func:get_req_post_args_by_name("waf_ip", 1);
if waf_ip then
diff --git a/bin/install_centeros.sh b/bin/install_centeros.sh
index d7e0603..de22624 100644
--- a/bin/install_centeros.sh
+++ b/bin/install_centeros.sh
@@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
-TL_OPS_VER="v2.8.9"
+TL_OPS_VER="v2.9.0"
echo_msg(){
cur_time=$(date "+%Y-%m-%d %H:%M:%S")
diff --git a/bin/install_ubuntu.sh b/bin/install_ubuntu.sh
index 69c844f..cdf8a97 100644
--- a/bin/install_ubuntu.sh
+++ b/bin/install_ubuntu.sh
@@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
-TL_OPS_VER="v2.8.9"
+TL_OPS_VER="v2.9.0"
echo_msg(){
cur_time=$(date "+%Y-%m-%d %H:%M:%S")
diff --git a/doc/change.md b/doc/change.md
index b822fce..992e91c 100644
--- a/doc/change.md
+++ b/doc/change.md
@@ -1,6 +1,31 @@
## 事务更新日程
+2022-09-15
+
+ 1. 支持登录插件配置实时修改
+
+ 2. 支持请求耗时告警策略实时修改
+
+ 3. 支持集群节点查看
+
+ 4. 调整部分插件变量命名
+
+ 5. 调整公共js文件路径
+
+ 6. 调整控制台展示名称错误
+
+ 7. 移除控制台调试日志
+
+ 8. 修复告警插件异常跳出问题
+
+ 9. 调整部分注释
+
+ 10. 负载和waf详情统计功能预告
+
+ 11. 事务日程调整
+
+
2022-09-08
1. 逐步支持模块测试用例
diff --git a/plugins/tl_ops_auth/auth.lua b/plugins/tl_ops_auth/auth.lua
index c8925f5..4d0d357 100644
--- a/plugins/tl_ops_auth/auth.lua
+++ b/plugins/tl_ops_auth/auth.lua
@@ -4,12 +4,15 @@
-- @author iamtsm
-- @email 1905333456@qq.com
+local cache = require("cache.tl_ops_cache_core"):new("tl-ops-auth");
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_auth")
-local auth_constant = require("plugins.tl_ops_auth.tl_ops_plugin_constant")
-local login_router = require("plugins.tl_ops_auth.login")
+local constant_auth = require("plugins.tl_ops_auth.tl_ops_plugin_constant")
+local login_router = require("plugins.tl_ops_auth.login_auth")
local cjson = require("cjson.safe")
local shared = tlops.plugin_shared
local utils = tlops.utils
+local cjson = require("cjson.safe");
+cjson.encode_empty_table_as_object(false)
local _M = {
_VERSION = '0.01'
@@ -21,10 +24,10 @@ function _M:new()
return setmetatable({}, mt)
end
--- 添加登录态
+-- 获取登录态
function _M:auth_get_session(id)
- local key = auth_constant.cache_key.session .. id
+ local key = constant_auth.cache_key.session .. id
tlog:dbg("auth_get_session, key=",key)
@@ -40,9 +43,21 @@ end
-- 添加登录态
function _M:auth_add_session(id, user)
- local key = auth_constant.cache_key.session .. id
+ local login_str, _ = cache:get(constant_auth.cache_key.login)
+ if not login_str then
+ tlog:err("auth_add_session get login cache err login_str=",login_str,",err=",_)
+ return
+ end
+
+ local login, _ = cjson.decode(login_str)
+ if not login then
+ tlog:err("auth_add_session decode login cache err login=",login,",err=",_)
+ return
+ end
+
+ local key = constant_auth.cache_key.session .. id
local value = cjson.encode(user)
- local time = auth_constant.login.auth_time
+ local time = login.auth_time
tlog:dbg("auth_add_session, key=",key,",value=",value,",time=",time)
@@ -57,7 +72,7 @@ end
-- 删除登录态
function _M:auth_del_session(id)
- local key = auth_constant.cache_key.session .. id
+ local key = constant_auth.cache_key.session .. id
tlog:dbg("auth_del_session, key=",key)
@@ -71,7 +86,7 @@ end
local uri_in_intercept_uri = function(ctx)
- for i, intercept_uri in ipairs(auth_constant.login.intercept) do
+ for i, intercept_uri in ipairs(constant_auth.login.intercept) do
if ngx.re.find(ctx.request_uri, intercept_uri, 'jo') then
return true
end
@@ -82,8 +97,20 @@ end
function _M:auth_core(ctx)
+ local login_str, _ = cache:get(constant_auth.cache_key.login)
+ if not login_str then
+ tlog:err("auth_core get login cache err login_str=",login_str,",err=",_)
+ return
+ end
+
+ local login, _ = cjson.decode(login_str)
+ if not login then
+ tlog:err("auth_core decode login cache err login=",login,",err=",_)
+ return
+ end
+
-- 处理白名单
- for i, filter_ui in ipairs(auth_constant.login.filter) do
+ for i, filter_ui in ipairs(login.filter) do
if ngx.re.find(ctx.request_uri, filter_ui, 'jo') then
return
end
@@ -96,7 +123,7 @@ function _M:auth_core(ctx)
-- cookie校验
local cookie_utils = require("lib.cookie"):new();
- local auth_cid, _ = cookie_utils:get(auth_constant.login.auth_cid);
+ local auth_cid, _ = cookie_utils:get(login.auth_cid);
if auth_cid ~= nil and auth_cid then
local session = self:auth_get_session(auth_cid)
if session then
@@ -106,7 +133,7 @@ function _M:auth_core(ctx)
-- header校验
local headers = ngx.req.get_headers()
- local auth_hid = headers[auth_constant.login.auth_hid]
+ local auth_hid = headers[login.auth_hid]
if auth_hid ~= nil then
local session = self:auth_get_session(auth_hid)
if session then
@@ -117,9 +144,9 @@ function _M:auth_core(ctx)
tlog:dbg("req uri no auth, uri=",ctx.request_uri)
utils:set_ngx_req_return_content(
- auth_constant.login.code,
- auth_constant.login.content,
- auth_constant.login.content_type
+ login.code,
+ login.content,
+ login.content_type
)
return
end
diff --git a/plugins/tl_ops_auth/get_auth.lua b/plugins/tl_ops_auth/get_auth.lua
new file mode 100644
index 0000000..8475210
--- /dev/null
+++ b/plugins/tl_ops_auth/get_auth.lua
@@ -0,0 +1,36 @@
+-- tl_ops_auth_get
+-- en : get auth config/list
+-- zn : 获取auth插件配置列表
+-- @author iamtsm
+-- @email 1905333456@qq.com
+
+local cache = require("cache.tl_ops_cache_core"):new("tl-ops-auth");
+local constant_auth = require("plugins.tl_ops_auth.tl_ops_plugin_constant");
+local tl_ops_rt = tlops.constant.comm.tl_ops_rt;
+local tl_ops_utils_func = tlops.utils
+local cjson = require("cjson.safe");
+cjson.encode_empty_table_as_object(false)
+
+
+local Router = function()
+
+ local list_str, _ = cache:get(constant_auth.cache_key.list);
+ if not list_str or list_str == nil then
+ tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found list", _);
+ return;
+ end
+
+ local login_str, _ = cache:get(constant_auth.cache_key.login);
+ if not login_str or login_str == nil then
+ tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found login", _);
+ return;
+ end
+
+ local res_data = {}
+ res_data[constant_auth.cache_key.list] = cjson.decode(list_str)
+ res_data[constant_auth.cache_key.login] = cjson.decode(login_str)
+
+ tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
+end
+
+return Router
\ No newline at end of file
diff --git a/plugins/tl_ops_auth/login.lua b/plugins/tl_ops_auth/login_auth.lua
similarity index 59%
rename from plugins/tl_ops_auth/login.lua
rename to plugins/tl_ops_auth/login_auth.lua
index 7e23247..a33b0ed 100644
--- a/plugins/tl_ops_auth/login.lua
+++ b/plugins/tl_ops_auth/login_auth.lua
@@ -4,14 +4,16 @@
-- @author iamtsm
-- @email 1905333456@qq.com
+local cache = require("cache.tl_ops_cache_core"):new("tl-ops-auth");
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_auth")
-local auth_constant = require("plugins.tl_ops_auth.tl_ops_plugin_constant")
+local constant_auth = require("plugins.tl_ops_auth.tl_ops_plugin_constant")
local auth = require("plugins.tl_ops_auth.auth")
local uuid = require("lib.jit-uuid")
local utils = tlops.utils
local shared = tlops.plugin_shared
local tl_ops_rt = tlops.constant.comm.tl_ops_rt
-
+local cjson = require("cjson.safe");
+cjson.encode_empty_table_as_object(false)
local Router = function()
@@ -27,18 +29,42 @@ local Router = function()
return;
end
- for i, user in ipairs(auth_constant.list) do
+ local login_str, _ = cache:get(constant_auth.cache_key.login)
+ if not login_str then
+ utils:set_ngx_req_return_ok(tl_ops_rt.args_error ,"auth login_str err3", _);
+ return
+ end
+
+ local login, _ = cjson.decode(login_str)
+ if not login then
+ utils:set_ngx_req_return_ok(tl_ops_rt.args_error ,"auth login err4", _);
+ return
+ end
+
+ local list_str, _ = cache:get(constant_auth.cache_key.list)
+ if not list_str then
+ utils:set_ngx_req_return_ok(tl_ops_rt.args_error ,"auth list_str err5", _);
+ return
+ end
+
+ local list, _ = cjson.decode(list_str)
+ if not list then
+ utils:set_ngx_req_return_ok(tl_ops_rt.args_error ,"auth list err6", _);
+ return
+ end
+
+ for i, user in ipairs(list) do
if user.username == username and user.password == password then
-- add cookie
local cookie_utils = require("lib.cookie"):new();
local auth_cid = uuid()
cookie_utils:set({
- key = auth_constant.login.auth_cid,
+ key = login.auth_cid,
value = auth_cid,
path = "/",
domain = ngx.var.host,
httponly = true,
- max_age = auth_constant.login.auth_time,
+ max_age = login.auth_time,
})
-- add session
diff --git a/plugins/tl_ops_auth/set_auth.lua b/plugins/tl_ops_auth/set_auth.lua
new file mode 100644
index 0000000..69f1584
--- /dev/null
+++ b/plugins/tl_ops_auth/set_auth.lua
@@ -0,0 +1,61 @@
+-- tl_ops_set_auth
+-- en : set auth config/list
+-- zn : 更新auth插件配置列表
+-- @author iamtsm
+-- @email 1905333456@qq.com
+
+local snowflake = require("lib.snowflake");
+local cache = require("cache.tl_ops_cache_core"):new("tl-ops-auth");
+local constant_auth = require("plugins.tl_ops_auth.tl_ops_plugin_constant");
+local tl_ops_rt = tlops.constant.comm.tl_ops_rt;
+local tl_ops_utils_func = tlops.utils
+local cjson = require("cjson.safe");
+cjson.encode_empty_table_as_object(false)
+
+
+local Router = function()
+
+ local change = "success"
+
+ local list, _ = tl_ops_utils_func:get_req_post_args_by_name(constant_auth.cache_key.list, 1);
+ if list then
+ -- 更新生成id
+ for _, user in ipairs(list) do
+ if not user.id or user.id == nil or user.id == '' then
+ user.id = snowflake.generate_id( 100 )
+ end
+ if not user.updatetime or user.updatetime == nil or user.updatetime == '' then
+ user.updatetime = ngx.localtime()
+ end
+ if user.change and user.change == true then
+ user.updatetime = ngx.localtime()
+ user.change = nil
+ end
+ end
+
+ local res, _ = cache:set(constant_auth.cache_key.list, cjson.encode(list));
+ if not res then
+ tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.error, "set list err ", _)
+ return;
+ end
+
+ change = "list"
+ end
+
+ local login, _ = tl_ops_utils_func:get_req_post_args_by_name(constant_auth.cache_key.login, 1);
+ if login then
+ local res, _ = cache:set(constant_auth.cache_key.login, cjson.encode(login));
+ if not res then
+ tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.error, "set login err ", _)
+ return;
+ end
+
+ change = "login"
+ end
+
+ local res_data = {}
+
+ tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, change, res_data)
+ end
+
+return Router
diff --git a/plugins/tl_ops_auth/sync.lua b/plugins/tl_ops_auth/sync.lua
new file mode 100644
index 0000000..25d71bc
--- /dev/null
+++ b/plugins/tl_ops_auth/sync.lua
@@ -0,0 +1,213 @@
+-- tl_ops_auth_sync
+-- en : sync auth config list
+-- zn : 同步、预热登录权限相关数据
+-- @author iamtsm
+-- @email 1905333456@qq.com
+
+local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_auth")
+local cache = require("cache.tl_ops_cache_core"):new("tl-ops-auth")
+local constant_auth = require("plugins.tl_ops_auth.tl_ops_plugin_constant")
+local tl_ops_rt = tlops.constant.comm.tl_ops_rt
+local cjson = require("cjson.safe")
+cjson.encode_empty_table_as_object(false)
+
+
+-- 静态文件中的未同步到store的配置数据
+local sync_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
+
+
+
+local sync_fields_list_config = function()
+
+ local cache_key_list = constant_auth.cache_key.list;
+
+ local demo = constant_auth.demo.list
+
+ local data_str, _ = cache:get(cache_key_list);
+ if not data_str then
+ local res, _ = cache:set(cache_key_list, cjson.encode(constant_auth.list))
+ if not res then
+ tlog:err("auth list sync_fields new store data err, res=",res)
+ return tl_ops_rt.error
+ end
+
+ data_str, _ = cache:get(cache_key_list)
+
+ tlog:dbg("auth list sync_fields new store data, res=",res)
+ end
+
+ local data = cjson.decode(data_str);
+ if not data and type(data) ~= 'table' then
+ tlog:err("auth sync_fields err, old=",data)
+ return tl_ops_rt.error
+ end
+
+ tlog:dbg("auth list sync_fields start, old=",data)
+
+ local add_keys = {}
+
+ -- demo fileds check
+ for key , _ in pairs(demo) do
+ -- data fileds check
+ for i = 1, #data do
+ -- add keys
+ if data[i][key] == nil then
+ data[i][key] = demo[key]
+ table.insert(add_keys , {
+ key = data[i][key]
+ })
+ end
+ end
+ end
+
+ local res = cache:set(cache_key_list, cjson.encode(data))
+ if not res then
+ tlog:err("auth list sync_fields err, res=",res,",new=",data)
+ return tl_ops_rt.error
+ end
+
+ tlog:dbg("auth list sync_fields done, new=",data,",add_keys=",add_keys)
+
+ return tl_ops_rt.ok
+end
+
+
+local sync_fields_login_config = function()
+
+ local cache_keys = {
+ login = {
+ cache_key = constant_auth.cache_key.login,
+ constant = constant_auth.login,
+ demo = constant_auth.demo.login
+ }
+ }
+
+ for key, obj in pairs(cache_keys) do
+ local cache_key = obj.cache_key
+ local constant_data = obj.constant
+ local demo = obj.demo
+
+ local data_str, _ = cache:get(cache_key);
+ if not data_str then
+ local res, _ = cache:set(cache_key, cjson.encode(constant_data))
+ if not res then
+ tlog:err("auth login sync_fields new store err, cache_key=",cache_key,",res=",res)
+ break
+ end
+
+ data_str, _ = cache:get(cache_key);
+
+ tlog:dbg("auth login sync_fields new store, cache_key=",cache_key,",res=",res)
+ end
+
+ local data = cjson.decode(data_str);
+ if not data and type(data) ~= 'table' then
+ tlog:err("auth login sync_fields err, cache_key=",cache_key,",old=",data)
+ break
+ end
+
+ tlog:dbg("auth login sync_fields start, cache_key=",cache_key,",old=",data)
+
+ local add_keys = {}
+
+ -- demo fileds check
+ for key , _ in pairs(demo) do
+ -- data fileds check
+ -- add keys
+ if data[key] == nil then
+ data[key] = demo[key]
+ table.insert(add_keys , key)
+ end
+ end
+
+ local res = cache:set(cache_key, cjson.encode(data))
+ if not res then
+ tlog:err("auth login sync_fields err, cache_key=",cache_key,",res=",res,",new=",data)
+ break
+ end
+
+ tlog:dbg("auth login sync_fields done, cache_key=",cache_key,",new=",data,",add_keys=",add_keys)
+ end
+
+ return tl_ops_rt.ok
+end
+
+
+
+-- 静态配置数据同步
+local sync_data = function ()
+ local cache_key_list = constant_auth.cache_key.list
+
+ local data_str, _ = cache:get(cache_key_list);
+ if not data_str then
+ local res, _ = cache:set(cache_key_list, cjson.encode(constant_auth.list))
+ if not res then
+ tlog:err("auth sync_data new store data err, res=",res)
+ return tl_ops_rt.error
+ end
+
+ tlog:dbg("auth sync_data 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("auth sync_data err, old=",data)
+ return tl_ops_rt.error
+ end
+
+ tlog:dbg("auth sync_data start, old=",data)
+
+ -- 静态配置
+ local constant_data = constant_auth.list
+
+ -- 获取需要同步的配置
+ local add = sync_data_need_sync(constant_data, data)
+ for i = 1, #add do
+ table.insert(data, add[i])
+ end
+
+ local res = cache:set(cache_key_list, cjson.encode(data))
+ if not res then
+ tlog:err("auth sync_data err, res=",res,",new=",data)
+ return tl_ops_rt.error
+ end
+
+ tlog:dbg("auth sync_data done, new=",data)
+
+ return tl_ops_rt.ok
+end
+
+
+
+-- 字段数据同步
+local sync_fields = function ()
+
+ sync_fields_list_config()
+
+ sync_fields_login_config()
+
+ return tl_ops_rt.ok
+end
+
+
+
+return {
+ sync_data = sync_data,
+ sync_fields = sync_fields
+}
\ No newline at end of file
diff --git a/plugins/tl_ops_auth/tl_ops_plugin_constant.lua b/plugins/tl_ops_auth/tl_ops_plugin_constant.lua
index ea665bc..55be297 100644
--- a/plugins/tl_ops_auth/tl_ops_plugin_constant.lua
+++ b/plugins/tl_ops_auth/tl_ops_plugin_constant.lua
@@ -1,5 +1,5 @@
-local content_page = [[
+local default_content_page = [[