Project

General

Profile

Download (55 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	Copyright (C) 2004-2006 Scott Ullrich
4
	All rights reserved.
5

    
6
	originally part of m0n0wall (http://m0n0.ch/wall)
7
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
1. Redistributions of source code must retain the above copyright notice,
14
	this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	notice, this list of conditions and the following disclaimer in the
18
	documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
	*/
31

    
32

    
33
/* Upgrade functions must be named:
34
*    upgrade_XXX_to_YYY
35
	* where XXX == previous version, zero padded, and YYY == next version, zero padded
36
	*/
37

    
38
function upgrade_010_to_011() {
39
	global $config;
40
	$opti = 1;
41
	$ifmap = array('lan' => 'lan', 'wan' => 'wan', 'pptp' => 'pptp');
42

    
43
	/* convert DMZ to optional, if necessary */
44
	if (isset($config['interfaces']['dmz'])) {
45

    
46
		$dmzcfg = &$config['interfaces']['dmz'];
47

    
48
		if ($dmzcfg['if']) {
49
			$config['interfaces']['opt' . $opti] = array();
50
			$optcfg = &$config['interfaces']['opt' . $opti];
51

    
52
			$optcfg['enable'] = $dmzcfg['enable'];
53
			$optcfg['descr'] = "DMZ";
54
			$optcfg['if'] = $dmzcfg['if'];
55
			$optcfg['ipaddr'] = $dmzcfg['ipaddr'];
56
			$optcfg['subnet'] = $dmzcfg['subnet'];
57

    
58
			$ifmap['dmz'] = "opt" . $opti;
59
			$opti++;
60
		}
61

    
62
		unset($config['interfaces']['dmz']);
63
	}
64

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

    
68
		if (!$config['interfaces']['wlan' . $i]['if']) {
69
			unset($config['interfaces']['wlan' . $i]);
70
			continue;
71
		}
72

    
73
		$wlancfg = &$config['interfaces']['wlan' . $i];
74
		$config['interfaces']['opt' . $opti] = array();
75
		$optcfg = &$config['interfaces']['opt' . $opti];
76

    
77
		$optcfg['enable'] = $wlancfg['enable'];
78
		$optcfg['descr'] = "WLAN" . $i;
79
		$optcfg['if'] = $wlancfg['if'];
80
		$optcfg['ipaddr'] = $wlancfg['ipaddr'];
81
		$optcfg['subnet'] = $wlancfg['subnet'];
82
		$optcfg['bridge'] = $wlancfg['bridge'];
83

    
84
		$optcfg['wireless'] = array();
85
		$optcfg['wireless']['mode'] = $wlancfg['mode'];
86
		$optcfg['wireless']['ssid'] = $wlancfg['ssid'];
87
		$optcfg['wireless']['channel'] = $wlancfg['channel'];
88
		$optcfg['wireless']['wep'] = $wlancfg['wep'];
89

    
90
		$ifmap['wlan' . $i] = "opt" . $opti;
91

    
92
		unset($config['interfaces']['wlan' . $i]);
93
		$opti++;
94
	}
95

    
96
	/* convert filter rules */
97
	$n = count($config['filter']['rule']);
98
	for ($i = 0; $i < $n; $i++) {
99

    
100
		$fr = &$config['filter']['rule'][$i];
101

    
102
		/* remap interface */
103
		if (array_key_exists($fr['interface'], $ifmap))
104
			$fr['interface'] = $ifmap[$fr['interface']];
105
		else {
106
			/* remove the rule */
107
			echo "\nWarning: filter rule removed " .
108
				"(interface '{$fr['interface']}' does not exist anymore).";
109
			unset($config['filter']['rule'][$i]);
110
			continue;
111
		}
112

    
113
		/* remap source network */
114
		if (isset($fr['source']['network'])) {
115
			if (array_key_exists($fr['source']['network'], $ifmap))
116
				$fr['source']['network'] = $ifmap[$fr['source']['network']];
117
			else {
118
				/* remove the rule */
119
				echo "\nWarning: filter rule removed " .
120
					"(source network '{$fr['source']['network']}' does not exist anymore).";
121
				unset($config['filter']['rule'][$i]);
122
				continue;
123
			}
124
		}
125

    
126
		/* remap destination network */
127
		if (isset($fr['destination']['network'])) {
128
			if (array_key_exists($fr['destination']['network'], $ifmap))
129
				$fr['destination']['network'] = $ifmap[$fr['destination']['network']];
130
			else {
131
				/* remove the rule */
132
				echo "\nWarning: filter rule removed " .
133
					"(destination network '{$fr['destination']['network']}' does not exist anymore).";
134
				unset($config['filter']['rule'][$i]);
135
				continue;
136
			}
137
		}
138
	}
139

    
140
	/* convert shaper rules */
141
	$n = count($config['pfqueueing']['rule']);
142
	if (is_array($config['pfqueueing']['rule']))
143
	for ($i = 0; $i < $n; $i++) {
144

    
145
		$fr = &$config['pfqueueing']['rule'][$i];
146

    
147
		/* remap interface */
148
		if (array_key_exists($fr['interface'], $ifmap))
149
			$fr['interface'] = $ifmap[$fr['interface']];
150
		else {
151
			/* remove the rule */
152
			echo "\nWarning: traffic shaper rule removed " .
153
				"(interface '{$fr['interface']}' does not exist anymore).";
154
			unset($config['pfqueueing']['rule'][$i]);
155
			continue;
156
		}
157

    
158
		/* remap source network */
159
		if (isset($fr['source']['network'])) {
160
			if (array_key_exists($fr['source']['network'], $ifmap))
161
				$fr['source']['network'] = $ifmap[$fr['source']['network']];
162
			else {
163
				/* remove the rule */
164
				echo "\nWarning: traffic shaper rule removed " .
165
					"(source network '{$fr['source']['network']}' does not exist anymore).";
166
				unset($config['pfqueueing']['rule'][$i]);
167
				continue;
168
			}
169
		}
170

    
171
		/* remap destination network */
172
		if (isset($fr['destination']['network'])) {
173
			if (array_key_exists($fr['destination']['network'], $ifmap))
174
				$fr['destination']['network'] = $ifmap[$fr['destination']['network']];
175
			else {
176
				/* remove the rule */
177
				echo "\nWarning: traffic shaper rule removed " .
178
					"(destination network '{$fr['destination']['network']}' does not exist anymore).";
179
				unset($config['pfqueueing']['rule'][$i]);
180
				continue;
181
			}
182
		}
183
	}
184
}
185

    
186

    
187
function upgrade_011_to_012() {
188
	global $config;
189
	/* move LAN DHCP server config */
190
	$tmp = $config['dhcpd'];
191
	$config['dhcpd'] = array();
192
	$config['dhcpd']['lan'] = $tmp;
193

    
194
	/* encrypt password */
195
	$config['system']['password'] = crypt($config['system']['password']);
196
}
197

    
198

    
199
function upgrade_012_to_013() {
200
	global $config;
201
	/* convert advanced outbound NAT config */
202
	for ($i = 0; isset($config['nat']['advancedoutbound']['rule'][$i]); $i++) {
203
		$curent = &$config['nat']['advancedoutbound']['rule'][$i];
204
		$src = $curent['source'];
205
		$curent['source'] = array();
206
		$curent['source']['network'] = $src;
207
		$curent['destination'] = array();
208
		$curent['destination']['any'] = true;
209
	}
210

    
211
	/* add an explicit type="pass" to all filter rules to make things consistent */
212
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++) {
213
		$config['filter']['rule'][$i]['type'] = "pass";
214
	}
215
}
216

    
217

    
218
function upgrade_013_to_014() {
219
	global $config;
220
	/* convert shaper rules (make pipes) */
221
	if (is_array($config['pfqueueing']['rule'])) {
222
		$config['pfqueueing']['pipe'] = array();
223

    
224
		for ($i = 0; isset($config['pfqueueing']['rule'][$i]); $i++) {
225
			$curent = &$config['pfqueueing']['rule'][$i];
226

    
227
			/* make new pipe and associate with this rule */
228
			$newpipe = array();
229
			$newpipe['descr'] = $curent['descr'];
230
			$newpipe['bandwidth'] = $curent['bandwidth'];
231
			$newpipe['delay'] = $curent['delay'];
232
			$newpipe['mask'] = $curent['mask'];
233
			$config['pfqueueing']['pipe'][$i] = $newpipe;
234

    
235
			$curent['targetpipe'] = $i;
236

    
237
			unset($curent['bandwidth']);
238
			unset($curent['delay']);
239
			unset($curent['mask']);
240
		}
241
	}
242
}
243

    
244

    
245
function upgrade_014_to_015() {
246
	global $config;
247
	/* Default route moved */
248
	if (isset($config['interfaces']['wan']['gateway']))
249
		if ($config['interfaces']['wan']['gateway'] <> "")
250
		$config['interfaces']['wan']['gateway'] = $config['interfaces']['wan']['gateway'];
251
	unset($config['interfaces']['wan']['gateway']);
252

    
253
	/* Queues are no longer interface specific */
254
	if (isset($config['interfaces']['lan']['schedulertype']))
255
		unset($config['interfaces']['lan']['schedulertype']);
256
	if (isset($config['interfaces']['wan']['schedulertype']))
257
		unset($config['interfaces']['wan']['schedulertype']);
258

    
259
	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
260
		if(isset($config['interfaces']['opt' . $i]['schedulertype']))
261
			unset($config['interfaces']['opt' . $i]['schedulertype']);
262
	}
