Skip to content

Commit

Permalink
refactor: 重构网站管理
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Nov 10, 2023
1 parent fe98a5b commit 46e027b
Show file tree
Hide file tree
Showing 44 changed files with 4,135 additions and 687 deletions.
2 changes: 1 addition & 1 deletion app/console/commands/cert_renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (receiver *CertRenew) Handle(ctx console.Context) error {
facades.Log().Tags("面板", "证书管理").With(map[string]any{
"cert_id": cert.ID,
"error": err.Error(),
}).Errorf("证书续签失败")
}).Infof("证书续签失败")
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/console/commands/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (receiver *Monitoring) Handle(ctx console.Context) error {
Info: info,
})
if err != nil {
facades.Log().Errorf("[面板] 系统监控保存失败: %s", err.Error())
facades.Log().Infof("[面板] 系统监控保存失败: %s", err.Error())
color.Redf("[面板] 系统监控保存失败: %s", err.Error())
return nil
}
Expand All @@ -69,7 +69,7 @@ func (receiver *Monitoring) Handle(ctx console.Context) error {
}
_, err = facades.Orm().Query().Where("created_at < ?", carbon.Now().SubDays(days).ToDateTimeString()).Delete(&models.Monitor{})
if err != nil {
facades.Log().Errorf("[面板] 系统监控删除过期数据失败: %s", err.Error())
facades.Log().Infof("[面板] 系统监控删除过期数据失败: %s", err.Error())
return nil
}

Expand Down
47 changes: 25 additions & 22 deletions app/http/controllers/cert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (r *CertController) Algorithms(ctx http.Context) http.Response {
// @Tags 证书管理
// @Produce json
// @Security BearerToken
// @Param data body commonrequests.Paginate true "分页信息"
// @Success 200 {object} SuccessResponse{data=responses.CertList}
// @Failure 401 {object} ErrorResponse "登录已过期"
// @Failure 500 {object} ErrorResponse "系统内部错误"
Expand All @@ -137,11 +138,11 @@ func (r *CertController) UserList(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("获取ACME用户列表失败")
}).Info("获取ACME用户列表失败")
return ErrorSystem(ctx)
}

return Success(ctx, &responses.UserList{
return Success(ctx, responses.UserList{
Total: total,
Items: users,
})
Expand Down Expand Up @@ -170,7 +171,7 @@ func (r *CertController) UserStore(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("添加ACME用户失败")
}).Info("添加ACME用户失败")
return Error(ctx, http.StatusInternalServerError, err.Error())
}

Expand Down Expand Up @@ -202,7 +203,7 @@ func (r *CertController) UserUpdate(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"userID": updateRequest.ID,
"error": err.Error(),
}).Error("更新ACME用户失败")
}).Info("更新ACME用户失败")
return Error(ctx, http.StatusInternalServerError, err.Error())
}

Expand Down Expand Up @@ -232,7 +233,7 @@ func (r *CertController) UserShow(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"userID": showAndDestroyRequest.ID,
"error": err.Error(),
}).Error("获取ACME用户失败")
}).Info("获取ACME用户失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -263,7 +264,7 @@ func (r *CertController) UserDestroy(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"userID": showAndDestroyRequest.ID,
"error": err.Error(),
}).Error("删除ACME用户失败")
}).Info("删除ACME用户失败")
return Error(ctx, http.StatusInternalServerError, err.Error())
}

Expand All @@ -276,6 +277,7 @@ func (r *CertController) UserDestroy(ctx http.Context) http.Response {
// @Tags 证书管理
// @Produce json
// @Security BearerToken
// @Param data body commonrequests.Paginate true "分页信息"
// @Success 200 {object} SuccessResponse{data=responses.DNSList}
// @Failure 401 {object} ErrorResponse "登录已过期"
// @Failure 500 {object} ErrorResponse "系统内部错误"
Expand All @@ -293,11 +295,11 @@ func (r *CertController) DNSList(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("获取DNS接口列表失败")
}).Info("获取DNS接口列表失败")
return ErrorSystem(ctx)
}

return Success(ctx, &responses.DNSList{
return Success(ctx, responses.DNSList{
Total: total,
Items: dns,
})
Expand Down Expand Up @@ -326,7 +328,7 @@ func (r *CertController) DNSStore(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("添加DNS接口失败")
}).Info("添加DNS接口失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -356,7 +358,7 @@ func (r *CertController) DNSShow(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"dnsID": showAndDestroyRequest.ID,
"error": err.Error(),
}).Error("获取DNS接口失败")
}).Info("获取DNS接口失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -388,7 +390,7 @@ func (r *CertController) DNSUpdate(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"dnsID": updateRequest.ID,
"error": err.Error(),
}).Error("更新DNS接口失败")
}).Info("更新DNS接口失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -419,7 +421,7 @@ func (r *CertController) DNSDestroy(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"dnsID": showAndDestroyRequest.ID,
"error": err.Error(),
}).Error("删除DNS接口失败")
}).Info("删除DNS接口失败")
return Error(ctx, http.StatusInternalServerError, err.Error())
}

