Skip to content

Commit

Permalink
feat: 增加 http, https, ftp, socks 认证项 (#75)
Browse files Browse the repository at this point in the history
增加 http, https, ftp, socks 认证项

Log: 增加 http, https, ftp, socks 认证项
Task: https://pms.uniontech.com/task-view-204811.html
Influence: 网络代理
Change-Id: If8c19af84693bf47668c8075975cbf1cd6ca26b0

Co-authored-by: liaohanqin <liaohanqin@uniontech.com>
  • Loading branch information
liaohanqin and liaohanqin authored Nov 21, 2022
1 parent 019d7fc commit a3fb0cc
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ package proxy

import (
"fmt"
"github.com/godbus/dbus"
"os"
"strconv"
"strings"

"github.com/godbus/dbus"

"github.com/linuxdeepin/go-gir/gio-2.0"
"github.com/linuxdeepin/go-lib/gsettings"
"github.com/linuxdeepin/go-lib/log"
Expand Down Expand Up @@ -51,10 +52,13 @@ const (
proxyModeManual = "manual"
proxyModeAuto = "auto"

gkeyProxyAuto = "autoconfig-url"
gkeyProxyIgnoreHosts = "ignore-hosts"
gkeyProxyHost = "host"
gkeyProxyPort = "port"
gkeyProxyAuto = "autoconfig-url"
gkeyProxyIgnoreHosts = "ignore-hosts"
gkeyProxyHost = "host"
gkeyProxyPort = "port"
gkeyProxyUseAuthentication = "use-authentication"
gkeyProxyAuthenticationUser = "authentication-user"
gkeyProxyAuthenticationPassword = "authentication-password"

gchildProxyHttp = "http"
gchildProxyHttps = "https"
Expand Down Expand Up @@ -139,6 +143,7 @@ func updateProxyEnvs() {
doSetEnv(envHttpProxy, getProxyValue(proxyTypeHttp, proxyTypeHttp))
doSetEnv(envHttpsProxy, getProxyValue(proxyTypeHttps, proxyTypeHttp))
doSetEnv(envFtpProxy, getProxyValue(proxyTypeFtp, proxyTypeHttp))
doSetEnv(envAllProxy, getProxyValue(proxyTypeSocks, proxyTypeSocks))
doSetEnv(envSocksProxy, getProxyValue(proxyTypeSocks, proxyTypeSocks))

arrayIgnoreHosts := proxySettings.GetStrv(gkeyProxyIgnoreHosts)
Expand Down Expand Up @@ -215,7 +220,18 @@ func getProxyValue(proxyType string, protocol string) (proxyValue string) {
return
}
port := strconv.Itoa(int(childSettings.GetInt(gkeyProxyPort)))
proxyValue = fmt.Sprintf("%s://%s:%s", protocol, host, port)

useAuthentication := false
if childSettings.GetSchema().HasKey(gkeyProxyUseAuthentication) {
useAuthentication = childSettings.GetBoolean(gkeyProxyUseAuthentication)
}
if useAuthentication {
user := childSettings.GetString(gkeyProxyAuthenticationUser)
password := childSettings.GetString(gkeyProxyAuthenticationPassword)
proxyValue = fmt.Sprintf("%s://%s:%s@%s:%s", protocol, user, password, host, port)
} else {
proxyValue = fmt.Sprintf("%s://%s:%s", protocol, host, port)
}
return
}

Expand Down

0 comments on commit a3fb0cc

Please sign in to comment.