Fix #261 add variable HTTP_CONTROL_SERVER_PORT

This commit is contained in:
Quentin McGaw
2020-10-17 22:07:15 +00:00
parent 6f4be72785
commit 8abc22977c
6 changed files with 60 additions and 2 deletions

View File

@@ -255,6 +255,12 @@ That one is important if you want to connect to the container from your LAN for
| `UID` | `1000` | | User ID to run as non root and for ownership of files written |
| `GID` | `1000` | | Group ID to run as non root and for ownership of files written |
### HTTP Control server
| Variable | Default | Choices | Description |
| --- | --- | --- | --- |
| `HTTP_CONTROL_SERVER_PORT` | `8000` | `1` to `65535` | Listening port for the HTTP control server |
### Other
| Variable | Default | Choices | Description |

View File

@@ -236,8 +236,8 @@ func _main(background context.Context, args []string) int { //nolint:gocognit,go
unboundLooper, updaterLooper, publicIPLooper, routingConf, logger, httpClient,
allSettings.VersionInformation, allSettings.OpenVPN.Provider.PortForwarding.Enabled, openvpnLooper.PortForward,
)
httpServer := server.New("0.0.0.0:8000", logger, openvpnLooper, unboundLooper, updaterLooper)
controlServerAddress := fmt.Sprintf("0.0.0.0:%d", allSettings.ControlServer.Port)
httpServer := server.New(controlServerAddress, logger, openvpnLooper, unboundLooper, updaterLooper)
wg.Add(1)
go httpServer.Run(ctx, wg)

View File

@@ -110,6 +110,9 @@ type Reader interface {
// Public IP getters
GetPublicIPPeriod() (period time.Duration, err error)
// Control server
GetControlServerPort() (port uint16, err error)
GetVersionInformation() (enabled bool, err error)
GetUpdaterPeriod() (period time.Duration, err error)

13
internal/params/server.go Normal file
View File

@@ -0,0 +1,13 @@
package params
import (
libparams "github.com/qdm12/golibs/params"
)
func (r *reader) GetControlServerPort() (port uint16, err error) {
n, err := r.envParams.GetEnvIntRange("HTTP_CONTROL_SERVER_PORT", 1, 65535, libparams.Default("8000"))
if err != nil {
return 0, err
}
return uint16(n), nil
}

View File

@@ -0,0 +1,30 @@
package settings
import (
"fmt"
"strings"
"github.com/qdm12/gluetun/internal/params"
)
// ControlServer contains settings to customize the control server operation
type ControlServer struct {
Port uint16
}
func (c *ControlServer) String() string {
settingsList := []string{
"HTTP Control server:",
fmt.Sprintf("Listening port: %d", c.Port),
}
return strings.Join(settingsList, "\n |--")
}
// GetControlServerSettings obtains the HTTP control server settings from environment variables using the params package.
func GetControlServerSettings(paramsReader params.Reader) (settings ControlServer, err error) {
settings.Port, err = paramsReader.GetControlServerPort()
if err != nil {
return settings, err
}
return settings, nil
}

View File

@@ -26,6 +26,7 @@ type Settings struct {
PublicIPPeriod time.Duration
UpdaterPeriod time.Duration
VersionInformation bool
ControlServer ControlServer
}
func (s *Settings) String() string {
@@ -45,6 +46,7 @@ func (s *Settings) String() string {
s.Firewall.String(),
s.TinyProxy.String(),
s.ShadowSocks.String(),
s.ControlServer.String(),
"Public IP check period: " + s.PublicIPPeriod.String(), // TODO print disabled if 0
"Version information: " + versionInformation,
updaterLine,
@@ -95,5 +97,9 @@ func GetAllSettings(paramsReader params.Reader) (settings Settings, err error) {
if err != nil {
return settings, err
}
settings.ControlServer, err = GetControlServerSettings(paramsReader)
if err != nil {
return settings, err
}
return settings, nil
}