Skip to content

Commit

Permalink
Merge pull request #5 from N0el4kLs/dev
Browse files Browse the repository at this point in the history
fix: optimize auth logic
  • Loading branch information
N0el4kLs authored May 20, 2024
2 parents d654355 + 3f0bd8c commit e119bb8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
25 changes: 17 additions & 8 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,30 +291,32 @@ func (c *CyberRetrieveEngine) checkSession() error {
if ok := provider.Auth(c.sessions); !ok {
errorMsg := fmt.Sprintf("%s auth err, please check your quake token", provider.Name())
err = errors.New(errorMsg)
} else {
c.providers = append(c.providers, provider)
engineNum++
}
c.providers = append(c.providers, provider)
engineNum++
}
if c.searchMode&ModeFofa == ModeFofa {
provider := &fofa.Provider{}
gologger.Info().Msgf("Check %s authorization,wait a second...\n", provider.Name())
if ok := provider.Auth(c.sessions); !ok {
errorMsg := fmt.Sprintf("%s auth err, please check your quake token", provider.Name())
err = errors.New(errorMsg)
} else {
c.providers = append(c.providers, provider)
engineNum++
}
c.providers = append(c.providers, provider)
engineNum++

}
if c.searchMode&ModeHunter == ModeHunter {
provider := &hunter.Provider{}
gologger.Info().Msgf("Check %s authorization,wait a second...\n", provider.Name())
if ok := provider.Auth(c.sessions); !ok {
errorMsg := fmt.Sprintf("%s auth err, please check your quake token", provider.Name())
err = errors.New(errorMsg)
} else {
c.providers = append(c.providers, provider)
engineNum++
}
c.providers = append(c.providers, provider)
engineNum++
}
if engineNum == 0 {
err = errors.New("please choose a search engine")
Expand All @@ -323,7 +325,14 @@ func (c *CyberRetrieveEngine) checkSession() error {
}

gologger.Info().Msgf("All search engine authorization check done...\n")
return err

// If have at least one engine can be used, just warning the unauthed engine and return nil
if engineNum != 0 && err != nil {
gologger.Warning().Msgf("%s\n", err)
return nil
} else {
return err
}
}

func (c *CyberRetrieveEngine) autoGrammar(query, name string) string {
Expand Down
1 change: 0 additions & 1 deletion sources/quake/quake.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (p *Provider) query(queryFiled *QuakeSearchFiled, results chan *sources.Res
"Content-Type": "application/json",
}
resp, err := sources.DefaultClient.Post(SEARCH_URL, header, queryFiled)
//gologger.Debug().Msgf("Quake Search Resp: %s \n", resp.String())
if err != nil {
gologger.Debug().Msgf("Quake Search Error: %s \n", err)
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions sources/quake/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package quake

// QuakeSearchResult Quake service data interface return data structure
type QuakeSearchResult struct {
Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Code interface{} `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Data []struct {
Service struct {
Http struct {
Expand Down

0 comments on commit e119bb8

Please sign in to comment.