Skip to content

Commit 189c45b

Browse files
Huan Wangfredwangwang
Huan Wang
authored andcommitted
add reboot
1 parent e0ce69b commit 189c45b

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This Go package provides a basic API wrapper for the tp-link M4 mesh router
88
- [x] ClientList: Get connected clients
99
- [x] Custom: Make a custom request to the router
1010
- [x] DeviceList: Get connected Decos
11+
- [x] Reboot: Reboot Deco mesh node(s)
1112
- [ ] Wan: Get information about wan
1213

1314
`TODO: look through the firmware for more endpoints`

client.go

+30-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"net/http/cookiejar"
1111
"net/url"
12+
"strings"
1213
"time"
1314

1415
"github.com/mrmarble/deco/utils"
@@ -51,7 +52,7 @@ type ClientListResp struct {
5152
Name string `json:"name"`
5253
Online bool `json:"online"`
5354
OwnerID string `json:"owner_id"`
54-
RemainTime int `json:"remain_time"`
55+
RemainTime int `json:"remain_time"`
5556
SpaceID string `json:"space_id"`
5657
UpSpeed uint `json:"up_speed"`
5758
WireType string `json:"wire_type"`
@@ -192,7 +193,7 @@ func (c *Client) ClientList() (*ClientListResp, error) {
192193
var result ClientListResp
193194
request := request{
194195
Operation: "read",
195-
Params: map[string]string{"device_mac": "default"},
196+
Params: map[string]interface{}{"device_mac": "default"},
196197
}
197198
jsonRequest, _ := json.Marshal(request)
198199
err := c.doEncryptedPost(fmt.Sprintf(";stok=%s/admin/client", c.stok), EndpointArgs{form: "client_list"}, jsonRequest, false, &result)
@@ -208,6 +209,33 @@ func (c *Client) ClientList() (*ClientListResp, error) {
208209
return &result, nil
209210
}
210211

212+
// Reboot the deco nodes by mac address
213+
func (c *Client) Reboot(macAddrs ...string) (map[string]interface{}, error) {
214+
var result map[string]interface{}
215+
var macList []map[string]string
216+
217+
for _, mac := range macAddrs {
218+
macList = append(macList, map[string]string{
219+
"mac": strings.ToUpper(mac),
220+
})
221+
}
222+
223+
request := request{
224+
Operation: "reboot",
225+
Params: map[string]interface{}{
226+
"mac_list": macList,
227+
},
228+
}
229+
230+
jsonRequest, _ := json.Marshal(request)
231+
err := c.doEncryptedPost(fmt.Sprintf(";stok=%s/admin/device", c.stok), EndpointArgs{form: "system"}, jsonRequest, false, &result)
232+
if err != nil {
233+
return nil, err
234+
}
235+
236+
return result, nil
237+
}
238+
211239
// Custom lets you make a custom request
212240
func (c *Client) Custom(path string, params EndpointArgs, body []byte) (interface{}, error) {
213241
var result interface{}

deco.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ type response struct {
5353
}
5454

5555
type request struct {
56-
Operation string `json:"operation,omitempty"`
57-
Params map[string]string `json:"params,omitempty"`
56+
Operation string `json:"operation,omitempty"`
57+
Params map[string]interface{} `json:"params,omitempty"`
5858
}
5959

6060
// EndpointArgs holds the url params to be sent

utils/aes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ func AES256Decrypt(encrypted string, key AESKey) (string, error) {
7878

7979
mode := cipher.NewCBCDecrypter(block, key.Iv)
8080
mode.CryptBlocks(cipherText, cipherText)
81-
cipherText, _ = pkcs7Unpadding(cipherText, aes.BlockSize)
82-
return string(cipherText), nil
81+
cipherText, err = pkcs7Unpadding(cipherText, aes.BlockSize)
82+
return string(cipherText), err
8383
}
8484

8585
func pkcs7Padding(b []byte, blocksize int) ([]byte, error) {

0 commit comments

Comments
 (0)