Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: add KDE set system proxy support #2

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 57 additions & 24 deletions common/settings/proxy_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux && !android

Check failure on line 1 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

: # github.com/sagernet/sing-box/common/settings

package settings

Expand All @@ -16,10 +16,12 @@

var (
hasGSettings bool
isKDE bool
sudoUser string
)

func init() {
isKDE = common.Error(exec.LookPath("kwriteconfig5")) == nil
hasGSettings = common.Error(exec.LookPath("gsettings")) == nil
if os.Getuid() == 0 {
sudoUser = os.Getenv("SUDO_USER")
Expand All @@ -37,35 +39,56 @@
}

func SetSystemProxy(router adapter.Router, port uint16, isMixed bool) (func() error, error) {
if !hasGSettings {
return nil, E.New("unsupported desktop environment")
}
err := runAsUser("gsettings", "set", "org.gnome.system.proxy.http", "enabled", "true")
if err != nil {
return nil, err
}
if isMixed {
err = setGnomeProxy(port, "ftp", "http", "https", "socks")
} else {
err = setGnomeProxy(port, "http", "https")
}
if err != nil {
return nil, err
}
err = runAsUser("gsettings", "set", "org.gnome.system.proxy", "use-same-proxy", F.ToString(isMixed))
if err != nil {
return nil, err
if hasGSettings {
err := runAsUser("gsettings", "set", "org.gnome.system.proxy.http", "enabled", "true")
if err != nil {
return nil, err
}
if isMixed {
err = setGnomeProxy(port, "ftp", "http", "https", "socks")
} else {
err = setGnomeProxy(port, "http", "https")
}
if err != nil {
return nil, err
}
err = runAsUser("gsettings", "set", "org.gnome.system.proxy", "use-same-proxy", F.ToString(isMixed))
if err != nil {
return nil, err
}
err = runAsUser("gsettings", "set", "org.gnome.system.proxy", "mode", "manual")
if err != nil {
return nil, err
}
return func() error {
return runAsUser("gsettings", "set", "org.gnome.system.proxy", "mode", "none")
}, nil
}
err = runAsUser("gsettings", "set", "org.gnome.system.proxy", "mode", "manual")
if err != nil {
return nil, err
if isKDE {
err := runAsUser("kwriteconfig5", "--file","kioslaverc", "--group", "'Proxy Settings'", "--key", "ProxyType", "1")
if err != nil {
return nil, err
}
if isMixed {
err = setKDEProxy(port, "ftp", "http", "https", "socks")
} else {
err = setKDEProxy(port, "http", "https")
}
if err != nil {
return nil, err
}
err := runAsUser("kwriteconfig5", "--file","kioslaverc", "--group", "'Proxy Settings'", "--key", "Authmode", "0")
if err != nil {
return nil, err
}
return func() error {
return err := runAsUser("kwriteconfig5", "--file","kioslaverc", "--group", "'Proxy Settings'", "--key", "ProxyType", "0")

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.18)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected := at end of statement (typecheck)

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

expected ';', found ':=' (typecheck)

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected := at end of statement) (typecheck)

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected := at end of statement) (typecheck)

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Debug build

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.20)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64, linux, amd64, v1)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64-v3, linux, amd64, v3)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-386, linux, 386)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-arm64, linux, arm64)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv5, linux, arm, 5)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv6, linux, arm, 6)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv7, linux, arm, 7)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips-softfloat, linux, mips, softfloat)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips-hardfloat, linux, mips, hardfloat)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-mipsel-softfloat, linux, mipsle, softfloat)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-mipsel-hardfloat, linux, mipsle, hardfloat)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64, linux, mips64)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64el, linux, mips64le)

syntax error: unexpected := at end of statement

Check failure on line 85 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / cross (linux-s390x, linux, s390x)

syntax error: unexpected := at end of statement
}, nil
}
return func() error {
return runAsUser("gsettings", "set", "org.gnome.system.proxy", "mode", "none")
}, nil
return nil, E.New("unsupported desktop environment")
}

func setGnomeProxy(port uint16, proxyTypes ...string) error {

Check failure on line 91 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

expected '(', found setGnomeProxy (typecheck)
for _, proxyType := range proxyTypes {
err := runAsUser("gsettings", "set", "org.gnome.system.proxy."+proxyType, "host", "127.0.0.1")
if err != nil {
Expand All @@ -78,3 +101,13 @@
}
return nil
}

func setKDEProxy(port uint16, proxyTypes ...string) error {

Check failure on line 105 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

expected '(', found setKDEProxy (typecheck)
for _, proxyType := range proxyTypes {
err := runAsUser("kwriteconfig5", "--file","kioslaverc", "--group", "'Proxy Settings'", "--key", proxyType+"Proxy", proxyType+"://127.0.0.1:"+F.ToString(port))
if err != nil {
return err
}
}
return nil
}

Check failure on line 113 in common/settings/proxy_linux.go

View workflow job for this annotation

GitHub Actions / Build

expected '}', found 'EOF' (typecheck)
Loading