Skip to content

Commit

Permalink
feat: 支持登录插件配置实时修改
Browse files Browse the repository at this point in the history
feat: 支持请求耗时告警策略实时修改
feat: 支持集群节点查看
feat: 调整部分插件变量命名
feat: 调整公共js文件路径
feat: 调整控制台展示名称错误
feat: 调整部分注释
feat: 负载和waf详情统计功能预告
feat: 事务日程调整
feat: 移除控制台调试日志
fix : 修复告警插件异常跳出问题
  • Loading branch information
tsm committed Sep 15, 2022
1 parent 9c4499b commit 21d46ba
Show file tree
Hide file tree
Showing 100 changed files with 2,402 additions and 228 deletions.
22 changes: 22 additions & 0 deletions api/router/tl_ops_api_get_store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/router/tl_ops_api_set_balance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/router/tl_ops_api_set_waf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/install_centeros.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion bin/install_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
25 changes: 25 additions & 0 deletions doc/change.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@

## 事务更新日程

2022-09-15

1. 支持登录插件配置实时修改

2. 支持请求耗时告警策略实时修改

3. 支持集群节点查看

4. 调整部分插件变量命名

5. 调整公共js文件路径

6. 调整控制台展示名称错误

7. 移除控制台调试日志

8. 修复告警插件异常跳出问题

9. 调整部分注释

10. 负载和waf详情统计功能预告

11. 事务日程调整


2022-09-08

1. 逐步支持模块测试用例
Expand Down
55 changes: 41 additions & 14 deletions plugins/tl_ops_auth/auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
-- @author iamtsm
-- @email [email protected]

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'
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions plugins/tl_ops_auth/get_auth.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- tl_ops_auth_get
-- en : get auth config/list
-- zn : 获取auth插件配置列表
-- @author iamtsm
-- @email [email protected]

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
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
-- @author iamtsm
-- @email [email protected]

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()

Expand All @@ -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
Expand Down
61 changes: 61 additions & 0 deletions plugins/tl_ops_auth/set_auth.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- tl_ops_set_auth
-- en : set auth config/list
-- zn : 更新auth插件配置列表
-- @author iamtsm
-- @email [email protected]

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
Loading

0 comments on commit 21d46ba

Please sign in to comment.