Project

General

Profile

Download (57.7 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
	$iflist = get_configured_interface_list();
760
	$gateways = array();
761
	$i = 0;
762
	foreach($iflist as $ifname => $interface) {
763
		if(! interface_has_gateway($ifname)) {
764
			continue;
765
		}
766
		if(is_ipaddr($config['interfaces'][$ifname]['gateway'])) {
767
			$config['gateways']['gateway_item'][$i]['gateway'] = $config['interfaces'][$ifname]['gateway'];
768
			$config['gateways']['gateway_item'][$i]['descr'] = "Interface $ifname Static Gateway";			
769
		} else {
770
			$config['gateways']['gateway_item'][$i]['gateway'] = "dynamic";
771
			$config['gateways']['gateway_item'][$i]['descr'] = "Interface $ifname Dynamic Gateway";			
772
		}
773
		$config['gateways']['gateway_item'][$i]['interface'] = $ifname;
774
		$config['gateways']['gateway_item'][$i]['name'] = "GW_" . strtoupper($ifname);
775
		/* add default gateway bit for wan on upgrade */
776
		if($ifname == "wan") {
777
			 $config['gateways']['gateway_item'][$i]['defaultgw'] = true;
778
		}
779
		if(is_ipaddr($config['interfaces'][$ifname]['use_rrd_gateway'])) {
780
			$config['gateways']['gateway_item'][$i]['monitor'] = $config['interfaces'][$ifname]['use_rrd_gateway'];
781
			unset($config['interfaces'][$ifname]['use_rrd_gateway']);
782
		}
783
		$config['interfaces'][$ifname]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
784

    
785
		/* Update all filter rules which might reference this gateway */
786
		$j = 0;
787
		foreach($config['filter']['rule'] as $rule) {
788
			if(is_ipaddr($rule['gateway']) && ($rule['gateway'] == $config['gateways']['gateway_item'][$i]['gateway'])) {
789
				$config['filter']['rule'][$j]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
790
			}
791
			$j++;
792
		}
793
		$i++;
794
	}
795
}
796

    
797

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

    
802

    
803
function upgrade_044_to_045() {
804
	global $config;
805
	$iflist = get_configured_interface_list(false, true);
806
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
807
		foreach ($config['vlans']['vlan'] as $id => $vlan) {
808
			$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}";
809
			$config['vlans']['vlan'][$id] = $vlan;
810
			/* Make sure to update the interfaces section with the right name */
811
			foreach($iflist as $ifname) {
812
				if($config['interfaces'][$ifname]['if'] == "vlan{$id}") {
813
					$config['interfaces'][$ifname]['if'] = $vlan['vlanif'];
814
				}
815
			}
816
			
817
		}
818
	}
