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 {
|
||||
nameserver := ""
|
||||
if allSettings.DNS.Enabled {
|
||||
nameserver = "127.0.0.1"
|
||||
}
|
||||
err = shadowsocksConf.MakeConf(
|
||||
allSettings.ShadowSocks.Port,
|
||||
allSettings.ShadowSocks.Password,
|
||||
allSettings.ShadowSocks.Method,
|
||||
nameserver,
|
||||
allSettings.System.UID,
|
||||
allSettings.System.GID)
|
||||
fatalOnError(err)
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"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")
|
||||
data := generateConf(port, password, method)
|
||||
data := generateConf(port, password, method, nameserver)
|
||||
return c.fileManager.WriteToFile(
|
||||
string(constants.ShadowsocksConf),
|
||||
data,
|
||||
@@ -18,7 +18,7 @@ func (c *configurator) MakeConf(port uint16, password, method string, uid, gid i
|
||||
files.Permissions(0400))
|
||||
}
|
||||
|
||||
func generateConf(port uint16, password, method string) (data []byte) {
|
||||
func generateConf(port uint16, password, method, nameserver string) (data []byte) {
|
||||
conf := struct {
|
||||
Server string `json:"server"`
|
||||
User string `json:"user"`
|
||||
@@ -29,7 +29,7 @@ func generateConf(port uint16, password, method string) (data []byte) {
|
||||
PortPassword map[string]string `json:"port_password"`
|
||||
Workers uint `json:"workers"`
|
||||
Interface string `json:"interface"`
|
||||
Nameserver string `json:"nameserver"`
|
||||
Nameserver *string `json:"nameserver,omitempty"`
|
||||
}{
|
||||
Server: "0.0.0.0",
|
||||
User: "nonrootuser",
|
||||
@@ -40,9 +40,11 @@ func generateConf(port uint16, password, method string) (data []byte) {
|
||||
PortPassword: map[string]string{
|
||||
fmt.Sprintf("%d", port): password,
|
||||
},
|
||||
Workers: 2,
|
||||
Interface: "tun",
|
||||
Nameserver: "127.0.0.1",
|
||||
Workers: 2,
|
||||
Interface: "tun",
|
||||
}
|
||||
if len(nameserver) > 0 {
|
||||
conf.Nameserver = &nameserver
|
||||
}
|
||||
data, _ = json.Marshal(conf)
|
||||
return data
|
||||
|
||||
@@ -16,24 +16,26 @@ import (
|
||||
func Test_generateConf(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := map[string]struct {
|
||||
port uint16
|
||||
password string
|
||||
data []byte
|
||||
port uint16
|
||||
password string
|
||||
nameserver string
|
||||
data []byte
|
||||
}{
|
||||
"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": {
|
||||
port: 2000,
|
||||
password: "abcde",
|
||||
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"}`),
|
||||
port: 2000,
|
||||
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"}`),
|
||||
},
|
||||
}
|
||||
for name, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
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)
|
||||
})
|
||||
}
|
||||
@@ -67,7 +69,7 @@ func Test_MakeConf(t *testing.T) {
|
||||
gomock.AssignableToTypeOf(files.Ownership(0, 0)),
|
||||
).Return(tc.writeErr).Times(1)
|
||||
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 {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, tc.err.Error(), err.Error())
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
type Configurator interface {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user