Skip to content

Commit db4ef39

Browse files
authored
Merge pull request #167 from projectdiscovery/dev
v1.0.2
2 parents c9f7cc3 + 545350f commit db4ef39

File tree

25 files changed

+423
-86
lines changed

25 files changed

+423
-86
lines changed

.github/workflows/build-test.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: 🔨 Build Test
22
on:
3-
push:
43
pull_request:
54
workflow_dispatch:
65

@@ -24,4 +23,14 @@ jobs:
2423

2524
- name: Build
2625
run: go build .
27-
working-directory: cmd/notify/
26+
working-directory: cmd/notify/
27+
28+
- name: Integration Tests
29+
env:
30+
DISCORD_WEBHOOK_URL: "${{ secrets.DISCORD_WEBHOOK_URL }}"
31+
SLACK_WEBHOOK_URL: "${{ secrets.SLACK_WEBHOOK_URL }}"
32+
CUSTOM_WEBOOK_URL: "${{ secrets.CUSTOM_WEBOOK_URL }}"
33+
run: |
34+
chmod +x action-run.sh
35+
bash action-run.sh
36+
working-directory: cmd/integration-test/

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.18.3-alpine as build-env
1+
FROM golang:1.19.0-alpine as build-env
22
RUN go install -v github.com/projectdiscovery/notify/cmd/notify@latest
33

44
FROM alpine:latest

README.md

+28-16
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ Notify is a Go-based assistance package that enables you to stream the output of
3535
# Features
3636

3737
- Supports for Slack / Discord / Telegram
38-
- Supports for Pushover / Email / Teams
39-
- Supports for File / Pipe output
38+
- Supports for Pushover / Email
39+
- Supports for Microsoft Teams / Google Chat
40+
- Supports for File / Pipe input
4041
- Supports Line by Line / Bulk Post
4142
- Supports using Single / Multiple providers
4243
- Supports Custom Web-hooks
@@ -51,20 +52,23 @@ notify -h
5152

5253
This will display help for the tool. Here are all the switches it supports.
5354

54-
| Flag | Description | Example |
55-
|--------------------|----------------------------------------------------|------------------------------|
56-
| `-config` | Notify configuration file | `notify -config config.yaml` |
57-
| `-silent` | Don't print the banner | `notify -silent` |
58-
| `-version` | Show version of notify | `notify -version` |
59-
| `-v` | Show Verbose output | `notify -v` |
60-
| `-no-color` | Don't Use colors in output | `notify -nc` |
61-
| `-data` | File path to read data from | `notify -i test.txt` |
62-
| `-bulk` | Read and send data in bulk | `notify -bulk` |
63-
| `-char-limit` | Character limit for message (default 4000) | `notify -cl 2000` |
64-
| `-provider-config` | provider config path | `notify -pc provider.yaml` |
65-
| `-provider` | provider to send the notification to (optional) | `notify -p slack,telegram` |
66-
| `-id` | id to send the notification to (optional) | `notify -id recon,scans` |
67-
| `-rate-limit` | maximum number of HTTP requests to send per second | `notify -rl 1` |
55+
| Flag | Description | Example |
56+
|--------------------|----------------------------------------------------|---------------------------------------|
57+
| `-bulk` | enable bulk processing | `notify -bulk` |
58+
| `-char-limit` | max character limit per message (default 4000) | `notify -cl 2000` |
59+
| `-config` | notify configuration file | `notify -config config.yaml` |
60+
| `-data` | input file to send for notify | `notify -i test.txt` |
61+
| `-delay` | delay in seconds between each notification | `notify -d 2` |
62+
| `-id` | id to send the notification to (optional) | `notify -id recon,scans` |
63+
| `-msg-format` | add custom formatting to message | `notify -mf Hey {{data}}` |
64+
| `-no-color` | disable colors in output | `notify -nc` |
65+
| `-provider-config` | provider config path | `notify -pc provider.yaml` |
66+
| `-provider` | provider to send the notification to (optional) | `notify -p slack,telegram` |
67+
| `-proxy` | http proxy to use with notify | `notify -proxy http://127.0.0.1:8080` |
68+
| `-rate-limit` | maximum number of HTTP requests to send per second | `notify -rl 1` |
69+
| `-silent` | enable silent mode | `notify -silent` |
70+
| `-verbose` | enable verbose mode | `notify -version` |
71+
| `-version` | display version | `notify -version` |
6872

6973

7074
# Notify Installation
@@ -109,6 +113,7 @@ telegram:
109113
telegram_api_key: "XXXXXXXXXXXX"
110114
telegram_chat_id: "XXXXXXXX"
111115
telegram_format: "{{data}}"
116+
telegram_parsemode: "Markdown" # None/Markdown/MarkdownV2/HTML (https://core.telegram.org/bots/api#formatting-options)
112117