Expand All @@ -432,6 +434,7 @@ func (r *CertController) DNSDestroy(ctx http.Context) http.Response {
// @Tags 证书管理
// @Produce json
// @Security BearerToken
// @Param data body commonrequests.Paginate true "分页信息"
// @Success 200 {object} SuccessResponse{data=responses.CertList}
// @Failure 401 {object} ErrorResponse "登录已过期"
// @Failure 500 {object} ErrorResponse "系统内部错误"
Expand All @@ -449,11 +452,11 @@ func (r *CertController) CertList(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("获取证书列表失败")
}).Info("获取证书列表失败")
return ErrorSystem(ctx)
}

return Success(ctx, &responses.CertList{
return Success(ctx, responses.CertList{
Total: total,
Items: certs,
})
Expand Down Expand Up @@ -482,7 +485,7 @@ func (r *CertController) CertStore(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("添加证书失败")
}).Info("添加证书失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -514,7 +517,7 @@ func (r *CertController) CertUpdate(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"certID": updateRequest.ID,
"error": err.Error(),
}).Error("更新证书失败")
}).Info("更新证书失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -544,7 +547,7 @@ func (r *CertController) CertShow(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"certID": showAndDestroyRequest.ID,
"error": err.Error(),
}).Error("获取证书失败")
}).Info("获取证书失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -575,7 +578,7 @@ func (r *CertController) CertDestroy(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"certID": showAndDestroyRequest.ID,
"error": err.Error(),
}).Error("删除证书失败")
}).Info("删除证书失败")
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -606,7 +609,7 @@ func (r *CertController) Obtain(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"certID": obtainRequest.ID,
"error": err.Error(),
}).Error("获取证书失败")
}).Info("获取证书失败")
return ErrorSystem(ctx)
}

Expand All @@ -618,7 +621,7 @@ func (r *CertController) Obtain(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("签发证书失败")
}).Info("签发证书失败")
return Error(ctx, http.StatusInternalServerError, err.Error())
}

Expand Down Expand Up @@ -648,7 +651,7 @@ func (r *CertController) Renew(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("续签证书失败")
}).Info("续签证书失败")
return Error(ctx, http.StatusInternalServerError, err.Error())
}

Expand Down Expand Up @@ -678,7 +681,7 @@ func (r *CertController) ManualDNS(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("获取手动DNS记录失败")
}).Info("获取手动DNS记录失败")
return Error(ctx, http.StatusInternalServerError, err.Error())
}

