HTTP_CONTROL_SERVER_LOG variable, fixes #249
This commit is contained in:
@@ -260,6 +260,7 @@ That one is important if you want to connect to the container from your LAN for
|
||||
| Variable | Default | Choices | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `HTTP_CONTROL_SERVER_PORT` | `8000` | `1` to `65535` | Listening port for the HTTP control server |
|
||||
| `HTTP_CONTROL_SERVER_LOG` | `on` | `on` or `off` | Enable logging of HTTP requests |
|
||||
|
||||
### Other
|
||||
|
||||
|
||||
@@ -237,7 +237,8 @@ func _main(background context.Context, args []string) int { //nolint:gocognit,go
|
||||
allSettings.VersionInformation, allSettings.OpenVPN.Provider.PortForwarding.Enabled, openvpnLooper.PortForward,
|
||||
)
|
||||
controlServerAddress := fmt.Sprintf("0.0.0.0:%d", allSettings.ControlServer.Port)
|
||||
httpServer := server.New(controlServerAddress, logger, openvpnLooper, unboundLooper, updaterLooper)
|
||||
controlServerLogging := allSettings.ControlServer.Log
|
||||
httpServer := server.New(controlServerAddress, controlServerLogging, logger, openvpnLooper, unboundLooper, updaterLooper)
|
||||
wg.Add(1)
|
||||
go httpServer.Run(ctx, wg)
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ type Reader interface {
|
||||
|
||||
// Control server
|
||||
GetControlServerPort() (port uint16, err error)
|
||||
GetControlServerLog() (enabled bool, err error)
|
||||
|
||||
GetVersionInformation() (enabled bool, err error)
|
||||
|
||||
|
||||
@@ -11,3 +11,7 @@ func (r *reader) GetControlServerPort() (port uint16, err error) {
|
||||
}
|
||||
return uint16(n), nil
|
||||
}
|
||||
|
||||
func (r *reader) GetControlServerLog() (enabled bool, err error) {
|
||||
return r.envParams.GetOnOff("HTTP_CONTROL_SERVER_LOG", libparams.Default("on"))
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ type Server interface {
|
||||
|
||||
type server struct {
|
||||
address string
|
||||
logging bool
|
||||
logger logging.Logger
|
||||
openvpnLooper openvpn.Looper
|
||||
unboundLooper dns.Looper
|
||||
@@ -27,9 +28,10 @@ type server struct {
|
||||
lookupIP func(host string) ([]net.IP, error)
|
||||
}
|
||||
|
||||
func New(address string, logger logging.Logger, openvpnLooper openvpn.Looper, unboundLooper dns.Looper, updaterLooper updater.Looper) Server {
|
||||
func New(address string, logging bool, logger logging.Logger, openvpnLooper openvpn.Looper, unboundLooper dns.Looper, updaterLooper updater.Looper) Server {
|
||||
return &server{
|
||||
address: address,
|
||||
logging: logging,
|
||||
logger: logger.WithPrefix("http server: "),
|
||||
openvpnLooper: openvpnLooper,
|
||||
unboundLooper: unboundLooper,
|
||||
@@ -60,7 +62,7 @@ func (s *server) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
|
||||
func (s *server) makeHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet || r.RequestURI != "/health" {
|
||||
if s.logging && (r.Method != http.MethodGet || r.RequestURI != "/health") {
|
||||
s.logger.Info("HTTP %s %s", r.Method, r.RequestURI)
|
||||
}
|
||||
switch r.Method {
|
||||
|
||||
@@ -10,12 +10,14 @@ import (
|
||||
// ControlServer contains settings to customize the control server operation
|
||||
type ControlServer struct {
|
||||
Port uint16
|
||||
Log bool
|
||||
}
|
||||
|
||||
func (c *ControlServer) String() string {
|
||||
settingsList := []string{
|
||||
"HTTP Control server:",
|
||||
fmt.Sprintf("Listening port: %d", c.Port),
|
||||
fmt.Sprintf("Logging: %t", c.Log),
|
||||
}
|
||||
return strings.Join(settingsList, "\n |--")
|
||||
}
|
||||
@@ -26,5 +28,9 @@ func GetControlServerSettings(paramsReader params.Reader) (settings ControlServe
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
settings.Log, err = paramsReader.GetControlServerLog()
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
return settings, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user