Skip to content

Commit 5f88b1e

Browse files
authored
Merge pull request #95 from projectdiscovery/dev
v1.0.1 Release
2 parents 44ef7b0 + 1c88d3b commit 5f88b1e

File tree

12 files changed

+131
-78
lines changed

12 files changed

+131
-78
lines changed

.github/workflows/dockerhub-push.yml

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
name: 🌥 Docker Push
22

33
on:
4-
release:
5-
types: [published]
4+
workflow_run:
5+
workflows: ["🎉 Release Binary"]
6+
types:
7+
- completed
68
workflow_dispatch:
79

810
jobs:
911
docker:
1012
runs-on: ubuntu-latest
1113
steps:
12-
-
13-
name: Checkout
14+
- name: Git Checkout
1415
uses: actions/checkout@v2
15-
-
16-
name: Set up QEMU
16+
17+
- name: Get Github tag
18+
id: meta
19+
run: |
20+
echo "::set-output name=tag::$(curl --silent "https://api.github.com/repos/projectdiscovery/notify/releases/latest" | jq -r .tag_name)"
21+
- name: Set up QEMU
1722
uses: docker/setup-qemu-action@v1
18-
-
19-
name: Set up Docker Buildx
23+
24+
- name: Set up Docker Buildx
2025
uses: docker/setup-buildx-action@v1
21-
-
22-
name: Login to DockerHub
26+
27+
- name: Login to DockerHub
2328
uses: docker/login-action@v1
2429
with:
2530
username: ${{ secrets.DOCKER_USERNAME }}
2631
password: ${{ secrets.DOCKER_TOKEN }}
27-
-
28-
name: Build and push
32+
33+
- name: Build and push
2934
uses: docker/build-push-action@v2
3035
with:
3136
context: .
3237
platforms: linux/amd64,linux/arm64,linux/arm
3338
push: true
34-
tags: projectdiscovery/notify:latest
39+
tags: projectdiscovery/notify:latest,projectdiscovery/notify:${{ steps.meta.outputs.tag }}

.github/workflows/release-binary.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: "Set up Go"
1919
uses: actions/setup-go@v2
2020
with:
21-
go-version: 1.16
21+
go-version: 1.17
2222
-
2323
env:
2424
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.16.0-alpine as build-env
1+
FROM golang:1.17.3-alpine as build-env
22
RUN GO111MODULE=on go get -v github.com/projectdiscovery/notify/cmd/notify
33

44
FROM alpine:latest

README.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,26 @@ notify -h
5151

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

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 -no-color |
61-
| -data | File path to read data from | notify -data test.txt |
62-
| -bulk | Read and send data in bulk from file. | notify -bulk |
63-
| -char-limit | Character limit for message (default 4000) | notify -char-limit 2000 |
64-
| -provider-config | provider config path | notify -provider-config conf.yaml |
65-
| -provider | provider to send the notification to (optional) | notify -provider slack,telegram |
66-
| -id | id to send the notification to (optional) | notify -id recon,scans |
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 from file. | 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 |
6768

6869

6970
# Notify Installation
7071

7172
```sh
72-
GO111MODULE=on go get -v github.com/projectdiscovery/notify/cmd/notify
73+
go install -v github.com/projectdiscovery/notify/cmd/notify@latest
7374
```
7475

7576
### Provider Config

