Project

General

Profile

Download (18.4 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 Rubicon Communications, LLC (Netgate)
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
$pconfig['dashboardperiod'] = isset($config['widgets']['period']) ? $config['widgets']['period']:"10";
70
$pconfig['loginshowhost'] = isset($config['system']['webgui']['loginshowhost']);
71

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

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

    
84
$changedesc = gettext("System") . ": ";
85
$changecount = 0;
86

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

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

    
95
$timezonelist = system_get_timezone_list();
96

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

    
105
if ($_POST) {
106

    
107
	$changecount++;
108

    
109
	unset($input_errors);
110
	$pconfig = $_POST;
111

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

    
116
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
117

    
118
	if ($_POST['dashboardperiod']) {
119
		$config['widgets']['period'] = $_POST['dashboardperiod'];
120
	}
121

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

    
128
	$config['system']['webgui']['loginshowhost'] = $_POST['loginshowhost'] ? true:false;
129

    
130
	if ($_POST['webguifixedmenu']) {
131
		$config['system']['webgui']['webguifixedmenu'] = $_POST['webguifixedmenu'];
132
	} else {
133
		unset($config['system']['webgui']['webguifixedmenu']);
134
	}
135

    
136
	if ($_POST['webguihostnamemenu']) {
137
		$config['system']['webgui']['webguihostnamemenu'] = $_POST['webguihostnamemenu'];
138
	} else {
139
		unset($config['system']['webgui']['webguihostnamemenu']);
140
	}
141

    
142
	if ($_POST['dashboardcolumns']) {
143
		$config['system']['webgui']['dashboardcolumns'] = $_POST['dashboardcolumns'];
144
	} else {
145
		unset($config['system']['webgui']['dashboardcolumns']);
146
	}
147

    
148
	if ($_POST['hostname']) {
149
		if (!is_hostname($_POST['hostname'])) {
150
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'. It may not start or end with '-'.");
151
		} else {
152
			if (!is_unqualified_hostname($_POST['hostname'])) {
153
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
154
			}
155
		}
156
	}
157
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
158
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
159
	}
160

    
161
	$dnslist = $ignore_posted_dnsgw = array();
162

    
163
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
164
		$dnsname="dns{$dnscounter}";
165
		$dnsgwname="dns{$dnscounter}gw";
166
		$dnslist[] = $_POST[$dnsname];
167

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

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

    
192
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
193
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
194
		$dnsitem = "dns{$dnscounter}";
195
		$dnsgwitem = "dns{$dnscounter}gw";
196
		if ($_POST[$dnsgwitem] && ($_POST[$dnsgwitem] <> "none")) {
197
			foreach ($direct_networks_list as $direct_network) {
198
				if (ip_in_subnet($_POST[$dnsitem], $direct_network)) {
199
					$input_errors[] = sprintf(gettext("A gateway can not be assigned to DNS '%s' server which is on a directly connected network."), $_POST[$dnsitem]);
200
				}
201
			}
202
		}
203
	}
204

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

    
214
	if (!$input_errors) {
215
		update_if_changed("hostname", $config['system']['hostname'], $_POST['hostname']);
216
		update_if_changed("domain", $config['system']['domain'], $_POST['domain']);
217
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
218
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
219

    
220
		if ($_POST['language'] && $_POST['language'] != $config['system']['language']) {
221
			$config['system']['language'] = $_POST['language'];
222
			set_language();
223
		}
224

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

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

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

    
234
		unset($config['system']['webgui']['systemlogsmanagelogpanel']);
235
		$config['system']['webgui']['systemlogsmanagelogpanel'] = $_POST['systemlogsmanagelogpanel'] ? true : false;
236

    
237
		unset($config['system']['webgui']['statusmonitoringsettingspanel']);
238
		$config['system']['webgui']['statusmonitoringsettingspanel'] = $_POST['statusmonitoringsettingspanel'] ? true : false;
239

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

    
256
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
257

    
258
		unset($config['system']['dnsallowoverride']);
259
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
260

    
261
		if ($_POST['dnslocalhost'] == "yes") {
262
			$config['system']['dnslocalhost'] = true;
263
		} else {
264
			unset($config['system']['dnslocalhost']);
265
		}
266

    
267
		/* which interface should the dns servers resolve through? */
268
		$outdnscounter = 0;
269
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
270
			$dnsname="dns{$dnscounter}";
271
			$dnsgwname="dns{$dnscounter}gw";
272
			$olddnsgwname = $config['system'][$dnsgwname];
273

    
274
			if ($ignore_posted_dnsgw[$dnsgwname]) {
275
				$thisdnsgwname = "none";
276
			} else {
277
				$thisdnsgwname = $pconfig[$dnsgwname];
278
			}
279

    
280
			// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
281
			$config['system'][$dnsgwname] = "none";
282
			$pconfig[$dnsgwname] = "none";
283
			$pconfig[$dnsname] = "";
284

    
285
			if ($_POST[$dnsname]) {
286
				// Only the non-blank DNS servers were put into the config above.
287
				// So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers.
288
				// 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.
289
				$outdnscounter++;
290
				$outdnsname="dns{$outdnscounter}";
291
				$outdnsgwname="dns{$outdnscounter}gw";
292
				$pconfig[$outdnsname] = $_POST[$dnsname];
293
				if ($_POST[$dnsgwname]) {
294
					$config['system'][$outdnsgwname] = $thisdnsgwname;
295
					$pconfig[$outdnsgwname] = $thisdnsgwname;
296
				} else {
297
					// Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens.
298
					unset($config['system'][$outdnsgwname]);
299
					$pconfig[$outdnsgwname] = "";
300
				}
301
			}
302
			if (($olddnsgwname != "") && ($olddnsgwname != "none") && (($olddnsgwname != $thisdnsgwname) || ($olddnsservers[$dnscounter-1] != $_POST[$dnsname]))) {
303
				// A previous DNS GW name was specified. It has now gone or changed, or the DNS server address has changed.
304
				// Remove the route. Later calls will add the correct new route if needed.
305
				if (is_ipaddrv4($olddnsservers[$dnscounter-1])) {
306
					mwexec("/sbin/route delete " . escapeshellarg($olddnsservers[$dnscounter-1]));
307
				} else if (is_ipaddrv6($olddnsservers[$dnscounter-1])) {
308
					mwexec("/sbin/route delete -inet6 " . escapeshellarg($olddnsservers[$dnscounter-1]));
309
				}
310
			}
311
		}
