diff --git a/dhcp-clients-webapp-backend/pkg/uibackend/types.go b/dhcp-clients-webapp-backend/pkg/uibackend/types.go index 36aa3b4..6b4c44f 100644 --- a/dhcp-clients-webapp-backend/pkg/uibackend/types.go +++ b/dhcp-clients-webapp-backend/pkg/uibackend/types.go @@ -132,12 +132,12 @@ func (b *AddonConfig) UnmarshalJSON(data []byte) error { // JSON parse var cfg struct { - IpAddressReservations []struct { + DhcpIpAddressReservations []struct { Name string `json:"name"` Mac string `json:"mac"` IP string `json:"ip"` Link string `json:"link"` - } `json:"ip_address_reservations"` + } `json:"dhcp_ip_address_reservations"` DhcpClientsFriendlyNames []struct { Name string `json:"name"` @@ -145,18 +145,18 @@ func (b *AddonConfig) UnmarshalJSON(data []byte) error { Link string `json:"link"` } `json:"dhcp_clients_friendly_names"` - DhcpRange struct { - StartIP string `json:"start_ip"` - EndIP string `json:"end_ip"` - } `json:"dhcp_range"` - - LogDHCP bool `json:"log_dhcp"` - LogWebUI bool `json:"log_web_ui"` - - WebUIPort int `json:"web_ui_port"` - - DefaultLease string `json:"default_lease"` - AddressReservationLease string `json:"address_reservation_lease"` + DhcpServer struct { + StartIP string `json:"start_ip"` + EndIP string `json:"end_ip"` + LogDHCP bool `json:"log_requests"` + DefaultLease string `json:"default_lease"` + AddressReservationLease string `json:"address_reservation_lease"` + } `json:"dhcp_server"` + + WebUI struct { + Log bool `json:"log_requests"` + Port int `json:"port"` + } `json:"web_ui"` } err := json.Unmarshal(data, &cfg) if err != nil { @@ -164,19 +164,19 @@ func (b *AddonConfig) UnmarshalJSON(data []byte) error { } // convert DHCP IP strings to net.IP - b.dhcpStartIP = net.ParseIP(cfg.DhcpRange.StartIP) - b.dhcpEndIP = net.ParseIP(cfg.DhcpRange.EndIP) + b.dhcpStartIP = net.ParseIP(cfg.DhcpServer.StartIP) + b.dhcpEndIP = net.ParseIP(cfg.DhcpServer.EndIP) if b.dhcpStartIP == nil || b.dhcpEndIP == nil { return fmt.Errorf("invalid DHCP range found in addon config file") } // ensure we have a valid port for web UI - if cfg.WebUIPort <= 0 || cfg.WebUIPort > 32768 { - return fmt.Errorf("invalid web UI port number: %d", cfg.WebUIPort) + if cfg.WebUI.Port <= 0 || cfg.WebUI.Port > 32768 { + return fmt.Errorf("invalid web UI port number: %d", cfg.WebUI.Port) } // convert IP address reservations to a map indexed by IP - for _, r := range cfg.IpAddressReservations { + for _, r := range cfg.DhcpIpAddressReservations { ipAddr, err := netip.ParseAddr(r.IP) if err != nil { return fmt.Errorf("invalid IP address found inside 'ip_address_reservations': %s", r.IP) @@ -232,11 +232,11 @@ func (b *AddonConfig) UnmarshalJSON(data []byte) error { } // copy basic settings - b.logDHCP = cfg.LogDHCP - b.logWebUI = cfg.LogWebUI - b.webUIPort = cfg.WebUIPort - b.defaultLease = cfg.DefaultLease - b.addressReservationLease = cfg.AddressReservationLease + b.logDHCP = cfg.DhcpServer.LogDHCP + b.logWebUI = cfg.WebUI.Log + b.webUIPort = cfg.WebUI.Port + b.defaultLease = cfg.DhcpServer.DefaultLease + b.addressReservationLease = cfg.DhcpServer.AddressReservationLease return nil } diff --git a/rootfs/etc/cont-init.d/10-dnsmasq.sh b/rootfs/etc/cont-init.d/10-dnsmasq.sh index 1fdc7de..f0f0856 100755 --- a/rootfs/etc/cont-init.d/10-dnsmasq.sh +++ b/rootfs/etc/cont-init.d/10-dnsmasq.sh @@ -27,7 +27,7 @@ function ipvalid() { } function dnsresolve() { - NTP_SERVERS="$(jq --raw-output '.network.ntp[]' ${ADDON_CONFIG} 2>/dev/null)" + NTP_SERVERS="$(jq --raw-output '.dhcp_network.ntp[]' ${ADDON_CONFIG} 2>/dev/null)" if [[ ! -z "${NTP_SERVERS}" ]]; then bashio::log.info "NTP servers are ${NTP_SERVERS/$'\n'/,}" @@ -52,7 +52,7 @@ function dnsresolve() { NTP_SERVERS_RESOLVED=${NTP_SERVERS_RESOLVED::-1} # add DNS-resolved IP addresses - jq -c ".network.ntp_resolved=[$NTP_SERVERS_RESOLVED]" ${ADDON_CONFIG} >${ADDON_CONFIG_RESOLVED} + jq -c ".dhcp_network.ntp_resolved=[$NTP_SERVERS_RESOLVED]" ${ADDON_CONFIG} >${ADDON_CONFIG_RESOLVED} fi else cp ${ADDON_CONFIG} ${ADDON_CONFIG_RESOLVED} @@ -84,7 +84,7 @@ function reset_dhcp_leases_database_if_just_rebooted() { fi } -should_reset_on_reboot=$(bashio::config 'reset_dhcp_lease_database_on_reboot') +should_reset_on_reboot=$(bashio::config '.dhcp_server.reset_dhcp_lease_database_on_reboot') if $should_reset_on_reboot ; then reset_dhcp_leases_database_if_just_rebooted fi diff --git a/test-options.json b/test-options.json index 0126460..548a459 100644 --- a/test-options.json +++ b/test-options.json @@ -1,7 +1,6 @@ { - "default_lease": "12h", - "address_reservation_lease": "24h", - "ip_address_reservations": [ + "interface": "enp3s0", + "dhcp_ip_address_reservations": [ { "mac": "aa:bb:cc:dd:ee:00", "name": "static-ip-important-host", @@ -22,21 +21,24 @@ "link": "https://{{ .ip }}/page-{{ .hostname }}" } ], - "dhcp_range": { + "dhcp_server": { + "default_lease": "12h", + "address_reservation_lease": "24h", "start_ip": "192.168.1.50", - "end_ip": "192.168.1.100" + "end_ip": "192.168.1.100", + "log_requests": true, + "reset_dhcp_lease_database_on_reboot": false }, - "network": { + "dhcp_network": { "broadcast": "192.168.1.255", "gateway": "192.168.1.254", - "interface": "enp3s0", "netmask": "255.255.255.0", "subnet": "192.168.1.0", - "dns": [ + "dns_servers": [ "8.8.8.8", "8.8.4.4" ], - "ntp": [ + "ntp_servers": [ "0.2.3.4", "ntp.pool.org", "0.europe.ntp.pool.org", @@ -45,7 +47,17 @@ "1.2.3.4" ] }, - "log_dhcp": true, - "log_web_ui": true, - "web_ui_port": 8976 + "dns_server": { + "enable": true, + "cache_size": 10000, + "log_requests": true + }, + "dns_upstream_servers": [ + "8.8.8.8", + "8.8.4.4" + ], + "web_ui": { + "log_requests": true, + "port": 8976 + } } diff --git a/test-startepoch b/test-startepoch index cea02ba..1266820 100644 --- a/test-startepoch +++ b/test-startepoch @@ -1 +1 @@ -1730118060 +1733260315