Project

General

Profile

Download (17.4 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] <> "") && (is_ipaddr($_POST[$dnsname]))) {
132
			if (($_POST[$dnsgwname] <> "none") && (is_ipaddrv4($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false )) {
133
				$input_errors[] = gettext("You can not specify a IPv6 gateway '{$_POST[$dnsgwname]}'for a IPv4 DNS server '{$_POST[$dnsname]}'");
134
			}
135
			if (($_POST[$dnsgwname] <> "none") && (is_ipaddrv6($_POST[$dnsname])) && (validate_address_family($_POST[$dnsname], $_POST[$dnsgwname]) === false )) {
136
				$input_errors[] = gettext("You can not specify a IPv4 gateway '{$_POST[$dnsgwname]}'for a IPv6 DNS server '{$_POST[$dnsname]}'");
137
			}
138
		}
139
	}
140

    
141
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
142
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
143
		$input_errors[] = gettext("A valid TCP/IP port must be specified for the webConfigurator port.");
144
	}
145

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

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

    
171
	if (!$input_errors) {
172
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
173
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
174

    
175
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
176
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
177
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
178

    
179
		if($_POST['language'] && $_POST['language'] != $config['system']['language']) {
180
			$config['system']['language'] = $_POST['language'];
181
			set_language($config['system']['language']);
182
		}
183

    
184
		/* pfSense themes */
185
		if (! $g['disablethemeselection']) {
186
			update_if_changed("System Theme", $config['theme'], $_POST['theme']);	
187
		}
188

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

    
200
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
201

    
202
		unset($config['system']['dnsallowoverride']);
203
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
204

    
205
		if($_POST['dnslocalhost'] == "yes")
206
			$config['system']['dnslocalhost'] = true;
207
		else
208
			unset($config['system']['dnslocalhost']);
209

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

    
221
		if ($changecount > 0)
222
			write_config($changedesc);
223

    
224
		$retval = 0;
225
		$retval = system_hostname_configure();
226
		$retval |= system_hosts_generate();
227
		$retval |= system_resolvconf_generate();
228
		$retval |= services_dnsmasq_configure();
229
		$retval |= system_timezone_configure();
230
		$retval |= system_ntp_configure();
231

    
232
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
233
			$retval |= send_event("service reload dns");
234

    
235
		// Reload the filter - plugins might need to be run.
236
		$retval |= filter_configure();
237
		
238
		$savemsg = get_std_save_message($retval);
239
	}
240
}
241

    
242
$pgtitle = array(gettext("System"),gettext("General Setup"));
243
include("head.inc");
244

    
245
?>
246

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