Community discussions

 
amardeep704
just joined
Topic Author
Posts: 5
Joined: Thu Sep 20, 2018 1:09 pm

Mikrotik API call not working

Fri Jun 28, 2019 5:34 pm

Hi Guys,

I am using the Mikrotik API (php) to connect with the gateway and enable/disable hotspot. However, the API connect function is return false.

Sample code:

require('routeros_api.class.php');
$API = new RouterosAPI();

if ($API->connect('IP', 'USERNAME', 'PASSWORD')) {
die('connnect');
}

Any thoughts?

Thanks
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5913
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Mikrotik API call not working

Mon Jul 01, 2019 9:58 am

Make sure your PHP code is using new authentication method:
https://wiki.mikrotik.com/wiki/Manual:API#Initial_login
 
imort
just joined
Posts: 5
Joined: Sat May 26, 2018 9:34 am

Re: Mikrotik API call not working

Mon Jul 01, 2019 12:20 pm

Make sure your PHP code is using new authentication method:
https://wiki.mikrotik.com/wiki/Manual:API#Initial_login
Have same issue with upgrade to the new 6.45.1 firmware.
API authentication fails, and same is working with 6.44.3

Is it related with removed unsafe user passwords storage?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5913
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Mikrotik API call not working

Mon Jul 01, 2019 12:27 pm

Yes, make sure you are using new authentication method.
 
Kurosudo
just joined
Posts: 20
Joined: Wed Aug 01, 2018 1:21 pm

Re: Mikrotik API call not working

Mon Jul 01, 2019 12:41 pm

Same problem, i'm using same API class like you and all my systems died
 
imort
just joined
Posts: 5
Joined: Sat May 26, 2018 9:34 am

Re: Mikrotik API call not working

Mon Jul 01, 2019 12:44 pm

Yes, make sure you are using new authentication method.
I think that a proper warning about deprecated API authentication with this release was at least essential.
Problem is that I have a strange success/fail API authentication entries in the logs even after downgrade and restoring the last backup.

Can you please suggest should downgrade restore old-API authentication working, before third-party software can fix it from their side?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5913
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Mikrotik API call not working

Mon Jul 01, 2019 12:54 pm

There is already important note due to removal of compatibility with old version passwords.
Third party software should have been fixed long time ago ,new authentication method was introduced back in May 2018.
 
imort
just joined
Posts: 5
Joined: Sat May 26, 2018 9:34 am

Re: Mikrotik API call not working

Mon Jul 01, 2019 1:00 pm

There is already important note due to removal of compatibility with old version passwords.
Third party software should have been fixed long time ago ,new authentication method was introduced back in May 2018.
Sorry, can't see anything about deprecation of old-style authentication both in the changelogs or API link you posted above.
Can you please post a link to the important note you're mention?

Thank you!
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5913
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Mikrotik API call not working

Mon Jul 01, 2019 1:04 pm

Important note!!!
Due to removal of compatibility with old version passwords in this version...
...
!) user - removed insecure password storage;
...
 
imort
just joined
Posts: 5
Joined: Sat May 26, 2018 9:34 am

Re: Mikrotik API call not working

Mon Jul 01, 2019 1:16 pm

Important note!!!
Due to removal of compatibility with old version passwords in this version...
...
!) user - removed insecure password storage;
...
I still can't see any API-related warnings in the release.
Just to be sure that you can understand my point:

1. Removing compatibility with old version passwords
Ok, I really can't say that it should be intuitive for any user that it will affect their API authentication somehow.

2. user - removed insecure password storage;
Same here.

I didn't trying to hype on that, but I strongly believe that another important notice about old-style API authentication deprecation starts with this release will be very pleased for many MikroTik users.

Thank you.
 
Kurosudo
just joined
Posts: 20
Joined: Wed Aug 01, 2018 1:21 pm

Re: Mikrotik API call not working

Mon Jul 01, 2019 1:48 pm

It is possible to fix it via little dirty hack in API. Just change login sequence. But This will make API usable only 6.43 higher
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5913
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Mikrotik API call not working

Mon Jul 01, 2019 2:02 pm

Not true. See how it is done in our api example client:
https://wiki.mikrotik.com/wiki/Manual:A ... ple_client
 
Kurosudo
just joined
Posts: 20
Joined: Wed Aug 01, 2018 1:21 pm

Re: Mikrotik API call not working

Mon Jul 01, 2019 2:15 pm

Not true. See how it is done in our api example client:
https://wiki.mikrotik.com/wiki/Manual:A ... ple_client
Yea, i basically did same thing in my patch i just wrote "how it fastly fix".
Infact i don't see any advantage to use old style API because having unpatched ROS (pre-6.43) is big security hole
 
amardeep704
just joined
Topic Author
Posts: 5
Joined: Thu Sep 20, 2018 1:09 pm

Re: Mikrotik API call not working

Mon Jul 01, 2019 6:38 pm

Hi Guys,

I am able to connect using the new authentication method. Sample code:

use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b6.phar';

