Feat: AllowProxyToLocal config

pull/31/head
zijiren233 1 year ago
parent f7facc4bbf
commit 2fb4767ffb

@ -1,13 +1,15 @@
package conf package conf
type ProxyConfig struct { type ProxyConfig struct {
MovieProxy bool `yaml:"movie_proxy" env:"PROXY_MOVIE"` MovieProxy bool `yaml:"movie_proxy" env:"PROXY_MOVIE"`
LiveProxy bool `yaml:"live_proxy" env:"PROXY_LIVE"` LiveProxy bool `yaml:"live_proxy" env:"PROXY_LIVE"`
AllowProxyToLocal bool `yaml:"allow_proxy_to_local" env:"PROXY_ALLOW_TO_LOCAL"`
} }
func DefaultProxyConfig() ProxyConfig { func DefaultProxyConfig() ProxyConfig {
return ProxyConfig{ return ProxyConfig{
MovieProxy: true, MovieProxy: true,
LiveProxy: true, LiveProxy: true,
AllowProxyToLocal: false,
} }
} }

@ -67,7 +67,7 @@ func (m *BaseMovie) Validate() error {
if err != nil { if err != nil {
return err return err
} }
if utils.IsLocalIP(u.Host) { if !conf.Conf.Proxy.AllowProxyToLocal && utils.IsLocalIP(u.Host) {
return errors.New("local ip is not allowed") return errors.New("local ip is not allowed")
} }
switch u.Scheme { switch u.Scheme {
@ -89,7 +89,7 @@ func (m *BaseMovie) Validate() error {
if err != nil { if err != nil {
return err return err
} }
if utils.IsLocalIP(u.Host) { if !conf.Conf.Proxy.AllowProxyToLocal && utils.IsLocalIP(u.Host) {
return errors.New("local ip is not allowed") return errors.New("local ip is not allowed")
} }
if u.Scheme != "http" && u.Scheme != "https" { if u.Scheme != "http" && u.Scheme != "https" {

@ -499,8 +499,12 @@ func ProxyMovie(ctx *gin.Context) {
} }
func proxyURL(ctx *gin.Context, u string, headers map[string]string) error { func proxyURL(ctx *gin.Context, u string, headers map[string]string) error {
if l, err := utils.ParseURLIsLocalIP(u); err != nil || l { if !conf.Conf.Proxy.AllowProxyToLocal {
return err if l, err := utils.ParseURLIsLocalIP(u); err != nil {
return err
} else if l {
return errors.New("not allow proxy to local")
}
} }
r, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil) r, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
if err != nil { if err != nil {

Loading…
Cancel
Save