Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new login (choose between pre-v6.43 and post-v6.43 (post-v6.43 by default)) #97

Open
wants to merge 3 commits into
base: release
Choose a base branch
from

Conversation

nunokisc
Copy link

No description provided.

@bycaldr
Copy link

bycaldr commented Mar 12, 2020

It would be great to merge and publish this fix. Today is this libary almost unusable without support of new login API 🙏

@khertg
Copy link

khertg commented Jun 1, 2021

@nunokisc Hi how can I use this fix ?

Below are my dependencies

  "dependencies": {
    "core-decorators": "^0.20.0",
    "mikronode": "^2.3.11",
    "rxjs": "^5.3.0"
  }

And heres my sample code.

connection.connect(function(conn) {

   conn.closeOnDone(true);
   var chan2=conn.openChannel(2);
   chan2.write('/interface/listen',function(chan) {
      chan.on('read',function(data) {
         packet=api.parseItems([data])[0];
         console.log('Interface change: '+JSON.stringify(packet));
      });
   });
});

And got this error

internal/timers.js:361
    throw new ERR_OUT_OF_RANGE(name, 'a non-negative finite number', msecs);
    ^

RangeError [ERR_OUT_OF_RANGE]: The value of "msecs" is out of range. It must be a non-negative finite number. Received NaN
�[90m    at getTimerDuration (internal/timers.js:361:11)�[39m
�[90m    at Socket.setStreamTimeout [as setTimeout] (internal/stream_base_commons.js:227:11)�[39m
    at SocketStream.setTimeout (E:\Projects\mikrotek-test\node_modules\�[4mmikronode�[24m\dist\mikronode.js:577:32)
    at new SocketStream (E:\Projects\mikrotek-test\node_modules\�[4mmikronode�[24m\dist\mikronode.js:550:15)
    at MikroNode.connect (E:\Projects\mikrotek-test\node_modules\�[4mmikronode�[24m\dist\mikronode.js:330:30)
    at Object.<anonymous> (E:\Projects\mikrotek-test\index.js:5:12)
�[90m    at Module._compile (internal/modules/cjs/loader.js:959:30)�[39m
�[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)�[39m
�[90m    at Module.load (internal/modules/cjs/loader.js:815:32)�[39m
�[90m    at Function.Module._load (internal/modules/cjs/loader.js:727:14)�[39m {
  code: �[32m'ERR_OUT_OF_RANGE'�[39m
}

@nunokisc
Copy link
Author

nunokisc commented Jun 1, 2021

This fix is only for the login issue. The login method change on v6.43.
As i can see your error is in another place.
It looks like you have a NaN in some "timer".

@xeleniumz
Copy link
Contributor

I don't have permission to approve your commit , My permission is maintainer may be we should have to fork this project because the maintainer didn't update project for a long time.

@Habbiton
Copy link

Habbiton commented Jul 1, 2021

Any news on this fix? It's almost mandatory on 07/2021

@DevilMorgan
Copy link

DevilMorgan commented Aug 22, 2021 via email

@imPPLs
Copy link

imPPLs commented Nov 5, 2021

Guys! If you wanna fix connection with mikrotik via API:

https://help.mikrotik.com/docs/display/ROS/API:
Login method post-v6.43:

  • Now the client sends a username and password in the first message.
  • Password is sent in plain text.
  • in case of error, the reply contains =message=error message.
  • In case of a successful login, the client can start to issue commands.

Just open your file /node_modules/mikronode/dist/mikronode.js
Find string №358 in code.
stream.write(["/login", "=name=" + user, "=response=00" + md5.digest("hex")]);
Change string to
stream.write(["/login", "=name=" + user, "=password=" + password, "=response=00" + md5.digest("hex")]);
And after this you can use standard code for connect to your mikrotik via API like this:

var MikroNode = require('mikronode');

var device = new MikroNode('IP');

device.setDebug(MikroNode.DEBUG);

device.connect().then(([login])=>login('username','password')).then(function(conn) {

var chan=conn.openChannel();

chan.write('/ip/address/add',{'interface':'ether1','address':'192.168.1.1'});
chan.on('trap',function(data) {
console.log('Error setting IP: '+data);
});
chan.on('done',function(data) {
console.log('IP Set.');
});
chan.close();
conn.close();
});

My version RouterOS now is 6.47. Hope this helps someone!

@JamesDelfini
Copy link

Changing it to post-v6.43 the password will be sent to the network in plain text. As result, this is not good when using Mikrotik API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants