I am having a bit of a problem with updating rules on my router via PHP API, how can I make my code first check if there is a difference in the setting for example first check the router if the rule/object is disabled and then apply or do nothing if everything matches perfectly.
Currently whenever my sync script runs, it keeps readding(updating) the rule/object on the router when it doesn't need to because the code already has the same info that is already configured on the router.
Current code:
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);
}
}
I have figured the answer I was looking for