Project

General

Profile

Download (55.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@gmail.com>
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
	pfSense_BUILDER_BINARIES:	/usr/bin/find	/bin/cd	/usr/local/bin/rrdtool	/usr/bin/nice
34
	pfSense_MODULE:	config
35
*/
36

    
37
/* Upgrade functions must be named:
38
*    upgrade_XXX_to_YYY
39
	* where XXX == previous version, zero padded, and YYY == next version, zero padded
40
	*/
41

    
42
function upgrade_010_to_011() {
43
	global $config;
44
	$opti = 1;
45
	$ifmap = array('lan' => 'lan', 'wan' => 'wan', 'pptp' => 'pptp');
46

    
47
	/* convert DMZ to optional, if necessary */
48
	if (isset($config['interfaces']['dmz'])) {
49

    
50
		$dmzcfg = &$config['interfaces']['dmz'];
51

    
52
		if ($dmzcfg['if']) {
53
			$config['interfaces']['opt' . $opti] = array();
54
			$optcfg = &$config['interfaces']['opt' . $opti];
55

    
56
			$optcfg['enable'] = $dmzcfg['enable'];
57
			$optcfg['descr'] = "DMZ";
58
			$optcfg['if'] = $dmzcfg['if'];
59
			$optcfg['ipaddr'] = $dmzcfg['ipaddr'];
60
			$optcfg['subnet'] = $dmzcfg['subnet'];
61

    
62
			$ifmap['dmz'] = "opt" . $opti;
63
			$opti++;
64
		}
65

    
66
		unset($config['interfaces']['dmz']);
67
	}
68

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

    
72
		if (!$config['interfaces']['wlan' . $i]['if']) {
73
			unset($config['interfaces']['wlan' . $i]);
74
			continue;
75
		}
76

    
77
		$wlancfg = &$config['interfaces']['wlan' . $i];
78
		$config['interfaces']['opt' . $opti] = array();
79
		$optcfg = &$config['interfaces']['opt' . $opti];
80

    
81
		$optcfg['enable'] = $wlancfg['enable'];
82
		$optcfg['descr'] = "WLAN" . $i;
83
		$optcfg['if'] = $wlancfg['if'];
84
		$optcfg['ipaddr'] = $wlancfg['ipaddr'];
85
		$optcfg['subnet'] = $wlancfg['subnet'];
86
		$optcfg['bridge'] = $wlancfg['bridge'];
87

    
88
		$optcfg['wireless'] = array();
89
		$optcfg['wireless']['mode'] = $wlancfg['mode'];
90
		$optcfg['wireless']['ssid'] = $wlancfg['ssid'];
91
		$optcfg['wireless']['channel'] = $wlancfg['channel'];
92
		$optcfg['wireless']['wep'] = $wlancfg['wep'];
93

    
94
		$ifmap['wlan' . $i] = "opt" . $opti;
95

    
96
		unset($config['interfaces']['wlan' . $i]);
97
		$opti++;
98
	}
99

    
100
	/* convert filter rules */
101
	$n = count($config['filter']['rule']);
102
	for ($i = 0; $i < $n; $i++) {
103

    
104
		$fr = &$config['filter']['rule'][$i];
105

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

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

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

    
144
	/* convert shaper rules */
145
	$n = count($config['pfqueueing']['rule']);
146
	if (is_array($config['pfqueueing']['rule']))
147
	for ($i = 0; $i < $n; $i++) {
148

    
149
		$fr = &$config['pfqueueing']['rule'][$i];
150

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

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

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

    
190

    
191
function upgrade_011_to_012() {
192
	global $config;
193
	/* move LAN DHCP server config */
194
	$tmp = $config['dhcpd'];
195
	$config['dhcpd'] = array();
196
	$config['dhcpd']['lan'] = $tmp;
197

    
198
	/* encrypt password */
199
	$config['system']['password'] = crypt($config['system']['password']);
200
}
201

    
202

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

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

    
221

    
222
function upgrade_013_to_014() {
223
	global $config;
224
	/* convert shaper rules (make pipes) */
225
	if (is_array($config['pfqueueing']['rule'])) {
226
		$config['pfqueueing']['pipe'] = array();
227

    
228
		for ($i = 0; isset($config['pfqueueing']['rule'][$i]); $i++) {
229
			$curent = &$config['pfqueueing']['rule'][$i];
230

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

    
239
			$curent['targetpipe'] = $i;
240

    
241
			unset($curent['bandwidth']);
242
			unset($curent['delay']);
243
			unset($curent['mask']);
244
		}
245
	}
246
}
247

    
248

    
249
function upgrade_014_to_015() {
250
	global $config;
251
	/* Default route moved */
252
	if (isset($config['interfaces']['wan']['gateway']))
253
		if ($config['interfaces']['wan']['gateway'] <> "")
254
		$config['interfaces']['wan']['gateway'] = $config['interfaces']['wan']['gateway'];
255
	unset($config['interfaces']['wan']['gateway']);
256

    
257
	/* Queues are no longer interface specific */
258
	if (isset($config['interfaces']['lan']['schedulertype']))
259
		unset($config['interfaces']['lan']['schedulertype']);
260
	if (isset($config['interfaces']['wan']['schedulertype']))
261
		unset($config['interfaces']['wan']['schedulertype']);
262

    
263
	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
264
		if(isset($config['interfaces']['opt' . $i]['schedulertype']))
265
			unset($config['interfaces']['opt' . $i]['schedulertype']);
266
	}
267
}
268

    
269

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

    
284

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

    
297

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

    
345
	/* enable SSH */
346
	if ($config['version'] == "1.8") {
347
		$config['system']['sshenabled'] = true;
348
	}
349
}
350

    
351

    
352
function upgrade_018_to_019() {
353
	global $config;
354
	$config['theme']="metallic";
355
}
356

    
357

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

    
372
function upgrade_020_to_021() {
373
	global $config;
374
	/* shaper scheduler moved */
375
	if(isset($config['system']['schedulertype'])) {
376
		$config['shaper']['schedulertype'] = $config['system']['schedulertype'];
377
		unset($config['system']['schedulertype']);
378
	}
379
}
380

    
381

    
382
function upgrade_021_to_022() {
383
	global $config;
384
	/* move gateway to wan interface */
385
	$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
386
}
387

    
388
function upgrade_022_to_023() {
389
	global $config;
390
	if(isset($config['shaper'])) {
391
		/* wipe previous shaper configuration */
392
		unset($config['shaper']);
393
	}
394
}
395

    
396

    
397
function upgrade_023_to_024() {
398
	global $config;
399
}
400

    
401

    
402
function upgrade_024_to_025() {
403
	global $config;
404
	$config['interfaces']['wan']['use_rrd_gateway'] = $config['system']['use_rrd_gateway'];
405
	unset($config['system']['use_rrd_gateway']);
406
}
407

    
408

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

    
420
	$config['cron']['item'][] = $cron_item;
421

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

    
431
	$config['cron']['item'][] = $cron_item;
432

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

    
442
	$config['cron']['item'][] = $cron_item;
443

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

    
453
	$config['cron']['item'][] = $cron_item;
454

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

    
464
	$config['cron']['item'][] = $cron_item;
465

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

    
475
	$config['cron']['item'][] = $cron_item;
476

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

    
486
	$config['cron']['item'][] = $cron_item;
487

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

    
497
	$config['cron']['item'][] = $cron_item;
498
}
499

    
500

    
501
function upgrade_026_to_027() {
502
	global $config;
503
}
504

    
505

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

    
526

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

    
540

    
541
function upgrade_029_to_030() {
542
	global $config;
543
	/* enable the rrd config setting by default */
544
	$config['rrd']['enable'] = true;
545
}
546

    
547

    
548
function upgrade_030_to_031() {
549
	global $config;
550
	/* Insert upgrade code here */
551
}
552

    
553

    
554
function upgrade_031_to_032() {
555
	global $config;
556
	/* Insert upgrade code here */
557
}
558

    
559

    
560
function upgrade_032_to_033() {
561
	global $config;
562
	/* Insert upgrade code here */
563
}
564

    
565

    
566
function upgrade_033_to_034() {
567
	global $config;
568
	/* Insert upgrade code here */
569
}
570

    
571

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

    
577

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

    
583

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

    
589

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

    
595

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

    
601

    
602
function upgrade_039_to_040() {
603
	global $config;
604
	$config['system']['webgui']['auth_method'] = "session";
605
	$config['system']['webgui']['backing_method'] = "htpasswd";
606

    
607
	if (isset ($config['system']['username'])) {
608
		$config['system']['group'] = array();
609
		$config['system']['group'][0]['name'] = "admins";
610
		$config['system']['group'][0]['description'] = "System Administrators";
611
		$config['system']['group'][0]['scope'] = "system";
612
		$config['system']['group'][0]['pages'] = "ANY";
613
		$config['system']['group'][0]['home'] = "index.php";
614
		$config['system']['group'][0]['gid'] = "110";
615

    
616
		$config['system']['user'] = array();
617
		$config['system']['user'][0]['name'] = "{$config['system']['username']}";
618
		$config['system']['user'][0]['fullname'] = "System Administrator";
619
		$config['system']['user'][0]['scope'] = "system";
620
		$config['system']['user'][0]['groupname'] = "admins";
621
		$config['system']['user'][0]['password'] = "{$config['system']['password']}";
622
		$config['system']['user'][0]['uid'] = "0";
623

    
624
		$config['system']['user'][0]['priv'] = array();
625
		$config['system']['user'][0]['priv'][0]['id'] = "lockwc";
626
		$config['system']['user'][0]['priv'][0]['name'] = "Lock webConfigurator";
627
		$config['system']['user'][0]['priv'][0]['descr'] = "Indicates whether this user will lock access to the webConfigurator for other users.";
628
		$config['system']['user'][0]['priv'][1]['id'] = "lock-ipages";
629
		$config['system']['user'][0]['priv'][1]['name'] = "Lock individual pages";
630
		$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).";
631
		$config['system']['user'][0]['priv'][2]['id'] = "hasshell";
632
		$config['system']['user'][0]['priv'][2]['name'] = "Has shell access";
633
		$config['system']['user'][0]['priv'][2]['descr'] = "Indicates whether this user is able to login for example via SSH.";
634
		$config['system']['user'][0]['priv'][3]['id'] = "copyfiles";
635
		$config['system']['user'][0]['priv'][3]['name'] = "Is allowed to copy files";
636
		$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).";
