Community discussions

MikroTik App
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 1:17 am

Good day!

I was going to use Node for MikroTik Hotspot and I'm unable to get my HTML page. What the heck? Why does it want to work with a directory?

I've installed express + ejs, run the server, my customized page is opened in the Chrome as expected.
I open Hotspot -> Server Profiles -> create a new profile -> Hotspot address: my server IP + HTML directory: IP of my server. Instead of opening a HTML page created by node.js it creates a new directory with IP address of my Node server in its memory.

I hate the man who told me that the power of MikroTik is flexibility. What a non-sense!

Who could help me to set up the router so that I could carry on coding on Node. I wonder how much time things haven't been changed... My firmware is 6.48 beta40

Thanks.

# forgotten to mention.... I've add a necessary rule to /ip hotspot walled-garden ip to whitelist the Node server
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 9:52 am

Is there any coders from a MikroTik's development? Is it possible to point a device to a node server?
I would like to have something like UniFi Controller provides:

Image
 
blingblouw
Member
Member
Posts: 345
Joined: Wed Aug 25, 2010 9:43 am

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 9:56 am

There are many ways to perform HTTP redirects, here is one example

https://wiki.mikrotik.com/wiki/HotSpot_ ... login_page
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 10:16 am

There are many ways to perform HTTP redirects, here is one example

https://wiki.mikrotik.com/wiki/HotSpot_ ... login_page
Well, It's for an external php version. I think I don't need redirects. I want MikroTik device to use my external server communicating via API if it's needed.
As far as I understand I should eventually pass http://IP_address/login?login=login&password=password&dst=redirect_link to get user authenticated.
I don't want to keep JavaScript code exposed that's why I've chosen to code in Node.js rather than on Vanilla JavaScript.

Here's the most succinct code I cannot get a login page. It creates a new directory of my server IP address name in the inner memory OR keeps redirecting to its own page.
const express = require('express');
const app = express();

app.set('view engine', 'ejs');

app.listen(80, '192.168.10.254');

app.use(express.static('public'));

app.get('/login', (req, res) => {
    res.render('login');
});
app.use((req, res) => {
    res.status(404).render('404');
});
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 11:18 am

Here is the video, it persistently wants to get a HTML file.

Image
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 12:14 pm

Wow, the tip of the iceberg is that I went to Customer Service to submit my request and failed to sign up. Then I tried to open the link in Yandex with a VPN - eventually it's been opened. Well, Ukraine blocks a range of Russian's IP addresses who knows it might be the reason. I typed my email, even received an answer back with another link after all my blood, sweat and tears I put in the service is down I've already checked it in online services.

For goodness sake! Is there any MikroTik representative alive?
 
blingblouw
Member
Member
Posts: 345
Joined: Wed Aug 25, 2010 9:43 am

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 12:38 pm

AFAIK mikrotiks web server cannot host _any_ server side languages. Your only option is to redirect to an external web page hosting your node application, that application must grab the parameters and process them as you require

IMHO this should be the case anyway, unless you only have 1 router updating is going to be a pain in the long term

EDIT:

The example shows how to redirect to an external PHP server, use that as a guide to redirect to your node.js application, the logic is exactly the same
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 3:12 pm

AFAIK mikrotiks web server cannot host _any_ server side languages.
I get nothing! It doesn't redirect me. It even doesn't send me a POST request.

Why do we need MikroTik webserver at all? What's the point?
There is a RouterOS Client allowing to communicate with a router via API
The example shows how to redirect to an external PHP server, use that as a guide to redirect to your node.js application, the logic is exactly the same
Could you do me a favour? Share with me a snippet of code redirecting me to a node.js web server. I see you an experienced fellow. Thanks!
 
andriys
Forum Guru
Forum Guru
Posts: 1527
Joined: Thu Nov 24, 2011 1:59 pm
Location: Kharkiv, Ukraine

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 4:01 pm

I tried to open the link in Yandex with a VPN - eventually it's been opened. Well, Ukraine blocks a range of Russian's IP addresses who knows it might be the reason.
Just checked, works fine for me. Tried opening that page via several ISPs here in Kharkiv, no problems at all. It's probably the browser, not VPN, that made a difference for you. That support portal is powered by JIRA, so I'd suggest trying to clean the cookies and try again from your main browser.

Another way to contact Mikrotik support is to reach them at support@mikrotik.com.


For goodness sake! Is there any MikroTik representative alive?
This is a user/community forum. The chance you get an official reply from Mikrotik employees here on the forum is close to zero pretty low.
 
andriys
Forum Guru
Forum Guru
Posts: 1527
Joined: Thu Nov 24, 2011 1:59 pm
Location: Kharkiv, Ukraine

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 4:26 pm

And to your original question. Have you seen the Customizing Hotspot page on the wiki? Specifically, the "External authentication" section may be of interest to you. And if you don't feel like passing a (temporary) username/password pair in a redirect back to the router, you can consider doing manual login via the API instead.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26378
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 4:37 pm

Yes, the above poster is correct. You should consider external authentication, because (as another poster pointed out), MikroTik HTTP server can only serve static pages, there is no server side language support at all.
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 4:41 pm

Another way to contact Mikrotik support is to reach them at support@mikrotik.com.
Thank you for the email! It's kind of you. I owe you! :D As for the website availability, well it's better to see something once than to hear about it a thousand times.
Image

Kharkiv is an eastern part of Ukraine you're really close to Russia. I'm on the other side of the country. You might have a different set of routes to get to Latvia.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26378
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 4:44 pm

replace jira.mt.lv with help.mikrotik.com and it should work (the rest of the link should stay the same).
we recently upgraded the server, it seems the wrong (test server) links are published, we will look into it.
 
hazartilirot
newbie
Topic Author
Posts: 31
Joined: Thu Sep 17, 2020 11:48 pm
Location: Lviv

Re: Mikrotik hotspot is unfriendly with Node.js

Tue Oct 06, 2020 5:10 pm

Yes, the above poster is correct. You should consider external authentication, because (as another poster pointed out), MikroTik HTTP server can only serve static pages, there is no server side language support at all.
Well, now it's clear. I wish I knew the info when I was going to buy MikroTik
Is there any difficulties to implement an external link and provide access to a routerOS through API?

For example, I want to authenticate a user by SMS.
Here's a simple task. A user enters their number and hits a send button -> (pause) -> the user gets respond - a SMS with a temporary password. Obviously I can implement the code on Javascript, though:
1) Everybody could have an access to the code and it may be easily stolen
2) I don't want to expose my tokens.

It's just a small reason not to write code on JavaScript and buy the router!
 
andriys
Forum Guru
Forum Guru
Posts: 1527
Joined: Thu Nov 24, 2011 1:59 pm
Location: Kharkiv, Ukraine

Re: Mikrotik hotspot is unfriendly with Node.js  [SOLVED]

Tue Oct 06, 2020 5:32 pm

Is there any difficulties to implement an external link and provide access to a routerOS through API?
Nothing too fancy. The API description is here. At the bottom of that page there is a list of third party clients in different languages. You should enable the API first in the /ip service menu, see this page for details.

As to the external link, please check the link I've pointed you to before (this link: https://wiki.mikrotik.com/wiki/Manual:C ... ng_Hotspot). You basically have to customize the on-the-router login.html page to redirect the user to your external server, then do whatever you want on that external server, then finally either (a) redirect the user back to the router passing username/password as the request parameters, or (b) log the user in manually via the API call from your external server to the router, and then optionally redirect the user directly to the original request URL or wherever else you want.

Who is online

Users browsing this forum: grayfoxbsd and 46 guests