Jump to content

JavaScript question


A.lemane

Recommended Posts

oh god i hate this router

 

am trying to reboot my router without the webui and i tried the telnet way but it seems that it isn't compatible with it so i am now hopping that there is a way through this code 

 

reboot.js

// JavaScript Document
var g_timerReboot = 1000;

function gotoLoginWhileSystemUp() {

    if (DATA_READY.statusReady) {
        log.debug('Reboot : system is up.');
        gotoPageWithoutHistory('home.html');
    } else {
        log.debug('Reboot : system is down.');
    }
}

function do_reboot() {
    var request = {
        Control: 1
    };
    var DEFAULT_GATEWAY_IP = '';
    // get current settings gateway address
    getAjaxData('api/dhcp/settings', function($xml) {
        var ret = xml2object($xml);
        if ('response' == ret.type) {
            DEFAULT_GATEWAY_IP = ret.response.DhcpIPAddress;
        }
    }, {
        sync: true
    }
    );
    var xmlstr = object2xml('request', request);
    log.debug('xmlstr = ' + xmlstr);
    saveAjaxData('api/device/control', xmlstr, function($xml) {
        log.debug('saveAjaxData successed!');
        var ret = xml2object($xml);
        if (isAjaxReturnOK(ret)) {
            ping_setPingAddress(DEFAULT_GATEWAY_IP);
            setTimeout(startPing, 50000);
        } else {
            closeWaitingDialog();
            showInfoDialog(common_failed);
            return false;
        }
    });
}

function reboot() {
    showWaitingDialog(common_waiting, update_label_device_waiting);
    clearTimeout(g_decive_timer);
    clearTimeout(g_simcard_timer);
    clearTimeout(g_heart_beat_timer);
    /*After send "api/device/control" cmd, server will't response webui request.
     So delay 1 second.*/
    setTimeout(do_reboot, g_timerReboot);
}

$( function() {
    $('#button_reboot').bind('click', function() {
        showConfirmDialog(system_setting_reboot, reboot, function() {
        });
        return false;
    });
});

 

Link to comment
Share on other sites


  • Replies 3
  • Views 1k
  • Created
  • Last Reply

Why use this when you can just use the reset button? (if there is any in your router)

Link to comment
Share on other sites


  • Administrator

Previously, when I was wanting something like this, I had considered writing a software in some common language, which would open the page in a specific browser, click on the reboot button and then close the browser. Did not require to do so though.

Link to comment
Share on other sites


which router you want to use ? i mean model and company !

 

This script is working well with my dlink and also draytek router.

 

////// RebootRouter.js ////////
// Change these for your environment
var ROUTER_IP = "192.168.0.1";
var ROUTER_USER = "admin";
var ROUTER_PASSWORD = "pA55w0rd";

var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("POST", "http://" + ROUTER_IP
    + "/cgi-bin/reboot.cgi", false,
    ROUTER_USER, ROUTER_PASSWORD);
http.setRequestHeader("Content-Type",
    "application/x-www-form-urlencoded");
http.send("sReboot=Current&submit=OK");

// For debugging/logging un-comment the following lines:
// WScript.Echo(http.status + " " + http.statusText);
// WScript.Echo(http.responseText);

 

Source :

 

 

And specially for dlink

 

Link to comment
Share on other sites


Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...