From eaf530407f207bbeca06aaf5139abc97f83f074d Mon Sep 17 00:00:00 2001 From: Jrohy Date: Fri, 27 Mar 2020 00:07:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/root.go | 2 +- core/mysql.go | 6 ++++++ trojan/install.go | 17 +++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 6521e04a..e8dfbdc1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -44,7 +44,7 @@ exit: fmt.Println() fmt.Println(util.Cyan("欢迎使用trojan管理程序")) fmt.Println() - menuList := []string{"trojan管理", "用户管理", "安装管理", "web管理", "查看配置", "生成客户端配置文件"} + menuList := []string{"trojan管理", "用户管理", "安装管理", "web管理", "查看配置", "生成json"} for i := 0; i < len(menuList); i++ { if i%2 == 0 { fmt.Printf("%d.%-15s\t", i+1, menuList[i]) diff --git a/core/mysql.go b/core/mysql.go index 72e885cc..c66e2628 100644 --- a/core/mysql.go +++ b/core/mysql.go @@ -5,6 +5,10 @@ import ( "database/sql" "errors" "fmt" + mysqlDriver "github.com/go-sql-driver/mysql" + "io/ioutil" + "log" + // mysql sql驱动 _ "github.com/go-sql-driver/mysql" "strconv" @@ -33,6 +37,8 @@ type User struct { // GetDB 获取mysql数据库连接 func (mysql *Mysql) GetDB() *sql.DB { + // 屏蔽mysql驱动包的日志输出 + mysqlDriver.SetLogger(log.New(ioutil.Discard, "", 0)) conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", mysql.Username, mysql.Password, mysql.ServerAddr, mysql.ServerPort, mysql.Database) db, err := sql.Open("mysql", conn) if err != nil { diff --git a/trojan/install.go b/trojan/install.go index 235a9522..f34e719c 100644 --- a/trojan/install.go +++ b/trojan/install.go @@ -20,7 +20,9 @@ var ( func InstallMenu() { fmt.Println() menu := []string{"更新trojan", "证书申请", "安装mysql"} - switch util.LoopInput("请选择: ", menu, true) { + choice := util.LoopInput("请选择: ", menu, true) + fmt.Println() + switch choice { case 1: InstallTrojan() case 2: @@ -30,7 +32,6 @@ func InstallMenu() { default: return } - Restart() } // InstallDocker 安装docker @@ -49,9 +50,9 @@ func InstallTrojan() { fmt.Println(err) } util.ExecCommand(data) + util.OpenPort(443) util.ExecCommand("systemctl restart trojan") util.ExecCommand("systemctl enable trojan") - util.OpenPort(443) fmt.Println() } @@ -59,7 +60,9 @@ func InstallTrojan() { func InstallTls() { domain := "" choice := util.LoopInput("请选择使用证书方式: ", []string{"Let's Encrypt 证书", "自定义证书路径"}, true) - if choice == 1 { + if choice < 0 { + return + } else if choice == 1 { localIP := util.GetLocalIP() fmt.Printf("本机ip: %s\n", localIP) for { @@ -107,6 +110,7 @@ func InstallTls() { } } core.SetValue("domain", domain) + Restart() fmt.Println() } @@ -132,9 +136,9 @@ func InstallMysql() { } util.OpenPort(mysql.ServerPort) util.ExecCommand(fmt.Sprintf(mysqlDodkcerRun, mysql.ServerPort, mysql.Password)) - fmt.Println("mysql启动中, 请稍等...") + db := mysql.GetDB() for { - db := mysql.GetDB() + fmt.Printf("%s mysql启动中,请稍等...\n", time.Now().Format("2006-01-02 15:04:05")) err := db.Ping() if err == nil { db.Close() @@ -179,5 +183,6 @@ func InstallMysql() { if len(mysql.GetData()) == 0 { AddUser() } + Restart() fmt.Println() }