URL to shutdown or other operations?

Discussion in 'Asuswrt-Merlin' started by mmmmmm, Jan 11, 2013.

  1. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    Hi,

    I am thinking of writing a small widget for my Samsung Smart TV to shutdown/restart the router on request.
    Giving the fact that the widget can only make some simple http requests I was wondering if there is a url on the rotuer's web server that will take some parameters and perform some actions.

    Something like a basic webservice.

    For instance my D-Link NAS can be switched off like so:

    set UNAME=admin
    set PASSWD=yourpassword
    set IP=172.17.0.6

    wget --tries=1 --timeout=5 "http://%IP%/goform/formLogin?f_login_type=0&f_LOGIN_NAME=%UNAME%&f_LOGIN_PASSWD=%PASSWD%"
    IF %ERRORLEVEL%==0
    (
    wget --tries=1 --timeout=5 "http://%IP%/goform/sysShutDown?shootdown"
    )
    ELSE
    (
    echo Unable to shutdown NAS_002
    )

    NAS forum link: http://forums.dlink.com/index.php?topic=8362.0

    Cand this be done on RT-n66U running Merlin's firmware?

    Thank you.
     
  2. Log in / Register to remove this ad

  3. darius456

    darius456 Occasional Visitor

    Joined:
    Oct 16, 2012
    Messages:
    11
    That would be a nice gadget to samsung TV. I also have Samsung Smart TV so i'm interested of such gadget. Unfortunately i dont have enough knowledge to help You with this project, but i will keep cross my fingers :)
    So good luck.
     
  4. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    Thank you darius.

    I think I am on to something.

    Just found the "/Tools_RunCmd.asp" page that lets you execute linux commands from the web gui.

    I think I am on the right track :).

    I will post my findings.
     
  5. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    maybe Merlin can give some pointers.

    What data to post for login and for the system command?

    Thanks in advance.
     
  6. RMerlin

    RMerlin Part of the Furniture

    Joined:
    Apr 14, 2012
    Messages:
    14,050
    Location:
    Canada
    The web server uses basic HTTP authentication.
     
  7. ryzhov_al

    ryzhov_al Senior Member

    Joined:
    Jul 23, 2012
    Messages:
    496
    Location:
    Russia
    We ran some commands on Oleg's firmware this way before:
    mmmmmm is quite close to solution:))
     
    Last edited: Jan 12, 2013
  8. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    Thank you ryzhov_al for this valuable information.
    It turns out that it's the same way here.

    The request is the following:
    h t t p://192.168.1.1/apply.cgi?current_page=Main_AdmStatus_Content.asp&next_page=Main_AdmStatus_Content.asp&next_host=&group_id=&modified=0&action_mode=+Refresh+&action_script=&action_wait=&first_time=&preferred_lang=EN&SystemCmd=df&action=Refresh

    Now, I managed to execute simple command using this http request. So, simple shutdown seems to be possible in this way.

    But I've noticed another interesting query string parameter: "action_script"

    Now I am wondering if it's possible to execute a script (stored somewhere on the router: jfss or usb stick) that will first gracefully stop some daemons like transmission and then execute the shutdown.

    Do you have any ideea if the mentioned parameter can be used for such scenario?
     
    Last edited: Jan 12, 2013
  9. ryzhov_al

    ryzhov_al Senior Member

    Joined:
    Jul 23, 2012
    Messages:
    496
    Location:
    Russia
    As long as you are on Asuswrt-Merlin, you may use /jffs/scripts/services-stop script:
    When you run halt, Asuswrt-Merlin will execute this script before unmounting USB partition automagically.
     
  10. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    Strange thing: I am requesting the page with sys_cmd=halt and it seems that the router does a reboot instead of a power down.

    Also tried "halt -p -h".
    I get the message "shutting down" int the "Tools_RunCmd.asp" page of the web gui, but the router (RT-N66U) reboots.

    Am I missing someting?
    Please advice.

    Yes, I am using Merlin's version (3.0.0.4.246.20).
     
  11. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    Awesome. Thank you very much for this information. Very very useful.
     
  12. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    I've created the services-stop script on the jfss partition as you suggested and put some commands in there.

    I've run "halt -p" (remotely via the apply.cgi http request) and I need to know if what happens is normal:

    - the Power Led remains ON
    - the WAN Led remains ON
    - the USB Hdd connected to one of the USB is still powered on (2.5" hdd with a led on when connected to a device)

    The Power button is of course On. Does this mean that the USBport will provide power to the usb devices?

    What is the proper way to start the router after a software halt: press the power button to Off and then On, or is there another way?
     
  13. ryzhov_al

    ryzhov_al Senior Member

    Joined:
    Jul 23, 2012
    Messages:
    496
    Location:
    Russia
    Yes, it's normal. It's not a big PC and it can't cut power from peripherals, it's a system on chip, we've got a soldered wire from power supply to USB connector:)) The halt make sense only for gracefully finish all jobs with USB-HDD.

    Yes. In fact, halt finishes OS work and puts CPU to endless loop. Only hardware reset or off/on sequence can force router to boot again.
     
  14. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    I understand. It actually makes sense that as long as the power button is in On position, there will be power on the USB devices.

    The question now is: does it makes any sense to "halt" the router since it will not actually switch it off completely?

    I am using it as a small NAS (besinde my main one D-LINK DNS-343) and have the shares mounted on my Samsung TV. I was thinking, that when going to sleep, to switch off the router and the USB HDD from the TV.

    I've tested the widget on the TV and it works, but I am not sure if it is very useful in this scenario. I think I will be better with only switching off the wireless and leave everything else up and running.

    ryzhov_al, thank you very much for the time you spent to share your knowledge. I greatly appreciate it.
     
  15. ryzhov_al

    ryzhov_al Senior Member

    Joined:
    Jul 23, 2012
    Messages:
    496
    Location:
    Russia
    I'm afraid no. Better to spin down HDD, you can save up to 3W, see below.
    Just FYI, I've measured RT-N66U's power consumption in different scenarios with this tool.
    • It's ~9 Watt regardless of CPU load or number of powered wireless interfaces.
    • It's ~12 Watt with 2.5" HDD attached.
     
  16. RMerlin

    RMerlin Part of the Furniture

    Joined:
    Apr 14, 2012
    Messages:
    14,050
    Location:
    Canada
    There's isn't really a "power down" mode for the router. That wouldn't make much sense since the power switch is a mechanical toggle switch, so the router cannot be turned off through software.
     
  17. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    I understand and it makes perfect sense.
    Thank you so much for taking the time to share information.

    I appreciate this useful forum and the great people taking time to share knowledge.
     
  18. mmmmmm

    mmmmmm Occasional Visitor

    Joined:
    Nov 29, 2012
    Messages:
    35
    This is very useful info. Thank you very much.

    As you suggested I've configured the router to spin down the drive and leave it on for now.
     

Share This Page