Community discussions

MikroTik App
 
marklodge
Member Candidate
Member Candidate
Topic Author
Posts: 250
Joined: Sun Jun 21, 2009 6:15 pm

Scripting and [] commands in PEAR2_Net_RouterOS

Mon Aug 13, 2018 12:09 am

Using PEAR2_Net_RouterOS-1.0.0b6

The following works fine the in the Mikrotik Terminal. But I cant get it to work via the API. How would I do the following:
:foreach user in=[/ip firewall address-list find find address=10.2.2.2] do={

   /ip firewall address-list disable $user
}
Or
ip firewall address-list disable [/ip firewall address-list find address=10.2.2.2]
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Scripting and [] commands in PEAR2_Net_RouterOS  [SOLVED]

Mon Aug 13, 2018 9:08 pm

Easiest would be:
$util = new RouterOS\Util($client);
$util->setMenu('/ip firewall address-list')->disable(RouterOS\Query::where('address', '10.2.2.2'));
Although there is a bug with Util and queries with multiple matches that's already fixed in the upcoming version... Until that version is released, if you have more than one match, you could use:
$ids = array();
$util->setMenu('/ip firewall address-list');
foreach ($util->getAll(array('.proplist' => '.id'), RouterOS\Query::where('address', '10.2.2.2')) as $item) {
    $ids[] = $item('.id');
}
$util->disable(implode(',', $ids));
 
marklodge
Member Candidate
Member Candidate
Topic Author
Posts: 250
Joined: Sun Jun 21, 2009 6:15 pm

Re: Scripting and [] commands in PEAR2_Net_RouterOS

Mon Aug 13, 2018 11:33 pm

Thank you, so much!

Who is online

Users browsing this forum: Majestic-12 [Bot] and 22 guests