Project

General

Profile

Download (17.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * system.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-system-generalsetup
28
##|*NAME=System: General Setup
29
##|*DESCR=Allow access to the 'System: General Setup' page.
30
##|*MATCH=system.php*
31
##|-PRIV
32

    
33
require_once("guiconfig.inc");
34
require_once("functions.inc");
35
require_once("filter.inc");
36
require_once("shaper.inc");
37
require_once("system.inc");
38

    
39
$pconfig['hostname'] = $config['system']['hostname'];
40
$pconfig['domain'] = $config['system']['domain'];
41
list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['system']['dnsserver'];
42

    
43
$arr_gateways = return_gateways_array();
44

    
45
// set default columns to two if unset
46
if (!isset($config['system']['webgui']['dashboardcolumns'])) {
47
	$config['system']['webgui']['dashboardcolumns'] = 2;
48
}
49

    
50
$pconfig['dns1gw'] = $config['system']['dns1gw'];
51
$pconfig['dns2gw'] = $config['system']['dns2gw'];
52
$pconfig['dns3gw'] = $config['system']['dns3gw'];
53
$pconfig['dns4gw'] = $config['system']['dns4gw'];
54

    
55
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
56
$pconfig['timezone'] = $config['system']['timezone'];
57
$pconfig['timeservers'] = $config['system']['timeservers'];
58
$pconfig['language'] = $config['system']['language'];
59
$pconfig['webguicss'] = $config['system']['webgui']['webguicss'];
60
$pconfig['webguifixedmenu'] = $config['system']['webgui']['webguifixedmenu'];
61
$pconfig['dashboardcolumns'] = $config['system']['webgui']['dashboardcolumns'];
62
$pconfig['webguileftcolumnhyper'] = isset($config['system']['webgui']['webguileftcolumnhyper']);
63
$pconfig['dashboardavailablewidgetspanel'] = isset($config['system']['webgui']['dashboardavailablewidgetspanel']);
64
$pconfig['systemlogsfilterpanel'] = isset($config['system']['webgui']['systemlogsfilterpanel']);
65
$pconfig['systemlogsmanagelogpanel'] = isset($config['system']['webgui']['systemlogsmanagelogpanel']);
66
$pconfig['statusmonitoringsettingspanel'] = isset($config['system']['webgui']['statusmonitoringsettingspanel']);
67
$pconfig['webguihostnamemenu'] = $config['system']['webgui']['webguihostnamemenu'];
68
$pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']);
69

    
70
if (!$pconfig['timezone']) {
71
	if (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
72
		$pconfig['timezone'] = $g['default_timezone'];
73
	} else {
74
		$pconfig['timezone'] = "Etc/UTC";
75
	}
76
}
77

    
78
if (!$pconfig['timeservers']) {
79
	$pconfig['timeservers'] = "pool.ntp.org";
80
}
81

    
82
$changedesc = gettext("System") . ": ";
83
$changecount = 0;
84

    
85
function is_timezone($elt) {
86
	return !preg_match("/\/$/", $elt);
87
}
88

    
89
if ($pconfig['timezone'] <> $_POST['timezone']) {
90
	filter_pflog_start(true);
91
}
92

    
93
$timezonelist = system_get_timezone_list();
94

    
95
$multiwan = false;
96
$interfaces = get_configured_interface_list();
97
foreach ($interfaces as $interface) {
98
	if (interface_has_gateway($interface)) {
99
		$multiwan = true;
100
	}
101
}
102

    
103
if ($_POST) {
104

    
105
	$changecount++;
106

    
107
	unset($input_errors);
108
	$pconfig = $_POST;
109

    
110
	/* input validation */
111
	$reqdfields = explode(" ", "hostname domain");
112
	$reqdfieldsn = array(gettext("Hostname"), gettext("Domain"));
113

    
114
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
115

    
116
	if ($_POST['webguicss']) {
117
		$config['system']['webgui']['webguicss'] = $_POST['webguicss'];
118
	} else {
119
		unset($config['system']['webgui']['webguicss']);
120
	}
121

    
122
	if ($_POST['webguifixedmenu']) {
123
		$config['system']['webgui']['webguifixedmenu'] = $_POST['webguifixedmenu'];
124
	} else {
125
		unset($config['system']['webgui']['webguifixedmenu']);
126
	}
127

    
128
	if ($_POST['webguihostnamemenu']) {
129
		$config['system']['webgui']['webguihostnamemenu'] = $_POST['webguihostnamemenu'];
130
	} else {
131
		unset($config['system']['webgui']['webguihostnamemenu']);
132
	}
133

    
134
	if ($_POST['dashboardcolumns']) {
135
		$config['system']['webgui']['dashboardcolumns'] = $_POST['dashboardcolumns'];
136
	} else {
137
		unset($config['system']['webgui']['dashboardcolumns']);
138
	}
139

    
140
	if ($_POST['hostname']) {
141
		if (!is_hostname($_POST['hostname'])) {
142
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'. It may not start or end with '-'.");
143
		} else {
144
			if (!is_unqualified_hostname($_POST['hostname'])) {
145
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
146
			}
147
		}
148
	}
149
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
150
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
151
	}
152

    
153
	$dnslist = $ignore_posted_dnsgw = array();
154

    
155
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
156
		$dnsname="dns{$dnscounter}";
157
		$dnsgwname="dns{$dnscounter}gw";
158
		$dnslist[] = $_POST[$dnsname];
159

    
160
		if (($_POST[$dnsname] && !is_ipaddr($_POST[$dnsname]))) {
161
			$input_errors[] = sprintf(gettext("A valid IP address must be specified for DNS server %s."), $dnscounter);
162
		} else {
163
			if (($_POST[$dnsgwname] <> "") && ($_POST[$dnsgwname] <> "none")) {
164
				// A real gateway has been selected.
165
				if (is_ipaddr($_POST[$dnsname])) {
166
					if ((is_ipaddrv4($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false)) {
167
						$input_errors[] = sprintf(gettext('The IPv6 gateway "%1$s" can not be specified for IPv4 DNS server "%2$s".'), $_POST[$dnsgwname], $_POST[$dnsname]);
168
					}
169
					if ((is_ipaddrv6($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false)) {
170
						$input_errors[] = sprintf(gettext('The IPv4 gateway "%1$s" can not be specified for IPv6 DNS server "%2$s".'), $_POST[$dnsgwname], $_POST[$dnsname]);
171
					}
172
				} else {
173
					// The user selected a gateway but did not provide a DNS address. Be nice and set the gateway back to "none".
174
					$ignore_posted_dnsgw[$dnsgwname] = true;
175
				}
176
			}
177
		}
178
	}
179

    
180
	if (count(array_filter($dnslist)) != count(array_unique(array_filter($dnslist)))) {
181
		$input_errors[] = gettext('Each configured DNS server must have a unique IP address. Remove the duplicated IP.');
182
	}
183

    
184
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
185
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
186
		$dnsitem = "dns{$dnscounter}";
187
		$dnsgwitem = "dns{$dnscounter}gw";
188
		if ($_POST[$dnsgwitem]) {
189
			if (interface_has_gateway($_POST[$dnsgwitem])) {
190
				foreach ($direct_networks_list as $direct_network) {
191
					if (ip_in_subnet($_POST[$dnsitem], $direct_network)) {
192
						$input_errors[] = sprintf(gettext("A gateway can not be assigned to DNS '%s' server which is on a directly connected network."), $_POST[$dnsitem]);
193
					}
194
				}
195
			}
196
		}
197
	}
198

    
199
	# it's easy to have a little too much whitespace in the field, clean it up for the user before processing.
200
	$_POST['timeservers'] = preg_replace('/[[:blank:]]+/', ' ', $_POST['timeservers']);
201
	$_POST['timeservers'] = trim($_POST['timeservers']);
202
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
203
		if (!is_domain($ts)) {
204
			$input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.");
205
		}
206
	}
