From 76f59be5ede8333eabe263d2ce3036855546dbb9 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Tue, 6 Aug 2019 11:00:52 +0200 Subject: [PATCH] merge commandline tools --- cmd/{sendxmpp => fluxxmpp}/README.md | 103 +++++++++++++++--- cmd/{sendxmpp => fluxxmpp}/TODO.md | 11 +- cmd/{xmpp-check/main.go => fluxxmpp/check.go} | 15 +-- cmd/fluxxmpp/doc.go | 5 + cmd/{sendxmpp => fluxxmpp}/log.go | 0 cmd/fluxxmpp/main.go | 19 ++++ cmd/{sendxmpp/cmd.go => fluxxmpp/send.go} | 29 ++--- cmd/{sendxmpp/muc.go => fluxxmpp/xmppmuc.go} | 0 .../send.go => fluxxmpp/xmppsend.go} | 0 cmd/sendxmpp/doc.go | 6 - cmd/sendxmpp/main.go | 12 -- cmd/xmpp-check/README.md | 49 --------- cmd/xmpp-check/TODO.md | 3 - cmd/xmpp-check/doc.go | 6 - cmd/xmpp-check/log.go | 34 ------ 15 files changed, 140 insertions(+), 152 deletions(-) rename cmd/{sendxmpp => fluxxmpp}/README.md (53%) rename cmd/{sendxmpp => fluxxmpp}/TODO.md (72%) rename cmd/{xmpp-check/main.go => fluxxmpp/check.go} (61%) create mode 100644 cmd/fluxxmpp/doc.go rename cmd/{sendxmpp => fluxxmpp}/log.go (100%) create mode 100644 cmd/fluxxmpp/main.go rename cmd/{sendxmpp/cmd.go => fluxxmpp/send.go} (71%) rename cmd/{sendxmpp/muc.go => fluxxmpp/xmppmuc.go} (100%) rename cmd/{sendxmpp/send.go => fluxxmpp/xmppsend.go} (100%) delete mode 100644 cmd/sendxmpp/doc.go delete mode 100644 cmd/sendxmpp/main.go delete mode 100644 cmd/xmpp-check/README.md delete mode 100644 cmd/xmpp-check/TODO.md delete mode 100644 cmd/xmpp-check/doc.go delete mode 100644 cmd/xmpp-check/log.go diff --git a/cmd/sendxmpp/README.md b/cmd/fluxxmpp/README.md similarity index 53% rename from cmd/sendxmpp/README.md rename to cmd/fluxxmpp/README.md index aa5af53..534d571 100644 --- a/cmd/sendxmpp/README.md +++ b/cmd/fluxxmpp/README.md @@ -1,29 +1,68 @@ -# sendXMPP +# fluxxmpp -sendxmpp is a tool to send messages from command-line. +fluxxIO's xmpp comandline tool ## Installation -To install `sendxmpp` in your Go path: +To install `fluxxmpp` in your Go path: ``` -$ go get -u gosrc.io/xmpp/cmd/sendxmpp +$ go get -u gosrc.io/xmpp/cmd/fluxxmpp ``` ## Usage ``` -$ sendxmpp --help +$ fluxxmpp --help +fluxxIO's xmpp comandline tool + Usage: - sendxmpp [message] [flags] + fluxxmpp [command] + +Available Commands: + check is a command-line to check if you XMPP TLS certificate is valid and warn you before it expires + help Help about any command + send is a command-line tool to send to send XMPP messages to users + +Flags: + -h, --help help for fluxxmpp + +Use "fluxxmpp [command] --help" for more information about a command. +``` + +### check tls + +``` +$ fluxxmpp check --help +is a command-line to check if you XMPP TLS certificate is valid and warn you before it expires + +Usage: + fluxxmpp check [flags] Examples: -sendxmpp to@chat.sum7.eu "Hello World!" +fluxxmpp check chat.sum7.eu:5222 --domain meckerspace.de + +Flags: + -d, --domain string domain if host handle multiple domains + -h, --help help for check +``` + +### sending messages + +``` +$ fluxxmpp send --help +is a command-line tool to send to send XMPP messages to users + +Usage: + fluxxmpp send [message] [flags] + +Examples: +fluxxmpp send to@chat.sum7.eu "Hello World!" Flags: --addr string host[:port] --config string config file (default is ~/.config/fluxxmpp.yml) - -h, --help help for sendxmpp + -h, --help help for send --jid string using jid (required) -m, --muc recipient is a muc (join it before sending messages) --password string using password for your jid (required) @@ -32,9 +71,37 @@ Flags: ## Examples +### check tls + +If you server is on standard port and XMPP domains matches the hostname you can simply use: + +``` +$ fluxxmpp check chat.sum7.eu + info All checks passed + ⇢ address="chat.sum7.eu" domain="" + ⇢ main.go:43 main.runCheck + ⇢ 2019-07-16T22:01:39.765+02:00 +``` + +You can also pass the port and the XMPP domain if different from the server hostname: + +``` +$ fluxxmpp check chat.sum7.eu:5222 --domain meckerspace.de + info All checks passed + ⇢ address="chat.sum7.eu:5222" domain="meckerspace.de" + ⇢ main.go:43 main.runCheck + ⇢ 2019-07-16T22:01:33.270+02:00 +``` + +Error code will be non-zero in case of error. You can thus use it directly with your usual +monitoring scripts. + + +### sending messages + Message from arguments: ```bash -$ sendxmpp to@example.org "Hello World!" +$ fluxxmpp send to@example.org "Hello World!" info client connected ⇢ cmd.go:56 main.glob..func1.1 ⇢ 2019-07-17T23:42:43.310+02:00 @@ -46,7 +113,7 @@ $ sendxmpp to@example.org "Hello World!" Message from STDIN: ```bash -$ journalctl -f | sendxmpp to@example.org - +$ journalctl -f | fluxxmpp send to@example.org - info client connected ⇢ cmd.go:56 main.glob..func1.1 ⇢ 2019-07-17T23:40:03.177+02:00 @@ -64,7 +131,7 @@ $ journalctl -f | sendxmpp to@example.org - Multiple recipients: ```bash -$ sendxmpp to1@example.org,to2@example.org "Multiple recipient" +$ fluxxmpp send to1@example.org,to2@example.org "Multiple recipient" info client connected ⇢ cmd.go:56 main.glob..func1.1 ⇢ 2019-07-17T23:47:57.650+02:00 @@ -80,7 +147,7 @@ $ sendxmpp to1@example.org,to2@example.org "Multiple recipient" Send to MUC: ```bash -journalctl -f | sendxmpp testit@conference.chat.sum7.eu - --muc +journalctl -f | fluxxmpp send testit@conference.chat.sum7.eu - --muc info client connected ⇢ cmd.go:56 main.glob..func1.1 ⇢ 2019-07-17T23:52:56.269+02:00 @@ -95,9 +162,9 @@ journalctl -f | sendxmpp testit@conference.chat.sum7.eu - --muc ^C ``` -### Authentification +## Authentification -#### Configuration file +### Configuration file In `/etc/`, `~/.config` and `.` (here). You could create the file name `fluxxmpp` with you favorite file extenion (e.g. `toml`, `yml`). @@ -110,7 +177,7 @@ password = "secret" addr = "example.com:5222" ``` -#### Environment variables +### Environment variables ```bash export FLUXXMPP_JID='bot@example.org'; @@ -118,14 +185,14 @@ export FLUXXMPP_PASSWORD='secret'; export FLUXXMPP_ADDR='example.com:5222'; -sendxmpp to@example.org "Hello Welt"; +fluxxmpp send to@example.org "Hello Welt"; ``` -#### Parameters +### Parameters Warning: This should not be used for production systems, as all users on the system can read the running processes, and their parameters (and thus the password). ```bash -sendxmpp to@example.org "Hello World!" --jid bot@example.org --password secret --addr example.com:5222; +fluxxmpp send to@example.org "Hello World!" --jid bot@example.org --password secret --addr example.com:5222; ``` diff --git a/cmd/sendxmpp/TODO.md b/cmd/fluxxmpp/TODO.md similarity index 72% rename from cmd/sendxmpp/TODO.md rename to cmd/fluxxmpp/TODO.md index 0c2d030..61866f3 100644 --- a/cmd/sendxmpp/TODO.md +++ b/cmd/fluxxmpp/TODO.md @@ -1,11 +1,18 @@ # TODO -## Issues +## check +### Features + +- Use a config file to define the checks to perform as client on an XMPP server. + +## send + +### Issues - Remove global variable (like mucToleave) - Does not report error when trying to connect to a non open port (for example localhost with no server running). -## Features +### Features - configuration - allow unencrypted diff --git a/cmd/xmpp-check/main.go b/cmd/fluxxmpp/check.go similarity index 61% rename from cmd/xmpp-check/main.go rename to cmd/fluxxmpp/check.go index 88faa9b..9a27854 100644 --- a/cmd/xmpp-check/main.go +++ b/cmd/fluxxmpp/check.go @@ -6,15 +6,11 @@ import ( "gosrc.io/xmpp" ) -func main() { - log.AddHook(&hook{}) - cmd.Execute() -} - var domain = "" -var cmd = &cobra.Command{ - Use: "xmpp-check ", - Example: "xmpp-check chat.sum7.eu:5222 --domain meckerspace.de", +var cmdCheck = &cobra.Command{ + Use: "check ", + 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", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { runCheck(args[0], domain) @@ -22,7 +18,8 @@ var cmd = &cobra.Command{ } func init() { - cmd.Flags().StringVarP(&domain, "domain", "d", "", "domain if host handle multiple domains") + cmdRoot.AddCommand(cmdCheck) + cmdCheck.Flags().StringVarP(&domain, "domain", "d", "", "domain if host handle multiple domains") } func runCheck(address, domain string) { diff --git a/cmd/fluxxmpp/doc.go b/cmd/fluxxmpp/doc.go new file mode 100644 index 0000000..80cf4a8 --- /dev/null +++ b/cmd/fluxxmpp/doc.go @@ -0,0 +1,5 @@ +/* + +fluxxmpp: fluxxIO's xmpp comandline tool +*/ +package main diff --git a/cmd/sendxmpp/log.go b/cmd/fluxxmpp/log.go similarity index 100% rename from cmd/sendxmpp/log.go rename to cmd/fluxxmpp/log.go diff --git a/cmd/fluxxmpp/main.go b/cmd/fluxxmpp/main.go new file mode 100644 index 0000000..ee073f6 --- /dev/null +++ b/cmd/fluxxmpp/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "github.com/bdlm/log" + "github.com/spf13/cobra" +) + +// cmdRoot represents the base command when called without any subcommands +var cmdRoot = &cobra.Command{ + Use: "fluxxmpp", + Short: "fluxxIO's xmpp comandline tool", +} + +func main() { + log.AddHook(&hook{}) + if err := cmdRoot.Execute(); err != nil { + log.Fatal(err) + } +} diff --git a/cmd/sendxmpp/cmd.go b/cmd/fluxxmpp/send.go similarity index 71% rename from cmd/sendxmpp/cmd.go rename to cmd/fluxxmpp/send.go index b446f26..b730c05 100644 --- a/cmd/sendxmpp/cmd.go +++ b/cmd/fluxxmpp/send.go @@ -18,9 +18,10 @@ var configFile = "" // FIXME: Remove global variables var isMUCRecipient = false -var cmd = &cobra.Command{ - Use: "sendxmpp [message]", - Example: `sendxmpp to@chat.sum7.eu "Hello World!"`, +var cmdSend = &cobra.Command{ + Use: "send [message]", + Short: "is a command-line tool to send to send XMPP messages to users", + Example: `fluxxmpp send to@chat.sum7.eu "Hello World!"`, Args: cobra.ExactArgs(2), Run: sendxmpp, } @@ -95,23 +96,25 @@ func sendxmpp(cmd *cobra.Command, args []string) { } func init() { - cobra.OnInitialize(initConfig) - cmd.PersistentFlags().StringVar(&configFile, "config", "", "config file (default is ~/.config/fluxxmpp.yml)") + cmdRoot.AddCommand(cmdSend) - cmd.Flags().StringP("jid", "", "", "using jid (required)") - viper.BindPFlag("jid", cmd.Flags().Lookup("jid")) + cobra.OnInitialize(initConfigFile) + cmdSend.PersistentFlags().StringVar(&configFile, "config", "", "config file (default is ~/.config/fluxxmpp.yml)") - cmd.Flags().StringP("password", "", "", "using password for your jid (required)") - viper.BindPFlag("password", cmd.Flags().Lookup("password")) + cmdSend.Flags().StringP("jid", "", "", "using jid (required)") + viper.BindPFlag("jid", cmdSend.Flags().Lookup("jid")) - cmd.Flags().StringP("addr", "", "", "host[:port]") - viper.BindPFlag("addr", cmd.Flags().Lookup("addr")) + cmdSend.Flags().StringP("password", "", "", "using password for your jid (required)") + viper.BindPFlag("password", cmdSend.Flags().Lookup("password")) - cmd.Flags().BoolVarP(&isMUCRecipient, "muc", "m", false, "recipient is a muc (join it before sending messages)") + cmdSend.Flags().StringP("addr", "", "", "host[:port]") + viper.BindPFlag("addr", cmdSend.Flags().Lookup("addr")) + + cmdSend.Flags().BoolVarP(&isMUCRecipient, "muc", "m", false, "recipient is a muc (join it before sending messages)") } // initConfig reads in config file and ENV variables if set. -func initConfig() { +func initConfigFile() { if configFile != "" { viper.SetConfigFile(configFile) } diff --git a/cmd/sendxmpp/muc.go b/cmd/fluxxmpp/xmppmuc.go similarity index 100% rename from cmd/sendxmpp/muc.go rename to cmd/fluxxmpp/xmppmuc.go diff --git a/cmd/sendxmpp/send.go b/cmd/fluxxmpp/xmppsend.go similarity index 100% rename from cmd/sendxmpp/send.go rename to cmd/fluxxmpp/xmppsend.go diff --git a/cmd/sendxmpp/doc.go b/cmd/sendxmpp/doc.go deleted file mode 100644 index 46f9956..0000000 --- a/cmd/sendxmpp/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -/* - -sendxmpp is a command-line tool to send to send XMPP messages to users - -*/ -package main diff --git a/cmd/sendxmpp/main.go b/cmd/sendxmpp/main.go deleted file mode 100644 index f1773cf..0000000 --- a/cmd/sendxmpp/main.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "github.com/bdlm/log" -) - -func main() { - log.AddHook(&hook{}) - if err := cmd.Execute(); err != nil { - log.Fatal(err) - } -} diff --git a/cmd/xmpp-check/README.md b/cmd/xmpp-check/README.md deleted file mode 100644 index d943248..0000000 --- a/cmd/xmpp-check/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# XMPP Check - -XMPP check is a tool to check TLS certificate on a remote server. - -## Installation - -To install `xmpp-check` in your Go path: - -``` -$ go get -u gosrc.io/xmpp/cmd/xmpp-check -``` - -## Usage - -``` -$ xmpp-check --help -Usage: - xmpp-check [flags] - -Examples: -xmpp-check chat.sum7.eu:5222 --domain meckerspace.de - -Flags: - -d, --domain string domain if host handle multiple domains - -h, --help help for xmpp-check -``` - -If you server is on standard port and XMPP domains matches the hostname you can simply use: - -``` -$ xmpp-check chat.sum7.eu - info All checks passed - ⇢ address="chat.sum7.eu" domain="" - ⇢ main.go:43 main.runCheck - ⇢ 2019-07-16T22:01:39.765+02:00 -``` - -You can also pass the port and the XMPP domain if different from the server hostname: - -``` -$ xmpp-check chat.sum7.eu:5222 --domain meckerspace.de - info All checks passed - ⇢ address="chat.sum7.eu:5222" domain="meckerspace.de" - ⇢ main.go:43 main.runCheck - ⇢ 2019-07-16T22:01:33.270+02:00 -``` - -Error code will be non-zero in case of error. You can thus use it directly with your usual -monitoring scripts. diff --git a/cmd/xmpp-check/TODO.md b/cmd/xmpp-check/TODO.md deleted file mode 100644 index 682b4cb..0000000 --- a/cmd/xmpp-check/TODO.md +++ /dev/null @@ -1,3 +0,0 @@ -# TODO - -- Use a config file to define the checks to perform as client on an XMPP server. \ No newline at end of file diff --git a/cmd/xmpp-check/doc.go b/cmd/xmpp-check/doc.go deleted file mode 100644 index ba5b3e4..0000000 --- a/cmd/xmpp-check/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -/* - -xmpp-check is a command-line to check if you XMPP TLS certificate is valid and warn you before it expires. - -*/ -package main diff --git a/cmd/xmpp-check/log.go b/cmd/xmpp-check/log.go deleted file mode 100644 index eb67593..0000000 --- a/cmd/xmpp-check/log.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "os" - - "github.com/bdlm/log" - stdLogger "github.com/bdlm/std/logger" -) - -type hook struct{} - -func (h *hook) Fire(entry *log.Entry) error { - switch entry.Level { - case log.PanicLevel: - entry.Logger.Out = os.Stderr - case log.FatalLevel: - entry.Logger.Out = os.Stderr - case log.ErrorLevel: - entry.Logger.Out = os.Stderr - case log.WarnLevel: - entry.Logger.Out = os.Stdout - case log.InfoLevel: - entry.Logger.Out = os.Stdout - case log.DebugLevel: - entry.Logger.Out = os.Stdout - default: - } - - return nil -} - -func (h *hook) Levels() []stdLogger.Level { - return log.AllLevels -}