Skip to content

Commit

Permalink
feat: phpMyAdmin支持编辑配置
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Jun 24, 2024
1 parent fa41b18 commit 63838bf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/http/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Success(ctx http.Context, data any) http.Response {
// Error 响应错误
func Error(ctx http.Context, code int, message string) http.Response {
return ctx.Response().Json(code, &ErrorResponse{
Message: facades.Lang(ctx).Get("messages.mistake") + ": " + message,
Message: message,
})
}

Expand Down
31 changes: 31 additions & 0 deletions app/http/controllers/plugins/phpmyadmin_controller.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package plugins

import (
"fmt"
"regexp"
"strings"

Expand Down Expand Up @@ -93,3 +94,33 @@ func (r *PhpMyAdminController) SetPort(ctx http.Context) http.Response {

return controllers.Success(ctx, nil)
}

func (r *PhpMyAdminController) GetConfig(ctx http.Context) http.Response {
config, err := io.Read("/www/server/vhost/phpmyadmin.conf")
if err != nil {
return controllers.Error(ctx, http.StatusInternalServerError, err.Error())
}

return controllers.Success(ctx, config)
}

func (r *PhpMyAdminController) SaveConfig(ctx http.Context) http.Response {
config := ctx.Request().Input("config")
if len(config) == 0 {
return controllers.Error(ctx, http.StatusInternalServerError, "配置不能为空")
}

if err := io.Write("/www/server/vhost/phpmyadmin.conf", config, 0644); err != nil {
facades.Log().Request(ctx.Request()).Tags("插件", "phpMyAdmin").With(map[string]any{
"error": err.Error(),
}).Info("修改 phpMyAdmin 配置失败")
return controllers.ErrorSystem(ctx)
}

if err := systemctl.Reload("openresty"); err != nil {
_, err = shell.Execf("openresty -t")
return controllers.Error(ctx, http.StatusInternalServerError, fmt.Sprintf("重载OpenResty失败: %v", err))
}

return controllers.Success(ctx, nil)
}
3 changes: 0 additions & 3 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@
"incompatible": "plugin :slug is incompatible with :exclude plugin"
}
},
"messages": {
"mistake": "mistake"
},
"status": {
"upgrade": "Panel is currently undergoing an upgrade. Please try again later.",
"maintain": "Panel is currently undergoing maintenance. Please try again later.",
Expand Down
3 changes: 0 additions & 3 deletions lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@
"incompatible": "插件 :slug 不兼容 :exclude 插件"
}
},
"messages": {
"mistake": "错误"
},
"status": {
"upgrade": "面板升级中,请稍后",
"maintain": "面板正在运行维护,请稍后",
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/plugin_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var PluginPHPMyAdmin = Plugin{
Description: "phpMyAdmin 是一个以 PHP 为基础,以 Web-Base 方式架构在网站主机上的 MySQL 数据库管理工具",
Slug: "phpmyadmin",
Version: "5.2.1",
Requires: []string{},
Requires: []string{"openresty"},
Excludes: []string{},
Install: `bash /www/panel/scripts/phpmyadmin/install.sh`,
Uninstall: `bash /www/panel/scripts/phpmyadmin/uninstall.sh`,
Expand Down
2 changes: 2 additions & 0 deletions routes/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func Plugin() {
phpMyAdminController := plugins.NewPhpMyAdminController()
route.Get("info", phpMyAdminController.Info)
route.Post("port", phpMyAdminController.SetPort)
route.Get("config", phpMyAdminController.GetConfig)
route.Post("config", phpMyAdminController.SaveConfig)
})
r.Prefix("pureftpd").Group(func(route route.Router) {
pureFtpdController := plugins.NewPureFtpdController()
Expand Down
6 changes: 6 additions & 0 deletions scripts/php/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ systemctl disable php-fpm-${phpVersion}
rm -rf /lib/systemd/system/php-fpm-${phpVersion}.service
systemctl daemon-reload

# 检查是否存在phpMyAdmin
if [ -d "${setupPath}/server/phpmyadmin" ]; then
sed -i "s/enable-php-${phpVersion}/enable-php-0/g" ${setupPath}/server/vhost/phpmyadmin.conf
systemctl reload openresty
fi

rm -rf ${phpPath}
rm -f /usr/bin/php-${phpVersion}

Expand Down

0 comments on commit 63838bf

Please sign in to comment.