Expand Down
2 changes: 1 addition & 1 deletion app/http/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Check(ctx http.Context, slug string) http.Response {
installedPlugin := services.NewPluginImpl().GetInstalledBySlug(slug)
installedPlugins, err := services.NewPluginImpl().AllInstalled()
if err != nil {
facades.Log().Error("[面板][插件] 获取已安装插件失败")
facades.Log().Info("[面板][插件] 获取已安装插件失败")
return ErrorSystem(ctx)
}

Expand Down
22 changes: 11 additions & 11 deletions app/http/controllers/cron_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *CronController) List(ctx http.Context) http.Response {
var total int64
err := facades.Orm().Query().Paginate(page, limit, &crons, &total)
if err != nil {
facades.Log().Error("[面板][CronController] 查询计划任务列表失败 ", err)
facades.Log().Info("[面板][CronController] 查询计划任务列表失败 ", err)
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -111,16 +111,16 @@ panel cutoff ${name} ${save} 2>&1
shellDir := "/www/server/cron/"
shellLogDir := "/www/server/cron/logs/"
if !tools.Exists(shellDir) {
facades.Log().Error("[面板][CronController] 计划任务目录不存在")
facades.Log().Info("[面板][CronController] 计划任务目录不存在")
return Error(ctx, http.StatusInternalServerError, "计划任务目录不存在")
}
if !tools.Exists(shellLogDir) {
facades.Log().Error("[面板][CronController] 计划任务日志目录不存在")
facades.Log().Info("[面板][CronController] 计划任务日志目录不存在")
return Error(ctx, http.StatusInternalServerError, "计划任务日志目录不存在")
}
shellFile := strconv.Itoa(int(carbon.Now().Timestamp())) + tools.RandomString(16)
if !tools.Write(shellDir+shellFile+".sh", shell, 0700) {
facades.Log().Error("[面板][CronController] 创建计划任务脚本失败 ", err)
if err = tools.Write(shellDir+shellFile+".sh", shell, 0700); err != nil {
facades.Log().Info("[面板][CronController] 创建计划任务脚本失败 ", err)
return ErrorSystem(ctx)
}
tools.Exec("dos2unix " + shellDir + shellFile + ".sh")
Expand All @@ -135,7 +135,7 @@ panel cutoff ${name} ${save} 2>&1

err = facades.Orm().Query().Create(&cron)
if err != nil {
facades.Log().Error("[面板][CronController] 创建计划任务失败 ", err)
facades.Log().Info("[面板][CronController] 创建计划任务失败 ", err)
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -190,12 +190,12 @@ func (c *CronController) Update(ctx http.Context) http.Response {
cron.Name = ctx.Request().Input("name")
err = facades.Orm().Query().Save(&cron)
if err != nil {
facades.Log().Error("[面板][CronController] 更新计划任务失败 ", err)
facades.Log().Info("[面板][CronController] 更新计划任务失败 ", err)
return ErrorSystem(ctx)
}

if !tools.Write(cron.Shell, ctx.Request().Input("script"), 0644) {
facades.Log().Error("[面板][CronController] 更新计划任务脚本失败 ", err)
if err = tools.Write(cron.Shell, ctx.Request().Input("script"), 0644); err != nil {
facades.Log().Info("[面板][CronController] 更新计划任务脚本失败 ", err)
return ErrorSystem(ctx)
}
tools.Exec("dos2unix " + cron.Shell)
Expand All @@ -221,7 +221,7 @@ func (c *CronController) Delete(ctx http.Context) http.Response {

_, err = facades.Orm().Query().Delete(&cron)
if err != nil {
facades.Log().Error("[面板][CronController] 删除计划任务失败 ", err)
facades.Log().Info("[面板][CronController] 删除计划任务失败 ", err)
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -249,7 +249,7 @@ func (c *CronController) Status(ctx http.Context) http.Response {
cron.Status = ctx.Request().InputBool("status")
err = facades.Orm().Query().Save(&cron)
if err != nil {
facades.Log().Error("[面板][CronController] 更新计划任务状态失败 ", err)
facades.Log().Info("[面板][CronController] 更新计划任务状态失败 ", err)
return ErrorSystem(ctx)
}

Expand Down
12 changes: 6 additions & 6 deletions app/http/controllers/info_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *InfoController) Name(ctx http.Context) http.Response {
var setting models.Setting
err := facades.Orm().Query().Where("key", "name").First(&setting)
if err != nil {
facades.Log().Error("[面板][InfoController] 查询面板名称失败 ", err)
facades.Log().Info("[面板][InfoController] 查询面板名称失败 ", err)
return ErrorSystem(ctx)
}

Expand All @@ -52,7 +52,7 @@ func (c *InfoController) HomePlugins(ctx http.Context) http.Response {
var plugins []models.Plugin
err := facades.Orm().Query().Where("show", 1).Find(&plugins)
if err != nil {
facades.Log().Error("[面板][InfoController] 查询首页插件失败 ", err)
facades.Log().Info("[面板][InfoController] 查询首页插件失败 ", err)
return ErrorSystem(ctx)
}

Expand Down Expand Up @@ -121,15 +121,15 @@ func (c *InfoController) CountInfo(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).With(map[string]any{
"error": err.Error(),
}).Error("[面板][InfoController] 获取数据库列表失败")
}).Info("[面板][InfoController] 获取数据库列表失败")
databaseCount = -1
} else {
defer db.Close()
rows, err := db.Query("SHOW DATABASES")
if err != nil {
facades.Log().Request(ctx.Request()).With(map[string]any{
"error": err.Error(),
}).Error("[面板][InfoController] 获取数据库列表失败")
}).Info("[面板][InfoController] 获取数据库列表失败")
databaseCount = -1
} else {
defer rows.Close()
Expand Down Expand Up @@ -307,15 +307,15 @@ func (c *InfoController) Update(ctx http.Context) http.Response {
if err != nil {
facades.Log().Request(ctx.Request()).With(map[string]any{
"error": err.Error(),
}).Error("[面板][InfoController] 获取最新版本失败")
}).Info("[面板][InfoController] 获取最新版本失败")
return Error(ctx, http.StatusInternalServerError, "获取最新版本失败")
}

err = tools.UpdatePanel(panel)
if err != nil {
facades.Log().Request(ctx.Request()).With(map[string]any{
"error": err.Error(),
}).Error("[面板][InfoController] 更新面板失败")
}).Info("[面板][InfoController] 更新面板失败")
return Error(ctx, http.StatusInternalServerError, "更新失败: "+err.Error())
}

Expand Down
Loading

0 comments on commit 46e027b

Please sign in to comment.