From 765d3b887712eae69ad35516bb74b6a43fcb2f36 Mon Sep 17 00:00:00 2001 From: Jon Hadfield Date: Sat, 25 May 2024 10:21:03 +0100 Subject: [PATCH] improve table formatting. --- providers/abuseipdb/abuseipdb.go | 7 ++++--- providers/annotated/annotated.go | 6 +++--- providers/aws/aws.go | 10 +++++----- providers/azure/azure.go | 8 ++------ providers/bingbot/bingbot.go | 6 +----- providers/criminalip/criminalip.go | 9 +++------ providers/digitalocean/digitalocean.go | 9 +++------ providers/gcp/gcp.go | 9 +++------ providers/google/google.go | 9 +++------ providers/googlebot/googlebot.go | 9 +++------ providers/icloudpr/icloudpr.go | 9 +++------ providers/ipapi/ipapi.go | 10 +++------- providers/ipurl/ipurl.go | 10 ++++++---- providers/linode/linode.go | 9 +++------ providers/providers.go | 13 ++++++++++--- providers/ptr/ptr.go | 4 +--- providers/shodan/shodan.go | 6 +++--- providers/virustotal/virustotal.go | 15 +++++++-------- session/session.go | 1 - 19 files changed, 66 insertions(+), 93 deletions(-) diff --git a/providers/abuseipdb/abuseipdb.go b/providers/abuseipdb/abuseipdb.go index b140852..1969619 100644 --- a/providers/abuseipdb/abuseipdb.go +++ b/providers/abuseipdb/abuseipdb.go @@ -13,6 +13,8 @@ import ( "strings" "time" + "github.com/jedib0t/go-pretty/v6/text" + "github.com/fatih/color" "github.com/hashicorp/go-retryablehttp" "github.com/jedib0t/go-pretty/v6/table" @@ -25,7 +27,6 @@ const ( ProviderName = "abuseipdb" APIURL = "https://api.abuseipdb.com" HostIPPath = "/api/v2/check" - MaxColumnWidth = 120 IndentPipeHyphens = " |-----" portLastModifiedFormat = "2006-01-02T15:04:05+07:00" ResultTTL = 12 * time.Hour @@ -127,7 +128,7 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) { }) tw.AppendRow(table.Row{"Last Reported", result.Data.LastReportedAt.UTC().Format(providers.TimeFormat)}) - tw.AppendRow(table.Row{"Abuse Confidence Score", providers.DashIfEmpty(result.Data.AbuseConfidenceScore)}) + tw.AppendRow(table.Row{"Confidence", providers.DashIfEmpty(result.Data.AbuseConfidenceScore)}) tw.AppendRow(table.Row{"Public", result.Data.IsPublic}) tw.AppendRow(table.Row{"Domain", providers.DashIfEmpty(result.Data.Domain)}) tw.AppendRow(table.Row{"Hostnames", providers.DashIfEmpty(strings.Join(result.Data.Hostnames, ", "))}) @@ -148,7 +149,7 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) { } tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: true, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: true, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth, ColorsHeader: text.Colors{text.BgCyan}}, }) tw.SetAutoIndex(false) // tw.SetStyle(table.StyleColoredDark) diff --git a/providers/annotated/annotated.go b/providers/annotated/annotated.go index 0dc0922..bc2a5ac 100644 --- a/providers/annotated/annotated.go +++ b/providers/annotated/annotated.go @@ -29,7 +29,6 @@ import ( const ( ProviderName = "annotated" CacheTTL = 5 * time.Minute - MaxColumnWidth = 120 ipFileSuffixesToIgnore = "sh,conf" ) @@ -253,7 +252,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row for prefix, annotations := range result { - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(prefix.String())}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(prefix.String())}) for _, anno := range annotations { tw.AppendRow(table.Row{"Date", anno.Date}) @@ -279,7 +279,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) diff --git a/providers/aws/aws.go b/providers/aws/aws.go index 64d68e5..55c2985 100644 --- a/providers/aws/aws.go +++ b/providers/aws/aws.go @@ -16,9 +16,8 @@ import ( ) const ( - ProviderName = "aws" - DocTTL = 24 * time.Hour - MaxColumnWidth = 120 + ProviderName = "aws" + DocTTL = 24 * time.Hour ) type Config struct { @@ -314,7 +313,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(result.Prefix.IPPrefix.String())}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(result.Prefix.IPPrefix.String())}) tw.AppendRow(table.Row{"Service", dashIfEmpty(result.Prefix.Service)}) tw.AppendRow(table.Row{"Region", dashIfEmpty(result.Prefix.Region)}) @@ -332,7 +332,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("AWS | Host: %s", c.Host.String()) diff --git a/providers/azure/azure.go b/providers/azure/azure.go index 61f7a54..3ae686d 100644 --- a/providers/azure/azure.go +++ b/providers/azure/azure.go @@ -64,10 +64,6 @@ func (c *ProviderClient) GetConfig() *session.Session { return &c.Session } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) loadProviderDataFromSource() error { azureClient := azure.New() azureClient.Client = c.HTTPClient @@ -293,10 +289,10 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRow(table.Row{"Platform", dashIfEmpty(result.Properties.Platform)}) tw.AppendRow(table.Row{"Cloud", dashIfEmpty(result.Cloud)}) tw.AppendRow(table.Row{"System Service", dashIfEmpty(result.Properties.SystemService)}) - tw.AppendRow(table.Row{"Network Features", dashIfEmpty(strings.Join(result.Properties.NetworkFeatures, ","))}) + tw.AppendRow(table.Row{"Net Features", dashIfEmpty(strings.Join(result.Properties.NetworkFeatures, ","))}) tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("AZURE | Host: %s", c.Host.String()) diff --git a/providers/bingbot/bingbot.go b/providers/bingbot/bingbot.go index 9744efd..fe47c0b 100644 --- a/providers/bingbot/bingbot.go +++ b/providers/bingbot/bingbot.go @@ -113,10 +113,6 @@ func (c *ProviderClient) loadProviderData() error { return nil } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) Initialise() error { if c.Cache == nil { return errors.New("cache not set") @@ -294,7 +290,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("Bingbot | Host: %s", c.Host.String()) diff --git a/providers/criminalip/criminalip.go b/providers/criminalip/criminalip.go index f200dd6..899b552 100644 --- a/providers/criminalip/criminalip.go +++ b/providers/criminalip/criminalip.go @@ -200,10 +200,6 @@ func fetchData(client session.Session) (*HostSearchResult, error) { return result, nil } -const ( - MaxColumnWidth = 120 -) - func tidyBanner(banner string) string { // remove empty lines using regex match var lines []string @@ -358,7 +354,8 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRow(table.Row{"Domains", strings.Join(getDomains(result.Domain), ", ")}) } - tw.AppendRow(table.Row{"Score Inbound", result.Score.Inbound}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Score Inbound", providers.Column1MinWidth), result.Score.Inbound}) tw.AppendRow(table.Row{"Score Outbound", result.Score.Outbound}) portDataForTable, err := c.GenPortDataForTable(result.Port.Data) @@ -417,7 +414,7 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: true, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: true, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("CRIMINAL IP | Host: %s", c.Host.String()) diff --git a/providers/digitalocean/digitalocean.go b/providers/digitalocean/digitalocean.go index a607c3e..b8bcfde 100644 --- a/providers/digitalocean/digitalocean.go +++ b/providers/digitalocean/digitalocean.go @@ -114,10 +114,6 @@ func (c *ProviderClient) loadProviderData() error { return nil } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) Initialise() error { if c.Cache == nil { return errors.New("cache not set") @@ -270,7 +266,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(result.Record.NetworkText)}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(result.Record.NetworkText)}) tw.AppendRow(table.Row{"Country Code", dashIfEmpty(result.Record.CountryCode)}) tw.AppendRow(table.Row{"City Name", dashIfEmpty(result.Record.CityName)}) tw.AppendRow(table.Row{"City Code", dashIfEmpty(result.Record.CityCode)}) @@ -286,7 +283,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("DIGITAL OCEAN | Host: %s", c.Host.String()) diff --git a/providers/gcp/gcp.go b/providers/gcp/gcp.go index e82711b..85ef63f 100644 --- a/providers/gcp/gcp.go +++ b/providers/gcp/gcp.go @@ -113,10 +113,6 @@ func (c *ProviderClient) loadProviderData() error { return nil } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) Initialise() error { if c.Cache == nil { return errors.New("cache not set") @@ -292,7 +288,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(result.Prefix.String())}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(result.Prefix.String())}) tw.AppendRow(table.Row{"Scope", dashIfEmpty(result.Scope)}) tw.AppendRow(table.Row{"Service", dashIfEmpty(result.Service)}) @@ -306,7 +303,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("GCP | Host: %s", c.Host.String()) diff --git a/providers/google/google.go b/providers/google/google.go index b4e413a..d1aeab6 100644 --- a/providers/google/google.go +++ b/providers/google/google.go @@ -113,10 +113,6 @@ func (c *ProviderClient) loadProviderData() error { return nil } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) Initialise() error { if c.Cache == nil { return errors.New("cache not set") @@ -286,7 +282,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(result.Prefix.String())}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(result.Prefix.String())}) if !result.CreationTime.IsZero() { tw.AppendRow(table.Row{"Creation Time", dashIfEmpty(result.CreationTime.UTC().Format(providers.TimeFormat))}) @@ -294,7 +291,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("GOOGLE | Host: %s", c.Host.String()) diff --git a/providers/googlebot/googlebot.go b/providers/googlebot/googlebot.go index a1766d7..def07c6 100644 --- a/providers/googlebot/googlebot.go +++ b/providers/googlebot/googlebot.go @@ -113,10 +113,6 @@ func (c *ProviderClient) loadProviderData() error { return nil } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) Initialise() error { if c.Cache == nil { return errors.New("cache not set") @@ -286,7 +282,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(result.Prefix.String())}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(result.Prefix.String())}) if !result.CreationTime.IsZero() { tw.AppendRow(table.Row{"Creation Time", dashIfEmpty(result.CreationTime.String())}) @@ -294,7 +291,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("Googlebot | Host: %s", c.Host.String()) diff --git a/providers/icloudpr/icloudpr.go b/providers/icloudpr/icloudpr.go index 6a9fbdd..660402f 100644 --- a/providers/icloudpr/icloudpr.go +++ b/providers/icloudpr/icloudpr.go @@ -113,10 +113,6 @@ func (c *ProviderClient) loadProviderData() error { return nil } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) Initialise() error { if c.Cache == nil { return errors.New("cache not set") @@ -273,7 +269,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(result.Prefix.String())}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(result.Prefix.String())}) tw.AppendRow(table.Row{"Alpha2Code", dashIfEmpty(result.Alpha2Code)}) tw.AppendRow(table.Row{"Region", dashIfEmpty(result.Region)}) tw.AppendRow(table.Row{"City", dashIfEmpty(result.City)}) @@ -285,7 +282,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("ICLOUD PRIVATE RELAY | Host: %s", c.Host.String()) diff --git a/providers/ipapi/ipapi.go b/providers/ipapi/ipapi.go index 85bb917..d08c684 100644 --- a/providers/ipapi/ipapi.go +++ b/providers/ipapi/ipapi.go @@ -21,7 +21,6 @@ import ( const ( ProviderName = "ipapi" - MaxColumnWidth = 120 IndentPipeHyphens = " |-----" portLastModifiedFormat = "2006-01-02T15:04:05+07:00" ResultTTL = 1 * time.Hour @@ -124,8 +123,8 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) { } tw := table.NewWriter() - - tw.AppendRow(table.Row{"Organisation", providers.DashIfEmpty(findHostData.Org)}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Organisation", providers.Column1MinWidth), providers.DashIfEmpty(findHostData.Org)}) tw.AppendRow(table.Row{"Hostname", providers.DashIfEmpty(findHostData.Hostname)}) tw.AppendRow(table.Row{"Country", providers.DashIfEmpty(findHostData.CountryName)}) tw.AppendRow(table.Row{"Region", providers.DashIfEmpty(findHostData.Region)}) @@ -134,13 +133,10 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRow(table.Row{"ASN", providers.DashIfEmpty(findHostData.Asn)}) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: true, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, {Number: 1, AutoMerge: true}, }) - tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: true, WidthMax: MaxColumnWidth, WidthMin: 50}, - }) tw.SetAutoIndex(false) // tw.SetStyle(table.StyleColoredDark) // tw.Style().Options.DrawBorder = true diff --git a/providers/ipurl/ipurl.go b/providers/ipurl/ipurl.go index dae3558..107381a 100644 --- a/providers/ipurl/ipurl.go +++ b/providers/ipurl/ipurl.go @@ -22,6 +22,8 @@ import ( const ( ProviderName = "ipurl" CacheTTL = 3 * time.Hour + // override default set in providers package constant as column 2 is expected to be wide + column1MinWidth = 13 ) type Config struct { @@ -371,7 +373,9 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { } tw := table.NewWriter() - tw.AppendRow(table.Row{color.HiWhiteString("Prefixes")}) + + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{color.HiWhiteString(providers.PadRight("Prefixes", column1MinWidth))}) for prefix, urls := range result { tw.AppendRow(table.Row{"", color.CyanString(prefix.String())}) @@ -382,7 +386,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { } tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: true, WidthMax: MaxColumnWidth, WidthMin: 10}, + {Number: 2, AutoMerge: true, WidthMax: providers.WideColumnMaxWidth, WidthMin: 10}, }) tw.SetAutoIndex(false) tw.SetTitle("IP URL | Host: %s", c.Host.String()) @@ -394,6 +398,4 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { return &tw, nil } -const MaxColumnWidth = 120 - const IndentPipeHyphens = " |-----" diff --git a/providers/linode/linode.go b/providers/linode/linode.go index ea13b2b..c401b74 100644 --- a/providers/linode/linode.go +++ b/providers/linode/linode.go @@ -113,10 +113,6 @@ func (c *ProviderClient) loadProviderData() error { return nil } -const ( - MaxColumnWidth = 120 -) - func (c *ProviderClient) Initialise() error { if c.Cache == nil { return errors.New("cache not set") @@ -273,7 +269,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"Prefix", dashIfEmpty(result.Prefix.String())}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("Prefix", providers.Column1MinWidth), dashIfEmpty(result.Prefix.String())}) tw.AppendRow(table.Row{"Alpha2Code", dashIfEmpty(result.Alpha2Code)}) tw.AppendRow(table.Row{"Region", dashIfEmpty(result.Region)}) tw.AppendRow(table.Row{"City", dashIfEmpty(result.City)}) @@ -284,7 +281,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: false, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: false, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) tw.SetAutoIndex(false) tw.SetTitle("LINODE | Host: %s", c.Host.String()) diff --git a/providers/providers.go b/providers/providers.go index 0af4b8c..24755de 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -14,8 +14,11 @@ import ( ) const ( - DefaultUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125." - TimeFormat = "2006-01-02 15:04:05 MST" + DefaultUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125." + TimeFormat = "2006-01-02 15:04:05 MST" + Column1MinWidth = 14 + WideColumnMaxWidth = 75 + WideColumnMinWidth = 50 ) var ( @@ -24,7 +27,7 @@ var ( ErrNoMatchFound = errors.New("no match found") ErrForbiddenByProvider = errors.New("forbidden by provider") CacheProviderPrefix = "provider_" - CacheKeySHALen = 16 + CacheKeySHALen = 15 ) func AgeToHours(age string) (int64, error) { @@ -296,3 +299,7 @@ func FormatTimeOrDash(s string, format string) string { return result.UTC().Format(TimeFormat) } + +func PadRight(str string, length int) string { + return str + strings.Repeat(" ", length-len(str)) +} diff --git a/providers/ptr/ptr.go b/providers/ptr/ptr.go index 43b99da..097da04 100644 --- a/providers/ptr/ptr.go +++ b/providers/ptr/ptr.go @@ -22,8 +22,6 @@ import ( const ( ProviderName = "ptr" - MaxColumnWidth = 120 - IndentPipeHyphens = " |-----" portLastModifiedFormat = "2006-01-02T15:04:05+07:00" ResultTTL = 30 * time.Minute DefaultNameserver = "1.1.1.1:53" @@ -132,7 +130,7 @@ func (c *Client) CreateTable(data []byte) (*table.Writer, error) { }) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: true, WidthMax: MaxColumnWidth, WidthMin: 15}, + {Number: 2, AutoMerge: true, WidthMax: providers.WideColumnMaxWidth, WidthMin: 15}, }) tw.SetAutoIndex(false) // tw.SetStyle(table.StyleColoredDark) diff --git a/providers/shodan/shodan.go b/providers/shodan/shodan.go index 54d24b7..e4a3849 100644 --- a/providers/shodan/shodan.go +++ b/providers/shodan/shodan.go @@ -25,7 +25,6 @@ const ( ProviderName = "shodan" APIURL = "https://api.shodan.io" HostIPPath = "/shodan/host" - MaxColumnWidth = 120 IndentPipeHyphens = " |-----" portLastModifiedFormat = "2006-01-02T15:04:05.999999" ResultTTL = 12 * time.Hour @@ -293,7 +292,8 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { var rows []table.Row - tw.AppendRow(table.Row{"WHOIS", providers.FormatTimeOrDash(result.LastUpdate, portLastModifiedFormat)}) + // pad column to ensure title row fills the table + tw.AppendRow(table.Row{providers.PadRight("WHOIS", providers.Column1MinWidth), providers.FormatTimeOrDash(result.LastUpdate, portLastModifiedFormat)}) tw.AppendRow(table.Row{" - Org", providers.DashIfEmpty(result.Org)}) tw.AppendRow(table.Row{ " - Country", @@ -516,7 +516,7 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { tw.AppendRows(rows) tw.SetColumnConfigs([]table.ColumnConfig{ - {Number: 2, AutoMerge: true, WidthMax: MaxColumnWidth, WidthMin: 50}, + {Number: 2, AutoMerge: true, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth}, }) } diff --git a/providers/virustotal/virustotal.go b/providers/virustotal/virustotal.go index eb13a40..3ce3e74 100644 --- a/providers/virustotal/virustotal.go +++ b/providers/virustotal/virustotal.go @@ -13,6 +13,8 @@ import ( "strings" "time" + "github.com/jedib0t/go-pretty/v6/text" + "github.com/fatih/color" "github.com/hashicorp/go-retryablehttp" @@ -26,7 +28,6 @@ const ( ProviderName = "virustotal" APIURL = "https://www.virustotal.com" HostIPPath = "/api/v3/ip_addresses" - MaxColumnWidth = 120 IndentPipeHyphens = " |-----" portLastModifiedFormat = "2006-01-02T15:04:05.999999" ResultTTL = 12 * time.Hour @@ -463,12 +464,16 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { {Number: 1, AutoMerge: true}, }) + tw.SetColumnConfigs([]table.ColumnConfig{ + {Number: 2, AutoMerge: true, WidthMax: providers.WideColumnMaxWidth, WidthMin: providers.WideColumnMinWidth, ColorsHeader: text.Colors{text.BgCyan}}, + }) + var rows []table.Row tm := time.Unix(int64(result.Data.Attributes.LastAnalysisDate), 0) rda := result.Data.Attributes - tw.AppendRow(table.Row{"Network", result.Data.Attributes.Network}) + tw.AppendRow(table.Row{providers.PadRight("Network", providers.Column1MinWidth), result.Data.Attributes.Network}) tw.AppendRow(table.Row{"Country", result.Data.Attributes.Country}) tw.AppendRow(table.Row{"Reputation", result.Data.Attributes.Reputation}) tw.AppendRow(table.Row{"Total Votes", fmt.Sprintf("Malicious %d Harmless %d", result.Data.Attributes.TotalVotes.Malicious, result.Data.Attributes.TotalVotes.Harmless)}) @@ -482,12 +487,6 @@ func (c *ProviderClient) CreateTable(data []byte) (*table.Writer, error) { rda.LastAnalysisResults.GetTableRows(&c.Session, tw) tw.AppendRows(rows) - // - // tw.SetColumnConfigs([]table.ColumnConfig{ - // {Number: 2, AutoMerge: true, WidthMax: MaxColumnWidth, WidthMin: 50}, - // }) - //} - // tw.SetAutoIndex(false) // tw.SetStyle(table.StyleColoredDark) // tw.Style().Options.DrawBorder = true diff --git a/session/session.go b/session/session.go index 228291b..83d2630 100644 --- a/session/session.go +++ b/session/session.go @@ -125,7 +125,6 @@ type Session struct { Providers Providers `mapstructure:"providers"` HideProgress bool `mapstructure:"hide-progress"` - // MaxWidth int UseTestData bool }