637
		$config['system']['user'][0]['priv'][4]['id'] = "isroot";
638
		$config['system']['user'][0]['priv'][4]['name'] = "Is root user";
639
		$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).";
640

    
641
		$config['system']['nextuid'] = "111";
642
		$config['system']['nextgid'] = "111";
643

    
644
		/* wipe previous auth configuration */
645
		unset ($config['system']['username']);
646
		unset ($config['system']['password']);
647
	}
648
}
649

    
650
function upgrade_040_to_041() {
651
	global $config;
652
	if(!$config['sysctl']) {
653
		$config['sysctl']['item'] = array();
654

    
655
		$config['sysctl']['item'][0]['tunable'] = "net.inet.tcp.blackhole";
656
		$config['sysctl']['item'][0]['desc'] =    "Drop packets to closed TCP ports without returning a RST";
657
		$config['sysctl']['item'][0]['value'] =   "default";
658

    
659
		$config['sysctl']['item'][1]['tunable'] = "net.inet.udp.blackhole";
660
		$config['sysctl']['item'][1]['desc'] =    "Do not send ICMP port unreachable messages for closed UDP ports";
661
		$config['sysctl']['item'][1]['value'] =   "default";
662

    
663
		$config['sysctl']['item'][2]['tunable'] = "net.inet.ip.random_id";
664
		$config['sysctl']['item'][2]['desc'] =    "Randomize the ID field in IP packets (default is 0: sequential IP IDs)";
665
		$config['sysctl']['item'][2]['value'] =   "default";
666

    
667
		$config['sysctl']['item'][3]['tunable'] = "net.inet.tcp.drop_synfin";
668
		$config['sysctl']['item'][3]['desc'] =    "Drop SYN-FIN packets (breaks RFC1379, but nobody uses it anyway)";
669
		$config['sysctl']['item'][3]['value'] =   "default";
670

    
671
		$config['sysctl']['item'][4]['tunable'] = "net.inet.ip.redirect";
672
		$config['sysctl']['item'][4]['desc'] =    "Sending of IPv4 ICMP redirects";
673
		$config['sysctl']['item'][4]['value'] =   "default";
674

    
675
		$config['sysctl']['item'][5]['tunable'] = "net.inet6.ip6.redirect";
676
		$config['sysctl']['item'][5]['desc'] =    "Sending of IPv6 ICMP redirects";
677
		$config['sysctl']['item'][5]['value'] =   "default";
678

    
679
		$config['sysctl']['item'][6]['tunable'] = "net.inet.tcp.syncookies";
680
		$config['sysctl']['item'][6]['desc'] =    "Generate SYN cookies for outbound SYN-ACK packets";
681
		$config['sysctl']['item'][6]['value'] =   "default";
682

    
683
		$config['sysctl']['item'][7]['tunable'] = "net.inet.tcp.recvspace";
684
		$config['sysctl']['item'][7]['desc'] =    "Maximum incoming TCP datagram size";
685
		$config['sysctl']['item'][7]['value'] =   "default";
686

    
687
		$config['sysctl']['item'][8]['tunable'] = "net.inet.tcp.sendspace";
688
		$config['sysctl']['item'][8]['desc'] =    "Maximum outgoing TCP datagram size";
689
		$config['sysctl']['item'][8]['value'] =   "default";
690

    
691
		$config['sysctl']['item'][9]['tunable'] = "net.inet.ip.fastforwarding";
692
		$config['sysctl']['item'][9]['desc'] =    "Fastforwarding (see http://lists.freebsd.org/pipermail/freebsd-net/2004-January/002534.html)";
693
		$config['sysctl']['item'][9]['value'] =   "default";
694

    
695
		$config['sysctl']['item'][10]['tunable'] = "net.inet.tcp.delayed_ack";
696
		$config['sysctl']['item'][10]['desc'] =    "Do not delay ACK to try and piggyback it onto a data packet";
697
		$config['sysctl']['item'][10]['value'] =   "default";
698

    
699
		$config['sysctl']['item'][11]['tunable'] = "net.inet.udp.maxdgram";
700
		$config['sysctl']['item'][11]['desc'] =    "Maximum outgoing UDP datagram size";
701
		$config['sysctl']['item'][11]['value'] =   "default";
702

    
703
		$config['sysctl']['item'][12]['tunable'] = "net.link.bridge.pfil_onlyip";
704
		$config['sysctl']['item'][12]['desc'] =    "Handling of non-IP packets which are not passed to pfil (see if_bridge(4))";
705
		$config['sysctl']['item'][12]['value'] =   "default";
706

    
707
		$config['sysctl']['item'][13]['tunable'] = "net.link.tap.user_open";
708
		$config['sysctl']['item'][13]['desc'] =    "Allow unprivileged access to tap(4) device nodes";
709
		$config['sysctl']['item'][13]['value'] =   "default";
710

    
711
		$config['sysctl']['item'][14]['tunable'] = "kern.rndtest.verbose";
712
		$config['sysctl']['item'][14]['desc'] =    "Verbosity of the rndtest driver (0: do not display results on console)";
713
		$config['sysctl']['item'][14]['value'] =   "default";
714

    
715
		$config['sysctl']['item'][15]['tunable'] = "kern.randompid";
716
		$config['sysctl']['item'][15]['desc'] =    "Randomize PID's (see src/sys/kern/kern_fork.c: sysctl_kern_randompid())";
717
		$config['sysctl']['item'][15]['value'] =   "default";
718

    
719
		$config['sysctl']['item'][16]['tunable'] = "net.inet.tcp.inflight.enable";
720
		$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. ";
721
		$config['sysctl']['item'][16]['value'] =   "default";
722

    
723
		$config['sysctl']['item'][17]['tunable'] = "net.inet.icmp.icmplim";
724
		$config['sysctl']['item'][17]['desc'] =    "Set ICMP Limits";
725
		$config['sysctl']['item'][17]['value'] =   "default";
726

    
727
		$config['sysctl']['item'][18]['tunable'] = "net.inet.tcp.tso";
728
		$config['sysctl']['item'][18]['desc'] =    "TCP Offload engine";
729
		$config['sysctl']['item'][18]['value'] =   "default";
730

    
731
		$config['sysctl']['item'][19]['tunable'] = "hw.bce.tso_enable";
732
		$config['sysctl']['item'][19]['desc'] =    "TCP Offload engine - BCE";
733
		$config['sysctl']['item'][19]['value'] =   "default";
734
		
735
		$config['sysctl']['item'][20]['tunable'] = "net.inet.ip.portrange.first";
736
		$config['sysctl']['item'][20]['desc'] =    "Set the ephemeral port range starting port";
737
		$config['sysctl']['item'][20]['value'] =   "default";
738

    
739
		$config['sysctl']['item'][21]['tunable'] = "hw.syscons.kbd_reboot ";
740
		$config['sysctl']['item'][21]['desc'] =    "Enables ctrl+alt+delete";
741
		$config['sysctl']['item'][21]['value'] =   "default";
742

    
743
	}
744
}
745

    
746

    
747
function upgrade_041_to_042() {
748
	global $config;
749
	if (isset($config['shaper']))
750
		unset($config['shaper']);
751
	if (isset($config['ezshaper']))
752
		unset($config['ezshaper']);
753
}
754

    
755

    
756
function upgrade_042_to_043() {
757
	global $config;
758
	/* migrate old interface gateway to the new gateways config */
759
	$old_gateways = array();
760
	$gateways = array();
761
	$i = 0;
762
	$old_gateways = get_interfaces_with_gateway();
763
	foreach($old_gateways as $ifname => $interface) {
764
		if(is_ipaddr($config['interfaces'][$ifname]['gateway'])) {
765
			$config['gateways'][$i][$ifname]['gateway'] = $config['interfaces'][$ifname]['gateway'];
766
			$config['gateways'][$i][$ifname]['interface'] = $ifname;
767
			$config['gateways'][$i][$ifname]['name'] = $ifname ."-". $config['interfaces'][$ifname]['gateway'];
768
			if(is_ipaddr($config['interfaces'][$ifname]['use_rrd_gateway'])) {
769
				$config['gateways'][$i][$ifname]['monitor'] = $config['interfaces'][$ifname]['use_rrd_gateway'];
770
				unset($config['interfaces'][$ifname]['use_rrd_gateway']);
771
			}
772
			$config['interfaces'][$ifname]['gateway'] = $config['gateways'][$i][$ifname]['name'];
773
			$i++;
774
		}
775
	}
776
}
777

    
778

    
779
function upgrade_043_to_044() {
780
	global $config;
781
}
782

    
783

    
784
function upgrade_044_to_045() {
785
	global $config;
786
	$iflist = get_configured_interface_list(false, true);
787
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
788
		foreach ($config['vlans']['vlan'] as $id => $vlan) {
789
			$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}";
790
			$config['vlans']['vlan'][$id] = $vlan;
791
			/* Make sure to update the interfaces section with the right name */
792
			foreach($iflist as $ifname) {
793
				if($config['interfaces'][$ifname]['if'] == "vlan{$id}") {
794
					$config['interfaces'][$ifname]['if'] = $vlan['vlanif'];
795
				}
796
			}
797
			
798
		}
