You've already forked caddy-opnsense-blocker
Build initial caddy-opnsense-blocker daemon
This commit is contained in:
140
internal/model/types.go
Normal file
140
internal/model/types.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type DecisionAction string
|
||||
|
||||
const (
|
||||
DecisionActionNone DecisionAction = "none"
|
||||
DecisionActionReview DecisionAction = "review"
|
||||
DecisionActionBlock DecisionAction = "block"
|
||||
DecisionActionAllow DecisionAction = "allow"
|
||||
)
|
||||
|
||||
type ManualOverride string
|
||||
|
||||
const (
|
||||
ManualOverrideNone ManualOverride = "none"
|
||||
ManualOverrideForceAllow ManualOverride = "force_allow"
|
||||
ManualOverrideForceBlock ManualOverride = "force_block"
|
||||
)
|
||||
|
||||
type IPStateStatus string
|
||||
|
||||
const (
|
||||
IPStateObserved IPStateStatus = "observed"
|
||||
IPStateReview IPStateStatus = "review"
|
||||
IPStateBlocked IPStateStatus = "blocked"
|
||||
IPStateAllowed IPStateStatus = "allowed"
|
||||
)
|
||||
|
||||
type AccessLogRecord struct {
|
||||
OccurredAt time.Time
|
||||
RemoteIP string
|
||||
ClientIP string
|
||||
Host string
|
||||
Method string
|
||||
URI string
|
||||
Path string
|
||||
Status int
|
||||
UserAgent string
|
||||
RawJSON string
|
||||
}
|
||||
|
||||
type Decision struct {
|
||||
Action DecisionAction
|
||||
Reasons []string
|
||||
}
|
||||
|
||||
func (d Decision) PrimaryReason() string {
|
||||
if len(d.Reasons) == 0 {
|
||||
return ""
|
||||
}
|
||||
return d.Reasons[0]
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
ID int64 `json:"id"`
|
||||
SourceName string `json:"source_name"`
|
||||
ProfileName string `json:"profile_name"`
|
||||
OccurredAt time.Time `json:"occurred_at"`
|
||||
RemoteIP string `json:"remote_ip"`
|
||||
ClientIP string `json:"client_ip"`
|
||||
Host string `json:"host"`
|
||||
Method string `json:"method"`
|
||||
URI string `json:"uri"`
|
||||
Path string `json:"path"`
|
||||
Status int `json:"status"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
Decision DecisionAction `json:"decision"`
|
||||
DecisionReason string `json:"decision_reason"`
|
||||
DecisionReasons []string `json:"decision_reasons,omitempty"`
|
||||
Enforced bool `json:"enforced"`
|
||||
RawJSON string `json:"raw_json"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CurrentState IPStateStatus `json:"current_state"`
|
||||
ManualOverride ManualOverride `json:"manual_override"`
|
||||
}
|
||||
|
||||
type IPState struct {
|
||||
IP string `json:"ip"`
|
||||
FirstSeenAt time.Time `json:"first_seen_at"`
|
||||
LastSeenAt time.Time `json:"last_seen_at"`
|
||||
LastSourceName string `json:"last_source_name"`
|
||||
LastUserAgent string `json:"last_user_agent"`
|
||||
LatestStatus int `json:"latest_status"`
|
||||
TotalEvents int64 `json:"total_events"`
|
||||
State IPStateStatus `json:"state"`
|
||||
StateReason string `json:"state_reason"`
|
||||
ManualOverride ManualOverride `json:"manual_override"`
|
||||
LastEventID int64 `json:"last_event_id"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type DecisionRecord struct {
|
||||
ID int64 `json:"id"`
|
||||
EventID int64 `json:"event_id"`
|
||||
IP string `json:"ip"`
|
||||
SourceName string `json:"source_name"`
|
||||
Kind string `json:"kind"`
|
||||
Action DecisionAction `json:"action"`
|
||||
Reason string `json:"reason"`
|
||||
Actor string `json:"actor"`
|
||||
Enforced bool `json:"enforced"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type OPNsenseAction struct {
|
||||
ID int64 `json:"id"`
|
||||
IP string `json:"ip"`
|
||||
Action string `json:"action"`
|
||||
Result string `json:"result"`
|
||||
Message string `json:"message"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type SourceOffset struct {
|
||||
SourceName string
|
||||
Path string
|
||||
Inode string
|
||||
Offset int64
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type IPDetails struct {
|
||||
State IPState `json:"state"`
|
||||
RecentEvents []Event `json:"recent_events"`
|
||||
Decisions []DecisionRecord `json:"decisions"`
|
||||
BackendActions []OPNsenseAction `json:"backend_actions"`
|
||||
}
|
||||
|
||||
type Overview struct {
|
||||
TotalEvents int64 `json:"total_events"`
|
||||
TotalIPs int64 `json:"total_ips"`
|
||||
BlockedIPs int64 `json:"blocked_ips"`
|
||||
ReviewIPs int64 `json:"review_ips"`
|
||||
AllowedIPs int64 `json:"allowed_ips"`
|
||||
ObservedIPs int64 `json:"observed_ips"`
|
||||
RecentIPs []IPState `json:"recent_ips"`
|
||||
RecentEvents []Event `json:"recent_events"`
|
||||
}
|
||||
Reference in New Issue
Block a user