feat: v2.0 全面升级 - SSH密钥管理/模板中心/文件分发/全新UI
- 新增SSH密钥库管理(集中托管私钥、自动指纹识别) - 新增模板中心(24个预置模板,7大分类,一键创建Playbook) - 新增文件分发功能(内容/文件双模式,权限设置) - 新增系统信息接口(版本/主机数/运行时间) - 主机支持密码/SSH密钥双认证方式 - 全新暗色玻璃拟态UI(侧边栏导航、SSE实时日志流) - 修复UpdateHost ID丢失bug - 添加.gitignore排除敏感数据
This commit is contained in:
+20
-12
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
var (
|
||||
configPath string
|
||||
port string
|
||||
port string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -23,23 +23,17 @@ func init() {
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
// 加载配置
|
||||
cfg, err := services.LoadConfig(configPath)
|
||||
if err != nil {
|
||||
log.Printf("配置加载失败: %v,使用默认配置", err)
|
||||
cfg = services.DefaultConfig()
|
||||
}
|
||||
|
||||
// 初始化Ansible服务
|
||||
ansibleService := services.NewAnsibleService(cfg)
|
||||
|
||||
// 初始化处理器
|
||||
h := handlers.NewAnsibleHandler(ansibleService)
|
||||
|
||||
// 初始化Web服务
|
||||
r := gin.Default()
|
||||
|
||||
// CORS配置
|
||||
r.Use(func(c *gin.Context) {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
@@ -51,11 +45,9 @@ func main() {
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// 静态文件
|
||||
r.Static("/static", "./web/dist")
|
||||
r.Static("/assets", "./web/dist/assets")
|
||||
|
||||
// API路由
|
||||
api := r.Group("/api")
|
||||
{
|
||||
// 主机管理
|
||||
@@ -64,6 +56,7 @@ func main() {
|
||||
api.DELETE("/hosts/:id", h.DeleteHost)
|
||||
api.PUT("/hosts/:id", h.UpdateHost)
|
||||
api.POST("/hosts/test/:id", h.TestConnection)
|
||||
api.GET("/hosts/test/:id", h.TestConnection)
|
||||
|
||||
// 主机组管理
|
||||
api.GET("/groups", h.ListGroups)
|
||||
@@ -80,18 +73,34 @@ func main() {
|
||||
api.POST("/playbooks/execute", h.ExecutePlaybook)
|
||||
api.GET("/playbooks/:name", h.GetPlaybook)
|
||||
|
||||
// Playbook模板
|
||||
api.GET("/templates", h.ListTemplates)
|
||||
api.GET("/templates/categories", h.ListTemplateCategories)
|
||||
api.GET("/templates/:id", h.GetTemplate)
|
||||
api.POST("/templates/deploy", h.CreateFromTemplate)
|
||||
|
||||
// 命令执行
|
||||
api.POST("/command/execute", h.ExecuteCommand)
|
||||
api.POST("/command/batch", h.BatchExecute)
|
||||
|
||||
// 文件分发
|
||||
api.POST("/files/distribute", h.DistributeFile)
|
||||
|
||||
// SSH密钥管理
|
||||
api.GET("/sshkeys", h.ListSSHKeys)
|
||||
api.POST("/sshkeys", h.AddSSHKey)
|
||||
api.DELETE("/sshkeys/:name", h.DeleteSSHKey)
|
||||
|
||||
// 任务执行
|
||||
api.GET("/tasks", h.ListTasks)
|
||||
api.GET("/tasks/:id", h.GetTask)
|
||||
api.GET("/tasks/:id/stream", h.StreamTaskOutput)
|
||||
api.DELETE("/tasks/:id", h.CancelTask)
|
||||
|
||||
// 系统信息
|
||||
api.GET("/system/info", h.GetSystemInfo)
|
||||
}
|
||||
|
||||
// 前端路由 - 禁止缓存确保始终返回最新版本
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
c.Header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
c.Header("Pragma", "no-cache")
|
||||
@@ -99,12 +108,11 @@ func main() {
|
||||
c.File("./web/dist/index.html")
|
||||
})
|
||||
|
||||
// 创建必要目录
|
||||
os.MkdirAll(cfg.InventoryDir, 0755)
|
||||
os.MkdirAll(cfg.PlaybookDir, 0755)
|
||||
os.MkdirAll(cfg.LogDir, 0755)
|
||||
|
||||
log.Printf("Ansible部署工具启动,监听端口: %s", port)
|
||||
log.Printf("🚀 Ansible Deploy v2.0 启动,监听端口: %s", port)
|
||||
if err := r.Run(":" + port); err != nil {
|
||||
log.Fatalf("服务启动失败: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user