Project

General

Profile

Download (110 KB) Statistics
| Branch: | Tag: | Revision:
1 791bcfd4 Bill Marquette
<?php
2
/*
3 ce77a9c4 Phil Davis
	upgrade_config.inc
4 a1a4a22b Scott Ullrich
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@gmail.com>
5 791bcfd4 Bill Marquette
	All rights reserved.
6
7
	originally part of m0n0wall (http://m0n0.ch/wall)
8 a1a4a22b Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9 791bcfd4 Bill Marquette
	All rights reserved.
10
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
14 ce77a9c4 Phil Davis
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 791bcfd4 Bill Marquette
17
	2. Redistributions in binary form must reproduce the above copyright
18 ce77a9c4 Phil Davis
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20 791bcfd4 Bill Marquette
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25 ce77a9c4 Phil Davis
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 791bcfd4 Bill Marquette
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31 ce77a9c4 Phil Davis
*/
32 791bcfd4 Bill Marquette
33 523855b0 Scott Ullrich
/*
34
	pfSense_BUILDER_BINARIES:	/usr/bin/find	/bin/cd	/usr/local/bin/rrdtool	/usr/bin/nice
35
	pfSense_MODULE:	config
36
*/
37 791bcfd4 Bill Marquette
38 751533a2 Phil Davis
if (!function_exists("dump_rrd_to_xml")) {
39 901aa044 Scott Ullrich
	require("rrd.inc");
40 751533a2 Phil Davis
}
41 901aa044 Scott Ullrich
42 791bcfd4 Bill Marquette
/* Upgrade functions must be named:
43
*    upgrade_XXX_to_YYY
44
	* where XXX == previous version, zero padded, and YYY == next version, zero padded
45
	*/
46
function upgrade_010_to_011() {
47
	global $config;
48
	$opti = 1;
49
	$ifmap = array('lan' => 'lan', 'wan' => 'wan', 'pptp' => 'pptp');
50
51
	/* convert DMZ to optional, if necessary */
52
	if (isset($config['interfaces']['dmz'])) {
53
54
		$dmzcfg = &$config['interfaces']['dmz'];
55
56
		if ($dmzcfg['if']) {
57
			$config['interfaces']['opt' . $opti] = array();
58
			$optcfg = &$config['interfaces']['opt' . $opti];
59
60
			$optcfg['enable'] = $dmzcfg['enable'];
61
			$optcfg['descr'] = "DMZ";
62
			$optcfg['if'] = $dmzcfg['if'];
63
			$optcfg['ipaddr'] = $dmzcfg['ipaddr'];
64
			$optcfg['subnet'] = $dmzcfg['subnet'];
65
66
			$ifmap['dmz'] = "opt" . $opti;
67
			$opti++;
68
		}
69
70
		unset($config['interfaces']['dmz']);
71
	}
72
73
	/* convert WLAN1/2 to optional, if necessary */
74
	for ($i = 1; isset($config['interfaces']['wlan' . $i]); $i++) {
75
76
		if (!$config['interfaces']['wlan' . $i]['if']) {
77
			unset($config['interfaces']['wlan' . $i]);
78
			continue;
79
		}
80
81
		$wlancfg = &$config['interfaces']['wlan' . $i];
82
		$config['interfaces']['opt' . $opti] = array();
83
		$optcfg = &$config['interfaces']['opt' . $opti];
84
85
		$optcfg['enable'] = $wlancfg['enable'];
86
		$optcfg['descr'] = "WLAN" . $i;
87
		$optcfg['if'] = $wlancfg['if'];
88
		$optcfg['ipaddr'] = $wlancfg['ipaddr'];
89
		$optcfg['subnet'] = $wlancfg['subnet'];
90
		$optcfg['bridge'] = $wlancfg['bridge'];
91
92
		$optcfg['wireless'] = array();
93
		$optcfg['wireless']['mode'] = $wlancfg['mode'];
94
		$optcfg['wireless']['ssid'] = $wlancfg['ssid'];
95
		$optcfg['wireless']['channel'] = $wlancfg['channel'];
96
		$optcfg['wireless']['wep'] = $wlancfg['wep'];
97
98
		$ifmap['wlan' . $i] = "opt" . $opti;
99
100
		unset($config['interfaces']['wlan' . $i]);
101
		$opti++;
102
	}
103
104
	/* convert filter rules */
105
	$n = count($config['filter']['rule']);
106
	for ($i = 0; $i < $n; $i++) {
107
108
		$fr = &$config['filter']['rule'][$i];
109
110
		/* remap interface */
111 751533a2 Phil Davis
		if (array_key_exists($fr['interface'], $ifmap)) {
112 791bcfd4 Bill Marquette
			$fr['interface'] = $ifmap[$fr['interface']];
113 751533a2 Phil Davis
		} else {
114 791bcfd4 Bill Marquette
			/* remove the rule */
115 4b48d1b9 Carlos Eduardo Ramos
			printf(gettext("%sWarning: filter rule removed " .
116
				"(interface '%s' does not exist anymore)."), "\n", $fr['interface']);
117 791bcfd4 Bill Marquette
			unset($config['filter']['rule'][$i]);
118
			continue;
119
		}
120
121
		/* remap source network */
122
		if (isset($fr['source']['network'])) {
123 751533a2 Phil Davis
			if (array_key_exists($fr['source']['network'], $ifmap)) {
124 791bcfd4 Bill Marquette
				$fr['source']['network'] = $ifmap[$fr['source']['network']];
125 751533a2 Phil Davis
			} else {
126 791bcfd4 Bill Marquette
				/* remove the rule */
127 4b48d1b9 Carlos Eduardo Ramos
				printf(gettext("%sWarning: filter rule removed " .
128
					"(source network '%s' does not exist anymore)."), "\n", $fr['source']['network']);
129 791bcfd4 Bill Marquette
				unset($config['filter']['rule'][$i]);
130
				continue;
131
			}
132
		}
133
134
		/* remap destination network */
135
		if (isset($fr['destination']['network'])) {
136 751533a2 Phil Davis
			if (array_key_exists($fr['destination']['network'], $ifmap)) {
137 791bcfd4 Bill Marquette
				$fr['destination']['network'] = $ifmap[$fr['destination']['network']];
138 751533a2 Phil Davis
			} else {
139 791bcfd4 Bill Marquette
				/* remove the rule */
140 4b48d1b9 Carlos Eduardo Ramos
				printf(gettext("%sWarning: filter rule removed " .
141
					"(destination network '%s' does not exist anymore)."), "\n", $fr['destination']['network']);
142 791bcfd4 Bill Marquette
				unset($config['filter']['rule'][$i]);
143
				continue;
144
			}
145
		}
146
	}
147
148
	/* convert shaper rules */
149
	$n = count($config['pfqueueing']['rule']);
150 751533a2 Phil Davis
	if (is_array($config['pfqueueing']['rule'])) {
151
		for ($i = 0; $i < $n; $i++) {
152 791bcfd4 Bill Marquette
153 751533a2 Phil Davis
			$fr = &$config['pfqueueing']['rule'][$i];
154 791bcfd4 Bill Marquette
155 751533a2 Phil Davis
			/* remap interface */
156
			if (array_key_exists($fr['interface'], $ifmap)) {
157
				$fr['interface'] = $ifmap[$fr['interface']];
158
			} else {
159 791bcfd4 Bill Marquette
				/* remove the rule */
160 4d511e5b Renato Botelho
				printf(gettext("%sWarning: traffic shaper rule removed " .
161 751533a2 Phil Davis
					"(interface '%s' does not exist anymore)."), "\n", $fr['interface']);
162 791bcfd4 Bill Marquette
				unset($config['pfqueueing']['rule'][$i]);
163
				continue;
164
			}
165
166 751533a2 Phil Davis
			/* remap source network */
167
			if (isset($fr['source']['network'])) {
168
				if (array_key_exists($fr['source']['network'], $ifmap)) {
169
					$fr['source']['network'] = $ifmap[$fr['source']['network']];
170
				} else {
171
					/* remove the rule */
172
					printf(gettext("%sWarning: traffic shaper rule removed " .
173
						"(source network '%s' does not exist anymore)."), "\n", $fr['source']['network']);
174
					unset($config['pfqueueing']['rule'][$i]);
175
					continue;
176
				}
177
			}
178
179
			/* remap destination network */
180
			if (isset($fr['destination']['network'])) {
181
				if (array_key_exists($fr['destination']['network'], $ifmap)) {
182
					$fr['destination']['network'] = $ifmap[$fr['destination']['network']];
183
				} else {
184
					/* remove the rule */
185
					printf(gettext("%sWarning: traffic shaper rule removed " .
186
						"(destination network '%s' does not exist anymore)."), "\n", $fr['destination']['network']);
187
					unset($config['pfqueueing']['rule'][$i]);
188
					continue;
189
				}
190 791bcfd4 Bill Marquette
			}
191
		}
192
	}
193
}
194
195
196
function upgrade_011_to_012() {
197
	global $config;
198
	/* move LAN DHCP server config */
199
	$tmp = $config['dhcpd'];
200
	$config['dhcpd'] = array();
201
	$config['dhcpd']['lan'] = $tmp;
202
203
	/* encrypt password */
204
	$config['system']['password'] = crypt($config['system']['password']);
205
}
206
207
208
function upgrade_012_to_013() {
209
	global $config;
210
	/* convert advanced outbound NAT config */
211
	for ($i = 0; isset($config['nat']['advancedoutbound']['rule'][$i]); $i++) {
212
		$curent = &$config['nat']['advancedoutbound']['rule'][$i];
213
		$src = $curent['source'];
214
		$curent['source'] = array();
215
		$curent['source']['network'] = $src;
216
		$curent['destination'] = array();
217
		$curent['destination']['any'] = true;
218
	}
219
220
	/* add an explicit type="pass" to all filter rules to make things consistent */
221
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++) {
222
		$config['filter']['rule'][$i]['type'] = "pass";
223
	}
224
}
225
226
227
function upgrade_013_to_014() {
228
	global $config;
229
	/* convert shaper rules (make pipes) */
230
	if (is_array($config['pfqueueing']['rule'])) {
231
		$config['pfqueueing']['pipe'] = array();
232
233
		for ($i = 0; isset($config['pfqueueing']['rule'][$i]); $i++) {
234
			$curent = &$config['pfqueueing']['rule'][$i];
235
236
			/* make new pipe and associate with this rule */
237
			$newpipe = array();
238
			$newpipe['descr'] = $curent['descr'];
239
			$newpipe['bandwidth'] = $curent['bandwidth'];
240
			$newpipe['delay'] = $curent['delay'];
241
			$newpipe['mask'] = $curent['mask'];
242
			$config['pfqueueing']['pipe'][$i] = $newpipe;
243
244
			$curent['targetpipe'] = $i;
245
246
			unset($curent['bandwidth']);
247
			unset($curent['delay']);
248
			unset($curent['mask']);
249
		}
250
	}
251
}
252
253
254
function upgrade_014_to_015() {
255
	global $config;
256
	/* Default route moved */
257 751533a2 Phil Davis
	if (isset($config['interfaces']['wan']['gateway'])) {
258
		if ($config['interfaces']['wan']['gateway'] <> "") {
259 839966e3 Phil Davis
			$config['system']['gateway'] = $config['interfaces']['wan']['gateway'];
260 751533a2 Phil Davis
		}
261
	}
262 791bcfd4 Bill Marquette
	unset($config['interfaces']['wan']['gateway']);
263
264
	/* Queues are no longer interface specific */
265 751533a2 Phil Davis
	if (isset($config['interfaces']['lan']['schedulertype'])) {
266 791bcfd4 Bill Marquette
		unset($config['interfaces']['lan']['schedulertype']);
267 751533a2 Phil Davis
	}
268
	if (isset($config['interfaces']['wan']['schedulertype'])) {
269 791bcfd4 Bill Marquette
		unset($config['interfaces']['wan']['schedulertype']);
270 751533a2 Phil Davis
	}
271 791bcfd4 Bill Marquette
272
	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
273 751533a2 Phil Davis
		if (isset($config['interfaces']['opt' . $i]['schedulertype'])) {
274 791bcfd4 Bill Marquette
			unset($config['interfaces']['opt' . $i]['schedulertype']);
275 751533a2 Phil Davis
		}
276 791bcfd4 Bill Marquette
	}
