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
package main

import (
    "log"
    "net/http"
    "time"
    "io/ioutil"
    "io"
    "strings"
    //"regexp"
    "fmt"
)

func main() {
    // create an HTTP Client with a sane timeout.
    var http_client = &http.Client{
      Timeout: time.Second * 10,
    }

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {

        // grab parameters from query string.
	target_sarray, _ := r.URL.Query()["target"]
	keyword_sarray, _ := r.URL.Query()["keyword"]
	target := strings.Join(target_sarray, "")
	keyword := strings.Join(keyword_sarray, "")

	// connect to target uri and fetch the body.
	resp, _ := http_client.Get(target)
	defer resp.Body.Close()

        body_bytes, _ := ioutil.ReadAll(resp.Body)
	body := string(body_bytes)

	var keyword_found = strings.Contains(body, keyword)
	var found = "false"
	if keyword_found {
	    found = "true"
	}

	// log to stdout.
        fmt.Printf("found=%q, keywork=%q, uri=%q\n", found, keyword, target)

	// return true or false over HTTP.
        io.WriteString(w, found)
    })

    fmt.Println("listening on port 0.0.0.0:8888")
    log.Fatal(http.ListenAndServe(":8888", nil))
}