Project

General

Profile

Download (14.5 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
if (!$pconfig['timezone'])
72
	$pconfig['timezone'] = "Etc/UTC";
73
if (!$pconfig['timeservers'])
74
	$pconfig['timeservers'] = "pool.ntp.org";
75

    
76
$changedesc = gettext("System") . ": ";
77
$changecount = 0;
78

    
79
function is_timezone($elt) {
80
	return !preg_match("/\/$/", $elt);
81
}
82

    
83
if($pconfig['timezone'] != $_POST['timezone']) {
84
	filter_pflog_start(true);
85
}
86

    
87
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
88
$timezonelist = array_filter($timezonelist, 'is_timezone');
89
sort($timezonelist);
90

    
91
$multiwan = false;
92
$interfaces = get_configured_interface_list();
93
foreach($interfaces as $interface) {
94
	if(interface_has_gateway($interface)) {
95
		$multiwan = true;
96
	}
97
}
98

    
99
if ($_POST) {
100

    
101
	$changecount++;
102

    
103
	unset($input_errors);
104
	$pconfig = $_POST;
105

    
106
	/* input validation */
107
	$reqdfields = explode(" ", "hostname domain");
108
	$reqdfieldsn = array(gettext("Hostname"),gettext("Domain"));
109

    
110
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
111

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

    
125
	$ignore_posted_dnsgw = array();
126

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

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

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

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

    
185
		if($_POST['language'] && $_POST['language'] != $config['system']['language']) {
186
			$config['system']['language'] = $_POST['language'];
187
			set_language($config['system']['language']);
188
		}
189

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

    
195
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
196
		$olddnsservers = $config['system']['dnsserver'];
197
		unset($config['system']['dnsserver']);
198
		if ($_POST['dns1'])
199
			$config['system']['dnsserver'][] = $_POST['dns1'];
200
		if ($_POST['dns2'])
201
			$config['system']['dnsserver'][] = $_POST['dns2'];
202
		if ($_POST['dns3'])
203
			$config['system']['dnsserver'][] = $_POST['dns3'];
204
		if ($_POST['dns4'])
205
			$config['system']['dnsserver'][] = $_POST['dns4'];
206

    
207
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
208

    
209
		unset($config['system']['dnsallowoverride']);
210
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
211

    
212
		if($_POST['dnslocalhost'] == "yes")
213
			$config['system']['dnslocalhost'] = true;
214
		else
215
			unset($config['system']['dnslocalhost']);
216

    
217
		/* which interface should the dns servers resolve through? */
218
		$outdnscounter = 0;
219
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
220
			$dnsname="dns{$dnscounter}";
221
			$dnsgwname="dns{$dnscounter}gw";
222
			$olddnsgwname = $config['system'][$dnsgwname];
223

    
224
			if ($ignore_posted_dnsgw[$dnsgwname])
225
				$thisdnsgwname = "none";
226
			else
227
				$thisdnsgwname = $pconfig[$dnsgwname];
228

    
229
			// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
230
			$config['system'][$dnsgwname] = "none";
231
			$pconfig[$dnsgwname] = "none";
232
			$pconfig[$dnsname] = "";
233

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

    
262
		if ($changecount > 0)
263
			write_config($changedesc);
264

    
265
		$retval = 0;
266
		$retval = system_hostname_configure();
267
		$retval |= system_hosts_generate();
268
		$retval |= system_resolvconf_generate();
269
		if (isset($config['dnsmasq']['enable']))
270
			$retval |= services_dnsmasq_configure();
271
		elseif (isset($config['unbound']['enable']))
272
			$retval |= services_unbound_configure();
273
		$retval |= system_timezone_configure();
274
		$retval |= system_ntp_configure();
275

    
276
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
277
			$retval |= send_event("service reload dns");
278

    
279
		// Reload the filter - plugins might need to be run.
280
		$retval |= filter_configure();
281

    
282
		$savemsg = get_std_save_message($retval);
283
	}
284

    
285
	unset($ignore_posted_dnsgw);
286
}
287

    
288
$pgtitle = array(gettext("System"),gettext("General Setup"));
289
include("head.inc");
290

    
291
if ($input_errors)
292
	print_input_errors($input_errors);