819
}
820

    
821

    
822
function upgrade_045_to_046() {
823
	global $config;
824
	/* Upgrade load balancer from slb to relayd */
825
	if (is_array($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server'])) {
826
		$vs_a = &$config['load_balancer']['virtual_server'];
827
		$pool_a = &$config['load_balancer']['lbpool'];
828
		$pools = array();
829
		/* Index pools by name */
830
		if(is_array($pool_a)) {
831
			for ($i = 0; isset($pool_a[$i]); $i++) {
832
				if($pool_a[$i]['type'] == "server") {
833
					$pools[$pool_a[$i]['name']] = $pool_a[$i];
834
				}
835
			}
836
		}
837
		/* Convert sitedown entries to pools and re-attach */
838
		for ($i = 0; isset($vs_a[$i]); $i++) {
839
			if (isset($vs_a[$i]['sitedown'])) {
840
				$pool = array();
841
				$pool['type'] = 'server';
842
				$pool['behaviour'] = 'balance';
843
				$pool['name'] = "{$vs_a[$i]['name']}-sitedown";
844
				$pool['desc'] = "Sitedown pool for VS: {$vs_a[$i]['name']}";
845
				$pool['port'] = $pools[$vs_a[$i]['pool']]['port'];
846
				$pool['servers'] = array();
847
				$pool['servers'][] = $vs_a[$i]['sitedown'];
848
				$pool['monitor'] = $pools[$vs_a[$i]['pool']]['monitor'];
849
				$pool_a[] = $pool;
850
				$vs_a[$i]['sitedown'] = $pool['name'];
851
			}
852
		}
853
	}
854
	if(count($config['load_balancer']) == 0) {
855
		unset($config['load_balancer']);
856
	}
857
}
858

    
859

    
860
function upgrade_046_to_047() {
861
	global $config;
862
	/* Upgrade IPsec from tunnel to phase1/phase2 */
863

    
864
	if(is_array($config['ipsec']['tunnel'])) {
865

    
866
		$a_phase1 = array();
867
		$a_phase2 = array();
868
		$ikeid = 0;
869

    
870
		foreach ($config['ipsec']['tunnel'] as $tunnel) {
871

    
872
			unset($ph1ent);
873
			unset($ph2ent);
874

    
875
			/*
876
				*  attempt to locate an enabled phase1
877
				*  entry that matches the peer gateway
878
				*/
879

    
880
			if (!isset($tunnel['disabled'])) {
881

    
882
				$remote_gateway = $tunnel['remote-gateway'];
883

    
884
				foreach ($a_phase1 as $ph1tmp) {
885
					if ($ph1tmp['remote-gateway'] == $remote_gateway) {
886
						$ph1ent = $ph1tmp;
887
						break;
888
					}
889
				}
890
			}
891

    
892
			/* none found, create a new one */
893

    
894
			if (!isset( $ph1ent )) {
895

    
896
				/* build new phase1 entry */
897

    
898
				$ph1ent = array();
899

    
900
				$ph1ent['ikeid'] = ++$ikeid;
901

    
902
				if (isset($tunnel['disabled']))
903
					$ph1ent['disabled'] = $tunnel['disabled'];
904

    
905
				$ph1ent['interface'] = $tunnel['interface'];
906
				$ph1ent['remote-gateway'] = $tunnel['remote-gateway'];
907
				$ph1ent['descr'] = $tunnel['descr'];
908

    
909
				$ph1ent['mode'] = $tunnel['p1']['mode'];
910

    
911
				if (isset($tunnel['p1']['myident']['myaddress']))
912
					$ph1ent['myid_type'] = "myaddress";
913
				if (isset($tunnel['p1']['myident']['address'])) {
914
					$ph1ent['myid_type'] = "address";
915
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['address'];
916
				}
917
				if (isset($tunnel['p1']['myident']['fqdn'])) {
918
					$ph1ent['myid_type'] = "fqdn";
919
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['fqdn'];
920
				}
921
				if (isset($tunnel['p1']['myident']['user_fqdn'])) {
922
					$ph1ent['myid_type'] = "user_fqdn";
923
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['user_fqdn'];
924
				}
925
				if (isset($tunnel['p1']['myident']['asn1dn'])) {
926
					$ph1ent['myid_type'] = "asn1dn";
927
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['asn1dn'];
928
				}
929
				if (isset($tunnel['p1']['myident']['dyn_dns'])) {
930
					$ph1ent['myid_type'] = "dyn_dns";
931
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['dyn_dns'];
932
				}
933

    
934
				$ph1ent['peerid_type'] = "peeraddress";
935

    
936
				switch ($tunnel['p1']['encryption-algorithm']) {
937
					case "des":
938
					$ph1alg = array( 'name' => 'des' );
939
					break;
940
					case "3des":
941
					$ph1alg = array( 'name' => '3des' );
942
					break;
943
					case "blowfish":
944
					$ph1alg = array( 'name' => 'blowfish', 'keylen' => '128'  );
945
					break;
946
					case "cast128":
947
					$ph1alg = array( 'name' => 'cast128' );
948
					break;
949
					case "rijndael":
950
					$ph1alg = array( 'name' => 'aes', 'keylen' => '128' );
951
					break;
952
					case "rijndael 256":
953
					$ph1alg = array( 'name' => 'aes', 'keylen' => '256' );
954
					break;
955
				}
956

    
957
				$ph1ent['encryption-algorithm'] = $ph1alg;
958
				$ph1ent['hash-algorithm'] = $tunnel['p1']['hash-algorithm'];
959
				$ph1ent['dhgroup'] = $tunnel['p1']['dhgroup'];
960
				$ph1ent['lifetime'] = $tunnel['p1']['lifetime'];
961
				$ph1ent['authentication_method'] = $tunnel['p1']['authentication_method'];
962

    
963
				if (isset($tunnel['p1']['pre-shared-key']))
964
					$ph1ent['pre-shared-key'] = $tunnel['p1']['pre-shared-key'];
965
				if (isset($tunnel['p1']['cert']))
966
					$ph1ent['cert'] = $tunnel['p1']['cert'];
967
				if (isset($tunnel['p1']['peercert']))
968
					$ph1ent['peercert'] = $tunnel['p1']['peercert'];
969
				if (isset($tunnel['p1']['private-key']))
970
					$ph1ent['private-key'] = $tunnel['p1']['private-key'];
971

    
972
				$ph1ent['nat_traversal'] = "on";
973
				$ph1ent['dpd_enable'] = 1;
974
				$ph1ent['dpd_delay'] = 10;
975
				$ph1ent['dpd_maxfail'] = 5;
976

    
977
				$a_phase1[] = $ph1ent;
978
			}
979

    
980
			/* build new phase2 entry */
981

    
982
			$ph2ent = array();
983

    
984
			$ph2ent['ikeid'] = $ph1ent['ikeid'];
985

    
986
			if (isset($tunnel['disabled']))
987
				$ph1ent['disabled'] = $tunnel['disabled'];
988

    
989
			$ph2ent['descr'] = "phase2 for ".$tunnel['descr'];
990

    
991
			$type = "lan";
992
			if ($tunnel['local-subnet']['network'])
993
				$type = $tunnel['local-subnet']['network'];
994
			if ($tunnel['local-subnet']['address']) {
995
				list($address,$netbits) = explode("/",$tunnel['local-subnet']['address']);
996
				if (is_null($netbits))
997
					$type = "address";
998
				else
999
					$type = "network";
1000
			}
1001

    
1002
			switch ($type) {
1003
				case "address":
1004
				$ph2ent['localid'] = array('type' => $type,'address' => $address);
1005
				break;
1006
				case "network":
1007
				$ph2ent['localid'] = array('type' => $type,'address' => $address,'netbits' => $netbits);
1008
				break;
1009
				default:
1010
				$ph2ent['localid'] = array('type' => $type);
1011
				break;
1012
			}
1013

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

    
1017
			$ph2ent['protocol'] = $tunnel['p2']['protocol'];
1018

    
1019
			$aes_count = 0;
1020
			foreach( $tunnel['p2']['encryption-algorithm-option'] as $tunalg ) {
1021
				$aes_found = false;
1022
				switch ($tunalg) {
1023
					case "des":
1024
					$ph2alg = array( 'name' => 'des' );
1025
					break;
1026
					case "3des":
1027
					$ph2alg = array( 'name' => '3des' );
1028
					break;
1029
					case "blowfish":
1030
					$ph2alg = array( 'name' => 'blowfish', 'keylen' => 'auto'  );
1031
					break;
1032
					case "cast128":
1033
					$ph2alg = array( 'name' => 'cast128' );
1034
					break;
1035
					case "rijndael":
1036
					case "rijndael 256":
1037
					$ph2alg = array( 'name' => 'aes', 'keylen' => 'auto' );
1038
					$aes_found = true;
1039
					$aes_count++;
1040
					break;
1041
				}
1042

    
1043
				if( !$aes_found || ($aes_count < 2))
1044
					$ph2ent['encryption-algorithm-option'][] = $ph2alg;
1045
			}
1046

    
1047
			$ph2ent['hash-algorithm-option'] = $tunnel['p2']['hash-algorithm-option'];
1048
			$ph2ent['pfsgroup'] = $tunnel['p2']['pfsgroup'];
1049
			$ph2ent['lifetime'] = $tunnel['p2']['lifetime'];
1050

    
1051
			if (isset($tunnel['pinghost']['pinghost']))
1052
				$ph2ent['pinghost'] = $tunnel['pinghost'];
1053

    
1054
			$a_phase2[] = $ph2ent;
1055
		}
1056

    
1057
		unset($config['ipsec']['tunnel']);
1058
		$config['ipsec']['phase1'] = $a_phase1;
1059
		$config['ipsec']['phase2'] = $a_phase2;
1060
	}
1061
}
1062

    
1063

    
1064
function upgrade_047_to_048() {
1065
	global $config;
1066
	$config['dyndnses']['dyndns'] = array();
1067
	if (isset($config['dyndns']['enable'])) {
1068
		$tempdyn = array();
1069
		$tempdyn['enable'] = isset($config['dyndns']['enable']);
1070
		$tempdyn['type'] = $config['dyndns']['type'];
1071
		$tempdyn['wildcard'] = isset($config['dyndns']['wildcard']);
1072
		$tempdyn['usernamefld'] = $config['dyndns']['username'];
1073
		$tempdyn['passwordfld'] = $config['dyndns']['password'];
1074
		$tempdyn['host'] = $config['dyndns']['host'];
1075
		$tempdyn['mx'] = $config['dyndns']['mx'];		
1076
		$config['dyndnses']['dyndns'][] = $tempdyn;
1077
		unset($config['dyndns']);
1078
	}		
1079
	$config['dnsupdates']['dnsupdate'] = array();
1080
	if (isset($config['dnsupdate']['enable'])) {
1081
		$pconfig = array();
1082
		$pconfig['dnsupdate_enable'] = isset($config['dnsupdate']['enable']);
1083
		$pconfig['dnsupdate_host'] = $config['dnsupdate']['host'];
1084
		$pconfig['dnsupdate_ttl'] = $config['dnsupdate']['ttl'];
1085
		if (!$pconfig['dnsupdate_ttl'])
1086
			$pconfig['dnsupdate_ttl'] = 60;
1087
		$pconfig['dnsupdate_keydata'] = $config['dnsupdate']['keydata'];
1088
		$pconfig['dnsupdate_keyname'] = $config['dnsupdate']['keyname'];
1089
		$pconfig['dnsupdate_keytype'] = $config['dnsupdate']['keytype'];
1090
		if (!$pconfig['dnsupdate_keytype'])
1091
			$pconfig['dnsupdate_keytype'] = "zone";
1092
		$pconfig['dnsupdate_server'] = $config['dnsupdate']['server'];
1093
		$pconfig['dnsupdate_usetcp'] = isset($config['dnsupdate']['usetcp']);
1094
		$config['dnsupdates']['dnsupdate'][] = $pconfig;
1095
		unset($config['dnsupdate']);
1096
	}
1097

    
1098
	if (is_array($config['pppoe'])) {
1099
		$pconfig = array();
1100
		$pconfig['username'] = $config['pppoe']['username'];
1101
		$pconfig['password'] = $config['pppoe']['password'];
1102
		$pconfig['provider'] = $config['pppoe']['provider'];
1103
		$pconfig['ondemand'] = isset($config['pppoe']['ondemand']);
1104
		$pconfig['timeout'] = $config['pppoe']['timeout'];
1105
		unset($config['pppoe']);
1106
		$config['interfaces']['wan']['pppoe_username'] = $pconfig['username'];
1107
		$config['interfaces']['wan']['pppoe_password'] = $pconfig['password'];
1108
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1109
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
1110
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1111
	}
1112
	if (is_array($config['pptp'])) {
1113
		$pconfig = array();
1114
		$pconfig['username'] = $config['pptp']['username'];
1115
		$pconfig['password'] = $config['pptp']['password'];
1116
		$pconfig['provider'] = $config['pptp']['provider'];
1117
		$pconfig['ondemand'] = isset($config['pptp']['ondemand']);
1118
		$pconfig['timeout'] = $config['pptp']['timeout'];
1119
		unset($config['pptp']);
1120
		$config['interfaces']['wan']['pptp_username'] = $pconfig['username'];
1121
		$config['interfaces']['wan']['pptp_password'] = $pconfig['password'];
1122
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1123
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand'] );
1124
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1125
	}
1126
}
1127

    
1128

    
1129
function upgrade_048_to_049() {
1130
	global $config;
1131
	/* setup new all users group */
1132
	$all = array();
1133
	$all['name'] = "all";
1134
	$all['description'] = "All Users";
1135
	$all['scope'] = "system";
1136
	$all['gid'] = 1998;
1137
	$all['member'] = array();
1138

    
1139
	if (!is_array($config['system']['group']))
1140
		$config['system']['group'] = array();
1141

    
1142
	/* work around broken uid assignments */
1143
	$config['system']['nextuid'] = 2000;
1144
	foreach ($config['system']['user'] as & $user) {
1145
		if (isset($user['uid']) && !$user['uid'])
1146
			continue;
1147
		$user['uid'] = $config['system']['nextuid']++;
1148
	}
1149

    
1150
	/* work around broken gid assignments */
1151
	$config['system']['nextgid'] = 2000;
1152
	foreach ($config['system']['group'] as & $group) {
1153
		if ($group['name'] == $g['admin_group'])
1154
			$group['gid'] = 1999;
1155
		else
1156
			$group['gid'] = $config['system']['nextgid']++;
1157
	}
1158

    
1159
	/* build group membership information */
1160
	foreach ($config['system']['group'] as & $group) {
1161
		$group['member'] = array();
1162
		foreach ($config['system']['user'] as & $user) {
1163
			$groupnames = explode(",", $user['groupname']);
1164
			if (in_array($group['name'],$groupnames))
1165
				$group['member'][] = $user['uid'];
1166
		}
1167
	}
1168

    
1169
	/* reset user group information */
1170
	foreach ($config['system']['user'] as & $user) {
1171
		unset($user['groupname']);
1172
		$all['member'][] = $user['uid'];
1173
	}
1174

    
1175
	/* reset group scope information */
1176
	foreach ($config['system']['group'] as & $group)
1177
		if ($group['name'] != $g['admin_group'])
1178
		$group['scope'] = "user";
1179

    
1180
	/* insert new all group */
1181
	$groups = Array();
1182
	$groups[] = $all;
1183
	$groups = array_merge($config['system']['group'],$groups);
1184
	$config['system']['group'] = $groups;
1185
}
1186

    
1187

    
1188
function upgrade_049_to_050() {
1189
	global $config;
1190
	/* update user privileges */
1191
	foreach ($config['system']['user'] as & $user) {
1192
		$privs = array();
1193
		if (!is_array($user['priv'])) {
1194
			unset($user['priv']);
1195
			continue;
1196
		}
1197
		foreach ($user['priv'] as $priv) {
1198
			switch($priv['id']) {
1199
				case "hasshell":
1200
				$privs[] = "user-shell-access";
1201
				break;
1202
				case "copyfiles":
1203
				$privs[] = "user-copy-files";
1204
				break;
1205
			}
1206
		}
1207
		$user['priv'] = $privs;
1208
	}
1209

    
1210
	/* update group privileges */
1211
	foreach ($config['system']['group'] as & $group) {
1212
		$privs = array();
1213
		if (!is_array($group['pages'])) {
1214
			unset($group['pages']);
1215
			continue;
1216
		}
1217
		foreach ($group['pages'] as $page) {
1218
			$priv = map_page_privname($page);
1219
			if ($priv)
1220
				$privs[] = $priv;
1221
		}
1222
		unset($group['pages']);
1223
		$group['priv'] = $privs;
1224
	}
1225

    
1226
	/* sync all local account information */
1227
	local_sync_accounts();
1228
}
1229

    
1230

    
1231
function upgrade_050_to_051() {
1232
	global $config;
1233
	$pconfig = array();
1234
	$pconfig['desc'] = "Set to 0 to disable filtering on the incoming and outgoing member interfaces.";
1235
	$pconfig['tunable'] = "net.link.bridge.pfil_member";
1236
	$pconfig['value'] = "1";
1237
	$config['sysctl']['item'][] = $pconfig;
1238
	$pconfig = array();
1239
	$pconfig['desc'] = "Set to 1 to enable filtering on the bridge interface";
1240
	$pconfig['tunable'] = "net.link.bridge.pfil_bridge";
1241
	$pconfig['value'] = "0";
1242
	$config['sysctl']['item'][] = $pconfig;
1243

    
1244
	unset($config['bridge']);
1245

    
1246
	$convert_bridges = false;
1247
	foreach($config['interfaces'] as $intf) {
1248
		if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1249
			$config['bridges'] = array();
1250
			$config['bridges']['bridged'] = array();
1251
			$convert_bridges = true;
1252
			break;
1253
		}
1254
	}
1255
	if ($convert_bridges == true) {
1256
		$i = 0;
1257
		foreach ($config['interfaces'] as $ifr => &$intf) {
1258
			if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1259
				$nbridge = array();
1260
				$nbridge['members'] = "{$ifr},{$intf['bridge']}";
1261
				$nbridge['descr'] = "Converted bridged {$ifr}";
1262
				$nbridge['bridgeif'] = "bridge{$i}";
1263
				$config['bridges']['bridged'][] = $nbridge;
1264
				unset($intf['bridge']);
1265
				$i++;
1266
			}
1267
		}
1268
	}
