pear2/Net_RouterOS

Modifying configurtion on ancient Mikrotik doesn't work

etiennesw opened this issue · 3 comments

Hi,

First of all, I'd like to thank you for your project. Seems you have put a lot of work into it.

I am not sure if this is the best place to post but other channels seem down.

I am testing this API with a Mikrotik RouterOS v3.20 from a Raspberry PI with PHP5 installed.

When retrieving data from the Mikrotik, it works fine, such as the basic example of the arp table.

$util->setMenu('/ip arp');

foreach ($util->getAll() as $item) {
echo 'IP: ', $item->getProperty('address'),
'---> MAC: ', $item->getProperty('mac-address')."
";

However, when I try to enable/disable or remove an arp entry, nothing happens, not even an error.

$util->setMenu('/ip arp')->remove(8);

or this

$util->setMenu('/ip arp');
$util->disable(RouterOS\Query::where('comment', 'DISABLE ME'));

The api connection is successful, as I see it in the Mikrotik logs, however, nothing happens.

Could the problem be related to the old RouterOS version?

If I perform the command to disable id 8 from the Mikrotik terminal it works, so its the API that somehow fails.

Do you have any idea and suggestions?

Thanks

Rgs
ETienne

Thanks.

It could be the old RouterOS version indeed. I've never tested versions 4.* and 3.*. I only started this project near the end of the 5.* versions, so that's the earliest ones supported (though today, I test only against the latest "current" version, and only touch others if reports come in).

Queries, according to the manual, were only supported since 3.21, so that last item failing is to be expected.

The other ones should work though. Check the return value. It contains the responses from the router. e.g.

$responses = $util->setMenu('/ip arp')->remove(8);
var_dump($responses);

(As already suggested in #19, future versions of Util will throw an exception on failure, so that the failure is more apparent)

I checked the source, and it seems find() (which is internally used by remove() to get the proper ID) only uses the "find" command for numbers, and never falls back to "print". I think I may have done this because on zero matches, no "ret" is present... So I can't really detect whether you're simply in a menu with zero items, or if you're using an older version where "find" doesn't work at all.

As a workaround, you can try to get all IDs, and get whatever the 8th one is, i.e.:

$util->setMenu('/ip arp')->remove(
    $util->getAll(array('.proplist' => '.id'))[8]->getProperty('.id')
);

(though keep in mind this is somewhat inefficient, since ALL items' IDs are retrieved, only for the 8th one to be used, and the other ones effectively discarded)

I'll (re)evaluate if I could fallback to a "print" for older versions... In the meantime (and in general in fact), upgrading to a newer RouterOS version (preferably the latest one) would be best in the long run.

Thanks for your prompt reply.

I have updated the router to 6.10 and everything is now working. Seems it was time to scrap the old version and work on the new ones.

I will continue to explore the other feature of your client. In the meantime, thank you once again for your great work.

Etienne