Project

General

Profile

Download (16.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	system.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58
/*
59
	pfSense_BUILDER_BINARIES:	/bin/kill	/usr/bin/tar
60
	pfSense_MODULE: system
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-system-generalsetup
65
##|*NAME=System: General Setup
66
##|*DESCR=Allow access to the 'System: General Setup' page.
67
##|*MATCH=system.php*
68
##|-PRIV
69

    
70
require("guiconfig.inc");
71
require_once("functions.inc");
72
require_once("filter.inc");
73
require_once("shaper.inc");
74
require_once("system.inc");
75

    
76
$pconfig['hostname'] = $config['system']['hostname'];
77
$pconfig['domain'] = $config['system']['domain'];
78
list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['system']['dnsserver'];
79

    
80
$arr_gateways = return_gateways_array();
81

    
82
$pconfig['dns1gw'] = $config['system']['dns1gw'];
83
$pconfig['dns2gw'] = $config['system']['dns2gw'];
84
$pconfig['dns3gw'] = $config['system']['dns3gw'];
85
$pconfig['dns4gw'] = $config['system']['dns4gw'];
86

    
87
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
88
$pconfig['timezone'] = $config['system']['timezone'];
89
$pconfig['timeservers'] = $config['system']['timeservers'];
90
$pconfig['language'] = $config['system']['language'];
91
$pconfig['webguicss'] = $config['system']['webgui']['webguicss'];
92
//$pconfig['webguifixedmenu'] = $config['system']['webgui']['webguifixedmenu'];
93
$pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']);
94

    
95
if (!$pconfig['timezone']) {
96
	if (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
97
		$pconfig['timezone'] = $g['default_timezone'];
98
	} else {
99
		$pconfig['timezone'] = "Etc/UTC";
100
	}
101
}
102

    
103
if (!$pconfig['timeservers']) {
104
	$pconfig['timeservers'] = "pool.ntp.org";
105
}
106

    
107
$changedesc = gettext("System") . ": ";
108
$changecount = 0;
109

    
110
function is_timezone($elt) {
111
	return !preg_match("/\/$/", $elt);
112
}
113

    
114
if ($pconfig['timezone'] <> $_POST['timezone']) {
115
	filter_pflog_start(true);
116
}
117

    
118
$timezonelist = system_get_timezone_list();
119

    
120
$multiwan = false;
121
$interfaces = get_configured_interface_list();
122
foreach ($interfaces as $interface) {
123
	if (interface_has_gateway($interface)) {
124
		$multiwan = true;
125
	}
126
}
127

    
128
if ($_POST) {
129

    
130
	$changecount++;
131

    
132
	unset($input_errors);
133
	$pconfig = $_POST;
134

    
135
	/* input validation */
136
	$reqdfields = explode(" ", "hostname domain");
137
	$reqdfieldsn = array(gettext("Hostname"), gettext("Domain"));
138

    
139
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
140

    
141
	if ($_POST['webguicss']) {
142
		$config['system']['webgui']['webguicss'] = $_POST['webguicss'];
143
	} else {
144
		unset($config['system']['webgui']['webguicss']);
145
	}
146
	/*
147
	if ($_POST['webguifixedmenu']) {
148
		$config['system']['webgui']['webguifixedmenu'] = $_POST['webguifixedmenu'];
149
	} else {
150
		unset($config['system']['webgui']['webguifixedmenu']);
151
	}
152
	*/
153
	if ($_POST['hostname']) {
154
		if (!is_hostname($_POST['hostname'])) {
155
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'. It may not start or end with '-'.");
156
		} else {
157
			if (!is_unqualified_hostname($_POST['hostname'])) {
158
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
159
			}
160
		}
161
	}
162
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
163
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
164
	}
165

    
166
	$ignore_posted_dnsgw = array();
167

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

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

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

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

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

    
226
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
227
		$olddnsservers = $config['system']['dnsserver'];
228
		unset($config['system']['dnsserver']);
229
		if ($_POST['dns1']) {
230
			$config['system']['dnsserver'][] = $_POST['dns1'];
231
		}
