Authored by jie

去掉nginx的默认值&增加清空恶意IP&增加查询所有恶意IP接口

... ... @@ -192,6 +192,9 @@ local subscribe_mal_ips=function()
cache:delete("yh:mip:" .. ip)
ngx.log(ngx.INFO,"nginx subscribe del mal ip:" .. tostring(ip) .. ":" .. tostring(expire))
end
elseif t.type == "flush" then
cache:flush_all()
ngx.log(ngx.INFO,"nginx subscribe flush all mal ip")
end
end
... ...
... ... @@ -25,242 +25,3 @@ lua_context.lua_conf_cache=ngx.shared.ngxconf
lua_context.configs={}
-- api limit rate default conf
local api_rate_limit_conf={is_open=true,
api_rate_limit={
["app.yohocoin.total"]={100},
["app.yohocoin.subtract"]={100},
["app.yohocoin.add"]={100},
["app.yohocoin.lists"]={100},
["resources.simple.pice"]={600},
["app.product.data"]={600},
["app.product.promotion"]={600},
["app.coupons.queryProdPageCoupons"]={600},
["h5.product.intro"]={600},
["web.brand.banner"]={600},
["app.product.queryShopsInfoById"]={600},
["app.product.queryBuyLimit"]={600},
["app.product.intro"]={600},
["app.product.preference"]={160},
["app.product.shopPreference"]={120},
["app.product.supportService"]={600},
["app.consult.common"]={600},
["app.shop.queryShopsByBrandId"]={600},
["shop.coupons.list"]={600},
["show.recentShareOrderByProductId"]={600},
["app.consult.lastTwo"]={600},
["app.shopsdecorator.getList"]={600},
["app.shops.getIntro"]={600},
["app.shop.banner"]={600},
["web.productBanner.data"]={600},
["web.productModelcard.list"]={600},
["web.productComfort.data"]={600},
["web.productModelTry.data"]={600},
["app.passport.profile"]={400},
["app.activity.getlist"]={400},
["app.home.getInfoNum"]={100},
["app.invitecode.my"]={400},
["app.promotion.getCoupon"]={40,9999992,"人太多啦,稍后再试!"},
["app.coupons.couponSend"]={40,9999992,"人太多啦,稍后再试!"},
["app.coupons.sendCouponByConfig"]={40,9999992,"人太多啦,稍后再试!"},
["app.promotion.getACoupon"]={40,9999992,"人太多啦,稍后再试!"},
["app.coupons.couponsSend"]={40,9999992,"人太多啦,稍后再试!"},
["app.promotion.queryCouponCenter"]={160,9999992,"人太多啦,稍后再试!"},
["app.search.li"]={200},
["app.search.sales"]={160},
["app.search.word"]={400},
["app.limitProduct.hotLimitProduct"]={400},
["app.limitProduct.soonToSaleLimitProduct"]={400},
["app.limitProduct.alreadySaleLimitProduct"]={400},
["app.limitProduct.limitProductHtml"]={400},
["app.limitProduct.limitProductDetail"]={400},
["app.limitProduct.productStatus"]={400},
["app.Shopping.count"]={400},
["app.home.newPreference"]={200},
["app.Shopping.easyPayment"]={40,9999992,"人太多啦,稍后再试!"},
["app.Shopping.easyCompute"]={40,9999992,"人太多啦,稍后再试!"},
["app.Shopping.easySubmit"]={40,9999992,"人太多啦,稍后再试!"},
["app.inbox.getTotal"]={80},
["web.regular.groupsort"]={600},
["web.search.search"]={500},
["web.search.shopListInfo"]={600},
["web.brand.byDomain"]={600},
["web.search.newshelve"]={1000},
["web.search.newShelveBatch"]={600},
["web.regular.groupsort.sale"]={600},
["app.Seckill.payment"]={60,9999992,"活动太火爆了,商品已被秒完!"},
["app.Seckill.compute"]={60,9999992,"活动太火爆了,商品已被秒完!"},
["app.Seckill.submit"]={40,9999992,"活动太火爆了,商品已被秒完!"},
["app.Seckill.countUsableCoupon"]={100},
["app.seckill.queryActivity"]={300,9999992,"人太多啦,稍后再试!"},
["app.seckill.queryProductList"]={300,9999992,"人太多啦,稍后再试!"},
["app.seckill.data"]={300,9999992,"人太多啦,稍后再试!"},
["app.shopping.submitTicket"]={80,9999992,"人太多啦,稍后再试!"},
["app.shopping.ticket"]={80,9999992,"人太多啦,稍后再试!"},
["app.Shopping.submit"]={100,9999992,"人太多啦,稍后再试!"},
["app.Shopping.compute"]={120,9999992,"人太多啦,稍后再试!"},
["app.Shopping.payment"]={120,9999992,"人太多啦,稍后再试!"},
["app.Shopping.enhancedPayment"]={120,9999992,"人太多啦,稍后再试!"},
["app.Shopping.selectCoupon"]={120,9999992,"人太多啦,稍后再试!"},
["app.Shopping.useCoupon"]={120,9999992,"人太多啦,稍后再试!"},
["app.Shopping.countUsableCoupon"]={200},
["app.Shopping.countUsableGiftCard"]={200},
["app.product.seckill.data"]={240,9999992,"人太多啦,稍后再试!"},
["app.product.seckill.promotion"]={240},
["app.product.seckill.intro"]={240},
["app.consult.seckill.common"]={240},
["app.shop.seckill.queryShopsByBrandId"]={240},
["app.consult.seckill.lastTwo"]={240},
["show.seckill.recentShareOrderByProductId"]={240},
["app.depositAdvance.data"]={400},
["app.limitTimeAdvance.data"]={400},
["app.product.shopRecommend"]={160},
["app.product.sizehelper.show"]={600},
["app.product.sizehelper.detail"]={600},
["app.show.instalment"]={600},
["clear.productCache"]={2000},
["app.helper.getServiceOnline"]={600},
["app.Shopping.queryCart"]={300},
["app.Shopping.queryCartCouponCenter"]={300},
["app.Shopping.selectedAndQryCart"]={300,9999992,"人太多啦,稍后再试!"},
["app.Shopping.add"]={100,9999992,"人太多啦,稍后再试!"},
["web.product.shopRecommend"]={40},
["app.coupons.queryUserCouponRemind"]={100},
["app.search.findLike"]={40},
["web.search.findLike"]={40},
["web.search.forseo"]={40},
["app.inbox.getAllInboxCatInfo"]={40},
["app.inbox.getlistnew"]={40},
["app.favorite.product"]={40},
["web.favorite.product"]={40},
["app.favorite.brand"]={40},
["app.coupons.total"]={80},
["app.promotion.couponStatus"]={80},
["app.activity.friendhelp"]={60,9999992,"人太多啦,稍后再试!"},
["user.instalment.activate"]={40},
["user.instalment.getStatus"]={200},
["user.instalment.getBankCards"]={10},
["user.instalment.queryCreditLimit"]={10,9999992,"人太多啦,稍后再试!"},
["user.instalment.getSnsCheckCode"]={10},
["user.instalment.getBankInfoByCardNo"]={10},
["user.instalment.getCardInfoById"]={10},
["app.search.instalment"]={20},
["app.promotion.instalment"]={50},
["app.order.queryAmtInfo"]={10,9999992,"人太多啦,稍后再试!"},
["app.order.queryAmtList"]={10,9999992,"人太多啦,稍后再试!"},
["app.order.queryRePayList"]={10,9999992,"人太多啦,稍后再试!"},
["app.instalment.condition"]={10,9999992,"人太多啦,稍后再试!"},
["app.instalment.pay"]={10,9999992,"人太多啦,稍后再试!"},
["app.instalment.prerepay"]={10,9999992,"人太多啦,稍后再试!"},
["app.instalment.confirmrepay"]={10,9999992,"人太多啦,稍后再试!"},
["app.Buynow.payment"]={10,9999992,"人太多啦,稍后再试!"},
["app.Buynow.countUsableCoupon"]={20},
["app.Buynow.enhancedPayment"]={20,9999992,"人太多啦,稍后再试!"},
["app.Buynow.selectCoupon"]={20},
["app.Buynow.listCoupon"]={20},
["app.Buynow.compute"]={20,9999992,"人太多啦,稍后再试!"},
["app.Buynow.submit"]={10,9999992,"人太多啦,稍后再试!"},
["app.Buynow.useCoupon"]={10},
["app.Buynow.usePromotionCode"]={10},
["app.SpaceOrders.getInstallment"]={10},
["app.SpaceOrders.installDetail"]={10},
["user.instalment.validateSnsCheckCode"]={10},
["user.instalment.reSendSms4FcpService"]={10},
["user.instalment.bindingCards"]={5},
["app.search.promotion"]={80},
["app.search.newPromotion"]={120},
["app.search.zq.filter"]={40},
["app.search.promotion.filter"]={40},
["app.search.coupon.filter"]={40},
["app.search.fuzzy.filter"]={40},
["app.search.category.filter"]={40},
["app.search.filter"]={40},
["app.search.breakSize.filter"]={40},
["app.search.pool.filter"]={40},
["app.search.shop.filter"]={40},
["app.search.good"]={40},
["app.search.fuzzy"]={120},
["app.search.category.productList"]={120},
["app.search.productList"]={120},
["app.search.recomandLi"]={60},
["app.search.shop.productList"]={120},
["app.search.promotion.productList"]={80},
["app.search.zq.productList"]={80},
["app.search.pool.productList"]={80},
["app.search.newProduct.shop"]={80},
["app.search.coupon.productList"]={80},
["app.search.newLast7day"]={120},
["app.resources.holidayGifConfig"]={400},
["app.passport.verify"]={80},
["clear.productCache.batch"]={200},
["/operations/api/v5/resource/get"]={800},
["/operations/api/v5/resource/home"]={400,9999992},
["/operations/api/v5/webshare/getShare"]={400},
["/operations/api/v5/entrance/getEntrance"]={400},
["/operations/api/v6/category/getCategory"]={400},
["/operations/api/v4/icon/getIcon"]={400},
["/guang/api/v1/article/getArticleNotice"]={100},
["/payment/alipay_data"]={200},
["/payment/applepay_data"]={200},
["/payment/weixin_data"]={200},
["/payment/alipay_notify"]={200},
["/payment/weixin_notify"]={200},
["/payment/applepay_notify"]={200},
["/erp/sync/promotion/update"]={600},
["/erp/clear/batch/productPriceCache"]={800}
}
}
-- limit ip access conf
local limit_ip_access={
is_open=true, white_ips={
"172.31.0.0/16",
"10.66.0.0/16",
"54.222.0.0/16",
"118.89.221.106/32",
"123.206.21.19/32",
"123.206.73.107/32",
"54.223.0.0/16"
},
ip_qps_limit={60,1},
interface_ip_qps_limit={
["app.bind.sendThirdBindMobileCodeOnly"]={15,2},
["app.bind.sendThirdBindMobileCodeOnlyImg"]={15,2},
["app.bind.sendChangeBindMobileCodeOnlyImg"]={15,2},
["/smart/way"]={20,3}
}
}
local common_conf={
-- this variable control limit ip & limit rate flow execute
-- true: open ,false: close
lua_golbal_switch = true
}
lua_context.configs["common_conf"]=common_conf
lua_context.configs["limit_ip_access"]=limit_ip_access
... ...
... ... @@ -49,11 +49,17 @@ end
function rate_limit()
local common_config=lua_context.configs["common_conf"]
local limit_config=lua_context.configs["api_rate_limit_conf"]
if (not common_config) or (not limit_config) then
return
end
if not common_config.lua_golbal_switch then
return
end
local limit_config=lua_context.configs["api_rate_limit_conf"]
local api_rate_limit=limit_config.api_rate_limit
local req_uri_method = extract_limit_method()
--ngx.log(ngx.INFO,"=================>>" .. cjson.encode(api_rate_limit[req_uri_method]))
... ...
... ... @@ -43,6 +43,9 @@ end
function M:limit_ip_access()
local limit_ip_config=lua_context.configs["limit_ip_access"]
local common_config=lua_context.configs["common_conf"]
if (not common_config) or (not limit_ip_config) then
return
end
-- global switch control
if not common_config.lua_golbal_switch then
return
... ... @@ -130,7 +133,7 @@ function M:mal_ip()
local ips=self:get_req_param("ips")
local expire=self:get_req_param("expire")
ngx.header["Content-type"]="application/json;charset=utf-8"
if not method or not ips then
if not method then
ngx.say('{"code": 400, "msg": "params error!"}')
ngx.exit(ngx.HTTP_OK)
end
... ... @@ -146,6 +149,15 @@ function M:mal_ip()
t.ips=ips
t.type="del"
redis_limit_ip:cmd("publish","mal_ips",cjson.encode(t))
elseif method == 'flushAll' then
local t={}
t.type="flush"
redis_limit_ip:cmd("publish","mal_ips",cjson.encode(t))
elseif method == 'queryAll' then
local all_ips=cache:get_keys(0)
for i,v in pairs(all_ips) do
exists[#exists+1]=string.sub(v,8,string.len(v))
end
else
for ip in string.gmatch(ips,"[^',']+") do
if method == 'add' then
... ...