Project

General

Profile

Download (17.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
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

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

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

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

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

    
52
$arr_gateways = return_gateways_array();
53

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

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

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

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

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

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

    
82
if($pconfig['timezone'] <> $_POST['timezone']) {
83
	filter_pflog_start(true);
84
}
85

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

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

    
98
if ($_POST) {
99

    
100
	$changecount++;
101
	
102
	unset($input_errors);
103
	$pconfig = $_POST;
104

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

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

    
111
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
112
		$input_errors[] = gettext("The hostname may only contain the characters a-z, 0-9 and '-'.");
113
	}
114
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
115
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
116
	}
117

    
118
	for ($dnscounter=1; $dnscounter<5; $dnscounter++){
119
		$dnsname="dns{$dnscounter}";
120
		$dnsgwname="dns{$dnscounter}gw";
121
		if (($_POST[$dnsname] && !is_ipaddr($_POST[$dnsname]))) {
122
			$input_errors[] = gettext("A valid IP address must be specified for the DNS server $dnscounter.");
123
		}
124
		if(($_POST[$dnsgwname] <> "") && (is_ipaddr($_POST[$dnsname]))) {
125
			if (($_POST[$dnsgwname] <> "none") && (is_ipaddrv4($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false )) {
126
				$input_errors[] = gettext("You can not specify a IPv6 gateway '{$_POST[$dnsgwname]}'for a IPv4 DNS server '{$_POST[$dnsname]}'");
127
			}
128
			if (($_POST[$dnsgwname] <> "none") && (is_ipaddrv6($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false )) {
129
				$input_errors[] = gettext("You can not specify a IPv4 gateway '{$_POST[$dnsgwname]}'for a IPv6 DNS server '{$_POST[$dnsname]}'");
130
			}
131
		}
132
	}
133

    
134
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
135
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
136
		$input_errors[] = gettext("A valid TCP/IP port must be specified for the webConfigurator port.");
137
	}
138

    
139
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
140
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
141
		$dnsitem = "dns{$dnscounter}";
142
		$dnsgwitem = "dns{$dnscounter}gw";
143
		if ($_POST[$dnsgwitem]) {
144
			if(interface_has_gateway($_POST[$dnsgwitem])) {
145
				foreach($direct_networks_list as $direct_network) {
146
					if(ip_in_subnet($_POST[$dnsitem], $direct_network)) {
147
						$input_errors[] = sprintf(gettext("You can not assign a gateway to DNS '%s' server which is on a directly connected network."),$_POST[$dnsitem]);
148
					}
149
				}
150
			}
151
		}
152
	}
153

    
154
	$t = (int)$_POST['timeupdateinterval'];
155
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
156
		$input_errors[] = gettext("The time update interval must be either 0 (disabled) or between 6 and 1440.");
157
	}
158
	# it's easy to have a little too much whitespace in the field, clean it up for the user before processing.
159
	$_POST['timeservers'] = preg_replace('/[[:blank:]]+/', ' ', $_POST['timeservers']);
160
	$_POST['timeservers'] = trim($_POST['timeservers']);
161
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
162
		if (!is_domain($ts)) {
163
			$input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.");
164
		}
165
	}
166

    
167
	if (!$input_errors) {
168
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
169
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
170

    
171
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
172
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
173
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
174

    
175
		if($_POST['language'] && $_POST['language'] != $config['system']['language']) {
176
			$config['system']['language'] = $_POST['language'];
177
			set_language($config['system']['language']);
178
		}
179

    
180
		/* pfSense themes */
181
		if (! $g['disablethemeselection']) {
182
			update_if_changed("System Theme", $config['theme'], $_POST['theme']);	
183
		}
184

    
185
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
186
		unset($config['system']['dnsserver']);
187
		if ($_POST['dns1'])
188
			$config['system']['dnsserver'][] = $_POST['dns1'];
189
		if ($_POST['dns2'])
190
			$config['system']['dnsserver'][] = $_POST['dns2'];
191
		if ($_POST['dns3'])
192
			$config['system']['dnsserver'][] = $_POST['dns3'];
193
		if ($_POST['dns4'])
194
			$config['system']['dnsserver'][] = $_POST['dns4'];
195

    
196
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
197

    
198
		unset($config['system']['dnsallowoverride']);
199
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
200

    
201
		if($_POST['dnslocalhost'] == "yes")
202
			$config['system']['dnslocalhost'] = true;
203
		else
204
			unset($config['system']['dnslocalhost']);
205

    
206
		/* which interface should the dns servers resolve through? */
207
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
208
			$dnsname="dns{$dnscounter}";
209
			$dnsgwname="dns{$dnscounter}gw";
210
			if($_POST[$dnsgwname]) {
211
				$config['system'][$dnsgwname] = $pconfig[$dnsgwname];
212
			} else {
213
				unset($config['system'][$dnsgwname]);
214
			}
215
		}
216

    
217
		if ($changecount > 0)
218
			write_config($changedesc);
219

    
220
		$retval = 0;
221
		$retval = system_hostname_configure();
222
		$retval |= system_hosts_generate();
