Project

General

Profile

Download (17.3 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
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
159
		if (!is_domain($ts)) {
160
			$input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.");
161
		}
162
	}
163

    
164
	if (!$input_errors) {
165
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
166
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
167

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

    
172
		if($_POST['language'] && $_POST['language'] != $config['system']['language']) {
173
			$config['system']['language'] = $_POST['language'];
174
			set_language($config['system']['language']);
175
		}
176

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

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

    
193
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
194

    
195
		unset($config['system']['dnsallowoverride']);
196
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
197

    
198
		if($_POST['dnslocalhost'] == "yes")
199
			$config['system']['dnslocalhost'] = true;
200
		else
201
			unset($config['system']['dnslocalhost']);
202

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

    
214
		if ($changecount > 0)
215
			write_config($changedesc);
216

    
217
		$retval = 0;
218
		$retval = system_hostname_configure();
219
		$retval |= system_hosts_generate();
220
		$retval |= system_resolvconf_generate();
221
		$retval |= services_dnsmasq_configure();
222
		$retval |= system_timezone_configure();
223
		$retval |= system_ntp_configure();
224

    
225
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
226
			$retval |= send_event("service reload dns");
227

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

    
235
$pgtitle = array(gettext("System"),gettext("General Setup"));
236
include("head.inc");
237

    
238
?>
239

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