mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 14:57:16 +08:00
feat: 同步前端接口更新
This commit is contained in:
@@ -74,7 +74,7 @@ func (c *CronController) Add(ctx http.Context) http.Response {
|
||||
backupName = ctx.Request().Input("website")
|
||||
}
|
||||
backupPath := ctx.Request().Input("backup_path")
|
||||
if len(backupName) == 0 {
|
||||
if len(backupPath) == 0 {
|
||||
backupPath = c.setting.Get(models.SettingKeyBackupPath) + "/" + backupType
|
||||
}
|
||||
backupSave := ctx.Request().InputInt("save", 10)
|
||||
|
||||
@@ -23,7 +23,7 @@ func NewMonitorController() *MonitorController {
|
||||
|
||||
// Switch 监控开关
|
||||
func (r *MonitorController) Switch(ctx http.Context) http.Response {
|
||||
value := ctx.Request().InputBool("switch")
|
||||
value := ctx.Request().InputBool("monitor")
|
||||
err := r.setting.Set(models.SettingKeyMonitor, cast.ToString(value))
|
||||
if err != nil {
|
||||
facades.Log().Error("[面板][MonitorController] 更新监控开关失败 ", err)
|
||||
|
||||
@@ -132,17 +132,35 @@ func (r *SafeController) AddFirewallRule(ctx http.Context) http.Response {
|
||||
return Error(ctx, http.StatusBadRequest, "防火墙未启动")
|
||||
}
|
||||
|
||||
port := ctx.Request().InputInt("port", 0)
|
||||
protocol := ctx.Request().Input("protocol", "")
|
||||
if port == 0 || protocol == "" {
|
||||
port := ctx.Request().Input("port")
|
||||
protocol := ctx.Request().Input("protocol")
|
||||
if port == "" || protocol == "" || (protocol != "tcp" && protocol != "udp") {
|
||||
return Error(ctx, http.StatusBadRequest, "参数错误")
|
||||
}
|
||||
// 端口有 2 种写法,一种是 80-443,一种是 80
|
||||
if strings.Contains(port, "-") {
|
||||
ports := strings.Split(port, "-")
|
||||
startPort := cast.ToInt(ports[0])
|
||||
endPort := cast.ToInt(ports[1])
|
||||
if startPort < 1 || startPort > 65535 || endPort < 1 || endPort > 65535 || startPort > endPort {
|
||||
return Error(ctx, http.StatusBadRequest, "参数错误")
|
||||
}
|
||||
} else {
|
||||
port := cast.ToInt(port)
|
||||
if port < 1 || port > 65535 {
|
||||
return Error(ctx, http.StatusBadRequest, "参数错误")
|
||||
}
|
||||
}
|
||||
|
||||
if tools.IsRHEL() {
|
||||
tools.Exec("firewall-cmd --remove-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1")
|
||||
tools.Exec("firewall-cmd --add-port=" + cast.ToString(port) + "/" + protocol + " --permanent 2>&1")
|
||||
tools.Exec("firewall-cmd --reload")
|
||||
} else {
|
||||
// ufw 需要替换 - 为 : 添加
|
||||
if strings.Contains(port, "-") {
|
||||
port = strings.ReplaceAll(port, "-", ":")
|
||||
}
|
||||
tools.Exec("ufw delete allow " + cast.ToString(port) + "/" + protocol)
|
||||
tools.Exec("ufw allow " + cast.ToString(port) + "/" + protocol)
|
||||
tools.Exec("ufw reload")
|
||||
|
||||
@@ -28,25 +28,33 @@ func (r *SettingController) List(ctx http.Context) http.Response {
|
||||
return Error(ctx, http.StatusInternalServerError, "系统内部错误")
|
||||
}
|
||||
|
||||
var result = make(map[string]string)
|
||||
for _, setting := range settings {
|
||||
if setting.Key == models.SettingKeyMysqlRootPassword {
|
||||
continue
|
||||
}
|
||||
|
||||
result[setting.Key] = setting.Value
|
||||
type data struct {
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
Port string `json:"port"`
|
||||
Entrance string `json:"entrance"`
|
||||
WebsitePath string `json:"website_path"`
|
||||
BackupPath string `json:"backup_path"`
|
||||
}
|
||||
|
||||
var result data
|
||||
result.Name = r.setting.Get(models.SettingKeyName)
|
||||
result.Entrance = r.setting.Get(models.SettingKeyEntrance)
|
||||
result.WebsitePath = r.setting.Get(models.SettingKeyWebsitePath)
|
||||
result.BackupPath = r.setting.Get(models.SettingKeyBackupPath)
|
||||
|
||||
var user models.User
|
||||
err = facades.Auth().User(ctx, &user)
|
||||
if err != nil {
|
||||
facades.Log().Error("[面板][SettingController] 获取用户失败 ", err)
|
||||
return Error(ctx, http.StatusInternalServerError, "系统内部错误")
|
||||
}
|
||||
result["username"] = user.Username
|
||||
result["email"] = user.Email
|
||||
result.Username = user.Username
|
||||
result.Email = user.Email
|
||||
|
||||
result["port"] = tools.Exec(`cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}' | tr -d '\n'`)
|
||||
result.Port = tools.Exec(`cat /www/panel/panel.conf | grep APP_PORT | awk -F '=' '{print $2}' | tr -d '\n'`)
|
||||
|
||||
return Success(ctx, result)
|
||||
}
|
||||
|
||||
@@ -61,12 +61,18 @@ func (r *UserController) Login(ctx http.Context) http.Response {
|
||||
|
||||
// Info 用户信息
|
||||
func (r *UserController) Info(ctx http.Context) http.Response {
|
||||
user, ok := ctx.Value("user").(models.User)
|
||||
if !ok {
|
||||
return Error(ctx, http.StatusUnauthorized, "登录已过期")
|
||||
var user models.User
|
||||
err := facades.Auth().User(ctx, &user)
|
||||
if err != nil {
|
||||
facades.Log().With(map[string]any{
|
||||
"error": err.Error(),
|
||||
}).Error("[面板][UserController] 查询用户信息失败")
|
||||
return Error(ctx, http.StatusInternalServerError, "系统内部错误")
|
||||
}
|
||||
|
||||
return Success(ctx, http.Json{
|
||||
"id": user.ID,
|
||||
"role": []string{"admin"},
|
||||
"username": user.Username,
|
||||
"email": user.Email,
|
||||
})
|
||||
|
||||
@@ -66,20 +66,20 @@ func Api() {
|
||||
r.Prefix("cron").Middleware(middleware.Jwt()).Group(func(r route.Router) {
|
||||
cronController := controllers.NewCronController()
|
||||
r.Get("list", cronController.List)
|
||||
r.Get("script", cronController.Script)
|
||||
r.Get("{id}", cronController.Script)
|
||||
r.Post("add", cronController.Add)
|
||||
r.Post("update", cronController.Update)
|
||||
r.Post("delete", cronController.Delete)
|
||||
r.Put("{id}", cronController.Update)
|
||||
r.Delete("{id}", cronController.Delete)
|
||||
r.Post("status", cronController.Status)
|
||||
r.Get("log", cronController.Log)
|
||||
r.Get("log/{id}", cronController.Log)
|
||||
})
|
||||
r.Prefix("safe").Middleware(middleware.Jwt()).Group(func(r route.Router) {
|
||||
safeController := controllers.NewSafeController()
|
||||
r.Get("firewallStatus", safeController.GetFirewallStatus)
|
||||
r.Post("firewallStatus", safeController.SetFirewallStatus)
|
||||
r.Get("firewallRules", safeController.GetFirewallRules)
|
||||
r.Post("addFirewallRule", safeController.AddFirewallRule)
|
||||
r.Post("deleteFirewallRule", safeController.DeleteFirewallRule)
|
||||
r.Post("firewallRules", safeController.AddFirewallRule)
|
||||
r.Delete("firewallRules", safeController.DeleteFirewallRule)
|
||||
r.Get("sshStatus", safeController.GetSshStatus)
|
||||
r.Post("sshStatus", safeController.SetSshStatus)
|
||||
r.Get("sshPort", safeController.GetSshPort)
|
||||
|
||||
Reference in New Issue
Block a user