799
	}
800
}
801

    
802

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

    
840

    
841
function upgrade_046_to_047() {
842
	global $config;
843
	/* Upgrade IPsec from tunnel to phase1/phase2 */
844

    
845
	if(is_array($config['ipsec']['tunnel'])) {
846

    
847
		$a_phase1 = array();
848
		$a_phase2 = array();
849
		$ikeid = 0;
850

    
851
		foreach ($config['ipsec']['tunnel'] as $tunnel) {
852

    
853
			unset($ph1ent);
854
			unset($ph2ent);
855

    
856
			/*
857
				*  attempt to locate an enabled phase1
858
				*  entry that matches the peer gateway
859
				*/
860

    
861
			if (!isset($tunnel['disabled'])) {
862

    
863
				$remote_gateway = $tunnel['remote-gateway'];
864

    
865
				foreach ($a_phase1 as $ph1tmp) {
866
					if ($ph1tmp['remote-gateway'] == $remote_gateway) {
867
						$ph1ent = $ph1tmp;
868
						break;
869
					}
870
				}
871
			}
872

    
873
			/* none found, create a new one */
874

    
875
			if (!isset( $ph1ent )) {
876

    
877
				/* build new phase1 entry */
878

    
879
				$ph1ent = array();
880

    
881
				$ph1ent['ikeid'] = ++$ikeid;
882

    
883
				if (isset($tunnel['disabled']))
884
					$ph1ent['disabled'] = $tunnel['disabled'];
885

    
886
				$ph1ent['interface'] = $tunnel['interface'];
887
				$ph1ent['remote-gateway'] = $tunnel['remote-gateway'];
888
				$ph1ent['descr'] = $tunnel['descr'];
889

    
890
				$ph1ent['mode'] = $tunnel['p1']['mode'];
891

    
892
				if (isset($tunnel['p1']['myident']['myaddress']))
893
					$ph1ent['myid_type'] = "myaddress";
894
				if (isset($tunnel['p1']['myident']['address'])) {
895
					$ph1ent['myid_type'] = "address";
896
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['address'];
897
				}
898
				if (isset($tunnel['p1']['myident']['fqdn'])) {
899
					$ph1ent['myid_type'] = "fqdn";
900
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['fqdn'];
901
				}
902
				if (isset($tunnel['p1']['myident']['user_fqdn'])) {
903
					$ph1ent['myid_type'] = "user_fqdn";
904
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['user_fqdn'];
905
				}
906
				if (isset($tunnel['p1']['myident']['asn1dn'])) {
907
					$ph1ent['myid_type'] = "asn1dn";
908
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['asn1dn'];
909
				}
910
				if (isset($tunnel['p1']['myident']['dyn_dns'])) {
911
					$ph1ent['myid_type'] = "dyn_dns";
912
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['dyn_dns'];
913
				}
914

    
915
				$ph1ent['peerid_type'] = "peeraddress";
916

    
917
				switch ($tunnel['p1']['encryption-algorithm']) {
918
					case "des":
919
					$ph1alg = array( 'name' => 'des' );
920
					break;
921
					case "3des":
922
					$ph1alg = array( 'name' => '3des' );
923
					break;
924
					case "blowfish":
925
					$ph1alg = array( 'name' => 'blowfish', 'keylen' => '128'  );
926
					break;
927
					case "cast128":
928
					$ph1alg = array( 'name' => 'cast128' );
929
					break;
930
					case "rijndael":
931
					$ph1alg = array( 'name' => 'aes', 'keylen' => '128' );
932
					break;
933
					case "rijndael 256":
934
					$ph1alg = array( 'name' => 'aes', 'keylen' => '256' );
935
					break;
936
				}
937

    
938
				$ph1ent['encryption-algorithm'] = $ph1alg;
939
				$ph1ent['hash-algorithm'] = $tunnel['p1']['hash-algorithm'];
940
				$ph1ent['dhgroup'] = $tunnel['p1']['dhgroup'];
941
				$ph1ent['lifetime'] = $tunnel['p1']['lifetime'];
942
				$ph1ent['authentication_method'] = $tunnel['p1']['authentication_method'];
943

    
944
				if (isset($tunnel['p1']['pre-shared-key']))
945
					$ph1ent['pre-shared-key'] = $tunnel['p1']['pre-shared-key'];
946
				if (isset($tunnel['p1']['cert']))
947
					$ph1ent['cert'] = $tunnel['p1']['cert'];
948
				if (isset($tunnel['p1']['peercert']))
949
					$ph1ent['peercert'] = $tunnel['p1']['peercert'];
950
				if (isset($tunnel['p1']['private-key']))
951
					$ph1ent['private-key'] = $tunnel['p1']['private-key'];
952

    
953
				$ph1ent['nat_traversal'] = "on";
954
				$ph1ent['dpd_enable'] = 1;
955
				$ph1ent['dpd_delay'] = 10;
956
				$ph1ent['dpd_maxfail'] = 5;
957

    
958
				$a_phase1[] = $ph1ent;
959
			}
960

    
961
			/* build new phase2 entry */
962

    
963
			$ph2ent = array();
964

    
965
			$ph2ent['ikeid'] = $ph1ent['ikeid'];
966

    
967
			if (isset($tunnel['disabled']))
968
				$ph1ent['disabled'] = $tunnel['disabled'];
969

    
970
			$ph2ent['descr'] = "phase2 for ".$tunnel['descr'];
971

    
972
			$type = "lan";
973
			if ($tunnel['local-subnet']['network'])
974
				$type = $tunnel['local-subnet']['network'];
975
			if ($tunnel['local-subnet']['address']) {
976
				list($address,$netbits) = explode("/",$tunnel['local-subnet']['address']);
977
				if (is_null($netbits))
978
					$type = "address";
979
				else
980
					$type = "network";
981
			}
982

    
983
			switch ($type) {
984
				case "address":
985
				$ph2ent['localid'] = array('type' => $type,'address' => $address);
986
				break;
987
				case "network":
988
				$ph2ent['localid'] = array('type' => $type,'address' => $address,'netbits' => $netbits);
989
				break;
990
				default:
991
				$ph2ent['localid'] = array('type' => $type);
992
				break;
993
			}
994

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

    
998
			$ph2ent['protocol'] = $tunnel['p2']['protocol'];
999

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

    
1024
				if( !$aes_found || ($aes_count < 2))
1025
					$ph2ent['encryption-algorithm-option'][] = $ph2alg;
1026
			}
1027

    
1028
			$ph2ent['hash-algorithm-option'] = $tunnel['p2']['hash-algorithm-option'];
1029
			$ph2ent['pfsgroup'] = $tunnel['p2']['pfsgroup'];
1030
			$ph2ent['lifetime'] = $tunnel['p2']['lifetime'];
1031

    
1032
			if (isset($tunnel['pinghost']['pinghost']))
1033
				$ph2ent['pinghost'] = $tunnel['pinghost'];
1034

    
1035
			$a_phase2[] = $ph2ent;
1036
		}
1037

    
1038
		unset($config['ipsec']['tunnel']);
1039
		$config['ipsec']['phase1'] = $a_phase1;
1040
		$config['ipsec']['phase2'] = $a_phase2;
1041
	}
