@@ -110,37 +110,33 @@ function saveDHCPConfig($status)
110110 $ dnsmasq = new DnsmasqManager ();
111111 $ iface = $ _POST ['interface ' ];
112112
113- // dhcp
114- if (! isset ( $ _POST [ ' dhcp-iface ' ]) && file_exists ( RASPI_DNSMASQ_PREFIX . $ iface . ' .conf ' )) {
115- // remove dhcp + dnsmasq configs for selected interface
116- $ return = $ dhcpcd ->remove ($ iface , $ status );
117- $ return = $ dnsmasq -> remove ( $ iface , $ status );
113+ // Always save dhcpcd static IP config
114+ $ errors = $ dhcpcd -> validate ( $ _POST );
115+ if ( empty ( $ errors )) {
116+ $ dhcp_cfg = $ dhcpcd ->buildConfigEx ($ iface, $ _POST , $ status );
117+ $ dhcpcd -> saveConfig ( $ dhcp_cfg , $ iface , $ status );
118118 } else {
119- $ errors = $ dhcpcd ->validate ($ _POST );
119+ foreach ($ errors as $ error ) {
120+ $ status ->addMessage ($ error , 'danger ' );
121+ }
122+ }
123+
124+ // dnsmasq: remove if DHCP was previously enabled but now disabled
125+ if (!isset ($ _POST ['dhcp-iface ' ]) && file_exists (RASPI_DNSMASQ_PREFIX .$ iface .'.conf ' )) {
126+ $ dnsmasq ->remove ($ iface , $ status );
127+ } elseif (($ _POST ['dhcp-iface ' ] ?? '' ) == "1 " || isset ($ _POST ['mac ' ])) {
128+ $ errors = $ dnsmasq ->validate ($ _POST );
120129 if (empty ($ errors )) {
121- $ dhcp_cfg = $ dhcpcd ->buildConfigEx ($ iface , $ _POST , $ status );
122- $ dhcpcd ->saveConfig ($ dhcp_cfg , $ iface , $ status );
130+ $ config = $ dnsmasq ->buildConfigEx ($ iface , $ _POST );
131+ $ return = $ dnsmasq ->saveConfig ($ config , $ iface );
132+ $ config = $ dnsmasq ->buildDefault ($ _POST );
133+ $ return = $ dnsmasq ->saveConfigDefault ($ config );
123134 } else {
124135 foreach ($ errors as $ error ) {
125136 $ status ->addMessage ($ error , 'danger ' );
126137 }
127138 }
128-
129- // dnsmasq
130- if (($ _POST ['dhcp-iface ' ] == "1 " ) || (isset ($ _POST ['mac ' ]))) {
131- $ errors = $ dnsmasq ->validate ($ _POST );
132- if (empty ($ errors )) {
133- $ config = $ dnsmasq ->buildConfigEx ($ iface , $ _POST );
134- $ return = $ dnsmasq ->saveConfig ($ config , $ iface );
135- $ config = $ dnsmasq ->buildDefault ($ _POST );
136- $ return = $ dnsmasq ->saveConfigDefault ($ config );
137- } else {
138- foreach ($ errors as $ error ) {
139- $ status ->addMessage ($ error , 'danger ' );
140- }
141- }
142- }
143- return true ;
144139 }
140+ return true ;
145141}
146142
0 commit comments