277
}
278
279
280
function upgrade_015_to_016() {
281
	global $config;
282
	/* Alternate firmware URL moved */
283
	if (isset($config['system']['firmwareurl']) && isset($config['system']['firmwarename'])) { // Only convert if *both* are defined.
284
		$config['system']['alt_firmware_url'] = array();
285
		$config['system']['alt_firmware_url']['enabled'] = "";
286
		$config['system']['alt_firmware_url']['firmware_base_url'] = $config['system']['firmwareurl'];
287
		$config['system']['alt_firmware_url']['firmware_filename'] = $config['system']['firmwarename'];
288
		unset($config['system']['firmwareurl'], $config['system']['firmwarename']);
289
	} else {
290
		unset($config['system']['firmwareurl'], $config['system']['firmwarename']);
291
	}
292
}
293
294
295
function upgrade_016_to_017() {
296
	global $config;
297
	/* wipe previous shaper configuration */
298
	unset($config['shaper']['queue']);
299
	unset($config['shaper']['rule']);
300
	unset($config['interfaces']['wan']['bandwidth']);
301
	unset($config['interfaces']['wan']['bandwidthtype']);
302
	unset($config['interfaces']['lan']['bandwidth']);
303
	unset($config['interfaces']['lan']['bandwidthtype']);
304
	$config['shaper']['enable'] = FALSE;
305
}
306
307
308
function upgrade_017_to_018() {
309
	global $config;
310 751533a2 Phil Davis
	if (isset($config['proxyarp']) && is_array($config['proxyarp']['proxyarpnet'])) {
311 791bcfd4 Bill Marquette
		$proxyarp = &$config['proxyarp']['proxyarpnet'];
312 751533a2 Phil Davis
		foreach ($proxyarp as $arpent) {
313 791bcfd4 Bill Marquette
			$vip = array();
314
			$vip['mode'] = "proxyarp";
315
			$vip['interface'] = $arpent['interface'];
316
			$vip['descr'] = $arpent['descr'];
317
			if (isset($arpent['range'])) {
318
				$vip['range'] = $arpent['range'];
319
				$vip['type'] = "range";
320
			} else {
321
				$subnet = explode('/', $arpent['network']);
322
				$vip['subnet'] = $subnet[0];
323
				if (isset($subnet[1])) {
324
					$vip['subnet_bits'] = $subnet[1];
325
					$vip['type'] = "network";
326
				} else {
327
					$vip['subnet_bits'] = "32";
328
					$vip['type'] = "single";
329
				}
330
			}
331
			$config['virtualip']['vip'][] = $vip;
332
		}
333
		unset($config['proxyarp']);
334
	}
335 751533a2 Phil Davis
	if (isset($config['installedpackages']) && isset($config['installedpackages']['carp']) && is_array($config['installedpackages']['carp']['config'])) {
336 791bcfd4 Bill Marquette
		$carp = &$config['installedpackages']['carp']['config'];
337 751533a2 Phil Davis
		foreach ($carp as $carpent) {
338 791bcfd4 Bill Marquette
			$vip = array();
339
			$vip['mode'] = "carp";
340
			$vip['interface'] = "AUTO";
341 4d511e5b Renato Botelho
			$vip['descr'] = sprintf(gettext("CARP vhid %s"), $carpent['vhid']);
342 791bcfd4 Bill Marquette
			$vip['type'] = "single";
343
			$vip['vhid'] = $carpent['vhid'];
344
			$vip['advskew'] = $carpent['advskew'];
345
			$vip['password'] = $carpent['password'];
346
			$vip['subnet'] = $carpent['ipaddress'];
347
			$vip['subnet_bits'] = $carpent['netmask'];
348
			$config['virtualip']['vip'][] = $vip;
349
		}
350
		unset($config['installedpackages']['carp']);
351
	}
352
	/* Server NAT is no longer needed */
353
	unset($config['nat']['servernat']);
354
355
	/* enable SSH */
356
	if ($config['version'] == "1.8") {
357
		$config['system']['sshenabled'] = true;
358
	}
359
}
360
361
362
function upgrade_018_to_019() {
363
	global $config;
364
	$config['theme']="metallic";
365
}
366
367
368
function upgrade_019_to_020() {
369
	global $config;
370 751533a2 Phil Davis
	if (is_array($config['ipsec']['tunnel'])) {
371 791bcfd4 Bill Marquette
		reset($config['ipsec']['tunnel']);
372
		while (list($index, $tunnel) = each($config['ipsec']['tunnel'])) {
373
			/* Sanity check on required variables */
374
			/* This fixes bogus <tunnel> entries - remnant of bug #393 */
375
			if (!isset($tunnel['local-subnet']) && !isset($tunnel['remote-subnet'])) {
376
				unset($config['ipsec']['tunnel'][$tunnel]);
377
			}
378
		}
379
	}
380
}
381
382
function upgrade_020_to_021() {
383
	global $config;
384
	/* shaper scheduler moved */
385 751533a2 Phil Davis
	if (isset($config['system']['schedulertype'])) {
386 791bcfd4 Bill Marquette
		$config['shaper']['schedulertype'] = $config['system']['schedulertype'];
387
		unset($config['system']['schedulertype']);
388
	}
389
}
390
391
392
function upgrade_021_to_022() {
393
	global $config;
394
	/* move gateway to wan interface */
395
	$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
396
}
397
398
function upgrade_022_to_023() {
399
	global $config;
400 751533a2 Phil Davis
	if (isset($config['shaper'])) {
401 791bcfd4 Bill Marquette
		/* wipe previous shaper configuration */
402
		unset($config['shaper']);
403
	}
404
}
405
406
407
function upgrade_023_to_024() {
408
	global $config;
409
}
410
411
412
function upgrade_024_to_025() {
413
	global $config;
414
	$config['interfaces']['wan']['use_rrd_gateway'] = $config['system']['use_rrd_gateway'];
415
	unset($config['system']['use_rrd_gateway']);
416
}
417
418
419
function upgrade_025_to_026() {
420
	global $config;
421
	$cron_item = array();
422
	$cron_item['minute'] = "0";
423
	$cron_item['hour'] = "*";
424
	$cron_item['mday'] = "*";
425
	$cron_item['month'] = "*";
426
	$cron_item['wday'] = "*";
427
	$cron_item['who'] = "root";
428
	$cron_item['command'] = "/usr/bin/nice -n20 newsyslog";
429
430
	$config['cron']['item'][] = $cron_item;
431
432
	$cron_item = array();
433
	$cron_item['minute'] = "1,31";
434
	$cron_item['hour'] = "0-5";
435
	$cron_item['mday'] = "*";
436
	$cron_item['month'] = "*";
437
	$cron_item['wday'] = "*";
438
	$cron_item['who'] = "root";
439
	$cron_item['command'] = "/usr/bin/nice -n20 adjkerntz -a";
440
441
	$config['cron']['item'][] = $cron_item;
442
443
	$cron_item = array();
444
	$cron_item['minute'] = "1";
445
	$cron_item['hour'] = "*";
446
	$cron_item['mday'] = "1";
447
	$cron_item['month'] = "*";
448
	$cron_item['wday'] = "*";
449
	$cron_item['who'] = "root";
450
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.update_bogons.sh";
451
452
	$config['cron']['item'][] = $cron_item;
453
454
	$cron_item = array();
455
	$cron_item['minute'] = "*/60";
456
	$cron_item['hour'] = "*";
457
	$cron_item['mday'] = "*";
458
	$cron_item['month'] = "*";
459
	$cron_item['wday'] = "*";
460
	$cron_item['who'] = "root";
461
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 sshlockout";
462
463
	$config['cron']['item'][] = $cron_item;
464
465
	$cron_item = array();
466
	$cron_item['minute'] = "1";
467
	$cron_item['hour'] = "1";
468
	$cron_item['mday'] = "*";
469
	$cron_item['month'] = "*";
470
	$cron_item['wday'] = "*";
471
	$cron_item['who'] = "root";
472
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.dyndns.update";
473
474
	$config['cron']['item'][] = $cron_item;
475
476
	$cron_item = array();
477
	$cron_item['minute'] = "*/60";
478
	$cron_item['hour'] = "*";
479
	$cron_item['mday'] = "*";
480
	$cron_item['month'] = "*";
481
	$cron_item['wday'] = "*";
482
	$cron_item['who'] = "root";
483
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 virusprot";
484
485
	$config['cron']['item'][] = $cron_item;
486
487
	$cron_item = array();
488
	$cron_item['minute'] = "*/60";
489
	$cron_item['hour'] = "*";
490
	$cron_item['mday'] = "*";
491
	$cron_item['month'] = "*";
492
	$cron_item['wday'] = "*";
493
	$cron_item['who'] = "root";
494
	$cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/expiretable -t 1800 snort2c";
495
496
	$config['cron']['item'][] = $cron_item;
497
}
498
499
500
function upgrade_026_to_027() {
501
	global $config;
502
}
503
504
505
function upgrade_027_to_028() {
506
	global $config;
507
}
508
509
510
function upgrade_028_to_029() {
511
	global $config;
512
	$rule_item = array();
513
	$a_filter = &$config['filter']['rule'];
514
	$rule_item['interface'] = "enc0";
515
	$rule_item['type'] = "pass";
516
	$rule_item['source']['any'] = true;
517
	$rule_item['destination']['any'] = true;
518 4d511e5b Renato Botelho
	$rule_item['descr'] = gettext("Permit IPsec traffic.");
519 791bcfd4 Bill Marquette
	$rule_item['statetype'] = "keep state";
520
	$a_filter[] = $rule_item;
521
}
522
523
524
function upgrade_029_to_030() {
525
	global $config;
526
	/* enable the rrd config setting by default */
527
	$config['rrd']['enable'] = true;
528
}
529
530
531
function upgrade_030_to_031() {
532
	global $config;
533
	/* Insert upgrade code here */
534
}
535
536
537
function upgrade_031_to_032() {
538
	global $config;
539
	/* Insert upgrade code here */
540
}
541
542
543
function upgrade_032_to_033() {
544
	global $config;
545
	/* Insert upgrade code here */
546
}
547
548
549
function upgrade_033_to_034() {
550
	global $config;
551
	/* Insert upgrade code here */
552
}
553
554
555
function upgrade_034_to_035() {
556
	global $config;
557
	/* Insert upgrade code here */
558
}
559
560
561
function upgrade_035_to_036() {
562
	global $config;
563
	/* Insert upgrade code here */
564
}
565
566
567
function upgrade_036_to_037() {
568
	global $config;
569
	/* Insert upgrade code here */
570
}
571
572
573
function upgrade_037_to_038() {
574
	global $config;
575 db7f618b Seth Mos
	/* Insert upgrade code here */
576 791bcfd4 Bill Marquette
}
577
578
579
function upgrade_038_to_039() {
580
	global $config;
581 ef026950 Ermal Lu?i
	/* Insert upgrade code here */
582 791bcfd4 Bill Marquette
}
583
584
585
function upgrade_039_to_040() {
586 879f7db7 Erik Fonnesbeck
	global $config, $g;
587 791bcfd4 Bill Marquette
	$config['system']['webgui']['auth_method'] = "session";
588
	$config['system']['webgui']['backing_method'] = "htpasswd";
589
590
	if (isset ($config['system']['username'])) {
591
		$config['system']['group'] = array();
592
		$config['system']['group'][0]['name'] = "admins";
593 4d511e5b Renato Botelho
		$config['system']['group'][0]['description'] = gettext("System Administrators");
594 791bcfd4 Bill Marquette
		$config['system']['group'][0]['scope'] = "system";
595 ebcdcaaa jim-p
		$config['system']['group'][0]['priv'] = "page-all";
596 791bcfd4 Bill Marquette
		$config['system']['group'][0]['home'] = "index.php";
597
		$config['system']['group'][0]['gid'] = "110";
598
599
		$config['system']['user'] = array();
600
		$config['system']['user'][0]['name'] = "{$config['system']['username']}";
601 9ff73b79 jim-p
		$config['system']['user'][0]['descr'] = "System Administrator";
602 791bcfd4 Bill Marquette
		$config['system']['user'][0]['scope'] = "system";
603
		$config['system']['user'][0]['groupname'] = "admins";
604
		$config['system']['user'][0]['password'] = "{$config['system']['password']}";
605
		$config['system']['user'][0]['uid'] = "0";
606 6d8e6b22 jim-p
		/* Ensure that we follow what this new "admin" username should be in the session. */
607
		$_SESSION["Username"] = "{$config['system']['username']}";
608 791bcfd4 Bill Marquette
609
		$config['system']['user'][0]['priv'] = array();
610
		$config['system']['user'][0]['priv'][0]['id'] = "lockwc";
611
		$config['system']['user'][0]['priv'][0]['name'] = "Lock webConfigurator";
612 4d511e5b Renato Botelho
		$config['system']['user'][0]['priv'][0]['descr'] = gettext("Indicates whether this user will lock access to the webConfigurator for other users.");
613 791bcfd4 Bill Marquette
		$config['system']['user'][0]['priv'][1]['id'] = "lock-ipages";
614
		$config['system']['user'][0]['priv'][1]['name'] = "Lock individual pages";
615 4d511e5b Renato Botelho
		$config['system']['user'][0]['priv'][1]['descr'] = gettext("Indicates whether this user will lock individual HTML pages after having accessed a particular page (the lock will be freed if the user leaves or saves the page form).");
616 791bcfd4 Bill Marquette
		$config['system']['user'][0]['priv'][2]['id'] = "hasshell";
617
		$config['system']['user'][0]['priv'][2]['name'] = "Has shell access";
618 4d511e5b Renato Botelho
		$config['system']['user'][0]['priv'][2]['descr'] = gettext("Indicates whether this user is able to login for example via SSH.");
619 791bcfd4 Bill Marquette
		$config['system']['user'][0]['priv'][3]['id'] = "copyfiles";
620
		$config['system']['user'][0]['priv'][3]['name'] = "Is allowed to copy files";
621 4d511e5b Renato Botelho
		$config['system']['user'][0]['priv'][3]['descr'] = sprintf(gettext("Indicates whether this user is allowed to copy files onto the %s appliance via SCP/SFTP. If you are going to use this privilege, you must install scponly on the appliance (Hint: pkg_add -r scponly)."), $g['product_name']);
622 791bcfd4 Bill Marquette
		$config['system']['user'][0]['priv'][4]['id'] = "isroot";
623
		$config['system']['user'][0]['priv'][4]['name'] = "Is root user";
624 4d511e5b Renato Botelho
		$config['system']['user'][0]['priv'][4]['descr'] = gettext("This user is associated with the UNIX root user (you should associate this privilege only with one single user).");
625 791bcfd4 Bill Marquette
626
		$config['system']['nextuid'] = "111";
627
		$config['system']['nextgid'] = "111";
628
629
		/* wipe previous auth configuration */
630
		unset ($config['system']['username']);
631
		unset ($config['system']['password']);
632
	}
633
}
634
635
function upgrade_040_to_041() {
636
	global $config;
637 751533a2 Phil Davis
	if (!$config['sysctl']) {
638 791bcfd4 Bill Marquette
		$config['sysctl']['item'] = array();
639
640
		$config['sysctl']['item'][0]['tunable'] = "net.inet.tcp.blackhole";
641 4816e5ca Renato Botelho
		$config['sysctl']['item'][0]['descr'] =    gettext("Drop packets to closed TCP ports without returning a RST");
642 908c4eea sullrich
		$config['sysctl']['item'][0]['value'] =   "default";
643 791bcfd4 Bill Marquette
644
		$config['sysctl']['item'][1]['tunable'] = "net.inet.udp.blackhole";
645 4816e5ca Renato Botelho
		$config['sysctl']['item'][1]['descr'] =    gettext("Do not send ICMP port unreachable messages for closed UDP ports");
646 908c4eea sullrich
		$config['sysctl']['item'][1]['value'] =   "default";
647 791bcfd4 Bill Marquette
648
		$config['sysctl']['item'][2]['tunable'] = "net.inet.ip.random_id";
649 4816e5ca Renato Botelho
		$config['sysctl']['item'][2]['descr'] =    gettext("Randomize the ID field in IP packets (default is 0: sequential IP IDs)");
650 908c4eea sullrich
		$config['sysctl']['item'][2]['value'] =   "default";
651 791bcfd4 Bill Marquette
652
		$config['sysctl']['item'][3]['tunable'] = "net.inet.tcp.drop_synfin";
653 4816e5ca Renato Botelho
		$config['sysctl']['item'][3]['descr'] =    gettext("Drop SYN-FIN packets (breaks RFC1379, but nobody uses it anyway)");
654 908c4eea sullrich
		$config['sysctl']['item'][3]['value'] =   "default";
655 791bcfd4 Bill Marquette
656
		$config['sysctl']['item'][4]['tunable'] = "net.inet.ip.redirect";
657 4816e5ca Renato Botelho
		$config['sysctl']['item'][4]['descr'] =    gettext("Sending of IPv4 ICMP redirects");
658 908c4eea sullrich
		$config['sysctl']['item'][4]['value'] =   "default";
659 791bcfd4 Bill Marquette
660
		$config['sysctl']['item'][5]['tunable'] = "net.inet6.ip6.redirect";
661 4816e5ca Renato Botelho
		$config['sysctl']['item'][5]['descr'] =    gettext("Sending of IPv6 ICMP redirects");
662 908c4eea sullrich
		$config['sysctl']['item'][5]['value'] =   "default";
663 791bcfd4 Bill Marquette
664
		$config['sysctl']['item'][6]['tunable'] = "net.inet.tcp.syncookies";
665 4816e5ca Renato Botelho
		$config['sysctl']['item'][6]['descr'] =    gettext("Generate SYN cookies for outbound SYN-ACK packets");
666 908c4eea sullrich
		$config['sysctl']['item'][6]['value'] =   "default";
667 791bcfd4 Bill Marquette
668
		$config['sysctl']['item'][7]['tunable'] = "net.inet.tcp.recvspace";
669 4816e5ca Renato Botelho
		$config['sysctl']['item'][7]['descr'] =    gettext("Maximum incoming TCP datagram size");
670 908c4eea sullrich
		$config['sysctl']['item'][7]['value'] =   "default";
671 791bcfd4 Bill Marquette
672
		$config['sysctl']['item'][8]['tunable'] = "net.inet.tcp.sendspace";
673 4816e5ca Renato Botelho
		$config['sysctl']['item'][8]['descr'] =    gettext("Maximum outgoing TCP datagram size");
674 908c4eea sullrich
		$config['sysctl']['item'][8]['value'] =   "default";
675 791bcfd4 Bill Marquette
676
		$config['sysctl']['item'][9]['tunable'] = "net.inet.ip.fastforwarding";
677 4816e5ca Renato Botelho
		$config['sysctl']['item'][9]['descr'] =    gettext("Fastforwarding (see http://lists.freebsd.org/pipermail/freebsd-net/2004-January/002534.html)");
678 908c4eea sullrich
		$config['sysctl']['item'][9]['value'] =   "default";
679 791bcfd4 Bill Marquette
680
		$config['sysctl']['item'][10]['tunable'] = "net.inet.tcp.delayed_ack";
681 4816e5ca Renato Botelho
		$config['sysctl']['item'][10]['descr'] =    gettext("Do not delay ACK to try and piggyback it onto a data packet");
682 908c4eea sullrich
		$config['sysctl']['item'][10]['value'] =   "default";
683 791bcfd4 Bill Marquette
684
		$config['sysctl']['item'][11]['tunable'] = "net.inet.udp.maxdgram";
685 4816e5ca Renato Botelho
		$config['sysctl']['item'][11]['descr'] =    gettext("Maximum outgoing UDP datagram size");
686 908c4eea sullrich
		$config['sysctl']['item'][11]['value'] =   "default";
687 791bcfd4 Bill Marquette
688
		$config['sysctl']['item'][12]['tunable'] = "net.link.bridge.pfil_onlyip";
689 4816e5ca Renato Botelho
		$config['sysctl']['item'][12]['descr'] =    gettext("Handling of non-IP packets which are not passed to pfil (see if_bridge(4))");
690 908c4eea sullrich
		$config['sysctl']['item'][12]['value'] =   "default";
691 791bcfd4 Bill Marquette
692
		$config['sysctl']['item'][13]['tunable'] = "net.link.tap.user_open";
693 4816e5ca Renato Botelho
		$config['sysctl']['item'][13]['descr'] =    gettext("Allow unprivileged access to tap(4) device nodes");
694 908c4eea sullrich
		$config['sysctl']['item'][13]['value'] =   "default";
695 791bcfd4 Bill Marquette
696
		$config['sysctl']['item'][15]['tunable'] = "kern.randompid";
697 4816e5ca Renato Botelho
		$config['sysctl']['item'][15]['descr'] =    gettext("Randomize PID's (see src/sys/kern/kern_fork.c: sysctl_kern_randompid())");
698 908c4eea sullrich
		$config['sysctl']['item'][15]['value'] =   "default";
699 791bcfd4 Bill Marquette
700
		$config['sysctl']['item'][16]['tunable'] = "net.inet.tcp.inflight.enable";
701 4816e5ca Renato Botelho
		$config['sysctl']['item'][16]['descr'] =    gettext("The system will attempt to calculate the bandwidth delay product for each connection and limit the amount of data queued to the network to just the amount required to maintain optimum throughput. ");
702 908c4eea sullrich
		$config['sysctl']['item'][16]['value'] =   "default";
703 791bcfd4 Bill Marquette
704
		$config['sysctl']['item'][17]['tunable'] = "net.inet.icmp.icmplim";
705 4816e5ca Renato Botelho
		$config['sysctl']['item'][17]['descr'] =    gettext("Set ICMP Limits");
706 908c4eea sullrich
		$config['sysctl']['item'][17]['value'] =   "default";
707 791bcfd4 Bill Marquette
708
		$config['sysctl']['item'][18]['tunable'] = "net.inet.tcp.tso";
709 4816e5ca Renato Botelho
		$config['sysctl']['item'][18]['descr'] =    gettext("TCP Offload engine");
710 908c4eea sullrich
		$config['sysctl']['item'][18]['value'] =   "default";
711 2d563280 Renato Botelho
712 558dda01 Scott Ullrich
		$config['sysctl']['item'][19]['tunable'] = "net.inet.ip.portrange.first";
713
		$config['sysctl']['item'][19]['descr'] =    "Set the ephemeral port range starting port";
714
		$config['sysctl']['item'][19]['value'] =   "default";
715 908c4eea sullrich
716 64c86313 Warren Baker
		$config['sysctl']['item'][20]['tunable'] = "hw.syscons.kbd_reboot";
717 558dda01 Scott Ullrich
		$config['sysctl']['item'][20]['descr'] =    "Enables ctrl+alt+delete";
718
		$config['sysctl']['item'][20]['value'] =   "default";
719 06702ef7 Chris Buechler
720 99fbc94a Warren Baker
		$config['sysctl']['item'][21]['tunable'] = "kern.ipc.maxsockbuf";
721
		$config['sysctl']['item'][21]['descr'] =    "Maximum socket buffer size";
722
		$config['sysctl']['item'][21]['value'] =   "default";
723 64c86313 Warren Baker
724 791bcfd4 Bill Marquette
	}
725
}
726
727
728
function upgrade_041_to_042() {
729
	global $config;
730 751533a2 Phil Davis
	if (isset($config['shaper'])) {
731 791bcfd4 Bill Marquette
		unset($config['shaper']);
732 751533a2 Phil Davis
	}
733
	if (isset($config['ezshaper'])) {
734 791bcfd4 Bill Marquette
		unset($config['ezshaper']);
735 751533a2 Phil Davis
	}
736 791bcfd4 Bill Marquette
}
737
738
739
function upgrade_042_to_043() {
740
	global $config;
741
	/* migrate old interface gateway to the new gateways config */
742 ab0eced7 Ermal
	$iflist = get_configured_interface_list(false, true);
743 791bcfd4 Bill Marquette
	$gateways = array();
744
	$i = 0;
745 751533a2 Phil Davis
	foreach ($iflist as $ifname => $interface) {
746
		if (! interface_has_gateway($ifname)) {
747 fc85edaf Seth Mos
			continue;
748
		}
749 b314ab72 Ermal
		$config['gateways']['gateway_item'][$i] = array();
750 751533a2 Phil Davis
		if (is_ipaddr($config['interfaces'][$ifname]['gateway'])) {
751 3240836a Seth Mos
			$config['gateways']['gateway_item'][$i]['gateway'] = $config['interfaces'][$ifname]['gateway'];
752 4d511e5b Renato Botelho
			$config['gateways']['gateway_item'][$i]['descr'] = sprintf(gettext("Interface %s Static Gateway"), $ifname);
753 2328dcc5 Seth Mos
		} else {
754
			$config['gateways']['gateway_item'][$i]['gateway'] = "dynamic";
755 4d511e5b Renato Botelho
			$config['gateways']['gateway_item'][$i]['descr'] = sprintf(gettext("Interface %s Dynamic Gateway"), $ifname);
756 2328dcc5 Seth Mos
		}
757
		$config['gateways']['gateway_item'][$i]['interface'] = $ifname;
758
		$config['gateways']['gateway_item'][$i]['name'] = "GW_" . strtoupper($ifname);
759
		/* add default gateway bit for wan on upgrade */
760 751533a2 Phil Davis
		if ($ifname == "wan") {
761 2d563280 Renato Botelho
			$config['gateways']['gateway_item'][$i]['defaultgw'] = true;
762 2328dcc5 Seth Mos
		}
763 751533a2 Phil Davis
		if (is_ipaddr($config['interfaces'][$ifname]['use_rrd_gateway'])) {
764 2328dcc5 Seth Mos
			$config['gateways']['gateway_item'][$i]['monitor'] = $config['interfaces'][$ifname]['use_rrd_gateway'];
765
			unset($config['interfaces'][$ifname]['use_rrd_gateway']);
766
		}
767
		$config['interfaces'][$ifname]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
768 3240836a Seth Mos
769 2328dcc5 Seth Mos
		/* Update all filter rules which might reference this gateway */
770
		$j = 0;
771 751533a2 Phil Davis
		foreach ($config['filter']['rule'] as $rule) {
772
			if (is_ipaddr($rule['gateway'])) {
773
				if ($rule['gateway'] == $config['gateways']['gateway_item'][$i]['gateway']) {
774 6364b88b Ermal
					$config['filter']['rule'][$j]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
775 751533a2 Phil Davis
				} else if ($rule['gateway'] == $ifname) {
776 6364b88b Ermal
					$config['filter']['rule'][$j]['gateway'] = $config['gateways']['gateway_item'][$i]['name'];
777 751533a2 Phil Davis
				}
778 3240836a Seth Mos
			}
779 2328dcc5 Seth Mos
			$j++;
780 791bcfd4 Bill Marquette
		}
781 c9ba2835 smos
782
		/* rename old Quality RRD files in the process */
783
		$rrddbpath = "/var/db/rrd";
784
		$gwname = "GW_" . strtoupper($ifname);
785 751533a2 Phil Davis
		if (is_readable("{$rrddbpath}/{$ifname}-quality.rrd")) {
786 c9ba2835 smos
			rename("{$rrddbpath}/{$ifname}-quality.rrd", "{$rrddbpath}/{$gwname}-quality.rrd");
787
		}
788 2328dcc5 Seth Mos
		$i++;
789 791bcfd4 Bill Marquette
	}
790
}
791
792
793
function upgrade_043_to_044() {
794
	global $config;
795 a842e988 Ermal
796
	/* migrate static routes to the new gateways config */
797
	$gateways = return_gateways_array(true);
798 6cae2c44 Ermal
	$i = 0;
799 a842e988 Ermal
	if (is_array($config['staticroutes']['route'])) {
800 323f3f9c smos
		$gwmap = array();
801 a842e988 Ermal
		foreach ($config['staticroutes']['route'] as $idx => $sroute) {
802
			$found = false;
803
			foreach ($gateways as $gwname => $gw) {
804
				if ($gw['gateway'] == $sroute['gateway']) {
805
					$config['staticroutes']['route'][$idx]['gateway'] = $gwname;
806
					$found = true;
807
					break;
808
				}
809
			}
810 751533a2 Phil Davis
			if ($gwmap[$sroute['gateway']]) {
811 323f3f9c smos
				/* We already added a gateway name for this IP */
812
				$config['staticroutes']['route'][$idx]['gateway'] = "{$gwmap[$sroute['gateway']]}";
813
				$found = true;
814 2d563280 Renato Botelho
			}
815
816 a842e988 Ermal
			if ($found == false) {
817
				$gateway = array();
818 323f3f9c smos
				$gateway['name'] = "SROUTE{$i}";
819
				$gwmap[$sroute['gateway']] = $gateway['name'];
820 a842e988 Ermal
				$gateway['gateway'] = $sroute['gateway'];
821
				$gateway['interface'] = $sroute['interface'];
822 4d511e5b Renato Botelho
				$gateway['descr'] = sprintf(gettext("Upgraded static route for %s"), $sroute['network']);
823 751533a2 Phil Davis
				if (!is_array($config['gateways']['gateway_item'])) {
824 a842e988 Ermal
					$config['gateways']['gateway_item'] = array();
825 751533a2 Phil Davis
				}
826 a842e988 Ermal
				$config['gateways']['gateway_item'][] = $gateway;
827
				$config['staticroutes']['route'][$idx]['gateway'] = $gateway['name'];
828 6cae2c44 Ermal
				$i++;
829 a842e988 Ermal
			}
830
		}
831
	}
832 791bcfd4 Bill Marquette
}
833
834
835
function upgrade_044_to_045() {
836
	global $config;
837 da74e673 Seth Mos
	$iflist = get_configured_interface_list(false, true);
838 791bcfd4 Bill Marquette
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
839 3d039701 smos
		$i = 0;
840 da74e673 Seth Mos
		foreach ($config['vlans']['vlan'] as $id => $vlan) {
841
			/* Make sure to update the interfaces section with the right name */
842 62958eae smos
			$vlan_name = "{$vlan['if']}_vlan{$vlan['tag']}";
843 751533a2 Phil Davis
			foreach ($iflist as $ifname) {
844
				if ($config['interfaces'][$ifname]['if'] == "vlan{$i}") {
845 62958eae smos
					$config['interfaces'][$ifname]['if'] = $vlan_name;
846
					continue;
847 da74e673 Seth Mos
				}
848
			}
849 62958eae smos
			$config['vlans']['vlan'][$i]['vlanif'] = "{$vlan_name}";
850 2d563280 Renato Botelho
			$i++;
851 da74e673 Seth Mos
		}
852 791bcfd4 Bill Marquette
	}
