mirror of
https://github.com/therootcompany/golib.git
synced 2026-04-24 20:58:00 +00:00
42 lines
698 B
Go
42 lines
698 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) < 3 {
|
|
fmt.Fprintf(os.Stderr, "Usage: %s <blacklist.csv> <ip-address> [git-url]\n", os.Args[0])
|
|
os.Exit(1)
|
|
}
|
|
|
|
dataPath := os.Args[1]
|
|
ipStr := os.Args[2]
|
|
gitURL := ""
|
|
if len(os.Args) >= 4 {
|
|
gitURL = os.Args[3]
|
|
}
|
|
|
|
var bl *Blacklist
|
|
if gitURL != "" {
|
|
bl = NewGitBlacklist(gitURL, dataPath)
|
|
} else {
|
|
bl = NewBlacklist(dataPath)
|
|
}
|
|
|
|
if err := bl.Init(false); err != nil {
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "Loaded %d entries\n", bl.Size())
|
|
|
|
if bl.Contains(ipStr) {
|
|
fmt.Printf("%s is BLOCKED\n", ipStr)
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Printf("%s is allowed\n", ipStr)
|
|
}
|