request_data.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package data
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/google/btree"
  6. "git.scraperwall.com/scw/grs"
  7. )
  8. type RequestData struct {
  9. ID string `bson:"_id,omitempty" json:"_id,omitempty" form:"_id,omitempty"`
  10. Connection string `bson:"connection" json:"connection" form:"connection,omitempty"`
  11. IpDst string `bson:"ip_dst" json:"ip_dst" form:"ip_dst,omitempty"`
  12. TcpSeq uint32 `bson:"tcp_seq" json:"tcp_seq" form:"tcp_seq,omitempty"`
  13. XForwardedFor string `bson:"x_forwarded_for" json:"x_forwarded_for,omitempty" form:"x_forwarded_for,omitempty"`
  14. XRealIP string `bson:"x_real_ip" json:"x_real_ip,omitempty" form:"x_real_ip,omitempty"`
  15. Origin string `bson:"origin" json:"origin,omitempty" form:"origin,omitempty"`
  16. PortDst uint32 `bson:"port_dst" json:"port_dst,omitempty" form: "port_dst,omitempty"`
  17. Referer string `bson:"referer" json:"referer,omitempty" form:"referer,omitempty"`
  18. XRequestedWith string `bson:"x_requested_with" json:"x_requested_with,omitempty" form:"x_requested_with.omitempty"`
  19. PortSrc uint32 `bson:"port_src" json:"port_src,omitempty" form:"port_src,omitempty"`
  20. Url string `bson:"url" json:"url,omitempty" form:"url,omitempty"`
  21. Reverse string `bson:"reverse" json:"reverse,omitempty" form:"reverse,omitempty"`
  22. AcceptEncoding string `bson:"accept_encoding" json:"accept_encoding,omitempty" form:"accept_encoding,omitempty"`
  23. AcceptLanguage string `bson:"accept_language" json:"accept_language,omitempty" form:"accept_language,omitempty"`
  24. CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty" form:"created_at,omitempty"`
  25. SortTime time.Time `bson:"-" json:"-" form"-"`
  26. IpSrc string `bson:"ip_src" json:"ip_src,omitempty" form:"ip_src,omitempty"`
  27. Method string `bson:"method" json:"method,omitempty" form:"method,omitempty"`
  28. UserAgent string `bson:"user_agent" json:"user_agent,omitempty" form:"user_agent,omitempty"`
  29. Accept string `bson:"accept" json:"accept,omitempty" form:"accept,omitempty"`
  30. Cookie string `bson:"cookie" json:"cookie,omitempty" form:"cookie,omitempty"`
  31. Host string `bson:"host" json:"host,omitempty" form:"host,omitempty"`
  32. HostName string `bson:"hostname" json:"hostname,omitempty" form:"hostname,omitempty"`
  33. Protocol string `bson:"protocol" json:"protocol,omitempty" form:"protocol,omitempty"`
  34. Source string `bson:"source" json:"source,omitempty" form:"source,omitempty"`
  35. Via string `bson:"via" json:"via,omitempty" form:"via,omitempty"`
  36. DataRaw map[string]interface{} `bson:"data_raw" json:"data_raw,omitempty" form:"data_raw,omitempty"`
  37. Weight uint64 `bson:"weight" json:"weight,omitempty" form:"weight,omitempty"`
  38. Grs grs.GRS `bson:"grs" json:"grs,omitempty" form:"grs,omitempty"`
  39. }
  40. func (a *RequestData) Less(b btree.Item) bool {
  41. return a.CreatedAt.Before(b.(*RequestData).CreatedAt)
  42. }
  43. func (a *RequestData) ToRequest() *Request {
  44. return &Request{
  45. Url: a.Url,
  46. Reverse: a.Reverse,
  47. IpSrc: a.IpSrc,
  48. IpDst: a.IpDst,
  49. PortSrc: a.PortSrc,
  50. PortDst: a.PortDst,
  51. TcpSeq: a.TcpSeq,
  52. CreatedAt: a.CreatedAt.UnixNano(),
  53. XForwardedFor: a.XForwardedFor,
  54. XRealIP: a.XRealIP,
  55. Method: a.Method,
  56. Origin: a.Origin,
  57. Referer: a.Referer,
  58. UserAgent: a.UserAgent,
  59. Source: a.Source,
  60. Host: a.Host,
  61. Protocol: a.Protocol,
  62. Connection: a.Connection,
  63. XRequestedWith: a.XRequestedWith,
  64. AcceptEncoding: a.AcceptEncoding,
  65. AcceptLanguage: a.AcceptLanguage,
  66. Accept: a.Accept,
  67. Cookie: a.Cookie,
  68. Via: a.Via,
  69. }
  70. }
  71. // Path returns the Url without any query string
  72. func (a *RequestData) Path() string {
  73. idx := strings.Index(a.Url, "?")
  74. if idx >= 0 {
  75. return a.Url[0:idx]
  76. }
  77. return a.Url
  78. }