mirror of
https://github.com/acepanel/panel.git
synced 2026-02-06 12:27:13 +08:00
refactor: 使用中间件判断安装状态
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
"github.com/goravel/framework/facades"
|
||||
|
||||
"panel/app/services"
|
||||
)
|
||||
|
||||
// SuccessResponse 通用成功响应
|
||||
@@ -59,47 +54,3 @@ func Sanitize(ctx http.Context, request http.FormRequest) http.Response {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check 检查插件是否可用
|
||||
func Check(ctx http.Context, slug string) http.Response {
|
||||
plugin := services.NewPluginImpl().GetBySlug(slug)
|
||||
installedPlugin := services.NewPluginImpl().GetInstalledBySlug(slug)
|
||||
installedPlugins, err := services.NewPluginImpl().AllInstalled()
|
||||
if err != nil {
|
||||
facades.Log().Info("[面板][插件] 获取已安装插件失败")
|
||||
return ErrorSystem(ctx)
|
||||
}
|
||||
|
||||
if installedPlugin.Version != plugin.Version || installedPlugin.Slug != plugin.Slug {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 需要更新至 "+plugin.Version+" 版本")
|
||||
}
|
||||
|
||||
var lock sync.RWMutex
|
||||
pluginsMap := make(map[string]bool)
|
||||
|
||||
for _, p := range installedPlugins {
|
||||
lock.Lock()
|
||||
pluginsMap[p.Slug] = true
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
for _, require := range plugin.Requires {
|
||||
lock.RLock()
|
||||
_, requireFound := pluginsMap[require]
|
||||
lock.RUnlock()
|
||||
if !requireFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 需要依赖 "+require+" 插件")
|
||||
}
|
||||
}
|
||||
|
||||
for _, exclude := range plugin.Excludes {
|
||||
lock.RLock()
|
||||
_, excludeFound := pluginsMap[exclude]
|
||||
lock.RUnlock()
|
||||
if excludeFound {
|
||||
return Error(ctx, http.StatusForbidden, "插件 "+slug+" 不兼容 "+exclude+" 插件")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,11 +26,6 @@ func NewFail2banController() *Fail2banController {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *Fail2banController) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("fail2ban")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取服务运行状态失败")
|
||||
@@ -41,11 +36,6 @@ func (r *Fail2banController) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Reload 重载配置
|
||||
func (r *Fail2banController) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if _, err := tools.Exec("systemctl reload fail2ban"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载配置失败")
|
||||
}
|
||||
@@ -55,11 +45,6 @@ func (r *Fail2banController) Reload(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启服务
|
||||
func (r *Fail2banController) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("fail2ban"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启服务失败")
|
||||
}
|
||||
@@ -69,11 +54,6 @@ func (r *Fail2banController) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动服务
|
||||
func (r *Fail2banController) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("fail2ban"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动服务失败")
|
||||
}
|
||||
@@ -83,11 +63,6 @@ func (r *Fail2banController) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止服务
|
||||
func (r *Fail2banController) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("fail2ban"); err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -101,11 +76,6 @@ func (r *Fail2banController) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// List 所有 Fail2ban 规则
|
||||
func (r *Fail2banController) List(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
page := ctx.Request().QueryInt("page", 1)
|
||||
limit := ctx.Request().QueryInt("limit", 10)
|
||||
raw, err := tools.Read("/etc/fail2ban/jail.local")
|
||||
@@ -169,11 +139,6 @@ func (r *Fail2banController) List(ctx http.Context) http.Response {
|
||||
|
||||
// Add 添加 Fail2ban 规则
|
||||
func (r *Fail2banController) Add(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"name": "required",
|
||||
"type": "required|in:website,service",
|
||||
@@ -318,11 +283,6 @@ logpath = ` + logPath + `
|
||||
|
||||
// Delete 删除规则
|
||||
func (r *Fail2banController) Delete(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
jailName := ctx.Request().Input("name")
|
||||
raw, err := tools.Read("/etc/fail2ban/jail.local")
|
||||
if err != nil {
|
||||
@@ -348,11 +308,6 @@ func (r *Fail2banController) Delete(ctx http.Context) http.Response {
|
||||
|
||||
// BanList 获取封禁列表
|
||||
func (r *Fail2banController) BanList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
name := ctx.Request().Input("name")
|
||||
if len(name) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "缺少参数")
|
||||
@@ -394,11 +349,6 @@ func (r *Fail2banController) BanList(ctx http.Context) http.Response {
|
||||
|
||||
// Unban 解封
|
||||
func (r *Fail2banController) Unban(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
name := ctx.Request().Input("name")
|
||||
ip := ctx.Request().Input("ip")
|
||||
if len(name) == 0 || len(ip) == 0 {
|
||||
@@ -414,11 +364,6 @@ func (r *Fail2banController) Unban(ctx http.Context) http.Response {
|
||||
|
||||
// SetWhiteList 设置白名单
|
||||
func (r *Fail2banController) SetWhiteList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
ip := ctx.Request().Input("ip")
|
||||
if len(ip) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "缺少参数")
|
||||
@@ -448,11 +393,6 @@ func (r *Fail2banController) SetWhiteList(ctx http.Context) http.Response {
|
||||
|
||||
// GetWhiteList 获取白名单
|
||||
func (r *Fail2banController) GetWhiteList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "fail2ban")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
raw, err := tools.Read("/etc/fail2ban/jail.local")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, err.Error())
|
||||
|
||||
@@ -28,11 +28,6 @@ func NewMysql57Controller() *Mysql57Controller {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *Mysql57Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("mysqld")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败")
|
||||
@@ -43,11 +38,6 @@ func (r *Mysql57Controller) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Reload 重载配置
|
||||
func (r *Mysql57Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载MySQL失败")
|
||||
}
|
||||
@@ -57,11 +47,6 @@ func (r *Mysql57Controller) Reload(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启服务
|
||||
func (r *Mysql57Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启MySQL服务失败")
|
||||
}
|
||||
@@ -71,11 +56,6 @@ func (r *Mysql57Controller) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动服务
|
||||
func (r *Mysql57Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动MySQL服务失败")
|
||||
}
|
||||
@@ -85,11 +65,6 @@ func (r *Mysql57Controller) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止服务
|
||||
func (r *Mysql57Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止MySQL服务失败")
|
||||
}
|
||||
@@ -99,11 +74,6 @@ func (r *Mysql57Controller) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (r *Mysql57Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/mysql/conf/my.cnf")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL配置失败")
|
||||
@@ -114,11 +84,6 @@ func (r *Mysql57Controller) GetConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveConfig 保存配置
|
||||
func (r *Mysql57Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "配置不能为空")
|
||||
@@ -133,11 +98,6 @@ func (r *Mysql57Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
|
||||
// Load 获取负载
|
||||
func (r *Mysql57Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword)
|
||||
if len(rootPassword) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "MySQL root密码为空")
|
||||
@@ -208,11 +168,6 @@ func (r *Mysql57Controller) Load(ctx http.Context) http.Response {
|
||||
|
||||
// ErrorLog 获取错误日志
|
||||
func (r *Mysql57Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/mysql/mysql-error.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -223,11 +178,6 @@ func (r *Mysql57Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
|
||||
// ClearErrorLog 清空错误日志
|
||||
func (r *Mysql57Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/mysql/mysql-error.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -237,11 +187,6 @@ func (r *Mysql57Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
|
||||
// SlowLog 获取慢查询日志
|
||||
func (r *Mysql57Controller) SlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/mysql/mysql-slow.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -252,11 +197,6 @@ func (r *Mysql57Controller) SlowLog(ctx http.Context) http.Response {
|
||||
|
||||
// ClearSlowLog 清空慢查询日志
|
||||
func (r *Mysql57Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/mysql/mysql-slow.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -265,11 +205,6 @@ func (r *Mysql57Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
|
||||
// GetRootPassword 获取root密码
|
||||
func (r *Mysql57Controller) GetRootPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword)
|
||||
if len(rootPassword) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "MySQL root密码为空")
|
||||
@@ -280,11 +215,6 @@ func (r *Mysql57Controller) GetRootPassword(ctx http.Context) http.Response {
|
||||
|
||||
// SetRootPassword 设置root密码
|
||||
func (r *Mysql57Controller) SetRootPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("mysqld")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败")
|
||||
@@ -323,11 +253,6 @@ func (r *Mysql57Controller) SetRootPassword(ctx http.Context) http.Response {
|
||||
|
||||
// DatabaseList 获取数据库列表
|
||||
func (r *Mysql57Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword)
|
||||
type database struct {
|
||||
Name string `json:"name"`
|
||||
@@ -383,11 +308,6 @@ func (r *Mysql57Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
|
||||
// AddDatabase 添加数据库
|
||||
func (r *Mysql57Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -423,11 +343,6 @@ func (r *Mysql57Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteDatabase 删除数据库
|
||||
func (r *Mysql57Controller) DeleteDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
})
|
||||
@@ -449,11 +364,6 @@ func (r *Mysql57Controller) DeleteDatabase(ctx http.Context) http.Response {
|
||||
|
||||
// BackupList 获取备份列表
|
||||
func (r *Mysql57Controller) BackupList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
backupList, err := r.backup.MysqlList()
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -485,11 +395,6 @@ func (r *Mysql57Controller) BackupList(ctx http.Context) http.Response {
|
||||
|
||||
// UploadBackup 上传备份
|
||||
func (r *Mysql57Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
file, err := ctx.Request().File("file")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "上传文件失败")
|
||||
@@ -513,11 +418,6 @@ func (r *Mysql57Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
|
||||
// CreateBackup 创建备份
|
||||
func (r *Mysql57Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
})
|
||||
@@ -539,11 +439,6 @@ func (r *Mysql57Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteBackup 删除备份
|
||||
func (r *Mysql57Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"name": "required|min_len:1|max_len:255",
|
||||
})
|
||||
@@ -565,11 +460,6 @@ func (r *Mysql57Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
|
||||
// RestoreBackup 还原备份
|
||||
func (r *Mysql57Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"backup": "required|min_len:1|max_len:255",
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
@@ -591,11 +481,6 @@ func (r *Mysql57Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
|
||||
// UserList 用户列表
|
||||
func (r *Mysql57Controller) UserList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
type user struct {
|
||||
User string `json:"user"`
|
||||
Host string `json:"host"`
|
||||
@@ -675,11 +560,6 @@ func (r *Mysql57Controller) UserList(ctx http.Context) http.Response {
|
||||
|
||||
// AddUser 添加用户
|
||||
func (r *Mysql57Controller) AddUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -711,11 +591,6 @@ func (r *Mysql57Controller) AddUser(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteUser 删除用户
|
||||
func (r *Mysql57Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
})
|
||||
@@ -737,11 +612,6 @@ func (r *Mysql57Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
|
||||
// SetUserPassword 设置用户密码
|
||||
func (r *Mysql57Controller) SetUserPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"password": "required|min_len:8|max_len:255",
|
||||
@@ -768,11 +638,6 @@ func (r *Mysql57Controller) SetUserPassword(ctx http.Context) http.Response {
|
||||
|
||||
// SetUserPrivileges 设置用户权限
|
||||
func (r *Mysql57Controller) SetUserPrivileges(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql57")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"database": "required|min_len:1|max_len:255",
|
||||
|
||||
@@ -28,11 +28,6 @@ func NewMysql80Controller() *Mysql80Controller {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *Mysql80Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("mysqld")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败")
|
||||
@@ -43,11 +38,6 @@ func (r *Mysql80Controller) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Reload 重载配置
|
||||
func (r *Mysql80Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载MySQL配置失败")
|
||||
}
|
||||
@@ -57,11 +47,6 @@ func (r *Mysql80Controller) Reload(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启服务
|
||||
func (r *Mysql80Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启MySQL服务失败")
|
||||
}
|
||||
@@ -71,11 +56,6 @@ func (r *Mysql80Controller) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动服务
|
||||
func (r *Mysql80Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动MySQL服务失败")
|
||||
}
|
||||
@@ -85,11 +65,6 @@ func (r *Mysql80Controller) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止服务
|
||||
func (r *Mysql80Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("mysqld"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止MySQL服务失败")
|
||||
}
|
||||
@@ -99,11 +74,6 @@ func (r *Mysql80Controller) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (r *Mysql80Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/mysql/conf/my.cnf")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL配置失败")
|
||||
@@ -114,11 +84,6 @@ func (r *Mysql80Controller) GetConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveConfig 保存配置
|
||||
func (r *Mysql80Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "配置不能为空")
|
||||
@@ -133,11 +98,6 @@ func (r *Mysql80Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
|
||||
// Load 获取负载
|
||||
func (r *Mysql80Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword)
|
||||
if len(rootPassword) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "MySQL root密码为空")
|
||||
@@ -208,11 +168,6 @@ func (r *Mysql80Controller) Load(ctx http.Context) http.Response {
|
||||
|
||||
// ErrorLog 获取错误日志
|
||||
func (r *Mysql80Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/mysql/mysql-error.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -223,11 +178,6 @@ func (r *Mysql80Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
|
||||
// ClearErrorLog 清空错误日志
|
||||
func (r *Mysql80Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/mysql/mysql-error.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -237,11 +187,6 @@ func (r *Mysql80Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
|
||||
// SlowLog 获取慢查询日志
|
||||
func (r *Mysql80Controller) SlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/mysql/mysql-slow.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -252,11 +197,6 @@ func (r *Mysql80Controller) SlowLog(ctx http.Context) http.Response {
|
||||
|
||||
// ClearSlowLog 清空慢查询日志
|
||||
func (r *Mysql80Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/mysql/mysql-slow.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -265,11 +205,6 @@ func (r *Mysql80Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
|
||||
// GetRootPassword 获取root密码
|
||||
func (r *Mysql80Controller) GetRootPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword)
|
||||
if len(rootPassword) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "MySQL root密码为空")
|
||||
@@ -280,11 +215,6 @@ func (r *Mysql80Controller) GetRootPassword(ctx http.Context) http.Response {
|
||||
|
||||
// SetRootPassword 设置root密码
|
||||
func (r *Mysql80Controller) SetRootPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("mysqld")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取MySQL状态失败")
|
||||
@@ -323,11 +253,6 @@ func (r *Mysql80Controller) SetRootPassword(ctx http.Context) http.Response {
|
||||
|
||||
// DatabaseList 获取数据库列表
|
||||
func (r *Mysql80Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
rootPassword := r.setting.Get(models.SettingKeyMysqlRootPassword)
|
||||
type database struct {
|
||||
Name string `json:"name"`
|
||||
@@ -383,11 +308,6 @@ func (r *Mysql80Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
|
||||
// AddDatabase 添加数据库
|
||||
func (r *Mysql80Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -423,11 +343,6 @@ func (r *Mysql80Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteDatabase 删除数据库
|
||||
func (r *Mysql80Controller) DeleteDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
})
|
||||
@@ -449,11 +364,6 @@ func (r *Mysql80Controller) DeleteDatabase(ctx http.Context) http.Response {
|
||||
|
||||
// BackupList 获取备份列表
|
||||
func (r *Mysql80Controller) BackupList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
backupList, err := r.backup.MysqlList()
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -485,11 +395,6 @@ func (r *Mysql80Controller) BackupList(ctx http.Context) http.Response {
|
||||
|
||||
// UploadBackup 上传备份
|
||||
func (r *Mysql80Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
file, err := ctx.Request().File("file")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "上传文件失败")
|
||||
@@ -513,11 +418,6 @@ func (r *Mysql80Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
|
||||
// CreateBackup 创建备份
|
||||
func (r *Mysql80Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
})
|
||||
@@ -539,11 +439,6 @@ func (r *Mysql80Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteBackup 删除备份
|
||||
func (r *Mysql80Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"name": "required|min_len:1|max_len:255",
|
||||
})
|
||||
@@ -565,11 +460,6 @@ func (r *Mysql80Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
|
||||
// RestoreBackup 还原备份
|
||||
func (r *Mysql80Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"backup": "required|min_len:1|max_len:255",
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
@@ -591,11 +481,6 @@ func (r *Mysql80Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
|
||||
// UserList 用户列表
|
||||
func (r *Mysql80Controller) UserList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
type user struct {
|
||||
User string `json:"user"`
|
||||
Host string `json:"host"`
|
||||
@@ -675,11 +560,6 @@ func (r *Mysql80Controller) UserList(ctx http.Context) http.Response {
|
||||
|
||||
// AddUser 添加用户
|
||||
func (r *Mysql80Controller) AddUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -711,11 +591,6 @@ func (r *Mysql80Controller) AddUser(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteUser 删除用户
|
||||
func (r *Mysql80Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
})
|
||||
@@ -737,11 +612,6 @@ func (r *Mysql80Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
|
||||
// SetUserPassword 设置用户密码
|
||||
func (r *Mysql80Controller) SetUserPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"password": "required|min_len:8|max_len:255",
|
||||
@@ -768,11 +638,6 @@ func (r *Mysql80Controller) SetUserPassword(ctx http.Context) http.Response {
|
||||
|
||||
// SetUserPrivileges 设置用户权限
|
||||
func (r *Mysql80Controller) SetUserPrivileges(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "mysql80")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"database": "required|min_len:1|max_len:255",
|
||||
|
||||
@@ -24,11 +24,6 @@ func NewOpenrestyController() *OpenRestyController {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *OpenRestyController) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("openresty")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty状态失败")
|
||||
@@ -39,11 +34,6 @@ func (r *OpenRestyController) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Reload 重载配置
|
||||
func (r *OpenRestyController) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("openresty"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载OpenResty失败")
|
||||
}
|
||||
@@ -53,11 +43,6 @@ func (r *OpenRestyController) Reload(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动OpenResty
|
||||
func (r *OpenRestyController) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("openresty"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动OpenResty失败")
|
||||
}
|
||||
@@ -67,11 +52,6 @@ func (r *OpenRestyController) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止OpenResty
|
||||
func (r *OpenRestyController) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("openresty"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止OpenResty失败")
|
||||
}
|
||||
@@ -81,11 +61,6 @@ func (r *OpenRestyController) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启OpenResty
|
||||
func (r *OpenRestyController) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("openresty"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启OpenResty失败")
|
||||
}
|
||||
@@ -95,11 +70,6 @@ func (r *OpenRestyController) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (r *OpenRestyController) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/openresty/conf/nginx.conf")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取OpenResty配置失败")
|
||||
@@ -110,11 +80,6 @@ func (r *OpenRestyController) GetConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveConfig 保存配置
|
||||
func (r *OpenRestyController) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "配置不能为空")
|
||||
@@ -129,11 +94,6 @@ func (r *OpenRestyController) SaveConfig(ctx http.Context) http.Response {
|
||||
|
||||
// ErrorLog 获取错误日志
|
||||
func (r *OpenRestyController) ErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if !tools.Exists("/www/wwwlogs/nginx_error.log") {
|
||||
return controllers.Success(ctx, "")
|
||||
}
|
||||
@@ -148,11 +108,6 @@ func (r *OpenRestyController) ErrorLog(ctx http.Context) http.Response {
|
||||
|
||||
// ClearErrorLog 清空错误日志
|
||||
func (r *OpenRestyController) ClearErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/wwwlogs/nginx_error.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -162,11 +117,6 @@ func (r *OpenRestyController) ClearErrorLog(ctx http.Context) http.Response {
|
||||
|
||||
// Load 获取负载
|
||||
func (r *OpenRestyController) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
client := req.C().SetTimeout(10 * time.Second)
|
||||
resp, err := client.R().Get("http://127.0.0.1/nginx_status")
|
||||
if err != nil || !resp.IsSuccessState() {
|
||||
|
||||
@@ -31,11 +31,6 @@ func NewPhp74Controller() *Php74Controller {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("php-fpm-" + r.version)
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"运行状态失败")
|
||||
@@ -45,11 +40,6 @@ func (r *Php74Controller) Status(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -58,11 +48,6 @@ func (r *Php74Controller) Reload(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -71,11 +56,6 @@ func (r *Php74Controller) Start(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -84,11 +64,6 @@ func (r *Php74Controller) Stop(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -97,11 +72,6 @@ func (r *Php74Controller) Restart(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/php/" + r.version + "/etc/php.ini")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"配置失败")
|
||||
@@ -111,11 +81,6 @@ func (r *Php74Controller) GetConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if err := tools.Write("/www/server/php/"+r.version+"/etc/php.ini", config, 0644); err != nil {
|
||||
return nil
|
||||
@@ -124,11 +89,6 @@ func (r *Php74Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
client := req.C().SetTimeout(10 * time.Second)
|
||||
resp, err := client.R().Get("http://127.0.0.1/phpfpm_status/" + r.version)
|
||||
if err != nil || !resp.IsSuccessState() {
|
||||
@@ -160,11 +120,6 @@ func (r *Php74Controller) Load(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/php-fpm.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -174,11 +129,6 @@ func (r *Php74Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) SlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/slow.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -188,11 +138,6 @@ func (r *Php74Controller) SlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/php-fpm.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -201,11 +146,6 @@ func (r *Php74Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/slow.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -213,21 +153,11 @@ func (r *Php74Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) GetExtensionList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
extensions := r.GetExtensions()
|
||||
return controllers.Success(ctx, extensions)
|
||||
}
|
||||
|
||||
func (r *Php74Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
@@ -260,11 +190,6 @@ func (r *Php74Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php74Controller) UninstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
|
||||
@@ -31,11 +31,6 @@ func NewPhp80Controller() *Php80Controller {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("php-fpm-" + r.version)
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"运行状态失败")
|
||||
@@ -45,11 +40,6 @@ func (r *Php80Controller) Status(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -58,11 +48,6 @@ func (r *Php80Controller) Reload(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -71,11 +56,6 @@ func (r *Php80Controller) Start(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -84,11 +64,6 @@ func (r *Php80Controller) Stop(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -97,11 +72,6 @@ func (r *Php80Controller) Restart(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/php/" + r.version + "/etc/php.ini")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"配置失败")
|
||||
@@ -111,11 +81,6 @@ func (r *Php80Controller) GetConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if err := tools.Write("/www/server/php/"+r.version+"/etc/php.ini", config, 0644); err != nil {
|
||||
return nil
|
||||
@@ -124,11 +89,6 @@ func (r *Php80Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
client := req.C().SetTimeout(10 * time.Second)
|
||||
resp, err := client.R().Get("http://127.0.0.1/phpfpm_status/" + r.version)
|
||||
if err != nil || !resp.IsSuccessState() {
|
||||
@@ -160,11 +120,6 @@ func (r *Php80Controller) Load(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/php-fpm.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -174,11 +129,6 @@ func (r *Php80Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) SlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/slow.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -188,11 +138,6 @@ func (r *Php80Controller) SlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/php-fpm.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -201,11 +146,6 @@ func (r *Php80Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/slow.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -213,21 +153,11 @@ func (r *Php80Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) GetExtensionList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
extensions := r.GetExtensions()
|
||||
return controllers.Success(ctx, extensions)
|
||||
}
|
||||
|
||||
func (r *Php80Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
@@ -260,11 +190,6 @@ func (r *Php80Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php80Controller) UninstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
|
||||
@@ -31,11 +31,6 @@ func NewPhp81Controller() *Php81Controller {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("php-fpm-" + r.version)
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"运行状态失败")
|
||||
@@ -45,11 +40,6 @@ func (r *Php81Controller) Status(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -58,11 +48,6 @@ func (r *Php81Controller) Reload(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -71,11 +56,6 @@ func (r *Php81Controller) Start(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -84,11 +64,6 @@ func (r *Php81Controller) Stop(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -97,11 +72,6 @@ func (r *Php81Controller) Restart(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/php/" + r.version + "/etc/php.ini")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"配置失败")
|
||||
@@ -111,11 +81,6 @@ func (r *Php81Controller) GetConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if err := tools.Write("/www/server/php/"+r.version+"/etc/php.ini", config, 0644); err != nil {
|
||||
return nil
|
||||
@@ -124,11 +89,6 @@ func (r *Php81Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
client := req.C().SetTimeout(10 * time.Second)
|
||||
resp, err := client.R().Get("http://127.0.0.1/phpfpm_status/" + r.version)
|
||||
if err != nil || !resp.IsSuccessState() {
|
||||
@@ -160,11 +120,6 @@ func (r *Php81Controller) Load(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/php-fpm.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -174,11 +129,6 @@ func (r *Php81Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) SlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/slow.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -188,11 +138,6 @@ func (r *Php81Controller) SlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/php-fpm.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -201,11 +146,6 @@ func (r *Php81Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/slow.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -213,21 +153,11 @@ func (r *Php81Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) GetExtensionList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
extensions := r.GetExtensions()
|
||||
return controllers.Success(ctx, extensions)
|
||||
}
|
||||
|
||||
func (r *Php81Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
@@ -260,11 +190,6 @@ func (r *Php81Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php81Controller) UninstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
|
||||
@@ -31,11 +31,6 @@ func NewPhp82Controller() *Php82Controller {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("php-fpm-" + r.version)
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"运行状态失败")
|
||||
@@ -45,11 +40,6 @@ func (r *Php82Controller) Status(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -58,11 +48,6 @@ func (r *Php82Controller) Reload(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -71,11 +56,6 @@ func (r *Php82Controller) Start(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -84,11 +64,6 @@ func (r *Php82Controller) Stop(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("php-fpm-" + r.version); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启PHP-"+r.version+"失败")
|
||||
}
|
||||
@@ -97,11 +72,6 @@ func (r *Php82Controller) Restart(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config, err := tools.Read("/www/server/php/" + r.version + "/etc/php.ini")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PHP-"+r.version+"配置失败")
|
||||
@@ -111,11 +81,6 @@ func (r *Php82Controller) GetConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if err := tools.Write("/www/server/php/"+r.version+"/etc/php.ini", config, 0644); err != nil {
|
||||
return nil
|
||||
@@ -124,11 +89,6 @@ func (r *Php82Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
client := req.C().SetTimeout(10 * time.Second)
|
||||
resp, err := client.R().Get("http://127.0.0.1/phpfpm_status/" + r.version)
|
||||
if err != nil || !resp.IsSuccessState() {
|
||||
@@ -160,11 +120,6 @@ func (r *Php82Controller) Load(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/php-fpm.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -174,11 +129,6 @@ func (r *Php82Controller) ErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) SlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/php/" + r.version + "/var/log/slow.log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -188,11 +138,6 @@ func (r *Php82Controller) SlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/php-fpm.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -201,11 +146,6 @@ func (r *Php82Controller) ClearErrorLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/php/" + r.version + "/var/log/slow.log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -213,21 +153,11 @@ func (r *Php82Controller) ClearSlowLog(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) GetExtensionList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
extensions := r.GetExtensions()
|
||||
return controllers.Success(ctx, extensions)
|
||||
}
|
||||
|
||||
func (r *Php82Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
@@ -260,11 +190,6 @@ func (r *Php82Controller) InstallExtension(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *Php82Controller) UninstallExtension(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "php"+r.version)
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
slug := ctx.Request().Input("slug")
|
||||
if len(slug) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "参数错误")
|
||||
|
||||
@@ -21,11 +21,6 @@ func NewPhpMyAdminController() *PhpMyAdminController {
|
||||
}
|
||||
|
||||
func (r *PhpMyAdminController) Info(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "phpmyadmin")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
files, err := os.ReadDir("/www/server/phpmyadmin")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "找不到 phpMyAdmin 目录")
|
||||
@@ -57,11 +52,6 @@ func (r *PhpMyAdminController) Info(ctx http.Context) http.Response {
|
||||
}
|
||||
|
||||
func (r *PhpMyAdminController) SetPort(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "phpmyadmin")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
port := ctx.Request().Input("port")
|
||||
if len(port) == 0 {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "端口不能为空")
|
||||
|
||||
@@ -26,11 +26,6 @@ func NewPostgresql15Controller() *Postgresql15Controller {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *Postgresql15Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("postgresql")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PostgreSQL状态失败")
|
||||
@@ -41,11 +36,6 @@ func (r *Postgresql15Controller) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Reload 重载配置
|
||||
func (r *Postgresql15Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载PostgreSQL失败")
|
||||
}
|
||||
@@ -55,11 +45,6 @@ func (r *Postgresql15Controller) Reload(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启服务
|
||||
func (r *Postgresql15Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启PostgreSQL失败")
|
||||
}
|
||||
@@ -69,11 +54,6 @@ func (r *Postgresql15Controller) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动服务
|
||||
func (r *Postgresql15Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动PostgreSQL失败")
|
||||
}
|
||||
@@ -83,11 +63,6 @@ func (r *Postgresql15Controller) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止服务
|
||||
func (r *Postgresql15Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止PostgreSQL失败")
|
||||
}
|
||||
@@ -97,11 +72,6 @@ func (r *Postgresql15Controller) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (r *Postgresql15Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
config, err := tools.Read("/www/server/postgresql/data/postgresql.conf")
|
||||
if err != nil {
|
||||
@@ -113,11 +83,6 @@ func (r *Postgresql15Controller) GetConfig(ctx http.Context) http.Response {
|
||||
|
||||
// GetUserConfig 获取用户配置
|
||||
func (r *Postgresql15Controller) GetUserConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
config, err := tools.Read("/www/server/postgresql/data/pg_hba.conf")
|
||||
if err != nil {
|
||||
@@ -129,11 +94,6 @@ func (r *Postgresql15Controller) GetUserConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveConfig 保存配置
|
||||
func (r *Postgresql15Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "配置不能为空")
|
||||
@@ -148,11 +108,6 @@ func (r *Postgresql15Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveUserConfig 保存用户配置
|
||||
func (r *Postgresql15Controller) SaveUserConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "配置不能为空")
|
||||
@@ -167,11 +122,6 @@ func (r *Postgresql15Controller) SaveUserConfig(ctx http.Context) http.Response
|
||||
|
||||
// Load 获取负载
|
||||
func (r *Postgresql15Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("postgresql")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PostgreSQL状态失败")
|
||||
@@ -214,11 +164,6 @@ func (r *Postgresql15Controller) Load(ctx http.Context) http.Response {
|
||||
|
||||
// Log 获取日志
|
||||
func (r *Postgresql15Controller) Log(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/postgresql/logs/postgresql-" + carbon.Now().ToDateString() + ".log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -229,11 +174,6 @@ func (r *Postgresql15Controller) Log(ctx http.Context) http.Response {
|
||||
|
||||
// ClearLog 清空日志
|
||||
func (r *Postgresql15Controller) ClearLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/postgresql/logs/postgresql-" + carbon.Now().ToDateString() + ".log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -243,11 +183,6 @@ func (r *Postgresql15Controller) ClearLog(ctx http.Context) http.Response {
|
||||
|
||||
// DatabaseList 获取数据库列表
|
||||
func (r *Postgresql15Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("postgresql")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PostgreSQL状态失败")
|
||||
@@ -313,11 +248,6 @@ func (r *Postgresql15Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
|
||||
// AddDatabase 添加数据库
|
||||
func (r *Postgresql15Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -357,11 +287,6 @@ func (r *Postgresql15Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteDatabase 删除数据库
|
||||
func (r *Postgresql15Controller) DeleteDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:postgres,template0,template1",
|
||||
})
|
||||
@@ -382,11 +307,6 @@ func (r *Postgresql15Controller) DeleteDatabase(ctx http.Context) http.Response
|
||||
|
||||
// BackupList 获取备份列表
|
||||
func (r *Postgresql15Controller) BackupList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
backupList, err := r.backup.PostgresqlList()
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取备份列表失败")
|
||||
@@ -418,11 +338,6 @@ func (r *Postgresql15Controller) BackupList(ctx http.Context) http.Response {
|
||||
|
||||
// UploadBackup 上传备份
|
||||
func (r *Postgresql15Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
file, err := ctx.Request().File("file")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "上传文件失败")
|
||||
@@ -446,11 +361,6 @@ func (r *Postgresql15Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
|
||||
// CreateBackup 创建备份
|
||||
func (r *Postgresql15Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
})
|
||||
@@ -472,11 +382,6 @@ func (r *Postgresql15Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteBackup 删除备份
|
||||
func (r *Postgresql15Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"name": "required|min_len:1|max_len:255",
|
||||
})
|
||||
@@ -498,11 +403,6 @@ func (r *Postgresql15Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
|
||||
// RestoreBackup 还原备份
|
||||
func (r *Postgresql15Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"backup": "required|min_len:1|max_len:255",
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
@@ -524,11 +424,6 @@ func (r *Postgresql15Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
|
||||
// UserList 用户列表
|
||||
func (r *Postgresql15Controller) UserList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
type user struct {
|
||||
User string `json:"user"`
|
||||
Role string `json:"role"`
|
||||
@@ -580,11 +475,6 @@ func (r *Postgresql15Controller) UserList(ctx http.Context) http.Response {
|
||||
|
||||
// AddUser 添加用户
|
||||
func (r *Postgresql15Controller) AddUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -617,11 +507,6 @@ func (r *Postgresql15Controller) AddUser(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteUser 删除用户
|
||||
func (r *Postgresql15Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
})
|
||||
@@ -645,11 +530,6 @@ func (r *Postgresql15Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
|
||||
// SetUserPassword 设置用户密码
|
||||
func (r *Postgresql15Controller) SetUserPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql15")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"password": "required|min_len:8|max_len:255",
|
||||
|
||||
@@ -26,11 +26,6 @@ func NewPostgresql16Controller() *Postgresql16Controller {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *Postgresql16Controller) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("postgresql")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PostgreSQL状态失败")
|
||||
@@ -41,11 +36,6 @@ func (r *Postgresql16Controller) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Reload 重载配置
|
||||
func (r *Postgresql16Controller) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载PostgreSQL失败")
|
||||
}
|
||||
@@ -55,11 +45,6 @@ func (r *Postgresql16Controller) Reload(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启服务
|
||||
func (r *Postgresql16Controller) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启PostgreSQL失败")
|
||||
}
|
||||
@@ -69,11 +54,6 @@ func (r *Postgresql16Controller) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动服务
|
||||
func (r *Postgresql16Controller) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动PostgreSQL失败")
|
||||
}
|
||||
@@ -83,11 +63,6 @@ func (r *Postgresql16Controller) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止服务
|
||||
func (r *Postgresql16Controller) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("postgresql"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止PostgreSQL失败")
|
||||
}
|
||||
@@ -97,11 +72,6 @@ func (r *Postgresql16Controller) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (r *Postgresql16Controller) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
config, err := tools.Read("/www/server/postgresql/data/postgresql.conf")
|
||||
if err != nil {
|
||||
@@ -113,11 +83,6 @@ func (r *Postgresql16Controller) GetConfig(ctx http.Context) http.Response {
|
||||
|
||||
// GetUserConfig 获取用户配置
|
||||
func (r *Postgresql16Controller) GetUserConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
config, err := tools.Read("/www/server/postgresql/data/pg_hba.conf")
|
||||
if err != nil {
|
||||
@@ -129,11 +94,6 @@ func (r *Postgresql16Controller) GetUserConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveConfig 保存配置
|
||||
func (r *Postgresql16Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "配置不能为空")
|
||||
@@ -148,11 +108,6 @@ func (r *Postgresql16Controller) SaveConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveUserConfig 保存用户配置
|
||||
func (r *Postgresql16Controller) SaveUserConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "配置不能为空")
|
||||
@@ -167,11 +122,6 @@ func (r *Postgresql16Controller) SaveUserConfig(ctx http.Context) http.Response
|
||||
|
||||
// Load 获取负载
|
||||
func (r *Postgresql16Controller) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("postgresql")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PostgreSQL状态失败")
|
||||
@@ -214,11 +164,6 @@ func (r *Postgresql16Controller) Load(ctx http.Context) http.Response {
|
||||
|
||||
// Log 获取日志
|
||||
func (r *Postgresql16Controller) Log(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec("tail -n 100 /www/server/postgresql/logs/postgresql-" + carbon.Now().ToDateString() + ".log")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -229,11 +174,6 @@ func (r *Postgresql16Controller) Log(ctx http.Context) http.Response {
|
||||
|
||||
// ClearLog 清空日志
|
||||
func (r *Postgresql16Controller) ClearLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec("echo '' > /www/server/postgresql/logs/postgresql-" + carbon.Now().ToDateString() + ".log"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -243,11 +183,6 @@ func (r *Postgresql16Controller) ClearLog(ctx http.Context) http.Response {
|
||||
|
||||
// DatabaseList 获取数据库列表
|
||||
func (r *Postgresql16Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("postgresql")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PostgreSQL状态失败")
|
||||
@@ -313,11 +248,6 @@ func (r *Postgresql16Controller) DatabaseList(ctx http.Context) http.Response {
|
||||
|
||||
// AddDatabase 添加数据库
|
||||
func (r *Postgresql16Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -357,11 +287,6 @@ func (r *Postgresql16Controller) AddDatabase(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteDatabase 删除数据库
|
||||
func (r *Postgresql16Controller) DeleteDatabase(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:postgres,template0,template1",
|
||||
})
|
||||
@@ -382,11 +307,6 @@ func (r *Postgresql16Controller) DeleteDatabase(ctx http.Context) http.Response
|
||||
|
||||
// BackupList 获取备份列表
|
||||
func (r *Postgresql16Controller) BackupList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
backupList, err := r.backup.PostgresqlList()
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取备份列表失败")
|
||||
@@ -418,11 +338,6 @@ func (r *Postgresql16Controller) BackupList(ctx http.Context) http.Response {
|
||||
|
||||
// UploadBackup 上传备份
|
||||
func (r *Postgresql16Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
file, err := ctx.Request().File("file")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "上传文件失败")
|
||||
@@ -446,11 +361,6 @@ func (r *Postgresql16Controller) UploadBackup(ctx http.Context) http.Response {
|
||||
|
||||
// CreateBackup 创建备份
|
||||
func (r *Postgresql16Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
})
|
||||
@@ -472,11 +382,6 @@ func (r *Postgresql16Controller) CreateBackup(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteBackup 删除备份
|
||||
func (r *Postgresql16Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"name": "required|min_len:1|max_len:255",
|
||||
})
|
||||
@@ -498,11 +403,6 @@ func (r *Postgresql16Controller) DeleteBackup(ctx http.Context) http.Response {
|
||||
|
||||
// RestoreBackup 还原备份
|
||||
func (r *Postgresql16Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"backup": "required|min_len:1|max_len:255",
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$|not_in:information_schema,mysql,performance_schema,sys",
|
||||
@@ -524,11 +424,6 @@ func (r *Postgresql16Controller) RestoreBackup(ctx http.Context) http.Response {
|
||||
|
||||
// UserList 用户列表
|
||||
func (r *Postgresql16Controller) UserList(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
type user struct {
|
||||
User string `json:"user"`
|
||||
Role string `json:"role"`
|
||||
@@ -580,11 +475,6 @@ func (r *Postgresql16Controller) UserList(ctx http.Context) http.Response {
|
||||
|
||||
// AddUser 添加用户
|
||||
func (r *Postgresql16Controller) AddUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"database": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
@@ -617,11 +507,6 @@ func (r *Postgresql16Controller) AddUser(ctx http.Context) http.Response {
|
||||
|
||||
// DeleteUser 删除用户
|
||||
func (r *Postgresql16Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
})
|
||||
@@ -645,11 +530,6 @@ func (r *Postgresql16Controller) DeleteUser(ctx http.Context) http.Response {
|
||||
|
||||
// SetUserPassword 设置用户密码
|
||||
func (r *Postgresql16Controller) SetUserPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "postgresql16")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"user": "required|min_len:1|max_len:255|regex:^[a-zA-Z][a-zA-Z0-9_]+$",
|
||||
"password": "required|min_len:8|max_len:255",
|
||||
|
||||
@@ -25,11 +25,6 @@ func NewPureFtpdController() *PureFtpdController {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *PureFtpdController) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("pure-ftpd")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PureFtpd状态失败")
|
||||
@@ -40,11 +35,6 @@ func (r *PureFtpdController) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启服务
|
||||
func (r *PureFtpdController) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
err := tools.ServiceRestart("pure-ftpd")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启PureFtpd失败")
|
||||
@@ -55,11 +45,6 @@ func (r *PureFtpdController) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动服务
|
||||
func (r *PureFtpdController) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
err := tools.ServiceStart("pure-ftpd")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动PureFtpd失败")
|
||||
@@ -70,11 +55,6 @@ func (r *PureFtpdController) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止服务
|
||||
func (r *PureFtpdController) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
err := tools.ServiceStop("pure-ftpd")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止PureFtpd失败")
|
||||
@@ -85,11 +65,6 @@ func (r *PureFtpdController) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// List 获取用户列表
|
||||
func (r *PureFtpdController) List(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
listRaw, err := tools.Exec("pure-pw list")
|
||||
if err != nil {
|
||||
return controllers.Success(ctx, http.Json{
|
||||
@@ -135,11 +110,6 @@ func (r *PureFtpdController) List(ctx http.Context) http.Response {
|
||||
|
||||
// Add 添加用户
|
||||
func (r *PureFtpdController) Add(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"username": "required",
|
||||
"password": "required|min_len:6",
|
||||
@@ -181,11 +151,6 @@ func (r *PureFtpdController) Add(ctx http.Context) http.Response {
|
||||
|
||||
// Delete 删除用户
|
||||
func (r *PureFtpdController) Delete(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"username": "required",
|
||||
})
|
||||
@@ -210,11 +175,6 @@ func (r *PureFtpdController) Delete(ctx http.Context) http.Response {
|
||||
|
||||
// ChangePassword 修改密码
|
||||
func (r *PureFtpdController) ChangePassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"username": "required",
|
||||
"password": "required|min_len:6",
|
||||
@@ -241,11 +201,6 @@ func (r *PureFtpdController) ChangePassword(ctx http.Context) http.Response {
|
||||
|
||||
// GetPort 获取端口
|
||||
func (r *PureFtpdController) GetPort(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
port, err := tools.Exec(`cat /www/server/pure-ftpd/etc/pure-ftpd.conf | grep "Bind" | awk '{print $2}' | awk -F "," '{print $2}'`)
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取PureFtpd端口失败")
|
||||
@@ -256,11 +211,6 @@ func (r *PureFtpdController) GetPort(ctx http.Context) http.Response {
|
||||
|
||||
// SetPort 设置端口
|
||||
func (r *PureFtpdController) SetPort(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "pureftpd")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"port": "required",
|
||||
})
|
||||
|
||||
@@ -18,11 +18,6 @@ func NewRedisController() *RedisController {
|
||||
|
||||
// Status 获取运行状态
|
||||
func (r *RedisController) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "redis")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("redis")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取Redis状态失败")
|
||||
@@ -33,11 +28,6 @@ func (r *RedisController) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启服务
|
||||
func (r *RedisController) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "redis")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart("redis"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启Redis失败")
|
||||
}
|
||||
@@ -47,11 +37,6 @@ func (r *RedisController) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动服务
|
||||
func (r *RedisController) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "redis")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart("redis"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动Redis失败")
|
||||
}
|
||||
@@ -61,11 +46,6 @@ func (r *RedisController) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止服务
|
||||
func (r *RedisController) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "redis")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop("redis"); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止Redis失败")
|
||||
}
|
||||
@@ -75,11 +55,6 @@ func (r *RedisController) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (r *RedisController) GetConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "redis")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
config, err := tools.Read("/www/server/redis/redis.conf")
|
||||
if err != nil {
|
||||
@@ -91,11 +66,6 @@ func (r *RedisController) GetConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveConfig 保存配置
|
||||
func (r *RedisController) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "redis")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
if len(config) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "配置不能为空")
|
||||
@@ -110,11 +80,6 @@ func (r *RedisController) SaveConfig(ctx http.Context) http.Response {
|
||||
|
||||
// Load 获取负载
|
||||
func (r *RedisController) Load(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "redis")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus("redis")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取Redis状态失败")
|
||||
|
||||
@@ -25,11 +25,6 @@ func NewS3fsController() *S3fsController {
|
||||
|
||||
// List 所有 S3fs 挂载
|
||||
func (r *S3fsController) List(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "s3fs")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
page := ctx.Request().QueryInt("page", 1)
|
||||
limit := ctx.Request().QueryInt("limit", 10)
|
||||
|
||||
@@ -63,11 +58,6 @@ func (r *S3fsController) List(ctx http.Context) http.Response {
|
||||
|
||||
// Add 添加 S3fs 挂载
|
||||
func (r *S3fsController) Add(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "s3fs")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"ak": "required|regex:^[a-zA-Z0-9]*$",
|
||||
"sk": "required|regex:^[a-zA-Z0-9]*$",
|
||||
@@ -153,11 +143,6 @@ func (r *S3fsController) Add(ctx http.Context) http.Response {
|
||||
|
||||
// Delete 删除 S3fs 挂载
|
||||
func (r *S3fsController) Delete(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "s3fs")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
id := ctx.Request().Input("id")
|
||||
if len(id) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "挂载ID不能为空")
|
||||
|
||||
@@ -29,11 +29,6 @@ func NewSupervisorController() *SupervisorController {
|
||||
|
||||
// Status 状态
|
||||
func (r *SupervisorController) Status(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
status, err := tools.ServiceStatus(r.ServiceName)
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "获取Supervisor状态失败")
|
||||
@@ -44,11 +39,6 @@ func (r *SupervisorController) Status(ctx http.Context) http.Response {
|
||||
|
||||
// Start 启动
|
||||
func (r *SupervisorController) Start(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStart(r.ServiceName); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "启动Supervisor失败")
|
||||
}
|
||||
@@ -58,11 +48,6 @@ func (r *SupervisorController) Start(ctx http.Context) http.Response {
|
||||
|
||||
// Stop 停止
|
||||
func (r *SupervisorController) Stop(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceStop(r.ServiceName); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "停止Supervisor失败")
|
||||
}
|
||||
@@ -72,11 +57,6 @@ func (r *SupervisorController) Stop(ctx http.Context) http.Response {
|
||||
|
||||
// Restart 重启
|
||||
func (r *SupervisorController) Restart(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceRestart(r.ServiceName); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重启Supervisor失败")
|
||||
}
|
||||
@@ -86,11 +66,6 @@ func (r *SupervisorController) Restart(ctx http.Context) http.Response {
|
||||
|
||||
// Reload 重载
|
||||
func (r *SupervisorController) Reload(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if err := tools.ServiceReload(r.ServiceName); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, "重载Supervisor失败")
|
||||
}
|
||||
@@ -100,11 +75,6 @@ func (r *SupervisorController) Reload(ctx http.Context) http.Response {
|
||||
|
||||
// Log 日志
|
||||
func (r *SupervisorController) Log(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
log, err := tools.Exec(`tail -n 200 /var/log/supervisor/supervisord.log`)
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, log)
|
||||
@@ -115,11 +85,6 @@ func (r *SupervisorController) Log(ctx http.Context) http.Response {
|
||||
|
||||
// ClearLog 清空日志
|
||||
func (r *SupervisorController) ClearLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
if out, err := tools.Exec(`echo "" > /var/log/supervisor/supervisord.log`); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
}
|
||||
@@ -129,11 +94,6 @@ func (r *SupervisorController) ClearLog(ctx http.Context) http.Response {
|
||||
|
||||
// Config 获取配置
|
||||
func (r *SupervisorController) Config(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var config string
|
||||
var err error
|
||||
if tools.IsRHEL() {
|
||||
@@ -151,11 +111,6 @@ func (r *SupervisorController) Config(ctx http.Context) http.Response {
|
||||
|
||||
// SaveConfig 保存配置
|
||||
func (r *SupervisorController) SaveConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
config := ctx.Request().Input("config")
|
||||
var err error
|
||||
if tools.IsRHEL() {
|
||||
@@ -173,11 +128,6 @@ func (r *SupervisorController) SaveConfig(ctx http.Context) http.Response {
|
||||
|
||||
// Processes 进程列表
|
||||
func (r *SupervisorController) Processes(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
page := ctx.Request().QueryInt("page", 1)
|
||||
limit := ctx.Request().QueryInt("limit", 10)
|
||||
|
||||
@@ -240,11 +190,6 @@ func (r *SupervisorController) Processes(ctx http.Context) http.Response {
|
||||
|
||||
// StartProcess 启动进程
|
||||
func (r *SupervisorController) StartProcess(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Input("process")
|
||||
if out, err := tools.Exec(`supervisorctl start ` + process); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
@@ -255,11 +200,6 @@ func (r *SupervisorController) StartProcess(ctx http.Context) http.Response {
|
||||
|
||||
// StopProcess 停止进程
|
||||
func (r *SupervisorController) StopProcess(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Input("process")
|
||||
if out, err := tools.Exec(`supervisorctl stop ` + process); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
@@ -270,11 +210,6 @@ func (r *SupervisorController) StopProcess(ctx http.Context) http.Response {
|
||||
|
||||
// RestartProcess 重启进程
|
||||
func (r *SupervisorController) RestartProcess(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Input("process")
|
||||
if out, err := tools.Exec(`supervisorctl restart ` + process); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
@@ -285,11 +220,6 @@ func (r *SupervisorController) RestartProcess(ctx http.Context) http.Response {
|
||||
|
||||
// ProcessLog 进程日志
|
||||
func (r *SupervisorController) ProcessLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Input("process")
|
||||
var logPath string
|
||||
var err error
|
||||
@@ -313,11 +243,6 @@ func (r *SupervisorController) ProcessLog(ctx http.Context) http.Response {
|
||||
|
||||
// ClearProcessLog 清空进程日志
|
||||
func (r *SupervisorController) ClearProcessLog(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Input("process")
|
||||
var logPath string
|
||||
var err error
|
||||
@@ -340,11 +265,6 @@ func (r *SupervisorController) ClearProcessLog(ctx http.Context) http.Response {
|
||||
|
||||
// ProcessConfig 获取进程配置
|
||||
func (r *SupervisorController) ProcessConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Query("process")
|
||||
var config string
|
||||
var err error
|
||||
@@ -363,11 +283,6 @@ func (r *SupervisorController) ProcessConfig(ctx http.Context) http.Response {
|
||||
|
||||
// SaveProcessConfig 保存进程配置
|
||||
func (r *SupervisorController) SaveProcessConfig(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Input("process")
|
||||
config := ctx.Request().Input("config")
|
||||
var err error
|
||||
@@ -396,11 +311,6 @@ func (r *SupervisorController) SaveProcessConfig(ctx http.Context) http.Response
|
||||
|
||||
// AddProcess 添加进程
|
||||
func (r *SupervisorController) AddProcess(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
validator, err := ctx.Request().Validate(map[string]string{
|
||||
"name": "required|alpha_dash",
|
||||
"user": "required|alpha_dash",
|
||||
@@ -457,11 +367,6 @@ stdout_logfile_maxbytes=2MB
|
||||
|
||||
// DeleteProcess 删除进程
|
||||
func (r *SupervisorController) DeleteProcess(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "supervisor")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
process := ctx.Request().Input("process")
|
||||
if out, err := tools.Exec(`supervisorctl stop ` + process); err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, out)
|
||||
|
||||
@@ -20,11 +20,6 @@ func NewToolBoxController() *ToolBoxController {
|
||||
|
||||
// GetDNS 获取 DNS 信息
|
||||
func (r *ToolBoxController) GetDNS(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
raw, err := tools.Read("/etc/resolv.conf")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -44,11 +39,6 @@ func (r *ToolBoxController) GetDNS(ctx http.Context) http.Response {
|
||||
|
||||
// SetDNS 设置 DNS 信息
|
||||
func (r *ToolBoxController) SetDNS(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
dns1 := ctx.Request().Input("dns1")
|
||||
dns2 := ctx.Request().Input("dns2")
|
||||
|
||||
@@ -69,11 +59,6 @@ func (r *ToolBoxController) SetDNS(ctx http.Context) http.Response {
|
||||
|
||||
// GetSWAP 获取 SWAP 信息
|
||||
func (r *ToolBoxController) GetSWAP(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var total, used, free string
|
||||
var size int64
|
||||
if tools.Exists("/www/swap") {
|
||||
@@ -110,11 +95,6 @@ func (r *ToolBoxController) GetSWAP(ctx http.Context) http.Response {
|
||||
|
||||
// SetSWAP 设置 SWAP 信息
|
||||
func (r *ToolBoxController) SetSWAP(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
size := ctx.Request().InputInt("size")
|
||||
|
||||
if tools.Exists("/www/swap") {
|
||||
@@ -167,11 +147,6 @@ func (r *ToolBoxController) SetSWAP(ctx http.Context) http.Response {
|
||||
|
||||
// GetTimezone 获取时区
|
||||
func (r *ToolBoxController) GetTimezone(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
raw, err := tools.Exec("timedatectl | grep zone")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "获取时区信息失败")
|
||||
@@ -209,11 +184,6 @@ func (r *ToolBoxController) GetTimezone(ctx http.Context) http.Response {
|
||||
|
||||
// SetTimezone 设置时区
|
||||
func (r *ToolBoxController) SetTimezone(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
timezone := ctx.Request().Input("timezone")
|
||||
if len(timezone) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "时区不能为空")
|
||||
@@ -228,11 +198,6 @@ func (r *ToolBoxController) SetTimezone(ctx http.Context) http.Response {
|
||||
|
||||
// GetHosts 获取 hosts 信息
|
||||
func (r *ToolBoxController) GetHosts(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
hosts, err := tools.Read("/etc/hosts")
|
||||
if err != nil {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, err.Error())
|
||||
@@ -243,11 +208,6 @@ func (r *ToolBoxController) GetHosts(ctx http.Context) http.Response {
|
||||
|
||||
// SetHosts 设置 hosts 信息
|
||||
func (r *ToolBoxController) SetHosts(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
hosts := ctx.Request().Input("hosts")
|
||||
if len(hosts) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "hosts 信息不能为空")
|
||||
@@ -262,11 +222,6 @@ func (r *ToolBoxController) SetHosts(ctx http.Context) http.Response {
|
||||
|
||||
// SetRootPassword 设置 root 密码
|
||||
func (r *ToolBoxController) SetRootPassword(ctx http.Context) http.Response {
|
||||
check := controllers.Check(ctx, "toolbox")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
password := ctx.Request().Input("password")
|
||||
if len(password) == 0 {
|
||||
return controllers.Error(ctx, http.StatusUnprocessableEntity, "密码不能为空")
|
||||
|
||||
@@ -73,10 +73,6 @@ func (r *WebsiteController) List(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/websites [post]
|
||||
func (r *WebsiteController) Add(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
var addRequest requests.Add
|
||||
sanitize := Sanitize(ctx, &addRequest)
|
||||
if sanitize != nil {
|
||||
@@ -125,11 +121,6 @@ func (r *WebsiteController) Add(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/websites/{id} [delete]
|
||||
func (r *WebsiteController) Delete(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var idRequest requests.ID
|
||||
sanitize := Sanitize(ctx, &idRequest)
|
||||
if sanitize != nil {
|
||||
@@ -158,10 +149,6 @@ func (r *WebsiteController) Delete(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse{data=map[string]string}
|
||||
// @Router /panel/website/defaultConfig [get]
|
||||
func (r *WebsiteController) GetDefaultConfig(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
index, err := tools.Read("/www/server/openresty/html/index.html")
|
||||
if err != nil {
|
||||
return Error(ctx, http.StatusInternalServerError, err.Error())
|
||||
@@ -189,10 +176,6 @@ func (r *WebsiteController) GetDefaultConfig(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/website/defaultConfig [post]
|
||||
func (r *WebsiteController) SaveDefaultConfig(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
index := ctx.Request().Input("index")
|
||||
stop := ctx.Request().Input("stop")
|
||||
|
||||
@@ -225,11 +208,6 @@ func (r *WebsiteController) SaveDefaultConfig(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse{data=services.PanelWebsite}
|
||||
// @Router /panel/websites/{id}/config [get]
|
||||
func (r *WebsiteController) GetConfig(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var idRequest requests.ID
|
||||
sanitize := Sanitize(ctx, &idRequest)
|
||||
if sanitize != nil {
|
||||
@@ -261,11 +239,6 @@ func (r *WebsiteController) GetConfig(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/websites/{id}/config [post]
|
||||
func (r *WebsiteController) SaveConfig(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var saveConfigRequest requests.SaveConfig
|
||||
sanitize := Sanitize(ctx, &saveConfigRequest)
|
||||
if sanitize != nil {
|
||||
@@ -292,11 +265,6 @@ func (r *WebsiteController) SaveConfig(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/websites/{id}/log [delete]
|
||||
func (r *WebsiteController) ClearLog(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var idRequest requests.ID
|
||||
sanitize := Sanitize(ctx, &idRequest)
|
||||
if sanitize != nil {
|
||||
@@ -526,11 +494,6 @@ func (r *WebsiteController) DeleteBackup(ctx http.Context) http.Response {
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/websites/{id}/resetConfig [post]
|
||||
func (r *WebsiteController) ResetConfig(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var idRequest requests.ID
|
||||
sanitize := Sanitize(ctx, &idRequest)
|
||||
if sanitize != nil {
|
||||
@@ -635,11 +598,6 @@ server
|
||||
// @Success 200 {object} SuccessResponse
|
||||
// @Router /panel/websites/{id}/status [post]
|
||||
func (r *WebsiteController) Status(ctx http.Context) http.Response {
|
||||
check := Check(ctx, "openresty")
|
||||
if check != nil {
|
||||
return check
|
||||
}
|
||||
|
||||
var idRequest requests.ID
|
||||
sanitize := Sanitize(ctx, &idRequest)
|
||||
if sanitize != nil {
|
||||
|
||||
87
app/http/middleware/must_install.go
Normal file
87
app/http/middleware/must_install.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/goravel/framework/contracts/http"
|
||||
|
||||
"panel/app/services"
|
||||
)
|
||||
|
||||
// MustInstall 确保已安装插件
|
||||
func MustInstall() http.Middleware {
|
||||
return func(ctx http.Context) {
|
||||
path := ctx.Request().Path()
|
||||
var slug string
|
||||
if strings.HasPrefix(path, "/api/panel/website") {
|
||||
slug = "openresty"
|
||||
} else {
|
||||
pathArr := strings.Split(path, "/")
|
||||
if len(pathArr) < 4 {
|
||||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
|
||||
"code": http.StatusForbidden,
|
||||
"message": "插件不存在",
|
||||
})
|
||||
return
|
||||
}
|
||||
slug = pathArr[3]
|
||||
}
|
||||
|
||||
plugin := services.NewPluginImpl().GetBySlug(slug)
|
||||
installedPlugin := services.NewPluginImpl().GetInstalledBySlug(slug)
|
||||
installedPlugins, err := services.NewPluginImpl().AllInstalled()
|
||||
if err != nil {
|
||||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
|
||||
"code": http.StatusInternalServerError,
|
||||
"message": "系统内部错误",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if installedPlugin.Version != plugin.Version || installedPlugin.Slug != plugin.Slug {
|
||||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
|
||||
"code": http.StatusForbidden,
|
||||
"message": "插件 " + slug + " 需要更新至 " + plugin.Version + " 版本",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var lock sync.RWMutex
|
||||
pluginsMap := make(map[string]bool)
|
||||
|
||||
for _, p := range installedPlugins {
|
||||
lock.Lock()
|
||||
pluginsMap[p.Slug] = true
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
for _, require := range plugin.Requires {
|
||||
lock.RLock()
|
||||
_, requireFound := pluginsMap[require]
|
||||
lock.RUnlock()
|
||||
if !requireFound {
|
||||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
|
||||
"code": http.StatusForbidden,
|
||||
"message": "插件 " + slug + " 需要依赖 " + require + " 插件",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, exclude := range plugin.Excludes {
|
||||
lock.RLock()
|
||||
_, excludeFound := pluginsMap[exclude]
|
||||
lock.RUnlock()
|
||||
if excludeFound {
|
||||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{
|
||||
"code": http.StatusForbidden,
|
||||
"message": "插件 " + slug + " 不兼容 " + exclude + " 插件",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Request().Next()
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func Api() {
|
||||
r.Get("log", taskController.Log)
|
||||
r.Post("delete", taskController.Delete)
|
||||
})
|
||||
r.Prefix("website").Middleware(middleware.Jwt()).Group(func(r route.Router) {
|
||||
r.Prefix("website").Middleware(middleware.Jwt(), middleware.MustInstall()).Group(func(r route.Router) {
|
||||
websiteController := controllers.NewWebsiteController()
|
||||
r.Get("defaultConfig", websiteController.GetDefaultConfig)
|
||||
r.Post("defaultConfig", websiteController.SaveDefaultConfig)
|
||||
@@ -43,7 +43,7 @@ func Api() {
|
||||
r.Post("uploadBackup", websiteController.UploadBackup)
|
||||
r.Post("deleteBackup", websiteController.DeleteBackup)
|
||||
})
|
||||
r.Prefix("websites").Middleware(middleware.Jwt()).Group(func(r route.Router) {
|
||||
r.Prefix("websites").Middleware(middleware.Jwt(), middleware.MustInstall()).Group(func(r route.Router) {
|
||||
websiteController := controllers.NewWebsiteController()
|
||||
r.Get("/", websiteController.List)
|
||||
r.Post("/", websiteController.Add)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Plugin 加载插件路由
|
||||
func Plugin() {
|
||||
facades.Route().Prefix("api/plugins").Middleware(middleware.Jwt()).Group(func(r route.Router) {
|
||||
facades.Route().Prefix("api/plugins").Middleware(middleware.Jwt(), middleware.MustInstall()).Group(func(r route.Router) {
|
||||
r.Prefix("openresty").Group(func(route route.Router) {
|
||||
openRestyController := plugins.NewOpenrestyController()
|
||||
route.Get("status", openRestyController.Status)
|
||||
|
||||
Reference in New Issue
Block a user