try{
$util = new RouterOS\Util($client = new RouterOS\Client('IP', 'USERNAME', 'PASSWORD'));
foreach ($util->setMenu('/log')->getAll() as $entry) {
echo $entry('time') . ' ' . $entry('topics') . ' ' . $entry('message') . "\n";
}
} catch (Exception $e) {
echo 'Unable to connect to RouterOS.';
}

It lists the logs on the router.

I am trying to enable/disable the hotspot(p hotspot disable 0) but can't find the property that will be used to achieve this in the above code.

I am also trying to print the interface list but nothing ie being returned.

Sample code:

$getRequest = new RouterOS\Request('/interface/get');
$getRequest->setArgument('value-name', 'type');
$getRequest->setArgument('number', 'ether1');
$type = $client->sendSync($getRequest)->getProperty('ret');
print_r($type);

Any thoughts?

Thanks
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5913
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Mikrotik API call not working

Tue Jul 02, 2019 12:46 pm

I didn't trying to hype on that, but I strongly believe that another important notice about old-style API authentication deprecation starts with this release will be very pleased for many MikroTik users.
Thank you.
We will add note regarding API, too.
 
stealth
just joined
Posts: 21
Joined: Fri May 26, 2006 4:55 pm

Re: Mikrotik API call not working

Wed Jul 03, 2019 12:12 am

For those who are using old good routeros_api.class.php from Denis Basta. The urls are no longer active. The needed changes to make it work again with new /login

https://github.com/Ftelf/netprovider-ne ... 73647463b3
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Mikrotik API call not working  [SOLVED]

Wed Jul 03, 2019 9:21 am

Right now, PEAR2_Net_RouterOS supports the new login method only in the development version. That is, the currently unreleased 1.0.0b7. You can only get it via Composer by specifying "dev-develop" as your required version.

Generating PHARs is a little bit difficult and time consuming right now, which is why I haven't done it yet... Since these new versions no longer support the old authentication method, I'll try to make a release this weekend.

@amardeep704 I'm surprised b6 works to be honest. As for disabling hotspot, you can use f.e.
$util->setMenu('/ip hotspot')->disable('hostspot1');
If your hostpot server instance is named "hotspot1".
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
BinaryCrash
newbie
Posts: 39
Joined: Thu Apr 28, 2011 11:20 pm

Re: Mikrotik API call not working

Fri Jul 05, 2019 8:35 pm

Generating PHARs is a little bit difficult and time consuming right now, which is why I haven't done it yet... Since these new versions no longer support the old authentication method, I'll try to make a release this weekend.
Looking forward to the release! :D
 
User avatar
machack
newbie
Posts: 46
Joined: Fri Jun 01, 2007 9:35 pm
Location: San Luis Argentina
Contact:

Re: Mikrotik API call not working

Wed Jul 17, 2019 6:42 pm

For Login Using Php API, you need change in: routeros_api.classv1.6.php

$this->write('=response=00' . md5(chr(0) . $password . pack('H*', $MATCHES[0][1])));

for

$this->write('=password=' . $password);
Cesar Javier Robles
www.WindNet.com.ar
MTCNA - MTCTCE - MTCRE - MTCWE
 
benkhlifahaythem
just joined
Posts: 2
Joined: Mon Jun 24, 2019 9:19 am

Re: Mikrotik API call not working

Tue Aug 13, 2019 12:50 pm

Not true. See how it is done in our api example client:
https://wiki.mikrotik.com/wiki/Manual:A ... ple_client

Good day,

i did apply the new login method and i still get the same issue with V6.45.1 and up im using php .

Code: Select all


<?php


use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b6.phar';

try{
$util = new RouterOS\Util($client = new RouterOS\Client('ip','user','password'));
foreach ($util->setMenu('/log')->getAll() as $entry) {
echo $entry('time') . ' ' . $entry('topics') . ' ' . $entry('message') . "\n";
}
} catch (Exception $e) {
die($e);
}

?>



-------------------------------------OUT PUT--------------------------------------------------------------


PEAR2\Net\RouterOS\DataFlowException: Invalid username or password supplied. in phar://C:/xampp/htdocs/test2/PEAR2_Net_RouterOS-1.0.0b6.phar/PEAR2_Net_RouterOS-1.0.0b6/src/PEAR2/Net/RouterOS/Client.php:175 Stack trace: #0 C:\xampp\htdocs\test2\example.php(8): PEAR2\Net\RouterOS\Client->__construct('ip', 'user', 'password') #1 {main}



I Don't figure it out why I'm getting the error.
Last edited by benkhlifahaythem on Tue Aug 13, 2019 3:54 pm, edited 1 time in total.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1239
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Mikrotik API call not working

Tue Aug 13, 2019 3:35 pm

Fixed
Last edited by Jotne on Tue Aug 20, 2019 7:48 pm, edited 1 time in total.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
nrtszr
just joined
Posts: 9
Joined: Mon Dec 23, 2013 3:33 pm
Location: Denizli
Contact:

Re: Mikrotik API call not working

Tue Aug 20, 2019 2:49 pm

when will it come out?

PEAR2_Net_RouterOS-1.0.0b7.phar

thanks

Who is online

Users browsing this forum: No registered users and 5 guests