207

    
208
	if (!$input_errors) {
209
		update_if_changed("hostname", $config['system']['hostname'], $_POST['hostname']);
210
		update_if_changed("domain", $config['system']['domain'], $_POST['domain']);
211
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
212
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
213

    
214
		if ($_POST['language'] && $_POST['language'] != $config['system']['language']) {
215
			$config['system']['language'] = $_POST['language'];
216
			set_language();
217
		}
218

    
219
		unset($config['system']['webgui']['webguileftcolumnhyper']);
220
		$config['system']['webgui']['webguileftcolumnhyper'] = $_POST['webguileftcolumnhyper'] ? true : false;
221

    
222
		unset($config['system']['webgui']['dashboardavailablewidgetspanel']);
223
		$config['system']['webgui']['dashboardavailablewidgetspanel'] = $_POST['dashboardavailablewidgetspanel'] ? true : false;
224

    
225
		unset($config['system']['webgui']['systemlogsfilterpanel']);
226
		$config['system']['webgui']['systemlogsfilterpanel'] = $_POST['systemlogsfilterpanel'] ? true : false;
227

    
228
		unset($config['system']['webgui']['systemlogsmanagelogpanel']);
229
		$config['system']['webgui']['systemlogsmanagelogpanel'] = $_POST['systemlogsmanagelogpanel'] ? true : false;
230

    
231
		unset($config['system']['webgui']['statusmonitoringsettingspanel']);
232
		$config['system']['webgui']['statusmonitoringsettingspanel'] = $_POST['statusmonitoringsettingspanel'] ? true : false;
233

    
234
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
235
		$olddnsservers = $config['system']['dnsserver'];
236
		unset($config['system']['dnsserver']);
237
		if ($_POST['dns1']) {
238
			$config['system']['dnsserver'][] = $_POST['dns1'];
239
		}
240
		if ($_POST['dns2']) {
241
			$config['system']['dnsserver'][] = $_POST['dns2'];
242
		}
243
		if ($_POST['dns3']) {
244
			$config['system']['dnsserver'][] = $_POST['dns3'];
245
		}
246
		if ($_POST['dns4']) {
247
			$config['system']['dnsserver'][] = $_POST['dns4'];
248
		}
249

    
250
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
251

    
252
		unset($config['system']['dnsallowoverride']);
253
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
254

    
255
		if ($_POST['dnslocalhost'] == "yes") {
256
			$config['system']['dnslocalhost'] = true;
257
		} else {
258
			unset($config['system']['dnslocalhost']);
259
		}
260

    
261
		/* which interface should the dns servers resolve through? */
262
		$outdnscounter = 0;
263
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
264
			$dnsname="dns{$dnscounter}";
265
			$dnsgwname="dns{$dnscounter}gw";
266
			$olddnsgwname = $config['system'][$dnsgwname];
267

    
268
			if ($ignore_posted_dnsgw[$dnsgwname]) {
269
				$thisdnsgwname = "none";
270
			} else {
271
				$thisdnsgwname = $pconfig[$dnsgwname];
272
			}
273

    
274
			// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
275
			$config['system'][$dnsgwname] = "none";
276
			$pconfig[$dnsgwname] = "none";
277
			$pconfig[$dnsname] = "";
278

    
279
			if ($_POST[$dnsname]) {
280
				// Only the non-blank DNS servers were put into the config above.
281
				// So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers.
282
				// This keeps the DNS server IP and corresponding gateway "lined up" when the user blanks out a DNS server IP in the middle of the list.
283
				$outdnscounter++;
284
				$outdnsname="dns{$outdnscounter}";
285
				$outdnsgwname="dns{$outdnscounter}gw";
286
				$pconfig[$outdnsname] = $_POST[$dnsname];
287
				if ($_POST[$dnsgwname]) {
288
					$config['system'][$outdnsgwname] = $thisdnsgwname;
289
					$pconfig[$outdnsgwname] = $thisdnsgwname;
290
				} else {
291
					// Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens.
292
					unset($config['system'][$outdnsgwname]);
293
					$pconfig[$outdnsgwname] = "";
294
				}
295
			}
296
			if (($olddnsgwname != "") && ($olddnsgwname != "none") && (($olddnsgwname != $thisdnsgwname) || ($olddnsservers[$dnscounter-1] != $_POST[$dnsname]))) {
297
				// A previous DNS GW name was specified. It has now gone or changed, or the DNS server address has changed.
298
				// Remove the route. Later calls will add the correct new route if needed.
299
				if (is_ipaddrv4($olddnsservers[$dnscounter-1])) {
300
					mwexec("/sbin/route delete " . escapeshellarg($olddnsservers[$dnscounter-1]));
301
				} else if (is_ipaddrv6($olddnsservers[$dnscounter-1])) {
302
					mwexec("/sbin/route delete -inet6 " . escapeshellarg($olddnsservers[$dnscounter-1]));
303
				}
304
			}
305
		}
