2019-07-16 20:03:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bdlm/log"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"gosrc.io/xmpp"
|
|
|
|
)
|
|
|
|
|
|
|
|
var domain = ""
|
2019-08-06 09:00:52 +00:00
|
|
|
var cmdCheck = &cobra.Command{
|
|
|
|
Use: "check <host[:port]>",
|
|
|
|
Short: "is a command-line to check if you XMPP TLS certificate is valid and warn you before it expires",
|
|
|
|
Example: "fluxxmpp check chat.sum7.eu:5222 --domain meckerspace.de",
|
2019-07-16 20:03:26 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
runCheck(args[0], domain)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2019-08-06 09:00:52 +00:00
|
|
|
cmdRoot.AddCommand(cmdCheck)
|
|
|
|
cmdCheck.Flags().StringVarP(&domain, "domain", "d", "", "domain if host handle multiple domains")
|
2019-07-16 20:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func runCheck(address, domain string) {
|
|
|
|
logger := log.WithFields(map[string]interface{}{
|
|
|
|
"address": address,
|
|
|
|
"domain": domain,
|
|
|
|
})
|
|
|
|
client, err := xmpp.NewChecker(address, domain)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = client.Check(); err != nil {
|
|
|
|
logger.Fatal("Failed connection check: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Println("All checks passed")
|
|
|
|
}
|