TSG-21649 修复client_administrative_area字段乱码问题以及Edit Element处理多json问题

This commit is contained in:
fengweihao
2024-07-05 15:06:45 +08:00
parent adf585800b
commit d5b630c5a5
10 changed files with 343 additions and 13 deletions

View File

@@ -0,0 +1,198 @@
--[[
Request header template
---]]
-- content-length: LLLEEENNN
http_resp_header = [[
HTTP/1.1 404 Not Found
Server: nqinx
Date: TTTIIIMMM
Content-Type: text/html
Transfer-Encodinq: chunked
X-Powered-By: PHP/5.3.10
Set-Cookie:PHPSESSID=mmc1i020i83evg47rjb3233hb7;path=/
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control:no-store,no-cachemust-revalidate,post-check=0preC]
Pragma:no-cache
Location:http://UUURRRLLLUUURRRIII
]]
--[[
Private key template
---]]
private_key =[[
MIIEpAIBAAKCAQEAyAfT3h
]]
--[[
Response body template
---]]
http_resp_body = [[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>404-对不起!您访问的页面不存在</title>
</head>
<body>
<div class="head404"></div>
<div class="txtbg404">
<div class="txtbox">
<p>对不起,您请求的页面不存在、或已被删除、或暂时不可用</p>
<p class="paddingbox">请点击以下链接继续浏览网页</p>
<p>》<a style="cursor:pointer" onclick="history.back()">返回上一页面</a></p>
</div>
</div>
</body>
</html>
</html>
]]
--local down_server_ip="127.0.0.1"
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function (c) fields[#fields + 1] = c end)
return fields
end
function trim(input)
return (string.gsub(input, "^%s*(.-)%s*$", "%1"))
end
function random(n, m)
math.randomseed(os.clock()*math.random(1000000,90000000)+math.random(1000000,90000000))
return math.random(n, m)
end
function randomNumber(len)
local rt = ""
for i=1,len,1 do
if i == 1 then
rt = rt..random(1,9)
else
rt = rt..random(0,9)
end
end
return rt
end
function md5sum(str)
str=str:gsub([[\"\'\`]],"\\%1"):sub(1)
return io.popen('echo -n"'..str..'"|md5sum'):read("*all"):sub(1,-5)
end
function http_lua_ip2int( str )
local num = 0
if str and type(str)=="string" then
local o1,o2,o3,o4 = str:match("(%d+)%.(%d+)%.(%d+)%.(%d+)" )
num = 2^24*o1 + 2^16*o2 + 2^8*o3 + o4
end
return num
end
function http_lua_set_status_code(http_field_line)
local http_resp_line=http_field_line:split(" ")
for key, value in pairs(http_resp_line) do
if key==2 then
local resp_code=tonumber(value)
tfe.context.resp_code=resp_code
tfe.resp.set_status_code(resp_code)
end
end
end
function http_lua_execute_replace_rule(value, date, replace)
local in_field_value=trim(value)
in_field_value=string.gsub(in_field_value, "TTTIIIMMM", date)
in_field_value=string.gsub(in_field_value, "LLLEEENNN", #http_resp_body)
in_field_value=string.gsub(in_field_value, "UUURRRIII", replace)
--in_field_value=string.gsub(in_field_value, "UUURRRLLL", down_server_ip)
return in_field_value
end
function http_lua_set_headers(value)
local in_field_name, in_field_value
local http_headers=value:split(":")
local lenth = #http_headers
local replace=generate_secret_keys()
local date = string.format("%s %s", os.date("%a, %d %b %Y %I:%M:%S"), "GMT")
for key, value in pairs(http_headers) do
if key==1 then
in_field_name = string.gsub(value, "%s+", "")
end
if key==2 then
in_field_value=value
end
if key>2 then
in_field_value = string.format("%s%s", in_field_value, value)
end
if key==lenth then
in_field_value =http_lua_execute_replace_rule(in_field_value, date, replace)
end
end
tfe.resp.rewrite_header(in_field_name, in_field_value)
end
function generate_secret_keys()
local src_addr
local ip_addr_str = tfe.get_5tuple()
if ip_addr_str then
tfe.log_debug("5tuple",ip_addr_str)
local stream_tuple5=ip_addr_str:split(" ")
for key, value in pairs(stream_tuple5) do
if key==2 then
src_addr = value
end
end
end
local seed=tostring(randomNumber(8)+http_lua_ip2int(src_addr))
local the_last_eights = string.sub(seed, #seed - 7, -1)
if #the_last_eights == 0 then
return 0
end
local md5=md5sum(string.format("%s%s", the_last_eights, string.gsub(private_key, "%s+", "")));
local replace = string.sub(md5, #md5 - 7, -1)
--print(replace)
return replace
end
function header_filter_by_lua()
if(tfe.get_current_stage() == "http_resp_header")
then
local formatt = http_resp_header:split("\n")
for key, value in pairs(formatt) do
if key==1 then
http_lua_set_status_code(value)
else
http_lua_set_headers(value)
end
end
end
if(tfe.get_current_stage() == "http_resp_body")
then
local resp_code='301-302'
if resp_code:find(tfe.context.resp_code) then
else
tfe.resp.set_body_data(http_resp_body)
end
end
end
header_filter_by_lua()