高级设置/数据库/修改:数据库密码中支持特殊字符

This commit is contained in:
GoEdgeLab
2021-01-19 10:44:52 +08:00
parent 7d55f61660
commit 78caadc3ea
6 changed files with 20 additions and 19 deletions

View File

@@ -11,7 +11,7 @@ func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
Helper(settingutils.NewHelper("backup")).
Helper(settingutils.NewAdvancedHelper("backup")).
Prefix("/settings/backup").
Get("", new(IndexAction)).
EndAll()

View File

@@ -3,15 +3,13 @@ package profile
import (
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/maps"
"gopkg.in/yaml.v3"
"io/ioutil"
"net/url"
"path/filepath"
"regexp"
"strings"
)
@@ -57,28 +55,33 @@ func (this *UpdateAction) RunGet(params struct{}) {
}
dsn := dbConfig.Dsn
dsn = regexp.MustCompile(`tcp\((.+)\)`).ReplaceAllString(dsn, "$1")
dsnURL, err := url.Parse("mysql://" + dsn)
cfg, err := mysql.ParseDSN(dsn)
if err != nil {
this.Data["dbConfig"] = maps.Map{
"host": "",
"port": "",
"username": "",
"password": "",
"database": "",
}
this.Show()
return
}
host := dsnURL.Host
host := cfg.Addr
port := "3306"
index := strings.LastIndex(dsnURL.Host, ":")
index := strings.LastIndex(cfg.Addr, ":")
if index > 0 {
host = dsnURL.Host[:index]
port = dsnURL.Host[index+1:]
host = cfg.Addr[:index]
port = cfg.Addr[index+1:]
}
password, _ := dsnURL.User.Password()
this.Data["dbConfig"] = maps.Map{
"host": host,
"port": port,
"username": dsnURL.User.Username(),
"password": password,
"database": filepath.Base(dsnURL.Path),
"username": cfg.User,
"password": cfg.Passwd,
"database": cfg.DBName,
}
this.Show()

View File

@@ -34,6 +34,7 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex
tabbar.Add("API节点", "", "/api", "", this.tab == "apiNodes")
tabbar.Add("用户节点", "", "/settings/userNodes", "", this.tab == "userNodes")
tabbar.Add("日志数据库", "", "/db", "", this.tab == "dbNodes")
//tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup")
}
actionutils.SetTabbar(actionPtr, tabbar)

View File

@@ -34,7 +34,6 @@ func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool)
tabbar.Add("用户界面设置", "", "/settings/user-ui", "", this.tab == "userUI")
tabbar.Add("安全设置", "", "/settings/security", "", this.tab == "security")
tabbar.Add("IP库", "", "/settings/ip-library", "", this.tab == "ipLibrary")
tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup")
}
tabbar.Add("个人资料", "", "/settings/profile", "", this.tab == "profile")
tabbar.Add("登录设置", "", "/settings/login", "", this.tab == "login")