232
		if ($_POST['dns2']) {
233
			$config['system']['dnsserver'][] = $_POST['dns2'];
234
		}
235
		if ($_POST['dns3']) {
236
			$config['system']['dnsserver'][] = $_POST['dns3'];
237
		}
238
		if ($_POST['dns4']) {
239
			$config['system']['dnsserver'][] = $_POST['dns4'];
240
		}
241

    
242
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
243

    
244
		unset($config['system']['dnsallowoverride']);
245
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
246

    
247
		if ($_POST['dnslocalhost'] == "yes") {
248
			$config['system']['dnslocalhost'] = true;
249
		} else {
250
			unset($config['system']['dnslocalhost']);
251
		}
252

    
253
		/* which interface should the dns servers resolve through? */
254
		$outdnscounter = 0;
255
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
256
			$dnsname="dns{$dnscounter}";
257
			$dnsgwname="dns{$dnscounter}gw";
258
			$olddnsgwname = $config['system'][$dnsgwname];
259

    
260
			if ($ignore_posted_dnsgw[$dnsgwname]) {
261
				$thisdnsgwname = "none";
262
			} else {
263
				$thisdnsgwname = $pconfig[$dnsgwname];
264
			}
265

    
266
			// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
267
			$config['system'][$dnsgwname] = "none";
268
			$pconfig[$dnsgwname] = "none";
269
			$pconfig[$dnsname] = "";
270

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

    
299
		if ($changecount > 0) {
300
			write_config($changedesc);
301
		}
302

    
303
		$retval = 0;
304
		$retval = system_hostname_configure();
305
		$retval |= system_hosts_generate();
306
		$retval |= system_resolvconf_generate();
307
		if (isset($config['dnsmasq']['enable'])) {
308
			$retval |= services_dnsmasq_configure();
309
		} elseif (isset($config['unbound']['enable'])) {
310
			$retval |= services_unbound_configure();
311
		}
312
		$retval |= system_timezone_configure();
313
		$retval |= system_ntp_configure();
314

    
315
		if ($olddnsallowoverride != $config['system']['dnsallowoverride']) {
316
			$retval |= send_event("service reload dns");
317
		}
318

    
319
		// Reload the filter - plugins might need to be run.
320
		$retval |= filter_configure();
321

    
322
		$savemsg = get_std_save_message($retval);
323
	}
324

    
325
	unset($ignore_posted_dnsgw);
326
}
327

    
328
$pgtitle = array(gettext("System"), gettext("General Setup"));
329
include("head.inc");
330

    
331
if ($input_errors)
332
	print_input_errors($input_errors);
333

    
334
if ($savemsg)
335
	print_info_box($savemsg, success);
336
?>
337
<div id="container">
338
<?php
339

    
340
$form = new Form;
341
$section = new Form_Section('System');
342
$section->addInput(new Form_Input(
343
	'hostname',
344
	'Hostname',
345
	'text',
346
	$pconfig['hostname'],
347
	['placeholder' => 'pfSense']
348
))->setHelp('Name of the firewall host, without domain part');
349
$section->addInput(new Form_Input(
350
	'domain',
351
	'Domain',
352
	'text',
353
	$pconfig['domain'],
354
	['placeholder' => 'mycorp.com, home, office, private, etc.']
355
))->setHelp('Do not use \'local\' as a domain name. It will cause local '.
356
	'hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve '.
357
	'local hosts not running mDNS.');
