Project

General

Profile

Download (15.8 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 page
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['timeupdateinterval'] = $config['system']['time-update-interval'];
90
$pconfig['timeservers'] = $config['system']['timeservers'];
91
$pconfig['language'] = $config['system']['language'];
92

    
93
$pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']);
94

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

    
106
if (!$pconfig['timeservers']) {
107
	$pconfig['timeservers'] = "pool.ntp.org";
108
}
109

    
110
$changedesc = gettext("System") . ": ";
111
$changecount = 0;
112

    
113
function is_timezone($elt) {
114
	return !preg_match("/\/$/", $elt);
115
}
116

    
117
if ($pconfig['timezone'] <> $_POST['timezone']) {
118
	filter_pflog_start(true);
119
}
120

    
121
$timezonelist = system_get_timezone_list();
122

    
123
$multiwan = false;
124
$interfaces = get_configured_interface_list();
125
foreach ($interfaces as $interface) {
126
	if (interface_has_gateway($interface)) {
127
		$multiwan = true;
128
	}
129
}
130

    
131
if ($_POST) {
132

    
133
	$changecount++;
134

    
135
	unset($input_errors);
136
	$pconfig = $_POST;
137

    
138
	/* input validation */
139
	$reqdfields = explode(" ", "hostname domain");
140
	$reqdfieldsn = array(gettext("Hostname"), gettext("Domain"));
141

    
142
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
143

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

    
157
	$ignore_posted_dnsgw = array();
158

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

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

    
197
	$t = (int)$_POST['timeupdateinterval'];
198
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
199
		$input_errors[] = gettext("The time update interval must be either 0 (disabled) or between 6 and 1440.");
200
	}
201
	# it's easy to have a little too much whitespace in the field, clean it up for the user before processing.
202
	$_POST['timeservers'] = preg_replace('/[[:blank:]]+/', ' ', $_POST['timeservers']);
203
	$_POST['timeservers'] = trim($_POST['timeservers']);
204
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
205
		if (!is_domain($ts)) {
206
			$input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.");
207
		}
208
	}
209

    
210
	if (!$input_errors) {
211
		update_if_changed("hostname", $config['system']['hostname'], $_POST['hostname']);
212
		update_if_changed("domain", $config['system']['domain'], $_POST['domain']);
213
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
214
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
215
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
216

    
217
		if ($_POST['language'] && $_POST['language'] != $config['system']['language']) {
218
			$config['system']['language'] = $_POST['language'];
219
			set_language($config['system']['language']);
220
		}
221

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

    
238
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
239

    
240
		unset($config['system']['dnsallowoverride']);
241
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
242

    
243
		if ($_POST['dnslocalhost'] == "yes") {
244
			$config['system']['dnslocalhost'] = true;
245
		} else {
246
			unset($config['system']['dnslocalhost']);
247
		}
248

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

    
256
			if ($ignore_posted_dnsgw[$dnsgwname]) {
257
				$thisdnsgwname = "none";
258
			} else {
259
				$thisdnsgwname = $pconfig[$dnsgwname];
260
			}
261

    
262
			// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
263
			$config['system'][$dnsgwname] = "none";
264
			$pconfig[$dnsgwname] = "none";
265
			$pconfig[$dnsname] = "";
266

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

    
297
		if ($changecount > 0) {
298
			write_config($changedesc);
299
		}
300

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

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

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

    
320
		$savemsg = get_std_save_message($retval);
321
	}
322

    
323
	unset($ignore_posted_dnsgw);
324
}
325

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

    
329
if ($input_errors)
330
	print_input_errors($input_errors);
331
if ($savemsg)
332
	print_info_box($savemsg);
333
?>
334
<div id="container">
335
<?php
336

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

    
358
$section = new Form_Section('DNS server settings');
359

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

    
365
	$group = new Form_Group('DNS Server ' . $i);
366

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

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

    
377
	if ($multiwan)	{
378
		$options = array('none' => 'none');
379

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

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

    
389
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
390
		}
391

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

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

    
403
	if($i == 4)
404
		$group->setHelp($help);
405

    
406
	$section->add($group);
407
}
408

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

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

    
429
$form->add($section);
430

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

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

    
454
print $form;
455

    
456
include("foot.inc");
(187-187/235)