Project

General

Profile

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

    
122
	for ($dnscounter=1; $dnscounter<5; $dnscounter++){
123
		$dnsname="dns{$dnscounter}";
124
		$dnsgwname="dns{$dnscounter}gw";
125
		if (($_POST[$dnsname] && !is_ipaddr($_POST[$dnsname]))) {
126
			$input_errors[] = gettext("A valid IP address must be specified for the DNS server $dnscounter.");
127
		}
128
		if (($_POST[$dnsgwname] && validate_address_family(lookup_gateway_ip_by_name($_POST[$dnsgwname])))) {
129
			$input_errors[] = gettext("The gateway specified for DNS server $dnscounter is not from the same Address Family.");
130
		}
131
	}
132

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

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

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

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

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

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

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

    
187
		$olddnsallowoverride = $config['system']['dnsallowoverride'];
188

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

    
192
		/* which interface should the dns servers resolve through? */
193
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
194
			$dnsname="dns{$dnscounter}";
195
			$dnsgwname="dns{$dnscounter}gw";
196
			if($_POST[$dnsgwname]) {
197
				$config['system'][$dnsgwname] = $pconfig[$dnsgwname];
198
			} else {
199
				unset($config['system'][$dnsgwname]);
200
			}
201
		}
202

    
203
		if ($changecount > 0)
204
			write_config($changedesc);
205

    
206
		$retval = 0;
207
		$retval = system_hostname_configure();
208
		$retval |= system_hosts_generate();
209
		$retval |= system_resolvconf_generate();
210
		$retval |= services_dnsmasq_configure();
211
		$retval |= system_timezone_configure();
212
		$retval |= system_ntp_configure();
213

    
214
		if ($olddnsallowoverride != $config['system']['dnsallowoverride'])
215
			$retval |= send_event("service reload dns");
216

    
217
		// Reload the filter - plugins might need to be run.
218
		$retval |= filter_configure();
219
		
220
		$savemsg = get_std_save_message($retval);
221
	}
222
}
223

    
224
$pgtitle = array(gettext("System"),gettext("General Setup"));
225
include("head.inc");
226

    
227
?>
228

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