1042
}
1043

    
1044

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

    
1079
	if (is_array($config['pppoe'])) {
1080
		$pconfig = array();
1081
		$pconfig['username'] = $config['pppoe']['username'];
1082
		$pconfig['password'] = $config['pppoe']['password'];
1083
		$pconfig['provider'] = $config['pppoe']['provider'];
1084
		$pconfig['ondemand'] = isset($config['pppoe']['ondemand']);
1085
		$pconfig['timeout'] = $config['pppoe']['timeout'];
1086
		unset($config['pppoe']);
1087
		$config['interfaces']['wan']['pppoe_username'] = $pconfig['username'];
1088
		$config['interfaces']['wan']['pppoe_password'] = $pconfig['password'];
1089
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1090
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
1091
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1092
	}
1093
	if (is_array($config['pptp'])) {
1094
		$pconfig = array();
1095
		$pconfig['username'] = $config['pptp']['username'];
1096
		$pconfig['password'] = $config['pptp']['password'];
1097
		$pconfig['provider'] = $config['pptp']['provider'];
1098
		$pconfig['ondemand'] = isset($config['pptp']['ondemand']);
1099
		$pconfig['timeout'] = $config['pptp']['timeout'];
1100
		unset($config['pptp']);
1101
		$config['interfaces']['wan']['pptp_username'] = $pconfig['username'];
1102
		$config['interfaces']['wan']['pptp_password'] = $pconfig['password'];
1103
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1104
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand'] );
1105
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1106
	}
