Add stub OpenAPI methods
This commit is contained in:
parent
0820983d81
commit
8725c1df7a
11
config.go
11
config.go
|
@ -40,6 +40,7 @@ type configuration struct {
|
|||
Filters []filter `yaml:"filters"`
|
||||
UserRules []string `yaml:"user_rules"`
|
||||
DHCP dhcpd.ServerConfig `yaml:"dhcp"`
|
||||
TLS tlsConfig `yaml:"tls"`
|
||||
|
||||
logSettings `yaml:",inline"`
|
||||
|
||||
|
@ -60,6 +61,16 @@ type dnsConfig struct {
|
|||
|
||||
var defaultDNS = []string{"tls://1.1.1.1", "tls://1.0.0.1"}
|
||||
|
||||
// field ordering is important -- yaml fields will mirror ordering from here
|
||||
type tlsConfig struct {
|
||||
ServerName string `yaml:"server_name" json:"server_name"`
|
||||
ForceHTTPS bool `yaml:"force_https" json:"force_https"`
|
||||
PortHTTPS int `yaml:"port_https" json:"port_https"`
|
||||
PortDNSOverTLS int `yaml:"port_dns_over_tls" json:"port_dns_over_tls"`
|
||||
CertificateChain string `yaml:"certificate_chain" json:"certificate_chain"`
|
||||
PrivateKey string `yaml:"private_key" json:"private_key"`
|
||||
}
|
||||
|
||||
// initialize to default values, will be changed later when reading config or parsing command line
|
||||
var config = configuration{
|
||||
ourConfigFilename: "AdGuardHome.yaml",
|
||||
|
|
26
control.go
26
control.go
|
@ -1025,6 +1025,29 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// ---
|
||||
// TLS
|
||||
// ---
|
||||
func handleTLSStatus(w http.ResponseWriter, r *http.Request) {
|
||||
err := json.NewEncoder(w).Encode(&config.TLS)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusInternalServerError, "Failed to marshal json with TLS status: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
newconfig := tlsConfig{}
|
||||
err := json.NewDecoder(r.body).Decode(&newconfig)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusBadRequest, "Failed to parse new TLS config json: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: validate before applying
|
||||
config.TLS = newconfig
|
||||
}
|
||||
|
||||
func registerInstallHandlers() {
|
||||
http.HandleFunc("/control/install/get_addresses", preInstall(ensureGET(handleInstallGetAddresses)))
|
||||
http.HandleFunc("/control/install/configure", preInstall(ensurePOST(handleInstallConfigure)))
|
||||
|
@ -1068,4 +1091,7 @@ func registerControlHandlers() {
|
|||
http.HandleFunc("/control/dhcp/interfaces", postInstall(optionalAuth(ensureGET(handleDHCPInterfaces))))
|
||||
http.HandleFunc("/control/dhcp/set_config", postInstall(optionalAuth(ensurePOST(handleDHCPSetConfig))))
|
||||
http.HandleFunc("/control/dhcp/find_active_dhcp", postInstall(optionalAuth(ensurePOST(handleDHCPFindActiveServer))))
|
||||
|
||||
http.HandleFunc("/control/tls/status", postInstall(optionalAuth(ensureGET(handleTLSStatus))))
|
||||
http.HandleFunc("/control/tls/configure", postInstall(optionalAuth(ensurePOST(handleTLSConfigure))))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue