Skip to content

Commit

Permalink
Merge pull request #167 from projectdiscovery/dev
Browse files Browse the repository at this point in the history
v1.0.2
  • Loading branch information
ehsandeep authored Aug 24, 2022
2 parents c9f7cc3 + 545350f commit db4ef39
Show file tree
Hide file tree
Showing 25 changed files with 423 additions and 86 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: 🔨 Build Test
on:
push:
pull_request:
workflow_dispatch:

Expand All @@ -24,4 +23,14 @@ jobs:

- name: Build
run: go build .
working-directory: cmd/notify/
working-directory: cmd/notify/

- name: Integration Tests
env:
DISCORD_WEBHOOK_URL: "${{ secrets.DISCORD_WEBHOOK_URL }}"
SLACK_WEBHOOK_URL: "${{ secrets.SLACK_WEBHOOK_URL }}"
CUSTOM_WEBOOK_URL: "${{ secrets.CUSTOM_WEBOOK_URL }}"
run: |
chmod +x action-run.sh
bash action-run.sh
working-directory: cmd/integration-test/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18.3-alpine as build-env
FROM golang:1.19.0-alpine as build-env
RUN go install -v github.com/projectdiscovery/notify/cmd/notify@latest

FROM alpine:latest
Expand Down
44 changes: 28 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ Notify is a Go-based assistance package that enables you to stream the output of
# Features

- Supports for Slack / Discord / Telegram
- Supports for Pushover / Email / Teams
- Supports for File / Pipe output
- Supports for Pushover / Email
- Supports for Microsoft Teams / Google Chat
- Supports for File / Pipe input
- Supports Line by Line / Bulk Post
- Supports using Single / Multiple providers
- Supports Custom Web-hooks
Expand All @@ -51,20 +52,23 @@ notify -h

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

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


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

pushover:
- id: "push"
Expand All @@ -129,6 +134,13 @@ smtp:
smtp_format: "{{data}}"
subject: "Email subject"

googlechat:
- id: "gc"
key: "XXXXXXXX"
token: "XXXXXX"
space: "XXXXXX"
google_chat_format: "{{data}}"

custom:
- id: webhook
custom_webook_url: http://host/api/webhook
Expand Down
20 changes: 20 additions & 0 deletions cmd/integration-test/action-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

rm -f final-config.yaml temp.yaml
( echo "cat <<EOF >final-config.yaml";
cat test-config.yaml;
echo "EOF";
) >temp.yaml
. temp.yaml
rm integration-test notify 2>/dev/null

go build ../notify
go build

DEBUG=true ./integration-test --provider-config final-config.yaml
if [ $? -eq 0 ]
then
exit 0
else
exit 1
fi
45 changes: 45 additions & 0 deletions cmd/integration-test/integration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/logrusorgru/aurora"
"github.com/projectdiscovery/notify/internal/testutils"
)

var (
providerConfig = flag.String("provider-config", "", "provider config to use for testing")
debug = os.Getenv("DEBUG") == "true"
errored = false
success = aurora.Green("[✓]").String()
failed = aurora.Red("[✘]").String()
testCases = map[string]testutils.TestCase{
"discord": &discord{},
"slack": &slack{},
"custom": &custom{},
// "telegram": &telegram{},
// "teams": &teams{},
// "smtp": &smtp{},
// "pushover": &pushover{},
}
)

func main() {
flag.Parse()

for name, test := range testCases {
fmt.Printf("Running test cases for \"%s\"\n", aurora.Blue(name))
err := test.Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, name, err)
errored = true
} else {
fmt.Printf("%s Test \"%s\" passed!\n", success, name)
}
}
if errored {
os.Exit(1)
}
}
74 changes: 74 additions & 0 deletions cmd/integration-test/providers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"fmt"
"strings"

"github.com/projectdiscovery/notify/internal/testutils"
)

func run(provider string) error {
args := []string{"--provider", provider}
if *providerConfig != "" {
args = append(args, "--provider-config", *providerConfig)
}
results, err := testutils.RunNotifyAndGetResults(debug, args...)
if err != nil {
return err
}
if len(results) < 1 {
return errIncorrectResultsCount(results)
}
for _, r := range results {
if !strings.Contains(r, provider) {
return fmt.Errorf("incorrect result %s", results[0])
}
}
return nil
}

type discord struct{}

func (h *discord) Execute() error {
return run("discord")
}

type custom struct{}

func (h *custom) Execute() error {
return run("custom")
}

type slack struct{}

func (h *slack) Execute() error {
return run("slack")
}

