Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Log query
This program takes user input to query https://ct.googleapis.com/pilot/ct/v1/ for log information. This was created to practice golang and better understand the logging process, not intended for direct use in our final monitor.
  • Loading branch information
mwl11002 committed Oct 15, 2021
1 parent c093b59 commit 0612dae
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
3 changes: 3 additions & 0 deletions log-query/go.mod
@@ -0,0 +1,3 @@
module temp/query

go 1.17
115 changes: 115 additions & 0 deletions log-query/query.go
@@ -0,0 +1,115 @@
// Query the google API for log information.
// Created by Marcus Barone.

// Note: this was only made to practice golang
// and to better understand the logging process

package main

import (
"bufio"
"fmt"
"os"
"strings"
"strconv"
"io/ioutil"
"log"
"net/http"
)

func main() {

fmt.Println("Query ct.googleapis.com/pilot/ct/v1 for logs.")
fmt.Println("To get the signed tree head, type 'sth'")
fmt.Println("To get entries, type 'entries'")
fmt.Println("To quit, use ctrl+c or type 'quit'")

input := bufio.NewScanner(os.Stdin)


for input.Scan() {

var text string
text = strings.ToLower(input.Text())

if text == "sth" {

resp, err := http.Get("https://ct.googleapis.com/pilot/ct/v1/get-sth")

if err != nil {
log.Fatal(err)
}

defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)

if err != nil {
log.Fatal(err)
}

fmt.Println(string(body))

} else if text == "entries" {

fmt.Println("Enter start:")
input.Scan()
var start int

_, start_err := fmt.Sscan(input.Text(), &start)

if start_err != nil {
fmt.Println(start_err)
goto loop
}

fmt.Println("Enter end:")
input.Scan()
var end int

_, end_err := fmt.Sscan(input.Text(), &end)

if end_err != nil {
fmt.Println(end_err)
goto loop
}

if start > end {
fmt.Println("Start must be smaller than end.")
goto loop
}

resp, err := http.Get("https://ct.googleapis.com/pilot/ct/v1/get-entries?start=" + strconv.Itoa(start) + "&end=" + strconv.Itoa(end))

if err != nil {
log.Fatal(err)
}

defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)

if err != nil {
log.Fatal(err)
}

fmt.Println(string(body))

} else if text == "quit" {

break

} else {

fmt.Println("Invalid input");

}
loop:
fmt.Println("\nTo get the signed tree head, type 'sth'")
fmt.Println("To get entries, type 'entries'")
fmt.Println("To quit, use ctrl+c or type 'quit'")

}


}

0 comments on commit 0612dae

Please sign in to comment.