feat: add environment variable support for proxy authentication and geo-blocking

- Introduced `.env.example` for environment variable configuration.
- Updated `docker-compose.yml` to utilize environment variables for proxy settings.
- Implemented proxy authentication with Basic Auth and geo-blocking based on country codes.
- Added `GEO_FILTER.md` for documentation on geo-filtering configuration.
- Enhanced logging to indicate authentication status and blocked countries during proxy server startup.
This commit is contained in:
isboyjc
2026-03-29 04:11:38 +08:00
parent 7a5061b101
commit a70df0d505
14 changed files with 1088 additions and 120 deletions

View File

@@ -20,6 +20,7 @@ type Validator struct {
timeout time.Duration
validateURL string
maxResponseMs int
cfg *config.Config
}
func concurrencyBuffer(total, concurrency int) int {
@@ -40,6 +41,7 @@ func New(concurrency, timeoutSec int, validateURL string) *Validator {
timeout: time.Duration(timeoutSec) * time.Second,
validateURL: validateURL,
maxResponseMs: maxMs,
cfg: cfg,
}
}
@@ -160,12 +162,13 @@ func (v *Validator) ValidateOne(p storage.Proxy) (bool, time.Duration, string, s
return false, latency, exitIP, exitLocation
}
// 过滤中国大陆出口香港的countryCode是HK不是CN
if len(exitLocation) >= 2 {
// 过滤屏蔽国家出口(根据配置
if v.cfg != nil && len(v.cfg.BlockedCountries) > 0 && len(exitLocation) >= 2 {
countryCode := exitLocation[:2]
if countryCode == "CN" {
// 中国大陆出口,直接拒绝
return false, latency, exitIP, exitLocation
for _, blocked := range v.cfg.BlockedCountries {
if countryCode == blocked {
return false, latency, exitIP, exitLocation
}
}
}