853
}
854
855
856
function upgrade_045_to_046() {
857
	global $config;
858 2d563280 Renato Botelho
	/* Load up monitors that are in the default config for 2.0 but not in 1.2.3
859 506514e7 jim-p
		thus wouldn't be in an upgraded config. */
860
	$config['load_balancer']['monitor_type'] = array (
861 751533a2 Phil Davis
		array ('name' => 'ICMP',
862 506514e7 jim-p
			'type' => 'icmp',
863
			'descr' => 'ICMP',
864
			'options' => '',
865
		),
866 751533a2 Phil Davis
		array ('name' => 'TCP',
867 506514e7 jim-p
			'type' => 'tcp',
868
			'descr' => 'Generic TCP',
869
			'options' => '',
870
		),
871 751533a2 Phil Davis
		array ('name' => 'HTTP',
872 506514e7 jim-p
			'type' => 'http',
873
			'descr' => 'Generic HTTP',
874
			'options' =>
875 751533a2 Phil Davis
			array ('path' => '/',
876 506514e7 jim-p
				'host' => '',
877
				'code' => '200',
878
			),
879
		),
880 751533a2 Phil Davis
		array ('name' => 'HTTPS',
881 506514e7 jim-p
			'type' => 'https',
882
			'descr' => 'Generic HTTPS',
883
			'options' =>
884 751533a2 Phil Davis
			array ('path' => '/',
885 506514e7 jim-p
				'host' => '',
886
				'code' => '200',
887
			),
888
		),
889 751533a2 Phil Davis
		array ('name' => 'SMTP',
890 506514e7 jim-p
			'type' => 'send',
891
			'descr' => 'Generic SMTP',
892
			'options' =>
893 751533a2 Phil Davis
			array ('send' => '',
894 520d4137 jim-p
				'expect' => '220 *',
895 506514e7 jim-p
			),
896
		),
897
	);
898 791bcfd4 Bill Marquette
	/* Upgrade load balancer from slb to relayd */
899
	if (is_array($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server'])) {
900
		$vs_a = &$config['load_balancer']['virtual_server'];
901
		$pool_a = &$config['load_balancer']['lbpool'];
902
		$pools = array();
903 25753b5b sullrich
		/* Index pools by name */
904 751533a2 Phil Davis
		if (is_array($pool_a)) {
905 791bcfd4 Bill Marquette
			for ($i = 0; isset($pool_a[$i]); $i++) {
906 751533a2 Phil Davis
				if ($pool_a[$i]['type'] == "server") {
907 791bcfd4 Bill Marquette
					$pools[$pool_a[$i]['name']] = $pool_a[$i];
908
				}
909
			}
910
		}
911
		/* Convert sitedown entries to pools and re-attach */
912
		for ($i = 0; isset($vs_a[$i]); $i++) {
913 d30afa60 jim-p
			/* Set mode while we're here. */
914
			$vs_a[$i]['mode'] = "redirect_mode";
915 791bcfd4 Bill Marquette
			if (isset($vs_a[$i]['sitedown'])) {
916
				$pool = array();
917
				$pool['type'] = 'server';
918
				$pool['behaviour'] = 'balance';
919
				$pool['name'] = "{$vs_a[$i]['name']}-sitedown";
920 4816e5ca Renato Botelho
				$pool['descr'] = sprintf(gettext("Sitedown pool for VS: %s"), $vs_a[$i]['name']);
921 751533a2 Phil Davis
				if (is_array($vs_a[$i]['pool'])) {
922 6e9b046e jim-p
					$vs_a[$i]['pool'] = $vs_a[$i]['pool'][0];
923 751533a2 Phil Davis
				}
924 791bcfd4 Bill Marquette
				$pool['port'] = $pools[$vs_a[$i]['pool']]['port'];
925
				$pool['servers'] = array();
926
				$pool['servers'][] = $vs_a[$i]['sitedown'];
927
				$pool['monitor'] = $pools[$vs_a[$i]['pool']]['monitor'];
928
				$pool_a[] = $pool;
929
				$vs_a[$i]['sitedown'] = $pool['name'];
930
			}
931
		}
932
	}
933 751533a2 Phil Davis
	if (count($config['load_balancer']) == 0) {
934 0b5b4f32 Seth Mos
		unset($config['load_balancer']);
935
	}
936 a09d8bfc jim-p
	mwexec('/usr/sbin/pw groupadd -n _relayd -g 913');
937
	mwexec('/usr/sbin/pw useradd -n _relayd -c "Relay Daemon" -d /var/empty -s /usr/sbin/nologin -u 913 -g 913');
938 791bcfd4 Bill Marquette
}
939
940
941
function upgrade_046_to_047() {
942
	global $config;
943
	/* Upgrade IPsec from tunnel to phase1/phase2 */
944
945 751533a2 Phil Davis
	if (is_array($config['ipsec']['tunnel'])) {
946 791bcfd4 Bill Marquette
947
		$a_phase1 = array();
948
		$a_phase2 = array();
949
		$ikeid = 0;
950
951
		foreach ($config['ipsec']['tunnel'] as $tunnel) {
952
953
			unset($ph1ent);
954
			unset($ph2ent);
955
956
			/*
957
				*  attempt to locate an enabled phase1
958
				*  entry that matches the peer gateway
959
				*/
960
961
			if (!isset($tunnel['disabled'])) {
962
963
				$remote_gateway = $tunnel['remote-gateway'];
964
965
				foreach ($a_phase1 as $ph1tmp) {
966
					if ($ph1tmp['remote-gateway'] == $remote_gateway) {
967
						$ph1ent = $ph1tmp;
968
						break;
969
					}
970
				}
971
			}
972
973
			/* none found, create a new one */
974
975 751533a2 Phil Davis
			if (!isset($ph1ent)) {
976 791bcfd4 Bill Marquette
977
				/* build new phase1 entry */
978
979
				$ph1ent = array();
980
981
				$ph1ent['ikeid'] = ++$ikeid;
982
983 751533a2 Phil Davis
				if (isset($tunnel['disabled'])) {
984 791bcfd4 Bill Marquette
					$ph1ent['disabled'] = $tunnel['disabled'];
985 751533a2 Phil Davis
				}
986 791bcfd4 Bill Marquette
987 443f2e6e smos
				/* convert to the new vip[$vhid] name */
988 751533a2 Phil Davis
				if (preg_match("/^carp/", $tunnel['interface'])) {
989 bc75a430 smos
					$carpid = str_replace("carp", "", $tunnel['interface']);
990 4aa58d46 smos
					$tunnel['interface'] = "vip" . $config['virtualip']['vip'][$carpid]['vhid'];
991 443f2e6e smos
				}
992 791bcfd4 Bill Marquette
				$ph1ent['interface'] = $tunnel['interface'];
993
				$ph1ent['remote-gateway'] = $tunnel['remote-gateway'];
994
				$ph1ent['descr'] = $tunnel['descr'];
995
996
				$ph1ent['mode'] = $tunnel['p1']['mode'];
997
998 751533a2 Phil Davis
				if (isset($tunnel['p1']['myident']['myaddress'])) {
999 791bcfd4 Bill Marquette
					$ph1ent['myid_type'] = "myaddress";
1000 751533a2 Phil Davis
				}
1001 791bcfd4 Bill Marquette
				if (isset($tunnel['p1']['myident']['address'])) {
1002
					$ph1ent['myid_type'] = "address";
1003
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['address'];
1004
				}
1005
				if (isset($tunnel['p1']['myident']['fqdn'])) {
1006
					$ph1ent['myid_type'] = "fqdn";
1007
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['fqdn'];
1008
				}
1009 dfa11031 jim-p
				if (isset($tunnel['p1']['myident']['ufqdn'])) {
1010 791bcfd4 Bill Marquette
					$ph1ent['myid_type'] = "user_fqdn";
1011 dfa11031 jim-p
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['ufqdn'];
1012 791bcfd4 Bill Marquette
				}
1013
				if (isset($tunnel['p1']['myident']['asn1dn'])) {
1014
					$ph1ent['myid_type'] = "asn1dn";
1015
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['asn1dn'];
1016
				}
1017
				if (isset($tunnel['p1']['myident']['dyn_dns'])) {
1018
					$ph1ent['myid_type'] = "dyn_dns";
1019
					$ph1ent['myid_data'] = $tunnel['p1']['myident']['dyn_dns'];
1020
				}
1021
1022
				$ph1ent['peerid_type'] = "peeraddress";
1023
1024
				switch ($tunnel['p1']['encryption-algorithm']) {
1025
					case "des":
1026 751533a2 Phil Davis
						$ph1alg = array('name' => 'des');
1027
						break;
1028 791bcfd4 Bill Marquette
					case "3des":
1029 751533a2 Phil Davis
						$ph1alg = array('name' => '3des');
1030
						break;
1031 791bcfd4 Bill Marquette
					case "blowfish":
1032 751533a2 Phil Davis
						$ph1alg = array('name' => 'blowfish', 'keylen' => '128');
1033
						break;
1034 791bcfd4 Bill Marquette
					case "cast128":
1035 751533a2 Phil Davis
						$ph1alg = array('name' => 'cast128');
1036
						break;
1037 791bcfd4 Bill Marquette
					case "rijndael":
1038 751533a2 Phil Davis
						$ph1alg = array('name' => 'aes', 'keylen' => '128');
1039
						break;
1040 791bcfd4 Bill Marquette
					case "rijndael 256":
1041 a5187d43 jim-p
					case "aes 256":
1042 751533a2 Phil Davis
						$ph1alg = array('name' => 'aes', 'keylen' => '256');
1043
						break;
1044 791bcfd4 Bill Marquette
				}
1045
1046
				$ph1ent['encryption-algorithm'] = $ph1alg;
1047
				$ph1ent['hash-algorithm'] = $tunnel['p1']['hash-algorithm'];
1048
				$ph1ent['dhgroup'] = $tunnel['p1']['dhgroup'];
1049
				$ph1ent['lifetime'] = $tunnel['p1']['lifetime'];
1050
				$ph1ent['authentication_method'] = $tunnel['p1']['authentication_method'];
1051
1052 751533a2 Phil Davis
				if (isset($tunnel['p1']['pre-shared-key'])) {
1053 791bcfd4 Bill Marquette
					$ph1ent['pre-shared-key'] = $tunnel['p1']['pre-shared-key'];
1054 751533a2 Phil Davis
				}
1055
				if (isset($tunnel['p1']['cert'])) {
1056 791bcfd4 Bill Marquette
					$ph1ent['cert'] = $tunnel['p1']['cert'];
1057 751533a2 Phil Davis
				}
1058
				if (isset($tunnel['p1']['peercert'])) {
1059 791bcfd4 Bill Marquette
					$ph1ent['peercert'] = $tunnel['p1']['peercert'];
1060 751533a2 Phil Davis
				}
1061
				if (isset($tunnel['p1']['private-key'])) {
1062 791bcfd4 Bill Marquette
					$ph1ent['private-key'] = $tunnel['p1']['private-key'];
1063 751533a2 Phil Davis
				}
1064 791bcfd4 Bill Marquette
1065
				$ph1ent['nat_traversal'] = "on";
1066
				$ph1ent['dpd_enable'] = 1;
1067
				$ph1ent['dpd_delay'] = 10;
1068
				$ph1ent['dpd_maxfail'] = 5;
1069
1070
				$a_phase1[] = $ph1ent;
1071
			}
1072
1073
			/* build new phase2 entry */
1074
1075
			$ph2ent = array();
1076
1077
			$ph2ent['ikeid'] = $ph1ent['ikeid'];
1078
1079 751533a2 Phil Davis
			if (isset($tunnel['disabled'])) {
1080 791bcfd4 Bill Marquette
				$ph1ent['disabled'] = $tunnel['disabled'];
1081 751533a2 Phil Davis
			}
1082 791bcfd4 Bill Marquette
1083 4d511e5b Renato Botelho
			$ph2ent['descr'] = sprintf(gettext("phase2 for %s"), $tunnel['descr']);
1084 791bcfd4 Bill Marquette
1085
			$type = "lan";
1086 751533a2 Phil Davis
			if ($tunnel['local-subnet']['network']) {
1087 791bcfd4 Bill Marquette
				$type = $tunnel['local-subnet']['network'];
1088 751533a2 Phil Davis
			}
1089 791bcfd4 Bill Marquette
			if ($tunnel['local-subnet']['address']) {
1090
				list($address,$netbits) = explode("/",$tunnel['local-subnet']['address']);
1091 751533a2 Phil Davis
				if (is_null($netbits)) {
1092 791bcfd4 Bill Marquette
					$type = "address";
1093 751533a2 Phil Davis
				} else {
1094 791bcfd4 Bill Marquette
					$type = "network";
1095 751533a2 Phil Davis
				}
1096 791bcfd4 Bill Marquette
			}
1097
1098
			switch ($type) {
1099
				case "address":
1100 751533a2 Phil Davis
					$ph2ent['localid'] = array('type' => $type,'address' => $address);
1101
					break;
1102 791bcfd4 Bill Marquette
				case "network":
1103 751533a2 Phil Davis
					$ph2ent['localid'] = array('type' => $type,'address' => $address,'netbits' => $netbits);
1104
					break;
1105 791bcfd4 Bill Marquette
				default:
1106 751533a2 Phil Davis
					$ph2ent['localid'] = array('type' => $type);
1107
					break;
1108 791bcfd4 Bill Marquette
			}
1109
1110
			list($address,$netbits) = explode("/",$tunnel['remote-subnet']);
1111
			$ph2ent['remoteid'] = array('type' => 'network','address' => $address,'netbits' => $netbits);
1112
1113
			$ph2ent['protocol'] = $tunnel['p2']['protocol'];
1114
1115
			$aes_count = 0;
1116 751533a2 Phil Davis
			foreach ($tunnel['p2']['encryption-algorithm-option'] as $tunalg) {
1117 791bcfd4 Bill Marquette
				$aes_found = false;
1118
				switch ($tunalg) {
1119
					case "des":
1120 751533a2 Phil Davis
						$ph2alg = array('name' => 'des');
1121
						break;
1122 791bcfd4 Bill Marquette
					case "3des":
1123 751533a2 Phil Davis
						$ph2alg = array('name' => '3des');
1124
						break;
1125 791bcfd4 Bill Marquette
					case "blowfish":
1126 751533a2 Phil Davis
						$ph2alg = array('name' => 'blowfish', 'keylen' => 'auto');
1127
						break;
1128 791bcfd4 Bill Marquette
					case "cast128":
1129 751533a2 Phil Davis
						$ph2alg = array('name' => 'cast128');
1130
						break;
1131 791bcfd4 Bill Marquette
					case "rijndael":
1132
					case "rijndael 256":
1133 a5187d43 jim-p
					case "aes 256":
1134 751533a2 Phil Davis
						$ph2alg = array('name' => 'aes', 'keylen' => 'auto');
1135
						$aes_found = true;
1136
						$aes_count++;
1137
						break;
1138 791bcfd4 Bill Marquette
				}
1139
1140 751533a2 Phil Davis
				if (!$aes_found || ($aes_count < 2)) {
1141 791bcfd4 Bill Marquette
					$ph2ent['encryption-algorithm-option'][] = $ph2alg;
1142 751533a2 Phil Davis
				}
1143 791bcfd4 Bill Marquette
			}
1144
1145
			$ph2ent['hash-algorithm-option'] = $tunnel['p2']['hash-algorithm-option'];
1146
			$ph2ent['pfsgroup'] = $tunnel['p2']['pfsgroup'];
1147
			$ph2ent['lifetime'] = $tunnel['p2']['lifetime'];
1148
1149 751533a2 Phil Davis
			if (isset($tunnel['pinghost']['pinghost'])) {
1150 87e07f52 mgrooms
				$ph2ent['pinghost'] = $tunnel['pinghost'];
1151 751533a2 Phil Davis
			}
1152 87e07f52 mgrooms
1153 791bcfd4 Bill Marquette
			$a_phase2[] = $ph2ent;
1154
		}
1155
1156
		unset($config['ipsec']['tunnel']);
1157
		$config['ipsec']['phase1'] = $a_phase1;
1158
		$config['ipsec']['phase2'] = $a_phase2;
1159
	}
1160 49bb5c07 jim-p
1161
	/* Upgrade Mobile IPsec */
1162 751533a2 Phil Davis
	if (isset($config['ipsec']['mobileclients']) &&
1163
	    is_array($config['ipsec']['mobileclients']) &&
1164
	    is_array($config['ipsec']['mobileclients']['p1']) &&
1165
	    is_array($config['ipsec']['mobileclients']['p2'])) {
1166 49bb5c07 jim-p
1167
		if (isset($config['ipsec']['mobileclients']['enable'])) {
1168
			$config['ipsec']['client']['enable'] = true;
1169
			$config['ipsec']['client']['user_source'] = 'system';
1170
			$config['ipsec']['client']['group_source'] = 'system';
1171
		}
1172
1173
		$mobilecfg = $config['ipsec']['mobileclients'];
1174
1175
		$ph1ent = array();
1176
		$ph1ent['ikeid'] = ++$ikeid;
1177
1178 751533a2 Phil Davis
		if (!isset($mobilecfg['enable'])) {
1179 49bb5c07 jim-p
			$ph1ent['disabled'] = true;
1180 751533a2 Phil Davis
		}
1181 49bb5c07 jim-p
1182
		/* Assume WAN since mobile tunnels couldn't be on a separate interface on 1.2.x */
1183
		$ph1ent['interface'] = 'wan';
1184
		$ph1ent['descr'] = "Mobile Clients (upgraded)";
1185
		$ph1ent['mode'] = $mobilecfg['p1']['mode'];
1186
1187 751533a2 Phil Davis
		if (isset($mobilecfg['p1']['myident']['myaddress'])) {
1188 49bb5c07 jim-p
			$ph1ent['myid_type'] = "myaddress";
1189 751533a2 Phil Davis
		}
1190 49bb5c07 jim-p
		if (isset($mobilecfg['p1']['myident']['address'])) {
1191
			$ph1ent['myid_type'] = "address";
1192
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['address'];
1193
		}
1194
		if (isset($mobilecfg['p1']['myident']['fqdn'])) {
1195
			$ph1ent['myid_type'] = "fqdn";
1196
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['fqdn'];
1197
		}
1198
		if (isset($mobilecfg['p1']['myident']['ufqdn'])) {
1199
			$ph1ent['myid_type'] = "user_fqdn";
1200
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['ufqdn'];
1201
		}
1202
		if (isset($mobilecfg['p1']['myident']['asn1dn'])) {
1203
			$ph1ent['myid_type'] = "asn1dn";
1204
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['asn1dn'];
1205
		}
1206
		if (isset($mobilecfg['p1']['myident']['dyn_dns'])) {
1207
			$ph1ent['myid_type'] = "dyn_dns";
1208
			$ph1ent['myid_data'] = $mobilecfg['p1']['myident']['dyn_dns'];
1209
		}
1210
		$ph1ent['peerid_type'] = "fqdn";
1211
		$ph1ent['peerid_data'] = "";
1212
1213
		switch ($mobilecfg['p1']['encryption-algorithm']) {
1214
			case "des":
1215 751533a2 Phil Davis
				$ph1alg = array('name' => 'des');
1216
				break;
1217 49bb5c07 jim-p
			case "3des":
1218 751533a2 Phil Davis
				$ph1alg = array('name' => '3des');
1219
				break;
1220 49bb5c07 jim-p
			case "blowfish":
1221 751533a2 Phil Davis
				$ph1alg = array('name' => 'blowfish', 'keylen' => '128');
1222
				break;
1223 49bb5c07 jim-p
			case "cast128":
1224 751533a2 Phil Davis
				$ph1alg = array('name' => 'cast128');
1225
				break;
1226 49bb5c07 jim-p
			case "rijndael":
1227 751533a2 Phil Davis
				$ph1alg = array('name' => 'aes', 'keylen' => '128');
1228
				break;
1229 49bb5c07 jim-p
			case "rijndael 256":
1230 a5187d43 jim-p
			case "aes 256":
1231 751533a2 Phil Davis
				$ph1alg = array('name' => 'aes', 'keylen' => '256');
1232
				break;
1233 49bb5c07 jim-p
		}
1234
1235
		$ph1ent['encryption-algorithm'] = $ph1alg;
1236
		$ph1ent['hash-algorithm'] = $mobilecfg['p1']['hash-algorithm'];
1237
		$ph1ent['dhgroup'] = $mobilecfg['p1']['dhgroup'];
1238
		$ph1ent['lifetime'] = $mobilecfg['p1']['lifetime'];
1239
		$ph1ent['authentication_method'] = $mobilecfg['p1']['authentication_method'];
1240
1241 751533a2 Phil Davis
		if (isset($mobilecfg['p1']['cert'])) {
1242 49bb5c07 jim-p
			$ph1ent['cert'] = $mobilecfg['p1']['cert'];
1243 751533a2 Phil Davis
		}
1244
		if (isset($mobilecfg['p1']['peercert'])) {
1245 49bb5c07 jim-p
			$ph1ent['peercert'] = $mobilecfg['p1']['peercert'];
1246 751533a2 Phil Davis
		}
1247
		if (isset($mobilecfg['p1']['private-key'])) {
1248 49bb5c07 jim-p
			$ph1ent['private-key'] = $mobilecfg['p1']['private-key'];
1249 751533a2 Phil Davis
		}
1250 49bb5c07 jim-p
1251
		$ph1ent['nat_traversal'] = "on";
1252
		$ph1ent['dpd_enable'] = 1;
1253
		$ph1ent['dpd_delay'] = 10;
1254
		$ph1ent['dpd_maxfail'] = 5;
1255
		$ph1ent['mobile'] = true;
1256
1257
		$ph2ent = array();
1258
		$ph2ent['ikeid'] = $ph1ent['ikeid'];
1259
		$ph2ent['descr'] = "phase2 for ".$mobilecfg['descr'];
1260
		$ph2ent['localid'] = array('type' => 'none');
1261
		$ph2ent['remoteid'] = array('type' => 'mobile');
1262
		$ph2ent['protocol'] = $mobilecfg['p2']['protocol'];
1263
1264
		$aes_count = 0;
1265 751533a2 Phil Davis
		foreach ($mobilecfg['p2']['encryption-algorithm-option'] as $tunalg) {
1266 49bb5c07 jim-p
			$aes_found = false;
1267
			switch ($tunalg) {
1268
				case "des":
1269 751533a2 Phil Davis
					$ph2alg = array('name' => 'des');
1270
					break;
1271 49bb5c07 jim-p
				case "3des":
1272 751533a2 Phil Davis
					$ph2alg = array('name' => '3des');
1273
					break;
1274 49bb5c07 jim-p
				case "blowfish":
1275 751533a2 Phil Davis
					$ph2alg = array('name' => 'blowfish', 'keylen' => 'auto');
1276
					break;
1277 49bb5c07 jim-p
				case "cast128":
1278 751533a2 Phil Davis
					$ph2alg = array('name' => 'cast128');
1279
					break;
1280 49bb5c07 jim-p
				case "rijndael":
1281
				case "rijndael 256":
1282 a5187d43 jim-p
				case "aes 256":
1283 751533a2 Phil Davis
					$ph2alg = array('name' => 'aes', 'keylen' => 'auto');
1284
					$aes_found = true;
1285
					$aes_count++;
1286
					break;
1287 49bb5c07 jim-p
			}
1288
1289 751533a2 Phil Davis
			if (!$aes_found || ($aes_count < 2)) {
1290 49bb5c07 jim-p
				$ph2ent['encryption-algorithm-option'][] = $ph2alg;
1291 751533a2 Phil Davis
			}
1292 49bb5c07 jim-p
		}
1293
		$ph2ent['hash-algorithm-option'] = $mobilecfg['p2']['hash-algorithm-option'];
1294
		$ph2ent['pfsgroup'] = $mobilecfg['p2']['pfsgroup'];
1295
		$ph2ent['lifetime'] = $mobilecfg['p2']['lifetime'];
1296
		$ph2ent['mobile'] = true;
1297
1298
		$config['ipsec']['phase1'][] = $ph1ent;
1299
		$config['ipsec']['phase2'][] = $ph2ent;
1300
		unset($config['ipsec']['mobileclients']);
1301
	}
1302 791bcfd4 Bill Marquette
}
1303
1304
1305
function upgrade_047_to_048() {
1306
	global $config;
1307 e31c90fc Ermal
	if (!empty($config['dyndns'])) {
1308
		$config['dyndnses'] = array();
1309
		$config['dyndnses']['dyndns'] = array();
1310 751533a2 Phil Davis
		if (isset($config['dyndns'][0]['host'])) {
1311 246aceaa smos
			$tempdyn = array();
1312
			$tempdyn['enable'] = isset($config['dyndns'][0]['enable']);
1313
			$tempdyn['type'] = $config['dyndns'][0]['type'];
1314
			$tempdyn['wildcard'] = isset($config['dyndns'][0]['wildcard']);
1315 7d62c4c8 Ermal
			$tempdyn['username'] = $config['dyndns'][0]['username'];
1316
			$tempdyn['password'] = $config['dyndns'][0]['password'];
1317 246aceaa smos
			$tempdyn['host'] = $config['dyndns'][0]['host'];
1318 2d563280 Renato Botelho
			$tempdyn['mx'] = $config['dyndns'][0]['mx'];
1319 246aceaa smos
			$tempdyn['interface'] = "wan";
1320 4d511e5b Renato Botelho
			$tempdyn['descr'] = sprintf(gettext("Upgraded Dyndns %s"), $tempdyn['type']);
1321 246aceaa smos
			$config['dyndnses']['dyndns'][] = $tempdyn;
1322
		}
1323 791bcfd4 Bill Marquette
		unset($config['dyndns']);
1324 2d563280 Renato Botelho
	}
1325 e31c90fc Ermal
	if (!empty($config['dnsupdate'])) {
1326 2b1b78e6 jim-p
		$pconfig = $config['dnsupdate'][0];
1327 751533a2 Phil Davis
		if (!$pconfig['ttl']) {
1328 2b1b78e6 jim-p
			$pconfig['ttl'] = 60;
1329 751533a2 Phil Davis
		}
1330
		if (!$pconfig['keytype']) {
1331 2b1b78e6 jim-p
			$pconfig['keytype'] = "zone";
1332 751533a2 Phil Davis
		}
1333 e31c90fc Ermal
		$pconfig['interface'] = "wan";
1334 791bcfd4 Bill Marquette
		$config['dnsupdates']['dnsupdate'][] = $pconfig;
1335
		unset($config['dnsupdate']);
1336
	}
1337
1338 1f0c76cf jim-p
	if (is_array($config['pppoe']) && is_array($config['pppoe'][0])) {
1339 791bcfd4 Bill Marquette
		$pconfig = array();
1340 1f0c76cf jim-p
		$pconfig['username'] = $config['pppoe'][0]['username'];
1341
		$pconfig['password'] = $config['pppoe'][0]['password'];
1342
		$pconfig['provider'] = $config['pppoe'][0]['provider'];
1343
		$pconfig['ondemand'] = isset($config['pppoe'][0]['ondemand']);
1344
		$pconfig['timeout'] = $config['pppoe'][0]['timeout'];
1345 791bcfd4 Bill Marquette
		unset($config['pppoe']);
1346
		$config['interfaces']['wan']['pppoe_username'] = $pconfig['username'];
1347
		$config['interfaces']['wan']['pppoe_password'] = $pconfig['password'];
1348
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1349
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
1350
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1351
	}
1352
	if (is_array($config['pptp'])) {
1353
		$pconfig = array();
1354
		$pconfig['username'] = $config['pptp']['username'];
1355
		$pconfig['password'] = $config['pptp']['password'];
1356
		$pconfig['provider'] = $config['pptp']['provider'];
1357
		$pconfig['ondemand'] = isset($config['pptp']['ondemand']);
1358
		$pconfig['timeout'] = $config['pptp']['timeout'];
1359
		unset($config['pptp']);
1360
		$config['interfaces']['wan']['pptp_username'] = $pconfig['username'];
1361
		$config['interfaces']['wan']['pptp_password'] = $pconfig['password'];
1362
		$config['interfaces']['wan']['provider'] = $pconfig['provider'];
1363 751533a2 Phil Davis
		$config['interfaces']['wan']['ondemand'] = isset($pconfig['ondemand']);
1364 791bcfd4 Bill Marquette
		$config['interfaces']['wan']['timeout'] = $pconfig['timeout'];
1365
	}
1366
}
1367
1368
1369
function upgrade_048_to_049() {
1370
	global $config;
1371
	/* setup new all users group */
1372
	$all = array();
1373
	$all['name'] = "all";
1374 4d511e5b Renato Botelho
	$all['description'] = gettext("All Users");
1375 791bcfd4 Bill Marquette
	$all['scope'] = "system";
1376
	$all['gid'] = 1998;
1377
	$all['member'] = array();
1378
1379 751533a2 Phil Davis
	if (!is_array($config['system']['user'])) {
1380 84924e76 Ermal
		$config['system']['user'] = array();
1381 751533a2 Phil Davis
	}
1382
	if (!is_array($config['system']['group'])) {
1383 791bcfd4 Bill Marquette
		$config['system']['group'] = array();
1384 751533a2 Phil Davis
	}
1385 791bcfd4 Bill Marquette
1386
	/* work around broken uid assignments */
1387
	$config['system']['nextuid'] = 2000;
1388
	foreach ($config['system']['user'] as & $user) {
1389 751533a2 Phil Davis
		if (isset($user['uid']) && !$user['uid']) {
1390 791bcfd4 Bill Marquette
			continue;
1391 751533a2 Phil Davis
		}
1392 791bcfd4 Bill Marquette
		$user['uid'] = $config['system']['nextuid']++;
1393
	}
1394
1395
	/* work around broken gid assignments */
1396
	$config['system']['nextgid'] = 2000;
1397
	foreach ($config['system']['group'] as & $group) {
1398 751533a2 Phil Davis
		if ($group['name'] == $g['admin_group']) {
1399 791bcfd4 Bill Marquette
			$group['gid'] = 1999;
1400 751533a2 Phil Davis
		} else {
1401 791bcfd4 Bill Marquette
			$group['gid'] = $config['system']['nextgid']++;
1402 751533a2 Phil Davis
		}
1403 791bcfd4 Bill Marquette
	}
1404
1405
	/* build group membership information */
1406
	foreach ($config['system']['group'] as & $group) {
1407
		$group['member'] = array();
1408
		foreach ($config['system']['user'] as & $user) {
1409
			$groupnames = explode(",", $user['groupname']);
1410 751533a2 Phil Davis
			if (in_array($group['name'],$groupnames)) {
1411 791bcfd4 Bill Marquette
				$group['member'][] = $user['uid'];
1412 751533a2 Phil Davis
			}
1413 791bcfd4 Bill Marquette
		}
1414
	}
1415
1416
	/* reset user group information */
1417
	foreach ($config['system']['user'] as & $user) {
1418
		unset($user['groupname']);
1419
		$all['member'][] = $user['uid'];
1420
	}
1421
1422
	/* reset group scope information */
1423 751533a2 Phil Davis
	foreach ($config['system']['group'] as & $group) {
1424
		if ($group['name'] != $g['admin_group']) {
1425
			$group['scope'] = "user";
1426
		}
1427
	}
1428 791bcfd4 Bill Marquette
1429
	/* insert new all group */
1430
	$groups = Array();
1431
	$groups[] = $all;
1432
	$groups = array_merge($config['system']['group'],$groups);
1433
	$config['system']['group'] = $groups;
1434
}
1435
1436
1437
function upgrade_049_to_050() {
1438
	global $config;
1439 84924e76 Ermal
1440 751533a2 Phil Davis
	if (!is_array($config['system']['user'])) {
1441 84924e76 Ermal
		$config['system']['user'] = array();
1442 751533a2 Phil Davis
	}
1443 791bcfd4 Bill Marquette
	/* update user privileges */
1444
	foreach ($config['system']['user'] as & $user) {
1445
		$privs = array();
1446
		if (!is_array($user['priv'])) {
1447
			unset($user['priv']);
1448
			continue;
1449
		}
1450
		foreach ($user['priv'] as $priv) {
1451 751533a2 Phil Davis
			switch ($priv['id']) {
1452 791bcfd4 Bill Marquette
				case "hasshell":
1453 751533a2 Phil Davis
					$privs[] = "user-shell-access";
1454
					break;
1455 791bcfd4 Bill Marquette
				case "copyfiles":
1456 751533a2 Phil Davis
					$privs[] = "user-copy-files";
1457
					break;
1458 791bcfd4 Bill Marquette
			}
1459
		}
1460
		$user['priv'] = $privs;
1461
	}
1462
1463
	/* update group privileges */
1464
	foreach ($config['system']['group'] as & $group) {
1465
		$privs = array();
1466
		if (!is_array($group['pages'])) {
1467
			unset($group['pages']);
1468
			continue;
1469
		}
1470
		foreach ($group['pages'] as $page) {
1471
			$priv = map_page_privname($page);
1472 751533a2 Phil Davis
			if ($priv) {
1473 791bcfd4 Bill Marquette
				$privs[] = $priv;
1474 751533a2 Phil Davis
			}
1475 791bcfd4 Bill Marquette
		}
1476
		unset($group['pages']);
1477
		$group['priv'] = $privs;
1478
	}
1479
1480
	/* sync all local account information */
1481
	local_sync_accounts();
1482
}
1483
1484
1485
function upgrade_050_to_051() {
1486
	global $config;
1487
	$pconfig = array();
1488 15864861 jim-p
	$pconfig['descr'] = "Set to 0 to disable filtering on the incoming and outgoing member interfaces.";
1489 791bcfd4 Bill Marquette
	$pconfig['tunable'] = "net.link.bridge.pfil_member";
1490
	$pconfig['value'] = "1";
1491
	$config['sysctl']['item'][] = $pconfig;
1492
	$pconfig = array();
1493 15864861 jim-p
	$pconfig['descr'] = "Set to 1 to enable filtering on the bridge interface";
1494 791bcfd4 Bill Marquette
	$pconfig['tunable'] = "net.link.bridge.pfil_bridge";
1495
	$pconfig['value'] = "0";
1496
	$config['sysctl']['item'][] = $pconfig;
1497
1498
	unset($config['bridge']);
1499
1500
	$convert_bridges = false;
1501 751533a2 Phil Davis
	foreach ($config['interfaces'] as $intf) {
1502 791bcfd4 Bill Marquette
		if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1503
			$config['bridges'] = array();
1504
			$config['bridges']['bridged'] = array();
1505
			$convert_bridges = true;
1506
			break;
1507
		}
1508
	}
1509
	if ($convert_bridges == true) {
1510
		$i = 0;
1511
		foreach ($config['interfaces'] as $ifr => &$intf) {
1512
			if (isset($intf['bridge']) && $intf['bridge'] <> "") {
1513
				$nbridge = array();
1514
				$nbridge['members'] = "{$ifr},{$intf['bridge']}";
1515 4d511e5b Renato Botelho
				$nbridge['descr'] = sprintf(gettext("Converted bridged %s"), $ifr);
1516 791bcfd4 Bill Marquette
				$nbridge['bridgeif'] = "bridge{$i}";
1517
				$config['bridges']['bridged'][] = $nbridge;
1518
				unset($intf['bridge']);
1519
				$i++;
1520
			}
1521
		}
1522
	}
1523
}
1524
1525
1526
function upgrade_051_to_052() {
1527
	global $config;
1528
	$config['openvpn'] = array();
1529 751533a2 Phil Davis
	if (!is_array($config['ca'])) {
1530 9ad72e5e jim-p
		$config['ca'] = array();
1531 751533a2 Phil Davis
	}
1532
	if (!is_array($config['cert'])) {
1533 9ad72e5e jim-p
		$config['cert'] = array();
1534 751533a2 Phil Davis
	}
1535 791bcfd4 Bill Marquette
1536
	$vpnid = 1;
1537
1538
	/* openvpn server configurations */
1539
	if (is_array($config['installedpackages']['openvpnserver'])) {
1540
		$config['openvpn']['openvpn-server'] = array();
1541
1542
		$index = 1;
1543 751533a2 Phil Davis
		foreach ($config['installedpackages']['openvpnserver']['config'] as $server) {
1544 791bcfd4 Bill Marquette
1545 751533a2 Phil Davis
			if (!is_array($server)) {
1546 791bcfd4 Bill Marquette
				continue;
1547 751533a2 Phil Davis
			}
1548 791bcfd4 Bill Marquette
1549
			if ($server['auth_method'] == "pki") {
1550
1551
				/* create ca entry */
1552
				$ca = array();
1553
				$ca['refid'] = uniqid();
1554 f2a86ca9 jim-p
				$ca['descr'] = "OpenVPN Server CA #{$index}";
1555 791bcfd4 Bill Marquette
				$ca['crt'] = $server['ca_cert'];
1556 9ad72e5e jim-p
				$config['ca'][] = $ca;
1557 791bcfd4 Bill Marquette
1558
				/* create ca reference */
1559
				unset($server['ca_cert']);
1560
				$server['caref'] = $ca['refid'];
1561
1562 47319bfb jim-p
				/* create a crl entry if needed */
1563 ab75b4ee jim-p
				if (!empty($server['crl'][0])) {
1564 47319bfb jim-p
					$crl = array();
1565
					$crl['refid'] = uniqid();
1566
					$crl['descr'] = "Imported OpenVPN CRL #{$index}";
1567
					$crl['caref'] = $ca['refid'];
1568 ab75b4ee jim-p
					$crl['text'] = $server['crl'][0];
1569 751533a2 Phil Davis
					if (!is_array($config['crl'])) {
1570 90e64fad Warren Baker
						$config['crl'] = array();
1571 751533a2 Phil Davis
					}
1572 fc3e88f1 jim-p
					$config['crl'][] = $crl;
1573 47319bfb jim-p
					$server['crlref'] = $crl['refid'];
1574
				}
1575
				unset($server['crl']);
1576
1577 791bcfd4 Bill Marquette
				/* create cert entry */
1578
				$cert = array();
1579
				$cert['refid'] = uniqid();
1580 f2a86ca9 jim-p
				$cert['descr'] = "OpenVPN Server Certificate #{$index}";
1581 791bcfd4 Bill Marquette
				$cert['crt'] = $server['server_cert'];
1582
				$cert['prv'] = $server['server_key'];
1583 9ad72e5e jim-p
				$config['cert'][] = $cert;
1584 791bcfd4 Bill Marquette
1585
				/* create cert reference */
1586
				unset($server['server_cert']);
1587
				unset($server['server_key']);
1588
				$server['certref'] = $cert['refid'];
1589
1590
				$index++;
1591
			}
1592
1593
			/* determine operational mode */
1594
			if ($server['auth_method'] == 'pki') {
1595 751533a2 Phil Davis
				if ($server['nopool']) {
1596 791bcfd4 Bill Marquette
					$server['mode'] = "p2p_tls";
1597
				} else {
1598
					$server['mode'] = "server_tls";
1599
				}
1600
			} else {
1601
				$server['mode'] = "p2p_shared_key";
1602
			}
1603
			unset($server['auth_method']);
1604
1605
			/* modify configuration values */
1606
			$server['dh_length'] = 1024;
1607
			unset($server['dh_params']);
1608 751533a2 Phil Davis
			if (!$server['interface']) {
1609 a15a7738 jim-p
				$server['interface'] = 'any';
1610 751533a2 Phil Davis
			}
1611 791bcfd4 Bill Marquette
			$server['tunnel_network'] = $server['addresspool'];
1612
			unset($server['addresspool']);
1613 a843870d jim-p
			if (isset($server['use_lzo']) && ($server['use_lzo'] == "on")) {
1614 8b666514 jim-p
				$server['compression'] = "on";
1615 da831323 Ermal Lu?i
				unset($server['use_lzo']);
1616
			}
1617 751533a2 Phil Davis
			if ($server['nopool']) {
1618 791bcfd4 Bill Marquette
				$server['pool_enable'] = false;
1619 751533a2 Phil Davis
			} else {
1620 791bcfd4 Bill Marquette
				$server['pool_enable'] = "yes";
1621 751533a2 Phil Davis
			}
1622 791bcfd4 Bill Marquette
			unset($server['nopool']);
1623
			$server['dns_domain'] = $server['dhcp_domainname'];
1624
			unset($server['dhcp_domainname']);
1625 c3ae41e6 jim-p
1626
			$tmparr = explode(";", $server['dhcp_dns'], 4);
1627
			$d=1;
1628
			foreach ($tmparr as $tmpa) {
1629
				$server["dns_server{$d}"] = $tmpa;
1630
				$d++;
1631
			}
1632 791bcfd4 Bill Marquette
			unset($server['dhcp_dns']);
1633 c3ae41e6 jim-p
1634
			$tmparr = explode(";", $server['dhcp_ntp'], 2);
1635
			$d=1;
1636
			foreach ($tmparr as $tmpa) {
1637
				$server["ntp_server{$d}"] = $tmpa;
1638
				$d++;
1639
			}
1640 791bcfd4 Bill Marquette
			unset($server['dhcp_ntp']);
1641 c3ae41e6 jim-p
1642 751533a2 Phil Davis
			if ($server['dhcp_nbtdisable']) {
1643 791bcfd4 Bill Marquette
				$server['netbios_enable'] = false;
1644 751533a2 Phil Davis
			} else {
1645 791bcfd4 Bill Marquette
				$server['netbios_enable'] = "yes";
1646 751533a2 Phil Davis
			}
1647 791bcfd4 Bill Marquette
			unset($server['dhcp_nbtdisable']);
1648
			$server['netbios_ntype'] = $server['dhcp_nbttype'];
1649
			unset($server['dhcp_nbttype']);
1650
			$server['netbios_scope'] = $server['dhcp_nbtscope'];
1651
			unset($server['dhcp_nbtscope']);
1652 c3ae41e6 jim-p
1653
			$tmparr = explode(";", $server['dhcp_nbdd'], 2);
1654
			$d=1;
1655
			foreach ($tmparr as $tmpa) {
1656
				$server["nbdd_server{$d}"] = $tmpa;
1657
				$d++;
1658
			}
1659 791bcfd4 Bill Marquette
			unset($server['dhcp_nbdd']);
1660 c3ae41e6 jim-p
1661
			$tmparr = explode(";", $server['dhcp_wins'], 2);
1662
			$d=1;
1663
			foreach ($tmparr as $tmpa) {
1664
				$server["wins_server{$d}"] = $tmpa;
1665
				$d++;
1666
			}
1667 791bcfd4 Bill Marquette
			unset($server['dhcp_wins']);
1668
1669 751533a2 Phil Davis
			if (!empty($server['disable'])) {
1670 763a1b52 jim-p
				$server['disable'] = true;
1671 751533a2 Phil Davis
			} else {
1672 763a1b52 jim-p
				unset($server['disable']);
1673 751533a2 Phil Davis
			}
1674 763a1b52 jim-p
1675 791bcfd4 Bill Marquette
			/* allocate vpnid */
1676
			$server['vpnid'] = $vpnid++;
1677
1678 4f1ebacb Ermal
			if (!empty($server['custom_options'])) {
1679
				$cstmopts = array();
1680
				$tmpcstmopts = explode(";", $server['custom_options']);
1681 48e24ada jim-p
				$assigned_if = "";
1682 4f1ebacb Ermal
				$tmpstr = "";
1683
				foreach ($tmpcstmopts as $tmpcstmopt) {
1684
					$tmpstr = str_replace(" ", "", $tmpcstmopt);
1685
					if (substr($tmpstr,0 ,6) == "devtun") {
1686 48e24ada jim-p
						$assigned_if = substr($tmpstr, 3);
1687 4f1ebacb Ermal
						continue;
1688 8fd0badd Ermal
					} else if (substr($tmpstr, 0, 5) == "local") {
1689 9bc27ae5 jim-p
						$localip = substr($tmpstr, 5);
1690 8fd0badd Ermal
						$server['ipaddr'] = str_replace("\n", "", $localip);
1691 751533a2 Phil Davis
					} else {
1692 4f1ebacb Ermal
						$cstmopts[] = $tmpcstmopt;
1693 751533a2 Phil Davis
					}
1694 4f1ebacb Ermal
				}
1695
				$server['custom_options'] = implode(";", $cstmopts);
1696 48e24ada jim-p
				if (!empty($assigned_if)) {
1697 4f1ebacb Ermal
					foreach ($config['interfaces'] as $iface => $cfgif) {
1698 48e24ada jim-p
						if ($cfgif['if'] == $assigned_if) {
1699 4f1ebacb Ermal
							$config['interfaces'][$iface]['if'] = "ovpns{$server['vpnid']}";
1700
							break;
1701
						}
1702
					}
1703
				}
1704
			}
1705
1706 791bcfd4 Bill Marquette
			$config['openvpn']['openvpn-server'][] = $server;
1707
		}
1708
		unset($config['installedpackages']['openvpnserver']);
1709
	}
1710
1711
	/* openvpn client configurations */
1712
	if (is_array($config['installedpackages']['openvpnclient'])) {
1713
		$config['openvpn']['openvpn-client'] = array();
1714
1715
		$index = 1;
1716 751533a2 Phil Davis
		foreach ($config['installedpackages']['openvpnclient']['config'] as $client) {
1717 791bcfd4 Bill Marquette
1718 751533a2 Phil Davis
			if (!is_array($client)) {
1719 791bcfd4 Bill Marquette
				continue;
1720 751533a2 Phil Davis
			}
1721 791bcfd4 Bill Marquette
1722
			if ($client['auth_method'] == "pki") {
1723
1724
				/* create ca entry */
1725
				$ca = array();
1726
				$ca['refid'] = uniqid();
1727 f2a86ca9 jim-p
				$ca['descr'] = "OpenVPN Client CA #{$index}";
1728 791bcfd4 Bill Marquette
				$ca['crt'] = $client['ca_cert'];
1729
				$ca['crl'] = $client['crl'];
1730 9ad72e5e jim-p
				$config['ca'][] = $ca;
1731 791bcfd4 Bill Marquette
1732
				/* create ca reference */
1733
				unset($client['ca_cert']);
1734
				unset($client['crl']);
1735
				$client['caref'] = $ca['refid'];
1736
1737
				/* create cert entry */
1738
				$cert = array();
1739
				$cert['refid'] = uniqid();
1740 f2a86ca9 jim-p
				$cert['descr'] = "OpenVPN Client Certificate #{$index}";
1741 791bcfd4 Bill Marquette
				$cert['crt'] = $client['client_cert'];
1742
				$cert['prv'] = $client['client_key'];
1743 9ad72e5e jim-p
				$config['cert'][] = $cert;
1744 791bcfd4 Bill Marquette
1745
				/* create cert reference */
1746
				unset($client['client_cert']);
1747
				unset($client['client_key']);
1748
				$client['certref'] = $cert['refid'];
1749
1750
				$index++;
1751
			}
1752
1753
			/* determine operational mode */
1754 751533a2 Phil Davis
			if ($client['auth_method'] == 'pki') {
1755 791bcfd4 Bill Marquette
				$client['mode'] = "p2p_tls";
1756 751533a2 Phil Davis
			} else {
1757 791bcfd4 Bill Marquette
				$client['mode'] = "p2p_shared_key";
1758 751533a2 Phil Davis
			}
1759 791bcfd4 Bill Marquette
			unset($client['auth_method']);
1760
1761
			/* modify configuration values */
1762 751533a2 Phil Davis
			if (!$client['interface']) {
1763 791bcfd4 Bill Marquette
				$client['interface'] = 'wan';
1764 751533a2 Phil Davis
			}
1765 791bcfd4 Bill Marquette
			$client['tunnel_network'] = $client['interface_ip'];
1766
			unset($client['interface_ip']);
1767
			$client['server_addr'] = $client['serveraddr'];
1768
			unset($client['serveraddr']);
1769
			$client['server_port'] = $client['serverport'];
1770
			unset($client['serverport']);
1771
			$client['proxy_addr'] = $client['poxy_hostname'];
1772
			unset($client['proxy_addr']);
1773 a843870d jim-p
			if (isset($client['use_lzo']) && ($client['use_lzo'] == "on")) {
1774 8b666514 jim-p
				$client['compression'] = "on";
1775 da831323 Ermal Lu?i
				unset($client['use_lzo']);
1776
			}
1777 791bcfd4 Bill Marquette
			$client['resolve_retry'] = $client['infiniteresolvretry'];
1778
			unset($client['infiniteresolvretry']);
1779
1780
			/* allocate vpnid */
1781
			$client['vpnid'] = $vpnid++;
1782
1783 4f1ebacb Ermal
			if (!empty($client['custom_options'])) {
1784
				$cstmopts = array();
1785
				$tmpcstmopts = explode(";", $client['custom_options']);
1786 48e24ada jim-p
				$assigned_if = "";
1787 4f1ebacb Ermal
				$tmpstr = "";
1788
				foreach ($tmpcstmopts as $tmpcstmopt) {
1789
					$tmpstr = str_replace(" ", "", $tmpcstmopt);
1790
					if (substr($tmpstr,0 ,6) == "devtun") {
1791 48e24ada jim-p
						$assigned_if = substr($tmpstr, 3);
1792 4f1ebacb Ermal
						continue;
1793 8fd0badd Ermal
					} else if (substr($tmpstr, 0, 5) == "local") {
1794 2d563280 Renato Botelho
						$localip = substr($tmpstr, 5);
1795
						$client['ipaddr'] = str_replace("\n", "", $localip);
1796 751533a2 Phil Davis
					} else {
1797 4f1ebacb Ermal
						$cstmopts[] = $tmpcstmopt;
1798 751533a2 Phil Davis
					}
1799 4f1ebacb Ermal
				}
1800
				$client['custom_options'] = implode(";", $cstmopts);
1801 48e24ada jim-p
				if (!empty($assigned_if)) {
1802 4f1ebacb Ermal
					foreach ($config['interfaces'] as $iface => $cfgif) {
1803 48e24ada jim-p
						if ($cfgif['if'] == $assigned_if) {
1804 4f1ebacb Ermal
							$config['interfaces'][$iface]['if'] = "ovpnc{$client['vpnid']}";
1805
							break;
1806
						}
1807
					}
1808
				}
1809
			}
1810
1811 751533a2 Phil Davis
			if (!empty($client['disable'])) {
1812 763a1b52 jim-p
				$client['disable'] = true;
1813 751533a2 Phil Davis
			} else {
1814 763a1b52 jim-p
				unset($client['disable']);
1815 751533a2 Phil Davis
			}
1816 763a1b52 jim-p
1817 791bcfd4 Bill Marquette
			$config['openvpn']['openvpn-client'][] = $client;
1818
		}
1819
1820
		unset($config['installedpackages']['openvpnclient']);
1821
	}
1822
1823
	/* openvpn client specific configurations */
1824
	if (is_array($config['installedpackages']['openvpncsc'])) {
1825
		$config['openvpn']['openvpn-csc'] = array();
1826
1827 751533a2 Phil Davis
		foreach ($config['installedpackages']['openvpncsc']['config'] as $csc) {
1828 791bcfd4 Bill Marquette
1829 751533a2 Phil Davis
			if (!is_array($csc)) {
1830 791bcfd4 Bill Marquette
				continue;
1831 751533a2 Phil Davis
			}
1832 791bcfd4 Bill Marquette
1833
			/* modify configuration values */
1834
			$csc['common_name'] = $csc['commonname'];
1835
			unset($csc['commonname']);
1836
			$csc['tunnel_network'] = $csc['ifconfig_push'];
1837
			unset($csc['ifconfig_push']);
1838
			$csc['dns_domain'] = $csc['dhcp_domainname'];
1839
			unset($csc['dhcp_domainname']);
1840 c3ae41e6 jim-p
1841
			$tmparr = explode(";", $csc['dhcp_dns'], 4);
1842
			$d=1;
1843
			foreach ($tmparr as $tmpa) {
1844
				$csc["dns_server{$d}"] = $tmpa;
1845
				$d++;
1846
			}
1847 791bcfd4 Bill Marquette
			unset($csc['dhcp_dns']);
1848 c3ae41e6 jim-p
1849
			$tmparr = explode(";", $csc['dhcp_ntp'], 2);
1850
			$d=1;
1851
			foreach ($tmparr as $tmpa) {
1852
				$csc["ntp_server{$d}"] = $tmpa;
1853
				$d++;
1854
			}
1855 791bcfd4 Bill Marquette
			unset($csc['dhcp_ntp']);
1856 c3ae41e6 jim-p
1857 751533a2 Phil Davis
			if ($csc['dhcp_nbtdisable']) {
1858 791bcfd4 Bill Marquette
				$csc['netbios_enable'] = false;
1859 751533a2 Phil Davis
			} else {
1860 791bcfd4 Bill Marquette
				$csc['netbios_enable'] = "yes";
1861 751533a2 Phil Davis
			}
1862 791bcfd4 Bill Marquette
			unset($csc['dhcp_nbtdisable']);
1863
			$csc['netbios_ntype'] = $csc['dhcp_nbttype'];
1864
			unset($csc['dhcp_nbttype']);
1865
			$csc['netbios_scope'] = $csc['dhcp_nbtscope'];
1866
			unset($csc['dhcp_nbtscope']);
1867 c3ae41e6 jim-p
1868
			$tmparr = explode(";", $csc['dhcp_nbdd'], 2);
1869
			$d=1;
1870
			foreach ($tmparr as $tmpa) {
1871
				$csc["nbdd_server{$d}"] = $tmpa;
1872
				$d++;
1873
			}
1874 791bcfd4 Bill Marquette
			unset($csc['dhcp_nbdd']);
1875 c3ae41e6 jim-p
1876
			$tmparr = explode(";", $csc['dhcp_wins'], 2);
1877
			$d=1;
1878
			foreach ($tmparr as $tmpa) {
1879
				$csc["wins_server{$d}"] = $tmpa;
1880
				$d++;
1881
			}
1882 791bcfd4 Bill Marquette
			unset($csc['dhcp_wins']);
1883
1884 751533a2 Phil Davis
			if (!empty($csc['disable'])) {
1885 1e68a58b jim-p
				$csc['disable'] = true;
1886 751533a2 Phil Davis
			} else {
1887 1e68a58b jim-p
				unset($csc['disable']);
1888 751533a2 Phil Davis
			}
1889 1e68a58b jim-p
1890 791bcfd4 Bill Marquette
			$config['openvpn']['openvpn-csc'][] = $csc;
1891
		}
1892
1893
		unset($config['installedpackages']['openvpncsc']);
1894
	}
1895
1896 c73bd8f0 Ermal Lu?i
	if (count($config['openvpn']['openvpn-server']) > 0 ||
1897 751533a2 Phil Davis
	    count($config['openvpn']['openvpn-client']) > 0) {
1898 c73bd8f0 Ermal Lu?i
		$ovpnrule = array();
1899 2d563280 Renato Botelho
		$ovpnrule['type'] = "pass";
1900
		$ovpnrule['interface'] = "openvpn";
1901
		$ovpnrule['statetype'] = "keep state";
1902
		$ovpnrule['source'] = array();
1903
		$ovpnrule['destination'] = array();
1904
		$ovpnrule['source']['any'] = true;
1905
		$ovpnrule['destination']['any'] = true;
1906
		$ovpnrule['descr'] = gettext("Auto added OpenVPN rule from config upgrade.");
1907 c73bd8f0 Ermal Lu?i
		$config['filter']['rule'][] = $ovpnrule;
1908
	}
1909
1910 791bcfd4 Bill Marquette
	/*
1911
		* FIXME: hack to keep things working with no installedpackages
1912
		* or carp array in the configuration data.
1913
		*/
1914 751533a2 Phil Davis
	if (!is_array($config['installedpackages'])) {
1915 791bcfd4 Bill Marquette
		$config['installedpackages'] = array();
1916 751533a2 Phil Davis
	}
1917
	if (!is_array($config['installedpackages']['carp'])) {
1918 791bcfd4 Bill Marquette
		$config['installedpackages']['carp'] = array();
1919 751533a2 Phil Davis
	}
1920 791bcfd4 Bill Marquette
1921
}
1922
1923
1924
function upgrade_052_to_053() {
1925
	global $config;
1926 751533a2 Phil Davis
	if (!is_array($config['ca'])) {
1927 9ad72e5e jim-p
		$config['ca'] = array();
1928 751533a2 Phil Davis
	}
1929
	if (!is_array($config['cert'])) {
1930 9ad72e5e jim-p
		$config['cert'] = array();
1931 751533a2 Phil Davis
	}
1932 791bcfd4 Bill Marquette
1933 f416763b Phil Davis
	/* migrate advanced admin page webui ssl to certificate manager */
1934 791bcfd4 Bill Marquette
	if ($config['system']['webgui']['certificate'] &&
1935 751533a2 Phil Davis
	    $config['system']['webgui']['private-key']) {
1936 791bcfd4 Bill Marquette
1937
		/* create cert entry */
1938
		$cert = array();
1939
		$cert['refid'] = uniqid();
1940 f2a86ca9 jim-p
		$cert['descr'] = "webConfigurator SSL Certificate";
1941 791bcfd4 Bill Marquette
		$cert['crt'] = $config['system']['webgui']['certificate'];
1942
		$cert['prv'] = $config['system']['webgui']['private-key'];
1943 9ad72e5e jim-p
		$config['cert'][] = $cert;
1944 791bcfd4 Bill Marquette
1945
		/* create cert reference */
1946
		unset($config['system']['webgui']['certificate']);
1947
		unset($config['system']['webgui']['private-key']);
1948
		$config['system']['webgui']['ssl-certref'] = $cert['refid'];
1949
	}
1950
1951
	/* migrate advanced admin page ssh keys to user manager */
1952
	if ($config['system']['ssh']['authorizedkeys']) {
1953
		$admin_user =& getUserEntryByUID(0);
1954
		$admin_user['authorizedkeys'] = $config['system']['ssh']['authorizedkeys'];
1955
		unset($config['system']['ssh']['authorizedkeys']);
1956
	}
1957
}
1958
1959
1960
function upgrade_053_to_054() {
1961
	global $config;
1962 751533a2 Phil Davis
	if (is_array($config['load_balancer']['lbpool'])) {
1963 38b5beaf sullrich
		$lbpool_arr = $config['load_balancer']['lbpool'];
1964 791bcfd4 Bill Marquette
		$lbpool_srv_arr = array();
1965
		$gateway_group_arr = array();
1966 816a5aff Seth Mos
		$gateways = return_gateways_array();
1967 ce107ca5 jim-p
		$group_name_changes = array();
1968 751533a2 Phil Davis
		if (! is_array($config['gateways']['gateway_item'])) {
1969 bf02c784 Ermal
			$config['gateways']['gateway_item'] = array();
1970 751533a2 Phil Davis
		}
1971 d827f9cc smos
1972 bf02c784 Ermal
		$a_gateways =& $config['gateways']['gateway_item'];
1973 751533a2 Phil Davis
		foreach ($lbpool_arr as $lbpool) {
1974
			if ($lbpool['type'] == "gateway") {
1975 ce107ca5 jim-p
				// Gateway Groups have to have valid names in pf, old lb pools did not. Clean them up.
1976 751533a2 Phil Davis
				$group_name = preg_replace("/[^A-Za-z0-9]/", "", $lbpool['name']);
1977 ce107ca5 jim-p
				// If we made and changes, check for collisions and note the change.
1978
				if ($group_name != $lbpool['name']) {
1979
					// Make sure the name isn't already in use.
1980
					foreach ($gateway_group_arr as $gwg) {
1981
						// If the name is in use, add some random bits to avoid collision.
1982 751533a2 Phil Davis
						if ($gwg['name'] == $group_name) {
1983 ce107ca5 jim-p
							$group_name .= uniqid();
1984 751533a2 Phil Davis
						}
1985 ce107ca5 jim-p
					}
1986
					$group_name_changes[$lbpool['name']] = $group_name;
1987
				}
1988
				$gateway_group['name'] = $group_name;
1989 e988813d jim-p
				$gateway_group['descr'] = $lbpool['descr'];
1990 791bcfd4 Bill Marquette
				$gateway_group['trigger'] = "down";
1991
				$gateway_group['item'] = array();
1992 cb945ced sullrich
				$i = 0;
1993 751533a2 Phil Davis
				foreach ($lbpool['servers'] as $member) {
1994 2ce660ad smos
					$split = explode("|", $member);
1995 791bcfd4 Bill Marquette
					$interface = $split[0];
1996 d9d4c637 Seth Mos
					$monitor = $split[1];
1997 2328dcc5 Seth Mos
					/* on static upgraded configuration we automatically prepend GW_ */
1998
					$static_name = "GW_" . strtoupper($interface);
1999 751533a2 Phil Davis
					if (is_ipaddr($monitor)) {
2000
						foreach ($a_gateways as & $gw) {
2001
							if ($gw['name'] == $static_name) {
2002 d2b20ab6 jim-p
								$gw['monitor'] = $monitor;
2003 751533a2 Phil Davis
							}
2004
						}
2005
					}
2006 d2b20ab6 jim-p
2007 6ee1b7eb Seth Mos
					/* on failover increment tier. Else always assign 1 */
2008 751533a2 Phil Davis
					if ($lbpool['behaviour'] == "failover") {
2009 6ee1b7eb Seth Mos
						$i++;
2010
					} else {
2011
						$i = 1;
2012
					}
2013 685a26fc smos
					$gateway_group['item'][] = "$static_name|$i";
2014 791bcfd4 Bill Marquette
				}
2015
				$gateway_group_arr[] = $gateway_group;
2016
			} else {
2017
				$lbpool_srv_arr[] = $lbpool;
2018
			}
2019
		}
2020 38b5beaf sullrich
		$config['load_balancer']['lbpool'] = $lbpool_srv_arr;
2021 791bcfd4 Bill Marquette
		$config['gateways']['gateway_group'] = $gateway_group_arr;
2022
	}
2023
	// Unset lbpool if we no longer have any server pools
2024
	if (count($lbpool_srv_arr) == 0) {
2025 751533a2 Phil Davis
		if (empty($config['load_balancer'])) {
2026 0b5b4f32 Seth Mos
			unset($config['load_balancer']);
2027 92a2ceae Seth Mos
		} else {
2028
			unset($config['load_balancer']['lbpool']);
2029 0b5b4f32 Seth Mos
		}
2030 791bcfd4 Bill Marquette
	} else {
2031
		$config['load_balancer']['lbpool'] = $lbpool_srv_arr;
2032
	}
2033
	// Only set the gateway group array if we converted any
2034
	if (count($gateway_group_arr) != 0) {
2035
		$config['gateways']['gateway_group'] = $gateway_group_arr;
2036 ce107ca5 jim-p
		// Update any rules that had a gateway change, if any.
2037 751533a2 Phil Davis
		if (count($group_name_changes) > 0) {
2038
			foreach ($config['filter']['rule'] as & $rule) {
2039
				if (!empty($rule["gateway"]) && array_key_exists($rule["gateway"], $group_name_changes)) {
2040 ce107ca5 jim-p
					$rule["gateway"] = $group_name_changes[$rule["gateway"]];
2041 751533a2 Phil Davis
				}
2042
			}
2043
		}
2044 791bcfd4 Bill Marquette
	}
2045
}
2046
2047
2048
function upgrade_054_to_055() {
2049
	global $config;
2050 54f8bad0 Seth Mos
	global $g;
2051
2052 791bcfd4 Bill Marquette
	/* RRD files changed for quality, traffic and packets graphs */
2053 59cfe65d Ermal
	//ini_set("max_execution_time", "1800");
2054 791bcfd4 Bill Marquette
	/* convert traffic RRD file */
2055
	global $parsedcfg, $listtags;
2056
	$listtags = array("ds", "v", "rra", "row");
2057
2058
	$rrddbpath = "/var/db/rrd/";
2059
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
2060 e34cf1f6 smos
	if ($g['platform'] != "pfSense") {
2061
		/* restore the databases, if we have one */
2062 8bdb6879 Darren Embry
		if (restore_rrd()) {
2063 e34cf1f6 smos
			/* Make sure to move the rrd backup out of the way. We will make a new one after converting. */
2064 8560c756 jim-p
			@rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup/rrd.tgz");
2065 e34cf1f6 smos
		}
2066
	}
2067 791bcfd4 Bill Marquette
2068
	$rrdinterval = 60;
2069
	$valid = $rrdinterval * 2;
2070
2071
	/* Asume GigE for now */
2072
	$downstream = 125000000;
2073
	$upstream = 125000000;
2074
2075
	/* build a list of quality databases */
2076
	/* roundtrip has become delay */
2077
	function divide_delay($delayval) {
2078
		$delayval = floatval($delayval);
2079
		$delayval = ($delayval / 1000);
2080
		$delayval = " ". sprintf("%1.10e", $delayval) ." ";
2081
		return $delayval;
2082
	}
2083
	/* the roundtrip times need to be divided by 1000 to get seconds, really */
2084
	$databases = array();
2085 751533a2 Phil Davis
	if (!file_exists($rrddbpath)) {
2086 af0b07d3 jim-p
		@mkdir($rrddbpath);
2087 751533a2 Phil Davis
	}
2088 4cb9abc3 jim-p
	chdir($rrddbpath);
2089
	$databases = glob("*-quality.rrd");
2090 791bcfd4 Bill Marquette
	rsort($databases);
2091 751533a2 Phil Davis
	foreach ($databases as $database) {
2092 791bcfd4 Bill Marquette
		$xmldump = "{$database}.old.xml";
2093
		$xmldumpnew = "{$database}.new.xml";
2094
2095 751533a2 Phil Davis
		if (platform_booting()) {
2096 9bc8b6b6 Seth Mos
			echo "Migrate RRD database {$database} to new format for IPv6 \n";
2097 751533a2 Phil Davis
		}
2098 791bcfd4 Bill Marquette
		mwexec("$rrdtool tune {$rrddbpath}{$database} -r roundtrip:delay 2>&1");
2099
2100
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
2101 1005d4bf Seth Mos
		$rrdold = xml2array(file_get_contents("{$g['tmp_path']}/{$xmldump}"), 1, "tag");
2102 791bcfd4 Bill Marquette
		$rrdold = $rrdold['rrd'];
2103
2104
		$i = 0;
2105 751533a2 Phil Davis
		foreach ($rrdold['rra'] as $rra) {
2106 791bcfd4 Bill Marquette
			$l = 0;
2107 751533a2 Phil Davis
			foreach ($rra['database']['row'] as $row) {
2108 791bcfd4 Bill Marquette
				$vnew = divide_delay($row['v'][1]);
2109
				$rrdold['rra'][$i]['database']['row'][$l]['v'][1] = $vnew;
2110
				$l++;
2111
			}
2112
			$i++;
2113
		}
2114
2115 56ee96ed smos
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", dump_xml_config_raw($rrdold, "rrd"));
2116 791bcfd4 Bill Marquette
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
2117
2118 1005d4bf Seth Mos
		unset($rrdold);
2119 7ceff68a Ermal LUÇI
		@unlink("{$g['tmp_path']}/{$xmldump}");
2120
		@unlink("{$g['tmp_path']}/{$xmldumpnew}");
2121 791bcfd4 Bill Marquette
	}
2122
	/* let apinger recreate required files */
2123 751533a2 Phil Davis
	if (!platform_booting()) {
2124 f29e20a3 Ermal LUÇI
		setup_gateways_monitor();
2125 751533a2 Phil Davis
	}
2126 791bcfd4 Bill Marquette
2127
	/* build a list of traffic and packets databases */
2128 84683e42 Renato Botelho
	$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
2129 791bcfd4 Bill Marquette
	rsort($databases);
2130 751533a2 Phil Davis
	foreach ($databases as $database) {
2131 791bcfd4 Bill Marquette
		$databasetmp = "{$database}.tmp";
2132
		$xmldump = "{$database}.old.xml";
2133
		$xmldumptmp = "{$database}.tmp.xml";
2134
		$xmldumpnew = "{$database}.new.xml";
2135
2136 751533a2 Phil Davis
		if (platform_booting()) {
2137 34834e7e jim-p
			echo "Migrate RRD database {$database} to new format \n";
2138 751533a2 Phil Davis
		}
2139 791bcfd4 Bill Marquette
		/* rename DS source */
2140
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r in:inpass 2>&1");
2141
		mwexec("$rrdtool tune {$rrddbpath}/{$database} -r out:outpass 2>71");
2142
2143
		/* dump contents to xml and move database out of the way */
2144
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
2145
2146
		/* create new rrd database file */
2147
		$rrdcreate = "$rrdtool create {$g['tmp_path']}/{$databasetmp} --step $rrdinterval ";
2148
		$rrdcreate .= "DS:inpass:COUNTER:$valid:0:$downstream ";
2149
		$rrdcreate .= "DS:outpass:COUNTER:$valid:0:$upstream ";
2150
		$rrdcreate .= "DS:inblock:COUNTER:$valid:0:$downstream ";
2151
		$rrdcreate .= "DS:outblock:COUNTER:$valid:0:$upstream ";
2152
		$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
2153
		$rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
2154
		$rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
2155 eb346e0b Seth Mos
		$rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
2156 791bcfd4 Bill Marquette
2157
		create_new_rrd("$rrdcreate");
2158
		/* create temporary xml from new RRD */
2159
		dump_rrd_to_xml("{$g['tmp_path']}/{$databasetmp}", "{$g['tmp_path']}/{$xmldumptmp}");
2160
2161 1005d4bf Seth Mos
		$rrdold = xml2array(file_get_contents("{$g['tmp_path']}/{$xmldump}"), 1, "tag");
2162 791bcfd4 Bill Marquette
		$rrdold = $rrdold['rrd'];
2163
2164 1005d4bf Seth Mos
		$rrdnew = xml2array(file_get_contents("{$g['tmp_path']}/{$xmldumptmp}"), 1, "tag");
2165 791bcfd4 Bill Marquette
		$rrdnew = $rrdnew['rrd'];
2166
2167
		/* remove any MAX RRA's. Not needed for traffic. */
2168
		$i = 0;
2169
		foreach ($rrdold['rra'] as $rra) {
2170 751533a2 Phil Davis
			if (trim($rra['cf']) == "MAX") {
2171 791bcfd4 Bill Marquette
				unset($rrdold['rra'][$i]);
2172
			}
2173
			$i++;
2174
		}
2175
2176 56ee96ed smos
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", dump_xml_config_raw(migrate_rrd_format($rrdold, $rrdnew), "rrd"));
2177 791bcfd4 Bill Marquette
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
2178 eb346e0b Seth Mos
		/* we now have the rrd with the new fields, adjust the size now. */
2179
		/* RRA 2 is 60 minutes, RRA 3 is 720 minutes */
2180
		mwexec("/bin/sync");
2181 12a2f395 Seth Mos
		mwexec("$rrdtool resize {$rrddbpath}/{$database} 2 GROW 2000;/bin/mv resize.rrd {$rrddbpath}/{$database} 2>&1");
2182 eb346e0b Seth Mos
		mwexec("/bin/sync");
2183 12a2f395 Seth Mos
		mwexec("$rrdtool resize {$rrddbpath}/{$database} 3 GROW 2000;/bin/mv resize.rrd {$rrddbpath}/{$database} 2>&1");
2184 1005d4bf Seth Mos
		unset($rrdxmlarray);
2185 7ceff68a Ermal LUÇI
		@unlink("{$g['tmp_path']}/{$xmldump}");
2186
		@unlink("{$g['tmp_path']}/{$xmldumpnew}");
2187 791bcfd4 Bill Marquette
	}
2188 751533a2 Phil Davis
	if (!platform_booting()) {
2189 e546d2d1 Ermal LUÇI
		enable_rrd_graphing();
2190 751533a2 Phil Davis
	}
2191 e34cf1f6 smos
	/* Let's save the RRD graphs after we run enable RRD graphing */
2192
	/* The function will restore the rrd.tgz so we will save it after */
2193 8bdb6879 Darren Embry
	exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
2194 e7f65689 Renato Botelho
	unlink_if_exists("{$g['vardb_path']}/rrd/*.xml");
2195 751533a2 Phil Davis
	if (platform_booting()) {
2196 34834e7e jim-p
		echo "Updating configuration...";
2197 751533a2 Phil Davis
	}
2198 791bcfd4 Bill Marquette
}
2199
2200
2201
function upgrade_055_to_056() {
2202
	global $config;
2203
2204 751533a2 Phil Davis
	if (!is_array($config['ca'])) {
2205 9ad72e5e jim-p
		$config['ca'] = array();
2206 751533a2 Phil Davis
	}
2207
	if (!is_array($config['cert'])) {
2208 9ad72e5e jim-p
		$config['cert'] = array();
2209 751533a2 Phil Davis
	}
2210 791bcfd4 Bill Marquette
2211
	/* migrate ipsec ca's to cert manager */
2212
	if (is_array($config['ipsec']['cacert'])) {
2213 751533a2 Phil Davis
		foreach ($config['ipsec']['cacert'] as & $cacert) {
2214 791bcfd4 Bill Marquette
			$ca = array();
2215
			$ca['refid'] = uniqid();
2216 751533a2 Phil Davis
			if (is_array($cacert['cert'])) {
2217 791bcfd4 Bill Marquette
				$ca['crt'] = $cacert['cert'][0];
2218 751533a2 Phil Davis
			} else {
2219 791bcfd4 Bill Marquette
				$ca['crt'] = $cacert['cert'];
2220 751533a2 Phil Davis
			}
2221 f2a86ca9 jim-p
			$ca['descr'] = $cacert['ident'];
2222 9ad72e5e jim-p
			$config['ca'][] = $ca;
2223 791bcfd4 Bill Marquette
		}
2224
		unset($config['ipsec']['cacert']);
2225
	}
2226
2227
	/* migrate phase1 certificates to cert manager */
2228
	if (is_array($config['ipsec']['phase1'])) {
2229 751533a2 Phil Davis
		foreach ($config['ipsec']['phase1'] as & $ph1ent) {
2230 791bcfd4 Bill Marquette
			$cert = array();
2231
			$cert['refid'] = uniqid();
2232 f2a86ca9 jim-p
			$cert['descr'] = "IPsec Peer {$ph1ent['remote-gateway']} Certificate";
2233 751533a2 Phil Davis
			if (is_array($ph1ent['cert'])) {
2234 791bcfd4 Bill Marquette
				$cert['crt'] = $ph1ent['cert'][0];
2235 751533a2 Phil Davis
			} else {
2236 791bcfd4 Bill Marquette
				$cert['crt'] = $ph1ent['cert'];
2237 751533a2 Phil Davis
			}
2238 791bcfd4 Bill Marquette
			$cert['prv'] = $ph1ent['private-key'];
2239 9ad72e5e jim-p
			$config['cert'][] = $cert;
2240 791bcfd4 Bill Marquette
			$ph1ent['certref'] = $cert['refid'];
2241 751533a2 Phil Davis
			if ($ph1ent['cert']) {
2242 791bcfd4 Bill Marquette
				unset($ph1ent['cert']);
2243 751533a2 Phil Davis
			}
2244
			if ($ph1ent['private-key']) {
2245 791bcfd4 Bill Marquette
				unset($ph1ent['private-key']);
2246 751533a2 Phil Davis
			}
2247
			if ($ph1ent['peercert']) {
2248 791bcfd4 Bill Marquette
				unset($ph1ent['peercert']);
2249 751533a2 Phil Davis
			}
2250 791bcfd4 Bill Marquette
		}
2251
	}
2252
}
2253
2254
2255
function upgrade_056_to_057() {
2256
	global $config;
2257 84924e76 Ermal
2258 751533a2 Phil Davis
	if (!is_array($config['system']['user'])) {
2259 4830e56a Erik Fonnesbeck
		$config['system']['user'] = array();
2260 751533a2 Phil Davis
	}
2261 791bcfd4 Bill Marquette
	/* migrate captivate portal to user manager */
2262
	if (is_array($config['captiveportal']['user'])) {
2263 751533a2 Phil Davis
		foreach ($config['captiveportal']['user'] as $user) {
2264 791bcfd4 Bill Marquette
			// avoid user conflicts
2265 4830e56a Erik Fonnesbeck
			$found = false;
2266
			foreach ($config['system']['user'] as $userent) {
2267
				if ($userent['name'] == $user['name']) {
2268
					$found = true;
2269
					break;
2270
				}
2271
			}
2272 751533a2 Phil Davis
			if ($found) {
2273 791bcfd4 Bill Marquette
				continue;
2274 751533a2 Phil Davis
			}
2275 791bcfd4 Bill Marquette
			$user['scope'] = "user";
2276
			if (isset($user['expirationdate'])) {
2277
				$user['expires'] = $user['expirationdate'];
2278
				unset($user['expirationdate']);
2279
			}
2280
			if (isset($user['password'])) {
2281
				$user['md5-hash'] = $user['password'];
2282
				unset($user['password']);
2283
			}
2284 4830e56a Erik Fonnesbeck
			$user['uid'] = $config['system']['nextuid']++;
2285 791bcfd4 Bill Marquette
			$config['system']['user'][] = $user;
2286
		}
2287
		unset($config['captiveportal']['user']);
2288
	}
2289
}
2290 4b96b367 mgrooms
2291
function upgrade_057_to_058() {
2292
	global $config;
2293
	/* set all phase2 entries to tunnel mode */
2294 751533a2 Phil Davis
	if (is_array($config['ipsec']['phase2'])) {
2295
		foreach ($config['ipsec']['phase2'] as & $ph2ent) {
2296 4b96b367 mgrooms
			$ph2ent['mode'] = 'tunnel';
2297 751533a2 Phil Davis
		}
2298
	}
2299 4b96b367 mgrooms
}
2300 60120e37 Ermal Lu?i
2301
function upgrade_058_to_059() {
2302
	global $config;
2303
2304
	if (is_array($config['schedules']['schedule'])) {
2305 751533a2 Phil Davis
		foreach ($config['schedules']['schedule'] as & $schedl) {
2306 60120e37 Ermal Lu?i
			$schedl['schedlabel'] = uniqid();
2307 751533a2 Phil Davis
		}
2308 60120e37 Ermal Lu?i
	}
2309
}
2310 2523c923 Seth Mos
2311
function upgrade_059_to_060() {
2312 fcf5afa0 Seth Mos
	global $config;
2313 a0588fad Scott Ullrich
	require_once("/etc/inc/certs.inc");
2314 9ad72e5e jim-p
	if (is_array($config['ca'])) {
2315 2cf6ddcb Nigel Graham
		/* Locate issuer for all CAs */
2316 9ad72e5e jim-p
		foreach ($config['ca'] as & $ca) {
2317 2cf6ddcb Nigel Graham
			$subject = cert_get_subject($ca['crt']);
2318
			$issuer = cert_get_issuer($ca['crt']);
2319 751533a2 Phil Davis
			if ($issuer <> $subject) {
2320 2cf6ddcb Nigel Graham
				$issuer_crt =& lookup_ca_by_subject($issuer);
2321 751533a2 Phil Davis
				if ($issuer_crt) {
2322 2cf6ddcb Nigel Graham
					$ca['caref'] = $issuer_crt['refid'];
2323 751533a2 Phil Davis
				}
2324 2cf6ddcb Nigel Graham
			}
2325
		}
2326 2d563280 Renato Botelho
2327 2cf6ddcb Nigel Graham
		/* Locate issuer for all certificates */
2328 9ad72e5e jim-p
		if (is_array($config['cert'])) {
2329
			foreach ($config['cert'] as & $cert) {
2330 2cf6ddcb Nigel Graham
				$subject = cert_get_subject($cert['crt']);
2331
				$issuer = cert_get_issuer($cert['crt']);
2332 751533a2 Phil Davis
				if ($issuer <> $subject) {
2333 2cf6ddcb Nigel Graham
					$issuer_crt =& lookup_ca_by_subject($issuer);
2334 751533a2 Phil Davis
					if ($issuer_crt) {
2335 2cf6ddcb Nigel Graham
						$cert['caref'] = $issuer_crt['refid'];
2336 751533a2 Phil Davis
					}
2337 2cf6ddcb Nigel Graham
				}
2338
			}
2339 9d3dab70 Scott Ullrich
		}
2340 2cf6ddcb Nigel Graham
	}
2341
}
2342 d43ad788 Scott Ullrich
2343 6a688547 Ermal
function upgrade_060_to_061() {
2344
	global $config;
2345 3cfa11c2 Scott Ullrich
2346 751533a2 Phil Davis
	if (is_array($config['interfaces']['wan'])) {
2347 6a688547 Ermal
		$config['interfaces']['wan']['enable'] = true;
2348 751533a2 Phil Davis
	}
2349
	if (is_array($config['interfaces']['lan'])) {
2350 6a688547 Ermal
		$config['interfaces']['lan']['enable'] = true;
2351 751533a2 Phil Davis
	}
2352 1cad6f6c jim-p
2353
	/* On 1.2.3 the "mtu" field adjusted MSS.
2354
	   On 2.x the "mtu" field is actually the MTU. Rename accordingly.
2355
	   See redmine ticket #1886
2356
	*/
2357
	foreach ($config['interfaces'] as $ifr => &$intf) {
2358
		if (isset($intf['mtu']) && is_numeric($intf['mtu'])) {
2359
			$intf['mss'] = $intf['mtu'];
2360
			unset($intf['mtu']);
2361
		}
2362
	}
2363 6a688547 Ermal
}
2364 3cfa11c2 Scott Ullrich
2365 59ecde49 Renato Botelho
function upgrade_061_to_062() {
2366
	global $config;
2367
2368
	/* Convert NAT port forwarding rules */
2369
	if (is_array($config['nat']['rule'])) {
2370
		$a_nat = &$config['nat']['rule'];
2371
2372
		foreach ($a_nat as &$natent) {
2373
			$natent['disabled'] = false;
2374
			$natent['nordr']    = false;
2375
2376
			$natent['source'] = array(
2377
				"not"     => false,
2378
				"any"     => true,
2379
				"port"    => ""
2380
			);
2381
2382
			$natent['destination'] = array(
2383
				"not"     => false,
2384
				"address" => $natent['external-address'],
2385
				"port"    => $natent['external-port']
2386
			);
2387
2388 743ce9f8 Erik Fonnesbeck
			if (empty($natent['destination']['address'])) {
2389 fcf4e8cd Erik Fonnesbeck
				unset($natent['destination']['address']);
2390
				$natent['destination']['network'] = $natent['interface'] . 'ip';
2391 743ce9f8 Erik Fonnesbeck
			} else if ($natent['destination']['address'] == 'any') {
2392
				unset($natent['destination']['address']);
2393
				$natent['destination']['any'] = true;
2394
			}
2395
2396 59ecde49 Renato Botelho
			unset($natent['external-address']);
2397
			unset($natent['external-port']);
2398
		}
2399
2400
		unset($natent);
2401
	}
2402
}
2403
2404 0f8266ed smos
function upgrade_062_to_063() {
2405 168a1e48 smos
	/* Upgrade legacy Themes to the new pfsense_ng */
2406
	global $config;
2407
2408 751533a2 Phil Davis
	switch ($config['theme']) {
2409 1852fef0 smos
		case "nervecenter":
2410 168a1e48 smos
			$config['theme'] = "pfsense_ng";
2411
			break;
2412
	}
2413 2d563280 Renato Botelho
2414 168a1e48 smos
}
2415 c2b2b571 gnhb
2416
function upgrade_063_to_064() {
2417
	global $config;
2418 d09ca87e gnhb
	$j=0;
2419
	$ifcfg = &$config['interfaces'];
2420 2d563280 Renato Botelho
2421
	if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
2422 c2b2b571 gnhb
		foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
2423 d09ca87e gnhb
			$config['ppps']['ppp'][$pppid]['if'] = "ppp".$j;
2424
			$config['ppps']['ppp'][$pppid]['ptpid'] = $j;
2425
			$j++;
2426 751533a2 Phil Davis
			if (isset($ppp['port'])) {
2427 c2b2b571 gnhb
				$config['ppps']['ppp'][$pppid]['ports'] = $ppp['port'];
2428
				unset($config['ppps']['ppp'][$pppid]['port']);
2429
			}
2430 751533a2 Phil Davis
			if (!isset($ppp['type'])) {
2431 c2b2b571 gnhb
				$config['ppps']['ppp'][$pppid]['type'] = "ppp";
2432
			}
2433 751533a2 Phil Davis
			if (isset($ppp['defaultgw'])) {
2434 6fdfa8fb gnhb
				unset($config['ppps']['ppp'][$pppid]['defaultgw']);
2435 751533a2 Phil Davis
			}
2436 c2b2b571 gnhb
		}
