Project

General

Profile

Download (120 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	upgrade_config.inc
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	are permitted provided that the following conditions are met:
10
 *
11
 *	1. Redistributions of source code must retain the above copyright notice,
12
 *		this list of conditions and the following disclaimer.
13
 *
14
 *	2. Redistributions in binary form must reproduce the above copyright
15
 *		notice, this list of conditions and the following disclaimer in
16
 *		the documentation and/or other materials provided with the
17
 *		distribution.
18
 *
19
 *	3. All advertising materials mentioning features or use of this software
20
 *		must display the following acknowledgment:
21
 *		"This product includes software developed by the pfSense Project
22
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
23
 *
24
 *	4. The names "pfSense" and "pfSense Project" must not be used to
25
 *		 endorse or promote products derived from this software without
26
 *		 prior written permission. For written permission, please contact
27
 *		 coreteam@pfsense.org.
28
 *
29
 *	5. Products derived from this software may not be called "pfSense"
30
 *		nor may "pfSense" appear in their names without prior written
31
 *		permission of the Electric Sheep Fencing, LLC.
32
 *
33
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35
 *
36
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52
 *	====================================================================
53
 *
54
 */
55
/*
56
	pfSense_BUILDER_BINARIES:	/usr/bin/find	/bin/cd	/usr/local/bin/rrdtool	/usr/bin/nice
57
	pfSense_MODULE:	config
58
*/
59

    
60
if (!function_exists("dump_rrd_to_xml")) {
61
	require("rrd.inc");
62
}
63

    
64
/* Upgrade functions must be named:
65
*    upgrade_XXX_to_YYY
66
	* where XXX == previous version, zero padded, and YYY == next version, zero padded
67
	*/
68
function upgrade_010_to_011() {
69
	global $config;
70
	$opti = 1;
71
	$ifmap = array('lan' => 'lan', 'wan' => 'wan', 'pptp' => 'pptp');
72

    
73
	/* convert DMZ to optional, if necessary */
74
	if (isset($config['interfaces']['dmz'])) {
75

    
76
		$dmzcfg = &$config['interfaces']['dmz'];
77

    
78
		if ($dmzcfg['if']) {
79
			$config['interfaces']['opt' . $opti] = array();
80
			$optcfg = &$config['interfaces']['opt' . $opti];
81

    
82
			$optcfg['enable'] = $dmzcfg['enable'];
83
			$optcfg['descr'] = "DMZ";
84
			$optcfg['if'] = $dmzcfg['if'];
85
			$optcfg['ipaddr'] = $dmzcfg['ipaddr'];
86
			$optcfg['subnet'] = $dmzcfg['subnet'];
87

    
88
			$ifmap['dmz'] = "opt" . $opti;
89
			$opti++;
90
		}
91

    
92
		unset($config['interfaces']['dmz']);
93
	}
94

    
95
	/* convert WLAN1/2 to optional, if necessary */
96
	for ($i = 1; isset($config['interfaces']['wlan' . $i]); $i++) {
97

    
98
		if (!$config['interfaces']['wlan' . $i]['if']) {
99
			unset($config['interfaces']['wlan' . $i]);
100
			continue;
101
		}
102

    
103
		$wlancfg = &$config['interfaces']['wlan' . $i];
104
		$config['interfaces']['opt' . $opti] = array();
105
		$optcfg = &$config['interfaces']['opt' . $opti];
106

    
107
		$optcfg['enable'] = $wlancfg['enable'];
108
		$optcfg['descr'] = "WLAN" . $i;
109
		$optcfg['if'] = $wlancfg['if'];
110
		$optcfg['ipaddr'] = $wlancfg['ipaddr'];
111
		$optcfg['subnet'] = $wlancfg['subnet'];
112
		$optcfg['bridge'] = $wlancfg['bridge'];
113

    
114
		$optcfg['wireless'] = array();
115
		$optcfg['wireless']['mode'] = $wlancfg['mode'];
116
		$optcfg['wireless']['ssid'] = $wlancfg['ssid'];
117
		$optcfg['wireless']['channel'] = $wlancfg['channel'];
118
		$optcfg['wireless']['wep'] = $wlancfg['wep'];
119

    
120
		$ifmap['wlan' . $i] = "opt" . $opti;
121

    
122
		unset($config['interfaces']['wlan' . $i]);
123
		$opti++;
124
	}
125

    
126
	/* convert filter rules */
127
	$n = count($config['filter']['rule']);
128
	for ($i = 0; $i < $n; $i++) {
129

    
130
		$fr = &$config['filter']['rule'][$i];
131

    
132
		/* remap interface */
133
		if (array_key_exists($fr['interface'], $ifmap)) {
134
			$fr['interface'] = $ifmap[$fr['interface']];
135
		} else {
136
			/* remove the rule */
137
			printf(gettext("%sWarning: filter rule removed " .
138
				"(interface '%s' does not exist anymore)."), "\n", $fr['interface']);
139
			unset($config['filter']['rule'][$i]);
140
			continue;
141
		}
142

    
143
		/* remap source network */
144
		if (isset($fr['source']['network'])) {
145
			if (array_key_exists($fr['source']['network'], $ifmap)) {
146
				$fr['source']['network'] = $ifmap[$fr['source']['network']];
147
			} else {
148
				/* remove the rule */
149
				printf(gettext("%sWarning: filter rule removed " .
150
					"(source network '%s' does not exist anymore)."), "\n", $fr['source']['network']);
151
				unset($config['filter']['rule'][$i]);
152
				continue;
153
			}
154
		}
155

    
156
		/* remap destination network */
157
		if (isset($fr['destination']['network'])) {
158
			if (array_key_exists($fr['destination']['network'], $ifmap)) {
159
				$fr['destination']['network'] = $ifmap[$fr['destination']['network']];
160
			} else {
161
				/* remove the rule */
162
				printf(gettext("%sWarning: filter rule removed " .
163
					"(destination network '%s' does not exist anymore)."), "\n", $fr['destination']['network']);
164
				unset($config['filter']['rule'][$i]);
165
				continue;
166
			}
167
		}
168
	}
169

    
170
	/* convert shaper rules */
171
	$n = count($config['pfqueueing']['rule']);
172
	if (is_array($config['pfqueueing']['rule'])) {
173
		for ($i = 0; $i < $n; $i++) {
174

    
175
			$fr = &$config['pfqueueing']['rule'][$i];
176

    
177
			/* remap interface */
178
			if (array_key_exists($fr['interface'], $ifmap)) {
179
				$fr['interface'] = $ifmap[$fr['interface']];
180
			} else {
181
				/* remove the rule */
182
				printf(gettext("%sWarning: traffic shaper rule removed " .
183
					"(interface '%s' does not exist anymore)."), "\n", $fr['interface']);
184
				unset($config['pfqueueing']['rule'][$i]);
185
				continue;
186
			}
187

    
188
			/* remap source network */
189
			if (isset($fr['source']['network'])) {
190
				if (array_key_exists($fr['source']['network'], $ifmap)) {
191
					$fr['source']['network'] = $ifmap[$fr['source']['network']];
192
				} else {
193
					/* remove the rule */
194
					printf(gettext("%sWarning: traffic shaper rule removed " .
195
						"(source network '%s' does not exist anymore)."), "\n", $fr['source']['network']);
196
					unset($config['pfqueueing']['rule'][$i]);
197
					continue;
198
				}
199
			}
200

    
201
			/* remap destination network */
202
			if (isset($fr['destination']['network'])) {
203
				if (array_key_exists($fr['destination']['network'], $ifmap)) {
204
					$fr['destination']['network'] = $ifmap[$fr['destination']['network']];
205
				} else {
206
					/* remove the rule */
207
					printf(gettext("%sWarning: traffic shaper rule removed " .
208
						"(destination network '%s' does not exist anymore)."), "\n", $fr['destination']['network']);
209
					unset($config['pfqueueing']['rule'][$i]);
210
					continue;
211
				}
212
			}
213
		}
214
	}
215
}
216

    
217

    
218
function upgrade_011_to_012() {
219
	global $config;
220
	/* move LAN DHCP server config */
221
	$tmp = $config['dhcpd'];
222
	$config['dhcpd'] = array();
223
	$config['dhcpd']['lan'] = $tmp;
224

    
225
	/* encrypt password */
226
	$config['system']['password'] = crypt($config['system']['password']);
227
}
228

    
229

    
230
function upgrade_012_to_013() {
231
	global $config;
232
	/* convert advanced outbound NAT config */
233
	for ($i = 0; isset($config['nat']['advancedoutbound']['rule'][$i]); $i++) {
234
		$curent = &$config['nat']['advancedoutbound']['rule'][$i];
235
		$src = $curent['source'];
236
		$curent['source'] = array();
237
		$curent['source']['network'] = $src;
238
		$curent['destination'] = array();
239
		$curent['destination']['any'] = true;
240
	}
241

    
242
	/* add an explicit type="pass" to all filter rules to make things consistent */
243
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++) {
244
		$config['filter']['rule'][$i]['type'] = "pass";
245
	}
246
}
247

    
248

    
249
function upgrade_013_to_014() {
250
	global $config;
251
	/* convert shaper rules (make pipes) */
252
	if (is_array($config['pfqueueing']['rule'])) {
253
		$config['pfqueueing']['pipe'] = array();
254

    
255
		for ($i = 0; isset($config['pfqueueing']['rule'][$i]); $i++) {
256
			$curent = &$config['pfqueueing']['rule'][$i];
257

    
258
			/* make new pipe and associate with this rule */
259
			$newpipe = array();
260
			$newpipe['descr'] = $curent['descr'];
261
			$newpipe['bandwidth'] = $curent['bandwidth'];
262
			$newpipe['delay'] = $curent['delay'];
263
			$newpipe['mask'] = $curent['mask'];
264
			$config['pfqueueing']['pipe'][$i] = $newpipe;
265

    
266
			$curent['targetpipe'] = $i;
267

    
268
			unset($curent['bandwidth']);
269
			unset($curent['delay']);
270
			unset($curent['mask']);
271
		}
272
	}
273
}
274

    
275

    
276
function upgrade_014_to_015() {
277
	global $config;
278
	/* Default route moved */
279
	if (isset($config['interfaces']['wan']['gateway'])) {
280
		if ($config['interfaces']['wan']['gateway'] <> "") {
281
			$config['system']['gateway'] = $config['interfaces']['wan']['gateway'];
282
		}
283
		unset($config['interfaces']['wan']['gateway']);
284
	}
285

    
286
	/* Queues are no longer interface specific */
287
	if (isset($config['interfaces']['lan']['schedulertype'])) {
288
		unset($config['interfaces']['lan']['schedulertype']);
289
	}
290
	if (isset($config['interfaces']['wan']['schedulertype'])) {
291
		unset($config['interfaces']['wan']['schedulertype']);
292
	}
293

    
294
	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
295
		if (isset($config['interfaces']['opt' . $i]['schedulertype'])) {
296
			unset($config['interfaces']['opt' . $i]['schedulertype']);
297
		}
298
	}