113118
pushover:
114119
- id: "push"
@@ -129,6 +134,13 @@ smtp:
129134
smtp_format: "{{data}}"
130135
subject: "Email subject"
131136

137+
googlechat:
138+
- id: "gc"
139+
key: "XXXXXXXX"
140+
token: "XXXXXX"
141+
space: "XXXXXX"
142+
google_chat_format: "{{data}}"
143+
132144
custom:
133145
- id: webhook
134146
custom_webook_url: http://host/api/webhook

cmd/integration-test/action-run.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
rm -f final-config.yaml temp.yaml
4+
( echo "cat <<EOF >final-config.yaml";
5+
cat test-config.yaml;
6+
echo "EOF";
7+
) >temp.yaml
8+
. temp.yaml
9+
rm integration-test notify 2>/dev/null
10+
11+
go build ../notify
12+
go build
13+
14+
DEBUG=true ./integration-test --provider-config final-config.yaml
15+
if [ $? -eq 0 ]
16+
then
17+
exit 0
18+
else
19+
exit 1
20+
fi

cmd/integration-test/integration.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
8+
"github.com/logrusorgru/aurora"
9+
"github.com/projectdiscovery/notify/internal/testutils"
10+
)
11+
12+
var (
13+
providerConfig = flag.String("provider-config", "", "provider config to use for testing")
14+
debug = os.Getenv("DEBUG") == "true"
15+
errored = false
16+
success = aurora.Green("[✓]").String()
17+
failed = aurora.Red("[✘]").String()
18+
testCases = map[string]testutils.TestCase{
19+
"discord": &discord{},
20+
"slack": &slack{},
21+
"custom": &custom{},
22+
// "telegram": &telegram{},
23+
// "teams": &teams{},
24+
// "smtp": &smtp{},
25+
// "pushover": &pushover{},
26+
}
27+
)
28+
29+
func main() {
30+
flag.Parse()
31+
32+
for name, test := range testCases {
33+
fmt.Printf("Running test cases for \"%s\"\n", aurora.Blue(name))
34+
err := test.Execute()
35+
if err != nil {
36+
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, name, err)
37+
errored = true
38+
} else {
39+
fmt.Printf("%s Test \"%s\" passed!\n", success, name)
40+
}
41+
}
42+
if errored {
43+
os.Exit(1)
44+
}
45+
}

cmd/integration-test/providers.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/projectdiscovery/notify/internal/testutils"
8+
)
9+
10+
func run(provider string) error {
11+
args := []string{"--provider", provider}
12+
if *providerConfig != "" {
13+
args = append(args, "--provider-config", *providerConfig)
14+
}
15+
results, err := testutils.RunNotifyAndGetResults(debug, args...)
16+
if err != nil {
17+
return err
18+
}
19+
if len(results) < 1 {
20+
return errIncorrectResultsCount(results)
21+
}
22+
for _, r := range results {
23+
if !strings.Contains(r, provider) {
24+
return fmt.Errorf("incorrect result %s", results[0])
25+
}
26+
}
27+
return nil
28+
}
29+
30+
type discord struct{}
31+
32+
func (h *discord) Execute() error {
33+
return run("discord")
34+
}
35+
36+
type custom struct{}
37+
38+
func (h *custom) Execute() error {
39+
return run("custom")
40+
}
41+
42+
type slack struct{}
43+
44+
func (h *slack) Execute() error {
45+
return run("slack")
46+
}
47+
48+
// type pushover struct{}
49+
//
50+
// func (h *pushover) Execute() error {
51+
// return run("pushover")
52+
// }
53+
//
54+
// type smtp struct{}
55+
//
56+
// func (h *smtp) Execute() error {
57+
// return run("smtp")
58+
// }
59+
//
60+
// type teams struct{}
61+
//
62+
// func (h *teams) Execute() error {
63+
// return run("teams")
64+
// }
65+
//
66+
// type telegram struct{}
67+
//
68+
// func (h *telegram) Execute() error {
69+
// return run("telegram")
70+
// }
71+
72+
func errIncorrectResultsCount(results []string) error {
73+
return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t"))
74+
}

cmd/integration-test/run.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
rm integration-test notify 2>/dev/null
4+
5+
go build ../notify
6+
go build
7+
8+
./integration-test
9+
if [ $? -eq 0 ]
10+
then
11+
exit 0
12+
else
13+
exit 1
14+
fi

