Project

General

Profile

Download (14.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, 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 the
19
		documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*
33
	pfSense_BUILDER_BINARIES:	/bin/kill	/usr/bin/tar
34
	pfSense_MODULE: system
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-system-generalsetup
39
##|*NAME=System: General Setup page
40
##|*DESCR=Allow access to the 'System: General Setup' page.
41
##|*MATCH=system.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48

    
49
$pconfig['hostname'] = $config['system']['hostname'];
50
$pconfig['domain'] = $config['system']['domain'];
51
list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['system']['dnsserver'];
52

    
53
$arr_gateways = return_gateways_array();
54

    
55
$pconfig['dns1gw'] = $config['system']['dns1gw'];
56
$pconfig['dns2gw'] = $config['system']['dns2gw'];
57
$pconfig['dns3gw'] = $config['system']['dns3gw'];
58
$pconfig['dns4gw'] = $config['system']['dns4gw'];
59

    
60
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
61
$pconfig['timezone'] = $config['system']['timezone'];
62
$pconfig['timeupdateinterval'] = $config['system']['time-update-interval'];
63
$pconfig['timeservers'] = $config['system']['timeservers'];
64
$pconfig['theme'] = $config['system']['theme'];
65
$pconfig['language'] = $config['system']['language'];
66

    
67
$pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']);
68

    
69
if (!isset($pconfig['timeupdateinterval'])) {
70
	$pconfig['timeupdateinterval'] = 300;
71
}
72
if (!$pconfig['timezone']) {
73
	$pconfig['timezone'] = "Etc/UTC";
74
}
75
if (!$pconfig['timeservers']) {
76
	$pconfig['timeservers'] = "pool.ntp.org";
77
}
78

    
79
$changedesc = gettext("System") . ": ";
80
$changecount = 0;
81

    
82
function is_timezone($elt) {
83
	return !preg_match("/\/$/", $elt);
84
}
85

    
86
if ($pconfig['timezone'] <> $_POST['timezone']) {
87
	filter_pflog_start(true);
88
}
89

    
90
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
91
$timezonelist = array_filter($timezonelist, 'is_timezone');
92
sort($timezonelist);
93

    
94
$multiwan = false;
95
$interfaces = get_configured_interface_list();
96
foreach ($interfaces as $interface) {
97
	if (interface_has_gateway($interface)) {
98
		$multiwan = true;
99
	}
100
}
101

    
102
if ($_POST) {
103

    
104
	$changecount++;
105

    
106
	unset($input_errors);
107
	$pconfig = $_POST;
108

    
109
	/* input validation */
110
	$reqdfields = explode(" ", "hostname domain");
111
	$reqdfieldsn = array(gettext("Hostname"), gettext("Domain"));
112

    
113
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
114

    
115
	if ($_POST['hostname']) {
116
		if (!is_hostname($_POST['hostname'])) {
117
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'. It may not start or end with '-'.");
118
		} else {
119
			if (!is_unqualified_hostname($_POST['hostname'])) {
120
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
121
			}
122
		}
123
	}
124
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
125
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
126
	}
127

    
128
	$ignore_posted_dnsgw = array();
129

    
130
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
131
		$dnsname="dns{$dnscounter}";
132
		$dnsgwname="dns{$dnscounter}gw";
133
		if (($_POST[$dnsname] && !is_ipaddr($_POST[$dnsname]))) {
134
			$input_errors[] = gettext("A valid IP address must be specified for DNS server $dnscounter.");
135
		} else {
136
			if (($_POST[$dnsgwname] <> "") && ($_POST[$dnsgwname] <> "none")) {
137
				// A real gateway has been selected.
138
				if (is_ipaddr($_POST[$dnsname])) {
139
					if ((is_ipaddrv4($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false)) {
140
						$input_errors[] = gettext("You can not specify IPv6 gateway '{$_POST[$dnsgwname]}' for IPv4 DNS server '{$_POST[$dnsname]}'");
141
					}
142
					if ((is_ipaddrv6($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false)) {
143
						$input_errors[] = gettext("You can not specify IPv4 gateway '{$_POST[$dnsgwname]}' for IPv6 DNS server '{$_POST[$dnsname]}'");
144
					}
145
				} else {
146
					// The user selected a gateway but did not provide a DNS address. Be nice and set the gateway back to "none".
147
					$ignore_posted_dnsgw[$dnsgwname] = true;
148
				}
149
			}
150
		}
151
	}
152

    
153
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
154
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
155
		$dnsitem = "dns{$dnscounter}";
156
		$dnsgwitem = "dns{$dnscounter}gw";
157
		if ($_POST[$dnsgwitem]) {
158
			if (interface_has_gateway($_POST[$dnsgwitem])) {
159
				foreach ($direct_networks_list as $direct_network) {
160
					if (ip_in_subnet($_POST[$dnsitem], $direct_network)) {
161
						$input_errors[] = sprintf(gettext("You can not assign a gateway to DNS '%s' server which is on a directly connected network."), $_POST[$dnsitem]);
162
					}
163
				}
164
			}
165
		}
166
	}
167

    
168
	$t = (int)$_POST['timeupdateinterval'];
169
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
170
		$input_errors[] = gettext("The time update interval must be either 0 (disabled) or between 6 and 1440.");
171
	}
