audit.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package api
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/gin-gonic/gin/binding"
  5. request "github.com/lejianwen/rustdesk-api/v2/http/request/api"
  6. "github.com/lejianwen/rustdesk-api/v2/http/response"
  7. "github.com/lejianwen/rustdesk-api/v2/model"
  8. "github.com/lejianwen/rustdesk-api/v2/service"
  9. "time"
  10. )
  11. type Audit struct {
  12. }
  13. // AuditConn
  14. // @Tags 审计
  15. // @Summary 审计连接
  16. // @Description 审计连接
  17. // @Accept json
  18. // @Produce json
  19. // @Param body body request.AuditConnForm true "审计连接"
  20. // @Success 200 {string} string ""
  21. // @Failure 500 {object} response.Response
  22. // @Router /audit/conn [post]
  23. func (a *Audit) AuditConn(c *gin.Context) {
  24. af := &request.AuditConnForm{}
  25. err := c.ShouldBindBodyWith(af, binding.JSON)
  26. if err != nil {
  27. response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
  28. return
  29. }
  30. /*ttt := &gin.H{}
  31. c.ShouldBindBodyWith(ttt, binding.JSON)
  32. fmt.Println(ttt)*/
  33. ac := af.ToAuditConn()
  34. if af.Action == model.AuditActionNew {
  35. service.AllService.AuditService.CreateAuditConn(ac)
  36. } else if af.Action == model.AuditActionClose {
  37. ex := service.AllService.AuditService.InfoByPeerIdAndConnId(af.Id, af.ConnId)
  38. if ex.Id != 0 {
  39. ex.CloseTime = time.Now().Unix()
  40. service.AllService.AuditService.UpdateAuditConn(ex)
  41. }
  42. } else if af.Action == "" {
  43. ex := service.AllService.AuditService.InfoByPeerIdAndConnId(af.Id, af.ConnId)
  44. if ex.Id != 0 {
  45. up := &model.AuditConn{
  46. IdModel: model.IdModel{Id: ex.Id},
  47. FromPeer: ac.FromPeer,
  48. FromName: ac.FromName,
  49. SessionId: ac.SessionId,
  50. Type: ac.Type,
  51. }
  52. service.AllService.AuditService.UpdateAuditConn(up)
  53. }
  54. }
  55. response.Success(c, "")
  56. }
  57. // AuditFile
  58. // @Tags 审计
  59. // @Summary 审计文件
  60. // @Description 审计文件
  61. // @Accept json
  62. // @Produce json
  63. // @Param body body request.AuditFileForm true "审计文件"
  64. // @Success 200 {string} string ""
  65. // @Failure 500 {object} response.Response
  66. // @Router /audit/file [post]
  67. func (a *Audit) AuditFile(c *gin.Context) {
  68. aff := &request.AuditFileForm{}
  69. err := c.ShouldBindBodyWith(aff, binding.JSON)
  70. if err != nil {
  71. response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
  72. return
  73. }
  74. //ttt := &gin.H{}
  75. //c.ShouldBindBodyWith(ttt, binding.JSON)
  76. //fmt.Println(ttt)
  77. af := aff.ToAuditFile()
  78. service.AllService.AuditService.CreateAuditFile(af)
  79. response.Success(c, "")
  80. }