From 1c6d837a801cefe5a3a0cb30b5108ae17da0106b Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 3 Dec 2020 10:29:11 +0000 Subject: [PATCH] Bugfix: handle subnetmask null value --- ajax/networking/get_netcfg.php | 2 +- includes/dhcp.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ajax/networking/get_netcfg.php b/ajax/networking/get_netcfg.php index 7ba5dcf6..2dd330bb 100644 --- a/ajax/networking/get_netcfg.php +++ b/ajax/networking/get_netcfg.php @@ -46,7 +46,7 @@ if (isset($interface)) { preg_match('/static\sdomain_name_server=(.*)/', $matched[0], $static_dns); preg_match('/fallback\sstatic_'.$interface.'/', $matched[0], $fallback); $dhcpdata['Metric'] = $metric[1]; - $dhcpdata['StaticIP'] = substr($static_ip[1], 0, strpos($static_ip[1],'/')); + $dhcpdata['StaticIP'] = strpos($static_ip[1],'/') ? substr($static_ip[1], 0, strpos($static_ip[1],'/')) : $static_ip[1]; $dhcpdata['SubnetMask'] = cidr2mask($static_ip[1]); $dhcpdata['StaticRouters'] = $static_routers[1]; $dhcpdata['StaticDNS'] = $static_dns[1]; diff --git a/includes/dhcp.php b/includes/dhcp.php index 071caa1d..e16d4194 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -187,7 +187,8 @@ function UpdateDHCPConfig($iface,$status) $cfg[] = '# RaspAP '.$iface.' configuration'; $cfg[] = 'interface '.$iface; if (isset($_POST['StaticIP'])) { - $cfg[] = 'static ip_address='.$_POST['StaticIP'].'/'.mask2cidr($_POST['SubnetMask']); + $mask = ($_POST['SubnetMask'] !== '' && $_POST['SubnetMask'] !== '0.0.0.0') ? '/'.mask2cidr($_POST['SubnetMask']) : null; + $cfg[] = 'static ip_address='.$_POST['StaticIP'].$mask; } if (isset($_POST['DefaultGateway'])) { $cfg[] = 'static routers='.$_POST['DefaultGateway'];