diff --git a/internal/web/actions/default/index/index.go b/internal/web/actions/default/index/index.go index 4889d727..1750c885 100644 --- a/internal/web/actions/default/index/index.go +++ b/internal/web/actions/default/index/index.go @@ -2,6 +2,7 @@ package index import ( "fmt" + teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" "github.com/TeaOSLab/EdgeAdmin/internal/rpc" "github.com/TeaOSLab/EdgeAdmin/internal/setup" @@ -55,6 +56,12 @@ func (this *IndexAction) RunGet(params struct { return } this.Data["systemName"] = config.AdminSystemName + this.Data["showVersion"] = config.ShowVersion + if len(config.Version) > 0 { + this.Data["version"] = config.Version + } else { + this.Data["version"] = teaconst.Version + } this.Show() } diff --git a/internal/web/actions/default/settings/database/index.go b/internal/web/actions/default/settings/database/index.go index a82cba08..318e089f 100644 --- a/internal/web/actions/default/settings/database/index.go +++ b/internal/web/actions/default/settings/database/index.go @@ -2,14 +2,12 @@ package profile import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/go-sql-driver/mysql" "github.com/go-yaml/yaml" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/maps" "io/ioutil" - "net/url" - "path/filepath" - "regexp" "strings" ) @@ -52,32 +50,31 @@ func (this *IndexAction) RunGet(params struct{}) { break } 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["error"] = "parse dsn failed: " + err.Error() + this.Data["error"] = "parse dsn error: " + err.Error() this.Show() return } - host := dsnURL.Host + host := cfg.Addr port := "3306" - index := strings.LastIndex(dsnURL.Host, ":") + index := strings.LastIndex(host, ":") if index > 0 { - host = dsnURL.Host[:index] - port = dsnURL.Host[index+1:] + port = host[index+1:] + host = host[:index] } - password, _ := dsnURL.User.Password() + password := cfg.Passwd if len(password) > 0 { password = strings.Repeat("*", len(password)) } this.Data["dbConfig"] = maps.Map{ "host": host, "port": port, - "username": dsnURL.User.Username(), + "username": cfg.User, "password": password, - "database": filepath.Base(dsnURL.Path), + "database": cfg.DBName, } // TODO 测试连接 diff --git a/internal/web/actions/default/settings/database/update.go b/internal/web/actions/default/settings/database/update.go index d1b19711..ec7329ce 100644 --- a/internal/web/actions/default/settings/database/update.go +++ b/internal/web/actions/default/settings/database/update.go @@ -109,12 +109,6 @@ func (this *UpdateAction) RunPost(params struct { Require("请输入连接数据库的用户名"). Match(`^[\w\.-]+$`, "用户名中不能包含特殊字符") - if len(params.Password) > 0 { - params.Must. - Field("password", params.Password). - Match(`^[\w\.-]+$`, "密码中不能包含特殊字符") - } - // 保存 dsn := params.Username + ":" + params.Password + "@tcp(" + params.Host + ":" + fmt.Sprintf("%d", params.Port) + ")/" + params.Database