告警中心 - 新增统一告警(alert_unified)、监控告警规则(monitor_alert_rule)、指标目录(alert_metric_catalog) - 通知策略与消息分发(alert_notify_policy/dispatch/message)、静默规则 - 告警引擎按阈值/SNMP 拆分(alert_engine_monitor/snmp) 监控采集 - SNMP 常量/模板与历史指标(snmp templates/constants、snmp_metrics_history、snmp_collect) - 中间件监控 Redis 采集与种子(middleware_monitor_redis/seed) - 站点探测 pkg(siteprobe) + 站点视图(site_view) 自动化任务 - cron 调度器(cronscheduler)、脚本运行器(scriptrunner)、系统任务(systask)及运行记录(cron_job_run、system_task) 审计与凭证 - 审计设置(audit_setting) + 历史清理(auditcleaner) 前端 - 监控页面(host/middleware/site/snmp)拆分为子模块并大屏化 - 告警中心多 Tab(规则/指标目录/通知策略/静默)、任务管理组件重构、Agent CLI Markdown 渲染 - 移除旧脚本卡片/详情/日志组件,统一为 ScriptTable/ScriptCodeEditor/TerminalOutput Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
// 自动化运维写操作权限 — 脚本库 / 定时任务 // Logan.Li
|
|
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"ezops/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// AutomationWrite 创建/修改/删除/执行脚本与定时任务需具备自动化运维权限 // Logan.Li
|
|
func AutomationWrite(db *gorm.DB) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if isAdmin, _ := c.Get("isAdmin"); isAdmin == true {
|
|
c.Next()
|
|
return
|
|
}
|
|
userID, ok := c.Get("userID")
|
|
if !ok {
|
|
c.JSON(http.StatusUnauthorized, model.Response{Code: 401, Message: "未认证"})
|
|
c.Abort()
|
|
return
|
|
}
|
|
codes := collectPermissionCodes(db, userID.(uint))
|
|
for _, code := range codes {
|
|
if code == "*" || strings.HasPrefix(code, "auto:") {
|
|
c.Next()
|
|
return
|
|
}
|
|
}
|
|
c.JSON(http.StatusForbidden, model.Response{
|
|
Code: 403,
|
|
Message: "需要自动化运维权限(auto:script 或 auto:cron),请联系管理员分配角色",
|
|
})
|
|
c.Abort()
|
|
}
|
|
}
|
|
|
|
// collectPermissionCodes 查询用户有效权限码 // Logan.Li
|
|
func collectPermissionCodes(db *gorm.DB, userID uint) []string {
|
|
var rows []struct{ Code string }
|
|
db.Raw(`
|
|
SELECT DISTINCT p.code AS code
|
|
FROM iam_user_roles ur
|
|
JOIN iam_roles r ON r.id = ur.role_id AND r.status = 1
|
|
JOIN role_permissions rp ON rp.role_id = r.id
|
|
JOIN iam_permissions p ON p.id = rp.permission_id AND p.status = 1
|
|
WHERE ur.user_id = ?
|
|
`, userID).Scan(&rows)
|
|
codes := make([]string, 0, len(rows))
|
|
for _, r := range rows {
|
|
if r.Code != "" {
|
|
codes = append(codes, r.Code)
|
|
}
|
|
}
|
|
return codes
|
|
} |