2437
	}
2438 2d563280 Renato Botelho
2439 751533a2 Phil Davis
	if (!is_array($config['ppps']['ppp'])) {
2440 c2b2b571 gnhb
		$config['ppps']['ppp'] = array();
2441 751533a2 Phil Davis
	}
2442 c2b2b571 gnhb
	$a_ppps = &$config['ppps']['ppp'];
2443
2444
	foreach ($ifcfg as $ifname => $ifinfo) {
2445
		$ppp = array();
2446
		// For pppoe conversion
2447 751533a2 Phil Davis
		if ($ifinfo['ipaddr'] == "pppoe" || $ifinfo['ipaddr'] == "pptp") {
2448
			if (isset($ifinfo['ptpid'])) {
2449 c2b2b571 gnhb
				continue;
2450 751533a2 Phil Davis
			}
2451 d09ca87e gnhb
			$ppp['ptpid'] =  $j;
2452 c2b2b571 gnhb
			$ppp['type'] = $ifinfo['ipaddr'];
2453 d09ca87e gnhb
			$ppp['if'] = $ifinfo['ipaddr'].$j;
2454 c2b2b571 gnhb
			$ppp['ports'] = $ifinfo['if'];
2455 751533a2 Phil Davis
			if ($ifinfo['ipaddr'] == "pppoe") {
2456 c2b2b571 gnhb
				$ppp['username'] = $ifinfo['pppoe_username'];
2457
				$ppp['password'] = base64_encode($ifinfo['pppoe_password']);
2458
			}
2459 751533a2 Phil Davis
			if ($ifinfo['ipaddr'] == "pptp") {
2460 c2b2b571 gnhb
				$ppp['username'] = $ifinfo['pptp_username'];
2461
				$ppp['password'] = base64_encode($ifinfo['pptp_password']);
2462
			}
2463 2d563280 Renato Botelho
2464 751533a2 Phil Davis
			if (isset($ifinfo['provider'])) {
2465 c2b2b571 gnhb
				$ppp['provider'] = $ifinfo['provider'];
2466 751533a2 Phil Davis
			}
2467
			if (isset($ifinfo['ondemand'])) {
2468 c2b2b571 gnhb
				$ppp['ondemand'] = true;
2469 751533a2 Phil Davis
			}
2470
			if (isset($ifinfo['timeout'])) {
2471 c2b2b571 gnhb
				$ppp['idletimeout'] = $ifinfo['timeout'];
2472 751533a2 Phil Davis
			}
2473
			if (isset($ifinfo['pppoe']['pppoe-reset-type'])) {
2474 c2b2b571 gnhb
				$ppp['pppoe-reset-type'] = $ifinfo['pppoe']['pppoe-reset-type'];
2475
				if (is_array($config['cron']['item'])) {
2476
					for ($i = 0; $i < count($config['cron']['item']); $i++) {
2477
						$item = $config['cron']['item'][$i];
2478 751533a2 Phil Davis
						if (strpos($item['command'], "/conf/pppoe{$ifname}restart") !== false) {
2479 f7480829 gnhb
							$config['cron']['item'][$i]['command'] = "/var/etc/pppoe_restart_" . $ppp['if'];
2480 751533a2 Phil Davis
						}
2481 c2b2b571 gnhb
					}
2482
				}
2483
			}
2484 751533a2 Phil Davis
			if (isset($ifinfo['local'])) {
2485 c2b2b571 gnhb
				$ppp['localip'] = $ifinfo['local'];
2486 751533a2 Phil Davis
			}
2487
			if (isset($ifinfo['subnet'])) {
2488 c2b2b571 gnhb
				$ppp['subnet'] = $ifinfo['subnet'];
2489 751533a2 Phil Davis
			}
2490
			if (isset($ifinfo['remote'])) {
2491 c2b2b571 gnhb
				$ppp['gateway'] = $ifinfo['remote'];
2492 751533a2 Phil Davis
			}
2493 f7480829 gnhb
2494 d09ca87e gnhb
			$ifcfg[$ifname]['if'] = $ifinfo['ipaddr'].$j;
2495
			$j++;
2496 2d563280 Renato Botelho
2497 c2b2b571 gnhb
			unset($ifcfg[$ifname]['pppoe_username']);
2498
			unset($ifcfg[$ifname]['pppoe_password']);
2499
			unset($ifcfg[$ifname]['provider']);
2500
			unset($ifcfg[$ifname]['ondemand']);
2501
			unset($ifcfg[$ifname]['timeout']);
2502
			unset($ifcfg[$ifname]['pppoe_reset']);
2503
			unset($ifcfg[$ifname]['pppoe_preset']);
2504
			unset($ifcfg[$ifname]['pppoe']);
2505
			unset($ifcfg[$ifname]['pptp_username']);
2506
			unset($ifcfg[$ifname]['pptp_password']);
2507
			unset($ifcfg[$ifname]['local']);
2508
			unset($ifcfg[$ifname]['subnet']);
2509
			unset($ifcfg[$ifname]['remote']);
2510 2d563280 Renato Botelho
2511 c2b2b571 gnhb
			$a_ppps[] = $ppp;
2512 2d563280 Renato Botelho
2513 c2b2b571 gnhb
		}
2514
	}
