agent_pub.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. local _M = {}
  2. local login_url = "/wolf/rbac/login.html"
  3. local login_post_url = "/wolf/rbac/login.submit"
  4. local logout_url = "/wolf/rbac/logout"
  5. local no_permission = "/wolf/rbac/no_permission"
  6. local no_permission_html = "/wolf/rbac/no_permission.html"
  7. local access_check_url = "/wolf/rbac/access_check"
  8. local change_pwd_url = "/wolf/rbac/change_pwd.html"
  9. local change_pwd_post_url = "/wolf/rbac/change_pwd.submit"
  10. local ignore_list = {login_url, login_post_url,logout_url,no_permission,no_permission_html,access_check_url, change_pwd_url, change_pwd_post_url}
  11. function _M.is_ignore_url(url)
  12. if ignore_list == nil then
  13. return false
  14. end
  15. local matched = false
  16. if type(ignore_list)=='table' then
  17. for i, item in ipairs(ignore_list) do
  18. if item == url then
  19. matched = true
  20. break
  21. end
  22. end
  23. end
  24. return matched
  25. end
  26. local function split(s, delimiter)
  27. local result = {};
  28. for match in string.gmatch(s, "[^"..delimiter.."]+") do
  29. table.insert(result, match);
  30. end
  31. return result;
  32. end
  33. local function need_replace_internal()
  34. if _M.is_ignore_url(ngx.var.uri) then
  35. ngx.log(ngx.INFO, "### filter ignore : ", ngx.var.uri)
  36. return false
  37. end
  38. local contentType = ngx.header["Content-Type"]
  39. if contentType == nil then
  40. ngx.log(ngx.INFO, "---- ignore type: ", tostring(contentType));
  41. return false
  42. end
  43. local arr = split(contentType, ";")
  44. contentType = arr[1]
  45. return contentType == "text/plain" or contentType == "text/html"
  46. end
  47. function _M.need_replace()
  48. if ngx.ctx.need_replace == nil then
  49. ngx.ctx.need_replace = need_replace_internal()
  50. end
  51. return ngx.ctx.need_replace
  52. end
  53. return _M