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
|
|
182
|
update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
|
183
|
update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
|
184
|
update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
|
185
|
|
186
|
if($_POST['language'] && $_POST['language'] != $config['system']['language']) {
|
187
|
$config['system']['language'] = $_POST['language'];
|
188
|
set_language($config['system']['language']);
|
189
|
}
|
190
|
|
191
|
/* pfSense themes */
|
192
|
if (! $g['disablethemeselection']) {
|
193
|
update_if_changed("System Theme", $config['theme'], $_POST['theme']);
|
194
|
}
|
195
|
|
196
|
/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
|
197
|
$olddnsservers = $config['system']['dnsserver'];
|
198
|
unset($config['system']['dnsserver']);
|
199
|
if ($_POST['dns1'])
|
200
|
$config['system']['dnsserver'][] = $_POST['dns1'];
|
201
|
if ($_POST['dns2'])
|
202
|
$config['system']['dnsserver'][] = $_POST['dns2'];
|
203
|
if ($_POST['dns3'])
|
204
|
$config['system']['dnsserver'][] = $_POST['dns3'];
|
205
|
if ($_POST['dns4'])
|
206
|
$config['system']['dnsserver'][] = $_POST['dns4'];
|
207
|
|
208
|
$olddnsallowoverride = $config['system']['dnsallowoverride'];
|
209
|
|
210
|
unset($config['system']['dnsallowoverride']);
|
211
|
$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
|
212
|
|
213
|
if($_POST['dnslocalhost'] == "yes")
|
214
|
$config['system']['dnslocalhost'] = true;
|
215
|
else
|
216
|
unset($config['system']['dnslocalhost']);
|
217
|
|
218
|
/* which interface should the dns servers resolve through? */
|
219
|
$outdnscounter = 0;
|
220
|
for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
|
221
|
$dnsname="dns{$dnscounter}";
|
222
|
$dnsgwname="dns{$dnscounter}gw";
|
223
|
$olddnsgwname = $config['system'][$dnsgwname];
|
224
|
|
225
|
if ($ignore_posted_dnsgw[$dnsgwname])
|
226
|
$thisdnsgwname = "none";
|
227
|
else
|
228
|
$thisdnsgwname = $pconfig[$dnsgwname];
|
229
|
|
230
|
// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
|
231
|
$config['system'][$dnsgwname] = "none";
|
232
|
$pconfig[$dnsgwname] = "none";
|
233
|
$pconfig[$dnsname] = "";
|
234
|
|
235
|
if ($_POST[$dnsname]) {
|
236
|
// Only the non-blank DNS servers were put into the config above.
|
237
|
// So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers.
|
238
|
// 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.
|
239
|
$outdnscounter++;
|
240
|
$outdnsname="dns{$outdnscounter}";
|
241
|
$outdnsgwname="dns{$outdnscounter}gw";
|
242
|
$pconfig[$outdnsname] = $_POST[$dnsname];
|
243
|
if($_POST[$dnsgwname]) {
|
244
|
$config['system'][$outdnsgwname] = $thisdnsgwname;
|
245
|
$pconfig[$outdnsgwname] = $thisdnsgwname;
|
246
|
} else {
|
247
|
// Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens.
|
248
|
unset($config['system'][$outdnsgwname]);
|
249
|
$pconfig[$outdnsgwname] = "";
|
250
|
}
|
251
|
}
|
252
|
if (($olddnsgwname != "") && ($olddnsgwname != "none") && (($olddnsgwname != $thisdnsgwname) || ($olddnsservers[$dnscounter-1] != $_POST[$dnsname]))) {
|
253
|
// A previous DNS GW name was specified. It has now gone or changed, or the DNS server address has changed.
|
254
|
// Remove the route. Later calls will add the correct new route if needed.
|
255
|
if (is_ipaddrv4($olddnsservers[$dnscounter-1]))
|
256
|
mwexec("/sbin/route delete " . escapeshellarg($olddnsservers[$dnscounter-1]));
|
257
|
else
|
258
|
if (is_ipaddrv6($olddnsservers[$dnscounter-1]))
|
259
|
mwexec("/sbin/route delete -inet6 " . escapeshellarg($olddnsservers[$dnscounter-1]));
|
260
|
}
|
261
|
}
|
262
|
|
263
|
if ($changecount > 0)
|
264
|
write_config($changedesc);
|
265
|
|
266
|
$retval = 0;
|
267
|
$retval = system_hostname_configure();
|
268
|
$retval |= system_hosts_generate();
|
269
|
$retval |= system_resolvconf_generate();
|
270
|
if (isset($config['dnsmasq']['enable']))
|
271
|
$retval |= services_dnsmasq_configure();
|
272
|
elseif (isset($config['unbound']['enable']))
|
273
|
$retval |= services_unbound_configure();
|
274
|
$retval |= system_timezone_configure();
|
275
|
$retval |= system_ntp_configure();
|
276
|
|
277
|
if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
|
278
|
$retval |= send_event("service reload dns");
|
279
|
|
280
|
// Reload the filter - plugins might need to be run.
|
281
|
$retval |= filter_configure();
|
282
|
|
283
|
$savemsg = get_std_save_message($retval);
|
284
|
}
|
285
|
|
286
|
unset($ignore_posted_dnsgw);
|
287
|
}
|
288
|
|
289
|
$pgtitle = array(gettext("System"),gettext("General Setup"));
|
290
|
include("head.inc");
|
291
|
|
292
|
if ($input_errors)
|
293
|
print_input_errors($input_errors);
|
294
|
if ($savemsg)
|
295
|
print_info_box($savemsg);
|
296
|
?>
|
297
|
<div id="container">
|
298
|
<?php
|
299
|
|
300
|
require('classes/Form.class.php');
|
301
|
$form = new Form;
|
302
|
$section = new Form_Section('System');
|
303
|
$section->addInput(new Form_Input(
|
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
|
'text',
|
312
|
$pconfig['domain'],
|
313
|
['placeholder' => 'mycorp.com, home, office, private, etc.']
|
314
|
))->setHelp('Do not use \'local\' as a domain name. It will cause local '.
|
315
|
'hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve '.
|
316
|
'local hosts not running mDNS.');
|
317
|
$form->add($section);
|
318
|
|
319
|
$section = new Form_Section('DNS server settings');
|
320
|
|
321
|
for ($i=1; $i<5; $i++)
|
322
|
{
|
323
|
if (!isset($pconfig['dns'.$i]))
|
324
|
continue;
|
325
|
|
326
|
$group = new Form_Group('DNS Server');
|
327
|
$group->add(new Form_Input('DNS Server', 'text', $pconfig['dns'.$i]));
|
328
|
$help = "Enter IP addresses to be used by the system for DNS resolution. " .
|
329
|
"These are also used for the DHCP service, DNS forwarder and for PPTP VPN clients.";
|
330
|
|
331
|
if ($multiwan)
|
332
|
{
|
333
|
$options = array('none' => 'none');
|
334
|
|
335
|
foreach($arr_gateways as $gwname => $gwitem)
|
336
|
{
|
337
|
if((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
|
338
|
continue;
|
339
|
}
|
340
|
if((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
|
341
|
continue;
|
342
|
}
|
343
|
|
344
|
$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
|
345
|
}
|
346
|
|
347
|
$group->add(new Form_Select('Gateway', $pconfig['dns'.$i.'gw'], $options));
|
348
|
|
349
|
$help .= '<br/>'. "In addition, optionally select the gateway for each DNS server. " .
|
350
|
"When using multiple WAN connections there should be at least one unique DNS server per gateway.";
|
351
|
}
|
352
|
|
353
|
$group->setHelp($help);
|
354
|
$section->add($group);
|
355
|
}
|
356
|
|
357
|
$section->addInput(new Form_Checkbox(
|
358
|
'DNS server override',
|
359
|
'Allow DNS server list to be overridden by DHCP/PPP on WAN',
|
360
|
$pconfig['dnsallowoverride']
|
361
|
))->setHelp(sprintf(gettext('If this option is set, %s will use DNS servers'.
|
362
|
'assigned by a DHCP/PPP server on WAN for its own purposes (including '.
|
363
|
'the DNS forwarder). However, they will not be assigned to DHCP and PPTP '.
|
364
|
'VPN clients.'), $g['product_name']));
|
365
|
|
366
|
$section->addInput(new Form_Checkbox(
|
367
|
'Disable DNS forwarder',
|
368
|
'Do not use the DNS Forwarder as a DNS server for the firewall',
|
369
|
$pconfig['dnslocalhost']
|
370
|
))->setHelp('By default localhost (127.0.0.1) will be used as the first DNS'.
|
371
|
'server where the DNS Forwarder or DNS Resolver is enabled and set to '.
|
372
|
'listen on Localhost, so system can use the local DNS service to perform'.
|
373
|
'lookups. Checking this box omits localhost from the list of DNS servers.');
|
374
|
|
375
|
$form->add($section);
|
376
|
|
377
|
$section = new Form_Section('Localization');
|
378
|
$section->addInput(new Form_Select(
|
379
|
'Timezone',
|
380
|
$pconfig['timezone'],
|
381
|
$timezonelist
|
382
|
))->setHelp('Select the location closest to you');
|
383
|
$section->addInput(new Form_Input(
|
384
|
'Timeservers',
|
385
|
'text',
|
386
|
$pconfig['timeservers']
|
387
|
))->setHelp('Use a space to separate multiple hosts (only one required). '.
|
388
|
'Remember to set up at least one DNS server if you enter a host name here!');
|
389
|
$section->addInput(new Form_Select(
|
390
|
'Language',
|
391
|
$pconfig['language'],
|
392
|
get_locale_list()
|
393
|
))->setHelp('Choose a language for the webConfigurator');
|
394
|
|
395
|
$form->add($section);
|
396
|
|
397
|
print $form;
|
398
|
|
399
|
include("foot.inc");
|