Fix #261 add variable HTTP_CONTROL_SERVER_PORT
This commit is contained in:
@@ -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 |
|
| `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 |
|
| `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
|
### Other
|
||||||
|
|
||||||
| Variable | Default | Choices | Description |
|
| Variable | Default | Choices | Description |
|
||||||
|
|||||||
@@ -236,8 +236,8 @@ func _main(background context.Context, args []string) int { //nolint:gocognit,go
|
|||||||
unboundLooper, updaterLooper, publicIPLooper, routingConf, logger, httpClient,
|
unboundLooper, updaterLooper, publicIPLooper, routingConf, logger, httpClient,
|
||||||
allSettings.VersionInformation, allSettings.OpenVPN.Provider.PortForwarding.Enabled, openvpnLooper.PortForward,
|
allSettings.VersionInformation, allSettings.OpenVPN.Provider.PortForwarding.Enabled, openvpnLooper.PortForward,
|
||||||
)
|
)
|
||||||
|
controlServerAddress := fmt.Sprintf("0.0.0.0:%d", allSettings.ControlServer.Port)
|
||||||
httpServer := server.New("0.0.0.0:8000", logger, openvpnLooper, unboundLooper, updaterLooper)
|
httpServer := server.New(controlServerAddress, logger, openvpnLooper, unboundLooper, updaterLooper)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go httpServer.Run(ctx, wg)
|
go httpServer.Run(ctx, wg)
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ type Reader interface {
|
|||||||
// Public IP getters
|
// Public IP getters
|
||||||
GetPublicIPPeriod() (period time.Duration, err error)
|
GetPublicIPPeriod() (period time.Duration, err error)
|
||||||
|
|
||||||
|
// Control server
|
||||||
|
GetControlServerPort() (port uint16, err error)
|
||||||
|
|
||||||
GetVersionInformation() (enabled bool, err error)
|
GetVersionInformation() (enabled bool, err error)
|
||||||
|
|
||||||
GetUpdaterPeriod() (period time.Duration, err error)
|
GetUpdaterPeriod() (period time.Duration, err error)
|
||||||
|
|||||||
13
internal/params/server.go
Normal file
13
internal/params/server.go
Normal 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
|
||||||
|
}
|
||||||
30
internal/settings/server.go
Normal file
30
internal/settings/server.go
Normal 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
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ type Settings struct {
|
|||||||
PublicIPPeriod time.Duration
|
PublicIPPeriod time.Duration
|
||||||
UpdaterPeriod time.Duration
|
UpdaterPeriod time.Duration
|
||||||
VersionInformation bool
|
VersionInformation bool
|
||||||
|
ControlServer ControlServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) String() string {
|
func (s *Settings) String() string {
|
||||||
@@ -45,6 +46,7 @@ func (s *Settings) String() string {
|
|||||||
s.Firewall.String(),
|
s.Firewall.String(),
|
||||||
s.TinyProxy.String(),
|
s.TinyProxy.String(),
|
||||||
s.ShadowSocks.String(),
|
s.ShadowSocks.String(),
|
||||||
|
s.ControlServer.String(),
|
||||||
"Public IP check period: " + s.PublicIPPeriod.String(), // TODO print disabled if 0
|
"Public IP check period: " + s.PublicIPPeriod.String(), // TODO print disabled if 0
|
||||||
"Version information: " + versionInformation,
|
"Version information: " + versionInformation,
|
||||||
updaterLine,
|
updaterLine,
|
||||||
@@ -95,5 +97,9 @@ func GetAllSettings(paramsReader params.Reader) (settings Settings, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return settings, err
|
return settings, err
|
||||||
}
|
}
|
||||||
|
settings.ControlServer, err = GetControlServerSettings(paramsReader)
|
||||||
|
if err != nil {
|
||||||
|
return settings, err
|
||||||
|
}
|
||||||
return settings, nil
|
return settings, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user