2022-05-09 23:16:59 +02:00
|
|
|
package tracer
|
|
|
|
|
|
|
|
import (
|
2022-05-10 22:50:29 +02:00
|
|
|
"net/http"
|
2022-05-19 23:20:20 +02:00
|
|
|
"time"
|
2022-05-09 23:16:59 +02:00
|
|
|
)
|
|
|
|
|
2022-05-11 22:58:03 +02:00
|
|
|
type Strategy func(event Event)
|
|
|
|
|
2022-05-09 23:16:59 +02:00
|
|
|
type Tracer struct {
|
2022-05-11 22:58:03 +02:00
|
|
|
strategy Strategy
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
2022-05-11 22:58:03 +02:00
|
|
|
func Init(strategy Strategy) *Tracer {
|
|
|
|
return &Tracer{
|
|
|
|
strategy: strategy,
|
|
|
|
}
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tracer *Tracer) TraceEvent(event Event) {
|
2022-05-19 23:20:20 +02:00
|
|
|
event.DateTime = time.Now().UTC().String()
|
2022-05-11 22:58:03 +02:00
|
|
|
tracer.strategy(event)
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Event struct {
|
2022-05-19 23:20:20 +02:00
|
|
|
DateTime string
|
2022-05-10 22:50:29 +02:00
|
|
|
RemoteAddr string
|
2022-05-17 23:32:00 +02:00
|
|
|
Protocol string
|
2022-05-10 22:50:29 +02:00
|
|
|
Command string
|
2022-05-17 23:32:00 +02:00
|
|
|
Status string
|
2022-05-10 22:50:29 +02:00
|
|
|
Msg string
|
|
|
|
ID string
|
|
|
|
Environ string
|
|
|
|
User string
|
|
|
|
Password string
|
|
|
|
Client string
|
|
|
|
Headers http.Header
|
|
|
|
Cookies []*http.Cookie
|
|
|
|
UserAgent string
|
|
|
|
HostHTTPRequest string
|
|
|
|
Body string
|
|
|
|
HTTPMethod string
|
|
|
|
RequestURI string
|
2022-05-09 23:16:59 +02:00
|
|
|
}
|
|
|
|
|
2022-05-10 22:50:29 +02:00
|
|
|
type Protocol int
|
|
|
|
|
|
|
|
const (
|
|
|
|
HTTP Protocol = iota
|
|
|
|
SSH
|
|
|
|
)
|
|
|
|
|
2022-05-17 23:32:00 +02:00
|
|
|
func (status Protocol) String() string {
|
|
|
|
return [...]string{"HTTP", "SSH"}[status]
|
|
|
|
}
|
|
|
|
|
2022-05-09 23:16:59 +02:00
|
|
|
type Status int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Start Status = iota
|
|
|
|
End
|
|
|
|
Stateless
|
|
|
|
Interaction
|
|
|
|
)
|
|
|
|
|
|
|
|
func (status Status) String() string {
|
|
|
|
return [...]string{"Start", "End", "Stateless", "Interaction"}[status]
|
|
|
|
}
|