223
		$retval |= system_resolvconf_generate();
224
		$retval |= services_dnsmasq_configure();
225
		$retval |= system_timezone_configure();
226
		$retval |= system_ntp_configure();
227

    
228
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
229
			$retval |= send_event("service reload dns");
230

    
231
		// Reload the filter - plugins might need to be run.
232
		$retval |= filter_configure();
233
		
234
		$savemsg = get_std_save_message($retval);
235
	}
236
}
237

    
238
$pgtitle = array(gettext("System"),gettext("General Setup"));
239
include("head.inc");
240

    
241
?>
242

    
243
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
244
<?php
245
	include("fbegin.inc");
246
	if ($input_errors)
247
		print_input_errors($input_errors);
248
	if ($savemsg)
249
		print_info_box($savemsg);
250
?>
251
	<form action="system.php" method="post">
252
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="general setup">
253
                        <tr>
254
                                <td id="mainarea">
255
                                        <div class="tabcont">
256
			<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
257
			<tr>
258
				<td colspan="2" valign="top" class="listtopic"><?=gettext("System"); ?></td>
259
			</tr>
260
			<tr>
261
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname"); ?></td>
262
				<td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld unknown" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>" />
263
					<br/>
264
					<span class="vexpl">
265
						<?=gettext("Name of the firewall host, without domain part"); ?>
266
						<br/>
267
						<?=gettext("e.g."); ?> <em>firewall</em>
268
					</span>
269
				</td>
270
			</tr>
271
			<tr>
272
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Domain"); ?></td>
273
				<td width="78%" class="vtable"> <input name="domain" type="text" class="formfld unknown" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>" />
274
					<br/>
275
					<span class="vexpl">
276
						<?=gettext("Do not use 'local' as a domain name. It will cause local hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve local hosts not running mDNS."); ?>
277
						<br/>
278
						<?=gettext("e.g."); ?> <em><?=gettext("mycorp.com, home, office, private, etc."); ?></em>
279
					</span>
280
				</td>
281
			</tr>
282
			<tr>
283
				<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers"); ?></td>
284
				<td width="78%" class="vtable">
285
						<br/>
286
						<table summary="dns servers and gateways">
287
							<tr>
288
								<td><b><?=gettext("DNS Server"); ?></b></td>
289
								<?php if ($multiwan): ?>
290
								<td><b><?=gettext("Use gateway"); ?></b></td>
291
								<?php endif; ?>
292
							</tr>
293
							<?php
294
								for ($dnscounter=1; $dnscounter<5; $dnscounter++):
295
									$fldname="dns{$dnscounter}gw";
296
							?>
297
							<tr>
298
								<td>
299
									<input name="dns<?php echo $dnscounter;?>" type="text" class="formfld unknown" id="dns<?php echo $dnscounter;?>" size="28" value="<?php echo $pconfig['dns'.$dnscounter];?>" />
300
								</td>
301
								<td>
302
<?php if ($multiwan): ?>
303
									<select name='<?=$fldname;?>'>
304
										<?php
305
											$gwname = "none";
306
											$dnsgw = "dns{$dnscounter}gw";
307
											if($pconfig[$dnsgw] == $gwname) {
308
												$selected = "selected=\"selected\"";
309
											} else {
310
												$selected = "";
311
											}
312
											echo "<option value='$gwname' $selected>$gwname</option>\n";