2515
}
2516
2517 56a5a0ab jim-p
function upgrade_064_to_065() {
2518
	/* Disable TSO and LRO in upgraded configs */
2519
	global $config;
2520
	$config['system']['disablesegmentationoffloading'] = true;
2521
	$config['system']['disablelargereceiveoffloading'] = true;
2522
}
2523
2524 2f06cc3f Ermal
function upgrade_065_to_066() {
2525
	global $config;
2526
2527
	$dhcrelaycfg =& $config['dhcrelay'];
2528
2529 2d563280 Renato Botelho
	if (is_array($dhcrelaycfg)) {
2530
		$dhcrelayifs = array();
2531 2f06cc3f Ermal
		$foundifs = false;
2532 2d563280 Renato Botelho
		/* DHCPRelay enabled on any interfaces? */
2533
		foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
2534
			if (isset($dhcrelayifconf['enable'])) {
2535 2f06cc3f Ermal
				$dhcrelayifs[] = $dhcrelayif;
2536
				unset($dhcrelaycfg['dhcrelayif']);
2537
				$foundifs = true;
2538
			}
2539 2d563280 Renato Botelho
		}
2540 751533a2 Phil Davis
		if ($foundifs == true) {
2541 2f06cc3f Ermal
			$dhcrelaycfg['interface'] = implode(",", $dhcrelayifs);
2542 751533a2 Phil Davis
		}
2543 2d563280 Renato Botelho
	}
