4 host_Mod - starjun/starjun.github.io GitHub Wiki
host_Mod 基于域名网站的私有规则模块
该模块是整个访问控制的 第四步 ,是基于host的私有规则配置,和其他 host 不会有交叉影响
所有域名的总开关配置
[
["127.0.0.1","on"],
# 第一个参数:域名名称(host),第二个:开关(on/log/off)
["localhost","on"],
["pass.game.com","off"],
["101.200.122.200","log"],
... # 其他域名开关规则
]
对应域名的访问控制规则
[
{
"state": "on",
# 本条规则开关 (on = 开启,off = 关闭)
"action": ["allow","uri"],
# 第一个参数是:执行动作,第二个:匹配字段
"uri": ["\\.(css|js|flv|swf|woff|txt)$","jio"]
# 匹配uri的条件 这里是用正则进行匹配
# 第一个参数:匹配内容,第二个:匹配方式
},
{
"state": "on",
"action":["log","referer"],
# 第一个参数是:执行动作,第二个:匹配字段
"uri": ["\\.(gif|jpg|png|jpeg|bmp|ico)$","jio"],
"referer": ["hao123","in",true]
# 匹配referer 这里是要匹配 referer不包含hao123
# 第一个参数:匹配内容,第二个:匹配方式,第三个:是否取反
},
{
"state": "on",
"action":["deny","useragent"],
"useragent": ["baidu","in"]
},
{
"state": "on",
"action":["deny","app_ext"],
# 第一个参数是:执行动作,第二个:匹配字段(app_ext:表示规则组)
"uri": ["/post.html",""],
"post_form":1024,
# 这个参数 是配置取post内容长度参数,base.json中也会有,两者取最小的为准
"app_ext":[
["post_form",["\\.(jpg|jpeg|png|webp|gif)$","jio",["image0",2],true],"or"],
# 第一个参数 表示匹配位置 第二个参数 是匹配规则
# 匹配规则中 第一个参数:匹配内容,第二个:匹配方式,第三:匹配名称和匹配位置,第四个:连接符 (and/or)
["post_form",["(;|-|/)","jio",["image0",2]]]
# 匹配规则中 第四个参数 默认是 and
]
},
{
"state": "on",
"action":["deny","network"],
"network":{"maxReqs":30,"pTime":10,"blackTime":600},
# 频率规则 第一个参数:单位时间访问最大值,第二个:单位时间,第三个:封锁时间
"uri": ["/index.html",""]
}
]
数据请求样式
URI: http://%ip:%port/api/v2/host_dict
查询操作:
1:查询所有
GET/POST querystring:
action=get&host=all
2:查询所有host名称
GET/POST querystring:
action=get&host=all_host
3:查询指定host的规则 (支持子节点查询,eg: 1@state)
id 为空表示查询所有,id 指定表示查询指定id
GET/POST querystring:
action=get&host=pass.chj.com
action=get&host=pass.chj.com&id=1@state
设置操作:
1:修改单个
GET/POST querystring:
action=set&host=test.chj.com&id=1&value=
{
"state": "on",
"action": ["allow","uri"],
"uri": ["\\.(css|js|flv|swf|woff|txt)$","jio"]
}
2:修改开关
开关状态(on 表示开启;off 表示关闭;log 表示记录)
GET/POST querystring:
action=set&host=test.chj.com&id=state&value=on
3:修改整个
GET/POST querystring:
action=set&host=test.chj.com&&value=
[
{
"state": "on",
"action": ["allow","uri"],
"uri": ["\\.(css|js|flv|swf|woff|txt)$","jio"]
},
{
"state": "on",
"action":["log","referer"],
"uri": ["\\.(gif|jpg|png|jpeg|bmp|ico)$","jio"],
"referer": ["hao123","in",true]
},
{
"state": "on",
"action":["deny","useragent"],
"useragent": ["baidu","in"]
},
{
"state": "on",
"action":["deny","app_ext"],
"uri": ["/post.html",""],
"post_form":1024,
"app_ext":[
["post_form",["\\.(jpg|jpeg|png|webp|gif)$","jio",["image0",2],true],"or"],
["post_form",["(;|-|/)","jio",["image0",2]]]
]
},
{
"state": "on",
"action":["deny","network"],
"network":{"maxReqs":30,"pTime":10,"blackTime":600},
"uri": ["/index.html",""]
}
]
删除操作:
1:删除单个规则
GET/POST querystring:
action=del&host=www.test.com&id=1
2:删除所有
GET/POST querystring:
action=del&host=www.test.com&id=all
添加操作:
1:添加状态
开关状态(on 表示开启;off 表示关闭;log 表示记录)
GET/POST querystring:
action=add&host=www.test.com&id=state&value=on
2:添加单个规则
GET/POST querystring:
action=add&host=www.test.com&value=
{
"state": "on",
"action":["deny","network"],
"network":{"maxReqs":30,"pTime":10,"blackTime":600},
"uri": ["/index.html",""]
}
返回消息:
服务器失败:http code ~= 200
服务器成功:{code="ok/error",msg=...}
code = error ,执行状态错误,msg 为错误内容