306

    
307
		if ($changecount > 0) {
308
			write_config($changedesc);
309
		}
310

    
311
		$retval = 0;
312
		$retval = system_hostname_configure();
313
		$retval |= system_hosts_generate();
314
		$retval |= system_resolvconf_generate();
315
		if (isset($config['dnsmasq']['enable'])) {
316
			$retval |= services_dnsmasq_configure();
317
		} elseif (isset($config['unbound']['enable'])) {
318
			$retval |= services_unbound_configure();
319
		}
320
		$retval |= system_timezone_configure();
321
		$retval |= system_ntp_configure();
322

    
323
		if ($olddnsallowoverride != $config['system']['dnsallowoverride']) {
324
			$retval |= send_event("service reload dns");
325
		}
326

    
327
		// Reload the filter - plugins might need to be run.
328
		$retval |= filter_configure();
329

    
330
		$savemsg = get_std_save_message($retval);
331
	}
332

    
333
	unset($ignore_posted_dnsgw);
334
}
335

    
336
$pgtitle = array(gettext("System"), gettext("General Setup"));
337
include("head.inc");
338

    
339
if ($input_errors) {
340
	print_input_errors($input_errors);
341
}
342

    
343
if ($savemsg) {
344
	print_info_box($savemsg, 'success');
345
}
346
?>
347
<div id="container">
348
<?php
349

    
350
$form = new Form;
351
$section = new Form_Section('System');
352
$section->addInput(new Form_Input(
353
	'hostname',
354
	'Hostname',
355
	'text',
356
	$pconfig['hostname'],
357
	['placeholder' => 'pfSense']
358
))->setHelp('Name of the firewall host, without domain part');
359
$section->addInput(new Form_Input(
360
	'domain',
361
	'Domain',
362
	'text',
363
	$pconfig['domain'],
364
	['placeholder' => 'mycorp.com, home, office, private, etc.']
365
))->setHelp('Do not use \'local\' as a domain name. It will cause local '.
366
	'hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve '.
367
	'local hosts not running mDNS.');
