certchecker/cmd/main.go

53 lines
1 KiB
Go
Raw Normal View History

2024-07-25 17:03:53 +02:00
package main
import (
"doman/certchecker"
"bufio"
"flag"
"fmt"
"os"
"sync"
)
func main() {
notifyExpirationDays := *flag.Int("notify", 7, "Notify when the certificate expires in less than this number of days")
flag.Parse()
domains := flag.Args()
if len(domains) == 0 {
stat, _ := os.Stdin.Stat()
scanner := bufio.NewScanner(os.Stdin)
if (stat.Mode() & os.ModeCharDevice) == 0 {
for scanner.Scan() {
domains = append(domains, scanner.Text())
}
} else {
fmt.Println("Enter a domain to check:")
scanner.Scan()
domains = append(domains, scanner.Text())
}
err := scanner.Err()
if err != nil {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
}
var wg sync.WaitGroup
defer wg.Wait()
for _, domain := range domains {
wg.Add(1)
go func() {
err := certchecker.Check(domain, notifyExpirationDays)
if err != nil {
fmt.Printf("%s: %v\n", domain, err)
} else{
fmt.Printf("%s: OK\n", domain)
}
wg.Done()
} ()
}
}