263
}
264

    
265

    
266
function upgrade_015_to_016() {
267
	global $config;
268
	/* Alternate firmware URL moved */
269
	if (isset($config['system']['firmwareurl']) && isset($config['system']['firmwarename'])) { // Only convert if *both* are defined.
270
		$config['system']['alt_firmware_url'] = array();
271
		$config['system']['alt_firmware_url']['enabled'] = "";
272
		$config['system']['alt_firmware_url']['firmware_base_url'] = $config['system']['firmwareurl'];
273
		$config['system']['alt_firmware_url']['firmware_filename'] = $config['system']['firmwarename'];
274
		unset($config['system']['firmwareurl'], $config['system']['firmwarename']);
275
	} else {
276
		unset($config['system']['firmwareurl'], $config['system']['firmwarename']);
277
	}
278
}
279

    
280

    
281
function upgrade_016_to_017() {
282
	global $config;
283
	/* wipe previous shaper configuration */
284
	unset($config['shaper']['queue']);
285
	unset($config['shaper']['rule']);
286
	unset($config['interfaces']['wan']['bandwidth']);
287
	unset($config['interfaces']['wan']['bandwidthtype']);
288
	unset($config['interfaces']['lan']['bandwidth']);
289
	unset($config['interfaces']['lan']['bandwidthtype']);
290
	$config['shaper']['enable'] = FALSE;
291
}
292

    
293

    
294
function upgrade_017_to_018() {
295
	global $config;
296
	if(isset($config['proxyarp']) && is_array($config['proxyarp']['proxyarpnet'])) {
297
		$proxyarp = &$config['proxyarp']['proxyarpnet'];
298
		foreach($proxyarp as $arpent){
299
			$vip = array();
300
			$vip['mode'] = "proxyarp";
301
			$vip['interface'] = $arpent['interface'];
302
			$vip['descr'] = $arpent['descr'];
303
			if (isset($arpent['range'])) {
304
				$vip['range'] = $arpent['range'];
305
				$vip['type'] = "range";
306
			} else {
307
				$subnet = explode('/', $arpent['network']);
308
				$vip['subnet'] = $subnet[0];
309
				if (isset($subnet[1])) {
310
					$vip['subnet_bits'] = $subnet[1];
311
					$vip['type'] = "network";
312
				} else {
313
					$vip['subnet_bits'] = "32";
314
					$vip['type'] = "single";
315
				}
316
			}
317
			$config['virtualip']['vip'][] = $vip;
318
		}
319
		unset($config['proxyarp']);
320
	}
321
	if(isset($config['installedpackages']) && isset($config['installedpackages']['carp']) && is_array($config['installedpackages']['carp']['config'])) {
322
		$carp = &$config['installedpackages']['carp']['config'];
323
		foreach($carp as $carpent){
324
			$vip = array();
325
			$vip['mode'] = "carp";
326
			$vip['interface'] = "AUTO";
327
			$vip['descr'] = "CARP vhid {$carpent['vhid']}";
328
			$vip['type'] = "single";
329
			$vip['vhid'] = $carpent['vhid'];
330
			$vip['advskew'] = $carpent['advskew'];
331
			$vip['password'] = $carpent['password'];
332
			$vip['subnet'] = $carpent['ipaddress'];
333
			$vip['subnet_bits'] = $carpent['netmask'];
334
			$config['virtualip']['vip'][] = $vip;
335
		}
336
		unset($config['installedpackages']['carp']);
337
	}
338
	/* Server NAT is no longer needed */
339
	unset($config['nat']['servernat']);
340

    
341
	/* enable SSH */
342
	if ($config['version'] == "1.8") {
343
		$config['system']['sshenabled'] = true;
344
	}
345
}
346

    
347

    
348
function upgrade_018_to_019() {
349
	global $config;
350
	$config['theme']="metallic";
351
}
352

    
353

    
354
function upgrade_019_to_020() {
355
	global $config;
356
	if(is_array($config['ipsec']['tunnel'])) {
357
		reset($config['ipsec']['tunnel']);
358
		while (list($index, $tunnel) = each($config['ipsec']['tunnel'])) {
359
			/* Sanity check on required variables */
360
			/* This fixes bogus <tunnel> entries - remnant of bug #393 */
361
			if (!isset($tunnel['local-subnet']) && !isset($tunnel['remote-subnet'])) {
362
				unset($config['ipsec']['tunnel'][$tunnel]);
363
			}
364
		}
365
	}
366
}
367

    
368
function upgrade_020_to_021() {
369
	global $config;
370
	/* shaper scheduler moved */
371
	if(isset($config['system']['schedulertype'])) {
372
		$config['shaper']['schedulertype'] = $config['system']['schedulertype'];
373
		unset($config['system']['schedulertype']);
374
	}
375
}
376

    
377

    
378
function upgrade_021_to_022() {
379
	global $config;
380
	/* move gateway to wan interface */
381
	$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
382
}
383

    
384
function upgrade_022_to_023() {
385
	global $config;
386
	if(isset($config['shaper'])) {
387
		/* wipe previous shaper configuration */
388
		unset($config['shaper']);
389
	}
390
}
391

    
392

    
393
function upgrade_023_to_024() {
394
	global $config;
395
}
396

    
397

    
398
function upgrade_024_to_025() {
399
	global $config;
400
	$config['interfaces']['wan']['use_rrd_gateway'] = $config['system']['use_rrd_gateway'];
401
	unset($config['system']['use_rrd_gateway']);
402
}
403

    
404

    
405
function upgrade_025_to_026() {
406
	global $config;
407
	$cron_item = array();
408
	$cron_item['minute'] = "0";
409
	$cron_item['hour'] = "*";
410
	$cron_item['mday'] = "*";
411
	$cron_item['month'] = "*";
412
	$cron_item['wday'] = "*";
413
	$cron_item['who'] = "root";
414
	$cron_item['command'] = "/usr/bin/nice -n20 newsyslog";
415

    
416
	$config['cron']['item'][] = $cron_item;
417

    
418
	$cron_item = array();
419
	$cron_item['minute'] = "1,31";
420
	$cron_item['hour'] = "0-5";
421
	$cron_item['mday'] = "*";
422
	$cron_item['month'] = "*";
423
	$cron_item['wday'] = "*";
424
	$cron_item['who'] = "root";
425
	$cron_item['command'] = "/usr/bin/nice -n20 adjkerntz -a";
426

    
427
	$config['cron']['item'][] = $cron_item;
428

    
429
	$cron_item = array();
430
	$cron_item['minute'] = "1";
431
	$cron_item['hour'] = "*";
432
	$cron_item['mday'] = "1";
433
	$cron_item['month'] = "*";
434
	$cron_item['wday'] = "*";
435
	$cron_item['who'] = "root";
436
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.update_bogons.sh";
437

    
438
	$config['cron']['item'][] = $cron_item;
439

    
440
	$cron_item = array();
441
	$cron_item['minute'] = "*/60";
442
	$cron_item['hour'] = "*";
443
	$cron_item['mday'] = "*";
444
	$cron_item['month'] = "*";
445
	$cron_item['wday'] = "*";
446
	$cron_item['who'] = "root";
447
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 sshlockout";
448

    
449
	$config['cron']['item'][] = $cron_item;
450

    
451
	$cron_item = array();
452
	$cron_item['minute'] = "1";
453
	$cron_item['hour'] = "1";
454
	$cron_item['mday'] = "*";
455
	$cron_item['month'] = "*";
456
	$cron_item['wday'] = "*";
457
	$cron_item['who'] = "root";
458
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.dyndns.update";
459

    
460
	$config['cron']['item'][] = $cron_item;
461

    
462
	$cron_item = array();
463
	$cron_item['minute'] = "*/60";
464
	$cron_item['hour'] = "*";
465
	$cron_item['mday'] = "*";
466
	$cron_item['month'] = "*";
467
	$cron_item['wday'] = "*";
468
	$cron_item['who'] = "root";
469
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 virusprot";
470

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

    
473
	$cron_item = array();
474
	$cron_item['minute'] = "*/60";
475
	$cron_item['hour'] = "*";
476
	$cron_item['mday'] = "*";
477
	$cron_item['month'] = "*";
478
	$cron_item['wday'] = "*";
479
	$cron_item['who'] = "root";
480
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -t 1800 snort2c";
481

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

    
484
	$cron_item = array();
485
	$cron_item['minute'] = "*/5";
486
	$cron_item['hour'] = "*";
487
	$cron_item['mday'] = "*";
488
	$cron_item['month'] = "*";
489
	$cron_item['wday'] = "*";
490
	$cron_item['who'] = "root";
491
	$cron_item['command'] = "/usr/local/bin/checkreload.sh";
492

    
493
	$config['cron']['item'][] = $cron_item;
494
}
495

    
496

    
497
function upgrade_026_to_027() {
498
	global $config;
499
}
500

    
501

    
502
function upgrade_027_to_028() {
503
	global $config;
504
	$founditem = false;
505
	foreach($config['cron']['item'] as $cronitem) {
506
		if($cronitem['command'] == "/usr/local/bin/checkreload.sh")
507
			$founditem = true;
508
	}
509
	if($founditem == false) {
510
		$cron_item = array();
511
		$cron_item['minute'] = "*/5";
512
		$cron_item['hour'] = "*";
513
		$cron_item['mday'] = "*";
514
		$cron_item['month'] = "*";
515
		$cron_item['wday'] = "*";
516
		$cron_item['who'] = "root";
517
		$cron_item['command'] = "/usr/local/bin/checkreload.sh";
518
		$config['cron']['item'][] = $cron_item;
519
	}
520
}
521

    
522

    
523
function upgrade_028_to_029() {
524
	global $config;
525
	$rule_item = array();
526
	$a_filter = &$config['filter']['rule'];
527
	$rule_item['interface'] = "enc0";
528
	$rule_item['type'] = "pass";
529
	$rule_item['source']['any'] = true;
530
	$rule_item['destination']['any'] = true;
531
	$rule_item['descr'] = "Permit IPsec traffic.";
532
	$rule_item['statetype'] = "keep state";
533
	$a_filter[] = $rule_item;
534
}
535

    
536

    
537
function upgrade_029_to_030() {
538
	global $config;
539
	/* enable the rrd config setting by default */
540
	$config['rrd']['enable'] = true;
541
}
542

    
543

    
544
function upgrade_030_to_031() {
545
	global $config;
546
	/* Insert upgrade code here */
547
}
548

    
549

    
550
function upgrade_031_to_032() {
551
	global $config;
552
	/* Insert upgrade code here */
553
}
554

    
555

    
556
function upgrade_032_to_033() {
557
	global $config;
558
	/* Insert upgrade code here */
559
}
560

    
561

    
562
function upgrade_033_to_034() {
563
	global $config;
564
	/* Insert upgrade code here */
565
}
566

    
567

    
568
function upgrade_034_to_035() {
569
	global $config;
570
	/* Insert upgrade code here */
571
}
572

    
573

    
574
function upgrade_035_to_036() {
575
	global $config;
576
	/* Insert upgrade code here */
577
}
578

    
579

    
580
function upgrade_036_to_037() {
581
	global $config;
582
	/* Insert upgrade code here */
583
}
584

    
585

    
586
function upgrade_037_to_038() {
587
	global $config;
588

    
589
	/* This should only be valid when upgrading bridges from a 1.2 config */
590
	$a_bridges = array();
591
	$counter = 0;
592
	foreach($config['interfaces'] as $name => & $interface ) {
593
		if($interface['bridge'] <> "") {
594
			$bridge = array();
595
			$bridge['members'] = "{$name},{$interface['bridge']}";
596
			$bridge['descr'] = "Upgraded from 1.2";
597
			$bridge['maxaddr'] = "";
598
			$bridge['timeout'] = "";
599
			$bridge['maxage'] = "";
600
			$bridge['fwdelay'] = "";
601
			$bridge['hellotime'] = "";
602
			$bridge['priority'] = "";
603
			$bridge['proto'] = "rstp";
604
			$bridge['holdcount'] = "";
605
			$bridge['ifpriority'] = "";
606
			$bridge['ifpathcost'] = "";
607
			$bridge['bridgeif'] = "bridge{$counter}";
608
			$a_bridges[$counter] = $bridge;
609
			$counter++;
610
		}
611
	}
612
	$config['bridges'] = $a_bridges;
613
}
614

    
615

    
616
function upgrade_038_to_039() {
617
	global $config;
618

    
619
	/* This should only be valid when upgrading vlans from a 1.2 config though */
620
	/* Vlan upgrade code. Since we now create vlans with a vlanif tag we just start at 0 */
621
	$vlan_counter = 0;
622
	if (is_array($config['vlans']['vlan'])) {
623
		foreach ($config['vlans']['vlan'] as $vlan) {
624
			$config['vlans']['vlan'][$vlan_counter]['vlanif'] = "vlan{$vlan_counter}";
625
			$vlan_counter++;
626
		}
627
	}
628
}
629

    
630

    
631
function upgrade_039_to_040() {
632
	global $config;
633
	$config['system']['webgui']['auth_method'] = "session";
634
	$config['system']['webgui']['backing_method'] = "htpasswd";
635

    
636
	if (isset ($config['system']['username'])) {
637
		$config['system']['group'] = array();
638
		$config['system']['group'][0]['name'] = "admins";
639
		$config['system']['group'][0]['description'] = "System Administrators";
640
		$config['system']['group'][0]['scope'] = "system";
641
		$config['system']['group'][0]['pages'] = "ANY";
642
		$config['system']['group'][0]['home'] = "index.php";
643
		$config['system']['group'][0]['gid'] = "110";
644

    
645
		$config['system']['user'] = array();
646
		$config['system']['user'][0]['name'] = "{$config['system']['username']}";
647
		$config['system']['user'][0]['fullname'] = "System Administrator";
648
		$config['system']['user'][0]['scope'] = "system";
649
		$config['system']['user'][0]['groupname'] = "admins";
650
		$config['system']['user'][0]['password'] = "{$config['system']['password']}";
651
		$config['system']['user'][0]['uid'] = "0";
652

    
653
		$config['system']['user'][0]['priv'] = array();
654
		$config['system']['user'][0]['priv'][0]['id'] = "lockwc";
655
		$config['system']['user'][0]['priv'][0]['name'] = "Lock webConfigurator";
656
		$config['system']['user'][0]['priv'][0]['descr'] = "Indicates whether this user will lock access to the webConfigurator for other users.";
657
		$config['system']['user'][0]['priv'][1]['id'] = "lock-ipages";
658
		$config['system']['user'][0]['priv'][1]['name'] = "Lock individual pages";
659
		$config['system']['user'][0]['priv'][1]['descr'] = "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).";
660
		$config['system']['user'][0]['priv'][2]['id'] = "hasshell";
661
		$config['system']['user'][0]['priv'][2]['name'] = "Has shell access";
662
		$config['system']['user'][0]['priv'][2]['descr'] = "Indicates whether this user is able to login for example via SSH.";
663
		$config['system']['user'][0]['priv'][3]['id'] = "copyfiles";
664
		$config['system']['user'][0]['priv'][3]['name'] = "Is allowed to copy files";
665
		$config['system']['user'][0]['priv'][3]['descr'] = "Indicates whether this user is allowed to copy files onto the {$g['product_name']} appliance via SCP/SFTP. If you are going to use this privilege, you must install scponly on the appliance (Hint: pkg_add -r scponly).";
666
		$config['system']['user'][0]['priv'][4]['id'] = "isroot";
667
		$config['system']['user'][0]['priv'][4]['name'] = "Is root user";
668
		$config['system']['user'][0]['priv'][4]['descr'] = "This user is associated with the UNIX root user (you should associate this privilege only with one single user).";
669

    
670
		$config['system']['nextuid'] = "111";
671
		$config['system']['nextgid'] = "111";
672

    
673
		/* wipe previous auth configuration */
674
		unset ($config['system']['username']);
675
		unset ($config['system']['password']);
676
	}
677
}
678

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

    
684
		$config['sysctl']['item'][0]['tunable'] = "net.inet.tcp.blackhole";
