Yeuoly 1 year ago
parent
commit
b564037413
4 changed files with 38 additions and 8 deletions
  1. 3 1
      conf/config.yaml
  2. 9 2
      internal/core/runner/python/python.go
  3. 24 5
      internal/static/config.go
  4. 2 0
      internal/types/config.go

+ 3 - 1
conf/config.yaml

@@ -8,4 +8,6 @@ worker_timeout: 5
 python_path: /usr/local/bin/python3
 enable_network: True # please make sure there is no network risk in your environment
 proxy:
-  socks5: '192.168.64.1:7890'
+  socks5: ''
+  http: ''
+  https: ''

+ 9 - 2
internal/core/runner/python/python.go

@@ -71,8 +71,15 @@ func (p *PythonRunner) Run(
 		cmd.Env = []string{}
 
 		if configuration.Proxy.Socks5 != "" {
-			cmd.Env = append(cmd.Env, fmt.Sprintf("HTTPS_PROXY=socks5://%s", configuration.Proxy.Socks5))
-			cmd.Env = append(cmd.Env, fmt.Sprintf("HTTP_PROXY=socks5://%s", configuration.Proxy.Socks5))
+			cmd.Env = append(cmd.Env, fmt.Sprintf("HTTPS_PROXY=%s", configuration.Proxy.Socks5))
+			cmd.Env = append(cmd.Env, fmt.Sprintf("HTTP_PROXY=%s", configuration.Proxy.Socks5))
+		} else if configuration.Proxy.Https != "" || configuration.Proxy.Http != "" {
+			if configuration.Proxy.Https != "" {
+				cmd.Env = append(cmd.Env, fmt.Sprintf("HTTPS_PROXY=%s", configuration.Proxy.Https))
+			}
+			if configuration.Proxy.Http != "" {
+				cmd.Env = append(cmd.Env, fmt.Sprintf("HTTP_PROXY=%s", configuration.Proxy.Http))
+			}
 		}
 
 		err = output_handler.CaptureOutput(cmd)

+ 24 - 5
internal/static/config.go

@@ -84,14 +84,33 @@ func InitConfig(path string) error {
 
 	if difySandboxGlobalConfigurations.EnableNetwork {
 		log.Info("network has been enabled")
-	}
+		socks5_proxy := os.Getenv("SOCKS5_PROXY")
+		if socks5_proxy != "" {
+			difySandboxGlobalConfigurations.Proxy.Socks5 = socks5_proxy
+		}
 
-	socks5_proxy := os.Getenv("SOCKS5_PROXY")
-	if socks5_proxy != "" {
-		difySandboxGlobalConfigurations.Proxy.Socks5 = socks5_proxy
+		if difySandboxGlobalConfigurations.Proxy.Socks5 != "" {
+			log.Info("using socks5 proxy: %s", difySandboxGlobalConfigurations.Proxy.Socks5)
+		}
 
-	}
+		https_proxy := os.Getenv("HTTPS_PROXY")
+		if https_proxy != "" {
+			difySandboxGlobalConfigurations.Proxy.Https = https_proxy
+		}
+
+		if difySandboxGlobalConfigurations.Proxy.Https != "" {
+			log.Info("using https proxy: %s", difySandboxGlobalConfigurations.Proxy.Https)
+		}
 
+		http_proxy := os.Getenv("HTTP_PROXY")
+		if http_proxy != "" {
+			difySandboxGlobalConfigurations.Proxy.Http = http_proxy
+		}
+
+		if difySandboxGlobalConfigurations.Proxy.Http != "" {
+			log.Info("using http proxy: %s", difySandboxGlobalConfigurations.Proxy.Http)
+		}
+	}
 	return nil
 }
 

+ 2 - 0
internal/types/config.go

@@ -14,5 +14,7 @@ type DifySandboxGlobalConfigurations struct {
 	EnableNetwork bool   `yaml:"enable_network"`
 	Proxy         struct {
 		Socks5 string `yaml:"socks5"`
+		Https  string `yaml:"https"`
+		Http   string `yaml:"http"`
 	} `yaml:"proxy"`
 }