-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
146 lines (119 loc) · 3.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"time"
)
const (
discordURL_BBP string = "BBP WEBHOOK URL"
discordURL_VDP string = "VDP WEBHOOK URL"
)
type companyChanges struct {
Name string
Type string
URL string
Changes []string
}
type webhookPayload struct {
Contents string `json:"content"`
}
func main() {
// create a directory for json files
createDirIfNotExist("platforms")
// compare bugcrowd changes
bugcrowdChanges := GetBugcrowdChanges("platforms/bugcrowd.json")
// send changes to the discord server
sendNotif(bugcrowdChanges)
// compare hackerone changes
hackeroneChanges := GetHackeroneChanges("platforms/hackerone.json")
// send changes to the discord server
sendNotif(hackeroneChanges)
// compare yeswehack changes
yeswehackChanges := GetYeswehackChanges("platforms/yeswehack.json")
// send changes to the discord server
sendNotif(yeswehackChanges)
// compare intigriti changes
intigritiChanges := GetIntigritiChanges("platforms/intigriti.json")
// send changes to the discord server
sendNotif(intigritiChanges)
//log this program's activity
healthCheck()
}
func createDirIfNotExist(path string) {
// check if directory already exists
if _, err := os.Stat(path); os.IsNotExist(err) {
// if directory doesn't exist, create it
err = os.MkdirAll(path, 0755)
checkError(err)
}
}
func sendNotif(changes []companyChanges) {
//beautify it for discord markdown
for _, company := range changes {
content := fmt.Sprintf(">>> **%v**\n**Type**: %v\n**URL**: <%v>\n**Assets**:\n```\n", company.Name, company.Type, company.URL)
for _, asset := range company.Changes {
content += asset + "\n"
}
content += "```"
postData, err := json.Marshal(webhookPayload{Contents: content})
checkError(err)
if company.Type == "vdp" {
http.Post(discordURL_VDP, "application/json", bytes.NewBuffer(postData))
} else {
http.Post(discordURL_BBP, "application/json", bytes.NewBuffer(postData))
}
}
}
func fileExists(path string) bool {
if _, err := os.Stat(path); err == nil {
return true
} else {
return false
}
}
func checkError(err error) {
if err != nil {
log.Panic(err)
}
}
func getReq(url string) []byte {
response, err := http.Get(url)
checkError(err)
defer response.Body.Close()
rawBody, err := ioutil.ReadAll(response.Body)
checkError(err)
return rawBody
}
func saveToFile(path string, content []byte) {
file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
checkError(err)
defer file.Close()
io.Copy(file, bytes.NewBuffer(content))
}
func loadFile(path string) []byte {
file, err := os.OpenFile(path, os.O_RDONLY, 0644)
checkError(err)
content, err := io.ReadAll(file)
checkError(err)
return content
}
func healthCheck() {
file, err := os.OpenFile("health_check", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
panic(err)
}
defer file.Close()
time := getCurrentTime()
file.WriteString(time + " working fine\n")
}
func getCurrentTime() string {
currentTime := time.Now()
formattedTime := fmt.Sprintf("%v/%v/%v %v:%v:%v", currentTime.Year(), int(currentTime.Month()), currentTime.Day(), currentTime.Hour(), currentTime.Minute(), currentTime.Second())
return formattedTime
}