2544 2f06cc3f Ermal
}
2545
2546 9ad72e5e jim-p
function upgrade_066_to_067() {
2547
	global $config;
2548
	if (isset($config['system']['ca'])) {
2549
		$config['ca'] = $config['system']['ca'];
2550
	}
2551
	if (isset($config['system']['cert'])) {
2552
		$config['cert'] = $config['system']['cert'];
2553
	}
2554
}
2555
2556 6ae9f9b7 Ermal
function upgrade_067_to_068() {
2557
	global $config;
2558
2559
	if (!empty($config['pppoe'])) {
2560
		$config['pppoes'] = array();
2561
		$config['pppoes']['pppoe'] = array();
2562
		$config['pppoes']['pppoe'][] = $config['pppoe'][0];
2563 ce968051 Ermal
2564
		if (is_array($config['pppoe']['user'])) {
2565 2d563280 Renato Botelho
			$username = array();
2566 ce968051 Ermal
			foreach ($config['pppoe']['user'] as $user) {
2567 2fc29020 Ermal
				$usr = $user['name'] . ":" . base64_encode($user['password']);
2568 751533a2 Phil Davis
				if ($user['ip']) {
2569 ce968051 Ermal
					$usr .= ":{$user['ip']}";
2570 751533a2 Phil Davis
				}
2571 ce968051 Ermal
				$username[] = $usr;
2572
			}
2573
			$config['pppoes']['pppoe'][0]['username'] = implode(" ", $username);
2574
		}
2575 6ae9f9b7 Ermal
		unset($config['pppoe']);
2576
	}
2577
}
2578
2579 18de0728 Ermal
function upgrade_068_to_069() {
2580 8fefb9dd jim-p
	global $config;
2581 751533a2 Phil Davis
	if (!is_array($config['system']['user'])) {
2582 8fefb9dd jim-p
		return;
2583 751533a2 Phil Davis
	}
2584 8fefb9dd jim-p
	foreach ($config['system']['user'] as & $user) {
2585 751533a2 Phil Davis
		if (!is_array($user['cert'])) {
2586 8fefb9dd jim-p
			continue;
2587 751533a2 Phil Davis
		}
2588 8fefb9dd jim-p
		$rids = array();
2589
		foreach ($user['cert'] as $id => $cert) {
2590 751533a2 Phil Davis
			if (!isset($cert['descr'])) {
2591 8fefb9dd jim-p
				continue;
2592 751533a2 Phil Davis
			}
2593 8fefb9dd jim-p
			$tcert = $cert;
2594
			// Make sure each cert gets a refid
2595 751533a2 Phil Davis
			if (!isset($tcert['refid'])) {
2596 8fefb9dd jim-p
				$tcert['refid'] = uniqid();
2597 751533a2 Phil Davis
			}
2598 8fefb9dd jim-p
			// Keep the cert references for this user
2599
			$rids[] = $tcert['refid'];
2600
			$config['cert'][] = $tcert;
2601
		}
2602
		// Replace user certs with cert references instead.
2603 751533a2 Phil Davis
		if (count($rids) > 0) {
2604 8fefb9dd jim-p
			$user['cert'] = $rids;
2605 751533a2 Phil Davis
		}
2606 8fefb9dd jim-p
	}
2607
}
2608
2609 4c5b8653 Erik Fonnesbeck
function upgrade_069_to_070() {
2610
	global $config;
2611
2612
	/* Convert NAT 1:1 rules */
2613
	if (is_array($config['nat']['onetoone'])) {
2614 a3bac4ce Ermal
		foreach ($config['nat']['onetoone'] as $nidx => $natent) {
2615 751533a2 Phil Davis
			if ($natent['subnet'] == 32) {
2616 a3bac4ce Ermal
				$config['nat']['onetoone'][$nidx]['source'] = array("address" => $natent['internal']);
2617 751533a2 Phil Davis
			} else {
2618 a3bac4ce Ermal
				$config['nat']['onetoone'][$nidx]['source'] = array("address" => $natent['internal'] . "/" . $natent['subnet']);
2619 751533a2 Phil Davis
			}
2620 4c5b8653 Erik Fonnesbeck
2621 a3bac4ce Ermal
			$config['nat']['onetoone'][$nidx]['destination'] = array("any" => true);
2622 4c5b8653 Erik Fonnesbeck
2623 a3bac4ce Ermal
			unset($config['nat']['onetoone'][$nidx]['internal']);
2624
			unset($config['nat']['onetoone'][$nidx]['subnet']);
2625 4c5b8653 Erik Fonnesbeck
		}
2626
2627
		unset($natent);
2628
	}
2629
}
2630
2631 65167fcc Ermal
function upgrade_070_to_071() {
2632
	global $config;
2633
2634
	if (is_array($config['cron']['item'])) {
2635 751533a2 Phil Davis
		foreach ($config['cron']['item'] as $idx => $cronitem) {
2636
			if (stristr($cronitem['command'], "checkreload.sh")) {
2637 65167fcc Ermal
				unset($config['cron']['item'][$idx]);
2638
				break;
2639
			}
2640
		}
2641
	}
2642
}
2643 15864861 jim-p
2644 6751b3e7 jim-p
function rename_field(& $section, $oldname, $newname) {
2645 e988813d jim-p
	if (is_array($section)) {
2646 751533a2 Phil Davis
		foreach ($section as & $item) {
2647
			if (is_array($item) && !empty($item[$oldname])) {
2648 6751b3e7 jim-p
				$item[$newname] = $item[$oldname];
2649 751533a2 Phil Davis
			}
2650
			if (is_array($item) && isset($item[$oldname])) {
2651 6751b3e7 jim-p
				unset($item[$oldname]);
2652 751533a2 Phil Davis
			}
2653 e988813d jim-p
		}
2654
	}
2655
}
2656
2657 6751b3e7 jim-p
function upgrade_071_to_072() {
2658
	global $config;
2659 751533a2 Phil Davis
	if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) {
2660 6bef0554 jim-p
		rename_field($config['sysctl']['item'], 'desc', 'descr');
2661 751533a2 Phil Davis
	}
2662 6751b3e7 jim-p
}
2663
2664 e988813d jim-p
function upgrade_072_to_073() {
2665
	global $config;
2666 751533a2 Phil Davis
	if (!is_array($config['load_balancer'])) {
2667 6bef0554 jim-p
		return;
2668 751533a2 Phil Davis
	}
2669
	if (is_array($config['load_balancer']['monitor_type'])) {
2670 6bef0554 jim-p
		rename_field($config['load_balancer']['monitor_type'], 'desc', 'descr');
2671 751533a2 Phil Davis
	}
2672
	if (is_array($config['load_balancer']['lbpool'])) {
2673 6bef0554 jim-p
		rename_field($config['load_balancer']['lbpool'], 'desc', 'descr');
2674 751533a2 Phil Davis
	}
2675
	if (is_array($config['load_balancer']['lbaction'])) {
2676 6bef0554 jim-p
		rename_field($config['load_balancer']['lbaction'], 'desc', 'descr');
2677 751533a2 Phil Davis
	}
2678
	if (is_array($config['load_balancer']['lbprotocol'])) {
2679 6bef0554 jim-p
		rename_field($config['load_balancer']['lbprotocol'], 'desc', 'descr');
2680 751533a2 Phil Davis
	}
2681
	if (is_array($config['load_balancer']['virtual_server'])) {
2682 6bef0554 jim-p
		rename_field($config['load_balancer']['virtual_server'], 'desc', 'descr');
2683 751533a2 Phil Davis
	}
2684 e988813d jim-p
}
2685 9ff73b79 jim-p
2686
function upgrade_073_to_074() {
2687
	global $config;
2688 6751b3e7 jim-p
	rename_field($config['system']['user'], 'fullname', 'descr');
2689 9ff73b79 jim-p
}
2690 f2a86ca9 jim-p
2691
function upgrade_074_to_075() {
2692
	global $config;
2693 751533a2 Phil Davis
	if (is_array($config['ca'])) {
2694 6bef0554 jim-p
		rename_field($config['ca'], 'name', 'descr');
2695 751533a2 Phil Davis
	}
2696
	if (is_array($config['cert'])) {
2697 6bef0554 jim-p
		rename_field($config['cert'], 'name', 'descr');
2698 751533a2 Phil Davis
	}
2699
	if (is_array($config['crl'])) {
2700 6bef0554 jim-p
		rename_field($config['crl'], 'name', 'descr');
2701 751533a2 Phil Davis
	}
2702 f2a86ca9 jim-p
}
2703 9734b054 Scott Ullrich
2704 d0dc2fd1 jim-p
function upgrade_075_to_076() {
2705 7d9b3d5e jim-p
	global $config;
2706
	$cron_item = array();
2707
	$cron_item['minute'] = "30";
2708
	$cron_item['hour'] = "12";
2709
	$cron_item['mday'] = "*";
2710
	$cron_item['month'] = "*";
2711
	$cron_item['wday'] = "*";
2712
	$cron_item['who'] = "root";
2713
	$cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.update_urltables";
2714
	$config['cron']['item'][] = $cron_item;
2715 d0dc2fd1 jim-p
}
2716
2717 9bc8b6b6 Seth Mos
function upgrade_076_to_077() {
2718 9956b38a Seth Mos
	global $config;
2719 751533a2 Phil Davis
	foreach ($config['filter']['rule'] as & $rule) {
2720
		if (isset($rule['protocol']) && !empty($rule['protocol'])) {
2721
			$rule['protocol'] = strtolower($rule['protocol']);
2722
		}
2723 9956b38a Seth Mos
	}
2724
}
2725
2726
function upgrade_077_to_078() {
2727 f33030aa jim-p
	global $config;
2728 751533a2 Phil Davis
	if (is_array($config['pptpd']) && is_array($config['pptpd']['radius']) &&
2729
	    !is_array($config['pptpd']['radius']['server'])) {
2730 7171b7b6 jim-p
		$radarr = array();
2731
		$radsvr = array();
2732
		$radsvr['ip'] = $config['pptpd']['radius']['server'];
2733
		$radsvr['secret'] = $config['pptpd']['radius']['secret'];
2734
		$radsvr['port'] = 1812;
2735
		$radsvr['acctport'] = 1813;
2736
		$radsvr['enable'] = isset($config['pptpd']['radius']['enable']);
2737
		$radarr['accounting'] = isset($config['pptpd']['radius']['accounting']);
2738 751533a2 Phil Davis
		if ($radarr['accounting']) {
2739 7171b7b6 jim-p
			$radarr['acct_update'] = $radsvr['ip'];
2740 751533a2 Phil Davis
		}
2741 7171b7b6 jim-p
		$radarr['server'] = $radsvr;
2742
		$config['pptpd']['radius'] = $radarr;
2743
	}
2744 f7c8f633 jim-p
	if (is_array($config['pptpd'])) {
2745
		$config['pptpd']['n_pptp_units'] = empty($config['pptpd']['n_pptp_units']) ? 16 : $config['pptpd']['n_pptp_units'];
2746
	}
2747 7171b7b6 jim-p
}
2748 27d0722d jim-p
function upgrade_078_to_079() {
2749 838e4eb8 Warren Baker
	global $g;
2750 5c723d9f Warren Baker
	/* Delete old and unused RRD file */
2751 838e4eb8 Warren Baker
	unlink_if_exists("{$g['vardb_path']}/rrd/captiveportal-totalusers.rrd");
2752 5c723d9f Warren Baker
}
2753
2754 58005e52 jim-p
function upgrade_079_to_080() {
2755 9bc8b6b6 Seth Mos
	global $config;
2756 e6ee8fc6 Ermal
2757 f416763b Phil Davis
	/* Upgrade config in 1.2.3 specifying a username other than admin for syncing. */
2758 e6ee8fc6 Ermal
	if (!empty($config['system']['username']) && is_array($config['installedpackages']['carpsettings']) &&
2759 751533a2 Phil Davis
	    is_array($config['installedpackages']['carpsettings']['config'])) {
2760 e6ee8fc6 Ermal
		$config['installedpackages']['carpsettings']['config'][0]['username'] = $config['system']['username'];
2761
		unset($config['system']['username']);
2762
	}
2763
}
2764
2765 e49d4564 jim-p
function upgrade_080_to_081() {
2766
	global $config;
2767 9bc8b6b6 Seth Mos
	global $g;
2768 ff6677cf smos
	/* Welcome to the 2.1 migration path */
2769
2770
	/* tag all the existing gateways as being IPv4 */
2771
	$i = 0;
2772 751533a2 Phil Davis
	if (is_array($config['gateways']['gateway_item'])) {
2773
		foreach ($config['gateways']['gateway_item'] as $gw) {
2774 ff6677cf smos
			$config['gateways']['gateway_item'][$i]['ipprotocol'] = "inet";
2775
			$i++;
2776
		}
2777
	}
2778 9bc8b6b6 Seth Mos
2779
	/* RRD files changed for quality, traffic and packets graphs */
2780
	/* convert traffic RRD file */
2781
	global $parsedcfg, $listtags;
2782
	$listtags = array("ds", "v", "rra", "row");
2783
2784
	$rrddbpath = "/var/db/rrd/";
2785
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
2786
2787 42ec9337 Renato Botelho
	if ($g['platform'] != "pfSense") {
2788
		/* restore the databases, if we have one */
2789
		if (restore_rrd()) {
2790
			/* Make sure to move the rrd backup out of the way. We will make a new one after converting. */
2791 e1854cad jim-p
			@rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup/rrd.tgz");
2792 42ec9337 Renato Botelho
		}
2793
	}
2794
2795 9bc8b6b6 Seth Mos
	$rrdinterval = 60;
2796
	$valid = $rrdinterval * 2;
2797
2798
	/* Asume GigE for now */
2799
	$downstream = 125000000;
2800
	$upstream = 125000000;
2801
2802
	/* build a list of traffic and packets databases */
2803 84683e42 Renato Botelho
	$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
2804 9bc8b6b6 Seth Mos
	rsort($databases);
2805 751533a2 Phil Davis
	foreach ($databases as $database) {
2806 9bc8b6b6 Seth Mos
		$xmldump = "{$database}.old.xml";
2807
		$xmldumpnew = "{$database}.new.xml";
2808
2809 751533a2 Phil Davis
		if (platform_booting()) {
2810 d55ea970 Seth Mos
			echo "Migrate RRD database {$database} to new format for IPv6.\n";
2811 751533a2 Phil Davis
		}
2812 9bc8b6b6 Seth Mos
2813
		/* dump contents to xml and move database out of the way */
2814
		dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}");
2815
2816 fcaa56b1 smos
		/* search and replace tags to add data sources */
2817
		$ds_search = "<!-- Round Robin Archives -->";
2818
		$ds_arr = array();
2819
		$ds_arr[] = "	<ds>
2820
				<name> inpass6 </name>
2821
				<type> COUNTER </type>
2822
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2823
				<min> 0.0000000000e+00 </min>
2824
				<max> 1.2500000000e+08 </max>
2825
2826
				<!-- PDP Status -->
2827
				<last_ds> 0 </last_ds>
2828
				<value> NaN </value>
2829
				<unknown_sec> 3 </unknown_sec>
2830
			</ds>
2831
			";
2832
		$ds_arr[] = "	<ds>
2833
				<name> outpass6 </name>
2834
				<type> COUNTER </type>
2835
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2836
				<min> 0.0000000000e+00 </min>
2837
				<max> 1.2500000000e+08 </max>
2838
2839
				<!-- PDP Status -->
2840
				<last_ds> 0 </last_ds>
2841
				<value> NaN </value>
2842
				<unknown_sec> 3 </unknown_sec>
2843
			</ds>
2844
			";
2845
		$ds_arr[] = "	<ds>
2846
				<name> inblock6 </name>
2847
				<type> COUNTER </type>
2848
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2849
				<min> 0.0000000000e+00 </min>
2850
				<max> 1.2500000000e+08 </max>
2851
2852
				<!-- PDP Status -->
2853
				<last_ds> 0 </last_ds>
2854
				<value> NaN </value>
2855
				<unknown_sec> 3 </unknown_sec>
2856
			</ds>
2857
			";
2858
		$ds_arr[] = "	<ds>
2859
				<name> outblock6 </name>
2860
				<type> COUNTER </type>
2861
				<minimal_heartbeat> {$valid} </minimal_heartbeat>
2862
				<min> 0.0000000000e+00 </min>
2863
				<max> 1.2500000000e+08 </max>
2864
2865
				<!-- PDP Status -->
2866
				<last_ds> 0 </last_ds>
2867
				<value> NaN </value>
2868
				<unknown_sec> 3 </unknown_sec>
2869
			</ds>
2870
			";
2871
2872
		$cdp_search = "<\/cdp_prep>";
2873
		$cdp_replace = "</cdp_prep>";
2874
		$cdp_arr = array();
2875
		$cdp_arr[] = "			<ds>
2876
					<primary_value> NaN </primary_value>
2877
					<secondary_value> 0.0000000000e+00 </secondary_value>
2878
					<value> NaN </value>
2879
					<unknown_datapoints> 0 </unknown_datapoints>
2880
					</ds>
2881
		";
2882
		$cdp_arr[] = "			<ds>
2883
					<primary_value> NaN </primary_value>
2884
					<secondary_value> 0.0000000000e+00 </secondary_value>
2885
					<value> NaN </value>
2886
					<unknown_datapoints> 0 </unknown_datapoints>
2887
					</ds>
2888
		";
2889
		$cdp_arr[] = "			<ds>
2890
					<primary_value> NaN </primary_value>
2891
					<secondary_value> 0.0000000000e+00 </secondary_value>
2892
					<value> NaN </value>
2893
					<unknown_datapoints> 0 </unknown_datapoints>
2894
					</ds>
2895
		";
2896
		$cdp_arr[] = "			<ds>
2897
					<primary_value> NaN </primary_value>
2898
					<secondary_value> 0.0000000000e+00 </secondary_value>
2899
					<value> NaN </value>
2900
					<unknown_datapoints> 0 </unknown_datapoints>
2901
					</ds>
2902
		";
2903
2904
		$value_search = "<\/row>";
2905
		$value_replace = "</row>";
2906
		$value = "<v> NaN </v>";
2907
2908
		$xml = file_get_contents("{$g['tmp_path']}/{$xmldump}");
2909 751533a2 Phil Davis
		foreach ($ds_arr as $ds) {
2910 fcaa56b1 smos
			$xml = preg_replace("/$ds_search/s", "$ds{$ds_search}", $xml);
2911
		}
2912 751533a2 Phil Davis
		foreach ($cdp_arr as $cdp) {
2913 fcaa56b1 smos
			$xml = preg_replace("/$cdp_search/s", "$cdp{$cdp_replace}", $xml);
2914
		}
2915 751533a2 Phil Davis
		foreach ($ds_arr as $ds) {
2916 fcaa56b1 smos
			$xml = preg_replace("/$value_search/s", "$value{$value_replace}", $xml);
2917
		}
2918 751533a2 Phil Davis
2919 fcaa56b1 smos
		file_put_contents("{$g['tmp_path']}/{$xmldumpnew}", $xml);
2920
		mwexec("$rrdtool restore -f {$g['tmp_path']}/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1");
2921
		unset($xml);
2922 73c569ea Xon
		# Default /tmp tmpfs is ~40mb, do not leave temp files around
2923 48047e3f Renato Botelho
		unlink_if_exists("{$g['tmp_path']}/{$xmldump}");
2924
		unlink_if_exists("{$g['tmp_path']}/{$xmldumpnew}");
2925 9bc8b6b6 Seth Mos
	}