299
}
300

    
301

    
302
function upgrade_015_to_016() {
303
	global $config;
304
	/* Alternate firmware URL moved */
305
	if (isset($config['system']['firmwareurl']) && isset($config['system']['firmwarename'])) { // Only convert if *both* are defined.
306
		$config['system']['alt_firmware_url'] = array();
307
		$config['system']['alt_firmware_url']['enabled'] = "";
308
		$config['system']['alt_firmware_url']['firmware_base_url'] = $config['system']['firmwareurl'];
309
		$config['system']['alt_firmware_url']['firmware_filename'] = $config['system']['firmwarename'];
310
	}
311
	if (isset($config['system']['firmwareurl'])) {
312
		unset($config['system']['firmwareurl']);
313
	}
314
	if (isset($config['system']['firmwarename'])) {
315
		unset($config['system']['firmwarename']);
316
	}
317
}
318

    
319

    
320
function upgrade_016_to_017() {
321
	global $config;
322
	/* wipe previous shaper configuration */
323
	if (isset($config['shaper']['queue'])) {
324
		unset($config['shaper']['queue']);
325
	}
326
	if (isset($config['shaper']['rule'])) {
327
		unset($config['shaper']['rule']);
328
	}
329
	if (isset($config['interfaces']['wan']['bandwidth'])) {
330
		unset($config['interfaces']['wan']['bandwidth']);
331
	}
332
	if (isset($config['interfaces']['wan']['bandwidthtype'])) {
333
		unset($config['interfaces']['wan']['bandwidthtype']);
334
	}
335
	if (isset($config['interfaces']['lan']['bandwidth'])) {
336
		unset($config['interfaces']['lan']['bandwidth']);
337
	}
338
	if (isset($config['interfaces']['lan']['bandwidthtype'])) {
339
		unset($config['interfaces']['lan']['bandwidthtype']);
340
	}
341
	$config['shaper']['enable'] = FALSE;
342
}
343

    
344

    
345
function upgrade_017_to_018() {
346
	global $config;
347
	if (isset($config['proxyarp']) && is_array($config['proxyarp']['proxyarpnet'])) {
348
		$proxyarp = &$config['proxyarp']['proxyarpnet'];
349
		foreach ($proxyarp as $arpent) {
350
			$vip = array();
351
			$vip['mode'] = "proxyarp";
352
			$vip['interface'] = $arpent['interface'];
353
			$vip['descr'] = $arpent['descr'];
354
			if (isset($arpent['range'])) {
355
				$vip['range'] = $arpent['range'];
356
				$vip['type'] = "range";
357
			} else {
358
				$subnet = explode('/', $arpent['network']);
359
				$vip['subnet'] = $subnet[0];
360
				if (isset($subnet[1])) {
361
					$vip['subnet_bits'] = $subnet[1];
362
					$vip['type'] = "network";
363
				} else {
364
					$vip['subnet_bits'] = "32";
365
					$vip['type'] = "single";
366
				}
367
			}
368
			$config['virtualip']['vip'][] = $vip;
369
		}
370
		unset($config['proxyarp']);
371
	}
372
	if (isset($config['installedpackages']) && isset($config['installedpackages']['carp']) && is_array($config['installedpackages']['carp']['config'])) {
373
		$carp = &$config['installedpackages']['carp']['config'];
374
		foreach ($carp as $carpent) {
375
			$vip = array();
376
			$vip['mode'] = "carp";
377
			$vip['interface'] = "AUTO";
378
			$vip['descr'] = sprintf(gettext("CARP vhid %s"), $carpent['vhid']);
379
			$vip['type'] = "single";
380
			$vip['vhid'] = $carpent['vhid'];
381
			$vip['advskew'] = $carpent['advskew'];
382
			$vip['password'] = $carpent['password'];
383
			$vip['subnet'] = $carpent['ipaddress'];
384
			$vip['subnet_bits'] = $carpent['netmask'];
385
			$config['virtualip']['vip'][] = $vip;
386
		}
387
		unset($config['installedpackages']['carp']);
388
	}
389
	/* Server NAT is no longer needed */
390
	if (isset($config['nat']['servernat'])) {
391
		unset($config['nat']['servernat']);
392
	}
393

    
394
	/* enable SSH */
395
	if ($config['version'] == "1.8") {
396
		$config['system']['sshenabled'] = true;
397
	}
398
}
399

    
400

    
401
function upgrade_018_to_019() {
402
	global $config;
403
}
404

    
405

    
406
function upgrade_019_to_020() {
407
	global $config;
408
	if (is_array($config['ipsec']['tunnel'])) {
409
		reset($config['ipsec']['tunnel']);
410
		while (list($index, $tunnel) = each($config['ipsec']['tunnel'])) {
411
			/* Sanity check on required variables */
412
			/* This fixes bogus <tunnel> entries - remnant of bug #393 */
413
			if (!isset($tunnel['local-subnet']) && !isset($tunnel['remote-subnet'])) {
414
				unset($config['ipsec']['tunnel'][$tunnel]);
415
			}
416
		}
417
	}
418
}
419

    
420
function upgrade_020_to_021() {
421
	global $config;
422
	/* shaper scheduler moved */
423
	if (isset($config['system']['schedulertype'])) {
424
		$config['shaper']['schedulertype'] = $config['system']['schedulertype'];
425
		unset($config['system']['schedulertype']);
426
	}
427
}
428

    
429

    
430
function upgrade_021_to_022() {
431
	global $config;
432
	/* move gateway to wan interface */
433
	$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
434
}
435

    
436
function upgrade_022_to_023() {
437
	global $config;
438
	if (isset($config['shaper'])) {
439
		/* wipe previous shaper configuration */
440
		unset($config['shaper']);
441
	}
442
}
443

    
444

    
445
function upgrade_023_to_024() {
446
	global $config;
447
}
448

    
449

    
450
function upgrade_024_to_025() {
451
	global $config;
452
	$config['interfaces']['wan']['use_rrd_gateway'] = $config['system']['use_rrd_gateway'];
453
	if (isset($config['system']['use_rrd_gateway'])) {
454
		unset($config['system']['use_rrd_gateway']);
455
	}
456
}
457

    
458

    
459
function upgrade_025_to_026() {
460
	global $config;
461
	$cron_item = array();
462
	$cron_item['minute'] = "0";
463
	$cron_item['hour'] = "*";
464
	$cron_item['mday'] = "*";
465
	$cron_item['month'] = "*";
466
	$cron_item['wday'] = "*";
467
	$cron_item['who'] = "root";
468
	$cron_item['command'] = "/usr/bin/nice -n20 newsyslog";
469

    
470
	$config['cron']['item'][] = $cron_item;
471

    
472
	$cron_item = array();
473
	$cron_item['minute'] = "1,31";
474
	$cron_item['hour'] = "0-5";
475
	$cron_item['mday'] = "*";
476
	$cron_item['month'] = "*";
477
	$cron_item['wday'] = "*";
478
	$cron_item['who'] = "root";
479
	$cron_item['command'] = "/usr/bin/nice -n20 adjkerntz -a";
480

    
481
	$config['cron']['item'][] = $cron_item;
482

    
483
	$cron_item = array();
484
	$cron_item['minute'] = "1";
485
	$cron_item['hour'] = "*";
486
	$cron_item['mday'] = "1";
487
	$cron_item['month'] = "*";
488
	$cron_item['wday'] = "*";
489
	$cron_item['who'] = "root";
490
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.update_bogons.sh";
491

    
492
	$config['cron']['item'][] = $cron_item;
493

    
494
	$cron_item = array();
495
	$cron_item['minute'] = "*/60";
496
	$cron_item['hour'] = "*";
497
	$cron_item['mday'] = "*";
498
	$cron_item['month'] = "*";
499
	$cron_item['wday'] = "*";
500
	$cron_item['who'] = "root";
501
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 sshlockout";
502

    
503
	$config['cron']['item'][] = $cron_item;
504

    
505
	$cron_item = array();
506
	$cron_item['minute'] = "1";
507
	$cron_item['hour'] = "1";
508
	$cron_item['mday'] = "*";
509
	$cron_item['month'] = "*";
510
	$cron_item['wday'] = "*";
511
	$cron_item['who'] = "root";
512
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.dyndns.update";
513

    
514
	$config['cron']['item'][] = $cron_item;
515

    
516
	$cron_item = array();
517
	$cron_item['minute'] = "*/60";
518
	$cron_item['hour'] = "*";
519
	$cron_item['mday'] = "*";
520
	$cron_item['month'] = "*";
521
	$cron_item['wday'] = "*";
522
	$cron_item['who'] = "root";
523
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 virusprot";
524

    
525
	$config['cron']['item'][] = $cron_item;
526

    
527
	$cron_item = array();
528
	$cron_item['minute'] = "*/60";
529
	$cron_item['hour'] = "*";
530
	$cron_item['mday'] = "*";
531
	$cron_item['month'] = "*";
532
	$cron_item['wday'] = "*";
533
	$cron_item['who'] = "root";
534
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -t 1800 snort2c";
535

    
536
	$config['cron']['item'][] = $cron_item;
537
}
538

    
539

    
540
function upgrade_026_to_027() {
541
	global $config;
542
}
543

    
544

    
545
function upgrade_027_to_028() {
546
	global $config;
547
}
548

    
549

    
550
function upgrade_028_to_029() {
551
	global $config;
552
	$rule_item = array();
553
	$a_filter = &$config['filter']['rule'];
554
	$rule_item['interface'] = "enc0";
555
	$rule_item['type'] = "pass";
556
	$rule_item['source']['any'] = true;
557
	$rule_item['destination']['any'] = true;
558
	$rule_item['descr'] = gettext("Permit IPsec traffic.");
559
	$rule_item['statetype'] = "keep state";
560
	$a_filter[] = $rule_item;
561
}
562

    
563

    
564
function upgrade_029_to_030() {
565
	global $config;
566
	/* enable the rrd config setting by default */
567
	$config['rrd']['enable'] = true;
568
}
569

    
570

    
571
function upgrade_030_to_031() {
572
	global $config;
573
	/* Insert upgrade code here */
574
}
575

    
576

    
577
function upgrade_031_to_032() {
578
	global $config;
579
	/* Insert upgrade code here */
580
}
581

    
582

    
583
function upgrade_032_to_033() {
584
	global $config;
585
	/* Insert upgrade code here */
586
}
587

    
588

    
589
function upgrade_033_to_034() {
590
	global $config;
591
	/* Insert upgrade code here */
592
}
593

    
594

    
595
function upgrade_034_to_035() {
596
	global $config;
597
	/* Insert upgrade code here */
598
}
599

    
600

    
601
function upgrade_035_to_036() {
602
	global $config;
603
	/* Insert upgrade code here */
604
}
605

    
606

    
607
function upgrade_036_to_037() {
608
	global $config;
609
	/* Insert upgrade code here */
610
}
611

    
612

    
613
function upgrade_037_to_038() {
614
	global $config;
615
	/* Insert upgrade code here */
616
}
617

    
618

    
619
function upgrade_038_to_039() {
620
	global $config;
621
	/* Insert upgrade code here */
622
}
623

    
624

    
625
function upgrade_039_to_040() {
626
	global $config, $g;
627
	$config['system']['webgui']['auth_method'] = "session";
628
	$config['system']['webgui']['backing_method'] = "htpasswd";
629

    
630
	if (isset($config['system']['username'])) {
631
		$config['system']['group'] = array();
632
		$config['system']['group'][0]['name'] = "admins";
633
		$config['system']['group'][0]['description'] = gettext("System Administrators");
634
		$config['system']['group'][0]['scope'] = "system";
635
		$config['system']['group'][0]['priv'] = "page-all";
636
		$config['system']['group'][0]['home'] = "index.php";
637
		$config['system']['group'][0]['gid'] = "110";
638

    
639
		$config['system']['user'] = array();
640
		$config['system']['user'][0]['name'] = "{$config['system']['username']}";
641
		$config['system']['user'][0]['descr'] = "System Administrator";
642
		$config['system']['user'][0]['scope'] = "system";
643
		$config['system']['user'][0]['groupname'] = "admins";
644
		$config['system']['user'][0]['password'] = "{$config['system']['password']}";
645
		$config['system']['user'][0]['uid'] = "0";
646
		/* Ensure that we follow what this new "admin" username should be in the session. */
647
		$_SESSION["Username"] = "{$config['system']['username']}";
648

    
649
		$config['system']['user'][0]['priv'] = array();
650
		$config['system']['user'][0]['priv'][0]['id'] = "lockwc";
651
		$config['system']['user'][0]['priv'][0]['name'] = "Lock webConfigurator";
652
		$config['system']['user'][0]['priv'][0]['descr'] = gettext("Indicates whether this user will lock access to the webConfigurator for other users.");
653
		$config['system']['user'][0]['priv'][1]['id'] = "lock-ipages";
654
		$config['system']['user'][0]['priv'][1]['name'] = "Lock individual pages";
655
		$config['system']['user'][0]['priv'][1]['descr'] = gettext("Indicates whether this user will lock individual HTML pages after having accessed a particular page (the lock will be freed if the user leaves or saves the page form).");
656
		$config['system']['user'][0]['priv'][2]['id'] = "hasshell";
657
		$config['system']['user'][0]['priv'][2]['name'] = "Has shell access";
658
		$config['system']['user'][0]['priv'][2]['descr'] = gettext("Indicates whether this user is able to login for example via SSH.");
659
		$config['system']['user'][0]['priv'][3]['id'] = "copyfiles";
660
		$config['system']['user'][0]['priv'][3]['name'] = "Is allowed to copy files";
661
		$config['system']['user'][0]['priv'][3]['descr'] = sprintf(gettext("Indicates whether this user is allowed to copy files onto the %s appliance via SCP/SFTP. If you are going to use this privilege, you must install scponly on the appliance (Hint: pkg_add -r scponly)."), $g['product_name']);
662
		$config['system']['user'][0]['priv'][4]['id'] = "isroot";
663
		$config['system']['user'][0]['priv'][4]['name'] = "Is root user";
664
		$config['system']['user'][0]['priv'][4]['descr'] = gettext("This user is associated with the UNIX root user (you should associate this privilege only with one single user).");
665

    
666
		$config['system']['nextuid'] = "111";
667
		$config['system']['nextgid'] = "111";
668

    
669
		/* wipe previous auth configuration */
670
		unset($config['system']['username']);
671
		if (isset($config['system']['password'])) {
672
			unset($config['system']['password']);
673
		}
674
	}
675
}
676

    
677
function upgrade_040_to_041() {
678
	global $config;
679
	if (!$config['sysctl']) {
680
		$config['sysctl']['item'] = array();
681

    
682
		$config['sysctl']['item'][0]['tunable'] = "net.inet.tcp.blackhole";
683
		$config['sysctl']['item'][0]['descr'] =    gettext("Drop packets to closed TCP ports without returning a RST");
684
		$config['sysctl']['item'][0]['value'] =   "default";
685

    
686
		$config['sysctl']['item'][1]['tunable'] = "net.inet.udp.blackhole";
687
		$config['sysctl']['item'][1]['descr'] =    gettext("Do not send ICMP port unreachable messages for closed UDP ports");
688
		$config['sysctl']['item'][1]['value'] =   "default";
689

    
690
		$config['sysctl']['item'][2]['tunable'] = "net.inet.ip.random_id";
691
		$config['sysctl']['item'][2]['descr'] =    gettext("Randomize the ID field in IP packets (default is 0: sequential IP IDs)");
692
		$config['sysctl']['item'][2]['value'] =   "default";
693

    
694
		$config['sysctl']['item'][3]['tunable'] = "net.inet.tcp.drop_synfin";
695
		$config['sysctl']['item'][3]['descr'] =    gettext("Drop SYN-FIN packets (breaks RFC1379, but nobody uses it anyway)");
696
		$config['sysctl']['item'][3]['value'] =   "default";
697

    
698
		$config['sysctl']['item'][4]['tunable'] = "net.inet.ip.redirect";
699
		$config['sysctl']['item'][4]['descr'] =    gettext("Sending of IPv4 ICMP redirects");
700
		$config['sysctl']['item'][4]['value'] =   "default";
701

    
702
		$config['sysctl']['item'][5]['tunable'] = "net.inet6.ip6.redirect";
703
		$config['sysctl']['item'][5]['descr'] =    gettext("Sending of IPv6 ICMP redirects");
704
		$config['sysctl']['item'][5]['value'] =   "default";
705

    
706
		$config['sysctl']['item'][6]['tunable'] = "net.inet.tcp.syncookies";
707
		$config['sysctl']['item'][6]['descr'] =    gettext("Generate SYN cookies for outbound SYN-ACK packets");
708
		$config['sysctl']['item'][6]['value'] =   "default";
709

    
710
		$config['sysctl']['item'][7]['tunable'] = "net.inet.tcp.recvspace";
711
		$config['sysctl']['item'][7]['descr'] =    gettext("Maximum incoming TCP datagram size");
712
		$config['sysctl']['item'][7]['value'] =   "default";
713

    
714
		$config['sysctl']['item'][8]['tunable'] = "net.inet.tcp.sendspace";
715
		$config['sysctl']['item'][8]['descr'] =    gettext("Maximum outgoing TCP datagram size");
716
		$config['sysctl']['item'][8]['value'] =   "default";
717

    
718
		$config['sysctl']['item'][9]['tunable'] = "net.inet.tcp.delayed_ack";
719
		$config['sysctl']['item'][9]['descr'] =    gettext("Do not delay ACK to try and piggyback it onto a data packet");
720
		$config['sysctl']['item'][9]['value'] =   "default";
721

    
722
		$config['sysctl']['item'][10]['tunable'] = "net.inet.udp.maxdgram";
723
		$config['sysctl']['item'][10]['descr'] =    gettext("Maximum outgoing UDP datagram size");
724
		$config['sysctl']['item'][10]['value'] =   "default";
725

    
726
		$config['sysctl']['item'][11]['tunable'] = "net.link.bridge.pfil_onlyip";
727
		$config['sysctl']['item'][11]['descr'] =    gettext("Handling of non-IP packets which are not passed to pfil (see if_bridge(4))");
728
		$config['sysctl']['item'][11]['value'] =   "default";
729

    
730
		$config['sysctl']['item'][12]['tunable'] = "net.link.tap.user_open";
731
		$config['sysctl']['item'][12]['descr'] =    gettext("Allow unprivileged access to tap(4) device nodes");
732
		$config['sysctl']['item'][12]['value'] =   "default";
733

    
734
		$config['sysctl']['item'][13]['tunable'] = "kern.randompid";
735
		$config['sysctl']['item'][13]['descr'] =    gettext("Randomize PID's (see src/sys/kern/kern_fork.c: sysctl_kern_randompid())");
736
		$config['sysctl']['item'][13]['value'] =   "default";
737

    
738
		$config['sysctl']['item'][14]['tunable'] = "net.inet.tcp.inflight.enable";
739
		$config['sysctl']['item'][14]['descr'] =    gettext("The system will attempt to calculate the bandwidth delay product for each connection and limit the amount of data queued to the network to just the amount required to maintain optimum throughput. ");
740
		$config['sysctl']['item'][14]['value'] =   "default";
741

    
742
		$config['sysctl']['item'][15]['tunable'] = "net.inet.icmp.icmplim";
743
		$config['sysctl']['item'][15]['descr'] =    gettext("Set ICMP Limits");
744
		$config['sysctl']['item'][15]['value'] =   "default";
745

    
746
		$config['sysctl']['item'][16]['tunable'] = "net.inet.tcp.tso";
747
		$config['sysctl']['item'][16]['descr'] =    gettext("TCP Offload engine");
748
		$config['sysctl']['item'][16]['value'] =   "default";
749

    
750
		$config['sysctl']['item'][17]['tunable'] = "net.inet.ip.portrange.first";
751
		$config['sysctl']['item'][17]['descr'] =    "Set the ephemeral port range starting port";
752
		$config['sysctl']['item'][17]['value'] =   "default";
753

    
754
		$config['sysctl']['item'][18]['tunable'] = "hw.syscons.kbd_reboot";
755
		$config['sysctl']['item'][18]['descr'] =    "Enables ctrl+alt+delete";
756
		$config['sysctl']['item'][18]['value'] =   "default";
757

    
758
		$config['sysctl']['item'][19]['tunable'] = "kern.ipc.maxsockbuf";
759
		$config['sysctl']['item'][19]['descr'] =    "Maximum socket buffer size";
760
		$config['sysctl']['item'][19]['value'] =   "default";
761

    
762
	}
763
}
764

    
765

    
766
function upgrade_041_to_042() {
767
	global $config;
768
	if (isset($config['shaper'])) {
769
		unset($config['shaper']);
770
	}
771
	if (isset($config['ezshaper'])) {
772
		unset($config['ezshaper']);
773
	}
774
}
775

    
776

    
777
function upgrade_042_to_043() {
778
	global $config;
779
	/* migrate old interface gateway to the new gateways config */
780
	$iflist = get_configured_interface_list(false, true);
781
	$gateways = array();
782
	$i = 0;
783
	foreach ($iflist as $ifname => $interface) {
784
		if (!interface_has_gateway($ifname)) {
785
			continue;
786
		}
787
		$config['gateways']['gateway_item'][$i] = array();
788
		if (is_ipaddr($config['interfaces'][$ifname]['gateway'])) {
789
			$config['gateways']['gateway_item'][$i]['gateway'] = $config['interfaces'][$ifname]['gateway'];
790
			$config['gateways']['gateway_item'][$i]['descr'] = sprintf(gettext("Interface %s Static Gateway"), $ifname);
791
		} else {
792
			$config['gateways']['gateway_item'][$i]['gateway'] = "dynamic";
793
			$config['gateways']['gateway_item'][$i]['descr'] = sprintf(gettext("Interface %s Dynamic Gateway"), $ifname);
794
		}
795
		$config['gateways']['gateway_item'][$i]['interface'] = $ifname;
796
		$config['gateways']['gateway_item'][$i]['name'] = "GW_" . strtoupper($ifname);
797
		/* add default gateway bit for wan on upgrade */
798
		if ($ifname == "wan") {
799
			$config['gateways']['gateway_item'][$i]['defaultgw'] = true;
800
		}
801
		if (is_ipaddr($config['interfaces'][$ifname]['use_rrd_gateway'])) {
802
			$config['gateways']['gateway_item'][$i]['monitor'] = $config['interfaces'][$ifname]['use_rrd_gateway'];
803
			unset($config['interfaces'][$ifname]['use_rrd_gateway']);
804
		}
805
		$config['interfaces'][$ifname]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
806

    
807
		/* Update all filter rules which might reference this gateway */
808
		$j = 0;
809
		foreach ($config['filter']['rule'] as $rule) {
810
			if (is_ipaddr($rule['gateway'])) {
811
				if ($rule['gateway'] == $config['gateways']['gateway_item'][$i]['gateway']) {
812
					$config['filter']['rule'][$j]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
813
				} else if ($rule['gateway'] == $ifname) {
814
					$config['filter']['rule'][$j]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
815
				}
816
			}
817
			$j++;
818
		}
819

    
820
		/* rename old Quality RRD files in the process */
821
		$rrddbpath = "/var/db/rrd";
822
		$gwname = "GW_" . strtoupper($ifname);
823
		if (is_readable("{$rrddbpath}/{$ifname}-quality.rrd")) {
824
			rename("{$rrddbpath}/{$ifname}-quality.rrd", "{$rrddbpath}/{$gwname}-quality.rrd");
825
		}
826
		$i++;
827
	}
828
}
829

    
830

    
831
function upgrade_043_to_044() {
832
	global $config;
833

    
834
	/* migrate static routes to the new gateways config */
835
	$gateways = return_gateways_array(true);
836
	$i = 0;
837
	if (is_array($config['staticroutes']['route'])) {
838
		$gwmap = array();
839
		foreach ($config['staticroutes']['route'] as $idx => $sroute) {
840
			$found = false;
841
			foreach ($gateways as $gwname => $gw) {
842
				if ($gw['gateway'] == $sroute['gateway']) {
843
					$config['staticroutes']['route'][$idx]['gateway'] = $gwname;
844
					$found = true;
845
					break;
846
				}
847
			}
848
			if ($gwmap[$sroute['gateway']]) {
849
				/* We already added a gateway name for this IP */
850
				$config['staticroutes']['route'][$idx]['gateway'] = "{$gwmap[$sroute['gateway']]}";
851
				$found = true;
852
			}
853

    
854
			if ($found == false) {
855
				$gateway = array();
856
				$gateway['name'] = "SROUTE{$i}";
857
				$gwmap[$sroute['gateway']] = $gateway['name'];
858
				$gateway['gateway'] = $sroute['gateway'];
859
				$gateway['interface'] = $sroute['interface'];
860
				$gateway['descr'] = sprintf(gettext("Upgraded static route for %s"), $sroute['network']);
861
				if (!is_array($config['gateways']['gateway_item'])) {
862
					$config['gateways']['gateway_item'] = array();
863
				}
864
				$config['gateways']['gateway_item'][] = $gateway;
865
				$config['staticroutes']['route'][$idx]['gateway'] = $gateway['name'];
866
				$i++;
867
			}
868
		}
869
	}
870
}
871

    
872

    
873
function upgrade_044_to_045() {
874
	global $config;
875
	$iflist = get_configured_interface_list(false, true);
876
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
877
		$i = 0;
878
		foreach ($config['vlans']['vlan'] as $id => $vlan) {
879
			/* Make sure to update the interfaces section with the right name */
880
			$vlan_name = "{$vlan['if']}_vlan{$vlan['tag']}";
881
			foreach ($iflist as $ifname) {
882
				if ($config['interfaces'][$ifname]['if'] == "vlan{$i}") {
883
					$config['interfaces'][$ifname]['if'] = $vlan_name;
884
					continue;
885
				}
886
			}
887
			$config['vlans']['vlan'][$i]['vlanif'] = "{$vlan_name}";
888
			$i++;
889
		}
890
	}