1107
}
1108

    
1109

    
1110
function upgrade_048_to_049() {
1111
	global $config;
1112
	/* setup new all users group */
1113
	$all = array();
1114
	$all['name'] = "all";
1115
	$all['description'] = "All Users";
1116
	$all['scope'] = "system";
1117
	$all['gid'] = 1998;
1118
	$all['member'] = array();
1119

    
1120
	if (!is_array($config['system']['group']))
1121
		$config['system']['group'] = array();
1122

    
1123
	/* work around broken uid assignments */
1124
	$config['system']['nextuid'] = 2000;
1125
	foreach ($config['system']['user'] as & $user) {
1126
		if (isset($user['uid']) && !$user['uid'])
1127
			continue;
1128
		$user['uid'] = $config['system']['nextuid']++;
1129
	}
1130

    
1131
	/* work around broken gid assignments */
1132
	$config['system']['nextgid'] = 2000;
1133
	foreach ($config['system']['group'] as & $group) {
1134
		if ($group['name'] == $g['admin_group'])
1135
			$group['gid'] = 1999;
1136
		else
1137
			$group['gid'] = $config['system']['nextgid']++;
1138
	}
1139

    
1140
	/* build group membership information */
1141
	foreach ($config['system']['group'] as & $group) {
1142
		$group['member'] = array();
1143
		foreach ($config['system']['user'] as & $user) {
1144
			$groupnames = explode(",", $user['groupname']);
1145
			if (in_array($group['name'],$groupnames))
1146
				$group['member'][] = $user['uid'];
1147
		}
1148
	}
1149

    
1150
	/* reset user group information */
1151
	foreach ($config['system']['user'] as & $user) {
1152
		unset($user['groupname']);
1153
		$all['member'][] = $user['uid'];
1154
	}
1155

    
1156
	/* reset group scope information */
1157
	foreach ($config['system']['group'] as & $group)
1158
		if ($group['name'] != $g['admin_group'])
1159
		$group['scope'] = "user";
1160

    
1161
	/* insert new all group */
1162
	$groups = Array();
1163
	$groups[] = $all;
1164
	$groups = array_merge($config['system']['group'],$groups);
1165
	$config['system']['group'] = $groups;
1166
}
1167

    
1168

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

    
1191
	/* update group privileges */
