Score
0
Watch 67 Star 311 Fork 64

GVP赵建辉 / rttyCMIT

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
在任何地方通过web访问您的设备的终端 spread retract

Clone or download
COMMAND.md 2.53 KB
Copy Edit Web IDE Raw Blame History
赵建辉 authored 2020-01-17 01:05 . Drop the depend of libuwsc

How to operate

You first need to send a command to the server through POST, the message format is as follows.

{"devid": "test", "username": "test", "password": "test", "cmd": "echo", "params": ["hello rtty"]}

The devid, username, cmd in the message must be provided. Password, params are optional. Params is a JSON array.

Then the server returns a unique token.

{"token":"7fb8dcfe3fee2129427276b692987338"}

Then use the token as a URL parameter to query the command execution result from the server. If the command is executed, the server will return the command execution result in json format.

{"code":0,"stdout":"aGVsbG8gcnR0eQo=","stderr":""}

The stdout and stderr in the response are base64 encoded.

If any of the steps fail, the server will return an error message in json format.

{"err": 1002, "msg":"device offline"}

All error codes are as follows

1001    invalid format
1002    device offline
1003    server is busy
1004    timeout
1005    pending
1006    invalid token
1       operation not permitted
2       not found
3       no mem
4       sys error
5       stdout+stderr is too big

Example

Shell

Jquery

function queryCmdResp(token) {
    $.getJSON('https://your-server:5912/cmd?token=' + token, function(r) {
        if (r.stdout) {
            console.log(window.atob(r.stdout))
        } else {
            console.log(r)
        }
    });
}

var data = {devid: 'test', username: 'test', password: 'test', cmd: 'echo', params: ['hello rtty']};
$.post('http://your-server:5912/cmd', JSON.stringify(data), function(r) {
    if (!r.token) {
        console.log(r)
        return;
    }
    
    setTimeout(function () {
        queryCmdResp(r.token);
    }, 100);
});

Axios

function queryCmdResp(token) {
    axios.get('http://your-server:5912/cmd?token=' + token).then(function(r) {
        var resp = r.data;
        if (resp.stdout) {
            console.log(window.atob(resp.stdout))
        } else {
            console.log(resp)
        }
    });
}

var data = {devid: 'test', username: 'test', password: 'test', cmd: 'echo', params: ['hello rtty']};
axios.post('http://your-server:5912/cmd', data).then(function(r) {
    var resp = r.data;
    if (!resp.token) {
        console.log(r)
        return;
    }
    
    setTimeout(function () {
        queryCmdResp(resp.token);
    }, 100);
});

Comment ( 0 )

Sign in for post a comment

C
1
https://gitee.com/zhaojh329/rtty.git
git@gitee.com:zhaojh329/rtty.git
zhaojh329
rtty
rtty
master

Help Search