summaryrefslogtreecommitdiffstats
path: root/internal/client/osint.go
blob: 20f53ce6881c96176961258521e8064006a9ca2a (plain)
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
package client

import (
	"encoding/json"
	"fmt"
	"git.db.org.ai/dborg/internal/models"
	"net/url"
)

func (c *Client) LookupBSSID(params *models.BSSIDParams) (*models.BSSIDLookupResponse, error) {
	path := fmt.Sprintf("/osint/bssid/%s", url.PathEscape(params.BSSID))

	queryParams := url.Values{}
	if params.All {
		queryParams.Add("all", "true")
	}
	if params.Google {
		queryParams.Add("google", "true")
	}
	if params.OSM {
		queryParams.Add("osm", "true")
	}

	data, err := c.Get(path, queryParams)
	if err != nil {
		return nil, err
	}

	var response models.BSSIDLookupResponse
	if err := json.Unmarshal(data, &response); err != nil {
		return nil, fmt.Errorf("failed to parse BSSID lookup response: %w", err)
	}

	return &response, nil
}

func (c *Client) SearchBreachForum(params *models.BreachForumSearchParams) (*models.BreachForumSearchResponse, error) {
	path := "/osint/breachforum/search"

	queryParams := url.Values{}
	queryParams.Add("search", params.Search)
	if params.MaxHits > 0 {
		queryParams.Add("max_hits", fmt.Sprintf("%d", params.MaxHits))
	}

	data, err := c.Get(path, queryParams)
	if err != nil {
		return nil, err
	}

	var response models.BreachForumSearchResponse
	if err := json.Unmarshal(data, &response); err != nil {
		return nil, fmt.Errorf("failed to parse BreachForum search response: %w", err)
	}

	return &response, nil
}