merge commandline tools

This commit is contained in:
Martin/Geno 2019-08-06 11:00:52 +02:00 committed by Mickaël Rémond
parent 80d2e0fa1e
commit 76f59be5ed
15 changed files with 140 additions and 152 deletions

View File

@ -1,29 +1,68 @@
# sendXMPP # fluxxmpp
sendxmpp is a tool to send messages from command-line. fluxxIO's xmpp comandline tool
## Installation ## 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 ## Usage
``` ```
$ sendxmpp --help $ fluxxmpp --help
fluxxIO's xmpp comandline tool
Usage: Usage:
sendxmpp <recipient,> [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 <host[:port]> [flags]
Examples: 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 <recipient,> [message] [flags]
Examples:
fluxxmpp send to@chat.sum7.eu "Hello World!"
Flags: Flags:
--addr string host[:port] --addr string host[:port]
--config string config file (default is ~/.config/fluxxmpp.yml) --config string config file (default is ~/.config/fluxxmpp.yml)
-h, --help help for sendxmpp -h, --help help for send
--jid string using jid (required) --jid string using jid (required)
-m, --muc recipient is a muc (join it before sending messages) -m, --muc recipient is a muc (join it before sending messages)
--password string using password for your jid (required) --password string using password for your jid (required)
@ -32,9 +71,37 @@ Flags:
## Examples ## 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: Message from arguments:
```bash ```bash
$ sendxmpp to@example.org "Hello World!" $ fluxxmpp send to@example.org "Hello World!"
info client connected info client connected
⇢ cmd.go:56 main.glob..func1.1 ⇢ cmd.go:56 main.glob..func1.1
⇢ 2019-07-17T23:42:43.310+02:00 ⇢ 2019-07-17T23:42:43.310+02:00
@ -46,7 +113,7 @@ $ sendxmpp to@example.org "Hello World!"
Message from STDIN: Message from STDIN:
```bash ```bash
$ journalctl -f | sendxmpp to@example.org - $ journalctl -f | fluxxmpp send to@example.org -
info client connected info client connected
⇢ cmd.go:56 main.glob..func1.1 ⇢ cmd.go:56 main.glob..func1.1
⇢ 2019-07-17T23:40:03.177+02:00 ⇢ 2019-07-17T23:40:03.177+02:00
@ -64,7 +131,7 @@ $ journalctl -f | sendxmpp to@example.org -
Multiple recipients: Multiple recipients:
```bash ```bash
$ sendxmpp to1@example.org,to2@example.org "Multiple recipient" $ fluxxmpp send to1@example.org,to2@example.org "Multiple recipient"
info client connected info client connected
⇢ cmd.go:56 main.glob..func1.1 ⇢ cmd.go:56 main.glob..func1.1
⇢ 2019-07-17T23:47:57.650+02:00 ⇢ 2019-07-17T23:47:57.650+02:00
@ -80,7 +147,7 @@ $ sendxmpp to1@example.org,to2@example.org "Multiple recipient"
Send to MUC: Send to MUC:
```bash ```bash
journalctl -f | sendxmpp testit@conference.chat.sum7.eu - --muc journalctl -f | fluxxmpp send testit@conference.chat.sum7.eu - --muc
info client connected info client connected
⇢ cmd.go:56 main.glob..func1.1 ⇢ cmd.go:56 main.glob..func1.1
⇢ 2019-07-17T23:52:56.269+02:00 ⇢ 2019-07-17T23:52:56.269+02:00
@ -95,9 +162,9 @@ journalctl -f | sendxmpp testit@conference.chat.sum7.eu - --muc
^C ^C
``` ```
### Authentification ## Authentification
#### Configuration file ### Configuration file
In `/etc/`, `~/.config` and `.` (here). In `/etc/`, `~/.config` and `.` (here).
You could create the file name `fluxxmpp` with you favorite file extenion (e.g. `toml`, `yml`). 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" addr = "example.com:5222"
``` ```
#### Environment variables ### Environment variables
```bash ```bash
export FLUXXMPP_JID='bot@example.org'; export FLUXXMPP_JID='bot@example.org';
@ -118,14 +185,14 @@ export FLUXXMPP_PASSWORD='secret';
export FLUXXMPP_ADDR='example.com:5222'; 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 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). can read the running processes, and their parameters (and thus the password).
```bash ```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;
``` ```