368
$form->add($section);
369

    
370
$section = new Form_Section('DNS Server Settings');
371

    
372
for ($i=1; $i<5; $i++) {
373
//	if (!isset($pconfig['dns'.$i]))
374
//		continue;
375

    
376
	$group = new Form_Group('DNS Server ' . $i);
377

    
378
	$group->add(new Form_Input(
379
		'dns' . $i,
380
		'DNS Server',
381
		'text',
382
		$pconfig['dns'. $i]
383
	))->setHelp(($i == 4) ? 'Address':null);
384

    
385
	$help = "Enter IP addresses to be used by the system for DNS resolution. " .
386
		"These are also used for the DHCP service, DNS forwarder and for PPTP VPN clients.";
387

    
388
	if ($multiwan)	{
389
		$options = array('none' => 'none');
390

    
391
		foreach ($arr_gateways as $gwname => $gwitem) {
392
			if ((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
393
				continue;
394
			}
395

    
396
			if ((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
397
				continue;
398
			}
399

    
400
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
401
		}
402

    
403
		$group->add(new Form_Select(
404
			'dns' . $i . 'gw',
405
			'Gateway',
406
			$pconfig['dns' . $i . 'gw'],
407
			$options
408
		))->setHelp(($i == 4) ? 'Gateway':null);;
409

    
410
		$help .= '<br/>'. "In addition, optionally select the gateway for each DNS server. " .
411
			"When using multiple WAN connections there should be at least one unique DNS server per gateway.";
412
	}
413

    
414
	if ($i == 4) {
415
		$group->setHelp($help);
416
	}
417

    
418
	$section->add($group);
419
}
420

    
421
$section->addInput(new Form_Checkbox(
422
	'dnsallowoverride',
423
	'DNS Server Override',
424
	'Allow DNS server list to be overridden by DHCP/PPP on WAN',
425
	$pconfig['dnsallowoverride']
426
))->setHelp(sprintf(gettext('If this option is set, %s will use DNS servers '.
427
	'assigned by a DHCP/PPP server on WAN for its own purposes (including '.
428
	'the DNS forwarder). However, they will not be assigned to DHCP and PPTP '.
429
	'VPN clients.'), $g['product_name']));
430

    
431
$section->addInput(new Form_Checkbox(
432
	'dnslocalhost',
433
	'Disable DNS Forwarder',
434
	'Do not use the DNS Forwarder as a DNS server for the firewall',
435
	$pconfig['dnslocalhost']
436
))->setHelp('By default localhost (127.0.0.1) will be used as the first DNS '.
437
	'server where the DNS Forwarder or DNS Resolver is enabled and set to '.
438
	'listen on Localhost, so system can use the local DNS service to perform '.
439
	'lookups. Checking this box omits localhost from the list of DNS servers.');
440

    
441
$form->add($section);
442

    
443
$section = new Form_Section('Localization');
444
$section->addInput(new Form_Select(
445
	'timezone',
446
	'Timezone',
447
	$pconfig['timezone'],
448
	array_combine($timezonelist, $timezonelist)
449
))->setHelp('Select the timezone or location within the timezone to be used by this system.');
450
$section->addInput(new Form_Input(
451
	'timeservers',
452
	'Timeservers',
453
	'text',
454
	$pconfig['timeservers']
455
))->setHelp('Use a space to separate multiple hosts (only one required). '.
456
	'Remember to set up at least one DNS server if a host name is entered here!');
457
$section->addInput(new Form_Select(
458
	'language',
459
	'Language',
460
	$pconfig['language'],
461
	get_locale_list()
462
))->setHelp('Choose a language for the webConfigurator');
463

    
464
$form->add($section);
465

    
466
$section = new Form_Section('webConfigurator');
467

    
468
gen_webguicss_field($section, $pconfig['webguicss']);
469
gen_webguifixedmenu_field($section, $pconfig['webguifixedmenu']);
470
gen_webguihostnamemenu_field($section, $pconfig['webguihostnamemenu']);
471
gen_dashboardcolumns_field($section, $pconfig['dashboardcolumns']);
472
gen_associatedpanels_fields(
473
	$section,
474
	$pconfig['dashboardavailablewidgetspanel'],
475
	$pconfig['systemlogsfilterpanel'],
476
	$pconfig['systemlogsmanagelogpanel'],
477
	$pconfig['statusmonitoringsettingspanel']);
478
gen_webguileftcolumnhyper_field($section, $pconfig['webguileftcolumnhyper']);
479

    
480
$form->add($section);
481

    
482
print $form;
483

    
484
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
485

    
486
?>
487
</div>
488

    
489
<script>
490
//<![CDATA[
491
events.push(function() {
492

    
493
	function setThemeWarning() {
494
		if ($('#webguicss').val().startsWith("pfSense")) {
495
			$('#csstxt').html("").addClass("text-default");
496
		} else {
497
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
498
		}
499
	}
500

    
501
	$('#webguicss').change(function() {
502
		setThemeWarning();
503
	});
504

    
505
	setThemeWarning();
506
});
507
//]]>
508
</script>
509

    
510
<?php
511
include("foot.inc");
512
?>
(186-186/227)