Skip to content

Commit

Permalink
Merge pull request #3 from anandpaithankar/use_defaults
Browse files Browse the repository at this point in the history
Handle empty/missing port values
  • Loading branch information
anandpaithankar authored Oct 2, 2023
2 parents 00e9f69 + 4abc170 commit 8d5a1d7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/
**/bin/**
**/build/**
**/result.csv
Empty file modified build.sh
100644 → 100755
Empty file.
32 changes: 23 additions & 9 deletions cmd/mangobars/mangobars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion host.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
amazon.com,443
google.com,443
google.com,443,
cloudflare.com,443
microsoft.com,443
instagram.com,443
Expand Down
22 changes: 11 additions & 11 deletions result.csv
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8d5a1d7

Please # to comment.