891
}
892

    
893

    
894
function upgrade_045_to_046() {
895
	global $config;
896
	/* Load up monitors that are in the default config for 2.0 but not in 1.2.3
897
		thus wouldn't be in an upgraded config. */
898
	$config['load_balancer']['monitor_type'] = array (
899
		array ('name' => 'ICMP',
900
			'type' => 'icmp',
901
			'descr' => 'ICMP',
902
			'options' => '',
903
		),
904
		array ('name' => 'TCP',
905
			'type' => 'tcp',
906
			'descr' => 'Generic TCP',
907
			'options' => '',
908
		),
909
		array ('name' => 'HTTP',
910
			'type' => 'http',
911
			'descr' => 'Generic HTTP',
912
			'options' =>
913
			array ('path' => '/',
914
				'host' => '',
915
				'code' => '200',
916
			),
917
		),
918
		array ('name' => 'HTTPS',
919
			'type' => 'https',
920
			'descr' => 'Generic HTTPS',
921
			'options' =>
922
			array ('path' => '/',
923
				'host' => '',
924
				'code' => '200',
925
			),
926
		),
927
		array ('name' => 'SMTP',
928
			'type' => 'send',
929
			'descr' => 'Generic SMTP',
930
			'options' =>
931
			array ('send' => '',
932
				'expect' => '220 *',
933
			),
934
		),
935
	);
936
	/* Upgrade load balancer from slb to relayd */
937
	if (is_array($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server'])) {
938
		$vs_a = &$config['load_balancer']['virtual_server'];
939
		$pool_a = &$config['load_balancer']['lbpool'];
940
		$pools = array();
941
		/* Index pools by name */
942
		if (is_array($pool_a)) {
943
			for ($i = 0; isset($pool_a[$i]); $i++) {
944
				if ($pool_a[$i]['type'] == "server") {
945
					$pools[$pool_a[$i]['name']] = $pool_a[$i];
946
				}
947
			}
948
		}
949
		/* Convert sitedown entries to pools and re-attach */
950
		for ($i = 0; isset($vs_a[$i]); $i++) {
951
			/* Set mode while we're here. */
952
			$vs_a[$i]['mode'] = "redirect_mode";
953
			if (isset($vs_a[$i]['sitedown'])) {
954
				$pool = array();
955
				$pool['type'] = 'server';
956
				$pool['behaviour'] = 'balance';
957
				$pool['name'] = "{$vs_a[$i]['name']}-sitedown";
958
				$pool['descr'] = sprintf(gettext("Sitedown pool for VS: %s"), $vs_a[$i]['name']);
959
				if (is_array($vs_a[$i]['pool'])) {
960
					$vs_a[$i]['pool'] = $vs_a[$i]['pool'][0];
961
				}
962
				$pool['port'] = $pools[$vs_a[$i]['pool']]['port'];
963
				$pool['servers'] = array();
964
				$pool['servers'][] = $vs_a[$i]['sitedown'];
965
				$pool['monitor'] = $pools[$vs_a[$i]['pool']]['monitor'];
966
				$pool_a[] = $pool;
967
				$vs_a[$i]['sitedown'] = $pool['name'];
968
			}
969
		}
970
	}
971
	if (count($config['load_balancer']) == 0) {
972
		unset($config['load_balancer']);
973
	}
974
	mwexec('/usr/sbin/pw groupadd -n _relayd -g 913');
975
	mwexec('/usr/sbin/pw useradd -n _relayd -c "Relay Daemon" -d /var/empty -s /usr/sbin/nologin -u 913 -g 913');
976
}
977

    
978

    
979
function upgrade_046_to_047() {
980
	global $config;
981
	/* Upgrade IPsec from tunnel to phase1/phase2 */
982

    
983
	if (is_array($config['ipsec']['tunnel'])) {
984

    
985
		$a_phase1 = array();
986
		$a_phase2 = array();
987
		$ikeid = 0;
988

    
989
		foreach ($config['ipsec']['tunnel'] as $tunnel) {
990

    
991
			unset($ph1ent);
992
			unset($ph2ent);
993

    
994
			/*
995
				*  attempt to locate an enabled phase1
996
				*  entry that matches the peer gateway
997
				*/
998

    
999
			if (!isset($tunnel['disabled'])) {
1000

    
1001
				$remote_gateway = $tunnel['remote-gateway'];
1002

    
1003
				foreach ($a_phase1 as $ph1tmp) {
1004
					if ($ph1tmp['remote-gateway'] == $remote_gateway) {
1005
						$ph1ent = $ph1tmp;
1006
						break;
1007
					}
1008
				}
1009
			}
1010

    
1011
			/* none found, create a new one */
1012

    
1013
			if (!isset($ph1ent)) {
1014

    
1015
				/* build new phase1 entry */
1016

    
1017
				$ph1ent = array();
1018

    
1019
				$ph1ent['ikeid'] = ++$ikeid;
1020

    
1021
				if (isset($tunnel['disabled'])) {
1022
					$ph1ent['disabled'] = $tunnel['disabled'];
1023
				}
1024

    
1025
				/* convert to the new vip[$vhid] name */
1026
				if (preg_match("/^carp/", $tunnel['interface'])) {
1027
					$carpid = str_replace("carp", "", $tunnel['interface']);
1028
					$tunnel['interface'] = "vip" . $config['virtualip']['vip'][$carpid]['vhid'];
1029
				}
1030
				$ph1ent['interface'] = $tunnel['interface'];
1031
				$ph1ent['remote-gateway'] = $tunnel['remote-gateway'];
1032
				$ph1ent['descr'] = $tunnel['descr'];
1033

    
1034
				$ph1ent['mode'] = $tunnel['p1']['mode'];
1035

    
1036
				if (isset($tunnel['p1']['myident']['myaddress'])) {
1037
					$ph1ent['myid_type'] = "myaddress";
1038
				}
1039
				if (isset($tunnel['p1']['myident']['address'])) {
1040
					$ph1ent['myid_type'] = "address";
1041
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['address'];
1042
				}
1043
				if (isset($tunnel['p1']['myident']['fqdn'])) {
1044
					$ph1ent['myid_type'] = "fqdn";
1045
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['fqdn'];
1046
				}
1047
				if (isset($tunnel['p1']['myident']['ufqdn'])) {
1048
					$ph1ent['myid_type'] = "user_fqdn";
1049
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['ufqdn'];
1050
				}
1051
				if (isset($tunnel['p1']['myident']['asn1dn'])) {
1052
					$ph1ent['myid_type'] = "asn1dn";
1053
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['asn1dn'];
1054
				}
1055
				if (isset($tunnel['p1']['myident']['dyn_dns'])) {
1056
					$ph1ent['myid_type'] = "dyn_dns";
1057
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['dyn_dns'];
1058
				}
1059

    
1060
				$ph1ent['peerid_type'] = "peeraddress";
1061

    
1062
				switch ($tunnel['p1']['encryption-algorithm']) {
1063
					case "des":
1064
						$ph1alg = array('name' => 'des');
1065
						break;
1066
					case "3des":
1067
						$ph1alg = array('name' => '3des');
1068
						break;
1069
					case "blowfish":
1070
						$ph1alg = array('name' => 'blowfish', 'keylen' => '128');
1071
						break;
1072
					case "cast128":
1073
						$ph1alg = array('name' => 'cast128');
1074
						break;
1075
					case "rijndael":
1076
						$ph1alg = array('name' => 'aes', 'keylen' => '128');
1077
						break;
1078
					case "rijndael 256":
1079
					case "aes 256":
1080
						$ph1alg = array('name' => 'aes', 'keylen' => '256');
1081
						break;
1082
				}
1083

    
1084
				$ph1ent['encryption-algorithm'] = $ph1alg;
1085
				$ph1ent['hash-algorithm'] = $tunnel['p1']['hash-algorithm'];
1086
				$ph1ent['dhgroup'] = $tunnel['p1']['dhgroup'];
1087
				$ph1ent['lifetime'] = $tunnel['p1']['lifetime'];
1088
				$ph1ent['authentication_method'] = $tunnel['p1']['authentication_method'];
1089

    
1090
				if (isset($tunnel['p1']['pre-shared-key'])) {
1091
					$ph1ent['pre-shared-key'] = $tunnel['p1']['pre-shared-key'];
1092
				}
1093
				if (isset($tunnel['p1']['cert'])) {
1094
					$ph1ent['cert'] = $tunnel['p1']['cert'];
1095
				}
1096
				if (isset($tunnel['p1']['peercert'])) {
1097
					$ph1ent['peercert'] = $tunnel['p1']['peercert'];
1098
				}
1099
				if (isset($tunnel['p1']['private-key'])) {
1100
					$ph1ent['private-key'] = $tunnel['p1']['private-key'];
1101
				}
1102

    
1103
				$ph1ent['nat_traversal'] = "on";
1104
				$ph1ent['dpd_enable'] = 1;
1105
				$ph1ent['dpd_delay'] = 10;
1106
				$ph1ent['dpd_maxfail'] = 5;
1107

    
1108
				$a_phase1[] = $ph1ent;
1109
			}
1110

    
1111
			/* build new phase2 entry */
1112

    
1113
			$ph2ent = array();
1114

    
1115
			$ph2ent['ikeid'] = $ph1ent['ikeid'];
1116

    
1117
			if (isset($tunnel['disabled'])) {
1118
				$ph1ent['disabled'] = $tunnel['disabled'];
1119
			}
1120

    
1121
			$ph2ent['descr'] = sprintf(gettext("phase2 for %s"), $tunnel['descr']);
1122

    
1123
			$type = "lan";
1124
			if ($tunnel['local-subnet']['network']) {
1125
				$type = $tunnel['local-subnet']['network'];
1126
			}
1127
			if ($tunnel['local-subnet']['address']) {
1128
				list($address, $netbits) = explode("/", $tunnel['local-subnet']['address']);
1129
				if (is_null($netbits)) {
1130
					$type = "address";
1131
				} else {
1132
					$type = "network";
1133
				}
1134
			}
1135

    
1136
			switch ($type) {
1137
				case "address":
1138
					$ph2ent['localid'] = array('type' => $type, 'address' => $address);
1139
					break;
1140
				case "network":
1141
					$ph2ent['localid'] = array('type' => $type, 'address' => $address, 'netbits' => $netbits);
1142
					break;
1143
				default:
1144
					$ph2ent['localid'] = array('type' => $type);
1145
					break;
1146
			}
1147

    
1148
			list($address, $netbits) = explode("/", $tunnel['remote-subnet']);
1149
			$ph2ent['remoteid'] = array('type' => 'network', 'address' => $address, 'netbits' => $netbits);
1150

    
1151
			$ph2ent['protocol'] = $tunnel['p2']['protocol'];
1152

    
1153
			$aes_count = 0;
1154
			foreach ($tunnel['p2']['encryption-algorithm-option'] as $tunalg) {
1155
				$aes_found = false;
1156
				switch ($tunalg) {
1157
					case "des":
1158
						$ph2alg = array('name' => 'des');
1159
						break;
1160
					case "3des":
1161
						$ph2alg = array('name' => '3des');
1162
						break;
1163
					case "blowfish":
1164
						$ph2alg = array('name' => 'blowfish', 'keylen' => 'auto');
1165
						break;
1166
					case "cast128":
1167
						$ph2alg = array('name' => 'cast128');
1168
						break;
1169
					case "rijndael":
1170
					case "rijndael 256":
1171
					case "aes 256":
1172
						$ph2alg = array('name' => 'aes', 'keylen' => 'auto');
1173
						$aes_found = true;
1174
						$aes_count++;
1175
						break;
1176
				}
1177

    
1178
				if (!$aes_found || ($aes_count < 2)) {
1179
					$ph2ent['encryption-algorithm-option'][] = $ph2alg;
1180
				}
1181
			}
1182

    
1183
			$ph2ent['hash-algorithm-option'] = $tunnel['p2']['hash-algorithm-option'];
1184
			$ph2ent['pfsgroup'] = $tunnel['p2']['pfsgroup'];
1185
			$ph2ent['lifetime'] = $tunnel['p2']['lifetime'];
1186

    
1187
			if (isset($tunnel['pinghost']['pinghost'])) {
1188
				$ph2ent['pinghost'] = $tunnel['pinghost'];
1189
			}
1190

    
1191
			$a_phase2[] = $ph2ent;
1192
		}
1193

    
1194
		unset($config['ipsec']['tunnel']);
1195
		$config['ipsec']['phase1'] = $a_phase1;
1196
		$config['ipsec']['phase2'] = $a_phase2;
1197
	}
1198

    
1199
	/* Upgrade Mobile IPsec */
1200
	if (isset($config['ipsec']['mobileclients']) &&
1201
	    is_array($config['ipsec']['mobileclients']) &&
1202
	    is_array($config['ipsec']['mobileclients']['p1']) &&
1203
	    is_array($config['ipsec']['mobileclients']['p2'])) {
1204

    
1205
		if (isset($config['ipsec']['mobileclients']['enable'])) {
1206
			$config['ipsec']['client']['enable'] = true;
1207
			$config['ipsec']['client']['user_source'] = 'system';
1208
			$config['ipsec']['client']['group_source'] = 'system';
1209
		}
1210

    
1211
		$mobilecfg = $config['ipsec']['mobileclients'];
1212

    
1213
		$ph1ent = array();
1214
		$ph1ent['ikeid'] = ++$ikeid;
1215

    
1216
		if (!isset($mobilecfg['enable'])) {
1217
			$ph1ent['disabled'] = true;
1218
		}
1219

    
1220
		/* Assume WAN since mobile tunnels couldn't be on a separate interface on 1.2.x */
1221
		$ph1ent['interface'] = 'wan';
1222
		$ph1ent['descr'] = "Mobile Clients (upgraded)";
1223
		$ph1ent['mode'] = $mobilecfg['p1']['mode'];
1224

    
1225
		if (isset($mobilecfg['p1']['myident']['myaddress'])) {
1226
			$ph1ent['myid_type'] = "myaddress";
1227
		}
1228
		if (isset($mobilecfg['p1']['myident']['address'])) {
1229
			$ph1ent['myid_type'] = "address";
1230
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['address'];
1231
		}
1232
		if (isset($mobilecfg['p1']['myident']['fqdn'])) {
1233
			$ph1ent['myid_type'] = "fqdn";
1234
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['fqdn'];
1235
		}
1236
		if (isset($mobilecfg['p1']['myident']['ufqdn'])) {
1237
			$ph1ent['myid_type'] = "user_fqdn";
1238
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['ufqdn'];
1239
		}
1240
		if (isset($mobilecfg['p1']['myident']['asn1dn'])) {
1241
			$ph1ent['myid_type'] = "asn1dn";
1242
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['asn1dn'];
1243
		}
1244
		if (isset($mobilecfg['p1']['myident']['dyn_dns'])) {
1245
			$ph1ent['myid_type'] = "dyn_dns";
1246
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['dyn_dns'];
1247
		}
1248
		$ph1ent['peerid_type'] = "fqdn";
1249
		$ph1ent['peerid_data'] = "";
1250

    
1251
		switch ($mobilecfg['p1']['encryption-algorithm']) {
1252
			case "des":
1253
				$ph1alg = array('name' => 'des');
1254
				break;
1255
			case "3des":
1256
				$ph1alg = array('name' => '3des');
1257
				break;
1258
			case "blowfish":
1259
				$ph1alg = array('name' => 'blowfish', 'keylen' => '128');
1260
				break;
1261
			case "cast128":
1262
				$ph1alg = array('name' => 'cast128');
1263
				break;
1264
			case "rijndael":
1265
				$ph1alg = array('name' => 'aes', 'keylen' => '128');
1266
				break;
1267
			case "rijndael 256":
1268
			case "aes 256":
1269
				$ph1alg = array('name' => 'aes', 'keylen' => '256');
1270
				break;
1271
		}
1272

    
1273
		$ph1ent['encryption-algorithm'] = $ph1alg;
1274
		$ph1ent['hash-algorithm'] = $mobilecfg['p1']['hash-algorithm'];
1275
		$ph1ent['dhgroup'] = $mobilecfg['p1']['dhgroup'];
1276
		$ph1ent['lifetime'] = $mobilecfg['p1']['lifetime'];
1277
		$ph1ent['authentication_method'] = $mobilecfg['p1']['authentication_method'];
1278

    
1279
		if (isset($mobilecfg['p1']['cert'])) {
1280
			$ph1ent['cert'] = $mobilecfg['p1']['cert'];
1281
		}
1282
		if (isset($mobilecfg['p1']['peercert'])) {
1283
			$ph1ent['peercert'] = $mobilecfg['p1']['peercert'];
1284
		}
1285
		if (isset($mobilecfg['p1']['private-key'])) {
1286
			$ph1ent['private-key'] = $mobilecfg['p1']['private-key'];
1287
		}
1288

    
1289
		$ph1ent['nat_traversal'] = "on";
1290
		$ph1ent['dpd_enable'] = 1;
1291
		$ph1ent['dpd_delay'] = 10;
1292
		$ph1ent['dpd_maxfail'] = 5;
1293
		$ph1ent['mobile'] = true;
1294

    
1295
		$ph2ent = array();
1296
		$ph2ent['ikeid'] = $ph1ent['ikeid'];
1297
		$ph2ent['descr'] = "phase2 for ".$mobilecfg['descr'];
1298
		$ph2ent['localid'] = array('type' => 'none');
1299
		$ph2ent['remoteid'] = array('type' => 'mobile');
1300
		$ph2ent['protocol'] = $mobilecfg['p2']['protocol'];
1301

    
1302
		$aes_count = 0;
1303
		foreach ($mobilecfg['p2']['encryption-algorithm-option'] as $tunalg) {
1304
			$aes_found = false;
1305
			switch ($tunalg) {
1306
				case "des":
1307
					$ph2alg = array('name' => 'des');
1308
					break;
1309
				case "3des":
1310
					$ph2alg = array('name' => '3des');
1311
					break;
1312
				case "blowfish":
1313
					$ph2alg = array('name' => 'blowfish', 'keylen' => 'auto');
1314
					break;
1315
				case "cast128":
1316
					$ph2alg = array('name' => 'cast128');
1317
					break;
1318
				case "rijndael":
1319
				case "rijndael 256":
1320
				case "aes 256":
1321
					$ph2alg = array('name' => 'aes', 'keylen' => 'auto');
1322
					$aes_found = true;
1323
					$aes_count++;
1324
					break;
1325
			}
1326

    
1327
			if (!$aes_found || ($aes_count < 2)) {
1328
				$ph2ent['encryption-algorithm-option'][] = $ph2alg;
1329
			}
1330
		}
1331
		$ph2ent['hash-algorithm-option'] = $mobilecfg['p2']['hash-algorithm-option'];
1332
		$ph2ent['pfsgroup'] = $mobilecfg['p2']['pfsgroup'];
1333
		$ph2ent['lifetime'] = $mobilecfg['p2']['lifetime'];
1334
		$ph2ent['mobile'] = true;
1335

    
1336
		$config['ipsec']['phase1'][] = $ph1ent;
1337
		$config['ipsec']['phase2'][] = $ph2ent;
1338
		unset($config['ipsec']['mobileclients']);
1339
	}
1340
}
1341

    
1342

    
1343
function upgrade_047_to_048() {
1344
	global $config;
1345
	if (!empty($config['dyndns'])) {
1346
		$config['dyndnses'] = array();
1347
		$config['dyndnses']['dyndns'] = array();
1348
		if (isset($config['dyndns'][0]['host'])) {
1349
			$tempdyn = array();
1350
			$tempdyn['enable'] = isset($config['dyndns'][0]['enable']);
1351
			$tempdyn['type'] = $config['dyndns'][0]['type'];
1352
			$tempdyn['wildcard'] = isset($config['dyndns'][0]['wildcard']);
1353
			$tempdyn['username'] = $config['dyndns'][0]['username'];
1354
			$tempdyn['password'] = $config['dyndns'][0]['password'];
1355
			$tempdyn['host'] = $config['dyndns'][0]['host'];
1356
			$tempdyn['mx'] = $config['dyndns'][0]['mx'];
1357
			$tempdyn['interface'] = "wan";
1358
			$tempdyn['descr'] = sprintf(gettext("Upgraded Dyndns %s"), $tempdyn['type']);
1359
			$config['dyndnses']['dyndns'][] = $tempdyn;
1360
		}
1361
		unset($config['dyndns']);
1362
	}
1363
	if (!empty($config['dnsupdate'])) {
1364
		$pconfig = $config['dnsupdate'][0];
1365
		if (!$pconfig['ttl']) {
1366
			$pconfig['ttl'] = 60;
1367
		}
1368
		if (!$pconfig['keytype']) {
1369
			$pconfig['keytype'] = "zone";
1370
		}
1371
		$pconfig['interface'] = "wan";
1372
		$config['dnsupdates']['dnsupdate'][] = $pconfig;
1373
		unset($config['dnsupdate']);
1374
	}
1375

    
1376
	if (is_array($config['pppoe']) && is_array($config['pppoe'][0])) {
1377
		$pconfig = array();
1378
		$pconfig['username'] = $config['pppoe'][0]['username'];
1379
		$pconfig['password'] = $config['pppoe'][0]['password'];
1380
		$pconfig['provider'] = $config['pppoe'][0]['provider'];
1381
		$pconfig['ondemand'] = isset($config['pppoe'][0]['ondemand']);
1382
		$pconfig['timeout'] = $config['pppoe'][0]['timeout'];
1383
		unset($config['pppoe']);
1384
		$config['interfaces']['wan']['pppoe_username'] = $pconfig['username'];
1385
		$config['interfaces']['wan']['pppoe_password'] = $pconfig['password'];
1386
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1387
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
1388
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1389
	}
1390
	if (is_array($config['pptp'])) {
1391
		$pconfig = array();
1392
		$pconfig['username'] = $config['pptp']['username'];
1393
		$pconfig['password'] = $config['pptp']['password'];
1394
		$pconfig['provider'] = $config['pptp']['provider'];
1395
		$pconfig['ondemand'] = isset($config['pptp']['ondemand']);
1396
		$pconfig['timeout'] = $config['pptp']['timeout'];
1397
		unset($config['pptp']);
1398
		$config['interfaces']['wan']['pptp_username'] = $pconfig['username'];
1399
		$config['interfaces']['wan']['pptp_password'] = $pconfig['password'];
1400
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1401
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
1402
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1403
	}
1404
}
1405

    
1406

    
1407
function upgrade_048_to_049() {
1408
	global $config;
1409
	/* setup new all users group */
1410
	$all = array();
1411
	$all['name'] = "all";
1412
	$all['description'] = gettext("All Users");
1413
	$all['scope'] = "system";
1414
	$all['gid'] = 1998;
1415
	$all['member'] = array();
1416

    
1417
	if (!is_array($config['system']['user'])) {
1418
		$config['system']['user'] = array();
1419
	}
1420
	if (!is_array($config['system']['group'])) {
1421
		$config['system']['group'] = array();
1422
	}
1423

    
1424
	/* work around broken uid assignments */
1425
	$config['system']['nextuid'] = 2000;
1426
	foreach ($config['system']['user'] as & $user) {
1427
		if (isset($user['uid']) && !$user['uid']) {
1428
			continue;
1429
		}
1430
		$user['uid'] = $config['system']['nextuid']++;
1431
	}
1432

    
1433
	/* work around broken gid assignments */
1434
	$config['system']['nextgid'] = 2000;
1435
	foreach ($config['system']['group'] as & $group) {
1436
		if ($group['name'] == $g['admin_group']) {
1437
			$group['gid'] = 1999;
1438
		} else {
1439
			$group['gid'] = $config['system']['nextgid']++;
1440
		}
1441
	}
1442

    
1443
	/* build group membership information */
1444
	foreach ($config['system']['group'] as & $group) {
1445
		$group['member'] = array();
1446
		foreach ($config['system']['user'] as & $user) {
1447
			$groupnames = explode(",", $user['groupname']);
1448
			if (in_array($group['name'], $groupnames)) {
1449
				$group['member'][] = $user['uid'];
1450
			}
1451
		}
1452
	}
1453

    
1454
	/* reset user group information */
1455
	foreach ($config['system']['user'] as & $user) {
1456
		unset($user['groupname']);
1457
		$all['member'][] = $user['uid'];
1458
	}
1459

    
1460
	/* reset group scope information */
1461
	foreach ($config['system']['group'] as & $group) {
1462
		if ($group['name'] != $g['admin_group']) {
1463
			$group['scope'] = "user";
1464
		}
1465
	}
1466

    
1467
	/* insert new all group */
1468
	$groups = Array();
1469
	$groups[] = $all;
1470
	$groups = array_merge($config['system']['group'], $groups);
1471
	$config['system']['group'] = $groups;
1472
}
1473

    
1474

    
1475
function upgrade_049_to_050() {
1476
	global $config;
1477

    
1478
	if (!is_array($config['system']['user'])) {
1479
		$config['system']['user'] = array();
1480
	}
1481
	/* update user privileges */
1482
	foreach ($config['system']['user'] as & $user) {
1483
		$privs = array();
1484
		if (!is_array($user['priv'])) {
1485
			unset($user['priv']);
1486
			continue;
1487
		}
1488
		foreach ($user['priv'] as $priv) {
1489
			switch ($priv['id']) {
1490
				case "hasshell":
1491
					$privs[] = "user-shell-access";
1492
					break;
1493
				case "copyfiles":
1494
					$privs[] = "user-copy-files";
1495
					break;
1496
			}
1497
		}
1498
		$user['priv'] = $privs;
1499
	}
1500

    
1501
	/* update group privileges */
1502
	foreach ($config['system']['group'] as & $group) {
1503
		$privs = array();
1504
		if (!is_array($group['pages'])) {
1505
			unset($group['pages']);
1506
			continue;
1507
		}
1508
		foreach ($group['pages'] as $page) {
1509
			$priv = map_page_privname($page);
1510
			if ($priv) {
1511
				$privs[] = $priv;
1512
			}
1513
		}
1514
		unset($group['pages']);
1515
		$group['priv'] = $privs;
1516
	}
1517

    
1518
	/* sync all local account information */
1519
	local_sync_accounts();
1520
}
1521

    
1522

    
1523
function upgrade_050_to_051() {
1524
	global $config;
1525
	$pconfig = array();
1526
	$pconfig['descr'] = "Set to 0 to disable filtering on the incoming and outgoing member interfaces.";
1527
	$pconfig['tunable'] = "net.link.bridge.pfil_member";
1528
	$pconfig['value'] = "1";
1529
	$config['sysctl']['item'][] = $pconfig;
1530
	$pconfig = array();
1531
	$pconfig['descr'] = "Set to 1 to enable filtering on the bridge interface";
1532
	$pconfig['tunable'] = "net.link.bridge.pfil_bridge";
1533
	$pconfig['value'] = "0";
1534
	$config['sysctl']['item'][] = $pconfig;
1535

    
1536
	if (isset($config['bridge'])) {
1537
		unset($config['bridge']);
1538
	}
1539

    
1540
	$convert_bridges = false;
1541
	foreach ($config['interfaces'] as $intf) {
1542
		if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1543
			$config['bridges'] = array();
1544
			$config['bridges']['bridged'] = array();
1545
			$convert_bridges = true;
1546
			break;
1547
		}
1548
	}
1549
	if ($convert_bridges == true) {
1550
		$i = 0;
1551
		foreach ($config['interfaces'] as $ifr => &$intf) {
1552
			if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1553
				$nbridge = array();
1554
				$nbridge['members'] = "{$ifr},{$intf['bridge']}";
1555
				$nbridge['descr'] = sprintf(gettext("Converted bridged %s"), $ifr);
1556
				$nbridge['bridgeif'] = "bridge{$i}";
1557
				$config['bridges']['bridged'][] = $nbridge;
1558
				unset($intf['bridge']);
1559
				$i++;
1560
			}
1561
		}
1562
	}
