-
Notifications
You must be signed in to change notification settings - Fork 1
/
system.go
166 lines (154 loc) · 3.49 KB
/
system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/modouwifi/md/api"
)
var cmdSystem = cli.Command{
Name: "system",
Usage: "Operate system",
//Action: runSystem,
Subcommands: []cli.Command{
{
Name: "current",
Usage: "Display currently version",
Action: runSystemGetVersionInfo,
},
{
Name: "check",
Usage: "Check latest version",
Action: runSystemCheckLatestVersion,
},
{
Name: "reboot",
Usage: "Reboot router",
Action: runSystemReboot,
},
{
Name: "safe",
Usage: "Enter safe mode",
Action: runSystemSafe,
},
{
Name: "reset",
Usage: "Reset system",
Action: runSystemReset,
},
{
Name: "backlight",
Usage: "Control the backlight",
Action: runSystemBacklight,
Flags: []cli.Flag{
cli.StringFlag{Name: "action, a", Value: "lock", Usage: "Control the blacklight, lock|release|wakeup"},
},
},
{
Name: "time",
Usage: "Get/set system time",
Action: runSystemTime,
},
{
Name: "cable",
Usage: "Get system cable connections",
Action: runSystemCable,
},
},
}
func runSystemGetVersionInfo(c *cli.Context) {
req, err := client.NewRequest("GET", "/system/get_version_info")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.SystemVersion
err = req.ToJSON(&result)
fmt.Println(result.Code)
fmt.Println(result.Track)
fmt.Println(result.Version1)
fmt.Println(result.Version2)
}
func runSystemCheckLatestVersion(c *cli.Context) {
req, err := client.NewRequest("GET", "/system/check_remote_version_upgrade")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.SystemLatestVersion
err = req.ToJSON(&result)
fmt.Println(result)
fmt.Println(result.Filename)
fmt.Println(result.Version)
fmt.Println(result.Releasenote)
}
func runSystemReboot(c *cli.Context) {
req, err := client.NewRequest("GET", "/system/reboot")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.ResponseMessage
err = req.ToJSON(&result)
fmt.Println(result)
}
func runSystemSafe(c *cli.Context) {
req, err := client.NewRequest("GET", "/system/safe_reboot")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.ResponseMessage
err = req.ToJSON(&result)
fmt.Println(result)
}
func runSystemReset(c *cli.Context) {
req, err := client.NewRequest("GET", "/system/reset_config")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.ResponseMessage
err = req.ToJSON(&result)
fmt.Println(result)
}
var actionsOfBacklight = []string{"lock", "release", "wakeup"}
func runSystemBacklight(c *cli.Context) {
var a = c.String("action")
var b bool
for _, i := range actionsOfBacklight {
b = a == i
if b {
break
}
}
if b {
url := fmt.Sprintf("/system/%s_backlight", a)
req, err := client.NewRequest("GET", url)
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.ResponseMessage
err = req.ToJSON(&result)
fmt.Println(result)
}
}
func runSystemTime(c *cli.Context) {
req, err := client.NewRequest("GET", "/system/get_time")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.SystemTime
err = req.ToJSON(&result)
fmt.Println(result)
}
func runSystemCable(c *cli.Context) {
req, err := client.NewRequest("GET", "/system/get_cable_connection")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.SystemCable
err = req.ToJSON(&result)
fmt.Println(result)
}