Project

General

Profile

Download (17 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
	/* restart firewall log dumper helper */
84
	require_once("functions.inc");
85
	$pid = `ps awwwux | grep -v "grep" | grep "tcpdump -v -l -n -e -ttt -i pflog0"  | awk '{ print $2 }'`;
86
	if($pid) {
87
		mwexec("/bin/kill $pid");
88
		usleep(1000);
89
	}		
90
	filter_pflog_start();
91
}
92

    
93
exec('/usr/bin/tar -tzf /usr/share/zoneinfo.tgz', $timezonelist);
94
$timezonelist = array_filter($timezonelist, 'is_timezone');
95
sort($timezonelist);
96

    
97
$multiwan = false;
98
$interfaces = get_configured_interface_list();
99
foreach($interfaces as $interface) {
100
	if(interface_has_gateway($interface)) {
101
		$multiwan = true;
102
	}
103
}
104

    
105
if ($_POST) {
106

    
107
	$changecount++;
108
	
109
	unset($input_errors);
110
	$pconfig = $_POST;
111

    
112
	/* input validation */
113
	$reqdfields = explode(" ", "hostname domain");
114
	$reqdfieldsn = array(gettext("Hostname"),gettext("Domain"));
115

    
116
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
117

    
118
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
119
		$input_errors[] = gettext("The hostname may only contain the characters a-z, 0-9 and '-'.");
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
	for ($dnscounter=1; $dnscounter<5; $dnscounter++){
126
		$dnsname="dns{$dnscounter}";
127
		$dnsgwname="dns{$dnscounter}gw";
128
		if (($_POST[$dnsname] && !is_ipaddr($_POST[$dnsname]))) {
129
			$input_errors[] = gettext("A valid IP address must be specified for the DNS server $dnscounter.");
130
		}
131
		if (($_POST[$dnsgwname] <> "none") && (validate_address_family($_POST[$dnsname], lookup_gateway_ip_by_name($_POST[$dnsgwname])) === false )) {
132
			$input_errors[] = gettext("The gateway specified for DNS server '{$_POST[$dnsname]}' is not from the same Address Family as gateway '". lookup_gateway_ip_by_name($_POST[$dnsgwname]) ."'.");
133
		}
134
	}
135

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

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

    
156
	$t = (int)$_POST['timeupdateinterval'];
157
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
158
		$input_errors[] = gettext("The time update interval must be either 0 (disabled) or between 6 and 1440.");
159
	}
160
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
161
		if (!is_domain($ts)) {
162
			$input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.");
163
		}
164
	}
165

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
240
?>
241

    
242
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
243
<?php
244
	include("fbegin.inc");
245
	if ($input_errors)
246
		print_input_errors($input_errors);
247
	if ($savemsg)
248
		print_info_box($savemsg);
249
?>
250
	<form action="system.php" method="post">
251
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
252
                        <tr>
253
                                <td id="mainarea">
254
                                        <div class="tabcont">
255
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
256
			<tr>
257
				<td colspan="2" valign="top" class="listtopic"><?=gettext("System"); ?></td>
258
			</tr>
259
			<tr>
260
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname"); ?></td>
261
				<td width="78%" class="vtable"> <input name="hostname" type="text" class="formfld unknown" id="hostname" size="40" value="<?=htmlspecialchars($pconfig['hostname']);?>">
262
					<br/>
263
					<span class="vexpl">
264
						<?=gettext("Name of the firewall host, without domain part"); ?>
265
						<br/>
266
						<?=gettext("e.g."); ?> <em>firewall</em>
267
					</span>
268
				</td>
269
			</tr>
270
			<tr>
271
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Domain"); ?></td>
272
				<td width="78%" class="vtable"> <input name="domain" type="text" class="formfld unknown" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>">
273
					<br/>
274
					<span class="vexpl">
275
						<?=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."); ?>
276
						<br/>
277
						<?=gettext("e.g."); ?> <em><?=gettext("mycorp.com, home, office, private, etc."); ?></em>
278
					</span>
279
				</td>
280
			</tr>
281
			<tr>
282
				<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers"); ?></td>
283
				<td width="78%" class="vtable">
284
					<p>
285
						<table>
286
							<tr>
287
								<td><b><?=gettext("DNS Server"); ?></b></td>
288
								<?php if ($multiwan): ?>
289
								<td><b><?=gettext("Use gateway"); ?></b></td>
290
								<?php endif; ?>
291
							</tr>
292
							<?php
293
								for ($dnscounter=1; $dnscounter<5; $dnscounter++):
294
									$fldname="dns{$dnscounter}gw";
295
							?>
296
							<tr>
297
								<td>
298
									<input name="dns<?php echo $dnscounter;?>" type="text" class="formfld unknown" id="dns<?php echo $dnscounter;?>" size="28" value="<?php echo $pconfig['dns'.$dnscounter];?>">
299
								</td>
300
								<td>
301
<?php if ($multiwan): ?>
302
									<select name='<?=$fldname;?>'>
303
										<?php
304
											$gwname = "none";
305
											$dnsgw = "dns{$dnscounter}gw";
306
											if($pconfig[$dnsgw] == $gwname) {
307
												$selected = "selected";
308
											} else {
309
												$selected = "";
310
											}