View File

@ -1,11 +1,18 @@
# TODO # 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) - 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). - Does not report error when trying to connect to a non open port (for example localhost with no server running).
## Features ### Features
- configuration - configuration
- allow unencrypted - allow unencrypted

View File

@ -6,15 +6,11 @@ import (
"gosrc.io/xmpp" "gosrc.io/xmpp"
) )
func main() {
log.AddHook(&hook{})
cmd.Execute()
}
var domain = "" var domain = ""
var cmd = &cobra.Command{ var cmdCheck = &cobra.Command{
Use: "xmpp-check <host[:port]>", Use: "check <host[:port]>",
Example: "xmpp-check chat.sum7.eu:5222 --domain meckerspace.de", 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), Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
runCheck(args[0], domain) runCheck(args[0], domain)
@ -22,7 +18,8 @@ var cmd = &cobra.Command{
} }
func init() { 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) { func runCheck(address, domain string) {

5
cmd/fluxxmpp/doc.go Normal file
View File

@ -0,0 +1,5 @@
/*
fluxxmpp: fluxxIO's xmpp comandline tool
*/
package main

19
cmd/fluxxmpp/main.go Normal file
View File

@ -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)
}
}

View File

@ -18,9 +18,10 @@ var configFile = ""
// FIXME: Remove global variables // FIXME: Remove global variables
var isMUCRecipient = false var isMUCRecipient = false
var cmd = &cobra.Command{ var cmdSend = &cobra.Command{
Use: "sendxmpp <recipient,> [message]", Use: "send <recipient,> [message]",
Example: `sendxmpp to@chat.sum7.eu "Hello World!"`, 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), Args: cobra.ExactArgs(2),
Run: sendxmpp, Run: sendxmpp,
} }
@ -95,23 +96,25 @@ func sendxmpp(cmd *cobra.Command, args []string) {
} }
func init() { func init() {
cobra.OnInitialize(initConfig) cmdRoot.AddCommand(cmdSend)
cmd.PersistentFlags().StringVar(&configFile, "config", "", "config file (default is ~/.config/fluxxmpp.yml)")
cmd.Flags().StringP("jid", "", "", "using jid (required)") cobra.OnInitialize(initConfigFile)
viper.BindPFlag("jid", cmd.Flags().Lookup("jid")) cmdSend.PersistentFlags().StringVar(&configFile, "config", "", "config file (default is ~/.config/fluxxmpp.yml)")
cmd.Flags().StringP("password", "", "", "using password for your jid (required)") cmdSend.Flags().StringP("jid", "", "", "using jid (required)")
viper.BindPFlag("password", cmd.Flags().Lookup("password")) viper.BindPFlag("jid", cmdSend.Flags().Lookup("jid"))
cmd.Flags().StringP("addr", "", "", "host[:port]") cmdSend.Flags().StringP("password", "", "", "using password for your jid (required)")
viper.BindPFlag("addr", cmd.Flags().Lookup("addr")) 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. // initConfig reads in config file and ENV variables if set.
func initConfig() { func initConfigFile() {
if configFile != "" { if configFile != "" {
viper.SetConfigFile(configFile) viper.SetConfigFile(configFile)
} }

View File

@ -1,6 +0,0 @@
/*
sendxmpp is a command-line tool to send to send XMPP messages to users
*/
package main

View File

@ -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)
}
}

View File

@ -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 <host[:port]> [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.

View File

@ -1,3 +0,0 @@
# TODO
- Use a config file to define the checks to perform as client on an XMPP server.

View File

@ -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

View File

@ -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
}