172
	# it's easy to have a little too much whitespace in the field, clean it up for the user before processing.
173
	$_POST['timeservers'] = preg_replace('/[[:blank:]]+/', ' ', $_POST['timeservers']);
174
	$_POST['timeservers'] = trim($_POST['timeservers']);
175
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
176
		if (!is_domain($ts)) {
177
			$input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.");
178
		}
179
	}
180

    
181
	if (!$input_errors) {
182
		update_if_changed("hostname", $config['system']['hostname'], $_POST['hostname']);
183
		update_if_changed("domain", $config['system']['domain'], $_POST['domain']);
184
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
185
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
186
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
187

    
188
		if ($_POST['language'] && $_POST['language'] != $config['system']['language']) {
189
			$config['system']['language'] = $_POST['language'];
190
			set_language($config['system']['language']);
191
		}
192

    
193
		/* pfSense themes */
194
		if (!$g['disablethemeselection']) {
195
			update_if_changed("System Theme", $config['theme'], $_POST['theme']);
196
		}
197

    
198
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
199
		$olddnsservers = $config['system']['dnsserver'];
200
		unset($config['system']['dnsserver']);
201
		if ($_POST['dns1']) {
202
			$config['system']['dnsserver'][] = $_POST['dns1'];
203
		}
204
		if ($_POST['dns2']) {
205
			$config['system']['dnsserver'][] = $_POST['dns2'];
206
		}
207
		if ($_POST['dns3']) {
208
			$config['system']['dnsserver'][] = $_POST['dns3'];
209
		}
210
		if ($_POST['dns4']) {
211
			$config['system']['dnsserver'][] = $_POST['dns4'];
212
		}
213

    
214
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
215

    
216
		unset($config['system']['dnsallowoverride']);
217
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
218

    
219
		if ($_POST['dnslocalhost'] == "yes") {
220
			$config['system']['dnslocalhost'] = true;
221
		} else {
222
			unset($config['system']['dnslocalhost']);
223
		}
224

    
225
		/* which interface should the dns servers resolve through? */
226
		$outdnscounter = 0;
227
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
228
			$dnsname="dns{$dnscounter}";
229
			$dnsgwname="dns{$dnscounter}gw";
230
			$olddnsgwname = $config['system'][$dnsgwname];
231

    
232
			if ($ignore_posted_dnsgw[$dnsgwname]) {
233
				$thisdnsgwname = "none";
234
			} else {
235
				$thisdnsgwname = $pconfig[$dnsgwname];
236
			}
237

    
238
			// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
239
			$config['system'][$dnsgwname] = "none";
240
			$pconfig[$dnsgwname] = "none";
241
			$pconfig[$dnsname] = "";
242

    
243
			if ($_POST[$dnsname]) {
244
				// Only the non-blank DNS servers were put into the config above.
245
				// So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers.
246
				// 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.
247
				$outdnscounter++;
248
				$outdnsname="dns{$outdnscounter}";
249
				$outdnsgwname="dns{$outdnscounter}gw";
250
				$pconfig[$outdnsname] = $_POST[$dnsname];
251
				if ($_POST[$dnsgwname]) {
252
					$config['system'][$outdnsgwname] = $thisdnsgwname;
253
					$pconfig[$outdnsgwname] = $thisdnsgwname;
254
				} else {
255
					// Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens.
256
					unset($config['system'][$outdnsgwname]);
257
					$pconfig[$outdnsgwname] = "";
258
				}
259
			}
260
			if (($olddnsgwname != "") && ($olddnsgwname != "none") && (($olddnsgwname != $thisdnsgwname) || ($olddnsservers[$dnscounter-1] != $_POST[$dnsname]))) {
261
				// A previous DNS GW name was specified. It has now gone or changed, or the DNS server address has changed.
262
				// Remove the route. Later calls will add the correct new route if needed.
263
				if (is_ipaddrv4($olddnsservers[$dnscounter-1])) {
264
					mwexec("/sbin/route delete " . escapeshellarg($olddnsservers[$dnscounter-1]));
265
				} else {
266
					if (is_ipaddrv6($olddnsservers[$dnscounter-1])) {
267
						mwexec("/sbin/route delete -inet6 " . escapeshellarg($olddnsservers[$dnscounter-1]));
268
					}
269
				}
270
			}
271
		}
272

    
273
		if ($changecount > 0) {
274
			write_config($changedesc);
275
		}
276

    
277
		$retval = 0;
278
		$retval = system_hostname_configure();
279
		$retval |= system_hosts_generate();
280
		$retval |= system_resolvconf_generate();
