forked from Jrohy/trojan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
65 lines (60 loc) · 1.34 KB
/
root.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"os"
"trojan/core"
"trojan/trojan"
"trojan/util"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "trojan",
Run: func(cmd *cobra.Command, args []string) {
mainMenu()
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func check() {
if !util.IsExists("/usr/local/etc/trojan/config.json") {
fmt.Println("本机未安装trojan, 正在自动安装...")
trojan.InstallTrojan("")
core.WritePassword(nil)
trojan.InstallTls()
trojan.InstallMysql()
util.SystemctlRestart("trojan-web")
}
}
func mainMenu() {
check()
exit:
for {
fmt.Println()
fmt.Println(util.Cyan("欢迎使用trojan管理程序"))
fmt.Println()
menuList := []string{"trojan管理", "用户管理", "安装管理", "web管理", "查看配置", "生成json"}
switch util.LoopInput("请选择: ", menuList, false) {
case 1:
trojan.ControlMenu()
case 2:
trojan.UserMenu()
case 3:
trojan.InstallMenu()
case 4:
trojan.WebMenu()
case 5:
trojan.UserList()
case 6:
trojan.GenClientJson()
default:
break exit
}
}
}