local config = require("config") local util = require("util") local agent_pub = require("agent_pub") local logout_url = "/wolf/rbac/logout" local change_pwd_url = "/wolf/rbac/change_pwd.html" local def_topbar_style = [[ ]] local topbar_tpl = [[
%s
USER: %s(%s)
]] local function get_style() return def_topbar_style end local function get_infobar() local username = "NONE" local nickname = "UNKNOW" local userInfo = ngx.ctx.userInfo if userInfo then username = userInfo.username nickname = userInfo.nickname or '' elseif ngx.var.arg_username then username = ngx.var.arg_username nickname = ngx.var.arg_nickname or '' end local href = string.format([[href="%s" target="_blank"]], change_pwd_url) if config.not_allow_change_pwd then href = string.format([[href="#" onclick="javascript:alert('Password change is not allowed');"]]) end ngx.log(ngx.INFO, "user [", username, "](", nickname, ") request...") local replace = get_style() .. string.format(topbar_tpl, config.sysname or 'WOLF-RBAC', username, nickname, href, logout_url) return true, replace end ngx.log(ngx.DEBUG, "url:", ngx.var.uri) if agent_pub.need_replace() then local ok, infobar = get_infobar() if ok then local n = nil if ngx.var.uri == "/" or util.endswith(ngx.var.uri, "/") then ngx.arg[1], n = ngx.re.sub(ngx.arg[1], "\\]*\\>", "$0 " .. infobar , "jom") else ngx.arg[1] = ngx.re.sub(ngx.arg[1], [[]], infobar , "jom") end ngx.ctx.topbar_added = (n==1) ngx.log(ngx.INFO, "### add infobar. ### n:", tostring(ngx.ctx.topbar_added)) end else ngx.log(ngx.INFO, "---- ignore url: ", ngx.var.uri); end