Fix: Shadowsocks nameserver when DOT=off
This commit is contained in:
@@ -260,10 +260,15 @@ func _main(background context.Context, args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if allSettings.ShadowSocks.Enabled {
|
if allSettings.ShadowSocks.Enabled {
|
||||||
|
nameserver := ""
|
||||||
|
if allSettings.DNS.Enabled {
|
||||||
|
nameserver = "127.0.0.1"
|
||||||
|
}
|
||||||
err = shadowsocksConf.MakeConf(
|
err = shadowsocksConf.MakeConf(
|
||||||
allSettings.ShadowSocks.Port,
|
allSettings.ShadowSocks.Port,
|
||||||
allSettings.ShadowSocks.Password,
|
allSettings.ShadowSocks.Password,
|
||||||
allSettings.ShadowSocks.Method,
|
allSettings.ShadowSocks.Method,
|
||||||
|
nameserver,
|
||||||
allSettings.System.UID,
|
allSettings.System.UID,
|
||||||
allSettings.System.GID)
|
allSettings.System.GID)
|
||||||
fatalOnError(err)
|
fatalOnError(err)
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import (
|
|||||||
"github.com/qdm12/private-internet-access-docker/internal/constants"
|
"github.com/qdm12/private-internet-access-docker/internal/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *configurator) MakeConf(port uint16, password, method string, uid, gid int) (err error) {
|
func (c *configurator) MakeConf(port uint16, password, method, nameserver string, uid, gid int) (err error) {
|
||||||
c.logger.Info("generating configuration file")
|
c.logger.Info("generating configuration file")
|
||||||
data := generateConf(port, password, method)
|
data := generateConf(port, password, method, nameserver)
|
||||||
return c.fileManager.WriteToFile(
|
return c.fileManager.WriteToFile(
|
||||||
string(constants.ShadowsocksConf),
|
string(constants.ShadowsocksConf),
|
||||||
data,
|
data,
|
||||||
@@ -18,7 +18,7 @@ func (c *configurator) MakeConf(port uint16, password, method string, uid, gid i
|
|||||||
files.Permissions(0400))
|
files.Permissions(0400))
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateConf(port uint16, password, method string) (data []byte) {
|
func generateConf(port uint16, password, method, nameserver string) (data []byte) {
|
||||||
conf := struct {
|
conf := struct {
|
||||||
Server string `json:"server"`
|
Server string `json:"server"`
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
@@ -29,7 +29,7 @@ func generateConf(port uint16, password, method string) (data []byte) {
|
|||||||
PortPassword map[string]string `json:"port_password"`
|
PortPassword map[string]string `json:"port_password"`
|
||||||
Workers uint `json:"workers"`
|
Workers uint `json:"workers"`
|
||||||
Interface string `json:"interface"`
|
Interface string `json:"interface"`
|
||||||
Nameserver string `json:"nameserver"`
|
Nameserver *string `json:"nameserver,omitempty"`
|
||||||
}{
|
}{
|
||||||
Server: "0.0.0.0",
|
Server: "0.0.0.0",
|
||||||
User: "nonrootuser",
|
User: "nonrootuser",
|
||||||
@@ -42,7 +42,9 @@ func generateConf(port uint16, password, method string) (data []byte) {
|
|||||||
},
|
},
|
||||||
Workers: 2,
|
Workers: 2,
|
||||||
Interface: "tun",
|
Interface: "tun",
|
||||||
Nameserver: "127.0.0.1",
|
}
|
||||||
|
if len(nameserver) > 0 {
|
||||||
|
conf.Nameserver = &nameserver
|
||||||
}
|
}
|
||||||
data, _ = json.Marshal(conf)
|
data, _ = json.Marshal(conf)
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -18,14 +18,16 @@ func Test_generateConf(t *testing.T) {
|
|||||||
tests := map[string]struct {
|
tests := map[string]struct {
|
||||||
port uint16
|
port uint16
|
||||||
password string
|
password string
|
||||||
|
nameserver string
|
||||||
data []byte
|
data []byte
|
||||||
}{
|
}{
|
||||||
"no data": {
|
"no data": {
|
||||||
data: []byte(`{"server":"0.0.0.0","user":"nonrootuser","method":"chacha20-ietf-poly1305","timeout":30,"fast_open":false,"mode":"tcp_and_udp","port_password":{"0":""},"workers":2,"interface":"tun","nameserver":"127.0.0.1"}`),
|
data: []byte(`{"server":"0.0.0.0","user":"nonrootuser","method":"chacha20-ietf-poly1305","timeout":30,"fast_open":false,"mode":"tcp_and_udp","port_password":{"0":""},"workers":2,"interface":"tun"}`),
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {
|
||||||
port: 2000,
|
port: 2000,
|
||||||
password: "abcde",
|
password: "abcde",
|
||||||
|
nameserver: "127.0.0.1",
|
||||||
data: []byte(`{"server":"0.0.0.0","user":"nonrootuser","method":"chacha20-ietf-poly1305","timeout":30,"fast_open":false,"mode":"tcp_and_udp","port_password":{"2000":"abcde"},"workers":2,"interface":"tun","nameserver":"127.0.0.1"}`),
|
data: []byte(`{"server":"0.0.0.0","user":"nonrootuser","method":"chacha20-ietf-poly1305","timeout":30,"fast_open":false,"mode":"tcp_and_udp","port_password":{"2000":"abcde"},"workers":2,"interface":"tun","nameserver":"127.0.0.1"}`),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -33,7 +35,7 @@ func Test_generateConf(t *testing.T) {
|
|||||||
tc := tc
|
tc := tc
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
data := generateConf(tc.port, tc.password, "chacha20-ietf-poly1305")
|
data := generateConf(tc.port, tc.password, "chacha20-ietf-poly1305", tc.nameserver)
|
||||||
assert.Equal(t, tc.data, data)
|
assert.Equal(t, tc.data, data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,7 @@ func Test_MakeConf(t *testing.T) {
|
|||||||
gomock.AssignableToTypeOf(files.Ownership(0, 0)),
|
gomock.AssignableToTypeOf(files.Ownership(0, 0)),
|
||||||
).Return(tc.writeErr).Times(1)
|
).Return(tc.writeErr).Times(1)
|
||||||
c := &configurator{logger: logger, fileManager: fileManager}
|
c := &configurator{logger: logger, fileManager: fileManager}
|
||||||
err := c.MakeConf(2000, "abcde", "chacha20-ietf-poly1305", 1000, 1001)
|
err := c.MakeConf(2000, "abcde", "chacha20-ietf-poly1305", "127.0.0.1", 1000, 1001)
|
||||||
if tc.err != nil {
|
if tc.err != nil {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Equal(t, tc.err.Error(), err.Error())
|
assert.Equal(t, tc.err.Error(), err.Error())
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
type Configurator interface {
|
type Configurator interface {
|
||||||
Version(ctx context.Context) (string, error)
|
Version(ctx context.Context) (string, error)
|
||||||
MakeConf(port uint16, password, method string, uid, gid int) (err error)
|
MakeConf(port uint16, password, method, nameserver string, uid, gid int) (err error)
|
||||||
Start(ctx context.Context, server string, port uint16, password string, log bool) (stdout, stderr io.ReadCloser, waitFn func() error, err error)
|
Start(ctx context.Context, server string, port uint16, password string, log bool) (stdout, stderr io.ReadCloser, waitFn func() error, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user