311
											echo "<option value='$gwname' $selected>$gwname</option>\n";
312
											foreach($arr_gateways as $gwname => $gwitem) {
313
												echo $pconfig[$dnsgw];
314
												if((is_ipaddrv4(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv6($gwitem['gateway'])))) {
315
													continue;
316
												}
317
												if((is_ipaddrv6(lookup_gateway_ip_by_name($pconfig[$dnsgw])) && (is_ipaddrv4($gwitem['gateway'])))) {
318
													continue;
319
												}
320
												if($pconfig[$dnsgw] == $gwname) {
321
													$selected = "selected";
322
												} else {
323
													$selected = "";
324
												}
325
												echo "<option value='$gwname' $selected>$gwname - {$gwitem['friendlyiface']} - {$gwitem['gateway']}
326
</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 by 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"; ?>>
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"; ?> />
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
					</p>
368
				</td>
369
			</tr>
370
			<tr>
371
				<td width="22%" valign="top" class="vncell"><?=gettext("Time zone"); ?></td>
372
				<td width="78%" class="vtable">
373
					<select name="timezone" id="timezone">
374
						<?php foreach ($timezonelist as $value): ?>
375
						<?php if(strstr($value, "GMT")) continue; ?>
376
						<option value="<?=htmlspecialchars($value);?>" <?php if ($value == $pconfig['timezone']) echo "selected"; ?>>
377
							<?=htmlspecialchars($value);?>
378
						</option>
379
						<?php endforeach; ?>
380
					</select>
381
					<br/>
382
					<span class="vexpl">
383
						<?=gettext("Select the location closest to you"); ?>
384
					</span>
385
				</td>
386
			</tr>
387
<!--
388
			<tr>
389
				<td width="22%" valign="top" class="vncell">Time update interval</td>
390
				<td width="78%" class="vtable">
391
					<input name="timeupdateinterval" type="text" class="formfld unknown" id="timeupdateinterval" size="4" value="<?=htmlspecialchars($pconfig['timeupdateinterval']);?>">
392
					<br/>
393
					<span class="vexpl">
394
						Minutes between network time sync. 300 recommended,
395
						or 0 to disable
396
					</span>
397
				</td>
398
			</tr>
399
-->
400
			<tr>
401
				<td width="22%" valign="top" class="vncell"><?=gettext("NTP time server"); ?></td>
402
				<td width="78%" class="vtable">
403
					<input name="timeservers" type="text" class="formfld unknown" id="timeservers" size="40" value="<?=htmlspecialchars($pconfig['timeservers']);?>">
404
					<br/>
405
					<span class="vexpl">
406
						<?=gettext("Use a space to separate multiple hosts (only one " .
407
						"required). Remember to set up at least one DNS server " .
408
						"if you enter a host name here!"); ?>
409
					</span>
410
				</td>
411
			</tr>
412
			<tr>
413
				<td width="22%" valign="top" class="vncell"><?php echo gettext("Language");?></td>
414
				<td width="78%" class="vtable">
415
					<select name="language">
416
						<?php
417
						foreach(get_locale_list() as $lcode => $ldesc) {
418
							$selected = ' selected';
419
							if($lcode != $pconfig['language'])
420
								$selected = '';
421
							echo "<option value=\"{$lcode}\"{$selected}>{$ldesc}</option>";
422
						}
423
						?>
424
					</select>
425
					<strong>
426
						<?=gettext("Choose a language for the webConfigurator"); ?>
427
					</strong>
428
				</td>
429
			</tr>
430
			<tr>
431
				<td colspan="2" class="list" height="12">&nbsp;</td>
432
			</tr>
433
			<?php if (! $g['disablethemeselection']): ?>
434
			<tr>
435
				<td colspan="2" valign="top" class="listtopic"><?=gettext("Theme"); ?></td>
436
			</tr>
437
			<tr>
438
				<td width="22%" valign="top" class="vncell">&nbsp;</td>
439
				<td width="78%" class="vtable">
440
					<select name="theme">
441
						<?php
442
							$files = return_dir_as_array("/usr/local/www/themes/");
443
							foreach($files as $f):
444
								if ((substr($f, 0, 1) == "_") && !isset($config['system']['developer']))
445
									continue;
446
								if ($f == "CVS")
447
									continue;
448
								$curtheme = "pfsense";
449
								if ($config['theme'])
450
									$curtheme = $config['theme'];
451
								$selected = "";
452
								if($f == $curtheme)
453
									$selected = " SELECTED";
454
						?>
455
						<option <?=$selected;?>><?=$f;?></option>
456
						<?php endforeach; ?>
457
					</select>
458
					<strong>
459
						<?=gettext("This will change the look and feel of"); ?>
460
						<?=$g['product_name'];?>.
461
					</strong>
462
				</td>
463
			</tr>
464
			<?php endif; ?>
465
			<tr>
466
				<td colspan="2" class="list" height="12">&nbsp;</td>
467
			</tr>			
468
			<tr>
469
				<td width="22%" valign="top">&nbsp;</td>
470
				<td width="78%">
471
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>">
472
				</td>
473
			</tr>
474
		</table>
475
		</div>
476
		</td></tr>
477
		</table>
478
	</form>
479
<?php include("fend.inc"); ?>
480
</body>
481
</html>
(190-190/242)