1563
}
1564

    
1565

    
1566
function upgrade_051_to_052() {
1567
	global $config;
1568
	$config['openvpn'] = array();
1569
	if (!is_array($config['ca'])) {
1570
		$config['ca'] = array();
1571
	}
1572
	if (!is_array($config['cert'])) {
1573
		$config['cert'] = array();
1574
	}
1575

    
1576
	$vpnid = 1;
1577

    
1578
	/* openvpn server configurations */
1579
	if (is_array($config['installedpackages']['openvpnserver'])) {
1580
		$config['openvpn']['openvpn-server'] = array();
1581

    
1582
		$index = 1;
1583
		foreach ($config['installedpackages']['openvpnserver']['config'] as $server) {
1584

    
1585
			if (!is_array($server)) {
1586
				continue;
1587
			}
1588

    
1589
			if ($server['auth_method'] == "pki") {
1590

    
1591
				/* create ca entry */
1592
				$ca = array();
1593
				$ca['refid'] = uniqid();
1594
				$ca['descr'] = "OpenVPN Server CA #{$index}";
1595
				$ca['crt'] = $server['ca_cert'];
1596
				$config['ca'][] = $ca;
1597

    
1598
				/* create ca reference */
1599
				unset($server['ca_cert']);
1600
				$server['caref'] = $ca['refid'];
1601

    
1602
				/* create a crl entry if needed */
1603
				if (!empty($server['crl'][0])) {
1604
					$crl = array();
1605
					$crl['refid'] = uniqid();
1606
					$crl['descr'] = "Imported OpenVPN CRL #{$index}";
1607
					$crl['caref'] = $ca['refid'];
1608
					$crl['text'] = $server['crl'][0];
1609
					if (!is_array($config['crl'])) {
1610
						$config['crl'] = array();
1611
					}
1612
					$config['crl'][] = $crl;
1613
					$server['crlref'] = $crl['refid'];
1614
				}
1615
				unset($server['crl']);
1616

    
1617
				/* create cert entry */
1618
				$cert = array();
1619
				$cert['refid'] = uniqid();
1620
				$cert['descr'] = "OpenVPN Server Certificate #{$index}";
1621
				$cert['crt'] = $server['server_cert'];
1622
				$cert['prv'] = $server['server_key'];
1623
				$config['cert'][] = $cert;
1624

    
1625
				/* create cert reference */
1626
				unset($server['server_cert']);
1627
				unset($server['server_key']);
1628
				$server['certref'] = $cert['refid'];
1629

    
1630
				$index++;
1631
			}
1632

    
1633
			/* determine operational mode */
1634
			if ($server['auth_method'] == 'pki') {
1635
				if ($server['nopool']) {
1636
					$server['mode'] = "p2p_tls";
1637
				} else {
1638
					$server['mode'] = "server_tls";
1639
				}
1640
			} else {
1641
				$server['mode'] = "p2p_shared_key";
1642
			}
1643
			unset($server['auth_method']);
1644

    
1645
			/* modify configuration values */
1646
			$server['dh_length'] = 1024;
1647
			unset($server['dh_params']);
1648
			if (!$server['interface']) {
1649
				$server['interface'] = 'any';
1650
			}
1651
			$server['tunnel_network'] = $server['addresspool'];
1652
			unset($server['addresspool']);
1653
			if (isset($server['use_lzo']) && ($server['use_lzo'] == "on")) {
1654
				$server['compression'] = "on";
1655
				unset($server['use_lzo']);
1656
			}
1657
			if ($server['nopool']) {
1658
				$server['pool_enable'] = false;
1659
			} else {
1660
				$server['pool_enable'] = "yes";
1661
			}
1662
			unset($server['nopool']);
1663
			$server['dns_domain'] = $server['dhcp_domainname'];
1664
			unset($server['dhcp_domainname']);
1665

    
1666
			$tmparr = explode(";", $server['dhcp_dns'], 4);
1667
			$d=1;
1668
			foreach ($tmparr as $tmpa) {
1669
				$server["dns_server{$d}"] = $tmpa;
1670
				$d++;
1671
			}
1672
			unset($server['dhcp_dns']);
1673

    
1674
			$tmparr = explode(";", $server['dhcp_ntp'], 2);
1675
			$d=1;
1676
			foreach ($tmparr as $tmpa) {
1677
				$server["ntp_server{$d}"] = $tmpa;
1678
				$d++;
1679
			}
1680
			unset($server['dhcp_ntp']);
1681

    
1682
			if ($server['dhcp_nbtdisable']) {
1683
				$server['netbios_enable'] = false;
1684
			} else {
1685
				$server['netbios_enable'] = "yes";
1686
			}
1687
			unset($server['dhcp_nbtdisable']);
1688
			$server['netbios_ntype'] = $server['dhcp_nbttype'];
1689
			unset($server['dhcp_nbttype']);
1690
			$server['netbios_scope'] = $server['dhcp_nbtscope'];
1691
			unset($server['dhcp_nbtscope']);
1692

    
1693
			$tmparr = explode(";", $server['dhcp_nbdd'], 2);
1694
			$d=1;
1695
			foreach ($tmparr as $tmpa) {
1696
				$server["nbdd_server{$d}"] = $tmpa;
1697
				$d++;
1698
			}
1699
			unset($server['dhcp_nbdd']);
1700

    
1701
			$tmparr = explode(";", $server['dhcp_wins'], 2);
1702
			$d=1;
1703
			foreach ($tmparr as $tmpa) {
1704
				$server["wins_server{$d}"] = $tmpa;
1705
				$d++;
1706
			}
1707
			unset($server['dhcp_wins']);
1708

    
1709
			if (!empty($server['disable'])) {
1710
				$server['disable'] = true;
1711
			} else {
1712
				unset($server['disable']);
1713
			}
1714

    
1715
			/* allocate vpnid */
1716
			$server['vpnid'] = $vpnid++;
1717

    
1718
			if (!empty($server['custom_options'])) {
1719
				$cstmopts = array();
1720
				$tmpcstmopts = explode(";", $server['custom_options']);
1721
				$assigned_if = "";
1722
				$tmpstr = "";
1723
				foreach ($tmpcstmopts as $tmpcstmopt) {
1724
					$tmpstr = str_replace(" ", "", $tmpcstmopt);
1725
					if (substr($tmpstr, 0, 6) == "devtun") {
1726
						$assigned_if = substr($tmpstr, 3);
1727
						continue;
1728
					} else if (substr($tmpstr, 0, 5) == "local") {
1729
						$localip = substr($tmpstr, 5);
1730
						$server['ipaddr'] = str_replace("\n", "", $localip);
1731
					} else {
1732
						$cstmopts[] = $tmpcstmopt;
1733
					}
1734
				}
1735
				$server['custom_options'] = implode(";", $cstmopts);
1736
				if (!empty($assigned_if)) {
1737
					foreach ($config['interfaces'] as $iface => $cfgif) {
1738
						if ($cfgif['if'] == $assigned_if) {
1739
							$config['interfaces'][$iface]['if'] = "ovpns{$server['vpnid']}";
1740
							break;
1741
						}
1742
					}
1743
				}
1744
			}
1745

    
1746
			$config['openvpn']['openvpn-server'][] = $server;
1747
		}
1748
		unset($config['installedpackages']['openvpnserver']);
1749
	}
1750

    
1751
	/* openvpn client configurations */
1752
	if (is_array($config['installedpackages']['openvpnclient'])) {
1753
		$config['openvpn']['openvpn-client'] = array();
1754

    
1755
		$index = 1;
1756
		foreach ($config['installedpackages']['openvpnclient']['config'] as $client) {
1757

    
1758
			if (!is_array($client)) {
1759
				continue;
1760
			}
1761

    
1762
			if ($client['auth_method'] == "pki") {
1763

    
1764
				/* create ca entry */
1765
				$ca = array();
1766
				$ca['refid'] = uniqid();
1767
				$ca['descr'] = "OpenVPN Client CA #{$index}";
1768
				$ca['crt'] = $client['ca_cert'];
1769
				$ca['crl'] = $client['crl'];
1770
				$config['ca'][] = $ca;
1771

    
1772
				/* create ca reference */
1773
				unset($client['ca_cert']);
1774
				unset($client['crl']);
1775
				$client['caref'] = $ca['refid'];
1776

    
1777
				/* create cert entry */
1778
				$cert = array();
1779
				$cert['refid'] = uniqid();
1780
				$cert['descr'] = "OpenVPN Client Certificate #{$index}";
1781
				$cert['crt'] = $client['client_cert'];
1782
				$cert['prv'] = $client['client_key'];
1783
				$config['cert'][] = $cert;
1784

    
1785
				/* create cert reference */
1786
				unset($client['client_cert']);
1787
				unset($client['client_key']);
1788
				$client['certref'] = $cert['refid'];
1789

    
1790
				$index++;
1791
			}
1792

    
1793
			/* determine operational mode */
1794
			if ($client['auth_method'] == 'pki') {
1795
				$client['mode'] = "p2p_tls";
1796
			} else {
1797
				$client['mode'] = "p2p_shared_key";
1798
			}
1799
			unset($client['auth_method']);
1800

    
1801
			/* modify configuration values */
1802
			if (!$client['interface']) {
1803
				$client['interface'] = 'wan';
1804
			}
1805
			$client['tunnel_network'] = $client['interface_ip'];
1806
			unset($client['interface_ip']);
1807
			$client['server_addr'] = $client['serveraddr'];
1808
			unset($client['serveraddr']);
1809
			$client['server_port'] = $client['serverport'];
1810
			unset($client['serverport']);
1811
			$client['proxy_addr'] = $client['poxy_hostname'];
1812
			unset($client['proxy_addr']);
1813
			if (isset($client['use_lzo']) && ($client['use_lzo'] == "on")) {
1814
				$client['compression'] = "on";
1815
				unset($client['use_lzo']);
1816
			}
1817
			$client['resolve_retry'] = $client['infiniteresolvretry'];
1818
			unset($client['infiniteresolvretry']);
1819

    
1820
			/* allocate vpnid */
1821
			$client['vpnid'] = $vpnid++;
1822

    
1823
			if (!empty($client['custom_options'])) {
1824
				$cstmopts = array();
1825
				$tmpcstmopts = explode(";", $client['custom_options']);
1826
				$assigned_if = "";
1827
				$tmpstr = "";
1828
				foreach ($tmpcstmopts as $tmpcstmopt) {
1829
					$tmpstr = str_replace(" ", "", $tmpcstmopt);
1830
					if (substr($tmpstr, 0, 6) == "devtun") {
1831
						$assigned_if = substr($tmpstr, 3);
1832
						continue;
1833
					} else if (substr($tmpstr, 0, 5) == "local") {
1834
						$localip = substr($tmpstr, 5);
1835
						$client['ipaddr'] = str_replace("\n", "", $localip);
1836
					} else {
1837
						$cstmopts[] = $tmpcstmopt;
1838
					}
1839
				}
1840
				$client['custom_options'] = implode(";", $cstmopts);
1841
				if (!empty($assigned_if)) {
1842
					foreach ($config['interfaces'] as $iface => $cfgif) {
1843
						if ($cfgif['if'] == $assigned_if) {
1844
							$config['interfaces'][$iface]['if'] = "ovpnc{$client['vpnid']}";
1845
							break;
1846
						}
1847
					}
1848
				}
1849
			}
1850

    
1851
			if (!empty($client['disable'])) {
1852
				$client['disable'] = true;
1853
			} else {
1854
				unset($client['disable']);
1855
			}
1856

    
1857
			$config['openvpn']['openvpn-client'][] = $client;
1858
		}
1859

    
1860
		unset($config['installedpackages']['openvpnclient']);
1861
	}
1862

    
1863
	/* openvpn client specific configurations */
1864
	if (is_array($config['installedpackages']['openvpncsc'])) {
1865
		$config['openvpn']['openvpn-csc'] = array();
1866

    
1867
		foreach ($config['installedpackages']['openvpncsc']['config'] as $csc) {
1868

    
1869
			if (!is_array($csc)) {
1870
				continue;
1871
			}
1872

    
1873
			/* modify configuration values */
1874
			$csc['common_name'] = $csc['commonname'];
1875
			unset($csc['commonname']);
1876
			$csc['tunnel_network'] = $csc['ifconfig_push'];
1877
			unset($csc['ifconfig_push']);
1878
			$csc['dns_domain'] = $csc['dhcp_domainname'];
1879
			unset($csc['dhcp_domainname']);
1880

    
1881
			$tmparr = explode(";", $csc['dhcp_dns'], 4);
1882
			$d=1;
1883
			foreach ($tmparr as $tmpa) {
1884
				$csc["dns_server{$d}"] = $tmpa;
1885
				$d++;
1886
			}
1887
			unset($csc['dhcp_dns']);
1888

    
1889
			$tmparr = explode(";", $csc['dhcp_ntp'], 2);
1890
			$d=1;
1891
			foreach ($tmparr as $tmpa) {
1892
				$csc["ntp_server{$d}"] = $tmpa;
1893
				$d++;
1894
			}
1895
			unset($csc['dhcp_ntp']);
1896

    
1897
			if ($csc['dhcp_nbtdisable']) {
1898
				$csc['netbios_enable'] = false;
1899
			} else {
1900
				$csc['netbios_enable'] = "yes";
1901
			}
1902
			unset($csc['dhcp_nbtdisable']);
1903
			$csc['netbios_ntype'] = $csc['dhcp_nbttype'];
1904
			unset($csc['dhcp_nbttype']);
1905
			$csc['netbios_scope'] = $csc['dhcp_nbtscope'];
1906
			unset($csc['dhcp_nbtscope']);
1907

    
1908
			$tmparr = explode(";", $csc['dhcp_nbdd'], 2);
1909
			$d=1;
1910
			foreach ($tmparr as $tmpa) {
1911
				$csc["nbdd_server{$d}"] = $tmpa;
1912
				$d++;
1913
			}
1914
			unset($csc['dhcp_nbdd']);
1915

    
1916
			$tmparr = explode(";", $csc['dhcp_wins'], 2);
1917
			$d=1;
1918
			foreach ($tmparr as $tmpa) {
1919
				$csc["wins_server{$d}"] = $tmpa;
1920
				$d++;
1921
			}
1922
			unset($csc['dhcp_wins']);
1923

    
1924
			if (!empty($csc['disable'])) {
1925
				$csc['disable'] = true;
1926
			} else {
1927
				unset($csc['disable']);
1928
			}
1929

    
1930
			$config['openvpn']['openvpn-csc'][] = $csc;
1931
		}
1932

    
1933
		unset($config['installedpackages']['openvpncsc']);
1934
	}
1935

    
1936
	if (count($config['openvpn']['openvpn-server']) > 0 ||
1937
	    count($config['openvpn']['openvpn-client']) > 0) {
1938
		$ovpnrule = array();
1939
		$ovpnrule['type'] = "pass";
1940
		$ovpnrule['interface'] = "openvpn";
1941
		$ovpnrule['statetype'] = "keep state";
1942
		$ovpnrule['source'] = array();
1943
		$ovpnrule['destination'] = array();
1944
		$ovpnrule['source']['any'] = true;
1945
		$ovpnrule['destination']['any'] = true;
1946
		$ovpnrule['descr'] = gettext("Auto added OpenVPN rule from config upgrade.");
1947
		$config['filter']['rule'][] = $ovpnrule;
1948
	}
1949

    
1950
	/*
1951
		* FIXME: hack to keep things working with no installedpackages
1952
		* or carp array in the configuration data.
1953
		*/
1954
	if (!is_array($config['installedpackages'])) {
1955
		$config['installedpackages'] = array();
1956
	}
1957
	if (!is_array($config['installedpackages']['carp'])) {
1958
		$config['installedpackages']['carp'] = array();
1959
	}
1960

    
1961
}
1962

    
1963

    
1964
function upgrade_052_to_053() {
1965
	global $config;
1966
	if (!is_array($config['ca'])) {
1967
		$config['ca'] = array();
1968
	}
1969
	if (!is_array($config['cert'])) {
1970
		$config['cert'] = array();
1971
	}
1972

    
1973
	/* migrate advanced admin page webui ssl to certificate manager */
1974
	if ($config['system']['webgui']['certificate'] &&
1975
	    $config['system']['webgui']['private-key']) {
1976

    
1977
		/* create cert entry */
1978
		$cert = array();
1979
		$cert['refid'] = uniqid();
1980
		$cert['descr'] = "webConfigurator SSL Certificate";
1981
		$cert['crt'] = $config['system']['webgui']['certificate'];
1982
		$cert['prv'] = $config['system']['webgui']['private-key'];
1983
		$config['cert'][] = $cert;
1984

    
1985
		/* create cert reference */
1986
		unset($config['system']['webgui']['certificate']);
1987
		unset($config['system']['webgui']['private-key']);
1988
		$config['system']['webgui']['ssl-certref'] = $cert['refid'];
1989
	}
1990

    
1991
	/* migrate advanced admin page ssh keys to user manager */
1992
	if ($config['system']['ssh']['authorizedkeys']) {
1993
		$admin_user =& getUserEntryByUID(0);
1994
		$admin_user['authorizedkeys'] = $config['system']['ssh']['authorizedkeys'];
1995
		unset($config['system']['ssh']['authorizedkeys']);
1996
	}
1997
}
1998

    
1999

    
2000
function upgrade_053_to_054() {
2001
	global $config;
2002
	if (is_array($config['load_balancer']['lbpool'])) {
2003
		$lbpool_arr = $config['load_balancer']['lbpool'];
2004
		$lbpool_srv_arr = array();
2005
		$gateway_group_arr = array();
2006
		$gateways = return_gateways_array();
2007
		$group_name_changes = array();
2008
		if (!is_array($config['gateways']['gateway_item'])) {
2009
			$config['gateways']['gateway_item'] = array();
2010
		}
2011

    
2012
		$a_gateways =& $config['gateways']['gateway_item'];
2013
		foreach ($lbpool_arr as $lbpool) {
2014
			if ($lbpool['type'] == "gateway") {
2015
				// Gateway Groups have to have valid names in pf, old lb pools did not. Clean them up.
2016
				$group_name = preg_replace("/[^A-Za-z0-9]/", "", $lbpool['name']);
2017
				// If we made and changes, check for collisions and note the change.
2018
				if ($group_name != $lbpool['name']) {
2019
					// Make sure the name isn't already in use.
2020
					foreach ($gateway_group_arr as $gwg) {
2021
						// If the name is in use, add some random bits to avoid collision.
2022
						if ($gwg['name'] == $group_name) {
2023
							$group_name .= uniqid();
2024
						}
2025
					}
2026
					$group_name_changes[$lbpool['name']] = $group_name;
2027
				}
2028
				$gateway_group['name'] = $group_name;
2029
				$gateway_group['descr'] = $lbpool['descr'];
2030
				$gateway_group['trigger'] = "down";
2031
				$gateway_group['item'] = array();
2032
				$i = 0;
2033
				foreach ($lbpool['servers'] as $member) {
2034
					$split = explode("|", $member);
2035
					$interface = $split[0];
2036
					$monitor = $split[1];
2037
					/* on static upgraded configuration we automatically prepend GW_ */
2038
					$static_name = "GW_" . strtoupper($interface);
2039
					if (is_ipaddr($monitor)) {
2040
						foreach ($a_gateways as & $gw) {
2041
							if ($gw['name'] == $static_name) {
2042
								$gw['monitor'] = $monitor;
2043
							}
2044
						}
2045
					}
2046

    
2047
					/* on failover increment tier. Else always assign 1 */
2048
					if ($lbpool['behaviour'] == "failover") {
2049
						$i++;
2050
					} else {
2051
						$i = 1;
2052
					}
2053
					$gateway_group['item'][] = "$static_name|$i";
2054
				}
2055
				$gateway_group_arr[] = $gateway_group;
2056
			} else {
2057
				$lbpool_srv_arr[] = $lbpool;
2058
			}
2059
		}
2060
		$config['load_balancer']['lbpool'] = $lbpool_srv_arr;
2061
		$config['gateways']['gateway_group'] = $gateway_group_arr;
2062
	}
2063
	// Unset lbpool if we no longer have any server pools
2064
	if (count($lbpool_srv_arr) == 0) {
2065
		if (empty($config['load_balancer'])) {
2066
			unset($config['load_balancer']);
2067
		} else {
2068
			if (isset($config['load_balancer']['lbpool'])) {
2069
				unset($config['load_balancer']['lbpool']);
2070
			}
2071
		}
2072
	} else {
2073
		$config['load_balancer']['lbpool'] = $lbpool_srv_arr;
2074
	}
2075
	// Only set the gateway group array if we converted any
2076
	if (count($gateway_group_arr) != 0) {
2077
		$config['gateways']['gateway_group'] = $gateway_group_arr;
2078
		// Update any rules that had a gateway change, if any.
2079
		if (count($group_name_changes) > 0) {
2080
			foreach ($config['filter']['rule'] as & $rule) {
2081
				if (!empty($rule["gateway"]) && array_key_exists($rule["gateway"], $group_name_changes)) {
2082
					$rule["gateway"] = $group_name_changes[$rule["gateway"]];
2083
				}
2084
			}
2085
		}
2086
	}
2087
}
2088

    
2089

    
2090
function upgrade_054_to_055() {
2091
	global $config;
2092
	global $g;
2093

    
2094
	/* RRD files changed for quality, traffic and packets graphs */
2095
	//ini_set("max_execution_time", "1800");
2096
	/* convert traffic RRD file */
2097
	global $parsedcfg, $listtags;
2098
	$listtags = array("ds", "v", "rra", "row");
2099

    
2100
	$rrddbpath = "/var/db/rrd/";
2101
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
2102
	if ($g['platform'] != $g['product_name']) {
2103
		/* restore the databases, if we have one */
2104
		if (restore_rrd()) {
2105
			/* Make sure to move the rrd backup out of the way. We will make a new one after converting. */
2106
			@rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup/rrd.tgz");
2107
		}
2108
	}
2109

    
2110
	$rrdinterval = 60;
2111
	$valid = $rrdinterval * 2;
2112

    
2113
	/* Asume GigE for now */
2114
	$downstream = 125000000;
2115
	$upstream = 125000000;
2116

    
2117
	/* build a list of quality databases */
2118
	/* roundtrip has become delay */
2119
	function divide_delay($delayval) {
2120
		$delayval = floatval($delayval);
2121
		$delayval = ($delayval / 1000);
2122
		$delayval = " ". sprintf("%1.10e", $delayval) ." ";
2123
		return $delayval;
2124
	}
2125
	/* the roundtrip times need to be divided by 1000 to get seconds, really */
2126
	$databases = array();
2127
	if (!file_exists($rrddbpath)) {
2128
		@mkdir($rrddbpath);
2129
	}
2130
	chdir($rrddbpath);
2131
	$databases = glob("*-quality.rrd");
2132
	rsort($databases);
2133
	foreach ($databases as $database) {
2134
		$xmldump = "{$database}.old.xml";
2135
		$xmldumpnew = "{$database}.new.xml";
2136

    
2137
		if (platform_booting()) {
2138
			echo "Migrate RRD database {$database} to new format for IPv6 \n";
2139
		}
2140
		mwexec("$rrdtool tune {$rrddbpath}{$database} -r roundtrip:delay 2>&1");
2141

    
2142
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
2143
		$rrdold = xml2array(file_get_contents("{$g['tmp_path']}/{$xmldump}"), 1, "tag");
2144
		$rrdold = $rrdold['rrd'];
2145

    
2146
		$i = 0;
2147
		foreach ($rrdold['rra'] as $rra) {
2148
			$l = 0;
2149
			foreach ($rra['database']['row'] as $row) {
2150
				$vnew = divide_delay($row['v'][1]);
2151
				$rrdold['rra'][$i]['database']['row'][$l]['v'][1] = $vnew;
2152
				$l++;
2153
			}
2154
			$i++;
2155
		}
2156

    
2157
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", dump_xml_config_raw($rrdold, "rrd"));
2158
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
2159

    
2160
		unset($rrdold);
2161
		@unlink("{$g['tmp_path']}/{$xmldump}");
2162
		@unlink("{$g['tmp_path']}/{$xmldumpnew}");
2163
	}
2164
	/* let apinger recreate required files */
2165
	if (!platform_booting()) {
2166
		setup_gateways_monitor();
2167
	}
2168

    
2169
	/* build a list of traffic and packets databases */
2170
	$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
2171
	rsort($databases);
2172
	foreach ($databases as $database) {
2173
		$databasetmp = "{$database}.tmp";
2174
		$xmldump = "{$database}.old.xml";
2175
		$xmldumptmp = "{$database}.tmp.xml";
2176
		$xmldumpnew = "{$database}.new.xml";
2177

    
2178
		if (platform_booting()) {
2179
			echo "Migrate RRD database {$database} to new format \n";
2180
		}
2181
		/* rename DS source */
2182
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r in:inpass 2>&1");
2183
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r out:outpass 2>71");
2184

    
2185
		/* dump contents to xml and move database out of the way */
2186
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
2187

    
2188
		/* create new rrd database file */
2189
		$rrdcreate = "$rrdtool create {$g['tmp_path']}/{$databasetmp} --step $rrdinterval ";
2190
		$rrdcreate .= "DS:inpass:COUNTER:$valid:0:$downstream ";
2191
		$rrdcreate .= "DS:outpass:COUNTER:$valid:0:$upstream ";
2192
		$rrdcreate .= "DS:inblock:COUNTER:$valid:0:$downstream ";
2193
		$rrdcreate .= "DS:outblock:COUNTER:$valid:0:$upstream ";
2194
		$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
2195
		$rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
2196
		$rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
2197
		$rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
2198

    
2199
		create_new_rrd("$rrdcreate");
2200
		/* create temporary xml from new RRD */
2201
		dump_rrd_to_xml("{$g['tmp_path']}/{$databasetmp}", "{$g['tmp_path']}/{$xmldumptmp}");
2202

    
2203
		$rrdold = xml2array(file_get_contents("{$g['tmp_path']}/{$xmldump}"), 1, "tag");
2204
		$rrdold = $rrdold['rrd'];
2205

    
2206
		$rrdnew = xml2array(file_get_contents("{$g['tmp_path']}/{$xmldumptmp}"), 1, "tag");
2207
		$rrdnew = $rrdnew['rrd'];
2208

    
2209
		/* remove any MAX RRA's. Not needed for traffic. */
2210
		$i = 0;
2211
		foreach ($rrdold['rra'] as $rra) {
2212
			if (trim($rra['cf']) == "MAX") {
2213
				unset($rrdold['rra'][$i]);
2214
			}
2215
			$i++;
2216
		}
2217

    
2218
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", dump_xml_config_raw(migrate_rrd_format($rrdold, $rrdnew), "rrd"));
2219
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
2220
		/* we now have the rrd with the new fields, adjust the size now. */
2221
		/* RRA 2 is 60 minutes, RRA 3 is 720 minutes */
2222
		mwexec("/bin/sync");
2223
		mwexec("$rrdtool resize {$rrddbpath}/{$database} 2 GROW 2000;/bin/mv resize.rrd {$rrddbpath}/{$database} 2>&1");
2224
		mwexec("/bin/sync");
2225
		mwexec("$rrdtool resize {$rrddbpath}/{$database} 3 GROW 2000;/bin/mv resize.rrd {$rrddbpath}/{$database} 2>&1");
2226
		unset($rrdxmlarray);
2227
		@unlink("{$g['tmp_path']}/{$xmldump}");
2228
		@unlink("{$g['tmp_path']}/{$xmldumpnew}");
2229
	}
2230
	if (!platform_booting()) {
2231
		enable_rrd_graphing();
2232
	}
2233
	/* Let's save the RRD graphs after we run enable RRD graphing */
2234
	/* The function will restore the rrd.tgz so we will save it after */
2235
	exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
2236
	unlink_if_exists("{$g['vardb_path']}/rrd/*.xml");
2237
	if (platform_booting()) {
2238
		echo "Updating configuration...";
2239
	}
2240
}
2241

    
2242

    
2243
function upgrade_055_to_056() {
2244
	global $config;
2245

    
2246
	if (!is_array($config['ca'])) {
2247
		$config['ca'] = array();
2248
	}
2249
	if (!is_array($config['cert'])) {
2250
		$config['cert'] = array();
2251
	}
2252

    
2253
	/* migrate ipsec ca's to cert manager */
2254
	if (is_array($config['ipsec']['cacert'])) {
2255
		foreach ($config['ipsec']['cacert'] as & $cacert) {
2256
			$ca = array();
2257
			$ca['refid'] = uniqid();
2258
			if (is_array($cacert['cert'])) {
2259
				$ca['crt'] = $cacert['cert'][0];
2260
			} else {
2261
				$ca['crt'] = $cacert['cert'];
2262
			}
2263
			$ca['descr'] = $cacert['ident'];
2264
			$config['ca'][] = $ca;
2265
		}
2266
		unset($config['ipsec']['cacert']);
2267
	}
2268

    
2269
	/* migrate phase1 certificates to cert manager */
2270
	if (is_array($config['ipsec']['phase1'])) {
2271
		foreach ($config['ipsec']['phase1'] as & $ph1ent) {
2272
			$cert = array();
2273
			$cert['refid'] = uniqid();
2274
			$cert['descr'] = "IPsec Peer {$ph1ent['remote-gateway']} Certificate";
2275
			if (is_array($ph1ent['cert'])) {
2276
				$cert['crt'] = $ph1ent['cert'][0];
2277
			} else {
2278
				$cert['crt'] = $ph1ent['cert'];
2279
			}
2280
			$cert['prv'] = $ph1ent['private-key'];
2281
			$config['cert'][] = $cert;
2282
			$ph1ent['certref'] = $cert['refid'];
2283
			if ($ph1ent['cert']) {
2284
				unset($ph1ent['cert']);
2285
			}
2286
			if ($ph1ent['private-key']) {
2287
				unset($ph1ent['private-key']);
2288
			}
2289
			if ($ph1ent['peercert']) {
2290
				unset($ph1ent['peercert']);
2291
			}
2292
		}
2293
	}
2294
}
2295

    
2296

    
2297
function upgrade_056_to_057() {
2298
	global $config;
2299

    
2300
	if (!is_array($config['system']['user'])) {
2301
		$config['system']['user'] = array();
2302
	}
2303
	/* migrate captivate portal to user manager */
2304
	if (is_array($config['captiveportal']['user'])) {
2305
		foreach ($config['captiveportal']['user'] as $user) {
2306
			// avoid user conflicts
2307
			$found = false;
2308
			foreach ($config['system']['user'] as $userent) {
2309
				if ($userent['name'] == $user['name']) {
2310
					$found = true;
2311
					break;
2312
				}
2313
			}
2314
			if ($found) {
2315
				continue;
2316
			}
2317
			$user['scope'] = "user";
2318
			if (isset($user['expirationdate'])) {
2319
				$user['expires'] = $user['expirationdate'];
2320
				unset($user['expirationdate']);
2321
			}
2322
			if (isset($user['password'])) {
2323
				$user['md5-hash'] = $user['password'];
2324
				unset($user['password']);
2325
			}
2326
			$user['uid'] = $config['system']['nextuid']++;
2327
			$config['system']['user'][] = $user;
2328
		}
2329
		unset($config['captiveportal']['user']);
2330
	}
2331
}
2332

    
2333
function upgrade_057_to_058() {
2334
	global $config;
2335
	/* set all phase2 entries to tunnel mode */
2336
	if (is_array($config['ipsec']['phase2'])) {
2337
		foreach ($config['ipsec']['phase2'] as & $ph2ent) {
2338
			$ph2ent['mode'] = 'tunnel';
2339
		}
2340
	}
2341
}
2342

    
2343
function upgrade_058_to_059() {
2344
	global $config;
2345

    
2346
	if (is_array($config['schedules']['schedule'])) {
2347
		foreach ($config['schedules']['schedule'] as & $schedl) {
2348
			$schedl['schedlabel'] = uniqid();
2349
		}
2350
	}
2351
}
2352

    
2353
function upgrade_059_to_060() {
2354
	global $config;
2355
	require_once("/etc/inc/certs.inc");
2356
	if (is_array($config['ca'])) {
2357
		/* Locate issuer for all CAs */
2358
		foreach ($config['ca'] as & $ca) {
2359
			$subject = cert_get_subject($ca['crt']);
2360
			$issuer = cert_get_issuer($ca['crt']);
2361
			if ($issuer <> $subject) {
2362
				$issuer_crt =& lookup_ca_by_subject($issuer);
2363
				if ($issuer_crt) {
2364
					$ca['caref'] = $issuer_crt['refid'];
2365
				}
2366
			}
2367
		}
2368

    
2369
		/* Locate issuer for all certificates */
2370
		if (is_array($config['cert'])) {
2371
			foreach ($config['cert'] as & $cert) {
2372
				$subject = cert_get_subject($cert['crt']);
2373
				$issuer = cert_get_issuer($cert['crt']);
2374
				if ($issuer <> $subject) {
2375
					$issuer_crt =& lookup_ca_by_subject($issuer);
2376
					if ($issuer_crt) {
2377
						$cert['caref'] = $issuer_crt['refid'];
2378
					}
2379
				}
2380
			}
2381
		}
2382
	}
2383
}
2384

    
2385
function upgrade_060_to_061() {
2386
	global $config;
2387

    
2388
	if (is_array($config['interfaces']['wan'])) {
2389
		$config['interfaces']['wan']['enable'] = true;
2390
	}
2391
	if (is_array($config['interfaces']['lan'])) {
2392
		$config['interfaces']['lan']['enable'] = true;
2393
	}
2394

    
2395
	/* On 1.2.3 the "mtu" field adjusted MSS.
2396
	   On 2.x the "mtu" field is actually the MTU. Rename accordingly.
2397
	   See redmine ticket #1886
2398
	*/
2399
	foreach ($config['interfaces'] as $ifr => &$intf) {
2400
		if (isset($intf['mtu']) && is_numeric($intf['mtu'])) {
2401
			$intf['mss'] = $intf['mtu'];
2402
			unset($intf['mtu']);
2403
		}
2404
	}
2405
}
2406

    
2407
function upgrade_061_to_062() {
2408
	global $config;
2409

    
2410
	/* Convert NAT port forwarding rules */
2411
	if (is_array($config['nat']['rule'])) {
2412
		$a_nat = &$config['nat']['rule'];
2413

    
2414
		foreach ($a_nat as &$natent) {
2415
			$natent['disabled'] = false;
2416
			$natent['nordr']    = false;
2417

    
2418
			$natent['source'] = array(
2419
				"not"     => false,
2420
				"any"     => true,
2421
				"port"    => ""
2422
			);
2423

    
2424
			$natent['destination'] = array(
2425
				"not"     => false,
2426
				"address" => $natent['external-address'],
2427
				"port"    => $natent['external-port']
2428
			);
2429

    
2430
			if (empty($natent['destination']['address'])) {
2431
				unset($natent['destination']['address']);
2432
				$natent['destination']['network'] = $natent['interface'] . 'ip';
2433
			} else if ($natent['destination']['address'] == 'any') {
2434
				unset($natent['destination']['address']);
2435
				$natent['destination']['any'] = true;
2436
			}
2437

    
2438
			unset($natent['external-address']);
2439
			unset($natent['external-port']);
2440
		}
2441

    
2442
		unset($natent);
2443
	}
2444
}
2445

    
2446
function upgrade_062_to_063() {
2447
	/* Upgrade legacy Themes to the new pfsense_ng */
2448
	// Not supported in 2.3+
2449

    
2450
}
2451

    
2452
function upgrade_063_to_064() {
2453
	global $config;
2454
	$j = 0;
2455
	$ifcfg = &$config['interfaces'];
2456

    
2457
	if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
2458
		foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
2459
			$config['ppps']['ppp'][$pppid]['if'] = "ppp".$j;
2460
			$config['ppps']['ppp'][$pppid]['ptpid'] = $j;
2461
			$j++;
2462
			if (isset($ppp['port'])) {
2463
				$config['ppps']['ppp'][$pppid]['ports'] = $ppp['port'];
2464
				unset($config['ppps']['ppp'][$pppid]['port']);
2465
			}
2466
			if (!isset($ppp['type'])) {
2467
				$config['ppps']['ppp'][$pppid]['type'] = "ppp";
2468
			}
2469
			if (isset($ppp['defaultgw'])) {
2470
				unset($config['ppps']['ppp'][$pppid]['defaultgw']);
2471
			}
2472
		}
