From 3dff8b48f74817764c1ab694e9398c2fb416b82e Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Sat, 21 Aug 2021 02:47:08 +0300 Subject: [PATCH] Refactor `BaseEntryDetails` struct and display the source and destination ports in the UI --- agent/pkg/controllers/entries_controller.go | 3 +- tap/api/api.go | 16 +++++++--- tap/extensions/http/main.go | 10 ++++++- ui/src/components/EndpointPath.tsx | 6 ++-- ui/src/components/HarEntry.tsx | 31 +++++++++++++------- ui/src/components/StatusCode.tsx | 6 +++- ui/src/components/style/HarEntry.module.sass | 5 ++++ 7 files changed, 56 insertions(+), 21 deletions(-) diff --git a/agent/pkg/controllers/entries_controller.go b/agent/pkg/controllers/entries_controller.go index 1d6568b24..894a0d83d 100644 --- a/agent/pkg/controllers/entries_controller.go +++ b/agent/pkg/controllers/entries_controller.go @@ -3,6 +3,7 @@ package controllers import ( "encoding/json" "fmt" + "log" "mizuserver/pkg/database" "mizuserver/pkg/models" "mizuserver/pkg/providers" @@ -221,7 +222,7 @@ func GetEntry(c *gin.Context) { "msg": "Can't get entry details", }) } - fmt.Printf("entryData: %+v\n", entryData) + log.Printf("entryData: %+v\n", entryData) // fullEntryWithPolicy := models.FullEntryWithPolicy{} // if err := models.GetEntry(&entryData, &fullEntryWithPolicy); err != nil { // c.JSON(http.StatusInternalServerError, map[string]interface{}{ diff --git a/tap/api/api.go b/tap/api/api.go index 8a11fc48d..59349f628 100644 --- a/tap/api/api.go +++ b/tap/api/api.go @@ -99,6 +99,10 @@ type MizuEntry struct { Path string `json:"path" gorm:"column:path"` ResolvedSource string `json:"resolvedSource,omitempty" gorm:"column:resolvedSource"` ResolvedDestination string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"` + SourceIp string `json:"sourceIp,omitempty" gorm:"column:sourceIp"` + DestinationIp string `json:"destinationIp,omitempty" gorm:"column:destinationIp"` + SourcePort string `json:"sourcePort,omitempty" gorm:"column:sourcePort"` + DestinationPort string `json:"destinationPort,omitempty" gorm:"column:destinationPort"` IsOutgoing bool `json:"isOutgoing,omitempty" gorm:"column:isOutgoing"` EstimatedSizeBytes int `json:"-" gorm:"column:estimatedSizeBytes"` } @@ -107,12 +111,16 @@ type BaseEntryDetails struct { Id string `json:"id,omitempty"` Protocol Protocol `json:"protocol,omitempty"` Url string `json:"url,omitempty"` - RequestSenderIp string `json:"requestSenderIp,omitempty"` + RequestSenderIp string `json:"request_sender_ip,omitempty"` Service string `json:"service,omitempty"` - Path string `json:"path,omitempty"` - StatusCode int `json:"statusCode,omitempty"` + Summary string `json:"summary,omitempty"` + StatusCode int `json:"status_code,omitempty"` Method string `json:"method,omitempty"` Timestamp int64 `json:"timestamp,omitempty"` + SourceIp string `json:"source_ip,omitempty"` + DestinationIp string `json:"destination_ip,omitempty"` + SourcePort string `json:"source_port,omitempty"` + DestinationPort string `json:"destination_port,omitempty"` IsOutgoing bool `json:"isOutgoing,omitempty"` Latency int64 `json:"latency,omitempty"` Rules ApplicableRules `json:"rules,omitempty"` @@ -133,7 +141,7 @@ func (bed *BaseEntryDetails) UnmarshalData(entry *MizuEntry) error { bed.Id = entry.EntryId bed.Url = entryUrl bed.Service = service - bed.Path = entry.Path + bed.Summary = entry.Path bed.StatusCode = entry.Status bed.Method = entry.Method bed.Timestamp = entry.Timestamp diff --git a/tap/extensions/http/main.go b/tap/extensions/http/main.go index 5f3776c30..b5d36c8c7 100644 --- a/tap/extensions/http/main.go +++ b/tap/extensions/http/main.go @@ -127,6 +127,10 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolve Path: request["url"].(string), ResolvedSource: resolvedSource, ResolvedDestination: resolvedDestination, + SourceIp: item.ConnectionInfo.ClientIP, + DestinationIp: item.ConnectionInfo.ServerIP, + SourcePort: item.ConnectionInfo.ClientPort, + DestinationPort: item.ConnectionInfo.ServerPort, IsOutgoing: item.ConnectionInfo.IsOutgoing, } } @@ -138,10 +142,14 @@ func (d dissecting) Summarize(entry *api.MizuEntry) *api.BaseEntryDetails { Url: entry.Url, RequestSenderIp: entry.RequestSenderIp, Service: entry.Service, - Path: entry.Path, + Summary: entry.Path, StatusCode: entry.Status, Method: entry.Method, Timestamp: entry.Timestamp, + SourceIp: entry.SourceIp, + DestinationIp: entry.DestinationIp, + SourcePort: entry.SourcePort, + DestinationPort: entry.DestinationPort, IsOutgoing: entry.IsOutgoing, Latency: 0, Rules: api.ApplicableRules{ diff --git a/ui/src/components/EndpointPath.tsx b/ui/src/components/EndpointPath.tsx index 4209d6e19..2561aab44 100644 --- a/ui/src/components/EndpointPath.tsx +++ b/ui/src/components/EndpointPath.tsx @@ -9,7 +9,7 @@ interface EndpointPathProps { export const EndpointPath: React.FC = ({method, path}) => { return
- {method && {method}} - {path &&
{path}
} + {method && {method}} + {path &&
{path}
}
-}; \ No newline at end of file +}; diff --git a/ui/src/components/HarEntry.tsx b/ui/src/components/HarEntry.tsx index 6d5f7a325..a95acc100 100644 --- a/ui/src/components/HarEntry.tsx +++ b/ui/src/components/HarEntry.tsx @@ -13,13 +13,16 @@ import outgoingIconNeutral from "./assets/outgoing-traffic-neutral.svg" interface HAREntry { protocol: ProtocolInterface, method?: string, - path: string, + summary: string, service: string, id: string, - statusCode?: number; + status_code?: number; url?: string; - isCurrentRevision?: boolean; timestamp: Date; + source_ip: string, + source_port: string, + destination_ip: string, + destination_port: string, isOutgoing?: boolean; latency: number; rules: Rules; @@ -37,7 +40,7 @@ interface HAREntryProps { } export const HarEntry: React.FC = ({entry, setFocusedEntryId, isSelected}) => { - const classification = getClassification(entry.statusCode) + const classification = getClassification(entry.status_code) let ingoingIcon; let outgoingIcon; switch(classification) { @@ -74,23 +77,29 @@ export const HarEntry: React.FC = ({entry, setFocusedEntryId, isS style={{border: isSelected ? `1px ${entry.protocol.background_color} solid` : "1px transparent solid"}} > - {entry.statusCode &&
- + {entry.status_code &&
+
}
- +
- {entry.service} + {entry.service}
+ {entry.source_port} {entry.isOutgoing ? - outgoing traffic + Outgoing traffic : - ingoing traffic + Ingoing traffic } + {entry.destination_port} +
+
+ + {new Date(+entry.timestamp)?.toLocaleString()} +
-
{new Date(+entry.timestamp)?.toLocaleString()}
}; diff --git a/ui/src/components/StatusCode.tsx b/ui/src/components/StatusCode.tsx index 2230a9b8a..be7243fee 100644 --- a/ui/src/components/StatusCode.tsx +++ b/ui/src/components/StatusCode.tsx @@ -16,7 +16,11 @@ const StatusCode: React.FC = ({statusCode}) => { const classification = getClassification(statusCode) - return {statusCode} + return + {statusCode} + }; export function getClassification(statusCode: number): string { diff --git a/ui/src/components/style/HarEntry.module.sass b/ui/src/components/style/HarEntry.module.sass index c87c6d5fb..78d4dc6aa 100644 --- a/ui/src/components/style/HarEntry.module.sass +++ b/ui/src/components/style/HarEntry.module.sass @@ -63,3 +63,8 @@ border-right: 1px solid $data-background-color padding: 4px padding-right: 12px + +.port + font-size: 12px + color: $secondary-font-color + margin: 5px