diff --git a/.gitignore b/.gitignore index 66fd13c..1f74d7f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ # Dependency directories (remove the comment below to include it) # vendor/ +**/bin/** +**/build/** +**/result.csv diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/cmd/mangobars/mangobars.go b/cmd/mangobars/mangobars.go index 6a888a3..129d916 100644 --- a/cmd/mangobars/mangobars.go +++ b/cmd/mangobars/mangobars.go @@ -16,7 +16,7 @@ import ( const usageString = `Usage: mangobars [OPTION] [FILEPATH] Checks the expiration status for Server certificates. -Example: +Example: mangobars -w 20 -a 10 -i host.csv -o result.csv mangobars -h amazon.com -p 443 mangobars -h amazon.com @@ -36,13 +36,6 @@ var ( fw *writer.FileWriter ) -func main() { - if err := start(); err != nil { - fmt.Fprintf(os.Stderr, "%+v", err) - os.Exit(1) - } -} - func start() error { usage() @@ -132,6 +125,7 @@ func dispatch(reader io.Reader) (chan ssl.CertificateStatusResult, error) { r := csv.NewReader(reader) r.Comma = ',' r.Comment = '#' + r.FieldsPerRecord = -1 // could have variable number of fields per record for { entry, err := r.Read() if err == io.EOF { @@ -142,9 +136,22 @@ func dispatch(reader io.Reader) (chan ssl.CertificateStatusResult, error) { cleanup() return nil, err } + + if len(entry) < 0 { + cleanup() + return nil, fmt.Errorf("number of fields in the record are less than expected length") + } + + derivePort := func(record []string) string { + if len(record) == 2 && len(record[1]) != 0 { + return record[1] + } + return "443" + } + task := ssl.SSLHost{ Host: entry[0], - Port: entry[1], + Port: derivePort(entry), } wg.Add(1) wp.Submit(func() { @@ -155,3 +162,10 @@ func dispatch(reader io.Reader) (chan ssl.CertificateStatusResult, error) { go cleanup() return results, nil } + +func main() { + if err := start(); err != nil { + fmt.Fprintf(os.Stderr, "%+v", err) + os.Exit(1) + } +} diff --git a/host.csv b/host.csv index f0a5bf2..9ffea67 100644 --- a/host.csv +++ b/host.csv @@ -1,5 +1,5 @@ amazon.com,443 -google.com,443 +google.com,443, cloudflare.com,443 microsoft.com,443 instagram.com,443 diff --git a/result.csv b/result.csv index 4f9bb00..6eb118d 100644 --- a/result.csv +++ b/result.csv @@ -1,11 +1,11 @@ -cloudflare.com,443,cloudflare.com,Valid,188,2023-05-04 23:59:59 +0000 UTC -instagram.com,443,*.instagram.com,Alert,9,2022-11-06 23:59:59 +0000 UTC -facebook.com,443,*.facebook.com,Alert,9,2022-11-06 23:59:59 +0000 UTC -google.com,443,*.google.com,Valid,51,2022-12-19 08:19:39 +0000 UTC -youtube.com,443,*.google.com,Valid,51,2022-12-19 08:19:39 +0000 UTC -stackoverflow.com,443,*.stackexchange.com,Valid,35,2022-12-03 13:06:49 +0000 UTC -microsoft.com,443,microsoft.com,Valid,351,2023-10-15 07:08:50 +0000 UTC -www.wayfair.com,443,wayfair.com,Valid,43,2022-12-10 23:59:59 +0000 UTC -stripe.com, 443,stripe.com,Valid,90,2023-01-26 23:59:59 +0000 UTC -expired.badssl.com,443,*.badssl.com,Expired,-2756,2015-04-12 23:59:59 +0000 UTC -amazon.com,443,*.peg.a2z.com,Valid,355,2023-10-18 23:59:59 +0000 UTC +facebook.com,443,*.facebook.com,Alert,8,2023-10-09 23:59:59 +0000 UTC +cloudflare.com,443,cloudflare.com,Alert,31,2023-11-01 23:59:59 +0000 UTC +instagram.com,443,*.instagram.com,Alert,8,2023-10-09 23:59:59 +0000 UTC +google.com,443,*.google.com,Warn,57,2023-11-27 08:17:05 +0000 UTC +stackoverflow.com,443,stackoverflow.com,Warn,77,2023-12-17 15:37:42 +0000 UTC +www.wayfair.com,443,wayfair.com,Alert,46,2023-11-16 12:22:08 +0000 UTC +youtube.com,443,*.google.com,Warn,57,2023-11-27 08:17:05 +0000 UTC +microsoft.com,443,microsoft.com,Valid,343,2024-09-08 21:39:33 +0000 UTC +stripe.com, 443,stripe.com,Alert,39,2023-11-09 23:59:59 +0000 UTC +expired.badssl.com,443,*.badssl.com,Expired,-3094,2015-04-12 23:59:59 +0000 UTC +amazon.com,443,*.peg.a2z.com,Valid,173,2024-03-22 23:59:59 +0000 UTC