358
$form->add($section);
359

    
360
$section = new Form_Section('DNS server settings');
361

    
362
for ($i=1; $i<5; $i++)
363
{
364
//	if (!isset($pconfig['dns'.$i]))
365
//		continue;
366

    
367
	$group = new Form_Group('DNS Server ' . $i);
368

    
369
	$group->add(new Form_Input(
370
		'dns' . $i,
371
		'DNS Server',
372
		'text',
373
		$pconfig['dns'. $i]
374
	))->setHelp(($i == 4) ? 'Address':null);
375

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

    
379
	if ($multiwan)	{
380
		$options = array('none' => 'none');
381

    
382
		foreach($arr_gateways as $gwname => $gwitem) {
383
			if((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
384
				continue;
385
			}
386

    
387
			if((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
388
				continue;
389
			}
390

    
391
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
392
		}
393

    
394
		$group->add(new Form_Select(
395
			'dns' . $i . 'gw',
396
			'Gateway',
397
			$pconfig['dns' . $i . 'gw'],
398
			$options
399
		))->setHelp(($i == 4) ? 'Gateway':null);;
400

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

    
405
	if($i == 4)
406
		$group->setHelp($help);
407

    
408
	$section->add($group);
409
}
410

    
411
$section->addInput(new Form_Checkbox(
412
	'dnsallowoverride',
413
	'DNS server override',
414
	'Allow DNS server list to be overridden by DHCP/PPP on WAN',
415
	$pconfig['dnsallowoverride']
416
))->setHelp(sprintf(gettext('If this option is set, %s will use DNS servers'.
417
	'assigned by a DHCP/PPP server on WAN for its own purposes (including '.
418
	'the DNS forwarder). However, they will not be assigned to DHCP and PPTP '.
419
	'VPN clients.'), $g['product_name']));
420

    
421
$section->addInput(new Form_Checkbox(
422
	'dnslocalhost',
423
	'Disable DNS forwarder',
424
	'Do not use the DNS Forwarder as a DNS server for the firewall',
425
	$pconfig['dnslocalhost']
426
))->setHelp('By default localhost (127.0.0.1) will be used as the first DNS'.
427
	'server where the DNS Forwarder or DNS Resolver is enabled and set to '.
428
	'listen on Localhost, so system can use the local DNS service to perform'.
429
	'lookups. Checking this box omits localhost from the list of DNS servers.');
430

    
431
$form->add($section);
432

    
433
$section = new Form_Section('Localization');
434
$section->addInput(new Form_Select(
435
	'timezone',
436
	'Timezone',
437
	$pconfig['timezone'],
438
	array_combine($timezonelist, $timezonelist)
439
))->setHelp('Select the location closest to you');
440
$section->addInput(new Form_Input(
441
	'timeservers',
442
	'Timeservers',
443
	'text',
444
	$pconfig['timeservers']
445
))->setHelp('Use a space to separate multiple hosts (only one required). '.
446
	'Remember to set up at least one DNS server if you enter a host name here!');
447
$section->addInput(new Form_Select(
448
	'language',
449
	'Language',
450
	$pconfig['language'],
451
	get_locale_list()
452
))->setHelp('Choose a language for the webConfigurator');
453

    
454
$form->add($section);
455

    
456
$csslist = array();
457
$css = glob("bootstrap/css/*.css");
458
foreach ($css as $file) {
459
	$file = basename($file);
460
	if(substr($file, 0, 9) !== 'bootstrap') {
461
		$csslist[$file] = pathinfo($file, PATHINFO_FILENAME);
462
	}
463
}
464

    
465
asort($csslist);
466

    
467
if (!isset($pconfig['webguicss']) || !isset($csslist[$pconfig['webguicss']])) {
468
	$pconfig['webguicss'] = "pfSense.css";
469
}
470

    
471
$section = new Form_Section('Web configurator');
472

    
473
$section->addInput(new Form_Select(
474
	'webguicss',
475
	'Theme',
476
	$pconfig['webguicss'],
477
	$csslist
478
))->setHelp("Choose an alternative css file (if installed) to change the appearance of the Web configurator. css files are located in /usr/local/www/bootstrap/css");
479
/*
480
$section->addInput(new Form_Select(
481
	'webguifixedmenu',
482
	'Menu',
483
	$pconfig['webguifixedmenu'],
484
	["" => "Scrolls with page", "fixed" => "Fixed (Remains visible at top of page)"]
485
));
486
*/
487
$form->add($section);
488

    
489
print $form;
490

    
491
include("foot.inc");
(184-184/228)