audit.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package api
  2. import (
  3. "encoding/json"
  4. "github.com/lejianwen/rustdesk-api/global"
  5. "github.com/lejianwen/rustdesk-api/model"
  6. "strconv"
  7. )
  8. type AuditConnForm struct {
  9. Action string `json:"action"`
  10. ConnId int64 `json:"conn_id"`
  11. Id string `json:"id"`
  12. Peer []string `json:"peer"`
  13. Ip string `json:"ip"`
  14. SessionId float64 `json:"session_id"`
  15. Type int `json:"type"`
  16. Uuid string `json:"uuid"`
  17. }
  18. func (a *AuditConnForm) ToAuditConn() *model.AuditConn {
  19. fp := ""
  20. fn := ""
  21. if len(a.Peer) >= 1 {
  22. fp = a.Peer[0]
  23. if len(a.Peer) == 2 {
  24. fn = a.Peer[1]
  25. }
  26. }
  27. ssid := strconv.FormatFloat(a.SessionId, 'f', -1, 64)
  28. return &model.AuditConn{
  29. Action: a.Action,
  30. ConnId: a.ConnId,
  31. PeerId: a.Id,
  32. FromPeer: fp,
  33. FromName: fn,
  34. Ip: a.Ip,
  35. SessionId: ssid,
  36. Type: a.Type,
  37. Uuid: a.Uuid,
  38. }
  39. }
  40. type AuditFileForm struct {
  41. Id string `json:"id"`
  42. Info string `json:"info"`
  43. IsFile bool `json:"is_file"`
  44. Path string `json:"path"`
  45. PeerId string `json:"peer_id"`
  46. Type int `json:"type"`
  47. Uuid string `json:"uuid"`
  48. }
  49. type AuditFileInfo struct {
  50. Ip string `json:"ip"`
  51. Name string `json:"name"`
  52. Num int `json:"num"`
  53. }
  54. func (a *AuditFileForm) ToAuditFile() *model.AuditFile {
  55. fi := &AuditFileInfo{}
  56. err := json.Unmarshal([]byte(a.Info), fi)
  57. if err != nil {
  58. global.Logger.Warn("ToAuditFile", err)
  59. }
  60. return &model.AuditFile{
  61. PeerId: a.Id,
  62. Info: a.Info,
  63. IsFile: a.IsFile,
  64. FromPeer: a.PeerId,
  65. Path: a.Path,
  66. Type: a.Type,
  67. Uuid: a.Uuid,
  68. FromName: fi.Name,
  69. Ip: fi.Ip,
  70. Num: fi.Num,
  71. }
  72. }