d1abd2b15d
Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
961 B
Go
37 lines
961 B
Go
package remote
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
type StatusReport struct {
|
|
Hostname string `json:"hostname"`
|
|
IPs []string `json:"ips,omitempty"`
|
|
Agent string `json:"agent"`
|
|
CWD string `json:"cwd"`
|
|
Status string `json:"status"`
|
|
Event string `json:"event,omitempty"`
|
|
ConversationID string `json:"conversation_id,omitempty"`
|
|
LastUser string `json:"last_user,omitempty"`
|
|
LastAgent string `json:"last_agent,omitempty"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func SessionKey(hostname, primaryIP, cwd, agent string) string {
|
|
sum := sha256.Sum256([]byte(hostname + "\x00" + primaryIP + "\x00" + cwd + "\x00" + agent))
|
|
return hex.EncodeToString(sum[:])[:32]
|
|
}
|
|
|
|
func PrimaryIP(ips []string) string {
|
|
for _, s := range ips {
|
|
ip := net.ParseIP(s)
|
|
if ip != nil && ip.To4() != nil {
|
|
return ip.To4().String()
|
|
}
|
|
}
|
|
return ""
|
|
}
|