Community discussions

MUM Europe 2020
 
User avatar
Edoras
newbie
Topic Author
Posts: 32
Joined: Wed Apr 05, 2006 12:03 am
Location: Prague, Czech rep.

PHP-API: Delete firewall filter rules, where comment started with "MYRULE" string

Mon Dec 12, 2016 3:45 pm

There are a lot of rules in "ip firewall filter". Some of them are commented. Comments starts "MYRULE_<anything>" (for example MYRULE_user1, MYRULE_user2, and so on ...)
I need to delete all ip firewall flter rules, where comment started with string "MYRULE_" .
I know how to do that in command line:
ip firewall filter remove [find [:pick $comment 0 6]="MYRULE"]
Now the same thing I need to do in PHP API. How to do it?
 
User avatar
Edoras
newbie
Topic Author
Posts: 32
Joined: Wed Apr 05, 2006 12:03 am
Location: Prague, Czech rep.

Re: PHP-API: Delete firewall filter rules, where comment started with "MYRULE" string

Tue Dec 13, 2016 1:24 am

Acually I solved that, but I don't like the solution so much ...
My sollution:
1. Read all rules from ip/firewall/filter to PHP array.
2. Filter the array.
3. Remove from ip/firewall/filter .id's from the filtered array.

It works, but there are 3 steps. Better would be 1 step - just "Remove from ip/firewall/filter all rules, where comment contain MYRULES." But I don't know, how to do that.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: PHP-API: Delete firewall filter rules, where comment started with "MYRULE" string

Tue Dec 13, 2016 2:44 am

Sadly, there's no better way... not yet anyway.

In my API client, I have an util method to ease this, but it does those same steps under the hood. More specifically:
$util->setMenu('/ip firewall filter')->remove(function ($item) {
    return 0 === strpos($item('comment'), 'MYRULE');
});
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)

Who is online

Users browsing this forum: No registered users and 14 guests