Project

General

Profile

« Previous | Next » 

Revision 0d121100

Added by Jim Pingle almost 3 years ago

DHCP/v6 PHP8 error fixes for some cases.

If a config starts with only WAN, no LAN assigned, there are a number of
tags that were not handled properly on DHCP, DHCPv6, and RA.

Fixed up some other unrelated low-hanging fruit while I'm here, but all
of these files need a lot more work for PHP8.

View differences:

src/usr/local/www/services_dhcp.php
52 52
if (!$if || !isset($iflist[$if])) {
53 53
	$found_starting_if = false;
54 54
	// First look for an interface with DHCP already enabled.
55
	foreach ($iflist as $ifent => $ifname) {
56
		$oc = $config['interfaces'][$ifent];
57
		if (is_array($config['dhcpd'][$ifent]) &&
58
		    isset($config['dhcpd'][$ifent]['enable']) &&
59
		    is_ipaddrv4($oc['ipaddr']) && $oc['subnet'] < 31) {
55
	foreach (array_keys($iflist) as $ifent) {
56
		if (config_path_enabled("dhcpd/{$ifent}") &&
57
		    is_ipaddrv4(config_get_path("interfaces/{$ifent}/ipaddr")) &&
58
		    ((int) config_get_path("interfaces/{$ifent}/subnet", 0) < 31)) {
60 59
			$if = $ifent;
61 60
			$found_starting_if = true;
62 61
			break;
......
67 66
	 * If there is no DHCP-enabled interface and LAN is a candidate,
68 67
	 * then choose LAN.
69 68
	 */
70
	if (!$found_starting_if && isset($iflist['lan']) &&
71
	    is_ipaddrv4($config['interfaces']['lan']['ipaddr']) &&
72
	    $config['interfaces']['lan']['subnet'] < 31) {
69
	if (!$found_starting_if &&
70
	    !empty(array_get_path($iflist, 'lan')) &&
71
	    is_ipaddrv4(config_get_path("interfaces/lan/ipaddr")) &&
72
	    ((int) config_get_path("interfaces/lan/subnet", 0) < 31)) {
73 73
		$if = 'lan';
74 74
		$found_starting_if = true;
75 75
	}
76 76

  
77 77
	// At the last select whatever can be found.
78 78
	if (!$found_starting_if) {
79
		foreach ($iflist as $ifent => $ifname) {
80
			$oc = $config['interfaces'][$ifent];
81

  
79
		foreach (array_keys($iflist) as $ifent) {
82 80
			/* Not static IPv4 or subnet >= 31 */
83
			if (!is_ipaddrv4($oc['ipaddr']) ||
84
			    empty($oc['subnet']) || $oc['subnet'] < 31) {
81
			if (!is_ipaddrv4(config_get_path("interfaces/{$ifent}/ipaddr")) ||
82
			    empty($oc['subnet']) ||
83
			    ((int) config_get_path("interfaces/{$ifent}/subnet", 0) < 31)) {
85 84
				continue;
86 85
			}
87 86

  
88
			if (!is_array($config['dhcpd'][$ifent]) ||
89
			    !isset($config['dhcpd'][$ifent]['enable'])) {
87
			if (!config_path_enabled("dhcpd/{$ifent}")) {
90 88
				continue;
91 89
			}
92 90

  
......
100 98

  
101 99
$a_pools = array();
102 100

  
103
if (is_array($config['dhcpd'][$if])) {
101
if (!empty(config_get_path("dhcpd/{$if}"))) {
104 102
	$pool = $_REQUEST['pool'];
105 103
	if (is_numeric($_POST['pool'])) {
106 104
		$pool = $_POST['pool'];
......
781 779
	$retvaldns = 0;
782 780
	/* dnsmasq_configure calls dhcpd_configure */
783 781
	/* no need to restart dhcpd twice */
784
	if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
782
	if (config_path_enabled('dnsmasq') &&
783
	    config_path_enabled('dnsmasq', 'regdhcpstatic')) {
785 784
		$retvaldns |= services_dnsmasq_configure();
786 785
		if ($retvaldns == 0) {
787 786
			clear_subsystem_dirty('hosts');
788 787
			clear_subsystem_dirty('staticmaps');
789 788
		}
790
	} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
789
	} elseif (config_path_enabled('unbound') &&
790
		  config_path_enabled('unbound', 'regdhcpstatic')) {
791 791
		$retvaldns |= services_unbound_configure();
792 792
		if ($retvaldns == 0) {
793 793
			clear_subsystem_dirty('unbound');
......
804 804
	if (!function_exists('is_package_installed')) {
805 805
		require_once('pkg-utils.inc');
806 806
	}
807
	if (is_package_installed('pfSense-pkg-bind') && isset($config['installedpackages']['bind']['config'][0]['enable_bind'])) {
807
	if (is_package_installed('pfSense-pkg-bind') &&
808
	    config_path_enabled('installedpackages/bind/config/0', 'enable_bind')) {
808 809
		$reloadbind = false;
809
		if (is_array($config['installedpackages']['bindzone'])) {
810
			$bindzone = $config['installedpackages']['bindzone']['config'];
811
		} else {
812
			$bindzone = array();
813
		}
810
		$bindzone = config_get_path('installedpackages/bindzone/config', []);
811

  
814 812
		for ($x = 0; $x < sizeof($bindzone); $x++) {
815 813
			$zone = $bindzone[$x];
816 814
			if ($zone['regdhcpstatic'] == 'on') {
......
1059 1057

  
1060 1058
if (is_numeric($pool) || ($act == "newpool")) {
1061 1059
	$rangestr .= '<br />' . gettext('In-use DHCP Pool Ranges:');
1062
	if (is_array($config['dhcpd'][$if]['range'])) {
1063
		$rangestr .= '<br />' . $config['dhcpd'][$if]['range']['from'] . ' - ' . $config['dhcpd'][$if]['range']['to'];
1060
	$rangearr = config_get_path("dhcpd/{$if}/range", []);
1061
	if (!empty($rangearr)) {
1062
		$rangestr .= '<br />' . array_get_path($rangearr, 'from') . ' - ' . array_get_path($rangearr, 'to');
1064 1063
	}
1065 1064

  
1066 1065
	foreach ($a_pools as $p) {
1067
		if (is_array($p['range'])) {
1068
			$rangestr .= '<br />' . $p['range']['from'] . ' - ' . $p['range']['to'];
1066
		$pa = array_get_path($p, 'range', []);
1067
		if (!empty($pa)) {
1068
			$rangestr .= '<br />' . array_get_path($pa, 'from') . ' - ' . array_get_path($pa, 'to');
1069 1069
		}
1070 1070
	}
1071 1071
}

Also available in: Unified diff