diff --git a/cmd/apimain.go b/cmd/apimain.go index e8862d9..f78963c 100644 --- a/cmd/apimain.go +++ b/cmd/apimain.go @@ -200,7 +200,7 @@ func getTranslatorForLang(lang string) ut.Translator { } } func DatabaseAutoUpdate() { - version := 233 + version := 235 db := global.DB @@ -263,6 +263,7 @@ func Migrate(version uint) { &model.LoginLog{}, &model.ShareRecord{}, &model.AuditConn{}, + &model.AuditFile{}, ) if err != nil { fmt.Println("migrate err :=>", err) diff --git a/docs/admin/admin_docs.go b/docs/admin/admin_docs.go index 6efbd52..edba631 100644 --- a/docs/admin/admin_docs.go +++ b/docs/admin/admin_docs.go @@ -387,7 +387,7 @@ const docTemplateadmin = `{ "token": [] } ], - "description": "链接日志删除", + "description": "文件日志删除", "consumes": [ "application/json" ], @@ -395,17 +395,17 @@ const docTemplateadmin = `{ "application/json" ], "tags": [ - "链接日志" + "文件日志" ], - "summary": "链接日志删除", + "summary": "文件日志删除", "parameters": [ { - "description": "链接日志信息", + "description": "文件日志信息", "name": "body", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.AuditConn" + "$ref": "#/definitions/model.AuditFile" } } ], @@ -432,7 +432,7 @@ const docTemplateadmin = `{ "token": [] } ], - "description": "链接日志列表", + "description": "文件日志列表", "consumes": [ "application/json" ], @@ -440,9 +440,9 @@ const docTemplateadmin = `{ "application/json" ], "tags": [ - "链接日志" + "文件日志" ], - "summary": "链接日志列表", + "summary": "文件日志列表", "parameters": [ { "type": "integer", @@ -481,7 +481,7 @@ const docTemplateadmin = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/model.AuditConnList" + "$ref": "#/definitions/model.AuditFileList" } } } @@ -2566,6 +2566,9 @@ const docTemplateadmin = `{ }, "name": { "type": "string" + }, + "type": { + "type": "integer" } } }, @@ -2925,6 +2928,70 @@ const docTemplateadmin = `{ } } }, + "model.AuditFile": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "from_name": { + "type": "string" + }, + "from_peer": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "info": { + "type": "string" + }, + "ip": { + "type": "string" + }, + "is_file": { + "type": "boolean" + }, + "num": { + "type": "integer" + }, + "path": { + "type": "string" + }, + "peer_id": { + "type": "string" + }, + "type": { + "type": "integer" + }, + "updated_at": { + "type": "string" + }, + "uuid": { + "type": "string" + } + } + }, + "model.AuditFileList": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.AuditFile" + } + }, + "page": { + "type": "integer" + }, + "page_size": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, "model.Group": { "type": "object", "properties": { diff --git a/docs/admin/admin_swagger.json b/docs/admin/admin_swagger.json index 6eeb3f3..5b42d2a 100644 --- a/docs/admin/admin_swagger.json +++ b/docs/admin/admin_swagger.json @@ -380,7 +380,7 @@ "token": [] } ], - "description": "链接日志删除", + "description": "文件日志删除", "consumes": [ "application/json" ], @@ -388,17 +388,17 @@ "application/json" ], "tags": [ - "链接日志" + "文件日志" ], - "summary": "链接日志删除", + "summary": "文件日志删除", "parameters": [ { - "description": "链接日志信息", + "description": "文件日志信息", "name": "body", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.AuditConn" + "$ref": "#/definitions/model.AuditFile" } } ], @@ -425,7 +425,7 @@ "token": [] } ], - "description": "链接日志列表", + "description": "文件日志列表", "consumes": [ "application/json" ], @@ -433,9 +433,9 @@ "application/json" ], "tags": [ - "链接日志" + "文件日志" ], - "summary": "链接日志列表", + "summary": "文件日志列表", "parameters": [ { "type": "integer", @@ -474,7 +474,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/model.AuditConnList" + "$ref": "#/definitions/model.AuditFileList" } } } @@ -2559,6 +2559,9 @@ }, "name": { "type": "string" + }, + "type": { + "type": "integer" } } }, @@ -2918,6 +2921,70 @@ } } }, + "model.AuditFile": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "from_name": { + "type": "string" + }, + "from_peer": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "info": { + "type": "string" + }, + "ip": { + "type": "string" + }, + "is_file": { + "type": "boolean" + }, + "num": { + "type": "integer" + }, + "path": { + "type": "string" + }, + "peer_id": { + "type": "string" + }, + "type": { + "type": "integer" + }, + "updated_at": { + "type": "string" + }, + "uuid": { + "type": "string" + } + } + }, + "model.AuditFileList": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.AuditFile" + } + }, + "page": { + "type": "integer" + }, + "page_size": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, "model.Group": { "type": "object", "properties": { diff --git a/docs/admin/admin_swagger.yaml b/docs/admin/admin_swagger.yaml index ccbcdff..980891a 100644 --- a/docs/admin/admin_swagger.yaml +++ b/docs/admin/admin_swagger.yaml @@ -75,6 +75,8 @@ definitions: type: integer name: type: string + type: + type: integer required: - name type: object @@ -315,6 +317,48 @@ definitions: total: type: integer type: object + model.AuditFile: + properties: + created_at: + type: string + from_name: + type: string + from_peer: + type: string + id: + type: integer + info: + type: string + ip: + type: string + is_file: + type: boolean + num: + type: integer + path: + type: string + peer_id: + type: string + type: + type: integer + updated_at: + type: string + uuid: + type: string + type: object + model.AuditFileList: + properties: + list: + items: + $ref: '#/definitions/model.AuditFile' + type: array + page: + type: integer + page_size: + type: integer + total: + type: integer + type: object model.Group: properties: created_at: @@ -765,14 +809,14 @@ paths: post: consumes: - application/json - description: 链接日志删除 + description: 文件日志删除 parameters: - - description: 链接日志信息 + - description: 文件日志信息 in: body name: body required: true schema: - $ref: '#/definitions/model.AuditConn' + $ref: '#/definitions/model.AuditFile' produces: - application/json responses: @@ -786,14 +830,14 @@ paths: $ref: '#/definitions/response.Response' security: - token: [] - summary: 链接日志删除 + summary: 文件日志删除 tags: - - 链接日志 + - 文件日志 /admin/audit_conn/list: get: consumes: - application/json - description: 链接日志列表 + description: 文件日志列表 parameters: - description: 页码 in: query @@ -821,7 +865,7 @@ paths: - $ref: '#/definitions/response.Response' - properties: data: - $ref: '#/definitions/model.AuditConnList' + $ref: '#/definitions/model.AuditFileList' type: object "500": description: Internal Server Error @@ -829,9 +873,9 @@ paths: $ref: '#/definitions/response.Response' security: - token: [] - summary: 链接日志列表 + summary: 文件日志列表 tags: - - 链接日志 + - 文件日志 /admin/file/oss_token: get: consumes: diff --git a/docs/api/api_docs.go b/docs/api/api_docs.go index 18b5264..81a342e 100644 --- a/docs/api/api_docs.go +++ b/docs/api/api_docs.go @@ -727,6 +727,46 @@ const docTemplateapi = `{ } } }, + "/audit/file": { + "post": { + "description": "审计文件", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "审计" + ], + "summary": "审计文件", + "parameters": [ + { + "description": "审计文件", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/api.AuditFileForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/heartbeat": { "post": { "description": "心跳", @@ -1259,6 +1299,32 @@ const docTemplateapi = `{ } } }, + "api.AuditFileForm": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "info": { + "type": "string" + }, + "is_file": { + "type": "boolean" + }, + "path": { + "type": "string" + }, + "peer_id": { + "type": "string" + }, + "type": { + "type": "integer" + }, + "uuid": { + "type": "string" + } + } + }, "api.DeviceInfoInLogin": { "type": "object", "properties": { diff --git a/docs/api/api_swagger.json b/docs/api/api_swagger.json index 3c8d4e0..ed95d19 100644 --- a/docs/api/api_swagger.json +++ b/docs/api/api_swagger.json @@ -720,6 +720,46 @@ } } }, + "/audit/file": { + "post": { + "description": "审计文件", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "审计" + ], + "summary": "审计文件", + "parameters": [ + { + "description": "审计文件", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/api.AuditFileForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/heartbeat": { "post": { "description": "心跳", @@ -1252,6 +1292,32 @@ } } }, + "api.AuditFileForm": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "info": { + "type": "string" + }, + "is_file": { + "type": "boolean" + }, + "path": { + "type": "string" + }, + "peer_id": { + "type": "string" + }, + "type": { + "type": "integer" + }, + "uuid": { + "type": "string" + } + } + }, "api.DeviceInfoInLogin": { "type": "object", "properties": { diff --git a/docs/api/api_swagger.yaml b/docs/api/api_swagger.yaml index ea10ac0..2e5e949 100644 --- a/docs/api/api_swagger.yaml +++ b/docs/api/api_swagger.yaml @@ -27,6 +27,23 @@ definitions: uuid: type: string type: object + api.AuditFileForm: + properties: + id: + type: string + info: + type: string + is_file: + type: boolean + path: + type: string + peer_id: + type: string + type: + type: integer + uuid: + type: string + type: object api.DeviceInfoInLogin: properties: name: @@ -609,6 +626,32 @@ paths: summary: 审计连接 tags: - 审计 + /audit/file: + post: + consumes: + - application/json + description: 审计文件 + parameters: + - description: 审计文件 + in: body + name: body + required: true + schema: + $ref: '#/definitions/api.AuditFileForm' + produces: + - application/json + responses: + "200": + description: OK + schema: + type: string + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + summary: 审计文件 + tags: + - 审计 /heartbeat: post: consumes: diff --git a/http/controller/admin/audit.go b/http/controller/admin/audit.go index 8714b64..b771cea 100644 --- a/http/controller/admin/audit.go +++ b/http/controller/admin/audit.go @@ -67,7 +67,7 @@ func (a *Audit) ConnDelete(c *gin.Context) { response.Fail(c, 101, errList[0]) return } - l := service.AllService.AuditService.InfoById(f.Id) + l := service.AllService.AuditService.ConnInfoById(f.Id) if l.Id > 0 { err := service.AllService.AuditService.DeleteAuditConn(l) if err == nil { @@ -79,3 +79,70 @@ func (a *Audit) ConnDelete(c *gin.Context) { } response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) } + +// FileList 列表 +// @Tags 文件日志 +// @Summary 文件日志列表 +// @Description 文件日志列表 +// @Accept json +// @Produce json +// @Param page query int false "页码" +// @Param page_size query int false "页大小" +// @Param peer_id query int false "目标设备" +// @Param from_peer query int false "来源设备" +// @Success 200 {object} response.Response{data=model.AuditFileList} +// @Failure 500 {object} response.Response +// @Router /admin/audit_conn/list [get] +// @Security token +func (a *Audit) FileList(c *gin.Context) { + query := &admin.AuditQuery{} + if err := c.ShouldBindQuery(query); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + res := service.AllService.AuditService.AuditFileList(query.Page, query.PageSize, func(tx *gorm.DB) { + if query.PeerId != "" { + tx.Where("peer_id like ?", "%"+query.PeerId+"%") + } + if query.FromPeer != "" { + tx.Where("from_peer like ?", "%"+query.FromPeer+"%") + } + }) + response.Success(c, res) +} + +// FileDelete 删除 +// @Tags 文件日志 +// @Summary 文件日志删除 +// @Description 文件日志删除 +// @Accept json +// @Produce json +// @Param body body model.AuditFile true "文件日志信息" +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /admin/audit_conn/delete [post] +// @Security token +func (a *Audit) FileDelete(c *gin.Context) { + f := &model.AuditFile{} + if err := c.ShouldBindJSON(f); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + id := f.Id + errList := global.Validator.ValidVar(c, id, "required,gt=0") + if len(errList) > 0 { + response.Fail(c, 101, errList[0]) + return + } + l := service.AllService.AuditService.FileInfoById(f.Id) + if l.Id > 0 { + err := service.AllService.AuditService.DeleteAuditFile(l) + if err == nil { + response.Success(c, nil) + return + } + response.Fail(c, 101, err.Error()) + return + } + response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) +} diff --git a/http/controller/api/audit.go b/http/controller/api/audit.go index cf89057..0a3c05c 100644 --- a/http/controller/api/audit.go +++ b/http/controller/api/audit.go @@ -30,7 +30,9 @@ func (a *Audit) AuditConn(c *gin.Context) { response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error()) return } - //fmt.Println(af) + /*ttt := &gin.H{} + c.ShouldBindBodyWith(ttt, binding.JSON) + fmt.Println(ttt)*/ ac := af.ToAuditConn() if af.Action == model.AuditActionNew { service.AllService.AuditService.CreateAuditConn(ac) @@ -48,9 +50,35 @@ func (a *Audit) AuditConn(c *gin.Context) { FromPeer: ac.FromPeer, FromName: ac.FromName, SessionId: ac.SessionId, + Type: ac.Type, } service.AllService.AuditService.UpdateAuditConn(up) } } response.Success(c, "") } + +// AuditFile +// @Tags 审计 +// @Summary 审计文件 +// @Description 审计文件 +// @Accept json +// @Produce json +// @Param body body request.AuditFileForm true "审计文件" +// @Success 200 {string} string "" +// @Failure 500 {object} response.Response +// @Router /audit/file [post] +func (a *Audit) AuditFile(c *gin.Context) { + aff := &request.AuditFileForm{} + err := c.ShouldBindBodyWith(aff, binding.JSON) + if err != nil { + response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + //ttt := &gin.H{} + //c.ShouldBindBodyWith(ttt, binding.JSON) + //fmt.Println(ttt) + af := aff.ToAuditFile() + service.AllService.AuditService.CreateAuditFile(af) + response.Success(c, "") +} diff --git a/http/request/api/audit.go b/http/request/api/audit.go index 99b54a8..242a73e 100644 --- a/http/request/api/audit.go +++ b/http/request/api/audit.go @@ -1,7 +1,9 @@ package api import ( + "Gwen/global" "Gwen/model" + "encoding/json" "strconv" ) @@ -38,3 +40,39 @@ func (a *AuditConnForm) ToAuditConn() *model.AuditConn { Uuid: a.Uuid, } } + +type AuditFileForm struct { + Id string `json:"id"` + Info string `json:"info"` + IsFile bool `json:"is_file"` + Path string `json:"path"` + PeerId string `json:"peer_id"` + Type int `json:"type"` + Uuid string `json:"uuid"` +} +type AuditFileInfo struct { + Ip string `json:"ip"` + Name string `json:"name"` + Num int `json:"num"` +} + +func (a *AuditFileForm) ToAuditFile() *model.AuditFile { + fi := &AuditFileInfo{} + err := json.Unmarshal([]byte(a.Info), fi) + if err != nil { + global.Logger.Warn("ToAuditFile", err) + } + + return &model.AuditFile{ + PeerId: a.Id, + Info: a.Info, + IsFile: a.IsFile, + FromPeer: a.PeerId, + Path: a.Path, + Type: a.Type, + Uuid: a.Uuid, + FromName: fi.Name, + Ip: fi.Ip, + Num: fi.Num, + } +} diff --git a/http/router/admin.go b/http/router/admin.go index 7291f3f..de8718b 100644 --- a/http/router/admin.go +++ b/http/router/admin.go @@ -148,6 +148,9 @@ func AuditBind(rg *gin.RouterGroup) { aR := rg.Group("/audit_conn").Use(middleware.AdminPrivilege()) aR.GET("/list", cont.ConnList) aR.POST("/delete", cont.ConnDelete) + afR := rg.Group("/audit_file").Use(middleware.AdminPrivilege()) + afR.GET("/list", cont.FileList) + afR.POST("/delete", cont.FileDelete) } /* diff --git a/http/router/api.go b/http/router/api.go index a228c46..8593115 100644 --- a/http/router/api.go +++ b/http/router/api.go @@ -53,6 +53,8 @@ func ApiInit(g *gin.Engine) { au := &api.Audit{} //[method:POST] [uri:/api/audit/conn] frg.POST("/audit/conn", au.AuditConn) + //[method:POST] [uri:/api/audit/file] + frg.POST("/audit/file", au.AuditFile) frg.Use(middleware.RustAuth()) { u := &api.User{} diff --git a/model/audit.go b/model/audit.go index 4d18852..609d3b0 100644 --- a/model/audit.go +++ b/model/audit.go @@ -24,3 +24,23 @@ type AuditConnList struct { AuditConns []*AuditConn `json:"list"` Pagination } + +type AuditFile struct { + IdModel + FromPeer string `json:"from_peer" gorm:"default:'';not null;index"` + Info string `json:"info" gorm:"default:'';not null;"` + IsFile bool `json:"is_file" gorm:"default:0;not null;"` + Path string `json:"path" gorm:"default:'';not null;"` + PeerId string `json:"peer_id" gorm:"default:'';not null;index"` + Type int `json:"type" gorm:"default:0;not null;"` + Uuid string `json:"uuid" gorm:"default:'';not null;"` + Ip string `json:"ip" gorm:"default:'';not null;"` + Num int `json:"num" gorm:"default:0;not null;"` + FromName string `json:"from_name" gorm:"default:'';not null;"` + TimeModel +} + +type AuditFileList struct { + AuditFiles []*AuditFile `json:"list"` + Pagination +} diff --git a/service/audit.go b/service/audit.go index b79acc4..2ad718b 100644 --- a/service/audit.go +++ b/service/audit.go @@ -44,9 +44,44 @@ func (as *AuditService) InfoByPeerIdAndConnId(peerId string, connId int64) (res return } -// InfoById -func (as *AuditService) InfoById(id uint) (res *model.AuditConn) { +// ConnInfoById +func (as *AuditService) ConnInfoById(id uint) (res *model.AuditConn) { res = &model.AuditConn{} global.DB.Where("id = ?", id).First(res) return } + +// FileInfoById +func (as *AuditService) FileInfoById(id uint) (res *model.AuditFile) { + res = &model.AuditFile{} + global.DB.Where("id = ?", id).First(res) + return +} + +func (as *AuditService) AuditFileList(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AuditFileList) { + res = &model.AuditFileList{} + res.Page = int64(page) + res.PageSize = int64(pageSize) + tx := global.DB.Model(&model.AuditFile{}) + if where != nil { + where(tx) + } + tx.Count(&res.Total) + tx.Scopes(Paginate(page, pageSize)) + tx.Find(&res.AuditFiles) + return +} + +// CreateAuditFile +func (as *AuditService) CreateAuditFile(u *model.AuditFile) error { + res := global.DB.Create(u).Error + return res +} +func (as *AuditService) DeleteAuditFile(u *model.AuditFile) error { + return global.DB.Delete(u).Error +} + +// Update 更新 +func (as *AuditService) UpdateAuditFile(u *model.AuditFile) error { + return global.DB.Model(u).Updates(u).Error +}