Loops and HTTP control server rework (#308)
- CRUD REST HTTP server - `/v1` HTTP server prefix - Retrocompatible with older routes (redirects to v1 or handles the requests directly) - DNS, Updater and Openvpn refactored to have a REST-like state with new methods to change their states synchronously - Openvpn, Unbound and Updater status, see #287
This commit is contained in:
@@ -12,9 +12,9 @@ import (
|
||||
// OpenVPN contains settings to configure the OpenVPN client.
|
||||
type OpenVPN struct {
|
||||
User string `json:"user"`
|
||||
Password string `json:"-"`
|
||||
Password string `json:"password"`
|
||||
Verbosity int `json:"verbosity"`
|
||||
Root bool `json:"runAsRoot"`
|
||||
Root bool `json:"run_as_root"`
|
||||
Cipher string `json:"cipher"`
|
||||
Auth string `json:"auth"`
|
||||
Provider models.ProviderSettings `json:"provider"`
|
||||
|
||||
@@ -20,7 +20,7 @@ func Test_OpenVPN_JSON(t *testing.T) {
|
||||
data, err := json.Marshal(in)
|
||||
require.NoError(t, err)
|
||||
//nolint:lll
|
||||
assert.Equal(t, `{"user":"","verbosity":0,"runAsRoot":true,"cipher":"","auth":"","provider":{"name":"name","serverSelection":{"networkProtocol":"","regions":null,"group":"","countries":null,"cities":null,"hostnames":null,"isps":null,"owned":false,"customPort":0,"numbers":null,"encryptionPreset":""},"extraConfig":{"encryptionPreset":"","openvpnIPv6":false},"portForwarding":{"enabled":false,"filepath":""}}}`, string(data))
|
||||
assert.Equal(t, `{"user":"","password":"","verbosity":0,"run_as_root":true,"cipher":"","auth":"","provider":{"name":"name","server_selection":{"network_protocol":"","regions":null,"group":"","countries":null,"cities":null,"hostnames":null,"isps":null,"owned":false,"custom_port":0,"numbers":null,"encryption_preset":""},"extra_config":{"encryption_preset":"","openvpn_ipv6":false},"port_forwarding":{"enabled":false,"filepath":""}}}`, string(data))
|
||||
var out OpenVPN
|
||||
err = json.Unmarshal(data, &out)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -24,7 +23,7 @@ type Settings struct {
|
||||
HTTPProxy HTTPProxy
|
||||
ShadowSocks ShadowSocks
|
||||
PublicIPPeriod time.Duration
|
||||
UpdaterPeriod time.Duration
|
||||
Updater Updater
|
||||
VersionInformation bool
|
||||
ControlServer ControlServer
|
||||
}
|
||||
@@ -34,10 +33,6 @@ func (s *Settings) String() string {
|
||||
if s.VersionInformation {
|
||||
versionInformation = enabled
|
||||
}
|
||||
updaterLine := "Updater: disabled"
|
||||
if s.UpdaterPeriod > 0 {
|
||||
updaterLine = fmt.Sprintf("Updater period: %s", s.UpdaterPeriod)
|
||||
}
|
||||
return strings.Join([]string{
|
||||
"Settings summary below:",
|
||||
s.OpenVPN.String(),
|
||||
@@ -47,9 +42,9 @@ func (s *Settings) String() string {
|
||||
s.HTTPProxy.String(),
|
||||
s.ShadowSocks.String(),
|
||||
s.ControlServer.String(),
|
||||
s.Updater.String(),
|
||||
"Public IP check period: " + s.PublicIPPeriod.String(), // TODO print disabled if 0
|
||||
"Version information: " + versionInformation,
|
||||
updaterLine,
|
||||
"", // new line at the end
|
||||
}, "\n")
|
||||
}
|
||||
@@ -93,7 +88,7 @@ func GetAllSettings(paramsReader params.Reader) (settings Settings, err error) {
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
settings.UpdaterPeriod, err = paramsReader.GetUpdaterPeriod()
|
||||
settings.Updater, err = GetUpdaterSettings(paramsReader)
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
|
||||
59
internal/settings/updater.go
Normal file
59
internal/settings/updater.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/params"
|
||||
)
|
||||
|
||||
type Updater struct {
|
||||
Period time.Duration `json:"period"`
|
||||
DNSAddress string `json:"dns_address"`
|
||||
Cyberghost bool `json:"cyberghost"`
|
||||
Mullvad bool `json:"mullvad"`
|
||||
Nordvpn bool `json:"nordvpn"`
|
||||
PIA bool `json:"pia"`
|
||||
Privado bool `json:"privado"`
|
||||
Purevpn bool `json:"purevpn"`
|
||||
Surfshark bool `json:"surfshark"`
|
||||
Vyprvpn bool `json:"vyprvpn"`
|
||||
Windscribe bool `json:"windscribe"`
|
||||
// The two below should be used in CLI mode only
|
||||
Stdout bool `json:"-"` // in order to update constants file (maintainer side)
|
||||
CLI bool `json:"-"`
|
||||
}
|
||||
|
||||
// GetUpdaterSettings obtains the server updater settings using the params functions.
|
||||
func GetUpdaterSettings(paramsReader params.Reader) (settings Updater, err error) {
|
||||
settings = Updater{
|
||||
Cyberghost: true,
|
||||
Mullvad: true,
|
||||
Nordvpn: true,
|
||||
PIA: true,
|
||||
Purevpn: true,
|
||||
Surfshark: true,
|
||||
Vyprvpn: true,
|
||||
Windscribe: true,
|
||||
Stdout: false,
|
||||
CLI: false,
|
||||
DNSAddress: "127.0.0.1",
|
||||
}
|
||||
settings.Period, err = paramsReader.GetUpdaterPeriod()
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
return settings, nil
|
||||
}
|
||||
|
||||
func (s *Updater) String() string {
|
||||
if s.Period == 0 {
|
||||
return "Server updater settings: disabled"
|
||||
}
|
||||
settingsList := []string{
|
||||
"Server updater settings:",
|
||||
fmt.Sprintf("Period: %s", s.Period),
|
||||
}
|
||||
return strings.Join(settingsList, "\n|--")
|
||||
}
|
||||
Reference in New Issue
Block a user