2926 751533a2 Phil Davis
	if (!platform_booting()) {
2927 e546d2d1 Ermal LUÇI
		enable_rrd_graphing();
2928 751533a2 Phil Davis
	}
2929 42ec9337 Renato Botelho
	/* Let's save the RRD graphs after we run enable RRD graphing */
2930
	/* The function will restore the rrd.tgz so we will save it after */
2931
	exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
2932 751533a2 Phil Davis
	if (platform_booting()) {
2933 9bc8b6b6 Seth Mos
		echo "Updating configuration...";
2934 751533a2 Phil Davis
	}
2935
	foreach ($config['filter']['rule'] as & $rule) {
2936
		if (isset($rule['protocol']) && !empty($rule['protocol'])) {
2937 1c1a74fa jim-p
			$rule['protocol'] = strtolower($rule['protocol']);
2938 751533a2 Phil Davis
		}
2939 7ec0e6e2 jim-p
	}
2940 17640b28 Ermal
	unset($rule);
2941 9bc8b6b6 Seth Mos
}
2942
2943 e49d4564 jim-p
function upgrade_081_to_082() {
2944 4cdf35a4 Chris Buechler
	/* don't enable the allow IPv6 toggle */
2945 1f116988 Seth Mos
}
2946 b4792bf8 Ermal
2947
function upgrade_082_to_083() {
2948
	global $config;
2949 7b47bd4c Ermal
2950 b4792bf8 Ermal
	/* Upgrade captiveportal config */
2951
	if (!empty($config['captiveportal'])) {
2952
		$tmpcp = $config['captiveportal'];
2953
		$config['captiveportal'] = array();
2954 17640b28 Ermal
		$config['captiveportal']['cpzone'] = array();
2955
		$config['captiveportal']['cpzone'] = $tmpcp;
2956
		$config['captiveportal']['cpzone']['zoneid'] = 8000;
2957 26b6e758 jim-p
		$config['captiveportal']['cpzone']['zone'] = "cpzone";
2958 751533a2 Phil Davis
		if ($config['captiveportal']['cpzone']['auth_method'] == "radius") {
2959 2d72659a Renato Botelho
			$config['captiveportal']['cpzone']['radius_protocol'] = "PAP";
2960 751533a2 Phil Davis
		}
2961 b4792bf8 Ermal
	}
2962 67e73dcd Ermal
	if (!empty($config['voucher'])) {
2963
		$tmpcp = $config['voucher'];
2964
		$config['voucher'] = array();
2965 17640b28 Ermal
		$config['voucher']['cpzone'] = array();
2966
		$config['voucher']['cpzone'] = $tmpcp;
2967 67e73dcd Ermal
	}
2968 b4792bf8 Ermal
}
2969 67e73dcd Ermal
2970 f97a5b04 Darren Embry
function upgrade_083_to_084() {
2971
	global $config;
2972
	if (!isset($config['hasync'])) {
2973
		if (!empty($config['installedpackages']) &&
2974
		    !empty($config['installedpackages']['carpsettings']) &&
2975
		    !empty($config['installedpackages']['carpsettings']['config'])) {
2976
			$config['hasync'] = $config['installedpackages']['carpsettings']['config'][0];
2977
			unset($config['installedpackages']['carpsettings']);
2978
		}
2979
		if (empty($config['installedpackages']['carpsettings'])) {
2980
			unset($config['installedpackages']['carpsettings']);
2981
		}
2982
		if (empty($config['installedpackages'])) {
2983
			unset($config['installedpackages']);
2984
		}
2985
	}
2986
}
2987
2988 c3ce2ece smos
function upgrade_084_to_085() {
2989
	global $config;
2990
2991
	$gateway_group_arr = array();
2992
	$gateways = return_gateways_array();
2993
	$oldnames = array();
2994
	/* setup translation array */
2995 751533a2 Phil Davis
	foreach ($gateways as $name => $gw) {
2996
		if (isset($gw['dynamic'])) {
2997 c3ce2ece smos
			$oldname = strtoupper($config['interfaces'][$gw['friendlyiface']]['descr']);
2998 2d563280 Renato Botelho
			$oldnames[$oldname] = $name;
2999 c3ce2ece smos
		} else {
3000
			$oldnames[$name] = $name;
3001
		}
3002
	}
3003
3004
	/* process the old array */
3005 751533a2 Phil Davis
	if (is_array($config['gateways']['gateway_group'])) {
3006 c3ce2ece smos
		$group_array_new = array();
3007 751533a2 Phil Davis
		foreach ($config['gateways']['gateway_group'] as $name => $group) {
3008
			if (is_array($group['item'])) {
3009 c3ce2ece smos
				$newlist = array();
3010 751533a2 Phil Davis
				foreach ($group['item'] as $entry) {
3011 c3ce2ece smos
					$elements = explode("|", $entry);
3012 751533a2 Phil Davis
					if ($oldnames[$elements[0]] <> "") {
3013 c3ce2ece smos
						$newlist[] = "{$oldnames[$elements[0]]}|{$elements[1]}";
3014 da12a8a4 smos
					} else {
3015
						$newlist[] = "{$elements[0]}|{$elements[1]}";
3016 c3ce2ece smos
					}
3017
				}
3018
				$group['item'] = $newlist;
3019
				$group_array_new[$name] = $group;
3020
			}
3021
		}
3022
		$config['gateways']['gateway_group'] = $group_array_new;
3023
	}
3024 d4d5f7b4 smos
	/* rename old Quality RRD files in the process */
3025
	$rrddbpath = "/var/db/rrd";
3026 751533a2 Phil Davis
	foreach ($oldnames as $old => $new) {
3027
		if (is_readable("{$rrddbpath}/{$old}-quality.rrd")) {
3028 17640b28 Ermal
			@rename("{$rrddbpath}/{$old}-quality.rrd", "{$rrddbpath}/{$new}-quality.rrd");
3029 d4d5f7b4 smos
		}
3030
	}
3031 17640b28 Ermal
	unset($gateways, $oldnames, $gateway_group_arr);
3032 c3ce2ece smos
}
3033
3034 b22fc825 jim-p
function upgrade_085_to_086() {
3035 879f7db7 Erik Fonnesbeck
	global $config, $g;
3036 b22fc825 jim-p
3037
	/* XXX: Gross hacks in sight */
3038 12766374 Erik Fonnesbeck
	if (is_array($config['virtualip']['vip'])) {
3039 b22fc825 jim-p
		$vipchg = array();
3040 12766374 Erik Fonnesbeck
		foreach ($config['virtualip']['vip'] as $vip) {
3041 751533a2 Phil Davis
			if ($vip['mode'] != "carp") {
3042 fbda07b9 Ermal
				continue;
3043 751533a2 Phil Davis
			}
3044 f2cc3344 Renato Botelho
			$config = array_replace_values_recursive(
3045
				$config,
3046
				'^vip' . $vip['vhid'] . '$',
3047
				"{$vip['interface']}_vip{$vip['vhid']}"
3048
			);
3049 fe47f1f2 Erik Fonnesbeck
		}
3050 b22fc825 jim-p
	}
3051
}
3052
3053 85a236e9 Ermal
function upgrade_086_to_087() {
3054
	global $config, $dummynet_pipe_list;
3055
3056 751533a2 Phil Davis
	if (!is_array($config['filter']) || !is_array($config['filter']['rule'])) {
3057 85a236e9 Ermal
		return;
3058 751533a2 Phil Davis
	}
3059
	if (!is_array($config['dnshaper']) || !is_array($config['dnshaper']['queue'])) {
3060 85a236e9 Ermal
		return;
3061 751533a2 Phil Davis
	}
3062 85a236e9 Ermal
3063
	$dnqueue_number = 1;
3064
	$dnpipe_number = 1;
3065
3066
	foreach ($config['dnshaper']['queue'] as $idx => $dnpipe) {
3067
		$config['dnshaper']['queue'][$idx]['number'] = $dnpipe_number;
3068
		$dnpipe_number++;
3069
		if (is_array($dnpipe['queue'])) {
3070
			foreach ($dnpipe['queue'] as $qidx => $dnqueue) {
3071
				$config['dnshaper']['queue'][$idx]['queue'][$qidx]['number'] = $dnqueue_number;
3072
				$dnqueue_number++;
3073
			}
3074
		}
3075
	}
3076
3077
	unset($dnqueue_number, $dnpipe_number, $qidx, $idx, $dnpipe, $dnqueue);
3078
3079
	require_once("shaper.inc");
3080
	read_dummynet_config();
3081
3082 628306af Ermal
	$dn_list = array();
3083 2d563280 Renato Botelho
	if (is_array($dummynet_pipe_list)) {
3084
		foreach ($dummynet_pipe_list as $dn) {
3085
			$tmplist =& $dn->get_queue_list();
3086
			foreach ($tmplist as $qname => $link) {
3087
				$dn_list[$link] = $qname;
3088
			}
3089
		}
3090 17640b28 Ermal
		unset($dummynet_pipe_list);
3091 2d563280 Renato Botelho
	}
3092 628306af Ermal
3093 85a236e9 Ermal
	foreach ($config['filter']['rule'] as $idx => $rule) {
3094
		if (!empty($rule['dnpipe'])) {
3095 751533a2 Phil Davis
			if (!empty($dn_list[$rule['dnpipe']])) {
3096 628306af Ermal
				$config['filter']['rule'][$idx]['dnpipe'] = $dn_list[$rule['dnpipe']];
3097 751533a2 Phil Davis
			}
3098 85a236e9 Ermal
		}
3099
		if (!empty($rule['pdnpipe'])) {
3100 751533a2 Phil Davis
			if (!empty($dn_list[$rule['pdnpipe']])) {
3101 628306af Ermal
				$config['filter']['rule'][$idx]['pdnpipe'] = $dn_list[$rule['pdnpipe']];
3102 751533a2 Phil Davis
			}
3103 85a236e9 Ermal
		}
3104
	}
3105
}
3106 7530177c jim-p
function upgrade_087_to_088() {
3107
	global $config;
3108
	if (isset($config['system']['glxsb_enable'])) {
3109
		unset($config['system']['glxsb_enable']);
3110
		$config['system']['crypto_hardware'] = "glxsb";
3111
	}
3112
}
3113 36f6ed35 bcyrill
3114
function upgrade_088_to_089() {
3115 2d563280 Renato Botelho
	global $config;
3116 751533a2 Phil Davis
	if (!is_array($config['ca'])) {
3117 2d563280 Renato Botelho
		$config['ca'] = array();
3118 751533a2 Phil Davis
	}
3119
	if (!is_array($config['cert'])) {
3120 2d563280 Renato Botelho
		$config['cert'] = array();
3121 751533a2 Phil Davis
	}
3122 2d563280 Renato Botelho
3123 f416763b Phil Davis
	/* migrate captive portal ssl to certificate manager */
3124 2d563280 Renato Botelho
	if (is_array($config['captiveportal'])) {
3125
		foreach ($config['captiveportal'] as $id => &$setting) {
3126
			if (isset($setting['httpslogin'])) {
3127
				/* create cert entry */
3128
				$cert = array();
3129
				$cert['refid'] = uniqid();
3130
				$cert['descr'] = "Captive Portal Cert - {$setting['zone']}";
3131
				$cert['crt'] = $setting['certificate'];
3132
				$cert['prv'] = $setting['private-key'];
3133
3134
				if (!empty($setting['cacertificate'])) {
3135
					/* create ca entry */
3136
					$ca = array();
3137
					$ca['refid'] = uniqid();
3138
					$ca['descr'] = "Captive Portal CA - {$setting['zone']}";
3139
					$ca['crt'] = $setting['cacertificate'];
3140
					$config['ca'][] = $ca;
3141
3142
					/* add ca reference to certificate */
3143
					$cert['caref'] = $ca['refid'];
3144
				}
3145
3146
				$config['cert'][] = $cert;
3147
3148
				/* create cert reference */
3149
				$setting['certref'] = $cert['refid'];
3150
3151
				unset($setting['certificate']);
3152
				unset($setting['private-key']);
3153
				unset($setting['cacertificate']);
3154
3155
			}
3156
		}
3157
	}
3158 36f6ed35 bcyrill
}
3159 2d563280 Renato Botelho
3160 6e9b046e jim-p
function upgrade_089_to_090() {
3161
	global $config;
3162
	if (is_array($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server'])) {
3163
		$vs_a = &$config['load_balancer']['virtual_server'];
3164
		for ($i = 0; isset($vs_a[$i]); $i++) {
3165
			if (is_array($vs_a[$i]['pool'])) {
3166
				$vs_a[$i]['poolname'] = $vs_a[$i]['pool'][0];
3167
				unset($vs_a[$i]['pool']);
3168
			} elseif (!empty($vs_a[$i]['pool'])) {
3169
				$vs_a[$i]['poolname'] = $vs_a[$i]['pool'];
3170
				unset($vs_a[$i]['pool']);
3171
			}
3172
		}
3173
	}
3174
}
3175 c9ba2f8a Ermal
3176
function upgrade_090_to_091() {
3177
	global $config;
3178
3179
	if (is_array($config['dnshaper']) && is_array($config['dnshaper']['queue'])) {
3180
		foreach ($config['dnshaper']['queue'] as $idx => $dnqueue) {
3181
			if (!empty($dnqueue['bandwidth'])) {
3182
				$bw = array();
3183
				$bw['bw'] = $dnqueue['bandwidth'];
3184
				$bw['bwscale'] = $dnqueue['bandwidthtype'];
3185
				$bw['bwsched'] = "none";
3186
				$config['dnshaper']['queue'][$idx]['bandwidth'] = array();
3187
				$config['dnshaper']['queue'][$idx]['bandwidth']['item'] = array();
3188
				$config['dnshaper']['queue'][$idx]['bandwidth']['item'][] = $bw;
3189
			}
3190
		}
3191
	}
3192
}
3193 e99ba2d6 Renato Botelho
3194
function upgrade_091_to_092() {
3195
	global $config;
3196
3197
	if (is_array($config['nat']['advancedoutbound']) && is_array($config['nat']['advancedoutbound']['rule'])) {
3198
		$nat_rules = &$config['nat']['advancedoutbound']['rule'];
3199
		for ($i = 0; isset($nat_rules[$i]); $i++) {
3200
			if (empty($nat_rules[$i]['interface'])) {
3201
				$nat_rules[$i]['interface'] = 'wan';
3202
			}
3203
		}
3204
	}
3205
}
3206 2d563280 Renato Botelho
3207 cba9d7d9 Renato Botelho
function upgrade_092_to_093() {
3208
	global $g;
3209
3210
	$suffixes = array("concurrent", "loggedin");
3211
3212 751533a2 Phil Davis
	foreach ($suffixes as $suffix) {
3213
		if (file_exists("{$g['vardb_path']}/rrd/captiveportal-{$suffix}.rrd")) {
3214 cba9d7d9 Renato Botelho
			rename("{$g['vardb_path']}/rrd/captiveportal-{$suffix}.rrd",
3215
				"{$g['vardb_path']}/rrd/captiveportal-cpZone-{$suffix}.rrd");
3216 751533a2 Phil Davis
		}
3217
	}
3218 cba9d7d9 Renato Botelho
3219 751533a2 Phil Davis
	if (!platform_booting()) {
3220 e546d2d1 Ermal LUÇI
		enable_rrd_graphing();
3221 751533a2 Phil Davis
	}
3222 cba9d7d9 Renato Botelho
}
3223
3224 6015f75b N0YB
function upgrade_093_to_094() {
3225
	global $config;
3226
3227
	if (isset($config['system']['powerd_mode'])) {
3228
		$config['system']['powerd_ac_mode'] = $config['system']['powerd_mode'];
3229
		$config['system']['powerd_battery_mode'] = $config['system']['powerd_mode'];
3230
		unset($config['system']['powerd_mode']);
3231
	}
3232
}
3233
3234 02203e6d Renato Botelho
function upgrade_094_to_095() {
3235
	global $config;
3236
3237 751533a2 Phil Davis
	if (!isset($config['interfaces']) || !is_array($config['interfaces'])) {
3238 02203e6d Renato Botelho
		return;
3239 751533a2 Phil Davis
	}
3240 02203e6d Renato Botelho
3241 751533a2 Phil Davis
	foreach ($config['interfaces'] as $iface => $cfg) {
3242
		if (isset($cfg['ipaddrv6']) && ($cfg['ipaddrv6'] == "track6")) {
3243
			if (!isset($cfg['track6-prefix-id']) || ($cfg['track6-prefix-id'] == "")) {
3244 02203e6d Renato Botelho
				$config['interfaces'][$iface]['track6-prefix-id'] = 0;
3245 751533a2 Phil Davis
			}
3246
		}
3247
	}
3248 02203e6d Renato Botelho
}
3249
3250 fa3b33a5 Renato Botelho
function upgrade_095_to_096() {
3251
	global $config, $g;
3252
3253
	$names = array("inpass", "outpass", "inblock", "outblock",
3254
		"inpass6", "outpass6", "inblock6", "outblock6");
3255
	$rrddbpath = "/var/db/rrd";
3256
	$rrdtool = "/usr/local/bin/rrdtool";
3257
3258 42ec9337 Renato Botelho
	if ($g['platform'] != "pfSense") {
3259
		/* restore the databases, if we have one */
3260
		if (restore_rrd()) {
3261
			/* Make sure to move the rrd backup out of the way. We will make a new one after converting. */
3262 8560c756 jim-p
			@rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup/rrd.tgz");
3263 42ec9337 Renato Botelho
		}
3264
	}
3265
3266 fa3b33a5 Renato Botelho
	/* Assume 2*10GigE for now */
3267
	$stream = 2500000000;
3268
3269
	/* build a list of traffic and packets databases */
3270
	$databases = return_dir_as_array($rrddbpath, '/-(traffic|packets)\.rrd$/');
3271
	rsort($databases);
3272 751533a2 Phil Davis
	foreach ($databases as $database) {
3273
		if (platform_booting()) {
3274 fa3b33a5 Renato Botelho
			echo "Update RRD database {$database}.\n";
3275 751533a2 Phil Davis
		}
3276 fa3b33a5 Renato Botelho
3277
		$cmd = "{$rrdtool} tune {$rrddbpath}/{$database}";
3278 751533a2 Phil Davis
		foreach ($names as $name) {
3279 fa3b33a5 Renato Botelho
			$cmd .= " -a {$name}:{$stream}";
3280 751533a2 Phil Davis
		}
3281 fa3b33a5 Renato Botelho
		mwexec("{$cmd} 2>&1");
3282
3283
	}
3284 751533a2 Phil Davis
	if (!platform_booting()) {
3285 e546d2d1 Ermal LUÇI
		enable_rrd_graphing();
3286 751533a2 Phil Davis
	}
3287 42ec9337 Renato Botelho
	/* Let's save the RRD graphs after we run enable RRD graphing */
3288
	/* The function will restore the rrd.tgz so we will save it after */
3289
	exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh");
3290 fa3b33a5 Renato Botelho
}
3291
3292 1cf24f0a jim-p
function upgrade_096_to_097() {
3293
	global $config, $g;
3294
	/* If the user had disabled default block rule logging before, then bogon/private network logging was already off, so respect their choice. */
3295
	if (isset($config['syslog']['nologdefaultblock'])) {
3296
		$config['syslog']['nologbogons'] = true;
3297
		$config['syslog']['nologprivatenets'] = true;
3298
	}
3299
}
3300 af0a477a Renato Botelho
3301
function upgrade_097_to_098() {
3302
	global $config, $g;
3303
	/* Disable kill_states by default */
3304
	$config['system']['kill_states'] = true;
3305
}
3306 67e5e3c6 Renato Botelho
3307
function upgrade_098_to_099() {
3308 a3cc1409 jim-p
	global $config;
3309 759a6fcf Ermal
3310 751533a2 Phil Davis
	if (empty($config['dhcpd']) || !is_array($config['dhcpd'])) {
3311 759a6fcf Ermal
		return;
3312 751533a2 Phil Davis
	}
3313 759a6fcf Ermal
3314 a3cc1409 jim-p
	foreach ($config['dhcpd'] as & $dhcpifconf) {
3315
		if (isset($dhcpifconf['next-server'])) {
3316
			$dhcpifconf['nextserver'] = $dhcpifconf['next-server'];
3317 aa0753e3 jim-p
			unset($dhcpifconf['next-server']);
3318 a3cc1409 jim-p
		}
3319
	}
3320
}
3321
3322
function upgrade_099_to_100() {
3323
	require_once("/etc/inc/services.inc");
3324
	install_cron_job("/usr/bin/nice -n20 newsyslog", false);
3325
}
3326
3327 20dad315 Ermal
function upgrade_100_to_101() {
3328
	global $config, $g;
3329
3330 751533a2 Phil Davis
	if (!is_array($config['voucher'])) {
3331 20dad315 Ermal
		return;
3332 751533a2 Phil Davis
	}
3333 20dad315 Ermal
3334
	foreach ($config['voucher'] as $cpzone => $cp) {
3335 751533a2 Phil Davis
		if (!is_array($cp['roll'])) {
3336 20dad315 Ermal
			continue;
3337 751533a2 Phil Davis
		}
3338 20dad315 Ermal
		foreach ($cp['roll'] as $ridx => $rcfg) {
3339 751533a2 Phil Davis
			if (!empty($rcfg['comment'])) {
3340 20dad315 Ermal
				$config['voucher'][$cpzone]['roll'][$ridx]['descr'] = $rcfg['comment'];
3341 751533a2 Phil Davis
			}
3342 20dad315 Ermal
		}
3343
	}
3344
}
3345
3346 eae91304 Ermal
function upgrade_101_to_102() {
3347 67e5e3c6 Renato Botelho
	global $config, $g;
3348
3349 ee34e137 Phil Davis
	if (is_array($config['captiveportal'])) {
3350
		foreach ($config['captiveportal'] as $cpzone => $cp) {
3351 751533a2 Phil Davis
			if (!is_array($cp['passthrumac'])) {
3352 ee34e137 Phil Davis
				continue;
3353 751533a2 Phil Davis
			}
3354 67e5e3c6 Renato Botelho
3355 751533a2 Phil Davis
			foreach ($cp['passthrumac'] as $idx => $passthrumac) {
3356 ee34e137 Phil Davis
				$config['captiveportal'][$cpzone]['passthrumac'][$idx]['action'] = 'pass';
3357 751533a2 Phil Davis
			}
3358 ee34e137 Phil Davis
		}
3359 67e5e3c6 Renato Botelho
	}
3360 edba1982 jim-p
3361 eae91304 Ermal
	/* Convert OpenVPN Compression option to the new style */
3362 edba1982 jim-p
	// Nothing to do if there is no OpenVPN tag
3363 ee34e137 Phil Davis
	if (isset($config['openvpn']) && is_array($config['openvpn'])) {
3364
		if (is_array($config['openvpn']['openvpn-server'])) {
3365
			foreach ($config['openvpn']['openvpn-server'] as &$vpn) {
3366 751533a2 Phil Davis
				if (!empty($vpn['compression'])) {
3367 ee34e137 Phil Davis
					$vpn['compression'] = "adaptive";
3368 751533a2 Phil Davis
				}
3369 ee34e137 Phil Davis
			}
3370 edba1982 jim-p
		}
3371 ee34e137 Phil Davis
		if (is_array($config['openvpn']['openvpn-client'])) {
3372
			foreach ($config['openvpn']['openvpn-client'] as &$vpn) {
3373 751533a2 Phil Davis
				if (!empty($vpn['compression'])) {
3374 ee34e137 Phil Davis
					$vpn['compression'] = "adaptive";
3375 751533a2 Phil Davis
				}
3376 ee34e137 Phil Davis
			}
3377 edba1982 jim-p
		}
3378
	}
3379
}
3380 eef01b14 Renato Botelho
3381
function upgrade_102_to_103() {
3382
	global $config;
3383
3384
	if (isset($config['nat']['advancedoutbound']['enable'])) {
3385
		$config['nat']['advancedoutbound']['mode'] = "advanced";
3386
		unset($config['nat']['advancedoutbound']['enable']);
3387 751533a2 Phil Davis
	} else {
3388 eef01b14 Renato Botelho
		$config['nat']['advancedoutbound']['mode'] = "automatic";
3389 751533a2 Phil Davis
	}
3390 eef01b14 Renato Botelho
3391
	$config['nat']['outbound'] = $config['nat']['advancedoutbound'];
3392
3393
	unset($config['nat']['ipsecpassthru']);
3394
	unset($config['nat']['advancedoutbound']);
3395
}
3396
3397 7997ed44 Renato Botelho
function upgrade_103_to_104() {
3398
	global $config;
3399
3400
	$changed_privs = array(
3401
		"page-diag-system-activity" => "page-diagnostics-system-activity",
3402
		"page-interfacess-groups" => "page-interfaces-groups",
3403
		"page-interfacess-lagg" => "page-interfaces-lagg",
3404
		"page-interfacess-qinq" => "page-interfaces-qinq"
3405
	);
3406
3407
	/* update user privileges */
3408
	foreach ($config['system']['user'] as & $user) {
3409 751533a2 Phil Davis
		if (!is_array($user['priv'])) {
3410 7997ed44 Renato Botelho
			continue;
3411 751533a2 Phil Davis
		}
3412 7997ed44 Renato Botelho
		foreach ($user['priv'] as & $priv) {
3413 751533a2 Phil Davis
			if (array_key_exists($priv, $changed_privs)) {
3414 7997ed44 Renato Botelho
				$priv = $changed_privs[$priv];
3415 751533a2 Phil Davis
			}
3416 7997ed44 Renato Botelho
		}
3417
	}
3418
3419
	/* update group privileges */
3420
	foreach ($config['system']['group'] as & $group) {
3421 751533a2 Phil Davis
		if (!is_array($group['priv'])) {
3422 7997ed44 Renato Botelho
			continue;
3423 751533a2 Phil Davis
		}
3424 7997ed44 Renato Botelho
		foreach ($group['priv'] as & $priv) {
3425 751533a2 Phil Davis
			if (array_key_exists($priv, $changed_privs)) {
3426 7997ed44 Renato Botelho
				$priv = $changed_privs[$priv];
3427 751533a2 Phil Davis
			}
3428 7997ed44 Renato Botelho
		}
3429
	}
3430
3431
	/* sync all local account information */
3432
	local_sync_accounts();
3433
}
3434
3435 0a806969 Ermal
function upgrade_104_to_105() {
3436
	global $config;
3437
3438
	if (is_array($config['captiveportal'])) {
3439
		$zoneid = 2;
3440
		foreach ($config['captiveportal'] as $cpzone => $cpcfg) {
3441
			if (empty($cpfg['zoneid'])) {
3442
				$config['captiveportal'][$cpzone]['zoneid'] = $zoneid;
3443
				$zoneid += 2;
3444
			} else if ($cpcfg['zoneid'] > 4000) {
3445
				$config['captiveportal'][$cpzone]['zoneid'] = $zoneid;
3446
				$zoneid += 2;
3447
			}
3448
		}
3449
	}
3450
}
3451
3452 e7d35d84 Ermal
function upgrade_105_to_106() {
3453
3454 6f55af1c Ermal
	/* NOTE: This entry can be reused for something else since the upgrade code was reverted */
3455 e7d35d84 Ermal
}
3456
3457 31dce430 Ermal
function upgrade_106_to_107() {
3458
	global $config;
3459
3460
	if (is_array($config['filter']) && is_array($config['filter']['rule'])) {
3461
		$tracker = (int)microtime(true);
3462
		foreach ($config['filter']['rule'] as $ridx => $rule) {
3463
			if (empty($rule['tracker'])) {
3464
				$config['filter']['rule'][$ridx]['tracker'] = $tracker;
3465
				$tracker++;
3466
			}
3467
		}
3468
		unset($tracker, $ridx);
3469
	}
3470
	if (is_array($config['nat']) && is_array($config['nat']['rule'])) {
3471
		$tracker = (int)microtime(true);
3472
		foreach ($config['nat']['rule'] as $ridx => $rule) {
3473
			if (empty($rule['tracker'])) {
3474
				$config['nat']['rule'][$ridx]['tracker'] = $tracker;
3475
				$tracker++;
3476
			}
3477
		}
3478
		unset($tracker, $ridx);
3479
	}
3480
}
3481
3482 08f30320 Renato Botelho
function upgrade_107_to_108() {
3483
	global $config;
3484
3485 751533a2 Phil Davis
	if (isset($config['system']['webgui']['noautocomplete'])) {
3486 08f30320 Renato Botelho
		unset($config['system']['webgui']['noautocomplete']);
3487 751533a2 Phil Davis
	} else {
3488 08f30320 Renato Botelho
		$config['system']['webgui']['loginautocomplete'] = true;
3489 751533a2 Phil Davis
	}
3490 08f30320 Renato Botelho
}
3491
3492 c15b5ed8 Renato Botelho
function upgrade_108_to_109() {
3493
	global $config;
3494
3495 751533a2 Phil Davis
	if (!isset($config['filter']['rule']) || !is_array($config['filter']['rule'])) {
3496 c15b5ed8 Renato Botelho
		return;
3497 751533a2 Phil Davis
	}
3498 c15b5ed8 Renato Botelho
3499
	foreach ($config['filter']['rule'] as &$rule) {
3500 751533a2 Phil Davis
		if (!isset($rule['dscp']) || empty($rule['dscp'])) {
3501 c15b5ed8 Renato Botelho
			continue;
3502 751533a2 Phil Davis
		}
3503 c15b5ed8 Renato Botelho
3504
		$pos = strpos($rule['dscp'], ' ');
3505 751533a2 Phil Davis
		if ($pos !== false) {
3506 c15b5ed8 Renato Botelho
			$rule['dscp'] = substr($rule['dscp'], 0, $pos);
3507 751533a2 Phil Davis
		}
3508 c15b5ed8 Renato Botelho
		unset($pos);
3509
	}
3510
}
3511
3512 9b915686 Ermal
function upgrade_109_to_110() {
3513
	global $config;
3514
3515 751533a2 Phil Davis
	if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2'])) {
3516 9b915686 Ermal
		return;
3517 751533a2 Phil Davis
	}
3518 9b915686 Ermal
3519
	foreach ($config['ipsec']['phase2'] as &$rule) {
3520 751533a2 Phil Davis
		if (!empty($rule['uniqid'])) {
3521 9b915686 Ermal
			continue;
3522 751533a2 Phil Davis
		}
3523 9b915686 Ermal
3524
		$rule['uniqid'] = uniqid();
3525
	}
3526
}
3527
3528 3f257101 Renato Botelho
function upgrade_110_to_111() {
3529
	global $config;
3530
3531 bdbb4dba Renato Botelho
	/* Make sure unbound user exist */
3532
	mwexec('/usr/sbin/pw groupadd -n unbound -g 59', true);
3533
	mwexec('/usr/sbin/pw useradd -n unbound -c "Unbound DNS Resolver" -d /var/unbound -s /usr/sbin/nologin -u 59 -g 59', true);
3534
3535 c11b7ffe Renato Botelho
	/* cleanup old unbound package stuffs */
3536
	unlink_if_exists("/usr/local/pkg/unbound.xml");
3537
	unlink_if_exists("/usr/local/pkg/unbound.inc");
3538
	unlink_if_exists("/usr/local/pkg/unbound_advanced.xml");
3539
	unlink_if_exists("/usr/local/www/unbound_status.php");
3540
	unlink_if_exists("/usr/local/www/unbound_acls.php");
3541
	unlink_if_exists("/usr/local/bin/unbound_monitor.sh");
3542 b4db2d0e Renato Botelho
	unlink_if_exists("/usr/local/etc/rc.d/unbound.sh");
3543 c11b7ffe Renato Botelho
3544
	/* Remove old menu and service entries */
3545
	if (isset($config['installedpackages']['menu']) && is_array($config['installedpackages']['menu'])) {
3546
		foreach ($config['installedpackages']['menu'] as $idx => $menu) {
3547 751533a2 Phil Davis
			if ($menu['name'] != 'Unbound DNS') {
3548 c11b7ffe Renato Botelho
				continue;
3549 751533a2 Phil Davis
			}
3550 c11b7ffe Renato Botelho
3551
			unset($config['installedpackages']['menu'][$idx]);
3552
			break;
3553
		}
3554
	}
3555
3556
	if (isset($config['installedpackages']['service']) && is_array($config['installedpackages']['service'])) {
3557
		foreach ($config['installedpackages']['service'] as $idx => $service) {
3558 751533a2 Phil Davis
			if ($service['name'] != 'unbound') {
3559 c11b7ffe Renato Botelho
				continue;
3560 751533a2 Phil Davis
			}
3561 c11b7ffe Renato Botelho
			unset($config['installedpackages']['service'][$idx]);
3562
			break;
3563
		}
3564
	}
3565
3566 751533a2 Phil Davis
	if (!isset($config['installedpackages']['unbound']['config'][0])) {
3567 3f257101 Renato Botelho
		return;
3568 751533a2 Phil Davis
	}
3569 3f257101 Renato Botelho
3570
	$pkg = $config['installedpackages']['unbound']['config'][0];
3571
3572 751533a2 Phil Davis
	if (isset($config['installedpackages']['unboundadvanced']['config'][0])) {
3573 3f257101 Renato Botelho
		$pkg = array_merge($pkg, $config['installedpackages']['unboundadvanced']['config'][0]);
3574 751533a2 Phil Davis
	}
3575 3f257101 Renato Botelho
3576
	$new = array();
3577
3578
	/* deal first with boolean fields */
3579
	$fields = array(
3580
		"enable" => "enable",
3581
		"dnssec_status" => "dnssec",
3582
		"forwarding_mode" => "forwarding",
3583
		"regdhcp" => "regdhcp",
3584
		"regdhcpstatic" => "regdhcpstatic",
3585
		"txtsupport" => "txtsupport",
3586
		"hide_id" => "hideidentity",
3587
		"hide_version" => "hideversion",
3588
		"prefetch" => "prefetch",
3589
		"prefetch_key" => "prefetchkey",
3590
		"harden_glue" => "hardenglue",
3591
		"harden_dnssec_stripped" => "dnssec_stripped");
3592
3593
	foreach ($fields as $oldk => $newk) {
3594
		if (isset($pkg[$oldk])) {
3595 751533a2 Phil Davis
			if ($pkg[$oldk] == 'on') {
3596 3f257101 Renato Botelho
				$new[$newk] = true;
3597 751533a2 Phil Davis
			}
3598 3f257101 Renato Botelho
			unset($pkg[$oldk]);
3599
		}
3600
	}
3601
3602
	$fields = array(
3603
		"active_interface" => "network_interface",
3604
		"query_interface" => "outgoing_interface",
3605
		"unbound_verbosity" => "log_verbosity",
3606
		"msg_cache_size" => "msgcachesize",
3607
		"outgoing_num_tcp" => "outgoing_num_tcp",
3608
		"incoming_num_tcp" => "incoming_num_tcp",
3609
		"edns_buffer_size" => "edns_buffer_size",
3610
		"num_queries_per_thread" => "num_queries_per_thread",
3611
		"jostle_timeout" => "jostle_timeout",
3612
		"cache_max_ttl" => "cache_max_ttl",
3613
		"cache_min_ttl" => "cache_min_ttl",
3614
		"infra_host_ttl" => "infra_host_ttl",
3615
		"infra_cache_numhosts" => "infra_cache_numhosts",
3616
		"unwanted_reply_threshold" => "unwanted_reply_threshold",
3617
		"custom_options" => "custom_options");
3618
3619
	foreach ($fields as $oldk => $newk) {
3620
		if (isset($pkg[$oldk])) {
3621
			$new[$newk] = $pkg[$oldk];
3622
			unset($pkg[$oldk]);
3623
		}
3624
	}
3625
3626 751533a2 Phil Davis
	if (isset($new['custom_options']) && !empty($new['custom_options'])) {
3627 fbf3d06e Renato Botelho
		$new['custom_options'] = str_replace("\r\n", "\n", $new['custom_options']);
3628 751533a2 Phil Davis
	}
3629 c23f4d8f Renato Botelho
3630 3f257101 Renato Botelho
	/* Following options were removed, bring them as custom_options */
3631
	if (isset($pkg['stats']) && $pkg['stats'] == "on") {
3632 751533a2 Phil Davis
		if (isset($pkg['stats_interval'])) {
3633 387ab31a Renato Botelho
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "statistics-interval: {$pkg['stats_interval']}";
3634 751533a2 Phil Davis
		}
3635
		if (isset($pkg['cumulative_stats'])) {
3636 387ab31a Renato Botelho
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "statistics-cumulative: {$pkg['cumulative_stats']}";
3637 751533a2 Phil Davis
		}
3638
		if (isset($pkg['extended_stats']) && $pkg['extended_stats'] == "on") {
3639 387ab31a Renato Botelho
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "extended-statistics: yes";
3640 751533a2 Phil Davis
		} else {
3641 387ab31a Renato Botelho
			$new['custom_options'] .= (empty($new['custom_options']) ? "" : "\n") . "extended-statistics: no";
3642 751533a2 Phil Davis
		}
3643 3f257101 Renato Botelho
	}
3644
3645
	$new['acls'] = array();
3646
	if (isset($config['installedpackages']['unboundacls']['config']) &&
3647
	    is_array($config['installedpackages']['unboundacls']['config'])) {
3648 751533a2 Phil Davis
		foreach ($config['installedpackages']['unboundacls']['config'] as $acl) {
3649 3f257101 Renato Botelho
			$new['acls'][] = $acl;
3650 751533a2 Phil Davis
		}
3651 3f257101 Renato Botelho
	}
3652
3653
	$config['unbound'] = $new;
3654
3655 751533a2 Phil Davis
	if (isset($config['installedpackages']['unbound'])) {
3656 3f257101 Renato Botelho
		unset($config['installedpackages']['unbound']);
3657 751533a2 Phil Davis
	}
3658
	if (isset($config['installedpackages']['unboundadvanced'])) {
3659 3f257101 Renato Botelho
		unset($config['installedpackages']['unboundadvanced']);
3660 751533a2 Phil Davis
	}
3661
	if (isset($config['installedpackages']['unboundacls'])) {
3662 3f257101 Renato Botelho
		unset($config['installedpackages']['unboundacls']);
3663 751533a2 Phil Davis
	}
3664 3f257101 Renato Botelho
3665
	unset($pkg, $new);
3666
}
3667
3668 b0885c5a Renato Botelho
function upgrade_111_to_112() {
3669
	global $config;
3670
3671
	$config['cron']['item'][] = array(
3672
		'minute' => '*/60',
3673
		'hour' => '*',
3674
		'mday' => '*',
3675
		'month' => '*',
3676
		'wday' => '*',
3677
		'who' => 'root',
3678
		'command' => '/usr/bin/nice -n20 /usr/local/sbin/expiretable -v -t 3600 webConfiguratorlockout'
3679
	);
3680
}
3681
3682 ccf30846 Renato Botelho
function upgrade_112_to_113() {
3683
	global $config;
3684
3685
	if (isset($config['notifications']['smtp']['ssl']) &&
3686 751533a2 Phil Davis
	    $config['notifications']['smtp']['ssl'] == "checked") {
3687 ccf30846 Renato Botelho
		$config['notifications']['smtp']['ssl'] = true;
3688 751533a2 Phil Davis
	} else {
3689 ccf30846 Renato Botelho
		unset($config['notifications']['smtp']['ssl']);
3690 751533a2 Phil Davis
	}
3691 ccf30846 Renato Botelho
3692
	if (isset($config['notifications']['smtp']['tls']) &&
3693 751533a2 Phil Davis
	    $config['notifications']['smtp']['tls'] == "checked") {
3694 ccf30846 Renato Botelho
		$config['notifications']['smtp']['tls'] = true;
3695 751533a2 Phil Davis
	} else {
3696 ccf30846 Renato Botelho
		unset($config['notifications']['smtp']['tls']);
3697 751533a2 Phil Davis
	}
3698 ccf30846 Renato Botelho
}
3699
3700 368d4910 Renato Botelho
function upgrade_113_to_114() {
3701
	global $config;
3702
3703
	if (!isset($config['ipsec']['phase1']) ||
3704 751533a2 Phil Davis
	    !is_array($config['ipsec']['phase1'])) {
3705 368d4910 Renato Botelho
		return;
3706 751533a2 Phil Davis
	}
3707 368d4910 Renato Botelho
3708 751533a2 Phil Davis
	foreach ($config['ipsec']['phase1'] as &$ph1ent) {
3709
		if (!isset($ph1ent['iketype'])) {
3710 368d4910 Renato Botelho
			$ph1ent['iketype'] = 'ikev1';
3711 751533a2 Phil Davis
		}
3712
	}
3713 368d4910 Renato Botelho
}
3714
3715 cfb5073f Renato Botelho
function upgrade_114_to_115() {
3716
	global $config;
3717
3718 751533a2 Phil Davis
	if (isset($config['unbound']['custom_options'])) {
3719 cfb5073f Renato Botelho
		$config['unbound']['custom_options'] = base64_encode($config['unbound']['custom_options']);
3720 751533a2 Phil Davis
	}
3721 cfb5073f Renato Botelho
}
3722
3723 1fe208ec Ermal LUÇI
function upgrade_115_to_116() {
3724
	global $config;
3725
3726 751533a2 Phil Davis
	if (!is_array($config['ipsec']) || !is_array($config['ipsec']['phase2'])) {
3727
		return;
3728
	}
3729 1fe208ec Ermal LUÇI
3730 751533a2 Phil Davis
	$keyid = 1;
3731
	foreach ($config['ipsec']['phase2'] as $idx => $ph2) {
3732
		$config['ipsec']['phase2'][$idx]['reqid'] = $keyid;
3733 1fe208ec Ermal LUÇI
		$keyid++;
3734
	}
3735
}
3736
3737 b997da8b xbipin
function upgrade_116_to_117() {
3738 751533a2 Phil Davis
	global $config;
3739 b997da8b xbipin
3740 8206b2d9 Ermal LUÇI
	if (is_array($config['ipsec']))
3741
		$config['ipsec']['shuntlaninterfaces'] = true;
3742
3743 877740ee Renato Botelho
	if (!isset($config['ipsec']['client']) ||
3744
	    !isset($config['ipsec']['client']['dns_split']) ||
3745
	    empty($config['ipsec']['client']['dns_split'])) {
3746
		return;
3747
	}
3748
3749
	$config['ipsec']['client']['dns_split'] =
3750
		preg_replace('/\s*,\s*/', ' ', trim($config['ipsec']['client']['dns_split']));
3751 74eaabbb Ermal LUÇI
3752 877740ee Renato Botelho
}
3753
3754
function upgrade_117_to_118() {
3755
	global $config;
3756
3757 751533a2 Phil Davis
	if (!isset($config['installedpackages']['miniupnpd']['config'][0])) {
3758 ee874f47 xbipin
		return;
3759 751533a2 Phil Davis
	}
3760 b997da8b xbipin
3761 ee874f47 xbipin
	$miniupnpd =& $config['installedpackages']['miniupnpd']['config'][0];
3762 b997da8b xbipin
3763 ee874f47 xbipin
	$miniupnpd['row'] = array();
3764 b997da8b xbipin
3765 ee874f47 xbipin
	for ($i = 1; $i <= 4; $i++) {
3766 751533a2 Phil Davis
		if (isset($miniupnpd["permuser{$i}"]) && !empty($miniupnpd["permuser{$i}"])) {
3767 ee874f47 xbipin
			$miniupnpd['row'][] = array('permuser' => $miniupnpd["permuser{$i}"]);
3768 751533a2 Phil Davis
		}
3769 ee874f47 xbipin
		unset($miniupnpd["permuser{$i}"]);
3770
	}
3771 b997da8b xbipin
}
3772 1916d34a Ermal
?>