2473
	}
2474

    
2475
	if (!is_array($config['ppps']['ppp'])) {
2476
		$config['ppps']['ppp'] = array();
2477
	}
2478
	$a_ppps = &$config['ppps']['ppp'];
2479

    
2480
	foreach ($ifcfg as $ifname => $ifinfo) {
2481
		$ppp = array();
2482
		// For pppoe conversion
2483
		if ($ifinfo['ipaddr'] == "pppoe" || $ifinfo['ipaddr'] == "pptp") {
2484
			if (isset($ifinfo['ptpid'])) {
2485
				continue;
2486
			}
2487
			$ppp['ptpid'] = $j;
2488
			$ppp['type'] = $ifinfo['ipaddr'];
2489
			$ppp['if'] = $ifinfo['ipaddr'].$j;
2490
			$ppp['ports'] = $ifinfo['if'];
2491
			if ($ifinfo['ipaddr'] == "pppoe") {
2492
				$ppp['username'] = $ifinfo['pppoe_username'];
2493
				$ppp['password'] = base64_encode($ifinfo['pppoe_password']);
2494
			}
2495
			if ($ifinfo['ipaddr'] == "pptp") {
2496
				$ppp['username'] = $ifinfo['pptp_username'];
2497
				$ppp['password'] = base64_encode($ifinfo['pptp_password']);
2498
			}
2499

    
2500
			if (isset($ifinfo['provider'])) {
2501
				$ppp['provider'] = $ifinfo['provider'];
2502
			}
2503
			if (isset($ifinfo['ondemand'])) {
2504
				$ppp['ondemand'] = true;
2505
			}
2506
			if (isset($ifinfo['timeout'])) {
2507
				$ppp['idletimeout'] = $ifinfo['timeout'];
2508
			}
2509
			if (isset($ifinfo['pppoe']['pppoe-reset-type'])) {
2510
				$ppp['pppoe-reset-type'] = $ifinfo['pppoe']['pppoe-reset-type'];
2511
				if (is_array($config['cron']['item'])) {
2512
					for ($i = 0; $i < count($config['cron']['item']); $i++) {
2513
						$item = $config['cron']['item'][$i];
2514
						if (strpos($item['command'], "/conf/pppoe{$ifname}restart") !== false) {
2515
							$config['cron']['item'][$i]['command'] = "/var/etc/pppoe_restart_" . $ppp['if'];
2516
						}
2517
					}
2518
				}
2519
			}
2520
			if (isset($ifinfo['local'])) {
2521
				$ppp['localip'] = $ifinfo['local'];
2522
			}
2523
			if (isset($ifinfo['subnet'])) {
2524
				$ppp['subnet'] = $ifinfo['subnet'];
2525
			}
2526
			if (isset($ifinfo['remote'])) {
2527
				$ppp['gateway'] = $ifinfo['remote'];
2528
			}
2529

    
2530
			$ifcfg[$ifname]['if'] = $ifinfo['ipaddr'].$j;
2531
			$j++;
2532

    
2533
			unset($ifcfg[$ifname]['pppoe_username']);
2534
			unset($ifcfg[$ifname]['pppoe_password']);
2535
			unset($ifcfg[$ifname]['provider']);
2536
			unset($ifcfg[$ifname]['ondemand']);
2537
			unset($ifcfg[$ifname]['timeout']);
2538
			unset($ifcfg[$ifname]['pppoe_reset']);
2539
			unset($ifcfg[$ifname]['pppoe_preset']);
2540
			unset($ifcfg[$ifname]['pppoe']);
2541
			unset($ifcfg[$ifname]['pptp_username']);
2542
			unset($ifcfg[$ifname]['pptp_password']);
2543
			unset($ifcfg[$ifname]['local']);
2544
			unset($ifcfg[$ifname]['subnet']);
2545
			unset($ifcfg[$ifname]['remote']);
2546

    
2547
			$a_ppps[] = $ppp;
2548

    
2549
		}
2550
	}
