我在通过 PHP API 更新路由器上的规则时遇到了一点问题,如何让我的代码首先检查设置是否存在差异,例如首先检查路由器是否禁用规则/对象然后应用或者如果一切都完美匹配,什么也不做。
目前,每当我的同步脚本运行时,它都会在不需要时继续读取(更新)路由器上的规则/对象,因为代码已经具有路由器上已经配置的相同信息。
当前代码:
function update_routerOS_address_list($list, $address, $comment) {
//Set globals
global $API;
global $Debug;
$API->write('/ip/firewall/address-list/print',false);
$API->write('?comment='.$comment,true);
$READ = $API->read(false);
$ARRAY = $API->parseResponse($READ);
if(count($ARRAY)>0){
$API->write('/ip/firewall/address-list/set',false);
$API->write("=.id=".$ARRAY[0]['.id'],false);
$API->write('=disabled=no',true);
$READ = $API->read(false);
$ARRAY = $API->parseResponse($READ);
} else {
$API->write('/ip/firewall/address-list/add',false);
$API->write('=list='.$list,false);
$API->write('=address='.$address,false);
$API->write('=comment='.$comment,true);
$READ = $API->read(false);
$ARRAY = $API->parseResponse($READ);
}
}