Project

General

Profile

Download (26.8 KB) Statistics
| Branch: | Tag: | Revision:
1 04ad7c7c Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * system.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 54c605d4 Stephen Beaver
 *
11 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 54c605d4 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18 54c605d4 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
20 54c605d4 Stephen Beaver
 *
21 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26 54c605d4 Stephen Beaver
 */
27 5b237745 Scott Ullrich
28 6b07c15a Matthew Grooms
##|+PRIV
29
##|*IDENT=page-system-generalsetup
30 5230f468 jim-p
##|*NAME=System: General Setup
31 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: General Setup' page.
32
##|*MATCH=system.php*
33
##|-PRIV
34
35 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
36 7a927e67 Scott Ullrich
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("shaper.inc");
39 60ff91f1 Renato Botelho
require_once("system.inc");
40 5b237745 Scott Ullrich
41
$pconfig['hostname'] = $config['system']['hostname'];
42
$pconfig['domain'] = $config['system']['domain'];
43 a2d23e88 Phil Davis
$pconfig['dnsserver'] = $config['system']['dnsserver'];
44 0d8a219e Scott Ullrich
45 d623f2da Seth Mos
$arr_gateways = return_gateways_array();
46
47 e6367325 Phil Davis
// set default columns to two if unset
48 8f65151c Phil Davis
if (!isset($config['system']['webgui']['dashboardcolumns'])) {
49 477db933 Jared Dillard
	$config['system']['webgui']['dashboardcolumns'] = 2;
50
}
51
52 27db3c75 Phil Davis
// set default language if unset
53
if (!isset($config['system']['language'])) {
54 41817934 jim-p
	$config['system']['language'] = $g['language'];
55 27db3c75 Phil Davis
}
56
57 7e8bfed2 jim-p
$dnshost_counter = 1;
58
59
while (isset($config["system"]["dns{$dnshost_counter}host"])) {
60
	$pconfig_dnshost_counter = $dnshost_counter - 1;
61
	$pconfig["dnshost{$pconfig_dnshost_counter}"] = $config["system"]["dns{$dnshost_counter}host"];
62
	$dnshost_counter++;
63
}
64
65 a2d23e88 Phil Davis
$dnsgw_counter = 1;
66
67
while (isset($config["system"]["dns{$dnsgw_counter}gw"])) {
68
	$pconfig_dnsgw_counter = $dnsgw_counter - 1;
69
	$pconfig["dnsgw{$pconfig_dnsgw_counter}"] = $config["system"]["dns{$dnsgw_counter}gw"];
70
	$dnsgw_counter++;
71
}
72 e180a6e3 Scott Ullrich
73 5b237745 Scott Ullrich
$pconfig['dnsallowoverride'] = isset($config['system']['dnsallowoverride']);
74
$pconfig['timezone'] = $config['system']['timezone'];
75
$pconfig['timeservers'] = $config['system']['timeservers'];
76 3e139f90 Vinicius Coque
$pconfig['language'] = $config['system']['language'];
77 a5995a8e Stephen Beaver
$pconfig['webguicss'] = $config['system']['webgui']['webguicss'];
78 e79ff1ee Steve Beaver
$pconfig['logincss'] = $config['system']['webgui']['logincss'];
79 3d29d2eb Jared Dillard
$pconfig['webguifixedmenu'] = $config['system']['webgui']['webguifixedmenu'];
80 477db933 Jared Dillard
$pconfig['dashboardcolumns'] = $config['system']['webgui']['dashboardcolumns'];
81 1d3510cf Phil Davis
$pconfig['interfacessort'] = isset($config['system']['webgui']['interfacessort']);
82 24f15b3a NOYB
$pconfig['webguileftcolumnhyper'] = isset($config['system']['webgui']['webguileftcolumnhyper']);
83 d9058974 Phil Davis
$pconfig['disablealiaspopupdetail'] = isset($config['system']['webgui']['disablealiaspopupdetail']);
84 c05363c8 NOYB
$pconfig['dashboardavailablewidgetspanel'] = isset($config['system']['webgui']['dashboardavailablewidgetspanel']);
85
$pconfig['systemlogsfilterpanel'] = isset($config['system']['webgui']['systemlogsfilterpanel']);
86
$pconfig['systemlogsmanagelogpanel'] = isset($config['system']['webgui']['systemlogsmanagelogpanel']);
87 b1b8784a NOYB
$pconfig['statusmonitoringsettingspanel'] = isset($config['system']['webgui']['statusmonitoringsettingspanel']);
88 e93242eb Phil Davis
$pconfig['webguihostnamemenu'] = $config['system']['webgui']['webguihostnamemenu'];
89 f0c51530 jim-p
$pconfig['dnslocalhost'] = $config['system']['dnslocalhost'];
90 6c1f2a1c Steve Beaver
//$pconfig['dashboardperiod'] = isset($config['widgets']['period']) ? $config['widgets']['period']:"10";
91 52e91f70 PiBa-NL
$pconfig['roworderdragging'] = isset($config['system']['webgui']['roworderdragging']);
92 a22947a4 Steve Beaver
$pconfig['loginshowhost'] = isset($config['system']['webgui']['loginshowhost']);
93 88081ea2 derelict-pf
$pconfig['requirestatefilter'] = isset($config['system']['webgui']['requirestatefilter']);
94 8ca95ed8 jim-p
95 2ee8dea1 Phil Davis
if (!$pconfig['timezone']) {
96 ecaca752 Renato Botelho
	if (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
97
		$pconfig['timezone'] = $g['default_timezone'];
98
	} else {
99
		$pconfig['timezone'] = "Etc/UTC";
100
	}
101 2ee8dea1 Phil Davis
}
102 ecaca752 Renato Botelho
103 2ee8dea1 Phil Davis
if (!$pconfig['timeservers']) {
104 5b237745 Scott Ullrich
	$pconfig['timeservers'] = "pool.ntp.org";
105 2ee8dea1 Phil Davis
}
106 04ad7c7c Scott Ullrich
107 79eaddf4 Renato Botelho
$changedesc = gettext("System") . ": ";
108 62d01225 Bill Marquette
$changecount = 0;
109 417c6042 Bill Marquette
110 5b237745 Scott Ullrich
function is_timezone($elt) {
111
	return !preg_match("/\/$/", $elt);
112
}
113
114 2ee8dea1 Phil Davis
if ($pconfig['timezone'] <> $_POST['timezone']) {
115 744306c6 jim-p
	filter_pflog_start(true);
116 aa1ab1da Scott Ullrich
}
117
118 60ff91f1 Renato Botelho
$timezonelist = system_get_timezone_list();
119 e5f4c829 Renato Botelho
$timezonedesc = $timezonelist;
120
121
/*
122
 * Etc/GMT entries work the opposite way to what people expect.
123
 * Ref: https://github.com/eggert/tz/blob/master/etcetera and Redmine issue 7089
124
 * Add explanatory text to entries like:
125
 * Etc/GMT+1 and Etc/GMT-1
126
 * but not:
127
 * Etc/GMT or Etc/GMT+0
128
 */
