63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
// Command tiledump reads a CT log tile file and dumps all entries.
|
|
// (C) Copyright 2026 Pim van Pelt <pim@ipng.ch>
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"ctfetch/internal/utils"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) != 2 {
|
|
fmt.Fprintf(os.Stderr, "Usage: %s <tile-file-or-url>\n", os.Args[0])
|
|
fmt.Fprintf(os.Stderr, "Examples:\n")
|
|
fmt.Fprintf(os.Stderr, " %s tile.data\n", os.Args[0])
|
|
fmt.Fprintf(os.Stderr, " %s https://halloumi2026h1.mon.ct.ipng.ch/tile/data/x002/x460/135\n", os.Args[0])
|
|
os.Exit(1)
|
|
}
|
|
|
|
arg := os.Args[1]
|
|
|
|
var tileData []byte
|
|
var err error
|
|
|
|
// Check if argument is a URL
|
|
if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
|
|
// Fetch from URL
|
|
fmt.Fprintf(os.Stderr, "Fetching: %s\n", arg)
|
|
tileData, err = utils.FetchURL(arg)
|
|
if err != nil {
|
|
fatal("failed to fetch URL: %v", err)
|
|
}
|
|
fmt.Fprintf(os.Stderr, "Fetched %d bytes\n", len(tileData))
|
|
} else {
|
|
// Read from file
|
|
tileData, err = os.ReadFile(arg)
|
|
if err != nil {
|
|
fatal("failed to read file: %v", err)
|
|
}
|
|
fmt.Fprintf(os.Stderr, "Read %d bytes from %s\n", len(tileData), arg)
|
|
}
|
|
|
|
// Decompress if needed
|
|
tileData, err = utils.Decompress(tileData)
|
|
if err != nil {
|
|
fatal("failed to decompress tile: %v", err)
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "Tile size: %d bytes\n\n", len(tileData))
|
|
|
|
// Dump all entries
|
|
if err := utils.DumpAllEntries(tileData); err != nil {
|
|
fatal("%v", err)
|
|
}
|
|
}
|
|
|
|
func fatal(format string, args ...any) {
|
|
fmt.Fprintf(os.Stderr, "Error: "+format+"\n", args...)
|
|
os.Exit(1)
|
|
}
|