2

I want to call to a onclick function as I am writting script for MikroTik RouterBoard in order to restart my Modem by just visiting a simple link directly but what I found was that the page from which Modem is rebooting there is a button which calls to a onlick function as :

<input type="button" onclick="btnReset()" value="Reboot">

So is there any way that I can Call this onclick function directly in a http url like :

http://admin:hunter@192.168.1.1/resetrouter.html?btnReset()=Reboot

Here is MikroTik Script which I am writting but it can't do the job..It need a direct link which it visits only and downloads a file..!

If anyone MikroTik Scripting person can help will be greatful..Until then if there is any way to do it in direct url so then that will be great..!

 {
/tool fetch url="http://admin:hunter@192.168.1.1/resetrouter.html?btnReset()=Reboot" mode=http 
}
Umair Shah
  • 2,305
  • 2
  • 25
  • 50

3 Answers3

2

That's not possible to perform js code from a hyperlink (unless the page has script inside, specifically for this and it's checking for some parameter...) .

However there are some tools which could help you perform desired action in other way:

  • Install Custom JS for Web Sites plugin and define js script which would be executed after your http://admin:hunter... page would be loaded in browser.

    For your case it would be simple function call:

    btnReset()
    
  • Analyse body of btnReset() function( probably that function sends http request) and construct same request with cURL, see cURL Tutorial.

  • Take a look on Bookmarklet, which is a bookmark stored in a web browser that contains JavaScript commands.

  • Get familiar with PhantomJS or Selenium and write simple script which would perform desired action for you.

Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82
1

The btnReset() function is probably just a dialog followed by a URL fetch. Open the javascript console, type btnReset.toString() and have a look. If you see a URL in there, try visiting that directly.

Oh My Goodness
  • 216
  • 2
  • 9
1

You need a very specific URL "http://admin:hunter@192.168.1.1/rebootinfo.cgi". In my case the function btnReset() calls "rebootinfo.cgi". I followed the below steps to find "rebootinfo.cgi".

  1. Open the "save/reboot" page or equivalent page of your router.

  2. Inspect the button "Reboot", i.e, right click on the particular button and click "Inspect" from the menu.

  3. In the developer tool now opened to the right, note the function for the onclick attribute in the highlighted line. E.g. in my case, btnReset() from the line "input type="button" onclick="btnReset()" value="Reboot".

  4. Go to the console tab on the developer tool and paste the function name without parenthesis E.g., btnReset (not btnReset() ) and hit enter.

  5. In the function definition for btnReset(), look for the exact command that is responsible for rebooting the router. In my case it was "rebootinfo.cgi".

  6. That's it, construct the URL.

Pradeep B
  • 11
  • 3