1192
	foreach ($config['system']['group'] as & $group) {
1193
		$privs = array();
1194
		if (!is_array($group['pages'])) {
1195
			unset($group['pages']);
1196
			continue;
1197
		}
1198
		foreach ($group['pages'] as $page) {
1199
			$priv = map_page_privname($page);
1200
			if ($priv)
1201
				$privs[] = $priv;
1202
		}
1203
		unset($group['pages']);
1204
		$group['priv'] = $privs;
1205
	}
1206

    
1207
	/* sync all local account information */
1208
	local_sync_accounts();
1209
}
1210

    
1211

    
1212
function upgrade_050_to_051() {
1213
	global $config;
1214
	$pconfig = array();
1215
	$pconfig['desc'] = "Set to 0 to disable filtering on the incoming and outgoing member interfaces.";
1216
	$pconfig['tunable'] = "net.link.bridge.pfil_member";
1217
	$pconfig['value'] = "1";
1218
	$config['sysctl']['item'][] = $pconfig;
1219
	$pconfig = array();
1220
	$pconfig['desc'] = "Set to 1 to enable filtering on the bridge interface";
1221
	$pconfig['tunable'] = "net.link.bridge.pfil_bridge";
1222
	$pconfig['value'] = "0";
1223
	$config['sysctl']['item'][] = $pconfig;
1224

    
1225
	unset($config['bridge']);
1226

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

    
1252

    
1253
function upgrade_051_to_052() {
1254
	global $config;
1255
	$config['openvpn'] = array();
1256
	if (!is_array($config['system']['ca']))
1257
		$config['system']['ca'] = array();
1258
	if (!is_array($config['system']['cert']))
1259
		$config['system']['cert'] = array();
1260

    
1261
	$vpnid = 1;
1262

    
1263
	/* openvpn server configurations */
1264
	if (is_array($config['installedpackages']['openvpnserver'])) {
1265
		$config['openvpn']['openvpn-server'] = array();
1266

    
1267
		$index = 1;
1268
		foreach($config['installedpackages']['openvpnserver']['config'] as $server) {
1269

    
1270
			if (!is_array($server))
1271
				continue;
1272

    
1273
			if ($server['auth_method'] == "pki") {
1274

    
1275
				/* create ca entry */
1276
				$ca = array();
1277
				$ca['refid'] = uniqid();
1278
				$ca['name'] = "OpenVPN Server CA #{$index}";
1279
				$ca['crt'] = $server['ca_cert'];
1280
				$ca['crl'] = $server['crl'];
1281
				$config['system']['ca'][] = $ca;
1282

    
1283
				/* create ca reference */
1284
				unset($server['ca_cert']);
1285
				unset($server['crl']);
1286
				$server['caref'] = $ca['refid'];
1287

    
1288
				/* create cert entry */
1289
				$cert = array();
1290
				$cert['refid'] = uniqid();
1291
				$cert['name'] = "OpenVPN Server Certificate #{$index}";
1292
				$cert['crt'] = $server['server_cert'];
1293
				$cert['prv'] = $server['server_key'];
1294
				$config['system']['cert'][] = $cert;
1295

    
1296
				/* create cert reference */
1297
				unset($server['server_cert']);
1298
				unset($server['server_key']);
1299
				$server['certref'] = $cert['refid'];
1300

    
1301
				$index++;
1302
			}
1303

    
1304
			/* determine operational mode */
1305
			if ($server['auth_method'] == 'pki') {
1306
				if($server['nopool']) {
1307
					$server['mode'] = "p2p_tls";
1308
				} else {
1309
					$server['mode'] = "server_tls";
1310
				}
1311
			} else {
1312
				$server['mode'] = "p2p_shared_key";
1313
			}
1314
			unset($server['auth_method']);
1315

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

    
1350
			/* allocate vpnid */
1351
			$server['vpnid'] = $vpnid++;
1352

    
1353
			$config['openvpn']['openvpn-server'][] = $server;
1354
		}
1355
		unset($config['installedpackages']['openvpnserver']);
1356
	}
1357

    
1358
	/* openvpn client configurations */
1359
	if (is_array($config['installedpackages']['openvpnclient'])) {
1360
		$config['openvpn']['openvpn-client'] = array();
1361

    
1362
		$index = 1;
1363
		foreach($config['installedpackages']['openvpnclient']['config'] as $client) {
1364

    
1365
			if (!is_array($client))
1366
				continue;
1367

    
1368
			if ($client['auth_method'] == "pki") {
1369

    
1370
				/* create ca entry */
1371
				$ca = array();
1372
				$ca['refid'] = uniqid();
1373
				$ca['name'] = "OpenVPN Client CA #{$index}";
1374
				$ca['crt'] = $client['ca_cert'];
1375
				$ca['crl'] = $client['crl'];
1376
				$config['system']['ca'][] = $ca;
1377

    
1378
				/* create ca reference */
1379
				unset($client['ca_cert']);
1380
				unset($client['crl']);
1381
				$client['caref'] = $ca['refid'];
1382

    
1383
				/* create cert entry */
1384
				$cert = array();
1385
				$cert['refid'] = uniqid();
1386
				$cert['name'] = "OpenVPN Client Certificate #{$index}";
1387
				$cert['crt'] = $client['client_cert'];
1388
				$cert['prv'] = $client['client_key'];
1389
				$config['system']['cert'][] = $cert;
1390

    
1391
				/* create cert reference */
1392
				unset($client['client_cert']);
1393
				unset($client['client_key']);
1394
				$client['certref'] = $cert['refid'];
1395

    
1396
				$index++;
1397
			}
1398

    
1399
			/* determine operational mode */
1400
			if ($client['auth_method'] == 'pki')
1401
				$client['mode'] = "p2p_tls";
1402
			else
1403
				$client['mode'] = "p2p_shared_key";
1404
			unset($client['auth_method']);
1405

    
1406
			/* modify configuration values */
1407
			if (!$client['interface'])
1408
				$client['interface'] = 'wan';
1409
			$client['tunnel_network'] = $client['interface_ip'];
1410
			unset($client['interface_ip']);
1411
			$client['server_addr'] = $client['serveraddr'];
1412
			unset($client['serveraddr']);
1413
			$client['server_port'] = $client['serverport'];
1414
			unset($client['serverport']);
1415
			$client['proxy_addr'] = $client['poxy_hostname'];
1416
			unset($client['proxy_addr']);
1417
			$client['compress'] = $client['use_lzo'];
1418
			unset($client['use_lzo']);
1419
			$client['resolve_retry'] = $client['infiniteresolvretry'];
1420
			unset($client['infiniteresolvretry']);
1421

    
1422
			/* allocate vpnid */
1423
			$client['vpnid'] = $vpnid++;
1424

    
1425
			$config['openvpn']['openvpn-client'][] = $client;
1426
		}
1427

    
1428
		unset($config['installedpackages']['openvpnclient']);
1429
	}
1430

    
1431
	/* openvpn client specific configurations */
1432
	if (is_array($config['installedpackages']['openvpncsc'])) {
1433
		$config['openvpn']['openvpn-csc'] = array();
1434

    
1435
		foreach($config['installedpackages']['openvpncsc']['config'] as $csc) {
1436

    
1437
			if (!is_array($csc))
1438
				continue;
1439

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

    
1465
			$config['openvpn']['openvpn-csc'][] = $csc;
1466
		}
1467

    
1468
		unset($config['installedpackages']['openvpncsc']);
1469
	}
1470

    
1471
	/*
1472
		* FIXME: hack to keep things working with no installedpackages
1473
		* or carp array in the configuration data.
1474
		*/
1475
	if (!is_array($config['installedpackages']))
1476
		$config['installedpackages'] = array();
1477
	if (!is_array($config['installedpackages']['carp']))
1478
		$config['installedpackages']['carp'] = array();
1479

    
1480
}
1481

    
1482

    
1483
function upgrade_052_to_053() {
1484
	global $config;
1485
	if (!is_array($config['system']['ca']))
1486
		$config['system']['ca'] = array();
1487
	if (!is_array($config['system']['cert']))
1488
		$config['system']['cert'] = array();
1489

    
1490
	/* migrate advanced admin page webui ssl to certifcate mngr */
1491
	if ($config['system']['webgui']['certificate'] &&
1492
	$config['system']['webgui']['private-key']) {
1493

    
1494
		/* create cert entry */
1495
		$cert = array();
1496
		$cert['refid'] = uniqid();
1497
		$cert['name'] = "webConfigurator SSL Certificate";
1498
		$cert['crt'] = $config['system']['webgui']['certificate'];
1499
		$cert['prv'] = $config['system']['webgui']['private-key'];
1500
		$config['system']['cert'][] = $cert;
1501

    
1502
		/* create cert reference */
1503
		unset($config['system']['webgui']['certificate']);
1504
		unset($config['system']['webgui']['private-key']);
1505
		$config['system']['webgui']['ssl-certref'] = $cert['refid'];
1506
	}
1507

    
1508
	/* migrate advanced admin page ssh keys to user manager */
1509
	if ($config['system']['ssh']['authorizedkeys']) {
1510
		$admin_user =& getUserEntryByUID(0);
1511
		$admin_user['authorizedkeys'] = $config['system']['ssh']['authorizedkeys'];
1512
		unset($config['system']['ssh']['authorizedkeys']);
1513
	}
1514
}
1515

    
1516

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

    
1561

    
1562
function upgrade_054_to_055() {
1563
	global $config;
1564
	global $g;
1565

    
1566
	/* RRD files changed for quality, traffic and packets graphs */
1567
	ini_set("max_execution_time", "1800");
1568
	/* convert traffic RRD file */
1569
	global $parsedcfg, $listtags;
1570
	$listtags = array("ds", "v", "rra", "row");
1571

    
1572
	$rrddbpath = "/var/db/rrd/";
1573
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
1574

    
1575
	$rrdinterval = 60;
1576
	$valid = $rrdinterval * 2;
1577

    
1578
	/* Asume GigE for now */
1579
	$downstream = 125000000;
1580
	$upstream = 125000000;
1581

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

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

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

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

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

    
1622
	}
1623
	/* let apinger recreate required files */
1624
	setup_gateways_monitor();
1625

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

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

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

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

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

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

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

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

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

    
1681
	}
