2023-03-01 21:30:16 +00:00
|
|
|
package inspect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
"src.lwithers.me.uk/go/rsa/pkg/inspect"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
displayedFingerprints = map[string]int{}
|
|
|
|
)
|
|
|
|
|
2023-04-29 10:59:15 +01:00
|
|
|
func displayText(src string, info []inspect.Info) {
|
2023-03-01 21:30:16 +00:00
|
|
|
// compute max key length, for nicely aligning columns
|
|
|
|
var maxKey int
|
|
|
|
for _, item := range info {
|
|
|
|
for _, section := range item.Info() {
|
|
|
|
for _, field := range section.Fields {
|
|
|
|
l := utf8.RuneCountInString(field.Key)
|
|
|
|
if l > maxKey {
|
|
|
|
maxKey = l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// display loop
|
|
|
|
for _, item := range info {
|
|
|
|
fmt.Printf("════════ %s:%s ════════\n",
|
2023-04-29 10:59:15 +01:00
|
|
|
aura.BrightBlue(src), aura.Blue(item.Location()))
|
2023-03-01 21:30:16 +00:00
|
|
|
for _, section := range item.Info() {
|
2023-04-29 10:59:15 +01:00
|
|
|
fmt.Println(aura.Underline(section.Title))
|
2023-03-01 21:30:16 +00:00
|
|
|
for _, field := range section.Fields {
|
2023-04-29 10:59:15 +01:00
|
|
|
fmt.Printf(" %*s: ", maxKey, aura.Yellow(field.Key))
|
2023-03-01 21:30:16 +00:00
|
|
|
switch v := field.Value.(type) {
|
|
|
|
case int:
|
2023-04-29 10:59:15 +01:00
|
|
|
fmt.Print(aura.Blue(v))
|
2023-03-01 21:30:16 +00:00
|
|
|
|
|
|
|
case bool:
|
2023-04-29 10:59:15 +01:00
|
|
|
fmt.Print(aura.Blue(v))
|
2023-03-01 21:30:16 +00:00
|
|
|
|
|
|
|
case time.Time:
|
|
|
|
var note string
|
|
|
|
switch {
|
|
|
|
case strings.Contains(field.Key, "from"):
|
|
|
|
if v.After(time.Now()) {
|
2023-04-29 10:59:15 +01:00
|
|
|
note = aura.Red("not valid yet").String()
|
2023-03-01 21:30:16 +00:00
|
|
|
} else {
|
2023-04-29 10:59:15 +01:00
|
|
|
note = aura.Green("ok").String()
|
2023-03-01 21:30:16 +00:00
|
|
|
}
|
|
|
|
case strings.Contains(field.Key, "until"):
|
|
|
|
if v.After(time.Now()) {
|
2023-04-29 10:59:15 +01:00
|
|
|
note = aura.Green("ok").String()
|
2023-03-01 21:30:16 +00:00
|
|
|
} else {
|
2023-04-29 10:59:15 +01:00
|
|
|
note = aura.Red("expired").String()
|
2023-03-01 21:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%s %s", v.Format(time.RFC3339), note)
|
|
|
|
|
|
|
|
case []string:
|
|
|
|
for i, s := range v {
|
|
|
|
fmt.Print(s)
|
|
|
|
if i < len(v)-1 {
|
|
|
|
fmt.Printf("\n%*s", maxKey+4, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case inspect.Fingerprint:
|
|
|
|
f := v.String()
|
|
|
|
fidx := displayedFingerprints[f]
|
|
|
|
var firstSeen bool
|
|
|
|
if fidx == 0 {
|
|
|
|
firstSeen = true
|
|
|
|
fidx = 1 + len(displayedFingerprints)
|
|
|
|
displayedFingerprints[f] = fidx
|
|
|
|
}
|
|
|
|
|
|
|
|
var note string
|
|
|
|
if firstSeen {
|
2023-04-29 10:59:15 +01:00
|
|
|
note = fmt.Sprintf("#%d %s", aura.Blue(fidx),
|
|
|
|
aura.Magenta("first occurrence"))
|
2023-03-01 21:30:16 +00:00
|
|
|
} else {
|
2023-04-29 10:59:15 +01:00
|
|
|
note = fmt.Sprintf("#%d %s", aura.Blue(fidx),
|
|
|
|
aura.Green("already seen"))
|
2023-03-01 21:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%v [%s]", f, note)
|
|
|
|
|
|
|
|
default:
|
|
|
|
fmt.Print(v)
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
}
|
|
|
|
}
|