313
											foreach($arr_gateways as $gwname => $gwitem) {
314
												//echo $pconfig[$dnsgw];
315
												if((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
316
													continue;
317
												}
318
												if((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
319
													continue;
320
												}
321
												if($pconfig[$dnsgw] == $gwname) {
322
													$selected = "selected=\"selected\"";
323
												} else {
324
													$selected = "";
325
												}
326
												echo "<option value='$gwname' $selected>$gwname - {$gwitem['friendlyiface']} - {$gwitem['gateway']}</option>\n";
327
											}
328
										?>
329
									</select>
330
<?php endif; ?>
331
								</td>
332
							</tr>
333
							<?php endfor; ?>
334
						</table>
335
						<br />
336
						<span class="vexpl">
337
							<?=gettext("Enter IP addresses to be used by the system for DNS resolution. " .
338
							"These are also used for the DHCP service, DNS forwarder and for PPTP VPN clients."); ?>
339
							<br/>
340
							<?php if($multiwan): ?>
341
							<br/>
342
							<?=gettext("In addition, optionally select the gateway for each DNS server. " .
343
							"When using multiple WAN connections there should be at least one unique DNS server per gateway."); ?>
344
							<br/>
345
							<?php endif; ?>
346
							<br/>
347
							<input name="dnsallowoverride" type="checkbox" id="dnsallowoverride" value="yes" <?php if ($pconfig['dnsallowoverride']) echo "checked=\"checked\""; ?> />
348
							<strong>
349
								<?=gettext("Allow DNS server list to be overridden by DHCP/PPP on WAN"); ?>
350
							</strong>
351
							<br/>
352
							<?php printf(gettext("If this option is set, %s will " .
353
							"use DNS servers assigned by a DHCP/PPP server on WAN " .
354
							"for its own purposes (including the DNS forwarder). " .
355
							"However, they will not be assigned to DHCP and PPTP " .
356
							"VPN clients."), $g['product_name']); ?>
357
							<br />
358
							<br />
359
							<input name="dnslocalhost" type="checkbox" id="dnslocalhost" value="yes" <?php if ($pconfig['dnslocalhost']) echo "checked=\"checked\""; ?> />
360
							<strong>
361
								<?=gettext("Do not use the DNS Forwarder as a DNS server for the firewall"); ?>
362
							</strong>
363
							<br />
364
							<?=gettext("By default localhost (127.0.0.1) will be used as the first DNS server where the DNS forwarder is enabled, so system can use the DNS forwarder to perform lookups. ".
365
							"Checking this box omits localhost from the list of DNS servers."); ?>
366
						</span>
367
				</td>
368
			</tr>
369
			<tr>
370
				<td width="22%" valign="top" class="vncell"><?=gettext("Time zone"); ?></td>
371
				<td width="78%" class="vtable">
372
					<select name="timezone" id="timezone">
373
						<?php foreach ($timezonelist as $value): ?>
374
						<?php if(strstr($value, "GMT")) continue; ?>
375
						<option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected=\"selected\""; ?>>
376
							<?=htmlspecialchars($value);?>
377
						</option>
378
						<?php endforeach; ?>
379
					</select>
380
					<br/>
381
					<span class="vexpl">
382
						<?=gettext("Select the location closest to you"); ?>
383
					</span>
384
				</td>
385
			</tr>
386
<!--
387
			<tr>
388
				<td width="22%" valign="top" class="vncell">Time update interval</td>
389
				<td width="78%" class="vtable">
390
					<input name="timeupdateinterval" type="text" class="formfld unknown" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>" />
391
					<br/>
392
					<span class="vexpl">
393
						Minutes between network time sync. 300 recommended,
394
						or 0 to disable
395
					</span>
396
				</td>
397
			</tr>
398
-->
399
			<tr>
400
				<td width="22%" valign="top" class="vncell"><?=gettext("NTP time server"); ?></td>
401
				<td width="78%" class="vtable">
402
					<input name="timeservers" type="text" class="formfld unknown" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>" />
403
					<br/>
404
					<span class="vexpl">
405
						<?=gettext("Use a space to separate multiple hosts (only one " .
406
						"required). Remember to set up at least one DNS server " .
407
						"if you enter a host name here!"); ?>
408
					</span>
409
				</td>
410
			</tr>
411
			<tr>
412
				<td width="22%" valign="top" class="vncell"><?php echo gettext("Language");?></td>
413
				<td width="78%" class="vtable">
414
					<select name="language">
415
						<?php
416
						foreach(get_locale_list() as $lcode => $ldesc) {
417
							$selected = ' selected="selected"';
418
							if($lcode != $pconfig['language'])
419
								$selected = '';
420
							echo "<option value=\"{$lcode}\"{$selected}>{$ldesc}</option>";
421
						}
422
						?>
423
					</select>
424
					<strong>
425
						<?=gettext("Choose a language for the webConfigurator"); ?>
426
					</strong>
427
				</td>
428
			</tr>
429
			<tr>
430
				<td colspan="2" class="list" height="12">&nbsp;</td>
431
			</tr>
432
			<?php if (! $g['disablethemeselection']): ?>
433
			<tr>
434
				<td colspan="2" valign="top" class="listtopic"><?=gettext("Theme"); ?></td>
435
			</tr>
436
			<tr>
437
				<td width="22%" valign="top" class="vncell">&nbsp;</td>
438
				<td width="78%" class="vtable">
439
					<select name="theme">
440
						<?php
441
							$files = return_dir_as_array("/usr/local/www/themes/");
442
							foreach($files as $f):
443
								if ((substr($f, 0, 1) == "_") && !isset($config['system']['developer']))
444
									continue;
445
								if ($f == "CVS")
446
									continue;
447
								$curtheme = "pfsense";
448
								if ($config['theme'])
449
									$curtheme = $config['theme'];
450
								$selected = "";
451
								if($f == $curtheme)
452
									$selected = " selected=\"selected\"";
453
						?>
454
						<option <?=$selected;?>><?=$f;?></option>
455
						<?php endforeach; ?>
456
					</select>
457
					<strong>
458
						<?=gettext("This will change the look and feel of"); ?>
459
						<?=$g['product_name'];?>.
460
					</strong>
461
				</td>
462
			</tr>
463
			<?php endif; ?>
464
			<tr>
465
				<td colspan="2" class="list" height="12">&nbsp;</td>
466
			</tr>			
467
			<tr>
468
				<td width="22%" valign="top">&nbsp;</td>
469
				<td width="78%">
470
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
471
				</td>
472
			</tr>
473
		</table>
474
		</div>
475
		</td></tr>
476
		</table>
477
	</form>
478
<?php include("fend.inc"); ?>
479
</body>
480
</html>
(198-198/249)