// type pushover struct{}
//
// func (h *pushover) Execute() error {
// return run("pushover")
// }
//
// type smtp struct{}
//
// func (h *smtp) Execute() error {
// return run("smtp")
// }
//
// type teams struct{}
//
// func (h *teams) Execute() error {
// return run("teams")
// }
//
// type telegram struct{}
//
// func (h *telegram) Execute() error {
// return run("telegram")
// }

func errIncorrectResultsCount(results []string) error {
return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t"))
}
14 changes: 14 additions & 0 deletions cmd/integration-test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

rm integration-test notify 2>/dev/null

go build ../notify
go build

./integration-test
if [ $? -eq 0 ]
then
exit 0
else
exit 1
fi
42 changes: 42 additions & 0 deletions cmd/integration-test/test-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
discord:
- id: "disocord-integration-test"
discord_webhook_url: "${DISCORD_WEBHOOK_URL}"
discord_format: "{{data}}"
slack:
- id: "slack-integration-test"
slack_channel: "random"
slack_username: "test"
slack_webhook_url: "${SLACK_WEBHOOK_URL}"
slack_format: "{{data}}"
telegram:
- id: "telegram-integration-test"
telegram_api_key: "${telegram_api_key}"
telegram_chat_id: "${telegram_chat_id}"
telegram_format: "{{data}}"
custom:
- id: "custom-integration-test"
custom_webook_url: "${CUSTOM_WEBOOK_URL}"
custom_method: POST
custom_format: '{{data}}'
custom_headers:
Content-Type: application/json
pushover:
- id: "push"
pushover_user_key: "${pushover_user_key}"
pushover_api_token: "${pushover_api_token}"
pushover_format: "{{data}}"
pushover_devices:
- "iphone"
smtp:
- id: email
smtp_server: "${smtp_server}"
smtp_username: "${smtp_username}"
smtp_password: "${smtp_password}"
from_address: "${smtp_from_address}"
smtp_cc:
- "${smtp_cc}"
smtp_format: "{{data}}"
teams:
- id: teams-integration-test
teams_webhook_url: "${teams_webhook_url}"
teams_format: "{{data}}"
7 changes: 4 additions & 3 deletions cmd/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ func readConfig() {
set.StringVar(&cfgFile, "config", "", "notify configuration file")
set.StringVarP(&options.ProviderConfig, "provider-config", "pc", "", "provider config path (default: $HOME/.config/notify/provider-config.yaml)")
set.StringVarP(&options.Data, "data", "i", "", "input file to send for notify")
set.NormalizedStringSliceVarP(&options.Providers, "provider", "p", []string{}, "provider to send the notification to (optional)")
set.NormalizedStringSliceVar(&options.IDs, "id", []string{}, "id to send the notification to (optional)")
set.StringSliceVarP(&options.Providers, "provider", "p", []string{}, "provider to send the notification to (optional)", goflags.NormalizedStringSliceOptions)
set.StringSliceVar(&options.IDs, "id", []string{}, "id to send the notification to (optional)", goflags.NormalizedStringSliceOptions)
set.IntVarP(&options.RateLimit, "rate-limit", "rl", 1, "maximum number of HTTP requests to send per second")
set.IntVarP(&options.Delay, "delay", "d", 0, "delay in seconds between each notification")
set.BoolVar(&options.Bulk, "bulk", false, "enable bulk processing")
set.IntVarP(&options.CharLimit, "char-limit", "cl", 4000, "max character limit per message")
set.StringVarP(&options.MessageFormat, "msg-format", "mf", "{{data}}", "add custom formatting to message")
set.StringVarP(&options.MessageFormat, "msg-format", "mf", "", "add custom formatting to message")
set.BoolVar(&options.Silent, "silent", false, "enable silent mode")
set.BoolVarP(&options.Verbose, "verbose", "v", false, "enable verbose mode")
set.BoolVar(&options.Version, "version", false, "display version")
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ require (
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/containrrr/shoutrrr v0.4.5-0.20220522113502-c91dc3cf1279
github.com/json-iterator/go v1.1.12
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/oriser/regroup v0.0.0-20210730155327-fca8d7531263
github.com/pkg/errors v0.9.1
github.com/projectdiscovery/fileutil v0.0.0-20220510111557-fba17e05663f
github.com/projectdiscovery/goflags v0.0.7
github.com/projectdiscovery/goflags v0.0.9
github.com/projectdiscovery/gologger v1.1.4
github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4
go.uber.org/multierr v1.8.0
go.uber.org/ratelimit v0.2.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -21,7 +23,6 @@ require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -31,5 +32,5 @@ require (
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit db4ef39

Please sign in to comment.