Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module temp/query | ||
|
||
go 1.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'") | ||
|
||
} | ||
|
||
|
||
} |