2551
}
2552

    
2553
function upgrade_064_to_065() {
2554
	/* Disable TSO and LRO in upgraded configs */
2555
	global $config;
2556
	$config['system']['disablesegmentationoffloading'] = true;
2557
	$config['system']['disablelargereceiveoffloading'] = true;
2558
}
2559

    
2560
function upgrade_065_to_066() {
2561
	global $config;
2562

    
2563
	$dhcrelaycfg =& $config['dhcrelay'];
2564

    
2565
	if (is_array($dhcrelaycfg)) {
2566
		$dhcrelayifs = array();
2567
		$foundifs = false;
2568
		/* DHCPRelay enabled on any interfaces? */
2569
		foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
2570
			if (isset($dhcrelayifconf['enable'])) {
2571
				$dhcrelayifs[] = $dhcrelayif;
2572
				unset($dhcrelaycfg['dhcrelayif']);
2573
				$foundifs = true;
2574
			}
2575
		}
2576
		if ($foundifs == true) {
2577
			$dhcrelaycfg['interface'] = implode(",", $dhcrelayifs);
2578
		}
2579
	}
2580
}
2581

    
2582
function upgrade_066_to_067() {
2583
	global $config;
2584
	if (isset($config['system']['ca'])) {
2585
		$config['ca'] = $config['system']['ca'];
2586
		unset($config['system']['ca']);
2587
	}
2588
	if (isset($config['system']['cert'])) {
2589
		$config['cert'] = $config['system']['cert'];
2590
		unset($config['system']['cert']);
2591
	}
2592
}
2593

    
2594
function upgrade_067_to_068() {
2595
	global $config;
2596

    
2597
	if (!empty($config['pppoe'])) {
2598
		$config['pppoes'] = array();
2599
		$config['pppoes']['pppoe'] = array();
2600
		$config['pppoes']['pppoe'][] = $config['pppoe'][0];
2601

    
2602
		if (is_array($config['pppoe']['user'])) {
2603
			$username = array();
2604
			foreach ($config['pppoe']['user'] as $user) {
2605
				$usr = $user['name'] . ":" . base64_encode($user['password']);
2606
				if ($user['ip']) {
2607
					$usr .= ":{$user['ip']}";
2608
				}
2609
				$username[] = $usr;
2610
			}
2611
			$config['pppoes']['pppoe'][0]['username'] = implode(" ", $username);
2612
		}
2613
		unset($config['pppoe']);
2614
	}
2615
}
2616

    
2617
function upgrade_068_to_069() {
2618
	global $config;
2619
	if (!is_array($config['system']['user'])) {
2620
		return;
2621
	}
2622
	foreach ($config['system']['user'] as & $user) {
2623
		if (!is_array($user['cert'])) {
2624
			continue;
2625
		}
2626
		$rids = array();
2627
		foreach ($user['cert'] as $id => $cert) {
2628
			if (!isset($cert['descr'])) {
2629
				continue;
2630
			}
2631
			$tcert = $cert;
2632
			// Make sure each cert gets a refid
2633
			if (!isset($tcert['refid'])) {
2634
				$tcert['refid'] = uniqid();
2635
			}
2636
			// Keep the cert references for this user
2637
			$rids[] = $tcert['refid'];
2638
			$config['cert'][] = $tcert;
2639
		}
2640
		// Replace user certs with cert references instead.
2641
		if (count($rids) > 0) {
2642
			$user['cert'] = $rids;
2643
		}
2644
	}
2645
}
2646

    
2647
function upgrade_069_to_070() {
2648
	global $config;
2649

    
2650
	/* Convert NAT 1:1 rules */
2651
	if (is_array($config['nat']['onetoone'])) {
2652
		foreach ($config['nat']['onetoone'] as $nidx => $natent) {
2653
			if ($natent['subnet'] == 32) {
2654
				$config['nat']['onetoone'][$nidx]['source'] = array("address" => $natent['internal']);
2655
			} else {
2656
				$config['nat']['onetoone'][$nidx]['source'] = array("address" => $natent['internal'] . "/" . $natent['subnet']);
2657
			}
2658

    
2659
			$config['nat']['onetoone'][$nidx]['destination'] = array("any" => true);
2660

    
2661
			unset($config['nat']['onetoone'][$nidx]['internal']);
2662
			unset($config['nat']['onetoone'][$nidx]['subnet']);
2663
		}
2664

    
2665
		unset($natent);
2666
	}
2667
}
2668

    
2669
function upgrade_070_to_071() {
2670
	global $config;
2671

    
2672
	if (is_array($config['cron']['item'])) {
2673
		foreach ($config['cron']['item'] as $idx => $cronitem) {
2674
			if (stristr($cronitem['command'], "checkreload.sh")) {
2675
				unset($config['cron']['item'][$idx]);
2676
				break;
2677
			}
2678
		}
2679
	}
2680
}
2681

    
2682
function rename_field(& $section, $oldname, $newname) {
2683
	if (is_array($section)) {
2684
		foreach ($section as & $item) {
2685
			if (is_array($item) && !empty($item[$oldname])) {
2686
				$item[$newname] = $item[$oldname];
2687
			}
2688
			if (is_array($item) && isset($item[$oldname])) {
2689
				unset($item[$oldname]);
2690
			}
2691
		}
2692
	}
2693
}
2694

    
2695
function upgrade_071_to_072() {
2696
	global $config;
2697
	if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) {
2698
		rename_field($config['sysctl']['item'], 'desc', 'descr');
2699
	}