cmd/integration-test/test-config.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
discord:
2+
- id: "disocord-integration-test"
3+
discord_webhook_url: "${DISCORD_WEBHOOK_URL}"
4+
discord_format: "{{data}}"
5+
slack:
6+
- id: "slack-integration-test"
7+
slack_channel: "random"
8+
slack_username: "test"
9+
slack_webhook_url: "${SLACK_WEBHOOK_URL}"
10+
slack_format: "{{data}}"
11+
telegram:
12+
- id: "telegram-integration-test"
13+
telegram_api_key: "${telegram_api_key}"
14+
telegram_chat_id: "${telegram_chat_id}"
15+
telegram_format: "{{data}}"
16+
custom:
17+
- id: "custom-integration-test"
18+
custom_webook_url: "${CUSTOM_WEBOOK_URL}"
19+
custom_method: POST
20+
custom_format: '{{data}}'
21+
custom_headers:
22+
Content-Type: application/json
23+
pushover:
24+
- id: "push"
25+
pushover_user_key: "${pushover_user_key}"
26+
pushover_api_token: "${pushover_api_token}"
27+
pushover_format: "{{data}}"
28+
pushover_devices:
29+
- "iphone"
30+
smtp:
31+
- id: email
32+
smtp_server: "${smtp_server}"
33+
smtp_username: "${smtp_username}"
34+
smtp_password: "${smtp_password}"
35+
from_address: "${smtp_from_address}"
36+
smtp_cc:
37+
- "${smtp_cc}"
38+
smtp_format: "{{data}}"
39+
teams:
40+
- id: teams-integration-test
41+
teams_webhook_url: "${teams_webhook_url}"
42+
teams_format: "{{data}}"

cmd/notify/notify.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ func readConfig() {
5252
set.StringVar(&cfgFile, "config", "", "notify configuration file")
5353
set.StringVarP(&options.ProviderConfig, "provider-config", "pc", "", "provider config path (default: $HOME/.config/notify/provider-config.yaml)")
5454
set.StringVarP(&options.Data, "data", "i", "", "input file to send for notify")
55-
set.NormalizedStringSliceVarP(&options.Providers, "provider", "p", []string{}, "provider to send the notification to (optional)")
56-
set.NormalizedStringSliceVar(&options.IDs, "id", []string{}, "id to send the notification to (optional)")
55+
set.StringSliceVarP(&options.Providers, "provider", "p", []string{}, "provider to send the notification to (optional)", goflags.NormalizedStringSliceOptions)
56+
set.StringSliceVar(&options.IDs, "id", []string{}, "id to send the notification to (optional)", goflags.NormalizedStringSliceOptions)
5757
set.IntVarP(&options.RateLimit, "rate-limit", "rl", 1, "maximum number of HTTP requests to send per second")
58+
set.IntVarP(&options.Delay, "delay", "d", 0, "delay in seconds between each notification")
5859
set.BoolVar(&options.Bulk, "bulk", false, "enable bulk processing")
5960
set.IntVarP(&options.CharLimit, "char-limit", "cl", 4000, "max character limit per message")
60-
set.StringVarP(&options.MessageFormat, "msg-format", "mf", "{{data}}", "add custom formatting to message")
61+
set.StringVarP(&options.MessageFormat, "msg-format", "mf", "", "add custom formatting to message")
6162
set.BoolVar(&options.Silent, "silent", false, "enable silent mode")
6263
set.BoolVarP(&options.Verbose, "verbose", "v", false, "enable verbose mode")
6364
set.BoolVar(&options.Version, "version", false, "display version")

go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ require (
66
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
77
github.com/containrrr/shoutrrr v0.4.5-0.20220522113502-c91dc3cf1279
88
github.com/json-iterator/go v1.1.12
9+
github.com/logrusorgru/aurora v2.0.3+incompatible
910
github.com/oriser/regroup v0.0.0-20210730155327-fca8d7531263
1011
github.com/pkg/errors v0.9.1
1112
github.com/projectdiscovery/fileutil v0.0.0-20220510111557-fba17e05663f
12-
github.com/projectdiscovery/goflags v0.0.7
13+
github.com/projectdiscovery/goflags v0.0.9
1314
github.com/projectdiscovery/gologger v1.1.4
15+
github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4
1416
go.uber.org/multierr v1.8.0
1517
go.uber.org/ratelimit v0.2.0
1618
gopkg.in/yaml.v2 v2.4.0
@@ -21,7 +23,6 @@ require (
2123
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
2224
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect
2325
github.com/fatih/color v1.10.0 // indirect
24-
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
2526
github.com/mattn/go-colorable v0.1.8 // indirect
2627
github.com/mattn/go-isatty v0.0.12 // indirect
2728
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -31,5 +32,5 @@ require (
3132
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
3233
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
3334
google.golang.org/protobuf v1.25.0 // indirect
34-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
35+
gopkg.in/yaml.v3 v3.0.1 // indirect
3536
)

0 commit comments

Comments
 (0)