Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
3.0 KiB
Go
108 lines
3.0 KiB
Go
// Comando demo gera os dados de demonstração das capturas de tela do Urutau:
|
|
// uma base de geolocalização MMDB (city + asn) e logs de 30 dias (Traefik,
|
|
// auth.log, fail2ban.log), tudo com endereços e domínios reservados para
|
|
// documentação. Veja scripts/screenshots.sh.
|
|
//
|
|
// demo geo <dir> grava dbip-city-lite-*.mmdb e dbip-asn-lite-*.mmdb
|
|
// demo logs <dir> <edge-1|edge-2> [seed] grava access.log, auth.log e fail2ban.log
|
|
// demo live <segundos> <dir>:<host>... acrescenta eventos ao vivo, até o tempo acabar
|
|
// demo egress <dir> grava egress.log e containers.map (análise de saída)
|
|
// demo check <arquivo>... falha se achar IP fora das faixas reservadas
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/netip"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
if err := run(os.Args[1:]); err != nil {
|
|
fmt.Fprintln(os.Stderr, "demo:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(a []string) error {
|
|
if len(a) < 2 {
|
|
return fmt.Errorf("uso: demo geo|logs|live|check ...")
|
|
}
|
|
switch a[0] {
|
|
case "geo":
|
|
return writeGeo(a[1])
|
|
case "logs":
|
|
if len(a) < 3 {
|
|
return fmt.Errorf("uso: demo logs <dir> <edge-1|edge-2> [seed]")
|
|
}
|
|
seed := int64(1)
|
|
if len(a) > 3 {
|
|
seed, _ = strconv.ParseInt(a[3], 10, 64)
|
|
}
|
|
return writeLogs(a[1], a[2], seed)
|
|
case "live":
|
|
secs, err := strconv.Atoi(a[1])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var dirs, hosts []string
|
|
for _, p := range a[2:] {
|
|
d, h, ok := strings.Cut(p, ":")
|
|
if !ok {
|
|
return fmt.Errorf("esperado <dir>:<host>, recebi %q", p)
|
|
}
|
|
dirs, hosts = append(dirs, d), append(hosts, h)
|
|
}
|
|
return live(dirs, hosts, time.Duration(secs)*time.Second)
|
|
case "egress":
|
|
return writeEgress(a[1])
|
|
case "check":
|
|
return check(a[1:])
|
|
}
|
|
return fmt.Errorf("subcomando desconhecido %q", a[0])
|
|
}
|
|
|
|
var ipRe = regexp.MustCompile(`\b(?:\d{1,3}\.){3}\d{1,3}\b|\b(?:[0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}\b`)
|
|
|
|
// check procura endereços IP em arquivos de texto e falha se algum estiver fora
|
|
// das faixas reservadas.
|
|
func check(files []string) error {
|
|
bad := 0
|
|
for _, f := range files {
|
|
b, err := os.ReadFile(f)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
txt := string(b)
|
|
for _, loc := range ipRe.FindAllStringIndex(txt, -1) {
|
|
m := txt[loc[0]:loc[1]]
|
|
if loc[0] > 0 && txt[loc[0]-1] == '/' && strings.HasSuffix(m, ".0.0.0") {
|
|
continue // versão de navegador (Chrome/130.0.0.0), não um endereço
|
|
}
|
|
ip, err := netip.ParseAddr(m)
|
|
base := filepath.Base(f)
|
|
if err == nil && ip.IsPrivate() && (base == "egress.log" || base == "containers.map") {
|
|
continue // origens dos contêineres (10.x/172.x/fd00::)
|
|
}
|
|
if err != nil || reserved(ip) {
|
|
continue
|
|
}
|
|
if ip.Is4() && strings.HasPrefix(m, "0.") {
|
|
continue
|
|
}
|
|
fmt.Printf("%s: %s fora das faixas reservadas\n", f, m)
|
|
if bad++; bad > 20 {
|
|
return fmt.Errorf("muitos endereços fora das faixas")
|
|
}
|
|
}
|
|
}
|
|
if bad > 0 {
|
|
return fmt.Errorf("%d endereços fora das faixas reservadas", bad)
|
|
}
|
|
return nil
|
|
}
|