Skip to content

Commit

Permalink
feat: add description func to scanner interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sundowndev committed Sep 4, 2022
1 parent 2dd7657 commit 1d0971e
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 5 deletions.
49 changes: 49 additions & 0 deletions cmd/scanners.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
"github.com/sundowndev/phoneinfoga/v2/lib/filter"
"github.com/sundowndev/phoneinfoga/v2/lib/remote"
)

type ScannersCmdOptions struct {
Plugin []string
}

func init() {
opts := &ScannersCmdOptions{}
scannersCmd := NewScannersCmd(opts)

fl := scannersCmd.Flags()
fl.StringSliceVar(&opts.Plugin, "plugin", []string{}, "Output file")

rootCmd.AddCommand(scannersCmd)
}

func NewScannersCmd(opts *ScannersCmdOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "scanners",
Example: "phoneinfoga scanners",
Short: "Display list of loaded scanners",
Run: func(cmd *cobra.Command, args []string) {
for _, p := range opts.Plugin {
err := remote.OpenPlugin(p)
if err != nil {
exitWithError(err)
}
}

remoteLibrary := remote.NewLibrary(filter.NewEngine())
remote.InitScanners(remoteLibrary)

for i, s := range remoteLibrary.GetAllScanners() {
fmt.Printf("%s\n%s\n", s.Name(), s.Description())
if i < len(remoteLibrary.GetAllScanners()) {
fmt.Printf("\n")
}
}
},
}
return cmd
}
5 changes: 5 additions & 0 deletions examples/plugin/customscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func (s *customScanner) Name() string {
return "customscanner"
}

// Description returns a short description for this scanner.
func (s *customScanner) Description() string {
return "This is a dummy scanner"
}

// ShouldRun returns a boolean indicating whether
// this scanner should be used or not.
// This can be useful to check for authentication or
Expand Down
4 changes: 4 additions & 0 deletions lib/remote/googlecse_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (s *googleCSEScanner) Name() string {
return GoogleCSE
}

func (s *googleCSEScanner) Description() string {
return "Googlecse searches for footprints of a given phone number on the web using Google Custom Search Engine."
}

func (s *googleCSEScanner) ShouldRun(_ number.Number) bool {
if s.Cx == "" || s.ApiKey == "" {
return false
Expand Down
6 changes: 5 additions & 1 deletion lib/remote/googlesearch_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ type GoogleSearchResponse struct {
General []*GoogleSearchDork `json:"general" console:"General,omitempty"`
}

func NewGoogleSearchScanner() *googlesearchScanner {
func NewGoogleSearchScanner() Scanner {
return &googlesearchScanner{}
}

func (s *googlesearchScanner) Name() string {
return Googlesearch
}

func (s *googlesearchScanner) Description() string {
return "Generate several Google dork requests for a given phone number."
}

func (s *googlesearchScanner) ShouldRun(_ number.Number) bool {
return true
}
Expand Down
6 changes: 5 additions & 1 deletion lib/remote/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ type LocalScannerResponse struct {
Carrier string `json:"carrier,omitempty" console:"Carrier,omitempty"`
}

func NewLocalScanner() *localScanner {
func NewLocalScanner() Scanner {
return &localScanner{}
}

func (s *localScanner) Name() string {
return Local
}

func (s *localScanner) Description() string {
return "Gather offline info about a given phone number."
}

func (s *localScanner) ShouldRun(_ number.Number) bool {
return true
}
Expand Down
6 changes: 5 additions & 1 deletion lib/remote/numverify_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ type NumverifyScannerResponse struct {
LineType string `json:"line_type" console:"Line type"`
}

func NewNumverifyScanner(s suppliers.NumverifySupplierInterface) *numverifyScanner {
func NewNumverifyScanner(s suppliers.NumverifySupplierInterface) Scanner {
return &numverifyScanner{client: s}
}

func (s *numverifyScanner) Name() string {
return Numverify
}

func (s *numverifyScanner) Description() string {
return "Request info about a given phone number through the Numverify API."
}

func (s *numverifyScanner) ShouldRun(_ number.Number) bool {
return s.client.IsAvailable()
}
Expand Down
6 changes: 5 additions & 1 deletion lib/remote/ovh_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ type OVHScannerResponse struct {
ZipCode string `json:"zip_code,omitempty" console:"Zip code,omitempty"`
}

func NewOVHScanner(s suppliers.OVHSupplierInterface) *ovhScanner {
func NewOVHScanner(s suppliers.OVHSupplierInterface) Scanner {
return &ovhScanner{client: s}
}

func (s *ovhScanner) Name() string {
return OVH
}

func (s *ovhScanner) Description() string {
return "Search a phone number through the OVH Telecom REST API."
}

func (s *ovhScanner) ShouldRun(n number.Number) bool {
return s.isSupported(n.CountryCode)
}
Expand Down
4 changes: 4 additions & 0 deletions lib/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (r *Library) Scan(n *number.Number) (map[string]interface{}, map[string]err
return r.results, r.errors
}

func (r *Library) GetAllScanners() []Scanner {
return r.scanners
}

func RegisterPlugin(s Scanner) {
mu.Lock()
defer mu.Unlock()
Expand Down
1 change: 1 addition & 0 deletions lib/remote/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Plugin interface {

type Scanner interface {
Name() string
Description() string
Scan(number.Number) (interface{}, error)
ShouldRun(number.Number) bool
}
Expand Down
16 changes: 15 additions & 1 deletion mocks/Scanner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1d0971e

Please sign in to comment.