685
		$config['sysctl']['item'][0]['desc'] =    "Drop packets to closed TCP ports without returning a RST";
686
		$config['sysctl']['item'][0]['value'] =   "2";
687

    
688
		$config['sysctl']['item'][1]['tunable'] = "net.inet.udp.blackhole";
689
		$config['sysctl']['item'][1]['desc'] =    "Do not send ICMP port unreachable messages for closed UDP ports";
690
		$config['sysctl']['item'][1]['value'] =   "1";
691

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

    
696
		$config['sysctl']['item'][3]['tunable'] = "net.inet.tcp.drop_synfin";
697
		$config['sysctl']['item'][3]['desc'] =    "Drop SYN-FIN packets (breaks RFC1379, but nobody uses it anyway)";
698
		$config['sysctl']['item'][3]['value'] =   "1";
699

    
700
		$config['sysctl']['item'][4]['tunable'] = "net.inet.ip.redirect";
701
		$config['sysctl']['item'][4]['desc'] =    "Disable sending IPv4 redirects";
702
		$config['sysctl']['item'][4]['value'] =   "0";
703

    
704
		$config['sysctl']['item'][5]['tunable'] = "net.inet6.ip6.redirect";
705
		$config['sysctl']['item'][5]['desc'] =    "Disable sending IPv6 redirects";
706
		$config['sysctl']['item'][5]['value'] =   "0";
707

    
708
		$config['sysctl']['item'][6]['tunable'] = "net.inet.tcp.syncookies";
709
		$config['sysctl']['item'][6]['desc'] =    "Generate SYN cookies for outbound SYN-ACK packets";
710
		$config['sysctl']['item'][6]['value'] =   "1";
711

    
712
		$config['sysctl']['item'][7]['tunable'] = "net.inet.tcp.recvspace";
713
		$config['sysctl']['item'][7]['desc'] =    "Maximum incoming TCP datagram size";
