Project

General

Profile

Download (16.2 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
$pconfig['dns1gwint'] = $config['system']['dns1gwint'];
53
$pconfig['dns2gwint'] = $config['system']['dns2gwint'];
54
$pconfig['dns3gwint'] = $config['system']['dns3gwint'];
55
$pconfig['dns4gwint'] = $config['system']['dns4gwint'];
56

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

    
63
$pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']);
64

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

    
72
$changedesc = gettext("System") . ": ";
73
$changecount = 0;
74

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

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

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

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

    
102
if ($_POST) {
103

    
104
	$changecount++;
105
	
106
	unset($input_errors);
107
	$pconfig = $_POST;
108

    
109
	/* input validation */
110
	$reqdfields = split(" ", "hostname domain");
111
	$reqdfieldsn = array(gettext("Hostname"),gettext("Domain"));
112

    
113
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
114

    
115
	if ($_POST['hostname'] && !is_hostname($_POST['hostname'])) {
116
		$input_errors[] = gettext("The hostname may only contain the characters a-z, 0-9 and '-'.");
117
	}
118
	if ($_POST['domain'] && !is_domain($_POST['domain'])) {
119
		$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
120
	}
121
	if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
122
		$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary DNS server.");
123
	}
124
	if (($_POST['dns3'] && !is_ipaddr($_POST['dns3'])) || ($_POST['dns4'] && !is_ipaddr($_POST['dns4']))) {
125
		$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary DNS server.");
126
	}	
127
	if ($_POST['webguiport'] && (!is_numericint($_POST['webguiport']) ||
128
			($_POST['webguiport'] < 1) || ($_POST['webguiport'] > 65535))) {
129
		$input_errors[] = gettext("A valid TCP/IP port must be specified for the webConfigurator port.");
130
	}
131

    
132
	$direct_networks_list = explode(" ", filter_get_direct_networks_list());
133
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
134
		$dnsitem = "dns{$dnscounter}";
135
		$dnsgwitem = "dns{$dnscounter}gwint";
136
		if ($_POST[$dnsgwitem]) {
137
			if(interface_has_gateway($_POST[$dnsgwitem])) {
138
				foreach($direct_networks_list as $direct_network) {
139
					if(ip_in_subnet($_POST[$dnsitem], $direct_network)) {
140
						$input_errors[] = gettext("You can not assign a gateway to DNS '{$_POST[$dnsitem]}' server which is on a directly connected network.");
141
					}
142
				}
143
			}
144
		}
145
	}
146

    
147
	$t = (int)$_POST['timeupdateinterval'];
148
	if (($t < 0) || (($t > 0) && ($t < 6)) || ($t > 1440)) {
149
		$input_errors[] = gettext("The time update interval must be either 0 (disabled) or between 6 and 1440.");
150
	}
151
	foreach (explode(' ', $_POST['timeservers']) as $ts) {
152
		if (!is_domain($ts)) {
153
			$input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'.");
154
		}
155
	}
156

    
157
	if (!$input_errors) {
158
		update_if_changed("hostname", $config['system']['hostname'], strtolower($_POST['hostname']));
159
		update_if_changed("domain", $config['system']['domain'], strtolower($_POST['domain']));
160

    
161
		update_if_changed("timezone", $config['system']['timezone'], $_POST['timezone']);
162
		update_if_changed("NTP servers", $config['system']['timeservers'], strtolower($_POST['timeservers']));
163
		update_if_changed("NTP update interval", $config['system']['time-update-interval'], $_POST['timeupdateinterval']);
164

    
165
		/* pfSense themes */
166
		if (! $g['disablethemeselection']) {
167
			update_if_changed("System Theme", $config['theme'], $_POST['theme']);	
168
		}
169

    
170
		/* XXX - billm: these still need updating after figuring out how to check if they actually changed */
171
		unset($config['system']['dnsserver']);
172
		if ($_POST['dns1'])
173
			$config['system']['dnsserver'][] = $_POST['dns1'];
174
		if ($_POST['dns2'])
175
			$config['system']['dnsserver'][] = $_POST['dns2'];
176
		if ($_POST['dns3'])
177
			$config['system']['dnsserver'][] = $_POST['dns3'];
178
		if ($_POST['dns4'])
179
			$config['system']['dnsserver'][] = $_POST['dns4'];
180

    
181
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
182

    
183
		unset($config['system']['dnsallowoverride']);
184
		$config['system']['dnsallowoverride'] = $_POST['dnsallowoverride'] ? true : false;
185

    
186
		if($_POST['dnslocalhost'] == "yes")
187
			$config['system']['dnslocalhost'] = true;
188
		else
189
			unset($config['system']['dnslocalhost']);
190

    
191
		/* which interface should the dns servers resolve through? */
192
		if($_POST['dns1gwint']) 
193
			$config['system']['dns1gwint'] = $pconfig['dns1gwint'];
194
		else 
195
			unset($config['system']['dns1gwint']);
196

    
197
		if($_POST['dns2gwint']) 
198
			$config['system']['dns2gwint'] = $pconfig['dns2gwint'];
199
		else
200
			unset($config['system']['dns2gwint']);
201

    
202
		if($_POST['dns3gwint']) 
203
			$config['system']['dns3gwint'] = $pconfig['dns3gwint'];
204
		else 
205
			unset($config['system']['dns3gwint']);
206

    
207
		if($_POST['dns4gwint']) 
208
			$config['system']['dns4gwint'] = $pconfig['dns4gwint'];
209
		else
210
			unset($config['system']['dns4gwint']);
211

    
212
		if ($changecount > 0)
213
			write_config($changedesc);
214

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

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

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

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

    
236
?>
237

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