用API修改应用过滤配置

来自WFilter上网行为管理系统文档和指南
WFilter讨论 | 贡献2023年9月27日 (三) 19:16的版本

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索


下面是用php调用API修改“应用过滤”规则的例子。

1 读取配置config_load

$result = $ngf->config_load("wfilter-appcontrol");

echo "config:$result";

返回格式:

config:{

	"jsonrpc":"2.0",
	"id":2,
	"result":
	[ 0, 
		{ "values": //配置文件内容

			{ "rule1695810460278":	//rule ID

				{
					".anonymous":false,
					".type":"rule",
					".name":"rule1695810460278",
					".index":0,
					"name":"test1", 			//规则名称
					"toall":"false",			//是否对所有终端生效
					"enable_ab":"true",			
					"utype":"device",			//应用对象类型:device--终端,user-用户,range自定义
					"user":["group1546995000471"],	//应用对象
					"time":"time1",				//生效时间段
					"autoblock":"0,0,0",		//自动禁止规则
					"blockup2":"false",			//智能过滤
					"blockall":"false",			//禁止所有
					"unknown":"false",			//禁止未知
					"block":["PPLive","QQLive","PPStream"],	//禁止的应用列表
					"id":"rule1695810460278",	//规则id
					"enabled":"true"			//是否启用
				}
			},
			...	//多条规则
		}
	]
} 

2 添加规则config_add

//规则内容要填写在一行内不能换行,双引号要转义

$values = "{ \"name\":\"test2\",\"toall\":\"false\",\"enable_ab\":\"true\",\"utype\":\"device\",\"user\":[\"group1546995000471\"],\"time\":\"time1\",\"autoblock\":\"0,0,0\",\"blockup2\":\"false\",\"blockall\":\"false\",\"unknown\":\"false\",\"block\":[\"Youtube\"],\"id\":\"rule12345\",\"enabled\":\"true\"}";

//规则中的id要和config_add的第三个参数一致

$result = $ngf->config_add( "wfilter-appcontrol", "rule", "rule12345", $values );

echo "config_add:$result";

调用成功后,服务端返回格式:

config_add:{"jsonrpc":"2.0","id":2,"result":[0,{"section":"rule12345"}]} 

3 修改规则config_set

$values = "{\"enabled\":\"false\"}";    //把规则状态改成不启用
$result = $ngf->config_set( "wfilter-appcontrol",  "rule12345", $values );
echo "config_set:$result";

调用成功后,服务端返回格式:

config_set:{"jsonrpc":"2.0","id":2,"result":[0]} 

4 删除规则config_del

$result = $ngf->config_del( "wfilter-appcontrol",  "rule12345" );
echo "config_del:$result";

调用成功后,服务端返回格式:

config_del:{"jsonrpc":"2.0","id":2,"result":[0]} 

5 应用新配置

$result = $ngf->config_apply();
echo "config_apply:$result";