293
if ($savemsg)
294
	print_info_box($savemsg);
295
?>
296
<div id="container">
297
<?php
298

    
299
require('classes/Form.class.php');
300
$form = new Form;
301
$section = new Form_Section('System');
302
$section->addInput(new Form_Input(
303
	'hostname',
304
	'Hostname',
305
	'text',
306
	$pconfig['hostname'],
307
	['placeholder' => 'pfSense']
308
))->setHelp('Name of the firewall host, without domain part');
309
$section->addInput(new Form_Input(
310
	'domain',
311
	'Domain',
312
	'text',
313
	$pconfig['domain'],
314
	['placeholder' => 'mycorp.com, home, office, private, etc.']
315
))->setHelp('Do not use \'local\' as a domain name. It will cause local '.
316
	'hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve '.
317
	'local hosts not running mDNS.');
318
$form->add($section);
319

    
320
$section = new Form_Section('DNS server settings');
321

    
322
for ($i=1; $i<5; $i++)
323
{
324
	if (!isset($pconfig['dns'.$i]))
325
		continue;
326

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

    
332
	if ($multiwan)
333
	{
334
		$options = array('none' => 'none');
335

    
336
		foreach($arr_gateways as $gwname => $gwitem)
337
		{
338
			if((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
339
				continue;
340
			}
341
			if((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
342
				continue;
343
			}
344

    
345
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
346
		}
347

    
348
		$group->add(new Form_Select(
349
			'gateway',
350
			'Gateway',
351
			$pconfig['dns'.$i.'gw'],
352
			$options
353
		));
354

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

    
359
	$group->setHelp($help);
360
	$section->add($group);
361
}
362

    
363
$section->addInput(new Form_Checkbox(
364
	'dnsallowoverride',
365
	'DNS server override',
366
	'Allow DNS server list to be overridden by DHCP/PPP on WAN',
367
	$pconfig['dnsallowoverride']
368
))->setHelp(sprintf(gettext('If this option is set, %s will use DNS servers'.
369
	'assigned by a DHCP/PPP server on WAN for its own purposes (including '.
370
	'the DNS forwarder). However, they will not be assigned to DHCP and PPTP '.
371
	'VPN clients.'), $g['product_name']));
372

    
373
$section->addInput(new Form_Checkbox(
374
	'dnslocalhost',
375
	'Disable DNS forwarder',
376
	'Do not use the DNS Forwarder as a DNS server for the firewall',
377
	$pconfig['dnslocalhost']
378
))->setHelp('By default localhost (127.0.0.1) will be used as the first DNS'.
379
	'server where the DNS Forwarder or DNS Resolver is enabled and set to '.
380
	'listen on Localhost, so system can use the local DNS service to perform'.
381
	'lookups. Checking this box omits localhost from the list of DNS servers.');
382

    
383
$form->add($section);
384

    
385
$section = new Form_Section('Localization');
386
$section->addInput(new Form_Select(
387
	'timezone',
388
	'Timezone',
389
	$pconfig['timezone'],
390
	array_combine($timezonelist, $timezonelist)
391
))->setHelp('Select the location closest to you');
392
$section->addInput(new Form_Input(
393
	'timeservers',
394
	'Timeservers',
395
	'text',
396
	$pconfig['timeservers']
397
))->setHelp('Use a space to separate multiple hosts (only one required). '.
398
	'Remember to set up at least one DNS server if you enter a host name here!');
399
$section->addInput(new Form_Select(
400
	'language',
401
	'Language',
402
	$pconfig['language'],
403
	get_locale_list()
404
))->setHelp('Choose a language for the webConfigurator');
405

    
406
$form->add($section);
407

    
408
print $form;
409

    
410
include("foot.inc");
(201-201/252)