forked from Jrohy/trojan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
47 lines (43 loc) · 1.52 KB
/
web.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"trojan/util"
"trojan/web"
)
var (
host string
port int
ssl bool
timeout int
)
// webCmd represents the web command
var webCmd = &cobra.Command{
Use: "web",
Short: "以web方式启动",
Run: func(cmd *cobra.Command, args []string) {
web.Start(host, port, timeout, ssl)
},
}
func init() {
webCmd.Flags().StringVarP(&host, "host", "", "0.0.0.0", "web服务监听地址")
webCmd.Flags().IntVarP(&port, "port", "p", 80, "web服务启动端口")
webCmd.Flags().BoolVarP(&ssl, "ssl", "", false, "web服务是否以https方式运行")
webCmd.Flags().IntVarP(&timeout, "timeout", "t", 120, "登录超时时间(min)")
webCmd.AddCommand(&cobra.Command{Use: "stop", Short: "停止trojan-web", Run: func(cmd *cobra.Command, args []string) {
util.SystemctlStop("trojan-web")
}})
webCmd.AddCommand(&cobra.Command{Use: "start", Short: "启动trojan-web", Run: func(cmd *cobra.Command, args []string) {
util.SystemctlStart("trojan-web")
}})
webCmd.AddCommand(&cobra.Command{Use: "restart", Short: "重启trojan-web", Run: func(cmd *cobra.Command, args []string) {
util.SystemctlRestart("trojan-web")
}})
webCmd.AddCommand(&cobra.Command{Use: "status", Short: "查看trojan-web状态", Run: func(cmd *cobra.Command, args []string) {
fmt.Println(util.SystemctlStatus("trojan-web"))
}})
webCmd.AddCommand(&cobra.Command{Use: "log", Short: "查看trojan-web日志", Run: func(cmd *cobra.Command, args []string) {
util.Log("trojan-web", 300)
}})
rootCmd.AddCommand(webCmd)
}