cmd/notify/notify.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,20 @@ func readConfig() {
4949
set := goflags.NewFlagSet()
5050
set.Marshal = true
5151
set.SetDescription(`Notify is a general notification tool`)
52-
set.StringVar(&cfgFile, "config", "", "Notify configuration file")
53-
set.BoolVar(&options.Silent, "silent", false, "Don't print the banner")
54-
set.BoolVar(&options.Version, "version", false, "Show version of notify")
55-
set.BoolVar(&options.Verbose, "v", false, "Show Verbose output")
56-
set.BoolVar(&options.NoColor, "no-color", false, "Don't Use colors in output")
57-
set.StringVar(&options.Data, "data", "", "File path to read data from")
58-
set.BoolVar(&options.Bulk, "bulk", false, "Read the input and send it in bulk, character limit can be set using char-limit flag")
59-
set.IntVar(&options.CharLimit, "char-limit", 4000, "Character limit for message")
60-
set.StringVar(&options.ProviderConfig, "provider-config", "", "provider config path (default: $HOME/.config/notify/provider-config.yaml)")
61-
set.NormalizedStringSliceVar(&options.Providers, "provider", []string{}, "provider to send the notification to (optional)")
52+
set.StringVar(&cfgFile, "config", "", "notify configuration file")
53+
set.StringVarP(&options.ProviderConfig, "provider-config", "pc", "", "provider config path (default: $HOME/.config/notify/provider-config.yaml)")
54+
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)")
6256
set.NormalizedStringSliceVar(&options.IDs, "id", []string{}, "id to send the notification to (optional)")
63-
set.StringVar(&options.MessageFormat, "msg-format", "{{data}}", "apply custom formatting to the text")
64-
set.StringVar(&options.Proxy, "proxy", "", "Set http proxy to be used by notify")
57+
set.IntVarP(&options.RateLimit, "rate-limit", "rl", 0, "maximum number of HTTP requests to send per second")
58+
set.BoolVar(&options.Bulk, "bulk", false, "enable bulk processing (supported with file input")
59+
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.BoolVar(&options.Silent, "silent", false, "enable silent mode")
62+
set.BoolVarP(&options.Verbose, "verbose", "v", false, "enable verbose mode")
63+
set.BoolVar(&options.Version, "version", false, "display version")
64+
set.BoolVarP(&options.NoColor, "no-color", "nc", false, "disable colors in output")
65+
set.StringVar(&options.Proxy, "proxy", "", "HTTP Proxy to use with notify")
6566

6667
_ = set.Parse()
6768

