Project

General

Profile

« Previous | Next » 

Revision 3f257101

Added by Renato Botelho almost 11 years ago

Provide upgrade config code to migrate unbound settings from 2.1 package to 2.2 base. Bump config version to 11.1. It fixes #3880

View differences:

etc/inc/upgrade_config.inc
3374 3374
	}
3375 3375
}
3376 3376

  
3377
function upgrade_110_to_111() {
3378
	global $config;
3379

  
3380
	if (!isset($config['installedpackages']['unbound']['config'][0]))
3381
		return;
3382

  
3383
	$pkg = $config['installedpackages']['unbound']['config'][0];
3384

  
3385
	if (isset($config['installedpackages']['unboundadvanced']['config'][0]))
3386
		$pkg = array_merge($pkg, $config['installedpackages']['unboundadvanced']['config'][0]);
3387

  
3388
	$new = array();
3389

  
3390
	/* deal first with boolean fields */
3391
	$fields = array(
3392
		"enable" => "enable",
3393
		"dnssec_status" => "dnssec",
3394
		"forwarding_mode" => "forwarding",
3395
		"regdhcp" => "regdhcp",
3396
		"regdhcpstatic" => "regdhcpstatic",
3397
		"txtsupport" => "txtsupport",
3398
		"hide_id" => "hideidentity",
3399
		"hide_version" => "hideversion",
3400
		"prefetch" => "prefetch",
3401
		"prefetch_key" => "prefetchkey",
3402
		"harden_glue" => "hardenglue",
3403
		"harden_dnssec_stripped" => "dnssec_stripped");
3404

  
3405
	foreach ($fields as $oldk => $newk) {
3406
		if (isset($pkg[$oldk])) {
3407
			if ($pkg[$oldk] == 'on')
3408
				$new[$newk] = true;
3409
			unset($pkg[$oldk]);
3410
		}
3411
	}
3412

  
3413
	$fields = array(
3414
		"active_interface" => "network_interface",
3415
		"query_interface" => "outgoing_interface",
3416
		"unbound_verbosity" => "log_verbosity",
3417
		"unbound_verbosity" => "log_verbosity",
3418
		"msg_cache_size" => "msgcachesize",
3419
		"outgoing_num_tcp" => "outgoing_num_tcp",
3420
		"incoming_num_tcp" => "incoming_num_tcp",
3421
		"edns_buffer_size" => "edns_buffer_size",
3422
		"num_queries_per_thread" => "num_queries_per_thread",
3423
		"jostle_timeout" => "jostle_timeout",
3424
		"cache_max_ttl" => "cache_max_ttl",
3425
		"cache_min_ttl" => "cache_min_ttl",
3426
		"infra_host_ttl" => "infra_host_ttl",
3427
		"infra_cache_numhosts" => "infra_cache_numhosts",
3428
		"unwanted_reply_threshold" => "unwanted_reply_threshold",
3429
		"custom_options" => "custom_options");
3430

  
3431
	foreach ($fields as $oldk => $newk) {
3432
		if (isset($pkg[$oldk])) {
3433
			$new[$newk] = $pkg[$oldk];
3434
			unset($pkg[$oldk]);
3435
		}
3436
	}
3437

  
3438
	/* Following options were removed, bring them as custom_options */
3439
	if (isset($pkg['stats']) && $pkg['stats'] == "on") {
3440
		if (isset($pkg['stats_interval']))
3441
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : ";") . "statistics-interval: {$pkg['stats_interval']}";
3442
		if (isset($pkg['cumulative_stats']))
3443
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : ";") . "statistics-cumulative: {$pkg['cumulative_stats']}";
3444
		if (isset($pkg['extended_stats']) && $pkg['extended_stats'] == "on")
3445
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : ";") . "extended-statistics: yes";
3446
		else
3447
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : ";") . "extended-statistics: no";
3448
	}
3449

  
3450
	$new['acls'] = array();
3451
	if (isset($config['installedpackages']['unboundacls']['config']) &&
3452
	    is_array($config['installedpackages']['unboundacls']['config'])) {
3453
		foreach ($config['installedpackages']['unboundacls']['config'] as $acl)
3454
			$new['acls'][] = $acl;
3455
	}
3456

  
3457
	$config['unbound'] = $new;
3458

  
3459
	if(isset($config['installedpackages']['unbound']))
3460
		unset($config['installedpackages']['unbound']);
3461
	if(isset($config['installedpackages']['unboundadvanced']))
3462
		unset($config['installedpackages']['unboundadvanced']);
3463
	if(isset($config['installedpackages']['unboundacls']))
3464
		unset($config['installedpackages']['unboundacls']);
3465

  
3466
	unset($pkg, $new);
3467
}
3468

  
3377 3469
?>

Also available in: Unified diff