Project

General

Profile

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

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

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

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

    
81
$arr_gateways = return_gateways_array();
82

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

    
88
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
89
$pconfig['timezone'] = $config['system']['timezone'];
90
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
91
$pconfig['timeservers'] = $config['system']['timeservers'];
92
$pconfig['language'] = $config['system']['language'];
93

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

    
96
if (!isset($pconfig['timeupdateinterval'])) {
97
	$pconfig['timeupdateinterval'] = 300;
98
}
99
if (!$pconfig['timezone']) {
100
	$pconfig['timezone'] = "Etc/UTC";
101
}
102
if (!$pconfig['timeservers']) {
103
	$pconfig['timeservers'] = "pool.ntp.org";
104
}
105

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

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

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

    
117
$timezonelist = system_get_timezone_list();
118

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

    
127
if ($_POST) {
128

    
129
	$changecount++;
130

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

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

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

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

    
153
	$ignore_posted_dnsgw = array();
154

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

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

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

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

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

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

    
234
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
235

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

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

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

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

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

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

    
293
		if ($changecount > 0) {
294
			write_config($changedesc);
295
		}
296

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

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

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

    
316
		$savemsg = get_std_save_message($retval);
317
	}
318

    
319
	unset($ignore_posted_dnsgw);
320
}
321

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
450
print $form;
451

    
452
include("foot.inc");
(186-186/234)