Bugfix: handle subnetmask null value

This commit is contained in:
billz 2020-12-03 10:29:11 +00:00
parent 8420bbb0da
commit 1c6d837a80
2 changed files with 3 additions and 2 deletions

View File

@ -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];

View File

@ -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'];