Project

General

Profile

Download (16.2 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['timeservers'] = $config['system']['timeservers'];
90
$pconfig['language'] = $config['system']['language'];
91
$pconfig['webguicss'] = $config['system']['webgui']['webguicss'];
92

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

    
160
	$ignore_posted_dnsgw = array();
161

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

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

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

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

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

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

    
236
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
237

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

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

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

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

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

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

    
295
		if ($changecount > 0) {
296
			write_config($changedesc);
297
		}
298

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

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

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

    
318
		$savemsg = get_std_save_message($retval);
319
	}
320

    
321
	unset($ignore_posted_dnsgw);
322
}
323

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

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

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

    
355
$section = new Form_Section('DNS server settings');
356

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

    
362
	$group = new Form_Group('DNS Server ' . $i);
363

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

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

    
374
	if ($multiwan)	{
375
		$options = array('none' => 'none');
376

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

    
382
			if((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
383
				continue;
384
			}
385

    
386
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
387
		}
388

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

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

    
400
	if($i == 4)
401
		$group->setHelp($help);
402

    
403
	$section->add($group);
404
}
405

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

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

    
426
$form->add($section);
427

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

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

    
451
$csslist = array();
452
$css = glob("bootstrap/css/*.css");
453
foreach ($css as $file) {
454
	$file = basename($file);
455
	if(substr($file, 0, 9) !== 'bootstrap') {
456
		$csslist[$file] = pathinfo($file, PATHINFO_FILENAME);
457
	}
458
}
459

    
460
asort($csslist);
461

    
462
if (!isset($pconfig['webguicss']) || !isset($csslist[$pconfig['webguicss']])) {
463
	$pconfig['webguicss'] = "pfSense.css";
464
}
465

    
466
$section = new Form_Section('Web configurator theme');
467

    
468
$section->addInput(new Form_Select(
469
	'webguicss',
470
	'Theme',
471
	$pconfig['webguicss'],
472
	$csslist
473
))->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");
474

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

    
477
print $form;
478

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