2700
}
2701

    
2702
function upgrade_072_to_073() {
2703
	global $config;
2704
	if (!is_array($config['load_balancer'])) {
2705
		return;
2706
	}
2707
	if (is_array($config['load_balancer']['monitor_type'])) {
2708
		rename_field($config['load_balancer']['monitor_type'], 'desc', 'descr');
2709
	}
2710
	if (is_array($config['load_balancer']['lbpool'])) {
2711
		rename_field($config['load_balancer']['lbpool'], 'desc', 'descr');
2712
	}
2713
	if (is_array($config['load_balancer']['lbaction'])) {
2714
		rename_field($config['load_balancer']['lbaction'], 'desc', 'descr');
2715
	}
2716
	if (is_array($config['load_balancer']['lbprotocol'])) {
2717
		rename_field($config['load_balancer']['lbprotocol'], 'desc', 'descr');
2718
	}
2719
	if (is_array($config['load_balancer']['virtual_server'])) {
2720
		rename_field($config['load_balancer']['virtual_server'], 'desc', 'descr');
2721
	}
2722
}
2723

    
2724
function upgrade_073_to_074() {
2725
	global $config;
2726
	rename_field($config['system']['user'], 'fullname', 'descr');
2727
}
2728

    
2729
function upgrade_074_to_075() {
2730
	global $config;
2731
	if (is_array($config['ca'])) {
2732
		rename_field($config['ca'], 'name', 'descr');
2733
	}
2734
	if (is_array($config['cert'])) {
2735
		rename_field($config['cert'], 'name', 'descr');
2736
	}
2737
	if (is_array($config['crl'])) {
2738
		rename_field($config['crl'], 'name', 'descr');
2739
	}
2740
}
2741

    
2742
function upgrade_075_to_076() {
2743
	global $config;
2744
	$cron_item = array();
2745
	$cron_item['minute'] = "30";
2746
	$cron_item['hour'] = "12";
2747
	$cron_item['mday'] = "*";
2748
	$cron_item['month'] = "*";
2749
	$cron_item['wday'] = "*";
2750
	$cron_item['who'] = "root";
2751
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.update_urltables";
2752
	$config['cron']['item'][] = $cron_item;
2753
}
2754

    
2755
function upgrade_076_to_077() {
2756
	global $config;
2757
	foreach ($config['filter']['rule'] as & $rule) {
2758
		if (isset($rule['protocol']) && !empty($rule['protocol'])) {
2759
			$rule['protocol'] = strtolower($rule['protocol']);
2760
		}
2761
	}
2762
}
2763

    
2764
function upgrade_077_to_078() {
2765
	global $config;
2766
	if (is_array($config['pptpd']) && is_array($config['pptpd']['radius']) &&
2767
	    !is_array($config['pptpd']['radius']['server'])) {
2768
		$radarr = array();
2769
		$radsvr = array();
2770
		$radsvr['ip'] = $config['pptpd']['radius']['server'];
2771
		$radsvr['secret'] = $config['pptpd']['radius']['secret'];
2772
		$radsvr['port'] = 1812;
2773
		$radsvr['acctport'] = 1813;
2774
		$radsvr['enable'] = isset($config['pptpd']['radius']['enable']);
2775
		$radarr['accounting'] = isset($config['pptpd']['radius']['accounting']);
2776
		if ($radarr['accounting']) {
2777
			$radarr['acct_update'] = $radsvr['ip'];
2778
		}
2779
		$radarr['server'] = $radsvr;
2780
		$config['pptpd']['radius'] = $radarr;
2781
	}
2782
	if (is_array($config['pptpd'])) {
2783
		$config['pptpd']['n_pptp_units'] = empty($config['pptpd']['n_pptp_units']) ? 16 : $config['pptpd']['n_pptp_units'];
2784
	}
2785
}
2786
function upgrade_078_to_079() {
2787
	global $g;
2788
	/* Delete old and unused RRD file */
2789
	unlink_if_exists("{$g['vardb_path']}/rrd/captiveportal-totalusers.rrd");
2790
}
2791

    
2792
function upgrade_079_to_080() {
2793
	global $config;
2794

    
2795
	/* Upgrade config in 1.2.3 specifying a username other than admin for syncing. */
2796
	if (!empty($config['system']['username']) && is_array($config['installedpackages']['carpsettings']) &&
2797
	    is_array($config['installedpackages']['carpsettings']['config'])) {
2798
		$config['installedpackages']['carpsettings']['config'][0]['username'] = $config['system']['username'];
2799
		unset($config['system']['username']);
2800
	}
2801
}
2802

    
2803
function upgrade_080_to_081() {
2804
	global $config;
2805
	global $g;
2806
	/* Welcome to the 2.1 migration path */
2807

    
2808
	/* tag all the existing gateways as being IPv4 */
2809
	$i = 0;
2810
	if (is_array($config['gateways']['gateway_item'])) {
2811
		foreach ($config['gateways']['gateway_item'] as $gw) {
2812
			$config['gateways']['gateway_item'][$i]['ipprotocol'] = "inet";
2813
			$i++;
2814
		}
2815
	}
2816

    
2817
	/* RRD files changed for quality, traffic and packets graphs */
2818
	/* convert traffic RRD file */
2819
	global $parsedcfg, $listtags;
2820
	$listtags = array("ds", "v", "rra", "row");
2821

    
2822
	$rrddbpath = "/var/db/rrd/";
2823
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
2824

    
2825
	if ($g['platform'] != $g['product_name']) {
2826
		/* restore the databases, if we have one */
2827
		if (restore_rrd()) {
2828
			/* Make sure to move the rrd backup out of the way. We will make a new one after converting. */
2829
			@rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup/rrd.tgz");
2830
		}
2831
	}
2832

    
2833
	$rrdinterval = 60;
2834
	$valid = $rrdinterval * 2;
2835

    
2836
	/* Asume GigE for now */
2837
	$downstream = 125000000;
2838
	$upstream = 125000000;
2839

    
2840
	/* build a list of traffic and packets databases */
2841
	$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
2842
	rsort($databases);
2843
	foreach ($databases as $database) {
2844
		$xmldump = "{$database}.old.xml";
2845
		$xmldumpnew = "{$database}.new.xml";
2846

    
2847
		if (platform_booting()) {
2848
			echo "Migrate RRD database {$database} to new format for IPv6.\n";
2849
		}
2850

    
2851
		/* dump contents to xml and move database out of the way */
2852
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
2853

    
2854
		/* search and replace tags to add data sources */
2855
		$ds_search = "<!-- Round Robin Archives -->";
2856
		$ds_arr = array();
2857
		$ds_arr[] = "	<ds>
2858
				<name> inpass6 </name>
2859
				<type> COUNTER </type>
2860
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2861
				<min> 0.0000000000e+00 </min>
2862
				<max> 1.2500000000e+08 </max>
2863

    
2864
				<!-- PDP Status -->
2865
				<last_ds> 0 </last_ds>
2866
				<value> NaN </value>
2867
				<unknown_sec> 3 </unknown_sec>
2868
			</ds>
2869
			";
2870
		$ds_arr[] = "	<ds>
2871
				<name> outpass6 </name>
2872
				<type> COUNTER </type>
2873
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2874
				<min> 0.0000000000e+00 </min>
2875
				<max> 1.2500000000e+08 </max>
2876

    
2877
				<!-- PDP Status -->
2878
				<last_ds> 0 </last_ds>
2879
				<value> NaN </value>
2880
				<unknown_sec> 3 </unknown_sec>
2881
			</ds>
2882
			";
2883
		$ds_arr[] = "	<ds>
2884
				<name> inblock6 </name>
2885
				<type> COUNTER </type>
2886
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2887
				<min> 0.0000000000e+00 </min>
2888
				<max> 1.2500000000e+08 </max>
2889

    
2890
				<!-- PDP Status -->
2891
				<last_ds> 0 </last_ds>
2892
				<value> NaN </value>
2893
				<unknown_sec> 3 </unknown_sec>
2894
			</ds>
2895
			";
2896
		$ds_arr[] = "	<ds>
2897
				<name> outblock6 </name>
2898
				<type> COUNTER </type>
2899
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2900
				<min> 0.0000000000e+00 </min>
2901
				<max> 1.2500000000e+08 </max>
2902

    
2903
				<!-- PDP Status -->
2904
				<last_ds> 0 </last_ds>
2905
				<value> NaN </value>
2906
				<unknown_sec> 3 </unknown_sec>
2907
			</ds>
2908
			";
2909

    
2910
		$cdp_search = "<\/cdp_prep>";
2911
		$cdp_replace = "</cdp_prep>";
2912
		$cdp_arr = array();
2913
		$cdp_arr[] = "			<ds>
2914
					<primary_value> NaN </primary_value>
2915
					<secondary_value> 0.0000000000e+00 </secondary_value>
2916
					<value> NaN </value>
2917
					<unknown_datapoints> 0 </unknown_datapoints>
2918
					</ds>
2919
		";
2920
		$cdp_arr[] = "			<ds>
2921
					<primary_value> NaN </primary_value>
2922
					<secondary_value> 0.0000000000e+00 </secondary_value>
2923
					<value> NaN </value>
2924
					<unknown_datapoints> 0 </unknown_datapoints>
2925
					</ds>
2926
		";
2927
		$cdp_arr[] = "			<ds>
2928
					<primary_value> NaN </primary_value>
2929
					<secondary_value> 0.0000000000e+00 </secondary_value>
2930
					<value> NaN </value>
2931
					<unknown_datapoints> 0 </unknown_datapoints>
2932
					</ds>
2933
		";
2934
		$cdp_arr[] = "			<ds>
2935
					<primary_value> NaN </primary_value>
2936
					<secondary_value> 0.0000000000e+00 </secondary_value>
2937
					<value> NaN </value>
2938
					<unknown_datapoints> 0 </unknown_datapoints>
2939
					</ds>
2940
		";
2941

    
2942
		$value_search = "<\/row>";
2943
		$value_replace = "</row>";
2944
		$value = "<v> NaN </v>";
2945

    
2946
		$xml = file_get_contents("{$g['tmp_path']}/{$xmldump}");
2947
		foreach ($ds_arr as $ds) {
2948
			$xml = preg_replace("/$ds_search/s", "$ds{$ds_search}", $xml);
2949
		}
2950
		foreach ($cdp_arr as $cdp) {
2951
			$xml = preg_replace("/$cdp_search/s", "$cdp{$cdp_replace}", $xml);
2952
		}
2953
		foreach ($ds_arr as $ds) {
2954
			$xml = preg_replace("/$value_search/s", "$value{$value_replace}", $xml);
2955
		}
2956

    
2957
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", $xml);
2958
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
2959
		unset($xml);
2960
		# Default /tmp tmpfs is ~40mb, do not leave temp files around
2961
		unlink_if_exists("{$g['tmp_path']}/{$xmldump}");
2962
		unlink_if_exists("{$g['tmp_path']}/{$xmldumpnew}");
2963
	}
2964
	if (!platform_booting()) {
2965
		enable_rrd_graphing();
2966
	}
2967
	/* Let's save the RRD graphs after we run enable RRD graphing */
2968
	/* The function will restore the rrd.tgz so we will save it after */
2969
	exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
2970
	if (platform_booting()) {
2971
		echo "Updating configuration...";
2972
	}
2973
	foreach ($config['filter']['rule'] as & $rule) {
2974
		if (isset($rule['protocol']) && !empty($rule['protocol'])) {
2975
			$rule['protocol'] = strtolower($rule['protocol']);
2976
		}
2977
	}
2978
	unset($rule);
2979
}
2980

    
2981
function upgrade_081_to_082() {
2982
	/* don't enable the allow IPv6 toggle */
2983
}
2984

    
2985
function upgrade_082_to_083() {
2986
	global $config;
2987

    
2988
	/* Upgrade captiveportal config */
2989
	if (!empty($config['captiveportal'])) {
2990
		$tmpcp = $config['captiveportal'];
2991
		$config['captiveportal'] = array();
2992
		$config['captiveportal']['cpzone'] = array();
2993
		$config['captiveportal']['cpzone'] = $tmpcp;
2994
		$config['captiveportal']['cpzone']['zoneid'] = 8000;
2995
		$config['captiveportal']['cpzone']['zone'] = "cpzone";
2996
		if ($config['captiveportal']['cpzone']['auth_method'] == "radius") {
2997
			$config['captiveportal']['cpzone']['radius_protocol'] = "PAP";
2998
		}
2999
	}
3000
	if (!empty($config['voucher'])) {
3001
		$tmpcp = $config['voucher'];
3002
		$config['voucher'] = array();
3003
		$config['voucher']['cpzone'] = array();
3004
		$config['voucher']['cpzone'] = $tmpcp;
3005
	}
3006
}
3007

    
3008
function upgrade_083_to_084() {
3009
	global $config;
3010
	if (!isset($config['hasync'])) {
3011
		if (!empty($config['installedpackages']) &&
3012
		    !empty($config['installedpackages']['carpsettings']) &&
3013
		    !empty($config['installedpackages']['carpsettings']['config'])) {
3014
			$config['hasync'] = $config['installedpackages']['carpsettings']['config'][0];
3015
			unset($config['installedpackages']['carpsettings']);
3016
		}
3017
		if (empty($config['installedpackages']['carpsettings']) && isset($config['installedpackages']['carpsettings'])) {
3018
			unset($config['installedpackages']['carpsettings']);
3019
		}
3020
		if (empty($config['installedpackages']) && isset($config['installedpackages'])) {
3021
			unset($config['installedpackages']);
3022
		}
3023
	}
3024
}
3025

    
3026
function upgrade_084_to_085() {
3027
	global $config;
3028

    
3029
	$gateway_group_arr = array();
3030
	$gateways = return_gateways_array();
3031
	$oldnames = array();
3032
	/* setup translation array */
3033
	foreach ($gateways as $name => $gw) {
3034
		if (isset($gw['dynamic'])) {
3035
			$oldname = strtoupper($config['interfaces'][$gw['friendlyiface']]['descr']);
3036
			$oldnames[$oldname] = $name;
3037
		} else {
3038
			$oldnames[$name] = $name;
3039
		}
3040
	}
3041

    
3042
	/* process the old array */
3043
	if (is_array($config['gateways']['gateway_group'])) {
3044
		$group_array_new = array();
3045
		foreach ($config['gateways']['gateway_group'] as $name => $group) {
3046
			if (is_array($group['item'])) {
3047
				$newlist = array();
3048
				foreach ($group['item'] as $entry) {
3049
					$elements = explode("|", $entry);
3050
					if ($oldnames[$elements[0]] <> "") {
3051
						$newlist[] = "{$oldnames[$elements[0]]}|{$elements[1]}";
3052
					} else {
3053
						$newlist[] = "{$elements[0]}|{$elements[1]}";
3054
					}
3055
				}
3056
				$group['item'] = $newlist;
3057
				$group_array_new[$name] = $group;
3058
			}
3059
		}
3060
		$config['gateways']['gateway_group'] = $group_array_new;
3061
	}
3062
	/* rename old Quality RRD files in the process */
3063
	$rrddbpath = "/var/db/rrd";
3064
	foreach ($oldnames as $old => $new) {
3065
		if (is_readable("{$rrddbpath}/{$old}-quality.rrd")) {
3066
			@rename("{$rrddbpath}/{$old}-quality.rrd", "{$rrddbpath}/{$new}-quality.rrd");
3067
		}
3068
	}
3069
	unset($gateways, $oldnames, $gateway_group_arr);
3070
}
3071

    
3072
function upgrade_085_to_086() {
3073
	global $config, $g;
3074

    
3075
	/* XXX: Gross hacks in sight */
3076
	if (is_array($config['virtualip']['vip'])) {
3077
		$vipchg = array();
3078
		foreach ($config['virtualip']['vip'] as $vip) {
3079
			if ($vip['mode'] != "carp") {
3080
				continue;
3081
			}
3082
			$config = array_replace_values_recursive(
3083
				$config,
3084
				'^vip' . $vip['vhid'] . '$',
3085
				"{$vip['interface']}_vip{$vip['vhid']}"
3086
			);
3087
		}
3088
	}
3089
}
3090

    
3091
function upgrade_086_to_087() {
3092
	global $config, $dummynet_pipe_list;
3093

    
3094
	if (!is_array($config['dnshaper']) || !is_array($config['dnshaper']['queue'])) {
3095
		return;
3096
	}
3097

    
3098
	$dnqueue_number = 1;
3099
	$dnpipe_number = 1;
3100

    
3101
	foreach ($config['dnshaper']['queue'] as $idx => $dnpipe) {
3102
		$config['dnshaper']['queue'][$idx]['number'] = $dnpipe_number;
3103
		$dnpipe_number++;
3104
		if (is_array($dnpipe['queue'])) {
3105
			foreach ($dnpipe['queue'] as $qidx => $dnqueue) {
3106
				$config['dnshaper']['queue'][$idx]['queue'][$qidx]['number'] = $dnqueue_number;
3107
				$dnqueue_number++;
3108
			}
3109
		}
3110
	}
3111

    
3112
	unset($dnqueue_number, $dnpipe_number, $qidx, $idx, $dnpipe, $dnqueue);
3113

    
3114
	if (!is_array($config['filter']) || !is_array($config['filter']['rule'])) {
3115
		return;
3116
	}
3117

    
3118
	require_once("shaper.inc");
3119
	read_dummynet_config();
3120

    
3121
	$dn_list = array();
3122
	if (is_array($dummynet_pipe_list)) {
3123
		foreach ($dummynet_pipe_list as $dn) {
3124
			$tmplist =& $dn->get_queue_list();
3125
			foreach ($tmplist as $qname => $link) {
3126
				$dn_list[$link] = $qname;
3127
			}
3128
		}
3129
		unset($dummynet_pipe_list);
3130
	}
3131

    
3132
	foreach ($config['filter']['rule'] as $idx => $rule) {
3133
		if (!empty($rule['dnpipe'])) {
3134
			if (!empty($dn_list[$rule['dnpipe']])) {
3135
				$config['filter']['rule'][$idx]['dnpipe'] = $dn_list[$rule['dnpipe']];
3136
			}
3137
		}
3138
		if (!empty($rule['pdnpipe'])) {
3139
			if (!empty($dn_list[$rule['pdnpipe']])) {
3140
				$config['filter']['rule'][$idx]['pdnpipe'] = $dn_list[$rule['pdnpipe']];
3141
			}
3142
		}
3143
	}
3144
}
3145
function upgrade_087_to_088() {
3146
	global $config;
3147
	if (isset($config['system']['glxsb_enable'])) {
3148
		unset($config['system']['glxsb_enable']);
3149
		$config['system']['crypto_hardware'] = "glxsb";
3150
	}
3151
}
3152

    
3153
function upgrade_088_to_089() {
3154
	global $config;
3155
	if (!is_array($config['ca'])) {
3156
		$config['ca'] = array();
3157
	}
3158
	if (!is_array($config['cert'])) {
3159
		$config['cert'] = array();
3160
	}
3161

    
3162
	/* migrate captive portal ssl to certificate manager */
3163
	if (is_array($config['captiveportal'])) {
3164
		foreach ($config['captiveportal'] as $id => &$setting) {
3165
			if (isset($setting['httpslogin'])) {
3166
				/* create cert entry */
3167
				$cert = array();
3168
				$cert['refid'] = uniqid();
3169
				$cert['descr'] = "Captive Portal Cert - {$setting['zone']}";
3170
				$cert['crt'] = $setting['certificate'];
3171
				$cert['prv'] = $setting['private-key'];
3172

    
3173
				if (!empty($setting['cacertificate'])) {
3174
					/* create ca entry */
3175
					$ca = array();
3176
					$ca['refid'] = uniqid();
3177
					$ca['descr'] = "Captive Portal CA - {$setting['zone']}";
3178
					$ca['crt'] = $setting['cacertificate'];
3179
					$config['ca'][] = $ca;
3180

    
3181
					/* add ca reference to certificate */
3182
					$cert['caref'] = $ca['refid'];
3183
				}
3184

    
3185
				$config['cert'][] = $cert;
3186

    
3187
				/* create cert reference */
3188
				$setting['certref'] = $cert['refid'];
3189

    
3190
				unset($setting['certificate']);
3191
				unset($setting['private-key']);
3192
				unset($setting['cacertificate']);
3193

    
3194
			}
3195
		}
3196
	}
3197
}
3198

    
3199
function upgrade_089_to_090() {
3200
	global $config;
3201
	if (is_array($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server'])) {
3202
		$vs_a = &$config['load_balancer']['virtual_server'];
3203
		for ($i = 0; isset($vs_a[$i]); $i++) {
3204
			if (is_array($vs_a[$i]['pool'])) {
3205
				$vs_a[$i]['poolname'] = $vs_a[$i]['pool'][0];
3206
				unset($vs_a[$i]['pool']);
3207
			} elseif (!empty($vs_a[$i]['pool'])) {
3208
				$vs_a[$i]['poolname'] = $vs_a[$i]['pool'];
3209
				unset($vs_a[$i]['pool']);
3210
			}
3211
		}
3212
	}
3213
}
3214

    
3215
function upgrade_090_to_091() {
3216
	global $config;
3217

    
3218
	if (is_array($config['dnshaper']) && is_array($config['dnshaper']['queue'])) {
3219
		foreach ($config['dnshaper']['queue'] as $idx => $dnqueue) {
3220
			if (!empty($dnqueue['bandwidth'])) {
3221
				$bw = array();
3222
				$bw['bw'] = $dnqueue['bandwidth'];
3223
				$bw['bwscale'] = $dnqueue['bandwidthtype'];
3224
				$bw['bwsched'] = "none";
3225
				$config['dnshaper']['queue'][$idx]['bandwidth'] = array();
3226
				$config['dnshaper']['queue'][$idx]['bandwidth']['item'] = array();
3227
				$config['dnshaper']['queue'][$idx]['bandwidth']['item'][] = $bw;
3228
			}
3229
		}
3230
	}
3231
}
3232

    
3233
function upgrade_091_to_092() {
3234
	global $config;
3235

    
3236
	if (is_array($config['nat']['advancedoutbound']) && is_array($config['nat']['advancedoutbound']['rule'])) {
3237
		$nat_rules = &$config['nat']['advancedoutbound']['rule'];
3238
		for ($i = 0; isset($nat_rules[$i]); $i++) {
3239
			if (empty($nat_rules[$i]['interface'])) {
3240
				$nat_rules[$i]['interface'] = 'wan';
3241
			}
3242
		}
3243
	}
3244
}
3245

    
3246
function upgrade_092_to_093() {
3247
	global $g;
3248

    
3249
	$suffixes = array("concurrent", "loggedin");
3250

    
3251
	foreach ($suffixes as $suffix) {
3252
		if (file_exists("{$g['vardb_path']}/rrd/captiveportal-{$suffix}.rrd")) {
3253
			rename("{$g['vardb_path']}/rrd/captiveportal-{$suffix}.rrd",
3254
				"{$g['vardb_path']}/rrd/captiveportal-cpZone-{$suffix}.rrd");
3255
		}
3256
	}
3257

    
3258
	if (!platform_booting()) {
3259
		enable_rrd_graphing();
3260
	}
3261
}
3262

    
3263
function upgrade_093_to_094() {
3264
	global $config;
3265

    
3266
	if (isset($config['system']['powerd_mode'])) {
3267
		$config['system']['powerd_ac_mode'] = $config['system']['powerd_mode'];
3268
		$config['system']['powerd_battery_mode'] = $config['system']['powerd_mode'];
3269
		unset($config['system']['powerd_mode']);
3270
	}
3271
}
3272

    
3273
function upgrade_094_to_095() {
3274
	global $config;
3275

    
3276
	if (!isset($config['interfaces']) || !is_array($config['interfaces'])) {
3277
		return;
3278
	}
3279

    
3280
	foreach ($config['interfaces'] as $iface => $cfg) {
3281
		if (isset($cfg['ipaddrv6']) && ($cfg['ipaddrv6'] == "track6")) {
3282
			if (!isset($cfg['track6-prefix-id']) || ($cfg['track6-prefix-id'] == "")) {
3283
				$config['interfaces'][$iface]['track6-prefix-id'] = 0;
3284
			}
3285
		}
3286
	}
3287
}
3288

    
3289
function upgrade_095_to_096() {
3290
	global $config, $g;
3291

    
3292
	$names = array("inpass", "outpass", "inblock", "outblock",
3293
		"inpass6", "outpass6", "inblock6", "outblock6");
3294
	$rrddbpath = "/var/db/rrd";
3295
	$rrdtool = "/usr/local/bin/rrdtool";
3296

    
3297
	if ($g['platform'] != $g['product_name']) {
3298
		/* restore the databases, if we have one */
3299
		if (restore_rrd()) {
3300
			/* Make sure to move the rrd backup out of the way. We will make a new one after converting. */
3301
			@rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup/rrd.tgz");
3302
		}
3303
	}
3304

    
3305
	/* Assume 2*10GigE for now */
3306
	$stream = 2500000000;
3307

    
3308
	/* build a list of traffic and packets databases */
3309
	$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
3310
	rsort($databases);
3311
	foreach ($databases as $database) {
3312
		if (platform_booting()) {
3313
			echo "Update RRD database {$database}.\n";
3314
		}
3315

    
3316
		$cmd = "{$rrdtool} tune {$rrddbpath}/{$database}";
3317
		foreach ($names as $name) {
3318
			$cmd .= " -a {$name}:{$stream}";
3319
		}
3320
		mwexec("{$cmd} 2>&1");
3321

    
3322
	}
3323
	if (!platform_booting()) {
3324
		enable_rrd_graphing();
3325
	}
3326
	/* Let's save the RRD graphs after we run enable RRD graphing */
3327
	/* The function will restore the rrd.tgz so we will save it after */
3328
	exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
3329
}
3330

    
3331
function upgrade_096_to_097() {
3332
	global $config, $g;
3333
	/* If the user had disabled default block rule logging before, then bogon/private network logging was already off, so respect their choice. */
3334
	if (isset($config['syslog']['nologdefaultblock'])) {
3335
		$config['syslog']['nologbogons'] = true;
3336
		$config['syslog']['nologprivatenets'] = true;
3337
	}
3338
}
3339

    
3340
function upgrade_097_to_098() {
3341
	global $config, $g;
3342
	/* Disable kill_states by default */
3343
	$config['system']['kill_states'] = true;
3344
}
3345

    
3346
function upgrade_098_to_099() {
3347
	global $config;
3348

    
3349
	if (empty($config['dhcpd']) || !is_array($config['dhcpd'])) {
3350
		return;
3351
	}
3352

    
3353
	foreach ($config['dhcpd'] as & $dhcpifconf) {
3354
		if (isset($dhcpifconf['next-server'])) {
3355
			$dhcpifconf['nextserver'] = $dhcpifconf['next-server'];
3356
			unset($dhcpifconf['next-server']);
3357
		}
3358
	}
3359
}
3360

    
3361
function upgrade_099_to_100() {
3362
	require_once("/etc/inc/services.inc");
3363
	install_cron_job("/usr/bin/nice -n20 newsyslog", false);
3364
}
3365

    
3366
function upgrade_100_to_101() {
3367
	global $config, $g;
3368

    
3369
	if (!is_array($config['voucher'])) {
3370
		return;
3371
	}
3372

    
3373
	foreach ($config['voucher'] as $cpzone => $cp) {
3374
		if (!is_array($cp['roll'])) {
3375
			continue;
3376
		}
3377
		foreach ($cp['roll'] as $ridx => $rcfg) {
3378
			if (!empty($rcfg['comment'])) {
3379
				$config['voucher'][$cpzone]['roll'][$ridx]['descr'] = $rcfg['comment'];
3380
			}
3381
		}
3382
	}
3383
}
3384

    
3385
function upgrade_101_to_102() {
3386
	global $config, $g;
3387

    
3388
	if (is_array($config['captiveportal'])) {
3389
		foreach ($config['captiveportal'] as $cpzone => $cp) {
3390
			if (!is_array($cp['passthrumac'])) {
3391
				continue;
3392
			}
3393

    
3394
			foreach ($cp['passthrumac'] as $idx => $passthrumac) {
3395
				$config['captiveportal'][$cpzone]['passthrumac'][$idx]['action'] = 'pass';
3396
			}
3397
		}
3398
	}
3399

    
3400
	/* Convert OpenVPN Compression option to the new style */
3401
	// Nothing to do if there is no OpenVPN tag
3402
	if (isset($config['openvpn']) && is_array($config['openvpn'])) {
3403
		if (is_array($config['openvpn']['openvpn-server'])) {
3404
			foreach ($config['openvpn']['openvpn-server'] as &$vpn) {
3405
				if (!empty($vpn['compression'])) {
3406
					$vpn['compression'] = "adaptive";
3407
				}
3408
			}
3409
		}
3410
		if (is_array($config['openvpn']['openvpn-client'])) {
3411
			foreach ($config['openvpn']['openvpn-client'] as &$vpn) {
3412
				if (!empty($vpn['compression'])) {
3413
					$vpn['compression'] = "adaptive";
3414
				}
3415
			}
3416
		}
3417
	}
3418
}
3419

    
3420
function upgrade_102_to_103() {
3421
	global $config;
3422

    
3423
	if (isset($config['nat']['advancedoutbound']['enable'])) {
3424
		$config['nat']['advancedoutbound']['mode'] = "advanced";
3425
		unset($config['nat']['advancedoutbound']['enable']);
3426
	} else {
3427
		$config['nat']['advancedoutbound']['mode'] = "automatic";
3428
	}
3429

    
3430
	$config['nat']['outbound'] = $config['nat']['advancedoutbound'];
3431

    
3432
	if (isset($config['nat']['ipsecpassthru'])) {
3433
		unset($config['nat']['ipsecpassthru']);
3434
	}
3435
	if (isset($config['nat']['advancedoutbound'])) {
3436
		unset($config['nat']['advancedoutbound']);
3437
	}
3438
}
3439

    
3440
function upgrade_103_to_104() {
3441
	global $config;
3442

    
3443
	$changed_privs = array(
3444
		"page-diag-system-activity" => "page-diagnostics-system-activity",
3445
		"page-interfacess-groups" => "page-interfaces-groups",
3446
		"page-interfacess-lagg" => "page-interfaces-lagg",
3447
		"page-interfacess-qinq" => "page-interfaces-qinq"
3448
	);
3449

    
3450
	/* update user privileges */
3451
	foreach ($config['system']['user'] as & $user) {
3452
		if (!is_array($user['priv'])) {
3453
			continue;
3454
		}
3455
		foreach ($user['priv'] as & $priv) {
3456
			if (array_key_exists($priv, $changed_privs)) {
3457
				$priv = $changed_privs[$priv];
3458
			}
3459
		}
3460
	}
3461

    
3462
	/* update group privileges */
3463
	foreach ($config['system']['group'] as & $group) {
3464
		if (!is_array($group['priv'])) {
3465
			continue;
3466
		}
3467
		foreach ($group['priv'] as & $priv) {
3468
			if (array_key_exists($priv, $changed_privs)) {
3469
				$priv = $changed_privs[$priv];
3470
			}
3471
		}
3472
	}
3473

    
3474
	/* sync all local account information */
3475
	local_sync_accounts();
3476
}
3477

    
3478
function upgrade_104_to_105() {
3479
	global $config;
3480

    
3481
	if (is_array($config['captiveportal'])) {
3482
		$zoneid = 2;
3483
		foreach ($config['captiveportal'] as $cpzone => $cpcfg) {
3484
			if (empty($cpcfg['zoneid'])) {
3485
				$config['captiveportal'][$cpzone]['zoneid'] = $zoneid;
3486
				$zoneid += 2;
3487
			} else if ($cpcfg['zoneid'] > 4000) {
3488
				$config['captiveportal'][$cpzone]['zoneid'] = $zoneid;
3489
				$zoneid += 2;
3490
			}
3491
		}
3492
	}
3493
}
3494

    
3495
function upgrade_105_to_106() {
3496

    
3497
	/* NOTE: This entry can be reused for something else since the upgrade code was reverted */
3498
}
3499

    
3500
function upgrade_106_to_107() {
3501
	global $config;
3502

    
3503
	if (is_array($config['filter']) && is_array($config['filter']['rule'])) {
3504
		$tracker = (int)microtime(true);
3505
		foreach ($config['filter']['rule'] as $ridx => $rule) {
3506
			if (empty($rule['tracker'])) {
3507
				$config['filter']['rule'][$ridx]['tracker'] = $tracker;
3508
				$tracker++;
3509
			}
3510
		}
3511
		unset($tracker, $ridx);
3512
	}
3513
	if (is_array($config['nat']) && is_array($config['nat']['rule'])) {
3514
		$tracker = (int)microtime(true);
3515
		foreach ($config['nat']['rule'] as $ridx => $rule) {
3516
			if (empty($rule['tracker'])) {
3517
				$config['nat']['rule'][$ridx]['tracker'] = $tracker;
3518
				$tracker++;
3519
			}
3520
		}
3521
		unset($tracker, $ridx);
3522
	}
3523
}
3524

    
3525
function upgrade_107_to_108() {
3526
	global $config;
3527

    
3528
	if (isset($config['system']['webgui']['noautocomplete'])) {
3529
		unset($config['system']['webgui']['noautocomplete']);
3530
	} else {
3531
		$config['system']['webgui']['loginautocomplete'] = true;
3532
	}
3533
}
3534

    
3535
function upgrade_108_to_109() {
3536
	global $config;
3537

    
3538
	if (!isset($config['filter']['rule']) || !is_array($config['filter']['rule'])) {
3539
		return;
3540
	}
3541

    
3542
	foreach ($config['filter']['rule'] as &$rule) {
3543
		if (!isset($rule['dscp']) || empty($rule['dscp'])) {
3544
			continue;
3545
		}
3546

    
3547
		$pos = strpos($rule['dscp'], ' ');
3548
		if ($pos !== false) {
3549
			$rule['dscp'] = substr($rule['dscp'], 0, $pos);
3550
		}
3551
		unset($pos);
3552
	}
3553
}
3554

    
3555
function upgrade_109_to_110() {
3556
	global $config;
3557

    
3558
	if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2'])) {
3559
		return;
3560
	}
3561

    
3562
	foreach ($config['ipsec']['phase2'] as &$rule) {
3563
		if (!empty($rule['uniqid'])) {
3564
			continue;
3565
		}
3566

    
3567
		$rule['uniqid'] = uniqid();
3568
	}
3569
}
3570

    
3571
function upgrade_110_to_111() {
3572
	global $config;
3573

    
3574
	/* Make sure unbound user exist */
3575
	mwexec('/usr/sbin/pw groupadd -n unbound -g 59', true);
3576
	mwexec('/usr/sbin/pw useradd -n unbound -c "Unbound DNS Resolver" -d /var/unbound -s /usr/sbin/nologin -u 59 -g 59', true);
3577

    
3578
	/* cleanup old unbound package stuffs */
3579
	unlink_if_exists("/usr/local/pkg/unbound.xml");
3580
	unlink_if_exists("/usr/local/pkg/unbound.inc");
3581
	unlink_if_exists("/usr/local/pkg/unbound_advanced.xml");
3582
	unlink_if_exists("/usr/local/www/unbound_status.php");
3583
	unlink_if_exists("/usr/local/www/unbound_acls.php");
3584
	unlink_if_exists("/usr/local/bin/unbound_monitor.sh");
3585
	unlink_if_exists("/usr/local/etc/rc.d/unbound.sh");
3586

    
3587
	/* Remove old menu and service entries */
3588
	if (isset($config['installedpackages']['menu']) && is_array($config['installedpackages']['menu'])) {
3589
		foreach ($config['installedpackages']['menu'] as $idx => $menu) {
3590
			if ($menu['name'] != 'Unbound DNS') {
3591
				continue;
3592
			}
3593

    
3594
			unset($config['installedpackages']['menu'][$idx]);
3595
			break;
3596
		}
3597
	}
3598

    
3599
	if (isset($config['installedpackages']['service']) && is_array($config['installedpackages']['service'])) {
3600
		foreach ($config['installedpackages']['service'] as $idx => $service) {
3601
			if ($service['name'] != 'unbound') {
3602
				continue;
3603
			}
3604
			unset($config['installedpackages']['service'][$idx]);
3605
			break;
3606
		}
3607
	}
3608

    
3609
	if (!isset($config['installedpackages']['unbound']['config'][0])) {
3610
		return;
3611
	}
3612

    
3613
	$pkg = $config['installedpackages']['unbound']['config'][0];
3614

    
3615
	if (isset($config['installedpackages']['unboundadvanced']['config'][0])) {
3616
		$pkg = array_merge($pkg, $config['installedpackages']['unboundadvanced']['config'][0]);
3617
	}
3618

    
3619
	$new = array();
3620

    
3621
	/* deal first with boolean fields */
3622
	$fields = array(
3623
		"enable" => "enable",
3624
		"dnssec_status" => "dnssec",
3625
		"forwarding_mode" => "forwarding",
3626
		"regdhcp" => "regdhcp",
3627
		"regdhcpstatic" => "regdhcpstatic",
3628
		"txtsupport" => "txtsupport",
3629
		"hide_id" => "hideidentity",
3630
		"hide_version" => "hideversion",
3631
		"prefetch" => "prefetch",
3632
		"prefetch_key" => "prefetchkey",
3633
		"harden_glue" => "hardenglue",
3634
		"harden_dnssec_stripped" => "dnssec_stripped");
3635

    
3636
	foreach ($fields as $oldk => $newk) {
3637
		if (isset($pkg[$oldk])) {
3638
			if ($pkg[$oldk] == 'on') {
3639
				$new[$newk] = true;
3640
			}
3641
			unset($pkg[$oldk]);
3642
		}
3643
	}
3644

    
3645
	$fields = array(
3646
		"active_interface" => "network_interface",
3647
		"query_interface" => "outgoing_interface",
3648
		"unbound_verbosity" => "log_verbosity",
3649
		"msg_cache_size" => "msgcachesize",
3650
		"outgoing_num_tcp" => "outgoing_num_tcp",
3651
		"incoming_num_tcp" => "incoming_num_tcp",
3652
		"edns_buffer_size" => "edns_buffer_size",
3653
		"num_queries_per_thread" => "num_queries_per_thread",
3654
		"jostle_timeout" => "jostle_timeout",
3655
		"cache_max_ttl" => "cache_max_ttl",
3656
		"cache_min_ttl" => "cache_min_ttl",
3657
		"infra_host_ttl" => "infra_host_ttl",
3658
		"infra_cache_numhosts" => "infra_cache_numhosts",
3659
		"unwanted_reply_threshold" => "unwanted_reply_threshold",
3660
		"custom_options" => "custom_options");
3661

    
3662
	foreach ($fields as $oldk => $newk) {
3663
		if (isset($pkg[$oldk])) {
3664
			$new[$newk] = $pkg[$oldk];
3665
			unset($pkg[$oldk]);
3666
		}
3667
	}
3668

    
3669
	if (isset($new['custom_options']) && !empty($new['custom_options'])) {
3670
		$new['custom_options'] = str_replace("\r\n", "\n", $new['custom_options']);
3671
	}
3672

    
3673
	/* Following options were removed, bring them as custom_options */
3674
	if (isset($pkg['stats']) && $pkg['stats'] == "on") {
3675
		if (isset($pkg['stats_interval'])) {
3676
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "statistics-interval: {$pkg['stats_interval']}";
3677
		}
3678
		if (isset($pkg['cumulative_stats'])) {
3679
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "statistics-cumulative: {$pkg['cumulative_stats']}";
3680
		}
3681
		if (isset($pkg['extended_stats']) && $pkg['extended_stats'] == "on") {
3682
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "extended-statistics: yes";
3683
		} else {
3684
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "extended-statistics: no";
3685
		}
3686
	}
3687

    
3688
	$new['acls'] = array();
3689
	if (isset($config['installedpackages']['unboundacls']['config']) &&
3690
	    is_array($config['installedpackages']['unboundacls']['config'])) {
3691
		foreach ($config['installedpackages']['unboundacls']['config'] as $acl) {
3692
			$new['acls'][] = $acl;
3693
		}
3694
	}
3695

    
3696
	$config['unbound'] = $new;
3697

    
3698
	if (isset($config['installedpackages']['unbound'])) {
3699
		unset($config['installedpackages']['unbound']);
3700
	}
3701
	if (isset($config['installedpackages']['unboundadvanced'])) {
3702
		unset($config['installedpackages']['unboundadvanced']);
3703
	}
3704
	if (isset($config['installedpackages']['unboundacls'])) {
3705
		unset($config['installedpackages']['unboundacls']);
3706
	}
3707

    
3708
	unset($pkg, $new);
3709
}
3710

    
3711
function upgrade_111_to_112() {
3712
	global $config;
3713

    
3714
	$config['cron']['item'][] = array(
3715
		'minute' => '*/60',
3716
		'hour' => '*',
3717
		'mday' => '*',
3718
		'month' => '*',
3719
		'wday' => '*',
3720
		'who' => 'root',
3721
		'command' => '/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 webConfiguratorlockout'
3722
	);
3723
}
3724

    
3725
function upgrade_112_to_113() {
3726
	global $config;
3727

    
3728
	if (isset($config['notifications']['smtp']['ssl'])) {
3729
		if ($config['notifications']['smtp']['ssl'] == "checked") {
3730
			$config['notifications']['smtp']['ssl'] = true;
3731
		} else {
3732
			unset($config['notifications']['smtp']['ssl']);
3733
		}
3734
	}
3735

    
3736
	if (isset($config['notifications']['smtp']['tls'])) {
3737
		if ($config['notifications']['smtp']['tls'] == "checked") {
3738
			$config['notifications']['smtp']['tls'] = true;
3739
		} else {
3740
			unset($config['notifications']['smtp']['tls']);
3741
		}
3742
	}
3743
}
3744

    
3745
function upgrade_113_to_114() {
3746
	global $config;
3747

    
3748
	if (!isset($config['ipsec']['phase1']) ||
3749
	    !is_array($config['ipsec']['phase1'])) {
3750
		return;
3751
	}
3752

    
3753
	foreach ($config['ipsec']['phase1'] as &$ph1ent) {
3754
		if (!isset($ph1ent['iketype'])) {
3755
			$ph1ent['iketype'] = 'ikev1';
3756
		}
3757
	}
3758
}
3759

    
3760
function upgrade_114_to_115() {
3761
	global $config;
3762

    
3763
	if (isset($config['unbound']['custom_options'])) {
3764
		$config['unbound']['custom_options'] = base64_encode($config['unbound']['custom_options']);
3765
	}
3766
}
3767

    
3768
function upgrade_115_to_116() {
3769
	global $config;
3770

    
3771
	if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2'])) {
3772
		return;
3773
	}
