Project

General

Profile

Download (18.3 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]) {
197
			if (interface_has_gateway($_POST[$dnsgwitem])) {
198
				foreach ($direct_networks_list as $direct_network) {
199
					if (ip_in_subnet($_POST[$dnsitem], $direct_network)) {
200
						$input_errors[] = sprintf(gettext("A gateway can not be assigned to DNS '%s' server which is on a directly connected network."), $_POST[$dnsitem]);
201
					}
202
				}
203
			}
204
		}
205
	}
206

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

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

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

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

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

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

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

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

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

    
258
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
259

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

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

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

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

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

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

    
315
		if ($changecount > 0) {
316
			write_config($changedesc);
317
		}
318

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

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

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

    
338
		$savemsg = get_std_save_message($retval);
339
	}
340

    
341
	unset($ignore_posted_dnsgw);
342
}
343

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

    
347
if ($input_errors) {
348
	print_input_errors($input_errors);
349
}
350

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

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

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

    
378
$form->add($section);
379

    
380
$section = new Form_Section('DNS Server Settings');
381

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

    
386
	$group = new Form_Group('DNS Server ' . $i);
387

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
512
print $form;
513

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

    
516
?>
517
</div>
518

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

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

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

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

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