312

    
313
		if ($changecount > 0) {
314
			write_config($changedesc);
315
		}
316

    
317
		$retval = 0;
318
		$retval = system_hostname_configure();
319
		$retval |= system_hosts_generate();
320
		$retval |= system_resolvconf_generate();
321
		if (isset($config['dnsmasq']['enable'])) {
322
			$retval |= services_dnsmasq_configure();
323
		} elseif (isset($config['unbound']['enable'])) {
324
			$retval |= services_unbound_configure();
325
		}
326
		$retval |= system_timezone_configure();
327
		$retval |= system_ntp_configure();
328

    
329
		if ($olddnsallowoverride != $config['system']['dnsallowoverride']) {
330
			$retval |= send_event("service reload dns");
331
		}
332

    
333
		// Reload the filter - plugins might need to be run.
334
		$retval |= filter_configure();
335

    
336
		$savemsg = get_std_save_message($retval);
337
	}
338

    
339
	unset($ignore_posted_dnsgw);
340
}
341

    
342
$pgtitle = array(gettext("System"), gettext("General Setup"));
343
include("head.inc");
344

    
345
if ($input_errors) {
346
	print_input_errors($input_errors);
347
}
348

    
349
if ($savemsg) {
350
	print_info_box($savemsg, 'success');
351
}
352
?>
353
<div id="container">
354
<?php
355

    
356
$form = new Form;
357
$section = new Form_Section('System');
358
$section->addInput(new Form_Input(
359
	'hostname',
360
	'Hostname',
361
	'text',
362
	$pconfig['hostname'],
363
	['placeholder' => 'pfSense']
364
))->setHelp('Name of the firewall host, without domain part');
365

    
366
$section->addInput(new Form_Input(
367
	'domain',
368
	'Domain',
369
	'text',
370
	$pconfig['domain'],
371
	['placeholder' => 'mycorp.com, home, office, private, etc.']
372
))->setHelp('Do not use \'local\' as a domain name. It will cause local '.
373
	'hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve '.
374
	'local hosts not running mDNS.');