129
foreach ($timezonedesc as $idx => $desc) {
130
	if (substr($desc, 0, 7) != "Etc/GMT" || substr($desc, 8, 1) == "0") {
131
		continue;
132
	}
133
134
	$direction = substr($desc, 7, 1);
135
136
	switch ($direction) {
137
	case '-':
138 88de4ab0 Phil Davis
		$direction_str = gettext('AHEAD of');
139 e5f4c829 Renato Botelho
		break;
140
	case '+':
141
		$direction_str = gettext('BEHIND');
142
		break;
143
	default:
144 86ec819a jim-p
		continue 2;
145 e5f4c829 Renato Botelho
	}
146
147
	$hr_offset = substr($desc, 8);
148 88de4ab0 Phil Davis
	$timezonedesc[$idx] = $desc . " " .
149 d93d8c9c Steve Beaver
	    sprintf(ngettext('(%1$s hour %2$s GMT)', '(%1$s hours %2$s GMT)', intval($hr_offset)), $hr_offset, $direction_str);
150 e5f4c829 Renato Botelho
}
151 5b237745 Scott Ullrich
152 f211d7c0 luckman212
$multiwan = 0;
153 47e079f6 Viktor G
$multiwan6 = 0;
154
foreach ($arr_gateways as $gw) {
155
	if ($gw['ipprotocol'] == 'inet') {
156 f211d7c0 luckman212
		$multiwan++;
157 6038cba7 luckman212
		if ($multiwan > 1) {
158
			break;
159
		}
160 47e079f6 Viktor G
	} else {
161
		$multiwan6++;
162
		if ($multiwan6 > 1) {
163
			break;
164
		}
165 7922db8a Seth Mos
	}
166
}
167 77446beb Matthew Grooms
168 5b237745 Scott Ullrich
if ($_POST) {
169
170 c668c964 Scott Ullrich
	$changecount++;
171 1180e4f0 Sjon Hortensius
172 5b237745 Scott Ullrich
	unset($input_errors);
173
	$pconfig = $_POST;
174
175
	/* input validation */
176 cfbfd941 smos
	$reqdfields = explode(" ", "hostname domain");
177 2ee8dea1 Phil Davis
	$reqdfieldsn = array(gettext("Hostname"), gettext("Domain"));
178 04ad7c7c Scott Ullrich
179 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
180 04ad7c7c Scott Ullrich
181 2d86ee95 Phil Davis
	if ($_POST['hostname']) {
182
		if (!is_hostname($_POST['hostname'])) {
183
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'. It may not start or end with '-'.");
184
		} else {
185
			if (!is_unqualified_hostname($_POST['hostname'])) {
186
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
187
			}
188
		}
189 5b237745 Scott Ullrich
	}
190 8ee5aa03 Viktor Gurov
	if ($_POST['domain'] && (!is_domain($_POST['domain'], false, false))) {
191 41e0d95f jim-p
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.', and it cannot start with '.' or '-'.");
192 5b237745 Scott Ullrich
	}
193 9ceace25 jim-p
	validate_webguicss_field($input_errors, $_POST['webguicss']);
194
	validate_webguifixedmenu_field($input_errors, $_POST['webguifixedmenu']);
195
	validate_webguihostnamemenu_field($input_errors, $_POST['webguihostnamemenu']);
196
	validate_dashboardcolumns_field($input_errors, $_POST['dashboardcolumns']);
197 d623f2da Seth Mos
198 58b07c57 NewEraCracker
	$dnslist = $ignore_posted_dnsgw = array();
199 df4471e2 Phil Davis
200 a2d23e88 Phil Davis
	$dnscounter = 0;
201
	$dnsname = "dns{$dnscounter}";
202
203
	while (isset($_POST[$dnsname])) {
204
		$dnsgwname = "dnsgw{$dnscounter}";
205 7e8bfed2 jim-p
		$dnshostname = "dnshost{$dnscounter}";
206 a936104b Stephen Beaver
		$dnslist[] = $_POST[$dnsname];
207
208 d623f2da Seth Mos
		if (($_POST[$dnsname] && !is_ipaddr($_POST[$dnsname]))) {
209 a2d23e88 Phil Davis
			$input_errors[] = sprintf(gettext("A valid IP address must be specified for DNS server %s."), $dnscounter+1);
210 52acb1ff Phil Davis
		} else {
211 7e8bfed2 jim-p
			if (!empty($_POST[$dnshostname]) && !is_hostname($_POST[$dnshostname])) {
212
				$input_errors[] = sprintf(gettext('The hostname provided for DNS server "%1$s" is not valid.'), $_POST[$dnsname]);
213
			}
214 2ee8dea1 Phil Davis
			if (($_POST[$dnsgwname] <> "") && ($_POST[$dnsgwname] <> "none")) {
215 52acb1ff Phil Davis
				// A real gateway has been selected.
216
				if (is_ipaddr($_POST[$dnsname])) {
217 2ee8dea1 Phil Davis
					if ((is_ipaddrv4($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false)) {
218 1bab4a10 NOYB
						$input_errors[] = sprintf(gettext('The IPv6 gateway "%1$s" can not be specified for IPv4 DNS server "%2$s".'), $_POST[$dnsgwname], $_POST[$dnsname]);
219 52acb1ff Phil Davis
					}
220 2ee8dea1 Phil Davis
					if ((is_ipaddrv6($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false)) {
221 1bab4a10 NOYB
						$input_errors[] = sprintf(gettext('The IPv4 gateway "%1$s" can not be specified for IPv6 DNS server "%2$s".'), $_POST[$dnsgwname], $_POST[$dnsname]);
222 52acb1ff Phil Davis
					}
223
				} else {
224 df4471e2 Phil Davis
					// The user selected a gateway but did not provide a DNS address. Be nice and set the gateway back to "none".
225
					$ignore_posted_dnsgw[$dnsgwname] = true;
226 52acb1ff Phil Davis
				}
227 13ea7caa smos
			}
228 d623f2da Seth Mos
		}
229 a2d23e88 Phil Davis
		$dnscounter++;
230
		$dnsname = "dns{$dnscounter}";
231 5b237745 Scott Ullrich
	}
232 d623f2da Seth Mos
233 c25e42c8 Mark Furneaux
	if (count(array_filter($dnslist)) != count(array_unique(array_filter($dnslist)))) {
234 f700dc99 Chris Buechler
		$input_errors[] = gettext('Each configured DNS server must have a unique IP address. Remove the duplicated IP.');
235
	}
236
237 a2d23e88 Phil Davis
	$dnscounter = 0;
238
	$dnsname = "dns{$dnscounter}";
239
240 985fc0fb Ermal Lu?i
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
241 a2d23e88 Phil Davis
	while (isset($_POST[$dnsname])) {
242
		$dnsgwname = "dnsgw{$dnscounter}";
243
		if ($_POST[$dnsgwname] && ($_POST[$dnsgwname] <> "none")) {
244 d8587952 Phil Davis
			foreach ($direct_networks_list as $direct_network) {
245 a2d23e88 Phil Davis
				if (ip_in_subnet($_POST[$dnsname], $direct_network)) {
246 86212d70 luckman212
					$input_errors[] = sprintf(gettext("A gateway cannot be specified for %s because that IP address is part of a directly connected subnet %s. To use that nameserver, change its Gateway to `none`."), $_POST[$dnsname], $direct_network);
247 c98d28e1 Seth Mos
				}
248
			}
249
		}
250 a2d23e88 Phil Davis
		$dnscounter++;
251
		$dnsname = "dns{$dnscounter}";
252 c98d28e1 Seth Mos
	}
253
254 8adb814b David P Hilton
	# it's easy to have a little too much whitespace in the field, clean it up for the user before processing.
255
	$_POST['timeservers'] = preg_replace('/[[:blank:]]+/', ' ', $_POST['timeservers']);
256
	$_POST['timeservers'] = trim($_POST['timeservers']);
257 5b237745 Scott Ullrich
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
258 518fa664 kiokoman
		if (!is_domain($ts) && (!is_ipaddr($ts))) {
259
			$input_errors[] = gettext("NTP Time Server names must be valid domain names, IPv4 addresses, or IPv6 addresses");
260 5b237745 Scott Ullrich
		}
261
	}
262
263 a2d23e88 Phil Davis
	if ($input_errors) {
264
		// Put the user-entered list back into place so it will be redisplayed for correction.
265
		$pconfig['dnsserver'] = $dnslist;
266
	} else {
267 f211d7c0 luckman212
		// input validation passed, so we can proceed with removing static routes for dead DNS gateways
268
		if (is_array($config['system']['dnsserver'])) {
269
		  	$dns_servers_arr = $config['system']['dnsserver'];
270
	 		foreach ($dns_servers_arr as $arr_index => $this_dnsserver) {
271
	   			$i = (int)$arr_index + 1;
272
	   			$this_dnsgw = $config['system']['dns'.$i.'gw'];
273
				unset($gatewayip);
274
				unset($inet6);
275
				if ((!empty($this_dnsgw)) && ($this_dnsgw != 'none') && (!empty($this_dnsserver))) {
276
					$gatewayip = lookup_gateway_ip_by_name($this_dnsgw);
277
					$inet6 = is_ipaddrv6($gatewayip) ? '-inet6 ' : '';
278 ded361f5 Viktor G
					mwexec("/sbin/route -q delete -host {$inet6}{$this_dnsserver} " . escapeshellarg($gatewayip));
279 f211d7c0 luckman212
				}
280
			}
281
		}
282
283 f1a34790 N0YB
		update_if_changed("hostname", $config['system']['hostname'], $_POST['hostname']);
284
		update_if_changed("domain", $config['system']['domain'], $_POST['domain']);
285 9eab73da Bill Marquette
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
286
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
287 04ad7c7c Scott Ullrich
288 2ee8dea1 Phil Davis
		if ($_POST['language'] && $_POST['language'] != $config['system']['language']) {
289 3e139f90 Vinicius Coque
			$config['system']['language'] = $_POST['language'];
290 ceecd29b Renato Botelho
			set_language();
291 3e139f90 Vinicius Coque
		}
292
293 1d3510cf Phil Davis
		unset($config['system']['webgui']['interfacessort']);
294
		$config['system']['webgui']['interfacessort'] = $_POST['interfacessort'] ? true : false;
295
296 24f15b3a NOYB
		unset($config['system']['webgui']['webguileftcolumnhyper']);
297
		$config['system']['webgui']['webguileftcolumnhyper'] = $_POST['webguileftcolumnhyper'] ? true : false;
298
299 d9058974 Phil Davis
		unset($config['system']['webgui']['disablealiaspopupdetail']);
300
		$config['system']['webgui']['disablealiaspopupdetail'] = $_POST['disablealiaspopupdetail'] ? true : false;
301
302 c05363c8 NOYB
		unset($config['system']['webgui']['dashboardavailablewidgetspanel']);
303
		$config['system']['webgui']['dashboardavailablewidgetspanel'] = $_POST['dashboardavailablewidgetspanel'] ? true : false;
304
305
		unset($config['system']['webgui']['systemlogsfilterpanel']);
306
		$config['system']['webgui']['systemlogsfilterpanel'] = $_POST['systemlogsfilterpanel'] ? true : false;
307
308
		unset($config['system']['webgui']['systemlogsmanagelogpanel']);
309
		$config['system']['webgui']['systemlogsmanagelogpanel'] = $_POST['systemlogsmanagelogpanel'] ? true : false;
310
311 b1b8784a NOYB
		unset($config['system']['webgui']['statusmonitoringsettingspanel']);
312
		$config['system']['webgui']['statusmonitoringsettingspanel'] = $_POST['statusmonitoringsettingspanel'] ? true : false;
313
314 9ceace25 jim-p
//		if ($_POST['dashboardperiod']) {
315
//			$config['widgets']['period'] = $_POST['dashboardperiod'];
316
//		}
317
318
		if ($_POST['webguicss']) {
319
			$config['system']['webgui']['webguicss'] = $_POST['webguicss'];
320
		} else {
321
			unset($config['system']['webgui']['webguicss']);
322
		}
323
324
		$config['system']['webgui']['roworderdragging'] = $_POST['roworderdragging'] ? true:false;
325
326
		if ($_POST['logincss']) {
327
			$config['system']['webgui']['logincss'] = $_POST['logincss'];
328
		} else {
329
			unset($config['system']['webgui']['logincss']);
330
		}
331
332
		$config['system']['webgui']['loginshowhost'] = $_POST['loginshowhost'] ? true:false;
333
334
		if ($_POST['webguifixedmenu']) {
335
			$config['system']['webgui']['webguifixedmenu'] = $_POST['webguifixedmenu'];
336
		} else {
337
			unset($config['system']['webgui']['webguifixedmenu']);
338
		}
339
340
		if ($_POST['webguihostnamemenu']) {
341
			$config['system']['webgui']['webguihostnamemenu'] = $_POST['webguihostnamemenu'];
342
		} else {
343
			unset($config['system']['webgui']['webguihostnamemenu']);
344
		}
345
346
		if ($_POST['dashboardcolumns']) {
347
			$config['system']['webgui']['dashboardcolumns'] = $_POST['dashboardcolumns'];
348
		} else {
349
			unset($config['system']['webgui']['dashboardcolumns']);
350
		}
351
352
		$config['system']['webgui']['requirestatefilter'] = $_POST['requirestatefilter'] ? true : false;
353
354 4fbf63aa Bill Marquette
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
355 52acb1ff Phil Davis
		$olddnsservers = $config['system']['dnsserver'];
356 5b237745 Scott Ullrich
		unset($config['system']['dnsserver']);
357 a2d23e88 Phil Davis
358
		$dnscounter = 0;
359
		$dnsname = "dns{$dnscounter}";
360
361
		while (isset($_POST[$dnsname])) {
362
			if ($_POST[$dnsname]) {
363
				$config['system']['dnsserver'][] = $_POST[$dnsname];
364
			}
365
			$dnscounter++;
366
			$dnsname = "dns{$dnscounter}";
367 2ee8dea1 Phil Davis
		}
368 04ad7c7c Scott Ullrich
369 a2d23e88 Phil Davis
		// Remember the new list for display also.
370
		$pconfig['dnsserver'] = $config['system']['dnsserver'];
371
372 07bd3f83 Scott Ullrich
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
373 20b90e0a Scott Ullrich
374 0d8a219e Scott Ullrich
		unset($config['system']['dnsallowoverride']);
375 5b237745 Scott Ullrich
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
376 e180a6e3 Scott Ullrich
377 f0c51530 jim-p
		if ($_POST['dnslocalhost']) {
378
			$config['system']['dnslocalhost'] = $_POST['dnslocalhost'];
379 2ee8dea1 Phil Davis
		} else {
380 8ca95ed8 jim-p
			unset($config['system']['dnslocalhost']);
381 2ee8dea1 Phil Davis
		}
382 8ca95ed8 jim-p
383 e180a6e3 Scott Ullrich
		/* which interface should the dns servers resolve through? */
384 a2d23e88 Phil Davis
		$dnscounter = 0;
385
		// The $_POST array key of the DNS IP (starts from 0)
386
		$dnsname = "dns{$dnscounter}";
387 df4471e2 Phil Davis
		$outdnscounter = 0;
388 a2d23e88 Phil Davis
		while (isset($_POST[$dnsname])) {
389
			// The $_POST array key of the corresponding gateway (starts from 0)
390
			$dnsgwname = "dnsgw{$dnscounter}";
391 7e8bfed2 jim-p
			$dnshostname = "dnshost{$dnscounter}";
392
			// The numbering of DNS GW/host entries in the config starts from 1
393 a2d23e88 Phil Davis
			$dnsgwconfigcounter = $dnscounter + 1;
394 7e8bfed2 jim-p
			$dnshostconfigcounter = $dnscounter + 1;
395 a2d23e88 Phil Davis
			// So this is the array key of the DNS GW entry in $config['system']
396
			$dnsgwconfigname = "dns{$dnsgwconfigcounter}gw";
397 7e8bfed2 jim-p
			$dnshostconfigname = "dns{$dnshostconfigcounter}host";
398 a2d23e88 Phil Davis
399
			$olddnsgwname = $config['system'][$dnsgwconfigname];
400 7e8bfed2 jim-p
			$olddnshostname = $config['system'][$dnshostconfigname];
401 df4471e2 Phil Davis
402 2ee8dea1 Phil Davis
			if ($ignore_posted_dnsgw[$dnsgwname]) {
403 df4471e2 Phil Davis
				$thisdnsgwname = "none";
404 2ee8dea1 Phil Davis
			} else {
405 df4471e2 Phil Davis
				$thisdnsgwname = $pconfig[$dnsgwname];
406 2ee8dea1 Phil Davis
			}
407 7e8bfed2 jim-p
			$thisdnshostname = $pconfig[$dnshostname];
408 df4471e2 Phil Davis
409
			// "Blank" out the settings for this index, then we set them below using the "outdnscounter" index.
410 a2d23e88 Phil Davis
			$config['system'][$dnsgwconfigname] = "none";
411 df4471e2 Phil Davis
			$pconfig[$dnsgwname] = "none";
412 7e8bfed2 jim-p
			$config['system'][$dnshostconfigname] = "";
413
			$pconfig[$dnshostname] = "";
414 df4471e2 Phil Davis
			$pconfig[$dnsname] = "";
415
416
			if ($_POST[$dnsname]) {
417
				// Only the non-blank DNS servers were put into the config above.
418
				// So we similarly only add the corresponding gateways sequentially to the config (and to pconfig), as we find non-blank DNS servers.
419
				// 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.
420 a2d23e88 Phil Davis
421
				// The $pconfig array key of the DNS IP (starts from 0)
422
				$outdnsname = "dns{$outdnscounter}";
423
				// The $pconfig array key of the corresponding gateway (starts from 0)
424
				$outdnsgwname = "dnsgw{$outdnscounter}";
425 7e8bfed2 jim-p
				// The $pconfig array key of the corresponding hostname (starts from 0)
426
				$outdnshostname = "dnshost{$outdnscounter}";
427
428
				// The numbering of DNS GW/host entries in the config starts from 1
429 a2d23e88 Phil Davis
				$outdnsgwconfigcounter = $outdnscounter + 1;
430 7e8bfed2 jim-p
				$outdnshostconfigcounter = $outdnscounter + 1;
431 a2d23e88 Phil Davis
				// So this is the array key of the output DNS GW entry in $config['system']
432
				$outdnsgwconfigname = "dns{$outdnsgwconfigcounter}gw";
433 7e8bfed2 jim-p
				$outdnshostconfigname = "dns{$outdnshostconfigcounter}host";
434 a2d23e88 Phil Davis
435 df4471e2 Phil Davis
				$pconfig[$outdnsname] = $_POST[$dnsname];
436 2ee8dea1 Phil Davis
				if ($_POST[$dnsgwname]) {
437 a2d23e88 Phil Davis
					$config['system'][$outdnsgwconfigname] = $thisdnsgwname;
438 df4471e2 Phil Davis
					$pconfig[$outdnsgwname] = $thisdnsgwname;
439
				} else {
440
					// Note: when no DNS GW name is chosen, the entry is set to "none", so actually this case never happens.
441 a2d23e88 Phil Davis
					unset($config['system'][$outdnsgwconfigname]);
442 df4471e2 Phil Davis
					$pconfig[$outdnsgwname] = "";
443 0d192133 jim-p
				}
444
				if ($_POST[$dnshostname]) {
445
					$config['system'][$outdnshostconfigname] = $thisdnshostname;
446
					$pconfig[$outdnshostname] = $thisdnshostname;
447
				} else {
448
					// Note: when no DNS hostname is chosen, unset the value.
449 7e8bfed2 jim-p
					unset($config['system'][$outdnshostconfigname]);
450
					$pconfig[$outdnshostname] = "";
451 df4471e2 Phil Davis
				}
452 a2d23e88 Phil Davis
				$outdnscounter++;
453 d623f2da Seth Mos
			}
454 a2d23e88 Phil Davis
455
			$dnscounter++;
456
			// The $_POST array key of the DNS IP (starts from 0)
457
			$dnsname = "dns{$dnscounter}";
458 d623f2da Seth Mos
		}
459 04ad7c7c Scott Ullrich
460 f211d7c0 luckman212
		// clean up dnsgw orphans
461
		$oldgwcounter = 1;
462
		$olddnsgwconfigname = "dns{$oldgwcounter}gw";
463
		while (isset($config['system'][$olddnsgwconfigname])) {
464
			if (empty($config['system']['dnsserver'][$oldgwcounter - 1])) {
465
				unset($config['system'][$olddnsgwconfigname]);
466
			}
467
			$oldgwcounter++;
468
			$olddnsgwconfigname = "dns{$oldgwcounter}gw";
469
		}
470
		unset($oldgwcounter);
471
		unset($olddnsgwconfigname);
472
473 2ee8dea1 Phil Davis
		if ($changecount > 0) {
474 62d01225 Bill Marquette
			write_config($changedesc);
475 2ee8dea1 Phil Davis
		}
476 04ad7c7c Scott Ullrich
477 44c42356 Phil Davis
		$changes_applied = true;
478 5b237745 Scott Ullrich
		$retval = 0;
479 44c42356 Phil Davis
		$retval |= system_hostname_configure();
480 3cfdba5f Scott Ullrich
		$retval |= system_hosts_generate();
481
		$retval |= system_resolvconf_generate();
482 2ee8dea1 Phil Davis
		if (isset($config['dnsmasq']['enable'])) {
483 1e2c8821 Warren Baker
			$retval |= services_dnsmasq_configure();
484 2ee8dea1 Phil Davis
		} elseif (isset($config['unbound']['enable'])) {
485 1e2c8821 Warren Baker
			$retval |= services_unbound_configure();
486 2ee8dea1 Phil Davis
		}
487 3cfdba5f Scott Ullrich
		$retval |= system_timezone_configure();
488
		$retval |= system_ntp_configure();
489
490 2ee8dea1 Phil Davis
		if ($olddnsallowoverride != $config['system']['dnsallowoverride']) {
491 b8292903 Ermal
			$retval |= send_event("service reload dns");
492 2ee8dea1 Phil Davis
		}
493 3cfdba5f Scott Ullrich
494 e7d967d8 Scott Ullrich
		// Reload the filter - plugins might need to be run.
495 0027de0a Ermal Lu?i
		$retval |= filter_configure();
496 5b237745 Scott Ullrich
	}
497 df4471e2 Phil Davis
498
	unset($ignore_posted_dnsgw);
499 5b237745 Scott Ullrich
}
500 4df96eff Scott Ullrich
501 2ee8dea1 Phil Davis
$pgtitle = array(gettext("System"), gettext("General Setup"));
502 4df96eff Scott Ullrich
include("head.inc");
503
504 8f65151c Phil Davis
if ($input_errors) {
505 41ea4cf3 Sjon Hortensius
	print_input_errors($input_errors);
506 8f65151c Phil Davis
}
507 ddb84143 Stephen Beaver
508 44c42356 Phil Davis
if ($changes_applied) {
509
	print_apply_result_box($retval);
510 8f65151c Phil Davis
}
511 5b237745 Scott Ullrich
?>
512 41ea4cf3 Sjon Hortensius
<div id="container">
513 b40bcb23 Sjon Hortensius
<?php
514 1180e4f0 Sjon Hortensius
515 b40bcb23 Sjon Hortensius
$form = new Form;
516 a32c0623 Sjon Hortensius
$section = new Form_Section('System');
517
$section->addInput(new Form_Input(
518 a97531c5 Sjon Hortensius
	'hostname',
519 153c3aa6 Phil Davis
	'*Hostname',
520 a32c0623 Sjon Hortensius
	'text',
521
	$pconfig['hostname'],
522
	['placeholder' => 'pfSense']
523
))->setHelp('Name of the firewall host, without domain part');
524 512f2c10 Stephen Beaver
525 a32c0623 Sjon Hortensius
$section->addInput(new Form_Input(
526 a97531c5 Sjon Hortensius
	'domain',
527 153c3aa6 Phil Davis
	'*Domain',
528 a32c0623 Sjon Hortensius
	'text',
529
	$pconfig['domain'],
530 41e0d95f jim-p
	['placeholder' => 'example.com, home, office, private, etc.']
531
))->setHelp('Do not end the domain name with \'.local\' as the final part (Top Level Domain, TLD), ' .
532
	'The \'local\' TLD is %1$swidely used%2$s by mDNS (e.g. Avahi, Bonjour, Rendezvous, Airprint, Airplay) ' .
533
	'and some Windows systems and networked devices. ' .
534
	'These will not network correctly if the router uses \'local\' as its TLD. ' .
535
	'Alternative TLDs such as \'local.lan\' or \'mylocal\' are safe.',
536
	'<a target="_blank" href="https://www.unbound.net/pipermail/unbound-users/2011-March/001735.html">',
537
	'</a>'
538 ef77e40e stilez
);
539 512f2c10 Stephen Beaver
540 b40bcb23 Sjon Hortensius
$form->add($section);
541
542 70dc5cd6 Phil Davis
$section = new Form_Section('DNS Server Settings');
543 b40bcb23 Sjon Hortensius
544 a2d23e88 Phil Davis
if (!is_array($pconfig['dnsserver'])) {
545
	$pconfig['dnsserver'] = array();
546
}
547
548
$dnsserver_count = count($pconfig['dnsserver']);
549
$dnsserver_num = 0;
550
$dnsserver_help = gettext("Address") . '<br/>' . gettext("Enter IP addresses to be used by the system for DNS resolution.") . " " .
551
	gettext("These are also used for the DHCP service, DNS Forwarder and DNS Resolver when it has DNS Query Forwarding enabled.");
552 7e8bfed2 jim-p
$dnshost_help = gettext("Hostname") . '<br/>' . gettext("Enter the DNS Server Hostname for TLS Verification in the DNS Resolver (optional).");
553 a2d23e88 Phil Davis
$dnsgw_help = gettext("Gateway") . '<br/>'. gettext("Optionally select the gateway for each DNS server.") . " " .
554
	gettext("When using multiple WAN connections there should be at least one unique DNS server per gateway.");
555
556
// If there are no DNS servers, make an empty entry for initial display.
557
if ($dnsserver_count == 0) {
558
	$pconfig['dnsserver'][] = '';
559
}
560
561
foreach ($pconfig['dnsserver'] as $dnsserver) {
562 54c605d4 Stephen Beaver
563 05025e63 Steve Beaver
	$is_last_dnsserver = (($dnsserver_num == $dnsserver_count - 1) || $dnsserver_count == 0);
564 a2d23e88 Phil Davis
	$group = new Form_Group($dnsserver_num == 0 ? 'DNS Servers':'');
565
	$group->addClass('repeatable');
566 54c605d4 Stephen Beaver
567
	$group->add(new Form_Input(
568 a2d23e88 Phil Davis
		'dns' . $dnsserver_num,
569 54c605d4 Stephen Beaver
		'DNS Server',
570
		'text',
571 a2d23e88 Phil Davis
		$dnsserver
572
	))->setHelp(($is_last_dnsserver) ? $dnsserver_help:null);
573 b40bcb23 Sjon Hortensius
574 7e8bfed2 jim-p
	$group->add(new Form_Input(
575
		'dnshost' . $dnsserver_num,
576
		'DNS Hostname',
577
		'text',
578
		$pconfig['dnshost' . $dnsserver_num]
579
	))->setHelp(($is_last_dnsserver) ? $dnshost_help:null);
580
581 47e079f6 Viktor G
	if (($multiwan > 1) || ($multiwan6 > 1)) {
582 b40bcb23 Sjon Hortensius
		$options = array('none' => 'none');
583
584 8f65151c Phil Davis
		foreach ($arr_gateways as $gwname => $gwitem) {
585
			if ((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
586 b40bcb23 Sjon Hortensius
				continue;
587
			}
588 54c605d4 Stephen Beaver
589 8f65151c Phil Davis
			if ((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
590 b40bcb23 Sjon Hortensius
				continue;
591
			}
592 1180e4f0 Sjon Hortensius
593 b40bcb23 Sjon Hortensius
			$options[$gwname] = $gwname.' - '.$gwitem['friendlyiface'].' - '.$gwitem['gateway'];
594
		}
595 1180e4f0 Sjon Hortensius
596 a97531c5 Sjon Hortensius
		$group->add(new Form_Select(
597 a2d23e88 Phil Davis
			'dnsgw' . $dnsserver_num,
598 e4dd8be4 NOYB
			'Gateway',
599 a2d23e88 Phil Davis
			$pconfig['dnsgw' . $dnsserver_num],
600 a97531c5 Sjon Hortensius
			$options
601 f211d7c0 luckman212
		))->setWidth(4)->setHelp(($is_last_dnsserver) ? $dnsgw_help:null);
602 b40bcb23 Sjon Hortensius
	}
603 1180e4f0 Sjon Hortensius
604 a2d23e88 Phil Davis
	$group->add(new Form_Button(
605
		'deleterow' . $dnsserver_num,
606
		'Delete',
607
		null,
608
		'fa-trash'
609 f211d7c0 luckman212
	))->setWidth(2)->addClass('btn-warning');
610 54c605d4 Stephen Beaver
611 b40bcb23 Sjon Hortensius
	$section->add($group);
612 a2d23e88 Phil Davis
	$dnsserver_num++;
613 b40bcb23 Sjon Hortensius
}
614 1180e4f0 Sjon Hortensius
615 a2d23e88 Phil Davis
$section->addInput(new Form_Button(
616
	'addrow',
617
	'Add DNS Server',
618
	null,
619
	'fa-plus'
620
))->addClass('btn-success addbtn');
621
622 a005a836 Sjon Hortensius
$section->addInput(new Form_Checkbox(
623 a97531c5 Sjon Hortensius
	'dnsallowoverride',
624 70dc5cd6 Phil Davis
	'DNS Server Override',
625 349e7c67 Viktor G
	'Allow DNS server list to be overridden by DHCP/PPP on WAN or remote OpenVPN server',
626 b40bcb23 Sjon Hortensius
	$pconfig['dnsallowoverride']
627 314a088a Phil Davis
))->setHelp('If this option is set, %s will use DNS servers '.
628 349e7c67 Viktor G
	'assigned by a DHCP/PPP server on WAN or a remote OpenVPN server (if Pull DNS ' .
629
	'option is enabled) for its own purposes (including the DNS Forwarder/DNS Resolver). '.
630
        'However, they will not be assigned to DHCP clients.', $g['product_label']);
631 b40bcb23 Sjon Hortensius
632 f0c51530 jim-p
$section->addInput(new Form_Select(
633 a97531c5 Sjon Hortensius
	'dnslocalhost',
634 f0c51530 jim-p
	'DNS Resolution Behavior',
635
	$pconfig['dnslocalhost'],
636
	array(
637
		''       => 'Use local DNS (127.0.0.1), fall back to remote DNS Servers (Default)',
638
		'local'  => 'Use local DNS (127.0.0.1), ignore remote DNS Servers',
639
		'remote' => 'Use remote DNS Servers, ignore local DNS',
640
	)
641
))->setHelp('By default the firewall will use local DNS service (127.0.0.1, DNS '.
642
	'Resolver or Forwarder) as the first DNS server when possible, and it '.
643
	'will fall back to remote DNS servers otherwise. Use this option to '.
644
	'choose alternate behaviors.');
645 b40bcb23 Sjon Hortensius
646
$form->add($section);
647
648 a005a836 Sjon Hortensius
$section = new Form_Section('Localization');
649 512f2c10 Stephen Beaver
650 a005a836 Sjon Hortensius
$section->addInput(new Form_Select(
651 a97531c5 Sjon Hortensius
	'timezone',
652 153c3aa6 Phil Davis
	'*Timezone',
653 a32c0623 Sjon Hortensius
	$pconfig['timezone'],
654 e5f4c829 Renato Botelho
	array_combine($timezonelist, $timezonedesc)
655 781d9ce4 Phil Davis
))->setHelp('Select a geographic region name (Continent/Location) to determine the timezone for the firewall. %1$s' .
656
	'Choose a special or "Etc" zone only in cases where the geographic zones do not properly handle the clock offset required for this firewall.', '<br/>');
657 512f2c10 Stephen Beaver
658 a005a836 Sjon Hortensius
$section->addInput(new Form_Input(
659 a97531c5 Sjon Hortensius
	'timeservers',
660 a32c0623 Sjon Hortensius
	'Timeservers',
661
	'text',
662
	$pconfig['timeservers']
663
))->setHelp('Use a space to separate multiple hosts (only one required). '.
664 1bab4a10 NOYB
	'Remember to set up at least one DNS server if a host name is entered here!');
665 512f2c10 Stephen Beaver
666 a005a836 Sjon Hortensius
$section->addInput(new Form_Select(
667 a97531c5 Sjon Hortensius
	'language',
668 153c3aa6 Phil Davis
	'*Language',
669 a32c0623 Sjon Hortensius
	$pconfig['language'],
670
	get_locale_list()
671
))->setHelp('Choose a language for the webConfigurator');
672 b40bcb23 Sjon Hortensius
673
$form->add($section);
674
675 1176360c k-paulius
$section = new Form_Section('webConfigurator');
676 a5995a8e Stephen Beaver
677 8bab524e Phil Davis
gen_webguicss_field($section, $pconfig['webguicss']);
678
gen_webguifixedmenu_field($section, $pconfig['webguifixedmenu']);
679
gen_webguihostnamemenu_field($section, $pconfig['webguihostnamemenu']);
680
gen_dashboardcolumns_field($section, $pconfig['dashboardcolumns']);
681 1d3510cf Phil Davis
gen_interfacessort_field($section, $pconfig['interfacessort']);
682 8bab524e Phil Davis
gen_associatedpanels_fields(
683
	$section,
684
	$pconfig['dashboardavailablewidgetspanel'],
685
	$pconfig['systemlogsfilterpanel'],
686
	$pconfig['systemlogsmanagelogpanel'],
687
	$pconfig['statusmonitoringsettingspanel']);
688 88081ea2 derelict-pf
gen_requirestatefilter_field($section, $pconfig['requirestatefilter']);
689 8bab524e Phil Davis
gen_webguileftcolumnhyper_field($section, $pconfig['webguileftcolumnhyper']);
690 d9058974 Phil Davis
gen_disablealiaspopupdetail_field($section, $pconfig['disablealiaspopupdetail']);
691 24f15b3a NOYB
692 52e91f70 PiBa-NL
$section->addInput(new Form_Checkbox(
693
	'roworderdragging',
694
	'Disable dragging',
695 86212d70 luckman212
	'Disable dragging of firewall/NAT rules',
696 52e91f70 PiBa-NL
	$pconfig['roworderdragging']
697
))->setHelp('Disables dragging rows to allow selecting and copying row contents and avoid accidental changes.');
698
699 e79ff1ee Steve Beaver
$section->addInput(new Form_Select(
700
	'logincss',
701 d58a7378 Steve Beaver
	'Login page color',
702 e79ff1ee Steve Beaver
	$pconfig['logincss'],
703 1fe82d1d Administrator
	["1e3f75;" => gettext("Dark Blue"), "003300" => gettext("Dark green"), "770101" => gettext("Crimson red"),
704 626aefbe Steve Beaver
	 "4b1263" => gettext("Purple"), "424142" => gettext("Gray"), "333333" => gettext("Dark gray"),
705 1fe82d1d Administrator
	 "000000" => gettext("Black"), "633215" => gettext("Dark brown"), "bf7703" => gettext("Brown"), 
706
	 "008000" => gettext("Green"), "007faa" => gettext("Light Blue"), "dc2a2a" => gettext("Red"),
707
	 "9b59b6" => gettext("Violet")]
708 d58a7378 Steve Beaver
))->setHelp('Choose a color for the login page');
709 e79ff1ee Steve Beaver
710 a22947a4 Steve Beaver
$section->addInput(new Form_Checkbox(
711
	'loginshowhost',
712
	'Login hostname',
713
	'Show hostname on login banner',
714
	$pconfig['loginshowhost']
715
));
716 6c1f2a1c Steve Beaver
/*
717 512f2c10 Stephen Beaver
$section->addInput(new Form_Input(
718
	'dashboardperiod',
719
	'Dashboard update period',
720
	'number',
721
	$pconfig['dashboardperiod'],
722 134ee13d Stephen Beaver
	['min' => '5', 'max' => '600']
723 512f2c10 Stephen Beaver
))->setHelp('Time in seconds between dashboard widget updates. Small values cause ' .
724
			'more frequent updates but increase the load on the web server. ' .
725
			'Minimum is 5 seconds, maximum 600 seconds');
726 6c1f2a1c Steve Beaver
*/
727 a5995a8e Stephen Beaver
$form->add($section);
728
729 b40bcb23 Sjon Hortensius
print $form;
730 7bb301eb Stephen Beaver
731
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
732
733 8c4ef875 NOYB
?>
734
</div>
735 7bb301eb Stephen Beaver
736 46345696 Colin Fleming
<script type="text/javascript">
737 7bb301eb Stephen Beaver
//<![CDATA[
738
events.push(function() {
739
740
	function setThemeWarning() {
741
		if ($('#webguicss').val().startsWith("pfSense")) {
742
			$('#csstxt').html("").addClass("text-default");
743
		} else {
744
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
745
		}
746
	}
747
748
	$('#webguicss').change(function() {
749
		setThemeWarning();
750
	});
751
752
	setThemeWarning();
753 a2d23e88 Phil Davis
754
	// Suppress "Delete row" button if there are fewer than two rows
755
	checkLastRow();
756 7bb301eb Stephen Beaver
});
757
//]]>
758
</script>
759
760 8c4ef875 NOYB
<?php
761 60ff91f1 Renato Botelho
include("foot.inc");
762 8c4ef875 NOYB
?>