1269
}
1270

    
1271

    
1272
function upgrade_051_to_052() {
1273
	global $config;
1274
	$config['openvpn'] = array();
1275
	if (!is_array($config['system']['ca']))
1276
		$config['system']['ca'] = array();
1277
	if (!is_array($config['system']['cert']))
1278
		$config['system']['cert'] = array();
1279

    
1280
	$vpnid = 1;
1281

    
1282
	/* openvpn server configurations */
1283
	if (is_array($config['installedpackages']['openvpnserver'])) {
1284
		$config['openvpn']['openvpn-server'] = array();
1285

    
1286
		$index = 1;
1287
		foreach($config['installedpackages']['openvpnserver']['config'] as $server) {
1288

    
1289
			if (!is_array($server))
1290
				continue;
1291

    
1292
			if ($server['auth_method'] == "pki") {
1293

    
1294
				/* create ca entry */
1295
				$ca = array();
1296
				$ca['refid'] = uniqid();
1297
				$ca['name'] = "OpenVPN Server CA #{$index}";
1298
				$ca['crt'] = $server['ca_cert'];
1299
				$ca['crl'] = $server['crl'];
1300
				$config['system']['ca'][] = $ca;
1301

    
1302
				/* create ca reference */
1303
				unset($server['ca_cert']);
1304
				unset($server['crl']);
1305
				$server['caref'] = $ca['refid'];
1306

    
1307
				/* create cert entry */
1308
				$cert = array();
1309
				$cert['refid'] = uniqid();
1310
				$cert['name'] = "OpenVPN Server Certificate #{$index}";
1311
				$cert['crt'] = $server['server_cert'];
1312
				$cert['prv'] = $server['server_key'];
1313
				$config['system']['cert'][] = $cert;
1314

    
1315
				/* create cert reference */
1316
				unset($server['server_cert']);
1317
				unset($server['server_key']);
1318
				$server['certref'] = $cert['refid'];
1319

    
1320
				$index++;
1321
			}
1322

    
1323
			/* determine operational mode */
1324
			if ($server['auth_method'] == 'pki') {
1325
				if($server['nopool']) {
1326
					$server['mode'] = "p2p_tls";
1327
				} else {
1328
					$server['mode'] = "server_tls";
1329
				}
1330
			} else {
1331
				$server['mode'] = "p2p_shared_key";
1332
			}
1333
			unset($server['auth_method']);
1334

    
1335
			/* modify configuration values */
1336
			$server['dh_length'] = 1024;
1337
			unset($server['dh_params']);
1338
			if (!$server['interface'])
1339
				$server['interface'] = 'wan';
1340
			$server['tunnel_network'] = $server['addresspool'];
1341
			unset($server['addresspool']);
1342
			if (isset($server['use_lzo'])) {
1343
				$server['compress'] = true;
1344
				unset($server['use_lzo']);
1345
			}
1346
			if ($server['nopool'])
1347
				$server['pool_enable'] = false;
1348
			else
1349
				$server['pool_enable'] = "yes";
1350
			unset($server['nopool']);
1351
			$server['dns_domain'] = $server['dhcp_domainname'];
1352
			unset($server['dhcp_domainname']);
1353
			$server['dns_server1'] = $server['dhcp_dns'];
1354
			unset($server['dhcp_dns']);
1355
			$server['ntp_server1'] = $server['dhcp_ntp'];
1356
			unset($server['dhcp_ntp']);
1357
			if ($server['dhcp_nbtdisable'])
1358
				$server['netbios_enable'] = false;
1359
			else
1360
				$server['netbios_enable'] = "yes";
1361
			unset($server['dhcp_nbtdisable']);
1362
			$server['netbios_ntype'] = $server['dhcp_nbttype'];
1363
			unset($server['dhcp_nbttype']);
1364
			$server['netbios_scope'] = $server['dhcp_nbtscope'];
1365
			unset($server['dhcp_nbtscope']);
1366
			$server['nbdd_server1'] = $server['dhcp_nbdd'];
1367
			unset($server['dhcp_nbdd']);
1368
			$server['wins_server1'] = $server['dhcp_wins'];
1369
			unset($server['dhcp_wins']);
1370

    
1371
			/* allocate vpnid */
1372
			$server['vpnid'] = $vpnid++;
1373

    
1374
			$config['openvpn']['openvpn-server'][] = $server;
1375
		}
1376
		unset($config['installedpackages']['openvpnserver']);
1377
	}
1378

    
1379
	/* openvpn client configurations */
1380
	if (is_array($config['installedpackages']['openvpnclient'])) {
1381
		$config['openvpn']['openvpn-client'] = array();
1382

    
1383
		$index = 1;
1384
		foreach($config['installedpackages']['openvpnclient']['config'] as $client) {
1385

    
1386
			if (!is_array($client))
1387
				continue;
1388

    
1389
			if ($client['auth_method'] == "pki") {
1390

    
1391
				/* create ca entry */
1392
				$ca = array();
1393
				$ca['refid'] = uniqid();
1394
				$ca['name'] = "OpenVPN Client CA #{$index}";
1395
				$ca['crt'] = $client['ca_cert'];
1396
				$ca['crl'] = $client['crl'];
1397
				$config['system']['ca'][] = $ca;
1398

    
1399
				/* create ca reference */
1400
				unset($client['ca_cert']);
1401
				unset($client['crl']);
1402
				$client['caref'] = $ca['refid'];
1403

    
1404
				/* create cert entry */
1405
				$cert = array();
1406
				$cert['refid'] = uniqid();
1407
				$cert['name'] = "OpenVPN Client Certificate #{$index}";
1408
				$cert['crt'] = $client['client_cert'];
1409
				$cert['prv'] = $client['client_key'];
1410
				$config['system']['cert'][] = $cert;
1411

    
1412
				/* create cert reference */
1413
				unset($client['client_cert']);
1414
				unset($client['client_key']);
1415
				$client['certref'] = $cert['refid'];
1416

    
1417
				$index++;
1418
			}
1419

    
1420
			/* determine operational mode */
1421
			if ($client['auth_method'] == 'pki')
1422
				$client['mode'] = "p2p_tls";
1423
			else
1424
				$client['mode'] = "p2p_shared_key";
1425
			unset($client['auth_method']);
1426

    
1427
			/* modify configuration values */
1428
			if (!$client['interface'])
1429
				$client['interface'] = 'wan';
1430
			$client['tunnel_network'] = $client['interface_ip'];
1431
			unset($client['interface_ip']);
1432
			$client['server_addr'] = $client['serveraddr'];
1433
			unset($client['serveraddr']);
1434
			$client['server_port'] = $client['serverport'];
1435
			unset($client['serverport']);
1436
			$client['proxy_addr'] = $client['poxy_hostname'];
1437
			unset($client['proxy_addr']);
1438
			if (isset($client['use_lzo'])) {
1439
				$client['compress'] = true;
1440
				unset($client['use_lzo']);
1441
			}
1442
			$client['resolve_retry'] = $client['infiniteresolvretry'];
1443
			unset($client['infiniteresolvretry']);
1444

    
1445
			/* allocate vpnid */
1446
			$client['vpnid'] = $vpnid++;
1447

    
1448
			$config['openvpn']['openvpn-client'][] = $client;
1449
		}
1450

    
1451
		unset($config['installedpackages']['openvpnclient']);
1452
	}
1453

    
1454
	/* openvpn client specific configurations */
1455
	if (is_array($config['installedpackages']['openvpncsc'])) {
1456
		$config['openvpn']['openvpn-csc'] = array();
1457

    
1458
		foreach($config['installedpackages']['openvpncsc']['config'] as $csc) {
1459

    
1460
			if (!is_array($csc))
1461
				continue;
1462

    
1463
			/* modify configuration values */
1464
			$csc['common_name'] = $csc['commonname'];
1465
			unset($csc['commonname']);
1466
			$csc['tunnel_network'] = $csc['ifconfig_push'];
1467
			unset($csc['ifconfig_push']);
1468
			$csc['dns_domain'] = $csc['dhcp_domainname'];
1469
			unset($csc['dhcp_domainname']);
1470
			$csc['dns_server1'] = $csc['dhcp_dns'];
1471
			unset($csc['dhcp_dns']);
1472
			$csc['ntp_server1'] = $csc['dhcp_ntp'];
1473
			unset($csc['dhcp_ntp']);
1474
			if ($csc['dhcp_nbtdisable'])
1475
				$csc['netbios_enable'] = false;
1476
			else
1477
				$csc['netbios_enable'] = "yes";
1478
			unset($csc['dhcp_nbtdisable']);
1479
			$csc['netbios_ntype'] = $csc['dhcp_nbttype'];
1480
			unset($csc['dhcp_nbttype']);
1481
			$csc['netbios_scope'] = $csc['dhcp_nbtscope'];
1482
			unset($csc['dhcp_nbtscope']);
1483
			$csc['nbdd_server1'] = $csc['dhcp_nbdd'];
1484
			unset($csc['dhcp_nbdd']);
1485
			$csc['wins_server1'] = $csc['dhcp_wins'];
1486
			unset($csc['dhcp_wins']);
1487

    
1488
			$config['openvpn']['openvpn-csc'][] = $csc;
1489
		}
1490

    
1491
		unset($config['installedpackages']['openvpncsc']);
1492
	}
1493

    
1494
	if (count($config['openvpn']['openvpn-server']) > 0 ||
1495
		count($config['openvpn']['openvpn-client']) > 0) {
1496
		$ovpnrule = array();
1497
                $ovpnrule['type'] = "pass";
1498
                $ovpnrule['interface'] = "openvpn";
1499
                $ovpnrule['statetype'] = "keep state";
1500
                $ovpnrule['source'] = array();
1501
                $ovpnrule['destination'] = array();
1502
                $ovpnrule['source']['any'] = true;
1503
                $ovpnrule['destination']['any'] = true;
1504
                $ovpnrule['descr'] = "Auto added OpenVPN rule from config upgrade.";
1505
		$config['filter']['rule'][] = $ovpnrule;
1506
	}
1507

    
1508
	/*
1509
		* FIXME: hack to keep things working with no installedpackages
1510
		* or carp array in the configuration data.
1511
		*/
1512
	if (!is_array($config['installedpackages']))
1513
		$config['installedpackages'] = array();
1514
	if (!is_array($config['installedpackages']['carp']))
1515
		$config['installedpackages']['carp'] = array();
1516

    
1517
}
1518

    
1519

    
1520
function upgrade_052_to_053() {
1521
	global $config;
1522
	if (!is_array($config['system']['ca']))
1523
		$config['system']['ca'] = array();
1524
	if (!is_array($config['system']['cert']))
1525
		$config['system']['cert'] = array();
1526

    
1527
	/* migrate advanced admin page webui ssl to certifcate mngr */
1528
	if ($config['system']['webgui']['certificate'] &&
1529
	$config['system']['webgui']['private-key']) {
1530

    
1531
		/* create cert entry */
1532
		$cert = array();
1533
		$cert['refid'] = uniqid();
1534
		$cert['name'] = "webConfigurator SSL Certificate";
1535
		$cert['crt'] = $config['system']['webgui']['certificate'];
1536
		$cert['prv'] = $config['system']['webgui']['private-key'];
1537
		$config['system']['cert'][] = $cert;
1538

    
1539
		/* create cert reference */
1540
		unset($config['system']['webgui']['certificate']);
1541
		unset($config['system']['webgui']['private-key']);
1542
		$config['system']['webgui']['ssl-certref'] = $cert['refid'];
1543
	}
1544

    
1545
	/* migrate advanced admin page ssh keys to user manager */
1546
	if ($config['system']['ssh']['authorizedkeys']) {
1547
		$admin_user =& getUserEntryByUID(0);
1548
		$admin_user['authorizedkeys'] = $config['system']['ssh']['authorizedkeys'];
1549
		unset($config['system']['ssh']['authorizedkeys']);
1550
	}
1551
}
1552

    
1553

    
1554
function upgrade_053_to_054() {
1555
	global $config;
1556
	if(is_array($config['load_balancer']['lbpool'])) {
1557
		$lbpool_arr = $config['load_balancer']['lbpool'];
1558
		$lbpool_srv_arr = array();
1559
		$gateway_group_arr = array();
1560
		$gateways = return_gateways_array();
1561
		foreach($lbpool_arr as $lbpool) {
1562
			if($lbpool['type'] == "gateway") {
1563
				$gateway_group['name'] = $lbpool['name'];
1564
				$gateway_group['descr'] = $lbpool['desc'];
1565
				$gateway_group['trigger'] = "down";
1566
				$gateway_group['item'] = array();
1567
				$i = 0;
1568
				foreach($lbpool['servers'] as $member) {
1569
					$split = split("\|", $member);
1570
					$interface = $split[0];
1571
					$monitor = $split[1];
1572
					if(is_ipaddr($monitor)) {
1573
						$config['interfaces'][$interface]['monitorip'] = "$monitor";
1574
					}
1575
					/* on static upgraded configuration we automatically prepend GW_ */
1576
					$static_name = "GW_" . strtoupper($interface);
1577
					if(is_array($gateways[$static_name])) {
1578
						$interface = $static_name;
1579
					}
1580
					/* on failover increment tier. Else always assign 1 */
1581
					if($lbpool['behaviour'] == "failover") {
1582
						$i++;
1583
					} else {
1584
						$i = 1;
1585
					}
1586
					$gateway_group['item'][] = "$interface|$i";
1587
				}
1588
				$gateway_group_arr[] = $gateway_group;
1589
			} else {
1590
				$lbpool_srv_arr[] = $lbpool;
1591
			}
1592
		}
1593
		$config['load_balancer']['lbpool'] = $lbpool_srv_arr;
1594
		$config['gateways']['gateway_group'] = $gateway_group_arr;
1595
	}
1596
	// Unset lbpool if we no longer have any server pools
1597
	if (count($lbpool_srv_arr) == 0) {
1598
		unset($config['load_balancer']['lbpool']);
1599
		if(count($config['load_balancer']) == 0) {
1600
			unset($config['load_balancer']);
1601
		}
1602
	} else {
1603
		$config['load_balancer']['lbpool'] = $lbpool_srv_arr;
1604
	}
1605
	// Only set the gateway group array if we converted any
1606
	if (count($gateway_group_arr) != 0) {
1607
		$config['gateways']['gateway_group'] = $gateway_group_arr;
1608
	}
1609
}
1610

    
1611

    
1612
function upgrade_054_to_055() {
1613
	global $config;
1614
	global $g;
1615

    
1616
	/* RRD files changed for quality, traffic and packets graphs */
1617
	ini_set("max_execution_time", "1800");
1618
	/* convert traffic RRD file */
1619
	global $parsedcfg, $listtags;
1620
	$listtags = array("ds", "v", "rra", "row");
1621

    
1622
	$rrddbpath = "/var/db/rrd/";
1623
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
1624

    
1625
	$rrdinterval = 60;
1626
	$valid = $rrdinterval * 2;
1627

    
1628
	/* Asume GigE for now */
1629
	$downstream = 125000000;
1630
	$upstream = 125000000;
1631

    
1632
	/* build a list of quality databases */
1633
	/* roundtrip has become delay */
1634
	function divide_delay($delayval) {
1635
		$delayval = floatval($delayval);
1636
		$delayval = ($delayval / 1000);
1637
		$delayval = " ". sprintf("%1.10e", $delayval) ." ";
1638
		return $delayval;
1639
	}
1640
	/* the roundtrip times need to be divided by 1000 to get seconds, really */
1641
	$databases = array();
1642
	exec("cd $rrddbpath;/usr/bin/find *-quality.rrd", $databases);
1643
	echo "done.\n";
1644
	rsort($databases);
1645
	foreach($databases as $database) {
1646
		$xmldump = "{$database}.old.xml";
1647
		$xmldumpnew = "{$database}.new.xml";
1648

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

    
1652
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
1653
		$rrdoldxml = file_get_contents("{$g['tmp_path']}/{$xmldump}");
1654
		$rrdold = xml2array($rrdoldxml, 1, "tag");
1655
		$rrdold = $rrdold['rrd'];
1656

    
1657
		$i = 0;
1658
		foreach($rrdold['rra'] as $rra) {
1659
			$l = 0;
1660
			foreach($rra['database']['row'] as $row) {
1661
				$vnew = divide_delay($row['v'][1]);
1662
				$rrdold['rra'][$i]['database']['row'][$l]['v'][1] = $vnew;
1663
				$l++;
1664
			}
1665
			$i++;
1666
		}
1667

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

    
1672
	}
1673
	/* let apinger recreate required files */
1674
	setup_gateways_monitor();
1675

    
1676
	/* build a list of traffic and packets databases */
1677
	$databases = array();
1678
	exec("cd $rrddbpath;/usr/bin/find *-traffic.rrd *-packets.rrd", $databases);
1679
	rsort($databases);
1680
	foreach($databases as $database) {
1681
		$databasetmp = "{$database}.tmp";
1682
		$xmldump = "{$database}.old.xml";
1683
		$xmldumptmp = "{$database}.tmp.xml";
1684
		$xmldumpnew = "{$database}.new.xml";
1685

    
1686
		echo "Migrate RRD database {$database} to new format \n";
1687
		/* rename DS source */
1688
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r in:inpass 2>&1");
1689
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r out:outpass 2>71");
1690

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

    
1694
		/* create new rrd database file */
1695
		$rrdcreate = "$rrdtool create {$g['tmp_path']}/{$databasetmp} --step $rrdinterval ";
1696
		$rrdcreate .= "DS:inpass:COUNTER:$valid:0:$downstream ";
1697
		$rrdcreate .= "DS:outpass:COUNTER:$valid:0:$upstream ";
1698
		$rrdcreate .= "DS:inblock:COUNTER:$valid:0:$downstream ";
1699
		$rrdcreate .= "DS:outblock:COUNTER:$valid:0:$upstream ";
1700
		$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
1701
		$rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
1702
		$rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
1703
		$rrdcreate .= "RRA:AVERAGE:0.5:720:3000 ";
1704

    
1705
		create_new_rrd("$rrdcreate");
1706
		/* create temporary xml from new RRD */
1707
		dump_rrd_to_xml("{$g['tmp_path']}/{$databasetmp}", "{$g['tmp_path']}/{$xmldumptmp}");
1708

    
1709
		$rrdoldxml = file_get_contents("{$g['tmp_path']}/{$xmldump}");
1710
		$rrdold = xml2array($rrdoldxml, 1, "tag");
1711
		$rrdold = $rrdold['rrd'];
1712

    
1713
		$rrdnewxml = file_get_contents("{$g['tmp_path']}/{$xmldumptmp}");
1714
		$rrdnew = xml2array($rrdnewxml, 1, "tag");
1715
		$rrdnew = $rrdnew['rrd'];
1716

    
1717
		/* remove any MAX RRA's. Not needed for traffic. */
1718
		$i = 0;
1719
		foreach ($rrdold['rra'] as $rra) {
1720
			if(trim($rra['cf']) == "MAX") {
1721
				unset($rrdold['rra'][$i]);
1722
			}
1723
			$i++;
1724
		}
1725

    
1726
		$rrdxmlarray = migrate_rrd_format($rrdold, $rrdnew);
1727
		$rrdxml = dump_xml_config_raw($rrdxmlarray, "rrd");
1728
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", $rrdxml);
1729
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
1730

    
1731
	}
1732
	enable_rrd_graphing();
1733
	echo "Updating configuration...";
1734
}
1735

    
1736

    
1737
function upgrade_055_to_056() {
1738
	global $config;
1739

    
1740
	if (!is_array($config['system']['ca']))
1741
		$config['system']['ca'] = array();
1742
	if (!is_array($config['system']['cert']))
1743
		$config['system']['cert'] = array();
1744

    
1745
	/* migrate ipsec ca's to cert manager */
1746
	if (is_array($config['ipsec']['cacert'])) {
1747
		foreach($config['ipsec']['cacert'] as & $cacert) {
1748
			$ca = array();
1749
			$ca['refid'] = uniqid();
1750
			if (is_array($cacert['cert']))
1751
				$ca['crt'] = $cacert['cert'][0];
1752
			else
1753
				$ca['crt'] = $cacert['cert'];
1754
			$ca['name'] = $cacert['ident'];
1755
			$config['system']['ca'][] = $ca;
1756
		}
1757
		unset($config['ipsec']['cacert']);
1758
	}
1759

    
1760
	/* migrate phase1 certificates to cert manager */
1761
	if (is_array($config['ipsec']['phase1'])) {
1762
		foreach($config['ipsec']['phase1'] as & $ph1ent) {
1763
			$cert = array();
1764
			$cert['refid'] = uniqid();
1765
			$cert['name'] = "IPsec Peer {$ph1ent['remote-gateway']} Certificate";
1766
			if (is_array($ph1ent['cert']))
1767
				$cert['crt'] = $ph1ent['cert'][0];
1768
			else
1769
				$cert['crt'] = $ph1ent['cert'];
1770
			$cert['prv'] = $ph1ent['private-key'];
1771
			$config['system']['cert'][] = $cert;
1772
			$ph1ent['certref'] = $cert['refid'];
1773
			if ($ph1ent['cert'])
1774
				unset($ph1ent['cert']);
1775
			if ($ph1ent['private-key'])
1776
				unset($ph1ent['private-key']);
1777
			if ($ph1ent['peercert'])
1778
				unset($ph1ent['peercert']);
1779
		}
1780
	}
1781
}
1782

    
1783

    
1784
function upgrade_056_to_057() {
1785
	global $config;
1786
	/* migrate captivate portal to user manager */
1787
	if (is_array($config['captiveportal']['user'])) {
1788
		foreach($config['captiveportal']['user'] as $user) {
1789
			// avoid user conflicts
1790
			if ($config['system']['user'][$user['name']])
1791
				continue;
1792
			$user['scope'] = "user";
1793
			if (isset($user['expirationdate'])) {
1794
				$user['expires'] = $user['expirationdate'];
1795
				unset($user['expirationdate']);
1796
			}
1797
			if (isset($user['password'])) {
1798
				$user['md5-hash'] = $user['password'];
1799
				unset($user['password']);
1800
			}
1801
			$config['system']['user'][] = $user;
1802
		}
1803
		unset($config['captiveportal']['user']);
1804
	}
1805
}
1806

    
1807
function upgrade_057_to_058() {
1808
	global $config;
1809
	/* set all phase2 entries to tunnel mode */
1810
	if (is_array($config['ipsec']['phase2']))
1811
		foreach($config['ipsec']['phase2'] as & $ph2ent)
1812
			$ph2ent['mode'] = 'tunnel';
1813
}
1814

    
1815
function upgrade_058_to_059() {
1816
	global $config;
1817

    
1818
	if (is_array($config['schedules']['schedule'])) {
1819
		foreach ($config['schedules']['schedule'] as & $schedl)
1820
			$schedl['schedlabel'] = uniqid();
1821
	}
1822
}
1823

    
1824
function upgrade_059_to_060() {
1825
	global $config;
1826
	require_once("/etc/inc/certs.inc");
1827
	if (is_array($config['system']['ca'])) {
1828
		/* Locate issuer for all CAs */
1829
		foreach ($config['system']['ca'] as & $ca) {
1830
			$subject = cert_get_subject($ca['crt']);
1831
			$issuer = cert_get_issuer($ca['crt']);
1832
			if($issuer <> $subject) {
1833
				$issuer_crt =& lookup_ca_by_subject($issuer);
1834
				if($issuer_crt)
1835
					$ca['caref'] = $issuer_crt['refid'];
1836
			}
1837
		}
1838
		
1839
		/* Locate issuer for all certificates */
1840
		if (is_array($config['system']['cert'])) {
1841
			foreach ($config['system']['cert'] as & $cert) {
1842
				$subject = cert_get_subject($cert['crt']);
1843
				$issuer = cert_get_issuer($cert['crt']);
1844
				if($issuer <> $subject) {
1845
					$issuer_crt =& lookup_ca_by_subject($issuer);
1846
					if($issuer_crt)
1847
						$cert['caref'] = $issuer_crt['refid'];
1848
				}
1849
			}
1850
		}
1851
	}
1852
}
1853

    
1854

    
1855

    
1856
?>
(40-40/50)