714
		$config['sysctl']['item'][7]['value'] =   "65228";
715

    
716
		$config['sysctl']['item'][8]['tunable'] = "net.inet.tcp.sendspace";
717
		$config['sysctl']['item'][8]['desc'] =    "Maximum outgoing TCP datagram size";
718
		$config['sysctl']['item'][8]['value'] =   "65228";
719

    
720
		$config['sysctl']['item'][9]['tunable'] = "net.inet.ip.fastforwarding";
721
		$config['sysctl']['item'][9]['desc'] =    "Fastforwarding (see http://lists.freebsd.org/pipermail/freebsd-net/2004-January/002534.html)";
722
		$config['sysctl']['item'][9]['value'] =   "1";
723

    
724
		$config['sysctl']['item'][10]['tunable'] = "net.inet.tcp.delayed_ack";
725
		$config['sysctl']['item'][10]['desc'] =    "Do not delay ACK to try and piggyback it onto a data packet";
726
		$config['sysctl']['item'][10]['value'] =   "0";
727

    
728
		$config['sysctl']['item'][11]['tunable'] = "net.inet.udp.maxdgram";
729
		$config['sysctl']['item'][11]['desc'] =    "Maximum outgoing UDP datagram size";
730
		$config['sysctl']['item'][11]['value'] =   "57344";
731

    
732
		$config['sysctl']['item'][12]['tunable'] = "net.link.bridge.pfil_onlyip";
733
		$config['sysctl']['item'][12]['desc'] =    "Handling of non-IP packets which are not passed to pfil (see if_bridge(4))";
734
		$config['sysctl']['item'][12]['value'] =   "0";
735

    
736
		$config['sysctl']['item'][13]['tunable'] = "net.link.tap.user_open";
737
		$config['sysctl']['item'][13]['desc'] =    "Allow unprivileged access to tap(4) device nodes";
738
		$config['sysctl']['item'][13]['value'] =   "1";
739

    
740
		$config['sysctl']['item'][14]['tunable'] = "kern.rndtest.verbose";
741
		$config['sysctl']['item'][14]['desc'] =    "Verbosity of the rndtest driver (0: do not display results on console)";
742
		$config['sysctl']['item'][14]['value'] =   "0";
743

    
744
		$config['sysctl']['item'][15]['tunable'] = "kern.randompid";
745
		$config['sysctl']['item'][15]['desc'] =    "Randomize PID's (see src/sys/kern/kern_fork.c: sysctl_kern_randompid())";
746
		$config['sysctl']['item'][15]['value'] =   "347";
747

    
748
		$config['sysctl']['item'][16]['tunable'] = "net.inet.tcp.inflight.enable";
749
		$config['sysctl']['item'][16]['desc'] =    "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. ";
750
		$config['sysctl']['item'][16]['value'] =   "1";
751

    
752
		$config['sysctl']['item'][17]['tunable'] = "net.inet.icmp.icmplim";
753
		$config['sysctl']['item'][17]['desc'] =    "Set ICMP Limits";
754
		$config['sysctl']['item'][17]['value'] =   "750";
755

    
756
		$config['sysctl']['item'][18]['tunable'] = "net.inet.tcp.tso";
757
		$config['sysctl']['item'][18]['desc'] =    "TCP Offload engine";
758
		$config['sysctl']['item'][18]['value'] =   "0";
759

    
760
		$config['sysctl']['item'][19]['tunable'] = "hw.bce.tso_enable";
761
		$config['sysctl']['item'][19]['desc'] =    "TCP Offload engine - BCE";
762
		$config['sysctl']['item'][19]['value'] =   "0";
763
	}
764
}
765

    
766

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

    
775

    
776
function upgrade_042_to_043() {
777
	global $config;
778
	/* migrate old interface gateway to the new gateways config */
779
	$old_gateways = array();
780
	$gateways = array();
781
	$i = 0;
782
	$old_gateways = get_interfaces_with_gateway();
783
	foreach($old_gateways as $ifname => $interface) {
784
		if(is_ipaddr($config['interfaces'][$ifname]['gateway'])) {
785
			$config['gateways'][$i][$ifname]['gateway'] = $config['interfaces'][$ifname]['gateway'];
786
			$config['gateways'][$i][$ifname]['interface'] = $ifname;
787
			$config['gateways'][$i][$ifname]['name'] = $ifname ."-". $config['interfaces'][$ifname]['gateway'];
788
			if(is_ipaddr($config['interfaces'][$ifname]['use_rrd_gateway'])) {
789
				$config['gateways'][$i][$ifname]['monitor'] = $config['interfaces'][$ifname]['use_rrd_gateway'];
790
				unset($config['interfaces'][$ifname]['use_rrd_gateway']);
791
			}
792
			$config['interfaces'][$ifname]['gateway'] = $config['gateways'][$i][$ifname]['name'];
793
			$i++;
794
		}
795
	}
796
}
797

    
798

    
799
function upgrade_043_to_044() {
800
	global $config;
801
}
802

    
803

    
804
function upgrade_044_to_045() {
805
	global $config;
806
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
807
		foreach ($config['vlans']['vlan'] as $id => &$vlan)
808
			$vlan['vlanif'] = "vlan{$tag}";
809
	}
