-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
92 lines (73 loc) · 3.16 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
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/madhuakula/hacked-emails/api"
"github.com/madhuakula/hacked-emails/version"
)
const (
// BANNER is what is printed for help/info output.
BANNER = `
██╗ ██╗ █████╗ ██████╗██╗ ██╗███████╗██████╗ ███████╗███╗ ███╗ █████╗ ██╗██╗ ███████╗
██║ ██║██╔══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗ ██╔════╝████╗ ████║██╔══██╗██║██║ ██╔════╝
███████║███████║██║ █████╔╝ █████╗ ██║ ██║█████╗█████╗ ██╔████╔██║███████║██║██║ ███████╗
██╔══██║██╔══██║██║ ██╔═██╗ ██╔══╝ ██║ ██║╚════╝██╔══╝ ██║╚██╔╝██║██╔══██║██║██║ ╚════██║
██║ ██║██║ ██║╚██████╗██║ ██╗███████╗██████╔╝ ███████╗██║ ╚═╝ ██║██║ ██║██║███████╗███████║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝
Hacked Emails Command Line Tool
Version: %s
`
)
var (
vrsn bool
)
func init() {
// parse flags
flag.BoolVar(&vrsn, "version", false, "print version and exit")
flag.BoolVar(&vrsn, "v", false, "print version and exit (shorthand)")
flag.Usage = func() {
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, version.VERSION))
flag.PrintDefaults()
}
flag.Parse()
if vrsn {
fmt.Printf("hacked-emails version %s", version.VERSION)
os.Exit(0)
}
if flag.NArg() < 1 {
usageAndExit("Pass an email address: email@domain.com", 1)
}
// parse the arg
arg := strings.Join(flag.Args(), " ")
if arg == "help" {
usageAndExit("", 0)
}
if arg == "version" {
fmt.Printf("hacked-emails version %s", version.VERSION)
os.Exit(0)
}
}
func main() {
email := strings.Join(flag.Args(), " ")
response, err := api.Check(email)
if err != nil {
fmt.Printf("Decoding api response as JSON failed: %v", err)
return
}
defResponse := fmt.Sprintf("%s email %s in %d results\n", response.Query, response.Status, response.Results)
for _, def := range response.Data {
defResponse += fmt.Sprintf("\n%s : Leaked Date (%s)\n <%s>\n", def.Title, def.Date_leaked, def.Details)
}
fmt.Println(defResponse)
}
func usageAndExit(message string, exitCode int) {
if message != "" {
fmt.Fprintf(os.Stderr, message)
fmt.Fprintf(os.Stderr, "\n\n")
}
flag.Usage()
fmt.Fprintf(os.Stderr, "\n")
os.Exit(exitCode)
}