Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alpkeskin
GitHub Repository: alpkeskin/mosint
Path: blob/master/v3/internal/output/output.go
689 views
1
/*
2
Copyright © 2023 github.com/alpkeskin
3
*/
4
package output
5
6
import (
7
"encoding/json"
8
"os"
9
10
"github.com/alpkeskin/mosint/v3/internal/runner"
11
"github.com/alpkeskin/mosint/v3/internal/spinner"
12
"github.com/alpkeskin/mosint/v3/pkg/dns"
13
"github.com/alpkeskin/mosint/v3/pkg/services/breachdirectory"
14
"github.com/alpkeskin/mosint/v3/pkg/services/emailrep"
15
"github.com/alpkeskin/mosint/v3/pkg/services/haveibeenpwned"
16
"github.com/alpkeskin/mosint/v3/pkg/services/hunter"
17
"github.com/alpkeskin/mosint/v3/pkg/services/ipapi"
18
)
19
20
type Output struct {
21
FilePath string
22
}
23
24
func New() *Output {
25
return &Output{}
26
}
27
28
type jsonOutput struct {
29
Email string `json:"email"`
30
Verified bool `json:"verified"`
31
32
EmailRep emailrep.EmailRepResponse `json:"emailrep"`
33
BreachDirectory breachdirectory.BreachDirectoryResponse `json:"breachdirectory"`
34
HaveIBeenPwned haveibeenpwned.HaveIBeenPwnedResponse `json:"haveibeenpwned"`
35
Hunter hunter.HunterResponse `json:"hunter"`
36
IpApi ipapi.IpApiResponse `json:"ipapi"`
37
IntelX []string `json:"intelx"`
38
PsbDmp []string `json:"psbdmp"`
39
InstagramExists bool `json:"instagram_exists"`
40
SpotifyExists bool `json:"spotify_exists"`
41
TwitterExists bool `json:"twitter_exists"`
42
GoogleSearch []string `json:"google_search"`
43
DnsRecords []dns.Record `json:"dns_records"`
44
}
45
46
func (o *Output) SetFilePath(filePath string) {
47
o.FilePath = filePath
48
}
49
50
func (o *Output) JSON(runner *runner.Runner) {
51
spinner := spinner.New("JSON Output")
52
spinner.Start()
53
54
data := jsonOutput{
55
Email: runner.Email,
56
Verified: true,
57
EmailRep: runner.EmailRepC.Response,
58
BreachDirectory: runner.BreachDirectoryC.Response,
59
HaveIBeenPwned: runner.HaveibeenpwnedC.Response,
60
Hunter: runner.HunterC.Response,
61
IpApi: runner.IpApiC.Response,
62
IntelX: runner.IntelxC.Response,
63
PsbDmp: runner.PsbdmpC.Urls,
64
InstagramExists: runner.InstagramC.Exists,
65
SpotifyExists: runner.SpotifyC.Exists,
66
TwitterExists: runner.TwitterC.Exists,
67
GoogleSearch: runner.GoogleSearchC.Response,
68
DnsRecords: runner.DnsC.Records,
69
}
70
71
file, err := json.MarshalIndent(data, "", " ")
72
73
if err != nil {
74
spinner.StopFail()
75
spinner.SetMessage(err.Error())
76
return
77
}
78
79
err = os.WriteFile(o.FilePath, file, 0644)
80
81
if err != nil {
82
spinner.StopFail()
83
spinner.SetMessage(err.Error())
84
return
85
}
86
87
spinner.Stop()
88
}
89
90