810
}
811

    
812

    
813
function upgrade_045_to_046() {
814
	global $config;
815
	/* Upgrade load balancer from slb to relayd */
816
	if (is_array($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server'])) {
817
		$vs_a = &$config['load_balancer']['virtual_server'];
818
		$pool_a = &$config['load_balancer']['lbpool'];
819
		$pools = array();
820
		/* Index pools by name */
821
		if(is_array($pool_a)) {
822
			for ($i = 0; isset($pool_a[$i]); $i++) {
823
				if ($pool_a[$i]['type'] == "server") {
824
					$pools[$pool_a[$i]['name']] = $pool_a[$i];
825
				}
826
			}
827
		}
828
		/* Convert sitedown entries to pools and re-attach */
829
		for ($i = 0; isset($vs_a[$i]); $i++) {
830
			if (isset($vs_a[$i]['sitedown'])) {
831
				$pool = array();
832
				$pool['type'] = 'server';
833
				$pool['behaviour'] = 'balance';
834
				$pool['name'] = "{$vs_a[$i]['name']}-sitedown";
835
				$pool['desc'] = "Sitedown pool for VS: {$vs_a[$i]['name']}";
836
				$pool['port'] = $pools[$vs_a[$i]['pool']]['port'];
837
				$pool['servers'] = array();
838
				$pool['servers'][] = $vs_a[$i]['sitedown'];
839
				$pool['monitor'] = $pools[$vs_a[$i]['pool']]['monitor'];
840
				$pool_a[] = $pool;
841
				$vs_a[$i]['sitedown'] = $pool['name'];
842
			}
843
		}
844
	}
845
}
846

    
847

    
848
function upgrade_046_to_047() {
849
	global $config;
850
	/* Upgrade IPsec from tunnel to phase1/phase2 */
851

    
852
	if(is_array($config['ipsec']['tunnel'])) {
853

    
854
		$a_phase1 = array();
855
		$a_phase2 = array();
856
		$ikeid = 0;
857

    
858
		foreach ($config['ipsec']['tunnel'] as $tunnel) {
859

    
860
			unset($ph1ent);
861
			unset($ph2ent);
862

    
863
			/*
864
				*  attempt to locate an enabled phase1
865
				*  entry that matches the peer gateway
866
				*/
867

    
868
			if (!isset($tunnel['disabled'])) {
869

    
870
				$remote_gateway = $tunnel['remote-gateway'];
871

    
872
				foreach ($a_phase1 as $ph1tmp) {
873
					if ($ph1tmp['remote-gateway'] == $remote_gateway) {
874
						$ph1ent = $ph1tmp;
875
						break;
876
					}
877
				}
878
			}
879

    
880
			/* none found, create a new one */
881

    
882
			if (!isset( $ph1ent )) {
883

    
884
				/* build new phase1 entry */
885

    
886
				$ph1ent = array();
887

    
888
				$ph1ent['ikeid'] = ++$ikeid;
889

    
890
				if (isset($tunnel['disabled']))
891
					$ph1ent['disabled'] = $tunnel['disabled'];
892

    
893
				$ph1ent['interface'] = $tunnel['interface'];
894
				$ph1ent['remote-gateway'] = $tunnel['remote-gateway'];
895
				$ph1ent['descr'] = $tunnel['descr'];
896

    
897
				$ph1ent['mode'] = $tunnel['p1']['mode'];
898

    
899
				if (isset($tunnel['p1']['myident']['myaddress']))
900
					$ph1ent['myid_type'] = "myaddress";
901
				if (isset($tunnel['p1']['myident']['address'])) {
902
					$ph1ent['myid_type'] = "address";
903
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['address'];
904
				}
905
				if (isset($tunnel['p1']['myident']['fqdn'])) {
906
					$ph1ent['myid_type'] = "fqdn";
907
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['fqdn'];
908
				}
909
				if (isset($tunnel['p1']['myident']['user_fqdn'])) {
910
					$ph1ent['myid_type'] = "user_fqdn";
911
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['user_fqdn'];
912
				}
913
				if (isset($tunnel['p1']['myident']['asn1dn'])) {
914
					$ph1ent['myid_type'] = "asn1dn";
915
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['asn1dn'];
916
				}
917
				if (isset($tunnel['p1']['myident']['dyn_dns'])) {
918
					$ph1ent['myid_type'] = "dyn_dns";
919
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['dyn_dns'];
920
				}
921

    
922
				$ph1ent['peerid_type'] = "peeraddress";
923

    
924
				switch ($tunnel['p1']['encryption-algorithm']) {
925
					case "des":
926
					$ph1alg = array( 'name' => 'des' );
927
					break;
928
					case "3des":
929
					$ph1alg = array( 'name' => '3des' );
930
					break;
931
					case "blowfish":
932
					$ph1alg = array( 'name' => 'blowfish', 'keylen' => '128'  );
933
					break;
934
					case "cast128":
935
					$ph1alg = array( 'name' => 'cast128' );
936
					break;
937
					case "rijndael":
938
					$ph1alg = array( 'name' => 'aes', 'keylen' => '128' );
939
					break;
940
					case "rijndael 256":
941
					$ph1alg = array( 'name' => 'aes', 'keylen' => '256' );
942
					break;
943
				}
944

    
945
				$ph1ent['encryption-algorithm'] = $ph1alg;
946
				$ph1ent['hash-algorithm'] = $tunnel['p1']['hash-algorithm'];
947
				$ph1ent['dhgroup'] = $tunnel['p1']['dhgroup'];
948
				$ph1ent['lifetime'] = $tunnel['p1']['lifetime'];
949
				$ph1ent['authentication_method'] = $tunnel['p1']['authentication_method'];
950

    
951
				if (isset($tunnel['p1']['pre-shared-key']))
952
					$ph1ent['pre-shared-key'] = $tunnel['p1']['pre-shared-key'];
953
				if (isset($tunnel['p1']['cert']))
954
					$ph1ent['cert'] = $tunnel['p1']['cert'];
955
				if (isset($tunnel['p1']['peercert']))
956
					$ph1ent['peercert'] = $tunnel['p1']['peercert'];
957
				if (isset($tunnel['p1']['private-key']))
958
					$ph1ent['private-key'] = $tunnel['p1']['private-key'];
959

    
960
				$ph1ent['nat_traversal'] = "on";
961
				$ph1ent['dpd_enable'] = 1;
962
				$ph1ent['dpd_delay'] = 10;
963
				$ph1ent['dpd_maxfail'] = 5;
964

    
965
				$a_phase1[] = $ph1ent;
966
			}
967

    
968
			/* build new phase2 entry */
969

    
970
			$ph2ent = array();
971

    
972
			$ph2ent['ikeid'] = $ph1ent['ikeid'];
973

    
974
			if (isset($tunnel['disabled']))
975
				$ph1ent['disabled'] = $tunnel['disabled'];
976

    
977
			$ph2ent['descr'] = "phase2 for ".$tunnel['descr'];
978

    
979
			$type = "lan";
980
			if ($tunnel['local-subnet']['network'])
981
				$type = $tunnel['local-subnet']['network'];
982
			if ($tunnel['local-subnet']['address']) {
983
				list($address,$netbits) = explode("/",$tunnel['local-subnet']['address']);
984
				if (is_null($netbits))
985
					$type = "address";
986
				else
987
					$type = "network";
988
			}
989

    
990
			switch ($type) {
991
				case "address":
992
				$ph2ent['localid'] = array('type' => $type,'address' => $address);
993
				break;
994
				case "network":
995
				$ph2ent['localid'] = array('type' => $type,'address' => $address,'netbits' => $netbits);
996
				break;
997
				default:
998
				$ph2ent['localid'] = array('type' => $type);
999
				break;
1000
			}
1001

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

    
1005
			$ph2ent['protocol'] = $tunnel['p2']['protocol'];
1006

    
1007
			$aes_count = 0;
1008
			foreach( $tunnel['p2']['encryption-algorithm-option'] as $tunalg ) {
1009
				$aes_found = false;
1010
				switch ($tunalg) {
1011
					case "des":
1012
					$ph2alg = array( 'name' => 'des' );
1013
					break;
1014
					case "3des":
1015
					$ph2alg = array( 'name' => '3des' );
1016
					break;
1017
					case "blowfish":
1018
					$ph2alg = array( 'name' => 'blowfish', 'keylen' => 'auto'  );
1019
					break;
1020
					case "cast128":
1021
					$ph2alg = array( 'name' => 'cast128' );
1022
					break;
1023
					case "rijndael":
1024
					case "rijndael 256":
1025
					$ph2alg = array( 'name' => 'aes', 'keylen' => 'auto' );
1026
					$aes_found = true;
1027
					$aes_count++;
1028
					break;
1029
				}
1030

    
1031
				if( !$aes_found || ($aes_count < 2))
1032
					$ph2ent['encryption-algorithm-option'][] = $ph2alg;
1033
			}
1034

    
1035
			$ph2ent['hash-algorithm-option'] = $tunnel['p2']['hash-algorithm-option'];
1036
			$ph2ent['pfsgroup'] = $tunnel['p2']['pfsgroup'];
1037
			$ph2ent['lifetime'] = $tunnel['p2']['lifetime'];
1038

    
1039
			if (isset($tunnel['pinghost']['pinghost']))
1040
				$ph2ent['pinghost'] = $tunnel['pinghost'];
1041

    
1042
			$a_phase2[] = $ph2ent;
1043
		}
1044

    
1045
		unset($config['ipsec']['tunnel']);
1046
		$config['ipsec']['phase1'] = $a_phase1;
1047
		$config['ipsec']['phase2'] = $a_phase2;
1048
	}
1049
}
1050

    
1051

    
1052
function upgrade_047_to_048() {
1053
	global $config;
1054
	$config['dyndnses']['dyndns'] = array();
1055
	if (isset($config['dyndns']['enable'])) {
1056
		$tempdyn = array();
1057
		$tempdyn['enable'] = isset($config['dyndns']['enable']);
1058
		$tempdyn['type'] = $config['dyndns']['type'];
1059
		$tempdyn['wildcard'] = isset($config['dyndns']['wildcard']);
1060
		$tempdyn['usernamefld'] = $config['dyndns']['username'];
1061
		$tempdyn['passwordfld'] = $config['dyndns']['password'];
1062
		$tempdyn['host'] = $config['dyndns']['host'];
1063
		$tempdyn['mx'] = $config['dyndns']['mx'];		
1064
		$config['dyndnses']['dyndns'][] = $tempdyn;
1065
		unset($config['dyndns']);
1066
	}		
1067
	$config['dnsupdates']['dnsupdate'] = array();
1068
	if (isset($config['dnsupdate']['enable'])) {
1069
		$pconfig = array();
1070
		$pconfig['dnsupdate_enable'] = isset($config['dnsupdate']['enable']);
1071
		$pconfig['dnsupdate_host'] = $config['dnsupdate']['host'];
1072
		$pconfig['dnsupdate_ttl'] = $config['dnsupdate']['ttl'];
1073
		if (!$pconfig['dnsupdate_ttl'])
1074
			$pconfig['dnsupdate_ttl'] = 60;
1075
		$pconfig['dnsupdate_keydata'] = $config['dnsupdate']['keydata'];
1076
		$pconfig['dnsupdate_keyname'] = $config['dnsupdate']['keyname'];
1077
		$pconfig['dnsupdate_keytype'] = $config['dnsupdate']['keytype'];
1078
		if (!$pconfig['dnsupdate_keytype'])
1079
			$pconfig['dnsupdate_keytype'] = "zone";
1080
		$pconfig['dnsupdate_server'] = $config['dnsupdate']['server'];
1081
		$pconfig['dnsupdate_usetcp'] = isset($config['dnsupdate']['usetcp']);
1082
		$config['dnsupdates']['dnsupdate'][] = $pconfig;
1083
		unset($config['dnsupdate']);
1084
	}
1085

    
1086
	if (is_array($config['pppoe'])) {
1087
		$pconfig = array();
1088
		$pconfig['username'] = $config['pppoe']['username'];
1089
		$pconfig['password'] = $config['pppoe']['password'];
1090
		$pconfig['provider'] = $config['pppoe']['provider'];
1091
		$pconfig['ondemand'] = isset($config['pppoe']['ondemand']);
1092
		$pconfig['timeout'] = $config['pppoe']['timeout'];
1093
		unset($config['pppoe']);
1094
		$config['interfaces']['wan']['pppoe_username'] = $pconfig['username'];
1095
		$config['interfaces']['wan']['pppoe_password'] = $pconfig['password'];
1096
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1097
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
1098
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1099
	}
1100
	if (is_array($config['pptp'])) {
1101
		$pconfig = array();
1102
		$pconfig['username'] = $config['pptp']['username'];
1103
		$pconfig['password'] = $config['pptp']['password'];
1104
		$pconfig['provider'] = $config['pptp']['provider'];
1105
		$pconfig['ondemand'] = isset($config['pptp']['ondemand']);
1106
		$pconfig['timeout'] = $config['pptp']['timeout'];
1107
		unset($config['pptp']);
1108
		$config['interfaces']['wan']['pptp_username'] = $pconfig['username'];
1109
		$config['interfaces']['wan']['pptp_password'] = $pconfig['password'];
1110
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1111
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand'] );
1112
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1113
	}
1114
}
1115

    
1116

    
1117
function upgrade_048_to_049() {
1118
	global $config;
1119
	/* setup new all users group */
1120
	$all = array();
1121
	$all['name'] = "all";
1122
	$all['description'] = "All Users";
1123
	$all['scope'] = "system";
1124
	$all['gid'] = 1998;
1125
	$all['member'] = array();
1126

    
1127
	if (!is_array($config['system']['group']))
1128
		$config['system']['group'] = array();
1129

    
1130
	/* work around broken uid assignments */
1131
	$config['system']['nextuid'] = 2000;
1132
	foreach ($config['system']['user'] as & $user) {
1133
		if (isset($user['uid']) && !$user['uid'])
1134
			continue;
1135
		$user['uid'] = $config['system']['nextuid']++;
1136
	}
1137

    
1138
	/* work around broken gid assignments */
1139
	$config['system']['nextgid'] = 2000;
1140
	foreach ($config['system']['group'] as & $group) {
1141
		if ($group['name'] == $g['admin_group'])
1142
			$group['gid'] = 1999;
1143
		else
1144
			$group['gid'] = $config['system']['nextgid']++;
1145
	}
1146

    
1147
	/* build group membership information */
1148
	foreach ($config['system']['group'] as & $group) {
1149
		$group['member'] = array();
1150
		foreach ($config['system']['user'] as & $user) {
1151
			$groupnames = explode(",", $user['groupname']);
1152
			if (in_array($group['name'],$groupnames))
1153
				$group['member'][] = $user['uid'];
1154
		}
1155
	}
1156

    
1157
	/* reset user group information */
1158
	foreach ($config['system']['user'] as & $user) {
1159
		unset($user['groupname']);
1160
		$all['member'][] = $user['uid'];
1161
	}
1162

    
1163
	/* reset group scope information */
1164
	foreach ($config['system']['group'] as & $group)
1165
		if ($group['name'] != $g['admin_group'])
1166
		$group['scope'] = "user";
1167

    
1168
	/* insert new all group */
1169
	$groups = Array();
1170
	$groups[] = $all;
1171
	$groups = array_merge($config['system']['group'],$groups);
1172
	$config['system']['group'] = $groups;
1173
}
1174

    
1175

    
1176
function upgrade_049_to_050() {
1177
	global $config;
1178
	/* update user privileges */
1179
	foreach ($config['system']['user'] as & $user) {
1180
		$privs = array();
1181
		if (!is_array($user['priv'])) {
1182
			unset($user['priv']);
1183
			continue;
1184
		}
1185
		foreach ($user['priv'] as $priv) {
1186
			switch($priv['id']) {
1187
				case "hasshell":
1188
				$privs[] = "user-shell-access";
1189
				break;
1190
				case "copyfiles":
1191
				$privs[] = "user-copy-files";
1192
				break;
1193
			}
1194
		}
1195
		$user['priv'] = $privs;
1196
	}
1197

    
1198
	/* update group privileges */
1199
	foreach ($config['system']['group'] as & $group) {
1200
		$privs = array();
1201
		if (!is_array($group['pages'])) {
1202
			unset($group['pages']);
1203
			continue;
1204
		}
1205
		foreach ($group['pages'] as $page) {
1206
			$priv = map_page_privname($page);
1207
			if ($priv)
1208
				$privs[] = $priv;
1209
		}
1210
		unset($group['pages']);
1211
		$group['priv'] = $privs;
1212
	}
1213

    
1214
	/* sync all local account information */
1215
	local_sync_accounts();
1216
}
1217

    
1218

    
1219
function upgrade_050_to_051() {
1220
	global $config;
1221
	$pconfig = array();
1222
	$pconfig['desc'] = "Set to 0 to disable filtering on the incoming and outgoing member interfaces.";
1223
	$pconfig['tunable'] = "net.link.bridge.pfil_member";
1224
	$pconfig['value'] = "1";
1225
	$config['sysctl']['item'][] = $pconfig;
1226
	$pconfig = array();
1227
	$pconfig['desc'] = "Set to 1 to enable filtering on the bridge interface";
1228
	$pconfig['tunable'] = "net.link.bridge.pfil_bridge";
1229
	$pconfig['value'] = "0";
1230
	$config['sysctl']['item'][] = $pconfig;
1231

    
1232
	unset($config['bridge']);
1233

    
1234
	$convert_bridges = false;
1235
	foreach($config['interfaces'] as $intf) {
1236
		if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1237
			$config['bridges'] = array();
1238
			$config['bridges']['bridged'] = array();
1239
			$convert_bridges = true;
1240
			break;
1241
		}
1242
	}
1243
	if ($convert_bridges == true) {
1244
		$i = 0;
1245
		foreach ($config['interfaces'] as $ifr => &$intf) {
1246
			if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1247
				$nbridge = array();
1248
				$nbridge['members'] = "{$ifr},{$intf['bridge']}";
1249
				$nbridge['descr'] = "Converted bridged {$ifr}";
1250
				$nbridge['bridgeif'] = "bridge{$i}";
1251
				$config['bridges']['bridged'][] = $nbridge;
1252
				unset($intf['bridge']);
1253
				$i++;
1254
			}
1255
		}
1256
	}