go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ require (
99
github.com/golang/protobuf v1.4.3 // indirect
1010
github.com/google/go-cmp v0.5.4 // indirect
1111
github.com/google/uuid v1.2.0 // indirect
12-
github.com/json-iterator/go v1.1.11
12+
github.com/json-iterator/go v1.1.12
1313
github.com/klauspost/compress v1.13.1 // indirect
1414
github.com/mattn/go-isatty v0.0.13 // indirect
1515
github.com/onsi/ginkgo v1.16.4 // indirect
1616
github.com/onsi/gomega v1.10.5 // indirect
17+
github.com/oriser/regroup v0.0.0-20210730155327-fca8d7531263
1718
github.com/pkg/errors v0.9.1
1819
github.com/projectdiscovery/goflags v0.0.7
1920
github.com/projectdiscovery/gologger v1.1.4
20-
github.com/projectdiscovery/retryablehttp-go v1.0.1
21-
go.uber.org/multierr v1.1.0
21+
go.uber.org/multierr v1.7.0
2222
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
2323
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
24+
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
2425
google.golang.org/protobuf v1.25.0 // indirect
2526
gopkg.in/yaml.v2 v2.4.0
2627
nhooyr.io/websocket v1.8.7 // indirect

go.sum

+12-7
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ github.com/jarcoal/httpmock v1.0.4/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT
123123
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
124124
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
125125
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
126-
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
127-
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
126+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
127+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
128128
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
129129
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
130130
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
@@ -173,8 +173,9 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
173173
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
174174
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
175175
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
176-
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
177176
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
177+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
178+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
178179
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
179180
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
180181
github.com/nxadm/tail v1.4.6/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
@@ -192,6 +193,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
192193
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
193194
github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
194195
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
196+
github.com/oriser/regroup v0.0.0-20210730155327-fca8d7531263 h1:Qd1Ml+uEhpesT8Og0ysEhu5+DGhbhW+qxjapH8t1Kvs=
197+
github.com/oriser/regroup v0.0.0-20210730155327-fca8d7531263/go.mod h1:odkMeLkWS8G6+WP2z3Pn2vkzhPSvBtFhAUYTKXAtZMQ=
195198
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
196199
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
197200
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -204,8 +207,6 @@ github.com/projectdiscovery/goflags v0.0.7 h1:aykmRkrOgDyRwcvGrK3qp+9aqcjGfAMs/+
204207
github.com/projectdiscovery/goflags v0.0.7/go.mod h1:Jjwsf4eEBPXDSQI2Y+6fd3dBumJv/J1U0nmpM+hy2YY=
205208
github.com/projectdiscovery/gologger v1.1.4 h1:qWxGUq7ukHWT849uGPkagPKF3yBPYAsTtMKunQ8O2VI=
206209
github.com/projectdiscovery/gologger v1.1.4/go.mod h1:Bhb6Bdx2PV1nMaFLoXNBmHIU85iROS9y1tBuv7T5pMY=
207-
github.com/projectdiscovery/retryablehttp-go v1.0.1 h1:V7wUvsZNq1Rcz7+IlcyoyQlNwshuwptuBVYWw9lx8RE=
208-
github.com/projectdiscovery/retryablehttp-go v1.0.1/go.mod h1:SrN6iLZilNG1X4neq1D+SBxoqfAF4nyzvmevkTkWsek=
209210
github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe h1:tQTgf5XLBgZbkJDPtnV3SfdP9tzz5ZWeDBwv8WhnH9Q=
210211
github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe/go.mod h1:oTRc18WBv9t6BpaN9XBY+QmG28PUpsyDzRht56Qf49I=
211212
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
@@ -246,6 +247,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
246247
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
247248
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
248249
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
250+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
249251
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
250252
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
251253
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
@@ -261,10 +263,12 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:
261263
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
262264
go.coder.com/go-tools v0.0.0-20190317003359-0c6a35b74a16/go.mod h1:iKV5yK9t+J5nG9O3uF6KYdPEz3dyfMyB15MN1rbQ8Qw=
263265
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
264-
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
265266
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
266-
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
267+
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
268+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
267269
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
270+
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
271+
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
268272
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
269273
golang.org/x/crypto v0.0.0-20180426230345-b49d69b5da94/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
270274
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -337,6 +341,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
337341
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
338342
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
339343
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
344+
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
340345
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
341346
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
342347
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

internal/runner/banner.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const banner = `
88
__ _ ___
99
___ ___ / /_(_) _/_ __
1010
/ _ \/ _ \/ __/ / _/ // /
11-
/_//_/\___/\__/_/_/ \_, / v1.0.0
11+
/_//_/\___/\__/_/_/ \_, / v1.0.1
1212
/___/
1313
`
1414

1515
// Version is the current version
16-
const Version = `1.0.0`
16+
const Version = `1.0.1`
1717

1818
// showBanner is used to show the banner to the user
1919
func showBanner() {

internal/runner/runner.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import (
99
"net/url"
1010
"os"
1111
"path"
12+
"time"
1213

1314
"github.com/containrrr/shoutrrr"
1415
"github.com/pkg/errors"
1516
"github.com/projectdiscovery/gologger"
1617
"github.com/projectdiscovery/notify/pkg/providers"
1718
"github.com/projectdiscovery/notify/pkg/types"
19+
"github.com/projectdiscovery/notify/pkg/utils"
1820
"gopkg.in/yaml.v2"
1921
)
2022

@@ -59,13 +61,13 @@ func NewRunner(options *types.Options) (*Runner, error) {
5961

6062
// Run polling and notification
6163
func (r *Runner) Run() error {
62-
64+
defaultTransport := http.DefaultTransport.(*http.Transport)
6365
if r.options.Proxy != "" {
6466
proxyurl, err := url.Parse(r.options.Proxy)
6567
if err != nil || proxyurl == nil {
6668
gologger.Warning().Msgf("supplied proxy '%s' is not valid", r.options.Proxy)
6769
} else {
68-
http.DefaultClient.Transport = &http.Transport{
70+
defaultTransport = &http.Transport{
6971
Proxy: http.ProxyURL(proxyurl),
7072
ForceAttemptHTTP2: true,
7173
TLSClientConfig: &tls.Config{
@@ -75,22 +77,25 @@ func (r *Runner) Run() error {
7577
}
7678
}
7779

80+
if r.options.RateLimit > 0 {
81+
http.DefaultClient.Transport = utils.NewThrottledTransport(time.Second, r.options.RateLimit, defaultTransport)
82+
}
83+
7884
var inFile *os.File
7985
var err error
8086

8187
switch {
88+
case r.options.Data != "":
89+
inFile, err = os.Open(r.options.Data)
90+
if err != nil {
91+
gologger.Fatal().Msgf("%s\n", err)
92+
}
8293
case hasStdin():
8394
if r.options.Bulk {
8495
gologger.Error().Msgf("bulk flag is not supported with stdin")
8596
os.Exit(1)
8697
}
8798
inFile = os.Stdin
88-
89-
case r.options.Data != "":
90-
inFile, err = os.Open(r.options.Data)
91-
if err != nil {
92-
gologger.Fatal().Msgf("%s\n", err)
93-
}
9499
default:
95100
return errors.New("notify works with stdin or file using -data flag")
96101
}

pkg/providers/discord/discord.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package discord
22

33
import (
44
"fmt"
5-
"strings"
65

76
"github.com/containrrr/shoutrrr"
87
"github.com/pkg/errors"
98
"github.com/projectdiscovery/gologger"
109
"github.com/projectdiscovery/notify/pkg/utils"
1110
"go.uber.org/multierr"
11+
"github.com/oriser/regroup"
1212
)
1313

1414
type Provider struct {
@@ -39,20 +39,22 @@ func (p *Provider) Send(message, CliFormat string) error {
3939

4040
for _, pr := range p.Discord {
4141
msg := utils.FormatMessage(message, utils.SelectFormat(CliFormat, pr.DiscordFormat))
42-
43-
discordTokens := strings.TrimPrefix(pr.DiscordWebHookURL, "https://discord.com/api/webhooks/")
44-
tokens := strings.Split(discordTokens, "/")
45-
if len(tokens) < 2 {
42+
43+
discordWebhookRegex := regroup.MustCompile(`(?P<scheme>https?):\/\/(?P<domain>(?:ptb\.|canary\.)?discord(?:app)?\.com)\/api(?:\/)?(?P<api_version>v\d{1,2})?\/webhooks\/(?P<webhook_identifier>\d{17,19})\/(?P<webhook_token>[\w\-]{68})`)
44+
matchedGroups, err := discordWebhookRegex.Groups(pr.DiscordWebHookURL)
45+
46+
if err != nil {
4647
err := fmt.Errorf("incorrect discord configuration for id: %s ", pr.ID)
4748
DiscordErr = multierr.Append(DiscordErr, err)
4849
continue
4950
}
50-
webhookID, token := tokens[0], tokens[1]
51-
url := fmt.Sprintf("discord://%s@%s?splitlines=no", token, webhookID)
52-
err := shoutrrr.Send(url, msg)
53-
if err != nil {
54-
err = errors.Wrap(err, fmt.Sprintf("failed to send discord notification for id: %s ", pr.ID))
55-
DiscordErr = multierr.Append(DiscordErr, err)
51+
52+
webhookID, webhookToken := matchedGroups["webhook_identifier"], matchedGroups["webhook_token"]
53+
url := fmt.Sprintf("discord://%s@%s?splitlines=no", webhookToken, webhookID)
54+
sendErr := shoutrrr.Send(url, msg)
55+
if sendErr != nil {
56+
sendErr = errors.Wrap(sendErr, fmt.Sprintf("failed to send discord notification for id: %s ", pr.ID))
57+
DiscordErr = multierr.Append(DiscordErr, sendErr)
5658
continue
5759
}
5860
gologger.Verbose().Msgf("discord notification sent for id: %s", pr.ID)

0 commit comments

Comments
 (0)