fetch_setting.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. package system_setting
  2. import "github.com/QuantumNous/new-api/setting/config"
  3. type FetchSetting struct {
  4. EnableSSRFProtection bool `json:"enable_ssrf_protection"` // 是否启用SSRF防护
  5. AllowPrivateIp bool `json:"allow_private_ip"`
  6. DomainFilterMode bool `json:"domain_filter_mode"` // 域名过滤模式,true: 白名单模式,false: 黑名单模式
  7. IpFilterMode bool `json:"ip_filter_mode"` // IP过滤模式,true: 白名单模式,false: 黑名单模式
  8. DomainList []string `json:"domain_list"` // domain format, e.g. example.com, *.example.com
  9. IpList []string `json:"ip_list"` // CIDR format
  10. AllowedPorts []string `json:"allowed_ports"` // port range format, e.g. 80, 443, 8000-9000
  11. ApplyIPFilterForDomain bool `json:"apply_ip_filter_for_domain"` // 对域名启用IP过滤(实验性)
  12. }
  13. var defaultFetchSetting = FetchSetting{
  14. EnableSSRFProtection: true, // 默认开启SSRF防护
  15. AllowPrivateIp: false,
  16. DomainFilterMode: false,
  17. IpFilterMode: false,
  18. DomainList: []string{},
  19. IpList: []string{},
  20. AllowedPorts: []string{"80", "443", "8080", "8443"},
  21. ApplyIPFilterForDomain: false,
  22. }
  23. func init() {
  24. // 注册到全局配置管理器
  25. config.GlobalConfig.Register("fetch_setting", &defaultFetchSetting)
  26. }
  27. func GetFetchSetting() *FetchSetting {
  28. return &defaultFetchSetting
  29. }