Skip to content

Commit

Permalink
Merge pull request #4 from ibnaleem/dzen.ru
Browse files Browse the repository at this point in the history
closes #1 by adding cookies
  • Loading branch information
ibnaleem authored Nov 19, 2024
2 parents f42c530 + b878f96 commit 6da571a
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions gosearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ type Website struct {
ErrorType string `yaml:"errorType"`
ErrorMsg string `yaml:"errorMsg,omitempty"`
ErrorCode int `yaml:"errorCode,omitempty"`
Cookies []Cookie `yaml:"cookies,omitempty"` // New field for cookies
}

type Config struct {
Websites []Website `yaml:"websites"`
}

type Cookie struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
}

func UnmarshalYAML() (Config, error) {

// GoSearch relies on config.yaml to determine the websites to search for.
Expand Down Expand Up @@ -101,6 +107,38 @@ func BuildURL(baseURL, username string) string {
return strings.Replace(baseURL, "{}", username, 1)
}

func MakeRequestWithCookies(url string, cookies [] Cookie, WebsiteErrorCode int, wg *sync.WaitGroup) {
defer wg.Done()

client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)

if err != nil {
fmt.Printf("Error creating request in function MakeRequestWithCookies: %v\n", err)
return
}

for _, cookie := range cookies {
cookieObj := &http.Cookie{
Name: cookie.Name,
Value: cookie.Value,
}
req.AddCookie(cookieObj)
}

resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error making request to %s: %v\n", url, err)
return
}
defer resp.Body.Close()

if resp.StatusCode != WebsiteErrorCode {
fmt.Println(Green + "::", url + Reset)
WriteToFile("results.txt", url + "\n")
}
}

func MakeRequestWithoutErrorMsg(url string, WebsiteErrorCode int, wg *sync.WaitGroup) {
defer wg.Done()

Expand Down Expand Up @@ -160,13 +198,16 @@ func Search(config Config, username string) {
} else if website.ErrorType == "unknown" {
fmt.Println(Yellow + ":: [?]", url + Reset)
WriteToFile("results.txt", "[?] " + url + "\n")
} else {

} else if website.Cookies != nil {
wg.Add(1)
go MakeRequestWithCookies(url, website.Cookies, website.ErrorCode, &wg)
} else {
wg.Add(1)
go MakeRequestWithoutErrorMsg(url, website.ErrorCode, &wg)
}
}

// Wait for all goroutines to finish
wg.Wait()
}

Expand Down

0 comments on commit 6da571a

Please sign in to comment.