1682
	enable_rrd_graphing();
1683
	echo "Updating configuration...";
1684
}
1685

    
1686

    
1687
function upgrade_055_to_056() {
1688
	global $config;
1689

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

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

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

    
1733

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

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

    
1765
function upgrade_058_to_059() {
1766
	global $config;
1767

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

    
1774
function upgrade_059_to_060() {
1775
	global $config;
1776
	require_once("/etc/inc/certs.inc");
1777
	if (is_array($config['system']['ca'])) {
1778
		/* Locate issuer for all CAs */
1779
		foreach ($config['system']['ca'] as & $ca) {
1780
			$subject = cert_get_subject($ca['crt']);
1781
			$issuer = cert_get_issuer($ca['crt']);
1782
			if($issuer <> $subject) {
1783
				$issuer_crt =& lookup_ca_by_subject($issuer);
1784
				if($issuer_crt)
1785
					$ca['caref'] = $issuer_crt['refid'];
1786
			}
1787
		}
1788
		
1789
		/* Locate issuer for all certificates */
1790
		if (is_array($config['system']['cert'])) {
1791
			foreach ($config['system']['cert'] as & $cert) {
1792
				$subject = cert_get_subject($cert['crt']);
1793
				$issuer = cert_get_issuer($cert['crt']);
1794
				if($issuer <> $subject) {
1795
					$issuer_crt =& lookup_ca_by_subject($issuer);
1796
					if($issuer_crt)
1797
						$cert['caref'] = $issuer_crt['refid'];
1798
				}
1799
			}
1800
		}
1801
	}
1802
}
1803

    
1804
?>
(41-41/51)