375

    
376
$form->add($section);
377

    
378
$section = new Form_Section('DNS Server Settings');
379

    
380
for ($i=1; $i<5; $i++) {
381
//	if (!isset($pconfig['dns'.$i]))
382
//		continue;
383

    
384
	$group = new Form_Group('DNS Server ' . $i);
385

    
386
	$group->add(new Form_Input(
387
		'dns' . $i,
388
		'DNS Server',
389
		'text',
390
		$pconfig['dns'. $i]
391
	))->setHelp(($i == 4) ? 'Address':null);
392

    
393
	$help = "Enter IP addresses to be used by the system for DNS resolution. " .
394
		"These are also used for the DHCP service, DNS Forwarder and DNS Resolver " .
395
		"when it has DNS Query Forwarding enabled.";
396

    
397
	if ($multiwan)	{
398
		$options = array('none' => 'none');
399

    
400
		foreach ($arr_gateways as $gwname => $gwitem) {
401
			if ((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
402
				continue;
403
			}
404

    
405
			if ((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
406
				continue;
407
			}
408

    
409
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
410
		}
411

    
412
		$group->add(new Form_Select(
413
			'dns' . $i . 'gw',
414
			'Gateway',
415
			$pconfig['dns' . $i . 'gw'],
416
			$options
417
		))->setHelp(($i == 4) ? 'Gateway':null);;
418

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

    
423
	if ($i == 4) {
424
		$group->setHelp($help);
425
	}
426

    
427
	$section->add($group);
428
}
429

    
430
$section->addInput(new Form_Checkbox(
431
	'dnsallowoverride',
432
	'DNS Server Override',
433
	'Allow DNS server list to be overridden by DHCP/PPP on WAN',
434
	$pconfig['dnsallowoverride']
435
))->setHelp(sprintf(gettext('If this option is set, %s will use DNS servers '.
436
	'assigned by a DHCP/PPP server on WAN for its own purposes (including '.
437
	'the DNS Forwarder/DNS Resolver). However, they will not be assigned to DHCP '.
438
	'clients.'), $g['product_name']));
439

    
440
$section->addInput(new Form_Checkbox(
441
	'dnslocalhost',
442
	'Disable DNS Forwarder',
443
	'Do not use the DNS Forwarder/DNS Resolver as a DNS server for the firewall',
444
	$pconfig['dnslocalhost']
445
))->setHelp('By default localhost (127.0.0.1) will be used as the first DNS '.
446
	'server where the DNS Forwarder or DNS Resolver is enabled and set to '.
447
	'listen on localhost, so system can use the local DNS service to perform '.
448
	'lookups. Checking this box omits localhost from the list of DNS servers in resolv.conf.');
449

    
450
$form->add($section);
451

    
452
$section = new Form_Section('Localization');
453

    
454
$section->addInput(new Form_Select(
455
	'timezone',
456
	'Timezone',
457
	$pconfig['timezone'],
458
	array_combine($timezonelist, $timezonelist)
459
))->setHelp('Select the timezone or location within the timezone to be used by this system.');
460

    
461
$section->addInput(new Form_Input(
462
	'timeservers',
463
	'Timeservers',
464
	'text',
465
	$pconfig['timeservers']
466
))->setHelp('Use a space to separate multiple hosts (only one required). '.
467
	'Remember to set up at least one DNS server if a host name is entered here!');
468

    
469
$section->addInput(new Form_Select(
470
	'language',
471
	'Language',
472
	$pconfig['language'],
473
	get_locale_list()
474
))->setHelp('Choose a language for the webConfigurator');
475

    
476
$form->add($section);
477

    
478
$section = new Form_Section('webConfigurator');
479

    
480
gen_webguicss_field($section, $pconfig['webguicss']);
481
gen_webguifixedmenu_field($section, $pconfig['webguifixedmenu']);
482
gen_webguihostnamemenu_field($section, $pconfig['webguihostnamemenu']);
483
gen_dashboardcolumns_field($section, $pconfig['dashboardcolumns']);
484
gen_associatedpanels_fields(
485
	$section,
486
	$pconfig['dashboardavailablewidgetspanel'],
487
	$pconfig['systemlogsfilterpanel'],
488
	$pconfig['systemlogsmanagelogpanel'],
489
	$pconfig['statusmonitoringsettingspanel']);
490
gen_webguileftcolumnhyper_field($section, $pconfig['webguileftcolumnhyper']);
491

    
492
$section->addInput(new Form_Checkbox(
493
	'loginshowhost',
494
	'Login hostname',
495
	'Show hostname on login banner',
496
	$pconfig['loginshowhost']
497
));
498

    
499
$section->addInput(new Form_Input(
500
	'dashboardperiod',
501
	'Dashboard update period',
502
	'number',
503
	$pconfig['dashboardperiod'],
504
	['min' => '5', 'max' => '600']
505
))->setHelp('Time in seconds between dashboard widget updates. Small values cause ' .
506
			'more frequent updates but increase the load on the web server. ' .
507
			'Minimum is 5 seconds, maximum 600 seconds');
508

    
509
$form->add($section);
510

    
511
print $form;
512

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

    
515
?>
516
</div>
517

    
518
<script>
519
//<![CDATA[
520
events.push(function() {
521

    
522
	function setThemeWarning() {
523
		if ($('#webguicss').val().startsWith("pfSense")) {
524
			$('#csstxt').html("").addClass("text-default");
525
		} else {
526
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
527
		}
528
	}
529

    
530
	$('#webguicss').change(function() {
531
		setThemeWarning();
532
	});
533

    
534
	setThemeWarning();
535
});
536
//]]>
537
</script>
538

    
539
<?php
540
include("foot.inc");
541
?>
(184-184/225)