Files
eleakxir/back/search/search.go

94 lines
1.9 KiB
Go

package search
import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"sync"
"time"
"github.com/anotherhadi/eleakxir/backend/search/dataleak"
"github.com/anotherhadi/eleakxir/backend/search/osint"
"github.com/anotherhadi/eleakxir/backend/server"
)
type Query struct {
Text string
Column string // The column to search in (e.g., "email", "password", etc.
ExactMatch bool // Whether to search for an exact match
// Services
Datawells bool // Whether to include datawells in the search
GithubRecon bool // Whether to include github-recon in the search
}
type Result struct {
Id string
Date time.Time
Status string // "pending", "completed"
Query Query
LeakResult dataleak.LeakResult
GithubResult osint.GithubResult
}
func Search(s *server.Server, q Query, r *Result, mu *sync.RWMutex) {
var wg sync.WaitGroup
cleanQueryText := strings.TrimPrefix(q.Text, "^")
cleanQueryText = strings.TrimSuffix(q.Text, "$")
mu.Lock()
r.Date = time.Now()
r.Status = "pending"
r.Query = q
mu.Unlock()
wg.Add(2)
go func() {
if !q.Datawells {
mu.Lock()
r.LeakResult = dataleak.LeakResult{Error: "not enabled"}
mu.Unlock()
wg.Done()
return
}
leakResult := dataleak.Search(s, q.Text, q.Column, q.ExactMatch)
mu.Lock()
r.LeakResult = leakResult
mu.Unlock()
wg.Done()
}()
go func() {
if !q.GithubRecon {
mu.Lock()
r.GithubResult = osint.GithubResult{Error: "not enabled"}
mu.Unlock()
wg.Done()
return
}
githubResult := osint.Search(s, cleanQueryText, q.Column)
mu.Lock()
if githubResult == nil {
r.GithubResult = osint.GithubResult{}
} else {
r.GithubResult = *githubResult
}
mu.Unlock()
wg.Done()
}()
wg.Wait()
mu.Lock()
r.Status = "completed"
mu.Unlock()
}
func EncodeQueryID(q Query, dataleaksCount uint64) string {
raw, _ := json.Marshal(q)
return fmt.Sprintf("%d:%s", dataleaksCount, base64.URLEncoding.EncodeToString(raw))
}