3774

    
3775
	$keyid = 1;
3776
	foreach ($config['ipsec']['phase2'] as $idx => $ph2) {
3777
		$config['ipsec']['phase2'][$idx]['reqid'] = $keyid;
3778
		$keyid++;
3779
	}
3780
}
3781

    
3782
function upgrade_116_to_117() {
3783
	global $config;
3784

    
3785
	if (!isset($config['ipsec']['client']) ||
3786
	    !isset($config['ipsec']['client']['dns_split']) ||
3787
	    empty($config['ipsec']['client']['dns_split'])) {
3788
		return;
3789
	}
3790

    
3791
	$config['ipsec']['client']['dns_split'] =
3792
		preg_replace('/\s*,\s*/', ' ', trim($config['ipsec']['client']['dns_split']));
3793

    
3794
}
3795

    
3796
function upgrade_117_to_118() {
3797
	global $config;
3798

    
3799
	// Unset any old CA and Cert in the system section that might still be there from when upgrade_066_to_067 did not unset them.
3800
	if (isset($config['system']['ca'])) {
3801
		unset($config['system']['ca']);
3802
	}
3803
	if (isset($config['system']['cert'])) {
3804
		unset($config['system']['cert']);
3805
	}
3806

    
3807
	if (!isset($config['ipsec']['phase1'])) {
3808
		return;
3809
	}
3810

    
3811
	$a_phase1 =& $config['ipsec']['phase1'];
3812

    
3813
	foreach ($a_phase1 as &$ph1_entry) {
3814
		// update asn1dn strings from racoon's format to strongswan's
3815
		if (isset($ph1_entry['myid_type']) && $ph1_entry['myid_type'] == 'asn1dn') {
3816
			$ph1_entry['myid_data'] =
3817
			    preg_replace('/\/\s*emailAddress\s*=\s*/', ', E=', $ph1_entry['myid_data']);
3818
		}
3819
		if (isset($ph1_entry['peerid_type']) && $ph1_entry['peerid_type'] == 'asn1dn') {
3820
			$ph1_entry['peerid_data'] =
3821
			    preg_replace('/\/\s*emailAddress\s*=\s*/', ', E=', $ph1_entry['peerid_data']);
3822
		}
3823
	}
3824
}
3825

    
3826
function upgrade_118_to_119() {
3827
	global $config;
3828

    
3829
        if (!isset($config['ipsec']['phase1'])) {
3830
                return;
3831
        }
3832

    
3833
	// change peerid_type to 'any' for EAP types to retain previous behavior of omitting rightid
3834
	$a_phase1 =& $config['ipsec']['phase1'];
3835

    
3836
	foreach ($a_phase1 as &$ph1_entry) {
3837
		if (strstr($ph1_entry['authentication_method'], 'eap')) {
3838
			$ph1_entry['peerid_type'] = "any";
3839
		}
3840
	}
3841
}
3842

    
3843
function upgrade_119_to_120() {
3844
	global $config, $ipsec_log_cats;
3845

    
3846
	if (!is_array($config['ipsec'])) {
3847
		return;
3848
	}
3849

    
3850
	// add 1 to configured log levels as part of redmine #5340
3851
	foreach ($ipsec_log_cats as $lkey => $ldescr) {
3852
		if (isset($config['ipsec']["ipsec_{$lkey}"])) {
3853
			$config['ipsec']["ipsec_{$lkey}"] = $config['ipsec']["ipsec_{$lkey}"] + 1;
3854
		}
3855
	}
3856

    
3857
}
3858

    
3859

    
3860
function upgrade_120_to_121() {
3861
	global $config;
3862

    
3863
	if (!isset($config['installedpackages']['miniupnpd']['config'][0])) {
3864
		return;
3865
	}
3866

    
3867
	$miniupnpd =& $config['installedpackages']['miniupnpd']['config'][0];
3868

    
3869
	$miniupnpd['row'] = array();
3870

    
3871
	for ($i = 1; $i <= 4; $i++) {
3872
		if (isset($miniupnpd["permuser{$i}"]) && !empty($miniupnpd["permuser{$i}"])) {
3873
			$miniupnpd['row'][] = array('permuser' => $miniupnpd["permuser{$i}"]);
3874
		}
3875
		unset($miniupnpd["permuser{$i}"]);
3876
	}
3877
}
3878

    
3879
function upgrade_121_to_122() {
3880
	global $config;
3881
	foreach ($config['system']['user'] as &$user) {
3882
		if (isset($user['nt-hash'])) {
3883
			unset($user['nt-hash']);
3884
		}
3885
	}
3886
}
3887

    
3888
function upgrade_122_to_123() {
3889
	global $config;
3890

    
3891
	// PPTP server was removed
3892
	if (isset($config['pptpd'])) {
3893
		unset($config['pptpd']);
3894
	}
3895

    
3896
	// Cleanup firewall rules
3897
	if (isset($config['filter']['rule']) && is_array($config['filter']['rule'])) {
3898
		$rules =& $config['filter']['rule'];
3899
		$last_rule = count($rules) - 1;
3900
		// Process in reverse order to be able to unset items
3901
		for ($i = $last_rule; $i >= 0; $i--) {
3902
			if (isset($rules[$i]['interface']) && $rules[$i]['interface'] == 'pptp') {
3903
				unset($config['filter']['rule'][$i]);
3904
				continue;
3905
			}
3906
			if (isset($rules[$i]['source']['network']) && $rules[$i]['source']['network'] == 'pptp') {
3907
				unset($config['filter']['rule'][$i]);
3908
				continue;
3909
			}
3910
			if (isset($rules[$i]['destination']['network']) && $rules[$i]['destination']['network'] == 'pptp') {
3911
				unset($config['filter']['rule'][$i]);
3912
				continue;
3913
			}
3914
		}
3915
	}
3916

    
3917
	// Cleanup 1:1 NAT rules
3918
	if (isset($config['nat']['onetoone']) && is_array($config['nat']['onetoone'])) {
3919
		$onetoone =& $config['nat']['onetoone'];
3920
		$last_rule = count($onetoone) - 1;
3921
		// Process in reverse order to be able to unset items
3922
		for ($i = $last_rule; $i >= 0; $i--) {
3923
			if (isset($onetoone[$i]['interface']) && $onetoone[$i]['interface'] == 'pptp') {
3924
				unset($config['nat']['onetoone'][$i]);
3925
				continue;
3926
			}
3927
			if (isset($onetoone[$i]['source']['network']) && $onetoone[$i]['source']['network'] == 'pptp') {
3928
				unset($config['nat']['onetoone'][$i]);
3929
				continue;
3930
			}
3931
			if (isset($onetoone[$i]['destination']['network']) && $onetoone[$i]['destination']['network'] == 'pptp') {
3932
				unset($config['nat']['onetoone'][$i]);
3933
				continue;
3934
			}
3935
		}
3936
	}
3937

    
3938
	// Cleanup npt NAT rules
3939
	if (isset($config['nat']['npt']) && is_array($config['nat']['npt'])) {
3940
		$npt =& $config['nat']['npt'];
3941
		$last_rule = count($npt) - 1;
3942
		// Process in reverse order to be able to unset items
3943
		for ($i = $last_rule; $i >= 0; $i--) {
3944
			if (isset($npt[$i]['interface']) && $npt[$i]['interface'] == 'pptp') {
3945
				unset($config['nat']['npt'][$i]);
3946
				continue;
3947
			}
3948
		}
3949
	}
3950

    
3951
	// Cleanup Port-forward NAT rules
3952
	if (isset($config['nat']['rule']) && is_array($config['nat']['rule'])) {
3953
		$nat_rules =& $config['nat']['rule'];
3954
		$last_rule = count($nat_rules) - 1;
3955
		// Process in reverse order to be able to unset items
3956
		for ($i = $last_rule; $i >= 0; $i--) {
3957
			if (isset($nat_rules[$i]['interface']) && $nat_rules[$i]['interface'] == 'pptp') {
3958
				unset($config['nat']['rule'][$i]);
3959
				continue;
3960
			}
3961
			if (isset($nat_rules[$i]['source']['network']) && $nat_rules[$i]['source']['network'] == 'pptp') {
3962
				unset($config['nat']['rule'][$i]);
3963
				continue;
3964
			}
3965
			if (isset($nat_rules[$i]['destination']['network']) && $nat_rules[$i]['destination']['network'] == 'pptp') {
3966
				unset($config['nat']['rule'][$i]);
3967
				continue;
3968
			}
3969
		}
3970
	}
3971

    
3972
	// Cleanup Port-forward NAT rules
3973
	if (isset($config['nat']['outbound']['rule']) && is_array($config['nat']['outbound']['rule'])) {
3974
		$out_rules =& $config['nat']['outbound']['rule'];
3975
		$last_rule = count($out_rules) - 1;
3976
		// Process in reverse order to be able to unset items
3977
		for ($i = $last_rule; $i >= 0; $i--) {
3978
			if (isset($out_rules[$i]['interface']) && $out_rules[$i]['interface'] == 'pptp') {
3979
				unset($config['nat']['outbound']['rule'][$i]);
3980
				continue;
3981
			}
3982
		}
3983
	}
3984
}
3985

    
3986
function upgrade_123_to_124() {
3987
	if (isset($config['system']['altpkgrepo'])) {
3988
		unset($config['system']['altpkgrepo']);
3989
	}
3990

    
3991
	if (isset($config['theme'])) {
3992
		unset($config['theme']);
3993
	}
3994
}
3995

    
3996
function upgrade_124_to_125() {
3997
	global $config;
3998

    
3999
	/* Find interfaces with WEP configured. */
4000
	foreach ($config['interfaces'] as $ifname => $intf) {
4001
		if (!is_array($intf['wireless'])) {
4002
			continue;
4003
		}
4004

    
4005
		/* Generate a notice, disable interface, remove WEP settings */
4006
		if (isset($intf['wireless']['wep']['enable'])) {
4007
			if (!function_exists("file_notice")) {
4008
				require_once("notices.inc");
4009
			}
4010
			file_notice("WirelessSettings", "WEP is no longer supported. It will be disabled on the {$ifname} interface and the interface will be disabled. Please reconfigure the interface.");
4011
			unset($config['interfaces'][$ifname]['wireless']['wep']);
4012
			if (isset($intf['enable'])) {
4013
				unset($config['interfaces'][$ifname]['enable']);
4014
			}
4015
		}
4016
	}
4017
}
4018

    
4019
function upgrade_125_to_126() {
4020
	require_once("ipsec.inc");
4021
	global $config, $ipsec_log_cats, $ipsec_log_sevs;
4022

    
4023
	$def_loglevel = 1;
4024
	if (!is_array($config['ipsec'])) {
4025
		return;
4026
	}
4027

    
4028
	if (!isset($config['ipsec']['logging']) || !is_array($config['ipsec']['logging'])) {
4029
		$config['ipsec']['logging'] = array();
4030
	}
4031

    
4032
	/* subtract 2 from ipsec log levels. the value stored in the config.xml
4033
	 * will now match the strongswan level exactly.
4034
	 */
4035
	foreach(array_keys($ipsec_log_cats) as $cat) {
4036
		if (!isset($config['ipsec']["ipsec_{$cat}"])) {
4037
			$new_level = $def_loglevel;
4038
		} else {
4039
			$new_level = intval($config['ipsec']["ipsec_{$cat}"]) - 2;
4040
		}
4041

    
4042
		if (in_array($new_level, array_keys($ipsec_log_sevs))) {
4043
			$config['ipsec']['logging'][$cat] = $new_level;
4044
		} else {
4045
			$config['ipsec']['logging'][$cat] = $def_loglevel;
4046
		}
4047
		unset($config['ipsec']["ipsec_{$cat}"]);
4048
	}
4049
}
4050

    
4051
// prior to v2.3 <widgets><sequence> contains a list of widgets with display types:
4052
//		none, close, hide, & show
4053
// v2.3 & later uses:
4054
//		close & open
4055
// widgets not in use are simply not in the list
4056
function upgrade_126_to_127() {
4057
	global $config;
4058

    
4059
	if (!isset($config['widgets']['sequence'])) {
4060
		return;
4061
	}
4062

    
4063
	$cur_widgets = explode(',', trim($config['widgets']['sequence']));
4064
	$new_widgets = array();
4065

    
4066
	foreach ($cur_widgets as $widget) {
4067
		list($file, $col, $display) = explode(':', $widget);
4068

    
4069
		switch ($display) {
4070
			case 'hide':
4071
				$display = 'close';
4072
				break;
4073
			case 'show':
4074
				$display = 'open';
4075
				break;
4076
			case 'open':
4077
				break;
4078
			default:
4079
				continue 2;
4080
		}
4081

    
4082
		/* Remove '-container' from widget name */
4083
		$file = preg_replace('/-container$/', '', $file);
4084

    
4085
		$new_widgets[] = "{$file}:{$col}:{$display}";
4086
	}
4087

    
4088
	$config['widgets']['sequence'] = implode(',', $new_widgets);
4089

    
4090
}
4091

    
4092
function upgrade_127_to_128() {
4093
	global $config;
4094

    
4095
	// If bindip is not already specified then migrate the old SNMP bindlan flag to a bindip setting
4096
	if (isset($config['snmpd']['bindlan'])) {
4097
		if (!isset($config['snmpd']['bindip'])) {
4098
			$config['snmpd']['bindip'] = 'lan';
4099
		}
4100
		unset($config['snmpd']['bindlan']);
4101
	}
4102
}
4103

    
4104
function upgrade_128_to_129() {
4105
	global $config;
4106

    
4107
	/* net.inet.ip.fastforwarding does not exist in 2.3. */
4108
	if (!isset($config['sysctl']['item']) ||
4109
	    !is_array($config['sysctl']['item'])) {
4110
		return;
4111
	}
4112

    
4113
	foreach ($config['sysctl']['item'] as $idx => $sysctl) {
4114
		if ($sysctl['tunable'] == "net.inet.ip.fastforwarding") {
4115
			unset($config['sysctl']['item'][$idx]);
4116
		}
4117
	}
4118

    
4119
	/* IPSEC is always on in 2.3. */
4120
	if (isset($config['ipsec']['enable']))
4121
		unset($config['ipsec']['enable']);
4122
}
4123

    
4124
?>
(54-54/65)