How do I get the Mikrotik to respond to a web request?

Is it possible to run a web page on the Mikrotik router that has buttons to do things - run a script on the Mikrotik, say? Or have it respond directly http requests?

The situation is this:

My router is running a number of VPNs, and has scripts on it for starting up and shutting down VPNs, routing traffic through them and so on.

So if a client IP address 192.168.90.254 is in the firewall address list “vpn-france-clients” then when a request from 192.168.90.254 comes in, the router starts the French VPN, routes all packets from that client, and then shuts down the VPN after a period of inactivity. All that runs fine.

And I can have CMD files on Windows that “move” the Windows PC (or it’s IP address) from one address list to another - they simply write a small VPNMOVE.auto.rsc file locally on the PC, which contains the required instructions (and the IP address), and then send this file to the router using curl ftp.

But this is clunky, and requires the client machine to have the code, plus passwords in a file, plus have a version of curl installed, and I would need to re-write it for Apple Macs and I can’t see how to make it work with iPads at all!

What I really want is a zero installation footprint - a webpage on the router with a number of buttons, and pressing the buttons causes a script on the router to be run.

How do I do that?

(I don’t have a webserver outside the router available)

Is it possible to run a web page on the Mikrotik router that has buttons to do things - run a script on the Mikrotik, say? Or have it respond directly http requests?

No. Not without an extra device - a web server - being available.

I don’t have a webserver outside the router available

But you do have your own Windows machine with what’s currently a CMD file, right?

If that’s the case, you can set up a web server on that same machine. Then, use the API with that web server. Yes, you’d still have code sitting not on the router, but at least this code would be portable - it would run anywhere your web server and/or language of choice can run. In the case of, let’s say PHP, this includes Windows, as well as UNIX flavors (including Apple Mac). And because it’s on a web server, there’s zero installation footprint for VPN clients, and any device with a browser (so really, all devices) can use that functionality.

Or do you have Windows CMD files that currently VPN clients are supposed to run? If that’s the case, then your best bet is to replace them with a Java application that uses the API, and pack that into a “.jar” file. The Java runtime is available for all desktop platforms, as well as most mobile ones, with the notable exception of iOS, for which you’d need to redo your app with Objective-C… having only 2 versions still sounds like a sweet deal though, if a web server is really out of the question.

Thanks for the suggestions.

I was just wondering if it was possible to do the job using the webserver built into the router, but sadly it sounds like it’s not possible; as it is, after all, a router and not a webserver.

I don’t really want to use my own machine as a webserver for security and power consumption reasons.

So this sounds like a job for… Raspberry Pi!

Crazy idea.
if figure a way how to put javascript in mikrotik hosted web page, i think is possible to program mikrotik API on javascript.

Or just turn up a MetaRouter with openwrt :slight_smile:

JavaScript does not support TCP sockets, so there’s no way even in theory you could do that.

(Note: “WebSockets” != “TCP sockets”)

There’s already an ActionScript API client, meaning that if your users have Flash installed, you could use the API through Flash.

But even if you could do that with JavaScript… even though you can already do it with Flash… that doesn’t mean you should. Why? Well, in order to use the API, you need to make the API client login to the router. If you had it in JavaScript, this means you’re letting users potentially view your router’s password by viewing the source of your web page. With Flash, it’s better, in that users can’t view Flash’s source, but they can still monitor the connection with a packet sniffer on their computer. With only a very basic knowledge of the API protocol, a power user could crack your password by brute forcing it against what he saw with the sniffer.

P.S. To insert JavaScript in a MikroTik hosted page, just open that web page, and edit it - JavaScript can be placed within HTML’s “script” element.

Good reason against JavaScript.

Primary becauseof it I name this idea crazy.

But what if there not question of scurity but question of simplicity.