Project

General

Profile

Download (16.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

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

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

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

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

    
81
if($pconfig['timezone'] <> $_POST['timezone']) {
82
	/* restart firewall log dumper helper */
83
	require_once("functions.inc");
84
	$pid = `ps awwwux | grep -v "grep" | grep "tcpdump -v -l -n -e -ttt -i pflog0"  | awk '{ print $2 }'`;
85
	if($pid) {
86
		mwexec("/bin/kill $pid");
87
		usleep(1000);
88
	}		
89
	filter_pflog_start();
90
}
91

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

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

    
104
if ($_POST) {
105

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

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

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

    
117
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
118
		$input_errors[] = gettext("The hostname may only contain the characters a-z, 0-9 and '-'.");
119
	}
120
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
121
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
122
	}
123

    
124
	for ($dnscounter=1; $dnscounter<5; $dnscounter++){
125
		$dnsname="dns{$dnscounter}";
126
		$dnsgwname="dns{$dnscounter}gw";
127
		if (($_POST[$dnsname] && !is_ipaddr($_POST[$dnsname]))) {
128
			$input_errors[] = gettext("A valid IP address must be specified for the DNS server $dnscounter.");
129
		}
130
		if (($_POST[$dnsgwname] <> "none") && (validate_address_family($_POST[$dnsname], lookup_gateway_ip_by_name($_POST[$dnsgwname])) === false )) {
131
			$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]) ."'.");
132
		}
133
	}
134

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

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

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

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

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

    
173
		/* pfSense themes */
174
		if (! $g['disablethemeselection']) {
175
			update_if_changed("System Theme", $config['theme'], $_POST['theme']);	
176
		}
177

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

    
189
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
190

    
191
		unset($config['system']['dnsallowoverride']);
192
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
193

    
194
		if($_POST['dnslocalhost'] == "yes")
195
			$config['system']['dnslocalhost'] = true;
196
		else
197
			unset($config['system']['dnslocalhost']);
198

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

    
210
		if ($changecount > 0)
211
			write_config($changedesc);
212

    
213
		$retval = 0;
214
		$retval = system_hostname_configure();
215
		$retval |= system_hosts_generate();
216
		$retval |= system_resolvconf_generate();
217
		$retval |= services_dnsmasq_configure();
218
		$retval |= system_timezone_configure();
219
		$retval |= system_ntp_configure();
220

    
221
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
222
			$retval |= send_event("service reload dns");
223

    
224
		// Reload the filter - plugins might need to be run.
225
		$retval |= filter_configure();
226
		
227
		$savemsg = get_std_save_message($retval);
228
	}
229
}
230

    
231
$pgtitle = array(gettext("System"),gettext("General Setup"));
232
include("head.inc");
233

    
234
?>
235

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