fix(phpmyadmin): 配置目录改为运行时求值

app.Root 在启动时才由 bootstrap 赋值,写成包级变量会在包初始化阶段
拿到空串,拼出 /sites/phpmyadmin/config 这种没有前缀的路径。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
耗子
2026-09-21 14:11:31 +08:00
co-authored by Claude Opus 5
parent 0755ea7808
commit ac79a2bcf2
+9 -6
View File
@@ -32,8 +32,11 @@ import (
webservertypes "github.com/acepanel/panel/v3/pkg/webserver/types"
)
// configDir phpMyAdmin 站点配置目录,由安装脚本按当前 Web 服务器写入
var configDir = app.Root + "/sites/phpmyadmin/config"
// configDir phpMyAdmin 站点配置目录,由安装脚本按当前 Web 服务器写入。
// app.Root 是启动时才赋值的,写成包级变量会在包初始化阶段拼出没有前缀的路径
func configDir() string {
return app.Root + "/sites/phpmyadmin/config"
}
type App struct {
t *gotext.Locale
@@ -100,7 +103,7 @@ func (s *App) info() (string, int, error) {
if err != nil {
return "", 0, err
}
vhost, err := d.NewPHPVhost(configDir)
vhost, err := d.NewPHPVhost(configDir())
if err != nil {
return "", 0, err
}
@@ -279,7 +282,7 @@ func (s *App) UpdatePort(w http.ResponseWriter, r *http.Request) {
service.Error(w, http.StatusInternalServerError, "%v", err)
return
}
vhost, err := d.NewPHPVhost(configDir)
vhost, err := d.NewPHPVhost(configDir())
if err != nil {
service.Error(w, http.StatusInternalServerError, "%v", err)
return
@@ -322,7 +325,7 @@ func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
service.Error(w, http.StatusInternalServerError, "%v", err)
return
}
config, err := io.Read(filepath.Join(configDir, d.ConfigFile()))
config, err := io.Read(filepath.Join(configDir(), d.ConfigFile()))
if err != nil {
service.Error(w, http.StatusInternalServerError, "%v", err)
return
@@ -343,7 +346,7 @@ func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
service.Error(w, http.StatusInternalServerError, "%v", err)
return
}
if err = io.Write(filepath.Join(configDir, d.ConfigFile()), req.Config, 0600); err != nil {
if err = io.Write(filepath.Join(configDir(), d.ConfigFile()), req.Config, 0600); err != nil {
service.Error(w, http.StatusInternalServerError, "%v", err)
return
}