281
		if (isset($config['dnsmasq']['enable'])) {
282
			$retval |= services_dnsmasq_configure();
283
		} elseif (isset($config['unbound']['enable'])) {
284
			$retval |= services_unbound_configure();
285
		}
286
		$retval |= system_timezone_configure();
287
		$retval |= system_ntp_configure();
288

    
289
		if ($olddnsallowoverride != $config['system']['dnsallowoverride']) {
290
			$retval |= send_event("service reload dns");
291
		}
292

    
293
		// Reload the filter - plugins might need to be run.
294
		$retval |= filter_configure();
295

    
296
		$savemsg = get_std_save_message($retval);
297
	}
298

    
299
	unset($ignore_posted_dnsgw);
300
}
301

    
302
$pgtitle = array(gettext("System"), gettext("General Setup"));
303
include("head.inc");
304

    
305
if ($input_errors)
306
	print_input_errors($input_errors);
307
if ($savemsg)
308
	print_info_box($savemsg);
309
?>
310
<div id="container">
311
<?php
312

    
313
require_once('classes/Form.class.php');
314
$form = new Form;
315
$section = new Form_Section('System');
316
$section->addInput(new Form_Input(
317
	'hostname',
318
	'Hostname',
319
	'text',
320
	$pconfig['hostname'],
321
	['placeholder' => 'pfSense']
322
))->setHelp('Name of the firewall host, without domain part');
323
$section->addInput(new Form_Input(
324
	'domain',
325
	'Domain',
326
	'text',
327
	$pconfig['domain'],
328
	['placeholder' => 'mycorp.com, home, office, private, etc.']
329
))->setHelp('Do not use \'local\' as a domain name. It will cause local '.
330
	'hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve '.
331
	'local hosts not running mDNS.');
332
$form->add($section);
333

    
334
$section = new Form_Section('DNS server settings');
335

    
336
for ($i=1; $i<5; $i++)
337
{
338
	if (!isset($pconfig['dns'.$i]))
339
		continue;
340

    
341
	$group = new Form_Group('DNS Server');
342
	$group->add(new Form_Input('dns['.$i.']', 'DNS Server', 'text', $pconfig['dns'.$i]));
343
	$help = "Enter IP addresses to be used by the system for DNS resolution. " .
344
		"These are also used for the DHCP service, DNS forwarder and for PPTP VPN clients.";
345

    
346
	if ($multiwan)
347
	{
348
		$options = array('none' => 'none');
349

    
350
		foreach($arr_gateways as $gwname => $gwitem)
351
		{
352
			if((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
353
				continue;
354
			}
355
			if((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
356
				continue;
357
			}
358

    
359
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
360
		}
361

    
362
		$group->add(new Form_Select(
363
			'gateway',
364
			'Gateway',
365
			$pconfig['dns'.$i.'gw'],
366
			$options
367
		));
368

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

    
373
	$group->setHelp($help);
374
	$section->add($group);
375
}
376

    
377
$section->addInput(new Form_Checkbox(
378
	'dnsallowoverride',
379
	'DNS server override',
380
	'Allow DNS server list to be overridden by DHCP/PPP on WAN',
381
	$pconfig['dnsallowoverride']
382
))->setHelp(sprintf(gettext('If this option is set, %s will use DNS servers'.
383
	'assigned by a DHCP/PPP server on WAN for its own purposes (including '.
384
	'the DNS forwarder). However, they will not be assigned to DHCP and PPTP '.
385
	'VPN clients.'), $g['product_name']));
386

    
387
$section->addInput(new Form_Checkbox(
388
	'dnslocalhost',
389
	'Disable DNS forwarder',
390
	'Do not use the DNS Forwarder as a DNS server for the firewall',
391
	$pconfig['dnslocalhost']
392
))->setHelp('By default localhost (127.0.0.1) will be used as the first DNS'.
393
	'server where the DNS Forwarder or DNS Resolver is enabled and set to '.
394
	'listen on Localhost, so system can use the local DNS service to perform'.
395
	'lookups. Checking this box omits localhost from the list of DNS servers.');
396

    
397
$form->add($section);
398

    
399
$section = new Form_Section('Localization');
400
$section->addInput(new Form_Select(
401
	'timezone',
402
	'Timezone',
403
	$pconfig['timezone'],
404
	array_combine($timezonelist, $timezonelist)
405
))->setHelp('Select the location closest to you');
406
$section->addInput(new Form_Input(
407
	'timeservers',
408
	'Timeservers',
409
	'text',
410
	$pconfig['timeservers']
411
))->setHelp('Use a space to separate multiple hosts (only one required). '.
412
	'Remember to set up at least one DNS server if you enter a host name here!');
413
$section->addInput(new Form_Select(
414
	'language',
415
	'Language',
416
	$pconfig['language'],
417
	get_locale_list()
418
))->setHelp('Choose a language for the webConfigurator');
419

    
420
$form->add($section);
421

    
422
print $form;
423

    
424
include("foot.inc");
(187-187/238)