1257
}
1258

    
1259

    
1260
function upgrade_051_to_052() {
1261
	global $config;
1262
	$config['openvpn'] = array();
1263
	if (!is_array($config['system']['ca']))
1264
		$config['system']['ca'] = array();
1265
	if (!is_array($config['system']['cert']))
1266
		$config['system']['cert'] = array();
1267

    
1268
	$vpnid = 1;
1269

    
1270
	/* openvpn server configurations */
1271
	if (is_array($config['installedpackages']['openvpnserver'])) {
1272
		$config['openvpn']['openvpn-server'] = array();
1273

    
1274
		$index = 1;
1275
		foreach($config['installedpackages']['openvpnserver']['config'] as $server) {
1276

    
1277
			if (!is_array($server))
1278
				continue;
1279

    
1280
			if ($server['auth_method'] == "pki") {
1281

    
1282
				/* create ca entry */
1283
				$ca = array();
1284
				$ca['refid'] = uniqid();
1285
				$ca['name'] = "OpenVPN Server CA #{$index}";
1286
				$ca['crt'] = $server['ca_cert'];
1287
				$ca['crl'] = $server['crl'];
1288
				$config['system']['ca'][] = $ca;
1289

    
1290
				/* create ca reference */
1291
				unset($server['ca_cert']);
1292
				unset($server['crl']);
1293
				$server['caref'] = $ca['refid'];
1294

    
1295
				/* create cert entry */
1296
				$cert = array();
1297
				$cert['refid'] = uniqid();
1298
				$cert['name'] = "OpenVPN Server Certificate #{$index}";
1299
				$cert['crt'] = $server['server_cert'];
1300
				$cert['prv'] = $server['server_key'];
1301
				$config['system']['cert'][] = $cert;
1302

    
1303
				/* create cert reference */
1304
				unset($server['server_cert']);
1305
				unset($server['server_key']);
1306
				$server['certref'] = $cert['refid'];
1307

    
1308
				$index++;
1309
			}
1310

    
1311
			/* determine operational mode */
1312
			if ($server['auth_method'] == 'pki') {
1313
				if($server['nopool']) {
1314
					$server['mode'] = "p2p_tls";
1315
				} else {
1316
					$server['mode'] = "server_tls";
1317
				}
1318
			} else {
1319
				$server['mode'] = "p2p_shared_key";
1320
			}
1321
			unset($server['auth_method']);
1322

    
1323
			/* modify configuration values */
1324
			$server['dh_length'] = 1024;
1325
			unset($server['dh_params']);
1326
			if (!$server['interface'])
1327
				$server['interface'] = 'wan';
1328
			$server['tunnel_network'] = $server['addresspool'];
1329
			unset($server['addresspool']);
1330
			$server['compress'] = $server['use_lzo'];
1331
			unset($server['use_lzo']);
1332
			if ($server['nopool'])
1333
				$server['pool_enable'] = false;
1334
			else
1335
				$server['pool_enable'] = "yes";
1336
			unset($server['nopool']);
1337
			$server['dns_domain'] = $server['dhcp_domainname'];
1338
			unset($server['dhcp_domainname']);
1339
			$server['dns_server1'] = $server['dhcp_dns'];
1340
			unset($server['dhcp_dns']);
1341
			$server['ntp_server1'] = $server['dhcp_ntp'];
1342
			unset($server['dhcp_ntp']);
1343
			if ($server['dhcp_nbtdisable'])
1344
				$server['netbios_enable'] = false;
1345
			else
1346
				$server['netbios_enable'] = "yes";
1347
			unset($server['dhcp_nbtdisable']);
1348
			$server['netbios_ntype'] = $server['dhcp_nbttype'];
1349
			unset($server['dhcp_nbttype']);
1350
			$server['netbios_scope'] = $server['dhcp_nbtscope'];
1351
			unset($server['dhcp_nbtscope']);
1352
			$server['nbdd_server1'] = $server['dhcp_nbdd'];
1353
			unset($server['dhcp_nbdd']);
1354
			$server['wins_server1'] = $server['dhcp_wins'];
1355
			unset($server['dhcp_wins']);
1356

    
1357
			/* allocate vpnid */
1358
			$server['vpnid'] = $vpnid++;
1359

    
1360
			$config['openvpn']['openvpn-server'][] = $server;
1361
		}
1362
		unset($config['installedpackages']['openvpnserver']);
1363
	}
1364

    
1365
	/* openvpn client configurations */
1366
	if (is_array($config['installedpackages']['openvpnclient'])) {
1367
		$config['openvpn']['openvpn-client'] = array();
1368

    
1369
		$index = 1;
1370
		foreach($config['installedpackages']['openvpnclient']['config'] as $client) {
1371

    
1372
			if (!is_array($client))
1373
				continue;
1374

    
1375
			if ($client['auth_method'] == "pki") {
1376

    
1377
				/* create ca entry */
1378
				$ca = array();
1379
				$ca['refid'] = uniqid();
1380
				$ca['name'] = "OpenVPN Client CA #{$index}";
1381
				$ca['crt'] = $client['ca_cert'];
1382
				$ca['crl'] = $client['crl'];
1383
				$config['system']['ca'][] = $ca;
1384

    
1385
				/* create ca reference */
1386
				unset($client['ca_cert']);
1387
				unset($client['crl']);
1388
				$client['caref'] = $ca['refid'];
1389

    
1390
				/* create cert entry */
1391
				$cert = array();
1392
				$cert['refid'] = uniqid();
1393
				$cert['name'] = "OpenVPN Client Certificate #{$index}";
1394
				$cert['crt'] = $client['client_cert'];
1395
				$cert['prv'] = $client['client_key'];
1396
				$config['system']['cert'][] = $cert;
1397

    
1398
				/* create cert reference */
1399
				unset($client['client_cert']);
1400
				unset($client['client_key']);
1401
				$client['certref'] = $cert['refid'];
1402

    
1403
				$index++;
1404
			}
1405

    
1406
			/* determine operational mode */
1407
			if ($client['auth_method'] == 'pki')
1408
				$client['mode'] = "p2p_tls";
1409
			else
1410
				$client['mode'] = "p2p_shared_key";
1411
			unset($client['auth_method']);
1412

    
1413
			/* modify configuration values */
1414
			if (!$client['interface'])
1415
				$client['interface'] = 'wan';
1416
			$client['tunnel_network'] = $client['interface_ip'];
1417
			unset($client['interface_ip']);
1418
			$client['server_addr'] = $client['serveraddr'];
1419
			unset($client['serveraddr']);
1420
			$client['server_port'] = $client['serverport'];
1421
			unset($client['serverport']);
1422
			$client['proxy_addr'] = $client['poxy_hostname'];
1423
			unset($client['proxy_addr']);
1424
			$client['compress'] = $client['use_lzo'];
1425
			unset($client['use_lzo']);
1426
			$client['resolve_retry'] = $client['infiniteresolvretry'];
1427
			unset($client['infiniteresolvretry']);
1428

    
1429
			/* allocate vpnid */
1430
			$client['vpnid'] = $vpnid++;
1431

    
1432
			$config['openvpn']['openvpn-client'][] = $client;
1433
		}
1434

    
1435
		unset($config['installedpackages']['openvpnclient']);
1436
	}
1437

    
1438
	/* openvpn client specific configurations */
1439
	if (is_array($config['installedpackages']['openvpncsc'])) {
1440
		$config['openvpn']['openvpn-csc'] = array();
1441

    
1442
		foreach($config['installedpackages']['openvpncsc']['config'] as $csc) {
1443

    
1444
			if (!is_array($csc))
1445
				continue;
1446

    
1447
			/* modify configuration values */
1448
			$csc['common_name'] = $csc['commonname'];
1449
			unset($csc['commonname']);
1450
			$csc['tunnel_network'] = $csc['ifconfig_push'];
1451
			unset($csc['ifconfig_push']);
1452
			$csc['dns_domain'] = $csc['dhcp_domainname'];
1453
			unset($csc['dhcp_domainname']);
1454
			$csc['dns_server1'] = $csc['dhcp_dns'];
1455
			unset($csc['dhcp_dns']);
1456
			$csc['ntp_server1'] = $csc['dhcp_ntp'];
1457
			unset($csc['dhcp_ntp']);
1458
			if ($csc['dhcp_nbtdisable'])
1459
				$csc['netbios_enable'] = false;
1460
			else
1461
				$csc['netbios_enable'] = "yes";
1462
			unset($csc['dhcp_nbtdisable']);
1463
			$csc['netbios_ntype'] = $csc['dhcp_nbttype'];
1464
			unset($csc['dhcp_nbttype']);
1465
			$csc['netbios_scope'] = $csc['dhcp_nbtscope'];
1466
			unset($csc['dhcp_nbtscope']);
1467
			$csc['nbdd_server1'] = $csc['dhcp_nbdd'];
1468
			unset($csc['dhcp_nbdd']);
1469
			$csc['wins_server1'] = $csc['dhcp_wins'];
1470
			unset($csc['dhcp_wins']);
1471

    
1472
			$config['openvpn']['openvpn-csc'][] = $csc;
1473
		}
1474

    
1475
		unset($config['installedpackages']['openvpncsc']);
1476
	}
1477

    
1478
	/*
1479
		* FIXME: hack to keep things working with no installedpackages
1480
		* or carp array in the configuration data.
1481
		*/
1482
	if (!is_array($config['installedpackages']))
1483
		$config['installedpackages'] = array();
1484
	if (!is_array($config['installedpackages']['carp']))
1485
		$config['installedpackages']['carp'] = array();
1486

    
1487
	/* reconfigure openvpn services */
1488
	openvpn_resync_all();
1489
}
1490

    
1491

    
1492
function upgrade_052_to_053() {
1493
	global $config;
1494
	if (!is_array($config['system']['ca']))
1495
		$config['system']['ca'] = array();
1496
	if (!is_array($config['system']['cert']))
1497
		$config['system']['cert'] = array();
1498

    
1499
	/* migrate advanced admin page webui ssl to certifcate mngr */
1500
	if ($config['system']['webgui']['certificate'] &&
1501
	$config['system']['webgui']['private-key']) {
1502

    
1503
		/* create cert entry */
1504
		$cert = array();
1505
		$cert['refid'] = uniqid();
1506
		$cert['name'] = "webConfigurator SSL Certificate";
1507
		$cert['crt'] = $config['system']['webgui']['certificate'];
1508
		$cert['prv'] = $config['system']['webgui']['private-key'];
1509
		$config['system']['cert'][] = $cert;
1510

    
1511
		/* create cert reference */
1512
		unset($config['system']['webgui']['certificate']);
1513
		unset($config['system']['webgui']['private-key']);
1514
		$config['system']['webgui']['ssl-certref'] = $cert['refid'];
1515
	}
1516

    
1517
	/* migrate advanced admin page ssh keys to user manager */
1518
	if ($config['system']['ssh']['authorizedkeys']) {
1519
		$admin_user =& getUserEntryByUID(0);
1520
		$admin_user['authorizedkeys'] = $config['system']['ssh']['authorizedkeys'];
1521
		unset($config['system']['ssh']['authorizedkeys']);
1522
	}
1523
}
1524

    
1525

    
1526
function upgrade_053_to_054() {
1527
	global $config;
1528
	if(is_array($config['loadbalancer']['lbpool'])) {
1529
		$lbpool_arr = $config['loadbalancer']['lbpool'];
1530
		$lbpool_srv_arr = array();
1531
		$gateway_group_arr = array();
1532
		foreach($lbpool_arr as $lbpool) {
1533
			if($lbpool['type'] == "gateway") {
1534
				$gateway_group['name'] = $lbpool['name'];
1535
				$gateway_group['descr'] = $lbpool['desc'];
1536
				$gateway_group['trigger'] = "down";
1537
				$gateway_group['item'] = array();
1538
				$i=0;
1539
				foreach($lbpool['servers'] as $member) {
1540
					$split = split("\|", $member);
1541
					$interface = $split[0];
1542
					$monitor = $split[1];
1543
					if($lbpool['behaviour'] == "failover") { $i++; }
1544
					$gateway_group['item'][] = "$interface|$i";
1545
					$config['interfaces'][$interface]['monitorip'] = "$monitor";
1546
				}
1547
				$gateway_group_arr[] = $gateway_group;
1548
			} else {
1549
				$lbpool_srv_arr[] = $lbpool;
1550
			}
1551
		}
1552
		$config['loadbalancer']['lbpool'] = $lbpool_srv_arr;
1553
		$config['gateways']['gateway_group'] = $gateway_group_arr;
1554
	}
1555
	// Unset lbpool if we no longer have any server pools
1556
	if (count($lbpool_srv_arr) == 0) {
1557
		unset($config['load_balancer']['lbpool']);
1558
	} else {
1559
		$config['load_balancer']['lbpool'] = $lbpool_srv_arr;
1560
	}
1561
	// Only set the gateway group array if we converted any
1562
	if (count($gateway_group_arr) != 0) {
1563
		$config['gateways']['gateway_group'] = $gateway_group_arr;
1564
	}
1565
}
1566

    
1567

    
1568
function upgrade_054_to_055() {
1569
	global $config;
1570
	/* RRD files changed for quality, traffic and packets graphs */
1571
	ini_set("max_execution_time", "1800");
1572
	/* convert traffic RRD file */
1573
	global $parsedcfg, $listtags;
1574
	$listtags = array("ds", "v", "rra", "row");
1575

    
1576
	$rrddbpath = "/var/db/rrd/";
1577
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
1578

    
1579
	$rrdinterval = 60;
1580
	$valid = $rrdinterval * 2;
1581

    
1582
	/* Asume GigE for now */
1583
	$downstream = 125000000;
1584
	$upstream = 125000000;
1585

    
1586
	/* build a list of quality databases */
1587
	/* roundtrip has become delay */
1588
	function divide_delay($delayval) {
1589
		$delayval = floatval($delayval);
1590
		$delayval = ($delayval / 1000);
1591
		$delayval = " ". sprintf("%1.10e", $delayval) ." ";
1592
		return $delayval;
1593
	}
1594
	/* the roundtrip times need to be divided by 1000 to get seconds, really */
1595
	$databases = array();
1596
	exec("cd $rrddbpath;/usr/bin/find *-quality.rrd", $databases);
1597
	rsort($databases);
1598
	foreach($databases as $database) {
1599
		$xmldump = "{$database}.old.xml";
1600
		$xmldumpnew = "{$database}.new.xml";
1601

    
1602
		echo "Migrate RRD database {$database} to new format \n";
1603
		mwexec("$rrdtool tune {$rrddbpath}{$database} -r roundtrip:delay 2>&1");
1604

    
1605
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
1606
		$rrdoldxml = file_get_contents("{$g['tmp_path']}/{$xmldump}");
1607
		$rrdold = xml2array($rrdoldxml, 1, "tag");
1608
		$rrdold = $rrdold['rrd'];
1609

    
1610
		$i = 0;
1611
		foreach($rrdold['rra'] as $rra) {
1612
			$l = 0;
1613
			foreach($rra['database']['row'] as $row) {
1614
				$vnew = divide_delay($row['v'][1]);
1615
				$rrdold['rra'][$i]['database']['row'][$l]['v'][1] = $vnew;
1616
				$l++;
1617
			}
1618
			$i++;
1619
		}
1620

    
1621
		$rrdxml = dump_xml_config_raw($rrdold, "rrd");
1622
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", $rrdxml);
1623
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
1624

    
1625
	}
1626
	/* let apinger recreate required files */
1627
	setup_gateways_monitor();
1628

    
1629
	/* build a list of traffic and packets databases */
1630
	$databases = array();
1631
	exec("cd $rrddbpath;/usr/bin/find *-traffic.rrd *-packets.rrd", $databases);
1632
	rsort($databases);
1633
	foreach($databases as $database) {
1634
		$databasetmp = "{$database}.tmp";
1635
		$xmldump = "{$database}.old.xml";
1636
		$xmldumptmp = "{$database}.tmp.xml";
1637
		$xmldumpnew = "{$database}.new.xml";
1638

    
1639
		echo "Migrate RRD database {$database} to new format \n";
1640
		/* rename DS source */
1641
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r in:inpass 2>&1");
1642
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r out:outpass 2>71");
1643

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

    
1647
		/* create new rrd database file */
1648
		$rrdcreate = "$rrdtool create {$g['tmp_path']}/{$databasetmp} --step $rrdinterval ";
1649
		$rrdcreate .= "DS:inpass:COUNTER:$valid:0:$downstream ";
1650
		$rrdcreate .= "DS:outpass:COUNTER:$valid:0:$upstream ";
1651
		$rrdcreate .= "DS:inblock:COUNTER:$valid:0:$downstream ";
1652
		$rrdcreate .= "DS:outblock:COUNTER:$valid:0:$upstream ";
1653
		$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
1654
		$rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
1655
		$rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
1656
		$rrdcreate .= "RRA:AVERAGE:0.5:720:3000 ";
1657

    
1658
		create_new_rrd("$rrdcreate");
1659
		/* create temporary xml from new RRD */
1660
		dump_rrd_to_xml("{$g['tmp_path']}/{$databasetmp}", "{$g['tmp_path']}/{$xmldumptmp}");
1661

    
1662
		$rrdoldxml = file_get_contents("{$g['tmp_path']}/{$xmldump}");
1663
		$rrdold = xml2array($rrdoldxml, 1, "tag");
1664
		$rrdold = $rrdold['rrd'];
1665

    
1666
		$rrdnewxml = file_get_contents("{$g['tmp_path']}/{$xmldumptmp}");
1667
		$rrdnew = xml2array($rrdnewxml, 1, "tag");
1668
		$rrdnew = $rrdnew['rrd'];
1669

    
1670
		/* remove any MAX RRA's. Not needed for traffic. */
1671
		$i = 0;
1672
		foreach ($rrdold['rra'] as $rra) {
1673
			if(trim($rra['cf']) == "MAX") {
1674
				unset($rrdold['rra'][$i]);
1675
			}
1676
			$i++;
1677
		}
1678

    
1679
		$rrdxmlarray = migrate_rrd_format($rrdold, $rrdnew);
1680
		$rrdxml = dump_xml_config_raw($rrdxmlarray, "rrd");
1681
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", $rrdxml);
1682
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
1683

    
1684
	}
1685
	enable_rrd_graphing();
1686
}
1687

    
1688

    
1689
function upgrade_055_to_056() {
1690
	global $config;
1691

    
1692
	if (!is_array($config['system']['ca']))
1693
		$config['system']['ca'] = array();
1694
	if (!is_array($config['system']['cert']))
1695
		$config['system']['cert'] = array();
1696

    
1697
	/* migrate ipsec ca's to cert manager */
1698
	if (is_array($config['ipsec']['cacert'])) {
1699
		foreach($config['ipsec']['cacert'] as & $cacert) {
1700
			$ca = array();
1701
			$ca['refid'] = uniqid();
1702
			if (is_array($cacert['cert']))
1703
				$ca['crt'] = $cacert['cert'][0];
1704
			else
1705
				$ca['crt'] = $cacert['cert'];
1706
			$ca['name'] = $cacert['ident'];
1707
			$config['system']['ca'][] = $ca;
1708
		}
1709
		unset($config['ipsec']['cacert']);
1710
	}
1711

    
1712
	/* migrate phase1 certificates to cert manager */
1713
	if (is_array($config['ipsec']['phase1'])) {
1714
		foreach($config['ipsec']['phase1'] as & $ph1ent) {
1715
			$cert = array();
1716
			$cert['refid'] = uniqid();
1717
			$cert['name'] = "IPsec Peer {$ph1ent['remote-gateway']} Certificate";
1718
			if (is_array($ph1ent['cert']))
1719
				$cert['crt'] = $ph1ent['cert'][0];
1720
			else
1721
				$cert['crt'] = $ph1ent['cert'];
1722
			$cert['prv'] = $ph1ent['private-key'];
1723
			$config['system']['cert'][] = $cert;
1724
			$ph1ent['certref'] = $cert['refid'];
1725
			if ($ph1ent['cert'])
1726
				unset($ph1ent['cert']);
1727
			if ($ph1ent['private-key'])
1728
				unset($ph1ent['private-key']);
1729
			if ($ph1ent['peercert'])
1730
				unset($ph1ent['peercert']);
1731
		}
1732
	}
1733
}
1734

    
1735

    
1736
function upgrade_056_to_057() {
1737
	global $config;
1738
	/* migrate captivate portal to user manager */
1739
	if (is_array($config['captiveportal']['user'])) {
1740
		foreach($config['captiveportal']['user'] as $user) {
1741
			// avoid user conflicts
1742
			if ($config['system']['user'][$user['name']])
1743
				continue;
1744
			$user['scope'] = "user";
1745
			if (isset($user['expirationdate'])) {
1746
				$user['expires'] = $user['expirationdate'];
1747
				unset($user['expirationdate']);
1748
			}
1749
			if (isset($user['password'])) {
1750
				$user['md5-hash'] = $user['password'];
1751
				unset($user['password']);
1752
			}
1753
			$config['system']['user'][] = $user;
1754
		}
1755
		unset($config['captiveportal']['user']);
1756
	}
1757
}
1758

    
1759
function upgrade_057_to_058() {
1760
	global $config;
1761
	/* set all phase2 entries to tunnel mode */
1762
	if (is_array($config['ipsec']['phase2']))
1763
		foreach($config['ipsec']['phase2'] as & $ph2ent)
1764
			$ph2ent['mode'] = 'tunnel';
1765
}
1766

    
1767
function upgrade_058_to_059() {
1768
	global $config;
1769

    
1770
	if (is_array($config['schedules']['schedule'])) {
1771
		foreach ($config['schedules']['schedule'] as & $schedl)
1772
			$schedl['schedlabel'] = uniqid();
1773
	}
1774
}
1775

    
1776
function upgrade_059_to_060() {
1777
	global $config;
1778
	/* Insert upgrade code here */
1779
}
1780

    
1781
?>
(33-33/40)