Update main.go

This commit is contained in:
Shlee
2026-05-26 13:06:35 +09:30
committed by GitHub
parent 5ef4490692
commit 5a7d54058e

View File

@@ -55,6 +55,7 @@ type Config struct {
TraefikBouncerKey string
DoCrowdsecInstall bool
EnableGeoblocking bool
EnableASNblocking bool
Secret string
IsEnterprise bool
}
@@ -123,11 +124,18 @@ func main() {
fmt.Println("\nConfiguration files created successfully!")
// Download MaxMind database if requested
// Download MaxMind Country / ASN database if requested
if config.EnableGeoblocking {
fmt.Println("\n=== Downloading MaxMind Database ===")
fmt.Println("\n=== Downloading MaxMind Country Database ===")
if err := downloadMaxMindDatabase(); err != nil {
fmt.Printf("Error downloading MaxMind database: %v\n", err)
fmt.Printf("Error downloading MaxMind Country database: %v\n", err)
fmt.Println("You can download it manually later if needed.")
}
}
if config.EnableASNblocking {
fmt.Println("\n=== Downloading MaxMind ASN Database ===")
if err := downloadMaxMindASNDatabase(); err != nil {
fmt.Printf("Error downloading MaxMind ASN database: %v\n", err)
fmt.Println("You can download it manually later if needed.")
}
}
@@ -527,7 +535,8 @@ func collectUserInput() Config {
fmt.Println("\n=== Advanced Configuration ===")
config.EnableIPv6 = readBool("Is your server IPv6 capable?", true)
config.EnableGeoblocking = readBool("Do you want to download the MaxMind GeoLite2 database for geoblocking functionality?", true)
config.EnableGeoblocking = readBool("Do you want to download the MaxMind GeoLite2 Country database for geoblocking functionality?", true)
config.EnableASNblocking = readBool("Do you want to download the MaxMind GeoLite2 ASN database for rule-blocking functionality?", true)
if config.DashboardDomain == "" {
fmt.Println("Error: Dashboard Domain name is required")
@@ -785,17 +794,17 @@ func downloadMaxMindDatabase() error {
// Download the GeoLite2 Country database
if err := run("curl", "-L", "-o", "GeoLite2-Country.tar.gz",
"https://github.com/GitSquared/node-geolite2-redist/raw/refs/heads/master/redist/GeoLite2-Country.tar.gz"); err != nil {
return fmt.Errorf("failed to download GeoLite2 database: %v", err)
return fmt.Errorf("failed to download GeoLite2 Country database: %v", err)
}
// Extract the database
if err := run("tar", "-xzf", "GeoLite2-Country.tar.gz"); err != nil {
return fmt.Errorf("failed to extract GeoLite2 database: %v", err)
return fmt.Errorf("failed to extract GeoLite2 Country database: %v", err)
}
// Find the .mmdb file and move it to the config directory
if err := run("bash", "-c", "mv GeoLite2-Country_*/GeoLite2-Country.mmdb config/"); err != nil {
return fmt.Errorf("failed to move GeoLite2 database to config directory: %v", err)
return fmt.Errorf("failed to move GeoLite2 Country database to config directory: %v", err)
}
// Clean up the downloaded files
@@ -806,3 +815,31 @@ func downloadMaxMindDatabase() error {
fmt.Println("MaxMind GeoLite2 Country database downloaded successfully!")
return nil
}
func downloadMaxMindASNDatabase() error {
fmt.Println("Downloading MaxMind GeoLite2 ASN database...")
// Download the GeoLite2 ASN database
if err := run("curl", "-L", "-o", "GeoLite2-ASN.tar.gz",
"https://github.com/GitSquared/node-geolite2-redist/raw/refs/heads/master/redist/GeoLite2-ASN.tar.gz"); err != nil {
return fmt.Errorf("failed to download GeoLite2 ASN database: %v", err)
}
// Extract the database
if err := run("tar", "-xzf", "GeoLite2-ASN.tar.gz"); err != nil {
return fmt.Errorf("failed to extract GeoLite2 ASN database: %v", err)
}
// Find the .mmdb file and move it to the config directory
if err := run("bash", "-c", "mv GeoLite2-ASN*/GeoLite2-ASN.mmdb config/"); err != nil {
return fmt.Errorf("failed to move GeoLite2 ASN database to config directory: %v", err)
}
// Clean up the downloaded files
if err := run("rm", "-rf", "GeoLite2-ASN.tar.gz", "GeoLite2-ASN*"); err != nil {
fmt.Printf("Warning: failed to clean up temporary files: %v\n", err)
}
fmt.Println("MaxMind GeoLite2 ASN database downloaded successfully!")
return nil
}